diff --git a/CURRENT_STATE.md b/CURRENT_STATE.md index a91d2b3..f71f08a 100644 --- a/CURRENT_STATE.md +++ b/CURRENT_STATE.md @@ -21,6 +21,7 @@ These correctness fixes landed after the 2026-10-03 checkpoint below: - The footer keeps its status readable at 100–160 columns by dropping optional view hints first. The header label no longer runs into the file count, condensed help keeps its indentation, and the small-terminal notice wraps. - The footer source status describes the cursor's file instead of any file visible on screen. - Host calls into the syntax worker recover a poisoned mailbox lock instead of panicking; a dead worker surfaces through the existing `Engine::poll` error. +- The vendored, patched `libgit2-sys` is gone; the build uses the published crate with its bundled libgit2. Stock libgit2 cuts unquoted `rename`/`copy` names at whitespace, so the parser now receives those names in Git's quoted form and line offsets map back to the supplied bytes. `LIBGIT2_NO_VENDOR` is still rejected at build time. - Unnamed temporary files (patch spool, Git helper output, clipboard input) are created owner-only. On Linux they previously took the umask-derived mode, usually 0644. Linux CI found this. Canonical source output is byte-identical to the 2026-10-03 build for the five DiffsHub corpus patches and the repository fixtures. diff --git a/Cargo.lock b/Cargo.lock index b3e2df7..b4f1f06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,9 +250,9 @@ checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" [[package]] name = "clipboard-win" -version = "5.4.1" +version = "5.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4" +checksum = "052af7878466feccda12ba7a6a67d019d712f296809559b47c12c8cc196d3a9a" dependencies = [ "error-code", ] @@ -649,6 +649,8 @@ checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" [[package]] name = "libgit2-sys" version = "0.18.8+1.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7c568b25d7489bc3fb2988ed69ab111d2944d2f5fec3d5c987fe545ea97b50" dependencies = [ "cc", "libc", diff --git a/Cargo.toml b/Cargo.toml index 0c7f2c5..fc90c37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,13 @@ keywords = ["diff", "patch", "terminal", "tui", "ratatui"] categories = ["command-line-utilities", "development-tools", "text-processing"] # Publishing stays off until the crate no longer needs the [patch.crates-io] # overrides below. crates.io ignores [patch], so a published build would -# silently use unpatched upstream syntect, fancy-regex and libgit2-sys. +# silently use unpatched upstream syntect and fancy-regex. publish = false # Ship only what the library and binary need to build, plus the docs a reader # of the crate needs. Tests, fixtures, tools, reports and vendor/ stay in Git. include = [ "/src/**/*.rs", + "/build.rs", "/assets/pierre/**", "/examples/embedded_viewer.rs", "/Cargo.toml", @@ -41,7 +42,6 @@ owner-census = ["regex-census", "syntect/owner-census"] [patch.crates-io] syntect = { path = "vendor/syntect" } fancy-regex = { path = "vendor/fancy-regex" } -libgit2-sys = { path = "vendor/libgit2-sys" } [dependencies] anyhow = "1.0" diff --git a/EMBEDDING.md b/EMBEDDING.md index 422c2d0..3ce1577 100644 --- a/EMBEDDING.md +++ b/EMBEDDING.md @@ -11,7 +11,7 @@ Native clipboard, physical-terminal acceptance, and the final package remain pen Use a path dependency on the source package. The host must use Ratatui 0.30. Cargo does not inherit dependency patches from a dependency's manifest. -The consuming workspace root therefore needs all three patches: +The consuming workspace root therefore needs both patches: ```toml [dependencies] @@ -21,11 +21,11 @@ ratatui = { version = "0.30.2", default-features = false, features = ["crossterm [patch.crates-io] syntect = { path = "../native-diff/vendor/syntect" } fancy-regex = { path = "../native-diff/vendor/fancy-regex" } -libgit2-sys = { path = "../native-diff/vendor/libgit2-sys" } ``` Adjust these paths for the host's workspace. Retain the vendor directories and their notices. -The patches provide required syntax-engine behavior and the corrected local Git parser. +The patches provide required syntax-engine behavior. +The Git patch parser is the stock `libgit2-sys` crate. The build fails if `LIBGIT2_NO_VENDOR` asks it to link a system libgit2. Do not substitute registry or system versions to make dependency resolution succeed. Keep the host's generated lockfile and use `--locked` for subsequent builds. Diagnostic crate features are not required for embedding. diff --git a/README.md b/README.md index 189afef..4e106e3 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ The installation record (external record `native-diff-production-hardening/INSTA The qualified build environment is macOS arm64 with Rust 1.96.0, the separately checked Rust 1.88.0 minimum, and Xcode command-line build tools. Other platforms remain unqualified. For an isolated source installation, use `cargo install --path . --locked --root /absolute/path/to/an/isolated/prefix`; add `--offline` only after locked dependencies have been acquired. This does not add the prefix to PATH. -The build uses the [locally corrected parser](vendor/libgit2-sys/NATIVE_DIFF_PATCH.md). +The build compiles the libgit2 source bundled with the published `libgit2-sys` crate. If `LIBGIT2_NO_VENDOR` is set to a nonzero value, unset it before building. -The build rejects an override that would select an unpatched system library. +The build rejects an override that would select a system library. In an existing Ghostty window, open the sample patch: @@ -291,6 +291,7 @@ One Cargo package contains one library and one executable. Ratatui draws the ter | --- | --- | | `ingest.rs` | Read file-patch units and check their hunk boundaries | | `model.rs` | Parse file-patch units through libgit2 and apply the existing line-pairing rule | +| `model/rename_names.rs` | Quote rename and copy names that libgit2 would cut at whitespace, and map parser offsets back | | `storage.rs` | Publish compact patch indexes and stable source identities | | `source.rs` | Capture immutable source bodies, disk line indexes, and exact correspondence | | `input` | Bind local comparisons, supervise Git, and prepare visible source pairs | diff --git a/RELEASE_READINESS.md b/RELEASE_READINESS.md index 66af990..9d70e84 100644 --- a/RELEASE_READINESS.md +++ b/RELEASE_READINESS.md @@ -78,7 +78,7 @@ The inventory records each changed and added file separately. | --- | --- | --- | | Syntect 5.3.0 | [Patch note](vendor/syntect/NATIVE_DIFF_PATCH.md), source provenance, standalone checks | Summary updated 2026-09-22 for required-byte rejection, retained-heap APIs, and affected files. Keep the documented checks during updates. | | Fancy Regex 0.16.2 | [Patch note](vendor/fancy-regex/NATIVE_DIFF_PATCH.md), source provenance, standalone checks | Summary updated 2026-09-22 for required-byte metadata, public error behavior, and affected files. Keep the documented checks during updates. | -| libgit2-sys 0.18.8+1.9.7 | [Parser correction](vendor/libgit2-sys/NATIVE_DIFF_PATCH.md), unchanged notices | Retain the parser regression checks during updates | +| libgit2-sys 0.18.8+1.9.7 | Parser correction, unchanged notices | Removed 2026-10-27. The stock crate is used; `src/model/rename_names.rs` quotes rename and copy names before parsing. Retain the parser regression checks during updates. | The bundled grammar package supplies notices in addition to its crate license. The local export contains 66 syntax notice entries from the pinned package's public API. diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..7cf8242 --- /dev/null +++ b/build.rs @@ -0,0 +1,13 @@ +//! Keeps the Git patch parser on the libgit2 source that `git2`'s `vendored-libgit2` feature +//! builds. libgit2-sys links a system library instead when `LIBGIT2_NO_VENDOR` is set to a +//! nonzero value, and that library's parser has not been checked against this crate. + +fn main() { + println!("cargo:rerun-if-env-changed=LIBGIT2_NO_VENDOR"); + if std::env::var_os("LIBGIT2_NO_VENDOR").is_some_and(|value| value != "0") { + panic!( + "native-diff requires the libgit2 source vendored by libgit2-sys. \ + Unset LIBGIT2_NO_VENDOR or set it to 0." + ); + } +} diff --git a/src/model.rs b/src/model.rs index 95298c1..a4db00c 100644 --- a/src/model.rs +++ b/src/model.rs @@ -4,6 +4,8 @@ use anyhow::{Context, Result, bail}; use git2::{Delta, Diff, Patch}; use serde::Serialize; +mod rename_names; + #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)] pub enum Kind { Context, @@ -138,7 +140,9 @@ impl Document { bail!("Combined merge diffs are not supported. Supply a two-sided patch."); } let normalized = empty_file_headers(input); - let diff = Diff::from_buffer(normalized.as_deref().unwrap_or(input)) + let normalized = normalized.as_deref().unwrap_or(input); + let quoted = rename_names::quote_rename_names(normalized); + let diff = Diff::from_buffer(quoted.as_ref().map_or(normalized, |q| &q.bytes)) .context("Cannot parse this patch")?; if diff.deltas().len() == 0 { bail!("The input contains no recognized file changes."); @@ -245,9 +249,13 @@ impl Document { file.deletions += usize::from(kind == Kind::Deletion); let largest = old.unwrap_or(0).max(new.unwrap_or(0)).max(1); file.digits = file.digits.max(largest.ilog10() as usize + 1); - let offset = usize::try_from(line.content_offset())? - .checked_add(1) - .context("Source offset overflow")?; + let offset = usize::try_from(line.content_offset())?; + let offset = match "ed { + Some(quoted) => quoted.original_offset(offset), + None => Some(offset), + } + .and_then(|offset| offset.checked_add(1)) + .context("Source offset overflow")?; let end = offset .checked_add(line.content().len()) .context("Source length overflow")?; diff --git a/src/model/rename_names.rs b/src/model/rename_names.rs new file mode 100644 index 0000000..f26d480 --- /dev/null +++ b/src/model/rename_names.rs @@ -0,0 +1,413 @@ +//! Rename and copy names that libgit2 cannot read verbatim. +//! +//! Git writes an unquoted `rename from`, `rename to`, `copy from`, or `copy to` name literally +//! through the line ending, so it can contain leading, interior, and trailing spaces. libgit2 +//! stops an unquoted name at the first whitespace byte. It decodes Git's C-quoted form exactly, +//! so the parser receives those names rewritten into quoted form. Hunk lines are not changed, +//! and [`QuotedNames::original_offset`] maps parser offsets back to the supplied bytes. + +/// Header line prefixes whose remainder is one unprefixed file name. +const NAME_LINES: [&[u8]; 6] = [ + b"rename from ", + b"rename to ", + b"rename old ", + b"rename new ", + b"copy from ", + b"copy to ", +]; + +/// Lines that end a Git extended header. A name line after one of these is not a header. +const HEADER_ENDS: [&[u8]; 5] = [ + b"--- ", + b"+++ ", + b"@@ ", + b"Binary files ", + b"GIT binary patch", +]; + +/// A patch with rewritten rename and copy names. +#[derive(Debug)] +pub(super) struct QuotedNames { + pub(super) bytes: Vec, + /// One entry per rewritten line, in order: the end of that line in `bytes` and the total + /// number of bytes added up to it. + shifts: Vec<(usize, usize)>, +} + +impl QuotedNames { + /// Maps an offset in [`Self::bytes`] that lies outside every rewritten line to the same + /// byte in the supplied patch. + pub(super) fn original_offset(&self, offset: usize) -> Option { + let before = self.shifts.partition_point(|&(end, _)| end <= offset); + let added = before + .checked_sub(1) + .map_or(0, |index| self.shifts[index].1); + offset.checked_sub(added) + } +} + +/// Returns `None` when libgit2 already reads every rename and copy name as written. +pub(super) fn quote_rename_names(input: &[u8]) -> Option { + // A name line always follows a `diff --git` line, so it never starts the input. + if memchr::memmem::find(input, b"\nrename ").is_none() + && memchr::memmem::find(input, b"\ncopy ").is_none() + { + return None; + } + let mut result: Option = None; + let mut copied = 0; + let mut start = 0; + let mut header = false; + for line in input.split_inclusive(|byte| *byte == b'\n') { + let end = start + line.len(); + if line.starts_with(b"diff --git ") { + header = true; + } else if HEADER_ENDS.iter().any(|prefix| line.starts_with(prefix)) { + header = false; + } else if header && let Some((prefix, name, ending)) = unreadable_name(line) { + let quoted = result.get_or_insert_with(|| QuotedNames { + bytes: Vec::with_capacity(input.len() + 64), + shifts: Vec::new(), + }); + quoted.bytes.extend_from_slice(&input[copied..start]); + quoted.bytes.extend_from_slice(prefix); + quote(name, &mut quoted.bytes); + quoted.bytes.extend_from_slice(ending); + quoted + .shifts + .push((quoted.bytes.len(), quoted.bytes.len() - end)); + copied = end; + } + start = end; + } + let mut quoted = result?; + quoted.bytes.extend_from_slice(&input[copied..]); + Some(quoted) +} + +/// Splits a complete name line that libgit2 would misread into its prefix, name, and ending. +fn unreadable_name(line: &[u8]) -> Option<(&[u8], &[u8], &[u8])> { + let prefix = NAME_LINES.iter().find(|prefix| line.starts_with(prefix))?; + // libgit2 stops reading the header at a line without a newline. + let body = line[prefix.len()..].strip_suffix(b"\n")?; + let (name, ending): (_, &[u8]) = match body.strip_suffix(b"\r") { + Some(name) => (name, b"\r\n"), + None => (body, b"\n"), + }; + // Quoted names already use libgit2's decoder, and empty names remain errors. + if name.first() == Some(&b'"') || !name.iter().any(|byte| is_libgit2_space(*byte)) { + return None; + } + Some((prefix, name, ending)) +} + +/// The bytes that end an unquoted name in libgit2's `git__isspace`. +fn is_libgit2_space(byte: u8) -> bool { + matches!(byte, b' ' | b'\t' | b'\n' | b'\x0b' | b'\x0c' | b'\r') +} + +/// Writes `name` in Git's C-quoted form, which libgit2's `git_str_unquote` reverses exactly. +fn quote(name: &[u8], output: &mut Vec) { + output.push(b'"'); + for &byte in name { + let escape = match byte { + b'"' => b'"', + b'\\' => b'\\', + b'\x07' => b'a', + b'\x08' => b'b', + b'\t' => b't', + b'\n' => b'n', + b'\x0b' => b'v', + b'\x0c' => b'f', + b'\r' => b'r', + 0..=0x1f | 0x7f => { + output.extend_from_slice(&[ + b'\\', + b'0' + (byte >> 6), + b'0' + ((byte >> 3) & 7), + b'0' + (byte & 7), + ]); + continue; + } + _ => { + output.push(byte); + continue; + } + }; + output.extend_from_slice(&[b'\\', escape]); + } + output.push(b'"'); +} + +#[cfg(test)] +mod tests { + use super::super::{Document, FileDiff}; + use super::*; + + fn rewritten(input: &[u8]) -> Vec { + quote_rename_names(input).expect("rewritten").bytes + } + + fn rename(old: &str, new: &str, ending: &str) -> String { + [ + format!("diff --git a/{old} b/{new}"), + "similarity index 80%".into(), + format!("rename from {old}"), + format!("rename to {new}"), + "index 1111111..2222222 100644".into(), + format!("--- a/{old}"), + format!("+++ b/{new}"), + "@@ -1,3 +1,3 @@".into(), + " keep".into(), + "-before".into(), + "+after".into(), + " rename from tail".into(), + String::new(), + ] + .join(ending) + } + + fn pure_copy(old: &str, new: &str) -> String { + format!( + "diff --git a/{old} b/{new}\nsimilarity index 100%\ncopy from {old}\ncopy to {new}\n" + ) + } + + /// Every parsed line must address its exact bytes in the supplied patch. + fn check_offsets(input: &[u8], doc: &Document) { + assert!(!doc.lines.is_empty()); + for line in &doc.lines { + let end = line.offset + line.bytes.len(); + assert_eq!(&input[line.offset..end], line.bytes.as_slice()); + } + } + + fn only_file(doc: &Document) -> &FileDiff { + assert_eq!(doc.files.len(), 1); + &doc.files[0] + } + + #[test] + fn names_libgit2_reads_as_written_are_left_alone() { + for input in [ + rename("old.txt", "new.txt", "\n"), + rename("old.txt", "new.txt", "\r\n"), + rename("old-日本語.txt", "new-日本語.txt", "\n"), + pure_copy("dir/old.rs", "dir/new.rs"), + "diff --git \"a/old name\" \"b/new name\"\nsimilarity index 100%\n\ + rename from \"old name\"\nrename to \"new\\tname\"\n" + .into(), + "diff --git a/old b/new\nsimilarity index 100%\nrename from \nrename to new\n".into(), + "diff --git a/a.rs b/a.rs\n--- a/a.rs\n+++ b/a.rs\n@@ -1 +1 @@\n-x\n+y\n".into(), + ] { + assert!(quote_rename_names(input.as_bytes()).is_none(), "{input:?}"); + } + } + + #[test] + fn whitespace_names_are_quoted_with_the_line_ending_kept() { + let cases: [(&str, &str); 7] = [ + ("old name.txt", "\"old name.txt\""), + ("old.txt ", "\"old.txt \""), + (" old.txt", "\" old.txt\""), + ("old\tname", "\"old\\tname\""), + ("日本 語.txt", "\"日本 語.txt\""), + ("a \\b\"c\".txt", "\"a \\\\b\\\"c\\\".txt\""), + ( + "a\rb c\x01\x7f\x0b\x0c\x07\x08", + "\"a\\rb c\\001\\177\\v\\f\\a\\b\"", + ), + ]; + for (name, expected) in cases { + for ending in ["\n", "\r\n"] { + for prefix in NAME_LINES { + let mut input = b"diff --git a/x b/y\n".to_vec(); + input.extend_from_slice(prefix); + input.extend_from_slice(name.as_bytes()); + input.extend_from_slice(ending.as_bytes()); + let mut expected_bytes = b"diff --git a/x b/y\n".to_vec(); + expected_bytes.extend_from_slice(prefix); + expected_bytes.extend_from_slice(expected.as_bytes()); + expected_bytes.extend_from_slice(ending.as_bytes()); + assert_eq!(rewritten(&input), expected_bytes, "{name:?} {ending:?}"); + } + } + } + } + + #[test] + fn only_extended_header_lines_are_rewritten() { + let input = b"commit message\n\ + rename from not a header\n\ + diff --git a/a b b/c d\n\ + similarity index 50%\n\ + rename from a b\n\ + rename to c d\n\ + --- a/a b\n\ + +++ b/c d\n\ + rename from not a header\n\ + @@ -1 +1 @@\n\ + -x\n\ + +y\n\ + rename to not a header\n\ + rename to unterminated name"; + let expected = String::from_utf8(input.to_vec()) + .unwrap() + .replacen("rename from a b\n", "rename from \"a b\"\n", 1) + .replacen("rename to c d\n", "rename to \"c d\"\n", 1); + assert_eq!(rewritten(input), expected.as_bytes()); + } + + #[test] + fn offsets_map_back_across_several_rewritten_lines() { + let input = b"diff --git a/a b b/c d\nsimilarity index 100%\n\ + rename from a b\nrename to c d\n\ + diff --git a/e b/f g\nsimilarity index 100%\ncopy from e\ncopy to f g\n"; + let quoted = quote_rename_names(input).unwrap(); + // Each rewritten line gains two quotes. `copy from e` is readable and stays as written. + let expected = [ + (0, 0), + (23, 23), + (45, 45), + (61, 63), + (75, 79), + (118, 122), + (130, 134), + ]; + for (original, rewritten) in expected { + assert_eq!(quoted.bytes[rewritten], input[original]); + assert_eq!(quoted.original_offset(rewritten), Some(original)); + } + assert_eq!(quoted.bytes.len(), input.len() + 6); + assert_eq!( + quoted.original_offset(quoted.bytes.len()), + Some(input.len()) + ); + } + + #[test] + fn rewritten_names_match_the_git_header_and_quoted_form() { + let names = [ + ("old name.txt", "new name.txt"), + ("old.txt ", "new.txt "), + (" old.txt", " new.txt"), + ("old\tname", "new\tname"), + ("old 日本語.txt", "new 日本語.txt"), + ("dir/a \\b\".txt", "dir/c \\d\".txt"), + ]; + for (old, new) in names { + for ending in ["\n", "\r\n"] { + let input = rename(old, new, ending); + let doc = Document::parse_file(input.as_bytes()).unwrap(); + let file = only_file(&doc); + assert_eq!(file.status, "Renamed"); + assert_eq!(file.identity.old_path, old.as_bytes(), "{old:?} {ending:?}"); + assert_eq!(file.identity.new_path, new.as_bytes(), "{new:?} {ending:?}"); + assert_eq!(file.raw_path, new.as_bytes()); + // The rename lines agree with the untouched `diff --git` header. + let header = input.lines().next().unwrap().trim_end_matches('\r'); + let old_path = String::from_utf8(file.identity.old_path.clone()).unwrap(); + let new_path = String::from_utf8(file.identity.new_path.clone()).unwrap(); + assert_eq!(header, format!("diff --git a/{old_path} b/{new_path}")); + assert_eq!(doc.lines.len(), 4); + assert_eq!(doc.lines[1].bytes, format!("before{ending}").as_bytes()); + assert_eq!( + doc.lines.iter().map(|l| (l.old, l.new)).collect::>(), + [ + (Some(1), Some(1)), + (Some(2), None), + (None, Some(2)), + (Some(3), Some(3)) + ] + ); + check_offsets(input.as_bytes(), &doc); + + // Git's own quoted spelling of the same names parses identically. + let mut quoted_old = Vec::new(); + quote(old.as_bytes(), &mut quoted_old); + let mut quoted_new = Vec::new(); + quote(new.as_bytes(), &mut quoted_new); + let quoted_input = input + .replacen( + &format!("rename from {old}{ending}"), + &format!( + "rename from {}{ending}", + String::from_utf8(quoted_old).unwrap() + ), + 1, + ) + .replacen( + &format!("rename to {new}{ending}"), + &format!( + "rename to {}{ending}", + String::from_utf8(quoted_new).unwrap() + ), + 1, + ); + assert_ne!(quoted_input, input); + let quoted_doc = Document::parse_file(quoted_input.as_bytes()).unwrap(); + let quoted_file = only_file("ed_doc); + assert_eq!(quoted_file.identity.old_path, file.identity.old_path); + assert_eq!(quoted_file.identity.new_path, file.identity.new_path); + check_offsets(quoted_input.as_bytes(), "ed_doc); + let shift = quoted_input.len() - input.len(); + for (line, quoted_line) in doc.lines.iter().zip("ed_doc.lines) { + assert_eq!(line.bytes, quoted_line.bytes); + assert_eq!(line.offset + shift, quoted_line.offset); + } + } + } + } + + #[test] + fn copies_and_multiple_files_keep_exact_offsets() { + let mut input = rename("a b.txt", "c d.txt", "\n"); + input.push_str(&pure_copy("e f.txt ", "g h.txt ")); + input.push_str(&rename("i j.txt", "k l.txt", "\n").replace("rename ", "copy ")); + let doc = Document::parse_file(input.as_bytes()).unwrap(); + let paths: Vec<_> = doc + .files + .iter() + .map(|file| { + ( + file.status.as_str(), + file.identity.old_path.as_slice(), + file.identity.new_path.as_slice(), + ) + }) + .collect(); + assert_eq!( + paths, + [ + ("Renamed", &b"a b.txt"[..], &b"c d.txt"[..]), + ("Copied", b"e f.txt ", b"g h.txt "), + ("Copied", b"i j.txt", b"k l.txt"), + ] + ); + assert_eq!(doc.lines.len(), 8); + check_offsets(input.as_bytes(), &doc); + // The last file's lines sit after three rewritten lines. + let last = &doc.lines[4]; + assert_eq!( + last.offset, + input.rfind("\n keep\n").unwrap() + 2, + "{:?}", + last.bytes + ); + } + + #[test] + fn libgit2_is_built_from_the_vendored_source() { + assert!(git2::Version::get().vendored()); + } + + #[test] + fn malformed_names_remain_errors() { + for name in ["\"unterminated", "\"a\" b", "\"bad\\q\"", "\"\""] { + let input = format!( + "diff --git a/old b/new\nsimilarity index 100%\nrename from {name}\nrename to new\n" + ); + assert!(Document::parse_file(input.as_bytes()).is_err(), "{name:?}"); + } + } +} diff --git a/vendor/libgit2-sys/.cargo_vcs_info.json b/vendor/libgit2-sys/.cargo_vcs_info.json deleted file mode 100644 index 11d58c2..0000000 --- a/vendor/libgit2-sys/.cargo_vcs_info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "git": { - "sha1": "6c93812dbc1c34aef6e6464a645545b4a4299807" - }, - "path_in_vcs": "libgit2-sys" -} \ No newline at end of file diff --git a/vendor/libgit2-sys/CHANGELOG.md b/vendor/libgit2-sys/CHANGELOG.md deleted file mode 100644 index f0532e8..0000000 --- a/vendor/libgit2-sys/CHANGELOG.md +++ /dev/null @@ -1,337 +0,0 @@ -# Changelog - -## 0.18.8+1.9.7 - 2026-08-21 -[0.18.7...0.18.8](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.18.7+1.9.6...libgit2-sys-0.18.8+1.9.7) - -### Changed - -- Updated to libgit2 [1.9.7](https://github.com/libgit2/libgit2/releases/tag/v1.9.7). - This fixes - [CVE-2026-5917](https://github.com/libgit2/libgit2/security/advisories/GHSA-xqj4-2j5v-rr75), - a potential command injection on the remote host - via unescaped repository paths in the libssh2 SSH transport. - -## 0.18.7+1.9.6 - 2026-07-22 -[0.18.6...0.18.7](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.18.6+1.9.5...libgit2-sys-0.18.7+1.9.6) - -### Changed - -- Updated to libgit2 [1.9.6](https://github.com/libgit2/libgit2/releases/tag/v1.9.6). - This fixes SSH known-host loading with an invalid home directory, - an Android crash when `HOME` is unset, - and hidden symbol visibility for static builds. - -## 0.18.6+1.9.5 - 2026-07-22 -[0.18.5...0.18.6](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.18.5+1.9.4...libgit2-sys-0.18.6+1.9.5) - -### Added - -- Added bindings for `GIT_OPT_ADD_SSL_X509_CERT`. -- Added bindings for `GIT_OPT_GET_PACK_MAX_OBJECT_SIZE` and `GIT_OPT_SET_PACK_MAX_OBJECT_SIZE`. - -### Changed - -- Updated to libgit2 [1.9.5](https://github.com/libgit2/libgit2/releases/tag/v1.9.5). - This fixes - [CVE-2026-53583](https://github.com/libgit2/libgit2/security/advisories/GHSA-h7gc-w2gg-p9xp), - [CVE-2026-53584](https://github.com/libgit2/libgit2/security/advisories/GHSA-cw77-j82w-mchm), - [CVE-2026-53585](https://github.com/libgit2/libgit2/security/advisories/GHSA-27m5-gxxh-x79j), - [CVE-2026-53586](https://github.com/libgit2/libgit2/security/advisories/GHSA-2889-x8f6-mc4x), - [CVE-2026-53587](https://github.com/libgit2/libgit2/security/advisories/GHSA-pm24-4jhq-3xvm), - and [GHSA-wfx7-g85r-q6vw](https://github.com/libgit2/libgit2/security/advisories/GHSA-wfx7-g85r-q6vw). -- Updated the vendored build to use libgit2's bundled PCRE2 regex backend. - -## 0.18.5+1.9.4 - 2026-05-23 -[0.18.4...0.18.5](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.18.4+1.9.3...libgit2-sys-0.18.5+1.9.4) - -### Changed -- Updated to libgit2 [1.9.4](https://github.com/libgit2/libgit2/releases/tag/v1.9.4) - [#1260](https://github.com/rust-lang/git2-rs/pull/1260) - -## 0.18.4+1.9.3 - 2026-05-07 -[0.18.3...0.18.4](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.18.3+1.9.2...libgit2-sys-0.18.4+1.9.3) - -### Changed - -- Updated to libgit2 [1.9.3](https://github.com/libgit2/libgit2/releases/tag/v1.9.3) - [#1242](https://github.com/rust-lang/git2-rs/pull/1242) - -### Fixed - -- Fixed the signature of `git_config_backend::unlock`. - Previously the second `c_int` argument was missing - and the declaration was unusable. - [#1181](https://github.com/rust-lang/git2-rs/pull/1181) - -### Added - -- Added experimental SHA256 OID support behind a new `unstable-sha256` Cargo feature. - This reflects upstream libgit2's `GIT_EXPERIMENTAL_SHA256` feature gate, - and requires the linked libgit2 C library to be built with the experimental flag. - When enabled, the build supports linking against a system `libgit2-experimental.so`. - See the feature description in `Cargo.toml` for ABI-stability caveats. - [#1201](https://github.com/rust-lang/git2-rs/pull/1201) -- Added binding for `git_repository_oid_type`. - [#1204](https://github.com/rust-lang/git2-rs/pull/1204) -- Added binding for `git_oid_is_zero`, replacing the deprecated `git_oid_iszero`. - [#1205](https://github.com/rust-lang/git2-rs/pull/1205) -- Added binding for `git_remote_oid_type`. - [#1242](https://github.com/rust-lang/git2-rs/pull/1242) -- Added `GIT_REPOSITORY_INIT_RELATIVE_GITLINK` flag. - [#1242](https://github.com/rust-lang/git2-rs/pull/1242) -- Added bindings for the `git_merge_file_input` API, including `git_merge_file_input_init`. - [#1210](https://github.com/rust-lang/git2-rs/pull/1210) -- Added bindings for `git_odb_stream` and `git_odb_stream_t`. - [#1181](https://github.com/rust-lang/git2-rs/pull/1181) -- Added bindings for `git_reference_iterator`. - [#1181](https://github.com/rust-lang/git2-rs/pull/1181) -- Added bindings for APIs from `git2/sys/config.h`, - including the missing `iterator` function on `git_config_backend`. - [#1181](https://github.com/rust-lang/git2-rs/pull/1181) -- Added binding for `git_reference_dup`. - [#1233](https://github.com/rust-lang/git2-rs/pull/1233) -- Added binding for `git_signature_default_from_env`. - [#1237](https://github.com/rust-lang/git2-rs/pull/1237) - -## 0.18.3+1.9.2 - 2025-12-06 -[0.18.2...0.18.3](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.18.2+1.9.1...libgit2-sys-0.18.3+1.9.2) - -### Changed -- Updated to libgit2 [1.9.2](https://github.com/libgit2/libgit2/releases/tag/v1.9.2) - [#1195](https://github.com/rust-lang/git2-rs/pull/1195) - - Note that this release fixes two security issues. However, the Rust bindings do not provide direct support for the affected APIs. In particular: - - The `libgit2-sys` crate does not support building the vendored C library with the `GIT_SSH_EXEC` setting. This will only be an issue if you are binding to a system-provided library built with this setting. - - The `git2` crate does not support custom SSH credentials. However, the `libgit2-sys` crate does export the `git_cred_ssh_custom_new` C-binding. Any projects using the C bindings directly are affected. - -## 0.18.2+1.9.1 - 2025-06-21 -[0.18.1...0.18.2](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.18.1+1.9.0...libgit2-sys-0.18.2+1.9.1) - -### Changed -- Updated to libgit2 [1.9.1](https://github.com/libgit2/libgit2/releases/tag/v1.9.1) - [#1169](https://github.com/rust-lang/git2-rs/pull/1169) - -## 0.18.1+1.9.0 - 2025-03-17 -[0.18.0...0.18.1](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.18.0+1.9.0...libgit2-sys-0.18.1+1.9.0) - -### Added - -- Added binding for `git_branch_upstream_merge` - [#1131](https://github.com/rust-lang/git2-rs/pull/1131) -- Added bindings for `git_merge_file_options` and `git_merge_file_result`, `git_merge_file_options_init`, `git_merge_file_from_index`, `git_merge_file_result_free`, and updated `git_merge_file_flag_t`. - [#1062](https://github.com/rust-lang/git2-rs/pull/1062) - -### Fixed - -- Fixed linking to advapi32 on Windows for recent nightly versions of Rust. - [#1143](https://github.com/rust-lang/git2-rs/pull/1143) - -## 0.18.0+1.9.0 - 2025-01-04 -[0.16.2...0.17.0](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.17.0+1.8.1...libgit2-sys-0.18.0+1.9.0) - -### Added - -- Added bindings for `git_repository_commondir` - [#1079](https://github.com/rust-lang/git2-rs/pull/1079) -- Added bindings for `git_merge_base_octopus` - [#1088](https://github.com/rust-lang/git2-rs/pull/1088) - -### Changed - -- ❗ Updated to libgit2 [1.9.0](https://github.com/libgit2/libgit2/releases/tag/v1.9.0) - [#1111](https://github.com/rust-lang/git2-rs/pull/1111) -- ❗ Removed the `ssh_key_from_memory` Cargo feature, it was unused. - [#1087](https://github.com/rust-lang/git2-rs/pull/1087) - -## 0.17.0+1.8.1 - 2024-06-13 -[0.16.2...0.17.0](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.16.2+1.7.2...libgit2-sys-0.17.0+1.8.1) - -### Changed - -- ❗ Updated to libgit2 [1.8.1](https://github.com/libgit2/libgit2/releases/tag/v1.8.1) - [#1032](https://github.com/rust-lang/git2-rs/pull/1032) - -## 0.16.2+1.7.2 - 2024-02-06 -[0.16.1...0.16.2](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.16.1+1.7.1...libgit2-sys-0.16.2+1.7.2) - -### Added - -- Added binding for `git_commit_lookup_prefix`. - [#1011](https://github.com/rust-lang/git2-rs/pull/1011) -- Added binding for `git_object_lookup_prefix`. - [#1014](https://github.com/rust-lang/git2-rs/pull/1014) - -### Changed - -- ❗ Updated to libgit2 [1.7.2](https://github.com/libgit2/libgit2/releases/tag/v1.7.2). - This fixes [CVE-2024-24575](https://github.com/libgit2/libgit2/security/advisories/GHSA-54mf-x2rh-hq9v) and [CVE-2024-24577](https://github.com/libgit2/libgit2/security/advisories/GHSA-j2v7-4f6v-gpg8). - [#1017](https://github.com/rust-lang/git2-rs/pull/1017) - -## 0.16.1+1.7.1 - 2023-08-28 -[0.16.0...0.16.1](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.16.0+1.7.1...libgit2-sys-0.16.1+1.7.1) - -### Fixed - -- Fixed publish of 0.16.0 missing the libgit2 submodule. - -## 0.16.0+1.7.1 - 2023-08-28 -[0.15.2...0.16.0](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.15.2+1.6.4...libgit2-sys-0.16.0+1.7.1) - -### Added - -- Added LIBGIT2_NO_VENDOR environment variable to force using the system libgit2. - [#966](https://github.com/rust-lang/git2-rs/pull/966) -- Added binding for `git_blame_buffer`. - [#981](https://github.com/rust-lang/git2-rs/pull/981) - -### Changed - -- Updated to libgit2 [1.7.0](https://github.com/libgit2/libgit2/releases/tag/v1.7.0). - [#968](https://github.com/rust-lang/git2-rs/pull/968) -- Updated to libgit2 [1.7.1](https://github.com/libgit2/libgit2/releases/tag/v1.7.1). - [#982](https://github.com/rust-lang/git2-rs/pull/982) - -### Fixed - -- Fixed builds with cargo's `-Zminimal-versions`. - [#960](https://github.com/rust-lang/git2-rs/pull/960) - - -## 0.15.2+1.6.4 - 2023-05-27 -[0.15.1...0.15.2](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.15.1+1.6.4...libgit2-sys-0.15.2+1.6.4) - -### Added - -- Added bindings for stash options. - [#930](https://github.com/rust-lang/git2-rs/pull/930) - -## 0.15.1+1.6.4 - 2023-04-13 -[0.15.0...0.15.1](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.15.0+1.6.3...libgit2-sys-0.15.1+1.6.4) - -### Changed - -- Updated to libgit2 [1.6.4](https://github.com/libgit2/libgit2/releases/tag/v1.6.4). - This brings in a minor fix on Windows when the ProgramData directory does not exist. - [#948](https://github.com/rust-lang/git2-rs/pull/948) - -## 0.15.0+1.6.3 - 2023-04-02 -[0.14.2...0.15.0](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.14.2+1.5.1...libgit2-sys-0.15.0+1.6.3) - -### Added - -- Added bindings for `git_remote_name_is_valid`, `git_reference_name_is_valid`, and `git_tag_name_is_valid`. - [#882](https://github.com/rust-lang/git2-rs/pull/882) -- Added bindings for `git_indexer` support. - [#911](https://github.com/rust-lang/git2-rs/pull/911) -- Added bindings for `git_index_find_prefix`. - [#903](https://github.com/rust-lang/git2-rs/pull/903) -- Added support for the deprecated group-writeable blob file mode. - [#887](https://github.com/rust-lang/git2-rs/pull/887) - -### Changed - -- Updated libssh2-sys from 0.2 to 0.3. - This brings in numerous changes, including SHA2 algorithm support with RSA. - [#919](https://github.com/rust-lang/git2-rs/pull/919) -- Updated to libgit2 [1.6.3](https://github.com/libgit2/libgit2/blob/main/docs/changelog.md#v163). - This brings in many changes, including better SSH host key support on Windows and better SSH host key algorithm negotiation. - 1.6.3 is now the minimum supported version. - [#935](https://github.com/rust-lang/git2-rs/pull/935) -- The `GIT_DIFF_` constants have been changed to be a `git_diff_option_t` type. - [#935](https://github.com/rust-lang/git2-rs/pull/935) - -### Fixed - -- Fixed the rerun-if-changed build script support on Windows. This is only relevant for those working within the git2-rs source tree. - [#916](https://github.com/rust-lang/git2-rs/pull/916) - -## 0.14.2+1.5.1 - 2023-01-20 -[0.14.1...0.14.2](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.14.1+1.5.0...libgit2-sys-0.14.2+1.5.1) - -### Changed -- Updated the bundled libgit2 to [1.5.1](https://github.com/libgit2/libgit2/releases/tag/v1.5.1). - [a233483a3952d6112653be86fb5ce65267e3d5ac](https://github.com/rust-lang/git2-rs/commit/a233483a3952d6112653be86fb5ce65267e3d5ac) - - Changes: [fbea439d4b6fc91c6b619d01b85ab3b7746e4c19...42e5db98b963ae503229c63e44e06e439df50e56](https://github.com/libgit2/libgit2/compare/fbea439d4b6fc91c6b619d01b85ab3b7746e4c19...42e5db98b963ae503229c63e44e06e439df50e56): - - Fixes [GHSA-8643-3wh5-rmjq](https://github.com/libgit2/libgit2/security/advisories/GHSA-8643-3wh5-rmjq) to validate SSH host keys. - - The supported libgit2 system library range is 1.5.1 to less than 1.6.0 or 1.4.5 to less than 1.5.0, which should include this fix. - -## 0.13.5+1.4.5 - 2023-01-20 -[0.13.4...0.13.5](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.13.4+1.4.2...libgit2-sys-0.13.5+1.4.5) - -### Changed -- Updated the bundled libgit2 to [1.4.5](https://github.com/libgit2/libgit2/releases/tag/v1.4.5). - - Changes: [2a0d0bd19b5d13e2ab7f3780e094404828cbb9a7...cd6f679af401eda1f172402006ef8265f8bd58ea](https://github.com/libgit2/libgit2/compare/2a0d0bd19b5d13e2ab7f3780e094404828cbb9a7...cd6f679af401eda1f172402006ef8265f8bd58ea): - - Fixes [GHSA-8643-3wh5-rmjq](https://github.com/libgit2/libgit2/security/advisories/GHSA-8643-3wh5-rmjq) to validate SSH host keys. - - The supported libgit2 system library range is 1.4.5 to less than 1.5.0. - -## 0.14.1+1.5.0 - 2023-01-10 -[0.14.0...0.14.1](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.14.0+1.5.0...libgit2-sys-0.14.1+1.5.0) - -### Added -- Added variants to `git_cert_ssh_raw_type_t`. - [#909](https://github.com/rust-lang/git2-rs/pull/909) - -## 0.14.0+1.5.0 - 2022-07-28 -[0.13.4...0.14.0](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.13.4+1.4.2...libgit2-sys-0.14.0+1.5.0) - -### Added -- Added bindings for ownership validation. - [#839](https://github.com/rust-lang/git2-rs/pull/839) - -### Changed - -- Updated the bundled libgit2 to [1.5.0](https://github.com/libgit2/libgit2/releases/tag/v1.5.0). - [#839](https://github.com/rust-lang/git2-rs/pull/839) - [#858](https://github.com/rust-lang/git2-rs/pull/858) - - Changes: [2a0d0bd19b5d13e2ab7f3780e094404828cbb9a7...fbea439d4b6fc91c6b619d01b85ab3b7746e4c19](https://github.com/libgit2/libgit2/compare/2a0d0bd19b5d13e2ab7f3780e094404828cbb9a7...fbea439d4b6fc91c6b619d01b85ab3b7746e4c19): - - The supported libgit2 system library range is 1.4.4 to less than 1.6.0. - - Fixes [CVE 2022-24765](https://github.com/libgit2/libgit2/releases/tag/v1.4.3). - -## 0.13.4+1.4.2 - 2022-05-10 -[0.13.3...0.13.4](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.13.3+1.4.2...libgit2-sys-0.13.4+1.4.2) - -### Added -- Added bindings for `git_commit_body` - [#835](https://github.com/rust-lang/git2-rs/pull/835) - -## 0.13.3+1.4.2 - 2022-04-27 -[0.13.2...0.13.3](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.13.2+1.4.2...libgit2-sys-0.13.3+1.4.2) - -### Changed -- Updated the bundled libgit2 to 1.5.0-alpha. - [#822](https://github.com/rust-lang/git2-rs/pull/822) - - Changes: [182d0d1ee933de46bf0b5a6ec269bafa77aba9a2...2a0d0bd19b5d13e2ab7f3780e094404828cbb9a7](https://github.com/libgit2/libgit2/compare/182d0d1ee933de46bf0b5a6ec269bafa77aba9a2...2a0d0bd19b5d13e2ab7f3780e094404828cbb9a7) -- Changed the pkg-config probe to restrict linking against a version of a system-installed libgit2 to a version less than 1.5.0. - Previously it would allow any version above 1.4.0 which could pick up an API-breaking version. - [#817](https://github.com/rust-lang/git2-rs/pull/817) -- When using pkg-config to locate libgit2, the system lib dirs are no longer added to the search path. - [#831](https://github.com/rust-lang/git2-rs/pull/831) -- When using the `zlib-ng-compat` Cargo feature, `libssh2-sys` is no longer automatically included unless you also enable the `ssh` feature. - [#833](https://github.com/rust-lang/git2-rs/pull/833) - -## 0.13.2+1.4.2 - 2022-03-10 -[0.13.1...0.13.2](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.13.1+1.4.2...libgit2-sys-0.13.2+1.4.2) - -### Added -- Added bindings for `git_odb_exists_ext`. - [#818](https://github.com/rust-lang/git2-rs/pull/818) - -## 0.13.1+1.4.2 - 2022-02-28 -[0.13.0...0.13.1](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.13.0+1.4.1...libgit2-sys-0.13.1+1.4.2) - -### Changed -- Updated the bundled libgit2 to [1.4.2](https://github.com/libgit2/libgit2/releases/tag/v1.4.2). - [#815](https://github.com/rust-lang/git2-rs/pull/815) - - Changes: [fdd15bcfca6b2ec4b7ecad1aa11a396cb15bd064...182d0d1ee933de46bf0b5a6ec269bafa77aba9a2](https://github.com/libgit2/libgit2/compare/fdd15bcfca6b2ec4b7ecad1aa11a396cb15bd064...182d0d1ee933de46bf0b5a6ec269bafa77aba9a2). - -## 0.13.0+1.4.1 - 2022-02-24 -[0.12.26...0.13.0](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.12.26+1.3.0...libgit2-sys-0.13.0+1.4.1) - -### Changed -- Changed libgit2-sys to use the presence of the `src` directory instead of `.git` to determine if it has a git submodule that needs updating. - [#801](https://github.com/rust-lang/git2-rs/pull/801) -- Updated the bundled libgit2 to [1.4.1](https://github.com/libgit2/libgit2/releases/tag/v1.4.1) (see also [1.4.0](https://github.com/libgit2/libgit2/releases/tag/v1.4.0)) - [#806](https://github.com/rust-lang/git2-rs/pull/806) - [#811](https://github.com/rust-lang/git2-rs/pull/811) - - Changes: [b7bad55e4bb0a285b073ba5e02b01d3f522fc95d...fdd15bcfca6b2ec4b7ecad1aa11a396cb15bd064](https://github.com/libgit2/libgit2/compare/b7bad55e4bb0a285b073ba5e02b01d3f522fc95d...fdd15bcfca6b2ec4b7ecad1aa11a396cb15bd064) - - The supported libgit2 system library range is 1.4.0 or greater. diff --git a/vendor/libgit2-sys/Cargo.lock b/vendor/libgit2-sys/Cargo.lock deleted file mode 100644 index f91a6ee..0000000 --- a/vendor/libgit2-sys/Cargo.lock +++ /dev/null @@ -1,166 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - -[[package]] -name = "cc" -version = "1.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" -dependencies = [ - "jobserver", - "libc", - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" - -[[package]] -name = "cmake" -version = "0.1.54" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7caa3f9de89ddbe2c607f4101924c5abec803763ae9534e4f4d7d8f84aa81f0" -dependencies = [ - "cc", -] - -[[package]] -name = "getrandom" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasi", -] - -[[package]] -name = "jobserver" -version = "0.1.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" -dependencies = [ - "getrandom", - "libc", -] - -[[package]] -name = "libc" -version = "0.2.174" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" - -[[package]] -name = "libgit2-sys" -version = "0.18.8+1.9.7" -dependencies = [ - "cc", - "libc", - "libssh2-sys", - "libz-sys", - "openssl-sys", - "pkg-config", -] - -[[package]] -name = "libssh2-sys" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9" -dependencies = [ - "cc", - "libc", - "libz-sys", - "openssl-sys", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "libz-sys" -version = "1.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b70e7a7df205e92a1a4cd9aaae7898dac0aa555503cc0a649494d0d60e7651d" -dependencies = [ - "cc", - "cmake", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "openssl-src" -version = "300.5.0+3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8ce546f549326b0e6052b649198487d91320875da901e7bd11a06d1ee3f9c2f" -dependencies = [ - "cc", -] - -[[package]] -name = "openssl-sys" -version = "0.9.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571" -dependencies = [ - "cc", - "libc", - "openssl-src", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "pkg-config" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" - -[[package]] -name = "r-efi" -version = "5.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] -name = "wasi" -version = "0.14.2+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" -dependencies = [ - "wit-bindgen-rt", -] - -[[package]] -name = "wit-bindgen-rt" -version = "0.39.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" -dependencies = [ - "bitflags", -] diff --git a/vendor/libgit2-sys/Cargo.toml b/vendor/libgit2-sys/Cargo.toml deleted file mode 100644 index 8c39eb2..0000000 --- a/vendor/libgit2-sys/Cargo.toml +++ /dev/null @@ -1,75 +0,0 @@ -# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. -# -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. - -[package] -edition = "2021" -name = "libgit2-sys" -version = "0.18.8+1.9.7" -authors = [ - "Josh Triplett ", - "Alex Crichton ", -] -build = "build.rs" -links = "git2" -exclude = [ - "libgit2/ci/*", - "libgit2/docs/*", - "libgit2/examples/*", - "libgit2/fuzzers/*", - "libgit2/tests/*", -] -autolib = false -autobins = false -autoexamples = false -autotests = false -autobenches = false -description = "Native bindings to the libgit2 library" -readme = false -license = "MIT OR Apache-2.0" -repository = "https://github.com/rust-lang/git2-rs" - -[features] -https = ["openssl-sys"] -ssh = ["libssh2-sys"] -unstable-sha256 = [] -vendored = [] -vendored-openssl = ["openssl-sys/vendored"] -zlib-ng-compat = [ - "libz-sys/zlib-ng", - "libssh2-sys?/zlib-ng-compat", -] - -[lib] -name = "libgit2_sys" -path = "lib.rs" - -[dependencies.libc] -version = "0.2" - -[dependencies.libssh2-sys] -version = "0.3.0" -optional = true - -[dependencies.libz-sys] -version = "1.1.0" -features = ["libc"] -default-features = false - -[build-dependencies.cc] -version = "1.0.43" -features = ["parallel"] - -[build-dependencies.pkg-config] -version = "0.3.15" - -[target."cfg(unix)".dependencies.openssl-sys] -version = "0.9.45" -optional = true diff --git a/vendor/libgit2-sys/Cargo.toml.orig b/vendor/libgit2-sys/Cargo.toml.orig deleted file mode 100644 index 8db52d6..0000000 --- a/vendor/libgit2-sys/Cargo.toml.orig +++ /dev/null @@ -1,52 +0,0 @@ -[package] -name = "libgit2-sys" -version = "0.18.8+1.9.7" -authors = ["Josh Triplett ", "Alex Crichton "] -links = "git2" -build = "build.rs" -repository = "https://github.com/rust-lang/git2-rs" -license = "MIT OR Apache-2.0" -description = "Native bindings to the libgit2 library" -exclude = [ - "libgit2/ci/*", - "libgit2/docs/*", - "libgit2/examples/*", - "libgit2/fuzzers/*", - "libgit2/tests/*", -] -edition = "2021" - -[lib] -name = "libgit2_sys" -path = "lib.rs" - -[dependencies] -libc = "0.2" -libssh2-sys = { version = "0.3.0", optional = true } -libz-sys = { version = "1.1.0", default-features = false, features = ["libc"] } - -[build-dependencies] -pkg-config = "0.3.15" -cc = { version = "1.0.43", features = ['parallel'] } - -[target.'cfg(unix)'.dependencies] -openssl-sys = { version = "0.9.45", optional = true } - -[features] -ssh = ["libssh2-sys"] -https = ["openssl-sys"] -vendored = [] -vendored-openssl = ["openssl-sys/vendored"] -zlib-ng-compat = ["libz-sys/zlib-ng", "libssh2-sys?/zlib-ng-compat"] -# Experimental SHA256 OID support, -# reflecting upstream libgit2's GIT_EXPERIMENTAL_SHA256. -# -# This is an ABI-breaking change. -# Future releases with this feature may introduce breakages without notice -# Use at your own risk. -# -# Library authors: -# DO NOT enable this feature by default in your dependencies. -# Due to Cargo's additive features, -# downstream users cannot deactivate it once enabled. -unstable-sha256 = [] diff --git a/vendor/libgit2-sys/LICENSE-APACHE b/vendor/libgit2-sys/LICENSE-APACHE deleted file mode 100644 index 16fe87b..0000000 --- a/vendor/libgit2-sys/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/vendor/libgit2-sys/LICENSE-MIT b/vendor/libgit2-sys/LICENSE-MIT deleted file mode 100644 index 39e0ed6..0000000 --- a/vendor/libgit2-sys/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2014 Alex Crichton - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/vendor/libgit2-sys/NATIVE_DIFF_PATCH.md b/vendor/libgit2-sys/NATIVE_DIFF_PATCH.md deleted file mode 100644 index 603386f..0000000 --- a/vendor/libgit2-sys/NATIVE_DIFF_PATCH.md +++ /dev/null @@ -1,41 +0,0 @@ -# Local parser correction - -Base: the published `libgit2-sys` crate `0.18.8+1.9.7`, containing libgit2 1.9.7. -The original crate SHA-256 is -`7f7c568b25d7489bc3fb2988ed69ab111d2944d2f5fec3d5c987fe545ea97b50`. -Its VCS record identifies git2-rs commit -`6c93812dbc1c34aef6e6464a645545b4a4299807`. - -The complete published crate remains present. Only `build.rs` and -`libgit2/src/libgit2/patch_parse.c` differ from that crate, apart from this note. - -## Behavior - -Git rename and copy headers contain an unprefixed filename. Unquoted filenames -can contain leading, interior, and trailing spaces. The parser consumes these -names through the line ending without trimming filename whitespace. -Quoted names retain the existing token boundary and escape decoder. Extra data -after a quoted name remains an error. The temporary path buffer is released -on decoding failure. - -The common path helper retains its previous trimming behavior for other headers. -No patch bytes, source offsets, source records, or application rendering rules -change. The application enables `vendored-libgit2`. The build rejects a nonzero -`LIBGIT2_NO_VENDOR` override to prevent an unpatched system library from bypassing -the correction. - -The regression contracts generate real Git rename and copy patches. They check -exact safe-display names, status, supplied source bytes, line numbers, newline -markers, retained source export, both terminal layouts, and file navigation. -Malformed quoted names remain errors. - -## Source and notices - -- [Published crate](https://crates.io/crates/libgit2-sys/0.18.8+1.9.7) -- [Git patch format](https://git-scm.com/docs/diff-format) -- Bindings: `LICENSE-MIT` and `LICENSE-APACHE`, unchanged. -- libgit2: `libgit2/COPYING`, including its linking exception, unchanged. -- Bundled component notices remain in their original directories. - -The changed C file carries a dated modification notice. This local correction -does not change the license of the original components. diff --git a/vendor/libgit2-sys/build.rs b/vendor/libgit2-sys/build.rs deleted file mode 100644 index 1f63b11..0000000 --- a/vendor/libgit2-sys/build.rs +++ /dev/null @@ -1,395 +0,0 @@ -use std::env; -use std::fs; -use std::io; -use std::path::{Path, PathBuf}; -use std::process::Command; - -/// Tries to use system libgit2 and emits necessary build script instructions. -fn try_system_libgit2( - experimental_sha256: bool, -) -> Result> { - let mut cfg = pkg_config::Config::new(); - let range_version = "1.9.7".."1.10.0"; - - let lib = if experimental_sha256 { - // Determine whether experimental SHA256 object support is enabled. - // - // Given the SHA256 support is ABI-incompatible, - // we take a conservative approach here: - // - // 1. Only accept if the library name has the `-experimental` suffix - // 2. The experimental library must have an `experimental.h` header file - // containing an enabled `GIT_EXPERIMENTAL_SHA256` constant. - // - // See how libgit2 handles experimental features: - // https://github.com/libgit2/libgit2/blob/3ac4c0adb1064bad16a7f980d87e7261753fd07e/cmake/ExperimentalFeatures.cmake - match cfg - .range_version(range_version.clone()) - .probe("libgit2-experimental") - { - Ok(lib) => { - let sha256_constant_in_header = lib.include_paths.iter().any(|path| { - let header = path.join("git2/experimental.h"); - let contents = match std::fs::read_to_string(header) { - Ok(s) => s, - Err(_) => return false, - }; - if contents.contains("#cmakedefine") { - // still template - return false; - } - contents - .lines() - .any(|l| l.starts_with("#define GIT_EXPERIMENTAL_SHA256 1")) - }); - if sha256_constant_in_header { - println!("cargo:rustc-cfg=libgit2_experimental_sha256"); - lib - } else { - println!("cargo:warning=no GIT_EXPERIMENTAL_SHA256 constant in headers"); - return Err( - "GIT_EXPERIMENTAL_SHA256 wasn't enabled for libgit2-experimental library" - .into(), - ); - } - } - Err(e) => { - println!("cargo:warning=failed to probe system libgit2-experimental: {e}"); - return Err(e.into()); - } - } - } else { - match cfg.range_version(range_version).probe("libgit2") { - Ok(lib) => lib, - Err(e) => { - println!("cargo:warning=failed to probe system libgit2: {e}"); - return Err(e.into()); - } - } - }; - - for include in &lib.include_paths { - println!("cargo:root={}", include.display()); - } - Ok(lib) -} - -fn main() { - println!( - "cargo:rustc-check-cfg=cfg(\ - libgit2_vendored,\ - libgit2_experimental_sha256,\ - )" - ); - - let https = env::var("CARGO_FEATURE_HTTPS").is_ok(); - let ssh = env::var("CARGO_FEATURE_SSH").is_ok(); - let vendored = env::var("CARGO_FEATURE_VENDORED").is_ok(); - let zlib_ng_compat = env::var("CARGO_FEATURE_ZLIB_NG_COMPAT").is_ok(); - let unstable_sha256 = env::var("CARGO_FEATURE_UNSTABLE_SHA256").is_ok(); - - // A system library must not bypass the local parser correction. - println!("cargo:rerun-if-env-changed=LIBGIT2_NO_VENDOR"); - let forced_no_vendor = env::var_os("LIBGIT2_NO_VENDOR").map_or(false, |s| s != "0"); - - if forced_no_vendor { - panic!( - "native-diff requires its patched vendored libgit2. \ - Unset LIBGIT2_NO_VENDOR or set it to 0." - ); - } - - // To use zlib-ng in zlib-compat mode, we have to build libgit2 ourselves. - let try_to_use_system_libgit2 = !vendored && !zlib_ng_compat; - if try_to_use_system_libgit2 && try_system_libgit2(unstable_sha256).is_ok() { - // using system libgit2 has worked - return; - } - - println!("cargo:rustc-cfg=libgit2_vendored"); - - if !Path::new("libgit2/src").exists() { - let _ = Command::new("git") - .args(&["submodule", "update", "--init", "libgit2"]) - .status(); - } - - let target = env::var("TARGET").unwrap(); - let windows = target.contains("windows"); - let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap()); - let include = dst.join("include"); - let mut cfg = cc::Build::new(); - fs::create_dir_all(&include).unwrap(); - - // Copy over all header files - cp_r("libgit2/include", &include); - - cfg.include(&include) - .include("libgit2/src/libgit2") - .include("libgit2/src/util") - .out_dir(dst.join("build")) - .warnings(false); - - if unstable_sha256 { - println!("cargo:rustc-cfg=libgit2_experimental_sha256"); - cfg.define("GIT_EXPERIMENTAL_SHA256", "1"); - } - - // Include all cross-platform C files - add_c_files(&mut cfg, "libgit2/src/libgit2"); - add_c_files(&mut cfg, "libgit2/src/util"); - - // These are activated by features, but they're all unconditionally always - // compiled apparently and have internal #define's to make sure they're - // compiled correctly. - add_c_files(&mut cfg, "libgit2/src/libgit2/transports"); - add_c_files(&mut cfg, "libgit2/src/libgit2/streams"); - - // Always use bundled HTTP parser (llhttp) for now - cfg.include("libgit2/deps/llhttp"); - add_c_files(&mut cfg, "libgit2/deps/llhttp"); - - // external/system xdiff is not yet supported - cfg.include("libgit2/deps/xdiff"); - add_c_files(&mut cfg, "libgit2/deps/xdiff"); - - // Use the included PCRE2 regex backend. - // Keep these settings aligned with libgit2's bundled PCRE2 configuration. - cfg.define("GIT_REGEX_BUILTIN", "1") - .include("libgit2/deps/pcre2") - .define("PCRE2_STATIC", None) - .define("PCRE2_EXPORT", Some("")) - .define("PCRE2_EXP_DECL", Some("")) - .define("PCRE2_EXP_DEFN", Some("")) - .define("PCRE2_CODE_UNIT_WIDTH", Some("8")) - .define("SUPPORT_PCRE2_8", Some("1")) - .define("SUPPORT_UNICODE", Some("1")) - .define("LINK_SIZE", Some("2")) - .define("HEAP_LIMIT", Some("20000000")) - .define("MATCH_LIMIT", Some("10000000")) - .define("MATCH_LIMIT_DEPTH", Some("MATCH_LIMIT")) - .define("MAX_VARLOOKBEHIND", Some("255")) - .define("NEWLINE_DEFAULT", Some("2")) - .define("PARENS_NEST_LIMIT", Some("250")) - .define("MAX_NAME_SIZE", Some("128")) - .define("MAX_NAME_COUNT", Some("10000")); - add_pcre2_files(&mut cfg); - - cfg.file("libgit2/src/util/allocators/failalloc.c"); - cfg.file("libgit2/src/util/allocators/stdalloc.c"); - - if windows { - if target.contains("msvc") { - cfg.define("_CRT_SECURE_NO_DEPRECATE", None); - cfg.define("_CRT_SECURE_NO_WARNINGS", None); - } - add_c_files(&mut cfg, "libgit2/src/util/win32"); - cfg.define("STRSAFE_NO_DEPRECATE", None); - cfg.define("WIN32", None); - cfg.define("_WIN32_WINNT", Some("0x0600")); - - // libgit2's build system claims that forks like mingw-w64 of MinGW - // still want this define to use C99 stdio functions automatically. - // Apparently libgit2 breaks at runtime if this isn't here? Who knows! - if target.contains("gnu") { - cfg.define("__USE_MINGW_ANSI_STDIO", "1"); - } - } else { - add_c_files(&mut cfg, "libgit2/src/util/unix"); - cfg.flag("-fvisibility=hidden"); - } - if target.contains("solaris") || target.contains("illumos") { - cfg.define("_POSIX_C_SOURCE", "200112L"); - cfg.define("__EXTENSIONS__", None); - } - - let mut features = String::new(); - - features.push_str("#ifndef INCLUDE_features_h\n"); - features.push_str("#define INCLUDE_features_h\n"); - features.push_str("#define GIT_THREADS 1\n"); - features.push_str("#define GIT_TRACE 1\n"); - features.push_str("#define GIT_HTTPPARSER_BUILTIN 1\n"); - - if !target.contains("android") { - features.push_str("#define GIT_USE_NSEC 1\n"); - } - - if windows { - features.push_str("#define GIT_IO_WSAPOLL 1\n"); - } else { - // Should we fallback to `select` as more systems have that? - features.push_str("#define GIT_IO_POLL 1\n"); - features.push_str("#define GIT_IO_SELECT 1\n"); - } - - if target.contains("apple") { - features.push_str("#define GIT_USE_STAT_MTIMESPEC 1\n"); - } else { - features.push_str("#define GIT_USE_STAT_MTIM 1\n"); - } - - if env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32" { - features.push_str("#define GIT_ARCH_32 1\n"); - } else { - features.push_str("#define GIT_ARCH_64 1\n"); - } - - if ssh { - if let Some(path) = env::var_os("DEP_SSH2_INCLUDE") { - cfg.include(path); - } - features.push_str("#define GIT_SSH 1\n"); - features.push_str("#define GIT_SSH_LIBSSH2 1\n"); - features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n"); - } - if https { - features.push_str("#define GIT_HTTPS 1\n"); - - if windows { - features.push_str("#define GIT_WINHTTP 1\n"); - } else if target.contains("apple") { - features.push_str("#define GIT_SECURE_TRANSPORT 1\n"); - } else { - features.push_str("#define GIT_OPENSSL 1\n"); - if let Some(path) = env::var_os("DEP_OPENSSL_INCLUDE") { - cfg.include(path); - } - } - } - - // Use the CollisionDetection SHA1 implementation. - features.push_str("#define GIT_SHA1_COLLISIONDETECT 1\n"); - cfg.define("SHA1DC_NO_STANDARD_INCLUDES", "1"); - cfg.define("SHA1DC_CUSTOM_INCLUDE_SHA1_C", "\"common.h\""); - cfg.define("SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C", "\"common.h\""); - cfg.file("libgit2/src/util/hash/collisiondetect.c"); - cfg.file("libgit2/src/util/hash/sha1dc/sha1.c"); - cfg.file("libgit2/src/util/hash/sha1dc/ubc_check.c"); - - if https { - if windows { - features.push_str("#define GIT_SHA256_WIN32 1\n"); - cfg.file("libgit2/src/util/hash/win32.c"); - } else if target.contains("apple") { - features.push_str("#define GIT_SHA256_COMMON_CRYPTO 1\n"); - cfg.file("libgit2/src/util/hash/common_crypto.c"); - } else { - features.push_str("#define GIT_SHA256_OPENSSL 1\n"); - cfg.file("libgit2/src/util/hash/openssl.c"); - } - } else { - features.push_str("#define GIT_SHA256_BUILTIN 1\n"); - cfg.file("libgit2/src/util/hash/builtin.c"); - cfg.file("libgit2/src/util/hash/rfc6234/sha224-256.c"); - } - - if let Some(path) = env::var_os("DEP_Z_INCLUDE") { - cfg.include(path); - } - - if target.contains("apple") { - features.push_str("#define GIT_USE_ICONV 1\n"); - } - - features.push_str("#endif\n"); - fs::write(include.join("git2_features.h"), features).unwrap(); - - cfg.compile("git2"); - - println!("cargo:root={}", dst.display()); - - if target.contains("windows") { - println!("cargo:rustc-link-lib=winhttp"); - println!("cargo:rustc-link-lib=rpcrt4"); - println!("cargo:rustc-link-lib=ole32"); - println!("cargo:rustc-link-lib=crypt32"); - println!("cargo:rustc-link-lib=secur32"); - println!("cargo:rustc-link-lib=advapi32"); - } - - if target.contains("apple") { - println!("cargo:rustc-link-lib=iconv"); - println!("cargo:rustc-link-lib=framework=Security"); - println!("cargo:rustc-link-lib=framework=CoreFoundation"); - } - - println!("cargo:rerun-if-changed=libgit2/include"); - println!("cargo:rerun-if-changed=libgit2/src"); - println!("cargo:rerun-if-changed=libgit2/deps"); -} - -fn cp_r(from: impl AsRef, to: impl AsRef) { - for e in from.as_ref().read_dir().unwrap() { - let e = e.unwrap(); - let from = e.path(); - let to = to.as_ref().join(e.file_name()); - if e.file_type().unwrap().is_dir() { - fs::create_dir_all(&to).unwrap(); - cp_r(&from, &to); - } else { - println!("{} => {}", from.display(), to.display()); - fs::copy(&from, &to).unwrap(); - } - } -} - -fn add_c_files(build: &mut cc::Build, path: impl AsRef) { - let path = path.as_ref(); - if !path.exists() { - panic!("Path {} does not exist", path.display()); - } - // sort the C files to ensure a deterministic build for reproducible builds - let dir = path.read_dir().unwrap(); - let mut paths = dir.collect::>>().unwrap(); - paths.sort_by_key(|e| e.path()); - - for e in paths { - let path = e.path(); - if e.file_type().unwrap().is_dir() { - // skip dirs for now - } else if path.extension().and_then(|s| s.to_str()) == Some("c") { - build.file(&path); - } - } -} - -fn add_pcre2_files(build: &mut cc::Build) { - // Keep this list in sync with libgit2's PCRE2_SOURCES: - // https://github.com/libgit2/libgit2/blob/f7a4071c766ceea3915415e22134cbe3e581c420/deps/pcre2/CMakeLists.txt#L65-L96 - let root = Path::new("libgit2/deps/pcre2"); - for file in &[ - "pcre2_auto_possess.c", - "pcre2_chartables.c", - "pcre2_chkdint.c", - "pcre2_compile.c", - "pcre2_compile_cgroup.c", - "pcre2_compile_class.c", - "pcre2_config.c", - "pcre2_context.c", - "pcre2_convert.c", - "pcre2_dfa_match.c", - "pcre2_error.c", - "pcre2_extuni.c", - "pcre2_find_bracket.c", - "pcre2_maketables.c", - "pcre2_match.c", - "pcre2_match_data.c", - "pcre2_match_next.c", - "pcre2_newline.c", - "pcre2_ord2utf.c", - "pcre2_pattern_info.c", - "pcre2_script_run.c", - "pcre2_serialize.c", - "pcre2_string_utils.c", - "pcre2_study.c", - "pcre2_substitute.c", - "pcre2_substring.c", - "pcre2_tables.c", - "pcre2_ucd.c", - "pcre2_valid_utf.c", - "pcre2_xclass.c", - ] { - build.file(root.join(file)); - } -} diff --git a/vendor/libgit2-sys/lib.rs b/vendor/libgit2-sys/lib.rs deleted file mode 100644 index 73022c8..0000000 --- a/vendor/libgit2-sys/lib.rs +++ /dev/null @@ -1,4772 +0,0 @@ -#![doc(html_root_url = "https://docs.rs/libgit2-sys/0.18")] -#![allow(non_camel_case_types, unused_extern_crates)] - -// This is required to link libz when libssh2-sys is not included. -extern crate libz_sys as libz; - -use libc::{c_char, c_int, c_uchar, c_uint, c_ushort, c_void, size_t}; -#[cfg(feature = "ssh")] -use libssh2_sys as libssh2; -use std::ffi::CStr; - -#[cfg(not(feature = "unstable-sha256"))] -#[deprecated(note = "use `GIT_OID_SHA1_SIZE` instead")] -pub const GIT_OID_RAWSZ: usize = GIT_OID_SHA1_SIZE; -#[cfg(not(feature = "unstable-sha256"))] -#[deprecated(note = "use `GIT_OID_SHA1_HEXSIZE` instead")] -pub const GIT_OID_HEXSZ: usize = GIT_OID_SHA1_HEXSIZE; -pub const GIT_OID_SHA1_SIZE: usize = 20; -pub const GIT_OID_SHA1_HEXSIZE: usize = GIT_OID_SHA1_SIZE * 2; -#[cfg(feature = "unstable-sha256")] -pub const GIT_OID_SHA256_SIZE: usize = 32; -#[cfg(feature = "unstable-sha256")] -pub const GIT_OID_SHA256_HEXSIZE: usize = GIT_OID_SHA256_SIZE * 2; -#[cfg(not(feature = "unstable-sha256"))] -pub const GIT_OID_MAX_SIZE: usize = GIT_OID_SHA1_SIZE; -#[cfg(feature = "unstable-sha256")] -pub const GIT_OID_MAX_SIZE: usize = GIT_OID_SHA256_SIZE; -#[cfg(not(feature = "unstable-sha256"))] -pub const GIT_OID_MAX_HEXSIZE: usize = GIT_OID_SHA1_HEXSIZE; -#[cfg(feature = "unstable-sha256")] -pub const GIT_OID_MAX_HEXSIZE: usize = GIT_OID_SHA256_HEXSIZE; - -pub const GIT_CLONE_OPTIONS_VERSION: c_uint = 1; -pub const GIT_STASH_APPLY_OPTIONS_VERSION: c_uint = 1; -pub const GIT_CHECKOUT_OPTIONS_VERSION: c_uint = 1; -pub const GIT_MERGE_OPTIONS_VERSION: c_uint = 1; -pub const GIT_REMOTE_CALLBACKS_VERSION: c_uint = 1; -pub const GIT_STATUS_OPTIONS_VERSION: c_uint = 1; -pub const GIT_BLAME_OPTIONS_VERSION: c_uint = 1; -pub const GIT_PROXY_OPTIONS_VERSION: c_uint = 1; -pub const GIT_SUBMODULE_UPDATE_OPTIONS_VERSION: c_uint = 1; -pub const GIT_ODB_BACKEND_VERSION: c_uint = 1; -pub const GIT_REFDB_BACKEND_VERSION: c_uint = 1; -pub const GIT_CHERRYPICK_OPTIONS_VERSION: c_uint = 1; -pub const GIT_APPLY_OPTIONS_VERSION: c_uint = 1; -pub const GIT_REVERT_OPTIONS_VERSION: c_uint = 1; -pub const GIT_INDEXER_OPTIONS_VERSION: c_uint = 1; - -macro_rules! git_enum { - (pub enum $name:ident { $($variants:tt)* }) => { - #[cfg(target_env = "msvc")] - pub type $name = i32; - #[cfg(not(target_env = "msvc"))] - pub type $name = u32; - git_enum!(gen, $name, 0, $($variants)*); - }; - (pub enum $name:ident: $t:ty { $($variants:tt)* }) => { - pub type $name = $t; - git_enum!(gen, $name, 0, $($variants)*); - }; - (gen, $name:ident, $val:expr, #[$attr:meta] $variant:ident, $($rest:tt)*) => { - #[$attr] - pub const $variant: $name = $val; - git_enum!(gen, $name, $val+1, $($rest)*); - }; - (gen, $name:ident, $val:expr, #[$attr:meta] $variant:ident = $e:expr, $($rest:tt)*) => { - #[$attr] - pub const $variant: $name = $e; - git_enum!(gen, $name, $e+1, $($rest)*); - }; - (gen, $name:ident, $val:expr, $variant:ident, $($rest:tt)*) => { - pub const $variant: $name = $val; - git_enum!(gen, $name, $val+1, $($rest)*); - }; - (gen, $name:ident, $val:expr, $variant:ident = $e:expr, $($rest:tt)*) => { - pub const $variant: $name = $e; - git_enum!(gen, $name, $e+1, $($rest)*); - }; - (gen, $name:ident, $val:expr, ) => {} -} - -pub enum git_blob {} -pub enum git_branch_iterator {} -pub enum git_blame {} -pub enum git_commit {} -pub enum git_config {} - -#[repr(C)] -pub struct git_config_backend_entry { - pub entry: git_config_entry, - pub free: Option, -} - -#[repr(C)] -pub struct git_config_iterator { - pub backend: *mut git_config_backend, - pub flags: c_uint, - pub next: Option< - extern "C" fn(*mut *mut git_config_backend_entry, *mut git_config_iterator) -> c_int, - >, - pub free: Option, -} - -#[repr(C)] -pub struct git_config_backend { - pub version: c_uint, - pub readonly: c_int, - pub cfg: *mut git_config, - pub open: Option< - extern "C" fn(*mut git_config_backend, git_config_level_t, *const git_repository) -> c_int, - >, - pub get: Option< - extern "C" fn( - *mut git_config_backend, - *const c_char, - *mut *mut git_config_backend_entry, - ) -> c_int, - >, - pub set: Option c_int>, - pub set_multivar: Option< - extern "C" fn( - *mut git_config_backend, - *const c_char, - *const c_char, - *const c_char, - ) -> c_int, - >, - pub del: Option c_int>, - pub del_multivar: - Option c_int>, - pub iterator: - Option c_int>, - pub snapshot: - Option c_int>, - pub lock: Option c_int>, - pub unlock: Option c_int>, - pub free: Option, -} - -pub const GIT_CONFIG_BACKEND_VERSION: c_uint = 1; - -pub enum git_index {} -pub enum git_index_conflict_iterator {} -pub enum git_object {} -pub enum git_reference {} - -#[repr(C)] -pub struct git_reference_iterator { - pub db: *mut git_refdb, - pub next: Option c_int>, - pub next_name: Option c_int>, - pub free: Option, -} - -pub enum git_annotated_commit {} -pub enum git_refdb {} -pub enum git_refspec {} -pub enum git_remote {} -pub enum git_repository {} -pub enum git_revwalk {} -pub enum git_submodule {} -pub enum git_tag {} -pub enum git_tree {} -pub enum git_tree_entry {} -pub enum git_treebuilder {} -pub enum git_push {} -pub enum git_note {} -pub enum git_note_iterator {} -pub enum git_status_list {} -pub enum git_pathspec {} -pub enum git_pathspec_match_list {} -pub enum git_diff {} -pub enum git_diff_stats {} -pub enum git_patch {} -pub enum git_rebase {} -pub enum git_reflog {} -pub enum git_reflog_entry {} -pub enum git_describe_result {} -pub enum git_packbuilder {} -pub enum git_odb {} - -#[repr(C)] -pub struct git_odb_stream { - pub backend: *mut git_odb_backend, - pub mode: c_uint, - pub hash_ctx: *mut c_void, - #[cfg(feature = "unstable-sha256")] - pub oid_type: git_oid_t, - pub declared_size: git_object_size_t, - pub received_bytes: git_object_size_t, - pub read: Option c_int>, - pub write: Option c_int>, - pub finalize_write: Option c_int>, - pub free: Option, -} - -git_enum! { - pub enum git_odb_stream_t { - GIT_STREAM_RDONLY = 2, - GIT_STREAM_WRONLY = 4, - GIT_STREAM_RW = 6, - } -} - -pub enum git_odb_object {} -pub enum git_worktree {} -pub enum git_transaction {} -pub enum git_mailmap {} -pub enum git_indexer {} - -#[repr(C)] -pub struct git_revspec { - pub from: *mut git_object, - pub to: *mut git_object, - pub flags: c_uint, -} - -#[repr(C)] -pub struct git_error { - pub message: *mut c_char, - pub klass: c_int, -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct git_oid { - #[cfg(feature = "unstable-sha256")] - pub kind: c_uchar, - pub id: [u8; GIT_OID_MAX_SIZE], -} - -#[repr(C)] -#[derive(Copy)] -pub struct git_strarray { - pub strings: *mut *mut c_char, - pub count: size_t, -} -impl Clone for git_strarray { - fn clone(&self) -> git_strarray { - *self - } -} - -#[repr(C)] -#[derive(Copy)] -pub struct git_oidarray { - pub ids: *mut git_oid, - pub count: size_t, -} -impl Clone for git_oidarray { - fn clone(&self) -> git_oidarray { - *self - } -} - -#[repr(C)] -pub struct git_signature { - pub name: *mut c_char, - pub email: *mut c_char, - pub when: git_time, -} - -#[repr(C)] -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct git_time { - pub time: git_time_t, - pub offset: c_int, - pub sign: c_char, -} - -pub type git_off_t = i64; -pub type git_time_t = i64; -pub type git_object_size_t = u64; - -git_enum! { - pub enum git_revparse_mode_t { - GIT_REVPARSE_SINGLE = 1 << 0, - GIT_REVPARSE_RANGE = 1 << 1, - GIT_REVPARSE_MERGE_BASE = 1 << 2, - } -} - -git_enum! { - pub enum git_error_code: c_int { - GIT_OK = 0, - - GIT_ERROR = -1, - GIT_ENOTFOUND = -3, - GIT_EEXISTS = -4, - GIT_EAMBIGUOUS = -5, - GIT_EBUFS = -6, - GIT_EUSER = -7, - GIT_EBAREREPO = -8, - GIT_EUNBORNBRANCH = -9, - GIT_EUNMERGED = -10, - GIT_ENONFASTFORWARD = -11, - GIT_EINVALIDSPEC = -12, - GIT_ECONFLICT = -13, - GIT_ELOCKED = -14, - GIT_EMODIFIED = -15, - GIT_EAUTH = -16, - GIT_ECERTIFICATE = -17, - GIT_EAPPLIED = -18, - GIT_EPEEL = -19, - GIT_EEOF = -20, - GIT_EINVALID = -21, - GIT_EUNCOMMITTED = -22, - GIT_EDIRECTORY = -23, - GIT_EMERGECONFLICT = -24, - GIT_PASSTHROUGH = -30, - GIT_ITEROVER = -31, - GIT_RETRY = -32, - GIT_EMISMATCH = -33, - GIT_EINDEXDIRTY = -34, - GIT_EAPPLYFAIL = -35, - GIT_EOWNER = -36, - GIT_TIMEOUT = -37, - GIT_EUNCHANGED = -38, - GIT_ENOTSUPPORTED = -39, - GIT_EREADONLY = -40, - } -} - -git_enum! { - pub enum git_error_t { - GIT_ERROR_NONE = 0, - GIT_ERROR_NOMEMORY, - GIT_ERROR_OS, - GIT_ERROR_INVALID, - GIT_ERROR_REFERENCE, - GIT_ERROR_ZLIB, - GIT_ERROR_REPOSITORY, - GIT_ERROR_CONFIG, - GIT_ERROR_REGEX, - GIT_ERROR_ODB, - GIT_ERROR_INDEX, - GIT_ERROR_OBJECT, - GIT_ERROR_NET, - GIT_ERROR_TAG, - GIT_ERROR_TREE, - GIT_ERROR_INDEXER, - GIT_ERROR_SSL, - GIT_ERROR_SUBMODULE, - GIT_ERROR_THREAD, - GIT_ERROR_STASH, - GIT_ERROR_CHECKOUT, - GIT_ERROR_FETCHHEAD, - GIT_ERROR_MERGE, - GIT_ERROR_SSH, - GIT_ERROR_FILTER, - GIT_ERROR_REVERT, - GIT_ERROR_CALLBACK, - GIT_ERROR_CHERRYPICK, - GIT_ERROR_DESCRIBE, - GIT_ERROR_REBASE, - GIT_ERROR_FILESYSTEM, - GIT_ERROR_PATCH, - GIT_ERROR_WORKTREE, - GIT_ERROR_SHA1, - GIT_ERROR_HTTP, - } -} - -git_enum! { - pub enum git_repository_state_t { - GIT_REPOSITORY_STATE_NONE, - GIT_REPOSITORY_STATE_MERGE, - GIT_REPOSITORY_STATE_REVERT, - GIT_REPOSITORY_STATE_REVERT_SEQUENCE, - GIT_REPOSITORY_STATE_CHERRYPICK, - GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE, - GIT_REPOSITORY_STATE_BISECT, - GIT_REPOSITORY_STATE_REBASE, - GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, - GIT_REPOSITORY_STATE_REBASE_MERGE, - GIT_REPOSITORY_STATE_APPLY_MAILBOX, - GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE, - } -} - -git_enum! { - pub enum git_direction { - GIT_DIRECTION_FETCH, - GIT_DIRECTION_PUSH, - } -} - -#[repr(C)] -pub struct git_clone_options { - pub version: c_uint, - pub checkout_opts: git_checkout_options, - pub fetch_opts: git_fetch_options, - pub bare: c_int, - pub local: git_clone_local_t, - pub checkout_branch: *const c_char, - pub repository_cb: git_repository_create_cb, - pub repository_cb_payload: *mut c_void, - pub remote_cb: git_remote_create_cb, - pub remote_cb_payload: *mut c_void, -} - -git_enum! { - pub enum git_clone_local_t { - GIT_CLONE_LOCAL_AUTO, - GIT_CLONE_LOCAL, - GIT_CLONE_NO_LOCAL, - GIT_CLONE_LOCAL_NO_LINKS, - } -} - -#[repr(C)] -pub struct git_checkout_options { - pub version: c_uint, - pub checkout_strategy: c_uint, - pub disable_filters: c_int, - pub dir_mode: c_uint, - pub file_mode: c_uint, - pub file_open_flags: c_int, - pub notify_flags: c_uint, - pub notify_cb: git_checkout_notify_cb, - pub notify_payload: *mut c_void, - pub progress_cb: git_checkout_progress_cb, - pub progress_payload: *mut c_void, - pub paths: git_strarray, - pub baseline: *mut git_tree, - pub baseline_index: *mut git_index, - pub target_directory: *const c_char, - pub ancestor_label: *const c_char, - pub our_label: *const c_char, - pub their_label: *const c_char, - pub perfdata_cb: git_checkout_perfdata_cb, - pub perfdata_payload: *mut c_void, -} - -pub type git_checkout_notify_cb = Option< - extern "C" fn( - git_checkout_notify_t, - *const c_char, - *const git_diff_file, - *const git_diff_file, - *const git_diff_file, - *mut c_void, - ) -> c_int, ->; -pub type git_checkout_progress_cb = - Option; - -pub type git_checkout_perfdata_cb = - Option; - -#[repr(C)] -pub struct git_checkout_perfdata { - pub mkdir_calls: size_t, - pub stat_calls: size_t, - pub chmod_calls: size_t, -} - -#[repr(C)] -#[derive(Copy, Clone, Default)] -pub struct git_indexer_progress { - pub total_objects: c_uint, - pub indexed_objects: c_uint, - pub received_objects: c_uint, - pub local_objects: c_uint, - pub total_deltas: c_uint, - pub indexed_deltas: c_uint, - pub received_bytes: size_t, -} - -pub type git_indexer_progress_cb = - Option c_int>; - -#[deprecated( - since = "0.10.0", - note = "renamed to `git_indexer_progress` to match upstream" -)] -pub type git_transfer_progress = git_indexer_progress; - -#[repr(C)] -pub struct git_indexer_options { - pub version: c_uint, - #[cfg(feature = "unstable-sha256")] - pub mode: c_uint, - #[cfg(feature = "unstable-sha256")] - pub oid_type: git_oid_t, - #[cfg(feature = "unstable-sha256")] - pub odb: *mut git_odb, - pub progress_cb: git_indexer_progress_cb, - pub progress_cb_payload: *mut c_void, - pub verify: c_uchar, -} - -pub type git_remote_ready_cb = Option c_int>; - -git_enum! { - pub enum git_remote_update_flags { - GIT_REMOTE_UPDATE_FETCHHEAD = 1 << 0, - GIT_REMOTE_UPDATE_REPORT_UNCHANGED = 1 << 1, - } -} - -#[repr(C)] -pub struct git_remote_callbacks { - pub version: c_uint, - pub sideband_progress: git_transport_message_cb, - pub completion: Option c_int>, - pub credentials: git_cred_acquire_cb, - pub certificate_check: git_transport_certificate_check_cb, - pub transfer_progress: git_indexer_progress_cb, - pub update_tips: - Option c_int>, - pub pack_progress: git_packbuilder_progress, - pub push_transfer_progress: git_push_transfer_progress, - pub push_update_reference: git_push_update_reference_cb, - pub push_negotiation: git_push_negotiation, - pub transport: git_transport_cb, - pub remote_ready: git_remote_ready_cb, - pub payload: *mut c_void, - pub resolve_url: git_url_resolve_cb, - pub update_refs: Option< - extern "C" fn( - *const c_char, - *const git_oid, - *const git_oid, - *mut git_refspec, - *mut c_void, - ) -> c_int, - >, -} - -#[repr(C)] -pub struct git_fetch_options { - pub version: c_int, - pub callbacks: git_remote_callbacks, - pub prune: git_fetch_prune_t, - pub update_fetchhead: c_uint, - pub download_tags: git_remote_autotag_option_t, - pub proxy_opts: git_proxy_options, - pub depth: c_int, - pub follow_redirects: git_remote_redirect_t, - pub custom_headers: git_strarray, -} - -#[repr(C)] -pub struct git_fetch_negotiation { - refs: *const *const git_remote_head, - refs_len: size_t, - shallow_roots: *mut git_oid, - shallow_roots_len: size_t, - depth: c_int, -} - -git_enum! { - pub enum git_remote_autotag_option_t { - GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, - GIT_REMOTE_DOWNLOAD_TAGS_AUTO, - GIT_REMOTE_DOWNLOAD_TAGS_NONE, - GIT_REMOTE_DOWNLOAD_TAGS_ALL, - } -} - -git_enum! { - pub enum git_fetch_prune_t { - GIT_FETCH_PRUNE_UNSPECIFIED, - GIT_FETCH_PRUNE, - GIT_FETCH_NO_PRUNE, - } -} - -git_enum! { - pub enum git_remote_completion_type { - GIT_REMOTE_COMPLETION_DOWNLOAD, - GIT_REMOTE_COMPLETION_INDEXING, - GIT_REMOTE_COMPLETION_ERROR, - } -} - -pub type git_transport_message_cb = - Option c_int>; -pub type git_cred_acquire_cb = Option< - extern "C" fn(*mut *mut git_cred, *const c_char, *const c_char, c_uint, *mut c_void) -> c_int, ->; -pub type git_transfer_progress_cb = - Option c_int>; -pub type git_packbuilder_progress = - Option c_int>; -pub type git_push_transfer_progress = - Option c_int>; -pub type git_transport_certificate_check_cb = - Option c_int>; -pub type git_push_negotiation = - Option c_int>; - -pub type git_push_update_reference_cb = - Option c_int>; -pub type git_url_resolve_cb = - Option c_int>; - -#[repr(C)] -pub struct git_push_update { - pub src_refname: *mut c_char, - pub dst_refname: *mut c_char, - pub src: git_oid, - pub dst: git_oid, -} - -git_enum! { - pub enum git_cert_t { - GIT_CERT_NONE, - GIT_CERT_X509, - GIT_CERT_HOSTKEY_LIBSSH2, - GIT_CERT_STRARRAY, - } -} - -#[repr(C)] -pub struct git_cert { - pub cert_type: git_cert_t, -} - -#[repr(C)] -pub struct git_cert_hostkey { - pub parent: git_cert, - pub kind: git_cert_ssh_t, - pub hash_md5: [u8; 16], - pub hash_sha1: [u8; 20], - pub hash_sha256: [u8; 32], - pub raw_type: git_cert_ssh_raw_type_t, - pub hostkey: *const c_char, - pub hostkey_len: size_t, -} - -#[repr(C)] -pub struct git_cert_x509 { - pub parent: git_cert, - pub data: *mut c_void, - pub len: size_t, -} - -git_enum! { - pub enum git_cert_ssh_t { - GIT_CERT_SSH_MD5 = 1 << 0, - GIT_CERT_SSH_SHA1 = 1 << 1, - GIT_CERT_SSH_SHA256 = 1 << 2, - GIT_CERT_SSH_RAW = 1 << 3, - } -} - -git_enum! { - pub enum git_cert_ssh_raw_type_t { - GIT_CERT_SSH_RAW_TYPE_UNKNOWN = 0, - GIT_CERT_SSH_RAW_TYPE_RSA = 1, - GIT_CERT_SSH_RAW_TYPE_DSS = 2, - GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_256 = 3, - GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_384 = 4, - GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_521 = 5, - GIT_CERT_SSH_RAW_TYPE_KEY_ED25519 = 6, - } -} - -git_enum! { - pub enum git_diff_flag_t { - GIT_DIFF_FLAG_BINARY = 1 << 0, - GIT_DIFF_FLAG_NOT_BINARY = 1 << 1, - GIT_DIFF_FLAG_VALID_ID = 1 << 2, - GIT_DIFF_FLAG_EXISTS = 1 << 3, - } -} - -#[repr(C)] -pub struct git_diff_file { - pub id: git_oid, - pub path: *const c_char, - pub size: git_object_size_t, - pub flags: u32, - pub mode: u16, - pub id_abbrev: u16, -} - -pub type git_repository_create_cb = - Option c_int>; -pub type git_remote_create_cb = Option< - extern "C" fn( - *mut *mut git_remote, - *mut git_repository, - *const c_char, - *const c_char, - *mut c_void, - ) -> c_int, ->; - -git_enum! { - pub enum git_checkout_notify_t { - GIT_CHECKOUT_NOTIFY_NONE = 0, - GIT_CHECKOUT_NOTIFY_CONFLICT = 1 << 0, - GIT_CHECKOUT_NOTIFY_DIRTY = 1 << 1, - GIT_CHECKOUT_NOTIFY_UPDATED = 1 << 2, - GIT_CHECKOUT_NOTIFY_UNTRACKED = 1 << 3, - GIT_CHECKOUT_NOTIFY_IGNORED = 1 << 4, - - GIT_CHECKOUT_NOTIFY_ALL = 0x0FFFF, - } -} - -git_enum! { - pub enum git_status_t { - GIT_STATUS_CURRENT = 0, - - GIT_STATUS_INDEX_NEW = 1 << 0, - GIT_STATUS_INDEX_MODIFIED = 1 << 1, - GIT_STATUS_INDEX_DELETED = 1 << 2, - GIT_STATUS_INDEX_RENAMED = 1 << 3, - GIT_STATUS_INDEX_TYPECHANGE = 1 << 4, - - GIT_STATUS_WT_NEW = 1 << 7, - GIT_STATUS_WT_MODIFIED = 1 << 8, - GIT_STATUS_WT_DELETED = 1 << 9, - GIT_STATUS_WT_TYPECHANGE = 1 << 10, - GIT_STATUS_WT_RENAMED = 1 << 11, - GIT_STATUS_WT_UNREADABLE = 1 << 12, - - GIT_STATUS_IGNORED = 1 << 14, - GIT_STATUS_CONFLICTED = 1 << 15, - } -} - -git_enum! { - pub enum git_status_opt_t { - GIT_STATUS_OPT_INCLUDE_UNTRACKED = 1 << 0, - GIT_STATUS_OPT_INCLUDE_IGNORED = 1 << 1, - GIT_STATUS_OPT_INCLUDE_UNMODIFIED = 1 << 2, - GIT_STATUS_OPT_EXCLUDE_SUBMODULES = 1 << 3, - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = 1 << 4, - GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH = 1 << 5, - GIT_STATUS_OPT_RECURSE_IGNORED_DIRS = 1 << 6, - GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX = 1 << 7, - GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR = 1 << 8, - GIT_STATUS_OPT_SORT_CASE_SENSITIVELY = 1 << 9, - GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY = 1 << 10, - - GIT_STATUS_OPT_RENAMES_FROM_REWRITES = 1 << 11, - GIT_STATUS_OPT_NO_REFRESH = 1 << 12, - GIT_STATUS_OPT_UPDATE_INDEX = 1 << 13, - GIT_STATUS_OPT_INCLUDE_UNREADABLE = 1 << 14, - GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = 1 << 15, - } -} - -git_enum! { - pub enum git_status_show_t { - GIT_STATUS_SHOW_INDEX_AND_WORKDIR = 0, - GIT_STATUS_SHOW_INDEX_ONLY = 1, - GIT_STATUS_SHOW_WORKDIR_ONLY = 2, - } -} - -git_enum! { - pub enum git_delta_t { - GIT_DELTA_UNMODIFIED, - GIT_DELTA_ADDED, - GIT_DELTA_DELETED, - GIT_DELTA_MODIFIED, - GIT_DELTA_RENAMED, - GIT_DELTA_COPIED, - GIT_DELTA_IGNORED, - GIT_DELTA_UNTRACKED, - GIT_DELTA_TYPECHANGE, - GIT_DELTA_UNREADABLE, - GIT_DELTA_CONFLICTED, - } -} - -#[repr(C)] -pub struct git_status_options { - pub version: c_uint, - pub show: git_status_show_t, - pub flags: c_uint, - pub pathspec: git_strarray, - pub baseline: *mut git_tree, - pub rename_threshold: u16, -} - -#[repr(C)] -pub struct git_diff_delta { - pub status: git_delta_t, - pub flags: u32, - pub similarity: u16, - pub nfiles: u16, - pub old_file: git_diff_file, - pub new_file: git_diff_file, -} - -#[repr(C)] -pub struct git_status_entry { - pub status: git_status_t, - pub head_to_index: *mut git_diff_delta, - pub index_to_workdir: *mut git_diff_delta, -} - -git_enum! { - pub enum git_checkout_strategy_t { - GIT_CHECKOUT_SAFE = 0, - GIT_CHECKOUT_FORCE = 1 << 1, - GIT_CHECKOUT_RECREATE_MISSING = 1 << 2, - GIT_CHECKOUT_ALLOW_CONFLICTS = 1 << 4, - GIT_CHECKOUT_REMOVE_UNTRACKED = 1 << 5, - GIT_CHECKOUT_REMOVE_IGNORED = 1 << 6, - GIT_CHECKOUT_UPDATE_ONLY = 1 << 7, - GIT_CHECKOUT_DONT_UPDATE_INDEX = 1 << 8, - GIT_CHECKOUT_NO_REFRESH = 1 << 9, - GIT_CHECKOUT_SKIP_UNMERGED = 1 << 10, - GIT_CHECKOUT_USE_OURS = 1 << 11, - GIT_CHECKOUT_USE_THEIRS = 1 << 12, - GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH = 1 << 13, - GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES = 1 << 18, - GIT_CHECKOUT_DONT_OVERWRITE_IGNORED = 1 << 19, - GIT_CHECKOUT_CONFLICT_STYLE_MERGE = 1 << 20, - GIT_CHECKOUT_CONFLICT_STYLE_DIFF3 = 1 << 21, - GIT_CHECKOUT_NONE = 1 << 30, - - GIT_CHECKOUT_UPDATE_SUBMODULES = 1 << 16, - GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = 1 << 17, - } -} - -git_enum! { - pub enum git_reset_t { - GIT_RESET_SOFT = 1, - GIT_RESET_MIXED = 2, - GIT_RESET_HARD = 3, - } -} - -git_enum! { - pub enum git_object_t: c_int { - GIT_OBJECT_ANY = -2, - GIT_OBJECT_INVALID = -1, - GIT_OBJECT_COMMIT = 1, - GIT_OBJECT_TREE = 2, - GIT_OBJECT_BLOB = 3, - GIT_OBJECT_TAG = 4, - GIT_OBJECT_OFS_DELTA = 6, - GIT_OBJECT_REF_DELTA = 7, - } -} - -git_enum! { - pub enum git_reference_t { - GIT_REFERENCE_INVALID = 0, - GIT_REFERENCE_DIRECT = 1, - GIT_REFERENCE_SYMBOLIC = 2, - GIT_REFERENCE_ALL = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC, - } -} - -git_enum! { - pub enum git_filemode_t { - GIT_FILEMODE_UNREADABLE = 0o000000, - GIT_FILEMODE_TREE = 0o040000, - GIT_FILEMODE_BLOB = 0o100644, - GIT_FILEMODE_BLOB_GROUP_WRITABLE = 0o100664, - GIT_FILEMODE_BLOB_EXECUTABLE = 0o100755, - GIT_FILEMODE_LINK = 0o120000, - GIT_FILEMODE_COMMIT = 0o160000, - } -} - -git_enum! { - pub enum git_treewalk_mode { - GIT_TREEWALK_PRE = 0, - GIT_TREEWALK_POST = 1, - } -} - -pub type git_treewalk_cb = - extern "C" fn(*const c_char, *const git_tree_entry, *mut c_void) -> c_int; -pub type git_treebuilder_filter_cb = - Option c_int>; - -pub type git_revwalk_hide_cb = Option c_int>; - -git_enum! { - pub enum git_tree_update_t { - GIT_TREE_UPDATE_UPSERT = 0, - GIT_TREE_UPDATE_REMOVE = 1, - } -} - -#[repr(C)] -pub struct git_tree_update { - pub action: git_tree_update_t, - pub id: git_oid, - pub filemode: git_filemode_t, - pub path: *const c_char, -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct git_buf { - pub ptr: *mut c_char, - pub reserved: size_t, - pub size: size_t, -} - -git_enum! { - pub enum git_branch_t { - GIT_BRANCH_LOCAL = 1, - GIT_BRANCH_REMOTE = 2, - GIT_BRANCH_ALL = GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, - } -} - -pub const GIT_BLAME_NORMAL: u32 = 0; -pub const GIT_BLAME_TRACK_COPIES_SAME_FILE: u32 = 1 << 0; -pub const GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES: u32 = 1 << 1; -pub const GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES: u32 = 1 << 2; -pub const GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES: u32 = 1 << 3; -pub const GIT_BLAME_FIRST_PARENT: u32 = 1 << 4; -pub const GIT_BLAME_USE_MAILMAP: u32 = 1 << 5; -pub const GIT_BLAME_IGNORE_WHITESPACE: u32 = 1 << 6; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct git_blame_options { - pub version: c_uint, - - pub flags: u32, - pub min_match_characters: u16, - pub newest_commit: git_oid, - pub oldest_commit: git_oid, - pub min_line: usize, - pub max_line: usize, -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct git_blame_hunk { - pub lines_in_hunk: usize, - pub final_commit_id: git_oid, - pub final_start_line_number: usize, - pub final_signature: *mut git_signature, - pub final_committer: *mut git_signature, - pub orig_commit_id: git_oid, - pub orig_path: *const c_char, - pub orig_start_line_number: usize, - pub orig_signature: *mut git_signature, - pub orig_committer: *mut git_signature, - pub summary: *const c_char, - pub boundary: c_char, -} - -pub type git_index_matched_path_cb = - Option c_int>; - -git_enum! { - pub enum git_index_entry_extended_flag_t { - GIT_INDEX_ENTRY_INTENT_TO_ADD = 1 << 13, - GIT_INDEX_ENTRY_SKIP_WORKTREE = 1 << 14, - - GIT_INDEX_ENTRY_UPTODATE = 1 << 2, - } -} - -git_enum! { - pub enum git_index_entry_flag_t { - GIT_INDEX_ENTRY_EXTENDED = 0x4000, - GIT_INDEX_ENTRY_VALID = 0x8000, - } -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct git_index_entry { - pub ctime: git_index_time, - pub mtime: git_index_time, - pub dev: u32, - pub ino: u32, - pub mode: u32, - pub uid: u32, - pub gid: u32, - pub file_size: u32, - pub id: git_oid, - pub flags: u16, - pub flags_extended: u16, - pub path: *const c_char, -} - -pub const GIT_INDEX_ENTRY_NAMEMASK: u16 = 0xfff; -pub const GIT_INDEX_ENTRY_STAGEMASK: u16 = 0x3000; -pub const GIT_INDEX_ENTRY_STAGESHIFT: u16 = 12; - -#[repr(C)] -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct git_index_time { - pub seconds: i32, - pub nanoseconds: u32, -} - -#[repr(C)] -pub struct git_config_entry { - pub name: *const c_char, - pub value: *const c_char, - pub backend_type: *const c_char, - pub origin_path: *const c_char, - pub include_depth: c_uint, - pub level: git_config_level_t, -} - -git_enum! { - pub enum git_config_level_t: c_int { - GIT_CONFIG_LEVEL_PROGRAMDATA = 1, - GIT_CONFIG_LEVEL_SYSTEM = 2, - GIT_CONFIG_LEVEL_XDG = 3, - GIT_CONFIG_LEVEL_GLOBAL = 4, - GIT_CONFIG_LEVEL_LOCAL = 5, - GIT_CONFIG_LEVEL_WORKTREE = 6, - GIT_CONFIG_LEVEL_APP = 7, - GIT_CONFIG_HIGHEST_LEVEL = -1, - } -} - -git_enum! { - pub enum git_submodule_update_t { - GIT_SUBMODULE_UPDATE_CHECKOUT = 1, - GIT_SUBMODULE_UPDATE_REBASE = 2, - GIT_SUBMODULE_UPDATE_MERGE = 3, - GIT_SUBMODULE_UPDATE_NONE = 4, - GIT_SUBMODULE_UPDATE_DEFAULT = 0, - } -} - -git_enum! { - pub enum git_submodule_ignore_t: c_int { - GIT_SUBMODULE_IGNORE_UNSPECIFIED = -1, - - GIT_SUBMODULE_IGNORE_NONE = 1, - GIT_SUBMODULE_IGNORE_UNTRACKED = 2, - GIT_SUBMODULE_IGNORE_DIRTY = 3, - GIT_SUBMODULE_IGNORE_ALL = 4, - } -} - -pub type git_submodule_cb = - Option c_int>; - -#[repr(C)] -pub struct git_submodule_update_options { - pub version: c_uint, - pub checkout_opts: git_checkout_options, - pub fetch_opts: git_fetch_options, - pub allow_fetch: c_int, -} - -#[repr(C)] -pub struct git_writestream { - pub write: Option c_int>, - pub close: Option c_int>, - pub free: Option, -} - -git_enum! { - pub enum git_attr_value_t { - GIT_ATTR_VALUE_UNSPECIFIED = 0, - GIT_ATTR_VALUE_TRUE, - GIT_ATTR_VALUE_FALSE, - GIT_ATTR_VALUE_STRING, - } -} - -pub const GIT_ATTR_CHECK_FILE_THEN_INDEX: u32 = 0; -pub const GIT_ATTR_CHECK_INDEX_THEN_FILE: u32 = 1; -pub const GIT_ATTR_CHECK_INDEX_ONLY: u32 = 2; -pub const GIT_ATTR_CHECK_NO_SYSTEM: u32 = 1 << 2; -pub const GIT_ATTR_CHECK_INCLUDE_HEAD: u32 = 1 << 3; - -#[repr(C)] -pub struct git_cred { - pub credtype: git_credtype_t, - pub free: Option, -} - -git_enum! { - pub enum git_credtype_t { - GIT_CREDTYPE_USERPASS_PLAINTEXT = 1 << 0, - GIT_CREDTYPE_SSH_KEY = 1 << 1, - GIT_CREDTYPE_SSH_CUSTOM = 1 << 2, - GIT_CREDTYPE_DEFAULT = 1 << 3, - GIT_CREDTYPE_SSH_INTERACTIVE = 1 << 4, - GIT_CREDTYPE_USERNAME = 1 << 5, - GIT_CREDTYPE_SSH_MEMORY = 1 << 6, - } -} - -pub type git_cred_ssh_interactive_callback = Option< - extern "C" fn( - name: *const c_char, - name_len: c_int, - instruction: *const c_char, - instruction_len: c_int, - num_prompts: c_int, - prompts: *const LIBSSH2_USERAUTH_KBDINT_PROMPT, - responses: *mut LIBSSH2_USERAUTH_KBDINT_RESPONSE, - abstrakt: *mut *mut c_void, - ), ->; - -pub type git_cred_sign_callback = Option< - extern "C" fn( - session: *mut LIBSSH2_SESSION, - sig: *mut *mut c_uchar, - sig_len: *mut size_t, - data: *const c_uchar, - data_len: size_t, - abstrakt: *mut *mut c_void, - ), ->; - -pub enum LIBSSH2_SESSION {} -pub enum LIBSSH2_USERAUTH_KBDINT_PROMPT {} -pub enum LIBSSH2_USERAUTH_KBDINT_RESPONSE {} - -#[repr(C)] -pub struct git_push_options { - pub version: c_uint, - pub pb_parallelism: c_uint, - pub callbacks: git_remote_callbacks, - pub proxy_opts: git_proxy_options, - pub follow_redirects: git_remote_redirect_t, - pub custom_headers: git_strarray, - pub remote_push_options: git_strarray, -} - -pub type git_tag_foreach_cb = - Option c_int>; - -git_enum! { - pub enum git_index_add_option_t { - GIT_INDEX_ADD_DEFAULT = 0, - GIT_INDEX_ADD_FORCE = 1 << 0, - GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = 1 << 1, - GIT_INDEX_ADD_CHECK_PATHSPEC = 1 << 2, - } -} - -git_enum! { - pub enum git_repository_open_flag_t { - GIT_REPOSITORY_OPEN_NO_SEARCH = 1 << 0, - GIT_REPOSITORY_OPEN_CROSS_FS = 1 << 1, - GIT_REPOSITORY_OPEN_BARE = 1 << 2, - GIT_REPOSITORY_OPEN_NO_DOTGIT = 1 << 3, - GIT_REPOSITORY_OPEN_FROM_ENV = 1 << 4, - } -} - -#[repr(C)] -pub struct git_repository_init_options { - pub version: c_uint, - pub flags: u32, - pub mode: u32, - pub workdir_path: *const c_char, - pub description: *const c_char, - pub template_path: *const c_char, - pub initial_head: *const c_char, - pub origin_url: *const c_char, - #[cfg(feature = "unstable-sha256")] - pub oid_type: git_oid_t, -} - -pub const GIT_REPOSITORY_INIT_OPTIONS_VERSION: c_uint = 1; - -#[cfg(feature = "unstable-sha256")] -#[repr(C)] -pub struct git_repository_new_options { - pub version: c_uint, - pub oid_type: git_oid_t, -} - -#[cfg(feature = "unstable-sha256")] -pub const GIT_REPOSITORY_NEW_OPTIONS_VERSION: c_uint = 1; - -#[cfg(feature = "unstable-sha256")] -#[repr(C)] -pub struct git_index_options { - pub version: c_uint, - pub oid_type: git_oid_t, -} - -#[cfg(feature = "unstable-sha256")] -pub const GIT_INDEX_OPTIONS_VERSION: c_uint = 1; - -#[cfg(feature = "unstable-sha256")] -#[repr(C)] -pub struct git_odb_options { - pub version: c_uint, - pub oid_type: git_oid_t, -} - -#[cfg(feature = "unstable-sha256")] -pub const GIT_ODB_OPTIONS_VERSION: c_uint = 1; - -#[cfg(feature = "unstable-sha256")] -#[repr(C)] -pub struct git_odb_backend_pack_options { - pub version: c_uint, - pub oid_type: git_oid_t, -} - -#[cfg(feature = "unstable-sha256")] -pub const GIT_ODB_BACKEND_PACK_OPTIONS_VERSION: c_uint = 1; - -#[cfg(feature = "unstable-sha256")] -#[repr(C)] -pub struct git_odb_backend_loose_options { - pub version: c_uint, - pub flags: u32, - pub compression_level: c_int, - pub dir_mode: c_uint, - pub file_mode: c_uint, - pub oid_type: git_oid_t, -} - -#[cfg(feature = "unstable-sha256")] -pub const GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION: c_uint = 1; - -#[cfg(feature = "unstable-sha256")] -#[repr(C)] -pub struct git_diff_parse_options { - pub version: c_uint, - pub oid_type: git_oid_t, -} - -#[cfg(feature = "unstable-sha256")] -pub const GIT_DIFF_PARSE_OPTIONS_VERSION: c_uint = 1; - -git_enum! { - pub enum git_repository_init_flag_t { - GIT_REPOSITORY_INIT_BARE = 1 << 0, - GIT_REPOSITORY_INIT_NO_REINIT = 1 << 1, - GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = 1 << 2, - GIT_REPOSITORY_INIT_MKDIR = 1 << 3, - GIT_REPOSITORY_INIT_MKPATH = 1 << 4, - GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = 1 << 5, - GIT_REPOSITORY_INIT_RELATIVE_GITLINK = 1 << 6, - } -} - -git_enum! { - pub enum git_repository_init_mode_t { - GIT_REPOSITORY_INIT_SHARED_UMASK = 0, - GIT_REPOSITORY_INIT_SHARED_GROUP = 0o002775, - GIT_REPOSITORY_INIT_SHARED_ALL = 0o002777, - } -} - -git_enum! { - pub enum git_sort_t { - GIT_SORT_NONE = 0, - GIT_SORT_TOPOLOGICAL = 1 << 0, - GIT_SORT_TIME = 1 << 1, - GIT_SORT_REVERSE = 1 << 2, - } -} - -git_enum! { - pub enum git_submodule_status_t { - GIT_SUBMODULE_STATUS_IN_HEAD = 1 << 0, - GIT_SUBMODULE_STATUS_IN_INDEX = 1 << 1, - GIT_SUBMODULE_STATUS_IN_CONFIG = 1 << 2, - GIT_SUBMODULE_STATUS_IN_WD = 1 << 3, - GIT_SUBMODULE_STATUS_INDEX_ADDED = 1 << 4, - GIT_SUBMODULE_STATUS_INDEX_DELETED = 1 << 5, - GIT_SUBMODULE_STATUS_INDEX_MODIFIED = 1 << 6, - GIT_SUBMODULE_STATUS_WD_UNINITIALIZED = 1 << 7, - GIT_SUBMODULE_STATUS_WD_ADDED = 1 << 8, - GIT_SUBMODULE_STATUS_WD_DELETED = 1 << 9, - GIT_SUBMODULE_STATUS_WD_MODIFIED = 1 << 10, - GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = 1 << 11, - GIT_SUBMODULE_STATUS_WD_WD_MODIFIED = 1 << 12, - GIT_SUBMODULE_STATUS_WD_UNTRACKED = 1 << 13, - } -} - -#[repr(C)] -pub struct git_remote_head { - pub local: c_int, - pub oid: git_oid, - pub loid: git_oid, - pub name: *mut c_char, - pub symref_target: *mut c_char, -} - -git_enum! { - pub enum git_pathspec_flag_t { - GIT_PATHSPEC_DEFAULT = 0, - GIT_PATHSPEC_IGNORE_CASE = 1 << 0, - GIT_PATHSPEC_USE_CASE = 1 << 1, - GIT_PATHSPEC_NO_GLOB = 1 << 2, - GIT_PATHSPEC_NO_MATCH_ERROR = 1 << 3, - GIT_PATHSPEC_FIND_FAILURES = 1 << 4, - GIT_PATHSPEC_FAILURES_ONLY = 1 << 5, - } -} - -pub type git_diff_file_cb = Option c_int>; -pub type git_diff_hunk_cb = - Option c_int>; -pub type git_diff_line_cb = Option< - extern "C" fn( - *const git_diff_delta, - *const git_diff_hunk, - *const git_diff_line, - *mut c_void, - ) -> c_int, ->; -pub type git_diff_binary_cb = - Option c_int>; - -#[repr(C)] -pub struct git_diff_hunk { - pub old_start: c_int, - pub old_lines: c_int, - pub new_start: c_int, - pub new_lines: c_int, - pub header_len: size_t, - pub header: [c_char; 128], -} - -git_enum! { - pub enum git_diff_line_t { - GIT_DIFF_LINE_CONTEXT = b' ' as git_diff_line_t, - GIT_DIFF_LINE_ADDITION = b'+' as git_diff_line_t, - GIT_DIFF_LINE_DELETION = b'-' as git_diff_line_t, - GIT_DIFF_LINE_CONTEXT_EOFNL = b'=' as git_diff_line_t, - GIT_DIFF_LINE_ADD_EOFNL = b'>' as git_diff_line_t, - GIT_DIFF_LINE_DEL_EOFNL = b'<' as git_diff_line_t, - GIT_DIFF_LINE_FILE_HDR = b'F' as git_diff_line_t, - GIT_DIFF_LINE_HUNK_HDR = b'H' as git_diff_line_t, - GIT_DIFF_LINE_BINARY = b'B' as git_diff_line_t, - } -} - -#[repr(C)] -pub struct git_diff_line { - pub origin: c_char, - pub old_lineno: c_int, - pub new_lineno: c_int, - pub num_lines: c_int, - pub content_len: size_t, - pub content_offset: git_off_t, - pub content: *const c_char, -} - -#[repr(C)] -pub struct git_diff_options { - pub version: c_uint, - pub flags: u32, - pub ignore_submodules: git_submodule_ignore_t, - pub pathspec: git_strarray, - pub notify_cb: git_diff_notify_cb, - pub progress_cb: git_diff_progress_cb, - pub payload: *mut c_void, - pub context_lines: u32, - pub interhunk_lines: u32, - pub oid_type: git_oid_t, - pub id_abbrev: u16, - pub max_size: git_off_t, - pub old_prefix: *const c_char, - pub new_prefix: *const c_char, -} - -git_enum! { - pub enum git_oid_t { - GIT_OID_SHA1 = 1, - #[cfg(feature = "unstable-sha256")] - GIT_OID_SHA256 = 2, - } -} - -git_enum! { - pub enum git_diff_format_t { - GIT_DIFF_FORMAT_PATCH = 1, - GIT_DIFF_FORMAT_PATCH_HEADER = 2, - GIT_DIFF_FORMAT_RAW = 3, - GIT_DIFF_FORMAT_NAME_ONLY = 4, - GIT_DIFF_FORMAT_NAME_STATUS = 5, - GIT_DIFF_FORMAT_PATCH_ID = 6, - } -} - -git_enum! { - pub enum git_diff_stats_format_t { - GIT_DIFF_STATS_NONE = 0, - GIT_DIFF_STATS_FULL = 1 << 0, - GIT_DIFF_STATS_SHORT = 1 << 1, - GIT_DIFF_STATS_NUMBER = 1 << 2, - GIT_DIFF_STATS_INCLUDE_SUMMARY = 1 << 3, - } -} - -pub type git_diff_notify_cb = Option< - extern "C" fn(*const git_diff, *const git_diff_delta, *const c_char, *mut c_void) -> c_int, ->; - -pub type git_diff_progress_cb = - Option c_int>; - -git_enum! { - pub enum git_diff_option_t { - GIT_DIFF_NORMAL = 0, - GIT_DIFF_REVERSE = 1 << 0, - GIT_DIFF_INCLUDE_IGNORED = 1 << 1, - GIT_DIFF_RECURSE_IGNORED_DIRS = 1 << 2, - GIT_DIFF_INCLUDE_UNTRACKED = 1 << 3, - GIT_DIFF_RECURSE_UNTRACKED_DIRS = 1 << 4, - GIT_DIFF_INCLUDE_UNMODIFIED = 1 << 5, - GIT_DIFF_INCLUDE_TYPECHANGE = 1 << 6, - GIT_DIFF_INCLUDE_TYPECHANGE_TREES = 1 << 7, - GIT_DIFF_IGNORE_FILEMODE = 1 << 8, - GIT_DIFF_IGNORE_SUBMODULES = 1 << 9, - GIT_DIFF_IGNORE_CASE = 1 << 10, - GIT_DIFF_DISABLE_PATHSPEC_MATCH = 1 << 12, - GIT_DIFF_SKIP_BINARY_CHECK = 1 << 13, - GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS = 1 << 14, - GIT_DIFF_UPDATE_INDEX = 1 << 15, - GIT_DIFF_INCLUDE_UNREADABLE = 1 << 16, - GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED = 1 << 17, - GIT_DIFF_INDENT_HEURISTIC = 1 << 18, - GIT_DIFF_IGNORE_BLANK_LINES = 1 << 19, - GIT_DIFF_FORCE_TEXT = 1 << 20, - GIT_DIFF_FORCE_BINARY = 1 << 21, - GIT_DIFF_IGNORE_WHITESPACE = 1 << 22, - GIT_DIFF_IGNORE_WHITESPACE_CHANGE = 1 << 23, - GIT_DIFF_IGNORE_WHITESPACE_EOL = 1 << 24, - GIT_DIFF_SHOW_UNTRACKED_CONTENT = 1 << 25, - GIT_DIFF_SHOW_UNMODIFIED = 1 << 26, - GIT_DIFF_PATIENCE = 1 << 28, - GIT_DIFF_MINIMAL = 1 << 29, - GIT_DIFF_SHOW_BINARY = 1 << 30, - } -} - -#[repr(C)] -pub struct git_diff_find_options { - pub version: c_uint, - pub flags: u32, - pub rename_threshold: u16, - pub rename_from_rewrite_threshold: u16, - pub copy_threshold: u16, - pub break_rewrite_threshold: u16, - pub rename_limit: size_t, - pub metric: *mut git_diff_similarity_metric, -} - -#[repr(C)] -pub struct git_diff_similarity_metric { - pub file_signature: Option< - extern "C" fn(*mut *mut c_void, *const git_diff_file, *const c_char, *mut c_void) -> c_int, - >, - pub buffer_signature: Option< - extern "C" fn( - *mut *mut c_void, - *const git_diff_file, - *const c_char, - size_t, - *mut c_void, - ) -> c_int, - >, - pub free_signature: Option, - pub similarity: - Option c_int>, - pub payload: *mut c_void, -} - -pub const GIT_DIFF_FIND_OPTIONS_VERSION: c_uint = 1; - -pub const GIT_DIFF_FIND_BY_CONFIG: u32 = 0; -pub const GIT_DIFF_FIND_RENAMES: u32 = 1 << 0; -pub const GIT_DIFF_FIND_RENAMES_FROM_REWRITES: u32 = 1 << 1; -pub const GIT_DIFF_FIND_COPIES: u32 = 1 << 2; -pub const GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED: u32 = 1 << 3; -pub const GIT_DIFF_FIND_REWRITES: u32 = 1 << 4; -pub const GIT_DIFF_BREAK_REWRITES: u32 = 1 << 5; -pub const GIT_DIFF_FIND_AND_BREAK_REWRITES: u32 = GIT_DIFF_FIND_REWRITES | GIT_DIFF_BREAK_REWRITES; -pub const GIT_DIFF_FIND_FOR_UNTRACKED: u32 = 1 << 6; -pub const GIT_DIFF_FIND_ALL: u32 = 0x0ff; -pub const GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE: u32 = 0; -pub const GIT_DIFF_FIND_IGNORE_WHITESPACE: u32 = 1 << 12; -pub const GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE: u32 = 1 << 13; -pub const GIT_DIFF_FIND_EXACT_MATCH_ONLY: u32 = 1 << 14; -pub const GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY: u32 = 1 << 15; -pub const GIT_DIFF_FIND_REMOVE_UNMODIFIED: u32 = 1 << 16; - -#[repr(C)] -pub struct git_diff_format_email_options { - pub version: c_uint, - pub flags: u32, - pub patch_no: usize, - pub total_patches: usize, - pub id: *const git_oid, - pub summary: *const c_char, - pub body: *const c_char, - pub author: *const git_signature, -} - -pub const GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION: c_uint = 1; - -pub const GIT_DIFF_FORMAT_EMAIL_NONE: u32 = 0; -pub const GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER: u32 = 1 << 0; - -#[repr(C)] -pub struct git_diff_patchid_options { - pub version: c_uint, -} - -pub const GIT_DIFF_PATCHID_OPTIONS_VERSION: c_uint = 1; - -#[repr(C)] -pub struct git_diff_binary { - pub contains_data: c_uint, - pub old_file: git_diff_binary_file, - pub new_file: git_diff_binary_file, -} - -#[repr(C)] -pub struct git_diff_binary_file { - pub kind: git_diff_binary_t, - pub data: *const c_char, - pub datalen: size_t, - pub inflatedlen: size_t, -} - -git_enum! { - pub enum git_diff_binary_t { - GIT_DIFF_BINARY_NONE, - GIT_DIFF_BINARY_LITERAL, - GIT_DIFF_BINARY_DELTA, - } -} - -#[repr(C)] -pub struct git_merge_options { - pub version: c_uint, - pub flags: u32, - pub rename_threshold: c_uint, - pub target_limit: c_uint, - pub metric: *mut git_diff_similarity_metric, - pub recursion_limit: c_uint, - pub default_driver: *const c_char, - pub file_favor: git_merge_file_favor_t, - pub file_flags: u32, -} - -#[repr(C)] -pub struct git_merge_file_options { - pub version: c_uint, - pub ancestor_label: *const c_char, - pub our_label: *const c_char, - pub their_label: *const c_char, - pub favor: git_merge_file_favor_t, - pub flags: u32, - pub marker_size: c_ushort, -} - -#[repr(C)] -pub struct git_merge_file_input { - pub version: c_uint, - pub ptr: *const c_char, - pub size: size_t, - pub path: *const c_char, - pub mode: c_uint, -} - -#[repr(C)] -pub struct git_merge_file_result { - pub automergeable: c_uint, - pub path: *const c_char, - pub mode: c_uint, - pub ptr: *const c_char, - pub len: size_t, -} - -git_enum! { - pub enum git_merge_flag_t { - GIT_MERGE_FIND_RENAMES = 1 << 0, - GIT_MERGE_FAIL_ON_CONFLICT = 1 << 1, - GIT_MERGE_SKIP_REUC = 1 << 2, - GIT_MERGE_NO_RECURSIVE = 1 << 3, - } -} - -git_enum! { - pub enum git_merge_file_favor_t { - GIT_MERGE_FILE_FAVOR_NORMAL = 0, - GIT_MERGE_FILE_FAVOR_OURS = 1, - GIT_MERGE_FILE_FAVOR_THEIRS = 2, - GIT_MERGE_FILE_FAVOR_UNION = 3, - } -} - -git_enum! { - pub enum git_merge_file_flag_t { - GIT_MERGE_FILE_DEFAULT = 0, - GIT_MERGE_FILE_STYLE_MERGE = 1 << 0, - GIT_MERGE_FILE_STYLE_DIFF3 = 1 << 1, - GIT_MERGE_FILE_SIMPLIFY_ALNUM = 1 << 2, - GIT_MERGE_FILE_IGNORE_WHITESPACE = 1 << 3, - GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE = 1 << 4, - GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL = 1 << 5, - GIT_MERGE_FILE_DIFF_PATIENCE = 1 << 6, - GIT_MERGE_FILE_DIFF_MINIMAL = 1 << 7, - GIT_MERGE_FILE_STYLE_ZDIFF3 = 1 << 8, - GIT_MERGE_FILE_ACCEPT_CONFLICTS = 1 << 9, - } -} - -git_enum! { - pub enum git_merge_analysis_t { - GIT_MERGE_ANALYSIS_NONE = 0, - GIT_MERGE_ANALYSIS_NORMAL = 1 << 0, - GIT_MERGE_ANALYSIS_UP_TO_DATE = 1 << 1, - GIT_MERGE_ANALYSIS_FASTFORWARD = 1 << 2, - GIT_MERGE_ANALYSIS_UNBORN = 1 << 3, - } -} - -git_enum! { - pub enum git_merge_preference_t { - GIT_MERGE_PREFERENCE_NONE = 0, - GIT_MERGE_PREFERENCE_NO_FASTFORWARD = 1 << 0, - GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY = 1 << 1, - } -} - -pub type git_transport_cb = Option< - extern "C" fn( - out: *mut *mut git_transport, - owner: *mut git_remote, - param: *mut c_void, - ) -> c_int, ->; - -#[repr(C)] -pub struct git_transport { - pub version: c_uint, - pub connect: Option< - extern "C" fn( - transport: *mut git_transport, - url: *const c_char, - direction: c_int, - connect_opts: *const git_remote_connect_options, - ) -> c_int, - >, - pub set_connect_opts: Option< - extern "C" fn( - transport: *mut git_transport, - connect_opts: *const git_remote_connect_options, - ) -> c_int, - >, - pub capabilities: - Option c_int>, - #[cfg(feature = "unstable-sha256")] - pub oid_type: - Option c_int>, - pub ls: Option< - extern "C" fn( - out: *mut *mut *const git_remote_head, - size: *mut size_t, - transport: *mut git_transport, - ) -> c_int, - >, - pub push: Option c_int>, - pub negotiate_fetch: Option< - extern "C" fn( - transport: *mut git_transport, - repo: *mut git_repository, - fetch_data: *const git_fetch_negotiation, - ) -> c_int, - >, - pub shallow_roots: - Option c_int>, - pub download_pack: Option< - extern "C" fn( - transport: *mut git_transport, - repo: *mut git_repository, - stats: *mut git_indexer_progress, - ) -> c_int, - >, - pub is_connected: Option c_int>, - pub cancel: Option, - pub close: Option c_int>, - pub free: Option, -} - -#[repr(C)] -pub struct git_remote_connect_options { - pub version: c_uint, - pub callbacks: git_remote_callbacks, - pub proxy_opts: git_proxy_options, - pub follow_redirects: git_remote_redirect_t, - pub custom_headers: git_strarray, -} - -git_enum! { - pub enum git_remote_redirect_t { - GIT_REMOTE_REDIRECT_NONE = 1 << 0, - GIT_REMOTE_REDIRECT_INITIAL = 1 << 1, - GIT_REMOTE_REDIRECT_ALL = 1 << 2, - } -} - -#[repr(C)] -pub struct git_odb_backend { - pub version: c_uint, - pub odb: *mut git_odb, - pub read: Option< - extern "C" fn( - *mut *mut c_void, - *mut size_t, - *mut git_object_t, - *mut git_odb_backend, - *const git_oid, - ) -> c_int, - >, - - pub read_prefix: Option< - extern "C" fn( - *mut git_oid, - *mut *mut c_void, - *mut size_t, - *mut git_object_t, - *mut git_odb_backend, - *const git_oid, - size_t, - ) -> c_int, - >, - pub read_header: Option< - extern "C" fn( - *mut size_t, - *mut git_object_t, - *mut git_odb_backend, - *const git_oid, - ) -> c_int, - >, - - pub write: Option< - extern "C" fn( - *mut git_odb_backend, - *const git_oid, - *const c_void, - size_t, - git_object_t, - ) -> c_int, - >, - - pub writestream: Option< - extern "C" fn( - *mut *mut git_odb_stream, - *mut git_odb_backend, - git_object_size_t, - git_object_t, - ) -> c_int, - >, - - pub readstream: Option< - extern "C" fn( - *mut *mut git_odb_stream, - *mut size_t, - *mut git_object_t, - *mut git_odb_backend, - *const git_oid, - ) -> c_int, - >, - - pub exists: Option c_int>, - - pub exists_prefix: - Option c_int>, - - pub refresh: Option c_int>, - - pub foreach: - Option c_int>, - - pub writepack: Option< - extern "C" fn( - *mut *mut git_odb_writepack, - *mut git_odb_backend, - *mut git_odb, - git_indexer_progress_cb, - *mut c_void, - ) -> c_int, - >, - - pub writemidx: Option c_int>, - - pub freshen: Option c_int>, - - pub free: Option, -} - -git_enum! { - pub enum git_odb_lookup_flags_t { - GIT_ODB_LOOKUP_NO_REFRESH = 1 << 0, - } -} - -#[repr(C)] -pub struct git_odb_writepack { - pub backend: *mut git_odb_backend, - - pub append: Option< - extern "C" fn( - *mut git_odb_writepack, - *const c_void, - size_t, - *mut git_indexer_progress, - ) -> c_int, - >, - - pub commit: - Option c_int>, - - pub free: Option, -} - -#[repr(C)] -pub struct git_refdb_backend { - pub version: c_uint, - pub exists: Option c_int>, - pub lookup: Option< - extern "C" fn(*mut *mut git_reference, *mut git_refdb_backend, *const c_char) -> c_int, - >, - pub iterator: Option< - extern "C" fn( - *mut *mut git_reference_iterator, - *mut git_refdb_backend, - *const c_char, - ) -> c_int, - >, - pub write: Option< - extern "C" fn( - *mut git_refdb_backend, - *const git_reference, - c_int, - *const git_signature, - *const c_char, - *const git_oid, - *const c_char, - ) -> c_int, - >, - pub rename: Option< - extern "C" fn( - *mut *mut git_reference, - *mut git_refdb_backend, - *const c_char, - *const c_char, - c_int, - *const git_signature, - *const c_char, - ) -> c_int, - >, - pub del: Option< - extern "C" fn( - *mut git_refdb_backend, - *const c_char, - *const git_oid, - *const c_char, - ) -> c_int, - >, - pub compress: Option c_int>, - pub has_log: Option c_int>, - pub ensure_log: Option c_int>, - pub free: Option, - pub reflog_read: - Option c_int>, - pub reflog_write: Option c_int>, - pub reflog_rename: - Option c_int>, - pub reflog_delete: Option c_int>, - pub lock: - Option c_int>, - pub unlock: Option< - extern "C" fn( - *mut git_refdb_backend, - *mut c_void, - c_int, - c_int, - *const git_reference, - *const git_signature, - *const c_char, - ) -> c_int, - >, -} - -#[repr(C)] -pub struct git_proxy_options { - pub version: c_uint, - pub kind: git_proxy_t, - pub url: *const c_char, - pub credentials: git_cred_acquire_cb, - pub certificate_check: git_transport_certificate_check_cb, - pub payload: *mut c_void, -} - -git_enum! { - pub enum git_proxy_t { - GIT_PROXY_NONE = 0, - GIT_PROXY_AUTO = 1, - GIT_PROXY_SPECIFIED = 2, - } -} - -git_enum! { - pub enum git_smart_service_t { - GIT_SERVICE_UPLOADPACK_LS = 1, - GIT_SERVICE_UPLOADPACK = 2, - GIT_SERVICE_RECEIVEPACK_LS = 3, - GIT_SERVICE_RECEIVEPACK = 4, - } -} - -#[repr(C)] -pub struct git_smart_subtransport_stream { - pub subtransport: *mut git_smart_subtransport, - pub read: Option< - extern "C" fn( - *mut git_smart_subtransport_stream, - *mut c_char, - size_t, - *mut size_t, - ) -> c_int, - >, - pub write: - Option c_int>, - pub free: Option, -} - -#[repr(C)] -pub struct git_smart_subtransport { - pub action: Option< - extern "C" fn( - *mut *mut git_smart_subtransport_stream, - *mut git_smart_subtransport, - *const c_char, - git_smart_service_t, - ) -> c_int, - >, - pub close: Option c_int>, - pub free: Option, -} - -pub type git_smart_subtransport_cb = Option< - extern "C" fn(*mut *mut git_smart_subtransport, *mut git_transport, *mut c_void) -> c_int, ->; - -#[repr(C)] -pub struct git_smart_subtransport_definition { - pub callback: git_smart_subtransport_cb, - pub rpc: c_uint, - pub param: *mut c_void, -} - -#[repr(C)] -pub struct git_describe_options { - pub version: c_uint, - pub max_candidates_tags: c_uint, - pub describe_strategy: c_uint, - pub pattern: *const c_char, - pub only_follow_first_parent: c_int, - pub show_commit_oid_as_fallback: c_int, -} - -git_enum! { - pub enum git_describe_strategy_t { - GIT_DESCRIBE_DEFAULT, - GIT_DESCRIBE_TAGS, - GIT_DESCRIBE_ALL, - } -} - -#[repr(C)] -pub struct git_describe_format_options { - pub version: c_uint, - pub abbreviated_size: c_uint, - pub always_use_long_format: c_int, - pub dirty_suffix: *const c_char, -} - -git_enum! { - pub enum git_packbuilder_stage_t { - GIT_PACKBUILDER_ADDING_OBJECTS, - GIT_PACKBUILDER_DELTAFICATION, - } -} - -git_enum! { - pub enum git_stash_flags { - GIT_STASH_DEFAULT = 0, - GIT_STASH_KEEP_INDEX = 1 << 0, - GIT_STASH_INCLUDE_UNTRACKED = 1 << 1, - GIT_STASH_INCLUDE_IGNORED = 1 << 2, - GIT_STASH_KEEP_ALL = 1 << 3, - } -} - -git_enum! { - pub enum git_stash_apply_flags { - GIT_STASH_APPLY_DEFAULT = 0, - GIT_STASH_APPLY_REINSTATE_INDEX = 1 << 0, - } -} - -git_enum! { - pub enum git_stash_apply_progress_t { - GIT_STASH_APPLY_PROGRESS_NONE = 0, - GIT_STASH_APPLY_PROGRESS_LOADING_STASH, - GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX, - GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED, - GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED, - GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED, - GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED, - GIT_STASH_APPLY_PROGRESS_DONE, - } -} - -#[repr(C)] -pub struct git_stash_save_options { - pub version: c_uint, - pub flags: u32, - pub stasher: *const git_signature, - pub message: *const c_char, - pub paths: git_strarray, -} - -pub const GIT_STASH_SAVE_OPTIONS_VERSION: c_uint = 1; - -#[repr(C)] -pub struct git_stash_apply_options { - pub version: c_uint, - pub flags: u32, - pub checkout_options: git_checkout_options, - pub progress_cb: git_stash_apply_progress_cb, - pub progress_payload: *mut c_void, -} - -pub type git_stash_apply_progress_cb = - Option c_int>; - -pub type git_stash_cb = Option< - extern "C" fn( - index: size_t, - message: *const c_char, - stash_id: *const git_oid, - payload: *mut c_void, - ) -> c_int, ->; - -pub type git_packbuilder_foreach_cb = - Option c_int>; - -pub type git_odb_foreach_cb = - Option c_int>; - -pub type git_commit_signing_cb = Option< - extern "C" fn( - signature: *mut git_buf, - signature_field: *mut git_buf, - commit_content: *const c_char, - payload: *mut c_void, - ) -> c_int, ->; - -pub type git_commit_create_cb = Option< - extern "C" fn( - *mut git_oid, - *const git_signature, - *const git_signature, - *const c_char, - *const c_char, - *const git_tree, - usize, - *const git_commit, - *mut c_void, - ) -> c_int, ->; - -pub const GIT_REBASE_NO_OPERATION: usize = usize::max_value(); - -#[repr(C)] -pub struct git_rebase_options { - pub version: c_uint, - pub quiet: c_int, - pub inmemory: c_int, - pub rewrite_notes_ref: *const c_char, - pub merge_options: git_merge_options, - pub checkout_options: git_checkout_options, - pub commit_create_cb: git_commit_create_cb, - pub signing_cb: git_commit_signing_cb, - pub payload: *mut c_void, -} - -git_enum! { - pub enum git_rebase_operation_t { - GIT_REBASE_OPERATION_PICK = 0, - GIT_REBASE_OPERATION_REWORD, - GIT_REBASE_OPERATION_EDIT, - GIT_REBASE_OPERATION_SQUASH, - GIT_REBASE_OPERATION_FIXUP, - GIT_REBASE_OPERATION_EXEC, - } -} - -#[repr(C)] -pub struct git_rebase_operation { - pub kind: git_rebase_operation_t, - pub id: git_oid, - pub exec: *const c_char, -} - -#[repr(C)] -pub struct git_cherrypick_options { - pub version: c_uint, - pub mainline: c_uint, - pub merge_opts: git_merge_options, - pub checkout_opts: git_checkout_options, -} - -pub type git_revert_options = git_cherrypick_options; - -pub type git_apply_delta_cb = - Option c_int>; - -pub type git_apply_hunk_cb = - Option c_int>; - -git_enum! { - pub enum git_apply_flags_t { - GIT_APPLY_CHECK = 1<<0, - } -} - -#[repr(C)] -pub struct git_apply_options { - pub version: c_uint, - pub delta_cb: git_apply_delta_cb, - pub hunk_cb: git_apply_hunk_cb, - pub payload: *mut c_void, - pub flags: u32, -} - -git_enum! { - pub enum git_apply_location_t { - GIT_APPLY_LOCATION_WORKDIR = 0, - GIT_APPLY_LOCATION_INDEX = 1, - GIT_APPLY_LOCATION_BOTH = 2, - } -} - -git_enum! { - pub enum git_libgit2_opt_t { - GIT_OPT_GET_MWINDOW_SIZE = 0, - GIT_OPT_SET_MWINDOW_SIZE, - GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, - GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, - GIT_OPT_GET_SEARCH_PATH, - GIT_OPT_SET_SEARCH_PATH, - GIT_OPT_SET_CACHE_OBJECT_LIMIT, - GIT_OPT_SET_CACHE_MAX_SIZE, - GIT_OPT_ENABLE_CACHING, - GIT_OPT_GET_CACHED_MEMORY, - GIT_OPT_GET_TEMPLATE_PATH, - GIT_OPT_SET_TEMPLATE_PATH, - GIT_OPT_SET_SSL_CERT_LOCATIONS, - GIT_OPT_SET_USER_AGENT, - GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, - GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, - GIT_OPT_SET_SSL_CIPHERS, - GIT_OPT_GET_USER_AGENT, - GIT_OPT_ENABLE_OFS_DELTA, - GIT_OPT_ENABLE_FSYNC_GITDIR, - GIT_OPT_GET_WINDOWS_SHAREMODE, - GIT_OPT_SET_WINDOWS_SHAREMODE, - GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, - GIT_OPT_SET_ALLOCATOR, - GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, - GIT_OPT_GET_PACK_MAX_OBJECTS, - GIT_OPT_SET_PACK_MAX_OBJECTS, - GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, - GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, - GIT_OPT_GET_MWINDOW_FILE_LIMIT, - GIT_OPT_SET_MWINDOW_FILE_LIMIT, - GIT_OPT_SET_ODB_PACKED_PRIORITY, - GIT_OPT_SET_ODB_LOOSE_PRIORITY, - GIT_OPT_GET_EXTENSIONS, - GIT_OPT_SET_EXTENSIONS, - GIT_OPT_GET_OWNER_VALIDATION, - GIT_OPT_SET_OWNER_VALIDATION, - GIT_OPT_GET_HOMEDIR, - GIT_OPT_SET_HOMEDIR, - GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, - GIT_OPT_GET_SERVER_CONNECT_TIMEOUT, - GIT_OPT_SET_SERVER_TIMEOUT, - GIT_OPT_GET_SERVER_TIMEOUT, - GIT_OPT_SET_USER_AGENT_PRODUCT, - GIT_OPT_GET_USER_AGENT_PRODUCT, - GIT_OPT_ADD_SSL_X509_CERT, - GIT_OPT_GET_PACK_MAX_OBJECT_SIZE, - GIT_OPT_SET_PACK_MAX_OBJECT_SIZE, - } -} - -git_enum! { - pub enum git_reference_format_t { - GIT_REFERENCE_FORMAT_NORMAL = 0, - GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL = 1 << 0, - GIT_REFERENCE_FORMAT_REFSPEC_PATTERN = 1 << 1, - GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = 1 << 2, - } -} - -#[repr(C)] -pub struct git_worktree_add_options { - pub version: c_uint, - pub lock: c_int, - pub checkout_existing: c_int, - pub reference: *mut git_reference, - pub checkout_options: git_checkout_options, -} - -pub const GIT_WORKTREE_ADD_OPTIONS_VERSION: c_uint = 1; - -git_enum! { - pub enum git_worktree_prune_t { - /* Prune working tree even if working tree is valid */ - GIT_WORKTREE_PRUNE_VALID = 1 << 0, - /* Prune working tree even if it is locked */ - GIT_WORKTREE_PRUNE_LOCKED = 1 << 1, - /* Prune checked out working tree */ - GIT_WORKTREE_PRUNE_WORKING_TREE = 1 << 2, - } -} - -#[repr(C)] -pub struct git_worktree_prune_options { - pub version: c_uint, - pub flags: u32, -} - -pub const GIT_WORKTREE_PRUNE_OPTIONS_VERSION: c_uint = 1; - -pub type git_repository_mergehead_foreach_cb = - Option c_int>; - -pub type git_repository_fetchhead_foreach_cb = Option< - extern "C" fn(*const c_char, *const c_char, *const git_oid, c_uint, *mut c_void) -> c_int, ->; - -git_enum! { - pub enum git_trace_level_t { - /* No tracing will be performed. */ - GIT_TRACE_NONE = 0, - - /* Severe errors that may impact the program's execution */ - GIT_TRACE_FATAL = 1, - - /* Errors that do not impact the program's execution */ - GIT_TRACE_ERROR = 2, - - /* Warnings that suggest abnormal data */ - GIT_TRACE_WARN = 3, - - /* Informational messages about program execution */ - GIT_TRACE_INFO = 4, - - /* Detailed data that allows for debugging */ - GIT_TRACE_DEBUG = 5, - - /* Exceptionally detailed debugging data */ - GIT_TRACE_TRACE = 6, - } -} - -pub type git_trace_cb = Option; - -git_enum! { - pub enum git_feature_t { - GIT_FEATURE_THREADS = 1 << 0, - GIT_FEATURE_HTTPS = 1 << 1, - GIT_FEATURE_SSH = 1 << 2, - GIT_FEATURE_NSEC = 1 << 3, - } -} - -#[repr(C)] -pub struct git_message_trailer { - pub key: *const c_char, - pub value: *const c_char, -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct git_message_trailer_array { - pub trailers: *mut git_message_trailer, - pub count: size_t, - pub _trailer_block: *mut c_char, -} - -#[repr(C)] -pub struct git_email_create_options { - pub version: c_uint, - pub flags: u32, - pub diff_opts: git_diff_options, - pub diff_find_opts: git_diff_find_options, - pub subject_prefix: *const c_char, - pub start_number: usize, - pub reroll_number: usize, -} - -pub const GIT_EMAIL_CREATE_OPTIONS_VERSION: c_uint = 1; - -git_enum! { - pub enum git_email_create_flags_t { - GIT_EMAIL_CREATE_DEFAULT = 0, - GIT_EMAIL_CREATE_OMIT_NUMBERS = 1 << 0, - GIT_EMAIL_CREATE_ALWAYS_NUMBER = 1 << 1, - GIT_EMAIL_CREATE_NO_RENAMES = 1 << 2, - } -} - -extern "C" { - // threads - pub fn git_libgit2_init() -> c_int; - pub fn git_libgit2_shutdown() -> c_int; - - // repository - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_repository_new(out: *mut *mut git_repository) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_repository_new( - out: *mut *mut git_repository, - opts: *mut git_repository_new_options, - ) -> c_int; - pub fn git_repository_free(repo: *mut git_repository); - pub fn git_repository_open(repo: *mut *mut git_repository, path: *const c_char) -> c_int; - pub fn git_repository_open_bare(repo: *mut *mut git_repository, path: *const c_char) -> c_int; - pub fn git_repository_open_ext( - repo: *mut *mut git_repository, - path: *const c_char, - flags: c_uint, - ceiling_dirs: *const c_char, - ) -> c_int; - pub fn git_repository_open_from_worktree( - repo: *mut *mut git_repository, - worktree: *mut git_worktree, - ) -> c_int; - pub fn git_repository_wrap_odb(repo: *mut *mut git_repository, odb: *mut git_odb) -> c_int; - pub fn git_repository_init( - repo: *mut *mut git_repository, - path: *const c_char, - is_bare: c_uint, - ) -> c_int; - pub fn git_repository_init_ext( - out: *mut *mut git_repository, - repo_path: *const c_char, - opts: *mut git_repository_init_options, - ) -> c_int; - pub fn git_repository_init_init_options( - opts: *mut git_repository_init_options, - version: c_uint, - ) -> c_int; - pub fn git_repository_get_namespace(repo: *mut git_repository) -> *const c_char; - pub fn git_repository_set_namespace( - repo: *mut git_repository, - namespace: *const c_char, - ) -> c_int; - pub fn git_repository_head(out: *mut *mut git_reference, repo: *mut git_repository) -> c_int; - pub fn git_repository_set_head(repo: *mut git_repository, refname: *const c_char) -> c_int; - - pub fn git_repository_head_detached(repo: *mut git_repository) -> c_int; - pub fn git_repository_set_head_detached( - repo: *mut git_repository, - commitish: *const git_oid, - ) -> c_int; - pub fn git_repository_set_head_detached_from_annotated( - repo: *mut git_repository, - commitish: *const git_annotated_commit, - ) -> c_int; - pub fn git_repository_set_bare(repo: *mut git_repository) -> c_int; - pub fn git_repository_is_worktree(repo: *const git_repository) -> c_int; - pub fn git_repository_is_bare(repo: *const git_repository) -> c_int; - pub fn git_repository_is_empty(repo: *mut git_repository) -> c_int; - pub fn git_repository_is_shallow(repo: *mut git_repository) -> c_int; - pub fn git_repository_path(repo: *const git_repository) -> *const c_char; - pub fn git_repository_commondir(repo: *const git_repository) -> *const c_char; - pub fn git_repository_state(repo: *mut git_repository) -> c_int; - pub fn git_repository_workdir(repo: *const git_repository) -> *const c_char; - pub fn git_repository_set_workdir( - repo: *mut git_repository, - workdir: *const c_char, - update_gitlink: c_int, - ) -> c_int; - pub fn git_repository_index(out: *mut *mut git_index, repo: *mut git_repository) -> c_int; - pub fn git_repository_set_index(repo: *mut git_repository, index: *mut git_index) -> c_int; - - pub fn git_repository_oid_type(repo: *mut git_repository) -> git_oid_t; - - pub fn git_repository_message(buf: *mut git_buf, repo: *mut git_repository) -> c_int; - - pub fn git_repository_message_remove(repo: *mut git_repository) -> c_int; - pub fn git_repository_config(out: *mut *mut git_config, repo: *mut git_repository) -> c_int; - pub fn git_repository_set_config(repo: *mut git_repository, config: *mut git_config) -> c_int; - pub fn git_repository_config_snapshot( - out: *mut *mut git_config, - repo: *mut git_repository, - ) -> c_int; - pub fn git_repository_discover( - out: *mut git_buf, - start_path: *const c_char, - across_fs: c_int, - ceiling_dirs: *const c_char, - ) -> c_int; - pub fn git_repository_set_odb(repo: *mut git_repository, odb: *mut git_odb) -> c_int; - - pub fn git_repository_refdb(out: *mut *mut git_refdb, repo: *mut git_repository) -> c_int; - pub fn git_repository_set_refdb(repo: *mut git_repository, refdb: *mut git_refdb) -> c_int; - - pub fn git_repository_reinit_filesystem( - repo: *mut git_repository, - recurse_submodules: c_int, - ) -> c_int; - pub fn git_repository_mergehead_foreach( - repo: *mut git_repository, - callback: git_repository_mergehead_foreach_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_repository_fetchhead_foreach( - repo: *mut git_repository, - callback: git_repository_fetchhead_foreach_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_ignore_add_rule(repo: *mut git_repository, rules: *const c_char) -> c_int; - pub fn git_ignore_clear_internal_rules(repo: *mut git_repository) -> c_int; - pub fn git_ignore_path_is_ignored( - ignored: *mut c_int, - repo: *mut git_repository, - path: *const c_char, - ) -> c_int; - - // revparse - pub fn git_revparse( - revspec: *mut git_revspec, - repo: *mut git_repository, - spec: *const c_char, - ) -> c_int; - pub fn git_revparse_single( - out: *mut *mut git_object, - repo: *mut git_repository, - spec: *const c_char, - ) -> c_int; - pub fn git_revparse_ext( - object_out: *mut *mut git_object, - reference_out: *mut *mut git_reference, - repo: *mut git_repository, - spec: *const c_char, - ) -> c_int; - - // object - pub fn git_object_dup(dest: *mut *mut git_object, source: *mut git_object) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_object_rawcontent_is_valid( - valid: *mut c_int, - buf: *const c_char, - len: size_t, - object_type: git_object_t, - ) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_object_rawcontent_is_valid( - valid: *mut c_int, - buf: *const c_char, - len: size_t, - object_type: git_object_t, - oid_type: git_oid_t, - ) -> c_int; - pub fn git_object_id(obj: *const git_object) -> *const git_oid; - pub fn git_object_free(object: *mut git_object); - pub fn git_object_lookup( - dest: *mut *mut git_object, - repo: *mut git_repository, - id: *const git_oid, - kind: git_object_t, - ) -> c_int; - pub fn git_object_lookup_prefix( - dest: *mut *mut git_object, - repo: *mut git_repository, - id: *const git_oid, - len: size_t, - kind: git_object_t, - ) -> c_int; - pub fn git_object_type(obj: *const git_object) -> git_object_t; - pub fn git_object_peel( - peeled: *mut *mut git_object, - object: *const git_object, - target_type: git_object_t, - ) -> c_int; - pub fn git_object_short_id(out: *mut git_buf, obj: *const git_object) -> c_int; - pub fn git_object_type2string(kind: git_object_t) -> *const c_char; - pub fn git_object_string2type(s: *const c_char) -> git_object_t; - pub fn git_object_typeisloose(kind: git_object_t) -> c_int; - - // oid - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_oid_fromraw(out: *mut git_oid, raw: *const c_uchar) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_oid_fromstrn(out: *mut git_oid, str: *const c_char, len: size_t) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_oid_fromstr(out: *mut git_oid, str: *const c_char) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_oid_fromstrp(out: *mut git_oid, str: *const c_char) -> c_int; - - #[cfg(feature = "unstable-sha256")] - pub fn git_oid_fromraw(out: *mut git_oid, raw: *const c_uchar, oid_type: git_oid_t) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_oid_fromstrn( - out: *mut git_oid, - str: *const c_char, - len: size_t, - oid_type: git_oid_t, - ) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_oid_fromstr(out: *mut git_oid, str: *const c_char, oid_type: git_oid_t) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_oid_fromstrp(out: *mut git_oid, str: *const c_char, oid_type: git_oid_t) -> c_int; - - pub fn git_oid_tostr(out: *mut c_char, n: size_t, id: *const git_oid) -> *mut c_char; - pub fn git_oid_cmp(a: *const git_oid, b: *const git_oid) -> c_int; - pub fn git_oid_equal(a: *const git_oid, b: *const git_oid) -> c_int; - pub fn git_oid_streq(id: *const git_oid, str: *const c_char) -> c_int; - #[deprecated = "use `git_oid_is_zero`"] - pub fn git_oid_iszero(id: *const git_oid) -> c_int; - pub fn git_oid_is_zero(id: *const git_oid) -> c_int; - - // error - pub fn git_error_last() -> *const git_error; - pub fn git_error_clear(); - pub fn git_error_set_str(error_class: c_int, string: *const c_char) -> c_int; - - // remote - pub fn git_remote_create( - out: *mut *mut git_remote, - repo: *mut git_repository, - name: *const c_char, - url: *const c_char, - ) -> c_int; - pub fn git_remote_create_with_fetchspec( - out: *mut *mut git_remote, - repo: *mut git_repository, - name: *const c_char, - url: *const c_char, - fetch: *const c_char, - ) -> c_int; - pub fn git_remote_lookup( - out: *mut *mut git_remote, - repo: *mut git_repository, - name: *const c_char, - ) -> c_int; - pub fn git_remote_create_anonymous( - out: *mut *mut git_remote, - repo: *mut git_repository, - url: *const c_char, - ) -> c_int; - pub fn git_remote_create_detached(out: *mut *mut git_remote, url: *const c_char) -> c_int; - pub fn git_remote_delete(repo: *mut git_repository, name: *const c_char) -> c_int; - pub fn git_remote_free(remote: *mut git_remote); - pub fn git_remote_name(remote: *const git_remote) -> *const c_char; - pub fn git_remote_pushurl(remote: *const git_remote) -> *const c_char; - pub fn git_remote_refspec_count(remote: *const git_remote) -> size_t; - pub fn git_remote_url(remote: *const git_remote) -> *const c_char; - pub fn git_remote_connect( - remote: *mut git_remote, - dir: git_direction, - callbacks: *const git_remote_callbacks, - proxy_opts: *const git_proxy_options, - custom_headers: *const git_strarray, - ) -> c_int; - pub fn git_remote_connected(remote: *const git_remote) -> c_int; - pub fn git_remote_disconnect(remote: *mut git_remote) -> c_int; - pub fn git_remote_add_fetch( - repo: *mut git_repository, - remote: *const c_char, - refspec: *const c_char, - ) -> c_int; - pub fn git_remote_add_push( - repo: *mut git_repository, - remote: *const c_char, - refspec: *const c_char, - ) -> c_int; - pub fn git_remote_download( - remote: *mut git_remote, - refspecs: *const git_strarray, - opts: *const git_fetch_options, - ) -> c_int; - pub fn git_remote_stop(remote: *mut git_remote) -> c_int; - pub fn git_remote_dup(dest: *mut *mut git_remote, source: *mut git_remote) -> c_int; - pub fn git_remote_get_fetch_refspecs( - array: *mut git_strarray, - remote: *const git_remote, - ) -> c_int; - pub fn git_remote_get_push_refspecs( - array: *mut git_strarray, - remote: *const git_remote, - ) -> c_int; - pub fn git_remote_get_refspec(remote: *const git_remote, n: size_t) -> *const git_refspec; - pub fn git_remote_is_valid_name(remote_name: *const c_char) -> c_int; - pub fn git_remote_name_is_valid(valid: *mut c_int, remote_name: *const c_char) -> c_int; - pub fn git_remote_list(out: *mut git_strarray, repo: *mut git_repository) -> c_int; - pub fn git_remote_rename( - problems: *mut git_strarray, - repo: *mut git_repository, - name: *const c_char, - new_name: *const c_char, - ) -> c_int; - pub fn git_remote_fetch( - remote: *mut git_remote, - refspecs: *const git_strarray, - opts: *const git_fetch_options, - reflog_message: *const c_char, - ) -> c_int; - pub fn git_remote_push( - remote: *mut git_remote, - refspecs: *const git_strarray, - opts: *const git_push_options, - ) -> c_int; - pub fn git_remote_update_tips( - remote: *mut git_remote, - callbacks: *const git_remote_callbacks, - update_flags: c_uint, - download_tags: git_remote_autotag_option_t, - reflog_message: *const c_char, - ) -> c_int; - pub fn git_remote_set_url( - repo: *mut git_repository, - remote: *const c_char, - url: *const c_char, - ) -> c_int; - pub fn git_remote_set_pushurl( - repo: *mut git_repository, - remote: *const c_char, - pushurl: *const c_char, - ) -> c_int; - pub fn git_remote_init_callbacks(opts: *mut git_remote_callbacks, version: c_uint) -> c_int; - pub fn git_fetch_init_options(opts: *mut git_fetch_options, version: c_uint) -> c_int; - pub fn git_remote_stats(remote: *mut git_remote) -> *const git_indexer_progress; - pub fn git_remote_ls( - out: *mut *mut *const git_remote_head, - size: *mut size_t, - remote: *mut git_remote, - ) -> c_int; - pub fn git_remote_oid_type(out: *mut git_oid_t, remote: *mut git_remote) -> c_int; - pub fn git_remote_set_autotag( - repo: *mut git_repository, - remote: *const c_char, - value: git_remote_autotag_option_t, - ) -> c_int; - pub fn git_remote_prune( - remote: *mut git_remote, - callbacks: *const git_remote_callbacks, - ) -> c_int; - pub fn git_remote_default_branch(out: *mut git_buf, remote: *mut git_remote) -> c_int; - - // refspec - pub fn git_refspec_direction(spec: *const git_refspec) -> git_direction; - pub fn git_refspec_dst(spec: *const git_refspec) -> *const c_char; - pub fn git_refspec_dst_matches(spec: *const git_refspec, refname: *const c_char) -> c_int; - pub fn git_refspec_src(spec: *const git_refspec) -> *const c_char; - pub fn git_refspec_src_matches(spec: *const git_refspec, refname: *const c_char) -> c_int; - pub fn git_refspec_force(spec: *const git_refspec) -> c_int; - pub fn git_refspec_string(spec: *const git_refspec) -> *const c_char; - pub fn git_refspec_transform( - out: *mut git_buf, - spec: *const git_refspec, - name: *const c_char, - ) -> c_int; - pub fn git_refspec_rtransform( - out: *mut git_buf, - spec: *const git_refspec, - name: *const c_char, - ) -> c_int; - - // strarray - pub fn git_strarray_free(array: *mut git_strarray); - - // oidarray - pub fn git_oidarray_free(array: *mut git_oidarray); - - // signature - pub fn git_signature_default(out: *mut *mut git_signature, repo: *mut git_repository) -> c_int; - pub fn git_signature_free(sig: *mut git_signature); - pub fn git_signature_new( - out: *mut *mut git_signature, - name: *const c_char, - email: *const c_char, - time: git_time_t, - offset: c_int, - ) -> c_int; - pub fn git_signature_now( - out: *mut *mut git_signature, - name: *const c_char, - email: *const c_char, - ) -> c_int; - pub fn git_signature_default_from_env( - author_out: *mut *mut git_signature, - committer_out: *mut *mut git_signature, - repo: *mut git_repository, - ) -> c_int; - pub fn git_signature_dup(dest: *mut *mut git_signature, sig: *const git_signature) -> c_int; - - // status - pub fn git_status_list_new( - out: *mut *mut git_status_list, - repo: *mut git_repository, - options: *const git_status_options, - ) -> c_int; - pub fn git_status_list_entrycount(list: *mut git_status_list) -> size_t; - pub fn git_status_byindex( - statuslist: *mut git_status_list, - idx: size_t, - ) -> *const git_status_entry; - pub fn git_status_list_free(list: *mut git_status_list); - pub fn git_status_init_options(opts: *mut git_status_options, version: c_uint) -> c_int; - pub fn git_status_file( - status_flags: *mut c_uint, - repo: *mut git_repository, - path: *const c_char, - ) -> c_int; - pub fn git_status_should_ignore( - ignored: *mut c_int, - repo: *mut git_repository, - path: *const c_char, - ) -> c_int; - - // clone - pub fn git_clone( - out: *mut *mut git_repository, - url: *const c_char, - local_path: *const c_char, - options: *const git_clone_options, - ) -> c_int; - pub fn git_clone_init_options(opts: *mut git_clone_options, version: c_uint) -> c_int; - - // reset - pub fn git_reset( - repo: *mut git_repository, - target: *const git_object, - reset_type: git_reset_t, - checkout_opts: *const git_checkout_options, - ) -> c_int; - pub fn git_reset_default( - repo: *mut git_repository, - target: *const git_object, - pathspecs: *const git_strarray, - ) -> c_int; - - // reference - pub fn git_reference_dup(dest: *mut *mut git_reference, src: *mut git_reference) -> c_int; - pub fn git_reference_cmp(ref1: *const git_reference, ref2: *const git_reference) -> c_int; - pub fn git_reference_delete(r: *mut git_reference) -> c_int; - pub fn git_reference_free(r: *mut git_reference); - pub fn git_reference_is_branch(r: *const git_reference) -> c_int; - pub fn git_reference_is_note(r: *const git_reference) -> c_int; - pub fn git_reference_is_remote(r: *const git_reference) -> c_int; - pub fn git_reference_is_tag(r: *const git_reference) -> c_int; - pub fn git_reference_is_valid_name(name: *const c_char) -> c_int; - pub fn git_reference_name_is_valid(valid: *mut c_int, refname: *const c_char) -> c_int; - pub fn git_reference_lookup( - out: *mut *mut git_reference, - repo: *mut git_repository, - name: *const c_char, - ) -> c_int; - pub fn git_reference_dwim( - out: *mut *mut git_reference, - repo: *mut git_repository, - refname: *const c_char, - ) -> c_int; - pub fn git_reference_name(r: *const git_reference) -> *const c_char; - pub fn git_reference_name_to_id( - out: *mut git_oid, - repo: *mut git_repository, - name: *const c_char, - ) -> c_int; - pub fn git_reference_peel( - out: *mut *mut git_object, - r: *const git_reference, - otype: git_object_t, - ) -> c_int; - pub fn git_reference_rename( - new_ref: *mut *mut git_reference, - r: *mut git_reference, - new_name: *const c_char, - force: c_int, - log_message: *const c_char, - ) -> c_int; - pub fn git_reference_resolve(out: *mut *mut git_reference, r: *const git_reference) -> c_int; - pub fn git_reference_shorthand(r: *const git_reference) -> *const c_char; - pub fn git_reference_symbolic_target(r: *const git_reference) -> *const c_char; - pub fn git_reference_target(r: *const git_reference) -> *const git_oid; - pub fn git_reference_target_peel(r: *const git_reference) -> *const git_oid; - pub fn git_reference_set_target( - out: *mut *mut git_reference, - r: *mut git_reference, - id: *const git_oid, - log_message: *const c_char, - ) -> c_int; - pub fn git_reference_symbolic_set_target( - out: *mut *mut git_reference, - r: *mut git_reference, - target: *const c_char, - log_message: *const c_char, - ) -> c_int; - pub fn git_reference_type(r: *const git_reference) -> git_reference_t; - pub fn git_reference_iterator_new( - out: *mut *mut git_reference_iterator, - repo: *mut git_repository, - ) -> c_int; - pub fn git_reference_iterator_glob_new( - out: *mut *mut git_reference_iterator, - repo: *mut git_repository, - glob: *const c_char, - ) -> c_int; - pub fn git_reference_iterator_free(iter: *mut git_reference_iterator); - pub fn git_reference_next( - out: *mut *mut git_reference, - iter: *mut git_reference_iterator, - ) -> c_int; - pub fn git_reference_next_name( - out: *mut *const c_char, - iter: *mut git_reference_iterator, - ) -> c_int; - pub fn git_reference_create( - out: *mut *mut git_reference, - repo: *mut git_repository, - name: *const c_char, - id: *const git_oid, - force: c_int, - log_message: *const c_char, - ) -> c_int; - pub fn git_reference_symbolic_create( - out: *mut *mut git_reference, - repo: *mut git_repository, - name: *const c_char, - target: *const c_char, - force: c_int, - log_message: *const c_char, - ) -> c_int; - pub fn git_reference_create_matching( - out: *mut *mut git_reference, - repo: *mut git_repository, - name: *const c_char, - id: *const git_oid, - force: c_int, - current_id: *const git_oid, - log_message: *const c_char, - ) -> c_int; - pub fn git_reference_symbolic_create_matching( - out: *mut *mut git_reference, - repo: *mut git_repository, - name: *const c_char, - target: *const c_char, - force: c_int, - current_id: *const c_char, - log_message: *const c_char, - ) -> c_int; - pub fn git_reference_has_log(repo: *mut git_repository, name: *const c_char) -> c_int; - pub fn git_reference_ensure_log(repo: *mut git_repository, name: *const c_char) -> c_int; - pub fn git_reference_normalize_name( - buffer_out: *mut c_char, - buffer_size: size_t, - name: *const c_char, - flags: u32, - ) -> c_int; - - // stash - pub fn git_stash_save( - out: *mut git_oid, - repo: *mut git_repository, - stasher: *const git_signature, - message: *const c_char, - flags: c_uint, - ) -> c_int; - - pub fn git_stash_save_options_init(opts: *mut git_stash_save_options, version: c_uint) - -> c_int; - - pub fn git_stash_save_with_opts( - out: *mut git_oid, - repo: *mut git_repository, - options: *const git_stash_save_options, - ) -> c_int; - - pub fn git_stash_apply_init_options( - opts: *mut git_stash_apply_options, - version: c_uint, - ) -> c_int; - - pub fn git_stash_apply( - repo: *mut git_repository, - index: size_t, - options: *const git_stash_apply_options, - ) -> c_int; - - pub fn git_stash_foreach( - repo: *mut git_repository, - callback: git_stash_cb, - payload: *mut c_void, - ) -> c_int; - - pub fn git_stash_drop(repo: *mut git_repository, index: size_t) -> c_int; - - pub fn git_stash_pop( - repo: *mut git_repository, - index: size_t, - options: *const git_stash_apply_options, - ) -> c_int; - - // submodules - pub fn git_submodule_add_finalize(submodule: *mut git_submodule) -> c_int; - pub fn git_submodule_add_setup( - submodule: *mut *mut git_submodule, - repo: *mut git_repository, - url: *const c_char, - path: *const c_char, - use_gitlink: c_int, - ) -> c_int; - pub fn git_submodule_add_to_index(submodule: *mut git_submodule, write_index: c_int) -> c_int; - pub fn git_submodule_branch(submodule: *mut git_submodule) -> *const c_char; - pub fn git_submodule_clone( - repo: *mut *mut git_repository, - submodule: *mut git_submodule, - opts: *const git_submodule_update_options, - ) -> c_int; - pub fn git_submodule_foreach( - repo: *mut git_repository, - callback: git_submodule_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_submodule_free(submodule: *mut git_submodule); - pub fn git_submodule_head_id(submodule: *mut git_submodule) -> *const git_oid; - pub fn git_submodule_ignore(submodule: *mut git_submodule) -> git_submodule_ignore_t; - pub fn git_submodule_index_id(submodule: *mut git_submodule) -> *const git_oid; - pub fn git_submodule_init(submodule: *mut git_submodule, overwrite: c_int) -> c_int; - pub fn git_submodule_repo_init( - repo: *mut *mut git_repository, - submodule: *const git_submodule, - use_gitlink: c_int, - ) -> c_int; - pub fn git_submodule_location(status: *mut c_uint, submodule: *mut git_submodule) -> c_int; - pub fn git_submodule_lookup( - out: *mut *mut git_submodule, - repo: *mut git_repository, - name: *const c_char, - ) -> c_int; - pub fn git_submodule_name(submodule: *mut git_submodule) -> *const c_char; - pub fn git_submodule_open( - repo: *mut *mut git_repository, - submodule: *mut git_submodule, - ) -> c_int; - pub fn git_submodule_path(submodule: *mut git_submodule) -> *const c_char; - pub fn git_submodule_reload(submodule: *mut git_submodule, force: c_int) -> c_int; - pub fn git_submodule_set_ignore( - repo: *mut git_repository, - name: *const c_char, - ignore: git_submodule_ignore_t, - ) -> c_int; - pub fn git_submodule_set_update( - repo: *mut git_repository, - name: *const c_char, - update: git_submodule_update_t, - ) -> c_int; - pub fn git_submodule_set_url( - repo: *mut git_repository, - name: *const c_char, - url: *const c_char, - ) -> c_int; - pub fn git_submodule_sync(submodule: *mut git_submodule) -> c_int; - pub fn git_submodule_update_strategy(submodule: *mut git_submodule) -> git_submodule_update_t; - pub fn git_submodule_update( - submodule: *mut git_submodule, - init: c_int, - options: *mut git_submodule_update_options, - ) -> c_int; - pub fn git_submodule_update_init_options( - options: *mut git_submodule_update_options, - version: c_uint, - ) -> c_int; - pub fn git_submodule_url(submodule: *mut git_submodule) -> *const c_char; - pub fn git_submodule_wd_id(submodule: *mut git_submodule) -> *const git_oid; - pub fn git_submodule_status( - status: *mut c_uint, - repo: *mut git_repository, - name: *const c_char, - ignore: git_submodule_ignore_t, - ) -> c_int; - pub fn git_submodule_set_branch( - repo: *mut git_repository, - name: *const c_char, - branch: *const c_char, - ) -> c_int; - - // blob - pub fn git_blob_free(blob: *mut git_blob); - pub fn git_blob_id(blob: *const git_blob) -> *const git_oid; - pub fn git_blob_is_binary(blob: *const git_blob) -> c_int; - pub fn git_blob_lookup( - blob: *mut *mut git_blob, - repo: *mut git_repository, - id: *const git_oid, - ) -> c_int; - pub fn git_blob_lookup_prefix( - blob: *mut *mut git_blob, - repo: *mut git_repository, - id: *const git_oid, - len: size_t, - ) -> c_int; - pub fn git_blob_rawcontent(blob: *const git_blob) -> *const c_void; - pub fn git_blob_rawsize(blob: *const git_blob) -> git_object_size_t; - pub fn git_blob_create_frombuffer( - id: *mut git_oid, - repo: *mut git_repository, - buffer: *const c_void, - len: size_t, - ) -> c_int; - pub fn git_blob_create_fromdisk( - id: *mut git_oid, - repo: *mut git_repository, - path: *const c_char, - ) -> c_int; - pub fn git_blob_create_fromworkdir( - id: *mut git_oid, - repo: *mut git_repository, - relative_path: *const c_char, - ) -> c_int; - pub fn git_blob_create_fromstream( - out: *mut *mut git_writestream, - repo: *mut git_repository, - hintpath: *const c_char, - ) -> c_int; - pub fn git_blob_create_fromstream_commit( - id: *mut git_oid, - stream: *mut git_writestream, - ) -> c_int; - - // tree - pub fn git_tree_entry_byid(tree: *const git_tree, id: *const git_oid) -> *const git_tree_entry; - pub fn git_tree_entry_byindex(tree: *const git_tree, idx: size_t) -> *const git_tree_entry; - pub fn git_tree_entry_byname( - tree: *const git_tree, - filename: *const c_char, - ) -> *const git_tree_entry; - pub fn git_tree_entry_bypath( - out: *mut *mut git_tree_entry, - tree: *const git_tree, - filename: *const c_char, - ) -> c_int; - pub fn git_tree_entry_cmp(e1: *const git_tree_entry, e2: *const git_tree_entry) -> c_int; - pub fn git_tree_entry_dup(dest: *mut *mut git_tree_entry, src: *const git_tree_entry) -> c_int; - pub fn git_tree_entry_filemode(entry: *const git_tree_entry) -> git_filemode_t; - pub fn git_tree_entry_filemode_raw(entry: *const git_tree_entry) -> git_filemode_t; - pub fn git_tree_entry_free(entry: *mut git_tree_entry); - pub fn git_tree_entry_id(entry: *const git_tree_entry) -> *const git_oid; - pub fn git_tree_entry_name(entry: *const git_tree_entry) -> *const c_char; - pub fn git_tree_entry_to_object( - out: *mut *mut git_object, - repo: *mut git_repository, - entry: *const git_tree_entry, - ) -> c_int; - pub fn git_tree_entry_type(entry: *const git_tree_entry) -> git_object_t; - pub fn git_tree_entrycount(tree: *const git_tree) -> size_t; - pub fn git_tree_free(tree: *mut git_tree); - pub fn git_tree_id(tree: *const git_tree) -> *const git_oid; - pub fn git_tree_lookup( - tree: *mut *mut git_tree, - repo: *mut git_repository, - id: *const git_oid, - ) -> c_int; - pub fn git_tree_walk( - tree: *const git_tree, - mode: git_treewalk_mode, - callback: git_treewalk_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_tree_create_updated( - out: *mut git_oid, - repo: *mut git_repository, - baseline: *mut git_tree, - nupdates: usize, - updates: *const git_tree_update, - ) -> c_int; - - // treebuilder - pub fn git_treebuilder_new( - out: *mut *mut git_treebuilder, - repo: *mut git_repository, - source: *const git_tree, - ) -> c_int; - pub fn git_treebuilder_clear(bld: *mut git_treebuilder) -> c_int; - pub fn git_treebuilder_entrycount(bld: *mut git_treebuilder) -> size_t; - pub fn git_treebuilder_free(bld: *mut git_treebuilder); - pub fn git_treebuilder_get( - bld: *mut git_treebuilder, - filename: *const c_char, - ) -> *const git_tree_entry; - pub fn git_treebuilder_insert( - out: *mut *const git_tree_entry, - bld: *mut git_treebuilder, - filename: *const c_char, - id: *const git_oid, - filemode: git_filemode_t, - ) -> c_int; - pub fn git_treebuilder_remove(bld: *mut git_treebuilder, filename: *const c_char) -> c_int; - pub fn git_treebuilder_filter( - bld: *mut git_treebuilder, - filter: git_treebuilder_filter_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_treebuilder_write(id: *mut git_oid, bld: *mut git_treebuilder) -> c_int; - - // buf - pub fn git_buf_dispose(buffer: *mut git_buf); - pub fn git_buf_grow(buffer: *mut git_buf, target_size: size_t) -> c_int; - pub fn git_buf_set(buffer: *mut git_buf, data: *const c_void, datalen: size_t) -> c_int; - - // commit - pub fn git_commit_author(commit: *const git_commit) -> *const git_signature; - pub fn git_commit_author_with_mailmap( - out: *mut *mut git_signature, - commit: *const git_commit, - mailmap: *const git_mailmap, - ) -> c_int; - pub fn git_commit_committer(commit: *const git_commit) -> *const git_signature; - pub fn git_commit_committer_with_mailmap( - out: *mut *mut git_signature, - commit: *const git_commit, - mailmap: *const git_mailmap, - ) -> c_int; - pub fn git_commit_free(commit: *mut git_commit); - pub fn git_commit_id(commit: *const git_commit) -> *const git_oid; - pub fn git_commit_lookup( - commit: *mut *mut git_commit, - repo: *mut git_repository, - id: *const git_oid, - ) -> c_int; - pub fn git_commit_lookup_prefix( - commit: *mut *mut git_commit, - repo: *mut git_repository, - id: *const git_oid, - len: size_t, - ) -> c_int; - pub fn git_commit_message(commit: *const git_commit) -> *const c_char; - pub fn git_commit_message_encoding(commit: *const git_commit) -> *const c_char; - pub fn git_commit_message_raw(commit: *const git_commit) -> *const c_char; - pub fn git_commit_nth_gen_ancestor( - ancestor: *mut *mut git_commit, - commit: *const git_commit, - n: c_uint, - ) -> c_int; - pub fn git_commit_parent( - out: *mut *mut git_commit, - commit: *const git_commit, - n: c_uint, - ) -> c_int; - pub fn git_commit_parent_id(commit: *const git_commit, n: c_uint) -> *const git_oid; - pub fn git_commit_parentcount(commit: *const git_commit) -> c_uint; - pub fn git_commit_raw_header(commit: *const git_commit) -> *const c_char; - pub fn git_commit_summary(commit: *mut git_commit) -> *const c_char; - pub fn git_commit_body(commit: *mut git_commit) -> *const c_char; - pub fn git_commit_time(commit: *const git_commit) -> git_time_t; - pub fn git_commit_time_offset(commit: *const git_commit) -> c_int; - pub fn git_commit_tree(tree_out: *mut *mut git_tree, commit: *const git_commit) -> c_int; - pub fn git_commit_tree_id(commit: *const git_commit) -> *const git_oid; - pub fn git_commit_amend( - id: *mut git_oid, - commit_to_amend: *const git_commit, - update_ref: *const c_char, - author: *const git_signature, - committer: *const git_signature, - message_encoding: *const c_char, - message: *const c_char, - tree: *const git_tree, - ) -> c_int; - pub fn git_commit_create( - id: *mut git_oid, - repo: *mut git_repository, - update_ref: *const c_char, - author: *const git_signature, - committer: *const git_signature, - message_encoding: *const c_char, - message: *const c_char, - tree: *const git_tree, - parent_count: size_t, - parents: *mut *const git_commit, - ) -> c_int; - pub fn git_commit_create_buffer( - out: *mut git_buf, - repo: *mut git_repository, - author: *const git_signature, - committer: *const git_signature, - message_encoding: *const c_char, - message: *const c_char, - tree: *const git_tree, - parent_count: size_t, - parents: *mut *const git_commit, - ) -> c_int; - pub fn git_commit_header_field( - out: *mut git_buf, - commit: *const git_commit, - field: *const c_char, - ) -> c_int; - pub fn git_annotated_commit_lookup( - out: *mut *mut git_annotated_commit, - repo: *mut git_repository, - id: *const git_oid, - ) -> c_int; - pub fn git_commit_create_with_signature( - id: *mut git_oid, - repo: *mut git_repository, - commit_content: *const c_char, - signature: *const c_char, - signature_field: *const c_char, - ) -> c_int; - pub fn git_commit_extract_signature( - signature: *mut git_buf, - signed_data: *mut git_buf, - repo: *mut git_repository, - commit_id: *mut git_oid, - field: *const c_char, - ) -> c_int; - - // branch - pub fn git_branch_create( - out: *mut *mut git_reference, - repo: *mut git_repository, - branch_name: *const c_char, - target: *const git_commit, - force: c_int, - ) -> c_int; - pub fn git_branch_create_from_annotated( - ref_out: *mut *mut git_reference, - repository: *mut git_repository, - branch_name: *const c_char, - commit: *const git_annotated_commit, - force: c_int, - ) -> c_int; - pub fn git_branch_delete(branch: *mut git_reference) -> c_int; - pub fn git_branch_is_head(branch: *const git_reference) -> c_int; - pub fn git_branch_iterator_free(iter: *mut git_branch_iterator); - pub fn git_branch_iterator_new( - iter: *mut *mut git_branch_iterator, - repo: *mut git_repository, - list_flags: git_branch_t, - ) -> c_int; - pub fn git_branch_lookup( - out: *mut *mut git_reference, - repo: *mut git_repository, - branch_name: *const c_char, - branch_type: git_branch_t, - ) -> c_int; - pub fn git_branch_move( - out: *mut *mut git_reference, - branch: *mut git_reference, - new_branch_name: *const c_char, - force: c_int, - ) -> c_int; - pub fn git_branch_name(out: *mut *const c_char, branch: *const git_reference) -> c_int; - pub fn git_branch_name_is_valid(valid: *mut c_int, name: *const c_char) -> c_int; - pub fn git_branch_remote_name( - out: *mut git_buf, - repo: *mut git_repository, - refname: *const c_char, - ) -> c_int; - pub fn git_branch_next( - out: *mut *mut git_reference, - out_type: *mut git_branch_t, - iter: *mut git_branch_iterator, - ) -> c_int; - pub fn git_branch_set_upstream( - branch: *mut git_reference, - upstream_name: *const c_char, - ) -> c_int; - pub fn git_branch_upstream(out: *mut *mut git_reference, branch: *const git_reference) - -> c_int; - pub fn git_branch_upstream_name( - out: *mut git_buf, - repo: *mut git_repository, - refname: *const c_char, - ) -> c_int; - pub fn git_branch_upstream_remote( - out: *mut git_buf, - repo: *mut git_repository, - refname: *const c_char, - ) -> c_int; - pub fn git_branch_upstream_merge( - out: *mut git_buf, - repo: *mut git_repository, - refname: *const c_char, - ) -> c_int; - - // index - pub fn git_index_version(index: *mut git_index) -> c_uint; - pub fn git_index_set_version(index: *mut git_index, version: c_uint) -> c_int; - pub fn git_index_add(index: *mut git_index, entry: *const git_index_entry) -> c_int; - pub fn git_index_add_all( - index: *mut git_index, - pathspec: *const git_strarray, - flags: c_uint, - callback: git_index_matched_path_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_index_add_bypath(index: *mut git_index, path: *const c_char) -> c_int; - pub fn git_index_add_frombuffer( - index: *mut git_index, - entry: *const git_index_entry, - buffer: *const c_void, - len: size_t, - ) -> c_int; - pub fn git_index_conflict_add( - index: *mut git_index, - ancestor_entry: *const git_index_entry, - our_entry: *const git_index_entry, - their_entry: *const git_index_entry, - ) -> c_int; - pub fn git_index_conflict_remove(index: *mut git_index, path: *const c_char) -> c_int; - pub fn git_index_conflict_get( - ancestor_out: *mut *const git_index_entry, - our_out: *mut *const git_index_entry, - their_out: *mut *const git_index_entry, - index: *mut git_index, - path: *const c_char, - ) -> c_int; - pub fn git_index_conflict_iterator_new( - iter: *mut *mut git_index_conflict_iterator, - index: *mut git_index, - ) -> c_int; - pub fn git_index_conflict_next( - ancestor_out: *mut *const git_index_entry, - our_out: *mut *const git_index_entry, - their_out: *mut *const git_index_entry, - iter: *mut git_index_conflict_iterator, - ) -> c_int; - pub fn git_index_conflict_iterator_free(iter: *mut git_index_conflict_iterator); - pub fn git_index_clear(index: *mut git_index) -> c_int; - pub fn git_index_entry_stage(entry: *const git_index_entry) -> c_int; - pub fn git_index_entrycount(entry: *const git_index) -> size_t; - pub fn git_index_find(at_pos: *mut size_t, index: *mut git_index, path: *const c_char) - -> c_int; - pub fn git_index_find_prefix( - at_pos: *mut size_t, - index: *mut git_index, - prefix: *const c_char, - ) -> c_int; - pub fn git_index_free(index: *mut git_index); - pub fn git_index_get_byindex(index: *mut git_index, n: size_t) -> *const git_index_entry; - pub fn git_index_get_bypath( - index: *mut git_index, - path: *const c_char, - stage: c_int, - ) -> *const git_index_entry; - pub fn git_index_has_conflicts(index: *const git_index) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_index_new(index: *mut *mut git_index) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_index_new(index: *mut *mut git_index, opts: *const git_index_options) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_index_open(index: *mut *mut git_index, index_path: *const c_char) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_index_open( - index: *mut *mut git_index, - index_path: *const c_char, - opts: *const git_index_options, - ) -> c_int; - // #[cfg(feature = "unstable-sha256")] - // pub fn git_index_options_init(opts: *mut git_index_options, version: c_uint) -> c_int; - pub fn git_index_path(index: *const git_index) -> *const c_char; - pub fn git_index_read(index: *mut git_index, force: c_int) -> c_int; - pub fn git_index_read_tree(index: *mut git_index, tree: *const git_tree) -> c_int; - pub fn git_index_remove(index: *mut git_index, path: *const c_char, stage: c_int) -> c_int; - pub fn git_index_remove_all( - index: *mut git_index, - pathspec: *const git_strarray, - callback: git_index_matched_path_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_index_remove_bypath(index: *mut git_index, path: *const c_char) -> c_int; - pub fn git_index_remove_directory( - index: *mut git_index, - dir: *const c_char, - stage: c_int, - ) -> c_int; - pub fn git_index_update_all( - index: *mut git_index, - pathspec: *const git_strarray, - callback: git_index_matched_path_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_index_write(index: *mut git_index) -> c_int; - pub fn git_index_write_tree(out: *mut git_oid, index: *mut git_index) -> c_int; - pub fn git_index_write_tree_to( - out: *mut git_oid, - index: *mut git_index, - repo: *mut git_repository, - ) -> c_int; - - // config - pub fn git_config_add_backend( - cfg: *mut git_config, - file: *mut git_config_backend, - level: git_config_level_t, - repo: *const git_repository, - force: c_int, - ) -> c_int; - pub fn git_config_add_file_ondisk( - cfg: *mut git_config, - path: *const c_char, - level: git_config_level_t, - repo: *const git_repository, - force: c_int, - ) -> c_int; - pub fn git_config_delete_entry(cfg: *mut git_config, name: *const c_char) -> c_int; - pub fn git_config_delete_multivar( - cfg: *mut git_config, - name: *const c_char, - regexp: *const c_char, - ) -> c_int; - pub fn git_config_find_programdata(out: *mut git_buf) -> c_int; - pub fn git_config_find_global(out: *mut git_buf) -> c_int; - pub fn git_config_find_system(out: *mut git_buf) -> c_int; - pub fn git_config_find_xdg(out: *mut git_buf) -> c_int; - pub fn git_config_free(cfg: *mut git_config); - pub fn git_config_get_bool( - out: *mut c_int, - cfg: *const git_config, - name: *const c_char, - ) -> c_int; - pub fn git_config_get_entry( - out: *mut *mut git_config_entry, - cfg: *const git_config, - name: *const c_char, - ) -> c_int; - pub fn git_config_get_int32( - out: *mut i32, - cfg: *const git_config, - name: *const c_char, - ) -> c_int; - pub fn git_config_get_int64( - out: *mut i64, - cfg: *const git_config, - name: *const c_char, - ) -> c_int; - pub fn git_config_get_string( - out: *mut *const c_char, - cfg: *const git_config, - name: *const c_char, - ) -> c_int; - pub fn git_config_get_string_buf( - out: *mut git_buf, - cfg: *const git_config, - name: *const c_char, - ) -> c_int; - pub fn git_config_get_path( - out: *mut git_buf, - cfg: *const git_config, - name: *const c_char, - ) -> c_int; - pub fn git_config_init_backend(backend: *mut git_config_backend, version: c_uint) -> c_int; - pub fn git_config_iterator_free(iter: *mut git_config_iterator); - pub fn git_config_iterator_glob_new( - out: *mut *mut git_config_iterator, - cfg: *const git_config, - regexp: *const c_char, - ) -> c_int; - pub fn git_config_iterator_new( - out: *mut *mut git_config_iterator, - cfg: *const git_config, - ) -> c_int; - pub fn git_config_new(out: *mut *mut git_config) -> c_int; - pub fn git_config_next( - entry: *mut *mut git_config_entry, - iter: *mut git_config_iterator, - ) -> c_int; - pub fn git_config_open_default(out: *mut *mut git_config) -> c_int; - pub fn git_config_open_global(out: *mut *mut git_config, config: *mut git_config) -> c_int; - pub fn git_config_open_level( - out: *mut *mut git_config, - parent: *const git_config, - level: git_config_level_t, - ) -> c_int; - pub fn git_config_open_ondisk(out: *mut *mut git_config, path: *const c_char) -> c_int; - pub fn git_config_parse_bool(out: *mut c_int, value: *const c_char) -> c_int; - pub fn git_config_parse_int32(out: *mut i32, value: *const c_char) -> c_int; - pub fn git_config_parse_int64(out: *mut i64, value: *const c_char) -> c_int; - pub fn git_config_set_bool(cfg: *mut git_config, name: *const c_char, value: c_int) -> c_int; - pub fn git_config_set_int32(cfg: *mut git_config, name: *const c_char, value: i32) -> c_int; - pub fn git_config_set_int64(cfg: *mut git_config, name: *const c_char, value: i64) -> c_int; - pub fn git_config_set_multivar( - cfg: *mut git_config, - name: *const c_char, - regexp: *const c_char, - value: *const c_char, - ) -> c_int; - pub fn git_config_set_string( - cfg: *mut git_config, - name: *const c_char, - value: *const c_char, - ) -> c_int; - pub fn git_config_snapshot(out: *mut *mut git_config, config: *mut git_config) -> c_int; - pub fn git_config_entry_free(entry: *mut git_config_entry); - pub fn git_config_multivar_iterator_new( - out: *mut *mut git_config_iterator, - cfg: *const git_config, - name: *const c_char, - regexp: *const c_char, - ) -> c_int; - - // attr - pub fn git_attr_get( - value_out: *mut *const c_char, - repo: *mut git_repository, - flags: u32, - path: *const c_char, - name: *const c_char, - ) -> c_int; - pub fn git_attr_value(value: *const c_char) -> git_attr_value_t; - - // cred - pub fn git_cred_default_new(out: *mut *mut git_cred) -> c_int; - pub fn git_cred_has_username(cred: *mut git_cred) -> c_int; - pub fn git_cred_ssh_custom_new( - out: *mut *mut git_cred, - username: *const c_char, - publickey: *const c_char, - publickey_len: size_t, - sign_callback: git_cred_sign_callback, - payload: *mut c_void, - ) -> c_int; - pub fn git_cred_ssh_interactive_new( - out: *mut *mut git_cred, - username: *const c_char, - prompt_callback: git_cred_ssh_interactive_callback, - payload: *mut c_void, - ) -> c_int; - pub fn git_cred_ssh_key_from_agent(out: *mut *mut git_cred, username: *const c_char) -> c_int; - pub fn git_cred_ssh_key_new( - out: *mut *mut git_cred, - username: *const c_char, - publickey: *const c_char, - privatekey: *const c_char, - passphrase: *const c_char, - ) -> c_int; - pub fn git_cred_ssh_key_memory_new( - out: *mut *mut git_cred, - username: *const c_char, - publickey: *const c_char, - privatekey: *const c_char, - passphrase: *const c_char, - ) -> c_int; - pub fn git_cred_userpass( - cred: *mut *mut git_cred, - url: *const c_char, - user_from_url: *const c_char, - allowed_types: c_uint, - payload: *mut c_void, - ) -> c_int; - pub fn git_cred_userpass_plaintext_new( - out: *mut *mut git_cred, - username: *const c_char, - password: *const c_char, - ) -> c_int; - pub fn git_cred_username_new(cred: *mut *mut git_cred, username: *const c_char) -> c_int; - - // tags - pub fn git_tag_annotation_create( - oid: *mut git_oid, - repo: *mut git_repository, - tag_name: *const c_char, - target: *const git_object, - tagger: *const git_signature, - message: *const c_char, - ) -> c_int; - pub fn git_tag_create( - oid: *mut git_oid, - repo: *mut git_repository, - tag_name: *const c_char, - target: *const git_object, - tagger: *const git_signature, - message: *const c_char, - force: c_int, - ) -> c_int; - pub fn git_tag_create_frombuffer( - oid: *mut git_oid, - repo: *mut git_repository, - buffer: *const c_char, - force: c_int, - ) -> c_int; - pub fn git_tag_create_lightweight( - oid: *mut git_oid, - repo: *mut git_repository, - tag_name: *const c_char, - target: *const git_object, - force: c_int, - ) -> c_int; - pub fn git_tag_delete(repo: *mut git_repository, tag_name: *const c_char) -> c_int; - pub fn git_tag_foreach( - repo: *mut git_repository, - callback: git_tag_foreach_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_tag_free(tag: *mut git_tag); - pub fn git_tag_id(tag: *const git_tag) -> *const git_oid; - pub fn git_tag_list(tag_names: *mut git_strarray, repo: *mut git_repository) -> c_int; - pub fn git_tag_list_match( - tag_names: *mut git_strarray, - pattern: *const c_char, - repo: *mut git_repository, - ) -> c_int; - pub fn git_tag_lookup( - out: *mut *mut git_tag, - repo: *mut git_repository, - id: *const git_oid, - ) -> c_int; - pub fn git_tag_lookup_prefix( - out: *mut *mut git_tag, - repo: *mut git_repository, - id: *const git_oid, - len: size_t, - ) -> c_int; - pub fn git_tag_message(tag: *const git_tag) -> *const c_char; - pub fn git_tag_name(tag: *const git_tag) -> *const c_char; - pub fn git_tag_peel(tag_target_out: *mut *mut git_object, tag: *const git_tag) -> c_int; - pub fn git_tag_tagger(tag: *const git_tag) -> *const git_signature; - pub fn git_tag_target(target_out: *mut *mut git_object, tag: *const git_tag) -> c_int; - pub fn git_tag_target_id(tag: *const git_tag) -> *const git_oid; - pub fn git_tag_target_type(tag: *const git_tag) -> git_object_t; - pub fn git_tag_name_is_valid(valid: *mut c_int, tag_name: *const c_char) -> c_int; - - // checkout - pub fn git_checkout_head(repo: *mut git_repository, opts: *const git_checkout_options) - -> c_int; - pub fn git_checkout_index( - repo: *mut git_repository, - index: *mut git_index, - opts: *const git_checkout_options, - ) -> c_int; - pub fn git_checkout_tree( - repo: *mut git_repository, - treeish: *const git_object, - opts: *const git_checkout_options, - ) -> c_int; - pub fn git_checkout_init_options(opts: *mut git_checkout_options, version: c_uint) -> c_int; - - // merge - pub fn git_annotated_commit_id(commit: *const git_annotated_commit) -> *const git_oid; - pub fn git_annotated_commit_ref(commit: *const git_annotated_commit) -> *const c_char; - pub fn git_annotated_commit_from_ref( - out: *mut *mut git_annotated_commit, - repo: *mut git_repository, - reference: *const git_reference, - ) -> c_int; - pub fn git_annotated_commit_from_fetchhead( - out: *mut *mut git_annotated_commit, - repo: *mut git_repository, - branch_name: *const c_char, - remote_url: *const c_char, - oid: *const git_oid, - ) -> c_int; - pub fn git_annotated_commit_free(commit: *mut git_annotated_commit); - pub fn git_merge_init_options(opts: *mut git_merge_options, version: c_uint) -> c_int; - pub fn git_merge( - repo: *mut git_repository, - their_heads: *mut *const git_annotated_commit, - len: size_t, - merge_opts: *const git_merge_options, - checkout_opts: *const git_checkout_options, - ) -> c_int; - pub fn git_merge_commits( - out: *mut *mut git_index, - repo: *mut git_repository, - our_commit: *const git_commit, - their_commit: *const git_commit, - opts: *const git_merge_options, - ) -> c_int; - pub fn git_merge_trees( - out: *mut *mut git_index, - repo: *mut git_repository, - ancestor_tree: *const git_tree, - our_tree: *const git_tree, - their_tree: *const git_tree, - opts: *const git_merge_options, - ) -> c_int; - pub fn git_merge_file_input_init(opts: *mut git_merge_file_input, version: c_uint) -> c_int; - pub fn git_merge_file_options_init(opts: *mut git_merge_file_options, version: c_uint) - -> c_int; - pub fn git_repository_state_cleanup(repo: *mut git_repository) -> c_int; - - // merge analysis - - pub fn git_merge_analysis( - analysis_out: *mut git_merge_analysis_t, - pref_out: *mut git_merge_preference_t, - repo: *mut git_repository, - their_heads: *mut *const git_annotated_commit, - their_heads_len: usize, - ) -> c_int; - - pub fn git_merge_analysis_for_ref( - analysis_out: *mut git_merge_analysis_t, - pref_out: *mut git_merge_preference_t, - repo: *mut git_repository, - git_reference: *mut git_reference, - their_heads: *mut *const git_annotated_commit, - their_heads_len: usize, - ) -> c_int; - - // notes - pub fn git_note_author(note: *const git_note) -> *const git_signature; - pub fn git_note_committer(note: *const git_note) -> *const git_signature; - pub fn git_note_create( - out: *mut git_oid, - repo: *mut git_repository, - notes_ref: *const c_char, - author: *const git_signature, - committer: *const git_signature, - oid: *const git_oid, - note: *const c_char, - force: c_int, - ) -> c_int; - pub fn git_note_default_ref(out: *mut git_buf, repo: *mut git_repository) -> c_int; - pub fn git_note_free(note: *mut git_note); - pub fn git_note_id(note: *const git_note) -> *const git_oid; - pub fn git_note_iterator_free(it: *mut git_note_iterator); - pub fn git_note_iterator_new( - out: *mut *mut git_note_iterator, - repo: *mut git_repository, - notes_ref: *const c_char, - ) -> c_int; - pub fn git_note_message(note: *const git_note) -> *const c_char; - pub fn git_note_next( - note_id: *mut git_oid, - annotated_id: *mut git_oid, - it: *mut git_note_iterator, - ) -> c_int; - pub fn git_note_read( - out: *mut *mut git_note, - repo: *mut git_repository, - notes_ref: *const c_char, - oid: *const git_oid, - ) -> c_int; - pub fn git_note_remove( - repo: *mut git_repository, - notes_ref: *const c_char, - author: *const git_signature, - committer: *const git_signature, - oid: *const git_oid, - ) -> c_int; - - // blame - pub fn git_blame_buffer( - out: *mut *mut git_blame, - reference: *mut git_blame, - buffer: *const c_char, - buffer_len: size_t, - ) -> c_int; - pub fn git_blame_file( - out: *mut *mut git_blame, - repo: *mut git_repository, - path: *const c_char, - options: *mut git_blame_options, - ) -> c_int; - pub fn git_blame_free(blame: *mut git_blame); - - pub fn git_blame_init_options(opts: *mut git_blame_options, version: c_uint) -> c_int; - pub fn git_blame_get_hunk_count(blame: *mut git_blame) -> u32; - - pub fn git_blame_get_hunk_byline(blame: *mut git_blame, lineno: usize) - -> *const git_blame_hunk; - pub fn git_blame_get_hunk_byindex(blame: *mut git_blame, index: u32) -> *const git_blame_hunk; - - // revwalk - pub fn git_revwalk_new(out: *mut *mut git_revwalk, repo: *mut git_repository) -> c_int; - pub fn git_revwalk_free(walk: *mut git_revwalk); - - pub fn git_revwalk_reset(walk: *mut git_revwalk) -> c_int; - - pub fn git_revwalk_sorting(walk: *mut git_revwalk, sort_mode: c_uint) -> c_int; - - pub fn git_revwalk_push_head(walk: *mut git_revwalk) -> c_int; - pub fn git_revwalk_push(walk: *mut git_revwalk, oid: *const git_oid) -> c_int; - pub fn git_revwalk_push_ref(walk: *mut git_revwalk, refname: *const c_char) -> c_int; - pub fn git_revwalk_push_glob(walk: *mut git_revwalk, glob: *const c_char) -> c_int; - pub fn git_revwalk_push_range(walk: *mut git_revwalk, range: *const c_char) -> c_int; - pub fn git_revwalk_simplify_first_parent(walk: *mut git_revwalk) -> c_int; - - pub fn git_revwalk_hide_head(walk: *mut git_revwalk) -> c_int; - pub fn git_revwalk_hide(walk: *mut git_revwalk, oid: *const git_oid) -> c_int; - pub fn git_revwalk_hide_ref(walk: *mut git_revwalk, refname: *const c_char) -> c_int; - pub fn git_revwalk_hide_glob(walk: *mut git_revwalk, refname: *const c_char) -> c_int; - pub fn git_revwalk_add_hide_cb( - walk: *mut git_revwalk, - hide_cb: git_revwalk_hide_cb, - payload: *mut c_void, - ) -> c_int; - - pub fn git_revwalk_next(out: *mut git_oid, walk: *mut git_revwalk) -> c_int; - - // merge - pub fn git_merge_base( - out: *mut git_oid, - repo: *mut git_repository, - one: *const git_oid, - two: *const git_oid, - ) -> c_int; - - pub fn git_merge_base_many( - out: *mut git_oid, - repo: *mut git_repository, - length: size_t, - input_array: *const git_oid, - ) -> c_int; - - pub fn git_merge_base_octopus( - out: *mut git_oid, - repo: *mut git_repository, - length: size_t, - input_array: *const git_oid, - ) -> c_int; - - pub fn git_merge_bases( - out: *mut git_oidarray, - repo: *mut git_repository, - one: *const git_oid, - two: *const git_oid, - ) -> c_int; - - pub fn git_merge_bases_many( - out: *mut git_oidarray, - repo: *mut git_repository, - length: size_t, - input_array: *const git_oid, - ) -> c_int; - - pub fn git_merge_file_from_index( - out: *mut git_merge_file_result, - repo: *mut git_repository, - ancestor: *const git_index_entry, - ours: *const git_index_entry, - theirs: *const git_index_entry, - opts: *const git_merge_file_options, - ) -> c_int; - - pub fn git_merge_file( - out: *mut git_merge_file_result, - ancestor: *const git_merge_file_input, - ours: *const git_merge_file_input, - theirs: *const git_merge_file_input, - opts: *const git_merge_file_options, - ) -> c_int; - - pub fn git_merge_file_result_free(file_result: *mut git_merge_file_result); - - // pathspec - pub fn git_pathspec_free(ps: *mut git_pathspec); - pub fn git_pathspec_match_diff( - out: *mut *mut git_pathspec_match_list, - diff: *mut git_diff, - flags: u32, - ps: *mut git_pathspec, - ) -> c_int; - pub fn git_pathspec_match_index( - out: *mut *mut git_pathspec_match_list, - index: *mut git_index, - flags: u32, - ps: *mut git_pathspec, - ) -> c_int; - pub fn git_pathspec_match_list_diff_entry( - m: *const git_pathspec_match_list, - pos: size_t, - ) -> *const git_diff_delta; - pub fn git_pathspec_match_list_entry( - m: *const git_pathspec_match_list, - pos: size_t, - ) -> *const c_char; - pub fn git_pathspec_match_list_entrycount(m: *const git_pathspec_match_list) -> size_t; - pub fn git_pathspec_match_list_failed_entry( - m: *const git_pathspec_match_list, - pos: size_t, - ) -> *const c_char; - pub fn git_pathspec_match_list_failed_entrycount(m: *const git_pathspec_match_list) -> size_t; - pub fn git_pathspec_match_list_free(m: *mut git_pathspec_match_list); - pub fn git_pathspec_match_tree( - out: *mut *mut git_pathspec_match_list, - tree: *mut git_tree, - flags: u32, - ps: *mut git_pathspec, - ) -> c_int; - pub fn git_pathspec_match_workdir( - out: *mut *mut git_pathspec_match_list, - repo: *mut git_repository, - flags: u32, - ps: *mut git_pathspec, - ) -> c_int; - pub fn git_pathspec_matches_path( - ps: *const git_pathspec, - flags: u32, - path: *const c_char, - ) -> c_int; - pub fn git_pathspec_new(out: *mut *mut git_pathspec, pathspec: *const git_strarray) -> c_int; - - // diff - pub fn git_diff_blob_to_buffer( - old_blob: *const git_blob, - old_as_path: *const c_char, - buffer: *const c_char, - buffer_len: size_t, - buffer_as_path: *const c_char, - options: *const git_diff_options, - file_cb: git_diff_file_cb, - binary_cb: git_diff_binary_cb, - hunk_cb: git_diff_hunk_cb, - line_cb: git_diff_line_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_diff_blobs( - old_blob: *const git_blob, - old_as_path: *const c_char, - new_blob: *const git_blob, - new_as_path: *const c_char, - options: *const git_diff_options, - file_cb: git_diff_file_cb, - binary_cb: git_diff_binary_cb, - hunk_cb: git_diff_hunk_cb, - line_cb: git_diff_line_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_diff_buffers( - old_buffer: *const c_void, - old_len: size_t, - old_as_path: *const c_char, - new_buffer: *const c_void, - new_len: size_t, - new_as_path: *const c_char, - options: *const git_diff_options, - file_cb: git_diff_file_cb, - binary_cb: git_diff_binary_cb, - hunk_cb: git_diff_hunk_cb, - line_cb: git_diff_line_cb, - payload: *mut c_void, - ) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_diff_from_buffer( - diff: *mut *mut git_diff, - content: *const c_char, - content_len: size_t, - ) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_diff_from_buffer( - diff: *mut *mut git_diff, - content: *const c_char, - content_len: size_t, - opts: *mut git_diff_parse_options, - ) -> c_int; - pub fn git_diff_find_similar( - diff: *mut git_diff, - options: *const git_diff_find_options, - ) -> c_int; - pub fn git_diff_find_init_options(opts: *mut git_diff_find_options, version: c_uint) -> c_int; - pub fn git_diff_foreach( - diff: *mut git_diff, - file_cb: git_diff_file_cb, - binary_cb: git_diff_binary_cb, - hunk_cb: git_diff_hunk_cb, - line_cb: git_diff_line_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_diff_free(diff: *mut git_diff); - pub fn git_diff_get_delta(diff: *const git_diff, idx: size_t) -> *const git_diff_delta; - pub fn git_diff_get_stats(out: *mut *mut git_diff_stats, diff: *mut git_diff) -> c_int; - pub fn git_diff_index_to_index( - diff: *mut *mut git_diff, - repo: *mut git_repository, - old_index: *mut git_index, - new_index: *mut git_index, - opts: *const git_diff_options, - ) -> c_int; - pub fn git_diff_index_to_workdir( - diff: *mut *mut git_diff, - repo: *mut git_repository, - index: *mut git_index, - opts: *const git_diff_options, - ) -> c_int; - pub fn git_diff_init_options(opts: *mut git_diff_options, version: c_uint) -> c_int; - pub fn git_diff_is_sorted_icase(diff: *const git_diff) -> c_int; - pub fn git_diff_merge(onto: *mut git_diff, from: *const git_diff) -> c_int; - pub fn git_diff_num_deltas(diff: *const git_diff) -> size_t; - pub fn git_diff_num_deltas_of_type(diff: *const git_diff, delta: git_delta_t) -> size_t; - pub fn git_diff_print( - diff: *mut git_diff, - format: git_diff_format_t, - print_cb: git_diff_line_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_diff_stats_deletions(stats: *const git_diff_stats) -> size_t; - pub fn git_diff_stats_files_changed(stats: *const git_diff_stats) -> size_t; - pub fn git_diff_stats_free(stats: *mut git_diff_stats); - pub fn git_diff_stats_insertions(stats: *const git_diff_stats) -> size_t; - pub fn git_diff_stats_to_buf( - out: *mut git_buf, - stats: *const git_diff_stats, - format: git_diff_stats_format_t, - width: size_t, - ) -> c_int; - pub fn git_diff_status_char(status: git_delta_t) -> c_char; - pub fn git_diff_tree_to_index( - diff: *mut *mut git_diff, - repo: *mut git_repository, - old_tree: *mut git_tree, - index: *mut git_index, - opts: *const git_diff_options, - ) -> c_int; - pub fn git_diff_tree_to_tree( - diff: *mut *mut git_diff, - repo: *mut git_repository, - old_tree: *mut git_tree, - new_tree: *mut git_tree, - opts: *const git_diff_options, - ) -> c_int; - pub fn git_diff_tree_to_workdir( - diff: *mut *mut git_diff, - repo: *mut git_repository, - old_tree: *mut git_tree, - opts: *const git_diff_options, - ) -> c_int; - pub fn git_diff_tree_to_workdir_with_index( - diff: *mut *mut git_diff, - repo: *mut git_repository, - old_tree: *mut git_tree, - opts: *const git_diff_options, - ) -> c_int; - - pub fn git_graph_ahead_behind( - ahead: *mut size_t, - behind: *mut size_t, - repo: *mut git_repository, - local: *const git_oid, - upstream: *const git_oid, - ) -> c_int; - - pub fn git_graph_descendant_of( - repo: *mut git_repository, - commit: *const git_oid, - ancestor: *const git_oid, - ) -> c_int; - - pub fn git_diff_format_email( - out: *mut git_buf, - diff: *mut git_diff, - opts: *const git_diff_format_email_options, - ) -> c_int; - pub fn git_diff_format_email_options_init( - opts: *mut git_diff_format_email_options, - version: c_uint, - ) -> c_int; - - pub fn git_diff_patchid( - out: *mut git_oid, - diff: *mut git_diff, - opts: *mut git_diff_patchid_options, - ) -> c_int; - pub fn git_diff_patchid_options_init( - opts: *mut git_diff_patchid_options, - version: c_uint, - ) -> c_int; - - // patch - pub fn git_patch_from_diff(out: *mut *mut git_patch, diff: *mut git_diff, idx: size_t) - -> c_int; - pub fn git_patch_from_blobs( - out: *mut *mut git_patch, - old_blob: *const git_blob, - old_as_path: *const c_char, - new_blob: *const git_blob, - new_as_path: *const c_char, - opts: *const git_diff_options, - ) -> c_int; - pub fn git_patch_from_blob_and_buffer( - out: *mut *mut git_patch, - old_blob: *const git_blob, - old_as_path: *const c_char, - buffer: *const c_void, - buffer_len: size_t, - buffer_as_path: *const c_char, - opts: *const git_diff_options, - ) -> c_int; - pub fn git_patch_from_buffers( - out: *mut *mut git_patch, - old_buffer: *const c_void, - old_len: size_t, - old_as_path: *const c_char, - new_buffer: *const c_void, - new_len: size_t, - new_as_path: *const c_char, - opts: *const git_diff_options, - ) -> c_int; - pub fn git_patch_free(patch: *mut git_patch); - pub fn git_patch_get_delta(patch: *const git_patch) -> *const git_diff_delta; - pub fn git_patch_num_hunks(patch: *const git_patch) -> size_t; - pub fn git_patch_line_stats( - total_context: *mut size_t, - total_additions: *mut size_t, - total_deletions: *mut size_t, - patch: *const git_patch, - ) -> c_int; - pub fn git_patch_get_hunk( - out: *mut *const git_diff_hunk, - lines_in_hunk: *mut size_t, - patch: *mut git_patch, - hunk_idx: size_t, - ) -> c_int; - pub fn git_patch_num_lines_in_hunk(patch: *const git_patch, hunk_idx: size_t) -> c_int; - pub fn git_patch_get_line_in_hunk( - out: *mut *const git_diff_line, - patch: *mut git_patch, - hunk_idx: size_t, - line_of_hunk: size_t, - ) -> c_int; - pub fn git_patch_size( - patch: *mut git_patch, - include_context: c_int, - include_hunk_headers: c_int, - include_file_headers: c_int, - ) -> size_t; - pub fn git_patch_print( - patch: *mut git_patch, - print_cb: git_diff_line_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_patch_to_buf(buf: *mut git_buf, patch: *mut git_patch) -> c_int; - - // reflog - pub fn git_reflog_append( - reflog: *mut git_reflog, - id: *const git_oid, - committer: *const git_signature, - msg: *const c_char, - ) -> c_int; - pub fn git_reflog_delete(repo: *mut git_repository, name: *const c_char) -> c_int; - pub fn git_reflog_drop( - reflog: *mut git_reflog, - idx: size_t, - rewrite_previous_entry: c_int, - ) -> c_int; - pub fn git_reflog_entry_byindex( - reflog: *const git_reflog, - idx: size_t, - ) -> *const git_reflog_entry; - pub fn git_reflog_entry_committer(entry: *const git_reflog_entry) -> *const git_signature; - pub fn git_reflog_entry_id_new(entry: *const git_reflog_entry) -> *const git_oid; - pub fn git_reflog_entry_id_old(entry: *const git_reflog_entry) -> *const git_oid; - pub fn git_reflog_entry_message(entry: *const git_reflog_entry) -> *const c_char; - pub fn git_reflog_entrycount(reflog: *mut git_reflog) -> size_t; - pub fn git_reflog_free(reflog: *mut git_reflog); - pub fn git_reflog_read( - out: *mut *mut git_reflog, - repo: *mut git_repository, - name: *const c_char, - ) -> c_int; - pub fn git_reflog_rename( - repo: *mut git_repository, - old_name: *const c_char, - name: *const c_char, - ) -> c_int; - pub fn git_reflog_write(reflog: *mut git_reflog) -> c_int; - - // transport - pub fn git_transport_register( - prefix: *const c_char, - cb: git_transport_cb, - param: *mut c_void, - ) -> c_int; - pub fn git_transport_unregister(prefix: *const c_char) -> c_int; - pub fn git_transport_smart( - out: *mut *mut git_transport, - owner: *mut git_remote, - payload: *mut c_void, - ) -> c_int; - - // describe - pub fn git_describe_commit( - result: *mut *mut git_describe_result, - object: *mut git_object, - opts: *mut git_describe_options, - ) -> c_int; - pub fn git_describe_format( - buf: *mut git_buf, - result: *const git_describe_result, - opts: *const git_describe_format_options, - ) -> c_int; - pub fn git_describe_result_free(result: *mut git_describe_result); - pub fn git_describe_workdir( - out: *mut *mut git_describe_result, - repo: *mut git_repository, - opts: *mut git_describe_options, - ) -> c_int; - - // message - pub fn git_message_prettify( - out: *mut git_buf, - message: *const c_char, - strip_comments: c_int, - comment_char: c_char, - ) -> c_int; - - pub fn git_message_trailers( - out: *mut git_message_trailer_array, - message: *const c_char, - ) -> c_int; - - pub fn git_message_trailer_array_free(trailer: *mut git_message_trailer_array); - - // packbuilder - pub fn git_packbuilder_new(out: *mut *mut git_packbuilder, repo: *mut git_repository) -> c_int; - pub fn git_packbuilder_set_threads(pb: *mut git_packbuilder, n: c_uint) -> c_uint; - pub fn git_packbuilder_insert( - pb: *mut git_packbuilder, - id: *const git_oid, - name: *const c_char, - ) -> c_int; - pub fn git_packbuilder_insert_tree(pb: *mut git_packbuilder, id: *const git_oid) -> c_int; - pub fn git_packbuilder_insert_commit(pb: *mut git_packbuilder, id: *const git_oid) -> c_int; - pub fn git_packbuilder_insert_walk(pb: *mut git_packbuilder, walk: *mut git_revwalk) -> c_int; - pub fn git_packbuilder_insert_recur( - pb: *mut git_packbuilder, - id: *const git_oid, - name: *const c_char, - ) -> c_int; - pub fn git_packbuilder_write_buf(buf: *mut git_buf, pb: *mut git_packbuilder) -> c_int; - pub fn git_packbuilder_write( - pb: *mut git_packbuilder, - path: *const c_char, - mode: c_uint, - progress_cb: git_indexer_progress_cb, - progress_cb_payload: *mut c_void, - ) -> c_int; - #[deprecated = "use `git_packbuilder_name` to retrieve the filename"] - pub fn git_packbuilder_hash(pb: *mut git_packbuilder) -> *const git_oid; - pub fn git_packbuilder_name(pb: *mut git_packbuilder) -> *const c_char; - pub fn git_packbuilder_foreach( - pb: *mut git_packbuilder, - cb: git_packbuilder_foreach_cb, - payload: *mut c_void, - ) -> c_int; - pub fn git_packbuilder_object_count(pb: *mut git_packbuilder) -> size_t; - pub fn git_packbuilder_written(pb: *mut git_packbuilder) -> size_t; - pub fn git_packbuilder_set_callbacks( - pb: *mut git_packbuilder, - progress_cb: git_packbuilder_progress, - progress_cb_payload: *mut c_void, - ) -> c_int; - pub fn git_packbuilder_free(pb: *mut git_packbuilder); - - // indexer - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_indexer_new( - out: *mut *mut git_indexer, - path: *const c_char, - mode: c_uint, - odb: *mut git_odb, - opts: *mut git_indexer_options, - ) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_indexer_new( - out: *mut *mut git_indexer, - path: *const c_char, - opts: *mut git_indexer_options, - ) -> c_int; - pub fn git_indexer_append( - idx: *mut git_indexer, - data: *const c_void, - size: size_t, - stats: *mut git_indexer_progress, - ) -> c_int; - pub fn git_indexer_commit(idx: *mut git_indexer, stats: *mut git_indexer_progress) -> c_int; - #[deprecated = "use `git_indexer_name` to retrieve the filename"] - pub fn git_indexer_hash(idx: *const git_indexer) -> *const git_oid; - pub fn git_indexer_name(idx: *const git_indexer) -> *const c_char; - pub fn git_indexer_free(idx: *mut git_indexer); - - pub fn git_indexer_options_init(opts: *mut git_indexer_options, version: c_uint) -> c_int; - - // odb - pub fn git_repository_odb(out: *mut *mut git_odb, repo: *mut git_repository) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_odb_new(db: *mut *mut git_odb) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_odb_new(db: *mut *mut git_odb, opts: *const git_odb_options) -> c_int; - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_odb_open(out: *mut *mut git_odb, objects_dir: *const c_char) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_odb_open( - out: *mut *mut git_odb, - objects_dir: *const c_char, - opts: *const git_odb_options, - ) -> c_int; - pub fn git_odb_free(db: *mut git_odb); - pub fn git_odb_open_rstream( - out: *mut *mut git_odb_stream, - len: *mut size_t, - otype: *mut git_object_t, - db: *mut git_odb, - oid: *const git_oid, - ) -> c_int; - pub fn git_odb_stream_read( - stream: *mut git_odb_stream, - buffer: *mut c_char, - len: size_t, - ) -> c_int; - pub fn git_odb_open_wstream( - out: *mut *mut git_odb_stream, - db: *mut git_odb, - size: git_object_size_t, - obj_type: git_object_t, - ) -> c_int; - pub fn git_odb_stream_write( - stream: *mut git_odb_stream, - buffer: *const c_char, - len: size_t, - ) -> c_int; - pub fn git_odb_stream_finalize_write(id: *mut git_oid, stream: *mut git_odb_stream) -> c_int; - pub fn git_odb_stream_free(stream: *mut git_odb_stream); - pub fn git_odb_foreach(db: *mut git_odb, cb: git_odb_foreach_cb, payload: *mut c_void) - -> c_int; - - pub fn git_odb_read( - out: *mut *mut git_odb_object, - odb: *mut git_odb, - oid: *const git_oid, - ) -> c_int; - - pub fn git_odb_read_header( - len_out: *mut size_t, - type_out: *mut git_object_t, - odb: *mut git_odb, - oid: *const git_oid, - ) -> c_int; - - pub fn git_odb_write( - out: *mut git_oid, - odb: *mut git_odb, - data: *const c_void, - len: size_t, - otype: git_object_t, - ) -> c_int; - - pub fn git_odb_write_pack( - out: *mut *mut git_odb_writepack, - odb: *mut git_odb, - progress_cb: git_indexer_progress_cb, - progress_payload: *mut c_void, - ) -> c_int; - - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_odb_hash( - out: *mut git_oid, - data: *const c_void, - len: size_t, - otype: git_object_t, - ) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_odb_hash( - out: *mut git_oid, - data: *const c_void, - len: size_t, - otype: git_object_t, - oid_type: git_oid_t, - ) -> c_int; - - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_odb_hashfile(out: *mut git_oid, path: *const c_char, otype: git_object_t) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_odb_hashfile( - out: *mut git_oid, - path: *const c_char, - otype: git_object_t, - oid_type: git_oid_t, - ) -> c_int; - - pub fn git_odb_exists_prefix( - out: *mut git_oid, - odb: *mut git_odb, - short_oid: *const git_oid, - len: size_t, - ) -> c_int; - - pub fn git_odb_exists(odb: *mut git_odb, oid: *const git_oid) -> c_int; - pub fn git_odb_exists_ext(odb: *mut git_odb, oid: *const git_oid, flags: c_uint) -> c_int; - - pub fn git_odb_refresh(odb: *mut git_odb) -> c_int; - - pub fn git_odb_object_id(obj: *mut git_odb_object) -> *const git_oid; - pub fn git_odb_object_size(obj: *mut git_odb_object) -> size_t; - pub fn git_odb_object_type(obj: *mut git_odb_object) -> git_object_t; - pub fn git_odb_object_data(obj: *mut git_odb_object) -> *const c_void; - pub fn git_odb_object_dup(out: *mut *mut git_odb_object, obj: *mut git_odb_object) -> c_int; - pub fn git_odb_object_free(obj: *mut git_odb_object); - - pub fn git_odb_init_backend(odb: *mut git_odb_backend, version: c_uint) -> c_int; - - pub fn git_odb_add_backend( - odb: *mut git_odb, - backend: *mut git_odb_backend, - priority: c_int, - ) -> c_int; - - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_odb_backend_pack( - out: *mut *mut git_odb_backend, - objects_dir: *const c_char, - ) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_odb_backend_pack( - out: *mut *mut git_odb_backend, - objects_dir: *const c_char, - opts: *const git_odb_backend_pack_options, - ) -> c_int; - - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_odb_backend_one_pack( - out: *mut *mut git_odb_backend, - index_file: *const c_char, - ) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_odb_backend_one_pack( - out: *mut *mut git_odb_backend, - index_file: *const c_char, - opts: *const git_odb_backend_pack_options, - ) -> c_int; - - pub fn git_odb_add_disk_alternate(odb: *mut git_odb, path: *const c_char) -> c_int; - - #[cfg(not(feature = "unstable-sha256"))] - pub fn git_odb_backend_loose( - out: *mut *mut git_odb_backend, - objects_dir: *const c_char, - compression_level: c_int, - do_fsync: c_int, - dir_mode: c_uint, - file_mode: c_uint, - ) -> c_int; - #[cfg(feature = "unstable-sha256")] - pub fn git_odb_backend_loose( - out: *mut *mut git_odb_backend, - objects_dir: *const c_char, - opts: *mut git_odb_backend_loose_options, - ) -> c_int; - - pub fn git_odb_add_alternate( - odb: *mut git_odb, - backend: *mut git_odb_backend, - priority: c_int, - ) -> c_int; - - #[deprecated(note = "only kept for compatibility; prefer git_odb_backend_data_alloc")] - pub fn git_odb_backend_malloc(backend: *mut git_odb_backend, len: size_t) -> *mut c_void; - - pub fn git_odb_backend_data_alloc(backend: *mut git_odb_backend, len: size_t) -> *mut c_void; - pub fn git_odb_backend_data_free(backend: *mut git_odb_backend, data: *mut c_void); - - pub fn git_odb_num_backends(odb: *mut git_odb) -> size_t; - pub fn git_odb_get_backend( - backend: *mut *mut git_odb_backend, - odb: *mut git_odb, - position: size_t, - ) -> c_int; - - // mempack - pub fn git_mempack_new(out: *mut *mut git_odb_backend) -> c_int; - pub fn git_mempack_reset(backend: *mut git_odb_backend) -> c_int; - pub fn git_mempack_dump( - pack: *mut git_buf, - repo: *mut git_repository, - backend: *mut git_odb_backend, - ) -> c_int; - - // refdb - pub fn git_refdb_new(out: *mut *mut git_refdb, repo: *mut git_repository) -> c_int; - pub fn git_refdb_open(out: *mut *mut git_refdb, repo: *mut git_repository) -> c_int; - pub fn git_refdb_backend_fs( - out: *mut *mut git_refdb_backend, - repo: *mut git_repository, - ) -> c_int; - pub fn git_refdb_init_backend(backend: *mut git_refdb_backend, version: c_uint) -> c_int; - pub fn git_refdb_set_backend(refdb: *mut git_refdb, backend: *mut git_refdb_backend) -> c_int; - pub fn git_refdb_compress(refdb: *mut git_refdb) -> c_int; - pub fn git_refdb_free(refdb: *mut git_refdb); - - // rebase - pub fn git_rebase_init_options(opts: *mut git_rebase_options, version: c_uint) -> c_int; - pub fn git_rebase_init( - out: *mut *mut git_rebase, - repo: *mut git_repository, - branch: *const git_annotated_commit, - upstream: *const git_annotated_commit, - onto: *const git_annotated_commit, - opts: *const git_rebase_options, - ) -> c_int; - pub fn git_rebase_open( - out: *mut *mut git_rebase, - repo: *mut git_repository, - opts: *const git_rebase_options, - ) -> c_int; - pub fn git_rebase_operation_entrycount(rebase: *mut git_rebase) -> size_t; - pub fn git_rebase_operation_current(rebase: *mut git_rebase) -> size_t; - pub fn git_rebase_operation_byindex( - rebase: *mut git_rebase, - idx: size_t, - ) -> *mut git_rebase_operation; - pub fn git_rebase_orig_head_id(rebase: *mut git_rebase) -> *const git_oid; - pub fn git_rebase_orig_head_name(rebase: *mut git_rebase) -> *const c_char; - pub fn git_rebase_next( - operation: *mut *mut git_rebase_operation, - rebase: *mut git_rebase, - ) -> c_int; - pub fn git_rebase_inmemory_index(index: *mut *mut git_index, rebase: *mut git_rebase) -> c_int; - pub fn git_rebase_commit( - id: *mut git_oid, - rebase: *mut git_rebase, - author: *const git_signature, - committer: *const git_signature, - message_encoding: *const c_char, - message: *const c_char, - ) -> c_int; - pub fn git_rebase_abort(rebase: *mut git_rebase) -> c_int; - pub fn git_rebase_finish(rebase: *mut git_rebase, signature: *const git_signature) -> c_int; - pub fn git_rebase_free(rebase: *mut git_rebase); - - // cherrypick - pub fn git_cherrypick_init_options(opts: *mut git_cherrypick_options, version: c_uint) - -> c_int; - pub fn git_cherrypick( - repo: *mut git_repository, - commit: *mut git_commit, - options: *const git_cherrypick_options, - ) -> c_int; - pub fn git_cherrypick_commit( - out: *mut *mut git_index, - repo: *mut git_repository, - cherrypick_commit: *mut git_commit, - our_commit: *mut git_commit, - mainline: c_uint, - merge_options: *const git_merge_options, - ) -> c_int; - - // apply - pub fn git_apply_options_init(opts: *mut git_apply_options, version: c_uint) -> c_int; - pub fn git_apply_to_tree( - out: *mut *mut git_index, - repo: *mut git_repository, - preimage: *mut git_tree, - diff: *mut git_diff, - options: *const git_apply_options, - ) -> c_int; - pub fn git_apply( - repo: *mut git_repository, - diff: *mut git_diff, - location: git_apply_location_t, - options: *const git_apply_options, - ) -> c_int; - - // revert - pub fn git_revert_options_init(opts: *mut git_revert_options, version: c_uint) -> c_int; - pub fn git_revert_commit( - out: *mut *mut git_index, - repo: *mut git_repository, - revert_commit: *mut git_commit, - our_commit: *mut git_commit, - mainline: c_uint, - merge_options: *const git_merge_options, - ) -> c_int; - pub fn git_revert( - repo: *mut git_repository, - commit: *mut git_commit, - given_opts: *const git_revert_options, - ) -> c_int; - - // Common - pub fn git_libgit2_version(major: *mut c_int, minor: *mut c_int, rev: *mut c_int) -> c_int; - pub fn git_libgit2_features() -> c_int; - pub fn git_libgit2_opts(option: c_int, ...) -> c_int; - - // Worktrees - pub fn git_worktree_list(out: *mut git_strarray, repo: *mut git_repository) -> c_int; - pub fn git_worktree_lookup( - out: *mut *mut git_worktree, - repo: *mut git_repository, - name: *const c_char, - ) -> c_int; - pub fn git_worktree_open_from_repository( - out: *mut *mut git_worktree, - repo: *mut git_repository, - ) -> c_int; - pub fn git_worktree_free(wt: *mut git_worktree); - pub fn git_worktree_validate(wt: *const git_worktree) -> c_int; - pub fn git_worktree_add_options_init( - opts: *mut git_worktree_add_options, - version: c_uint, - ) -> c_int; - pub fn git_worktree_add( - out: *mut *mut git_worktree, - repo: *mut git_repository, - name: *const c_char, - path: *const c_char, - opts: *const git_worktree_add_options, - ) -> c_int; - pub fn git_worktree_lock(wt: *mut git_worktree, reason: *const c_char) -> c_int; - pub fn git_worktree_unlock(wt: *mut git_worktree) -> c_int; - pub fn git_worktree_is_locked(reason: *mut git_buf, wt: *const git_worktree) -> c_int; - pub fn git_worktree_name(wt: *const git_worktree) -> *const c_char; - pub fn git_worktree_path(wt: *const git_worktree) -> *const c_char; - pub fn git_worktree_prune_options_init( - opts: *mut git_worktree_prune_options, - version: c_uint, - ) -> c_int; - pub fn git_worktree_is_prunable( - wt: *mut git_worktree, - opts: *mut git_worktree_prune_options, - ) -> c_int; - pub fn git_worktree_prune( - wt: *mut git_worktree, - opts: *mut git_worktree_prune_options, - ) -> c_int; - - // Ref transactions - pub fn git_transaction_new(out: *mut *mut git_transaction, repo: *mut git_repository) -> c_int; - pub fn git_transaction_lock_ref(tx: *mut git_transaction, refname: *const c_char) -> c_int; - pub fn git_transaction_set_target( - tx: *mut git_transaction, - refname: *const c_char, - target: *const git_oid, - sig: *const git_signature, - msg: *const c_char, - ) -> c_int; - pub fn git_transaction_set_symbolic_target( - tx: *mut git_transaction, - refname: *const c_char, - target: *const c_char, - sig: *const git_signature, - msg: *const c_char, - ) -> c_int; - pub fn git_transaction_set_reflog( - tx: *mut git_transaction, - refname: *const c_char, - reflog: *const git_reflog, - ) -> c_int; - pub fn git_transaction_remove(tx: *mut git_transaction, refname: *const c_char) -> c_int; - pub fn git_transaction_commit(tx: *mut git_transaction) -> c_int; - pub fn git_transaction_free(tx: *mut git_transaction); - - // Mailmap - pub fn git_mailmap_new(out: *mut *mut git_mailmap) -> c_int; - pub fn git_mailmap_from_buffer( - out: *mut *mut git_mailmap, - buf: *const c_char, - len: size_t, - ) -> c_int; - pub fn git_mailmap_from_repository( - out: *mut *mut git_mailmap, - repo: *mut git_repository, - ) -> c_int; - pub fn git_mailmap_free(mm: *mut git_mailmap); - pub fn git_mailmap_resolve_signature( - out: *mut *mut git_signature, - mm: *const git_mailmap, - sig: *const git_signature, - ) -> c_int; - pub fn git_mailmap_add_entry( - mm: *mut git_mailmap, - real_name: *const c_char, - real_email: *const c_char, - replace_name: *const c_char, - replace_email: *const c_char, - ) -> c_int; - - // email - pub fn git_email_create_from_diff( - out: *mut git_buf, - diff: *mut git_diff, - patch_idx: usize, - patch_count: usize, - commit_id: *const git_oid, - summary: *const c_char, - body: *const c_char, - author: *const git_signature, - given_opts: *const git_email_create_options, - ) -> c_int; - - pub fn git_email_create_from_commit( - out: *mut git_buf, - commit: *mut git_commit, - given_opts: *const git_email_create_options, - ) -> c_int; - - pub fn git_trace_set(level: git_trace_level_t, cb: git_trace_cb) -> c_int; -} - -pub fn init() { - use std::sync::Once; - - static INIT: Once = Once::new(); - INIT.call_once(|| unsafe { - openssl_init(); - ssh_init(); - let rc = git_libgit2_init(); - if rc >= 0 { - // Note that we intentionally never schedule `git_libgit2_shutdown` - // to get called. There's not really a great time to call that and - // #276 has some more info about how automatically doing it can - // cause problems. - return; - } - - let git_error = git_error_last(); - let error = if !git_error.is_null() { - CStr::from_ptr((*git_error).message).to_string_lossy() - } else { - "unknown error".into() - }; - panic!( - "couldn't initialize the libgit2 library: {}, error: {}", - rc, error - ); - }); -} - -#[cfg(all(unix, feature = "https"))] -#[doc(hidden)] -pub fn openssl_init() { - openssl_sys::init(); -} - -#[cfg(any(windows, not(feature = "https")))] -#[doc(hidden)] -pub fn openssl_init() {} - -#[cfg(feature = "ssh")] -fn ssh_init() { - libssh2::init(); -} - -#[cfg(not(feature = "ssh"))] -fn ssh_init() {} - -#[doc(hidden)] -pub fn vendored() -> bool { - cfg!(libgit2_vendored) -} - -#[doc(hidden)] -pub fn experimental_features() -> Vec<&'static str> { - let mut features = vec![]; - - if cfg!(libgit2_experimental_sha256) { - features.push("sha256"); - } - - features -} diff --git a/vendor/libgit2-sys/libgit2/.HEADER b/vendor/libgit2-sys/libgit2/.HEADER deleted file mode 100644 index fd8430b..0000000 --- a/vendor/libgit2-sys/libgit2/.HEADER +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ diff --git a/vendor/libgit2-sys/libgit2/.clang-format b/vendor/libgit2-sys/libgit2/.clang-format deleted file mode 100644 index d6e9cfc..0000000 --- a/vendor/libgit2-sys/libgit2/.clang-format +++ /dev/null @@ -1,92 +0,0 @@ -# This file is an example configuration for clang-format 5.0. -# -# Note that this style definition should only be understood as a hint -# for writing new code. The rules are still work-in-progress and does -# not yet exactly match the style we have in the existing code. - -# C Language specifics -Language: Cpp - -# Use tabs whenever we need to fill whitespace that spans at least from one tab -# stop to the next one. -# -# These settings are mirrored in .editorconfig. Keep them in sync. -UseTab: ForIndentation -TabWidth: 8 -IndentWidth: 8 -ContinuationIndentWidth: 8 -ColumnLimit: 80 - -AlignAfterOpenBracket: AlwaysBreak -AlignEscapedNewlines: Left -AlignTrailingComments: false - -# Allow putting parameters onto the next line -AllowAllArgumentsOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false - -# Don't allow short braced statements to be on a single line -# if (a) not if (a) return; -# return; -AllowShortBlocksOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLoopsOnASingleLine: false -AllowShortLambdasOnASingleLine: None - -# Pack as many parameters or arguments onto the same line as possible -# int myFunction(int aaaaaaaaaaaa, int bbbbbbbb, -# int cccc); -BinPackArguments: true -BinPackParameters: false - -BreakBeforeBraces: Linux -BreakBeforeBinaryOperators: None -BreakBeforeTernaryOperators: false -BreakStringLiterals: false - -# The number of spaces before trailing line comments (// - comments). -# This does not affect trailing block comments (/* - comments). -SpacesBeforeTrailingComments: 1 - -# Don't insert spaces in casts -# x = (int32) y; not x = ( int32 ) y; -SpacesInCStyleCastParentheses: false - -# Don't insert spaces inside container literals -# var arr = [1, 2, 3]; not var arr = [ 1, 2, 3 ]; -SpacesInContainerLiterals: false - -# Don't insert spaces after '(' or before ')' -# f(arg); not f( arg ); -SpacesInParentheses: false - -# Don't insert spaces after '[' or before ']' -# int a[5]; not int a[ 5 ]; -SpacesInSquareBrackets: false - -# Insert a space after '{' and before '}' in struct initializers -Cpp11BracedListStyle: false - -# A list of macros that should be interpreted as foreach loops instead of as -# function calls. -ForEachMacros: - - 'git_array_foreach' - - 'git_vector_foreach' - -# The maximum number of consecutive empty lines to keep. -MaxEmptyLinesToKeep: 1 - -# No empty line at the start of a block. -KeepEmptyLinesAtTheStartOfBlocks: false - -# Penalties -# This decides what order things should be done if a line is too long -PenaltyBreakAssignment: 10 -PenaltyBreakBeforeFirstCallParameter: 30 -PenaltyBreakComment: 10 -PenaltyBreakFirstLessLess: 0 -PenaltyBreakString: 10 -PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 60 - -SortIncludes: false diff --git a/vendor/libgit2-sys/libgit2/.devcontainer/devcontainer.json b/vendor/libgit2-sys/libgit2/.devcontainer/devcontainer.json deleted file mode 100644 index bc6344b..0000000 --- a/vendor/libgit2-sys/libgit2/.devcontainer/devcontainer.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "postCreateCommand": "bash .devcontainer/setup.sh" -} diff --git a/vendor/libgit2-sys/libgit2/.devcontainer/setup.sh b/vendor/libgit2-sys/libgit2/.devcontainer/setup.sh deleted file mode 100755 index c328bf3..0000000 --- a/vendor/libgit2-sys/libgit2/.devcontainer/setup.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -set -e - -sudo apt-get update -sudo apt-get -y --no-install-recommends install cmake - -mkdir build -cd build -cmake .. \ No newline at end of file diff --git a/vendor/libgit2-sys/libgit2/.editorconfig b/vendor/libgit2-sys/libgit2/.editorconfig deleted file mode 100644 index 2230fd8..0000000 --- a/vendor/libgit2-sys/libgit2/.editorconfig +++ /dev/null @@ -1,21 +0,0 @@ -; Check http://editorconfig.org/ for more informations -root = true - -[*] -indent_style = tab -tab_width = 8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.yml] -indent_style = space -indent_size = 2 - -[*.md] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -[*.py] -indent_style = space -indent_size = 4 diff --git a/vendor/libgit2-sys/libgit2/.gitattributes b/vendor/libgit2-sys/libgit2/.gitattributes deleted file mode 100644 index 3788dc9..0000000 --- a/vendor/libgit2-sys/libgit2/.gitattributes +++ /dev/null @@ -1,4 +0,0 @@ -* text=auto -ci/**/*.sh text eol=lf -script/**/*.sh text eol=lf -tests/resources/** linguist-vendored diff --git a/vendor/libgit2-sys/libgit2/.github/ISSUE_TEMPLATE b/vendor/libgit2-sys/libgit2/.github/ISSUE_TEMPLATE deleted file mode 100644 index 717f8b9..0000000 --- a/vendor/libgit2-sys/libgit2/.github/ISSUE_TEMPLATE +++ /dev/null @@ -1,19 +0,0 @@ -You are opening a _bug report_ against the libgit2 project: we use -GitHub Issues for tracking bug reports and feature requests. If you -have a question about an API or usage, please ask on StackOverflow: -http://stackoverflow.com/questions/tagged/libgit2. If you want to -have high-level discussions about the libgit2 project itself, visit -https://github.com/libgit2/discussions. - -Otherwise, to report a bug, please fill out the reproduction steps -(below) and delete these introductory paragraphs. Thanks! - -### Reproduction steps - -### Expected behavior - -### Actual behavior - -### Version of libgit2 (release number or SHA1) - -### Operating system(s) tested diff --git a/vendor/libgit2-sys/libgit2/.github/actions/download-or-build-container/action.yml b/vendor/libgit2-sys/libgit2/.github/actions/download-or-build-container/action.yml deleted file mode 100644 index 9c83a98..0000000 --- a/vendor/libgit2-sys/libgit2/.github/actions/download-or-build-container/action.yml +++ /dev/null @@ -1,109 +0,0 @@ -# Run a build step in a container or directly on the Actions runner -name: Download or Build Container -description: Download a container from the package registry, or build it if it's not found - -inputs: - container: - description: Container name - type: string - required: true - dockerfile: - description: Dockerfile - type: string - base: - description: Container base - type: string - registry: - description: Docker registry to read and publish to - type: string - default: ghcr.io - config-path: - description: Path to Dockerfiles - type: string - github_token: - description: GitHub Token - type: string - -runs: - using: 'composite' - steps: - - name: Download container - run: | - IMAGE_NAME="${{ inputs.container }}" - DOCKERFILE_PATH="${{ inputs.dockerfile }}" - DOCKER_REGISTRY="${{ inputs.registry }}" - DOCKERFILE_ROOT="${{ inputs.config-path }}" - - if [ "${DOCKERFILE_PATH}" = "" ]; then - DOCKERFILE_PATH="${DOCKERFILE_ROOT}/${IMAGE_NAME}" - else - DOCKERFILE_PATH="${DOCKERFILE_ROOT}/${DOCKERFILE_PATH}" - fi - - GIT_WORKTREE=$(cd "${GITHUB_ACTION_PATH}" && git rev-parse --show-toplevel) - echo "::: git worktree is ${GIT_WORKTREE}" - cd "${GIT_WORKTREE}" - - DOCKER_CONTAINER="${GITHUB_REPOSITORY}/${IMAGE_NAME}" - DOCKER_REGISTRY_CONTAINER="${DOCKER_REGISTRY}/${DOCKER_CONTAINER}" - - echo "dockerfile=${DOCKERFILE_PATH}" >> $GITHUB_ENV - echo "docker-container=${DOCKER_CONTAINER}" >> $GITHUB_ENV - echo "docker-registry-container=${DOCKER_REGISTRY_CONTAINER}" >> $GITHUB_ENV - - # Identify the last git commit that touched the Dockerfiles - # Use this as a hash to identify the resulting docker containers - echo "::: dockerfile path is ${DOCKERFILE_PATH}" - - DOCKER_SHA=$(git log -1 --pretty=format:"%h" -- "${DOCKERFILE_PATH}") - echo "docker-sha=${DOCKER_SHA}" >> $GITHUB_ENV - - echo "::: docker sha is ${DOCKER_SHA}" - - DOCKER_REGISTRY_CONTAINER_SHA="${DOCKER_REGISTRY_CONTAINER}:${DOCKER_SHA}" - - echo "docker-registry-container-sha=${DOCKER_REGISTRY_CONTAINER_SHA}" >> $GITHUB_ENV - echo "docker-registry-container-latest=${DOCKER_REGISTRY_CONTAINER}:latest" >> $GITHUB_ENV - - echo "::: logging in to ${DOCKER_REGISTRY} as ${GITHUB_ACTOR}" - - exists="true" - docker login https://${DOCKER_REGISTRY} -u ${GITHUB_ACTOR} -p ${GITHUB_TOKEN} || exists="false" - - echo "::: pulling ${DOCKER_REGISTRY_CONTAINER_SHA}" - - if [ "${exists}" != "false" ]; then - docker pull ${DOCKER_REGISTRY_CONTAINER_SHA} || exists="false" - fi - - if [ "${exists}" = "true" ]; then - echo "::: docker container exists in registry" - echo "docker-container-exists=true" >> $GITHUB_ENV - else - echo "::: docker container does not exist in registry" - echo "docker-container-exists=false" >> $GITHUB_ENV - fi - shell: bash - env: - GITHUB_TOKEN: ${{ inputs.github_token }} - - name: Create container - run: | - if [ "${{ inputs.base }}" != "" ]; then - BASE_ARG="--build-arg BASE=${{ inputs.base }}" - fi - - GIT_WORKTREE=$(cd "${GITHUB_ACTION_PATH}" && git rev-parse --show-toplevel) - echo "::: git worktree is ${GIT_WORKTREE}" - cd "${GIT_WORKTREE}" - - docker build -t ${{ env.docker-registry-container-sha }} --build-arg UID=$(id -u) --build-arg GID=$(id -g) ${BASE_ARG} -f ${{ env.dockerfile }} . - docker tag ${{ env.docker-registry-container-sha }} ${{ env.docker-registry-container-latest }} - shell: bash - working-directory: source/${{ inputs.config-path }} - if: env.docker-container-exists != 'true' - - name: Publish container - run: | - docker push ${{ env.docker-registry-container-sha }} - docker push ${{ env.docker-registry-container-latest }} - shell: bash - if: env.docker-container-exists != 'true' && github.event_name != 'pull_request' diff --git a/vendor/libgit2-sys/libgit2/.github/actions/run-build/action.yml b/vendor/libgit2-sys/libgit2/.github/actions/run-build/action.yml deleted file mode 100644 index 9afcfb1..0000000 --- a/vendor/libgit2-sys/libgit2/.github/actions/run-build/action.yml +++ /dev/null @@ -1,51 +0,0 @@ -# Run a build step in a container or directly on the Actions runner -name: Run Build Step -description: Run a build step in a container or directly on the Actions runner - -inputs: - command: - description: Command to run - type: string - required: true - container: - description: Optional container to run in - type: string - container-version: - description: Version of the container to run - type: string - shell: - description: Shell to use - type: string - required: true - default: 'bash' - -runs: - using: 'composite' - steps: - - run: | - if [ -n "${{ inputs.container }}" ]; then - docker run \ - --rm \ - --user "$(id -u):$(id -g)" \ - -v "$(pwd)/source:/home/libgit2/source" \ - -v "$(pwd)/build:/home/libgit2/build" \ - -w /home/libgit2 \ - -e ASAN_SYMBOLIZER_PATH \ - -e CC \ - -e CFLAGS \ - -e CMAKE_GENERATOR \ - -e CMAKE_OPTIONS \ - -e GITTEST_NEGOTIATE_PASSWORD \ - -e GITTEST_FLAKY_STAT \ - -e PKG_CONFIG_PATH \ - -e SKIP_NEGOTIATE_TESTS \ - -e SKIP_SSH_TESTS \ - -e SKIP_PUSHOPTIONS_TESTS \ - -e TSAN_OPTIONS \ - -e UBSAN_OPTIONS \ - ${{ inputs.container-version }} \ - /bin/bash -c "${{ inputs.command }}" - else - ${{ inputs.command }} - fi - shell: ${{ inputs.shell != '' && inputs.shell || 'bash' }} diff --git a/vendor/libgit2-sys/libgit2/.github/release.yml b/vendor/libgit2-sys/libgit2/.github/release.yml deleted file mode 100644 index ac05fc6..0000000 --- a/vendor/libgit2-sys/libgit2/.github/release.yml +++ /dev/null @@ -1,38 +0,0 @@ -changelog: - categories: - - title: New features - labels: - - feature - - title: Performance improvements - labels: - - performance - - title: Bug fixes - labels: - - bug - - title: Security fixes - labels: - - security - - title: Code cleanups - labels: - - cleanup - - title: Benchmarks - labels: - - benchmarks - - title: Build and CI improvements - labels: - - build - - title: Documentation improvements - labels: - - documentation - - title: Platform compatibility fixes - labels: - - compatibility - - title: Git compatibility fixes - labels: - - git compatibility - - title: Dependency updates - labels: - - dependency - - title: Other changes - labels: - - '*' diff --git a/vendor/libgit2-sys/libgit2/.github/workflows/benchmark.yml b/vendor/libgit2-sys/libgit2/.github/workflows/benchmark.yml deleted file mode 100644 index 3fb912d..0000000 --- a/vendor/libgit2-sys/libgit2/.github/workflows/benchmark.yml +++ /dev/null @@ -1,167 +0,0 @@ -# Benchmark libgit2 against the git reference implementation. -name: Benchmark - -on: - workflow_dispatch: - inputs: - suite: - description: Benchmark suite to run - debug: - type: boolean - description: Debugging output - schedule: - - cron: '15 4 * * *' - -permissions: - contents: read - -jobs: - # Run our benchmarks. We build a matrix with the various build - # targets and their details. Unlike our CI builds, we run these - # directly on the VM instead of in containers since we do not - # need the breadth of platform diversity. - build: - # Only run scheduled workflows on the main repository; prevents people - # from using build minutes on their forks. - if: github.repository == 'libgit2/libgit2' - - strategy: - matrix: - platform: - - name: "Linux (clang, OpenSSL)" - id: linux - os: ubuntu-latest - setup-script: ubuntu - env: - CC: clang - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release - CMAKE_BUILD_OPTIONS: --config Release - - name: "macOS" - id: macos - os: macos-latest - setup-script: osx - env: - CC: clang - CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release - CMAKE_BUILD_OPTIONS: --config Release - PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig - - name: "Windows (amd64, Visual Studio)" - id: windows - os: windows-2022 - setup-script: win32 - env: - ARCH: amd64 - CMAKE_GENERATOR: Visual Studio 17 2022 - CMAKE_OPTIONS: -A x64 -DDEPRECATE_HARD=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release - CMAKE_BUILD_OPTIONS: --config Release - fail-fast: false - name: "Benchmark ${{ matrix.platform.name }}" - env: ${{ matrix.platform.env }} - runs-on: ${{ matrix.platform.os }} - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 0 - - name: Set up benchmark environment - run: source/ci/setup-${{ matrix.platform.setup-script }}-benchmark.sh - shell: bash - if: matrix.platform.setup-script != '' - - name: Clone resource repositories - run: | - mkdir resources - git clone --bare https://github.com/git/git resources/git - git clone --bare https://github.com/torvalds/linux resources/linux - - name: Build - run: | - mkdir build && cd build - ../source/ci/build.sh - shell: bash - - name: Benchmark - run: | - export BENCHMARK_GIT_REPOSITORY="$(pwd)/resources/git" - # avoid linux temporarily; the linux blame benchmarks are simply - # too slow to use - # export BENCHMARK_LINUX_REPOSITORY="$(pwd)/resources/linux" - - if [[ "$(uname -s)" == MINGW* ]]; then - GIT2_CLI="$(cygpath -w $(pwd))\\build\\Release\\git2" - else - GIT2_CLI="$(pwd)/build/git2" - fi - - if [ "${{ github.event.inputs.suite }}" != "" ]; then - SUITE_FLAG="--suite ${{ github.event.inputs.suite }}" - fi - - if [ "${{ github.event.inputs.debug }}" = "true" ]; then - DEBUG_FLAG="--debug" - fi - - mkdir benchmark && cd benchmark - ../source/tests/benchmarks/benchmark.sh \ - ${SUITE_FLAG} ${DEBUG_FLAG} \ - --baseline-cli "git" --cli "${GIT2_CLI}" --name libgit2 \ - --json benchmarks.json --zip benchmarks.zip - shell: bash - - name: Upload results - uses: actions/upload-artifact@v4 - with: - name: benchmark-${{ matrix.platform.id }} - path: benchmark - if: always() - - # Publish the results - publish: - name: Publish results - needs: [ build ] - if: always() && github.repository == 'libgit2/libgit2' && github.event_name == 'schedule' - runs-on: ubuntu-latest - steps: - - name: Check out benchmark repository - uses: actions/checkout@v4 - with: - repository: libgit2/benchmarks - path: site - fetch-depth: 0 - ssh-key: ${{ secrets.BENCHMARKS_PUBLISH_KEY }} - - name: Download test results - uses: actions/download-artifact@v4 - - name: Publish API - run: | - # Move today's benchmark run into the right place - for platform in linux macos windows; do - TIMESTAMP=$(jq .time.start < "benchmark-${platform}/benchmarks.json") - TIMESTAMP_LEN=$(echo -n ${TIMESTAMP} | wc -c | xargs) - DENOMINATOR=1 - if [ "${TIMESTAMP_LEN}" = "19" ]; then - DENOMINATOR="1000000000" - elif [ "${TIMESTAMP_LEN}" = "13" ]; then - DENOMINATOR="1000" - else - echo "unknown timestamp" - exit 1 - fi - - if [[ "$(uname -s)" == "Darwin" ]]; then - DATE=$(date -R -r $(("${TIMESTAMP}/${DENOMINATOR}")) +"%Y-%m-%d") - else - DATE=$(date -d @$(("${TIMESTAMP}/${DENOMINATOR}")) +"%Y-%m-%d") - fi - - mkdir -p "site/public/api/runs/${DATE}" - cp "benchmark-${platform}/benchmarks.json" "site/public/api/runs/${DATE}/${platform}.json" - done - - (cd site && node scripts/aggregate.js) - - ( - cd site && - git config user.name 'Benchmark Site Generation' && - git config user.email 'libgit2@users.noreply.github.com' && - git add . && - git commit --allow-empty -m"benchmark update ${DATE}" && - git push origin main - ) - shell: bash diff --git a/vendor/libgit2-sys/libgit2/.github/workflows/build-containers.yml b/vendor/libgit2-sys/libgit2/.github/workflows/build-containers.yml deleted file mode 100644 index b52571c..0000000 --- a/vendor/libgit2-sys/libgit2/.github/workflows/build-containers.yml +++ /dev/null @@ -1,74 +0,0 @@ -# Generate the containers that we use for builds. -name: Build Containers - -on: - workflow_call: - -env: - docker-registry: ghcr.io - docker-config-path: source/ci/docker - -jobs: - # Build the docker container images that we will use for our Linux - # builds. This will identify the last commit to the repository that - # updated the docker images, and try to download the image tagged with - # that sha. If it does not exist, we'll do a docker build and push - # the image up to GitHub Packages for the actual CI/CD runs. We tag - # with both the sha and "latest" so that the subsequent runs need not - # know the sha. Only do this on CI builds (when the event is a "push") - # because PR builds from forks lack permission to write packages. - containers: - strategy: - matrix: - container: - - name: xenial - - name: bionic - - name: focal - - name: noble - - name: docurium - - name: bionic-x86 - dockerfile: bionic - base: multiarch/ubuntu-core:x86-bionic - qemu: true - - name: bionic-arm32 - dockerfile: bionic - base: multiarch/ubuntu-core:armhf-bionic - qemu: true - - name: bionic-arm64 - dockerfile: bionic - base: multiarch/ubuntu-core:arm64-bionic - qemu: true - - name: centos7 - - name: centos8 - - name: fedora - runs-on: ubuntu-latest - name: "Create container: ${{ matrix.container.name }}" - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 0 - if: github.event_name != 'pull_request' - - name: Setup QEMU - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - if: matrix.container.qemu == true - - name: Download existing container - run: | - "${{ github.workspace }}/source/ci/getcontainer.sh" "${{ matrix.container.name }}" "${{ matrix.container.dockerfile }}" - env: - DOCKER_REGISTRY: ${{ env.docker-registry }} - GITHUB_TOKEN: ${{ secrets.github_token }} - working-directory: ${{ env.docker-config-path }} - if: github.event_name != 'pull_request' - - name: Build and publish image - run: | - if [ "${{ matrix.container.base }}" != "" ]; then - BASE_ARG="--build-arg BASE=${{ matrix.container.base }}" - fi - docker build -t ${{ env.docker-registry-container-sha }} --build-arg UID=$(id -u) --build-arg GID=$(id -g) ${BASE_ARG} -f ${{ env.dockerfile }} . - docker tag ${{ env.docker-registry-container-sha }} ${{ env.docker-registry-container-latest }} - docker push ${{ env.docker-registry-container-sha }} - docker push ${{ env.docker-registry-container-latest }} - working-directory: ${{ env.docker-config-path }} - if: github.event_name != 'pull_request' && env.docker-container-exists != 'true' diff --git a/vendor/libgit2-sys/libgit2/.github/workflows/documentation.yml b/vendor/libgit2-sys/libgit2/.github/workflows/documentation.yml deleted file mode 100644 index d82887d..0000000 --- a/vendor/libgit2-sys/libgit2/.github/workflows/documentation.yml +++ /dev/null @@ -1,76 +0,0 @@ -# Update the www.libgit2.org reference documentation -name: Generate Documentation - -on: - push: - branches: [ main ] - release: - workflow_dispatch: - inputs: - force: - description: 'Force rebuild' - type: boolean - required: true - -concurrency: - group: documentation - -permissions: - contents: read - -jobs: - documentation: - name: "Generate documentation" - runs-on: "ubuntu-latest" - steps: - - name: Check out source repository - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 0 - - name: Check out documentation repository - uses: actions/checkout@v4 - with: - repository: libgit2/www.libgit2.org - path: www - fetch-depth: 0 - ssh-key: ${{ secrets.DOCS_PUBLISH_KEY }} - - name: Prepare branches - run: | - for a in main $(git branch -r --list 'origin/maint/*' | sed -e "s/^ origin\///"); do - if [ "$(git rev-parse --abbrev-ref HEAD)" != "${a}" ]; then - git branch --track "$a" "origin/$a" - fi - done - working-directory: source - - name: Generate documentation - run: | - args="" - - if [ "${{ inputs.force }}" = "true" ]; then - args="--force" - fi - - npm install - ./generate --verbose $args ../.. ../../../www/docs - working-directory: source/script/api-docs - - name: Examine changes - run: | - if [ -n "$(git diff --name-only)" ]; then - echo "changes=true" >> $GITHUB_OUTPUT - else - echo "changes=false" >> $GITHUB_OUTPUT - fi - id: check - working-directory: www - - name: Publish documentation - run: | - DATE=$(date +"%Y-%m-%d") - - git config user.name 'Documentation Site Generator' - git config user.email 'libgit2@users.noreply.github.com' - git add . - git commit -m"Documentation update ${DATE}" - git push origin main - if: steps.check.outputs.changes == 'true' - working-directory: www diff --git a/vendor/libgit2-sys/libgit2/.github/workflows/experimental.yml b/vendor/libgit2-sys/libgit2/.github/workflows/experimental.yml deleted file mode 100644 index 2670da3..0000000 --- a/vendor/libgit2-sys/libgit2/.github/workflows/experimental.yml +++ /dev/null @@ -1,120 +0,0 @@ -# Validation builds for experimental features; these shouldn't be -# required for pull request approval. -name: Experimental Features - -on: - push: - branches: [ main, maint/* ] - pull_request: - branches: [ main, maint/* ] - workflow_dispatch: - -env: - docker-registry: ghcr.io - docker-config-path: ci/docker - -permissions: - contents: write - packages: write - -jobs: - # Run our CI/CD builds. We build a matrix with the various build targets - # and their details. Then we build either in a docker container (Linux) - # or on the actual hosts (macOS, Windows). - build: - strategy: - matrix: - platform: - # All builds: experimental SHA256 support - - name: "Linux (SHA256, Xenial, Clang, OpenSSL)" - id: linux-sha256 - os: ubuntu-latest - container: - name: xenial - env: - CC: clang - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON -DEXPERIMENTAL_SHA256=ON - - name: "macOS (SHA256)" - id: macos-sha256 - os: macos-14 - setup-script: osx - env: - CC: clang - CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON -DEXPERIMENTAL_SHA256=ON - CMAKE_GENERATOR: Ninja - PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (SHA256, amd64, Visual Studio)" - id: windows-sha256 - os: windows-2022 - env: - ARCH: amd64 - CMAKE_GENERATOR: Visual Studio 17 2022 - CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DEXPERIMENTAL_SHA256=ON - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - # TODO: this is a temporary removal - SKIP_GITDAEMON_TESTS: true - fail-fast: false - env: ${{ matrix.platform.env }} - runs-on: ${{ matrix.platform.os }} - name: "Build: ${{ matrix.platform.name }}" - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 0 - - name: Set up build environment - run: source/ci/setup-${{ matrix.platform.setup-script }}-build.sh - shell: bash - if: matrix.platform.setup-script != '' - - name: Setup QEMU - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - if: matrix.platform.container.qemu == true - - name: Set up container - uses: ./source/.github/actions/download-or-build-container - with: - registry: ${{ env.docker-registry }} - config-path: ${{ env.docker-config-path }} - container: ${{ matrix.platform.container.name }} - github_token: ${{ secrets.github_token }} - dockerfile: ${{ matrix.platform.container.dockerfile }} - if: matrix.platform.container.name != '' - - name: Prepare build - run: mkdir build - - name: Build - uses: ./source/.github/actions/run-build - with: - command: cd ${BUILD_WORKSPACE:-.}/build && ../source/ci/build.sh - container: ${{ matrix.platform.container.name }} - container-version: ${{ env.docker-registry-container-sha }} - shell: ${{ matrix.platform.shell }} - - name: Test - uses: ./source/.github/actions/run-build - with: - command: cd ${BUILD_WORKSPACE:-.}/build && ../source/ci/test.sh - container: ${{ matrix.platform.container.name }} - container-version: ${{ env.docker-registry-container-sha }} - shell: ${{ matrix.platform.shell }} - - name: Upload test results - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: test-results-${{ matrix.platform.id }} - path: build/results_*.xml - - test_results: - name: Test results - needs: [ build ] - if: always() - runs-on: ubuntu-latest - steps: - - name: Download test results - uses: actions/download-artifact@v4 - - name: Generate test summary - uses: test-summary/action@v2 - with: - paths: 'test-results-*/*.xml' diff --git a/vendor/libgit2-sys/libgit2/.github/workflows/main.yml b/vendor/libgit2-sys/libgit2/.github/workflows/main.yml deleted file mode 100644 index 3e8fadc..0000000 --- a/vendor/libgit2-sys/libgit2/.github/workflows/main.yml +++ /dev/null @@ -1,258 +0,0 @@ -# Continuous integration and pull request validation builds for the -# main and maintenance branches. -name: CI Build - -on: - push: - branches: [ main, maint/* ] - pull_request: - branches: [ main, maint/* ] - workflow_dispatch: - -env: - docker-registry: ghcr.io - docker-config-path: ci/docker - -permissions: - contents: write - packages: write - -jobs: - # Run our CI/CD builds. We build a matrix with the various build targets - # and their details. Then we build either in a docker container (Linux) - # or on the actual hosts (macOS, Windows). - build: - strategy: - matrix: - platform: - # All builds: core platforms - - name: "Linux (Noble, GCC, OpenSSL, libssh2)" - id: noble-gcc-openssl - os: ubuntu-latest - container: - name: noble - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=libssh2 -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON - - name: "Linux (Noble, Clang, mbedTLS, OpenSSH)" - id: noble-clang-mbedtls - os: ubuntu-latest - container: - name: noble - env: - CC: clang - CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=exec -DUSE_HTTP_PARSER=http-parser - CMAKE_GENERATOR: Ninja - - name: "Linux (Xenial, GCC, OpenSSL, OpenSSH)" - id: xenial-gcc-openssl - os: ubuntu-latest - container: - name: xenial - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=exec -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON - - name: "Linux (Xenial, Clang, mbedTLS, libssh2)" - id: xenial-gcc-mbedtls - os: ubuntu-latest - container: - name: xenial - env: - CC: clang - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=libssh2 - - name: "macOS" - id: macos - os: macos-14 - setup-script: osx - env: - CC: clang - CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON - CMAKE_GENERATOR: Ninja - PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (amd64, Visual Studio, Schannel)" - id: windows-amd64-vs - os: windows-2022 - setup-script: win32 - env: - ARCH: amd64 - CMAKE_GENERATOR: Visual Studio 17 2022 - CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_HTTPS=Schannel -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2 - BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin - BUILD_TEMP: D:\Temp - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (x86, Visual Studio, WinHTTP)" - id: windows-x86-vs - os: windows-2022 - setup-script: win32 - env: - ARCH: x86 - CMAKE_GENERATOR: Visual Studio 17 2022 - CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2 - BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin - BUILD_TEMP: D:\Temp - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (amd64, mingw, WinHTTP)" - id: windows-amd64-mingw - os: windows-2022 - setup-script: mingw - env: - ARCH: amd64 - CMAKE_GENERATOR: MinGW Makefiles - CMAKE_OPTIONS: -DDEPRECATE_HARD=ON - BUILD_TEMP: D:\Temp - BUILD_PATH: D:\Temp\mingw64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (x86, mingw, Schannel)" - id: windows-x86-mingw - os: windows-2022 - setup-script: mingw - env: - ARCH: x86 - CMAKE_GENERATOR: MinGW Makefiles - CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_HTTPS=Schannel - BUILD_TEMP: D:\Temp - BUILD_PATH: D:\Temp\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - # All builds: sanitizers - - name: "Sanitizer (Memory)" - id: sanitizer-memory - os: ubuntu-latest - setup-script: sanitizer - container: - name: noble - env: - CC: clang - CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_C_EXTENSIONS=ON -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - - name: "Sanitizer (Address)" - id: sanitizer-address - os: ubuntu-latest - setup-script: sanitizer - container: - name: noble - env: - CC: clang - CFLAGS: -fsanitize=address -ggdb -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - - name: "Sanitizer (UndefinedBehavior)" - id: sanitizer-ub - os: ubuntu-latest - setup-script: sanitizer - container: - name: noble - env: - CC: clang - CFLAGS: -fsanitize=undefined,nullability -fno-sanitize-recover=undefined,nullability -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - - name: "Sanitizer (Thread)" - id: sanitizer-thread - os: ubuntu-latest - setup-script: sanitizer - container: - name: noble - env: - CC: clang - CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - TSAN_OPTIONS: suppressions=/home/libgit2/source/script/thread-sanitizer.supp second_deadlock_stack=1 - fail-fast: false - env: ${{ matrix.platform.env }} - runs-on: ${{ matrix.platform.os }} - name: "Build: ${{ matrix.platform.name }}" - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 0 - - name: Set up build environment - run: source/ci/setup-${{ matrix.platform.setup-script }}-build.sh - shell: bash - if: matrix.platform.setup-script != '' - - name: Setup QEMU - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - if: matrix.platform.container.qemu == true - - name: Set up container - uses: ./source/.github/actions/download-or-build-container - with: - registry: ${{ env.docker-registry }} - config-path: ${{ env.docker-config-path }} - container: ${{ matrix.platform.container.name }} - github_token: ${{ secrets.github_token }} - dockerfile: ${{ matrix.platform.container.dockerfile }} - if: matrix.platform.container.name != '' - - name: Prepare build - run: mkdir build - - name: Build - uses: ./source/.github/actions/run-build - with: - command: cd ${BUILD_WORKSPACE:-.}/build && ../source/ci/build.sh - container: ${{ matrix.platform.container.name }} - container-version: ${{ env.docker-registry-container-sha }} - shell: ${{ matrix.platform.shell }} - - name: Test - uses: ./source/.github/actions/run-build - with: - command: cd ${BUILD_WORKSPACE:-.}/build && ../source/ci/test.sh - container: ${{ matrix.platform.container.name }} - container-version: ${{ env.docker-registry-container-sha }} - shell: ${{ matrix.platform.shell }} - - name: Upload test results - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: test-results-${{ matrix.platform.id }} - path: build/results_*.xml - - documentation: - name: Validate documentation - runs-on: ubuntu-latest - steps: - - name: Check out repository - uses: actions/checkout@v4 - - name: Validate documentation - run: | - (cd script/api-docs && npm install) - script/api-docs/api-generator.js --validate-only --strict --deprecate-hard . - - test_results: - name: Test results - needs: [ build ] - if: always() - runs-on: ubuntu-latest - steps: - - name: Download test results - uses: actions/download-artifact@v4 - - name: Generate test summary - uses: test-summary/action@v2 - with: - paths: 'test-results-*/*.xml' diff --git a/vendor/libgit2-sys/libgit2/.github/workflows/nightly.yml b/vendor/libgit2-sys/libgit2/.github/workflows/nightly.yml deleted file mode 100644 index 0f835d5..0000000 --- a/vendor/libgit2-sys/libgit2/.github/workflows/nightly.yml +++ /dev/null @@ -1,507 +0,0 @@ -# Nightly build for the main branch across multiple targets. -name: Nightly Build - -on: - workflow_dispatch: - schedule: - - cron: '15 1 * * *' - -env: - docker-registry: ghcr.io - docker-config-path: ci/docker - -permissions: - contents: read - packages: write - -jobs: - # Run our nightly builds. We build a matrix with the various build - # targets and their details. Then we build either in a docker container - # (Linux) or on the actual hosts (macOS, Windows). - build: - # Only run scheduled workflows on the main repository; prevents people - # from using build minutes on their forks. - if: github.repository == 'libgit2/libgit2' - - strategy: - matrix: - platform: - # All builds: core platforms - - name: "Linux (Noble, GCC, OpenSSL, libssh2)" - id: noble-gcc-openssl - os: ubuntu-latest - container: - name: noble - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=libssh2 -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON - - name: "Linux (Noble, Clang, mbedTLS, OpenSSH)" - id: noble-clang-mbedtls - os: ubuntu-latest - container: - name: noble - env: - CC: clang - CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=exec -DUSE_HTTP_PARSER=http-parser - CMAKE_GENERATOR: Ninja - - name: "Linux (Xenial, GCC, OpenSSL, OpenSSH)" - id: xenial-gcc-openssl - os: ubuntu-latest - container: - name: xenial - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=exec -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON - - name: "Linux (Xenial, Clang, mbedTLS, libssh2)" - id: xenial-gcc-mbedtls - os: ubuntu-latest - container: - name: xenial - env: - CC: clang - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=libssh2 - - name: "macOS" - id: macos - os: macos-14 - setup-script: osx - env: - CC: clang - CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON - CMAKE_GENERATOR: Ninja - PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "iOS" - id: ios - os: macos-14 - setup-script: ios - env: - CC: clang - CMAKE_OPTIONS: -DBUILD_TESTS=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON -DCMAKE_TOOLCHAIN_FILE=../ios.toolchain.cmake -DCMAKE_SYSTEM_NAME=iOS -DPLATFORM=OS64 - CMAKE_GENERATOR: Ninja - PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig - SKIP_TESTS: true # Cannot exec iOS app on macOS - - name: "Windows (amd64, Visual Studio, Schannel)" - id: windows-amd64-vs - os: windows-2022 - setup-script: win32 - env: - ARCH: amd64 - CMAKE_GENERATOR: Visual Studio 17 2022 - CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_HTTPS=Schannel -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2 - BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin - BUILD_TEMP: D:\Temp - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (x86, Visual Studio, WinHTTP)" - id: windows-x86-vs - os: windows-2022 - setup-script: win32 - env: - ARCH: x86 - CMAKE_GENERATOR: Visual Studio 17 2022 - CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2 - BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin - BUILD_TEMP: D:\Temp - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (amd64, mingw, WinHTTP)" - id: windows-amd64-mingw - os: windows-2022 - setup-script: mingw - env: - ARCH: amd64 - CMAKE_GENERATOR: MinGW Makefiles - CMAKE_OPTIONS: -DDEPRECATE_HARD=ON - BUILD_TEMP: D:\Temp - BUILD_PATH: D:\Temp\mingw64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (x86, mingw, Schannel)" - id: windows-x86-mingw - os: windows-2022 - setup-script: mingw - env: - ARCH: x86 - CMAKE_GENERATOR: MinGW Makefiles - CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_HTTPS=Schannel - BUILD_TEMP: D:\Temp - BUILD_PATH: D:\Temp\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - # All builds: sanitizers - - name: "Sanitizer (Memory)" - id: memorysanitizer - os: ubuntu-latest - setup-script: sanitizer - container: - name: noble - env: - CC: clang - CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_C_EXTENSIONS=ON -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - - name: "Sanitizer (UndefinedBehavior)" - id: ubsanitizer - os: ubuntu-latest - setup-script: sanitizer - container: - name: noble - env: - CC: clang - CFLAGS: -fsanitize=undefined,nullability -fno-sanitize-recover=undefined,nullability -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - - name: "Sanitizer (Thread)" - id: threadsanitizer - os: ubuntu-latest - setup-script: sanitizer - container: - name: noble - env: - CC: clang - CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - TSAN_OPTIONS: suppressions=/home/libgit2/source/script/thread-sanitizer.supp second_deadlock_stack=1 - - # Nightly builds: extended platforms - - name: "Linux (CentOS 7, OpenSSL)" - id: centos7-openssl - os: ubuntu-latest - container: - name: centos7 - env: - CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON - PKG_CONFIG_PATH: /usr/local/lib/pkgconfig - SKIP_NEGOTIATE_TESTS: true - SKIP_PUSHOPTIONS_TESTS: true - - name: "Linux (CentOS 7, dynamically-loaded OpenSSL)" - id: centos7-dynamicopenssl - os: ubuntu-latest - container: - name: centos7 - env: - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON - PKG_CONFIG_PATH: /usr/local/lib/pkgconfig - SKIP_NEGOTIATE_TESTS: true - SKIP_PUSHOPTIONS_TESTS: true - - name: "Linux (CentOS 8, OpenSSL)" - id: centos8-openssl - os: ubuntu-latest - container: - name: centos8 - env: - CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON - PKG_CONFIG_PATH: /usr/local/lib/pkgconfig - SKIP_NEGOTIATE_TESTS: true - SKIP_SSH_TESTS: true - - name: "Linux (CentOS 8, dynamically-loaded OpenSSL)" - id: centos8-dynamicopenssl - os: ubuntu-latest - container: - name: centos8 - env: - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON - PKG_CONFIG_PATH: /usr/local/lib/pkgconfig - SKIP_NEGOTIATE_TESTS: true - SKIP_SSH_TESTS: true - ARCH: x86 - - name: "Linux (Fedora, llhttp)" - id: fedora - os: ubuntu-latest - container: - name: fedora - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=pcre2 -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=libssh2 -DUSE_HTTP_PARSER=llhttp - - name: "Linux (Bionic, GCC, dynamically-loaded OpenSSL)" - id: bionic-gcc-dynamicopenssl - container: - name: bionic - dockerfile: bionic - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON - RUN_INVASIVE_TESTS: true - SKIP_PUSHOPTIONS_TESTS: true - os: ubuntu-latest - - name: "Linux (x86, Bionic, Clang, OpenSSL)" - id: bionic-x86-clang-openssl - container: - name: bionic-x86 - dockerfile: bionic - qemu: true - env: - CC: clang - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON - RUN_INVASIVE_TESTS: true - SKIP_PUSHOPTIONS_TESTS: true - os: ubuntu-latest - - name: "Linux (x86, Bionic, GCC, OpenSSL)" - id: bionic-x86-gcc-openssl - container: - name: bionic-x86 - dockerfile: bionic - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON - RUN_INVASIVE_TESTS: true - SKIP_PUSHOPTIONS_TESTS: true - os: ubuntu-latest - - name: "Linux (arm32, Bionic, GCC, OpenSSL)" - id: bionic-arm32-gcc-openssl - container: - name: bionic-arm32 - dockerfile: bionic - qemu: true - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON - RUN_INVASIVE_TESTS: true - SKIP_PROXY_TESTS: true - SKIP_PUSHOPTIONS_TESTS: true - GITTEST_FLAKY_STAT: true - os: ubuntu-latest - - name: "Linux (arm64, Bionic, GCC, OpenSSL)" - id: bionic-arm64-gcc-openssl - container: - name: bionic-arm64 - dockerfile: bionic - qemu: true - env: - CC: gcc - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON - RUN_INVASIVE_TESTS: true - SKIP_PROXY_TESTS: true - SKIP_PUSHOPTIONS_TESTS: true - os: ubuntu-latest - - # Nightly builds: ensure we fallback when missing core functionality - - name: "Linux (no threads)" - id: xenial-nothreads - os: ubuntu-latest - container: - name: xenial - env: - CC: gcc - CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_PUSHOPTIONS_TESTS: true - - name: "Linux (no mmap)" - id: noble-nommap - os: ubuntu-latest - container: - name: noble - env: - CC: gcc - CFLAGS: -DNO_MMAP - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (no mmap)" - id: windows-nommap - os: windows-2022 - env: - ARCH: amd64 - CMAKE_GENERATOR: Visual Studio 17 2022 - CFLAGS: -DNO_MMAP - CMAKE_OPTIONS: -A x64 -DDEPRECATE_HARD=ON - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - # Nightly builds: extended SSL support - - name: "Linux (dynamically-loaded OpenSSL)" - id: xenial-dynamicopenssl - os: ubuntu-latest - container: - name: xenial - env: - CC: clang - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - - # All builds: experimental SHA256 support - - name: "Linux (SHA256, Xenial, Clang, OpenSSL)" - id: linux-sha256 - container: - name: xenial - env: - CC: clang - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON - os: ubuntu-latest - - name: "macOS (SHA256)" - id: macos-sha256 - os: macos-14 - setup-script: osx - env: - CC: clang - CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON -DEXPERIMENTAL_SHA256=ON - PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - - name: "Windows (SHA256, amd64, Visual Studio)" - id: windows-sha256 - os: windows-2022 - env: - ARCH: amd64 - CMAKE_GENERATOR: Visual Studio 17 2022 - CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DEXPERIMENTAL_SHA256=ON - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - # TODO: this is a temporary removal - SKIP_GITDAEMON_TESTS: true - - name: "Linux (SHA256, Xenial, Clang, OpenSSL-FIPS)" - id: linux-sha256-fips - container: - name: xenial - env: - CC: clang - CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON -DUSE_SHA1=OpenSSL-FIPS -DUSE_SHA256=OpenSSL-FIPS - os: ubuntu-latest - fail-fast: false - env: ${{ matrix.platform.env }} - runs-on: ${{ matrix.platform.os }} - name: "Build ${{ matrix.platform.name }}" - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 0 - - name: Set up build environment - run: source/ci/setup-${{ matrix.platform.setup-script }}-build.sh - shell: bash - if: matrix.platform.setup-script != '' - - name: Setup QEMU - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - if: matrix.platform.container.qemu == true - - name: Set up container - uses: ./source/.github/actions/download-or-build-container - with: - registry: ${{ env.docker-registry }} - config-path: ${{ env.docker-config-path }} - container: ${{ matrix.platform.container.name }} - github_token: ${{ secrets.github_token }} - dockerfile: ${{ matrix.platform.container.dockerfile }} - if: matrix.platform.container.name != '' - - name: Prepare build - run: mkdir build - - name: Build - uses: ./source/.github/actions/run-build - with: - command: cd ${BUILD_WORKSPACE:-.}/build && ../source/ci/build.sh - container: ${{ matrix.platform.container.name }} - container-version: ${{ env.docker-registry-container-sha }} - shell: ${{ matrix.platform.shell }} - - name: Test - uses: ./source/.github/actions/run-build - with: - command: cd ${BUILD_WORKSPACE:-.}/build && ../source/ci/test.sh - container: ${{ matrix.platform.container.name }} - container-version: ${{ env.docker-registry-container-sha }} - shell: ${{ matrix.platform.shell }} - - name: Upload test results - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: test-results-${{ matrix.platform.id }} - path: build/results_*.xml - - test_results: - name: Test results - needs: [ build ] - if: ${{ always() && github.repository == 'libgit2/libgit2' }} - runs-on: ubuntu-latest - steps: - - name: Download test results - uses: actions/download-artifact@v4 - - name: Generate test summary - uses: test-summary/action@v2 - with: - paths: 'test-results-*/*.xml' - - coverity: - # Only run scheduled workflows on the main repository; prevents people - # from using build minutes on their forks. - if: github.repository == 'libgit2/libgit2' - - name: Coverity - runs-on: ubuntu-latest - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 0 - - name: Set up container - uses: ./source/.github/actions/download-or-build-container - with: - registry: ${{ env.docker-registry }} - config-path: ${{ env.docker-config-path }} - container: xenial - github_token: ${{ secrets.github_token }} - if: matrix.platform.container.name != '' - - name: Run Coverity - run: source/ci/coverity.sh - env: - COVERITY_TOKEN: ${{ secrets.coverity_token }} - - codeql: - # Only run scheduled workflows on the main repository; prevents people - # from using build minutes on their forks. - if: github.repository == 'libgit2/libgit2' - - permissions: - actions: read - contents: read - security-events: write - - name: CodeQL - runs-on: ubuntu-latest - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: 'cpp' - - - name: Build - run: | - mkdir build - cd build - cmake .. -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON - cmake --build . - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/vendor/libgit2-sys/libgit2/.gitignore b/vendor/libgit2-sys/libgit2/.gitignore deleted file mode 100644 index 1b482f0..0000000 --- a/vendor/libgit2-sys/libgit2/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/build/ -.DS_Store -*~ -.*.swp -/tags -CMakeSettings.json -.vs -.idea diff --git a/vendor/libgit2-sys/libgit2/.mailmap b/vendor/libgit2-sys/libgit2/.mailmap deleted file mode 100644 index 0b16a7e..0000000 --- a/vendor/libgit2-sys/libgit2/.mailmap +++ /dev/null @@ -1,22 +0,0 @@ -Vicent Martí Vicent Marti -Vicent Martí Vicent Martí -Michael Schubert schu -Ben Straub Ben Straub -Ben Straub Ben Straub -Carlos Martín Nieto -Carlos Martín Nieto -nulltoken -Scott J. Goldman -Martin Woodward -Peter Drahoš -Adam Roben -Adam Roben -Xavier L. -Xavier L. -Sascha Cunz -Authmillenon -Authmillenon -Edward Thomson -Edward Thomson -J. David Ibáñez -Russell Belfer diff --git a/vendor/libgit2-sys/libgit2/.vscode/launch.json b/vendor/libgit2-sys/libgit2/.vscode/launch.json deleted file mode 100644 index 62d4ec9..0000000 --- a/vendor/libgit2-sys/libgit2/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "(gdb) Launch", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/build/libgit2_tests", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} diff --git a/vendor/libgit2-sys/libgit2/.vscode/settings.json b/vendor/libgit2-sys/libgit2/.vscode/settings.json deleted file mode 100644 index 5dabb89..0000000 --- a/vendor/libgit2-sys/libgit2/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "sarif-viewer.connectToGithubCodeScanning": "off" -} \ No newline at end of file diff --git a/vendor/libgit2-sys/libgit2/.vscode/tasks.json b/vendor/libgit2-sys/libgit2/.vscode/tasks.json deleted file mode 100644 index 24b4d74..0000000 --- a/vendor/libgit2-sys/libgit2/.vscode/tasks.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "Build", - "type": "shell", - "command": "cd build && cmake --build . --parallel", - "group": "build", - "presentation": { - "reveal": "always", - "panel": "new" - } - }, - { - "label": "Run Tests", - "type": "shell", - "command": "build/libgit2_tests -v", - "group": "test", - "presentation": { - "reveal": "always", - "panel": "new" - } - } - ] - } diff --git a/vendor/libgit2-sys/libgit2/AUTHORS b/vendor/libgit2-sys/libgit2/AUTHORS deleted file mode 100644 index f6164ae..0000000 --- a/vendor/libgit2-sys/libgit2/AUTHORS +++ /dev/null @@ -1,81 +0,0 @@ -The following people contribute or have contributed -to the libgit2 project (sorted alphabetically): - -Alex Budovski -Alexei Sholik -Andreas Ericsson -Anton "antong" Gyllenberg -Ankur Sethi -Arthur Schreiber -Ben Noordhuis -Ben Straub -Benjamin C Meyer -Brian Downing -Brian Lopez -Carlos Martín Nieto -Colin Timmermans -Daniel Huckstep -Dave Borowitz -David Boyce -David Glesser -Dmitry Kakurin -Dmitry Kovega -Emeric Fermas -Emmanuel Rodriguez -Eric Myhre -Erik Aigner -Florian Forster -Holger Weiss -Ingmar Vanhassel -J. David Ibáñez -Jacques Germishuys -Jakob Pfender -Jason Penny -Jason R. McNeil -Jerome Lambourg -Johan 't Hart -John Wiegley -Jonathan "Duke" Leto -Julien Miotte -Julio Espinoza-Sokal -Justin Love -Kelly "kelly.leahy" Leahy -Kirill A. Shutemov -Lambert CLARA -Luc Bertrand -Marc Pegon -Marcel Groothuis -Marco Villegas -Michael "schu" Schubert -Microsoft Corporation -Olivier Ramonat -Peter Drahoš -Pierre Habouzit -Pierre-Olivier Latour -Przemyslaw Pawelczyk -Ramsay Jones -Robert G. Jakabosky -Romain Geissler -Romain Muller -Russell Belfer -Sakari Jokinen -Sam Altier -Samuel Charles "Sam" Day -Sarath Lakshman -Sascha Cunz -Sascha Peilicke -Scott Chacon -Sebastian Schuberth -Sergey Nikishin -Shawn O. Pearce -Shuhei Tanuma -Steve Frécinaux -Sven Strickroth -Talya "kivikakk" Connor -Tim Branyen -Tim Clem -Tim Harder -Torsten Bögershausen -Trent Mick -Venus Xeon-Blonde -Vicent Marti diff --git a/vendor/libgit2-sys/libgit2/CMakeLists.txt b/vendor/libgit2-sys/libgit2/CMakeLists.txt deleted file mode 100644 index fa38f42..0000000 --- a/vendor/libgit2-sys/libgit2/CMakeLists.txt +++ /dev/null @@ -1,158 +0,0 @@ -# libgit2: the cross-platform, linkable library implementation of git. -# See `README.md` for build instructions. -# -# This top-level CMakeLists.txt sets up configuration options and -# determines which subprojects to build. - -cmake_minimum_required(VERSION 3.5.1) - -project(libgit2 VERSION "1.9.7" LANGUAGES C) - -# Add find modules to the path -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") - -# -# Build options -# - -# Experimental features -option(EXPERIMENTAL_SHA256 "Enable experimental SHA256 support (for R&D/testing)" OFF) - -# Optional subsystems -option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) -option(BUILD_TESTS "Build Tests using the Clar suite" ON) -option(BUILD_CLI "Build the command-line interface" ON) -option(BUILD_EXAMPLES "Build library usage example apps" OFF) -option(BUILD_FUZZERS "Build the fuzz targets" OFF) - -# Suggested functionality that may not be available on a per-platform basis -option(USE_THREADS "Use threads for parallel processing when possible" ON) -option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON) - -# Backend selection - set(USE_SSH "" CACHE STRING "Enables SSH support and optionally selects provider. One of ON, OFF, or a specific provider: libssh2 or exec. (Defaults to OFF.)") - set(USE_HTTPS "" CACHE STRING "Enable HTTPS support and optionally selects the provider. One of ON, OFF, or a specific provider: OpenSSL, OpenSSL-FIPS, OpenSSL-Dynamic, mbedTLS, SecureTransport, Schannel, or WinHTTP. (Defaults to ON.)") - set(USE_SHA1 "" CACHE STRING "Selects SHA1 provider. One of CollisionDetection, HTTPS, or a specific provider. (Defaults to CollisionDetection.)") - set(USE_SHA256 "" CACHE STRING "Selects SHA256 provider. One of Builtin, HTTPS, or a specific provider. (Defaults to HTTPS.)") -option(USE_GSSAPI "Enable SPNEGO authentication using GSSAPI" OFF) - set(USE_HTTP_PARSER "" CACHE STRING "Selects HTTP Parser support: http-parser, llhttp, or builtin. (Defaults to builtin.)") -# set(USE_XDIFF "" CACHE STRING "Specifies the xdiff implementation; either system or builtin.") - set(REGEX_BACKEND "" CACHE STRING "Selects regex provider. One of regcomp_l, pcre2, pcre, regcomp, or builtin.") -option(USE_BUNDLED_ZLIB "Use the bundled version of zlib. Can be set to one of Bundled(ON)/Chromium. The Chromium option requires a x86_64 processor with SSE4.2 and CLMUL" OFF) - -# Debugging options -option(USE_LEAK_CHECKER "Run tests with leak checker" OFF) -option(USE_STANDALONE_FUZZERS "Enable standalone fuzzers (compatible with gcc)" OFF) -option(DEBUG_POOL "Enable debug pool allocator" OFF) -option(DEBUG_STRICT_ALLOC "Enable strict allocator behavior" OFF) -option(DEBUG_STRICT_OPEN "Enable path validation in open" OFF) - -# Output options -option(SONAME "Set the (SO)VERSION of the target" ON) - set(LIBGIT2_FILENAME "git2" CACHE STRING "Name of the produced binary") -option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF) - -# Compilation options -# Default to c99 on Android Studio for compatibility; c90 everywhere else -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Android") - set(CMAKE_C_STANDARD "99" CACHE STRING "The C standard to compile against") -else() - set(CMAKE_C_STANDARD "90" CACHE STRING "The C standard to compile against") -endif() -option(CMAKE_C_EXTENSIONS "Whether compiler extensions are supported" OFF) -option(ENABLE_WERROR "Enable compilation with -Werror" OFF) - -if(UNIX) - # NTLM client requires crypto libraries from the system HTTPS stack - if(USE_HTTPS STREQUAL "OFF") - option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF) - else() - option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON) - endif() - - option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF) -endif() - -if(APPLE) - option(USE_ICONV "Link with and use iconv library" ON) -endif() - -if(MSVC) - # This option must match the settings used in your program, in particular if you - # are linking statically - option(STATIC_CRT "Link the static CRT libraries" ON) - - # If you want to embed a copy of libssh2 into libgit2, pass a - # path to libssh2 - option(EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF) - - # Enable leak checking using the debugging C runtime. - option(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF) -endif() - -if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) -endif() - - -# Modules - -include(FeatureSummary) -include(CheckLibraryExists) -include(CheckFunctionExists) -include(CheckSymbolExists) -include(CheckStructHasMember) -include(CheckPrototypeDefinitionSafe) -include(AddCFlagIfSupported) -include(FindPkgLibraries) -include(FindThreads) -include(FindStatNsec) -include(Findfutimens) -include(GNUInstallDirs) -include(IdeSplitSources) -include(EnableWarnings) -include(DefaultCFlags) -include(ExperimentalFeatures) - - -# -# Subdirectories -# - -add_subdirectory(src) - -if(BUILD_TESTS) - enable_testing() - add_subdirectory(tests) -endif() - -if(BUILD_EXAMPLES) - add_subdirectory(examples) -endif() - -if(BUILD_FUZZERS) - if((BUILD_TESTS OR BUILD_EXAMPLES) AND NOT USE_STANDALONE_FUZZERS) - message(FATAL_ERROR "Cannot build the fuzzer and the tests or examples together") - endif() - add_subdirectory(fuzzers) -endif() - - -# Export for people who use us as a dependency - -if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") - set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE) - set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE) -endif() - - -# Summary - -feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:") -feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:") - -# warn for not using sha1dc - -foreach(WARNING ${WARNINGS}) - message(WARNING ${WARNING}) -endforeach() diff --git a/vendor/libgit2-sys/libgit2/COPYING b/vendor/libgit2-sys/libgit2/COPYING deleted file mode 100644 index 80788a3..0000000 --- a/vendor/libgit2-sys/libgit2/COPYING +++ /dev/null @@ -1,1482 +0,0 @@ - libgit2 is Copyright (C) the libgit2 contributors, - unless otherwise stated. See the AUTHORS file for details. - - Note that the only valid version of the GPL as far as this project - is concerned is _this_ particular version of the license (ie v2, not - v2.2 or v3.x or whatever), unless explicitly otherwise stated. - ----------------------------------------------------------------------- - - LINKING EXCEPTION - - In addition to the permissions in the GNU General Public License, - the authors give you unlimited permission to link the compiled - version of this library into combinations with other programs, - and to distribute those combinations without any restriction - coming from the use of this file. (The General Public License - restrictions do apply in other respects; for example, they cover - modification of the file, and distribution when not linked into - a combined executable.) - ----------------------------------------------------------------------- - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. - ----------------------------------------------------------------------- - -The bundled ZLib code is licensed under the ZLib license: - - (C) 1995-2022 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - ----------------------------------------------------------------------- - -The Clar framework is licensed under the ISC license: - -Copyright (c) 2011-2015 Vicent Marti - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ----------------------------------------------------------------------- - -The bundled PCRE implementation (deps/pcre2/) is licensed under the -PCRE2 Licence. - -PCRE2 is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - -Releases 10.00 and above of PCRE2 are distributed under the terms of the "BSD" -licence, as specified below, with one exemption for certain binary -redistributions. The documentation for PCRE2, supplied in the "doc" directory, -is distributed under the same terms as the software itself. The data in the -testdata directory is not copyrighted and is in the public domain. - -The basic library functions are written in C and are freestanding. Also -included in the distribution is a just-in-time compiler that can be used to -optimize pattern matching. This is an optional feature that can be omitted when -the library is built. The just-in-time compiler is separately licensed under the -"2-clause BSD" licence. - - -COPYRIGHT ---------- - -### The basic library functions - - Written by: Philip Hazel - Email local part: Philip.Hazel - Email domain: gmail.com - - Retired from University of Cambridge Computing Service, - Cambridge, England. - - Copyright (c) 1997-2007 University of Cambridge - Copyright (c) 2007-2024 Philip Hazel - All rights reserved. - -### PCRE2 Just-In-Time compilation support - - Written by: Zoltan Herczeg - Email local part: hzmester - Email domain: freemail.hu - - Copyright (c) 2010-2024 Zoltan Herczeg - All rights reserved. - -### Stack-less Just-In-Time compiler - - Written by: Zoltan Herczeg - Email local part: hzmester - Email domain: freemail.hu - - Copyright (c) 2009-2024 Zoltan Herczeg - All rights reserved. - -The code in the `deps/sljit` directory has its own LICENSE file. - -### All other contributions - -Many other contributors have participated in the authorship of PCRE2. As PCRE2 -has never required a Contributor Licensing Agreement, or other copyright -assignment agreement, all contributions have copyright retained by each -original contributor or their employer. - - -THE "BSD" LICENCE ------------------ - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notices, - this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright - notices, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -* Neither the name of the University of Cambridge nor the names of any - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - -EXEMPTION FOR BINARY LIBRARY-LIKE PACKAGES ------------------------------------------- - -The second condition in the BSD licence (covering binary redistributions) does -not apply all the way down a chain of software. If binary package A includes -PCRE2, it must respect the condition, but if package B is software that -includes package A, the condition is not imposed on package B unless it uses -PCRE2 independently. - ----------------------------------------------------------------------- - -The bundled winhttp definition files (deps/winhttp/) are licensed under -the GNU LGPL (available at the end of this file). - -Copyright (C) 2007 Francois Gouget - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - ----------------------------------------------------------------------- - - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - ----------------------------------------------------------------------- - -The bundled SHA1 collision detection code is licensed under the MIT license: - -MIT License - -Copyright (c) 2017: - Marc Stevens - Cryptology Group - Centrum Wiskunde & Informatica - P.O. Box 94079, 1090 GB Amsterdam, Netherlands - marc@marc-stevens.nl - - Dan Shumow - Microsoft Research - danshu@microsoft.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - ----------------------------------------------------------------------- - -The bundled wildmatch code is licensed under the BSD license: - -Copyright Rich Salz. -All rights reserved. - -Redistribution and use in any form are permitted provided that the -following restrictions are are met: - -1. Source distributions must retain this entire copyright notice - and comment. -2. Binary distributions must include the acknowledgement ``This - product includes software developed by Rich Salz'' in the - documentation or other materials provided with the - distribution. This must not be represented as an endorsement - or promotion without specific prior written permission. -3. The origin of this software must not be misrepresented, either - by explicit claim or by omission. Credits must appear in the - source and documentation. -4. Altered versions must be plainly marked as such in the source - and documentation and must not be misrepresented as being the - original software. - -THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ----------------------------------------------------------------------- - -Portions of the OpenSSL headers are included under the OpenSSL license: - -Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) -All rights reserved. - -This package is an SSL implementation written -by Eric Young (eay@cryptsoft.com). -The implementation was written so as to conform with Netscapes SSL. - -This library is free for commercial and non-commercial use as long as -the following conditions are aheared to. The following conditions -apply to all code found in this distribution, be it the RC4, RSA, -lhash, DES, etc., code; not just the SSL code. The SSL documentation -included with this distribution is covered by the same copyright terms -except that the holder is Tim Hudson (tjh@cryptsoft.com). - -Copyright remains Eric Young's, and as such any Copyright notices in -the code are not to be removed. -If this package is used in a product, Eric Young should be given attribution -as the author of the parts of the library used. -This can be in the form of a textual message at program startup or -in documentation (online or textual) provided with the package. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. All advertising materials mentioning features or use of this software - must display the following acknowledgement: - "This product includes cryptographic software written by - Eric Young (eay@cryptsoft.com)" - The word 'cryptographic' can be left out if the rouines from the library - being used are not cryptographic related :-). -4. If you include any Windows specific code (or a derivative thereof) from - the apps directory (application code) you must include an acknowledgement: - "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - -THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - -The licence and distribution terms for any publically available version or -derivative of this code cannot be changed. i.e. this code cannot simply be -copied and put under another distribution licence -[including the GNU Public Licence.] - -==================================================================== -Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - -3. All advertising materials mentioning features or use of this - software must display the following acknowledgment: - "This product includes software developed by the OpenSSL Project - for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - -4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - endorse or promote products derived from this software without - prior written permission. For written permission, please contact - openssl-core@openssl.org. - -5. Products derived from this software may not be called "OpenSSL" - nor may "OpenSSL" appear in their names without prior written - permission of the OpenSSL Project. - -6. Redistributions of any form whatsoever must retain the following - acknowledgment: - "This product includes software developed by the OpenSSL Project - for use in the OpenSSL Toolkit (http://www.openssl.org/)" - -THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY -EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR -ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -OF THE POSSIBILITY OF SUCH DAMAGE. - ----------------------------------------------------------------------- - -The xoroshiro256** implementation is licensed in the public domain: - -Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) - -To the extent possible under law, the author has dedicated all copyright -and related and neighboring rights to this software to the public domain -worldwide. This software is distributed without any warranty. - -See . - ----------------------------------------------------------------------- - -The built-in SHA256 support (src/hash/rfc6234) is taken from RFC 6234 -under the following license: - -Copyright (c) 2011 IETF Trust and the persons identified as -authors of the code. All rights reserved. - -Redistribution and use in source and binary forms, with or -without modification, are permitted provided that the following -conditions are met: - -- Redistributions of source code must retain the above - copyright notice, this list of conditions and - the following disclaimer. - -- Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - -- Neither the name of Internet Society, IETF or IETF Trust, nor - the names of specific contributors, may be used to endorse or - promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ----------------------------------------------------------------------- - -The built-in git_fs_path_basename_r() function is based on the -Android implementation, BSD licensed: - -Copyright (C) 2008 The Android Open Source Project -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - ----------------------------------------------------------------------- - -The bundled ntlmclient code is licensed under the MIT license: - -Copyright (c) Edward Thomson. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- - -Portions of this software derived from Team Explorer Everywhere: - -Copyright (c) Microsoft Corporation - -All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - ---------------------------------------------------------------------------- - -Portions of this software derived from the LLVM Compiler Infrastructure: - -Copyright (c) 2003-2016 University of Illinois at Urbana-Champaign. -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. - ---------------------------------------------------------------------------- - -Portions of this software derived from Unicode, Inc: - -Copyright 2001-2004 Unicode, Inc. - -Disclaimer - -This source code is provided as is by Unicode, Inc. No claims are -made as to fitness for any particular purpose. No warranties of any -kind are expressed or implied. The recipient agrees to determine -applicability of information provided. If this file has been -purchased on magnetic or optical media from Unicode, Inc., the -sole remedy for any claim will be exchange of defective media -within 90 days of receipt. - -Limitations on Rights to Redistribute This Code - -Unicode, Inc. hereby grants the right to freely use the information -supplied in this file in the creation of products supporting the -Unicode Standard, and to make copies of this file in any form -for internal or external distribution as long as this notice -remains attached. - ---------------------------------------------------------------------------- - -Portions of this software derived from sheredom/utf8.h: - -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to - ---------------------------------------------------------------------------- - -Portions of this software derived from RFC 1320: - -Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved. - -License to copy and use this software is granted provided that it -is identified as the "RSA Data Security, Inc. MD4 Message-Digest -Algorithm" in all material mentioning or referencing this software -or this function. - -License is also granted to make and use derivative works provided -that such works are identified as "derived from the RSA Data -Security, Inc. MD4 Message-Digest Algorithm" in all material -mentioning or referencing the derived work. - -RSA Data Security, Inc. makes no representations concerning either -the merchantability of this software or the suitability of this -software for any particular purpose. It is provided "as is" -without express or implied warranty of any kind. - -These notices must be retained in any copies of any part of this -documentation and/or software. - ----------------------------------------------------------------------- - -The bundled llhttp dependency is licensed under the MIT license: - -Copyright Fedor Indutny, 2018. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to permit -persons to whom the Software is furnished to do so, subject to the -following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/libgit2-sys/libgit2/FUNDING.json b/vendor/libgit2-sys/libgit2/FUNDING.json deleted file mode 100644 index eb2f631..0000000 --- a/vendor/libgit2-sys/libgit2/FUNDING.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "drips": { - "ethereum": { - "ownedBy": "0x939121dD13f796C69d0Ac4185787285518081f8D" - } - } -} diff --git a/vendor/libgit2-sys/libgit2/README.md b/vendor/libgit2-sys/libgit2/README.md deleted file mode 100644 index 65116b5..0000000 --- a/vendor/libgit2-sys/libgit2/README.md +++ /dev/null @@ -1,573 +0,0 @@ -libgit2 - the Git linkable library -================================== -[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9609/badge)](https://www.bestpractices.dev/projects/9609) - -| Build Status | | -| ------------ | - | -| **main** branch builds | [![CI Build](https://github.com/libgit2/libgit2/actions/workflows/main.yml/badge.svg?branch=main&event=push)](https://github.com/libgit2/libgit2/actions/workflows/main.yml?query=event%3Apush+branch%3Amain) [![Experimental Features](https://github.com/libgit2/libgit2/actions/workflows/experimental.yml/badge.svg?branch=main)](https://github.com/libgit2/libgit2/actions/workflows/experimental.yml?query=event%3Apush+branch%3Amain) | -| **v1.9 branch** builds | [![CI Build](https://github.com/libgit2/libgit2/actions/workflows/main.yml/badge.svg?branch=maint%2Fv1.9&event=push)](https://github.com/libgit2/libgit2/actions/workflows/main.yml?query=event%3Apush+branch%3Amaint%2Fv1.9) [![Experimental Features](https://github.com/libgit2/libgit2/actions/workflows/experimental.yml/badge.svg?branch=maint%2Fv1.9)](https://github.com/libgit2/libgit2/actions/workflows/experimental.yml?query=event%3Apush+branch%3Amaint%2Fv1.9) | -| **v1.8 branch** builds | [![CI Build](https://github.com/libgit2/libgit2/actions/workflows/main.yml/badge.svg?branch=maint%2Fv1.8&event=push)](https://github.com/libgit2/libgit2/actions/workflows/main.yml?query=event%3Apush+branch%3Amaint%2Fv1.8) [![Experimental Features](https://github.com/libgit2/libgit2/actions/workflows/experimental.yml/badge.svg?branch=maint%2Fv1.8)](https://github.com/libgit2/libgit2/actions/workflows/experimental.yml?query=event%3Apush+branch%3Amaint%2Fv1.8) | -| **Nightly** builds | [![Nightly Build](https://github.com/libgit2/libgit2/actions/workflows/nightly.yml/badge.svg?branch=main&event=schedule)](https://github.com/libgit2/libgit2/actions/workflows/nightly.yml) [![Coverity Scan Status](https://scan.coverity.com/projects/639/badge.svg)](https://scan.coverity.com/projects/639) | - -`libgit2` is a portable, pure C implementation of the Git core methods -provided as a linkable library with a solid API, allowing to build Git -functionality into your application. - -`libgit2` is used in a variety of places, from GUI clients to hosting -providers ("forges") and countless utilities and applications in -between. Because it's written in C, it can be made available to any -other programming language through "bindings", so you can use it in -[Ruby](https://github.com/libgit2/rugged), -[.NET](https://github.com/libgit2/libgit2sharp), -[Python](http://www.pygit2.org/), -[Node.js](http://nodegit.org), -[Rust](https://github.com/rust-lang/git2-rs), and more. - -`libgit2` is licensed under a **very permissive license** (GPLv2 with -a special Linking Exception). This means that you can link against -the library with any kind of software without making that software -fall under the GPL. Changes to libgit2 would still be covered under -its GPL license. - -Table of Contents -================= - -* [Using libgit2](#using-libgit2) -* [Quick Start](#quick-start) -* [Getting Help](#getting-help) -* [What It Can Do](#what-it-can-do) -* [Optional dependencies](#optional-dependencies) -* [Initialization](#initialization) -* [Threading](#threading) -* [Conventions](#conventions) -* [Building libgit2 - Using CMake](#building-libgit2---using-cmake) - * [Building](#building) - * [Installation](#installation) - * [Advanced Usage](#advanced-usage) - * [Compiler and linker options](#compiler-and-linker-options) - * [macOS](#macos) - * [iOS](#ios) - * [Android](#android) - * [MinGW](#mingw) -* [Language Bindings](#language-bindings) -* [How Can I Contribute?](#how-can-i-contribute) -* [License](#license) - -Using libgit2 -============= - -Most of these instructions assume that you're writing an application -in C and want to use libgit2 directly. If you're _not_ using C, -and you're writing in a different language or platform like .NET, -Node.js, or Ruby, then there is probably a -"[language binding](#language-bindings)" that you can use to take care -of the messy tasks of calling into native code. - -But if you _do_ want to use libgit2 directly - because you're building -an application in C - then you may be able use an existing binary. -There are packages for the -[vcpkg](https://github.com/Microsoft/vcpkg) and -[conan](https://conan.io/center/recipes/libgit2) -package managers. And libgit2 is available in -[Homebrew](https://formulae.brew.sh/formula/libgit2) and most Linux -distributions. - -However, these versions _may_ be outdated and we recommend using the -latest version if possible. Thankfully libgit2 is not hard to compile. - -Quick Start -=========== - -**Prerequisites** for building libgit2: - -1. [CMake](https://cmake.org/), and is recommended to be installed into - your `PATH`. -2. [Python](https://www.python.org) is used by our test framework, and - should be installed into your `PATH`. -3. C compiler: libgit2 is C90 and should compile on most compilers. - * Windows: Visual Studio is recommended - * Mac: Xcode is recommended - * Unix: gcc or clang is recommended. - -**Build** - -1. Create a build directory beneath the libgit2 source directory, - and change into it: `mkdir build && cd build` -2. Create the cmake build environment: `cmake ..` -3. Build libgit2: `cmake --build .` - -Trouble with these steps? Read our [troubleshooting guide](docs/troubleshooting.md). -More detailed build guidance is available below. - -Getting Help -============ - -**Chat with us** - -- via IRC: join [#libgit2](https://web.libera.chat/#libgit2) on - [libera](https://libera.chat). -- via Slack: visit [slack.libgit2.org](http://slack.libgit2.org/) - to sign up, then join us in `#libgit2` - -**Getting Help** - -If you have questions about the library, please be sure to check out the -[API documentation](https://libgit2.org/libgit2/). If you still have -questions, reach out to us on Slack or post a question on -[StackOverflow](http://stackoverflow.com/questions/tagged/libgit2) -(with the `libgit2` tag). - -**Reporting Bugs** - -Please open a [GitHub Issue](https://github.com/libgit2/libgit2/issues) -and include as much information as possible. If possible, provide -sample code that illustrates the problem you're seeing. If you're -seeing a bug only on a specific repository, please provide a link to -it if possible. - -We ask that you not open a GitHub Issue for help, only for bug reports. - -**Reporting Security Issues** - -Please have a look at SECURITY.md. - -What It Can Do -============== - -libgit2 provides you with the ability to manage Git repositories in the -programming language of your choice. It's used in production to power many -applications including GitHub.com, Plastic SCM and Azure DevOps. - -It does not aim to replace the git tool or its user-facing commands. Some -APIs resemble the plumbing commands as those align closely with the -concepts of the Git system, but most commands a user would type are out -of scope for this library to implement directly. - -The library provides: - -* SHA conversions, formatting and shortening -* abstracted ODB backend system -* commit, tag, tree and blob parsing, editing, and write-back -* tree traversal -* revision walking -* index file (staging area) manipulation -* reference management (including packed references) -* config file management -* high level repository management -* thread safety and reentrancy -* descriptive and detailed error messages -* ...and more (over 175 different API calls) - -As libgit2 is purely a consumer of the Git system, we have to -adjust to changes made upstream. This has two major consequences: - -* Some changes may require us to change provided interfaces. While - we try to implement functions in a generic way so that no future - changes are required, we cannot promise a completely stable API. -* As we have to keep up with changes in behavior made upstream, we - may lag behind in some areas. We usually to document these - incompatibilities in our issue tracker with the label "git change". - -Optional dependencies -===================== - -While the library provides git functionality with very few -dependencies, some recommended dependencies are used for performance -or complete functionality. - -- Hash generation: Git uses SHA1DC (collision detecting SHA1) for - its default hash generation. SHA256 support is experimental, and - optimized support is provided by system libraries on macOS and - Windows, or by the HTTPS library on Unix systems when available. -- Threading: is provided by the system libraries on Windows, and - pthreads on Unix systems. -- HTTPS: is provided by the system libraries on macOS and Windows, - or by OpenSSL or mbedTLS on other Unix systems. -- SSH: is provided by [libssh2](https://libssh2.org/) or by invoking - [OpenSSH](https://www.openssh.com). -- Unicode: is provided by the system libraries on Windows and macOS. - -Initialization -=============== - -The library needs to keep track of some global state. Call - - git_libgit2_init(); - -before calling any other libgit2 functions. You can call this function many times. A matching number of calls to - - git_libgit2_shutdown(); - -will free the resources. Note that if you have worker threads, you should -call `git_libgit2_shutdown` *after* those threads have exited. If you -require assistance coordinating this, simply have the worker threads call -`git_libgit2_init` at startup and `git_libgit2_shutdown` at shutdown. - -Threading -========= - -See [threading](docs/threading.md) for information - -Conventions -=========== - -See [conventions](docs/conventions.md) for an overview of the external -and internal API/coding conventions we use. - -Building libgit2 - Using CMake -============================== - -Building --------- - -`libgit2` builds cleanly on most platforms without any external -dependencies as a requirement. `libgit2` is built using -[CMake]() (version 2.8 or newer) on all platforms. - -On most systems you can build the library using the following commands - - $ mkdir build && cd build - $ cmake .. - $ cmake --build . - -To include the examples in the build, use `cmake -DBUILD_EXAMPLES=ON ..` -instead of `cmake ..`. The built executable for the examples can then -be found in `build/examples`, relative to the toplevel directory. - -Alternatively you can point the CMake GUI tool to the CMakeLists.txt file and generate platform specific build project or IDE workspace. - -If you're not familiar with CMake, [a more detailed explanation](https://preshing.com/20170511/how-to-build-a-cmake-based-project/) may be helpful. - -Advanced Options ----------------- - -You can specify a number of options to `cmake` that will change the -way `libgit2` is built. To use this, specify `-Doption=value` during -the initial `cmake` configuration. For example, to enable SHA256 -compatibility: - - $ mkdir build && cd build - $ cmake -DEXPERIMENTAL_SHA256=ON .. - $ cmake --build . - -libgit2 options: - -* `EXPERIMENTAL_SHA256=ON`: turns on SHA256 compatibility; note that - this is an API-incompatible change, hence why it is labeled - "experimental" - -Build options: - -* `BUILD_EXAMPLES=ON`: builds the suite of example code -* `BUILD_FUZZERS=ON`: builds the fuzzing suite -* `ENABLE_WERROR=ON`: build with `-Werror` or the equivalent, which turns - compiler warnings into errors in the libgit2 codebase (but not its - dependencies) - -Dependency options: - -* `USE_SSH=type`: enables SSH support and optionally selects the provider; - `type` can be set to `libssh2` or `exec` (which will execute an external - OpenSSH command). `ON` implies `libssh2`; defaults to `OFF`. -* `USE_HTTPS=type`: enables HTTPS support and optionally selects the - provider; `type` can be set to `OpenSSL`, `OpenSSL-Dynamic` (to not - link against OpenSSL, but load it dynamically), `SecureTransport`, - `Schannel` or `WinHTTP`; the default is `SecureTransport` on macOS, - `WinHTTP` on Windows, and whichever of `OpenSSL` or `mbedTLS` is - detected on other platforms. Defaults to `ON`. -* `USE_SHA1=type`: selects the SHA1 mechanism to use; `type` can be set - to `CollisionDetection`, `HTTPS` to use the system or HTTPS provider, - or one of `OpenSSL`, `OpenSSL-Dynamic`, `OpenSSL-FIPS` (to use FIPS - compliant routines in OpenSSL), `CommonCrypto`, or `Schannel`. - Defaults to `CollisionDetection`. This option is retained for - backward compatibility and should not be changed. -* `USE_SHA256=type`: selects the SHA256 mechanism to use; `type` can be - set to `HTTPS` to use the system or HTTPS driver, `builtin`, or one of - `OpenSSL`, `OpenSSL-Dynamic`, `OpenSSL-FIPS` (to use FIPS compliant - routines in OpenSSL), `CommonCrypto`, or `Schannel`. Defaults to `HTTPS`. -* `USE_GSSAPI=`: enables GSSAPI for SPNEGO authentication on - Unix. Defaults to `OFF`. -* `USE_HTTP_PARSER=type`: selects the HTTP Parser; either `http-parser` - for an external - [`http-parser`](https://github.com/nodejs/http-parser) dependency, - `llhttp` for an external [`llhttp`](https://github.com/nodejs/llhttp) - dependency, or `builtin`. Defaults to `builtin`. -* `REGEX_BACKEND=type`: selects the regular expression backend to use; - one of `regcomp_l`, `pcre2`, `pcre`, `regcomp`, or `builtin`. The - default is to use `regcomp_l` where available, PCRE if found, otherwise, - to use the builtin. -* `USE_BUNDLED_ZLIB=type`: selects the bundled zlib; either `ON` or `OFF`. - Defaults to using the system zlib if available, falling back to the - bundled zlib. - -Locating Dependencies ---------------------- - -The `libgit2` project uses `cmake` since it helps with cross-platform -projects, especially those with many dependencies. If your dependencies -are in non-standard places, you may want to use the `_ROOT_DIR` options -to specify their location. For example, to specify an OpenSSL location: - - $ cmake -DOPENSSL_ROOT_DIR=/tmp/openssl-3.3.2 .. - -Since these options are general to CMake, their -[documentation](https://cmake.org/documentation/) may be helpful. If -you have questions about dependencies, please [contact us](#getting-help). - -Running Tests -------------- - -Once built, you can run the tests from the `build` directory with the command - - $ ctest -V - -Alternatively you can run the test suite directly using, - - $ ./libgit2_tests - -Invoking the test suite directly is useful because it allows you to execute -individual tests, or groups of tests using the `-s` flag. For example, to -run the index tests: - - $ ./libgit2_tests -sindex - -To run a single test named `index::racy::diff`, which corresponds to -the test function -[`test_index_racy__diff`](https://github.com/libgit2/libgit2/blob/main/tests/libgit2/index/racy.c#L22): - - $ ./libgit2_tests -sindex::racy::diff - -The test suite will print a `.` for every passing test, and an `F` for any -failing test. An `S` indicates that a test was skipped because it is not -applicable to your platform or is particularly expensive. - -**Note:** There should be _no_ failing tests when you build an unmodified -source tree from a [release](https://github.com/libgit2/libgit2/releases), -or from the [main branch](https://github.com/libgit2/libgit2/tree/main). -Please contact us or -[open an issue](https://github.com/libgit2/libgit2/issues) -if you see test failures. - -Installation ------------- - -To install the library you can specify the install prefix by setting: - - $ cmake .. -DCMAKE_INSTALL_PREFIX=/install/prefix - $ cmake --build . --target install - -Advanced Usage --------------- - -For more advanced use or questions about CMake please read the -[CMake FAQ](https://cmake.org/Wiki/CMake_FAQ). - -The following CMake variables are declared: - -- `CMAKE_INSTALL_BINDIR`: Where to install binaries to. -- `CMAKE_INSTALL_LIBDIR`: Where to install libraries to. -- `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to. -- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON) -- `BUILD_TESTS`: Build the unit and integration test suites (defaults to ON) -- `USE_THREADS`: Build libgit2 with threading support (defaults to ON) - -To list all build options and their current value, you can do the -following: - - # Create and set up a build directory - $ mkdir build && cd build - $ cmake .. - - # List all build options and their values - $ cmake -L - -Compiler and linker options ---------------------------- - -There are several options that control the behavior of the compiler and -linker. These flags may be useful for cross-compilation or specialized -setups. - -- `CMAKE_C_FLAGS`: Set your own compiler flags -- `CMAKE_C_STANDARD`: the C standard to compile against; defaults to `C90` -- `CMAKE_C_EXTENSIONS`: whether compiler extensions are supported; defaults to `OFF` -- `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries -- `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`: -Tell CMake where to find those specific libraries -- `LINK_WITH_STATIC_LIBRARIES`: Link only with static versions of -system libraries - -macOS -------- - -If you'd like to work with Xcode, you can generate an Xcode project with "-G Xcode". - - # Create and set up a build directory - $ mkdir build && cd build - $ cmake -G Xcode .. - -> [!TIP] -> Universal binary support: -> -> If you want to build a universal binary for macOS 11.0+, CMake sets it -> all up for you if you use `-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"` -> when configuring. -> -> [Deprecated] If you want to build a universal binary for Mac OS X -> (10.4.4 ~ 10.6), CMake sets it all up for you if you use -> `-DCMAKE_OSX_ARCHITECTURES="i386;x86_64"` when configuring. - -iOS -------- - -1. Get an iOS cmake toolchain File: - -You can use a pre-existing toolchain file like [ios-cmake](https://github.com/leetal/ios-cmake) or write your own. - -2. Specify the toolchain and system Name: - -- The CMAKE_TOOLCHAIN_FILE variable points to the toolchain file for iOS. -- The CMAKE_SYSTEM_NAME should be set to iOS. - -3. Example Command: - -Assuming you're using the ios-cmake toolchain, the command might look like this: - -``` -cmake -G Xcode -DCMAKE_TOOLCHAIN_FILE=path/to/ios.toolchain.cmake -DCMAKE_SYSTEM_NAME=iOS -DPLATFORM=OS64 .. -``` - -4. Build the Project: - -After generating the project, open the .xcodeproj file in Xcode, select your iOS device or simulator as the target, and build your project. - -Android -------- - -Extract toolchain from NDK using, `make-standalone-toolchain.sh` script. -Optionally, crosscompile and install OpenSSL inside of it. Then create CMake -toolchain file that configures paths to your crosscompiler (substitute `{PATH}` -with full path to the toolchain): - - SET(CMAKE_SYSTEM_NAME Linux) - SET(CMAKE_SYSTEM_VERSION Android) - - SET(CMAKE_C_COMPILER {PATH}/bin/arm-linux-androideabi-gcc) - SET(CMAKE_CXX_COMPILER {PATH}/bin/arm-linux-androideabi-g++) - SET(CMAKE_FIND_ROOT_PATH {PATH}/sysroot/) - - SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) - SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - -Add `-DCMAKE_TOOLCHAIN_FILE={pathToToolchainFile}` to cmake command -when configuring. - -MinGW ------ - -If you want to build the library in MinGW environment with SSH support -enabled, you may need to pass -`-DCMAKE_LIBRARY_PATH="${MINGW_PREFIX}/${MINGW_CHOST}/lib/"` flag -to CMake when configuring. This is because CMake cannot find the -Win32 libraries in MinGW folders by default and you might see an -error message stating that CMake could not resolve `ws2_32` library -during configuration. - -Another option would be to install `msys2-w32api-runtime` package before -configuring. This package installs the Win32 libraries into `/usr/lib` -folder which is by default recognized as the library path by CMake. -Please note though that this package is meant for MSYS subsystem which -is different from MinGW. - -Language Bindings -================================== - -Here are the bindings to libgit2 that are currently available: - -* C++ - * libqgit2, Qt bindings -* Chicken Scheme - * chicken-git -* D - * dlibgit -* Delphi - * GitForDelphi - * libgit2-delphi -* Erlang - * Geef -* Go - * git2go -* GObject - * libgit2-glib -* Guile - * Guile-Git -* Haskell - * hgit2 -* Java - * Jagged - * Git24j -* Javascript / WebAssembly ( browser and nodejs ) - * WASM-git -* Julia - * LibGit2.jl -* Lua - * luagit2 -* .NET - * libgit2sharp -* Node.js - * nodegit -* Objective-C - * objective-git -* OCaml - * ocaml-libgit2 -* Parrot Virtual Machine - * parrot-libgit2 -* Perl - * Git-Raw -* Pharo Smalltalk - * libgit2-pharo-bindings -* PHP - * php-git2 -* Python - * pygit2 -* R - * gert - * git2r -* Ruby - * Rugged -* Rust - * git2-rs -* Swift - * SwiftGit2 -* Tcl - * lg2 -* Vala - * libgit2.vapi - -If you start another language binding to libgit2, please let us know so -we can add it to the list. - -How Can I Contribute? -================================== - -We welcome new contributors! We have a number of issues marked as -["up for grabs"](https://github.com/libgit2/libgit2/issues?q=is%3Aissue+is%3Aopen+label%3A%22up+for+grabs%22) -and -["easy fix"](https://github.com/libgit2/libgit2/issues?utf8=✓&q=is%3Aissue+is%3Aopen+label%3A%22easy+fix%22) -that are good places to jump in and get started. There's much more detailed -information in our list of [outstanding projects](docs/projects.md). - -Please be sure to check the [contribution guidelines](docs/contributing.md) -to understand our workflow, and the libgit2 -[coding conventions](docs/conventions.md). - -License -================================== - -`libgit2` is under GPL2 **with linking exception**. This means you can -link to and use the library from any program, proprietary or open source; -paid or gratis. However, if you modify libgit2 itself, you must distribute -the source to your modified version of libgit2. - -See the [COPYING file](COPYING) for the full license text. diff --git a/vendor/libgit2-sys/libgit2/SECURITY.md b/vendor/libgit2-sys/libgit2/SECURITY.md deleted file mode 100644 index 914e660..0000000 --- a/vendor/libgit2-sys/libgit2/SECURITY.md +++ /dev/null @@ -1,14 +0,0 @@ -# Security Policy - -## Supported Versions - -This project will always provide security fixes for the latest two released -versions. E.g. if the latest version is v0.28.x, then we will provide security -fixes for both v0.28.x and v0.27.y, but no earlier versions. - -## Reporting a Vulnerability - -In case you think to have found a security issue with libgit2, please do not -open a public issue. Instead, you can report the issue to the private mailing -list [security@libgit2.com](mailto:security@libgit2.com). We will acknowledge -receipt of your message in at most three days and try to clarify further steps. diff --git a/vendor/libgit2-sys/libgit2/api.docurium b/vendor/libgit2-sys/libgit2/api.docurium deleted file mode 100644 index bf73327..0000000 --- a/vendor/libgit2-sys/libgit2/api.docurium +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "libgit2", - "github": "libgit2/libgit2", - "input": "include", - "prefix": "git_", - "output": "docs", - "branch": "gh-pages", - "examples": "examples", - "legacy": { - "input": {"src/git": ["v0.1.0"], - "src/git2": ["v0.2.0", "v0.3.0"]} - } -} diff --git a/vendor/libgit2-sys/libgit2/cmake/AddCFlagIfSupported.cmake b/vendor/libgit2-sys/libgit2/cmake/AddCFlagIfSupported.cmake deleted file mode 100644 index 685f26a..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/AddCFlagIfSupported.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# - Append compiler flag to CMAKE_C_FLAGS if compiler supports it -# ADD_C_FLAG_IF_SUPPORTED() -# - the compiler flag to test -# This internally calls the CHECK_C_COMPILER_FLAG macro. - -include(CheckCCompilerFlag) - -macro(ADD_C_FLAG _FLAG) - string(TOUPPER ${_FLAG} UPCASE) - string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) - string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) - check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) - - if(IS_${UPCASE_PRETTY}_SUPPORTED) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") - else() - message(FATAL_ERROR "Required flag ${_FLAG} is not supported") - endif() -endmacro() - -macro(ADD_C_FLAG_IF_SUPPORTED _FLAG) - string(TOUPPER ${_FLAG} UPCASE) - string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) - string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) - check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) - - if(IS_${UPCASE_PRETTY}_SUPPORTED) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") - endif() -endmacro() diff --git a/vendor/libgit2-sys/libgit2/cmake/AddClarTest.cmake b/vendor/libgit2-sys/libgit2/cmake/AddClarTest.cmake deleted file mode 100644 index 7439416..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/AddClarTest.cmake +++ /dev/null @@ -1,7 +0,0 @@ -function(ADD_CLAR_TEST project name) - if(NOT USE_LEAK_CHECKER STREQUAL "OFF") - add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/${project}" ${ARGN}) - else() - add_test(${name} "${PROJECT_BINARY_DIR}/${project}" ${ARGN}) - endif() -endfunction(ADD_CLAR_TEST) diff --git a/vendor/libgit2-sys/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake b/vendor/libgit2-sys/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake deleted file mode 100644 index f82603d..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +++ /dev/null @@ -1,16 +0,0 @@ -include(CheckPrototypeDefinition) - -function(check_prototype_definition_safe function prototype return header variable) - # temporarily save CMAKE_C_FLAGS and disable warnings about unused - # unused functions and parameters, otherwise they will always fail - # if ENABLE_WERROR is on - set(SAVED_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - - disable_warnings(unused-function) - disable_warnings(unused-parameter) - - check_prototype_definition("${function}" "${prototype}" "${return}" "${header}" "${variable}") - - # restore CMAKE_C_FLAGS - set(CMAKE_C_FLAGS "${SAVED_CMAKE_C_FLAGS}") -endfunction() diff --git a/vendor/libgit2-sys/libgit2/cmake/DefaultCFlags.cmake b/vendor/libgit2-sys/libgit2/cmake/DefaultCFlags.cmake deleted file mode 100644 index 950b69c..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/DefaultCFlags.cmake +++ /dev/null @@ -1,159 +0,0 @@ -# Platform specific compilation flags -if(MSVC) - add_definitions(-D_SCL_SECURE_NO_WARNINGS) - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - - string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - - # /GF - String pooling - # /MP - Parallel build - set(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}") - - # /Gd - explicitly set cdecl calling convention - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd") - - # Remove warnings about operands that use different enum types. - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd5287") - - if(NOT (MSVC_VERSION LESS 1900)) - # /guard:cf - Enable Control Flow Guard - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf") - endif() - - if(STATIC_CRT) - set(CRT_FLAG_DEBUG "/MTd") - set(CRT_FLAG_RELEASE "/MT") - else() - set(CRT_FLAG_DEBUG "/MDd") - set(CRT_FLAG_RELEASE "/MD") - endif() - - if(WIN32_LEAKCHECK) - set(GIT_WIN32_LEAKCHECK 1) - set(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG}") - set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib") - endif() - - # /Zi - Create debugging information - # /Od - Disable optimization - # /D_DEBUG - #define _DEBUG - # /MTd - Statically link the multithreaded debug version of the CRT - # /MDd - Dynamically link the multithreaded debug version of the CRT - # /RTC1 - Run time checks - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}") - - # /DNDEBUG - Disables asserts - # /MT - Statically link the multithreaded release version of the CRT - # /MD - Dynamically link the multithreaded release version of the CRT - # /O2 - Optimize for speed - # /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off) - # /GL - Link time code generation (whole program optimization) - # /Gy - Function-level linking - set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") - - # /Oy- - Disable frame pointer omission (FPO) - set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}") - - # /O1 - Optimize for size - set(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") - - # /IGNORE:4221 - Ignore empty compilation units - set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221") - - # /DYNAMICBASE - Address space load randomization (ASLR) - # /NXCOMPAT - Data execution prevention (DEP) - # /LARGEADDRESSAWARE - >2GB user address space on x86 - # /VERSION - Embed version information in PE header - set(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}") - - if(NOT (MSVC_VERSION LESS 1900)) - # /GUARD:CF - Enable Control Flow Guard - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF") - endif() - - # /DEBUG - Create a PDB - # /LTCG - Link time code generation (whole program optimization) - # /OPT:REF /OPT:ICF - Fold out duplicate code at link step - # /INCREMENTAL:NO - Required to use /LTCG - # /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug) - set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") - set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") - set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") - - # Same linker settings for DLL as EXE - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") - set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") - set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") -else() - if(ENABLE_REPRODUCIBLE_BUILDS) - set(CMAKE_C_ARCHIVE_CREATE " Dqc ") - set(CMAKE_C_ARCHIVE_APPEND " Dq ") - set(CMAKE_C_ARCHIVE_FINISH " -D ") - endif() - - if(NOT BUILD_SHARED_LIBS AND LINK_WITH_STATIC_LIBRARIES) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - endif() - - set(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}") - - enable_warnings(all) - enable_warnings(extra) - - if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") - set(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}") - endif() - - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0") - - if(MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to - string(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") - else() - add_c_flag_if_supported(-fvisibility=hidden) - endif() - - if(BUILD_SHARED_LIBS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - endif() - - if(MINGW) - # MinGW >= 3.14 uses the C99-style stdio functions - # automatically, but forks like mingw-w64 still want - # us to define this in order to use them - add_definitions(-D__USE_MINGW_ANSI_STDIO=1) - endif() - - enable_warnings(documentation) - disable_warnings(documentation-deprecated-sync) - disable_warnings(missing-field-initializers) - enable_warnings(missing-declarations) - enable_warnings(strict-aliasing) - enable_warnings(strict-prototypes) - enable_warnings(declaration-after-statement) - enable_warnings(shift-count-overflow) - enable_warnings(unused-const-variable) - enable_warnings(unused-function) - enable_warnings(int-conversion) - enable_warnings(c11-extensions) - enable_warnings(c99-c11-compat) - - # MinGW uses gcc, which expects POSIX formatting for printf, but - # uses the Windows C library, which uses its own format specifiers. - # Disable format specifier warnings. - if(MINGW) - disable_warnings(format) - disable_warnings(format-security) - else() - enable_warnings(format) - enable_warnings(format-security) - endif() -endif() - -# Ensure that MinGW provides the correct header files. -if(WIN32 AND NOT CYGWIN) - add_definitions(-DWIN32 -D_WIN32_WINNT=0x0600) -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/EnableWarnings.cmake b/vendor/libgit2-sys/libgit2/cmake/EnableWarnings.cmake deleted file mode 100644 index 0700b52..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/EnableWarnings.cmake +++ /dev/null @@ -1,15 +0,0 @@ -macro(ENABLE_WARNINGS flag) - add_c_flag_if_supported(-W${flag}) -endmacro() - -macro(DISABLE_WARNINGS flag) - add_c_flag_if_supported(-Wno-${flag}) -endmacro() - -if(ENABLE_WERROR) - if(MSVC) - add_compile_options(-WX) - else() - add_c_flag_if_supported(-Werror) - endif() -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/ExperimentalFeatures.cmake b/vendor/libgit2-sys/libgit2/cmake/ExperimentalFeatures.cmake deleted file mode 100644 index 7eff40b..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/ExperimentalFeatures.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# Experimental feature support for libgit2 - developers can opt in to -# experimental functionality, like sha256 support. When experimental -# functionality is enabled, we set both a cmake flag *and* a compile -# definition. The cmake flag is used to generate `experimental.h`, -# which will be installed by a `make install`. But the compile definition -# is used by the libgit2 sources to detect the functionality at library -# build time. This allows us to have an in-tree `experimental.h` with -# *no* experiments enabled. This lets us support users who build without -# cmake and cannot generate the `experimental.h` file. - -if(EXPERIMENTAL_SHA256) - add_feature_info("SHA256 API" ON "experimental SHA256 APIs") - - set(EXPERIMENTAL 1) - set(GIT_EXPERIMENTAL_SHA256 1) - add_definitions(-DGIT_EXPERIMENTAL_SHA256=1) -else() - add_feature_info("SHA256 API" OFF "experimental SHA256 APIs") -endif() - -if(EXPERIMENTAL) - set(LIBGIT2_FILENAME "${LIBGIT2_FILENAME}-experimental") -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/FindCoreFoundation.cmake b/vendor/libgit2-sys/libgit2/cmake/FindCoreFoundation.cmake deleted file mode 100644 index b419ec9..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindCoreFoundation.cmake +++ /dev/null @@ -1,26 +0,0 @@ -# Find CoreFoundation.framework -# This will define : -# -# COREFOUNDATION_FOUND -# COREFOUNDATION_LIBRARIES -# COREFOUNDATION_LDFLAGS -# - -find_path(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h) -find_library(COREFOUNDATION_LIBRARIES NAMES CoreFoundation) -if(COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES) - if(NOT CoreFoundation_FIND_QUIETLY) - message(STATUS "Found CoreFoundation ${COREFOUNDATION_LIBRARIES}") - endif() - set(COREFOUNDATION_FOUND TRUE) - set(COREFOUNDATION_LDFLAGS "-framework CoreFoundation") -endif() - -if(CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND) - message(FATAL_ERROR "CoreFoundation not found") -endif() - -mark_as_advanced( - COREFOUNDATION_INCLUDE_DIR - COREFOUNDATION_LIBRARIES -) diff --git a/vendor/libgit2-sys/libgit2/cmake/FindGSSAPI.cmake b/vendor/libgit2-sys/libgit2/cmake/FindGSSAPI.cmake deleted file mode 100644 index a11d72a..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindGSSAPI.cmake +++ /dev/null @@ -1,208 +0,0 @@ -# - Try to find GSSAPI -# Once done this will define -# -# KRB5_CONFIG - Path to krb5-config -# GSSAPI_ROOT_DIR - Set this variable to the root installation of GSSAPI -# -# Read-Only variables: -# GSSAPI_FLAVOR_MIT - set to TRUE if MIT Kerberos has been found -# GSSAPI_FLAVOR_HEIMDAL - set to TRUE if Heimdal Kerberos has been found -# GSSAPI_FOUND - system has GSSAPI -# GSSAPI_INCLUDE_DIR - the GSSAPI include directory -# GSSAPI_LIBRARIES - Link these to use GSSAPI -# GSSAPI_DEFINITIONS - Compiler switches required for using GSSAPI -# -#============================================================================= -# Copyright (c) 2013 Andreas Schneider -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# - -find_path(GSSAPI_ROOT_DIR - NAMES include/gssapi.h include/gssapi/gssapi.h - HINTS ${_GSSAPI_ROOT_HINTS} - PATHS ${_GSSAPI_ROOT_PATHS}) -mark_as_advanced(GSSAPI_ROOT_DIR) - -if(UNIX) - find_program(KRB5_CONFIG - NAMES krb5-config - PATHS ${GSSAPI_ROOT_DIR}/bin /opt/local/bin) - mark_as_advanced(KRB5_CONFIG) - - if(KRB5_CONFIG) - # Check if we have MIT KRB5 - execute_process( - COMMAND ${KRB5_CONFIG} --vendor - RESULT_VARIABLE _GSSAPI_VENDOR_RESULT - OUTPUT_VARIABLE _GSSAPI_VENDOR_STRING) - - if(_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*") - set(GSSAPI_FLAVOR_MIT TRUE) - else() - execute_process( - COMMAND ${KRB5_CONFIG} --libs gssapi - RESULT_VARIABLE _GSSAPI_LIBS_RESULT - OUTPUT_VARIABLE _GSSAPI_LIBS_STRING) - - if(_GSSAPI_LIBS_STRING MATCHES ".*roken.*") - set(GSSAPI_FLAVOR_HEIMDAL TRUE) - endif() - endif() - - # Get the include dir - execute_process( - COMMAND ${KRB5_CONFIG} --cflags gssapi - RESULT_VARIABLE _GSSAPI_INCLUDE_RESULT - OUTPUT_VARIABLE _GSSAPI_INCLUDE_STRING) - string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}") - string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}") - endif() - - if(NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL) - # Check for HEIMDAL - find_package(PkgConfig) - if(PKG_CONFIG_FOUND) - pkg_check_modules(_GSSAPI heimdal-gssapi) - endif() - - if(_GSSAPI_FOUND) - set(GSSAPI_FLAVOR_HEIMDAL TRUE) - else() - find_path(_GSSAPI_ROKEN - NAMES roken.h - PATHS ${GSSAPI_ROOT_DIR}/include ${_GSSAPI_INCLUDEDIR}) - if(_GSSAPI_ROKEN) - set(GSSAPI_FLAVOR_HEIMDAL TRUE) - endif() - endif() - endif() -endif() - -find_path(GSSAPI_INCLUDE_DIR - NAMES gssapi.h gssapi/gssapi.h - PATHS ${GSSAPI_ROOT_DIR}/include ${_GSSAPI_INCLUDEDIR}) - -if(GSSAPI_FLAVOR_MIT) - find_library(GSSAPI_LIBRARY - NAMES gssapi_krb5 - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(KRB5_LIBRARY - NAMES krb5 - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(K5CRYPTO_LIBRARY - NAMES k5crypto - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(COM_ERR_LIBRARY - NAMES com_err - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - if(GSSAPI_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${GSSAPI_LIBRARY}) - endif() - - if(KRB5_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${KRB5_LIBRARY}) - endif() - - if(K5CRYPTO_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${K5CRYPTO_LIBRARY}) - endif() - - if(COM_ERR_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${COM_ERR_LIBRARY}) - endif() -endif() - -if(GSSAPI_FLAVOR_HEIMDAL) - find_library(GSSAPI_LIBRARY - NAMES gssapi - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(KRB5_LIBRARY - NAMES krb5 - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(HCRYPTO_LIBRARY - NAMES hcrypto - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(COM_ERR_LIBRARY - NAMES com_err - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(HEIMNTLM_LIBRARY - NAMES heimntlm - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(HX509_LIBRARY - NAMES hx509 - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(ASN1_LIBRARY - NAMES asn1 - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(WIND_LIBRARY - NAMES wind - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - find_library(ROKEN_LIBRARY - NAMES roken - PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) - - if(GSSAPI_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${GSSAPI_LIBRARY}) - endif() - - if(KRB5_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${KRB5_LIBRARY}) - endif() - - if(HCRYPTO_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HCRYPTO_LIBRARY}) - endif() - - if(COM_ERR_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${COM_ERR_LIBRARY}) - endif() - - if(HEIMNTLM_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HEIMNTLM_LIBRARY}) - endif() - - if(HX509_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HX509_LIBRARY}) - endif() - - if(ASN1_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${ASN1_LIBRARY}) - endif() - - if(WIND_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${WIND_LIBRARY}) - endif() - - if(ROKEN_LIBRARY) - set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${WIND_LIBRARY}) - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GSSAPI DEFAULT_MSG GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIR) - -if(GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES) - set(GSSAPI_FOUND TRUE) -endif(GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES) - -# show the GSSAPI_INCLUDE_DIRS and GSSAPI_LIBRARIES variables only in the advanced view -mark_as_advanced(GSSAPI_INCLUDE_DIRS GSSAPI_LIBRARIES) diff --git a/vendor/libgit2-sys/libgit2/cmake/FindGSSFramework.cmake b/vendor/libgit2-sys/libgit2/cmake/FindGSSFramework.cmake deleted file mode 100644 index 1b0c936..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindGSSFramework.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# Find GSS.framework -# This will define : -# -# GSSFRAMEWORK_FOUND -# GSSFRAMEWORK_INCLUDE_DIR -# GSSFRAMEWORK_LIBRARIES -# GSSFRAMEWORK_LDFLAGS -# - -find_path(GSSFRAMEWORK_INCLUDE_DIR NAMES GSS.h) -find_library(GSSFRAMEWORK_LIBRARIES NAMES GSS) -if(GSSFRAMEWORK_INCLUDE_DIR AND GSSFRAMEWORK_LIBRARIES) - if(NOT CoreFoundation_FIND_QUIETLY) - message(STATUS "Found GSS.framework ${GSSFRAMEWORK_LIBRARIES}") - endif() - set(GSSFRAMEWORK_FOUND TRUE) - set(GSSFRAMEWORK_LDFLAGS "-framework GSS") -endif() - -if(GSS_FIND_REQUIRED AND NOT GSSFRAMEWORK_FOUND) - message(FATAL_ERROR "CoreFoundation not found") -endif() - -mark_as_advanced( - GSSFRAMEWORK_INCLUDE_DIR - GSSFRAMEWORK_LIBRARIES - GSSFRAMEWORK_LDFLAGS -) diff --git a/vendor/libgit2-sys/libgit2/cmake/FindHTTP_Parser.cmake b/vendor/libgit2-sys/libgit2/cmake/FindHTTP_Parser.cmake deleted file mode 100644 index 3350190..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindHTTP_Parser.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# - Try to find http-parser -# -# Defines the following variables: -# -# HTTP_PARSER_FOUND - system has http-parser -# HTTP_PARSER_INCLUDE_DIR - the http-parser include directory -# HTTP_PARSER_LIBRARIES - Link these to use http-parser -# HTTP_PARSER_VERSION_MAJOR - major version -# HTTP_PARSER_VERSION_MINOR - minor version -# HTTP_PARSER_VERSION_STRING - the version of http-parser found - -# Find the header and library -find_path(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h) -find_library(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser) - -# Found the header, read version -if(HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h") - file(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H) - if(HTTP_PARSER_H) - string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}") - string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}") - set(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}") - endif() - unset(HTTP_PARSER_H) -endif() - -# Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND -# to TRUE if all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) - -# Hide advanced variables -mark_as_advanced(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) - -# Set standard variables -if(HTTP_PARSER_FOUND) - set(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY}) - set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR}) -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/FindIntlIconv.cmake b/vendor/libgit2-sys/libgit2/cmake/FindIntlIconv.cmake deleted file mode 100644 index 07959ca..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindIntlIconv.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# - Try to find Iconv -# Once done this will define -# -# ICONV_FOUND - system has Iconv -# ICONV_INCLUDE_DIR - the Iconv include directory -# ICONV_LIBRARIES - Link these to use Iconv -# - -if(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) - # Already in cache, be silent - set(ICONV_FIND_QUIETLY TRUE) -endif() - -find_path(ICONV_INCLUDE_DIR iconv.h) -check_function_exists(iconv_open libc_has_iconv) -find_library(iconv_lib NAMES iconv libiconv libiconv-2 c) - -# workaround the iOS issue where iconv is provided by libc -# We set it to false to force it add -liconv to the linker flags -if(CMAKE_SYSTEM_NAME MATCHES "iOS") - set(libc_has_iconv FALSE) -endif() - -if(ICONV_INCLUDE_DIR AND libc_has_iconv) - set(ICONV_FOUND TRUE) - set(ICONV_LIBRARIES "") - if(NOT ICONV_FIND_QUIETLY) - message(STATUS "Found Iconv: provided by libc") - endif(NOT ICONV_FIND_QUIETLY) -elseif(ICONV_INCLUDE_DIR AND iconv_lib) - set(ICONV_FOUND TRUE) - # split iconv into -L and -l linker options, so we can - # set them for pkg-config - get_filename_component(iconv_path ${iconv_lib} PATH) - get_filename_component(iconv_name ${iconv_lib} NAME_WE) - string(REGEX REPLACE "^lib" "" iconv_name ${iconv_name}) - set(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}") - - if(NOT ICONV_FIND_QUIETLY) - message(STATUS "Found Iconv: ${ICONV_LIBRARIES}") - endif() -else() - if(Iconv_FIND_REQUIRED) - message(FATAL_ERROR "Could not find Iconv") - endif(Iconv_FIND_REQUIRED) -endif() - -mark_as_advanced( - ICONV_INCLUDE_DIR - ICONV_LIBRARIES -) diff --git a/vendor/libgit2-sys/libgit2/cmake/FindLLHTTP.cmake b/vendor/libgit2-sys/libgit2/cmake/FindLLHTTP.cmake deleted file mode 100644 index a87d335..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindLLHTTP.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# - Try to find llhttp -# -# Defines the following variables: -# -# LLHTTP_FOUND - system has llhttp -# LLHTTP_INCLUDE_DIR - the llhttp include directory -# LLHTTP_LIBRARIES - Link these to use llhttp -# LLHTTP_VERSION_MAJOR - major version -# LLHTTP_VERSION_MINOR - minor version -# LLHTTP_VERSION_STRING - the version of llhttp found - -# Find the header and library -find_path(LLHTTP_INCLUDE_DIR NAMES llhttp.h) -find_library(LLHTTP_LIBRARY NAMES llhttp libllhttp) - -# Found the header, read version -if(LLHTTP_INCLUDE_DIR AND EXISTS "${LLHTTP_INCLUDE_DIR}/llhttp.h") - file(READ "${LLHTTP_INCLUDE_DIR}/llhttp.h" LLHTTP_H) - if(LLHTTP_H) - string(REGEX REPLACE ".*#define[\t ]+LLHTTP_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" LLHTTP_VERSION_MAJOR "${LLHTTP_H}") - string(REGEX REPLACE ".*#define[\t ]+LLHTTP_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" LLHTTP_VERSION_MINOR "${LLHTTP_H}") - set(LLHTTP_VERSION_STRING "${LLHTTP_VERSION_MAJOR}.${LLHTTP_VERSION_MINOR}") - endif() - unset(LLHTTP_H) -endif() - -# Handle the QUIETLY and REQUIRED arguments and set LLHTTP_FOUND -# to TRUE if all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LLHTTP REQUIRED_VARS LLHTTP_INCLUDE_DIR LLHTTP_LIBRARY) - -# Hide advanced variables -mark_as_advanced(LLHTTP_INCLUDE_DIR LLHTTP_LIBRARY) - -# Set standard variables -if(LLHTTP_FOUND) - set(LLHTTP_LIBRARIES ${LLHTTP_LIBRARY}) - set(LLHTTP_INCLUDE_DIRS ${LLHTTP_INCLUDE_DIR}) -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/FindLibSSH2.cmake b/vendor/libgit2-sys/libgit2/cmake/FindLibSSH2.cmake deleted file mode 100644 index c571997..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindLibSSH2.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# LIBSSH2_FOUND - system has the libssh2 library -# LIBSSH2_INCLUDE_DIR - the libssh2 include directory -# LIBSSH2_LIBRARY - the libssh2 library name - -find_path(LIBSSH2_INCLUDE_DIR libssh2.h) - -find_library(LIBSSH2_LIBRARY NAMES ssh2 libssh2) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LibSSH2 - REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR) - -mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY) diff --git a/vendor/libgit2-sys/libgit2/cmake/FindPCRE.cmake b/vendor/libgit2-sys/libgit2/cmake/FindPCRE.cmake deleted file mode 100644 index 02e7edc..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindPCRE.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2007-2009 LuaDist. -# Created by Peter Kapec -# Redistribution and use of this file is allowed according to the terms of the MIT license. -# For details see the COPYRIGHT file distributed with LuaDist. -# Note: -# Searching headers and libraries is very simple and is NOT as powerful as scripts -# distributed with CMake, because LuaDist defines directories to search for. -# Everyone is encouraged to contact the author with improvements. Maybe this file -# becomes part of CMake distribution sometimes. - -# - Find pcre -# Find the native PCRE headers and libraries. -# -# PCRE_INCLUDE_DIRS - where to find pcre.h, etc. -# PCRE_LIBRARIES - List of libraries when using pcre. -# PCRE_FOUND - True if pcre found. - -# Look for the header file. -find_path(PCRE_INCLUDE_DIR NAMES pcre.h) - -# Look for the library. -find_library(PCRE_LIBRARY NAMES pcre) - -# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR) - -# Copy the results to the output variables. -if(PCRE_FOUND) - set(PCRE_LIBRARIES ${PCRE_LIBRARY}) - set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR}) -else(PCRE_FOUND) - set(PCRE_LIBRARIES) - set(PCRE_INCLUDE_DIRS) -endif() - -mark_as_advanced(PCRE_INCLUDE_DIRS PCRE_LIBRARIES) diff --git a/vendor/libgit2-sys/libgit2/cmake/FindPCRE2.cmake b/vendor/libgit2-sys/libgit2/cmake/FindPCRE2.cmake deleted file mode 100644 index 41c165b..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindPCRE2.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2007-2009 LuaDist. -# Created by Peter Kapec -# Redistribution and use of this file is allowed according to the terms of the MIT license. -# For details see the COPYRIGHT file distributed with LuaDist. -# Note: -# Searching headers and libraries is very simple and is NOT as powerful as scripts -# distributed with CMake, because LuaDist defines directories to search for. -# Everyone is encouraged to contact the author with improvements. Maybe this file -# becomes part of CMake distribution sometimes. - -# - Find pcre -# Find the native PCRE2 headers and libraries. -# -# PCRE2_INCLUDE_DIRS - where to find pcre.h, etc. -# PCRE2_LIBRARIES - List of libraries when using pcre. -# PCRE2_FOUND - True if pcre found. - -# Look for the header file. -find_path(PCRE2_INCLUDE_DIR NAMES pcre2.h) - -# Look for the library. -find_library(PCRE2_LIBRARY NAMES pcre2-8) - -# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR) - -# Copy the results to the output variables. -if(PCRE2_FOUND) - set(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) - set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) -else(PCRE2_FOUND) - set(PCRE2_LIBRARIES) - set(PCRE2_INCLUDE_DIRS) -endif() - -mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES) diff --git a/vendor/libgit2-sys/libgit2/cmake/FindPkgLibraries.cmake b/vendor/libgit2-sys/libgit2/cmake/FindPkgLibraries.cmake deleted file mode 100644 index 220bb2c..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindPkgLibraries.cmake +++ /dev/null @@ -1,28 +0,0 @@ -include(FindPkgConfig) - -# This function will find and set up a pkg-config based module. -# If a pc-file was found, it will resolve library paths to -# absolute paths. Furthermore, the function will automatically -# fall back to use static libraries in case no dynamic libraries -# were found. -function(FIND_PKGLIBRARIES prefix package) - pkg_check_modules(${prefix} ${package}) - if(NOT ${prefix}_FOUND) - return() - endif() - - foreach(LIBRARY ${${prefix}_LIBRARIES}) - find_library(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS}) - if(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND") - message(FATAL_ERROR "could not resolve ${LIBRARY}") - endif() - list(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED}) - endforeach() - - set(${prefix}_FOUND 1 PARENT_SCOPE) - set(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE) - set(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE) - set(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE) - - message(STATUS " Resolved libraries: ${RESOLVED_LIBRARIES}") -endfunction() diff --git a/vendor/libgit2-sys/libgit2/cmake/FindSecurity.cmake b/vendor/libgit2-sys/libgit2/cmake/FindSecurity.cmake deleted file mode 100644 index 14a2e2d..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindSecurity.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# Find Security.framework -# This will define : -# -# SECURITY_FOUND -# SECURITY_LIBRARIES -# SECURITY_LDFLAGS -# SECURITY_HAS_SSLCREATECONTEXT -# - -find_path(SECURITY_INCLUDE_DIR NAMES Security/Security.h) -find_library(SECURITY_LIBRARIES NAMES Security) -if(SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES) - if(NOT Security_FIND_QUIETLY) - message(STATUS "Found Security ${SECURITY_LIBRARIES}") - endif() - set(SECURITY_FOUND TRUE) - set(SECURITY_LDFLAGS "-framework Security") - check_library_exists("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT) -endif() - -if(Security_FIND_REQUIRED AND NOT SECURITY_FOUND) - message(FATAL_ERROR "Security not found") -endif() - -mark_as_advanced( - SECURITY_INCLUDE_DIR - SECURITY_LIBRARIES -) diff --git a/vendor/libgit2-sys/libgit2/cmake/FindStatNsec.cmake b/vendor/libgit2-sys/libgit2/cmake/FindStatNsec.cmake deleted file mode 100644 index 9dfdf51..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindStatNsec.cmake +++ /dev/null @@ -1,20 +0,0 @@ -include(FeatureSummary) - -check_struct_has_member("struct stat" st_mtim "sys/types.h;sys/stat.h" - HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C) -check_struct_has_member("struct stat" st_mtimespec "sys/types.h;sys/stat.h" - HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C) -check_struct_has_member("struct stat" st_mtime_nsec sys/stat.h - HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C) - -if(HAVE_STRUCT_STAT_ST_MTIM) - check_struct_has_member("struct stat" st_mtim.tv_nsec sys/stat.h - HAVE_STRUCT_STAT_NSEC LANGUAGE C) -elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC) - check_struct_has_member("struct stat" st_mtimespec.tv_nsec sys/stat.h - HAVE_STRUCT_STAT_NSEC LANGUAGE C) -else() - set(HAVE_STRUCT_STAT_NSEC ON ) -endif() - -add_feature_info(nanoseconds USE_NSEC "support nanosecond precision file mtimes and ctimes") diff --git a/vendor/libgit2-sys/libgit2/cmake/Findfutimens.cmake b/vendor/libgit2-sys/libgit2/cmake/Findfutimens.cmake deleted file mode 100644 index 3449c9d..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/Findfutimens.cmake +++ /dev/null @@ -1,14 +0,0 @@ -include(EnableWarnings) - -if(APPLE) - # We cannot simply CHECK_FUNCTION_EXISTS on macOS because - # MACOSX_DEPLOYMENT_TARGET may be set to a version in the past - # that doesn't have futimens. Instead we need to enable warnings - # as errors, then check for the symbol existing in `sys/stat.h`, - # then reset warnings as errors. - enable_warnings(error) - check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS) - disable_warnings(error) -else() - check_function_exists(futimens HAVE_FUTIMENS) -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/FindmbedTLS.cmake b/vendor/libgit2-sys/libgit2/cmake/FindmbedTLS.cmake deleted file mode 100644 index a4a5487..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/FindmbedTLS.cmake +++ /dev/null @@ -1,86 +0,0 @@ -# - Try to find mbedTLS -# Once done this will define -# -# Read-Only variables -# MBEDTLS_FOUND - system has mbedTLS -# MBEDTLS_INCLUDE_DIR - the mbedTLS include directory -# MBEDTLS_LIBRARY_DIR - the mbedTLS library directory -# MBEDTLS_LIBRARIES - Link these to use mbedTLS -# MBEDTLS_LIBRARY - path to mbedTLS library -# MBEDX509_LIBRARY - path to mbedTLS X.509 library -# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library -# -# Hint -# MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation. - -set(_MBEDTLS_ROOT_HINTS - ${MBEDTLS_ROOT_DIR} - ENV MBEDTLS_ROOT_DIR) - -set(_MBEDTLS_ROOT_HINTS_AND_PATHS - HINTS ${_MBEDTLS_ROOT_HINTS} - PATHS ${_MBEDTLS_ROOT_PATHS}) - -find_path(MBEDTLS_INCLUDE_DIR - NAMES mbedtls/version.h - ${_MBEDTLS_ROOT_HINTS_AND_PATHS} - PATH_SUFFIXES include) - -if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) - # Already in cache, be silent - set(MBEDTLS_FIND_QUIETLY TRUE) -endif() - -find_library(MBEDTLS_LIBRARY - NAMES mbedtls libmbedtls - ${_MBEDTLS_ROOT_HINTS_AND_PATHS} - PATH_SUFFIXES library) -find_library(MBEDX509_LIBRARY - NAMES mbedx509 libmbedx509 - ${_MBEDTLS_ROOT_HINTS_AND_PATHS} - PATH_SUFFIXES library) -find_library(MBEDCRYPTO_LIBRARY - NAMES mbedcrypto libmbedcrypto - ${_MBEDTLS_ROOT_HINTS_AND_PATHS} - PATH_SUFFIXES library) - -if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) - set(MBEDTLS_FOUND TRUE) -endif() - -if(MBEDTLS_FOUND) - # split mbedTLS into -L and -l linker options, so we can set them for pkg-config - get_filename_component(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH) - get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) - get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) - get_filename_component(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE) - string(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) - string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) - string(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) - set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") - - if(NOT MBEDTLS_FIND_QUIETLY) - message(STATUS "Found mbedTLS:") - file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) - string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) - if(MBEDTLSMATCH) - string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) - message(STATUS " version ${MBEDTLS_VERSION}") - endif() - message(STATUS " TLS: ${MBEDTLS_LIBRARY}") - message(STATUS " X509: ${MBEDX509_LIBRARY}") - message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") - endif() -else(MBEDTLS_FOUND) - if(MBEDTLS_FIND_REQUIRED) - message(FATAL_ERROR "Could not find mbedTLS") - endif() -endif() - -mark_as_advanced( - MBEDTLS_INCLUDE_DIR - MBEDTLS_LIBRARY_DIR - MBEDTLS_LIBRARIES - MBEDTLS_LIBRARY - MBEDX509_LIBRARY - MBEDCRYPTO_LIBRARY) diff --git a/vendor/libgit2-sys/libgit2/cmake/IdeSplitSources.cmake b/vendor/libgit2-sys/libgit2/cmake/IdeSplitSources.cmake deleted file mode 100644 index 4f928ac..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/IdeSplitSources.cmake +++ /dev/null @@ -1,22 +0,0 @@ -# This function splits the sources files up into their appropriate -# subdirectories. This is especially useful for IDEs like Xcode and -# Visual Studio, so that you can navigate into the libgit2_tests project, -# and see the folders within the tests folder (instead of just seeing all -# source and tests in a single folder.) -function(IDE_SPLIT_SOURCES target) - if(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode) - get_target_property(sources ${target} SOURCES) - foreach(source ${sources}) - if(source MATCHES ".*/") - string(REPLACE ${PROJECT_SOURCE_DIR}/ "" rel ${source}) - if(rel) - string(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) - if(rel) - string(REPLACE "/" "\\\\" rel ${rel}) - source_group(${rel} FILES ${source}) - endif() - endif() - endif() - endforeach() - endif() -endfunction() diff --git a/vendor/libgit2-sys/libgit2/cmake/PkgBuildConfig.cmake b/vendor/libgit2-sys/libgit2/cmake/PkgBuildConfig.cmake deleted file mode 100644 index c8939e6..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/PkgBuildConfig.cmake +++ /dev/null @@ -1,77 +0,0 @@ -# pkg-config file generation -# - -function(pkg_build_config) - set(options) - set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF) - set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS) - - cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME) - set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME}) - endif() - if (NOT DEFINED PKGCONFIG_FILENAME) - message(FATAL_ERROR "Missing FILENAME argument") - endif() - set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc") - - if (NOT DEFINED PKGCONFIG_DESCRIPTION) - message(FATAL_ERROR "Missing DESCRIPTION argument") - endif() - - if (NOT DEFINED PKGCONFIG_VERSION) - message(FATAL_ERROR "Missing VERSION argument") - endif() - - # Write .pc "header" - file(WRITE "${PKGCONFIG_FILE}" - "prefix=\"${CMAKE_INSTALL_PREFIX}\"\n" - "libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n" - "includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n" - "\n" - "Name: ${PKGCONFIG_NAME}\n" - "Description: ${PKGCONFIG_DESCRIPTION}\n" - "Version: ${PKGCONFIG_VERSION}\n" - ) - - # Prepare Libs - if(NOT DEFINED PKGCONFIG_LIBS_SELF) - set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}") - endif() - - if(NOT DEFINED PKGCONFIG_LIBS) - set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}") - else() - list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}") - endif() - - list(REMOVE_DUPLICATES PKGCONFIG_LIBS) - string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}") - file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n") - - # Prepare Libs.private - if(DEFINED PKGCONFIG_PRIVATE_LIBS) - list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS) - string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}") - file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n") - endif() - - # Prepare Requires.private - if(DEFINED PKGCONFIG_REQUIRES) - list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES) - string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}") - file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n") - endif() - - # Prepare Cflags - if(DEFINED PKGCONFIG_CFLAGS) - string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}") - else() - set(PKGCONFIG_CFLAGS "") - endif() - file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n") - - # Install .pc file - install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -endfunction() diff --git a/vendor/libgit2-sys/libgit2/cmake/SanitizeBool.cmake b/vendor/libgit2-sys/libgit2/cmake/SanitizeBool.cmake deleted file mode 100644 index 586c17d..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SanitizeBool.cmake +++ /dev/null @@ -1,20 +0,0 @@ -function(SanitizeBool VAR) - string(TOLOWER "${${VAR}}" VALUE) - if(VALUE STREQUAL "on") - set(${VAR} "ON" PARENT_SCOPE) - elseif(VALUE STREQUAL "yes") - set(${VAR} "ON" PARENT_SCOPE) - elseif(VALUE STREQUAL "true") - set(${VAR} "ON" PARENT_SCOPE) - elseif(VALUE STREQUAL "1") - set(${VAR} "ON" PARENT_SCOPE) - elseif(VALUE STREQUAL "off") - set(${VAR} "OFF" PARENT_SCOPE) - elseif(VALUE STREQUAL "no") - set(${VAR} "OFF" PARENT_SCOPE) - elseif(VALUE STREQUAL "false") - set(${VAR} "OFF" PARENT_SCOPE) - elseif(VALUE STREQUAL "0") - set(${VAR} "OFF" PARENT_SCOPE) - endif() -endfunction() diff --git a/vendor/libgit2-sys/libgit2/cmake/SelectGSSAPI.cmake b/vendor/libgit2-sys/libgit2/cmake/SelectGSSAPI.cmake deleted file mode 100644 index 829850a..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SelectGSSAPI.cmake +++ /dev/null @@ -1,48 +0,0 @@ -include(SanitizeBool) - -# We try to find any packages our backends might use -find_package(GSSAPI) -if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "iOS") - include(FindGSSFramework) -endif() - -if(USE_GSSAPI) - # Auto-select GSS backend - sanitizebool(USE_GSSAPI) - if(USE_GSSAPI STREQUAL ON) - if(GSSFRAMEWORK_FOUND) - set(USE_GSSAPI "GSS.framework") - elseif(GSSAPI_FOUND) - set(USE_GSSAPI "gssapi") - else() - message(FATAL_ERROR "Unable to autodetect a usable GSS backend." - "Please pass the backend name explicitly (-DUSE_GSS=backend)") - endif() - endif() - - # Check that we can find what's required for the selected backend - if(USE_GSSAPI STREQUAL "GSS.framework") - if(NOT GSSFRAMEWORK_FOUND) - message(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found") - endif() - - list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSFRAMEWORK_LIBRARIES}) - - set(GIT_GSSFRAMEWORK 1) - add_feature_info(GSSAPI GIT_GSSFRAMEWORK "GSSAPI support for SPNEGO authentication (${USE_GSSAPI})") - elseif(USE_GSSAPI STREQUAL "gssapi") - if(NOT GSSAPI_FOUND) - message(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found") - endif() - - list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSAPI_LIBRARIES}) - - set(GIT_GSSAPI 1) - add_feature_info(GSSAPI GIT_GSSAPI "GSSAPI support for SPNEGO authentication (${USE_GSSAPI})") - else() - message(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found") - endif() -else() - set(GIT_GSSAPI 0) - add_feature_info(GSSAPI NO "GSSAPI support for SPNEGO authentication") -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/SelectHTTPParser.cmake b/vendor/libgit2-sys/libgit2/cmake/SelectHTTPParser.cmake deleted file mode 100644 index e547e2d..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SelectHTTPParser.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# Optional external dependency: http-parser -if(USE_HTTP_PARSER STREQUAL "http-parser" OR USE_HTTP_PARSER STREQUAL "system") - find_package(HTTP_Parser) - - if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${HTTP_PARSER_LIBRARIES}) - list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser") - set(GIT_HTTPPARSER_HTTPPARSER 1) - add_feature_info(http-parser ON "using http-parser (system)") - else() - message(FATAL_ERROR "http-parser support was requested but not found") - endif() -elseif(USE_HTTP_PARSER STREQUAL "llhttp") - find_package(LLHTTP) - - if(LLHTTP_FOUND AND LLHTTP_VERSION_MAJOR EQUAL 9) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LLHTTP_INCLUDE_DIRS}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${LLHTTP_LIBRARIES}) - list(APPEND LIBGIT2_PC_LIBS "-lllhttp") - set(GIT_HTTPPARSER_LLHTTP 1) - add_feature_info(http-parser ON "using llhttp (system)") - else() - message(FATAL_ERROR "llhttp support was requested but not found") - endif() -elseif(USE_HTTP_PARSER STREQUAL "" OR USE_HTTP_PARSER STREQUAL "builtin") - add_subdirectory("${PROJECT_SOURCE_DIR}/deps/llhttp" "${PROJECT_BINARY_DIR}/deps/llhttp") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/llhttp") - list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$") - set(GIT_HTTPPARSER_BUILTIN 1) - add_feature_info(http-parser ON "using bundled parser") -else() - message(FATAL_ERROR "unknown http-parser: ${USE_HTTP_PARSER}") -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/SelectHTTPSBackend.cmake b/vendor/libgit2-sys/libgit2/cmake/SelectHTTPSBackend.cmake deleted file mode 100644 index 0316b3a..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SelectHTTPSBackend.cmake +++ /dev/null @@ -1,152 +0,0 @@ -include(SanitizeBool) - -# We try to find any packages our backends might use -find_package(OpenSSL) -find_package(mbedTLS) -if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "iOS") - find_package(Security) - find_package(CoreFoundation) -endif() - -if(USE_HTTPS STREQUAL "") - set(USE_HTTPS ON) -endif() - -sanitizebool(USE_HTTPS) - -if(USE_HTTPS) - # Auto-select TLS backend - if(USE_HTTPS STREQUAL ON) - if(SECURITY_FOUND) - if(SECURITY_HAS_SSLCREATECONTEXT) - set(USE_HTTPS "SecureTransport") - else() - message(STATUS "Security framework is too old, falling back to OpenSSL") - set(USE_HTTPS "OpenSSL") - endif() - elseif(WIN32) - set(USE_HTTPS "WinHTTP") - elseif(OPENSSL_FOUND) - set(USE_HTTPS "OpenSSL") - elseif(MBEDTLS_FOUND) - set(USE_HTTPS "mbedTLS") - else() - message(FATAL_ERROR "Unable to autodetect a usable HTTPS backend." - "Please pass the backend name explicitly (-DUSE_HTTPS=backend)") - endif() - endif() - - # Check that we can find what's required for the selected backend - if(USE_HTTPS STREQUAL "SecureTransport") - if(NOT COREFOUNDATION_FOUND) - message(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found") - endif() - if(NOT SECURITY_FOUND) - message(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found") - endif() - if(NOT SECURITY_HAS_SSLCREATECONTEXT) - message(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported") - endif() - - set(GIT_SECURE_TRANSPORT 1) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) - list(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) - elseif(USE_HTTPS STREQUAL "OpenSSL") - if(NOT OPENSSL_FOUND) - message(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found") - endif() - - set(GIT_OPENSSL 1) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${OPENSSL_LIBRARIES}) - # Static OpenSSL (lib crypto.a) requires libdl, include it explicitly - if(LINK_WITH_STATIC_LIBRARIES STREQUAL ON) - list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_DL_LIBS}) - endif() - list(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS}) - list(APPEND LIBGIT2_PC_REQUIRES "openssl") - elseif(USE_HTTPS STREQUAL "mbedTLS") - if(NOT MBEDTLS_FOUND) - message(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found") - endif() - - if(NOT CERT_LOCATION) - message(STATUS "Auto-detecting default certificates location") - if(EXISTS "/usr/local/opt/openssl/bin/openssl") - # Check for an Homebrew installation - set(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl") - else() - set(OPENSSL_CMD "openssl") - endif() - execute_process(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) - if(OPENSSL_DIR) - string(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR}) - - set(OPENSSL_CA_LOCATIONS - "ca-bundle.pem" # OpenSUSE Leap 42.1 - "cert.pem" # Ubuntu 14.04, FreeBSD - "certs/ca-certificates.crt" # Ubuntu 16.04 - "certs/ca.pem" # Debian 7 - ) - foreach(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS) - set(LOC "${OPENSSL_DIR}${SUFFIX}") - if(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}") - set(CERT_LOCATION ${LOC}) - endif() - endforeach() - else() - message(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION") - endif() - endif() - - if(CERT_LOCATION) - if(NOT EXISTS ${CERT_LOCATION}) - message(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist") - endif() - add_feature_info(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}") - add_definitions(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}") - endif() - - set(GIT_MBEDTLS 1) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES}) - # mbedTLS has no pkgconfig file, hence we can't require it - # https://github.com/ARMmbed/mbedtls/issues/228 - # For now, pass its link flags as our own - list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) - elseif(USE_HTTPS STREQUAL "Schannel") - set(GIT_SCHANNEL 1) - - list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32") - list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32") - elseif(USE_HTTPS STREQUAL "WinHTTP") - set(GIT_WINHTTP 1) - - # Since MinGW does not come with headers or an import library for winhttp, - # we have to include a private header and generate our own import library - if(MINGW) - add_subdirectory("${PROJECT_SOURCE_DIR}/deps/winhttp" "${PROJECT_BINARY_DIR}/deps/winhttp") - list(APPEND LIBGIT2_SYSTEM_LIBS winhttp) - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/winhttp") - else() - list(APPEND LIBGIT2_SYSTEM_LIBS "winhttp") - list(APPEND LIBGIT2_PC_LIBS "-lwinhttp") - endif() - - list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32") - list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32") - elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic") - set(GIT_OPENSSL 1) - set(GIT_OPENSSL_DYNAMIC 1) - list(APPEND LIBGIT2_SYSTEM_LIBS dl) - else() - message(FATAL_ERROR "unknown HTTPS backend: ${USE_HTTPS}") - endif() - - set(GIT_HTTPS 1) - add_feature_info(HTTPS GIT_HTTPS "using ${USE_HTTPS}") -else() - set(GIT_HTTPS 0) - add_feature_info(HTTPS NO "HTTPS support is disabled") -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/SelectHashes.cmake b/vendor/libgit2-sys/libgit2/cmake/SelectHashes.cmake deleted file mode 100644 index 35fea3e..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SelectHashes.cmake +++ /dev/null @@ -1,121 +0,0 @@ -# Select a hash backend - -include(SanitizeBool) - -sanitizebool(USE_SHA1) -sanitizebool(USE_SHA256) - -# sha1 - -if(USE_SHA1 STREQUAL "" OR USE_SHA1 STREQUAL ON) - SET(USE_SHA1 "CollisionDetection") -elseif(USE_SHA1 STREQUAL "HTTPS") - if(USE_HTTPS STREQUAL "SecureTransport") - set(USE_SHA1 "CommonCrypto") - elseif(USE_HTTPS STREQUAL "Schannel") - set(USE_SHA1 "Win32") - elseif(USE_HTTPS STREQUAL "WinHTTP") - set(USE_SHA1 "Win32") - elseif(USE_HTTPS) - set(USE_SHA1 ${USE_HTTPS}) - else() - message(FATAL_ERROR "asked for HTTPS SHA1 backend but HTTPS is not enabled") - endif() -endif() - -if(USE_SHA1 STREQUAL "CollisionDetection") - set(GIT_SHA1_COLLISIONDETECT 1) -elseif(USE_SHA1 STREQUAL "OpenSSL") - set(GIT_SHA1_OPENSSL 1) -elseif(USE_SHA1 STREQUAL "OpenSSL-FIPS") - set(GIT_SHA1_OPENSSL_FIPS 1) -elseif(USE_SHA1 STREQUAL "OpenSSL-Dynamic") - set(GIT_SHA1_OPENSSL 1) - set(GIT_SHA1_OPENSSL_DYNAMIC 1) - list(APPEND LIBGIT2_SYSTEM_LIBS dl) -elseif(USE_SHA1 STREQUAL "CommonCrypto") - set(GIT_SHA1_COMMON_CRYPTO 1) -elseif(USE_SHA1 STREQUAL "mbedTLS") - set(GIT_SHA1_MBEDTLS 1) -elseif(USE_SHA1 STREQUAL "Win32") - set(GIT_SHA1_WIN32 1) -else() - message(FATAL_ERROR "asked for unknown SHA1 backend: ${USE_SHA1}") -endif() - -# sha256 - -if(USE_SHA256 STREQUAL "" OR USE_SHA256 STREQUAL ON) - if(USE_HTTPS) - SET(USE_SHA256 "HTTPS") - else() - SET(USE_SHA256 "builtin") - endif() -endif() - -if(USE_SHA256 STREQUAL "Builtin") - set(USE_SHA256 "builtin") -endif() - -if(USE_SHA256 STREQUAL "HTTPS") - if(USE_HTTPS STREQUAL "SecureTransport") - set(USE_SHA256 "CommonCrypto") - elseif(USE_HTTPS STREQUAL "Schannel") - set(USE_SHA256 "Win32") - elseif(USE_HTTPS STREQUAL "WinHTTP") - set(USE_SHA256 "Win32") - elseif(USE_HTTPS) - set(USE_SHA256 ${USE_HTTPS}) - endif() -endif() - -if(USE_SHA256 STREQUAL "builtin") - set(GIT_SHA256_BUILTIN 1) -elseif(USE_SHA256 STREQUAL "OpenSSL") - set(GIT_SHA256_OPENSSL 1) -elseif(USE_SHA256 STREQUAL "OpenSSL-FIPS") - set(GIT_SHA256_OPENSSL_FIPS 1) -elseif(USE_SHA256 STREQUAL "OpenSSL-Dynamic") - set(GIT_SHA256_OPENSSL 1) - set(GIT_SHA256_OPENSSL_DYNAMIC 1) - list(APPEND LIBGIT2_SYSTEM_LIBS dl) -elseif(USE_SHA256 STREQUAL "CommonCrypto") - set(GIT_SHA256_COMMON_CRYPTO 1) -elseif(USE_SHA256 STREQUAL "mbedTLS") - set(GIT_SHA256_MBEDTLS 1) -elseif(USE_SHA256 STREQUAL "Win32") - set(GIT_SHA256_WIN32 1) -else() - message(FATAL_ERROR "asked for unknown SHA256 backend: ${USE_SHA256}") -endif() - -# add library requirements -if(USE_SHA1 STREQUAL "OpenSSL" OR USE_SHA256 STREQUAL "OpenSSL" OR - USE_SHA1 STREQUAL "OpenSSL-FIPS" OR USE_SHA256 STREQUAL "OpenSSL-FIPS") - if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - list(APPEND LIBGIT2_PC_LIBS "-lssl") - else() - list(APPEND LIBGIT2_PC_REQUIRES "openssl") - endif() -endif() - -if(USE_SHA1 STREQUAL "mbedTLS" OR USE_SHA256 STREQUAL "mbedTLS") - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES}) - # mbedTLS has no pkgconfig file, hence we can't require it - # https://github.com/ARMmbed/mbedtls/issues/228 - # For now, pass its link flags as our own - list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) -endif() - -# notify feature enablement - -add_feature_info(SHA1 ON "using ${USE_SHA1}") -add_feature_info(SHA256 ON "using ${USE_SHA256}") - -# warn for users who do not use sha1dc - -if(NOT "${USE_SHA1}" STREQUAL "CollisionDetection") - list(APPEND WARNINGS "SHA1 support is set to ${USE_SHA1} which is not recommended - git's hash algorithm is sha1dc, it is *not* SHA1. Using SHA1 may leave you and your users susceptible to SHAttered-style attacks.") - set(WARNINGS ${WARNINGS} PARENT_SCOPE) -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/SelectRegex.cmake b/vendor/libgit2-sys/libgit2/cmake/SelectRegex.cmake deleted file mode 100644 index 78799c3..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SelectRegex.cmake +++ /dev/null @@ -1,61 +0,0 @@ -# Specify regular expression implementation -find_package(PCRE) - -if(REGEX_BACKEND STREQUAL "") - check_symbol_exists(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L) - - if(HAVE_REGCOMP_L) - # 'regcomp_l' has been explicitly marked unavailable on iOS_SDK - if(CMAKE_SYSTEM_NAME MATCHES "iOS") - set(REGEX_BACKEND "regcomp") - else() - set(REGEX_BACKEND "regcomp_l") - endif() - elseif(PCRE_FOUND) - set(REGEX_BACKEND "pcre") - else() - set(REGEX_BACKEND "builtin") - endif() -endif() - -if(REGEX_BACKEND STREQUAL "regcomp_l") - add_feature_info(regex ON "using system regcomp_l") - set(GIT_REGEX_REGCOMP_L 1) -elseif(REGEX_BACKEND STREQUAL "pcre2") - find_package(PCRE2) - - if(NOT PCRE2_FOUND) - MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found") - endif() - - add_feature_info(regex ON "using system PCRE2") - set(GIT_REGEX_PCRE2 1) - - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE2_LIBRARIES}) - list(APPEND LIBGIT2_PC_REQUIRES "libpcre2-8") -elseif(REGEX_BACKEND STREQUAL "pcre") - add_feature_info(regex ON "using system PCRE") - set(GIT_REGEX_PCRE 1) - - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE_LIBRARIES}) - list(APPEND LIBGIT2_PC_REQUIRES "libpcre") -elseif(REGEX_BACKEND STREQUAL "regcomp") - add_feature_info(regex ON "using system regcomp") - set(GIT_REGEX_REGCOMP 1) -elseif(REGEX_BACKEND STREQUAL "builtin") - add_feature_info(regex ON "using bundled PCRE") - set(GIT_REGEX_BUILTIN 1) - - add_definitions(-DPCRE2_STATIC) - add_definitions(-DPCRE2_EXPORT=) - add_definitions(-DPCRE2_EXP_DECL=) - add_definitions(-DPCRE2_EXP_DEFN=) - - add_subdirectory("${PROJECT_SOURCE_DIR}/deps/pcre2" "${PROJECT_BINARY_DIR}/deps/pcre2") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/pcre2") - list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $) -else() - message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported") -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/SelectSSH.cmake b/vendor/libgit2-sys/libgit2/cmake/SelectSSH.cmake deleted file mode 100644 index a925579..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SelectSSH.cmake +++ /dev/null @@ -1,52 +0,0 @@ -if(USE_SSH STREQUAL "exec") - set(GIT_SSH 1) - set(GIT_SSH_EXEC 1) - - add_feature_info(SSH ON "using OpenSSH exec support") -elseif(USE_SSH STREQUAL ON OR USE_SSH STREQUAL "libssh2") - find_pkglibraries(LIBSSH2 libssh2) - - if(LIBSSH2_FOUND) - set(LIBSSH2_FOUND_PKGCONFIG 1) - else() - find_package(LibSSH2) - set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR}) - get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY) - set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY}) - set(LIBSSH2_LDFLAGS "-lssh2") - endif() - - if(NOT LIBSSH2_FOUND) - message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.") - endif() - - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${LIBSSH2_LIBRARIES}) - if(LIBSSH2_FOUND_PKGCONFIG) - list(APPEND LIBGIT2_PC_REQUIRES "libssh2") - else() - list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS}) - endif() - - check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS) - if(HAVE_LIBSSH2_MEMORY_CREDENTIALS) - set(GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1) - endif() - - if(WIN32 AND EMBED_SSH_PATH) - file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c") - list(SORT SSH_SRC) - list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC}) - - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include") - file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"") - endif() - - set(GIT_SSH 1) - set(GIT_SSH_LIBSSH2 1) - add_feature_info(SSH ON "using libssh2") -elseif(USE_SSH STREQUAL OFF OR USE_SSH STREQUAL "") - add_feature_info(SSH OFF "SSH transport support") -else() - message(FATAL_ERROR "unknown SSH option: ${USE_SSH}") -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/SelectXdiff.cmake b/vendor/libgit2-sys/libgit2/cmake/SelectXdiff.cmake deleted file mode 100644 index 9ab9f3f..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SelectXdiff.cmake +++ /dev/null @@ -1,9 +0,0 @@ -# Optional external dependency: xdiff -if(USE_XDIFF STREQUAL "system") - message(FATAL_ERROR "external/system xdiff is not yet supported") -else() - add_subdirectory("${PROJECT_SOURCE_DIR}/deps/xdiff" "${PROJECT_BINARY_DIR}/deps/xdiff") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/xdiff") - list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$") - add_feature_info(xdiff ON "xdiff support (bundled)") -endif() diff --git a/vendor/libgit2-sys/libgit2/cmake/SelectZlib.cmake b/vendor/libgit2-sys/libgit2/cmake/SelectZlib.cmake deleted file mode 100644 index 25c7b2f..0000000 --- a/vendor/libgit2-sys/libgit2/cmake/SelectZlib.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# Optional external dependency: zlib -include(SanitizeBool) - -SanitizeBool(USE_BUNDLED_ZLIB) -if(USE_BUNDLED_ZLIB STREQUAL ON) - set(USE_BUNDLED_ZLIB "Bundled") - set(GIT_COMPRESSION_BUILTIN) -endif() - -if(USE_BUNDLED_ZLIB STREQUAL "OFF") - find_package(ZLIB) - if(ZLIB_FOUND) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${ZLIB_LIBRARIES}) - if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - list(APPEND LIBGIT2_PC_LIBS "-lz") - else() - list(APPEND LIBGIT2_PC_REQUIRES "zlib") - endif() - add_feature_info(zlib ON "using system zlib") - set(GIT_COMPRESSION_ZLIB 1) - else() - message(STATUS "zlib was not found; using bundled 3rd-party sources." ) - endif() -endif() -if(USE_BUNDLED_ZLIB STREQUAL "Chromium") - add_subdirectory("${PROJECT_SOURCE_DIR}/deps/chromium-zlib" "${PROJECT_BINARY_DIR}/deps/chromium-zlib") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/chromium-zlib") - list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $) - add_feature_info(zlib ON "using (Chromium) bundled zlib") - set(GIT_COMPRESSION_BUILTIN 1) -elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND) - add_subdirectory("${PROJECT_SOURCE_DIR}/deps/zlib" "${PROJECT_BINARY_DIR}/deps/zlib") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/zlib") - list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $) - add_feature_info(zlib ON "using bundled zlib") - set(GIT_COMPRESSION_BUILTIN 1) -endif() diff --git a/vendor/libgit2-sys/libgit2/deps/chromium-zlib/CMakeLists.txt b/vendor/libgit2-sys/libgit2/deps/chromium-zlib/CMakeLists.txt deleted file mode 100644 index 55d6794..0000000 --- a/vendor/libgit2-sys/libgit2/deps/chromium-zlib/CMakeLists.txt +++ /dev/null @@ -1,101 +0,0 @@ -# CMake build script for the bundled Chromium zlib implementation. So far, it -# is only supported for x86_64 processors with CLMUL, SSE3, SSE4.2. -# -# TODO: The Chromium build file (in deps/chromium-zlib/zlib/BUILD.gn) supports -# more platforms (like ARM with NEON), more can be enabled as needed. - -cmake_minimum_required(VERSION 3.11) - -include(FetchContent) -include(FindGit) - -# Ensure that the git binary is present to download the sources. -find_package(Git) -if(NOT Git_FOUND) - message(FATAL_ERROR "git is required to download the Chromium zlib sources") -endif() - -fetchcontent_populate(chromium_zlib_src - GIT_REPOSITORY https://chromium.googlesource.com/chromium/src/third_party/zlib.git - GIT_TAG 2c183c9f93a328bfb3121284da13cf89a0f7e64a - QUIET -) - -# The Chromium build globally disables some warnings. -disable_warnings(implicit-fallthrough) -disable_warnings(unused-function) -disable_warnings(unused-parameter) -disable_warnings(sign-compare) -disable_warnings(declaration-after-statement) -disable_warnings(missing-declarations) - -# -O3 is also set by the Chromium configuration and has been deemed safe enough -# for them. -set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG") -set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") - -# Common definitions. -add_definitions( - -DSTDC - -DNO_GZIP - -DZLIB_IMPLEMENTATION -) -list(APPEND SRC_ZLIB - "${chromium_zlib_src_SOURCE_DIR}/adler32.c" - "${chromium_zlib_src_SOURCE_DIR}/chromeconf.h" - "${chromium_zlib_src_SOURCE_DIR}/compress.c" - "${chromium_zlib_src_SOURCE_DIR}/contrib/optimizations/insert_string.h" - "${chromium_zlib_src_SOURCE_DIR}/cpu_features.c" - "${chromium_zlib_src_SOURCE_DIR}/cpu_features.h" - "${chromium_zlib_src_SOURCE_DIR}/crc32.c" - "${chromium_zlib_src_SOURCE_DIR}/crc32.h" - "${chromium_zlib_src_SOURCE_DIR}/deflate.c" - "${chromium_zlib_src_SOURCE_DIR}/deflate.h" - "${chromium_zlib_src_SOURCE_DIR}/gzclose.c" - "${chromium_zlib_src_SOURCE_DIR}/gzguts.h" - "${chromium_zlib_src_SOURCE_DIR}/gzlib.c" - "${chromium_zlib_src_SOURCE_DIR}/gzread.c" - "${chromium_zlib_src_SOURCE_DIR}/gzwrite.c" - "${chromium_zlib_src_SOURCE_DIR}/infback.c" - "${chromium_zlib_src_SOURCE_DIR}/inffast.c" - "${chromium_zlib_src_SOURCE_DIR}/inffast.h" - "${chromium_zlib_src_SOURCE_DIR}/inffixed.h" - "${chromium_zlib_src_SOURCE_DIR}/inflate.h" - "${chromium_zlib_src_SOURCE_DIR}/inftrees.c" - "${chromium_zlib_src_SOURCE_DIR}/inftrees.h" - "${chromium_zlib_src_SOURCE_DIR}/trees.c" - "${chromium_zlib_src_SOURCE_DIR}/trees.h" - "${chromium_zlib_src_SOURCE_DIR}/uncompr.c" - "${chromium_zlib_src_SOURCE_DIR}/zconf.h" - "${chromium_zlib_src_SOURCE_DIR}/zlib.h" - "${chromium_zlib_src_SOURCE_DIR}/zutil.c" - "${chromium_zlib_src_SOURCE_DIR}/zutil.h" -) - -# x86_64-specific optimizations -string(APPEND CMAKE_C_FLAGS " -mssse3 -msse4.2 -mpclmul") -add_definitions( - -DCHROMIUM_ZLIB_NO_CHROMECONF - -DX86_NOT_WINDOWS - -DADLER32_SIMD_SSSE3 - -DCRC32_SIMD_SSE42_PCLMUL - -DDEFLATE_FILL_WINDOW_SSE2 - -DINFLATE_CHUNK_READ_64LE - -DINFLATE_CHUNK_SIMD_SSE2 -) -list(APPEND SRC_ZLIB - "${chromium_zlib_src_SOURCE_DIR}/adler32_simd.c" - "${chromium_zlib_src_SOURCE_DIR}/adler32_simd.h" - "${chromium_zlib_src_SOURCE_DIR}/contrib/optimizations/chunkcopy.h" - "${chromium_zlib_src_SOURCE_DIR}/contrib/optimizations/inffast_chunk.c" - "${chromium_zlib_src_SOURCE_DIR}/contrib/optimizations/inffast_chunk.h" - "${chromium_zlib_src_SOURCE_DIR}/contrib/optimizations/inflate.c" - "${chromium_zlib_src_SOURCE_DIR}/crc32_simd.c" - "${chromium_zlib_src_SOURCE_DIR}/crc32_simd.h" - "${chromium_zlib_src_SOURCE_DIR}/crc_folding.c" - "${chromium_zlib_src_SOURCE_DIR}/fill_window_sse.c" -) - -list(SORT SRC_ZLIB) -include_directories("${chromium_zlib_src_SOURCE_DIR}") -add_library(chromium_zlib OBJECT ${SRC_ZLIB}) diff --git a/vendor/libgit2-sys/libgit2/deps/llhttp/CMakeLists.txt b/vendor/libgit2-sys/libgit2/deps/llhttp/CMakeLists.txt deleted file mode 100644 index 6965335..0000000 --- a/vendor/libgit2-sys/libgit2/deps/llhttp/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -file(GLOB SRC_LLHTTP "*.c" "*.h") -list(SORT SRC_LLHTTP) - -add_library(llhttp OBJECT ${SRC_LLHTTP}) - -if(NOT MSVC) - set_source_files_properties(api.c http.c llhttp.c PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-missing-declarations") -endif() diff --git a/vendor/libgit2-sys/libgit2/deps/llhttp/LICENSE-MIT b/vendor/libgit2-sys/libgit2/deps/llhttp/LICENSE-MIT deleted file mode 100644 index 6c1512d..0000000 --- a/vendor/libgit2-sys/libgit2/deps/llhttp/LICENSE-MIT +++ /dev/null @@ -1,22 +0,0 @@ -This software is licensed under the MIT License. - -Copyright Fedor Indutny, 2018. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to permit -persons to whom the Software is furnished to do so, subject to the -following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/libgit2-sys/libgit2/deps/llhttp/api.c b/vendor/libgit2-sys/libgit2/deps/llhttp/api.c deleted file mode 100644 index eddb478..0000000 --- a/vendor/libgit2-sys/libgit2/deps/llhttp/api.c +++ /dev/null @@ -1,510 +0,0 @@ -#include -#include -#include - -#include "llhttp.h" - -#define CALLBACK_MAYBE(PARSER, NAME) \ - do { \ - const llhttp_settings_t* settings; \ - settings = (const llhttp_settings_t*) (PARSER)->settings; \ - if (settings == NULL || settings->NAME == NULL) { \ - err = 0; \ - break; \ - } \ - err = settings->NAME((PARSER)); \ - } while (0) - -#define SPAN_CALLBACK_MAYBE(PARSER, NAME, START, LEN) \ - do { \ - const llhttp_settings_t* settings; \ - settings = (const llhttp_settings_t*) (PARSER)->settings; \ - if (settings == NULL || settings->NAME == NULL) { \ - err = 0; \ - break; \ - } \ - err = settings->NAME((PARSER), (START), (LEN)); \ - if (err == -1) { \ - err = HPE_USER; \ - llhttp_set_error_reason((PARSER), "Span callback error in " #NAME); \ - } \ - } while (0) - -void llhttp_init(llhttp_t* parser, llhttp_type_t type, - const llhttp_settings_t* settings) { - llhttp__internal_init(parser); - - parser->type = type; - parser->settings = (void*) settings; -} - - -#if defined(__wasm__) - -extern int wasm_on_message_begin(llhttp_t * p); -extern int wasm_on_url(llhttp_t* p, const char* at, size_t length); -extern int wasm_on_status(llhttp_t* p, const char* at, size_t length); -extern int wasm_on_header_field(llhttp_t* p, const char* at, size_t length); -extern int wasm_on_header_value(llhttp_t* p, const char* at, size_t length); -extern int wasm_on_headers_complete(llhttp_t * p, int status_code, - uint8_t upgrade, int should_keep_alive); -extern int wasm_on_body(llhttp_t* p, const char* at, size_t length); -extern int wasm_on_message_complete(llhttp_t * p); - -static int wasm_on_headers_complete_wrap(llhttp_t* p) { - return wasm_on_headers_complete(p, p->status_code, p->upgrade, - llhttp_should_keep_alive(p)); -} - -const llhttp_settings_t wasm_settings = { - wasm_on_message_begin, - wasm_on_url, - wasm_on_status, - NULL, - NULL, - wasm_on_header_field, - wasm_on_header_value, - NULL, - NULL, - wasm_on_headers_complete_wrap, - wasm_on_body, - wasm_on_message_complete, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, -}; - - -llhttp_t* llhttp_alloc(llhttp_type_t type) { - llhttp_t* parser = malloc(sizeof(llhttp_t)); - llhttp_init(parser, type, &wasm_settings); - return parser; -} - -void llhttp_free(llhttp_t* parser) { - free(parser); -} - -#endif /* defined(__wasm__) */ - -/* Some getters required to get stuff from the parser */ - -uint8_t llhttp_get_type(llhttp_t* parser) { - return parser->type; -} - -uint8_t llhttp_get_http_major(llhttp_t* parser) { - return parser->http_major; -} - -uint8_t llhttp_get_http_minor(llhttp_t* parser) { - return parser->http_minor; -} - -uint8_t llhttp_get_method(llhttp_t* parser) { - return parser->method; -} - -int llhttp_get_status_code(llhttp_t* parser) { - return parser->status_code; -} - -uint8_t llhttp_get_upgrade(llhttp_t* parser) { - return parser->upgrade; -} - - -void llhttp_reset(llhttp_t* parser) { - llhttp_type_t type = parser->type; - const llhttp_settings_t* settings = parser->settings; - void* data = parser->data; - uint16_t lenient_flags = parser->lenient_flags; - - llhttp__internal_init(parser); - - parser->type = type; - parser->settings = (void*) settings; - parser->data = data; - parser->lenient_flags = lenient_flags; -} - - -llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len) { - return llhttp__internal_execute(parser, data, data + len); -} - - -void llhttp_settings_init(llhttp_settings_t* settings) { - memset(settings, 0, sizeof(*settings)); -} - - -llhttp_errno_t llhttp_finish(llhttp_t* parser) { - int err; - - /* We're in an error state. Don't bother doing anything. */ - if (parser->error != 0) { - return 0; - } - - switch (parser->finish) { - case HTTP_FINISH_SAFE_WITH_CB: - CALLBACK_MAYBE(parser, on_message_complete); - if (err != HPE_OK) return err; - - /* FALLTHROUGH */ - case HTTP_FINISH_SAFE: - return HPE_OK; - case HTTP_FINISH_UNSAFE: - parser->reason = "Invalid EOF state"; - return HPE_INVALID_EOF_STATE; - default: - abort(); - } -} - - -void llhttp_pause(llhttp_t* parser) { - if (parser->error != HPE_OK) { - return; - } - - parser->error = HPE_PAUSED; - parser->reason = "Paused"; -} - - -void llhttp_resume(llhttp_t* parser) { - if (parser->error != HPE_PAUSED) { - return; - } - - parser->error = 0; -} - - -void llhttp_resume_after_upgrade(llhttp_t* parser) { - if (parser->error != HPE_PAUSED_UPGRADE) { - return; - } - - parser->error = 0; -} - - -llhttp_errno_t llhttp_get_errno(const llhttp_t* parser) { - return parser->error; -} - - -const char* llhttp_get_error_reason(const llhttp_t* parser) { - return parser->reason; -} - - -void llhttp_set_error_reason(llhttp_t* parser, const char* reason) { - parser->reason = reason; -} - - -const char* llhttp_get_error_pos(const llhttp_t* parser) { - return parser->error_pos; -} - - -const char* llhttp_errno_name(llhttp_errno_t err) { -#define HTTP_ERRNO_GEN(CODE, NAME, _) case HPE_##NAME: return "HPE_" #NAME; - switch (err) { - HTTP_ERRNO_MAP(HTTP_ERRNO_GEN) - default: abort(); - } -#undef HTTP_ERRNO_GEN -} - - -const char* llhttp_method_name(llhttp_method_t method) { -#define HTTP_METHOD_GEN(NUM, NAME, STRING) case HTTP_##NAME: return #STRING; - switch (method) { - HTTP_ALL_METHOD_MAP(HTTP_METHOD_GEN) - default: abort(); - } -#undef HTTP_METHOD_GEN -} - -const char* llhttp_status_name(llhttp_status_t status) { -#define HTTP_STATUS_GEN(NUM, NAME, STRING) case HTTP_STATUS_##NAME: return #STRING; - switch (status) { - HTTP_STATUS_MAP(HTTP_STATUS_GEN) - default: abort(); - } -#undef HTTP_STATUS_GEN -} - - -void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_HEADERS; - } else { - parser->lenient_flags &= ~LENIENT_HEADERS; - } -} - - -void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_CHUNKED_LENGTH; - } else { - parser->lenient_flags &= ~LENIENT_CHUNKED_LENGTH; - } -} - - -void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_KEEP_ALIVE; - } else { - parser->lenient_flags &= ~LENIENT_KEEP_ALIVE; - } -} - -void llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_TRANSFER_ENCODING; - } else { - parser->lenient_flags &= ~LENIENT_TRANSFER_ENCODING; - } -} - -void llhttp_set_lenient_version(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_VERSION; - } else { - parser->lenient_flags &= ~LENIENT_VERSION; - } -} - -void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_DATA_AFTER_CLOSE; - } else { - parser->lenient_flags &= ~LENIENT_DATA_AFTER_CLOSE; - } -} - -void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_OPTIONAL_LF_AFTER_CR; - } else { - parser->lenient_flags &= ~LENIENT_OPTIONAL_LF_AFTER_CR; - } -} - -void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_OPTIONAL_CRLF_AFTER_CHUNK; - } else { - parser->lenient_flags &= ~LENIENT_OPTIONAL_CRLF_AFTER_CHUNK; - } -} - -void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_OPTIONAL_CR_BEFORE_LF; - } else { - parser->lenient_flags &= ~LENIENT_OPTIONAL_CR_BEFORE_LF; - } -} - -void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled) { - if (enabled) { - parser->lenient_flags |= LENIENT_SPACES_AFTER_CHUNK_SIZE; - } else { - parser->lenient_flags &= ~LENIENT_SPACES_AFTER_CHUNK_SIZE; - } -} - -/* Callbacks */ - - -int llhttp__on_message_begin(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_message_begin); - return err; -} - - -int llhttp__on_url(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_url, p, endp - p); - return err; -} - - -int llhttp__on_url_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_url_complete); - return err; -} - - -int llhttp__on_status(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_status, p, endp - p); - return err; -} - - -int llhttp__on_status_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_status_complete); - return err; -} - - -int llhttp__on_method(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_method, p, endp - p); - return err; -} - - -int llhttp__on_method_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_method_complete); - return err; -} - - -int llhttp__on_version(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_version, p, endp - p); - return err; -} - - -int llhttp__on_version_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_version_complete); - return err; -} - - -int llhttp__on_header_field(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_header_field, p, endp - p); - return err; -} - - -int llhttp__on_header_field_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_header_field_complete); - return err; -} - - -int llhttp__on_header_value(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_header_value, p, endp - p); - return err; -} - - -int llhttp__on_header_value_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_header_value_complete); - return err; -} - - -int llhttp__on_headers_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_headers_complete); - return err; -} - - -int llhttp__on_message_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_message_complete); - return err; -} - - -int llhttp__on_body(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_body, p, endp - p); - return err; -} - - -int llhttp__on_chunk_header(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_chunk_header); - return err; -} - - -int llhttp__on_chunk_extension_name(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_chunk_extension_name, p, endp - p); - return err; -} - - -int llhttp__on_chunk_extension_name_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_chunk_extension_name_complete); - return err; -} - - -int llhttp__on_chunk_extension_value(llhttp_t* s, const char* p, const char* endp) { - int err; - SPAN_CALLBACK_MAYBE(s, on_chunk_extension_value, p, endp - p); - return err; -} - - -int llhttp__on_chunk_extension_value_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_chunk_extension_value_complete); - return err; -} - - -int llhttp__on_chunk_complete(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_chunk_complete); - return err; -} - - -int llhttp__on_reset(llhttp_t* s, const char* p, const char* endp) { - int err; - CALLBACK_MAYBE(s, on_reset); - return err; -} - - -/* Private */ - - -void llhttp__debug(llhttp_t* s, const char* p, const char* endp, - const char* msg) { - if (p == endp) { - fprintf(stderr, "p=%p type=%d flags=%02x next=null debug=%s\n", s, s->type, - s->flags, msg); - } else { - fprintf(stderr, "p=%p type=%d flags=%02x next=%02x debug=%s\n", s, - s->type, s->flags, *p, msg); - } -} diff --git a/vendor/libgit2-sys/libgit2/deps/llhttp/http.c b/vendor/libgit2-sys/libgit2/deps/llhttp/http.c deleted file mode 100644 index 1ab91a5..0000000 --- a/vendor/libgit2-sys/libgit2/deps/llhttp/http.c +++ /dev/null @@ -1,170 +0,0 @@ -#include -#ifndef LLHTTP__TEST -# include "llhttp.h" -#else -# define llhttp_t llparse_t -#endif /* */ - -int llhttp_message_needs_eof(const llhttp_t* parser); -int llhttp_should_keep_alive(const llhttp_t* parser); - -int llhttp__before_headers_complete(llhttp_t* parser, const char* p, - const char* endp) { - /* Set this here so that on_headers_complete() callbacks can see it */ - if ((parser->flags & F_UPGRADE) && - (parser->flags & F_CONNECTION_UPGRADE)) { - /* For responses, "Upgrade: foo" and "Connection: upgrade" are - * mandatory only when it is a 101 Switching Protocols response, - * otherwise it is purely informational, to announce support. - */ - parser->upgrade = - (parser->type == HTTP_REQUEST || parser->status_code == 101); - } else { - parser->upgrade = (parser->method == HTTP_CONNECT); - } - return 0; -} - - -/* Return values: - * 0 - No body, `restart`, message_complete - * 1 - CONNECT request, `restart`, message_complete, and pause - * 2 - chunk_size_start - * 3 - body_identity - * 4 - body_identity_eof - * 5 - invalid transfer-encoding for request - */ -int llhttp__after_headers_complete(llhttp_t* parser, const char* p, - const char* endp) { - int hasBody; - - hasBody = parser->flags & F_CHUNKED || parser->content_length > 0; - if ( - (parser->upgrade && (parser->method == HTTP_CONNECT || - (parser->flags & F_SKIPBODY) || !hasBody)) || - /* See RFC 2616 section 4.4 - 1xx e.g. Continue */ - (parser->type == HTTP_RESPONSE && parser->status_code == 101) - ) { - /* Exit, the rest of the message is in a different protocol. */ - return 1; - } - - if (parser->type == HTTP_RESPONSE && parser->status_code == 100) { - /* No body, restart as the message is complete */ - return 0; - } - - /* See RFC 2616 section 4.4 */ - if ( - parser->flags & F_SKIPBODY || /* response to a HEAD request */ - ( - parser->type == HTTP_RESPONSE && ( - parser->status_code == 102 || /* Processing */ - parser->status_code == 103 || /* Early Hints */ - parser->status_code == 204 || /* No Content */ - parser->status_code == 304 /* Not Modified */ - ) - ) - ) { - return 0; - } else if (parser->flags & F_CHUNKED) { - /* chunked encoding - ignore Content-Length header, prepare for a chunk */ - return 2; - } else if (parser->flags & F_TRANSFER_ENCODING) { - if (parser->type == HTTP_REQUEST && - (parser->lenient_flags & LENIENT_CHUNKED_LENGTH) == 0 && - (parser->lenient_flags & LENIENT_TRANSFER_ENCODING) == 0) { - /* RFC 7230 3.3.3 */ - - /* If a Transfer-Encoding header field - * is present in a request and the chunked transfer coding is not - * the final encoding, the message body length cannot be determined - * reliably; the server MUST respond with the 400 (Bad Request) - * status code and then close the connection. - */ - return 5; - } else { - /* RFC 7230 3.3.3 */ - - /* If a Transfer-Encoding header field is present in a response and - * the chunked transfer coding is not the final encoding, the - * message body length is determined by reading the connection until - * it is closed by the server. - */ - return 4; - } - } else { - if (!(parser->flags & F_CONTENT_LENGTH)) { - if (!llhttp_message_needs_eof(parser)) { - /* Assume content-length 0 - read the next */ - return 0; - } else { - /* Read body until EOF */ - return 4; - } - } else if (parser->content_length == 0) { - /* Content-Length header given but zero: Content-Length: 0\r\n */ - return 0; - } else { - /* Content-Length header given and non-zero */ - return 3; - } - } -} - - -int llhttp__after_message_complete(llhttp_t* parser, const char* p, - const char* endp) { - int should_keep_alive; - - should_keep_alive = llhttp_should_keep_alive(parser); - parser->finish = HTTP_FINISH_SAFE; - parser->flags = 0; - - /* NOTE: this is ignored in loose parsing mode */ - return should_keep_alive; -} - - -int llhttp_message_needs_eof(const llhttp_t* parser) { - if (parser->type == HTTP_REQUEST) { - return 0; - } - - /* See RFC 2616 section 4.4 */ - if (parser->status_code / 100 == 1 || /* 1xx e.g. Continue */ - parser->status_code == 204 || /* No Content */ - parser->status_code == 304 || /* Not Modified */ - (parser->flags & F_SKIPBODY)) { /* response to a HEAD request */ - return 0; - } - - /* RFC 7230 3.3.3, see `llhttp__after_headers_complete` */ - if ((parser->flags & F_TRANSFER_ENCODING) && - (parser->flags & F_CHUNKED) == 0) { - return 1; - } - - if (parser->flags & (F_CHUNKED | F_CONTENT_LENGTH)) { - return 0; - } - - return 1; -} - - -int llhttp_should_keep_alive(const llhttp_t* parser) { - if (parser->http_major > 0 && parser->http_minor > 0) { - /* HTTP/1.1 */ - if (parser->flags & F_CONNECTION_CLOSE) { - return 0; - } - } else { - /* HTTP/1.0 or earlier */ - if (!(parser->flags & F_CONNECTION_KEEP_ALIVE)) { - return 0; - } - } - - return !llhttp_message_needs_eof(parser); -} diff --git a/vendor/libgit2-sys/libgit2/deps/llhttp/llhttp.c b/vendor/libgit2-sys/libgit2/deps/llhttp/llhttp.c deleted file mode 100644 index 3ef3b81..0000000 --- a/vendor/libgit2-sys/libgit2/deps/llhttp/llhttp.c +++ /dev/null @@ -1,10168 +0,0 @@ -#include -#include -#include - -#ifdef __SSE4_2__ - #ifdef _MSC_VER - #include - #else /* !_MSC_VER */ - #include - #endif /* _MSC_VER */ -#endif /* __SSE4_2__ */ - -#ifdef _MSC_VER - #define ALIGN(n) _declspec(align(n)) -#else /* !_MSC_VER */ - #define ALIGN(n) __attribute__((aligned(n))) -#endif /* _MSC_VER */ - -#include "llhttp.h" - -typedef int (*llhttp__internal__span_cb)( - llhttp__internal_t*, const char*, const char*); - -static const unsigned char llparse_blob0[] = { - 'o', 'n' -}; -static const unsigned char llparse_blob1[] = { - 'e', 'c', 't', 'i', 'o', 'n' -}; -static const unsigned char llparse_blob2[] = { - 'l', 'o', 's', 'e' -}; -static const unsigned char llparse_blob3[] = { - 'e', 'e', 'p', '-', 'a', 'l', 'i', 'v', 'e' -}; -static const unsigned char llparse_blob4[] = { - 'p', 'g', 'r', 'a', 'd', 'e' -}; -static const unsigned char llparse_blob5[] = { - 'c', 'h', 'u', 'n', 'k', 'e', 'd' -}; -#ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob6[] = { - 0x9, 0x9, ' ', '~', 0x80, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0 -}; -#endif /* __SSE4_2__ */ -#ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob7[] = { - '!', '!', '#', '\'', '*', '+', '-', '.', '0', '9', 'A', - 'Z', '^', 'z', '|', '|' -}; -#endif /* __SSE4_2__ */ -#ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob8[] = { - '~', '~', 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0 -}; -#endif /* __SSE4_2__ */ -static const unsigned char llparse_blob9[] = { - 'e', 'n', 't', '-', 'l', 'e', 'n', 'g', 't', 'h' -}; -static const unsigned char llparse_blob10[] = { - 'r', 'o', 'x', 'y', '-', 'c', 'o', 'n', 'n', 'e', 'c', - 't', 'i', 'o', 'n' -}; -static const unsigned char llparse_blob11[] = { - 'r', 'a', 'n', 's', 'f', 'e', 'r', '-', 'e', 'n', 'c', - 'o', 'd', 'i', 'n', 'g' -}; -static const unsigned char llparse_blob12[] = { - 'p', 'g', 'r', 'a', 'd', 'e' -}; -static const unsigned char llparse_blob13[] = { - 'T', 'T', 'P', '/' -}; -static const unsigned char llparse_blob14[] = { - 0xd, 0xa, 0xd, 0xa, 'S', 'M', 0xd, 0xa, 0xd, 0xa -}; -static const unsigned char llparse_blob15[] = { - 'C', 'E', '/' -}; -static const unsigned char llparse_blob16[] = { - 'T', 'S', 'P', '/' -}; -static const unsigned char llparse_blob17[] = { - 'N', 'O', 'U', 'N', 'C', 'E' -}; -static const unsigned char llparse_blob18[] = { - 'I', 'N', 'D' -}; -static const unsigned char llparse_blob19[] = { - 'E', 'C', 'K', 'O', 'U', 'T' -}; -static const unsigned char llparse_blob20[] = { - 'N', 'E', 'C', 'T' -}; -static const unsigned char llparse_blob21[] = { - 'E', 'T', 'E' -}; -static const unsigned char llparse_blob22[] = { - 'C', 'R', 'I', 'B', 'E' -}; -static const unsigned char llparse_blob23[] = { - 'L', 'U', 'S', 'H' -}; -static const unsigned char llparse_blob24[] = { - 'E', 'T' -}; -static const unsigned char llparse_blob25[] = { - 'P', 'A', 'R', 'A', 'M', 'E', 'T', 'E', 'R' -}; -static const unsigned char llparse_blob26[] = { - 'E', 'A', 'D' -}; -static const unsigned char llparse_blob27[] = { - 'N', 'K' -}; -static const unsigned char llparse_blob28[] = { - 'C', 'K' -}; -static const unsigned char llparse_blob29[] = { - 'S', 'E', 'A', 'R', 'C', 'H' -}; -static const unsigned char llparse_blob30[] = { - 'R', 'G', 'E' -}; -static const unsigned char llparse_blob31[] = { - 'C', 'T', 'I', 'V', 'I', 'T', 'Y' -}; -static const unsigned char llparse_blob32[] = { - 'L', 'E', 'N', 'D', 'A', 'R' -}; -static const unsigned char llparse_blob33[] = { - 'V', 'E' -}; -static const unsigned char llparse_blob34[] = { - 'O', 'T', 'I', 'F', 'Y' -}; -static const unsigned char llparse_blob35[] = { - 'P', 'T', 'I', 'O', 'N', 'S' -}; -static const unsigned char llparse_blob36[] = { - 'C', 'H' -}; -static const unsigned char llparse_blob37[] = { - 'S', 'E' -}; -static const unsigned char llparse_blob38[] = { - 'A', 'Y' -}; -static const unsigned char llparse_blob39[] = { - 'S', 'T' -}; -static const unsigned char llparse_blob40[] = { - 'I', 'N', 'D' -}; -static const unsigned char llparse_blob41[] = { - 'A', 'T', 'C', 'H' -}; -static const unsigned char llparse_blob42[] = { - 'G', 'E' -}; -static const unsigned char llparse_blob43[] = { - 'U', 'E', 'R', 'Y' -}; -static const unsigned char llparse_blob44[] = { - 'I', 'N', 'D' -}; -static const unsigned char llparse_blob45[] = { - 'O', 'R', 'D' -}; -static const unsigned char llparse_blob46[] = { - 'I', 'R', 'E', 'C', 'T' -}; -static const unsigned char llparse_blob47[] = { - 'O', 'R', 'T' -}; -static const unsigned char llparse_blob48[] = { - 'R', 'C', 'H' -}; -static const unsigned char llparse_blob49[] = { - 'P', 'A', 'R', 'A', 'M', 'E', 'T', 'E', 'R' -}; -static const unsigned char llparse_blob50[] = { - 'U', 'R', 'C', 'E' -}; -static const unsigned char llparse_blob51[] = { - 'B', 'S', 'C', 'R', 'I', 'B', 'E' -}; -static const unsigned char llparse_blob52[] = { - 'A', 'R', 'D', 'O', 'W', 'N' -}; -static const unsigned char llparse_blob53[] = { - 'A', 'C', 'E' -}; -static const unsigned char llparse_blob54[] = { - 'I', 'N', 'D' -}; -static const unsigned char llparse_blob55[] = { - 'N', 'K' -}; -static const unsigned char llparse_blob56[] = { - 'C', 'K' -}; -static const unsigned char llparse_blob57[] = { - 'U', 'B', 'S', 'C', 'R', 'I', 'B', 'E' -}; -static const unsigned char llparse_blob58[] = { - 'H', 'T', 'T', 'P', '/' -}; -static const unsigned char llparse_blob59[] = { - 'A', 'D' -}; -static const unsigned char llparse_blob60[] = { - 'T', 'P', '/' -}; - -enum llparse_match_status_e { - kMatchComplete, - kMatchPause, - kMatchMismatch -}; -typedef enum llparse_match_status_e llparse_match_status_t; - -struct llparse_match_s { - llparse_match_status_t status; - const unsigned char* current; -}; -typedef struct llparse_match_s llparse_match_t; - -static llparse_match_t llparse__match_sequence_to_lower( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp, - const unsigned char* seq, uint32_t seq_len) { - uint32_t index; - llparse_match_t res; - - index = s->_index; - for (; p != endp; p++) { - unsigned char current; - - current = ((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p)); - if (current == seq[index]) { - if (++index == seq_len) { - res.status = kMatchComplete; - goto reset; - } - } else { - res.status = kMatchMismatch; - goto reset; - } - } - s->_index = index; - res.status = kMatchPause; - res.current = p; - return res; -reset: - s->_index = 0; - res.current = p; - return res; -} - -static llparse_match_t llparse__match_sequence_to_lower_unsafe( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp, - const unsigned char* seq, uint32_t seq_len) { - uint32_t index; - llparse_match_t res; - - index = s->_index; - for (; p != endp; p++) { - unsigned char current; - - current = ((*p) | 0x20); - if (current == seq[index]) { - if (++index == seq_len) { - res.status = kMatchComplete; - goto reset; - } - } else { - res.status = kMatchMismatch; - goto reset; - } - } - s->_index = index; - res.status = kMatchPause; - res.current = p; - return res; -reset: - s->_index = 0; - res.current = p; - return res; -} - -static llparse_match_t llparse__match_sequence_id( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp, - const unsigned char* seq, uint32_t seq_len) { - uint32_t index; - llparse_match_t res; - - index = s->_index; - for (; p != endp; p++) { - unsigned char current; - - current = *p; - if (current == seq[index]) { - if (++index == seq_len) { - res.status = kMatchComplete; - goto reset; - } - } else { - res.status = kMatchMismatch; - goto reset; - } - } - s->_index = index; - res.status = kMatchPause; - res.current = p; - return res; -reset: - s->_index = 0; - res.current = p; - return res; -} - -enum llparse_state_e { - s_error, - s_n_llhttp__internal__n_closed, - s_n_llhttp__internal__n_invoke_llhttp__after_message_complete, - s_n_llhttp__internal__n_pause_1, - s_n_llhttp__internal__n_invoke_is_equal_upgrade, - s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2, - s_n_llhttp__internal__n_chunk_data_almost_done_1, - s_n_llhttp__internal__n_chunk_data_almost_done, - s_n_llhttp__internal__n_consume_content_length, - s_n_llhttp__internal__n_span_start_llhttp__on_body, - s_n_llhttp__internal__n_invoke_is_equal_content_length, - s_n_llhttp__internal__n_chunk_size_almost_done, - s_n_llhttp__internal__n_invoke_test_lenient_flags_9, - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete, - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1, - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2, - s_n_llhttp__internal__n_invoke_test_lenient_flags_10, - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete, - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1, - s_n_llhttp__internal__n_chunk_extension_quoted_value_done, - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2, - s_n_llhttp__internal__n_error_30, - s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair, - s_n_llhttp__internal__n_error_31, - s_n_llhttp__internal__n_chunk_extension_quoted_value, - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3, - s_n_llhttp__internal__n_error_33, - s_n_llhttp__internal__n_chunk_extension_value, - s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_value, - s_n_llhttp__internal__n_error_34, - s_n_llhttp__internal__n_chunk_extension_name, - s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name, - s_n_llhttp__internal__n_chunk_extensions, - s_n_llhttp__internal__n_chunk_size_otherwise, - s_n_llhttp__internal__n_chunk_size, - s_n_llhttp__internal__n_chunk_size_digit, - s_n_llhttp__internal__n_invoke_update_content_length_1, - s_n_llhttp__internal__n_consume_content_length_1, - s_n_llhttp__internal__n_span_start_llhttp__on_body_1, - s_n_llhttp__internal__n_eof, - s_n_llhttp__internal__n_span_start_llhttp__on_body_2, - s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete, - s_n_llhttp__internal__n_error_5, - s_n_llhttp__internal__n_headers_almost_done, - s_n_llhttp__internal__n_header_field_colon_discard_ws, - s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete, - s_n_llhttp__internal__n_span_start_llhttp__on_header_value, - s_n_llhttp__internal__n_header_value_discard_lws, - s_n_llhttp__internal__n_header_value_discard_ws_almost_done, - s_n_llhttp__internal__n_header_value_lws, - s_n_llhttp__internal__n_header_value_almost_done, - s_n_llhttp__internal__n_invoke_test_lenient_flags_17, - s_n_llhttp__internal__n_header_value_lenient, - s_n_llhttp__internal__n_error_54, - s_n_llhttp__internal__n_header_value_otherwise, - s_n_llhttp__internal__n_header_value_connection_token, - s_n_llhttp__internal__n_header_value_connection_ws, - s_n_llhttp__internal__n_header_value_connection_1, - s_n_llhttp__internal__n_header_value_connection_2, - s_n_llhttp__internal__n_header_value_connection_3, - s_n_llhttp__internal__n_header_value_connection, - s_n_llhttp__internal__n_error_56, - s_n_llhttp__internal__n_error_57, - s_n_llhttp__internal__n_header_value_content_length_ws, - s_n_llhttp__internal__n_header_value_content_length, - s_n_llhttp__internal__n_error_59, - s_n_llhttp__internal__n_error_58, - s_n_llhttp__internal__n_header_value_te_token_ows, - s_n_llhttp__internal__n_header_value, - s_n_llhttp__internal__n_header_value_te_token, - s_n_llhttp__internal__n_header_value_te_chunked_last, - s_n_llhttp__internal__n_header_value_te_chunked, - s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1, - s_n_llhttp__internal__n_header_value_discard_ws, - s_n_llhttp__internal__n_invoke_load_header_state, - s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete, - s_n_llhttp__internal__n_header_field_general_otherwise, - s_n_llhttp__internal__n_header_field_general, - s_n_llhttp__internal__n_header_field_colon, - s_n_llhttp__internal__n_header_field_3, - s_n_llhttp__internal__n_header_field_4, - s_n_llhttp__internal__n_header_field_2, - s_n_llhttp__internal__n_header_field_1, - s_n_llhttp__internal__n_header_field_5, - s_n_llhttp__internal__n_header_field_6, - s_n_llhttp__internal__n_header_field_7, - s_n_llhttp__internal__n_header_field, - s_n_llhttp__internal__n_span_start_llhttp__on_header_field, - s_n_llhttp__internal__n_header_field_start, - s_n_llhttp__internal__n_headers_start, - s_n_llhttp__internal__n_url_to_http_09, - s_n_llhttp__internal__n_url_skip_to_http09, - s_n_llhttp__internal__n_url_skip_lf_to_http09_1, - s_n_llhttp__internal__n_url_skip_lf_to_http09, - s_n_llhttp__internal__n_req_pri_upgrade, - s_n_llhttp__internal__n_req_http_complete_crlf, - s_n_llhttp__internal__n_req_http_complete, - s_n_llhttp__internal__n_invoke_load_method_1, - s_n_llhttp__internal__n_invoke_llhttp__on_version_complete, - s_n_llhttp__internal__n_error_66, - s_n_llhttp__internal__n_error_73, - s_n_llhttp__internal__n_req_http_minor, - s_n_llhttp__internal__n_error_74, - s_n_llhttp__internal__n_req_http_dot, - s_n_llhttp__internal__n_error_75, - s_n_llhttp__internal__n_req_http_major, - s_n_llhttp__internal__n_span_start_llhttp__on_version, - s_n_llhttp__internal__n_req_http_start_1, - s_n_llhttp__internal__n_req_http_start_2, - s_n_llhttp__internal__n_req_http_start_3, - s_n_llhttp__internal__n_req_http_start, - s_n_llhttp__internal__n_url_to_http, - s_n_llhttp__internal__n_url_skip_to_http, - s_n_llhttp__internal__n_url_fragment, - s_n_llhttp__internal__n_span_end_stub_query_3, - s_n_llhttp__internal__n_url_query, - s_n_llhttp__internal__n_url_query_or_fragment, - s_n_llhttp__internal__n_url_path, - s_n_llhttp__internal__n_span_start_stub_path_2, - s_n_llhttp__internal__n_span_start_stub_path, - s_n_llhttp__internal__n_span_start_stub_path_1, - s_n_llhttp__internal__n_url_server_with_at, - s_n_llhttp__internal__n_url_server, - s_n_llhttp__internal__n_url_schema_delim_1, - s_n_llhttp__internal__n_url_schema_delim, - s_n_llhttp__internal__n_span_end_stub_schema, - s_n_llhttp__internal__n_url_schema, - s_n_llhttp__internal__n_url_start, - s_n_llhttp__internal__n_span_start_llhttp__on_url_1, - s_n_llhttp__internal__n_url_entry_normal, - s_n_llhttp__internal__n_span_start_llhttp__on_url, - s_n_llhttp__internal__n_url_entry_connect, - s_n_llhttp__internal__n_req_spaces_before_url, - s_n_llhttp__internal__n_req_first_space_before_url, - s_n_llhttp__internal__n_invoke_llhttp__on_method_complete_1, - s_n_llhttp__internal__n_after_start_req_2, - s_n_llhttp__internal__n_after_start_req_3, - s_n_llhttp__internal__n_after_start_req_1, - s_n_llhttp__internal__n_after_start_req_4, - s_n_llhttp__internal__n_after_start_req_6, - s_n_llhttp__internal__n_after_start_req_8, - s_n_llhttp__internal__n_after_start_req_9, - s_n_llhttp__internal__n_after_start_req_7, - s_n_llhttp__internal__n_after_start_req_5, - s_n_llhttp__internal__n_after_start_req_12, - s_n_llhttp__internal__n_after_start_req_13, - s_n_llhttp__internal__n_after_start_req_11, - s_n_llhttp__internal__n_after_start_req_10, - s_n_llhttp__internal__n_after_start_req_14, - s_n_llhttp__internal__n_after_start_req_17, - s_n_llhttp__internal__n_after_start_req_16, - s_n_llhttp__internal__n_after_start_req_15, - s_n_llhttp__internal__n_after_start_req_18, - s_n_llhttp__internal__n_after_start_req_20, - s_n_llhttp__internal__n_after_start_req_21, - s_n_llhttp__internal__n_after_start_req_19, - s_n_llhttp__internal__n_after_start_req_23, - s_n_llhttp__internal__n_after_start_req_24, - s_n_llhttp__internal__n_after_start_req_26, - s_n_llhttp__internal__n_after_start_req_28, - s_n_llhttp__internal__n_after_start_req_29, - s_n_llhttp__internal__n_after_start_req_27, - s_n_llhttp__internal__n_after_start_req_25, - s_n_llhttp__internal__n_after_start_req_30, - s_n_llhttp__internal__n_after_start_req_22, - s_n_llhttp__internal__n_after_start_req_31, - s_n_llhttp__internal__n_after_start_req_32, - s_n_llhttp__internal__n_after_start_req_35, - s_n_llhttp__internal__n_after_start_req_36, - s_n_llhttp__internal__n_after_start_req_34, - s_n_llhttp__internal__n_after_start_req_37, - s_n_llhttp__internal__n_after_start_req_38, - s_n_llhttp__internal__n_after_start_req_42, - s_n_llhttp__internal__n_after_start_req_43, - s_n_llhttp__internal__n_after_start_req_41, - s_n_llhttp__internal__n_after_start_req_40, - s_n_llhttp__internal__n_after_start_req_39, - s_n_llhttp__internal__n_after_start_req_45, - s_n_llhttp__internal__n_after_start_req_44, - s_n_llhttp__internal__n_after_start_req_33, - s_n_llhttp__internal__n_after_start_req_46, - s_n_llhttp__internal__n_after_start_req_49, - s_n_llhttp__internal__n_after_start_req_50, - s_n_llhttp__internal__n_after_start_req_51, - s_n_llhttp__internal__n_after_start_req_52, - s_n_llhttp__internal__n_after_start_req_48, - s_n_llhttp__internal__n_after_start_req_47, - s_n_llhttp__internal__n_after_start_req_55, - s_n_llhttp__internal__n_after_start_req_57, - s_n_llhttp__internal__n_after_start_req_58, - s_n_llhttp__internal__n_after_start_req_56, - s_n_llhttp__internal__n_after_start_req_54, - s_n_llhttp__internal__n_after_start_req_59, - s_n_llhttp__internal__n_after_start_req_60, - s_n_llhttp__internal__n_after_start_req_53, - s_n_llhttp__internal__n_after_start_req_62, - s_n_llhttp__internal__n_after_start_req_63, - s_n_llhttp__internal__n_after_start_req_61, - s_n_llhttp__internal__n_after_start_req_66, - s_n_llhttp__internal__n_after_start_req_68, - s_n_llhttp__internal__n_after_start_req_69, - s_n_llhttp__internal__n_after_start_req_67, - s_n_llhttp__internal__n_after_start_req_70, - s_n_llhttp__internal__n_after_start_req_65, - s_n_llhttp__internal__n_after_start_req_64, - s_n_llhttp__internal__n_after_start_req, - s_n_llhttp__internal__n_span_start_llhttp__on_method_1, - s_n_llhttp__internal__n_res_line_almost_done, - s_n_llhttp__internal__n_invoke_test_lenient_flags_30, - s_n_llhttp__internal__n_res_status, - s_n_llhttp__internal__n_span_start_llhttp__on_status, - s_n_llhttp__internal__n_res_status_code_otherwise, - s_n_llhttp__internal__n_res_status_code_digit_3, - s_n_llhttp__internal__n_res_status_code_digit_2, - s_n_llhttp__internal__n_res_status_code_digit_1, - s_n_llhttp__internal__n_res_after_version, - s_n_llhttp__internal__n_invoke_llhttp__on_version_complete_1, - s_n_llhttp__internal__n_error_89, - s_n_llhttp__internal__n_error_103, - s_n_llhttp__internal__n_res_http_minor, - s_n_llhttp__internal__n_error_104, - s_n_llhttp__internal__n_res_http_dot, - s_n_llhttp__internal__n_error_105, - s_n_llhttp__internal__n_res_http_major, - s_n_llhttp__internal__n_span_start_llhttp__on_version_1, - s_n_llhttp__internal__n_start_res, - s_n_llhttp__internal__n_invoke_llhttp__on_method_complete, - s_n_llhttp__internal__n_req_or_res_method_2, - s_n_llhttp__internal__n_invoke_update_type_1, - s_n_llhttp__internal__n_req_or_res_method_3, - s_n_llhttp__internal__n_req_or_res_method_1, - s_n_llhttp__internal__n_req_or_res_method, - s_n_llhttp__internal__n_span_start_llhttp__on_method, - s_n_llhttp__internal__n_start_req_or_res, - s_n_llhttp__internal__n_invoke_load_type, - s_n_llhttp__internal__n_invoke_update_finish, - s_n_llhttp__internal__n_start, -}; -typedef enum llparse_state_e llparse_state_t; - -int llhttp__on_method( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_url( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_version( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_header_field( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_header_value( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_body( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_chunk_extension_name( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_chunk_extension_value( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_status( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_load_initial_message_completed( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->initial_message_completed; -} - -int llhttp__on_reset( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_update_finish( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->finish = 2; - return 0; -} - -int llhttp__on_message_begin( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_load_type( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->type; -} - -int llhttp__internal__c_store_method( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp, - int match) { - state->method = match; - return 0; -} - -int llhttp__on_method_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_is_equal_method( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->method == 5; -} - -int llhttp__internal__c_update_http_major( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->http_major = 0; - return 0; -} - -int llhttp__internal__c_update_http_minor( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->http_minor = 9; - return 0; -} - -int llhttp__on_url_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_test_lenient_flags( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 1) == 1; -} - -int llhttp__internal__c_test_lenient_flags_1( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 256) == 256; -} - -int llhttp__internal__c_test_flags( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->flags & 128) == 128; -} - -int llhttp__on_chunk_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_message_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_is_equal_upgrade( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->upgrade == 1; -} - -int llhttp__after_message_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_update_content_length( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->content_length = 0; - return 0; -} - -int llhttp__internal__c_update_initial_message_completed( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->initial_message_completed = 1; - return 0; -} - -int llhttp__internal__c_update_finish_1( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->finish = 0; - return 0; -} - -int llhttp__internal__c_test_lenient_flags_2( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 4) == 4; -} - -int llhttp__internal__c_test_lenient_flags_3( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 32) == 32; -} - -int llhttp__before_headers_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_headers_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__after_headers_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_mul_add_content_length( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp, - int match) { - /* Multiplication overflow */ - if (state->content_length > 0xffffffffffffffffULL / 16) { - return 1; - } - - state->content_length *= 16; - - /* Addition overflow */ - if (match >= 0) { - if (state->content_length > 0xffffffffffffffffULL - match) { - return 1; - } - } else { - if (state->content_length < 0ULL - match) { - return 1; - } - } - state->content_length += match; - return 0; -} - -int llhttp__internal__c_test_lenient_flags_4( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 512) == 512; -} - -int llhttp__on_chunk_header( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_is_equal_content_length( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->content_length == 0; -} - -int llhttp__internal__c_test_lenient_flags_7( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 128) == 128; -} - -int llhttp__internal__c_or_flags( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 128; - return 0; -} - -int llhttp__internal__c_test_lenient_flags_8( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 64) == 64; -} - -int llhttp__on_chunk_extension_name_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_chunk_extension_value_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_update_finish_3( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->finish = 1; - return 0; -} - -int llhttp__internal__c_or_flags_1( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 64; - return 0; -} - -int llhttp__internal__c_update_upgrade( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->upgrade = 1; - return 0; -} - -int llhttp__internal__c_store_header_state( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp, - int match) { - state->header_state = match; - return 0; -} - -int llhttp__on_header_field_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_load_header_state( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->header_state; -} - -int llhttp__internal__c_test_flags_4( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->flags & 512) == 512; -} - -int llhttp__internal__c_test_lenient_flags_22( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 2) == 2; -} - -int llhttp__internal__c_or_flags_5( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 1; - return 0; -} - -int llhttp__internal__c_update_header_state( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->header_state = 1; - return 0; -} - -int llhttp__on_header_value_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_or_flags_6( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 2; - return 0; -} - -int llhttp__internal__c_or_flags_7( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 4; - return 0; -} - -int llhttp__internal__c_or_flags_8( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 8; - return 0; -} - -int llhttp__internal__c_update_header_state_3( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->header_state = 6; - return 0; -} - -int llhttp__internal__c_update_header_state_1( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->header_state = 0; - return 0; -} - -int llhttp__internal__c_update_header_state_6( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->header_state = 5; - return 0; -} - -int llhttp__internal__c_update_header_state_7( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->header_state = 7; - return 0; -} - -int llhttp__internal__c_test_flags_2( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->flags & 32) == 32; -} - -int llhttp__internal__c_mul_add_content_length_1( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp, - int match) { - /* Multiplication overflow */ - if (state->content_length > 0xffffffffffffffffULL / 10) { - return 1; - } - - state->content_length *= 10; - - /* Addition overflow */ - if (match >= 0) { - if (state->content_length > 0xffffffffffffffffULL - match) { - return 1; - } - } else { - if (state->content_length < 0ULL - match) { - return 1; - } - } - state->content_length += match; - return 0; -} - -int llhttp__internal__c_or_flags_17( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 32; - return 0; -} - -int llhttp__internal__c_test_flags_3( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->flags & 8) == 8; -} - -int llhttp__internal__c_test_lenient_flags_20( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 8) == 8; -} - -int llhttp__internal__c_or_flags_18( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 512; - return 0; -} - -int llhttp__internal__c_and_flags( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags &= -9; - return 0; -} - -int llhttp__internal__c_update_header_state_8( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->header_state = 8; - return 0; -} - -int llhttp__internal__c_or_flags_20( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->flags |= 16; - return 0; -} - -int llhttp__internal__c_load_method( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->method; -} - -int llhttp__internal__c_store_http_major( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp, - int match) { - state->http_major = match; - return 0; -} - -int llhttp__internal__c_store_http_minor( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp, - int match) { - state->http_minor = match; - return 0; -} - -int llhttp__internal__c_test_lenient_flags_24( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 16) == 16; -} - -int llhttp__on_version_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_load_http_major( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->http_major; -} - -int llhttp__internal__c_load_http_minor( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->http_minor; -} - -int llhttp__internal__c_update_status_code( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->status_code = 0; - return 0; -} - -int llhttp__internal__c_mul_add_status_code( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp, - int match) { - /* Multiplication overflow */ - if (state->status_code > 0xffff / 10) { - return 1; - } - - state->status_code *= 10; - - /* Addition overflow */ - if (match >= 0) { - if (state->status_code > 0xffff - match) { - return 1; - } - } else { - if (state->status_code < 0 - match) { - return 1; - } - } - state->status_code += match; - return 0; -} - -int llhttp__on_status_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_update_type( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->type = 1; - return 0; -} - -int llhttp__internal__c_update_type_1( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - state->type = 2; - return 0; -} - -int llhttp__internal_init(llhttp__internal_t* state) { - memset(state, 0, sizeof(*state)); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_start; - return 0; -} - -static llparse_state_t llhttp__internal__run( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - int match; - switch ((llparse_state_t) (intptr_t) state->_current) { - case s_n_llhttp__internal__n_closed: - s_n_llhttp__internal__n_closed: { - if (p == endp) { - return s_n_llhttp__internal__n_closed; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_closed; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_closed; - } - default: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_3; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__after_message_complete: - s_n_llhttp__internal__n_invoke_llhttp__after_message_complete: { - switch (llhttp__after_message_complete(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_update_content_length; - default: - goto s_n_llhttp__internal__n_invoke_update_finish_1; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_pause_1: - s_n_llhttp__internal__n_pause_1: { - state->error = 0x16; - state->reason = "Pause on CONNECT/Upgrade"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__after_message_complete; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_is_equal_upgrade: - s_n_llhttp__internal__n_invoke_is_equal_upgrade: { - switch (llhttp__internal__c_is_equal_upgrade(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__after_message_complete; - default: - goto s_n_llhttp__internal__n_pause_1; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: - s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: { - switch (llhttp__on_message_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_is_equal_upgrade; - case 21: - goto s_n_llhttp__internal__n_pause_13; - default: - goto s_n_llhttp__internal__n_error_38; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_data_almost_done_1: - s_n_llhttp__internal__n_chunk_data_almost_done_1: { - if (p == endp) { - return s_n_llhttp__internal__n_chunk_data_almost_done_1; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; - } - default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_7; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_data_almost_done: - s_n_llhttp__internal__n_chunk_data_almost_done: { - if (p == endp) { - return s_n_llhttp__internal__n_chunk_data_almost_done; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_6; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_chunk_data_almost_done_1; - } - default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_7; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_consume_content_length: - s_n_llhttp__internal__n_consume_content_length: { - size_t avail; - uint64_t need; - - avail = endp - p; - need = state->content_length; - if (avail >= need) { - p += need; - state->content_length = 0; - goto s_n_llhttp__internal__n_span_end_llhttp__on_body; - } - - state->content_length -= avail; - return s_n_llhttp__internal__n_consume_content_length; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_body: - s_n_llhttp__internal__n_span_start_llhttp__on_body: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_body; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_body; - goto s_n_llhttp__internal__n_consume_content_length; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_is_equal_content_length: - s_n_llhttp__internal__n_invoke_is_equal_content_length: { - switch (llhttp__internal__c_is_equal_content_length(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_span_start_llhttp__on_body; - default: - goto s_n_llhttp__internal__n_invoke_or_flags; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_size_almost_done: - s_n_llhttp__internal__n_chunk_size_almost_done: { - if (p == endp) { - return s_n_llhttp__internal__n_chunk_size_almost_done; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_header; - } - default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_8; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_test_lenient_flags_9: - s_n_llhttp__internal__n_invoke_test_lenient_flags_9: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_chunk_size_almost_done; - default: - goto s_n_llhttp__internal__n_error_20; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete: { - switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_9; - case 21: - goto s_n_llhttp__internal__n_pause_5; - default: - goto s_n_llhttp__internal__n_error_19; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1: { - switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_chunk_size_almost_done; - case 21: - goto s_n_llhttp__internal__n_pause_6; - default: - goto s_n_llhttp__internal__n_error_21; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2: { - switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_chunk_extensions; - case 21: - goto s_n_llhttp__internal__n_pause_7; - default: - goto s_n_llhttp__internal__n_error_22; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_test_lenient_flags_10: - s_n_llhttp__internal__n_invoke_test_lenient_flags_10: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_chunk_size_almost_done; - default: - goto s_n_llhttp__internal__n_error_25; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete: { - switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_10; - case 21: - goto s_n_llhttp__internal__n_pause_8; - default: - goto s_n_llhttp__internal__n_error_24; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: { - switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_chunk_size_almost_done; - case 21: - goto s_n_llhttp__internal__n_pause_9; - default: - goto s_n_llhttp__internal__n_error_26; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_extension_quoted_value_done: - s_n_llhttp__internal__n_chunk_extension_quoted_value_done: { - if (p == endp) { - return s_n_llhttp__internal__n_chunk_extension_quoted_value_done; - } - switch (*p) { - case 10: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_11; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_chunk_size_almost_done; - } - case ';': { - p++; - goto s_n_llhttp__internal__n_chunk_extensions; - } - default: { - goto s_n_llhttp__internal__n_error_29; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: { - switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_chunk_extension_quoted_value_done; - case 21: - goto s_n_llhttp__internal__n_pause_10; - default: - goto s_n_llhttp__internal__n_error_27; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_30: - s_n_llhttp__internal__n_error_30: { - state->error = 0x2; - state->reason = "Invalid quoted-pair in chunk extensions quoted value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair: - s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - }; - if (p == endp) { - return s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_quoted_value; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_3; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_31: - s_n_llhttp__internal__n_error_31: { - state->error = 0x2; - state->reason = "Invalid character in chunk extensions quoted value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_extension_quoted_value: - s_n_llhttp__internal__n_chunk_extension_quoted_value: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - }; - if (p == endp) { - return s_n_llhttp__internal__n_chunk_extension_quoted_value; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_quoted_value; - } - case 2: { - p++; - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_2; - } - case 3: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_4; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3: { - switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_chunk_extensions; - case 21: - goto s_n_llhttp__internal__n_pause_11; - default: - goto s_n_llhttp__internal__n_error_32; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_33: - s_n_llhttp__internal__n_error_33: { - state->error = 0x2; - state->reason = "Invalid character in chunk extensions value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_extension_value: - s_n_llhttp__internal__n_chunk_extension_value: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 3, 4, 3, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3, 0, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 5, 0, 0, 0, 0, - 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_chunk_extension_value; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value; - } - case 2: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_1; - } - case 3: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_value; - } - case 4: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_quoted_value; - } - case 5: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_5; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_6; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_value: - s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_value: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_value; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_chunk_extension_value; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_3; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_34: - s_n_llhttp__internal__n_error_34: { - state->error = 0x2; - state->reason = "Invalid character in chunk extensions name"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_extension_name: - s_n_llhttp__internal__n_chunk_extension_name: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 3, 0, 3, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3, 0, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 4, 0, 5, 0, 0, - 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_chunk_extension_name; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name; - } - case 2: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_1; - } - case 3: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_name; - } - case 4: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_2; - } - case 5: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_3; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_4; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name: - s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_chunk_extension_name; - goto s_n_llhttp__internal__n_chunk_extension_name; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_extensions: - s_n_llhttp__internal__n_chunk_extensions: { - if (p == endp) { - return s_n_llhttp__internal__n_chunk_extensions; - } - switch (*p) { - case 13: { - p++; - goto s_n_llhttp__internal__n_error_17; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_error_18; - } - default: { - goto s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_size_otherwise: - s_n_llhttp__internal__n_chunk_size_otherwise: { - if (p == endp) { - return s_n_llhttp__internal__n_chunk_size_otherwise; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_4; - } - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_5; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_chunk_size_almost_done; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_4; - } - case ';': { - p++; - goto s_n_llhttp__internal__n_chunk_extensions; - } - default: { - goto s_n_llhttp__internal__n_error_35; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_size: - s_n_llhttp__internal__n_chunk_size: { - if (p == endp) { - return s_n_llhttp__internal__n_chunk_size; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'A': { - p++; - match = 10; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'B': { - p++; - match = 11; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'C': { - p++; - match = 12; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'D': { - p++; - match = 13; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'E': { - p++; - match = 14; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'F': { - p++; - match = 15; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'a': { - p++; - match = 10; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'b': { - p++; - match = 11; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'c': { - p++; - match = 12; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'd': { - p++; - match = 13; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'e': { - p++; - match = 14; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'f': { - p++; - match = 15; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - default: { - goto s_n_llhttp__internal__n_chunk_size_otherwise; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_chunk_size_digit: - s_n_llhttp__internal__n_chunk_size_digit: { - if (p == endp) { - return s_n_llhttp__internal__n_chunk_size_digit; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'A': { - p++; - match = 10; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'B': { - p++; - match = 11; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'C': { - p++; - match = 12; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'D': { - p++; - match = 13; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'E': { - p++; - match = 14; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'F': { - p++; - match = 15; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'a': { - p++; - match = 10; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'b': { - p++; - match = 11; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'c': { - p++; - match = 12; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'd': { - p++; - match = 13; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'e': { - p++; - match = 14; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - case 'f': { - p++; - match = 15; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length; - } - default: { - goto s_n_llhttp__internal__n_error_37; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_update_content_length_1: - s_n_llhttp__internal__n_invoke_update_content_length_1: { - switch (llhttp__internal__c_update_content_length(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_chunk_size_digit; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_consume_content_length_1: - s_n_llhttp__internal__n_consume_content_length_1: { - size_t avail; - uint64_t need; - - avail = endp - p; - need = state->content_length; - if (avail >= need) { - p += need; - state->content_length = 0; - goto s_n_llhttp__internal__n_span_end_llhttp__on_body_1; - } - - state->content_length -= avail; - return s_n_llhttp__internal__n_consume_content_length_1; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_body_1: - s_n_llhttp__internal__n_span_start_llhttp__on_body_1: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_body_1; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_body; - goto s_n_llhttp__internal__n_consume_content_length_1; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_eof: - s_n_llhttp__internal__n_eof: { - if (p == endp) { - return s_n_llhttp__internal__n_eof; - } - p++; - goto s_n_llhttp__internal__n_eof; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_body_2: - s_n_llhttp__internal__n_span_start_llhttp__on_body_2: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_body_2; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_body; - goto s_n_llhttp__internal__n_eof; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete: - s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete: { - switch (llhttp__after_headers_complete(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_1; - case 2: - goto s_n_llhttp__internal__n_invoke_update_content_length_1; - case 3: - goto s_n_llhttp__internal__n_span_start_llhttp__on_body_1; - case 4: - goto s_n_llhttp__internal__n_invoke_update_finish_3; - case 5: - goto s_n_llhttp__internal__n_error_39; - default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_5: - s_n_llhttp__internal__n_error_5: { - state->error = 0xa; - state->reason = "Invalid header field char"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_headers_almost_done: - s_n_llhttp__internal__n_headers_almost_done: { - if (p == endp) { - return s_n_llhttp__internal__n_headers_almost_done; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_test_flags_1; - } - default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_12; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_colon_discard_ws: - s_n_llhttp__internal__n_header_field_colon_discard_ws: { - if (p == endp) { - return s_n_llhttp__internal__n_header_field_colon_discard_ws; - } - switch (*p) { - case ' ': { - p++; - goto s_n_llhttp__internal__n_header_field_colon_discard_ws; - } - default: { - goto s_n_llhttp__internal__n_header_field_colon; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete: - s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete: { - switch (llhttp__on_header_value_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_header_field_start; - case 21: - goto s_n_llhttp__internal__n_pause_18; - default: - goto s_n_llhttp__internal__n_error_48; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_header_value: - s_n_llhttp__internal__n_span_start_llhttp__on_header_value: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_header_value; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_header_value; - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_discard_lws: - s_n_llhttp__internal__n_header_value_discard_lws: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_discard_lws; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_15; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_15; - } - default: { - goto s_n_llhttp__internal__n_invoke_load_header_state_1; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_discard_ws_almost_done: - s_n_llhttp__internal__n_header_value_discard_ws_almost_done: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_discard_ws_almost_done; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_header_value_discard_lws; - } - default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_16; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_lws: - s_n_llhttp__internal__n_header_value_lws: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_lws; - } - switch (*p) { - case 9: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_18; - } - case ' ': { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_18; - } - default: { - goto s_n_llhttp__internal__n_invoke_load_header_state_5; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_almost_done: - s_n_llhttp__internal__n_header_value_almost_done: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_almost_done; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_header_value_lws; - } - default: { - goto s_n_llhttp__internal__n_error_53; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_test_lenient_flags_17: - s_n_llhttp__internal__n_invoke_test_lenient_flags_17: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_header_value_almost_done; - default: - goto s_n_llhttp__internal__n_error_51; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_lenient: - s_n_llhttp__internal__n_header_value_lenient: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_lenient; - } - switch (*p) { - case 10: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4; - } - case 13: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5; - } - default: { - p++; - goto s_n_llhttp__internal__n_header_value_lenient; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_54: - s_n_llhttp__internal__n_error_54: { - state->error = 0xa; - state->reason = "Invalid header value char"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_otherwise: - s_n_llhttp__internal__n_header_value_otherwise: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_otherwise; - } - switch (*p) { - case 10: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_1; - } - case 13: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2; - } - default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_19; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_connection_token: - s_n_llhttp__internal__n_header_value_connection_token: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - }; - if (p == endp) { - return s_n_llhttp__internal__n_header_value_connection_token; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_header_value_connection_token; - } - case 2: { - p++; - goto s_n_llhttp__internal__n_header_value_connection; - } - default: { - goto s_n_llhttp__internal__n_header_value_otherwise; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_connection_ws: - s_n_llhttp__internal__n_header_value_connection_ws: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_connection_ws; - } - switch (*p) { - case 10: { - goto s_n_llhttp__internal__n_header_value_otherwise; - } - case 13: { - goto s_n_llhttp__internal__n_header_value_otherwise; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_header_value_connection_ws; - } - case ',': { - p++; - goto s_n_llhttp__internal__n_invoke_load_header_state_6; - } - default: { - goto s_n_llhttp__internal__n_invoke_update_header_state_5; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_connection_1: - s_n_llhttp__internal__n_header_value_connection_1: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_value_connection_1; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob2, 4); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_invoke_update_header_state_3; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_value_connection_1; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_header_value_connection_token; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_connection_2: - s_n_llhttp__internal__n_header_value_connection_2: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_value_connection_2; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob3, 9); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_invoke_update_header_state_6; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_value_connection_2; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_header_value_connection_token; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_connection_3: - s_n_llhttp__internal__n_header_value_connection_3: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_value_connection_3; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob4, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_invoke_update_header_state_7; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_value_connection_3; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_header_value_connection_token; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_connection: - s_n_llhttp__internal__n_header_value_connection: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_connection; - } - switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) { - case 9: { - p++; - goto s_n_llhttp__internal__n_header_value_connection; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_header_value_connection; - } - case 'c': { - p++; - goto s_n_llhttp__internal__n_header_value_connection_1; - } - case 'k': { - p++; - goto s_n_llhttp__internal__n_header_value_connection_2; - } - case 'u': { - p++; - goto s_n_llhttp__internal__n_header_value_connection_3; - } - default: { - goto s_n_llhttp__internal__n_header_value_connection_token; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_56: - s_n_llhttp__internal__n_error_56: { - state->error = 0xb; - state->reason = "Content-Length overflow"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_57: - s_n_llhttp__internal__n_error_57: { - state->error = 0xb; - state->reason = "Invalid character in Content-Length"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_content_length_ws: - s_n_llhttp__internal__n_header_value_content_length_ws: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_content_length_ws; - } - switch (*p) { - case 10: { - goto s_n_llhttp__internal__n_invoke_or_flags_17; - } - case 13: { - goto s_n_llhttp__internal__n_invoke_or_flags_17; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_header_value_content_length_ws; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_7; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_content_length: - s_n_llhttp__internal__n_header_value_content_length: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_content_length; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_mul_add_content_length_1; - } - default: { - goto s_n_llhttp__internal__n_header_value_content_length_ws; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_59: - s_n_llhttp__internal__n_error_59: { - state->error = 0xf; - state->reason = "Invalid `Transfer-Encoding` header value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_58: - s_n_llhttp__internal__n_error_58: { - state->error = 0xf; - state->reason = "Invalid `Transfer-Encoding` header value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_te_token_ows: - s_n_llhttp__internal__n_header_value_te_token_ows: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_te_token_ows; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_header_value_te_token_ows; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_header_value_te_token_ows; - } - default: { - goto s_n_llhttp__internal__n_header_value_te_chunked; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value: - s_n_llhttp__internal__n_header_value: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - }; - if (p == endp) { - return s_n_llhttp__internal__n_header_value; - } - #ifdef __SSE4_2__ - if (endp - p >= 16) { - __m128i ranges; - __m128i input; - int avail; - int match_len; - - /* Load input */ - input = _mm_loadu_si128((__m128i const*) p); - ranges = _mm_loadu_si128((__m128i const*) llparse_blob6); - - /* Find first character that does not match `ranges` */ - match_len = _mm_cmpestri(ranges, 6, - input, 16, - _SIDD_UBYTE_OPS | _SIDD_CMP_RANGES | - _SIDD_NEGATIVE_POLARITY); - - if (match_len != 0) { - p += match_len; - goto s_n_llhttp__internal__n_header_value; - } - goto s_n_llhttp__internal__n_header_value_otherwise; - } - #endif /* __SSE4_2__ */ - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_header_value; - } - default: { - goto s_n_llhttp__internal__n_header_value_otherwise; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_te_token: - s_n_llhttp__internal__n_header_value_te_token: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - }; - if (p == endp) { - return s_n_llhttp__internal__n_header_value_te_token; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_header_value_te_token; - } - case 2: { - p++; - goto s_n_llhttp__internal__n_header_value_te_token_ows; - } - default: { - goto s_n_llhttp__internal__n_invoke_update_header_state_9; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_te_chunked_last: - s_n_llhttp__internal__n_header_value_te_chunked_last: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_te_chunked_last; - } - switch (*p) { - case 10: { - goto s_n_llhttp__internal__n_invoke_update_header_state_8; - } - case 13: { - goto s_n_llhttp__internal__n_invoke_update_header_state_8; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_header_value_te_chunked_last; - } - case ',': { - goto s_n_llhttp__internal__n_invoke_load_type_1; - } - default: { - goto s_n_llhttp__internal__n_header_value_te_token; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_te_chunked: - s_n_llhttp__internal__n_header_value_te_chunked: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_value_te_chunked; - } - match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob5, 7); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_header_value_te_chunked_last; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_value_te_chunked; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_header_value_te_token; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1: - s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_header_value; - goto s_n_llhttp__internal__n_invoke_load_header_state_3; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_value_discard_ws: - s_n_llhttp__internal__n_header_value_discard_ws: { - if (p == endp) { - return s_n_llhttp__internal__n_header_value_discard_ws; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_header_value_discard_ws; - } - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_14; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_header_value_discard_ws_almost_done; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_header_value_discard_ws; - } - default: { - goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_load_header_state: - s_n_llhttp__internal__n_invoke_load_header_state: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 2: - goto s_n_llhttp__internal__n_invoke_test_flags_4; - case 3: - goto s_n_llhttp__internal__n_invoke_test_flags_5; - default: - goto s_n_llhttp__internal__n_header_value_discard_ws; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete: - s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete: { - switch (llhttp__on_header_field_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_load_header_state; - case 21: - goto s_n_llhttp__internal__n_pause_19; - default: - goto s_n_llhttp__internal__n_error_45; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_general_otherwise: - s_n_llhttp__internal__n_header_field_general_otherwise: { - if (p == endp) { - return s_n_llhttp__internal__n_header_field_general_otherwise; - } - switch (*p) { - case ':': { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_field_2; - } - default: { - goto s_n_llhttp__internal__n_error_62; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_general: - s_n_llhttp__internal__n_header_field_general: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_header_field_general; - } - #ifdef __SSE4_2__ - if (endp - p >= 16) { - __m128i ranges; - __m128i input; - int avail; - int match_len; - - /* Load input */ - input = _mm_loadu_si128((__m128i const*) p); - ranges = _mm_loadu_si128((__m128i const*) llparse_blob7); - - /* Find first character that does not match `ranges` */ - match_len = _mm_cmpestri(ranges, 16, - input, 16, - _SIDD_UBYTE_OPS | _SIDD_CMP_RANGES | - _SIDD_NEGATIVE_POLARITY); - - if (match_len != 0) { - p += match_len; - goto s_n_llhttp__internal__n_header_field_general; - } - ranges = _mm_loadu_si128((__m128i const*) llparse_blob8); - - /* Find first character that does not match `ranges` */ - match_len = _mm_cmpestri(ranges, 2, - input, 16, - _SIDD_UBYTE_OPS | _SIDD_CMP_RANGES | - _SIDD_NEGATIVE_POLARITY); - - if (match_len != 0) { - p += match_len; - goto s_n_llhttp__internal__n_header_field_general; - } - goto s_n_llhttp__internal__n_header_field_general_otherwise; - } - #endif /* __SSE4_2__ */ - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_header_field_general; - } - default: { - goto s_n_llhttp__internal__n_header_field_general_otherwise; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_colon: - s_n_llhttp__internal__n_header_field_colon: { - if (p == endp) { - return s_n_llhttp__internal__n_header_field_colon; - } - switch (*p) { - case ' ': { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_13; - } - case ':': { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_field_1; - } - default: { - goto s_n_llhttp__internal__n_invoke_update_header_state_10; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_3: - s_n_llhttp__internal__n_header_field_3: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_field_3; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob1, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_store_header_state; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_field_3; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_invoke_update_header_state_11; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_4: - s_n_llhttp__internal__n_header_field_4: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_field_4; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob9, 10); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_store_header_state; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_field_4; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_invoke_update_header_state_11; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_2: - s_n_llhttp__internal__n_header_field_2: { - if (p == endp) { - return s_n_llhttp__internal__n_header_field_2; - } - switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) { - case 'n': { - p++; - goto s_n_llhttp__internal__n_header_field_3; - } - case 't': { - p++; - goto s_n_llhttp__internal__n_header_field_4; - } - default: { - goto s_n_llhttp__internal__n_invoke_update_header_state_11; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_1: - s_n_llhttp__internal__n_header_field_1: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_field_1; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob0, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_header_field_2; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_field_1; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_invoke_update_header_state_11; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_5: - s_n_llhttp__internal__n_header_field_5: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_field_5; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob10, 15); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_store_header_state; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_field_5; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_invoke_update_header_state_11; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_6: - s_n_llhttp__internal__n_header_field_6: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_field_6; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob11, 16); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_store_header_state; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_field_6; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_invoke_update_header_state_11; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_7: - s_n_llhttp__internal__n_header_field_7: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_header_field_7; - } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob12, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_store_header_state; - } - case kMatchPause: { - return s_n_llhttp__internal__n_header_field_7; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_invoke_update_header_state_11; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field: - s_n_llhttp__internal__n_header_field: { - if (p == endp) { - return s_n_llhttp__internal__n_header_field; - } - switch (((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p))) { - case 'c': { - p++; - goto s_n_llhttp__internal__n_header_field_1; - } - case 'p': { - p++; - goto s_n_llhttp__internal__n_header_field_5; - } - case 't': { - p++; - goto s_n_llhttp__internal__n_header_field_6; - } - case 'u': { - p++; - goto s_n_llhttp__internal__n_header_field_7; - } - default: { - goto s_n_llhttp__internal__n_invoke_update_header_state_11; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_header_field: - s_n_llhttp__internal__n_span_start_llhttp__on_header_field: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_header_field; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_header_field; - goto s_n_llhttp__internal__n_header_field; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_header_field_start: - s_n_llhttp__internal__n_header_field_start: { - if (p == endp) { - return s_n_llhttp__internal__n_header_field_start; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_headers_almost_done; - } - case ':': { - goto s_n_llhttp__internal__n_error_44; - } - default: { - goto s_n_llhttp__internal__n_span_start_llhttp__on_header_field; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_headers_start: - s_n_llhttp__internal__n_headers_start: { - if (p == endp) { - return s_n_llhttp__internal__n_headers_start; - } - switch (*p) { - case ' ': { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags; - } - default: { - goto s_n_llhttp__internal__n_header_field_start; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_to_http_09: - s_n_llhttp__internal__n_url_to_http_09: { - if (p == endp) { - return s_n_llhttp__internal__n_url_to_http_09; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - default: { - goto s_n_llhttp__internal__n_invoke_update_http_major; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_skip_to_http09: - s_n_llhttp__internal__n_url_skip_to_http09: { - if (p == endp) { - return s_n_llhttp__internal__n_url_skip_to_http09; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - default: { - p++; - goto s_n_llhttp__internal__n_url_to_http_09; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_skip_lf_to_http09_1: - s_n_llhttp__internal__n_url_skip_lf_to_http09_1: { - if (p == endp) { - return s_n_llhttp__internal__n_url_skip_lf_to_http09_1; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_url_to_http_09; - } - default: { - goto s_n_llhttp__internal__n_error_63; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_skip_lf_to_http09: - s_n_llhttp__internal__n_url_skip_lf_to_http09: { - if (p == endp) { - return s_n_llhttp__internal__n_url_skip_lf_to_http09; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_url_skip_lf_to_http09_1; - } - default: { - goto s_n_llhttp__internal__n_error_63; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_pri_upgrade: - s_n_llhttp__internal__n_req_pri_upgrade: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_req_pri_upgrade; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob14, 10); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_error_71; - } - case kMatchPause: { - return s_n_llhttp__internal__n_req_pri_upgrade; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_72; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_complete_crlf: - s_n_llhttp__internal__n_req_http_complete_crlf: { - if (p == endp) { - return s_n_llhttp__internal__n_req_http_complete_crlf; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_headers_start; - } - default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_26; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_complete: - s_n_llhttp__internal__n_req_http_complete: { - if (p == endp) { - return s_n_llhttp__internal__n_req_http_complete; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_25; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_req_http_complete_crlf; - } - default: { - goto s_n_llhttp__internal__n_error_70; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_load_method_1: - s_n_llhttp__internal__n_invoke_load_method_1: { - switch (llhttp__internal__c_load_method(state, p, endp)) { - case 34: - goto s_n_llhttp__internal__n_req_pri_upgrade; - default: - goto s_n_llhttp__internal__n_req_http_complete; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_version_complete: - s_n_llhttp__internal__n_invoke_llhttp__on_version_complete: { - switch (llhttp__on_version_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_load_method_1; - case 21: - goto s_n_llhttp__internal__n_pause_21; - default: - goto s_n_llhttp__internal__n_error_67; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_66: - s_n_llhttp__internal__n_error_66: { - state->error = 0x9; - state->reason = "Invalid HTTP version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_73: - s_n_llhttp__internal__n_error_73: { - state->error = 0x9; - state->reason = "Invalid minor version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_minor: - s_n_llhttp__internal__n_req_http_minor: { - if (p == endp) { - return s_n_llhttp__internal__n_req_http_minor; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_store_http_minor; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_2; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_74: - s_n_llhttp__internal__n_error_74: { - state->error = 0x9; - state->reason = "Expected dot"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_dot: - s_n_llhttp__internal__n_req_http_dot: { - if (p == endp) { - return s_n_llhttp__internal__n_req_http_dot; - } - switch (*p) { - case '.': { - p++; - goto s_n_llhttp__internal__n_req_http_minor; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_3; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_75: - s_n_llhttp__internal__n_error_75: { - state->error = 0x9; - state->reason = "Invalid major version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_major: - s_n_llhttp__internal__n_req_http_major: { - if (p == endp) { - return s_n_llhttp__internal__n_req_http_major; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_store_http_major; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_4; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_version: - s_n_llhttp__internal__n_span_start_llhttp__on_version: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_version; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_version; - goto s_n_llhttp__internal__n_req_http_major; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_start_1: - s_n_llhttp__internal__n_req_http_start_1: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_req_http_start_1; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob13, 4); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_invoke_load_method; - } - case kMatchPause: { - return s_n_llhttp__internal__n_req_http_start_1; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_78; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_start_2: - s_n_llhttp__internal__n_req_http_start_2: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_req_http_start_2; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob15, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_invoke_load_method_2; - } - case kMatchPause: { - return s_n_llhttp__internal__n_req_http_start_2; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_78; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_start_3: - s_n_llhttp__internal__n_req_http_start_3: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_req_http_start_3; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob16, 4); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_invoke_load_method_3; - } - case kMatchPause: { - return s_n_llhttp__internal__n_req_http_start_3; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_78; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_http_start: - s_n_llhttp__internal__n_req_http_start: { - if (p == endp) { - return s_n_llhttp__internal__n_req_http_start; - } - switch (*p) { - case ' ': { - p++; - goto s_n_llhttp__internal__n_req_http_start; - } - case 'H': { - p++; - goto s_n_llhttp__internal__n_req_http_start_1; - } - case 'I': { - p++; - goto s_n_llhttp__internal__n_req_http_start_2; - } - case 'R': { - p++; - goto s_n_llhttp__internal__n_req_http_start_3; - } - default: { - goto s_n_llhttp__internal__n_error_78; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_to_http: - s_n_llhttp__internal__n_url_to_http: { - if (p == endp) { - return s_n_llhttp__internal__n_url_to_http; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - default: { - goto s_n_llhttp__internal__n_invoke_llhttp__on_url_complete_1; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_skip_to_http: - s_n_llhttp__internal__n_url_skip_to_http: { - if (p == endp) { - return s_n_llhttp__internal__n_url_skip_to_http; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - default: { - p++; - goto s_n_llhttp__internal__n_url_to_http; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_fragment: - s_n_llhttp__internal__n_url_fragment: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 3, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_url_fragment; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 2: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_6; - } - case 3: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_7; - } - case 4: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_8; - } - case 5: { - p++; - goto s_n_llhttp__internal__n_url_fragment; - } - default: { - goto s_n_llhttp__internal__n_error_79; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_end_stub_query_3: - s_n_llhttp__internal__n_span_end_stub_query_3: { - if (p == endp) { - return s_n_llhttp__internal__n_span_end_stub_query_3; - } - p++; - goto s_n_llhttp__internal__n_url_fragment; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_query: - s_n_llhttp__internal__n_url_query: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 3, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 4, 5, 5, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_url_query; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 2: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_9; - } - case 3: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_10; - } - case 4: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_11; - } - case 5: { - p++; - goto s_n_llhttp__internal__n_url_query; - } - case 6: { - goto s_n_llhttp__internal__n_span_end_stub_query_3; - } - default: { - goto s_n_llhttp__internal__n_error_80; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_query_or_fragment: - s_n_llhttp__internal__n_url_query_or_fragment: { - if (p == endp) { - return s_n_llhttp__internal__n_url_query_or_fragment; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 10: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_3; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 13: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_4; - } - case ' ': { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_5; - } - case '#': { - p++; - goto s_n_llhttp__internal__n_url_fragment; - } - case '?': { - p++; - goto s_n_llhttp__internal__n_url_query; - } - default: { - goto s_n_llhttp__internal__n_error_81; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_path: - s_n_llhttp__internal__n_url_path: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_url_path; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 2: { - p++; - goto s_n_llhttp__internal__n_url_path; - } - default: { - goto s_n_llhttp__internal__n_url_query_or_fragment; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_stub_path_2: - s_n_llhttp__internal__n_span_start_stub_path_2: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_stub_path_2; - } - p++; - goto s_n_llhttp__internal__n_url_path; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_stub_path: - s_n_llhttp__internal__n_span_start_stub_path: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_stub_path; - } - p++; - goto s_n_llhttp__internal__n_url_path; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_stub_path_1: - s_n_llhttp__internal__n_span_start_stub_path_1: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_stub_path_1; - } - p++; - goto s_n_llhttp__internal__n_url_path; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_server_with_at: - s_n_llhttp__internal__n_url_server_with_at: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 3, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 4, 5, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 0, 7, - 8, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 0, 5, - 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_url_server_with_at; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 2: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_12; - } - case 3: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_13; - } - case 4: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_14; - } - case 5: { - p++; - goto s_n_llhttp__internal__n_url_server; - } - case 6: { - goto s_n_llhttp__internal__n_span_start_stub_path_1; - } - case 7: { - p++; - goto s_n_llhttp__internal__n_url_query; - } - case 8: { - p++; - goto s_n_llhttp__internal__n_error_82; - } - default: { - goto s_n_llhttp__internal__n_error_83; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_server: - s_n_llhttp__internal__n_url_server: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 3, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 4, 5, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 0, 7, - 8, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 0, 5, - 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_url_server; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 2: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url; - } - case 3: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_1; - } - case 4: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_url_2; - } - case 5: { - p++; - goto s_n_llhttp__internal__n_url_server; - } - case 6: { - goto s_n_llhttp__internal__n_span_start_stub_path; - } - case 7: { - p++; - goto s_n_llhttp__internal__n_url_query; - } - case 8: { - p++; - goto s_n_llhttp__internal__n_url_server_with_at; - } - default: { - goto s_n_llhttp__internal__n_error_84; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_schema_delim_1: - s_n_llhttp__internal__n_url_schema_delim_1: { - if (p == endp) { - return s_n_llhttp__internal__n_url_schema_delim_1; - } - switch (*p) { - case '/': { - p++; - goto s_n_llhttp__internal__n_url_server; - } - default: { - goto s_n_llhttp__internal__n_error_85; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_schema_delim: - s_n_llhttp__internal__n_url_schema_delim: { - if (p == endp) { - return s_n_llhttp__internal__n_url_schema_delim; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 10: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case '/': { - p++; - goto s_n_llhttp__internal__n_url_schema_delim_1; - } - default: { - goto s_n_llhttp__internal__n_error_85; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_end_stub_schema: - s_n_llhttp__internal__n_span_end_stub_schema: { - if (p == endp) { - return s_n_llhttp__internal__n_span_end_stub_schema; - } - p++; - goto s_n_llhttp__internal__n_url_schema_delim; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_schema: - s_n_llhttp__internal__n_url_schema: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, - 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, - 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_url_schema; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 2: { - goto s_n_llhttp__internal__n_span_end_stub_schema; - } - case 3: { - p++; - goto s_n_llhttp__internal__n_url_schema; - } - default: { - goto s_n_llhttp__internal__n_error_86; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_start: - s_n_llhttp__internal__n_url_start: { - static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, - 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (p == endp) { - return s_n_llhttp__internal__n_url_start; - } - switch (lookup_table[(uint8_t) *p]) { - case 1: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 2: { - goto s_n_llhttp__internal__n_span_start_stub_path_2; - } - case 3: { - goto s_n_llhttp__internal__n_url_schema; - } - default: { - goto s_n_llhttp__internal__n_error_87; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_url_1: - s_n_llhttp__internal__n_span_start_llhttp__on_url_1: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_url_1; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_url; - goto s_n_llhttp__internal__n_url_start; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_entry_normal: - s_n_llhttp__internal__n_url_entry_normal: { - if (p == endp) { - return s_n_llhttp__internal__n_url_entry_normal; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - default: { - goto s_n_llhttp__internal__n_span_start_llhttp__on_url_1; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_url: - s_n_llhttp__internal__n_span_start_llhttp__on_url: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_url; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_url; - goto s_n_llhttp__internal__n_url_server; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_url_entry_connect: - s_n_llhttp__internal__n_url_entry_connect: { - if (p == endp) { - return s_n_llhttp__internal__n_url_entry_connect; - } - switch (*p) { - case 9: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - case 12: { - p++; - goto s_n_llhttp__internal__n_error_2; - } - default: { - goto s_n_llhttp__internal__n_span_start_llhttp__on_url; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_spaces_before_url: - s_n_llhttp__internal__n_req_spaces_before_url: { - if (p == endp) { - return s_n_llhttp__internal__n_req_spaces_before_url; - } - switch (*p) { - case ' ': { - p++; - goto s_n_llhttp__internal__n_req_spaces_before_url; - } - default: { - goto s_n_llhttp__internal__n_invoke_is_equal_method; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_first_space_before_url: - s_n_llhttp__internal__n_req_first_space_before_url: { - if (p == endp) { - return s_n_llhttp__internal__n_req_first_space_before_url; - } - switch (*p) { - case ' ': { - p++; - goto s_n_llhttp__internal__n_req_spaces_before_url; - } - default: { - goto s_n_llhttp__internal__n_error_88; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_method_complete_1: - s_n_llhttp__internal__n_invoke_llhttp__on_method_complete_1: { - switch (llhttp__on_method_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_req_first_space_before_url; - case 21: - goto s_n_llhttp__internal__n_pause_26; - default: - goto s_n_llhttp__internal__n_error_107; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_2: - s_n_llhttp__internal__n_after_start_req_2: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_2; - } - switch (*p) { - case 'L': { - p++; - match = 19; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_3: - s_n_llhttp__internal__n_after_start_req_3: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_3; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob17, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 36; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_3; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_1: - s_n_llhttp__internal__n_after_start_req_1: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_1; - } - switch (*p) { - case 'C': { - p++; - goto s_n_llhttp__internal__n_after_start_req_2; - } - case 'N': { - p++; - goto s_n_llhttp__internal__n_after_start_req_3; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_4: - s_n_llhttp__internal__n_after_start_req_4: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_4; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob18, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 16; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_4; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_6: - s_n_llhttp__internal__n_after_start_req_6: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_6; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob19, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 22; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_6; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_8: - s_n_llhttp__internal__n_after_start_req_8: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_8; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob20, 4); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_8; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_9: - s_n_llhttp__internal__n_after_start_req_9: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_9; - } - switch (*p) { - case 'Y': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_7: - s_n_llhttp__internal__n_after_start_req_7: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_7; - } - switch (*p) { - case 'N': { - p++; - goto s_n_llhttp__internal__n_after_start_req_8; - } - case 'P': { - p++; - goto s_n_llhttp__internal__n_after_start_req_9; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_5: - s_n_llhttp__internal__n_after_start_req_5: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_5; - } - switch (*p) { - case 'H': { - p++; - goto s_n_llhttp__internal__n_after_start_req_6; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_7; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_12: - s_n_llhttp__internal__n_after_start_req_12: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_12; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob21, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_12; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_13: - s_n_llhttp__internal__n_after_start_req_13: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_13; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob22, 5); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 35; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_13; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_11: - s_n_llhttp__internal__n_after_start_req_11: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_11; - } - switch (*p) { - case 'L': { - p++; - goto s_n_llhttp__internal__n_after_start_req_12; - } - case 'S': { - p++; - goto s_n_llhttp__internal__n_after_start_req_13; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_10: - s_n_llhttp__internal__n_after_start_req_10: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_10; - } - switch (*p) { - case 'E': { - p++; - goto s_n_llhttp__internal__n_after_start_req_11; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_14: - s_n_llhttp__internal__n_after_start_req_14: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_14; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob23, 4); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 45; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_14; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_17: - s_n_llhttp__internal__n_after_start_req_17: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_17; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob25, 9); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 41; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_17; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_16: - s_n_llhttp__internal__n_after_start_req_16: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_16; - } - switch (*p) { - case '_': { - p++; - goto s_n_llhttp__internal__n_after_start_req_17; - } - default: { - match = 1; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_15: - s_n_llhttp__internal__n_after_start_req_15: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_15; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob24, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_after_start_req_16; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_15; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_18: - s_n_llhttp__internal__n_after_start_req_18: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_18; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob26, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_18; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_20: - s_n_llhttp__internal__n_after_start_req_20: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_20; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob27, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 31; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_20; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_21: - s_n_llhttp__internal__n_after_start_req_21: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_21; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob28, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_21; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_19: - s_n_llhttp__internal__n_after_start_req_19: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_19; - } - switch (*p) { - case 'I': { - p++; - goto s_n_llhttp__internal__n_after_start_req_20; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_21; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_23: - s_n_llhttp__internal__n_after_start_req_23: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_23; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob29, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 24; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_23; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_24: - s_n_llhttp__internal__n_after_start_req_24: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_24; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob30, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 23; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_24; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_26: - s_n_llhttp__internal__n_after_start_req_26: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_26; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob31, 7); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 21; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_26; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_28: - s_n_llhttp__internal__n_after_start_req_28: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_28; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob32, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 30; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_28; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_29: - s_n_llhttp__internal__n_after_start_req_29: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_29; - } - switch (*p) { - case 'L': { - p++; - match = 10; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_27: - s_n_llhttp__internal__n_after_start_req_27: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_27; - } - switch (*p) { - case 'A': { - p++; - goto s_n_llhttp__internal__n_after_start_req_28; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_29; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_25: - s_n_llhttp__internal__n_after_start_req_25: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_25; - } - switch (*p) { - case 'A': { - p++; - goto s_n_llhttp__internal__n_after_start_req_26; - } - case 'C': { - p++; - goto s_n_llhttp__internal__n_after_start_req_27; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_30: - s_n_llhttp__internal__n_after_start_req_30: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_30; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob33, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 11; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_30; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_22: - s_n_llhttp__internal__n_after_start_req_22: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_22; - } - switch (*p) { - case '-': { - p++; - goto s_n_llhttp__internal__n_after_start_req_23; - } - case 'E': { - p++; - goto s_n_llhttp__internal__n_after_start_req_24; - } - case 'K': { - p++; - goto s_n_llhttp__internal__n_after_start_req_25; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_30; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_31: - s_n_llhttp__internal__n_after_start_req_31: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_31; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob34, 5); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 25; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_31; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_32: - s_n_llhttp__internal__n_after_start_req_32: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_32; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob35, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_32; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_35: - s_n_llhttp__internal__n_after_start_req_35: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_35; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob36, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 28; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_35; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_36: - s_n_llhttp__internal__n_after_start_req_36: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_36; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob37, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 39; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_36; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_34: - s_n_llhttp__internal__n_after_start_req_34: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_34; - } - switch (*p) { - case 'T': { - p++; - goto s_n_llhttp__internal__n_after_start_req_35; - } - case 'U': { - p++; - goto s_n_llhttp__internal__n_after_start_req_36; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_37: - s_n_llhttp__internal__n_after_start_req_37: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_37; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob38, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 38; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_37; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_38: - s_n_llhttp__internal__n_after_start_req_38: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_38; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob39, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_38; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_42: - s_n_llhttp__internal__n_after_start_req_42: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_42; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob40, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 12; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_42; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_43: - s_n_llhttp__internal__n_after_start_req_43: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_43; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob41, 4); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 13; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_43; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_41: - s_n_llhttp__internal__n_after_start_req_41: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_41; - } - switch (*p) { - case 'F': { - p++; - goto s_n_llhttp__internal__n_after_start_req_42; - } - case 'P': { - p++; - goto s_n_llhttp__internal__n_after_start_req_43; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_40: - s_n_llhttp__internal__n_after_start_req_40: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_40; - } - switch (*p) { - case 'P': { - p++; - goto s_n_llhttp__internal__n_after_start_req_41; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_39: - s_n_llhttp__internal__n_after_start_req_39: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_39; - } - switch (*p) { - case 'I': { - p++; - match = 34; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_40; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_45: - s_n_llhttp__internal__n_after_start_req_45: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_45; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob42, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 29; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_45; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_44: - s_n_llhttp__internal__n_after_start_req_44: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_44; - } - switch (*p) { - case 'R': { - p++; - goto s_n_llhttp__internal__n_after_start_req_45; - } - case 'T': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_33: - s_n_llhttp__internal__n_after_start_req_33: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_33; - } - switch (*p) { - case 'A': { - p++; - goto s_n_llhttp__internal__n_after_start_req_34; - } - case 'L': { - p++; - goto s_n_llhttp__internal__n_after_start_req_37; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_38; - } - case 'R': { - p++; - goto s_n_llhttp__internal__n_after_start_req_39; - } - case 'U': { - p++; - goto s_n_llhttp__internal__n_after_start_req_44; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_46: - s_n_llhttp__internal__n_after_start_req_46: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_46; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob43, 4); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 46; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_46; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_49: - s_n_llhttp__internal__n_after_start_req_49: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_49; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob44, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 17; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_49; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_50: - s_n_llhttp__internal__n_after_start_req_50: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_50; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob45, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 44; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_50; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_51: - s_n_llhttp__internal__n_after_start_req_51: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_51; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob46, 5); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 43; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_51; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_52: - s_n_llhttp__internal__n_after_start_req_52: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_52; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob47, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 20; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_52; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_48: - s_n_llhttp__internal__n_after_start_req_48: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_48; - } - switch (*p) { - case 'B': { - p++; - goto s_n_llhttp__internal__n_after_start_req_49; - } - case 'C': { - p++; - goto s_n_llhttp__internal__n_after_start_req_50; - } - case 'D': { - p++; - goto s_n_llhttp__internal__n_after_start_req_51; - } - case 'P': { - p++; - goto s_n_llhttp__internal__n_after_start_req_52; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_47: - s_n_llhttp__internal__n_after_start_req_47: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_47; - } - switch (*p) { - case 'E': { - p++; - goto s_n_llhttp__internal__n_after_start_req_48; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_55: - s_n_llhttp__internal__n_after_start_req_55: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_55; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob48, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 14; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_55; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_57: - s_n_llhttp__internal__n_after_start_req_57: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_57; - } - switch (*p) { - case 'P': { - p++; - match = 37; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_58: - s_n_llhttp__internal__n_after_start_req_58: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_58; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob49, 9); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 42; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_58; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_56: - s_n_llhttp__internal__n_after_start_req_56: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_56; - } - switch (*p) { - case 'U': { - p++; - goto s_n_llhttp__internal__n_after_start_req_57; - } - case '_': { - p++; - goto s_n_llhttp__internal__n_after_start_req_58; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_54: - s_n_llhttp__internal__n_after_start_req_54: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_54; - } - switch (*p) { - case 'A': { - p++; - goto s_n_llhttp__internal__n_after_start_req_55; - } - case 'T': { - p++; - goto s_n_llhttp__internal__n_after_start_req_56; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_59: - s_n_llhttp__internal__n_after_start_req_59: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_59; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob50, 4); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 33; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_59; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_60: - s_n_llhttp__internal__n_after_start_req_60: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_60; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob51, 7); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 26; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_60; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_53: - s_n_llhttp__internal__n_after_start_req_53: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_53; - } - switch (*p) { - case 'E': { - p++; - goto s_n_llhttp__internal__n_after_start_req_54; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_59; - } - case 'U': { - p++; - goto s_n_llhttp__internal__n_after_start_req_60; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_62: - s_n_llhttp__internal__n_after_start_req_62: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_62; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob52, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 40; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_62; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_63: - s_n_llhttp__internal__n_after_start_req_63: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_63; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob53, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_63; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_61: - s_n_llhttp__internal__n_after_start_req_61: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_61; - } - switch (*p) { - case 'E': { - p++; - goto s_n_llhttp__internal__n_after_start_req_62; - } - case 'R': { - p++; - goto s_n_llhttp__internal__n_after_start_req_63; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_66: - s_n_llhttp__internal__n_after_start_req_66: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_66; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob54, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 18; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_66; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_68: - s_n_llhttp__internal__n_after_start_req_68: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_68; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob55, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 32; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_68; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_69: - s_n_llhttp__internal__n_after_start_req_69: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_69; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob56, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 15; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_69; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_67: - s_n_llhttp__internal__n_after_start_req_67: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_67; - } - switch (*p) { - case 'I': { - p++; - goto s_n_llhttp__internal__n_after_start_req_68; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_69; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_70: - s_n_llhttp__internal__n_after_start_req_70: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_70; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob57, 8); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 27; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_70; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_65: - s_n_llhttp__internal__n_after_start_req_65: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_65; - } - switch (*p) { - case 'B': { - p++; - goto s_n_llhttp__internal__n_after_start_req_66; - } - case 'L': { - p++; - goto s_n_llhttp__internal__n_after_start_req_67; - } - case 'S': { - p++; - goto s_n_llhttp__internal__n_after_start_req_70; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_64: - s_n_llhttp__internal__n_after_start_req_64: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_64; - } - switch (*p) { - case 'N': { - p++; - goto s_n_llhttp__internal__n_after_start_req_65; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req: - s_n_llhttp__internal__n_after_start_req: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req; - } - switch (*p) { - case 'A': { - p++; - goto s_n_llhttp__internal__n_after_start_req_1; - } - case 'B': { - p++; - goto s_n_llhttp__internal__n_after_start_req_4; - } - case 'C': { - p++; - goto s_n_llhttp__internal__n_after_start_req_5; - } - case 'D': { - p++; - goto s_n_llhttp__internal__n_after_start_req_10; - } - case 'F': { - p++; - goto s_n_llhttp__internal__n_after_start_req_14; - } - case 'G': { - p++; - goto s_n_llhttp__internal__n_after_start_req_15; - } - case 'H': { - p++; - goto s_n_llhttp__internal__n_after_start_req_18; - } - case 'L': { - p++; - goto s_n_llhttp__internal__n_after_start_req_19; - } - case 'M': { - p++; - goto s_n_llhttp__internal__n_after_start_req_22; - } - case 'N': { - p++; - goto s_n_llhttp__internal__n_after_start_req_31; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_32; - } - case 'P': { - p++; - goto s_n_llhttp__internal__n_after_start_req_33; - } - case 'Q': { - p++; - goto s_n_llhttp__internal__n_after_start_req_46; - } - case 'R': { - p++; - goto s_n_llhttp__internal__n_after_start_req_47; - } - case 'S': { - p++; - goto s_n_llhttp__internal__n_after_start_req_53; - } - case 'T': { - p++; - goto s_n_llhttp__internal__n_after_start_req_61; - } - case 'U': { - p++; - goto s_n_llhttp__internal__n_after_start_req_64; - } - default: { - goto s_n_llhttp__internal__n_error_108; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_method_1: - s_n_llhttp__internal__n_span_start_llhttp__on_method_1: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_method_1; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_method; - goto s_n_llhttp__internal__n_after_start_req; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_line_almost_done: - s_n_llhttp__internal__n_res_line_almost_done: { - if (p == endp) { - return s_n_llhttp__internal__n_res_line_almost_done; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; - } - default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_29; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_test_lenient_flags_30: - s_n_llhttp__internal__n_invoke_test_lenient_flags_30: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; - default: - goto s_n_llhttp__internal__n_error_94; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_status: - s_n_llhttp__internal__n_res_status: { - if (p == endp) { - return s_n_llhttp__internal__n_res_status; - } - switch (*p) { - case 10: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_status; - } - case 13: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_status_1; - } - default: { - p++; - goto s_n_llhttp__internal__n_res_status; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_status: - s_n_llhttp__internal__n_span_start_llhttp__on_status: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_status; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_status; - goto s_n_llhttp__internal__n_res_status; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_status_code_otherwise: - s_n_llhttp__internal__n_res_status_code_otherwise: { - if (p == endp) { - return s_n_llhttp__internal__n_res_status_code_otherwise; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_28; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_res_line_almost_done; - } - case ' ': { - p++; - goto s_n_llhttp__internal__n_span_start_llhttp__on_status; - } - default: { - goto s_n_llhttp__internal__n_error_95; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_status_code_digit_3: - s_n_llhttp__internal__n_res_status_code_digit_3: { - if (p == endp) { - return s_n_llhttp__internal__n_res_status_code_digit_3; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; - } - default: { - goto s_n_llhttp__internal__n_error_97; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_status_code_digit_2: - s_n_llhttp__internal__n_res_status_code_digit_2: { - if (p == endp) { - return s_n_llhttp__internal__n_res_status_code_digit_2; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; - } - default: { - goto s_n_llhttp__internal__n_error_99; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_status_code_digit_1: - s_n_llhttp__internal__n_res_status_code_digit_1: { - if (p == endp) { - return s_n_llhttp__internal__n_res_status_code_digit_1; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_mul_add_status_code; - } - default: { - goto s_n_llhttp__internal__n_error_101; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_after_version: - s_n_llhttp__internal__n_res_after_version: { - if (p == endp) { - return s_n_llhttp__internal__n_res_after_version; - } - switch (*p) { - case ' ': { - p++; - goto s_n_llhttp__internal__n_invoke_update_status_code; - } - default: { - goto s_n_llhttp__internal__n_error_102; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_version_complete_1: - s_n_llhttp__internal__n_invoke_llhttp__on_version_complete_1: { - switch (llhttp__on_version_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_res_after_version; - case 21: - goto s_n_llhttp__internal__n_pause_25; - default: - goto s_n_llhttp__internal__n_error_90; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_89: - s_n_llhttp__internal__n_error_89: { - state->error = 0x9; - state->reason = "Invalid HTTP version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_103: - s_n_llhttp__internal__n_error_103: { - state->error = 0x9; - state->reason = "Invalid minor version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_http_minor: - s_n_llhttp__internal__n_res_http_minor: { - if (p == endp) { - return s_n_llhttp__internal__n_res_http_minor; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_store_http_minor_1; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_7; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_104: - s_n_llhttp__internal__n_error_104: { - state->error = 0x9; - state->reason = "Expected dot"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_http_dot: - s_n_llhttp__internal__n_res_http_dot: { - if (p == endp) { - return s_n_llhttp__internal__n_res_http_dot; - } - switch (*p) { - case '.': { - p++; - goto s_n_llhttp__internal__n_res_http_minor; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_8; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_error_105: - s_n_llhttp__internal__n_error_105: { - state->error = 0x9; - state->reason = "Invalid major version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_res_http_major: - s_n_llhttp__internal__n_res_http_major: { - if (p == endp) { - return s_n_llhttp__internal__n_res_http_major; - } - switch (*p) { - case '0': { - p++; - match = 0; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '1': { - p++; - match = 1; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '2': { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '3': { - p++; - match = 3; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '4': { - p++; - match = 4; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '5': { - p++; - match = 5; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '6': { - p++; - match = 6; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '7': { - p++; - match = 7; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '8': { - p++; - match = 8; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - case '9': { - p++; - match = 9; - goto s_n_llhttp__internal__n_invoke_store_http_major_1; - } - default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_9; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_version_1: - s_n_llhttp__internal__n_span_start_llhttp__on_version_1: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_version_1; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_version; - goto s_n_llhttp__internal__n_res_http_major; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_start_res: - s_n_llhttp__internal__n_start_res: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_start_res; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob58, 5); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_span_start_llhttp__on_version_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_start_res; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_109; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_method_complete: - s_n_llhttp__internal__n_invoke_llhttp__on_method_complete: { - switch (llhttp__on_method_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_req_first_space_before_url; - case 21: - goto s_n_llhttp__internal__n_pause_23; - default: - goto s_n_llhttp__internal__n_error_1; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_or_res_method_2: - s_n_llhttp__internal__n_req_or_res_method_2: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_req_or_res_method_2; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob59, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 2; - goto s_n_llhttp__internal__n_invoke_store_method; - } - case kMatchPause: { - return s_n_llhttp__internal__n_req_or_res_method_2; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_106; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_update_type_1: - s_n_llhttp__internal__n_invoke_update_type_1: { - switch (llhttp__internal__c_update_type_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version_1; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_or_res_method_3: - s_n_llhttp__internal__n_req_or_res_method_3: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_req_or_res_method_3; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob60, 3); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - goto s_n_llhttp__internal__n_span_end_llhttp__on_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_req_or_res_method_3; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_106; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_or_res_method_1: - s_n_llhttp__internal__n_req_or_res_method_1: { - if (p == endp) { - return s_n_llhttp__internal__n_req_or_res_method_1; - } - switch (*p) { - case 'E': { - p++; - goto s_n_llhttp__internal__n_req_or_res_method_2; - } - case 'T': { - p++; - goto s_n_llhttp__internal__n_req_or_res_method_3; - } - default: { - goto s_n_llhttp__internal__n_error_106; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_req_or_res_method: - s_n_llhttp__internal__n_req_or_res_method: { - if (p == endp) { - return s_n_llhttp__internal__n_req_or_res_method; - } - switch (*p) { - case 'H': { - p++; - goto s_n_llhttp__internal__n_req_or_res_method_1; - } - default: { - goto s_n_llhttp__internal__n_error_106; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_span_start_llhttp__on_method: - s_n_llhttp__internal__n_span_start_llhttp__on_method: { - if (p == endp) { - return s_n_llhttp__internal__n_span_start_llhttp__on_method; - } - state->_span_pos0 = (void*) p; - state->_span_cb0 = llhttp__on_method; - goto s_n_llhttp__internal__n_req_or_res_method; - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_start_req_or_res: - s_n_llhttp__internal__n_start_req_or_res: { - if (p == endp) { - return s_n_llhttp__internal__n_start_req_or_res; - } - switch (*p) { - case 'H': { - goto s_n_llhttp__internal__n_span_start_llhttp__on_method; - } - default: { - goto s_n_llhttp__internal__n_invoke_update_type_2; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_load_type: - s_n_llhttp__internal__n_invoke_load_type: { - switch (llhttp__internal__c_load_type(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_span_start_llhttp__on_method_1; - case 2: - goto s_n_llhttp__internal__n_start_res; - default: - goto s_n_llhttp__internal__n_start_req_or_res; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_update_finish: - s_n_llhttp__internal__n_invoke_update_finish: { - switch (llhttp__internal__c_update_finish(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_message_begin; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_start: - s_n_llhttp__internal__n_start: { - if (p == endp) { - return s_n_llhttp__internal__n_start; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_start; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_start; - } - default: { - goto s_n_llhttp__internal__n_invoke_load_initial_message_completed; - } - } - /* UNREACHABLE */; - abort(); - } - default: - /* UNREACHABLE */ - abort(); - } - s_n_llhttp__internal__n_error_2: { - state->error = 0x7; - state->reason = "Invalid characters in url"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_finish_2: { - switch (llhttp__internal__c_update_finish_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_start; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_initial_message_completed: { - switch (llhttp__internal__c_update_initial_message_completed(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_finish_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_content_length: { - switch (llhttp__internal__c_update_content_length(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_initial_message_completed; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_8: { - state->error = 0x5; - state->reason = "Data after `Connection: close`"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_3: { - switch (llhttp__internal__c_test_lenient_flags_3(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_closed; - default: - goto s_n_llhttp__internal__n_error_8; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_2: { - switch (llhttp__internal__c_test_lenient_flags_2(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_update_initial_message_completed; - default: - goto s_n_llhttp__internal__n_closed; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_finish_1: { - switch (llhttp__internal__c_update_finish_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_13: { - state->error = 0x15; - state->reason = "on_message_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_is_equal_upgrade; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_38: { - state->error = 0x12; - state->reason = "`on_message_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_15: { - state->error = 0x15; - state->reason = "on_chunk_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_40: { - state->error = 0x14; - state->reason = "`on_chunk_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1: { - switch (llhttp__on_chunk_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; - case 21: - goto s_n_llhttp__internal__n_pause_15; - default: - goto s_n_llhttp__internal__n_error_40; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_2: { - state->error = 0x15; - state->reason = "on_message_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_pause_1; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_9: { - state->error = 0x12; - state->reason = "`on_message_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_1: { - switch (llhttp__on_message_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_pause_1; - case 21: - goto s_n_llhttp__internal__n_pause_2; - default: - goto s_n_llhttp__internal__n_error_9; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_36: { - state->error = 0xc; - state->reason = "Chunk size overflow"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_10: { - state->error = 0xc; - state->reason = "Invalid character in chunk size"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_4: { - switch (llhttp__internal__c_test_lenient_flags_4(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_chunk_size_otherwise; - default: - goto s_n_llhttp__internal__n_error_10; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_3: { - state->error = 0x15; - state->reason = "on_chunk_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_update_content_length_1; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_14: { - state->error = 0x14; - state->reason = "`on_chunk_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete: { - switch (llhttp__on_chunk_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_update_content_length_1; - case 21: - goto s_n_llhttp__internal__n_pause_3; - default: - goto s_n_llhttp__internal__n_error_14; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_13: { - state->error = 0x19; - state->reason = "Missing expected CR after chunk data"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_6: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; - default: - goto s_n_llhttp__internal__n_error_13; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_15: { - state->error = 0x2; - state->reason = "Expected LF after chunk data"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_7: { - switch (llhttp__internal__c_test_lenient_flags_7(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; - default: - goto s_n_llhttp__internal__n_error_15; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_body: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_body(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_data_almost_done; - return s_error; - } - goto s_n_llhttp__internal__n_chunk_data_almost_done; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags: { - switch (llhttp__internal__c_or_flags(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_field_start; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_4: { - state->error = 0x15; - state->reason = "on_chunk_header pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_is_equal_content_length; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_12: { - state->error = 0x13; - state->reason = "`on_chunk_header` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_header: { - switch (llhttp__on_chunk_header(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_is_equal_content_length; - case 21: - goto s_n_llhttp__internal__n_pause_4; - default: - goto s_n_llhttp__internal__n_error_12; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_16: { - state->error = 0x2; - state->reason = "Expected LF after chunk size"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_8: { - switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_header; - default: - goto s_n_llhttp__internal__n_error_16; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_11: { - state->error = 0x19; - state->reason = "Missing expected CR after chunk size"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_5: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_chunk_size_almost_done; - default: - goto s_n_llhttp__internal__n_error_11; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_17: { - state->error = 0x2; - state->reason = "Invalid character in chunk extensions"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_18: { - state->error = 0x2; - state->reason = "Invalid character in chunk extensions"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_20: { - state->error = 0x19; - state->reason = "Missing expected CR after chunk extension name"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_5: { - state->error = 0x15; - state->reason = "on_chunk_extension_name pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_9; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_19: { - state->error = 0x22; - state->reason = "`on_chunk_extension_name` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_name(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_6: { - state->error = 0x15; - state->reason = "on_chunk_extension_name pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_21: { - state->error = 0x22; - state->reason = "`on_chunk_extension_name` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_name(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_7: { - state->error = 0x15; - state->reason = "on_chunk_extension_name pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extensions; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_22: { - state->error = 0x22; - state->reason = "`on_chunk_extension_name` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_2: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_name(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_25: { - state->error = 0x19; - state->reason = "Missing expected CR after chunk extension value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_8: { - state->error = 0x15; - state->reason = "on_chunk_extension_value pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_10; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_24: { - state->error = 0x23; - state->reason = "`on_chunk_extension_value` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_9: { - state->error = 0x15; - state->reason = "on_chunk_extension_value pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_26: { - state->error = 0x23; - state->reason = "`on_chunk_extension_value` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_28: { - state->error = 0x19; - state->reason = "Missing expected CR after chunk extension value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_11: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_chunk_size_almost_done; - default: - goto s_n_llhttp__internal__n_error_28; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_29: { - state->error = 0x2; - state->reason = "Invalid character in chunk extensions quote value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_10: { - state->error = 0x15; - state->reason = "on_chunk_extension_value pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extension_quoted_value_done; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_27: { - state->error = 0x23; - state->reason = "`on_chunk_extension_value` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_2: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_3: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_30; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_error_30; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_4: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_31; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_error_31; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_11: { - state->error = 0x15; - state->reason = "on_chunk_extension_value pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extensions; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_32: { - state->error = 0x23; - state->reason = "`on_chunk_extension_value` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_5: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_6: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_33; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_error_33; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_12: { - state->error = 0x15; - state->reason = "on_chunk_extension_name pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extension_value; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_23: { - state->error = 0x22; - state->reason = "`on_chunk_extension_name` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_3: { - switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_chunk_extension_value; - case 21: - goto s_n_llhttp__internal__n_pause_12; - default: - goto s_n_llhttp__internal__n_error_23; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_3: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_name(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_value; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_value; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_4: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_chunk_extension_name(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_34; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_error_34; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_35: { - state->error = 0xc; - state->reason = "Invalid character in chunk size"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_mul_add_content_length: { - switch (llhttp__internal__c_mul_add_content_length(state, p, endp, match)) { - case 1: - goto s_n_llhttp__internal__n_error_36; - default: - goto s_n_llhttp__internal__n_chunk_size; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_37: { - state->error = 0xc; - state->reason = "Invalid character in chunk size"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_body_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_body(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_finish_3: { - switch (llhttp__internal__c_update_finish_3(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_body_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_39: { - state->error = 0xf; - state->reason = "Request has invalid `Transfer-Encoding`"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause: { - state->error = 0x15; - state->reason = "on_message_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__after_message_complete; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_7: { - state->error = 0x12; - state->reason = "`on_message_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_message_complete: { - switch (llhttp__on_message_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__after_message_complete; - case 21: - goto s_n_llhttp__internal__n_pause; - default: - goto s_n_llhttp__internal__n_error_7; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_1: { - switch (llhttp__internal__c_or_flags_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_2: { - switch (llhttp__internal__c_or_flags_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_upgrade: { - switch (llhttp__internal__c_update_upgrade(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_or_flags_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_14: { - state->error = 0x15; - state->reason = "Paused by on_headers_complete"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_6: { - state->error = 0x11; - state->reason = "User callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete: { - switch (llhttp__on_headers_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - case 1: - goto s_n_llhttp__internal__n_invoke_or_flags_1; - case 2: - goto s_n_llhttp__internal__n_invoke_update_upgrade; - case 21: - goto s_n_llhttp__internal__n_pause_14; - default: - goto s_n_llhttp__internal__n_error_6; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete: { - switch (llhttp__before_headers_complete(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags: { - switch (llhttp__internal__c_test_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1; - default: - goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_1: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_test_flags; - default: - goto s_n_llhttp__internal__n_error_5; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_17: { - state->error = 0x15; - state->reason = "on_chunk_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_42: { - state->error = 0x14; - state->reason = "`on_chunk_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_2: { - switch (llhttp__on_chunk_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; - case 21: - goto s_n_llhttp__internal__n_pause_17; - default: - goto s_n_llhttp__internal__n_error_42; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_3: { - switch (llhttp__internal__c_or_flags_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_4: { - switch (llhttp__internal__c_or_flags_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_upgrade_1: { - switch (llhttp__internal__c_update_upgrade(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_or_flags_4; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_16: { - state->error = 0x15; - state->reason = "Paused by on_headers_complete"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_41: { - state->error = 0x11; - state->reason = "User callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete_1: { - switch (llhttp__on_headers_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - case 1: - goto s_n_llhttp__internal__n_invoke_or_flags_3; - case 2: - goto s_n_llhttp__internal__n_invoke_update_upgrade_1; - case 21: - goto s_n_llhttp__internal__n_pause_16; - default: - goto s_n_llhttp__internal__n_error_41; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete_1: { - switch (llhttp__before_headers_complete(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete_1; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags_1: { - switch (llhttp__internal__c_test_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_2; - default: - goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete_1; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_43: { - state->error = 0x2; - state->reason = "Expected LF after headers"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_12: { - switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_test_flags_1; - default: - goto s_n_llhttp__internal__n_error_43; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_44: { - state->error = 0xa; - state->reason = "Invalid header token"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_field: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_field(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_5; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_error_5; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_13: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_header_field_colon_discard_ws; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_field; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_60: { - state->error = 0xb; - state->reason = "Content-Length can't be present with Transfer-Encoding"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_47: { - state->error = 0xa; - state->reason = "Invalid header value char"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_15: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_header_value_discard_ws; - default: - goto s_n_llhttp__internal__n_error_47; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_49: { - state->error = 0xb; - state->reason = "Empty Content-Length"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_18: { - state->error = 0x15; - state->reason = "on_header_value_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_field_start; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_48: { - state->error = 0x1d; - state->reason = "`on_header_value_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state: { - switch (llhttp__internal__c_update_header_state(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_5: { - switch (llhttp__internal__c_or_flags_5(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_6: { - switch (llhttp__internal__c_or_flags_6(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_7: { - switch (llhttp__internal__c_or_flags_7(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_8: { - switch (llhttp__internal__c_or_flags_8(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_header_state_2: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_5; - case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_6; - case 7: - goto s_n_llhttp__internal__n_invoke_or_flags_7; - case 8: - goto s_n_llhttp__internal__n_invoke_or_flags_8; - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_header_state_1: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 2: - goto s_n_llhttp__internal__n_error_49; - default: - goto s_n_llhttp__internal__n_invoke_load_header_state_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_46: { - state->error = 0xa; - state->reason = "Invalid header value char"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_14: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_header_value_discard_lws; - default: - goto s_n_llhttp__internal__n_error_46; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_50: { - state->error = 0x2; - state->reason = "Expected LF after CR"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_16: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_header_value_discard_lws; - default: - goto s_n_llhttp__internal__n_error_50; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_1: { - switch (llhttp__internal__c_update_header_state_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_header_state_4: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 8: - goto s_n_llhttp__internal__n_invoke_update_header_state_1; - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_52: { - state->error = 0xa; - state->reason = "Unexpected whitespace after header value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_18: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_load_header_state_4; - default: - goto s_n_llhttp__internal__n_error_52; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_2: { - switch (llhttp__internal__c_update_header_state(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_9: { - switch (llhttp__internal__c_or_flags_5(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_10: { - switch (llhttp__internal__c_or_flags_6(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_11: { - switch (llhttp__internal__c_or_flags_7(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_12: { - switch (llhttp__internal__c_or_flags_8(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_header_state_5: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_9; - case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_10; - case 7: - goto s_n_llhttp__internal__n_invoke_or_flags_11; - case 8: - goto s_n_llhttp__internal__n_invoke_or_flags_12; - default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_53: { - state->error = 0x3; - state->reason = "Missing expected LF after header value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_51: { - state->error = 0x19; - state->reason = "Missing expected CR after header value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_17; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_17; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_almost_done; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_header_value_almost_done; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_almost_done; - return s_error; - } - goto s_n_llhttp__internal__n_header_value_almost_done; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_almost_done; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_header_value_almost_done; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_3: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_54; - return s_error; - } - goto s_n_llhttp__internal__n_error_54; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_19: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_header_value_lenient; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_3; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_4: { - switch (llhttp__internal__c_update_header_state(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_connection; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_13: { - switch (llhttp__internal__c_or_flags_5(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_4; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_14: { - switch (llhttp__internal__c_or_flags_6(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_4; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_15: { - switch (llhttp__internal__c_or_flags_7(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_4; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_16: { - switch (llhttp__internal__c_or_flags_8(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_connection; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_header_state_6: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_13; - case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_14; - case 7: - goto s_n_llhttp__internal__n_invoke_or_flags_15; - case 8: - goto s_n_llhttp__internal__n_invoke_or_flags_16; - default: - goto s_n_llhttp__internal__n_header_value_connection; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_5: { - switch (llhttp__internal__c_update_header_state_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_connection_token; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_3: { - switch (llhttp__internal__c_update_header_state_3(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_connection_ws; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_6: { - switch (llhttp__internal__c_update_header_state_6(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_connection_ws; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_7: { - switch (llhttp__internal__c_update_header_state_7(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_connection_ws; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_56; - return s_error; - } - goto s_n_llhttp__internal__n_error_56; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_mul_add_content_length_1: { - switch (llhttp__internal__c_mul_add_content_length_1(state, p, endp, match)) { - case 1: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6; - default: - goto s_n_llhttp__internal__n_header_value_content_length; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_17: { - switch (llhttp__internal__c_or_flags_17(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_otherwise; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_7: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_57; - return s_error; - } - goto s_n_llhttp__internal__n_error_57; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_55: { - state->error = 0x4; - state->reason = "Duplicate Content-Length"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags_2: { - switch (llhttp__internal__c_test_flags_2(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_header_value_content_length; - default: - goto s_n_llhttp__internal__n_error_55; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_9: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_59; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_error_59; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_8: { - switch (llhttp__internal__c_update_header_state_8(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_otherwise; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_58; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_error_58; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_20: { - switch (llhttp__internal__c_test_lenient_flags_20(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8; - default: - goto s_n_llhttp__internal__n_header_value_te_chunked; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_type_1: { - switch (llhttp__internal__c_load_type(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_20; - default: - goto s_n_llhttp__internal__n_header_value_te_chunked; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_9: { - switch (llhttp__internal__c_update_header_state_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_and_flags: { - switch (llhttp__internal__c_and_flags(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_te_chunked; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_19: { - switch (llhttp__internal__c_or_flags_18(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_and_flags; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_21: { - switch (llhttp__internal__c_test_lenient_flags_20(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_9; - default: - goto s_n_llhttp__internal__n_invoke_or_flags_19; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_type_2: { - switch (llhttp__internal__c_load_type(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_21; - default: - goto s_n_llhttp__internal__n_invoke_or_flags_19; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_18: { - switch (llhttp__internal__c_or_flags_18(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_and_flags; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags_3: { - switch (llhttp__internal__c_test_flags_3(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_load_type_2; - default: - goto s_n_llhttp__internal__n_invoke_or_flags_18; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_20: { - switch (llhttp__internal__c_or_flags_20(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_9; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_header_state_3: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_header_value_connection; - case 2: - goto s_n_llhttp__internal__n_invoke_test_flags_2; - case 3: - goto s_n_llhttp__internal__n_invoke_test_flags_3; - case 4: - goto s_n_llhttp__internal__n_invoke_or_flags_20; - default: - goto s_n_llhttp__internal__n_header_value; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_22: { - switch (llhttp__internal__c_test_lenient_flags_22(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_error_60; - default: - goto s_n_llhttp__internal__n_header_value_discard_ws; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags_4: { - switch (llhttp__internal__c_test_flags_4(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_22; - default: - goto s_n_llhttp__internal__n_header_value_discard_ws; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_61: { - state->error = 0xf; - state->reason = "Transfer-Encoding can't be present with Content-Length"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_23: { - switch (llhttp__internal__c_test_lenient_flags_22(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_error_61; - default: - goto s_n_llhttp__internal__n_header_value_discard_ws; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags_5: { - switch (llhttp__internal__c_test_flags_2(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_23; - default: - goto s_n_llhttp__internal__n_header_value_discard_ws; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_19: { - state->error = 0x15; - state->reason = "on_header_field_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_load_header_state; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_45: { - state->error = 0x1c; - state->reason = "`on_header_field_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_field_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_field(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_field_2: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_field(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_62: { - state->error = 0xa; - state->reason = "Invalid header token"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_10: { - switch (llhttp__internal__c_update_header_state_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_field_general; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_store_header_state: { - switch (llhttp__internal__c_store_header_state(state, p, endp, match)) { - default: - goto s_n_llhttp__internal__n_header_field_colon; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_11: { - switch (llhttp__internal__c_update_header_state_1(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_field_general; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_4: { - state->error = 0x1e; - state->reason = "Unexpected space after start line"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_header_field_start; - default: - goto s_n_llhttp__internal__n_error_4; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_20: { - state->error = 0x15; - state->reason = "on_url_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_headers_start; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_3: { - state->error = 0x1a; - state->reason = "`on_url_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_url_complete: { - switch (llhttp__on_url_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_headers_start; - case 21: - goto s_n_llhttp__internal__n_pause_20; - default: - goto s_n_llhttp__internal__n_error_3; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_http_minor: { - switch (llhttp__internal__c_update_http_minor(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_url_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_http_major: { - switch (llhttp__internal__c_update_http_major(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_http_minor; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_3: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_63: { - state->error = 0x7; - state->reason = "Expected CRLF"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_4: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_lf_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_lf_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_71: { - state->error = 0x17; - state->reason = "Pause on PRI/Upgrade"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_72: { - state->error = 0x9; - state->reason = "Expected HTTP/2 Connection Preface"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_69: { - state->error = 0x2; - state->reason = "Expected CRLF after version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_26: { - switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_headers_start; - default: - goto s_n_llhttp__internal__n_error_69; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_68: { - state->error = 0x9; - state->reason = "Expected CRLF after version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_25: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_req_http_complete_crlf; - default: - goto s_n_llhttp__internal__n_error_68; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_70: { - state->error = 0x9; - state->reason = "Expected CRLF after version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_21: { - state->error = 0x15; - state->reason = "on_version_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_load_method_1; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_67: { - state->error = 0x21; - state->reason = "`on_version_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_version_complete; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_version_complete; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_66; - return s_error; - } - goto s_n_llhttp__internal__n_error_66; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_http_minor: { - switch (llhttp__internal__c_load_http_minor(state, p, endp)) { - case 9: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_1; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_http_minor_1: { - switch (llhttp__internal__c_load_http_minor(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_1; - case 1: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_1; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_http_minor_2: { - switch (llhttp__internal__c_load_http_minor(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_1; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_http_major: { - switch (llhttp__internal__c_load_http_major(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_load_http_minor; - case 1: - goto s_n_llhttp__internal__n_invoke_load_http_minor_1; - case 2: - goto s_n_llhttp__internal__n_invoke_load_http_minor_2; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_24: { - switch (llhttp__internal__c_test_lenient_flags_24(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_1; - default: - goto s_n_llhttp__internal__n_invoke_load_http_major; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_store_http_minor: { - switch (llhttp__internal__c_store_http_minor(state, p, endp, match)) { - default: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_24; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_2: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_73; - return s_error; - } - goto s_n_llhttp__internal__n_error_73; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_3: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_74; - return s_error; - } - goto s_n_llhttp__internal__n_error_74; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_store_http_major: { - switch (llhttp__internal__c_store_http_major(state, p, endp, match)) { - default: - goto s_n_llhttp__internal__n_req_http_dot; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_4: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_75; - return s_error; - } - goto s_n_llhttp__internal__n_error_75; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_65: { - state->error = 0x8; - state->reason = "Invalid method for HTTP/x.x request"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_method: { - switch (llhttp__internal__c_load_method(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 1: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 2: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 3: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 4: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 5: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 6: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 7: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 8: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 9: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 10: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 11: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 12: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 13: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 14: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 15: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 16: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 17: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 18: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 19: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 20: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 21: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 22: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 23: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 24: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 25: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 26: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 27: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 28: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 29: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 30: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 31: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 32: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 33: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 34: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 46: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - default: - goto s_n_llhttp__internal__n_error_65; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_78: { - state->error = 0x8; - state->reason = "Expected HTTP/"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_76: { - state->error = 0x8; - state->reason = "Expected SOURCE method for ICE/x.x request"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_method_2: { - switch (llhttp__internal__c_load_method(state, p, endp)) { - case 33: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - default: - goto s_n_llhttp__internal__n_error_76; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_77: { - state->error = 0x8; - state->reason = "Invalid method for RTSP/x.x request"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_method_3: { - switch (llhttp__internal__c_load_method(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 3: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 6: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 35: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 36: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 37: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 38: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 39: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 40: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 41: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 42: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 43: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 44: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - case 45: - goto s_n_llhttp__internal__n_span_start_llhttp__on_version; - default: - goto s_n_llhttp__internal__n_error_77; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_22: { - state->error = 0x15; - state->reason = "on_url_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_req_http_start; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_64: { - state->error = 0x1a; - state->reason = "`on_url_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_url_complete_1: { - switch (llhttp__on_url_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_req_http_start; - case 21: - goto s_n_llhttp__internal__n_pause_22; - default: - goto s_n_llhttp__internal__n_error_64; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_5: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_6: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_7: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_lf_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_lf_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_8: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_79: { - state->error = 0x7; - state->reason = "Invalid char in url fragment start"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_9: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_10: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_lf_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_lf_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_11: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_80: { - state->error = 0x7; - state->reason = "Invalid char in url query"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_81: { - state->error = 0x7; - state->reason = "Invalid char in url path"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_lf_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_lf_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_2: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_12: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_13: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_lf_to_http09; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_lf_to_http09; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_url_14: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_url(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_url_skip_to_http; - return s_error; - } - goto s_n_llhttp__internal__n_url_skip_to_http; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_82: { - state->error = 0x7; - state->reason = "Double @ in url"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_83: { - state->error = 0x7; - state->reason = "Unexpected char in url server"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_84: { - state->error = 0x7; - state->reason = "Unexpected char in url server"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_85: { - state->error = 0x7; - state->reason = "Unexpected char in url schema"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_86: { - state->error = 0x7; - state->reason = "Unexpected char in url schema"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_87: { - state->error = 0x7; - state->reason = "Unexpected start char in url"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_is_equal_method: { - switch (llhttp__internal__c_is_equal_method(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_url_entry_normal; - default: - goto s_n_llhttp__internal__n_url_entry_connect; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_88: { - state->error = 0x6; - state->reason = "Expected space after method"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_26: { - state->error = 0x15; - state->reason = "on_method_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_req_first_space_before_url; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_107: { - state->error = 0x20; - state->reason = "`on_method_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_method_2: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_method(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_method_complete_1; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_method_complete_1; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_store_method_1: { - switch (llhttp__internal__c_store_method(state, p, endp, match)) { - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_method_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_108: { - state->error = 0x6; - state->reason = "Invalid method encountered"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_100: { - state->error = 0xd; - state->reason = "Invalid status code"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_98: { - state->error = 0xd; - state->reason = "Invalid status code"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_96: { - state->error = 0xd; - state->reason = "Invalid status code"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_24: { - state->error = 0x15; - state->reason = "on_status_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_headers_start; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_92: { - state->error = 0x1b; - state->reason = "`on_status_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_status_complete: { - switch (llhttp__on_status_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_headers_start; - case 21: - goto s_n_llhttp__internal__n_pause_24; - default: - goto s_n_llhttp__internal__n_error_92; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_91: { - state->error = 0xd; - state->reason = "Invalid response status"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_28: { - switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; - default: - goto s_n_llhttp__internal__n_error_91; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_93: { - state->error = 0x2; - state->reason = "Expected LF after CR"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_29: { - switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; - default: - goto s_n_llhttp__internal__n_error_93; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_94: { - state->error = 0x19; - state->reason = "Missing expected CR after response line"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_status: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_status(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_30; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_30; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_status_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_status(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_res_line_almost_done; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_res_line_almost_done; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_95: { - state->error = 0xd; - state->reason = "Invalid response status"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_mul_add_status_code_2: { - switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { - case 1: - goto s_n_llhttp__internal__n_error_96; - default: - goto s_n_llhttp__internal__n_res_status_code_otherwise; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_97: { - state->error = 0xd; - state->reason = "Invalid status code"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_mul_add_status_code_1: { - switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { - case 1: - goto s_n_llhttp__internal__n_error_98; - default: - goto s_n_llhttp__internal__n_res_status_code_digit_3; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_99: { - state->error = 0xd; - state->reason = "Invalid status code"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_mul_add_status_code: { - switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { - case 1: - goto s_n_llhttp__internal__n_error_100; - default: - goto s_n_llhttp__internal__n_res_status_code_digit_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_101: { - state->error = 0xd; - state->reason = "Invalid status code"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_status_code: { - switch (llhttp__internal__c_update_status_code(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_res_status_code_digit_1; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_102: { - state->error = 0x9; - state->reason = "Expected space after version"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_25: { - state->error = 0x15; - state->reason = "on_version_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_res_after_version; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_90: { - state->error = 0x21; - state->reason = "`on_version_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_6: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_version_complete_1; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_version_complete_1; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_5: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_89; - return s_error; - } - goto s_n_llhttp__internal__n_error_89; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_http_minor_3: { - switch (llhttp__internal__c_load_http_minor(state, p, endp)) { - case 9: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_6; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_5; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_http_minor_4: { - switch (llhttp__internal__c_load_http_minor(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_6; - case 1: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_6; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_5; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_http_minor_5: { - switch (llhttp__internal__c_load_http_minor(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_6; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_5; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_http_major_1: { - switch (llhttp__internal__c_load_http_major(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_load_http_minor_3; - case 1: - goto s_n_llhttp__internal__n_invoke_load_http_minor_4; - case 2: - goto s_n_llhttp__internal__n_invoke_load_http_minor_5; - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_5; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_27: { - switch (llhttp__internal__c_test_lenient_flags_24(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_span_end_llhttp__on_version_6; - default: - goto s_n_llhttp__internal__n_invoke_load_http_major_1; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_store_http_minor_1: { - switch (llhttp__internal__c_store_http_minor(state, p, endp, match)) { - default: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_27; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_7: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_103; - return s_error; - } - goto s_n_llhttp__internal__n_error_103; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_8: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_104; - return s_error; - } - goto s_n_llhttp__internal__n_error_104; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_store_http_major_1: { - switch (llhttp__internal__c_store_http_major(state, p, endp, match)) { - default: - goto s_n_llhttp__internal__n_res_http_dot; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_version_9: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_version(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_105; - return s_error; - } - goto s_n_llhttp__internal__n_error_105; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_109: { - state->error = 0x8; - state->reason = "Expected HTTP/"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_23: { - state->error = 0x15; - state->reason = "on_method_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_req_first_space_before_url; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_1: { - state->error = 0x20; - state->reason = "`on_method_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_method: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_method(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_method_complete; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_llhttp__on_method_complete; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_type: { - switch (llhttp__internal__c_update_type(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_method; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_store_method: { - switch (llhttp__internal__c_store_method(state, p, endp, match)) { - default: - goto s_n_llhttp__internal__n_invoke_update_type; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_106: { - state->error = 0x8; - state->reason = "Invalid word encountered"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_method_1: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_method(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_update_type_1; - return s_error; - } - goto s_n_llhttp__internal__n_invoke_update_type_1; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_type_2: { - switch (llhttp__internal__c_update_type(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_method_1; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_27: { - state->error = 0x15; - state->reason = "on_message_begin pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_load_type; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error: { - state->error = 0x10; - state->reason = "`on_message_begin` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_message_begin: { - switch (llhttp__on_message_begin(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_load_type; - case 21: - goto s_n_llhttp__internal__n_pause_27; - default: - goto s_n_llhttp__internal__n_error; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_28: { - state->error = 0x15; - state->reason = "on_reset pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_update_finish; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_110: { - state->error = 0x1f; - state->reason = "`on_reset` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_reset: { - switch (llhttp__on_reset(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_update_finish; - case 21: - goto s_n_llhttp__internal__n_pause_28; - default: - goto s_n_llhttp__internal__n_error_110; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_initial_message_completed: { - switch (llhttp__internal__c_load_initial_message_completed(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_reset; - default: - goto s_n_llhttp__internal__n_invoke_update_finish; - } - /* UNREACHABLE */; - abort(); - } -} - -int llhttp__internal_execute(llhttp__internal_t* state, const char* p, const char* endp) { - llparse_state_t next; - - /* check lingering errors */ - if (state->error != 0) { - return state->error; - } - - /* restart spans */ - if (state->_span_pos0 != NULL) { - state->_span_pos0 = (void*) p; - } - - next = llhttp__internal__run(state, (const unsigned char*) p, (const unsigned char*) endp); - if (next == s_error) { - return state->error; - } - state->_current = (void*) (intptr_t) next; - - /* execute spans */ - if (state->_span_pos0 != NULL) { - int error; - - error = ((llhttp__internal__span_cb) state->_span_cb0)(state, state->_span_pos0, (const char*) endp); - if (error != 0) { - state->error = error; - state->error_pos = endp; - return error; - } - } - - return 0; -} \ No newline at end of file diff --git a/vendor/libgit2-sys/libgit2/deps/llhttp/llhttp.h b/vendor/libgit2-sys/libgit2/deps/llhttp/llhttp.h deleted file mode 100644 index 26f01c3..0000000 --- a/vendor/libgit2-sys/libgit2/deps/llhttp/llhttp.h +++ /dev/null @@ -1,897 +0,0 @@ - -#ifndef INCLUDE_LLHTTP_H_ -#define INCLUDE_LLHTTP_H_ - -#define LLHTTP_VERSION_MAJOR 9 -#define LLHTTP_VERSION_MINOR 2 -#define LLHTTP_VERSION_PATCH 1 - -#ifndef INCLUDE_LLHTTP_ITSELF_H_ -#define INCLUDE_LLHTTP_ITSELF_H_ -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef struct llhttp__internal_s llhttp__internal_t; -struct llhttp__internal_s { - int32_t _index; - void* _span_pos0; - void* _span_cb0; - int32_t error; - const char* reason; - const char* error_pos; - void* data; - void* _current; - uint64_t content_length; - uint8_t type; - uint8_t method; - uint8_t http_major; - uint8_t http_minor; - uint8_t header_state; - uint16_t lenient_flags; - uint8_t upgrade; - uint8_t finish; - uint16_t flags; - uint16_t status_code; - uint8_t initial_message_completed; - void* settings; -}; - -int llhttp__internal_init(llhttp__internal_t* s); -int llhttp__internal_execute(llhttp__internal_t* s, const char* p, const char* endp); - -#ifdef __cplusplus -} /* extern "C" */ -#endif -#endif /* INCLUDE_LLHTTP_ITSELF_H_ */ - - -#ifndef LLLLHTTP_C_HEADERS_ -#define LLLLHTTP_C_HEADERS_ -#ifdef __cplusplus -extern "C" { -#endif - -enum llhttp_errno { - HPE_OK = 0, - HPE_INTERNAL = 1, - HPE_STRICT = 2, - HPE_CR_EXPECTED = 25, - HPE_LF_EXPECTED = 3, - HPE_UNEXPECTED_CONTENT_LENGTH = 4, - HPE_UNEXPECTED_SPACE = 30, - HPE_CLOSED_CONNECTION = 5, - HPE_INVALID_METHOD = 6, - HPE_INVALID_URL = 7, - HPE_INVALID_CONSTANT = 8, - HPE_INVALID_VERSION = 9, - HPE_INVALID_HEADER_TOKEN = 10, - HPE_INVALID_CONTENT_LENGTH = 11, - HPE_INVALID_CHUNK_SIZE = 12, - HPE_INVALID_STATUS = 13, - HPE_INVALID_EOF_STATE = 14, - HPE_INVALID_TRANSFER_ENCODING = 15, - HPE_CB_MESSAGE_BEGIN = 16, - HPE_CB_HEADERS_COMPLETE = 17, - HPE_CB_MESSAGE_COMPLETE = 18, - HPE_CB_CHUNK_HEADER = 19, - HPE_CB_CHUNK_COMPLETE = 20, - HPE_PAUSED = 21, - HPE_PAUSED_UPGRADE = 22, - HPE_PAUSED_H2_UPGRADE = 23, - HPE_USER = 24, - HPE_CB_URL_COMPLETE = 26, - HPE_CB_STATUS_COMPLETE = 27, - HPE_CB_METHOD_COMPLETE = 32, - HPE_CB_VERSION_COMPLETE = 33, - HPE_CB_HEADER_FIELD_COMPLETE = 28, - HPE_CB_HEADER_VALUE_COMPLETE = 29, - HPE_CB_CHUNK_EXTENSION_NAME_COMPLETE = 34, - HPE_CB_CHUNK_EXTENSION_VALUE_COMPLETE = 35, - HPE_CB_RESET = 31 -}; -typedef enum llhttp_errno llhttp_errno_t; - -enum llhttp_flags { - F_CONNECTION_KEEP_ALIVE = 0x1, - F_CONNECTION_CLOSE = 0x2, - F_CONNECTION_UPGRADE = 0x4, - F_CHUNKED = 0x8, - F_UPGRADE = 0x10, - F_CONTENT_LENGTH = 0x20, - F_SKIPBODY = 0x40, - F_TRAILING = 0x80, - F_TRANSFER_ENCODING = 0x200 -}; -typedef enum llhttp_flags llhttp_flags_t; - -enum llhttp_lenient_flags { - LENIENT_HEADERS = 0x1, - LENIENT_CHUNKED_LENGTH = 0x2, - LENIENT_KEEP_ALIVE = 0x4, - LENIENT_TRANSFER_ENCODING = 0x8, - LENIENT_VERSION = 0x10, - LENIENT_DATA_AFTER_CLOSE = 0x20, - LENIENT_OPTIONAL_LF_AFTER_CR = 0x40, - LENIENT_OPTIONAL_CRLF_AFTER_CHUNK = 0x80, - LENIENT_OPTIONAL_CR_BEFORE_LF = 0x100, - LENIENT_SPACES_AFTER_CHUNK_SIZE = 0x200 -}; -typedef enum llhttp_lenient_flags llhttp_lenient_flags_t; - -enum llhttp_type { - HTTP_BOTH = 0, - HTTP_REQUEST = 1, - HTTP_RESPONSE = 2 -}; -typedef enum llhttp_type llhttp_type_t; - -enum llhttp_finish { - HTTP_FINISH_SAFE = 0, - HTTP_FINISH_SAFE_WITH_CB = 1, - HTTP_FINISH_UNSAFE = 2 -}; -typedef enum llhttp_finish llhttp_finish_t; - -enum llhttp_method { - HTTP_DELETE = 0, - HTTP_GET = 1, - HTTP_HEAD = 2, - HTTP_POST = 3, - HTTP_PUT = 4, - HTTP_CONNECT = 5, - HTTP_OPTIONS = 6, - HTTP_TRACE = 7, - HTTP_COPY = 8, - HTTP_LOCK = 9, - HTTP_MKCOL = 10, - HTTP_MOVE = 11, - HTTP_PROPFIND = 12, - HTTP_PROPPATCH = 13, - HTTP_SEARCH = 14, - HTTP_UNLOCK = 15, - HTTP_BIND = 16, - HTTP_REBIND = 17, - HTTP_UNBIND = 18, - HTTP_ACL = 19, - HTTP_REPORT = 20, - HTTP_MKACTIVITY = 21, - HTTP_CHECKOUT = 22, - HTTP_MERGE = 23, - HTTP_MSEARCH = 24, - HTTP_NOTIFY = 25, - HTTP_SUBSCRIBE = 26, - HTTP_UNSUBSCRIBE = 27, - HTTP_PATCH = 28, - HTTP_PURGE = 29, - HTTP_MKCALENDAR = 30, - HTTP_LINK = 31, - HTTP_UNLINK = 32, - HTTP_SOURCE = 33, - HTTP_PRI = 34, - HTTP_DESCRIBE = 35, - HTTP_ANNOUNCE = 36, - HTTP_SETUP = 37, - HTTP_PLAY = 38, - HTTP_PAUSE = 39, - HTTP_TEARDOWN = 40, - HTTP_GET_PARAMETER = 41, - HTTP_SET_PARAMETER = 42, - HTTP_REDIRECT = 43, - HTTP_RECORD = 44, - HTTP_FLUSH = 45, - HTTP_QUERY = 46 -}; -typedef enum llhttp_method llhttp_method_t; - -enum llhttp_status { - HTTP_STATUS_CONTINUE = 100, - HTTP_STATUS_SWITCHING_PROTOCOLS = 101, - HTTP_STATUS_PROCESSING = 102, - HTTP_STATUS_EARLY_HINTS = 103, - HTTP_STATUS_RESPONSE_IS_STALE = 110, - HTTP_STATUS_REVALIDATION_FAILED = 111, - HTTP_STATUS_DISCONNECTED_OPERATION = 112, - HTTP_STATUS_HEURISTIC_EXPIRATION = 113, - HTTP_STATUS_MISCELLANEOUS_WARNING = 199, - HTTP_STATUS_OK = 200, - HTTP_STATUS_CREATED = 201, - HTTP_STATUS_ACCEPTED = 202, - HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION = 203, - HTTP_STATUS_NO_CONTENT = 204, - HTTP_STATUS_RESET_CONTENT = 205, - HTTP_STATUS_PARTIAL_CONTENT = 206, - HTTP_STATUS_MULTI_STATUS = 207, - HTTP_STATUS_ALREADY_REPORTED = 208, - HTTP_STATUS_TRANSFORMATION_APPLIED = 214, - HTTP_STATUS_IM_USED = 226, - HTTP_STATUS_MISCELLANEOUS_PERSISTENT_WARNING = 299, - HTTP_STATUS_MULTIPLE_CHOICES = 300, - HTTP_STATUS_MOVED_PERMANENTLY = 301, - HTTP_STATUS_FOUND = 302, - HTTP_STATUS_SEE_OTHER = 303, - HTTP_STATUS_NOT_MODIFIED = 304, - HTTP_STATUS_USE_PROXY = 305, - HTTP_STATUS_SWITCH_PROXY = 306, - HTTP_STATUS_TEMPORARY_REDIRECT = 307, - HTTP_STATUS_PERMANENT_REDIRECT = 308, - HTTP_STATUS_BAD_REQUEST = 400, - HTTP_STATUS_UNAUTHORIZED = 401, - HTTP_STATUS_PAYMENT_REQUIRED = 402, - HTTP_STATUS_FORBIDDEN = 403, - HTTP_STATUS_NOT_FOUND = 404, - HTTP_STATUS_METHOD_NOT_ALLOWED = 405, - HTTP_STATUS_NOT_ACCEPTABLE = 406, - HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407, - HTTP_STATUS_REQUEST_TIMEOUT = 408, - HTTP_STATUS_CONFLICT = 409, - HTTP_STATUS_GONE = 410, - HTTP_STATUS_LENGTH_REQUIRED = 411, - HTTP_STATUS_PRECONDITION_FAILED = 412, - HTTP_STATUS_PAYLOAD_TOO_LARGE = 413, - HTTP_STATUS_URI_TOO_LONG = 414, - HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415, - HTTP_STATUS_RANGE_NOT_SATISFIABLE = 416, - HTTP_STATUS_EXPECTATION_FAILED = 417, - HTTP_STATUS_IM_A_TEAPOT = 418, - HTTP_STATUS_PAGE_EXPIRED = 419, - HTTP_STATUS_ENHANCE_YOUR_CALM = 420, - HTTP_STATUS_MISDIRECTED_REQUEST = 421, - HTTP_STATUS_UNPROCESSABLE_ENTITY = 422, - HTTP_STATUS_LOCKED = 423, - HTTP_STATUS_FAILED_DEPENDENCY = 424, - HTTP_STATUS_TOO_EARLY = 425, - HTTP_STATUS_UPGRADE_REQUIRED = 426, - HTTP_STATUS_PRECONDITION_REQUIRED = 428, - HTTP_STATUS_TOO_MANY_REQUESTS = 429, - HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL = 430, - HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, - HTTP_STATUS_LOGIN_TIMEOUT = 440, - HTTP_STATUS_NO_RESPONSE = 444, - HTTP_STATUS_RETRY_WITH = 449, - HTTP_STATUS_BLOCKED_BY_PARENTAL_CONTROL = 450, - HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451, - HTTP_STATUS_CLIENT_CLOSED_LOAD_BALANCED_REQUEST = 460, - HTTP_STATUS_INVALID_X_FORWARDED_FOR = 463, - HTTP_STATUS_REQUEST_HEADER_TOO_LARGE = 494, - HTTP_STATUS_SSL_CERTIFICATE_ERROR = 495, - HTTP_STATUS_SSL_CERTIFICATE_REQUIRED = 496, - HTTP_STATUS_HTTP_REQUEST_SENT_TO_HTTPS_PORT = 497, - HTTP_STATUS_INVALID_TOKEN = 498, - HTTP_STATUS_CLIENT_CLOSED_REQUEST = 499, - HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, - HTTP_STATUS_NOT_IMPLEMENTED = 501, - HTTP_STATUS_BAD_GATEWAY = 502, - HTTP_STATUS_SERVICE_UNAVAILABLE = 503, - HTTP_STATUS_GATEWAY_TIMEOUT = 504, - HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED = 505, - HTTP_STATUS_VARIANT_ALSO_NEGOTIATES = 506, - HTTP_STATUS_INSUFFICIENT_STORAGE = 507, - HTTP_STATUS_LOOP_DETECTED = 508, - HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509, - HTTP_STATUS_NOT_EXTENDED = 510, - HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511, - HTTP_STATUS_WEB_SERVER_UNKNOWN_ERROR = 520, - HTTP_STATUS_WEB_SERVER_IS_DOWN = 521, - HTTP_STATUS_CONNECTION_TIMEOUT = 522, - HTTP_STATUS_ORIGIN_IS_UNREACHABLE = 523, - HTTP_STATUS_TIMEOUT_OCCURED = 524, - HTTP_STATUS_SSL_HANDSHAKE_FAILED = 525, - HTTP_STATUS_INVALID_SSL_CERTIFICATE = 526, - HTTP_STATUS_RAILGUN_ERROR = 527, - HTTP_STATUS_SITE_IS_OVERLOADED = 529, - HTTP_STATUS_SITE_IS_FROZEN = 530, - HTTP_STATUS_IDENTITY_PROVIDER_AUTHENTICATION_ERROR = 561, - HTTP_STATUS_NETWORK_READ_TIMEOUT = 598, - HTTP_STATUS_NETWORK_CONNECT_TIMEOUT = 599 -}; -typedef enum llhttp_status llhttp_status_t; - -#define HTTP_ERRNO_MAP(XX) \ - XX(0, OK, OK) \ - XX(1, INTERNAL, INTERNAL) \ - XX(2, STRICT, STRICT) \ - XX(25, CR_EXPECTED, CR_EXPECTED) \ - XX(3, LF_EXPECTED, LF_EXPECTED) \ - XX(4, UNEXPECTED_CONTENT_LENGTH, UNEXPECTED_CONTENT_LENGTH) \ - XX(30, UNEXPECTED_SPACE, UNEXPECTED_SPACE) \ - XX(5, CLOSED_CONNECTION, CLOSED_CONNECTION) \ - XX(6, INVALID_METHOD, INVALID_METHOD) \ - XX(7, INVALID_URL, INVALID_URL) \ - XX(8, INVALID_CONSTANT, INVALID_CONSTANT) \ - XX(9, INVALID_VERSION, INVALID_VERSION) \ - XX(10, INVALID_HEADER_TOKEN, INVALID_HEADER_TOKEN) \ - XX(11, INVALID_CONTENT_LENGTH, INVALID_CONTENT_LENGTH) \ - XX(12, INVALID_CHUNK_SIZE, INVALID_CHUNK_SIZE) \ - XX(13, INVALID_STATUS, INVALID_STATUS) \ - XX(14, INVALID_EOF_STATE, INVALID_EOF_STATE) \ - XX(15, INVALID_TRANSFER_ENCODING, INVALID_TRANSFER_ENCODING) \ - XX(16, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \ - XX(17, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \ - XX(18, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \ - XX(19, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \ - XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \ - XX(21, PAUSED, PAUSED) \ - XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \ - XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \ - XX(24, USER, USER) \ - XX(26, CB_URL_COMPLETE, CB_URL_COMPLETE) \ - XX(27, CB_STATUS_COMPLETE, CB_STATUS_COMPLETE) \ - XX(32, CB_METHOD_COMPLETE, CB_METHOD_COMPLETE) \ - XX(33, CB_VERSION_COMPLETE, CB_VERSION_COMPLETE) \ - XX(28, CB_HEADER_FIELD_COMPLETE, CB_HEADER_FIELD_COMPLETE) \ - XX(29, CB_HEADER_VALUE_COMPLETE, CB_HEADER_VALUE_COMPLETE) \ - XX(34, CB_CHUNK_EXTENSION_NAME_COMPLETE, CB_CHUNK_EXTENSION_NAME_COMPLETE) \ - XX(35, CB_CHUNK_EXTENSION_VALUE_COMPLETE, CB_CHUNK_EXTENSION_VALUE_COMPLETE) \ - XX(31, CB_RESET, CB_RESET) \ - - -#define HTTP_METHOD_MAP(XX) \ - XX(0, DELETE, DELETE) \ - XX(1, GET, GET) \ - XX(2, HEAD, HEAD) \ - XX(3, POST, POST) \ - XX(4, PUT, PUT) \ - XX(5, CONNECT, CONNECT) \ - XX(6, OPTIONS, OPTIONS) \ - XX(7, TRACE, TRACE) \ - XX(8, COPY, COPY) \ - XX(9, LOCK, LOCK) \ - XX(10, MKCOL, MKCOL) \ - XX(11, MOVE, MOVE) \ - XX(12, PROPFIND, PROPFIND) \ - XX(13, PROPPATCH, PROPPATCH) \ - XX(14, SEARCH, SEARCH) \ - XX(15, UNLOCK, UNLOCK) \ - XX(16, BIND, BIND) \ - XX(17, REBIND, REBIND) \ - XX(18, UNBIND, UNBIND) \ - XX(19, ACL, ACL) \ - XX(20, REPORT, REPORT) \ - XX(21, MKACTIVITY, MKACTIVITY) \ - XX(22, CHECKOUT, CHECKOUT) \ - XX(23, MERGE, MERGE) \ - XX(24, MSEARCH, M-SEARCH) \ - XX(25, NOTIFY, NOTIFY) \ - XX(26, SUBSCRIBE, SUBSCRIBE) \ - XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \ - XX(28, PATCH, PATCH) \ - XX(29, PURGE, PURGE) \ - XX(30, MKCALENDAR, MKCALENDAR) \ - XX(31, LINK, LINK) \ - XX(32, UNLINK, UNLINK) \ - XX(33, SOURCE, SOURCE) \ - XX(46, QUERY, QUERY) \ - - -#define RTSP_METHOD_MAP(XX) \ - XX(1, GET, GET) \ - XX(3, POST, POST) \ - XX(6, OPTIONS, OPTIONS) \ - XX(35, DESCRIBE, DESCRIBE) \ - XX(36, ANNOUNCE, ANNOUNCE) \ - XX(37, SETUP, SETUP) \ - XX(38, PLAY, PLAY) \ - XX(39, PAUSE, PAUSE) \ - XX(40, TEARDOWN, TEARDOWN) \ - XX(41, GET_PARAMETER, GET_PARAMETER) \ - XX(42, SET_PARAMETER, SET_PARAMETER) \ - XX(43, REDIRECT, REDIRECT) \ - XX(44, RECORD, RECORD) \ - XX(45, FLUSH, FLUSH) \ - - -#define HTTP_ALL_METHOD_MAP(XX) \ - XX(0, DELETE, DELETE) \ - XX(1, GET, GET) \ - XX(2, HEAD, HEAD) \ - XX(3, POST, POST) \ - XX(4, PUT, PUT) \ - XX(5, CONNECT, CONNECT) \ - XX(6, OPTIONS, OPTIONS) \ - XX(7, TRACE, TRACE) \ - XX(8, COPY, COPY) \ - XX(9, LOCK, LOCK) \ - XX(10, MKCOL, MKCOL) \ - XX(11, MOVE, MOVE) \ - XX(12, PROPFIND, PROPFIND) \ - XX(13, PROPPATCH, PROPPATCH) \ - XX(14, SEARCH, SEARCH) \ - XX(15, UNLOCK, UNLOCK) \ - XX(16, BIND, BIND) \ - XX(17, REBIND, REBIND) \ - XX(18, UNBIND, UNBIND) \ - XX(19, ACL, ACL) \ - XX(20, REPORT, REPORT) \ - XX(21, MKACTIVITY, MKACTIVITY) \ - XX(22, CHECKOUT, CHECKOUT) \ - XX(23, MERGE, MERGE) \ - XX(24, MSEARCH, M-SEARCH) \ - XX(25, NOTIFY, NOTIFY) \ - XX(26, SUBSCRIBE, SUBSCRIBE) \ - XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \ - XX(28, PATCH, PATCH) \ - XX(29, PURGE, PURGE) \ - XX(30, MKCALENDAR, MKCALENDAR) \ - XX(31, LINK, LINK) \ - XX(32, UNLINK, UNLINK) \ - XX(33, SOURCE, SOURCE) \ - XX(34, PRI, PRI) \ - XX(35, DESCRIBE, DESCRIBE) \ - XX(36, ANNOUNCE, ANNOUNCE) \ - XX(37, SETUP, SETUP) \ - XX(38, PLAY, PLAY) \ - XX(39, PAUSE, PAUSE) \ - XX(40, TEARDOWN, TEARDOWN) \ - XX(41, GET_PARAMETER, GET_PARAMETER) \ - XX(42, SET_PARAMETER, SET_PARAMETER) \ - XX(43, REDIRECT, REDIRECT) \ - XX(44, RECORD, RECORD) \ - XX(45, FLUSH, FLUSH) \ - XX(46, QUERY, QUERY) \ - - -#define HTTP_STATUS_MAP(XX) \ - XX(100, CONTINUE, CONTINUE) \ - XX(101, SWITCHING_PROTOCOLS, SWITCHING_PROTOCOLS) \ - XX(102, PROCESSING, PROCESSING) \ - XX(103, EARLY_HINTS, EARLY_HINTS) \ - XX(110, RESPONSE_IS_STALE, RESPONSE_IS_STALE) \ - XX(111, REVALIDATION_FAILED, REVALIDATION_FAILED) \ - XX(112, DISCONNECTED_OPERATION, DISCONNECTED_OPERATION) \ - XX(113, HEURISTIC_EXPIRATION, HEURISTIC_EXPIRATION) \ - XX(199, MISCELLANEOUS_WARNING, MISCELLANEOUS_WARNING) \ - XX(200, OK, OK) \ - XX(201, CREATED, CREATED) \ - XX(202, ACCEPTED, ACCEPTED) \ - XX(203, NON_AUTHORITATIVE_INFORMATION, NON_AUTHORITATIVE_INFORMATION) \ - XX(204, NO_CONTENT, NO_CONTENT) \ - XX(205, RESET_CONTENT, RESET_CONTENT) \ - XX(206, PARTIAL_CONTENT, PARTIAL_CONTENT) \ - XX(207, MULTI_STATUS, MULTI_STATUS) \ - XX(208, ALREADY_REPORTED, ALREADY_REPORTED) \ - XX(214, TRANSFORMATION_APPLIED, TRANSFORMATION_APPLIED) \ - XX(226, IM_USED, IM_USED) \ - XX(299, MISCELLANEOUS_PERSISTENT_WARNING, MISCELLANEOUS_PERSISTENT_WARNING) \ - XX(300, MULTIPLE_CHOICES, MULTIPLE_CHOICES) \ - XX(301, MOVED_PERMANENTLY, MOVED_PERMANENTLY) \ - XX(302, FOUND, FOUND) \ - XX(303, SEE_OTHER, SEE_OTHER) \ - XX(304, NOT_MODIFIED, NOT_MODIFIED) \ - XX(305, USE_PROXY, USE_PROXY) \ - XX(306, SWITCH_PROXY, SWITCH_PROXY) \ - XX(307, TEMPORARY_REDIRECT, TEMPORARY_REDIRECT) \ - XX(308, PERMANENT_REDIRECT, PERMANENT_REDIRECT) \ - XX(400, BAD_REQUEST, BAD_REQUEST) \ - XX(401, UNAUTHORIZED, UNAUTHORIZED) \ - XX(402, PAYMENT_REQUIRED, PAYMENT_REQUIRED) \ - XX(403, FORBIDDEN, FORBIDDEN) \ - XX(404, NOT_FOUND, NOT_FOUND) \ - XX(405, METHOD_NOT_ALLOWED, METHOD_NOT_ALLOWED) \ - XX(406, NOT_ACCEPTABLE, NOT_ACCEPTABLE) \ - XX(407, PROXY_AUTHENTICATION_REQUIRED, PROXY_AUTHENTICATION_REQUIRED) \ - XX(408, REQUEST_TIMEOUT, REQUEST_TIMEOUT) \ - XX(409, CONFLICT, CONFLICT) \ - XX(410, GONE, GONE) \ - XX(411, LENGTH_REQUIRED, LENGTH_REQUIRED) \ - XX(412, PRECONDITION_FAILED, PRECONDITION_FAILED) \ - XX(413, PAYLOAD_TOO_LARGE, PAYLOAD_TOO_LARGE) \ - XX(414, URI_TOO_LONG, URI_TOO_LONG) \ - XX(415, UNSUPPORTED_MEDIA_TYPE, UNSUPPORTED_MEDIA_TYPE) \ - XX(416, RANGE_NOT_SATISFIABLE, RANGE_NOT_SATISFIABLE) \ - XX(417, EXPECTATION_FAILED, EXPECTATION_FAILED) \ - XX(418, IM_A_TEAPOT, IM_A_TEAPOT) \ - XX(419, PAGE_EXPIRED, PAGE_EXPIRED) \ - XX(420, ENHANCE_YOUR_CALM, ENHANCE_YOUR_CALM) \ - XX(421, MISDIRECTED_REQUEST, MISDIRECTED_REQUEST) \ - XX(422, UNPROCESSABLE_ENTITY, UNPROCESSABLE_ENTITY) \ - XX(423, LOCKED, LOCKED) \ - XX(424, FAILED_DEPENDENCY, FAILED_DEPENDENCY) \ - XX(425, TOO_EARLY, TOO_EARLY) \ - XX(426, UPGRADE_REQUIRED, UPGRADE_REQUIRED) \ - XX(428, PRECONDITION_REQUIRED, PRECONDITION_REQUIRED) \ - XX(429, TOO_MANY_REQUESTS, TOO_MANY_REQUESTS) \ - XX(430, REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL, REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL) \ - XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, REQUEST_HEADER_FIELDS_TOO_LARGE) \ - XX(440, LOGIN_TIMEOUT, LOGIN_TIMEOUT) \ - XX(444, NO_RESPONSE, NO_RESPONSE) \ - XX(449, RETRY_WITH, RETRY_WITH) \ - XX(450, BLOCKED_BY_PARENTAL_CONTROL, BLOCKED_BY_PARENTAL_CONTROL) \ - XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, UNAVAILABLE_FOR_LEGAL_REASONS) \ - XX(460, CLIENT_CLOSED_LOAD_BALANCED_REQUEST, CLIENT_CLOSED_LOAD_BALANCED_REQUEST) \ - XX(463, INVALID_X_FORWARDED_FOR, INVALID_X_FORWARDED_FOR) \ - XX(494, REQUEST_HEADER_TOO_LARGE, REQUEST_HEADER_TOO_LARGE) \ - XX(495, SSL_CERTIFICATE_ERROR, SSL_CERTIFICATE_ERROR) \ - XX(496, SSL_CERTIFICATE_REQUIRED, SSL_CERTIFICATE_REQUIRED) \ - XX(497, HTTP_REQUEST_SENT_TO_HTTPS_PORT, HTTP_REQUEST_SENT_TO_HTTPS_PORT) \ - XX(498, INVALID_TOKEN, INVALID_TOKEN) \ - XX(499, CLIENT_CLOSED_REQUEST, CLIENT_CLOSED_REQUEST) \ - XX(500, INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR) \ - XX(501, NOT_IMPLEMENTED, NOT_IMPLEMENTED) \ - XX(502, BAD_GATEWAY, BAD_GATEWAY) \ - XX(503, SERVICE_UNAVAILABLE, SERVICE_UNAVAILABLE) \ - XX(504, GATEWAY_TIMEOUT, GATEWAY_TIMEOUT) \ - XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP_VERSION_NOT_SUPPORTED) \ - XX(506, VARIANT_ALSO_NEGOTIATES, VARIANT_ALSO_NEGOTIATES) \ - XX(507, INSUFFICIENT_STORAGE, INSUFFICIENT_STORAGE) \ - XX(508, LOOP_DETECTED, LOOP_DETECTED) \ - XX(509, BANDWIDTH_LIMIT_EXCEEDED, BANDWIDTH_LIMIT_EXCEEDED) \ - XX(510, NOT_EXTENDED, NOT_EXTENDED) \ - XX(511, NETWORK_AUTHENTICATION_REQUIRED, NETWORK_AUTHENTICATION_REQUIRED) \ - XX(520, WEB_SERVER_UNKNOWN_ERROR, WEB_SERVER_UNKNOWN_ERROR) \ - XX(521, WEB_SERVER_IS_DOWN, WEB_SERVER_IS_DOWN) \ - XX(522, CONNECTION_TIMEOUT, CONNECTION_TIMEOUT) \ - XX(523, ORIGIN_IS_UNREACHABLE, ORIGIN_IS_UNREACHABLE) \ - XX(524, TIMEOUT_OCCURED, TIMEOUT_OCCURED) \ - XX(525, SSL_HANDSHAKE_FAILED, SSL_HANDSHAKE_FAILED) \ - XX(526, INVALID_SSL_CERTIFICATE, INVALID_SSL_CERTIFICATE) \ - XX(527, RAILGUN_ERROR, RAILGUN_ERROR) \ - XX(529, SITE_IS_OVERLOADED, SITE_IS_OVERLOADED) \ - XX(530, SITE_IS_FROZEN, SITE_IS_FROZEN) \ - XX(561, IDENTITY_PROVIDER_AUTHENTICATION_ERROR, IDENTITY_PROVIDER_AUTHENTICATION_ERROR) \ - XX(598, NETWORK_READ_TIMEOUT, NETWORK_READ_TIMEOUT) \ - XX(599, NETWORK_CONNECT_TIMEOUT, NETWORK_CONNECT_TIMEOUT) \ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif -#endif /* LLLLHTTP_C_HEADERS_ */ - - -#ifndef INCLUDE_LLHTTP_API_H_ -#define INCLUDE_LLHTTP_API_H_ -#ifdef __cplusplus -extern "C" { -#endif -#include - -#define LLHTTP_EXPORT - -typedef llhttp__internal_t llhttp_t; -typedef struct llhttp_settings_s llhttp_settings_t; - -typedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length); -typedef int (*llhttp_cb)(llhttp_t*); - -struct llhttp_settings_s { - /* Possible return values 0, -1, `HPE_PAUSED` */ - llhttp_cb on_message_begin; - - /* Possible return values 0, -1, HPE_USER */ - llhttp_data_cb on_url; - llhttp_data_cb on_status; - llhttp_data_cb on_method; - llhttp_data_cb on_version; - llhttp_data_cb on_header_field; - llhttp_data_cb on_header_value; - llhttp_data_cb on_chunk_extension_name; - llhttp_data_cb on_chunk_extension_value; - - /* Possible return values: - * 0 - Proceed normally - * 1 - Assume that request/response has no body, and proceed to parsing the - * next message - * 2 - Assume absence of body (as above) and make `llhttp_execute()` return - * `HPE_PAUSED_UPGRADE` - * -1 - Error - * `HPE_PAUSED` - */ - llhttp_cb on_headers_complete; - - /* Possible return values 0, -1, HPE_USER */ - llhttp_data_cb on_body; - - /* Possible return values 0, -1, `HPE_PAUSED` */ - llhttp_cb on_message_complete; - llhttp_cb on_url_complete; - llhttp_cb on_status_complete; - llhttp_cb on_method_complete; - llhttp_cb on_version_complete; - llhttp_cb on_header_field_complete; - llhttp_cb on_header_value_complete; - llhttp_cb on_chunk_extension_name_complete; - llhttp_cb on_chunk_extension_value_complete; - - /* When on_chunk_header is called, the current chunk length is stored - * in parser->content_length. - * Possible return values 0, -1, `HPE_PAUSED` - */ - llhttp_cb on_chunk_header; - llhttp_cb on_chunk_complete; - llhttp_cb on_reset; -}; - -/* Initialize the parser with specific type and user settings. - * - * NOTE: lifetime of `settings` has to be at least the same as the lifetime of - * the `parser` here. In practice, `settings` has to be either a static - * variable or be allocated with `malloc`, `new`, etc. - */ -LLHTTP_EXPORT -void llhttp_init(llhttp_t* parser, llhttp_type_t type, - const llhttp_settings_t* settings); - -LLHTTP_EXPORT -llhttp_t* llhttp_alloc(llhttp_type_t type); - -LLHTTP_EXPORT -void llhttp_free(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_type(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_http_major(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_http_minor(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_method(llhttp_t* parser); - -LLHTTP_EXPORT -int llhttp_get_status_code(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_upgrade(llhttp_t* parser); - -/* Reset an already initialized parser back to the start state, preserving the - * existing parser type, callback settings, user data, and lenient flags. - */ -LLHTTP_EXPORT -void llhttp_reset(llhttp_t* parser); - -/* Initialize the settings object */ -LLHTTP_EXPORT -void llhttp_settings_init(llhttp_settings_t* settings); - -/* Parse full or partial request/response, invoking user callbacks along the - * way. - * - * If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing - * interrupts, and such errno is returned from `llhttp_execute()`. If - * `HPE_PAUSED` was used as a errno, the execution can be resumed with - * `llhttp_resume()` call. - * - * In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE` - * is returned after fully parsing the request/response. If the user wishes to - * continue parsing, they need to invoke `llhttp_resume_after_upgrade()`. - * - * NOTE: if this function ever returns a non-pause type error, it will continue - * to return the same error upon each successive call up until `llhttp_init()` - * is called. - */ -LLHTTP_EXPORT -llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len); - -/* This method should be called when the other side has no further bytes to - * send (e.g. shutdown of readable side of the TCP connection.) - * - * Requests without `Content-Length` and other messages might require treating - * all incoming bytes as the part of the body, up to the last byte of the - * connection. This method will invoke `on_message_complete()` callback if the - * request was terminated safely. Otherwise a error code would be returned. - */ -LLHTTP_EXPORT -llhttp_errno_t llhttp_finish(llhttp_t* parser); - -/* Returns `1` if the incoming message is parsed until the last byte, and has - * to be completed by calling `llhttp_finish()` on EOF - */ -LLHTTP_EXPORT -int llhttp_message_needs_eof(const llhttp_t* parser); - -/* Returns `1` if there might be any other messages following the last that was - * successfully parsed. - */ -LLHTTP_EXPORT -int llhttp_should_keep_alive(const llhttp_t* parser); - -/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set - * appropriate error reason. - * - * Important: do not call this from user callbacks! User callbacks must return - * `HPE_PAUSED` if pausing is required. - */ -LLHTTP_EXPORT -void llhttp_pause(llhttp_t* parser); - -/* Might be called to resume the execution after the pause in user's callback. - * See `llhttp_execute()` above for details. - * - * Call this only if `llhttp_execute()` returns `HPE_PAUSED`. - */ -LLHTTP_EXPORT -void llhttp_resume(llhttp_t* parser); - -/* Might be called to resume the execution after the pause in user's callback. - * See `llhttp_execute()` above for details. - * - * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE` - */ -LLHTTP_EXPORT -void llhttp_resume_after_upgrade(llhttp_t* parser); - -/* Returns the latest return error */ -LLHTTP_EXPORT -llhttp_errno_t llhttp_get_errno(const llhttp_t* parser); - -/* Returns the verbal explanation of the latest returned error. - * - * Note: User callback should set error reason when returning the error. See - * `llhttp_set_error_reason()` for details. - */ -LLHTTP_EXPORT -const char* llhttp_get_error_reason(const llhttp_t* parser); - -/* Assign verbal description to the returned error. Must be called in user - * callbacks right before returning the errno. - * - * Note: `HPE_USER` error code might be useful in user callbacks. - */ -LLHTTP_EXPORT -void llhttp_set_error_reason(llhttp_t* parser, const char* reason); - -/* Returns the pointer to the last parsed byte before the returned error. The - * pointer is relative to the `data` argument of `llhttp_execute()`. - * - * Note: this method might be useful for counting the number of parsed bytes. - */ -LLHTTP_EXPORT -const char* llhttp_get_error_pos(const llhttp_t* parser); - -/* Returns textual name of error code */ -LLHTTP_EXPORT -const char* llhttp_errno_name(llhttp_errno_t err); - -/* Returns textual name of HTTP method */ -LLHTTP_EXPORT -const char* llhttp_method_name(llhttp_method_t method); - -/* Returns textual name of HTTP status */ -LLHTTP_EXPORT -const char* llhttp_status_name(llhttp_status_t status); - -/* Enables/disables lenient header value parsing (disabled by default). - * - * Lenient parsing disables header value token checks, extending llhttp's - * protocol support to highly non-compliant clients/server. No - * `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when - * lenient parsing is "on". - * - * **Enabling this flag can pose a security issue since you will be exposed to - * request smuggling attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_headers(llhttp_t* parser, int enabled); - - -/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and - * `Content-Length` headers (disabled by default). - * - * Normally `llhttp` would error when `Transfer-Encoding` is present in - * conjunction with `Content-Length`. This error is important to prevent HTTP - * request smuggling, but may be less desirable for small number of cases - * involving legacy servers. - * - * **Enabling this flag can pose a security issue since you will be exposed to - * request smuggling attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled); - - -/* Enables/disables lenient handling of `Connection: close` and HTTP/1.0 - * requests responses. - * - * Normally `llhttp` would error on (in strict mode) or discard (in loose mode) - * the HTTP request/response after the request/response with `Connection: close` - * and `Content-Length`. This is important to prevent cache poisoning attacks, - * but might interact badly with outdated and insecure clients. With this flag - * the extra request/response will be parsed normally. - * - * **Enabling this flag can pose a security issue since you will be exposed to - * poisoning attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled); - -/* Enables/disables lenient handling of `Transfer-Encoding` header. - * - * Normally `llhttp` would error when a `Transfer-Encoding` has `chunked` value - * and another value after it (either in a single header or in multiple - * headers whose value are internally joined using `, `). - * This is mandated by the spec to reliably determine request body size and thus - * avoid request smuggling. - * With this flag the extra value will be parsed normally. - * - * **Enabling this flag can pose a security issue since you will be exposed to - * request smuggling attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled); - -/* Enables/disables lenient handling of HTTP version. - * - * Normally `llhttp` would error when the HTTP version in the request or status line - * is not `0.9`, `1.0`, `1.1` or `2.0`. - * With this flag the invalid value will be parsed normally. - * - * **Enabling this flag can pose a security issue since you will allow unsupported - * HTTP versions. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_version(llhttp_t* parser, int enabled); - -/* Enables/disables lenient handling of additional data received after a message ends - * and keep-alive is disabled. - * - * Normally `llhttp` would error when additional unexpected data is received if the message - * contains the `Connection` header with `close` value. - * With this flag the extra data will discarded without throwing an error. - * - * **Enabling this flag can pose a security issue since you will be exposed to - * poisoning attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled); - -/* Enables/disables lenient handling of incomplete CRLF sequences. - * - * Normally `llhttp` would error when a CR is not followed by LF when terminating the - * request line, the status line, the headers or a chunk header. - * With this flag only a CR is required to terminate such sections. - * - * **Enabling this flag can pose a security issue since you will be exposed to - * request smuggling attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled); - -/* - * Enables/disables lenient handling of line separators. - * - * Normally `llhttp` would error when a LF is not preceded by CR when terminating the - * request line, the status line, the headers, a chunk header or a chunk data. - * With this flag only a LF is required to terminate such sections. - * - * **Enabling this flag can pose a security issue since you will be exposed to - * request smuggling attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled); - -/* Enables/disables lenient handling of chunks not separated via CRLF. - * - * Normally `llhttp` would error when after a chunk data a CRLF is missing before - * starting a new chunk. - * With this flag the new chunk can start immediately after the previous one. - * - * **Enabling this flag can pose a security issue since you will be exposed to - * request smuggling attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled); - -/* Enables/disables lenient handling of spaces after chunk size. - * - * Normally `llhttp` would error when after a chunk size is followed by one or more - * spaces are present instead of a CRLF or `;`. - * With this flag this check is disabled. - * - * **Enabling this flag can pose a security issue since you will be exposed to - * request smuggling attacks. USE WITH CAUTION!** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled); - -#ifdef __cplusplus -} /* extern "C" */ -#endif -#endif /* INCLUDE_LLHTTP_API_H_ */ - - -#endif /* INCLUDE_LLHTTP_H_ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/CMakeLists.txt b/vendor/libgit2-sys/libgit2/deps/ntlmclient/CMakeLists.txt deleted file mode 100644 index f1f5de1..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -file(GLOB SRC_NTLMCLIENT "ntlm.c" "ntlm.h" "util.c" "util.h") -list(SORT SRC_NTLMCLIENT) - -add_definitions(-DNTLM_STATIC=1) - -disable_warnings(implicit-fallthrough) - -if(USE_ICONV) - add_definitions(-DUNICODE_ICONV=1) - file(GLOB SRC_NTLMCLIENT_UNICODE "unicode_iconv.c" "unicode_iconv.h") -else() - add_definitions(-DUNICODE_BUILTIN=1) - file(GLOB SRC_NTLMCLIENT_UNICODE "unicode_builtin.c" "unicode_builtin.h") -endif() - -if(USE_HTTPS STREQUAL "SecureTransport") - add_definitions(-DCRYPT_COMMONCRYPTO) - set(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c" "crypt_commoncrypto.h") - # CC_MD4 has been deprecated in macOS 10.15. - set_source_files_properties("crypt_commoncrypto.c" COMPILE_FLAGS "-Wno-deprecated") -elseif(USE_HTTPS STREQUAL "OpenSSL") - add_definitions(-DCRYPT_OPENSSL) - add_definitions(-DOPENSSL_API_COMPAT=0x10100000L) - include_directories(${OPENSSL_INCLUDE_DIR}) - set(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h") -elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic") - add_definitions(-DCRYPT_OPENSSL) - add_definitions(-DCRYPT_OPENSSL_DYNAMIC) - add_definitions(-DOPENSSL_API_COMPAT=0x10100000L) - set(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h") -elseif(USE_HTTPS STREQUAL "mbedTLS") - add_definitions(-DCRYPT_MBEDTLS) - include_directories(${MBEDTLS_INCLUDE_DIR}) - set(SRC_NTLMCLIENT_CRYPTO "crypt_mbedtls.c" "crypt_mbedtls.h" "crypt_builtin_md4.c") -else() - message(FATAL_ERROR "Unable to use libgit2's HTTPS backend (${USE_HTTPS}) for NTLM crypto") -endif() - -add_library(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_UNICODE} ${SRC_NTLMCLIENT_CRYPTO}) diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/compat.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/compat.h deleted file mode 100644 index befc7cc..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/compat.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_COMPAT_H__ -#define PRIVATE_COMPAT_H__ - -#if defined (_MSC_VER) - typedef unsigned char bool; -# ifndef true -# define true 1 -# endif -# ifndef false -# define false 0 -# endif -#else -# include -#endif - -#ifndef MIN -# define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#endif - -#endif /* PRIVATE_COMPAT_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt.h deleted file mode 100644 index 4ad543e..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_CRYPT_COMMON_H__ -#define PRIVATE_CRYPT_COMMON_H__ - -#include "ntlmclient.h" -#include "ntlm.h" - -#if defined(CRYPT_OPENSSL) -# include "crypt_openssl.h" -#elif defined(CRYPT_MBEDTLS) -# include "crypt_mbedtls.h" -#elif defined(CRYPT_COMMONCRYPTO) -# include "crypt_commoncrypto.h" -#else -# error "no crypto support" -#endif - -#define CRYPT_DES_BLOCKSIZE 8 -#define CRYPT_MD4_DIGESTSIZE 16 -#define CRYPT_MD5_DIGESTSIZE 16 - -typedef unsigned char ntlm_des_block[CRYPT_DES_BLOCKSIZE]; - -typedef struct ntlm_crypt_ctx ntlm_crypt_ctx; - -extern bool ntlm_crypt_init(ntlm_client *ntlm); - -extern bool ntlm_random_bytes( - unsigned char *out, - ntlm_client *ntlm, - size_t len); - -extern bool ntlm_des_encrypt( - ntlm_des_block *out, - ntlm_client *ntlm, - ntlm_des_block *plaintext, - ntlm_des_block *key); - -extern bool ntlm_md4_digest( - unsigned char out[CRYPT_MD4_DIGESTSIZE], - ntlm_client *ntlm, - const unsigned char *in, - size_t in_len); - -extern bool ntlm_hmac_md5_init( - ntlm_client *ntlm, - const unsigned char *key, - size_t key_len); - -extern bool ntlm_hmac_md5_update( - ntlm_client *ntlm, - const unsigned char *data, - size_t data_len); - -extern bool ntlm_hmac_md5_final( - unsigned char *out, - size_t *out_len, - ntlm_client *ntlm); - -extern void ntlm_crypt_shutdown(ntlm_client *ntlm); - -#endif /* PRIVATE_CRYPT_COMMON_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_builtin_md4.c b/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_builtin_md4.c deleted file mode 100644 index de9a85c..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_builtin_md4.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#include -#include - -#include "ntlm.h" -#include "crypt.h" - -/* - * Below is the MD4 code from RFC 1320, with minor modifications - * to make it compile on a modern compiler. It is included since - * many system crypto libraries lack MD4, sensibly. - */ - -/* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm - */ - -/* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved. - - License to copy and use this software is granted provided that it - is identified as the "RSA Data Security, Inc. MD4 Message-Digest - Algorithm" in all material mentioning or referencing this software - or this function. - - License is also granted to make and use derivative works provided - that such works are identified as "derived from the RSA Data - Security, Inc. MD4 Message-Digest Algorithm" in all material - mentioning or referencing the derived work. - - RSA Data Security, Inc. makes no representations concerning either - the merchantability of this software or the suitability of this - software for any particular purpose. It is provided "as is" - without express or implied warranty of any kind. - - These notices must be retained in any copies of any part of this - documentation and/or software. - */ - -/* POINTER defines a generic pointer type */ -typedef unsigned char *POINTER; - -/* UINT2 defines a two byte word */ -typedef uint16_t UINT2; - -/* UINT4 defines a four byte word */ -typedef uint32_t UINT4; - -#define MD4_memcpy memcpy -#define MD4_memset memset - -/* MD4 context. */ -typedef struct { - UINT4 state[4]; /* state (ABCD) */ - UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} MD4_CTX; - -/* Constants for MD4Transform routine. - */ -#define S11 3 -#define S12 7 -#define S13 11 -#define S14 19 -#define S21 3 -#define S22 5 -#define S23 9 -#define S24 13 -#define S31 3 -#define S32 9 -#define S33 11 -#define S34 15 - -static void MD4Transform(UINT4 [4], const unsigned char [64]); -static void Encode (unsigned char *, UINT4 *, unsigned int); -static void Decode (UINT4 *, const unsigned char *, unsigned int); - -static unsigned char PADDING[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* F, G and H are basic MD4 functions. - */ -#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) -#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) - -/* ROTATE_LEFT rotates x left n bits. - */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -/* FF, GG and HH are transformations for rounds 1, 2 and 3 */ -/* Rotation is separate from addition to prevent recomputation */ -#define FF(a, b, c, d, x, s) { \ - (a) += F ((b), (c), (d)) + (x); \ - (a) = ROTATE_LEFT ((a), (s)); \ - } -#define GG(a, b, c, d, x, s) { \ - (a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \ - (a) = ROTATE_LEFT ((a), (s)); \ - } -#define HH(a, b, c, d, x, s) { \ - (a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \ - (a) = ROTATE_LEFT ((a), (s)); \ - } - -/* MD4 initialization. Begins an MD4 operation, writing a new context. - */ -static void MD4Init (MD4_CTX *context) -{ - context->count[0] = context->count[1] = 0; - - /* Load magic initialization constants. - */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; -} - -/* MD4 block update operation. Continues an MD4 message-digest - operation, processing another message block, and updating the - context. - */ -static void MD4Update (MD4_CTX *context, const unsigned char *input, unsigned int inputLen) -{ - unsigned int i, index, partLen; - - /* Compute number of bytes mod 64 */ - index = (unsigned int)((context->count[0] >> 3) & 0x3F); - /* Update number of bits */ - if ((context->count[0] += ((UINT4)inputLen << 3)) - < ((UINT4)inputLen << 3)) - context->count[1]++; - context->count[1] += ((UINT4)inputLen >> 29); - - partLen = 64 - index; - - /* Transform as many times as possible. - */ - if (inputLen >= partLen) { - MD4_memcpy - ((POINTER)&context->buffer[index], (POINTER)input, partLen); - MD4Transform (context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - MD4Transform (context->state, &input[i]); - - index = 0; - } - else - i = 0; - - /* Buffer remaining input */ - MD4_memcpy - ((POINTER)&context->buffer[index], (POINTER)&input[i], - inputLen-i); -} - -/* MD4 finalization. Ends an MD4 message-digest operation, writing the - the message digest and zeroizing the context. - */ -static void MD4Final (unsigned char digest[16], MD4_CTX *context) -{ - unsigned char bits[8]; - unsigned int index, padLen; - - /* Save number of bits */ - Encode (bits, context->count, 8); - - /* Pad out to 56 mod 64. - */ - index = (unsigned int)((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); - MD4Update (context, PADDING, padLen); - - /* Append length (before padding) */ - MD4Update (context, bits, 8); - /* Store state in digest */ - Encode (digest, context->state, 16); - - /* Zeroize sensitive information. - */ - MD4_memset ((POINTER)context, 0, sizeof (*context)); -} - -/* MD4 basic transformation. Transforms state based on block. - */ -static void MD4Transform (UINT4 state[4], const unsigned char block[64]) -{ - UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; - - Decode (x, block, 64); - - /* Round 1 */ - FF (a, b, c, d, x[ 0], S11); /* 1 */ - FF (d, a, b, c, x[ 1], S12); /* 2 */ - FF (c, d, a, b, x[ 2], S13); /* 3 */ - FF (b, c, d, a, x[ 3], S14); /* 4 */ - FF (a, b, c, d, x[ 4], S11); /* 5 */ - FF (d, a, b, c, x[ 5], S12); /* 6 */ - FF (c, d, a, b, x[ 6], S13); /* 7 */ - FF (b, c, d, a, x[ 7], S14); /* 8 */ - FF (a, b, c, d, x[ 8], S11); /* 9 */ - FF (d, a, b, c, x[ 9], S12); /* 10 */ - FF (c, d, a, b, x[10], S13); /* 11 */ - FF (b, c, d, a, x[11], S14); /* 12 */ - FF (a, b, c, d, x[12], S11); /* 13 */ - FF (d, a, b, c, x[13], S12); /* 14 */ - FF (c, d, a, b, x[14], S13); /* 15 */ - FF (b, c, d, a, x[15], S14); /* 16 */ - - /* Round 2 */ - GG (a, b, c, d, x[ 0], S21); /* 17 */ - GG (d, a, b, c, x[ 4], S22); /* 18 */ - GG (c, d, a, b, x[ 8], S23); /* 19 */ - GG (b, c, d, a, x[12], S24); /* 20 */ - GG (a, b, c, d, x[ 1], S21); /* 21 */ - GG (d, a, b, c, x[ 5], S22); /* 22 */ - GG (c, d, a, b, x[ 9], S23); /* 23 */ - GG (b, c, d, a, x[13], S24); /* 24 */ - GG (a, b, c, d, x[ 2], S21); /* 25 */ - GG (d, a, b, c, x[ 6], S22); /* 26 */ - GG (c, d, a, b, x[10], S23); /* 27 */ - GG (b, c, d, a, x[14], S24); /* 28 */ - GG (a, b, c, d, x[ 3], S21); /* 29 */ - GG (d, a, b, c, x[ 7], S22); /* 30 */ - GG (c, d, a, b, x[11], S23); /* 31 */ - GG (b, c, d, a, x[15], S24); /* 32 */ - - /* Round 3 */ - HH (a, b, c, d, x[ 0], S31); /* 33 */ - HH (d, a, b, c, x[ 8], S32); /* 34 */ - HH (c, d, a, b, x[ 4], S33); /* 35 */ - HH (b, c, d, a, x[12], S34); /* 36 */ - HH (a, b, c, d, x[ 2], S31); /* 37 */ - HH (d, a, b, c, x[10], S32); /* 38 */ - HH (c, d, a, b, x[ 6], S33); /* 39 */ - HH (b, c, d, a, x[14], S34); /* 40 */ - HH (a, b, c, d, x[ 1], S31); /* 41 */ - HH (d, a, b, c, x[ 9], S32); /* 42 */ - HH (c, d, a, b, x[ 5], S33); /* 43 */ - HH (b, c, d, a, x[13], S34); /* 44 */ - HH (a, b, c, d, x[ 3], S31); /* 45 */ - HH (d, a, b, c, x[11], S32); /* 46 */ - HH (c, d, a, b, x[ 7], S33); /* 47 */ - HH (b, c, d, a, x[15], S34); /* 48 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - - /* Zeroize sensitive information. - */ - MD4_memset ((POINTER)x, 0, sizeof (x)); -} - -/* Encodes input (UINT4) into output (unsigned char). Assumes len is - a multiple of 4. - */ -static void Encode (unsigned char *output, UINT4 *input, unsigned int len) -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char)(input[i] & 0xff); - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); - } -} - -/* Decodes input (unsigned char) into output (UINT4). Assumes len is - a multiple of 4. - */ -static void Decode (UINT4 *output, const unsigned char *input, unsigned int len) -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | - (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); -} - -bool ntlm_md4_digest( - unsigned char out[CRYPT_MD4_DIGESTSIZE], - ntlm_client *ntlm, - const unsigned char *in, - size_t in_len) -{ - MD4_CTX ctx; - - NTLM_UNUSED(ntlm); - - if (in_len > UINT_MAX) - return false; - - MD4Init(&ctx); - MD4Update(&ctx, in, (unsigned int)in_len); - MD4Final (out, &ctx); - - return true; -} diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_commoncrypto.c b/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_commoncrypto.c deleted file mode 100644 index 3c20469..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_commoncrypto.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#include -#include -#include -#include -#include -#include - -#include - -#include "ntlm.h" -#include "crypt.h" - -bool ntlm_crypt_init(ntlm_client *ntlm) -{ - memset(&ntlm->crypt_ctx, 0, sizeof(ntlm_crypt_ctx)); - return true; -} - -bool ntlm_random_bytes( - unsigned char *out, - ntlm_client *ntlm, - size_t len) -{ - int fd, ret; - size_t total = 0; - - if ((fd = open("/dev/urandom", O_RDONLY)) < 0) { - ntlm_client_set_errmsg(ntlm, strerror(errno)); - return false; - } - - while (total < len) { - if ((ret = read(fd, out, (len - total))) < 0) { - ntlm_client_set_errmsg(ntlm, strerror(errno)); - return false; - } else if (ret == 0) { - ntlm_client_set_errmsg(ntlm, "unexpected eof on random device"); - return false; - } - - total += ret; - } - - close(fd); - return true; -} - -bool ntlm_des_encrypt( - ntlm_des_block *out, - ntlm_client *ntlm, - ntlm_des_block *plaintext, - ntlm_des_block *key) -{ - CCCryptorStatus result; - size_t written; - - NTLM_UNUSED(ntlm); - - result = CCCrypt(kCCEncrypt, - kCCAlgorithmDES, kCCOptionECBMode, - key, sizeof(ntlm_des_block), NULL, - plaintext, sizeof(ntlm_des_block), - out, sizeof(ntlm_des_block), &written); - - return (result == kCCSuccess) ? true : false; -} - -bool ntlm_md4_digest( - unsigned char out[CRYPT_MD4_DIGESTSIZE], - ntlm_client *ntlm, - const unsigned char *in, - size_t in_len) -{ - NTLM_UNUSED(ntlm); - return !!CC_MD4(in, in_len, out); -} - -bool ntlm_hmac_md5_init( - ntlm_client *ntlm, - const unsigned char *key, - size_t key_len) -{ - CCHmacInit(&ntlm->crypt_ctx.hmac, kCCHmacAlgMD5, key, key_len); - return true; -} - -bool ntlm_hmac_md5_update( - ntlm_client *ntlm, - const unsigned char *data, - size_t data_len) -{ - CCHmacUpdate(&ntlm->crypt_ctx.hmac, data, data_len); - return true; -} - -bool ntlm_hmac_md5_final( - unsigned char *out, - size_t *out_len, - ntlm_client *ntlm) -{ - if (*out_len < CRYPT_MD5_DIGESTSIZE) - return false; - - CCHmacFinal(&ntlm->crypt_ctx.hmac, out); - - *out_len = CRYPT_MD5_DIGESTSIZE; - return true; -} - -void ntlm_crypt_shutdown(ntlm_client *ntlm) -{ - NTLM_UNUSED(ntlm); -} diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_commoncrypto.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_commoncrypto.h deleted file mode 100644 index e4df91d..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_commoncrypto.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_CRYPT_COMMONCRYPTO_H__ -#define PRIVATE_CRYPT_COMMONCRYPTO_H__ - -#include - -struct ntlm_crypt_ctx { - CCHmacContext hmac; -}; - -#endif /* PRIVATE_CRYPT_COMMONCRYPTO_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_mbedtls.c b/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_mbedtls.c deleted file mode 100644 index 4bbb878..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_mbedtls.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#include -#include - -#include "mbedtls/ctr_drbg.h" -#include "mbedtls/des.h" -#include "mbedtls/entropy.h" - -#include "ntlm.h" -#include "crypt.h" - -bool ntlm_crypt_init(ntlm_client *ntlm) -{ - const mbedtls_md_info_t *info = mbedtls_md_info_from_type(MBEDTLS_MD_MD5); - - mbedtls_md_init(&ntlm->crypt_ctx.hmac); - - if (mbedtls_md_setup(&ntlm->crypt_ctx.hmac, info, 1) != 0) { - ntlm_client_set_errmsg(ntlm, "could not setup mbedtls digest"); - return false; - } - - return true; -} - - -bool ntlm_random_bytes( - unsigned char *out, - ntlm_client *ntlm, - size_t len) -{ - mbedtls_ctr_drbg_context ctr_drbg; - mbedtls_entropy_context entropy; - bool ret = true; - - const unsigned char personalization[] = { - 0xec, 0xb5, 0xd1, 0x0b, 0x8f, 0x15, 0x1f, 0xc2, - 0xe4, 0x8e, 0xec, 0x36, 0xf7, 0x0a, 0x45, 0x9a, - 0x1f, 0xe1, 0x35, 0x58, 0xb1, 0xcb, 0xfd, 0x8a, - 0x57, 0x5c, 0x75, 0x7d, 0x2f, 0xc9, 0x70, 0xac - }; - - mbedtls_ctr_drbg_init(&ctr_drbg); - mbedtls_entropy_init(&entropy); - - if (mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, - &entropy, personalization, sizeof(personalization)) || - mbedtls_ctr_drbg_random(&ctr_drbg, out, len)) { - ntlm_client_set_errmsg(ntlm, "random generation failed"); - ret = false; - } - - mbedtls_entropy_free(&entropy); - mbedtls_ctr_drbg_free(&ctr_drbg); - - return ret; -} - -bool ntlm_des_encrypt( - ntlm_des_block *out, - ntlm_client *ntlm, - ntlm_des_block *plaintext, - ntlm_des_block *key) -{ - mbedtls_des_context ctx; - bool success = false; - - mbedtls_des_init(&ctx); - - if (mbedtls_des_setkey_enc(&ctx, *key) || - mbedtls_des_crypt_ecb(&ctx, *plaintext, *out)) { - ntlm_client_set_errmsg(ntlm, "DES encryption failed"); - goto done; - } - - success = true; - -done: - mbedtls_des_free(&ctx); - return success; -} - -bool ntlm_hmac_md5_init( - ntlm_client *ntlm, - const unsigned char *key, - size_t key_len) -{ - if (ntlm->crypt_ctx.hmac_initialized) { - if (mbedtls_md_hmac_reset(&ntlm->crypt_ctx.hmac)) - return false; - } - - ntlm->crypt_ctx.hmac_initialized = !mbedtls_md_hmac_starts(&ntlm->crypt_ctx.hmac, key, key_len); - return ntlm->crypt_ctx.hmac_initialized; -} - -bool ntlm_hmac_md5_update( - ntlm_client *ntlm, - const unsigned char *in, - size_t in_len) -{ - return !mbedtls_md_hmac_update(&ntlm->crypt_ctx.hmac, in, in_len); -} - -bool ntlm_hmac_md5_final( - unsigned char *out, - size_t *out_len, - ntlm_client *ntlm) -{ - if (*out_len < CRYPT_MD5_DIGESTSIZE) - return false; - - return !mbedtls_md_hmac_finish(&ntlm->crypt_ctx.hmac, out); -} - -void ntlm_crypt_shutdown(ntlm_client *ntlm) -{ - mbedtls_md_free(&ntlm->crypt_ctx.hmac); -} diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_mbedtls.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_mbedtls.h deleted file mode 100644 index 2fc8503..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_mbedtls.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_CRYPT_MBEDTLS_H__ -#define PRIVATE_CRYPT_MBEDTLS_H__ - -#include "mbedtls/md.h" - -struct ntlm_crypt_ctx { - mbedtls_md_context_t hmac; - unsigned int hmac_initialized : 1; -}; - -#endif /* PRIVATE_CRYPT_MBEDTLS_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_openssl.c b/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_openssl.c deleted file mode 100644 index 3bec272..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_openssl.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#include -#include - -#ifdef CRYPT_OPENSSL_DYNAMIC -# include -#else -# include -# include -# include -# include -# include -#endif - -#include "ntlm.h" -#include "compat.h" -#include "util.h" -#include "crypt.h" - -#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(CRYPT_OPENSSL_DYNAMIC) - -NTLM_INLINE(HMAC_CTX *) HMAC_CTX_new(void) -{ - return calloc(1, sizeof(HMAC_CTX)); -} - -NTLM_INLINE(int) HMAC_CTX_reset(HMAC_CTX *ctx) -{ - ntlm_memzero(ctx, sizeof(HMAC_CTX)); - return 1; -} - -NTLM_INLINE(void) HMAC_CTX_free(HMAC_CTX *ctx) -{ - free(ctx); -} - -#endif - -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)) || \ - (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x03050000fL) || \ - defined(CRYPT_OPENSSL_DYNAMIC) - -NTLM_INLINE(void) HMAC_CTX_cleanup(HMAC_CTX *ctx) -{ - NTLM_UNUSED(ctx); -} - -#endif - - -#ifdef CRYPT_OPENSSL_DYNAMIC - -static bool ntlm_crypt_init_functions(ntlm_client *ntlm) -{ - void *handle; - - if ((handle = dlopen("libssl.so.1.1", RTLD_NOW)) == NULL && - (handle = dlopen("libssl.1.1.dylib", RTLD_NOW)) == NULL && - (handle = dlopen("libssl.so.1.0.0", RTLD_NOW)) == NULL && - (handle = dlopen("libssl.1.0.0.dylib", RTLD_NOW)) == NULL && - (handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL) { - ntlm_client_set_errmsg(ntlm, "could not open libssl"); - return false; - } - - ntlm->crypt_ctx.des_set_key_fn = dlsym(handle, "DES_set_key"); - ntlm->crypt_ctx.des_ecb_encrypt_fn = dlsym(handle, "DES_ecb_encrypt"); - ntlm->crypt_ctx.err_get_error_fn = dlsym(handle, "ERR_get_error"); - ntlm->crypt_ctx.err_lib_error_string_fn = dlsym(handle, "ERR_lib_error_string"); - ntlm->crypt_ctx.evp_md5_fn = dlsym(handle, "EVP_md5"); - ntlm->crypt_ctx.hmac_ctx_new_fn = dlsym(handle, "HMAC_CTX_new"); - ntlm->crypt_ctx.hmac_ctx_free_fn = dlsym(handle, "HMAC_CTX_free"); - ntlm->crypt_ctx.hmac_ctx_reset_fn = dlsym(handle, "HMAC_CTX_reset"); - ntlm->crypt_ctx.hmac_init_ex_fn = dlsym(handle, "HMAC_Init_ex"); - ntlm->crypt_ctx.hmac_update_fn = dlsym(handle, "HMAC_Update"); - ntlm->crypt_ctx.hmac_final_fn = dlsym(handle, "HMAC_Final"); - ntlm->crypt_ctx.md4_fn = dlsym(handle, "MD4"); - ntlm->crypt_ctx.rand_bytes_fn = dlsym(handle, "RAND_bytes"); - - if (!ntlm->crypt_ctx.des_set_key_fn || - !ntlm->crypt_ctx.des_ecb_encrypt_fn || - !ntlm->crypt_ctx.err_get_error_fn || - !ntlm->crypt_ctx.err_lib_error_string_fn || - !ntlm->crypt_ctx.evp_md5_fn || - !ntlm->crypt_ctx.hmac_init_ex_fn || - !ntlm->crypt_ctx.hmac_update_fn || - !ntlm->crypt_ctx.hmac_final_fn || - !ntlm->crypt_ctx.md4_fn || - !ntlm->crypt_ctx.rand_bytes_fn) { - ntlm_client_set_errmsg(ntlm, "could not load libssl functions"); - dlclose(handle); - return false; - } - - /* Toggle legacy HMAC context functions */ - if (ntlm->crypt_ctx.hmac_ctx_new_fn && - ntlm->crypt_ctx.hmac_ctx_free_fn && - ntlm->crypt_ctx.hmac_ctx_reset_fn) { - ntlm->crypt_ctx.hmac_ctx_cleanup_fn = HMAC_CTX_cleanup; - } else { - ntlm->crypt_ctx.hmac_ctx_cleanup_fn = dlsym(handle, "HMAC_CTX_cleanup"); - - if (!ntlm->crypt_ctx.hmac_ctx_cleanup_fn) { - ntlm_client_set_errmsg(ntlm, "could not load legacy libssl functions"); - dlclose(handle); - return false; - } - - ntlm->crypt_ctx.hmac_ctx_new_fn = HMAC_CTX_new; - ntlm->crypt_ctx.hmac_ctx_free_fn = HMAC_CTX_free; - ntlm->crypt_ctx.hmac_ctx_reset_fn = HMAC_CTX_reset; - } - - ntlm->crypt_ctx.openssl_handle = handle; - return true; -} - -#else /* CRYPT_OPENSSL_DYNAMIC */ - -static bool ntlm_crypt_init_functions(ntlm_client *ntlm) -{ - ntlm->crypt_ctx.des_set_key_fn = DES_set_key; - ntlm->crypt_ctx.des_ecb_encrypt_fn = DES_ecb_encrypt; - ntlm->crypt_ctx.err_get_error_fn = ERR_get_error; - ntlm->crypt_ctx.err_lib_error_string_fn = ERR_lib_error_string; - ntlm->crypt_ctx.evp_md5_fn = EVP_md5; - ntlm->crypt_ctx.hmac_ctx_new_fn = HMAC_CTX_new; - ntlm->crypt_ctx.hmac_ctx_free_fn = HMAC_CTX_free; - ntlm->crypt_ctx.hmac_ctx_reset_fn = HMAC_CTX_reset; - ntlm->crypt_ctx.hmac_ctx_cleanup_fn = HMAC_CTX_cleanup; - ntlm->crypt_ctx.hmac_init_ex_fn = HMAC_Init_ex; - ntlm->crypt_ctx.hmac_update_fn = HMAC_Update; - ntlm->crypt_ctx.hmac_final_fn = HMAC_Final; - ntlm->crypt_ctx.md4_fn = MD4; - ntlm->crypt_ctx.rand_bytes_fn = RAND_bytes; - - return true; -} - -#endif /* CRYPT_OPENSSL_DYNAMIC */ - -bool ntlm_crypt_init(ntlm_client *ntlm) -{ - if (!ntlm_crypt_init_functions(ntlm)) - return false; - - ntlm->crypt_ctx.hmac = ntlm->crypt_ctx.hmac_ctx_new_fn(); - - if (ntlm->crypt_ctx.hmac == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return false; - } - - return true; -} - -bool ntlm_random_bytes( - unsigned char *out, - ntlm_client *ntlm, - size_t len) -{ - int rc = ntlm->crypt_ctx.rand_bytes_fn(out, len); - - if (rc != 1) { - ntlm_client_set_errmsg(ntlm, ntlm->crypt_ctx.err_lib_error_string_fn(ntlm->crypt_ctx.err_get_error_fn())); - return false; - } - - return true; -} - -bool ntlm_des_encrypt( - ntlm_des_block *out, - ntlm_client *ntlm, - ntlm_des_block *plaintext, - ntlm_des_block *key) -{ - DES_key_schedule keysched; - - NTLM_UNUSED(ntlm); - - memset(out, 0, sizeof(ntlm_des_block)); - - ntlm->crypt_ctx.des_set_key_fn(key, &keysched); - ntlm->crypt_ctx.des_ecb_encrypt_fn(plaintext, out, &keysched, DES_ENCRYPT); - - return true; -} - -bool ntlm_md4_digest( - unsigned char out[CRYPT_MD4_DIGESTSIZE], - ntlm_client *ntlm, - const unsigned char *in, - size_t in_len) -{ - ntlm->crypt_ctx.md4_fn(in, in_len, out); - return true; -} - -bool ntlm_hmac_md5_init( - ntlm_client *ntlm, - const unsigned char *key, - size_t key_len) -{ - const EVP_MD *md5 = ntlm->crypt_ctx.evp_md5_fn(); - - ntlm->crypt_ctx.hmac_ctx_cleanup_fn(ntlm->crypt_ctx.hmac); - - return ntlm->crypt_ctx.hmac_ctx_reset_fn(ntlm->crypt_ctx.hmac) && - ntlm->crypt_ctx.hmac_init_ex_fn(ntlm->crypt_ctx.hmac, key, key_len, md5, NULL); -} - -bool ntlm_hmac_md5_update( - ntlm_client *ntlm, - const unsigned char *in, - size_t in_len) -{ - return ntlm->crypt_ctx.hmac_update_fn(ntlm->crypt_ctx.hmac, in, in_len); -} - -bool ntlm_hmac_md5_final( - unsigned char *out, - size_t *out_len, - ntlm_client *ntlm) -{ - unsigned int len; - - if (*out_len < CRYPT_MD5_DIGESTSIZE) - return false; - - if (!ntlm->crypt_ctx.hmac_final_fn(ntlm->crypt_ctx.hmac, out, &len)) - return false; - - *out_len = len; - return true; -} - -void ntlm_crypt_shutdown(ntlm_client *ntlm) -{ - if (ntlm->crypt_ctx.hmac) { - ntlm->crypt_ctx.hmac_ctx_cleanup_fn(ntlm->crypt_ctx.hmac); - ntlm->crypt_ctx.hmac_ctx_free_fn(ntlm->crypt_ctx.hmac); - } - -#ifdef CRYPT_OPENSSL_DYNAMIC - if (ntlm->crypt_ctx.openssl_handle) - dlclose(ntlm->crypt_ctx.openssl_handle); -#endif - - memset(&ntlm->crypt_ctx, 0, sizeof(ntlm_crypt_ctx)); -} diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_openssl.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_openssl.h deleted file mode 100644 index 8654027..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/crypt_openssl.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_CRYPT_OPENSSL_H__ -#define PRIVATE_CRYPT_OPENSSL_H__ - -#ifndef CRYPT_OPENSSL_DYNAMIC -# include -# include -#endif - -/* OpenSSL 1.1.0 uses opaque structs, we'll reuse these. */ -#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L -# define HMAC_CTX struct hmac_ctx_st -#endif - -#ifdef CRYPT_OPENSSL_DYNAMIC -typedef unsigned char DES_cblock[8]; -typedef unsigned char const_DES_cblock[8]; - -typedef unsigned long DES_LONG; - -typedef struct DES_ks { - union { - DES_cblock cblock; - DES_LONG deslong[2]; - } ks[16]; -} DES_key_schedule; - -#define DES_ENCRYPT 1 - -typedef void EVP_MD; -typedef void ENGINE; -typedef void EVP_PKEY_CTX; - -#define HMAC_MAX_MD_CBLOCK 128 - -typedef struct env_md_ctx_st EVP_MD_CTX; -struct env_md_ctx_st { - const EVP_MD *digest; - ENGINE *engine; - unsigned long flags; - void *md_data; - EVP_PKEY_CTX *pctx; - int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count); -}; - -typedef struct hmac_ctx_st { - const EVP_MD *md; - EVP_MD_CTX md_ctx; - EVP_MD_CTX i_ctx; - EVP_MD_CTX o_ctx; - unsigned int key_length; - unsigned char key[HMAC_MAX_MD_CBLOCK]; -} HMAC_CTX; -#endif - -struct ntlm_crypt_ctx { - HMAC_CTX *hmac; - - void *openssl_handle; - - void (*des_ecb_encrypt_fn)(const_DES_cblock *input, DES_cblock *output, DES_key_schedule *ks, int enc); - int (*des_set_key_fn)(const_DES_cblock *key, DES_key_schedule *schedule); - - unsigned long (*err_get_error_fn)(void); - const char *(*err_lib_error_string_fn)(unsigned long e); - - const EVP_MD *(*evp_md5_fn)(void); - - HMAC_CTX *(*hmac_ctx_new_fn)(void); - int (*hmac_ctx_reset_fn)(HMAC_CTX *ctx); - void (*hmac_ctx_free_fn)(HMAC_CTX *ctx); - void (*hmac_ctx_cleanup_fn)(HMAC_CTX *ctx); - - int (*hmac_init_ex_fn)(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md, ENGINE *impl); - int (*hmac_update_fn)(HMAC_CTX *ctx, const unsigned char *data, size_t len); - int (*hmac_final_fn)(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); - - unsigned char *(*md4_fn)(const unsigned char *d, size_t n, unsigned char *md); - - int (*rand_bytes_fn)(unsigned char *buf, int num); -}; - -#endif /* PRIVATE_CRYPT_OPENSSL_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlm.c b/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlm.c deleted file mode 100644 index 28dff67..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlm.c +++ /dev/null @@ -1,1451 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ntlm.h" -#include "unicode.h" -#include "utf8.h" -#include "crypt.h" -#include "compat.h" -#include "util.h" - -#define NTLM_ASSERT_ARG(expr) do { \ - if (!(expr)) \ - return NTLM_CLIENT_ERROR_INVALID_INPUT; \ - } while(0) - -#define NTLM_ASSERT(ntlm, expr) do { \ - if (!(expr)) { \ - ntlm_client_set_errmsg(ntlm, "internal error: " #expr); \ - return -1; \ - } \ - } while(0) - -unsigned char ntlm_client_signature[] = NTLM_SIGNATURE; - -static bool supports_unicode(ntlm_client *ntlm) -{ - return (ntlm->flags & NTLM_CLIENT_DISABLE_UNICODE) ? - false : true; -} - -NTLM_INLINE(bool) increment_size(size_t *out, size_t incr) -{ - if (SIZE_MAX - *out < incr) { - *out = (size_t)-1; - return false; - } - - *out = *out + incr; - return true; -} - -ntlm_client *ntlm_client_init(ntlm_client_flags flags) -{ - ntlm_client *ntlm = NULL; - - if ((ntlm = calloc(1, sizeof(ntlm_client))) == NULL) - return NULL; - - ntlm->flags = flags; - - return ntlm; -} - -#define ENSURE_INITIALIZED(ntlm) \ - do { \ - if (!(ntlm)->unicode_initialized) \ - (ntlm)->unicode_initialized = ntlm_unicode_init((ntlm)); \ - if (!(ntlm)->crypt_initialized) \ - (ntlm)->crypt_initialized = ntlm_crypt_init((ntlm)); \ - if (!(ntlm)->unicode_initialized || \ - !(ntlm)->crypt_initialized) \ - return -1; \ - } while(0) - -void ntlm_client_set_errmsg(ntlm_client *ntlm, const char *errmsg) -{ - ntlm->state = NTLM_STATE_ERROR; - ntlm->errmsg = errmsg; -} - -const char *ntlm_client_errmsg(ntlm_client *ntlm) -{ - if (!ntlm) - return "internal error"; - - return ntlm->errmsg ? ntlm->errmsg : "no error"; -} - -int ntlm_client_set_version( - ntlm_client *ntlm, - uint8_t major, - uint8_t minor, - uint16_t build) -{ - NTLM_ASSERT_ARG(ntlm); - - ntlm->host_version.major = major; - ntlm->host_version.minor = minor; - ntlm->host_version.build = build; - ntlm->host_version.reserved = 0x0f000000; - - ntlm->flags |= NTLM_ENABLE_HOSTVERSION; - - return 0; -} - -#define reset(ptr) do { free(ptr); ptr = NULL; } while(0) - -static void free_hostname(ntlm_client *ntlm) -{ - reset(ntlm->hostname); - reset(ntlm->hostdomain); - reset(ntlm->hostname_utf16); - ntlm->hostname_utf16_len = 0; -} - -int ntlm_client_set_hostname( - ntlm_client *ntlm, - const char *hostname, - const char *domain) -{ - NTLM_ASSERT_ARG(ntlm); - ENSURE_INITIALIZED(ntlm); - - free_hostname(ntlm); - - if (hostname && (ntlm->hostname = strdup(hostname)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return -1; - } - - if (domain && (ntlm->hostdomain = strdup(domain)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return -1; - } - - if (hostname && supports_unicode(ntlm) && !ntlm_unicode_utf8_to_16( - &ntlm->hostname_utf16, - &ntlm->hostname_utf16_len, - ntlm, - hostname, - strlen(hostname))) - return -1; - - return 0; -} - -static void free_credentials(ntlm_client *ntlm) -{ - if (ntlm->password) - ntlm_memzero(ntlm->password, strlen(ntlm->password)); - - if (ntlm->password_utf16) - ntlm_memzero(ntlm->password_utf16, ntlm->password_utf16_len); - - reset(ntlm->username); - reset(ntlm->username_upper); - reset(ntlm->userdomain); - reset(ntlm->password); - - reset(ntlm->username_utf16); - reset(ntlm->username_upper_utf16); - reset(ntlm->userdomain_utf16); - reset(ntlm->password_utf16); - - ntlm->username_utf16_len = 0; - ntlm->username_upper_utf16_len = 0; - ntlm->userdomain_utf16_len = 0; - ntlm->password_utf16_len = 0; -} - -int ntlm_client_set_credentials( - ntlm_client *ntlm, - const char *username, - const char *domain, - const char *password) -{ - NTLM_ASSERT_ARG(ntlm); - ENSURE_INITIALIZED(ntlm); - - free_credentials(ntlm); - - if ((username && (ntlm->username = strdup(username)) == NULL) || - (domain && (ntlm->userdomain = strdup(domain)) == NULL) || - (password && (ntlm->password = strdup(password)) == NULL)) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return -1; - } - - if (username && supports_unicode(ntlm)) { - if ((ntlm->username_upper = strdup(username)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return -1; - } - utf8upr(ntlm->username_upper); - - if (!ntlm_unicode_utf8_to_16( - &ntlm->username_utf16, - &ntlm->username_utf16_len, - ntlm, - ntlm->username, - strlen(ntlm->username))) - return -1; - - if (!ntlm_unicode_utf8_to_16( - &ntlm->username_upper_utf16, - &ntlm->username_upper_utf16_len, - ntlm, - ntlm->username_upper, - strlen(ntlm->username_upper))) - return -1; - } - - if (domain && supports_unicode(ntlm) && !ntlm_unicode_utf8_to_16( - &ntlm->userdomain_utf16, - &ntlm->userdomain_utf16_len, - ntlm, - ntlm->userdomain, - strlen(ntlm->userdomain))) - return -1; - - return 0; -} - -int ntlm_client_set_target(ntlm_client *ntlm, const char *target) -{ - NTLM_ASSERT_ARG(ntlm); - ENSURE_INITIALIZED(ntlm); - - free(ntlm->target); - free(ntlm->target_utf16); - - ntlm->target = NULL; - ntlm->target_utf16 = NULL; - - if (target) { - if ((ntlm->target = strdup(target)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return -1; - } - - if (supports_unicode(ntlm) && !ntlm_unicode_utf8_to_16( - &ntlm->target_utf16, - &ntlm->target_utf16_len, - ntlm, - ntlm->target, - strlen(ntlm->target))) - return -1; - } - - return 0; -} - -int ntlm_client_set_nonce(ntlm_client *ntlm, uint64_t nonce) -{ - NTLM_ASSERT_ARG(ntlm); - - ntlm->nonce = nonce; - return 0; -} - -int ntlm_client_set_timestamp(ntlm_client *ntlm, uint64_t timestamp) -{ - NTLM_ASSERT_ARG(ntlm); - - ntlm->timestamp = timestamp; - return 0; -} - -NTLM_INLINE(bool) write_buf( - ntlm_client *ntlm, - ntlm_buf *out, - const unsigned char *buf, - size_t len) -{ - if (!len) - return true; - - if (out->len - out->pos < len) { - ntlm_client_set_errmsg(ntlm, "out of buffer space"); - return false; - } - - memcpy(&out->buf[out->pos], buf, len); - out->pos += len; - return true; -} - -NTLM_INLINE(bool) write_byte( - ntlm_client *ntlm, - ntlm_buf *out, - uint8_t value) -{ - if (out->len - out->pos < 1) { - ntlm_client_set_errmsg(ntlm, "out of buffer space"); - return false; - } - - out->buf[out->pos++] = value; - return true; -} - -NTLM_INLINE(bool) write_int16( - ntlm_client *ntlm, - ntlm_buf *out, - uint16_t value) -{ - if (out->len - out->pos < 2) { - ntlm_client_set_errmsg(ntlm, "out of buffer space"); - return false; - } - - out->buf[out->pos++] = (value & 0x000000ff); - out->buf[out->pos++] = (value & 0x0000ff00) >> 8; - return true; -} - -NTLM_INLINE(bool) write_int32( - ntlm_client *ntlm, - ntlm_buf *out, - uint32_t value) -{ - if (out->len - out->pos < 2) { - ntlm_client_set_errmsg(ntlm, "out of buffer space"); - return false; - } - - out->buf[out->pos++] = (value & 0x000000ff); - out->buf[out->pos++] = (value & 0x0000ff00) >> 8; - out->buf[out->pos++] = (value & 0x00ff0000) >> 16; - out->buf[out->pos++] = (value & 0xff000000) >> 24; - return true; -} - -NTLM_INLINE(bool) write_version( - ntlm_client *ntlm, - ntlm_buf *out, - ntlm_version *version) -{ - return write_byte(ntlm, out, version->major) && - write_byte(ntlm, out, version->minor) && - write_int16(ntlm, out, version->build) && - write_int32(ntlm, out, version->reserved); -} - -NTLM_INLINE(bool) write_bufinfo( - ntlm_client *ntlm, - ntlm_buf *out, - size_t len, - size_t offset) -{ - if (len > UINT16_MAX) { - ntlm_client_set_errmsg(ntlm, "invalid string, too long"); - return false; - } - - if (offset > UINT32_MAX) { - ntlm_client_set_errmsg(ntlm, "invalid string, invalid offset"); - return false; - } - - return write_int16(ntlm, out, (uint16_t)len) && - write_int16(ntlm, out, (uint16_t)len) && - write_int32(ntlm, out, (uint32_t)offset); -} - -NTLM_INLINE(bool) read_buf( - unsigned char *out, - ntlm_client *ntlm, - ntlm_buf *message, - size_t len) -{ - if (message->len - message->pos < len) { - ntlm_client_set_errmsg(ntlm, "truncated message"); - return false; - } - - memcpy(out, &message->buf[message->pos], len); - message->pos += len; - - return true; -} - -NTLM_INLINE(bool) read_byte( - uint8_t *out, - ntlm_client *ntlm, - ntlm_buf *message) -{ - if (message->len - message->pos < 1) { - ntlm_client_set_errmsg(ntlm, "truncated message"); - return false; - } - - *out = message->buf[message->pos++]; - return true; -} - -NTLM_INLINE(bool) read_int16( - uint16_t *out, - ntlm_client *ntlm, - ntlm_buf *message) -{ - if (message->len - message->pos < 2) { - ntlm_client_set_errmsg(ntlm, "truncated message"); - return false; - } - - *out = - ((message->buf[message->pos] & 0xff)) | - ((message->buf[message->pos+1] & 0xff) << 8); - - message->pos += 2; - return true; -} - -NTLM_INLINE(bool) read_int32( - uint32_t *out, - ntlm_client *ntlm, - ntlm_buf *message) -{ - if (message->len - message->pos < 4) { - ntlm_client_set_errmsg(ntlm, "truncated message"); - return false; - } - - *out = - ((message->buf[message->pos] & 0xff)) | - ((message->buf[message->pos+1] & 0xff) << 8) | - ((message->buf[message->pos+2] & 0xff) << 16) | - ((message->buf[message->pos+3] & 0xff) << 24); - - message->pos += 4; - return true; -} - -NTLM_INLINE(bool) read_int64( - uint64_t *out, - ntlm_client *ntlm, - ntlm_buf *message) -{ - if (message->len - message->pos < 8) { - ntlm_client_set_errmsg(ntlm, "truncated message"); - return false; - } - - *out = - ((uint64_t)(message->buf[message->pos] & 0xff)) | - ((uint64_t)(message->buf[message->pos+1] & 0xff) << 8) | - ((uint64_t)(message->buf[message->pos+2] & 0xff) << 16) | - ((uint64_t)(message->buf[message->pos+3] & 0xff) << 24) | - ((uint64_t)(message->buf[message->pos+4] & 0xff) << 32) | - ((uint64_t)(message->buf[message->pos+5] & 0xff) << 40) | - ((uint64_t)(message->buf[message->pos+6] & 0xff) << 48) | - ((uint64_t)(message->buf[message->pos+7] & 0xff) << 56); - - message->pos += 8; - return true; -} - -NTLM_INLINE(bool) read_version( - ntlm_version *out, - ntlm_client *ntlm, - ntlm_buf *message) -{ - return read_byte(&out->major, ntlm, message) && - read_byte(&out->minor, ntlm, message) && - read_int16(&out->build, ntlm, message) && - read_int32(&out->reserved, ntlm, message); -} - -NTLM_INLINE(bool) read_bufinfo( - uint16_t *out_len, - uint32_t *out_offset, - ntlm_client *ntlm, - ntlm_buf *message) -{ - uint16_t allocated; - - return read_int16(out_len, ntlm, message) && - read_int16(&allocated, ntlm, message) && - read_int32(out_offset, ntlm, message); -} - -NTLM_INLINE(bool) read_string_unicode( - char **out, - ntlm_client *ntlm, - ntlm_buf *message, - uint8_t string_len) -{ - size_t out_len; - int ret = ntlm_unicode_utf16_to_8(out, - &out_len, - ntlm, - (char *)&message->buf[message->pos], - string_len); - - message->pos += string_len; - - return ret; -} - -NTLM_INLINE(bool) read_string_ascii( - char **out, - ntlm_client *ntlm, - ntlm_buf *message, - uint8_t string_len) -{ - char *str; - - if ((str = malloc(string_len + 1)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return false; - } - - memcpy(str, &message->buf[message->pos], string_len); - str[string_len] = '\0'; - - message->pos += string_len; - - *out = str; - return true; -} - -NTLM_INLINE(bool) read_string( - char **out, - ntlm_client *ntlm, - ntlm_buf *message, - uint8_t string_len, - bool unicode) -{ - if (unicode) - return read_string_unicode(out, ntlm, message, string_len); - else - return read_string_ascii(out, ntlm, message, string_len); -} - -NTLM_INLINE(bool) read_target_info( - char **server_out, - char **domain_out, - char **server_dns_out, - char **domain_dns_out, - ntlm_client *ntlm, - ntlm_buf *message, - bool unicode) -{ - uint16_t block_type, block_len; - bool done = false; - - *server_out = NULL; - *domain_out = NULL; - *server_dns_out = NULL; - *domain_dns_out = NULL; - - while (!done && (message->len - message->pos) >= 4) { - if (!read_int16(&block_type, ntlm, message) || - !read_int16(&block_len, ntlm, message)) { - ntlm_client_set_errmsg(ntlm, "truncated target info block"); - return false; - } - - if (!block_type && block_len) { - ntlm_client_set_errmsg(ntlm, "invalid target info block"); - return -1; - } - - switch (block_type) { - case NTLM_TARGET_INFO_DOMAIN: - if (!read_string(domain_out, ntlm, message, block_len, unicode)) - return -1; - break; - case NTLM_TARGET_INFO_SERVER: - if (!read_string(server_out, ntlm, message, block_len, unicode)) - return -1; - break; - case NTLM_TARGET_INFO_DOMAIN_DNS: - if (!read_string(domain_dns_out, ntlm, message, block_len, unicode)) - return -1; - break; - case NTLM_TARGET_INFO_SERVER_DNS: - if (!read_string(server_dns_out, ntlm, message, block_len, unicode)) - return -1; - break; - case NTLM_TARGET_INFO_END: - done = true; - break; - default: - ntlm_client_set_errmsg(ntlm, "unknown target info block type"); - return -1; - } - } - - if (message->len != message->pos) { - ntlm_client_set_errmsg(ntlm, - "invalid extra data in target info section"); - return false; - } - - return true; -} - -int ntlm_client_negotiate( - const unsigned char **out, - size_t *out_len, - ntlm_client *ntlm) -{ - size_t hostname_len, domain_len; - size_t domain_offset = 0; - size_t hostname_offset = 0; - uint32_t flags = 0; - - NTLM_ASSERT_ARG(out); - NTLM_ASSERT_ARG(out_len); - NTLM_ASSERT_ARG(ntlm); - - *out = NULL; - *out_len = 0; - - if (ntlm->state != NTLM_STATE_NEGOTIATE) { - ntlm_client_set_errmsg(ntlm, "ntlm handle in invalid state"); - return -1; - } - - flags |= NTLM_NEGOTIATE_OEM; - - if (supports_unicode(ntlm)) - flags |= NTLM_NEGOTIATE_UNICODE; - - if (!(ntlm->flags & NTLM_CLIENT_DISABLE_NTLM2) || - (ntlm->flags & NTLM_CLIENT_ENABLE_NTLM)) - flags |= NTLM_NEGOTIATE_NTLM; - - if (!(ntlm->flags & NTLM_CLIENT_DISABLE_REQUEST_TARGET)) - flags |= NTLM_NEGOTIATE_REQUEST_TARGET; - - hostname_len = ntlm->hostname ? strlen(ntlm->hostname) : 0; - domain_len = ntlm->hostdomain ? strlen(ntlm->hostdomain) : 0; - - /* Minimum header size */ - ntlm->negotiate.len = 16; - - /* Include space for security buffer descriptors */ - if (domain_len) - increment_size(&ntlm->negotiate.len, 8); - - if (hostname_len) - increment_size(&ntlm->negotiate.len, 8); - - if (ntlm->flags & NTLM_ENABLE_HOSTVERSION) - increment_size(&ntlm->negotiate.len, 8); - - /* Location of security buffers */ - if (hostname_len) { - flags |= NTLM_NEGOTIATE_WORKSTATION_SUPPLIED; - hostname_offset = ntlm->negotiate.len; - increment_size(&ntlm->negotiate.len, hostname_len); - } - - if (domain_len) { - flags |= NTLM_NEGOTIATE_DOMAIN_SUPPLIED; - domain_offset = ntlm->negotiate.len; - increment_size(&ntlm->negotiate.len, domain_len); - } - - if (ntlm->negotiate.len == (size_t)-1) { - ntlm_client_set_errmsg(ntlm, "message too large"); - return -1; - } - - if ((ntlm->negotiate.buf = calloc(1, ntlm->negotiate.len)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return -1; - } - - if (!write_buf(ntlm, &ntlm->negotiate, - ntlm_client_signature, sizeof(ntlm_client_signature)) || - !write_int32(ntlm, &ntlm->negotiate, 1) || - !write_int32(ntlm, &ntlm->negotiate, flags)) - return -1; - - /* Domain information */ - if (domain_len > 0 && - !write_bufinfo(ntlm, &ntlm->negotiate, domain_len, domain_offset)) - return -1; - - /* Workstation information */ - if (hostname_len > 0 && - !write_bufinfo(ntlm, &ntlm->negotiate, hostname_len, hostname_offset)) - return -1; - - /* Version number */ - if (!!(ntlm->flags & NTLM_ENABLE_HOSTVERSION) && - !write_version(ntlm, &ntlm->negotiate, &ntlm->host_version)) - return -1; - - if (hostname_len > 0) { - NTLM_ASSERT(ntlm, hostname_offset == ntlm->negotiate.pos); - - if (!write_buf(ntlm, &ntlm->negotiate, - (const unsigned char *)ntlm->hostname, hostname_len)) - return -1; - } - - if (domain_len > 0) { - NTLM_ASSERT(ntlm, domain_offset == ntlm->negotiate.pos); - - if (!write_buf(ntlm, &ntlm->negotiate, - (const unsigned char *)ntlm->hostdomain, domain_len)) - return -1; - } - - NTLM_ASSERT(ntlm, ntlm->negotiate.pos == ntlm->negotiate.len); - - ntlm->state = NTLM_STATE_CHALLENGE; - - *out = ntlm->negotiate.buf; - *out_len = ntlm->negotiate.len; - - return 0; -} - -int ntlm_client_set_challenge( - ntlm_client *ntlm, - const unsigned char *challenge_msg, - size_t challenge_msg_len) -{ - unsigned char signature[8]; - ntlm_buf challenge; - uint32_t type_indicator, header_end; - uint16_t name_len, info_len = 0; - uint32_t name_offset, info_offset = 0; - bool unicode, has_target_info = false; - - NTLM_ASSERT_ARG(ntlm); - NTLM_ASSERT_ARG(challenge_msg || !challenge_msg_len); - - ENSURE_INITIALIZED(ntlm); - - if (ntlm->state != NTLM_STATE_NEGOTIATE && - ntlm->state != NTLM_STATE_CHALLENGE) { - ntlm_client_set_errmsg(ntlm, "ntlm handle in invalid state"); - return -1; - } - - challenge.buf = (unsigned char *)challenge_msg; - challenge.len = challenge_msg_len; - challenge.pos = 0; - - if (!read_buf(signature, ntlm, &challenge, 8) || - !read_int32(&type_indicator, ntlm, &challenge) || - !read_bufinfo(&name_len, &name_offset, ntlm, &challenge) || - !read_int32(&ntlm->challenge.flags, ntlm, &challenge) || - !read_int64(&ntlm->challenge.nonce, ntlm, &challenge)) - return -1; - - if (memcmp(signature, - ntlm_client_signature, sizeof(ntlm_client_signature)) != 0) { - ntlm_client_set_errmsg(ntlm, "invalid message signature"); - return -1; - } - - if (type_indicator != 2) { - ntlm_client_set_errmsg(ntlm, "invalid message indicator"); - return -1; - } - - /* - * If there's additional space before the data section, that's the - * target information description section. - */ - header_end = challenge.len; - - if (name_offset && name_offset < header_end) - header_end = name_offset; - - if ((header_end - challenge.pos) >= 16) { - has_target_info = true; - } - - if (!has_target_info && - (ntlm->challenge.flags & NTLM_NEGOTIATE_TARGET_INFO)) { - ntlm_client_set_errmsg(ntlm, - "truncated message; expected target info"); - return -1; - } - - /* - * If there's a target info section then advanced over the reserved - * space and read the target information. - */ - if (has_target_info) { - uint64_t reserved; - - if (!read_int64(&reserved, ntlm, &challenge)) { - ntlm_client_set_errmsg(ntlm, - "truncated message; expected reserved space"); - return -1; - } - - if (reserved != 0) { - ntlm_client_set_errmsg(ntlm, - "invalid message; expected reserved space to be empty"); - return -1; - } - - if (!read_bufinfo(&info_len, &info_offset, ntlm, &challenge)) { - ntlm_client_set_errmsg(ntlm, - "truncated message; expected target info"); - return -1; - } - } - - unicode = !!(ntlm->challenge.flags & NTLM_NEGOTIATE_UNICODE); - - /* - * If there's still additional space before the data section, - * that's the server's version information. - */ - if (info_offset && info_offset < header_end) - header_end = info_offset; - - if (ntlm->challenge.flags & NTLM_NEGOTIATE_VERSION) { - if ((header_end - challenge.pos) != sizeof(ntlm_version) || - !read_version(&ntlm->challenge.target_version, - ntlm, &challenge)) { - ntlm_client_set_errmsg(ntlm, - "truncated message; expected version"); - return -1; - } - } - - /* validate data section */ - if ((name_offset && name_offset < challenge.pos) || - challenge.len < name_len || - (challenge.len - name_len) < name_offset) { - ntlm_client_set_errmsg(ntlm, - "invalid message; invalid target name buffer"); - return -1; - } - if ((info_offset && info_offset < challenge.pos) || - challenge.len < info_len || - (challenge.len - info_len) < info_offset) { - ntlm_client_set_errmsg(ntlm, - "invalid message; invalid target info buffer"); - return -1; - } - - /* advance to the data section */ - if (name_len && name_offset) { - challenge.pos = name_offset; - - if (!read_string(&ntlm->challenge.target, - ntlm, &challenge, name_len, unicode)) { - ntlm_client_set_errmsg(ntlm, - "truncated message; truncated target name"); - return -1; - } - } - - if (info_len && info_offset) { - ntlm_buf info_buf; - - challenge.pos = info_offset; - - /* create a copy of the target info; we need the literal data */ - if ((ntlm->challenge.target_info = malloc(info_len)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return -1; - } - - if (!read_buf(ntlm->challenge.target_info, - ntlm, &challenge, info_len)) { - ntlm_client_set_errmsg(ntlm, - "truncated message; truncated target info"); - return -1; - } - - info_buf.buf = ntlm->challenge.target_info; - info_buf.pos = 0; - info_buf.len = info_len; - - /* then set up the target info and parse it */ - if (!read_target_info(&ntlm->challenge.target_server, - &ntlm->challenge.target_domain, - &ntlm->challenge.target_server_dns, - &ntlm->challenge.target_domain_dns, - ntlm, &info_buf, unicode)) - return -1; - - ntlm->challenge.target_info_len = info_len; - } - - ntlm->state = NTLM_STATE_RESPONSE; - - return 0; -} - -uint64_t ntlm_client_challenge_nonce(ntlm_client *ntlm) -{ - return ntlm->challenge.nonce; -} - -const char *ntlm_client_target(ntlm_client *ntlm) -{ - return ntlm->challenge.target; -} - -const char *ntlm_client_target_server(ntlm_client *ntlm) -{ - return ntlm->challenge.target_server; -} - -const char *ntlm_client_target_domain(ntlm_client *ntlm) -{ - return ntlm->challenge.target_domain; -} - -const char *ntlm_client_target_server_dns(ntlm_client *ntlm) -{ - return ntlm->challenge.target_server_dns; -} - -const char *ntlm_client_target_domain_dns(ntlm_client *ntlm) -{ - return ntlm->challenge.target_domain_dns; -} - -#define EVEN_PARITY(a) \ - (!!((a) & INT64_C(0x01)) ^ !!((a) & INT64_C(0x02)) ^ \ - !!((a) & INT64_C(0x04)) ^ !!((a) & INT64_C(0x08)) ^ \ - !!((a) & INT64_C(0x10)) ^ !!((a) & INT64_C(0x20)) ^ \ - !!((a) & INT64_C(0x40)) ^ !!((a) & INT64_C(0x80))) - -static void generate_odd_parity(ntlm_des_block *block) -{ - size_t i; - - for (i = 0; i < sizeof(ntlm_des_block); i++) - (*block)[i] |= (1 ^ EVEN_PARITY((*block)[i])); -} - -static void des_key_from_password( - ntlm_des_block *out, - const unsigned char *plaintext, - size_t plaintext_len) -{ - size_t i; - - plaintext_len = MIN(plaintext_len, 7); - - memset(*out, 0, sizeof(ntlm_des_block)); - - for (i = 0; i < plaintext_len; i++) { - size_t j = (7 - i); - uint8_t mask = (0xff >> j); - - (*out)[i] |= ((plaintext[i] & (0xff - mask)) >> i); - (*out)[i+1] |= ((plaintext[i] & mask) << j); - } - - generate_odd_parity(out); -} - -NTLM_INLINE(bool) generate_lm_hash( - ntlm_des_block out[2], - ntlm_client *ntlm, - const char *password) -{ - /* LM encrypts this known plaintext using the password as a key */ - ntlm_des_block plaintext = NTLM_LM_PLAINTEXT; - ntlm_des_block keystr1, keystr2; - size_t keystr1_len, keystr2_len; - ntlm_des_block key1, key2; - size_t password_len, i; - - /* Copy the first 14 characters of the password, uppercased */ - memset(&keystr1, 0, sizeof(keystr1)); - memset(&keystr2, 0, sizeof(keystr2)); - - password_len = password ? strlen(password) : 0; - - /* Split the password into two 7 byte chunks */ - keystr1_len = MIN(7, password_len); - keystr2_len = (password_len > 7) ? MIN(14, password_len) - 7 : 0; - - for (i = 0; i < keystr1_len; i++) - keystr1[i] = (unsigned char)toupper((unsigned char)password[i]); - for (i = 0; i < keystr2_len; i++) - keystr2[i] = (unsigned char)toupper((unsigned char)password[i+7]); - - /* DES encrypt the LM constant using the password as the key */ - des_key_from_password(&key1, keystr1, keystr1_len); - des_key_from_password(&key2, keystr2, keystr2_len); - - return ntlm_des_encrypt(&out[0], ntlm, &plaintext, &key1) && - ntlm_des_encrypt(&out[1], ntlm, &plaintext, &key2); -} - -static void des_keys_from_lm_hash(ntlm_des_block out[3], ntlm_des_block lm_hash[2]) -{ - ntlm_des_block split[3]; - - memcpy(&split[0][0], &lm_hash[0][0], 7); - - memcpy(&split[1][0], &lm_hash[0][7], 1); - memcpy(&split[1][1], &lm_hash[1][0], 6); - - memcpy(&split[2][0], &lm_hash[1][6], 2); - - des_key_from_password(&out[0], split[0], 7); - des_key_from_password(&out[1], split[1], 7); - des_key_from_password(&out[2], split[2], 2); -} - -static bool generate_lm_response(ntlm_client *ntlm) -{ - ntlm_des_block lm_hash[2], key[3], lm_response[3]; - ntlm_des_block *challenge = (ntlm_des_block *)&ntlm->challenge.nonce; - - /* Generate the LM hash from the password */ - if (!generate_lm_hash(lm_hash, ntlm, ntlm->password)) - return false; - - /* Convert that LM hash to three DES keys */ - des_keys_from_lm_hash(key, lm_hash); - - /* Finally, encrypt the challenge with each of these keys */ - if (!ntlm_des_encrypt(&lm_response[0], ntlm, challenge, &key[0]) || - !ntlm_des_encrypt(&lm_response[1], ntlm, challenge, &key[1]) || - !ntlm_des_encrypt(&lm_response[2], ntlm, challenge, &key[2])) - return false; - - memcpy(&ntlm->lm_response[0], lm_response[0], 8); - memcpy(&ntlm->lm_response[8], lm_response[1], 8); - memcpy(&ntlm->lm_response[16], lm_response[2], 8); - - ntlm->lm_response_len = sizeof(ntlm->lm_response); - - return true; -} - -static bool generate_ntlm_hash( - unsigned char out[NTLM_NTLM_HASH_LEN], ntlm_client *ntlm) -{ - /* Generate the LM hash from the (Unicode) password */ - if (ntlm->password && !ntlm_unicode_utf8_to_16( - &ntlm->password_utf16, - &ntlm->password_utf16_len, - ntlm, - ntlm->password, - strlen(ntlm->password))) - return false; - - return ntlm_md4_digest(out, - ntlm, - (const unsigned char *)ntlm->password_utf16, - ntlm->password_utf16_len); -} - -static bool generate_ntlm_response(ntlm_client *ntlm) -{ - unsigned char ntlm_hash[NTLM_NTLM_HASH_LEN] = {0}; - ntlm_des_block key[3], ntlm_response[3]; - ntlm_des_block *challenge = - (ntlm_des_block *)&ntlm->challenge.nonce; - - if (!generate_ntlm_hash(ntlm_hash, ntlm)) - return false; - - /* Convert that LM hash to three DES keys */ - des_key_from_password(&key[0], &ntlm_hash[0], 7); - des_key_from_password(&key[1], &ntlm_hash[7], 7); - des_key_from_password(&key[2], &ntlm_hash[14], 2); - - /* Finally, encrypt the challenge with each of these keys */ - if (!ntlm_des_encrypt(&ntlm_response[0], ntlm, challenge, &key[0]) || - !ntlm_des_encrypt(&ntlm_response[1], ntlm, challenge, &key[1]) || - !ntlm_des_encrypt(&ntlm_response[2], ntlm, challenge, &key[2])) - return false; - - memcpy(&ntlm->ntlm_response[0], ntlm_response[0], 8); - memcpy(&ntlm->ntlm_response[8], ntlm_response[1], 8); - memcpy(&ntlm->ntlm_response[16], ntlm_response[2], 8); - - ntlm->ntlm_response_len = sizeof(ntlm->ntlm_response); - return true; -} - -static bool generate_ntlm2_hash( - unsigned char out[NTLM_NTLM2_HASH_LEN], ntlm_client *ntlm) -{ - unsigned char ntlm_hash[NTLM_NTLM_HASH_LEN] = {0}; - const unsigned char *username = NULL, *target = NULL; - size_t username_len = 0, target_len = 0, out_len = NTLM_NTLM2_HASH_LEN; - - if (!generate_ntlm_hash(ntlm_hash, ntlm)) - return false; - - if (ntlm->username_upper_utf16) { - username = (const unsigned char *)ntlm->username_upper_utf16; - username_len = ntlm->username_upper_utf16_len; - } - - if (ntlm->target_utf16) { - target = (const unsigned char *)ntlm->target_utf16; - target_len = ntlm->target_utf16_len; - } - - if (!ntlm_hmac_md5_init(ntlm, ntlm_hash, sizeof(ntlm_hash)) || - !ntlm_hmac_md5_update(ntlm, username, username_len) || - !ntlm_hmac_md5_update(ntlm, target, target_len) || - !ntlm_hmac_md5_final(out, &out_len, ntlm)) { - ntlm_client_set_errmsg(ntlm, "failed to create HMAC-MD5"); - return false; - } - - NTLM_ASSERT(ntlm, out_len == NTLM_NTLM2_HASH_LEN); - return true; -} - -static bool generate_ntlm2_challengehash( - unsigned char out[16], - ntlm_client *ntlm, - unsigned char ntlm2_hash[NTLM_NTLM2_HASH_LEN], - const unsigned char *blob, - size_t blob_len) -{ - size_t out_len = 16; - - if (!ntlm_hmac_md5_init(ntlm, ntlm2_hash, NTLM_NTLM2_HASH_LEN) || - !ntlm_hmac_md5_update(ntlm, (const unsigned char *)&ntlm->challenge.nonce, 8) || - !ntlm_hmac_md5_update(ntlm, blob, blob_len) || - !ntlm_hmac_md5_final(out, &out_len, ntlm)) { - ntlm_client_set_errmsg(ntlm, "failed to create HMAC-MD5"); - return false; - } - - NTLM_ASSERT(ntlm, out_len == 16); - return true; -} - -static bool generate_lm2_response(ntlm_client *ntlm, - unsigned char ntlm2_hash[NTLM_NTLM2_HASH_LEN]) -{ - unsigned char lm2_challengehash[16] = {0}; - size_t lm2_len = 16; - uint64_t local_nonce; - - local_nonce = ntlm_htonll(ntlm->nonce); - - if (!ntlm_hmac_md5_init(ntlm, ntlm2_hash, NTLM_NTLM2_HASH_LEN) || - !ntlm_hmac_md5_update(ntlm, (const unsigned char *)&ntlm->challenge.nonce, 8) || - !ntlm_hmac_md5_update(ntlm, (const unsigned char *)&local_nonce, 8) || - !ntlm_hmac_md5_final(lm2_challengehash, &lm2_len, ntlm)) { - ntlm_client_set_errmsg(ntlm, "failed to create HMAC-MD5"); - return false; - } - - NTLM_ASSERT(ntlm, lm2_len == 16); - - memcpy(&ntlm->lm_response[0], lm2_challengehash, 16); - memcpy(&ntlm->lm_response[16], &local_nonce, 8); - - ntlm->lm_response_len = 24; - return true; -} - -static bool generate_timestamp(ntlm_client *ntlm) -{ - if (!ntlm->timestamp) - ntlm->timestamp = (time(NULL) + 11644473600) * 10000000; - - return true; -} - -static bool generate_nonce(ntlm_client *ntlm) -{ - unsigned char buf[8]; - - if (ntlm->nonce) - return true; - - if (!ntlm_random_bytes(buf, ntlm, 8)) - return false; - - memcpy(&ntlm->nonce, buf, sizeof(uint64_t)); - return true; -} - -static bool generate_ntlm2_response(ntlm_client *ntlm) -{ - size_t blob_len, ntlm2_response_len; - uint32_t signature; - uint64_t timestamp, nonce; - unsigned char ntlm2_hash[NTLM_NTLM2_HASH_LEN]; - unsigned char challengehash[16] = {0}; - unsigned char *blob; - - if (!generate_timestamp(ntlm) || - !generate_nonce(ntlm) || - !generate_ntlm2_hash(ntlm2_hash, ntlm)) - return false; - - blob_len = ntlm->challenge.target_info_len + 32; - ntlm2_response_len = blob_len + 16; - - if ((ntlm->ntlm2_response = malloc(ntlm2_response_len)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return false; - } - - /* position the blob in the response; we'll use it then return it */ - blob = ntlm->ntlm2_response + 16; - - /* the blob's integer values are in network byte order */ - signature = htonl(0x01010000); - timestamp = ntlm_htonll(ntlm->timestamp); - nonce = ntlm_htonll(ntlm->nonce); - - /* construct the blob */ - memcpy(&blob[0], &signature, 4); - memset(&blob[4], 0, 4); - memcpy(&blob[8], ×tamp, 8); - memcpy(&blob[16], &nonce, 8); - memset(&blob[24], 0, 4); - memcpy(&blob[28], ntlm->challenge.target_info, ntlm->challenge.target_info_len); - memset(&blob[28 + ntlm->challenge.target_info_len], 0, 4); - - if (!generate_ntlm2_challengehash(challengehash, ntlm, ntlm2_hash, blob, blob_len)) - return false; - - memcpy(ntlm->ntlm2_response, challengehash, 16); - ntlm->ntlm2_response_len = ntlm2_response_len; - - if (!generate_lm2_response(ntlm, ntlm2_hash)) - return false; - - return true; -} - -int ntlm_client_response( - const unsigned char **out, - size_t *out_len, - ntlm_client *ntlm) -{ - unsigned char *domain, *username, *hostname, *ntlm_rep, *session; - size_t lm_rep_len, lm_rep_offset, ntlm_rep_len, ntlm_rep_offset, - domain_len, domain_offset, username_len, username_offset, - hostname_len, hostname_offset, session_len, session_offset; - uint32_t flags = 0; - bool unicode; - - NTLM_ASSERT_ARG(out); - NTLM_ASSERT_ARG(out_len); - NTLM_ASSERT_ARG(ntlm); - - ENSURE_INITIALIZED(ntlm); - - *out = NULL; - *out_len = 0; - - if (ntlm->state != NTLM_STATE_RESPONSE) { - ntlm_client_set_errmsg(ntlm, "ntlm handle in invalid state"); - return -1; - } - - /* - * Minimum message size is 64 bytes: - * 8 byte signature, - * 4 byte message indicator, - * 6x8 byte security buffers - * 4 byte flags - */ - ntlm->response.len = 64; - - unicode = supports_unicode(ntlm) && - (ntlm->challenge.flags & NTLM_NEGOTIATE_UNICODE); - - if (unicode) - flags |= NTLM_NEGOTIATE_UNICODE; - else - flags |= NTLM_NEGOTIATE_OEM; - - if (unicode) { - domain = (unsigned char *)ntlm->userdomain_utf16; - domain_len = ntlm->userdomain_utf16_len; - - username = (unsigned char *)ntlm->username_utf16; - username_len = ntlm->username_utf16_len; - - hostname = (unsigned char *)ntlm->hostname_utf16; - hostname_len = ntlm->hostname_utf16_len; - } else { - domain = (unsigned char *)ntlm->userdomain; - domain_len = ntlm->userdomain ? strlen(ntlm->userdomain) : 0; - - username = (unsigned char *)ntlm->username; - username_len = ntlm->username ? strlen(ntlm->username) : 0; - - hostname = (unsigned char *)ntlm->hostname; - hostname_len = ntlm->hostname ? strlen(ntlm->hostname) : 0; - } - - /* Negotiate our requested authentication type with the server's */ - if (!(ntlm->flags & NTLM_CLIENT_DISABLE_NTLM2) && - (ntlm->challenge.flags & NTLM_NEGOTIATE_NTLM)) { - flags |= NTLM_NEGOTIATE_NTLM; - - if (!generate_ntlm2_response(ntlm)) - return -1; - } else if ((ntlm->flags & NTLM_CLIENT_ENABLE_NTLM) && - (ntlm->challenge.flags & NTLM_NEGOTIATE_NTLM)) { - flags |= NTLM_NEGOTIATE_NTLM; - - if (!generate_ntlm_response(ntlm) || - !generate_lm_response(ntlm)) - return -1; - } else if (ntlm->flags & NTLM_CLIENT_ENABLE_LM) { - if (!generate_lm_response(ntlm)) - return -1; - } else { - ntlm_client_set_errmsg(ntlm, - "no encryption options could be negotiated"); - return -1; - } - - domain_offset = ntlm->response.len; - increment_size(&ntlm->response.len, domain_len); - - username_offset = ntlm->response.len; - increment_size(&ntlm->response.len, username_len); - - hostname_offset = ntlm->response.len; - increment_size(&ntlm->response.len, hostname_len); - - lm_rep_len = ntlm->lm_response_len; - lm_rep_offset = ntlm->response.len; - increment_size(&ntlm->response.len, lm_rep_len); - - ntlm_rep = ntlm->ntlm2_response_len ? - ntlm->ntlm2_response : ntlm->ntlm_response; - ntlm_rep_len = ntlm->ntlm2_response_len ? - ntlm->ntlm2_response_len : ntlm->ntlm_response_len; - ntlm_rep_offset = ntlm->response.len; - increment_size(&ntlm->response.len, ntlm_rep_len); - - session = NULL; - session_len = 0; - session_offset = ntlm->response.len; - increment_size(&ntlm->response.len, session_len); - - if (ntlm->response.len == (size_t)-1) { - ntlm_client_set_errmsg(ntlm, "message too large"); - return -1; - } - - if ((ntlm->response.buf = calloc(1, ntlm->response.len)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return -1; - } - - if (!write_buf(ntlm, &ntlm->response, - ntlm_client_signature, sizeof(ntlm_client_signature)) || - !write_int32(ntlm, &ntlm->response, 3) || - !write_bufinfo(ntlm, &ntlm->response, lm_rep_len, lm_rep_offset) || - !write_bufinfo(ntlm, &ntlm->response, ntlm_rep_len, ntlm_rep_offset) || - !write_bufinfo(ntlm, &ntlm->response, domain_len, domain_offset) || - !write_bufinfo(ntlm, &ntlm->response, username_len, username_offset) || - !write_bufinfo(ntlm, &ntlm->response, hostname_len, hostname_offset) || - !write_bufinfo(ntlm, &ntlm->response, session_len, session_offset) || - !write_int32(ntlm, &ntlm->response, flags) || - !write_buf(ntlm, &ntlm->response, domain, domain_len) || - !write_buf(ntlm, &ntlm->response, username, username_len) || - !write_buf(ntlm, &ntlm->response, hostname, hostname_len) || - !write_buf(ntlm, &ntlm->response, ntlm->lm_response, lm_rep_len) || - !write_buf(ntlm, &ntlm->response, ntlm_rep, ntlm_rep_len) || - !write_buf(ntlm, &ntlm->response, session, session_len)) - return -1; - - NTLM_ASSERT(ntlm, ntlm->response.pos == ntlm->response.len); - - ntlm->state = NTLM_STATE_COMPLETE; - - *out = ntlm->response.buf; - *out_len = ntlm->response.len; - - return 0; -} - -void ntlm_client_reset(ntlm_client *ntlm) -{ - if (!ntlm) - return; - - ntlm->state = NTLM_STATE_NEGOTIATE; - - free_hostname(ntlm); - - memset(&ntlm->host_version, 0, sizeof(ntlm_version)); - - reset(ntlm->target); - reset(ntlm->target_utf16); - ntlm->target_utf16_len = 0; - - free_credentials(ntlm); - - ntlm->nonce = 0; - ntlm->timestamp = 0; - - memset(ntlm->lm_response, 0, NTLM_LM_RESPONSE_LEN); - ntlm->lm_response_len = 0; - - memset(ntlm->ntlm_response, 0, NTLM_NTLM_RESPONSE_LEN); - ntlm->ntlm_response_len = 0; - - reset(ntlm->ntlm2_response); - ntlm->ntlm2_response_len = 0; - - reset(ntlm->negotiate.buf); - ntlm->negotiate.pos = 0; - ntlm->negotiate.len = 0; - - reset(ntlm->response.buf); - ntlm->response.pos = 0; - ntlm->response.len = 0; - - free(ntlm->challenge.target_info); - free(ntlm->challenge.target); - free(ntlm->challenge.target_domain); - free(ntlm->challenge.target_domain_dns); - free(ntlm->challenge.target_server); - free(ntlm->challenge.target_server_dns); - memset(&ntlm->challenge, 0, sizeof(ntlm_challenge)); -} - -void ntlm_client_free(ntlm_client *ntlm) -{ - if (!ntlm) - return; - - ntlm_crypt_shutdown(ntlm); - ntlm_unicode_shutdown(ntlm); - - ntlm_client_reset(ntlm); - - free(ntlm); -} diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlm.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlm.h deleted file mode 100644 index 4abfd7a..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlm.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_NTLM_H__ -#define PRIVATE_NTLM_H__ - -#include "ntlmclient.h" -#include "unicode.h" -#include "crypt.h" -#include "compat.h" - -#define NTLM_UNUSED(x) ((void)(x)) - -#define NTLM_LM_RESPONSE_LEN 24 -#define NTLM_NTLM_RESPONSE_LEN 24 -#define NTLM_NTLM_HASH_LEN 16 -#define NTLM_NTLM2_HASH_LEN 16 - -#define NTLM_SIGNATURE { 'N', 'T', 'L', 'M', 'S', 'S', 'P', 0x00 } - -#define NTLM_LM_PLAINTEXT { 0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 } - -typedef enum { - NTLM_STATE_NEGOTIATE = 0, - NTLM_STATE_CHALLENGE = 1, - NTLM_STATE_RESPONSE = 2, - NTLM_STATE_ERROR = 3, - NTLM_STATE_COMPLETE = 4 -} ntlm_state; - -typedef struct { - unsigned char *buf; - size_t pos; - size_t len; -} ntlm_buf; - -typedef struct { - uint8_t major; - uint8_t minor; - uint16_t build; - uint32_t reserved; -} ntlm_version; - -typedef struct { - uint32_t flags; - uint64_t nonce; - ntlm_version target_version; - - /* The unparsed target information from the server */ - unsigned char *target_info; - size_t target_info_len; - - /* The target information parsed into usable strings */ - char *target; - char *target_server; - char *target_domain; - char *target_server_dns; - char *target_domain_dns; -} ntlm_challenge; - -struct ntlm_client { - ntlm_client_flags flags; - - ntlm_state state; - - /* subsystem contexts */ - ntlm_crypt_ctx crypt_ctx; - ntlm_unicode_ctx unicode_ctx; - int crypt_initialized : 1, - unicode_initialized : 1; - - /* error message as set by the library */ - const char *errmsg; - - char *hostname; - char *hostdomain; - ntlm_version host_version; - - char *target; - - char *username; - char *username_upper; - char *userdomain; - char *password; - - /* strings as converted to utf16 */ - char *hostname_utf16; - char *target_utf16; - char *username_utf16; - char *username_upper_utf16; - char *userdomain_utf16; - char *password_utf16; - - size_t hostname_utf16_len; - size_t username_utf16_len; - size_t username_upper_utf16_len; - size_t userdomain_utf16_len; - size_t password_utf16_len; - size_t target_utf16_len; - - /* timestamp and nonce; only for debugging */ - uint64_t nonce; - uint64_t timestamp; - - unsigned char lm_response[NTLM_LM_RESPONSE_LEN]; - size_t lm_response_len; - - unsigned char ntlm_response[NTLM_NTLM_RESPONSE_LEN]; - size_t ntlm_response_len; - - unsigned char *ntlm2_response; - size_t ntlm2_response_len; - - ntlm_buf negotiate; - ntlm_challenge challenge; - ntlm_buf response; -}; - -typedef enum { - NTLM_ENABLE_HOSTVERSION = (1 << 31) -} ntlm_client_internal_flags; - -typedef enum { - NTLM_TARGET_INFO_END = 0, - NTLM_TARGET_INFO_SERVER = 1, - NTLM_TARGET_INFO_DOMAIN = 2, - NTLM_TARGET_INFO_SERVER_DNS = 3, - NTLM_TARGET_INFO_DOMAIN_DNS = 4 -} ntlm_target_info_type_t; - -typedef enum { - /* Unicode strings are supported in security buffers */ - NTLM_NEGOTIATE_UNICODE = 0x00000001, - - /* OEM (ANSI) strings are supported in security buffers */ - NTLM_NEGOTIATE_OEM = 0x00000002, - - /* Request the target realm from the server */ - NTLM_NEGOTIATE_REQUEST_TARGET = 0x00000004, - - /* NTLM authentication is supported */ - NTLM_NEGOTIATE_NTLM = 0x00000200, - - /* Negotiate domain name */ - NTLM_NEGOTIATE_DOMAIN_SUPPLIED = 0x00001000, - - /* Negotiate workstation (client) name */ - NTLM_NEGOTIATE_WORKSTATION_SUPPLIED = 0x00002000, - - /* Indicates that a local context is available */ - NTLM_NEGOTIATE_LOCAL_CALL = 0x00004000, - - /* Request a dummy signature */ - NTLM_NEGOTIATE_ALWAYS_SIGN = 0x00008000, - - /* Target (server) is a domain */ - NTLM_NEGOTIATE_TYPE_DOMAIN = 0x00010000, - - /* NTLM2 signing and sealing is supported */ - NTLM_NEGOTIATE_NTLM2_SIGN_AND_SEAL = 0x00080000, - - /* A target information block is included */ - NTLM_NEGOTIATE_TARGET_INFO = 0x00800000, - - /* Version information should be provided */ - NTLM_NEGOTIATE_VERSION = 0x01000000 -} ntlm_negotiate_t; - -extern int ntlm_client_set_nonce(ntlm_client *ntlm, uint64_t nonce); -extern int ntlm_client_set_timestamp(ntlm_client *ntlm, uint64_t timestamp); -extern void ntlm_client_set_errmsg(ntlm_client *ntlm, const char *errmsg); - -#endif /* PRIVATE_NTLM_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlmclient.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlmclient.h deleted file mode 100644 index 958b27e..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/ntlmclient.h +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ -#ifndef INCLUDE_NTLMCLIENT_H__ -#define INCLUDE_NTLMCLIENT_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define NTLM_CLIENT_VERSION "0.9.0" -#define NTLM_CLIENT_VERSION_MAJOR 0 -#define NTLM_CLIENT_VERSION_MINOR 9 -#define NTLM_CLIENT_VERSION_TEENY 0 - -typedef struct ntlm_client ntlm_client; - -typedef enum { - /** - * An error occurred; more details are available by querying - * `ntlm_client_errmsg`. - */ - NTLM_CLIENT_ERROR = -1, - - /** - * The input provided to the function is missing or invalid. - */ - NTLM_CLIENT_ERROR_INVALID_INPUT = -2 -} ntlm_error_code; - -/* - * Flags for initializing the `ntlm_client` context. A combination of - * these flags can be provided to `ntlm_client_init`. - */ -typedef enum { - /** Default settings for the `ntlm_client`. */ - NTLM_CLIENT_DEFAULTS = 0, - - /** - * Disable Unicode negotiation. By default, strings are converted - * into UTF-16 when supplied to the remote host, but if this flag - * is specified, localizable strings (like username and password) - * will only be sent to the server as they were provided to the - * library. Since the NTLM protocol does not deliver the locale - * information, these will be interpreted by the remote host in - * whatever locale is configured, and likely be corrupted unless - * you limit yourself to ASCII. - * - * You are discouraged from setting this flag. - */ - NTLM_CLIENT_DISABLE_UNICODE = (1 << 0), - - /* - * Enable LM ("Lan Manager") authentication support. By default, - * LM authentication is disabled, since most remote servers have - * disabled support for it, and because it is both trivially - * brute-forced _and_ subject to rainbow table lookups. If this - * flag is enabled, LM is still not used unless NTLM2 support is - * also disabled. - * - * You are discouraged from setting this flag. - */ - NTLM_CLIENT_ENABLE_LM = (1 << 1), - - /* - * Enable NTLM ("Lan Manager") authentication support. By default, - * NTLM authentication is disabled, since most remote servers have - * disabled support for it, due to its weakness. If this flag is - * enabled, NTLM is still not used unless NTLM2 support is also - * disabled. - * - * You are discouraged from setting this flag. - */ - NTLM_CLIENT_ENABLE_NTLM = (1 << 2), - - /* - * Disable NTLM2 authentication support. By default, _only_ NTLM2 - * support is enabled, since most remote servers will only support - * it due to its (relative) lack of weakness. If this flag is - * set, either NTLM or LM (or both) must be explicitly enabled or - * there will be no mechanisms available to use. - * - * You are discouraged from setting this flag. - */ - NTLM_CLIENT_DISABLE_NTLM2 = (1 << 3), - - /* - * Request the target's name. By default, you are expected to - * provide the name of the target you are authenticating to (eg, - * the remote hostname). If set, the remote host will provide - * its idea of its hostname in the challenge message. You may - * then set the authentication target based on it. - */ - NTLM_CLIENT_DISABLE_REQUEST_TARGET = (1 << 4) -} ntlm_client_flags; - - -/** Declare a public function exported for application use. */ -#if __GNUC__ >= 4 && !defined(NTLM_STATIC) -# define NTLM_EXTERN(type) extern \ - __attribute__((visibility("default"))) \ - type -#elif defined(_MSC_VER) && !defined(NTLM_STATIC) -# define NTLM_EXTERN(type) __declspec(dllexport) type -#else -# define NTLM_EXTERN(type) extern type -#endif - -/** - * Initializes an `ntlm_client` context, which can begin sending - * and receiving NTLM authentication messages. - * - * @param flags the `ntlm_client_flag_t`s to use for negotiation. - * @return the `ntlm_client` context, or `NULL` if out-of-memory. - */ -NTLM_EXTERN(ntlm_client *) ntlm_client_init(ntlm_client_flags flags); - -/** - * Gets the error message for the most recent error that occurred. If - * a function returns an error, more details can be retrieved with this - * function. The string returned is a constant string; it should not - * be freed. - * - * @return a constant string containing the error message. - */ -NTLM_EXTERN(const char *) ntlm_client_errmsg(ntlm_client *ntlm); - -/** - * Sets the local hostname and domain. These strings should be in - * ASCII. They will be provided to the remote host during the - * negotiation phase. - * - * @param ntlm the `ntlm_client` context to configure - * @param hostname the hostname of the local machine - * @param domain the domain of the local machine - * @return 0 on success, non-zero on failure - */ -NTLM_EXTERN(int) ntlm_client_set_hostname( - ntlm_client *ntlm, - const char *hostname, - const char *domain); - -/** - * Sets the local operating system version. These numbers are expected - * to correspond to Windows operating system versions; for example - * major version 6, minor version 2, build 9200 would correspond to - * Windows 8 (aka "NT 6.2"). - * - * It is not likely that you need to set the local version. - * - * @param ntlm the `ntlm_client` context to configure - * @param major the major version number of the local operating system - * @param minor the minor version number of the local operating system - * @param build the build number of the local operating system - * @return 0 on success, non-zero on failure - */ -NTLM_EXTERN(int) ntlm_client_set_version( - ntlm_client *ntlm, - uint8_t major, - uint8_t minor, - uint16_t build); - -/** - * Sets the username and password to authenticate with to the remote - * host. Username and password may be specified in UTF-8 but the - * domain should be in ASCII. These will not be sent to the remote host - * but will instead be used to compute the LM, NTLM or NTLM2 responses, - * which will be provided to the remote host during the response phase. - * - * @param ntlm the `ntlm_client` context to configure - * @param username the username to authenticate with - * @param domain the domain of the user authenticating - * @param password the password to authenticate with - * @return 0 on success, non-zero on failure - */ -NTLM_EXTERN(int) ntlm_client_set_credentials( - ntlm_client *ntlm, - const char *username, - const char *domain, - const char *password); - -/** - * Sets the authentication target, your idea of the remote host's - * name. The target should be provided as ASCII. It will be - * provided to the remote host during the response phase. - * - * @param ntlm the `ntlm_client` context to configure - * @param target the name of the authentication target - * @return 0 on success, non-zero on failure - */ -NTLM_EXTERN(int) ntlm_client_set_target( - ntlm_client *ntlm, - const char *target); - -/** - * Gets the remote host's nonce, as it was provided in the challenge - * message. This is an opaque 8 byte value that is used to compute - * the LM, NTLM and NTLM2 responses. - * - * @param ntlm the `ntlm_client` context to query - * @return the challenge from the remote host - */ -NTLM_EXTERN(uint64_t) ntlm_client_challenge_nonce( - ntlm_client *ntlm); - -/** - * Gets the remote hosts's target name, which can be used as the - * authentication target. This will be given as it was provided - * in the challenge message. - * - * @param ntlm the `ntlm_client` context to query - * @return the remote host's target name - */ -NTLM_EXTERN(const char *) ntlm_client_target(ntlm_client *ntlm); - -/** - * Gets the remote hosts's name, which is generally its short name. - * This will be given as it was provided in the challenge message. - * - * @param ntlm the `ntlm_client` context to query - * @return the remote host's server name - */ -NTLM_EXTERN(const char *) ntlm_client_target_server(ntlm_client *ntlm); - -/** - * Gets the remote hosts's domain, which is generally the short or - * NT-style domain name. This will be given as it was provided in - * the challenge message. - * - * @param ntlm the `ntlm_client` context to query - * @return the remote host's domain - */ -NTLM_EXTERN(const char *) ntlm_client_target_domain(ntlm_client *ntlm); - -/** - * Gets the remote hosts's DNS name, which is generally the long-style - * Active Directory or fully-qualified hostname. This will be given - * as it was provided in the challenge message. - * - * @param ntlm the `ntlm_client` context to query - * @return the remote host's DNS name - */ -NTLM_EXTERN(const char *) ntlm_client_target_server_dns(ntlm_client *ntlm); - -/** - * Gets the remote hosts's DNS domain, which is generally the long-style - * Active Directory or fully-qualified domain name. This will be given - * as it was provided in the challenge message. - * - * @param ntlm the `ntlm_client` context to query - * @return the remote host's DNS domain - */ -NTLM_EXTERN(const char *) ntlm_client_target_domain_dns(ntlm_client *ntlm); - -/** - * Computes a negotiation message (aka a "Type 1" message) to begin - * NTLM authentication with the server. The local hostname should be - * set before calling this function (if necessary). This message - * should be delivered to the server to indicate a willingness to begin - * NTLM authentication. This buffer should not be freed by the caller. - * - * @param out a pointer to the negotiation message - * @param out_len a pointer to the length of the negotiation message - * @param ntlm the `ntlm_client` context - * @return 0 on success, non-zero on failure - */ -NTLM_EXTERN(int) ntlm_client_negotiate( - const unsigned char **out, - size_t *out_len, - ntlm_client *ntlm); - -/** - * Parses a challenge message (aka a "Type 2" message) from the server. - * This must be called in order to calculate the response to the - * authentication. - * - * @param ntlm the `ntlm_client` context - * @param message the challenge message from the server - * @param message_len the length of the challenge message - * @return 0 on success, non-zero on failure - */ -NTLM_EXTERN(int) ntlm_client_set_challenge( - ntlm_client *ntlm, - const unsigned char *message, - size_t message_len); - -/** - * Computes a response message (aka a "Type 3" message) to complete - * NTLM authentication with the server. The credentials should be - * set before calling this function. This message should be delivered - * to the server to complete authentication. This buffer should not - * be freed by the caller. - * - * @param out a pointer to the response message - * @param out_len a pointer to the length of the response message - * @param ntlm the `ntlm_client` context - * @return 0 on success, non-zero on failure - */ -NTLM_EXTERN(int) ntlm_client_response( - const unsigned char **out, - size_t *out_len, - ntlm_client *ntlm); - -/** - * Resets an `ntlm_client` context completely, so that authentication - * may be retried. You must set _all_ parameters again, including the - * target, username, password, etc. Once these values are configured - * again, the negotiation can begin. - * - * @param ntlm the `ntlm_client` context to reset - */ -NTLM_EXTERN(void) ntlm_client_reset(ntlm_client *ntlm); - -/** - * Frees an `ntlm_client` context. This should be done to free memory - * belonging to the context. The context cannot be reused. - * - * @param ntlm the `ntlm_client` context to free - */ -NTLM_EXTERN(void) ntlm_client_free(ntlm_client *ntlm); - -#ifdef __cplusplus -} -#endif - -#endif /* INCLUDE_NTLMCLIENT_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode.h deleted file mode 100644 index b7c63f2..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_UNICODE_H__ -#define PRIVATE_UNICODE_H__ - -#include "compat.h" - -#ifdef UNICODE_ICONV -# include "unicode_iconv.h" -#elif UNICODE_BUILTIN -# include "unicode_builtin.h" -#endif - -#define NTLM_UNICODE_MAX_LEN 2048 - -typedef struct ntlm_unicode_ctx ntlm_unicode_ctx; - -extern bool ntlm_unicode_init(ntlm_client *ntlm); - -bool ntlm_unicode_utf8_to_16( - char **converted, - size_t *converted_len, - ntlm_client *ntlm, - const char *string, - size_t string_len); - -bool ntlm_unicode_utf16_to_8( - char **converted, - size_t *converted_len, - ntlm_client *ntlm, - const char *string, - size_t string_len); - -extern void ntlm_unicode_shutdown(ntlm_client *ntlm); - -#endif /* PRIVATE_UNICODE_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_builtin.c b/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_builtin.c deleted file mode 100644 index cb98f70..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_builtin.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#include -#include - -#include "ntlm.h" -#include "unicode.h" -#include "compat.h" -#include "util.h" - -typedef unsigned int UTF32; /* at least 32 bits */ -typedef unsigned short UTF16; /* at least 16 bits */ -typedef unsigned char UTF8; /* typically 8 bits */ - -/* Some fundamental constants */ -#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD -#define UNI_MAX_BMP (UTF32)0x0000FFFF -#define UNI_MAX_UTF16 (UTF32)0x0010FFFF -#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF -#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF - -#define UNI_MAX_UTF8_BYTES_PER_CODE_POINT 4 - -typedef enum { - conversionOK, /* conversion successful */ - sourceExhausted, /* partial character in source, but hit end */ - targetExhausted, /* insuff. room in target for conversion */ - sourceIllegal /* source sequence is illegal/malformed */ -} ConversionResult; - -typedef enum { - strictConversion = 0, - lenientConversion -} ConversionFlags; - - -static const int halfShift = 10; /* used for shifting by 10 bits */ - -static const UTF32 halfBase = 0x0010000UL; -static const UTF32 halfMask = 0x3FFUL; - -#define UNI_SUR_HIGH_START (UTF32)0xD800 -#define UNI_SUR_HIGH_END (UTF32)0xDBFF -#define UNI_SUR_LOW_START (UTF32)0xDC00 -#define UNI_SUR_LOW_END (UTF32)0xDFFF -#define false 0 -#define true 1 - -/* --------------------------------------------------------------------- */ - -/* - * Index into the table below with the first byte of a UTF-8 sequence to - * get the number of trailing bytes that are supposed to follow it. - * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is - * left as-is for anyone who may want to do such conversion, which was - * allowed in earlier algorithms. - */ -static const char trailingBytesForUTF8[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 -}; - -/* - * Magic values subtracted from a buffer value during UTF8 conversion. - * This table contains as many values as there might be trailing bytes - * in a UTF-8 sequence. - */ -static const UTF32 offsetsFromUTF8[6] = { - 0x00000000UL, 0x00003080UL, 0x000E2080UL, - 0x03C82080UL, 0xFA082080UL, 0x82082080UL }; - -/* - * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed - * into the first byte, depending on how many bytes follow. There are - * as many entries in this table as there are UTF-8 sequence types. - * (I.e., one byte sequence, two byte... etc.). Remember that sequencs - * for *legal* UTF-8 will be 4 or fewer bytes total. - */ -static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - -/* --------------------------------------------------------------------- */ - -/* The interface converts a whole buffer to avoid function-call overhead. - * Constants have been gathered. Loops & conditionals have been removed as - * much as possible for efficiency, in favor of drop-through switches. - * (See "Note A" at the bottom of the file for equivalent code.) - * If your compiler supports it, the "isLegalUTF8" call can be turned - * into an inline function. - */ - -static ConversionResult ConvertUTF16toUTF8 ( - const UTF16** sourceStart, const UTF16* sourceEnd, - UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) { - ConversionResult result = conversionOK; - const UTF16* source = *sourceStart; - UTF8* target = *targetStart; - while (source < sourceEnd) { - UTF32 ch; - unsigned short bytesToWrite = 0; - const UTF32 byteMask = 0xBF; - const UTF32 byteMark = 0x80; - const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */ - ch = *source++; - /* If we have a surrogate pair, convert to UTF32 first. */ - if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) { - /* If the 16 bits following the high surrogate are in the source buffer... */ - if (source < sourceEnd) { - UTF32 ch2 = *source; - /* If it's a low surrogate, convert to UTF32. */ - if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) { - ch = ((ch - UNI_SUR_HIGH_START) << halfShift) - + (ch2 - UNI_SUR_LOW_START) + halfBase; - ++source; - } else if (flags == strictConversion) { /* it's an unpaired high surrogate */ - --source; /* return to the illegal value itself */ - result = sourceIllegal; - break; - } - } else { /* We don't have the 16 bits following the high surrogate. */ - --source; /* return to the high surrogate */ - result = sourceExhausted; - break; - } - } else if (flags == strictConversion) { - /* UTF-16 surrogate values are illegal in UTF-32 */ - if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) { - --source; /* return to the illegal value itself */ - result = sourceIllegal; - break; - } - } - /* Figure out how many bytes the result will require */ - if (ch < (UTF32)0x80) { bytesToWrite = 1; - } else if (ch < (UTF32)0x800) { bytesToWrite = 2; - } else if (ch < (UTF32)0x10000) { bytesToWrite = 3; - } else if (ch < (UTF32)0x110000) { bytesToWrite = 4; - } else { bytesToWrite = 3; - ch = UNI_REPLACEMENT_CHAR; - } - - target += bytesToWrite; - if (target > targetEnd) { - source = oldSource; /* Back up source pointer! */ - target -= bytesToWrite; result = targetExhausted; break; - } - switch (bytesToWrite) { /* note: everything falls through. */ - case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; - case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; - case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; - case 1: *--target = (UTF8)(ch | firstByteMark[bytesToWrite]); - } - target += bytesToWrite; - } - *sourceStart = source; - *targetStart = target; - return result; -} - -/* --------------------------------------------------------------------- */ - -/* - * Utility routine to tell whether a sequence of bytes is legal UTF-8. - * This must be called with the length pre-determined by the first byte. - * If not calling this from ConvertUTF8to*, then the length can be set by: - * length = trailingBytesForUTF8[*source]+1; - * and the sequence is illegal right away if there aren't that many bytes - * available. - * If presented with a length > 4, this returns false. The Unicode - * definition of UTF-8 goes up to 4-byte sequences. - */ - -NTLM_INLINE(bool) isLegalUTF8(const UTF8 *source, int length) { - UTF8 a; - const UTF8 *srcptr = source+length; - switch (length) { - default: return false; - /* Everything else falls through when "true"... */ - case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; - case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; - case 2: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; - - switch (*source) { - /* no fall-through in this inner switch */ - case 0xE0: if (a < 0xA0) return false; break; - case 0xED: if (a > 0x9F) return false; break; - case 0xF0: if (a < 0x90) return false; break; - case 0xF4: if (a > 0x8F) return false; break; - default: if (a < 0x80) return false; - } - - case 1: if (*source >= 0x80 && *source < 0xC2) return false; - } - if (*source > 0xF4) return false; - return true; -} - -static ConversionResult ConvertUTF8toUTF16 ( - const UTF8** sourceStart, const UTF8* sourceEnd, - UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) { - ConversionResult result = conversionOK; - const UTF8* source = *sourceStart; - UTF16* target = *targetStart; - while (source < sourceEnd) { - UTF32 ch = 0; - unsigned short extraBytesToRead = trailingBytesForUTF8[*source]; - if (extraBytesToRead >= sourceEnd - source) { - result = sourceExhausted; break; - } - /* Do this check whether lenient or strict */ - if (!isLegalUTF8(source, extraBytesToRead+1)) { - result = sourceIllegal; - break; - } - /* - * The cases all fall through. See "Note A" below. - */ - switch (extraBytesToRead) { - case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ - case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ - case 3: ch += *source++; ch <<= 6; - case 2: ch += *source++; ch <<= 6; - case 1: ch += *source++; ch <<= 6; - case 0: ch += *source++; - } - ch -= offsetsFromUTF8[extraBytesToRead]; - - if (target >= targetEnd) { - source -= (extraBytesToRead+1); /* Back up source pointer! */ - result = targetExhausted; break; - } - if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */ - /* UTF-16 surrogate values are illegal in UTF-32 */ - if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) { - if (flags == strictConversion) { - source -= (extraBytesToRead+1); /* return to the illegal value itself */ - result = sourceIllegal; - break; - } else { - *target++ = UNI_REPLACEMENT_CHAR; - } - } else { - *target++ = (UTF16)ch; /* normal case */ - } - } else if (ch > UNI_MAX_UTF16) { - if (flags == strictConversion) { - result = sourceIllegal; - source -= (extraBytesToRead+1); /* return to the start */ - break; /* Bail out; shouldn't continue */ - } else { - *target++ = UNI_REPLACEMENT_CHAR; - } - } else { - /* target is a character in range 0xFFFF - 0x10FFFF. */ - if (target + 1 >= targetEnd) { - source -= (extraBytesToRead+1); /* Back up source pointer! */ - result = targetExhausted; break; - } - ch -= halfBase; - *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START); - *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START); - } - } - *sourceStart = source; - *targetStart = target; - return result; -} - - -bool ntlm_unicode_init(ntlm_client *ntlm) -{ - NTLM_UNUSED(ntlm); - return true; -} - -typedef enum { - unicode_builtin_utf8_to_16, - unicode_builtin_utf16_to_8 -} unicode_builtin_encoding_direction; - -NTLM_INLINE(bool) unicode_builtin_encoding_convert( - char **converted, - size_t *converted_len, - ntlm_client *ntlm, - const char *string, - size_t string_len, - unicode_builtin_encoding_direction direction) -{ - const char *in_start, *in_end; - char *out, *out_start, *out_end, *new_out; - size_t out_size, out_len; - bool success = false; - ConversionResult result; - - *converted = NULL; - *converted_len = 0; - - in_start = string; - in_end = in_start + string_len; - - /* - * When translating UTF8 to UTF16, these strings are only used - * internally, and we obey the given length, so we can simply - * use a buffer that is 2x the size. Add an extra byte to NUL - * terminate the results (two bytes for UTF16). - */ - if (direction == unicode_builtin_utf8_to_16) - out_size = (string_len * 2 + 2); - else - out_size = (string_len / 2 + 1); - - /* Round to the nearest multiple of 8 */ - out_size = (out_size + 7) & ~7; - - if ((out = malloc(out_size)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return false; - } - - out_start = out; - out_end = out_start + out_size; - - /* Make room for NUL termination */ - if (direction == unicode_builtin_utf16_to_8) - out_end--; - - while (true) { - if (direction == unicode_builtin_utf8_to_16) - result = ConvertUTF8toUTF16( - (const UTF8 **)&in_start, (UTF8 *)in_end, - (UTF16 **)&out_start, (UTF16 *)out_end, strictConversion); - else - result = ConvertUTF16toUTF8( - (const UTF16 **)&in_start, (UTF16 *)in_end, - (UTF8 **)&out_start, (UTF8 *)out_end, lenientConversion); - - switch (result) { - case conversionOK: - success = true; - goto done; - case sourceExhausted: - ntlm_client_set_errmsg(ntlm, - "invalid unicode string; trailing data remains"); - goto done; - case targetExhausted: - break; - case sourceIllegal: - ntlm_client_set_errmsg(ntlm, - "invalid unicode string; trailing data remains"); - goto done; - default: - ntlm_client_set_errmsg(ntlm, - "unknown unicode conversion failure"); - goto done; - } - - /* Grow buffer size by 1.5 (rounded up to a multiple of 8) */ - out_size = ((((out_size << 1) - (out_size >> 1)) + 7) & ~7); - - if (out_size > NTLM_UNICODE_MAX_LEN) { - ntlm_client_set_errmsg(ntlm, "unicode conversion too large"); - goto done; - } - - out_len = out_start - out; - - if ((new_out = realloc(out, out_size)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - goto done; - } - - out = new_out; - out_start = new_out + out_len; - out_end = out + out_size; - - /* Make room for NUL termination */ - out_end -= (direction == unicode_builtin_utf8_to_16) ? 2 : 1; - } - -done: - if (!success) { - free(out); - return false; - } - - out_len = (out_start - out); - - /* NUL terminate */ - out[out_len] = '\0'; - - if (direction == unicode_builtin_utf8_to_16) - out[out_len+1] = '\0'; - - *converted = out; - *converted_len = out_len; - return true; -} - -bool ntlm_unicode_utf8_to_16( - char **converted, - size_t *converted_len, - ntlm_client *client, - const char *string, - size_t string_len) -{ - return unicode_builtin_encoding_convert(converted, converted_len, - client, string, string_len, unicode_builtin_utf8_to_16); -} - -bool ntlm_unicode_utf16_to_8( - char **converted, - size_t *converted_len, - ntlm_client *client, - const char *string, - size_t string_len) -{ - return unicode_builtin_encoding_convert(converted, converted_len, - client, string, string_len, unicode_builtin_utf16_to_8); -} - -void ntlm_unicode_shutdown(ntlm_client *ntlm) -{ - NTLM_UNUSED(ntlm); -} diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_builtin.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_builtin.h deleted file mode 100644 index eabec40..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_builtin.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_UNICODE_BUILTIN_H__ -#define PRIVATE_UNICODE_BUILTIN_H__ - -#include -#include - -#include "ntlmclient.h" - -struct ntlm_unicode_ctx { -}; - -#endif /* PRIVATE_UNICODE_BUILTIN_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_iconv.c b/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_iconv.c deleted file mode 100644 index ac53638..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_iconv.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#include -#include -#include -#include - -#include "ntlmclient.h" -#include "unicode.h" -#include "ntlm.h" -#include "util.h" -#include "compat.h" - -typedef enum { - unicode_iconv_utf8_to_16, - unicode_iconv_utf16_to_8 -} unicode_iconv_encoding_direction; - -bool ntlm_unicode_init(ntlm_client *ntlm) -{ - ntlm->unicode_ctx.utf8_to_16 = iconv_open("UTF-16LE", "UTF-8"); - ntlm->unicode_ctx.utf16_to_8 = iconv_open("UTF-8", "UTF-16LE"); - - if (ntlm->unicode_ctx.utf8_to_16 == (iconv_t)-1 || - ntlm->unicode_ctx.utf16_to_8 == (iconv_t)-1) { - if (errno == EINVAL) - ntlm_client_set_errmsg(ntlm, - "iconv does not support UTF8 <-> UTF16 conversion"); - else - ntlm_client_set_errmsg(ntlm, strerror(errno)); - - return false; - } - - return true; -} - -NTLM_INLINE(bool) unicode_iconv_encoding_convert( - char **converted, - size_t *converted_len, - ntlm_client *ntlm, - const char *string, - size_t string_len, - unicode_iconv_encoding_direction direction) -{ - char *in_start, *out_start, *out, *new_out; - size_t in_start_len, out_start_len, out_size, nul_size, ret, written = 0; - iconv_t converter; - - *converted = NULL; - *converted_len = 0; - - /* - * When translating UTF8 to UTF16, these strings are only used - * internally, and we obey the given length, so we can simply - * use a buffer that is 2x the size. When translating from UTF16 - * to UTF8, we may need to return to callers, so we need to NUL - * terminate and expect an extra byte for UTF8, two for UTF16. - */ - if (direction == unicode_iconv_utf8_to_16) { - converter = ntlm->unicode_ctx.utf8_to_16; - out_size = (string_len * 2) + 2; - nul_size = 2; - } else { - converter = ntlm->unicode_ctx.utf16_to_8; - out_size = (string_len / 2) + 1; - nul_size = 1; - } - - /* Round to the nearest multiple of 8 */ - out_size = (out_size + 7) & ~7; - - if ((out = malloc(out_size)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - return false; - } - - in_start = (char *)string; - in_start_len = string_len; - - while (true) { - out_start = out + written; - out_start_len = (out_size - nul_size) - written; - - ret = iconv(converter, &in_start, &in_start_len, &out_start, &out_start_len); - written = (out_size - nul_size) - out_start_len; - - if (ret == 0) - break; - - if (ret == (size_t)-1 && errno != E2BIG) { - ntlm_client_set_errmsg(ntlm, strerror(errno)); - goto on_error; - } - - /* Grow buffer size by 1.5 (rounded up to a multiple of 8) */ - out_size = ((((out_size << 1) - (out_size >> 1)) + 7) & ~7); - - if (out_size > NTLM_UNICODE_MAX_LEN) { - ntlm_client_set_errmsg(ntlm, "unicode conversion too large"); - goto on_error; - } - - if ((new_out = realloc(out, out_size)) == NULL) { - ntlm_client_set_errmsg(ntlm, "out of memory"); - goto on_error; - } - - out = new_out; - } - - if (in_start_len != 0) { - ntlm_client_set_errmsg(ntlm, - "invalid unicode string; trailing data remains"); - goto on_error; - } - - /* NUL terminate */ - out[written] = '\0'; - - if (direction == unicode_iconv_utf8_to_16) - out[written + 1] = '\0'; - - *converted = out; - - if (converted_len) - *converted_len = written; - - return true; - -on_error: - free(out); - return false; -} - -bool ntlm_unicode_utf8_to_16( - char **converted, - size_t *converted_len, - ntlm_client *ntlm, - const char *string, - size_t string_len) -{ - return unicode_iconv_encoding_convert( - converted, converted_len, ntlm, string, string_len, - unicode_iconv_utf8_to_16); -} - -bool ntlm_unicode_utf16_to_8( - char **converted, - size_t *converted_len, - ntlm_client *ntlm, - const char *string, - size_t string_len) -{ - return unicode_iconv_encoding_convert( - converted, converted_len, ntlm, string, string_len, - unicode_iconv_utf16_to_8); -} - -void ntlm_unicode_shutdown(ntlm_client *ntlm) -{ - if (ntlm->unicode_ctx.utf16_to_8 != (iconv_t)0 && - ntlm->unicode_ctx.utf16_to_8 != (iconv_t)-1) - iconv_close(ntlm->unicode_ctx.utf16_to_8); - - if (ntlm->unicode_ctx.utf8_to_16 != (iconv_t)0 && - ntlm->unicode_ctx.utf8_to_16 != (iconv_t)-1) - iconv_close(ntlm->unicode_ctx.utf8_to_16); - - ntlm->unicode_ctx.utf8_to_16 = (iconv_t)-1; - ntlm->unicode_ctx.utf16_to_8 = (iconv_t)-1; -} diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_iconv.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_iconv.h deleted file mode 100644 index 87a96a6..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/unicode_iconv.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_UNICODE_ICONV_H__ -#define PRIVATE_UNICODE_ICONV_H__ - -#include -#include - -#include "ntlmclient.h" - -struct ntlm_unicode_ctx { - iconv_t utf8_to_16; - iconv_t utf16_to_8; -}; - -#endif /* PRIVATE_UNICODE_ICONV_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/utf8.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/utf8.h deleted file mode 100644 index 495e259..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/utf8.h +++ /dev/null @@ -1,1712 +0,0 @@ -/* The latest version of this library is available on GitHub; - * https://github.com/sheredom/utf8.h */ - -/* This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to */ - -#ifndef SHEREDOM_UTF8_H_INCLUDED -#define SHEREDOM_UTF8_H_INCLUDED - -#if defined(_MSC_VER) -#pragma warning(push) - -/* disable warning: no function prototype given: converting '()' to '(void)' */ -#pragma warning(disable : 4255) - -/* disable warning: '__cplusplus' is not defined as a preprocessor macro, - * replacing with '0' for '#if/#elif' */ -#pragma warning(disable : 4668) - -/* disable warning: bytes padding added after construct */ -#pragma warning(disable : 4820) -#endif - -#if defined(__cplusplus) -#if defined(_MSC_VER) -#define utf8_cplusplus _MSVC_LANG -#else -#define utf8_cplusplus __cplusplus -#endif -#endif - -#include -#include - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif - -#if defined(_MSC_VER) && (_MSC_VER < 1920) -typedef __int32 utf8_int32_t; -#else -#include -typedef int32_t utf8_int32_t; -#endif - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wold-style-cast" -#pragma clang diagnostic ignored "-Wcast-qual" - -#if __has_warning("-Wunsafe-buffer-usage") -#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" -#endif -#endif - -#ifdef utf8_cplusplus -extern "C" { -#endif - -#if defined(__TINYC__) -#define UTF8_ATTRIBUTE(a) __attribute((a)) -#else -#define UTF8_ATTRIBUTE(a) __attribute__((a)) -#endif - -#if defined(_MSC_VER) -#define utf8_nonnull -#define utf8_pure -#define utf8_restrict __restrict -#define utf8_weak __inline -#elif defined(__clang__) || defined(__GNUC__) -#define utf8_nonnull UTF8_ATTRIBUTE(nonnull) -#define utf8_pure UTF8_ATTRIBUTE(pure) -#define utf8_restrict __restrict__ -#define utf8_weak UTF8_ATTRIBUTE(weak) -#elif defined(__TINYC__) -#define utf8_nonnull UTF8_ATTRIBUTE(nonnull) -#define utf8_pure UTF8_ATTRIBUTE(pure) -#define utf8_restrict -#define utf8_weak UTF8_ATTRIBUTE(weak) -#else -#error Non clang, non gcc, non MSVC, non tcc compiler found! -#endif - -#ifdef utf8_cplusplus -#define utf8_null NULL -#else -#define utf8_null 0 -#endif - -#if defined(utf8_cplusplus) && utf8_cplusplus >= 201402L && (!defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER >= 1910)) -#define utf8_constexpr14 constexpr -#define utf8_constexpr14_impl constexpr -#else -/* constexpr and weak are incompatible. so only enable one of them */ -#define utf8_constexpr14 utf8_weak -#define utf8_constexpr14_impl -#endif - -#if defined(utf8_cplusplus) && utf8_cplusplus >= 202002L -using utf8_int8_t = char8_t; /* Introduced in C++20 */ -#else -typedef char utf8_int8_t; -#endif - -/* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > - * src2 respectively, case insensitive. */ -utf8_constexpr14 utf8_nonnull utf8_pure int -utf8casecmp(const utf8_int8_t *src1, const utf8_int8_t *src2); - -/* Append the utf8 string src onto the utf8 string dst. */ -utf8_nonnull utf8_weak utf8_int8_t * -utf8cat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); - -/* Find the first match of the utf8 codepoint chr in the utf8 string src. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8chr(const utf8_int8_t *src, utf8_int32_t chr); - -/* Return less than 0, 0, greater than 0 if src1 < src2, - * src1 == src2, src1 > src2 respectively. */ -utf8_constexpr14 utf8_nonnull utf8_pure int utf8cmp(const utf8_int8_t *src1, - const utf8_int8_t *src2); - -/* Copy the utf8 string src onto the memory allocated in dst. */ -utf8_nonnull utf8_weak utf8_int8_t * -utf8cpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); - -/* Number of utf8 codepoints in the utf8 string src that consists entirely - * of utf8 codepoints not from the utf8 string reject. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t -utf8cspn(const utf8_int8_t *src, const utf8_int8_t *reject); - -/* Duplicate the utf8 string src by getting its size, malloc'ing a new buffer - * copying over the data, and returning that. Or 0 if malloc failed. */ -utf8_weak utf8_int8_t *utf8dup(const utf8_int8_t *src); - -/* Number of utf8 codepoints in the utf8 string str, - * excluding the null terminating byte. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8len(const utf8_int8_t *str); - -/* Similar to utf8len, except that only at most n bytes of src are looked. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8nlen(const utf8_int8_t *str, - size_t n); - -/* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > - * src2 respectively, case insensitive. Checking at most n bytes of each utf8 - * string. */ -utf8_constexpr14 utf8_nonnull utf8_pure int -utf8ncasecmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); - -/* Append the utf8 string src onto the utf8 string dst, - * writing at most n+1 bytes. Can produce an invalid utf8 - * string if n falls partway through a utf8 codepoint. */ -utf8_nonnull utf8_weak utf8_int8_t * -utf8ncat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, - size_t n); - -/* Return less than 0, 0, greater than 0 if src1 < src2, - * src1 == src2, src1 > src2 respectively. Checking at most n - * bytes of each utf8 string. */ -utf8_constexpr14 utf8_nonnull utf8_pure int -utf8ncmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); - -/* Copy the utf8 string src onto the memory allocated in dst. - * Copies at most n bytes. If n falls partway through a utf8 - * codepoint, or if dst doesn't have enough room for a null - * terminator, the final string will be cut short to preserve - * utf8 validity. */ - -utf8_nonnull utf8_weak utf8_int8_t * -utf8ncpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, - size_t n); - -/* Similar to utf8dup, except that at most n bytes of src are copied. If src is - * longer than n, only n bytes are copied and a null byte is added. - * - * Returns a new string if successful, 0 otherwise */ -utf8_weak utf8_int8_t *utf8ndup(const utf8_int8_t *src, size_t n); - -/* Locates the first occurrence in the utf8 string str of any byte in the - * utf8 string accept, or 0 if no match was found. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8pbrk(const utf8_int8_t *str, const utf8_int8_t *accept); - -/* Find the last match of the utf8 codepoint chr in the utf8 string src. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8rchr(const utf8_int8_t *src, int chr); - -/* Number of bytes in the utf8 string str, - * including the null terminating byte. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8size(const utf8_int8_t *str); - -/* Similar to utf8size, except that the null terminating byte is excluded. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t -utf8size_lazy(const utf8_int8_t *str); - -/* Similar to utf8size, except that only at most n bytes of src are looked and - * the null terminating byte is excluded. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t -utf8nsize_lazy(const utf8_int8_t *str, size_t n); - -/* Number of utf8 codepoints in the utf8 string src that consists entirely - * of utf8 codepoints from the utf8 string accept. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t -utf8spn(const utf8_int8_t *src, const utf8_int8_t *accept); - -/* The position of the utf8 string needle in the utf8 string haystack. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8str(const utf8_int8_t *haystack, const utf8_int8_t *needle); - -/* The position of the utf8 string needle in the utf8 string haystack, case - * insensitive. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8casestr(const utf8_int8_t *haystack, const utf8_int8_t *needle); - -/* Return 0 on success, or the position of the invalid - * utf8 codepoint on failure. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8valid(const utf8_int8_t *str); - -/* Similar to utf8valid, except that only at most n bytes of src are looked. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8nvalid(const utf8_int8_t *str, size_t n); - -/* Given a null-terminated string, makes the string valid by replacing invalid - * codepoints with a 1-byte replacement. Returns 0 on success. */ -utf8_nonnull utf8_weak int utf8makevalid(utf8_int8_t *str, - const utf8_int32_t replacement); - -/* Sets out_codepoint to the current utf8 codepoint in str, and returns the - * address of the next utf8 codepoint after the current one in str. */ -utf8_constexpr14 utf8_nonnull utf8_int8_t * -utf8codepoint(const utf8_int8_t *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint); - -/* Calculates the size of the next utf8 codepoint in str. */ -utf8_constexpr14 utf8_nonnull size_t -utf8codepointcalcsize(const utf8_int8_t *str); - -/* Returns the size of the given codepoint in bytes. */ -utf8_constexpr14 size_t utf8codepointsize(utf8_int32_t chr); - -/* Write a codepoint to the given string, and return the address to the next - * place after the written codepoint. Pass how many bytes left in the buffer to - * n. If there is not enough space for the codepoint, this function returns - * null. */ -utf8_nonnull utf8_weak utf8_int8_t * -utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n); - -/* Returns 1 if the given character is lowercase, or 0 if it is not. */ -utf8_constexpr14 int utf8islower(utf8_int32_t chr); - -/* Returns 1 if the given character is uppercase, or 0 if it is not. */ -utf8_constexpr14 int utf8isupper(utf8_int32_t chr); - -/* Transform the given string into all lowercase codepoints. */ -utf8_nonnull utf8_weak void utf8lwr(utf8_int8_t *utf8_restrict str); - -/* Transform the given string into all uppercase codepoints. */ -utf8_nonnull utf8_weak void utf8upr(utf8_int8_t *utf8_restrict str); - -/* Make a codepoint lower case if possible. */ -utf8_constexpr14 utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp); - -/* Make a codepoint upper case if possible. */ -utf8_constexpr14 utf8_int32_t utf8uprcodepoint(utf8_int32_t cp); - -/* Sets out_codepoint to the current utf8 codepoint in str, and returns the - * address of the previous utf8 codepoint before the current one in str. */ -utf8_constexpr14 utf8_nonnull utf8_int8_t * -utf8rcodepoint(const utf8_int8_t *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint); - -/* Duplicate the utf8 string src by getting its size, calling alloc_func_ptr to - * copy over data to a new buffer, and returning that. Or 0 if alloc_func_ptr - * returned null. */ -utf8_weak utf8_int8_t *utf8dup_ex(const utf8_int8_t *src, - utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, - size_t), - utf8_int8_t *user_data); - -/* Similar to utf8dup, except that at most n bytes of src are copied. If src is - * longer than n, only n bytes are copied and a null byte is added. - * - * Returns a new string if successful, 0 otherwise. */ -utf8_weak utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, - utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, - size_t), - utf8_int8_t *user_data); - -#undef utf8_weak -#undef utf8_pure -#undef utf8_nonnull - -utf8_constexpr14_impl int utf8casecmp(const utf8_int8_t *src1, - const utf8_int8_t *src2) { - utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, - src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; - - for (;;) { - src1 = utf8codepoint(src1, &src1_orig_cp); - src2 = utf8codepoint(src2, &src2_orig_cp); - - /* lower the srcs if required */ - src1_lwr_cp = utf8lwrcodepoint(src1_orig_cp); - src2_lwr_cp = utf8lwrcodepoint(src2_orig_cp); - - /* lower the srcs if required */ - src1_upr_cp = utf8uprcodepoint(src1_orig_cp); - src2_upr_cp = utf8uprcodepoint(src2_orig_cp); - - /* check if the lowered codepoints match */ - if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) { - return 0; - } else if ((src1_lwr_cp == src2_lwr_cp) || (src1_upr_cp == src2_upr_cp)) { - continue; - } - - /* if they don't match, then we return the difference between the characters - */ - return src1_lwr_cp - src2_lwr_cp; - } -} - -utf8_int8_t *utf8cat(utf8_int8_t *utf8_restrict dst, - const utf8_int8_t *utf8_restrict src) { - utf8_int8_t *d = dst; - /* find the null terminating byte in dst */ - while ('\0' != *d) { - d++; - } - - /* overwriting the null terminating byte in dst, append src byte-by-byte */ - while ('\0' != *src) { - *d++ = *src++; - } - - /* write out a new null terminating byte into dst */ - *d = '\0'; - - return dst; -} - -utf8_constexpr14_impl utf8_int8_t *utf8chr(const utf8_int8_t *src, - utf8_int32_t chr) { - utf8_int8_t c[5] = {'\0', '\0', '\0', '\0', '\0'}; - - if (0 == chr) { - /* being asked to return position of null terminating byte, so - * just run s to the end, and return! */ - while ('\0' != *src) { - src++; - } - return (utf8_int8_t *)src; - } else if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - /* 1-byte/7-bit ascii - * (0b0xxxxxxx) */ - c[0] = (utf8_int8_t)chr; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - /* 2-byte/11-bit utf8 code point - * (0b110xxxxx 0b10xxxxxx) */ - c[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)(chr >> 6)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - /* 3-byte/16-bit utf8 code point - * (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) */ - c[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)(chr >> 12)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } else { /* if (0 == ((int)0xffe00000 & chr)) { */ - /* 4-byte/21-bit utf8 code point - * (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) */ - c[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)(chr >> 18)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); - c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - c[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } - - /* we've made c into a 2 utf8 codepoint string, one for the chr we are - * seeking, another for the null terminating byte. Now use utf8str to - * search */ - return utf8str(src, c); -} - -utf8_constexpr14_impl int utf8cmp(const utf8_int8_t *src1, - const utf8_int8_t *src2) { - while (('\0' != *src1) || ('\0' != *src2)) { - if (*src1 < *src2) { - return -1; - } else if (*src1 > *src2) { - return 1; - } - - src1++; - src2++; - } - - /* both utf8 strings matched */ - return 0; -} - -utf8_constexpr14_impl int utf8coll(const utf8_int8_t *src1, - const utf8_int8_t *src2); - -utf8_int8_t *utf8cpy(utf8_int8_t *utf8_restrict dst, - const utf8_int8_t *utf8_restrict src) { - utf8_int8_t *d = dst; - - /* overwriting anything previously in dst, write byte-by-byte - * from src */ - while ('\0' != *src) { - *d++ = *src++; - } - - /* append null terminating byte */ - *d = '\0'; - - return dst; -} - -utf8_constexpr14_impl size_t utf8cspn(const utf8_int8_t *src, - const utf8_int8_t *reject) { - size_t chars = 0; - - while ('\0' != *src) { - const utf8_int8_t *r = reject; - size_t offset = 0; - - while ('\0' != *r) { - /* checking that if *r is the start of a utf8 codepoint - * (it is not 0b10xxxxxx) and we have successfully matched - * a previous character (0 < offset) - we found a match */ - if ((0x80 != (0xc0 & *r)) && (0 < offset)) { - return chars; - } else { - if (*r == src[offset]) { - /* part of a utf8 codepoint matched, so move our checking - * onwards to the next byte */ - offset++; - r++; - } else { - /* r could be in the middle of an unmatching utf8 code point, - * so we need to march it on to the next character beginning, */ - - do { - r++; - } while (0x80 == (0xc0 & *r)); - - /* reset offset too as we found a mismatch */ - offset = 0; - } - } - } - - /* found a match at the end of *r, so didn't get a chance to test it */ - if (0 < offset) { - return chars; - } - - /* the current utf8 codepoint in src did not match reject, but src - * could have been partway through a utf8 codepoint, so we need to - * march it onto the next utf8 codepoint starting byte */ - do { - src++; - } while ((0x80 == (0xc0 & *src))); - chars++; - } - - return chars; -} - -utf8_int8_t *utf8dup(const utf8_int8_t *src) { - return utf8dup_ex(src, utf8_null, utf8_null); -} - -utf8_int8_t *utf8dup_ex(const utf8_int8_t *src, - utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), - utf8_int8_t *user_data) { - utf8_int8_t *n = utf8_null; - - /* figure out how many bytes (including the terminator) we need to copy first - */ - size_t bytes = utf8size(src); - - if (alloc_func_ptr) { - n = alloc_func_ptr(user_data, bytes); - } else { -#if !defined(UTF8_NO_STD_MALLOC) - n = (utf8_int8_t *)malloc(bytes); -#else - return utf8_null; -#endif - } - - if (utf8_null == n) { - /* out of memory so we bail */ - return utf8_null; - } else { - bytes = 0; - - /* copy src byte-by-byte into our new utf8 string */ - while ('\0' != src[bytes]) { - n[bytes] = src[bytes]; - bytes++; - } - - /* append null terminating byte */ - n[bytes] = '\0'; - return n; - } -} - -utf8_constexpr14_impl utf8_int8_t *utf8fry(const utf8_int8_t *str); - -utf8_constexpr14_impl size_t utf8len(const utf8_int8_t *str) { - return utf8nlen(str, SIZE_MAX); -} - -utf8_constexpr14_impl size_t utf8nlen(const utf8_int8_t *str, size_t n) { - const utf8_int8_t *t = str; - size_t length = 0; - - while ((size_t)(str - t) < n && '\0' != *str) { - if (0xf0 == (0xf8 & *str)) { - /* 4-byte utf8 code point (began with 0b11110xxx) */ - str += 4; - } else if (0xe0 == (0xf0 & *str)) { - /* 3-byte utf8 code point (began with 0b1110xxxx) */ - str += 3; - } else if (0xc0 == (0xe0 & *str)) { - /* 2-byte utf8 code point (began with 0b110xxxxx) */ - str += 2; - } else { /* if (0x00 == (0x80 & *s)) { */ - /* 1-byte ascii (began with 0b0xxxxxxx) */ - str += 1; - } - - /* no matter the bytes we marched s forward by, it was - * only 1 utf8 codepoint */ - length++; - } - - if ((size_t)(str - t) > n) { - length--; - } - return length; -} - -utf8_constexpr14_impl int utf8ncasecmp(const utf8_int8_t *src1, - const utf8_int8_t *src2, size_t n) { - utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, - src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; - - do { - const utf8_int8_t *const s1 = src1; - const utf8_int8_t *const s2 = src2; - - /* first check that we have enough bytes left in n to contain an entire - * codepoint */ - if (0 == n) { - return 0; - } - - if ((1 == n) && ((0xc0 == (0xe0 & *s1)) || (0xc0 == (0xe0 & *s2)))) { - const utf8_int32_t c1 = (0xe0 & *s1); - const utf8_int32_t c2 = (0xe0 & *s2); - - if (c1 != c2) { - return c1 - c2; - } else { - return 0; - } - } - - if ((2 >= n) && ((0xe0 == (0xf0 & *s1)) || (0xe0 == (0xf0 & *s2)))) { - const utf8_int32_t c1 = (0xf0 & *s1); - const utf8_int32_t c2 = (0xf0 & *s2); - - if (c1 != c2) { - return c1 - c2; - } else { - return 0; - } - } - - if ((3 >= n) && ((0xf0 == (0xf8 & *s1)) || (0xf0 == (0xf8 & *s2)))) { - const utf8_int32_t c1 = (0xf8 & *s1); - const utf8_int32_t c2 = (0xf8 & *s2); - - if (c1 != c2) { - return c1 - c2; - } else { - return 0; - } - } - - src1 = utf8codepoint(src1, &src1_orig_cp); - src2 = utf8codepoint(src2, &src2_orig_cp); - n -= utf8codepointsize(src1_orig_cp); - - src1_lwr_cp = utf8lwrcodepoint(src1_orig_cp); - src2_lwr_cp = utf8lwrcodepoint(src2_orig_cp); - - src1_upr_cp = utf8uprcodepoint(src1_orig_cp); - src2_upr_cp = utf8uprcodepoint(src2_orig_cp); - - /* check if the lowered codepoints match */ - if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) { - return 0; - } else if ((src1_lwr_cp == src2_lwr_cp) || (src1_upr_cp == src2_upr_cp)) { - continue; - } - - /* if they don't match, then we return the difference between the characters - */ - return src1_lwr_cp - src2_lwr_cp; - } while (0 < n); - - /* both utf8 strings matched */ - return 0; -} - -utf8_int8_t *utf8ncat(utf8_int8_t *utf8_restrict dst, - const utf8_int8_t *utf8_restrict src, size_t n) { - utf8_int8_t *d = dst; - - /* find the null terminating byte in dst */ - while ('\0' != *d) { - d++; - } - - /* overwriting the null terminating byte in dst, append src byte-by-byte - * stopping if we run out of space */ - while (('\0' != *src) && (0 != n--)) { - *d++ = *src++; - } - - /* write out a new null terminating byte into dst */ - *d = '\0'; - - return dst; -} - -utf8_constexpr14_impl int utf8ncmp(const utf8_int8_t *src1, - const utf8_int8_t *src2, size_t n) { - while ((0 != n--) && (('\0' != *src1) || ('\0' != *src2))) { - if (*src1 < *src2) { - return -1; - } else if (*src1 > *src2) { - return 1; - } - - src1++; - src2++; - } - - /* both utf8 strings matched */ - return 0; -} - -utf8_int8_t *utf8ncpy(utf8_int8_t *utf8_restrict dst, - const utf8_int8_t *utf8_restrict src, size_t n) { - utf8_int8_t *d = dst; - size_t index = 0, check_index = 0; - - if (n == 0) { - return dst; - } - - /* overwriting anything previously in dst, write byte-by-byte - * from src */ - for (index = 0; index < n; index++) { - d[index] = src[index]; - if ('\0' == src[index]) { - break; - } - } - - for (check_index = index - 1; - check_index > 0 && 0x80 == (0xc0 & d[check_index]); check_index--) { - /* just moving the index */ - } - - if (check_index < index && - ((index - check_index) < utf8codepointcalcsize(&d[check_index]) || - (index - check_index) == n)) { - index = check_index; - } - - /* append null terminating byte */ - for (; index < n; index++) { - d[index] = 0; - } - - return dst; -} - -utf8_int8_t *utf8ndup(const utf8_int8_t *src, size_t n) { - return utf8ndup_ex(src, n, utf8_null, utf8_null); -} - -utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, - utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), - utf8_int8_t *user_data) { - utf8_int8_t *c = utf8_null; - size_t bytes = 0; - - /* Find the end of the string or stop when n is reached */ - while ('\0' != src[bytes] && bytes < n) { - bytes++; - } - - /* In case bytes is actually less than n, we need to set it - * to be used later in the copy byte by byte. */ - n = bytes; - - if (alloc_func_ptr) { - c = alloc_func_ptr(user_data, bytes + 1); - } else { -#if !defined(UTF8_NO_STD_MALLOC) - c = (utf8_int8_t *)malloc(bytes + 1); -#else - c = utf8_null; -#endif - } - - if (utf8_null == c) { - /* out of memory so we bail */ - return utf8_null; - } - - bytes = 0; - - /* copy src byte-by-byte into our new utf8 string */ - while ('\0' != src[bytes] && bytes < n) { - c[bytes] = src[bytes]; - bytes++; - } - - /* append null terminating byte */ - c[bytes] = '\0'; - return c; -} - -utf8_constexpr14_impl utf8_int8_t *utf8rchr(const utf8_int8_t *src, int chr) { - - utf8_int8_t *match = utf8_null; - utf8_int8_t c[5] = {'\0', '\0', '\0', '\0', '\0'}; - - if (0 == chr) { - /* being asked to return position of null terminating byte, so - * just run s to the end, and return! */ - while ('\0' != *src) { - src++; - } - return (utf8_int8_t *)src; - } else if (0 == ((int)0xffffff80 & chr)) { - /* 1-byte/7-bit ascii - * (0b0xxxxxxx) */ - c[0] = (utf8_int8_t)chr; - } else if (0 == ((int)0xfffff800 & chr)) { - /* 2-byte/11-bit utf8 code point - * (0b110xxxxx 0b10xxxxxx) */ - c[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)(chr >> 6)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } else if (0 == ((int)0xffff0000 & chr)) { - /* 3-byte/16-bit utf8 code point - * (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) */ - c[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)(chr >> 12)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } else { /* if (0 == ((int)0xffe00000 & chr)) { */ - /* 4-byte/21-bit utf8 code point - * (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) */ - c[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)(chr >> 18)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); - c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - c[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } - - /* we've created a 2 utf8 codepoint string in c that is - * the utf8 character asked for by chr, and a null - * terminating byte */ - - while ('\0' != *src) { - size_t offset = 0; - - while ((src[offset] == c[offset]) && ('\0' != src[offset])) { - offset++; - } - - if ('\0' == c[offset]) { - /* we found a matching utf8 code point */ - match = (utf8_int8_t *)src; - src += offset; - - if ('\0' == *src) { - break; - } - } else { - src += offset; - - /* need to march s along to next utf8 codepoint start - * (the next byte that doesn't match 0b10xxxxxx) */ - if ('\0' != *src) { - do { - src++; - } while (0x80 == (0xc0 & *src)); - } - } - } - - /* return the last match we found (or 0 if no match was found) */ - return match; -} - -utf8_constexpr14_impl utf8_int8_t *utf8pbrk(const utf8_int8_t *str, - const utf8_int8_t *accept) { - while ('\0' != *str) { - const utf8_int8_t *a = accept; - size_t offset = 0; - - while ('\0' != *a) { - /* checking that if *a is the start of a utf8 codepoint - * (it is not 0b10xxxxxx) and we have successfully matched - * a previous character (0 < offset) - we found a match */ - if ((0x80 != (0xc0 & *a)) && (0 < offset)) { - return (utf8_int8_t *)str; - } else { - if (*a == str[offset]) { - /* part of a utf8 codepoint matched, so move our checking - * onwards to the next byte */ - offset++; - a++; - } else { - /* r could be in the middle of an unmatching utf8 code point, - * so we need to march it on to the next character beginning, */ - - do { - a++; - } while (0x80 == (0xc0 & *a)); - - /* reset offset too as we found a mismatch */ - offset = 0; - } - } - } - - /* we found a match on the last utf8 codepoint */ - if (0 < offset) { - return (utf8_int8_t *)str; - } - - /* the current utf8 codepoint in src did not match accept, but src - * could have been partway through a utf8 codepoint, so we need to - * march it onto the next utf8 codepoint starting byte */ - do { - str++; - } while ((0x80 == (0xc0 & *str))); - } - - return utf8_null; -} - -utf8_constexpr14_impl size_t utf8size(const utf8_int8_t *str) { - return utf8size_lazy(str) + 1; -} - -utf8_constexpr14_impl size_t utf8size_lazy(const utf8_int8_t *str) { - return utf8nsize_lazy(str, SIZE_MAX); -} - -utf8_constexpr14_impl size_t utf8nsize_lazy(const utf8_int8_t *str, size_t n) { - size_t size = 0; - while (size < n && '\0' != str[size]) { - size++; - } - return size; -} - -utf8_constexpr14_impl size_t utf8spn(const utf8_int8_t *src, - const utf8_int8_t *accept) { - size_t chars = 0; - - while ('\0' != *src) { - const utf8_int8_t *a = accept; - size_t offset = 0; - - while ('\0' != *a) { - /* checking that if *r is the start of a utf8 codepoint - * (it is not 0b10xxxxxx) and we have successfully matched - * a previous character (0 < offset) - we found a match */ - if ((0x80 != (0xc0 & *a)) && (0 < offset)) { - /* found a match, so increment the number of utf8 codepoints - * that have matched and stop checking whether any other utf8 - * codepoints in a match */ - chars++; - src += offset; - offset = 0; - break; - } else { - if (*a == src[offset]) { - offset++; - a++; - } else { - /* a could be in the middle of an unmatching utf8 codepoint, - * so we need to march it on to the next character beginning, */ - do { - a++; - } while (0x80 == (0xc0 & *a)); - - /* reset offset too as we found a mismatch */ - offset = 0; - } - } - } - - /* found a match at the end of *a, so didn't get a chance to test it */ - if (0 < offset) { - chars++; - src += offset; - continue; - } - - /* if a got to its terminating null byte, then we didn't find a match. - * Return the current number of matched utf8 codepoints */ - if ('\0' == *a) { - return chars; - } - } - - return chars; -} - -utf8_constexpr14_impl utf8_int8_t *utf8str(const utf8_int8_t *haystack, - const utf8_int8_t *needle) { - utf8_int32_t throwaway_codepoint = 0; - - /* if needle has no utf8 codepoints before the null terminating - * byte then return haystack */ - if ('\0' == *needle) { - return (utf8_int8_t *)haystack; - } - - while ('\0' != *haystack) { - const utf8_int8_t *maybeMatch = haystack; - const utf8_int8_t *n = needle; - - while (*haystack == *n && (*haystack != '\0' && *n != '\0')) { - n++; - haystack++; - } - - if ('\0' == *n) { - /* we found the whole utf8 string for needle in haystack at - * maybeMatch, so return it */ - return (utf8_int8_t *)maybeMatch; - } else { - /* h could be in the middle of an unmatching utf8 codepoint, - * so we need to march it on to the next character beginning - * starting from the current character */ - haystack = utf8codepoint(maybeMatch, &throwaway_codepoint); - } - } - - /* no match */ - return utf8_null; -} - -utf8_constexpr14_impl utf8_int8_t *utf8casestr(const utf8_int8_t *haystack, - const utf8_int8_t *needle) { - /* if needle has no utf8 codepoints before the null terminating - * byte then return haystack */ - if ('\0' == *needle) { - return (utf8_int8_t *)haystack; - } - - for (;;) { - const utf8_int8_t *maybeMatch = haystack; - const utf8_int8_t *n = needle; - utf8_int32_t h_cp = 0, n_cp = 0; - - /* Get the next code point and track it */ - const utf8_int8_t *nextH = haystack = utf8codepoint(haystack, &h_cp); - n = utf8codepoint(n, &n_cp); - - while ((0 != h_cp) && (0 != n_cp)) { - h_cp = utf8lwrcodepoint(h_cp); - n_cp = utf8lwrcodepoint(n_cp); - - /* if we find a mismatch, bail out! */ - if (h_cp != n_cp) { - break; - } - - haystack = utf8codepoint(haystack, &h_cp); - n = utf8codepoint(n, &n_cp); - } - - if (0 == n_cp) { - /* we found the whole utf8 string for needle in haystack at - * maybeMatch, so return it */ - return (utf8_int8_t *)maybeMatch; - } - - if (0 == h_cp) { - /* no match */ - return utf8_null; - } - - /* Roll back to the next code point in the haystack to test */ - haystack = nextH; - } -} - -utf8_constexpr14_impl utf8_int8_t *utf8valid(const utf8_int8_t *str) { - return utf8nvalid(str, SIZE_MAX); -} - -utf8_constexpr14_impl utf8_int8_t *utf8nvalid(const utf8_int8_t *str, - size_t n) { - const utf8_int8_t *t = str; - size_t consumed = 0; - - while ((void)(consumed = (size_t)(str - t)), consumed < n && '\0' != *str) { - const size_t remaining = n - consumed; - - if (0xf0 == (0xf8 & *str)) { - /* ensure that there's 4 bytes or more remaining */ - if (remaining < 4) { - return (utf8_int8_t *)str; - } - - /* ensure each of the 3 following bytes in this 4-byte - * utf8 codepoint began with 0b10xxxxxx */ - if ((0x80 != (0xc0 & str[1])) || (0x80 != (0xc0 & str[2])) || - (0x80 != (0xc0 & str[3]))) { - return (utf8_int8_t *)str; - } - - /* ensure that our utf8 codepoint ended after 4 bytes */ - if ((remaining != 4) && (0x80 == (0xc0 & str[4]))) { - return (utf8_int8_t *)str; - } - - /* ensure that the top 5 bits of this 4-byte utf8 - * codepoint were not 0, as then we could have used - * one of the smaller encodings */ - if ((0 == (0x07 & str[0])) && (0 == (0x30 & str[1]))) { - return (utf8_int8_t *)str; - } - - /* 4-byte utf8 code point (began with 0b11110xxx) */ - str += 4; - } else if (0xe0 == (0xf0 & *str)) { - /* ensure that there's 3 bytes or more remaining */ - if (remaining < 3) { - return (utf8_int8_t *)str; - } - - /* ensure each of the 2 following bytes in this 3-byte - * utf8 codepoint began with 0b10xxxxxx */ - if ((0x80 != (0xc0 & str[1])) || (0x80 != (0xc0 & str[2]))) { - return (utf8_int8_t *)str; - } - - /* ensure that our utf8 codepoint ended after 3 bytes */ - if ((remaining != 3) && (0x80 == (0xc0 & str[3]))) { - return (utf8_int8_t *)str; - } - - /* ensure that the top 5 bits of this 3-byte utf8 - * codepoint were not 0, as then we could have used - * one of the smaller encodings */ - if ((0 == (0x0f & str[0])) && (0 == (0x20 & str[1]))) { - return (utf8_int8_t *)str; - } - - /* 3-byte utf8 code point (began with 0b1110xxxx) */ - str += 3; - } else if (0xc0 == (0xe0 & *str)) { - /* ensure that there's 2 bytes or more remaining */ - if (remaining < 2) { - return (utf8_int8_t *)str; - } - - /* ensure the 1 following byte in this 2-byte - * utf8 codepoint began with 0b10xxxxxx */ - if (0x80 != (0xc0 & str[1])) { - return (utf8_int8_t *)str; - } - - /* ensure that our utf8 codepoint ended after 2 bytes */ - if ((remaining != 2) && (0x80 == (0xc0 & str[2]))) { - return (utf8_int8_t *)str; - } - - /* ensure that the top 4 bits of this 2-byte utf8 - * codepoint were not 0, as then we could have used - * one of the smaller encodings */ - if (0 == (0x1e & str[0])) { - return (utf8_int8_t *)str; - } - - /* 2-byte utf8 code point (began with 0b110xxxxx) */ - str += 2; - } else if (0x00 == (0x80 & *str)) { - /* 1-byte ascii (began with 0b0xxxxxxx) */ - str += 1; - } else { - /* we have an invalid 0b1xxxxxxx utf8 code point entry */ - return (utf8_int8_t *)str; - } - } - - return utf8_null; -} - -int utf8makevalid(utf8_int8_t *str, const utf8_int32_t replacement) { - utf8_int8_t *read = str; - utf8_int8_t *write = read; - const utf8_int8_t r = (utf8_int8_t)replacement; - utf8_int32_t codepoint = 0; - - if (replacement > 0x7f) { - return -1; - } - - while ('\0' != *read) { - if (0xf0 == (0xf8 & *read)) { - /* ensure each of the 3 following bytes in this 4-byte - * utf8 codepoint began with 0b10xxxxxx */ - if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2])) || - (0x80 != (0xc0 & read[3]))) { - *write++ = r; - read++; - continue; - } - - /* 4-byte utf8 code point (began with 0b11110xxx) */ - read = utf8codepoint(read, &codepoint); - write = utf8catcodepoint(write, codepoint, 4); - } else if (0xe0 == (0xf0 & *read)) { - /* ensure each of the 2 following bytes in this 3-byte - * utf8 codepoint began with 0b10xxxxxx */ - if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2]))) { - *write++ = r; - read++; - continue; - } - - /* 3-byte utf8 code point (began with 0b1110xxxx) */ - read = utf8codepoint(read, &codepoint); - write = utf8catcodepoint(write, codepoint, 3); - } else if (0xc0 == (0xe0 & *read)) { - /* ensure the 1 following byte in this 2-byte - * utf8 codepoint began with 0b10xxxxxx */ - if (0x80 != (0xc0 & read[1])) { - *write++ = r; - read++; - continue; - } - - /* 2-byte utf8 code point (began with 0b110xxxxx) */ - read = utf8codepoint(read, &codepoint); - write = utf8catcodepoint(write, codepoint, 2); - } else if (0x00 == (0x80 & *read)) { - /* 1-byte ascii (began with 0b0xxxxxxx) */ - read = utf8codepoint(read, &codepoint); - write = utf8catcodepoint(write, codepoint, 1); - } else { - /* if we got here then we've got a dangling continuation (0b10xxxxxx) */ - *write++ = r; - read++; - continue; - } - } - - *write = '\0'; - - return 0; -} - -utf8_constexpr14_impl utf8_int8_t * -utf8codepoint(const utf8_int8_t *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint) { - if (0xf0 == (0xf8 & str[0])) { - /* 4 byte utf8 codepoint */ - *out_codepoint = ((0x07 & str[0]) << 18) | ((0x3f & str[1]) << 12) | - ((0x3f & str[2]) << 6) | (0x3f & str[3]); - str += 4; - } else if (0xe0 == (0xf0 & str[0])) { - /* 3 byte utf8 codepoint */ - *out_codepoint = - ((0x0f & str[0]) << 12) | ((0x3f & str[1]) << 6) | (0x3f & str[2]); - str += 3; - } else if (0xc0 == (0xe0 & str[0])) { - /* 2 byte utf8 codepoint */ - *out_codepoint = ((0x1f & str[0]) << 6) | (0x3f & str[1]); - str += 2; - } else { - /* 1 byte utf8 codepoint otherwise */ - *out_codepoint = str[0]; - str += 1; - } - - return (utf8_int8_t *)str; -} - -utf8_constexpr14_impl size_t utf8codepointcalcsize(const utf8_int8_t *str) { - if (0xf0 == (0xf8 & str[0])) { - /* 4 byte utf8 codepoint */ - return 4; - } else if (0xe0 == (0xf0 & str[0])) { - /* 3 byte utf8 codepoint */ - return 3; - } else if (0xc0 == (0xe0 & str[0])) { - /* 2 byte utf8 codepoint */ - return 2; - } - - /* 1 byte utf8 codepoint otherwise */ - return 1; -} - -utf8_constexpr14_impl size_t utf8codepointsize(utf8_int32_t chr) { - if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - return 1; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - return 2; - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - return 3; - } else { /* if (0 == ((int)0xffe00000 & chr)) { */ - return 4; - } -} - -utf8_int8_t *utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n) { - if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - /* 1-byte/7-bit ascii - * (0b0xxxxxxx) */ - if (n < 1) { - return utf8_null; - } - str[0] = (utf8_int8_t)chr; - str += 1; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - /* 2-byte/11-bit utf8 code point - * (0b110xxxxx 0b10xxxxxx) */ - if (n < 2) { - return utf8_null; - } - str[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)((chr >> 6) & 0x1f)); - str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - str += 2; - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - /* 3-byte/16-bit utf8 code point - * (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) */ - if (n < 3) { - return utf8_null; - } - str[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)((chr >> 12) & 0x0f)); - str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - str += 3; - } else { /* if (0 == ((int)0xffe00000 & chr)) { */ - /* 4-byte/21-bit utf8 code point - * (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) */ - if (n < 4) { - return utf8_null; - } - str[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)((chr >> 18) & 0x07)); - str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); - str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - str[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - str += 4; - } - - return str; -} - -utf8_constexpr14_impl int utf8islower(utf8_int32_t chr) { - return chr != utf8uprcodepoint(chr); -} - -utf8_constexpr14_impl int utf8isupper(utf8_int32_t chr) { - return chr != utf8lwrcodepoint(chr); -} - -void utf8lwr(utf8_int8_t *utf8_restrict str) { - utf8_int32_t cp = 0; - utf8_int8_t *pn = utf8codepoint(str, &cp); - - while (cp != 0) { - const utf8_int32_t lwr_cp = utf8lwrcodepoint(cp); - const size_t size = utf8codepointsize(lwr_cp); - - if (lwr_cp != cp) { - utf8catcodepoint(str, lwr_cp, size); - } - - str = pn; - pn = utf8codepoint(str, &cp); - } -} - -void utf8upr(utf8_int8_t *utf8_restrict str) { - utf8_int32_t cp = 0; - utf8_int8_t *pn = utf8codepoint(str, &cp); - - while (cp != 0) { - const utf8_int32_t lwr_cp = utf8uprcodepoint(cp); - const size_t size = utf8codepointsize(lwr_cp); - - if (lwr_cp != cp) { - utf8catcodepoint(str, lwr_cp, size); - } - - str = pn; - pn = utf8codepoint(str, &cp); - } -} - -utf8_constexpr14_impl utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp) { - if (((0x0041 <= cp) && (0x005a >= cp)) || - ((0x00c0 <= cp) && (0x00d6 >= cp)) || - ((0x00d8 <= cp) && (0x00de >= cp)) || - ((0x0391 <= cp) && (0x03a1 >= cp)) || - ((0x03a3 <= cp) && (0x03ab >= cp)) || - ((0x0410 <= cp) && (0x042f >= cp))) { - cp += 32; - } else if ((0x0400 <= cp) && (0x040f >= cp)) { - cp += 80; - } else if (((0x0100 <= cp) && (0x012f >= cp)) || - ((0x0132 <= cp) && (0x0137 >= cp)) || - ((0x014a <= cp) && (0x0177 >= cp)) || - ((0x0182 <= cp) && (0x0185 >= cp)) || - ((0x01a0 <= cp) && (0x01a5 >= cp)) || - ((0x01de <= cp) && (0x01ef >= cp)) || - ((0x01f8 <= cp) && (0x021f >= cp)) || - ((0x0222 <= cp) && (0x0233 >= cp)) || - ((0x0246 <= cp) && (0x024f >= cp)) || - ((0x03d8 <= cp) && (0x03ef >= cp)) || - ((0x0460 <= cp) && (0x0481 >= cp)) || - ((0x048a <= cp) && (0x04ff >= cp))) { - cp |= 0x1; - } else if (((0x0139 <= cp) && (0x0148 >= cp)) || - ((0x0179 <= cp) && (0x017e >= cp)) || - ((0x01af <= cp) && (0x01b0 >= cp)) || - ((0x01b3 <= cp) && (0x01b6 >= cp)) || - ((0x01cd <= cp) && (0x01dc >= cp))) { - cp += 1; - cp &= ~0x1; - } else { - switch (cp) { - default: - break; - case 0x0178: - cp = 0x00ff; - break; - case 0x0243: - cp = 0x0180; - break; - case 0x018e: - cp = 0x01dd; - break; - case 0x023d: - cp = 0x019a; - break; - case 0x0220: - cp = 0x019e; - break; - case 0x01b7: - cp = 0x0292; - break; - case 0x01c4: - cp = 0x01c6; - break; - case 0x01c7: - cp = 0x01c9; - break; - case 0x01ca: - cp = 0x01cc; - break; - case 0x01f1: - cp = 0x01f3; - break; - case 0x01f7: - cp = 0x01bf; - break; - case 0x0187: - cp = 0x0188; - break; - case 0x018b: - cp = 0x018c; - break; - case 0x0191: - cp = 0x0192; - break; - case 0x0198: - cp = 0x0199; - break; - case 0x01a7: - cp = 0x01a8; - break; - case 0x01ac: - cp = 0x01ad; - break; - case 0x01b8: - cp = 0x01b9; - break; - case 0x01bc: - cp = 0x01bd; - break; - case 0x01f4: - cp = 0x01f5; - break; - case 0x023b: - cp = 0x023c; - break; - case 0x0241: - cp = 0x0242; - break; - case 0x03fd: - cp = 0x037b; - break; - case 0x03fe: - cp = 0x037c; - break; - case 0x03ff: - cp = 0x037d; - break; - case 0x037f: - cp = 0x03f3; - break; - case 0x0386: - cp = 0x03ac; - break; - case 0x0388: - cp = 0x03ad; - break; - case 0x0389: - cp = 0x03ae; - break; - case 0x038a: - cp = 0x03af; - break; - case 0x038c: - cp = 0x03cc; - break; - case 0x038e: - cp = 0x03cd; - break; - case 0x038f: - cp = 0x03ce; - break; - case 0x0370: - cp = 0x0371; - break; - case 0x0372: - cp = 0x0373; - break; - case 0x0376: - cp = 0x0377; - break; - case 0x03f4: - cp = 0x03b8; - break; - case 0x03cf: - cp = 0x03d7; - break; - case 0x03f9: - cp = 0x03f2; - break; - case 0x03f7: - cp = 0x03f8; - break; - case 0x03fa: - cp = 0x03fb; - break; - } - } - - return cp; -} - -utf8_constexpr14_impl utf8_int32_t utf8uprcodepoint(utf8_int32_t cp) { - if (((0x0061 <= cp) && (0x007a >= cp)) || - ((0x00e0 <= cp) && (0x00f6 >= cp)) || - ((0x00f8 <= cp) && (0x00fe >= cp)) || - ((0x03b1 <= cp) && (0x03c1 >= cp)) || - ((0x03c3 <= cp) && (0x03cb >= cp)) || - ((0x0430 <= cp) && (0x044f >= cp))) { - cp -= 32; - } else if ((0x0450 <= cp) && (0x045f >= cp)) { - cp -= 80; - } else if (((0x0100 <= cp) && (0x012f >= cp)) || - ((0x0132 <= cp) && (0x0137 >= cp)) || - ((0x014a <= cp) && (0x0177 >= cp)) || - ((0x0182 <= cp) && (0x0185 >= cp)) || - ((0x01a0 <= cp) && (0x01a5 >= cp)) || - ((0x01de <= cp) && (0x01ef >= cp)) || - ((0x01f8 <= cp) && (0x021f >= cp)) || - ((0x0222 <= cp) && (0x0233 >= cp)) || - ((0x0246 <= cp) && (0x024f >= cp)) || - ((0x03d8 <= cp) && (0x03ef >= cp)) || - ((0x0460 <= cp) && (0x0481 >= cp)) || - ((0x048a <= cp) && (0x04ff >= cp))) { - cp &= ~0x1; - } else if (((0x0139 <= cp) && (0x0148 >= cp)) || - ((0x0179 <= cp) && (0x017e >= cp)) || - ((0x01af <= cp) && (0x01b0 >= cp)) || - ((0x01b3 <= cp) && (0x01b6 >= cp)) || - ((0x01cd <= cp) && (0x01dc >= cp))) { - cp -= 1; - cp |= 0x1; - } else { - switch (cp) { - default: - break; - case 0x00ff: - cp = 0x0178; - break; - case 0x0180: - cp = 0x0243; - break; - case 0x01dd: - cp = 0x018e; - break; - case 0x019a: - cp = 0x023d; - break; - case 0x019e: - cp = 0x0220; - break; - case 0x0292: - cp = 0x01b7; - break; - case 0x01c6: - cp = 0x01c4; - break; - case 0x01c9: - cp = 0x01c7; - break; - case 0x01cc: - cp = 0x01ca; - break; - case 0x01f3: - cp = 0x01f1; - break; - case 0x01bf: - cp = 0x01f7; - break; - case 0x0188: - cp = 0x0187; - break; - case 0x018c: - cp = 0x018b; - break; - case 0x0192: - cp = 0x0191; - break; - case 0x0199: - cp = 0x0198; - break; - case 0x01a8: - cp = 0x01a7; - break; - case 0x01ad: - cp = 0x01ac; - break; - case 0x01b9: - cp = 0x01b8; - break; - case 0x01bd: - cp = 0x01bc; - break; - case 0x01f5: - cp = 0x01f4; - break; - case 0x023c: - cp = 0x023b; - break; - case 0x0242: - cp = 0x0241; - break; - case 0x037b: - cp = 0x03fd; - break; - case 0x037c: - cp = 0x03fe; - break; - case 0x037d: - cp = 0x03ff; - break; - case 0x03f3: - cp = 0x037f; - break; - case 0x03ac: - cp = 0x0386; - break; - case 0x03ad: - cp = 0x0388; - break; - case 0x03ae: - cp = 0x0389; - break; - case 0x03af: - cp = 0x038a; - break; - case 0x03cc: - cp = 0x038c; - break; - case 0x03cd: - cp = 0x038e; - break; - case 0x03ce: - cp = 0x038f; - break; - case 0x0371: - cp = 0x0370; - break; - case 0x0373: - cp = 0x0372; - break; - case 0x0377: - cp = 0x0376; - break; - case 0x03d1: - cp = 0x0398; - break; - case 0x03d7: - cp = 0x03cf; - break; - case 0x03f2: - cp = 0x03f9; - break; - case 0x03f8: - cp = 0x03f7; - break; - case 0x03fb: - cp = 0x03fa; - break; - } - } - - return cp; -} - -utf8_constexpr14_impl utf8_int8_t * -utf8rcodepoint(const utf8_int8_t *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint) { - const utf8_int8_t *s = (const utf8_int8_t *)str; - - if (0xf0 == (0xf8 & s[0])) { - /* 4 byte utf8 codepoint */ - *out_codepoint = ((0x07 & s[0]) << 18) | ((0x3f & s[1]) << 12) | - ((0x3f & s[2]) << 6) | (0x3f & s[3]); - } else if (0xe0 == (0xf0 & s[0])) { - /* 3 byte utf8 codepoint */ - *out_codepoint = - ((0x0f & s[0]) << 12) | ((0x3f & s[1]) << 6) | (0x3f & s[2]); - } else if (0xc0 == (0xe0 & s[0])) { - /* 2 byte utf8 codepoint */ - *out_codepoint = ((0x1f & s[0]) << 6) | (0x3f & s[1]); - } else { - /* 1 byte utf8 codepoint otherwise */ - *out_codepoint = s[0]; - } - - do { - s--; - } while ((0 != (0x80 & s[0])) && (0x80 == (0xc0 & s[0]))); - - return (utf8_int8_t *)s; -} - -#undef utf8_restrict -#undef utf8_constexpr14 -#undef utf8_null - -#ifdef utf8_cplusplus -} /* extern "C" */ -#endif - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif - -#endif /* SHEREDOM_UTF8_H_INCLUDED */ diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/util.c b/vendor/libgit2-sys/libgit2/deps/ntlmclient/util.c deleted file mode 100644 index 07d10f6..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/util.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#include -#include -#include - -#include "compat.h" -#include "util.h" - -void ntlm_memzero(void *data, size_t size) -{ - volatile uint8_t *scan = (volatile uint8_t *)data; - - while (size--) - *scan++ = 0x0; -} - -uint64_t ntlm_htonll(uint64_t value) -{ - static union { - uint32_t i; - char c[8]; - } test = { 0x01020304 }; - - if (test.c[0] == 0x01) - return value; - else - return ((uint64_t)htonl(value) << 32) | htonl((uint64_t)value >> 32); -} diff --git a/vendor/libgit2-sys/libgit2/deps/ntlmclient/util.h b/vendor/libgit2-sys/libgit2/deps/ntlmclient/util.h deleted file mode 100644 index 48e0169..0000000 --- a/vendor/libgit2-sys/libgit2/deps/ntlmclient/util.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) Edward Thomson. All rights reserved. - * - * This file is part of ntlmclient, distributed under the MIT license. - * For full terms and copyright information, and for third-party - * copyright information, see the included LICENSE.txt file. - */ - -#ifndef PRIVATE_UTIL_H__ -#define PRIVATE_UTIL_H__ - -#include -#include - -#if defined(_MSC_VER) -# define NTLM_INLINE(type) static __inline type -#elif defined(__GNUC__) -# define NTLM_INLINE(type) static __inline__ type -#else -# define NTLM_INLINE(type) static type -#endif - -extern void ntlm_memzero(void *data, size_t size); -extern uint64_t ntlm_htonll(uint64_t value); - -#endif /* PRIVATE_UTIL_H__ */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/CMakeLists.txt b/vendor/libgit2-sys/libgit2/deps/pcre2/CMakeLists.txt deleted file mode 100644 index b680739..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/CMakeLists.txt +++ /dev/null @@ -1,110 +0,0 @@ -# -# Static configuration -# - -set(SUPPORT_PCRE2_8 1) -set(SUPPORT_UNICODE 1) -set(PCRE2_NEWLINE "LF") -set(NEWLINE_DEFAULT "2") -set(PCRE2_LINK_SIZE "2") -set(PCRE2_MAX_VARLOOKBEHIND "255") -set(PCRE2_PARENS_NEST_LIMIT "250") -set(PCRE2_HEAP_LIMIT "20000000") -set(PCRE2_MATCH_LIMIT "10000000") -set(PCRE2_MATCH_LIMIT_DEPTH "MATCH_LIMIT") - - -# -# Dynamic configuration -# - -include(CheckCSourceCompiles) -include(CheckFunctionExists) -include(CheckSymbolExists) -include(CheckIncludeFile) - -check_include_file(assert.h HAVE_ASSERT_H) -check_include_file(dirent.h HAVE_DIRENT_H) -check_include_file(sys/stat.h HAVE_SYS_STAT_H) -check_include_file(sys/types.h HAVE_SYS_TYPES_H) -check_include_file(unistd.h HAVE_UNISTD_H) -check_include_file(windows.h HAVE_WINDOWS_H) - -check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE) # glibc 2.27 -check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV) # glibc 2.17 - -check_c_source_compiles( - "int main(void) { char buf[128] __attribute__((uninitialized)); (void)buf; return 0; }" - HAVE_ATTRIBUTE_UNINITIALIZED -) - -check_c_source_compiles("int main(void) { __assume(1); return 0; }" HAVE_BUILTIN_ASSUME) - -check_c_source_compiles( - [=[ - #include - int main(void) { int a,b; size_t m; __builtin_mul_overflow(a,b,&m); return 0; } - ]=] - HAVE_BUILTIN_MUL_OVERFLOW -) - -check_c_source_compiles( - "int main(int c, char *v[]) { if (c) __builtin_unreachable(); return (int)(*v[0]); }" - HAVE_BUILTIN_UNREACHABLE -) - - -# Output files - -configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) - - -# Source code - -set(PCRE2_HEADERS pcre2.h) -set(PCRE2_SOURCES - pcre2_auto_possess.c - pcre2_chartables.c - pcre2_chkdint.c - pcre2_compile.c - pcre2_compile_cgroup.c - pcre2_compile_class.c - pcre2_config.c - pcre2_context.c - pcre2_convert.c - pcre2_dfa_match.c - pcre2_error.c - pcre2_extuni.c - pcre2_find_bracket.c - pcre2_maketables.c - pcre2_match.c - pcre2_match_data.c - pcre2_match_next.c - pcre2_newline.c - pcre2_ord2utf.c - pcre2_pattern_info.c - pcre2_script_run.c - pcre2_serialize.c - pcre2_string_utils.c - pcre2_study.c - pcre2_substitute.c - pcre2_substring.c - pcre2_tables.c - pcre2_ucd.c - pcre2_valid_utf.c - pcre2_xclass.c -) - - -# Build setup - -add_definitions(-DHAVE_CONFIG_H) -add_definitions(-DPCRE2_CODE_UNIT_WIDTH=8) - -if(MSVC) - add_compile_definitions(_CRT_SECURE_NO_DEPRECATE _CRT_SECURE_NO_WARNINGS) -endif() - -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -add_library(pcre2 OBJECT ${PCRE2_HEADERS} ${PCRE2_SOURCES}) diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/LICENCE.md b/vendor/libgit2-sys/libgit2/deps/pcre2/LICENCE.md deleted file mode 100644 index f6fba35..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/LICENCE.md +++ /dev/null @@ -1,104 +0,0 @@ -PCRE2 Licence -============= - -| SPDX-License-Identifier: | BSD-3-Clause WITH PCRE2-exception | -|---------|-------| - -PCRE2 is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - -Releases 10.00 and above of PCRE2 are distributed under the terms of the "BSD" -licence, as specified below, with one exemption for certain binary -redistributions. The documentation for PCRE2, supplied in the "doc" directory, -is distributed under the same terms as the software itself. The data in the -testdata directory is not copyrighted and is in the public domain. - -The basic library functions are written in C and are freestanding. Also -included in the distribution is a just-in-time compiler that can be used to -optimize pattern matching. This is an optional feature that can be omitted when -the library is built. The just-in-time compiler is separately licensed under the -"2-clause BSD" licence. - - -COPYRIGHT ---------- - -### The basic library functions - - Written by: Philip Hazel - Email local part: Philip.Hazel - Email domain: gmail.com - - Retired from University of Cambridge Computing Service, - Cambridge, England. - - Copyright (c) 1997-2007 University of Cambridge - Copyright (c) 2007-2024 Philip Hazel - All rights reserved. - -### PCRE2 Just-In-Time compilation support - - Written by: Zoltan Herczeg - Email local part: hzmester - Email domain: freemail.hu - - Copyright (c) 2010-2024 Zoltan Herczeg - All rights reserved. - -### Stack-less Just-In-Time compiler - - Written by: Zoltan Herczeg - Email local part: hzmester - Email domain: freemail.hu - - Copyright (c) 2009-2024 Zoltan Herczeg - All rights reserved. - -The code in the `deps/sljit` directory has its own LICENSE file. - -### All other contributions - -Many other contributors have participated in the authorship of PCRE2. As PCRE2 -has never required a Contributor Licensing Agreement, or other copyright -assignment agreement, all contributions have copyright retained by each -original contributor or their employer. - - -THE "BSD" LICENCE ------------------ - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notices, - this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright - notices, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -* Neither the name of the University of Cambridge nor the names of any - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - -EXEMPTION FOR BINARY LIBRARY-LIKE PACKAGES ------------------------------------------- - -The second condition in the BSD licence (covering binary redistributions) does -not apply all the way down a chain of software. If binary package A includes -PCRE2, it must respect the condition, but if package B is software that -includes package A, the condition is not imposed on package B unless it uses -PCRE2 independently. diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/config.h.in b/vendor/libgit2-sys/libgit2/deps/pcre2/config.h.in deleted file mode 100644 index 9b5cb2f..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/config.h.in +++ /dev/null @@ -1,54 +0,0 @@ -/* config.h for CMake builds */ - -#cmakedefine HAVE_ASSERT_H 1 -#cmakedefine HAVE_BUILTIN_ASSUME 1 -#cmakedefine HAVE_BUILTIN_MUL_OVERFLOW 1 -#cmakedefine HAVE_BUILTIN_UNREACHABLE 1 -#cmakedefine HAVE_ATTRIBUTE_UNINITIALIZED 1 -#cmakedefine HAVE_DIRENT_H 1 -#cmakedefine HAVE_SYS_STAT_H 1 -#cmakedefine HAVE_SYS_TYPES_H 1 -#cmakedefine HAVE_UNISTD_H 1 -#cmakedefine HAVE_WINDOWS_H 1 - -#cmakedefine HAVE_MEMFD_CREATE 1 -#cmakedefine HAVE_SECURE_GETENV 1 - -#cmakedefine SUPPORT_PCRE2_8 1 -#cmakedefine SUPPORT_PCRE2_16 1 -#cmakedefine SUPPORT_PCRE2_32 1 -#cmakedefine DISABLE_PERCENT_ZT 1 - -#cmakedefine SUPPORT_LIBBZ2 1 -#cmakedefine SUPPORT_LIBEDIT 1 -#cmakedefine SUPPORT_LIBREADLINE 1 -#cmakedefine SUPPORT_LIBZ 1 - -#cmakedefine SUPPORT_JIT 1 -#cmakedefine SLJIT_PROT_EXECUTABLE_ALLOCATOR 1 -#cmakedefine SUPPORT_PCRE2GREP_JIT 1 -#cmakedefine SUPPORT_PCRE2GREP_CALLOUT 1 -#cmakedefine SUPPORT_PCRE2GREP_CALLOUT_FORK 1 -#cmakedefine SUPPORT_UNICODE 1 -#cmakedefine SUPPORT_VALGRIND 1 - -#cmakedefine BSR_ANYCRLF 1 -#cmakedefine EBCDIC 1 -#cmakedefine EBCDIC_NL25 1 -#cmakedefine EBCDIC_IGNORING_COMPILER 1 -#cmakedefine NEVER_BACKSLASH_C 1 - -#define LINK_SIZE @PCRE2_LINK_SIZE@ -#define HEAP_LIMIT @PCRE2_HEAP_LIMIT@ -#define MATCH_LIMIT @PCRE2_MATCH_LIMIT@ -#define MATCH_LIMIT_DEPTH @PCRE2_MATCH_LIMIT_DEPTH@ -#define MAX_VARLOOKBEHIND @PCRE2_MAX_VARLOOKBEHIND@ -#define NEWLINE_DEFAULT @NEWLINE_DEFAULT@ -#define PARENS_NEST_LIMIT @PCRE2_PARENS_NEST_LIMIT@ -#define PCRE2GREP_BUFSIZE @PCRE2GREP_BUFSIZE@ -#define PCRE2GREP_MAX_BUFSIZE @PCRE2GREP_MAX_BUFSIZE@ - -#define MAX_NAME_SIZE 128 -#define MAX_NAME_COUNT 10000 - -/* end config.h for CMake builds */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2.h b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2.h deleted file mode 100644 index 4034e5a..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2.h +++ /dev/null @@ -1,1079 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* This is the public header file for the PCRE library, second API, to be -#included by applications that call PCRE2 functions. - - Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - -#ifndef PCRE2_H_IDEMPOTENT_GUARD -#define PCRE2_H_IDEMPOTENT_GUARD - -/* The current PCRE version information. */ - -#define PCRE2_MAJOR 10 -#define PCRE2_MINOR 47 -#define PCRE2_PRERELEASE -#define PCRE2_DATE 2025-10-21 - -/* When an application links to a PCRE2 DLL in Windows, the symbols that are -imported have to be identified as such. When building PCRE2, the appropriate -export setting is defined in pcre2_internal.h, which includes this file. So, we -don't change existing definitions of PCRE2_EXP_DECL. - -By default, we use the standard "extern" declarations. */ - -#ifndef PCRE2_EXP_DECL -# if defined(_WIN32) && !defined(PCRE2_STATIC) -# define PCRE2_EXP_DECL extern __declspec(dllimport) -# elif defined __cplusplus -# define PCRE2_EXP_DECL extern "C" -# else -# define PCRE2_EXP_DECL extern -# endif -#endif - -/* When compiling with the MSVC compiler, it is sometimes necessary to include -a "calling convention" before exported function names. For example: - - void __cdecl function(....) - -might be needed. In order to make this easy, all the exported functions have -PCRE2_CALL_CONVENTION just before their names. - -PCRE2 normally uses the platform's standard calling convention, so this should -not be set unless you know you need it. */ - -#ifndef PCRE2_CALL_CONVENTION -#define PCRE2_CALL_CONVENTION -#endif - -/* Have to include limits.h, stdlib.h, and inttypes.h to ensure that size_t and -uint8_t, UCHAR_MAX, etc are defined. Some systems that do have inttypes.h do -not have stdint.h, which is why we use inttypes.h, which according to the C -standard is a superset of stdint.h. If inttypes.h is not available the build -will break and the relevant values must be provided by some other means. */ - -#include -#include -#include - -/* Allow for C++ users compiling this directly. */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* The following option bits can be passed to pcre2_compile(), pcre2_match(), -or pcre2_dfa_match(). PCRE2_NO_UTF_CHECK affects only the function to which it -is passed. Put these bits at the most significant end of the options word so -others can be added next to them */ - -#define PCRE2_ANCHORED 0x80000000u -#define PCRE2_NO_UTF_CHECK 0x40000000u -#define PCRE2_ENDANCHORED 0x20000000u - -/* The following option bits can be passed only to pcre2_compile(). However, -they may affect compilation, JIT compilation, and/or interpretive execution. -The following tags indicate which: - -C alters what is compiled by pcre2_compile() -J alters what is compiled by pcre2_jit_compile() -M is inspected during pcre2_match() execution -D is inspected during pcre2_dfa_match() execution -*/ - -#define PCRE2_ALLOW_EMPTY_CLASS 0x00000001u /* C */ -#define PCRE2_ALT_BSUX 0x00000002u /* C */ -#define PCRE2_AUTO_CALLOUT 0x00000004u /* C */ -#define PCRE2_CASELESS 0x00000008u /* C */ -#define PCRE2_DOLLAR_ENDONLY 0x00000010u /* J M D */ -#define PCRE2_DOTALL 0x00000020u /* C */ -#define PCRE2_DUPNAMES 0x00000040u /* C */ -#define PCRE2_EXTENDED 0x00000080u /* C */ -#define PCRE2_FIRSTLINE 0x00000100u /* J M D */ -#define PCRE2_MATCH_UNSET_BACKREF 0x00000200u /* C J M */ -#define PCRE2_MULTILINE 0x00000400u /* C */ -#define PCRE2_NEVER_UCP 0x00000800u /* C */ -#define PCRE2_NEVER_UTF 0x00001000u /* C */ -#define PCRE2_NO_AUTO_CAPTURE 0x00002000u /* C */ -#define PCRE2_NO_AUTO_POSSESS 0x00004000u /* C */ -#define PCRE2_NO_DOTSTAR_ANCHOR 0x00008000u /* C */ -#define PCRE2_NO_START_OPTIMIZE 0x00010000u /* J M D */ -#define PCRE2_UCP 0x00020000u /* C J M D */ -#define PCRE2_UNGREEDY 0x00040000u /* C */ -#define PCRE2_UTF 0x00080000u /* C J M D */ -#define PCRE2_NEVER_BACKSLASH_C 0x00100000u /* C */ -#define PCRE2_ALT_CIRCUMFLEX 0x00200000u /* J M D */ -#define PCRE2_ALT_VERBNAMES 0x00400000u /* C */ -#define PCRE2_USE_OFFSET_LIMIT 0x00800000u /* J M D */ -#define PCRE2_EXTENDED_MORE 0x01000000u /* C */ -#define PCRE2_LITERAL 0x02000000u /* C */ -#define PCRE2_MATCH_INVALID_UTF 0x04000000u /* J M D */ -#define PCRE2_ALT_EXTENDED_CLASS 0x08000000u /* C */ - -/* An additional compile options word is available in the compile context. */ - -#define PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES 0x00000001u /* C */ -#define PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL 0x00000002u /* C */ -#define PCRE2_EXTRA_MATCH_WORD 0x00000004u /* C */ -#define PCRE2_EXTRA_MATCH_LINE 0x00000008u /* C */ -#define PCRE2_EXTRA_ESCAPED_CR_IS_LF 0x00000010u /* C */ -#define PCRE2_EXTRA_ALT_BSUX 0x00000020u /* C */ -#define PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK 0x00000040u /* C */ -#define PCRE2_EXTRA_CASELESS_RESTRICT 0x00000080u /* C */ -#define PCRE2_EXTRA_ASCII_BSD 0x00000100u /* C */ -#define PCRE2_EXTRA_ASCII_BSS 0x00000200u /* C */ -#define PCRE2_EXTRA_ASCII_BSW 0x00000400u /* C */ -#define PCRE2_EXTRA_ASCII_POSIX 0x00000800u /* C */ -#define PCRE2_EXTRA_ASCII_DIGIT 0x00001000u /* C */ -#define PCRE2_EXTRA_PYTHON_OCTAL 0x00002000u /* C */ -#define PCRE2_EXTRA_NO_BS0 0x00004000u /* C */ -#define PCRE2_EXTRA_NEVER_CALLOUT 0x00008000u /* C */ -#define PCRE2_EXTRA_TURKISH_CASING 0x00010000u /* C */ - -/* These are for pcre2_jit_compile(). */ - -#define PCRE2_JIT_COMPLETE 0x00000001u /* For full matching */ -#define PCRE2_JIT_PARTIAL_SOFT 0x00000002u -#define PCRE2_JIT_PARTIAL_HARD 0x00000004u -#define PCRE2_JIT_INVALID_UTF 0x00000100u -#define PCRE2_JIT_TEST_ALLOC 0x00000200u - -/* These are for pcre2_match(), pcre2_dfa_match(), pcre2_jit_match(), and -pcre2_substitute(). Some are allowed only for one of the functions, and in -these cases it is noted below. Note that PCRE2_ANCHORED, PCRE2_ENDANCHORED and -PCRE2_NO_UTF_CHECK can also be passed to these functions (though -pcre2_jit_match() ignores the latter since it bypasses all sanity checks). */ - -#define PCRE2_NOTBOL 0x00000001u -#define PCRE2_NOTEOL 0x00000002u -#define PCRE2_NOTEMPTY 0x00000004u /* ) These two must be kept */ -#define PCRE2_NOTEMPTY_ATSTART 0x00000008u /* ) adjacent to each other. */ -#define PCRE2_PARTIAL_SOFT 0x00000010u -#define PCRE2_PARTIAL_HARD 0x00000020u -#define PCRE2_DFA_RESTART 0x00000040u /* pcre2_dfa_match() only */ -#define PCRE2_DFA_SHORTEST 0x00000080u /* pcre2_dfa_match() only */ -#define PCRE2_SUBSTITUTE_GLOBAL 0x00000100u /* pcre2_substitute() only */ -#define PCRE2_SUBSTITUTE_EXTENDED 0x00000200u /* pcre2_substitute() only */ -#define PCRE2_SUBSTITUTE_UNSET_EMPTY 0x00000400u /* pcre2_substitute() only */ -#define PCRE2_SUBSTITUTE_UNKNOWN_UNSET 0x00000800u /* pcre2_substitute() only */ -#define PCRE2_SUBSTITUTE_OVERFLOW_LENGTH 0x00001000u /* pcre2_substitute() only */ -#define PCRE2_NO_JIT 0x00002000u /* not for pcre2_dfa_match() */ -#define PCRE2_COPY_MATCHED_SUBJECT 0x00004000u -#define PCRE2_SUBSTITUTE_LITERAL 0x00008000u /* pcre2_substitute() only */ -#define PCRE2_SUBSTITUTE_MATCHED 0x00010000u /* pcre2_substitute() only */ -#define PCRE2_SUBSTITUTE_REPLACEMENT_ONLY 0x00020000u /* pcre2_substitute() only */ -#define PCRE2_DISABLE_RECURSELOOP_CHECK 0x00040000u /* not for pcre2_dfa_match() or pcre2_jit_match() */ - -/* Options for pcre2_pattern_convert(). */ - -#define PCRE2_CONVERT_UTF 0x00000001u -#define PCRE2_CONVERT_NO_UTF_CHECK 0x00000002u -#define PCRE2_CONVERT_POSIX_BASIC 0x00000004u -#define PCRE2_CONVERT_POSIX_EXTENDED 0x00000008u -#define PCRE2_CONVERT_GLOB 0x00000010u -#define PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR 0x00000030u -#define PCRE2_CONVERT_GLOB_NO_STARSTAR 0x00000050u - -/* Newline and \R settings, for use in compile contexts. The newline values -must be kept in step with values set in config.h and both sets must all be -greater than zero. */ - -#define PCRE2_NEWLINE_CR 1 -#define PCRE2_NEWLINE_LF 2 -#define PCRE2_NEWLINE_CRLF 3 -#define PCRE2_NEWLINE_ANY 4 -#define PCRE2_NEWLINE_ANYCRLF 5 -#define PCRE2_NEWLINE_NUL 6 - -#define PCRE2_BSR_UNICODE 1 -#define PCRE2_BSR_ANYCRLF 2 - -/* Error codes for pcre2_compile(). Some of these are also used by -pcre2_pattern_convert(). */ - -#define PCRE2_ERROR_END_BACKSLASH 101 -#define PCRE2_ERROR_END_BACKSLASH_C 102 -#define PCRE2_ERROR_UNKNOWN_ESCAPE 103 -#define PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER 104 -#define PCRE2_ERROR_QUANTIFIER_TOO_BIG 105 -#define PCRE2_ERROR_MISSING_SQUARE_BRACKET 106 -#define PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS 107 -#define PCRE2_ERROR_CLASS_RANGE_ORDER 108 -#define PCRE2_ERROR_QUANTIFIER_INVALID 109 -#define PCRE2_ERROR_INTERNAL_UNEXPECTED_REPEAT 110 -#define PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY 111 -#define PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS 112 -#define PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING 113 -#define PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS 114 -#define PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE 115 -#define PCRE2_ERROR_NULL_PATTERN 116 -#define PCRE2_ERROR_BAD_OPTIONS 117 -#define PCRE2_ERROR_MISSING_COMMENT_CLOSING 118 -#define PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP 119 -#define PCRE2_ERROR_PATTERN_TOO_LARGE 120 -#define PCRE2_ERROR_HEAP_FAILED 121 -#define PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS 122 -#define PCRE2_ERROR_INTERNAL_CODE_OVERFLOW 123 -#define PCRE2_ERROR_MISSING_CONDITION_CLOSING 124 -#define PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH 125 -#define PCRE2_ERROR_ZERO_RELATIVE_REFERENCE 126 -#define PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES 127 -#define PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED 128 -#define PCRE2_ERROR_BAD_RELATIVE_REFERENCE 129 -#define PCRE2_ERROR_UNKNOWN_POSIX_CLASS 130 -#define PCRE2_ERROR_INTERNAL_STUDY_ERROR 131 -#define PCRE2_ERROR_UNICODE_NOT_SUPPORTED 132 -#define PCRE2_ERROR_PARENTHESES_STACK_CHECK 133 -#define PCRE2_ERROR_CODE_POINT_TOO_BIG 134 -#define PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED 135 -#define PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C 136 -#define PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE 137 -#define PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG 138 -#define PCRE2_ERROR_MISSING_CALLOUT_CLOSING 139 -#define PCRE2_ERROR_ESCAPE_INVALID_IN_VERB 140 -#define PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P 141 -#define PCRE2_ERROR_MISSING_NAME_TERMINATOR 142 -#define PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME 143 -#define PCRE2_ERROR_INVALID_SUBPATTERN_NAME 144 -#define PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE 145 -#define PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY 146 -#define PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY 147 -#define PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG 148 -#define PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS 149 -#define PCRE2_ERROR_CLASS_INVALID_RANGE 150 -#define PCRE2_ERROR_OCTAL_BYTE_TOO_BIG 151 -#define PCRE2_ERROR_INTERNAL_OVERRAN_WORKSPACE 152 -#define PCRE2_ERROR_INTERNAL_MISSING_SUBPATTERN 153 -#define PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES 154 -#define PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE 155 -#define PCRE2_ERROR_INTERNAL_UNKNOWN_NEWLINE 156 -#define PCRE2_ERROR_BACKSLASH_G_SYNTAX 157 -#define PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING 158 -/* Error 159 is obsolete and should now never occur */ -#define PCRE2_ERROR_VERB_ARGUMENT_NOT_ALLOWED 159 -#define PCRE2_ERROR_VERB_UNKNOWN 160 -#define PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG 161 -#define PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED 162 -#define PCRE2_ERROR_INTERNAL_PARSED_OVERFLOW 163 -#define PCRE2_ERROR_INVALID_OCTAL 164 -#define PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH 165 -#define PCRE2_ERROR_MARK_MISSING_ARGUMENT 166 -#define PCRE2_ERROR_INVALID_HEXADECIMAL 167 -#define PCRE2_ERROR_BACKSLASH_C_SYNTAX 168 -#define PCRE2_ERROR_BACKSLASH_K_SYNTAX 169 -#define PCRE2_ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS 170 -#define PCRE2_ERROR_BACKSLASH_N_IN_CLASS 171 -#define PCRE2_ERROR_CALLOUT_STRING_TOO_LONG 172 -#define PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT 173 -#define PCRE2_ERROR_UTF_IS_DISABLED 174 -#define PCRE2_ERROR_UCP_IS_DISABLED 175 -#define PCRE2_ERROR_VERB_NAME_TOO_LONG 176 -#define PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG 177 -#define PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS 178 -#define PCRE2_ERROR_VERSION_CONDITION_SYNTAX 179 -#define PCRE2_ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS 180 -#define PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER 181 -#define PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER 182 -#define PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED 183 -#define PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP 184 -#define PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED 185 -#define PCRE2_ERROR_PATTERN_TOO_COMPLICATED 186 -#define PCRE2_ERROR_LOOKBEHIND_TOO_LONG 187 -#define PCRE2_ERROR_PATTERN_STRING_TOO_LONG 188 -#define PCRE2_ERROR_INTERNAL_BAD_CODE 189 -#define PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP 190 -#define PCRE2_ERROR_NO_SURROGATES_IN_UTF16 191 -#define PCRE2_ERROR_BAD_LITERAL_OPTIONS 192 -#define PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE 193 -#define PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS 194 -#define PCRE2_ERROR_ALPHA_ASSERTION_UNKNOWN 195 -#define PCRE2_ERROR_SCRIPT_RUN_NOT_AVAILABLE 196 -#define PCRE2_ERROR_TOO_MANY_CAPTURES 197 -#define PCRE2_ERROR_MISSING_OCTAL_DIGIT 198 -#define PCRE2_ERROR_BACKSLASH_K_IN_LOOKAROUND 199 -#define PCRE2_ERROR_MAX_VAR_LOOKBEHIND_EXCEEDED 200 -#define PCRE2_ERROR_PATTERN_COMPILED_SIZE_TOO_BIG 201 -#define PCRE2_ERROR_OVERSIZE_PYTHON_OCTAL 202 -#define PCRE2_ERROR_CALLOUT_CALLER_DISABLED 203 -#define PCRE2_ERROR_EXTRA_CASING_REQUIRES_UNICODE 204 -#define PCRE2_ERROR_TURKISH_CASING_REQUIRES_UTF 205 -#define PCRE2_ERROR_EXTRA_CASING_INCOMPATIBLE 206 -#define PCRE2_ERROR_ECLASS_NEST_TOO_DEEP 207 -#define PCRE2_ERROR_ECLASS_INVALID_OPERATOR 208 -#define PCRE2_ERROR_ECLASS_UNEXPECTED_OPERATOR 209 -#define PCRE2_ERROR_ECLASS_EXPECTED_OPERAND 210 -#define PCRE2_ERROR_ECLASS_MIXED_OPERATORS 211 -#define PCRE2_ERROR_ECLASS_HINT_SQUARE_BRACKET 212 -#define PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_EXPR 213 -#define PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR 214 -#define PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE 215 -#define PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR 216 -#define PCRE2_ERROR_EXPECTED_CAPTURE_GROUP 217 -#define PCRE2_ERROR_MISSING_OPENING_PARENTHESIS 218 -#define PCRE2_ERROR_MISSING_NUMBER_TERMINATOR 219 -#define PCRE2_ERROR_NULL_ERROROFFSET 220 - -/* "Expected" matching error codes: no match and partial match. */ - -#define PCRE2_ERROR_NOMATCH (-1) -#define PCRE2_ERROR_PARTIAL (-2) - -/* Error codes for UTF-8 validity checks */ - -#define PCRE2_ERROR_UTF8_ERR1 (-3) -#define PCRE2_ERROR_UTF8_ERR2 (-4) -#define PCRE2_ERROR_UTF8_ERR3 (-5) -#define PCRE2_ERROR_UTF8_ERR4 (-6) -#define PCRE2_ERROR_UTF8_ERR5 (-7) -#define PCRE2_ERROR_UTF8_ERR6 (-8) -#define PCRE2_ERROR_UTF8_ERR7 (-9) -#define PCRE2_ERROR_UTF8_ERR8 (-10) -#define PCRE2_ERROR_UTF8_ERR9 (-11) -#define PCRE2_ERROR_UTF8_ERR10 (-12) -#define PCRE2_ERROR_UTF8_ERR11 (-13) -#define PCRE2_ERROR_UTF8_ERR12 (-14) -#define PCRE2_ERROR_UTF8_ERR13 (-15) -#define PCRE2_ERROR_UTF8_ERR14 (-16) -#define PCRE2_ERROR_UTF8_ERR15 (-17) -#define PCRE2_ERROR_UTF8_ERR16 (-18) -#define PCRE2_ERROR_UTF8_ERR17 (-19) -#define PCRE2_ERROR_UTF8_ERR18 (-20) -#define PCRE2_ERROR_UTF8_ERR19 (-21) -#define PCRE2_ERROR_UTF8_ERR20 (-22) -#define PCRE2_ERROR_UTF8_ERR21 (-23) - -/* Error codes for UTF-16 validity checks */ - -#define PCRE2_ERROR_UTF16_ERR1 (-24) -#define PCRE2_ERROR_UTF16_ERR2 (-25) -#define PCRE2_ERROR_UTF16_ERR3 (-26) - -/* Error codes for UTF-32 validity checks */ - -#define PCRE2_ERROR_UTF32_ERR1 (-27) -#define PCRE2_ERROR_UTF32_ERR2 (-28) - -/* Miscellaneous error codes for pcre2[_dfa]_match(), substring extraction -functions, context functions, and serializing functions. They are in numerical -order. Originally they were in alphabetical order too, but now that PCRE2 is -released, the numbers must not be changed. */ - -#define PCRE2_ERROR_BADDATA (-29) -#define PCRE2_ERROR_MIXEDTABLES (-30) /* Name was changed */ -#define PCRE2_ERROR_BADMAGIC (-31) -#define PCRE2_ERROR_BADMODE (-32) -#define PCRE2_ERROR_BADOFFSET (-33) -#define PCRE2_ERROR_BADOPTION (-34) -#define PCRE2_ERROR_BADREPLACEMENT (-35) -#define PCRE2_ERROR_BADUTFOFFSET (-36) -#define PCRE2_ERROR_CALLOUT (-37) /* Never used by PCRE2 itself */ -#define PCRE2_ERROR_DFA_BADRESTART (-38) -#define PCRE2_ERROR_DFA_RECURSE (-39) -#define PCRE2_ERROR_DFA_UCOND (-40) -#define PCRE2_ERROR_DFA_UFUNC (-41) -#define PCRE2_ERROR_DFA_UITEM (-42) -#define PCRE2_ERROR_DFA_WSSIZE (-43) -#define PCRE2_ERROR_INTERNAL (-44) -#define PCRE2_ERROR_JIT_BADOPTION (-45) -#define PCRE2_ERROR_JIT_STACKLIMIT (-46) -#define PCRE2_ERROR_MATCHLIMIT (-47) -#define PCRE2_ERROR_NOMEMORY (-48) -#define PCRE2_ERROR_NOSUBSTRING (-49) -#define PCRE2_ERROR_NOUNIQUESUBSTRING (-50) -#define PCRE2_ERROR_NULL (-51) -#define PCRE2_ERROR_RECURSELOOP (-52) -#define PCRE2_ERROR_DEPTHLIMIT (-53) -#define PCRE2_ERROR_RECURSIONLIMIT (-53) /* Obsolete synonym */ -#define PCRE2_ERROR_UNAVAILABLE (-54) -#define PCRE2_ERROR_UNSET (-55) -#define PCRE2_ERROR_BADOFFSETLIMIT (-56) -#define PCRE2_ERROR_BADREPESCAPE (-57) -#define PCRE2_ERROR_REPMISSINGBRACE (-58) -#define PCRE2_ERROR_BADSUBSTITUTION (-59) -#define PCRE2_ERROR_BADSUBSPATTERN (-60) -#define PCRE2_ERROR_TOOMANYREPLACE (-61) -#define PCRE2_ERROR_BADSERIALIZEDDATA (-62) -#define PCRE2_ERROR_HEAPLIMIT (-63) -#define PCRE2_ERROR_CONVERT_SYNTAX (-64) -#define PCRE2_ERROR_INTERNAL_DUPMATCH (-65) -#define PCRE2_ERROR_DFA_UINVALID_UTF (-66) -#define PCRE2_ERROR_INVALIDOFFSET (-67) -#define PCRE2_ERROR_JIT_UNSUPPORTED (-68) -#define PCRE2_ERROR_REPLACECASE (-69) -#define PCRE2_ERROR_TOOLARGEREPLACE (-70) -#define PCRE2_ERROR_DIFFSUBSPATTERN (-71) -#define PCRE2_ERROR_DIFFSUBSSUBJECT (-72) -#define PCRE2_ERROR_DIFFSUBSOFFSET (-73) -#define PCRE2_ERROR_DIFFSUBSOPTIONS (-74) -#define PCRE2_ERROR_BAD_BACKSLASH_K (-75) - - -/* Request types for pcre2_pattern_info() */ - -#define PCRE2_INFO_ALLOPTIONS 0 -#define PCRE2_INFO_ARGOPTIONS 1 -#define PCRE2_INFO_BACKREFMAX 2 -#define PCRE2_INFO_BSR 3 -#define PCRE2_INFO_CAPTURECOUNT 4 -#define PCRE2_INFO_FIRSTCODEUNIT 5 -#define PCRE2_INFO_FIRSTCODETYPE 6 -#define PCRE2_INFO_FIRSTBITMAP 7 -#define PCRE2_INFO_HASCRORLF 8 -#define PCRE2_INFO_JCHANGED 9 -#define PCRE2_INFO_JITSIZE 10 -#define PCRE2_INFO_LASTCODEUNIT 11 -#define PCRE2_INFO_LASTCODETYPE 12 -#define PCRE2_INFO_MATCHEMPTY 13 -#define PCRE2_INFO_MATCHLIMIT 14 -#define PCRE2_INFO_MAXLOOKBEHIND 15 -#define PCRE2_INFO_MINLENGTH 16 -#define PCRE2_INFO_NAMECOUNT 17 -#define PCRE2_INFO_NAMEENTRYSIZE 18 -#define PCRE2_INFO_NAMETABLE 19 -#define PCRE2_INFO_NEWLINE 20 -#define PCRE2_INFO_DEPTHLIMIT 21 -#define PCRE2_INFO_RECURSIONLIMIT 21 /* Obsolete synonym */ -#define PCRE2_INFO_SIZE 22 -#define PCRE2_INFO_HASBACKSLASHC 23 -#define PCRE2_INFO_FRAMESIZE 24 -#define PCRE2_INFO_HEAPLIMIT 25 -#define PCRE2_INFO_EXTRAOPTIONS 26 - -/* Request types for pcre2_config(). */ - -#define PCRE2_CONFIG_BSR 0 -#define PCRE2_CONFIG_JIT 1 -#define PCRE2_CONFIG_JITTARGET 2 -#define PCRE2_CONFIG_LINKSIZE 3 -#define PCRE2_CONFIG_MATCHLIMIT 4 -#define PCRE2_CONFIG_NEWLINE 5 -#define PCRE2_CONFIG_PARENSLIMIT 6 -#define PCRE2_CONFIG_DEPTHLIMIT 7 -#define PCRE2_CONFIG_RECURSIONLIMIT 7 /* Obsolete synonym */ -#define PCRE2_CONFIG_STACKRECURSE 8 /* Obsolete */ -#define PCRE2_CONFIG_UNICODE 9 -#define PCRE2_CONFIG_UNICODE_VERSION 10 -#define PCRE2_CONFIG_VERSION 11 -#define PCRE2_CONFIG_HEAPLIMIT 12 -#define PCRE2_CONFIG_NEVER_BACKSLASH_C 13 -#define PCRE2_CONFIG_COMPILED_WIDTHS 14 -#define PCRE2_CONFIG_TABLES_LENGTH 15 -#define PCRE2_CONFIG_EFFECTIVE_LINKSIZE 16 - -/* Optimization directives for pcre2_set_optimize(). -For binary compatibility, only add to this list; do not renumber. */ - -#define PCRE2_OPTIMIZATION_NONE 0 -#define PCRE2_OPTIMIZATION_FULL 1 - -#define PCRE2_AUTO_POSSESS 64 -#define PCRE2_AUTO_POSSESS_OFF 65 -#define PCRE2_DOTSTAR_ANCHOR 66 -#define PCRE2_DOTSTAR_ANCHOR_OFF 67 -#define PCRE2_START_OPTIMIZE 68 -#define PCRE2_START_OPTIMIZE_OFF 69 - -/* Types used in pcre2_set_substitute_case_callout(). - -PCRE2_SUBSTITUTE_CASE_LOWER and PCRE2_SUBSTITUTE_CASE_UPPER are passed to the -callout to indicate that the case of the entire callout input should be -case-transformed. PCRE2_SUBSTITUTE_CASE_TITLE_FIRST is passed to indicate that -only the first character or glyph should be transformed to Unicode titlecase, -and the rest to lowercase. */ - -#define PCRE2_SUBSTITUTE_CASE_LOWER 1 -#define PCRE2_SUBSTITUTE_CASE_UPPER 2 -#define PCRE2_SUBSTITUTE_CASE_TITLE_FIRST 3 - -/* Types for code units in patterns and subject strings. */ - -typedef uint8_t PCRE2_UCHAR8; -typedef uint16_t PCRE2_UCHAR16; -typedef uint32_t PCRE2_UCHAR32; - -typedef const PCRE2_UCHAR8 *PCRE2_SPTR8; -typedef const PCRE2_UCHAR16 *PCRE2_SPTR16; -typedef const PCRE2_UCHAR32 *PCRE2_SPTR32; - -/* The PCRE2_SIZE type is used for all string lengths and offsets in PCRE2, -including pattern offsets for errors and subject offsets after a match. We -define special values to indicate zero-terminated strings and unset offsets in -the offset vector (ovector). */ - -#define PCRE2_SIZE size_t -#define PCRE2_SIZE_MAX SIZE_MAX -#define PCRE2_ZERO_TERMINATED (~(PCRE2_SIZE)0) -#define PCRE2_UNSET (~(PCRE2_SIZE)0) - -/* Generic types for opaque structures and JIT callback functions. These -declarations are defined in a macro that is expanded for each width later. */ - -#define PCRE2_TYPES_LIST \ -struct pcre2_real_general_context; \ -typedef struct pcre2_real_general_context pcre2_general_context; \ -\ -struct pcre2_real_compile_context; \ -typedef struct pcre2_real_compile_context pcre2_compile_context; \ -\ -struct pcre2_real_match_context; \ -typedef struct pcre2_real_match_context pcre2_match_context; \ -\ -struct pcre2_real_convert_context; \ -typedef struct pcre2_real_convert_context pcre2_convert_context; \ -\ -struct pcre2_real_code; \ -typedef struct pcre2_real_code pcre2_code; \ -\ -struct pcre2_real_match_data; \ -typedef struct pcre2_real_match_data pcre2_match_data; \ -\ -struct pcre2_real_jit_stack; \ -typedef struct pcre2_real_jit_stack pcre2_jit_stack; \ -\ -typedef pcre2_jit_stack *(*pcre2_jit_callback)(void *); - - -/* The structures for passing out data via callout functions. We use structures -so that new fields can be added on the end in future versions, without changing -the API of the function, thereby allowing old clients to work without -modification. Define the generic versions in a macro; the width-specific -versions are generated from this macro below. */ - -/* Flags for the callout_flags field. These are cleared after a callout. */ - -#define PCRE2_CALLOUT_STARTMATCH 0x00000001u /* Set for each bumpalong */ -#define PCRE2_CALLOUT_BACKTRACK 0x00000002u /* Set after a backtrack */ - -#define PCRE2_STRUCTURE_LIST \ -typedef struct pcre2_callout_block { \ - uint32_t version; /* Identifies version of block */ \ - /* ------------------------ Version 0 ------------------------------- */ \ - uint32_t callout_number; /* Number compiled into pattern */ \ - uint32_t capture_top; /* Max current capture */ \ - uint32_t capture_last; /* Most recently closed capture */ \ - PCRE2_SIZE *offset_vector; /* The offset vector */ \ - PCRE2_SPTR mark; /* Pointer to current mark or NULL */ \ - PCRE2_SPTR subject; /* The subject being matched */ \ - PCRE2_SIZE subject_length; /* The length of the subject */ \ - PCRE2_SIZE start_match; /* Offset to start of this match attempt */ \ - PCRE2_SIZE current_position; /* Where we currently are in the subject */ \ - PCRE2_SIZE pattern_position; /* Offset to next item in the pattern */ \ - PCRE2_SIZE next_item_length; /* Length of next item in the pattern */ \ - /* ------------------- Added for Version 1 -------------------------- */ \ - PCRE2_SIZE callout_string_offset; /* Offset to string within pattern */ \ - PCRE2_SIZE callout_string_length; /* Length of string compiled into pattern */ \ - PCRE2_SPTR callout_string; /* String compiled into pattern */ \ - /* ------------------- Added for Version 2 -------------------------- */ \ - uint32_t callout_flags; /* See above for list */ \ - /* ------------------------------------------------------------------ */ \ -} pcre2_callout_block; \ -\ -typedef struct pcre2_callout_enumerate_block { \ - uint32_t version; /* Identifies version of block */ \ - /* ------------------------ Version 0 ------------------------------- */ \ - PCRE2_SIZE pattern_position; /* Offset to next item in the pattern */ \ - PCRE2_SIZE next_item_length; /* Length of next item in the pattern */ \ - uint32_t callout_number; /* Number compiled into pattern */ \ - PCRE2_SIZE callout_string_offset; /* Offset to string within pattern */ \ - PCRE2_SIZE callout_string_length; /* Length of string compiled into pattern */ \ - PCRE2_SPTR callout_string; /* String compiled into pattern */ \ - /* ------------------------------------------------------------------ */ \ -} pcre2_callout_enumerate_block; \ -\ -typedef struct pcre2_substitute_callout_block { \ - uint32_t version; /* Identifies version of block */ \ - /* ------------------------ Version 0 ------------------------------- */ \ - PCRE2_SPTR input; /* Pointer to input subject string */ \ - PCRE2_SPTR output; /* Pointer to output buffer */ \ - PCRE2_SIZE output_offsets[2]; /* Changed portion of the output */ \ - PCRE2_SIZE *ovector; /* Pointer to current ovector */ \ - uint32_t oveccount; /* Count of pairs set in ovector */ \ - uint32_t subscount; /* Substitution number */ \ - /* ------------------------------------------------------------------ */ \ -} pcre2_substitute_callout_block; - - -/* List the generic forms of all other functions in macros, which will be -expanded for each width below. Start with functions that give general -information. */ - -#define PCRE2_GENERAL_INFO_FUNCTIONS \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION pcre2_config(uint32_t, void *); - - -/* Functions for manipulating contexts. */ - -#define PCRE2_GENERAL_CONTEXT_FUNCTIONS \ -PCRE2_EXP_DECL pcre2_general_context *PCRE2_CALL_CONVENTION \ - pcre2_general_context_copy(pcre2_general_context *); \ -PCRE2_EXP_DECL pcre2_general_context *PCRE2_CALL_CONVENTION \ - pcre2_general_context_create(void *(*)(size_t, void *), \ - void (*)(void *, void *), void *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_general_context_free(pcre2_general_context *); - -#define PCRE2_COMPILE_CONTEXT_FUNCTIONS \ -PCRE2_EXP_DECL pcre2_compile_context *PCRE2_CALL_CONVENTION \ - pcre2_compile_context_copy(pcre2_compile_context *); \ -PCRE2_EXP_DECL pcre2_compile_context *PCRE2_CALL_CONVENTION \ - pcre2_compile_context_create(pcre2_general_context *);\ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_compile_context_free(pcre2_compile_context *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_bsr(pcre2_compile_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_character_tables(pcre2_compile_context *, const uint8_t *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_compile_extra_options(pcre2_compile_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_max_pattern_length(pcre2_compile_context *, PCRE2_SIZE); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_max_pattern_compiled_length(pcre2_compile_context *, PCRE2_SIZE); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_max_varlookbehind(pcre2_compile_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_newline(pcre2_compile_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_parens_nest_limit(pcre2_compile_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_compile_recursion_guard(pcre2_compile_context *, \ - int (*)(uint32_t, void *), void *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_optimize(pcre2_compile_context *, uint32_t); - -#define PCRE2_MATCH_CONTEXT_FUNCTIONS \ -PCRE2_EXP_DECL pcre2_match_context *PCRE2_CALL_CONVENTION \ - pcre2_match_context_copy(pcre2_match_context *); \ -PCRE2_EXP_DECL pcre2_match_context *PCRE2_CALL_CONVENTION \ - pcre2_match_context_create(pcre2_general_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_match_context_free(pcre2_match_context *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_callout(pcre2_match_context *, \ - int (*)(pcre2_callout_block *, void *), void *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_substitute_callout(pcre2_match_context *, \ - int (*)(pcre2_substitute_callout_block *, void *), void *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_substitute_case_callout(pcre2_match_context *, \ - PCRE2_SIZE (*)(PCRE2_SPTR, PCRE2_SIZE, PCRE2_UCHAR *, PCRE2_SIZE, int, \ - void *), \ - void *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_depth_limit(pcre2_match_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_heap_limit(pcre2_match_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_match_limit(pcre2_match_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_offset_limit(pcre2_match_context *, PCRE2_SIZE); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_recursion_limit(pcre2_match_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_recursion_memory_management(pcre2_match_context *, \ - void *(*)(size_t, void *), void (*)(void *, void *), void *); - -#define PCRE2_CONVERT_CONTEXT_FUNCTIONS \ -PCRE2_EXP_DECL pcre2_convert_context *PCRE2_CALL_CONVENTION \ - pcre2_convert_context_copy(pcre2_convert_context *); \ -PCRE2_EXP_DECL pcre2_convert_context *PCRE2_CALL_CONVENTION \ - pcre2_convert_context_create(pcre2_general_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_convert_context_free(pcre2_convert_context *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_glob_escape(pcre2_convert_context *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_set_glob_separator(pcre2_convert_context *, uint32_t); - - -/* Functions concerned with compiling a pattern to PCRE internal code. */ - -#define PCRE2_COMPILE_FUNCTIONS \ -PCRE2_EXP_DECL pcre2_code *PCRE2_CALL_CONVENTION \ - pcre2_compile(PCRE2_SPTR, PCRE2_SIZE, uint32_t, int *, PCRE2_SIZE *, \ - pcre2_compile_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_code_free(pcre2_code *); \ -PCRE2_EXP_DECL pcre2_code *PCRE2_CALL_CONVENTION \ - pcre2_code_copy(const pcre2_code *); \ -PCRE2_EXP_DECL pcre2_code *PCRE2_CALL_CONVENTION \ - pcre2_code_copy_with_tables(const pcre2_code *); - - -/* Functions that give information about a compiled pattern. */ - -#define PCRE2_PATTERN_INFO_FUNCTIONS \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_pattern_info(const pcre2_code *, uint32_t, void *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_callout_enumerate(const pcre2_code *, \ - int (*)(pcre2_callout_enumerate_block *, void *), void *); - - -/* Functions for running a match and inspecting the result. */ - -#define PCRE2_MATCH_FUNCTIONS \ -PCRE2_EXP_DECL pcre2_match_data *PCRE2_CALL_CONVENTION \ - pcre2_match_data_create(uint32_t, pcre2_general_context *); \ -PCRE2_EXP_DECL pcre2_match_data *PCRE2_CALL_CONVENTION \ - pcre2_match_data_create_from_pattern(const pcre2_code *, \ - pcre2_general_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_match_data_free(pcre2_match_data *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_dfa_match(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, \ - uint32_t, pcre2_match_data *, pcre2_match_context *, int *, PCRE2_SIZE); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_match(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, \ - uint32_t, pcre2_match_data *, pcre2_match_context *); \ -PCRE2_EXP_DECL PCRE2_SPTR PCRE2_CALL_CONVENTION \ - pcre2_get_mark(pcre2_match_data *); \ -PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ - pcre2_get_match_data_size(pcre2_match_data *); \ -PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ - pcre2_get_match_data_heapframes_size(pcre2_match_data *); \ -PCRE2_EXP_DECL uint32_t PCRE2_CALL_CONVENTION \ - pcre2_get_ovector_count(pcre2_match_data *); \ -PCRE2_EXP_DECL PCRE2_SIZE *PCRE2_CALL_CONVENTION \ - pcre2_get_ovector_pointer(pcre2_match_data *); \ -PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ - pcre2_get_startchar(pcre2_match_data *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_next_match(pcre2_match_data *, PCRE2_SIZE *, uint32_t *); - - -/* Convenience functions for handling matched substrings. */ - -#define PCRE2_SUBSTRING_FUNCTIONS \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_copy_byname(pcre2_match_data *, PCRE2_SPTR, PCRE2_UCHAR *, \ - PCRE2_SIZE *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_copy_bynumber(pcre2_match_data *, uint32_t, PCRE2_UCHAR *, \ - PCRE2_SIZE *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_substring_free(PCRE2_UCHAR *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_get_byname(pcre2_match_data *, PCRE2_SPTR, PCRE2_UCHAR **, \ - PCRE2_SIZE *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_get_bynumber(pcre2_match_data *, uint32_t, PCRE2_UCHAR **, \ - PCRE2_SIZE *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_length_byname(pcre2_match_data *, PCRE2_SPTR, PCRE2_SIZE *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_length_bynumber(pcre2_match_data *, uint32_t, PCRE2_SIZE *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_nametable_scan(const pcre2_code *, PCRE2_SPTR, PCRE2_SPTR *, \ - PCRE2_SPTR *); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_number_from_name(const pcre2_code *, PCRE2_SPTR); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_substring_list_free(PCRE2_UCHAR **); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substring_list_get(pcre2_match_data *, PCRE2_UCHAR ***, PCRE2_SIZE **); - - -/* Functions for serializing / deserializing compiled patterns. */ - -#define PCRE2_SERIALIZE_FUNCTIONS \ -PCRE2_EXP_DECL int32_t PCRE2_CALL_CONVENTION \ - pcre2_serialize_encode(const pcre2_code **, int32_t, uint8_t **, \ - PCRE2_SIZE *, pcre2_general_context *); \ -PCRE2_EXP_DECL int32_t PCRE2_CALL_CONVENTION \ - pcre2_serialize_decode(pcre2_code **, int32_t, const uint8_t *, \ - pcre2_general_context *); \ -PCRE2_EXP_DECL int32_t PCRE2_CALL_CONVENTION \ - pcre2_serialize_get_number_of_codes(const uint8_t *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_serialize_free(uint8_t *); - - -/* Convenience function for match + substitute. */ - -#define PCRE2_SUBSTITUTE_FUNCTION \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_substitute(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, \ - uint32_t, pcre2_match_data *, pcre2_match_context *, PCRE2_SPTR, \ - PCRE2_SIZE, PCRE2_UCHAR *, PCRE2_SIZE *); - - -/* Functions for converting pattern source strings. */ - -#define PCRE2_CONVERT_FUNCTIONS \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_pattern_convert(PCRE2_SPTR, PCRE2_SIZE, uint32_t, PCRE2_UCHAR **, \ - PCRE2_SIZE *, pcre2_convert_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_converted_pattern_free(PCRE2_UCHAR *); - - -/* Functions for JIT processing */ - -#define PCRE2_JIT_FUNCTIONS \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_jit_compile(pcre2_code *, uint32_t); \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_jit_match(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, \ - uint32_t, pcre2_match_data *, pcre2_match_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_jit_free_unused_memory(pcre2_general_context *); \ -PCRE2_EXP_DECL pcre2_jit_stack *PCRE2_CALL_CONVENTION \ - pcre2_jit_stack_create(size_t, size_t, pcre2_general_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_jit_stack_assign(pcre2_match_context *, pcre2_jit_callback, void *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_jit_stack_free(pcre2_jit_stack *); - - -/* Other miscellaneous functions. */ - -#define PCRE2_OTHER_FUNCTIONS \ -PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ - pcre2_get_error_message(int, PCRE2_UCHAR *, PCRE2_SIZE); \ -PCRE2_EXP_DECL const uint8_t *PCRE2_CALL_CONVENTION \ - pcre2_maketables(pcre2_general_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_maketables_free(pcre2_general_context *, const uint8_t *); - -/* Define macros that generate width-specific names from generic versions. The -three-level macro scheme is necessary to get the macros expanded when we want -them to be. First we get the width from PCRE2_LOCAL_WIDTH, which is used for -generating three versions of everything below. After that, PCRE2_SUFFIX will be -re-defined to use PCRE2_CODE_UNIT_WIDTH, for use when macros such as -pcre2_compile are called by application code. */ - -#define PCRE2_JOIN(a,b) a ## b -#define PCRE2_GLUE(a,b) PCRE2_JOIN(a,b) -#define PCRE2_SUFFIX(a) PCRE2_GLUE(a,PCRE2_LOCAL_WIDTH) - - -/* Data types */ - -#define PCRE2_UCHAR PCRE2_SUFFIX(PCRE2_UCHAR) -#define PCRE2_SPTR PCRE2_SUFFIX(PCRE2_SPTR) - -#define pcre2_code PCRE2_SUFFIX(pcre2_code_) -#define pcre2_jit_callback PCRE2_SUFFIX(pcre2_jit_callback_) -#define pcre2_jit_stack PCRE2_SUFFIX(pcre2_jit_stack_) - -#define pcre2_real_code PCRE2_SUFFIX(pcre2_real_code_) -#define pcre2_real_general_context PCRE2_SUFFIX(pcre2_real_general_context_) -#define pcre2_real_compile_context PCRE2_SUFFIX(pcre2_real_compile_context_) -#define pcre2_real_convert_context PCRE2_SUFFIX(pcre2_real_convert_context_) -#define pcre2_real_match_context PCRE2_SUFFIX(pcre2_real_match_context_) -#define pcre2_real_jit_stack PCRE2_SUFFIX(pcre2_real_jit_stack_) -#define pcre2_real_match_data PCRE2_SUFFIX(pcre2_real_match_data_) - - -/* Data blocks */ - -#define pcre2_callout_block PCRE2_SUFFIX(pcre2_callout_block_) -#define pcre2_callout_enumerate_block PCRE2_SUFFIX(pcre2_callout_enumerate_block_) -#define pcre2_substitute_callout_block PCRE2_SUFFIX(pcre2_substitute_callout_block_) -#define pcre2_general_context PCRE2_SUFFIX(pcre2_general_context_) -#define pcre2_compile_context PCRE2_SUFFIX(pcre2_compile_context_) -#define pcre2_convert_context PCRE2_SUFFIX(pcre2_convert_context_) -#define pcre2_match_context PCRE2_SUFFIX(pcre2_match_context_) -#define pcre2_match_data PCRE2_SUFFIX(pcre2_match_data_) - - -/* Functions: the complete list in alphabetical order */ - -#define pcre2_callout_enumerate PCRE2_SUFFIX(pcre2_callout_enumerate_) -#define pcre2_code_copy PCRE2_SUFFIX(pcre2_code_copy_) -#define pcre2_code_copy_with_tables PCRE2_SUFFIX(pcre2_code_copy_with_tables_) -#define pcre2_code_free PCRE2_SUFFIX(pcre2_code_free_) -#define pcre2_compile PCRE2_SUFFIX(pcre2_compile_) -#define pcre2_compile_context_copy PCRE2_SUFFIX(pcre2_compile_context_copy_) -#define pcre2_compile_context_create PCRE2_SUFFIX(pcre2_compile_context_create_) -#define pcre2_compile_context_free PCRE2_SUFFIX(pcre2_compile_context_free_) -#define pcre2_config PCRE2_SUFFIX(pcre2_config_) -#define pcre2_convert_context_copy PCRE2_SUFFIX(pcre2_convert_context_copy_) -#define pcre2_convert_context_create PCRE2_SUFFIX(pcre2_convert_context_create_) -#define pcre2_convert_context_free PCRE2_SUFFIX(pcre2_convert_context_free_) -#define pcre2_converted_pattern_free PCRE2_SUFFIX(pcre2_converted_pattern_free_) -#define pcre2_dfa_match PCRE2_SUFFIX(pcre2_dfa_match_) -#define pcre2_general_context_copy PCRE2_SUFFIX(pcre2_general_context_copy_) -#define pcre2_general_context_create PCRE2_SUFFIX(pcre2_general_context_create_) -#define pcre2_general_context_free PCRE2_SUFFIX(pcre2_general_context_free_) -#define pcre2_get_error_message PCRE2_SUFFIX(pcre2_get_error_message_) -#define pcre2_get_mark PCRE2_SUFFIX(pcre2_get_mark_) -#define pcre2_get_match_data_heapframes_size PCRE2_SUFFIX(pcre2_get_match_data_heapframes_size_) -#define pcre2_get_match_data_size PCRE2_SUFFIX(pcre2_get_match_data_size_) -#define pcre2_get_ovector_pointer PCRE2_SUFFIX(pcre2_get_ovector_pointer_) -#define pcre2_get_ovector_count PCRE2_SUFFIX(pcre2_get_ovector_count_) -#define pcre2_get_startchar PCRE2_SUFFIX(pcre2_get_startchar_) -#define pcre2_jit_compile PCRE2_SUFFIX(pcre2_jit_compile_) -#define pcre2_jit_match PCRE2_SUFFIX(pcre2_jit_match_) -#define pcre2_jit_free_unused_memory PCRE2_SUFFIX(pcre2_jit_free_unused_memory_) -#define pcre2_jit_stack_assign PCRE2_SUFFIX(pcre2_jit_stack_assign_) -#define pcre2_jit_stack_create PCRE2_SUFFIX(pcre2_jit_stack_create_) -#define pcre2_jit_stack_free PCRE2_SUFFIX(pcre2_jit_stack_free_) -#define pcre2_maketables PCRE2_SUFFIX(pcre2_maketables_) -#define pcre2_maketables_free PCRE2_SUFFIX(pcre2_maketables_free_) -#define pcre2_match PCRE2_SUFFIX(pcre2_match_) -#define pcre2_match_context_copy PCRE2_SUFFIX(pcre2_match_context_copy_) -#define pcre2_match_context_create PCRE2_SUFFIX(pcre2_match_context_create_) -#define pcre2_match_context_free PCRE2_SUFFIX(pcre2_match_context_free_) -#define pcre2_match_data_create PCRE2_SUFFIX(pcre2_match_data_create_) -#define pcre2_match_data_create_from_pattern PCRE2_SUFFIX(pcre2_match_data_create_from_pattern_) -#define pcre2_match_data_free PCRE2_SUFFIX(pcre2_match_data_free_) -#define pcre2_next_match PCRE2_SUFFIX(pcre2_next_match_) -#define pcre2_pattern_convert PCRE2_SUFFIX(pcre2_pattern_convert_) -#define pcre2_pattern_info PCRE2_SUFFIX(pcre2_pattern_info_) -#define pcre2_serialize_decode PCRE2_SUFFIX(pcre2_serialize_decode_) -#define pcre2_serialize_encode PCRE2_SUFFIX(pcre2_serialize_encode_) -#define pcre2_serialize_free PCRE2_SUFFIX(pcre2_serialize_free_) -#define pcre2_serialize_get_number_of_codes PCRE2_SUFFIX(pcre2_serialize_get_number_of_codes_) -#define pcre2_set_bsr PCRE2_SUFFIX(pcre2_set_bsr_) -#define pcre2_set_callout PCRE2_SUFFIX(pcre2_set_callout_) -#define pcre2_set_character_tables PCRE2_SUFFIX(pcre2_set_character_tables_) -#define pcre2_set_compile_extra_options PCRE2_SUFFIX(pcre2_set_compile_extra_options_) -#define pcre2_set_compile_recursion_guard PCRE2_SUFFIX(pcre2_set_compile_recursion_guard_) -#define pcre2_set_depth_limit PCRE2_SUFFIX(pcre2_set_depth_limit_) -#define pcre2_set_glob_escape PCRE2_SUFFIX(pcre2_set_glob_escape_) -#define pcre2_set_glob_separator PCRE2_SUFFIX(pcre2_set_glob_separator_) -#define pcre2_set_heap_limit PCRE2_SUFFIX(pcre2_set_heap_limit_) -#define pcre2_set_match_limit PCRE2_SUFFIX(pcre2_set_match_limit_) -#define pcre2_set_max_varlookbehind PCRE2_SUFFIX(pcre2_set_max_varlookbehind_) -#define pcre2_set_max_pattern_length PCRE2_SUFFIX(pcre2_set_max_pattern_length_) -#define pcre2_set_max_pattern_compiled_length PCRE2_SUFFIX(pcre2_set_max_pattern_compiled_length_) -#define pcre2_set_newline PCRE2_SUFFIX(pcre2_set_newline_) -#define pcre2_set_parens_nest_limit PCRE2_SUFFIX(pcre2_set_parens_nest_limit_) -#define pcre2_set_offset_limit PCRE2_SUFFIX(pcre2_set_offset_limit_) -#define pcre2_set_optimize PCRE2_SUFFIX(pcre2_set_optimize_) -#define pcre2_set_substitute_callout PCRE2_SUFFIX(pcre2_set_substitute_callout_) -#define pcre2_set_substitute_case_callout PCRE2_SUFFIX(pcre2_set_substitute_case_callout_) -#define pcre2_substitute PCRE2_SUFFIX(pcre2_substitute_) -#define pcre2_substring_copy_byname PCRE2_SUFFIX(pcre2_substring_copy_byname_) -#define pcre2_substring_copy_bynumber PCRE2_SUFFIX(pcre2_substring_copy_bynumber_) -#define pcre2_substring_free PCRE2_SUFFIX(pcre2_substring_free_) -#define pcre2_substring_get_byname PCRE2_SUFFIX(pcre2_substring_get_byname_) -#define pcre2_substring_get_bynumber PCRE2_SUFFIX(pcre2_substring_get_bynumber_) -#define pcre2_substring_length_byname PCRE2_SUFFIX(pcre2_substring_length_byname_) -#define pcre2_substring_length_bynumber PCRE2_SUFFIX(pcre2_substring_length_bynumber_) -#define pcre2_substring_list_get PCRE2_SUFFIX(pcre2_substring_list_get_) -#define pcre2_substring_list_free PCRE2_SUFFIX(pcre2_substring_list_free_) -#define pcre2_substring_nametable_scan PCRE2_SUFFIX(pcre2_substring_nametable_scan_) -#define pcre2_substring_number_from_name PCRE2_SUFFIX(pcre2_substring_number_from_name_) - -/* Keep this old function name for backwards compatibility */ -#define pcre2_set_recursion_limit PCRE2_SUFFIX(pcre2_set_recursion_limit_) - -/* Keep this obsolete function for backwards compatibility: it is now a noop. */ -#define pcre2_set_recursion_memory_management PCRE2_SUFFIX(pcre2_set_recursion_memory_management_) - -/* Now generate all three sets of width-specific structures and function -prototypes. */ - -#define PCRE2_TYPES_STRUCTURES_AND_FUNCTIONS \ -PCRE2_TYPES_LIST \ -PCRE2_STRUCTURE_LIST \ -PCRE2_GENERAL_INFO_FUNCTIONS \ -PCRE2_GENERAL_CONTEXT_FUNCTIONS \ -PCRE2_COMPILE_CONTEXT_FUNCTIONS \ -PCRE2_CONVERT_CONTEXT_FUNCTIONS \ -PCRE2_CONVERT_FUNCTIONS \ -PCRE2_MATCH_CONTEXT_FUNCTIONS \ -PCRE2_COMPILE_FUNCTIONS \ -PCRE2_PATTERN_INFO_FUNCTIONS \ -PCRE2_MATCH_FUNCTIONS \ -PCRE2_SUBSTRING_FUNCTIONS \ -PCRE2_SERIALIZE_FUNCTIONS \ -PCRE2_SUBSTITUTE_FUNCTION \ -PCRE2_JIT_FUNCTIONS \ -PCRE2_OTHER_FUNCTIONS - -#define PCRE2_LOCAL_WIDTH 8 -PCRE2_TYPES_STRUCTURES_AND_FUNCTIONS -#undef PCRE2_LOCAL_WIDTH - -#define PCRE2_LOCAL_WIDTH 16 -PCRE2_TYPES_STRUCTURES_AND_FUNCTIONS -#undef PCRE2_LOCAL_WIDTH - -#define PCRE2_LOCAL_WIDTH 32 -PCRE2_TYPES_STRUCTURES_AND_FUNCTIONS -#undef PCRE2_LOCAL_WIDTH - -/* Undefine the list macros; they are no longer needed. */ - -#undef PCRE2_TYPES_LIST -#undef PCRE2_STRUCTURE_LIST -#undef PCRE2_GENERAL_INFO_FUNCTIONS -#undef PCRE2_GENERAL_CONTEXT_FUNCTIONS -#undef PCRE2_COMPILE_CONTEXT_FUNCTIONS -#undef PCRE2_CONVERT_CONTEXT_FUNCTIONS -#undef PCRE2_MATCH_CONTEXT_FUNCTIONS -#undef PCRE2_COMPILE_FUNCTIONS -#undef PCRE2_PATTERN_INFO_FUNCTIONS -#undef PCRE2_MATCH_FUNCTIONS -#undef PCRE2_SUBSTRING_FUNCTIONS -#undef PCRE2_SERIALIZE_FUNCTIONS -#undef PCRE2_SUBSTITUTE_FUNCTION -#undef PCRE2_JIT_FUNCTIONS -#undef PCRE2_OTHER_FUNCTIONS -#undef PCRE2_TYPES_STRUCTURES_AND_FUNCTIONS - -/* PCRE2_CODE_UNIT_WIDTH must be defined. If it is 8, 16, or 32, redefine -PCRE2_SUFFIX to use it. If it is 0, undefine the other macros and make -PCRE2_SUFFIX a no-op. Otherwise, generate an error. */ - -#undef PCRE2_SUFFIX -#ifndef PCRE2_CODE_UNIT_WIDTH -#error PCRE2_CODE_UNIT_WIDTH must be defined before including pcre2.h. -#error Use 8, 16, or 32; or 0 for a multi-width application. -#else /* PCRE2_CODE_UNIT_WIDTH is defined */ -#if PCRE2_CODE_UNIT_WIDTH == 8 || \ - PCRE2_CODE_UNIT_WIDTH == 16 || \ - PCRE2_CODE_UNIT_WIDTH == 32 -#define PCRE2_SUFFIX(a) PCRE2_GLUE(a, PCRE2_CODE_UNIT_WIDTH) -#elif PCRE2_CODE_UNIT_WIDTH == 0 -#undef PCRE2_JOIN -#undef PCRE2_GLUE -#define PCRE2_SUFFIX(a) a -#else -#error PCRE2_CODE_UNIT_WIDTH must be 0, 8, 16, or 32. -#endif -#endif /* PCRE2_CODE_UNIT_WIDTH is defined */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* PCRE2_H_IDEMPOTENT_GUARD */ - -/* End of pcre2.h */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_auto_possess.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_auto_possess.c deleted file mode 100644 index 4088032..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_auto_possess.c +++ /dev/null @@ -1,1416 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains functions that scan a compiled pattern and change -repeats into possessive repeats where possible. */ - - -#include "pcre2_internal.h" - - - -/* This macro represents the max size of list[] and that is used to keep -track of UCD info in several places, it should be kept on sync with the -value used by GenerateUcd.py */ -#define MAX_LIST 8 - -/************************************************* -* Tables for auto-possessification * -*************************************************/ - -/* This table is used to check whether auto-possessification is possible -between adjacent character-type opcodes. The left-hand (repeated) opcode is -used to select the row, and the right-hand opcode is use to select the column. -A value of 1 means that auto-possessification is OK. For example, the second -value in the first row means that \D+\d can be turned into \D++\d. - -The Unicode property types (\P and \p) have to be present to fill out the table -because of what their opcode values are, but the table values should always be -zero because property types are handled separately in the code. The last four -columns apply to items that cannot be repeated, so there is no need to have -rows for them. Note that OP_DIGIT etc. are generated only when PCRE2_UCP is -*not* set. When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */ - -#define APTROWS (LAST_AUTOTAB_LEFT_OP - FIRST_AUTOTAB_OP + 1) -#define APTCOLS (LAST_AUTOTAB_RIGHT_OP - FIRST_AUTOTAB_OP + 1) - -static const uint8_t autoposstab[APTROWS][APTCOLS] = { -/* \D \d \S \s \W \w . .+ \C \P \p \R \H \h \V \v \X \Z \z $ $M */ - { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* \D */ - { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 }, /* \d */ - { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 }, /* \S */ - { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* \s */ - { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* \W */ - { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 }, /* \w */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* . */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* .+ */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* \C */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* \P */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* \p */ - { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, /* \R */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, /* \H */ - { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0 }, /* \h */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0 }, /* \V */ - { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0 }, /* \v */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 } /* \X */ -}; - -#ifdef SUPPORT_UNICODE -/* This table is used to check whether auto-possessification is possible -between adjacent Unicode property opcodes (OP_PROP and OP_NOTPROP). The -left-hand (repeated) opcode is used to select the row, and the right-hand -opcode is used to select the column. The values are as follows: - - 0 Always return FALSE (never auto-possessify) - 1 Character groups are distinct (possessify if both are OP_PROP) - 2 Check character categories in the same group (general or particular) - 3 TRUE if the two opcodes are not the same (PROP vs NOTPROP) - - 4 Check left general category vs right particular category - 5 Check right general category vs left particular category - - 6 Left alphanum vs right general category - 7 Left space vs right general category - 8 Left word vs right general category - - 9 Right alphanum vs left general category - 10 Right space vs left general category - 11 Right word vs left general category - - 12 Left alphanum vs right particular category - 13 Left space vs right particular category - 14 Left word vs right particular category - - 15 Right alphanum vs left particular category - 16 Right space vs left particular category - 17 Right word vs left particular category -*/ - -static const uint8_t propposstab[PT_TABSIZE][PT_TABSIZE] = { -/* LAMP GC PC SC SCX ALNUM SPACE PXSPACE WORD CLIST UCNC BIDICL BOOL */ - { 3, 0, 0, 0, 0, 3, 1, 1, 0, 0, 0, 0, 0 }, /* PT_LAMP */ - { 0, 2, 4, 0, 0, 9, 10, 10, 11, 0, 0, 0, 0 }, /* PT_GC */ - { 0, 5, 2, 0, 0, 15, 16, 16, 17, 0, 0, 0, 0 }, /* PT_PC */ - { 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0 }, /* PT_SC */ - { 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0 }, /* PT_SCX */ - { 3, 6, 12, 0, 0, 3, 1, 1, 0, 0, 0, 0, 0 }, /* PT_ALNUM */ - { 1, 7, 13, 0, 0, 1, 3, 3, 1, 0, 0, 0, 0 }, /* PT_SPACE */ - { 1, 7, 13, 0, 0, 1, 3, 3, 1, 0, 0, 0, 0 }, /* PT_PXSPACE */ - { 0, 8, 14, 0, 0, 0, 1, 1, 3, 0, 0, 0, 0 }, /* PT_WORD */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* PT_CLIST */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 }, /* PT_UCNC */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* PT_BIDICL */ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* PT_BOOL */ - /* PT_ANY does not need a record. */ -}; - -/* This table is used to check whether auto-possessification is possible -between adjacent Unicode property opcodes (OP_PROP and OP_NOTPROP) when one -specifies a general category and the other specifies a particular category. The -row is selected by the general category and the column by the particular -category. The value is 1 if the particular category is not part of the general -category. */ - -static const uint8_t catposstab[7][30] = { -/* Cc Cf Cn Co Cs Ll Lm Lo Lt Lu Mc Me Mn Nd Nl No Pc Pd Pe Pf Pi Po Ps Sc Sk Sm So Zl Zp Zs */ - { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* C */ - { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* L */ - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* M */ - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* N */ - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }, /* P */ - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1 }, /* S */ - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 } /* Z */ -}; - -/* This table is used when checking ALNUM, (PX)SPACE, SPACE, and WORD against -a general or particular category. The properties in each row are those -that apply to the character set in question. Duplication means that a little -unnecessary work is done when checking, but this keeps things much simpler -because they can all use the same code. For more details see the comment where -this table is used. - -Note: SPACE and PXSPACE used to be different because Perl excluded VT from -"space", but from Perl 5.18 it's included, so both categories are treated the -same here. */ - -static const uint8_t posspropstab[3][4] = { - { ucp_L, ucp_N, ucp_N, ucp_Nl }, /* ALNUM, 3rd and 4th values redundant */ - { ucp_Z, ucp_Z, ucp_C, ucp_Cc }, /* SPACE and PXSPACE, 2nd value redundant */ - { ucp_L, ucp_N, ucp_P, ucp_Po } /* WORD */ -}; -#endif /* SUPPORT_UNICODE */ - - - -#ifdef SUPPORT_UNICODE -/************************************************* -* Check a character and a property * -*************************************************/ - -/* This function is called by compare_opcodes() when a property item is -adjacent to a fixed character. - -Arguments: - c the character - ptype the property type - pdata the data for the type - negated TRUE if it's a negated property (\P or \p{^) - -Returns: TRUE if auto-possessifying is OK -*/ - -static BOOL -check_char_prop(uint32_t c, unsigned int ptype, unsigned int pdata, - BOOL negated) -{ -BOOL ok, rc; -const uint32_t *p; -const ucd_record *prop = GET_UCD(c); - -switch(ptype) - { - case PT_LAMP: - return (prop->chartype == ucp_Lu || - prop->chartype == ucp_Ll || - prop->chartype == ucp_Lt) == negated; - - case PT_GC: - return (pdata == PRIV(ucp_gentype)[prop->chartype]) == negated; - - case PT_PC: - return (pdata == prop->chartype) == negated; - - case PT_SC: - return (pdata == prop->script) == negated; - - case PT_SCX: - ok = (pdata == prop->script - || MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), pdata) != 0); - return ok == negated; - - /* These are specials */ - - case PT_ALNUM: - return (PRIV(ucp_gentype)[prop->chartype] == ucp_L || - PRIV(ucp_gentype)[prop->chartype] == ucp_N) == negated; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, which - means that Perl space and POSIX space are now identical. PCRE was changed - at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - switch(c) - { - HSPACE_CASES: - VSPACE_CASES: - rc = negated; - break; - - default: - rc = (PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == negated; - } - return rc; - - case PT_WORD: - return (PRIV(ucp_gentype)[prop->chartype] == ucp_L || - PRIV(ucp_gentype)[prop->chartype] == ucp_N || - c == CHAR_UNDERSCORE) == negated; - - case PT_CLIST: - p = PRIV(ucd_caseless_sets) + prop->caseset; - for (;;) - { - if (c < *p) return !negated; - if (c == *p++) return negated; - } - /* LCOV_EXCL_START */ - PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ - break; - /* LCOV_EXCL_STOP */ - - /* Haven't yet thought these through. */ - - case PT_BIDICL: - return FALSE; - - case PT_BOOL: - return FALSE; - } - -return FALSE; -} -#endif /* SUPPORT_UNICODE */ - - - -/************************************************* -* Base opcode of repeated opcodes * -*************************************************/ - -/* Returns the base opcode for repeated single character type opcodes. If the -opcode is not a repeated character type, it returns with the original value. - -Arguments: c opcode -Returns: base opcode for the type -*/ - -static PCRE2_UCHAR -get_repeat_base(PCRE2_UCHAR c) -{ -return (c > OP_TYPEPOSUPTO)? c : - (c >= OP_TYPESTAR)? OP_TYPESTAR : - (c >= OP_NOTSTARI)? OP_NOTSTARI : - (c >= OP_NOTSTAR)? OP_NOTSTAR : - (c >= OP_STARI)? OP_STARI : - OP_STAR; -} - - -/************************************************* -* Fill the character property list * -*************************************************/ - -/* Checks whether the code points to an opcode that can take part in auto- -possessification, and if so, fills a list with its properties. - -Arguments: - code points to start of expression - utf TRUE if in UTF mode - ucp TRUE if in UCP mode - fcc points to the case-flipping table - list points to output list - list[0] will be filled with the opcode - list[1] will be non-zero if this opcode - can match an empty character string - list[2..7] depends on the opcode - -Returns: points to the start of the next opcode if *code is accepted - NULL if *code is not accepted -*/ - -static PCRE2_SPTR -get_chr_property_list(PCRE2_SPTR code, BOOL utf, BOOL ucp, const uint8_t *fcc, - uint32_t *list) -{ -PCRE2_UCHAR c = *code; -PCRE2_UCHAR base; -PCRE2_SPTR end; -PCRE2_SPTR class_end; -uint32_t chr; - -#ifdef SUPPORT_UNICODE -uint32_t *clist_dest; -const uint32_t *clist_src; -#else -(void)utf; /* Suppress "unused parameter" compiler warnings */ -(void)ucp; -#endif - -list[0] = c; -list[1] = FALSE; -code++; - -if (c >= OP_STAR && c <= OP_TYPEPOSUPTO) - { - base = get_repeat_base(c); - c -= (base - OP_STAR); - - if (c == OP_UPTO || c == OP_MINUPTO || c == OP_EXACT || c == OP_POSUPTO) - code += IMM2_SIZE; - - list[1] = (c != OP_PLUS && c != OP_MINPLUS && c != OP_EXACT && - c != OP_POSPLUS); - - switch(base) - { - case OP_STAR: - list[0] = OP_CHAR; - break; - - case OP_STARI: - list[0] = OP_CHARI; - break; - - case OP_NOTSTAR: - list[0] = OP_NOT; - break; - - case OP_NOTSTARI: - list[0] = OP_NOTI; - break; - - case OP_TYPESTAR: - list[0] = *code; - code++; - break; - } - c = list[0]; - } - -switch(c) - { - case OP_NOT_DIGIT: - case OP_DIGIT: - case OP_NOT_WHITESPACE: - case OP_WHITESPACE: - case OP_NOT_WORDCHAR: - case OP_WORDCHAR: - case OP_ANY: - case OP_ALLANY: - case OP_ANYNL: - case OP_NOT_HSPACE: - case OP_HSPACE: - case OP_NOT_VSPACE: - case OP_VSPACE: - case OP_EXTUNI: - case OP_EODN: - case OP_EOD: - case OP_DOLL: - case OP_DOLLM: - return code; - - case OP_CHAR: - case OP_NOT: - GETCHARINCTEST(chr, code); - list[2] = chr; - list[3] = NOTACHAR; - return code; - - case OP_CHARI: - case OP_NOTI: - list[0] = (c == OP_CHARI) ? OP_CHAR : OP_NOT; - GETCHARINCTEST(chr, code); - list[2] = chr; - -#ifdef SUPPORT_UNICODE - if (chr < 128 || (chr < 256 && !utf && !ucp)) - list[3] = fcc[chr]; - else - list[3] = UCD_OTHERCASE(chr); -#elif defined SUPPORT_WIDE_CHARS - list[3] = (chr < 256) ? fcc[chr] : chr; -#else - list[3] = fcc[chr]; -#endif - - /* The othercase might be the same value. */ - - if (chr == list[3]) - list[3] = NOTACHAR; - else - list[4] = NOTACHAR; - return code; - -#ifdef SUPPORT_UNICODE - case OP_PROP: - case OP_NOTPROP: - if (code[0] != PT_CLIST) - { - list[2] = code[0]; - list[3] = code[1]; - return code + 2; - } - - /* Convert only if we have enough space. */ - - clist_src = PRIV(ucd_caseless_sets) + code[1]; - clist_dest = list + 2; - code += 2; - - do { - if (clist_dest >= list + MAX_LIST) - { - /* Early return if there is not enough space. GenerateUcd.py - generated a list with more than 5 characters and something - must be done about that going forward. */ - PCRE2_DEBUG_UNREACHABLE(); /* Remove if it ever triggers */ - list[2] = code[0]; - list[3] = code[1]; - return code; - } - *clist_dest++ = *clist_src; - } - while(*clist_src++ != NOTACHAR); - - /* All characters are stored. The terminating NOTACHAR is copied from the - clist itself. */ - - list[0] = (c == OP_PROP) ? OP_CHAR : OP_NOT; - return code; -#endif - - case OP_NCLASS: - case OP_CLASS: -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - case OP_ECLASS: - if (c == OP_XCLASS || c == OP_ECLASS) - end = code + GET(code, 0) - 1; - else -#endif - end = code + 32 / sizeof(PCRE2_UCHAR); - class_end = end; - - switch(*end) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSSTAR: - case OP_CRPOSQUERY: - list[1] = TRUE; - end++; - break; - - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRPOSPLUS: - end++; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - list[1] = (GET2(end, 1) == 0); - end += 1 + 2 * IMM2_SIZE; - break; - } - list[2] = (uint32_t)(end - code); - list[3] = (uint32_t)(end - class_end); - return end; - } - -return NULL; /* Opcode not accepted */ -} - - - -/************************************************* -* Scan further character sets for match * -*************************************************/ - -/* Checks whether the base and the current opcode have a common character, in -which case the base cannot be possessified. - -Arguments: - code points to the byte code - utf TRUE in UTF mode - ucp TRUE in UCP mode - cb compile data block - base_list the data list of the base opcode - base_end the end of the base opcode - rec_limit points to recursion depth counter - -Returns: TRUE if the auto-possessification is possible -*/ - -static BOOL -compare_opcodes(PCRE2_SPTR code, BOOL utf, BOOL ucp, const compile_block *cb, - const uint32_t *base_list, PCRE2_SPTR base_end, int *rec_limit) -{ -PCRE2_UCHAR c; -uint32_t list[MAX_LIST]; -const uint32_t *chr_ptr; -const uint32_t *ochr_ptr; -const uint32_t *list_ptr; -PCRE2_SPTR next_code; -#ifdef SUPPORT_WIDE_CHARS -PCRE2_SPTR xclass_flags; -#endif -const uint8_t *class_bitset; -const uint8_t *set1, *set2, *set_end; -uint32_t chr; -BOOL accepted, invert_bits; -BOOL entered_a_group = FALSE; - -if (--(*rec_limit) <= 0) return FALSE; /* Recursion has gone too deep */ - -/* Note: the base_list[1] contains whether the current opcode has a greedy -(represented by a non-zero value) quantifier. This is a different from -other character type lists, which store here that the character iterator -matches to an empty string (also represented by a non-zero value). */ - -for(;;) - { - PCRE2_SPTR bracode; - - /* All operations move the code pointer forward. - Therefore infinite recursions are not possible. */ - - c = *code; - - /* Skip over callouts */ - - if (c == OP_CALLOUT) - { - code += PRIV(OP_lengths)[c]; - continue; - } - - if (c == OP_CALLOUT_STR) - { - code += GET(code, 1 + 2*LINK_SIZE); - continue; - } - - /* At the end of a branch, skip to the end of the group and process it. */ - - if (c == OP_ALT) - { - do code += GET(code, 1); while (*code == OP_ALT); - c = *code; - } - - /* Inspect the next opcode. */ - - switch(c) - { - /* We can always possessify a greedy iterator at the end of the pattern, - which is reached after skipping over the final OP_KET. A non-greedy - iterator must never be possessified. */ - - case OP_END: - return base_list[1] != 0; - - /* When an iterator is at the end of certain kinds of group we can inspect - what follows the group by skipping over the closing ket. Note that this - does not apply to OP_KETRMAX or OP_KETRMIN because what follows any given - iteration is variable (could be another iteration or could be the next - item). As these two opcodes are not listed in the next switch, they will - end up as the next code to inspect, and return FALSE by virtue of being - unsupported. */ - - case OP_KET: - case OP_KETRPOS: - /* The non-greedy case cannot be converted to a possessive form. */ - - if (base_list[1] == 0) return FALSE; - - /* If the bracket is capturing it might be referenced by an OP_RECURSE - so its last iterator can never be possessified if the pattern contains - recursions. (This could be improved by keeping a list of group numbers that - are called by recursion.) */ - - bracode = code - GET(code, 1); - switch(*bracode) - { - case OP_CBRA: - case OP_SCBRA: - case OP_CBRAPOS: - case OP_SCBRAPOS: - if (cb->had_recurse) return FALSE; - break; - - /* A script run might have to backtrack if the iterated item can match - characters from more than one script. So give up unless repeating an - explicit character. */ - - case OP_SCRIPT_RUN: - if (base_list[0] != OP_CHAR && base_list[0] != OP_CHARI) - return FALSE; - break; - - /* Atomic sub-patterns and forward assertions can always auto-possessify - their last iterator. However, if the group was entered as a result of - checking a previous iterator, this is not possible. */ - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ONCE: - return !entered_a_group; - - /* Fixed-length lookbehinds can be treated the same way, but variable - length lookbehinds must not auto-possessify their last iterator. Note - that in order to identify a variable length lookbehind we must check - through all branches, because some may be of fixed length. */ - - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - do - { - if (bracode[1+LINK_SIZE] == OP_VREVERSE) return FALSE; /* Variable */ - bracode += GET(bracode, 1); - } - while (*bracode == OP_ALT); - return !entered_a_group; /* Not variable length */ - - /* Non-atomic assertions - don't possessify last iterator. This needs - more thought. */ - - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - return FALSE; - } - - /* Skip over the bracket and inspect what comes next. */ - - code += PRIV(OP_lengths)[c]; - continue; - - /* Handle cases where the next item is a group. */ - - case OP_ONCE: - case OP_BRA: - case OP_CBRA: - next_code = code + GET(code, 1); - code += PRIV(OP_lengths)[c]; - - /* Check each branch. We have to recurse a level for all but the last - branch. */ - - while (*next_code == OP_ALT) - { - if (!compare_opcodes(code, utf, ucp, cb, base_list, base_end, rec_limit)) - return FALSE; - code = next_code + 1 + LINK_SIZE; - next_code += GET(next_code, 1); - } - - entered_a_group = TRUE; - continue; - - case OP_BRAZERO: - case OP_BRAMINZERO: - - next_code = code + 1; - if (*next_code != OP_BRA && *next_code != OP_CBRA && - *next_code != OP_ONCE) return FALSE; - - do next_code += GET(next_code, 1); while (*next_code == OP_ALT); - - /* The bracket content will be checked by the OP_BRA/OP_CBRA case above. */ - - next_code += 1 + LINK_SIZE; - if (!compare_opcodes(next_code, utf, ucp, cb, base_list, base_end, - rec_limit)) - return FALSE; - - code += PRIV(OP_lengths)[c]; - continue; - - /* The next opcode does not need special handling; fall through and use it - to see if the base can be possessified. */ - - default: - break; - } - - /* We now have the next appropriate opcode to compare with the base. Check - for a supported opcode, and load its properties. */ - - code = get_chr_property_list(code, utf, ucp, cb->fcc, list); - if (code == NULL) return FALSE; /* Unsupported */ - - /* If either opcode is a small character list, set pointers for comparing - characters from that list with another list, or with a property. */ - - if (base_list[0] == OP_CHAR) - { - chr_ptr = base_list + 2; - list_ptr = list; - } - else if (list[0] == OP_CHAR) - { - chr_ptr = list + 2; - list_ptr = base_list; - } - - /* Character bitsets can also be compared to certain opcodes. */ - - else if (base_list[0] == OP_CLASS || list[0] == OP_CLASS -#if PCRE2_CODE_UNIT_WIDTH == 8 - /* In 8 bit, non-UTF mode, OP_CLASS and OP_NCLASS are the same. */ - || (!utf && (base_list[0] == OP_NCLASS || list[0] == OP_NCLASS)) -#endif - ) - { -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (base_list[0] == OP_CLASS || (!utf && base_list[0] == OP_NCLASS)) -#else - if (base_list[0] == OP_CLASS) -#endif - { - set1 = (const uint8_t *)(base_end - base_list[2]); - list_ptr = list; - } - else - { - set1 = (const uint8_t *)(code - list[2]); - list_ptr = base_list; - } - - invert_bits = FALSE; - switch(list_ptr[0]) - { - case OP_CLASS: - case OP_NCLASS: - set2 = (const uint8_t *) - ((list_ptr == list ? code : base_end) - list_ptr[2]); - break; - -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - xclass_flags = (list_ptr == list ? code : base_end) - - list_ptr[2] + LINK_SIZE; - if ((*xclass_flags & XCL_HASPROP) != 0) return FALSE; - if ((*xclass_flags & XCL_MAP) == 0) - { - /* No bits are set for characters < 256. */ - if (list[1] == 0) return (*xclass_flags & XCL_NOT) == 0; - /* Might be an empty repeat. */ - continue; - } - set2 = (const uint8_t *)(xclass_flags + 1); - break; -#endif - - case OP_NOT_DIGIT: - invert_bits = TRUE; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_DIGIT: - set2 = (const uint8_t *)(cb->cbits + cbit_digit); - break; - - case OP_NOT_WHITESPACE: - invert_bits = TRUE; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_WHITESPACE: - set2 = (const uint8_t *)(cb->cbits + cbit_space); - break; - - case OP_NOT_WORDCHAR: - invert_bits = TRUE; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_WORDCHAR: - set2 = (const uint8_t *)(cb->cbits + cbit_word); - break; - - default: - return FALSE; - } - - /* Because the bit sets are unaligned bytes, we need to perform byte - comparison here. */ - - set_end = set1 + 32; - if (invert_bits) - { - do - { - if ((*set1++ & ~(*set2++)) != 0) return FALSE; - } - while (set1 < set_end); - } - else - { - do - { - if ((*set1++ & *set2++) != 0) return FALSE; - } - while (set1 < set_end); - } - - if (list[1] == 0) return TRUE; - /* Might be an empty repeat. */ - continue; - } - - /* Some property combinations also acceptable. Unicode property opcodes are - processed specially; the rest can be handled with a lookup table. */ - - else - { - uint32_t leftop, rightop; - - leftop = base_list[0]; - rightop = list[0]; - -#ifdef SUPPORT_UNICODE - accepted = FALSE; /* Always set in non-unicode case. */ - if (leftop == OP_PROP || leftop == OP_NOTPROP) - { - if (rightop == OP_EOD) - accepted = TRUE; - else if (rightop == OP_PROP || rightop == OP_NOTPROP) - { - int n; - const uint8_t *p; - BOOL same = leftop == rightop; - BOOL lisprop = leftop == OP_PROP; - BOOL risprop = rightop == OP_PROP; - BOOL bothprop = lisprop && risprop; - - /* There's a table that specifies how each combination is to be - processed: - 0 Always return FALSE (never auto-possessify) - 1 Character groups are distinct (possessify if both are OP_PROP) - 2 Check character categories in the same group (general or particular) - 3 Return TRUE if the two opcodes are not the same - ... see comments below - */ - - n = propposstab[base_list[2]][list[2]]; - switch(n) - { - case 0: break; - case 1: accepted = bothprop; break; - case 2: accepted = (base_list[3] == list[3]) != same; break; - case 3: accepted = !same; break; - - case 4: /* Left general category, right particular category */ - accepted = risprop && catposstab[base_list[3]][list[3]] == same; - break; - - case 5: /* Right general category, left particular category */ - accepted = lisprop && catposstab[list[3]][base_list[3]] == same; - break; - - /* This code is logically tricky. Think hard before fiddling with it. - The posspropstab table has four entries per row. Each row relates to - one of PCRE's special properties such as ALNUM or SPACE or WORD. - Only WORD actually needs all four entries, but using repeats for the - others means they can all use the same code below. - - The first two entries in each row are Unicode general categories, and - apply always, because all the characters they include are part of the - PCRE character set. The third and fourth entries are a general and a - particular category, respectively, that include one or more relevant - characters. One or the other is used, depending on whether the check - is for a general or a particular category. However, in both cases the - category contains more characters than the specials that are defined - for the property being tested against. Therefore, it cannot be used - in a NOTPROP case. - - Example: the row for WORD contains ucp_L, ucp_N, ucp_P, ucp_Po. - Underscore is covered by ucp_P or ucp_Po. */ - - case 6: /* Left alphanum vs right general category */ - case 7: /* Left space vs right general category */ - case 8: /* Left word vs right general category */ - p = posspropstab[n-6]; - accepted = risprop && lisprop == - (list[3] != p[0] && - list[3] != p[1] && - (list[3] != p[2] || !lisprop)); - break; - - case 9: /* Right alphanum vs left general category */ - case 10: /* Right space vs left general category */ - case 11: /* Right word vs left general category */ - p = posspropstab[n-9]; - accepted = lisprop && risprop == - (base_list[3] != p[0] && - base_list[3] != p[1] && - (base_list[3] != p[2] || !risprop)); - break; - - case 12: /* Left alphanum vs right particular category */ - case 13: /* Left space vs right particular category */ - case 14: /* Left word vs right particular category */ - p = posspropstab[n-12]; - accepted = risprop && lisprop == - (catposstab[p[0]][list[3]] && - catposstab[p[1]][list[3]] && - (list[3] != p[3] || !lisprop)); - break; - - case 15: /* Right alphanum vs left particular category */ - case 16: /* Right space vs left particular category */ - case 17: /* Right word vs left particular category */ - p = posspropstab[n-15]; - accepted = lisprop && risprop == - (catposstab[p[0]][base_list[3]] && - catposstab[p[1]][base_list[3]] && - (base_list[3] != p[3] || !risprop)); - break; - } - } - } - - else -#endif /* SUPPORT_UNICODE */ - - accepted = leftop >= FIRST_AUTOTAB_OP && leftop <= LAST_AUTOTAB_LEFT_OP && - rightop >= FIRST_AUTOTAB_OP && rightop <= LAST_AUTOTAB_RIGHT_OP && - autoposstab[leftop - FIRST_AUTOTAB_OP][rightop - FIRST_AUTOTAB_OP]; - - if (!accepted) return FALSE; - - if (list[1] == 0) return TRUE; - /* Might be an empty repeat. */ - continue; - } - - /* Control reaches here only if one of the items is a small character list. - All characters are checked against the other side. */ - - do - { - chr = *chr_ptr; - - switch(list_ptr[0]) - { - case OP_CHAR: - ochr_ptr = list_ptr + 2; - do - { - if (chr == *ochr_ptr) return FALSE; - ochr_ptr++; - } - while(*ochr_ptr != NOTACHAR); - break; - - case OP_NOT: - ochr_ptr = list_ptr + 2; - do - { - if (chr == *ochr_ptr) - break; - ochr_ptr++; - } - while(*ochr_ptr != NOTACHAR); - if (*ochr_ptr == NOTACHAR) return FALSE; /* Not found */ - break; - - /* Note that OP_DIGIT etc. are generated only when PCRE2_UCP is *not* - set. When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */ - - case OP_DIGIT: - if (chr < 256 && (cb->ctypes[chr] & ctype_digit) != 0) return FALSE; - break; - - case OP_NOT_DIGIT: - if (chr > 255 || (cb->ctypes[chr] & ctype_digit) == 0) return FALSE; - break; - - case OP_WHITESPACE: - if (chr < 256 && (cb->ctypes[chr] & ctype_space) != 0) return FALSE; - break; - - case OP_NOT_WHITESPACE: - if (chr > 255 || (cb->ctypes[chr] & ctype_space) == 0) return FALSE; - break; - - case OP_WORDCHAR: - if (chr < 255 && (cb->ctypes[chr] & ctype_word) != 0) return FALSE; - break; - - case OP_NOT_WORDCHAR: - if (chr > 255 || (cb->ctypes[chr] & ctype_word) == 0) return FALSE; - break; - - case OP_HSPACE: - switch(chr) - { - HSPACE_CASES: return FALSE; - default: break; - } - break; - - case OP_NOT_HSPACE: - switch(chr) - { - HSPACE_CASES: break; - default: return FALSE; - } - break; - - case OP_ANYNL: - case OP_VSPACE: - switch(chr) - { - VSPACE_CASES: return FALSE; - default: break; - } - break; - - case OP_NOT_VSPACE: - switch(chr) - { - VSPACE_CASES: break; - default: return FALSE; - } - break; - - case OP_DOLL: - case OP_EODN: - switch (chr) - { - case CHAR_CR: - case CHAR_LF: - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#ifndef EBCDIC - case 0x2028: - case 0x2029: -#endif /* Not EBCDIC */ - return FALSE; - } - break; - - case OP_EOD: /* Can always possessify before \z */ - break; - -#ifdef SUPPORT_UNICODE - case OP_PROP: - case OP_NOTPROP: - if (!check_char_prop(chr, list_ptr[2], list_ptr[3], - list_ptr[0] == OP_NOTPROP)) - return FALSE; - break; -#endif - - case OP_NCLASS: - if (chr > 255) return FALSE; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_CLASS: - if (chr > 255) break; - class_bitset = (const uint8_t *) - ((list_ptr == list ? code : base_end) - list_ptr[2]); - if ((class_bitset[chr >> 3] & (1u << (chr & 7))) != 0) return FALSE; - break; - -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - if (PRIV(xclass)(chr, (list_ptr == list ? code : base_end) - - list_ptr[2] + LINK_SIZE, (const uint8_t*)cb->start_code, utf)) - return FALSE; - break; - - case OP_ECLASS: - if (PRIV(eclass)(chr, - (list_ptr == list ? code : base_end) - list_ptr[2] + LINK_SIZE, - (list_ptr == list ? code : base_end) - list_ptr[3], - (const uint8_t*)cb->start_code, utf)) - return FALSE; - break; -#endif /* SUPPORT_WIDE_CHARS */ - - default: - return FALSE; - } - - chr_ptr++; - } - while(*chr_ptr != NOTACHAR); - - /* At least one character must be matched from this opcode. */ - - if (list[1] == 0) return TRUE; - } - -/* LCOV_EXCL_START */ -PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ -return FALSE; /* Avoid compiler warnings */ -/* LCOV_EXCL_STOP */ -} - - - -/************************************************* -* Scan compiled regex for auto-possession * -*************************************************/ - -/* Replaces single character iterations with their possessive alternatives -if appropriate. This function modifies the compiled opcode! Hitting a -non-existent opcode may indicate a bug in PCRE2, but it can also be caused if a -bad UTF string was compiled with PCRE2_NO_UTF_CHECK. The rec_limit catches -overly complicated or large patterns. In these cases, the check just stops, -leaving the remainder of the pattern unpossessified. - -Arguments: - code points to start of the byte code - cb compile data block - -Returns: 0 for success - -1 if a non-existant opcode is encountered -*/ - -int -PRIV(auto_possessify)(PCRE2_UCHAR *code, const compile_block *cb) -{ -PCRE2_UCHAR c; -PCRE2_SPTR end; -PCRE2_UCHAR *repeat_opcode; -uint32_t list[MAX_LIST]; -int rec_limit = 1000; /* Was 10,000 but clang+ASAN uses a lot of stack. */ -BOOL utf = (cb->external_options & PCRE2_UTF) != 0; -BOOL ucp = (cb->external_options & PCRE2_UCP) != 0; - -for (;;) - { - c = *code; - - /* LCOV_EXCL_START */ - if (c >= OP_TABLE_LENGTH) - { - PCRE2_DEBUG_UNREACHABLE(); - return -1; /* Something gone wrong */ - } - /* LCOV_EXCL_STOP */ - - if (c >= OP_STAR && c <= OP_TYPEPOSUPTO) - { - c -= get_repeat_base(c) - OP_STAR; - end = (c <= OP_MINUPTO) ? - get_chr_property_list(code, utf, ucp, cb->fcc, list) : NULL; - list[1] = c == OP_STAR || c == OP_PLUS || c == OP_QUERY || c == OP_UPTO; - - if (end != NULL && compare_opcodes(end, utf, ucp, cb, list, end, - &rec_limit)) - { - switch(c) - { - case OP_STAR: - *code += OP_POSSTAR - OP_STAR; - break; - - case OP_MINSTAR: - *code += OP_POSSTAR - OP_MINSTAR; - break; - - case OP_PLUS: - *code += OP_POSPLUS - OP_PLUS; - break; - - case OP_MINPLUS: - *code += OP_POSPLUS - OP_MINPLUS; - break; - - case OP_QUERY: - *code += OP_POSQUERY - OP_QUERY; - break; - - case OP_MINQUERY: - *code += OP_POSQUERY - OP_MINQUERY; - break; - - case OP_UPTO: - *code += OP_POSUPTO - OP_UPTO; - break; - - case OP_MINUPTO: - *code += OP_POSUPTO - OP_MINUPTO; - break; - } - } - c = *code; - } - else if (c == OP_CLASS || c == OP_NCLASS -#ifdef SUPPORT_WIDE_CHARS - || c == OP_XCLASS || c == OP_ECLASS -#endif - ) - { -#ifdef SUPPORT_WIDE_CHARS - if (c == OP_XCLASS || c == OP_ECLASS) - repeat_opcode = code + GET(code, 1); - else -#endif - repeat_opcode = code + 1 + (32 / sizeof(PCRE2_UCHAR)); - - c = *repeat_opcode; - if (c >= OP_CRSTAR && c <= OP_CRMINRANGE) - { - /* The return from get_chr_property_list() will never be NULL when - *code (aka c) is one of the four class opcodes. However, gcc with - -fanalyzer notes that a NULL return is possible, and grumbles. Hence we - put in a check. */ - - end = get_chr_property_list(code, utf, ucp, cb->fcc, list); - list[1] = (c & 1) == 0; - - if (end != NULL && - compare_opcodes(end, utf, ucp, cb, list, end, &rec_limit)) - { - switch (c) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - *repeat_opcode = OP_CRPOSSTAR; - break; - - case OP_CRPLUS: - case OP_CRMINPLUS: - *repeat_opcode = OP_CRPOSPLUS; - break; - - case OP_CRQUERY: - case OP_CRMINQUERY: - *repeat_opcode = OP_CRPOSQUERY; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - *repeat_opcode = OP_CRPOSRANGE; - break; - } - } - } - c = *code; - } - - switch(c) - { - case OP_END: - return 0; - - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; - break; - - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEEXACT: - case OP_TYPEPOSUPTO: - if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP) - code += 2; - break; - - case OP_CALLOUT_STR: - code += GET(code, 1 + 2*LINK_SIZE); - break; - -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - case OP_ECLASS: - code += GET(code, 1); - break; -#endif - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_SKIP_ARG: - case OP_THEN_ARG: - code += code[1]; - break; - } - - /* Add in the fixed length from the table */ - - code += PRIV(OP_lengths)[c]; - - /* In UTF-8 and UTF-16 modes, opcodes that are followed by a character may be - followed by a multi-byte character. The length in the table is a minimum, so - we have to arrange to skip the extra code units. */ - -#ifdef MAYBE_UTF_MULTI - if (utf) switch(c) - { - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - case OP_STAR: - case OP_MINSTAR: - case OP_PLUS: - case OP_MINPLUS: - case OP_QUERY: - case OP_MINQUERY: - case OP_UPTO: - case OP_MINUPTO: - case OP_EXACT: - case OP_POSSTAR: - case OP_POSPLUS: - case OP_POSQUERY: - case OP_POSUPTO: - case OP_STARI: - case OP_MINSTARI: - case OP_PLUSI: - case OP_MINPLUSI: - case OP_QUERYI: - case OP_MINQUERYI: - case OP_UPTOI: - case OP_MINUPTOI: - case OP_EXACTI: - case OP_POSSTARI: - case OP_POSPLUSI: - case OP_POSQUERYI: - case OP_POSUPTOI: - case OP_NOTSTAR: - case OP_NOTMINSTAR: - case OP_NOTPLUS: - case OP_NOTMINPLUS: - case OP_NOTQUERY: - case OP_NOTMINQUERY: - case OP_NOTUPTO: - case OP_NOTMINUPTO: - case OP_NOTEXACT: - case OP_NOTPOSSTAR: - case OP_NOTPOSPLUS: - case OP_NOTPOSQUERY: - case OP_NOTPOSUPTO: - case OP_NOTSTARI: - case OP_NOTMINSTARI: - case OP_NOTPLUSI: - case OP_NOTMINPLUSI: - case OP_NOTQUERYI: - case OP_NOTMINQUERYI: - case OP_NOTUPTOI: - case OP_NOTMINUPTOI: - case OP_NOTEXACTI: - case OP_NOTPOSSTARI: - case OP_NOTPOSPLUSI: - case OP_NOTPOSQUERYI: - case OP_NOTPOSUPTOI: - if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]); - break; - } -#else - (void)(utf); /* Keep compiler happy by referencing function argument */ -#endif /* SUPPORT_WIDE_CHARS */ - } -} - -/* End of pcre2_auto_possess.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_chartables.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_chartables.c deleted file mode 100644 index 29f9200..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_chartables.c +++ /dev/null @@ -1,192 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* This file was automatically written by the pcre2_dftables auxiliary -program. It contains character tables that are used when no external -tables are passed to PCRE2 by the application that calls it. The tables -are used only for characters whose code values are less than 256, and -only relevant if not in UCP mode. */ - -/* This set of tables was written in the C locale. */ - -/* The pcre2_ftables program (which is distributed with PCRE2) can be used -to build alternative versions of this file. This is necessary if you are -running in an EBCDIC environment, or if you want to default to a different -encoding, for example ISO-8859-1. When pcre2_dftables is run, it creates -these tables in the "C" locale by default. This happens automatically if -PCRE2 is configured with --enable-rebuild-chartables. However, you can run -pcre2_dftables manually with the -L option to build tables using the LC_ALL -locale. */ - -#include "pcre2_internal.h" - -const uint8_t PRIV(default_tables)[] = { - -/* This table is a lower casing table. */ - - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, - 64, 97, 98, 99,100,101,102,103, - 104,105,106,107,108,109,110,111, - 112,113,114,115,116,117,118,119, - 120,121,122, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103, - 104,105,106,107,108,109,110,111, - 112,113,114,115,116,117,118,119, - 120,121,122,123,124,125,126,127, - 128,129,130,131,132,133,134,135, - 136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151, - 152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167, - 168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183, - 184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199, - 200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215, - 216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231, - 232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247, - 248,249,250,251,252,253,254,255, - -/* This table is a case flipping table. */ - - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, - 64, 97, 98, 99,100,101,102,103, - 104,105,106,107,108,109,110,111, - 112,113,114,115,116,117,118,119, - 120,121,122, 91, 92, 93, 94, 95, - 96, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 90,123,124,125,126,127, - 128,129,130,131,132,133,134,135, - 136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151, - 152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167, - 168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183, - 184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199, - 200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215, - 216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231, - 232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247, - 248,249,250,251,252,253,254,255, - -/* This table contains bit maps for various character classes. Each map is 32 -bytes long and the bits run from the least significant end of each byte. The -classes that have their own maps are: space, xdigit, digit, upper, lower, word, -graph, print, punct, and cntrl. Other classes are built from combinations. */ - - 0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00, /* space */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03, /* xdigit */ - 0x7e,0x00,0x00,0x00,0x7e,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03, /* digit */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* upper */ - 0xfe,0xff,0xff,0x07,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* lower */ - 0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0x07, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03, /* word */ - 0xfe,0xff,0xff,0x87,0xfe,0xff,0xff,0x07, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0xff, /* graph */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff, /* print */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0xfe,0xff,0x00,0xfc, /* punct */ - 0x01,0x00,0x00,0xf8,0x01,0x00,0x00,0x78, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00, /* cntrl */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - -/* This table identifies various classes of character by individual bits: - 0x01 white space character - 0x02 letter - 0x04 lower case letter - 0x08 decimal digit - 0x10 word (alphanumeric or '_') -*/ - - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 */ - 0x00,0x01,0x01,0x01,0x01,0x01,0x00,0x00, /* 8- 15 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 16- 23 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 24- 31 */ - 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - ' */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* ( - / */ - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, /* 0 - 7 */ - 0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00, /* 8 - ? */ - 0x00,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* @ - G */ - 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* H - O */ - 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* P - W */ - 0x12,0x12,0x12,0x00,0x00,0x00,0x00,0x10, /* X - _ */ - 0x00,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* ` - g */ - 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* h - o */ - 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* p - w */ - 0x16,0x16,0x16,0x00,0x00,0x00,0x00,0x00, /* x -127 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 128-135 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 144-151 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 160-167 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 192-199 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 208-215 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 224-231 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */ - -/* End of pcre2_chartables.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_chkdint.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_chkdint.c deleted file mode 100644 index 7aeb640..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_chkdint.c +++ /dev/null @@ -1,94 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Copyright (c) 2023 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This file contains functions to implement checked integer operation */ - - -#ifndef PCRE2_PCRE2TEST -#include "pcre2_internal.h" -#endif - - - -/************************************************* -* Checked Integer Multiplication * -*************************************************/ - -/* -Arguments: - r A pointer to PCRE2_SIZE to store the answer - a, b Two integers - -Returns: Bool indicating if the operation overflows - -It is modeled after C23's interface -The INT64_OR_DOUBLE type is a 64-bit integer type when available, -otherwise double. */ - -BOOL -PRIV(ckd_smul)(PCRE2_SIZE *r, int a, int b) -{ -#ifdef HAVE_BUILTIN_MUL_OVERFLOW -PCRE2_SIZE m; - -if (__builtin_mul_overflow(a, b, &m)) return TRUE; - -*r = m; -#else -INT64_OR_DOUBLE m; - -PCRE2_ASSERT(a >= 0 && b >= 0); - -m = (INT64_OR_DOUBLE)a * (INT64_OR_DOUBLE)b; - -#if defined INT64_MAX || defined int64_t -if (sizeof(m) > sizeof(*r) && m > (INT64_OR_DOUBLE)PCRE2_SIZE_MAX) return TRUE; -*r = (PCRE2_SIZE)m; -#else -if (m > PCRE2_SIZE_MAX) return TRUE; -*r = m; -#endif - -#endif - -return FALSE; -} - -/* End of pcre2_chkdint.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile.c deleted file mode 100644 index 32e86cb..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile.c +++ /dev/null @@ -1,11345 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_compile.h" - - - -#define NLBLOCK cb /* Block containing newline information */ -#define PSSTART start_pattern /* Field containing processed string start */ -#define PSEND end_pattern /* Field containing processed string end */ - -/* In rare error cases debugging might require calling pcre2_printint(). */ - -#if 0 -#ifdef EBCDIC -#define PRINTABLE(c) ((c) >= 64 && (c) < 255) -#else -#define PRINTABLE(c) ((c) >= 32 && (c) < 127) -#endif -#define CHAR_OUTPUT(c) (c) -#define CHAR_OUTPUT_HEX(c) (c) -#define CHAR_INPUT(c) (c) -#define CHAR_INPUT_HEX(c) (c) -#include "pcre2_printint_inc.h" -#undef PRINTABLE -#undef CHAR_OUTPUT -#undef CHAR_OUTPUT_HEX -#undef CHAR_INPUT -#define DEBUG_CALL_PRINTINT -#endif - -/* Other debugging code can be enabled by these defines. */ - -/* #define DEBUG_SHOW_CAPTURES */ -/* #define DEBUG_SHOW_PARSED */ - -/* There are a few things that vary with different code unit sizes. Handle them -by defining macros in order to minimize #if usage. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -#define STRING_UTFn_RIGHTPAR STRING_UTF8_RIGHTPAR, 5 -#define XDIGIT(c) xdigitab[c] - -#else /* Either 16-bit or 32-bit */ -#define XDIGIT(c) (MAX_255(c)? xdigitab[c] : 0xff) - -#if PCRE2_CODE_UNIT_WIDTH == 16 -#define STRING_UTFn_RIGHTPAR STRING_UTF16_RIGHTPAR, 6 - -#else /* 32-bit */ -#define STRING_UTFn_RIGHTPAR STRING_UTF32_RIGHTPAR, 6 -#endif -#endif - -/* Function definitions to allow mutual recursion */ - -static int - compile_regex(uint32_t, uint32_t, PCRE2_UCHAR **, uint32_t **, int *, - uint32_t, uint32_t *, uint32_t *, uint32_t *, uint32_t *, branch_chain *, - open_capitem *, compile_block *, PCRE2_SIZE *); - -static int - get_branchlength(uint32_t **, int *, int *, int *, parsed_recurse_check *, - compile_block *); - -static BOOL - set_lookbehind_lengths(uint32_t **, int *, int *, parsed_recurse_check *, - compile_block *); - -static int - check_lookbehinds(uint32_t *, uint32_t **, parsed_recurse_check *, - compile_block *, int *); - - -/************************************************* -* Code parameters and static tables * -*************************************************/ - -#define MAX_GROUP_NUMBER 65535u -#define MAX_REPEAT_COUNT 65535u -#define REPEAT_UNLIMITED (MAX_REPEAT_COUNT+1) - -/* COMPILE_WORK_SIZE specifies the size of stack workspace, which is used in -different ways in the different pattern scans. The parsing and group- -identifying pre-scan uses it to handle nesting, and needs it to be 16-bit -aligned for this. Having defined the size in code units, we set up -C16_WORK_SIZE as the number of elements in the 16-bit vector. - -During the first compiling phase, when determining how much memory is required, -the regex is partly compiled into this space, but the compiled parts are -discarded as soon as they can be, so that hopefully there will never be an -overrun. The code does, however, check for an overrun, which can occur for -pathological patterns. The size of the workspace depends on LINK_SIZE because -the length of compiled items varies with this. - -In the real compile phase, this workspace is not currently used. */ - -#define COMPILE_WORK_SIZE (3000*LINK_SIZE) /* Size in code units */ - -#define C16_WORK_SIZE \ - ((COMPILE_WORK_SIZE * sizeof(PCRE2_UCHAR))/sizeof(uint16_t)) - -/* A uint32_t vector is used for caching information about the size of -capturing groups, to improve performance. A default is created on the stack of -this size. */ - -#define GROUPINFO_DEFAULT_SIZE 256 - -/* The overrun tests check for a slightly smaller size so that they detect the -overrun before it actually does run off the end of the data block. */ - -#define WORK_SIZE_SAFETY_MARGIN (100) - -/* This value determines the size of the initial vector that is used for -remembering named groups during the pre-compile. It is allocated on the stack, -but if it is too small, it is expanded, in a similar way to the workspace. The -value is the number of slots in the list. */ - -#define NAMED_GROUP_LIST_SIZE 20 - -/* The pre-compiling pass over the pattern creates a parsed pattern in a vector -of uint32_t. For short patterns this lives on the stack, with this size. Heap -memory is used for longer patterns. */ - -#define PARSED_PATTERN_DEFAULT_SIZE 1024 - -/* Maximum length value to check against when making sure that the variable -that holds the compiled pattern length does not overflow. We make it a bit less -than INT_MAX to allow for adding in group terminating code units, so that we -don't have to check them every time. */ - -#define OFLOW_MAX (INT_MAX - 20) - -/* Table of extra lengths for each of the meta codes. Must be kept in step with -the definitions above. For some items these values are a basic length to which -a variable amount has to be added. */ - -static unsigned char meta_extra_lengths[] = { - 0, /* META_END */ - 0, /* META_ALT */ - 0, /* META_ATOMIC */ - 0, /* META_BACKREF - more if group is >= 10 */ - 1+SIZEOFFSET, /* META_BACKREF_BYNAME */ - 1, /* META_BIGVALUE */ - 3, /* META_CALLOUT_NUMBER */ - 3+SIZEOFFSET, /* META_CALLOUT_STRING */ - 0, /* META_CAPTURE */ - 0, /* META_CIRCUMFLEX */ - 0, /* META_CLASS */ - 0, /* META_CLASS_EMPTY */ - 0, /* META_CLASS_EMPTY_NOT */ - 0, /* META_CLASS_END */ - 0, /* META_CLASS_NOT */ - 0, /* META_COND_ASSERT */ - SIZEOFFSET, /* META_COND_DEFINE */ - 1+SIZEOFFSET, /* META_COND_NAME */ - 1+SIZEOFFSET, /* META_COND_NUMBER */ - 1+SIZEOFFSET, /* META_COND_RNAME */ - 1+SIZEOFFSET, /* META_COND_RNUMBER */ - 3, /* META_COND_VERSION */ - SIZEOFFSET, /* META_OFFSET */ - 0, /* META_SCS */ - 1, /* META_CAPTURE_NAME */ - 1, /* META_CAPTURE_NUMBER */ - 0, /* META_DOLLAR */ - 0, /* META_DOT */ - 0, /* META_ESCAPE - one more for ESC_P and ESC_p */ - 0, /* META_KET */ - 0, /* META_NOCAPTURE */ - 2, /* META_OPTIONS */ - 1, /* META_POSIX */ - 1, /* META_POSIX_NEG */ - 0, /* META_RANGE_ESCAPED */ - 0, /* META_RANGE_LITERAL */ - SIZEOFFSET, /* META_RECURSE */ - 1+SIZEOFFSET, /* META_RECURSE_BYNAME */ - 0, /* META_SCRIPT_RUN */ - 0, /* META_LOOKAHEAD */ - 0, /* META_LOOKAHEADNOT */ - SIZEOFFSET, /* META_LOOKBEHIND */ - SIZEOFFSET, /* META_LOOKBEHINDNOT */ - 0, /* META_LOOKAHEAD_NA */ - SIZEOFFSET, /* META_LOOKBEHIND_NA */ - 1, /* META_MARK - plus the string length */ - 0, /* META_ACCEPT */ - 0, /* META_FAIL */ - 0, /* META_COMMIT */ - 1, /* META_COMMIT_ARG - plus the string length */ - 0, /* META_PRUNE */ - 1, /* META_PRUNE_ARG - plus the string length */ - 0, /* META_SKIP */ - 1, /* META_SKIP_ARG - plus the string length */ - 0, /* META_THEN */ - 1, /* META_THEN_ARG - plus the string length */ - 0, /* META_ASTERISK */ - 0, /* META_ASTERISK_PLUS */ - 0, /* META_ASTERISK_QUERY */ - 0, /* META_PLUS */ - 0, /* META_PLUS_PLUS */ - 0, /* META_PLUS_QUERY */ - 0, /* META_QUERY */ - 0, /* META_QUERY_PLUS */ - 0, /* META_QUERY_QUERY */ - 2, /* META_MINMAX */ - 2, /* META_MINMAX_PLUS */ - 2, /* META_MINMAX_QUERY */ - 0, /* META_ECLASS_AND */ - 0, /* META_ECLASS_OR */ - 0, /* META_ECLASS_SUB */ - 0, /* META_ECLASS_XOR */ - 0 /* META_ECLASS_NOT */ -}; - -/* Types for skipping parts of a parsed pattern. */ - -enum { PSKIP_ALT, PSKIP_CLASS, PSKIP_KET }; - -/* Values and flags for the unsigned xxcuflags variables that accompany xxcu -variables, which are concerned with first and required code units. A value -greater than or equal to REQ_NONE means "no code unit set"; otherwise the -matching xxcu variable is set, and the low valued bits are relevant. */ - -#define REQ_UNSET 0xffffffffu /* Not yet found anything */ -#define REQ_NONE 0xfffffffeu /* Found not fixed character */ -#define REQ_CASELESS 0x00000001u /* Code unit in xxcu is caseless */ -#define REQ_VARY 0x00000002u /* Code unit is followed by non-literal */ - -/* These flags are used in the groupinfo vector. */ - -#define GI_SET_FIXED_LENGTH 0x80000000u -#define GI_NOT_FIXED_LENGTH 0x40000000u -#define GI_FIXED_LENGTH_MASK 0x0000ffffu - -/* This simple test for a decimal digit works for both ASCII/Unicode and EBCDIC -and is fast (a good compiler can turn it into a subtraction and unsigned -comparison). */ - -#define IS_DIGIT(x) ((x) >= CHAR_0 && (x) <= CHAR_9) - -/* Table to identify hex digits. The tables in chartables are dependent on the -locale, and may mark arbitrary characters as digits. We want to recognize only -0-9, a-z, and A-Z as hex digits, which is why we have a private table here. It -costs 256 bytes, but it is a lot faster than doing character value tests (at -least in some simple cases I timed), and in some applications one wants PCRE2 -to compile efficiently as well as match efficiently. The value in the table is -the binary hex digit value, or 0xff for non-hex digits. */ - -/* This is the "normal" case, for ASCII systems, and EBCDIC systems running in -UTF-8 mode. */ - -#ifndef EBCDIC -static const uint8_t xdigitab[] = - { - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 0- 7 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 8- 15 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 16- 23 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 24- 31 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* - ' */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* ( - / */ - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, /* 0 - 7 */ - 0x08,0x09,0xff,0xff,0xff,0xff,0xff,0xff, /* 8 - ? */ - 0xff,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xff, /* @ - G */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* H - O */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* P - W */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* X - _ */ - 0xff,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xff, /* ` - g */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* h - o */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* p - w */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* x -127 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 128-135 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 136-143 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 144-151 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 152-159 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 160-167 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 168-175 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 176-183 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 184-191 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 192-199 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 2ff-207 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 208-215 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 216-223 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 224-231 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 232-239 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 240-247 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};/* 248-255 */ - -#else - -/* This is the "abnormal" case, for EBCDIC systems not running in UTF-8 mode. */ - -static const uint8_t xdigitab[] = - { - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 0- 7 0 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 8- 15 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 16- 23 10 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 24- 31 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 32- 39 20 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 40- 47 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 48- 55 30 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 56- 63 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* - 71 40 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 72- | */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* & - 87 50 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 88- 95 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* - -103 60 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 104- ? */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 112-119 70 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 120- " */ - 0xff,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xff, /* 128- g 80 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* h -143 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 144- p 90 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* q -159 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 160- x A0 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* y -175 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* ^ -183 B0 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* 184-191 */ - 0xff,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xff, /* { - G C0 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* H -207 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* } - P D0 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* Q -223 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* \ - X E0 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, /* Y -239 */ - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, /* 0 - 7 F0 */ - 0x08,0x09,0xff,0xff,0xff,0xff,0xff,0xff};/* 8 -255 */ -#endif /* EBCDIC */ - - -/* Table for handling alphanumeric escaped characters. Positive returns are -simple data values; negative values are for special things like \d and so on. -Zero means further processing is needed (for things like \x), or the escape is -invalid. */ - -/* This is the "normal" table for ASCII systems or for EBCDIC systems running -in UTF-8 mode. It runs from '0' to 'z'. */ - -#ifndef EBCDIC -#define ESCAPES_FIRST CHAR_0 -#define ESCAPES_LAST CHAR_z -#define UPPER_CASE(c) (c-32) - -static const short int escapes[] = { - /* 0 */ 0, /* 1 */ 0, - /* 2 */ 0, /* 3 */ 0, - /* 4 */ 0, /* 5 */ 0, - /* 6 */ 0, /* 7 */ 0, - /* 8 */ 0, /* 9 */ 0, - /* : */ ESCAPES_FIRST+0x0a, /* ; */ ESCAPES_FIRST+0x0b, - /* < */ ESCAPES_FIRST+0x0c, /* = */ ESCAPES_FIRST+0x0d, - /* > */ ESCAPES_FIRST+0x0e, /* ? */ ESCAPES_FIRST+0x0f, - /* @ */ ESCAPES_FIRST+0x10, /* A */ -ESC_A, - /* B */ -ESC_B, /* C */ -ESC_C, - /* D */ -ESC_D, /* E */ -ESC_E, - /* F */ 0, /* G */ -ESC_G, - /* H */ -ESC_H, /* I */ 0, - /* J */ 0, /* K */ -ESC_K, - /* L */ 0, /* M */ 0, - /* N */ -ESC_N, /* O */ 0, - /* P */ -ESC_P, /* Q */ -ESC_Q, - /* R */ -ESC_R, /* S */ -ESC_S, - /* T */ 0, /* U */ 0, - /* V */ -ESC_V, /* W */ -ESC_W, - /* X */ -ESC_X, /* Y */ 0, - /* Z */ -ESC_Z, /* [ */ ESCAPES_FIRST+0x2b, - /* \ */ ESCAPES_FIRST+0x2c, /* ] */ ESCAPES_FIRST+0x2d, - /* ^ */ ESCAPES_FIRST+0x2e, /* _ */ ESCAPES_FIRST+0x2f, - /* ` */ ESCAPES_FIRST+0x30, /* a */ CHAR_BEL, - /* b */ -ESC_b, /* c */ 0, - /* d */ -ESC_d, /* e */ CHAR_ESC, - /* f */ CHAR_FF, /* g */ 0, - /* h */ -ESC_h, /* i */ 0, - /* j */ 0, /* k */ -ESC_k, - /* l */ 0, /* m */ 0, - /* n */ CHAR_LF, /* o */ 0, - /* p */ -ESC_p, /* q */ 0, - /* r */ CHAR_CR, /* s */ -ESC_s, - /* t */ CHAR_HT, /* u */ 0, - /* v */ -ESC_v, /* w */ -ESC_w, - /* x */ 0, /* y */ 0, - /* z */ -ESC_z -}; - -#else - -/* This is the "abnormal" table for EBCDIC systems without UTF-8 support. -It runs from 'a' to '9'. Our EBCDIC support can be provided via the compiler, -which can interpret character literals like 'a' or '[' in an EBCDIC codepage; -in this case, there is wide variance between codepages on the interpretation of -characters between the letters ('[' and '{' and so on are placed in all sorts of -different positions in the table). Thankfully however, all EBCDIC codepages -place the letters and digits in the same location, so we hardcode that here. -Our EBCDIC support can also be provided via numeric literals instead of -character literals, so either way, 'CHAR_a' will be 0x81 when PCRE2 is compiled -in EBCDIC mode. */ - -#define ESCAPES_FIRST CHAR_a -#define ESCAPES_LAST CHAR_9 -#define UPPER_CASE(c) (c+64) - -static const short int escapes[] = { - /* 0x81 a */ CHAR_BEL, /* 0x82 b */ -ESC_b, - /* 0x83 c */ 0, /* 0x84 d */ -ESC_d, - /* 0x85 e */ CHAR_ESC, /* 0x86 f */ CHAR_FF, - /* 0x87 g */ 0, /* 0x88 h */ -ESC_h, - /* 0x89 i */ 0, /* 0x8a */ ESCAPES_FIRST+0x09, - /* 0x8b */ ESCAPES_FIRST+0x0a, /* 0x8c */ ESCAPES_FIRST+0x0b, - /* 0x8d */ ESCAPES_FIRST+0x0c, /* 0x8e */ ESCAPES_FIRST+0x0d, - /* 0x8f */ ESCAPES_FIRST+0x0e, /* 0x90 */ ESCAPES_FIRST+0x0f, - /* 0x91 j */ 0, /* 0x92 k */ -ESC_k, - /* 0x93 l */ 0, /* 0x94 m */ 0, - /* 0x95 n */ CHAR_LF, /* 0x96 o */ 0, - /* 0x97 p */ -ESC_p, /* 0x98 q */ 0, - /* 0x99 r */ CHAR_CR, /* 0x9a */ ESCAPES_FIRST+0x19, - /* 0x9b */ ESCAPES_FIRST+0x1a, /* 0x9c */ ESCAPES_FIRST+0x1b, - /* 0x9d */ ESCAPES_FIRST+0x1c, /* 0x9e */ ESCAPES_FIRST+0x1d, - /* 0x9f */ ESCAPES_FIRST+0x1e, /* 0xa0 */ ESCAPES_FIRST+0x1f, - /* 0xa1 */ ESCAPES_FIRST+0x20, /* 0xa2 s */ -ESC_s, - /* 0xa3 t */ CHAR_HT, /* 0xa4 u */ 0, - /* 0xa5 v */ -ESC_v, /* 0xa6 w */ -ESC_w, - /* 0xa7 x */ 0, /* 0xa8 y */ 0, - /* 0xa9 z */ -ESC_z, /* 0xaa */ ESCAPES_FIRST+0x29, - /* 0xab */ ESCAPES_FIRST+0x2a, /* 0xac */ ESCAPES_FIRST+0x2b, - /* 0xad */ ESCAPES_FIRST+0x2c, /* 0xae */ ESCAPES_FIRST+0x2d, - /* 0xaf */ ESCAPES_FIRST+0x2e, /* 0xb0 */ ESCAPES_FIRST+0x2f, - /* 0xb1 */ ESCAPES_FIRST+0x30, /* 0xb2 */ ESCAPES_FIRST+0x31, - /* 0xb3 */ ESCAPES_FIRST+0x32, /* 0xb4 */ ESCAPES_FIRST+0x33, - /* 0xb5 */ ESCAPES_FIRST+0x34, /* 0xb6 */ ESCAPES_FIRST+0x35, - /* 0xb7 */ ESCAPES_FIRST+0x36, /* 0xb8 */ ESCAPES_FIRST+0x37, - /* 0xb9 */ ESCAPES_FIRST+0x38, /* 0xba */ ESCAPES_FIRST+0x39, - /* 0xbb */ ESCAPES_FIRST+0x3a, /* 0xbc */ ESCAPES_FIRST+0x3b, - /* 0xbd */ ESCAPES_FIRST+0x3c, /* 0xbe */ ESCAPES_FIRST+0x3d, - /* 0xbf */ ESCAPES_FIRST+0x3e, /* 0xc0 */ ESCAPES_FIRST+0x3f, - /* 0xc1 A */ -ESC_A, /* 0xc2 B */ -ESC_B, - /* 0xc3 C */ -ESC_C, /* 0xc4 D */ -ESC_D, - /* 0xc5 E */ -ESC_E, /* 0xc6 F */ 0, - /* 0xc7 G */ -ESC_G, /* 0xc8 H */ -ESC_H, - /* 0xc9 I */ 0, /* 0xca */ ESCAPES_FIRST+0x49, - /* 0xcb */ ESCAPES_FIRST+0x4a, /* 0xcc */ ESCAPES_FIRST+0x4b, - /* 0xcd */ ESCAPES_FIRST+0x4c, /* 0xce */ ESCAPES_FIRST+0x4d, - /* 0xcf */ ESCAPES_FIRST+0x4e, /* 0xd0 */ ESCAPES_FIRST+0x4f, - /* 0xd1 J */ 0, /* 0xd2 K */ -ESC_K, - /* 0xd3 L */ 0, /* 0xd4 M */ 0, - /* 0xd5 N */ -ESC_N, /* 0xd6 O */ 0, - /* 0xd7 P */ -ESC_P, /* 0xd8 Q */ -ESC_Q, - /* 0xd9 R */ -ESC_R, /* 0xda */ ESCAPES_FIRST+0x59, - /* 0xdb */ ESCAPES_FIRST+0x5a, /* 0xdc */ ESCAPES_FIRST+0x5b, - /* 0xdd */ ESCAPES_FIRST+0x5c, /* 0xde */ ESCAPES_FIRST+0x5d, - /* 0xdf */ ESCAPES_FIRST+0x5e, /* 0xe0 */ ESCAPES_FIRST+0x5f, - /* 0xe1 */ ESCAPES_FIRST+0x60, /* 0xe2 S */ -ESC_S, - /* 0xe3 T */ 0, /* 0xe4 U */ 0, - /* 0xe5 V */ -ESC_V, /* 0xe6 W */ -ESC_W, - /* 0xe7 X */ -ESC_X, /* 0xe8 Y */ 0, - /* 0xe9 Z */ -ESC_Z, /* 0xea */ ESCAPES_FIRST+0x69, - /* 0xeb */ ESCAPES_FIRST+0x6a, /* 0xec */ ESCAPES_FIRST+0x6b, - /* 0xed */ ESCAPES_FIRST+0x6c, /* 0xee */ ESCAPES_FIRST+0x6d, - /* 0xef */ ESCAPES_FIRST+0x6e, /* 0xf0 0 */ 0, - /* 0xf1 1 */ 0, /* 0xf2 2 */ 0, - /* 0xf3 3 */ 0, /* 0xf4 4 */ 0, - /* 0xf5 5 */ 0, /* 0xf6 6 */ 0, - /* 0xf7 7 */ 0, /* 0xf8 8 */ 0, - /* 0xf9 9 */ 0, -}; - -/* We also need a table of characters that may follow \c in an EBCDIC -environment for characters 0-31. */ - -static unsigned char ebcdic_escape_c[] = { - CHAR_COMMERCIAL_AT, CHAR_A, CHAR_B, CHAR_C, CHAR_D, CHAR_E, CHAR_F, CHAR_G, - CHAR_H, CHAR_I, CHAR_J, CHAR_K, CHAR_L, CHAR_M, CHAR_N, CHAR_O, CHAR_P, - CHAR_Q, CHAR_R, CHAR_S, CHAR_T, CHAR_U, CHAR_V, CHAR_W, CHAR_X, CHAR_Y, - CHAR_Z, CHAR_LEFT_SQUARE_BRACKET, CHAR_BACKSLASH, CHAR_RIGHT_SQUARE_BRACKET, - CHAR_CIRCUMFLEX_ACCENT, CHAR_UNDERSCORE -}; - -#endif /* EBCDIC */ - - -/* Table of special "verbs" like (*PRUNE). This is a short table, so it is -searched linearly. Put all the names into a single string, in order to reduce -the number of relocations when a shared library is dynamically linked. The -string is built from string macros so that it works in UTF-8 mode on EBCDIC -platforms. */ - -typedef struct verbitem { - unsigned int len; /* Length of verb name */ - uint32_t meta; /* Base META_ code */ - int has_arg; /* Argument requirement */ -} verbitem; - -static const char verbnames[] = - "\0" /* Empty name is a shorthand for MARK */ - STRING_MARK0 - STRING_ACCEPT0 - STRING_F0 - STRING_FAIL0 - STRING_COMMIT0 - STRING_PRUNE0 - STRING_SKIP0 - STRING_THEN; - -static const verbitem verbs[] = { - { 0, META_MARK, +1 }, /* > 0 => must have an argument */ - { 4, META_MARK, +1 }, - { 6, META_ACCEPT, -1 }, /* < 0 => Optional argument, convert to pre-MARK */ - { 1, META_FAIL, -1 }, - { 4, META_FAIL, -1 }, - { 6, META_COMMIT, 0 }, - { 5, META_PRUNE, 0 }, /* Optional argument; bump META code if found */ - { 4, META_SKIP, 0 }, - { 4, META_THEN, 0 } -}; - -static const int verbcount = sizeof(verbs)/sizeof(verbitem); - -/* Verb opcodes, indexed by their META code offset from META_MARK. */ - -static const uint32_t verbops[] = { - OP_MARK, OP_ACCEPT, OP_FAIL, OP_COMMIT, OP_COMMIT_ARG, OP_PRUNE, - OP_PRUNE_ARG, OP_SKIP, OP_SKIP_ARG, OP_THEN, OP_THEN_ARG }; - -/* Table of "alpha assertions" like (*pla:...), similar to the (*VERB) table. */ - -typedef struct alasitem { - unsigned int len; /* Length of name */ - uint32_t meta; /* Base META_ code */ -} alasitem; - -static const char alasnames[] = - STRING_pla0 - STRING_plb0 - STRING_napla0 - STRING_naplb0 - STRING_nla0 - STRING_nlb0 - STRING_positive_lookahead0 - STRING_positive_lookbehind0 - STRING_non_atomic_positive_lookahead0 - STRING_non_atomic_positive_lookbehind0 - STRING_negative_lookahead0 - STRING_negative_lookbehind0 - STRING_scs0 - STRING_scan_substring0 - STRING_atomic0 - STRING_sr0 - STRING_asr0 - STRING_script_run0 - STRING_atomic_script_run; - -static const alasitem alasmeta[] = { - { 3, META_LOOKAHEAD }, - { 3, META_LOOKBEHIND }, - { 5, META_LOOKAHEAD_NA }, - { 5, META_LOOKBEHIND_NA }, - { 3, META_LOOKAHEADNOT }, - { 3, META_LOOKBEHINDNOT }, - { 18, META_LOOKAHEAD }, - { 19, META_LOOKBEHIND }, - { 29, META_LOOKAHEAD_NA }, - { 30, META_LOOKBEHIND_NA }, - { 18, META_LOOKAHEADNOT }, - { 19, META_LOOKBEHINDNOT }, - { 3, META_SCS }, - { 14, META_SCS }, - { 6, META_ATOMIC }, - { 2, META_SCRIPT_RUN }, /* sr = script run */ - { 3, META_ATOMIC_SCRIPT_RUN }, /* asr = atomic script run */ - { 10, META_SCRIPT_RUN }, /* script run */ - { 17, META_ATOMIC_SCRIPT_RUN } /* atomic script run */ -}; - -static const int alascount = sizeof(alasmeta)/sizeof(alasitem); - -/* Offsets from OP_STAR for case-independent and negative repeat opcodes. */ - -static uint32_t chartypeoffset[] = { - OP_STAR - OP_STAR, OP_STARI - OP_STAR, - OP_NOTSTAR - OP_STAR, OP_NOTSTARI - OP_STAR }; - -/* Tables of names of POSIX character classes and their lengths. The names are -now all in a single string, to reduce the number of relocations when a shared -library is dynamically loaded. The list of lengths is terminated by a zero -length entry. The first three must be alpha, lower, upper, as this is assumed -for handling case independence. - -The indices for several classes are stored in pcre2_compile.h - these must -be kept in sync with posix_names, posix_name_lengths, posix_class_maps, -and posix_substitutes. */ - -static const char posix_names[] = - STRING_alpha0 STRING_lower0 STRING_upper0 STRING_alnum0 - STRING_ascii0 STRING_blank0 STRING_cntrl0 STRING_digit0 - STRING_graph0 STRING_print0 STRING_punct0 STRING_space0 - STRING_word0 STRING_xdigit; - -static const uint8_t posix_name_lengths[] = { - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 6, 0 }; - -/* Table of class bit maps for each POSIX class. Each class is formed from a -base map, with an optional addition or removal of another map. Then, for some -classes, there is some additional tweaking: for [:blank:] the vertical space -characters are removed, and for [:alpha:] and [:alnum:] the underscore -character is removed. The triples in the table consist of the base map offset, -second map offset or -1 if no second map, and a non-negative value for map -addition or a negative value for map subtraction (if there are two maps). The -absolute value of the third field has these meanings: 0 => no tweaking, 1 => -remove vertical space characters, 2 => remove underscore. */ - -const int PRIV(posix_class_maps)[] = { - cbit_word, cbit_digit, -2, /* alpha */ - cbit_lower, -1, 0, /* lower */ - cbit_upper, -1, 0, /* upper */ - cbit_word, -1, 2, /* alnum - word without underscore */ - cbit_print, cbit_cntrl, 0, /* ascii */ - cbit_space, -1, 1, /* blank - a GNU extension */ - cbit_cntrl, -1, 0, /* cntrl */ - cbit_digit, -1, 0, /* digit */ - cbit_graph, -1, 0, /* graph */ - cbit_print, -1, 0, /* print */ - cbit_punct, -1, 0, /* punct */ - cbit_space, -1, 0, /* space */ - cbit_word, -1, 0, /* word - a Perl extension */ - cbit_xdigit, -1, 0 /* xdigit */ -}; - -#ifdef SUPPORT_UNICODE - -/* The POSIX class Unicode property substitutes that are used in UCP mode must -be in the order of the POSIX class names, defined above. */ - -static int posix_substitutes[] = { - PT_GC, ucp_L, /* alpha */ - PT_PC, ucp_Ll, /* lower */ - PT_PC, ucp_Lu, /* upper */ - PT_ALNUM, 0, /* alnum */ - -1, 0, /* ascii, treat as non-UCP */ - -1, 1, /* blank, treat as \h */ - PT_PC, ucp_Cc, /* cntrl */ - PT_PC, ucp_Nd, /* digit */ - PT_PXGRAPH, 0, /* graph */ - PT_PXPRINT, 0, /* print */ - PT_PXPUNCT, 0, /* punct */ - PT_PXSPACE, 0, /* space */ /* Xps is POSIX space, but from 8.34 */ - PT_WORD, 0, /* word */ /* Perl and POSIX space are the same */ - PT_PXXDIGIT, 0 /* xdigit */ /* Perl has additional hex digits */ -}; -#endif /* SUPPORT_UNICODE */ - -/* Masks for checking option settings. When PCRE2_LITERAL is set, only a subset -are allowed. */ - -#define PUBLIC_LITERAL_COMPILE_OPTIONS \ - (PCRE2_ANCHORED|PCRE2_AUTO_CALLOUT|PCRE2_CASELESS|PCRE2_ENDANCHORED| \ - PCRE2_FIRSTLINE|PCRE2_LITERAL|PCRE2_MATCH_INVALID_UTF| \ - PCRE2_NO_START_OPTIMIZE|PCRE2_NO_UTF_CHECK|PCRE2_USE_OFFSET_LIMIT|PCRE2_UTF) - -#define PUBLIC_COMPILE_OPTIONS \ - (PUBLIC_LITERAL_COMPILE_OPTIONS| \ - PCRE2_ALLOW_EMPTY_CLASS|PCRE2_ALT_BSUX|PCRE2_ALT_CIRCUMFLEX| \ - PCRE2_ALT_VERBNAMES|PCRE2_DOLLAR_ENDONLY|PCRE2_DOTALL|PCRE2_DUPNAMES| \ - PCRE2_EXTENDED|PCRE2_EXTENDED_MORE|PCRE2_MATCH_UNSET_BACKREF| \ - PCRE2_MULTILINE|PCRE2_NEVER_BACKSLASH_C|PCRE2_NEVER_UCP| \ - PCRE2_NEVER_UTF|PCRE2_NO_AUTO_CAPTURE|PCRE2_NO_AUTO_POSSESS| \ - PCRE2_NO_DOTSTAR_ANCHOR|PCRE2_UCP|PCRE2_UNGREEDY|PCRE2_ALT_EXTENDED_CLASS) - -#define PUBLIC_LITERAL_COMPILE_EXTRA_OPTIONS \ - (PCRE2_EXTRA_MATCH_LINE|PCRE2_EXTRA_MATCH_WORD| \ - PCRE2_EXTRA_CASELESS_RESTRICT|PCRE2_EXTRA_TURKISH_CASING) - -#define PUBLIC_COMPILE_EXTRA_OPTIONS \ - (PUBLIC_LITERAL_COMPILE_EXTRA_OPTIONS| \ - PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES|PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL| \ - PCRE2_EXTRA_ESCAPED_CR_IS_LF|PCRE2_EXTRA_ALT_BSUX| \ - PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK|PCRE2_EXTRA_ASCII_BSD| \ - PCRE2_EXTRA_ASCII_BSS|PCRE2_EXTRA_ASCII_BSW|PCRE2_EXTRA_ASCII_POSIX| \ - PCRE2_EXTRA_ASCII_DIGIT|PCRE2_EXTRA_PYTHON_OCTAL|PCRE2_EXTRA_NO_BS0| \ - PCRE2_EXTRA_NEVER_CALLOUT) - -/* This is a table of start-of-pattern options such as (*UTF) and settings such -as (*LIMIT_MATCH=nnnn) and (*CRLF). For completeness and backward -compatibility, (*UTFn) is supported in the relevant libraries, but (*UTF) is -generic and always supported. */ - -enum { PSO_OPT, /* Value is an option bit */ - PSO_XOPT, /* Value is an xoption bit */ - PSO_FLG, /* Value is a flag bit */ - PSO_NL, /* Value is a newline type */ - PSO_BSR, /* Value is a \R type */ - PSO_LIMH, /* Read integer value for heap limit */ - PSO_LIMM, /* Read integer value for match limit */ - PSO_LIMD, /* Read integer value for depth limit */ - PSO_OPTMZ /* Value is an optimization bit */ - }; - -typedef struct pso { - const char *name; - uint16_t length; - uint16_t type; - uint32_t value; -} pso; - -/* NB: STRING_UTFn_RIGHTPAR contains the length as well */ - -static const pso pso_list[] = { - { STRING_UTFn_RIGHTPAR, PSO_OPT, PCRE2_UTF }, - { STRING_UTF_RIGHTPAR, 4, PSO_OPT, PCRE2_UTF }, - { STRING_UCP_RIGHTPAR, 4, PSO_OPT, PCRE2_UCP }, - { STRING_NOTEMPTY_RIGHTPAR, 9, PSO_FLG, PCRE2_NOTEMPTY_SET }, - { STRING_NOTEMPTY_ATSTART_RIGHTPAR, 17, PSO_FLG, PCRE2_NE_ATST_SET }, - { STRING_NO_AUTO_POSSESS_RIGHTPAR, 16, PSO_OPTMZ, PCRE2_OPTIM_AUTO_POSSESS }, - { STRING_NO_DOTSTAR_ANCHOR_RIGHTPAR, 18, PSO_OPTMZ, PCRE2_OPTIM_DOTSTAR_ANCHOR }, - { STRING_NO_JIT_RIGHTPAR, 7, PSO_FLG, PCRE2_NOJIT }, - { STRING_NO_START_OPT_RIGHTPAR, 13, PSO_OPTMZ, PCRE2_OPTIM_START_OPTIMIZE }, - { STRING_CASELESS_RESTRICT_RIGHTPAR, 18, PSO_XOPT, PCRE2_EXTRA_CASELESS_RESTRICT }, - { STRING_TURKISH_CASING_RIGHTPAR, 15, PSO_XOPT, PCRE2_EXTRA_TURKISH_CASING }, - { STRING_LIMIT_HEAP_EQ, 11, PSO_LIMH, 0 }, - { STRING_LIMIT_MATCH_EQ, 12, PSO_LIMM, 0 }, - { STRING_LIMIT_DEPTH_EQ, 12, PSO_LIMD, 0 }, - { STRING_LIMIT_RECURSION_EQ, 16, PSO_LIMD, 0 }, - { STRING_CR_RIGHTPAR, 3, PSO_NL, PCRE2_NEWLINE_CR }, - { STRING_LF_RIGHTPAR, 3, PSO_NL, PCRE2_NEWLINE_LF }, - { STRING_CRLF_RIGHTPAR, 5, PSO_NL, PCRE2_NEWLINE_CRLF }, - { STRING_ANY_RIGHTPAR, 4, PSO_NL, PCRE2_NEWLINE_ANY }, - { STRING_NUL_RIGHTPAR, 4, PSO_NL, PCRE2_NEWLINE_NUL }, - { STRING_ANYCRLF_RIGHTPAR, 8, PSO_NL, PCRE2_NEWLINE_ANYCRLF }, - { STRING_BSR_ANYCRLF_RIGHTPAR, 12, PSO_BSR, PCRE2_BSR_ANYCRLF }, - { STRING_BSR_UNICODE_RIGHTPAR, 12, PSO_BSR, PCRE2_BSR_UNICODE } -}; - -/* This table is used when converting repeating opcodes into possessified -versions as a result of an explicit possessive quantifier such as ++. A zero -value means there is no possessified version - in those cases the item in -question must be wrapped in ONCE brackets. The table is truncated at OP_CALLOUT -because all relevant opcodes are less than that. */ - -static const uint8_t opcode_possessify[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 - 15 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16 - 31 */ - - 0, /* NOTI */ - OP_POSSTAR, 0, /* STAR, MINSTAR */ - OP_POSPLUS, 0, /* PLUS, MINPLUS */ - OP_POSQUERY, 0, /* QUERY, MINQUERY */ - OP_POSUPTO, 0, /* UPTO, MINUPTO */ - 0, /* EXACT */ - 0, 0, 0, 0, /* POS{STAR,PLUS,QUERY,UPTO} */ - - OP_POSSTARI, 0, /* STARI, MINSTARI */ - OP_POSPLUSI, 0, /* PLUSI, MINPLUSI */ - OP_POSQUERYI, 0, /* QUERYI, MINQUERYI */ - OP_POSUPTOI, 0, /* UPTOI, MINUPTOI */ - 0, /* EXACTI */ - 0, 0, 0, 0, /* POS{STARI,PLUSI,QUERYI,UPTOI} */ - - OP_NOTPOSSTAR, 0, /* NOTSTAR, NOTMINSTAR */ - OP_NOTPOSPLUS, 0, /* NOTPLUS, NOTMINPLUS */ - OP_NOTPOSQUERY, 0, /* NOTQUERY, NOTMINQUERY */ - OP_NOTPOSUPTO, 0, /* NOTUPTO, NOTMINUPTO */ - 0, /* NOTEXACT */ - 0, 0, 0, 0, /* NOTPOS{STAR,PLUS,QUERY,UPTO} */ - - OP_NOTPOSSTARI, 0, /* NOTSTARI, NOTMINSTARI */ - OP_NOTPOSPLUSI, 0, /* NOTPLUSI, NOTMINPLUSI */ - OP_NOTPOSQUERYI, 0, /* NOTQUERYI, NOTMINQUERYI */ - OP_NOTPOSUPTOI, 0, /* NOTUPTOI, NOTMINUPTOI */ - 0, /* NOTEXACTI */ - 0, 0, 0, 0, /* NOTPOS{STARI,PLUSI,QUERYI,UPTOI} */ - - OP_TYPEPOSSTAR, 0, /* TYPESTAR, TYPEMINSTAR */ - OP_TYPEPOSPLUS, 0, /* TYPEPLUS, TYPEMINPLUS */ - OP_TYPEPOSQUERY, 0, /* TYPEQUERY, TYPEMINQUERY */ - OP_TYPEPOSUPTO, 0, /* TYPEUPTO, TYPEMINUPTO */ - 0, /* TYPEEXACT */ - 0, 0, 0, 0, /* TYPEPOS{STAR,PLUS,QUERY,UPTO} */ - - OP_CRPOSSTAR, 0, /* CRSTAR, CRMINSTAR */ - OP_CRPOSPLUS, 0, /* CRPLUS, CRMINPLUS */ - OP_CRPOSQUERY, 0, /* CRQUERY, CRMINQUERY */ - OP_CRPOSRANGE, 0, /* CRRANGE, CRMINRANGE */ - 0, 0, 0, 0, /* CRPOS{STAR,PLUS,QUERY,RANGE} */ - - 0, 0, 0, 0, /* CLASS, NCLASS, XCLASS, ECLASS */ - 0, 0, /* REF, REFI */ - 0, 0, /* DNREF, DNREFI */ - 0, 0, /* RECURSE, CALLOUT */ -}; - -/* Compile-time check that the table has the correct size. */ -STATIC_ASSERT(sizeof(opcode_possessify) == OP_CALLOUT+1, opcode_possessify); - - -#ifdef DEBUG_SHOW_PARSED -/************************************************* -* Show the parsed pattern for debugging * -*************************************************/ - -/* For debugging the pre-scan, this code, which outputs the parsed data vector, -can be enabled. */ - -static void show_parsed(compile_block *cb) -{ -uint32_t *pptr = cb->parsed_pattern; - -for (;;) - { - int max, min; - PCRE2_SIZE offset; - uint32_t i; - uint32_t length; - uint32_t meta_arg = META_DATA(*pptr); - - fprintf(stderr, "+++ %02d %.8x ", (int)(pptr - cb->parsed_pattern), *pptr); - - if (*pptr < META_END) - { - if (*pptr > 32 && *pptr < 128) fprintf(stderr, "%c", *pptr); - pptr++; - } - - else switch (META_CODE(*pptr++)) - { - default: - fprintf(stderr, "**** OOPS - unknown META value - giving up ****\n"); - return; - - case META_END: - fprintf(stderr, "META_END\n"); - return; - - case META_CAPTURE: - fprintf(stderr, "META_CAPTURE %d", meta_arg); - break; - - case META_RECURSE: - GETOFFSET(offset, pptr); - fprintf(stderr, "META_RECURSE %d %zd", meta_arg, offset); - break; - - case META_BACKREF: - if (meta_arg < 10) - offset = cb->small_ref_offset[meta_arg]; - else - GETOFFSET(offset, pptr); - fprintf(stderr, "META_BACKREF %d %zd", meta_arg, offset); - break; - - case META_ESCAPE: - if (meta_arg == ESC_P || meta_arg == ESC_p) - { - uint32_t ptype = *pptr >> 16; - uint32_t pvalue = *pptr++ & 0xffff; - fprintf(stderr, "META \\%c %d %d", (meta_arg == ESC_P)? CHAR_P:CHAR_p, - ptype, pvalue); - } - else - { - uint32_t cc; - /* There's just one escape we might have here that isn't negated in the - escapes table. */ - if (meta_arg == ESC_g) cc = CHAR_g; - else for (cc = ESCAPES_FIRST; cc <= ESCAPES_LAST; cc++) - { - if (meta_arg == (uint32_t)(-escapes[cc - ESCAPES_FIRST])) break; - } - if (cc > ESCAPES_LAST) cc = CHAR_QUESTION_MARK; - fprintf(stderr, "META \\%c", cc); - } - break; - - case META_MINMAX: - min = *pptr++; - max = *pptr++; - if (max != REPEAT_UNLIMITED) - fprintf(stderr, "META {%d,%d}", min, max); - else - fprintf(stderr, "META {%d,}", min); - break; - - case META_MINMAX_QUERY: - min = *pptr++; - max = *pptr++; - if (max != REPEAT_UNLIMITED) - fprintf(stderr, "META {%d,%d}?", min, max); - else - fprintf(stderr, "META {%d,}?", min); - break; - - case META_MINMAX_PLUS: - min = *pptr++; - max = *pptr++; - if (max != REPEAT_UNLIMITED) - fprintf(stderr, "META {%d,%d}+", min, max); - else - fprintf(stderr, "META {%d,}+", min); - break; - - case META_BIGVALUE: fprintf(stderr, "META_BIGVALUE %.8x", *pptr++); break; - case META_CIRCUMFLEX: fprintf(stderr, "META_CIRCUMFLEX"); break; - case META_COND_ASSERT: fprintf(stderr, "META_COND_ASSERT"); break; - case META_DOLLAR: fprintf(stderr, "META_DOLLAR"); break; - case META_DOT: fprintf(stderr, "META_DOT"); break; - case META_ASTERISK: fprintf(stderr, "META *"); break; - case META_ASTERISK_QUERY: fprintf(stderr, "META *?"); break; - case META_ASTERISK_PLUS: fprintf(stderr, "META *+"); break; - case META_PLUS: fprintf(stderr, "META +"); break; - case META_PLUS_QUERY: fprintf(stderr, "META +?"); break; - case META_PLUS_PLUS: fprintf(stderr, "META ++"); break; - case META_QUERY: fprintf(stderr, "META ?"); break; - case META_QUERY_QUERY: fprintf(stderr, "META ??"); break; - case META_QUERY_PLUS: fprintf(stderr, "META ?+"); break; - - case META_ATOMIC: fprintf(stderr, "META (?>"); break; - case META_NOCAPTURE: fprintf(stderr, "META (?:"); break; - case META_LOOKAHEAD: fprintf(stderr, "META (?="); break; - case META_LOOKAHEADNOT: fprintf(stderr, "META (?!"); break; - case META_LOOKAHEAD_NA: fprintf(stderr, "META (*napla:"); break; - case META_SCRIPT_RUN: fprintf(stderr, "META (*sr:"); break; - case META_KET: fprintf(stderr, "META )"); break; - case META_ALT: fprintf(stderr, "META | %d", meta_arg); break; - - case META_CLASS: fprintf(stderr, "META ["); break; - case META_CLASS_NOT: fprintf(stderr, "META [^"); break; - case META_CLASS_END: fprintf(stderr, "META ]"); break; - case META_CLASS_EMPTY: fprintf(stderr, "META []"); break; - case META_CLASS_EMPTY_NOT: fprintf(stderr, "META [^]"); break; - - case META_RANGE_LITERAL: fprintf(stderr, "META - (literal)"); break; - case META_RANGE_ESCAPED: fprintf(stderr, "META - (escaped)"); break; - - case META_POSIX: fprintf(stderr, "META_POSIX %d", *pptr++); break; - case META_POSIX_NEG: fprintf(stderr, "META_POSIX_NEG %d", *pptr++); break; - - case META_ACCEPT: fprintf(stderr, "META (*ACCEPT)"); break; - case META_FAIL: fprintf(stderr, "META (*FAIL)"); break; - case META_COMMIT: fprintf(stderr, "META (*COMMIT)"); break; - case META_PRUNE: fprintf(stderr, "META (*PRUNE)"); break; - case META_SKIP: fprintf(stderr, "META (*SKIP)"); break; - case META_THEN: fprintf(stderr, "META (*THEN)"); break; - - case META_OPTIONS: - fprintf(stderr, "META_OPTIONS 0x%08x 0x%08x", pptr[0], pptr[1]); - pptr += 2; - break; - - case META_LOOKBEHIND: - fprintf(stderr, "META (?<= %d %d", meta_arg, *pptr); - pptr += 2; - break; - - case META_LOOKBEHIND_NA: - fprintf(stderr, "META (*naplb: %d %d", meta_arg, *pptr); - pptr += 2; - break; - - case META_LOOKBEHINDNOT: - fprintf(stderr, "META (?="); - fprintf(stderr, "%d.", *pptr++); - fprintf(stderr, "%d)", *pptr++); - break; - - case META_COND_NAME: - fprintf(stderr, "META (?() length=%d offset=", *pptr++); - GETOFFSET(offset, pptr); - fprintf(stderr, "%zd", offset); - break; - - case META_COND_RNAME: - fprintf(stderr, "META (?(R&name) length=%d offset=", *pptr++); - GETOFFSET(offset, pptr); - fprintf(stderr, "%zd", offset); - break; - - /* This is kept as a name, because it might be. */ - - case META_COND_RNUMBER: - fprintf(stderr, "META (?(Rnumber) length=%d offset=", *pptr++); - GETOFFSET(offset, pptr); - fprintf(stderr, "%zd", offset); - break; - - case META_OFFSET: - fprintf(stderr, "META_OFFSET offset="); - GETOFFSET(offset, pptr); - fprintf(stderr, "%zd", offset); - break; - - case META_SCS: - fprintf(stderr, "META (*scan_substring:"); - break; - - case META_CAPTURE_NAME: - fprintf(stderr, "META_CAPTURE_NAME length=%d relative_offset=%d", *pptr++, (int)meta_arg); - break; - - case META_CAPTURE_NUMBER: - fprintf(stderr, "META_CAPTURE_NUMBER %d relative_offset=%d", *pptr++, (int)meta_arg); - break; - - case META_MARK: - fprintf(stderr, "META (*MARK:"); - goto SHOWARG; - - case META_COMMIT_ARG: - fprintf(stderr, "META (*COMMIT:"); - goto SHOWARG; - - case META_PRUNE_ARG: - fprintf(stderr, "META (*PRUNE:"); - goto SHOWARG; - - case META_SKIP_ARG: - fprintf(stderr, "META (*SKIP:"); - goto SHOWARG; - - case META_THEN_ARG: - fprintf(stderr, "META (*THEN:"); - SHOWARG: - length = *pptr++; - for (i = 0; i < length; i++) - { - uint32_t cc = *pptr++; - if (cc > 32 && cc < 128) fprintf(stderr, "%c", cc); - else fprintf(stderr, "\\x{%x}", cc); - } - fprintf(stderr, ") length=%u", length); - break; - - case META_ECLASS_AND: fprintf(stderr, "META_ECLASS_AND"); break; - case META_ECLASS_OR: fprintf(stderr, "META_ECLASS_OR"); break; - case META_ECLASS_SUB: fprintf(stderr, "META_ECLASS_SUB"); break; - case META_ECLASS_XOR: fprintf(stderr, "META_ECLASS_XOR"); break; - case META_ECLASS_NOT: fprintf(stderr, "META_ECLASS_NOT"); break; - } - fprintf(stderr, "\n"); - } -return; -} -#endif /* DEBUG_SHOW_PARSED */ - - - -/************************************************* -* Copy compiled code * -*************************************************/ - -/* Compiled JIT code cannot be copied, so the new compiled block has no -associated JIT data. */ - -PCRE2_EXP_DEFN pcre2_code * PCRE2_CALL_CONVENTION -pcre2_code_copy(const pcre2_code *code) -{ -PCRE2_SIZE *ref_count; -pcre2_code *newcode; - -if (code == NULL) return NULL; -newcode = code->memctl.malloc(code->blocksize, code->memctl.memory_data); -if (newcode == NULL) return NULL; -memcpy(newcode, code, code->blocksize); -newcode->executable_jit = NULL; - -/* If the code is one that has been deserialized, increment the reference count -in the decoded tables. */ - -if ((code->flags & PCRE2_DEREF_TABLES) != 0) - { - ref_count = (PCRE2_SIZE *)(code->tables + TABLES_LENGTH); - (*ref_count)++; - } - -return newcode; -} - - - -/************************************************* -* Copy compiled code and character tables * -*************************************************/ - -/* Compiled JIT code cannot be copied, so the new compiled block has no -associated JIT data. This version of code_copy also makes a separate copy of -the character tables. */ - -PCRE2_EXP_DEFN pcre2_code * PCRE2_CALL_CONVENTION -pcre2_code_copy_with_tables(const pcre2_code *code) -{ -PCRE2_SIZE* ref_count; -pcre2_code *newcode; -uint8_t *newtables; - -if (code == NULL) return NULL; -newcode = code->memctl.malloc(code->blocksize, code->memctl.memory_data); -if (newcode == NULL) return NULL; -memcpy(newcode, code, code->blocksize); -newcode->executable_jit = NULL; - -newtables = code->memctl.malloc(TABLES_LENGTH + sizeof(PCRE2_SIZE), - code->memctl.memory_data); -if (newtables == NULL) - { - code->memctl.free((void *)newcode, code->memctl.memory_data); - return NULL; - } -memcpy(newtables, code->tables, TABLES_LENGTH); -ref_count = (PCRE2_SIZE *)(newtables + TABLES_LENGTH); -*ref_count = 1; - -newcode->tables = newtables; -newcode->flags |= PCRE2_DEREF_TABLES; -return newcode; -} - - - -/************************************************* -* Free compiled code * -*************************************************/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_code_free(pcre2_code *code) -{ -PCRE2_SIZE* ref_count; - -if (code != NULL) - { -#ifdef SUPPORT_JIT - if (code->executable_jit != NULL) - PRIV(jit_free)(code->executable_jit, &code->memctl); -#endif - - if ((code->flags & PCRE2_DEREF_TABLES) != 0) - { - /* Decoded tables belong to the codes after deserialization, and they must - be freed when there are no more references to them. The *ref_count should - always be > 0. */ - - ref_count = (PCRE2_SIZE *)(code->tables + TABLES_LENGTH); - if (*ref_count > 0) - { - (*ref_count)--; - if (*ref_count == 0) - code->memctl.free((void *)code->tables, code->memctl.memory_data); - } - } - - code->memctl.free(code, code->memctl.memory_data); - } -} - - - -/************************************************* -* Read a number, possibly signed * -*************************************************/ - -/* This function is used to read numbers in the pattern. The initial pointer -must be at the sign or first digit of the number. When relative values -(introduced by + or -) are allowed, they are relative group numbers, and the -result must be greater than zero. - -Arguments: - ptrptr points to the character pointer variable - ptrend points to the end of the input string - allow_sign if < 0, sign not allowed; if >= 0, sign is relative to this - max_value the largest number allowed; - you must not pass a value for max_value larger than - INT_MAX/10 - 1 because this function relies on max_value to - avoid integer overflow - max_error the error to give for an over-large number - intptr where to put the result - errcodeptr where to put an error code - -Returns: TRUE - a number was read - FALSE - errorcode == 0 => no number was found - errorcode != 0 => an error occurred -*/ - -static BOOL -read_number(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, int32_t allow_sign, - uint32_t max_value, uint32_t max_error, int *intptr, int *errorcodeptr) -{ -int sign = 0; -uint32_t n = 0; -PCRE2_SPTR ptr = *ptrptr; -BOOL yield = FALSE; - -PCRE2_ASSERT(max_value <= INT_MAX/10 - 1); - -*errorcodeptr = 0; - -if (allow_sign >= 0 && ptr < ptrend) - { - if (*ptr == CHAR_PLUS) - { - sign = +1; - max_value -= allow_sign; - ptr++; - } - else if (*ptr == CHAR_MINUS) - { - sign = -1; - ptr++; - } - } - -if (ptr >= ptrend || !IS_DIGIT(*ptr)) return FALSE; -while (ptr < ptrend && IS_DIGIT(*ptr)) - { - n = n * 10 + (*ptr++ - CHAR_0); - if (n > max_value) - { - *errorcodeptr = max_error; - while (ptr < ptrend && IS_DIGIT(*ptr)) ptr++; - goto EXIT; - } - } - -if (allow_sign >= 0 && sign != 0) - { - if (n == 0) - { - *errorcodeptr = ERR26; /* +0 and -0 are not allowed */ - goto EXIT; - } - - if (sign > 0) n += allow_sign; - else if (n > (uint32_t)allow_sign) - { - *errorcodeptr = ERR15; /* Non-existent subpattern */ - goto EXIT; - } - else n = allow_sign + 1 - n; - } - -yield = TRUE; - -EXIT: -*intptr = n; -*ptrptr = ptr; -return yield; -} - - - -/************************************************* -* Read repeat counts * -*************************************************/ - -/* Read an item of the form {n,m} and return the values when non-NULL pointers -are supplied. Repeat counts must be less than 65536 (MAX_REPEAT_COUNT); a -larger value is used for "unlimited". We have to use signed arguments for -read_number() because it is capable of returning a signed value. As of Perl -5.34.0 either n or m may be absent, but not both. Perl also allows spaces and -tabs after { and before } and between the numbers and the comma, so we do too. - -Arguments: - ptrptr points to pointer to character after '{' - ptrend pointer to end of input - minp if not NULL, pointer to int for min - maxp if not NULL, pointer to int for max - errorcodeptr points to error code variable - -Returns: FALSE if not a repeat quantifier, errorcode set zero - FALSE on error, with errorcode set non-zero - TRUE on success, with pointer updated to point after '}' -*/ - -static BOOL -read_repeat_counts(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, uint32_t *minp, - uint32_t *maxp, int *errorcodeptr) -{ -PCRE2_SPTR p = *ptrptr; -PCRE2_SPTR pp; -BOOL yield = FALSE; -BOOL had_minimum = FALSE; -int32_t min = 0; -int32_t max = REPEAT_UNLIMITED; /* This value is larger than MAX_REPEAT_COUNT */ - -*errorcodeptr = 0; -while (p < ptrend && (*p == CHAR_SPACE || *p == CHAR_HT)) p++; - -/* Check the syntax before interpreting. Otherwise, a non-quantifier sequence -such as "X{123456ABC" would incorrectly give a "number too big in quantifier" -error. */ - -pp = p; -if (pp < ptrend && IS_DIGIT(*pp)) - { - had_minimum = TRUE; - while (++pp < ptrend && IS_DIGIT(*pp)) {} - } - -while (pp < ptrend && (*pp == CHAR_SPACE || *pp == CHAR_HT)) pp++; -if (pp >= ptrend) return FALSE; - -if (*pp == CHAR_RIGHT_CURLY_BRACKET) - { - if (!had_minimum) return FALSE; - } -else - { - if (*pp++ != CHAR_COMMA) return FALSE; - while (pp < ptrend && (*pp == CHAR_SPACE || *pp == CHAR_HT)) pp++; - if (pp >= ptrend) return FALSE; - if (IS_DIGIT(*pp)) - { - while (++pp < ptrend && IS_DIGIT(*pp)) {} - } - else if (!had_minimum) return FALSE; - while (pp < ptrend && (*pp == CHAR_SPACE || *pp == CHAR_HT)) pp++; - if (pp >= ptrend || *pp != CHAR_RIGHT_CURLY_BRACKET) return FALSE; - } - -/* Now process the quantifier for real. We know it must be {n} or {n,} or {,m} -or {n,m}. The only error that read_number() can return is for a number that is -too big. If *errorcodeptr is returned as zero it means no number was found. */ - -/* Deal with {,m} or n too big. If we successfully read m there is no need to -check m >= n because n defaults to zero. */ - -if (!read_number(&p, ptrend, -1, MAX_REPEAT_COUNT, ERR5, &min, errorcodeptr)) - { - if (*errorcodeptr != 0) goto EXIT; /* n too big */ - p++; /* Skip comma and subsequent spaces */ - while (p < ptrend && (*p == CHAR_SPACE || *p == CHAR_HT)) p++; - if (!read_number(&p, ptrend, -1, MAX_REPEAT_COUNT, ERR5, &max, errorcodeptr)) - { - if (*errorcodeptr != 0) goto EXIT; /* m too big */ - } - } - -/* Have read one number. Deal with {n} or {n,} or {n,m} */ - -else - { - while (p < ptrend && (*p == CHAR_SPACE || *p == CHAR_HT)) p++; - if (*p == CHAR_RIGHT_CURLY_BRACKET) - { - max = min; - } - else /* Handle {n,} or {n,m} */ - { - p++; /* Skip comma and subsequent spaces */ - while (p < ptrend && (*p == CHAR_SPACE || *p == CHAR_HT)) p++; - if (!read_number(&p, ptrend, -1, MAX_REPEAT_COUNT, ERR5, &max, errorcodeptr)) - { - if (*errorcodeptr != 0) goto EXIT; /* m too big */ - } - - if (max < min) - { - *errorcodeptr = ERR4; - goto EXIT; - } - } - } - -/* Valid quantifier exists */ - -while (p < ptrend && (*p == CHAR_SPACE || *p == CHAR_HT)) p++; -p++; -yield = TRUE; -if (minp != NULL) *minp = (uint32_t)min; -if (maxp != NULL) *maxp = (uint32_t)max; - -/* Update the pattern pointer */ - -EXIT: -*ptrptr = p; -return yield; -} - - - -/************************************************* -* Handle escapes * -*************************************************/ - -/* This function is called when a \ has been encountered. It either returns a -positive value for a simple escape such as \d, or 0 for a data character, which -is placed in chptr. A backreference to group n is returned as -(n+1). On -entry, ptr is pointing at the character after \. On exit, it points after the -final code unit of the escape sequence. - -This function is also called from pcre2_substitute() to handle escape sequences -in replacement strings. In this case, the cb argument is NULL, and in the case -of escapes that have further processing, only sequences that define a data -character are recognised. The options argument is the final value of the -compiled pattern's options. - -Arguments: - ptrptr points to the input position pointer - ptrend points to the end of the input - chptr points to a returned data character - errorcodeptr points to the errorcode variable (containing zero) - options the current options bits - xoptions the current extra options bits - bracount the number of capturing parentheses encountered so far - isclass TRUE if in a character class - cb compile data block or NULL when called from pcre2_substitute() - -Returns: zero => a data character - positive => a special escape sequence - negative => a numerical back reference - on error, errorcodeptr is set non-zero -*/ - -int -PRIV(check_escape)(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, uint32_t *chptr, - int *errorcodeptr, uint32_t options, uint32_t xoptions, uint32_t bracount, - BOOL isclass, compile_block *cb) -{ -BOOL utf = (options & PCRE2_UTF) != 0; -BOOL alt_bsux = - ((options & PCRE2_ALT_BSUX) | (xoptions & PCRE2_EXTRA_ALT_BSUX)) != 0; -PCRE2_SPTR ptr = *ptrptr; -uint32_t c, cc; -int escape = 0; -int i; - -/* If backslash is at the end of the string, it's an error. */ - -if (ptr >= ptrend) - { - *errorcodeptr = ERR1; - return 0; - } - -GETCHARINCTEST(c, ptr); /* Get character value, increment pointer */ -*errorcodeptr = 0; /* Be optimistic */ - -/* Non-alphanumerics are literals, so we just leave the value in c. An initial -value test saves a memory lookup for code points outside the alphanumeric -range. */ - -if (c < ESCAPES_FIRST || c > ESCAPES_LAST) {} /* Definitely literal */ - -/* Otherwise, do a table lookup. Non-zero values need little processing here. A -positive value is a literal value for something like \n. A negative value is -the negation of one of the ESC_ macros that is passed back for handling by the -calling function. Some extra checking is needed for \N because only \N{U+dddd} -is supported. If the value is zero, further processing is handled below. */ - -else if ((i = escapes[c - ESCAPES_FIRST]) != 0) - { - if (i > 0) - { - c = (uint32_t)i; - if (c == CHAR_CR && (xoptions & PCRE2_EXTRA_ESCAPED_CR_IS_LF) != 0) - c = CHAR_LF; - } - else /* Negative table entry */ - { - escape = -i; /* Else return a special escape */ - if (cb != NULL && (escape == ESC_P || escape == ESC_p || escape == ESC_X)) - cb->external_flags |= PCRE2_HASBKPORX; /* Note \P, \p, or \X */ - - /* Perl supports \N{name} for character names and \N{U+dddd} for numerical - Unicode code points, as well as plain \N for "not newline". PCRE does not - support \N{name}. However, it does support quantification such as \N{2,3}, - so if \N{ is not followed by U+dddd we check for a quantifier. */ - - if (escape == ESC_N && ptr < ptrend && *ptr == CHAR_LEFT_CURLY_BRACKET) - { - PCRE2_SPTR p = ptr + 1; - - /* Perl ignores spaces and tabs after { */ - - while (p < ptrend && (*p == CHAR_SPACE || *p == CHAR_HT)) p++; - - /* \N{U+ can be handled by the \x{ code. However, this construction is - not valid in EBCDIC environments because it specifies a Unicode - character, not a codepoint in the local code. For example \N{U+0041} - must be "A" in all environments. Also, in Perl, \N{U+ forces Unicode - casing semantics for the entire pattern, so allow it only in UTF (i.e. - Unicode) mode. */ - - if (ptrend - p > 1 && *p == CHAR_U && p[1] == CHAR_PLUS) - { -#ifndef EBCDIC - if (utf) - { - ptr = p + 2; - escape = 0; /* Not a fancy escape after all */ - goto COME_FROM_NU; - } -#endif - - /* Improve error offset. */ - ptr = p + 2; - while (ptr < ptrend && XDIGIT(*ptr) != 0xff) ptr++; - while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; - if (ptr < ptrend && *ptr == CHAR_RIGHT_CURLY_BRACKET) ptr++; - - *errorcodeptr = ERR93; - } - - /* Give an error in contexts where quantifiers are not allowed - (character classes; substitution strings). */ - - else if (isclass || cb == NULL) - { - ptr++; /* Skip over the opening brace */ - *errorcodeptr = ERR37; - } - - /* Give an error if what follows is not a quantifier, but don't override - an error set by the quantifier reader (e.g. number overflow). */ - - else - { - if (!read_repeat_counts(&p, ptrend, NULL, NULL, errorcodeptr) && - *errorcodeptr == 0) - { - ptr++; /* Skip over the opening brace */ - *errorcodeptr = ERR37; - } - } - } - } - } - -/* Escapes that need further processing, including those that are unknown, have -a zero entry in the lookup table. When called from pcre2_substitute(), only \c, -\o, and \x are recognized (\u and \U can never appear as they are used for case -forcing). */ - -else - { - int s; - PCRE2_SPTR oldptr; - BOOL overflow; - - /* Filter calls from pcre2_substitute(). */ - - if (cb == NULL) - { - if (!(c >= CHAR_0 && c <= CHAR_9) && c != CHAR_c && c != CHAR_o && - c != CHAR_x && c != CHAR_g) - { - *errorcodeptr = ERR3; - goto EXIT; - } - alt_bsux = FALSE; /* Do not modify \x handling */ - } - - switch (c) - { - /* A number of Perl escapes are not handled by PCRE. We give an explicit - error. */ - - case CHAR_F: - case CHAR_l: - case CHAR_L: - *errorcodeptr = ERR37; - break; - - /* \u is unrecognized when neither PCRE2_ALT_BSUX nor PCRE2_EXTRA_ALT_BSUX - is set. Otherwise, \u must be followed by exactly four hex digits or, if - PCRE2_EXTRA_ALT_BSUX is set, by any number of hex digits in braces. - Otherwise it is a lowercase u letter. This gives some compatibility with - ECMAScript (aka JavaScript). Unlike other braced items, white space is NOT - allowed. When \u{ is not followed by hex digits, a special return is given - because otherwise \u{ 12} (for example) would be treated as u{12}. */ - - case CHAR_u: - if (!alt_bsux) - *errorcodeptr = ERR37; - else - { - uint32_t xc; - - if (ptr >= ptrend) break; - if (*ptr == CHAR_LEFT_CURLY_BRACKET && - (xoptions & PCRE2_EXTRA_ALT_BSUX) != 0) - { - PCRE2_SPTR hptr = ptr + 1; - - cc = 0; - while (hptr < ptrend && (xc = XDIGIT(*hptr)) != 0xff) - { - if ((cc & 0xf0000000) != 0) /* Test for 32-bit overflow */ - { - *errorcodeptr = ERR77; - ptr = hptr; /* Show where */ - break; /* *hptr != } will cause another break below */ - } - cc = (cc << 4) | xc; - hptr++; - } - - if (hptr == ptr + 1 || /* No hex digits */ - hptr >= ptrend || /* Hit end of input */ - *hptr != CHAR_RIGHT_CURLY_BRACKET) /* No } terminator */ - { - if (isclass) break; /* In a class, just treat as '\u' literal */ - escape = ESC_ub; /* Special return */ - ptr++; /* Skip { */ - break; /* Hex escape not recognized */ - } - - c = cc; /* Accept the code point */ - ptr = hptr + 1; - } - - else /* Must be exactly 4 hex digits */ - { - if (ptrend - ptr < 4) break; /* Less than 4 chars */ - if ((cc = XDIGIT(ptr[0])) == 0xff) break; /* Not a hex digit */ - if ((xc = XDIGIT(ptr[1])) == 0xff) break; /* Not a hex digit */ - cc = (cc << 4) | xc; - if ((xc = XDIGIT(ptr[2])) == 0xff) break; /* Not a hex digit */ - cc = (cc << 4) | xc; - if ((xc = XDIGIT(ptr[3])) == 0xff) break; /* Not a hex digit */ - c = (cc << 4) | xc; - ptr += 4; - } - - if (utf) - { - if (c > 0x10ffffU) *errorcodeptr = ERR77; - else - if (c >= 0xd800 && c <= 0xdfff && - (xoptions & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0) - *errorcodeptr = ERR73; - } - else if (c > MAX_NON_UTF_CHAR) *errorcodeptr = ERR77; - } - break; - - /* \U is unrecognized unless PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX is set, - in which case it is an upper case letter. */ - - case CHAR_U: - if (!alt_bsux) *errorcodeptr = ERR37; - break; - - /* In a character class, \g is just a literal "g". Outside a character - class, \g must be followed by one of a number of specific things: - - (1) A number, either plain or braced. If positive, it is an absolute - backreference. If negative, it is a relative backreference. This is a Perl - 5.10 feature. - - (2) Perl 5.10 also supports \g{name} as a reference to a named group. This - is part of Perl's movement towards a unified syntax for back references. As - this is synonymous with \k{name}, we fudge it up by pretending it really - was \k{name}. - - (3) For Oniguruma compatibility we also support \g followed by a name or a - number either in angle brackets or in single quotes. However, these are - (possibly recursive) subroutine calls, _not_ backreferences. We return - the ESC_g code. - - Summary: Return a negative number for a numerical back reference (offset - by 1), ESC_k for a named back reference, and ESC_g for a named or - numbered subroutine call. - - The above describes the \g behaviour inside patterns. Inside replacement - strings (pcre2_substitute) we support only \g for Python - compatibility. Return ESG_g for the named case, and -(num+1) for the - numbered case. - */ - - case CHAR_g: - if (isclass) break; - - if (ptr >= ptrend) - { - *errorcodeptr = ERR57; - break; - } - - if (cb == NULL) - { - PCRE2_SPTR p; - /* Substitution strings */ - if (*ptr != CHAR_LESS_THAN_SIGN) - { - *errorcodeptr = ERR57; - break; - } - - p = ptr + 1; - - if (!read_number(&p, ptrend, -1, MAX_GROUP_NUMBER, ERR61, &s, - errorcodeptr)) - { - if (*errorcodeptr == 0) escape = ESC_g; /* No number found */ - break; - } - - if (p >= ptrend || *p != CHAR_GREATER_THAN_SIGN) - { - ptr = p; - *errorcodeptr = ERR119; /* Missing terminator for number */ - break; - } - - /* This is the reason that back references are returned as -(s+1) rather - than just -s. In a pattern, \0 is not a back reference, but \g<0> is - valid in a substitution string, so this must be representable. */ - ptr = p + 1; - escape = -(s+1); - break; - } - - if (*ptr == CHAR_LESS_THAN_SIGN || *ptr == CHAR_APOSTROPHE) - { - escape = ESC_g; - break; - } - - /* If there is a brace delimiter, try to read a numerical reference. If - there isn't one, assume we have a name and treat it as \k. */ - - if (*ptr == CHAR_LEFT_CURLY_BRACKET) - { - PCRE2_SPTR p = ptr + 1; - - while (p < ptrend && (*p == CHAR_SPACE || *p == CHAR_HT)) p++; - if (!read_number(&p, ptrend, bracount, MAX_GROUP_NUMBER, ERR61, &s, - errorcodeptr)) - { - if (*errorcodeptr == 0) escape = ESC_k; /* No number found */ - break; - } - while (p < ptrend && (*p == CHAR_SPACE || *p == CHAR_HT)) p++; - - if (p >= ptrend || *p != CHAR_RIGHT_CURLY_BRACKET) - { - ptr = p; - *errorcodeptr = ERR119; /* Missing terminator for number */ - break; - } - ptr = p + 1; - } - - /* Read an undelimited number */ - - else - { - if (!read_number(&ptr, ptrend, bracount, MAX_GROUP_NUMBER, ERR61, &s, - errorcodeptr)) - { - if (*errorcodeptr == 0) *errorcodeptr = ERR57; /* No number found */ - break; - } - } - - if (s <= 0) - { - *errorcodeptr = ERR15; - break; - } - - escape = -(s+1); - break; - - /* The handling of escape sequences consisting of a string of digits - starting with one that is not zero is not straightforward. Perl has changed - over the years. Nowadays \g{} for backreferences and \o{} for octal are - recommended to avoid the ambiguities in the old syntax. - - Outside a character class, the digits are read as a decimal number. If the - number is less than 10, or if there are that many previous extracting left - brackets, it is a back reference. Otherwise, up to three octal digits are - read to form an escaped character code. Thus \123 is likely to be octal 123 - (cf \0123, which is octal 012 followed by the literal 3). This is the "Perl - style" of handling ambiguous octal/backrefences such as \12. - - There is an alternative disambiguation strategy, selected by - PCRE2_EXTRA_PYTHON_OCTAL, which follows Python's behaviour. An octal must - have either a leading zero, or exactly three octal digits; otherwise it's - a backreference. The disambiguation is stable, and does not depend on how - many capture groups are defined (it's simply an invalid backreference if - there is no corresponding capture group). Additionally, octal values above - \377 (\xff) are rejected. - - Inside a character class, \ followed by a digit is always either a literal - 8 or 9 or an octal number. */ - - case CHAR_1: case CHAR_2: case CHAR_3: case CHAR_4: case CHAR_5: - case CHAR_6: case CHAR_7: case CHAR_8: case CHAR_9: - - if (isclass) - { - /* Fall through to octal handling; never a backreference inside a class. */ - } - else if ((xoptions & PCRE2_EXTRA_PYTHON_OCTAL) != 0) - { - /* Python-style disambiguation. */ - if (ptr[-1] <= CHAR_7 && ptr + 1 < ptrend && ptr[0] >= CHAR_0 && - ptr[0] <= CHAR_7 && ptr[1] >= CHAR_0 && ptr[1] <= CHAR_7) - { - /* We peeked a three-digit octal, so fall through */ - } - else - { - /* We are at a digit, so the only possible error from read_number() is - a number that is too large. */ - ptr--; /* Back to the digit */ - - if (!read_number(&ptr, ptrend, -1, MAX_GROUP_NUMBER, 0, &s, errorcodeptr)) - { - *errorcodeptr = ERR61; - break; - } - - escape = -(s+1); - break; - } - } - else - { - /* Perl-style disambiguation. */ - oldptr = ptr; - ptr--; /* Back to the digit */ - - /* As we know we are at a digit, the only possible error from - read_number() is a number that is too large to be a group number. Because - that number might be still valid if read as an octal, errorcodeptr is not - set on failure and therefore a sentinel value of INT_MAX is used instead - of the original value, and will be used later to properly set the error, - if not falling through. */ - - if (!read_number(&ptr, ptrend, -1, MAX_GROUP_NUMBER, 0, &s, errorcodeptr)) - s = INT_MAX; - - /* \1 to \9 are always back references. \8x and \9x are too; \1x to \7x - are octal escapes if there are not that many previous captures. */ - - if (s < 10 || c >= CHAR_8 || (unsigned)s <= bracount) - { - /* s > MAX_GROUP_NUMBER should not be possible because of read_number(), - but we keep it just to be safe and because it will also catch the - sentinel value that was set on failure by that function. */ - - if ((unsigned)s > MAX_GROUP_NUMBER) - { - PCRE2_ASSERT(s == INT_MAX); - *errorcodeptr = ERR61; - } - else escape = -(s+1); /* Indicates a back reference */ - break; - } - - ptr = oldptr; /* Put the pointer back and fall through */ - } - - /* Handle a digit following \ when the number is not a back reference, or - we are within a character class. If the first digit is 8 or 9, Perl used to - generate a binary zero and then treat the digit as a following literal. At - least by Perl 5.18 this changed so as not to insert the binary zero. */ - - if (c >= CHAR_8) break; - - PCRE2_FALLTHROUGH /* Fall through */ - - /* \0 always starts an octal number, but we may drop through to here with a - larger first octal digit. The original code used just to take the least - significant 8 bits of octal numbers (I think this is what early Perls used - to do). Nowadays we allow for larger numbers in UTF-8 mode and 16/32-bit mode, - but no more than 3 octal digits. */ - - case CHAR_0: - c -= CHAR_0; - while(i++ < 2 && ptr < ptrend && *ptr >= CHAR_0 && *ptr <= CHAR_7) - c = c * 8 + *ptr++ - CHAR_0; - if (c > 0xff) - { - if ((xoptions & PCRE2_EXTRA_PYTHON_OCTAL) != 0) *errorcodeptr = ERR102; -#if PCRE2_CODE_UNIT_WIDTH == 8 - else if (!utf) *errorcodeptr = ERR51; -#endif - } - - /* PCRE2_EXTRA_NO_BS0 disables the NUL escape '\0' but doesn't affect - two- or three-character octal escapes \00 and \000, nor \x00. */ - - if ((xoptions & PCRE2_EXTRA_NO_BS0) != 0 && c == 0 && i == 1) - *errorcodeptr = ERR98; - break; - - /* \o is a relatively new Perl feature, supporting a more general way of - specifying character codes in octal. The only supported form is \o{ddd}, - with optional spaces or tabs after { and before }. */ - - case CHAR_o: - if (ptr >= ptrend || *ptr != CHAR_LEFT_CURLY_BRACKET) - { - *errorcodeptr = ERR55; - break; - } - ptr++; - - while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; - if (ptr >= ptrend || *ptr == CHAR_RIGHT_CURLY_BRACKET) - { - *errorcodeptr = ERR78; - break; - } - - c = 0; - overflow = FALSE; - while (ptr < ptrend && *ptr >= CHAR_0 && *ptr <= CHAR_7) - { - cc = *ptr++; - if (c == 0 && cc == CHAR_0) continue; /* Leading zeroes */ -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (c >= 0x20000000u) { overflow = TRUE; break; } -#endif - c = (c << 3) + (cc - CHAR_0); -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (c > (utf ? 0x10ffffU : 0xffU)) { overflow = TRUE; break; } -#elif PCRE2_CODE_UNIT_WIDTH == 16 - if (c > (utf ? 0x10ffffU : 0xffffU)) { overflow = TRUE; break; } -#elif PCRE2_CODE_UNIT_WIDTH == 32 - if (utf && c > 0x10ffffU) { overflow = TRUE; break; } -#endif - } - - while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; - - if (overflow) - { - while (ptr < ptrend && *ptr >= CHAR_0 && *ptr <= CHAR_7) ptr++; - *errorcodeptr = ERR34; - } - else if (utf && c >= 0xd800 && c <= 0xdfff && - (xoptions & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0) - { - *errorcodeptr = ERR73; - } - else if (ptr < ptrend && *ptr == CHAR_RIGHT_CURLY_BRACKET) - { - ptr++; - } - else - { - *errorcodeptr = ERR64; - goto ESCAPE_FAILED_FORWARD; - } - break; - - /* When PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX is set, \x must be followed - by two hexadecimal digits. Otherwise it is a lowercase x letter. */ - - case CHAR_x: - if (alt_bsux) - { - uint32_t xc; - if (ptrend - ptr < 2) break; /* Less than 2 characters */ - if ((cc = XDIGIT(ptr[0])) == 0xff) break; /* Not a hex digit */ - if ((xc = XDIGIT(ptr[1])) == 0xff) break; /* Not a hex digit */ - c = (cc << 4) | xc; - ptr += 2; - } - - /* Handle \x in Perl's style. \x{ddd} is a character code which can be - greater than 0xff in UTF-8 or non-8bit mode, but only if the ddd are hex - digits. If not, { used to be treated as a data character. However, Perl - seems to read hex digits up to the first non-such, and ignore the rest, so - that, for example \x{zz} matches a binary zero. This seems crazy, so PCRE - now gives an error. */ - - else - { - if (ptr < ptrend && *ptr == CHAR_LEFT_CURLY_BRACKET) - { - ptr++; - while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; - -#ifndef EBCDIC - COME_FROM_NU: -#endif - if (ptr >= ptrend || *ptr == CHAR_RIGHT_CURLY_BRACKET) - { - *errorcodeptr = ERR78; - break; - } - c = 0; - overflow = FALSE; - - while (ptr < ptrend && (cc = XDIGIT(*ptr)) != 0xff) - { - ptr++; - if (c == 0 && cc == 0) continue; /* Leading zeroes */ -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (c >= 0x10000000l) { overflow = TRUE; break; } -#endif - c = (c << 4) | cc; - if ((utf && c > 0x10ffffU) || (!utf && c > MAX_NON_UTF_CHAR)) - { - overflow = TRUE; - break; - } - } - - /* Perl ignores spaces and tabs before } */ - - while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; - - /* On overflow, skip remaining hex digits */ - - if (overflow) - { - while (ptr < ptrend && XDIGIT(*ptr) != 0xff) ptr++; - *errorcodeptr = ERR34; - } - else if (utf && c >= 0xd800 && c <= 0xdfff && - (xoptions & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0) - { - *errorcodeptr = ERR73; - } - else if (ptr < ptrend && *ptr == CHAR_RIGHT_CURLY_BRACKET) - { - ptr++; - } - - /* If the sequence of hex digits (followed by optional space) does not - end with '}', give an error. We used just to recognize this construct - and fall through to the normal \x handling, but nowadays Perl gives an - error, which seems much more sensible, so we do too. */ - - else - { - *errorcodeptr = ERR67; - goto ESCAPE_FAILED_FORWARD; - } - } /* End of \x{} processing */ - - /* Read a up to two hex digits after \x */ - - else - { - /* Perl has the surprising/broken behaviour that \x without following - hex digits is treated as an escape for NUL. Their source code laments - this but keeps it for backwards compatibility. A warning is printed - when "use warnings" is enabled. Because we don't have warnings, we - simply forbid it. */ - if (ptr >= ptrend || (cc = XDIGIT(*ptr)) == 0xff) - { - /* Not a hex digit */ - *errorcodeptr = ERR78; - break; - } - ptr++; - c = cc; - - /* With "use re 'strict'" Perl actually requires exactly two digits (error - for \x, \xA and \xAAA). While \x was already rejected, this seems overly - strict, and there seems little incentive to align with that, given the - backwards-compatibility cost. - - For comparison, note that other engines disagree. For example: - - Java allows 1 or 2 hex digits. Error if 0 digits. No error if >2 digits - - .NET requires 2 hex digits. Error if 0, 1 digits. No error if >2 digits. - */ - if (ptr >= ptrend || (cc = XDIGIT(*ptr)) == 0xff) break; /* Not a hex digit */ - ptr++; - c = (c << 4) | cc; - } /* End of \xdd handling */ - } /* End of Perl-style \x handling */ - break; - - /* The handling of \c is different in ASCII and EBCDIC environments. In an - ASCII (or Unicode) environment, an error is given if the character - following \c is not a printable ASCII character. Otherwise, the following - character is upper-cased if it is a letter, and after that the 0x40 bit is - flipped. The result is the value of the escape. - - In an EBCDIC environment the handling of \c is compatible with the - specification in the perlebcdic document. The following character must be - a letter or one of small number of special characters. These provide a - means of defining the character values 0-31. - - For testing the EBCDIC handling of \c in an ASCII environment, recognize - the EBCDIC value of 'c' explicitly. */ - - case CHAR_c: - if (ptr >= ptrend) - { - *errorcodeptr = ERR2; - break; - } - c = *ptr; - if (c >= CHAR_a && c <= CHAR_z) c = UPPER_CASE(c); - - /* Handle \c in an ASCII/Unicode environment. */ - -#ifndef EBCDIC /* ASCII/UTF-8 coding */ - if (c < 32 || c > 126) /* Excludes all non-printable ASCII */ - { - *errorcodeptr = ERR68; - goto ESCAPE_FAILED_FORWARD; - } - c ^= 0x40; - - /* Handle \c in an EBCDIC environment. The special case \c? is converted to - 255 (0xff) or 95 (0x5f) if other characters suggest we are using the - POSIX-BC encoding. (This is the way Perl indicates that it handles \c?.) - The other valid sequences correspond to a list of specific characters. */ - -#else - if (c == CHAR_QUESTION_MARK) - c = (CHAR_BACKSLASH == 188 && CHAR_GRAVE_ACCENT == 74)? 0x5f : 0xff; - else - { - for (i = 0; i < 32; i++) - { - if (c == ebcdic_escape_c[i]) break; - } - if (i < 32) - c = i; - else - { - *errorcodeptr = ERR68; - goto ESCAPE_FAILED_FORWARD; - } - } -#endif /* EBCDIC */ - - ptr++; - break; - - /* Any other alphanumeric following \ is an error. Perl gives an error only - if in warning mode, but PCRE doesn't have a warning mode. */ - - default: - *errorcodeptr = ERR3; - break; - } - } - -/* Set the pointer to the next character before returning. */ - -EXIT: -*ptrptr = ptr; -*chptr = c; -return escape; - -/* Some errors need to indicate the next character. */ - -ESCAPE_FAILED_FORWARD: -ptr++; -#ifdef SUPPORT_UNICODE -if (utf) FORWARDCHARTEST(ptr, ptrend); -#endif -goto EXIT; -} - - - -#ifdef SUPPORT_UNICODE -/************************************************* -* Handle \P and \p * -*************************************************/ - -/* This function is called after \P or \p has been encountered, provided that -PCRE2 is compiled with support for UTF and Unicode properties. On entry, the -contents of ptrptr are pointing after the P or p. On exit, it is left pointing -after the final code unit of the escape sequence. - -Arguments: - ptrptr the pattern position pointer - utf true if the input is UTF-encoded - negptr a boolean that is set TRUE for negation else FALSE - ptypeptr an unsigned int that is set to the type value - pdataptr an unsigned int that is set to the detailed property value - errorcodeptr the error code variable - cb the compile data - -Returns: TRUE if the type value was found, or FALSE for an invalid type -*/ - -static BOOL -get_ucp(PCRE2_SPTR *ptrptr, BOOL utf, BOOL *negptr, uint16_t *ptypeptr, - uint16_t *pdataptr, int *errorcodeptr, compile_block *cb) -{ -uint32_t c; -ptrdiff_t i; -PCRE2_SIZE bot, top; -PCRE2_SPTR ptr = *ptrptr; -PCRE2_UCHAR name[50]; -PCRE2_UCHAR *vptr = NULL; -uint16_t ptscript = PT_NOTSCRIPT; - -#ifndef MAYBE_UTF_MULTI -(void)utf; /* Avoid compiler warning */ -#endif - -if (ptr >= cb->end_pattern) goto ERROR_RETURN; -GETCHARINCTEST(c, ptr); -*negptr = FALSE; - -/* \P or \p can be followed by a name in {}, optionally preceded by ^ for -negation. We must be handling Unicode encoding here, though we may be compiling -for UTF-8 input in an EBCDIC environment. (PCRE2 does not support both EBCDIC -input and Unicode input in the same build.) In accordance with Unicode's "loose -matching" rules, ASCII white space, hyphens, and underscores are ignored. We -don't use isspace() or tolower() because (a) code points may be greater than -255, and (b) they wouldn't work when compiling for Unicode in an EBCDIC -environment. */ - -if (c == CHAR_LEFT_CURLY_BRACKET) - { - if (ptr >= cb->end_pattern) goto ERROR_RETURN; - - for (i = 0; i < (int)(sizeof(name) / sizeof(PCRE2_UCHAR)) - 1; i++) - { - REDO: - - if (ptr >= cb->end_pattern) goto ERROR_RETURN; - GETCHARINCTEST(c, ptr); - - /* Skip ignorable Unicode characters. */ - - if (c == CHAR_UNDERSCORE || c == CHAR_MINUS || c == CHAR_SPACE || - (c >= CHAR_HT && c <= CHAR_CR)) - { - goto REDO; - } - - /* The first significant character being circumflex negates the meaning of - the item. */ - - if (i == 0 && !*negptr && c == CHAR_CIRCUMFLEX_ACCENT) - { - *negptr = TRUE; - goto REDO; - } - - if (c == CHAR_RIGHT_CURLY_BRACKET) break; - - /* Names consist of ASCII letters and digits, but equals and colon may also - occur as a name/value separator. We must also allow for \p{L&}. A simple - check for a value between '&' and 'z' suffices because anything else in a - name or value will cause an "unknown property" error anyway. */ - - if (c < CHAR_AMPERSAND || c > CHAR_z) goto ERROR_RETURN; - - /* Lower case a capital letter or remember where the name/value separator - is. */ - - if (c >= CHAR_A && c <= CHAR_Z) c |= 0x20; - else if ((c == CHAR_COLON || c == CHAR_EQUALS_SIGN) && vptr == NULL) - vptr = name + i; - - name[i] = c; - } - - /* Error if the loop didn't end with '}' - either we hit the end of the - pattern or the name was longer than any legal property name. */ - - if (c != CHAR_RIGHT_CURLY_BRACKET) goto ERROR_RETURN; - name[i] = 0; - } - -/* If { doesn't follow \p or \P there is just one following character, which -must be an ASCII letter. */ - -else if (c >= CHAR_A && c <= CHAR_Z) - { - name[0] = c | 0x20; /* Lower case */ - name[1] = 0; - } -else if (c >= CHAR_a && c <= CHAR_z) - { - name[0] = c; - name[1] = 0; - } -else goto ERROR_RETURN; - -*ptrptr = ptr; /* Update pattern pointer */ - -/* If the property contains ':' or '=' we have class name and value separately -specified. The following are supported: - - . Bidi_Class (synonym bc), for which the property names are "bidi". - . Script (synonym sc) for which the property name is the script name - . Script_Extensions (synonym scx), ditto - -As this is a small number, we currently just check the names directly. If this -grows, a sorted table and a switch will be neater. - -For both the script properties, set a PT_xxx value so that (1) they can be -distinguished and (2) invalid script names that happen to be the name of -another property can be diagnosed. */ - -if (vptr != NULL) - { - int offset = 0; - PCRE2_UCHAR sname[8]; - - *vptr = 0; /* Terminate property name */ - if (PRIV(strcmp_c8)(name, STRING_bidiclass) == 0 || - PRIV(strcmp_c8)(name, STRING_bc) == 0) - { - offset = 4; - sname[0] = CHAR_b; - sname[1] = CHAR_i; /* There is no strcpy_c8 function */ - sname[2] = CHAR_d; - sname[3] = CHAR_i; - } - - else if (PRIV(strcmp_c8)(name, STRING_script) == 0 || - PRIV(strcmp_c8)(name, STRING_sc) == 0) - ptscript = PT_SC; - - else if (PRIV(strcmp_c8)(name, STRING_scriptextensions) == 0 || - PRIV(strcmp_c8)(name, STRING_scx) == 0) - ptscript = PT_SCX; - - else - { - *errorcodeptr = ERR47; - return FALSE; - } - - /* Adjust the string in name[] as needed */ - - memmove(name + offset, vptr + 1, (name + i - vptr)*sizeof(PCRE2_UCHAR)); - if (offset != 0) memmove(name, sname, offset*sizeof(PCRE2_UCHAR)); - } - -/* Search for a recognized property using binary chop. */ - -bot = 0; -top = PRIV(utt_size); - -while (bot < top) - { - int r; - i = (bot + top) >> 1; - r = PRIV(strcmp_c8)(name, PRIV(utt_names) + PRIV(utt)[i].name_offset); - - /* When a matching property is found, some extra checking is needed when the - \p{xx:yy} syntax is used and xx is either sc or scx. */ - - if (r == 0) - { - *pdataptr = PRIV(utt)[i].value; - if (vptr == NULL || ptscript == PT_NOTSCRIPT) - { - *ptypeptr = PRIV(utt)[i].type; - return TRUE; - } - - switch (PRIV(utt)[i].type) - { - case PT_SC: - *ptypeptr = PT_SC; - return TRUE; - - case PT_SCX: - *ptypeptr = ptscript; - return TRUE; - } - - break; /* Non-script found */ - } - - if (r > 0) bot = i + 1; else top = i; - } - -*errorcodeptr = ERR47; /* Unrecognized property */ -return FALSE; - -ERROR_RETURN: /* Malformed \P or \p */ -*errorcodeptr = ERR46; -*ptrptr = ptr; -return FALSE; -} -#endif - - - -/************************************************* -* Check for POSIX class syntax * -*************************************************/ - -/* This function is called when the sequence "[:" or "[." or "[=" is -encountered in a character class. It checks whether this is followed by a -sequence of characters terminated by a matching ":]" or ".]" or "=]". If we -reach an unescaped ']' without the special preceding character, return FALSE. - -Originally, this function only recognized a sequence of letters between the -terminators, but it seems that Perl recognizes any sequence of characters, -though of course unknown POSIX names are subsequently rejected. Perl gives an -"Unknown POSIX class" error for [:f\oo:] for example, where previously PCRE -didn't consider this to be a POSIX class. Likewise for [:1234:]. - -The problem in trying to be exactly like Perl is in the handling of escapes. We -have to be sure that [abc[:x\]pqr] is *not* treated as containing a POSIX -class, but [abc[:x\]pqr:]] is (so that an error can be generated). The code -below handles the special cases \\ and \], but does not try to do any other -escape processing. This makes it different from Perl for cases such as -[:l\ower:] where Perl recognizes it as the POSIX class "lower" but PCRE does -not recognize "l\ower". This is a lesser evil than not diagnosing bad classes -when Perl does, I think. - -A user pointed out that PCRE was rejecting [:a[:digit:]] whereas Perl was not. -It seems that the appearance of a nested POSIX class supersedes an apparent -external class. For example, [:a[:digit:]b:] matches "a", "b", ":", or -a digit. This is handled by returning FALSE if the start of a new group with -the same terminator is encountered, since the next closing sequence must close -the nested group, not the outer one. - -In Perl, unescaped square brackets may also appear as part of class names. For -example, [:a[:abc]b:] gives unknown POSIX class "[:abc]b:]". However, for -[:a[:abc]b][b:] it gives unknown POSIX class "[:abc]b][b:]", which does not -seem right at all. PCRE does not allow closing square brackets in POSIX class -names. - -Arguments: - ptr pointer to the character after the initial [ (colon, dot, equals) - ptrend pointer to the end of the pattern - endptr where to return a pointer to the terminating ':', '.', or '=' - -Returns: TRUE or FALSE -*/ - -static BOOL -check_posix_syntax(PCRE2_SPTR ptr, PCRE2_SPTR ptrend, PCRE2_SPTR *endptr) -{ -PCRE2_UCHAR terminator; /* Don't combine these lines; the Solaris cc */ -terminator = *ptr++; /* compiler warns about "non-constant" initializer. */ - -for (; ptrend - ptr >= 2; ptr++) - { - if (*ptr == CHAR_BACKSLASH && - (ptr[1] == CHAR_RIGHT_SQUARE_BRACKET || ptr[1] == CHAR_BACKSLASH)) - ptr++; - - else if ((*ptr == CHAR_LEFT_SQUARE_BRACKET && ptr[1] == terminator) || - *ptr == CHAR_RIGHT_SQUARE_BRACKET) return FALSE; - - else if (*ptr == terminator && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET) - { - *endptr = ptr; - return TRUE; - } - } - -return FALSE; -} - - - -/************************************************* -* Check POSIX class name * -*************************************************/ - -/* This function is called to check the name given in a POSIX-style class entry -such as [:alnum:]. - -Arguments: - ptr points to the first letter - len the length of the name - -Returns: a value representing the name, or -1 if unknown -*/ - -static int -check_posix_name(PCRE2_SPTR ptr, int len) -{ -const char *pn = posix_names; -int yield = 0; -while (posix_name_lengths[yield] != 0) - { - if (len == posix_name_lengths[yield] && - PRIV(strncmp_c8)(ptr, pn, (unsigned int)len) == 0) return yield; - pn += posix_name_lengths[yield] + 1; - yield++; - } -return -1; -} - - - -/************************************************* -* Read a subpattern or VERB name * -*************************************************/ - -/* This function is called from parse_regex() below whenever it needs to read -the name of a subpattern or a (*VERB) or an (*alpha_assertion). The initial -pointer must be to the preceding character. If that character is '*' we are -reading a verb or alpha assertion name. The pointer is updated to point after -the name, for a VERB or alpha assertion name, or after the name's terminator -for a subpattern name. Returning both the offset and the name pointer is -redundant information, but some callers use one and some the other, so it is -simplest just to return both. When the name is in braces, spaces and tabs are -allowed (and ignored) at either end. - -Arguments: - ptrptr points to the character pointer variable - ptrend points to the end of the input string - utf true if the input is UTF-encoded - terminator the terminator of a subpattern name must be this - offsetptr where to put the offset from the start of the pattern - nameptr where to put a pointer to the name in the input - namelenptr where to put the length of the name - errcodeptr where to put an error code - cb pointer to the compile data block - -Returns: TRUE if a name was read - FALSE otherwise, with error code set -*/ - -static BOOL -read_name(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, BOOL utf, uint32_t terminator, - PCRE2_SIZE *offsetptr, PCRE2_SPTR *nameptr, uint32_t *namelenptr, - int *errorcodeptr, compile_block *cb) -{ -PCRE2_SPTR ptr = *ptrptr; -BOOL is_group = (*ptr++ != CHAR_ASTERISK); -BOOL is_braced = terminator == CHAR_RIGHT_CURLY_BRACKET; - -if (is_braced) - while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; - -if (ptr >= ptrend) /* No characters in name */ - { - *errorcodeptr = is_group? ERR62: /* Subpattern name expected */ - ERR60; /* Verb not recognized or malformed */ - goto FAILED; - } - -*nameptr = ptr; -*offsetptr = (PCRE2_SIZE)(ptr - cb->start_pattern); - -/* If this logic were ever to change, the matching function in pcre2_substitute.c -ought to be updated to match. */ - -/* In UTF mode, a group name may contain letters and decimal digits as defined -by Unicode properties, and underscores, but must not start with a digit. */ - -#ifdef SUPPORT_UNICODE -if (utf && is_group) - { - uint32_t c, type; - PCRE2_SPTR p = ptr; - - GETCHARINC(c, p); /* Peek at next character */ - type = UCD_CHARTYPE(c); - - if (type == ucp_Nd) - { - ptr = p; - *errorcodeptr = ERR44; - goto FAILED; - } - - for(;;) - { - if (type != ucp_Nd && PRIV(ucp_gentype)[type] != ucp_L && - c != CHAR_UNDERSCORE) break; - ptr = p; /* Accept character and peek again */ - if (p >= ptrend) break; - GETCHARINC(c, p); - type = UCD_CHARTYPE(c); - } - } -else -#else -(void)utf; /* Avoid compiler warning */ -#endif /* SUPPORT_UNICODE */ - -/* Handle non-group names and group names in non-UTF modes. A group name must -not start with a digit. If either of the others start with a digit it just -won't be recognized. */ - - { - if (is_group && IS_DIGIT(*ptr)) - { - ++ptr; - *errorcodeptr = ERR44; - goto FAILED; - } - - while (ptr < ptrend && MAX_255(*ptr) && (cb->ctypes[*ptr] & ctype_word) != 0) - { - ptr++; - } - } - -/* Check name length */ - -if (ptr - *nameptr > MAX_NAME_SIZE) - { - *errorcodeptr = ERR48; - goto FAILED; - } -*namelenptr = (uint32_t)(ptr - *nameptr); - -/* Subpattern names must not be empty, and their terminator is checked here. -(What follows a verb or alpha assertion name is checked separately.) */ - -if (is_group) - { - if (ptr == *nameptr) - { - *errorcodeptr = ERR62; /* Subpattern name expected */ - goto FAILED; - } - if (is_braced) - while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; - if (terminator != 0) - { - if (ptr >= ptrend || *ptr != (PCRE2_UCHAR)terminator) - { - *errorcodeptr = ERR42; - goto FAILED; - } - ptr++; - } - } - -*ptrptr = ptr; -return TRUE; - -FAILED: -*ptrptr = ptr; -return FALSE; -} - - - -/************************************************** -* Parse capturing bracket argument list * -**************************************************/ - -/* Reads a list of capture references. The references -can be numbers or names. - -Arguments: - ptrptr points to the character pointer variable - ptrend points to the end of the input string - utf true if the input is UTF-encoded - parsed_pattern the parsed pattern pointer - offset last known offset - errcodeptr where to put an error code - cb pointer to the compile data block - -Returns: updated parsed_pattern pointer on success - NULL otherwise -*/ - -static uint32_t * -parse_capture_list(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, - BOOL utf, uint32_t *parsed_pattern, PCRE2_SIZE offset, - int *errorcodeptr, compile_block *cb) -{ -PCRE2_SIZE next_offset; -PCRE2_SPTR ptr = *ptrptr; -PCRE2_SPTR name; -PCRE2_UCHAR terminator; -uint32_t meta, namelen; -int i; - -if (ptr >= ptrend || *ptr != CHAR_LEFT_PARENTHESIS) - { - *errorcodeptr = ERR118; - goto FAILED; - } - -for (;;) - { - ptr++; - next_offset = (PCRE2_SIZE)(ptr - cb->start_pattern); - - if (ptr >= ptrend) - { - *errorcodeptr = ERR117; - goto FAILED; - } - - /* Handle [+-]number cases */ - if (read_number(&ptr, ptrend, cb->bracount, MAX_GROUP_NUMBER, ERR61, - &i, errorcodeptr)) - { - PCRE2_ASSERT(i >= 0); - if (i <= 0) - { - *errorcodeptr = ERR15; - goto FAILED; - } - meta = META_CAPTURE_NUMBER; - namelen = (uint32_t)i; - } - else if (*errorcodeptr != 0) goto FAILED; /* Number too big */ - else - { - /* Handle 'name' or cases. */ - if (*ptr == CHAR_LESS_THAN_SIGN) - terminator = CHAR_GREATER_THAN_SIGN; - else if (*ptr == CHAR_APOSTROPHE) - terminator = CHAR_APOSTROPHE; - else - { - *errorcodeptr = ERR117; - goto FAILED; - } - - if (!read_name(&ptr, ptrend, utf, terminator, &next_offset, - &name, &namelen, errorcodeptr, cb)) goto FAILED; - - meta = META_CAPTURE_NAME; - } - - PCRE2_ASSERT(next_offset > 0); - if (offset == 0 || (next_offset - offset) >= 0x10000) - { - *parsed_pattern++ = META_OFFSET; - PUTOFFSET(next_offset, parsed_pattern); - offset = next_offset; - } - - /* The offset is encoded as a relative offset, because for some - inputs such as ",2" in (1,2,3), we only have space for two uint32_t - values, and an opcode and absolute offset may require three uint32_t - values. */ - *parsed_pattern++ = meta | (uint32_t)(next_offset - offset); - *parsed_pattern++ = namelen; - offset = next_offset; - - if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - - if (*ptr == CHAR_RIGHT_PARENTHESIS) break; - - if (*ptr != CHAR_COMMA) - { - *errorcodeptr = ERR24; - goto FAILED; - } - } - -*ptrptr = ptr + 1; -return parsed_pattern; - -UNCLOSED_PARENTHESIS: -*errorcodeptr = ERR14; - -FAILED: -*ptrptr = ptr; -return NULL; -} - - - -/************************************************* -* Manage callouts at start of cycle * -*************************************************/ - -/* At the start of a new item in parse_regex() we are able to record the -details of the previous item in a prior callout, and also to set up an -automatic callout if enabled. Avoid having two adjacent automatic callouts, -which would otherwise happen for items such as \Q that contribute nothing to -the parsed pattern. - -Arguments: - ptr current pattern pointer - pcalloutptr points to a pointer to previous callout, or NULL - auto_callout TRUE if auto_callouts are enabled - parsed_pattern the parsed pattern pointer - cb compile block - -Returns: possibly updated parsed_pattern pointer. -*/ - -static uint32_t * -manage_callouts(PCRE2_SPTR ptr, uint32_t **pcalloutptr, BOOL auto_callout, - uint32_t *parsed_pattern, compile_block *cb) -{ -uint32_t *previous_callout = *pcalloutptr; - -if (previous_callout != NULL) previous_callout[2] = (uint32_t)(ptr - - cb->start_pattern - (PCRE2_SIZE)previous_callout[1]); - -if (!auto_callout) previous_callout = NULL; else - { - if (previous_callout == NULL || - previous_callout != parsed_pattern - 4 || - previous_callout[3] != 255) - { - previous_callout = parsed_pattern; /* Set up new automatic callout */ - parsed_pattern += 4; - previous_callout[0] = META_CALLOUT_NUMBER; - previous_callout[2] = 0; - previous_callout[3] = 255; - } - previous_callout[1] = (uint32_t)(ptr - cb->start_pattern); - } - -*pcalloutptr = previous_callout; -return parsed_pattern; -} - - - -/************************************************* -* Handle \d, \D, \s, \S, \w, \W * -*************************************************/ - -/* This function is called from parse_regex() below, both for freestanding -escapes, and those within classes, to handle those escapes that may change when -Unicode property support is requested. Note that PCRE2_UCP will never be set -without Unicode support because that is checked when pcre2_compile() is called. - -Arguments: - escape the ESC_... value - parsed_pattern where to add the code - options options bits - xoptions extra options bits - -Returns: updated value of parsed_pattern -*/ -static uint32_t * -handle_escdsw(int escape, uint32_t *parsed_pattern, uint32_t options, - uint32_t xoptions) -{ -uint32_t ascii_option = 0; -uint32_t prop = ESC_p; - -switch(escape) - { - case ESC_D: - prop = ESC_P; - PCRE2_FALLTHROUGH /* Fall through */ - case ESC_d: - ascii_option = PCRE2_EXTRA_ASCII_BSD; - break; - - case ESC_S: - prop = ESC_P; - PCRE2_FALLTHROUGH /* Fall through */ - case ESC_s: - ascii_option = PCRE2_EXTRA_ASCII_BSS; - break; - - case ESC_W: - prop = ESC_P; - PCRE2_FALLTHROUGH /* Fall through */ - case ESC_w: - ascii_option = PCRE2_EXTRA_ASCII_BSW; - break; - } - -if ((options & PCRE2_UCP) == 0 || (xoptions & ascii_option) != 0) - { - *parsed_pattern++ = META_ESCAPE + escape; - } -else - { - *parsed_pattern++ = META_ESCAPE + prop; - switch(escape) - { - case ESC_d: - case ESC_D: - *parsed_pattern++ = (PT_PC << 16) | ucp_Nd; - break; - - case ESC_s: - case ESC_S: - *parsed_pattern++ = PT_SPACE << 16; - break; - - case ESC_w: - case ESC_W: - *parsed_pattern++ = PT_WORD << 16; - break; - } - } - -return parsed_pattern; -} - - - -/************************************************* -* Maximum size of parsed_pattern for given input * -*************************************************/ - -/* This function is called from parse_regex() below, to determine the amount -of memory to allocate for parsed_pattern. It is also called to check whether -the amount of data written respects the amount of memory allocated. - -Arguments: - ptr points to the start of the pattern - ptrend points to the end of the pattern - utf TRUE in UTF mode - options the options bits - -Returns: the number of uint32_t units for parsed_pattern -*/ -static ptrdiff_t -max_parsed_pattern(PCRE2_SPTR ptr, PCRE2_SPTR ptrend, BOOL utf, - uint32_t options) -{ -PCRE2_SIZE big32count = 0; -ptrdiff_t parsed_size_needed; - -/* When PCRE2_AUTO_CALLOUT is not set, in all but one case the number of -unsigned 32-bit ints written out to the parsed pattern is bounded by the length -of the pattern. The exceptional case is when running in 32-bit, non-UTF mode, -when literal characters greater than META_END (0x80000000) have to be coded as -two units. In this case, therefore, we scan the pattern to check for such -values. */ - -#if PCRE2_CODE_UNIT_WIDTH == 32 -if (!utf) - { - PCRE2_SPTR p; - for (p = ptr; p < ptrend; p++) if (*p >= META_END) big32count++; - } -#else -(void)utf; /* Avoid compiler warning */ -#endif - -parsed_size_needed = (ptrend - ptr) + big32count; - -/* When PCRE2_AUTO_CALLOUT is set we have to assume a numerical callout (4 -elements) for each character. This is overkill, but memory is plentiful these -days. */ - -if ((options & PCRE2_AUTO_CALLOUT) != 0) - parsed_size_needed += (ptrend - ptr) * 4; - -return parsed_size_needed; -} - - - -/************************************************* -* Parse regex and identify named groups * -*************************************************/ - -/* This function is called first of all. It scans the pattern and does two -things: (1) It identifies capturing groups and makes a table of named capturing -groups so that information about them is fully available to both the compiling -scans. (2) It writes a parsed version of the pattern with comments omitted and -escapes processed into the parsed_pattern vector. - -Arguments: - ptr points to the start of the pattern - options compiling dynamic options (may change during the scan) - has_lookbehind points to a boolean, set TRUE if a lookbehind is found - cb pointer to the compile data block - -Returns: zero on success or a non-zero error code, with the - error offset placed in the cb field -*/ - -/* A structure and some flags for dealing with nested groups. */ - -typedef struct nest_save { - uint16_t nest_depth; - uint16_t reset_group; - uint16_t max_group; - uint16_t flags; - uint32_t options; - uint32_t xoptions; -} nest_save; - -#define NSF_RESET 0x0001u -#define NSF_CONDASSERT 0x0002u -#define NSF_ATOMICSR 0x0004u - -/* Options that are changeable within the pattern must be tracked during -parsing. Some (e.g. PCRE2_EXTENDED) are implemented entirely during parsing, -but all must be tracked so that META_OPTIONS items set the correct values for -the main compiling phase. */ - -#define PARSE_TRACKED_OPTIONS (PCRE2_CASELESS|PCRE2_DOTALL|PCRE2_DUPNAMES| \ - PCRE2_EXTENDED|PCRE2_EXTENDED_MORE|PCRE2_MULTILINE|PCRE2_NO_AUTO_CAPTURE| \ - PCRE2_UNGREEDY) - -#define PARSE_TRACKED_EXTRA_OPTIONS (PCRE2_EXTRA_CASELESS_RESTRICT| \ - PCRE2_EXTRA_ASCII_BSD|PCRE2_EXTRA_ASCII_BSS|PCRE2_EXTRA_ASCII_BSW| \ - PCRE2_EXTRA_ASCII_DIGIT|PCRE2_EXTRA_ASCII_POSIX) - -/* States used for analyzing ranges in character classes. The two OK values -must be last. */ - -enum { - RANGE_NO, /* State after '[' (initial), or '[a-z'; hyphen is literal */ - RANGE_STARTED, /* State after '[1-'; last-emitted code is META_RANGE_XYZ */ - RANGE_FORBID_NO, /* State after '[\d'; '-]' is allowed but not '-1]' */ - RANGE_FORBID_STARTED, /* State after '[\d-'*/ - RANGE_OK_ESCAPED, /* State after '[\1'; hyphen may be a range */ - RANGE_OK_LITERAL /* State after '[1'; hyphen may be a range */ -}; - -/* States used for analyzing operators and operands in extended character -classes. */ - -enum { - CLASS_OP_EMPTY, /* At start of an expression; empty previous contents */ - CLASS_OP_OPERAND, /* Have preceding operand; after "z" a "--" can follow */ - CLASS_OP_OPERATOR /* Have preceding operator; after "--" operand must follow */ -}; - -/* States used for determining the parse mode in character classes. The two -PERL_EXT values must be last. */ - -enum { - CLASS_MODE_NORMAL, /* Ordinary PCRE2 '[...]' class. */ - CLASS_MODE_ALT_EXT, /* UTS#18-style extended '[...]' class. */ - CLASS_MODE_PERL_EXT, /* Perl extended '(?[...])' class. */ - CLASS_MODE_PERL_EXT_LEAF /* Leaf within extended '(?[ [...] ])' class. */ -}; - -/* Only in 32-bit mode can there be literals > META_END. A macro encapsulates -the storing of literal values in the main parsed pattern, where they can always -be quantified. */ - -#if PCRE2_CODE_UNIT_WIDTH == 32 -#define PARSED_LITERAL(c, p) \ - { \ - if (c >= META_END) *p++ = META_BIGVALUE; \ - *p++ = c; \ - okquantifier = TRUE; \ - } -#else -#define PARSED_LITERAL(c, p) *p++ = c; okquantifier = TRUE; -#endif - -/* Here's the actual function. */ - -static int parse_regex(PCRE2_SPTR ptr, uint32_t options, uint32_t xoptions, - BOOL *has_lookbehind, compile_block *cb) -{ -uint32_t c; -uint32_t delimiter; -uint32_t namelen; -uint32_t class_range_state; -uint32_t class_op_state; -uint32_t class_mode_state; -uint32_t *class_start; -uint32_t *verblengthptr = NULL; /* Value avoids compiler warning */ -uint32_t *verbstartptr = NULL; -uint32_t *previous_callout = NULL; -uint32_t *parsed_pattern = cb->parsed_pattern; -uint32_t *parsed_pattern_end = cb->parsed_pattern_end; -uint32_t *this_parsed_item = NULL; -uint32_t *prev_parsed_item = NULL; -uint32_t meta_quantifier = 0; -uint32_t add_after_mark = 0; -uint16_t nest_depth = 0; -int16_t class_depth_m1 = -1; /* The m1 means minus 1. */ -int16_t class_maxdepth_m1 = -1; -uint16_t hash; -int after_manual_callout = 0; -int expect_cond_assert = 0; -int errorcode = 0; -int escape; -int i; -BOOL inescq = FALSE; -BOOL inverbname = FALSE; -BOOL utf = (options & PCRE2_UTF) != 0; -BOOL auto_callout = (options & PCRE2_AUTO_CALLOUT) != 0; -BOOL is_dupname; -BOOL negate_class; -BOOL okquantifier = FALSE; -PCRE2_SPTR thisptr; -PCRE2_SPTR name; -PCRE2_SPTR ptrend = cb->end_pattern; -PCRE2_SPTR verbnamestart = NULL; /* Value avoids compiler warning */ -PCRE2_SPTR class_range_forbid_ptr = NULL; -named_group *ng; -nest_save *top_nest, *end_nests; -#ifdef PCRE2_DEBUG -uint32_t *parsed_pattern_check; -ptrdiff_t parsed_pattern_extra = 0; -ptrdiff_t parsed_pattern_extra_check = 0; -PCRE2_SPTR ptr_check; -#endif - -PCRE2_ASSERT(parsed_pattern != NULL); - -/* Insert leading items for word and line matching (features provided for the -benefit of pcre2grep). */ - -if ((xoptions & PCRE2_EXTRA_MATCH_LINE) != 0) - { - *parsed_pattern++ = META_CIRCUMFLEX; - *parsed_pattern++ = META_NOCAPTURE; - } -else if ((xoptions & PCRE2_EXTRA_MATCH_WORD) != 0) - { - *parsed_pattern++ = META_ESCAPE + ESC_b; - *parsed_pattern++ = META_NOCAPTURE; - } - -#ifdef PCRE2_DEBUG -parsed_pattern_check = parsed_pattern; -ptr_check = ptr; -#endif - -/* If the pattern is actually a literal string, process it separately to avoid -cluttering up the main loop. */ - -if ((options & PCRE2_LITERAL) != 0) - { - while (ptr < ptrend) - { - /* LCOV_EXCL_START */ - if (parsed_pattern >= parsed_pattern_end) - { - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR63; /* Internal error (parsed pattern overflow) */ - goto FAILED; - } - /* LCOV_EXCL_STOP */ - - thisptr = ptr; - GETCHARINCTEST(c, ptr); - if (auto_callout) - parsed_pattern = manage_callouts(thisptr, &previous_callout, - auto_callout, parsed_pattern, cb); - PARSED_LITERAL(c, parsed_pattern); - } - goto PARSED_END; - } - -/* Process a real regex which may contain meta-characters. */ - -top_nest = NULL; -end_nests = (nest_save *)(cb->start_workspace + cb->workspace_size); - -/* The size of the nest_save structure might not be a factor of the size of the -workspace. Therefore we must round down end_nests so as to correctly avoid -creating a nest_save that spans the end of the workspace. */ - -end_nests = (nest_save *)((char *)end_nests - - ((cb->workspace_size * sizeof(PCRE2_UCHAR)) % sizeof(nest_save))); - -/* PCRE2_EXTENDED_MORE implies PCRE2_EXTENDED */ - -if ((options & PCRE2_EXTENDED_MORE) != 0) options |= PCRE2_EXTENDED; - -/* Now scan the pattern */ - -while (ptr < ptrend) - { - int prev_expect_cond_assert; - uint32_t min_repeat = 0, max_repeat = 0; - uint32_t set, unset, *optset; - uint32_t xset, xunset, *xoptset; - uint32_t terminator; - uint32_t prev_meta_quantifier; - BOOL prev_okquantifier; - PCRE2_SPTR tempptr; - PCRE2_SIZE offset; - - if (nest_depth > cb->cx->parens_nest_limit) - { - errorcode = ERR19; - goto FAILED; /* Parentheses too deeply nested */ - } - - /* Check that we haven't emitted too much into parsed_pattern. We allocate - a suitably-sized buffer upfront, then do unchecked writes to it. If we only - write a little bit too much, everything will appear to be OK, because the - upfront size is an overestimate... but a malicious pattern could end up - forcing a write past the buffer end. We must catch this during - development. */ - -#ifdef PCRE2_DEBUG - /* Strong post-write check. Won't help in release builds - at this point - the write has already occurred so it's too late. However, should stop us - committing unsafe code. */ - PCRE2_ASSERT((parsed_pattern - parsed_pattern_check) + - (parsed_pattern_extra - parsed_pattern_extra_check) <= - max_parsed_pattern(ptr_check, ptr, utf, options)); - parsed_pattern_check = parsed_pattern; - parsed_pattern_extra_check = parsed_pattern_extra; - ptr_check = ptr; -#endif - - /* LCOV_EXCL_START */ - if (parsed_pattern >= parsed_pattern_end) - { - /* Weak pre-write check; only ensures parsed_pattern[0] is writeable - (but the code below can write many chars). Better than nothing. */ - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR63; /* Internal error (parsed pattern overflow) */ - goto FAILED; - } - /* LCOV_EXCL_STOP */ - - /* If the last time round this loop something was added, parsed_pattern will - no longer be equal to this_parsed_item. Remember where the previous item - started and reset for the next item. Note that sometimes round the loop, - nothing gets added (e.g. for ignored white space). */ - - if (this_parsed_item != parsed_pattern) - { - prev_parsed_item = this_parsed_item; - this_parsed_item = parsed_pattern; - } - - /* Get next input character, save its position for callout handling. */ - - thisptr = ptr; - GETCHARINCTEST(c, ptr); - - /* Copy quoted literals until \E, allowing for the possibility of automatic - callouts, except when processing a (*VERB) "name". */ - - if (inescq) - { - if (c == CHAR_BACKSLASH && ptr < ptrend && *ptr == CHAR_E) - { - inescq = FALSE; - ptr++; /* Skip E */ - } - else - { - if (inverbname) - { /* Don't use PARSED_LITERAL() because it */ -#if PCRE2_CODE_UNIT_WIDTH == 32 /* sets okquantifier. */ - if (c >= META_END) *parsed_pattern++ = META_BIGVALUE; -#endif - *parsed_pattern++ = c; - } - else - { - if (after_manual_callout-- <= 0) - parsed_pattern = manage_callouts(thisptr, &previous_callout, - auto_callout, parsed_pattern, cb); - PARSED_LITERAL(c, parsed_pattern); - } - meta_quantifier = 0; - } - continue; /* Next character */ - } - - /* If we are processing the "name" part of a (*VERB:NAME) item, all - characters up to the closing parenthesis are literals except when - PCRE2_ALT_VERBNAMES is set. That causes backslash interpretation, but only \Q - and \E and escaped characters are allowed (no character types such as \d). If - PCRE2_EXTENDED is also set, we must ignore white space and # comments. Do - this by not entering the special (*VERB:NAME) processing - they are then - picked up below. Note that c is a character, not a code unit, so we must not - use MAX_255 to test its size because MAX_255 tests code units and is assumed - TRUE in 8-bit mode. */ - - if (inverbname && - ( - /* EITHER: not both options set */ - ((options & (PCRE2_EXTENDED | PCRE2_ALT_VERBNAMES)) != - (PCRE2_EXTENDED | PCRE2_ALT_VERBNAMES)) || -#ifdef SUPPORT_UNICODE - /* OR: character > 255 AND not Unicode Pattern White Space */ - (c > 255 && (c|1) != 0x200f && (c|1) != 0x2029) || -#endif - /* OR: not a # comment or isspace() white space */ - (c < 256 && c != CHAR_NUMBER_SIGN && (cb->ctypes[c] & ctype_space) == 0 -#ifdef SUPPORT_UNICODE - /* and not CHAR_NEL when Unicode is supported */ - && c != CHAR_NEL -#endif - ))) - { - PCRE2_SIZE verbnamelength; - - switch(c) - { - default: /* Don't use PARSED_LITERAL() because it */ -#if PCRE2_CODE_UNIT_WIDTH == 32 /* sets okquantifier. */ - if (c >= META_END) *parsed_pattern++ = META_BIGVALUE; -#endif - *parsed_pattern++ = c; - break; - - case CHAR_RIGHT_PARENTHESIS: - inverbname = FALSE; - /* This is the length in characters */ - verbnamelength = (PCRE2_SIZE)(parsed_pattern - verblengthptr - 1); - /* But the limit on the length is in code units */ - if (ptr - verbnamestart - 1 > (int)MAX_MARK) - { - ptr--; - errorcode = ERR76; - goto FAILED; - } - *verblengthptr = (uint32_t)verbnamelength; - - /* If this name was on a verb such as (*ACCEPT) which does not continue, - a (*MARK) was generated for the name. We now add the original verb as the - next item. */ - - if (add_after_mark != 0) - { - *parsed_pattern++ = add_after_mark; - add_after_mark = 0; - } - break; - - case CHAR_BACKSLASH: - if ((options & PCRE2_ALT_VERBNAMES) != 0) - { - escape = PRIV(check_escape)(&ptr, ptrend, &c, &errorcode, options, - xoptions, cb->bracount, FALSE, cb); - if (errorcode != 0) goto FAILED; - } - else escape = 0; /* Treat all as literal */ - - switch(escape) - { - case 0: /* Don't use PARSED_LITERAL() because it */ -#if PCRE2_CODE_UNIT_WIDTH == 32 /* sets okquantifier. */ - if (c >= META_END) *parsed_pattern++ = META_BIGVALUE; -#endif - *parsed_pattern++ = c; - break; - - case ESC_ub: - *parsed_pattern++ = CHAR_u; - PARSED_LITERAL(CHAR_LEFT_CURLY_BRACKET, parsed_pattern); - break; - - case ESC_Q: - inescq = TRUE; - break; - - case ESC_E: /* Ignore */ - break; - - default: - errorcode = ERR40; /* Invalid in verb name */ - goto FAILED; - } - } - continue; /* Next character in pattern */ - } - - /* Not a verb name character. At this point we must process everything that - must not change the quantification state. This is mainly comments, but we - handle \Q and \E here as well, so that an item such as A\Q\E+ is treated as - A+, as in Perl. An isolated \E is ignored. */ - - if (c == CHAR_BACKSLASH && ptr < ptrend) - { - if (*ptr == CHAR_Q || *ptr == CHAR_E) - { - /* A literal inside a \Q...\E is not allowed if we are expecting a - conditional assertion, but an empty \Q\E sequence is OK. */ - if (expect_cond_assert > 0 && *ptr == CHAR_Q && - !(ptrend - ptr >= 3 && ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)) - { - ptr--; - errorcode = ERR28; - goto FAILED; - } - inescq = *ptr == CHAR_Q; - ptr++; - continue; - } - } - - /* Skip over whitespace and # comments in extended mode. Note that c is a - character, not a code unit, so we must not use MAX_255 to test its size - because MAX_255 tests code units and is assumed TRUE in 8-bit mode. The - whitespace characters are those designated as "Pattern White Space" by - Unicode, which are the isspace() characters plus CHAR_NEL (newline), which is - U+0085 in Unicode, plus U+200E, U+200F, U+2028, and U+2029. These are a - subset of space characters that match \h and \v. */ - - if ((options & PCRE2_EXTENDED) != 0) - { - if (c < 256 && (cb->ctypes[c] & ctype_space) != 0) continue; -#ifdef SUPPORT_UNICODE - if (c == CHAR_NEL || (c|1) == 0x200f || (c|1) == 0x2029) continue; -#endif - if (c == CHAR_NUMBER_SIGN) - { - while (ptr < ptrend) - { - if (IS_NEWLINE(ptr)) /* For non-fixed-length newline cases, */ - { /* IS_NEWLINE sets cb->nllen. */ - ptr += cb->nllen; - break; - } - ptr++; -#ifdef SUPPORT_UNICODE - if (utf) FORWARDCHARTEST(ptr, ptrend); -#endif - } - continue; /* Next character in pattern */ - } - } - - /* Skip over bracketed comments */ - - if (c == CHAR_LEFT_PARENTHESIS && ptrend - ptr >= 2 && - ptr[0] == CHAR_QUESTION_MARK && ptr[1] == CHAR_NUMBER_SIGN) - { - while (++ptr < ptrend && *ptr != CHAR_RIGHT_PARENTHESIS); - if (ptr >= ptrend) - { - errorcode = ERR18; /* A special error for missing ) in a comment */ - goto FAILED; /* to make it easier to debug. */ - } - ptr++; - continue; /* Next character in pattern */ - } - - /* If the next item is not a quantifier, fill in length of any previous - callout and create an auto callout if required. */ - - if (c != CHAR_ASTERISK && c != CHAR_PLUS && c != CHAR_QUESTION_MARK && - (c != CHAR_LEFT_CURLY_BRACKET || - (tempptr = ptr, - !read_repeat_counts(&tempptr, ptrend, NULL, NULL, &errorcode)))) - { - if (after_manual_callout-- <= 0) - { - parsed_pattern = manage_callouts(thisptr, &previous_callout, auto_callout, - parsed_pattern, cb); - this_parsed_item = parsed_pattern; /* New start for current item */ - } - } - - /* If expect_cond_assert is 2, we have just passed (?( and are expecting an - assertion, possibly preceded by a callout. If the value is 1, we have just - had the callout and expect an assertion. There must be at least 3 more - characters in all cases. When expect_cond_assert is 2, we know that the - current character is an opening parenthesis, as otherwise we wouldn't be - here. However, when it is 1, we need to check, and it's easiest just to check - always. Note that expect_cond_assert may be negative, since all callouts just - decrement it. */ - - if (expect_cond_assert > 0) - { - BOOL ok = c == CHAR_LEFT_PARENTHESIS && ptrend - ptr >= 3 && - (ptr[0] == CHAR_QUESTION_MARK || ptr[0] == CHAR_ASTERISK); - if (ok) - { - if (ptr[0] == CHAR_ASTERISK) /* New alpha assertion format, possibly */ - { - ok = MAX_255(ptr[1]) && (cb->ctypes[ptr[1]] & ctype_lcletter) != 0; - } - else switch(ptr[1]) /* Traditional symbolic format */ - { - case CHAR_C: - ok = expect_cond_assert == 2; - break; - - case CHAR_EQUALS_SIGN: - case CHAR_EXCLAMATION_MARK: - break; - - case CHAR_LESS_THAN_SIGN: - ok = ptr[2] == CHAR_EQUALS_SIGN || ptr[2] == CHAR_EXCLAMATION_MARK; - break; - - default: - ok = FALSE; - } - } - - if (!ok) - { - errorcode = ERR28; - if (expect_cond_assert == 2) goto FAILED; - goto FAILED_BACK; - } - } - - /* Remember whether we are expecting a conditional assertion, and set the - default for this item. */ - - prev_expect_cond_assert = expect_cond_assert; - expect_cond_assert = 0; - - /* Remember quantification status for the previous significant item, then set - default for this item. */ - - prev_okquantifier = okquantifier; - prev_meta_quantifier = meta_quantifier; - okquantifier = FALSE; - meta_quantifier = 0; - - /* If the previous significant item was a quantifier, adjust the parsed code - if there is a following modifier. The base meta value is always followed by - the PLUS and QUERY values, in that order. We do this here rather than after - reading a quantifier so that intervening comments and /x whitespace can be - ignored without having to replicate code. */ - - if (prev_meta_quantifier != 0 && (c == CHAR_QUESTION_MARK || c == CHAR_PLUS)) - { - parsed_pattern[(prev_meta_quantifier == META_MINMAX)? -3 : -1] = - prev_meta_quantifier + ((c == CHAR_QUESTION_MARK)? - 0x00020000u : 0x00010000u); - continue; /* Next character in pattern */ - } - - /* Process the next item in the main part of a pattern. */ - - switch(c) - { - default: /* Non-special character */ - PARSED_LITERAL(c, parsed_pattern); - break; - - - /* ---- Escape sequence ---- */ - - case CHAR_BACKSLASH: - tempptr = ptr; - escape = PRIV(check_escape)(&ptr, ptrend, &c, &errorcode, options, - xoptions, cb->bracount, FALSE, cb); - if (errorcode != 0) - { - ESCAPE_FAILED: - if ((xoptions & PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL) == 0) - goto FAILED; - ptr = tempptr; - if (ptr >= ptrend) c = CHAR_BACKSLASH; else - { - GETCHARINCTEST(c, ptr); /* Get character value, increment pointer */ - } - escape = 0; /* Treat as literal character */ - } - - /* The escape was a data escape or literal character. */ - - if (escape == 0) - { - PARSED_LITERAL(c, parsed_pattern); - } - - /* The escape was a back (or forward) reference. We keep the offset in - order to give a more useful diagnostic for a bad forward reference. For - references to groups numbered less than 10 we can't use more than two items - in parsed_pattern because they may be just two characters in the input (and - in a 64-bit world an offset may need two elements). So for them, the offset - of the first occurrent is held in a special vector. */ - - else if (escape < 0) - { - offset = (PCRE2_SIZE)(ptr - cb->start_pattern); - escape = -escape - 1; - *parsed_pattern++ = META_BACKREF | (uint32_t)escape; - if (escape < 10) - { - if (cb->small_ref_offset[escape] == PCRE2_UNSET) - cb->small_ref_offset[escape] = offset; - } - else - { - PUTOFFSET(offset, parsed_pattern); - } - okquantifier = TRUE; - } - - /* The escape was a character class such as \d etc. or other special - escape indicator such as \A or \X. Most of them generate just a single - parsed item, but \P and \p are followed by a 16-bit type and a 16-bit - value. They are supported only when Unicode is available. The type and - value are packed into a single 32-bit value so that the whole sequences - uses only two elements in the parsed_vector. This is because the same - coding is used if \d (for example) is turned into \p{Nd} when PCRE2_UCP is - set. - - There are also some cases where the escape sequence is followed by a name: - \k{name}, \k, and \k'name' are backreferences by name, and \g - and \g'name' are subroutine calls by name; \g{name} is a synonym for - \k{name}. Note that \g and \g'number' are handled by check_escape() - and returned as a negative value (handled above). A name is coded as an - offset into the pattern and a length. */ - - else switch (escape) - { - case ESC_C: -#ifdef NEVER_BACKSLASH_C - errorcode = ERR85; - goto ESCAPE_FAILED; -#else - if ((options & PCRE2_NEVER_BACKSLASH_C) != 0) - { - errorcode = ERR83; - goto ESCAPE_FAILED; - } -#endif - okquantifier = TRUE; - *parsed_pattern++ = META_ESCAPE + escape; - break; - - /* This is a special return that happens only in EXTRA_ALT_BSUX mode, - when \u{ is not followed by hex digits and }. It requests two literal - characters, u and { and we need this, as otherwise \u{ 12} (for example) - would be treated as u{12} now that spaces are allowed in quantifiers. */ - - case ESC_ub: - *parsed_pattern++ = CHAR_u; - PARSED_LITERAL(CHAR_LEFT_CURLY_BRACKET, parsed_pattern); - break; - - case ESC_X: -#ifndef SUPPORT_UNICODE - errorcode = ERR45; /* Supported only with Unicode support */ - goto ESCAPE_FAILED; -#endif - case ESC_H: - case ESC_h: - case ESC_N: - case ESC_R: - case ESC_V: - case ESC_v: - okquantifier = TRUE; - *parsed_pattern++ = META_ESCAPE + escape; - break; - - default: /* \A, \B, \b, \G, \K, \Z, \z cannot be quantified. */ - *parsed_pattern++ = META_ESCAPE + escape; - break; - - /* Escapes that may change in UCP mode. */ - - case ESC_d: - case ESC_D: - case ESC_s: - case ESC_S: - case ESC_w: - case ESC_W: - okquantifier = TRUE; - parsed_pattern = handle_escdsw(escape, parsed_pattern, options, - xoptions); - break; - - /* Unicode property matching */ - - case ESC_P: - case ESC_p: -#ifdef SUPPORT_UNICODE - { - BOOL negated; - uint16_t ptype = 0, pdata = 0; - if (!get_ucp(&ptr, utf, &negated, &ptype, &pdata, &errorcode, cb)) - goto ESCAPE_FAILED; - if (negated) escape = (escape == ESC_P)? ESC_p : ESC_P; - *parsed_pattern++ = META_ESCAPE + escape; - *parsed_pattern++ = (ptype << 16) | pdata; - okquantifier = TRUE; - } -#else - errorcode = ERR45; - goto ESCAPE_FAILED; -#endif - break; /* End \P and \p */ - - /* When \g is used with quotes or angle brackets as delimiters, it is a - numerical or named subroutine call, and control comes here. When used - with brace delimiters it is a numerical back reference and does not come - here because check_escape() returns it directly as a reference. \k is - always a named back reference. */ - - case ESC_g: - case ESC_k: - if (ptr >= ptrend || (*ptr != CHAR_LEFT_CURLY_BRACKET && - *ptr != CHAR_LESS_THAN_SIGN && *ptr != CHAR_APOSTROPHE)) - { - errorcode = (escape == ESC_g)? ERR57 : ERR69; - goto ESCAPE_FAILED; - } - terminator = (*ptr == CHAR_LESS_THAN_SIGN)? - CHAR_GREATER_THAN_SIGN : (*ptr == CHAR_APOSTROPHE)? - CHAR_APOSTROPHE : CHAR_RIGHT_CURLY_BRACKET; - - /* For a non-braced \g, check for a numerical recursion. */ - - if (escape == ESC_g && terminator != CHAR_RIGHT_CURLY_BRACKET) - { - PCRE2_SPTR p = ptr + 1; - - if (read_number(&p, ptrend, cb->bracount, MAX_GROUP_NUMBER, ERR61, &i, - &errorcode)) - { - if (p >= ptrend || *p != terminator) - { - ptr = p; - errorcode = ERR119; /* Missing terminator for number */ - goto ESCAPE_FAILED; - } - ptr = p + 1; - goto SET_RECURSION; - } - if (errorcode != 0) goto ESCAPE_FAILED; - } - - /* Not a numerical recursion. Perl allows spaces and tabs after { and - before } but not for other delimiters. */ - - if (!read_name(&ptr, ptrend, utf, terminator, &offset, &name, &namelen, - &errorcode, cb)) goto ESCAPE_FAILED; - - /* \k and \g when used with braces are back references, whereas \g used - with quotes or angle brackets is a recursion */ - - *parsed_pattern++ = - (escape == ESC_k || terminator == CHAR_RIGHT_CURLY_BRACKET)? - META_BACKREF_BYNAME : META_RECURSE_BYNAME; - *parsed_pattern++ = namelen; - - PUTOFFSET(offset, parsed_pattern); - okquantifier = TRUE; - break; /* End special escape processing */ - } - break; /* End escape sequence processing */ - - - /* ---- Single-character special items ---- */ - - case CHAR_CIRCUMFLEX_ACCENT: - *parsed_pattern++ = META_CIRCUMFLEX; - break; - - case CHAR_DOLLAR_SIGN: - *parsed_pattern++ = META_DOLLAR; - break; - - case CHAR_DOT: - *parsed_pattern++ = META_DOT; - okquantifier = TRUE; - break; - - - /* ---- Single-character quantifiers ---- */ - - case CHAR_ASTERISK: - meta_quantifier = META_ASTERISK; - goto CHECK_QUANTIFIER; - - case CHAR_PLUS: - meta_quantifier = META_PLUS; - goto CHECK_QUANTIFIER; - - case CHAR_QUESTION_MARK: - meta_quantifier = META_QUERY; - goto CHECK_QUANTIFIER; - - - /* ---- Potential {n,m} quantifier ---- */ - - case CHAR_LEFT_CURLY_BRACKET: - if (!read_repeat_counts(&ptr, ptrend, &min_repeat, &max_repeat, - &errorcode)) - { - if (errorcode != 0) goto FAILED; /* Error in quantifier. */ - PARSED_LITERAL(c, parsed_pattern); /* Not a quantifier */ - break; /* No more quantifier processing */ - } - meta_quantifier = META_MINMAX; - /* Fall through */ - - - /* ---- Quantifier post-processing ---- */ - - /* Check that a quantifier is allowed after the previous item. This - guarantees that there is a previous item. */ - - CHECK_QUANTIFIER: - if (!prev_okquantifier) - { - errorcode = ERR9; - goto FAILED; - } - - /* Most (*VERB)s are not allowed to be quantified, but an ungreedy - quantifier can be useful for (*ACCEPT) - meaning "succeed on backtrack", a - sort of negated (*COMMIT). We therefore allow (*ACCEPT) to be quantified by - wrapping it in non-capturing brackets, but we have to allow for a preceding - (*MARK) for when (*ACCEPT) has an argument. */ - - if (*prev_parsed_item == META_ACCEPT) - { - uint32_t *p; - for (p = parsed_pattern - 1; p >= verbstartptr; p--) p[1] = p[0]; - *verbstartptr = META_NOCAPTURE; - parsed_pattern[1] = META_KET; - parsed_pattern += 2; - -#ifdef PCRE2_DEBUG - PCRE2_ASSERT(parsed_pattern_extra >= 2); - parsed_pattern_extra -= 2; -#endif - } - - /* Now we can put the quantifier into the parsed pattern vector. At this - stage, we have only the basic quantifier. The check for a following + or ? - modifier happens at the top of the loop, after any intervening comments - have been removed. */ - - *parsed_pattern++ = meta_quantifier; - if (c == CHAR_LEFT_CURLY_BRACKET) - { - *parsed_pattern++ = min_repeat; - *parsed_pattern++ = max_repeat; - } - break; - - - /* ---- Character class ---- */ - - case CHAR_LEFT_SQUARE_BRACKET: - - /* In another (POSIX) regex library, the ugly syntax [[:<:]] and [[:>:]] is - used for "start of word" and "end of word". As these are otherwise illegal - sequences, we don't break anything by recognizing them. They are replaced - by \b(?=\w) and \b(?<=\w) respectively. Sequences like [a[:<:]] are - erroneous and are handled by the normal code below. */ - - if (ptrend - ptr >= 6 && - (PRIV(strncmp_c8)(ptr, STRING_WEIRD_STARTWORD, 6) == 0 || - PRIV(strncmp_c8)(ptr, STRING_WEIRD_ENDWORD, 6) == 0)) - { - *parsed_pattern++ = META_ESCAPE + ESC_b; - - if (ptr[2] == CHAR_LESS_THAN_SIGN) - { - *parsed_pattern++ = META_LOOKAHEAD; - } - else - { - *parsed_pattern++ = META_LOOKBEHIND; - *has_lookbehind = TRUE; - - /* The offset is used only for the "non-fixed length" error; this won't - occur here, so just store zero. */ - - PUTOFFSET((PCRE2_SIZE)0, parsed_pattern); - } - - if ((options & PCRE2_UCP) == 0) - *parsed_pattern++ = META_ESCAPE + ESC_w; - else - { - *parsed_pattern++ = META_ESCAPE + ESC_p; - *parsed_pattern++ = PT_WORD << 16; - } - *parsed_pattern++ = META_KET; - ptr += 6; - okquantifier = TRUE; - break; - } - - /* PCRE supports POSIX class stuff inside a class. Perl gives an error if - they are encountered at the top level, so we'll do that too. */ - - if (ptr < ptrend && (*ptr == CHAR_COLON || *ptr == CHAR_DOT || - *ptr == CHAR_EQUALS_SIGN) && - check_posix_syntax(ptr, ptrend, &tempptr)) - { - errorcode = (*ptr-- == CHAR_COLON)? ERR12 : ERR13; - ptr = tempptr + 2; - goto FAILED; - } - - class_mode_state = ((options & PCRE2_ALT_EXTENDED_CLASS) != 0)? - CLASS_MODE_ALT_EXT : CLASS_MODE_NORMAL; - - /* Jump here from '(?[...])'. That jump must initialize class_mode_state, - set c to the '[' character, and ptr to just after the '['. */ - - FROM_PERL_EXTENDED_CLASS: - okquantifier = TRUE; - - /* In an EBCDIC environment, Perl treats alphabetic ranges specially - because there are holes in the encoding, and simply using the range A-Z - (for example) would include the characters in the holes. This applies only - to ranges where both values are literal; [\xC1-\xE9] is different to [A-Z] - in this respect. In order to accommodate this, we keep track of whether - character values are literal or not, and a state variable for handling - ranges. */ - - /* Loop for the contents of the class. Classes may be nested, if - PCRE2_ALT_EXTENDED_CLASS is set, or the class is of the form (?[...]). */ - - /* c is still set to '[' so the loop will handle the start of the class. */ - - class_depth_m1 = -1; - class_maxdepth_m1 = -1; - class_range_state = RANGE_NO; - class_op_state = CLASS_OP_EMPTY; - class_start = NULL; - - for (;;) - { - BOOL char_is_literal = TRUE; - - /* Inside \Q...\E everything is literal except \E */ - - if (inescq) - { - if (c == CHAR_BACKSLASH && ptr < ptrend && *ptr == CHAR_E) - { - inescq = FALSE; /* Reset literal state */ - ptr++; /* Skip the 'E' */ - goto CLASS_CONTINUE; - } - - /* Surprisingly, you cannot use \Q..\E to escape a character inside a - Perl extended class. However, empty \Q\E sequences are allowed, so here - were're only giving an error if the \Q..\E is non-empty. */ - - if (class_mode_state == CLASS_MODE_PERL_EXT) - { - errorcode = ERR116; - goto FAILED; - } - - goto CLASS_LITERAL; - } - - /* Skip over space and tab (only) in extended-more mode, or anywhere - inside a Perl extended class (which implies /xx). */ - - if ((c == CHAR_SPACE || c == CHAR_HT) && - ((options & PCRE2_EXTENDED_MORE) != 0 || - class_mode_state >= CLASS_MODE_PERL_EXT)) - goto CLASS_CONTINUE; - - /* Handle POSIX class names. Perl allows a negation extension of the - form [:^name:]. A square bracket that doesn't match the syntax is - treated as a literal. We also recognize the POSIX constructions - [.ch.] and [=ch=] ("collating elements") and fault them, as Perl - 5.6 and 5.8 do. */ - - if (class_depth_m1 >= 0 && - c == CHAR_LEFT_SQUARE_BRACKET && - ptrend - ptr >= 3 && - (*ptr == CHAR_COLON || *ptr == CHAR_DOT || - *ptr == CHAR_EQUALS_SIGN) && - check_posix_syntax(ptr, ptrend, &tempptr)) - { - BOOL posix_negate = FALSE; - int posix_class; - - /* Perl treats a hyphen before a POSIX class as a literal, not the - start of a range. However, it gives a warning in its warning mode. PCRE - does not have a warning mode, so we give an error, because this is - likely an error on the user's part. */ - - if (class_range_state == RANGE_STARTED) - { - ptr = tempptr + 2; - errorcode = ERR50; - goto FAILED; - } - - /* Perl treats a hyphen after a POSIX class as a literal, not the - start of a range. However, it gives a warning in its warning mode - unless the hyphen is the last character in the class. PCRE does not - have a warning mode, so we give an error, because this is likely an - error on the user's part. - - Roll back to the hyphen for the error position. */ - - if (class_range_state == RANGE_FORBID_STARTED) - { - ptr = class_range_forbid_ptr; - errorcode = ERR50; - goto FAILED; - } - - /* Disallow implicit union in Perl extended classes. */ - - if (class_op_state == CLASS_OP_OPERAND && - class_mode_state == CLASS_MODE_PERL_EXT) - { - ptr = tempptr + 2; - errorcode = ERR113; - goto FAILED; - } - - if (*ptr != CHAR_COLON) - { - ptr = tempptr + 2; - errorcode = ERR13; - goto FAILED; - } - - if (*(++ptr) == CHAR_CIRCUMFLEX_ACCENT) - { - posix_negate = TRUE; - ptr++; - } - - posix_class = check_posix_name(ptr, (int)(tempptr - ptr)); - ptr = tempptr + 2; - if (posix_class < 0) - { - errorcode = ERR30; - goto FAILED; - } - - /* Set "a hyphen is forbidden to be the start of a range". For the '-]' - case, the hyphen is treated as a literal, but for '-1' it is disallowed - (because it would be interpreted as range). */ - - class_range_state = RANGE_FORBID_NO; - class_op_state = CLASS_OP_OPERAND; - - /* When PCRE2_UCP is set, unless PCRE2_EXTRA_ASCII_POSIX is set, some - of the POSIX classes are converted to use Unicode properties \p or \P - or, in one case, \h or \H. The substitutes table has two values per - class, containing the type and value of a \p or \P item. The special - cases are specified with a negative type: a non-zero value causes \h or - \H to be used, and a zero value falls through to behave like a non-UCP - POSIX class. There are now also some extra options that force ASCII for - some classes. */ - -#ifdef SUPPORT_UNICODE - if ((options & PCRE2_UCP) != 0 && - (xoptions & PCRE2_EXTRA_ASCII_POSIX) == 0 && - !((xoptions & PCRE2_EXTRA_ASCII_DIGIT) != 0 && - (posix_class == PC_DIGIT || posix_class == PC_XDIGIT))) - { - int ptype = posix_substitutes[2*posix_class]; - int pvalue = posix_substitutes[2*posix_class + 1]; - - if (ptype >= 0) - { - *parsed_pattern++ = META_ESCAPE + (posix_negate? ESC_P : ESC_p); - *parsed_pattern++ = (ptype << 16) | pvalue; - goto CLASS_CONTINUE; - } - - if (pvalue != 0) - { - *parsed_pattern++ = META_ESCAPE + (posix_negate? ESC_H : ESC_h); - goto CLASS_CONTINUE; - } - - /* Fall through */ - } -#endif /* SUPPORT_UNICODE */ - - /* Non-UCP POSIX class */ - - *parsed_pattern++ = posix_negate? META_POSIX_NEG : META_POSIX; - *parsed_pattern++ = posix_class; - } - - /* Check for the start of the outermost class, or the start of a nested class. */ - - else if ((c == CHAR_LEFT_SQUARE_BRACKET && - (class_depth_m1 < 0 || class_mode_state == CLASS_MODE_ALT_EXT || - class_mode_state == CLASS_MODE_PERL_EXT)) || - (c == CHAR_LEFT_PARENTHESIS && - class_mode_state == CLASS_MODE_PERL_EXT)) - { - uint32_t start_c = c; - uint32_t new_class_mode_state; - - /* Update the class mode, if moving into a 'leaf' inside a Perl extended - class. */ - - if (start_c == CHAR_LEFT_SQUARE_BRACKET && - class_mode_state == CLASS_MODE_PERL_EXT && class_depth_m1 >= 0) - new_class_mode_state = CLASS_MODE_PERL_EXT_LEAF; - else - new_class_mode_state = class_mode_state; - - /* Tidy up the other class before starting the nested class. */ - /* -[ beginning a nested class is a literal '-' */ - - if (class_range_state == RANGE_STARTED) - parsed_pattern[-1] = CHAR_MINUS; - - /* Disallow implicit union in Perl extended classes. */ - - if (class_op_state == CLASS_OP_OPERAND && - class_mode_state == CLASS_MODE_PERL_EXT) - { - errorcode = ERR113; - goto FAILED; - } - - /* Validate nesting depth */ - if (class_depth_m1 >= ECLASS_NEST_LIMIT - 1) - { - ptr--; /* Point rightwards at the paren, same as ERR19. */ - errorcode = ERR107; /* Classes too deeply nested */ - goto FAILED; - } - - /* Process the character class start. If the first character is '^', set - the negation flag. If the first few characters (either before or after ^) - are \Q\E or \E or space or tab in extended-more mode, we skip them too. - This makes for compatibility with Perl. */ - - negate_class = FALSE; - for (;;) - { - if (ptr >= ptrend) - { - if (start_c == CHAR_LEFT_PARENTHESIS) - errorcode = ERR14; /* Missing terminating ')' */ - else - errorcode = ERR6; /* Missing terminating ']' */ - goto FAILED; - } - - GETCHARINCTEST(c, ptr); - if (new_class_mode_state == CLASS_MODE_PERL_EXT) break; - else if (c == CHAR_BACKSLASH) - { - if (ptr < ptrend && *ptr == CHAR_E) ptr++; - else if (ptrend - ptr >= 3 && - PRIV(strncmp_c8)(ptr, STR_Q STR_BACKSLASH STR_E, 3) == 0) - ptr += 3; - else - break; - } - else if ((c == CHAR_SPACE || c == CHAR_HT) && /* Note: just these two */ - ((options & PCRE2_EXTENDED_MORE) != 0 || - new_class_mode_state >= CLASS_MODE_PERL_EXT)) - continue; - else if (!negate_class && c == CHAR_CIRCUMFLEX_ACCENT) - negate_class = TRUE; - else break; - } - - /* Now the real contents of the class; c has the first "real" character. - Empty classes are permitted only if the option is set, and if it's not - a Perl-extended class. */ - - if (c == CHAR_RIGHT_SQUARE_BRACKET && - (cb->external_options & PCRE2_ALLOW_EMPTY_CLASS) != 0 && - new_class_mode_state < CLASS_MODE_PERL_EXT) - { - PCRE2_ASSERT(start_c == CHAR_LEFT_SQUARE_BRACKET); - - if (class_start != NULL) - { - PCRE2_ASSERT(class_depth_m1 >= 0); - /* Represents that the class is an extended class. */ - *class_start |= CLASS_IS_ECLASS; - class_start = NULL; - } - - *parsed_pattern++ = negate_class? META_CLASS_EMPTY_NOT : META_CLASS_EMPTY; - - /* Leave nesting depth unchanged; but check for zero depth to handle the - very first (top-level) class being empty. */ - if (class_depth_m1 < 0) break; - - class_range_state = RANGE_NO; /* for processing the containing class */ - class_op_state = CLASS_OP_OPERAND; - goto CLASS_CONTINUE; - } - - /* Enter a non-empty class. */ - - if (class_start != NULL) - { - PCRE2_ASSERT(class_depth_m1 >= 0); - /* Represents that the class is an extended class. */ - *class_start |= CLASS_IS_ECLASS; - class_start = NULL; - } - - class_start = parsed_pattern; - *parsed_pattern++ = negate_class? META_CLASS_NOT : META_CLASS; - class_range_state = RANGE_NO; - class_op_state = CLASS_OP_EMPTY; - class_mode_state = new_class_mode_state; - ++class_depth_m1; - if (class_maxdepth_m1 < class_depth_m1) - class_maxdepth_m1 = class_depth_m1; - /* Reset; no op seen yet at new depth. */ - cb->class_op_used[class_depth_m1] = 0; - - /* Implement the special start-of-class literal meaning of ']'. */ - if (c == CHAR_RIGHT_SQUARE_BRACKET && - new_class_mode_state != CLASS_MODE_PERL_EXT) - { - class_range_state = RANGE_OK_LITERAL; - class_op_state = CLASS_OP_OPERAND; - PARSED_LITERAL(c, parsed_pattern); - goto CLASS_CONTINUE; - } - - continue; /* We have already loaded c with the next character */ - } - - /* Check for the end of the class. */ - - else if (c == CHAR_RIGHT_SQUARE_BRACKET || - (c == CHAR_RIGHT_PARENTHESIS && class_mode_state == CLASS_MODE_PERL_EXT)) - { - /* In Perl extended mode, the ']' can only be used to match the - opening '[', and ')' must match an opening parenthesis. */ - if (class_mode_state == CLASS_MODE_PERL_EXT) - { - if (c == CHAR_RIGHT_SQUARE_BRACKET && class_depth_m1 != 0) - { - errorcode = ERR14; - ptr--; /* Correct the offset */ - goto FAILED; - } - if (c == CHAR_RIGHT_PARENTHESIS && class_depth_m1 < 1) - { - errorcode = ERR22; - goto FAILED; - } - } - - /* Check no trailing operator. */ - if (class_op_state == CLASS_OP_OPERATOR) - { - errorcode = ERR110; - goto FAILED; - } - - /* Check no empty expression for Perl extended expressions. */ - if (class_mode_state == CLASS_MODE_PERL_EXT && - class_op_state == CLASS_OP_EMPTY) - { - errorcode = ERR114; - goto FAILED; - } - - /* -] at the end of a class is a literal '-' */ - if (class_range_state == RANGE_STARTED) - parsed_pattern[-1] = CHAR_MINUS; - - *parsed_pattern++ = META_CLASS_END; - - if (--class_depth_m1 < 0) - { - /* Check for and consume ')' after '(?[...]'. */ - PCRE2_ASSERT(class_mode_state != CLASS_MODE_PERL_EXT_LEAF); - if (class_mode_state == CLASS_MODE_PERL_EXT) - { - if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) - { - errorcode = ERR115; - goto FAILED; - } - - ptr++; - } - - break; - } - - class_range_state = RANGE_NO; /* for processing the containing class */ - class_op_state = CLASS_OP_OPERAND; - if (class_mode_state == CLASS_MODE_PERL_EXT_LEAF) - class_mode_state = CLASS_MODE_PERL_EXT; - /* The extended class flag has already - been set for the parent class. */ - class_start = NULL; - } - - /* Handle a Perl set binary operator */ - - else if (class_mode_state == CLASS_MODE_PERL_EXT && - (c == CHAR_PLUS || c == CHAR_VERTICAL_LINE || c == CHAR_MINUS || - c == CHAR_AMPERSAND || c == CHAR_CIRCUMFLEX_ACCENT)) - { - /* Check that there was a preceding operand. */ - if (class_op_state != CLASS_OP_OPERAND) - { - errorcode = ERR109; - goto FAILED; - } - - if (class_start != NULL) - { - PCRE2_ASSERT(class_depth_m1 >= 0); - /* Represents that the class is an extended class. */ - *class_start |= CLASS_IS_ECLASS; - class_start = NULL; - } - - PCRE2_ASSERT(class_range_state != RANGE_STARTED && - class_range_state != RANGE_FORBID_STARTED); - - *parsed_pattern++ = c == CHAR_PLUS? META_ECLASS_OR : - c == CHAR_VERTICAL_LINE? META_ECLASS_OR : - c == CHAR_MINUS? META_ECLASS_SUB : - c == CHAR_AMPERSAND? META_ECLASS_AND : - META_ECLASS_XOR; - class_range_state = RANGE_NO; - class_op_state = CLASS_OP_OPERATOR; - } - - /* Handle a Perl set unary operator */ - - else if (class_mode_state == CLASS_MODE_PERL_EXT && - c == CHAR_EXCLAMATION_MARK) - { - /* Check that the "!" has not got a preceding operand (i.e. it's the - start of the class, or follows an operator). */ - if (class_op_state == CLASS_OP_OPERAND) - { - errorcode = ERR113; - goto FAILED; - } - - if (class_start != NULL) - { - PCRE2_ASSERT(class_depth_m1 >= 0); - /* Represents that the class is an extended class. */ - *class_start |= CLASS_IS_ECLASS; - class_start = NULL; - } - - PCRE2_ASSERT(class_range_state != RANGE_STARTED && - class_range_state != RANGE_FORBID_STARTED); - - *parsed_pattern++ = META_ECLASS_NOT; - class_range_state = RANGE_NO; - class_op_state = CLASS_OP_OPERATOR; - } - - /* Handle a UTS#18 set operator */ - - else if (class_mode_state == CLASS_MODE_ALT_EXT && - (c == CHAR_VERTICAL_LINE || c == CHAR_MINUS || - c == CHAR_AMPERSAND || c == CHAR_TILDE) && - ptr < ptrend && *ptr == c) - { - ++ptr; - - /* Check there isn't a triple-repetition. */ - if (ptr < ptrend && *ptr == c) - { - while (ptr < ptrend && *ptr == c) ++ptr; /* Improve error offset. */ - errorcode = ERR108; - goto FAILED; - } - - /* Check for a preceding operand. */ - if (class_op_state != CLASS_OP_OPERAND) - { - errorcode = ERR109; - goto FAILED; - } - - /* Check for mixed precedence. Forbid [A--B&&C]. */ - if (cb->class_op_used[class_depth_m1] != 0 && - cb->class_op_used[class_depth_m1] != (uint8_t)c) - { - errorcode = ERR111; - goto FAILED; - } - - if (class_start != NULL) - { - PCRE2_ASSERT(class_depth_m1 >= 0); - /* Represents that the class is an extended class. */ - *class_start |= CLASS_IS_ECLASS; - class_start = NULL; - } - - /* Dangling '-' before an operator is a literal */ - if (class_range_state == RANGE_STARTED) - parsed_pattern[-1] = CHAR_MINUS; - - *parsed_pattern++ = c == CHAR_VERTICAL_LINE? META_ECLASS_OR : - c == CHAR_MINUS? META_ECLASS_SUB : - c == CHAR_AMPERSAND? META_ECLASS_AND : - META_ECLASS_XOR; - class_range_state = RANGE_NO; - class_op_state = CLASS_OP_OPERATOR; - cb->class_op_used[class_depth_m1] = (uint8_t)c; - } - - /* Handle escapes in a class */ - - else if (c == CHAR_BACKSLASH) - { - tempptr = ptr; - escape = PRIV(check_escape)(&ptr, ptrend, &c, &errorcode, options, - xoptions, cb->bracount, TRUE, cb); - - if (errorcode != 0) - { - if ((xoptions & PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL) == 0 || - class_mode_state >= CLASS_MODE_PERL_EXT) - goto FAILED; - ptr = tempptr; - if (ptr >= ptrend) c = CHAR_BACKSLASH; else - { - GETCHARINCTEST(c, ptr); /* Get character value, increment pointer */ - } - escape = 0; /* Treat as literal character */ - } - - switch(escape) - { - case 0: /* Escaped character code point is in c */ - char_is_literal = FALSE; - goto CLASS_LITERAL; /* (a few lines above) */ - - case ESC_b: - c = CHAR_BS; /* \b is backspace in a class */ - char_is_literal = FALSE; - goto CLASS_LITERAL; - - case ESC_k: - c = CHAR_k; /* \k is not special in a class, just like \g */ - char_is_literal = FALSE; - goto CLASS_LITERAL; - - case ESC_Q: - inescq = TRUE; /* Enter literal mode */ - goto CLASS_CONTINUE; - - case ESC_E: /* Ignore orphan \E */ - goto CLASS_CONTINUE; - - case ESC_B: /* Always an error in a class */ - case ESC_R: - case ESC_X: - errorcode = ERR7; - goto FAILED; - - case ESC_N: /* Not permitted by Perl either */ - errorcode = ERR71; - goto FAILED; - - case ESC_H: - case ESC_h: - case ESC_V: - case ESC_v: - *parsed_pattern++ = META_ESCAPE + escape; - break; - - /* These escapes may be converted to Unicode property tests when - PCRE2_UCP is set. */ - - case ESC_d: - case ESC_D: - case ESC_s: - case ESC_S: - case ESC_w: - case ESC_W: - parsed_pattern = handle_escdsw(escape, parsed_pattern, options, - xoptions); - break; - - /* Explicit Unicode property matching */ - - case ESC_P: - case ESC_p: -#ifdef SUPPORT_UNICODE - { - BOOL negated; - uint16_t ptype = 0, pdata = 0; - if (!get_ucp(&ptr, utf, &negated, &ptype, &pdata, &errorcode, cb)) - goto FAILED; - - /* In caseless matching, particular characteristics Lu, Ll, and Lt - get converted to the general characteristic L&. That is, upper, - lower, and title case letters are all conflated. */ - - if ((options & PCRE2_CASELESS) != 0 && ptype == PT_PC && - (pdata == ucp_Lu || pdata == ucp_Ll || pdata == ucp_Lt)) - { - ptype = PT_LAMP; - pdata = 0; - } - - if (negated) escape = (escape == ESC_P)? ESC_p : ESC_P; - *parsed_pattern++ = META_ESCAPE + escape; - *parsed_pattern++ = (ptype << 16) | pdata; - } -#else - errorcode = ERR45; - goto FAILED; -#endif - break; /* End \P and \p */ - - /* All others are not allowed in a class */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - PCRE2_FALLTHROUGH /* Fall through */ - /* LCOV_EXCL_STOP */ - - case ESC_A: - case ESC_Z: - case ESC_z: - case ESC_G: - case ESC_K: - case ESC_C: - errorcode = ERR7; - goto FAILED; - } - - /* All the switch-cases above which end in "break" describe a set - of characters. None may start a range. */ - - /* The second part of a range can be a single-character escape - sequence (detected above), but not any of the other escapes. Perl - treats a hyphen as a literal in such circumstances. However, in Perl's - warning mode, a warning is given, so PCRE now faults it, as it is - almost certainly a mistake on the user's part. */ - - if (class_range_state == RANGE_STARTED) - { - errorcode = ERR50; - goto FAILED; - } - - /* Perl gives a warning unless the hyphen following a multi-character - escape is the last character in the class. PCRE throws an error. */ - - if (class_range_state == RANGE_FORBID_STARTED) - { - ptr = class_range_forbid_ptr; - errorcode = ERR50; - goto FAILED; - } - - /* Disallow implicit union in Perl extended classes. */ - - if (class_op_state == CLASS_OP_OPERAND && - class_mode_state == CLASS_MODE_PERL_EXT) - { - errorcode = ERR113; - goto FAILED; - } - - class_range_state = RANGE_FORBID_NO; - class_op_state = CLASS_OP_OPERAND; - } - - /* Forbid unescaped literals, and the special meaning of '-', inside a - Perl extended class. */ - - else if (class_mode_state == CLASS_MODE_PERL_EXT) - { - errorcode = ERR116; - goto FAILED; - } - - /* Handle potential start of range */ - - else if (c == CHAR_MINUS && class_range_state >= RANGE_OK_ESCAPED) - { - *parsed_pattern++ = (class_range_state == RANGE_OK_LITERAL)? - META_RANGE_LITERAL : META_RANGE_ESCAPED; - class_range_state = RANGE_STARTED; - } - - /* Handle forbidden start of range */ - - else if (c == CHAR_MINUS && class_range_state == RANGE_FORBID_NO) - { - *parsed_pattern++ = CHAR_MINUS; - class_range_state = RANGE_FORBID_STARTED; - class_range_forbid_ptr = ptr; - } - - /* Handle a literal character */ - - else - { - CLASS_LITERAL: - - /* Disallow implicit union in Perl extended classes. */ - - if (class_op_state == CLASS_OP_OPERAND && - class_mode_state == CLASS_MODE_PERL_EXT) - { - errorcode = ERR113; - goto FAILED; - } - - if (class_range_state == RANGE_STARTED) - { - if (c == parsed_pattern[-2]) /* Optimize one-char range */ - parsed_pattern--; - else if (parsed_pattern[-2] > c) /* Check range is in order */ - { - errorcode = ERR8; - goto FAILED; - } - else - { - if (!char_is_literal && parsed_pattern[-1] == META_RANGE_LITERAL) - parsed_pattern[-1] = META_RANGE_ESCAPED; - PARSED_LITERAL(c, parsed_pattern); - } - class_range_state = RANGE_NO; - class_op_state = CLASS_OP_OPERAND; - } - else if (class_range_state == RANGE_FORBID_STARTED) - { - ptr = class_range_forbid_ptr; - errorcode = ERR50; - goto FAILED; - } - else /* Potential start of range */ - { - class_range_state = char_is_literal? - RANGE_OK_LITERAL : RANGE_OK_ESCAPED; - class_op_state = CLASS_OP_OPERAND; - PARSED_LITERAL(c, parsed_pattern); - } - } - - /* Proceed to next thing in the class. */ - - CLASS_CONTINUE: - if (ptr >= ptrend) - { - if (class_mode_state == CLASS_MODE_PERL_EXT && class_depth_m1 > 0) - errorcode = ERR14; /* Missing terminating ')' */ - if (class_mode_state == CLASS_MODE_ALT_EXT && - class_depth_m1 == 0 && class_maxdepth_m1 == 1) - errorcode = ERR112; /* Missing terminating ']', but we saw '[ [ ]...' */ - else - errorcode = ERR6; /* Missing terminating ']' */ - goto FAILED; - } - GETCHARINCTEST(c, ptr); - } /* End of class-processing loop */ - - break; /* End of character class */ - - - /* ---- Opening parenthesis ---- */ - - case CHAR_LEFT_PARENTHESIS: - if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - - /* If ( is not followed by ? it is either a capture or a special verb or an - alpha assertion or a positive non-atomic lookahead. */ - - if (*ptr != CHAR_QUESTION_MARK) - { - const char *vn; - - /* Handle capturing brackets (or non-capturing if auto-capture is turned - off). */ - - if (*ptr != CHAR_ASTERISK) - { - nest_depth++; - if ((options & PCRE2_NO_AUTO_CAPTURE) == 0) - { - if (cb->bracount >= MAX_GROUP_NUMBER) - { - errorcode = ERR97; - goto FAILED; - } - cb->bracount++; - *parsed_pattern++ = META_CAPTURE | cb->bracount; - } - else *parsed_pattern++ = META_NOCAPTURE; - } - - /* Do nothing for (* followed by end of pattern or ) so it gives a "bad - quantifier" error rather than "(*MARK) must have an argument". */ - - else if (ptrend - ptr <= 1 || (c = ptr[1]) == CHAR_RIGHT_PARENTHESIS) - break; - - /* Handle "alpha assertions" such as (*pla:...). Most of these are - synonyms for the historical symbolic assertions, but the script run and - non-atomic lookaround ones are new. They are distinguished by starting - with a lower case letter. Checking both ends of the alphabet makes this - work in all character codes. */ - - else if (CHMAX_255(c) && (cb->ctypes[c] & ctype_lcletter) != 0) - { - uint32_t meta; - - vn = alasnames; - if (!read_name(&ptr, ptrend, utf, 0, &offset, &name, &namelen, - &errorcode, cb)) goto FAILED; - if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - if (*ptr != CHAR_COLON) - { - errorcode = ERR95; /* Malformed */ - goto FAILED_FORWARD; - } - - /* Scan the table of alpha assertion names */ - - for (i = 0; i < alascount; i++) - { - if (namelen == alasmeta[i].len && - PRIV(strncmp_c8)(name, vn, namelen) == 0) - break; - vn += alasmeta[i].len + 1; - } - - if (i >= alascount) - { - errorcode = ERR95; /* Alpha assertion not recognized */ - goto FAILED; - } - - /* Check for expecting an assertion condition. If so, only atomic - lookaround assertions are valid. */ - - meta = alasmeta[i].meta; - if (prev_expect_cond_assert > 0 && - (meta < META_LOOKAHEAD || meta > META_LOOKBEHINDNOT)) - { - errorcode = ERR28; /* Atomic assertion expected */ - goto FAILED; - } - - /* The lookaround alphabetic synonyms can mostly be handled by jumping - to the code that handles the traditional symbolic forms. */ - - switch(meta) - { - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR89; /* Unknown code; should never occur because */ - goto FAILED; /* the meta values come from a table above. */ - /* LCOV_EXCL_STOP */ - - case META_ATOMIC: - goto ATOMIC_GROUP; - - case META_LOOKAHEAD: - goto POSITIVE_LOOK_AHEAD; - - case META_LOOKAHEAD_NA: - goto POSITIVE_NONATOMIC_LOOK_AHEAD; - - case META_LOOKAHEADNOT: - goto NEGATIVE_LOOK_AHEAD; - - case META_SCS: - ptr++; - *parsed_pattern++ = META_SCS; - - parsed_pattern = parse_capture_list(&ptr, ptrend, utf, parsed_pattern, - 0, &errorcode, cb); - if (parsed_pattern == NULL) goto FAILED; - goto POST_ASSERTION; - - case META_LOOKBEHIND: - case META_LOOKBEHINDNOT: - case META_LOOKBEHIND_NA: - *parsed_pattern++ = meta; - ptr--; - goto POST_LOOKBEHIND; - - /* The script run facilities are handled here. Unicode support is - required (give an error if not, as this is a security issue). Always - record a META_SCRIPT_RUN item. Then, for the atomic version, insert - META_ATOMIC and remember that we need two META_KETs at the end. */ - - case META_SCRIPT_RUN: - case META_ATOMIC_SCRIPT_RUN: -#ifdef SUPPORT_UNICODE - *parsed_pattern++ = META_SCRIPT_RUN; - nest_depth++; - ptr++; - if (meta == META_ATOMIC_SCRIPT_RUN) - { - *parsed_pattern++ = META_ATOMIC; - if (top_nest == NULL) top_nest = (nest_save *)(cb->start_workspace); - else if (++top_nest >= end_nests) - { - errorcode = ERR84; - goto FAILED; - } - top_nest->nest_depth = nest_depth; - top_nest->flags = NSF_ATOMICSR; - top_nest->options = options & PARSE_TRACKED_OPTIONS; - top_nest->xoptions = xoptions & PARSE_TRACKED_EXTRA_OPTIONS; - -#ifdef PCRE2_DEBUG - /* We'll write out two META_KETs for a single ")" in the input - pattern, so we reserve space for that in our bounds check. */ - parsed_pattern_extra++; -#endif - } - break; -#else /* SUPPORT_UNICODE */ - errorcode = ERR96; - goto FAILED; -#endif - } - } - - - /* ---- Handle (*VERB) and (*VERB:NAME) ---- */ - - else - { - vn = verbnames; - if (!read_name(&ptr, ptrend, utf, 0, &offset, &name, &namelen, - &errorcode, cb)) goto FAILED; - if (ptr >= ptrend || (*ptr != CHAR_COLON && - *ptr != CHAR_RIGHT_PARENTHESIS)) - { - errorcode = ERR60; /* Malformed */ - goto FAILED; - } - - /* Scan the table of verb names */ - - for (i = 0; i < verbcount; i++) - { - if (namelen == verbs[i].len && - PRIV(strncmp_c8)(name, vn, namelen) == 0) - break; - vn += verbs[i].len + 1; - } - - if (i >= verbcount) - { - errorcode = ERR60; /* Verb not recognized */ - goto FAILED; - } - - /* An empty argument is treated as no argument. */ - - if (*ptr == CHAR_COLON && ptr + 1 < ptrend && - ptr[1] == CHAR_RIGHT_PARENTHESIS) - ptr++; /* Advance to the closing parens */ - - /* Check for mandatory non-empty argument; this is (*MARK) */ - - if (verbs[i].has_arg > 0 && *ptr != CHAR_COLON) - { - errorcode = ERR66; - goto FAILED; - } - - /* Remember where this verb, possibly with a preceding (*MARK), starts, - for handling quantified (*ACCEPT). */ - - verbstartptr = parsed_pattern; - okquantifier = (verbs[i].meta == META_ACCEPT); -#ifdef PCRE2_DEBUG - /* Reserve space in our bounds check for optionally wrapping the (*ACCEPT) - with a non-capturing bracket, if there is a following quantifier. */ - if (okquantifier) parsed_pattern_extra += 2; -#endif - - /* It appears that Perl allows any characters whatsoever, other than a - closing parenthesis, to appear in arguments ("names"), so we no longer - insist on letters, digits, and underscores. Perl does not, however, do - any interpretation within arguments, and has no means of including a - closing parenthesis. PCRE supports escape processing but only when it - is requested by an option. We set inverbname TRUE here, and let the - main loop take care of this so that escape and \x processing is done by - the main code above. */ - - if (*ptr++ == CHAR_COLON) /* Skip past : or ) */ - { - /* Some optional arguments can be treated as a preceding (*MARK) */ - - if (verbs[i].has_arg < 0) - { - add_after_mark = verbs[i].meta; - *parsed_pattern++ = META_MARK; - } - - /* The remaining verbs with arguments (except *MARK) need a different - opcode. */ - - else - { - *parsed_pattern++ = verbs[i].meta + - ((verbs[i].meta != META_MARK)? 0x00010000u:0); - } - - /* Set up for reading the name in the main loop. */ - - verblengthptr = parsed_pattern++; - verbnamestart = ptr; - inverbname = TRUE; - } - else /* No verb "name" argument */ - { - *parsed_pattern++ = verbs[i].meta; - } - } /* End of (*VERB) handling */ - break; /* Done with this parenthesis */ - } /* End of groups that don't start with (? */ - - - /* ---- Items starting (? ---- */ - - /* The type of item is determined by what follows (?. Handle (?| and option - changes under "default" because both need a new block on the nest stack. - Comments starting with (?# are handled above. Note that there is some - ambiguity about the sequence (?- because if a digit follows it's a relative - recursion or subroutine call whereas otherwise it's an option unsetting. */ - - if (++ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - - switch(*ptr) - { - default: - if (*ptr == CHAR_MINUS && ptrend - ptr > 1 && IS_DIGIT(ptr[1])) - goto RECURSION_BYNUMBER; /* The + case is handled by CHAR_PLUS */ - - /* We now have either (?| or a (possibly empty) option setting, - optionally followed by a non-capturing group. */ - - nest_depth++; - if (top_nest == NULL) top_nest = (nest_save *)(cb->start_workspace); - else if (++top_nest >= end_nests) - { - errorcode = ERR84; - goto FAILED; - } - top_nest->nest_depth = nest_depth; - top_nest->flags = 0; - top_nest->options = options & PARSE_TRACKED_OPTIONS; - top_nest->xoptions = xoptions & PARSE_TRACKED_EXTRA_OPTIONS; - - /* Start of non-capturing group that resets the capture count for each - branch. */ - - if (*ptr == CHAR_VERTICAL_LINE) - { - top_nest->reset_group = (uint16_t)cb->bracount; - top_nest->max_group = (uint16_t)cb->bracount; - top_nest->flags |= NSF_RESET; - cb->external_flags |= PCRE2_DUPCAPUSED; - *parsed_pattern++ = META_NOCAPTURE; - ptr++; - } - - /* Scan for options imnrsxJU to be set or unset. */ - - else - { - BOOL hyphenok = TRUE; - uint32_t oldoptions = options; - uint32_t oldxoptions = xoptions; - - top_nest->reset_group = 0; - top_nest->max_group = 0; - set = unset = 0; - optset = &set; - xset = xunset = 0; - xoptset = &xset; - - /* ^ at the start unsets irmnsx and disables the subsequent use of - */ - - if (ptr < ptrend && *ptr == CHAR_CIRCUMFLEX_ACCENT) - { - options &= ~(PCRE2_CASELESS|PCRE2_MULTILINE|PCRE2_NO_AUTO_CAPTURE| - PCRE2_DOTALL|PCRE2_EXTENDED|PCRE2_EXTENDED_MORE); - xoptions &= ~(PCRE2_EXTRA_CASELESS_RESTRICT); - hyphenok = FALSE; - ptr++; - } - - while (ptr < ptrend && *ptr != CHAR_RIGHT_PARENTHESIS && - *ptr != CHAR_COLON) - { - switch (*ptr++) - { - case CHAR_MINUS: - if (!hyphenok) - { - errorcode = ERR94; - goto FAILED; - } - optset = &unset; - xoptset = &xunset; - hyphenok = FALSE; - break; - - /* There are some two-character sequences that start with 'a'. */ - - case CHAR_a: - if (ptr < ptrend) - { - if (*ptr == CHAR_D) - { - *xoptset |= PCRE2_EXTRA_ASCII_BSD; - ptr++; - break; - } - if (*ptr == CHAR_P) - { - *xoptset |= (PCRE2_EXTRA_ASCII_POSIX|PCRE2_EXTRA_ASCII_DIGIT); - ptr++; - break; - } - if (*ptr == CHAR_S) - { - *xoptset |= PCRE2_EXTRA_ASCII_BSS; - ptr++; - break; - } - if (*ptr == CHAR_T) - { - *xoptset |= PCRE2_EXTRA_ASCII_DIGIT; - ptr++; - break; - } - if (*ptr == CHAR_W) - { - *xoptset |= PCRE2_EXTRA_ASCII_BSW; - ptr++; - break; - } - } - *xoptset |= PCRE2_EXTRA_ASCII_BSD|PCRE2_EXTRA_ASCII_BSS| - PCRE2_EXTRA_ASCII_BSW| - PCRE2_EXTRA_ASCII_DIGIT|PCRE2_EXTRA_ASCII_POSIX; - break; - - case CHAR_J: /* Record that it changed in the external options */ - *optset |= PCRE2_DUPNAMES; - cb->external_flags |= PCRE2_JCHANGED; - break; - - case CHAR_i: *optset |= PCRE2_CASELESS; break; - case CHAR_m: *optset |= PCRE2_MULTILINE; break; - case CHAR_n: *optset |= PCRE2_NO_AUTO_CAPTURE; break; - case CHAR_r: *xoptset|= PCRE2_EXTRA_CASELESS_RESTRICT; break; - case CHAR_s: *optset |= PCRE2_DOTALL; break; - case CHAR_U: *optset |= PCRE2_UNGREEDY; break; - - /* If x appears twice it sets the extended extended option. */ - - case CHAR_x: - *optset |= PCRE2_EXTENDED; - if (ptr < ptrend && *ptr == CHAR_x) - { - *optset |= PCRE2_EXTENDED_MORE; - ptr++; - } - break; - - default: - errorcode = ERR11; - goto FAILED; - } - } - - /* If we are setting extended without extended-more, ensure that any - existing extended-more gets unset. Also, unsetting extended must also - unset extended-more. */ - - if ((set & (PCRE2_EXTENDED|PCRE2_EXTENDED_MORE)) == PCRE2_EXTENDED || - (unset & PCRE2_EXTENDED) != 0) - unset |= PCRE2_EXTENDED_MORE; - - options = (options | set) & (~unset); - xoptions = (xoptions | xset) & (~xunset); - - /* If the options ended with ')' this is not the start of a nested - group with option changes, so the options change at this level. - In this case, if the previous level set up a nest block, discard the - one we have just created. Otherwise adjust it for the previous level. - If the options ended with ':' we are starting a non-capturing group, - possibly with an options setting. */ - - if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - if (*ptr++ == CHAR_RIGHT_PARENTHESIS) - { - nest_depth--; /* This is not a nested group after all. */ - if (top_nest > (nest_save *)(cb->start_workspace) && - (top_nest-1)->nest_depth == nest_depth) top_nest--; - else top_nest->nest_depth = nest_depth; - } - else *parsed_pattern++ = META_NOCAPTURE; - - /* If nothing changed, no need to record. */ - - if (options != oldoptions || xoptions != oldxoptions) - { - *parsed_pattern++ = META_OPTIONS; - *parsed_pattern++ = options; - *parsed_pattern++ = xoptions; - } - } /* End options processing */ - break; /* End default case after (? */ - - - /* ---- Python syntax support ---- */ - - case CHAR_P: - if (++ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - - /* (?P is the same as (?, which defines a named group. */ - - if (*ptr == CHAR_LESS_THAN_SIGN) - { - terminator = CHAR_GREATER_THAN_SIGN; - goto DEFINE_NAME; - } - - /* (?P>name) is the same as (?&name), which is a recursion or subroutine - call. */ - - if (*ptr == CHAR_GREATER_THAN_SIGN) goto RECURSE_BY_NAME; - - /* (?P=name) is the same as \k, a back reference by name. Anything - else after (?P is an error. */ - - if (*ptr != CHAR_EQUALS_SIGN) - { - errorcode = ERR41; - goto FAILED_FORWARD; - } - if (!read_name(&ptr, ptrend, utf, CHAR_RIGHT_PARENTHESIS, &offset, &name, - &namelen, &errorcode, cb)) goto FAILED; - *parsed_pattern++ = META_BACKREF_BYNAME; - *parsed_pattern++ = namelen; - PUTOFFSET(offset, parsed_pattern); - okquantifier = TRUE; - break; /* End of (?P processing */ - - - /* ---- Recursion/subroutine calls by number ---- */ - - case CHAR_R: - i = 0; /* (?R) == (?R0) */ - ptr++; - if (ptr >= ptrend || (*ptr != CHAR_RIGHT_PARENTHESIS && *ptr != CHAR_LEFT_PARENTHESIS)) - { - errorcode = ERR58; - goto FAILED; - } - terminator = CHAR_NUL; - goto SET_RECURSION; - - /* An item starting (?- followed by a digit comes here via the "default" - case because (?- followed by a non-digit is an options setting. */ - - case CHAR_PLUS: - if (ptr + 1 >= ptrend) - { - ++ptr; - goto UNCLOSED_PARENTHESIS; - } - if (!IS_DIGIT(ptr[1])) - { - errorcode = ERR29; /* Missing number */ - ++ptr; - goto FAILED_FORWARD; - } - PCRE2_FALLTHROUGH /* Fall through */ - - case CHAR_0: case CHAR_1: case CHAR_2: case CHAR_3: case CHAR_4: - case CHAR_5: case CHAR_6: case CHAR_7: case CHAR_8: case CHAR_9: - RECURSION_BYNUMBER: - if (!read_number(&ptr, ptrend, - (IS_DIGIT(*ptr))? -1:(int)(cb->bracount), /* + and - are relative */ - MAX_GROUP_NUMBER, ERR61, - &i, &errorcode)) goto FAILED; - PCRE2_ASSERT(i >= 0); /* NB (?0) is permitted, represented by i=0 */ - terminator = CHAR_NUL; - - SET_RECURSION: - *parsed_pattern++ = META_RECURSE | (uint32_t)i; - offset = (PCRE2_SIZE)(ptr - cb->start_pattern); - /* End of recursive call by number handling */ - goto READ_RECURSION_ARGUMENTS; - - - /* ---- Recursion/subroutine calls by name ---- */ - - case CHAR_AMPERSAND: - RECURSE_BY_NAME: - if (!read_name(&ptr, ptrend, utf, 0, &offset, &name, - &namelen, &errorcode, cb)) goto FAILED; - *parsed_pattern++ = META_RECURSE_BYNAME; - *parsed_pattern++ = namelen; - terminator = CHAR_NUL; - - READ_RECURSION_ARGUMENTS: - PUTOFFSET(offset, parsed_pattern); - okquantifier = TRUE; - - /* Arguments are not supported for \g construct. */ - if (terminator != CHAR_NUL) break; - - if (ptr < ptrend && *ptr == CHAR_LEFT_PARENTHESIS) - { - parsed_pattern = parse_capture_list(&ptr, ptrend, utf, parsed_pattern, - offset, &errorcode, cb); - if (parsed_pattern == NULL) goto FAILED; - } - - if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) - goto UNCLOSED_PARENTHESIS; - - ptr++; - break; - - /* ---- Callout with numerical or string argument ---- */ - - case CHAR_C: - if ((xoptions & PCRE2_EXTRA_NEVER_CALLOUT) != 0) - { - ptr++; - errorcode = ERR103; - goto FAILED; - } - - if (++ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - - /* If the previous item was a condition starting (?(? an assertion, - optionally preceded by a callout, is expected. This is checked later on, - during actual compilation. However we need to identify this kind of - assertion in this pass because it must not be qualified. The value of - expect_cond_assert is set to 2 after (?(? is processed. We decrement it - for a callout - still leaving a positive value that identifies the - assertion. Multiple callouts or any other items will make it zero or - less, which doesn't matter because they will cause an error later. */ - - expect_cond_assert = prev_expect_cond_assert - 1; - - /* If previous_callout is not NULL, it means this follows a previous - callout. If it was a manual callout, do nothing; this means its "length - of next pattern item" field will remain zero. If it was an automatic - callout, abolish it. */ - - if (previous_callout != NULL && (options & PCRE2_AUTO_CALLOUT) != 0 && - previous_callout == parsed_pattern - 4 && - parsed_pattern[-1] == 255) - parsed_pattern = previous_callout; - - /* Save for updating next pattern item length, and skip one item before - completing. */ - - previous_callout = parsed_pattern; - after_manual_callout = 1; - - /* Handle a string argument; specific delimiter is required. */ - - if (*ptr != CHAR_RIGHT_PARENTHESIS && !IS_DIGIT(*ptr)) - { - PCRE2_SIZE calloutlength; - PCRE2_SPTR startptr = ptr; - - delimiter = 0; - for (i = 0; PRIV(callout_start_delims)[i] != 0; i++) - { - if (*ptr == PRIV(callout_start_delims)[i]) - { - delimiter = PRIV(callout_end_delims)[i]; - break; - } - } - if (delimiter == 0) - { - errorcode = ERR82; - goto FAILED_FORWARD; - } - - *parsed_pattern = META_CALLOUT_STRING; - parsed_pattern += 3; /* Skip pattern info */ - - for (;;) - { - if (++ptr >= ptrend) - { - errorcode = ERR81; - ptr = startptr; /* To give a more useful message */ - goto FAILED; - } - if (*ptr == delimiter && (++ptr >= ptrend || *ptr != delimiter)) - break; - } - - calloutlength = (PCRE2_SIZE)(ptr - startptr); - if (calloutlength > UINT32_MAX) - { - errorcode = ERR72; - goto FAILED; - } - *parsed_pattern++ = (uint32_t)calloutlength; - offset = (PCRE2_SIZE)(startptr - cb->start_pattern); - PUTOFFSET(offset, parsed_pattern); - } - - /* Handle a callout with an optional numerical argument, which must be - less than or equal to 255. A missing argument gives 0. */ - - else - { - int n = 0; - *parsed_pattern = META_CALLOUT_NUMBER; /* Numerical callout */ - parsed_pattern += 3; /* Skip pattern info */ - while (ptr < ptrend && IS_DIGIT(*ptr)) - { - n = n * 10 + (*ptr++ - CHAR_0); - if (n > 255) - { - errorcode = ERR38; - goto FAILED; - } - } - *parsed_pattern++ = n; - } - - /* Both formats must have a closing parenthesis */ - - if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) - { - errorcode = ERR39; - goto FAILED; - } - ptr++; - - /* Remember the offset to the next item in the pattern, and set a default - length. This should get updated after the next item is read. */ - - previous_callout[1] = (uint32_t)(ptr - cb->start_pattern); - previous_callout[2] = 0; - break; /* End callout */ - - - /* ---- Conditional group ---- */ - - /* A condition can be an assertion, a number (referring to a numbered - group's having been set), a name (referring to a named group), or 'R', - referring to overall recursion. R and R&name are also permitted - for recursion state tests. Numbers may be preceded by + or - to specify a - relative group number. - - There are several syntaxes for testing a named group: (?(name)) is used - by Python; Perl 5.10 onwards uses (?() or (?('name')). - - There are two unfortunate ambiguities. 'R' can be the recursive thing or - the name 'R' (and similarly for 'R' followed by digits). 'DEFINE' can be - the Perl DEFINE feature or the Python named test. We look for a name - first; if not found, we try the other case. - - For compatibility with auto-callouts, we allow a callout to be specified - before a condition that is an assertion. */ - - case CHAR_LEFT_PARENTHESIS: - if (++ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - nest_depth++; - - /* If the next character is ? or * there must be an assertion next - (optionally preceded by a callout). We do not check this here, but - instead we set expect_cond_assert to 2. If this is still greater than - zero (callouts decrement it) when the next assertion is read, it will be - marked as a condition that must not be repeated. A value greater than - zero also causes checking that an assertion (possibly with callout) - follows. */ - - if (*ptr == CHAR_QUESTION_MARK || *ptr == CHAR_ASTERISK) - { - *parsed_pattern++ = META_COND_ASSERT; - ptr--; /* Pull pointer back to the opening parenthesis. */ - expect_cond_assert = 2; - break; /* End of conditional */ - } - - /* Handle (?([+-]number)... */ - - if (read_number(&ptr, ptrend, cb->bracount, MAX_GROUP_NUMBER, ERR61, &i, - &errorcode)) - { - PCRE2_ASSERT(i >= 0); - if (i <= 0) - { - errorcode = ERR15; - goto FAILED; - } - *parsed_pattern++ = META_COND_NUMBER; - offset = (PCRE2_SIZE)(ptr - cb->start_pattern - 2); - PUTOFFSET(offset, parsed_pattern); - *parsed_pattern++ = i; - } - else if (errorcode != 0) goto FAILED; /* Number too big */ - - /* No number found. Handle the special case (?(VERSION[>]=n.m)... */ - - else if (ptrend - ptr >= 10 && - PRIV(strncmp_c8)(ptr, STRING_VERSION, 7) == 0 && - ptr[7] != CHAR_RIGHT_PARENTHESIS) - { - uint32_t ge = 0; - int major = 0; - int minor = 0; - - ptr += 7; - if (*ptr == CHAR_GREATER_THAN_SIGN) - { - ge = 1; - ptr++; - } - - /* NOTE: cannot write IS_DIGIT(*(++ptr)) here because IS_DIGIT - references its argument twice. */ - - if (*ptr != CHAR_EQUALS_SIGN || (ptr++, !IS_DIGIT(*ptr))) - { - errorcode = ERR79; - if (!ge) goto FAILED_FORWARD; - goto FAILED; - } - - if (!read_number(&ptr, ptrend, -1, 1000, ERR79, &major, &errorcode)) - goto FAILED; - - if (ptr < ptrend && *ptr == CHAR_DOT) - { - if (++ptr >= ptrend || !IS_DIGIT(*ptr)) - { - errorcode = ERR79; - if (ptr < ptrend) goto FAILED_FORWARD; - goto FAILED; - } - if (!read_number(&ptr, ptrend, -1, 1000, ERR79, &minor, &errorcode)) - goto FAILED; - } - if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) - { - errorcode = ERR79; - if (ptr < ptrend) goto FAILED_FORWARD; - goto FAILED; - } - - *parsed_pattern++ = META_COND_VERSION; - *parsed_pattern++ = ge; - *parsed_pattern++ = major; - *parsed_pattern++ = minor; - } - - /* All the remaining cases now require us to read a name. We cannot at - this stage distinguish ambiguous cases such as (?(R12) which might be a - recursion test by number or a name, because the named groups have not yet - all been identified. Those cases are treated as names, but given a - different META code. */ - - else - { - BOOL was_r_ampersand = FALSE; - - if (*ptr == CHAR_R && ptrend - ptr > 1 && ptr[1] == CHAR_AMPERSAND) - { - terminator = CHAR_RIGHT_PARENTHESIS; - was_r_ampersand = TRUE; - ptr++; - } - else if (*ptr == CHAR_LESS_THAN_SIGN) - terminator = CHAR_GREATER_THAN_SIGN; - else if (*ptr == CHAR_APOSTROPHE) - terminator = CHAR_APOSTROPHE; - else - { - terminator = CHAR_RIGHT_PARENTHESIS; - ptr--; /* Point to char before name */ - } - - if (!read_name(&ptr, ptrend, utf, terminator, &offset, &name, &namelen, - &errorcode, cb)) goto FAILED; - - /* Handle (?(R&name) */ - - if (was_r_ampersand) - { - *parsed_pattern = META_COND_RNAME; - ptr--; /* Back to closing parens */ - } - - /* Handle (?(name). If the name is "DEFINE" we identify it with a - special code. Likewise if the name consists of R followed only by - digits. Otherwise, handle it like a quoted name. */ - - else if (terminator == CHAR_RIGHT_PARENTHESIS) - { - if (namelen == 6 && PRIV(strncmp_c8)(name, STRING_DEFINE, 6) == 0) - *parsed_pattern = META_COND_DEFINE; - else - { - for (i = 1; i < (int)namelen; i++) - if (!IS_DIGIT(name[i])) break; - *parsed_pattern = (*name == CHAR_R && i >= (int)namelen)? - META_COND_RNUMBER : META_COND_NAME; - } - ptr--; /* Back to closing parens */ - } - - /* Handle (?('name') or (?() */ - - else *parsed_pattern = META_COND_NAME; - - /* All these cases except DEFINE end with the name length and offset; - DEFINE just has an offset (for the "too many branches" error). */ - - if (*parsed_pattern++ != META_COND_DEFINE) *parsed_pattern++ = namelen; - PUTOFFSET(offset, parsed_pattern); - } /* End cases that read a name */ - - /* Check the closing parenthesis of the condition */ - - if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) - { - errorcode = ERR24; - goto FAILED; - } - ptr++; - break; /* End of condition processing */ - - - /* ---- Atomic group ---- */ - - case CHAR_GREATER_THAN_SIGN: - ATOMIC_GROUP: /* Come from (*atomic: */ - *parsed_pattern++ = META_ATOMIC; - nest_depth++; - ptr++; - break; - - - /* ---- Lookahead assertions ---- */ - - case CHAR_EQUALS_SIGN: - POSITIVE_LOOK_AHEAD: /* Come from (*pla: */ - *parsed_pattern++ = META_LOOKAHEAD; - ptr++; - goto POST_ASSERTION; - - case CHAR_ASTERISK: - POSITIVE_NONATOMIC_LOOK_AHEAD: /* Come from (*napla: */ - *parsed_pattern++ = META_LOOKAHEAD_NA; - ptr++; - goto POST_ASSERTION; - - case CHAR_EXCLAMATION_MARK: - NEGATIVE_LOOK_AHEAD: /* Come from (*nla: */ - *parsed_pattern++ = META_LOOKAHEADNOT; - ptr++; - goto POST_ASSERTION; - - - /* ---- Lookbehind assertions ---- */ - - /* (?< followed by = or ! or * is a lookbehind assertion. Otherwise (?< - is the start of the name of a capturing group. */ - - case CHAR_LESS_THAN_SIGN: - if (ptrend - ptr <= 1 || - (ptr[1] != CHAR_EQUALS_SIGN && - ptr[1] != CHAR_EXCLAMATION_MARK && - ptr[1] != CHAR_ASTERISK)) - { - terminator = CHAR_GREATER_THAN_SIGN; - goto DEFINE_NAME; - } - *parsed_pattern++ = (ptr[1] == CHAR_EQUALS_SIGN)? - META_LOOKBEHIND : (ptr[1] == CHAR_EXCLAMATION_MARK)? - META_LOOKBEHINDNOT : META_LOOKBEHIND_NA; - - POST_LOOKBEHIND: /* Come from (*plb: (*naplb: and (*nlb: */ - *has_lookbehind = TRUE; - offset = (PCRE2_SIZE)(ptr - cb->start_pattern - 2); - PUTOFFSET(offset, parsed_pattern); - ptr += 2; - /* Fall through */ - - /* If the previous item was a condition starting (?(? an assertion, - optionally preceded by a callout, is expected. This is checked later on, - during actual compilation. However we need to identify this kind of - assertion in this pass because it must not be qualified. The value of - expect_cond_assert is set to 2 after (?(? is processed. We decrement it - for a callout - still leaving a positive value that identifies the - assertion. Multiple callouts or any other items will make it zero or - less, which doesn't matter because they will cause an error later. */ - - POST_ASSERTION: - nest_depth++; - if (prev_expect_cond_assert > 0) - { - if (top_nest == NULL) top_nest = (nest_save *)(cb->start_workspace); - else if (++top_nest >= end_nests) - { - errorcode = ERR84; - goto FAILED; - } - top_nest->nest_depth = nest_depth; - top_nest->flags = NSF_CONDASSERT; - top_nest->options = options & PARSE_TRACKED_OPTIONS; - top_nest->xoptions = xoptions & PARSE_TRACKED_EXTRA_OPTIONS; - } - break; - - - /* ---- Define a named group ---- */ - - /* A named group may be defined as (?'name') or (?). In the latter - case we jump to DEFINE_NAME from the disambiguation of (?< above with the - terminator set to '>'. */ - - case CHAR_APOSTROPHE: - terminator = CHAR_APOSTROPHE; /* Terminator */ - - DEFINE_NAME: - if (!read_name(&ptr, ptrend, utf, terminator, &offset, &name, &namelen, - &errorcode, cb)) goto FAILED; - - /* We have a name for this capturing group. It is also assigned a number, - which is its primary means of identification. */ - - if (cb->bracount >= MAX_GROUP_NUMBER) - { - errorcode = ERR97; - goto FAILED; - } - cb->bracount++; - *parsed_pattern++ = META_CAPTURE | cb->bracount; - nest_depth++; - - /* Check not too many names */ - - if (cb->names_found >= MAX_NAME_COUNT) - { - errorcode = ERR49; - goto FAILED; - } - - /* Adjust the entry size to accommodate the longest name found. */ - - if (namelen + IMM2_SIZE + 1 > cb->name_entry_size) - cb->name_entry_size = (uint16_t)(namelen + IMM2_SIZE + 1); - - /* Scan the list to check for duplicates. For duplicate names, if the - number is the same, break the loop, which causes the name to be - discarded; otherwise, if DUPNAMES is not set, give an error. - If it is set, allow the name with a different number, but continue - scanning in case this is a duplicate with the same number. For - non-duplicate names, give an error if the number is duplicated. */ - - is_dupname = FALSE; - hash = PRIV(compile_get_hash_from_name)(name, namelen); - ng = cb->named_groups; - for (i = 0; i < cb->names_found; i++, ng++) - { - if (namelen == ng->length && hash == NAMED_GROUP_GET_HASH(ng) && - PRIV(strncmp)(name, ng->name, (PCRE2_SIZE)namelen) == 0) - { - /* When a bracket is referenced by the same name multiple - times, is not considered as a duplicate and ignored. */ - if (ng->number == cb->bracount) break; - if ((options & PCRE2_DUPNAMES) == 0) - { - errorcode = ERR43; - goto FAILED; - } - - ng->hash_dup |= NAMED_GROUP_IS_DUPNAME; - is_dupname = TRUE; /* Mark as a duplicate */ - cb->dupnames = TRUE; /* Duplicate names exist */ - - /* The entry represents a duplicate. */ - name = ng->name; - namelen = 0; - - /* Even duplicated names may refer to the same - capture index. These references are also ignored. */ - for (; i < cb->names_found; i++, ng++) - if (ng->name == name && ng->number == cb->bracount) - break; - break; - } - else if (ng->number == cb->bracount) - { - errorcode = ERR65; - goto FAILED; - } - } - - /* Ignore duplicate with same number. */ - if (i < cb->names_found) break; - - /* Increase the list size if necessary */ - - if (cb->names_found >= cb->named_group_list_size) - { - uint32_t newsize = cb->named_group_list_size * 2; - named_group *newspace = - cb->cx->memctl.malloc(newsize * sizeof(named_group), - cb->cx->memctl.memory_data); - if (newspace == NULL) - { - errorcode = ERR21; - goto FAILED; - } - - memcpy(newspace, cb->named_groups, - cb->named_group_list_size * sizeof(named_group)); - if (cb->named_group_list_size > NAMED_GROUP_LIST_SIZE) - cb->cx->memctl.free((void *)cb->named_groups, - cb->cx->memctl.memory_data); - cb->named_groups = newspace; - cb->named_group_list_size = newsize; - } - - /* Add this name to the list */ - if (is_dupname) - hash |= NAMED_GROUP_IS_DUPNAME; - - cb->named_groups[cb->names_found].name = name; - cb->named_groups[cb->names_found].length = (uint16_t)namelen; - cb->named_groups[cb->names_found].number = cb->bracount; - cb->named_groups[cb->names_found].hash_dup = hash; - cb->names_found++; - break; - - - /* ---- Perl extended character class ---- */ - - /* These are of the form '(?[...])'. We handle these via the same parser - that consumes ordinary '[...]' classes, but with a flag set to activate - the extended behaviour. */ - - case CHAR_LEFT_SQUARE_BRACKET: - class_mode_state = CLASS_MODE_PERL_EXT; - c = *ptr++; - goto FROM_PERL_EXTENDED_CLASS; - } /* End of (? switch */ - break; /* End of ( handling */ - - - /* ---- Branch terminators ---- */ - - /* Alternation: reset the capture count if we are in a (?| group. */ - - case CHAR_VERTICAL_LINE: - if (top_nest != NULL && top_nest->nest_depth == nest_depth && - (top_nest->flags & NSF_RESET) != 0) - { - if (cb->bracount > top_nest->max_group) - top_nest->max_group = (uint16_t)cb->bracount; - cb->bracount = top_nest->reset_group; - } - *parsed_pattern++ = META_ALT; - break; - - /* End of group; reset the capture count to the maximum if we are in a (?| - group and/or reset the options that are tracked during parsing. Disallow - quantifier for a condition that is an assertion. */ - - case CHAR_RIGHT_PARENTHESIS: - okquantifier = TRUE; - if (top_nest != NULL && top_nest->nest_depth == nest_depth) - { - options = (options & ~PARSE_TRACKED_OPTIONS) | top_nest->options; - xoptions = (xoptions & ~PARSE_TRACKED_EXTRA_OPTIONS) | top_nest->xoptions; - if ((top_nest->flags & NSF_RESET) != 0 && - top_nest->max_group > cb->bracount) - cb->bracount = top_nest->max_group; - if ((top_nest->flags & NSF_CONDASSERT) != 0) - okquantifier = FALSE; - - if ((top_nest->flags & NSF_ATOMICSR) != 0) - { - *parsed_pattern++ = META_KET; - -#ifdef PCRE2_DEBUG - PCRE2_ASSERT(parsed_pattern_extra > 0); - parsed_pattern_extra--; -#endif - } - - if (top_nest == (nest_save *)(cb->start_workspace)) top_nest = NULL; - else top_nest--; - } - if (nest_depth == 0) /* Unmatched closing parenthesis */ - { - errorcode = ERR22; - goto FAILED; - } - nest_depth--; - *parsed_pattern++ = META_KET; - break; - } /* End of switch on pattern character */ - } /* End of main character scan loop */ - -/* End of pattern reached. Check for missing ) at the end of a verb name. */ - -if (inverbname && ptr >= ptrend) - { - errorcode = ERR60; - goto FAILED; - } - - -PARSED_END: - -PCRE2_ASSERT((parsed_pattern - parsed_pattern_check) + - (parsed_pattern_extra - parsed_pattern_extra_check) <= - max_parsed_pattern(ptr_check, ptr, utf, options)); - -/* Manage callout for the final item */ - -parsed_pattern = manage_callouts(ptr, &previous_callout, auto_callout, - parsed_pattern, cb); - -/* Insert trailing items for word and line matching (features provided for the -benefit of pcre2grep). */ - -if ((xoptions & PCRE2_EXTRA_MATCH_LINE) != 0) - { - *parsed_pattern++ = META_KET; - *parsed_pattern++ = META_DOLLAR; - } -else if ((xoptions & PCRE2_EXTRA_MATCH_WORD) != 0) - { - *parsed_pattern++ = META_KET; - *parsed_pattern++ = META_ESCAPE + ESC_b; - } - -/* Terminate the parsed pattern, then return success if all groups are closed. -Otherwise we have unclosed parentheses. */ - -/* LCOV_EXCL_START */ -if (parsed_pattern >= parsed_pattern_end) - { - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR63; /* Internal error (parsed pattern overflow) */ - goto FAILED; - } -/* LCOV_EXCL_STOP */ - -*parsed_pattern = META_END; -if (nest_depth == 0) return 0; - -UNCLOSED_PARENTHESIS: -errorcode = ERR14; - -/* Come here for all failures. */ - -FAILED: -cb->erroroffset = (PCRE2_SIZE)(ptr - cb->start_pattern); -return errorcode; - -/* Some errors need to indicate the previous character. */ - -FAILED_BACK: -ptr--; -#ifdef SUPPORT_UNICODE -if (utf) BACKCHAR(ptr); -#endif -goto FAILED; - -/* Some errors need to indicate the next character. */ - -FAILED_FORWARD: -ptr++; -#ifdef SUPPORT_UNICODE -if (utf) FORWARDCHARTEST(ptr, ptrend); -#endif -goto FAILED; -} - - - -/************************************************* -* Find first significant opcode * -*************************************************/ - -/* This is called by several functions that scan a compiled expression looking -for a fixed first character, or an anchoring opcode etc. It skips over things -that do not influence this. For some calls, it makes sense to skip negative -forward and all backward assertions, and also the \b assertion; for others it -does not. - -Arguments: - code pointer to the start of the group - skipassert TRUE if certain assertions are to be skipped - -Returns: pointer to the first significant opcode -*/ - -static const PCRE2_UCHAR* -first_significant_code(PCRE2_SPTR code, BOOL skipassert) -{ -for (;;) - { - switch ((int)*code) - { - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERTBACK_NA: - if (!skipassert) return code; - do code += GET(code, 1); while (*code == OP_ALT); - code += PRIV(OP_lengths)[*code]; - break; - - case OP_WORD_BOUNDARY: - case OP_NOT_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - case OP_NOT_UCP_WORD_BOUNDARY: - if (!skipassert) return code; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_CALLOUT: - case OP_CREF: - case OP_DNCREF: - case OP_RREF: - case OP_DNRREF: - case OP_FALSE: - case OP_TRUE: - code += PRIV(OP_lengths)[*code]; - break; - - case OP_CALLOUT_STR: - code += GET(code, 1 + 2*LINK_SIZE); - break; - - case OP_SKIPZERO: - code += 2 + GET(code, 2) + LINK_SIZE; - break; - - case OP_COND: - case OP_SCOND: - if (code[1+LINK_SIZE] != OP_FALSE || /* Not DEFINE */ - code[GET(code, 1)] != OP_KET) /* More than one branch */ - return code; - code += GET(code, 1) + 1 + LINK_SIZE; - break; - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_SKIP_ARG: - case OP_THEN_ARG: - code += code[1] + PRIV(OP_lengths)[*code]; - break; - - default: - return code; - } - } - -/* LCOV_EXCL_START */ -PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ -/* LCOV_EXCL_STOP */ -} - - - -/************************************************* -* Compile one branch * -*************************************************/ - -/* Scan the parsed pattern, compiling it into the a vector of PCRE2_UCHAR. If -the options are changed during the branch, the pointer is used to change the -external options bits. This function is used during the pre-compile phase when -we are trying to find out the amount of memory needed, as well as during the -real compile phase. The value of lengthptr distinguishes the two phases. - -Arguments: - optionsptr pointer to the option bits - xoptionsptr pointer to the extra option bits - codeptr points to the pointer to the current code point - pptrptr points to the current parsed pattern pointer - errorcodeptr points to error code variable - firstcuptr place to put the first required code unit - firstcuflagsptr place to put the first code unit flags - reqcuptr place to put the last required code unit - reqcuflagsptr place to put the last required code unit flags - bcptr points to current branch chain - open_caps points to current capitem - cb contains pointers to tables etc. - lengthptr NULL during the real compile phase - points to length accumulator during pre-compile phase - -Returns: 0 There's been an error, *errorcodeptr is non-zero - +1 Success, this branch must match at least one character - -1 Success, this branch may match an empty string -*/ - -static int -compile_branch(uint32_t *optionsptr, uint32_t *xoptionsptr, - PCRE2_UCHAR **codeptr, uint32_t **pptrptr, int *errorcodeptr, - uint32_t *firstcuptr, uint32_t *firstcuflagsptr, uint32_t *reqcuptr, - uint32_t *reqcuflagsptr, branch_chain *bcptr, open_capitem *open_caps, - compile_block *cb, PCRE2_SIZE *lengthptr) -{ -int bravalue = 0; -int okreturn = -1; -int group_return = 0; -uint32_t repeat_min = 0, repeat_max = 0; /* To please picky compilers */ -uint32_t greedy_default, greedy_non_default; -uint32_t repeat_type, op_type; -uint32_t options = *optionsptr; /* May change dynamically */ -uint32_t xoptions = *xoptionsptr; /* May change dynamically */ -uint32_t firstcu, reqcu; -uint32_t zeroreqcu, zerofirstcu; -uint32_t *pptr = *pptrptr; -uint32_t meta, meta_arg; -uint32_t firstcuflags, reqcuflags; -uint32_t zeroreqcuflags, zerofirstcuflags; -uint32_t req_caseopt, reqvary, tempreqvary; -uint32_t j; -int i; -/* Some opcodes, such as META_CAPTURE_NUMBER or META_CAPTURE_NAME, -depends on the previous value of offset. */ -PCRE2_SIZE offset = 0; -PCRE2_SIZE length_prevgroup = 0; -PCRE2_UCHAR *code = *codeptr; -PCRE2_UCHAR *last_code = code; -PCRE2_UCHAR *orig_code = code; -PCRE2_UCHAR *tempcode; -PCRE2_UCHAR *previous = NULL; -PCRE2_UCHAR op_previous; -BOOL groupsetfirstcu = FALSE; -BOOL had_accept = FALSE; -BOOL matched_char = FALSE; -BOOL previous_matched_char = FALSE; -BOOL reset_caseful = FALSE; - -/* We can fish out the UTF setting once and for all into a BOOL, but we must -not do this for other options (e.g. PCRE2_EXTENDED) that may change dynamically -as we process the pattern. */ - -#ifdef SUPPORT_UNICODE -BOOL utf = (options & PCRE2_UTF) != 0; -BOOL ucp = (options & PCRE2_UCP) != 0; -#else /* No Unicode support */ -BOOL utf = FALSE; -#endif - -/* Set up the default and non-default settings for greediness */ - -greedy_default = ((options & PCRE2_UNGREEDY) != 0); -greedy_non_default = greedy_default ^ 1; - -/* Initialize no first unit, no required unit. REQ_UNSET means "no char -matching encountered yet". It gets changed to REQ_NONE if we hit something that -matches a non-fixed first unit; reqcu just remains unset if we never find one. - -When we hit a repeat whose minimum is zero, we may have to adjust these values -to take the zero repeat into account. This is implemented by setting them to -zerofirstcu and zeroreqcu when such a repeat is encountered. The individual -item types that can be repeated set these backoff variables appropriately. */ - -firstcu = reqcu = zerofirstcu = zeroreqcu = 0; -firstcuflags = reqcuflags = zerofirstcuflags = zeroreqcuflags = REQ_UNSET; - -/* The variable req_caseopt contains either the REQ_CASELESS bit or zero, -according to the current setting of the caseless flag. The REQ_CASELESS value -leaves the lower 28 bit empty. It is added into the firstcu or reqcu variables -to record the case status of the value. This is used only for ASCII characters. -*/ - -req_caseopt = ((options & PCRE2_CASELESS) != 0)? REQ_CASELESS : 0; - -/* Switch on next META item until the end of the branch */ - -for (;; pptr++) - { - BOOL possessive_quantifier; - BOOL note_group_empty; - uint32_t mclength; - uint32_t skipunits; - uint32_t subreqcu, subfirstcu; - uint32_t groupnumber; - uint32_t verbarglen, verbculen; - uint32_t subreqcuflags, subfirstcuflags; - open_capitem *oc; - PCRE2_UCHAR mcbuffer[8]; - - /* Get next META item in the pattern and its potential argument. */ - - meta = META_CODE(*pptr); - meta_arg = META_DATA(*pptr); - - /* If we are in the pre-compile phase, accumulate the length used for the - previous cycle of this loop, unless the next item is a quantifier. */ - - if (lengthptr != NULL) - { - /* LCOV_EXCL_START */ - if (code >= cb->start_workspace + cb->workspace_size) - { - PCRE2_DEBUG_UNREACHABLE(); - *errorcodeptr = ERR52; /* Over-ran workspace - internal error */ - cb->erroroffset = 0; - return 0; - } - /* LCOV_EXCL_STOP */ - - if (code > cb->start_workspace + cb->workspace_size - - WORK_SIZE_SAFETY_MARGIN) /* Check for overrun */ - { - *errorcodeptr = ERR86; /* Pattern too complicated */ - cb->erroroffset = 0; - return 0; - } - - /* There is at least one situation where code goes backwards: this is the - case of a zero quantifier after a class (e.g. [ab]{0}). When the quantifier - is processed, the whole class is eliminated. However, it is created first, - so we have to allow memory for it. Therefore, don't ever reduce the length - at this point. */ - - if (code < last_code) code = last_code; - - /* If the next thing is not a quantifier, we add the length of the previous - item into the total, and reset the code pointer to the start of the - workspace. Otherwise leave the previous item available to be quantified. */ - - if (meta < META_ASTERISK || meta > META_MINMAX_QUERY) - { - if (OFLOW_MAX - *lengthptr < (PCRE2_SIZE)(code - orig_code)) - { - *errorcodeptr = ERR20; /* Integer overflow */ - cb->erroroffset = 0; - return 0; - } - *lengthptr += (PCRE2_SIZE)(code - orig_code); - if (*lengthptr > MAX_PATTERN_SIZE) - { - *errorcodeptr = ERR20; /* Pattern is too large */ - cb->erroroffset = 0; - return 0; - } - code = orig_code; - } - - /* Remember where this code item starts so we can catch the "backwards" - case above next time round. */ - - last_code = code; - } - - /* Process the next parsed pattern item. If it is not a quantifier, remember - where it starts so that it can be quantified when a quantifier follows. - Checking for the legality of quantifiers happens in parse_regex(), except for - a quantifier after an assertion that is a condition. */ - - if (meta < META_ASTERISK || meta > META_MINMAX_QUERY) - { - previous = code; - if (matched_char && !had_accept) okreturn = 1; - } - - previous_matched_char = matched_char; - matched_char = FALSE; - note_group_empty = FALSE; - skipunits = 0; /* Default value for most subgroups */ - - switch(meta) - { - /* ===================================================================*/ - /* The branch terminates at pattern end or | or ) */ - - case META_END: - case META_ALT: - case META_KET: - *firstcuptr = firstcu; - *firstcuflagsptr = firstcuflags; - *reqcuptr = reqcu; - *reqcuflagsptr = reqcuflags; - *codeptr = code; - *pptrptr = pptr; - return okreturn; - - - /* ===================================================================*/ - /* Handle single-character metacharacters. In multiline mode, ^ disables - the setting of any following char as a first character. */ - - case META_CIRCUMFLEX: - if ((options & PCRE2_MULTILINE) != 0) - { - if (firstcuflags == REQ_UNSET) - zerofirstcuflags = firstcuflags = REQ_NONE; - *code++ = OP_CIRCM; - } - else *code++ = OP_CIRC; - break; - - case META_DOLLAR: - *code++ = ((options & PCRE2_MULTILINE) != 0)? OP_DOLLM : OP_DOLL; - break; - - /* There can never be a first char if '.' is first, whatever happens about - repeats. The value of reqcu doesn't change either. */ - - case META_DOT: - matched_char = TRUE; - if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; - zerofirstcu = firstcu; - zerofirstcuflags = firstcuflags; - zeroreqcu = reqcu; - zeroreqcuflags = reqcuflags; - *code++ = ((options & PCRE2_DOTALL) != 0)? OP_ALLANY: OP_ANY; - break; - - - /* ===================================================================*/ - /* Empty character classes are allowed if PCRE2_ALLOW_EMPTY_CLASS is set. - Otherwise, an initial ']' is taken as a data character. When empty classes - are allowed, [] must generate an empty class - we have no dedicated opcode - to optimise the representation, but it's a rare case (the '(*FAIL)' - construct would be a clearer way for a pattern author to represent a - non-matching branch, but it does have different semantics to '[]' if both - are followed by a quantifier). The empty-negated [^] matches any character, - so is useful: generate OP_ALLANY for this. */ - - case META_CLASS_EMPTY: - case META_CLASS_EMPTY_NOT: - matched_char = TRUE; - if (meta == META_CLASS_EMPTY_NOT) *code++ = OP_ALLANY; - else - { - *code++ = OP_CLASS; - memset(code, 0, 32); - code += 32 / sizeof(PCRE2_UCHAR); - } - - if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; - zerofirstcu = firstcu; - zerofirstcuflags = firstcuflags; - break; - - - /* ===================================================================*/ - /* Non-empty character class. If the included characters are all < 256, we - build a 32-byte bitmap of the permitted characters, except in the special - case where there is only one such character. For negated classes, we build - the map as usual, then invert it at the end. However, we use a different - opcode so that data characters > 255 can be handled correctly. - - If the class contains characters outside the 0-255 range, a different - opcode is compiled. It may optionally have a bit map for characters < 256, - but those above are explicitly listed afterwards. A flag code unit tells - whether the bitmap is present, and whether this is a negated class or - not. */ - - case META_CLASS_NOT: - case META_CLASS: - matched_char = TRUE; - - /* Check for complex extended classes and handle them separately. */ - - if ((*pptr & CLASS_IS_ECLASS) != 0) - { - if (!PRIV(compile_class_nested)(options, xoptions, &pptr, &code, - errorcodeptr, cb, lengthptr)) - return 0; - goto CLASS_END_PROCESSING; - } - - /* We can optimize the case of a single character in a class by generating - OP_CHAR or OP_CHARI if it's positive, or OP_NOT or OP_NOTI if it's - negative. In the negative case there can be no first char if this item is - first, whatever repeat count may follow. In the case of reqcu, save the - previous value for reinstating. */ - - /* NOTE: at present this optimization is not effective if the only - character in a class in 32-bit, non-UCP mode has its top bit set. */ - - if (pptr[1] < META_END && pptr[2] == META_CLASS_END) - { - uint32_t c = pptr[1]; - - pptr += 2; /* Move on to class end */ - if (meta == META_CLASS) /* A positive one-char class can be */ - { /* handled as a normal literal character. */ - meta = c; /* Set up the character */ - goto NORMAL_CHAR_SET; - } - - /* Handle a negative one-character class */ - - zeroreqcu = reqcu; - zeroreqcuflags = reqcuflags; - if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; - zerofirstcu = firstcu; - zerofirstcuflags = firstcuflags; - - /* For caseless UTF or UCP mode, check whether this character has more - than one other case. If so, generate a special OP_NOTPROP item instead of - OP_NOTI. When restricted by PCRE2_EXTRA_CASELESS_RESTRICT, ignore any - caseless set that starts with an ASCII character. If the character is - affected by the special Turkish rules, hardcode the not-matching - characters using a caseset. */ - -#ifdef SUPPORT_UNICODE - if ((utf||ucp) && (options & PCRE2_CASELESS) != 0) - { - uint32_t caseset; - - if ((xoptions & (PCRE2_EXTRA_TURKISH_CASING|PCRE2_EXTRA_CASELESS_RESTRICT)) == - PCRE2_EXTRA_TURKISH_CASING && - UCD_ANY_I(c)) - { - caseset = PRIV(ucd_turkish_dotted_i_caseset) + (UCD_DOTTED_I(c)? 0 : 3); - } - else if ((caseset = UCD_CASESET(c)) != 0 && - (xoptions & PCRE2_EXTRA_CASELESS_RESTRICT) != 0 && - PRIV(ucd_caseless_sets)[caseset] < 128) - { - caseset = 0; /* Ignore the caseless set if it's restricted. */ - } - - if (caseset != 0) - { - *code++ = OP_NOTPROP; - *code++ = PT_CLIST; - *code++ = caseset; - break; /* We are finished with this class */ - } - } -#endif - /* Char has only one other (usable) case, or UCP not available */ - - *code++ = ((options & PCRE2_CASELESS) != 0)? OP_NOTI: OP_NOT; - code += PUTCHAR(c, code); - break; /* We are finished with this class */ - } /* End of 1-char optimization */ - - /* Handle character classes that contain more than just one literal - character. If there are exactly two characters in a positive class, see if - they are case partners. This can be optimized to generate a caseless single - character match (which also sets first/required code units if relevant). - When casing restrictions apply, ignore a caseless set if both characters - are ASCII. When Turkish casing applies, an 'i' does not match its normal - Unicode "othercase". */ - - if (meta == META_CLASS && pptr[1] < META_END && pptr[2] < META_END && - pptr[3] == META_CLASS_END) - { - uint32_t c = pptr[1]; - -#ifdef SUPPORT_UNICODE - if ((UCD_CASESET(c) == 0 || - ((xoptions & PCRE2_EXTRA_CASELESS_RESTRICT) != 0 && - c < 128 && pptr[2] < 128)) && - !((xoptions & (PCRE2_EXTRA_TURKISH_CASING|PCRE2_EXTRA_CASELESS_RESTRICT)) == - PCRE2_EXTRA_TURKISH_CASING && - UCD_ANY_I(c))) -#endif - { - uint32_t d; - -#ifdef SUPPORT_UNICODE - if ((utf || ucp) && c > 127) d = UCD_OTHERCASE(c); else -#endif - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (c > 255) d = c; else -#endif - d = TABLE_GET(c, cb->fcc, c); - } - - if (c != d && pptr[2] == d) - { - pptr += 3; /* Move on to class end */ - meta = c; - if ((options & PCRE2_CASELESS) == 0) - { - reset_caseful = TRUE; - options |= PCRE2_CASELESS; - req_caseopt = REQ_CASELESS; - } - goto CLASS_CASELESS_CHAR; - } - } - } - - /* Now emit the OP_CLASS/OP_NCLASS/OP_XCLASS/OP_ALLANY opcode. */ - - pptr = PRIV(compile_class_not_nested)(options, xoptions, pptr + 1, - &code, meta == META_CLASS_NOT, NULL, - errorcodeptr, cb, lengthptr); - if (pptr == NULL) return 0; - PCRE2_ASSERT(*pptr == META_CLASS_END); - - CLASS_END_PROCESSING: - - /* If this class is the first thing in the branch, there can be no first - char setting, whatever the repeat count. Any reqcu setting must remain - unchanged after any kind of repeat. */ - - if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; - zerofirstcu = firstcu; - zerofirstcuflags = firstcuflags; - zeroreqcu = reqcu; - zeroreqcuflags = reqcuflags; - break; /* End of class processing */ - - - /* ===================================================================*/ - /* Deal with (*VERB)s. */ - - /* Check for open captures before ACCEPT and close those that are within - the same assertion level, also converting ACCEPT to ASSERT_ACCEPT in an - assertion. In the first pass, just accumulate the length required; - otherwise hitting (*ACCEPT) inside many nested parentheses can cause - workspace overflow. Do not set firstcu after *ACCEPT. */ - - case META_ACCEPT: - cb->had_accept = had_accept = TRUE; - for (oc = open_caps; - oc != NULL && oc->assert_depth >= cb->assert_depth; - oc = oc->next) - { - if (lengthptr != NULL) - { - *lengthptr += CU2BYTES(1) + IMM2_SIZE; - } - else - { - *code++ = OP_CLOSE; - PUT2INC(code, 0, oc->number); - } - } - *code++ = (cb->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT; - if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; - break; - - case META_PRUNE: - case META_SKIP: - cb->had_pruneorskip = TRUE; - PCRE2_FALLTHROUGH /* Fall through */ - case META_COMMIT: - case META_FAIL: - *code++ = verbops[(meta - META_MARK) >> 16]; - break; - - case META_THEN: - cb->external_flags |= PCRE2_HASTHEN; - *code++ = OP_THEN; - break; - - /* Handle verbs with arguments. Arguments can be very long, especially in - 16- and 32-bit modes, and can overflow the workspace in the first pass. - However, the argument length is constrained to be small enough to fit in - one code unit. This check happens in parse_regex(). In the first pass, - instead of putting the argument into memory, we just update the length - counter and set up an empty argument. */ - - case META_THEN_ARG: - cb->external_flags |= PCRE2_HASTHEN; - goto VERB_ARG; - - case META_PRUNE_ARG: - case META_SKIP_ARG: - cb->had_pruneorskip = TRUE; - PCRE2_FALLTHROUGH /* Fall through */ - case META_MARK: - case META_COMMIT_ARG: - VERB_ARG: - *code++ = verbops[(meta - META_MARK) >> 16]; - /* The length is in characters. */ - verbarglen = *(++pptr); - verbculen = 0; - tempcode = code++; - for (i = 0; i < (int)verbarglen; i++) - { - meta = *(++pptr); -#ifdef SUPPORT_UNICODE - if (utf) mclength = PRIV(ord2utf)(meta, mcbuffer); else -#endif - { - mclength = 1; - mcbuffer[0] = meta; - } - if (lengthptr != NULL) *lengthptr += mclength; else - { - memcpy(code, mcbuffer, CU2BYTES(mclength)); - code += mclength; - verbculen += mclength; - } - } - - *tempcode = verbculen; /* Fill in the code unit length */ - *code++ = 0; /* Terminating zero */ - break; - - - /* ===================================================================*/ - /* Handle options change. The new setting must be passed back for use in - subsequent branches. Reset the greedy defaults and the case value for - firstcu and reqcu. */ - - case META_OPTIONS: - *optionsptr = options = *(++pptr); - *xoptionsptr = xoptions = *(++pptr); - greedy_default = ((options & PCRE2_UNGREEDY) != 0); - greedy_non_default = greedy_default ^ 1; - req_caseopt = ((options & PCRE2_CASELESS) != 0)? REQ_CASELESS : 0; - break; - - /* ===================================================================*/ - /* Handle scan substring. Scan substring assertion starts with META_SCS, - which recursively calls compile_branch. The first opcode processed by - this recursive call is always META_OFFSET. */ - - case META_OFFSET: - if (lengthptr != NULL) - { - pptr = PRIV(compile_parse_scan_substr_args)(pptr, errorcodeptr, cb, lengthptr); - if (pptr == NULL) - return 0; - break; - } - - while (TRUE) - { - int count, index; - named_group *ng; - - switch (META_CODE(*pptr)) - { - case META_OFFSET: - pptr++; - SKIPOFFSET(pptr); - continue; - - case META_CAPTURE_NAME: - ng = cb->named_groups + pptr[1]; - pptr += 2; - count = 0; - index = 0; - - if (!PRIV(compile_find_dupname_details)(ng->name, ng->length, &index, - &count, errorcodeptr, cb)) return 0; - - code[0] = OP_DNCREF; - PUT2(code, 1, index); - PUT2(code, 1 + IMM2_SIZE, count); - code += 1 + 2 * IMM2_SIZE; - continue; - - case META_CAPTURE_NUMBER: - pptr += 2; - if (pptr[-1] == 0) continue; - - code[0] = OP_CREF; - PUT2(code, 1, pptr[-1]); - code += 1 + IMM2_SIZE; - continue; - - default: - break; - } - - break; - } - --pptr; - break; - - case META_SCS: - bravalue = OP_ASSERT_SCS; - cb->assert_depth += 1; - goto GROUP_PROCESS; - - - /* ===================================================================*/ - /* Handle conditional subpatterns. The case of (?(Rdigits) is ambiguous - because it could be a numerical check on recursion, or a name check on a - group's being set. The pre-pass sets up META_COND_RNUMBER as a name so that - we can handle it either way. We first try for a name; if not found, process - the number. */ - - case META_COND_RNUMBER: /* (?(Rdigits) */ - case META_COND_NAME: /* (?(name) or (?'name') or ?() */ - case META_COND_RNAME: /* (?(R&name) - test for recursion */ - bravalue = OP_COND; - - if (lengthptr != NULL) - { - uint32_t i; - PCRE2_SPTR name; - named_group *ng; - uint32_t *start_pptr = pptr; - uint32_t length = *(++pptr); - - GETPLUSOFFSET(offset, pptr); - name = cb->start_pattern + offset; - - /* In the first pass, the names generated in the pre-pass are available, - but the main name table has not yet been created. Scan the list of names - generated in the pre-pass in order to get a number and whether or not - this name is duplicated. If it is not duplicated, we can handle it as a - numerical group. */ - - ng = PRIV(compile_find_named_group)(name, length, cb); - - if (ng == NULL) - { - /* If the name was not found we have a bad reference, unless we are - dealing with R, which is treated as a recursion test by - number. */ - - groupnumber = 0; - if (meta == META_COND_RNUMBER) - { - for (i = 1; i < length; i++) - { - groupnumber = groupnumber * 10 + (name[i] - CHAR_0); - if (groupnumber > MAX_GROUP_NUMBER) - { - *errorcodeptr = ERR61; - cb->erroroffset = offset + i; - return 0; - } - } - } - - if (meta != META_COND_RNUMBER || groupnumber > cb->bracount) - { - *errorcodeptr = ERR15; - cb->erroroffset = offset; - return 0; - } - - /* (?Rdigits) treated as a recursion reference by number. A value of - zero (which is the result of both (?R) and (?R0)) means "any", and is - translated into RREF_ANY (which is 0xffff). */ - - if (groupnumber == 0) groupnumber = RREF_ANY; - PCRE2_ASSERT(start_pptr[0] == META_COND_RNUMBER); - start_pptr[1] = groupnumber; - skipunits = 1+IMM2_SIZE; - goto GROUP_PROCESS_NOTE_EMPTY; - } - - /* From here on, we know we have a name (not a number), - so treat META_COND_RNUMBER the same as META_COND_NAME. */ - if (meta == META_COND_RNUMBER) meta = META_COND_NAME; - - if ((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) == 0) - { - /* Found a non-duplicated name. Since it is a global, - it is enough to update it in the pre-processing phase. */ - if (ng->number > cb->top_backref) cb->top_backref = ng->number; - - start_pptr[0] = meta; - start_pptr[1] = ng->number; - - skipunits = 1 + IMM2_SIZE; - goto GROUP_PROCESS_NOTE_EMPTY; - } - - /* We have a duplicated name. In the compile pass we have to search the - main table in order to get the index and count values. */ - - start_pptr[0] = meta | 1; - start_pptr[1] = (uint32_t)(ng - cb->named_groups); - - /* A duplicated name was found. Note that if an R name is found - (META_COND_RNUMBER), it is a reference test, not a recursion test. */ - skipunits = 1 + 2 * IMM2_SIZE; - } - else - { - /* Otherwise lengthptr equals to NULL, - which is the second phase of compilation. */ - int count, index; - named_group *ng; - - /* Generate code using the data - collected in the pre-processing phase. */ - - if (meta == META_COND_RNUMBER) - { - code[1+LINK_SIZE] = OP_RREF; - PUT2(code, 2 + LINK_SIZE, pptr[1]); - skipunits = 1 + IMM2_SIZE; - pptr += 1 + SIZEOFFSET; - goto GROUP_PROCESS_NOTE_EMPTY; - } - - if (meta_arg == 0) - { - code[1+LINK_SIZE] = (meta == META_COND_RNAME)? OP_RREF : OP_CREF; - PUT2(code, 2 + LINK_SIZE, pptr[1]); - skipunits = 1 + IMM2_SIZE; - pptr += 1 + SIZEOFFSET; - goto GROUP_PROCESS_NOTE_EMPTY; - } - - ng = cb->named_groups + pptr[1]; - count = 0; /* Values for first pass (avoids compiler warning) */ - index = 0; - - /* The failed case is an internal error. */ - if (!PRIV(compile_find_dupname_details)(ng->name, ng->length, &index, - &count, errorcodeptr, cb)) return 0; - - /* A duplicated name was found. Note that if an R name is found - (META_COND_RNUMBER), it is a reference test, not a recursion test. */ - - code[1 + LINK_SIZE] = (meta == META_COND_RNAME)? OP_DNRREF : OP_DNCREF; - - /* Insert appropriate data values. */ - PUT2(code, 2 + LINK_SIZE, index); - PUT2(code, 2 + LINK_SIZE + IMM2_SIZE, count); - skipunits = 1 + 2 * IMM2_SIZE; - pptr += 1 + SIZEOFFSET; - } - - PCRE2_ASSERT(meta != META_CAPTURE_NAME); - goto GROUP_PROCESS_NOTE_EMPTY; - - /* The DEFINE condition is always false. Its internal groups may never - be called, so matched_char must remain false, hence the jump to - GROUP_PROCESS rather than GROUP_PROCESS_NOTE_EMPTY. */ - - case META_COND_DEFINE: - bravalue = OP_COND; - GETPLUSOFFSET(offset, pptr); - code[1+LINK_SIZE] = OP_DEFINE; - skipunits = 1; - goto GROUP_PROCESS; - - /* Conditional test of a group's being set. */ - - case META_COND_NUMBER: - bravalue = OP_COND; - GETPLUSOFFSET(offset, pptr); - - groupnumber = *(++pptr); - if (groupnumber > cb->bracount) - { - *errorcodeptr = ERR15; - cb->erroroffset = offset; - return 0; - } - if (groupnumber > cb->top_backref) cb->top_backref = groupnumber; - - /* Point at initial ( for too many branches error */ - offset -= 2; - code[1+LINK_SIZE] = OP_CREF; - skipunits = 1+IMM2_SIZE; - PUT2(code, 2+LINK_SIZE, groupnumber); - goto GROUP_PROCESS_NOTE_EMPTY; - - /* Test for the PCRE2 version. */ - - case META_COND_VERSION: - bravalue = OP_COND; - if (pptr[1] > 0) - code[1+LINK_SIZE] = ((PCRE2_MAJOR > pptr[2]) || - (PCRE2_MAJOR == pptr[2] && PCRE2_MINOR >= pptr[3]))? - OP_TRUE : OP_FALSE; - else - code[1+LINK_SIZE] = (PCRE2_MAJOR == pptr[2] && PCRE2_MINOR == pptr[3])? - OP_TRUE : OP_FALSE; - skipunits = 1; - pptr += 3; - goto GROUP_PROCESS_NOTE_EMPTY; - - /* The condition is an assertion, possibly preceded by a callout. */ - - case META_COND_ASSERT: - bravalue = OP_COND; - goto GROUP_PROCESS_NOTE_EMPTY; - - - /* ===================================================================*/ - /* Handle all kinds of nested bracketed groups. The non-capturing, - non-conditional cases are here; others come to GROUP_PROCESS via goto. */ - - case META_LOOKAHEAD: - bravalue = OP_ASSERT; - cb->assert_depth += 1; - goto GROUP_PROCESS; - - case META_LOOKAHEAD_NA: - bravalue = OP_ASSERT_NA; - cb->assert_depth += 1; - goto GROUP_PROCESS; - - /* Optimize (?!) to (*FAIL) unless it is quantified - which is a weird - thing to do, but Perl allows all assertions to be quantified, and when - they contain capturing parentheses there may be a potential use for - this feature. Not that that applies to a quantified (?!) but we allow - it for uniformity. */ - - case META_LOOKAHEADNOT: - if (pptr[1] == META_KET && - (pptr[2] < META_ASTERISK || pptr[2] > META_MINMAX_QUERY)) - { - *code++ = OP_FAIL; - pptr++; - } - else - { - bravalue = OP_ASSERT_NOT; - cb->assert_depth += 1; - goto GROUP_PROCESS; - } - break; - - case META_LOOKBEHIND: - bravalue = OP_ASSERTBACK; - cb->assert_depth += 1; - goto GROUP_PROCESS; - - case META_LOOKBEHINDNOT: - bravalue = OP_ASSERTBACK_NOT; - cb->assert_depth += 1; - goto GROUP_PROCESS; - - case META_LOOKBEHIND_NA: - bravalue = OP_ASSERTBACK_NA; - cb->assert_depth += 1; - goto GROUP_PROCESS; - - case META_ATOMIC: - bravalue = OP_ONCE; - goto GROUP_PROCESS_NOTE_EMPTY; - - case META_SCRIPT_RUN: - bravalue = OP_SCRIPT_RUN; - goto GROUP_PROCESS_NOTE_EMPTY; - - case META_NOCAPTURE: - bravalue = OP_BRA; - /* Fall through */ - - /* Process nested bracketed regex. The nesting depth is maintained for the - benefit of the stackguard function. The test for too deep nesting is now - done in parse_regex(). Assertion and DEFINE groups come to GROUP_PROCESS; - others come to GROUP_PROCESS_NOTE_EMPTY, to indicate that we need to take - note of whether or not they may match an empty string. */ - - GROUP_PROCESS_NOTE_EMPTY: - note_group_empty = TRUE; - - GROUP_PROCESS: - cb->parens_depth += 1; - *code = bravalue; - pptr++; - tempcode = code; - tempreqvary = cb->req_varyopt; /* Save value before group */ - length_prevgroup = 0; /* Initialize for pre-compile phase */ - - if ((group_return = - compile_regex( - options, /* The options state */ - xoptions, /* The extra options state */ - &tempcode, /* Where to put code (updated) */ - &pptr, /* Input pointer (updated) */ - errorcodeptr, /* Where to put an error message */ - skipunits, /* Skip over bracket number */ - &subfirstcu, /* For possible first char */ - &subfirstcuflags, - &subreqcu, /* For possible last char */ - &subreqcuflags, - bcptr, /* Current branch chain */ - open_caps, /* Pointer to capture stack */ - cb, /* Compile data block */ - (lengthptr == NULL)? NULL : /* Actual compile phase */ - &length_prevgroup /* Pre-compile phase */ - )) == 0) - return 0; /* Error */ - - cb->parens_depth -= 1; - - /* If that was a non-conditional significant group (not an assertion, not a - DEFINE) that matches at least one character, then the current item matches - a character. Conditionals are handled below. */ - - if (note_group_empty && bravalue != OP_COND && group_return > 0) - matched_char = TRUE; - - /* If we've just compiled an assertion, pop the assert depth. */ - - if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERT_SCS) - cb->assert_depth -= 1; - - /* At the end of compiling, code is still pointing to the start of the - group, while tempcode has been updated to point past the end of the group. - The parsed pattern pointer (pptr) is on the closing META_KET. - - If this is a conditional bracket, check that there are no more than - two branches in the group, or just one if it's a DEFINE group. We do this - in the real compile phase, not in the pre-pass, where the whole group may - not be available. */ - - if (bravalue == OP_COND && lengthptr == NULL) - { - PCRE2_UCHAR *tc = code; - int condcount = 0; - - do { - condcount++; - tc += GET(tc,1); - } - while (*tc != OP_KET); - - /* A DEFINE group is never obeyed inline (the "condition" is always - false). It must have only one branch. Having checked this, change the - opcode to OP_FALSE. */ - - if (code[LINK_SIZE+1] == OP_DEFINE) - { - if (condcount > 1) - { - cb->erroroffset = offset; - *errorcodeptr = ERR54; - return 0; - } - code[LINK_SIZE+1] = OP_FALSE; - bravalue = OP_DEFINE; /* A flag to suppress char handling below */ - } - - /* A "normal" conditional group. If there is just one branch, we must not - make use of its firstcu or reqcu, because this is equivalent to an - empty second branch. Also, it may match an empty string. If there are two - branches, this item must match a character if the group must. */ - - else - { - if (condcount > 2) - { - cb->erroroffset = offset; - *errorcodeptr = ERR27; - return 0; - } - if (condcount == 1) subfirstcuflags = subreqcuflags = REQ_NONE; - else if (group_return > 0) matched_char = TRUE; - } - } - - /* In the pre-compile phase, update the length by the length of the group, - less the brackets at either end. Then reduce the compiled code to just a - set of non-capturing brackets so that it doesn't use much memory if it is - duplicated by a quantifier.*/ - - if (lengthptr != NULL) - { - if (OFLOW_MAX - *lengthptr < length_prevgroup - 2 - 2*LINK_SIZE) - { - *errorcodeptr = ERR20; - return 0; - } - *lengthptr += length_prevgroup - 2 - 2*LINK_SIZE; - code++; /* This already contains bravalue */ - PUTINC(code, 0, 1 + LINK_SIZE); - *code++ = OP_KET; - PUTINC(code, 0, 1 + LINK_SIZE); - break; /* No need to waste time with special character handling */ - } - - /* Otherwise update the main code pointer to the end of the group. */ - - code = tempcode; - - /* For a DEFINE group, required and first character settings are not - relevant. */ - - if (bravalue == OP_DEFINE) break; - - /* Handle updating of the required and first code units for other types of - group. Update for normal brackets of all kinds, and conditions with two - branches (see code above). If the bracket is followed by a quantifier with - zero repeat, we have to back off. Hence the definition of zeroreqcu and - zerofirstcu outside the main loop so that they can be accessed for the back - off. */ - - zeroreqcu = reqcu; - zeroreqcuflags = reqcuflags; - zerofirstcu = firstcu; - zerofirstcuflags = firstcuflags; - groupsetfirstcu = FALSE; - - if (bravalue >= OP_ONCE) /* Not an assertion */ - { - /* If we have not yet set a firstcu in this branch, take it from the - subpattern, remembering that it was set here so that a repeat of more - than one can replicate it as reqcu if necessary. If the subpattern has - no firstcu, set "none" for the whole branch. In both cases, a zero - repeat forces firstcu to "none". */ - - if (firstcuflags == REQ_UNSET && subfirstcuflags != REQ_UNSET) - { - if (subfirstcuflags < REQ_NONE) - { - firstcu = subfirstcu; - firstcuflags = subfirstcuflags; - groupsetfirstcu = TRUE; - } - else firstcuflags = REQ_NONE; - zerofirstcuflags = REQ_NONE; - } - - /* If firstcu was previously set, convert the subpattern's firstcu - into reqcu if there wasn't one, using the vary flag that was in - existence beforehand. */ - - else if (subfirstcuflags < REQ_NONE && subreqcuflags >= REQ_NONE) - { - subreqcu = subfirstcu; - subreqcuflags = subfirstcuflags | tempreqvary; - } - - /* If the subpattern set a required code unit (or set a first code unit - that isn't really the first code unit - see above), set it. */ - - if (subreqcuflags < REQ_NONE) - { - reqcu = subreqcu; - reqcuflags = subreqcuflags; - } - } - - /* For a forward assertion, we take the reqcu, if set, provided that the - group has also set a firstcu. This can be helpful if the pattern that - follows the assertion doesn't set a different char. For example, it's - useful for /(?=abcde).+/. We can't set firstcu for an assertion, however - because it leads to incorrect effect for patterns such as /(?=a)a.+/ when - the "real" "a" would then become a reqcu instead of a firstcu. This is - overcome by a scan at the end if there's no firstcu, looking for an - asserted first char. A similar effect for patterns like /(?=.*X)X$/ means - we must only take the reqcu when the group also set a firstcu. Otherwise, - in that example, 'X' ends up set for both. */ - - else if ((bravalue == OP_ASSERT || bravalue == OP_ASSERT_NA) && - subreqcuflags < REQ_NONE && subfirstcuflags < REQ_NONE) - { - reqcu = subreqcu; - reqcuflags = subreqcuflags; - } - - break; /* End of nested group handling */ - - - /* ===================================================================*/ - /* Handle named backreferences and recursions. */ - - case META_BACKREF_BYNAME: - case META_RECURSE_BYNAME: - { - int count, index; - PCRE2_SPTR name; - named_group *ng; - uint32_t length = *(++pptr); - - GETPLUSOFFSET(offset, pptr); - name = cb->start_pattern + offset; - - /* In the first pass, the names generated in the pre-pass are available, - but the main name table has not yet been created. Scan the list of names - generated in the pre-pass in order to get a number and whether or not - this name is duplicated. */ - - ng = PRIV(compile_find_named_group)(name, length, cb); - - if (ng == NULL) - { - /* If the name was not found we have a bad reference. */ - *errorcodeptr = ERR15; - cb->erroroffset = offset; - return 0; - } - - groupnumber = ng->number; - - /* For a recursion, that's all that is needed. We can now go to - the code that handles numerical recursion, applying it to the first - group with the given name. */ - - if (meta == META_RECURSE_BYNAME) - { - meta_arg = groupnumber; - goto HANDLE_NUMERICAL_RECURSION; - } - - /* For a back reference, update the back reference map and the - maximum back reference. */ - - cb->backref_map |= (groupnumber < 32)? (1u << groupnumber) : 1; - if (groupnumber > cb->top_backref) - cb->top_backref = groupnumber; - - /* If a back reference name is not duplicated, we can handle it as - a numerical reference. */ - - if ((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) == 0) - { - meta_arg = groupnumber; - goto HANDLE_SINGLE_REFERENCE; - } - - /* If a back reference name is duplicated, we generate a different - opcode to a numerical back reference. In the second pass we must - search for the index and count in the final name table. */ - - count = 0; /* Values for first pass (avoids compiler warning) */ - index = 0; - if (lengthptr == NULL && !PRIV(compile_find_dupname_details)(name, length, - &index, &count, errorcodeptr, cb)) return 0; - - if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; - *code++ = ((options & PCRE2_CASELESS) != 0)? OP_DNREFI : OP_DNREF; - PUT2INC(code, 0, index); - PUT2INC(code, 0, count); - if ((options & PCRE2_CASELESS) != 0) - *code++ = (((xoptions & PCRE2_EXTRA_CASELESS_RESTRICT) != 0)? - REFI_FLAG_CASELESS_RESTRICT : 0) | - (((xoptions & PCRE2_EXTRA_TURKISH_CASING) != 0)? - REFI_FLAG_TURKISH_CASING : 0); - } - break; - - - /* ===================================================================*/ - /* Handle a numerical callout. */ - - case META_CALLOUT_NUMBER: - code[0] = OP_CALLOUT; - PUT(code, 1, pptr[1]); /* Offset to next pattern item */ - PUT(code, 1 + LINK_SIZE, pptr[2]); /* Length of next pattern item */ - code[1 + 2*LINK_SIZE] = pptr[3]; - pptr += 3; - code += PRIV(OP_lengths)[OP_CALLOUT]; - break; - - - /* ===================================================================*/ - /* Handle a callout with a string argument. In the pre-pass we just compute - the length without generating anything. The length in pptr[3] includes both - delimiters; in the actual compile only the first one is copied, but a - terminating zero is added. Any doubled delimiters within the string make - this an overestimate, but it is not worth bothering about. */ - - case META_CALLOUT_STRING: - if (lengthptr != NULL) - { - *lengthptr += pptr[3] + (1 + 4*LINK_SIZE); - pptr += 3; - SKIPOFFSET(pptr); - } - - /* In the real compile we can copy the string. The starting delimiter is - included so that the client can discover it if they want. We also pass the - start offset to help a script language give better error messages. */ - - else - { - PCRE2_SPTR pp; - uint32_t delimiter; - uint32_t length = pptr[3]; - PCRE2_UCHAR *callout_string = code + (1 + 4*LINK_SIZE); - - code[0] = OP_CALLOUT_STR; - PUT(code, 1, pptr[1]); /* Offset to next pattern item */ - PUT(code, 1 + LINK_SIZE, pptr[2]); /* Length of next pattern item */ - - pptr += 3; - GETPLUSOFFSET(offset, pptr); /* Offset to string in pattern */ - pp = cb->start_pattern + offset; - delimiter = *callout_string++ = *pp++; - if (delimiter == CHAR_LEFT_CURLY_BRACKET) - delimiter = CHAR_RIGHT_CURLY_BRACKET; - PUT(code, 1 + 3*LINK_SIZE, (int)(offset + 1)); /* One after delimiter */ - - /* The syntax of the pattern was checked in the parsing scan. The length - includes both delimiters, but we have passed the opening one just above, - so we reduce length before testing it. The test is for > 1 because we do - not want to copy the final delimiter. This also ensures that pp[1] is - accessible. */ - - while (--length > 1) - { - if (*pp == delimiter && pp[1] == delimiter) - { - *callout_string++ = delimiter; - pp += 2; - length--; - } - else *callout_string++ = *pp++; - } - *callout_string++ = CHAR_NUL; - - /* Set the length of the entire item, the advance to its end. */ - - PUT(code, 1 + 2*LINK_SIZE, (int)(callout_string - code)); - code = callout_string; - } - break; - - - /* ===================================================================*/ - /* Handle repetition. The different types are all sorted out in the parsing - pass. */ - - case META_MINMAX_PLUS: - case META_MINMAX_QUERY: - case META_MINMAX: - repeat_min = *(++pptr); - repeat_max = *(++pptr); - goto REPEAT; - - case META_ASTERISK: - case META_ASTERISK_PLUS: - case META_ASTERISK_QUERY: - repeat_min = 0; - repeat_max = REPEAT_UNLIMITED; - goto REPEAT; - - case META_PLUS: - case META_PLUS_PLUS: - case META_PLUS_QUERY: - repeat_min = 1; - repeat_max = REPEAT_UNLIMITED; - goto REPEAT; - - case META_QUERY: - case META_QUERY_PLUS: - case META_QUERY_QUERY: - repeat_min = 0; - repeat_max = 1; - - REPEAT: - if (previous_matched_char && repeat_min > 0) matched_char = TRUE; - - /* Remember whether this is a variable length repeat, and default to - single-char opcodes. */ - - reqvary = (repeat_min == repeat_max)? 0 : REQ_VARY; - - /* Adjust first and required code units for a zero repeat. */ - - if (repeat_min == 0) - { - firstcu = zerofirstcu; - firstcuflags = zerofirstcuflags; - reqcu = zeroreqcu; - reqcuflags = zeroreqcuflags; - } - - /* Note the greediness and possessiveness. */ - - switch (meta) - { - case META_MINMAX_PLUS: - case META_ASTERISK_PLUS: - case META_PLUS_PLUS: - case META_QUERY_PLUS: - repeat_type = 0; /* Force greedy */ - possessive_quantifier = TRUE; - break; - - case META_MINMAX_QUERY: - case META_ASTERISK_QUERY: - case META_PLUS_QUERY: - case META_QUERY_QUERY: - repeat_type = greedy_non_default; - possessive_quantifier = FALSE; - break; - - default: - repeat_type = greedy_default; - possessive_quantifier = FALSE; - break; - } - - /* Save start of previous item, in case we have to move it up in order to - insert something before it, and remember what it was. */ - - PCRE2_ASSERT(previous != NULL); - tempcode = previous; - op_previous = *previous; - - /* Now handle repetition for the different types of item. If the repeat - minimum and the repeat maximum are both 1, we can ignore the quantifier for - non-parenthesized items, as they have only one alternative. For anything in - parentheses, we must not ignore if {1} is possessive. */ - - switch (op_previous) - { - /* If previous was a character or negated character match, abolish the - item and generate a repeat item instead. If a char item has a minimum of - more than one, ensure that it is set in reqcu - it might not be if a - sequence such as x{3} is the first thing in a branch because the x will - have gone into firstcu instead. */ - - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - if (repeat_max == 1 && repeat_min == 1) goto END_REPEAT; - op_type = chartypeoffset[op_previous - OP_CHAR]; - - /* Deal with UTF characters that take up more than one code unit. */ - -#ifdef MAYBE_UTF_MULTI - if (utf && NOT_FIRSTCU(code[-1])) - { - PCRE2_UCHAR *lastchar = code - 1; - BACKCHAR(lastchar); - mclength = (uint32_t)(code - lastchar); /* Length of UTF character */ - memcpy(mcbuffer, lastchar, CU2BYTES(mclength)); /* Save the char */ - } - else -#endif /* MAYBE_UTF_MULTI */ - - /* Handle the case of a single code unit - either with no UTF support, or - with UTF disabled, or for a single-code-unit UTF character. In the latter - case, for a repeated positive match, get the caseless flag for the - required code unit from the previous character, because a class like [Aa] - sets a caseless A but by now the req_caseopt flag has been reset. */ - - { - mcbuffer[0] = code[-1]; - mclength = 1; - if (op_previous <= OP_CHARI && repeat_min > 1) - { - reqcu = mcbuffer[0]; - reqcuflags = cb->req_varyopt; - if (op_previous == OP_CHARI) reqcuflags |= REQ_CASELESS; - } - } - goto OUTPUT_SINGLE_REPEAT; /* Code shared with single character types */ - - /* If previous was a character class or a back reference, we put the - repeat stuff after it, but just skip the item if the repeat was {0,0}. */ - -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - case OP_ECLASS: -#endif - case OP_CLASS: - case OP_NCLASS: - case OP_REF: - case OP_REFI: - case OP_DNREF: - case OP_DNREFI: - - if (repeat_max == 0) - { - code = previous; - goto END_REPEAT; - } - if (repeat_max == 1 && repeat_min == 1) goto END_REPEAT; - - if (repeat_min == 0 && repeat_max == REPEAT_UNLIMITED) - *code++ = OP_CRSTAR + repeat_type; - else if (repeat_min == 1 && repeat_max == REPEAT_UNLIMITED) - *code++ = OP_CRPLUS + repeat_type; - else if (repeat_min == 0 && repeat_max == 1) - *code++ = OP_CRQUERY + repeat_type; - else - { - *code++ = OP_CRRANGE + repeat_type; - PUT2INC(code, 0, repeat_min); - if (repeat_max == REPEAT_UNLIMITED) repeat_max = 0; /* 2-byte encoding for max */ - PUT2INC(code, 0, repeat_max); - } - break; - - /* Prior to 10.30, repeated recursions were wrapped in OP_ONCE brackets - because pcre2_match() could not handle backtracking into recursively - called groups. Now that this backtracking is available, we no longer need - to do this. However, we still need to replicate recursions as we do for - groups so as to have independent backtracking points. We can replicate - for the minimum number of repeats directly. For optional repeats we now - wrap the recursion in OP_BRA brackets and make use of the bracket - repetition. */ - - case OP_RECURSE: - if (repeat_max == 1 && repeat_min == 1 && !possessive_quantifier) - goto END_REPEAT; - - /* Generate unwrapped repeats for a non-zero minimum, except when the - minimum is 1 and the maximum unlimited, because that can be handled with - OP_BRA terminated by OP_KETRMAX/MIN. When the maximum is equal to the - minimum, we just need to generate the appropriate additional copies. - Otherwise we need to generate one more, to simulate the situation when - the minimum is zero. */ - - if (repeat_min > 0 && (repeat_min != 1 || repeat_max != REPEAT_UNLIMITED)) - { - int replicate = repeat_min; - - if (repeat_min == repeat_max) replicate--; - - /* In the pre-compile phase, we don't actually do the replication. We - just adjust the length as if we had. Do some paranoid checks for - potential integer overflow. */ - - if (lengthptr != NULL) - { - PCRE2_SIZE delta; - if (PRIV(ckd_smul)(&delta, replicate, (int)length_prevgroup) || - OFLOW_MAX - *lengthptr < delta) - { - *errorcodeptr = ERR20; - return 0; - } - *lengthptr += delta; - } - else for (i = 0; i < replicate; i++) - { - memcpy(code, previous, CU2BYTES(length_prevgroup)); - previous = code; - code += length_prevgroup; - } - - /* If the number of repeats is fixed, we are done. Otherwise, adjust - the counts and fall through. */ - - if (repeat_min == repeat_max) break; - if (repeat_max != REPEAT_UNLIMITED) repeat_max -= repeat_min; - repeat_min = 0; - } - - /* Wrap the recursion call in OP_BRA brackets. */ - { - PCRE2_SIZE length = (lengthptr != NULL) ? 1 + LINK_SIZE : length_prevgroup; - - (void)memmove(previous + 1 + LINK_SIZE, previous, CU2BYTES(length)); - op_previous = *previous = OP_BRA; - PUT(previous, 1, 1 + LINK_SIZE + length); - previous[1 + LINK_SIZE + length] = OP_KET; - PUT(previous, 2 + LINK_SIZE + length, 1 + LINK_SIZE + length); - } - code += 2 + 2 * LINK_SIZE; - length_prevgroup += 2 + 2 * LINK_SIZE; - group_return = -1; /* Set "may match empty string" */ - - /* Now treat as a repeated OP_BRA. */ - PCRE2_FALLTHROUGH /* Fall through */ - - /* If previous was a bracket group, we may have to replicate it in - certain cases. Note that at this point we can encounter only the "basic" - bracket opcodes such as BRA and CBRA, as this is the place where they get - converted into the more special varieties such as BRAPOS and SBRA. - Originally, PCRE did not allow repetition of assertions, but now it does, - for Perl compatibility. */ - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERT_NA: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_BRA: - case OP_CBRA: - case OP_COND: - { - int len = (int)(code - previous); - PCRE2_UCHAR *bralink = NULL; - PCRE2_UCHAR *brazeroptr = NULL; - - if (repeat_max == 1 && repeat_min == 1 && !possessive_quantifier) - goto END_REPEAT; - - /* Repeating a DEFINE group (or any group where the condition is always - FALSE and there is only one branch) is pointless, but Perl allows the - syntax, so we just ignore the repeat. */ - - if (op_previous == OP_COND && previous[LINK_SIZE+1] == OP_FALSE && - previous[GET(previous, 1)] != OP_ALT) - goto END_REPEAT; - - /* Perl allows all assertions to be quantified, and when they contain - capturing parentheses and/or are optional there are potential uses for - this feature. PCRE2 used to force the maximum quantifier to 1 on the - invalid grounds that further repetition was never useful. This was - always a bit pointless, since an assertion could be wrapped with a - repeated group to achieve the effect. General repetition is now - permitted, but if the maximum is unlimited it is set to one more than - the minimum. */ - - if (op_previous < OP_ONCE) /* Assertion */ - { - if (repeat_max == REPEAT_UNLIMITED) repeat_max = repeat_min + 1; - } - - /* The case of a zero minimum is special because of the need to stick - OP_BRAZERO in front of it, and because the group appears once in the - data, whereas in other cases it appears the minimum number of times. For - this reason, it is simplest to treat this case separately, as otherwise - the code gets far too messy. There are several special subcases when the - minimum is zero. */ - - if (repeat_min == 0) - { - /* If the maximum is also zero, we used to just omit the group from - the output altogether, like this: - - ** if (repeat_max == 0) - ** { - ** code = previous; - ** goto END_REPEAT; - ** } - - However, that fails when a group or a subgroup within it is - referenced as a subroutine from elsewhere in the pattern, so now we - stick in OP_SKIPZERO in front of it so that it is skipped on - execution. As we don't have a list of which groups are referenced, we - cannot do this selectively. - - If the maximum is 1 or unlimited, we just have to stick in the - BRAZERO and do no more at this point. */ - - if (repeat_max <= 1 || repeat_max == REPEAT_UNLIMITED) - { - (void)memmove(previous + 1, previous, CU2BYTES(len)); - code++; - if (repeat_max == 0) - { - *previous++ = OP_SKIPZERO; - goto END_REPEAT; - } - brazeroptr = previous; /* Save for possessive optimizing */ - *previous++ = OP_BRAZERO + repeat_type; - } - - /* If the maximum is greater than 1 and limited, we have to replicate - in a nested fashion, sticking OP_BRAZERO before each set of brackets. - The first one has to be handled carefully because it's the original - copy, which has to be moved up. The remainder can be handled by code - that is common with the non-zero minimum case below. We have to - adjust the value or repeat_max, since one less copy is required. */ - - else - { - int linkoffset; - (void)memmove(previous + 2 + LINK_SIZE, previous, CU2BYTES(len)); - code += 2 + LINK_SIZE; - *previous++ = OP_BRAZERO + repeat_type; - *previous++ = OP_BRA; - - /* We chain together the bracket link offset fields that have to be - filled in later when the ends of the brackets are reached. */ - - linkoffset = (bralink == NULL)? 0 : (int)(previous - bralink); - bralink = previous; - PUTINC(previous, 0, linkoffset); - } - - if (repeat_max != REPEAT_UNLIMITED) repeat_max--; - } - - /* If the minimum is greater than zero, replicate the group as many - times as necessary, and adjust the maximum to the number of subsequent - copies that we need. */ - - else - { - if (repeat_min > 1) - { - /* In the pre-compile phase, we don't actually do the replication. - We just adjust the length as if we had. Do some paranoid checks for - potential integer overflow. */ - - if (lengthptr != NULL) - { - PCRE2_SIZE delta; - if (PRIV(ckd_smul)(&delta, repeat_min - 1, - (int)length_prevgroup) || - OFLOW_MAX - *lengthptr < delta) - { - *errorcodeptr = ERR20; - return 0; - } - *lengthptr += delta; - } - - /* This is compiling for real. If there is a set first code unit - for the group, and we have not yet set a "required code unit", set - it. */ - - else - { - if (groupsetfirstcu && reqcuflags >= REQ_NONE) - { - reqcu = firstcu; - reqcuflags = firstcuflags; - } - for (j = 1; j < repeat_min; j++) - { - memcpy(code, previous, CU2BYTES(len)); - code += len; - } - } - } - - if (repeat_max != REPEAT_UNLIMITED) repeat_max -= repeat_min; - } - - /* This code is common to both the zero and non-zero minimum cases. If - the maximum is limited, it replicates the group in a nested fashion, - remembering the bracket starts on a stack. In the case of a zero - minimum, the first one was set up above. In all cases the repeat_max - now specifies the number of additional copies needed. Again, we must - remember to replicate entries on the forward reference list. */ - - if (repeat_max != REPEAT_UNLIMITED) - { - /* In the pre-compile phase, we don't actually do the replication. We - just adjust the length as if we had. For each repetition we must add - 1 to the length for BRAZERO and for all but the last repetition we - must add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some - paranoid checks to avoid integer overflow. */ - - if (lengthptr != NULL && repeat_max > 0) - { - PCRE2_SIZE delta; - if (PRIV(ckd_smul)(&delta, repeat_max, - (int)length_prevgroup + 1 + 2 + 2*LINK_SIZE) || - OFLOW_MAX + (2 + 2*LINK_SIZE) - *lengthptr < delta) - { - *errorcodeptr = ERR20; - return 0; - } - delta -= (2 + 2*LINK_SIZE); /* Last one doesn't nest */ - *lengthptr += delta; - } - - /* This is compiling for real */ - - else for (i = repeat_max; i >= 1; i--) - { - *code++ = OP_BRAZERO + repeat_type; - - /* All but the final copy start a new nesting, maintaining the - chain of brackets outstanding. */ - - if (i != 1) - { - int linkoffset; - *code++ = OP_BRA; - linkoffset = (bralink == NULL)? 0 : (int)(code - bralink); - bralink = code; - PUTINC(code, 0, linkoffset); - } - - memcpy(code, previous, CU2BYTES(len)); - code += len; - } - - /* Now chain through the pending brackets, and fill in their length - fields (which are holding the chain links pro tem). */ - - while (bralink != NULL) - { - int oldlinkoffset; - int linkoffset = (int)(code - bralink + 1); - PCRE2_UCHAR *bra = code - linkoffset; - oldlinkoffset = GET(bra, 1); - bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset; - *code++ = OP_KET; - PUTINC(code, 0, linkoffset); - PUT(bra, 1, linkoffset); - } - } - - /* If the maximum is unlimited, set a repeater in the final copy. For - SCRIPT_RUN and ONCE brackets, that's all we need to do. However, - possessively repeated ONCE brackets can be converted into non-capturing - brackets, as the behaviour of (?:xx)++ is the same as (?>xx)++ and this - saves having to deal with possessive ONCEs specially. - - Otherwise, when we are doing the actual compile phase, check to see - whether this group is one that could match an empty string. If so, - convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so - that runtime checking can be done. [This check is also applied to ONCE - and SCRIPT_RUN groups at runtime, but in a different way.] - - Then, if the quantifier was possessive and the bracket is not a - conditional, we convert the BRA code to the POS form, and the KET code - to KETRPOS. (It turns out to be convenient at runtime to detect this - kind of subpattern at both the start and at the end.) The use of - special opcodes makes it possible to reduce greatly the stack usage in - pcre2_match(). If the group is preceded by OP_BRAZERO, convert this to - OP_BRAPOSZERO. - - Then, if the minimum number of matches is 1 or 0, cancel the possessive - flag so that the default action below, of wrapping everything inside - atomic brackets, does not happen. When the minimum is greater than 1, - there will be earlier copies of the group, and so we still have to wrap - the whole thing. */ - - else - { - PCRE2_UCHAR *ketcode = code - 1 - LINK_SIZE; - PCRE2_UCHAR *bracode = ketcode - GET(ketcode, 1); - - /* Convert possessive ONCE brackets to non-capturing */ - - if (*bracode == OP_ONCE && possessive_quantifier) *bracode = OP_BRA; - - /* For non-possessive ONCE and for SCRIPT_RUN brackets, all we need - to do is to set the KET. */ - - if (*bracode == OP_ONCE || *bracode == OP_SCRIPT_RUN) - *ketcode = OP_KETRMAX + repeat_type; - - /* Handle non-SCRIPT_RUN and non-ONCE brackets and possessive ONCEs - (which have been converted to non-capturing above). */ - - else - { - /* In the compile phase, adjust the opcode if the group can match - an empty string. For a conditional group with only one branch, the - value of group_return will not show "could be empty", so we must - check that separately. */ - - if (lengthptr == NULL) - { - if (group_return < 0) *bracode += OP_SBRA - OP_BRA; - if (*bracode == OP_COND && bracode[GET(bracode,1)] != OP_ALT) - *bracode = OP_SCOND; - } - - /* Handle possessive quantifiers. */ - - if (possessive_quantifier) - { - /* For COND brackets, we wrap the whole thing in a possessively - repeated non-capturing bracket, because we have not invented POS - versions of the COND opcodes. */ - - if (*bracode == OP_COND || *bracode == OP_SCOND) - { - int nlen = (int)(code - bracode); - (void)memmove(bracode + 1 + LINK_SIZE, bracode, CU2BYTES(nlen)); - code += 1 + LINK_SIZE; - nlen += 1 + LINK_SIZE; - *bracode = (*bracode == OP_COND)? OP_BRAPOS : OP_SBRAPOS; - *code++ = OP_KETRPOS; - PUTINC(code, 0, nlen); - PUT(bracode, 1, nlen); - } - - /* For non-COND brackets, we modify the BRA code and use KETRPOS. */ - - else - { - *bracode += 1; /* Switch to xxxPOS opcodes */ - *ketcode = OP_KETRPOS; - } - - /* If the minimum is zero, mark it as possessive, then unset the - possessive flag when the minimum is 0 or 1. */ - - if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO; - if (repeat_min < 2) possessive_quantifier = FALSE; - } - - /* Non-possessive quantifier */ - - else *ketcode = OP_KETRMAX + repeat_type; - } - } - } - break; - - /* If previous was a character type match (\d or similar), abolish it and - create a suitable repeat item. The code is shared with single-character - repeats by setting op_type to add a suitable offset into repeat_type. - Note the the Unicode property types will be present only when - SUPPORT_UNICODE is defined, but we don't wrap the little bits of code - here because it just makes it horribly messy. */ - - default: - - /* LCOV_EXCL_START */ - if (op_previous >= OP_EODN || op_previous <= OP_WORD_BOUNDARY) - { - PCRE2_DEBUG_UNREACHABLE(); - *errorcodeptr = ERR10; /* Not a character type - internal error */ - return 0; - } - /* LCOV_EXCL_STOP */ - - { - int prop_type, prop_value; - PCRE2_UCHAR *oldcode; - - if (repeat_max == 1 && repeat_min == 1) goto END_REPEAT; - - op_type = OP_TYPESTAR - OP_STAR; /* Use type opcodes */ - mclength = 0; /* Not a character */ - - if (op_previous == OP_PROP || op_previous == OP_NOTPROP) - { - prop_type = previous[1]; - prop_value = previous[2]; - } - else - { - /* Come here from just above with a character in mcbuffer/mclength. - You must also set op_type before the jump. */ - OUTPUT_SINGLE_REPEAT: - prop_type = prop_value = -1; - } - - /* At this point, if prop_type == prop_value == -1 we either have a - character in mcbuffer when mclength is greater than zero, or we have - mclength zero, in which case there is a non-property character type in - op_previous. If prop_type/value are not negative, we have a property - character type in op_previous. */ - - oldcode = code; /* Save where we were */ - code = previous; /* Usually overwrite previous item */ - - /* If the maximum is zero then the minimum must also be zero; Perl allows - this case, so we do too - by simply omitting the item altogether. */ - - if (repeat_max == 0) goto END_REPEAT; - - /* Combine the op_type with the repeat_type */ - - repeat_type += op_type; - - /* A minimum of zero is handled either as the special case * or ?, or as - an UPTO, with the maximum given. */ - - if (repeat_min == 0) - { - if (repeat_max == REPEAT_UNLIMITED) *code++ = OP_STAR + repeat_type; - else if (repeat_max == 1) *code++ = OP_QUERY + repeat_type; - else - { - *code++ = OP_UPTO + repeat_type; - PUT2INC(code, 0, repeat_max); - } - } - - /* A repeat minimum of 1 is optimized into some special cases. If the - maximum is unlimited, we use OP_PLUS. Otherwise, the original item is - left in place and, if the maximum is greater than 1, we use OP_UPTO with - one less than the maximum. */ - - else if (repeat_min == 1) - { - if (repeat_max == REPEAT_UNLIMITED) - *code++ = OP_PLUS + repeat_type; - else - { - code = oldcode; /* Leave previous item in place */ - if (repeat_max == 1) goto END_REPEAT; - *code++ = OP_UPTO + repeat_type; - PUT2INC(code, 0, repeat_max - 1); - } - } - - /* The case {n,n} is just an EXACT, while the general case {n,m} is - handled as an EXACT followed by an UPTO or STAR or QUERY. */ - - else - { - *code++ = OP_EXACT + op_type; /* NB EXACT doesn't have repeat_type */ - PUT2INC(code, 0, repeat_min); - - /* Unless repeat_max equals repeat_min, fill in the data for EXACT, - and then generate the second opcode. For a repeated Unicode property - match, there are two extra values that define the required property, - and mclength is set zero to indicate this. */ - - if (repeat_max != repeat_min) - { - if (mclength > 0) - { - memcpy(code, mcbuffer, CU2BYTES(mclength)); - code += mclength; - } - else - { - *code++ = op_previous; - if (prop_type >= 0) - { - *code++ = prop_type; - *code++ = prop_value; - } - } - - /* Now set up the following opcode */ - - if (repeat_max == REPEAT_UNLIMITED) - *code++ = OP_STAR + repeat_type; - else - { - repeat_max -= repeat_min; - if (repeat_max == 1) - { - *code++ = OP_QUERY + repeat_type; - } - else - { - *code++ = OP_UPTO + repeat_type; - PUT2INC(code, 0, repeat_max); - } - } - } - } - - /* Fill in the character or character type for the final opcode. */ - - if (mclength > 0) - { - memcpy(code, mcbuffer, CU2BYTES(mclength)); - code += mclength; - } - else - { - *code++ = op_previous; - if (prop_type >= 0) - { - *code++ = prop_type; - *code++ = prop_value; - } - } - } - break; - } /* End of switch on different op_previous values */ - - - /* If the character following a repeat is '+', possessive_quantifier is - TRUE. For some opcodes, there are special alternative opcodes for this - case. For anything else, we wrap the entire repeated item inside OP_ONCE - brackets. Logically, the '+' notation is just syntactic sugar, taken from - Sun's Java package, but the special opcodes can optimize it. - - Some (but not all) possessively repeated subpatterns have already been - completely handled in the code just above. For them, possessive_quantifier - is always FALSE at this stage. Note that the repeated item starts at - tempcode, not at previous, which might be the first part of a string whose - (former) last char we repeated. */ - - if (possessive_quantifier) - { - int len; - - /* Possessifying an EXACT quantifier has no effect, so we can ignore it. - However, QUERY, STAR, or UPTO may follow (for quantifiers such as {5,6}, - {5,}, or {5,10}). We skip over an EXACT item; if the length of what - remains is greater than zero, there's a further opcode that can be - handled. If not, do nothing, leaving the EXACT alone. */ - - switch(*tempcode) - { - case OP_TYPEEXACT: - tempcode += PRIV(OP_lengths)[*tempcode] + - ((tempcode[1 + IMM2_SIZE] == OP_PROP - || tempcode[1 + IMM2_SIZE] == OP_NOTPROP)? 2 : 0); - break; - - /* CHAR opcodes are used for exacts whose count is 1. */ - - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - case OP_EXACT: - case OP_EXACTI: - case OP_NOTEXACT: - case OP_NOTEXACTI: - tempcode += PRIV(OP_lengths)[*tempcode]; -#ifdef SUPPORT_UNICODE - if (utf && HAS_EXTRALEN(tempcode[-1])) - tempcode += GET_EXTRALEN(tempcode[-1]); -#endif - break; - - /* For the class opcodes, the repeat operator appears at the end; - adjust tempcode to point to it. */ - - case OP_CLASS: - case OP_NCLASS: - tempcode += 1 + 32/sizeof(PCRE2_UCHAR); - break; - -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - case OP_ECLASS: - tempcode += GET(tempcode, 1); - break; -#endif - } - - /* If tempcode is equal to code (which points to the end of the repeated - item), it means we have skipped an EXACT item but there is no following - QUERY, STAR, or UPTO; the value of len will be 0, and we do nothing. In - all other cases, tempcode will be pointing to the repeat opcode, and will - be less than code, so the value of len will be greater than 0. */ - - len = (int)(code - tempcode); - if (len > 0) - { - unsigned int repcode = *tempcode; - - /* There is a table for possessifying opcodes, all of which are less - than OP_CALLOUT. A zero entry means there is no possessified version. - */ - - if (repcode < OP_CALLOUT && opcode_possessify[repcode] > 0) - *tempcode = opcode_possessify[repcode]; - - /* For opcode without a special possessified version, wrap the item in - ONCE brackets. */ - - else - { - (void)memmove(tempcode + 1 + LINK_SIZE, tempcode, CU2BYTES(len)); - code += 1 + LINK_SIZE; - len += 1 + LINK_SIZE; - tempcode[0] = OP_ONCE; - *code++ = OP_KET; - PUTINC(code, 0, len); - PUT(tempcode, 1, len); - } - } - } - - /* We set the "follows varying string" flag for subsequently encountered - reqcus if it isn't already set and we have just passed a varying length - item. */ - - END_REPEAT: - cb->req_varyopt |= reqvary; - break; - - - /* ===================================================================*/ - /* Handle a 32-bit data character with a value greater than META_END. */ - - case META_BIGVALUE: - pptr++; - goto NORMAL_CHAR; - - - /* ===============================================================*/ - /* Handle a back reference by number, which is the meta argument. The - pattern offsets for back references to group numbers less than 10 are held - in a special vector, to avoid using more than two parsed pattern elements - in 64-bit environments. We only need the offset to the first occurrence, - because if that doesn't fail, subsequent ones will also be OK. */ - - case META_BACKREF: - if (meta_arg < 10) offset = cb->small_ref_offset[meta_arg]; - else GETPLUSOFFSET(offset, pptr); - - if (meta_arg > cb->bracount) - { - cb->erroroffset = offset; - *errorcodeptr = ERR15; /* Non-existent subpattern */ - return 0; - } - - /* Come here from named backref handling when the reference is to a - single group (that is, not to a duplicated name). The back reference - data will have already been updated. We must disable firstcu if not - set, to cope with cases like (?=(\w+))\1: which would otherwise set ':' - later. */ - - HANDLE_SINGLE_REFERENCE: - if (firstcuflags == REQ_UNSET) zerofirstcuflags = firstcuflags = REQ_NONE; - *code++ = ((options & PCRE2_CASELESS) != 0)? OP_REFI : OP_REF; - PUT2INC(code, 0, meta_arg); - if ((options & PCRE2_CASELESS) != 0) - *code++ = (((xoptions & PCRE2_EXTRA_CASELESS_RESTRICT) != 0)? - REFI_FLAG_CASELESS_RESTRICT : 0) | - (((xoptions & PCRE2_EXTRA_TURKISH_CASING) != 0)? - REFI_FLAG_TURKISH_CASING : 0); - - /* Update the map of back references, and keep the highest one. We - could do this in parse_regex() for numerical back references, but not - for named back references, because we don't know the numbers to which - named back references refer. So we do it all in this function. */ - - cb->backref_map |= (meta_arg < 32)? (1u << meta_arg) : 1; - if (meta_arg > cb->top_backref) cb->top_backref = meta_arg; - break; - - - /* ===============================================================*/ - /* Handle recursion by inserting the number of the called group (which is - the meta argument) after OP_RECURSE. At the end of compiling the pattern is - scanned and these numbers are replaced by offsets within the pattern. It is - done like this to avoid problems with forward references and adjusting - offsets when groups are duplicated and moved (as discovered in previous - implementations). Note that a recursion does not have a set first - character. */ - - case META_RECURSE: - GETPLUSOFFSET(offset, pptr); - if (meta_arg > cb->bracount) - { - cb->erroroffset = offset; - *errorcodeptr = ERR15; /* Non-existent subpattern */ - return 0; - } - HANDLE_NUMERICAL_RECURSION: - *code = OP_RECURSE; - PUT(code, 1, meta_arg); - code += 1 + LINK_SIZE; - /* Repeat processing requires this information to - determine the real length in pre-compile phase. */ - length_prevgroup = 1 + LINK_SIZE; - - if (META_CODE(pptr[1]) == META_OFFSET || - META_CODE(pptr[1]) == META_CAPTURE_NAME || - META_CODE(pptr[1]) == META_CAPTURE_NUMBER) - { - recurse_arguments *args; - - if (lengthptr != NULL) - { - if (!PRIV(compile_parse_recurse_args)(pptr, offset, errorcodeptr, cb)) - return 0; - - args = (recurse_arguments*)cb->last_data; - length_prevgroup += (args->size * (1 + IMM2_SIZE)); - *lengthptr += (args->size * (1 + IMM2_SIZE)); - pptr += args->skip_size; - } - else - { - uint16_t *current, *end; - - args = (recurse_arguments*)cb->first_data; - PCRE2_ASSERT(args != NULL && args->header.type == CDATA_RECURSE_ARGS); - - current = (uint16_t*)(args + 1); - end = current + args->size; - PCRE2_ASSERT(end > current); - - do - { - code[0] = OP_CREF; - PUT2(code, 1, *current); - code += 1 + IMM2_SIZE; - } - while (++current < end); - - length_prevgroup += (args->size * (1 + IMM2_SIZE)); - pptr += args->skip_size; - cb->first_data = args->header.next; - cb->cx->memctl.free(args, cb->cx->memctl.memory_data); - } - } - - groupsetfirstcu = FALSE; - cb->had_recurse = TRUE; - if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; - zerofirstcu = firstcu; - zerofirstcuflags = firstcuflags; - break; - - - /* ===============================================================*/ - /* Handle capturing parentheses; the number is the meta argument. */ - - case META_CAPTURE: - bravalue = OP_CBRA; - skipunits = IMM2_SIZE; - PUT2(code, 1+LINK_SIZE, meta_arg); - cb->lastcapture = meta_arg; - goto GROUP_PROCESS_NOTE_EMPTY; - - - /* ===============================================================*/ - /* Handle escape sequence items. For ones like \d, the ESC_values are - arranged to be the same as the corresponding OP_values in the default case - when PCRE2_UCP is not set (which is the only case in which they will appear - here). - - Note: \Q and \E are never seen here, as they were dealt with in - parse_pattern(). Neither are numerical back references or recursions, which - were turned into META_BACKREF or META_RECURSE items, respectively. \k and - \g, when followed by names, are turned into META_BACKREF_BYNAME or - META_RECURSE_BYNAME. */ - - case META_ESCAPE: - - /* We can test for escape sequences that consume a character because their - values lie between ESC_b and ESC_Z; this may have to change if any new ones - are ever created. For these sequences, we disable the setting of a first - character if it hasn't already been set. */ - - if (meta_arg > ESC_b && meta_arg < ESC_Z) - { - matched_char = TRUE; - if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; - } - - /* Set values to reset to if this is followed by a zero repeat. */ - - zerofirstcu = firstcu; - zerofirstcuflags = firstcuflags; - zeroreqcu = reqcu; - zeroreqcuflags = reqcuflags; - - /* If Unicode is not supported, \P and \p are not allowed and are - faulted at parse time, so will never appear here. */ - -#ifdef SUPPORT_UNICODE - if (meta_arg == ESC_P || meta_arg == ESC_p) - { - uint32_t ptype = *(++pptr) >> 16; - uint32_t pdata = *pptr & 0xffff; - - /* In caseless matching, particular characteristics Lu, Ll, and Lt get - converted to the general characteristic L&. That is, upper, lower, and - title case letters are all conflated. */ - - if ((options & PCRE2_CASELESS) != 0 && ptype == PT_PC && - (pdata == ucp_Lu || pdata == ucp_Ll || pdata == ucp_Lt)) - { - ptype = PT_LAMP; - pdata = 0; - } - - /* The special case of \p{Any} is compiled to OP_ALLANY and \P{Any} - is compiled to [] so as to benefit from the auto-anchoring code. */ - - if (ptype == PT_ANY) - { - if (meta_arg == ESC_P) - { - *code++ = OP_CLASS; - memset(code, 0, 32); - code += 32 / sizeof(PCRE2_UCHAR); - } - else - *code++ = OP_ALLANY; - } - else - { - *code++ = (meta_arg == ESC_p)? OP_PROP : OP_NOTPROP; - *code++ = ptype; - *code++ = pdata; - } - break; /* End META_ESCAPE */ - } -#endif - - /* \K is forbidden in lookarounds since 10.38 because that's what Perl has - done. However, there's an option, in case anyone was relying on it. */ - - if (cb->assert_depth > 0 && meta_arg == ESC_K && - (xoptions & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) == 0) - { - *errorcodeptr = ERR99; - return 0; - } - - /* For the rest (including \X when Unicode is supported - if not it's - faulted at parse time), the OP value is the escape value when PCRE2_UCP is - not set; if it is set, most of them do not show up here because they are - converted into Unicode property tests in parse_regex(). - - In non-UTF mode, and for both 32-bit modes, we turn \C into OP_ALLANY - instead of OP_ANYBYTE so that it works in DFA mode and in lookbehinds. - There are special UCP codes for \B and \b which are used in UCP mode unless - "word" matching is being forced to ASCII. - - Note that \b and \B do a one-character lookbehind, and \A also behaves as - if it does. */ - - switch(meta_arg) - { - case ESC_C: - cb->external_flags |= PCRE2_HASBKC; /* Record */ -#if PCRE2_CODE_UNIT_WIDTH == 32 - meta_arg = OP_ALLANY; - (void)utf; /* Avoid compiler warning. */ -#else - if (!utf) meta_arg = OP_ALLANY; -#endif - break; - - case ESC_B: - case ESC_b: - if ((options & PCRE2_UCP) != 0 && (xoptions & PCRE2_EXTRA_ASCII_BSW) == 0) - meta_arg = (meta_arg == ESC_B)? OP_NOT_UCP_WORD_BOUNDARY : - OP_UCP_WORD_BOUNDARY; - PCRE2_FALLTHROUGH /* Fall through */ - - case ESC_A: - if (cb->max_lookbehind == 0) cb->max_lookbehind = 1; - break; - - case ESC_K: - cb->external_flags |= PCRE2_HASBSK; /* Record */ - break; - } - - *code++ = meta_arg; - break; /* End META_ESCAPE */ - - - /* ===================================================================*/ - /* Handle an unrecognized meta value. A parsed pattern value less than - META_END is a literal. Otherwise we have a problem. */ - - default: - /* LCOV_EXCL_START */ - if (meta >= META_END) - { - PCRE2_DEBUG_UNREACHABLE(); - *errorcodeptr = ERR89; /* Internal error - unrecognized. */ - return 0; - } - /* LCOV_EXCL_STOP */ - - /* Handle a literal character. We come here by goto in the case of a - 32-bit, non-UTF character whose value is greater than META_END. */ - - NORMAL_CHAR: - meta = *pptr; /* Get the full 32 bits */ - NORMAL_CHAR_SET: /* Character is already in meta */ - matched_char = TRUE; - - /* For caseless UTF or UCP mode, check whether this character has more than - one other case. If so, generate a special OP_PROP item instead of OP_CHARI. - When casing restrictions apply, ignore caseless sets that start with an - ASCII character. If the character is affected by the special Turkish rules, - hardcode the matching characters using a caseset. */ - -#ifdef SUPPORT_UNICODE - if ((utf||ucp) && (options & PCRE2_CASELESS) != 0) - { - uint32_t caseset; - - if ((xoptions & (PCRE2_EXTRA_TURKISH_CASING|PCRE2_EXTRA_CASELESS_RESTRICT)) == - PCRE2_EXTRA_TURKISH_CASING && - UCD_ANY_I(meta)) - { - caseset = PRIV(ucd_turkish_dotted_i_caseset) + (UCD_DOTTED_I(meta)? 0 : 3); - } - else if ((caseset = UCD_CASESET(meta)) != 0 && - (xoptions & PCRE2_EXTRA_CASELESS_RESTRICT) != 0 && - PRIV(ucd_caseless_sets)[caseset] < 128) - { - caseset = 0; /* Ignore the caseless set if it's restricted. */ - } - - if (caseset != 0) - { - *code++ = OP_PROP; - *code++ = PT_CLIST; - *code++ = caseset; - if (firstcuflags == REQ_UNSET) - firstcuflags = zerofirstcuflags = REQ_NONE; - break; /* End handling this meta item */ - } - } -#endif - - /* Caseful matches, or caseless and not one of the multicase characters. We - come here by goto in the case of a positive class that contains only - case-partners of a character with just two cases; matched_char has already - been set TRUE and options fudged if necessary. */ - - CLASS_CASELESS_CHAR: - - /* Get the character's code units into mcbuffer, with the length in - mclength. When not in UTF mode, the length is always 1. */ - -#ifdef SUPPORT_UNICODE - if (utf) mclength = PRIV(ord2utf)(meta, mcbuffer); else -#endif - { - mclength = 1; - mcbuffer[0] = meta; - } - - /* Generate the appropriate code */ - - *code++ = ((options & PCRE2_CASELESS) != 0)? OP_CHARI : OP_CHAR; - memcpy(code, mcbuffer, CU2BYTES(mclength)); - code += mclength; - - /* Remember if \r or \n were seen */ - - if (mcbuffer[0] == CHAR_CR || mcbuffer[0] == CHAR_NL) - cb->external_flags |= PCRE2_HASCRORLF; - - /* Set the first and required code units appropriately. If no previous - first code unit, set it from this character, but revert to none on a zero - repeat. Otherwise, leave the firstcu value alone, and don't change it on - a zero repeat. */ - - if (firstcuflags == REQ_UNSET) - { - zerofirstcuflags = REQ_NONE; - zeroreqcu = reqcu; - zeroreqcuflags = reqcuflags; - - /* If the character is more than one code unit long, we can set a single - firstcu only if it is not to be matched caselessly. Multiple possible - starting code units may be picked up later in the studying code. */ - - if (mclength == 1 || req_caseopt == 0) - { - firstcu = mcbuffer[0]; - firstcuflags = req_caseopt; - if (mclength != 1) - { - reqcu = code[-1]; - reqcuflags = cb->req_varyopt; - } - } - else firstcuflags = reqcuflags = REQ_NONE; - } - - /* firstcu was previously set; we can set reqcu only if the length is - 1 or the matching is caseful. */ - - else - { - zerofirstcu = firstcu; - zerofirstcuflags = firstcuflags; - zeroreqcu = reqcu; - zeroreqcuflags = reqcuflags; - if (mclength == 1 || req_caseopt == 0) - { - reqcu = code[-1]; - reqcuflags = req_caseopt | cb->req_varyopt; - } - } - - /* If caselessness was temporarily instated, reset it. */ - - if (reset_caseful) - { - options &= ~PCRE2_CASELESS; - req_caseopt = 0; - reset_caseful = FALSE; - } - - break; /* End literal character handling */ - } /* End of big switch */ - } /* End of big loop */ - -/* LCOV_EXCL_START */ -PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ -return 0; /* Avoid compiler warnings */ -/* LCOV_EXCL_STOP */ -} - - - -/************************************************* -* Compile regex: a sequence of alternatives * -*************************************************/ - -/* On entry, pptr is pointing past the bracket meta, but on return it points to -the closing bracket or META_END. The code variable is pointing at the code unit -into which the BRA operator has been stored. This function is used during the -pre-compile phase when we are trying to find out the amount of memory needed, -as well as during the real compile phase. The value of lengthptr distinguishes -the two phases. - -Arguments: - options option bits, including any changes for this subpattern - xoptions extra option bits, ditto - codeptr -> the address of the current code pointer - pptrptr -> the address of the current parsed pattern pointer - errorcodeptr -> pointer to error code variable - skipunits skip this many code units at start (for brackets and OP_COND) - firstcuptr place to put the first required code unit - firstcuflagsptr place to put the first code unit flags - reqcuptr place to put the last required code unit - reqcuflagsptr place to put the last required code unit flags - bcptr pointer to the chain of currently open branches - cb points to the data block with tables pointers etc. - lengthptr NULL during the real compile phase - points to length accumulator during pre-compile phase - -Returns: 0 There has been an error - +1 Success, this group must match at least one character - -1 Success, this group may match an empty string -*/ - -static int -compile_regex(uint32_t options, uint32_t xoptions, PCRE2_UCHAR **codeptr, - uint32_t **pptrptr, int *errorcodeptr, uint32_t skipunits, - uint32_t *firstcuptr, uint32_t *firstcuflagsptr, uint32_t *reqcuptr, - uint32_t *reqcuflagsptr, branch_chain *bcptr, open_capitem *open_caps, - compile_block *cb, PCRE2_SIZE *lengthptr) -{ -PCRE2_UCHAR *code = *codeptr; -PCRE2_UCHAR *last_branch = code; -PCRE2_UCHAR *start_bracket = code; -BOOL lookbehind; -open_capitem capitem; -int capnumber = 0; -int okreturn = 1; -uint32_t *pptr = *pptrptr; -uint32_t firstcu, reqcu; -uint32_t lookbehindlength; -uint32_t lookbehindminlength; -uint32_t firstcuflags, reqcuflags; -PCRE2_SIZE length; -branch_chain bc; - -/* If set, call the external function that checks for stack availability. */ - -if (cb->cx->stack_guard != NULL && - cb->cx->stack_guard(cb->parens_depth, cb->cx->stack_guard_data)) - { - *errorcodeptr= ERR33; - cb->erroroffset = 0; - return 0; - } - -/* Miscellaneous initialization */ - -bc.outer = bcptr; -bc.current_branch = code; - -firstcu = reqcu = 0; -firstcuflags = reqcuflags = REQ_UNSET; - -/* Accumulate the length for use in the pre-compile phase. Start with the -length of the BRA and KET and any extra code units that are required at the -beginning. We accumulate in a local variable to save frequent testing of -lengthptr for NULL. We cannot do this by looking at the value of 'code' at the -start and end of each alternative, because compiled items are discarded during -the pre-compile phase so that the workspace is not exceeded. */ - -length = 2 + 2*LINK_SIZE + skipunits; - -/* Remember if this is a lookbehind assertion, and if it is, save its length -and skip over the pattern offset. */ - -lookbehind = *code == OP_ASSERTBACK || - *code == OP_ASSERTBACK_NOT || - *code == OP_ASSERTBACK_NA; - -if (lookbehind) - { - lookbehindlength = META_DATA(pptr[-1]); - lookbehindminlength = *pptr; - pptr += SIZEOFFSET; - } -else lookbehindlength = lookbehindminlength = 0; - -/* If this is a capturing subpattern, add to the chain of open capturing items -so that we can detect them if (*ACCEPT) is encountered. Note that only OP_CBRA -need be tested here; changing this opcode to one of its variants, e.g. -OP_SCBRAPOS, happens later, after the group has been compiled. */ - -if (*code == OP_CBRA) - { - capnumber = GET2(code, 1 + LINK_SIZE); - capitem.number = capnumber; - capitem.next = open_caps; - capitem.assert_depth = cb->assert_depth; - open_caps = &capitem; - } - -/* Offset is set zero to mark that this bracket is still open */ - -PUT(code, 1, 0); -code += 1 + LINK_SIZE + skipunits; - -/* Loop for each alternative branch */ - -for (;;) - { - int branch_return; - uint32_t branchfirstcu = 0, branchreqcu = 0; - uint32_t branchfirstcuflags = REQ_UNSET, branchreqcuflags = REQ_UNSET; - - /* Insert OP_REVERSE or OP_VREVERSE if this is a lookbehind assertion. There - is only a single minimum length for the whole assertion. When the minimum - length is LOOKBEHIND_MAX it means that all branches are of fixed length, - though not necessarily the same length. In this case, the original OP_REVERSE - can be used. It can also be used if a branch in a variable length lookbehind - has the same maximum and minimum. Otherwise, use OP_VREVERSE, which has both - maximum and minimum values. */ - - if (lookbehind && lookbehindlength > 0) - { - if (lookbehindminlength == LOOKBEHIND_MAX || - lookbehindminlength == lookbehindlength) - { - *code++ = OP_REVERSE; - PUT2INC(code, 0, lookbehindlength); - length += 1 + IMM2_SIZE; - } - else - { - *code++ = OP_VREVERSE; - PUT2INC(code, 0, lookbehindminlength); - PUT2INC(code, 0, lookbehindlength); - length += 1 + 2*IMM2_SIZE; - } - } - - /* Now compile the branch; in the pre-compile phase its length gets added - into the length. */ - - if ((branch_return = - compile_branch(&options, &xoptions, &code, &pptr, errorcodeptr, - &branchfirstcu, &branchfirstcuflags, &branchreqcu, &branchreqcuflags, - &bc, open_caps, cb, (lengthptr == NULL)? NULL : &length)) == 0) - return 0; - - /* If a branch can match an empty string, so can the whole group. */ - - if (branch_return < 0) okreturn = -1; - - /* In the real compile phase, there is some post-processing to be done. */ - - if (lengthptr == NULL) - { - /* If this is the first branch, the firstcu and reqcu values for the - branch become the values for the regex. */ - - if (*last_branch != OP_ALT) - { - firstcu = branchfirstcu; - firstcuflags = branchfirstcuflags; - reqcu = branchreqcu; - reqcuflags = branchreqcuflags; - } - - /* If this is not the first branch, the first char and reqcu have to - match the values from all the previous branches, except that if the - previous value for reqcu didn't have REQ_VARY set, it can still match, - and we set REQ_VARY for the group from this branch's value. */ - - else - { - /* If we previously had a firstcu, but it doesn't match the new branch, - we have to abandon the firstcu for the regex, but if there was - previously no reqcu, it takes on the value of the old firstcu. */ - - if (firstcuflags != branchfirstcuflags || firstcu != branchfirstcu) - { - if (firstcuflags < REQ_NONE) - { - if (reqcuflags >= REQ_NONE) - { - reqcu = firstcu; - reqcuflags = firstcuflags; - } - } - firstcuflags = REQ_NONE; - } - - /* If we (now or from before) have no firstcu, a firstcu from the - branch becomes a reqcu if there isn't a branch reqcu. */ - - if (firstcuflags >= REQ_NONE && branchfirstcuflags < REQ_NONE && - branchreqcuflags >= REQ_NONE) - { - branchreqcu = branchfirstcu; - branchreqcuflags = branchfirstcuflags; - } - - /* Now ensure that the reqcus match */ - - if (((reqcuflags & ~REQ_VARY) != (branchreqcuflags & ~REQ_VARY)) || - reqcu != branchreqcu) - reqcuflags = REQ_NONE; - else - { - reqcu = branchreqcu; - reqcuflags |= branchreqcuflags; /* To "or" REQ_VARY if present */ - } - } - } - - /* Handle reaching the end of the expression, either ')' or end of pattern. - In the real compile phase, go back through the alternative branches and - reverse the chain of offsets, with the field in the BRA item now becoming an - offset to the first alternative. If there are no alternatives, it points to - the end of the group. The length in the terminating ket is always the length - of the whole bracketed item. Return leaving the pointer at the terminating - char. */ - - if (META_CODE(*pptr) != META_ALT) - { - if (lengthptr == NULL) - { - uint32_t branch_length = (uint32_t)(code - last_branch); - do - { - uint32_t prev_length = GET(last_branch, 1); - PUT(last_branch, 1, branch_length); - branch_length = prev_length; - last_branch -= branch_length; - } - while (branch_length > 0); - } - - /* Fill in the ket */ - - *code = OP_KET; - PUT(code, 1, (uint32_t)(code - start_bracket)); - code += 1 + LINK_SIZE; - - /* Set values to pass back */ - - *codeptr = code; - *pptrptr = pptr; - *firstcuptr = firstcu; - *firstcuflagsptr = firstcuflags; - *reqcuptr = reqcu; - *reqcuflagsptr = reqcuflags; - if (lengthptr != NULL) - { - if (OFLOW_MAX - *lengthptr < length) - { - *errorcodeptr = ERR20; - return 0; - } - *lengthptr += length; - } - return okreturn; - } - - /* Another branch follows. In the pre-compile phase, we can move the code - pointer back to where it was for the start of the first branch. (That is, - pretend that each branch is the only one.) - - In the real compile phase, insert an ALT node. Its length field points back - to the previous branch while the bracket remains open. At the end the chain - is reversed. It's done like this so that the start of the bracket has a - zero offset until it is closed, making it possible to detect recursion. */ - - if (lengthptr != NULL) - { - code = *codeptr + 1 + LINK_SIZE + skipunits; - length += 1 + LINK_SIZE; - } - else - { - *code = OP_ALT; - PUT(code, 1, (int)(code - last_branch)); - bc.current_branch = last_branch = code; - code += 1 + LINK_SIZE; - } - - /* Set the maximum lookbehind length for the next branch (if not in a - lookbehind the value will be zero) and then advance past the vertical bar. */ - - lookbehindlength = META_DATA(*pptr); - pptr++; - } - -/* LCOV_EXCL_START */ -PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ -return 0; /* Avoid compiler warnings */ -/* LCOV_EXCL_STOP */ -} - - - -/************************************************* -* Check for anchored pattern * -*************************************************/ - -/* Try to find out if this is an anchored regular expression. Consider each -alternative branch. If they all start with OP_SOD or OP_CIRC, or with a bracket -all of whose alternatives start with OP_SOD or OP_CIRC (recurse ad lib), then -it's anchored. However, if this is a multiline pattern, then only OP_SOD will -be found, because ^ generates OP_CIRCM in that mode. - -We can also consider a regex to be anchored if OP_SOM starts all its branches. -This is the code for \G, which means "match at start of match position, taking -into account the match offset". - -A branch is also implicitly anchored if it starts with .* and DOTALL is set, -because that will try the rest of the pattern at all possible matching points, -so there is no point trying again.... er .... - -.... except when the .* appears inside capturing parentheses, and there is a -subsequent back reference to those parentheses. We haven't enough information -to catch that case precisely. - -At first, the best we could do was to detect when .* was in capturing brackets -and the highest back reference was greater than or equal to that level. -However, by keeping a bitmap of the first 31 back references, we can catch some -of the more common cases more precisely. - -... A second exception is when the .* appears inside an atomic group, because -this prevents the number of characters it matches from being adjusted. - -Arguments: - code points to start of the compiled pattern - bracket_map a bitmap of which brackets we are inside while testing; this - handles up to substring 31; after that we just have to take - the less precise approach - cb points to the compile data block - atomcount atomic group level - inassert TRUE if in an assertion - dotstar_anchor TRUE if automatic anchoring optimization is enabled - -Returns: TRUE or FALSE -*/ - -static BOOL -is_anchored(PCRE2_SPTR code, uint32_t bracket_map, compile_block *cb, - int atomcount, BOOL inassert, BOOL dotstar_anchor) -{ -do { - PCRE2_SPTR scode = first_significant_code( - code + PRIV(OP_lengths)[*code], FALSE); - int op = *scode; - - /* Non-capturing brackets */ - - if (op == OP_BRA || op == OP_BRAPOS || - op == OP_SBRA || op == OP_SBRAPOS) - { - if (!is_anchored(scode, bracket_map, cb, atomcount, inassert, dotstar_anchor)) - return FALSE; - } - - /* Capturing brackets */ - - else if (op == OP_CBRA || op == OP_CBRAPOS || - op == OP_SCBRA || op == OP_SCBRAPOS) - { - int n = GET2(scode, 1+LINK_SIZE); - uint32_t new_map = bracket_map | ((n < 32)? (1u << n) : 1); - if (!is_anchored(scode, new_map, cb, atomcount, inassert, dotstar_anchor)) return FALSE; - } - - /* Positive forward assertion */ - - else if (op == OP_ASSERT || op == OP_ASSERT_NA) - { - if (!is_anchored(scode, bracket_map, cb, atomcount, TRUE, dotstar_anchor)) return FALSE; - } - - /* Condition. If there is no second branch, it can't be anchored. */ - - else if (op == OP_COND || op == OP_SCOND) - { - if (scode[GET(scode,1)] != OP_ALT) return FALSE; - if (!is_anchored(scode, bracket_map, cb, atomcount, inassert, dotstar_anchor)) - return FALSE; - } - - /* Atomic groups */ - - else if (op == OP_ONCE) - { - if (!is_anchored(scode, bracket_map, cb, atomcount + 1, inassert, dotstar_anchor)) - return FALSE; - } - - /* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and - it isn't in brackets that are or may be referenced or inside an atomic - group or an assertion. Also the pattern must not contain *PRUNE or *SKIP, - because these break the feature. Consider, for example, /(?s).*?(*PRUNE)b/ - with the subject "aab", which matches "b", i.e. not at the start of a line. - There is also an option that disables auto-anchoring. */ - - else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR || - op == OP_TYPEPOSSTAR)) - { - if (scode[1] != OP_ALLANY || (bracket_map & cb->backref_map) != 0 || - atomcount > 0 || cb->had_pruneorskip || inassert || !dotstar_anchor) - return FALSE; - } - - /* Check for explicit anchoring */ - - else if (op != OP_SOD && op != OP_SOM && op != OP_CIRC) return FALSE; - - code += GET(code, 1); - } -while (*code == OP_ALT); /* Loop for each alternative */ -return TRUE; -} - - - -/************************************************* -* Check for starting with ^ or .* * -*************************************************/ - -/* This is called to find out if every branch starts with ^ or .* so that -"first char" processing can be done to speed things up in multiline -matching and for non-DOTALL patterns that start with .* (which must start at -the beginning or after \n). As in the case of is_anchored() (see above), we -have to take account of back references to capturing brackets that contain .* -because in that case we can't make the assumption. Also, the appearance of .* -inside atomic brackets or in an assertion, or in a pattern that contains *PRUNE -or *SKIP does not count, because once again the assumption no longer holds. - -Arguments: - code points to start of the compiled pattern or a group - bracket_map a bitmap of which brackets we are inside while testing; this - handles up to substring 31; after that we just have to take - the less precise approach - cb points to the compile data - atomcount atomic group level - inassert TRUE if in an assertion - dotstar_anchor TRUE if automatic anchoring optimization is enabled - -Returns: TRUE or FALSE -*/ - -static BOOL -is_startline(PCRE2_SPTR code, unsigned int bracket_map, compile_block *cb, - int atomcount, BOOL inassert, BOOL dotstar_anchor) -{ -do { - PCRE2_SPTR scode = first_significant_code( - code + PRIV(OP_lengths)[*code], FALSE); - int op = *scode; - - /* If we are at the start of a conditional assertion group, *both* the - conditional assertion *and* what follows the condition must satisfy the test - for start of line. Other kinds of condition fail. Note that there may be an - auto-callout at the start of a condition. */ - - if (op == OP_COND) - { - scode += 1 + LINK_SIZE; - - if (*scode == OP_CALLOUT) scode += PRIV(OP_lengths)[OP_CALLOUT]; - else if (*scode == OP_CALLOUT_STR) scode += GET(scode, 1 + 2*LINK_SIZE); - - switch (*scode) - { - case OP_CREF: - case OP_DNCREF: - case OP_RREF: - case OP_DNRREF: - case OP_FAIL: - case OP_FALSE: - case OP_TRUE: - return FALSE; - - default: /* Assertion */ - if (!is_startline(scode, bracket_map, cb, atomcount, TRUE, dotstar_anchor)) - return FALSE; - do scode += GET(scode, 1); while (*scode == OP_ALT); - scode += 1 + LINK_SIZE; - break; - } - scode = first_significant_code(scode, FALSE); - op = *scode; - } - - /* Non-capturing brackets */ - - if (op == OP_BRA || op == OP_BRAPOS || - op == OP_SBRA || op == OP_SBRAPOS) - { - if (!is_startline(scode, bracket_map, cb, atomcount, inassert, dotstar_anchor)) - return FALSE; - } - - /* Capturing brackets */ - - else if (op == OP_CBRA || op == OP_CBRAPOS || - op == OP_SCBRA || op == OP_SCBRAPOS) - { - int n = GET2(scode, 1+LINK_SIZE); - unsigned int new_map = bracket_map | ((n < 32)? (1u << n) : 1); - if (!is_startline(scode, new_map, cb, atomcount, inassert, dotstar_anchor)) - return FALSE; - } - - /* Positive forward assertions */ - - else if (op == OP_ASSERT || op == OP_ASSERT_NA) - { - if (!is_startline(scode, bracket_map, cb, atomcount, TRUE, dotstar_anchor)) - return FALSE; - } - - /* Atomic brackets */ - - else if (op == OP_ONCE) - { - if (!is_startline(scode, bracket_map, cb, atomcount + 1, inassert, dotstar_anchor)) - return FALSE; - } - - /* .* means "start at start or after \n" if it isn't in atomic brackets or - brackets that may be referenced or an assertion, and as long as the pattern - does not contain *PRUNE or *SKIP, because these break the feature. Consider, - for example, /.*?a(*PRUNE)b/ with the subject "aab", which matches "ab", - i.e. not at the start of a line. There is also an option that disables this - optimization. */ - - else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR) - { - if (scode[1] != OP_ANY || (bracket_map & cb->backref_map) != 0 || - atomcount > 0 || cb->had_pruneorskip || inassert || !dotstar_anchor) - return FALSE; - } - - /* Check for explicit circumflex; anything else gives a FALSE result. Note - in particular that this includes atomic brackets OP_ONCE because the number - of characters matched by .* cannot be adjusted inside them. */ - - else if (op != OP_CIRC && op != OP_CIRCM) return FALSE; - - /* Move on to the next alternative */ - - code += GET(code, 1); - } -while (*code == OP_ALT); /* Loop for each alternative */ -return TRUE; -} - - - -/************************************************* -* Scan compiled regex for recursion reference * -*************************************************/ - -/* This function scans through a compiled pattern until it finds an instance of -OP_RECURSE. - -Arguments: - code points to start of expression - utf TRUE in UTF mode - -Returns: pointer to the opcode for OP_RECURSE, or NULL if not found -*/ - -static PCRE2_UCHAR * -find_recurse(PCRE2_UCHAR *code, BOOL utf) -{ -for (;;) - { - PCRE2_UCHAR c = *code; - if (c == OP_END) return NULL; - if (c == OP_RECURSE) return code; - - /* XCLASS is used for classes that cannot be represented just by a bit map. - This includes negated single high-valued characters. ECLASS is used for - classes that use set operations internally. CALLOUT_STR is used for - callouts with string arguments. In each case the length in the table is - zero; the actual length is stored in the compiled code. */ - - if (c == OP_XCLASS || c == OP_ECLASS) code += GET(code, 1); - else if (c == OP_CALLOUT_STR) code += GET(code, 1 + 2*LINK_SIZE); - - /* Otherwise, we can get the item's length from the table, except that for - repeated character types, we have to test for \p and \P, which have an extra - two code units of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, - we must add in its length. */ - - else - { - switch(c) - { - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; - break; - - case OP_TYPEPOSUPTO: - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEEXACT: - if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP) - code += 2; - break; - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_SKIP_ARG: - case OP_THEN_ARG: - code += code[1]; - break; - } - - /* Add in the fixed length from the table */ - - code += PRIV(OP_lengths)[c]; - - /* In UTF-8 and UTF-16 modes, opcodes that are followed by a character may - be followed by a multi-unit character. The length in the table is a - minimum, so we have to arrange to skip the extra units. */ - -#ifdef MAYBE_UTF_MULTI - if (utf) switch(c) - { - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - case OP_EXACT: - case OP_EXACTI: - case OP_NOTEXACT: - case OP_NOTEXACTI: - case OP_UPTO: - case OP_UPTOI: - case OP_NOTUPTO: - case OP_NOTUPTOI: - case OP_MINUPTO: - case OP_MINUPTOI: - case OP_NOTMINUPTO: - case OP_NOTMINUPTOI: - case OP_POSUPTO: - case OP_POSUPTOI: - case OP_NOTPOSUPTO: - case OP_NOTPOSUPTOI: - case OP_STAR: - case OP_STARI: - case OP_NOTSTAR: - case OP_NOTSTARI: - case OP_MINSTAR: - case OP_MINSTARI: - case OP_NOTMINSTAR: - case OP_NOTMINSTARI: - case OP_POSSTAR: - case OP_POSSTARI: - case OP_NOTPOSSTAR: - case OP_NOTPOSSTARI: - case OP_PLUS: - case OP_PLUSI: - case OP_NOTPLUS: - case OP_NOTPLUSI: - case OP_MINPLUS: - case OP_MINPLUSI: - case OP_NOTMINPLUS: - case OP_NOTMINPLUSI: - case OP_POSPLUS: - case OP_POSPLUSI: - case OP_NOTPOSPLUS: - case OP_NOTPOSPLUSI: - case OP_QUERY: - case OP_QUERYI: - case OP_NOTQUERY: - case OP_NOTQUERYI: - case OP_MINQUERY: - case OP_MINQUERYI: - case OP_NOTMINQUERY: - case OP_NOTMINQUERYI: - case OP_POSQUERY: - case OP_POSQUERYI: - case OP_NOTPOSQUERY: - case OP_NOTPOSQUERYI: - if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]); - break; - } -#else - (void)(utf); /* Keep compiler happy by referencing function argument */ -#endif /* MAYBE_UTF_MULTI */ - } - } -} - - - -/************************************************* -* Check for asserted fixed first code unit * -*************************************************/ - -/* During compilation, the "first code unit" settings from forward assertions -are discarded, because they can cause conflicts with actual literals that -follow. However, if we end up without a first code unit setting for an -unanchored pattern, it is worth scanning the regex to see if there is an -initial asserted first code unit. If all branches start with the same asserted -code unit, or with a non-conditional bracket all of whose alternatives start -with the same asserted code unit (recurse ad lib), then we return that code -unit, with the flags set to zero or REQ_CASELESS; otherwise return zero with -REQ_NONE in the flags. - -Arguments: - code points to start of compiled pattern - flags points to the first code unit flags - inassert non-zero if in an assertion - -Returns: the fixed first code unit, or 0 with REQ_NONE in flags -*/ - -static uint32_t -find_firstassertedcu(PCRE2_SPTR code, uint32_t *flags, uint32_t inassert) -{ -uint32_t c = 0; -uint32_t cflags = REQ_NONE; - -*flags = REQ_NONE; -do { - uint32_t d; - uint32_t dflags; - int xl = (*code == OP_CBRA || *code == OP_SCBRA || - *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0; - PCRE2_SPTR scode = first_significant_code(code + 1+LINK_SIZE + xl, TRUE); - PCRE2_UCHAR op = *scode; - - switch(op) - { - default: - return 0; - - case OP_BRA: - case OP_BRAPOS: - case OP_CBRA: - case OP_SCBRA: - case OP_CBRAPOS: - case OP_SCBRAPOS: - case OP_ASSERT: - case OP_ASSERT_NA: - case OP_ONCE: - case OP_SCRIPT_RUN: - d = find_firstassertedcu(scode, &dflags, inassert + - ((op == OP_ASSERT || op == OP_ASSERT_NA)?1:0)); - if (dflags >= REQ_NONE) return 0; - if (cflags >= REQ_NONE) { c = d; cflags = dflags; } - else if (c != d || cflags != dflags) return 0; - break; - - case OP_EXACT: - scode += IMM2_SIZE; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_CHAR: - case OP_PLUS: - case OP_MINPLUS: - case OP_POSPLUS: - if (inassert == 0) return 0; - if (cflags >= REQ_NONE) { c = scode[1]; cflags = 0; } - else if (c != scode[1]) return 0; - break; - - case OP_EXACTI: - scode += IMM2_SIZE; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_CHARI: - case OP_PLUSI: - case OP_MINPLUSI: - case OP_POSPLUSI: - if (inassert == 0) return 0; - - /* If the character is more than one code unit long, we cannot set its - first code unit when matching caselessly. Later scanning may pick up - multiple code units. */ - -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (scode[1] >= 0x80) return 0; -#elif PCRE2_CODE_UNIT_WIDTH == 16 - if (scode[1] >= 0xd800 && scode[1] <= 0xdfff) return 0; -#endif -#endif - - if (cflags >= REQ_NONE) { c = scode[1]; cflags = REQ_CASELESS; } - else if (c != scode[1]) return 0; - break; - } - - code += GET(code, 1); - } -while (*code == OP_ALT); - -*flags = cflags; -return c; -} - - - -/************************************************* -* Skip in parsed pattern * -*************************************************/ - -/* This function is called to skip parts of the parsed pattern when finding the -length of a lookbehind branch. It is called after (*ACCEPT) and (*FAIL) to find -the end of the branch, it is called to skip over an internal lookaround or -(DEFINE) group, and it is also called to skip to the end of a class, during -which it will never encounter nested groups (but there's no need to have -special code for that). - -When called to find the end of a branch or group, pptr must point to the first -meta code inside the branch, not the branch-starting code. In other cases it -can point to the item that causes the function to be called. - -Arguments: - pptr current pointer to skip from - skiptype PSKIP_CLASS when skipping to end of class - PSKIP_ALT when META_ALT ends the skip - PSKIP_KET when only META_KET ends the skip - -Returns: new value of pptr - NULL if META_END is reached - should never occur - or for an unknown meta value - likewise -*/ - -static uint32_t * -parsed_skip(uint32_t *pptr, uint32_t skiptype) -{ -uint32_t nestlevel = 0; - -for (;; pptr++) - { - uint32_t meta = META_CODE(*pptr); - - switch(meta) - { - default: /* Just skip over most items */ - if (meta < META_END) continue; /* Literal */ - break; - - /* The parsed regex is malformed; we have reached the end and did - not find the end of the construct which we are skipping over. */ - - /* LCOV_EXCL_START */ - case META_END: - PCRE2_DEBUG_UNREACHABLE(); - return NULL; - /* LCOV_EXCL_STOP */ - - /* The data for these items is variable in length. */ - - case META_BACKREF: /* Offset is present only if group >= 10 */ - if (META_DATA(*pptr) >= 10) pptr += SIZEOFFSET; - break; - - case META_ESCAPE: - if (*pptr - META_ESCAPE == ESC_P || *pptr - META_ESCAPE == ESC_p) - pptr += 1; /* Skip prop data */ - break; - - case META_MARK: /* Add the length of the name. */ - case META_COMMIT_ARG: - case META_PRUNE_ARG: - case META_SKIP_ARG: - case META_THEN_ARG: - pptr += pptr[1]; - break; - - /* These are the "active" items in this loop. */ - - case META_CLASS_END: - if (skiptype == PSKIP_CLASS) return pptr; - break; - - case META_ATOMIC: - case META_CAPTURE: - case META_COND_ASSERT: - case META_COND_DEFINE: - case META_COND_NAME: - case META_COND_NUMBER: - case META_COND_RNAME: - case META_COND_RNUMBER: - case META_COND_VERSION: - case META_SCS: - case META_LOOKAHEAD: - case META_LOOKAHEADNOT: - case META_LOOKAHEAD_NA: - case META_LOOKBEHIND: - case META_LOOKBEHINDNOT: - case META_LOOKBEHIND_NA: - case META_NOCAPTURE: - case META_SCRIPT_RUN: - nestlevel++; - break; - - case META_ALT: - if (nestlevel == 0 && skiptype == PSKIP_ALT) return pptr; - break; - - case META_KET: - if (nestlevel == 0) return pptr; - nestlevel--; - break; - } - - /* The extra data item length for each meta is in a table. */ - - meta = (meta >> 16) & 0x7fff; - if (meta >= sizeof(meta_extra_lengths)) return NULL; - pptr += meta_extra_lengths[meta]; - } - -/* LCOV_EXCL_START */ -PCRE2_UNREACHABLE(); /* Control never reaches here */ -/* LCOV_EXCL_STOP */ -} - - - -/************************************************* -* Find length of a parsed group * -*************************************************/ - -/* This is called for nested groups within a branch of a lookbehind whose -length is being computed. On entry, the pointer must be at the first element -after the group initializing code. On exit it points to OP_KET. Caching is used -to improve processing speed when the same capturing group occurs many times. - -Arguments: - pptrptr pointer to pointer in the parsed pattern - minptr where to return the minimum length - isinline FALSE if a reference or recursion; TRUE for inline group - errcodeptr pointer to the errorcode - lcptr pointer to the loop counter - group number of captured group or -1 for a non-capturing group - recurses chain of recurse_check to catch mutual recursion - cb pointer to the compile data - -Returns: the maximum group length or a negative number -*/ - -static int -get_grouplength(uint32_t **pptrptr, int *minptr, BOOL isinline, int *errcodeptr, - int *lcptr, int group, parsed_recurse_check *recurses, compile_block *cb) -{ -uint32_t *gi = cb->groupinfo + 2 * group; -int branchlength, branchminlength; -int grouplength = -1; -int groupminlength = INT_MAX; - -/* The cache can be used only if there is no possibility of there being two -groups with the same number. We do not need to set the end pointer for a group -that is being processed as a back reference or recursion, but we must do so for -an inline group. */ - -if (group > 0 && (cb->external_flags & PCRE2_DUPCAPUSED) == 0) - { - uint32_t groupinfo = gi[0]; - if ((groupinfo & GI_NOT_FIXED_LENGTH) != 0) return -1; - if ((groupinfo & GI_SET_FIXED_LENGTH) != 0) - { - if (isinline) *pptrptr = parsed_skip(*pptrptr, PSKIP_KET); - *minptr = gi[1]; - return groupinfo & GI_FIXED_LENGTH_MASK; - } - } - -/* Scan the group. In this case we find the end pointer of necessity. */ - -for(;;) - { - branchlength = get_branchlength(pptrptr, &branchminlength, errcodeptr, lcptr, - recurses, cb); - if (branchlength < 0) goto ISNOTFIXED; - if (branchlength > grouplength) grouplength = branchlength; - if (branchminlength < groupminlength) groupminlength = branchminlength; - if (**pptrptr == META_KET) break; - *pptrptr += 1; /* Skip META_ALT */ - } - -if (group > 0) - { - gi[0] |= (uint32_t)(GI_SET_FIXED_LENGTH | grouplength); - gi[1] = groupminlength; - } - -*minptr = groupminlength; -return grouplength; - -ISNOTFIXED: -if (group > 0) gi[0] |= GI_NOT_FIXED_LENGTH; -return -1; -} - - - -/************************************************* -* Find length of a parsed branch * -*************************************************/ - -/* Return fixed maximum and minimum lengths for a branch in a lookbehind, -giving an error if the length is not limited. On entry, *pptrptr points to the -first element inside the branch. On exit it is set to point to the ALT or KET. - -Arguments: - pptrptr pointer to pointer in the parsed pattern - minptr where to return the minimum length - errcodeptr pointer to error code - lcptr pointer to loop counter - recurses chain of recurse_check to catch mutual recursion - cb pointer to compile block - -Returns: the maximum length, or a negative value on error -*/ - -static int -get_branchlength(uint32_t **pptrptr, int *minptr, int *errcodeptr, int *lcptr, - parsed_recurse_check *recurses, compile_block *cb) -{ -int branchlength = 0; -int branchminlength = 0; -int grouplength, groupminlength; -uint32_t lastitemlength = 0; -uint32_t lastitemminlength = 0; -uint32_t *pptr = *pptrptr; -PCRE2_SIZE offset; -parsed_recurse_check this_recurse; - -/* A large and/or complex regex can take too long to process. This can happen -more often when (?| groups are present in the pattern because their length -cannot be cached. */ - -if ((*lcptr)++ > 2000) - { - *errcodeptr = ERR35; /* Lookbehind is too complicated */ - return -1; - } - -/* Scan the branch, accumulating the length. */ - -for (;; pptr++) - { - parsed_recurse_check *r; - uint32_t *gptr, *gptrend; - uint32_t escape; - uint32_t min, max; - uint32_t group = 0; - uint32_t itemlength = 0; - uint32_t itemminlength = 0; - - if (*pptr < META_END) - { - itemlength = itemminlength = 1; - } - - else switch (META_CODE(*pptr)) - { - case META_KET: - case META_ALT: - goto EXIT; - - /* (*ACCEPT) and (*FAIL) terminate the branch, but we must skip to the - actual termination. */ - - case META_ACCEPT: - case META_FAIL: - pptr = parsed_skip(pptr, PSKIP_ALT); - if (pptr == NULL) goto PARSED_SKIP_FAILED; - goto EXIT; - - case META_MARK: - case META_COMMIT_ARG: - case META_PRUNE_ARG: - case META_SKIP_ARG: - case META_THEN_ARG: - pptr += pptr[1] + 1; - break; - - case META_CIRCUMFLEX: - case META_COMMIT: - case META_DOLLAR: - case META_PRUNE: - case META_SKIP: - case META_THEN: - break; - - case META_OPTIONS: - pptr += 2; - break; - - case META_BIGVALUE: - itemlength = itemminlength = 1; - pptr += 1; - break; - - case META_CLASS: - case META_CLASS_NOT: - itemlength = itemminlength = 1; - pptr = parsed_skip(pptr, PSKIP_CLASS); - if (pptr == NULL) goto PARSED_SKIP_FAILED; - break; - - case META_CLASS_EMPTY_NOT: - case META_DOT: - itemlength = itemminlength = 1; - break; - - case META_CALLOUT_NUMBER: - pptr += 3; - break; - - case META_CALLOUT_STRING: - pptr += 3 + SIZEOFFSET; - break; - - /* Only some escapes consume a character. Of those, \R can match one or two - characters, but \X is never allowed because it matches an unknown number of - characters. \C is allowed only in 32-bit and non-UTF 8/16-bit modes. */ - - case META_ESCAPE: - escape = META_DATA(*pptr); - if (escape == ESC_X) return -1; - if (escape == ESC_R) - { - itemminlength = 1; - itemlength = 2; - } - else if (escape > ESC_b && escape < ESC_Z) - { -#if PCRE2_CODE_UNIT_WIDTH != 32 - if ((cb->external_options & PCRE2_UTF) != 0 && escape == ESC_C) - { - *errcodeptr = ERR36; - return -1; - } -#endif - itemlength = itemminlength = 1; - if (escape == ESC_p || escape == ESC_P) pptr++; /* Skip prop data */ - } - break; - - /* Lookaheads do not contribute to the length of this branch, but they may - contain lookbehinds within them whose lengths need to be set. */ - - case META_LOOKAHEAD: - case META_LOOKAHEADNOT: - case META_LOOKAHEAD_NA: - case META_SCS: - *errcodeptr = check_lookbehinds(pptr + 1, &pptr, recurses, cb, lcptr); - if (*errcodeptr != 0) return -1; - - /* Ignore any qualifiers that follow a lookahead assertion. */ - - switch (pptr[1]) - { - case META_ASTERISK: - case META_ASTERISK_PLUS: - case META_ASTERISK_QUERY: - case META_PLUS: - case META_PLUS_PLUS: - case META_PLUS_QUERY: - case META_QUERY: - case META_QUERY_PLUS: - case META_QUERY_QUERY: - pptr++; - break; - - case META_MINMAX: - case META_MINMAX_PLUS: - case META_MINMAX_QUERY: - pptr += 3; - break; - - default: - break; - } - break; - - /* A nested lookbehind does not contribute any length to this lookbehind, - but must itself be checked and have its lengths set. Note that - set_lookbehind_lengths() updates pptr, leaving it pointing to the final ket - of the group, so no need to update it here. */ - - case META_LOOKBEHIND: - case META_LOOKBEHINDNOT: - case META_LOOKBEHIND_NA: - if (!set_lookbehind_lengths(&pptr, errcodeptr, lcptr, recurses, cb)) - return -1; - break; - - /* Back references and recursions are handled by very similar code. At this - stage, the names generated in the parsing pass are available, but the main - name table has not yet been created. So for the named varieties, scan the - list of names in order to get the number of the first one in the pattern, - and whether or not this name is duplicated. */ - - case META_BACKREF_BYNAME: - if ((cb->external_options & PCRE2_MATCH_UNSET_BACKREF) != 0) - goto ISNOTFIXED; - PCRE2_FALLTHROUGH /* Fall through */ - - case META_RECURSE_BYNAME: - { - PCRE2_SPTR name; - BOOL is_dupname = FALSE; - named_group *ng; - uint32_t meta_code = META_CODE(*pptr); - uint32_t length = *(++pptr); - - GETPLUSOFFSET(offset, pptr); - name = cb->start_pattern + offset; - ng = PRIV(compile_find_named_group)(name, length, cb); - - if (ng == NULL) - { - *errcodeptr = ERR15; /* Non-existent subpattern */ - cb->erroroffset = offset; - return -1; - } - - group = ng->number; - is_dupname = (ng->hash_dup & NAMED_GROUP_IS_DUPNAME) != 0; - - /* A numerical back reference can be fixed length if duplicate capturing - groups are not being used. A non-duplicate named back reference can also - be handled. */ - - if (meta_code == META_RECURSE_BYNAME || - (!is_dupname && (cb->external_flags & PCRE2_DUPCAPUSED) == 0)) - goto RECURSE_OR_BACKREF_LENGTH; /* Handle as a numbered version. */ - } - goto ISNOTFIXED; /* Duplicate name or number */ - - /* The offset values for back references < 10 are in a separate vector - because otherwise they would use more than two parsed pattern elements on - 64-bit systems. */ - - case META_BACKREF: - if ((cb->external_options & PCRE2_MATCH_UNSET_BACKREF) != 0 || - (cb->external_flags & PCRE2_DUPCAPUSED) != 0) - goto ISNOTFIXED; - group = META_DATA(*pptr); - if (group < 10) - { - offset = cb->small_ref_offset[group]; - goto RECURSE_OR_BACKREF_LENGTH; - } - - PCRE2_FALLTHROUGH /* Fall through */ - /* For groups >= 10 - picking up group twice does no harm. */ - - /* A true recursion implies not fixed length, but a subroutine call may - be OK. Back reference "recursions" are also failed. */ - - case META_RECURSE: - group = META_DATA(*pptr); - GETPLUSOFFSET(offset, pptr); - - RECURSE_OR_BACKREF_LENGTH: - if (group > cb->bracount) - { - cb->erroroffset = offset; - *errcodeptr = ERR15; /* Non-existent subpattern */ - return -1; - } - if (group == 0) goto ISNOTFIXED; /* Local recursion */ - for (gptr = cb->parsed_pattern; *gptr != META_END; gptr++) - { - if (META_CODE(*gptr) == META_BIGVALUE) gptr++; - else if (*gptr == (META_CAPTURE | group)) break; - } - - /* We must start the search for the end of the group at the first meta code - inside the group. Otherwise it will be treated as an enclosed group. */ - - gptrend = parsed_skip(gptr + 1, PSKIP_KET); - if (gptrend == NULL) goto PARSED_SKIP_FAILED; - if (pptr > gptr && pptr < gptrend) goto ISNOTFIXED; /* Local recursion */ - for (r = recurses; r != NULL; r = r->prev) if (r->groupptr == gptr) break; - if (r != NULL) goto ISNOTFIXED; /* Mutual recursion */ - this_recurse.prev = recurses; - this_recurse.groupptr = gptr; - - /* We do not need to know the position of the end of the group, that is, - gptr is not used after the call to get_grouplength(). Setting the second - argument FALSE stops it scanning for the end when the length can be found - in the cache. */ - - gptr++; - grouplength = get_grouplength(&gptr, &groupminlength, FALSE, errcodeptr, - lcptr, group, &this_recurse, cb); - if (grouplength < 0) - { - if (*errcodeptr == 0) goto ISNOTFIXED; - return -1; /* Error already set */ - } - itemlength = grouplength; - itemminlength = groupminlength; - break; - - /* A (DEFINE) group is never obeyed inline and so it does not contribute to - the length of this branch. Skip from the following item to the next - unpaired ket. */ - - case META_COND_DEFINE: - pptr = parsed_skip(pptr + 1, PSKIP_KET); - break; - - /* Check other nested groups - advance past the initial data for each type - and then seek a fixed length with get_grouplength(). */ - - case META_COND_NAME: - case META_COND_NUMBER: - case META_COND_RNAME: - case META_COND_RNUMBER: - pptr += 2 + SIZEOFFSET; - goto CHECK_GROUP; - - case META_COND_ASSERT: - pptr += 1; - goto CHECK_GROUP; - - case META_COND_VERSION: - pptr += 4; - goto CHECK_GROUP; - - case META_CAPTURE: - group = META_DATA(*pptr); - PCRE2_FALLTHROUGH /* Fall through */ - - case META_ATOMIC: - case META_NOCAPTURE: - case META_SCRIPT_RUN: - pptr++; - CHECK_GROUP: - grouplength = get_grouplength(&pptr, &groupminlength, TRUE, errcodeptr, - lcptr, group, recurses, cb); - if (grouplength < 0) return -1; - itemlength = grouplength; - itemminlength = groupminlength; - break; - - case META_QUERY: - case META_QUERY_PLUS: - case META_QUERY_QUERY: - min = 0; - max = 1; - goto REPETITION; - - /* Exact repetition is OK; variable repetition is not. A repetition of zero - must subtract the length that has already been added. */ - - case META_MINMAX: - case META_MINMAX_PLUS: - case META_MINMAX_QUERY: - min = pptr[1]; - max = pptr[2]; - pptr += 2; - - REPETITION: - if (max != REPEAT_UNLIMITED) - { - if (lastitemlength != 0 && /* Should not occur, but just in case */ - max != 0 && - (INT_MAX - branchlength)/lastitemlength < max - 1) - { - *errcodeptr = ERR87; /* Integer overflow; lookbehind too big */ - return -1; - } - if (min == 0) branchminlength -= lastitemminlength; - else itemminlength = (min - 1) * lastitemminlength; - if (max == 0) branchlength -= lastitemlength; - else itemlength = (max - 1) * lastitemlength; - break; - } - PCRE2_FALLTHROUGH /* Fall through */ - - /* Any other item means this branch does not have a fixed length. */ - - default: - ISNOTFIXED: - *errcodeptr = ERR25; /* Not fixed length */ - return -1; - } - - /* Add the item length to the branchlength, checking for integer overflow and - for the branch length exceeding the overall limit. Later, if there is at - least one variable-length branch in the group, there is a test for the - (smaller) variable-length branch length limit. */ - - if (INT_MAX - branchlength < (int)itemlength || - (branchlength += itemlength) > LOOKBEHIND_MAX) - { - *errcodeptr = ERR87; - return -1; - } - - branchminlength += itemminlength; - - /* Save this item length for use if the next item is a quantifier. */ - - lastitemlength = itemlength; - lastitemminlength = itemminlength; - } - -EXIT: -*pptrptr = pptr; -*minptr = branchminlength; -return branchlength; - -/* LCOV_EXCL_START */ -PARSED_SKIP_FAILED: -PCRE2_DEBUG_UNREACHABLE(); -*errcodeptr = ERR90; /* Unhandled META code - internal error */ -return -1; -/* LCOV_EXCL_STOP */ -} - - - -/************************************************* -* Set lengths in a lookbehind * -*************************************************/ - -/* This function is called for each lookbehind, to set the lengths in its -branches. An error occurs if any branch does not have a limited maximum length -that is less than the limit (65535). On exit, the pointer must be left on the -final ket. - -The function also maintains the max_lookbehind value. Any lookbehind branch -that contains a nested lookbehind may actually look further back than the -length of the branch. The additional amount is passed back from -get_branchlength() as an "extra" value. - -Arguments: - pptrptr pointer to pointer in the parsed pattern - errcodeptr pointer to error code - lcptr pointer to loop counter - recurses chain of recurse_check to catch mutual recursion - cb pointer to compile block - -Returns: TRUE if all is well - FALSE otherwise, with error code and offset set -*/ - -static BOOL -set_lookbehind_lengths(uint32_t **pptrptr, int *errcodeptr, int *lcptr, - parsed_recurse_check *recurses, compile_block *cb) -{ -PCRE2_SIZE offset; -uint32_t *bptr = *pptrptr; -uint32_t *gbptr = bptr; -int maxlength = 0; -int minlength = INT_MAX; -BOOL variable = FALSE; - -READPLUSOFFSET(offset, bptr); /* Offset for error messages */ -*pptrptr += SIZEOFFSET; - -/* Each branch can have a different maximum length, but we can keep only a -single minimum for the whole group, because there's nowhere to save individual -values in the META_ALT item. */ - -do - { - int branchlength, branchminlength; - - *pptrptr += 1; - branchlength = get_branchlength(pptrptr, &branchminlength, errcodeptr, lcptr, - recurses, cb); - - if (branchlength < 0) - { - /* The errorcode and offset may already be set from a nested lookbehind. */ - if (*errcodeptr == 0) *errcodeptr = ERR25; - if (cb->erroroffset == PCRE2_UNSET) cb->erroroffset = offset; - return FALSE; - } - - if (branchlength != branchminlength) variable = TRUE; - if (branchminlength < minlength) minlength = branchminlength; - if (branchlength > maxlength) maxlength = branchlength; - if (branchlength > cb->max_lookbehind) cb->max_lookbehind = branchlength; - *bptr |= branchlength; /* branchlength never more than 65535 */ - bptr = *pptrptr; - } -while (META_CODE(*bptr) == META_ALT); - -/* If any branch is of variable length, the whole lookbehind is of variable -length. If the maximum length of any branch exceeds the maximum for variable -lookbehinds, give an error. Otherwise, the minimum length is set in the word -that follows the original group META value. For a fixed-length lookbehind, this -is set to LOOKBEHIND_MAX, to indicate that each branch is of a fixed (but -possibly different) length. */ - -if (variable) - { - gbptr[1] = minlength; - if ((PCRE2_SIZE)maxlength > cb->max_varlookbehind) - { - *errcodeptr = ERR100; - cb->erroroffset = offset; - return FALSE; - } - } -else gbptr[1] = LOOKBEHIND_MAX; - -return TRUE; -} - - - -/************************************************* -* Check parsed pattern lookbehinds * -*************************************************/ - -/* This function is called at the end of parsing a pattern if any lookbehinds -were encountered. It scans the parsed pattern for them, calling -set_lookbehind_lengths() for each one. At the start, the errorcode is zero and -the error offset is marked unset. The enables the functions above not to -override settings from deeper nestings. - -This function is called recursively from get_branchlength() for lookaheads in -order to process any lookbehinds that they may contain. It stops when it hits a -non-nested closing parenthesis in this case, returning a pointer to it. - -Arguments - pptr points to where to start (start of pattern or start of lookahead) - retptr if not NULL, return the ket pointer here - recurses chain of recurse_check to catch mutual recursion - cb points to the compile block - lcptr points to loop counter - -Returns: 0 on success, or an errorcode (cb->erroroffset will be set) -*/ - -static int -check_lookbehinds(uint32_t *pptr, uint32_t **retptr, - parsed_recurse_check *recurses, compile_block *cb, int *lcptr) -{ -int errorcode = 0; -int nestlevel = 0; - -cb->erroroffset = PCRE2_UNSET; - -for (; *pptr != META_END; pptr++) - { - if (*pptr < META_END) continue; /* Literal */ - - switch (META_CODE(*pptr)) - { - /* The following erroroffset is a bogus but safe value. This branch should - be avoided by providing a proper implementation for all supported cases - below. */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - cb->erroroffset = 0; - return ERR70; /* Unrecognized meta code */ - /* LCOV_EXCL_STOP */ - - case META_ESCAPE: - if (*pptr - META_ESCAPE == ESC_P || *pptr - META_ESCAPE == ESC_p) - pptr += 1; /* Skip prop data */ - break; - - case META_KET: - if (--nestlevel < 0) - { - if (retptr != NULL) *retptr = pptr; - return 0; - } - break; - - case META_ATOMIC: - case META_CAPTURE: - case META_COND_ASSERT: - case META_SCS: - case META_LOOKAHEAD: - case META_LOOKAHEADNOT: - case META_LOOKAHEAD_NA: - case META_NOCAPTURE: - case META_SCRIPT_RUN: - nestlevel++; - break; - - case META_ACCEPT: - case META_ALT: - case META_ASTERISK: - case META_ASTERISK_PLUS: - case META_ASTERISK_QUERY: - case META_BACKREF: - case META_CIRCUMFLEX: - case META_CLASS: - case META_CLASS_EMPTY: - case META_CLASS_EMPTY_NOT: - case META_CLASS_END: - case META_CLASS_NOT: - case META_COMMIT: - case META_DOLLAR: - case META_DOT: - case META_FAIL: - case META_PLUS: - case META_PLUS_PLUS: - case META_PLUS_QUERY: - case META_PRUNE: - case META_QUERY: - case META_QUERY_PLUS: - case META_QUERY_QUERY: - case META_RANGE_ESCAPED: - case META_RANGE_LITERAL: - case META_SKIP: - case META_THEN: - break; - - case META_OFFSET: - case META_RECURSE: - pptr += SIZEOFFSET; - break; - - case META_BACKREF_BYNAME: - case META_RECURSE_BYNAME: - pptr += 1 + SIZEOFFSET; - break; - - case META_COND_DEFINE: - pptr += SIZEOFFSET; - nestlevel++; - break; - - case META_COND_NAME: - case META_COND_NUMBER: - case META_COND_RNAME: - case META_COND_RNUMBER: - pptr += 1 + SIZEOFFSET; - nestlevel++; - break; - - case META_COND_VERSION: - pptr += 3; - nestlevel++; - break; - - case META_CALLOUT_STRING: - pptr += 3 + SIZEOFFSET; - break; - - case META_BIGVALUE: - case META_POSIX: - case META_POSIX_NEG: - case META_CAPTURE_NAME: - case META_CAPTURE_NUMBER: - pptr += 1; - break; - - case META_MINMAX: - case META_MINMAX_QUERY: - case META_MINMAX_PLUS: - case META_OPTIONS: - pptr += 2; - break; - - case META_CALLOUT_NUMBER: - pptr += 3; - break; - - case META_MARK: - case META_COMMIT_ARG: - case META_PRUNE_ARG: - case META_SKIP_ARG: - case META_THEN_ARG: - pptr += 1 + pptr[1]; - break; - - /* Note that set_lookbehind_lengths() updates pptr, leaving it pointing to - the final ket of the group, so no need to update it here. */ - - case META_LOOKBEHIND: - case META_LOOKBEHINDNOT: - case META_LOOKBEHIND_NA: - if (!set_lookbehind_lengths(&pptr, &errorcode, lcptr, recurses, cb)) - return errorcode; - break; - } - } - -return 0; -} - - - -/************************************************* -* External function to compile a pattern * -*************************************************/ - -/* This function reads a regular expression in the form of a string and returns -a pointer to a block of store holding a compiled version of the expression. - -Arguments: - pattern the regular expression - patlen the length of the pattern, or PCRE2_ZERO_TERMINATED - options option bits - errorptr pointer to errorcode - erroroffset pointer to error offset - ccontext points to a compile context or is NULL - -Returns: pointer to compiled data block, or NULL on error, - with errorcode and erroroffset set -*/ - -PCRE2_EXP_DEFN pcre2_code * PCRE2_CALL_CONVENTION -pcre2_compile(PCRE2_SPTR pattern, PCRE2_SIZE patlen, uint32_t options, - int *errorptr, PCRE2_SIZE *erroroffset, pcre2_compile_context *ccontext) -{ -BOOL utf; /* Set TRUE for UTF mode */ -BOOL ucp; /* Set TRUE for UCP mode */ -BOOL has_lookbehind = FALSE; /* Set TRUE if a lookbehind is found */ -BOOL zero_terminated; /* Set TRUE for zero-terminated pattern */ -pcre2_real_code *re = NULL; /* What we will return */ -compile_block cb; /* "Static" compile-time data */ -const uint8_t *tables; /* Char tables base pointer */ - -PCRE2_UCHAR null_str[1] = { 0xcd }; /* Dummy for handling null inputs */ -PCRE2_UCHAR *code; /* Current pointer in compiled code */ -PCRE2_UCHAR *codestart; /* Start of compiled code */ -PCRE2_SPTR ptr; /* Current pointer in pattern */ -uint32_t *pptr; /* Current pointer in parsed pattern */ - -PCRE2_SIZE length = 1; /* Allow for final END opcode */ -PCRE2_SIZE usedlength; /* Actual length used */ -PCRE2_SIZE re_blocksize; /* Size of memory block */ -PCRE2_SIZE parsed_size_needed; /* Needed for parsed pattern */ - -uint32_t firstcuflags, reqcuflags; /* Type of first/req code unit */ -uint32_t firstcu, reqcu; /* Value of first/req code unit */ -uint32_t setflags = 0; /* NL and BSR set flags */ -uint32_t xoptions; /* Flags from context, modified */ - -uint32_t skipatstart; /* When checking (*UTF) etc */ -uint32_t limit_heap = UINT32_MAX; -uint32_t limit_match = UINT32_MAX; /* Unset match limits */ -uint32_t limit_depth = UINT32_MAX; - -int newline = 0; /* Unset; can be set by the pattern */ -int bsr = 0; /* Unset; can be set by the pattern */ -int errorcode = 0; /* Initialize to avoid compiler warn */ -int regexrc; /* Return from compile */ - -uint32_t i; /* Local loop counter */ - -/* Enable all optimizations by default. */ -uint32_t optim_flags = ccontext != NULL ? ccontext->optimization_flags : - PCRE2_OPTIMIZATION_ALL; - -/* Comments at the head of this file explain about these variables. */ - -uint32_t stack_groupinfo[GROUPINFO_DEFAULT_SIZE]; -uint32_t stack_parsed_pattern[PARSED_PATTERN_DEFAULT_SIZE]; -named_group named_groups[NAMED_GROUP_LIST_SIZE]; - -/* The workspace is used in different ways in the different compiling phases. -It needs to be 16-bit aligned for the preliminary parsing scan. */ - -uint32_t c16workspace[C16_WORK_SIZE]; -PCRE2_UCHAR *cworkspace = (PCRE2_UCHAR *)c16workspace; - - -/* -------------- Check arguments and set up the pattern ----------------- */ - -/* There must be error code and offset pointers. */ - -if (errorptr == NULL) - { - if (erroroffset != NULL) *erroroffset = 0; - return NULL; - } -if (erroroffset == NULL) - { - if (errorptr != NULL) *errorptr = ERR120; - return NULL; - } -*errorptr = ERR0; -*erroroffset = 0; - -/* There must be a pattern, but NULL is allowed with zero length. */ - -if (pattern == NULL) - { - if (patlen == 0) - pattern = null_str; - else - { - *errorptr = ERR16; - return NULL; - } - } - -/* A NULL compile context means "use a default context" */ - -if (ccontext == NULL) - ccontext = (pcre2_compile_context *)(&PRIV(default_compile_context)); - -/* PCRE2_MATCH_INVALID_UTF implies UTF */ - -if ((options & PCRE2_MATCH_INVALID_UTF) != 0) options |= PCRE2_UTF; - -/* Check that all undefined public option bits are zero. */ - -if ((options & ~PUBLIC_COMPILE_OPTIONS) != 0 || - (ccontext->extra_options & ~PUBLIC_COMPILE_EXTRA_OPTIONS) != 0) - { - *errorptr = ERR17; - return NULL; - } - -if ((options & PCRE2_LITERAL) != 0 && - ((options & ~PUBLIC_LITERAL_COMPILE_OPTIONS) != 0 || - (ccontext->extra_options & ~PUBLIC_LITERAL_COMPILE_EXTRA_OPTIONS) != 0)) - { - *errorptr = ERR92; - return NULL; - } - -/* A zero-terminated pattern is indicated by the special length value -PCRE2_ZERO_TERMINATED. Check for an overlong pattern. */ - -if ((zero_terminated = (patlen == PCRE2_ZERO_TERMINATED))) - patlen = PRIV(strlen)(pattern); -(void)zero_terminated; /* Silence compiler; only used if Valgrind enabled */ - -if (patlen > ccontext->max_pattern_length) - { - *errorptr = ERR88; - return NULL; - } - -/* Optimization flags in 'options' can override those in the compile context. -This is because some options to disable optimizations were added before the -optimization flags word existed, and we need to continue supporting them -for backwards compatibility. */ - -if ((options & PCRE2_NO_AUTO_POSSESS) != 0) - optim_flags &= ~PCRE2_OPTIM_AUTO_POSSESS; -if ((options & PCRE2_NO_DOTSTAR_ANCHOR) != 0) - optim_flags &= ~PCRE2_OPTIM_DOTSTAR_ANCHOR; -if ((options & PCRE2_NO_START_OPTIMIZE) != 0) - optim_flags &= ~PCRE2_OPTIM_START_OPTIMIZE; - -/* From here on, all returns from this function should end up going via the -EXIT label. */ - - -/* ------------ Initialize the "static" compile data -------------- */ - -tables = (ccontext->tables != NULL)? ccontext->tables : PRIV(default_tables); - -cb.lcc = tables + lcc_offset; /* Individual */ -cb.fcc = tables + fcc_offset; /* character */ -cb.cbits = tables + cbits_offset; /* tables */ -cb.ctypes = tables + ctypes_offset; - -cb.assert_depth = 0; -cb.bracount = 0; -cb.cx = ccontext; -cb.dupnames = FALSE; -cb.end_pattern = pattern + patlen; -cb.erroroffset = 0; -cb.external_flags = 0; -cb.external_options = options; -cb.groupinfo = stack_groupinfo; -cb.had_recurse = FALSE; -cb.lastcapture = 0; -cb.max_lookbehind = 0; /* Max encountered */ -cb.max_varlookbehind = ccontext->max_varlookbehind; /* Limit */ -cb.name_entry_size = 0; -cb.name_table = NULL; -cb.named_groups = named_groups; -cb.named_group_list_size = NAMED_GROUP_LIST_SIZE; -cb.names_found = 0; -cb.parens_depth = 0; -cb.parsed_pattern = stack_parsed_pattern; -cb.req_varyopt = 0; -cb.start_code = cworkspace; -cb.start_pattern = pattern; -cb.start_workspace = cworkspace; -cb.workspace_size = COMPILE_WORK_SIZE; -cb.first_data = NULL; -cb.last_data = NULL; -#ifdef SUPPORT_WIDE_CHARS -cb.char_lists_size = 0; -#endif - -/* Maximum back reference and backref bitmap. The bitmap records up to 31 back -references to help in deciding whether (.*) can be treated as anchored or not. -*/ - -cb.top_backref = 0; -cb.backref_map = 0; - -/* Escape sequences \1 to \9 are always back references, but as they are only -two characters long, only two elements can be used in the parsed_pattern -vector. The first contains the reference, and we'd like to use the second to -record the offset in the pattern, so that forward references to non-existent -groups can be diagnosed later with an offset. However, on 64-bit systems, -PCRE2_SIZE won't fit. Instead, we have a vector of offsets for the first -occurrence of \1 to \9, indexed by the second parsed_pattern value. All other -references have enough space for the offset to be put into the parsed pattern. -*/ - -for (i = 0; i < 10; i++) cb.small_ref_offset[i] = PCRE2_UNSET; - - -/* --------------- Start looking at the pattern --------------- */ - -/* Unless PCRE2_LITERAL is set, check for global one-time option settings at -the start of the pattern, and remember the offset to the actual regex. With -valgrind support, make the terminator of a zero-terminated pattern -inaccessible. This catches bugs that would otherwise only show up for -non-zero-terminated patterns. */ - -#ifdef SUPPORT_VALGRIND -if (zero_terminated) VALGRIND_MAKE_MEM_NOACCESS(pattern + patlen, CU2BYTES(1)); -#endif - -xoptions = ccontext->extra_options; -ptr = pattern; -skipatstart = 0; - -if ((options & PCRE2_LITERAL) == 0) - { - while (patlen - skipatstart >= 2 && - ptr[skipatstart] == CHAR_LEFT_PARENTHESIS && - ptr[skipatstart+1] == CHAR_ASTERISK) - { - for (i = 0; i < sizeof(pso_list)/sizeof(pso); i++) - { - const pso *p = pso_list + i; - - if (patlen - skipatstart - 2 >= p->length && - PRIV(strncmp_c8)(ptr + skipatstart + 2, p->name, p->length) == 0) - { - uint32_t c, pp; - - skipatstart += p->length + 2; - switch(p->type) - { - case PSO_OPT: - cb.external_options |= p->value; - break; - - case PSO_XOPT: - xoptions |= p->value; - break; - - case PSO_FLG: - setflags |= p->value; - break; - - case PSO_NL: - newline = p->value; - setflags |= PCRE2_NL_SET; - break; - - case PSO_BSR: - bsr = p->value; - setflags |= PCRE2_BSR_SET; - break; - - case PSO_LIMM: - case PSO_LIMD: - case PSO_LIMH: - c = 0; - pp = skipatstart; - while (pp < patlen && IS_DIGIT(ptr[pp])) - { - if (c > UINT32_MAX / 10 - 1) break; /* Integer overflow */ - c = c*10 + (ptr[pp++] - CHAR_0); - } - if (pp >= patlen || pp == skipatstart || ptr[pp] != CHAR_RIGHT_PARENTHESIS) - { - errorcode = ERR60; - ptr += pp; - utf = FALSE; /* Used by HAD_EARLY_ERROR */ - goto HAD_EARLY_ERROR; - } - if (p->type == PSO_LIMH) limit_heap = c; - else if (p->type == PSO_LIMM) limit_match = c; - else limit_depth = c; - skipatstart = ++pp; - break; - - case PSO_OPTMZ: - optim_flags &= ~(p->value); - - /* For backward compatibility the three original VERBs to disable - optimizations need to also update the corresponding bit in the - external options. */ - - switch(p->value) - { - case PCRE2_OPTIM_AUTO_POSSESS: - cb.external_options |= PCRE2_NO_AUTO_POSSESS; - break; - - case PCRE2_OPTIM_DOTSTAR_ANCHOR: - cb.external_options |= PCRE2_NO_DOTSTAR_ANCHOR; - break; - - case PCRE2_OPTIM_START_OPTIMIZE: - cb.external_options |= PCRE2_NO_START_OPTIMIZE; - break; - } - - break; - - /* LCOV_EXCL_START */ - default: - /* All values in the enum need an explicit entry for this switch - but until a better way to prevent coding mistakes is invented keep - a catch all that triggers a debug build assert as a failsafe */ - PCRE2_DEBUG_UNREACHABLE(); - /* LCOV_EXCL_STOP */ - } - break; /* Out of the table scan loop */ - } - } - if (i >= sizeof(pso_list)/sizeof(pso)) break; /* Out of pso loop */ - } - PCRE2_ASSERT(skipatstart <= patlen); - } - -/* End of pattern-start options; advance to start of real regex. */ - -ptr += skipatstart; - -/* Can't support UTF or UCP if PCRE2 was built without Unicode support. */ - -#ifndef SUPPORT_UNICODE -if ((cb.external_options & (PCRE2_UTF|PCRE2_UCP)) != 0) - { - errorcode = ERR32; - goto HAD_EARLY_ERROR; - } -#endif - -/* Check UTF. We have the original options in 'options', with that value as -modified by (*UTF) etc in cb->external_options. The extra option -PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is not permitted in UTF-16 mode because the -surrogate code points cannot be represented in UTF-16. */ - -utf = (cb.external_options & PCRE2_UTF) != 0; -if (utf) - { - if ((options & PCRE2_NEVER_UTF) != 0) - { - errorcode = ERR74; - goto HAD_EARLY_ERROR; - } - if ((options & PCRE2_NO_UTF_CHECK) == 0 && - (errorcode = PRIV(valid_utf)(pattern, patlen, erroroffset)) != 0) - goto HAD_ERROR; /* Offset was set by valid_utf() */ - -#if PCRE2_CODE_UNIT_WIDTH == 16 - if ((ccontext->extra_options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) != 0) - { - errorcode = ERR91; - goto HAD_EARLY_ERROR; - } -#endif - } - -/* Check UCP lockout. */ - -ucp = (cb.external_options & PCRE2_UCP) != 0; -if (ucp && (cb.external_options & PCRE2_NEVER_UCP) != 0) - { - errorcode = ERR75; - goto HAD_EARLY_ERROR; - } - -/* PCRE2_EXTRA_TURKISH_CASING checks */ - -if ((xoptions & PCRE2_EXTRA_TURKISH_CASING) != 0) - { - if (!utf && !ucp) - { - errorcode = ERR104; - goto HAD_EARLY_ERROR; - } - -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (!utf) - { - errorcode = ERR105; - goto HAD_EARLY_ERROR; - } -#endif - - if ((xoptions & PCRE2_EXTRA_CASELESS_RESTRICT) != 0) - { - errorcode = ERR106; - goto HAD_EARLY_ERROR; - } - } - -/* Process the BSR setting. */ - -if (bsr == 0) bsr = ccontext->bsr_convention; - -/* Process the newline setting. */ - -if (newline == 0) newline = ccontext->newline_convention; -cb.nltype = NLTYPE_FIXED; -switch(newline) - { - case PCRE2_NEWLINE_CR: - cb.nllen = 1; - cb.nl[0] = CHAR_CR; - break; - - case PCRE2_NEWLINE_LF: - cb.nllen = 1; - cb.nl[0] = CHAR_NL; - break; - - case PCRE2_NEWLINE_NUL: - cb.nllen = 1; - cb.nl[0] = CHAR_NUL; - break; - - case PCRE2_NEWLINE_CRLF: - cb.nllen = 2; - cb.nl[0] = CHAR_CR; - cb.nl[1] = CHAR_NL; - break; - - case PCRE2_NEWLINE_ANY: - cb.nltype = NLTYPE_ANY; - break; - - case PCRE2_NEWLINE_ANYCRLF: - cb.nltype = NLTYPE_ANYCRLF; - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR56; - goto HAD_EARLY_ERROR; - /* LCOV_EXCL_STOP */ - } - -/* Pre-scan the pattern to do two things: (1) Discover the named groups and -their numerical equivalents, so that this information is always available for -the remaining processing. (2) At the same time, parse the pattern and put a -processed version into the parsed_pattern vector. This has escapes interpreted -and comments removed (amongst other things). */ - -/* Ensure that the parsed pattern buffer is big enough. For many smaller -patterns the vector on the stack (which was set up above) can be used. */ - -parsed_size_needed = max_parsed_pattern(ptr, cb.end_pattern, utf, options); - -/* Allow for 2x uint32_t at the start and 2 at the end, for -PCRE2_EXTRA_MATCH_WORD or PCRE2_EXTRA_MATCH_LINE (which are exclusive). */ - -if ((ccontext->extra_options & - (PCRE2_EXTRA_MATCH_WORD|PCRE2_EXTRA_MATCH_LINE)) != 0) - parsed_size_needed += 4; - -/* When PCRE2_AUTO_CALLOUT is set we allow for one callout at the end. */ - -if ((options & PCRE2_AUTO_CALLOUT) != 0) - parsed_size_needed += 4; - -parsed_size_needed += 1; /* For the final META_END */ - -if (parsed_size_needed > PARSED_PATTERN_DEFAULT_SIZE) - { - uint32_t *heap_parsed_pattern = ccontext->memctl.malloc( - parsed_size_needed * sizeof(uint32_t), ccontext->memctl.memory_data); - if (heap_parsed_pattern == NULL) - { - *errorptr = ERR21; - goto EXIT; - } - cb.parsed_pattern = heap_parsed_pattern; - } -cb.parsed_pattern_end = cb.parsed_pattern + parsed_size_needed; - -/* Do the parsing scan. */ - -errorcode = parse_regex(ptr, cb.external_options, xoptions, &has_lookbehind, &cb); -if (errorcode != 0) goto HAD_CB_ERROR; - -/* If there are any lookbehinds, scan the parsed pattern to figure out their -lengths. Workspace is needed to remember whether numbered groups are or are not -of limited length, and if limited, what the minimum and maximum lengths are. -This caching saves re-computing the length of any group that is referenced more -than once, which is particularly relevant when recursion is involved. -Unnumbered groups do not have this exposure because they cannot be referenced. -If there are sufficiently few groups, the default index vector on the stack, as -set up above, can be used. Otherwise we have to get/free some heap memory. The -vector must be initialized to zero. */ - -if (has_lookbehind) - { - int loopcount = 0; - if (cb.bracount >= GROUPINFO_DEFAULT_SIZE/2) - { - cb.groupinfo = ccontext->memctl.malloc( - (2 * (cb.bracount + 1))*sizeof(uint32_t), ccontext->memctl.memory_data); - if (cb.groupinfo == NULL) - { - errorcode = ERR21; - cb.erroroffset = 0; - goto HAD_CB_ERROR; - } - } - memset(cb.groupinfo, 0, (2 * cb.bracount + 1) * sizeof(uint32_t)); - errorcode = check_lookbehinds(cb.parsed_pattern, NULL, NULL, &cb, &loopcount); - if (errorcode != 0) goto HAD_CB_ERROR; - } - -/* For debugging, there is a function that shows the parsed pattern vector. */ - -#ifdef DEBUG_SHOW_PARSED -fprintf(stderr, "+++ Pre-scan complete:\n"); -show_parsed(&cb); -#endif - -/* For debugging capturing information this code can be enabled. */ - -#ifdef DEBUG_SHOW_CAPTURES - { - named_group *ng = cb.named_groups; - fprintf(stderr, "+++Captures: %d\n", cb.bracount); - for (i = 0; i < cb.names_found; i++, ng++) - { - fprintf(stderr, "+++%3d %.*s\n", ng->number, ng->length, ng->name); - } - } -#endif - -/* Pretend to compile the pattern while actually just accumulating the amount -of memory required in the 'length' variable. This behaviour is triggered by -passing a non-NULL final argument to compile_regex(). We pass a block of -workspace (cworkspace) for it to compile parts of the pattern into; the -compiled code is discarded when it is no longer needed, so hopefully this -workspace will never overflow, though there is a test for its doing so. - -On error, errorcode will be set non-zero, so we don't need to look at the -result of the function. The initial options have been put into the cb block, -but we still have to pass a separate options variable (the first argument) -because the options may change as the pattern is processed. */ - -cb.erroroffset = patlen; /* For any subsequent errors that do not set it */ -pptr = cb.parsed_pattern; -code = cworkspace; -*code = OP_BRA; - -(void)compile_regex(cb.external_options, xoptions, &code, &pptr, - &errorcode, 0, &firstcu, &firstcuflags, &reqcu, &reqcuflags, NULL, NULL, - &cb, &length); - -if (errorcode != 0) goto HAD_CB_ERROR; /* Offset is in cb.erroroffset */ - -/* This should be caught in compile_regex(), but just in case... */ - -#if defined SUPPORT_WIDE_CHARS -PCRE2_ASSERT((cb.char_lists_size & 0x3) == 0); -if (length > MAX_PATTERN_SIZE || - MAX_PATTERN_SIZE - length < (cb.char_lists_size / sizeof(PCRE2_UCHAR))) -#else -if (length > MAX_PATTERN_SIZE) -#endif - { - errorcode = ERR20; - cb.erroroffset = 0; - goto HAD_CB_ERROR; - } - -/* Compute the size of, then, if not too large, get and initialize the data -block for storing the compiled pattern and names table. Integer overflow should -no longer be possible because nowadays we limit the maximum value of -cb.names_found and cb.name_entry_size. */ - -re_blocksize = - CU2BYTES((PCRE2_SIZE)cb.names_found * (PCRE2_SIZE)cb.name_entry_size); - -#if defined SUPPORT_WIDE_CHARS -if (cb.char_lists_size != 0) - { -#if PCRE2_CODE_UNIT_WIDTH != 32 - /* Align to 32 bit first. This ensures the - allocated area will also be 32 bit aligned. */ - re_blocksize = (PCRE2_SIZE)CLIST_ALIGN_TO(re_blocksize, sizeof(uint32_t)); -#endif - re_blocksize += cb.char_lists_size; - } -#endif - -re_blocksize += CU2BYTES(length); - -if (re_blocksize > ccontext->max_pattern_compiled_length) - { - errorcode = ERR101; - cb.erroroffset = 0; - goto HAD_CB_ERROR; - } - -re_blocksize += sizeof(pcre2_real_code); -re = (pcre2_real_code *) - ccontext->memctl.malloc(re_blocksize, ccontext->memctl.memory_data); -if (re == NULL) - { - errorcode = ERR21; - cb.erroroffset = 0; - goto HAD_CB_ERROR; - } - -/* The compiler may put padding at the end of the pcre2_real_code structure in -order to round it up to a multiple of 4 or 8 bytes. This means that when a -compiled pattern is copied (for example, when serialized) undefined bytes are -read, and this annoys debuggers such as valgrind. To avoid this, we explicitly -write to the last 8 bytes of the structure before setting the fields. */ - -memset((char *)re + sizeof(pcre2_real_code) - 8, 0, 8); -re->memctl = ccontext->memctl; -re->tables = tables; -re->executable_jit = NULL; -memset(re->start_bitmap, 0, 32 * sizeof(uint8_t)); -re->blocksize = re_blocksize; -re->code_start = re_blocksize - CU2BYTES(length); -re->magic_number = MAGIC_NUMBER; -re->compile_options = options; -re->overall_options = cb.external_options; -re->extra_options = xoptions; -re->flags = PCRE2_CODE_UNIT_WIDTH/8 | cb.external_flags | setflags; -re->limit_heap = limit_heap; -re->limit_match = limit_match; -re->limit_depth = limit_depth; -re->first_codeunit = 0; -re->last_codeunit = 0; -re->bsr_convention = bsr; -re->newline_convention = newline; -re->max_lookbehind = 0; -re->minlength = 0; -re->top_bracket = 0; -re->top_backref = 0; -re->name_entry_size = cb.name_entry_size; -re->name_count = cb.names_found; -re->optimization_flags = optim_flags; - -/* The basic block is immediately followed by the name table, and the compiled -code follows after that. */ - -codestart = (PCRE2_UCHAR *)((uint8_t *)re + re->code_start); - -/* Update the compile data block for the actual compile. The starting points of -the name/number translation table and of the code are passed around in the -compile data block. The start/end pattern and initial options are already set -from the pre-compile phase, as is the name_entry_size field. */ - -cb.parens_depth = 0; -cb.assert_depth = 0; -cb.lastcapture = 0; -cb.name_table = (PCRE2_UCHAR *)((uint8_t *)re + sizeof(pcre2_real_code)); -cb.start_code = codestart; -cb.req_varyopt = 0; -cb.had_accept = FALSE; -cb.had_pruneorskip = FALSE; -#ifdef SUPPORT_WIDE_CHARS -cb.char_lists_size = 0; -#endif - - -/* If any named groups were found, create the name/number table from the list -created in the pre-pass. */ - -if (cb.names_found > 0) - { - named_group *ng = cb.named_groups; - uint32_t tablecount = 0; - - /* Length 0 represents duplicates, and they have already been handled. */ - for (i = 0; i < cb.names_found; i++, ng++) - if (ng->length > 0) - tablecount = PRIV(compile_add_name_to_table)(&cb, ng, tablecount); - - PCRE2_ASSERT(tablecount == cb.names_found); - } - -/* Set up a starting, non-extracting bracket, then compile the expression. On -error, errorcode will be set non-zero, so we don't need to look at the result -of the function here. */ - -pptr = cb.parsed_pattern; -code = (PCRE2_UCHAR *)codestart; -*code = OP_BRA; -regexrc = compile_regex(re->overall_options, re->extra_options, &code, - &pptr, &errorcode, 0, &firstcu, &firstcuflags, &reqcu, &reqcuflags, NULL, - NULL, &cb, NULL); -if (regexrc < 0) re->flags |= PCRE2_MATCH_EMPTY; -re->top_bracket = cb.bracount; -re->top_backref = cb.top_backref; -re->max_lookbehind = cb.max_lookbehind; - -if (cb.had_accept) - { - reqcu = 0; /* Must disable after (*ACCEPT) */ - reqcuflags = REQ_NONE; - re->flags |= PCRE2_HASACCEPT; /* Disables minimum length */ - } - -/* Fill in the final opcode and check for disastrous overflow. If no overflow, -but the estimated length exceeds the really used length, adjust the value of -re->blocksize, and if valgrind support is configured, mark the extra allocated -memory as unaddressable, so that any out-of-bound reads can be detected. */ - -*code++ = OP_END; -usedlength = code - codestart; -/* LCOV_EXCL_START */ -if (usedlength > length) - { - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR23; /* Overflow of code block - internal error */ - cb.erroroffset = 0; - goto HAD_CB_ERROR; - } -/* LCOV_EXCL_STOP */ - -re->blocksize -= CU2BYTES(length - usedlength); -#ifdef SUPPORT_VALGRIND -VALGRIND_MAKE_MEM_NOACCESS(code, CU2BYTES(length - usedlength)); -#endif - -/* Scan the pattern for recursion/subroutine calls and convert the group -numbers into offsets. Maintain a small cache so that repeated groups containing -recursions are efficiently handled. */ - -#define RSCAN_CACHE_SIZE 8 - -if (errorcode == 0 && cb.had_recurse) - { - PCRE2_UCHAR *rcode; - PCRE2_SPTR rgroup; - unsigned int ccount = 0; - int start = RSCAN_CACHE_SIZE; - recurse_cache rc[RSCAN_CACHE_SIZE]; - - for (rcode = find_recurse(codestart, utf); - rcode != NULL; - rcode = find_recurse(rcode + 1 + LINK_SIZE, utf)) - { - int p, groupnumber; - - groupnumber = (int)GET(rcode, 1); - if (groupnumber == 0) rgroup = codestart; else - { - PCRE2_SPTR search_from = codestart; - rgroup = NULL; - for (i = 0, p = start; i < ccount; i++, p = (p + 1) & 7) - { - if (groupnumber == rc[p].groupnumber) - { - rgroup = rc[p].group; - break; - } - - /* Group n+1 must always start to the right of group n, so we can save - search time below when the new group number is greater than any of the - previously found groups. */ - - if (groupnumber > rc[p].groupnumber) search_from = rc[p].group; - } - - if (rgroup == NULL) - { - rgroup = PRIV(find_bracket)(search_from, utf, groupnumber); - /* LCOV_EXCL_START */ - if (rgroup == NULL) - { - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR53; - break; - } - /* LCOV_EXCL_STOP */ - - if (--start < 0) start = RSCAN_CACHE_SIZE - 1; - rc[start].groupnumber = groupnumber; - rc[start].group = rgroup; - if (ccount < RSCAN_CACHE_SIZE) ccount++; - } - } - - PUT(rcode, 1, (uint32_t)(rgroup - codestart)); - } - } - -/* In rare debugging situations we sometimes need to look at the compiled code -at this stage. */ - -#ifdef DEBUG_CALL_PRINTINT -pcre2_printint(re, stderr, TRUE); -fprintf(stderr, "Length=%lu Used=%lu\n", length, usedlength); -#endif - -/* Unless disabled, check whether any single character iterators can be -auto-possessified. The function overwrites the appropriate opcode values, so -the type of the pointer must be cast. NOTE: the intermediate variable "temp" is -used in this code because at least one compiler gives a warning about loss of -"const" attribute if the cast (PCRE2_UCHAR *)codestart is used directly in the -function call. */ - -if (errorcode == 0 && (optim_flags & PCRE2_OPTIM_AUTO_POSSESS) != 0) - { - PCRE2_UCHAR *temp = (PCRE2_UCHAR *)codestart; - int possessify_rc = PRIV(auto_possessify)(temp, &cb); - /* LCOV_EXCL_START */ - if (possessify_rc != 0) - { - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR80; - cb.erroroffset = 0; - } - /* LCOV_EXCL_STOP */ - } - -/* Failed to compile, or error while post-processing. */ - -if (errorcode != 0) goto HAD_CB_ERROR; - -/* Successful compile. If the anchored option was not passed, set it if -we can determine that the pattern is anchored by virtue of ^ characters or \A -or anything else, such as starting with non-atomic .* when DOTALL is set and -there are no occurrences of *PRUNE or *SKIP (though there is an option to -disable this case). */ - -if ((re->overall_options & PCRE2_ANCHORED) == 0) - { - BOOL dotstar_anchor = ((optim_flags & PCRE2_OPTIM_DOTSTAR_ANCHOR) != 0); - if (is_anchored(codestart, 0, &cb, 0, FALSE, dotstar_anchor)) - re->overall_options |= PCRE2_ANCHORED; - } - -/* Set up the first code unit or startline flag, the required code unit, and -then study the pattern. This code need not be obeyed if PCRE2_OPTIM_START_OPTIMIZE -is disabled, as the data it would create will not be used. Note that a first code -unit (but not the startline flag) is useful for anchored patterns because it -can still give a quick "no match" and also avoid searching for a last code -unit. */ - -if ((optim_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) - { - int minminlength = 0; /* For minimal minlength from first/required CU */ - int study_rc; - - /* If we do not have a first code unit, see if there is one that is asserted - (these are not saved during the compile because they can cause conflicts with - actual literals that follow). */ - - if (firstcuflags >= REQ_NONE) { - uint32_t assertedcuflags = 0; - uint32_t assertedcu = find_firstassertedcu(codestart, &assertedcuflags, 0); - /* It would be wrong to use the asserted first code unit as `firstcu` for - * regexes which are able to match a 1-character string (e.g. /(?=a)b?a/) - * For that example, if we set both firstcu and reqcu to 'a', it would mean - * the subject string needs to be at least 2 characters long, which is wrong. - * With more analysis, we would be able to set firstcu in more cases. */ - if (assertedcuflags < REQ_NONE && assertedcu != reqcu) { - firstcu = assertedcu; - firstcuflags = assertedcuflags; - } - } - - /* Save the data for a first code unit. The existence of one means the - minimum length must be at least 1. */ - - if (firstcuflags < REQ_NONE) - { - re->first_codeunit = firstcu; - re->flags |= PCRE2_FIRSTSET; - minminlength++; - - /* Handle caseless first code units. */ - - if ((firstcuflags & REQ_CASELESS) != 0) - { - if (firstcu < 128 || (!utf && !ucp && firstcu < 255)) - { - if (cb.fcc[firstcu] != firstcu) re->flags |= PCRE2_FIRSTCASELESS; - } - - /* The first code unit is > 128 in UTF or UCP mode, or > 255 otherwise. - In 8-bit UTF mode, code units in the range 128-255 are introductory code - units and cannot have another case, but if UCP is set they may do. */ - -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 - else if (ucp && !utf && UCD_OTHERCASE(firstcu) != firstcu) - re->flags |= PCRE2_FIRSTCASELESS; -#else - else if ((utf || ucp) && firstcu <= MAX_UTF_CODE_POINT && - UCD_OTHERCASE(firstcu) != firstcu) - re->flags |= PCRE2_FIRSTCASELESS; -#endif -#endif /* SUPPORT_UNICODE */ - } - } - - /* When there is no first code unit, for non-anchored patterns, see if we can - set the PCRE2_STARTLINE flag. This is helpful for multiline matches when all - branches start with ^ and also when all branches start with non-atomic .* for - non-DOTALL matches when *PRUNE and SKIP are not present. (There is an option - that disables this case.) */ - - else if ((re->overall_options & PCRE2_ANCHORED) == 0) - { - BOOL dotstar_anchor = ((optim_flags & PCRE2_OPTIM_DOTSTAR_ANCHOR) != 0); - if (is_startline(codestart, 0, &cb, 0, FALSE, dotstar_anchor)) - re->flags |= PCRE2_STARTLINE; - } - - /* Handle the "required code unit", if one is set. In the UTF case we can - increment the minimum minimum length only if we are sure this really is a - different character and not a non-starting code unit of the first character, - because the minimum length count is in characters, not code units. */ - - if (reqcuflags < REQ_NONE) - { -#if PCRE2_CODE_UNIT_WIDTH == 16 - if ((re->overall_options & PCRE2_UTF) == 0 || /* Not UTF */ - firstcuflags >= REQ_NONE || /* First not set */ - (firstcu & 0xf800) != 0xd800 || /* First not surrogate */ - (reqcu & 0xfc00) != 0xdc00) /* Req not low surrogate */ -#elif PCRE2_CODE_UNIT_WIDTH == 8 - if ((re->overall_options & PCRE2_UTF) == 0 || /* Not UTF */ - firstcuflags >= REQ_NONE || /* First not set */ - (firstcu & 0x80) == 0 || /* First is ASCII */ - (reqcu & 0x80) == 0) /* Req is ASCII */ -#endif - { - minminlength++; - } - - /* In the case of an anchored pattern, set up the value only if it follows - a variable length item in the pattern. */ - - if ((re->overall_options & PCRE2_ANCHORED) == 0 || - (reqcuflags & REQ_VARY) != 0) - { - re->last_codeunit = reqcu; - re->flags |= PCRE2_LASTSET; - - /* Handle caseless required code units as for first code units (above). */ - - if ((reqcuflags & REQ_CASELESS) != 0) - { - if (reqcu < 128 || (!utf && !ucp && reqcu < 255)) - { - if (cb.fcc[reqcu] != reqcu) re->flags |= PCRE2_LASTCASELESS; - } -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 - else if (ucp && !utf && UCD_OTHERCASE(reqcu) != reqcu) - re->flags |= PCRE2_LASTCASELESS; -#else - else if ((utf || ucp) && reqcu <= MAX_UTF_CODE_POINT && - UCD_OTHERCASE(reqcu) != reqcu) - re->flags |= PCRE2_LASTCASELESS; -#endif -#endif /* SUPPORT_UNICODE */ - } - } - } - - /* Study the compiled pattern to set up information such as a bitmap of - starting code units and a minimum matching length. */ - - study_rc = PRIV(study)(re); - /* LCOV_EXCL_START */ - if (study_rc != 0) - { - PCRE2_DEBUG_UNREACHABLE(); - errorcode = ERR31; - cb.erroroffset = 0; - goto HAD_CB_ERROR; - } - /* LCOV_EXCL_STOP */ - - /* If study() set a bitmap of starting code units, it implies a minimum - length of at least one. */ - - if ((re->flags & PCRE2_FIRSTMAPSET) != 0 && minminlength == 0) - minminlength = 1; - - /* If the minimum length set (or not set) by study() is less than the minimum - implied by required code units, override it. */ - - if (re->minlength < minminlength) re->minlength = minminlength; - } /* End of start-of-match optimizations. */ - -/* Control ends up here in all cases. When running under valgrind, make a -pattern's terminating zero defined again. If memory was obtained for the parsed -version of the pattern, free it before returning. Also free the list of named -groups if a larger one had to be obtained, and likewise the group information -vector. */ - -#ifdef SUPPORT_UNICODE -/* All items must be freed. */ -PCRE2_ASSERT(cb.first_data == NULL); -#endif - -EXIT: -#ifdef SUPPORT_VALGRIND -if (zero_terminated) VALGRIND_MAKE_MEM_DEFINED(pattern + patlen, CU2BYTES(1)); -#endif -if (cb.parsed_pattern != stack_parsed_pattern) - ccontext->memctl.free(cb.parsed_pattern, ccontext->memctl.memory_data); -if (cb.named_group_list_size > NAMED_GROUP_LIST_SIZE) - ccontext->memctl.free((void *)cb.named_groups, ccontext->memctl.memory_data); -if (cb.groupinfo != stack_groupinfo) - ccontext->memctl.free((void *)cb.groupinfo, ccontext->memctl.memory_data); - -return re; /* Will be NULL after an error */ - -/* Errors discovered in parse_regex() set the offset value in the compile -block. Errors discovered before it is called must compute it from the ptr -value. After parse_regex() is called, the offset in the compile block is set to -the end of the pattern, but certain errors in compile_regex() may reset it if -an offset is available in the parsed pattern. */ - -HAD_CB_ERROR: -ptr = pattern + cb.erroroffset; - -HAD_EARLY_ERROR: -/* Ensure we don't return out-of-range erroroffset. */ -PCRE2_ASSERT(ptr >= pattern); -PCRE2_ASSERT(ptr <= (pattern + patlen)); -/* Ensure that the erroroffset never slices a UTF-encoded character in half. -If the input is invalid, then we return an offset just before the first invalid -character, so the text to the left of the offset must always be valid. */ -#if defined PCRE2_DEBUG && defined SUPPORT_UNICODE -if (ptr > pattern && utf) - { - PCRE2_SPTR prev = ptr - 1; - PCRE2_SIZE dummyoffset; - BACKCHAR(prev); - PCRE2_ASSERT(prev >= pattern); - PCRE2_ASSERT(PRIV(valid_utf)(prev, ptr - prev, &dummyoffset) == 0); - } -#endif -*erroroffset = ptr - pattern; - -HAD_ERROR: -*errorptr = errorcode; -pcre2_code_free(re); -re = NULL; - -if (cb.first_data != NULL) - { - compile_data* current_data = cb.first_data; - do - { - compile_data* next_data = current_data->next; - cb.cx->memctl.free(current_data, cb.cx->memctl.memory_data); - current_data = next_data; - } - while (current_data != NULL); - } - -goto EXIT; -} - -/* These #undefs are here to enable unity builds with CMake. */ - -#undef NLBLOCK /* Block containing newline information */ -#undef PSSTART /* Field containing processed string start */ -#undef PSEND /* Field containing processed string end */ - -/* End of pcre2_compile.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile.h b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile.h deleted file mode 100644 index 331ca3a..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile.h +++ /dev/null @@ -1,356 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE2 is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - -#ifndef PCRE2_COMPILE_H_IDEMPOTENT_GUARD -#define PCRE2_COMPILE_H_IDEMPOTENT_GUARD - -#include "pcre2_internal.h" - -/* Compile time error code numbers. They are given names so that they can more -easily be tracked. When a new number is added, the tables called eint1 and -eint2 in pcre2posix.c may need to be updated, and a new error text must be -added to compile_error_texts in pcre2_error.c. Also, the error codes in -pcre2.h.in must be updated - their values are exactly 100 greater than these -values. */ - -enum { ERR0 = COMPILE_ERROR_BASE, - ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10, - ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20, - ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30, - ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40, - ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, ERR50, - ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, ERR60, - ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69, ERR70, - ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79, ERR80, - ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERR88, ERR89, ERR90, - ERR91, ERR92, ERR93, ERR94, ERR95, ERR96, ERR97, ERR98, ERR99, ERR100, - ERR101, ERR102, ERR103, ERR104, ERR105, ERR106, ERR107, ERR108, ERR109, ERR110, - ERR111, ERR112, ERR113, ERR114, ERR115, ERR116, ERR117, ERR118, ERR119, ERR120 }; - -/* Code values for parsed patterns, which are stored in a vector of 32-bit -unsigned ints. Values less than META_END are literal data values. The coding -for identifying the item is in the top 16-bits, leaving 16 bits for the -additional data that some of them need. The META_CODE, META_DATA, and META_DIFF -macros are used to manipulate parsed pattern elements. - -NOTE: When these definitions are changed, the table of extra lengths for each -code (meta_extra_lengths) must be updated to remain in step. */ - -#define META_END 0x80000000u /* End of pattern */ - -#define META_ALT 0x80010000u /* alternation */ -#define META_ATOMIC 0x80020000u /* atomic group */ -#define META_BACKREF 0x80030000u /* Back ref */ -#define META_BACKREF_BYNAME 0x80040000u /* \k'name' */ -#define META_BIGVALUE 0x80050000u /* Next is a literal > META_END */ -#define META_CALLOUT_NUMBER 0x80060000u /* (?C with numerical argument */ -#define META_CALLOUT_STRING 0x80070000u /* (?C with string argument */ -#define META_CAPTURE 0x80080000u /* Capturing parenthesis */ -#define META_CIRCUMFLEX 0x80090000u /* ^ metacharacter */ -#define META_CLASS 0x800a0000u /* start non-empty class */ -#define META_CLASS_EMPTY 0x800b0000u /* empty class */ -#define META_CLASS_EMPTY_NOT 0x800c0000u /* negative empty class */ -#define META_CLASS_END 0x800d0000u /* end of non-empty class */ -#define META_CLASS_NOT 0x800e0000u /* start non-empty negative class */ -#define META_COND_ASSERT 0x800f0000u /* (?(?assertion)... */ -#define META_COND_DEFINE 0x80100000u /* (?(DEFINE)... */ -#define META_COND_NAME 0x80110000u /* (?()... */ -#define META_COND_NUMBER 0x80120000u /* (?(digits)... */ -#define META_COND_RNAME 0x80130000u /* (?(R&name)... */ -#define META_COND_RNUMBER 0x80140000u /* (?(Rdigits)... */ -#define META_COND_VERSION 0x80150000u /* (?(VERSIONx.y)... */ -#define META_OFFSET 0x80160000u /* Setting offset for various META - codes (e.g. META_CAPTURE_NAME) */ -#define META_SCS 0x80170000u /* (*scan_substring:... */ -#define META_CAPTURE_NAME 0x80180000u /* Next in capture lists */ -#define META_CAPTURE_NUMBER 0x80190000u /* Next digits in capture lists */ -#define META_DOLLAR 0x801a0000u /* $ metacharacter */ -#define META_DOT 0x801b0000u /* . metacharacter */ -#define META_ESCAPE 0x801c0000u /* \d and friends */ -#define META_KET 0x801d0000u /* closing parenthesis */ -#define META_NOCAPTURE 0x801e0000u /* no capture parens */ -#define META_OPTIONS 0x801f0000u /* (?i) and friends */ -#define META_POSIX 0x80200000u /* POSIX class item */ -#define META_POSIX_NEG 0x80210000u /* negative POSIX class item */ -#define META_RANGE_ESCAPED 0x80220000u /* range with at least one escape */ -#define META_RANGE_LITERAL 0x80230000u /* range defined literally */ -#define META_RECURSE 0x80240000u /* Recursion */ -#define META_RECURSE_BYNAME 0x80250000u /* (?&name) */ -#define META_SCRIPT_RUN 0x80260000u /* (*script_run:...) */ - -/* These must be kept together to make it easy to check that an assertion -is present where expected in a conditional group. */ - -#define META_LOOKAHEAD 0x80270000u /* (?= */ -#define META_LOOKAHEADNOT 0x80280000u /* (?! */ -#define META_LOOKBEHIND 0x80290000u /* (?<= */ -#define META_LOOKBEHINDNOT 0x802a0000u /* (?>16) - -/* Macros to store and retrieve a PCRE2_SIZE value in the parsed pattern, which -consists of uint32_t elements. Assume that if uint32_t can't hold it, two of -them will be able to (i.e. assume a 64-bit world). */ - -#if PCRE2_SIZE_MAX <= UINT32_MAX -#define PUTOFFSET(s,p) *p++ = s -#define GETOFFSET(s,p) s = *p++ -#define GETPLUSOFFSET(s,p) s = *(++p) -#define READPLUSOFFSET(s,p) s = p[1] -#define SKIPOFFSET(p) p++ -#define SIZEOFFSET 1 -#else -#define PUTOFFSET(s,p) \ - { *p++ = (uint32_t)(s >> 32); *p++ = (uint32_t)(s & 0xffffffff); } -#define GETOFFSET(s,p) \ - { s = ((PCRE2_SIZE)p[0] << 32) | (PCRE2_SIZE)p[1]; p += 2; } -#define GETPLUSOFFSET(s,p) \ - { s = ((PCRE2_SIZE)p[1] << 32) | (PCRE2_SIZE)p[2]; p += 2; } -#define READPLUSOFFSET(s,p) \ - { s = ((PCRE2_SIZE)p[1] << 32) | (PCRE2_SIZE)p[2]; } -#define SKIPOFFSET(p) p += 2 -#define SIZEOFFSET 2 -#endif - -#ifdef PCRE2_DEBUG -/* Compile data types. */ -#define CDATA_RECURSE_ARGS 0 /* Argument list for recurse */ -#define CDATA_CRANGE 1 /* Character range list */ -#endif - -/* Extended class management flags. */ - -#define CLASS_IS_ECLASS 0x1 - -/* Macro for the highest character value. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -#define MAX_UCHAR_VALUE 0xffu -#elif PCRE2_CODE_UNIT_WIDTH == 16 -#define MAX_UCHAR_VALUE 0xffffu -#else -#define MAX_UCHAR_VALUE 0xffffffffu -#endif - -#define GET_MAX_CHAR_VALUE(utf) \ - ((utf) ? MAX_UTF_CODE_POINT : MAX_UCHAR_VALUE) - -/* Macro for setting individual bits in class bitmaps. */ - -#define SETBIT(a,b) a[(b) >> 3] |= (uint8_t)(1u << ((b) & 0x7)) - -/* Macro for 8 bit specific checks. */ -#if PCRE2_CODE_UNIT_WIDTH == 8 -#define SELECT_VALUE8(value8, value) (value8) -#else -#define SELECT_VALUE8(value8, value) (value) -#endif - -/* Macro for aligning data. */ -#define CLIST_ALIGN_TO(base, align) \ - ((base + ((size_t)(align) - 1)) & ~((size_t)(align) - 1)) - -/* Structure for holding information about an OP_ECLASS internal operand. -An "operand" here could be just a single OP_[X]CLASS, or it could be some -complex expression; but it's some sequence of ECL_* codes which pushes one -value to the stack. */ -typedef struct { - /* The position of the operand - or NULL if (lengthptr != NULL). */ - PCRE2_UCHAR *code_start; - PCRE2_SIZE length; - /* The operand's type if it is a single code (ECL_XCLASS, ECL_ANY, ECL_NONE); - otherwise zero if the operand is not atomic. */ - uint8_t op_single_type; - /* Regardless of whether it's a single code or not, we fully constant-fold - the bitmap for code points < 256. */ - class_bits_storage bits; -} eclass_op_info; - -/* Macros for the definitions below, to prevent name collisions. */ - -#define _pcre2_posix_class_maps PCRE2_SUFFIX(_pcre2_posix_class_maps) -#define _pcre2_update_classbits PCRE2_SUFFIX(_pcre2_update_classbits_) -#define _pcre2_compile_class_nested PCRE2_SUFFIX(_pcre2_compile_class_nested_) -#define _pcre2_compile_class_not_nested PCRE2_SUFFIX(_pcre2_compile_class_not_nested_) -#define _pcre2_compile_get_hash_from_name PCRE2_SUFFIX(_pcre2_compile_get_hash_from_name) -#define _pcre2_compile_find_named_group PCRE2_SUFFIX(_pcre2_compile_find_named_group) -#define _pcre2_compile_find_dupname_details PCRE2_SUFFIX(_pcre2_compile_find_dupname_details) -#define _pcre2_compile_add_name_to_table PCRE2_SUFFIX(_pcre2_compile_add_name_to_table) -#define _pcre2_compile_parse_scan_substr_args PCRE2_SUFFIX(_pcre2_compile_parse_scan_substr_args) -#define _pcre2_compile_parse_recurse_args PCRE2_SUFFIX(_pcre2_compile_parse_recurse_args) - - -/* Indices of the POSIX classes in posix_names, posix_name_lengths, -posix_class_maps, and posix_substitutes. They must be kept in sync. */ - -#define PC_DIGIT 7 -#define PC_GRAPH 8 -#define PC_PRINT 9 -#define PC_PUNCT 10 -#define PC_XDIGIT 13 - -extern const int PRIV(posix_class_maps)[]; - -/* Defines for hash_dup member in named_group structure. */ - -#define NAMED_GROUP_HASH_MASK ((uint16_t)0x7fff) -#define NAMED_GROUP_IS_DUPNAME ((uint16_t)0x8000) - -#define NAMED_GROUP_GET_HASH(ng) ((ng)->hash_dup & NAMED_GROUP_HASH_MASK) - -/* Exported functions from pcre2_compile_class.c file: */ - -/* Set bits in classbits according to the property type */ - -void PRIV(update_classbits)(uint32_t ptype, uint32_t pdata, BOOL negated, - uint8_t *classbits); - -/* Compile the META codes from start_ptr...end_ptr, writing a single OP_CLASS -OP_CLASS, OP_NCLASS, OP_XCLASS, or OP_ALLANY into pcode. */ - -uint32_t *PRIV(compile_class_not_nested)(uint32_t options, uint32_t xoptions, - uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class, BOOL* has_bitmap, - int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr); - -/* Compile the META codes in pptr into opcodes written to pcode. The pptr must -start at a META_CLASS or META_CLASS_NOT. - -The pptr will be left pointing at the matching META_CLASS_END. */ - -BOOL PRIV(compile_class_nested)(uint32_t options, uint32_t xoptions, - uint32_t **pptr, PCRE2_UCHAR **pcode, int *errorcodeptr, - compile_block *cb, PCRE2_SIZE *lengthptr); - -/* Exported functions from pcre2_compile_cgroup.c file: */ - -/* Compute hash from a capture name. */ - -uint16_t PRIV(compile_get_hash_from_name)(PCRE2_SPTR name, uint32_t length); - -/* Get the descriptor of a known named capture. */ - -named_group *PRIV(compile_find_named_group)(PCRE2_SPTR name, - uint32_t length, compile_block *cb); - -/* Add entires to name table in alphabetical order. */ - -uint32_t PRIV(compile_add_name_to_table)(compile_block *cb, - named_group *ng, uint32_t tablecount); - -/* Searches the properties of duplicated names, and returns them -in indexptr and countptr. */ - -BOOL PRIV(compile_find_dupname_details)(PCRE2_SPTR name, uint32_t length, - int *indexptr, int *countptr, int *errorcodeptr, compile_block *cb); - -/* Parse the arguments of recurse operations. */ - -uint32_t * PRIV(compile_parse_scan_substr_args)(uint32_t *pptr, - int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr); - -/* Parse the arguments of recurse operations. */ - -BOOL PRIV(compile_parse_recurse_args)(uint32_t *pptr_start, - PCRE2_SIZE offset, int *errorcodeptr, compile_block *cb); - -#endif /* PCRE2_COMPILE_H_IDEMPOTENT_GUARD */ - -/* End of pcre2_compile.h */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile_cgroup.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile_cgroup.c deleted file mode 100644 index ee0cd06..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile_cgroup.c +++ /dev/null @@ -1,632 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_compile.h" - -/************************************************* -* Compute the hash code from a capture name * -*************************************************/ - -/* This function returns with a simple hash code -computed from the name of a capture group. - -Arguments: - name name of the capture group - length the length of the name - -Returns: hash code -*/ - -uint16_t -PRIV(compile_get_hash_from_name)(PCRE2_SPTR name, uint32_t length) -{ -uint16_t hash; - -PCRE2_ASSERT(length > 0); - -hash = (uint16_t)((name[0] & 0x7f) | ((name[length - 1] & 0xff) << 7)); -PCRE2_ASSERT(hash <= NAMED_GROUP_HASH_MASK); -return hash; -} - - -/************************************************* -* Get the descriptor of a known named capture * -*************************************************/ - -/* This function returns the descriptor in the -named group list of a known capture group. - -Arguments: - name name of the capture group - length the length of the name - -Returns: pointer to the descriptor when found, - NULL otherwise - */ - -named_group * -PRIV(compile_find_named_group)(PCRE2_SPTR name, - uint32_t length, compile_block *cb) -{ -uint16_t hash = PRIV(compile_get_hash_from_name)(name, length); -named_group *ng; -named_group *end = cb->named_groups + cb->names_found; - -for (ng = cb->named_groups; ng < end; ng++) - if (length == ng->length && hash == NAMED_GROUP_GET_HASH(ng) && - PRIV(strncmp)(name, ng->name, length) == 0) return ng; - -return NULL; -} - - -/************************************************* -* Add an entry to the name/number table * -*************************************************/ - -/* This function is called between compiling passes to add an entry to the -name/number table, maintaining alphabetical order. Checking for permitted -and forbidden duplicates has already been done. - -Arguments: - cb the compile data block - nb named group entry - tablecount the count of names in the table so far - -Returns: new tablecount -*/ - -uint32_t -PRIV(compile_add_name_to_table)(compile_block *cb, - named_group *ng, uint32_t tablecount) -{ -uint32_t i; -PCRE2_SPTR name = ng->name; -int length = ng->length; -uint32_t duplicate_count = 1; - -PCRE2_UCHAR *slot = cb->name_table; - -PCRE2_ASSERT(length > 0); - -if ((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) != 0) - { - named_group *ng_it; - named_group *end = cb->named_groups + cb->names_found; - - for (ng_it = ng + 1; ng_it < end; ng_it++) - if (ng_it->name == name) duplicate_count++; - } - -for (i = 0; i < tablecount; i++) - { - int crc = memcmp(name, slot + IMM2_SIZE, CU2BYTES(length)); - if (crc == 0 && slot[IMM2_SIZE + length] != 0) - crc = -1; /* Current name is a substring */ - - /* Make space in the table and break the loop for an earlier name. For a - duplicate or later name, carry on. We do this for duplicates so that in the - simple case (when ?(| is not used) they are in order of their numbers. In all - cases they are in the order in which they appear in the pattern. */ - - if (crc < 0) - { - (void)memmove(slot + cb->name_entry_size * duplicate_count, slot, - CU2BYTES((tablecount - i) * cb->name_entry_size)); - break; - } - - /* Continue the loop for a later or duplicate name */ - - slot += cb->name_entry_size; - } - -tablecount += duplicate_count; - -while (TRUE) - { - PUT2(slot, 0, ng->number); - memcpy(slot + IMM2_SIZE, name, CU2BYTES(length)); - - /* Add a terminating zero and fill the rest of the slot with zeroes so that - the memory is all initialized. Otherwise valgrind moans about uninitialized - memory when saving serialized compiled patterns. */ - - memset(slot + IMM2_SIZE + length, 0, - CU2BYTES(cb->name_entry_size - length - IMM2_SIZE)); - - if (--duplicate_count == 0) break; - - while (TRUE) - { - ++ng; - if (ng->name == name) break; - } - - slot += cb->name_entry_size; - } - -return tablecount; -} - - -/************************************************* -* Find details of duplicate group names * -*************************************************/ - -/* This is called from compile_branch() when it needs to know the index and -count of duplicates in the names table when processing named backreferences, -either directly, or as conditions. - -Arguments: - name points to the name - length the length of the name - indexptr where to put the index - countptr where to put the count of duplicates - errorcodeptr where to put an error code - cb the compile block - -Returns: TRUE if OK, FALSE if not, error code set -*/ - -BOOL -PRIV(compile_find_dupname_details)(PCRE2_SPTR name, uint32_t length, - int *indexptr, int *countptr, int *errorcodeptr, compile_block *cb) -{ -uint32_t i, groupnumber; -int count; -PCRE2_UCHAR *slot = cb->name_table; - -/* Find the first entry in the table */ - -for (i = 0; i < cb->names_found; i++) - { - if (PRIV(strncmp)(name, slot + IMM2_SIZE, length) == 0 && - slot[IMM2_SIZE + length] == 0) break; - slot += cb->name_entry_size; - } - -/* This should not occur, because this function is called only when we know we -have duplicate names. Give an internal error. */ - -/* LCOV_EXCL_START */ -if (i >= cb->names_found) - { - PCRE2_DEBUG_UNREACHABLE(); - *errorcodeptr = ERR53; - cb->erroroffset = name - cb->start_pattern; - return FALSE; - } -/* LCOV_EXCL_STOP */ - -/* Record the index and then see how many duplicates there are, updating the -backref map and maximum back reference as we do. */ - -*indexptr = i; -count = 0; - -for (;;) - { - count++; - groupnumber = GET2(slot, 0); - cb->backref_map |= (groupnumber < 32)? (1u << groupnumber) : 1; - if (groupnumber > cb->top_backref) cb->top_backref = groupnumber; - if (++i >= cb->names_found) break; - slot += cb->name_entry_size; - if (PRIV(strncmp)(name, slot + IMM2_SIZE, length) != 0 || - (slot + IMM2_SIZE)[length] != 0) break; - } - -*countptr = count; -return TRUE; -} - - -/* Process the capture list of scan substring and recurse -operations. Since at least one argument must be present, -a 0 return value represents error. */ - -static size_t -PRIV(compile_process_capture_list)(uint32_t *pptr, PCRE2_SIZE offset, - int *errorcodeptr, compile_block *cb) -{ -size_t i, size = 0; -named_group *ng; -PCRE2_SPTR name; -uint32_t length; -named_group *end = cb->named_groups + cb->names_found; - -while (TRUE) - { - ++pptr; - - switch (META_CODE(*pptr)) - { - case META_OFFSET: - GETPLUSOFFSET(offset, pptr); - continue; - - case META_CAPTURE_NAME: - offset += META_DATA(*pptr); - length = *(++pptr); - name = cb->start_pattern + offset; - - ng = PRIV(compile_find_named_group)(name, length, cb); - - if (ng == NULL) - { - *errorcodeptr = ERR15; - cb->erroroffset = offset; - return 0; - } - - if ((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) == 0) - { - pptr[-1] = META_CAPTURE_NUMBER; - pptr[0] = ng->number; - size++; - continue; - } - - /* Remains only for duplicated names. */ - pptr[-1] = META_CAPTURE_NAME; - pptr[0] = (uint32_t)(ng - cb->named_groups); - size++; - name = ng->name; - - while (++ng < end) - if (ng->name == name) size++; - continue; - - case META_CAPTURE_NUMBER: - offset += META_DATA(*pptr); - - i = *(++pptr); - if (i > cb->bracount) - { - *errorcodeptr = ERR15; - cb->erroroffset = offset; - return 0; - } - if (i > cb->top_backref) cb->top_backref = (uint16_t)i; - size++; - continue; - - default: - break; - } - - PCRE2_ASSERT(size > 0); - return size; - } -} - - -/******************************************************* -* Parse the arguments of scan substring operations * -********************************************************/ - -/* This function parses the arguments of scan substring operations. - -Arguments: - pptr_start points to the current parsed pattern pointer - offset argument starting offset in the pattern - errorcodeptr where to put an error code - cb the compile block - lengthptr NULL during the real compile phase - points to length accumulator during pre-compile phase - -Returns: TRUE if OK, FALSE if not, error code set -*/ - -uint32_t * -PRIV(compile_parse_scan_substr_args)(uint32_t *pptr, - int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr) -{ -uint8_t *captures; -uint8_t *capture_ptr; -uint8_t bit; -PCRE2_SPTR name; -named_group *ng; -named_group *end = cb->named_groups + cb->names_found; -BOOL all_found; -size_t size; - -PCRE2_ASSERT(*pptr == META_OFFSET); -if (PRIV(compile_process_capture_list)(pptr - 1, 0, errorcodeptr, cb) == 0) - return NULL; - -/* Align to bytes. Since the highest capture can -be equal to bracount, +1 is added before the aligning. */ -size = (cb->bracount + 1 + 7) >> 3; -captures = (uint8_t*)cb->cx->memctl.malloc(size, cb->cx->memctl.memory_data); -if (captures == NULL) - { - *errorcodeptr = ERR21; - READPLUSOFFSET(cb->erroroffset, pptr); - return NULL; - } - -memset(captures, 0, size); - -while (TRUE) - { - switch (META_CODE(*pptr)) - { - case META_OFFSET: - pptr++; - SKIPOFFSET(pptr); - continue; - - case META_CAPTURE_NAME: - ng = cb->named_groups + pptr[1]; - PCRE2_ASSERT((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) != 0); - pptr += 2; - name = ng->name; - - all_found = TRUE; - do - { - if (ng->name != name) continue; - - capture_ptr = captures + (ng->number >> 3); - PCRE2_ASSERT(capture_ptr < captures + size); - bit = (uint8_t)(1 << (ng->number & 0x7)); - - if ((*capture_ptr & bit) == 0) - { - *capture_ptr |= bit; - all_found = FALSE; - } - } - while (++ng < end); - - if (!all_found) - { - *lengthptr += 1 + 2 * IMM2_SIZE; - continue; - } - - pptr[-2] = META_CAPTURE_NUMBER; - pptr[-1] = 0; - continue; - - case META_CAPTURE_NUMBER: - pptr += 2; - - capture_ptr = captures + (pptr[-1] >> 3); - PCRE2_ASSERT(capture_ptr < captures + size); - bit = (uint8_t)(1 << (pptr[-1] & 0x7)); - - if ((*capture_ptr & bit) != 0) - { - pptr[-1] = 0; - continue; - } - - *capture_ptr |= bit; - *lengthptr += 1 + IMM2_SIZE; - continue; - - default: - break; - } - - break; - } - -cb->cx->memctl.free(captures, cb->cx->memctl.memory_data); -return pptr - 1; -} - - -/* Implement heapsort heapify algorithm. */ - -static void do_heapify_u16(uint16_t *captures, size_t size, size_t i) -{ -size_t max; -size_t left; -size_t right; -uint16_t tmp; - -while (TRUE) - { - max = i; - left = (i << 1) + 1; - right = left + 1; - - if (left < size && captures[left] > captures[max]) max = left; - if (right < size && captures[right] > captures[max]) max = right; - if (i == max) return; - - tmp = captures[i]; - captures[i] = captures[max]; - captures[max] = tmp; - i = max; - } -} - - -/************************************************* -* Parse the arguments of recurse operations * -*************************************************/ - -/* This function parses the arguments of recurse operations. - -Arguments: - pptr_start the current parsed pattern pointer - offset argument starting offset in the pattern - errorcodeptr where to put an error code - cb the compile block - lengthptr NULL during the real compile phase - points to length accumulator during pre-compile phase - -Returns: TRUE if OK, FALSE if not, error code set -*/ - -BOOL -PRIV(compile_parse_recurse_args)(uint32_t *pptr_start, - PCRE2_SIZE offset, int *errorcodeptr, compile_block *cb) -{ -uint32_t *pptr = pptr_start; -size_t i, size; -PCRE2_SPTR name; -named_group *ng; -named_group *end = cb->named_groups + cb->names_found; -recurse_arguments *args; -uint16_t *captures; -uint16_t *current; -uint16_t *captures_end; -uint16_t tmp; - -/* Process all arguments, compute the required size. */ - -size = PRIV(compile_process_capture_list)(pptr, offset, errorcodeptr, cb); -if (size == 0) return FALSE; - -args = cb->cx->memctl.malloc( - sizeof(recurse_arguments) + size * sizeof(uint16_t), cb->cx->memctl.memory_data); - -if (args == NULL) - { - *errorcodeptr = ERR21; - cb->erroroffset = offset; - return FALSE; - } - -args->header.next = NULL; -#ifdef PCRE2_DEBUG -args->header.type = CDATA_RECURSE_ARGS; -#endif -args->size = size; - -/* Caching the pre-processed capture list. */ -if (cb->last_data != NULL) - cb->last_data->next = &args->header; -else - cb->first_data = &args->header; - -cb->last_data = &args->header; - -/* Create the capture list size. */ - -captures = (uint16_t*)(args + 1); - -while (TRUE) - { - ++pptr; - - switch (META_CODE(*pptr)) - { - case META_OFFSET: - SKIPOFFSET(pptr); - continue; - - case META_CAPTURE_NAME: - ng = cb->named_groups + *(++pptr); - PCRE2_ASSERT((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) != 0); - *captures++ = (uint16_t)(ng->number); - - name = ng->name; - - while (++ng < end) - if (ng->name == name) *captures++ = (uint16_t)(ng->number); - continue; - - case META_CAPTURE_NUMBER: - *captures++ = *(++pptr); - continue; - - default: - break; - } - - break; - } - -PCRE2_ASSERT(size == (size_t)(captures - (uint16_t*)(args + 1))); -args->skip_size = (size_t)(pptr - pptr_start) - 1; - -if (size == 1) return TRUE; - -/* Sort captures. */ - -captures = (uint16_t*)(args + 1); -i = (size >> 1) - 1; -while (TRUE) - { - do_heapify_u16(captures, size, i); - if (i == 0) break; - i--; - } - -for (i = size - 1; i > 0; i--) - { - tmp = captures[0]; - captures[0] = captures[i]; - captures[i] = tmp; - - do_heapify_u16(captures, i, 0); - } - -/* Remove duplicates. */ - -captures_end = captures + size; -tmp = *captures++; -current = captures; - -while (current < captures_end) - { - if (*current != tmp) - { - tmp = *current; - *captures++ = tmp; - } - - current++; - } - -args->size = (size_t)(captures - (uint16_t*)(args + 1)); -return TRUE; -} - -/* End of pcre2_compile_cgroup.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile_class.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile_class.c deleted file mode 100644 index eed74b3..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_compile_class.c +++ /dev/null @@ -1,2777 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_compile.h" - - - -typedef struct { - /* Option bits for eclass. */ - uint32_t options; - uint32_t xoptions; - /* Rarely used members. */ - int *errorcodeptr; - compile_block *cb; - /* Bitmap is needed. */ - BOOL needs_bitmap; -} eclass_context; - -/* Checks the allowed tokens at the end of a class structure in debug mode. -When a new token is not processed by all loops, and the token is equals to -a) one of the cases here: - the compiler will complain about a duplicated case value. -b) none of the cases here: - the loop without the handler will stop with an assertion failure. */ - -#ifdef PCRE2_DEBUG -#define CLASS_END_CASES(meta) \ - default: \ - PCRE2_ASSERT((meta) <= META_END); \ - PCRE2_FALLTHROUGH /* Fall through */ \ - case META_CLASS: \ - case META_CLASS_NOT: \ - case META_CLASS_EMPTY: \ - case META_CLASS_EMPTY_NOT: \ - case META_CLASS_END: \ - case META_ECLASS_AND: \ - case META_ECLASS_OR: \ - case META_ECLASS_SUB: \ - case META_ECLASS_XOR: \ - case META_ECLASS_NOT: -#else -#define CLASS_END_CASES(meta) \ - default: -#endif - -#ifdef SUPPORT_WIDE_CHARS - -/* Heapsort algorithm. */ - -static void do_heapify(uint32_t *buffer, size_t size, size_t i) -{ -size_t max; -size_t left; -size_t right; -uint32_t tmp1, tmp2; - -while (TRUE) - { - max = i; - left = (i << 1) + 2; - right = left + 2; - - if (left < size && buffer[left] > buffer[max]) max = left; - if (right < size && buffer[right] > buffer[max]) max = right; - if (i == max) return; - - /* Swap items. */ - tmp1 = buffer[i]; - tmp2 = buffer[i + 1]; - buffer[i] = buffer[max]; - buffer[i + 1] = buffer[max + 1]; - buffer[max] = tmp1; - buffer[max + 1] = tmp2; - i = max; - } -} - -#ifdef SUPPORT_UNICODE - -#define PARSE_CLASS_UTF 0x1 -#define PARSE_CLASS_CASELESS_UTF 0x2 -#define PARSE_CLASS_RESTRICTED_UTF 0x4 -#define PARSE_CLASS_TURKISH_UTF 0x8 - -/* Get the range of nocase characters which includes the -'c' character passed as argument, or directly follows 'c'. */ - -static const uint32_t* -get_nocase_range(uint32_t c) -{ -uint32_t left = 0; -uint32_t right = PRIV(ucd_nocase_ranges_size); -uint32_t middle; - -if (c > MAX_UTF_CODE_POINT) return PRIV(ucd_nocase_ranges) + right; - -while (TRUE) - { - /* Range end of the middle element. */ - middle = ((left + right) >> 1) | 0x1; - - if (PRIV(ucd_nocase_ranges)[middle] <= c) - left = middle + 1; - else if (middle > 1 && PRIV(ucd_nocase_ranges)[middle - 2] > c) - right = middle - 1; - else - return PRIV(ucd_nocase_ranges) + (middle - 1); - } -} - -/* Get the list of othercase characters, which belongs to the passed range. -Create ranges from these characters, and append them to the buffer argument. */ - -static size_t -utf_caseless_extend(uint32_t start, uint32_t end, uint32_t options, - uint32_t *buffer) -{ -uint32_t new_start = start; -uint32_t new_end = end; -uint32_t c = start; -const uint32_t *list; -uint32_t tmp[3]; -size_t result = 2; -const uint32_t *skip_range = get_nocase_range(c); -uint32_t skip_start = skip_range[0]; - -#if PCRE2_CODE_UNIT_WIDTH == 8 -PCRE2_ASSERT(options & PARSE_CLASS_UTF); -#endif - -#if PCRE2_CODE_UNIT_WIDTH == 32 -if (end > MAX_UTF_CODE_POINT) end = MAX_UTF_CODE_POINT; -#endif - -while (c <= end) - { - uint32_t co; - - if (c > skip_start) - { - c = skip_range[1]; - skip_range += 2; - skip_start = skip_range[0]; - continue; - } - - /* Compute caseless set. */ - - if ((options & (PARSE_CLASS_TURKISH_UTF|PARSE_CLASS_RESTRICTED_UTF)) == - PARSE_CLASS_TURKISH_UTF && - UCD_ANY_I(c)) - { - co = PRIV(ucd_turkish_dotted_i_caseset) + (UCD_DOTTED_I(c)? 0 : 3); - } - else if ((co = UCD_CASESET(c)) != 0 && - (options & PARSE_CLASS_RESTRICTED_UTF) != 0 && - PRIV(ucd_caseless_sets)[co] < 128) - { - co = 0; /* Ignore the caseless set if it's restricted. */ - } - - if (co != 0) - list = PRIV(ucd_caseless_sets) + co; - else - { - co = UCD_OTHERCASE(c); - list = tmp; - tmp[0] = c; - tmp[1] = NOTACHAR; - - if (co != c) - { - tmp[1] = co; - tmp[2] = NOTACHAR; - } - } - c++; - - /* Add characters. */ - do - { -#if PCRE2_CODE_UNIT_WIDTH == 16 - if (!(options & PARSE_CLASS_UTF) && *list > 0xffff) continue; -#endif - - if (*list < new_start) - { - if (*list + 1 == new_start) - { - new_start--; - continue; - } - } - else if (*list > new_end) - { - if (*list - 1 == new_end) - { - new_end++; - continue; - } - } - else continue; - - result += 2; - if (buffer != NULL) - { - buffer[0] = *list; - buffer[1] = *list; - buffer += 2; - } - } - while (*(++list) != NOTACHAR); - } - - if (buffer != NULL) - { - buffer[0] = new_start; - buffer[1] = new_end; - buffer += 2; - (void)buffer; - } - return result; -} - -#endif - -/* Add a character list to a buffer. */ - -static size_t -append_char_list(const uint32_t *p, uint32_t *buffer) -{ -const uint32_t *n; -size_t result = 0; - -while (*p != NOTACHAR) - { - n = p; - while (n[0] == n[1] - 1) n++; - - PCRE2_ASSERT(*p < 0xffff); - - if (buffer != NULL) - { - buffer[0] = *p; - buffer[1] = *n; - buffer += 2; - } - - result += 2; - p = n + 1; - } - - return result; -} - -static uint32_t -get_highest_char(uint32_t options) -{ -(void)options; /* Avoid compiler warning. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -return MAX_UTF_CODE_POINT; -#else -#ifdef SUPPORT_UNICODE -return GET_MAX_CHAR_VALUE((options & PARSE_CLASS_UTF) != 0); -#else -return MAX_UCHAR_VALUE; -#endif -#endif -} - -/* Add a negated character list to a buffer. */ -static size_t -append_negated_char_list(const uint32_t *p, uint32_t options, uint32_t *buffer) -{ -const uint32_t *n; -uint32_t start = 0; -size_t result = 2; - -PCRE2_ASSERT(*p > 0); - -while (*p != NOTACHAR) - { - n = p; - while (n[0] == n[1] - 1) n++; - - PCRE2_ASSERT(*p < 0xffff); - - if (buffer != NULL) - { - buffer[0] = start; - buffer[1] = *p - 1; - buffer += 2; - } - - result += 2; - start = *n + 1; - p = n + 1; - } - - if (buffer != NULL) - { - buffer[0] = start; - buffer[1] = get_highest_char(options); - buffer += 2; - (void)buffer; - } - - return result; -} - -static uint32_t * -append_non_ascii_range(uint32_t options, uint32_t *buffer) -{ - if (buffer == NULL) return NULL; - - buffer[0] = 0x100; - buffer[1] = get_highest_char(options); - return buffer + 2; -} - -static size_t -parse_class(uint32_t *ptr, uint32_t options, uint32_t *buffer) -{ -size_t total_size = 0; -size_t size; -uint32_t meta_arg; -uint32_t start_char; - -while (TRUE) - { - switch (META_CODE(*ptr)) - { - case META_ESCAPE: - meta_arg = META_DATA(*ptr); - switch (meta_arg) - { - case ESC_D: - case ESC_W: - case ESC_S: - buffer = append_non_ascii_range(options, buffer); - total_size += 2; - break; - - case ESC_h: - size = append_char_list(PRIV(hspace_list), buffer); - total_size += size; - if (buffer != NULL) buffer += size; - break; - - case ESC_H: - size = append_negated_char_list(PRIV(hspace_list), options, buffer); - total_size += size; - if (buffer != NULL) buffer += size; - break; - - case ESC_v: - size = append_char_list(PRIV(vspace_list), buffer); - total_size += size; - if (buffer != NULL) buffer += size; - break; - - case ESC_V: - size = append_negated_char_list(PRIV(vspace_list), options, buffer); - total_size += size; - if (buffer != NULL) buffer += size; - break; - - case ESC_p: - case ESC_P: - ptr++; - if (meta_arg == ESC_p && (*ptr >> 16) == PT_ANY) - { - if (buffer != NULL) - { - buffer[0] = 0; - buffer[1] = get_highest_char(options); - buffer += 2; - } - total_size += 2; - } - break; - } - ptr++; - continue; - case META_POSIX_NEG: - buffer = append_non_ascii_range(options, buffer); - total_size += 2; - ptr += 2; - continue; - case META_POSIX: - ptr += 2; - continue; - case META_BIGVALUE: - /* Character literal */ - ptr++; - break; - CLASS_END_CASES(*ptr) - if (*ptr >= META_END) return total_size; - break; - } - - start_char = *ptr; - - if (ptr[1] == META_RANGE_LITERAL || ptr[1] == META_RANGE_ESCAPED) - { - ptr += 2; - PCRE2_ASSERT(*ptr < META_END || *ptr == META_BIGVALUE); - - if (*ptr == META_BIGVALUE) ptr++; - -#ifdef EBCDIC -#error "Missing EBCDIC support" -#endif - } - -#ifdef SUPPORT_UNICODE - if (options & PARSE_CLASS_CASELESS_UTF) - { - size = utf_caseless_extend(start_char, *ptr++, options, buffer); - if (buffer != NULL) buffer += size; - total_size += size; - continue; - } -#endif - - if (buffer != NULL) - { - buffer[0] = start_char; - buffer[1] = *ptr; - buffer += 2; - } - - ptr++; - total_size += 2; - } - - return total_size; -} - -/* Extra uint32_t values for storing the lengths of range lists in -the worst case. Two uint32_t lengths and a range end for a range -starting before 255 */ -#define CHAR_LIST_EXTRA_SIZE 3 - -/* Starting character values for each character list. */ - -static const uint32_t char_list_starts[] = { -#if PCRE2_CODE_UNIT_WIDTH == 32 - XCL_CHAR_LIST_HIGH_32_START, -#endif -#if PCRE2_CODE_UNIT_WIDTH == 32 || defined SUPPORT_UNICODE - XCL_CHAR_LIST_LOW_32_START, -#endif - XCL_CHAR_LIST_HIGH_16_START, - /* Must be terminated by XCL_CHAR_LIST_LOW_16_START, - which also represents the end of the bitset. */ - XCL_CHAR_LIST_LOW_16_START, -}; - -static class_ranges * -compile_optimize_class(uint32_t *start_ptr, uint32_t options, - uint32_t xoptions, compile_block *cb) -{ -class_ranges* cranges; -uint32_t *ptr; -uint32_t *buffer; -uint32_t *dst; -uint32_t class_options = 0; -size_t range_list_size = 0, total_size, i; -uint32_t tmp1, tmp2; -const uint32_t *char_list_next; -uint16_t *next_char; -uint32_t char_list_start, char_list_end; -uint32_t range_start, range_end; - -#ifdef SUPPORT_UNICODE -if (options & PCRE2_UTF) - class_options |= PARSE_CLASS_UTF; - -if ((options & PCRE2_CASELESS) && (options & (PCRE2_UTF|PCRE2_UCP))) - class_options |= PARSE_CLASS_CASELESS_UTF; - -if (xoptions & PCRE2_EXTRA_CASELESS_RESTRICT) - class_options |= PARSE_CLASS_RESTRICTED_UTF; - -if (xoptions & PCRE2_EXTRA_TURKISH_CASING) - class_options |= PARSE_CLASS_TURKISH_UTF; -#else -(void)options; /* Avoid compiler warning. */ -(void)xoptions; /* Avoid compiler warning. */ -#endif - -/* Compute required space for the range. */ - -range_list_size = parse_class(start_ptr, class_options, NULL); -PCRE2_ASSERT((range_list_size & 0x1) == 0); - -/* Allocate buffer. The total_size also represents the end of the buffer. */ - -total_size = range_list_size + - ((range_list_size >= 2) ? CHAR_LIST_EXTRA_SIZE : 0); - -cranges = cb->cx->memctl.malloc( - sizeof(class_ranges) + total_size * sizeof(uint32_t), - cb->cx->memctl.memory_data); - -if (cranges == NULL) return NULL; - -cranges->header.next = NULL; -#ifdef PCRE2_DEBUG -cranges->header.type = CDATA_CRANGE; -#endif -cranges->range_list_size = (uint16_t)range_list_size; -cranges->char_lists_types = 0; -cranges->char_lists_size = 0; -cranges->char_lists_start = 0; - -if (range_list_size == 0) return cranges; - -buffer = (uint32_t*)(cranges + 1); -parse_class(start_ptr, class_options, buffer); - -/* Using <= instead of == to help static analysis. */ -if (range_list_size <= 2) return cranges; - -/* In-place sorting of ranges. */ - -i = (((range_list_size >> 2) - 1) << 1); -while (TRUE) - { - do_heapify(buffer, range_list_size, i); - if (i == 0) break; - i -= 2; - } - -i = range_list_size - 2; -while (TRUE) - { - tmp1 = buffer[i]; - tmp2 = buffer[i + 1]; - buffer[i] = buffer[0]; - buffer[i + 1] = buffer[1]; - buffer[0] = tmp1; - buffer[1] = tmp2; - - do_heapify(buffer, i, 0); - if (i == 0) break; - i -= 2; - } - -/* Merge ranges whenever possible. */ -dst = buffer; -ptr = buffer + 2; -range_list_size -= 2; - -/* The second condition is a very rare corner case, where the end of the last -range is the maximum character. This range cannot be extended further. */ - -while (range_list_size > 0 && dst[1] != ~(uint32_t)0) - { - if (dst[1] + 1 < ptr[0]) - { - dst += 2; - dst[0] = ptr[0]; - dst[1] = ptr[1]; - } - else if (dst[1] < ptr[1]) dst[1] = ptr[1]; - - ptr += 2; - range_list_size -= 2; - } - -PCRE2_ASSERT(dst[1] <= get_highest_char(class_options)); - -/* When the number of ranges are less than six, -they are not converted to range lists. */ - -ptr = buffer; -while (ptr < dst && ptr[1] < 0x100) ptr += 2; -if (dst - ptr < (2 * (6 - 1))) - { - cranges->range_list_size = (uint16_t)(dst + 2 - buffer); - return cranges; - } - -/* Compute character lists structures. */ - -char_list_next = char_list_starts; -char_list_start = *char_list_next++; -#if PCRE2_CODE_UNIT_WIDTH == 32 -char_list_end = XCL_CHAR_LIST_HIGH_32_END; -#elif defined SUPPORT_UNICODE -char_list_end = XCL_CHAR_LIST_LOW_32_END; -#else -char_list_end = XCL_CHAR_LIST_HIGH_16_END; -#endif -next_char = (uint16_t*)(buffer + total_size); - -tmp1 = 0; -tmp2 = ((sizeof(char_list_starts) / sizeof(uint32_t)) - 1) * XCL_TYPE_BIT_LEN; -PCRE2_ASSERT(tmp2 <= 3 * XCL_TYPE_BIT_LEN && tmp2 >= XCL_TYPE_BIT_LEN); -range_start = dst[0]; -range_end = dst[1]; - -while (TRUE) - { - if (range_start >= char_list_start) - { - if (range_start == range_end || range_end < char_list_end) - { - tmp1++; - next_char--; - - if (char_list_start < XCL_CHAR_LIST_LOW_32_START) - *next_char = (uint16_t)((range_end << XCL_CHAR_SHIFT) | XCL_CHAR_END); - else - *(uint32_t*)(--next_char) = - (range_end << XCL_CHAR_SHIFT) | XCL_CHAR_END; - } - - if (range_start < range_end) - { - if (range_start > char_list_start) - { - tmp1++; - next_char--; - - if (char_list_start < XCL_CHAR_LIST_LOW_32_START) - *next_char = (uint16_t)(range_start << XCL_CHAR_SHIFT); - else - *(uint32_t*)(--next_char) = (range_start << XCL_CHAR_SHIFT); - } - else - cranges->char_lists_types |= XCL_BEGIN_WITH_RANGE << tmp2; - } - - PCRE2_ASSERT((uint32_t*)next_char >= dst + 2); - - if (dst > buffer) - { - dst -= 2; - range_start = dst[0]; - range_end = dst[1]; - continue; - } - - range_start = 0; - range_end = 0; - } - - if (range_end >= char_list_start) - { - PCRE2_ASSERT(range_start < char_list_start); - - if (range_end < char_list_end) - { - tmp1++; - next_char--; - - if (char_list_start < XCL_CHAR_LIST_LOW_32_START) - *next_char = (uint16_t)((range_end << XCL_CHAR_SHIFT) | XCL_CHAR_END); - else - *(uint32_t*)(--next_char) = - (range_end << XCL_CHAR_SHIFT) | XCL_CHAR_END; - - PCRE2_ASSERT((uint32_t*)next_char >= dst + 2); - } - - cranges->char_lists_types |= XCL_BEGIN_WITH_RANGE << tmp2; - } - - if (tmp1 >= XCL_ITEM_COUNT_MASK) - { - cranges->char_lists_types |= XCL_ITEM_COUNT_MASK << tmp2; - next_char--; - - if (char_list_start < XCL_CHAR_LIST_LOW_32_START) - *next_char = (uint16_t)tmp1; - else - *(uint32_t*)(--next_char) = tmp1; - } - else - cranges->char_lists_types |= tmp1 << tmp2; - - if (range_start < XCL_CHAR_LIST_LOW_16_START) break; - - PCRE2_ASSERT(tmp2 >= XCL_TYPE_BIT_LEN); - char_list_end = char_list_start - 1; - char_list_start = *char_list_next++; - tmp1 = 0; - tmp2 -= XCL_TYPE_BIT_LEN; - } - -if (dst[0] < XCL_CHAR_LIST_LOW_16_START) dst += 2; -PCRE2_ASSERT((uint16_t*)dst <= next_char); - -cranges->char_lists_size = - (size_t)((uint8_t*)(buffer + total_size) - (uint8_t*)next_char); -cranges->char_lists_start = (size_t)((uint8_t*)next_char - (uint8_t*)buffer); -cranges->range_list_size = (uint16_t)(dst - buffer); -return cranges; -} - -#endif /* SUPPORT_WIDE_CHARS */ - -#ifdef SUPPORT_UNICODE - -void PRIV(update_classbits)(uint32_t ptype, uint32_t pdata, BOOL negated, - uint8_t *classbits) -{ -/* Update PRIV(xclass) when this function is changed. */ -int c, chartype; -const ucd_record *prop; -uint32_t gentype; -BOOL set_bit; - -if (ptype == PT_ANY) - { - if (!negated) memset(classbits, 0xff, 32); - return; - } - -for (c = 0; c < 256; c++) - { - prop = GET_UCD(c); - set_bit = FALSE; - (void)set_bit; - - switch (ptype) - { - case PT_LAMP: - chartype = prop->chartype; - set_bit = (chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt); - break; - - case PT_GC: - set_bit = (PRIV(ucp_gentype)[prop->chartype] == pdata); - break; - - case PT_PC: - set_bit = (prop->chartype == pdata); - break; - - case PT_SC: - set_bit = (prop->script == pdata); - break; - - case PT_SCX: - set_bit = (prop->script == pdata || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), pdata) != 0); - break; - - case PT_ALNUM: - gentype = PRIV(ucp_gentype)[prop->chartype]; - set_bit = (gentype == ucp_L || gentype == ucp_N); - break; - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - switch(c) - { - HSPACE_BYTE_CASES: - VSPACE_BYTE_CASES: - set_bit = TRUE; - break; - - default: - set_bit = (PRIV(ucp_gentype)[prop->chartype] == ucp_Z); - break; - } - break; - - case PT_WORD: - chartype = prop->chartype; - gentype = PRIV(ucp_gentype)[chartype]; - set_bit = (gentype == ucp_L || gentype == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc); - break; - - case PT_UCNC: - set_bit = (c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT || - c == CHAR_GRAVE_ACCENT || c >= 0xa0); - break; - - case PT_BIDICL: - set_bit = (UCD_BIDICLASS_PROP(prop) == pdata); - break; - - case PT_BOOL: - set_bit = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), pdata) != 0; - break; - - case PT_PXGRAPH: - chartype = prop->chartype; - gentype = PRIV(ucp_gentype)[chartype]; - set_bit = (gentype != ucp_Z && (gentype != ucp_C || chartype == ucp_Cf)); - break; - - case PT_PXPRINT: - chartype = prop->chartype; - set_bit = (chartype != ucp_Zl && chartype != ucp_Zp && - (PRIV(ucp_gentype)[chartype] != ucp_C || chartype == ucp_Cf)); - break; - - case PT_PXPUNCT: - gentype = PRIV(ucp_gentype)[prop->chartype]; - set_bit = (gentype == ucp_P || (c < 128 && gentype == ucp_S)); - break; - - default: - PCRE2_ASSERT(ptype == PT_PXXDIGIT); - set_bit = (c >= CHAR_0 && c <= CHAR_9) || - (c >= CHAR_A && c <= CHAR_F) || - (c >= CHAR_a && c <= CHAR_f); - break; - } - - if (negated) set_bit = !set_bit; - if (set_bit) *classbits |= (uint8_t)(1 << (c & 0x7)); - if ((c & 0x7) == 0x7) classbits++; - } -} - -#endif /* SUPPORT_UNICODE */ - - - -#ifdef SUPPORT_WIDE_CHARS - -/************************************************* -* XClass related properties * -*************************************************/ - -/* XClass needs to be generated. */ -#define XCLASS_REQUIRED 0x1 -/* XClass has 8 bit character. */ -#define XCLASS_HAS_8BIT_CHARS 0x2 -/* XClass has properties. */ -#define XCLASS_HAS_PROPS 0x4 -/* XClass has character lists. */ -#define XCLASS_HAS_CHAR_LISTS 0x8 -/* XClass matches to all >= 256 characters. */ -#define XCLASS_HIGH_ANY 0x10 - -#endif - - -/************************************************* -* Internal entry point for add range to class * -*************************************************/ - -/* This function sets the overall range for characters < 256. -It also handles non-utf case folding. - -Arguments: - options the options bits - xoptions the extra options bits - cb compile data - start start of range character - end end of range character - -Returns: cb->classbits is updated -*/ - -static void -add_to_class(uint32_t options, uint32_t xoptions, compile_block *cb, - uint32_t start, uint32_t end) -{ -uint8_t *classbits = cb->classbits.classbits; -uint32_t c, byte_start, byte_end; -uint32_t classbits_end = (end <= 0xff ? end : 0xff); - -#ifndef SUPPORT_UNICODE -(void)xoptions; /* Avoid compiler warning. */ -#endif - -/* If caseless matching is required, scan the range and process alternate -cases. In Unicode, there are 8-bit characters that have alternate cases that -are greater than 255 and vice-versa (though these may be ignored if caseless -restriction is in force). Sometimes we can just extend the original range. */ - -if ((options & PCRE2_CASELESS) != 0) - { -#ifdef SUPPORT_UNICODE - /* UTF mode. This branch is taken if we don't support wide characters (e.g. - 8-bit library, without UTF), but we do treat those characters as Unicode - (if UCP flag is set). In this case, we only need to expand the character class - set to include the case pairs which are in the 0-255 codepoint range. */ - if ((options & (PCRE2_UTF|PCRE2_UCP)) != 0) - { - BOOL turkish_i = (xoptions & (PCRE2_EXTRA_TURKISH_CASING|PCRE2_EXTRA_CASELESS_RESTRICT)) == - PCRE2_EXTRA_TURKISH_CASING; - if (start < 128) - { - uint32_t lo_end = (classbits_end < 127 ? classbits_end : 127); - for (c = start; c <= lo_end; c++) - { - if (turkish_i && UCD_ANY_I(c)) continue; - SETBIT(classbits, cb->fcc[c]); - } - } - if (classbits_end >= 128) - { - uint32_t hi_start = (start > 128 ? start : 128); - for (c = hi_start; c <= classbits_end; c++) - { - uint32_t co = UCD_OTHERCASE(c); - if (co <= 0xff) SETBIT(classbits, co); - } - } - } - - else -#endif /* SUPPORT_UNICODE */ - - /* Not UTF mode */ - { - for (c = start; c <= classbits_end; c++) - SETBIT(classbits, cb->fcc[c]); - } - } - -/* Use the bitmap for characters < 256. Otherwise use extra data. */ - -byte_start = (start + 7) >> 3; -byte_end = (classbits_end + 1) >> 3; - -if (byte_start >= byte_end) - { - for (c = start; c <= classbits_end; c++) - /* Regardless of start, c will always be <= 255. */ - SETBIT(classbits, c); - return; - } - -for (c = byte_start; c < byte_end; c++) - classbits[c] = 0xff; - -byte_start <<= 3; -byte_end <<= 3; - -for (c = start; c < byte_start; c++) - SETBIT(classbits, c); - -for (c = byte_end; c <= classbits_end; c++) - SETBIT(classbits, c); -} - - -#if PCRE2_CODE_UNIT_WIDTH == 8 -/************************************************* -* Internal entry point for add list to class * -*************************************************/ - -/* This function is used for adding a list of horizontal or vertical whitespace -characters to a class. The list must be in order so that ranges of characters -can be detected and handled appropriately. This function sets the overall range -so that the internal functions can try to avoid duplication when handling -case-independence. - -Arguments: - options the options bits - xoptions the extra options bits - cb contains pointers to tables etc. - p points to row of 32-bit values, terminated by NOTACHAR - -Returns: cb->classbits is updated -*/ - -static void -add_list_to_class(uint32_t options, uint32_t xoptions, compile_block *cb, - const uint32_t *p) -{ -while (p[0] < 256) - { - unsigned int n = 0; - - while(p[n+1] == p[0] + n + 1) n++; - add_to_class(options, xoptions, cb, p[0], p[n]); - - p += n + 1; - } -} - - - -/************************************************* -* Add characters not in a list to a class * -*************************************************/ - -/* This function is used for adding the complement of a list of horizontal or -vertical whitespace to a class. The list must be in order. - -Arguments: - options the options bits - xoptions the extra options bits - cb contains pointers to tables etc. - p points to row of 32-bit values, terminated by NOTACHAR - -Returns: cb->classbits is updated -*/ - -static void -add_not_list_to_class(uint32_t options, uint32_t xoptions, compile_block *cb, - const uint32_t *p) -{ -if (p[0] > 0) - add_to_class(options, xoptions, cb, 0, p[0] - 1); -while (p[0] < 256) - { - while (p[1] == p[0] + 1) p++; - add_to_class(options, xoptions, cb, p[0] + 1, (p[1] > 255) ? 255 : p[1] - 1); - p++; - } -} -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - - - -/************************************************* -* Main entry-point to compile a character class * -*************************************************/ - -/* This function consumes a "leaf", which is a set of characters that will -become a single OP_CLASS OP_NCLASS, OP_XCLASS, or OP_ALLANY. */ - -uint32_t * -PRIV(compile_class_not_nested)(uint32_t options, uint32_t xoptions, - uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class, BOOL* has_bitmap, - int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr) -{ -uint32_t *pptr = start_ptr; -PCRE2_UCHAR *code = *pcode; -BOOL should_flip_negation; -const uint8_t *cbits = cb->cbits; -/* Some functions such as add_to_class() or eclass processing -expects that the bitset is stored in cb->classbits.classbits. */ -uint8_t *const classbits = cb->classbits.classbits; -int i; - -#ifdef SUPPORT_UNICODE -BOOL utf = (options & PCRE2_UTF) != 0; -#else /* No Unicode support */ -BOOL utf = FALSE; -#endif - -/* Helper variables for OP_XCLASS opcode (for characters > 255). */ - -#ifdef SUPPORT_WIDE_CHARS -uint32_t xclass_props; -PCRE2_UCHAR *class_uchardata; -class_ranges* cranges; -#else -(void)has_bitmap; /* Avoid compiler warning. */ -(void)errorcodeptr; /* Avoid compiler warning. */ -(void)lengthptr; /* Avoid compiler warning. */ -#endif - -/* If an XClass contains a negative special such as \S, we need to flip the -negation flag at the end, so that support for characters > 255 works correctly -(they are all included in the class). An XClass may need to insert specific -matching or non-matching code for wide characters. -*/ - -should_flip_negation = FALSE; - -/* XClass will be used when characters > 255 might match. */ - -#ifdef SUPPORT_WIDE_CHARS -xclass_props = 0; - -#if PCRE2_CODE_UNIT_WIDTH == 8 -cranges = NULL; - -if (utf) -#endif - { - if (lengthptr != NULL) - { - cranges = compile_optimize_class(pptr, options, xoptions, cb); - - if (cranges == NULL) - { - *errorcodeptr = ERR21; - return NULL; - } - - /* Caching the pre-processed character ranges. */ - if (cb->last_data != NULL) - cb->last_data->next = &cranges->header; - else - cb->first_data = &cranges->header; - - cb->last_data = &cranges->header; - } - else - { - /* Reuse the pre-processed character ranges. */ - cranges = (class_ranges*)cb->first_data; - PCRE2_ASSERT(cranges != NULL && cranges->header.type == CDATA_CRANGE); - cb->first_data = cranges->header.next; - } - - if (cranges->range_list_size > 0) - { - const uint32_t *ranges = (const uint32_t*)(cranges + 1); - - if (ranges[0] <= 255) - xclass_props |= XCLASS_HAS_8BIT_CHARS; - - if (ranges[cranges->range_list_size - 1] == GET_MAX_CHAR_VALUE(utf) && - ranges[cranges->range_list_size - 2] <= 256) - xclass_props |= XCLASS_HIGH_ANY; - } - } - -class_uchardata = code + LINK_SIZE + 2; /* For XCLASS items */ -#endif /* SUPPORT_WIDE_CHARS */ - -/* Initialize the 256-bit (32-byte) bit map to all zeros. We build the map -in a temporary bit of memory, in case the class contains fewer than two -8-bit characters because in that case the compiled code doesn't use the bit -map. */ - -memset(classbits, 0, 32); - -/* Process items until end_ptr is reached. */ - -while (TRUE) - { - uint32_t meta = *(pptr++); - BOOL local_negate; - int posix_class; - int taboffset, tabopt; - class_bits_storage pbits; - uint32_t escape, c; - int i; - - /* Handle POSIX classes such as [:alpha:] etc. */ - switch (META_CODE(meta)) - { - case META_POSIX: - case META_POSIX_NEG: - - local_negate = (meta == META_POSIX_NEG); - posix_class = *(pptr++); - - if (local_negate) should_flip_negation = TRUE; /* Note negative special */ - - /* If matching is caseless, upper and lower are converted to alpha. - This relies on the fact that the class table starts with alpha, - lower, upper as the first 3 entries. */ - - if ((options & PCRE2_CASELESS) != 0 && posix_class <= 2) - posix_class = 0; - - /* When PCRE2_UCP is set, some of the POSIX classes are converted to - different escape sequences that use Unicode properties \p or \P. - Others that are not available via \p or \P have to generate - XCL_PROP/XCL_NOTPROP directly, which is done here. */ - -#ifdef SUPPORT_UNICODE - /* TODO This entire block of code here appears to be unreachable!? I simply - can't see how it can be hit, given that the frontend parser doesn't emit - META_POSIX for GRAPH/PRINT/PUNCT when UCP is set. */ - if ((options & PCRE2_UCP) != 0 && - (xoptions & PCRE2_EXTRA_ASCII_POSIX) == 0) - { - uint32_t ptype; - - switch(posix_class) - { - case PC_GRAPH: - case PC_PRINT: - case PC_PUNCT: - ptype = (posix_class == PC_GRAPH)? PT_PXGRAPH : - (posix_class == PC_PRINT)? PT_PXPRINT : PT_PXPUNCT; - - PRIV(update_classbits)(ptype, 0, local_negate, classbits); - - if ((xclass_props & XCLASS_HIGH_ANY) == 0) - { - if (lengthptr != NULL) - *lengthptr += 3; - else - { - *class_uchardata++ = local_negate? XCL_NOTPROP : XCL_PROP; - *class_uchardata++ = (PCRE2_UCHAR)ptype; - *class_uchardata++ = 0; - } - xclass_props |= XCLASS_REQUIRED | XCLASS_HAS_PROPS; - } - continue; - - /* For the other POSIX classes (ex: ascii) we are going to - fall through to the non-UCP case and build a bit map for - characters with code points less than 256. However, if we are in - a negated POSIX class, characters with code points greater than - 255 must either all match or all not match, depending on whether - the whole class is not or is negated. For example, for - [[:^ascii:]... they must all match, whereas for [^[:^ascii:]... - they must not. - - In the special case where there are no xclass items, this is - automatically handled by the use of OP_CLASS or OP_NCLASS, but an - explicit range is needed for OP_XCLASS. Setting a flag here - causes the range to be generated later when it is known that - OP_XCLASS is required. In the 8-bit library this is relevant only in - utf mode, since no wide characters can exist otherwise. */ - - default: - break; - } - } -#endif /* SUPPORT_UNICODE */ - - /* In the non-UCP case, or when UCP makes no difference, we build the - bit map for the POSIX class in a chunk of local store because we may - be adding and subtracting from it, and we don't want to subtract bits - that may be in the main map already. At the end we or the result into - the bit map that is being built. */ - - posix_class *= 3; - - /* Copy in the first table (always present) */ - - memcpy(pbits.classbits, cbits + PRIV(posix_class_maps)[posix_class], 32); - - /* If there is a second table, add or remove it as required. */ - - taboffset = PRIV(posix_class_maps)[posix_class + 1]; - tabopt = PRIV(posix_class_maps)[posix_class + 2]; - - if (taboffset >= 0) - { - if (tabopt >= 0) - for (i = 0; i < 32; i++) - pbits.classbits[i] |= cbits[i + taboffset]; - else - for (i = 0; i < 32; i++) - pbits.classbits[i] &= (uint8_t)(~cbits[i + taboffset]); - } - - /* Now see if we need to remove any special characters. An option - value of 1 removes vertical space and 2 removes underscore. */ - - if (tabopt < 0) tabopt = -tabopt; -#ifdef EBCDIC - { - uint8_t posix_vertical[4] = { CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR }; - uint8_t posix_underscore = CHAR_UNDERSCORE; - uint8_t *chars = NULL; - int n = 0; - - if (tabopt == 1) { chars = posix_vertical; n = 4; } - else if (tabopt == 2) { chars = &posix_underscore; n = 1; } - - for (; n > 0; ++chars, --n) - pbits.classbits[*chars/8] &= ~(1u << (*chars&7)); - } -#else - if (tabopt == 1) pbits.classbits[1] &= ~0x3c; - else if (tabopt == 2) pbits.classbits[11] &= 0x7f; -#endif - - /* Add the POSIX table or its complement into the main table that is - being built and we are done. */ - - { - uint32_t *classwords = cb->classbits.classwords; - - if (local_negate) - for (i = 0; i < 8; i++) - classwords[i] |= (uint32_t)(~pbits.classwords[i]); - else - for (i = 0; i < 8; i++) - classwords[i] |= pbits.classwords[i]; - } - -#ifdef SUPPORT_WIDE_CHARS - /* Every class contains at least one < 256 character. */ - xclass_props |= XCLASS_HAS_8BIT_CHARS; -#endif - continue; /* End of POSIX handling */ - - /* Other than POSIX classes, the only items we should encounter are - \d-type escapes and literal characters (possibly as ranges). */ - case META_BIGVALUE: - meta = *(pptr++); - break; - - case META_ESCAPE: - escape = META_DATA(meta); - - switch(escape) - { - case ESC_d: - for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_digit]; - break; - - case ESC_D: - should_flip_negation = TRUE; - for (i = 0; i < 32; i++) - classbits[i] |= (uint8_t)(~cbits[i+cbit_digit]); - break; - - case ESC_w: - for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_word]; - break; - - case ESC_W: - should_flip_negation = TRUE; - for (i = 0; i < 32; i++) - classbits[i] |= (uint8_t)(~cbits[i+cbit_word]); - break; - - /* Perl 5.004 onwards omitted VT from \s, but restored it at Perl - 5.18. Before PCRE 8.34, we had to preserve the VT bit if it was - previously set by something earlier in the character class. - Luckily, the value of CHAR_VT is 0x0b in both ASCII and EBCDIC, so - we could just adjust the appropriate bit. From PCRE 8.34 we no - longer treat \s and \S specially. */ - - case ESC_s: - for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_space]; - break; - - case ESC_S: - should_flip_negation = TRUE; - for (i = 0; i < 32; i++) - classbits[i] |= (uint8_t)(~cbits[i+cbit_space]); - break; - - /* When adding the horizontal or vertical space lists to a class, or - their complements, disable PCRE2_CASELESS, because it justs wastes - time, and in the "not-x" UTF cases can create unwanted duplicates in - the XCLASS list (provoked by characters that have more than one other - case and by both cases being in the same "not-x" sublist). */ - - case ESC_h: -#if PCRE2_CODE_UNIT_WIDTH == 8 -#ifdef SUPPORT_UNICODE - if (cranges != NULL) break; -#endif - add_list_to_class(options & ~PCRE2_CASELESS, xoptions, - cb, PRIV(hspace_list)); -#else - PCRE2_ASSERT(cranges != NULL); -#endif - break; - - case ESC_H: -#if PCRE2_CODE_UNIT_WIDTH == 8 -#ifdef SUPPORT_UNICODE - if (cranges != NULL) break; -#endif - add_not_list_to_class(options & ~PCRE2_CASELESS, xoptions, - cb, PRIV(hspace_list)); -#else - PCRE2_ASSERT(cranges != NULL); -#endif - break; - - case ESC_v: -#if PCRE2_CODE_UNIT_WIDTH == 8 -#ifdef SUPPORT_UNICODE - if (cranges != NULL) break; -#endif - add_list_to_class(options & ~PCRE2_CASELESS, xoptions, - cb, PRIV(vspace_list)); -#else - PCRE2_ASSERT(cranges != NULL); -#endif - break; - - case ESC_V: -#if PCRE2_CODE_UNIT_WIDTH == 8 -#ifdef SUPPORT_UNICODE - if (cranges != NULL) break; -#endif - add_not_list_to_class(options & ~PCRE2_CASELESS, xoptions, - cb, PRIV(vspace_list)); -#else - PCRE2_ASSERT(cranges != NULL); -#endif - break; - - /* If Unicode is not supported, \P and \p are not allowed and are - faulted at parse time, so will never appear here. */ - -#ifdef SUPPORT_UNICODE - case ESC_p: - case ESC_P: - { - uint32_t ptype = *pptr >> 16; - uint32_t pdata = *(pptr++) & 0xffff; - - /* The "Any" is processed by PRIV(update_classbits)(). */ - if (ptype == PT_ANY) - { -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (!utf && escape == ESC_p) memset(classbits, 0xff, 32); -#endif - continue; - } - - PRIV(update_classbits)(ptype, pdata, (escape == ESC_P), classbits); - - if ((xclass_props & XCLASS_HIGH_ANY) == 0) - { - if (lengthptr != NULL) - *lengthptr += 3; - else - { - *class_uchardata++ = (escape == ESC_p)? XCL_PROP : XCL_NOTPROP; - *class_uchardata++ = ptype; - *class_uchardata++ = pdata; - } - xclass_props |= XCLASS_REQUIRED | XCLASS_HAS_PROPS; - } - } - continue; -#endif - } - -#ifdef SUPPORT_WIDE_CHARS - /* Every non-property class contains at least one < 256 character. */ - xclass_props |= XCLASS_HAS_8BIT_CHARS; -#endif - /* End handling \d-type escapes */ - continue; - - CLASS_END_CASES(meta) - /* Literals. */ - if (meta < META_END) break; - /* Non-literals: end of class contents. */ - goto END_PROCESSING; - } - - /* A literal character may be followed by a range meta. At parse time - there are checks for out-of-order characters, for ranges where the two - characters are equal, and for hyphens that cannot indicate a range. At - this point, therefore, no checking is needed. */ - - c = meta; - - /* Remember if \r or \n were explicitly used */ - - if (c == CHAR_CR || c == CHAR_NL) cb->external_flags |= PCRE2_HASCRORLF; - - /* Process a character range */ - - if (*pptr == META_RANGE_LITERAL || *pptr == META_RANGE_ESCAPED) - { - uint32_t d; - -#ifdef EBCDIC - BOOL range_is_literal = (*pptr == META_RANGE_LITERAL); -#endif - ++pptr; - d = *(pptr++); - if (d == META_BIGVALUE) d = *(pptr++); - - /* Remember an explicit \r or \n, and add the range to the class. */ - - if (d == CHAR_CR || d == CHAR_NL) cb->external_flags |= PCRE2_HASCRORLF; - -#if PCRE2_CODE_UNIT_WIDTH == 8 -#ifdef SUPPORT_UNICODE - if (cranges != NULL) continue; - xclass_props |= XCLASS_HAS_8BIT_CHARS; -#endif - - /* In an EBCDIC environment, Perl treats alphabetic ranges specially - because there are holes in the encoding, and simply using the range - A-Z (for example) would include the characters in the holes. This - applies only to literal ranges; [\xC1-\xE9] is different to [A-Z]. */ - -#ifdef EBCDIC - if (range_is_literal && - (cb->ctypes[c] & ctype_letter) != 0 && - (cb->ctypes[d] & ctype_letter) != 0 && - (c <= CHAR_z) == (d <= CHAR_z)) - { - uint32_t uc = (d <= CHAR_z)? 0 : 64; - uint32_t C = c - uc; - uint32_t D = d - uc; - - if (C <= CHAR_i) - { - add_to_class(options, xoptions, cb, C + uc, - ((D < CHAR_i)? D : CHAR_i) + uc); - C = CHAR_j; - } - - if (C <= D && C <= CHAR_r) - { - add_to_class(options, xoptions, cb, C + uc, - ((D < CHAR_r)? D : CHAR_r) + uc); - C = CHAR_s; - } - - if (C <= D) - add_to_class(options, xoptions, cb, C + uc, D + uc); - } - else -#endif - /* Not an EBCDIC special range */ - - add_to_class(options, xoptions, cb, c, d); -#else - PCRE2_ASSERT(cranges != NULL); -#endif - continue; - } /* End of range handling */ - - /* Character ranges are ignored when class_ranges is present. */ -#if PCRE2_CODE_UNIT_WIDTH == 8 -#ifdef SUPPORT_UNICODE - if (cranges != NULL) continue; - xclass_props |= XCLASS_HAS_8BIT_CHARS; -#endif - /* Handle a single character. */ - - add_to_class(options, xoptions, cb, meta, meta); -#else - PCRE2_ASSERT(cranges != NULL); -#endif - } /* End of main class-processing loop */ - -END_PROCESSING: - -#ifdef SUPPORT_WIDE_CHARS -PCRE2_ASSERT((xclass_props & XCLASS_HAS_PROPS) == 0 || - (xclass_props & XCLASS_HIGH_ANY) == 0); - -if (cranges != NULL) - { - uint32_t *range = (uint32_t*)(cranges + 1); - uint32_t *end = range + cranges->range_list_size; - - while (range < end && range[0] < 256) - { - PCRE2_ASSERT((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0); - /* Add range to bitset. If we are in UTF or UCP mode, then clear the - caseless bit, because the cranges handle caselessness (only) in this - condition; see the condition for PARSE_CLASS_CASELESS_UTF in - compile_optimize_class(). */ - add_to_class(((options & (PCRE2_UTF|PCRE2_UCP)) != 0)? - (options & ~PCRE2_CASELESS) : options, xoptions, cb, range[0], range[1]); - - if (range[1] > 255) break; - range += 2; - } - - if (cranges->char_lists_size > 0) - { - /* The cranges structure is still used and freed later. */ - PCRE2_ASSERT((xclass_props & XCLASS_HIGH_ANY) == 0); - xclass_props |= XCLASS_REQUIRED | XCLASS_HAS_CHAR_LISTS; - } - else - { - if ((xclass_props & XCLASS_HIGH_ANY) != 0) - { - PCRE2_ASSERT(range + 2 == end && range[0] <= 256 && - range[1] >= GET_MAX_CHAR_VALUE(utf)); - should_flip_negation = TRUE; - range = end; - } - - while (range < end) - { - uint32_t range_start = range[0]; - uint32_t range_end = range[1]; - - range += 2; - xclass_props |= XCLASS_REQUIRED; - - if (range_start < 256) range_start = 256; - - if (lengthptr != NULL) - { -#ifdef SUPPORT_UNICODE - if (utf) - { - *lengthptr += 1; - - if (range_start < range_end) - *lengthptr += PRIV(ord2utf)(range_start, class_uchardata); - - *lengthptr += PRIV(ord2utf)(range_end, class_uchardata); - continue; - } -#endif /* SUPPORT_UNICODE */ - - *lengthptr += range_start < range_end ? 3 : 2; - continue; - } - -#ifdef SUPPORT_UNICODE - if (utf) - { - if (range_start < range_end) - { - *class_uchardata++ = XCL_RANGE; - class_uchardata += PRIV(ord2utf)(range_start, class_uchardata); - } - else - *class_uchardata++ = XCL_SINGLE; - - class_uchardata += PRIV(ord2utf)(range_end, class_uchardata); - continue; - } -#endif /* SUPPORT_UNICODE */ - - /* Without UTF support, character values are constrained - by the bit length, and can only be > 256 for 16-bit and - 32-bit libraries. */ -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (range_start < range_end) - { - *class_uchardata++ = XCL_RANGE; - *class_uchardata++ = range_start; - } - else - *class_uchardata++ = XCL_SINGLE; - - *class_uchardata++ = range_end; -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - } - - if (lengthptr == NULL) - cb->cx->memctl.free(cranges, cb->cx->memctl.memory_data); - } - } -#endif /* SUPPORT_WIDE_CHARS */ - -/* If there are characters with values > 255, or Unicode property settings -(\p or \P), we have to compile an extended class, with its own opcode, -unless there were no property settings and there was a negated special such -as \S in the class, and PCRE2_UCP is not set, because in that case all -characters > 255 are in or not in the class, so any that were explicitly -given as well can be ignored. - -In the UCP case, if certain negated POSIX classes (ex: [:^ascii:]) were -were present in a class, we either have to match or not match all wide -characters (depending on whether the whole class is or is not negated). -This requirement is indicated by match_all_or_no_wide_chars being true. -We do this by including an explicit range, which works in both cases. -This applies only in UTF and 16-bit and 32-bit non-UTF modes, since there -cannot be any wide characters in 8-bit non-UTF mode. - -When there *are* properties in a positive UTF-8 or any 16-bit or 32_bit -class where \S etc is present without PCRE2_UCP, causing an extended class -to be compiled, we make sure that all characters > 255 are included by -forcing match_all_or_no_wide_chars to be true. - -If, when generating an xclass, there are no characters < 256, we can omit -the bitmap in the actual compiled code. */ - -#ifdef SUPPORT_WIDE_CHARS /* Defined for 16/32 bits, or 8-bit with Unicode */ -if ((xclass_props & XCLASS_REQUIRED) != 0) - { - PCRE2_UCHAR *previous = code; - - if ((xclass_props & XCLASS_HAS_CHAR_LISTS) == 0) - *class_uchardata++ = XCL_END; /* Marks the end of extra data */ - *code++ = OP_XCLASS; - code += LINK_SIZE; - *code = negate_class? XCL_NOT:0; - if ((xclass_props & XCLASS_HAS_PROPS) != 0) *code |= XCL_HASPROP; - - /* If the map is required, move up the extra data to make room for it; - otherwise just move the code pointer to the end of the extra data. */ - - if ((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0 || has_bitmap != NULL) - { - if (negate_class) - { - uint32_t *classwords = cb->classbits.classwords; - for (i = 0; i < 8; i++) classwords[i] = ~classwords[i]; - } - - if (has_bitmap == NULL) - { - *code++ |= XCL_MAP; - (void)memmove(code + (32 / sizeof(PCRE2_UCHAR)), code, - CU2BYTES(class_uchardata - code)); - memcpy(code, classbits, 32); - code = class_uchardata + (32 / sizeof(PCRE2_UCHAR)); - } - else - { - code = class_uchardata; - if ((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0) - *has_bitmap = TRUE; - } - } - else code = class_uchardata; - - if ((xclass_props & XCLASS_HAS_CHAR_LISTS) != 0) - { - /* Char lists size is an even number, because all items are 16 or 32 - bit values. The character list data is always aligned to 32 bits. */ - size_t char_lists_size = cranges->char_lists_size; - PCRE2_ASSERT((char_lists_size & 0x1) == 0 && - (cb->char_lists_size & 0x3) == 0); - - if (lengthptr != NULL) - { - char_lists_size = CLIST_ALIGN_TO(char_lists_size, sizeof(uint32_t)); - -#if PCRE2_CODE_UNIT_WIDTH == 8 - *lengthptr += 2 + LINK_SIZE; -#else - *lengthptr += 1 + LINK_SIZE; -#endif - - cb->char_lists_size += char_lists_size; - - char_lists_size /= sizeof(PCRE2_UCHAR); - - /* Storage space for character lists is included - in the maximum pattern size. */ - if (*lengthptr > MAX_PATTERN_SIZE || - MAX_PATTERN_SIZE - *lengthptr < char_lists_size) - { - *errorcodeptr = ERR20; /* Pattern is too large */ - return NULL; - } - } - else - { - uint8_t *data; - - PCRE2_ASSERT(cranges->char_lists_types <= XCL_TYPE_MASK); -#if PCRE2_CODE_UNIT_WIDTH == 8 - /* Encode as high / low bytes. */ - code[0] = (uint8_t)(XCL_LIST | - (cranges->char_lists_types >> 8)); - code[1] = (uint8_t)cranges->char_lists_types; - code += 2; -#else - *code++ = (PCRE2_UCHAR)(XCL_LIST | cranges->char_lists_types); -#endif - - /* Character lists are stored in backwards direction from - byte code start. The non-dfa/dfa matchers can access these - lists using the byte code start stored in match blocks. - Each list is aligned to 32 bit with an optional unused - 16 bit value at the beginning of the character list. */ - - cb->char_lists_size += char_lists_size; - data = (uint8_t*)cb->start_code - cb->char_lists_size; - - memcpy(data, (uint8_t*)(cranges + 1) + cranges->char_lists_start, - char_lists_size); - - /* Since character lists total size is less than MAX_PATTERN_SIZE, - their starting offset fits into a value which size is LINK_SIZE. */ - - char_lists_size = cb->char_lists_size; - PUT(code, 0, (uint32_t)(char_lists_size >> 1)); - code += LINK_SIZE; - -#if defined PCRE2_DEBUG || defined SUPPORT_VALGRIND - if ((char_lists_size & 0x2) != 0) - { - /* In debug the unused 16 bit value is set - to a fixed value and marked unused. */ - ((uint16_t*)data)[-1] = 0x5555; -#ifdef SUPPORT_VALGRIND - VALGRIND_MAKE_MEM_NOACCESS(data - 2, 2); -#endif - } -#endif - - cb->char_lists_size = - CLIST_ALIGN_TO(char_lists_size, sizeof(uint32_t)); - - cb->cx->memctl.free(cranges, cb->cx->memctl.memory_data); - } - } - - /* Now fill in the complete length of the item */ - - PUT(previous, 1, (int)(code - previous)); - goto DONE; /* End of class handling */ - } -#endif /* SUPPORT_WIDE_CHARS */ - -/* If there are no characters > 255, or they are all to be included or -excluded, set the opcode to OP_CLASS or OP_NCLASS, depending on whether the -whole class was negated and whether there were negative specials such as \S -(non-UCP) in the class. Then copy the 32-byte map into the code vector, -negating it if necessary. */ - -if (negate_class) - { - uint32_t *classwords = cb->classbits.classwords; - - for (i = 0; i < 8; i++) classwords[i] = ~classwords[i]; - } - -if ((SELECT_VALUE8(!utf, 0) || negate_class != should_flip_negation) && - cb->classbits.classwords[0] == ~(uint32_t)0) - { - const uint32_t *classwords = cb->classbits.classwords; - int i; - - for (i = 0; i < 8; i++) - if (classwords[i] != ~(uint32_t)0) break; - - if (i == 8) - { - *code++ = OP_ALLANY; - goto DONE; /* End of class handling */ - } - } - -*code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS; -memcpy(code, classbits, 32); -code += 32 / sizeof(PCRE2_UCHAR); - -DONE: -*pcode = code; -return pptr - 1; -} - - - -/* ===================================================================*/ -/* Here follows a block of ECLASS-compiling functions. You may well want to -read them from top to bottom; they are ordered from leafmost (at the top) to -outermost parser (at the bottom of the file). */ - -/* This function folds one operand using the negation operator. -The new, combined chunk of stack code is written out to *pop_info. */ - -static void -fold_negation(eclass_op_info *pop_info, PCRE2_SIZE *lengthptr, - BOOL preserve_classbits) -{ -int i; - -/* If the chunk of stack code is already composed of multiple ops, we won't -descend in and try and propagate the negation down the tree. (That would lead -to O(n^2) compile-time, which could be exploitable with a malicious regex - -although maybe that's not really too much of a worry in a library that offers -an exponential-time matching function!) */ - -if (pop_info->op_single_type == 0) - { - if (lengthptr != NULL) - *lengthptr += 1; - else - pop_info->code_start[pop_info->length] = ECL_NOT; - pop_info->length += 1; - } - -/* Otherwise, it's a nice single-op item, so we can easily fold in the negation -without needing to produce an ECL_NOT. */ - -else if (pop_info->op_single_type == ECL_ANY || - pop_info->op_single_type == ECL_NONE) - { - pop_info->op_single_type = (pop_info->op_single_type == ECL_NONE)? - ECL_ANY : ECL_NONE; - if (lengthptr == NULL) - *(pop_info->code_start) = pop_info->op_single_type; - } -else - { - PCRE2_ASSERT(pop_info->op_single_type == ECL_XCLASS && - pop_info->length >= 1 + LINK_SIZE + 1); - if (lengthptr == NULL) - pop_info->code_start[1 + LINK_SIZE] ^= XCL_NOT; - } - -if (!preserve_classbits) - { - for (i = 0; i < 8; i++) - pop_info->bits.classwords[i] = ~pop_info->bits.classwords[i]; - } -} - - - -/* This function folds together two operands using a binary operator. -The new, combined chunk of stack code is written out to *lhs_op_info. */ - -static void -fold_binary(int op, eclass_op_info *lhs_op_info, eclass_op_info *rhs_op_info, - PCRE2_SIZE *lengthptr) -{ -int i; - -switch (op) - { - /* ECL_AND truth table: - - LHS RHS RESULT - ---------------- - ANY * RHS - * ANY LHS - NONE * NONE - * NONE NONE - X Y X & Y - */ - - case ECL_AND: - if (rhs_op_info->op_single_type == ECL_ANY) - { - /* no-op: drop the RHS */ - } - else if (lhs_op_info->op_single_type == ECL_ANY) - { - /* no-op: drop the LHS, and memmove the RHS into its place */ - if (lengthptr == NULL) - memmove(lhs_op_info->code_start, rhs_op_info->code_start, - CU2BYTES(rhs_op_info->length)); - lhs_op_info->length = rhs_op_info->length; - lhs_op_info->op_single_type = rhs_op_info->op_single_type; - } - else if (rhs_op_info->op_single_type == ECL_NONE) - { - /* the result is ECL_NONE: write into the LHS */ - if (lengthptr == NULL) - lhs_op_info->code_start[0] = ECL_NONE; - lhs_op_info->length = 1; - lhs_op_info->op_single_type = ECL_NONE; - } - else if (lhs_op_info->op_single_type == ECL_NONE) - { - /* the result is ECL_NONE: drop the RHS */ - } - else - { - /* Both of LHS & RHS are either ECL_XCLASS, or compound operations. */ - if (lengthptr != NULL) - *lengthptr += 1; - else - { - PCRE2_ASSERT(rhs_op_info->code_start == - lhs_op_info->code_start + lhs_op_info->length); - rhs_op_info->code_start[rhs_op_info->length] = ECL_AND; - } - lhs_op_info->length += rhs_op_info->length + 1; - lhs_op_info->op_single_type = 0; - } - - for (i = 0; i < 8; i++) - lhs_op_info->bits.classwords[i] &= rhs_op_info->bits.classwords[i]; - break; - - /* ECL_OR truth table: - - LHS RHS RESULT - ---------------- - ANY * ANY - * ANY ANY - NONE * RHS - * NONE LHS - X Y X | Y - */ - - case ECL_OR: - if (rhs_op_info->op_single_type == ECL_NONE) - { - /* no-op: drop the RHS */ - } - else if (lhs_op_info->op_single_type == ECL_NONE) - { - /* no-op: drop the LHS, and memmove the RHS into its place */ - if (lengthptr == NULL) - memmove(lhs_op_info->code_start, rhs_op_info->code_start, - CU2BYTES(rhs_op_info->length)); - lhs_op_info->length = rhs_op_info->length; - lhs_op_info->op_single_type = rhs_op_info->op_single_type; - } - else if (rhs_op_info->op_single_type == ECL_ANY) - { - /* the result is ECL_ANY: write into the LHS */ - if (lengthptr == NULL) - lhs_op_info->code_start[0] = ECL_ANY; - lhs_op_info->length = 1; - lhs_op_info->op_single_type = ECL_ANY; - } - else if (lhs_op_info->op_single_type == ECL_ANY) - { - /* the result is ECL_ANY: drop the RHS */ - } - else - { - /* Both of LHS & RHS are either ECL_XCLASS, or compound operations. */ - if (lengthptr != NULL) - *lengthptr += 1; - else - { - PCRE2_ASSERT(rhs_op_info->code_start == - lhs_op_info->code_start + lhs_op_info->length); - rhs_op_info->code_start[rhs_op_info->length] = ECL_OR; - } - lhs_op_info->length += rhs_op_info->length + 1; - lhs_op_info->op_single_type = 0; - } - - for (i = 0; i < 8; i++) - lhs_op_info->bits.classwords[i] |= rhs_op_info->bits.classwords[i]; - break; - - /* ECL_XOR truth table: - - LHS RHS RESULT - ---------------- - ANY * !RHS - * ANY !LHS - NONE * RHS - * NONE LHS - X Y X ^ Y - */ - - case ECL_XOR: - if (rhs_op_info->op_single_type == ECL_NONE) - { - /* no-op: drop the RHS */ - } - else if (lhs_op_info->op_single_type == ECL_NONE) - { - /* no-op: drop the LHS, and memmove the RHS into its place */ - if (lengthptr == NULL) - memmove(lhs_op_info->code_start, rhs_op_info->code_start, - CU2BYTES(rhs_op_info->length)); - lhs_op_info->length = rhs_op_info->length; - lhs_op_info->op_single_type = rhs_op_info->op_single_type; - } - else if (rhs_op_info->op_single_type == ECL_ANY) - { - /* the result is !LHS: fold in the negation, and drop the RHS */ - /* Preserve the classbits, because we promise to deal with them later. */ - fold_negation(lhs_op_info, lengthptr, TRUE); - } - else if (lhs_op_info->op_single_type == ECL_ANY) - { - /* the result is !RHS: drop the LHS, memmove the RHS into its place, and - fold in the negation */ - if (lengthptr == NULL) - memmove(lhs_op_info->code_start, rhs_op_info->code_start, - CU2BYTES(rhs_op_info->length)); - lhs_op_info->length = rhs_op_info->length; - lhs_op_info->op_single_type = rhs_op_info->op_single_type; - - /* Preserve the classbits, because we promise to deal with them later. */ - fold_negation(lhs_op_info, lengthptr, TRUE); - } - else - { - /* Both of LHS & RHS are either ECL_XCLASS, or compound operations. */ - if (lengthptr != NULL) - *lengthptr += 1; - else - { - PCRE2_ASSERT(rhs_op_info->code_start == - lhs_op_info->code_start + lhs_op_info->length); - rhs_op_info->code_start[rhs_op_info->length] = ECL_XOR; - } - lhs_op_info->length += rhs_op_info->length + 1; - lhs_op_info->op_single_type = 0; - } - - for (i = 0; i < 8; i++) - lhs_op_info->bits.classwords[i] ^= rhs_op_info->bits.classwords[i]; - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - break; - /* LCOV_EXCL_STOP */ - } -} - - - -static BOOL -compile_eclass_nested(eclass_context *context, BOOL negated, - uint32_t **pptr, PCRE2_UCHAR **pcode, - eclass_op_info *pop_info, PCRE2_SIZE *lengthptr); - -/* This function consumes a group of implicitly-unioned class elements. -These can be characters, ranges, properties, or nested classes, as long -as they are all joined by being placed adjacently. */ - -static BOOL -compile_class_operand(eclass_context *context, BOOL negated, - uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info, - PCRE2_SIZE *lengthptr) -{ -uint32_t *ptr = *pptr; -uint32_t *prev_ptr; -PCRE2_UCHAR *code = *pcode; -PCRE2_UCHAR *code_start = code; -PCRE2_SIZE prev_length = (lengthptr != NULL)? *lengthptr : 0; -PCRE2_SIZE extra_length; -uint32_t meta = META_CODE(*ptr); -int i; - -switch (meta) - { - case META_CLASS_EMPTY_NOT: - case META_CLASS_EMPTY: - ++ptr; - pop_info->length = 1; - if ((meta == META_CLASS_EMPTY) == negated) - { - *code++ = pop_info->op_single_type = ECL_ANY; - memset(pop_info->bits.classbits, 0xff, 32); - } - else - { - *code++ = pop_info->op_single_type = ECL_NONE; - memset(pop_info->bits.classbits, 0, 32); - } - break; - - case META_CLASS: - case META_CLASS_NOT: - if ((*ptr & CLASS_IS_ECLASS) != 0) - { - if (!compile_eclass_nested(context, negated, &ptr, &code, - pop_info, lengthptr)) - return FALSE; - - PCRE2_ASSERT(*ptr == META_CLASS_END); - ptr++; - goto DONE; - } - - ptr++; - PCRE2_FALLTHROUGH /* Fall through */ - - default: - /* Scan forward characters, ranges, and properties. - For example: inside [a-z_ -- m] we don't have brackets around "a-z_" but - we still need to collect that fragment up into a "leaf" OP_CLASS. */ - - prev_ptr = ptr; - ptr = PRIV(compile_class_not_nested)( - context->options, context->xoptions, ptr, &code, - (meta != META_CLASS_NOT) == negated, &context->needs_bitmap, - context->errorcodeptr, context->cb, lengthptr); - if (ptr == NULL) return FALSE; - - /* We must have a 100% guarantee that ptr increases when - compile_class_operand() returns, even on Release builds, so that we can - statically prove our loops terminate. */ - /* LCOV_EXCL_START */ - if (ptr <= prev_ptr) - { - PCRE2_DEBUG_UNREACHABLE(); - return FALSE; - } - /* LCOV_EXCL_STOP */ - - /* If we fell through above, consume the closing ']'. */ - if (meta == META_CLASS || meta == META_CLASS_NOT) - { - PCRE2_ASSERT(*ptr == META_CLASS_END); - ptr++; - } - - /* Regardless of whether (lengthptr == NULL), some data will still be written - out to *pcode, which we need: we have to peek at it, to transform the opcode - into the ECLASS version (since we need to hoist up the bitmaps). */ - PCRE2_ASSERT(code > code_start); - extra_length = (lengthptr != NULL)? *lengthptr - prev_length : 0; - - /* Easiest case: convert OP_ALLANY to ECL_ANY */ - - if (*code_start == OP_ALLANY) - { - PCRE2_ASSERT(code - code_start == 1 && extra_length == 0); - pop_info->length = 1; - *code_start = pop_info->op_single_type = ECL_ANY; - memset(pop_info->bits.classbits, 0xff, 32); - } - - /* For OP_CLASS and OP_NCLASS, we hoist out the bitmap and convert to - ECL_NONE / ECL_ANY respectively. */ - - else if (*code_start == OP_CLASS || *code_start == OP_NCLASS) - { - PCRE2_ASSERT(code - code_start == 1 + 32 / sizeof(PCRE2_UCHAR) && - extra_length == 0); - pop_info->length = 1; - *code_start = pop_info->op_single_type = - (*code_start == OP_CLASS)? ECL_NONE : ECL_ANY; - memcpy(pop_info->bits.classbits, code_start + 1, 32); - /* Rewind the code pointer, but make sure we adjust *lengthptr, because we - do need to reserve that space (even though we only use it temporarily). */ - if (lengthptr != NULL) - *lengthptr += code - (code_start + 1); - code = code_start + 1; - - if (!context->needs_bitmap && *code_start == ECL_NONE) - { - uint32_t *classwords = pop_info->bits.classwords; - - for (i = 0; i < 8; i++) - if (classwords[i] != 0) - { - context->needs_bitmap = TRUE; - break; - } - } - else - context->needs_bitmap = TRUE; - } - - /* Finally, for OP_XCLASS we hoist out the bitmap (if any), and convert to - ECL_XCLASS. */ - - else - { - PCRE2_ASSERT(*code_start == OP_XCLASS); - *code_start = pop_info->op_single_type = ECL_XCLASS; - - PCRE2_ASSERT(code - code_start >= 1 + LINK_SIZE + 1); - - memcpy(pop_info->bits.classbits, context->cb->classbits.classbits, 32); - pop_info->length = (code - code_start) + extra_length; - } - - break; - } /* End of switch(meta) */ - -pop_info->code_start = (lengthptr == NULL)? code_start : NULL; - -if (lengthptr != NULL) - { - *lengthptr += code - code_start; - code = code_start; - } - -DONE: -PCRE2_ASSERT(lengthptr == NULL || (code == code_start)); - -*pptr = ptr; -*pcode = code; -return TRUE; -} - - - -/* This function consumes a group of implicitly-unioned class elements. -These can be characters, ranges, properties, or nested classes, as long -as they are all joined by being placed adjacently. */ - -static BOOL -compile_class_juxtaposition(eclass_context *context, BOOL negated, - uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info, - PCRE2_SIZE *lengthptr) -{ -uint32_t *ptr = *pptr; -PCRE2_UCHAR *code = *pcode; -#ifdef PCRE2_DEBUG -PCRE2_UCHAR *start_code = *pcode; -#endif - -/* See compile_class_binary_loose() for comments on compile-time folding of -the "negated" flag. */ - -/* Because it's a non-empty class, there must be an operand at the start. */ -if (!compile_class_operand(context, negated, &ptr, &code, pop_info, lengthptr)) - return FALSE; - -while (*ptr != META_CLASS_END && - !(*ptr >= META_ECLASS_AND && *ptr <= META_ECLASS_NOT)) - { - uint32_t op; - BOOL rhs_negated; - eclass_op_info rhs_op_info; - - if (negated) - { - /* !(A juxtapose B) -> !A && !B */ - op = ECL_AND; - rhs_negated = TRUE; - } - else - { - /* A juxtapose B -> A || B */ - op = ECL_OR; - rhs_negated = FALSE; - } - - /* An operand must follow the operator. */ - if (!compile_class_operand(context, rhs_negated, &ptr, &code, - &rhs_op_info, lengthptr)) - return FALSE; - - /* Convert infix to postfix (RPN). */ - fold_binary(op, pop_info, &rhs_op_info, lengthptr); - if (lengthptr == NULL) - code = pop_info->code_start + pop_info->length; - } - -PCRE2_ASSERT(lengthptr == NULL || code == start_code); - -*pptr = ptr; -*pcode = code; -return TRUE; -} - - - -/* This function consumes unary prefix operators. */ - -static BOOL -compile_class_unary(eclass_context *context, BOOL negated, - uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info, - PCRE2_SIZE *lengthptr) -{ -uint32_t *ptr = *pptr; -#ifdef PCRE2_DEBUG -PCRE2_UCHAR *start_code = *pcode; -#endif - -while (*ptr == META_ECLASS_NOT) - { - ++ptr; - negated = !negated; - } - -*pptr = ptr; -/* Because it's a non-empty class, there must be an operand. */ -if (!compile_class_juxtaposition(context, negated, pptr, pcode, - pop_info, lengthptr)) - return FALSE; - -PCRE2_ASSERT(lengthptr == NULL || *pcode == start_code); -return TRUE; -} - - - -/* This function consumes tightly-binding binary operators. */ - -static BOOL -compile_class_binary_tight(eclass_context *context, BOOL negated, - uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info, - PCRE2_SIZE *lengthptr) -{ -uint32_t *ptr = *pptr; -PCRE2_UCHAR *code = *pcode; -#ifdef PCRE2_DEBUG -PCRE2_UCHAR *start_code = *pcode; -#endif - -/* See compile_class_binary_loose() for comments on compile-time folding of -the "negated" flag. */ - -/* Because it's a non-empty class, there must be an operand at the start. */ -if (!compile_class_unary(context, negated, &ptr, &code, pop_info, lengthptr)) - return FALSE; - -while (*ptr == META_ECLASS_AND) - { - uint32_t op; - BOOL rhs_negated; - eclass_op_info rhs_op_info; - - if (negated) - { - /* !(A && B) -> !A || !B */ - op = ECL_OR; - rhs_negated = TRUE; - } - else - { - /* A && B -> A && B */ - op = ECL_AND; - rhs_negated = FALSE; - } - - ++ptr; - - /* An operand must follow the operator. */ - if (!compile_class_unary(context, rhs_negated, &ptr, &code, - &rhs_op_info, lengthptr)) - return FALSE; - - /* Convert infix to postfix (RPN). */ - fold_binary(op, pop_info, &rhs_op_info, lengthptr); - if (lengthptr == NULL) - code = pop_info->code_start + pop_info->length; - } - -PCRE2_ASSERT(lengthptr == NULL || code == start_code); - -*pptr = ptr; -*pcode = code; -return TRUE; -} - - - -/* This function consumes loosely-binding binary operators. */ - -static BOOL -compile_class_binary_loose(eclass_context *context, BOOL negated, - uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info, - PCRE2_SIZE *lengthptr) -{ -uint32_t *ptr = *pptr; -PCRE2_UCHAR *code = *pcode; -#ifdef PCRE2_DEBUG -PCRE2_UCHAR *start_code = *pcode; -#endif - -/* We really want to fold the negation operator, if at all possible, so that -simple cases can be reduced down. In particular, in 8-bit no-UTF mode, we want -to produce a fully-folded expression, so that we can guarantee not to emit any -OP_ECLASS codes (in the same way that we never emit OP_XCLASS in this mode). - -This has the consequence that with a little ingenuity, we can in fact avoid -emitting (nearly...) all cases of the "NOT" operator. Imagine that we have: - !(A ... -We have parsed the preceding "!", and we are about to parse the "A" operand. We -don't know yet whether there will even be a following binary operand! Both of -these are possibilities for what follows: - !(A && B) - !(A) -However, we can still fold the "!" into the "A" operand, because no matter what -the following binary operator will be, we can produce an expression which is -equivalent. */ - -/* Because it's a non-empty class, there must be an operand at the start. */ -if (!compile_class_binary_tight(context, negated, &ptr, &code, - pop_info, lengthptr)) - return FALSE; - -while (*ptr >= META_ECLASS_OR && *ptr <= META_ECLASS_XOR) - { - uint32_t op; - BOOL op_neg; - BOOL rhs_negated; - eclass_op_info rhs_op_info; - - if (negated) - { - /* The whole expression is being negated; we respond by unconditionally - negating the LHS A, before seeing what follows. And hooray! We can recover, - no matter what follows. */ - /* !(A || B) -> !A && !B */ - /* !(A -- B) -> !(A && !B) -> !A || B */ - /* !(A XOR B) -> !(!A XOR !B) -> !A XNOR !B */ - op = (*ptr == META_ECLASS_OR )? ECL_AND : - (*ptr == META_ECLASS_SUB)? ECL_OR : - /*ptr == META_ECLASS_XOR*/ ECL_XOR; - op_neg = (*ptr == META_ECLASS_XOR); - rhs_negated = *ptr != META_ECLASS_SUB; - } - else - { - /* A || B -> A || B */ - /* A -- B -> A && !B */ - /* A XOR B -> A XOR B */ - op = (*ptr == META_ECLASS_OR )? ECL_OR : - (*ptr == META_ECLASS_SUB)? ECL_AND : - /*ptr == META_ECLASS_XOR*/ ECL_XOR; - op_neg = FALSE; - rhs_negated = *ptr == META_ECLASS_SUB; - } - - ++ptr; - - /* An operand must follow the operator. */ - if (!compile_class_binary_tight(context, rhs_negated, &ptr, &code, - &rhs_op_info, lengthptr)) - return FALSE; - - /* Convert infix to postfix (RPN). */ - fold_binary(op, pop_info, &rhs_op_info, lengthptr); - if (op_neg) fold_negation(pop_info, lengthptr, FALSE); - if (lengthptr == NULL) - code = pop_info->code_start + pop_info->length; - } - -PCRE2_ASSERT(lengthptr == NULL || code == start_code); - -*pptr = ptr; -*pcode = code; -return TRUE; -} - - - -/* This function converts the META codes in pptr into opcodes written to -pcode. The pptr must start at a META_CLASS or META_CLASS_NOT. - -The class is compiled as a left-associative sequence of operator -applications. - -The pptr will be left pointing at the matching META_CLASS_END. */ - -static BOOL -compile_eclass_nested(eclass_context *context, BOOL negated, - uint32_t **pptr, PCRE2_UCHAR **pcode, - eclass_op_info *pop_info, PCRE2_SIZE *lengthptr) -{ -uint32_t *ptr = *pptr; -#ifdef PCRE2_DEBUG -PCRE2_UCHAR *start_code = *pcode; -#endif - -/* The CLASS_IS_ECLASS bit must be set since it is a nested class. */ -PCRE2_ASSERT(*ptr == (META_CLASS | CLASS_IS_ECLASS) || - *ptr == (META_CLASS_NOT | CLASS_IS_ECLASS)); - -if (*ptr++ == (META_CLASS_NOT | CLASS_IS_ECLASS)) - negated = !negated; - -(*pptr)++; - -/* Because it's a non-empty class, there must be an operand at the start. */ -if (!compile_class_binary_loose(context, negated, pptr, pcode, - pop_info, lengthptr)) - return FALSE; - -PCRE2_ASSERT(**pptr == META_CLASS_END); -PCRE2_ASSERT(lengthptr == NULL || *pcode == start_code); -return TRUE; -} - -BOOL -PRIV(compile_class_nested)(uint32_t options, uint32_t xoptions, - uint32_t **pptr, PCRE2_UCHAR **pcode, int *errorcodeptr, - compile_block *cb, PCRE2_SIZE *lengthptr) -{ -eclass_context context; -eclass_op_info op_info; -PCRE2_SIZE previous_length = (lengthptr != NULL)? *lengthptr : 0; -PCRE2_UCHAR *code = *pcode; -PCRE2_UCHAR *previous; -BOOL allbitsone = TRUE; -int i; - -context.needs_bitmap = FALSE; -context.options = options; -context.xoptions = xoptions; -context.errorcodeptr = errorcodeptr; -context.cb = cb; - -previous = code; -*code++ = OP_ECLASS; -code += LINK_SIZE; -*code++ = 0; /* Flags, currently zero. */ -if (!compile_eclass_nested(&context, FALSE, pptr, &code, &op_info, lengthptr)) - return FALSE; - -if (lengthptr != NULL) - { - *lengthptr += code - previous; - code = previous; - /* (*lengthptr - previous_length) now holds the amount of buffer that - we require to make the call to compile_class_nested() with - lengthptr = NULL, and including the (1+LINK_SIZE+1) that we write out - before that call. */ - } - -/* Do some useful counting of what's in the bitmap. */ -for (i = 0; i < 8; i++) - if (op_info.bits.classwords[i] != 0xffffffff) - { - allbitsone = FALSE; - break; - } - -/* After constant-folding the extended class syntax, it may turn out to be -a simple class after all. In that case, we can unwrap it from the -OP_ECLASS container - and in fact, we must do so, because in 8-bit -no-Unicode mode the matcher is compiled without support for OP_ECLASS. */ - -#ifndef SUPPORT_WIDE_CHARS -PCRE2_ASSERT(op_info.op_single_type != 0); -#else -if (op_info.op_single_type != 0) -#endif - { - /* Rewind back over the OP_ECLASS. */ - code = previous; - - /* If the bits are all ones, and the "high characters" are all matched - too, we use a special-cased encoding of OP_ALLANY. */ - - if (op_info.op_single_type == ECL_ANY && allbitsone) - { - /* Advancing code means rewinding lengthptr, at this point. */ - if (lengthptr != NULL) *lengthptr -= 1; - *code++ = OP_ALLANY; - } - - /* If the high bits are all matched / all not-matched, then we emit an - OP_NCLASS/OP_CLASS respectively. */ - - else if (op_info.op_single_type == ECL_ANY || - op_info.op_single_type == ECL_NONE) - { - PCRE2_SIZE required_len = 1 + (32 / sizeof(PCRE2_UCHAR)); - - if (lengthptr != NULL) - { - if (required_len > (*lengthptr - previous_length)) - *lengthptr = previous_length + required_len; - } - - /* Advancing code means rewinding lengthptr, at this point. */ - if (lengthptr != NULL) *lengthptr -= required_len; - *code++ = (op_info.op_single_type == ECL_ANY)? OP_NCLASS : OP_CLASS; - memcpy(code, op_info.bits.classbits, 32); - code += 32 / sizeof(PCRE2_UCHAR); - } - - /* Otherwise, we have an ECL_XCLASS, so we have the OP_XCLASS data - there, but, we pulled out its bitmap into op_info, so now we have to - put that back into the OP_XCLASS. */ - - else - { -#ifndef SUPPORT_WIDE_CHARS - PCRE2_DEBUG_UNREACHABLE(); -#else - BOOL need_map = context.needs_bitmap; - PCRE2_SIZE required_len; - - PCRE2_ASSERT(op_info.op_single_type == ECL_XCLASS); - required_len = op_info.length + (need_map? 32/sizeof(PCRE2_UCHAR) : 0); - - if (lengthptr != NULL) - { - /* Don't unconditionally request all the space we need - we may - already have asked for more during processing of the ECLASS. */ - if (required_len > (*lengthptr - previous_length)) - *lengthptr = previous_length + required_len; - - /* The code we write out here won't be ignored, even during the - (lengthptr != NULL) phase, because if there's a following quantifier - it will peek backwards. So we do have to write out a (truncated) - OP_XCLASS, even on this branch. */ - *lengthptr -= 1 + LINK_SIZE + 1; - *code++ = OP_XCLASS; - PUT(code, 0, 1 + LINK_SIZE + 1); - code += LINK_SIZE; - *code++ = 0; - } - else - { - PCRE2_UCHAR *rest; - PCRE2_SIZE rest_len; - PCRE2_UCHAR flags; - - /* 1 unit: OP_XCLASS | LINK_SIZE units | 1 unit: flags | ...rest */ - PCRE2_ASSERT(op_info.length >= 1 + LINK_SIZE + 1); - rest = op_info.code_start + 1 + LINK_SIZE + 1; - rest_len = (op_info.code_start + op_info.length) - rest; - - /* First read any data we use, before memmove splats it. */ - flags = op_info.code_start[1 + LINK_SIZE]; - PCRE2_ASSERT((flags & XCL_MAP) == 0); - - /* Next do the memmove before any writes. */ - memmove(code + 1 + LINK_SIZE + 1 + (need_map? 32/sizeof(PCRE2_UCHAR) : 0), - rest, CU2BYTES(rest_len)); - - /* Finally write the header data. */ - *code++ = OP_XCLASS; - PUT(code, 0, (int)required_len); - code += LINK_SIZE; - *code++ = flags | (need_map? XCL_MAP : 0); - if (need_map) - { - memcpy(code, op_info.bits.classbits, 32); - code += 32 / sizeof(PCRE2_UCHAR); - } - code += rest_len; - } -#endif /* SUPPORT_WIDE_CHARS */ - } - } - -/* Otherwise, we're going to keep the OP_ECLASS. However, again we need -to do some adjustment to insert the bitmap if we have one. */ - -#ifdef SUPPORT_WIDE_CHARS -else - { - BOOL need_map = context.needs_bitmap; - PCRE2_SIZE required_len = - 1 + LINK_SIZE + 1 + (need_map? 32/sizeof(PCRE2_UCHAR) : 0) + op_info.length; - - if (lengthptr != NULL) - { - if (required_len > (*lengthptr - previous_length)) - *lengthptr = previous_length + required_len; - - /* As for the XCLASS branch above, we do have to write out a dummy - OP_ECLASS, because of the backwards peek by the quantifier code. Write - out a (truncated) OP_ECLASS, even on this branch. */ - *lengthptr -= 1 + LINK_SIZE + 1; - *code++ = OP_ECLASS; - PUT(code, 0, 1 + LINK_SIZE + 1); - code += LINK_SIZE; - *code++ = 0; - } - else - { - if (need_map) - { - PCRE2_UCHAR *map_start = previous + 1 + LINK_SIZE + 1; - previous[1 + LINK_SIZE] |= ECL_MAP; - memmove(map_start + 32/sizeof(PCRE2_UCHAR), map_start, - CU2BYTES(code - map_start)); - memcpy(map_start, op_info.bits.classbits, 32); - code += 32 / sizeof(PCRE2_UCHAR); - } - PUT(previous, 1, (int)(code - previous)); - } - } -#endif /* SUPPORT_WIDE_CHARS */ - -*pcode = code; -return TRUE; -} - -/* End of pcre2_compile_class.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_config.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_config.c deleted file mode 100644 index 045f6e7..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_config.c +++ /dev/null @@ -1,250 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2020 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -/* These macros are the standard way of turning unquoted text into C strings. -They allow macros like PCRE2_MAJOR to be defined without quotes, which is -convenient for user programs that want to test their values. */ - -#define STRING(a) # a -#define XSTRING(s) STRING(s) - - -/************************************************* -* Return info about what features are configured * -*************************************************/ - -/* If where is NULL, the length of memory required is returned. - -Arguments: - what what information is required - where where to put the information - -Returns: 0 if a numerical value is returned - >= 0 if a string value - PCRE2_ERROR_BADOPTION if "where" not recognized - or JIT target requested when JIT not enabled -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_config(uint32_t what, void *where) -{ -if (where == NULL) /* Requests a length */ - { - switch (what) - { - default: - return PCRE2_ERROR_BADOPTION; - - case PCRE2_CONFIG_BSR: - case PCRE2_CONFIG_COMPILED_WIDTHS: - case PCRE2_CONFIG_DEPTHLIMIT: - case PCRE2_CONFIG_EFFECTIVE_LINKSIZE: - case PCRE2_CONFIG_HEAPLIMIT: - case PCRE2_CONFIG_JIT: - case PCRE2_CONFIG_LINKSIZE: - case PCRE2_CONFIG_MATCHLIMIT: - case PCRE2_CONFIG_NEVER_BACKSLASH_C: - case PCRE2_CONFIG_NEWLINE: - case PCRE2_CONFIG_PARENSLIMIT: - case PCRE2_CONFIG_STACKRECURSE: /* Obsolete */ - case PCRE2_CONFIG_TABLES_LENGTH: - case PCRE2_CONFIG_UNICODE: - return sizeof(uint32_t); - - /* These are handled below */ - - case PCRE2_CONFIG_JITTARGET: - case PCRE2_CONFIG_UNICODE_VERSION: - case PCRE2_CONFIG_VERSION: - break; - } - } - -switch (what) - { - default: - return PCRE2_ERROR_BADOPTION; - - case PCRE2_CONFIG_BSR: -#ifdef BSR_ANYCRLF - *((uint32_t *)where) = PCRE2_BSR_ANYCRLF; -#else - *((uint32_t *)where) = PCRE2_BSR_UNICODE; -#endif - break; - - case PCRE2_CONFIG_COMPILED_WIDTHS: - *((uint32_t *)where) = 0 -#ifdef SUPPORT_PCRE2_8 - + (1 << 0) -#endif -#ifdef SUPPORT_PCRE2_16 - + (1 << 1) -#endif -#ifdef SUPPORT_PCRE2_32 - + (1 << 2) -#endif - ; - break; - - case PCRE2_CONFIG_DEPTHLIMIT: - *((uint32_t *)where) = MATCH_LIMIT_DEPTH; - break; - - case PCRE2_CONFIG_EFFECTIVE_LINKSIZE: - *((uint32_t *)where) = LINK_SIZE * sizeof(PCRE2_UCHAR); - break; - - case PCRE2_CONFIG_HEAPLIMIT: - *((uint32_t *)where) = HEAP_LIMIT; - break; - - case PCRE2_CONFIG_JIT: -#ifdef SUPPORT_JIT - *((uint32_t *)where) = 1; -#else - *((uint32_t *)where) = 0; -#endif - break; - - case PCRE2_CONFIG_JITTARGET: -#ifdef SUPPORT_JIT - { - const char *v = PRIV(jit_get_target)(); - return (int)(1 + ((where == NULL)? - strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v))); - } -#else - return PCRE2_ERROR_BADOPTION; -#endif - - case PCRE2_CONFIG_LINKSIZE: - *((uint32_t *)where) = (uint32_t)CONFIGURED_LINK_SIZE; - break; - - case PCRE2_CONFIG_MATCHLIMIT: - *((uint32_t *)where) = MATCH_LIMIT; - break; - - case PCRE2_CONFIG_NEWLINE: - *((uint32_t *)where) = NEWLINE_DEFAULT; - break; - - case PCRE2_CONFIG_NEVER_BACKSLASH_C: -#ifdef NEVER_BACKSLASH_C - *((uint32_t *)where) = 1; -#else - *((uint32_t *)where) = 0; -#endif - break; - - case PCRE2_CONFIG_PARENSLIMIT: - *((uint32_t *)where) = PARENS_NEST_LIMIT; - break; - - /* This is now obsolete. The stack is no longer used via recursion for - handling backtracking in pcre2_match(). */ - - case PCRE2_CONFIG_STACKRECURSE: - *((uint32_t *)where) = 0; - break; - - case PCRE2_CONFIG_TABLES_LENGTH: - *((uint32_t *)where) = TABLES_LENGTH; - break; - - case PCRE2_CONFIG_UNICODE_VERSION: - { -#if defined SUPPORT_UNICODE - const char *v = PRIV(unicode_version); -#else - const char *v = "Unicode not supported"; -#endif - return (int)(1 + ((where == NULL)? - strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v))); - } - - case PCRE2_CONFIG_UNICODE: -#if defined SUPPORT_UNICODE - *((uint32_t *)where) = 1; -#else - *((uint32_t *)where) = 0; -#endif - break; - - /* The hackery in setting "v" below is to cope with the case when - PCRE2_PRERELEASE is set to an empty string (which it is for real releases). - If the second alternative is used in this case, it does not leave a space - before the date. On the other hand, if all four macros are put into a single - XSTRING when PCRE2_PRERELEASE is not empty, an unwanted space is inserted. - There are problems using an "obvious" approach like this: - - XSTRING(PCRE2_MAJOR) "." XSTRING(PCRE2_MINOR) - XSTRING(PCRE2_PRERELEASE) " " XSTRING(PCRE2_DATE) - - because, when PCRE2_PRERELEASE is empty, this leads to an attempted expansion - of STRING(). The C standard states: "If (before argument substitution) any - argument consists of no preprocessing tokens, the behavior is undefined." It - turns out the gcc treats this case as a single empty string - which is what - we really want - but Visual C grumbles about the lack of an argument for the - macro. Unfortunately, both are within their rights. As there seems to be no - way to test for a macro's value being empty at compile time, we have to - resort to a runtime test. */ - - case PCRE2_CONFIG_VERSION: - { - const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)? - XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) : - XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE); - return (int)(1 + ((where == NULL)? - strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v))); - } - - } - -return 0; -} - -/* End of pcre2_config.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_context.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_context.c deleted file mode 100644 index 6246683..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_context.c +++ /dev/null @@ -1,557 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Default malloc/free functions * -*************************************************/ - -/* Ignore the "user data" argument in each case. */ - -static void *default_malloc(size_t size, void *data) -{ -(void)data; -return malloc(size); -} - - -static void default_free(void *block, void *data) -{ -(void)data; -free(block); -} - - - -/************************************************* -* Get a block and save memory control * -*************************************************/ - -/* This internal function is called to get a block of memory in which the -memory control data is to be stored at the start for future use. - -Arguments: - size amount of memory required - memctl pointer to a memctl block or NULL - -Returns: pointer to memory or NULL on failure -*/ - -extern void * -PRIV(memctl_malloc)(size_t size, pcre2_memctl *memctl) -{ -pcre2_memctl *newmemctl; -void *yield = (memctl == NULL)? malloc(size) : - memctl->malloc(size, memctl->memory_data); -if (yield == NULL) return NULL; -newmemctl = (pcre2_memctl *)yield; -if (memctl == NULL) - { - newmemctl->malloc = default_malloc; - newmemctl->free = default_free; - newmemctl->memory_data = NULL; - } -else *newmemctl = *memctl; -return yield; -} - - - -/************************************************* -* Create and initialize contexts * -*************************************************/ - -/* Initializing for compile and match contexts is done in separate, private -functions so that these can be called from functions such as pcre2_compile() -when an external context is not supplied. The initializing functions have an -option to set up default memory management. */ - -PCRE2_EXP_DEFN pcre2_general_context * PCRE2_CALL_CONVENTION -pcre2_general_context_create(void *(*private_malloc)(size_t, void *), - void (*private_free)(void *, void *), void *memory_data) -{ -pcre2_general_context *gcontext; -if (private_malloc == NULL) private_malloc = default_malloc; -if (private_free == NULL) private_free = default_free; -gcontext = private_malloc(sizeof(pcre2_real_general_context), memory_data); -if (gcontext == NULL) return NULL; -gcontext->memctl.malloc = private_malloc; -gcontext->memctl.free = private_free; -gcontext->memctl.memory_data = memory_data; -return gcontext; -} - - -/* A default compile context is set up to save having to initialize at run time -when no context is supplied to the compile function. */ - -pcre2_compile_context PRIV(default_compile_context) = { - { default_malloc, default_free, NULL }, /* Default memory handling */ - NULL, /* Stack guard */ - NULL, /* Stack guard data */ - PRIV(default_tables), /* Character tables */ - PCRE2_UNSET, /* Max pattern length */ - PCRE2_UNSET, /* Max pattern compiled length */ - BSR_DEFAULT, /* Backslash R default */ - NEWLINE_DEFAULT, /* Newline convention */ - PARENS_NEST_LIMIT, /* As it says */ - 0, /* Extra options */ - MAX_VARLOOKBEHIND, /* As it says */ - PCRE2_OPTIMIZATION_ALL /* All optimizations enabled */ - }; - -/* The create function copies the default into the new memory, but must -override the default memory handling functions if a gcontext was provided. */ - -PCRE2_EXP_DEFN pcre2_compile_context * PCRE2_CALL_CONVENTION -pcre2_compile_context_create(pcre2_general_context *gcontext) -{ -pcre2_compile_context *ccontext = PRIV(memctl_malloc)( - sizeof(pcre2_real_compile_context), (pcre2_memctl *)gcontext); -if (ccontext == NULL) return NULL; -*ccontext = PRIV(default_compile_context); -if (gcontext != NULL) - *((pcre2_memctl *)ccontext) = *((pcre2_memctl *)gcontext); -return ccontext; -} - - -/* A default match context is set up to save having to initialize at run time -when no context is supplied to a match function. */ - -pcre2_match_context PRIV(default_match_context) = { - { default_malloc, default_free, NULL }, -#ifdef SUPPORT_JIT - NULL, /* JIT callback */ - NULL, /* JIT callback data */ -#endif - NULL, /* Callout function */ - NULL, /* Callout data */ - NULL, /* Substitute callout function */ - NULL, /* Substitute callout data */ - NULL, /* Substitute case callout function */ - NULL, /* Substitute case callout data */ - PCRE2_UNSET, /* Offset limit */ - HEAP_LIMIT, - MATCH_LIMIT, - MATCH_LIMIT_DEPTH }; - -/* The create function copies the default into the new memory, but must -override the default memory handling functions if a gcontext was provided. */ - -PCRE2_EXP_DEFN pcre2_match_context * PCRE2_CALL_CONVENTION -pcre2_match_context_create(pcre2_general_context *gcontext) -{ -pcre2_match_context *mcontext = PRIV(memctl_malloc)( - sizeof(pcre2_real_match_context), (pcre2_memctl *)gcontext); -if (mcontext == NULL) return NULL; -*mcontext = PRIV(default_match_context); -if (gcontext != NULL) - *((pcre2_memctl *)mcontext) = *((pcre2_memctl *)gcontext); -return mcontext; -} - - -/* A default convert context is set up to save having to initialize at run time -when no context is supplied to the convert function. */ - -pcre2_convert_context PRIV(default_convert_context) = { - { default_malloc, default_free, NULL }, /* Default memory handling */ -#ifdef _WIN32 - CHAR_BACKSLASH, /* Default path separator */ - CHAR_GRAVE_ACCENT /* Default escape character */ -#else /* Not Windows */ - CHAR_SLASH, /* Default path separator */ - CHAR_BACKSLASH /* Default escape character */ -#endif - }; - -/* The create function copies the default into the new memory, but must -override the default memory handling functions if a gcontext was provided. */ - -PCRE2_EXP_DEFN pcre2_convert_context * PCRE2_CALL_CONVENTION -pcre2_convert_context_create(pcre2_general_context *gcontext) -{ -pcre2_convert_context *ccontext = PRIV(memctl_malloc)( - sizeof(pcre2_real_convert_context), (pcre2_memctl *)gcontext); -if (ccontext == NULL) return NULL; -*ccontext = PRIV(default_convert_context); -if (gcontext != NULL) - *((pcre2_memctl *)ccontext) = *((pcre2_memctl *)gcontext); -return ccontext; -} - - -/************************************************* -* Context copy functions * -*************************************************/ - -PCRE2_EXP_DEFN pcre2_general_context * PCRE2_CALL_CONVENTION -pcre2_general_context_copy(pcre2_general_context *gcontext) -{ -pcre2_general_context *newcontext = - gcontext->memctl.malloc(sizeof(pcre2_real_general_context), - gcontext->memctl.memory_data); -if (newcontext == NULL) return NULL; -memcpy(newcontext, gcontext, sizeof(pcre2_real_general_context)); -return newcontext; -} - - -PCRE2_EXP_DEFN pcre2_compile_context * PCRE2_CALL_CONVENTION -pcre2_compile_context_copy(pcre2_compile_context *ccontext) -{ -pcre2_compile_context *newcontext = - ccontext->memctl.malloc(sizeof(pcre2_real_compile_context), - ccontext->memctl.memory_data); -if (newcontext == NULL) return NULL; -memcpy(newcontext, ccontext, sizeof(pcre2_real_compile_context)); -return newcontext; -} - - -PCRE2_EXP_DEFN pcre2_match_context * PCRE2_CALL_CONVENTION -pcre2_match_context_copy(pcre2_match_context *mcontext) -{ -pcre2_match_context *newcontext = - mcontext->memctl.malloc(sizeof(pcre2_real_match_context), - mcontext->memctl.memory_data); -if (newcontext == NULL) return NULL; -memcpy(newcontext, mcontext, sizeof(pcre2_real_match_context)); -return newcontext; -} - - -PCRE2_EXP_DEFN pcre2_convert_context * PCRE2_CALL_CONVENTION -pcre2_convert_context_copy(pcre2_convert_context *ccontext) -{ -pcre2_convert_context *newcontext = - ccontext->memctl.malloc(sizeof(pcre2_real_convert_context), - ccontext->memctl.memory_data); -if (newcontext == NULL) return NULL; -memcpy(newcontext, ccontext, sizeof(pcre2_real_convert_context)); -return newcontext; -} - - -/************************************************* -* Context free functions * -*************************************************/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_general_context_free(pcre2_general_context *gcontext) -{ -if (gcontext != NULL) - gcontext->memctl.free(gcontext, gcontext->memctl.memory_data); -} - - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_compile_context_free(pcre2_compile_context *ccontext) -{ -if (ccontext != NULL) - ccontext->memctl.free(ccontext, ccontext->memctl.memory_data); -} - - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_match_context_free(pcre2_match_context *mcontext) -{ -if (mcontext != NULL) - mcontext->memctl.free(mcontext, mcontext->memctl.memory_data); -} - - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_convert_context_free(pcre2_convert_context *ccontext) -{ -if (ccontext != NULL) - ccontext->memctl.free(ccontext, ccontext->memctl.memory_data); -} - - -/************************************************* -* Set values in contexts * -*************************************************/ - -/* All these functions return 0 for success or PCRE2_ERROR_BADDATA if invalid -data is given. Only some of the functions are able to test the validity of the -data. */ - - -/* ------------ Compile context ------------ */ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_character_tables(pcre2_compile_context *ccontext, - const uint8_t *tables) -{ -ccontext->tables = tables; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_bsr(pcre2_compile_context *ccontext, uint32_t value) -{ -switch(value) - { - case PCRE2_BSR_ANYCRLF: - case PCRE2_BSR_UNICODE: - ccontext->bsr_convention = value; - return 0; - - default: - return PCRE2_ERROR_BADDATA; - } -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_max_pattern_length(pcre2_compile_context *ccontext, PCRE2_SIZE length) -{ -ccontext->max_pattern_length = length; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_max_pattern_compiled_length(pcre2_compile_context *ccontext, PCRE2_SIZE length) -{ -ccontext->max_pattern_compiled_length = length; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_newline(pcre2_compile_context *ccontext, uint32_t newline) -{ -switch(newline) - { - case PCRE2_NEWLINE_CR: - case PCRE2_NEWLINE_LF: - case PCRE2_NEWLINE_CRLF: - case PCRE2_NEWLINE_ANY: - case PCRE2_NEWLINE_ANYCRLF: - case PCRE2_NEWLINE_NUL: - ccontext->newline_convention = newline; - return 0; - - default: - return PCRE2_ERROR_BADDATA; - } -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_max_varlookbehind(pcre2_compile_context *ccontext, uint32_t limit) -{ -ccontext->max_varlookbehind = limit; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_parens_nest_limit(pcre2_compile_context *ccontext, uint32_t limit) -{ -ccontext->parens_nest_limit = limit; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_compile_extra_options(pcre2_compile_context *ccontext, uint32_t options) -{ -ccontext->extra_options = options; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_compile_recursion_guard(pcre2_compile_context *ccontext, - int (*guard)(uint32_t, void *), void *user_data) -{ -ccontext->stack_guard = guard; -ccontext->stack_guard_data = user_data; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_optimize(pcre2_compile_context *ccontext, uint32_t directive) -{ -if (ccontext == NULL) - return PCRE2_ERROR_NULL; - -switch (directive) - { - case PCRE2_OPTIMIZATION_NONE: - ccontext->optimization_flags = 0; - break; - - case PCRE2_OPTIMIZATION_FULL: - ccontext->optimization_flags = PCRE2_OPTIMIZATION_ALL; - break; - - default: - if (directive >= PCRE2_AUTO_POSSESS && directive <= PCRE2_START_OPTIMIZE_OFF) - { - /* Even directive numbers starting from 64 switch a bit on; - * Odd directive numbers starting from 65 switch a bit off */ - if ((directive & 1) != 0) - ccontext->optimization_flags &= ~(1u << ((directive >> 1) - 32)); - else - ccontext->optimization_flags |= 1u << ((directive >> 1) - 32); - return 0; - } - return PCRE2_ERROR_BADOPTION; - } - -return 0; -} - -/* ------------ Match context ------------ */ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_callout(pcre2_match_context *mcontext, - int (*callout)(pcre2_callout_block *, void *), void *callout_data) -{ -mcontext->callout = callout; -mcontext->callout_data = callout_data; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_substitute_callout(pcre2_match_context *mcontext, - int (*substitute_callout)(pcre2_substitute_callout_block *, void *), - void *substitute_callout_data) -{ -mcontext->substitute_callout = substitute_callout; -mcontext->substitute_callout_data = substitute_callout_data; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_substitute_case_callout(pcre2_match_context *mcontext, - PCRE2_SIZE (*substitute_case_callout)(PCRE2_SPTR, PCRE2_SIZE, PCRE2_UCHAR *, - PCRE2_SIZE, int, void *), - void *substitute_case_callout_data) -{ -mcontext->substitute_case_callout = substitute_case_callout; -mcontext->substitute_case_callout_data = substitute_case_callout_data; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_heap_limit(pcre2_match_context *mcontext, uint32_t limit) -{ -mcontext->heap_limit = limit; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_match_limit(pcre2_match_context *mcontext, uint32_t limit) -{ -mcontext->match_limit = limit; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_depth_limit(pcre2_match_context *mcontext, uint32_t limit) -{ -mcontext->depth_limit = limit; -return 0; -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_offset_limit(pcre2_match_context *mcontext, PCRE2_SIZE limit) -{ -mcontext->offset_limit = limit; -return 0; -} - -/* These functions became obsolete at release 10.30. The first is kept as a -synonym for backwards compatibility. The second now does nothing. */ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_recursion_limit(pcre2_match_context *mcontext, uint32_t limit) -{ -return pcre2_set_depth_limit(mcontext, limit); -} - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_recursion_memory_management(pcre2_match_context *mcontext, - void *(*mymalloc)(size_t, void *), void (*myfree)(void *, void *), - void *mydata) -{ -(void)mcontext; -(void)mymalloc; -(void)myfree; -(void)mydata; -return 0; -} - - -/* ------------ Convert context ------------ */ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_glob_separator(pcre2_convert_context *ccontext, uint32_t separator) -{ -if (separator != CHAR_SLASH && separator != CHAR_BACKSLASH && - separator != CHAR_DOT) return PCRE2_ERROR_BADDATA; -ccontext->glob_separator = separator; -return 0; -} - -static const char *globpunct = - STR_EXCLAMATION_MARK STR_QUOTATION_MARK STR_NUMBER_SIGN STR_DOLLAR_SIGN - STR_PERCENT_SIGN STR_AMPERSAND STR_APOSTROPHE STR_LEFT_PARENTHESIS - STR_RIGHT_PARENTHESIS STR_ASTERISK STR_PLUS STR_COMMA STR_MINUS STR_DOT - STR_SLASH STR_COLON STR_SEMICOLON STR_LESS_THAN_SIGN STR_EQUALS_SIGN - STR_GREATER_THAN_SIGN STR_QUESTION_MARK STR_COMMERCIAL_AT - STR_LEFT_SQUARE_BRACKET STR_BACKSLASH STR_RIGHT_SQUARE_BRACKET - STR_CIRCUMFLEX_ACCENT STR_UNDERSCORE STR_GRAVE_ACCENT STR_LEFT_CURLY_BRACKET - STR_VERTICAL_LINE STR_RIGHT_CURLY_BRACKET STR_TILDE; - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_set_glob_escape(pcre2_convert_context *ccontext, uint32_t escape) -{ -if (escape > 255 || (escape != 0 && strchr(globpunct, escape) == NULL)) - return PCRE2_ERROR_BADDATA; -ccontext->glob_escape = escape; -return 0; -} - -/* End of pcre2_context.c */ - diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_convert.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_convert.c deleted file mode 100644 index 4287736..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_convert.c +++ /dev/null @@ -1,1263 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -#define TYPE_OPTIONS (PCRE2_CONVERT_GLOB| \ - PCRE2_CONVERT_POSIX_BASIC|PCRE2_CONVERT_POSIX_EXTENDED) - -#define ALL_OPTIONS (PCRE2_CONVERT_UTF|PCRE2_CONVERT_NO_UTF_CHECK| \ - PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR| \ - PCRE2_CONVERT_GLOB_NO_STARSTAR| \ - TYPE_OPTIONS) - -#define DUMMY_BUFFER_SIZE 100 - -/* Generated pattern fragments */ - -#define STR_BACKSLASH_A STR_BACKSLASH STR_A -#define STR_BACKSLASH_z STR_BACKSLASH STR_z -#define STR_COLON_RIGHT_SQUARE_BRACKET STR_COLON STR_RIGHT_SQUARE_BRACKET -#define STR_DOT_STAR_LOOKBEHIND STR_DOT STR_ASTERISK STR_LEFT_PARENTHESIS STR_QUESTION_MARK STR_LESS_THAN_SIGN STR_EQUALS_SIGN -#define STR_LOOKAHEAD_NOT_DOT STR_LEFT_PARENTHESIS STR_QUESTION_MARK STR_EXCLAMATION_MARK STR_BACKSLASH STR_DOT STR_RIGHT_PARENTHESIS -#define STR_QUERY_s STR_LEFT_PARENTHESIS STR_QUESTION_MARK STR_s STR_RIGHT_PARENTHESIS -#define STR_STAR_NUL STR_LEFT_PARENTHESIS STR_ASTERISK STR_N STR_U STR_L STR_RIGHT_PARENTHESIS - -/* States for POSIX processing */ - -enum { POSIX_START_REGEX, POSIX_ANCHORED, POSIX_NOT_BRACKET, - POSIX_CLASS_NOT_STARTED, POSIX_CLASS_STARTING, POSIX_CLASS_STARTED }; - -/* Macro to add a character string to the output buffer, checking for overflow. */ - -#define PUTCHARS(string) \ - { \ - const char *s; \ - for (s = string; *s != 0; s++) \ - { \ - if (p >= endp) return PCRE2_ERROR_NOMEMORY; \ - *p++ = *s; \ - } \ - } - -/* Macro to check for lowercase characters. */ - -#ifdef EBCDIC -#define ISLOWER(c) (((c) >= CHAR_a && (c) <= CHAR_i) || \ - ((c) >= CHAR_j && (c) <= CHAR_r) || \ - ((c) >= CHAR_s && (c) <= CHAR_z)) -#else -#define ISLOWER(c) ((c) >= CHAR_a && (c) <= CHAR_z) -#endif - -/* Literals that must be escaped: \ ? * + | . ^ $ { } [ ] ( ) */ - -static const char *pcre2_escaped_literals = - STR_BACKSLASH STR_QUESTION_MARK STR_ASTERISK STR_PLUS - STR_VERTICAL_LINE STR_DOT STR_CIRCUMFLEX_ACCENT STR_DOLLAR_SIGN - STR_LEFT_CURLY_BRACKET STR_RIGHT_CURLY_BRACKET - STR_LEFT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET - STR_LEFT_PARENTHESIS STR_RIGHT_PARENTHESIS; - -/* Recognized escaped metacharacters in POSIX basic patterns. */ - -static const char *posix_meta_escapes = - STR_LEFT_PARENTHESIS STR_RIGHT_PARENTHESIS - STR_LEFT_CURLY_BRACKET STR_RIGHT_CURLY_BRACKET - STR_1 STR_2 STR_3 STR_4 STR_5 STR_6 STR_7 STR_8 STR_9; - -/* Recognized POSIX classes, colon-separated. */ - -static const char *posix_classes = - STR_a STR_l STR_p STR_h STR_a STR_COLON - STR_l STR_o STR_w STR_e STR_r STR_COLON - STR_u STR_p STR_p STR_e STR_r STR_COLON - STR_a STR_l STR_n STR_u STR_m STR_COLON - STR_a STR_s STR_c STR_i STR_i STR_COLON - STR_b STR_l STR_a STR_n STR_k STR_COLON - STR_c STR_n STR_t STR_r STR_l STR_COLON - STR_d STR_i STR_g STR_i STR_t STR_COLON - STR_g STR_r STR_a STR_p STR_h STR_COLON - STR_p STR_r STR_i STR_n STR_t STR_COLON - STR_p STR_u STR_n STR_c STR_t STR_COLON - STR_s STR_p STR_a STR_c STR_e STR_COLON - STR_w STR_o STR_r STR_d STR_COLON - STR_x STR_d STR_i STR_g STR_i STR_t STR_COLON; - - - -/************************************************* -* Convert a POSIX pattern * -*************************************************/ - -/* This function handles both basic and extended POSIX patterns. - -Arguments: - pattype the pattern type - pattern the pattern - plength length in code units - utf TRUE if UTF - use_buffer where to put the output - use_length length of use_buffer - bufflenptr where to put the used length - dummyrun TRUE if a dummy run - ccontext the convert context - -Returns: 0 => success - !0 => error code -*/ - -static int -convert_posix(uint32_t pattype, PCRE2_SPTR pattern, PCRE2_SIZE plength, - BOOL utf, PCRE2_UCHAR *use_buffer, PCRE2_SIZE use_length, - PCRE2_SIZE *bufflenptr, BOOL dummyrun, pcre2_convert_context *ccontext) -{ -PCRE2_SPTR posix = pattern; -PCRE2_UCHAR *p = use_buffer; -PCRE2_UCHAR *pp = p; -PCRE2_UCHAR *endp = p + use_length - 1; /* Allow for trailing zero */ -PCRE2_SIZE convlength = 0; - -uint32_t bracount = 0; -uint32_t posix_state = POSIX_START_REGEX; -uint32_t lastspecial = 0; -BOOL extended = (pattype & PCRE2_CONVERT_POSIX_EXTENDED) != 0; -BOOL nextisliteral = FALSE; - -(void)utf; /* Not used when Unicode not supported */ -(void)ccontext; /* Not currently used */ - -/* Initialize default for error offset as end of input. */ - -*bufflenptr = plength; -PUTCHARS(STR_STAR_NUL); - -/* Now scan the input. */ - -while (plength > 0) - { - uint32_t c, sc; - int clength = 1; - - /* Add in the length of the last item, then, if in the dummy run, pull the - pointer back to the start of the (temporary) buffer and then remember the - start of the next item. */ - - convlength += p - pp; - if (dummyrun) p = use_buffer; - pp = p; - - /* Pick up the next character */ - -#ifndef SUPPORT_UNICODE - c = *posix; -#else - GETCHARLENTEST(c, posix, clength); -#endif - posix += clength; - plength -= clength; - - sc = nextisliteral? 0 : c; - nextisliteral = FALSE; - - /* Handle a character within a class. */ - - if (posix_state >= POSIX_CLASS_NOT_STARTED) - { - if (c == CHAR_RIGHT_SQUARE_BRACKET) - { - PUTCHARS(STR_RIGHT_SQUARE_BRACKET); - posix_state = POSIX_NOT_BRACKET; - } - - /* Not the end of the class */ - - else - { - switch (posix_state) - { - case POSIX_CLASS_STARTED: - if (ISLOWER(c)) break; /* Remain in started state */ - posix_state = POSIX_CLASS_NOT_STARTED; - if (c == CHAR_COLON && plength > 0 && - *posix == CHAR_RIGHT_SQUARE_BRACKET) - { - PUTCHARS(STR_COLON_RIGHT_SQUARE_BRACKET); - plength--; - posix++; - continue; /* With next character after :] */ - } - PCRE2_FALLTHROUGH /* Fall through */ - - case POSIX_CLASS_NOT_STARTED: - if (c == CHAR_LEFT_SQUARE_BRACKET) - posix_state = POSIX_CLASS_STARTING; - break; - - case POSIX_CLASS_STARTING: - if (c == CHAR_COLON) posix_state = POSIX_CLASS_STARTED; - break; - } - - if (c == CHAR_BACKSLASH) PUTCHARS(STR_BACKSLASH); - if (p + clength > endp) return PCRE2_ERROR_NOMEMORY; - memcpy(p, posix - clength, CU2BYTES(clength)); - p += clength; - } - } - - /* Handle a character not within a class. */ - - else switch(sc) - { - case CHAR_LEFT_SQUARE_BRACKET: - PUTCHARS(STR_LEFT_SQUARE_BRACKET); - -#ifdef NEVER - /* We could handle special cases [[:<:]] and [[:>:]] (which PCRE does - support) but they are not part of POSIX 1003.1. */ - - if (plength >= 6) - { - if (posix[0] == CHAR_LEFT_SQUARE_BRACKET && - posix[1] == CHAR_COLON && - (posix[2] == CHAR_LESS_THAN_SIGN || - posix[2] == CHAR_GREATER_THAN_SIGN) && - posix[3] == CHAR_COLON && - posix[4] == CHAR_RIGHT_SQUARE_BRACKET && - posix[5] == CHAR_RIGHT_SQUARE_BRACKET) - { - if (p + 6 > endp) return PCRE2_ERROR_NOMEMORY; - memcpy(p, posix, CU2BYTES(6)); - p += 6; - posix += 6; - plength -= 6; - continue; /* With next character */ - } - } -#endif - - /* Handle start of "normal" character classes */ - - posix_state = POSIX_CLASS_NOT_STARTED; - - /* Handle ^ and ] as first characters */ - - if (plength > 0) - { - if (*posix == CHAR_CIRCUMFLEX_ACCENT) - { - posix++; - plength--; - PUTCHARS(STR_CIRCUMFLEX_ACCENT); - } - if (plength > 0 && *posix == CHAR_RIGHT_SQUARE_BRACKET) - { - posix++; - plength--; - PUTCHARS(STR_RIGHT_SQUARE_BRACKET); - } - } - break; - - case CHAR_BACKSLASH: - if (plength == 0) return PCRE2_ERROR_END_BACKSLASH; - if (extended) nextisliteral = TRUE; else - { - if (*posix < 255 && strchr(posix_meta_escapes, *posix) != NULL) - { - if (*posix >= CHAR_0 && *posix <= CHAR_9) PUTCHARS(STR_BACKSLASH); - if (p + 1 > endp) return PCRE2_ERROR_NOMEMORY; - lastspecial = *p++ = *posix++; - plength--; - } - else nextisliteral = TRUE; - } - break; - - case CHAR_RIGHT_PARENTHESIS: - if (!extended || bracount == 0) goto ESCAPE_LITERAL; - bracount--; - goto COPY_SPECIAL; - - case CHAR_LEFT_PARENTHESIS: - bracount++; - PCRE2_FALLTHROUGH /* Fall through */ - - case CHAR_QUESTION_MARK: - case CHAR_PLUS: - case CHAR_LEFT_CURLY_BRACKET: - case CHAR_RIGHT_CURLY_BRACKET: - case CHAR_VERTICAL_LINE: - if (!extended) goto ESCAPE_LITERAL; - PCRE2_FALLTHROUGH /* Fall through */ - - case CHAR_DOT: - case CHAR_DOLLAR_SIGN: - posix_state = POSIX_NOT_BRACKET; - COPY_SPECIAL: - lastspecial = c; - if (p + 1 > endp) return PCRE2_ERROR_NOMEMORY; - *p++ = c; - break; - - case CHAR_ASTERISK: - if (lastspecial != CHAR_ASTERISK) - { - if (!extended && (posix_state < POSIX_NOT_BRACKET || - lastspecial == CHAR_LEFT_PARENTHESIS)) - goto ESCAPE_LITERAL; - goto COPY_SPECIAL; - } - break; /* Ignore second and subsequent asterisks */ - - case CHAR_CIRCUMFLEX_ACCENT: - if (extended) goto COPY_SPECIAL; - if (posix_state == POSIX_START_REGEX || - lastspecial == CHAR_LEFT_PARENTHESIS) - { - posix_state = POSIX_ANCHORED; - goto COPY_SPECIAL; - } - PCRE2_FALLTHROUGH /* Fall through */ - - default: - if (c < 255 && strchr(pcre2_escaped_literals, c) != NULL) - { - ESCAPE_LITERAL: - PUTCHARS(STR_BACKSLASH); - } - lastspecial = 0xff; /* Indicates nothing special */ - if (p + clength > endp) return PCRE2_ERROR_NOMEMORY; - memcpy(p, posix - clength, CU2BYTES(clength)); - p += clength; - posix_state = POSIX_NOT_BRACKET; - break; - } - } - -if (posix_state >= POSIX_CLASS_NOT_STARTED) - return PCRE2_ERROR_MISSING_SQUARE_BRACKET; -convlength += p - pp; /* Final segment */ -*bufflenptr = convlength; -*p++ = 0; -return 0; -} - - -/************************************************* -* Convert a glob pattern * -*************************************************/ - -/* Context for writing the output into a buffer. */ - -typedef struct pcre2_output_context { - PCRE2_UCHAR *output; /* current output position */ - PCRE2_SPTR output_end; /* output end */ - PCRE2_SIZE output_size; /* size of the output */ - uint8_t out_str[8]; /* string copied to the output */ -} pcre2_output_context; - - -/* Write a character into the output. - -Arguments: - out output context - chr the next character -*/ - -static void -convert_glob_write(pcre2_output_context *out, PCRE2_UCHAR chr) -{ -out->output_size++; - -if (out->output < out->output_end) - *out->output++ = chr; -} - - -/* Write a string into the output. - -Arguments: - out output context - length length of out->out_str -*/ - -static void -convert_glob_write_str(pcre2_output_context *out, PCRE2_SIZE length) -{ -uint8_t *out_str = out->out_str; -PCRE2_UCHAR *output = out->output; -PCRE2_SPTR output_end = out->output_end; -PCRE2_SIZE output_size = out->output_size; - -do - { - output_size++; - - if (output < output_end) - *output++ = *out_str++; - } -while (--length != 0); - -out->output = output; -out->output_size = output_size; -} - - -/* Prints the separator into the output. - -Arguments: - out output context - separator glob separator - with_escape backslash is needed before separator -*/ - -static void -convert_glob_print_separator(pcre2_output_context *out, - PCRE2_UCHAR separator, BOOL with_escape) -{ -if (with_escape) - convert_glob_write(out, CHAR_BACKSLASH); - -convert_glob_write(out, separator); -} - - -/* Prints a wildcard into the output. - -Arguments: - out output context - separator glob separator - with_escape backslash is needed before separator -*/ - -static void -convert_glob_print_wildcard(pcre2_output_context *out, - PCRE2_UCHAR separator, BOOL with_escape) -{ -out->out_str[0] = CHAR_LEFT_SQUARE_BRACKET; -out->out_str[1] = CHAR_CIRCUMFLEX_ACCENT; -convert_glob_write_str(out, 2); - -convert_glob_print_separator(out, separator, with_escape); - -convert_glob_write(out, CHAR_RIGHT_SQUARE_BRACKET); -} - - -/* Parse a posix class. - -Arguments: - from starting point of scanning the range - pattern_end end of pattern - out output context - -Returns: >0 => class index - 0 => malformed class -*/ - -static int -convert_glob_parse_class(PCRE2_SPTR *from, PCRE2_SPTR pattern_end, - pcre2_output_context *out) -{ -PCRE2_SPTR start = *from + 1; -PCRE2_SPTR pattern = start; -const char *class_ptr; -PCRE2_UCHAR c; -int class_index; - -while (TRUE) - { - if (pattern >= pattern_end) return 0; - - c = *pattern++; - - if (c < CHAR_a || c > CHAR_z) break; - } - -if (c != CHAR_COLON || pattern >= pattern_end || - *pattern != CHAR_RIGHT_SQUARE_BRACKET) - return 0; - -class_ptr = posix_classes; -class_index = 1; - -while (TRUE) - { - if (*class_ptr == 0) return 0; - - pattern = start; - - while (*pattern == (PCRE2_UCHAR) *class_ptr) - { - if (*pattern == CHAR_COLON) - { - pattern += 2; - start -= 2; - - do convert_glob_write(out, *start++); while (start < pattern); - - *from = pattern; - return class_index; - } - pattern++; - class_ptr++; - } - - while (*class_ptr != CHAR_COLON) class_ptr++; - class_ptr++; - class_index++; - } -} - -/* Checks whether the character is in the class. - -Arguments: - class_index class index - c character - -Returns: !0 => character is found in the class - 0 => otherwise -*/ - -static BOOL -convert_glob_char_in_class(int class_index, PCRE2_UCHAR c) -{ -const uint8_t *cbits = PRIV(default_tables) + cbits_offset; -int cbit; - -#if PCRE2_CODE_UNIT_WIDTH != 8 -if (c > 0xff) - { - /* Can't access the character tables for c > 0xff */ - return FALSE; - } -#endif - -/* See posix_class_maps. This is a small local clone of that. -Note that we don't know exactly what character tables will be used at -match time, but, for the purposes of pattern conversion, it should be -sufficient to use PCRE2's built-in default tables. */ - -switch (class_index) - { - case 1: /* alpha */ - if (c == CHAR_UNDERSCORE) return FALSE; - if (((cbits + cbit_digit)[c/8] & (1u << (c&7))) != 0) return FALSE; - cbit = cbit_word; - break; - - case 2: cbit = cbit_lower; break; /* lower */ - case 3: cbit = cbit_upper; break; /* upper */ - - case 4: /* alnum */ - if (c == CHAR_UNDERSCORE) return FALSE; - cbit = cbit_word; - break; - - case 5: /* ascii */ - if (((cbits + cbit_cntrl)[c/8] & (1u << (c&7))) != 0) return TRUE; - cbit = cbit_print; - break; - - case 6: /* blank */ - if (c == CHAR_LF || c == CHAR_VT || c == CHAR_FF || c == CHAR_CR) - return FALSE; - cbit = cbit_space; - break; - - case 7: cbit = cbit_cntrl; break; /* cntrl */ - case 8: cbit = cbit_digit; break; /* digit */ - case 9: cbit = cbit_graph; break; /* graph */ - case 10: cbit = cbit_print; break; /* print */ - case 11: cbit = cbit_punct; break; /* punct */ - case 12: cbit = cbit_space; break; /* space */ - case 13: cbit = cbit_word; break; /* word */ - case 14: cbit = cbit_xdigit; break; /* xdigit */ - default: return FALSE; - } - -return ((cbits + cbit)[c/8] & (1u << (c&7))) != 0; -} - -/* Parse a range of characters. - -Arguments: - from starting point of scanning the range - pattern_end end of pattern - out output context - separator glob separator - with_escape backslash is needed before separator - -Returns: 0 => success - !0 => error code -*/ - -static int -convert_glob_parse_range(PCRE2_SPTR *from, PCRE2_SPTR pattern_end, - pcre2_output_context *out, BOOL utf, PCRE2_UCHAR separator, - BOOL with_escape, PCRE2_UCHAR escape, BOOL no_wildsep) -{ -BOOL is_negative = FALSE; -BOOL separator_seen = FALSE; -BOOL has_prev_c; -PCRE2_SPTR pattern = *from; -PCRE2_SPTR char_start = NULL; -uint32_t c, prev_c; -int len, class_index; - -(void)utf; /* Avoid compiler warning. */ - -if (pattern >= pattern_end) - { - *from = pattern; - return PCRE2_ERROR_MISSING_SQUARE_BRACKET; - } - -if (*pattern == CHAR_EXCLAMATION_MARK - || *pattern == CHAR_CIRCUMFLEX_ACCENT) - { - pattern++; - - if (pattern >= pattern_end) - { - *from = pattern; - return PCRE2_ERROR_MISSING_SQUARE_BRACKET; - } - - is_negative = TRUE; - - out->out_str[0] = CHAR_LEFT_SQUARE_BRACKET; - out->out_str[1] = CHAR_CIRCUMFLEX_ACCENT; - len = 2; - - if (!no_wildsep) - { - if (with_escape) - { - out->out_str[len] = CHAR_BACKSLASH; - len++; - } - out->out_str[len] = (uint8_t) separator; - } - - convert_glob_write_str(out, len + 1); - } -else - convert_glob_write(out, CHAR_LEFT_SQUARE_BRACKET); - -has_prev_c = FALSE; -prev_c = 0; - -if (*pattern == CHAR_RIGHT_SQUARE_BRACKET) - { - out->out_str[0] = CHAR_BACKSLASH; - out->out_str[1] = CHAR_RIGHT_SQUARE_BRACKET; - convert_glob_write_str(out, 2); - has_prev_c = TRUE; - prev_c = CHAR_RIGHT_SQUARE_BRACKET; - pattern++; - } - -while (pattern < pattern_end) - { - char_start = pattern; - GETCHARINCTEST(c, pattern); - - if (c == CHAR_RIGHT_SQUARE_BRACKET) - { - convert_glob_write(out, c); - - if (!is_negative && !no_wildsep && separator_seen) - { - out->out_str[0] = CHAR_LEFT_PARENTHESIS; - out->out_str[1] = CHAR_QUESTION_MARK; - out->out_str[2] = CHAR_LESS_THAN_SIGN; - out->out_str[3] = CHAR_EXCLAMATION_MARK; - convert_glob_write_str(out, 4); - - convert_glob_print_separator(out, separator, with_escape); - convert_glob_write(out, CHAR_RIGHT_PARENTHESIS); - } - - *from = pattern; - return 0; - } - - if (pattern >= pattern_end) break; - - if (c == CHAR_LEFT_SQUARE_BRACKET && *pattern == CHAR_COLON) - { - *from = pattern; - class_index = convert_glob_parse_class(from, pattern_end, out); - - if (class_index != 0) - { - pattern = *from; - - has_prev_c = FALSE; - prev_c = 0; - - if (!is_negative && - convert_glob_char_in_class (class_index, separator)) - separator_seen = TRUE; - continue; - } - } - else if (c == CHAR_MINUS && has_prev_c && - *pattern != CHAR_RIGHT_SQUARE_BRACKET) - { - convert_glob_write(out, CHAR_MINUS); - - char_start = pattern; - GETCHARINCTEST(c, pattern); - - if (pattern >= pattern_end) break; - - if (escape != 0 && c == escape) - { - char_start = pattern; - GETCHARINCTEST(c, pattern); - } - else if (c == CHAR_LEFT_SQUARE_BRACKET && *pattern == CHAR_COLON) - { - *from = pattern; - return PCRE2_ERROR_CONVERT_SYNTAX; - } - - if (prev_c > c) - { - *from = pattern; - return PCRE2_ERROR_CONVERT_SYNTAX; - } - - if (prev_c < separator && separator < c) separator_seen = TRUE; - - has_prev_c = FALSE; - prev_c = 0; - } - else - { - if (escape != 0 && c == escape) - { - char_start = pattern; - GETCHARINCTEST(c, pattern); - - if (pattern >= pattern_end) break; - } - - has_prev_c = TRUE; - prev_c = c; - } - - if (c == CHAR_LEFT_SQUARE_BRACKET || c == CHAR_RIGHT_SQUARE_BRACKET || - c == CHAR_BACKSLASH || c == CHAR_MINUS) - convert_glob_write(out, CHAR_BACKSLASH); - - if (c == separator) separator_seen = TRUE; - - do convert_glob_write(out, *char_start++); while (char_start < pattern); - } - -*from = pattern; -return PCRE2_ERROR_MISSING_SQUARE_BRACKET; -} - - -/* Prints a (*COMMIT) into the output. - -Arguments: - out output context -*/ - -static void -convert_glob_print_commit(pcre2_output_context *out) -{ -out->out_str[0] = CHAR_LEFT_PARENTHESIS; -out->out_str[1] = CHAR_ASTERISK; -out->out_str[2] = CHAR_C; -out->out_str[3] = CHAR_O; -out->out_str[4] = CHAR_M; -out->out_str[5] = CHAR_M; -out->out_str[6] = CHAR_I; -out->out_str[7] = CHAR_T; -convert_glob_write_str(out, 8); -convert_glob_write(out, CHAR_RIGHT_PARENTHESIS); -} - - -/* Bash glob converter. - -Arguments: - pattype the pattern type - pattern the pattern - plength length in code units - utf TRUE if UTF - use_buffer where to put the output - use_length length of use_buffer - bufflenptr where to put the used length - dummyrun TRUE if a dummy run - ccontext the convert context - -Returns: 0 => success - !0 => error code -*/ - -static int -convert_glob(uint32_t options, PCRE2_SPTR pattern, PCRE2_SIZE plength, - BOOL utf, PCRE2_UCHAR *use_buffer, PCRE2_SIZE use_length, - PCRE2_SIZE *bufflenptr, BOOL dummyrun, pcre2_convert_context *ccontext) -{ -pcre2_output_context out; -PCRE2_SPTR pattern_start = pattern; -PCRE2_SPTR pattern_end = pattern + plength; -PCRE2_UCHAR separator = ccontext->glob_separator; -PCRE2_UCHAR escape = ccontext->glob_escape; -PCRE2_UCHAR c; -BOOL no_wildsep = (options & PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR) != 0; -BOOL no_starstar = (options & PCRE2_CONVERT_GLOB_NO_STARSTAR) != 0; -BOOL in_atomic = FALSE; -BOOL after_starstar = FALSE; -BOOL no_slash_z = FALSE; -BOOL with_escape, is_start, after_separator; -int result = 0; - -(void)utf; /* Avoid compiler warning. */ - -#ifdef SUPPORT_UNICODE -if (utf && (separator >= 128 || escape >= 128)) - { - /* Currently only ASCII characters are supported. */ - *bufflenptr = 0; - return PCRE2_ERROR_CONVERT_SYNTAX; - } -#endif - -with_escape = strchr(pcre2_escaped_literals, separator) != NULL; - -/* Initialize default for error offset as end of input. */ -out.output = use_buffer; -out.output_end = use_buffer + use_length; -out.output_size = 0; - -out.out_str[0] = CHAR_LEFT_PARENTHESIS; -out.out_str[1] = CHAR_QUESTION_MARK; -out.out_str[2] = CHAR_s; -out.out_str[3] = CHAR_RIGHT_PARENTHESIS; -convert_glob_write_str(&out, 4); - -is_start = TRUE; - -if (pattern < pattern_end && pattern[0] == CHAR_ASTERISK) - { - if (no_wildsep) - is_start = FALSE; - else if (!no_starstar && pattern + 1 < pattern_end && - pattern[1] == CHAR_ASTERISK) - is_start = FALSE; - } - -if (is_start) - { - out.out_str[0] = CHAR_BACKSLASH; - out.out_str[1] = CHAR_A; - convert_glob_write_str(&out, 2); - } - -while (pattern < pattern_end) - { - c = *pattern++; - - if (c == CHAR_ASTERISK) - { - is_start = pattern == pattern_start + 1; - - if (in_atomic) - { - convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS); - in_atomic = FALSE; - } - - if (!no_starstar && pattern < pattern_end && *pattern == CHAR_ASTERISK) - { - after_separator = is_start || (pattern[-2] == separator); - - do pattern++; while (pattern < pattern_end && - *pattern == CHAR_ASTERISK); - - if (pattern >= pattern_end) - { - no_slash_z = TRUE; - break; - } - - after_starstar = TRUE; - - if (after_separator && escape != 0 && *pattern == escape && - pattern + 1 < pattern_end && pattern[1] == separator) - pattern++; - - if (is_start) - { - if (*pattern != separator) continue; - - out.out_str[0] = CHAR_LEFT_PARENTHESIS; - out.out_str[1] = CHAR_QUESTION_MARK; - out.out_str[2] = CHAR_COLON; - out.out_str[3] = CHAR_BACKSLASH; - out.out_str[4] = CHAR_A; - out.out_str[5] = CHAR_VERTICAL_LINE; - convert_glob_write_str(&out, 6); - - convert_glob_print_separator(&out, separator, with_escape); - convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS); - - pattern++; - continue; - } - - convert_glob_print_commit(&out); - - if (!after_separator || *pattern != separator) - { - out.out_str[0] = CHAR_DOT; - out.out_str[1] = CHAR_ASTERISK; - out.out_str[2] = CHAR_QUESTION_MARK; - convert_glob_write_str(&out, 3); - continue; - } - - out.out_str[0] = CHAR_LEFT_PARENTHESIS; - out.out_str[1] = CHAR_QUESTION_MARK; - out.out_str[2] = CHAR_COLON; - out.out_str[3] = CHAR_DOT; - out.out_str[4] = CHAR_ASTERISK; - out.out_str[5] = CHAR_QUESTION_MARK; - - convert_glob_write_str(&out, 6); - - convert_glob_print_separator(&out, separator, with_escape); - - out.out_str[0] = CHAR_RIGHT_PARENTHESIS; - out.out_str[1] = CHAR_QUESTION_MARK; - out.out_str[2] = CHAR_QUESTION_MARK; - convert_glob_write_str(&out, 3); - - pattern++; - continue; - } - - if (pattern < pattern_end && *pattern == CHAR_ASTERISK) - { - do pattern++; while (pattern < pattern_end && - *pattern == CHAR_ASTERISK); - } - - if (no_wildsep) - { - if (pattern >= pattern_end) - { - no_slash_z = TRUE; - break; - } - - /* Start check must be after the end check. */ - if (is_start) continue; - } - - if (!is_start) - { - if (after_starstar) - { - out.out_str[0] = CHAR_LEFT_PARENTHESIS; - out.out_str[1] = CHAR_QUESTION_MARK; - out.out_str[2] = CHAR_GREATER_THAN_SIGN; - convert_glob_write_str(&out, 3); - in_atomic = TRUE; - } - else - convert_glob_print_commit(&out); - } - - if (no_wildsep) - convert_glob_write(&out, CHAR_DOT); - else - convert_glob_print_wildcard(&out, separator, with_escape); - - out.out_str[0] = CHAR_ASTERISK; - out.out_str[1] = CHAR_QUESTION_MARK; - if (pattern >= pattern_end) - out.out_str[1] = CHAR_PLUS; - convert_glob_write_str(&out, 2); - continue; - } - - if (c == CHAR_QUESTION_MARK) - { - if (no_wildsep) - convert_glob_write(&out, CHAR_DOT); - else - convert_glob_print_wildcard(&out, separator, with_escape); - continue; - } - - if (c == CHAR_LEFT_SQUARE_BRACKET) - { - result = convert_glob_parse_range(&pattern, pattern_end, - &out, utf, separator, with_escape, escape, no_wildsep); - if (result != 0) break; - continue; - } - - if (escape != 0 && c == escape) - { - if (pattern >= pattern_end) - { - result = PCRE2_ERROR_CONVERT_SYNTAX; - break; - } - c = *pattern++; - } - - if (c < 255 && strchr(pcre2_escaped_literals, c) != NULL) - convert_glob_write(&out, CHAR_BACKSLASH); - - convert_glob_write(&out, c); - } - -if (result == 0) - { - if (!no_slash_z) - { - out.out_str[0] = CHAR_BACKSLASH; - out.out_str[1] = CHAR_z; - convert_glob_write_str(&out, 2); - } - - if (in_atomic) - convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS); - - convert_glob_write(&out, CHAR_NUL); - - if (!dummyrun && out.output_size != (PCRE2_SIZE) (out.output - use_buffer)) - result = PCRE2_ERROR_NOMEMORY; - } - -if (result != 0) - { - *bufflenptr = pattern - pattern_start; - return result; - } - -*bufflenptr = out.output_size - 1; -return 0; -} - - -/************************************************* -* Convert pattern * -*************************************************/ - -/* This is the external-facing function for converting other forms of pattern -into PCRE2 regular expression patterns. On error, the bufflenptr argument is -used to return an offset in the original pattern. - -Arguments: - pattern the input pattern - plength length of input, or PCRE2_ZERO_TERMINATED - options options bits - buffptr pointer to pointer to output buffer - bufflenptr pointer to length of output buffer - ccontext convert context or NULL - -Returns: 0 for success, else an error code (+ve or -ve) -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_pattern_convert(PCRE2_SPTR pattern, PCRE2_SIZE plength, uint32_t options, - PCRE2_UCHAR **buffptr, PCRE2_SIZE *bufflenptr, - pcre2_convert_context *ccontext) -{ -int rc; -PCRE2_UCHAR null_str[1] = { 0xcd }; -PCRE2_UCHAR dummy_buffer[DUMMY_BUFFER_SIZE]; -PCRE2_UCHAR *use_buffer = dummy_buffer; -PCRE2_SIZE use_length = DUMMY_BUFFER_SIZE; -BOOL utf = (options & PCRE2_CONVERT_UTF) != 0; -uint32_t pattype = options & TYPE_OPTIONS; -int i; - -if (pattern == NULL && plength == 0) - pattern = null_str; - -if (pattern == NULL || bufflenptr == NULL) - { - if (bufflenptr != NULL) *bufflenptr = 0; /* Error offset */ - return PCRE2_ERROR_NULL; - } - -if ((options & ~ALL_OPTIONS) != 0 || /* Undefined bit set */ - (pattype & (~pattype+1)) != pattype || /* More than one type set */ - pattype == 0) /* No type set */ - { - *bufflenptr = 0; /* Error offset */ - return PCRE2_ERROR_BADOPTION; - } - -if (plength == PCRE2_ZERO_TERMINATED) plength = PRIV(strlen)(pattern); -if (ccontext == NULL) ccontext = - (pcre2_convert_context *)(&PRIV(default_convert_context)); - -/* Check UTF if required. */ - -#ifndef SUPPORT_UNICODE -if (utf) - { - *bufflenptr = 0; /* Error offset */ - return PCRE2_ERROR_UNICODE_NOT_SUPPORTED; - } -#else -if (utf && (options & PCRE2_CONVERT_NO_UTF_CHECK) == 0) - { - PCRE2_SIZE erroroffset; - rc = PRIV(valid_utf)(pattern, plength, &erroroffset); - if (rc != 0) - { - *bufflenptr = erroroffset; - return rc; - } - } -#endif - -/* If buffptr is not NULL, and what it points to is not NULL, we are being -provided with a buffer and a length, so set them as the buffer to use. */ - -if (buffptr != NULL && *buffptr != NULL) - { - use_buffer = *buffptr; - use_length = *bufflenptr; - } - -/* Call an individual converter, either just once (if a buffer was provided or -just the length is needed), or twice (if a memory allocation is required). */ - -for (i = 0; i < 2; i++) - { - PCRE2_UCHAR *allocated; - BOOL dummyrun = buffptr == NULL || *buffptr == NULL; - - switch(pattype) - { - case PCRE2_CONVERT_GLOB: - rc = convert_glob(options & ~PCRE2_CONVERT_GLOB, pattern, plength, utf, - use_buffer, use_length, bufflenptr, dummyrun, ccontext); - break; - - case PCRE2_CONVERT_POSIX_BASIC: - case PCRE2_CONVERT_POSIX_EXTENDED: - rc = convert_posix(pattype, pattern, plength, utf, use_buffer, use_length, - bufflenptr, dummyrun, ccontext); - break; - - /* We have already validated pattype. */ - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - *bufflenptr = 0; /* Error offset */ - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - - if (rc != 0 || /* Error */ - buffptr == NULL || /* Just the length is required */ - *buffptr != NULL) /* Buffer was provided or allocated */ - return rc; - - /* Allocate memory for the buffer, with hidden space for an allocator at - the start. The next time round the loop runs the conversion for real. */ - - allocated = PRIV(memctl_malloc)(sizeof(pcre2_memctl) + - (*bufflenptr + 1)*PCRE2_CODE_UNIT_WIDTH, (pcre2_memctl *)ccontext); - if (allocated == NULL) - { - *bufflenptr = 0; /* Error offset */ - return PCRE2_ERROR_NOMEMORY; - } - *buffptr = (PCRE2_UCHAR *)(((char *)allocated) + sizeof(pcre2_memctl)); - - use_buffer = *buffptr; - use_length = *bufflenptr + 1; - } - -/* Running the loop above ought to have succeeded the second time. */ -/* LCOV_EXCL_START */ -PCRE2_DEBUG_UNREACHABLE(); -*bufflenptr = 0; /* Error offset */ -return PCRE2_ERROR_INTERNAL; -/* LCOV_EXCL_STOP */ -} - - -/************************************************* -* Free converted pattern * -*************************************************/ - -/* This frees a converted pattern that was put in newly-allocated memory. - -Argument: the converted pattern -Returns: nothing -*/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_converted_pattern_free(PCRE2_UCHAR *converted) -{ -if (converted != NULL) - { - pcre2_memctl *memctl = - (pcre2_memctl *)((char *)converted - sizeof(pcre2_memctl)); - memctl->free(memctl, memctl->memory_data); - } -} - -/* End of pcre2_convert.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_dfa_match.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_dfa_match.c deleted file mode 100644 index a93b461..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_dfa_match.c +++ /dev/null @@ -1,4135 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains the external function pcre2_dfa_match(), which is an -alternative matching function that uses a sort of DFA algorithm (not a true -FSM). This is NOT Perl-compatible, but it has advantages in certain -applications. */ - - -/* NOTE ABOUT PERFORMANCE: A user of this function sent some code that improved -the performance of his patterns greatly. I could not use it as it stood, as it -was not thread safe, and made assumptions about pattern sizes. Also, it caused -test 7 to loop, and test 9 to crash with a segfault. - -The issue is the check for duplicate states, which is done by a simple linear -search up the state list. (Grep for "duplicate" below to find the code.) For -many patterns, there will never be many states active at one time, so a simple -linear search is fine. In patterns that have many active states, it might be a -bottleneck. The suggested code used an indexing scheme to remember which states -had previously been used for each character, and avoided the linear search when -it knew there was no chance of a duplicate. This was implemented when adding -states to the state lists. - -I wrote some thread-safe, not-limited code to try something similar at the time -of checking for duplicates (instead of when adding states), using index vectors -on the stack. It did give a 13% improvement with one specially constructed -pattern for certain subject strings, but on other strings and on many of the -simpler patterns in the test suite it did worse. The major problem, I think, -was the extra time to initialize the index. This had to be done for each call -of internal_dfa_match(). (The supplied patch used a static vector, initialized -only once - I suspect this was the cause of the problems with the tests.) - -Overall, I concluded that the gains in some cases did not outweigh the losses -in others, so I abandoned this code. */ - - -#include "pcre2_internal.h" - - - -#define NLBLOCK mb /* Block containing newline information */ -#define PSSTART start_subject /* Field containing processed string start */ -#define PSEND end_subject /* Field containing processed string end */ - -#define PUBLIC_DFA_MATCH_OPTIONS \ - (PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY| \ - PCRE2_NOTEMPTY_ATSTART|PCRE2_NO_UTF_CHECK|PCRE2_PARTIAL_HARD| \ - PCRE2_PARTIAL_SOFT|PCRE2_DFA_SHORTEST|PCRE2_DFA_RESTART| \ - PCRE2_COPY_MATCHED_SUBJECT) - - -/************************************************* -* Code parameters and static tables * -*************************************************/ - -/* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes -into others, under special conditions. A gap of 20 between the blocks should be -enough. The resulting opcodes don't have to be less than 256 because they are -never stored, so we push them well clear of the normal opcodes. */ - -#define OP_PROP_EXTRA 300 -#define OP_EXTUNI_EXTRA 320 -#define OP_ANYNL_EXTRA 340 -#define OP_HSPACE_EXTRA 360 -#define OP_VSPACE_EXTRA 380 - - -/* This table identifies those opcodes that are followed immediately by a -character that is to be tested in some way. This makes it possible to -centralize the loading of these characters. In the case of Type * etc, the -"character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a -small value. Non-zero values in the table are the offsets from the opcode where -the character is to be found. ***NOTE*** If the start of this table is -modified, the three tables that follow must also be modified. */ - -static const uint8_t coptable[] = { - 0, /* End */ - 0, 0, 0, 0, 0, /* \A, \G, \K, \B, \b */ - 0, 0, 0, 0, 0, 0, /* \D, \d, \S, \s, \W, \w */ - 0, 0, 0, /* Any, AllAny, Anybyte */ - 0, 0, /* \P, \p */ - 0, 0, 0, 0, 0, /* \R, \H, \h, \V, \v */ - 0, /* \X */ - 0, 0, 0, 0, 0, 0, /* \Z, \z, $, $M, ^, ^M */ - 1, /* Char */ - 1, /* Chari */ - 1, /* not */ - 1, /* noti */ - /* Positive single-char repeats */ - 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ - 1+IMM2_SIZE, 1+IMM2_SIZE, /* upto, minupto */ - 1+IMM2_SIZE, /* exact */ - 1, 1, 1, 1+IMM2_SIZE, /* *+, ++, ?+, upto+ */ - 1, 1, 1, 1, 1, 1, /* *I, *?I, +I, +?I, ?I, ??I */ - 1+IMM2_SIZE, 1+IMM2_SIZE, /* upto I, minupto I */ - 1+IMM2_SIZE, /* exact I */ - 1, 1, 1, 1+IMM2_SIZE, /* *+I, ++I, ?+I, upto+I */ - /* Negative single-char repeats - only for chars < 256 */ - 1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */ - 1+IMM2_SIZE, 1+IMM2_SIZE, /* NOT upto, minupto */ - 1+IMM2_SIZE, /* NOT exact */ - 1, 1, 1, 1+IMM2_SIZE, /* NOT *+, ++, ?+, upto+ */ - 1, 1, 1, 1, 1, 1, /* NOT *I, *?I, +I, +?I, ?I, ??I */ - 1+IMM2_SIZE, 1+IMM2_SIZE, /* NOT upto I, minupto I */ - 1+IMM2_SIZE, /* NOT exact I */ - 1, 1, 1, 1+IMM2_SIZE, /* NOT *+I, ++I, ?+I, upto+I */ - /* Positive type repeats */ - 1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */ - 1+IMM2_SIZE, 1+IMM2_SIZE, /* Type upto, minupto */ - 1+IMM2_SIZE, /* Type exact */ - 1, 1, 1, 1+IMM2_SIZE, /* Type *+, ++, ?+, upto+ */ - /* Character class & ref repeats */ - 0, 0, 0, 0, 0, 0, /* *, *?, +, +?, ?, ?? */ - 0, 0, /* CRRANGE, CRMINRANGE */ - 0, 0, 0, 0, /* Possessive *+, ++, ?+, CRPOSRANGE */ - 0, /* CLASS */ - 0, /* NCLASS */ - 0, /* XCLASS - variable length */ - 0, /* ECLASS - variable length */ - 0, /* REF */ - 0, /* REFI */ - 0, /* DNREF */ - 0, /* DNREFI */ - 0, /* RECURSE */ - 0, /* CALLOUT */ - 0, /* CALLOUT_STR */ - 0, /* Alt */ - 0, /* Ket */ - 0, /* KetRmax */ - 0, /* KetRmin */ - 0, /* KetRpos */ - 0, 0, /* Reverse, Vreverse */ - 0, /* Assert */ - 0, /* Assert not */ - 0, /* Assert behind */ - 0, /* Assert behind not */ - 0, /* NA assert */ - 0, /* NA assert behind */ - 0, /* Assert scan substring */ - 0, /* ONCE */ - 0, /* SCRIPT_RUN */ - 0, 0, 0, 0, 0, /* BRA, BRAPOS, CBRA, CBRAPOS, COND */ - 0, 0, 0, 0, 0, /* SBRA, SBRAPOS, SCBRA, SCBRAPOS, SCOND */ - 0, 0, /* CREF, DNCREF */ - 0, 0, /* RREF, DNRREF */ - 0, 0, /* FALSE, TRUE */ - 0, 0, 0, /* BRAZERO, BRAMINZERO, BRAPOSZERO */ - 0, 0, 0, /* MARK, PRUNE, PRUNE_ARG */ - 0, 0, 0, 0, /* SKIP, SKIP_ARG, THEN, THEN_ARG */ - 0, 0, /* COMMIT, COMMIT_ARG */ - 0, 0, 0, /* FAIL, ACCEPT, ASSERT_ACCEPT */ - 0, 0, 0, /* CLOSE, SKIPZERO, DEFINE */ - 0, 0, /* \B and \b in UCP mode */ -}; - -/* This table identifies those opcodes that inspect a character. It is used to -remember the fact that a character could have been inspected when the end of -the subject is reached. ***NOTE*** If the start of this table is modified, the -two tables that follow must also be modified. */ - -static const uint8_t poptable[] = { - 0, /* End */ - 0, 0, 0, 1, 1, /* \A, \G, \K, \B, \b */ - 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ - 1, 1, 1, /* Any, AllAny, Anybyte */ - 1, 1, /* \P, \p */ - 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ - 1, /* \X */ - 0, 0, 0, 0, 0, 0, /* \Z, \z, $, $M, ^, ^M */ - 1, /* Char */ - 1, /* Chari */ - 1, /* not */ - 1, /* noti */ - /* Positive single-char repeats */ - 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ - 1, 1, 1, /* upto, minupto, exact */ - 1, 1, 1, 1, /* *+, ++, ?+, upto+ */ - 1, 1, 1, 1, 1, 1, /* *I, *?I, +I, +?I, ?I, ??I */ - 1, 1, 1, /* upto I, minupto I, exact I */ - 1, 1, 1, 1, /* *+I, ++I, ?+I, upto+I */ - /* Negative single-char repeats - only for chars < 256 */ - 1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */ - 1, 1, 1, /* NOT upto, minupto, exact */ - 1, 1, 1, 1, /* NOT *+, ++, ?+, upto+ */ - 1, 1, 1, 1, 1, 1, /* NOT *I, *?I, +I, +?I, ?I, ??I */ - 1, 1, 1, /* NOT upto I, minupto I, exact I */ - 1, 1, 1, 1, /* NOT *+I, ++I, ?+I, upto+I */ - /* Positive type repeats */ - 1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */ - 1, 1, 1, /* Type upto, minupto, exact */ - 1, 1, 1, 1, /* Type *+, ++, ?+, upto+ */ - /* Character class & ref repeats */ - 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ - 1, 1, /* CRRANGE, CRMINRANGE */ - 1, 1, 1, 1, /* Possessive *+, ++, ?+, CRPOSRANGE */ - 1, /* CLASS */ - 1, /* NCLASS */ - 1, /* XCLASS - variable length */ - 1, /* ECLASS - variable length */ - 0, /* REF */ - 0, /* REFI */ - 0, /* DNREF */ - 0, /* DNREFI */ - 0, /* RECURSE */ - 0, /* CALLOUT */ - 0, /* CALLOUT_STR */ - 0, /* Alt */ - 0, /* Ket */ - 0, /* KetRmax */ - 0, /* KetRmin */ - 0, /* KetRpos */ - 0, 0, /* Reverse, Vreverse */ - 0, /* Assert */ - 0, /* Assert not */ - 0, /* Assert behind */ - 0, /* Assert behind not */ - 0, /* NA assert */ - 0, /* NA assert behind */ - 0, /* Assert scan substring */ - 0, /* ONCE */ - 0, /* SCRIPT_RUN */ - 0, 0, 0, 0, 0, /* BRA, BRAPOS, CBRA, CBRAPOS, COND */ - 0, 0, 0, 0, 0, /* SBRA, SBRAPOS, SCBRA, SCBRAPOS, SCOND */ - 0, 0, /* CREF, DNCREF */ - 0, 0, /* RREF, DNRREF */ - 0, 0, /* FALSE, TRUE */ - 0, 0, 0, /* BRAZERO, BRAMINZERO, BRAPOSZERO */ - 0, 0, 0, /* MARK, PRUNE, PRUNE_ARG */ - 0, 0, 0, 0, /* SKIP, SKIP_ARG, THEN, THEN_ARG */ - 0, 0, /* COMMIT, COMMIT_ARG */ - 0, 0, 0, /* FAIL, ACCEPT, ASSERT_ACCEPT */ - 0, 0, 0, /* CLOSE, SKIPZERO, DEFINE */ - 1, 1, /* \B and \b in UCP mode */ -}; - -/* Compile-time check that these tables have the correct size. */ -STATIC_ASSERT(sizeof(coptable) == OP_TABLE_LENGTH, coptable); -STATIC_ASSERT(sizeof(poptable) == OP_TABLE_LENGTH, poptable); - -/* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W, -and \w */ - -static const uint8_t toptable1[] = { - 0, 0, 0, 0, 0, 0, - ctype_digit, ctype_digit, - ctype_space, ctype_space, - ctype_word, ctype_word, - 0, 0 /* OP_ANY, OP_ALLANY */ -}; - -static const uint8_t toptable2[] = { - 0, 0, 0, 0, 0, 0, - ctype_digit, 0, - ctype_space, 0, - ctype_word, 0, - 1, 1 /* OP_ANY, OP_ALLANY */ -}; - - -/* Structure for holding data about a particular state, which is in effect the -current data for an active path through the match tree. It must consist -entirely of ints because the working vector we are passed, and which we put -these structures in, is a vector of ints. */ - -typedef struct stateblock { - int offset; /* Offset to opcode (-ve has meaning) */ - int count; /* Count for repeats */ - int data; /* Some use extra data */ -} stateblock; - -#define INTS_PER_STATEBLOCK (int)(sizeof(stateblock)/sizeof(int)) - - -/* Before version 10.32 the recursive calls of internal_dfa_match() were passed -local working space and output vectors that were created on the stack. This has -caused issues for some patterns, especially in small-stack environments such as -Windows. A new scheme is now in use which sets up a vector on the stack, but if -this is too small, heap memory is used, up to the heap_limit. The main -parameters are all numbers of ints because the workspace is a vector of ints. - -The size of the starting stack vector, DFA_START_RWS_SIZE, is in bytes, and is -defined in pcre2_internal.h so as to be available to pcre2test when it is -finding the minimum heap requirement for a match. */ - -#define OVEC_UNIT (sizeof(PCRE2_SIZE)/sizeof(int)) - -#define RWS_BASE_SIZE (DFA_START_RWS_SIZE/sizeof(int)) /* Stack vector */ -#define RWS_RSIZE 1000 /* Work size for recursion */ -#define RWS_OVEC_RSIZE (1000*OVEC_UNIT) /* Ovector for recursion */ -#define RWS_OVEC_OSIZE (2*OVEC_UNIT) /* Ovector in other cases */ - -/* This structure is at the start of each workspace block. */ - -typedef struct RWS_anchor { - struct RWS_anchor *next; - uint32_t size; /* Number of ints */ - uint32_t free; /* Number of ints */ -} RWS_anchor; - -#define RWS_ANCHOR_SIZE (sizeof(RWS_anchor)/sizeof(int)) - - - -/************************************************* -* Process a callout * -*************************************************/ - -/* This function is called to perform a callout. - -Arguments: - code current code pointer - offsets points to current capture offsets - current_subject start of current subject match - ptr current position in subject - mb the match block - extracode extra code offset when called from condition - lengthptr where to return the callout length - -Returns: the return from the callout -*/ - -static int -do_callout_dfa(PCRE2_SPTR code, PCRE2_SIZE *offsets, PCRE2_SPTR current_subject, - PCRE2_SPTR ptr, dfa_match_block *mb, PCRE2_SIZE extracode, - PCRE2_SIZE *lengthptr) -{ -pcre2_callout_block *cb = mb->cb; - -*lengthptr = (code[extracode] == OP_CALLOUT)? - (PCRE2_SIZE)PRIV(OP_lengths)[OP_CALLOUT] : - (PCRE2_SIZE)GET(code, 1 + 2*LINK_SIZE + extracode); - -if (mb->callout == NULL) return 0; /* No callout provided */ - -/* Fixed fields in the callout block are set once and for all at the start of -matching. */ - -cb->offset_vector = offsets; -cb->start_match = (PCRE2_SIZE)(current_subject - mb->start_subject); -cb->current_position = (PCRE2_SIZE)(ptr - mb->start_subject); -cb->pattern_position = GET(code, 1 + extracode); -cb->next_item_length = GET(code, 1 + LINK_SIZE + extracode); - -if (code[extracode] == OP_CALLOUT) - { - cb->callout_number = code[1 + 2*LINK_SIZE + extracode]; - cb->callout_string_offset = 0; - cb->callout_string = NULL; - cb->callout_string_length = 0; - } -else - { - cb->callout_number = 0; - cb->callout_string_offset = GET(code, 1 + 3*LINK_SIZE + extracode); - cb->callout_string = code + (1 + 4*LINK_SIZE + extracode) + 1; - cb->callout_string_length = *lengthptr - (1 + 4*LINK_SIZE) - 2; - } - -return (mb->callout)(cb, mb->callout_data); -} - - - -/************************************************* -* Expand local workspace memory * -*************************************************/ - -/* This function is called when internal_dfa_match() is about to be called -recursively and there is insufficient working space left in the current -workspace block. If there's an existing next block, use it; otherwise get a new -block unless the heap limit is reached. - -Arguments: - rwsptr pointer to block pointer (updated) - ovecsize space needed for an ovector - mb the match block - -Returns: 0 rwsptr has been updated - !0 an error code -*/ - -static int -more_workspace(RWS_anchor **rwsptr, unsigned int ovecsize, dfa_match_block *mb) -{ -RWS_anchor *rws = *rwsptr; -RWS_anchor *new; - -if (rws->next != NULL) - { - new = rws->next; - } - -/* Sizes in the RWS_anchor blocks are in units of sizeof(int), but -mb->heap_limit and mb->heap_used are in kibibytes. Play carefully, to avoid -overflow. */ - -else - { - uint32_t newsize = (rws->size >= UINT32_MAX/(sizeof(int)*2))? UINT32_MAX/sizeof(int) : rws->size * 2; - uint32_t newsizeK = newsize/(1024/sizeof(int)); - - if (newsizeK + mb->heap_used > mb->heap_limit) - newsizeK = (uint32_t)(mb->heap_limit - mb->heap_used); - newsize = newsizeK*(1024/sizeof(int)); - - if (newsize < RWS_RSIZE + ovecsize + RWS_ANCHOR_SIZE) - return PCRE2_ERROR_HEAPLIMIT; - new = mb->memctl.malloc(newsize*sizeof(int), mb->memctl.memory_data); - if (new == NULL) return PCRE2_ERROR_NOMEMORY; - mb->heap_used += newsizeK; - new->next = NULL; - new->size = newsize; - rws->next = new; - } - -new->free = new->size - RWS_ANCHOR_SIZE; -*rwsptr = new; -return 0; -} - - - -/************************************************* -* Match a Regular Expression - DFA engine * -*************************************************/ - -/* This internal function applies a compiled pattern to a subject string, -starting at a given point, using a DFA engine. This function is called from the -external one, possibly multiple times if the pattern is not anchored. The -function calls itself recursively for some kinds of subpattern. - -Arguments: - mb the match_data block with fixed information - this_start_code the opening bracket of this subexpression's code - current_subject where we currently are in the subject string - start_offset start offset in the subject string - offsets vector to contain the matching string offsets - offsetcount size of same - workspace vector of workspace - wscount size of same - rlevel function call recursion level - -Returns: > 0 => number of match offset pairs placed in offsets - = 0 => offsets overflowed; longest matches are present - -1 => failed to match - < -1 => some kind of unexpected problem - -The following macros are used for adding states to the two state vectors (one -for the current character, one for the following character). */ - -#define ADD_ACTIVE(x,y) \ - if (active_count++ < wscount) \ - { \ - next_active_state->offset = (x); \ - next_active_state->count = (y); \ - next_active_state++; \ - } \ - else return PCRE2_ERROR_DFA_WSSIZE - -#define ADD_ACTIVE_DATA(x,y,z) \ - if (active_count++ < wscount) \ - { \ - next_active_state->offset = (x); \ - next_active_state->count = (y); \ - next_active_state->data = (z); \ - next_active_state++; \ - } \ - else return PCRE2_ERROR_DFA_WSSIZE - -#define ADD_NEW(x,y) \ - if (new_count++ < wscount) \ - { \ - next_new_state->offset = (x); \ - next_new_state->count = (y); \ - next_new_state++; \ - } \ - else return PCRE2_ERROR_DFA_WSSIZE - -#define ADD_NEW_DATA(x,y,z) \ - if (new_count++ < wscount) \ - { \ - next_new_state->offset = (x); \ - next_new_state->count = (y); \ - next_new_state->data = (z); \ - next_new_state++; \ - } \ - else return PCRE2_ERROR_DFA_WSSIZE - -/* And now, here is the code */ - -static int -internal_dfa_match( - dfa_match_block *mb, - PCRE2_SPTR this_start_code, - PCRE2_SPTR current_subject, - PCRE2_SIZE start_offset, - PCRE2_SIZE *offsets, - uint32_t offsetcount, - int *workspace, - int wscount, - uint32_t rlevel, - int *RWS) -{ -stateblock *active_states, *new_states, *temp_states; -stateblock *next_active_state, *next_new_state; -const uint8_t *ctypes, *lcc, *fcc; -PCRE2_SPTR ptr; -PCRE2_SPTR end_code; -dfa_recursion_info new_recursive; -int active_count, new_count, match_count; - -/* Some fields in the mb block are frequently referenced, so we load them into -independent variables in the hope that this will perform better. */ - -PCRE2_SPTR start_subject = mb->start_subject; -PCRE2_SPTR end_subject = mb->end_subject; -PCRE2_SPTR start_code = mb->start_code; - -#ifdef SUPPORT_UNICODE -BOOL utf = (mb->poptions & PCRE2_UTF) != 0; -BOOL utf_or_ucp = utf || (mb->poptions & PCRE2_UCP) != 0; -#else -BOOL utf = FALSE; -#endif - -BOOL reset_could_continue = FALSE; - -if (mb->match_call_count++ >= mb->match_limit) return PCRE2_ERROR_MATCHLIMIT; -if (rlevel++ > mb->match_limit_depth) return PCRE2_ERROR_DEPTHLIMIT; -offsetcount &= (uint32_t)(-2); /* Round down */ - -wscount -= 2; -wscount = (wscount - (wscount % (INTS_PER_STATEBLOCK * 2))) / - (2 * INTS_PER_STATEBLOCK); - -ctypes = mb->tables + ctypes_offset; -lcc = mb->tables + lcc_offset; -fcc = mb->tables + fcc_offset; - -match_count = PCRE2_ERROR_NOMATCH; /* A negative number */ - -active_states = (stateblock *)(workspace + 2); -next_new_state = new_states = active_states + wscount; -new_count = 0; - -/* The first thing in any (sub) pattern is a bracket of some sort. Push all -the alternative states onto the list, and find out where the end is. This -makes is possible to use this function recursively, when we want to stop at a -matching internal ket rather than at the end. - -If we are dealing with a backward assertion we have to find out the maximum -amount to move back, and set up each alternative appropriately. */ - -if (*this_start_code == OP_ASSERTBACK || *this_start_code == OP_ASSERTBACK_NOT) - { - size_t max_back = 0; - size_t gone_back; - - end_code = this_start_code; - do - { - size_t back = (size_t)GET2(end_code, 2+LINK_SIZE); - if (back > max_back) max_back = back; - end_code += GET(end_code, 1); - } - while (*end_code == OP_ALT); - - /* If we can't go back the amount required for the longest lookbehind - pattern, go back as far as we can; some alternatives may still be viable. */ - -#ifdef SUPPORT_UNICODE - /* In character mode we have to step back character by character */ - - if (utf) - { - for (gone_back = 0; gone_back < max_back; gone_back++) - { - if (current_subject <= start_subject) break; - current_subject--; - ACROSSCHAR(current_subject > start_subject, current_subject, - current_subject--); - } - } - else -#endif - - /* In byte-mode we can do this quickly. */ - - { - size_t current_offset = (size_t)(current_subject - start_subject); - gone_back = (current_offset < max_back)? current_offset : max_back; - current_subject -= gone_back; - } - - /* Save the earliest consulted character */ - - if (current_subject < mb->start_used_ptr) - mb->start_used_ptr = current_subject; - - /* Now we can process the individual branches. There will be an OP_REVERSE at - the start of each branch, except when the length of the branch is zero. */ - - end_code = this_start_code; - do - { - uint32_t revlen = (end_code[1+LINK_SIZE] == OP_REVERSE)? 1 + IMM2_SIZE : 0; - size_t back = (revlen == 0)? 0 : (size_t)GET2(end_code, 2+LINK_SIZE); - if (back <= gone_back) - { - int bstate = (int)(end_code - start_code + 1 + LINK_SIZE + revlen); - ADD_NEW_DATA(-bstate, 0, (int)(gone_back - back)); - } - end_code += GET(end_code, 1); - } - while (*end_code == OP_ALT); - } - -/* This is the code for a "normal" subpattern (not a backward assertion). The -start of a whole pattern is always one of these. If we are at the top level, -we may be asked to restart matching from the same point that we reached for a -previous partial match. We still have to scan through the top-level branches to -find the end state. */ - -else - { - end_code = this_start_code; - - /* Restarting */ - - if (rlevel == 1 && (mb->moptions & PCRE2_DFA_RESTART) != 0) - { - do { end_code += GET(end_code, 1); } while (*end_code == OP_ALT); - new_count = workspace[1]; - if (!workspace[0]) - memcpy(new_states, active_states, (size_t)new_count * sizeof(stateblock)); - } - - /* Not restarting */ - - else - { - int length = 1 + LINK_SIZE + - ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA || - *this_start_code == OP_CBRAPOS || *this_start_code == OP_SCBRAPOS) - ? IMM2_SIZE:0); - do - { - ADD_NEW((int)(end_code - start_code + length), 0); - end_code += GET(end_code, 1); - length = 1 + LINK_SIZE; - } - while (*end_code == OP_ALT); - } - } - -workspace[0] = 0; /* Bit indicating which vector is current */ - -/* Loop for scanning the subject */ - -ptr = current_subject; -for (;;) - { - int i, j; - int clen, dlen; - uint32_t c, d; - BOOL partial_newline = FALSE; - BOOL could_continue = reset_could_continue; - reset_could_continue = FALSE; - - if (ptr > mb->last_used_ptr) mb->last_used_ptr = ptr; - - /* Make the new state list into the active state list and empty the - new state list. */ - - temp_states = active_states; - active_states = new_states; - new_states = temp_states; - active_count = new_count; - new_count = 0; - - workspace[0] ^= 1; /* Remember for the restarting feature */ - workspace[1] = active_count; - - /* Set the pointers for adding new states */ - - next_active_state = active_states + active_count; - next_new_state = new_states; - - /* Load the current character from the subject outside the loop, as many - different states may want to look at it, and we assume that at least one - will. */ - - if (ptr < end_subject) - { - clen = 1; /* Number of data items in the character */ -#ifdef SUPPORT_UNICODE - GETCHARLENTEST(c, ptr, clen); -#else - c = *ptr; -#endif /* SUPPORT_UNICODE */ - } - else - { - clen = 0; /* This indicates the end of the subject */ - c = NOTACHAR; /* This value should never actually be used */ - } - - /* Scan up the active states and act on each one. The result of an action - may be to add more states to the currently active list (e.g. on hitting a - parenthesis) or it may be to put states on the new list, for considering - when we move the character pointer on. */ - - for (i = 0; i < active_count; i++) - { - stateblock *current_state = active_states + i; - BOOL caseless = FALSE; - PCRE2_SPTR code; - uint32_t codevalue; - int state_offset = current_state->offset; - int rrc; - int count; - - /* A negative offset is a special case meaning "hold off going to this - (negated) state until the number of characters in the data field have - been skipped". If the could_continue flag was passed over from a previous - state, arrange for it to passed on. */ - - if (state_offset < 0) - { - if (current_state->data > 0) - { - ADD_NEW_DATA(state_offset, current_state->count, - current_state->data - 1); - if (could_continue) reset_could_continue = TRUE; - continue; - } - else - { - current_state->offset = state_offset = -state_offset; - } - } - - /* Check for a duplicate state with the same count, and skip if found. - See the note at the head of this module about the possibility of improving - performance here. */ - - for (j = 0; j < i; j++) - { - if (active_states[j].offset == state_offset && - active_states[j].count == current_state->count) - goto NEXT_ACTIVE_STATE; - } - - /* The state offset is the offset to the opcode */ - - code = start_code + state_offset; - codevalue = *code; - - /* If this opcode inspects a character, but we are at the end of the - subject, remember the fact for use when testing for a partial match. */ - - if (clen == 0 && poptable[codevalue] != 0) - could_continue = TRUE; - - /* If this opcode is followed by an inline character, load it. It is - tempting to test for the presence of a subject character here, but that - is wrong, because sometimes zero repetitions of the subject are - permitted. - - We also use this mechanism for opcodes such as OP_TYPEPLUS that take an - argument that is not a data character - but is always one byte long because - the values are small. We have to take special action to deal with \P, \p, - \H, \h, \V, \v and \X in this case. To keep the other cases fast, convert - these ones to new opcodes. */ - - if (coptable[codevalue] > 0) - { - dlen = 1; -#ifdef SUPPORT_UNICODE - if (utf) { GETCHARLEN(d, (code + coptable[codevalue]), dlen); } else -#endif /* SUPPORT_UNICODE */ - d = code[coptable[codevalue]]; - if (codevalue >= OP_TYPESTAR) - { - switch(d) - { - case OP_ANYBYTE: return PCRE2_ERROR_DFA_UITEM; - case OP_NOTPROP: - case OP_PROP: codevalue += OP_PROP_EXTRA; break; - case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break; - case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break; - case OP_NOT_HSPACE: - case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break; - case OP_NOT_VSPACE: - case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break; - default: break; - } - } - } - else - { - dlen = 0; /* Not strictly necessary, but compilers moan */ - d = NOTACHAR; /* if these variables are not set. */ - } - - - /* Now process the individual opcodes */ - - switch (codevalue) - { -/* ========================================================================== */ - /* Reached a closing bracket. If not at the end of the pattern, carry - on with the next opcode. For repeating opcodes, also add the repeat - state. Note that KETRPOS will always be encountered at the end of the - subpattern, because the possessive subpattern repeats are always handled - using recursive calls. Thus, it never adds any new states. - - At the end of the (sub)pattern, unless we have an empty string and - PCRE2_NOTEMPTY is set, or PCRE2_NOTEMPTY_ATSTART is set and we are at the - start of the subject, save the match data, shifting up all previous - matches so we always have the longest first. */ - - case OP_KET: - case OP_KETRMIN: - case OP_KETRMAX: - case OP_KETRPOS: - if (code != end_code) - { - ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0); - if (codevalue != OP_KET) - { - ADD_ACTIVE(state_offset - (int)GET(code, 1), 0); - } - } - else - { - if (ptr > current_subject || - ((mb->moptions & PCRE2_NOTEMPTY) == 0 && - ((mb->moptions & PCRE2_NOTEMPTY_ATSTART) == 0 || - current_subject > start_subject + mb->start_offset))) - { - if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0; - else if (match_count > 0 && ++match_count * 2 > (int)offsetcount) - match_count = 0; - count = ((match_count == 0)? (int)offsetcount : match_count * 2) - 2; - if (count > 0) (void)memmove(offsets + 2, offsets, - (size_t)count * sizeof(PCRE2_SIZE)); - if (offsetcount >= 2) - { - offsets[0] = (PCRE2_SIZE)(current_subject - start_subject); - offsets[1] = (PCRE2_SIZE)(ptr - start_subject); - } - if ((mb->moptions & PCRE2_DFA_SHORTEST) != 0) return match_count; - } - } - break; - -/* ========================================================================== */ - /* These opcodes add to the current list of states without looking - at the current character. */ - - /*-----------------------------------------------------------------*/ - case OP_ALT: - do { code += GET(code, 1); } while (*code == OP_ALT); - ADD_ACTIVE((int)(code - start_code), 0); - break; - - /*-----------------------------------------------------------------*/ - case OP_BRA: - case OP_SBRA: - do - { - ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0); - code += GET(code, 1); - } - while (*code == OP_ALT); - break; - - /*-----------------------------------------------------------------*/ - case OP_CBRA: - case OP_SCBRA: - ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE + IMM2_SIZE), 0); - code += GET(code, 1); - while (*code == OP_ALT) - { - ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0); - code += GET(code, 1); - } - break; - - /*-----------------------------------------------------------------*/ - case OP_BRAZERO: - case OP_BRAMINZERO: - ADD_ACTIVE(state_offset + 1, 0); - code += 1 + GET(code, 2); - while (*code == OP_ALT) code += GET(code, 1); - ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0); - break; - - /*-----------------------------------------------------------------*/ - case OP_SKIPZERO: - code += 1 + GET(code, 2); - while (*code == OP_ALT) code += GET(code, 1); - ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0); - break; - - /*-----------------------------------------------------------------*/ - case OP_CIRC: - if (ptr == start_subject && (mb->moptions & PCRE2_NOTBOL) == 0) - { ADD_ACTIVE(state_offset + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - case OP_CIRCM: - if ((ptr == start_subject && (mb->moptions & PCRE2_NOTBOL) == 0) || - ((ptr != end_subject || (mb->poptions & PCRE2_ALT_CIRCUMFLEX) != 0 ) - && WAS_NEWLINE(ptr))) - { ADD_ACTIVE(state_offset + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - case OP_EOD: - if (ptr >= end_subject) - { - if ((mb->moptions & PCRE2_PARTIAL_HARD) != 0) - return PCRE2_ERROR_PARTIAL; - else { ADD_ACTIVE(state_offset + 1, 0); } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_SOD: - if (ptr == start_subject) { ADD_ACTIVE(state_offset + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - case OP_SOM: - if (ptr == start_subject + start_offset) { ADD_ACTIVE(state_offset + 1, 0); } - break; - - -/* ========================================================================== */ - /* These opcodes inspect the next subject character, and sometimes - the previous one as well, but do not have an argument. The variable - clen contains the length of the current character and is zero if we are - at the end of the subject. */ - - /*-----------------------------------------------------------------*/ - case OP_ANY: - if (clen > 0 && !IS_NEWLINE(ptr)) - { - if (ptr + 1 >= mb->end_subject && - (mb->moptions & (PCRE2_PARTIAL_HARD)) != 0 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - c == NLBLOCK->nl[0]) - { - could_continue = partial_newline = TRUE; - } - else - { - ADD_NEW(state_offset + 1, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_ALLANY: - if (clen > 0) - { ADD_NEW(state_offset + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - case OP_EODN: - if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - mb->nllen)) - { - if ((mb->moptions & PCRE2_PARTIAL_HARD) != 0) - return PCRE2_ERROR_PARTIAL; - ADD_ACTIVE(state_offset + 1, 0); - } - break; - - /*-----------------------------------------------------------------*/ - case OP_DOLL: - if ((mb->moptions & PCRE2_NOTEOL) == 0) - { - if (clen == 0 && (mb->moptions & PCRE2_PARTIAL_HARD) != 0) - could_continue = TRUE; - else if (clen == 0 || - ((mb->poptions & PCRE2_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr) && - (ptr == end_subject - mb->nllen) - )) - { ADD_ACTIVE(state_offset + 1, 0); } - else if (ptr + 1 >= mb->end_subject && - (mb->moptions & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - c == NLBLOCK->nl[0]) - { - if ((mb->moptions & PCRE2_PARTIAL_HARD) != 0) - { - reset_could_continue = TRUE; - ADD_NEW_DATA(-(state_offset + 1), 0, 1); - } - else could_continue = partial_newline = TRUE; - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_DOLLM: - if ((mb->moptions & PCRE2_NOTEOL) == 0) - { - if (clen == 0 && (mb->moptions & PCRE2_PARTIAL_HARD) != 0) - could_continue = TRUE; - else if (clen == 0 || - ((mb->poptions & PCRE2_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr))) - { ADD_ACTIVE(state_offset + 1, 0); } - else if (ptr + 1 >= mb->end_subject && - (mb->moptions & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - c == NLBLOCK->nl[0]) - { - if ((mb->moptions & PCRE2_PARTIAL_HARD) != 0) - { - reset_could_continue = TRUE; - ADD_NEW_DATA(-(state_offset + 1), 0, 1); - } - else could_continue = partial_newline = TRUE; - } - } - else if (IS_NEWLINE(ptr)) - { ADD_ACTIVE(state_offset + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - - case OP_DIGIT: - case OP_WHITESPACE: - case OP_WORDCHAR: - if (clen > 0 && c < 256 && - ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0) - { ADD_NEW(state_offset + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - case OP_NOT_DIGIT: - case OP_NOT_WHITESPACE: - case OP_NOT_WORDCHAR: - if (clen > 0 && (c >= 256 || - ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0)) - { ADD_NEW(state_offset + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - case OP_WORD_BOUNDARY: - case OP_NOT_WORD_BOUNDARY: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - { - int left_word, right_word; - - if (ptr > start_subject) - { - PCRE2_SPTR temp = ptr - 1; - if (temp < mb->start_used_ptr) mb->start_used_ptr = temp; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (utf) { BACKCHAR(temp); } -#endif - GETCHARTEST(d, temp); -#ifdef SUPPORT_UNICODE - if (codevalue == OP_UCP_WORD_BOUNDARY || - codevalue == OP_NOT_UCP_WORD_BOUNDARY) - { - int chartype = UCD_CHARTYPE(d); - int category = PRIV(ucp_gentype)[chartype]; - left_word = (category == ucp_L || category == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc); - } - else -#endif - left_word = d < 256 && (ctypes[d] & ctype_word) != 0; - } - else left_word = FALSE; - - if (clen > 0) - { - if (ptr >= mb->last_used_ptr) - { - PCRE2_SPTR temp = ptr + 1; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (utf) { FORWARDCHARTEST(temp, mb->end_subject); } -#endif - mb->last_used_ptr = temp; - } -#ifdef SUPPORT_UNICODE - if (codevalue == OP_UCP_WORD_BOUNDARY || - codevalue == OP_NOT_UCP_WORD_BOUNDARY) - { - int chartype = UCD_CHARTYPE(c); - int category = PRIV(ucp_gentype)[chartype]; - right_word = (category == ucp_L || category == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc); - } - else -#endif - right_word = c < 256 && (ctypes[c] & ctype_word) != 0; - } - else right_word = FALSE; - - if ((left_word == right_word) == - (codevalue == OP_NOT_WORD_BOUNDARY || - codevalue == OP_NOT_UCP_WORD_BOUNDARY)) - { ADD_ACTIVE(state_offset + 1, 0); } - } - break; - - - /*-----------------------------------------------------------------*/ - /* Check the next character by Unicode property. We will get here only - if the support is in the binary; otherwise a compile-time error occurs. - */ - -#ifdef SUPPORT_UNICODE - case OP_PROP: - case OP_NOTPROP: - if (clen > 0) - { - BOOL OK; - int chartype; - const uint32_t *cp; - const ucd_record * prop = GET_UCD(c); - switch(code[1]) - { - case PT_LAMP: - chartype = prop->chartype; - OK = chartype == ucp_Lu || chartype == ucp_Ll || - chartype == ucp_Lt; - break; - - case PT_GC: - OK = PRIV(ucp_gentype)[prop->chartype] == code[2]; - break; - - case PT_PC: - OK = prop->chartype == code[2]; - break; - - case PT_SC: - OK = prop->script == code[2]; - break; - - case PT_SCX: - OK = (prop->script == code[2] || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), code[2]) != 0); - break; - - /* These are specials for combination cases. */ - - case PT_ALNUM: - chartype = prop->chartype; - OK = PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N; - break; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - switch(c) - { - HSPACE_CASES: - VSPACE_CASES: - OK = TRUE; - break; - - default: - OK = PRIV(ucp_gentype)[prop->chartype] == ucp_Z; - break; - } - break; - - case PT_WORD: - chartype = prop->chartype; - OK = PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc; - break; - - case PT_CLIST: -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (c > MAX_UTF_CODE_POINT) - { - OK = FALSE; - break; - } -#endif - cp = PRIV(ucd_caseless_sets) + code[2]; - for (;;) - { - if (c < *cp) { OK = FALSE; break; } - if (c == *cp++) { OK = TRUE; break; } - } - break; - - case PT_UCNC: - OK = c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT || - c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) || - c >= 0xe000; - break; - - case PT_BIDICL: - OK = UCD_BIDICLASS(c) == code[2]; - break; - - case PT_BOOL: - OK = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), code[2]) != 0; - break; - - /* Should never occur, but keep compilers from grumbling. */ - - default: - OK = codevalue != OP_PROP; - break; - } - - if (OK == (codevalue == OP_PROP)) { ADD_NEW(state_offset + 3, 0); } - } - break; -#endif - - - -/* ========================================================================== */ - /* These opcodes likewise inspect the subject character, but have an - argument that is not a data character. It is one of these opcodes: - OP_ANY, OP_ALLANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE, - OP_WORDCHAR, OP_NOT_WORDCHAR. The value is loaded into d. */ - - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEPOSPLUS: - count = current_state->count; /* Already matched */ - if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } - if (clen > 0) - { - if (d == OP_ANY && ptr + 1 >= mb->end_subject && - (mb->moptions & (PCRE2_PARTIAL_HARD)) != 0 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - c == NLBLOCK->nl[0]) - { - could_continue = partial_newline = TRUE; - } - else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || - (c < 256 && - (d != OP_ANY || !IS_NEWLINE(ptr)) && - ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) - { - if (count > 0 && codevalue == OP_TYPEPOSPLUS) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - count++; - ADD_NEW(state_offset, count); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEPOSQUERY: - ADD_ACTIVE(state_offset + 2, 0); - if (clen > 0) - { - if (d == OP_ANY && ptr + 1 >= mb->end_subject && - (mb->moptions & (PCRE2_PARTIAL_HARD)) != 0 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - c == NLBLOCK->nl[0]) - { - could_continue = partial_newline = TRUE; - } - else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || - (c < 256 && - (d != OP_ANY || !IS_NEWLINE(ptr)) && - ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) - { - if (codevalue == OP_TYPEPOSQUERY) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW(state_offset + 2, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPOSSTAR: - ADD_ACTIVE(state_offset + 2, 0); - if (clen > 0) - { - if (d == OP_ANY && ptr + 1 >= mb->end_subject && - (mb->moptions & (PCRE2_PARTIAL_HARD)) != 0 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - c == NLBLOCK->nl[0]) - { - could_continue = partial_newline = TRUE; - } - else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || - (c < 256 && - (d != OP_ANY || !IS_NEWLINE(ptr)) && - ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) - { - if (codevalue == OP_TYPEPOSSTAR) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW(state_offset, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_TYPEEXACT: - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - if (d == OP_ANY && ptr + 1 >= mb->end_subject && - (mb->moptions & (PCRE2_PARTIAL_HARD)) != 0 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - c == NLBLOCK->nl[0]) - { - could_continue = partial_newline = TRUE; - } - else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || - (c < 256 && - (d != OP_ANY || !IS_NEWLINE(ptr)) && - ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) - { - if (++count >= (int)GET2(code, 1)) - { ADD_NEW(state_offset + 1 + IMM2_SIZE + 1, 0); } - else - { ADD_NEW(state_offset, count); } - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEPOSUPTO: - ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - if (d == OP_ANY && ptr + 1 >= mb->end_subject && - (mb->moptions & (PCRE2_PARTIAL_HARD)) != 0 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - c == NLBLOCK->nl[0]) - { - could_continue = partial_newline = TRUE; - } - else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || - (c < 256 && - (d != OP_ANY || !IS_NEWLINE(ptr)) && - ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) - { - if (codevalue == OP_TYPEPOSUPTO) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - if (++count >= (int)GET2(code, 1)) - { ADD_NEW(state_offset + 2 + IMM2_SIZE, 0); } - else - { ADD_NEW(state_offset, count); } - } - } - break; - -/* ========================================================================== */ - /* These are virtual opcodes that are used when something like - OP_TYPEPLUS has OP_PROP, OP_NOTPROP, OP_ANYNL, or OP_EXTUNI as its - argument. It keeps the code above fast for the other cases. The argument - is in the d variable. */ - -#ifdef SUPPORT_UNICODE - case OP_PROP_EXTRA + OP_TYPEPLUS: - case OP_PROP_EXTRA + OP_TYPEMINPLUS: - case OP_PROP_EXTRA + OP_TYPEPOSPLUS: - count = current_state->count; /* Already matched */ - if (count > 0) { ADD_ACTIVE(state_offset + 4, 0); } - if (clen > 0) - { - BOOL OK; - int chartype; - const uint32_t *cp; - const ucd_record * prop = GET_UCD(c); - switch(code[2]) - { - case PT_LAMP: - chartype = prop->chartype; - OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt; - break; - - case PT_GC: - OK = PRIV(ucp_gentype)[prop->chartype] == code[3]; - break; - - case PT_PC: - OK = prop->chartype == code[3]; - break; - - case PT_SC: - OK = prop->script == code[3]; - break; - - case PT_SCX: - OK = (prop->script == code[3] || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), code[3]) != 0); - break; - - /* These are specials for combination cases. */ - - case PT_ALNUM: - chartype = prop->chartype; - OK = PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N; - break; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - switch(c) - { - HSPACE_CASES: - VSPACE_CASES: - OK = TRUE; - break; - - default: - OK = PRIV(ucp_gentype)[prop->chartype] == ucp_Z; - break; - } - break; - - case PT_WORD: - chartype = prop->chartype; - OK = PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc; - break; - - case PT_CLIST: -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (c > MAX_UTF_CODE_POINT) - { - OK = FALSE; - break; - } -#endif - cp = PRIV(ucd_caseless_sets) + code[3]; - for (;;) - { - if (c < *cp) { OK = FALSE; break; } - if (c == *cp++) { OK = TRUE; break; } - } - break; - - case PT_UCNC: - OK = c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT || - c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) || - c >= 0xe000; - break; - - case PT_BIDICL: - OK = UCD_BIDICLASS(c) == code[3]; - break; - - case PT_BOOL: - OK = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), code[3]) != 0; - break; - - /* Should never occur, but keep compilers from grumbling. */ - - default: - OK = codevalue != OP_PROP; - break; - } - - if (OK == (d == OP_PROP)) - { - if (count > 0 && codevalue == OP_PROP_EXTRA + OP_TYPEPOSPLUS) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - count++; - ADD_NEW(state_offset, count); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_EXTUNI_EXTRA + OP_TYPEPLUS: - case OP_EXTUNI_EXTRA + OP_TYPEMINPLUS: - case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS: - count = current_state->count; /* Already matched */ - if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } - if (clen > 0) - { - int ncount = 0; - if (count > 0 && codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - (void)PRIV(extuni)(c, ptr + clen, mb->start_subject, end_subject, utf, - &ncount); - count++; - ADD_NEW_DATA(-state_offset, count, ncount); - } - break; -#endif - - /*-----------------------------------------------------------------*/ - case OP_ANYNL_EXTRA + OP_TYPEPLUS: - case OP_ANYNL_EXTRA + OP_TYPEMINPLUS: - case OP_ANYNL_EXTRA + OP_TYPEPOSPLUS: - count = current_state->count; /* Already matched */ - if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } - if (clen > 0) - { - int ncount = 0; - switch (c) - { - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#ifndef EBCDIC - case 0x2028: - case 0x2029: -#endif /* Not EBCDIC */ - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) break; - goto ANYNL01; - - case CHAR_CR: - if (ptr + 1 < end_subject && UCHAR21TEST(ptr + 1) == CHAR_LF) ncount = 1; - /* Fall through */ - - ANYNL01: - case CHAR_LF: - if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - count++; - ADD_NEW_DATA(-state_offset, count, ncount); - break; - - default: - break; - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_VSPACE_EXTRA + OP_TYPEPLUS: - case OP_VSPACE_EXTRA + OP_TYPEMINPLUS: - case OP_VSPACE_EXTRA + OP_TYPEPOSPLUS: - count = current_state->count; /* Already matched */ - if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } - if (clen > 0) - { - BOOL OK; - switch (c) - { - VSPACE_CASES: - OK = TRUE; - break; - - default: - OK = FALSE; - break; - } - - if (OK == (d == OP_VSPACE)) - { - if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - count++; - ADD_NEW_DATA(-state_offset, count, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_HSPACE_EXTRA + OP_TYPEPLUS: - case OP_HSPACE_EXTRA + OP_TYPEMINPLUS: - case OP_HSPACE_EXTRA + OP_TYPEPOSPLUS: - count = current_state->count; /* Already matched */ - if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } - if (clen > 0) - { - BOOL OK; - switch (c) - { - HSPACE_CASES: - OK = TRUE; - break; - - default: - OK = FALSE; - break; - } - - if (OK == (d == OP_HSPACE)) - { - if (count > 0 && codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSPLUS) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - count++; - ADD_NEW_DATA(-state_offset, count, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ -#ifdef SUPPORT_UNICODE - case OP_PROP_EXTRA + OP_TYPEQUERY: - case OP_PROP_EXTRA + OP_TYPEMINQUERY: - case OP_PROP_EXTRA + OP_TYPEPOSQUERY: - count = 4; - goto QS1; - - case OP_PROP_EXTRA + OP_TYPESTAR: - case OP_PROP_EXTRA + OP_TYPEMINSTAR: - case OP_PROP_EXTRA + OP_TYPEPOSSTAR: - count = 0; - - QS1: - - ADD_ACTIVE(state_offset + 4, 0); - if (clen > 0) - { - BOOL OK; - int chartype; - const uint32_t *cp; - const ucd_record * prop = GET_UCD(c); - switch(code[2]) - { - case PT_LAMP: - chartype = prop->chartype; - OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt; - break; - - case PT_GC: - OK = PRIV(ucp_gentype)[prop->chartype] == code[3]; - break; - - case PT_PC: - OK = prop->chartype == code[3]; - break; - - case PT_SC: - OK = prop->script == code[3]; - break; - - case PT_SCX: - OK = (prop->script == code[3] || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), code[3]) != 0); - break; - - /* These are specials for combination cases. */ - - case PT_ALNUM: - chartype = prop->chartype; - OK = PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N; - break; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - switch(c) - { - HSPACE_CASES: - VSPACE_CASES: - OK = TRUE; - break; - - default: - OK = PRIV(ucp_gentype)[prop->chartype] == ucp_Z; - break; - } - break; - - case PT_WORD: - chartype = prop->chartype; - OK = PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc; - break; - - case PT_CLIST: -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (c > MAX_UTF_CODE_POINT) - { - OK = FALSE; - break; - } -#endif - cp = PRIV(ucd_caseless_sets) + code[3]; - for (;;) - { - if (c < *cp) { OK = FALSE; break; } - if (c == *cp++) { OK = TRUE; break; } - } - break; - - case PT_UCNC: - OK = c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT || - c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) || - c >= 0xe000; - break; - - case PT_BIDICL: - OK = UCD_BIDICLASS(c) == code[3]; - break; - - case PT_BOOL: - OK = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), code[3]) != 0; - break; - - /* Should never occur, but keep compilers from grumbling. */ - - default: - OK = codevalue != OP_PROP; - break; - } - - if (OK == (d == OP_PROP)) - { - if (codevalue == OP_PROP_EXTRA + OP_TYPEPOSSTAR || - codevalue == OP_PROP_EXTRA + OP_TYPEPOSQUERY) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW(state_offset + count, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_EXTUNI_EXTRA + OP_TYPEQUERY: - case OP_EXTUNI_EXTRA + OP_TYPEMINQUERY: - case OP_EXTUNI_EXTRA + OP_TYPEPOSQUERY: - count = 2; - goto QS2; - - case OP_EXTUNI_EXTRA + OP_TYPESTAR: - case OP_EXTUNI_EXTRA + OP_TYPEMINSTAR: - case OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR: - count = 0; - - QS2: - - ADD_ACTIVE(state_offset + 2, 0); - if (clen > 0) - { - int ncount = 0; - if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR || - codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSQUERY) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - (void)PRIV(extuni)(c, ptr + clen, mb->start_subject, end_subject, utf, - &ncount); - ADD_NEW_DATA(-(state_offset + count), 0, ncount); - } - break; -#endif - - /*-----------------------------------------------------------------*/ - case OP_ANYNL_EXTRA + OP_TYPEQUERY: - case OP_ANYNL_EXTRA + OP_TYPEMINQUERY: - case OP_ANYNL_EXTRA + OP_TYPEPOSQUERY: - count = 2; - goto QS3; - - case OP_ANYNL_EXTRA + OP_TYPESTAR: - case OP_ANYNL_EXTRA + OP_TYPEMINSTAR: - case OP_ANYNL_EXTRA + OP_TYPEPOSSTAR: - count = 0; - - QS3: - ADD_ACTIVE(state_offset + 2, 0); - if (clen > 0) - { - int ncount = 0; - switch (c) - { - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#ifndef EBCDIC - case 0x2028: - case 0x2029: -#endif /* Not EBCDIC */ - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) break; - goto ANYNL02; - - case CHAR_CR: - if (ptr + 1 < end_subject && UCHAR21TEST(ptr + 1) == CHAR_LF) ncount = 1; - /* Fall through */ - - ANYNL02: - case CHAR_LF: - if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR || - codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW_DATA(-(state_offset + (int)count), 0, ncount); - break; - - default: - break; - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_VSPACE_EXTRA + OP_TYPEQUERY: - case OP_VSPACE_EXTRA + OP_TYPEMINQUERY: - case OP_VSPACE_EXTRA + OP_TYPEPOSQUERY: - count = 2; - goto QS4; - - case OP_VSPACE_EXTRA + OP_TYPESTAR: - case OP_VSPACE_EXTRA + OP_TYPEMINSTAR: - case OP_VSPACE_EXTRA + OP_TYPEPOSSTAR: - count = 0; - - QS4: - ADD_ACTIVE(state_offset + 2, 0); - if (clen > 0) - { - BOOL OK; - switch (c) - { - VSPACE_CASES: - OK = TRUE; - break; - - default: - OK = FALSE; - break; - } - if (OK == (d == OP_VSPACE)) - { - if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSSTAR || - codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSQUERY) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW_DATA(-(state_offset + (int)count), 0, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_HSPACE_EXTRA + OP_TYPEQUERY: - case OP_HSPACE_EXTRA + OP_TYPEMINQUERY: - case OP_HSPACE_EXTRA + OP_TYPEPOSQUERY: - count = 2; - goto QS5; - - case OP_HSPACE_EXTRA + OP_TYPESTAR: - case OP_HSPACE_EXTRA + OP_TYPEMINSTAR: - case OP_HSPACE_EXTRA + OP_TYPEPOSSTAR: - count = 0; - - QS5: - ADD_ACTIVE(state_offset + 2, 0); - if (clen > 0) - { - BOOL OK; - switch (c) - { - HSPACE_CASES: - OK = TRUE; - break; - - default: - OK = FALSE; - break; - } - - if (OK == (d == OP_HSPACE)) - { - if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSSTAR || - codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSQUERY) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW_DATA(-(state_offset + (int)count), 0, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ -#ifdef SUPPORT_UNICODE - case OP_PROP_EXTRA + OP_TYPEEXACT: - case OP_PROP_EXTRA + OP_TYPEUPTO: - case OP_PROP_EXTRA + OP_TYPEMINUPTO: - case OP_PROP_EXTRA + OP_TYPEPOSUPTO: - if (codevalue != OP_PROP_EXTRA + OP_TYPEEXACT) - { ADD_ACTIVE(state_offset + 1 + IMM2_SIZE + 3, 0); } - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - BOOL OK; - int chartype; - const uint32_t *cp; - const ucd_record * prop = GET_UCD(c); - switch(code[1 + IMM2_SIZE + 1]) - { - case PT_LAMP: - chartype = prop->chartype; - OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt; - break; - - case PT_GC: - OK = PRIV(ucp_gentype)[prop->chartype] == code[1 + IMM2_SIZE + 2]; - break; - - case PT_PC: - OK = prop->chartype == code[1 + IMM2_SIZE + 2]; - break; - - case PT_SC: - OK = prop->script == code[1 + IMM2_SIZE + 2]; - break; - - case PT_SCX: - OK = (prop->script == code[1 + IMM2_SIZE + 2] || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), - code[1 + IMM2_SIZE + 2]) != 0); - break; - - /* These are specials for combination cases. */ - - case PT_ALNUM: - chartype = prop->chartype; - OK = PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N; - break; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - switch(c) - { - HSPACE_CASES: - VSPACE_CASES: - OK = TRUE; - break; - - default: - OK = PRIV(ucp_gentype)[prop->chartype] == ucp_Z; - break; - } - break; - - case PT_WORD: - chartype = prop->chartype; - OK = PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc; - break; - - case PT_CLIST: -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (c > MAX_UTF_CODE_POINT) - { - OK = FALSE; - break; - } -#endif - cp = PRIV(ucd_caseless_sets) + code[1 + IMM2_SIZE + 2]; - for (;;) - { - if (c < *cp) { OK = FALSE; break; } - if (c == *cp++) { OK = TRUE; break; } - } - break; - - case PT_UCNC: - OK = c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT || - c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) || - c >= 0xe000; - break; - - case PT_BIDICL: - OK = UCD_BIDICLASS(c) == code[1 + IMM2_SIZE + 2]; - break; - - case PT_BOOL: - OK = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), code[1 + IMM2_SIZE + 2]) != 0; - break; - - /* Should never occur, but keep compilers from grumbling. */ - - default: - OK = codevalue != OP_PROP; - break; - } - - if (OK == (d == OP_PROP)) - { - if (codevalue == OP_PROP_EXTRA + OP_TYPEPOSUPTO) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - if (++count >= (int)GET2(code, 1)) - { ADD_NEW(state_offset + 1 + IMM2_SIZE + 3, 0); } - else - { ADD_NEW(state_offset, count); } - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_EXTUNI_EXTRA + OP_TYPEEXACT: - case OP_EXTUNI_EXTRA + OP_TYPEUPTO: - case OP_EXTUNI_EXTRA + OP_TYPEMINUPTO: - case OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO: - if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT) - { ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); } - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - PCRE2_SPTR nptr; - int ncount = 0; - if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - nptr = PRIV(extuni)(c, ptr + clen, mb->start_subject, end_subject, utf, - &ncount); - if (nptr >= end_subject && (mb->moptions & PCRE2_PARTIAL_HARD) != 0) - reset_could_continue = TRUE; - if (++count >= (int)GET2(code, 1)) - { ADD_NEW_DATA(-(state_offset + 2 + IMM2_SIZE), 0, ncount); } - else - { ADD_NEW_DATA(-state_offset, count, ncount); } - } - break; -#endif - - /*-----------------------------------------------------------------*/ - case OP_ANYNL_EXTRA + OP_TYPEEXACT: - case OP_ANYNL_EXTRA + OP_TYPEUPTO: - case OP_ANYNL_EXTRA + OP_TYPEMINUPTO: - case OP_ANYNL_EXTRA + OP_TYPEPOSUPTO: - if (codevalue != OP_ANYNL_EXTRA + OP_TYPEEXACT) - { ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); } - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - int ncount = 0; - switch (c) - { - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#ifndef EBCDIC - case 0x2028: - case 0x2029: -#endif /* Not EBCDIC */ - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) break; - goto ANYNL03; - - case CHAR_CR: - if (ptr + 1 < end_subject && UCHAR21TEST(ptr + 1) == CHAR_LF) ncount = 1; - /* Fall through */ - - ANYNL03: - case CHAR_LF: - if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - if (++count >= (int)GET2(code, 1)) - { ADD_NEW_DATA(-(state_offset + 2 + IMM2_SIZE), 0, ncount); } - else - { ADD_NEW_DATA(-state_offset, count, ncount); } - break; - - default: - break; - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_VSPACE_EXTRA + OP_TYPEEXACT: - case OP_VSPACE_EXTRA + OP_TYPEUPTO: - case OP_VSPACE_EXTRA + OP_TYPEMINUPTO: - case OP_VSPACE_EXTRA + OP_TYPEPOSUPTO: - if (codevalue != OP_VSPACE_EXTRA + OP_TYPEEXACT) - { ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); } - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - BOOL OK; - switch (c) - { - VSPACE_CASES: - OK = TRUE; - break; - - default: - OK = FALSE; - } - - if (OK == (d == OP_VSPACE)) - { - if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSUPTO) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - if (++count >= (int)GET2(code, 1)) - { ADD_NEW_DATA(-(state_offset + 2 + IMM2_SIZE), 0, 0); } - else - { ADD_NEW_DATA(-state_offset, count, 0); } - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_HSPACE_EXTRA + OP_TYPEEXACT: - case OP_HSPACE_EXTRA + OP_TYPEUPTO: - case OP_HSPACE_EXTRA + OP_TYPEMINUPTO: - case OP_HSPACE_EXTRA + OP_TYPEPOSUPTO: - if (codevalue != OP_HSPACE_EXTRA + OP_TYPEEXACT) - { ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); } - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - BOOL OK; - switch (c) - { - HSPACE_CASES: - OK = TRUE; - break; - - default: - OK = FALSE; - break; - } - - if (OK == (d == OP_HSPACE)) - { - if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSUPTO) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - if (++count >= (int)GET2(code, 1)) - { ADD_NEW_DATA(-(state_offset + 2 + IMM2_SIZE), 0, 0); } - else - { ADD_NEW_DATA(-state_offset, count, 0); } - } - } - break; - -/* ========================================================================== */ - /* These opcodes are followed by a character that is usually compared - to the current subject character; it is loaded into d. We still get - here even if there is no subject character, because in some cases zero - repetitions are permitted. */ - - /*-----------------------------------------------------------------*/ - case OP_CHAR: - if (clen > 0 && c == d) { ADD_NEW(state_offset + dlen + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - case OP_CHARI: - if (clen == 0) break; - -#ifdef SUPPORT_UNICODE - if (utf_or_ucp) - { - if (c == d) { ADD_NEW(state_offset + dlen + 1, 0); } else - { - unsigned int othercase; - if (c < 128) - othercase = fcc[c]; - else - othercase = UCD_OTHERCASE(c); - if (d == othercase) { ADD_NEW(state_offset + dlen + 1, 0); } - } - } - else -#endif /* SUPPORT_UNICODE */ - /* Not UTF or UCP mode */ - { - if (TABLE_GET(c, lcc, c) == TABLE_GET(d, lcc, d)) - { ADD_NEW(state_offset + 2, 0); } - } - break; - - -#ifdef SUPPORT_UNICODE - /*-----------------------------------------------------------------*/ - /* This is a tricky one because it can match more than one character. - Find out how many characters to skip, and then set up a negative state - to wait for them to pass before continuing. */ - - case OP_EXTUNI: - if (clen > 0) - { - int ncount = 0; - PCRE2_SPTR nptr = PRIV(extuni)(c, ptr + clen, mb->start_subject, - end_subject, utf, &ncount); - if (nptr >= end_subject && (mb->moptions & PCRE2_PARTIAL_HARD) != 0) - reset_could_continue = TRUE; - ADD_NEW_DATA(-(state_offset + 1), 0, ncount); - } - break; -#endif - - /*-----------------------------------------------------------------*/ - /* This is a tricky like EXTUNI because it too can match more than one - character (when CR is followed by LF). In this case, set up a negative - state to wait for one character to pass before continuing. */ - - case OP_ANYNL: - if (clen > 0) switch(c) - { - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#ifndef EBCDIC - case 0x2028: - case 0x2029: -#endif /* Not EBCDIC */ - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) break; - PCRE2_FALLTHROUGH /* Fall through */ - - case CHAR_LF: - ADD_NEW(state_offset + 1, 0); - break; - - case CHAR_CR: - if (ptr + 1 >= end_subject) - { - ADD_NEW(state_offset + 1, 0); - if ((mb->moptions & PCRE2_PARTIAL_HARD) != 0) - reset_could_continue = TRUE; - } - else if (UCHAR21TEST(ptr + 1) == CHAR_LF) - { - ADD_NEW_DATA(-(state_offset + 1), 0, 1); - } - else - { - ADD_NEW(state_offset + 1, 0); - } - break; - } - break; - - /*-----------------------------------------------------------------*/ - case OP_NOT_VSPACE: - if (clen > 0) switch(c) - { - VSPACE_CASES: - break; - - default: - ADD_NEW(state_offset + 1, 0); - break; - } - break; - - /*-----------------------------------------------------------------*/ - case OP_VSPACE: - if (clen > 0) switch(c) - { - VSPACE_CASES: - ADD_NEW(state_offset + 1, 0); - break; - - default: - break; - } - break; - - /*-----------------------------------------------------------------*/ - case OP_NOT_HSPACE: - if (clen > 0) switch(c) - { - HSPACE_CASES: - break; - - default: - ADD_NEW(state_offset + 1, 0); - break; - } - break; - - /*-----------------------------------------------------------------*/ - case OP_HSPACE: - if (clen > 0) switch(c) - { - HSPACE_CASES: - ADD_NEW(state_offset + 1, 0); - break; - - default: - break; - } - break; - - /*-----------------------------------------------------------------*/ - /* Match a negated single character casefully. */ - - case OP_NOT: - if (clen > 0 && c != d) { ADD_NEW(state_offset + dlen + 1, 0); } - break; - - /*-----------------------------------------------------------------*/ - /* Match a negated single character caselessly. */ - - case OP_NOTI: - if (clen > 0) - { - uint32_t otherd; -#ifdef SUPPORT_UNICODE - if (utf_or_ucp && d >= 128) - otherd = UCD_OTHERCASE(d); - else -#endif /* SUPPORT_UNICODE */ - otherd = TABLE_GET(d, fcc, d); - if (c != d && c != otherd) - { ADD_NEW(state_offset + dlen + 1, 0); } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_PLUSI: - case OP_MINPLUSI: - case OP_POSPLUSI: - case OP_NOTPLUSI: - case OP_NOTMINPLUSI: - case OP_NOTPOSPLUSI: - caseless = TRUE; - codevalue -= OP_STARI - OP_STAR; - - PCRE2_FALLTHROUGH /* Fall through */ - case OP_PLUS: - case OP_MINPLUS: - case OP_POSPLUS: - case OP_NOTPLUS: - case OP_NOTMINPLUS: - case OP_NOTPOSPLUS: - count = current_state->count; /* Already matched */ - if (count > 0) { ADD_ACTIVE(state_offset + dlen + 1, 0); } - if (clen > 0) - { - uint32_t otherd = NOTACHAR; - if (caseless) - { -#ifdef SUPPORT_UNICODE - if (utf_or_ucp && d >= 128) - otherd = UCD_OTHERCASE(d); - else -#endif /* SUPPORT_UNICODE */ - otherd = TABLE_GET(d, fcc, d); - } - if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) - { - if (count > 0 && - (codevalue == OP_POSPLUS || codevalue == OP_NOTPOSPLUS)) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - count++; - ADD_NEW(state_offset, count); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_QUERYI: - case OP_MINQUERYI: - case OP_POSQUERYI: - case OP_NOTQUERYI: - case OP_NOTMINQUERYI: - case OP_NOTPOSQUERYI: - caseless = TRUE; - codevalue -= OP_STARI - OP_STAR; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_QUERY: - case OP_MINQUERY: - case OP_POSQUERY: - case OP_NOTQUERY: - case OP_NOTMINQUERY: - case OP_NOTPOSQUERY: - ADD_ACTIVE(state_offset + dlen + 1, 0); - if (clen > 0) - { - uint32_t otherd = NOTACHAR; - if (caseless) - { -#ifdef SUPPORT_UNICODE - if (utf_or_ucp && d >= 128) - otherd = UCD_OTHERCASE(d); - else -#endif /* SUPPORT_UNICODE */ - otherd = TABLE_GET(d, fcc, d); - } - if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) - { - if (codevalue == OP_POSQUERY || codevalue == OP_NOTPOSQUERY) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW(state_offset + dlen + 1, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_STARI: - case OP_MINSTARI: - case OP_POSSTARI: - case OP_NOTSTARI: - case OP_NOTMINSTARI: - case OP_NOTPOSSTARI: - caseless = TRUE; - codevalue -= OP_STARI - OP_STAR; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_STAR: - case OP_MINSTAR: - case OP_POSSTAR: - case OP_NOTSTAR: - case OP_NOTMINSTAR: - case OP_NOTPOSSTAR: - ADD_ACTIVE(state_offset + dlen + 1, 0); - if (clen > 0) - { - uint32_t otherd = NOTACHAR; - if (caseless) - { -#ifdef SUPPORT_UNICODE - if (utf_or_ucp && d >= 128) - otherd = UCD_OTHERCASE(d); - else -#endif /* SUPPORT_UNICODE */ - otherd = TABLE_GET(d, fcc, d); - } - if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) - { - if (codevalue == OP_POSSTAR || codevalue == OP_NOTPOSSTAR) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW(state_offset, 0); - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_EXACTI: - case OP_NOTEXACTI: - caseless = TRUE; - codevalue -= OP_STARI - OP_STAR; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_EXACT: - case OP_NOTEXACT: - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - uint32_t otherd = NOTACHAR; - if (caseless) - { -#ifdef SUPPORT_UNICODE - if (utf_or_ucp && d >= 128) - otherd = UCD_OTHERCASE(d); - else -#endif /* SUPPORT_UNICODE */ - otherd = TABLE_GET(d, fcc, d); - } - if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) - { - if (++count >= (int)GET2(code, 1)) - { ADD_NEW(state_offset + dlen + 1 + IMM2_SIZE, 0); } - else - { ADD_NEW(state_offset, count); } - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_UPTOI: - case OP_MINUPTOI: - case OP_POSUPTOI: - case OP_NOTUPTOI: - case OP_NOTMINUPTOI: - case OP_NOTPOSUPTOI: - caseless = TRUE; - codevalue -= OP_STARI - OP_STAR; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_UPTO: - case OP_MINUPTO: - case OP_POSUPTO: - case OP_NOTUPTO: - case OP_NOTMINUPTO: - case OP_NOTPOSUPTO: - ADD_ACTIVE(state_offset + dlen + 1 + IMM2_SIZE, 0); - count = current_state->count; /* Number already matched */ - if (clen > 0) - { - uint32_t otherd = NOTACHAR; - if (caseless) - { -#ifdef SUPPORT_UNICODE - if (utf_or_ucp && d >= 128) - otherd = UCD_OTHERCASE(d); - else -#endif /* SUPPORT_UNICODE */ - otherd = TABLE_GET(d, fcc, d); - } - if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) - { - if (codevalue == OP_POSUPTO || codevalue == OP_NOTPOSUPTO) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - if (++count >= (int)GET2(code, 1)) - { ADD_NEW(state_offset + dlen + 1 + IMM2_SIZE, 0); } - else - { ADD_NEW(state_offset, count); } - } - } - break; - - -/* ========================================================================== */ - /* These are the class-handling opcodes */ - - case OP_CLASS: - case OP_NCLASS: -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - case OP_ECLASS: -#endif - { - BOOL isinclass = FALSE; - int next_state_offset; - PCRE2_SPTR ecode; - -#ifdef SUPPORT_WIDE_CHARS - /* An extended class may have a table or a list of single characters, - ranges, or both, and it may be positive or negative. There's a - function that sorts all this out. */ - - if (codevalue == OP_XCLASS) - { - ecode = code + GET(code, 1); - if (clen > 0) - isinclass = PRIV(xclass)(c, code + 1 + LINK_SIZE, - (const uint8_t*)mb->start_code, utf); - } - - /* A nested set-based class has internal opcodes for performing - set operations. */ - - else if (codevalue == OP_ECLASS) - { - ecode = code + GET(code, 1); - if (clen > 0) - isinclass = PRIV(eclass)(c, code + 1 + LINK_SIZE, ecode, - (const uint8_t*)mb->start_code, utf); - } - - else -#endif /* SUPPORT_WIDE_CHARS */ - - /* For a simple class, there is always just a 32-byte table, and we - can set isinclass from it. */ - - { - ecode = code + 1 + (32 / sizeof(PCRE2_UCHAR)); - if (clen > 0) - { - isinclass = (c > 255)? (codevalue == OP_NCLASS) : - ((((const uint8_t *)(code + 1))[c/8] & (1u << (c&7))) != 0); - } - } - - /* At this point, isinclass is set for all kinds of class, and ecode - points to the byte after the end of the class. If there is a - quantifier, this is where it will be. */ - - next_state_offset = (int)(ecode - start_code); - - switch (*ecode) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPOSSTAR: - ADD_ACTIVE(next_state_offset + 1, 0); - if (isinclass) - { - if (*ecode == OP_CRPOSSTAR) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW(state_offset, 0); - } - break; - - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRPOSPLUS: - count = current_state->count; /* Already matched */ - if (count > 0) { ADD_ACTIVE(next_state_offset + 1, 0); } - if (isinclass) - { - if (count > 0 && *ecode == OP_CRPOSPLUS) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - count++; - ADD_NEW(state_offset, count); - } - break; - - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSQUERY: - ADD_ACTIVE(next_state_offset + 1, 0); - if (isinclass) - { - if (*ecode == OP_CRPOSQUERY) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - ADD_NEW(next_state_offset + 1, 0); - } - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - count = current_state->count; /* Already matched */ - if (count >= (int)GET2(ecode, 1)) - { ADD_ACTIVE(next_state_offset + 1 + 2 * IMM2_SIZE, 0); } - if (isinclass) - { - int max = (int)GET2(ecode, 1 + IMM2_SIZE); - - if (*ecode == OP_CRPOSRANGE && count >= (int)GET2(ecode, 1)) - { - active_count--; /* Remove non-match possibility */ - next_active_state--; - } - - if (++count >= max && max != 0) /* Max 0 => no limit */ - { ADD_NEW(next_state_offset + 1 + 2 * IMM2_SIZE, 0); } - else - { ADD_NEW(state_offset, count); } - } - break; - - default: - if (isinclass) { ADD_NEW(next_state_offset, 0); } - break; - } - } - break; - -/* ========================================================================== */ - /* These are the opcodes for fancy brackets of various kinds. We have - to use recursion in order to handle them. The "always failing" assertion - (?!) is optimised to OP_FAIL when compiling, so we have to support that, - though the other "backtracking verbs" are not supported. */ - - case OP_FAIL: - break; - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - { - int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; - PCRE2_SPTR endasscode = code + GET(code, 1); - RWS_anchor *rws = (RWS_anchor *)RWS; - - if (rws->free < RWS_RSIZE + RWS_OVEC_OSIZE) - { - rc = more_workspace(&rws, RWS_OVEC_OSIZE, mb); - if (rc != 0) return rc; - RWS = (int *)rws; - } - - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; - rws->free -= RWS_RSIZE + RWS_OVEC_OSIZE; - - while (*endasscode == OP_ALT) endasscode += GET(endasscode, 1); - - rc = internal_dfa_match( - mb, /* static match data */ - code, /* this subexpression's code */ - ptr, /* where we currently are */ - (PCRE2_SIZE)(ptr - start_subject), /* start offset */ - local_offsets, /* offset vector */ - RWS_OVEC_OSIZE/OVEC_UNIT, /* size of same */ - local_workspace, /* workspace vector */ - RWS_RSIZE, /* size of same */ - rlevel, /* function recursion level */ - RWS); /* recursion workspace */ - - rws->free += RWS_RSIZE + RWS_OVEC_OSIZE; - - if (rc < 0 && rc != PCRE2_ERROR_NOMATCH) return rc; - if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK)) - { ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_COND: - case OP_SCOND: - { - int codelink = (int)GET(code, 1); - PCRE2_UCHAR condcode; - - /* Because of the way auto-callout works during compile, a callout item - is inserted between OP_COND and an assertion condition. This does not - happen for the other conditions. */ - - if (code[LINK_SIZE + 1] == OP_CALLOUT - || code[LINK_SIZE + 1] == OP_CALLOUT_STR) - { - PCRE2_SIZE callout_length; - rrc = do_callout_dfa(code, offsets, current_subject, ptr, mb, - 1 + LINK_SIZE, &callout_length); - if (rrc < 0) return rrc; /* Abandon */ - if (rrc > 0) break; /* Fail this thread */ - code += callout_length; /* Skip callout data */ - } - - condcode = code[LINK_SIZE+1]; - - /* Back reference conditions and duplicate named recursion conditions - are not supported */ - - if (condcode == OP_CREF || condcode == OP_DNCREF || - condcode == OP_DNRREF) - return PCRE2_ERROR_DFA_UCOND; - - /* The DEFINE condition is always false, and the assertion (?!) is - converted to OP_FAIL. */ - - if (condcode == OP_FALSE || condcode == OP_FAIL) - { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); } - - /* There is also an always-true condition */ - - else if (condcode == OP_TRUE) - { ADD_ACTIVE(state_offset + LINK_SIZE + 2, 0); } - - /* The only supported version of OP_RREF is for the value RREF_ANY, - which means "test if in any recursion". We can't test for specifically - recursed groups. */ - - else if (condcode == OP_RREF) - { - unsigned int value = GET2(code, LINK_SIZE + 2); - if (value != RREF_ANY) return PCRE2_ERROR_DFA_UCOND; - if (mb->recursive != NULL) - { ADD_ACTIVE(state_offset + LINK_SIZE + 2 + IMM2_SIZE, 0); } - else { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); } - } - - /* Otherwise, the condition is an assertion */ - - else - { - int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; - PCRE2_SPTR asscode = code + LINK_SIZE + 1; - PCRE2_SPTR endasscode = asscode + GET(asscode, 1); - RWS_anchor *rws = (RWS_anchor *)RWS; - - if (rws->free < RWS_RSIZE + RWS_OVEC_OSIZE) - { - rc = more_workspace(&rws, RWS_OVEC_OSIZE, mb); - if (rc != 0) return rc; - RWS = (int *)rws; - } - - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; - rws->free -= RWS_RSIZE + RWS_OVEC_OSIZE; - - while (*endasscode == OP_ALT) endasscode += GET(endasscode, 1); - - rc = internal_dfa_match( - mb, /* fixed match data */ - asscode, /* this subexpression's code */ - ptr, /* where we currently are */ - (PCRE2_SIZE)(ptr - start_subject), /* start offset */ - local_offsets, /* offset vector */ - RWS_OVEC_OSIZE/OVEC_UNIT, /* size of same */ - local_workspace, /* workspace vector */ - RWS_RSIZE, /* size of same */ - rlevel, /* function recursion level */ - RWS); /* recursion workspace */ - - rws->free += RWS_RSIZE + RWS_OVEC_OSIZE; - - if (rc < 0 && rc != PCRE2_ERROR_NOMATCH) return rc; - if ((rc >= 0) == - (condcode == OP_ASSERT || condcode == OP_ASSERTBACK)) - { ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); } - else - { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); } - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_RECURSE: - { - int rc; - int *local_workspace; - dfa_recursion_info *ri; - PCRE2_SIZE *local_offsets; - RWS_anchor *rws = (RWS_anchor *)RWS; - PCRE2_SPTR callpat = start_code + GET(code, 1); - uint32_t recno = (callpat == mb->start_code)? 0 : - GET2(callpat, 1 + LINK_SIZE); - - /* Argument list has not been supported yet. */ - if (code[1 + LINK_SIZE] == OP_CREF) return PCRE2_ERROR_DFA_UITEM; - - if (rws->free < RWS_RSIZE + RWS_OVEC_RSIZE) - { - rc = more_workspace(&rws, RWS_OVEC_RSIZE, mb); - if (rc != 0) return rc; - RWS = (int *)rws; - } - - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_RSIZE; - rws->free -= RWS_RSIZE + RWS_OVEC_RSIZE; - - /* Check for repeating a recursion without advancing the subject - pointer or last used character. This should catch convoluted mutual - recursions. (Some simple cases are caught at compile time.) */ - - for (ri = mb->recursive; - ri != NULL; - ri = ri->prevrec) - { - if (recno == ri->group_num && ptr == ri->subject_position && - mb->last_used_ptr == ri->last_used_ptr) - return PCRE2_ERROR_RECURSELOOP; - } - - /* Remember this recursion and where we started it so as to - catch infinite loops. */ - - new_recursive.group_num = recno; - new_recursive.subject_position = ptr; - new_recursive.last_used_ptr = mb->last_used_ptr; - new_recursive.prevrec = mb->recursive; - mb->recursive = &new_recursive; - - rc = internal_dfa_match( - mb, /* fixed match data */ - callpat, /* this subexpression's code */ - ptr, /* where we currently are */ - (PCRE2_SIZE)(ptr - start_subject), /* start offset */ - local_offsets, /* offset vector */ - RWS_OVEC_RSIZE/OVEC_UNIT, /* size of same */ - local_workspace, /* workspace vector */ - RWS_RSIZE, /* size of same */ - rlevel, /* function recursion level */ - RWS); /* recursion workspace */ - - rws->free += RWS_RSIZE + RWS_OVEC_RSIZE; - mb->recursive = new_recursive.prevrec; /* Done this recursion */ - - /* Ran out of internal offsets */ - - if (rc == 0) return PCRE2_ERROR_DFA_RECURSE; - - /* For each successful matched substring, set up the next state with a - count of characters to skip before trying it. Note that the count is in - characters, not bytes. */ - - if (rc > 0) - { - for (rc = rc*2 - 2; rc >= 0; rc -= 2) - { - PCRE2_SIZE charcount = local_offsets[rc+1] - local_offsets[rc]; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (utf) - { - PCRE2_SPTR p = start_subject + local_offsets[rc]; - PCRE2_SPTR pp = start_subject + local_offsets[rc+1]; - while (p < pp) if (NOT_FIRSTCU(*p++)) charcount--; - } -#endif - if (charcount > 0) - { - ADD_NEW_DATA(-(state_offset + LINK_SIZE + 1), 0, - (int)(charcount - 1)); - } - else - { - ADD_ACTIVE(state_offset + LINK_SIZE + 1, 0); - } - } - } - else if (rc != PCRE2_ERROR_NOMATCH) return rc; - } - break; - - /*-----------------------------------------------------------------*/ - case OP_BRAPOS: - case OP_SBRAPOS: - case OP_CBRAPOS: - case OP_SCBRAPOS: - case OP_BRAPOSZERO: - { - int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; - PCRE2_SIZE charcount, matched_count; - PCRE2_SPTR local_ptr = ptr; - RWS_anchor *rws = (RWS_anchor *)RWS; - BOOL allow_zero; - - if (rws->free < RWS_RSIZE + RWS_OVEC_OSIZE) - { - rc = more_workspace(&rws, RWS_OVEC_OSIZE, mb); - if (rc != 0) return rc; - RWS = (int *)rws; - } - - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; - rws->free -= RWS_RSIZE + RWS_OVEC_OSIZE; - - if (codevalue == OP_BRAPOSZERO) - { - allow_zero = TRUE; - ++code; /* The following opcode will be one of the above BRAs */ - } - else allow_zero = FALSE; - - /* Loop to match the subpattern as many times as possible as if it were - a complete pattern. */ - - for (matched_count = 0;; matched_count++) - { - rc = internal_dfa_match( - mb, /* fixed match data */ - code, /* this subexpression's code */ - local_ptr, /* where we currently are */ - (PCRE2_SIZE)(ptr - start_subject), /* start offset */ - local_offsets, /* offset vector */ - RWS_OVEC_OSIZE/OVEC_UNIT, /* size of same */ - local_workspace, /* workspace vector */ - RWS_RSIZE, /* size of same */ - rlevel, /* function recursion level */ - RWS); /* recursion workspace */ - - /* Failed to match */ - - if (rc < 0) - { - if (rc != PCRE2_ERROR_NOMATCH) return rc; - break; - } - - /* Matched: break the loop if zero characters matched. */ - - charcount = local_offsets[1] - local_offsets[0]; - if (charcount == 0) break; - local_ptr += charcount; /* Advance temporary position ptr */ - } - - rws->free += RWS_RSIZE + RWS_OVEC_OSIZE; - - /* At this point we have matched the subpattern matched_count - times, and local_ptr is pointing to the character after the end of the - last match. */ - - if (matched_count > 0 || allow_zero) - { - PCRE2_SPTR end_subpattern = code; - int next_state_offset; - - do { end_subpattern += GET(end_subpattern, 1); } - while (*end_subpattern == OP_ALT); - next_state_offset = - (int)(end_subpattern - start_code + LINK_SIZE + 1); - - /* Optimization: if there are no more active states, and there - are no new states yet set up, then skip over the subject string - right here, to save looping. Otherwise, set up the new state to swing - into action when the end of the matched substring is reached. */ - - if (i + 1 >= active_count && new_count == 0) - { - ptr = local_ptr; - clen = 0; - ADD_NEW(next_state_offset, 0); - } - else - { - PCRE2_SPTR p = ptr; - PCRE2_SPTR pp = local_ptr; - charcount = (PCRE2_SIZE)(pp - p); -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (utf) while (p < pp) if (NOT_FIRSTCU(*p++)) charcount--; -#endif - ADD_NEW_DATA(-next_state_offset, 0, (int)(charcount - 1)); - } - } - } - break; - - /*-----------------------------------------------------------------*/ - case OP_ONCE: - { - int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; - RWS_anchor *rws = (RWS_anchor *)RWS; - - if (rws->free < RWS_RSIZE + RWS_OVEC_OSIZE) - { - rc = more_workspace(&rws, RWS_OVEC_OSIZE, mb); - if (rc != 0) return rc; - RWS = (int *)rws; - } - - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; - rws->free -= RWS_RSIZE + RWS_OVEC_OSIZE; - - rc = internal_dfa_match( - mb, /* fixed match data */ - code, /* this subexpression's code */ - ptr, /* where we currently are */ - (PCRE2_SIZE)(ptr - start_subject), /* start offset */ - local_offsets, /* offset vector */ - RWS_OVEC_OSIZE/OVEC_UNIT, /* size of same */ - local_workspace, /* workspace vector */ - RWS_RSIZE, /* size of same */ - rlevel, /* function recursion level */ - RWS); /* recursion workspace */ - - rws->free += RWS_RSIZE + RWS_OVEC_OSIZE; - - if (rc >= 0) - { - PCRE2_SPTR end_subpattern = code; - PCRE2_SIZE charcount = local_offsets[1] - local_offsets[0]; - int next_state_offset, repeat_state_offset; - - do { end_subpattern += GET(end_subpattern, 1); } - while (*end_subpattern == OP_ALT); - next_state_offset = - (int)(end_subpattern - start_code + LINK_SIZE + 1); - - /* If the end of this subpattern is KETRMAX or KETRMIN, we must - arrange for the repeat state also to be added to the relevant list. - Calculate the offset, or set -1 for no repeat. */ - - repeat_state_offset = (*end_subpattern == OP_KETRMAX || - *end_subpattern == OP_KETRMIN)? - (int)(end_subpattern - start_code - GET(end_subpattern, 1)) : -1; - - /* If we have matched an empty string, add the next state at the - current character pointer. This is important so that the duplicate - checking kicks in, which is what breaks infinite loops that match an - empty string. */ - - if (charcount == 0) - { - ADD_ACTIVE(next_state_offset, 0); - } - - /* Optimization: if there are no more active states, and there - are no new states yet set up, then skip over the subject string - right here, to save looping. Otherwise, set up the new state to swing - into action when the end of the matched substring is reached. */ - - else if (i + 1 >= active_count && new_count == 0) - { - ptr += charcount; - clen = 0; - ADD_NEW(next_state_offset, 0); - - /* If we are adding a repeat state at the new character position, - we must fudge things so that it is the only current state. - Otherwise, it might be a duplicate of one we processed before, and - that would cause it to be skipped. */ - - if (repeat_state_offset >= 0) - { - next_active_state = active_states; - active_count = 0; - i = -1; - ADD_ACTIVE(repeat_state_offset, 0); - } - } - else - { -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (utf) - { - PCRE2_SPTR p = start_subject + local_offsets[0]; - PCRE2_SPTR pp = start_subject + local_offsets[1]; - while (p < pp) if (NOT_FIRSTCU(*p++)) charcount--; - } -#endif - ADD_NEW_DATA(-next_state_offset, 0, (int)(charcount - 1)); - if (repeat_state_offset >= 0) - { ADD_NEW_DATA(-repeat_state_offset, 0, (int)(charcount - 1)); } - } - } - else if (rc != PCRE2_ERROR_NOMATCH) return rc; - } - break; - - -/* ========================================================================== */ - /* Handle callouts */ - - case OP_CALLOUT: - case OP_CALLOUT_STR: - { - PCRE2_SIZE callout_length; - rrc = do_callout_dfa(code, offsets, current_subject, ptr, mb, 0, - &callout_length); - if (rrc < 0) return rrc; /* Abandon */ - if (rrc == 0) - { ADD_ACTIVE(state_offset + (int)callout_length, 0); } - } - break; - - -/* ========================================================================== */ - default: /* Unsupported opcode */ - return PCRE2_ERROR_DFA_UITEM; - } - - NEXT_ACTIVE_STATE: continue; - - } /* End of loop scanning active states */ - - /* We have finished the processing at the current subject character. If no - new states have been set for the next character, we have found all the - matches that we are going to find. If partial matching has been requested, - check for appropriate conditions. - - The "could_continue" variable is true if a state could have continued but - for the fact that the end of the subject was reached. */ - - if (new_count <= 0) - { - if (could_continue && /* Some could go on, and */ - ( /* either... */ - (mb->moptions & PCRE2_PARTIAL_HARD) != 0 /* Hard partial */ - || /* or... */ - ((mb->moptions & PCRE2_PARTIAL_SOFT) != 0 && /* Soft partial and */ - match_count < 0) /* no matches */ - ) && /* And... */ - ( - partial_newline || /* Either partial NL */ - ( /* or ... */ - ptr >= end_subject && /* End of subject and */ - ( /* either */ - ptr > mb->start_used_ptr || /* Inspected non-empty string */ - mb->allowemptypartial /* or pattern has lookbehind */ - ) /* or could match empty */ - ) - )) - match_count = PCRE2_ERROR_PARTIAL; - break; /* Exit from loop along the subject string */ - } - - /* One or more states are active for the next character. */ - - ptr += clen; /* Advance to next subject character */ - } /* Loop to move along the subject string */ - -/* Control gets here from "break" a few lines above. If we have a match and -PCRE2_ENDANCHORED is set, the match fails. */ - -if (match_count >= 0 && - ((mb->moptions | mb->poptions) & PCRE2_ENDANCHORED) != 0 && - ptr < end_subject) - match_count = PCRE2_ERROR_NOMATCH; - -return match_count; -} - - - -/************************************************* -* Match a pattern using the DFA algorithm * -*************************************************/ - -/* This function matches a compiled pattern to a subject string, using the -alternate matching algorithm that finds all matches at once. - -Arguments: - code points to the compiled pattern - subject subject string - length length of subject string - startoffset where to start matching in the subject - options option bits - match_data points to a match data structure - gcontext points to a match context - workspace pointer to workspace - wscount size of workspace - -Returns: > 0 => number of match offset pairs placed in offsets - = 0 => offsets overflowed; longest matches are present - -1 => failed to match - < -1 => some kind of unexpected problem -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_dfa_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, - PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data, - pcre2_match_context *mcontext, int *workspace, PCRE2_SIZE wscount) -{ -int rc; - -const pcre2_real_code *re = (const pcre2_real_code *)code; -uint32_t original_options = options; - -PCRE2_UCHAR null_str[1] = { 0xcd }; -PCRE2_SPTR original_subject = subject; -PCRE2_SPTR start_match; -PCRE2_SPTR end_subject; -PCRE2_SPTR bumpalong_limit; -PCRE2_SPTR req_cu_ptr; - -BOOL utf, anchored, startline, firstline; -BOOL has_first_cu = FALSE; -BOOL has_req_cu = FALSE; - -#if PCRE2_CODE_UNIT_WIDTH == 8 -PCRE2_SPTR memchr_found_first_cu = NULL; -PCRE2_SPTR memchr_found_first_cu2 = NULL; -#endif - -PCRE2_UCHAR first_cu = 0; -PCRE2_UCHAR first_cu2 = 0; -PCRE2_UCHAR req_cu = 0; -PCRE2_UCHAR req_cu2 = 0; - -const uint8_t *start_bits = NULL; - -/* We need to have mb pointing to a match block, because the IS_NEWLINE macro -is used below, and it expects NLBLOCK to be defined as a pointer. */ - -pcre2_callout_block cb; -dfa_match_block actual_match_block; -dfa_match_block *mb = &actual_match_block; - -/* Set up a starting block of memory for use during recursive calls to -internal_dfa_match(). By putting this on the stack, it minimizes resource use -in the case when it is not needed. If this is too small, more memory is -obtained from the heap. At the start of each block is an anchor structure.*/ - -int base_recursion_workspace[RWS_BASE_SIZE]; -RWS_anchor *rws = (RWS_anchor *)base_recursion_workspace; -rws->next = NULL; -rws->size = RWS_BASE_SIZE; -rws->free = RWS_BASE_SIZE - RWS_ANCHOR_SIZE; - -/* Recognize NULL, length 0 as an empty string. */ - -if (subject == NULL && length == 0) subject = null_str; - -/* Plausibility checks */ - -if (match_data == NULL) return PCRE2_ERROR_NULL; -if (re == NULL || subject == NULL || workspace == NULL) - { rc = PCRE2_ERROR_NULL; goto EXIT; } -if ((options & ~PUBLIC_DFA_MATCH_OPTIONS) != 0) - { rc = PCRE2_ERROR_BADOPTION; goto EXIT; } - -if (length == PCRE2_ZERO_TERMINATED) - { - length = PRIV(strlen)(subject); - } - -if (wscount < 20) { rc = PCRE2_ERROR_DFA_WSSIZE; goto EXIT; } -if (start_offset > length) { rc = PCRE2_ERROR_BADOFFSET; goto EXIT; } - -/* Partial matching and PCRE2_ENDANCHORED are currently not allowed at the same -time. */ - -if ((options & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0 && - ((re->overall_options | options) & PCRE2_ENDANCHORED) != 0) - { rc = PCRE2_ERROR_BADOPTION; goto EXIT; } - -/* Invalid UTF support is not available for DFA matching. */ - -if ((re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0) - { rc = PCRE2_ERROR_DFA_UINVALID_UTF; goto EXIT; } - -/* Check that the first field in the block is the magic number. If it is not, -return with PCRE2_ERROR_BADMAGIC. */ - -if (re->magic_number != MAGIC_NUMBER) - { rc = PCRE2_ERROR_BADMAGIC; goto EXIT; } - -/* Check the code unit width. */ - -if ((re->flags & PCRE2_MODE_MASK) != PCRE2_CODE_UNIT_WIDTH/8) - { rc = PCRE2_ERROR_BADMODE; goto EXIT; } - -/* PCRE2_NOTEMPTY and PCRE2_NOTEMPTY_ATSTART are match-time flags in the -options variable for this function. Users of PCRE2 who are not calling the -function directly would like to have a way of setting these flags, in the same -way that they can set pcre2_compile() flags like PCRE2_NO_AUTO_POSSESS with -constructions like (*NO_AUTOPOSSESS). To enable this, (*NOTEMPTY) and -(*NOTEMPTY_ATSTART) set bits in the pattern's "flag" function which can now be -transferred to the options for this function. The bits are guaranteed to be -adjacent, but do not have the same values. This bit of Boolean trickery assumes -that the match-time bits are not more significant than the flag bits. If by -accident this is not the case, a compile-time division by zero error will -occur. */ - -#define FF (PCRE2_NOTEMPTY_SET|PCRE2_NE_ATST_SET) -#define OO (PCRE2_NOTEMPTY|PCRE2_NOTEMPTY_ATSTART) -options |= (re->flags & FF) / ((FF & (~FF+1)) / (OO & (~OO+1))); -#undef FF -#undef OO - -/* If restarting after a partial match, do some sanity checks on the contents -of the workspace. */ - -if ((options & PCRE2_DFA_RESTART) != 0) - { - if ((workspace[0] & (-2)) != 0 || workspace[1] < 1 || - workspace[1] > (int)((wscount - 2)/INTS_PER_STATEBLOCK)) - { rc = PCRE2_ERROR_DFA_BADRESTART; goto EXIT; } - } - -/* Set some local values */ - -utf = (re->overall_options & PCRE2_UTF) != 0; -start_match = subject + start_offset; -end_subject = subject + length; -req_cu_ptr = start_match - 1; -anchored = (options & (PCRE2_ANCHORED|PCRE2_DFA_RESTART)) != 0 || - (re->overall_options & PCRE2_ANCHORED) != 0; - -/* The "must be at the start of a line" flags are used in a loop when finding -where to start. */ - -startline = (re->flags & PCRE2_STARTLINE) != 0; -firstline = !anchored && (re->overall_options & PCRE2_FIRSTLINE) != 0; -bumpalong_limit = end_subject; - -/* Initialize and set up the fixed fields in the callout block, with a pointer -in the match block. */ - -mb->cb = &cb; -cb.version = 2; -cb.subject = subject; -cb.subject_length = (PCRE2_SIZE)(end_subject - subject); -cb.callout_flags = 0; -cb.capture_top = 1; /* No capture support */ -cb.capture_last = 0; -cb.mark = NULL; /* No (*MARK) support */ - -/* Get data from the match context, if present, and fill in the remaining -fields in the match block. It is an error to set an offset limit without -setting the flag at compile time. */ - -if (mcontext == NULL) - { - mb->callout = NULL; - mb->memctl = re->memctl; - mb->match_limit = PRIV(default_match_context).match_limit; - mb->match_limit_depth = PRIV(default_match_context).depth_limit; - mb->heap_limit = PRIV(default_match_context).heap_limit; - } -else - { - if (mcontext->offset_limit != PCRE2_UNSET) - { - if ((re->overall_options & PCRE2_USE_OFFSET_LIMIT) == 0) - { rc = PCRE2_ERROR_BADOFFSETLIMIT; goto EXIT; } - bumpalong_limit = subject + mcontext->offset_limit; - } - mb->callout = mcontext->callout; - mb->callout_data = mcontext->callout_data; - mb->memctl = mcontext->memctl; - mb->match_limit = mcontext->match_limit; - mb->match_limit_depth = mcontext->depth_limit; - mb->heap_limit = mcontext->heap_limit; - } - -if (mb->match_limit > re->limit_match) - mb->match_limit = re->limit_match; - -if (mb->match_limit_depth > re->limit_depth) - mb->match_limit_depth = re->limit_depth; - -if (mb->heap_limit > re->limit_heap) - mb->heap_limit = re->limit_heap; - -mb->start_code = (PCRE2_SPTR)((const uint8_t *)re + re->code_start); -mb->tables = re->tables; -mb->start_subject = subject; -mb->end_subject = end_subject; -mb->start_offset = start_offset; -mb->allowemptypartial = (re->max_lookbehind > 0) || - (re->flags & PCRE2_MATCH_EMPTY) != 0; -mb->moptions = options; -mb->poptions = re->overall_options; -mb->match_call_count = 0; -mb->heap_used = 0; - -/* Process the \R and newline settings. */ - -mb->bsr_convention = re->bsr_convention; -mb->nltype = NLTYPE_FIXED; -switch(re->newline_convention) - { - case PCRE2_NEWLINE_CR: - mb->nllen = 1; - mb->nl[0] = CHAR_CR; - break; - - case PCRE2_NEWLINE_LF: - mb->nllen = 1; - mb->nl[0] = CHAR_NL; - break; - - case PCRE2_NEWLINE_NUL: - mb->nllen = 1; - mb->nl[0] = CHAR_NUL; - break; - - case PCRE2_NEWLINE_CRLF: - mb->nllen = 2; - mb->nl[0] = CHAR_CR; - mb->nl[1] = CHAR_NL; - break; - - case PCRE2_NEWLINE_ANY: - mb->nltype = NLTYPE_ANY; - break; - - case PCRE2_NEWLINE_ANYCRLF: - mb->nltype = NLTYPE_ANYCRLF; - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - rc = PCRE2_ERROR_INTERNAL; - goto EXIT; - /* LCOV_EXCL_STOP */ - } - -/* Check a UTF string for validity if required. For 8-bit and 16-bit strings, -we must also check that a starting offset does not point into the middle of a -multiunit character. We check only the portion of the subject that is going to -be inspected during matching - from the offset minus the maximum back reference -to the given length. This saves time when a small part of a large subject is -being matched by the use of a starting offset. Note that the maximum lookbehind -is a number of characters, not code units. */ - -#ifdef SUPPORT_UNICODE -if (utf && (options & PCRE2_NO_UTF_CHECK) == 0) - { - PCRE2_SPTR check_subject = start_match; /* start_match includes offset */ - - if (start_offset > 0) - { -#if PCRE2_CODE_UNIT_WIDTH != 32 - unsigned int i; - if (start_match < end_subject && NOT_FIRSTCU(*start_match)) - { rc = PCRE2_ERROR_BADUTFOFFSET; goto EXIT; } - for (i = re->max_lookbehind; i > 0 && check_subject > subject; i--) - { - check_subject--; - while (check_subject > subject && -#if PCRE2_CODE_UNIT_WIDTH == 8 - (*check_subject & 0xc0) == 0x80) -#else /* 16-bit */ - (*check_subject & 0xfc00) == 0xdc00) -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - check_subject--; - } -#else /* In the 32-bit library, one code unit equals one character. */ - check_subject -= re->max_lookbehind; - if (check_subject < subject) check_subject = subject; -#endif /* PCRE2_CODE_UNIT_WIDTH != 32 */ - } - - /* Validate the relevant portion of the subject. After an error, adjust the - offset to be an absolute offset in the whole string. */ - - rc = PRIV(valid_utf)(check_subject, - length - (PCRE2_SIZE)(check_subject - subject), &(match_data->startchar)); - if (rc != 0) - { - match_data->startchar += (PCRE2_SIZE)(check_subject - subject); - goto EXIT; - } - } -#endif /* SUPPORT_UNICODE */ - -/* Set up the first code unit to match, if available. If there's no first code -unit there may be a bitmap of possible first characters. */ - -if ((re->flags & PCRE2_FIRSTSET) != 0) - { - has_first_cu = TRUE; - first_cu = first_cu2 = (PCRE2_UCHAR)(re->first_codeunit); - if ((re->flags & PCRE2_FIRSTCASELESS) != 0) - { - first_cu2 = TABLE_GET(first_cu, mb->tables + fcc_offset, first_cu); -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (first_cu > 127 && !utf && (re->overall_options & PCRE2_UCP) != 0) - first_cu2 = (PCRE2_UCHAR)UCD_OTHERCASE(first_cu); -#else - if (first_cu > 127 && (utf || (re->overall_options & PCRE2_UCP) != 0)) - first_cu2 = (PCRE2_UCHAR)UCD_OTHERCASE(first_cu); -#endif -#endif /* SUPPORT_UNICODE */ - } - } -else - if (!startline && (re->flags & PCRE2_FIRSTMAPSET) != 0) - start_bits = re->start_bitmap; - -/* There may be a "last known required code unit" set. */ - -if ((re->flags & PCRE2_LASTSET) != 0) - { - has_req_cu = TRUE; - req_cu = req_cu2 = (PCRE2_UCHAR)(re->last_codeunit); - if ((re->flags & PCRE2_LASTCASELESS) != 0) - { - req_cu2 = TABLE_GET(req_cu, mb->tables + fcc_offset, req_cu); -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (req_cu > 127 && !utf && (re->overall_options & PCRE2_UCP) != 0) - req_cu2 = (PCRE2_UCHAR)UCD_OTHERCASE(req_cu); -#else - if (req_cu > 127 && (utf || (re->overall_options & PCRE2_UCP) != 0)) - req_cu2 = (PCRE2_UCHAR)UCD_OTHERCASE(req_cu); -#endif -#endif /* SUPPORT_UNICODE */ - } - } - -/* If the match data block was previously used with PCRE2_COPY_MATCHED_SUBJECT, -free the memory that was obtained. */ - -if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0) - { - match_data->memctl.free((void *)match_data->subject, - match_data->memctl.memory_data); - match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT; - } - -/* Fill in fields that are always returned in the match data. */ - -match_data->code = re; -match_data->subject = NULL; /* Default for match error */ -match_data->mark = NULL; -match_data->matchedby = PCRE2_MATCHEDBY_DFA_INTERPRETER; -match_data->options = original_options; - -/* Call the main matching function, looping for a non-anchored regex after a -failed match. If not restarting, perform certain optimizations at the start of -a match. */ - -for (;;) - { - /* ----------------- Start of match optimizations ---------------- */ - - /* There are some optimizations that avoid running the match if a known - starting point is not found, or if a known later code unit is not present. - However, there is an option (settable at compile time) that disables - these, for testing and for ensuring that all callouts do actually occur. - The optimizations must also be avoided when restarting a DFA match. */ - - if ((re->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0 && - (options & PCRE2_DFA_RESTART) == 0) - { - /* If firstline is TRUE, the start of the match is constrained to the first - line of a multiline string. That is, the match must be before or at the - first newline following the start of matching. Temporarily adjust - end_subject so that we stop the optimization scans for a first code unit - immediately after the first character of a newline (the first code unit can - legitimately be a newline). If the match fails at the newline, later code - breaks this loop. */ - - if (firstline) - { - PCRE2_SPTR t = start_match; -#ifdef SUPPORT_UNICODE - if (utf) - { - while (t < end_subject && !IS_NEWLINE(t)) - { - t++; - ACROSSCHAR(t < end_subject, t, t++); - } - } - else -#endif - while (t < end_subject && !IS_NEWLINE(t)) t++; - end_subject = t; - } - - /* Anchored: check the first code unit if one is recorded. This may seem - pointless but it can help in detecting a no match case without scanning for - the required code unit. */ - - if (anchored) - { - if (has_first_cu || start_bits != NULL) - { - BOOL ok = start_match < end_subject; - if (ok) - { - PCRE2_UCHAR c = UCHAR21TEST(start_match); - ok = has_first_cu && (c == first_cu || c == first_cu2); - if (!ok && start_bits != NULL) - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (c > 255) c = 255; -#endif - ok = (start_bits[c/8] & (1u << (c&7))) != 0; - } - } - if (!ok) break; - } - } - - /* Not anchored. Advance to a unique first code unit if there is one. */ - - else - { - if (has_first_cu) - { - if (first_cu != first_cu2) /* Caseless */ - { - /* In 16-bit and 32_bit modes we have to do our own search, so can - look for both cases at once. */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 - PCRE2_UCHAR smc; - while (start_match < end_subject && - (smc = UCHAR21TEST(start_match)) != first_cu && - smc != first_cu2) - start_match++; -#else - /* In 8-bit mode, the use of memchr() gives a big speed up, even - though we have to call it twice in order to find the earliest - occurrence of the code unit in either of its cases. Caching is used - to remember the positions of previously found code units. This can - make a huge difference when the strings are very long and only one - case is actually present. */ - - PCRE2_SPTR pp1 = NULL; - PCRE2_SPTR pp2 = NULL; - PCRE2_SIZE searchlength = end_subject - start_match; - - /* If we haven't got a previously found position for first_cu, or if - the current starting position is later, we need to do a search. If - the code unit is not found, set it to the end. */ - - if (memchr_found_first_cu == NULL || - start_match > memchr_found_first_cu) - { - pp1 = memchr(start_match, first_cu, searchlength); - memchr_found_first_cu = (pp1 == NULL)? end_subject : pp1; - } - - /* If the start is before a previously found position, use the - previous position, or NULL if a previous search failed. */ - - else pp1 = (memchr_found_first_cu == end_subject)? NULL : - memchr_found_first_cu; - - /* Do the same thing for the other case. */ - - if (memchr_found_first_cu2 == NULL || - start_match > memchr_found_first_cu2) - { - pp2 = memchr(start_match, first_cu2, searchlength); - memchr_found_first_cu2 = (pp2 == NULL)? end_subject : pp2; - } - - else pp2 = (memchr_found_first_cu2 == end_subject)? NULL : - memchr_found_first_cu2; - - /* Set the start to the end of the subject if neither case was found. - Otherwise, use the earlier found point. */ - - if (pp1 == NULL) - start_match = (pp2 == NULL)? end_subject : pp2; - else - start_match = (pp2 == NULL || pp1 < pp2)? pp1 : pp2; - -#endif /* 8-bit handling */ - } - - /* The caseful case is much simpler. */ - - else - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - while (start_match < end_subject && UCHAR21TEST(start_match) != - first_cu) - start_match++; -#else /* 8-bit code units */ - start_match = memchr(start_match, first_cu, end_subject - start_match); - if (start_match == NULL) start_match = end_subject; -#endif - } - - /* If we can't find the required code unit, having reached the true end - of the subject, break the bumpalong loop, to force a match failure, - except when doing partial matching, when we let the next cycle run at - the end of the subject. To see why, consider the pattern /(?<=abc)def/, - which partially matches "abc", even though the string does not contain - the starting character "d". If we have not reached the true end of the - subject (PCRE2_FIRSTLINE caused end_subject to be temporarily modified) - we also let the cycle run, because the matching string is legitimately - allowed to start with the first code unit of a newline. */ - - if ((mb->moptions & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) == 0 && - start_match >= mb->end_subject) - break; - } - - /* If there's no first code unit, advance to just after a linebreak for a - multiline match if required. */ - - else if (startline) - { - if (start_match > mb->start_subject + start_offset) - { -#ifdef SUPPORT_UNICODE - if (utf) - { - while (start_match < end_subject && !WAS_NEWLINE(start_match)) - { - start_match++; - ACROSSCHAR(start_match < end_subject, start_match, start_match++); - } - } - else -#endif - while (start_match < end_subject && !WAS_NEWLINE(start_match)) - start_match++; - - /* If we have just passed a CR and the newline option is ANY or - ANYCRLF, and we are now at a LF, advance the match position by one - more code unit. */ - - if (start_match[-1] == CHAR_CR && - (mb->nltype == NLTYPE_ANY || mb->nltype == NLTYPE_ANYCRLF) && - start_match < end_subject && - UCHAR21TEST(start_match) == CHAR_NL) - start_match++; - } - } - - /* If there's no first code unit or a requirement for a multiline line - start, advance to a non-unique first code unit if any have been - identified. The bitmap contains only 256 bits. When code units are 16 or - 32 bits wide, all code units greater than 254 set the 255 bit. */ - - else if (start_bits != NULL) - { - while (start_match < end_subject) - { - uint32_t c = UCHAR21TEST(start_match); -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (c > 255) c = 255; -#endif - if ((start_bits[c/8] & (1u << (c&7))) != 0) break; - start_match++; - } - - /* See comment above in first_cu checking about the next line. */ - - if ((mb->moptions & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) == 0 && - start_match >= mb->end_subject) - break; - } - } /* End of first code unit handling */ - - /* Restore fudged end_subject */ - - end_subject = mb->end_subject; - - /* The following two optimizations are disabled for partial matching. */ - - if ((mb->moptions & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) == 0) - { - PCRE2_SPTR p; - - /* The minimum matching length is a lower bound; no actual string of that - length may actually match the pattern. Although the value is, strictly, - in characters, we treat it as code units to avoid spending too much time - in this optimization. */ - - if (end_subject - start_match < re->minlength) goto NOMATCH_EXIT; - - /* If req_cu is set, we know that that code unit must appear in the - subject for the match to succeed. If the first code unit is set, req_cu - must be later in the subject; otherwise the test starts at the match - point. This optimization can save a huge amount of backtracking in - patterns with nested unlimited repeats that aren't going to match. - Writing separate code for cased/caseless versions makes it go faster, as - does using an autoincrement and backing off on a match. As in the case of - the first code unit, using memchr() in the 8-bit library gives a big - speed up. Unlike the first_cu check above, we do not need to call - memchr() twice in the caseless case because we only need to check for the - presence of the character in either case, not find the first occurrence. - - The search can be skipped if the code unit was found later than the - current starting point in a previous iteration of the bumpalong loop. - - HOWEVER: when the subject string is very, very long, searching to its end - can take a long time, and give bad performance on quite ordinary - patterns. This showed up when somebody was matching something like - /^\d+C/ on a 32-megabyte string... so we don't do this when the string is - sufficiently long, but it's worth searching a lot more for unanchored - patterns. */ - - p = start_match + (has_first_cu? 1:0); - if (has_req_cu && p > req_cu_ptr) - { - PCRE2_SIZE check_length = end_subject - start_match; - - if (check_length < REQ_CU_MAX || - (!anchored && check_length < REQ_CU_MAX * 1000)) - { - if (req_cu != req_cu2) /* Caseless */ - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - while (p < end_subject) - { - uint32_t pp = UCHAR21INCTEST(p); - if (pp == req_cu || pp == req_cu2) { p--; break; } - } -#else /* 8-bit code units */ - PCRE2_SPTR pp = p; - p = memchr(pp, req_cu, end_subject - pp); - if (p == NULL) - { - p = memchr(pp, req_cu2, end_subject - pp); - if (p == NULL) p = end_subject; - } -#endif /* PCRE2_CODE_UNIT_WIDTH != 8 */ - } - - /* The caseful case */ - - else - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - while (p < end_subject) - { - if (UCHAR21INCTEST(p) == req_cu) { p--; break; } - } - -#else /* 8-bit code units */ - p = memchr(p, req_cu, end_subject - p); - if (p == NULL) p = end_subject; -#endif - } - - /* If we can't find the required code unit, break the matching loop, - forcing a match failure. */ - - if (p >= end_subject) break; - - /* If we have found the required code unit, save the point where we - found it, so that we don't search again next time round the loop if - the start hasn't passed this code unit yet. */ - - req_cu_ptr = p; - } - } - } - } - - /* ------------ End of start of match optimizations ------------ */ - - /* Give no match if we have passed the bumpalong limit. */ - - if (start_match > bumpalong_limit) break; - - /* OK, now we can do the business */ - - mb->start_used_ptr = start_match; - mb->last_used_ptr = start_match; - mb->recursive = NULL; - - rc = internal_dfa_match( - mb, /* fixed match data */ - mb->start_code, /* this subexpression's code */ - start_match, /* where we currently are */ - start_offset, /* start offset in subject */ - match_data->ovector, /* offset vector */ - (uint32_t)match_data->oveccount * 2, /* actual size of same */ - workspace, /* workspace vector */ - (int)wscount, /* size of same */ - 0, /* function recurse level */ - base_recursion_workspace); /* initial workspace for recursion */ - - /* Anything other than "no match" means we are done, always; otherwise, carry - on only if not anchored. */ - - if (rc != PCRE2_ERROR_NOMATCH || anchored) - { - if (rc == PCRE2_ERROR_NOMATCH) goto NOMATCH_EXIT; - - if (rc == PCRE2_ERROR_PARTIAL && match_data->oveccount > 0) - { - match_data->ovector[0] = (PCRE2_SIZE)(start_match - subject); - match_data->ovector[1] = (PCRE2_SIZE)(end_subject - subject); - } - - if (rc >= 0 || rc == PCRE2_ERROR_PARTIAL) - { - match_data->subject_length = length; - match_data->start_offset = start_offset; - match_data->leftchar = (PCRE2_SIZE)(mb->start_used_ptr - subject); - match_data->rightchar = (PCRE2_SIZE)(mb->last_used_ptr - subject); - match_data->startchar = (PCRE2_SIZE)(start_match - subject); - } - - if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0) - { - if (length != 0) - { - match_data->subject = match_data->memctl.malloc(CU2BYTES(length), - match_data->memctl.memory_data); - if (match_data->subject == NULL) - { rc = PCRE2_ERROR_NOMEMORY; goto EXIT; } - memcpy((void *)match_data->subject, subject, CU2BYTES(length)); - } - else - match_data->subject = NULL; - match_data->flags |= PCRE2_MD_COPIED_SUBJECT; - } - else if (rc >= 0 || rc == PCRE2_ERROR_PARTIAL) - { - match_data->subject = original_subject; - } - goto EXIT; - } - - /* Advance to the next subject character unless we are at the end of a line - and firstline is set. */ - - if (firstline && IS_NEWLINE(start_match)) break; - start_match++; -#ifdef SUPPORT_UNICODE - if (utf) - { - ACROSSCHAR(start_match < end_subject, start_match, start_match++); - } -#endif - if (start_match > end_subject) break; - - /* If we have just passed a CR and we are now at a LF, and the pattern does - not contain any explicit matches for \r or \n, and the newline option is CRLF - or ANY or ANYCRLF, advance the match position by one more character. */ - - if (UCHAR21TEST(start_match - 1) == CHAR_CR && - start_match < end_subject && - UCHAR21TEST(start_match) == CHAR_NL && - (re->flags & PCRE2_HASCRORLF) == 0 && - (mb->nltype == NLTYPE_ANY || - mb->nltype == NLTYPE_ANYCRLF || - mb->nllen == 2)) - start_match++; - - } /* "Bumpalong" loop */ - -NOMATCH_EXIT: -match_data->subject = original_subject; -match_data->subject_length = length; -match_data->start_offset = start_offset; -rc = PCRE2_ERROR_NOMATCH; - -EXIT: -while (rws->next != NULL) - { - RWS_anchor *next = rws->next; - rws->next = next->next; - mb->memctl.free(next, mb->memctl.memory_data); - } - -match_data->rc = rc; -return rc; -} - -/* These #undefs are here to enable unity builds with CMake. */ - -#undef NLBLOCK /* Block containing newline information */ -#undef PSSTART /* Field containing processed string start */ -#undef PSEND /* Field containing processed string end */ - -/* End of pcre2_dfa_match.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_error.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_error.c deleted file mode 100644 index df26add..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_error.c +++ /dev/null @@ -1,384 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -#define STRING(a) # a -#define XSTRING(s) STRING(s) - -/* The texts of compile-time error messages. Compile-time error numbers start -at COMPILE_ERROR_BASE (100). - -This used to be a table of strings, but in order to reduce the number of -relocations needed when a shared library is loaded dynamically, it is now one -long string. We cannot use a table of offsets, because the lengths of inserts -such as XSTRING(MAX_NAME_SIZE) are not known. Instead, -pcre2_get_error_message() counts through to the one it wants - this isn't a -performance issue because these strings are used only when there is an error. - -Each substring ends with \0 to insert a null character. This includes the final -substring, so that the whole string ends with \0\0, which can be detected when -counting through. */ - -static const unsigned char compile_error_texts[] = - "no error\0" - "\\ at end of pattern\0" - "\\c at end of pattern\0" - "unrecognized character follows \\\0" - "numbers out of order in {} quantifier\0" - /* 5 */ - "number too big in {} quantifier\0" - "missing terminating ] for character class\0" - "escape sequence is invalid in character class\0" - "range out of order in character class\0" - "quantifier does not follow a repeatable item\0" - /* 10 */ - "internal error: unexpected repeat\0" - "unrecognized character after (? or (?-\0" - "POSIX named classes are supported only within a class\0" - "POSIX collating elements are not supported\0" - "missing closing parenthesis\0" - /* 15 */ - "reference to non-existent subpattern\0" - "pattern passed as NULL with non-zero length\0" - "unrecognised compile-time option bit(s)\0" - "missing ) after (?# comment\0" - "parentheses are too deeply nested\0" - /* 20 */ - "regular expression is too large\0" - "failed to allocate heap memory\0" - "unmatched closing parenthesis\0" - "internal error: code overflow\0" - "missing closing parenthesis for condition\0" - /* 25 */ - "length of lookbehind assertion is not limited\0" - "a relative value of zero is not allowed\0" - "conditional subpattern contains more than two branches\0" - "atomic assertion expected after (?( or (?(?C)\0" - "digit expected after (?+\0" - /* 30 */ - "unknown POSIX class name\0" - "internal error in pcre2_study(): should not occur\0" - "this version of PCRE2 does not have Unicode support\0" - "parentheses are too deeply nested (stack check)\0" - "character code point value in \\x{} or \\o{} is too large\0" - /* 35 */ - "lookbehind is too complicated\0" - "\\C is not allowed in a lookbehind assertion in UTF-" XSTRING(PCRE2_CODE_UNIT_WIDTH) " mode\0" - "PCRE2 does not support \\F, \\L, \\l, \\N{name}, \\U, or \\u\0" - "number after (?C is greater than 255\0" - "closing parenthesis for (?C expected\0" - /* 40 */ - "invalid escape sequence in (*VERB) name\0" - "unrecognized character after (?P\0" - "syntax error in subpattern name (missing terminator?)\0" - "two named subpatterns have the same name (PCRE2_DUPNAMES not set)\0" - "subpattern name must start with a non-digit\0" - /* 45 */ - "this version of PCRE2 does not have support for \\P, \\p, or \\X\0" - "malformed \\P or \\p sequence\0" - "unknown property after \\P or \\p\0" - "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " code units)\0" - "too many named subpatterns (maximum " XSTRING(MAX_NAME_COUNT) ")\0" - /* 50 */ - "invalid range in character class\0" - "octal value is greater than \\377 in 8-bit non-UTF-8 mode\0" - "internal error: overran compiling workspace\0" - "internal error: previously-checked referenced subpattern not found\0" - "DEFINE subpattern contains more than one branch\0" - /* 55 */ - "missing opening brace after \\o\0" - "internal error: unknown newline setting\0" - "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0" - "(?R (recursive pattern call) must be followed by a closing parenthesis\0" - /* "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0" */ - "obsolete error (should not occur)\0" /* Was the above */ - /* 60 */ - "(*VERB) not recognized or malformed\0" - "subpattern number is too big\0" - "subpattern name expected\0" - "internal error: parsed pattern overflow\0" - "non-octal character in \\o{} (closing brace missing?)\0" - /* 65 */ - "different names for subpatterns of the same number are not allowed\0" - "(*MARK) must have an argument\0" - "non-hex character in \\x{} (closing brace missing?)\0" -#ifndef EBCDIC - "\\c must be followed by a printable ASCII character\0" -#else - "\\c must be followed by a letter or one of @[\\]^_?\0" -#endif - "\\k is not followed by a braced, angle-bracketed, or quoted name\0" - /* 70 */ - "internal error: unknown meta code in check_lookbehinds()\0" - "\\N is not supported in a class\0" - "callout string is too long\0" - "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)\0" - "using UTF is disabled by the application\0" - /* 75 */ - "using UCP is disabled by the application\0" - "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0" - "character code point value in \\u.... sequence is too large\0" - "digits missing after \\x or in \\x{} or \\o{} or \\N{U+}\0" - "syntax error or number too big in (?(VERSION condition\0" - /* 80 */ - "internal error: unknown opcode in auto_possessify()\0" - "missing terminating delimiter for callout with string argument\0" - "unrecognized string delimiter follows (?C\0" - "using \\C is disabled by the application\0" - "(?| and/or (?J: or (?x: parentheses are too deeply nested\0" - /* 85 */ - "using \\C is disabled in this PCRE2 library\0" - "regular expression is too complicated\0" - "lookbehind assertion is too long\0" - "pattern string is longer than the limit set by the application\0" - "internal error: unknown code in parsed pattern\0" - /* 90 */ - "internal error: bad code value in parsed_skip()\0" - "PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is not allowed in UTF-16 mode\0" - "invalid option bits with PCRE2_LITERAL\0" - "\\N{U+dddd} is supported only in Unicode (UTF) mode\0" - "invalid hyphen in option setting\0" - /* 95 */ - "(*alpha_assertion) not recognized\0" - "script runs require Unicode support, which this version of PCRE2 does not have\0" - "too many capturing groups (maximum 65535)\0" - "octal digit missing after \\0 (PCRE2_EXTRA_NO_BS0 is set)\0" - "\\K is not allowed in lookarounds (but see PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK)\0" - /* 100 */ - "branch too long in variable-length lookbehind assertion\0" - "compiled pattern would be longer than the limit set by the application\0" - "octal value given by \\ddd is greater than \\377 (forbidden by PCRE2_EXTRA_PYTHON_OCTAL)\0" - "using callouts is disabled by the application\0" - "PCRE2_EXTRA_TURKISH_CASING require Unicode (UTF or UCP) mode\0" - /* 105 */ - "PCRE2_EXTRA_TURKISH_CASING requires UTF in 8-bit mode\0" - "PCRE2_EXTRA_TURKISH_CASING and PCRE2_EXTRA_CASELESS_RESTRICT are not compatible\0" - "extended character class nesting is too deep\0" - "invalid operator in extended character class\0" - "unexpected operator in extended character class (no preceding operand)\0" - /* 110 */ - "expected operand after operator in extended character class\0" - "square brackets needed to clarify operator precedence in extended character class\0" - "missing terminating ] for extended character class (note '[' must be escaped under PCRE2_ALT_EXTENDED_CLASS)\0" - "unexpected expression in extended character class (no preceding operator)\0" - "empty expression in extended character class\0" - /* 115 */ - "terminating ] with no following closing parenthesis in (?[...]\0" - "unexpected character in (?[...]) extended character class\0" - "expected capture group number or name\0" - "missing opening parenthesis\0" - "syntax error in subpattern number (missing terminator?)\0" - /* 120 */ - "erroroffset passed as NULL\0" - ; - -/* Match-time and UTF error texts are in the same format. */ - -static const unsigned char match_error_texts[] = - "no error\0" - "no match\0" - "partial match\0" - "UTF-8 error: 1 byte missing at end\0" - "UTF-8 error: 2 bytes missing at end\0" - /* 5 */ - "UTF-8 error: 3 bytes missing at end\0" - "UTF-8 error: 4 bytes missing at end\0" - "UTF-8 error: 5 bytes missing at end\0" - "UTF-8 error: byte 2 top bits not 0x80\0" - "UTF-8 error: byte 3 top bits not 0x80\0" - /* 10 */ - "UTF-8 error: byte 4 top bits not 0x80\0" - "UTF-8 error: byte 5 top bits not 0x80\0" - "UTF-8 error: byte 6 top bits not 0x80\0" - "UTF-8 error: 5-byte character is not allowed (RFC 3629)\0" - "UTF-8 error: 6-byte character is not allowed (RFC 3629)\0" - /* 15 */ - "UTF-8 error: code points greater than 0x10ffff are not defined\0" - "UTF-8 error: code points 0xd800-0xdfff are not defined\0" - "UTF-8 error: overlong 2-byte sequence\0" - "UTF-8 error: overlong 3-byte sequence\0" - "UTF-8 error: overlong 4-byte sequence\0" - /* 20 */ - "UTF-8 error: overlong 5-byte sequence\0" - "UTF-8 error: overlong 6-byte sequence\0" - "UTF-8 error: isolated byte with 0x80 bit set\0" - "UTF-8 error: illegal byte (0xfe or 0xff)\0" - "UTF-16 error: missing low surrogate at end\0" - /* 25 */ - "UTF-16 error: invalid low surrogate\0" - "UTF-16 error: isolated low surrogate\0" - "UTF-32 error: code points 0xd800-0xdfff are not defined\0" - "UTF-32 error: code points greater than 0x10ffff are not defined\0" - "bad data value\0" - /* 30 */ - "patterns do not all use the same character tables\0" - "magic number missing\0" - "pattern compiled in wrong mode: 8/16/32-bit error\0" - "bad offset value\0" - "bad option value\0" - /* 35 */ - "invalid replacement string\0" - "bad offset into UTF string\0" - "callout error code\0" /* Never returned by PCRE2 itself */ - "invalid data in workspace for DFA restart\0" - "too much recursion for DFA matching\0" - /* 40 */ - "backreference condition or recursion test is not supported for DFA matching\0" - "function is not supported for DFA matching\0" - "pattern contains an item that is not supported for DFA matching\0" - "workspace size exceeded in DFA matching\0" - "internal error - pattern overwritten?\0" - /* 45 */ - "bad JIT option\0" - "JIT stack limit reached\0" - "match limit exceeded\0" - "no more memory\0" - "unknown substring\0" - /* 50 */ - "non-unique substring name\0" - "NULL argument passed with non-zero length\0" - "nested recursion at the same subject position\0" - "matching depth limit exceeded\0" - "requested value is not available\0" - /* 55 */ - "requested value is not set\0" - "offset limit set without PCRE2_USE_OFFSET_LIMIT\0" - "bad escape sequence in replacement string\0" - "expected closing curly bracket in replacement string\0" - "bad substitution in replacement string\0" - /* 60 */ - "match with end before start or start moved backwards is not supported\0" - "too many replacements (more than INT_MAX)\0" - "bad serialized data\0" - "heap limit exceeded\0" - "invalid syntax\0" - /* 65 */ - "internal error: duplicate substitution match\0" - "PCRE2_MATCH_INVALID_UTF is not supported for DFA matching\0" - "internal error: invalid substring offset\0" - "feature is not supported by the JIT compiler\0" - "error performing replacement case transformation\0" - /* 70 */ - "replacement too large (longer than PCRE2_SIZE)\0" - "substitute pattern differs from prior match call\0" - "substitute subject differs from prior match call\0" - "substitute start offset differs from prior match call\0" - "substitute options differ from prior match call\0" - "disallowed use of \\K in lookaround\0" - ; - - -/************************************************* -* Return error message * -*************************************************/ - -/* This function copies an error message into a buffer whose units are of an -appropriate width. Error numbers are positive for compile-time errors, and -negative for match-time errors (except for UTF errors), but the numbers are all -distinct. - -Arguments: - enumber error number - buffer where to put the message (zero terminated) - size size of the buffer in code units - -Returns: length of message if all is well - negative on error -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_get_error_message(int enumber, PCRE2_UCHAR *buffer, PCRE2_SIZE size) -{ -const unsigned char *message; -PCRE2_SIZE i; -int n, rc = 0; - -if (size == 0) return PCRE2_ERROR_NOMEMORY; - -if (enumber >= COMPILE_ERROR_BASE) /* Compile error */ - { - message = compile_error_texts; - n = enumber - COMPILE_ERROR_BASE; - } -else if (enumber < 0) /* Match or UTF error */ - { - message = match_error_texts; - n = -enumber; - } -else /* Invalid error number */ - { - message = (const unsigned char *)"\0"; /* Empty message list */ - n = 1; - } - -for (; n > 0; n--) - { - while (*message++ != CHAR_NUL) {} - if (*message == CHAR_NUL) return PCRE2_ERROR_BADDATA; - } - -for (i = 0; *message != 0; i++) - { - if (i >= size - 1) - { - rc = PCRE2_ERROR_NOMEMORY; - break; - } - buffer[i] = *message++; - } - -#if defined EBCDIC && 'a' != 0x81 -/* If compiling for EBCDIC, but the compiler's string literals are not EBCDIC, -then we are in the "force EBCDIC 1047" mode. I have chosen to add a few lines -here to translate the error strings on the fly, rather than require the string -literals above to be written out arduously using the "STR_XYZ" macros. */ -for (PCRE2_SIZE j = 0; j < i; ++j) - buffer[j] = PRIV(ascii_to_ebcdic_1047)[buffer[j]]; -#endif - -buffer[i] = 0; /* Terminate message, even if truncated. */ -return rc? rc : (int)i; -} - -/* End of pcre2_error.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_extuni.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_extuni.c deleted file mode 100644 index 1b7f04b..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_extuni.c +++ /dev/null @@ -1,159 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains an internal function that is used to match a Unicode -extended grapheme sequence. It is used by both pcre2_match() and -pcre2_dfa_match(). However, it is called only when Unicode support is being -compiled. Nevertheless, we provide a dummy function when there is no Unicode -support, because some compilers do not like functionless source files. */ - - -#include "pcre2_internal.h" - - - -/* Dummy function */ - -#ifndef SUPPORT_UNICODE -PCRE2_SPTR -PRIV(extuni)(uint32_t c, PCRE2_SPTR eptr, PCRE2_SPTR start_subject, - PCRE2_SPTR end_subject, BOOL utf, int *xcount) -{ -(void)c; -(void)eptr; -(void)start_subject; -(void)end_subject; -(void)utf; -(void)xcount; -return NULL; -} -#else - - -/************************************************* -* Match an extended grapheme sequence * -*************************************************/ - -/* NOTE: The logic contained in this function is replicated in three special- -purpose functions in the pcre2_jit_compile.c module. If the logic below is -changed, they must be kept in step so that the interpreter and the JIT have the -same behaviour. - -Arguments: - c the first character - eptr pointer to next character - start_subject pointer to start of subject - end_subject pointer to end of subject - utf TRUE if in UTF mode - xcount pointer to count of additional characters, - or NULL if count not needed - -Returns: pointer after the end of the sequence -*/ - -PCRE2_SPTR -PRIV(extuni)(uint32_t c, PCRE2_SPTR eptr, PCRE2_SPTR start_subject, - PCRE2_SPTR end_subject, BOOL utf, int *xcount) -{ -BOOL was_ep_ZWJ = FALSE; -int lgb = UCD_GRAPHBREAK(c); - -while (eptr < end_subject) - { - int rgb; - int len = 1; - if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); } - rgb = UCD_GRAPHBREAK(c); - if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break; - - /* ZWJ followed by Extended Pictographic is allowed only if the ZWJ was - preceded by Extended Pictographic. */ - - if (lgb == ucp_gbZWJ && rgb == ucp_gbExtended_Pictographic && !was_ep_ZWJ) - break; - - /* Not breaking between Regional Indicators is allowed only if there - are an even number of preceding RIs. */ - - if (lgb == ucp_gbRegional_Indicator && rgb == ucp_gbRegional_Indicator) - { - int ricount = 0; - PCRE2_SPTR bptr = eptr - 1; - if (utf) BACKCHAR(bptr); - - /* bptr is pointing to the left-hand character */ - - while (bptr > start_subject) - { - bptr--; - if (utf) - { - BACKCHAR(bptr); - GETCHAR(c, bptr); - } - else - c = *bptr; - if (UCD_GRAPHBREAK(c) != ucp_gbRegional_Indicator) break; - ricount++; - } - if ((ricount & 1) != 0) break; /* Grapheme break required */ - } - - /* Set a flag when ZWJ follows Extended Pictographic (with optional Extend in - between; see next statement). */ - - was_ep_ZWJ = (lgb == ucp_gbExtended_Pictographic && rgb == ucp_gbZWJ); - - /* If Extend follows Extended_Pictographic, do not update lgb; this allows - any number of them before a following ZWJ. */ - - if (rgb != ucp_gbExtend || lgb != ucp_gbExtended_Pictographic) lgb = rgb; - - eptr += len; - if (xcount != NULL) *xcount += 1; - } - -return eptr; -} - -#endif /* SUPPORT_UNICODE */ - -/* End of pcre2_extuni.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_find_bracket.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_find_bracket.c deleted file mode 100644 index e26ee99..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_find_bracket.c +++ /dev/null @@ -1,217 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains a single function that scans through a compiled pattern -until it finds a capturing bracket with the given number, or, if the number is -negative, an instance of OP_REVERSE or OP_VREVERSE for a lookbehind. The -function is called from pcre2_compile.c and also from pcre2_study.c when -finding the minimum matching length. */ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Scan compiled regex for specific bracket * -*************************************************/ - -/* -Arguments: - code points to start of expression - utf TRUE in UTF mode - number the required bracket number or negative to find a lookbehind - -Returns: pointer to the opcode for the bracket, or NULL if not found -*/ - -PCRE2_SPTR -PRIV(find_bracket)(PCRE2_SPTR code, BOOL utf, int number) -{ -for (;;) - { - PCRE2_UCHAR c = *code; - - if (c == OP_END) return NULL; - - /* XCLASS is used for classes that cannot be represented just by a bit map. - This includes negated single high-valued characters. ECLASS is used for - classes that use set operations internally. CALLOUT_STR is used for - callouts with string arguments. In each case the length in the table is - zero; the actual length is stored in the compiled code. */ - - if (c == OP_XCLASS || c == OP_ECLASS) code += GET(code, 1); - else if (c == OP_CALLOUT_STR) code += GET(code, 1 + 2*LINK_SIZE); - - /* Handle lookbehind */ - - else if (c == OP_REVERSE || c == OP_VREVERSE) - { - if (number < 0) return code; - code += PRIV(OP_lengths)[c]; - } - - /* Handle capturing bracket */ - - else if (c == OP_CBRA || c == OP_SCBRA || - c == OP_CBRAPOS || c == OP_SCBRAPOS) - { - int n = (int)GET2(code, 1+LINK_SIZE); - if (n == number) return code; - code += PRIV(OP_lengths)[c]; - } - - /* Otherwise, we can get the item's length from the table, except that for - repeated character types, we have to test for \p and \P, which have an extra - two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we - must add in its length. */ - - else - { - switch(c) - { - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; - break; - - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEEXACT: - case OP_TYPEPOSUPTO: - if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP) - code += 2; - break; - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_SKIP_ARG: - case OP_THEN_ARG: - code += code[1]; - break; - } - - /* Add in the fixed length from the table */ - - code += PRIV(OP_lengths)[c]; - - /* In UTF-8 and UTF-16 modes, opcodes that are followed by a character may be - followed by a multi-byte character. The length in the table is a minimum, so - we have to arrange to skip the extra bytes. */ - -#ifdef MAYBE_UTF_MULTI - if (utf) switch(c) - { - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - case OP_EXACT: - case OP_EXACTI: - case OP_NOTEXACT: - case OP_NOTEXACTI: - case OP_UPTO: - case OP_UPTOI: - case OP_NOTUPTO: - case OP_NOTUPTOI: - case OP_MINUPTO: - case OP_MINUPTOI: - case OP_NOTMINUPTO: - case OP_NOTMINUPTOI: - case OP_POSUPTO: - case OP_POSUPTOI: - case OP_NOTPOSUPTO: - case OP_NOTPOSUPTOI: - case OP_STAR: - case OP_STARI: - case OP_NOTSTAR: - case OP_NOTSTARI: - case OP_MINSTAR: - case OP_MINSTARI: - case OP_NOTMINSTAR: - case OP_NOTMINSTARI: - case OP_POSSTAR: - case OP_POSSTARI: - case OP_NOTPOSSTAR: - case OP_NOTPOSSTARI: - case OP_PLUS: - case OP_PLUSI: - case OP_NOTPLUS: - case OP_NOTPLUSI: - case OP_MINPLUS: - case OP_MINPLUSI: - case OP_NOTMINPLUS: - case OP_NOTMINPLUSI: - case OP_POSPLUS: - case OP_POSPLUSI: - case OP_NOTPOSPLUS: - case OP_NOTPOSPLUSI: - case OP_QUERY: - case OP_QUERYI: - case OP_NOTQUERY: - case OP_NOTQUERYI: - case OP_MINQUERY: - case OP_MINQUERYI: - case OP_NOTMINQUERY: - case OP_NOTMINQUERYI: - case OP_POSQUERY: - case OP_POSQUERYI: - case OP_NOTPOSQUERY: - case OP_NOTPOSQUERYI: - if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]); - break; - } -#else - (void)(utf); /* Keep compiler happy by referencing function argument */ -#endif /* MAYBE_UTF_MULTI */ - } - } -} - -/* End of pcre2_find_bracket.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_fuzzsupport.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_fuzzsupport.c deleted file mode 100644 index ba3fc88..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_fuzzsupport.c +++ /dev/null @@ -1,844 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2023 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/*************************************************************************** -Fuzzer driver for PCRE2. Given an arbitrary string of bytes and a length, it -tries to compile and match it, deriving options from the string itself. If -STANDALONE is defined, a main program that calls the driver with the contents -of specified files is compiled, and commentary on what is happening is output. -If an argument starts with '=' the rest of it it is taken as a literal string -rather than a file name. This allows easy testing of short strings. - -Written by Philip Hazel, October 2016 -Updated February 2024 (Addison Crump added 16-bit/32-bit and JIT support) -Further updates March/April/May 2024 by PH -***************************************************************************/ - - -#include -#include -#include -#include -#include -#include - -/* stack size adjustment */ -#include -#include - -#define STACK_SIZE_MB 256 -#define JIT_SIZE_LIMIT (200 * 1024) - -#ifndef PCRE2_CODE_UNIT_WIDTH -#define PCRE2_CODE_UNIT_WIDTH 8 -#endif - -#include "pcre2_internal.h" - -#define MAX_MATCH_SIZE 1000 - -#define DFA_WORKSPACE_COUNT 100 - -/* When adding new compile or match options, remember to update the functions -below that output them. */ - -#define ALLOWED_COMPILE_OPTIONS \ - (PCRE2_ANCHORED|PCRE2_ALLOW_EMPTY_CLASS|PCRE2_ALT_BSUX|PCRE2_ALT_CIRCUMFLEX| \ - PCRE2_ALT_EXTENDED_CLASS|PCRE2_ALT_VERBNAMES|PCRE2_AUTO_CALLOUT| \ - PCRE2_CASELESS|PCRE2_DOLLAR_ENDONLY| \ - PCRE2_DOTALL|PCRE2_DUPNAMES|PCRE2_ENDANCHORED|PCRE2_EXTENDED| \ - PCRE2_EXTENDED_MORE|PCRE2_FIRSTLINE| \ - PCRE2_MATCH_UNSET_BACKREF|PCRE2_MULTILINE|PCRE2_NEVER_BACKSLASH_C| \ - PCRE2_NO_AUTO_CAPTURE| \ - PCRE2_NO_AUTO_POSSESS|PCRE2_NO_DOTSTAR_ANCHOR|PCRE2_NO_START_OPTIMIZE| \ - PCRE2_UCP|PCRE2_UNGREEDY|PCRE2_USE_OFFSET_LIMIT| \ - PCRE2_UTF) - -#define ALLOWED_MATCH_OPTIONS \ - (PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY| \ - PCRE2_NOTEMPTY_ATSTART|PCRE2_PARTIAL_HARD| \ - PCRE2_PARTIAL_SOFT) - -#define BASE_MATCH_OPTIONS \ - (PCRE2_NO_JIT|PCRE2_DISABLE_RECURSELOOP_CHECK) - - -#if defined(SUPPORT_DIFF_FUZZ) || defined(STANDALONE) -static void print_compile_options(FILE *stream, uint32_t compile_options) -{ -fprintf(stream, "Compile options %s%.8x =", - (compile_options == PCRE2_NEVER_BACKSLASH_C)? "(base) " : "", - compile_options); - -fprintf(stream, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", - ((compile_options & PCRE2_ALT_BSUX) != 0)? " alt_bsux" : "", - ((compile_options & PCRE2_ALT_CIRCUMFLEX) != 0)? " alt_circumflex" : "", - ((compile_options & PCRE2_ALT_EXTENDED_CLASS) != 0)? "alt_extended_class" : "", - ((compile_options & PCRE2_ALT_VERBNAMES) != 0)? " alt_verbnames" : "", - ((compile_options & PCRE2_ALLOW_EMPTY_CLASS) != 0)? " allow_empty_class" : "", - ((compile_options & PCRE2_ANCHORED) != 0)? " anchored" : "", - ((compile_options & PCRE2_AUTO_CALLOUT) != 0)? " auto_callout" : "", - ((compile_options & PCRE2_CASELESS) != 0)? " caseless" : "", - ((compile_options & PCRE2_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "", - ((compile_options & PCRE2_DOTALL) != 0)? " dotall" : "", - ((compile_options & PCRE2_DUPNAMES) != 0)? " dupnames" : "", - ((compile_options & PCRE2_ENDANCHORED) != 0)? " endanchored" : "", - ((compile_options & PCRE2_EXTENDED) != 0)? " extended" : "", - ((compile_options & PCRE2_EXTENDED_MORE) != 0)? " extended_more" : "", - ((compile_options & PCRE2_FIRSTLINE) != 0)? " firstline" : "", - ((compile_options & PCRE2_MATCH_UNSET_BACKREF) != 0)? " match_unset_backref" : "", - ((compile_options & PCRE2_MULTILINE) != 0)? " multiline" : "", - ((compile_options & PCRE2_NEVER_BACKSLASH_C) != 0)? " never_backslash_c" : "", - ((compile_options & PCRE2_NEVER_UCP) != 0)? " never_ucp" : "", - ((compile_options & PCRE2_NEVER_UTF) != 0)? " never_utf" : "", - ((compile_options & PCRE2_NO_AUTO_CAPTURE) != 0)? " no_auto_capture" : "", - ((compile_options & PCRE2_NO_AUTO_POSSESS) != 0)? " no_auto_possess" : "", - ((compile_options & PCRE2_NO_DOTSTAR_ANCHOR) != 0)? " no_dotstar_anchor" : "", - ((compile_options & PCRE2_NO_UTF_CHECK) != 0)? " no_utf_check" : "", - ((compile_options & PCRE2_NO_START_OPTIMIZE) != 0)? " no_start_optimize" : "", - ((compile_options & PCRE2_UCP) != 0)? " ucp" : "", - ((compile_options & PCRE2_UNGREEDY) != 0)? " ungreedy" : "", - ((compile_options & PCRE2_USE_OFFSET_LIMIT) != 0)? " use_offset_limit" : "", - ((compile_options & PCRE2_UTF) != 0)? " utf" : ""); -} - -static void print_match_options(FILE *stream, uint32_t match_options) -{ -fprintf(stream, "Match options %s%.8x =", - (match_options == BASE_MATCH_OPTIONS)? "(base) " : "", match_options); - -fprintf(stream, "%s%s%s%s%s%s%s%s%s%s%s\n", - ((match_options & PCRE2_ANCHORED) != 0)? " anchored" : "", - ((match_options & PCRE2_DISABLE_RECURSELOOP_CHECK) != 0)? " disable_recurseloop_check" : "", - ((match_options & PCRE2_ENDANCHORED) != 0)? " endanchored" : "", - ((match_options & PCRE2_NO_JIT) != 0)? " no_jit" : "", - ((match_options & PCRE2_NO_UTF_CHECK) != 0)? " no_utf_check" : "", - ((match_options & PCRE2_NOTBOL) != 0)? " notbol" : "", - ((match_options & PCRE2_NOTEMPTY) != 0)? " notempty" : "", - ((match_options & PCRE2_NOTEMPTY_ATSTART) != 0)? " notempty_atstart" : "", - ((match_options & PCRE2_NOTEOL) != 0)? " noteol" : "", - ((match_options & PCRE2_PARTIAL_HARD) != 0)? " partial_hard" : "", - ((match_options & PCRE2_PARTIAL_SOFT) != 0)? " partial_soft" : ""); -} - - -/* This function can print an error message at all code unit widths. */ - -static void print_error(FILE *f, int errorcode, const char *text, ...) -{ -PCRE2_UCHAR buffer[256]; -PCRE2_UCHAR *p = buffer; -va_list ap; -va_start(ap, text); -vfprintf(f, text, ap); -va_end(ap); -pcre2_get_error_message(errorcode, buffer, 256); -while (*p != 0) fprintf(f, "%c", *p++); -printf("\n"); -} -#endif /* defined(SUPPORT_DIFF_FUZZ || defined(STANDALONE) */ - - -#ifdef SUPPORT_JIT -#ifdef SUPPORT_DIFF_FUZZ -static void dump_matches(FILE *stream, int count, pcre2_match_data *match_data) -{ -int errorcode; - -for (int index = 0; index < count; index++) - { - PCRE2_UCHAR *bufferptr = NULL; - PCRE2_SIZE bufflen = 0; - - errorcode = pcre2_substring_get_bynumber(match_data, index, &bufferptr, - &bufflen); - - if (errorcode >= 0) - { - fprintf(stream, "Match %d (hex encoded): ", index); - for (PCRE2_SIZE i = 0; i < bufflen; i++) - { - fprintf(stream, "%02x", bufferptr[i]); - } - fprintf(stream, "\n"); - } - else - { - print_error(stream, errorcode, "Match %d failed: ", index); - } - } -} - -/* This function describes the current test case being evaluated, then aborts */ - -static void describe_failure( - const char *task, - const PCRE2_UCHAR *data, - PCRE2_SIZE size, - uint32_t compile_options, - uint32_t match_options, - int errorcode, - int errorcode_jit, - int matches, - int matches_jit, - pcre2_match_data *match_data, - pcre2_match_data *match_data_jit -) { - -fprintf(stderr, "Encountered failure while performing %s; context:\n", task); - -fprintf(stderr, "Pattern/sample string (hex encoded): "); -for (size_t i = 0; i < size; i++) - { - fprintf(stderr, "%02x", data[i]); - } -fprintf(stderr, "\n"); - -print_compile_options(stderr, compile_options); -print_match_options(stderr, match_options); - -if (errorcode < 0) - { - print_error(stderr, errorcode, "Non-JIT'd operation emitted an error: "); - } - -if (matches >= 0) - { - fprintf(stderr, "Non-JIT'd operation did not emit an error.\n"); - if (match_data != NULL) - { - fprintf(stderr, "%d matches discovered by non-JIT'd regex:\n", matches); - dump_matches(stderr, matches, match_data); - fprintf(stderr, "\n"); - } - } - -if (errorcode_jit < 0) - { - print_error(stderr, errorcode_jit, "JIT'd operation emitted error %d:", - errorcode_jit); - } - -if (matches_jit >= 0) - { - fprintf(stderr, "JIT'd operation did not emit an error.\n"); - if (match_data_jit != NULL) - { - fprintf(stderr, "%d matches discovered by JIT'd regex:\n", matches_jit); - dump_matches(stderr, matches_jit, match_data_jit); - fprintf(stderr, "\n"); - } - } - -abort(); -} -#endif /* SUPPORT_DIFF_FUZZ */ -#endif /* SUPPORT_JIT */ - -/* This is the callout function. Its only purpose is to halt matching if there -are more than 100 callouts, as one way of stopping too much time being spent on -fruitless matches. The callout data is a pointer to the counter. */ - -static int callout_function(pcre2_callout_block *cb, void *callout_data) -{ -(void)cb; /* Avoid unused parameter warning */ -*((uint32_t *)callout_data) += 1; -return (*((uint32_t *)callout_data) > 100)? PCRE2_ERROR_CALLOUT : 0; -} - -/* Putting in this apparently unnecessary prototype prevents gcc from giving a -"no previous prototype" warning when compiling at high warning level. */ - -int LLVMFuzzerInitialize(int *, char ***); - -int LLVMFuzzerTestOneInput(unsigned char *, size_t); - -int LLVMFuzzerInitialize(int *argc, char ***argv) -{ -int rc; -struct rlimit rlim; -getrlimit(RLIMIT_STACK, &rlim); -rlim.rlim_cur = STACK_SIZE_MB * 1024 * 1024; -if (rlim.rlim_cur > rlim.rlim_max) - { - fprintf(stderr, "Hard stack size limit is too small\n"); - _exit(1); - } -rc = setrlimit(RLIMIT_STACK, &rlim); -if (rc != 0) - { - fprintf(stderr, "Failed to expand stack size\n"); - _exit(1); - } - -(void)argc; /* Avoid "unused parameter" warnings */ -(void)argv; -return 0; -} - -/* Here's the driving function. */ - -int LLVMFuzzerTestOneInput(unsigned char *data, size_t size) -{ -PCRE2_UCHAR *wdata; -PCRE2_UCHAR *newwdata = NULL; -uint32_t compile_options; -uint32_t match_options; -uint64_t random_options; -pcre2_match_data *match_data = NULL; -#ifdef SUPPORT_JIT -pcre2_match_data *match_data_jit = NULL; -#endif -pcre2_compile_context *compile_context = NULL; -pcre2_match_context *match_context = NULL; -size_t match_size; -int dfa_workspace[DFA_WORKSPACE_COUNT]; - -if (size < sizeof(random_options)) return -1; - -random_options = *(uint64_t *)(data); -data += sizeof(random_options); -wdata = (PCRE2_UCHAR *)data; -size -= sizeof(random_options); -size /= PCRE2_CODE_UNIT_WIDTH / 8; - -/* PCRE2 compiles quantified groups by replicating them. In certain cases of -very large quantifiers this can lead to unacceptably long JIT compile times. To -get around this, we scan the data string for large quantifiers that follow a -closing parenthesis, and reduce the value of the quantifier to 10, assuming -that this will make minimal difference to the detection of bugs. - -Do the same for quantifiers that follow a closing square bracket, because -classes that contain a number of non-ascii characters can take a lot of time -when matching. - -We have to make a copy of the input because oss-fuzz complains if we overwrite -the original. Start the scan at the second character so there can be a -lookbehind for a backslash, and end it before the end so that the next -character can be checked for an opening brace. */ - -if (size > 3) - { - newwdata = malloc(size * sizeof(PCRE2_UCHAR)); - memcpy(newwdata, wdata, size * sizeof(PCRE2_UCHAR)); - wdata = newwdata; - - for (size_t i = 1; i < size - 2; i++) - { - size_t j; - - if ((wdata[i] != ')' && wdata[i] != ']') || wdata[i-1] == '\\' || - wdata[i+1] != '{') - continue; - i++; /* Points to '{' */ - - /* Loop for two values in a quantifier. Offset i points to brace or comma - at the start of the loop. */ - - for (int ii = 0; ii < 2; ii++) - { - int q = 0; - - if (i >= size - 1) goto END_QSCAN; /* Can happen for , */ - - /* Ignore leading spaces. */ - - while (wdata[i+1] == ' ' || wdata[i+1] == '\t') - { - i++; - if (i >= size - 1) goto END_QSCAN; - } - - /* Ignore non-significant leading zeros. */ - - while (wdata[i+1] == '0' && i+2 < size && wdata[i+2] >= '0' && - wdata[i+2] <= '9') - { - i++; - if (i >= size - 1) goto END_QSCAN; - } - - /* Scan for a number ending in brace, or comma in the first iteration, - optionally preceded by space. */ - - for (j = i + 1; j < size && j < i + 7; j++) - { - if (wdata[j] == ' ' || wdata[j] == '\t') - { - j++; - while (j < size && (wdata[j] == ' ' || wdata[j] == '\t')) j++; - if (j >= size) goto OUTERLOOP; - if (wdata[j] != '}' && wdata[j] != ',') goto OUTERLOOP; - } - if (wdata[j] == '}' || (ii == 0 && wdata[j] == ',')) break; - - if (wdata[j] < '0' || wdata[j] > '9') - { - j--; /* Ensure this character is checked next. The */ - goto OUTERLOOP; /* string might be (e.g.) "){9){234}" */ - } - q = q * 10 + (wdata[j] - '0'); - } - - if (j >= size) goto END_QSCAN; /* End of data */ - - /* Hit ',' or '}' or read 6 digits. Six digits is a number > 65536 which - is the maximum quantifier. Leave such numbers alone. */ - - if (j >= i + 7 || q > 65535) goto OUTERLOOP; - - /* Limit the quantifier size to 10 */ - - if (q > 10) - { -#ifdef STANDALONE - printf("Reduced quantifier value %d to 10.\n", q); -#endif - for (size_t k = i + 1; k < j; k++) wdata[k] = '0'; - wdata[j - 2] = '1'; - } - - /* Advance to end of number and break if reached closing brace (continue - after comma, which is only valid in the first time round this loop). */ - - i = j; - if (wdata[i] == '}') break; - } - - /* Continue along the data string */ - - OUTERLOOP: - i = j; - continue; - } - } -END_QSCAN: - -/* Limiting the length of the subject for matching stops fruitless searches -in large trees taking too much time. */ - -match_size = (size > MAX_MATCH_SIZE)? MAX_MATCH_SIZE : size; - -/* Create a compile context, and set a limit on the size of the compiled -pattern. This stops the fuzzer using vast amounts of memory. */ - -compile_context = pcre2_compile_context_create(NULL); -if (compile_context == NULL) - { -#ifdef STANDALONE - fprintf(stderr, "** Failed to create compile context block\n"); -#endif - abort(); - } -pcre2_set_max_pattern_compiled_length(compile_context, 10*1024*1024); - -/* Ensure that all undefined option bits are zero (waste of time trying them) -and also that PCRE2_NO_UTF_CHECK is unset, as there is no guarantee that the -input is valid UTF. Also unset PCRE2_NEVER_UTF and PCRE2_NEVER_UCP as there is -no reason to disallow UTF and UCP. Force PCRE2_NEVER_BACKSLASH_C to be set -because \C in random patterns is highly likely to cause a crash. */ - -compile_options = ((random_options >> 32) & ALLOWED_COMPILE_OPTIONS) | - PCRE2_NEVER_BACKSLASH_C; -match_options = (((uint32_t)random_options) & ALLOWED_MATCH_OPTIONS) | - BASE_MATCH_OPTIONS; - -/* Discard partial matching if PCRE2_ENDANCHORED is set, because they are not -allowed together and just give an immediate error return. */ - -if (((compile_options|match_options) & PCRE2_ENDANCHORED) != 0) - match_options &= ~(PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT); - -/* Do the compile with and without the options, and after a successful compile, -likewise do the match with and without the options. */ - -for (int i = 0; i < 2; i++) - { - uint32_t callout_count; - int errorcode; -#ifdef SUPPORT_JIT - int errorcode_jit; -#ifdef SUPPORT_DIFF_FUZZ - int matches = 0; - int matches_jit = 0; -#endif -#endif - PCRE2_SIZE erroroffset; - pcre2_code *code; - -#ifdef STANDALONE - printf("\n"); - print_compile_options(stdout, compile_options); -#endif - - code = pcre2_compile((PCRE2_SPTR)wdata, (PCRE2_SIZE)size, compile_options, - &errorcode, &erroroffset, compile_context); - - /* Compilation succeeded */ - - if (code != NULL) - { - int j; - uint32_t save_match_options = match_options; - - /* Call JIT compile only if the compiled pattern is not too big. */ - -#ifdef SUPPORT_JIT - int jit_ret = -1; - if (((struct pcre2_real_code *)code)->blocksize <= JIT_SIZE_LIMIT) - { -#ifdef STANDALONE - printf("Compile succeeded; calling JIT compile\n"); -#endif - jit_ret = pcre2_jit_compile(code, PCRE2_JIT_COMPLETE); -#ifdef STANDALONE - if (jit_ret < 0) printf("JIT compile error %d\n", jit_ret); -#endif - } - else - { -#ifdef STANDALONE - printf("Not calling JIT: compiled pattern is too long " - "(%ld bytes; limit=%d)\n", - ((struct pcre2_real_code *)code)->blocksize, JIT_SIZE_LIMIT); -#endif - } -#endif /* SUPPORT_JIT */ - - /* Create match data and context blocks only when we first need them. Set - low match and depth limits to avoid wasting too much searching large - pattern trees. Almost all matches are going to fail. */ - - if (match_data == NULL) - { - match_data = pcre2_match_data_create(32, NULL); -#ifdef SUPPORT_JIT - match_data_jit = pcre2_match_data_create(32, NULL); - if (match_data == NULL || match_data_jit == NULL) -#else - if (match_data == NULL) -#endif - { -#ifdef STANDALONE - fprintf(stderr, "** Failed to create match data block\n"); -#endif - abort(); - } - } - - if (match_context == NULL) - { - match_context = pcre2_match_context_create(NULL); - if (match_context == NULL) - { -#ifdef STANDALONE - fprintf(stderr, "** Failed to create match context block\n"); -#endif - abort(); - } - (void)pcre2_set_match_limit(match_context, 100); - (void)pcre2_set_depth_limit(match_context, 100); - (void)pcre2_set_callout(match_context, callout_function, &callout_count); - } - - /* Match twice, with and without options. */ - -#ifdef STANDALONE - printf("\n"); -#endif - for (j = 0; j < 2; j++) - { -#ifdef STANDALONE - print_match_options(stdout, match_options); -#endif - - callout_count = 0; - errorcode = pcre2_match(code, (PCRE2_SPTR)wdata, (PCRE2_SIZE)match_size, 0, - match_options, match_data, match_context); - -#ifdef STANDALONE - if (errorcode >= 0) printf("Match returned %d\n", errorcode); else - print_error(stdout, errorcode, "Match failed: error %d: ", errorcode); -#endif - -/* If JIT is enabled, do a JIT match and, if appropriately compiled, compare -with the interpreter. */ - -#ifdef SUPPORT_JIT - if (jit_ret >= 0) - { -#ifdef STANDALONE - printf("Matching with JIT\n"); -#endif - callout_count = 0; - errorcode_jit = pcre2_match(code, (PCRE2_SPTR)wdata, (PCRE2_SIZE)match_size, 0, - match_options & ~PCRE2_NO_JIT, match_data_jit, match_context); - -#ifdef STANDALONE - if (errorcode_jit >= 0) - printf("Match returned %d\n", errorcode_jit); - else - print_error(stdout, errorcode_jit, "JIT match failed: error %d: ", - errorcode_jit); -#else - (void)errorcode_jit; /* Avoid compiler warning */ -#endif /* STANDALONE */ - -/* With differential matching enabled, compare with interpreter. */ - -#ifdef SUPPORT_DIFF_FUZZ - matches = errorcode; - matches_jit = errorcode_jit; - - if (errorcode_jit != errorcode) - { - if (!(errorcode < 0 && errorcode_jit < 0) && - errorcode != PCRE2_ERROR_MATCHLIMIT && errorcode != PCRE2_ERROR_CALLOUT && - errorcode_jit != PCRE2_ERROR_MATCHLIMIT && errorcode_jit != PCRE2_ERROR_JIT_STACKLIMIT && errorcode_jit != PCRE2_ERROR_CALLOUT) - { - describe_failure("match errorcode comparison", wdata, size, compile_options, match_options, errorcode, errorcode_jit, matches, matches_jit, match_data, match_data_jit); - } - } - else - { - for (int index = 0; index < errorcode; index++) - { - PCRE2_UCHAR *bufferptr, *bufferptr_jit; - PCRE2_SIZE bufflen, bufflen_jit; - - bufferptr = bufferptr_jit = NULL; - bufflen = bufflen_jit = 0; - - errorcode = pcre2_substring_get_bynumber(match_data, (uint32_t) index, &bufferptr, &bufflen); - errorcode_jit = pcre2_substring_get_bynumber(match_data_jit, (uint32_t) index, &bufferptr_jit, &bufflen_jit); - - if (errorcode != errorcode_jit) - { - describe_failure("match entry errorcode comparison", wdata, size, - compile_options, match_options, errorcode, errorcode_jit, - matches, matches_jit, match_data, match_data_jit); - } - - if (errorcode >= 0) - { - if (bufflen != bufflen_jit) - { - describe_failure("match entry length comparison", wdata, size, - compile_options, match_options, errorcode, errorcode_jit, - matches, matches_jit, match_data, match_data_jit); - } - - if (memcmp(bufferptr, bufferptr_jit, bufflen) != 0) - { - describe_failure("match entry content comparison", wdata, size, - compile_options, match_options, errorcode, errorcode_jit, - matches, matches_jit, match_data, match_data_jit); - } - } - - pcre2_substring_free(bufferptr); - pcre2_substring_free(bufferptr_jit); - } - } -#endif /* SUPPORT_DIFF_FUZZ */ - } -#endif /* SUPPORT_JIT */ - - if (match_options == BASE_MATCH_OPTIONS) break; /* Don't do same twice */ - match_options = BASE_MATCH_OPTIONS; /* For second time */ - } - - /* Match with DFA twice, with and without options, but remove options that - are not allowed with DFA. */ - - match_options = save_match_options & ~BASE_MATCH_OPTIONS; - -#ifdef STANDALONE - printf("\n"); -#endif - - for (j = 0; j < 2; j++) - { -#ifdef STANDALONE - printf("DFA match options %.8x =", match_options); - printf("%s%s%s%s%s%s%s%s%s\n", - ((match_options & PCRE2_ANCHORED) != 0)? " anchored" : "", - ((match_options & PCRE2_ENDANCHORED) != 0)? " endanchored" : "", - ((match_options & PCRE2_NO_UTF_CHECK) != 0)? " no_utf_check" : "", - ((match_options & PCRE2_NOTBOL) != 0)? " notbol" : "", - ((match_options & PCRE2_NOTEMPTY) != 0)? " notempty" : "", - ((match_options & PCRE2_NOTEMPTY_ATSTART) != 0)? " notempty_atstart" : "", - ((match_options & PCRE2_NOTEOL) != 0)? " noteol" : "", - ((match_options & PCRE2_PARTIAL_HARD) != 0)? " partial_hard" : "", - ((match_options & PCRE2_PARTIAL_SOFT) != 0)? " partial_soft" : ""); -#endif - - callout_count = 0; - errorcode = pcre2_dfa_match(code, (PCRE2_SPTR)wdata, - (PCRE2_SIZE)match_size, 0, match_options, match_data, - match_context, dfa_workspace, DFA_WORKSPACE_COUNT); - -#ifdef STANDALONE - if (errorcode >= 0) - printf("Match returned %d\n", errorcode); - else - print_error(stdout, errorcode, "DFA match failed: error %d: ", errorcode); -#endif - - if (match_options == 0) break; /* No point doing same twice */ - match_options = 0; /* For second time */ - } - - match_options = save_match_options; /* Reset for the second compile */ - pcre2_code_free(code); - } - - /* Compilation failed */ - - else - { -#ifdef STANDALONE - print_error(stdout, errorcode, "Error %d at offset %lu: ", errorcode, - erroroffset); -#else - if (errorcode == PCRE2_ERROR_INTERNAL) abort(); -#endif - } - - if (compile_options == PCRE2_NEVER_BACKSLASH_C) break; /* Avoid same twice */ - compile_options = PCRE2_NEVER_BACKSLASH_C; /* For second time */ - } - -/* Tidy up before exiting */ - -if (match_data != NULL) pcre2_match_data_free(match_data); -#ifdef SUPPORT_JIT -if (match_data_jit != NULL) pcre2_match_data_free(match_data_jit); -#endif -free(newwdata); -if (match_context != NULL) pcre2_match_context_free(match_context); -if (compile_context != NULL) pcre2_compile_context_free(compile_context); -return 0; -} - - -/* Optional main program. */ - -#ifdef STANDALONE -int main(int argc, char **argv) -{ -LLVMFuzzerInitialize(&argc, &argv); - -if (argc < 2) - { - printf("** No arguments given\n"); - return 0; - } - -for (int i = 1; i < argc; i++) - { - size_t filelen; - size_t readsize; - unsigned char *buffer; - FILE *f; - - /* Handle a literal string. Copy to an exact size buffer so that checks for - overrunning work. */ - - if (argv[i][0] == '=') - { - readsize = strlen(argv[i]) - 1; - printf("------ ------\n"); - printf("Length = %lu\n", readsize); - printf("%.*s\n", (int)readsize, argv[i]+1); - buffer = (unsigned char *)malloc(readsize); - if (buffer == NULL) - printf("** Failed to allocate %lu bytes of memory\n", readsize); - else - { - memcpy(buffer, argv[i]+1, readsize); - LLVMFuzzerTestOneInput(buffer, readsize); - free(buffer); - } - continue; - } - - /* Handle a string given in a file */ - - f = fopen(argv[i], "rb"); - if (f == NULL) - { - printf("** Failed to open %s: %s\n", argv[i], strerror(errno)); - continue; - } - - printf("------ %s ------\n", argv[i]); - - fseek(f, 0, SEEK_END); - filelen = ftell(f); - fseek(f, 0, SEEK_SET); - - buffer = (unsigned char *)malloc(filelen); - if (buffer == NULL) - { - printf("** Failed to allocate %lu bytes of memory\n", filelen); - fclose(f); - continue; - } - - readsize = fread(buffer, 1, filelen, f); - fclose(f); - - if (readsize != filelen) - printf("** File size is %lu but fread() returned %lu\n", filelen, readsize); - else - { - printf("Length = %lu\n", filelen); - LLVMFuzzerTestOneInput(buffer, filelen); - } - free(buffer); - } - -return 0; -} -#endif /* STANDALONE */ - -/* End */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_internal.h b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_internal.h deleted file mode 100644 index aa79409..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_internal.h +++ /dev/null @@ -1,2353 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE2 is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - -#ifndef PCRE2_INTERNAL_H_IDEMPOTENT_GUARD -#define PCRE2_INTERNAL_H_IDEMPOTENT_GUARD - -/* We do not assume that the config.h file has an idempotent include guard, -since it may well be written by clients. The standard Autoheader config.h does -not have an include guard (although we could customise that). */ - -#if defined HAVE_CONFIG_H && !defined PCRE2_CONFIG_H_IDEMPOTENT_GUARD -#define PCRE2_CONFIG_H_IDEMPOTENT_GUARD -#include "config.h" -#endif - -/* We do not support both EBCDIC and Unicode at the same time. The "configure" -script prevents both being selected, but not everybody uses "configure". EBCDIC -is only supported for the 8-bit library, but the check for this has to be later -in this file, because the first part is not width-dependent, and is included by -pcre2test.c with CODE_UNIT_WIDTH == 0. */ - -#if defined EBCDIC && defined SUPPORT_UNICODE -#error The use of both EBCDIC and SUPPORT_UNICODE is not supported. -#endif - -/* When compiling one of the libraries, the value of PCRE2_CODE_UNIT_WIDTH must -be 8, 16, or 32. AutoTools and CMake ensure that this is always the case, but -other other building methods may not, so here is a check. It is cut out when -building pcre2test, bcause that sets the value to zero. No other source should -be including this file. There is no explicit way of forcing a compile to be -abandoned, but trying to include a non-existent file seems cleanest. Otherwise -there will be many irrelevant consequential errors. */ - -#if (!defined PCRE2_PCRE2TEST && !defined PCRE2_DFTABLES) && \ - (!defined PCRE2_CODE_UNIT_WIDTH || \ - (PCRE2_CODE_UNIT_WIDTH != 8 && \ - PCRE2_CODE_UNIT_WIDTH != 16 && \ - PCRE2_CODE_UNIT_WIDTH != 32)) -#error PCRE2_CODE_UNIT_WIDTH must be defined as 8, 16, or 32. -#endif - - -/* Standard C headers */ - -#include -#include -#include -#include -#include -#include - -/* Macros to make boolean values more obvious. The #ifndef is to pacify -compiler warnings in environments where these macros are defined elsewhere. -Unfortunately, there is no way to do the same for the typedef. */ - -typedef int BOOL; -#ifndef FALSE -#define FALSE 0 -#define TRUE 1 -#endif - -/* Helper macro for static (compile-time) assertions. Can be used inside -functions, or at the top-level of a file. */ -#define STATIC_ASSERT_JOIN(a,b) a ## b -#define STATIC_ASSERT(cond, msg) \ - typedef int STATIC_ASSERT_JOIN(static_assertion_,msg)[(cond)?1:-1] - -/* Valgrind (memcheck) support */ - -#ifdef SUPPORT_VALGRIND -#include -#endif - -/* -ftrivial-auto-var-init support supports initializing all local variables -to avoid some classes of bug, but this can cause an unacceptable slowdown -for large on-stack arrays in hot functions. This macro lets us annotate -such arrays. */ - -#ifdef HAVE_ATTRIBUTE_UNINITIALIZED -#define PCRE2_KEEP_UNINITIALIZED __attribute__((uninitialized)) -#else -#define PCRE2_KEEP_UNINITIALIZED -#endif - -/* Older versions of MSVC lack snprintf(). This define allows for -warning/error-free compilation and testing with MSVC compilers back to at least -MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */ - -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define snprintf _snprintf -#endif - -/* When compiling a DLL for Windows, the exported symbols have to be declared -using some MS magic, as documented here: -https://learn.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-declspec-dllexport - -In pcre2.h (which is included below), we define only PCRE2_EXP_DECL, -which is all that is needed for applications (they just import the symbols). To -compile the library, we use: - - PCRE2_EXP_DECL for declarations - PCRE2_EXP_DEFN for definitions - -The reason for wrapping this in #ifndef PCRE2_EXP_DECL is so that pcre2test, -which is an application, but needs to import this file in order to "peek" at -internals, can #include pcre2.h first to get an application's-eye view. - -In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon, -special-purpose environments) might want to stick other stuff in front of -exported symbols. That's why, in the non-Windows case, we set PCRE2_EXP_DEFN -only if it is not already set. */ - -#if defined __cplusplus -#error This project uses C99. C++ is not supported. -#endif - -#ifndef PCRE2_EXP_DECL -# if defined(_WIN32) && !defined(PCRE2_STATIC) -# define PCRE2_EXP_DECL extern __declspec(dllexport) -# else -# define PCRE2_EXP_DECL extern PCRE2_EXPORT -# endif -#endif - -#ifndef PCRE2_EXP_DEFN -# if defined(_WIN32) && !defined(PCRE2_STATIC) -# define PCRE2_EXP_DEFN extern __declspec(dllexport) -# else -# define PCRE2_EXP_DEFN extern PCRE2_EXPORT -# endif -#endif - -/* Include the public PCRE2 header and the definitions of UCP character -property values. This must follow the setting of PCRE2_EXP_DECL above. */ - -#include "pcre2.h" -#include "pcre2_ucp.h" - -/* When checking for integer overflow, we need to handle large integers. -If a 64-bit integer type is available, we can use that. -Otherwise we have to cast to double, which of course requires floating point -arithmetic. Handle this by defining a macro for the appropriate type. */ - -#if defined INT64_MAX || defined int64_t -#define INT64_OR_DOUBLE int64_t -#else -#define INT64_OR_DOUBLE double -#endif - -/* External (in the C sense) functions and tables that are private to the -libraries are always referenced using the PRIV macro. This makes it possible -for pcre2test.c to include some of the source files from the libraries using a -different PRIV definition to avoid name clashes. It also makes it clear in the -code that a non-static object is being referenced. */ - -#ifndef PRIV -#define PRIV(name) _pcre2_##name -#endif - -/* This is an unsigned int value that no UTF character can ever have, as -Unicode doesn't go beyond 0x0010ffff. */ - -#define NOTACHAR 0xffffffff - -/* This is the largest valid UTF/Unicode code point. */ - -#define MAX_UTF_CODE_POINT 0x10ffff - -/* Compile-time positive error numbers (all except UTF errors, which are -negative) start at this value. It should probably never be changed, in case -some application is checking for specific numbers. There is a copy of this -#define in pcre2posix.c (which now no longer includes this file). Ideally, a -way of having a single definition should be found, but as the number is -unlikely to change, this is not a pressing issue. The original reason for -having a base other than 0 was to keep the absolute values of compile-time and -run-time error numbers numerically different, but in the event the code does -not rely on this. */ - -#define COMPILE_ERROR_BASE 100 - -/* The initial frames vector for remembering pcre2_match() backtracking points -is allocated on the heap, of this size (bytes) or ten times the frame size if -larger, unless the heap limit is smaller. Typical frame sizes are a few hundred -bytes (it depends on the number of capturing parentheses) so 20KiB handles -quite a few frames. A larger vector on the heap is obtained for matches that -need more frames, subject to the heap limit. */ - -#define START_FRAMES_SIZE 20480 - -/* For DFA matching, an initial internal workspace vector is allocated on the -stack. The heap is used only if this turns out to be too small. */ - -#define DFA_START_RWS_SIZE 30720 - -/* Define the default BSR convention. */ - -#ifdef BSR_ANYCRLF -#define BSR_DEFAULT PCRE2_BSR_ANYCRLF -#else -#define BSR_DEFAULT PCRE2_BSR_UNICODE -#endif - - -/* ---------------- Basic UTF-8 macros ---------------- */ - -/* These UTF-8 macros are always defined because they are used in pcre2test for -handling wide characters in 16-bit and 32-bit modes, even if an 8-bit library -is not supported. */ - -/* Tests whether a UTF-8 code point needs extra bytes to decode. */ - -#define HASUTF8EXTRALEN(c) ((c) >= 0xc0) - -/* The following macros were originally written in the form of loops that used -data from the tables whose names start with PRIV(utf8_table). They were -rewritten by a user so as not to use loops, because in some environments this -gives a significant performance advantage, and it seems never to do any harm. -*/ - -/* Base macro to pick up the remaining bytes of a UTF-8 character, not -advancing the pointer. */ - -#define GETUTF8(c, eptr) \ - { \ - if ((c & 0x20u) == 0) \ - c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \ - else if ((c & 0x10u) == 0) \ - c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \ - else if ((c & 0x08u) == 0) \ - c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \ - ((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \ - else if ((c & 0x04u) == 0) \ - c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \ - ((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \ - (eptr[4] & 0x3fu); \ - else \ - c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \ - ((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \ - ((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \ - } - -/* Base macro to pick up the remaining bytes of a UTF-8 character, advancing -the pointer. */ - -#define GETUTF8INC(c, eptr) \ - { \ - if ((c & 0x20u) == 0) \ - c = ((c & 0x1fu) << 6) | (*eptr++ & 0x3fu); \ - else if ((c & 0x10u) == 0) \ - { \ - c = ((c & 0x0fu) << 12) | ((*eptr & 0x3fu) << 6) | (eptr[1] & 0x3fu); \ - eptr += 2; \ - } \ - else if ((c & 0x08u) == 0) \ - { \ - c = ((c & 0x07u) << 18) | ((*eptr & 0x3fu) << 12) | \ - ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \ - eptr += 3; \ - } \ - else if ((c & 0x04u) == 0) \ - { \ - c = ((c & 0x03u) << 24) | ((*eptr & 0x3fu) << 18) | \ - ((eptr[1] & 0x3fu) << 12) | ((eptr[2] & 0x3fu) << 6) | \ - (eptr[3] & 0x3fu); \ - eptr += 4; \ - } \ - else \ - { \ - c = ((c & 0x01u) << 30) | ((*eptr & 0x3fu) << 24) | \ - ((eptr[1] & 0x3fu) << 18) | ((eptr[2] & 0x3fu) << 12) | \ - ((eptr[3] & 0x3fu) << 6) | (eptr[4] & 0x3fu); \ - eptr += 5; \ - } \ - } - -/* Base macro to pick up the remaining bytes of a UTF-8 character, not -advancing the pointer, incrementing the length. */ - -#define GETUTF8LEN(c, eptr, len) \ - { \ - if ((c & 0x20u) == 0) \ - { \ - c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \ - len++; \ - } \ - else if ((c & 0x10u) == 0) \ - { \ - c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \ - len += 2; \ - } \ - else if ((c & 0x08u) == 0) \ - {\ - c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \ - ((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \ - len += 3; \ - } \ - else if ((c & 0x04u) == 0) \ - { \ - c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \ - ((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \ - (eptr[4] & 0x3fu); \ - len += 4; \ - } \ - else \ - {\ - c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \ - ((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \ - ((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \ - len += 5; \ - } \ - } - -/* --------------- Whitespace macros ---------------- */ - -/* Tests for Unicode horizontal and vertical whitespace characters must check a -number of different values. Using a switch statement for this generates the -fastest code (no loop, no memory access), and there are several places in the -interpreter code where this happens. In order to ensure that all the case lists -remain in step, we use macros so that there is only one place where the lists -are defined. - -These values are also required as lists in pcre2_compile.c when processing \h, -\H, \v and \V in a character class. The lists are defined in pcre2_tables.c, -but macros that define the values are here so that all the definitions are -together. The lists must be in ascending character order, terminated by -NOTACHAR (which is 0xffffffff). - -Any changes should ensure that the various macros are kept in step with each -other. NOTE: The values also appear in pcre2_jit_compile.c. */ - -/* -------------- ASCII/Unicode environments -------------- */ - -#ifndef EBCDIC - -/* Character U+180E (Mongolian Vowel Separator) is not included in the list of -spaces in the Unicode file PropList.txt, and Perl does not recognize it as a -space. However, in many other sources it is listed as a space and has been in -PCRE (both APIs) for a long time. */ - -#define HSPACE_LIST \ - CHAR_HT, CHAR_SPACE, CHAR_NBSP, \ - 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, \ - 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, 0x202f, 0x205f, 0x3000, \ - NOTACHAR - -#define HSPACE_MULTIBYTE_CASES \ - case 0x1680: /* OGHAM SPACE MARK */ \ - case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ \ - case 0x2000: /* EN QUAD */ \ - case 0x2001: /* EM QUAD */ \ - case 0x2002: /* EN SPACE */ \ - case 0x2003: /* EM SPACE */ \ - case 0x2004: /* THREE-PER-EM SPACE */ \ - case 0x2005: /* FOUR-PER-EM SPACE */ \ - case 0x2006: /* SIX-PER-EM SPACE */ \ - case 0x2007: /* FIGURE SPACE */ \ - case 0x2008: /* PUNCTUATION SPACE */ \ - case 0x2009: /* THIN SPACE */ \ - case 0x200a: /* HAIR SPACE */ \ - case 0x202f: /* NARROW NO-BREAK SPACE */ \ - case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ \ - case 0x3000 /* IDEOGRAPHIC SPACE */ - -#define HSPACE_BYTE_CASES \ - case CHAR_HT: \ - case CHAR_SPACE: \ - case CHAR_NBSP - -#define HSPACE_CASES \ - HSPACE_BYTE_CASES: \ - HSPACE_MULTIBYTE_CASES - -#define VSPACE_LIST \ - CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, 0x2028, 0x2029, NOTACHAR - -#define VSPACE_MULTIBYTE_CASES \ - case 0x2028: /* LINE SEPARATOR */ \ - case 0x2029 /* PARAGRAPH SEPARATOR */ - -#define VSPACE_BYTE_CASES \ - case CHAR_LF: \ - case CHAR_VT: \ - case CHAR_FF: \ - case CHAR_CR: \ - case CHAR_NEL - -#define VSPACE_CASES \ - VSPACE_BYTE_CASES: \ - VSPACE_MULTIBYTE_CASES - -/* -------------- EBCDIC environments -------------- */ - -#else -#define HSPACE_LIST CHAR_HT, CHAR_SPACE, CHAR_NBSP, NOTACHAR - -#define HSPACE_BYTE_CASES \ - case CHAR_HT: \ - case CHAR_SPACE: \ - case CHAR_NBSP - -#define HSPACE_CASES HSPACE_BYTE_CASES - -#ifdef EBCDIC_NL25 -#define VSPACE_LIST \ - CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, CHAR_LF, NOTACHAR -#else -#define VSPACE_LIST \ - CHAR_VT, CHAR_FF, CHAR_CR, CHAR_LF, CHAR_NEL, NOTACHAR -#endif - -#define VSPACE_BYTE_CASES \ - case CHAR_LF: \ - case CHAR_VT: \ - case CHAR_FF: \ - case CHAR_CR: \ - case CHAR_NEL - -#define VSPACE_CASES VSPACE_BYTE_CASES -#endif /* EBCDIC */ - -/* -------------- End of whitespace macros -------------- */ - - -/* PCRE2 is able to support several different kinds of newline (CR, LF, CRLF, -"any" and "anycrlf" at present). The following macros are used to package up -testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various -modules to indicate in which datablock the parameters exist, and what the -start/end of string field names are. */ - -#define NLTYPE_FIXED 0 /* Newline is a fixed length string */ -#define NLTYPE_ANY 1 /* Newline is any Unicode line ending */ -#define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */ - -/* This macro checks for a newline at the given position */ - -#define IS_NEWLINE(p) \ - ((NLBLOCK->nltype != NLTYPE_FIXED)? \ - ((p) < NLBLOCK->PSEND && \ - PRIV(is_newline)((p), NLBLOCK->nltype, NLBLOCK->PSEND, \ - &(NLBLOCK->nllen), utf)) \ - : \ - ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \ - UCHAR21TEST(p) == NLBLOCK->nl[0] && \ - (NLBLOCK->nllen == 1 || UCHAR21TEST(p+1) == NLBLOCK->nl[1]) \ - ) \ - ) - -/* This macro checks for a newline immediately preceding the given position */ - -#define WAS_NEWLINE(p) \ - ((NLBLOCK->nltype != NLTYPE_FIXED)? \ - ((p) > NLBLOCK->PSSTART && \ - PRIV(was_newline)((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \ - &(NLBLOCK->nllen), utf)) \ - : \ - ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \ - UCHAR21TEST(p - NLBLOCK->nllen) == NLBLOCK->nl[0] && \ - (NLBLOCK->nllen == 1 || UCHAR21TEST(p - NLBLOCK->nllen + 1) == NLBLOCK->nl[1]) \ - ) \ - ) - -/* Private flags containing information about the compiled pattern. The first -three must not be changed, because whichever is set is actually the number of -bytes in a code unit in that mode. */ - -#define PCRE2_MODE8 0x00000001u /* compiled in 8 bit mode */ -#define PCRE2_MODE16 0x00000002u /* compiled in 16 bit mode */ -#define PCRE2_MODE32 0x00000004u /* compiled in 32 bit mode */ -#define PCRE2_FIRSTSET 0x00000010u /* first_code unit is set */ -#define PCRE2_FIRSTCASELESS 0x00000020u /* caseless first code unit */ -#define PCRE2_FIRSTMAPSET 0x00000040u /* bitmap of first code units is set */ -#define PCRE2_LASTSET 0x00000080u /* last code unit is set */ -#define PCRE2_LASTCASELESS 0x00000100u /* caseless last code unit */ -#define PCRE2_STARTLINE 0x00000200u /* start after \n for multiline */ -#define PCRE2_JCHANGED 0x00000400u /* j option used in pattern */ -#define PCRE2_HASCRORLF 0x00000800u /* explicit \r or \n in pattern */ -#define PCRE2_HASTHEN 0x00001000u /* pattern contains (*THEN) */ -#define PCRE2_MATCH_EMPTY 0x00002000u /* pattern can match empty string */ -#define PCRE2_BSR_SET 0x00004000u /* BSR was set in the pattern */ -#define PCRE2_NL_SET 0x00008000u /* newline was set in the pattern */ -#define PCRE2_NOTEMPTY_SET 0x00010000u /* (*NOTEMPTY) used ) keep */ -#define PCRE2_NE_ATST_SET 0x00020000u /* (*NOTEMPTY_ATSTART) used) together */ -#define PCRE2_DEREF_TABLES 0x00040000u /* release character tables */ -#define PCRE2_NOJIT 0x00080000u /* (*NOJIT) used */ -#define PCRE2_HASBKPORX 0x00100000u /* contains \P, \p, or \X */ -#define PCRE2_DUPCAPUSED 0x00200000u /* contains (?| */ -#define PCRE2_HASBKC 0x00400000u /* contains \C */ -#define PCRE2_HASACCEPT 0x00800000u /* contains (*ACCEPT) */ -#define PCRE2_HASBSK 0x01000000u /* contains \K */ - -#define PCRE2_MODE_MASK (PCRE2_MODE8 | PCRE2_MODE16 | PCRE2_MODE32) - -/* Values for the matchedby field in a match data block. */ - -enum { PCRE2_MATCHEDBY_INTERPRETER, /* pcre2_match() */ - PCRE2_MATCHEDBY_DFA_INTERPRETER, /* pcre2_dfa_match() */ - PCRE2_MATCHEDBY_JIT }; /* pcre2_jit_match() */ - -/* Values for the flags field in a match data block. */ - -#define PCRE2_MD_COPIED_SUBJECT 0x01u - -/* Magic number to provide a small check against being handed junk. */ - -#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */ - -/* The maximum remaining length of subject we are prepared to search for a -req_unit match from an anchored pattern. In 8-bit mode, memchr() is used and is -much faster than the search loop that has to be used in 16-bit and 32-bit -modes. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -#define REQ_CU_MAX 5000 -#else -#define REQ_CU_MAX 2000 -#endif - -/* The maximum nesting depth for Unicode character class sets. -Currently fixed. Warning: the interpreter relies on this so it can encode -the operand stack in a uint32_t. A nesting limit of 15 implies (15*2+1)=31 -stack operands required, due to the fact that we have two (and only two) -levels of operator precedence. In the UTS#18 syntax, you can write 'x&&y[z]' -and in Perl syntax you can write '(?[ x - y & (z) ])', both of which imply -pushing the match results for x & y to the stack. */ - -#define ECLASS_NEST_LIMIT 15 - -/* Offsets for the bitmap tables in the cbits set of tables. Each table -contains a set of bits for a class map. Some classes are built by combining -these tables. */ - -#define cbit_space 0 /* [:space:] or \s */ -#define cbit_xdigit 32 /* [:xdigit:] */ -#define cbit_digit 64 /* [:digit:] or \d */ -#define cbit_upper 96 /* [:upper:] */ -#define cbit_lower 128 /* [:lower:] */ -#define cbit_word 160 /* [:word:] or \w */ -#define cbit_graph 192 /* [:graph:] */ -#define cbit_print 224 /* [:print:] */ -#define cbit_punct 256 /* [:punct:] */ -#define cbit_cntrl 288 /* [:cntrl:] */ -#define cbit_length 320 /* Length of the cbits table */ - -/* Bit definitions for entries in the ctypes table. Do not change these values -without checking pcre2_jit_compile.c, which has an assertion to ensure that -ctype_word has the value 16. */ - -#define ctype_space 0x01 -#define ctype_letter 0x02 -#define ctype_lcletter 0x04 -#define ctype_digit 0x08 -#define ctype_word 0x10 /* alphanumeric or '_' */ - -/* Offsets of the various tables from the base tables pointer, and -total length of the tables. */ - -#define lcc_offset 0 /* Lower case */ -#define fcc_offset 256 /* Flip case */ -#define cbits_offset 512 /* Character classes */ -#define ctypes_offset (cbits_offset + cbit_length) /* Character types */ -#define TABLES_LENGTH (ctypes_offset + 256) - -/* Private flags used in compile_context.optimization_flags */ - -#define PCRE2_OPTIM_AUTO_POSSESS 0x00000001u -#define PCRE2_OPTIM_DOTSTAR_ANCHOR 0x00000002u -#define PCRE2_OPTIM_START_OPTIMIZE 0x00000004u - -#define PCRE2_OPTIMIZATION_ALL 0x00000007u - -/* -------------------- Character and string names ------------------------ */ - -/* If PCRE2 is to support UTF-8 on EBCDIC platforms, we cannot use normal -character constants like '*' because the compiler would emit their EBCDIC code, -which is different from their ASCII/UTF-8 code. Instead we define macros for -the characters so that they always use the ASCII/UTF-8 code when UTF-8 support -is enabled. When UTF-8 support is not enabled, the definitions use character -literals. Both character and string versions of each character are needed, and -there are some longer strings as well. - -This means that, on EBCDIC platforms, the PCRE2 library can handle either -EBCDIC, or UTF-8, but not both. To support both in the same compiled library -would need different lookups depending on whether PCRE2_UTF was set or not. -This would make it impossible to use characters in switch/case statements, -which would reduce performance. For a theoretical use (which nobody has asked -for) in a minority area (EBCDIC platforms), this is not sensible. Any -application that did need both could compile two versions of the library, using -macros to give the functions distinct names. */ - -#ifndef SUPPORT_UNICODE - -/* UTF-8 support is not enabled; use the platform-dependent character literals -so that PCRE2 works in both ASCII and EBCDIC environments, but only in non-UTF -mode. Newline characters are problematic in EBCDIC. Though it has CR and LF -characters, a common practice has been to use its NL (0x15) character as the -line terminator in C-like processing environments. However, sometimes the LF -(0x25) character is used instead, according to this Unicode document: - -http://unicode.org/standard/reports/tr13/tr13-5.html - -PCRE2 defaults EBCDIC NL to 0x15, but has a build-time option to select 0x25 -instead. Whichever is *not* chosen is defined as NEL. - -In both ASCII and EBCDIC environments, CHAR_NL and CHAR_LF are synonyms for the -same code point. */ - -#ifdef EBCDIC - -#ifndef EBCDIC_NL25 -#define CHAR_NL '\x15' -#define CHAR_NEL '\x25' -#define STR_NL "\x15" -#define STR_NEL "\x25" -#else -#define CHAR_NL '\x25' -#define CHAR_NEL '\x15' -#define STR_NL "\x25" -#define STR_NEL "\x15" -#endif - -#define CHAR_LF CHAR_NL -#define STR_LF STR_NL - -#define CHAR_ESC '\047' -#define CHAR_DEL '\007' -#define CHAR_NBSP ((unsigned char)'\x41') -#define STR_ESC "\047" -#define STR_DEL "\007" - -#else /* Not EBCDIC */ - -/* In ASCII/Unicode, linefeed is '\n' and we equate this to NL for -compatibility. NEL is the Unicode newline character; make sure it is -a positive value. */ - -#if '\n' != 0x0a -#error "ASCII character '\n' is not 0x0a" -#endif - -#define CHAR_LF '\n' -#define CHAR_NL CHAR_LF -#define CHAR_NEL ((unsigned char)'\x85') -#define CHAR_ESC '\033' -#define CHAR_DEL '\177' -#define CHAR_NBSP ((unsigned char)'\xa0') - -#define STR_LF "\n" -#define STR_NL STR_LF -#define STR_NEL "\x85" -#define STR_ESC "\033" -#define STR_DEL "\177" - -#endif /* EBCDIC */ - -/* When we want to use EBCDIC with an ASCII compiler, for testing EBCDIC on -ASCII platforms, then we can hardcode an EBCDIC codepage (IBM-1047). */ - -#ifdef EBCDIC_IGNORING_COMPILER - -#define CHAR_NUL '\000' -#define CHAR_HT '\005' -#define CHAR_VT '\013' -#define CHAR_FF '\014' -#define CHAR_CR '\015' -#define CHAR_BS '\026' -#define CHAR_BEL '\057' - -#define CHAR_SPACE '\100' -#define CHAR_EXCLAMATION_MARK '\132' -#define CHAR_QUOTATION_MARK '\177' -#define CHAR_NUMBER_SIGN '\173' -#define CHAR_DOLLAR_SIGN '\133' -#define CHAR_PERCENT_SIGN '\154' -#define CHAR_AMPERSAND '\120' -#define CHAR_APOSTROPHE '\175' -#define CHAR_LEFT_PARENTHESIS '\115' -#define CHAR_RIGHT_PARENTHESIS '\135' -#define CHAR_ASTERISK '\134' -#define CHAR_PLUS '\116' -#define CHAR_COMMA '\153' -#define CHAR_MINUS '\140' -#define CHAR_DOT '\113' -#define CHAR_SLASH '\141' -#define CHAR_0 ((unsigned char)'\xf0') -#define CHAR_1 ((unsigned char)'\xf1') -#define CHAR_2 ((unsigned char)'\xf2') -#define CHAR_3 ((unsigned char)'\xf3') -#define CHAR_4 ((unsigned char)'\xf4') -#define CHAR_5 ((unsigned char)'\xf5') -#define CHAR_6 ((unsigned char)'\xf6') -#define CHAR_7 ((unsigned char)'\xf7') -#define CHAR_8 ((unsigned char)'\xf8') -#define CHAR_9 ((unsigned char)'\xf9') -#define CHAR_COLON '\172' -#define CHAR_SEMICOLON '\136' -#define CHAR_LESS_THAN_SIGN '\114' -#define CHAR_EQUALS_SIGN '\176' -#define CHAR_GREATER_THAN_SIGN '\156' -#define CHAR_QUESTION_MARK '\157' -#define CHAR_COMMERCIAL_AT '\174' -#define CHAR_A ((unsigned char)'\xc1') -#define CHAR_B ((unsigned char)'\xc2') -#define CHAR_C ((unsigned char)'\xc3') -#define CHAR_D ((unsigned char)'\xc4') -#define CHAR_E ((unsigned char)'\xc5') -#define CHAR_F ((unsigned char)'\xc6') -#define CHAR_G ((unsigned char)'\xc7') -#define CHAR_H ((unsigned char)'\xc8') -#define CHAR_I ((unsigned char)'\xc9') -#define CHAR_J ((unsigned char)'\xd1') -#define CHAR_K ((unsigned char)'\xd2') -#define CHAR_L ((unsigned char)'\xd3') -#define CHAR_M ((unsigned char)'\xd4') -#define CHAR_N ((unsigned char)'\xd5') -#define CHAR_O ((unsigned char)'\xd6') -#define CHAR_P ((unsigned char)'\xd7') -#define CHAR_Q ((unsigned char)'\xd8') -#define CHAR_R ((unsigned char)'\xd9') -#define CHAR_S ((unsigned char)'\xe2') -#define CHAR_T ((unsigned char)'\xe3') -#define CHAR_U ((unsigned char)'\xe4') -#define CHAR_V ((unsigned char)'\xe5') -#define CHAR_W ((unsigned char)'\xe6') -#define CHAR_X ((unsigned char)'\xe7') -#define CHAR_Y ((unsigned char)'\xe8') -#define CHAR_Z ((unsigned char)'\xe9') -#define CHAR_LEFT_SQUARE_BRACKET ((unsigned char)'\xad') -#define CHAR_BACKSLASH ((unsigned char)'\xe0') -#define CHAR_RIGHT_SQUARE_BRACKET ((unsigned char)'\xbd') -#define CHAR_CIRCUMFLEX_ACCENT '\137' -#define CHAR_UNDERSCORE '\155' -#define CHAR_GRAVE_ACCENT '\171' -#define CHAR_a ((unsigned char)'\x81') -#define CHAR_b ((unsigned char)'\x82') -#define CHAR_c ((unsigned char)'\x83') -#define CHAR_d ((unsigned char)'\x84') -#define CHAR_e ((unsigned char)'\x85') -#define CHAR_f ((unsigned char)'\x86') -#define CHAR_g ((unsigned char)'\x87') -#define CHAR_h ((unsigned char)'\x88') -#define CHAR_i ((unsigned char)'\x89') -#define CHAR_j ((unsigned char)'\x91') -#define CHAR_k ((unsigned char)'\x92') -#define CHAR_l ((unsigned char)'\x93') -#define CHAR_m ((unsigned char)'\x94') -#define CHAR_n ((unsigned char)'\x95') -#define CHAR_o ((unsigned char)'\x96') -#define CHAR_p ((unsigned char)'\x97') -#define CHAR_q ((unsigned char)'\x98') -#define CHAR_r ((unsigned char)'\x99') -#define CHAR_s ((unsigned char)'\xa2') -#define CHAR_t ((unsigned char)'\xa3') -#define CHAR_u ((unsigned char)'\xa4') -#define CHAR_v ((unsigned char)'\xa5') -#define CHAR_w ((unsigned char)'\xa6') -#define CHAR_x ((unsigned char)'\xa7') -#define CHAR_y ((unsigned char)'\xa8') -#define CHAR_z ((unsigned char)'\xa9') -#define CHAR_LEFT_CURLY_BRACKET ((unsigned char)'\xc0') -#define CHAR_VERTICAL_LINE '\117' -#define CHAR_RIGHT_CURLY_BRACKET ((unsigned char)'\xd0') -#define CHAR_TILDE ((unsigned char)'\xa1') - -#define STR_HT "\005" -#define STR_VT "\013" -#define STR_FF "\014" -#define STR_CR "\015" -#define STR_BS "\026" -#define STR_BEL "\057" - -#define STR_SPACE "\100" -#define STR_EXCLAMATION_MARK "\132" -#define STR_QUOTATION_MARK "\177" -#define STR_NUMBER_SIGN "\173" -#define STR_DOLLAR_SIGN "\133" -#define STR_PERCENT_SIGN "\154" -#define STR_AMPERSAND "\120" -#define STR_APOSTROPHE "\175" -#define STR_LEFT_PARENTHESIS "\115" -#define STR_RIGHT_PARENTHESIS "\135" -#define STR_ASTERISK "\134" -#define STR_PLUS "\116" -#define STR_COMMA "\153" -#define STR_MINUS "\140" -#define STR_DOT "\113" -#define STR_SLASH "\141" -#define STR_0 "\360" -#define STR_1 "\361" -#define STR_2 "\362" -#define STR_3 "\363" -#define STR_4 "\364" -#define STR_5 "\365" -#define STR_6 "\366" -#define STR_7 "\367" -#define STR_8 "\370" -#define STR_9 "\371" -#define STR_COLON "\172" -#define STR_SEMICOLON "\136" -#define STR_LESS_THAN_SIGN "\114" -#define STR_EQUALS_SIGN "\176" -#define STR_GREATER_THAN_SIGN "\156" -#define STR_QUESTION_MARK "\157" -#define STR_COMMERCIAL_AT "\174" -#define STR_A "\301" -#define STR_B "\302" -#define STR_C "\303" -#define STR_D "\304" -#define STR_E "\305" -#define STR_F "\306" -#define STR_G "\307" -#define STR_H "\310" -#define STR_I "\311" -#define STR_J "\321" -#define STR_K "\322" -#define STR_L "\323" -#define STR_M "\324" -#define STR_N "\325" -#define STR_O "\326" -#define STR_P "\327" -#define STR_Q "\330" -#define STR_R "\331" -#define STR_S "\342" -#define STR_T "\343" -#define STR_U "\344" -#define STR_V "\345" -#define STR_W "\346" -#define STR_X "\347" -#define STR_Y "\350" -#define STR_Z "\351" -#define STR_LEFT_SQUARE_BRACKET "\255" -#define STR_BACKSLASH "\340" -#define STR_RIGHT_SQUARE_BRACKET "\275" -#define STR_CIRCUMFLEX_ACCENT "\137" -#define STR_UNDERSCORE "\155" -#define STR_GRAVE_ACCENT "\171" -#define STR_a "\201" -#define STR_b "\202" -#define STR_c "\203" -#define STR_d "\204" -#define STR_e "\205" -#define STR_f "\206" -#define STR_g "\207" -#define STR_h "\210" -#define STR_i "\211" -#define STR_j "\221" -#define STR_k "\222" -#define STR_l "\223" -#define STR_m "\224" -#define STR_n "\225" -#define STR_o "\226" -#define STR_p "\227" -#define STR_q "\230" -#define STR_r "\231" -#define STR_s "\242" -#define STR_t "\243" -#define STR_u "\244" -#define STR_v "\245" -#define STR_w "\246" -#define STR_x "\247" -#define STR_y "\250" -#define STR_z "\251" -#define STR_LEFT_CURLY_BRACKET "\300" -#define STR_VERTICAL_LINE "\117" -#define STR_RIGHT_CURLY_BRACKET "\320" -#define STR_TILDE "\241" - -#else /* EBCDIC_IGNORING_COMPILER */ - -/* Otherwise, on a real EBCDIC compiler or an ASCII compiler, we can use simple -string and character literals. */ - -#ifdef EBCDIC -#if 'a' != 0x81 -#error "EBCDIC character 'a' is not 0x81" -#endif -#else -#if 'a' != 0x61 -#error "ASCII character 'a' is not 0x61" -#endif -#endif - -#define CHAR_NUL '\0' -#define CHAR_HT '\t' -#define CHAR_VT '\v' -#define CHAR_FF '\f' -#define CHAR_CR '\r' -#define CHAR_BS '\b' -#define CHAR_BEL '\a' - -#define CHAR_SPACE ' ' -#define CHAR_EXCLAMATION_MARK '!' -#define CHAR_QUOTATION_MARK '"' -#define CHAR_NUMBER_SIGN '#' -#define CHAR_DOLLAR_SIGN '$' -#define CHAR_PERCENT_SIGN '%' -#define CHAR_AMPERSAND '&' -#define CHAR_APOSTROPHE '\'' -#define CHAR_LEFT_PARENTHESIS '(' -#define CHAR_RIGHT_PARENTHESIS ')' -#define CHAR_ASTERISK '*' -#define CHAR_PLUS '+' -#define CHAR_COMMA ',' -#define CHAR_MINUS '-' -#define CHAR_DOT '.' -#define CHAR_SLASH '/' -#define CHAR_0 '0' -#define CHAR_1 '1' -#define CHAR_2 '2' -#define CHAR_3 '3' -#define CHAR_4 '4' -#define CHAR_5 '5' -#define CHAR_6 '6' -#define CHAR_7 '7' -#define CHAR_8 '8' -#define CHAR_9 '9' -#define CHAR_COLON ':' -#define CHAR_SEMICOLON ';' -#define CHAR_LESS_THAN_SIGN '<' -#define CHAR_EQUALS_SIGN '=' -#define CHAR_GREATER_THAN_SIGN '>' -#define CHAR_QUESTION_MARK '?' -#define CHAR_COMMERCIAL_AT '@' -#define CHAR_A 'A' -#define CHAR_B 'B' -#define CHAR_C 'C' -#define CHAR_D 'D' -#define CHAR_E 'E' -#define CHAR_F 'F' -#define CHAR_G 'G' -#define CHAR_H 'H' -#define CHAR_I 'I' -#define CHAR_J 'J' -#define CHAR_K 'K' -#define CHAR_L 'L' -#define CHAR_M 'M' -#define CHAR_N 'N' -#define CHAR_O 'O' -#define CHAR_P 'P' -#define CHAR_Q 'Q' -#define CHAR_R 'R' -#define CHAR_S 'S' -#define CHAR_T 'T' -#define CHAR_U 'U' -#define CHAR_V 'V' -#define CHAR_W 'W' -#define CHAR_X 'X' -#define CHAR_Y 'Y' -#define CHAR_Z 'Z' -#define CHAR_LEFT_SQUARE_BRACKET '[' -#define CHAR_BACKSLASH '\\' -#define CHAR_RIGHT_SQUARE_BRACKET ']' -#define CHAR_CIRCUMFLEX_ACCENT '^' -#define CHAR_UNDERSCORE '_' -#define CHAR_GRAVE_ACCENT '`' -#define CHAR_a 'a' -#define CHAR_b 'b' -#define CHAR_c 'c' -#define CHAR_d 'd' -#define CHAR_e 'e' -#define CHAR_f 'f' -#define CHAR_g 'g' -#define CHAR_h 'h' -#define CHAR_i 'i' -#define CHAR_j 'j' -#define CHAR_k 'k' -#define CHAR_l 'l' -#define CHAR_m 'm' -#define CHAR_n 'n' -#define CHAR_o 'o' -#define CHAR_p 'p' -#define CHAR_q 'q' -#define CHAR_r 'r' -#define CHAR_s 's' -#define CHAR_t 't' -#define CHAR_u 'u' -#define CHAR_v 'v' -#define CHAR_w 'w' -#define CHAR_x 'x' -#define CHAR_y 'y' -#define CHAR_z 'z' -#define CHAR_LEFT_CURLY_BRACKET '{' -#define CHAR_VERTICAL_LINE '|' -#define CHAR_RIGHT_CURLY_BRACKET '}' -#define CHAR_TILDE '~' - -#define STR_HT "\t" -#define STR_VT "\v" -#define STR_FF "\f" -#define STR_CR "\r" -#define STR_BS "\b" -#define STR_BEL "\a" - -#define STR_SPACE " " -#define STR_EXCLAMATION_MARK "!" -#define STR_QUOTATION_MARK "\"" -#define STR_NUMBER_SIGN "#" -#define STR_DOLLAR_SIGN "$" -#define STR_PERCENT_SIGN "%" -#define STR_AMPERSAND "&" -#define STR_APOSTROPHE "'" -#define STR_LEFT_PARENTHESIS "(" -#define STR_RIGHT_PARENTHESIS ")" -#define STR_ASTERISK "*" -#define STR_PLUS "+" -#define STR_COMMA "," -#define STR_MINUS "-" -#define STR_DOT "." -#define STR_SLASH "/" -#define STR_0 "0" -#define STR_1 "1" -#define STR_2 "2" -#define STR_3 "3" -#define STR_4 "4" -#define STR_5 "5" -#define STR_6 "6" -#define STR_7 "7" -#define STR_8 "8" -#define STR_9 "9" -#define STR_COLON ":" -#define STR_SEMICOLON ";" -#define STR_LESS_THAN_SIGN "<" -#define STR_EQUALS_SIGN "=" -#define STR_GREATER_THAN_SIGN ">" -#define STR_QUESTION_MARK "?" -#define STR_COMMERCIAL_AT "@" -#define STR_A "A" -#define STR_B "B" -#define STR_C "C" -#define STR_D "D" -#define STR_E "E" -#define STR_F "F" -#define STR_G "G" -#define STR_H "H" -#define STR_I "I" -#define STR_J "J" -#define STR_K "K" -#define STR_L "L" -#define STR_M "M" -#define STR_N "N" -#define STR_O "O" -#define STR_P "P" -#define STR_Q "Q" -#define STR_R "R" -#define STR_S "S" -#define STR_T "T" -#define STR_U "U" -#define STR_V "V" -#define STR_W "W" -#define STR_X "X" -#define STR_Y "Y" -#define STR_Z "Z" -#define STR_LEFT_SQUARE_BRACKET "[" -#define STR_BACKSLASH "\\" -#define STR_RIGHT_SQUARE_BRACKET "]" -#define STR_CIRCUMFLEX_ACCENT "^" -#define STR_UNDERSCORE "_" -#define STR_GRAVE_ACCENT "`" -#define STR_a "a" -#define STR_b "b" -#define STR_c "c" -#define STR_d "d" -#define STR_e "e" -#define STR_f "f" -#define STR_g "g" -#define STR_h "h" -#define STR_i "i" -#define STR_j "j" -#define STR_k "k" -#define STR_l "l" -#define STR_m "m" -#define STR_n "n" -#define STR_o "o" -#define STR_p "p" -#define STR_q "q" -#define STR_r "r" -#define STR_s "s" -#define STR_t "t" -#define STR_u "u" -#define STR_v "v" -#define STR_w "w" -#define STR_x "x" -#define STR_y "y" -#define STR_z "z" -#define STR_LEFT_CURLY_BRACKET "{" -#define STR_VERTICAL_LINE "|" -#define STR_RIGHT_CURLY_BRACKET "}" -#define STR_TILDE "~" - -#endif /* EBCDIC_WITH_ASCII_COMPILER */ - -#else /* SUPPORT_UNICODE */ - -/* UTF-8 support is enabled; always use UTF-8 (=ASCII) character codes. This -works in both modes non-EBCDIC platforms, and on EBCDIC platforms in UTF-8 mode -only. */ - -#define CHAR_HT '\011' -#define CHAR_VT '\013' -#define CHAR_FF '\014' -#define CHAR_CR '\015' -#define CHAR_LF '\012' -#define CHAR_NL CHAR_LF -#define CHAR_NEL ((unsigned char)'\x85') -#define CHAR_BS '\010' -#define CHAR_BEL '\007' -#define CHAR_ESC '\033' -#define CHAR_DEL '\177' - -#define CHAR_NUL '\0' -#define CHAR_SPACE '\040' -#define CHAR_EXCLAMATION_MARK '\041' -#define CHAR_QUOTATION_MARK '\042' -#define CHAR_NUMBER_SIGN '\043' -#define CHAR_DOLLAR_SIGN '\044' -#define CHAR_PERCENT_SIGN '\045' -#define CHAR_AMPERSAND '\046' -#define CHAR_APOSTROPHE '\047' -#define CHAR_LEFT_PARENTHESIS '\050' -#define CHAR_RIGHT_PARENTHESIS '\051' -#define CHAR_ASTERISK '\052' -#define CHAR_PLUS '\053' -#define CHAR_COMMA '\054' -#define CHAR_MINUS '\055' -#define CHAR_DOT '\056' -#define CHAR_SLASH '\057' -#define CHAR_0 '\060' -#define CHAR_1 '\061' -#define CHAR_2 '\062' -#define CHAR_3 '\063' -#define CHAR_4 '\064' -#define CHAR_5 '\065' -#define CHAR_6 '\066' -#define CHAR_7 '\067' -#define CHAR_8 '\070' -#define CHAR_9 '\071' -#define CHAR_COLON '\072' -#define CHAR_SEMICOLON '\073' -#define CHAR_LESS_THAN_SIGN '\074' -#define CHAR_EQUALS_SIGN '\075' -#define CHAR_GREATER_THAN_SIGN '\076' -#define CHAR_QUESTION_MARK '\077' -#define CHAR_COMMERCIAL_AT '\100' -#define CHAR_A '\101' -#define CHAR_B '\102' -#define CHAR_C '\103' -#define CHAR_D '\104' -#define CHAR_E '\105' -#define CHAR_F '\106' -#define CHAR_G '\107' -#define CHAR_H '\110' -#define CHAR_I '\111' -#define CHAR_J '\112' -#define CHAR_K '\113' -#define CHAR_L '\114' -#define CHAR_M '\115' -#define CHAR_N '\116' -#define CHAR_O '\117' -#define CHAR_P '\120' -#define CHAR_Q '\121' -#define CHAR_R '\122' -#define CHAR_S '\123' -#define CHAR_T '\124' -#define CHAR_U '\125' -#define CHAR_V '\126' -#define CHAR_W '\127' -#define CHAR_X '\130' -#define CHAR_Y '\131' -#define CHAR_Z '\132' -#define CHAR_LEFT_SQUARE_BRACKET '\133' -#define CHAR_BACKSLASH '\134' -#define CHAR_RIGHT_SQUARE_BRACKET '\135' -#define CHAR_CIRCUMFLEX_ACCENT '\136' -#define CHAR_UNDERSCORE '\137' -#define CHAR_GRAVE_ACCENT '\140' -#define CHAR_a '\141' -#define CHAR_b '\142' -#define CHAR_c '\143' -#define CHAR_d '\144' -#define CHAR_e '\145' -#define CHAR_f '\146' -#define CHAR_g '\147' -#define CHAR_h '\150' -#define CHAR_i '\151' -#define CHAR_j '\152' -#define CHAR_k '\153' -#define CHAR_l '\154' -#define CHAR_m '\155' -#define CHAR_n '\156' -#define CHAR_o '\157' -#define CHAR_p '\160' -#define CHAR_q '\161' -#define CHAR_r '\162' -#define CHAR_s '\163' -#define CHAR_t '\164' -#define CHAR_u '\165' -#define CHAR_v '\166' -#define CHAR_w '\167' -#define CHAR_x '\170' -#define CHAR_y '\171' -#define CHAR_z '\172' -#define CHAR_LEFT_CURLY_BRACKET '\173' -#define CHAR_VERTICAL_LINE '\174' -#define CHAR_RIGHT_CURLY_BRACKET '\175' -#define CHAR_TILDE '\176' -#define CHAR_NBSP ((unsigned char)'\xa0') - -#define STR_HT "\011" -#define STR_VT "\013" -#define STR_FF "\014" -#define STR_CR "\015" -#define STR_NL "\012" -#define STR_BS "\010" -#define STR_BEL "\007" -#define STR_ESC "\033" -#define STR_DEL "\177" - -#define STR_SPACE "\040" -#define STR_EXCLAMATION_MARK "\041" -#define STR_QUOTATION_MARK "\042" -#define STR_NUMBER_SIGN "\043" -#define STR_DOLLAR_SIGN "\044" -#define STR_PERCENT_SIGN "\045" -#define STR_AMPERSAND "\046" -#define STR_APOSTROPHE "\047" -#define STR_LEFT_PARENTHESIS "\050" -#define STR_RIGHT_PARENTHESIS "\051" -#define STR_ASTERISK "\052" -#define STR_PLUS "\053" -#define STR_COMMA "\054" -#define STR_MINUS "\055" -#define STR_DOT "\056" -#define STR_SLASH "\057" -#define STR_0 "\060" -#define STR_1 "\061" -#define STR_2 "\062" -#define STR_3 "\063" -#define STR_4 "\064" -#define STR_5 "\065" -#define STR_6 "\066" -#define STR_7 "\067" -#define STR_8 "\070" -#define STR_9 "\071" -#define STR_COLON "\072" -#define STR_SEMICOLON "\073" -#define STR_LESS_THAN_SIGN "\074" -#define STR_EQUALS_SIGN "\075" -#define STR_GREATER_THAN_SIGN "\076" -#define STR_QUESTION_MARK "\077" -#define STR_COMMERCIAL_AT "\100" -#define STR_A "\101" -#define STR_B "\102" -#define STR_C "\103" -#define STR_D "\104" -#define STR_E "\105" -#define STR_F "\106" -#define STR_G "\107" -#define STR_H "\110" -#define STR_I "\111" -#define STR_J "\112" -#define STR_K "\113" -#define STR_L "\114" -#define STR_M "\115" -#define STR_N "\116" -#define STR_O "\117" -#define STR_P "\120" -#define STR_Q "\121" -#define STR_R "\122" -#define STR_S "\123" -#define STR_T "\124" -#define STR_U "\125" -#define STR_V "\126" -#define STR_W "\127" -#define STR_X "\130" -#define STR_Y "\131" -#define STR_Z "\132" -#define STR_LEFT_SQUARE_BRACKET "\133" -#define STR_BACKSLASH "\134" -#define STR_RIGHT_SQUARE_BRACKET "\135" -#define STR_CIRCUMFLEX_ACCENT "\136" -#define STR_UNDERSCORE "\137" -#define STR_GRAVE_ACCENT "\140" -#define STR_a "\141" -#define STR_b "\142" -#define STR_c "\143" -#define STR_d "\144" -#define STR_e "\145" -#define STR_f "\146" -#define STR_g "\147" -#define STR_h "\150" -#define STR_i "\151" -#define STR_j "\152" -#define STR_k "\153" -#define STR_l "\154" -#define STR_m "\155" -#define STR_n "\156" -#define STR_o "\157" -#define STR_p "\160" -#define STR_q "\161" -#define STR_r "\162" -#define STR_s "\163" -#define STR_t "\164" -#define STR_u "\165" -#define STR_v "\166" -#define STR_w "\167" -#define STR_x "\170" -#define STR_y "\171" -#define STR_z "\172" -#define STR_LEFT_CURLY_BRACKET "\173" -#define STR_VERTICAL_LINE "\174" -#define STR_RIGHT_CURLY_BRACKET "\175" -#define STR_TILDE "\176" - -#endif /* SUPPORT_UNICODE */ - - -#define STRING_ACCEPT0 STR_A STR_C STR_C STR_E STR_P STR_T "\0" -#define STRING_COMMIT0 STR_C STR_O STR_M STR_M STR_I STR_T "\0" -#define STRING_F0 STR_F "\0" -#define STRING_FAIL0 STR_F STR_A STR_I STR_L "\0" -#define STRING_MARK0 STR_M STR_A STR_R STR_K "\0" -#define STRING_PRUNE0 STR_P STR_R STR_U STR_N STR_E "\0" -#define STRING_SKIP0 STR_S STR_K STR_I STR_P "\0" -#define STRING_THEN STR_T STR_H STR_E STR_N - -#define STRING_atomic0 STR_a STR_t STR_o STR_m STR_i STR_c "\0" -#define STRING_pla0 STR_p STR_l STR_a "\0" -#define STRING_plb0 STR_p STR_l STR_b "\0" -#define STRING_napla0 STR_n STR_a STR_p STR_l STR_a "\0" -#define STRING_naplb0 STR_n STR_a STR_p STR_l STR_b "\0" -#define STRING_nla0 STR_n STR_l STR_a "\0" -#define STRING_nlb0 STR_n STR_l STR_b "\0" -#define STRING_scs0 STR_s STR_c STR_s "\0" -#define STRING_sr0 STR_s STR_r "\0" -#define STRING_asr0 STR_a STR_s STR_r "\0" -#define STRING_positive_lookahead0 STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_a STR_h STR_e STR_a STR_d "\0" -#define STRING_positive_lookbehind0 STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_b STR_e STR_h STR_i STR_n STR_d "\0" -#define STRING_non_atomic_positive_lookahead0 STR_n STR_o STR_n STR_UNDERSCORE STR_a STR_t STR_o STR_m STR_i STR_c STR_UNDERSCORE STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_a STR_h STR_e STR_a STR_d "\0" -#define STRING_non_atomic_positive_lookbehind0 STR_n STR_o STR_n STR_UNDERSCORE STR_a STR_t STR_o STR_m STR_i STR_c STR_UNDERSCORE STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_b STR_e STR_h STR_i STR_n STR_d "\0" -#define STRING_negative_lookahead0 STR_n STR_e STR_g STR_a STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_a STR_h STR_e STR_a STR_d "\0" -#define STRING_negative_lookbehind0 STR_n STR_e STR_g STR_a STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_b STR_e STR_h STR_i STR_n STR_d "\0" -#define STRING_script_run0 STR_s STR_c STR_r STR_i STR_p STR_t STR_UNDERSCORE STR_r STR_u STR_n "\0" -#define STRING_atomic_script_run STR_a STR_t STR_o STR_m STR_i STR_c STR_UNDERSCORE STR_s STR_c STR_r STR_i STR_p STR_t STR_UNDERSCORE STR_r STR_u STR_n -#define STRING_scan_substring0 STR_s STR_c STR_a STR_n STR_UNDERSCORE STR_s STR_u STR_b STR_s STR_t STR_r STR_i STR_n STR_g "\0" - -#define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0" -#define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0" -#define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0" -#define STRING_alnum0 STR_a STR_l STR_n STR_u STR_m "\0" -#define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0" -#define STRING_blank0 STR_b STR_l STR_a STR_n STR_k "\0" -#define STRING_cntrl0 STR_c STR_n STR_t STR_r STR_l "\0" -#define STRING_digit0 STR_d STR_i STR_g STR_i STR_t "\0" -#define STRING_graph0 STR_g STR_r STR_a STR_p STR_h "\0" -#define STRING_print0 STR_p STR_r STR_i STR_n STR_t "\0" -#define STRING_punct0 STR_p STR_u STR_n STR_c STR_t "\0" -#define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0" -#define STRING_word0 STR_w STR_o STR_r STR_d "\0" -#define STRING_xdigit STR_x STR_d STR_i STR_g STR_i STR_t - -#define STRING_DEFINE STR_D STR_E STR_F STR_I STR_N STR_E -#define STRING_VERSION STR_V STR_E STR_R STR_S STR_I STR_O STR_N -#define STRING_WEIRD_STARTWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_LESS_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET -#define STRING_WEIRD_ENDWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_GREATER_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET - -#define STRING_CR_RIGHTPAR STR_C STR_R STR_RIGHT_PARENTHESIS -#define STRING_LF_RIGHTPAR STR_L STR_F STR_RIGHT_PARENTHESIS -#define STRING_CRLF_RIGHTPAR STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS -#define STRING_ANY_RIGHTPAR STR_A STR_N STR_Y STR_RIGHT_PARENTHESIS -#define STRING_ANYCRLF_RIGHTPAR STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS -#define STRING_NUL_RIGHTPAR STR_N STR_U STR_L STR_RIGHT_PARENTHESIS -#define STRING_BSR_ANYCRLF_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS -#define STRING_BSR_UNICODE_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_U STR_N STR_I STR_C STR_O STR_D STR_E STR_RIGHT_PARENTHESIS -#define STRING_UTF8_RIGHTPAR STR_U STR_T STR_F STR_8 STR_RIGHT_PARENTHESIS -#define STRING_UTF16_RIGHTPAR STR_U STR_T STR_F STR_1 STR_6 STR_RIGHT_PARENTHESIS -#define STRING_UTF32_RIGHTPAR STR_U STR_T STR_F STR_3 STR_2 STR_RIGHT_PARENTHESIS -#define STRING_UTF_RIGHTPAR STR_U STR_T STR_F STR_RIGHT_PARENTHESIS -#define STRING_UCP_RIGHTPAR STR_U STR_C STR_P STR_RIGHT_PARENTHESIS -#define STRING_NO_AUTO_POSSESS_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_A STR_U STR_T STR_O STR_UNDERSCORE STR_P STR_O STR_S STR_S STR_E STR_S STR_S STR_RIGHT_PARENTHESIS -#define STRING_NO_DOTSTAR_ANCHOR_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_D STR_O STR_T STR_S STR_T STR_A STR_R STR_UNDERSCORE STR_A STR_N STR_C STR_H STR_O STR_R STR_RIGHT_PARENTHESIS -#define STRING_NO_JIT_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_J STR_I STR_T STR_RIGHT_PARENTHESIS -#define STRING_NO_START_OPT_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_S STR_T STR_A STR_R STR_T STR_UNDERSCORE STR_O STR_P STR_T STR_RIGHT_PARENTHESIS -#define STRING_NOTEMPTY_RIGHTPAR STR_N STR_O STR_T STR_E STR_M STR_P STR_T STR_Y STR_RIGHT_PARENTHESIS -#define STRING_NOTEMPTY_ATSTART_RIGHTPAR STR_N STR_O STR_T STR_E STR_M STR_P STR_T STR_Y STR_UNDERSCORE STR_A STR_T STR_S STR_T STR_A STR_R STR_T STR_RIGHT_PARENTHESIS -#define STRING_CASELESS_RESTRICT_RIGHTPAR STR_C STR_A STR_S STR_E STR_L STR_E STR_S STR_S STR_UNDERSCORE STR_R STR_E STR_S STR_T STR_R STR_I STR_C STR_T STR_RIGHT_PARENTHESIS -#define STRING_TURKISH_CASING_RIGHTPAR STR_T STR_U STR_R STR_K STR_I STR_S STR_H STR_UNDERSCORE STR_C STR_A STR_S STR_I STR_N STR_G STR_RIGHT_PARENTHESIS -#define STRING_LIMIT_HEAP_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_H STR_E STR_A STR_P STR_EQUALS_SIGN -#define STRING_LIMIT_MATCH_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_M STR_A STR_T STR_C STR_H STR_EQUALS_SIGN -#define STRING_LIMIT_DEPTH_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_D STR_E STR_P STR_T STR_H STR_EQUALS_SIGN -#define STRING_LIMIT_RECURSION_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_R STR_E STR_C STR_U STR_R STR_S STR_I STR_O STR_N STR_EQUALS_SIGN -#define STRING_MARK STR_M STR_A STR_R STR_K - -#define STRING_bc STR_b STR_c -#define STRING_bidiclass STR_b STR_i STR_d STR_i STR_c STR_l STR_a STR_s STR_s -#define STRING_sc STR_s STR_c -#define STRING_script STR_s STR_c STR_r STR_i STR_p STR_t -#define STRING_scriptextensions STR_s STR_c STR_r STR_i STR_p STR_t STR_e STR_x STR_t STR_e STR_n STR_s STR_i STR_o STR_n STR_s -#define STRING_scx STR_s STR_c STR_x - - -/* -------------------- End of character and string names -------------------*/ - -/* -------------------- Definitions for compiled patterns -------------------*/ - -/* Codes for different types of Unicode property. If these definitions are -changed, the autopossessifying table in pcre2_auto_possess.c must be updated to -match. */ - -#define PT_LAMP 0 /* L& - the union of Lu, Ll, Lt */ -#define PT_GC 1 /* Specified general characteristic (e.g. L) */ -#define PT_PC 2 /* Specified particular characteristic (e.g. Lu) */ -#define PT_SC 3 /* Script only (e.g. Han) */ -#define PT_SCX 4 /* Script extensions (includes SC) */ -#define PT_ALNUM 5 /* Alphanumeric - the union of L and N */ -#define PT_SPACE 6 /* Perl space - general category Z plus 9,10,12,13 */ -#define PT_PXSPACE 7 /* POSIX space - Z plus 9,10,11,12,13 */ -#define PT_WORD 8 /* Word - L, N, Mn, or Pc */ -#define PT_CLIST 9 /* Pseudo-property: match character list */ -#define PT_UCNC 10 /* Universal Character nameable character */ -#define PT_BIDICL 11 /* Specified bidi class */ -#define PT_BOOL 12 /* Boolean property */ -#define PT_ANY 13 /* Must be the last entry! - Any property - matches all chars */ -#define PT_TABSIZE PT_ANY /* Size of square table for autopossessify tests */ - -/* The following special properties are used only in XCLASS items, when POSIX -classes are specified and PCRE2_UCP is set - in other words, for Unicode -handling of these classes. They are not available via the \p or \P escapes like -those in the above list, and so they do not take part in the autopossessifying -table. */ - -#define PT_PXGRAPH 14 /* [:graph:] - characters that mark the paper */ -#define PT_PXPRINT 15 /* [:print:] - [:graph:] plus non-control spaces */ -#define PT_PXPUNCT 16 /* [:punct:] - punctuation characters */ -#define PT_PXXDIGIT 17 /* [:xdigit:] - hex digits */ - -/* This value is used when parsing \p and \P escapes to indicate that neither -\p{script:...} nor \p{scx:...} has been encountered. */ - -#define PT_NOTSCRIPT 255 - -/* Flag bits and data types for the extended class (OP_XCLASS) for classes that -contain characters with values greater than 255. */ - -#define XCL_NOT 0x01 /* Flag: this is a negative class */ -#define XCL_MAP 0x02 /* Flag: a 32-byte map is present */ -#define XCL_HASPROP 0x04 /* Flag: property checks are present. */ - -#define XCL_END 0 /* Marks end of individual items */ -#define XCL_SINGLE 1 /* Single item (one multibyte char) follows */ -#define XCL_RANGE 2 /* A range (two multibyte chars) follows */ -#define XCL_PROP 3 /* Unicode property (2-byte property code follows) */ -#define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */ -/* This value represents the beginning of character lists. The value -is 16 bit long, and stored as a high and low byte pair in 8 bit mode. -The lower 12 bit contains information about character lists (see later). */ -#define XCL_LIST (sizeof(PCRE2_UCHAR) == 1 ? 0x10 : 0x1000) - -/* When a character class contains many characters/ranges, -they are stored in character lists. There are four character -lists which contain characters/ranges within a given range. - -The name, character range and item size for each list: -Low16 [0x100 - 0x7fff] 16 bit items -High16 [0x8000 - 0xffff] 16 bit items -Low32 [0x10000 - 0x7fffffff] 32 bit items -High32 [0x80000000 - 0xffffffff] 32 bit items - -The Low32 character list is used only when utf encoding or 32 bit -character width is enabled, and the High32 character is used only -when 32 bit character width is enabled. - -Each character list contain items. The lowest bit represents that -an item is the beginning of a range (bit is cleared), or not (bit -is set). The other bits represent the character shifted left by -one, so its highest bit is discarded. Due to the layout of character -lists, the highest bit of a character is always known: - -Low16 and Low32: the highest bit is always zero -High16 and High32: the highest bit is always one - -The items are ordered in increasing order, so binary search can be -used to find the lower bound of an input character. The lower bound -is the highest item, which value is less or equal than the input -character. If the lower bit of the item is cleard, or the character -stored in the item equals to the input character, the input -character is in the character list. */ - -/* Character list constants. */ -#define XCL_CHAR_LIST_LOW_16_START 0x100 -#define XCL_CHAR_LIST_LOW_16_END 0x7fff -#define XCL_CHAR_LIST_LOW_16_ADD 0x0 - -#define XCL_CHAR_LIST_HIGH_16_START 0x8000 -#define XCL_CHAR_LIST_HIGH_16_END 0xffff -#define XCL_CHAR_LIST_HIGH_16_ADD 0x8000 - -#define XCL_CHAR_LIST_LOW_32_START 0x10000 -#define XCL_CHAR_LIST_LOW_32_END 0x7fffffff -#define XCL_CHAR_LIST_LOW_32_ADD 0x0 - -#define XCL_CHAR_LIST_HIGH_32_START 0x80000000 -#define XCL_CHAR_LIST_HIGH_32_END 0xffffffff -#define XCL_CHAR_LIST_HIGH_32_ADD 0x80000000 - -/* Mask for getting the descriptors of character list ranges. -Each descriptor has XCL_TYPE_BIT_LEN bits, and can be processed -by XCL_BEGIN_WITH_RANGE and XCL_ITEM_COUNT_MASK macros. */ -#define XCL_TYPE_MASK 0xfff -#define XCL_TYPE_BIT_LEN 3 -/* If this bit is set, the first item of the character list is the -end of a range, which started before the starting character of the -character list. */ -#define XCL_BEGIN_WITH_RANGE 0x4 -/* Number of items in the character list: 0, 1, or 2. The value 3 -represents that the item count is stored at the begining of the -character list. The item count has the same width as the items -in the character list (e.g. 16 bit for Low16 and High16 lists). */ -#define XCL_ITEM_COUNT_MASK 0x3 -/* Shift and flag for constructing character list items. The XCL_CHAR_END -is set, when the item is not the beginning of a range. The XCL_CHAR_SHIFT -can be used to encode / decode the character value stored in an item. */ -#define XCL_CHAR_END 0x1 -#define XCL_CHAR_SHIFT 1 - -/* Flag bits for an extended class (OP_ECLASS), which is used for complex -character matches such as [\p{Greek} && \p{Ll}]. */ - -#define ECL_MAP 0x01 /* Flag: a 32-byte map is present */ - -/* Type tags for the items stored in an extended class (OP_ECLASS). These items -follow the OP_ECLASS's flag char and bitmap, and represent a Reverse Polish -Notation list of operands and operators manipulating a stack of bits. */ - -#define ECL_AND 1 /* Pop two from the stack, AND, and push result. */ -#define ECL_OR 2 /* Pop two from the stack, OR, and push result. */ -#define ECL_XOR 3 /* Pop two from the stack, XOR, and push result. */ -#define ECL_NOT 4 /* Pop one from the stack, NOT, and push result. */ -#define ECL_XCLASS 5 /* XCLASS nested within ECLASS; match and push result. */ -#define ECL_ANY 6 /* Temporary, only used during compilation. */ -#define ECL_NONE 7 /* Temporary, only used during compilation. */ - -/* These are escaped items that aren't just an encoding of a particular data -value such as \n. They must have non-zero values, as check_escape() returns 0 -for a data character. In the escapes[] table in pcre2_compile.c their values -are negated in order to distinguish them from data values. - -They must appear here in the same order as in the opcode definitions below, up -to ESC_z. There's a dummy for OP_ALLANY because it corresponds to "." in DOTALL -mode rather than an escape sequence. It is also used for [^] in JavaScript -compatibility mode, and for \C in non-utf mode. In non-DOTALL mode, "." behaves -like \N. - -ESC_ub is a special return from check_escape() when, in BSUX mode, \u{ is not -followed by hex digits and }, in which case it should mean a literal "u" -followed by a literal "{". This hack is necessary for cases like \u{ 12} -because without it, this is interpreted as u{12} now that spaces are allowed in -quantifiers. - -Negative numbers are used to encode a backreference (\1, \2, \3, etc.) in -check_escape(). There are tests in the code for an escape greater than ESC_b -and less than ESC_Z to detect the types that may be repeated. These are the -types that consume characters. If any new escapes are put in between that don't -consume a character, that code will have to change. */ - -enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, - ESC_W, ESC_w, ESC_N, ESC_dum, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H, - ESC_h, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z, - ESC_E, ESC_Q, ESC_g, ESC_k, ESC_ub }; - - -/********************** Opcode definitions ******************/ - -/****** NOTE NOTE NOTE ****** - -Starting from 1 (i.e. after OP_END), the values up to OP_EOD must correspond in -order to the list of escapes immediately above. Furthermore, values up to -OP_DOLLM must not be changed without adjusting the table called autoposstab in -pcre2_auto_possess.c. - -Whenever this list is updated, the two macro definitions that follow must be -updated to match. The possessification table called "opcode_possessify" in -pcre2_compile.c must also be updated, and also the tables called "coptable" -and "poptable" in pcre2_dfa_match.c. - -****** NOTE NOTE NOTE ******/ - - -/* The values between FIRST_AUTOTAB_OP and LAST_AUTOTAB_RIGHT_OP, inclusive, -are used in a table for deciding whether a repeated character type can be -auto-possessified. */ - -#define FIRST_AUTOTAB_OP OP_NOT_DIGIT -#define LAST_AUTOTAB_LEFT_OP OP_EXTUNI -#define LAST_AUTOTAB_RIGHT_OP OP_DOLLM - -enum { - OP_END, /* 0 End of pattern */ - - /* Values corresponding to backslashed metacharacters */ - - OP_SOD, /* 1 Start of data: \A */ - OP_SOM, /* 2 Start of match (subject + offset): \G */ - OP_SET_SOM, /* 3 Set start of match (\K) */ - OP_NOT_WORD_BOUNDARY, /* 4 \B -- see also OP_NOT_UCP_WORD_BOUNDARY */ - OP_WORD_BOUNDARY, /* 5 \b -- see also OP_UCP_WORD_BOUNDARY */ - OP_NOT_DIGIT, /* 6 \D */ - OP_DIGIT, /* 7 \d */ - OP_NOT_WHITESPACE, /* 8 \S */ - OP_WHITESPACE, /* 9 \s */ - OP_NOT_WORDCHAR, /* 10 \W */ - OP_WORDCHAR, /* 11 \w */ - - OP_ANY, /* 12 Match any character except newline (\N) */ - OP_ALLANY, /* 13 Match any character */ - OP_ANYBYTE, /* 14 Match any byte (\C); different to OP_ANY for UTF-8 */ - OP_NOTPROP, /* 15 \P (not Unicode property) */ - OP_PROP, /* 16 \p (Unicode property) */ - OP_ANYNL, /* 17 \R (any newline sequence) */ - OP_NOT_HSPACE, /* 18 \H (not horizontal whitespace) */ - OP_HSPACE, /* 19 \h (horizontal whitespace) */ - OP_NOT_VSPACE, /* 20 \V (not vertical whitespace) */ - OP_VSPACE, /* 21 \v (vertical whitespace) */ - OP_EXTUNI, /* 22 \X (extended Unicode sequence */ - OP_EODN, /* 23 End of data or \n at end of data (\Z) */ - OP_EOD, /* 24 End of data (\z) */ - - /* Line end assertions */ - - OP_DOLL, /* 25 End of line - not multiline */ - OP_DOLLM, /* 26 End of line - multiline */ - OP_CIRC, /* 27 Start of line - not multiline */ - OP_CIRCM, /* 28 Start of line - multiline */ - - /* Single characters; caseful must precede the caseless ones, and these - must remain in this order, and adjacent. */ - - OP_CHAR, /* 29 Match one character, casefully */ - OP_CHARI, /* 30 Match one character, caselessly */ - OP_NOT, /* 31 Match one character, not the given one, casefully */ - OP_NOTI, /* 32 Match one character, not the given one, caselessly */ - - /* The following sets of 13 opcodes must always be kept in step because - the offset from the first one is used to generate the others. */ - - /* Repeated characters; caseful must precede the caseless ones */ - - OP_STAR, /* 33 The maximizing and minimizing versions of */ - OP_MINSTAR, /* 34 these six opcodes must come in pairs, with */ - OP_PLUS, /* 35 the minimizing one second. */ - OP_MINPLUS, /* 36 */ - OP_QUERY, /* 37 */ - OP_MINQUERY, /* 38 */ - - OP_UPTO, /* 39 From 0 to n matches of one character, caseful*/ - OP_MINUPTO, /* 40 */ - OP_EXACT, /* 41 Exactly n matches */ - - OP_POSSTAR, /* 42 Possessified star, caseful */ - OP_POSPLUS, /* 43 Possessified plus, caseful */ - OP_POSQUERY, /* 44 Posesssified query, caseful */ - OP_POSUPTO, /* 45 Possessified upto, caseful */ - - /* Repeated characters; caseless must follow the caseful ones */ - - OP_STARI, /* 46 */ - OP_MINSTARI, /* 47 */ - OP_PLUSI, /* 48 */ - OP_MINPLUSI, /* 49 */ - OP_QUERYI, /* 50 */ - OP_MINQUERYI, /* 51 */ - - OP_UPTOI, /* 52 From 0 to n matches of one character, caseless */ - OP_MINUPTOI, /* 53 */ - OP_EXACTI, /* 54 */ - - OP_POSSTARI, /* 55 Possessified star, caseless */ - OP_POSPLUSI, /* 56 Possessified plus, caseless */ - OP_POSQUERYI, /* 57 Posesssified query, caseless */ - OP_POSUPTOI, /* 58 Possessified upto, caseless */ - - /* The negated ones must follow the non-negated ones, and match them */ - /* Negated repeated character, caseful; must precede the caseless ones */ - - OP_NOTSTAR, /* 59 The maximizing and minimizing versions of */ - OP_NOTMINSTAR, /* 60 these six opcodes must come in pairs, with */ - OP_NOTPLUS, /* 61 the minimizing one second. They must be in */ - OP_NOTMINPLUS, /* 62 exactly the same order as those above. */ - OP_NOTQUERY, /* 63 */ - OP_NOTMINQUERY, /* 64 */ - - OP_NOTUPTO, /* 65 From 0 to n matches, caseful */ - OP_NOTMINUPTO, /* 66 */ - OP_NOTEXACT, /* 67 Exactly n matches */ - - OP_NOTPOSSTAR, /* 68 Possessified versions, caseful */ - OP_NOTPOSPLUS, /* 69 */ - OP_NOTPOSQUERY, /* 70 */ - OP_NOTPOSUPTO, /* 71 */ - - /* Negated repeated character, caseless; must follow the caseful ones */ - - OP_NOTSTARI, /* 72 */ - OP_NOTMINSTARI, /* 73 */ - OP_NOTPLUSI, /* 74 */ - OP_NOTMINPLUSI, /* 75 */ - OP_NOTQUERYI, /* 76 */ - OP_NOTMINQUERYI, /* 77 */ - - OP_NOTUPTOI, /* 78 From 0 to n matches, caseless */ - OP_NOTMINUPTOI, /* 79 */ - OP_NOTEXACTI, /* 80 Exactly n matches */ - - OP_NOTPOSSTARI, /* 81 Possessified versions, caseless */ - OP_NOTPOSPLUSI, /* 82 */ - OP_NOTPOSQUERYI, /* 83 */ - OP_NOTPOSUPTOI, /* 84 */ - - /* Character types */ - - OP_TYPESTAR, /* 85 The maximizing and minimizing versions of */ - OP_TYPEMINSTAR, /* 86 these six opcodes must come in pairs, with */ - OP_TYPEPLUS, /* 87 the minimizing one second. These codes must */ - OP_TYPEMINPLUS, /* 88 be in exactly the same order as those above. */ - OP_TYPEQUERY, /* 89 */ - OP_TYPEMINQUERY, /* 90 */ - - OP_TYPEUPTO, /* 91 From 0 to n matches */ - OP_TYPEMINUPTO, /* 92 */ - OP_TYPEEXACT, /* 93 Exactly n matches */ - - OP_TYPEPOSSTAR, /* 94 Possessified versions */ - OP_TYPEPOSPLUS, /* 95 */ - OP_TYPEPOSQUERY, /* 96 */ - OP_TYPEPOSUPTO, /* 97 */ - - /* These are used for character classes and back references; only the - first six are the same as the sets above. */ - - OP_CRSTAR, /* 98 The maximizing and minimizing versions of */ - OP_CRMINSTAR, /* 99 all these opcodes must come in pairs, with */ - OP_CRPLUS, /* 100 the minimizing one second. These codes must */ - OP_CRMINPLUS, /* 101 be in exactly the same order as those above. */ - OP_CRQUERY, /* 102 */ - OP_CRMINQUERY, /* 103 */ - - OP_CRRANGE, /* 104 These are different to the three sets above. */ - OP_CRMINRANGE, /* 105 */ - - OP_CRPOSSTAR, /* 106 Possessified versions */ - OP_CRPOSPLUS, /* 107 */ - OP_CRPOSQUERY, /* 108 */ - OP_CRPOSRANGE, /* 109 */ - - /* End of quantifier opcodes */ - - OP_CLASS, /* 110 Match a character class, chars < 256 only */ - OP_NCLASS, /* 111 Same, but the bitmap was created from a negative - class - the difference is relevant only when a - character > 255 is encountered. */ - OP_XCLASS, /* 112 Extended class for handling > 255 chars within the - class. This does both positive and negative. */ - OP_ECLASS, /* 113 Really-extended class, for handling logical - expressions computed over characters. */ - OP_REF, /* 114 Match a back reference, casefully */ - OP_REFI, /* 115 Match a back reference, caselessly */ - OP_DNREF, /* 116 Match a duplicate name backref, casefully */ - OP_DNREFI, /* 117 Match a duplicate name backref, caselessly */ - OP_RECURSE, /* 118 Match a numbered subpattern (possibly recursive) */ - OP_CALLOUT, /* 119 Call out to external function if provided */ - OP_CALLOUT_STR, /* 120 Call out with string argument */ - - OP_ALT, /* 121 Start of alternation */ - OP_KET, /* 122 End of group that doesn't have an unbounded repeat */ - OP_KETRMAX, /* 123 These two must remain together and in this */ - OP_KETRMIN, /* 124 order. They are for groups the repeat for ever. */ - OP_KETRPOS, /* 125 Possessive unlimited repeat. */ - - /* The assertions must come before BRA, CBRA, ONCE, and COND. */ - - OP_REVERSE, /* 126 Move pointer back - used in lookbehind assertions */ - OP_VREVERSE, /* 127 Move pointer back - variable */ - OP_ASSERT, /* 128 Positive lookahead */ - OP_ASSERT_NOT, /* 129 Negative lookahead */ - OP_ASSERTBACK, /* 130 Positive lookbehind */ - OP_ASSERTBACK_NOT, /* 131 Negative lookbehind */ - OP_ASSERT_NA, /* 132 Positive non-atomic lookahead */ - OP_ASSERTBACK_NA, /* 133 Positive non-atomic lookbehind */ - OP_ASSERT_SCS, /* 134 Scan substring */ - - /* ONCE, SCRIPT_RUN, BRA, BRAPOS, CBRA, CBRAPOS, and COND must come - immediately after the assertions, with ONCE first, as there's a test for >= - ONCE for a subpattern that isn't an assertion. The POS versions must - immediately follow the non-POS versions in each case. */ - - OP_ONCE, /* 135 Atomic group, contains captures */ - OP_SCRIPT_RUN, /* 136 Non-capture, but check characters' scripts */ - OP_BRA, /* 137 Start of non-capturing bracket */ - OP_BRAPOS, /* 138 Ditto, with unlimited, possessive repeat */ - OP_CBRA, /* 139 Start of capturing bracket */ - OP_CBRAPOS, /* 140 Ditto, with unlimited, possessive repeat */ - OP_COND, /* 141 Conditional group */ - - /* These five must follow the previous five, in the same order. There's a - check for >= SBRA to distinguish the two sets. */ - - OP_SBRA, /* 142 Start of non-capturing bracket, check empty */ - OP_SBRAPOS, /* 143 Ditto, with unlimited, possessive repeat */ - OP_SCBRA, /* 144 Start of capturing bracket, check empty */ - OP_SCBRAPOS, /* 145 Ditto, with unlimited, possessive repeat */ - OP_SCOND, /* 146 Conditional group, check empty */ - - /* The next two pairs must (respectively) be kept together. */ - - OP_CREF, /* 147 Used to hold a capture number as condition */ - OP_DNCREF, /* 148 Used to point to duplicate names as a condition */ - OP_RREF, /* 149 Used to hold a recursion number as condition */ - OP_DNRREF, /* 150 Used to point to duplicate names as a condition */ - OP_FALSE, /* 151 Always false (used by DEFINE and VERSION) */ - OP_TRUE, /* 152 Always true (used by VERSION) */ - - OP_BRAZERO, /* 153 These two must remain together and in this */ - OP_BRAMINZERO, /* 154 order. */ - OP_BRAPOSZERO, /* 155 */ - - /* These are backtracking control verbs */ - - OP_MARK, /* 156 always has an argument */ - OP_PRUNE, /* 157 */ - OP_PRUNE_ARG, /* 158 same, but with argument */ - OP_SKIP, /* 159 */ - OP_SKIP_ARG, /* 160 same, but with argument */ - OP_THEN, /* 161 */ - OP_THEN_ARG, /* 162 same, but with argument */ - OP_COMMIT, /* 163 */ - OP_COMMIT_ARG, /* 164 same, but with argument */ - - /* These are forced failure and success verbs. FAIL and ACCEPT do accept an - argument, but these cases can be compiled as, for example, (*MARK:X)(*FAIL) - without the need for a special opcode. */ - - OP_FAIL, /* 165 */ - OP_ACCEPT, /* 166 */ - OP_ASSERT_ACCEPT, /* 167 Used inside assertions */ - OP_CLOSE, /* 168 Used before OP_ACCEPT to close open captures */ - - /* This is used to skip a subpattern with a {0} quantifier */ - - OP_SKIPZERO, /* 169 */ - - /* This is used to identify a DEFINE group during compilation so that it can - be checked for having only one branch. It is changed to OP_FALSE before - compilation finishes. */ - - OP_DEFINE, /* 170 */ - - /* These opcodes replace their normal counterparts in UCP mode when - PCRE2_EXTRA_ASCII_BSW is not set. */ - - OP_NOT_UCP_WORD_BOUNDARY, /* 171 */ - OP_UCP_WORD_BOUNDARY, /* 172 */ - - /* This is not an opcode, but is used to check that tables indexed by opcode - are the correct length, in order to catch updating errors - there have been - some in the past. */ - - OP_TABLE_LENGTH - -}; - -/* *** NOTE NOTE NOTE *** Whenever the list above is updated, the two macro -definitions that follow must also be updated to match. There are also tables -called "opcode_possessify" in pcre2_compile.c and "coptable" and "poptable" in -pcre2_dfa_match.c that must be updated. */ - - -/* This macro defines textual names for all the opcodes. These are used only -for debugging, and some of them are only partial names. The macro is referenced -only in pcre2_printint_inc.h, which fills out the full names in many cases (and in -some cases doesn't actually use these names at all). */ - -#define OP_NAME_LIST \ - "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d", \ - "\\S", "\\s", "\\W", "\\w", "Any", "AllAny", "Anybyte", \ - "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v", \ - "extuni", "\\Z", "\\z", \ - "$", "$", "^", "^", "char", "chari", "not", "noti", \ - "*", "*?", "+", "+?", "?", "??", \ - "{", "{", "{", \ - "*+","++", "?+", "{", \ - "*", "*?", "+", "+?", "?", "??", \ - "{", "{", "{", \ - "*+","++", "?+", "{", \ - "*", "*?", "+", "+?", "?", "??", \ - "{", "{", "{", \ - "*+","++", "?+", "{", \ - "*", "*?", "+", "+?", "?", "??", \ - "{", "{", "{", \ - "*+","++", "?+", "{", \ - "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \ - "*+","++", "?+", "{", \ - "*", "*?", "+", "+?", "?", "??", "{", "{", \ - "*+","++", "?+", "{", \ - "class", "nclass", "xclass", "eclass", \ - "Ref", "Refi", "DnRef", "DnRefi", \ - "Recurse", "Callout", "CalloutStr", \ - "Alt", "Ket", "KetRmax", "KetRmin", "KetRpos", \ - "Reverse", "VReverse", "Assert", "Assert not", \ - "Assert back", "Assert back not", \ - "Non-atomic assert", "Non-atomic assert back", \ - "Scan substring", \ - "Once", \ - "Script run", \ - "Bra", "BraPos", "CBra", "CBraPos", \ - "Cond", \ - "SBra", "SBraPos", "SCBra", "SCBraPos", \ - "SCond", \ - "Capture ref", "Capture dnref", "Cond rec", "Cond dnrec", \ - "Cond false", "Cond true", \ - "Brazero", "Braminzero", "Braposzero", \ - "*MARK", "*PRUNE", "*PRUNE", "*SKIP", "*SKIP", \ - "*THEN", "*THEN", "*COMMIT", "*COMMIT", "*FAIL", \ - "*ACCEPT", "*ASSERT_ACCEPT", \ - "Close", "Skip zero", "Define", "\\B (ucp)", "\\b (ucp)" - - -/* This macro defines the length of fixed length operations in the compiled -regex. The lengths are used when searching for specific things, and also in the -debugging printing of a compiled regex. We use a macro so that it can be -defined close to the definitions of the opcodes themselves. - -As things have been extended, some of these are no longer fixed lenths, but are -minima instead. For example, the length of a single-character repeat may vary -in UTF-8 mode. The code that uses this table must know about such things. */ - -#define OP_LENGTHS \ - 1, /* End */ \ - 1, 1, 1, 1, 1, /* \A, \G, \K, \B, \b */ \ - 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ \ - 1, 1, 1, /* Any, AllAny, Anybyte */ \ - 3, 3, /* \P, \p */ \ - 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ \ - 1, /* \X */ \ - 1, 1, 1, 1, 1, 1, /* \Z, \z, $, $M ^, ^M */ \ - 2, /* Char - the minimum length */ \ - 2, /* Chari - the minimum length */ \ - 2, /* not */ \ - 2, /* noti */ \ - /* Positive single-char repeats ** These are */ \ - 2, 2, 2, 2, 2, 2, /* *, *?, +, +?, ?, ?? ** minima in */ \ - 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto, minupto ** mode */ \ - 2+IMM2_SIZE, /* exact */ \ - 2, 2, 2, 2+IMM2_SIZE, /* *+, ++, ?+, upto+ */ \ - 2, 2, 2, 2, 2, 2, /* *I, *?I, +I, +?I, ?I, ??I ** UTF-8 */ \ - 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto I, minupto I */ \ - 2+IMM2_SIZE, /* exact I */ \ - 2, 2, 2, 2+IMM2_SIZE, /* *+I, ++I, ?+I, upto+I */ \ - /* Negative single-char repeats - only for chars < 256 */ \ - 2, 2, 2, 2, 2, 2, /* NOT *, *?, +, +?, ?, ?? */ \ - 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto, minupto */ \ - 2+IMM2_SIZE, /* NOT exact */ \ - 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *, +, ?, upto */ \ - 2, 2, 2, 2, 2, 2, /* NOT *I, *?I, +I, +?I, ?I, ??I */ \ - 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto I, minupto I */ \ - 2+IMM2_SIZE, /* NOT exact I */ \ - 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *I, +I, ?I, upto I */ \ - /* Positive type repeats */ \ - 2, 2, 2, 2, 2, 2, /* Type *, *?, +, +?, ?, ?? */ \ - 2+IMM2_SIZE, 2+IMM2_SIZE, /* Type upto, minupto */ \ - 2+IMM2_SIZE, /* Type exact */ \ - 2, 2, 2, 2+IMM2_SIZE, /* Possessive *+, ++, ?+, upto+ */ \ - /* Character class & ref repeats */ \ - 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ \ - 1+2*IMM2_SIZE, 1+2*IMM2_SIZE, /* CRRANGE, CRMINRANGE */ \ - 1, 1, 1, 1+2*IMM2_SIZE, /* Possessive *+, ++, ?+, CRPOSRANGE */ \ - 1+(32/sizeof(PCRE2_UCHAR)), /* CLASS */ \ - 1+(32/sizeof(PCRE2_UCHAR)), /* NCLASS */ \ - 0, /* XCLASS - variable length */ \ - 0, /* ECLASS - variable length */ \ - 1+IMM2_SIZE, /* REF */ \ - 1+IMM2_SIZE+1, /* REFI */ \ - 1+2*IMM2_SIZE, /* DNREF */ \ - 1+2*IMM2_SIZE+1, /* DNREFI */ \ - 1+LINK_SIZE, /* RECURSE */ \ - 1+2*LINK_SIZE+1, /* CALLOUT */ \ - 0, /* CALLOUT_STR - variable length */ \ - 1+LINK_SIZE, /* Alt */ \ - 1+LINK_SIZE, /* Ket */ \ - 1+LINK_SIZE, /* KetRmax */ \ - 1+LINK_SIZE, /* KetRmin */ \ - 1+LINK_SIZE, /* KetRpos */ \ - 1+IMM2_SIZE, /* Reverse */ \ - 1+2*IMM2_SIZE, /* VReverse */ \ - 1+LINK_SIZE, /* Assert */ \ - 1+LINK_SIZE, /* Assert not */ \ - 1+LINK_SIZE, /* Assert behind */ \ - 1+LINK_SIZE, /* Assert behind not */ \ - 1+LINK_SIZE, /* NA Assert */ \ - 1+LINK_SIZE, /* NA Assert behind */ \ - 1+LINK_SIZE, /* Scan substring */ \ - 1+LINK_SIZE, /* ONCE */ \ - 1+LINK_SIZE, /* SCRIPT_RUN */ \ - 1+LINK_SIZE, /* BRA */ \ - 1+LINK_SIZE, /* BRAPOS */ \ - 1+LINK_SIZE+IMM2_SIZE, /* CBRA */ \ - 1+LINK_SIZE+IMM2_SIZE, /* CBRAPOS */ \ - 1+LINK_SIZE, /* COND */ \ - 1+LINK_SIZE, /* SBRA */ \ - 1+LINK_SIZE, /* SBRAPOS */ \ - 1+LINK_SIZE+IMM2_SIZE, /* SCBRA */ \ - 1+LINK_SIZE+IMM2_SIZE, /* SCBRAPOS */ \ - 1+LINK_SIZE, /* SCOND */ \ - 1+IMM2_SIZE, 1+2*IMM2_SIZE, /* CREF, DNCREF */ \ - 1+IMM2_SIZE, 1+2*IMM2_SIZE, /* RREF, DNRREF */ \ - 1, 1, /* FALSE, TRUE */ \ - 1, 1, 1, /* BRAZERO, BRAMINZERO, BRAPOSZERO */ \ - 3, 1, 3, /* MARK, PRUNE, PRUNE_ARG */ \ - 1, 3, /* SKIP, SKIP_ARG */ \ - 1, 3, /* THEN, THEN_ARG */ \ - 1, 3, /* COMMIT, COMMIT_ARG */ \ - 1, 1, 1, /* FAIL, ACCEPT, ASSERT_ACCEPT */ \ - 1+IMM2_SIZE, 1, /* CLOSE, SKIPZERO */ \ - 1, /* DEFINE */ \ - 1, 1 /* \B and \b in UCP mode */ - -/* A magic value for OP_RREF to indicate the "any recursion" condition. */ - -#define RREF_ANY 0xffff - -/* Constants used by OP_REFI and OP_DNREFI to control matching behaviour. */ - -#define REFI_FLAG_CASELESS_RESTRICT 0x1 -#define REFI_FLAG_TURKISH_CASING 0x2 - - -/* ---------- Private structures that are mode-independent. ---------- */ - -/* Structure to hold data for custom memory management. */ - -typedef struct pcre2_memctl { - void * (*malloc)(size_t, void *); - void (*free)(void *, void *); - void *memory_data; -} pcre2_memctl; - -/* Structure for building a chain of open capturing subpatterns during -compiling, so that instructions to close them can be compiled when (*ACCEPT) is -encountered. */ - -typedef struct open_capitem { - struct open_capitem *next; /* Chain link */ - uint16_t number; /* Capture number */ - uint16_t assert_depth; /* Assertion depth when opened */ -} open_capitem; - -/* Layout of the UCP type table that translates property names into types and -codes. Each entry used to point directly to a name, but to reduce the number of -relocations in shared libraries, it now has an offset into a single string -instead. */ - -typedef struct { - uint16_t name_offset; - uint16_t type; - uint16_t value; -} ucp_type_table; - -/* Unicode character database (UCD) record format */ - -typedef struct { - uint8_t script; /* ucp_Arabic, etc. */ - uint8_t chartype; /* ucp_Cc, etc. (general categories) */ - uint8_t gbprop; /* ucp_gbControl, etc. (grapheme break property) */ - uint8_t caseset; /* offset to multichar other cases or zero */ - int32_t other_case; /* offset to other case, or zero if none */ - uint16_t scriptx_bidiclass; /* script extension (11 bit) and bidi class (5 bit) values */ - uint16_t bprops; /* binary properties offset */ -} ucd_record; - -/* UCD access macros */ - -#define UCD_BLOCK_SIZE 128 -#define REAL_GET_UCD(ch) (PRIV(ucd_records) + \ - PRIV(ucd_stage2)[PRIV(ucd_stage1)[(int)(ch) / UCD_BLOCK_SIZE] * \ - UCD_BLOCK_SIZE + (int)(ch) % UCD_BLOCK_SIZE]) - -#if PCRE2_CODE_UNIT_WIDTH == 32 -#define GET_UCD(ch) ((ch > MAX_UTF_CODE_POINT)? \ - PRIV(dummy_ucd_record) : REAL_GET_UCD(ch)) -#else -#define GET_UCD(ch) REAL_GET_UCD(ch) -#endif - -#define UCD_SCRIPTX_MASK 0x3ff -#define UCD_BIDICLASS_SHIFT 11 -#define UCD_BPROPS_MASK 0xfff - -#define UCD_SCRIPTX_PROP(prop) ((prop)->scriptx_bidiclass & UCD_SCRIPTX_MASK) -#define UCD_BIDICLASS_PROP(prop) ((prop)->scriptx_bidiclass >> UCD_BIDICLASS_SHIFT) -#define UCD_BPROPS_PROP(prop) ((prop)->bprops & UCD_BPROPS_MASK) - -#define UCD_CHARTYPE(ch) GET_UCD(ch)->chartype -#define UCD_SCRIPT(ch) GET_UCD(ch)->script -#define UCD_CATEGORY(ch) PRIV(ucp_gentype)[UCD_CHARTYPE(ch)] -#define UCD_GRAPHBREAK(ch) GET_UCD(ch)->gbprop -#define UCD_CASESET(ch) GET_UCD(ch)->caseset -#define UCD_OTHERCASE(ch) ((uint32_t)((int)ch + (int)(GET_UCD(ch)->other_case))) -#define UCD_SCRIPTX(ch) UCD_SCRIPTX_PROP(GET_UCD(ch)) -#define UCD_BPROPS(ch) UCD_BPROPS_PROP(GET_UCD(ch)) -#define UCD_BIDICLASS(ch) UCD_BIDICLASS_PROP(GET_UCD(ch)) -#define UCD_ANY_I(ch) \ - /* match any of the four characters 'i', 'I', U+0130, U+0131 */ \ - (((uint32_t)(ch) | 0x20u) == 0x69u || ((uint32_t)(ch) | 1u) == 0x0131u) -#define UCD_DOTTED_I(ch) \ - ((uint32_t)(ch) == 0x69u || (uint32_t)(ch) == 0x0130u) -#define UCD_FOLD_I_TURKISH(ch) \ - ((uint32_t)(ch) == 0x0130u ? 0x69u : \ - (uint32_t)(ch) == 0x49u ? 0x0131u : (uint32_t)(ch)) - -/* The "scriptx" and bprops fields contain offsets into vectors of 32-bit words -that form a bitmap representing a list of scripts or boolean properties. These -macros test or set a bit in the map by number. */ - -#define MAPBIT(map,n) ((map)[(n)/32]&(1u<<((n)%32))) -#define MAPSET(map,n) ((map)[(n)/32]|=(1u<<((n)%32))) - -/* Header for serialized pcre2 codes. */ - -typedef struct pcre2_serialized_data { - uint32_t magic; - uint32_t version; - uint32_t config; - int32_t number_of_codes; -} pcre2_serialized_data; - - - -/* ----------------- Items that need PCRE2_CODE_UNIT_WIDTH ----------------- */ - -/* When this file is included by pcre2test, PCRE2_CODE_UNIT_WIDTH is defined as -0, so the following items are omitted. */ - -#if defined PCRE2_CODE_UNIT_WIDTH && PCRE2_CODE_UNIT_WIDTH != 0 - -/* EBCDIC is supported only for the 8-bit library. */ - -#if defined EBCDIC && PCRE2_CODE_UNIT_WIDTH != 8 -#error EBCDIC is not supported for the 16-bit or 32-bit libraries -#endif - -/* This is the largest non-UTF code point. */ - -#define MAX_NON_UTF_CHAR (0xffffffffU >> (32 - PCRE2_CODE_UNIT_WIDTH)) - -/* Internal shared data tables and variables. These are used by more than one -of the exported public functions. They have to be "external" in the C sense, -but are not part of the PCRE2 public API. Although the data for some of them is -identical in all libraries, they must have different names so that multiple -libraries can be simultaneously linked to a single application. However, UTF-8 -tables are needed only when compiling the 8-bit library. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -extern const int PRIV(utf8_table1)[]; -extern const unsigned PRIV(utf8_table1_size); -extern const int PRIV(utf8_table2)[]; -extern const int PRIV(utf8_table3)[]; -extern const uint8_t PRIV(utf8_table4)[]; -#endif - -#define _pcre2_OP_lengths PCRE2_SUFFIX(_pcre2_OP_lengths_) -#define _pcre2_callout_end_delims PCRE2_SUFFIX(_pcre2_callout_end_delims_) -#define _pcre2_callout_start_delims PCRE2_SUFFIX(_pcre2_callout_start_delims_) -#define _pcre2_default_compile_context PCRE2_SUFFIX(_pcre2_default_compile_context_) -#define _pcre2_default_convert_context PCRE2_SUFFIX(_pcre2_default_convert_context_) -#define _pcre2_default_match_context PCRE2_SUFFIX(_pcre2_default_match_context_) -#define _pcre2_default_tables PCRE2_SUFFIX(_pcre2_default_tables_) -#if PCRE2_CODE_UNIT_WIDTH == 32 -#define _pcre2_dummy_ucd_record PCRE2_SUFFIX(_pcre2_dummy_ucd_record_) -#endif -#define _pcre2_hspace_list PCRE2_SUFFIX(_pcre2_hspace_list_) -#define _pcre2_vspace_list PCRE2_SUFFIX(_pcre2_vspace_list_) -#define _pcre2_ucd_boolprop_sets PCRE2_SUFFIX(_pcre2_ucd_boolprop_sets_) -#define _pcre2_ucd_caseless_sets PCRE2_SUFFIX(_pcre2_ucd_caseless_sets_) -#define _pcre2_ucd_turkish_dotted_i_caseset PCRE2_SUFFIX(_pcre2_ucd_turkish_dotted_i_caseset_) -#define _pcre2_ucd_nocase_ranges PCRE2_SUFFIX(_pcre2_ucd_nocase_ranges_) -#define _pcre2_ucd_nocase_ranges_size PCRE2_SUFFIX(_pcre2_ucd_nocase_ranges_size_) -#define _pcre2_ucd_digit_sets PCRE2_SUFFIX(_pcre2_ucd_digit_sets_) -#define _pcre2_ucd_script_sets PCRE2_SUFFIX(_pcre2_ucd_script_sets_) -#define _pcre2_ucd_records PCRE2_SUFFIX(_pcre2_ucd_records_) -#define _pcre2_ucd_stage1 PCRE2_SUFFIX(_pcre2_ucd_stage1_) -#define _pcre2_ucd_stage2 PCRE2_SUFFIX(_pcre2_ucd_stage2_) -#define _pcre2_ucp_gbtable PCRE2_SUFFIX(_pcre2_ucp_gbtable_) -#define _pcre2_ucp_gentype PCRE2_SUFFIX(_pcre2_ucp_gentype_) -#define _pcre2_ucp_typerange PCRE2_SUFFIX(_pcre2_ucp_typerange_) -#define _pcre2_unicode_version PCRE2_SUFFIX(_pcre2_unicode_version_) -#define _pcre2_utt PCRE2_SUFFIX(_pcre2_utt_) -#define _pcre2_utt_names PCRE2_SUFFIX(_pcre2_utt_names_) -#define _pcre2_utt_size PCRE2_SUFFIX(_pcre2_utt_size_) -#define _pcre2_ebcdic_1047_to_ascii PCRE2_SUFFIX(_pcre2_ebcdic_1047_to_ascii_) -#define _pcre2_ascii_to_ebcdic_1047 PCRE2_SUFFIX(_pcre2_ascii_to_ebcdic_1047_) - -extern const uint8_t PRIV(OP_lengths)[]; -extern const uint32_t PRIV(callout_end_delims)[]; -extern const uint32_t PRIV(callout_start_delims)[]; -extern pcre2_compile_context PRIV(default_compile_context); -extern pcre2_convert_context PRIV(default_convert_context); -extern pcre2_match_context PRIV(default_match_context); -extern const uint8_t PRIV(default_tables)[]; -extern const uint32_t PRIV(hspace_list)[]; -extern const uint32_t PRIV(vspace_list)[]; -extern const uint32_t PRIV(ucd_boolprop_sets)[]; -extern const uint32_t PRIV(ucd_caseless_sets)[]; -extern const uint32_t PRIV(ucd_turkish_dotted_i_caseset); -extern const uint32_t PRIV(ucd_nocase_ranges)[]; -extern const uint32_t PRIV(ucd_nocase_ranges_size); -extern const uint32_t PRIV(ucd_digit_sets)[]; -extern const uint32_t PRIV(ucd_script_sets)[]; -extern const ucd_record PRIV(ucd_records)[]; -#if PCRE2_CODE_UNIT_WIDTH == 32 -extern const ucd_record PRIV(dummy_ucd_record)[]; -#endif -extern const uint16_t PRIV(ucd_stage1)[]; -extern const uint16_t PRIV(ucd_stage2)[]; -extern const uint32_t PRIV(ucp_gbtable)[]; -extern const uint32_t PRIV(ucp_gentype)[]; -#ifdef SUPPORT_JIT -extern const int PRIV(ucp_typerange)[]; -#endif -extern const char *PRIV(unicode_version); -extern const ucp_type_table PRIV(utt)[]; -extern const char PRIV(utt_names)[]; -extern const size_t PRIV(utt_size); -extern const uint8_t PRIV(ebcdic_1047_to_ascii)[]; -extern const uint8_t PRIV(ascii_to_ebcdic_1047)[]; - -/* Mode-dependent macros and hidden and private structures are defined in a -separate file so that pcre2test can include them at all supported widths. When -compiling the library, PCRE2_CODE_UNIT_WIDTH will be defined, and we can -include them at the appropriate width, after setting up suffix macros for the -private structures. */ - -#define branch_chain PCRE2_SUFFIX(branch_chain_) -#define compile_block PCRE2_SUFFIX(compile_block_) -#define dfa_match_block PCRE2_SUFFIX(dfa_match_block_) -#define match_block PCRE2_SUFFIX(match_block_) -#define named_group PCRE2_SUFFIX(named_group_) - -#include "pcre2_intmodedep.h" - -/* Private "external" functions. These are internal functions that are called -from modules other than the one in which they are defined. They have to be -"external" in the C sense, but are not part of the PCRE2 public API. They are -not referenced from pcre2test, and must not be defined when no code unit width -is available. */ - -#define _pcre2_auto_possessify PCRE2_SUFFIX(_pcre2_auto_possessify_) -#define _pcre2_check_escape PCRE2_SUFFIX(_pcre2_check_escape_) -#define _pcre2_ckd_smul PCRE2_SUFFIX(_pcre2_ckd_smul_) -#define _pcre2_extuni PCRE2_SUFFIX(_pcre2_extuni_) -#define _pcre2_find_bracket PCRE2_SUFFIX(_pcre2_find_bracket_) -#define _pcre2_is_newline PCRE2_SUFFIX(_pcre2_is_newline_) -#define _pcre2_jit_free_rodata PCRE2_SUFFIX(_pcre2_jit_free_rodata_) -#define _pcre2_jit_free PCRE2_SUFFIX(_pcre2_jit_free_) -#define _pcre2_jit_get_size PCRE2_SUFFIX(_pcre2_jit_get_size_) -#define _pcre2_jit_get_target PCRE2_SUFFIX(_pcre2_jit_get_target_) -#define _pcre2_memctl_malloc PCRE2_SUFFIX(_pcre2_memctl_malloc_) -#define _pcre2_ord2utf PCRE2_SUFFIX(_pcre2_ord2utf_) -#define _pcre2_script_run PCRE2_SUFFIX(_pcre2_script_run_) -#define _pcre2_strcmp PCRE2_SUFFIX(_pcre2_strcmp_) -#define _pcre2_strcmp_c8 PCRE2_SUFFIX(_pcre2_strcmp_c8_) -#define _pcre2_strcpy_c8 PCRE2_SUFFIX(_pcre2_strcpy_c8_) -#define _pcre2_strlen PCRE2_SUFFIX(_pcre2_strlen_) -#define _pcre2_strncmp PCRE2_SUFFIX(_pcre2_strncmp_) -#define _pcre2_strncmp_c8 PCRE2_SUFFIX(_pcre2_strncmp_c8_) -#define _pcre2_study PCRE2_SUFFIX(_pcre2_study_) -#define _pcre2_valid_utf PCRE2_SUFFIX(_pcre2_valid_utf_) -#define _pcre2_was_newline PCRE2_SUFFIX(_pcre2_was_newline_) -#define _pcre2_xclass PCRE2_SUFFIX(_pcre2_xclass_) -#define _pcre2_eclass PCRE2_SUFFIX(_pcre2_eclass_) - -extern int _pcre2_auto_possessify(PCRE2_UCHAR *, - const compile_block *); -extern int _pcre2_check_escape(PCRE2_SPTR *, PCRE2_SPTR, uint32_t *, - int *, uint32_t, uint32_t, uint32_t, BOOL, compile_block *); -extern BOOL _pcre2_ckd_smul(PCRE2_SIZE *, int, int); -extern PCRE2_SPTR _pcre2_extuni(uint32_t, PCRE2_SPTR, PCRE2_SPTR, PCRE2_SPTR, - BOOL, int *); -extern PCRE2_SPTR _pcre2_find_bracket(PCRE2_SPTR, BOOL, int); -extern BOOL _pcre2_is_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR, - uint32_t *, BOOL); -extern void _pcre2_jit_free_rodata(void *, void *); -extern void _pcre2_jit_free(void *, pcre2_memctl *); -extern size_t _pcre2_jit_get_size(void *); -const char * _pcre2_jit_get_target(void); -extern void * _pcre2_memctl_malloc(size_t, pcre2_memctl *); -extern unsigned int _pcre2_ord2utf(uint32_t, PCRE2_UCHAR *); -extern BOOL _pcre2_script_run(PCRE2_SPTR, PCRE2_SPTR, BOOL); -extern int _pcre2_strcmp(PCRE2_SPTR, PCRE2_SPTR); -extern int _pcre2_strcmp_c8(PCRE2_SPTR, const char *); -extern PCRE2_SIZE _pcre2_strcpy_c8(PCRE2_UCHAR *, const char *); -extern PCRE2_SIZE _pcre2_strlen(PCRE2_SPTR); -extern int _pcre2_strncmp(PCRE2_SPTR, PCRE2_SPTR, size_t); -extern int _pcre2_strncmp_c8(PCRE2_SPTR, const char *, size_t); -extern int _pcre2_study(pcre2_real_code *); -extern int _pcre2_valid_utf(PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE *); -extern BOOL _pcre2_was_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR, - uint32_t *, BOOL); -extern BOOL _pcre2_xclass(uint32_t, PCRE2_SPTR, const uint8_t *, BOOL); -extern BOOL _pcre2_eclass(uint32_t, PCRE2_SPTR, PCRE2_SPTR, - const uint8_t *, BOOL); - -#endif /* PCRE2_CODE_UNIT_WIDTH */ - -#include "pcre2_util.h" - -#endif /* PCRE2_INTERNAL_H_IDEMPOTENT_GUARD */ - -/* End of pcre2_internal.h */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_intmodedep.h b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_intmodedep.h deleted file mode 100644 index 6cefb61..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_intmodedep.h +++ /dev/null @@ -1,1044 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains mode-dependent macro and structure definitions. The -file is #included by pcre2_internal.h if PCRE2_CODE_UNIT_WIDTH is defined. -These mode-dependent items are kept in a separate file so that they can also be -#included multiple times for different code unit widths by pcre2test in order -to have access to the hidden structures at all supported widths. - -Some of the mode-dependent macros are required at different widths for -different parts of the pcre2test code (in particular, the included -pcre2_printint_inc.h file). We undefine them here so that they can be re-defined -for multiple inclusions. Not all of these are used in pcre2test, but it's easier -just to undefine them all. - -You can also include pcre2_intmodedep.h with PCRE2_CODE_UNIT_WIDTH defined to -zero in order to simply clear the previous macros. */ - -#ifndef PCRE2_CODE_UNIT_WIDTH -#error PCRE2_CODE_UNIT_WIDTH must be defined -#endif - -#undef ACROSSCHAR -#undef BACKCHAR -#undef BYTES2CU -#undef CHMAX_255 -#undef CU2BYTES -#undef FORWARDCHAR -#undef FORWARDCHARTEST -#undef GET -#undef GET2 -#undef GETCHAR -#undef GETCHARINC -#undef GETCHARINCTEST -#undef GETCHARLEN -#undef GETCHARLENTEST -#undef GETCHARTEST -#undef GET_EXTRALEN -#undef HAS_EXTRALEN -#undef IMM2_SIZE -#undef MAX_255 -#undef MAX_MARK -#undef MAX_PATTERN_SIZE -#undef MAX_UTF_SINGLE_CU -#undef NOT_FIRSTCU -#undef PUT -#undef PUT2 -#undef PUT2INC -#undef PUTCHAR -#undef PUTINC -#undef TABLE_GET - -/************************************************* -* MACROS * -*************************************************/ - -/* Macros may be undefined and re-defined if the same file handles multiple -bit-widths. */ - -#if PCRE2_CODE_UNIT_WIDTH != 0 - -/* PCRE keeps offsets in its compiled code as at least 16-bit quantities -(always stored in big-endian order in 8-bit mode) by default. These are used, -for example, to link from the start of a subpattern to its alternatives and its -end. The use of 16 bits per offset limits the size of an 8-bit compiled regex -to around 64K, which is big enough for almost everybody. However, I received a -request for an even bigger limit. For this reason, and also to make the code -easier to maintain, the storing and loading of offsets from the compiled code -unit string is now handled by the macros that are defined here. - -The macros are controlled by the value of LINK_SIZE. This defaults to 2, but -values of 3 or 4 are also supported. */ - -#ifndef CONFIGURED_LINK_SIZE -#if LINK_SIZE == 2 -#define CONFIGURED_LINK_SIZE 2 -#elif LINK_SIZE == 3 -#define CONFIGURED_LINK_SIZE 3 -#elif LINK_SIZE == 4 -#define CONFIGURED_LINK_SIZE 4 -#else -#error LINK_SIZE must be 2, 3, or 4 -#endif -#endif /* CONFIGURED_LINK_SIZE */ - -/* ------------------- 8-bit support ------------------ */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 - -#if CONFIGURED_LINK_SIZE == 2 -#define PUT(a,n,d) \ - (a[n] = (PCRE2_UCHAR)((d) >> 8)), \ - (a[(n)+1] = (PCRE2_UCHAR)((d) & 255)) -#define GET(a,n) \ - (unsigned int)(((a)[n] << 8) | (a)[(n)+1]) -#define MAX_PATTERN_SIZE (1 << 16) - -#elif CONFIGURED_LINK_SIZE == 3 -#define PUT(a,n,d) \ - (a[n] = (PCRE2_UCHAR)((d) >> 16)), \ - (a[(n)+1] = (PCRE2_UCHAR)((d) >> 8)), \ - (a[(n)+2] = (PCRE2_UCHAR)((d) & 255)) -#define GET(a,n) \ - (unsigned int)(((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2]) -#define MAX_PATTERN_SIZE (1 << 24) - -#elif CONFIGURED_LINK_SIZE == 4 -#define PUT(a,n,d) \ - (a[n] = (PCRE2_UCHAR)((d) >> 24)), \ - (a[(n)+1] = (PCRE2_UCHAR)((d) >> 16)), \ - (a[(n)+2] = (PCRE2_UCHAR)((d) >> 8)), \ - (a[(n)+3] = (PCRE2_UCHAR)((d) & 255)) -#define GET(a,n) \ - (unsigned int)(((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3]) -#define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */ - -#endif - - -/* ------------------- 16-bit support ------------------ */ - -#elif PCRE2_CODE_UNIT_WIDTH == 16 - -#if CONFIGURED_LINK_SIZE == 2 -#undef LINK_SIZE -#define LINK_SIZE 1 -#define PUT(a,n,d) \ - (a[n] = (PCRE2_UCHAR)(d)) -#define GET(a,n) \ - (a[n]) -#define MAX_PATTERN_SIZE (1 << 16) - -#elif CONFIGURED_LINK_SIZE == 3 || CONFIGURED_LINK_SIZE == 4 -#undef LINK_SIZE -#define LINK_SIZE 2 -#define PUT(a,n,d) \ - (a[n] = (PCRE2_UCHAR)((d) >> 16)), \ - (a[(n)+1] = (PCRE2_UCHAR)((d) & 65535)) -#define GET(a,n) \ - (unsigned int)(((a)[n] << 16) | (a)[(n)+1]) -#define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */ - -#endif - - -/* ------------------- 32-bit support ------------------ */ - -#elif PCRE2_CODE_UNIT_WIDTH == 32 -#undef LINK_SIZE -#define LINK_SIZE 1 -#define PUT(a,n,d) \ - (a[n] = (d)) -#define GET(a,n) \ - (a[n]) -#define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */ - -#else -#error Unsupported compiling mode -#endif - - -/* --------------- Other mode-specific macros ----------------- */ - -/* PCRE uses some other (at least) 16-bit quantities that do not change when -the size of offsets changes. There are used for repeat counts and for other -things such as capturing parenthesis numbers in back references. - -Define the number of code units required to hold a 16-bit count/offset, and -macros to load and store such a value. For reasons that I do not understand, -the expression in the 8-bit GET2 macro is treated by gcc as a signed -expression, even when a is declared as unsigned. It seems that any kind of -arithmetic results in a signed value. Hence the cast. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -#define IMM2_SIZE 2 -#define GET2(a,n) (unsigned int)(((a)[n] << 8) | (a)[(n)+1]) -#define PUT2(a,n,d) a[n] = (d) >> 8, a[(n)+1] = (d) & 255 - -#elif PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -#define IMM2_SIZE 1 -#define GET2(a,n) a[n] -#define PUT2(a,n,d) a[n] = d -#endif - -/* Other macros that are different for 8-bit mode. The MAX_255 macro checks -whether its argument, which is assumed to be one code unit, is less than 256. -The CHMAX_255 macro does not assume one code unit. The maximum length of a MARK -name must fit in one code unit; currently it is set to 255 or 65535. The -TABLE_GET macro is used to access elements of tables containing exactly 256 -items. Its argument is a code unit. When code points can be greater than 255, a -check is needed before accessing these tables. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -#define MAX_255(c) TRUE -#define MAX_MARK ((1u << 8) - 1) -#define TABLE_GET(c, table, default) ((table)[c]) -#ifdef SUPPORT_UNICODE -#define SUPPORT_WIDE_CHARS -#define CHMAX_255(c) ((c) <= 255u) -#else -#define CHMAX_255(c) TRUE -#endif /* SUPPORT_UNICODE */ - -#elif PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -#define CHMAX_255(c) ((c) <= 255u) -#define MAX_255(c) ((c) <= 255u) -#define MAX_MARK ((1u << 16) - 1) -#define SUPPORT_WIDE_CHARS -#define TABLE_GET(c, table, default) (MAX_255(c)? ((table)[c]):(default)) -#endif - - -/* ----------------- Character-handling macros ----------------- */ - -/* There is a proposed future special "UTF-21" mode, in which only the lowest -21 bits of a 32-bit character are interpreted as UTF, with the remaining 11 -high-order bits available to the application for other uses. In preparation for -the future implementation of this mode, there are macros that load a data item -and, if in this special mode, mask it to 21 bits. These macros all have names -starting with UCHAR21. In all other modes, including the normal 32-bit -library, the macros all have the same simple definitions. When the new mode is -implemented, it is expected that these definitions will be varied appropriately -using #ifdef when compiling the library that supports the special mode. */ - -#define UCHAR21(eptr) (*(eptr)) -#define UCHAR21TEST(eptr) (*(eptr)) -#define UCHAR21INC(eptr) (*(eptr)++) -#define UCHAR21INCTEST(eptr) (*(eptr)++) - -/* When UTF encoding is being used, a character is no longer just a single -byte in 8-bit mode or a single short in 16-bit mode. The macros for character -handling generate simple sequences when used in the basic mode, and more -complicated ones for UTF characters. GETCHARLENTEST and other macros are not -used when UTF is not supported. To make sure they can never even appear when -UTF support is omitted, we don't even define them. */ - -#ifndef SUPPORT_UNICODE - -/* #define MAX_UTF_SINGLE_CU */ -/* #define HAS_EXTRALEN(c) */ -/* #define GET_EXTRALEN(c) */ -/* #define NOT_FIRSTCU(c) */ -#define GETCHAR(c, eptr) c = *eptr; -#define GETCHARTEST(c, eptr) c = *eptr; -#define GETCHARINC(c, eptr) c = *eptr++; -#define GETCHARINCTEST(c, eptr) c = *eptr++; -#define GETCHARLEN(c, eptr, len) c = *eptr; -#define PUTCHAR(c, p) (*p = c, 1) -/* #define GETCHARLENTEST(c, eptr, len) */ -/* #define BACKCHAR(eptr) */ -/* #define FORWARDCHAR(eptr) */ -/* #define FORWARCCHARTEST(eptr,end) */ -/* #define ACROSSCHAR(condition, eptr, action) */ - -#else /* SUPPORT_UNICODE */ - -/* ------------------- 8-bit support ------------------ */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -#define MAYBE_UTF_MULTI /* UTF chars may use multiple code units */ - -/* The largest UTF code point that can be encoded as a single code unit. */ - -#define MAX_UTF_SINGLE_CU 127 - -/* Tests whether the code point needs extra characters to decode. */ - -#define HAS_EXTRALEN(c) HASUTF8EXTRALEN(c) - -/* Returns with the additional number of characters if HAS_EXTRALEN(c) is TRUE. -Otherwise it has an undefined behaviour. */ - -#define GET_EXTRALEN(c) (PRIV(utf8_table4)[(c) & 0x3fu]) - -/* Returns TRUE, if the given value is not the first code unit of a UTF -sequence. */ - -#define NOT_FIRSTCU(c) (((c) & 0xc0u) == 0x80u) - -/* Get the next UTF-8 character, not advancing the pointer. This is called when -we know we are in UTF-8 mode. */ - -#define GETCHAR(c, eptr) \ - c = *eptr; \ - if (c >= 0xc0u) GETUTF8(c, eptr); - -/* Get the next UTF-8 character, testing for UTF-8 mode, and not advancing the -pointer. */ - -#define GETCHARTEST(c, eptr) \ - c = *eptr; \ - if (utf && c >= 0xc0u) GETUTF8(c, eptr); - -/* Get the next UTF-8 character, advancing the pointer. This is called when we -know we are in UTF-8 mode. */ - -#define GETCHARINC(c, eptr) \ - c = *eptr++; \ - if (c >= 0xc0u) GETUTF8INC(c, eptr); - -/* Get the next character, testing for UTF-8 mode, and advancing the pointer. -This is called when we don't know if we are in UTF-8 mode. */ - -#define GETCHARINCTEST(c, eptr) \ - c = *eptr++; \ - if (utf && c >= 0xc0u) GETUTF8INC(c, eptr); - -/* Get the next UTF-8 character, not advancing the pointer, incrementing length -if there are extra bytes. This is called when we know we are in UTF-8 mode. */ - -#define GETCHARLEN(c, eptr, len) \ - c = *eptr; \ - if (c >= 0xc0u) GETUTF8LEN(c, eptr, len); - -/* Get the next UTF-8 character, testing for UTF-8 mode, not advancing the -pointer, incrementing length if there are extra bytes. This is called when we -do not know if we are in UTF-8 mode. */ - -#define GETCHARLENTEST(c, eptr, len) \ - c = *eptr; \ - if (utf && c >= 0xc0u) GETUTF8LEN(c, eptr, len); - -/* If the pointer is not at the start of a character, move it back until -it is. This is called only in UTF-8 mode - we don't put a test within the macro -because almost all calls are already within a block of UTF-8 only code. */ - -#define BACKCHAR(eptr) while((*eptr & 0xc0u) == 0x80u) eptr-- - -/* Same as above, just in the other direction. */ -#define FORWARDCHAR(eptr) while((*eptr & 0xc0u) == 0x80u) eptr++ -#define FORWARDCHARTEST(eptr,end) while(eptr < end && (*eptr & 0xc0u) == 0x80u) eptr++ - -/* Same as above, but it allows a fully customizable form. */ -#define ACROSSCHAR(condition, eptr, action) \ - while((condition) && ((*eptr) & 0xc0u) == 0x80u) action - -/* Deposit a character into memory, returning the number of code units. */ - -#define PUTCHAR(c, p) ((utf && c > MAX_UTF_SINGLE_CU)? \ - PRIV(ord2utf)(c,p) : (*p = c, 1)) - - -/* ------------------- 16-bit support ------------------ */ - -#elif PCRE2_CODE_UNIT_WIDTH == 16 -#define MAYBE_UTF_MULTI /* UTF chars may use multiple code units */ - -/* The largest UTF code point that can be encoded as a single code unit. */ - -#define MAX_UTF_SINGLE_CU 65535 - -/* Tests whether the code point needs extra characters to decode. */ - -#define HAS_EXTRALEN(c) (((c) & 0xfc00u) == 0xd800u) - -/* Returns with the additional number of characters if HAS_EXTRALEN(c) is TRUE. -Otherwise it has an undefined behaviour. */ - -#define GET_EXTRALEN(c) 1 - -/* Returns TRUE, if the given value is not the first code unit of a UTF -sequence. */ - -#define NOT_FIRSTCU(c) (((c) & 0xfc00u) == 0xdc00u) - -/* Base macro to pick up the low surrogate of a UTF-16 character, not -advancing the pointer. */ - -#define GETUTF16(c, eptr) \ - { c = (((c & 0x3ffu) << 10) | (eptr[1] & 0x3ffu)) + 0x10000u; } - -/* Get the next UTF-16 character, not advancing the pointer. This is called when -we know we are in UTF-16 mode. */ - -#define GETCHAR(c, eptr) \ - c = *eptr; \ - if ((c & 0xfc00u) == 0xd800u) GETUTF16(c, eptr); - -/* Get the next UTF-16 character, testing for UTF-16 mode, and not advancing the -pointer. */ - -#define GETCHARTEST(c, eptr) \ - c = *eptr; \ - if (utf && (c & 0xfc00u) == 0xd800u) GETUTF16(c, eptr); - -/* Base macro to pick up the low surrogate of a UTF-16 character, advancing -the pointer. */ - -#define GETUTF16INC(c, eptr) \ - { c = (((c & 0x3ffu) << 10) | (*eptr++ & 0x3ffu)) + 0x10000u; } - -/* Get the next UTF-16 character, advancing the pointer. This is called when we -know we are in UTF-16 mode. */ - -#define GETCHARINC(c, eptr) \ - c = *eptr++; \ - if ((c & 0xfc00u) == 0xd800u) GETUTF16INC(c, eptr); - -/* Get the next character, testing for UTF-16 mode, and advancing the pointer. -This is called when we don't know if we are in UTF-16 mode. */ - -#define GETCHARINCTEST(c, eptr) \ - c = *eptr++; \ - if (utf && (c & 0xfc00u) == 0xd800u) GETUTF16INC(c, eptr); - -/* Base macro to pick up the low surrogate of a UTF-16 character, not -advancing the pointer, incrementing the length. */ - -#define GETUTF16LEN(c, eptr, len) \ - { c = (((c & 0x3ffu) << 10) | (eptr[1] & 0x3ffu)) + 0x10000u; len++; } - -/* Get the next UTF-16 character, not advancing the pointer, incrementing -length if there is a low surrogate. This is called when we know we are in -UTF-16 mode. */ - -#define GETCHARLEN(c, eptr, len) \ - c = *eptr; \ - if ((c & 0xfc00u) == 0xd800u) GETUTF16LEN(c, eptr, len); - -/* Get the next UTF-16 character, testing for UTF-16 mode, not advancing the -pointer, incrementing length if there is a low surrogate. This is called when -we do not know if we are in UTF-16 mode. */ - -#define GETCHARLENTEST(c, eptr, len) \ - c = *eptr; \ - if (utf && (c & 0xfc00u) == 0xd800u) GETUTF16LEN(c, eptr, len); - -/* If the pointer is not at the start of a character, move it back until -it is. This is called only in UTF-16 mode - we don't put a test within the -macro because almost all calls are already within a block of UTF-16 only -code. */ - -#define BACKCHAR(eptr) if ((*eptr & 0xfc00u) == 0xdc00u) eptr-- - -/* Same as above, just in the other direction. */ -#define FORWARDCHAR(eptr) if ((*eptr & 0xfc00u) == 0xdc00u) eptr++ -#define FORWARDCHARTEST(eptr,end) if (eptr < end && (*eptr & 0xfc00u) == 0xdc00u) eptr++ - -/* Same as above, but it allows a fully customizable form. */ -#define ACROSSCHAR(condition, eptr, action) \ - if ((condition) && ((*eptr) & 0xfc00u) == 0xdc00u) action - -/* Deposit a character into memory, returning the number of code units. */ - -#define PUTCHAR(c, p) ((utf && c > MAX_UTF_SINGLE_CU)? \ - PRIV(ord2utf)(c,p) : (*p = c, 1)) - - -/* ------------------- 32-bit support ------------------ */ - -#elif PCRE2_CODE_UNIT_WIDTH == 32 - -/* These are trivial for the 32-bit library, since all UTF-32 characters fit -into one PCRE2_UCHAR unit. */ - -#define MAX_UTF_SINGLE_CU (0x10ffffu) -#define HAS_EXTRALEN(c) (0) -#define GET_EXTRALEN(c) (0) -#define NOT_FIRSTCU(c) (0) - -/* Get the next UTF-32 character, not advancing the pointer. This is called when -we know we are in UTF-32 mode. */ - -#define GETCHAR(c, eptr) \ - c = *(eptr); - -/* Get the next UTF-32 character, testing for UTF-32 mode, and not advancing the -pointer. */ - -#define GETCHARTEST(c, eptr) \ - c = *(eptr); - -/* Get the next UTF-32 character, advancing the pointer. This is called when we -know we are in UTF-32 mode. */ - -#define GETCHARINC(c, eptr) \ - c = *((eptr)++); - -/* Get the next character, testing for UTF-32 mode, and advancing the pointer. -This is called when we don't know if we are in UTF-32 mode. */ - -#define GETCHARINCTEST(c, eptr) \ - c = *((eptr)++); - -/* Get the next UTF-32 character, not advancing the pointer, not incrementing -length (since all UTF-32 is of length 1). This is called when we know we are in -UTF-32 mode. */ - -#define GETCHARLEN(c, eptr, len) \ - GETCHAR(c, eptr) - -/* Get the next UTF-32character, testing for UTF-32 mode, not advancing the -pointer, not incrementing the length (since all UTF-32 is of length 1). -This is called when we do not know if we are in UTF-32 mode. */ - -#define GETCHARLENTEST(c, eptr, len) \ - GETCHARTEST(c, eptr) - -/* If the pointer is not at the start of a character, move it back until -it is. This is called only in UTF-32 mode - we don't put a test within the -macro because almost all calls are already within a block of UTF-32 only -code. - -These are all no-ops since all UTF-32 characters fit into one PCRE2_UCHAR. */ - -#define BACKCHAR(eptr) do { } while (0) - -/* Same as above, just in the other direction. */ - -#define FORWARDCHAR(eptr) do { } while (0) -#define FORWARDCHARTEST(eptr,end) do { } while (0) - -/* Same as above, but it allows a fully customizable form. */ - -#define ACROSSCHAR(condition, eptr, action) do { } while (0) - -/* Deposit a character into memory, returning the number of code units. */ - -#define PUTCHAR(c, p) (*p = c, 1) - -#endif /* UTF-32 character handling */ -#endif /* SUPPORT_UNICODE */ - - -/* Mode-dependent macros that have the same definition in all modes. */ - -#define CU2BYTES(x) ((x)*((PCRE2_CODE_UNIT_WIDTH/8))) -#define BYTES2CU(x) ((x)/((PCRE2_CODE_UNIT_WIDTH/8))) -#define PUTINC(a,n,d) PUT(a,n,d), a += LINK_SIZE -#define PUT2INC(a,n,d) PUT2(a,n,d), a += IMM2_SIZE - -#endif /* PCRE2_CODE_UNIT_WIDTH != 0 */ - - - -/************************************************* -* STRUCTURES * -*************************************************/ - -/* We need a more complex include guard than usual, because the file can be -included once for each bit-width to define the various structures. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 && !defined PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_8 -#define PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_8 -#define PCRE2_INTMODEDEP_CAN_DEFINE -#endif -#if PCRE2_CODE_UNIT_WIDTH == 16 && !defined PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_16 -#define PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_16 -#define PCRE2_INTMODEDEP_CAN_DEFINE -#endif -#if PCRE2_CODE_UNIT_WIDTH == 32 && !defined PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_32 -#define PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_32 -#define PCRE2_INTMODEDEP_CAN_DEFINE -#endif - -#ifdef PCRE2_INTMODEDEP_CAN_DEFINE -#undef PCRE2_INTMODEDEP_CAN_DEFINE - -/* ----------------------- HIDDEN STRUCTURES ----------------------------- */ - -/* NOTE: All these structures *must* start with a pcre2_memctl structure. The -code that uses them is simpler because it assumes this. */ - -/* The real general context structure. At present it holds only data for custom -memory control. */ - -/* WARNING: if this is ever changed, code in pcre2_substitute.c will have to be -changed because it builds a general context "by hand" in order to avoid the -malloc() call in pcre2_general_context)_create(). There is also code in -pcre2_match.c that makes the same assumption. */ - -typedef struct pcre2_real_general_context { - pcre2_memctl memctl; -} pcre2_real_general_context; - -/* The real compile context structure */ - -typedef struct pcre2_real_compile_context { - pcre2_memctl memctl; - int (*stack_guard)(uint32_t, void *); - void *stack_guard_data; - const uint8_t *tables; - PCRE2_SIZE max_pattern_length; - PCRE2_SIZE max_pattern_compiled_length; - uint16_t bsr_convention; - uint16_t newline_convention; - uint32_t parens_nest_limit; - uint32_t extra_options; - uint32_t max_varlookbehind; - uint32_t optimization_flags; -} pcre2_real_compile_context; - -/* The real match context structure. */ - -typedef struct pcre2_real_match_context { - pcre2_memctl memctl; -#ifdef SUPPORT_JIT - pcre2_jit_callback jit_callback; - void *jit_callback_data; -#endif - int (*callout)(pcre2_callout_block *, void *); - void *callout_data; - int (*substitute_callout)(pcre2_substitute_callout_block *, void *); - void *substitute_callout_data; - PCRE2_SIZE (*substitute_case_callout)(PCRE2_SPTR, PCRE2_SIZE, PCRE2_UCHAR *, - PCRE2_SIZE, int, void *); - void *substitute_case_callout_data; - PCRE2_SIZE offset_limit; - uint32_t heap_limit; - uint32_t match_limit; - uint32_t depth_limit; -} pcre2_real_match_context; - -/* The real convert context structure. */ - -typedef struct pcre2_real_convert_context { - pcre2_memctl memctl; - uint32_t glob_separator; - uint32_t glob_escape; -} pcre2_real_convert_context; - -/* The real compiled code structure. The type for the blocksize field is -defined specially because it is required in pcre2_serialize_decode() when -copying the size from possibly unaligned memory into a variable of the same -type. Use a macro rather than a typedef to avoid compiler warnings when this -file is included multiple times by pcre2test. LOOKBEHIND_MAX specifies the -largest lookbehind that is supported. (OP_REVERSE and OP_VREVERSE in a pattern -have 16-bit arguments in 8-bit and 16-bit modes, so we need no more than a -16-bit field here.) */ - -#undef CODE_BLOCKSIZE_TYPE -#define CODE_BLOCKSIZE_TYPE PCRE2_SIZE - -#undef LOOKBEHIND_MAX -#define LOOKBEHIND_MAX ((int)UINT16_MAX) - -typedef struct pcre2_real_code { - pcre2_memctl memctl; /* Memory control fields */ - const uint8_t *tables; /* The character tables */ - void *executable_jit; /* Pointer to JIT code */ - uint8_t start_bitmap[32]; /* Bitmap for starting code unit < 256 */ - CODE_BLOCKSIZE_TYPE blocksize; /* Total (bytes) that was malloc-ed */ - CODE_BLOCKSIZE_TYPE code_start; /* Byte code start offset */ - uint32_t magic_number; /* Paranoid and endianness check */ - uint32_t compile_options; /* Options passed to pcre2_compile() */ - uint32_t overall_options; /* Options after processing the pattern */ - uint32_t extra_options; /* Taken from compile_context */ - uint32_t flags; /* Various state flags */ - uint32_t limit_heap; /* Limit set in the pattern */ - uint32_t limit_match; /* Limit set in the pattern */ - uint32_t limit_depth; /* Limit set in the pattern */ - uint32_t first_codeunit; /* Starting code unit */ - uint32_t last_codeunit; /* This codeunit must be seen */ - uint16_t bsr_convention; /* What \R matches */ - uint16_t newline_convention; /* What is a newline? */ - uint16_t max_lookbehind; /* Longest lookbehind (characters) */ - uint16_t minlength; /* Minimum length of match */ - uint16_t top_bracket; /* Highest numbered group */ - uint16_t top_backref; /* Highest numbered back reference */ - uint16_t name_entry_size; /* Size (code units) of table entries */ - uint16_t name_count; /* Number of name entries in the table */ - uint32_t optimization_flags; /* Optimizations enabled at compile time */ -} pcre2_real_code; - -/* The real match data structure. Define ovector as large as it can ever -actually be so that array bound checkers don't grumble. Memory for this -structure is obtained by calling pcre2_match_data_create(), which sets the size -as the offset of ovector plus a pair of elements for each capturable string, so -the size varies from call to call. As the maximum number of capturing -subpatterns is 65535 we must allow for 65536 strings to include the overall -match. (See also the heapframe structure below.) */ - -struct heapframe; /* Forward reference */ - -typedef struct pcre2_real_match_data { - pcre2_memctl memctl; /* Memory control fields */ - const pcre2_real_code *code; /* The pattern used for the match */ - PCRE2_SPTR subject; /* The subject that was matched */ - PCRE2_SPTR mark; /* Pointer to last mark */ - struct heapframe *heapframes; /* Backtracking frames heap memory */ - PCRE2_SIZE heapframes_size; /* Malloc-ed size */ - PCRE2_SIZE subject_length; /* Subject length */ - PCRE2_SIZE start_offset; /* Offset to start of search */ - PCRE2_SIZE leftchar; /* Offset to leftmost code unit */ - PCRE2_SIZE rightchar; /* Offset to rightmost code unit */ - PCRE2_SIZE startchar; /* Offset to starting code unit */ - uint8_t matchedby; /* Type of match (normal, JIT, DFA) */ - uint8_t flags; /* Various flags */ - uint16_t oveccount; /* Number of pairs */ - uint32_t options; /* Options passed in to the match call */ - int rc; /* The return code from the match */ - PCRE2_SIZE ovector[131072]; /* Must be last in the structure */ -} pcre2_real_match_data; - - -/* ----------------------- PRIVATE STRUCTURES ----------------------------- */ - -/* These structures are not needed for pcre2test. */ - -#ifndef PCRE2_PCRE2TEST - -/* Structures for checking for mutual function recursion when scanning compiled -or parsed code. */ - -typedef struct recurse_check { - struct recurse_check *prev; - PCRE2_SPTR group; -} recurse_check; - -typedef struct parsed_recurse_check { - struct parsed_recurse_check *prev; - uint32_t *groupptr; -} parsed_recurse_check; - -/* Structure for building a cache when filling in pattern recursion offsets. */ - -typedef struct recurse_cache { - PCRE2_SPTR group; - int groupnumber; -} recurse_cache; - -/* Structure for maintaining a chain of pointers to the currently incomplete -branches, for testing for left recursion while compiling. */ - -typedef struct branch_chain { - struct branch_chain *outer; - PCRE2_UCHAR *current_branch; -} branch_chain; - -/* Structure for building a list of named groups during the first pass of -compiling. When a duplicate name is stored in the list, its name is set to -the name of the first entry with the same name, and its length is set to 0. */ - -typedef struct named_group { - PCRE2_SPTR name; /* Points to the name in the pattern */ - uint32_t number; /* Group number */ - uint16_t length; /* Length of the name */ - uint16_t hash_dup; /* A concatenation of a 15 bit hash code and - a singe bit which represents duplication */ -} named_group; - -/* Structure for storing compile time data. */ - -typedef struct compile_data { - struct compile_data *next; /* Next compile data */ -#ifdef PCRE2_DEBUG - uint8_t type; /* Debug only type of the data */ -#endif -} compile_data; - -/* Structure for caching sorted ranges. This improves the performance -of translating META code to byte code. */ - -typedef struct class_ranges { - compile_data header; /* Common header */ - size_t char_lists_size; /* Total size of encoded char lists */ - size_t char_lists_start; /* Start offset of encoded char lists */ - uint16_t range_list_size; /* Size of ranges array */ - uint16_t char_lists_types; /* The XCL_LIST header of char lists */ - /* Followed by the list of ranges (start/end pairs) */ -} class_ranges; - -/* Structure for sorted recurse arguments. */ - -typedef struct recurse_arguments { - compile_data header; /* Common header */ - size_t size; /* Total size */ - size_t skip_size; /* Space consumed by arguments */ -} recurse_arguments; - -typedef union class_bits_storage { - uint8_t classbits[32]; - uint32_t classwords[8]; -} class_bits_storage; - -/* Structure for passing "static" information around between the functions -doing the compiling, so that they are thread-safe. */ - -typedef struct compile_block { - pcre2_real_compile_context *cx; /* Points to the compile context */ - const uint8_t *lcc; /* Points to lower casing table */ - const uint8_t *fcc; /* Points to case-flipping table */ - const uint8_t *cbits; /* Points to character type table */ - const uint8_t *ctypes; /* Points to table of type maps */ - PCRE2_UCHAR *start_workspace; /* The start of working space */ - PCRE2_UCHAR *start_code; /* The start of the compiled code */ - PCRE2_SPTR start_pattern; /* The start of the pattern */ - PCRE2_SPTR end_pattern; /* The end of the pattern */ - PCRE2_UCHAR *name_table; /* The name/number table */ - PCRE2_SIZE workspace_size; /* Size of workspace */ - PCRE2_SIZE small_ref_offset[10]; /* Offsets for \1 to \9 */ - PCRE2_SIZE erroroffset; /* Offset of error in pattern */ - class_bits_storage classbits; /* Temporary store for classbits */ - uint16_t names_found; /* Number of entries so far */ - uint16_t name_entry_size; /* Size of each entry */ - uint16_t parens_depth; /* Depth of nested parentheses */ - uint16_t assert_depth; /* Depth of nested assertions */ - named_group *named_groups; /* Points to vector in pre-compile */ - uint32_t named_group_list_size; /* Number of entries in the list */ - uint32_t external_options; /* External (initial) options */ - uint32_t external_flags; /* External flag bits to be set */ - uint32_t bracount; /* Count of capturing parentheses */ - uint32_t lastcapture; /* Last capture encountered */ - uint32_t *parsed_pattern; /* Parsed pattern buffer */ - uint32_t *parsed_pattern_end; /* Parsed pattern should not get here */ - uint32_t *groupinfo; /* Group info vector */ - uint32_t top_backref; /* Maximum back reference */ - uint32_t backref_map; /* Bitmap of low back refs */ - uint32_t nltype; /* Newline type */ - uint32_t nllen; /* Newline string length */ - PCRE2_UCHAR nl[4]; /* Newline string when fixed length */ - uint8_t class_op_used[ECLASS_NEST_LIMIT]; /* Operation used for - extended classes */ - uint32_t req_varyopt; /* "After variable item" flag for reqbyte */ - uint32_t max_varlookbehind; /* Limit for variable lookbehinds */ - int max_lookbehind; /* Maximum lookbehind encountered (characters) */ - BOOL had_accept; /* (*ACCEPT) encountered */ - BOOL had_pruneorskip; /* (*PRUNE) or (*SKIP) encountered */ - BOOL had_recurse; /* Had a pattern recursion or subroutine call */ - BOOL dupnames; /* Duplicate names exist */ - compile_data *first_data; /* First item in the compile data list */ - compile_data *last_data; /* Last item in the compile data list */ -#ifdef SUPPORT_WIDE_CHARS - size_t char_lists_size; /* Current size of character lists */ -#endif -} compile_block; - -/* Structure for keeping the properties of the in-memory stack used -by the JIT matcher. */ - -typedef struct pcre2_real_jit_stack { - pcre2_memctl memctl; - void* stack; -} pcre2_real_jit_stack; - -/* Structure for items in a linked list that represents an explicit recursive -call within the pattern when running pcre2_dfa_match(). */ - -typedef struct dfa_recursion_info { - struct dfa_recursion_info *prevrec; - PCRE2_SPTR subject_position; - PCRE2_SPTR last_used_ptr; - uint32_t group_num; -} dfa_recursion_info; - -/* Structure for "stack" frames that are used for remembering backtracking -positions during matching. As these are used in a vector, with the ovector item -being extended, the size of the structure must be a multiple of PCRE2_SIZE. The -only way to check this at compile time is to force an error by generating an -array with a negative size. By putting this in a typedef (which is never used), -we don't generate any code when all is well. */ - -typedef struct heapframe { - - /* The first set of fields are variables that have to be preserved over calls - to RRMATCH(), but which do not need to be copied to new frames. */ - - PCRE2_SPTR ecode; /* The current position in the pattern */ - PCRE2_SPTR temp_sptr[2]; /* Used for short-term PCRE2_SPTR values */ - PCRE2_SIZE length; /* Used for character, string, or code lengths */ - PCRE2_SIZE back_frame; /* Amount to subtract on RRETURN */ - PCRE2_SIZE temp_size; /* Used for short-term PCRE2_SIZE values */ - uint32_t rdepth; /* Function "recursion" depth within pcre2_match() */ - uint32_t group_frame_type; /* Type information for group frames */ - uint32_t temp_32[4]; /* Used for short-term 32-bit or BOOL values */ - uint8_t return_id; /* Where to go on in internal "return" */ - uint8_t op; /* Processing opcode */ - - /* At this point, the structure is 16-bit aligned. On most architectures - the alignment requirement for a pointer will ensure that the eptr field below - is 32-bit or 64-bit aligned. However, on m68k it is fine to have a pointer - that is 16-bit aligned. We must therefore ensure that what comes between here - and eptr is an odd multiple of 16 bits so as to get back into 32-bit - alignment. This happens naturally when PCRE2_UCHAR is 8 bits wide, but needs - fudges in the other cases. In the 32-bit case the padding comes first so that - the occu field itself is 32-bit aligned. Without the padding, this structure - is no longer a multiple of PCRE2_SIZE on m68k, and the check below fails. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 - PCRE2_UCHAR occu[6]; /* Used for other case code units */ -#elif PCRE2_CODE_UNIT_WIDTH == 16 - PCRE2_UCHAR occu[2]; /* Used for other case code units */ - uint8_t unused[2]; /* Ensure 32-bit alignment (see above) */ -#else - uint8_t unused[2]; /* Ensure 32-bit alignment (see above) */ - PCRE2_UCHAR occu[1]; /* Used for other case code units */ -#endif - - /* The rest have to be copied from the previous frame whenever a new frame - becomes current. The final field is specified as a large vector so that - runtime array bound checks don't catch references to it. However, for any - specific call to pcre2_match() the memory allocated for each frame structure - allows for exactly the right size ovector for the number of capturing - parentheses. (See also the comment for pcre2_real_match_data above.) */ - - PCRE2_SPTR eptr; /* MUST BE FIRST */ - PCRE2_SPTR start_match; /* Can be adjusted by \K */ - PCRE2_SPTR mark; /* Most recent mark on the success path */ - PCRE2_SPTR recurse_last_used; /* Last character used at time of pattern recursion */ - uint32_t current_recurse; /* Group number of current (deepest) pattern recursion */ - uint32_t capture_last; /* Most recent capture */ - PCRE2_SIZE last_group_offset; /* Saved offset to most recent group frame */ - PCRE2_SIZE offset_top; /* Offset after highest capture */ - PCRE2_SIZE ovector[131072]; /* Must be last in the structure */ -} heapframe; - -/* Assert that the size of the heapframe structure is a multiple of PCRE2_SIZE. -See various comments above. */ - -STATIC_ASSERT((sizeof(heapframe) % sizeof(PCRE2_SIZE)) == 0, heapframe_size); - -/* Structure for computing the alignment of heapframe. */ - -typedef struct heapframe_align { - char unalign; /* Completely unalign the current offset */ - heapframe frame; /* Offset is its alignment */ -} heapframe_align; - -/* This define is the minimum alignment required for a heapframe, in bytes. */ - -#define HEAPFRAME_ALIGNMENT offsetof(heapframe_align, frame) - -/* Structure for passing "static" information around between the functions -doing traditional NFA matching (pcre2_match() and friends). */ - -typedef struct match_block { - pcre2_memctl memctl; /* For general use */ - uint32_t heap_limit; /* As it says */ - uint32_t match_limit; /* As it says */ - uint32_t match_limit_depth; /* As it says */ - uint32_t match_call_count; /* Number of times a new frame is created */ - BOOL hitend; /* Hit the end of the subject at some point */ - BOOL hasthen; /* Pattern contains (*THEN) */ - BOOL hasbsk; /* Pattern contains \K */ - BOOL allowemptypartial; /* Allow empty hard partial */ - BOOL allowlookaroundbsk; /* Allow \K within lookarounds */ - const uint8_t *lcc; /* Points to lower casing table */ - const uint8_t *fcc; /* Points to case-flipping table */ - const uint8_t *ctypes; /* Points to table of type maps */ - PCRE2_SIZE start_offset; /* The start offset value */ - PCRE2_SIZE end_offset_top; /* Highwater mark at end of match */ - uint16_t partial; /* PARTIAL options */ - uint16_t bsr_convention; /* \R interpretation */ - uint16_t name_count; /* Number of names in name table */ - uint16_t name_entry_size; /* Size of entry in names table */ - PCRE2_SPTR name_table; /* Table of group names */ - PCRE2_SPTR start_code; /* For use in pattern recursion */ - PCRE2_SPTR start_subject; /* Start of the subject string */ - PCRE2_SPTR check_subject; /* Where UTF-checked from */ - PCRE2_SPTR end_subject; /* Usable end of the subject string */ - PCRE2_SPTR true_end_subject; /* Actual end of the subject string */ - PCRE2_SPTR end_match_ptr; /* Subject position at end match */ - PCRE2_SPTR start_used_ptr; /* Earliest consulted character */ - PCRE2_SPTR last_used_ptr; /* Latest consulted character */ - PCRE2_SPTR mark; /* Mark pointer to pass back on success */ - PCRE2_SPTR nomatch_mark; /* Mark pointer to pass back on failure */ - PCRE2_SPTR verb_ecode_ptr; /* For passing back info */ - PCRE2_SPTR verb_skip_ptr; /* For passing back a (*SKIP) name */ - uint32_t verb_current_recurse; /* Current recursion group when (*VERB) happens */ - uint32_t moptions; /* Match options */ - uint32_t poptions; /* Pattern options */ - uint32_t skip_arg_count; /* For counting SKIP_ARGs */ - uint32_t ignore_skip_arg; /* For re-run when SKIP arg name not found */ - uint32_t nltype; /* Newline type */ - uint32_t nllen; /* Newline string length */ - PCRE2_UCHAR nl[4]; /* Newline string when fixed */ - pcre2_callout_block *cb; /* Points to a callout block */ - void *callout_data; /* To pass back to callouts */ - int (*callout)(pcre2_callout_block *,void *); /* Callout function or NULL */ -} match_block; - -/* A similar structure is used for the same purpose by the DFA matching -functions. */ - -typedef struct dfa_match_block { - pcre2_memctl memctl; /* For general use */ - PCRE2_SPTR start_code; /* Start of the compiled pattern */ - PCRE2_SPTR start_subject ; /* Start of the subject string */ - PCRE2_SPTR end_subject; /* End of subject string */ - PCRE2_SPTR start_used_ptr; /* Earliest consulted character */ - PCRE2_SPTR last_used_ptr; /* Latest consulted character */ - const uint8_t *tables; /* Character tables */ - PCRE2_SIZE start_offset; /* The start offset value */ - uint32_t heap_limit; /* As it says */ - PCRE2_SIZE heap_used; /* As it says */ - uint32_t match_limit; /* As it says */ - uint32_t match_limit_depth; /* As it says */ - uint32_t match_call_count; /* Number of calls of internal function */ - uint32_t moptions; /* Match options */ - uint32_t poptions; /* Pattern options */ - uint32_t nltype; /* Newline type */ - uint32_t nllen; /* Newline string length */ - BOOL allowemptypartial; /* Allow empty hard partial */ - PCRE2_UCHAR nl[4]; /* Newline string when fixed */ - uint16_t bsr_convention; /* \R interpretation */ - pcre2_callout_block *cb; /* Points to a callout block */ - void *callout_data; /* To pass back to callouts */ - int (*callout)(pcre2_callout_block *,void *); /* Callout function or NULL */ - dfa_recursion_info *recursive; /* Linked list of pattern recursion data */ -} dfa_match_block; - -#endif /* PCRE2_PCRE2TEST */ - -#endif /* PCRE2_INTMODEDEP_CAN_DEFINE */ - -/* End of pcre2_intmodedep.h */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_maketables.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_maketables.c deleted file mode 100644 index 0f6c511..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_maketables.c +++ /dev/null @@ -1,177 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains the external function pcre2_maketables(), which builds -character tables for PCRE2 in the current locale. The file is compiled on its -own as part of the PCRE2 library. It is also included in the compilation of -pcre2_dftables.c as a freestanding program, in which case the macro -PCRE2_DFTABLES is defined. */ - - -#ifndef PCRE2_DFTABLES /* Compiling the library */ -#include "pcre2_internal.h" -#endif - - - -/************************************************* -* Create PCRE2 character tables * -*************************************************/ - -/* This function builds a set of character tables for use by PCRE2 and returns -a pointer to them. They are build using the ctype functions, and consequently -their contents will depend upon the current locale setting. When compiled as -part of the library, the store is obtained via a general context malloc, if -supplied, but when PCRE2_DFTABLES is defined (when compiling the pcre2_dftables -freestanding auxiliary program) malloc() is used, and the function has a -different name so as not to clash with the prototype in pcre2.h. - -Arguments: pointers to character-transforming functions when PCRE2_DFTABLES is - defined; - else a PCRE2 general context or NULL -Returns: pointer to the contiguous block of data; - else NULL if memory allocation failed -*/ - -#ifdef PCRE2_DFTABLES /* Included in freestanding pcre2_dftables program */ -static const uint8_t *maketables(int (*charfn_to)(int), int (*charfn_from)(int)) -{ -uint8_t *yield = (uint8_t *)malloc(TABLES_LENGTH); - -#else /* Not PCRE2_DFTABLES, that is, compiling the library */ -PCRE2_EXP_DEFN const uint8_t * PCRE2_CALL_CONVENTION -pcre2_maketables(pcre2_general_context *gcontext) -{ -uint8_t *yield = (uint8_t *)((gcontext != NULL)? - gcontext->memctl.malloc(TABLES_LENGTH, gcontext->memctl.memory_data) : - malloc(TABLES_LENGTH)); - -#define charfn_to(c) (c) -#define charfn_from(c) (c) -#endif /* PCRE2_DFTABLES */ - -int i; -uint8_t *p; - -if (yield == NULL) return NULL; -p = yield; - -/* First comes the lower casing table */ - -for (i = 0; i < 256; i++) - { - int c = charfn_from(tolower(charfn_to(i))); - *p++ = (c < 256)? c : i; - } - -/* Next the case-flipping table */ - -for (i = 0; i < 256; i++) - { - int c = charfn_from(islower(charfn_to(i))? toupper(charfn_to(i)) - : tolower(charfn_to(i))); - *p++ = (c < 256)? c : i; - } - -/* Then the character class tables. Don't try to be clever and save effort on -exclusive ones - in some locales things may be different. - -Note that the table for "space" includes everything "isspace" gives, including -VT in the default locale. This makes it work for the POSIX class [:space:]. -From PCRE1 release 8.34 and for all PCRE2 releases it is also correct for Perl -space, because Perl added VT at release 5.18. - -Note also that it is possible for a character to be alnum or alpha without -being lower or upper, such as "male and female ordinals" (\xAA and \xBA) in the -fr_FR locale (at least under Debian Linux's locales as of 12/2005). So we must -test for alnum specially. */ - -memset(p, 0, cbit_length); -for (i = 0; i < 256; i++) - { - if (isdigit(charfn_to(i))) p[cbit_digit + i/8] |= 1u << (i&7); - if (isupper(charfn_to(i))) p[cbit_upper + i/8] |= 1u << (i&7); - if (islower(charfn_to(i))) p[cbit_lower + i/8] |= 1u << (i&7); - if (isalnum(charfn_to(i))) p[cbit_word + i/8] |= 1u << (i&7); - if (i == CHAR_UNDERSCORE) p[cbit_word + i/8] |= 1u << (i&7); - if (isspace(charfn_to(i))) p[cbit_space + i/8] |= 1u << (i&7); - if (isxdigit(charfn_to(i))) p[cbit_xdigit + i/8] |= 1u << (i&7); - if (isgraph(charfn_to(i))) p[cbit_graph + i/8] |= 1u << (i&7); - if (isprint(charfn_to(i))) p[cbit_print + i/8] |= 1u << (i&7); - if (ispunct(charfn_to(i))) p[cbit_punct + i/8] |= 1u << (i&7); - if (iscntrl(charfn_to(i))) p[cbit_cntrl + i/8] |= 1u << (i&7); - } -p += cbit_length; - -/* Finally, the character type table. In this, we used to exclude VT from the -white space chars, because Perl didn't recognize it as such for \s and for -comments within regexes. However, Perl changed at release 5.18, so PCRE1 -changed at release 8.34 and it's always been this way for PCRE2. */ - -for (i = 0; i < 256; i++) - { - int x = 0; - if (isspace(charfn_to(i))) x += ctype_space; - if (isalpha(charfn_to(i))) x += ctype_letter; - if (islower(charfn_to(i))) x += ctype_lcletter; - if (isdigit(charfn_to(i))) x += ctype_digit; - if (isalnum(charfn_to(i)) || i == CHAR_UNDERSCORE) x += ctype_word; - *p++ = x; - } - -return yield; -} - -#ifndef PCRE2_DFTABLES /* Compiling the library */ -#undef charfn_to -#undef charfn_from - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_maketables_free(pcre2_general_context *gcontext, const uint8_t *tables) -{ -if (gcontext != NULL) - gcontext->memctl.free((void *)tables, gcontext->memctl.memory_data); -else - free((void *)tables); -} -#endif - -/* End of pcre2_maketables.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match.c deleted file mode 100644 index d5574d7..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match.c +++ /dev/null @@ -1,8244 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2015-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -/* These defines enable debugging code */ - -/* #define DEBUG_FRAMES_DISPLAY */ -/* #define DEBUG_SHOW_OPS */ -/* #define DEBUG_SHOW_RMATCH */ - -#ifdef DEBUG_FRAMES_DISPLAY -#include -#endif - -#ifdef DEBUG_SHOW_OPS -static const char *OP_names[] = { OP_NAME_LIST }; -#endif - -/* These defines identify the name of the block containing "static" -information, and fields within it. */ - -#define NLBLOCK mb /* Block containing newline information */ -#define PSSTART start_subject /* Field containing processed string start */ -#define PSEND end_subject /* Field containing processed string end */ - -#define RECURSE_UNSET 0xffffffffu /* Bigger than max group number */ - -/* Masks for identifying the public options that are permitted at match time. */ - -#define PUBLIC_MATCH_OPTIONS \ - (PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY| \ - PCRE2_NOTEMPTY_ATSTART|PCRE2_NO_UTF_CHECK|PCRE2_PARTIAL_HARD| \ - PCRE2_PARTIAL_SOFT|PCRE2_NO_JIT|PCRE2_COPY_MATCHED_SUBJECT| \ - PCRE2_DISABLE_RECURSELOOP_CHECK) - -#define PUBLIC_JIT_MATCH_OPTIONS \ - (PCRE2_NO_UTF_CHECK|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY|\ - PCRE2_NOTEMPTY_ATSTART|PCRE2_PARTIAL_SOFT|PCRE2_PARTIAL_HARD|\ - PCRE2_COPY_MATCHED_SUBJECT) - -/* Non-error returns from and within the match() function. Error returns are -externally defined PCRE2_ERROR_xxx codes, which are all negative. */ - -#define MATCH_MATCH 1 -#define MATCH_NOMATCH 0 - -/* Special internal returns used in the match() function. Make them -sufficiently negative to avoid the external error codes. */ - -#define MATCH_ACCEPT (-999) -#define MATCH_KETRPOS (-998) -/* The next 5 must be kept together and in sequence so that a test that checks -for any one of them can use a range. */ -#define MATCH_COMMIT (-997) -#define MATCH_PRUNE (-996) -#define MATCH_SKIP (-995) -#define MATCH_SKIP_ARG (-994) -#define MATCH_THEN (-993) -#define MATCH_BACKTRACK_MAX MATCH_THEN -#define MATCH_BACKTRACK_MIN MATCH_COMMIT - -/* Group frame type values. Zero means the frame is not a group frame. The -lower 16 bits are used for data (e.g. the capture number). Group frames are -used for most groups so that information about the start is easily available at -the end without having to scan back through intermediate frames (backtrack -points). */ - -#define GF_CAPTURE 0x00010000u -#define GF_NOCAPTURE 0x00020000u -#define GF_CONDASSERT 0x00030000u -#define GF_RECURSE 0x00040000u - -/* Masks for the identity and data parts of the group frame type. */ - -#define GF_IDMASK(a) ((a) & 0xffff0000u) -#define GF_DATAMASK(a) ((a) & 0x0000ffffu) - -/* Repetition types */ - -enum { REPTYPE_MIN, REPTYPE_MAX, REPTYPE_POS }; - -/* Min and max values for the common repeats; a maximum of UINT32_MAX => -infinity. */ - -static const uint32_t rep_min[] = { - 0, 0, /* * and *? */ - 1, 1, /* + and +? */ - 0, 0, /* ? and ?? */ - 0, 0, /* dummy placefillers for OP_CR[MIN]RANGE */ - 0, 1, 0 }; /* OP_CRPOS{STAR, PLUS, QUERY} */ - -static const uint32_t rep_max[] = { - UINT32_MAX, UINT32_MAX, /* * and *? */ - UINT32_MAX, UINT32_MAX, /* + and +? */ - 1, 1, /* ? and ?? */ - 0, 0, /* dummy placefillers for OP_CR[MIN]RANGE */ - UINT32_MAX, UINT32_MAX, 1 }; /* OP_CRPOS{STAR, PLUS, QUERY} */ - -/* Repetition types - must include OP_CRPOSRANGE (not needed above) */ - -static const uint32_t rep_typ[] = { - REPTYPE_MAX, REPTYPE_MIN, /* * and *? */ - REPTYPE_MAX, REPTYPE_MIN, /* + and +? */ - REPTYPE_MAX, REPTYPE_MIN, /* ? and ?? */ - REPTYPE_MAX, REPTYPE_MIN, /* OP_CRRANGE and OP_CRMINRANGE */ - REPTYPE_POS, REPTYPE_POS, /* OP_CRPOSSTAR, OP_CRPOSPLUS */ - REPTYPE_POS, REPTYPE_POS }; /* OP_CRPOSQUERY, OP_CRPOSRANGE */ - -/* Numbers for RMATCH calls at backtracking points. When these lists are -changed, the code at RETURN_SWITCH below must be updated in sync. */ - -enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10, - RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20, - RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30, - RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39 }; - -#ifdef SUPPORT_WIDE_CHARS -enum { RM100=100, RM101, RM102, RM103 }; -#endif - -#ifdef SUPPORT_UNICODE -enum { RM200=200, RM201, RM202, RM203, RM204, RM205, RM206, RM207, - RM208, RM209, RM210, RM211, RM212, RM213, RM214, RM215, - RM216, RM217, RM218, RM219, RM220, RM221, RM222, RM223, - RM224 }; -#endif - -/* Define short names for general fields in the current backtrack frame, which -is always pointed to by the F variable. Occasional references to fields in -other frames are written out explicitly. There are also some fields in the -current frame whose names start with "temp" that are used for short-term, -localised backtracking memory. These are #defined with Lxxx names at the point -of use and undefined afterwards. */ - -#define Fback_frame F->back_frame -#define Fcapture_last F->capture_last -#define Fcurrent_recurse F->current_recurse -#define Fecode F->ecode -#define Feptr F->eptr -#define Fgroup_frame_type F->group_frame_type -#define Flast_group_offset F->last_group_offset -#define Flength F->length -#define Fmark F->mark -#define Frdepth F->rdepth -#define Fstart_match F->start_match -#define Foffset_top F->offset_top -#define Foccu F->occu -#define Fop F->op -#define Fovector F->ovector -#define Freturn_id F->return_id - - -#ifdef DEBUG_FRAMES_DISPLAY -/************************************************* -* Display current frames and contents * -*************************************************/ - -/* This debugging function displays the current set of frames and their -contents. It is not called automatically from anywhere, the intention being -that calls can be inserted where necessary when debugging frame-related -problems. - -Arguments: - f the file to write to - F the current top frame - P a previous frame of interest - frame_size the frame size - mb points to the match block - match_data points to the match data block - s identification text - -Returns: nothing -*/ - -static void -display_frames(FILE *f, heapframe *F, heapframe *P, PCRE2_SIZE frame_size, - match_block *mb, pcre2_match_data *match_data, const char *s, ...) -{ -uint32_t i; -heapframe *Q; -va_list ap; -va_start(ap, s); - -fprintf(f, "FRAMES "); -vfprintf(f, s, ap); -va_end(ap); - -if (P != NULL) fprintf(f, " P=%lu", - ((char *)P - (char *)(match_data->heapframes))/frame_size); -fprintf(f, "\n"); - -for (i = 0, Q = match_data->heapframes; - Q <= F; - i++, Q = (heapframe *)((char *)Q + frame_size)) - { - fprintf(f, "Frame %d type=%x subj=%lu code=%d back=%lu id=%d", - i, Q->group_frame_type, Q->eptr - mb->start_subject, *(Q->ecode), - Q->back_frame, Q->return_id); - - if (Q->last_group_offset == PCRE2_UNSET) - fprintf(f, " lgoffset=unset\n"); - else - fprintf(f, " lgoffset=%lu\n", Q->last_group_offset/frame_size); - } -} - -#endif - - - -/************************************************* -* Process a callout * -*************************************************/ - -/* This function is called for all callouts, whether "standalone" or at the -start of a conditional group. Feptr will be pointing to either OP_CALLOUT or -OP_CALLOUT_STR. A callout block is allocated in pcre2_match() and initialized -with fixed values. - -Arguments: - F points to the current backtracking frame - mb points to the match block - lengthptr where to return the length of the callout item - -Returns: the return from the callout - or 0 if no callout function exists -*/ - -static int -do_callout(heapframe *F, match_block *mb, PCRE2_SIZE *lengthptr) -{ -int rc; -PCRE2_SIZE save0, save1; -PCRE2_SIZE *callout_ovector; -pcre2_callout_block *cb; - -*lengthptr = (*Fecode == OP_CALLOUT)? - PRIV(OP_lengths)[OP_CALLOUT] : GET(Fecode, 1 + 2*LINK_SIZE); - -if (mb->callout == NULL) return 0; /* No callout function provided */ - -/* The original matching code (pre 10.30) worked directly with the ovector -passed by the user, and this was passed to callouts. Now that the working -ovector is in the backtracking frame, it no longer needs to reserve space for -the overall match offsets (which would waste space in the frame). For backward -compatibility, however, we pass capture_top and offset_vector to the callout as -if for the extended ovector, and we ensure that the first two slots are unset -by preserving and restoring their current contents. Picky compilers complain if -references such as Fovector[-2] are use directly, so we set up a separate -pointer. */ - -callout_ovector = (PCRE2_SIZE *)(Fovector) - 2; - -/* The cb->version, cb->subject, cb->subject_length, and cb->start_match fields -are set externally. The first 3 never change; the last is updated for each -bumpalong. */ - -cb = mb->cb; -cb->capture_top = (uint32_t)Foffset_top/2 + 1; -cb->capture_last = Fcapture_last; -cb->offset_vector = callout_ovector; -cb->mark = mb->nomatch_mark; -cb->current_position = (PCRE2_SIZE)(Feptr - mb->start_subject); -cb->pattern_position = GET(Fecode, 1); -cb->next_item_length = GET(Fecode, 1 + LINK_SIZE); - -if (*Fecode == OP_CALLOUT) /* Numerical callout */ - { - cb->callout_number = Fecode[1 + 2*LINK_SIZE]; - cb->callout_string_offset = 0; - cb->callout_string = NULL; - cb->callout_string_length = 0; - } -else /* String callout */ - { - cb->callout_number = 0; - cb->callout_string_offset = GET(Fecode, 1 + 3*LINK_SIZE); - cb->callout_string = Fecode + (1 + 4*LINK_SIZE) + 1; - cb->callout_string_length = - *lengthptr - (1 + 4*LINK_SIZE) - 2; - } - -save0 = callout_ovector[0]; -save1 = callout_ovector[1]; -callout_ovector[0] = callout_ovector[1] = PCRE2_UNSET; -rc = mb->callout(cb, mb->callout_data); -callout_ovector[0] = save0; -callout_ovector[1] = save1; -cb->callout_flags = 0; -return rc; -} - - - -/************************************************* -* Match a back-reference * -*************************************************/ - -/* This function is called only when it is known that the offset lies within -the offsets that have so far been used in the match. Note that in caseless -UTF-8 mode, the number of subject bytes matched may be different to the number -of reference bytes. (In theory this could also happen in UTF-16 mode, but it -seems unlikely.) - -Arguments: - offset index into the offset vector - caseless TRUE if caseless - caseopts bitmask of REFI_FLAG_XYZ values - F the current backtracking frame pointer - mb points to match block - lengthptr pointer for returning the length matched - -Returns: = 0 sucessful match; number of code units matched is set - < 0 no match - > 0 partial match -*/ - -static int -match_ref(PCRE2_SIZE offset, BOOL caseless, int caseopts, heapframe *F, - match_block *mb, PCRE2_SIZE *lengthptr) -{ -PCRE2_SPTR p; -PCRE2_SIZE length; -PCRE2_SPTR eptr; -PCRE2_SPTR eptr_start; - -#ifndef SUPPORT_UNICODE -(void)caseopts; /* Avoid compiler warning. */ -#endif - -/* Deal with an unset group. The default is no match, but there is an option to -match an empty string. */ - -if (offset >= Foffset_top || Fovector[offset] == PCRE2_UNSET) - { - if ((mb->poptions & PCRE2_MATCH_UNSET_BACKREF) != 0) - { - *lengthptr = 0; - return 0; /* Match */ - } - else return -1; /* No match */ - } - -/* Separate the caseless and UTF cases for speed. */ - -eptr = eptr_start = Feptr; -p = mb->start_subject + Fovector[offset]; -length = Fovector[offset+1] - Fovector[offset]; -PCRE2_ASSERT(eptr <= mb->end_subject); - -if (caseless) - { -#if defined SUPPORT_UNICODE - BOOL utf = (mb->poptions & PCRE2_UTF) != 0; - BOOL caseless_restrict = (caseopts & REFI_FLAG_CASELESS_RESTRICT) != 0; - BOOL turkish_casing = !caseless_restrict && (caseopts & REFI_FLAG_TURKISH_CASING) != 0; - - if (utf || (mb->poptions & PCRE2_UCP) != 0) - { - PCRE2_SPTR endptr = p + length; - - /* Match characters up to the end of the reference. NOTE: the number of - code units matched may differ, because in UTF-8 there are some characters - whose upper and lower case codes have different numbers of bytes. For - example, U+023A (2 bytes in UTF-8) is the upper case version of U+2C65 (3 - bytes in UTF-8); a sequence of 3 of the former uses 6 bytes, as does a - sequence of two of the latter. It is important, therefore, to check the - length along the reference, not along the subject (earlier code did this - wrong). UCP uses Unicode properties but without UTF encoding. */ - - while (p < endptr) - { - uint32_t c, d; - const ucd_record *ur; - if (eptr >= mb->end_subject) return 1; /* Partial match */ - - if (utf) - { - GETCHARINC(c, eptr); - GETCHARINC(d, p); - } - else - { - c = *eptr++; - d = *p++; - } - - if (turkish_casing && UCD_ANY_I(d)) - { - c = UCD_FOLD_I_TURKISH(c); - d = UCD_FOLD_I_TURKISH(d); - if (c != d) return -1; /* No match */ - } - else if (c != d && c != (uint32_t)((int)d + (ur = GET_UCD(d))->other_case)) - { - const uint32_t *pp = PRIV(ucd_caseless_sets) + ur->caseset; - - /* When PCRE2_EXTRA_CASELESS_RESTRICT is set, ignore any caseless sets - that start with an ASCII character. */ - if (caseless_restrict && *pp < 128) return -1; /* No match */ - - for (;;) - { - if (c < *pp) return -1; /* No match */ - if (c == *pp++) break; - } - } - } - } - else -#endif - - /* Not in UTF or UCP mode */ - { - for (; length > 0; length--) - { - uint32_t cc, cp; - if (eptr >= mb->end_subject) return 1; /* Partial match */ - cc = UCHAR21TEST(eptr); - cp = UCHAR21TEST(p); - if (TABLE_GET(cp, mb->lcc, cp) != TABLE_GET(cc, mb->lcc, cc)) - return -1; /* No match */ - p++; - eptr++; - } - } - } - -/* In the caseful case, we can just compare the code units, whether or not we -are in UTF and/or UCP mode. When partial matching, we have to do this unit by -unit. */ - -else - { - if (mb->partial != 0) - { - for (; length > 0; length--) - { - if (eptr >= mb->end_subject) return 1; /* Partial match */ - if (UCHAR21INCTEST(p) != UCHAR21INCTEST(eptr)) return -1; /* No match */ - } - } - - /* Not partial matching */ - - else - { - if ((PCRE2_SIZE)(mb->end_subject - eptr) < length || - memcmp(p, eptr, CU2BYTES(length)) != 0) return -1; /* No match */ - eptr += length; - } - } - -*lengthptr = eptr - eptr_start; -return 0; /* Match */ -} - - - -/************************************************* -* Restore offsets after a recurse * -*************************************************/ - -/* This function restores the ovector values when -a recursive block reaches its end, and the triggering -recurse has and argument list. - -Arguments: - F the current backtracking frame pointer - P the previous backtracking frame pointer -*/ - -static void -recurse_update_offsets(heapframe *F, heapframe *P) -{ -PCRE2_SIZE *dst = F->ovector; -PCRE2_SIZE *src = P->ovector; -/* The first bracket has offset 2, because -offset 0 is reserved for the full match. */ -PCRE2_SIZE offset = 2; -PCRE2_SIZE offset_top = Foffset_top + 2; -PCRE2_SIZE diff; -PCRE2_SPTR ecode = Fecode; - -do - { - diff = (GET2(ecode, 1) << 1) - offset; - ecode += 1 + IMM2_SIZE; - - if (offset + diff >= offset_top) - { - /* Some OP_CREF opcodes are not - processed, they must be skipped. */ - while (*ecode == OP_CREF) ecode += 1 + IMM2_SIZE; - break; - } - - if (diff == 2) - { - dst[0] = src[0]; - dst[1] = src[1]; - } - else if (diff >= 4) - memcpy(dst, src, diff * sizeof(PCRE2_SIZE)); - - /* Skip the unmodified entry. */ - diff += 2; - offset += diff; - dst += diff; - src += diff; - } -while (*ecode == OP_CREF); - -diff = offset_top - offset; -if (diff == 2) - { - dst[0] = src[0]; - dst[1] = src[1]; - } -else if (diff >= 4) - memcpy(dst, src, diff * sizeof(PCRE2_SIZE)); - -Fecode = ecode; -Foffset_top = (offset <= P->offset_top) ? P->offset_top : (offset - 2); -} - - - -/****************************************************************************** -******************************************************************************* - "Recursion" in the match() function - -The original match() function was highly recursive, but this proved to be the -source of a number of problems over the years, mostly because of the relatively -small system stacks that are commonly found. As new features were added to -patterns, various kludges were invented to reduce the amount of stack used, -making the code hard to understand in places. - -A version did exist that used individual frames on the heap instead of calling -match() recursively, but this ran substantially slower. The current version is -a refactoring that uses a vector of frames to remember backtracking points. -This runs no slower, and possibly even a bit faster than the original recursive -implementation. - -At first, an initial vector of size START_FRAMES_SIZE (enough for maybe 50 -frames) was allocated on the system stack. If this was not big enough, the heap -was used for a larger vector. However, it turns out that there are environments -where taking as little as 20KiB from the system stack is an embarrassment. -After another refactoring, the heap is used exclusively, but a pointer the -frames vector and its size are cached in the match_data block, so that there is -no new memory allocation if the same match_data block is used for multiple -matches (unless the frames vector has to be extended). -******************************************************************************* -******************************************************************************/ - - - - -/************************************************* -* Macros for the match() function * -*************************************************/ - -/* These macros pack up tests that are used for partial matching several times -in the code. The second one is used when we already know we are past the end of -the subject. We set the "hit end" flag if the pointer is at the end of the -subject and either (a) the pointer is past the earliest inspected character -(i.e. something has been matched, even if not part of the actual matched -string), or (b) the pattern contains a lookbehind. These are the conditions for -which adding more characters may allow the current match to continue. - -For hard partial matching, we immediately return a partial match. Otherwise, -carrying on means that a complete match on the current subject will be sought. -A partial match is returned only if no complete match can be found. */ - -#define CHECK_PARTIAL() \ - do { \ - if (Feptr >= mb->end_subject) \ - { \ - SCHECK_PARTIAL(); \ - } \ - } \ - while (0) - -#define SCHECK_PARTIAL() \ - do { \ - if (mb->partial != 0 && \ - (Feptr > mb->start_used_ptr || mb->allowemptypartial)) \ - { \ - mb->hitend = TRUE; \ - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; \ - } \ - } \ - while (0) - - -/* These macros are used to implement backtracking. They simulate a recursive -call to the match() function by means of a local vector of frames which -remember the backtracking points. */ - -#define RMATCH(ra,rb) \ - do { \ - start_ecode = ra; \ - Freturn_id = rb; \ - goto MATCH_RECURSE; \ - L_##rb:; \ - } \ - while (0) - -#define RRETURN(ra) \ - do { \ - rrc = ra; \ - goto RETURN_SWITCH; \ - } \ - while (0) - - - -/************************************************* -* Match from current position * -*************************************************/ - -/* This function is called to run one match attempt at a single starting point -in the subject. - -Performance note: It might be tempting to extract commonly used fields from the -mb structure (e.g. end_subject) into individual variables to improve -performance. Tests using gcc on a SPARC disproved this; in the first case, it -made performance worse. - -Arguments: - start_eptr starting character in subject - start_ecode starting position in compiled code - top_bracket number of capturing parentheses in the pattern - frame_size size of each backtracking frame - match_data pointer to the match_data block - mb pointer to "static" variables block - -Returns: MATCH_MATCH if matched ) these values are >= 0 - MATCH_NOMATCH if failed to match ) - negative MATCH_xxx value for PRUNE, SKIP, etc - negative PCRE2_ERROR_xxx value if aborted by an error condition - (e.g. stopped by repeated call or depth limit) -*/ - -static int -match(PCRE2_SPTR start_eptr, PCRE2_SPTR start_ecode, uint16_t top_bracket, - PCRE2_SIZE frame_size, pcre2_match_data *match_data, match_block *mb) -{ -/* Frame-handling variables */ - -heapframe *F; /* Current frame pointer */ -heapframe *N = NULL; /* Temporary frame pointers */ -heapframe *P = NULL; - -heapframe *frames_top; /* End of frames vector */ -heapframe *assert_accept_frame = NULL; /* For passing back a frame with captures */ -PCRE2_SIZE frame_copy_size; /* Amount to copy when creating a new frame */ - -/* Local variables that do not need to be preserved over calls to RRMATCH(). */ - -PCRE2_SPTR branch_end = NULL; -PCRE2_SPTR branch_start; -PCRE2_SPTR bracode; /* Temp pointer to start of group */ -PCRE2_SIZE offset; /* Used for group offsets */ -PCRE2_SIZE length; /* Used for various length calculations */ - -int rrc; /* Return from functions & backtracking "recursions" */ -#ifdef SUPPORT_UNICODE -int proptype; /* Type of character property */ -#endif - -uint32_t i; /* Used for local loops */ -uint32_t fc; /* Character values */ -uint32_t number; /* Used for group and other numbers */ -uint32_t reptype = 0; /* Type of repetition (0 to avoid compiler warning) */ -uint32_t group_frame_type; /* Specifies type for new group frames */ - -BOOL condition; /* Used in conditional groups */ -BOOL cur_is_word; /* Used in "word" tests */ -BOOL prev_is_word; /* Used in "word" tests */ - -/* UTF and UCP flags */ - -#ifdef SUPPORT_UNICODE -BOOL utf = (mb->poptions & PCRE2_UTF) != 0; -BOOL ucp = (mb->poptions & PCRE2_UCP) != 0; -#else -BOOL utf = FALSE; /* Required for convenience even when no Unicode support */ -#endif - -/* This is the length of the last part of a backtracking frame that must be -copied when a new frame is created. */ - -frame_copy_size = frame_size - offsetof(heapframe, eptr); - -/* Set up the first frame and the end of the frames vector. */ - -F = match_data->heapframes; -frames_top = (heapframe *)((char *)F + match_data->heapframes_size); - -Frdepth = 0; /* "Recursion" depth */ -Fcapture_last = 0; /* Number of most recent capture */ -Fcurrent_recurse = RECURSE_UNSET; /* Not pattern recursing. */ -Fstart_match = Feptr = start_eptr; /* Current data pointer and start match */ -Fmark = NULL; /* Most recent mark */ -Foffset_top = 0; /* End of captures within the frame */ -Flast_group_offset = PCRE2_UNSET; /* Saved frame of most recent group */ -group_frame_type = 0; /* Not a start of group frame */ -goto NEW_FRAME; /* Start processing with this frame */ - -/* Come back here when we want to create a new frame for remembering a -backtracking point. */ - -MATCH_RECURSE: - -/* Set up a new backtracking frame. If the vector is full, get a new one, -doubling the size, but constrained by the heap limit (which is in KiB). */ - -N = (heapframe *)((char *)F + frame_size); -if ((heapframe *)((char *)N + frame_size) >= frames_top) - { - heapframe *new; - PCRE2_SIZE newsize; - PCRE2_SIZE usedsize = (char *)N - (char *)(match_data->heapframes); - - if (match_data->heapframes_size >= PCRE2_SIZE_MAX / 2) - { - if (match_data->heapframes_size == PCRE2_SIZE_MAX - 1) - return PCRE2_ERROR_NOMEMORY; - newsize = PCRE2_SIZE_MAX - 1; - } - else - newsize = match_data->heapframes_size * 2; - - if (newsize / 1024 >= mb->heap_limit) - { - PCRE2_SIZE old_size = match_data->heapframes_size / 1024; - if (mb->heap_limit <= old_size) - return PCRE2_ERROR_HEAPLIMIT; - else - { - PCRE2_SIZE max_delta = 1024 * (mb->heap_limit - old_size); - int over_bytes = match_data->heapframes_size % 1024; - if (over_bytes) max_delta -= (1024 - over_bytes); - newsize = match_data->heapframes_size + max_delta; - } - } - - /* With a heap limit set, the permitted additional size may not be enough for - another frame, so do a final check. */ - - if (newsize - usedsize < frame_size) return PCRE2_ERROR_HEAPLIMIT; - new = match_data->memctl.malloc(newsize, match_data->memctl.memory_data); - if (new == NULL) return PCRE2_ERROR_NOMEMORY; - memcpy(new, match_data->heapframes, usedsize); - - N = (heapframe *)((char *)new + usedsize); - F = (heapframe *)((char *)N - frame_size); - - match_data->memctl.free(match_data->heapframes, match_data->memctl.memory_data); - match_data->heapframes = new; - match_data->heapframes_size = newsize; - frames_top = (heapframe *)((char *)new + newsize); - } - -#ifdef DEBUG_SHOW_RMATCH -fprintf(stderr, "++ RMATCH %d frame=%d", Freturn_id, Frdepth + 1); -if (group_frame_type != 0) - { - fprintf(stderr, " type=%x ", group_frame_type); - switch (GF_IDMASK(group_frame_type)) - { - case GF_CAPTURE: - fprintf(stderr, "capture=%d", GF_DATAMASK(group_frame_type)); - break; - - case GF_NOCAPTURE: - fprintf(stderr, "nocapture op=%d", GF_DATAMASK(group_frame_type)); - break; - - case GF_CONDASSERT: - fprintf(stderr, "condassert op=%d", GF_DATAMASK(group_frame_type)); - break; - - case GF_RECURSE: - fprintf(stderr, "recurse=%d", GF_DATAMASK(group_frame_type)); - break; - - default: - fprintf(stderr, "*** unknown ***"); - break; - } - } -fprintf(stderr, "\n"); -#endif - -/* Copy those fields that must be copied into the new frame, increase the -"recursion" depth (i.e. the new frame's index) and then make the new frame -current. */ - -memcpy((char *)N + offsetof(heapframe, eptr), - (char *)F + offsetof(heapframe, eptr), - frame_copy_size); - -N->rdepth = Frdepth + 1; -F = N; - -/* Carry on processing with a new frame. */ - -NEW_FRAME: -Fgroup_frame_type = group_frame_type; -Fecode = start_ecode; /* Starting code pointer */ -Fback_frame = frame_size; /* Default is go back one frame */ - -/* If this is a special type of group frame, remember its offset for quick -access at the end of the group. If this is a recursion, set a new current -recursion value. */ - -if (group_frame_type != 0) - { - Flast_group_offset = (char *)F - (char *)match_data->heapframes; - if (GF_IDMASK(group_frame_type) == GF_RECURSE) - Fcurrent_recurse = GF_DATAMASK(group_frame_type); - group_frame_type = 0; - } - - -/* ========================================================================= */ -/* This is the main processing loop. First check that we haven't recorded too -many backtracks (search tree is too large), or that we haven't exceeded the -recursive depth limit (used too many backtracking frames). If not, process the -opcodes. */ - -if (mb->match_call_count++ >= mb->match_limit) return PCRE2_ERROR_MATCHLIMIT; -if (Frdepth >= mb->match_limit_depth) return PCRE2_ERROR_DEPTHLIMIT; - -#ifdef DEBUG_SHOW_OPS -fprintf(stderr, "\n++ New frame: type=0x%x subject offset %ld\n", - GF_IDMASK(Fgroup_frame_type), Feptr - mb->start_subject); -#endif - -for (;;) - { -#ifdef DEBUG_SHOW_OPS -fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, - OP_names[*Fecode]); -#endif - - Fop = (uint8_t)(*Fecode); /* Cast needed for 16-bit and 32-bit modes */ - switch(Fop) - { - /* ===================================================================== */ - /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes, to close - any currently open capturing brackets. Unlike reaching the end of a group, - where we know the starting frame is at the top of the chained frames, in - this case we have to search back for the relevant frame in case other types - of group that use chained frames have intervened. Multiple OP_CLOSEs always - come innermost first, which matches the chain order. We can ignore this in - a recursion, because captures are not passed out of recursions. */ - - case OP_CLOSE: - if (Fcurrent_recurse == RECURSE_UNSET) - { - number = GET2(Fecode, 1); - offset = Flast_group_offset; - for(;;) - { - /* Corrupted heapframes?. Trigger an assert and return an error */ - PCRE2_ASSERT(offset != PCRE2_UNSET); - if (offset == PCRE2_UNSET) return PCRE2_ERROR_INTERNAL; - - N = (heapframe *)((char *)match_data->heapframes + offset); - P = (heapframe *)((char *)N - frame_size); - if (N->group_frame_type == (GF_CAPTURE | number)) break; - offset = P->last_group_offset; - } - offset = (number << 1) - 2; - Fcapture_last = number; - Fovector[offset] = P->eptr - mb->start_subject; - Fovector[offset+1] = Feptr - mb->start_subject; - if (offset >= Foffset_top) Foffset_top = offset + 2; - } - Fecode += PRIV(OP_lengths)[*Fecode]; - break; - - - /* ===================================================================== */ - /* Real or forced end of the pattern, assertion, or recursion. In an - assertion ACCEPT, update the last used pointer and remember the current - frame so that the captures and mark can be fished out of it. */ - - case OP_ASSERT_ACCEPT: - if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; - assert_accept_frame = F; - RRETURN(MATCH_ACCEPT); - - /* For ACCEPT within a recursion, we have to find the most recent - recursion. If not in a recursion, fall through to code that is common with - OP_END. */ - - case OP_ACCEPT: - if (Fcurrent_recurse != RECURSE_UNSET) - { -#ifdef DEBUG_SHOW_OPS - fprintf(stderr, "++ Accept within recursion\n"); -#endif - offset = Flast_group_offset; - for(;;) - { - /* Corrupted heapframes?. Trigger an assert and return an error */ - PCRE2_ASSERT(offset != PCRE2_UNSET); - if (offset == PCRE2_UNSET) return PCRE2_ERROR_INTERNAL; - - N = (heapframe *)((char *)match_data->heapframes + offset); - P = (heapframe *)((char *)N - frame_size); - if (GF_IDMASK(N->group_frame_type) == GF_RECURSE) break; - offset = P->last_group_offset; - } - - /* N is now the frame of the recursion; the previous frame is at the - OP_RECURSE position. Go back there, copying the current subject position - and mark, and the start_match position (\K might have changed it), and - then move on past the OP_RECURSE. */ - - P->eptr = Feptr; - P->mark = Fmark; - P->start_match = Fstart_match; - F = P; - Fecode += 1 + LINK_SIZE; - continue; - } - PCRE2_FALLTHROUGH /* Fall through */ - - /* OP_END itself can never be reached within a recursion because that is - picked up when the OP_KET that always precedes OP_END is reached. */ - - case OP_END: - - /* Fail for an empty string match if either PCRE2_NOTEMPTY is set, or if - PCRE2_NOTEMPTY_ATSTART is set and we have matched at the start of the - subject. In both cases, backtracking will then try other alternatives, if - any. */ - - if (Feptr == Fstart_match && - ((mb->moptions & PCRE2_NOTEMPTY) != 0 || - ((mb->moptions & PCRE2_NOTEMPTY_ATSTART) != 0 && - Fstart_match == mb->start_subject + mb->start_offset))) - { -#ifdef DEBUG_SHOW_OPS - fprintf(stderr, "++ Backtrack because empty string\n"); -#endif - RRETURN(MATCH_NOMATCH); - } - - /* Fail if PCRE2_ENDANCHORED is set and the end of the match is not - the end of the subject. After (*ACCEPT) we fail the entire match (at this - position) but backtrack if we've reached the end of the pattern. This - applies whether or not we are in a recursion. */ - - if (Feptr < mb->end_subject && - ((mb->moptions | mb->poptions) & PCRE2_ENDANCHORED) != 0) - { - if (Fop == OP_END) - { -#ifdef DEBUG_SHOW_OPS - fprintf(stderr, "++ Backtrack because not at end (endanchored set)\n"); -#endif - RRETURN(MATCH_NOMATCH); - } - -#ifdef DEBUG_SHOW_OPS - fprintf(stderr, "++ Failed ACCEPT not at end (endanchored set)\n"); -#endif - return MATCH_NOMATCH; /* (*ACCEPT) */ - } - - /* Fail if we detect that the start position was moved to be either after - the end position (\K in lookahead) or before the start offset (\K in - lookbehind). If this occurs, the pattern must have used \K in a somewhat - sneaky way (e.g. by pattern recursion), because if the \K is actually - syntactically inside the lookaround, it's blocked at compile-time. */ - - if (Fstart_match < mb->start_subject + mb->start_offset || - Fstart_match > Feptr) - { - /* The \K expression is fairly rare. We assert it was used so that we - catch any unexpected invalid data in start_match. */ - PCRE2_ASSERT(mb->hasbsk); - - if (!mb->allowlookaroundbsk) - return PCRE2_ERROR_BAD_BACKSLASH_K; - } - - /* We have a successful match of the whole pattern. Record the result and - then do a direct return from the function. If there is space in the offset - vector, set any pairs that follow the highest-numbered captured string but - are less than the number of capturing groups in the pattern to PCRE2_UNSET. - It is documented that this happens. "Gaps" are set to PCRE2_UNSET - dynamically. It is only those at the end that need setting here. */ - - mb->end_match_ptr = Feptr; /* Record where we ended */ - mb->end_offset_top = Foffset_top; /* and how many extracts were taken */ - mb->mark = Fmark; /* and the last success mark */ - if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; - - match_data->ovector[0] = Fstart_match - mb->start_subject; - match_data->ovector[1] = Feptr - mb->start_subject; - - /* Set i to the smaller of the sizes of the external and frame ovectors. */ - - i = 2 * ((top_bracket + 1 > match_data->oveccount)? - match_data->oveccount : top_bracket + 1); - memcpy(match_data->ovector + 2, Fovector, (i - 2) * sizeof(PCRE2_SIZE)); - while (--i >= Foffset_top + 2) match_data->ovector[i] = PCRE2_UNSET; - return MATCH_MATCH; /* Note: NOT RRETURN */ - - - /*===================================================================== */ - /* Match any single character type except newline; have to take care with - CRLF newlines and partial matching. */ - - case OP_ANY: - if (IS_NEWLINE(Feptr)) RRETURN(MATCH_NOMATCH); - if (mb->partial != 0 && - Feptr == mb->end_subject - 1 && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - UCHAR21TEST(Feptr) == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - PCRE2_FALLTHROUGH /* Fall through */ - - /* Match any single character whatsoever. */ - - case OP_ALLANY: - if (Feptr >= mb->end_subject) /* DO NOT merge the Feptr++ here; it must */ - { /* not be updated before SCHECK_PARTIAL. */ - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - Feptr++; -#ifdef SUPPORT_UNICODE - if (utf) ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); -#endif - Fecode++; - break; - - - /* ===================================================================== */ - /* Match a single code unit, even in UTF mode. This opcode really does - match any code unit, even newline. (It really should be called ANYCODEUNIT, - of course - the byte name is from pre-16 bit days.) */ - - case OP_ANYBYTE: - if (Feptr >= mb->end_subject) /* DO NOT merge the Feptr++ here; it must */ - { /* not be updated before SCHECK_PARTIAL. */ - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - Feptr++; - Fecode++; - break; - - - /* ===================================================================== */ - /* Match a single character, casefully */ - - case OP_CHAR: -#ifdef SUPPORT_UNICODE - if (utf) - { - Flength = 1; - Fecode++; - GETCHARLEN(fc, Fecode, Flength); - if (Flength > (PCRE2_SIZE)(mb->end_subject - Feptr)) - { - CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ - RRETURN(MATCH_NOMATCH); - } - for (; Flength > 0; Flength--) - { - if (*Fecode++ != UCHAR21INC(Feptr)) RRETURN(MATCH_NOMATCH); - } - } - else -#endif - - /* Not UTF mode */ - { - if (mb->end_subject - Feptr < 1) - { - SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ - RRETURN(MATCH_NOMATCH); - } - if (Fecode[1] != *Feptr++) RRETURN(MATCH_NOMATCH); - Fecode += 2; - } - break; - - - /* ===================================================================== */ - /* Match a single character, caselessly. If we are at the end of the - subject, give up immediately. We get here only when the pattern character - has at most one other case. Characters with more than two cases are coded - as OP_PROP with the pseudo-property PT_CLIST. */ - - case OP_CHARI: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - -#ifdef SUPPORT_UNICODE - if (utf) - { - Flength = 1; - Fecode++; - GETCHARLEN(fc, Fecode, Flength); - - /* If the pattern character's value is < 128, we know that its other case - (if any) is also < 128 (and therefore only one code unit long in all - code-unit widths), so we can use the fast lookup table. We checked above - that there is at least one character left in the subject. */ - - if (fc < 128) - { - uint32_t cc = UCHAR21(Feptr); - if (mb->lcc[fc] != TABLE_GET(cc, mb->lcc, cc)) RRETURN(MATCH_NOMATCH); - Fecode++; - Feptr++; - } - - /* Otherwise we must pick up the subject character and use Unicode - property support to test its other case. Note that we cannot use the - value of "Flength" to check for sufficient bytes left, because the other - case of the character may have more or fewer code units. */ - - else - { - uint32_t dc; - GETCHARINC(dc, Feptr); - Fecode += Flength; - if (dc != fc && dc != UCD_OTHERCASE(fc)) RRETURN(MATCH_NOMATCH); - } - } - - /* If UCP is set without UTF we must do the same as above, but with one - character per code unit. */ - - else if (ucp) - { - uint32_t cc = UCHAR21(Feptr); - fc = Fecode[1]; - if (fc < 128) - { - if (mb->lcc[fc] != TABLE_GET(cc, mb->lcc, cc)) RRETURN(MATCH_NOMATCH); - } - else - { - if (cc != fc && cc != UCD_OTHERCASE(fc)) RRETURN(MATCH_NOMATCH); - } - Feptr++; - Fecode += 2; - } - - else -#endif /* SUPPORT_UNICODE */ - - /* Not UTF or UCP mode; use the table for characters < 256. */ - { - if (TABLE_GET(Fecode[1], mb->lcc, Fecode[1]) - != TABLE_GET(*Feptr, mb->lcc, *Feptr)) RRETURN(MATCH_NOMATCH); - Feptr++; - Fecode += 2; - } - break; - - - /* ===================================================================== */ - /* Match not a single character. */ - - case OP_NOT: - case OP_NOTI: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - -#ifdef SUPPORT_UNICODE - if (utf) - { - uint32_t ch; - Fecode++; - GETCHARINC(ch, Fecode); - GETCHARINC(fc, Feptr); - if (ch == fc) - { - RRETURN(MATCH_NOMATCH); /* Caseful match */ - } - else if (Fop == OP_NOTI) /* If caseless */ - { - if (ch > 127) - ch = UCD_OTHERCASE(ch); - else - ch = (mb->fcc)[ch]; - if (ch == fc) RRETURN(MATCH_NOMATCH); - } - } - - /* UCP without UTF is as above, but with one character per code unit. */ - - else if (ucp) - { - uint32_t ch; - fc = UCHAR21INC(Feptr); - ch = Fecode[1]; - Fecode += 2; - - if (ch == fc) - { - RRETURN(MATCH_NOMATCH); /* Caseful match */ - } - else if (Fop == OP_NOTI) /* If caseless */ - { - if (ch > 127) - ch = UCD_OTHERCASE(ch); - else - ch = (mb->fcc)[ch]; - if (ch == fc) RRETURN(MATCH_NOMATCH); - } - } - - else -#endif /* SUPPORT_UNICODE */ - - /* Neither UTF nor UCP is set */ - - { - uint32_t ch = Fecode[1]; - fc = UCHAR21INC(Feptr); - if (ch == fc || (Fop == OP_NOTI && TABLE_GET(ch, mb->fcc, ch) == fc)) - RRETURN(MATCH_NOMATCH); - Fecode += 2; - } - break; - - - /* ===================================================================== */ - /* Match a single character repeatedly. */ - -#define Loclength F->temp_size -#define Lstart_eptr F->temp_sptr[0] -#define Lcharptr F->temp_sptr[1] -#define Lmin F->temp_32[0] -#define Lmax F->temp_32[1] -#define Lc F->temp_32[2] -#define Loc F->temp_32[3] - - case OP_EXACT: - case OP_EXACTI: - Lmin = Lmax = GET2(Fecode, 1); - Fecode += 1 + IMM2_SIZE; - goto REPEATCHAR; - - case OP_POSUPTO: - case OP_POSUPTOI: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = GET2(Fecode, 1); - Fecode += 1 + IMM2_SIZE; - goto REPEATCHAR; - - case OP_UPTO: - case OP_UPTOI: - reptype = REPTYPE_MAX; - Lmin = 0; - Lmax = GET2(Fecode, 1); - Fecode += 1 + IMM2_SIZE; - goto REPEATCHAR; - - case OP_MINUPTO: - case OP_MINUPTOI: - reptype = REPTYPE_MIN; - Lmin = 0; - Lmax = GET2(Fecode, 1); - Fecode += 1 + IMM2_SIZE; - goto REPEATCHAR; - - case OP_POSSTAR: - case OP_POSSTARI: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = UINT32_MAX; - Fecode++; - goto REPEATCHAR; - - case OP_POSPLUS: - case OP_POSPLUSI: - reptype = REPTYPE_POS; - Lmin = 1; - Lmax = UINT32_MAX; - Fecode++; - goto REPEATCHAR; - - case OP_POSQUERY: - case OP_POSQUERYI: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = 1; - Fecode++; - goto REPEATCHAR; - - case OP_STAR: - case OP_STARI: - case OP_MINSTAR: - case OP_MINSTARI: - case OP_PLUS: - case OP_PLUSI: - case OP_MINPLUS: - case OP_MINPLUSI: - case OP_QUERY: - case OP_QUERYI: - case OP_MINQUERY: - case OP_MINQUERYI: - fc = *Fecode++ - ((Fop < OP_STARI)? OP_STAR : OP_STARI); - Lmin = rep_min[fc]; - Lmax = rep_max[fc]; - reptype = rep_typ[fc]; - - /* Common code for all repeated single-character matches. We first check - for the minimum number of characters. If the minimum equals the maximum, we - are done. Otherwise, if minimizing, check the rest of the pattern for a - match; if there isn't one, advance up to the maximum, one character at a - time. - - If maximizing, advance up to the maximum number of matching characters, - until Feptr is past the end of the maximum run. If possessive, we are - then done (no backing up). Otherwise, match at this position; anything - other than no match is immediately returned. For nomatch, back up one - character, unless we are matching \R and the last thing matched was - \r\n, in which case, back up two code units until we reach the first - optional character position. - - The various UTF/non-UTF and caseful/caseless cases are handled separately, - for speed. */ - - REPEATCHAR: -#ifdef SUPPORT_UNICODE - if (utf) - { - Flength = 1; - Lcharptr = Fecode; - GETCHARLEN(fc, Fecode, Flength); - Fecode += Flength; - - /* Handle multi-code-unit character matching, caseful and caseless. */ - - if (Flength > 1) - { - uint32_t othercase; - - if (Fop >= OP_STARI && /* Caseless */ - (othercase = UCD_OTHERCASE(fc)) != fc) - Loclength = PRIV(ord2utf)(othercase, Foccu); - else Loclength = 0; - - for (i = 1; i <= Lmin; i++) - { - if (Feptr <= mb->end_subject - Flength && - memcmp(Feptr, Lcharptr, CU2BYTES(Flength)) == 0) Feptr += Flength; - else if (Loclength > 0 && - Feptr <= mb->end_subject - Loclength && - memcmp(Feptr, Foccu, CU2BYTES(Loclength)) == 0) - Feptr += Loclength; - else - { - CHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - } - - if (Lmin == Lmax) continue; - - if (reptype == REPTYPE_MIN) - { - for (;;) - { - RMATCH(Fecode, RM202); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr <= mb->end_subject - Flength && - memcmp(Feptr, Lcharptr, CU2BYTES(Flength)) == 0) Feptr += Flength; - else if (Loclength > 0 && - Feptr <= mb->end_subject - Loclength && - memcmp(Feptr, Foccu, CU2BYTES(Loclength)) == 0) - Feptr += Loclength; - else - { - CHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - - else /* Maximize */ - { - Lstart_eptr = Feptr; - for (i = Lmin; i < Lmax; i++) - { - if (Feptr <= mb->end_subject - Flength && - memcmp(Feptr, Lcharptr, CU2BYTES(Flength)) == 0) - Feptr += Flength; - else if (Loclength > 0 && - Feptr <= mb->end_subject - Loclength && - memcmp(Feptr, Foccu, CU2BYTES(Loclength)) == 0) - Feptr += Loclength; - else - { - CHECK_PARTIAL(); - break; - } - } - - /* After \C in UTF mode, Lstart_eptr might be in the middle of a - Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't - go too far. */ - - if (reptype != REPTYPE_POS) for(;;) - { - if (Feptr <= Lstart_eptr) break; - RMATCH(Fecode, RM203); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - BACKCHAR(Feptr); - } - } - break; /* End of repeated wide character handling */ - } - - /* Length of UTF character is 1. Put it into the preserved variable and - fall through to the non-UTF code. */ - - Lc = fc; - } - else -#endif /* SUPPORT_UNICODE */ - - /* When not in UTF mode, load a single-code-unit character. Then proceed as - above, using Unicode casing if either UTF or UCP is set. */ - - Lc = *Fecode++; - - /* Caseless comparison */ - - if (Fop >= OP_STARI) - { -#if PCRE2_CODE_UNIT_WIDTH == 8 -#ifdef SUPPORT_UNICODE - if (ucp && !utf && Lc > 127) Loc = UCD_OTHERCASE(Lc); - else -#endif /* SUPPORT_UNICODE */ - /* Lc will be < 128 in UTF-8 mode. */ - Loc = mb->fcc[Lc]; -#else /* 16-bit & 32-bit */ -#ifdef SUPPORT_UNICODE - if ((utf || ucp) && Lc > 127) Loc = UCD_OTHERCASE(Lc); - else -#endif /* SUPPORT_UNICODE */ - Loc = TABLE_GET(Lc, mb->fcc, Lc); -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - - for (i = 1; i <= Lmin; i++) - { - uint32_t cc; /* Faster than PCRE2_UCHAR */ - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - cc = UCHAR21TEST(Feptr); - if (Lc != cc && Loc != cc) RRETURN(MATCH_NOMATCH); - Feptr++; - } - if (Lmin == Lmax) continue; - - if (reptype == REPTYPE_MIN) - { - for (;;) - { - uint32_t cc; /* Faster than PCRE2_UCHAR */ - RMATCH(Fecode, RM25); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - cc = UCHAR21TEST(Feptr); - if (Lc != cc && Loc != cc) RRETURN(MATCH_NOMATCH); - Feptr++; - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - - else /* Maximize */ - { - Lstart_eptr = Feptr; - for (i = Lmin; i < Lmax; i++) - { - uint32_t cc; /* Faster than PCRE2_UCHAR */ - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - cc = UCHAR21TEST(Feptr); - if (Lc != cc && Loc != cc) break; - Feptr++; - } - if (reptype != REPTYPE_POS) for (;;) - { - if (Feptr == Lstart_eptr) break; - RMATCH(Fecode, RM26); - Feptr--; - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - } - } - } - - /* Caseful comparisons (includes all multi-byte characters) */ - - else - { - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (Lc != UCHAR21INCTEST(Feptr)) RRETURN(MATCH_NOMATCH); - } - - if (Lmin == Lmax) continue; - - if (reptype == REPTYPE_MIN) - { - for (;;) - { - RMATCH(Fecode, RM27); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (Lc != UCHAR21INCTEST(Feptr)) RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - else /* Maximize */ - { - Lstart_eptr = Feptr; - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - - if (Lc != UCHAR21TEST(Feptr)) break; - Feptr++; - } - - if (reptype != REPTYPE_POS) for (;;) - { - if (Feptr <= Lstart_eptr) break; - RMATCH(Fecode, RM28); - Feptr--; - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - } - } - } - break; - -#undef Loclength -#undef Lstart_eptr -#undef Lcharptr -#undef Lmin -#undef Lmax -#undef Lc -#undef Loc - - - /* ===================================================================== */ - /* Match a negated single one-byte character repeatedly. This is almost a - repeat of the code for a repeated single character, but I haven't found a - nice way of commoning these up that doesn't require a test of the - positive/negative option for each character match. Maybe that wouldn't add - very much to the time taken, but character matching *is* what this is all - about... */ - -#define Lstart_eptr F->temp_sptr[0] -#define Lmin F->temp_32[0] -#define Lmax F->temp_32[1] -#define Lc F->temp_32[2] -#define Loc F->temp_32[3] - - case OP_NOTEXACT: - case OP_NOTEXACTI: - Lmin = Lmax = GET2(Fecode, 1); - Fecode += 1 + IMM2_SIZE; - goto REPEATNOTCHAR; - - case OP_NOTUPTO: - case OP_NOTUPTOI: - Lmin = 0; - Lmax = GET2(Fecode, 1); - reptype = REPTYPE_MAX; - Fecode += 1 + IMM2_SIZE; - goto REPEATNOTCHAR; - - case OP_NOTMINUPTO: - case OP_NOTMINUPTOI: - Lmin = 0; - Lmax = GET2(Fecode, 1); - reptype = REPTYPE_MIN; - Fecode += 1 + IMM2_SIZE; - goto REPEATNOTCHAR; - - case OP_NOTPOSSTAR: - case OP_NOTPOSSTARI: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = UINT32_MAX; - Fecode++; - goto REPEATNOTCHAR; - - case OP_NOTPOSPLUS: - case OP_NOTPOSPLUSI: - reptype = REPTYPE_POS; - Lmin = 1; - Lmax = UINT32_MAX; - Fecode++; - goto REPEATNOTCHAR; - - case OP_NOTPOSQUERY: - case OP_NOTPOSQUERYI: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = 1; - Fecode++; - goto REPEATNOTCHAR; - - case OP_NOTPOSUPTO: - case OP_NOTPOSUPTOI: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = GET2(Fecode, 1); - Fecode += 1 + IMM2_SIZE; - goto REPEATNOTCHAR; - - case OP_NOTSTAR: - case OP_NOTSTARI: - case OP_NOTMINSTAR: - case OP_NOTMINSTARI: - case OP_NOTPLUS: - case OP_NOTPLUSI: - case OP_NOTMINPLUS: - case OP_NOTMINPLUSI: - case OP_NOTQUERY: - case OP_NOTQUERYI: - case OP_NOTMINQUERY: - case OP_NOTMINQUERYI: - fc = *Fecode++ - ((Fop >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR); - Lmin = rep_min[fc]; - Lmax = rep_max[fc]; - reptype = rep_typ[fc]; - - /* Common code for all repeated single-character non-matches. */ - - REPEATNOTCHAR: - GETCHARINCTEST(Lc, Fecode); - - /* The code is duplicated for the caseless and caseful cases, for speed, - since matching characters is likely to be quite common. First, ensure the - minimum number of matches are present. If Lmin = Lmax, we are done. - Otherwise, if minimizing, keep trying the rest of the expression and - advancing one matching character if failing, up to the maximum. - Alternatively, if maximizing, find the maximum number of characters and - work backwards. */ - - if (Fop >= OP_NOTSTARI) /* Caseless */ - { -#ifdef SUPPORT_UNICODE - if ((utf || ucp) && Lc > 127) - Loc = UCD_OTHERCASE(Lc); - else -#endif /* SUPPORT_UNICODE */ - - Loc = TABLE_GET(Lc, mb->fcc, Lc); /* Other case from table */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - uint32_t d; - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(d, Feptr); - if (Lc == d || Loc == d) RRETURN(MATCH_NOMATCH); - } - } - else -#endif /* SUPPORT_UNICODE */ - - /* Not UTF mode */ - { - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (Lc == *Feptr || Loc == *Feptr) RRETURN(MATCH_NOMATCH); - Feptr++; - } - } - - if (Lmin == Lmax) continue; /* Finished for exact count */ - - if (reptype == REPTYPE_MIN) - { -#ifdef SUPPORT_UNICODE - if (utf) - { - uint32_t d; - for (;;) - { - RMATCH(Fecode, RM204); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(d, Feptr); - if (Lc == d || Loc == d) RRETURN(MATCH_NOMATCH); - } - } - else -#endif /*SUPPORT_UNICODE */ - - /* Not UTF mode */ - { - for (;;) - { - RMATCH(Fecode, RM29); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (Lc == *Feptr || Loc == *Feptr) RRETURN(MATCH_NOMATCH); - Feptr++; - } - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - - /* Maximize case */ - - else - { - Lstart_eptr = Feptr; - -#ifdef SUPPORT_UNICODE - if (utf) - { - uint32_t d; - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(d, Feptr, len); - if (Lc == d || Loc == d) break; - Feptr += len; - } - - /* After \C in UTF mode, Lstart_eptr might be in the middle of a - Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't - go too far. */ - - if (reptype != REPTYPE_POS) for(;;) - { - if (Feptr <= Lstart_eptr) break; - RMATCH(Fecode, RM205); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - BACKCHAR(Feptr); - } - } - else -#endif /* SUPPORT_UNICODE */ - - /* Not UTF mode */ - { - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (Lc == *Feptr || Loc == *Feptr) break; - Feptr++; - } - if (reptype != REPTYPE_POS) for (;;) - { - if (Feptr == Lstart_eptr) break; - RMATCH(Fecode, RM30); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - } - } - } - } - - /* Caseful comparisons */ - - else - { -#ifdef SUPPORT_UNICODE - if (utf) - { - uint32_t d; - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(d, Feptr); - if (Lc == d) RRETURN(MATCH_NOMATCH); - } - } - else -#endif - /* Not UTF mode */ - { - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (Lc == *Feptr++) RRETURN(MATCH_NOMATCH); - } - } - - if (Lmin == Lmax) continue; - - if (reptype == REPTYPE_MIN) - { -#ifdef SUPPORT_UNICODE - if (utf) - { - uint32_t d; - for (;;) - { - RMATCH(Fecode, RM206); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(d, Feptr); - if (Lc == d) RRETURN(MATCH_NOMATCH); - } - } - else -#endif - /* Not UTF mode */ - { - for (;;) - { - RMATCH(Fecode, RM31); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (Lc == *Feptr++) RRETURN(MATCH_NOMATCH); - } - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - - /* Maximize case */ - - else - { - Lstart_eptr = Feptr; - -#ifdef SUPPORT_UNICODE - if (utf) - { - uint32_t d; - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(d, Feptr, len); - if (Lc == d) break; - Feptr += len; - } - - /* After \C in UTF mode, Lstart_eptr might be in the middle of a - Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't - go too far. */ - - if (reptype != REPTYPE_POS) for(;;) - { - if (Feptr <= Lstart_eptr) break; - RMATCH(Fecode, RM207); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - BACKCHAR(Feptr); - } - } - else -#endif - /* Not UTF mode */ - { - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (Lc == *Feptr) break; - Feptr++; - } - if (reptype != REPTYPE_POS) for (;;) - { - if (Feptr == Lstart_eptr) break; - RMATCH(Fecode, RM32); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - } - } - } - } - break; - -#undef Lstart_eptr -#undef Lmin -#undef Lmax -#undef Lc -#undef Loc - - - /* ===================================================================== */ - /* Match a bit-mapped character class, possibly repeatedly. These opcodes - are used when all the characters in the class have values in the range - 0-255, and either the matching is caseful, or the characters are in the - range 0-127 when UTF processing is enabled. The only difference between - OP_CLASS and OP_NCLASS occurs when a data character outside the range is - encountered. */ - -#define Lmin F->temp_32[0] -#define Lmax F->temp_32[1] -#define Lstart_eptr F->temp_sptr[0] -#define Lbyte_map_address F->temp_sptr[1] -#define Lbyte_map ((const unsigned char *)Lbyte_map_address) - - case OP_NCLASS: - case OP_CLASS: - { - Lbyte_map_address = Fecode + 1; /* Save for matching */ - Fecode += 1 + (32 / sizeof(PCRE2_UCHAR)); /* Advance past the item */ - - /* Look past the end of the item to see if there is repeat information - following. Then obey similar code to character type repeats. */ - - switch (*Fecode) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSSTAR: - case OP_CRPOSPLUS: - case OP_CRPOSQUERY: - fc = *Fecode++ - OP_CRSTAR; - Lmin = rep_min[fc]; - Lmax = rep_max[fc]; - reptype = rep_typ[fc]; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - Lmin = GET2(Fecode, 1); - Lmax = GET2(Fecode, 1 + IMM2_SIZE); - if (Lmax == 0) Lmax = UINT32_MAX; /* Max 0 => infinity */ - reptype = rep_typ[*Fecode - OP_CRSTAR]; - Fecode += 1 + 2 * IMM2_SIZE; - break; - - default: /* No repeat follows */ - Lmin = Lmax = 1; - break; - } - - /* First, ensure the minimum number of matches are present. */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(fc, Feptr); - if (fc > 255) - { - if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH); - } - else - if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH); - } - } - else -#endif - /* Not UTF mode */ - { - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - fc = *Feptr++; -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (fc > 255) - { - if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH); - } - else -#endif - if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH); - } - } - - /* If Lmax == Lmin we are done. Continue with main loop. */ - - if (Lmin == Lmax) continue; - - /* If minimizing, keep testing the rest of the expression and advancing - the pointer while it matches the class. */ - - if (reptype == REPTYPE_MIN) - { -#ifdef SUPPORT_UNICODE - if (utf) - { - for (;;) - { - RMATCH(Fecode, RM200); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(fc, Feptr); - if (fc > 255) - { - if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH); - } - else - if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH); - } - } - else -#endif - /* Not UTF mode */ - { - for (;;) - { - RMATCH(Fecode, RM23); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - fc = *Feptr++; -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (fc > 255) - { - if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH); - } - else -#endif - if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH); - } - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - - /* If maximizing, find the longest possible run, then work backwards. */ - - else - { - Lstart_eptr = Feptr; - -#ifdef SUPPORT_UNICODE - if (utf) - { - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - if (fc > 255) - { - if (Fop == OP_CLASS) break; - } - else - if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) break; - Feptr += len; - } - - if (reptype == REPTYPE_POS) continue; /* No backtracking */ - - /* After \C in UTF mode, Lstart_eptr might be in the middle of a - Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't - go too far. */ - - for (;;) - { - RMATCH(Fecode, RM201); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Feptr-- <= Lstart_eptr) break; /* Tried at original position */ - BACKCHAR(Feptr); - } - } - else -#endif - /* Not UTF mode */ - { - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - fc = *Feptr; -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (fc > 255) - { - if (Fop == OP_CLASS) break; - } - else -#endif - if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) break; - Feptr++; - } - - if (reptype == REPTYPE_POS) continue; /* No backtracking */ - - while (Feptr >= Lstart_eptr) - { - RMATCH(Fecode, RM24); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - } - } - - RRETURN(MATCH_NOMATCH); - } - } - - PCRE2_UNREACHABLE(); /* Control never reaches here */ - -#undef Lbyte_map_address -#undef Lbyte_map -#undef Lstart_eptr -#undef Lmin -#undef Lmax - - - /* ===================================================================== */ - /* Match an extended character class. In the 8-bit library, this opcode is - encountered only when UTF-8 mode mode is supported. In the 16-bit and - 32-bit libraries, codepoints greater than 255 may be encountered even when - UTF is not supported. */ - -#define Lstart_eptr F->temp_sptr[0] -#define Lxclass_data F->temp_sptr[1] -#define Lmin F->temp_32[0] -#define Lmax F->temp_32[1] - -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - { - Lxclass_data = Fecode + 1 + LINK_SIZE; /* Save for matching */ - Fecode += GET(Fecode, 1); /* Advance past the item */ - - switch (*Fecode) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSSTAR: - case OP_CRPOSPLUS: - case OP_CRPOSQUERY: - fc = *Fecode++ - OP_CRSTAR; - Lmin = rep_min[fc]; - Lmax = rep_max[fc]; - reptype = rep_typ[fc]; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - Lmin = GET2(Fecode, 1); - Lmax = GET2(Fecode, 1 + IMM2_SIZE); - if (Lmax == 0) Lmax = UINT32_MAX; /* Max 0 => infinity */ - reptype = rep_typ[*Fecode - OP_CRSTAR]; - Fecode += 1 + 2 * IMM2_SIZE; - break; - - default: /* No repeat follows */ - Lmin = Lmax = 1; - break; - } - - /* First, ensure the minimum number of matches are present. */ - - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (!PRIV(xclass)(fc, Lxclass_data, - (const uint8_t*)mb->start_code, utf)) - RRETURN(MATCH_NOMATCH); - } - - /* If Lmax == Lmin we can just continue with the main loop. */ - - if (Lmin == Lmax) continue; - - /* If minimizing, keep testing the rest of the expression and advancing - the pointer while it matches the class. */ - - if (reptype == REPTYPE_MIN) - { - for (;;) - { - RMATCH(Fecode, RM100); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (!PRIV(xclass)(fc, Lxclass_data, - (const uint8_t*)mb->start_code, utf)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - - /* If maximizing, find the longest possible run, then work backwards. */ - - else - { - Lstart_eptr = Feptr; - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } -#ifdef SUPPORT_UNICODE - GETCHARLENTEST(fc, Feptr, len); -#else - fc = *Feptr; -#endif - if (!PRIV(xclass)(fc, Lxclass_data, - (const uint8_t*)mb->start_code, utf)) break; - Feptr += len; - } - - if (reptype == REPTYPE_POS) continue; /* No backtracking */ - - /* After \C in UTF mode, Lstart_eptr might be in the middle of a - Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't - go too far. */ - - for(;;) - { - RMATCH(Fecode, RM101); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Feptr-- <= Lstart_eptr) break; /* Tried at original position */ -#ifdef SUPPORT_UNICODE - if (utf) BACKCHAR(Feptr); -#endif - } - RRETURN(MATCH_NOMATCH); - } - - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } -#endif /* SUPPORT_WIDE_CHARS: end of XCLASS */ - -#undef Lstart_eptr -#undef Lxclass_data -#undef Lmin -#undef Lmax - - - /* ===================================================================== */ - /* Match a complex, set-based character class. This opcodes are used when - there is complex nesting or logical operations within the character - class. */ - -#define Lstart_eptr F->temp_sptr[0] -#define Leclass_data F->temp_sptr[1] -#define Leclass_len F->temp_size -#define Lmin F->temp_32[0] -#define Lmax F->temp_32[1] - -#ifdef SUPPORT_WIDE_CHARS - case OP_ECLASS: - { - Leclass_data = Fecode + 1 + LINK_SIZE; /* Save for matching */ - Fecode += GET(Fecode, 1); /* Advance past the item */ - Leclass_len = (PCRE2_SIZE)(Fecode - Leclass_data); - - switch (*Fecode) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSSTAR: - case OP_CRPOSPLUS: - case OP_CRPOSQUERY: - fc = *Fecode++ - OP_CRSTAR; - Lmin = rep_min[fc]; - Lmax = rep_max[fc]; - reptype = rep_typ[fc]; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - Lmin = GET2(Fecode, 1); - Lmax = GET2(Fecode, 1 + IMM2_SIZE); - if (Lmax == 0) Lmax = UINT32_MAX; /* Max 0 => infinity */ - reptype = rep_typ[*Fecode - OP_CRSTAR]; - Fecode += 1 + 2 * IMM2_SIZE; - break; - - default: /* No repeat follows */ - Lmin = Lmax = 1; - break; - } - - /* First, ensure the minimum number of matches are present. */ - - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len, - (const uint8_t*)mb->start_code, utf)) - RRETURN(MATCH_NOMATCH); - } - - /* If Lmax == Lmin we can just continue with the main loop. */ - - if (Lmin == Lmax) continue; - - /* If minimizing, keep testing the rest of the expression and advancing - the pointer while it matches the class. */ - - if (reptype == REPTYPE_MIN) - { - for (;;) - { - RMATCH(Fecode, RM102); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len, - (const uint8_t*)mb->start_code, utf)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - - /* If maximizing, find the longest possible run, then work backwards. */ - - else - { - Lstart_eptr = Feptr; - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } -#ifdef SUPPORT_UNICODE - GETCHARLENTEST(fc, Feptr, len); -#else - fc = *Feptr; -#endif - if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len, - (const uint8_t*)mb->start_code, utf)) - break; - Feptr += len; - } - - if (reptype == REPTYPE_POS) continue; /* No backtracking */ - - /* After \C in UTF mode, Lstart_eptr might be in the middle of a - Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't - go too far. */ - - for(;;) - { - RMATCH(Fecode, RM103); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Feptr-- <= Lstart_eptr) break; /* Tried at original position */ -#ifdef SUPPORT_UNICODE - if (utf) BACKCHAR(Feptr); -#endif - } - RRETURN(MATCH_NOMATCH); - } - - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } -#endif /* SUPPORT_WIDE_CHARS: end of ECLASS */ - -#undef Lstart_eptr -#undef Leclass_data -#undef Leclass_len -#undef Lmin -#undef Lmax - - - /* ===================================================================== */ - /* Match various character types when PCRE2_UCP is not set. These opcodes - are not generated when PCRE2_UCP is set - instead appropriate property - tests are compiled. */ - - case OP_NOT_DIGIT: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_digit) != 0) - RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - case OP_DIGIT: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_digit) == 0) - RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - case OP_NOT_WHITESPACE: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_space) != 0) - RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - case OP_WHITESPACE: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_space) == 0) - RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - case OP_NOT_WORDCHAR: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0) - RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - case OP_WORDCHAR: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_word) == 0) - RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - case OP_ANYNL: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - switch(fc) - { - default: RRETURN(MATCH_NOMATCH); - - case CHAR_CR: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - } - else if (UCHAR21TEST(Feptr) == CHAR_LF) Feptr++; - break; - - case CHAR_LF: - break; - - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#ifndef EBCDIC - case 0x2028: - case 0x2029: -#endif /* Not EBCDIC */ - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) RRETURN(MATCH_NOMATCH); - break; - } - Fecode++; - break; - - case OP_NOT_HSPACE: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - switch(fc) - { - HSPACE_CASES: RRETURN(MATCH_NOMATCH); /* Byte and multibyte cases */ - default: break; - } - Fecode++; - break; - - case OP_HSPACE: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - switch(fc) - { - HSPACE_CASES: break; /* Byte and multibyte cases */ - default: RRETURN(MATCH_NOMATCH); - } - Fecode++; - break; - - case OP_NOT_VSPACE: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - switch(fc) - { - VSPACE_CASES: RRETURN(MATCH_NOMATCH); - default: break; - } - Fecode++; - break; - - case OP_VSPACE: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - switch(fc) - { - VSPACE_CASES: break; - default: RRETURN(MATCH_NOMATCH); - } - Fecode++; - break; - - -#ifdef SUPPORT_UNICODE - - /* ===================================================================== */ - /* Check the next character by Unicode property. We will get here only - if the support is in the binary; otherwise a compile-time error occurs. */ - - case OP_PROP: - case OP_NOTPROP: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - { - const uint32_t *cp; - uint32_t chartype; - const ucd_record *prop = GET_UCD(fc); - BOOL notmatch = Fop == OP_NOTPROP; - - switch(Fecode[1]) - { - case PT_LAMP: - chartype = prop->chartype; - if ((chartype == ucp_Lu || - chartype == ucp_Ll || - chartype == ucp_Lt) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - - case PT_GC: - if ((Fecode[2] == PRIV(ucp_gentype)[prop->chartype]) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - - case PT_PC: - if ((Fecode[2] == prop->chartype) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - - case PT_SC: - if ((Fecode[2] == prop->script) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - - case PT_SCX: - { - BOOL ok = (Fecode[2] == prop->script || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Fecode[2]) != 0); - if (ok == notmatch) RRETURN(MATCH_NOMATCH); - } - break; - - /* These are specials */ - - case PT_ALNUM: - chartype = prop->chartype; - if ((PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - switch(fc) - { - HSPACE_CASES: - VSPACE_CASES: - if (notmatch) RRETURN(MATCH_NOMATCH); - break; - - default: - if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - } - break; - - case PT_WORD: - chartype = prop->chartype; - if ((PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N || - chartype == ucp_Mn || - chartype == ucp_Pc) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - - case PT_CLIST: -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (fc > MAX_UTF_CODE_POINT) - { - if (notmatch) break;; - RRETURN(MATCH_NOMATCH); - } -#endif - cp = PRIV(ucd_caseless_sets) + Fecode[2]; - for (;;) - { - if (fc < *cp) - { if (notmatch) break; else { RRETURN(MATCH_NOMATCH); } } - if (fc == *cp++) - { if (notmatch) { RRETURN(MATCH_NOMATCH); } else break; } - } - break; - - case PT_UCNC: - if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT || - fc == CHAR_GRAVE_ACCENT || (fc >= 0xa0 && fc <= 0xd7ff) || - fc >= 0xe000) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - - case PT_BIDICL: - if ((UCD_BIDICLASS_PROP(prop) == Fecode[2]) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - - case PT_BOOL: - { - BOOL ok = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), Fecode[2]) != 0; - if (ok == notmatch) RRETURN(MATCH_NOMATCH); - } - break; - - /* This should never occur */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - - Fecode += 3; - } - break; - - - /* ===================================================================== */ - /* Match an extended Unicode sequence. We will get here only if the support - is in the binary; otherwise a compile-time error occurs. */ - - case OP_EXTUNI: - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - else - { - GETCHARINCTEST(fc, Feptr); - Feptr = PRIV(extuni)(fc, Feptr, mb->start_subject, mb->end_subject, utf, - NULL); - } - CHECK_PARTIAL(); - Fecode++; - break; - -#endif /* SUPPORT_UNICODE */ - - - /* ===================================================================== */ - /* Match a single character type repeatedly. Note that the property type - does not need to be in a stack frame as it is not used within an RMATCH() - loop. */ - -#define Lstart_eptr F->temp_sptr[0] -#define Lmin F->temp_32[0] -#define Lmax F->temp_32[1] -#define Lctype F->temp_32[2] -#define Lpropvalue F->temp_32[3] - - case OP_TYPEEXACT: - Lmin = Lmax = GET2(Fecode, 1); - Fecode += 1 + IMM2_SIZE; - goto REPEATTYPE; - - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - Lmin = 0; - Lmax = GET2(Fecode, 1); - reptype = (*Fecode == OP_TYPEMINUPTO)? REPTYPE_MIN : REPTYPE_MAX; - Fecode += 1 + IMM2_SIZE; - goto REPEATTYPE; - - case OP_TYPEPOSSTAR: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = UINT32_MAX; - Fecode++; - goto REPEATTYPE; - - case OP_TYPEPOSPLUS: - reptype = REPTYPE_POS; - Lmin = 1; - Lmax = UINT32_MAX; - Fecode++; - goto REPEATTYPE; - - case OP_TYPEPOSQUERY: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = 1; - Fecode++; - goto REPEATTYPE; - - case OP_TYPEPOSUPTO: - reptype = REPTYPE_POS; - Lmin = 0; - Lmax = GET2(Fecode, 1); - Fecode += 1 + IMM2_SIZE; - goto REPEATTYPE; - - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - fc = *Fecode++ - OP_TYPESTAR; - Lmin = rep_min[fc]; - Lmax = rep_max[fc]; - reptype = rep_typ[fc]; - - /* Common code for all repeated character type matches. */ - - REPEATTYPE: - Lctype = *Fecode++; /* Code for the character type */ - -#ifdef SUPPORT_UNICODE - if (Lctype == OP_PROP || Lctype == OP_NOTPROP) - { - proptype = *Fecode++; - Lpropvalue = *Fecode++; - } - else proptype = -1; -#endif - - /* First, ensure the minimum number of matches are present. Use inline - code for maximizing the speed, and do the type test once at the start - (i.e. keep it out of the loops). As there are no calls to RMATCH in the - loops, we can use an ordinary variable for "notmatch". The code for UTF - mode is separated out for tidiness, except for Unicode property tests. */ - - if (Lmin > 0) - { -#ifdef SUPPORT_UNICODE - if (proptype >= 0) /* Property tests in all modes */ - { - BOOL notmatch = Lctype == OP_NOTPROP; - switch(proptype) - { - case PT_LAMP: - for (i = 1; i <= Lmin; i++) - { - int chartype; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - chartype = UCD_CHARTYPE(fc); - if ((chartype == ucp_Lu || - chartype == ucp_Ll || - chartype == ucp_Lt) == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - case PT_GC: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((UCD_CATEGORY(fc) == Lpropvalue) == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - case PT_PC: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((UCD_CHARTYPE(fc) == Lpropvalue) == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - case PT_SC: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((UCD_SCRIPT(fc) == Lpropvalue) == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - case PT_SCX: - for (i = 1; i <= Lmin; i++) - { - BOOL ok; - const ucd_record *prop; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - prop = GET_UCD(fc); - ok = (prop->script == Lpropvalue || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); - if (ok == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - case PT_ALNUM: - for (i = 1; i <= Lmin; i++) - { - int category; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - category = UCD_CATEGORY(fc); - if ((category == ucp_L || category == ucp_N) == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - switch(fc) - { - HSPACE_CASES: - VSPACE_CASES: - if (notmatch) RRETURN(MATCH_NOMATCH); - break; - - default: - if ((UCD_CATEGORY(fc) == ucp_Z) == notmatch) - RRETURN(MATCH_NOMATCH); - break; - } - } - break; - - case PT_WORD: - for (i = 1; i <= Lmin; i++) - { - int chartype, category; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - chartype = UCD_CHARTYPE(fc); - category = PRIV(ucp_gentype)[chartype]; - if ((category == ucp_L || category == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc) == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - case PT_CLIST: - for (i = 1; i <= Lmin; i++) - { - const uint32_t *cp; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (fc > MAX_UTF_CODE_POINT) - { - if (notmatch) continue; - RRETURN(MATCH_NOMATCH); - } -#endif - cp = PRIV(ucd_caseless_sets) + Lpropvalue; - for (;;) - { - if (fc < *cp) - { - if (notmatch) break; - RRETURN(MATCH_NOMATCH); - } - if (fc == *cp++) - { - if (notmatch) RRETURN(MATCH_NOMATCH); - break; - } - } - } - break; - - case PT_UCNC: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT || - fc == CHAR_GRAVE_ACCENT || (fc >= 0xa0 && fc <= 0xd7ff) || - fc >= 0xe000) == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - case PT_BIDICL: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((UCD_BIDICLASS(fc) == Lpropvalue) == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - case PT_BOOL: - for (i = 1; i <= Lmin; i++) - { - BOOL ok; - const ucd_record *prop; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - prop = GET_UCD(fc); - ok = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), Lpropvalue) != 0; - if (ok == notmatch) - RRETURN(MATCH_NOMATCH); - } - break; - - /* This should not occur */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - } - - /* Match extended Unicode sequences. We will get here only if the - support is in the binary; otherwise a compile-time error occurs. */ - - else if (Lctype == OP_EXTUNI) - { - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - else - { - GETCHARINCTEST(fc, Feptr); - Feptr = PRIV(extuni)(fc, Feptr, mb->start_subject, - mb->end_subject, utf, NULL); - } - CHECK_PARTIAL(); - } - } - else -#endif /* SUPPORT_UNICODE */ - -/* Handle all other cases in UTF mode */ - -#ifdef SUPPORT_UNICODE - if (utf) switch(Lctype) - { - case OP_ANY: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (IS_NEWLINE(Feptr)) RRETURN(MATCH_NOMATCH); - if (mb->partial != 0 && - Feptr + 1 >= mb->end_subject && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - UCHAR21(Feptr) == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - Feptr++; - ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); - } - break; - - case OP_ALLANY: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - Feptr++; - ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); - } - break; - - case OP_ANYBYTE: - if (Feptr > mb->end_subject - Lmin) RRETURN(MATCH_NOMATCH); - Feptr += Lmin; - break; - - case OP_ANYNL: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(fc, Feptr); - switch(fc) - { - default: RRETURN(MATCH_NOMATCH); - - case CHAR_CR: - if (Feptr < mb->end_subject && UCHAR21(Feptr) == CHAR_LF) Feptr++; - break; - - case CHAR_LF: - break; - - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#ifndef EBCDIC - case 0x2028: - case 0x2029: -#endif /* Not EBCDIC */ - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) RRETURN(MATCH_NOMATCH); - break; - } - } - break; - - case OP_NOT_HSPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(fc, Feptr); - switch(fc) - { - HSPACE_CASES: RRETURN(MATCH_NOMATCH); - default: break; - } - } - break; - - case OP_HSPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(fc, Feptr); - switch(fc) - { - HSPACE_CASES: break; - default: RRETURN(MATCH_NOMATCH); - } - } - break; - - case OP_NOT_VSPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(fc, Feptr); - switch(fc) - { - VSPACE_CASES: RRETURN(MATCH_NOMATCH); - default: break; - } - } - break; - - case OP_VSPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(fc, Feptr); - switch(fc) - { - VSPACE_CASES: break; - default: RRETURN(MATCH_NOMATCH); - } - } - break; - - case OP_NOT_DIGIT: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINC(fc, Feptr); - if (fc < 128 && (mb->ctypes[fc] & ctype_digit) != 0) - RRETURN(MATCH_NOMATCH); - } - break; - - case OP_DIGIT: - for (i = 1; i <= Lmin; i++) - { - uint32_t cc; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - cc = UCHAR21(Feptr); - if (cc >= 128 || (mb->ctypes[cc] & ctype_digit) == 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - /* No need to skip more code units - we know it has only one. */ - } - break; - - case OP_NOT_WHITESPACE: - for (i = 1; i <= Lmin; i++) - { - uint32_t cc; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - cc = UCHAR21(Feptr); - if (cc < 128 && (mb->ctypes[cc] & ctype_space) != 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); - } - break; - - case OP_WHITESPACE: - for (i = 1; i <= Lmin; i++) - { - uint32_t cc; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - cc = UCHAR21(Feptr); - if (cc >= 128 || (mb->ctypes[cc] & ctype_space) == 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - /* No need to skip more code units - we know it has only one. */ - } - break; - - case OP_NOT_WORDCHAR: - for (i = 1; i <= Lmin; i++) - { - uint32_t cc; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - cc = UCHAR21(Feptr); - if (cc < 128 && (mb->ctypes[cc] & ctype_word) != 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); - } - break; - - case OP_WORDCHAR: - for (i = 1; i <= Lmin; i++) - { - uint32_t cc; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - cc = UCHAR21(Feptr); - if (cc >= 128 || (mb->ctypes[cc] & ctype_word) == 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - /* No need to skip more code units - we know it has only one. */ - } - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } /* End switch(Lctype) */ - - else -#endif /* SUPPORT_UNICODE */ - - /* Code for the non-UTF case for minimum matching of operators other - than OP_PROP and OP_NOTPROP. */ - - switch(Lctype) - { - case OP_ANY: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (IS_NEWLINE(Feptr)) RRETURN(MATCH_NOMATCH); - if (mb->partial != 0 && - Feptr + 1 >= mb->end_subject && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - *Feptr == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - Feptr++; - } - break; - - case OP_ALLANY: - if (Feptr > mb->end_subject - Lmin) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - Feptr += Lmin; - break; - - /* This OP_ANYBYTE case will never be reached because \C gets turned - into OP_ALLANY in non-UTF mode. Cut out the code so that coverage - reports don't complain about it's never being used. */ - -/* case OP_ANYBYTE: -* if (Feptr > mb->end_subject - Lmin) -* { -* SCHECK_PARTIAL(); -* RRETURN(MATCH_NOMATCH); -* } -* Feptr += Lmin; -* break; -*/ - case OP_ANYNL: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - switch(*Feptr++) - { - default: RRETURN(MATCH_NOMATCH); - - case CHAR_CR: - if (Feptr < mb->end_subject && *Feptr == CHAR_LF) Feptr++; - break; - - case CHAR_LF: - break; - - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#if PCRE2_CODE_UNIT_WIDTH != 8 - case 0x2028: - case 0x2029: -#endif - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) RRETURN(MATCH_NOMATCH); - break; - } - } - break; - - case OP_NOT_HSPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - switch(*Feptr++) - { - default: break; - HSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - HSPACE_MULTIBYTE_CASES: -#endif - RRETURN(MATCH_NOMATCH); - } - } - break; - - case OP_HSPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - switch(*Feptr++) - { - default: RRETURN(MATCH_NOMATCH); - HSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - HSPACE_MULTIBYTE_CASES: -#endif - break; - } - } - break; - - case OP_NOT_VSPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - switch(*Feptr++) - { - VSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - VSPACE_MULTIBYTE_CASES: -#endif - RRETURN(MATCH_NOMATCH); - default: break; - } - } - break; - - case OP_VSPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - switch(*Feptr++) - { - default: RRETURN(MATCH_NOMATCH); - VSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - VSPACE_MULTIBYTE_CASES: -#endif - break; - } - } - break; - - case OP_NOT_DIGIT: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_digit) != 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - } - break; - - case OP_DIGIT: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_digit) == 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - } - break; - - case OP_NOT_WHITESPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_space) != 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - } - break; - - case OP_WHITESPACE: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_space) == 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - } - break; - - case OP_NOT_WORDCHAR: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_word) != 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - } - break; - - case OP_WORDCHAR: - for (i = 1; i <= Lmin; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_word) == 0) - RRETURN(MATCH_NOMATCH); - Feptr++; - } - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - } - - /* If Lmin = Lmax we are done. Continue with the main loop. */ - - if (Lmin == Lmax) continue; - - /* If minimizing, we have to test the rest of the pattern before each - subsequent match. This means we cannot use a local "notmatch" variable as - in the other cases. As all 4 temporary 32-bit values in the frame are - already in use, just test the type each time. */ - - if (reptype == REPTYPE_MIN) - { -#ifdef SUPPORT_UNICODE - if (proptype >= 0) - { - switch(proptype) - { - case PT_LAMP: - for (;;) - { - int chartype; - RMATCH(Fecode, RM208); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - chartype = UCD_CHARTYPE(fc); - if ((chartype == ucp_Lu || - chartype == ucp_Ll || - chartype == ucp_Lt) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_GC: - for (;;) - { - RMATCH(Fecode, RM209); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((UCD_CATEGORY(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_PC: - for (;;) - { - RMATCH(Fecode, RM210); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((UCD_CHARTYPE(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_SC: - for (;;) - { - RMATCH(Fecode, RM211); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((UCD_SCRIPT(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_SCX: - for (;;) - { - BOOL ok; - const ucd_record *prop; - RMATCH(Fecode, RM224); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - prop = GET_UCD(fc); - ok = (prop->script == Lpropvalue - || MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); - if (ok == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_ALNUM: - for (;;) - { - int category; - RMATCH(Fecode, RM212); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - category = UCD_CATEGORY(fc); - if ((category == ucp_L || category == ucp_N) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - for (;;) - { - RMATCH(Fecode, RM213); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - switch(fc) - { - HSPACE_CASES: - VSPACE_CASES: - if (Lctype == OP_NOTPROP) RRETURN(MATCH_NOMATCH); - break; - - default: - if ((UCD_CATEGORY(fc) == ucp_Z) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - break; - } - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_WORD: - for (;;) - { - int chartype, category; - RMATCH(Fecode, RM214); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - chartype = UCD_CHARTYPE(fc); - category = PRIV(ucp_gentype)[chartype]; - if ((category == ucp_L || - category == ucp_N || - chartype == ucp_Mn || - chartype == ucp_Pc) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_CLIST: - for (;;) - { - const uint32_t *cp; - RMATCH(Fecode, RM215); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (fc > MAX_UTF_CODE_POINT) - { - if (Lctype == OP_NOTPROP) continue; - RRETURN(MATCH_NOMATCH); - } -#endif - cp = PRIV(ucd_caseless_sets) + Lpropvalue; - for (;;) - { - if (fc < *cp) - { - if (Lctype == OP_NOTPROP) break; - RRETURN(MATCH_NOMATCH); - } - if (fc == *cp++) - { - if (Lctype == OP_NOTPROP) RRETURN(MATCH_NOMATCH); - break; - } - } - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_UCNC: - for (;;) - { - RMATCH(Fecode, RM216); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT || - fc == CHAR_GRAVE_ACCENT || (fc >= 0xa0 && fc <= 0xd7ff) || - fc >= 0xe000) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_BIDICL: - for (;;) - { - RMATCH(Fecode, RM223); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - if ((UCD_BIDICLASS(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - case PT_BOOL: - for (;;) - { - BOOL ok; - const ucd_record *prop; - RMATCH(Fecode, RM222); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - GETCHARINCTEST(fc, Feptr); - prop = GET_UCD(fc); - ok = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), Lpropvalue) != 0; - if (ok == (Lctype == OP_NOTPROP)) - RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - - /* This should never occur */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - } - - /* Match extended Unicode sequences. We will get here only if the - support is in the binary; otherwise a compile-time error occurs. */ - - else if (Lctype == OP_EXTUNI) - { - for (;;) - { - RMATCH(Fecode, RM217); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - else - { - GETCHARINCTEST(fc, Feptr); - Feptr = PRIV(extuni)(fc, Feptr, mb->start_subject, mb->end_subject, - utf, NULL); - } - CHECK_PARTIAL(); - } - } - else -#endif /* SUPPORT_UNICODE */ - - /* UTF mode for non-property testing character types. */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - for (;;) - { - RMATCH(Fecode, RM218); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (Lctype == OP_ANY && IS_NEWLINE(Feptr)) RRETURN(MATCH_NOMATCH); - GETCHARINC(fc, Feptr); - switch(Lctype) - { - case OP_ANY: /* This is the non-NL case */ - if (mb->partial != 0 && /* Take care with CRLF partial */ - Feptr >= mb->end_subject && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - fc == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - break; - - case OP_ALLANY: - case OP_ANYBYTE: - break; - - case OP_ANYNL: - switch(fc) - { - default: RRETURN(MATCH_NOMATCH); - - case CHAR_CR: - if (Feptr < mb->end_subject && UCHAR21(Feptr) == CHAR_LF) Feptr++; - break; - - case CHAR_LF: - break; - - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#ifndef EBCDIC - case 0x2028: - case 0x2029: -#endif /* Not EBCDIC */ - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) - RRETURN(MATCH_NOMATCH); - break; - } - break; - - case OP_NOT_HSPACE: - switch(fc) - { - HSPACE_CASES: RRETURN(MATCH_NOMATCH); - default: break; - } - break; - - case OP_HSPACE: - switch(fc) - { - HSPACE_CASES: break; - default: RRETURN(MATCH_NOMATCH); - } - break; - - case OP_NOT_VSPACE: - switch(fc) - { - VSPACE_CASES: RRETURN(MATCH_NOMATCH); - default: break; - } - break; - - case OP_VSPACE: - switch(fc) - { - VSPACE_CASES: break; - default: RRETURN(MATCH_NOMATCH); - } - break; - - case OP_NOT_DIGIT: - if (fc < 256 && (mb->ctypes[fc] & ctype_digit) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_DIGIT: - if (fc >= 256 || (mb->ctypes[fc] & ctype_digit) == 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_NOT_WHITESPACE: - if (fc < 256 && (mb->ctypes[fc] & ctype_space) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_WHITESPACE: - if (fc >= 256 || (mb->ctypes[fc] & ctype_space) == 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_NOT_WORDCHAR: - if (fc < 256 && (mb->ctypes[fc] & ctype_word) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_WORDCHAR: - if (fc >= 256 || (mb->ctypes[fc] & ctype_word) == 0) - RRETURN(MATCH_NOMATCH); - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - } - } - else -#endif /* SUPPORT_UNICODE */ - - /* Not UTF mode */ - { - for (;;) - { - RMATCH(Fecode, RM33); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - if (Lctype == OP_ANY && IS_NEWLINE(Feptr)) - RRETURN(MATCH_NOMATCH); - fc = *Feptr++; - switch(Lctype) - { - case OP_ANY: /* This is the non-NL case */ - if (mb->partial != 0 && /* Take care with CRLF partial */ - Feptr >= mb->end_subject && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - fc == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - break; - - case OP_ALLANY: - case OP_ANYBYTE: - break; - - case OP_ANYNL: - switch(fc) - { - default: RRETURN(MATCH_NOMATCH); - - case CHAR_CR: - if (Feptr < mb->end_subject && *Feptr == CHAR_LF) Feptr++; - break; - - case CHAR_LF: - break; - - case CHAR_VT: - case CHAR_FF: - case CHAR_NEL: -#if PCRE2_CODE_UNIT_WIDTH != 8 - case 0x2028: - case 0x2029: -#endif - if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) - RRETURN(MATCH_NOMATCH); - break; - } - break; - - case OP_NOT_HSPACE: - switch(fc) - { - default: break; - HSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - HSPACE_MULTIBYTE_CASES: -#endif - RRETURN(MATCH_NOMATCH); - } - break; - - case OP_HSPACE: - switch(fc) - { - default: RRETURN(MATCH_NOMATCH); - HSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - HSPACE_MULTIBYTE_CASES: -#endif - break; - } - break; - - case OP_NOT_VSPACE: - switch(fc) - { - default: break; - VSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - VSPACE_MULTIBYTE_CASES: -#endif - RRETURN(MATCH_NOMATCH); - } - break; - - case OP_VSPACE: - switch(fc) - { - default: RRETURN(MATCH_NOMATCH); - VSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - VSPACE_MULTIBYTE_CASES: -#endif - break; - } - break; - - case OP_NOT_DIGIT: - if (MAX_255(fc) && (mb->ctypes[fc] & ctype_digit) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_DIGIT: - if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_digit) == 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_NOT_WHITESPACE: - if (MAX_255(fc) && (mb->ctypes[fc] & ctype_space) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_WHITESPACE: - if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_space) == 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_NOT_WORDCHAR: - if (MAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_WORDCHAR: - if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_word) == 0) - RRETURN(MATCH_NOMATCH); - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - } - } - - PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ - } - - /* If maximizing, it is worth using inline code for speed, doing the type - test once at the start (i.e. keep it out of the loops). Once again, - "notmatch" can be an ordinary local variable because the loops do not call - RMATCH. */ - - else - { - Lstart_eptr = Feptr; /* Remember where we started */ - -#ifdef SUPPORT_UNICODE - if (proptype >= 0) - { - BOOL notmatch = Lctype == OP_NOTPROP; - switch(proptype) - { - case PT_LAMP: - for (i = Lmin; i < Lmax; i++) - { - int chartype; - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - chartype = UCD_CHARTYPE(fc); - if ((chartype == ucp_Lu || - chartype == ucp_Ll || - chartype == ucp_Lt) == notmatch) - break; - Feptr+= len; - } - break; - - case PT_GC: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - if ((UCD_CATEGORY(fc) == Lpropvalue) == notmatch) break; - Feptr+= len; - } - break; - - case PT_PC: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - if ((UCD_CHARTYPE(fc) == Lpropvalue) == notmatch) break; - Feptr+= len; - } - break; - - case PT_SC: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - if ((UCD_SCRIPT(fc) == Lpropvalue) == notmatch) break; - Feptr+= len; - } - break; - - case PT_SCX: - for (i = Lmin; i < Lmax; i++) - { - BOOL ok; - const ucd_record *prop; - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - prop = GET_UCD(fc); - ok = (prop->script == Lpropvalue || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); - if (ok == notmatch) break; - Feptr+= len; - } - break; - - case PT_ALNUM: - for (i = Lmin; i < Lmax; i++) - { - int category; - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - category = UCD_CATEGORY(fc); - if ((category == ucp_L || category == ucp_N) == notmatch) - break; - Feptr+= len; - } - break; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - switch(fc) - { - HSPACE_CASES: - VSPACE_CASES: - if (notmatch) goto ENDLOOP99; /* Break the loop */ - break; - - default: - if ((UCD_CATEGORY(fc) == ucp_Z) == notmatch) - goto ENDLOOP99; /* Break the loop */ - break; - } - Feptr+= len; - } - ENDLOOP99: - break; - - case PT_WORD: - for (i = Lmin; i < Lmax; i++) - { - int chartype, category; - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - chartype = UCD_CHARTYPE(fc); - category = PRIV(ucp_gentype)[chartype]; - if ((category == ucp_L || - category == ucp_N || - chartype == ucp_Mn || - chartype == ucp_Pc) == notmatch) - break; - Feptr+= len; - } - break; - - case PT_CLIST: - for (i = Lmin; i < Lmax; i++) - { - const uint32_t *cp; - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); -#if PCRE2_CODE_UNIT_WIDTH == 32 - if (fc > MAX_UTF_CODE_POINT) - { - if (!notmatch) goto GOT_MAX; - } - else -#endif - { - cp = PRIV(ucd_caseless_sets) + Lpropvalue; - for (;;) - { - if (fc < *cp) - { if (notmatch) break; else goto GOT_MAX; } - if (fc == *cp++) - { if (notmatch) goto GOT_MAX; else break; } - } - } - - Feptr += len; - } - GOT_MAX: - break; - - case PT_UCNC: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT || - fc == CHAR_GRAVE_ACCENT || (fc >= 0xa0 && fc <= 0xd7ff) || - fc >= 0xe000) == notmatch) - break; - Feptr += len; - } - break; - - case PT_BIDICL: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - if ((UCD_BIDICLASS(fc) == Lpropvalue) == notmatch) break; - Feptr+= len; - } - break; - - case PT_BOOL: - for (i = Lmin; i < Lmax; i++) - { - BOOL ok; - const ucd_record *prop; - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLENTEST(fc, Feptr, len); - prop = GET_UCD(fc); - ok = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), Lpropvalue) != 0; - if (ok == notmatch) break; - Feptr+= len; - } - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - - /* Feptr is now past the end of the maximum run */ - - if (reptype == REPTYPE_POS) continue; /* No backtracking */ - - /* After \C in UTF mode, Lstart_eptr might be in the middle of a - Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't - go too far. */ - - for(;;) - { - if (Feptr <= Lstart_eptr) break; - RMATCH(Fecode, RM221); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - if (utf) BACKCHAR(Feptr); - } - } - - /* Match extended Unicode grapheme clusters. We will get here only if the - support is in the binary; otherwise a compile-time error occurs. */ - - else if (Lctype == OP_EXTUNI) - { - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - else - { - GETCHARINCTEST(fc, Feptr); - Feptr = PRIV(extuni)(fc, Feptr, mb->start_subject, mb->end_subject, - utf, NULL); - } - CHECK_PARTIAL(); - } - - /* Feptr is now past the end of the maximum run */ - - if (reptype == REPTYPE_POS) continue; /* No backtracking */ - - /* We use <= Lstart_eptr rather than == Lstart_eptr to detect the start - of the run while backtracking because the use of \C in UTF mode can - cause BACKCHAR to move back past Lstart_eptr. This is just palliative; - the use of \C in UTF mode is fraught with danger. */ - - for(;;) - { - int lgb, rgb; - PCRE2_SPTR fptr; - - if (Feptr <= Lstart_eptr) break; /* At start of char run */ - RMATCH(Fecode, RM219); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - - /* Backtracking over an extended grapheme cluster involves inspecting - the previous two characters (if present) to see if a break is - permitted between them. */ - - Feptr--; - if (!utf) fc = *Feptr; else - { - BACKCHAR(Feptr); - GETCHAR(fc, Feptr); - } - rgb = UCD_GRAPHBREAK(fc); - - for (;;) - { - if (Feptr <= Lstart_eptr) break; /* At start of char run */ - fptr = Feptr - 1; - if (!utf) fc = *fptr; else - { - BACKCHAR(fptr); - GETCHAR(fc, fptr); - } - lgb = UCD_GRAPHBREAK(fc); - if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break; - Feptr = fptr; - rgb = lgb; - } - } - } - - else -#endif /* SUPPORT_UNICODE */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - switch(Lctype) - { - case OP_ANY: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (IS_NEWLINE(Feptr)) break; - if (mb->partial != 0 && /* Take care with CRLF partial */ - Feptr + 1 >= mb->end_subject && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - UCHAR21(Feptr) == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - Feptr++; - ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); - } - break; - - case OP_ALLANY: - if (Lmax < UINT32_MAX) - { - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - Feptr++; - ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); - } - } - else - { - Feptr = mb->end_subject; /* Unlimited UTF-8 repeat */ - SCHECK_PARTIAL(); - } - break; - - /* The "byte" (i.e. "code unit") case is the same as non-UTF */ - - case OP_ANYBYTE: - fc = Lmax - Lmin; - if (fc > (uint32_t)(mb->end_subject - Feptr)) - { - Feptr = mb->end_subject; - SCHECK_PARTIAL(); - } - else Feptr += fc; - break; - - case OP_ANYNL: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - if (fc == CHAR_CR) - { - if (++Feptr >= mb->end_subject) break; - if (UCHAR21(Feptr) == CHAR_LF) Feptr++; - } - else - { - if (fc != CHAR_LF && - (mb->bsr_convention == PCRE2_BSR_ANYCRLF || - (fc != CHAR_VT && fc != CHAR_FF && fc != CHAR_NEL -#ifndef EBCDIC - && fc != 0x2028 && fc != 0x2029 -#endif /* Not EBCDIC */ - ))) - break; - Feptr += len; - } - } - break; - - case OP_NOT_HSPACE: - case OP_HSPACE: - for (i = Lmin; i < Lmax; i++) - { - BOOL gotspace; - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - switch(fc) - { - HSPACE_CASES: gotspace = TRUE; break; - default: gotspace = FALSE; break; - } - if (gotspace == (Lctype == OP_NOT_HSPACE)) break; - Feptr += len; - } - break; - - case OP_NOT_VSPACE: - case OP_VSPACE: - for (i = Lmin; i < Lmax; i++) - { - BOOL gotspace; - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - switch(fc) - { - VSPACE_CASES: gotspace = TRUE; break; - default: gotspace = FALSE; break; - } - if (gotspace == (Lctype == OP_NOT_VSPACE)) break; - Feptr += len; - } - break; - - case OP_NOT_DIGIT: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - if (fc < 256 && (mb->ctypes[fc] & ctype_digit) != 0) break; - Feptr+= len; - } - break; - - case OP_DIGIT: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - if (fc >= 256 ||(mb->ctypes[fc] & ctype_digit) == 0) break; - Feptr+= len; - } - break; - - case OP_NOT_WHITESPACE: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - if (fc < 256 && (mb->ctypes[fc] & ctype_space) != 0) break; - Feptr+= len; - } - break; - - case OP_WHITESPACE: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - if (fc >= 256 ||(mb->ctypes[fc] & ctype_space) == 0) break; - Feptr+= len; - } - break; - - case OP_NOT_WORDCHAR: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - if (fc < 256 && (mb->ctypes[fc] & ctype_word) != 0) break; - Feptr+= len; - } - break; - - case OP_WORDCHAR: - for (i = Lmin; i < Lmax; i++) - { - int len = 1; - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - GETCHARLEN(fc, Feptr, len); - if (fc >= 256 || (mb->ctypes[fc] & ctype_word) == 0) break; - Feptr+= len; - } - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - - if (reptype == REPTYPE_POS) continue; /* No backtracking */ - - /* After \C in UTF mode, Lstart_eptr might be in the middle of a - Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't go - too far. */ - - for(;;) - { - if (Feptr <= Lstart_eptr) break; - RMATCH(Fecode, RM220); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - BACKCHAR(Feptr); - if (Lctype == OP_ANYNL && Feptr > Lstart_eptr && - UCHAR21(Feptr) == CHAR_NL && UCHAR21(Feptr - 1) == CHAR_CR) - Feptr--; - } - } - else -#endif /* SUPPORT_UNICODE */ - - /* Not UTF mode */ - { - switch(Lctype) - { - case OP_ANY: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (IS_NEWLINE(Feptr)) break; - if (mb->partial != 0 && /* Take care with CRLF partial */ - Feptr + 1 >= mb->end_subject && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - *Feptr == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - Feptr++; - } - break; - - case OP_ALLANY: - case OP_ANYBYTE: - fc = Lmax - Lmin; - if (fc > (uint32_t)(mb->end_subject - Feptr)) - { - Feptr = mb->end_subject; - SCHECK_PARTIAL(); - } - else Feptr += fc; - break; - - case OP_ANYNL: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - fc = *Feptr; - if (fc == CHAR_CR) - { - if (++Feptr >= mb->end_subject) break; - if (*Feptr == CHAR_LF) Feptr++; - } - else - { - if (fc != CHAR_LF && (mb->bsr_convention == PCRE2_BSR_ANYCRLF || - (fc != CHAR_VT && fc != CHAR_FF && fc != CHAR_NEL -#if PCRE2_CODE_UNIT_WIDTH != 8 - && fc != 0x2028 && fc != 0x2029 -#endif - ))) break; - Feptr++; - } - } - break; - - case OP_NOT_HSPACE: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - switch(*Feptr) - { - default: Feptr++; break; - HSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - HSPACE_MULTIBYTE_CASES: -#endif - goto ENDLOOP00; - } - } - ENDLOOP00: - break; - - case OP_HSPACE: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - switch(*Feptr) - { - default: goto ENDLOOP01; - HSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - HSPACE_MULTIBYTE_CASES: -#endif - Feptr++; break; - } - } - ENDLOOP01: - break; - - case OP_NOT_VSPACE: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - switch(*Feptr) - { - default: Feptr++; break; - VSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - VSPACE_MULTIBYTE_CASES: -#endif - goto ENDLOOP02; - } - } - ENDLOOP02: - break; - - case OP_VSPACE: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - switch(*Feptr) - { - default: goto ENDLOOP03; - VSPACE_BYTE_CASES: -#if PCRE2_CODE_UNIT_WIDTH != 8 - VSPACE_MULTIBYTE_CASES: -#endif - Feptr++; break; - } - } - ENDLOOP03: - break; - - case OP_NOT_DIGIT: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_digit) != 0) - break; - Feptr++; - } - break; - - case OP_DIGIT: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_digit) == 0) - break; - Feptr++; - } - break; - - case OP_NOT_WHITESPACE: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_space) != 0) - break; - Feptr++; - } - break; - - case OP_WHITESPACE: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_space) == 0) - break; - Feptr++; - } - break; - - case OP_NOT_WORDCHAR: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_word) != 0) - break; - Feptr++; - } - break; - - case OP_WORDCHAR: - for (i = Lmin; i < Lmax; i++) - { - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - break; - } - if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_word) == 0) - break; - Feptr++; - } - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - - if (reptype == REPTYPE_POS) continue; /* No backtracking */ - - for (;;) - { - if (Feptr == Lstart_eptr) break; - RMATCH(Fecode, RM34); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr--; - if (Lctype == OP_ANYNL && Feptr > Lstart_eptr && *Feptr == CHAR_LF && - Feptr[-1] == CHAR_CR) Feptr--; - } - } - } - break; /* End of repeat character type processing */ - -#undef Lstart_eptr -#undef Lmin -#undef Lmax -#undef Lctype -#undef Lpropvalue - - - /* ===================================================================== */ - /* Match a back reference, possibly repeatedly. Look past the end of the - item to see if there is repeat information following. The OP_REF and - OP_REFI opcodes are used for a reference to a numbered group or to a - non-duplicated named group. For a duplicated named group, OP_DNREF and - OP_DNREFI are used. In this case we must scan the list of groups to which - the name refers, and use the first one that is set. */ - -#define Lmin F->temp_32[0] -#define Lmax F->temp_32[1] -#define Lcaseless F->temp_32[2] -#define Lcaseopts F->temp_32[3] -#define Lstart F->temp_sptr[0] -#define Loffset F->temp_size - - case OP_DNREF: - case OP_DNREFI: - Lcaseless = (Fop == OP_DNREFI); - Lcaseopts = (Fop == OP_DNREFI)? Fecode[1 + 2*IMM2_SIZE] : 0; - { - int count = GET2(Fecode, 1+IMM2_SIZE); - PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size; - Fecode += 1 + 2*IMM2_SIZE + (Fop == OP_DNREFI? 1 : 0); - - while (count-- > 0) - { - Loffset = (GET2(slot, 0) << 1) - 2; - if (Loffset < Foffset_top && Fovector[Loffset] != PCRE2_UNSET) break; - slot += mb->name_entry_size; - } - } - goto REF_REPEAT; - - case OP_REF: - case OP_REFI: - Lcaseless = (Fop == OP_REFI); - Lcaseopts = (Fop == OP_REFI)? Fecode[1 + IMM2_SIZE] : 0; - Loffset = (GET2(Fecode, 1) << 1) - 2; - Fecode += 1 + IMM2_SIZE + (Fop == OP_REFI? 1 : 0); - - /* Set up for repetition, or handle the non-repeated case. The maximum and - minimum must be in the heap frame, but as they are short-term values, we - use temporary fields. */ - - REF_REPEAT: - switch (*Fecode) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - fc = *Fecode++ - OP_CRSTAR; - Lmin = rep_min[fc]; - Lmax = rep_max[fc]; - reptype = rep_typ[fc]; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - Lmin = GET2(Fecode, 1); - Lmax = GET2(Fecode, 1 + IMM2_SIZE); - reptype = rep_typ[*Fecode - OP_CRSTAR]; - if (Lmax == 0) Lmax = UINT32_MAX; /* Max 0 => infinity */ - Fecode += 1 + 2 * IMM2_SIZE; - break; - - default: /* No repeat follows */ - { - rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &length); - if (rrc != 0) - { - if (rrc > 0) Feptr = mb->end_subject; /* Partial match */ - CHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - } - Feptr += length; - continue; /* With the main loop */ - } - - /* Handle repeated back references. If a set group has length zero, just - continue with the main loop, because it matches however many times. For an - unset reference, if the minimum is zero, we can also just continue. We can - also continue if PCRE2_MATCH_UNSET_BACKREF is set, because this makes unset - group behave as a zero-length group. For any other unset cases, carrying - on will result in NOMATCH. */ - - if (Loffset < Foffset_top && Fovector[Loffset] != PCRE2_UNSET) - { - if (Fovector[Loffset] == Fovector[Loffset + 1]) continue; - } - else /* Group is not set */ - { - if (Lmin == 0 || (mb->poptions & PCRE2_MATCH_UNSET_BACKREF) != 0) - continue; - } - - /* First, ensure the minimum number of matches are present. */ - - for (i = 1; i <= Lmin; i++) - { - PCRE2_SIZE slength; - rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength); - if (rrc != 0) - { - if (rrc > 0) Feptr = mb->end_subject; /* Partial match */ - CHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - Feptr += slength; - } - - /* If min = max, we are done. They are not both allowed to be zero. */ - - if (Lmin == Lmax) continue; - - /* If minimizing, keep trying and advancing the pointer. */ - - if (reptype == REPTYPE_MIN) - { - for (;;) - { - PCRE2_SIZE slength; - RMATCH(Fecode, RM20); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH); - rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength); - if (rrc != 0) - { - if (rrc > 0) Feptr = mb->end_subject; /* Partial match */ - CHECK_PARTIAL(); - RRETURN(MATCH_NOMATCH); - } - Feptr += slength; - } - - PCRE2_UNREACHABLE(); /* Control never reaches here */ - } - - /* If maximizing, find the longest string and work backwards, as long as - the matched lengths for each iteration are the same. */ - - else - { - BOOL samelengths = TRUE; - Lstart = Feptr; /* Starting position */ - Flength = Fovector[Loffset+1] - Fovector[Loffset]; - - for (i = Lmin; i < Lmax; i++) - { - PCRE2_SIZE slength; - rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength); - if (rrc != 0) - { - /* Can't use CHECK_PARTIAL because we don't want to update Feptr in - the soft partial matching case. */ - - if (rrc > 0 && mb->partial != 0 && - mb->end_subject > mb->start_used_ptr) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - break; - } - - if (slength != Flength) samelengths = FALSE; - Feptr += slength; - } - - /* If the length matched for each repetition is the same as the length of - the captured group, we can easily work backwards. This is the normal - case. However, in caseless UTF-8 mode there are pairs of case-equivalent - characters whose lengths (in terms of code units) differ. However, this - is very rare, so we handle it by re-matching fewer and fewer times. */ - - if (samelengths) - { - while (Feptr >= Lstart) - { - RMATCH(Fecode, RM21); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Feptr -= Flength; - } - } - - /* The rare case of non-matching lengths. Re-scan the repetition for each - iteration. We know that match_ref() will succeed every time. */ - - else - { - Lmax = i; - for (;;) - { - RMATCH(Fecode, RM22); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Feptr == Lstart) break; /* Failed after minimal repetition */ - Feptr = Lstart; - Lmax--; - for (i = Lmin; i < Lmax; i++) - { - PCRE2_SIZE slength; - (void)match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength); - Feptr += slength; - } - } - } - - RRETURN(MATCH_NOMATCH); - } - - PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ - -#undef Lcaseless -#undef Lmin -#undef Lmax -#undef Lstart -#undef Loffset - - - -/* ========================================================================= */ -/* Opcodes for the start of various parenthesized items */ -/* ========================================================================= */ - - /* In all cases, if the result of RMATCH() is MATCH_THEN, check whether the - (*THEN) is within the current branch by comparing the address of OP_THEN - that is passed back with the end of the branch. If (*THEN) is within the - current branch, and the branch is one of two or more alternatives (it - either starts or ends with OP_ALT), we have reached the limit of THEN's - action, so convert the return code to NOMATCH, which will cause normal - backtracking to happen from now on. Otherwise, THEN is passed back to an - outer alternative. This implements Perl's treatment of parenthesized - groups, where a group not containing | does not affect the current - alternative, that is, (X) is NOT the same as (X|(*F)). */ - - - /* ===================================================================== */ - /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a non-possessive - bracket group, indicating that it may occur zero times. It may repeat - infinitely, or not at all - i.e. it could be ()* or ()? or even (){0} in - the pattern. Brackets with fixed upper repeat limits are compiled as a - number of copies, with the optional ones preceded by BRAZERO or BRAMINZERO. - Possessive groups with possible zero repeats are preceded by BRAPOSZERO. */ - -#define Lnext_ecode F->temp_sptr[0] - - case OP_BRAZERO: - Lnext_ecode = Fecode + 1; - RMATCH(Lnext_ecode, RM9); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - do Lnext_ecode += GET(Lnext_ecode, 1); while (*Lnext_ecode == OP_ALT); - Fecode = Lnext_ecode + 1 + LINK_SIZE; - break; - - case OP_BRAMINZERO: - Lnext_ecode = Fecode + 1; - do Lnext_ecode += GET(Lnext_ecode, 1); while (*Lnext_ecode == OP_ALT); - RMATCH(Lnext_ecode + 1 + LINK_SIZE, RM10); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Fecode++; - break; - -#undef Lnext_ecode - - case OP_SKIPZERO: - Fecode++; - do Fecode += GET(Fecode,1); while (*Fecode == OP_ALT); - Fecode += 1 + LINK_SIZE; - break; - - - /* ===================================================================== */ - /* Handle possessive brackets with an unlimited repeat. The end of these - brackets will always be OP_KETRPOS, which returns MATCH_KETRPOS without - going further in the pattern. */ - -#define Lframe_type F->temp_32[0] -#define Lmatched_once F->temp_32[1] -#define Lzero_allowed F->temp_32[2] -#define Lstart_eptr F->temp_sptr[0] -#define Lstart_group F->temp_sptr[1] - - case OP_BRAPOSZERO: - Lzero_allowed = TRUE; /* Zero repeat is allowed */ - Fecode += 1; - if (*Fecode == OP_CBRAPOS || *Fecode == OP_SCBRAPOS) - goto POSSESSIVE_CAPTURE; - goto POSSESSIVE_NON_CAPTURE; - - case OP_BRAPOS: - case OP_SBRAPOS: - Lzero_allowed = FALSE; /* Zero repeat not allowed */ - - POSSESSIVE_NON_CAPTURE: - Lframe_type = GF_NOCAPTURE; /* Remembered frame type */ - goto POSSESSIVE_GROUP; - - case OP_CBRAPOS: - case OP_SCBRAPOS: - Lzero_allowed = FALSE; /* Zero repeat not allowed */ - - POSSESSIVE_CAPTURE: - number = GET2(Fecode, 1+LINK_SIZE); - Lframe_type = GF_CAPTURE | number; /* Remembered frame type */ - - POSSESSIVE_GROUP: - Lmatched_once = FALSE; /* Never matched */ - Lstart_group = Fecode; /* Start of this group */ - - for (;;) - { - Lstart_eptr = Feptr; /* Position at group start */ - group_frame_type = Lframe_type; - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM8); - if (rrc == MATCH_KETRPOS) - { - Lmatched_once = TRUE; /* Matched at least once */ - if (Feptr == Lstart_eptr) /* Empty match; skip to end */ - { - do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT); - break; - } - - Fecode = Lstart_group; - continue; - } - - /* See comment above about handling THEN. */ - - if (rrc == MATCH_THEN) - { - PCRE2_SPTR next_ecode = Fecode + GET(Fecode,1); - if (mb->verb_ecode_ptr < next_ecode && - (*Fecode == OP_ALT || *next_ecode == OP_ALT)) - rrc = MATCH_NOMATCH; - } - - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Fecode += GET(Fecode, 1); - if (*Fecode != OP_ALT) break; - } - - /* Success if matched something or zero repeat allowed */ - - if (Lmatched_once || Lzero_allowed) - { - Fecode += 1 + LINK_SIZE; - break; - } - - RRETURN(MATCH_NOMATCH); - -#undef Lmatched_once -#undef Lzero_allowed -#undef Lframe_type -#undef Lstart_eptr -#undef Lstart_group - - - /* ===================================================================== */ - /* Handle non-capturing brackets that cannot match an empty string. When we - get to the final alternative within the brackets, as long as there are no - THEN's in the pattern, we can optimize by not recording a new backtracking - point. (Ideally we should test for a THEN within this group, but we don't - have that information.) Don't do this if we are at the very top level, - however, because that would make handling assertions and once-only brackets - messier when there is nothing to go back to. */ - -#define Lframe_type F->temp_32[0] /* Set for all that use GROUPLOOP */ -#define Lnext_branch F->temp_sptr[0] /* Used only in OP_BRA handling */ - - case OP_BRA: - if (mb->hasthen || Frdepth == 0) - { - Lframe_type = 0; - goto GROUPLOOP; - } - - for (;;) - { - Lnext_branch = Fecode + GET(Fecode, 1); - if (*Lnext_branch != OP_ALT) break; - - /* This is never the final branch. We do not need to test for MATCH_THEN - here because this code is not used when there is a THEN in the pattern. */ - - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM1); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Fecode = Lnext_branch; - } - - /* Hit the start of the final branch. Continue at this level. */ - - Fecode += PRIV(OP_lengths)[*Fecode]; - break; - -#undef Lnext_branch - - - /* ===================================================================== */ - /* Handle a capturing bracket, other than those that are possessive with an - unlimited repeat. */ - - case OP_CBRA: - case OP_SCBRA: - Lframe_type = GF_CAPTURE | GET2(Fecode, 1+LINK_SIZE); - goto GROUPLOOP; - - - /* ===================================================================== */ - /* Atomic groups and non-capturing brackets that can match an empty string - must record a backtracking point and also set up a chained frame. */ - - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_SBRA: - Lframe_type = GF_NOCAPTURE | Fop; - - GROUPLOOP: - for (;;) - { - group_frame_type = Lframe_type; - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM2); - if (rrc == MATCH_THEN) - { - PCRE2_SPTR next_ecode = Fecode + GET(Fecode,1); - if (mb->verb_ecode_ptr < next_ecode && - (*Fecode == OP_ALT || *next_ecode == OP_ALT)) - rrc = MATCH_NOMATCH; - } - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Fecode += GET(Fecode, 1); - if (*Fecode != OP_ALT) RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - -#undef Lframe_type - - - /* ===================================================================== */ - /* Pattern recursion either matches the current regex, or some - subexpression. The offset data is the offset to the starting bracket from - the start of the whole pattern. This is so that it works from duplicated - subpatterns. For a whole-pattern recursion, we have to infer the number - zero. */ - -#define Lframe_type F->temp_32[0] -#define Lstart_branch F->temp_sptr[0] - - case OP_RECURSE: - bracode = mb->start_code + GET(Fecode, 1); - number = (bracode == mb->start_code)? 0 : GET2(bracode, 1 + LINK_SIZE); - - /* If we are already in a pattern recursion, check for repeating the same - one without changing the subject pointer or the last referenced character - in the subject. This should catch convoluted mutual recursions; some - simple cases are caught at compile time. However, there are rare cases when - this check needs to be turned off. In this case, actual recursion loops - will be caught by the match or heap limits. */ - - if (Fcurrent_recurse != RECURSE_UNSET) - { - offset = Flast_group_offset; - while (offset != PCRE2_UNSET) - { - N = (heapframe *)((char *)match_data->heapframes + offset); - P = (heapframe *)((char *)N - frame_size); - if (N->group_frame_type == (GF_RECURSE | number)) - { - if (Feptr == P->eptr && mb->last_used_ptr == P->recurse_last_used && - (mb->moptions & PCRE2_DISABLE_RECURSELOOP_CHECK) == 0) - return PCRE2_ERROR_RECURSELOOP; - break; - } - offset = P->last_group_offset; - } - } - - /* Remember the current last referenced character and then run the - recursion branch by branch. */ - - F->recurse_last_used = mb->last_used_ptr; - Lstart_branch = bracode; - Lframe_type = GF_RECURSE | number; - - for (;;) - { - PCRE2_SPTR next_ecode; - - group_frame_type = Lframe_type; - RMATCH(Lstart_branch + PRIV(OP_lengths)[*Lstart_branch], RM11); - next_ecode = Lstart_branch + GET(Lstart_branch,1); - - /* Handle backtracking verbs, which are defined in a range that can - easily be tested for. PCRE does not allow THEN, SKIP, PRUNE or COMMIT to - escape beyond a recursion; they cause a NOMATCH for the entire recursion. - - When one of these verbs triggers, the current recursion group number is - recorded. If it matches the recursion we are processing, the verb - happened within the recursion and we must deal with it. Otherwise it must - have happened after the recursion completed, and so has to be passed - back. See comment above about handling THEN. */ - - if (rrc >= MATCH_BACKTRACK_MIN && rrc <= MATCH_BACKTRACK_MAX && - mb->verb_current_recurse == (Lframe_type ^ GF_RECURSE)) - { - if (rrc == MATCH_THEN && mb->verb_ecode_ptr < next_ecode && - (*Lstart_branch == OP_ALT || *next_ecode == OP_ALT)) - rrc = MATCH_NOMATCH; - else RRETURN(MATCH_NOMATCH); - } - - /* Note that carrying on after (*ACCEPT) in a recursion is handled in the - OP_ACCEPT code. Nothing needs to be done here. */ - - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Lstart_branch = next_ecode; - if (*Lstart_branch != OP_ALT) RRETURN(MATCH_NOMATCH); - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - -#undef Lframe_type -#undef Lstart_branch - - - /* ===================================================================== */ - /* Positive assertions are like other groups except that PCRE doesn't allow - the effect of (*THEN) to escape beyond an assertion; it is therefore - treated as NOMATCH. (*ACCEPT) is treated as successful assertion, with its - captures and mark retained. Any other return is an error. */ - -#define Lframe_type F->temp_32[0] - - case OP_ASSERT: - case OP_ASSERTBACK: - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - Lframe_type = GF_NOCAPTURE | Fop; - for (;;) - { - group_frame_type = Lframe_type; - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM3); - if (rrc == MATCH_ACCEPT) - { - memcpy(Fovector, - (char *)assert_accept_frame + offsetof(heapframe, ovector), - assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); - Foffset_top = assert_accept_frame->offset_top; - Fmark = assert_accept_frame->mark; - break; - } - if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); - Fecode += GET(Fecode, 1); - if (*Fecode != OP_ALT) RRETURN(MATCH_NOMATCH); - } - - do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT); - Fecode += 1 + LINK_SIZE; - break; - -#undef Lframe_type - - - /* ===================================================================== */ - /* Handle negative assertions. Loop for each non-matching branch as for - positive assertions. */ - -#define Lframe_type F->temp_32[0] - - case OP_ASSERT_NOT: - case OP_ASSERTBACK_NOT: - Lframe_type = GF_NOCAPTURE | Fop; - - for (;;) - { - group_frame_type = Lframe_type; - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM4); - switch(rrc) - { - case MATCH_ACCEPT: /* Assertion matched, therefore it fails. */ - case MATCH_MATCH: - RRETURN (MATCH_NOMATCH); - - case MATCH_NOMATCH: /* Branch failed, try next if present. */ - case MATCH_THEN: - Fecode += GET(Fecode, 1); - if (*Fecode != OP_ALT) goto ASSERT_NOT_FAILED; - break; - - case MATCH_COMMIT: /* Assertion forced to fail, therefore continue. */ - case MATCH_SKIP: - case MATCH_PRUNE: - do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT); - goto ASSERT_NOT_FAILED; - - default: /* Pass back any other return */ - RRETURN(rrc); - } - } - - /* None of the branches have matched or there was a backtrack to (*COMMIT), - (*SKIP), (*PRUNE), or (*THEN) in the last branch. This is success for a - negative assertion, so carry on. */ - - ASSERT_NOT_FAILED: - Fecode += 1 + LINK_SIZE; - break; - -#undef Lframe_type - - /* ===================================================================== */ - /* Handle scan substring operation. */ - -#define Lframe_type F->temp_32[0] -#define Lextra_size F->temp_32[1] -#define Lsaved_moptions F->temp_32[2] -#define Lsaved_end_subject F->temp_sptr[0] -#define Lsaved_eptr F->temp_sptr[1] -#define Ltrue_end_extra F->temp_size - - case OP_ASSERT_SCS: - { - PCRE2_SPTR ecode = Fecode + 1 + LINK_SIZE; - uint32_t extra_size = 0; - int count; - PCRE2_SPTR slot; - - /* Disable compiler warning. */ - offset = 0; - (void)offset; - - for (;;) - { - if (*ecode == OP_CREF) - { - extra_size += 1+IMM2_SIZE; - offset = (GET2(ecode, 1) << 1) - 2; - ecode += 1+IMM2_SIZE; - if (offset < Foffset_top && Fovector[offset] != PCRE2_UNSET) - goto SCS_OFFSET_FOUND; - continue; - } - - if (*ecode != OP_DNCREF) RRETURN(MATCH_NOMATCH); - - count = GET2(ecode, 1 + IMM2_SIZE); - slot = mb->name_table + GET2(ecode, 1) * mb->name_entry_size; - extra_size += 1+2*IMM2_SIZE; - ecode += 1+2*IMM2_SIZE; - - while (count > 0) - { - offset = (GET2(slot, 0) << 1) - 2; - if (offset < Foffset_top && Fovector[offset] != PCRE2_UNSET) - goto SCS_OFFSET_FOUND; - slot += mb->name_entry_size; - count--; - } - } - - SCS_OFFSET_FOUND: - - /* Skip remaining options. */ - for (;;) - { - if (*ecode == OP_CREF) - { - extra_size += 1+IMM2_SIZE; - ecode += 1+IMM2_SIZE; - } - else if (*ecode == OP_DNCREF) - { - extra_size += 1+2*IMM2_SIZE; - ecode += 1+2*IMM2_SIZE; - } - else break; - } - - Lextra_size = extra_size; - } - - Lsaved_end_subject = mb->end_subject; - Ltrue_end_extra = mb->true_end_subject - mb->end_subject; - Lsaved_eptr = Feptr; - Lsaved_moptions = mb->moptions; - - Feptr = mb->start_subject + Fovector[offset]; - mb->true_end_subject = mb->end_subject = - mb->start_subject + Fovector[offset + 1]; - mb->moptions &= ~PCRE2_NOTEOL; - - Lframe_type = GF_NOCAPTURE | Fop; - for (;;) - { - group_frame_type = Lframe_type; - RMATCH(Fecode + 1 + LINK_SIZE + Lextra_size, RM38); - if (rrc == MATCH_ACCEPT) - { - memcpy(Fovector, - (char *)assert_accept_frame + offsetof(heapframe, ovector), - assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); - Foffset_top = assert_accept_frame->offset_top; - Fmark = assert_accept_frame->mark; - mb->end_subject = Lsaved_end_subject; - mb->true_end_subject = mb->end_subject + Ltrue_end_extra; - mb->moptions = Lsaved_moptions; - break; - } - - if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) - { - mb->end_subject = Lsaved_end_subject; - mb->true_end_subject = mb->end_subject + Ltrue_end_extra; - mb->moptions = Lsaved_moptions; - RRETURN(rrc); - } - - Fecode += GET(Fecode, 1); - if (*Fecode != OP_ALT) - { - mb->end_subject = Lsaved_end_subject; - mb->true_end_subject = mb->end_subject + Ltrue_end_extra; - mb->moptions = Lsaved_moptions; - RRETURN(MATCH_NOMATCH); - } - Lextra_size = 0; - } - - do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT); - Fecode += 1 + LINK_SIZE; - Feptr = Lsaved_eptr; - break; - -#undef Lframe_type -#undef Lextra_size -#undef Lsaved_end_subject -#undef Lsaved_eptr -#undef Ltrue_end_extra -#undef Lsave_moptions - - /* ===================================================================== */ - /* The callout item calls an external function, if one is provided, passing - details of the match so far. This is mainly for debugging, though the - function is able to force a failure. */ - - case OP_CALLOUT: - case OP_CALLOUT_STR: - rrc = do_callout(F, mb, &length); - if (rrc > 0) RRETURN(MATCH_NOMATCH); - if (rrc < 0) RRETURN(rrc); - Fecode += length; - break; - - - /* ===================================================================== */ - /* Conditional group: compilation checked that there are no more than two - branches. If the condition is false, skipping the first branch takes us - past the end of the item if there is only one branch, but that's exactly - what we want. */ - - case OP_COND: - case OP_SCOND: - - /* The variable Flength will be added to Fecode when the condition is - false, to get to the second branch. Setting it to the offset to the ALT or - KET, then incrementing Fecode achieves this effect. However, if the second - branch is non-existent, we must point to the KET so that the end of the - group is correctly processed. We now have Fecode pointing to the condition - or callout. */ - - Flength = GET(Fecode, 1); /* Offset to the second branch */ - if (Fecode[Flength] != OP_ALT) Flength -= 1 + LINK_SIZE; - Fecode += 1 + LINK_SIZE; /* From this opcode */ - - /* Because of the way auto-callout works during compile, a callout item is - inserted between OP_COND and an assertion condition. Such a callout can - also be inserted manually. */ - - if (*Fecode == OP_CALLOUT || *Fecode == OP_CALLOUT_STR) - { - rrc = do_callout(F, mb, &length); - if (rrc > 0) RRETURN(MATCH_NOMATCH); - if (rrc < 0) RRETURN(rrc); - - /* Advance Fecode past the callout, so it now points to the condition. We - must adjust Flength so that the value of Fecode+Flength is unchanged. */ - - Fecode += length; - Flength -= length; - } - - /* Test the various possible conditions */ - - condition = FALSE; - switch(*Fecode) - { - case OP_RREF: /* Group recursion test */ - if (Fcurrent_recurse != RECURSE_UNSET) - { - number = GET2(Fecode, 1); - condition = (number == RREF_ANY || number == Fcurrent_recurse); - } - break; - - case OP_DNRREF: /* Duplicate named group recursion test */ - if (Fcurrent_recurse != RECURSE_UNSET) - { - int count = GET2(Fecode, 1 + IMM2_SIZE); - PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size; - while (count-- > 0) - { - number = GET2(slot, 0); - condition = number == Fcurrent_recurse; - if (condition) break; - slot += mb->name_entry_size; - } - } - break; - - case OP_CREF: /* Numbered group used test */ - offset = (GET2(Fecode, 1) << 1) - 2; /* Doubled ref number */ - condition = offset < Foffset_top && Fovector[offset] != PCRE2_UNSET; - break; - - case OP_DNCREF: /* Duplicate named group used test */ - { - int count = GET2(Fecode, 1 + IMM2_SIZE); - PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size; - while (count-- > 0) - { - offset = (GET2(slot, 0) << 1) - 2; - condition = offset < Foffset_top && Fovector[offset] != PCRE2_UNSET; - if (condition) break; - slot += mb->name_entry_size; - } - } - break; - - case OP_FALSE: - case OP_FAIL: /* The assertion (?!) becomes OP_FAIL */ - break; - - case OP_TRUE: - condition = TRUE; - break; - - /* The condition is an assertion. Run code similar to the assertion code - above. */ - -#define Lpositive F->temp_32[0] -#define Lstart_branch F->temp_sptr[0] - - default: - Lpositive = (*Fecode == OP_ASSERT || *Fecode == OP_ASSERTBACK); - Lstart_branch = Fecode; - - for (;;) - { - group_frame_type = GF_CONDASSERT | *Fecode; - RMATCH(Lstart_branch + PRIV(OP_lengths)[*Lstart_branch], RM5); - - switch(rrc) - { - case MATCH_ACCEPT: /* Save captures */ - memcpy(Fovector, - (char *)assert_accept_frame + offsetof(heapframe, ovector), - assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); - Foffset_top = assert_accept_frame->offset_top; - - PCRE2_FALLTHROUGH /* Fall through */ - /* In the case of a match, the captures have already been put into - the current frame. */ - - case MATCH_MATCH: - condition = Lpositive; /* TRUE for positive assertion */ - break; - - /* PCRE doesn't allow the effect of (*THEN) to escape beyond an - assertion; it is therefore always treated as NOMATCH. */ - - case MATCH_NOMATCH: - case MATCH_THEN: - Lstart_branch += GET(Lstart_branch, 1); - if (*Lstart_branch == OP_ALT) continue; /* Try next branch */ - condition = !Lpositive; /* TRUE for negative assertion */ - break; - - /* These force no match without checking other branches. */ - - case MATCH_COMMIT: - case MATCH_SKIP: - case MATCH_PRUNE: - condition = !Lpositive; - break; - - default: - RRETURN(rrc); - } - break; /* Out of the branch loop */ - } - - /* If the condition is true, find the end of the assertion so that - advancing past it gets us to the start of the first branch. */ - - if (condition) - { - do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT); - } - break; /* End of assertion condition */ - } - -#undef Lpositive -#undef Lstart_branch - - /* Choose branch according to the condition. */ - - Fecode += condition? PRIV(OP_lengths)[*Fecode] : Flength; - - /* If the opcode is OP_SCOND it means we are at a repeated conditional - group that might match an empty string. We must therefore descend a level - so that the start is remembered for checking. For OP_COND we can just - continue at this level. */ - - if (Fop == OP_SCOND) - { - group_frame_type = GF_NOCAPTURE | Fop; - RMATCH(Fecode, RM35); - RRETURN(rrc); - } - break; - - - -/* ========================================================================= */ -/* End of start of parenthesis opcodes */ -/* ========================================================================= */ - - - /* ===================================================================== */ - /* Move the subject pointer back by one fixed amount. This occurs at the - start of each branch that has a fixed length in a lookbehind assertion. If - we are too close to the start to move back, fail. When working with UTF-8 - we move back a number of characters, not bytes. */ - - case OP_REVERSE: - number = GET2(Fecode, 1); -#ifdef SUPPORT_UNICODE - if (utf) - { - /* We used to do a simpler `while (number-- > 0)` but that triggers - clang's unsigned integer overflow sanitizer. */ - while (number > 0) - { - --number; - if (Feptr <= mb->check_subject) RRETURN(MATCH_NOMATCH); - Feptr--; - BACKCHAR(Feptr); - } - } - else -#endif - - /* No UTF support, or not in UTF mode: count is code unit count */ - - { - if ((ptrdiff_t)number > Feptr - mb->start_subject) RRETURN(MATCH_NOMATCH); - Feptr -= number; - } - - /* Save the earliest consulted character, then skip to next opcode */ - - if (Feptr < mb->start_used_ptr) mb->start_used_ptr = Feptr; - Fecode += 1 + IMM2_SIZE; - break; - - - /* ===================================================================== */ - /* Move the subject pointer back by a variable amount. This occurs at the - start of each branch of a lookbehind assertion when the branch has a - variable, but limited, length. A loop is needed to try matching the branch - after moving back different numbers of characters. If we are too close to - the start to move back even the minimum amount, fail. When working with - UTF-8 we move back a number of characters, not bytes. */ - -#define Lmin F->temp_32[0] -#define Lmax F->temp_32[1] -#define Leptr F->temp_sptr[0] - - case OP_VREVERSE: - Lmin = GET2(Fecode, 1); - Lmax = GET2(Fecode, 1 + IMM2_SIZE); - Leptr = Feptr; - - /* Move back by the maximum branch length and then work forwards. This - ensures that items such as \d{3,5} get the maximum length, which is - relevant for captures, and makes for Perl compatibility. */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - for (i = 0; i < Lmax; i++) - { - if (Feptr == mb->start_subject) - { - if (i < Lmin) RRETURN(MATCH_NOMATCH); - Lmax = i; - break; - } - Feptr--; - BACKCHAR(Feptr); - } - } - else -#endif - - /* No UTF support or not in UTF mode */ - - { - ptrdiff_t diff = Feptr - mb->start_subject; - uint32_t available = (diff > 65535)? 65535 : ((diff > 0)? (int)diff : 0); - if (Lmin > available) RRETURN(MATCH_NOMATCH); - if (Lmax > available) Lmax = available; - Feptr -= Lmax; - } - - /* Now try matching, moving forward one character on failure, until we - reach the minimum back length. */ - - for (;;) - { - RMATCH(Fecode + 1 + 2 * IMM2_SIZE, RM37); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (Lmax-- <= Lmin) RRETURN(MATCH_NOMATCH); - Feptr++; -#ifdef SUPPORT_UNICODE - if (utf) { FORWARDCHARTEST(Feptr, mb->end_subject); } -#endif - } - PCRE2_UNREACHABLE(); /* Control never reaches here */ - -#undef Lmin -#undef Lmax -#undef Leptr - - /* ===================================================================== */ - /* An alternation is the end of a branch; scan along to find the end of the - bracketed group. */ - - case OP_ALT: - branch_end = Fecode; - do Fecode += GET(Fecode,1); while (*Fecode == OP_ALT); - break; - - - /* ===================================================================== */ - /* The end of a parenthesized group. For all but OP_BRA and OP_COND, the - starting frame was added to the chained frames in order to remember the - starting subject position for the group. (Not true for OP_BRA when it's a - whole pattern recursion, but that is handled separately below.)*/ - - case OP_KET: - case OP_KETRMIN: - case OP_KETRMAX: - case OP_KETRPOS: - - bracode = Fecode - GET(Fecode, 1); - - if (branch_end == NULL) branch_end = Fecode; - branch_start = bracode; - while (branch_start + GET(branch_start, 1) != branch_end) - branch_start += GET(branch_start, 1); - branch_end = NULL; - - /* Point N to the frame at the start of the most recent group, and P to its - predecessor. Remember the subject pointer at the start of the group. */ - - if (*bracode != OP_BRA && *bracode != OP_COND) - { - N = (heapframe *)((char *)match_data->heapframes + Flast_group_offset); - P = (heapframe *)((char *)N - frame_size); - Flast_group_offset = P->last_group_offset; - -#ifdef DEBUG_SHOW_RMATCH - fprintf(stderr, "++ KET for frame=%d type=%x prev char offset=%lu\n", - N->rdepth, N->group_frame_type, - (char *)P->eptr - (char *)mb->start_subject); -#endif - - /* If we are at the end of an assertion that is a condition, first check - to see if we are at the end of a variable-length branch in a lookbehind. - If this is the case and we have not landed on the current character, - return no match. Compare code below for non-condition lookbehinds. In - other cases, return a match, discarding any intermediate backtracking - points. Copy back the mark setting and the captures into the frame before - N so that they are set on return. Doing this for all assertions, both - positive and negative, seems to match what Perl does. */ - - if (GF_IDMASK(N->group_frame_type) == GF_CONDASSERT) - { - if ((*bracode == OP_ASSERTBACK || *bracode == OP_ASSERTBACK_NOT) && - branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) - RRETURN(MATCH_NOMATCH); - memcpy((char *)P + offsetof(heapframe, ovector), Fovector, - Foffset_top * sizeof(PCRE2_SIZE)); - P->offset_top = Foffset_top; - P->mark = Fmark; - Fback_frame = (char *)F - (char *)P; - RRETURN(MATCH_MATCH); - } - } - else P = NULL; /* Indicates starting frame not recorded */ - - /* The group was not a conditional assertion. */ - - switch (*bracode) - { - /* Whole pattern recursion is handled as a recursion into group 0, but - the entire pattern is wrapped in OP_BRA/OP_KET rather than a capturing - group - a design mistake: it should perhaps have been capture group 0. - Anyway, that means the end of such recursion must be handled here. It is - detected by checking for an immediately following OP_END when we are - recursing in group 0. If this is not the end of a whole-pattern - recursion, there is nothing to be done. */ - - case OP_BRA: - if (Fcurrent_recurse != 0 || Fecode[1+LINK_SIZE] != OP_END) break; - - /* It is the end of whole-pattern recursion. */ - - offset = Flast_group_offset; - - /* Corrupted heapframes?. Trigger an assert and return an error */ - PCRE2_ASSERT(offset != PCRE2_UNSET); - if (offset == PCRE2_UNSET) return PCRE2_ERROR_INTERNAL; - - N = (heapframe *)((char *)match_data->heapframes + offset); - P = (heapframe *)((char *)N - frame_size); - Flast_group_offset = P->last_group_offset; - - /* Reinstate the previous set of captures and then carry on after the - recursion call. */ - - Fecode = P->ecode + 1 + LINK_SIZE; - - if (*Fecode != OP_CREF) - { - memcpy(F->ovector, P->ovector, Foffset_top * sizeof(PCRE2_SIZE)); - Foffset_top = P->offset_top; - } - else - recurse_update_offsets(F, P); - - Fcapture_last = P->capture_last; - Fcurrent_recurse = P->current_recurse; - continue; /* With next opcode */ - - case OP_COND: /* No need to do anything for these */ - case OP_SCOND: - break; - - /* Non-atomic positive assertions are like OP_BRA, except that the - subject pointer must be put back to where it was at the start of the - assertion. For a variable lookbehind, check its end point. */ - - case OP_ASSERTBACK_NA: - if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) - RRETURN(MATCH_NOMATCH); - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_ASSERT_NA: - if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; - Feptr = P->eptr; - break; - - /* Atomic positive assertions are like OP_ONCE, except that in addition - the subject pointer must be put back to where it was at the start of the - assertion. For a variable lookbehind, check its end point. */ - - case OP_ASSERTBACK: - if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) - RRETURN(MATCH_NOMATCH); - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_ASSERT: - if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; - Feptr = P->eptr; - PCRE2_FALLTHROUGH /* Fall through */ - - /* For an atomic group, discard internal backtracking points. We must - also ensure that any remaining branches within the top-level of the group - are not tried. Do this by adjusting the code pointer within the backtrack - frame so that it points to the final branch. */ - - case OP_ONCE: - Fback_frame = ((char *)F - (char *)P); - for (;;) - { - uint32_t y = GET(P->ecode,1); - if ((P->ecode)[y] != OP_ALT) break; - P->ecode += y; - } - break; - - /* A matching negative assertion returns MATCH, which is turned into - NOMATCH at the assertion level. For a variable lookbehind, check its end - point. */ - - case OP_ASSERTBACK_NOT: - if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) - RRETURN(MATCH_NOMATCH); - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_ASSERT_NOT: - RRETURN(MATCH_MATCH); - - /* A scan substring group must preserve the current end_subject, - and restore it before the backtracking is performed into its sub - pattern. */ - - case OP_ASSERT_SCS: - F->temp_sptr[0] = mb->end_subject; - mb->end_subject = P->temp_sptr[0]; - mb->true_end_subject = mb->end_subject + P->temp_size; - Feptr = P->temp_sptr[1]; - - RMATCH(Fecode + 1 + LINK_SIZE, RM39); - - mb->end_subject = F->temp_sptr[0]; - mb->true_end_subject = mb->end_subject; - RRETURN(rrc); - break; - - /* At the end of a script run, apply the script-checking rules. This code - will never by exercised if Unicode support it not compiled, because in - that environment script runs cause an error at compile time. */ - - case OP_SCRIPT_RUN: - if (!PRIV(script_run)(P->eptr, Feptr, utf)) RRETURN(MATCH_NOMATCH); - break; - - /* Whole-pattern recursion is coded as a recurse into group 0, and is - handled with OP_BRA above. Other recursion is handled here. */ - - case OP_CBRA: - case OP_CBRAPOS: - case OP_SCBRA: - case OP_SCBRAPOS: - number = GET2(bracode, 1+LINK_SIZE); - - /* Handle a recursively called group. We reinstate the previous set of - captures and then carry on after the recursion call. */ - - if (Fcurrent_recurse == number) - { - P = (heapframe *)((char *)N - frame_size); - Fecode = P->ecode + 1 + LINK_SIZE; - - if (*Fecode != OP_CREF) - { - memcpy(F->ovector, P->ovector, Foffset_top * sizeof(PCRE2_SIZE)); - Foffset_top = P->offset_top; - } - else - recurse_update_offsets(F, P); - - Fcapture_last = P->capture_last; - Fcurrent_recurse = P->current_recurse; - continue; /* With next opcode */ - } - - /* Deal with actual capturing. */ - - offset = (number << 1) - 2; - Fcapture_last = number; - Fovector[offset] = P->eptr - mb->start_subject; - Fovector[offset+1] = Feptr - mb->start_subject; - if (offset >= Foffset_top) Foffset_top = offset + 2; - break; - } /* End actions relating to the starting opcode */ - - /* OP_KETRPOS is a possessive repeating ket. Remember the current position, - and return the MATCH_KETRPOS. This makes it possible to do the repeats one - at a time from the outer level. This must precede the empty string test - - in this case that test is done at the outer level. */ - - if (*Fecode == OP_KETRPOS) - { - memcpy((char *)P + offsetof(heapframe, eptr), - (char *)F + offsetof(heapframe, eptr), - frame_copy_size); - RRETURN(MATCH_KETRPOS); - } - - /* Handle the different kinds of closing brackets. A non-repeating ket - needs no special action, just continuing at this level. This also happens - for the repeating kets if the group matched no characters, in order to - forcibly break infinite loops. Otherwise, the repeating kets try the rest - of the pattern or restart from the preceding bracket, in the appropriate - order. */ - - if (Fop != OP_KET && (P == NULL || Feptr != P->eptr)) - { - if (Fop == OP_KETRMIN) - { - RMATCH(Fecode + 1 + LINK_SIZE, RM6); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - Fecode -= GET(Fecode, 1); - break; /* End of ket processing */ - } - - /* Repeat the maximum number of times (KETRMAX) */ - - RMATCH(bracode, RM7); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - } - - /* Carry on at this level for a non-repeating ket, or after matching an - empty string, or after repeating for a maximum number of times. */ - - Fecode += 1 + LINK_SIZE; - break; - - - /* ===================================================================== */ - /* Start and end of line assertions, not multiline mode. */ - - case OP_CIRC: /* Start of line, unless PCRE2_NOTBOL is set. */ - if (Feptr != mb->start_subject || (mb->moptions & PCRE2_NOTBOL) != 0) - RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - case OP_SOD: /* Unconditional start of subject */ - if (Feptr != mb->start_subject) RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - /* When PCRE2_NOTEOL is unset, assert before the subject end, or a - terminating newline unless PCRE2_DOLLAR_ENDONLY is set. */ - - case OP_DOLL: - if ((mb->moptions & PCRE2_NOTEOL) != 0) RRETURN(MATCH_NOMATCH); - if ((mb->poptions & PCRE2_DOLLAR_ENDONLY) == 0) goto ASSERT_NL_OR_EOS; - - PCRE2_FALLTHROUGH /* Fall through */ - /* Unconditional end of subject assertion (\z). */ - - case OP_EOD: - if (Feptr < mb->true_end_subject) RRETURN(MATCH_NOMATCH); - if (mb->partial != 0) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - Fecode++; - break; - - /* End of subject or ending \n assertion (\Z) */ - - case OP_EODN: - ASSERT_NL_OR_EOS: - if (Feptr < mb->true_end_subject && - (!IS_NEWLINE(Feptr) || Feptr != mb->true_end_subject - mb->nllen)) - { - if (mb->partial != 0 && - Feptr + 1 >= mb->end_subject && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - UCHAR21TEST(Feptr) == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - RRETURN(MATCH_NOMATCH); - } - - /* Either at end of string or \n before end. */ - - if (mb->partial != 0) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - Fecode++; - break; - - - /* ===================================================================== */ - /* Start and end of line assertions, multiline mode. */ - - /* Start of subject unless notbol, or after any newline except for one at - the very end, unless PCRE2_ALT_CIRCUMFLEX is set. */ - - case OP_CIRCM: - if ((mb->moptions & PCRE2_NOTBOL) != 0 && Feptr == mb->start_subject) - RRETURN(MATCH_NOMATCH); - if (Feptr != mb->start_subject && - ((Feptr == mb->end_subject && - (mb->poptions & PCRE2_ALT_CIRCUMFLEX) == 0) || - !WAS_NEWLINE(Feptr))) - RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - /* Assert before any newline, or before end of subject unless noteol is - set. */ - - case OP_DOLLM: - if (Feptr < mb->end_subject) - { - if (!IS_NEWLINE(Feptr)) - { - if (mb->partial != 0 && - Feptr + 1 >= mb->end_subject && - NLBLOCK->nltype == NLTYPE_FIXED && - NLBLOCK->nllen == 2 && - UCHAR21TEST(Feptr) == NLBLOCK->nl[0]) - { - mb->hitend = TRUE; - if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; - } - RRETURN(MATCH_NOMATCH); - } - } - else - { - if ((mb->moptions & PCRE2_NOTEOL) != 0) RRETURN(MATCH_NOMATCH); - SCHECK_PARTIAL(); - } - Fecode++; - break; - - - /* ===================================================================== */ - /* Start of match assertion */ - - case OP_SOM: - if (Feptr != mb->start_subject + mb->start_offset) RRETURN(MATCH_NOMATCH); - Fecode++; - break; - - - /* ===================================================================== */ - /* Reset the start of match point */ - - case OP_SET_SOM: - Fstart_match = Feptr; - Fecode++; - break; - - - /* ===================================================================== */ - /* Word boundary assertions. Find out if the previous and current - characters are "word" characters. It takes a bit more work in UTF mode. - Characters > 255 are assumed to be "non-word" characters when PCRE2_UCP is - not set. When it is set, use Unicode properties if available, even when not - in UTF mode. Remember the earliest and latest consulted characters. */ - - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - if (Feptr == mb->check_subject) prev_is_word = FALSE; else - { - PCRE2_SPTR lastptr = Feptr - 1; -#ifdef SUPPORT_UNICODE - if (utf) - { - BACKCHAR(lastptr); - GETCHAR(fc, lastptr); - } - else -#endif /* SUPPORT_UNICODE */ - fc = *lastptr; - if (lastptr < mb->start_used_ptr) mb->start_used_ptr = lastptr; -#ifdef SUPPORT_UNICODE - if (Fop == OP_UCP_WORD_BOUNDARY || Fop == OP_NOT_UCP_WORD_BOUNDARY) - { - int chartype = UCD_CHARTYPE(fc); - int category = PRIV(ucp_gentype)[chartype]; - prev_is_word = (category == ucp_L || category == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc); - } - else -#endif /* SUPPORT_UNICODE */ - prev_is_word = CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0; - } - - /* Get status of next character */ - - if (Feptr >= mb->end_subject) - { - SCHECK_PARTIAL(); - cur_is_word = FALSE; - } - else - { - PCRE2_SPTR nextptr = Feptr + 1; -#ifdef SUPPORT_UNICODE - if (utf) - { - FORWARDCHARTEST(nextptr, mb->end_subject); - GETCHAR(fc, Feptr); - } - else -#endif /* SUPPORT_UNICODE */ - fc = *Feptr; - if (nextptr > mb->last_used_ptr) mb->last_used_ptr = nextptr; -#ifdef SUPPORT_UNICODE - if (Fop == OP_UCP_WORD_BOUNDARY || Fop == OP_NOT_UCP_WORD_BOUNDARY) - { - int chartype = UCD_CHARTYPE(fc); - int category = PRIV(ucp_gentype)[chartype]; - cur_is_word = (category == ucp_L || category == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc); - } - else -#endif /* SUPPORT_UNICODE */ - cur_is_word = CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0; - } - - /* Now see if the situation is what we want */ - - if ((*Fecode++ == OP_WORD_BOUNDARY || Fop == OP_UCP_WORD_BOUNDARY)? - cur_is_word == prev_is_word : cur_is_word != prev_is_word) - RRETURN(MATCH_NOMATCH); - break; - - - /* ===================================================================== */ - /* Backtracking (*VERB)s, with and without arguments. Note that if the - pattern is successfully matched, we do not come back from RMATCH. */ - - case OP_MARK: - Fmark = mb->nomatch_mark = Fecode + 2; - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM12); - - /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an - argument, and we must check whether that argument matches this MARK's - argument. It is passed back in mb->verb_skip_ptr. If it does match, we - return MATCH_SKIP with mb->verb_skip_ptr now pointing to the subject - position that corresponds to this mark. Otherwise, pass back the return - code unaltered. */ - - if (rrc == MATCH_SKIP_ARG && - PRIV(strcmp)(Fecode + 2, mb->verb_skip_ptr) == 0) - { - mb->verb_skip_ptr = Feptr; /* Pass back current position */ - RRETURN(MATCH_SKIP); - } - RRETURN(rrc); - - case OP_FAIL: - RRETURN(MATCH_NOMATCH); - - /* Record the current recursing group number in mb->verb_current_recurse - when a backtracking return such as MATCH_COMMIT is given. This enables the - recurse processing to catch verbs from within the recursion. */ - - case OP_COMMIT: - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM13); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - mb->verb_current_recurse = Fcurrent_recurse; - RRETURN(MATCH_COMMIT); - - case OP_COMMIT_ARG: - Fmark = mb->nomatch_mark = Fecode + 2; - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM36); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - mb->verb_current_recurse = Fcurrent_recurse; - RRETURN(MATCH_COMMIT); - - case OP_PRUNE: - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM14); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - mb->verb_current_recurse = Fcurrent_recurse; - RRETURN(MATCH_PRUNE); - - case OP_PRUNE_ARG: - Fmark = mb->nomatch_mark = Fecode + 2; - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM15); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - mb->verb_current_recurse = Fcurrent_recurse; - RRETURN(MATCH_PRUNE); - - case OP_SKIP: - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM16); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - mb->verb_skip_ptr = Feptr; /* Pass back current position */ - mb->verb_current_recurse = Fcurrent_recurse; - RRETURN(MATCH_SKIP); - - /* Note that, for Perl compatibility, SKIP with an argument does NOT set - nomatch_mark. When a pattern match ends with a SKIP_ARG for which there was - not a matching mark, we have to re-run the match, ignoring the SKIP_ARG - that failed and any that precede it (either they also failed, or were not - triggered). To do this, we maintain a count of executed SKIP_ARGs. If a - SKIP_ARG gets to top level, the match is re-run with mb->ignore_skip_arg - set to the count of the one that failed. */ - - case OP_SKIP_ARG: - mb->skip_arg_count++; - if (mb->skip_arg_count <= mb->ignore_skip_arg) - { - Fecode += PRIV(OP_lengths)[*Fecode] + Fecode[1]; - break; - } - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM17); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - - /* Pass back the current skip name and return the special MATCH_SKIP_ARG - return code. This will either be caught by a matching MARK, or get to the - top, where it causes a rematch with mb->ignore_skip_arg set to the value of - mb->skip_arg_count. */ - - mb->verb_skip_ptr = Fecode + 2; - mb->verb_current_recurse = Fcurrent_recurse; - RRETURN(MATCH_SKIP_ARG); - - /* For THEN (and THEN_ARG) we pass back the address of the opcode, so that - the branch in which it occurs can be determined. */ - - case OP_THEN: - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM18); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - mb->verb_ecode_ptr = Fecode; - mb->verb_current_recurse = Fcurrent_recurse; - RRETURN(MATCH_THEN); - - case OP_THEN_ARG: - Fmark = mb->nomatch_mark = Fecode + 2; - RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM19); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); - mb->verb_ecode_ptr = Fecode; - mb->verb_current_recurse = Fcurrent_recurse; - RRETURN(MATCH_THEN); - - - /* ===================================================================== */ - /* There's been some horrible disaster. Arrival here can only mean there is - something seriously wrong in the code above or the OP_xxx definitions. */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - - /* Do not insert any code in here without much thought; it is assumed - that "continue" in the code above comes out to here to repeat the main - loop. */ - - } /* End of main loop */ - -PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ - -/* ========================================================================= */ -/* The RRETURN() macro jumps here. The number that is saved in Freturn_id -indicates which label we actually want to return to. The value in Frdepth is -the index number of the frame in the vector. The return value has been placed -in rrc. */ - -#define LBL(val) case val: goto L_RM##val; - -RETURN_SWITCH: -if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; -if (Frdepth == 0) return rrc; /* Exit from the top level */ -F = (heapframe *)((char *)F - Fback_frame); /* Backtrack */ -mb->cb->callout_flags |= PCRE2_CALLOUT_BACKTRACK; /* Note for callouts */ - -#ifdef DEBUG_SHOW_RMATCH -fprintf(stderr, "++ RETURN %d to RM%d\n", rrc, Freturn_id); -#endif - -switch (Freturn_id) - { - LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8) - LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(16) - LBL(17) LBL(18) LBL(19) LBL(20) LBL(21) LBL(22) LBL(23) LBL(24) - LBL(25) LBL(26) LBL(27) LBL(28) LBL(29) LBL(30) LBL(31) LBL(32) - LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39) - -#ifdef SUPPORT_WIDE_CHARS - LBL(100) LBL(101) LBL(102) LBL(103) -#endif - -#ifdef SUPPORT_UNICODE - LBL(200) LBL(201) LBL(202) LBL(203) LBL(204) LBL(205) LBL(206) - LBL(207) LBL(208) LBL(209) LBL(210) LBL(211) LBL(212) LBL(213) - LBL(214) LBL(215) LBL(216) LBL(217) LBL(218) LBL(219) LBL(220) - LBL(221) LBL(222) LBL(223) LBL(224) -#endif - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } -#undef LBL -} - - -/************************************************* -* Match a Regular Expression * -*************************************************/ - -/* This function applies a compiled pattern to a subject string and picks out -portions of the string if it matches. Two elements in the vector are set for -each substring: the offsets to the start and end of the substring. - -Arguments: - code points to the compiled expression - subject points to the subject string - length length of subject string (may contain binary zeros) - start_offset where to start in the subject string - options option bits - match_data points to a match_data block - mcontext points a PCRE2 context - -Returns: > 0 => success; value is the number of ovector pairs filled - = 0 => success, but ovector is not big enough - = -1 => failed to match (PCRE2_ERROR_NOMATCH) - = -2 => partial match (PCRE2_ERROR_PARTIAL) - < -2 => some kind of unexpected problem -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, - PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data, - pcre2_match_context *mcontext) -{ -int rc; -const uint8_t *start_bits = NULL; -const pcre2_real_code *re = (const pcre2_real_code *)code; -uint32_t original_options = options; - -BOOL anchored; -BOOL firstline; -BOOL has_first_cu = FALSE; -BOOL has_req_cu = FALSE; -BOOL startline; - -#if PCRE2_CODE_UNIT_WIDTH == 8 -PCRE2_SPTR memchr_found_first_cu; -PCRE2_SPTR memchr_found_first_cu2; -#endif - -PCRE2_UCHAR first_cu = 0; -PCRE2_UCHAR first_cu2 = 0; -PCRE2_UCHAR req_cu = 0; -PCRE2_UCHAR req_cu2 = 0; - -PCRE2_UCHAR null_str[1] = { 0xcd }; -PCRE2_SPTR original_subject = subject; -PCRE2_SPTR bumpalong_limit; -PCRE2_SPTR end_subject; -PCRE2_SPTR true_end_subject; -PCRE2_SPTR start_match; -PCRE2_SPTR req_cu_ptr; -PCRE2_SPTR start_partial; -PCRE2_SPTR match_partial; - -#ifdef SUPPORT_JIT -BOOL use_jit; -#endif - -/* This flag is needed even when Unicode is not supported for convenience -(it is used by the IS_NEWLINE macro). */ - -BOOL utf = FALSE; - -#ifdef SUPPORT_UNICODE -BOOL ucp = FALSE; -BOOL allow_invalid; -uint32_t fragment_options = 0; -#ifdef SUPPORT_JIT -BOOL jit_checked_utf = FALSE; -#endif -#endif /* SUPPORT_UNICODE */ - -PCRE2_SIZE frame_size; -PCRE2_SIZE heapframes_size; - -/* We need to have mb as a pointer to a match block, because the IS_NEWLINE -macro is used below, and it expects NLBLOCK to be defined as a pointer. */ - -pcre2_callout_block cb; -match_block actual_match_block; -match_block *mb = &actual_match_block; - -/* Recognize NULL, length 0 as an empty string. */ - -if (subject == NULL && length == 0) subject = null_str; - -/* Plausibility checks */ - -if (match_data == NULL) return PCRE2_ERROR_NULL; -if (code == NULL || subject == NULL) - return match_data->rc = PCRE2_ERROR_NULL; -if ((options & ~PUBLIC_MATCH_OPTIONS) != 0) - return match_data->rc = PCRE2_ERROR_BADOPTION; - -start_match = subject + start_offset; -req_cu_ptr = start_match - 1; -if (length == PCRE2_ZERO_TERMINATED) - { - length = PRIV(strlen)(subject); - } -true_end_subject = end_subject = subject + length; - -if (start_offset > length) return match_data->rc = PCRE2_ERROR_BADOFFSET; - -/* Check that the first field in the block is the magic number. */ - -if (re->magic_number != MAGIC_NUMBER) - return match_data->rc = PCRE2_ERROR_BADMAGIC; - -/* Check the code unit width. */ - -if ((re->flags & PCRE2_MODE_MASK) != PCRE2_CODE_UNIT_WIDTH/8) - return match_data->rc = PCRE2_ERROR_BADMODE; - -/* PCRE2_NOTEMPTY and PCRE2_NOTEMPTY_ATSTART are match-time flags in the -options variable for this function. Users of PCRE2 who are not calling the -function directly would like to have a way of setting these flags, in the same -way that they can set pcre2_compile() flags like PCRE2_NO_AUTO_POSSESS with -constructions like (*NO_AUTOPOSSESS). To enable this, (*NOTEMPTY) and -(*NOTEMPTY_ATSTART) set bits in the pattern's "flag" function which we now -transfer to the options for this function. The bits are guaranteed to be -adjacent, but do not have the same values. This bit of Boolean trickery assumes -that the match-time bits are not more significant than the flag bits. If by -accident this is not the case, a compile-time division by zero error will -occur. */ - -#define FF (PCRE2_NOTEMPTY_SET|PCRE2_NE_ATST_SET) -#define OO (PCRE2_NOTEMPTY|PCRE2_NOTEMPTY_ATSTART) -options |= (re->flags & FF) / ((FF & (~FF+1)) / (OO & (~OO+1))); -#undef FF -#undef OO - -/* If the pattern was successfully studied with JIT support, we will run the -JIT executable instead of the rest of this function. Most options must be set -at compile time for the JIT code to be usable. */ - -#ifdef SUPPORT_JIT -use_jit = (re->executable_jit != NULL && - (options & ~PUBLIC_JIT_MATCH_OPTIONS) == 0); -#endif - -/* Initialize UTF/UCP parameters. */ - -#ifdef SUPPORT_UNICODE -utf = (re->overall_options & PCRE2_UTF) != 0; -allow_invalid = (re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0; -ucp = (re->overall_options & PCRE2_UCP) != 0; -#endif /* SUPPORT_UNICODE */ - -/* Convert the partial matching flags into an integer. */ - -mb->partial = ((options & PCRE2_PARTIAL_HARD) != 0)? 2 : - ((options & PCRE2_PARTIAL_SOFT) != 0)? 1 : 0; - -/* Partial matching and PCRE2_ENDANCHORED are currently not allowed at the same -time. */ - -if (mb->partial != 0 && - ((re->overall_options | options) & PCRE2_ENDANCHORED) != 0) - return match_data->rc = PCRE2_ERROR_BADOPTION; - -/* It is an error to set an offset limit without setting the flag at compile -time. */ - -if (mcontext != NULL && mcontext->offset_limit != PCRE2_UNSET && - (re->overall_options & PCRE2_USE_OFFSET_LIMIT) == 0) - return match_data->rc = PCRE2_ERROR_BADOFFSETLIMIT; - -/* If the match data block was previously used with PCRE2_COPY_MATCHED_SUBJECT, -free the memory that was obtained. Set the field to NULL for match error -cases. */ - -if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0) - { - match_data->memctl.free((void *)match_data->subject, - match_data->memctl.memory_data); - match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT; - } -match_data->subject = NULL; - -/* Zero the error offset in case the first code unit is invalid UTF. */ - -match_data->startchar = 0; - - -/* ============================= JIT matching ============================== */ - -/* Prepare for JIT matching. Check a UTF string for validity unless no check is -requested or invalid UTF can be handled. We check only the portion of the -subject that might be be inspected during matching - from the offset minus the -maximum lookbehind to the given length. This saves time when a small part of a -large subject is being matched by the use of a starting offset. Note that the -maximum lookbehind is a number of characters, not code units. */ - -#ifdef SUPPORT_JIT -if (use_jit) - { -#ifdef SUPPORT_UNICODE - if (utf && (options & PCRE2_NO_UTF_CHECK) == 0 && !allow_invalid) - { - - /* For 8-bit and 16-bit UTF, check that the first code unit is a valid - character start. */ - -#if PCRE2_CODE_UNIT_WIDTH != 32 - if (start_match < end_subject && NOT_FIRSTCU(*start_match)) - { - if (start_offset > 0) return match_data->rc = PCRE2_ERROR_BADUTFOFFSET; -#if PCRE2_CODE_UNIT_WIDTH == 8 - return match_data->rc = PCRE2_ERROR_UTF8_ERR20; /* Isolated 0x80 byte */ -#else - return match_data->rc = PCRE2_ERROR_UTF16_ERR3; /* Isolated low surrogate */ -#endif - } -#endif /* WIDTH != 32 */ - - /* Move back by the maximum lookbehind, just in case it happens at the very - start of matching. */ - -#if PCRE2_CODE_UNIT_WIDTH != 32 - for (unsigned int i = re->max_lookbehind; i > 0 && start_match > subject; i--) - { - start_match--; - while (start_match > subject && -#if PCRE2_CODE_UNIT_WIDTH == 8 - (*start_match & 0xc0) == 0x80) -#else /* 16-bit */ - (*start_match & 0xfc00) == 0xdc00) -#endif - start_match--; - } -#else /* PCRE2_CODE_UNIT_WIDTH != 32 */ - - /* In the 32-bit library, one code unit equals one character. However, - we cannot just subtract the lookbehind and then compare pointers, because - a very large lookbehind could create an invalid pointer. */ - - if (start_offset >= re->max_lookbehind) - start_match -= re->max_lookbehind; - else - start_match = subject; -#endif /* PCRE2_CODE_UNIT_WIDTH != 32 */ - - /* Validate the relevant portion of the subject. Adjust the offset of an - invalid code point to be an absolute offset in the whole string. */ - - rc = PRIV(valid_utf)(start_match, - length - (start_match - subject), &(match_data->startchar)); - if (rc != 0) - { - match_data->startchar += start_match - subject; - return match_data->rc = rc; - } - jit_checked_utf = TRUE; - } -#endif /* SUPPORT_UNICODE */ - - /* If JIT returns BADOPTION, which means that the selected complete or - partial matching mode was not compiled, fall through to the interpreter. */ - - rc = pcre2_jit_match(code, subject, length, start_offset, options, - match_data, mcontext); - if (rc != PCRE2_ERROR_JIT_BADOPTION) - { - match_data->options = original_options; - if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0) - { - if (length != 0) - { - match_data->subject = match_data->memctl.malloc(CU2BYTES(length), - match_data->memctl.memory_data); - if (match_data->subject == NULL) - return match_data->rc = PCRE2_ERROR_NOMEMORY; - memcpy((void *)match_data->subject, subject, CU2BYTES(length)); - } - else - match_data->subject = NULL; - match_data->flags |= PCRE2_MD_COPIED_SUBJECT; - } - else - { - /* When pcre2_jit_match sets the subject, it doesn't know what the - original passed-in pointer was. */ - if (match_data->subject != NULL) match_data->subject = original_subject; - } - return rc; - } - } -#endif /* SUPPORT_JIT */ - -/* ========================= End of JIT matching ========================== */ - - -/* Proceed with non-JIT matching. The default is to allow lookbehinds to the -start of the subject. A UTF check when there is a non-zero offset may change -this. */ - -mb->check_subject = subject; - -/* If a UTF subject string was not checked for validity in the JIT code above, -check it here, and handle support for invalid UTF strings. The check above -happens only when invalid UTF is not supported and PCRE2_NO_CHECK_UTF is unset. -If we get here in those circumstances, it means the subject string is valid, -but for some reason JIT matching was not successful. There is no need to check -the subject again. - -We check only the portion of the subject that might be be inspected during -matching - from the offset minus the maximum lookbehind to the given length. -This saves time when a small part of a large subject is being matched by the -use of a starting offset. Note that the maximum lookbehind is a number of -characters, not code units. - -Note also that support for invalid UTF forces a check, overriding the setting -of PCRE2_NO_CHECK_UTF. */ - -#ifdef SUPPORT_UNICODE -if (utf && -#ifdef SUPPORT_JIT - !jit_checked_utf && -#endif - ((options & PCRE2_NO_UTF_CHECK) == 0 || allow_invalid)) - { -#if PCRE2_CODE_UNIT_WIDTH != 32 - BOOL skipped_bad_start = FALSE; -#endif - - /* For 8-bit and 16-bit UTF, check that the first code unit is a valid - character start. If we are handling invalid UTF, just skip over such code - units. Otherwise, give an appropriate error. */ - -#if PCRE2_CODE_UNIT_WIDTH != 32 - if (allow_invalid) - { - while (start_match < end_subject && NOT_FIRSTCU(*start_match)) - { - start_match++; - skipped_bad_start = TRUE; - } - } - else if (start_match < end_subject && NOT_FIRSTCU(*start_match)) - { - if (start_offset > 0) return match_data->rc = PCRE2_ERROR_BADUTFOFFSET; -#if PCRE2_CODE_UNIT_WIDTH == 8 - return match_data->rc = PCRE2_ERROR_UTF8_ERR20; /* Isolated 0x80 byte */ -#else - return match_data->rc = PCRE2_ERROR_UTF16_ERR3; /* Isolated low surrogate */ -#endif - } -#endif /* WIDTH != 32 */ - - /* The mb->check_subject field points to the start of UTF checking; - lookbehinds can go back no further than this. */ - - mb->check_subject = start_match; - - /* Move back by the maximum lookbehind, just in case it happens at the very - start of matching, but don't do this if we skipped bad 8-bit or 16-bit code - units above. */ - -#if PCRE2_CODE_UNIT_WIDTH != 32 - if (!skipped_bad_start) - { - unsigned int i; - for (i = re->max_lookbehind; i > 0 && mb->check_subject > subject; i--) - { - mb->check_subject--; - while (mb->check_subject > subject && -#if PCRE2_CODE_UNIT_WIDTH == 8 - (*mb->check_subject & 0xc0) == 0x80) -#else /* 16-bit */ - (*mb->check_subject & 0xfc00) == 0xdc00) -#endif - mb->check_subject--; - } - } -#else /* PCRE2_CODE_UNIT_WIDTH != 32 */ - - /* In the 32-bit library, one code unit equals one character. However, - we cannot just subtract the lookbehind and then compare pointers, because - a very large lookbehind could create an invalid pointer. */ - - if (start_offset >= re->max_lookbehind) - mb->check_subject -= re->max_lookbehind; - else - mb->check_subject = subject; -#endif /* PCRE2_CODE_UNIT_WIDTH != 32 */ - - /* Validate the relevant portion of the subject. There's a loop in case we - encounter bad UTF in the characters preceding start_match which we are - scanning because of a lookbehind. */ - - for (;;) - { - rc = PRIV(valid_utf)(mb->check_subject, - length - (mb->check_subject - subject), &(match_data->startchar)); - - if (rc == 0) break; /* Valid UTF string */ - - /* Invalid UTF string. Adjust the offset to be an absolute offset in the - whole string. If we are handling invalid UTF strings, set end_subject to - stop before the bad code unit, and set the options to "not end of line". - Otherwise return the error. */ - - match_data->startchar += mb->check_subject - subject; - if (!allow_invalid || rc > 0) return match_data->rc = rc; - end_subject = subject + match_data->startchar; - - /* If the end precedes start_match, it means there is invalid UTF in the - extra code units we reversed over because of a lookbehind. Advance past the - first bad code unit, and then skip invalid character starting code units in - 8-bit and 16-bit modes, and try again with the original end point. */ - - if (end_subject < start_match) - { - mb->check_subject = end_subject + 1; -#if PCRE2_CODE_UNIT_WIDTH != 32 - while (mb->check_subject < start_match && NOT_FIRSTCU(*mb->check_subject)) - mb->check_subject++; -#endif - end_subject = true_end_subject; - } - - /* Otherwise, set the not end of line option, and do the match. */ - - else - { - fragment_options = PCRE2_NOTEOL; - break; - } - } - } -#endif /* SUPPORT_UNICODE */ - -/* A NULL match context means "use a default context", but we take the memory -control functions from the pattern. */ - -if (mcontext == NULL) - { - mcontext = (pcre2_match_context *)(&PRIV(default_match_context)); - mb->memctl = re->memctl; - } -else mb->memctl = mcontext->memctl; - -anchored = ((re->overall_options | options) & PCRE2_ANCHORED) != 0; -firstline = !anchored && (re->overall_options & PCRE2_FIRSTLINE) != 0; -startline = (re->flags & PCRE2_STARTLINE) != 0; -bumpalong_limit = (mcontext->offset_limit == PCRE2_UNSET)? - true_end_subject : subject + mcontext->offset_limit; - -/* Initialize and set up the fixed fields in the callout block, with a pointer -in the match block. */ - -mb->cb = &cb; -cb.version = 2; -cb.subject = subject; -cb.subject_length = (PCRE2_SIZE)(end_subject - subject); -cb.callout_flags = 0; - -/* Fill in the remaining fields in the match block, except for moptions, which -gets set later. */ - -mb->callout = mcontext->callout; -mb->callout_data = mcontext->callout_data; - -mb->start_subject = subject; -mb->start_offset = start_offset; -mb->end_subject = end_subject; -mb->true_end_subject = true_end_subject; -mb->hasthen = (re->flags & PCRE2_HASTHEN) != 0; -mb->hasbsk = (re->flags & PCRE2_HASBSK) != 0; -mb->allowemptypartial = (re->max_lookbehind > 0) || - (re->flags & PCRE2_MATCH_EMPTY) != 0; -mb->allowlookaroundbsk = - (re->extra_options & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) != 0; -mb->poptions = re->overall_options; /* Pattern options */ -mb->ignore_skip_arg = 0; -mb->mark = mb->nomatch_mark = NULL; /* In case never set */ - -/* The name table is needed for finding all the numbers associated with a -given name, for condition testing. The code follows the name table. */ - -mb->name_table = (PCRE2_SPTR)((const uint8_t *)re + sizeof(pcre2_real_code)); -mb->name_count = re->name_count; -mb->name_entry_size = re->name_entry_size; -mb->start_code = (PCRE2_SPTR)((const uint8_t *)re + re->code_start); - -/* Process the \R and newline settings. */ - -mb->bsr_convention = re->bsr_convention; -mb->nltype = NLTYPE_FIXED; -switch(re->newline_convention) - { - case PCRE2_NEWLINE_CR: - mb->nllen = 1; - mb->nl[0] = CHAR_CR; - break; - - case PCRE2_NEWLINE_LF: - mb->nllen = 1; - mb->nl[0] = CHAR_NL; - break; - - case PCRE2_NEWLINE_NUL: - mb->nllen = 1; - mb->nl[0] = CHAR_NUL; - break; - - case PCRE2_NEWLINE_CRLF: - mb->nllen = 2; - mb->nl[0] = CHAR_CR; - mb->nl[1] = CHAR_NL; - break; - - case PCRE2_NEWLINE_ANY: - mb->nltype = NLTYPE_ANY; - break; - - case PCRE2_NEWLINE_ANYCRLF: - mb->nltype = NLTYPE_ANYCRLF; - break; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return match_data->rc = PCRE2_ERROR_INTERNAL; - /* LCOV_EXCL_STOP */ - } - -/* The backtracking frames have fixed data at the front, and a PCRE2_SIZE -vector at the end, whose size depends on the number of capturing parentheses in -the pattern. It is not used at all if there are no capturing parentheses. - - frame_size is the total size of each frame - match_data->heapframes is the pointer to the frames vector - match_data->heapframes_size is the allocated size of the vector - -We must pad the frame_size for alignment to ensure subsequent frames are as -aligned as heapframe. Whilst ovector is word-aligned due to being a PCRE2_SIZE -array, that does not guarantee it is suitably aligned for pointers, as some -architectures have pointers that are larger than a size_t. */ - -frame_size = (offsetof(heapframe, ovector) + - re->top_bracket * 2 * sizeof(PCRE2_SIZE) + HEAPFRAME_ALIGNMENT - 1) & - ~(HEAPFRAME_ALIGNMENT - 1); - -/* Limits set in the pattern override the match context only if they are -smaller. */ - -mb->heap_limit = ((mcontext->heap_limit < re->limit_heap)? - mcontext->heap_limit : re->limit_heap); - -mb->match_limit = (mcontext->match_limit < re->limit_match)? - mcontext->match_limit : re->limit_match; - -mb->match_limit_depth = (mcontext->depth_limit < re->limit_depth)? - mcontext->depth_limit : re->limit_depth; - -/* If a pattern has very many capturing parentheses, the frame size may be very -large. Set the initial frame vector size to ensure that there are at least 10 -available frames, but enforce a minimum of START_FRAMES_SIZE. If this is -greater than the heap limit, get as large a vector as possible. */ - -heapframes_size = frame_size * 10; -if (heapframes_size < START_FRAMES_SIZE) heapframes_size = START_FRAMES_SIZE; -if (heapframes_size / 1024 > mb->heap_limit) - { - PCRE2_SIZE max_size = 1024 * mb->heap_limit; - if (max_size < frame_size) return match_data->rc = PCRE2_ERROR_HEAPLIMIT; - heapframes_size = max_size; - } - -/* If an existing frame vector in the match_data block is large enough, we can -use it. Otherwise, free any pre-existing vector and get a new one. */ - -if (match_data->heapframes_size < heapframes_size) - { - match_data->memctl.free(match_data->heapframes, - match_data->memctl.memory_data); - match_data->heapframes = match_data->memctl.malloc(heapframes_size, - match_data->memctl.memory_data); - if (match_data->heapframes == NULL) - { - match_data->heapframes_size = 0; - return match_data->rc = PCRE2_ERROR_NOMEMORY; - } - match_data->heapframes_size = heapframes_size; - } - -/* Write to the ovector within the first frame to mark every capture unset and -to avoid uninitialized memory read errors when it is copied to a new frame. */ - -memset((char *)(match_data->heapframes) + offsetof(heapframe, ovector), 0xff, - frame_size - offsetof(heapframe, ovector)); - -/* Pointers to the individual character tables */ - -mb->lcc = re->tables + lcc_offset; -mb->fcc = re->tables + fcc_offset; -mb->ctypes = re->tables + ctypes_offset; - -/* Set up the first code unit to match, if available. If there's no first code -unit there may be a bitmap of possible first characters. */ - -if ((re->flags & PCRE2_FIRSTSET) != 0) - { - has_first_cu = TRUE; - first_cu = first_cu2 = (PCRE2_UCHAR)(re->first_codeunit); - if ((re->flags & PCRE2_FIRSTCASELESS) != 0) - { - first_cu2 = TABLE_GET(first_cu, mb->fcc, first_cu); -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (first_cu > 127 && ucp && !utf) first_cu2 = UCD_OTHERCASE(first_cu); -#else - if (first_cu > 127 && (utf || ucp)) first_cu2 = UCD_OTHERCASE(first_cu); -#endif -#endif /* SUPPORT_UNICODE */ - } - } -else - if (!startline && (re->flags & PCRE2_FIRSTMAPSET) != 0) - start_bits = re->start_bitmap; - -/* There may also be a "last known required character" set. */ - -if ((re->flags & PCRE2_LASTSET) != 0) - { - has_req_cu = TRUE; - req_cu = req_cu2 = (PCRE2_UCHAR)(re->last_codeunit); - if ((re->flags & PCRE2_LASTCASELESS) != 0) - { - req_cu2 = TABLE_GET(req_cu, mb->fcc, req_cu); -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (req_cu > 127 && ucp && !utf) req_cu2 = UCD_OTHERCASE(req_cu); -#else - if (req_cu > 127 && (utf || ucp)) req_cu2 = UCD_OTHERCASE(req_cu); -#endif -#endif /* SUPPORT_UNICODE */ - } - } - - -/* ==========================================================================*/ - -/* Loop for handling unanchored repeated matching attempts; for anchored regexs -the loop runs just once. */ - -#ifdef SUPPORT_UNICODE -FRAGMENT_RESTART: -#endif - -start_partial = match_partial = NULL; -mb->hitend = FALSE; - -#if PCRE2_CODE_UNIT_WIDTH == 8 -memchr_found_first_cu = NULL; -memchr_found_first_cu2 = NULL; -#endif - -for(;;) - { - PCRE2_SPTR new_start_match; - - /* ----------------- Start of match optimizations ---------------- */ - - /* There are some optimizations that avoid running the match if a known - starting point is not found, or if a known later code unit is not present. - However, there is an option (settable at compile time) that disables these, - for testing and for ensuring that all callouts do actually occur. */ - - if ((re->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) - { - /* If firstline is TRUE, the start of the match is constrained to the first - line of a multiline string. That is, the match must be before or at the - first newline following the start of matching. Temporarily adjust - end_subject so that we stop the scans for a first code unit at a newline. - If the match fails at the newline, later code breaks the loop. */ - - if (firstline) - { - PCRE2_SPTR t = start_match; -#ifdef SUPPORT_UNICODE - if (utf) - { - while (t < end_subject && !IS_NEWLINE(t)) - { - t++; - ACROSSCHAR(t < end_subject, t, t++); - } - } - else -#endif - while (t < end_subject && !IS_NEWLINE(t)) t++; - end_subject = t; - } - - /* Anchored: check the first code unit if one is recorded. This may seem - pointless but it can help in detecting a no match case without scanning for - the required code unit. */ - - if (anchored) - { - if (has_first_cu || start_bits != NULL) - { - BOOL ok = start_match < end_subject; - if (ok) - { - PCRE2_UCHAR c = UCHAR21TEST(start_match); - ok = has_first_cu && (c == first_cu || c == first_cu2); - if (!ok && start_bits != NULL) - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (c > 255) c = 255; -#endif - ok = (start_bits[c/8] & (1u << (c&7))) != 0; - } - } - if (!ok) - { - rc = MATCH_NOMATCH; - break; - } - } - } - - /* Not anchored. Advance to a unique first code unit if there is one. */ - - else - { - if (has_first_cu) - { - if (first_cu != first_cu2) /* Caseless */ - { - /* In 16-bit and 32_bit modes we have to do our own search, so can - look for both cases at once. */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 - PCRE2_UCHAR smc; - while (start_match < end_subject && - (smc = UCHAR21TEST(start_match)) != first_cu && - smc != first_cu2) - start_match++; -#else - /* In 8-bit mode, the use of memchr() gives a big speed up, even - though we have to call it twice in order to find the earliest - occurrence of the code unit in either of its cases. Caching is used - to remember the positions of previously found code units. This can - make a huge difference when the strings are very long and only one - case is actually present. */ - - PCRE2_SPTR pp1 = NULL; - PCRE2_SPTR pp2 = NULL; - PCRE2_SIZE searchlength = end_subject - start_match; - - /* If we haven't got a previously found position for first_cu, or if - the current starting position is later, we need to do a search. If - the code unit is not found, set it to the end. */ - - if (memchr_found_first_cu == NULL || - start_match > memchr_found_first_cu) - { - pp1 = memchr(start_match, first_cu, searchlength); - memchr_found_first_cu = (pp1 == NULL)? end_subject : pp1; - } - - /* If the start is before a previously found position, use the - previous position, or NULL if a previous search failed. */ - - else pp1 = (memchr_found_first_cu == end_subject)? NULL : - memchr_found_first_cu; - - /* Do the same thing for the other case. */ - - if (memchr_found_first_cu2 == NULL || - start_match > memchr_found_first_cu2) - { - pp2 = memchr(start_match, first_cu2, searchlength); - memchr_found_first_cu2 = (pp2 == NULL)? end_subject : pp2; - } - - else pp2 = (memchr_found_first_cu2 == end_subject)? NULL : - memchr_found_first_cu2; - - /* Set the start to the end of the subject if neither case was found. - Otherwise, use the earlier found point. */ - - if (pp1 == NULL) - start_match = (pp2 == NULL)? end_subject : pp2; - else - start_match = (pp2 == NULL || pp1 < pp2)? pp1 : pp2; - -#endif /* 8-bit handling */ - } - - /* The caseful case is much simpler. */ - - else - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - while (start_match < end_subject && UCHAR21TEST(start_match) != - first_cu) - start_match++; -#else - start_match = memchr(start_match, first_cu, end_subject - start_match); - if (start_match == NULL) start_match = end_subject; -#endif - } - - /* If we can't find the required first code unit, having reached the - true end of the subject, break the bumpalong loop, to force a match - failure, except when doing partial matching, when we let the next cycle - run at the end of the subject. To see why, consider the pattern - /(?<=abc)def/, which partially matches "abc", even though the string - does not contain the starting character "d". If we have not reached the - true end of the subject (PCRE2_FIRSTLINE caused end_subject to be - temporarily modified) we also let the cycle run, because the matching - string is legitimately allowed to start with the first code unit of a - newline. */ - - if (mb->partial == 0 && start_match >= mb->end_subject) - { - rc = MATCH_NOMATCH; - break; - } - } - - /* If there's no first code unit, advance to just after a linebreak for a - multiline match if required. */ - - else if (startline) - { - if (start_match > mb->start_subject + start_offset) - { -#ifdef SUPPORT_UNICODE - if (utf) - { - while (start_match < end_subject && !WAS_NEWLINE(start_match)) - { - start_match++; - ACROSSCHAR(start_match < end_subject, start_match, start_match++); - } - } - else -#endif - while (start_match < end_subject && !WAS_NEWLINE(start_match)) - start_match++; - - /* If we have just passed a CR and the newline option is ANY or - ANYCRLF, and we are now at a LF, advance the match position by one - more code unit. */ - - if (start_match[-1] == CHAR_CR && - (mb->nltype == NLTYPE_ANY || mb->nltype == NLTYPE_ANYCRLF) && - start_match < end_subject && - UCHAR21TEST(start_match) == CHAR_NL) - start_match++; - } - } - - /* If there's no first code unit or a requirement for a multiline line - start, advance to a non-unique first code unit if any have been - identified. The bitmap contains only 256 bits. When code units are 16 or - 32 bits wide, all code units greater than 254 set the 255 bit. */ - - else if (start_bits != NULL) - { - while (start_match < end_subject) - { - uint32_t c = UCHAR21TEST(start_match); -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (c > 255) c = 255; -#endif - if ((start_bits[c/8] & (1u << (c&7))) != 0) break; - start_match++; - } - - /* See comment above in first_cu checking about the next few lines. */ - - if (mb->partial == 0 && start_match >= mb->end_subject) - { - rc = MATCH_NOMATCH; - break; - } - } - } /* End first code unit handling */ - - /* Restore fudged end_subject */ - - end_subject = mb->end_subject; - - /* The following two optimizations must be disabled for partial matching. */ - - if (mb->partial == 0) - { - PCRE2_SPTR p; - - /* The minimum matching length is a lower bound; no string of that length - may actually match the pattern. Although the value is, strictly, in - characters, we treat it as code units to avoid spending too much time in - this optimization. */ - - if (end_subject - start_match < re->minlength) - { - rc = MATCH_NOMATCH; - break; - } - - /* If req_cu is set, we know that that code unit must appear in the - subject for the (non-partial) match to succeed. If the first code unit is - set, req_cu must be later in the subject; otherwise the test starts at - the match point. This optimization can save a huge amount of backtracking - in patterns with nested unlimited repeats that aren't going to match. - Writing separate code for caseful/caseless versions makes it go faster, - as does using an autoincrement and backing off on a match. As in the case - of the first code unit, using memchr() in the 8-bit library gives a big - speed up. Unlike the first_cu check above, we do not need to call - memchr() twice in the caseless case because we only need to check for the - presence of the character in either case, not find the first occurrence. - - The search can be skipped if the code unit was found later than the - current starting point in a previous iteration of the bumpalong loop. - - HOWEVER: when the subject string is very, very long, searching to its end - can take a long time, and give bad performance on quite ordinary - anchored patterns. This showed up when somebody was matching something - like /^\d+C/ on a 32-megabyte string... so we don't do this when the - string is sufficiently long, but it's worth searching a lot more for - unanchored patterns. */ - - p = start_match + (has_first_cu? 1:0); - if (has_req_cu && p > req_cu_ptr) - { - PCRE2_SIZE check_length = end_subject - start_match; - - if (check_length < REQ_CU_MAX || - (!anchored && check_length < REQ_CU_MAX * 1000)) - { - if (req_cu != req_cu2) /* Caseless */ - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - while (p < end_subject) - { - uint32_t pp = UCHAR21INCTEST(p); - if (pp == req_cu || pp == req_cu2) { p--; break; } - } -#else /* 8-bit code units */ - PCRE2_SPTR pp = p; - p = memchr(pp, req_cu, end_subject - pp); - if (p == NULL) - { - p = memchr(pp, req_cu2, end_subject - pp); - if (p == NULL) p = end_subject; - } -#endif /* PCRE2_CODE_UNIT_WIDTH != 8 */ - } - - /* The caseful case */ - - else - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - while (p < end_subject) - { - if (UCHAR21INCTEST(p) == req_cu) { p--; break; } - } - -#else /* 8-bit code units */ - p = memchr(p, req_cu, end_subject - p); - if (p == NULL) p = end_subject; -#endif - } - - /* If we can't find the required code unit, break the bumpalong loop, - forcing a match failure. */ - - if (p >= end_subject) - { - rc = MATCH_NOMATCH; - break; - } - - /* If we have found the required code unit, save the point where we - found it, so that we don't search again next time round the bumpalong - loop if the start hasn't yet passed this code unit. */ - - req_cu_ptr = p; - } - } - } - } - - /* ------------ End of start of match optimizations ------------ */ - - /* Give no match if we have passed the bumpalong limit. */ - - if (start_match > bumpalong_limit) - { - rc = MATCH_NOMATCH; - break; - } - - /* OK, we can now run the match. If "hitend" is set afterwards, remember the - first starting point for which a partial match was found. */ - - cb.start_match = (PCRE2_SIZE)(start_match - subject); - cb.callout_flags |= PCRE2_CALLOUT_STARTMATCH; - - mb->start_used_ptr = start_match; - mb->last_used_ptr = start_match; -#ifdef SUPPORT_UNICODE - mb->moptions = options | fragment_options; -#else - mb->moptions = options; -#endif - mb->match_call_count = 0; - mb->end_offset_top = 0; - mb->skip_arg_count = 0; - -#ifdef DEBUG_SHOW_OPS - fprintf(stderr, "++ Calling match()\n"); -#endif - - rc = match(start_match, mb->start_code, re->top_bracket, frame_size, - match_data, mb); - -#ifdef DEBUG_SHOW_OPS - fprintf(stderr, "++ match() returned %d\n\n", rc); -#endif - - if (mb->hitend && start_partial == NULL) - { - start_partial = mb->start_used_ptr; - match_partial = start_match; - } - - switch(rc) - { - /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched - the SKIP's arg was not found. In this circumstance, Perl ignores the SKIP - entirely. The only way we can do that is to re-do the match at the same - point, with a flag to force SKIP with an argument to be ignored. Just - treating this case as NOMATCH does not work because it does not check other - alternatives in patterns such as A(*SKIP:A)B|AC when the subject is AC. */ - - case MATCH_SKIP_ARG: - new_start_match = start_match; - mb->ignore_skip_arg = mb->skip_arg_count; - break; - - /* SKIP passes back the next starting point explicitly, but if it is no - greater than the match we have just done, treat it as NOMATCH. */ - - case MATCH_SKIP: - if (mb->verb_skip_ptr > start_match) - { - new_start_match = mb->verb_skip_ptr; - break; - } - PCRE2_FALLTHROUGH /* Fall through */ - - /* NOMATCH and PRUNE advance by one character. THEN at this level acts - exactly like PRUNE. Unset ignore SKIP-with-argument. */ - - case MATCH_NOMATCH: - case MATCH_PRUNE: - case MATCH_THEN: - mb->ignore_skip_arg = 0; - new_start_match = start_match + 1; -#ifdef SUPPORT_UNICODE - if (utf) - ACROSSCHAR(new_start_match < end_subject, new_start_match, - new_start_match++); -#endif - break; - - /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */ - - case MATCH_COMMIT: - rc = MATCH_NOMATCH; - goto ENDLOOP; - - /* Any other return is either a match, or some kind of error. */ - - default: - goto ENDLOOP; - } - - /* Control reaches here for the various types of "no match at this point" - result. Reset the code to MATCH_NOMATCH for subsequent checking. */ - - rc = MATCH_NOMATCH; - - /* If PCRE2_FIRSTLINE is set, the match must happen before or at the first - newline in the subject (though it may continue over the newline). Therefore, - if we have just failed to match, starting at a newline, do not continue. */ - - if (firstline && IS_NEWLINE(start_match)) break; - - /* Advance to new matching position */ - - start_match = new_start_match; - - /* Break the loop if the pattern is anchored or if we have passed the end of - the subject. */ - - if (anchored || start_match > end_subject) break; - - /* If we have just passed a CR and we are now at a LF, and the pattern does - not contain any explicit matches for \r or \n, and the newline option is CRLF - or ANY or ANYCRLF, advance the match position by one more code unit. In - normal matching start_match will aways be greater than the first position at - this stage, but a failed *SKIP can cause a return at the same point, which is - why the first test exists. */ - - if (start_match > subject + start_offset && - start_match[-1] == CHAR_CR && - start_match < end_subject && - *start_match == CHAR_NL && - (re->flags & PCRE2_HASCRORLF) == 0 && - (mb->nltype == NLTYPE_ANY || - mb->nltype == NLTYPE_ANYCRLF || - mb->nllen == 2)) - start_match++; - - mb->mark = NULL; /* Reset for start of next match attempt */ - } /* End of for(;;) "bumpalong" loop */ - -/* ==========================================================================*/ - -/* When we reach here, one of the following stopping conditions is true: - -(1) The match succeeded, either completely, or partially; - -(2) The pattern is anchored or the match was failed after (*COMMIT); - -(3) We are past the end of the subject or the bumpalong limit; - -(4) PCRE2_FIRSTLINE is set and we have failed to match at a newline, because - this option requests that a match occur at or before the first newline in - the subject. - -(5) Some kind of error occurred. - -*/ - -ENDLOOP: - -/* If end_subject != true_end_subject, it means we are handling invalid UTF, -and have just processed a non-terminal fragment. If this resulted in no match -or a partial match we must carry on to the next fragment (a partial match is -returned to the caller only at the very end of the subject). A loop is used to -avoid trying to match against empty fragments; if the pattern can match an -empty string it would have done so already. */ - -#ifdef SUPPORT_UNICODE -if (utf && end_subject != true_end_subject && - (rc == MATCH_NOMATCH || rc == PCRE2_ERROR_PARTIAL)) - { - for (;;) - { - /* Advance past the first bad code unit, and then skip invalid character - starting code units in 8-bit and 16-bit modes. */ - - start_match = end_subject + 1; - -#if PCRE2_CODE_UNIT_WIDTH != 32 - while (start_match < true_end_subject && NOT_FIRSTCU(*start_match)) - start_match++; -#endif - - /* If we have hit the end of the subject, there isn't another non-empty - fragment, so give up. */ - - if (start_match >= true_end_subject) - { - rc = MATCH_NOMATCH; /* In case it was partial */ - match_partial = NULL; - break; - } - - /* Check the rest of the subject */ - - mb->check_subject = start_match; - rc = PRIV(valid_utf)(start_match, length - (start_match - subject), - &(match_data->startchar)); - - /* The rest of the subject is valid UTF. */ - - if (rc == 0) - { - mb->end_subject = end_subject = true_end_subject; - fragment_options = PCRE2_NOTBOL; - goto FRAGMENT_RESTART; - } - - /* A subsequent UTF error has been found; if the next fragment is - non-empty, set up to process it. Otherwise, let the loop advance. */ - - else if (rc < 0) - { - mb->end_subject = end_subject = start_match + match_data->startchar; - if (end_subject > start_match) - { - fragment_options = PCRE2_NOTBOL|PCRE2_NOTEOL; - goto FRAGMENT_RESTART; - } - } - } - } -#endif /* SUPPORT_UNICODE */ - -/* Fill in fields that are always returned in the match data. */ - -match_data->code = re; -match_data->mark = mb->mark; -match_data->matchedby = PCRE2_MATCHEDBY_INTERPRETER; -match_data->options = original_options; - -/* Handle a fully successful match. Set the return code to the number of -captured strings, or 0 if there were too many to fit into the ovector, and then -set the remaining returned values before returning. Make a copy of the subject -string if requested. */ - -if (rc == MATCH_MATCH) - { - match_data->rc = ((int)mb->end_offset_top >= 2 * match_data->oveccount)? - 0 : (int)mb->end_offset_top/2 + 1; - match_data->subject_length = length; - match_data->start_offset = start_offset; - match_data->startchar = start_match - subject; - match_data->leftchar = mb->start_used_ptr - subject; - match_data->rightchar = ((mb->last_used_ptr > mb->end_match_ptr)? - mb->last_used_ptr : mb->end_match_ptr) - subject; - if ((options & PCRE2_COPY_MATCHED_SUBJECT) != 0) - { - if (length != 0) - { - match_data->subject = match_data->memctl.malloc(CU2BYTES(length), - match_data->memctl.memory_data); - if (match_data->subject == NULL) - return match_data->rc = PCRE2_ERROR_NOMEMORY; - memcpy((void *)match_data->subject, subject, CU2BYTES(length)); - } - else - match_data->subject = NULL; - match_data->flags |= PCRE2_MD_COPIED_SUBJECT; - } - else match_data->subject = original_subject; - - return match_data->rc; - } - -/* Control gets here if there has been a partial match, an error, or if the -overall match attempt has failed at all permitted starting positions. Any mark -data is in the nomatch_mark field. */ - -match_data->mark = mb->nomatch_mark; - -/* For anything other than nomatch or partial match, just return the code. */ - -if (rc != MATCH_NOMATCH && rc != PCRE2_ERROR_PARTIAL) match_data->rc = rc; - -/* Handle a partial match. If a "soft" partial match was requested, searching -for a complete match will have continued, and the value of rc at this point -will be MATCH_NOMATCH. For a "hard" partial match, it will already be -PCRE2_ERROR_PARTIAL. */ - -else if (match_partial != NULL) - { - match_data->subject = original_subject; - match_data->subject_length = length; - match_data->start_offset = start_offset; - match_data->ovector[0] = match_partial - subject; - match_data->ovector[1] = end_subject - subject; - match_data->startchar = match_partial - subject; - match_data->leftchar = start_partial - subject; - match_data->rightchar = end_subject - subject; - match_data->rc = PCRE2_ERROR_PARTIAL; - } - -/* Else this is the classic nomatch case. */ - -else - { - match_data->subject = original_subject; - match_data->subject_length = length; - match_data->start_offset = start_offset; - match_data->rc = PCRE2_ERROR_NOMATCH; - } - -return match_data->rc; -} - -/* These #undefs are here to enable unity builds with CMake. */ - -#undef NLBLOCK /* Block containing newline information */ -#undef PSSTART /* Field containing processed string start */ -#undef PSEND /* Field containing processed string end */ - -/* End of pcre2_match.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match_data.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match_data.c deleted file mode 100644 index fade67a..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match_data.c +++ /dev/null @@ -1,184 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Create a match data block given ovector size * -*************************************************/ - -/* A minimum of 1 is imposed on the number of ovector pairs. A maximum is also -imposed because the oveccount field in a match data block is uintt6_t. */ - -PCRE2_EXP_DEFN pcre2_match_data * PCRE2_CALL_CONVENTION -pcre2_match_data_create(uint32_t oveccount, pcre2_general_context *gcontext) -{ -pcre2_match_data *yield; -if (oveccount < 1) oveccount = 1; -if (oveccount > UINT16_MAX) oveccount = UINT16_MAX; -yield = PRIV(memctl_malloc)( - offsetof(pcre2_match_data, ovector) + 2*oveccount*sizeof(PCRE2_SIZE), - (pcre2_memctl *)gcontext); -if (yield == NULL) return NULL; -yield->oveccount = oveccount; -yield->flags = 0; -yield->heapframes = NULL; -yield->heapframes_size = 0; -return yield; -} - - - -/************************************************* -* Create a match data block using pattern data * -*************************************************/ - -/* If no context is supplied, use the memory allocator from the code. This code -assumes that a general context contains nothing other than a memory allocator. -If that ever changes, this code will need fixing. */ - -PCRE2_EXP_DEFN pcre2_match_data * PCRE2_CALL_CONVENTION -pcre2_match_data_create_from_pattern(const pcre2_code *code, - pcre2_general_context *gcontext) -{ -if (code == NULL) return NULL; -if (gcontext == NULL) gcontext = (pcre2_general_context *)code; -return pcre2_match_data_create(((const pcre2_real_code *)code)->top_bracket + 1, - gcontext); -} - - - -/************************************************* -* Free a match data block * -*************************************************/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_match_data_free(pcre2_match_data *match_data) -{ -if (match_data != NULL) - { - if (match_data->heapframes != NULL) - match_data->memctl.free(match_data->heapframes, - match_data->memctl.memory_data); - if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0) - match_data->memctl.free((void *)match_data->subject, - match_data->memctl.memory_data); - match_data->memctl.free(match_data, match_data->memctl.memory_data); - } -} - - - -/************************************************* -* Get last mark in match * -*************************************************/ - -PCRE2_EXP_DEFN PCRE2_SPTR PCRE2_CALL_CONVENTION -pcre2_get_mark(pcre2_match_data *match_data) -{ -return match_data->mark; -} - - - -/************************************************* -* Get pointer to ovector * -*************************************************/ - -PCRE2_EXP_DEFN PCRE2_SIZE * PCRE2_CALL_CONVENTION -pcre2_get_ovector_pointer(pcre2_match_data *match_data) -{ -return match_data->ovector; -} - - - -/************************************************* -* Get number of ovector slots * -*************************************************/ - -PCRE2_EXP_DEFN uint32_t PCRE2_CALL_CONVENTION -pcre2_get_ovector_count(pcre2_match_data *match_data) -{ -return match_data->oveccount; -} - - - -/************************************************* -* Get starting code unit in match * -*************************************************/ - -PCRE2_EXP_DEFN PCRE2_SIZE PCRE2_CALL_CONVENTION -pcre2_get_startchar(pcre2_match_data *match_data) -{ -return match_data->startchar; -} - - - -/************************************************* -* Get size of match data block * -*************************************************/ - -PCRE2_EXP_DEFN PCRE2_SIZE PCRE2_CALL_CONVENTION -pcre2_get_match_data_size(pcre2_match_data *match_data) -{ -return offsetof(pcre2_match_data, ovector) + - 2 * (match_data->oveccount) * sizeof(PCRE2_SIZE); -} - - - -/************************************************* -* Get heapframes size * -*************************************************/ - -PCRE2_EXP_DEFN PCRE2_SIZE PCRE2_CALL_CONVENTION -pcre2_get_match_data_heapframes_size(pcre2_match_data *match_data) -{ -return match_data->heapframes_size; -} - -/* End of pcre2_match_data.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match_next.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match_next.c deleted file mode 100644 index ecd21d3..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_match_next.c +++ /dev/null @@ -1,171 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -/* Advance the offset by one code unit, and return the new value. -It is only called when the offset is not at the end of the subject. */ - -static PCRE2_SIZE do_bumpalong(pcre2_match_data *match_data, - PCRE2_SIZE offset) -{ -PCRE2_SPTR subject = match_data->subject; -PCRE2_SIZE subject_length = match_data->subject_length; -#ifdef SUPPORT_UNICODE -BOOL utf = (match_data->code->overall_options & PCRE2_UTF) != 0; -#endif - -/* Skip over CRLF as an atomic sequence, if CRLF is configured as a newline -sequence. */ - -if (subject[offset] == CHAR_CR && offset + 1 < subject_length && - subject[offset + 1] == CHAR_LF) - { - switch(match_data->code->newline_convention) - { - case PCRE2_NEWLINE_CRLF: - case PCRE2_NEWLINE_ANY: - case PCRE2_NEWLINE_ANYCRLF: - return offset + 2; - } - } - -/* Advance by one full character if in UTF mode. */ - -#ifdef SUPPORT_UNICODE -if (utf) - { - PCRE2_SPTR next = subject + offset + 1; - PCRE2_SPTR subject_end = subject + subject_length; - - (void)subject_end; /* Suppress warning; 32-bit FORWARDCHARTEST ignores this */ - FORWARDCHARTEST(next, subject_end); - return next - subject; - } -#endif - -return offset + 1; -} - - - -/************************************************* -* Advance the match * -*************************************************/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_next_match(pcre2_match_data *match_data, PCRE2_SIZE *pstart_offset, - uint32_t *poptions) -{ -int rc = match_data->rc; -PCRE2_SIZE start_offset = match_data->start_offset; -PCRE2_SIZE *ovector = match_data->ovector; - -/* Match error, or no match: no further iteration possible. In previous versions -of PCRE2, we recommended that clients use a strategy which involved retrying in -certain cases after PCRE2_ERROR_NOMATCH, but this is no longer required. */ - -if (rc < 0) - return FALSE; - -/* Match succeeded: get the start offset for the next match */ - -/* Although \K can affect the position of ovector[0], there are no ways to do -anything surprising with ovector[1], which must always be >= start_offset. */ - -PCRE2_ASSERT(ovector[1] >= start_offset); - -/* Special handling for patterns which contain \K in a lookaround, which enables -the match start to be pushed back to before the starting search offset -(ovector[0] < start_offset) or after the match ends (ovector[0] > ovector[1]). -This is not a problem if ovector[1] > start_offset, because in this case, we can -just attempt the next match at ovector[1]: we are making progress, which is all -that we require. - -However, if we have ovector[1] == start_offset, then we have a very rare case -which must be handled specially, because it's a non-empty match which -nonetheless fails to make progress through the subject. */ - -if (ovector[0] != start_offset && ovector[1] == start_offset) - { - /* If the match end is at the end of the subject, we are done. */ - - if (start_offset >= match_data->subject_length) - return FALSE; - - /* Otherwise, bump along by one code unit, and do a normal search. */ - - *pstart_offset = do_bumpalong(match_data, ovector[1]); - *poptions = 0; - return TRUE; - } - -/* If the previous match was for an empty string, we are finished if we are at -the end of the subject. Otherwise, arrange to run another match at the same -point to see if a non-empty match can be found. */ - -if (ovector[0] == ovector[1]) - { - /* If the match is at the end of the subject, we are done. */ - - if (ovector[0] >= match_data->subject_length) - return FALSE; - - /* Otherwise, continue at this exact same point, but we must set the flag - which ensures that we don't return the exact same empty match again. */ - - *pstart_offset = ovector[1]; - *poptions = PCRE2_NOTEMPTY_ATSTART; - return TRUE; - } - -/* Finally, we must be in the happy state of a non-empty match, where the end of -the match is further on in the subject than start_offset, so we are easily able -to continue and make progress. */ - -*pstart_offset = ovector[1]; -*poptions = 0; -return TRUE; -} - -/* End of pcre2_match_next.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_newline.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_newline.c deleted file mode 100644 index a7c9299..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_newline.c +++ /dev/null @@ -1,239 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains internal functions for testing newlines when more than -one kind of newline is to be recognized. When a newline is found, its length is -returned. In principle, we could implement several newline "types", each -referring to a different set of newline characters. At present, PCRE2 supports -only NLTYPE_FIXED, which gets handled without these functions, NLTYPE_ANYCRLF, -and NLTYPE_ANY. The full list of Unicode newline characters is taken from -http://unicode.org/unicode/reports/tr18/. */ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Check for newline at given position * -*************************************************/ - -/* This function is called only via the IS_NEWLINE macro, which does so only -when the newline type is NLTYPE_ANY or NLTYPE_ANYCRLF. The case of a fixed -newline (NLTYPE_FIXED) is handled inline. It is guaranteed that the code unit -pointed to by ptr is less than the end of the string. - -Arguments: - ptr pointer to possible newline - type the newline type - endptr pointer to the end of the string - lenptr where to return the length - utf TRUE if in utf mode - -Returns: TRUE or FALSE -*/ - -BOOL -PRIV(is_newline)(PCRE2_SPTR ptr, uint32_t type, PCRE2_SPTR endptr, - uint32_t *lenptr, BOOL utf) -{ -uint32_t c; - -#ifdef SUPPORT_UNICODE -if (utf) { GETCHAR(c, ptr); } else c = *ptr; -#else -(void)utf; -c = *ptr; -#endif /* SUPPORT_UNICODE */ - -if (type == NLTYPE_ANYCRLF) switch(c) - { - case CHAR_LF: - *lenptr = 1; - return TRUE; - - case CHAR_CR: - *lenptr = (ptr < endptr - 1 && ptr[1] == CHAR_LF)? 2 : 1; - return TRUE; - - default: - return FALSE; - } - -/* NLTYPE_ANY */ - -else switch(c) - { -#ifdef EBCDIC - case CHAR_NEL: -#endif - case CHAR_LF: - case CHAR_VT: - case CHAR_FF: - *lenptr = 1; - return TRUE; - - case CHAR_CR: - *lenptr = (ptr < endptr - 1 && ptr[1] == CHAR_LF)? 2 : 1; - return TRUE; - -#ifndef EBCDIC -#if PCRE2_CODE_UNIT_WIDTH == 8 - case CHAR_NEL: - *lenptr = utf? 2 : 1; - return TRUE; - - case 0x2028: /* LS */ - case 0x2029: /* PS */ - *lenptr = 3; - return TRUE; - -#else /* 16-bit or 32-bit code units */ - case CHAR_NEL: - case 0x2028: /* LS */ - case 0x2029: /* PS */ - *lenptr = 1; - return TRUE; -#endif -#endif /* Not EBCDIC */ - - default: - return FALSE; - } -} - - - -/************************************************* -* Check for newline at previous position * -*************************************************/ - -/* This function is called only via the WAS_NEWLINE macro, which does so only -when the newline type is NLTYPE_ANY or NLTYPE_ANYCRLF. The case of a fixed -newline (NLTYPE_FIXED) is handled inline. It is guaranteed that the initial -value of ptr is greater than the start of the string that is being processed. - -Arguments: - ptr pointer to possible newline - type the newline type - startptr pointer to the start of the string - lenptr where to return the length - utf TRUE if in utf mode - -Returns: TRUE or FALSE -*/ - -BOOL -PRIV(was_newline)(PCRE2_SPTR ptr, uint32_t type, PCRE2_SPTR startptr, - uint32_t *lenptr, BOOL utf) -{ -uint32_t c; -ptr--; - -#ifdef SUPPORT_UNICODE -if (utf) - { - BACKCHAR(ptr); - GETCHAR(c, ptr); - } -else c = *ptr; -#else -(void)utf; -c = *ptr; -#endif /* SUPPORT_UNICODE */ - -if (type == NLTYPE_ANYCRLF) switch(c) - { - case CHAR_LF: - *lenptr = (ptr > startptr && ptr[-1] == CHAR_CR)? 2 : 1; - return TRUE; - - case CHAR_CR: - *lenptr = 1; - return TRUE; - - default: - return FALSE; - } - -/* NLTYPE_ANY */ - -else switch(c) - { - case CHAR_LF: - *lenptr = (ptr > startptr && ptr[-1] == CHAR_CR)? 2 : 1; - return TRUE; - -#ifdef EBCDIC - case CHAR_NEL: -#endif - case CHAR_VT: - case CHAR_FF: - case CHAR_CR: - *lenptr = 1; - return TRUE; - -#ifndef EBCDIC -#if PCRE2_CODE_UNIT_WIDTH == 8 - case CHAR_NEL: - *lenptr = utf? 2 : 1; - return TRUE; - - case 0x2028: /* LS */ - case 0x2029: /* PS */ - *lenptr = 3; - return TRUE; - -#else /* 16-bit or 32-bit code units */ - case CHAR_NEL: - case 0x2028: /* LS */ - case 0x2029: /* PS */ - *lenptr = 1; - return TRUE; -#endif -#endif /* Not EBCDIC */ - - default: - return FALSE; - } -} - -/* End of pcre2_newline.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_ord2utf.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_ord2utf.c deleted file mode 100644 index 1339483..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_ord2utf.c +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This file contains a function that converts a Unicode character code point -into a UTF string. The behaviour is different for each code unit width. */ - - -#include "pcre2_internal.h" - - - -/* If SUPPORT_UNICODE is not defined, this function will never be called. -Supply a dummy function because some compilers do not like empty source -modules. */ - -#ifndef SUPPORT_UNICODE -unsigned int -PRIV(ord2utf)(uint32_t cvalue, PCRE2_UCHAR *buffer) -{ -(void)(cvalue); -(void)(buffer); -return 0; -} -#else /* SUPPORT_UNICODE */ - - -/************************************************* -* Convert code point to UTF * -*************************************************/ - -/* -Arguments: - cvalue the character value - buffer pointer to buffer for result - -Returns: number of code units placed in the buffer -*/ - -unsigned int -PRIV(ord2utf)(uint32_t cvalue, PCRE2_UCHAR *buffer) -{ -/* Convert to UTF-8 */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -unsigned int i, j; - -for (i = 0; i < PRIV(utf8_table1_size); i++) - if ((int)cvalue <= PRIV(utf8_table1)[i]) break; -buffer += i; -for (j = i; j != 0; j--) - { - *buffer-- = 0x80 | (cvalue & 0x3f); - cvalue >>= 6; - } -*buffer = (PCRE2_UCHAR)(PRIV(utf8_table2)[i] | (int)cvalue); -return i + 1; - -/* Convert to UTF-16 */ - -#elif PCRE2_CODE_UNIT_WIDTH == 16 -if (cvalue <= 0xffff) - { - *buffer = (PCRE2_UCHAR)cvalue; - return 1; - } -cvalue -= 0x10000; -*buffer++ = 0xd800 | (cvalue >> 10); -*buffer = 0xdc00 | (cvalue & 0x3ff); -return 2; - -/* Convert to UTF-32 */ - -#else -*buffer = (PCRE2_UCHAR)cvalue; -return 1; -#endif -} -#endif /* SUPPORT_UNICODE */ - -/* End of pcre2_ord2utf.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_pattern_info.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_pattern_info.c deleted file mode 100644 index e0bd83a..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_pattern_info.c +++ /dev/null @@ -1,430 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Return info about compiled pattern * -*************************************************/ - -/* -Arguments: - code points to compiled code - what what information is required - where where to put the information; if NULL, return length - -Returns: 0 when data returned - > 0 when length requested - < 0 on error or unset value -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_pattern_info(const pcre2_code *code, uint32_t what, void *where) -{ -const pcre2_real_code *re = (const pcre2_real_code *)code; - -if (where == NULL) /* Requests field length */ - { - switch(what) - { - case PCRE2_INFO_ALLOPTIONS: - case PCRE2_INFO_ARGOPTIONS: - case PCRE2_INFO_BACKREFMAX: - case PCRE2_INFO_BSR: - case PCRE2_INFO_CAPTURECOUNT: - case PCRE2_INFO_DEPTHLIMIT: - case PCRE2_INFO_EXTRAOPTIONS: - case PCRE2_INFO_FIRSTCODETYPE: - case PCRE2_INFO_FIRSTCODEUNIT: - case PCRE2_INFO_HASBACKSLASHC: - case PCRE2_INFO_HASCRORLF: - case PCRE2_INFO_HEAPLIMIT: - case PCRE2_INFO_JCHANGED: - case PCRE2_INFO_LASTCODETYPE: - case PCRE2_INFO_LASTCODEUNIT: - case PCRE2_INFO_MATCHEMPTY: - case PCRE2_INFO_MATCHLIMIT: - case PCRE2_INFO_MAXLOOKBEHIND: - case PCRE2_INFO_MINLENGTH: - case PCRE2_INFO_NAMEENTRYSIZE: - case PCRE2_INFO_NAMECOUNT: - case PCRE2_INFO_NEWLINE: - return sizeof(uint32_t); - - case PCRE2_INFO_FIRSTBITMAP: - return sizeof(const uint8_t *); - - case PCRE2_INFO_JITSIZE: - case PCRE2_INFO_SIZE: - case PCRE2_INFO_FRAMESIZE: - return sizeof(size_t); - - case PCRE2_INFO_NAMETABLE: - return sizeof(PCRE2_SPTR); - } - } - -if (re == NULL) return PCRE2_ERROR_NULL; - -/* Check that the first field in the block is the magic number. If it is not, -return with PCRE2_ERROR_BADMAGIC. */ - -if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; - -/* Check that this pattern was compiled in the correct bit mode */ - -if ((re->flags & (PCRE2_CODE_UNIT_WIDTH/8)) == 0) return PCRE2_ERROR_BADMODE; - -switch(what) - { - case PCRE2_INFO_ALLOPTIONS: - *((uint32_t *)where) = re->overall_options; - break; - - case PCRE2_INFO_ARGOPTIONS: - *((uint32_t *)where) = re->compile_options; - break; - - case PCRE2_INFO_BACKREFMAX: - *((uint32_t *)where) = re->top_backref; - break; - - case PCRE2_INFO_BSR: - *((uint32_t *)where) = re->bsr_convention; - break; - - case PCRE2_INFO_CAPTURECOUNT: - *((uint32_t *)where) = re->top_bracket; - break; - - case PCRE2_INFO_DEPTHLIMIT: - *((uint32_t *)where) = re->limit_depth; - if (re->limit_depth == UINT32_MAX) return PCRE2_ERROR_UNSET; - break; - - case PCRE2_INFO_EXTRAOPTIONS: - *((uint32_t *)where) = re->extra_options; - break; - - case PCRE2_INFO_FIRSTCODETYPE: - *((uint32_t *)where) = ((re->flags & PCRE2_FIRSTSET) != 0)? 1 : - ((re->flags & PCRE2_STARTLINE) != 0)? 2 : 0; - break; - - case PCRE2_INFO_FIRSTCODEUNIT: - *((uint32_t *)where) = ((re->flags & PCRE2_FIRSTSET) != 0)? - re->first_codeunit : 0; - break; - - case PCRE2_INFO_FIRSTBITMAP: - *((const uint8_t **)where) = ((re->flags & PCRE2_FIRSTMAPSET) != 0)? - &(re->start_bitmap[0]) : NULL; - break; - - case PCRE2_INFO_FRAMESIZE: - *((size_t *)where) = offsetof(heapframe, ovector) + - re->top_bracket * 2 * sizeof(PCRE2_SIZE); - break; - - case PCRE2_INFO_HASBACKSLASHC: - *((uint32_t *)where) = (re->flags & PCRE2_HASBKC) != 0; - break; - - case PCRE2_INFO_HASCRORLF: - *((uint32_t *)where) = (re->flags & PCRE2_HASCRORLF) != 0; - break; - - case PCRE2_INFO_HEAPLIMIT: - *((uint32_t *)where) = re->limit_heap; - if (re->limit_heap == UINT32_MAX) return PCRE2_ERROR_UNSET; - break; - - case PCRE2_INFO_JCHANGED: - *((uint32_t *)where) = (re->flags & PCRE2_JCHANGED) != 0; - break; - - case PCRE2_INFO_JITSIZE: -#ifdef SUPPORT_JIT - *((size_t *)where) = (re->executable_jit != NULL)? - PRIV(jit_get_size)(re->executable_jit) : 0; -#else - *((size_t *)where) = 0; -#endif - break; - - case PCRE2_INFO_LASTCODETYPE: - *((uint32_t *)where) = ((re->flags & PCRE2_LASTSET) != 0)? 1 : 0; - break; - - case PCRE2_INFO_LASTCODEUNIT: - *((uint32_t *)where) = ((re->flags & PCRE2_LASTSET) != 0)? - re->last_codeunit : 0; - break; - - case PCRE2_INFO_MATCHEMPTY: - *((uint32_t *)where) = (re->flags & PCRE2_MATCH_EMPTY) != 0; - break; - - case PCRE2_INFO_MATCHLIMIT: - *((uint32_t *)where) = re->limit_match; - if (re->limit_match == UINT32_MAX) return PCRE2_ERROR_UNSET; - break; - - case PCRE2_INFO_MAXLOOKBEHIND: - *((uint32_t *)where) = re->max_lookbehind; - break; - - case PCRE2_INFO_MINLENGTH: - *((uint32_t *)where) = re->minlength; - break; - - case PCRE2_INFO_NAMEENTRYSIZE: - *((uint32_t *)where) = re->name_entry_size; - break; - - case PCRE2_INFO_NAMECOUNT: - *((uint32_t *)where) = re->name_count; - break; - - case PCRE2_INFO_NAMETABLE: - *((PCRE2_SPTR *)where) = (PCRE2_SPTR)((const char *)re + - sizeof(pcre2_real_code)); - break; - - case PCRE2_INFO_NEWLINE: - *((uint32_t *)where) = re->newline_convention; - break; - - case PCRE2_INFO_SIZE: - *((size_t *)where) = re->blocksize; - break; - - default: return PCRE2_ERROR_BADOPTION; - } - -return 0; -} - - - -/************************************************* -* Callout enumerator * -*************************************************/ - -/* -Arguments: - code points to compiled code - callback function called for each callout block - callout_data user data passed to the callback - -Returns: 0 when successfully completed - < 0 on local error - != 0 for callback error -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_callout_enumerate(const pcre2_code *code, - int (*callback)(pcre2_callout_enumerate_block *, void *), void *callout_data) -{ -const pcre2_real_code *re = (const pcre2_real_code *)code; -pcre2_callout_enumerate_block cb; -PCRE2_SPTR cc; -#ifdef SUPPORT_UNICODE -BOOL utf; -#endif - -if (re == NULL) return PCRE2_ERROR_NULL; - -#ifdef SUPPORT_UNICODE -utf = (re->overall_options & PCRE2_UTF) != 0; -#endif - -/* Check that the first field in the block is the magic number. If it is not, -return with PCRE2_ERROR_BADMAGIC. */ - -if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; - -/* Check that this pattern was compiled in the correct bit mode */ - -if ((re->flags & (PCRE2_CODE_UNIT_WIDTH/8)) == 0) return PCRE2_ERROR_BADMODE; - -cb.version = 0; -cc = (PCRE2_SPTR)((uint8_t *)re + re->code_start); - -while (TRUE) - { - int rc; - switch (*cc) - { - case OP_END: - return 0; - - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - case OP_STAR: - case OP_MINSTAR: - case OP_PLUS: - case OP_MINPLUS: - case OP_QUERY: - case OP_MINQUERY: - case OP_UPTO: - case OP_MINUPTO: - case OP_EXACT: - case OP_POSSTAR: - case OP_POSPLUS: - case OP_POSQUERY: - case OP_POSUPTO: - case OP_STARI: - case OP_MINSTARI: - case OP_PLUSI: - case OP_MINPLUSI: - case OP_QUERYI: - case OP_MINQUERYI: - case OP_UPTOI: - case OP_MINUPTOI: - case OP_EXACTI: - case OP_POSSTARI: - case OP_POSPLUSI: - case OP_POSQUERYI: - case OP_POSUPTOI: - case OP_NOTSTAR: - case OP_NOTMINSTAR: - case OP_NOTPLUS: - case OP_NOTMINPLUS: - case OP_NOTQUERY: - case OP_NOTMINQUERY: - case OP_NOTUPTO: - case OP_NOTMINUPTO: - case OP_NOTEXACT: - case OP_NOTPOSSTAR: - case OP_NOTPOSPLUS: - case OP_NOTPOSQUERY: - case OP_NOTPOSUPTO: - case OP_NOTSTARI: - case OP_NOTMINSTARI: - case OP_NOTPLUSI: - case OP_NOTMINPLUSI: - case OP_NOTQUERYI: - case OP_NOTMINQUERYI: - case OP_NOTUPTOI: - case OP_NOTMINUPTOI: - case OP_NOTEXACTI: - case OP_NOTPOSSTARI: - case OP_NOTPOSPLUSI: - case OP_NOTPOSQUERYI: - case OP_NOTPOSUPTOI: - cc += PRIV(OP_lengths)[*cc]; -#ifdef SUPPORT_UNICODE - if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEEXACT: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - case OP_TYPEPOSUPTO: - cc += PRIV(OP_lengths)[*cc]; -#ifdef SUPPORT_UNICODE - if (cc[-1] == OP_PROP || cc[-1] == OP_NOTPROP) cc += 2; -#endif - break; - -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - case OP_ECLASS: - cc += GET(cc, 1); - break; -#endif - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_SKIP_ARG: - case OP_THEN_ARG: - cc += PRIV(OP_lengths)[*cc] + cc[1]; - break; - - case OP_CALLOUT: - cb.pattern_position = GET(cc, 1); - cb.next_item_length = GET(cc, 1 + LINK_SIZE); - cb.callout_number = cc[1 + 2*LINK_SIZE]; - cb.callout_string_offset = 0; - cb.callout_string_length = 0; - cb.callout_string = NULL; - rc = callback(&cb, callout_data); - if (rc != 0) return rc; - cc += PRIV(OP_lengths)[*cc]; - break; - - case OP_CALLOUT_STR: - cb.pattern_position = GET(cc, 1); - cb.next_item_length = GET(cc, 1 + LINK_SIZE); - cb.callout_number = 0; - cb.callout_string_offset = GET(cc, 1 + 3*LINK_SIZE); - cb.callout_string_length = - GET(cc, 1 + 2*LINK_SIZE) - (1 + 4*LINK_SIZE) - 2; - cb.callout_string = cc + (1 + 4*LINK_SIZE) + 1; - rc = callback(&cb, callout_data); - if (rc != 0) return rc; - cc += GET(cc, 1 + 2*LINK_SIZE); - break; - - default: - cc += PRIV(OP_lengths)[*cc]; - break; - } - } -} - -/* End of pcre2_pattern_info.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_printint_inc.h b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_printint_inc.h deleted file mode 100644 index 4dd689e..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_printint_inc.h +++ /dev/null @@ -1,1098 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains a PCRE private debugging function for printing out the -internal form of a compiled regular expression, along with some supporting -local functions. This source file is #included in pcre2test.c at each supported -code unit width, with PCRE2_SUFFIX set appropriately, just like the functions -that comprise the library. It can also optionally be included in -pcre2_compile.c for detailed debugging in error situations. */ - - - -/* Tables of operator names. The same 8-bit table is used for all code unit -widths, so it must be defined only once. The list itself is defined in -pcre2_internal.h, which is #included by pcre2test before this file. */ - -#ifndef OP_LISTS_DEFINED -static const char *OP_names[] = { OP_NAME_LIST }; -STATIC_ASSERT(sizeof(OP_names)/sizeof(*OP_names) == OP_TABLE_LENGTH, OP_names); -#define OP_LISTS_DEFINED -#endif - -/* The functions and tables herein must all have mode-dependent names. */ - -#define OP_lengths PCRE2_SUFFIX(OP_lengths_) -#define get_ucpname PCRE2_SUFFIX(get_ucpname_) -#define pcre2_printint PCRE2_SUFFIX(pcre2_printint_) -#define print_char PCRE2_SUFFIX(print_char_) -#define print_custring PCRE2_SUFFIX(print_custring_) -#define print_custring_bylen PCRE2_SUFFIX(print_custring_bylen_) -#define print_prop PCRE2_SUFFIX(print_prop_) -#define print_char_list PCRE2_SUFFIX(print_char_list_) -#define print_map PCRE2_SUFFIX(print_map_) -#define print_class PCRE2_SUFFIX(print_class_) - -/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that -the definition is next to the definition of the opcodes in pcre2_internal.h. -The contents of the table are, however, mode-dependent. */ - -static const uint8_t OP_lengths[] = { OP_LENGTHS }; -STATIC_ASSERT(sizeof(OP_lengths)/sizeof(*OP_lengths) == OP_TABLE_LENGTH, - PCRE2_SUFFIX(OP_lengths_)); - - -/************************************************* -* Print one character from a string * -*************************************************/ - -/* In UTF mode the character may occupy more than one code unit. - -Arguments: - f file to write to - ptr pointer to first code unit of the character - utf TRUE if string is UTF (will be FALSE if UTF is not supported) - -Returns: number of additional code units used -*/ - -static unsigned int -print_char(FILE *f, PCRE2_SPTR ptr, BOOL utf) -{ -uint32_t c = *ptr; -BOOL one_code_unit = !utf; - -/* If UTF is supported and requested, check for a valid single code unit. */ - -#ifdef SUPPORT_UNICODE -if (utf) - { -#if PCRE2_CODE_UNIT_WIDTH == 8 - one_code_unit = c < 0x80; -#elif PCRE2_CODE_UNIT_WIDTH == 16 - one_code_unit = (c & 0xfc00) != 0xd800; -#else - one_code_unit = (c & 0xfffff800u) != 0xd800u; -#endif /* CODE_UNIT_WIDTH */ - } -#endif /* SUPPORT_UNICODE */ - -/* Handle a valid one-code-unit character at any width. */ - -if (one_code_unit) - { - if (PRINTABLE(c)) - fprintf(f, "%c", CHAR_OUTPUT(c)); - else - { - c = CHAR_OUTPUT_HEX(c); - if (c < 0x80) fprintf(f, "\\x%02x", c); - else fprintf(f, "\\x{%02x}", c); - } - return 0; - } - -/* Code for invalid UTF code units and multi-unit UTF characters is different -for each width. If UTF is not supported, control should never get here, but we -need a return statement to keep the compiler happy. */ - -#ifndef SUPPORT_UNICODE -return 0; -#else - -/* Malformed UTF-8 should occur only if the sanity check has been turned off. -Rather than swallow random bytes, just stop if we hit a bad one. Print it with -\X instead of \x as an indication. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 -if ((c & 0xc0) != 0xc0) - { - fprintf(f, "\\X{%x}", c); /* Invalid starting byte */ - return 0; - } -else - { - int i; - int a = PRIV(utf8_table4)[c & 0x3f]; /* Number of additional bytes */ - int s = 6*a; - c = (c & PRIV(utf8_table3)[a]) << s; - for (i = 1; i <= a; i++) - { - if ((ptr[i] & 0xc0) != 0x80) - { - fprintf(f, "\\X{%x}", c); /* Invalid secondary byte */ - return i - 1; - } - s -= 6; - c |= (ptr[i] & 0x3f) << s; - } - fprintf(f, "\\x{%x}", c); - return a; -} -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - -/* UTF-16: rather than swallow a low surrogate, just stop if we hit a bad one. -Print it with \X instead of \x as an indication. */ - -#if PCRE2_CODE_UNIT_WIDTH == 16 -if ((ptr[1] & 0xfc00) != 0xdc00) - { - fprintf(f, "\\X{%x}", c); - return 0; - } -c = (((c & 0x3ff) << 10) | (ptr[1] & 0x3ff)) + 0x10000; -fprintf(f, "\\x{%x}", c); -return 1; -#endif /* PCRE2_CODE_UNIT_WIDTH == 16 */ - -/* For UTF-32 we get here only for a malformed code unit, which should only -occur if the sanity check has been turned off. Print it with \X instead of \x -as an indication. */ - -#if PCRE2_CODE_UNIT_WIDTH == 32 -fprintf(f, "\\X{%x}", c); -return 0; -#endif /* PCRE2_CODE_UNIT_WIDTH == 32 */ -#endif /* SUPPORT_UNICODE */ -} - - - -/************************************************* -* Print string as a list of code units * -*************************************************/ - -/* These take no account of UTF as they always print each individual code unit. -The string is zero-terminated for print_custring(); the length is given for -print_custring_bylen(). - -Arguments: - f file to write to - ptr point to the string - len length for print_custring_bylen() - -Returns: nothing -*/ - -static void -print_custring(FILE *f, PCRE2_SPTR ptr) -{ -while (*ptr != '\0') - { - uint32_t c = *ptr++; - if (PRINTABLE(c)) fprintf(f, "%c", CHAR_OUTPUT(c)); - else fprintf(f, "\\x{%x}", CHAR_OUTPUT_HEX(c)); - } -} - -static void -print_custring_bylen(FILE *f, PCRE2_SPTR ptr, PCRE2_UCHAR len) -{ -for (; len > 0; len--) - { - uint32_t c = *ptr++; - if (PRINTABLE(c)) fprintf(f, "%c", CHAR_OUTPUT(c)); - else fprintf(f, "\\x{%x}", CHAR_OUTPUT_HEX(c)); - } -} - - - -/************************************************* -* Find Unicode property name * -*************************************************/ - -/* When there is no UTF/UCP support, the table of names does not exist. This -function should not be called in such configurations, because a pattern that -tries to use Unicode properties won't compile. Rather than put lots of #ifdefs -into the main code, however, we just put one into this function. - -Now that the table contains both full names and their abbreviations, we do some -fiddling to try to get the full name, which is either the longer of two found -names, or a 3-character script name. */ - -static const char * -get_ucpname(unsigned int ptype, unsigned int pvalue) -{ -#ifdef SUPPORT_UNICODE -int count = 0; -const char *yield = "??"; -size_t len = 0; -unsigned int ptypex = (ptype == PT_SC)? PT_SCX : ptype; - -for (ptrdiff_t i = PRIV(utt_size) - 1; i >= 0; i--) - { - const ucp_type_table *u = PRIV(utt) + i; - - if ((ptype == u->type || ptypex == u->type) && pvalue == u->value) - { - const char *s = PRIV(utt_names) + u->name_offset; - size_t sl = strlen(s); - - if (sl == 3 && (u->type == PT_SC || u->type == PT_SCX)) - { - yield = s; - break; - } - - if (sl > len) - { - yield = s; - len = sl; - } - - if (++count >= 2) break; - } - } - -return yield; - -#else /* No UTF support */ -(void)ptype; -(void)pvalue; -return "??"; -#endif /* SUPPORT_UNICODE */ -} - - - -/************************************************* -* Print Unicode property value * -*************************************************/ - -/* "Normal" properties can be printed from tables. The PT_CLIST property is a -pseudo-property that contains a pointer to a list of case-equivalent -characters. - -Arguments: - f file to write to - code pointer in the compiled code - before text to print before - after text to print after - -Returns: nothing -*/ - -static void -print_prop(FILE *f, PCRE2_SPTR code, const char *before, const char *after) -{ -if (code[1] != PT_CLIST) - { - const char *sc = (code[1] == PT_SC)? "script:" : ""; - const char *s = get_ucpname(code[1], code[2]); - fprintf(f, "%s%s %s%c%s%s", before, OP_names[*code], sc, toupper(s[0]), s+1, after); - } -else - { - const uint32_t *p = PRIV(ucd_caseless_sets) + code[2]; - fprintf (f, "%s%sclist", before, (*code == OP_PROP)? "" : "not "); - while (*p < NOTACHAR) fprintf(f, " %04x", *p++); - fprintf(f, "%s", after); - } -} - - - -/************************************************* -* Print character list * -*************************************************/ - -/* Prints the characters and character ranges in a character list. - -Arguments: - f file to write to - code pointer in the compiled code -*/ - -static PCRE2_SPTR -print_char_list(FILE *f, PCRE2_SPTR code, const uint8_t *char_lists_end) -{ -uint32_t type, list_ind; -uint32_t char_list_add = XCL_CHAR_LIST_LOW_16_ADD; -uint32_t range_start = ~(uint32_t)0, range_end = 0; -const uint8_t *next_char; - -#if PCRE2_CODE_UNIT_WIDTH == 8 -type = (uint32_t)(code[0] << 8) | code[1]; -code += 2; -#else -type = code[0]; -code++; -#endif /* CODE_UNIT_WIDTH */ - -/* Align characters. */ -next_char = char_lists_end - (GET(code, 0) << 1); -type &= XCL_TYPE_MASK; -list_ind = 0; - -if ((type & XCL_BEGIN_WITH_RANGE) != 0) - range_start = XCL_CHAR_LIST_LOW_16_START; - -while (type > 0) - { - uint32_t item_count = type & XCL_ITEM_COUNT_MASK; - - if (item_count == XCL_ITEM_COUNT_MASK) - { - if (list_ind <= 1) - { - item_count = *(const uint16_t*)next_char; - next_char += 2; - } - else - { - item_count = *(const uint32_t*)next_char; - next_char += 4; - } - } - - while (item_count > 0) - { - if (list_ind <= 1) - { - range_end = *(const uint16_t*)next_char; - next_char += 2; - } - else - { - range_end = *(const uint32_t*)next_char; - next_char += 4; - } - - if ((range_end & XCL_CHAR_END) != 0) - { - range_end = char_list_add + (range_end >> XCL_CHAR_SHIFT); - - if (range_start < range_end) - fprintf(f, "\\x{%x}-", range_start); - - fprintf(f, "\\x{%x}", range_end); - range_start = ~(uint32_t)0; - } - else - range_start = char_list_add + (range_end >> XCL_CHAR_SHIFT); - - item_count--; - } - - list_ind++; - type >>= XCL_TYPE_BIT_LEN; - - /* The following code could be optimized to 8/16/32 bit, - but it is not worth it for a debugging function. */ - - if (range_start == ~(uint32_t)0) - { - if ((type & XCL_BEGIN_WITH_RANGE) != 0) - { - if (list_ind == 1) range_start = XCL_CHAR_LIST_HIGH_16_START; - else if (list_ind == 2) range_start = XCL_CHAR_LIST_LOW_32_START; - else range_start = XCL_CHAR_LIST_HIGH_32_START; - } - } - else if ((type & XCL_BEGIN_WITH_RANGE) == 0) - { - fprintf(f, "\\x{%x}-", range_start); - - if (list_ind == 1) range_end = XCL_CHAR_LIST_LOW_16_END; - else if (list_ind == 2) range_end = XCL_CHAR_LIST_HIGH_16_END; - else if (list_ind == 3) range_end = XCL_CHAR_LIST_LOW_32_END; - else range_end = XCL_CHAR_LIST_HIGH_32_END; - - fprintf(f, "\\x{%x}", range_end); - range_start = ~(uint32_t)0; - } - - if (list_ind == 1) char_list_add = XCL_CHAR_LIST_HIGH_16_ADD; - else if (list_ind == 2) char_list_add = XCL_CHAR_LIST_LOW_32_ADD; - else char_list_add = XCL_CHAR_LIST_HIGH_32_ADD; - } - -return code + LINK_SIZE; -} - - - -/************************************************* -* Print a character bitmap * -*************************************************/ - -/* Prints a 32-byte bitmap, which occurs within a character class opcode. - -Arguments: - f file to write to - map pointer to the bitmap - negated TRUE if the bitmap will be printed as negated - -Returns: nothing -*/ - -static void -print_map(FILE *f, const uint8_t *map, BOOL negated) -{ -BOOL first = TRUE; -uint8_t inverted_map[32]; -int i, input; - -if (negated) - { - /* Using 255 ^ instead of ~ avoids clang sanitize warning. */ - for (i = 0; i < 32; i++) inverted_map[i] = 255 ^ map[i]; - map = inverted_map; - } - -for (input = 0; input < 256; input++) - { - i = CHAR_INPUT_HEX(input); - if ((map[i/8] & (1u << (i&7))) != 0) - { - int j, jinput; - for (jinput = input; jinput+1 < 256; jinput++) - { - j = CHAR_INPUT_HEX(jinput+1); - if ((map[j/8] & (1u << (j&7))) == 0) break; - } - j = CHAR_INPUT_HEX(jinput); - if (i == CHAR_MINUS || i == CHAR_BACKSLASH || - i == CHAR_RIGHT_SQUARE_BRACKET || - (first && i == CHAR_CIRCUMFLEX_ACCENT)) - fprintf(f, "\\"); - if (PRINTABLE(i)) fprintf(f, "%c", CHAR_OUTPUT(i)); - else fprintf(f, "\\x%02x", CHAR_OUTPUT_HEX(i)); - first = FALSE; - if (jinput > input) - { - if (jinput != input + 1) fprintf(f, "-"); - if (j == CHAR_MINUS || j == CHAR_BACKSLASH || - j == CHAR_RIGHT_SQUARE_BRACKET) - fprintf(f, "\\"); - if (PRINTABLE(j)) fprintf(f, "%c", CHAR_OUTPUT(j)); - else fprintf(f, "\\x%02x", CHAR_OUTPUT_HEX(j)); - } - input = jinput; - } - } -} - - - -/************************************************* -* Print character class * -*************************************************/ - -/* Prints a character class, which must be either an OP_CLASS, OP_NCLASS, or -OP_XCLASS. - -Arguments: - f file to write to - type OP_CLASS, OP_NCLASS, or OP_XCLASS - code pointer in the compiled code (after the OP tag) - utf TRUE if re is UTF (will be FALSE if UTF is not supported) - before text to print before - after text to print after - -Returns: nothing -*/ - -static void -print_class(FILE *f, int type, PCRE2_SPTR code, const uint8_t *char_lists_end, - BOOL utf, const char *before, const char *after) -{ -BOOL printmap, negated; -PCRE2_SPTR ccode; - -/* Negative XCLASS and NCLASS both have a bitmap indicating which characters -are accepted. For clarity we print this inverted and prefixed by "^". */ -if (type == OP_XCLASS) - { - ccode = code + LINK_SIZE; - printmap = (*ccode & XCL_MAP) != 0; - negated = (*ccode & XCL_NOT) != 0; - ccode++; - } -else /* CLASS or NCLASS */ - { - printmap = TRUE; - negated = type == OP_NCLASS; - ccode = code; - } - -fprintf(f, "%s[%s", before, negated? "^" : ""); - -/* Print a bit map */ -if (printmap) - { - print_map(f, (const uint8_t *)ccode, negated); - ccode += 32 / sizeof(PCRE2_UCHAR); - } - -/* For an XCLASS there is always some additional data */ -if (type == OP_XCLASS) - { - PCRE2_UCHAR ch; - - while ((ch = *ccode++) != XCL_END) - { - const char *notch = ""; - - if (ch >= XCL_LIST) - { - ccode = print_char_list(f, ccode - 1, char_lists_end); - break; - } - - switch(ch) - { - case XCL_NOTPROP: - notch = "^"; - PCRE2_FALLTHROUGH /* Fall through */ - case XCL_PROP: - { - unsigned int ptype = *ccode++; - unsigned int pvalue = *ccode++; - const char *s; - switch(ptype) - { - case PT_PXGRAPH: - fprintf(f, "[:%sgraph:]", notch); - break; - case PT_PXPRINT: - fprintf(f, "[:%sprint:]", notch); - break; - case PT_PXPUNCT: - fprintf(f, "[:%spunct:]", notch); - break; - case PT_PXXDIGIT: - fprintf(f, "[:%sxdigit:]", notch); - break; - default: - s = get_ucpname(ptype, pvalue); - fprintf(f, "\\%c{%c%s}", ((notch[0] == '^')? 'P':'p'), - toupper(s[0]), s+1); - break; - } - } - break; - - default: - ccode += 1 + print_char(f, ccode, utf); - if (ch == XCL_RANGE) - { - fprintf(f, "-"); - ccode += 1 + print_char(f, ccode, utf); - } - break; - } - } - - PCRE2_ASSERT(ccode == code + (GET(code, 0) - 1)); - } - -/* Indicate a non-UTF class which was created by negation */ -fprintf(f, "]%s", after); -} - - - -/************************************************* -* Print compiled pattern * -*************************************************/ - -/* The print_lengths flag controls whether offsets and lengths of items are -printed. Lenths can be turned off from pcre2test so that automatic tests on -bytecode can be written that do not depend on the value of LINK_SIZE. - -Arguments: - re a compiled pattern - f the file to write to - print_lengths show various lengths - -Returns: nothing -*/ - -static void -pcre2_printint(pcre2_code *re, FILE *f, BOOL print_lengths) -{ -PCRE2_SPTR codestart, nametable, code; -uint32_t nesize = re->name_entry_size; -BOOL utf = (re->overall_options & PCRE2_UTF) != 0; - -nametable = (PCRE2_SPTR)((uint8_t *)re + sizeof(pcre2_real_code)); -code = codestart = (PCRE2_SPTR)((uint8_t *)re + re->code_start); - -for(;;) - { - PCRE2_SPTR ccode; - uint32_t c; - int i; - const char *flag = " "; - unsigned int extra = 0; - - if (print_lengths) - fprintf(f, "%3d ", (int)(code - codestart)); - else - fprintf(f, " "); - - switch(*code) - { - case OP_END: - fprintf(f, " %s\n", OP_names[*code]); - fprintf(f, "------------------------------------------------------------------\n"); - return; - - case OP_CHAR: - fprintf(f, " "); - do - { - code++; - code += 1 + print_char(f, code, utf); - } - while (*code == OP_CHAR); - fprintf(f, "\n"); - continue; - - case OP_CHARI: - fprintf(f, " /i "); - do - { - code++; - code += 1 + print_char(f, code, utf); - } - while (*code == OP_CHARI); - fprintf(f, "\n"); - continue; - - case OP_CBRA: - case OP_CBRAPOS: - case OP_SCBRA: - case OP_SCBRAPOS: - if (print_lengths) fprintf(f, "%3d ", GET(code, 1)); - else fprintf(f, " "); - fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE)); - break; - - case OP_BRA: - case OP_BRAPOS: - case OP_SBRA: - case OP_SBRAPOS: - case OP_KETRMAX: - case OP_KETRMIN: - case OP_KETRPOS: - case OP_ALT: - case OP_KET: - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_COND: - case OP_SCOND: - if (print_lengths) fprintf(f, "%3d ", GET(code, 1)); - else fprintf(f, " "); - fprintf(f, "%s", OP_names[*code]); - break; - - case OP_CLOSE: - fprintf(f, " %s %d", OP_names[*code], GET2(code, 1)); - break; - - case OP_CREF: - case OP_REVERSE: - case OP_VREVERSE: - fprintf(f, "%3d %s", GET2(code, 1), OP_names[*code]); - if (*code == OP_VREVERSE) fprintf(f, " %d", GET2(code, 1 + IMM2_SIZE)); - break; - - case OP_DNCREF: - case OP_DNRREF: - { - PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE; - fprintf(f, " %s %s<", flag, OP_names[*code]); - print_custring(f, entry); - fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE)); - } - break; - - case OP_RREF: - c = GET2(code, 1); - if (c == RREF_ANY) - fprintf(f, " %s any", OP_names[*code]); - else - fprintf(f, " %s %d", OP_names[*code], c); - break; - - case OP_STARI: - case OP_MINSTARI: - case OP_POSSTARI: - case OP_PLUSI: - case OP_MINPLUSI: - case OP_POSPLUSI: - case OP_QUERYI: - case OP_MINQUERYI: - case OP_POSQUERYI: - flag = "/i"; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_STAR: - case OP_MINSTAR: - case OP_POSSTAR: - case OP_PLUS: - case OP_MINPLUS: - case OP_POSPLUS: - case OP_QUERY: - case OP_MINQUERY: - case OP_POSQUERY: - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPOSSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEPOSPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEPOSQUERY: - fprintf(f, " %s ", flag); - - if (*code >= OP_TYPESTAR) - { - if (code[1] == OP_PROP || code[1] == OP_NOTPROP) - { - print_prop(f, code + 1, "", " "); - extra = 2; - } - else fprintf(f, "%s", OP_names[code[1]]); - } - else extra = print_char(f, code+1, utf); - fprintf(f, "%s", OP_names[*code]); - break; - - case OP_EXACTI: - case OP_UPTOI: - case OP_MINUPTOI: - case OP_POSUPTOI: - flag = "/i"; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_EXACT: - case OP_UPTO: - case OP_MINUPTO: - case OP_POSUPTO: - fprintf(f, " %s ", flag); - extra = print_char(f, code + 1 + IMM2_SIZE, utf); - fprintf(f, "{"); - if (*code != OP_EXACT && *code != OP_EXACTI) fprintf(f, "0,"); - fprintf(f, "%d}", GET2(code,1)); - if (*code == OP_MINUPTO || *code == OP_MINUPTOI) fprintf(f, "?"); - else if (*code == OP_POSUPTO || *code == OP_POSUPTOI) fprintf(f, "+"); - break; - - case OP_TYPEEXACT: - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEPOSUPTO: - if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP) - { - print_prop(f, code + IMM2_SIZE + 1, " ", " "); - extra = 2; - } - else fprintf(f, " %s", OP_names[code[1 + IMM2_SIZE]]); - fprintf(f, "{"); - if (*code != OP_TYPEEXACT) fprintf(f, "0,"); - fprintf(f, "%d}", GET2(code,1)); - if (*code == OP_TYPEMINUPTO) fprintf(f, "?"); - else if (*code == OP_TYPEPOSUPTO) fprintf(f, "+"); - break; - - case OP_NOTI: - flag = "/i"; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_NOT: - fprintf(f, " %s [^", flag); - extra = print_char(f, code + 1, utf); - fprintf(f, "] (not)"); - break; - - case OP_NOTSTARI: - case OP_NOTMINSTARI: - case OP_NOTPOSSTARI: - case OP_NOTPLUSI: - case OP_NOTMINPLUSI: - case OP_NOTPOSPLUSI: - case OP_NOTQUERYI: - case OP_NOTMINQUERYI: - case OP_NOTPOSQUERYI: - flag = "/i"; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_NOTSTAR: - case OP_NOTMINSTAR: - case OP_NOTPOSSTAR: - case OP_NOTPLUS: - case OP_NOTMINPLUS: - case OP_NOTPOSPLUS: - case OP_NOTQUERY: - case OP_NOTMINQUERY: - case OP_NOTPOSQUERY: - fprintf(f, " %s [^", flag); - extra = print_char(f, code + 1, utf); - fprintf(f, "]%s (not)", OP_names[*code]); - break; - - case OP_NOTEXACTI: - case OP_NOTUPTOI: - case OP_NOTMINUPTOI: - case OP_NOTPOSUPTOI: - flag = "/i"; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_NOTEXACT: - case OP_NOTUPTO: - case OP_NOTMINUPTO: - case OP_NOTPOSUPTO: - fprintf(f, " %s [^", flag); - extra = print_char(f, code + 1 + IMM2_SIZE, utf); - fprintf(f, "]{"); - if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,"); - fprintf(f, "%d}", GET2(code,1)); - if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?"); - else - if (*code == OP_NOTPOSUPTO || *code == OP_NOTPOSUPTOI) fprintf(f, "+"); - fprintf(f, " (not)"); - break; - - case OP_RECURSE: - if (print_lengths) fprintf(f, "%3d ", GET(code, 1)); - else fprintf(f, " "); - fprintf(f, "%s", OP_names[*code]); - break; - - case OP_REFI: - flag = "/i"; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_REF: - fprintf(f, " %s \\g{%d}", flag, GET2(code, 1)); - i = (*code == OP_REFI)? code[1 + IMM2_SIZE] : 0; - if (i != 0) fprintf(f, " 0x%02x", i); - ccode = code + OP_lengths[*code]; - goto CLASS_REF_REPEAT; - - case OP_DNREFI: - flag = "/i"; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_DNREF: - { - PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE; - fprintf(f, " %s \\k<", flag); - print_custring(f, entry); - fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE)); - i = (*code == OP_DNREFI)? code[1 + 2*IMM2_SIZE] : 0; - if (i != 0) fprintf(f, " 0x%02x", i); - } - ccode = code + OP_lengths[*code]; - goto CLASS_REF_REPEAT; - - case OP_CALLOUT: - fprintf(f, " %s %d %d %d", OP_names[*code], code[1 + 2*LINK_SIZE], - GET(code, 1), GET(code, 1 + LINK_SIZE)); - break; - - case OP_CALLOUT_STR: - c = code[1 + 4*LINK_SIZE]; - fprintf(f, " %s %c", OP_names[*code], CHAR_OUTPUT(c)); - extra = GET(code, 1 + 2*LINK_SIZE); - print_custring_bylen(f, code + 2 + 4*LINK_SIZE, extra - 3 - 4*LINK_SIZE); - for (i = 0; PRIV(callout_start_delims)[i] != 0; i++) - if (c == PRIV(callout_start_delims)[i]) - { - c = PRIV(callout_end_delims)[i]; - break; - } - fprintf(f, "%c %d %d %d", CHAR_OUTPUT(c), GET(code, 1 + 3*LINK_SIZE), - GET(code, 1), GET(code, 1 + LINK_SIZE)); - break; - - case OP_PROP: - case OP_NOTPROP: - print_prop(f, code, " ", ""); - break; - -#ifdef SUPPORT_WIDE_CHARS - case OP_ECLASS: - extra = GET(code, 1); - fprintf(f, " eclass[\n"); - /* We print the opcodes contained inside as well. */ - ccode = code + 1 + LINK_SIZE + 1; - if ((ccode[-1] & ECL_MAP) != 0) - { - const uint8_t *map = (const uint8_t *)ccode; - /* The first 6 ASCII characters (SOH...ACK) are totally, utterly useless. - If they're set in the bitmap, then it's clearly been formed by negation.*/ - BOOL print_negated = (map[0] & 0x7e) == 0x7e; - - fprintf(f, " bitmap: [%s", print_negated? "^" : ""); - print_map(f, map, print_negated); - fprintf(f, "]\n"); - ccode += 32 / sizeof(PCRE2_UCHAR); - } - else - fprintf(f, " no bitmap\n"); - while (ccode < code + extra) - { - if (print_lengths) - fprintf(f, "%3d ", (int)(ccode - codestart)); - else - fprintf(f, " "); - - switch (*ccode) - { - case ECL_AND: - fprintf(f, " AND\n"); - ccode += 1; - break; - case ECL_OR: - fprintf(f, " OR\n"); - ccode += 1; - break; - case ECL_XOR: - fprintf(f, " XOR\n"); - ccode += 1; - break; - case ECL_NOT: - fprintf(f, " NOT\n"); - ccode += 1; - break; - - case ECL_XCLASS: - print_class(f, OP_XCLASS, ccode+1, (uint8_t*)codestart, utf, - " xclass: ", "\n"); - ccode += GET(ccode, 1); - break; - - default: - fprintf(f, " UNEXPECTED\n"); - ccode += 1; - break; - } - } - fprintf(f, " ]"); - goto CLASS_REF_REPEAT; -#endif /* SUPPORT_WIDE_CHARS */ - - case OP_CLASS: - case OP_NCLASS: -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - if (*code == OP_XCLASS) - extra = GET(code, 1); -#endif - print_class(f, *code, code+1, (uint8_t*)codestart, utf, " ", ""); - ccode = code + OP_lengths[*code] + extra; - - /* Handle repeats after a class or a back reference */ - - CLASS_REF_REPEAT: - switch(*ccode) - { - unsigned int min, max; - - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSSTAR: - case OP_CRPOSPLUS: - case OP_CRPOSQUERY: - fprintf(f, "%s", OP_names[*ccode]); - extra += OP_lengths[*ccode]; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - min = GET2(ccode,1); - max = GET2(ccode,1 + IMM2_SIZE); - if (max == 0) fprintf(f, "{%u,}", min); - else fprintf(f, "{%u,%u}", min, max); - if (*ccode == OP_CRMINRANGE) fprintf(f, "?"); - else if (*ccode == OP_CRPOSRANGE) fprintf(f, "+"); - extra += OP_lengths[*ccode]; - break; - - /* Do nothing if it's not a repeat; this code stops picky compilers - warning about the lack of a default code path. */ - - default: - break; - } - break; - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_SKIP_ARG: - case OP_THEN_ARG: - fprintf(f, " %s ", OP_names[*code]); - print_custring_bylen(f, code + 2, code[1]); - extra += code[1]; - break; - - case OP_CIRCM: - case OP_DOLLM: - flag = "/m"; - PCRE2_FALLTHROUGH /* Fall through */ - - /* Anything else is just an item with no data, but possibly a flag. */ - - default: - fprintf(f, " %s %s", flag, OP_names[*code]); - break; - } - - code += OP_lengths[*code] + extra; - putc('\n', f); - } -} - -/* End of pcre2_printint_inc.h */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_script_run.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_script_run.c deleted file mode 100644 index dac6f3a..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_script_run.c +++ /dev/null @@ -1,344 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2021 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains the function for checking a script run. */ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Check script run * -*************************************************/ - -/* A script run is conceptually a sequence of characters all in the same -Unicode script. However, it isn't quite that simple. There are special rules -for scripts that are commonly used together, and also special rules for digits. -This function implements the appropriate checks, which is possible only when -PCRE2 is compiled with Unicode support. The function returns TRUE if there is -no Unicode support; however, it should never be called in that circumstance -because an error is given by pcre2_compile() if a script run is called for in a -version of PCRE2 compiled without Unicode support. - -Arguments: - pgr point to the first character - endptr point after the last character - utf TRUE if in UTF mode - -Returns: TRUE if this is a valid script run -*/ - -/* These are states in the checking process. */ - -enum { SCRIPT_UNSET, /* Requirement as yet unknown */ - SCRIPT_MAP, /* Bitmap contains acceptable scripts */ - SCRIPT_HANPENDING, /* Have had only Han characters */ - SCRIPT_HANHIRAKATA, /* Expect Han or Hirikata */ - SCRIPT_HANBOPOMOFO, /* Expect Han or Bopomofo */ - SCRIPT_HANHANGUL /* Expect Han or Hangul */ - }; - -#define UCD_MAPSIZE (ucp_Unknown/32 + 1) -#define FULL_MAPSIZE (ucp_Script_Count/32 + 1) - -BOOL -PRIV(script_run)(PCRE2_SPTR ptr, PCRE2_SPTR endptr, BOOL utf) -{ -#ifdef SUPPORT_UNICODE -uint32_t require_state = SCRIPT_UNSET; -uint32_t require_map[FULL_MAPSIZE]; -uint32_t map[FULL_MAPSIZE]; -uint32_t require_digitset = 0; -uint32_t c; -int i; - -#if PCRE2_CODE_UNIT_WIDTH == 32 -(void)utf; /* Avoid compiler warning */ -#endif - -/* Any string containing fewer than 2 characters is a valid script run. */ - -if (ptr >= endptr) return TRUE; -GETCHARINCTEST(c, ptr); -if (ptr >= endptr) return TRUE; - -/* Initialize the require map. This is a full-size bitmap that has a bit for -every script, as opposed to the maps in ucd_script_sets, which only have bits -for scripts less than ucp_Unknown - those that appear in script extension -lists. */ - -for (i = 0; i < FULL_MAPSIZE; i++) require_map[i] = 0; - -/* Scan strings of two or more characters, checking the Unicode characteristics -of each code point. There is special code for scripts that can be combined with -characters from the Han Chinese script. This may be used in conjunction with -four other scripts in these combinations: - -. Han with Hiragana and Katakana is allowed (for Japanese). -. Han with Bopomofo is allowed (for Taiwanese Mandarin). -. Han with Hangul is allowed (for Korean). - -If the first significant character's script is one of the four, the required -script type is immediately known. However, if the first significant -character's script is Han, we have to keep checking for a non-Han character. -Hence the SCRIPT_HANPENDING state. */ - -for (;;) - { - const ucd_record *ucd = GET_UCD(c); - uint32_t script = ucd->script; - - /* If the script is Unknown, the string is not a valid script run. Such - characters can only form script runs of length one (see test above). */ - - if (script == ucp_Unknown) return FALSE; - - /* A character without any script extensions whose script is Inherited or - Common is always accepted with any script. If there are extensions, the - following processing happens for all scripts. */ - - if (UCD_SCRIPTX_PROP(ucd) != 0 || (script != ucp_Inherited && script != ucp_Common)) - { - BOOL OK; - - /* Set up a full-sized map for this character that can include bits for all - scripts. Copy the scriptx map for this character (which covers those - scripts that appear in script extension lists), set the remaining values to - zero, and then, except for Common or Inherited, add this script's bit to - the map. */ - - memcpy(map, PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(ucd), UCD_MAPSIZE * sizeof(uint32_t)); - memset(map + UCD_MAPSIZE, 0, (FULL_MAPSIZE - UCD_MAPSIZE) * sizeof(uint32_t)); - if (script != ucp_Common && script != ucp_Inherited) MAPSET(map, script); - - /* Handle the different checking states */ - - switch(require_state) - { - /* First significant character - it might follow Common or Inherited - characters that do not have any script extensions. */ - - case SCRIPT_UNSET: - switch(script) - { - case ucp_Han: - require_state = SCRIPT_HANPENDING; - break; - - case ucp_Hiragana: - case ucp_Katakana: - require_state = SCRIPT_HANHIRAKATA; - break; - - case ucp_Bopomofo: - require_state = SCRIPT_HANBOPOMOFO; - break; - - case ucp_Hangul: - require_state = SCRIPT_HANHANGUL; - break; - - default: - memcpy(require_map, map, FULL_MAPSIZE * sizeof(uint32_t)); - require_state = SCRIPT_MAP; - break; - } - break; - - /* The first significant character was Han. An inspection of the Unicode - 11.0.0 files shows that there are the following types of Script Extension - list that involve the Han, Bopomofo, Hiragana, Katakana, and Hangul - scripts: - - . Bopomofo + Han - . Han + Hiragana + Katakana - . Hiragana + Katakana - . Bopopmofo + Hangul + Han + Hiragana + Katakana - - The following code tries to make sense of this. */ - -#define FOUND_BOPOMOFO 1 -#define FOUND_HIRAGANA 2 -#define FOUND_KATAKANA 4 -#define FOUND_HANGUL 8 - - case SCRIPT_HANPENDING: - if (script != ucp_Han) /* Another Han does nothing */ - { - uint32_t chspecial = 0; - - if (MAPBIT(map, ucp_Bopomofo) != 0) chspecial |= FOUND_BOPOMOFO; - if (MAPBIT(map, ucp_Hiragana) != 0) chspecial |= FOUND_HIRAGANA; - if (MAPBIT(map, ucp_Katakana) != 0) chspecial |= FOUND_KATAKANA; - if (MAPBIT(map, ucp_Hangul) != 0) chspecial |= FOUND_HANGUL; - - if (chspecial == 0) return FALSE; /* Not allowed with Han */ - - if (chspecial == FOUND_BOPOMOFO) - require_state = SCRIPT_HANBOPOMOFO; - else if (chspecial == (FOUND_HIRAGANA|FOUND_KATAKANA)) - require_state = SCRIPT_HANHIRAKATA; - - /* Otherwise this character must be allowed with all of them, so remain - in the pending state. */ - } - break; - - /* Previously encountered one of the "with Han" scripts. Check that - this character is appropriate. */ - - case SCRIPT_HANHIRAKATA: - if (MAPBIT(map, ucp_Han) + MAPBIT(map, ucp_Hiragana) + - MAPBIT(map, ucp_Katakana) == 0) return FALSE; - break; - - case SCRIPT_HANBOPOMOFO: - if (MAPBIT(map, ucp_Han) + MAPBIT(map, ucp_Bopomofo) == 0) return FALSE; - break; - - case SCRIPT_HANHANGUL: - if (MAPBIT(map, ucp_Han) + MAPBIT(map, ucp_Hangul) == 0) return FALSE; - break; - - /* Previously encountered one or more characters that are allowed with a - list of scripts. */ - - case SCRIPT_MAP: - OK = FALSE; - - for (i = 0; i < FULL_MAPSIZE; i++) - { - if ((require_map[i] & map[i]) != 0) - { - OK = TRUE; - break; - } - } - - if (!OK) return FALSE; - - /* The rest of the string must be in this script, but we have to - allow for the Han complications. */ - - switch(script) - { - case ucp_Han: - require_state = SCRIPT_HANPENDING; - break; - - case ucp_Hiragana: - case ucp_Katakana: - require_state = SCRIPT_HANHIRAKATA; - break; - - case ucp_Bopomofo: - require_state = SCRIPT_HANBOPOMOFO; - break; - - case ucp_Hangul: - require_state = SCRIPT_HANHANGUL; - break; - - /* Compute the intersection of the required list of scripts and the - allowed scripts for this character. */ - - default: - for (i = 0; i < FULL_MAPSIZE; i++) require_map[i] &= map[i]; - break; - } - - break; - } - } /* End checking character's script and extensions. */ - - /* The character is in an acceptable script. We must now ensure that all - decimal digits in the string come from the same set. Some scripts (e.g. - Common, Arabic) have more than one set of decimal digits. This code does - not allow mixing sets, even within the same script. The vector called - PRIV(ucd_digit_sets)[] contains, in its first element, the number of - following elements, and then, in ascending order, the code points of the - '9' characters in every set of 10 digits. Each set is identified by the - offset in the vector of its '9' character. An initial check of the first - value picks up ASCII digits quickly. Otherwise, a binary chop is used. */ - - if (ucd->chartype == ucp_Nd) - { - uint32_t digitset; - - if (c <= PRIV(ucd_digit_sets)[1]) digitset = 1; else - { - int mid; - int bot = 1; - int top = PRIV(ucd_digit_sets)[0]; - for (;;) - { - if (top <= bot + 1) /* <= rather than == is paranoia */ - { - digitset = top; - break; - } - mid = (top + bot) / 2; - if (c <= PRIV(ucd_digit_sets)[mid]) top = mid; else bot = mid; - } - } - - /* A required value of 0 means "unset". */ - - if (require_digitset == 0) require_digitset = digitset; - else if (digitset != require_digitset) return FALSE; - } /* End digit handling */ - - /* If we haven't yet got to the end, pick up the next character. */ - - if (ptr >= endptr) return TRUE; - GETCHARINCTEST(c, ptr); - } /* End checking loop */ - -#else /* NOT SUPPORT_UNICODE */ -(void)ptr; -(void)endptr; -(void)utf; -return TRUE; -#endif /* SUPPORT_UNICODE */ -} - -/* End of pcre2_script_run.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_serialize.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_serialize.c deleted file mode 100644 index f10a3fa..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_serialize.c +++ /dev/null @@ -1,284 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains functions for serializing and deserializing -a sequence of compiled codes. */ - - -#include "pcre2_internal.h" - - - -/* Magic number to provide a small check against being handed junk. */ - -#define SERIALIZED_DATA_MAGIC 0x50523253u - -/* Deserialization is limited to the current PCRE version and -character width. */ - -#define SERIALIZED_DATA_VERSION \ - ((PCRE2_MAJOR) | ((PCRE2_MINOR) << 16)) - -#define SERIALIZED_DATA_CONFIG \ - (sizeof(PCRE2_UCHAR) | ((sizeof(void*)) << 8) | ((sizeof(PCRE2_SIZE)) << 16)) - - - -/************************************************* -* Serialize compiled patterns * -*************************************************/ - -PCRE2_EXP_DEFN int32_t PCRE2_CALL_CONVENTION -pcre2_serialize_encode(const pcre2_code **codes, int32_t number_of_codes, - uint8_t **serialized_bytes, PCRE2_SIZE *serialized_size, - pcre2_general_context *gcontext) -{ -uint8_t *bytes; -uint8_t *dst_bytes; -int32_t i; -PCRE2_SIZE total_size; -const pcre2_real_code *re; -const uint8_t *tables; -pcre2_serialized_data *data; - -const pcre2_memctl *memctl = (gcontext != NULL) ? - &gcontext->memctl : &PRIV(default_compile_context).memctl; - -if (codes == NULL || serialized_bytes == NULL || serialized_size == NULL) - return PCRE2_ERROR_NULL; - -if (number_of_codes <= 0) return PCRE2_ERROR_BADDATA; - -/* Compute total size. */ -total_size = sizeof(pcre2_serialized_data) + TABLES_LENGTH; -tables = NULL; - -for (i = 0; i < number_of_codes; i++) - { - if (codes[i] == NULL) return PCRE2_ERROR_NULL; - re = (const pcre2_real_code *)(codes[i]); - if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; - if (tables == NULL) - tables = re->tables; - else if (tables != re->tables) - return PCRE2_ERROR_MIXEDTABLES; - total_size += re->blocksize; - } - -/* Initialize the byte stream. */ -bytes = memctl->malloc(total_size + sizeof(pcre2_memctl), memctl->memory_data); -if (bytes == NULL) return PCRE2_ERROR_NOMEMORY; - -/* The controller is stored as a hidden parameter. */ -memcpy(bytes, memctl, sizeof(pcre2_memctl)); -bytes += sizeof(pcre2_memctl); - -data = (pcre2_serialized_data *)bytes; -data->magic = SERIALIZED_DATA_MAGIC; -data->version = SERIALIZED_DATA_VERSION; -data->config = SERIALIZED_DATA_CONFIG; -data->number_of_codes = number_of_codes; - -/* Copy all compiled code data. */ -dst_bytes = bytes + sizeof(pcre2_serialized_data); -memcpy(dst_bytes, tables, TABLES_LENGTH); -dst_bytes += TABLES_LENGTH; - -for (i = 0; i < number_of_codes; i++) - { - re = (const pcre2_real_code *)(codes[i]); - (void)memcpy(dst_bytes, (const char *)re, re->blocksize); - - /* Certain fields in the compiled code block are re-set during - deserialization. In order to ensure that the serialized data stream is always - the same for the same pattern, set them to zero here. We can't assume the - copy of the pattern is correctly aligned for accessing the fields as part of - a structure. Note the use of sizeof(void *) in the second of these, to - specify the size of a pointer. If sizeof(uint8_t *) is used (tables is a - pointer to uint8_t), gcc gives a warning because the first argument is also a - pointer to uint8_t. Casting the first argument to (void *) can stop this, but - it didn't stop Coverity giving the same complaint. */ - - (void)memset(dst_bytes + offsetof(pcre2_real_code, memctl), 0, - sizeof(pcre2_memctl)); - (void)memset(dst_bytes + offsetof(pcre2_real_code, tables), 0, - sizeof(void *)); - (void)memset(dst_bytes + offsetof(pcre2_real_code, executable_jit), 0, - sizeof(void *)); - - dst_bytes += re->blocksize; - } - -*serialized_bytes = bytes; -*serialized_size = total_size; -return number_of_codes; -} - - -/************************************************* -* Deserialize compiled patterns * -*************************************************/ - -PCRE2_EXP_DEFN int32_t PCRE2_CALL_CONVENTION -pcre2_serialize_decode(pcre2_code **codes, int32_t number_of_codes, - const uint8_t *bytes, pcre2_general_context *gcontext) -{ -const pcre2_serialized_data *data = (const pcre2_serialized_data *)bytes; -const pcre2_memctl *memctl = (gcontext != NULL) ? - &gcontext->memctl : &PRIV(default_compile_context).memctl; - -const uint8_t *src_bytes; -pcre2_real_code *dst_re; -uint8_t *tables; -int32_t i, j; - -/* Sanity checks. */ - -if (data == NULL || codes == NULL) return PCRE2_ERROR_NULL; -if (number_of_codes <= 0) return PCRE2_ERROR_BADDATA; -if (data->number_of_codes <= 0) return PCRE2_ERROR_BADSERIALIZEDDATA; -if (data->magic != SERIALIZED_DATA_MAGIC) return PCRE2_ERROR_BADMAGIC; -if (data->version != SERIALIZED_DATA_VERSION) return PCRE2_ERROR_BADMODE; -if (data->config != SERIALIZED_DATA_CONFIG) return PCRE2_ERROR_BADMODE; - -if (number_of_codes > data->number_of_codes) - number_of_codes = data->number_of_codes; - -src_bytes = bytes + sizeof(pcre2_serialized_data); - -/* Decode tables. The reference count for the tables is stored immediately -following them. */ - -tables = memctl->malloc(TABLES_LENGTH + sizeof(PCRE2_SIZE), memctl->memory_data); -if (tables == NULL) return PCRE2_ERROR_NOMEMORY; - -memcpy(tables, src_bytes, TABLES_LENGTH); -*(PCRE2_SIZE *)(tables + TABLES_LENGTH) = number_of_codes; -src_bytes += TABLES_LENGTH; - -/* Decode the byte stream. We must not try to read the size from the compiled -code block in the stream, because it might be unaligned, which causes errors on -hardware such as Sparc-64 that doesn't like unaligned memory accesses. The type -of the blocksize field is given its own name to ensure that it is the same here -as in the block. */ - -for (i = 0; i < number_of_codes; i++) - { - CODE_BLOCKSIZE_TYPE blocksize; - memcpy(&blocksize, src_bytes + offsetof(pcre2_real_code, blocksize), - sizeof(CODE_BLOCKSIZE_TYPE)); - if (blocksize <= sizeof(pcre2_real_code)) - return PCRE2_ERROR_BADSERIALIZEDDATA; - - /* The allocator provided by gcontext replaces the original one. */ - - dst_re = (pcre2_real_code *)PRIV(memctl_malloc)(blocksize, - (pcre2_memctl *)gcontext); - if (dst_re == NULL) - { - memctl->free(tables, memctl->memory_data); - for (j = 0; j < i; j++) - { - memctl->free(codes[j], memctl->memory_data); - codes[j] = NULL; - } - return PCRE2_ERROR_NOMEMORY; - } - - /* The new allocator must be preserved. */ - - memcpy(((uint8_t *)dst_re) + sizeof(pcre2_memctl), - src_bytes + sizeof(pcre2_memctl), blocksize - sizeof(pcre2_memctl)); - if (dst_re->magic_number != MAGIC_NUMBER || - dst_re->name_entry_size > MAX_NAME_SIZE + IMM2_SIZE + 1 || - dst_re->name_count > MAX_NAME_COUNT) - { - memctl->free(dst_re, memctl->memory_data); - return PCRE2_ERROR_BADSERIALIZEDDATA; - } - - /* At the moment only one table is supported. */ - - dst_re->tables = tables; - dst_re->executable_jit = NULL; - dst_re->flags |= PCRE2_DEREF_TABLES; - - codes[i] = dst_re; - src_bytes += blocksize; - } - -return number_of_codes; -} - - -/************************************************* -* Get the number of serialized patterns * -*************************************************/ - -PCRE2_EXP_DEFN int32_t PCRE2_CALL_CONVENTION -pcre2_serialize_get_number_of_codes(const uint8_t *bytes) -{ -const pcre2_serialized_data *data = (const pcre2_serialized_data *)bytes; - -if (data == NULL) return PCRE2_ERROR_NULL; -if (data->magic != SERIALIZED_DATA_MAGIC) return PCRE2_ERROR_BADMAGIC; -if (data->version != SERIALIZED_DATA_VERSION) return PCRE2_ERROR_BADMODE; -if (data->config != SERIALIZED_DATA_CONFIG) return PCRE2_ERROR_BADMODE; - -return data->number_of_codes; -} - - -/************************************************* -* Free the allocated stream * -*************************************************/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_serialize_free(uint8_t *bytes) -{ -if (bytes != NULL) - { - pcre2_memctl *memctl = (pcre2_memctl *)(bytes - sizeof(pcre2_memctl)); - memctl->free(memctl, memctl->memory_data); - } -} - -/* End of pcre2_serialize.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_string_utils.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_string_utils.c deleted file mode 100644 index f1ac718..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_string_utils.c +++ /dev/null @@ -1,199 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2018-2021 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains internal functions for comparing and finding the length -of strings. These are used instead of strcmp() etc because the standard -functions work only on 8-bit data. */ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Compare two zero-terminated PCRE2 strings * -*************************************************/ - -/* -Arguments: - str1 first string - str2 second string - -Returns: 0, 1, or -1 -*/ - -int -PRIV(strcmp)(PCRE2_SPTR str1, PCRE2_SPTR str2) -{ -PCRE2_UCHAR c1, c2; -while (*str1 != '\0' || *str2 != '\0') - { - c1 = *str1++; - c2 = *str2++; - if (c1 != c2) return ((c1 > c2) << 1) - 1; - } -return 0; -} - - -/************************************************* -* Compare zero-terminated PCRE2 & 8-bit strings * -*************************************************/ - -/* As the 8-bit string is almost always a literal, its type is specified as -const char *. - -Arguments: - str1 first string - str2 second string - -Returns: 0, 1, or -1 -*/ - -int -PRIV(strcmp_c8)(PCRE2_SPTR str1, const char *str2) -{ -PCRE2_UCHAR c1, c2; -while (*str1 != '\0' || *str2 != '\0') - { - c1 = *str1++; - c2 = *str2++; - if (c1 != c2) return ((c1 > c2) << 1) - 1; - } -return 0; -} - - -/************************************************* -* Compare two PCRE2 strings, given a length * -*************************************************/ - -/* -Arguments: - str1 first string - str2 second string - len the length - -Returns: 0, 1, or -1 -*/ - -int -PRIV(strncmp)(PCRE2_SPTR str1, PCRE2_SPTR str2, size_t len) -{ -PCRE2_UCHAR c1, c2; -for (; len > 0; len--) - { - c1 = *str1++; - c2 = *str2++; - if (c1 != c2) return ((c1 > c2) << 1) - 1; - } -return 0; -} - - -/************************************************* -* Compare PCRE2 string to 8-bit string by length * -*************************************************/ - -/* As the 8-bit string is almost always a literal, its type is specified as -const char *. - -Arguments: - str1 first string - str2 second string - len the length - -Returns: 0, 1, or -1 -*/ - -int -PRIV(strncmp_c8)(PCRE2_SPTR str1, const char *str2, size_t len) -{ -PCRE2_UCHAR c1, c2; -for (; len > 0; len--) - { - c1 = *str1++; - c2 = *str2++; - if (c1 != c2) return ((c1 > c2) << 1) - 1; - } -return 0; -} - - -/************************************************* -* Find the length of a PCRE2 string * -*************************************************/ - -/* -Argument: the string -Returns: the length -*/ - -PCRE2_SIZE -PRIV(strlen)(PCRE2_SPTR str) -{ -PCRE2_SIZE c = 0; -while (*str++ != 0) c++; -return c; -} - - -/************************************************* -* Copy 8-bit 0-terminated string to PCRE2 string * -*************************************************/ - -/* Arguments: - str1 buffer to receive the string - str2 8-bit string to be copied - -Returns: the number of code units used (excluding trailing zero) -*/ - -PCRE2_SIZE -PRIV(strcpy_c8)(PCRE2_UCHAR *str1, const char *str2) -{ -PCRE2_UCHAR *t = str1; -while (*str2 != 0) *t++ = *str2++; -*t = 0; -return t - str1; -} - -/* End of pcre2_string_utils.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_study.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_study.c deleted file mode 100644 index 52efc93..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_study.c +++ /dev/null @@ -1,2087 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains functions for scanning a compiled pattern and -collecting data (e.g. minimum matching length). */ - - -#include "pcre2_internal.h" - - - -/* The maximum remembered capturing brackets minimum. */ - -#define MAX_CACHE_BACKREF 128 - -/* Set a bit in the starting code unit bit map. */ - -#define SET_BIT(c) re->start_bitmap[(c)/8] |= (1u << ((c)&7)) - -/* Returns from set_start_bits() */ - -enum { SSB_FAIL, SSB_DONE, SSB_CONTINUE, SSB_UNKNOWN, SSB_TOODEEP }; - - -/************************************************* -* Find the minimum subject length for a group * -*************************************************/ - -/* Scan a parenthesized group and compute the minimum length of subject that -is needed to match it. This is a lower bound; it does not mean there is a -string of that length that matches. In UTF mode, the result is in characters -rather than code units. The field in a compiled pattern for storing the minimum -length is 16-bits long (on the grounds that anything longer than that is -pathological), so we give up when we reach that amount. This also means that -integer overflow for really crazy patterns cannot happen. - -Backreference minimum lengths are cached to speed up multiple references. This -function is called only when the highest back reference in the pattern is less -than or equal to MAX_CACHE_BACKREF, which is one less than the size of the -caching vector. The zeroth element contains the number of the highest set -value. - -Arguments: - re compiled pattern block - code pointer to start of group (the bracket) - startcode pointer to start of the whole pattern's code - utf UTF flag - recurses chain of recurse_check to catch mutual recursion - countptr pointer to call count (to catch over complexity) - backref_cache vector for caching back references. - -This function is no longer called when the pattern contains (*ACCEPT); however, -the old code for returning -1 is retained, just in case. - -Returns: the minimum length - -1 \C in UTF-8 mode - or (*ACCEPT) - or pattern too complicated - -2 internal error (missing capturing bracket) - -3 internal error (opcode not listed) -*/ - -static int -find_minlength(const pcre2_real_code *re, PCRE2_SPTR code, - PCRE2_SPTR startcode, BOOL utf, recurse_check *recurses, int *countptr, - int *backref_cache) -{ -int length = -1; -int branchlength = 0; -int prev_cap_recno = -1; -int prev_cap_d = 0; -int prev_recurse_recno = -1; -int prev_recurse_d = 0; -uint32_t once_fudge = 0; -BOOL had_recurse = FALSE; -BOOL dupcapused = (re->flags & PCRE2_DUPCAPUSED) != 0; -PCRE2_SPTR nextbranch = code + GET(code, 1); -PCRE2_SPTR cc = code + 1 + LINK_SIZE; -recurse_check this_recurse; - -/* If this is a "could be empty" group, its minimum length is 0. */ - -if (*code >= OP_SBRA && *code <= OP_SCOND) return 0; - -/* Skip over capturing bracket number */ - -if (*code == OP_CBRA || *code == OP_CBRAPOS) cc += IMM2_SIZE; - -/* A large and/or complex regex can take too long to process. */ - -if ((*countptr)++ > 1000) return -1; - -/* Scan along the opcodes for this branch. If we get to the end of the branch, -check the length against that of the other branches. If the accumulated length -passes 16-bits, reset to that value and skip the rest of the branch. */ - -for (;;) - { - int d, min, recno; - PCRE2_UCHAR op; - PCRE2_SPTR cs, ce; - - if (branchlength >= (int)UINT16_MAX) - { - branchlength = UINT16_MAX; - cc = nextbranch; - } - - op = *cc; - switch (op) - { - case OP_COND: - case OP_SCOND: - - /* If there is only one branch in a condition, the implied branch has zero - length, so we don't add anything. This covers the DEFINE "condition" - automatically. If there are two branches we can treat it the same as any - other non-capturing subpattern. */ - - cs = cc + GET(cc, 1); - if (*cs != OP_ALT) - { - cc = cs + 1 + LINK_SIZE; - break; - } - goto PROCESS_NON_CAPTURE; - - case OP_BRA: - /* There's a special case of OP_BRA, when it is wrapped round a repeated - OP_RECURSE. We'd like to process the latter at this level so that - remembering the value works for repeated cases. So we do nothing, but - set a fudge value to skip over the OP_KET after the recurse. */ - - if (cc[1+LINK_SIZE] == OP_RECURSE && cc[2*(1+LINK_SIZE)] == OP_KET) - { - once_fudge = 1 + LINK_SIZE; - cc += 1 + LINK_SIZE; - break; - } - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_SBRA: - case OP_BRAPOS: - case OP_SBRAPOS: - PROCESS_NON_CAPTURE: - d = find_minlength(re, cc, startcode, utf, recurses, countptr, - backref_cache); - if (d < 0) return d; - branchlength += d; - do cc += GET(cc, 1); while (*cc == OP_ALT); - cc += 1 + LINK_SIZE; - break; - - /* To save time for repeated capturing subpatterns, we remember the - length of the previous one. Unfortunately we can't do the same for - the unnumbered ones above. Nor can we do this if (?| is present in the - pattern because captures with the same number are not then identical. */ - - case OP_CBRA: - case OP_SCBRA: - case OP_CBRAPOS: - case OP_SCBRAPOS: - recno = (int)GET2(cc, 1+LINK_SIZE); - if (dupcapused || recno != prev_cap_recno) - { - prev_cap_recno = recno; - prev_cap_d = find_minlength(re, cc, startcode, utf, recurses, countptr, - backref_cache); - if (prev_cap_d < 0) return prev_cap_d; - } - branchlength += prev_cap_d; - do cc += GET(cc, 1); while (*cc == OP_ALT); - cc += 1 + LINK_SIZE; - break; - - /* ACCEPT makes things far too complicated; we have to give up. In fact, - from 10.34 onwards, if a pattern contains (*ACCEPT), this function is not - used. However, leave the code in place, just in case. */ - - case OP_ACCEPT: - case OP_ASSERT_ACCEPT: - return -1; - - /* Reached end of a branch; if it's a ket it is the end of a nested - call. If it's ALT it is an alternation in a nested call. If it is END it's - the end of the outer call. All can be handled by the same code. If the - length of any branch is zero, there is no need to scan any subsequent - branches. */ - - case OP_ALT: - case OP_KET: - case OP_KETRMAX: - case OP_KETRMIN: - case OP_KETRPOS: - case OP_END: - if (length < 0 || (!had_recurse && branchlength < length)) - length = branchlength; - if (op != OP_ALT || length == 0) return length; - nextbranch = cc + GET(cc, 1); - cc += 1 + LINK_SIZE; - branchlength = 0; - had_recurse = FALSE; - break; - - /* Skip over assertive subpatterns */ - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERT_NA: - case OP_ASSERT_SCS: - case OP_ASSERTBACK_NA: - do cc += GET(cc, 1); while (*cc == OP_ALT); - PCRE2_FALLTHROUGH /* Fall through */ - - /* Skip over things that don't match chars */ - - case OP_REVERSE: - case OP_VREVERSE: - case OP_CREF: - case OP_DNCREF: - case OP_RREF: - case OP_DNRREF: - case OP_FALSE: - case OP_TRUE: - case OP_CALLOUT: - case OP_SOD: - case OP_SOM: - case OP_EOD: - case OP_EODN: - case OP_CIRC: - case OP_CIRCM: - case OP_DOLL: - case OP_DOLLM: - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - cc += PRIV(OP_lengths)[*cc]; - break; - - case OP_CALLOUT_STR: - cc += GET(cc, 1 + 2*LINK_SIZE); - break; - - /* Skip over a subpattern that has a {0} or {0,x} quantifier */ - - case OP_BRAZERO: - case OP_BRAMINZERO: - case OP_BRAPOSZERO: - case OP_SKIPZERO: - cc += PRIV(OP_lengths)[*cc]; - do cc += GET(cc, 1); while (*cc == OP_ALT); - cc += 1 + LINK_SIZE; - break; - - /* Handle literal characters and + repetitions */ - - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - case OP_PLUS: - case OP_PLUSI: - case OP_MINPLUS: - case OP_MINPLUSI: - case OP_POSPLUS: - case OP_POSPLUSI: - case OP_NOTPLUS: - case OP_NOTPLUSI: - case OP_NOTMINPLUS: - case OP_NOTMINPLUSI: - case OP_NOTPOSPLUS: - case OP_NOTPOSPLUSI: - branchlength++; - cc += 2; -#ifdef SUPPORT_UNICODE - if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEPOSPLUS: - branchlength++; - cc += (cc[1] == OP_PROP || cc[1] == OP_NOTPROP)? 4 : 2; - break; - - /* Handle exact repetitions. The count is already in characters, but we - may need to skip over a multibyte character in UTF mode. */ - - case OP_EXACT: - case OP_EXACTI: - case OP_NOTEXACT: - case OP_NOTEXACTI: - branchlength += GET2(cc,1); - cc += 2 + IMM2_SIZE; -#ifdef SUPPORT_UNICODE - if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - case OP_TYPEEXACT: - branchlength += GET2(cc,1); - cc += 2 + IMM2_SIZE + ((cc[1 + IMM2_SIZE] == OP_PROP - || cc[1 + IMM2_SIZE] == OP_NOTPROP)? 2 : 0); - break; - - /* Handle single-char non-literal matchers */ - - case OP_PROP: - case OP_NOTPROP: - cc += 2; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_NOT_DIGIT: - case OP_DIGIT: - case OP_NOT_WHITESPACE: - case OP_WHITESPACE: - case OP_NOT_WORDCHAR: - case OP_WORDCHAR: - case OP_ANY: - case OP_ALLANY: - case OP_EXTUNI: - case OP_HSPACE: - case OP_NOT_HSPACE: - case OP_VSPACE: - case OP_NOT_VSPACE: - branchlength++; - cc++; - break; - - /* "Any newline" might match two characters, but it also might match just - one. */ - - case OP_ANYNL: - branchlength += 1; - cc++; - break; - - /* The single-byte matcher means we can't proceed in UTF mode. (In - non-UTF mode \C will actually be turned into OP_ALLANY, so won't ever - appear, but leave the code, just in case.) */ - - case OP_ANYBYTE: -#ifdef SUPPORT_UNICODE - if (utf) return -1; -#endif - branchlength++; - cc++; - break; - - /* For repeated character types, we have to test for \p and \P, which have - an extra two bytes of parameters. */ - - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSQUERY: - if (cc[1] == OP_PROP || cc[1] == OP_NOTPROP) cc += 2; - cc += PRIV(OP_lengths)[op]; - break; - - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEPOSUPTO: - if (cc[1 + IMM2_SIZE] == OP_PROP - || cc[1 + IMM2_SIZE] == OP_NOTPROP) cc += 2; - cc += PRIV(OP_lengths)[op]; - break; - - /* Check a class for variable quantification */ - - case OP_CLASS: - case OP_NCLASS: -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - case OP_ECLASS: - /* The original code caused an unsigned overflow in 64 bit systems, - so now we use a conditional statement. */ - if (op == OP_XCLASS || op == OP_ECLASS) - cc += GET(cc, 1); - else -#endif - cc += PRIV(OP_lengths)[OP_CLASS]; - - switch (*cc) - { - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRPOSPLUS: - branchlength++; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSSTAR: - case OP_CRPOSQUERY: - cc++; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - branchlength += GET2(cc,1); - cc += 1 + 2 * IMM2_SIZE; - break; - - default: - branchlength++; - break; - } - break; - - /* Backreferences and subroutine calls (OP_RECURSE) are treated in the same - way: we find the minimum length for the subpattern. A recursion - (backreference or subroutine) causes an a flag to be set that causes the - length of this branch to be ignored. The logic is that a recursion can only - make sense if there is another alternative that stops the recursing. That - will provide the minimum length (when no recursion happens). - - If PCRE2_MATCH_UNSET_BACKREF is set, a backreference to an unset bracket - matches an empty string (by default it causes a matching failure), so in - that case we must set the minimum length to zero. - - For backreferenes, if duplicate numbers are present in the pattern we check - for a reference to a duplicate. If it is, we don't know which version will - be referenced, so we have to set the minimum length to zero. */ - - /* Duplicate named pattern back reference. */ - - case OP_DNREF: - case OP_DNREFI: - if (!dupcapused && (re->overall_options & PCRE2_MATCH_UNSET_BACKREF) == 0) - { - int count = GET2(cc, 1+IMM2_SIZE); - PCRE2_SPTR slot = - (PCRE2_SPTR)((const uint8_t *)re + sizeof(pcre2_real_code)) + - GET2(cc, 1) * re->name_entry_size; - - d = INT_MAX; - - /* Scan all groups with the same name; find the shortest. */ - - while (count-- > 0) - { - int dd, i; - recno = GET2(slot, 0); - - if (recno <= backref_cache[0] && backref_cache[recno] >= 0) - dd = backref_cache[recno]; - else - { - ce = cs = PRIV(find_bracket)(startcode, utf, recno); - if (cs == NULL) return -2; - do ce += GET(ce, 1); while (*ce == OP_ALT); - - dd = 0; - if (!dupcapused || PRIV(find_bracket)(ce, utf, recno) == NULL) - { - if (cc > cs && cc < ce) /* Simple recursion */ - { - had_recurse = TRUE; - } - else - { - recurse_check *r = recurses; - for (r = recurses; r != NULL; r = r->prev) - if (r->group == cs) break; - if (r != NULL) /* Mutual recursion */ - { - had_recurse = TRUE; - } - else - { - this_recurse.prev = recurses; /* No recursion */ - this_recurse.group = cs; - dd = find_minlength(re, cs, startcode, utf, &this_recurse, - countptr, backref_cache); - if (dd < 0) return dd; - } - } - } - - backref_cache[recno] = dd; - for (i = backref_cache[0] + 1; i < recno; i++) backref_cache[i] = -1; - backref_cache[0] = recno; - } - - if (dd < d) d = dd; - if (d <= 0) break; /* No point looking at any more */ - slot += re->name_entry_size; - } - } - else d = 0; - cc += PRIV(OP_lengths)[*cc]; - goto REPEAT_BACK_REFERENCE; - - /* Single back reference by number. References by name are converted to by - number when there is no duplication. */ - - case OP_REF: - case OP_REFI: - recno = GET2(cc, 1); - if (recno <= backref_cache[0] && backref_cache[recno] >= 0) - d = backref_cache[recno]; - else - { - int i; - d = 0; - - if ((re->overall_options & PCRE2_MATCH_UNSET_BACKREF) == 0) - { - ce = cs = PRIV(find_bracket)(startcode, utf, recno); - if (cs == NULL) return -2; - do ce += GET(ce, 1); while (*ce == OP_ALT); - - if (!dupcapused || PRIV(find_bracket)(ce, utf, recno) == NULL) - { - if (cc > cs && cc < ce) /* Simple recursion */ - { - had_recurse = TRUE; - } - else - { - recurse_check *r = recurses; - for (r = recurses; r != NULL; r = r->prev) if (r->group == cs) break; - if (r != NULL) /* Mutual recursion */ - { - had_recurse = TRUE; - } - else /* No recursion */ - { - this_recurse.prev = recurses; - this_recurse.group = cs; - d = find_minlength(re, cs, startcode, utf, &this_recurse, countptr, - backref_cache); - if (d < 0) return d; - } - } - } - } - - backref_cache[recno] = d; - for (i = backref_cache[0] + 1; i < recno; i++) backref_cache[i] = -1; - backref_cache[0] = recno; - } - - cc += PRIV(OP_lengths)[*cc]; - - /* Handle repeated back references */ - - REPEAT_BACK_REFERENCE: - switch (*cc) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSSTAR: - case OP_CRPOSQUERY: - min = 0; - cc++; - break; - - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRPOSPLUS: - min = 1; - cc++; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - min = GET2(cc, 1); - cc += 1 + 2 * IMM2_SIZE; - break; - - default: - min = 1; - break; - } - - /* Take care not to overflow: (1) min and d are ints, so check that their - product is not greater than INT_MAX. (2) branchlength is limited to - UINT16_MAX (checked at the top of the loop). */ - - if ((d > 0 && (INT_MAX/d) < min) || (int)UINT16_MAX - branchlength < min*d) - branchlength = UINT16_MAX; - else branchlength += min * d; - break; - - /* Recursion always refers to the first occurrence of a subpattern with a - given number. Therefore, we can always make use of caching, even when the - pattern contains multiple subpatterns with the same number. */ - - case OP_RECURSE: - cs = ce = startcode + GET(cc, 1); - recno = GET2(cs, 1+LINK_SIZE); - if (recno == prev_recurse_recno) - { - branchlength += prev_recurse_d; - } - else - { - do ce += GET(ce, 1); while (*ce == OP_ALT); - if (cc > cs && cc < ce) /* Simple recursion */ - had_recurse = TRUE; - else - { - recurse_check *r = recurses; - for (r = recurses; r != NULL; r = r->prev) if (r->group == cs) break; - if (r != NULL) /* Mutual recursion */ - had_recurse = TRUE; - else - { - this_recurse.prev = recurses; - this_recurse.group = cs; - prev_recurse_d = find_minlength(re, cs, startcode, utf, &this_recurse, - countptr, backref_cache); - if (prev_recurse_d < 0) return prev_recurse_d; - prev_recurse_recno = recno; - branchlength += prev_recurse_d; - } - } - } - cc += 1 + LINK_SIZE + once_fudge; - once_fudge = 0; - break; - - /* Anything else does not or need not match a character. We can get the - item's length from the table, but for those that can match zero occurrences - of a character, we must take special action for UTF-8 characters. As it - happens, the "NOT" versions of these opcodes are used at present only for - ASCII characters, so they could be omitted from this list. However, in - future that may change, so we include them here so as not to leave a - gotcha for a future maintainer. */ - - case OP_UPTO: - case OP_UPTOI: - case OP_NOTUPTO: - case OP_NOTUPTOI: - case OP_MINUPTO: - case OP_MINUPTOI: - case OP_NOTMINUPTO: - case OP_NOTMINUPTOI: - case OP_POSUPTO: - case OP_POSUPTOI: - case OP_NOTPOSUPTO: - case OP_NOTPOSUPTOI: - - case OP_STAR: - case OP_STARI: - case OP_NOTSTAR: - case OP_NOTSTARI: - case OP_MINSTAR: - case OP_MINSTARI: - case OP_NOTMINSTAR: - case OP_NOTMINSTARI: - case OP_POSSTAR: - case OP_POSSTARI: - case OP_NOTPOSSTAR: - case OP_NOTPOSSTARI: - - case OP_QUERY: - case OP_QUERYI: - case OP_NOTQUERY: - case OP_NOTQUERYI: - case OP_MINQUERY: - case OP_MINQUERYI: - case OP_NOTMINQUERY: - case OP_NOTMINQUERYI: - case OP_POSQUERY: - case OP_POSQUERYI: - case OP_NOTPOSQUERY: - case OP_NOTPOSQUERYI: - - cc += PRIV(OP_lengths)[op]; -#ifdef SUPPORT_UNICODE - if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - /* Skip these, but we need to add in the name length. */ - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_SKIP_ARG: - case OP_THEN_ARG: - cc += PRIV(OP_lengths)[op] + cc[1]; - break; - - /* The remaining opcodes are just skipped over. */ - - case OP_CLOSE: - case OP_COMMIT: - case OP_FAIL: - case OP_PRUNE: - case OP_SET_SOM: - case OP_SKIP: - case OP_THEN: - cc += PRIV(OP_lengths)[op]; - break; - - /* This should not occur: we list all opcodes explicitly so that when - new ones get added they are properly considered. */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return -3; - /* LCOV_EXCL_STOP */ - } - } - -/* LCOV_EXCL_START */ -PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ -return -3; /* Avoid compiler warnings */ -/* LCOV_EXCL_STOP */ -} - - - -/************************************************* -* Set a bit and maybe its alternate case * -*************************************************/ - -/* Given a character, set its first code unit's bit in the table, and also the -corresponding bit for the other version of a letter if we are caseless. - -Arguments: - re points to the regex block - p points to the first code unit of the character - caseless TRUE if caseless - utf TRUE for UTF mode - ucp TRUE for UCP mode - -Returns: pointer after the character -*/ - -static PCRE2_SPTR -set_table_bit(pcre2_real_code *re, PCRE2_SPTR p, BOOL caseless, BOOL utf, - BOOL ucp) -{ -uint32_t c = *p++; /* First code unit */ - -(void)utf; /* Stop compiler warnings when UTF not supported */ -(void)ucp; - -/* In 16-bit and 32-bit modes, code units greater than 0xff set the bit for -0xff. */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 -if (c > 0xff) SET_BIT(0xff); else -#endif - -SET_BIT(c); - -/* In UTF-8 or UTF-16 mode, pick up the remaining code units in order to find -the end of the character, even when caseless. */ - -#ifdef SUPPORT_UNICODE -if (utf) - { -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (c >= 0xc0) GETUTF8INC(c, p); -#elif PCRE2_CODE_UNIT_WIDTH == 16 - if ((c & 0xfc00) == 0xd800) GETUTF16INC(c, p); -#endif - } -#endif /* SUPPORT_UNICODE */ - -/* If caseless, handle the other case of the character. */ - -if (caseless) - { -#ifdef SUPPORT_UNICODE - if (utf || ucp) - { - c = UCD_OTHERCASE(c); -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (utf) - { - PCRE2_UCHAR buff[6]; - (void)PRIV(ord2utf)(c, buff); - SET_BIT(buff[0]); - } - else if (c < 256) SET_BIT(c); -#else /* 16-bit or 32-bit mode */ - if (c > 0xff) SET_BIT(0xff); else SET_BIT(c); -#endif - } - - else -#endif /* SUPPORT_UNICODE */ - - /* Not UTF or UCP */ - - if (MAX_255(c)) SET_BIT(re->tables[fcc_offset + c]); - } - -return p; -} - - - -/************************************************* -* Set bits for a positive character type * -*************************************************/ - -/* This function sets starting bits for a character type. In UTF-8 mode, we can -only do a direct setting for bytes less than 128, as otherwise there can be -confusion with bytes in the middle of UTF-8 characters. In a "traditional" -environment, the tables will only recognize ASCII characters anyway, but in at -least one Windows environment, some higher bytes bits were set in the tables. -So we deal with that case by considering the UTF-8 encoding. - -Arguments: - re the regex block - cbit type the type of character wanted - table_limit 32 for non-UTF-8; 16 for UTF-8 - -Returns: nothing -*/ - -static void -set_type_bits(pcre2_real_code *re, int cbit_type, unsigned int table_limit) -{ -uint32_t c; -for (c = 0; c < table_limit; c++) - re->start_bitmap[c] |= re->tables[c+cbits_offset+cbit_type]; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -if (table_limit == 32) return; -for (c = 128; c < 256; c++) - { - if ((re->tables[cbits_offset + c/8] & (1u << (c&7))) != 0) - { - PCRE2_UCHAR buff[6]; - (void)PRIV(ord2utf)(c, buff); - SET_BIT(buff[0]); - } - } -#endif /* UTF-8 */ -} - - -/************************************************* -* Set bits for a negative character type * -*************************************************/ - -/* This function sets starting bits for a negative character type such as \D. -In UTF-8 mode, we can only do a direct setting for bytes less than 128, as -otherwise there can be confusion with bytes in the middle of UTF-8 characters. -Unlike in the positive case, where we can set appropriate starting bits for -specific high-valued UTF-8 characters, in this case we have to set the bits for -all high-valued characters. The lowest is 0xc2, but we overkill by starting at -0xc0 (192) for simplicity. - -Arguments: - re the regex block - cbit type the type of character wanted - table_limit 32 for non-UTF-8; 16 for UTF-8 - -Returns: nothing -*/ - -static void -set_nottype_bits(pcre2_real_code *re, int cbit_type, unsigned int table_limit) -{ -uint32_t c; -for (c = 0; c < table_limit; c++) - re->start_bitmap[c] |= (uint8_t)(~(re->tables[c+cbits_offset+cbit_type])); -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -if (table_limit != 32) for (c = 24; c < 32; c++) re->start_bitmap[c] = 0xff; -#endif -} - - - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -/************************************************* -* Set starting bits for a character list. * -*************************************************/ - -/* This function sets starting bits for a character list. It enumerates -all characters and character ranges in the character list, and sets -the starting bits accordingly. - -Arguments: - code pointer to the code - start_bitmap pointer to the starting bitmap - -Returns: nothing -*/ -static void -study_char_list(PCRE2_SPTR code, uint8_t *start_bitmap, - const uint8_t *char_lists_end) -{ -uint32_t type, list_ind; -uint32_t char_list_add = XCL_CHAR_LIST_LOW_16_ADD; -uint32_t range_start = ~(uint32_t)0, range_end = 0; -const uint8_t *next_char; -PCRE2_UCHAR start_buffer[6], end_buffer[6]; -PCRE2_UCHAR start, end; - -/* Only needed in 8-bit mode at the moment. */ -type = (uint32_t)(code[0] << 8) | code[1]; -code += 2; - -/* Align characters. */ -next_char = char_lists_end - (GET(code, 0) << 1); -type &= XCL_TYPE_MASK; -list_ind = 0; - -if ((type & XCL_BEGIN_WITH_RANGE) != 0) - range_start = XCL_CHAR_LIST_LOW_16_START; - -while (type > 0) - { - uint32_t item_count = type & XCL_ITEM_COUNT_MASK; - - if (item_count == XCL_ITEM_COUNT_MASK) - { - if (list_ind <= 1) - { - item_count = *(const uint16_t*)next_char; - next_char += 2; - } - else - { - item_count = *(const uint32_t*)next_char; - next_char += 4; - } - } - - while (item_count > 0) - { - if (list_ind <= 1) - { - range_end = *(const uint16_t*)next_char; - next_char += 2; - } - else - { - range_end = *(const uint32_t*)next_char; - next_char += 4; - } - - if ((range_end & XCL_CHAR_END) != 0) - { - range_end = char_list_add + (range_end >> XCL_CHAR_SHIFT); - - PRIV(ord2utf)(range_end, end_buffer); - end = end_buffer[0]; - - if (range_start < range_end) - { - PRIV(ord2utf)(range_start, start_buffer); - for (start = start_buffer[0]; start <= end; start++) - start_bitmap[start / 8] |= (1u << (start & 7)); - } - else - start_bitmap[end / 8] |= (1u << (end & 7)); - - range_start = ~(uint32_t)0; - } - else - range_start = char_list_add + (range_end >> XCL_CHAR_SHIFT); - - item_count--; - } - - list_ind++; - type >>= XCL_TYPE_BIT_LEN; - - if (range_start == ~(uint32_t)0) - { - if ((type & XCL_BEGIN_WITH_RANGE) != 0) - { - /* In 8 bit mode XCL_CHAR_LIST_HIGH_32_START is not possible. */ - if (list_ind == 1) range_start = XCL_CHAR_LIST_HIGH_16_START; - else range_start = XCL_CHAR_LIST_LOW_32_START; - } - } - else if ((type & XCL_BEGIN_WITH_RANGE) == 0) - { - PRIV(ord2utf)(range_start, start_buffer); - - /* In 8 bit mode XCL_CHAR_LIST_LOW_32_END and - XCL_CHAR_LIST_HIGH_32_END are not possible. */ - if (list_ind == 1) range_end = XCL_CHAR_LIST_LOW_16_END; - else range_end = XCL_CHAR_LIST_HIGH_16_END; - - PRIV(ord2utf)(range_end, end_buffer); - end = end_buffer[0]; - - for (start = start_buffer[0]; start <= end; start++) - start_bitmap[start / 8] |= (1u << (start & 7)); - - range_start = ~(uint32_t)0; - } - - /* In 8 bit mode XCL_CHAR_LIST_HIGH_32_ADD is not possible. */ - if (list_ind == 1) char_list_add = XCL_CHAR_LIST_HIGH_16_ADD; - else char_list_add = XCL_CHAR_LIST_LOW_32_ADD; - } -} -#endif - - - -/************************************************* -* Create bitmap of starting code units * -*************************************************/ - -/* This function scans a compiled unanchored expression recursively and -attempts to build a bitmap of the set of possible starting code units whose -values are less than 256. In 16-bit and 32-bit mode, values above 255 all cause -the 255 bit to be set. When calling set[_not]_type_bits() in UTF-8 (sic) mode -we pass a value of 16 rather than 32 as the final argument. (See comments in -those functions for the reason.) - -The SSB_CONTINUE return is useful for parenthesized groups in patterns such as -(a*)b where the group provides some optional starting code units but scanning -must continue at the outer level to find at least one mandatory code unit. At -the outermost level, this function fails unless the result is SSB_DONE. - -We restrict recursion (for nested groups) to 1000 to avoid stack overflow -issues. - -Arguments: - re points to the compiled regex block - code points to an expression - utf TRUE if in UTF mode - ucp TRUE if in UCP mode - depthptr pointer to recurse depth - -Returns: SSB_FAIL => Failed to find any starting code units - SSB_DONE => Found mandatory starting code units - SSB_CONTINUE => Found optional starting code units - SSB_UNKNOWN => Hit an unrecognized opcode - SSB_TOODEEP => Recursion is too deep -*/ - -static int -set_start_bits(pcre2_real_code *re, PCRE2_SPTR code, BOOL utf, BOOL ucp, - int *depthptr) -{ -uint32_t c; -int yield = SSB_DONE; -BOOL done; - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -int table_limit = utf? 16:32; -#else -int table_limit = 32; -#endif - -*depthptr += 1; -if (*depthptr > 1000) return SSB_TOODEEP; - -do - { - BOOL try_next = TRUE; - PCRE2_SPTR tcode = code + 1 + LINK_SIZE; - - if (*code == OP_CBRA || *code == OP_SCBRA || - *code == OP_CBRAPOS || *code == OP_SCBRAPOS) tcode += IMM2_SIZE; - - while (try_next) /* Loop for items in this branch */ - { - int rc; - PCRE2_SPTR ncode; - const uint8_t *classmap = NULL; -#ifdef SUPPORT_WIDE_CHARS - PCRE2_UCHAR xclassflags; -#endif - - switch(*tcode) - { - /* If we reach something we don't understand, it means a new opcode has - been created that hasn't been added to this function. Hopefully this - problem will be discovered during testing. */ - - default: - return SSB_UNKNOWN; - - /* Fail for a valid opcode that implies no starting bits. */ - - case OP_ACCEPT: - case OP_ASSERT_ACCEPT: - case OP_ALLANY: - case OP_ANY: - case OP_ANYBYTE: - case OP_CIRCM: - case OP_CLOSE: - case OP_COMMIT: - case OP_COMMIT_ARG: - case OP_COND: - case OP_CREF: - case OP_FALSE: - case OP_TRUE: - case OP_DNCREF: - case OP_DNREF: - case OP_DNREFI: - case OP_DNRREF: - case OP_DOLL: - case OP_DOLLM: - case OP_END: - case OP_EOD: - case OP_EODN: - case OP_EXTUNI: - case OP_FAIL: - case OP_MARK: - case OP_NOT: - case OP_NOTEXACT: - case OP_NOTEXACTI: - case OP_NOTI: - case OP_NOTMINPLUS: - case OP_NOTMINPLUSI: - case OP_NOTMINQUERY: - case OP_NOTMINQUERYI: - case OP_NOTMINSTAR: - case OP_NOTMINSTARI: - case OP_NOTMINUPTO: - case OP_NOTMINUPTOI: - case OP_NOTPLUS: - case OP_NOTPLUSI: - case OP_NOTPOSPLUS: - case OP_NOTPOSPLUSI: - case OP_NOTPOSQUERY: - case OP_NOTPOSQUERYI: - case OP_NOTPOSSTAR: - case OP_NOTPOSSTARI: - case OP_NOTPOSUPTO: - case OP_NOTPOSUPTOI: - case OP_NOTPROP: - case OP_NOTQUERY: - case OP_NOTQUERYI: - case OP_NOTSTAR: - case OP_NOTSTARI: - case OP_NOTUPTO: - case OP_NOTUPTOI: - case OP_NOT_HSPACE: - case OP_NOT_VSPACE: - case OP_PRUNE: - case OP_PRUNE_ARG: - case OP_RECURSE: - case OP_REF: - case OP_REFI: - case OP_REVERSE: - case OP_VREVERSE: - case OP_RREF: - case OP_SCOND: - case OP_SET_SOM: - case OP_SKIP: - case OP_SKIP_ARG: - case OP_SOD: - case OP_SOM: - case OP_THEN: - case OP_THEN_ARG: - return SSB_FAIL; - - /* OP_CIRC happens only at the start of an anchored branch (multiline ^ - uses OP_CIRCM). Skip over it. */ - - case OP_CIRC: - tcode += PRIV(OP_lengths)[OP_CIRC]; - break; - - /* A "real" property test implies no starting bits, but the fake property - PT_CLIST identifies a list of characters. These lists are short, as they - are used for characters with more than one "other case", so there is no - point in recognizing them for OP_NOTPROP. */ - - case OP_PROP: - if (tcode[1] != PT_CLIST) return SSB_FAIL; - { - const uint32_t *p = PRIV(ucd_caseless_sets) + tcode[2]; - while ((c = *p++) < NOTACHAR) - { -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 - if (utf) - { - PCRE2_UCHAR buff[6]; - (void)PRIV(ord2utf)(c, buff); - c = buff[0]; - } -#endif - if (c > 0xff) SET_BIT(0xff); else SET_BIT(c); - } - } - try_next = FALSE; - break; - - /* We can ignore word boundary tests. */ - - case OP_WORD_BOUNDARY: - case OP_NOT_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - case OP_NOT_UCP_WORD_BOUNDARY: - tcode++; - break; - - /* For a positive lookahead assertion, inspect what immediately follows, - ignoring intermediate assertions and callouts. If the next item is one - that sets a mandatory character, skip this assertion. Otherwise, treat it - the same as other bracket groups. */ - - case OP_ASSERT: - case OP_ASSERT_NA: - ncode = tcode + GET(tcode, 1); - while (*ncode == OP_ALT) ncode += GET(ncode, 1); - ncode += 1 + LINK_SIZE; - - /* Skip irrelevant items */ - - for (done = FALSE; !done;) - { - switch (*ncode) - { - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - ncode += GET(ncode, 1); - while (*ncode == OP_ALT) ncode += GET(ncode, 1); - ncode += 1 + LINK_SIZE; - break; - - case OP_WORD_BOUNDARY: - case OP_NOT_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - case OP_NOT_UCP_WORD_BOUNDARY: - ncode++; - break; - - case OP_CALLOUT: - ncode += PRIV(OP_lengths)[OP_CALLOUT]; - break; - - case OP_CALLOUT_STR: - ncode += GET(ncode, 1 + 2*LINK_SIZE); - break; - - default: - done = TRUE; - break; - } - } - - /* Now check the next significant item. */ - - switch(*ncode) - { - default: - break; - - case OP_PROP: - if (ncode[1] != PT_CLIST) break; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_ANYNL: - case OP_CHAR: - case OP_CHARI: - case OP_EXACT: - case OP_EXACTI: - case OP_HSPACE: - case OP_MINPLUS: - case OP_MINPLUSI: - case OP_PLUS: - case OP_PLUSI: - case OP_POSPLUS: - case OP_POSPLUSI: - case OP_VSPACE: - /* Note that these types will only be present in non-UCP mode. */ - case OP_DIGIT: - case OP_NOT_DIGIT: - case OP_WORDCHAR: - case OP_NOT_WORDCHAR: - case OP_WHITESPACE: - case OP_NOT_WHITESPACE: - tcode = ncode; - continue; /* With the following significant opcode */ - } - PCRE2_FALLTHROUGH /* Fall through */ - - /* For a group bracket or a positive assertion without an immediately - following mandatory setting, recurse to set bits from within the - subpattern. If it can't find anything, we have to give up. If it finds - some mandatory character(s), we are done for this branch. Otherwise, - carry on scanning after the subpattern. */ - - case OP_BRA: - case OP_SBRA: - case OP_CBRA: - case OP_SCBRA: - case OP_BRAPOS: - case OP_SBRAPOS: - case OP_CBRAPOS: - case OP_SCBRAPOS: - case OP_ONCE: - case OP_SCRIPT_RUN: - rc = set_start_bits(re, tcode, utf, ucp, depthptr); - if (rc == SSB_DONE) - { - try_next = FALSE; - } - else if (rc == SSB_CONTINUE) - { - do tcode += GET(tcode, 1); while (*tcode == OP_ALT); - tcode += 1 + LINK_SIZE; - } - else return rc; /* FAIL, UNKNOWN, or TOODEEP */ - break; - - /* If we hit ALT or KET, it means we haven't found anything mandatory in - this branch, though we might have found something optional. For ALT, we - continue with the next alternative, but we have to arrange that the final - result from subpattern is SSB_CONTINUE rather than SSB_DONE. For KET, - return SSB_CONTINUE: if this is the top level, that indicates failure, - but after a nested subpattern, it causes scanning to continue. */ - - case OP_ALT: - yield = SSB_CONTINUE; - try_next = FALSE; - break; - - case OP_KET: - case OP_KETRMAX: - case OP_KETRMIN: - case OP_KETRPOS: - return SSB_CONTINUE; - - /* Skip over callout */ - - case OP_CALLOUT: - tcode += PRIV(OP_lengths)[OP_CALLOUT]; - break; - - case OP_CALLOUT_STR: - tcode += GET(tcode, 1 + 2*LINK_SIZE); - break; - - /* Skip over lookbehind, negative lookahead, and scan substring - assertions */ - - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - do tcode += GET(tcode, 1); while (*tcode == OP_ALT); - tcode += 1 + LINK_SIZE; - break; - - /* BRAZERO does the bracket, but carries on. */ - - case OP_BRAZERO: - case OP_BRAMINZERO: - case OP_BRAPOSZERO: - rc = set_start_bits(re, ++tcode, utf, ucp, depthptr); - if (rc == SSB_FAIL || rc == SSB_UNKNOWN || rc == SSB_TOODEEP) return rc; - do tcode += GET(tcode,1); while (*tcode == OP_ALT); - tcode += 1 + LINK_SIZE; - break; - - /* SKIPZERO skips the bracket. */ - - case OP_SKIPZERO: - tcode++; - do tcode += GET(tcode,1); while (*tcode == OP_ALT); - tcode += 1 + LINK_SIZE; - break; - - /* Single-char * or ? sets the bit and tries the next item */ - - case OP_STAR: - case OP_MINSTAR: - case OP_POSSTAR: - case OP_QUERY: - case OP_MINQUERY: - case OP_POSQUERY: - tcode = set_table_bit(re, tcode + 1, FALSE, utf, ucp); - break; - - case OP_STARI: - case OP_MINSTARI: - case OP_POSSTARI: - case OP_QUERYI: - case OP_MINQUERYI: - case OP_POSQUERYI: - tcode = set_table_bit(re, tcode + 1, TRUE, utf, ucp); - break; - - /* Single-char upto sets the bit and tries the next */ - - case OP_UPTO: - case OP_MINUPTO: - case OP_POSUPTO: - tcode = set_table_bit(re, tcode + 1 + IMM2_SIZE, FALSE, utf, ucp); - break; - - case OP_UPTOI: - case OP_MINUPTOI: - case OP_POSUPTOI: - tcode = set_table_bit(re, tcode + 1 + IMM2_SIZE, TRUE, utf, ucp); - break; - - /* At least one single char sets the bit and stops */ - - case OP_EXACT: - tcode += IMM2_SIZE; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_CHAR: - case OP_PLUS: - case OP_MINPLUS: - case OP_POSPLUS: - (void)set_table_bit(re, tcode + 1, FALSE, utf, ucp); - try_next = FALSE; - break; - - case OP_EXACTI: - tcode += IMM2_SIZE; - PCRE2_FALLTHROUGH /* Fall through */ - case OP_CHARI: - case OP_PLUSI: - case OP_MINPLUSI: - case OP_POSPLUSI: - (void)set_table_bit(re, tcode + 1, TRUE, utf, ucp); - try_next = FALSE; - break; - - /* Special spacing and line-terminating items. These recognize specific - lists of characters. The difference between VSPACE and ANYNL is that the - latter can match the two-character CRLF sequence, but that is not - relevant for finding the first character, so their code here is - identical. */ - - case OP_HSPACE: - SET_BIT(CHAR_HT); - SET_BIT(CHAR_SPACE); - - /* For the 16-bit and 32-bit libraries (which can never be EBCDIC), set - the bits for NBSP and for code units >= 255, independently of UTF. */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 - SET_BIT(CHAR_NBSP); - SET_BIT(0xFF); -#else - /* For the 8-bit library in UTF-8 mode, set the bits for the first code - units of horizontal space characters. */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - SET_BIT(0xC2); /* For U+00A0 */ - SET_BIT(0xE1); /* For U+1680, U+180E */ - SET_BIT(0xE2); /* For U+2000 - U+200A, U+202F, U+205F */ - SET_BIT(0xE3); /* For U+3000 */ - } - else -#endif - /* For the 8-bit library not in UTF-8 mode, set the bit for NBSP. */ - { - SET_BIT(CHAR_NBSP); - } -#endif /* 8-bit support */ - - try_next = FALSE; - break; - - case OP_ANYNL: - case OP_VSPACE: - SET_BIT(CHAR_LF); - SET_BIT(CHAR_VT); - SET_BIT(CHAR_FF); - SET_BIT(CHAR_CR); - - /* For the 16-bit and 32-bit libraries (which can never be EBCDIC), set - the bits for NEL and for code units >= 255, independently of UTF. */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 - SET_BIT(CHAR_NEL); - SET_BIT(0xFF); -#else - /* For the 8-bit library in UTF-8 mode, set the bits for the first code - units of vertical space characters. */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - SET_BIT(0xC2); /* For U+0085 (NEL) */ - SET_BIT(0xE2); /* For U+2028, U+2029 */ - } - else -#endif - /* For the 8-bit library not in UTF-8 mode, set the bit for NEL. */ - { - SET_BIT(CHAR_NEL); - } -#endif /* 8-bit support */ - - try_next = FALSE; - break; - - /* Single character types set the bits and stop. Note that if PCRE2_UCP - is set, we do not see these opcodes because \d etc are converted to - properties. Therefore, these apply in the case when only characters less - than 256 are recognized to match the types. */ - - case OP_NOT_DIGIT: - set_nottype_bits(re, cbit_digit, table_limit); - try_next = FALSE; - break; - - case OP_DIGIT: - set_type_bits(re, cbit_digit, table_limit); - try_next = FALSE; - break; - - case OP_NOT_WHITESPACE: - set_nottype_bits(re, cbit_space, table_limit); - try_next = FALSE; - break; - - case OP_WHITESPACE: - set_type_bits(re, cbit_space, table_limit); - try_next = FALSE; - break; - - case OP_NOT_WORDCHAR: - set_nottype_bits(re, cbit_word, table_limit); - try_next = FALSE; - break; - - case OP_WORDCHAR: - set_type_bits(re, cbit_word, table_limit); - try_next = FALSE; - break; - - /* One or more character type fudges the pointer and restarts, knowing - it will hit a single character type and stop there. */ - - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEPOSPLUS: - tcode++; - break; - - case OP_TYPEEXACT: - tcode += 1 + IMM2_SIZE; - break; - - /* Zero or more repeats of character types set the bits and then - try again. */ - - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEPOSUPTO: - tcode += IMM2_SIZE; - PCRE2_FALLTHROUGH /* Fall through */ - - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPOSSTAR: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEPOSQUERY: - switch(tcode[1]) - { - default: - case OP_ANY: - case OP_ALLANY: - return SSB_FAIL; - - case OP_HSPACE: - SET_BIT(CHAR_HT); - SET_BIT(CHAR_SPACE); - - /* For the 16-bit and 32-bit libraries (which can never be EBCDIC), set - the bits for NBSP and for code units >= 255, independently of UTF. */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 - SET_BIT(CHAR_NBSP); - SET_BIT(0xFF); -#else - /* For the 8-bit library in UTF-8 mode, set the bits for the first code - units of horizontal space characters. */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - SET_BIT(0xC2); /* For U+00A0 */ - SET_BIT(0xE1); /* For U+1680, U+180E */ - SET_BIT(0xE2); /* For U+2000 - U+200A, U+202F, U+205F */ - SET_BIT(0xE3); /* For U+3000 */ - } - else -#endif - /* For the 8-bit library not in UTF-8 mode, set the bit for NBSP. */ - { - SET_BIT(CHAR_NBSP); - } -#endif /* 8-bit support */ - break; - - case OP_ANYNL: - case OP_VSPACE: - SET_BIT(CHAR_LF); - SET_BIT(CHAR_VT); - SET_BIT(CHAR_FF); - SET_BIT(CHAR_CR); - - /* For the 16-bit and 32-bit libraries (which can never be EBCDIC), set - the bits for NEL and for code units >= 255, independently of UTF. */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 - SET_BIT(CHAR_NEL); - SET_BIT(0xFF); -#else - /* For the 8-bit library in UTF-8 mode, set the bits for the first code - units of vertical space characters. */ - -#ifdef SUPPORT_UNICODE - if (utf) - { - SET_BIT(0xC2); /* For U+0085 (NEL) */ - SET_BIT(0xE2); /* For U+2028, U+2029 */ - } - else -#endif - /* For the 8-bit library not in UTF-8 mode, set the bit for NEL. */ - { - SET_BIT(CHAR_NEL); - } -#endif /* 8-bit support */ - break; - - case OP_NOT_DIGIT: - set_nottype_bits(re, cbit_digit, table_limit); - break; - - case OP_DIGIT: - set_type_bits(re, cbit_digit, table_limit); - break; - - case OP_NOT_WHITESPACE: - set_nottype_bits(re, cbit_space, table_limit); - break; - - case OP_WHITESPACE: - set_type_bits(re, cbit_space, table_limit); - break; - - case OP_NOT_WORDCHAR: - set_nottype_bits(re, cbit_word, table_limit); - break; - - case OP_WORDCHAR: - set_type_bits(re, cbit_word, table_limit); - break; - } - - tcode += 2; - break; - - /* Set-based ECLASS: treat it the same as a "complex" XCLASS; give up. */ - -#ifdef SUPPORT_WIDE_CHARS - case OP_ECLASS: - return SSB_FAIL; -#endif - - /* Extended class: if there are any property checks, or if this is a - negative XCLASS without a map, give up. If there are no property checks, - there must be wide characters on the XCLASS list, because otherwise an - XCLASS would not have been created. This means that code points >= 255 - are potential starters. In the UTF-8 case we can scan them and set bits - for the relevant leading bytes. */ - -#ifdef SUPPORT_WIDE_CHARS - case OP_XCLASS: - xclassflags = tcode[1 + LINK_SIZE]; - if ((xclassflags & XCL_HASPROP) != 0 || - (xclassflags & (XCL_MAP|XCL_NOT)) == XCL_NOT) - return SSB_FAIL; - - /* We have a positive XCLASS or a negative one without a map. Set up the - map pointer if there is one, and fall through. */ - - classmap = ((xclassflags & XCL_MAP) == 0)? NULL : - (const uint8_t *)(tcode + 1 + LINK_SIZE + 1); - - /* In UTF-8 mode, scan the character list and set bits for leading bytes, - then jump to handle the map. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (utf && (xclassflags & XCL_NOT) == 0) - { - PCRE2_UCHAR b, e; - PCRE2_SPTR p = tcode + 1 + LINK_SIZE + 1 + ((classmap == NULL)? 0:32); - tcode += GET(tcode, 1); - - if (*p >= XCL_LIST) - { - study_char_list(p, re->start_bitmap, - ((const uint8_t *)re + re->code_start)); - goto HANDLE_CLASSMAP; - } - - for (;;) switch (*p++) - { - case XCL_SINGLE: - b = *p++; - while ((*p & 0xc0) == 0x80) p++; - re->start_bitmap[b/8] |= (1u << (b&7)); - break; - - case XCL_RANGE: - b = *p++; - while ((*p & 0xc0) == 0x80) p++; - e = *p++; - while ((*p & 0xc0) == 0x80) p++; - for (; b <= e; b++) - re->start_bitmap[b/8] |= (1u << (b&7)); - break; - - case XCL_END: - goto HANDLE_CLASSMAP; - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return SSB_UNKNOWN; /* Internal error, should not occur */ - /* LCOV_EXCL_STOP */ - } - } -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 */ -#endif /* SUPPORT_WIDE_CHARS */ - - /* It seems that the fall through comment must be outside the #ifdef if - it is to avoid the gcc compiler warning. */ - - PCRE2_FALLTHROUGH /* Fall through */ - - /* Enter here for a negative non-XCLASS. In the 8-bit library, if we are - in UTF mode, any byte with a value >= 0xc4 is a potentially valid starter - because it starts a character with a value > 255. In 8-bit non-UTF mode, - there is no difference between CLASS and NCLASS. In all other wide - character modes, set the 0xFF bit to indicate code units >= 255. */ - - case OP_NCLASS: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 - if (utf) - { - re->start_bitmap[24] |= 0xf0; /* Bits for 0xc4 - 0xc8 */ - memset(re->start_bitmap+25, 0xff, 7); /* Bits for 0xc9 - 0xff */ - } - PCRE2_FALLTHROUGH /* Fall through */ -#elif PCRE2_CODE_UNIT_WIDTH != 8 - SET_BIT(0xFF); /* For characters >= 255 */ - PCRE2_FALLTHROUGH /* Fall through */ -#endif - - /* Enter here for a positive non-XCLASS. If we have fallen through from - an XCLASS, classmap will already be set; just advance the code pointer. - Otherwise, set up classmap for a non-XCLASS and advance past it. */ - - case OP_CLASS: - if (*tcode == OP_XCLASS) tcode += GET(tcode, 1); else - { - classmap = (const uint8_t *)(++tcode); - tcode += 32 / sizeof(PCRE2_UCHAR); - } - - /* When wide characters are supported, classmap may be NULL. In UTF-8 - (sic) mode, the bits in a class bit map correspond to character values, - not to byte values. However, the bit map we are constructing is for byte - values. So we have to do a conversion for characters whose code point is - greater than 127. In fact, there are only two possible starting bytes for - characters in the range 128 - 255. */ - -#if defined SUPPORT_WIDE_CHARS && PCRE2_CODE_UNIT_WIDTH == 8 - HANDLE_CLASSMAP: -#endif - if (classmap != NULL) - { -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 - if (utf) - { - for (c = 0; c < 16; c++) re->start_bitmap[c] |= classmap[c]; - for (c = 128; c < 256; c++) - { - if ((classmap[c/8] & (1u << (c&7))) != 0) - { - int d = (c >> 6) | 0xc0; /* Set bit for this starter */ - re->start_bitmap[d/8] |= (1u << (d&7)); /* and then skip on to the */ - c = (c & 0xc0) + 0x40 - 1; /* next relevant character. */ - } - } - } - else -#endif - /* In all modes except UTF-8, the two bit maps are compatible. */ - - { - for (c = 0; c < 32; c++) re->start_bitmap[c] |= classmap[c]; - } - } - - /* Act on what follows the class. For a zero minimum repeat, continue; - otherwise stop processing. */ - - switch (*tcode) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSSTAR: - case OP_CRPOSQUERY: - tcode++; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - if (GET2(tcode, 1) == 0) tcode += 1 + 2 * IMM2_SIZE; - else try_next = FALSE; - break; - - default: - try_next = FALSE; - break; - } - break; /* End of class handling case */ - } /* End of switch for opcodes */ - } /* End of try_next loop */ - - code += GET(code, 1); /* Advance to next branch */ - } -while (*code == OP_ALT); - -return yield; -} - - - -/************************************************* -* Study a compiled expression * -*************************************************/ - -/* This function is handed a compiled expression that it must study to produce -information that will speed up the matching. - -Argument: - re points to the compiled expression - -Returns: 0 normally; non-zero should never normally occur - 1 unknown opcode in set_start_bits - 2 missing capturing bracket - 3 unknown opcode in find_minlength -*/ - -int -PRIV(study)(pcre2_real_code *re) -{ -int count = 0; -PCRE2_UCHAR *code; -BOOL utf = (re->overall_options & PCRE2_UTF) != 0; -BOOL ucp = (re->overall_options & PCRE2_UCP) != 0; - -/* Find start of compiled code */ - -code = (PCRE2_UCHAR *)((uint8_t *)re + re->code_start); - -/* For a pattern that has a first code unit, or a multiline pattern that -matches only at "line start", there is no point in seeking a list of starting -code units. */ - -if ((re->flags & (PCRE2_FIRSTSET|PCRE2_STARTLINE)) == 0) - { - int depth = 0; - int rc = set_start_bits(re, code, utf, ucp, &depth); - /* LCOV_EXCL_START */ - if (rc == SSB_UNKNOWN) - { - PCRE2_DEBUG_UNREACHABLE(); - return 1; - } - /* LCOV_EXCL_STOP */ - - /* If a list of starting code units was set up, scan the list to see if only - one or two were listed. Having only one listed is rare because usually a - single starting code unit will have been recognized and PCRE2_FIRSTSET set. - If two are listed, see if they are caseless versions of the same character; - if so we can replace the list with a caseless first code unit. This gives - better performance and is plausibly worth doing for patterns such as [Ww]ord - or (word|WORD). */ - - if (rc == SSB_DONE) - { - int i; - int a = -1; - int b = -1; - uint8_t *p = re->start_bitmap; - uint32_t flags = PCRE2_FIRSTMAPSET; - - for (i = 0; i < 256; p++, i += 8) - { - uint8_t x = *p; - if (x != 0) - { - int c; - uint8_t y = x & (~x + 1); /* Least significant bit */ - if (y != x) goto DONE; /* More than one bit set */ - - /* In the 16-bit and 32-bit libraries, the bit for 0xff means "0xff and - all wide characters", so we cannot use it here. */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 - if (i == 248 && x == 0x80) goto DONE; -#endif - - /* Compute the character value */ - - c = i; - switch (x) - { - case 1: break; - case 2: c += 1; break; case 4: c += 2; break; - case 8: c += 3; break; case 16: c += 4; break; - case 32: c += 5; break; case 64: c += 6; break; - case 128: c += 7; break; - } - - /* c contains the code unit value, in the range 0-255. In 8-bit UTF - mode, only values < 128 can be used. In all the other cases, c is a - character value. */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 - if (utf && c > 127) goto DONE; -#endif - if (a < 0) a = c; /* First one found, save in a */ - else if (b < 0) /* Second one found */ - { - int d = TABLE_GET((unsigned int)c, re->tables + fcc_offset, c); - -#ifdef SUPPORT_UNICODE - if (utf || ucp) - { - if (UCD_CASESET(c) != 0) goto DONE; /* Multiple case set */ - if (c > 127) d = UCD_OTHERCASE(c); - } -#endif /* SUPPORT_UNICODE */ - - if (d != a) goto DONE; /* Not the other case of a */ - b = c; /* Save second in b */ - -#ifdef EBCDIC - /* To match ASCII (which puts the uppercase one in a), swap a & b - if needed. This doesn't really matter, but neatens the tests. */ - if (TABLE_GET((unsigned int)a, re->tables + lcc_offset, a) == a) - { - b = a; - a = c; - } -#endif - } - else goto DONE; /* More than two characters found */ - } - } - - /* Replace the start code unit bits with a first code unit. If it is the - same as a required later code unit, then clear the required later code - unit. This is because a search for a required code unit starts after an - explicit first code unit, but at a code unit found from the bitmap. - Patterns such as /a*a/ don't work if both the start unit and required - unit are the same. */ - - if (a >= 0) { - if ((re->flags & PCRE2_LASTSET) && (re->last_codeunit == (uint32_t)a || (b >= 0 && re->last_codeunit == (uint32_t)b))) { - re->flags &= ~(PCRE2_LASTSET | PCRE2_LASTCASELESS); - re->last_codeunit = 0; - } - re->first_codeunit = a; - flags = PCRE2_FIRSTSET; - if (b >= 0) flags |= PCRE2_FIRSTCASELESS; - } - - DONE: - re->flags |= flags; - } - } - -/* Find the minimum length of subject string. If the pattern can match an empty -string, the minimum length is already known. If the pattern contains (*ACCEPT) -all bets are off, and we don't even try to find a minimum length. If there are -more back references than the size of the vector we are going to cache them in, -do nothing. A pattern that complicated will probably take a long time to -analyze and may in any case turn out to be too complicated. Note that back -reference minima are held as 16-bit numbers. */ - -if ((re->flags & (PCRE2_MATCH_EMPTY|PCRE2_HASACCEPT)) == 0 && - re->top_backref <= MAX_CACHE_BACKREF) - { - int min; - int backref_cache[MAX_CACHE_BACKREF+1]; - backref_cache[0] = 0; /* Highest one that is set */ - min = find_minlength(re, code, code, utf, NULL, &count, backref_cache); - switch(min) - { - case -1: /* \C in UTF mode or over-complex regex */ - break; /* Leave minlength unchanged (will be zero) */ - - /* LCOV_EXCL_START */ - case -2: - PCRE2_DEBUG_UNREACHABLE(); - return 2; /* missing capturing bracket */ - /* LCOV_EXCL_STOP */ - - /* LCOV_EXCL_START */ - case -3: - PCRE2_DEBUG_UNREACHABLE(); - return 3; /* unrecognized opcode */ - /* LCOV_EXCL_STOP */ - - default: - re->minlength = (min > (int)UINT16_MAX)? (int)UINT16_MAX : min; - break; - } - } - -return 0; -} - -/* End of pcre2_study.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_substitute.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_substitute.c deleted file mode 100644 index 9787188..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_substitute.c +++ /dev/null @@ -1,1761 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -#define PTR_STACK_SIZE 20 - -#define SUBSTITUTE_OPTIONS \ - (PCRE2_SUBSTITUTE_EXTENDED|PCRE2_SUBSTITUTE_GLOBAL| \ - PCRE2_SUBSTITUTE_LITERAL|PCRE2_SUBSTITUTE_MATCHED| \ - PCRE2_SUBSTITUTE_OVERFLOW_LENGTH|PCRE2_SUBSTITUTE_REPLACEMENT_ONLY| \ - PCRE2_SUBSTITUTE_UNKNOWN_UNSET|PCRE2_SUBSTITUTE_UNSET_EMPTY) - - - -/************************************************* -* Find end of substitute text * -*************************************************/ - -/* In extended mode, we recognize ${name:+set text:unset text} and similar -constructions. This requires the identification of unescaped : and } -characters. This function scans for such. It must deal with nested ${ -constructions. The pointer to the text is updated, either to the required end -character, or to where an error was detected. - -Arguments: - code points to the compiled expression (for options) - ptrptr points to the pointer to the start of the text (updated) - ptrend end of the whole string - last TRUE if the last expected string (only } recognized) - -Returns: 0 on success - negative error code on failure -*/ - -static int -find_text_end(const pcre2_code *code, PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, - BOOL last) -{ -int rc = 0; -uint32_t nestlevel = 0; -BOOL literal = FALSE; -PCRE2_SPTR ptr = *ptrptr; - -for (; ptr < ptrend; ptr++) - { - if (literal) - { - if (ptr[0] == CHAR_BACKSLASH && ptr < ptrend - 1 && ptr[1] == CHAR_E) - { - literal = FALSE; - ptr += 1; - } - } - - else if (*ptr == CHAR_RIGHT_CURLY_BRACKET) - { - if (nestlevel == 0) goto EXIT; - nestlevel--; - } - - else if (*ptr == CHAR_COLON && !last && nestlevel == 0) goto EXIT; - - else if (*ptr == CHAR_DOLLAR_SIGN) - { - if (ptr < ptrend - 1 && ptr[1] == CHAR_LEFT_CURLY_BRACKET) - { - nestlevel++; - ptr += 1; - } - } - - else if (*ptr == CHAR_BACKSLASH) - { - int erc; - int errorcode; - uint32_t ch; - - if (ptr < ptrend - 1) switch (ptr[1]) - { - case CHAR_L: - case CHAR_l: - case CHAR_U: - case CHAR_u: - ptr += 1; - continue; - } - - ptr += 1; /* Must point after \ */ - erc = PRIV(check_escape)(&ptr, ptrend, &ch, &errorcode, - code->overall_options, code->extra_options, code->top_bracket, FALSE, NULL); - if (errorcode != 0) - { - /* errorcode from check_escape is positive, so must not be returned by - pcre2_substitute(). */ - rc = PCRE2_ERROR_BADREPESCAPE; - goto EXIT; - } - - switch(erc) - { - case 0: /* Data character */ - case ESC_b: /* Data character */ - case ESC_v: /* Data character */ - case ESC_E: /* Isolated \E is ignored */ - break; - - case ESC_Q: - literal = TRUE; - break; - - case ESC_g: - /* The \g form (\g already handled by check_escape) - - Don't worry about finding the matching ">". We are super, super lenient - about validating ${} replacements inside find_text_end(), so we certainly - don't need to worry about other syntax. Importantly, a \g<..> or $<...> - sequence can't contain a '}' character. */ - break; - - default: - if (erc < 0) - break; /* capture group reference */ - rc = PCRE2_ERROR_BADREPESCAPE; - goto EXIT; - } - } - } - -rc = PCRE2_ERROR_REPMISSINGBRACE; /* Terminator not found */ - -EXIT: -*ptrptr = ptr; -return rc; -} - - -/************************************************* -* Validate group name * -*************************************************/ - -/* This function scans for a capture group name, validating it -consists of legal characters, is not empty, and does not exceed -MAX_NAME_SIZE. - -Arguments: - ptrptr points to the pointer to the start of the text (updated) - ptrend end of the whole string - utf true if the input is UTF-encoded - ctypes pointer to the character types table - -Returns: TRUE if a name was read - FALSE otherwise -*/ - -static BOOL -read_name_subst(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, BOOL utf, - const uint8_t* ctypes) -{ -PCRE2_SPTR ptr = *ptrptr; -PCRE2_SPTR nameptr = ptr; - -if (ptr >= ptrend) /* No characters in name */ - goto FAILED; - -/* We do not need to check whether the name starts with a non-digit. -We are simply referencing names here, not defining them. */ - -/* See read_name in the pcre2_compile.c for the corresponding logic -restricting group names inside the pattern itself. */ - -#ifdef SUPPORT_UNICODE -if (utf) - { - uint32_t c, type; - - while (ptr < ptrend) - { - GETCHAR(c, ptr); - type = UCD_CHARTYPE(c); - if (type != ucp_Nd && PRIV(ucp_gentype)[type] != ucp_L && - c != CHAR_UNDERSCORE) break; - ptr++; - FORWARDCHARTEST(ptr, ptrend); - } - } -else -#else -(void)utf; /* Avoid compiler warning */ -#endif /* SUPPORT_UNICODE */ - -/* Handle group names in non-UTF modes. */ - - { - while (ptr < ptrend && MAX_255(*ptr) && (ctypes[*ptr] & ctype_word) != 0) - { - ptr++; - } - } - -/* Check name length */ - -if (ptr - nameptr > MAX_NAME_SIZE) - goto FAILED; - -/* Subpattern names must not be empty */ -if (ptr == nameptr) - goto FAILED; - -*ptrptr = ptr; -return TRUE; - -FAILED: -*ptrptr = ptr; -return FALSE; -} - - -/************************************************* -* Case transformations * -*************************************************/ - -#define PCRE2_SUBSTITUTE_CASE_NONE 0 -/* 1, 2, 3 are PCRE2_SUBSTITUTE_CASE_LOWER, UPPER, TITLE_FIRST. */ -#define PCRE2_SUBSTITUTE_CASE_REVERSE_TITLE_FIRST 4 - -typedef struct { - int to_case; /* One of PCRE2_SUBSTITUTE_CASE_xyz */ - BOOL single_char; -} case_state; - -/* Helper to guess how much a string is likely to increase in size when -case-transformed. Usually, strings don't change size at all, but some rare -characters do grow. Estimate +10%, plus another few characters. - -Performing this estimation is unfortunate, but inevitable, since we can't call -the callout if we ran out of buffer space to prepare its input. - -Because this estimate is inexact (and in pathological cases, underestimates the -required buffer size) we must document that when you have a -substitute_case_callout, and you are using PCRE2_SUBSTITUTE_OVERFLOW_LENGTH, you -may need more than two calls to determine the final buffer size. */ - -static PCRE2_SIZE -pessimistic_case_inflation(PCRE2_SIZE len) -{ -return (len >> 3u) + 10; -} - -/* Case transformation behaviour if no callout is passed. */ - -static PCRE2_SIZE -default_substitute_case_callout( - PCRE2_SPTR input, PCRE2_SIZE input_len, - PCRE2_UCHAR *output, PCRE2_SIZE output_cap, - case_state *state, const pcre2_code *code) -{ -PCRE2_SPTR input_end = input + input_len; -#ifdef SUPPORT_UNICODE -BOOL utf; -BOOL ucp; -#endif -PCRE2_UCHAR temp[6]; -BOOL next_to_upper; -BOOL rest_to_upper; -BOOL single_char; -BOOL overflow = FALSE; -PCRE2_SIZE written = 0; - -/* Helpful simplifying invariant: input and output are disjoint buffers. -I believe that this code is technically undefined behaviour, because the two -pointers input/output are "unrelated" pointers and hence not comparable. Casting -via char* bypasses some but not all of those technical rules. It is not included -in release builds, in any case. */ -PCRE2_ASSERT((char *)(input + input_len) <= (char *)output || - (char *)(output + output_cap) <= (char *)input); - -#ifdef SUPPORT_UNICODE -utf = (code->overall_options & PCRE2_UTF) != 0; -ucp = (code->overall_options & PCRE2_UCP) != 0; -#endif - -if (input_len == 0) return 0; - -switch (state->to_case) - { - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return 0; - /* LCOV_EXCL_STOP */ - - case PCRE2_SUBSTITUTE_CASE_LOWER: /* Can be single_char TRUE or FALSE */ - case PCRE2_SUBSTITUTE_CASE_UPPER: /* Can only be single_char FALSE */ - next_to_upper = rest_to_upper = (state->to_case == PCRE2_SUBSTITUTE_CASE_UPPER); - break; - - case PCRE2_SUBSTITUTE_CASE_TITLE_FIRST: /* Can be single_char TRUE or FALSE */ - next_to_upper = TRUE; - rest_to_upper = FALSE; - state->to_case = PCRE2_SUBSTITUTE_CASE_LOWER; - break; - - case PCRE2_SUBSTITUTE_CASE_REVERSE_TITLE_FIRST: /* Can only be single_char FALSE */ - next_to_upper = FALSE; - rest_to_upper = TRUE; - state->to_case = PCRE2_SUBSTITUTE_CASE_UPPER; - break; - } - -single_char = state->single_char; -if (single_char) - state->to_case = PCRE2_SUBSTITUTE_CASE_NONE; - -while (input < input_end) - { - uint32_t ch; - unsigned int chlen; - - GETCHARINCTEST(ch, input); - -#ifdef SUPPORT_UNICODE - if ((utf || ucp) && ch >= 128) - { - uint32_t type = UCD_CHARTYPE(ch); - if (PRIV(ucp_gentype)[type] == ucp_L && - type != (next_to_upper? ucp_Lu : ucp_Ll)) - ch = UCD_OTHERCASE(ch); - - /* TODO This is far from correct... it doesn't support the SpecialCasing.txt - mappings, but worse, it's not even correct for all the ordinary case - mappings. We should add support for those (at least), and then add the - SpecialCasing.txt mappings for Esszet and ligatures, and finally use the - Turkish casing flag on the match context. */ - } - else -#endif - if (MAX_255(ch)) - { - if (((code->tables + cbits_offset + - (next_to_upper? cbit_upper:cbit_lower) - )[ch/8] & (1u << (ch%8))) == 0) - ch = (code->tables + fcc_offset)[ch]; - } - -#ifdef SUPPORT_UNICODE - if (utf) chlen = PRIV(ord2utf)(ch, temp); else -#endif - { - temp[0] = ch; - chlen = 1; - } - - if (!overflow && chlen <= output_cap) - { - memcpy(output, temp, CU2BYTES(chlen)); - output += chlen; - output_cap -= chlen; - } - else - { - overflow = TRUE; - } - - if (chlen > ~(PCRE2_SIZE)0 - written) /* Integer overflow */ - return ~(PCRE2_SIZE)0; - written += chlen; - - next_to_upper = rest_to_upper; - - /* memcpy the remainder, if only transforming a single character. */ - - if (single_char) - { - PCRE2_SIZE rest_len = input_end - input; - - if (!overflow && rest_len <= output_cap) - memcpy(output, input, CU2BYTES(rest_len)); - - if (rest_len > ~(PCRE2_SIZE)0 - written) /* Integer overflow */ - return ~(PCRE2_SIZE)0; - written += rest_len; - - return written; - } - } - -return written; -} - -/* Helper to perform the call to the substitute_case_callout. We wrap the -user-provided callout because our internal arguments are slightly extended. We -don't want the user callout to handle the case of "\l" (first character only to -lowercase) or "\l\U" (first character to lowercase, rest to uppercase) because -those are not operations defined by Unicode. Instead the user callout simply -needs to provide the three Unicode primitives: lower, upper, titlecase. */ - -static PCRE2_SIZE -do_case_copy( - PCRE2_UCHAR *input_output, PCRE2_SIZE input_len, PCRE2_SIZE output_cap, - case_state *state, BOOL utf, - PCRE2_SIZE (*substitute_case_callout)(PCRE2_SPTR, PCRE2_SIZE, PCRE2_UCHAR *, - PCRE2_SIZE, int, void *), - void *substitute_case_callout_data) -{ -PCRE2_SPTR input = input_output; -PCRE2_UCHAR *output = input_output; -PCRE2_SIZE rc; -PCRE2_SIZE rc2; -int ch1_to_case; -int rest_to_case; -PCRE2_UCHAR ch1[6]; -PCRE2_SIZE ch1_len; -PCRE2_SPTR rest; -PCRE2_SIZE rest_len; -BOOL ch1_overflow = FALSE; -BOOL rest_overflow = FALSE; - -#if PCRE2_CODE_UNIT_WIDTH == 32 || !defined(SUPPORT_UNICODE) -(void)utf; /* Avoid compiler warning. */ -#endif - -PCRE2_ASSERT(input_len != 0); - -switch (state->to_case) - { - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return 0; - /* LCOV_EXCL_STOP */ - - case PCRE2_SUBSTITUTE_CASE_LOWER: /* Can be single_char TRUE or FALSE */ - case PCRE2_SUBSTITUTE_CASE_UPPER: /* Can only be single_char FALSE */ - case PCRE2_SUBSTITUTE_CASE_TITLE_FIRST: /* Can be single_char TRUE or FALSE */ - - /* The easy case, where our internal casing operations align with those of - the callout. */ - - if (state->single_char == FALSE) - { - rc = substitute_case_callout(input, input_len, output, output_cap, - state->to_case, substitute_case_callout_data); - - if (state->to_case == PCRE2_SUBSTITUTE_CASE_TITLE_FIRST) - state->to_case = PCRE2_SUBSTITUTE_CASE_LOWER; - - return rc; - } - - ch1_to_case = state->to_case; - rest_to_case = PCRE2_SUBSTITUTE_CASE_NONE; - break; - - case PCRE2_SUBSTITUTE_CASE_REVERSE_TITLE_FIRST: /* Can only be single_char FALSE */ - ch1_to_case = PCRE2_SUBSTITUTE_CASE_LOWER; - rest_to_case = PCRE2_SUBSTITUTE_CASE_UPPER; - break; - } - -/* Identify the leading character. Take copy, because its storage overlaps with -`output`, and hence may be scrambled by the callout. */ - - { - PCRE2_SPTR ch_end = input; - uint32_t ch; - - GETCHARINCTEST(ch, ch_end); - (void) ch; - PCRE2_ASSERT(ch_end <= input + input_len && ch_end - input <= 6); - ch1_len = ch_end - input; - memcpy(ch1, input, CU2BYTES(ch1_len)); - } - -rest = input + ch1_len; -rest_len = input_len - ch1_len; - -/* Transform just ch1. The buffers are always in-place (input == output). With a -custom callout, we need a loop to discover its required buffer size. The loop -wouldn't be required if the callout were well-behaved, but it might be naughty -and return "5" the first time, then "10" the next time we call it using the -exact same input! */ - - { - PCRE2_SIZE ch1_cap; - PCRE2_SIZE max_ch1_cap; - - ch1_cap = ch1_len; /* First attempt uses the space vacated by ch1. */ - PCRE2_ASSERT(output_cap >= input_len && input_len >= rest_len); - max_ch1_cap = output_cap - rest_len; - - while (TRUE) - { - rc = substitute_case_callout(ch1, ch1_len, output, ch1_cap, ch1_to_case, - substitute_case_callout_data); - if (rc == ~(PCRE2_SIZE)0) return rc; - - if (rc <= ch1_cap) break; - - if (rc > max_ch1_cap) - { - ch1_overflow = TRUE; - break; - } - - /* Move the rest to the right, to make room for expanding ch1. */ - - memmove(input_output + rc, rest, CU2BYTES(rest_len)); - rest = input + rc; - - ch1_cap = rc; - - /* Proof of loop termination: `ch1_cap` is growing on each iteration, but - the loop ends if `rc` reaches the (unchanging) upper bound of output_cap. */ - } - } - -if (rest_to_case == PCRE2_SUBSTITUTE_CASE_NONE) - { - if (!ch1_overflow) - { - PCRE2_ASSERT(rest_len <= output_cap - rc); - memmove(output + rc, rest, CU2BYTES(rest_len)); - } - rc2 = rest_len; - - state->to_case = PCRE2_SUBSTITUTE_CASE_NONE; - } -else - { - PCRE2_UCHAR dummy[1]; - - rc2 = substitute_case_callout(rest, rest_len, - ch1_overflow? dummy : output + rc, - ch1_overflow? 0u : output_cap - rc, - rest_to_case, substitute_case_callout_data); - if (rc2 == ~(PCRE2_SIZE)0) return rc2; - - if (!ch1_overflow && rc2 > output_cap - rc) rest_overflow = TRUE; - - /* If ch1 grows so that `xform(ch1)+rest` can't fit in the buffer, but then - `rest` shrinks, it's actually possible for the total calculated length of - `xform(ch1)+xform(rest)` to come out at less than output_cap. But we can't - report that, because it would make it seem that the operation succeeded. - If either of xform(ch1) or xform(rest) won't fit in the buffer, our final - result must be > output_cap. */ - if (ch1_overflow && rc2 < rest_len) - rc2 = rest_len; - - state->to_case = PCRE2_SUBSTITUTE_CASE_UPPER; - } - -if (rc2 > ~(PCRE2_SIZE)0 - rc) /* Integer overflow */ - return ~(PCRE2_SIZE)0; - -PCRE2_ASSERT(!(ch1_overflow || rest_overflow) || rc + rc2 > output_cap); -(void)rest_overflow; - -return rc + rc2; -} - - -/************************************************* -* Match and substitute * -*************************************************/ - -/* This function applies a compiled re to a subject string and creates a new -string with substitutions. The first 7 arguments are the same as for -pcre2_match(). Either string length may be PCRE2_ZERO_TERMINATED. - -Arguments: - code points to the compiled expression - subject points to the subject string - length length of subject string (may contain binary zeros) - start_offset where to start in the subject string - options option bits - match_data points to a match_data block, or is NULL - context points a PCRE2 context - replacement points to the replacement string - rlength length of replacement string - buffer where to put the substituted string - blength points to length of buffer; updated to length of string - -Returns: >= 0 number of substitutions made - < 0 an error code - PCRE2_ERROR_BADREPLACEMENT means invalid use of $ -*/ - -/* This macro checks for space in the buffer before copying into it. On -overflow, either give an error immediately, or keep on, accumulating the -length. */ - -#define CHECKMEMCPY(from, length_) \ - do { \ - PCRE2_SIZE chkmc_length = length_; \ - if (overflowed) \ - { \ - if (chkmc_length > ~(PCRE2_SIZE)0 - extra_needed) /* Integer overflow */ \ - goto TOOLARGEREPLACE; \ - extra_needed += chkmc_length; \ - } \ - else if (lengthleft < chkmc_length) \ - { \ - if ((suboptions & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) == 0) goto NOROOM; \ - overflowed = TRUE; \ - extra_needed = chkmc_length - lengthleft; \ - } \ - else \ - { \ - memcpy(buffer + buff_offset, from, CU2BYTES(chkmc_length)); \ - buff_offset += chkmc_length; \ - lengthleft -= chkmc_length; \ - } \ - } \ - while (0) - -/* This macro checks for space and copies characters with casing modifications. -On overflow, it behaves as for CHECKMEMCPY(). - -When substitute_case_callout is NULL, the source and destination buffers must -not overlap, because our default handler does not support this. */ - -#define CHECKCASECPY_BASE(length_, do_call) \ - do { \ - PCRE2_SIZE chkcc_length = (PCRE2_SIZE)(length_); \ - PCRE2_SIZE chkcc_rc; \ - do_call \ - if (lengthleft < chkcc_rc) \ - { \ - if ((suboptions & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) == 0) goto NOROOM; \ - overflowed = TRUE; \ - extra_needed = chkcc_rc - lengthleft; \ - } \ - else \ - { \ - buff_offset += chkcc_rc; \ - lengthleft -= chkcc_rc; \ - } \ - } \ - while (0) - -#define CHECKCASECPY_DEFAULT(from, length_) \ - CHECKCASECPY_BASE(length_, { \ - chkcc_rc = default_substitute_case_callout(from, chkcc_length, \ - buffer + buff_offset, \ - overflowed? 0 : lengthleft, \ - &forcecase, code); \ - if (overflowed) \ - { \ - if (chkcc_rc > ~(PCRE2_SIZE)0 - extra_needed) /* Integer overflow */ \ - goto TOOLARGEREPLACE; \ - extra_needed += chkcc_rc; \ - break; \ - } \ - }) - -#define CHECKCASECPY_CALLOUT(length_) \ - CHECKCASECPY_BASE(length_, { \ - chkcc_rc = do_case_copy(buffer + buff_offset, chkcc_length, \ - lengthleft, &forcecase, utf, \ - substitute_case_callout, \ - substitute_case_callout_data); \ - if (chkcc_rc == ~(PCRE2_SIZE)0) goto CASEERROR; \ - }) - -/* This macro does a delayed case transformation, for the situation when we have -a case-forcing callout. */ - -#define DELAYEDFORCECASE() \ - do { \ - PCRE2_SIZE chars_outstanding = (buff_offset - casestart_offset) + \ - (extra_needed - casestart_extra_needed); \ - if (chars_outstanding > 0) \ - { \ - if (overflowed) \ - { \ - PCRE2_SIZE guess = pessimistic_case_inflation(chars_outstanding); \ - if (guess > ~(PCRE2_SIZE)0 - extra_needed) /* Integer overflow */ \ - goto TOOLARGEREPLACE; \ - extra_needed += guess; \ - } \ - else \ - { \ - /* Rewind the buffer */ \ - lengthleft += (buff_offset - casestart_offset); \ - buff_offset = casestart_offset; \ - /* Care! In-place case transformation */ \ - CHECKCASECPY_CALLOUT(chars_outstanding); \ - } \ - } \ - } \ - while (0) - - -/* Here's the function */ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substitute(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, - PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data, - pcre2_match_context *mcontext, PCRE2_SPTR replacement, PCRE2_SIZE rlength, - PCRE2_UCHAR *buffer, PCRE2_SIZE *blength) -{ -int rc; -int subs; -uint32_t ovector_count; -uint32_t goptions = 0; -uint32_t suboptions; -pcre2_match_data *internal_match_data = NULL; -BOOL escaped_literal = FALSE; -BOOL overflowed = FALSE; -BOOL use_existing_match; -BOOL replacement_only; -BOOL utf = (code->overall_options & PCRE2_UTF) != 0; -PCRE2_UCHAR temp[6]; -PCRE2_UCHAR null_str[1] = { 0xcd }; -PCRE2_SPTR original_subject = subject; -PCRE2_SPTR ptr; -PCRE2_SPTR repend = NULL; -PCRE2_SIZE extra_needed = 0; -PCRE2_SIZE buff_offset, buff_length, lengthleft, fraglength; -PCRE2_SIZE *ovector; -PCRE2_SIZE ovecsave[2] = { 0, 0 }; -pcre2_substitute_callout_block scb; -PCRE2_SIZE sub_start_extra_needed; -PCRE2_SIZE (*substitute_case_callout)(PCRE2_SPTR, PCRE2_SIZE, PCRE2_UCHAR *, - PCRE2_SIZE, int, void *) = NULL; -void *substitute_case_callout_data = NULL; - -/* General initialization */ - -buff_offset = 0; -lengthleft = buff_length = *blength; -*blength = PCRE2_UNSET; - -if (mcontext != NULL) - { - substitute_case_callout = mcontext->substitute_case_callout; - substitute_case_callout_data = mcontext->substitute_case_callout_data; - } - -/* Partial matching is not valid. This must come after setting *blength to -PCRE2_UNSET, so as not to imply an offset in the replacement. */ - -if ((options & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0) - return PCRE2_ERROR_BADOPTION; - -/* Validate length and find the end of the replacement. A NULL replacement of -zero length is interpreted as an empty string. */ - -if (replacement == NULL) - { - if (rlength != 0) return PCRE2_ERROR_NULL; - replacement = null_str; - } - -if (rlength == PCRE2_ZERO_TERMINATED) rlength = PRIV(strlen)(replacement); -repend = replacement + rlength; - -/* A NULL subject of zero length is treated as an empty string. */ - -if (subject == NULL) - { - if (length != 0) return PCRE2_ERROR_NULL; - subject = null_str; - } - -if (length == PCRE2_ZERO_TERMINATED) length = PRIV(strlen)(subject); - -/* Check for using a match that has already happened. Note that the subject -pointer in the match data may be NULL after a no-match. */ - -use_existing_match = ((options & PCRE2_SUBSTITUTE_MATCHED) != 0); -replacement_only = ((options & PCRE2_SUBSTITUTE_REPLACEMENT_ONLY) != 0); - -if (use_existing_match && match_data == NULL) return PCRE2_ERROR_NULL; - -/* If an existing match is being passed in, we should check that it matches -the passed-in subject pointer, length, and match options. We don't currently -have a use-case for someone to match on one subject, then try and use that -match data on a different subject. In a UTF-encoded string, a simple change -like replacing one character for another won't preserve the code unit offsets, -so it's hard to see, in the general case, how it would be safe or useful to -support swapping or mutating the subject string. - -Similarly, using different match options between the first (external) and -subsequent (internal, global) matches is hard to justify. */ - -if (use_existing_match) - { - /* Return early, as the rest of the match_data may not have been - initialised. This duplicates and must be in sync with the check below that - aborts substitution on any result other than success or no-match. */ - if (match_data->rc < 0 && match_data->rc != PCRE2_ERROR_NOMATCH) - return match_data->rc; - - /* Not supported if the passed-in match was from the DFA interpreter. */ - if (match_data->matchedby == PCRE2_MATCHEDBY_DFA_INTERPRETER) - return PCRE2_ERROR_DFA_UFUNC; - - if (code != match_data->code) - return PCRE2_ERROR_DIFFSUBSPATTERN; - - /* We want the passed-in subject strings to match. This implies the effective - length must match, and either: the pointers are equal (with strict matching - of NULL against NULL); or, the special case of PCRE2_COPY_MATCHED_SUBJECT - where we cannot compare pointers but we can verify the contents. */ - if (length != match_data->subject_length || - !(original_subject == match_data->subject || - ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0 && - (length == 0 || - memcmp(subject, match_data->subject, CU2BYTES(length)) == 0)))) - return PCRE2_ERROR_DIFFSUBSSUBJECT; - - if (start_offset != match_data->start_offset) - return PCRE2_ERROR_DIFFSUBSOFFSET; - - if ((options & ~SUBSTITUTE_OPTIONS) != match_data->options) - return PCRE2_ERROR_DIFFSUBSOPTIONS; - } - -/* If starting from an existing match, there must be an externally provided -match data block. We create an internal match_data block in two cases: (a) an -external one is not supplied (and we are not starting from an existing match); -(b) an existing match is to be used for the first substitution. In the latter -case, we copy the existing match into the internal block, except for any cached -heap frame size and pointer. This ensures that no changes are made to the -external match data block. */ - -/* WARNING: In both cases below a general context is constructed "by hand" -because calling pcre2_general_context_create() involves a memory allocation. If -the contents of a general context control block are ever changed there will -have to be changes below. */ - -if (match_data == NULL) - { - pcre2_general_context gcontext; - gcontext.memctl = (mcontext == NULL)? - ((pcre2_real_code *)code)->memctl : - ((pcre2_real_match_context *)mcontext)->memctl; - match_data = internal_match_data = - pcre2_match_data_create_from_pattern(code, &gcontext); - if (internal_match_data == NULL) return PCRE2_ERROR_NOMEMORY; - } - -else if (use_existing_match) - { - int pairs; - pcre2_general_context gcontext; - gcontext.memctl = (mcontext == NULL)? - ((pcre2_real_code *)code)->memctl : - ((pcre2_real_match_context *)mcontext)->memctl; - pairs = (code->top_bracket + 1 < match_data->oveccount)? - code->top_bracket + 1 : match_data->oveccount; - internal_match_data = pcre2_match_data_create(match_data->oveccount, - &gcontext); - if (internal_match_data == NULL) return PCRE2_ERROR_NOMEMORY; - memcpy(internal_match_data, match_data, offsetof(pcre2_match_data, ovector) - + 2*pairs*sizeof(PCRE2_SIZE)); - internal_match_data->heapframes = NULL; - internal_match_data->heapframes_size = 0; - /* Ensure that the subject is not freed when internal_match_data is */ - internal_match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT; - match_data = internal_match_data; - } - -/* If using an internal match data, there's no need to copy the subject. */ - -if (internal_match_data != NULL) options &= ~PCRE2_COPY_MATCHED_SUBJECT; - -/* Remember ovector details */ - -ovector = pcre2_get_ovector_pointer(match_data); -ovector_count = pcre2_get_ovector_count(match_data); - -/* Fixed things in the callout block */ - -scb.version = 0; -scb.input = subject; -scb.output = (PCRE2_SPTR)buffer; -scb.ovector = ovector; - -/* Check UTF replacement string if necessary. */ - -#ifdef SUPPORT_UNICODE -if (utf && (options & PCRE2_NO_UTF_CHECK) == 0) - { - rc = PRIV(valid_utf)(replacement, rlength, &(match_data->startchar)); - if (rc != 0) - { - match_data->leftchar = 0; - goto EXIT; - } - } -#endif /* SUPPORT_UNICODE */ - -/* Save the substitute options and remove them from the match options. */ - -suboptions = options & SUBSTITUTE_OPTIONS; -options &= ~SUBSTITUTE_OPTIONS; - -/* Error if the start match offset is greater than the length of the subject. */ - -if (start_offset > length) - { - match_data->leftchar = 0; - rc = PCRE2_ERROR_BADOFFSET; - goto EXIT; - } - -/* Copy up to the start offset, unless only the replacement is required. */ - -if (!replacement_only) CHECKMEMCPY(subject, start_offset); - -/* Loop for global substituting. If PCRE2_SUBSTITUTE_MATCHED is set, the first -match is taken from the match_data that was passed in. */ - -subs = 0; -for (;;) - { - PCRE2_SPTR ptrstack[PTR_STACK_SIZE]; - uint32_t ptrstackptr = 0; - case_state forcecase = { PCRE2_SUBSTITUTE_CASE_NONE, FALSE }; - PCRE2_SIZE casestart_offset = 0; - PCRE2_SIZE casestart_extra_needed = 0; - - if (use_existing_match) - { - rc = match_data->rc; - use_existing_match = FALSE; - } - else rc = pcre2_match(code, subject, length, start_offset, options|goptions, - match_data, mcontext); - -#ifdef SUPPORT_UNICODE - if (utf) options |= PCRE2_NO_UTF_CHECK; /* Only need to check once */ -#endif - - /* Any error other than no match returns the error code. No match breaks the - global loop. */ - - if (rc == PCRE2_ERROR_NOMATCH) break; - - if (rc < 0) goto EXIT; - - /* Handle a successful match. Matches that use \K to end before they start - or start before the current point in the subject are not supported. */ - - if (ovector[1] < ovector[0] || ovector[0] < start_offset) - { - rc = PCRE2_ERROR_BADSUBSPATTERN; - goto EXIT; - } - - /* Assert that our replacement loop is making progress, checked even in - release builds. This should be impossible to hit, however, an infinite loop - would be fairly catastrophic. - - "Progress" is measured as ovector[1] strictly advancing, or, an empty match - after a non-empty match. */ - - /* LCOV_EXCL_START */ - if (subs > 0 && - !(ovector[1] > ovecsave[1] || - (ovector[1] == ovector[0] && ovecsave[1] > ovecsave[0] && - ovector[1] == ovecsave[1]))) - { - PCRE2_DEBUG_UNREACHABLE(); - rc = PCRE2_ERROR_INTERNAL_DUPMATCH; - goto EXIT; - } - /* LCOV_EXCL_STOP */ - - ovecsave[0] = ovector[0]; - ovecsave[1] = ovector[1]; - - /* Count substitutions with a paranoid check for integer overflow; surely no - real call to this function would ever hit this! */ - - if (subs == INT_MAX) - { - rc = PCRE2_ERROR_TOOMANYREPLACE; - goto EXIT; - } - subs++; - - /* Copy the text leading up to the match (unless not required); remember - where the insert begins and how many ovector pairs are set; and remember how - much space we have requested in extra_needed. */ - - if (rc == 0) rc = ovector_count; - fraglength = ovector[0] - start_offset; - if (!replacement_only) CHECKMEMCPY(subject + start_offset, fraglength); - scb.output_offsets[0] = buff_offset; - scb.oveccount = rc; - sub_start_extra_needed = extra_needed; - - /* Process the replacement string. If the entire replacement is literal, just - copy it with length check. */ - - ptr = replacement; - if ((suboptions & PCRE2_SUBSTITUTE_LITERAL) != 0) - { - CHECKMEMCPY(ptr, rlength); - } - - /* Within a non-literal replacement, which must be scanned character by - character, local literal mode can be set by \Q, but only in extended mode - when backslashes are being interpreted. In extended mode we must handle - nested substrings that are to be reprocessed. */ - - else for (;;) - { - uint32_t ch; - unsigned int chlen; - int group; - uint32_t special; - PCRE2_SPTR text1_start = NULL; - PCRE2_SPTR text1_end = NULL; - PCRE2_SPTR text2_start = NULL; - PCRE2_SPTR text2_end = NULL; - PCRE2_UCHAR name[MAX_NAME_SIZE + 1]; - - /* If at the end of a nested substring, pop the stack. */ - - if (ptr >= repend) - { - if (ptrstackptr == 0) break; /* End of replacement string */ - repend = ptrstack[--ptrstackptr]; - ptr = ptrstack[--ptrstackptr]; - continue; - } - - /* Handle the next character */ - - if (escaped_literal) - { - if (ptr[0] == CHAR_BACKSLASH && ptr < repend - 1 && ptr[1] == CHAR_E) - { - escaped_literal = FALSE; - ptr += 2; - continue; - } - goto LOADLITERAL; - } - - /* Not in literal mode. */ - - if (*ptr == CHAR_DOLLAR_SIGN) - { - BOOL inparens; - BOOL inangle; - BOOL star; - PCRE2_SIZE sublength; - PCRE2_UCHAR next; - PCRE2_SPTR subptr, subptrend; - - if (++ptr >= repend) goto BAD; - if ((next = *ptr) == CHAR_DOLLAR_SIGN) goto LOADLITERAL; - - special = 0; - text1_start = NULL; - text1_end = NULL; - text2_start = NULL; - text2_end = NULL; - group = -1; - inparens = FALSE; - inangle = FALSE; - star = FALSE; - subptr = NULL; - subptrend = NULL; - - /* Special $ sequences, as supported by Perl, JavaScript, .NET and others. */ - if (next == CHAR_AMPERSAND) - { - ++ptr; - group = 0; - goto GROUP_SUBSTITUTE; - } - if (next == CHAR_GRAVE_ACCENT || next == CHAR_APOSTROPHE) - { - ++ptr; - rc = pcre2_substring_length_bynumber(match_data, 0, &sublength); - if (rc < 0) goto PTREXIT; /* (Sanity-check ovector before reading from it.) */ - - if (next == CHAR_GRAVE_ACCENT) - { - subptr = subject; - subptrend = subject + ovector[0]; - } - else - { - subptr = subject + ovector[1]; - subptrend = subject + length; - } - - goto SUBPTR_SUBSTITUTE; - } - if (next == CHAR_UNDERSCORE) - { - /* Java, .NET support $_ for "entire input string". */ - ++ptr; - subptr = subject; - subptrend = subject + length; - goto SUBPTR_SUBSTITUTE; - } - else if (next == CHAR_PLUS && - !(ptr+1 < repend && ptr[1] == CHAR_LEFT_CURLY_BRACKET)) - { - /* Perl supports $+ for "highest captured group" (not the same as $^N - which is mainly only useful inside Perl's match callbacks). We also - don't accept "$+{..." since that's Perl syntax for our ${name}. */ - ++ptr; - if (code->top_bracket == 0) - { - /* Treat either as "no such group" or "all groups unset" based on the - PCRE2_SUBSTITUTE_UNKNOWN_UNSET option. */ - if ((suboptions & PCRE2_SUBSTITUTE_UNKNOWN_UNSET) == 0) - { - rc = PCRE2_ERROR_NOSUBSTRING; - goto PTREXIT; - } - group = 0; - } - else - { - /* If we have any capture groups, then the ovector needs to be large - enough for all of them, or the result won't be accurate. */ - if (match_data->oveccount < code->top_bracket + 1) - { - rc = PCRE2_ERROR_UNAVAILABLE; - goto PTREXIT; - } - for (group = code->top_bracket; group > 0; group--) - if (ovector[2*group] != PCRE2_UNSET) break; - } - if (group == 0) - { - if ((suboptions & PCRE2_SUBSTITUTE_UNSET_EMPTY) != 0) continue; - rc = PCRE2_ERROR_UNSET; - goto PTREXIT; - } - goto GROUP_SUBSTITUTE; - } - - if (next == CHAR_LEFT_CURLY_BRACKET) - { - if (++ptr >= repend) goto BAD; - next = *ptr; - inparens = TRUE; - } - else if (next == CHAR_LESS_THAN_SIGN) - { - /* JavaScript compatibility syntax, $. Processes only named - groups (not numbered) and does not support extensions such as star - (you can do ${name} and ${*name}, but not $<*name>). */ - if (++ptr >= repend) goto BAD; - next = *ptr; - inangle = TRUE; - } - - if (!inangle && next == CHAR_ASTERISK) - { - if (++ptr >= repend) goto BAD; - next = *ptr; - star = TRUE; - } - - if (!star && !inangle && next >= CHAR_0 && next <= CHAR_9) - { - group = next - CHAR_0; - while (++ptr < repend) - { - next = *ptr; - if (next < CHAR_0 || next > CHAR_9) break; - group = group * 10 + (next - CHAR_0); - - /* A check for a number greater than the hightest captured group - is sufficient here; no need for a separate overflow check. If unknown - groups are to be treated as unset, just skip over any remaining - digits and carry on. */ - - if (group > code->top_bracket) - { - if ((suboptions & PCRE2_SUBSTITUTE_UNKNOWN_UNSET) != 0) - { - while (++ptr < repend && *ptr >= CHAR_0 && *ptr <= CHAR_9); - break; - } - else - { - rc = PCRE2_ERROR_NOSUBSTRING; - goto PTREXIT; - } - } - } - } - else - { - PCRE2_SIZE name_len; - PCRE2_SPTR name_start = ptr; - if (!read_name_subst(&ptr, repend, utf, code->tables + ctypes_offset)) - goto BAD; - name_len = ptr - name_start; - memcpy(name, name_start, CU2BYTES(name_len)); - name[name_len] = 0; - } - - next = 0; /* not used or updated after this point */ - (void)next; - - /* In extended mode we recognize ${name:+set text:unset text} and - ${name:-default text}. */ - - if (inparens) - { - if ((suboptions & PCRE2_SUBSTITUTE_EXTENDED) != 0 && - !star && ptr < repend - 2 && *ptr == CHAR_COLON) - { - special = *(++ptr); - if (special != CHAR_PLUS && special != CHAR_MINUS) - { - rc = PCRE2_ERROR_BADSUBSTITUTION; - goto PTREXIT; - } - - text1_start = ++ptr; - rc = find_text_end(code, &ptr, repend, special == CHAR_MINUS); - if (rc != 0) goto PTREXIT; - text1_end = ptr; - - if (special == CHAR_PLUS && *ptr == CHAR_COLON) - { - text2_start = ++ptr; - rc = find_text_end(code, &ptr, repend, TRUE); - if (rc != 0) goto PTREXIT; - text2_end = ptr; - } - } - - else - { - if (ptr >= repend || *ptr != CHAR_RIGHT_CURLY_BRACKET) - { - rc = PCRE2_ERROR_REPMISSINGBRACE; - goto PTREXIT; - } - } - - ptr++; - } - - if (inangle) - { - if (ptr >= repend || *ptr != CHAR_GREATER_THAN_SIGN) - goto BAD; - ptr++; - } - - /* Have found a syntactically correct group number or name, or *name. - Only *MARK is currently recognized. */ - - if (star) - { - if (PRIV(strcmp_c8)(name, STRING_MARK) == 0) - { - PCRE2_SPTR mark = pcre2_get_mark(match_data); - if (mark != NULL) - { - /* Peek backwards one code unit to obtain the length of the mark. - It can (theoretically) contain an embedded NUL. */ - fraglength = mark[-1]; - if (forcecase.to_case != PCRE2_SUBSTITUTE_CASE_NONE && - substitute_case_callout == NULL) - CHECKCASECPY_DEFAULT(mark, fraglength); - else - CHECKMEMCPY(mark, fraglength); - } - } - else goto BAD; - } - - /* Substitute the contents of a group. We don't use substring_copy - functions any more, in order to support case forcing. */ - - else - { - GROUP_SUBSTITUTE: - /* Find a number for a named group. In case there are duplicate names, - search for the first one that is set. If the name is not found when - PCRE2_SUBSTITUTE_UNKNOWN_EMPTY is set, set the group number to a - non-existent group. */ - - if (group < 0) - { - PCRE2_SPTR first, last, entry; - rc = pcre2_substring_nametable_scan(code, name, &first, &last); - if (rc == PCRE2_ERROR_NOSUBSTRING && - (suboptions & PCRE2_SUBSTITUTE_UNKNOWN_UNSET) != 0) - { - group = code->top_bracket + 1; - } - else - { - if (rc < 0) goto PTREXIT; - for (entry = first; entry <= last; entry += rc) - { - uint32_t ng = GET2(entry, 0); - if (ng < ovector_count) - { - if (group < 0) group = ng; /* First in ovector */ - if (ovector[ng*2] != PCRE2_UNSET) - { - group = ng; /* First that is set */ - break; - } - } - } - - /* If group is still negative, it means we did not find a group - that is in the ovector. Just set the first group. */ - - if (group < 0) group = GET2(first, 0); - } - } - - /* We now have a group that is identified by number. Find the length of - the captured string. If a group in a non-special substitution is unset - when PCRE2_SUBSTITUTE_UNSET_EMPTY is set, substitute nothing. */ - - rc = pcre2_substring_length_bynumber(match_data, group, &sublength); - if (rc < 0) - { - if (rc == PCRE2_ERROR_NOSUBSTRING && - (suboptions & PCRE2_SUBSTITUTE_UNKNOWN_UNSET) != 0) - { - rc = PCRE2_ERROR_UNSET; - } - if (rc != PCRE2_ERROR_UNSET) goto PTREXIT; /* Non-unset errors */ - if (special == 0) /* Plain substitution */ - { - if ((suboptions & PCRE2_SUBSTITUTE_UNSET_EMPTY) != 0) continue; - goto PTREXIT; /* Else error */ - } - } - - /* If special is '+' we have a 'set' and possibly an 'unset' text, - both of which are reprocessed when used. If special is '-' we have a - default text for when the group is unset; it must be reprocessed. */ - - if (special != 0) - { - if (special == CHAR_MINUS) - { - if (rc == 0) goto LITERAL_SUBSTITUTE; - text2_start = text1_start; - text2_end = text1_end; - } - - if (ptrstackptr >= PTR_STACK_SIZE) goto BAD; - ptrstack[ptrstackptr++] = ptr; - ptrstack[ptrstackptr++] = repend; - - if (rc == 0) - { - ptr = text1_start; - repend = text1_end; - } - else - { - ptr = text2_start; - repend = text2_end; - } - continue; - } - - /* Otherwise we have a literal substitution of a group's contents. */ - - LITERAL_SUBSTITUTE: - subptr = subject + ovector[group*2]; - subptrend = subject + ovector[group*2 + 1]; - - /* Substitute a literal string, possibly forcing alphabetic case. */ - - SUBPTR_SUBSTITUTE: - if (forcecase.to_case != PCRE2_SUBSTITUTE_CASE_NONE && - substitute_case_callout == NULL) - CHECKCASECPY_DEFAULT(subptr, subptrend - subptr); - else - CHECKMEMCPY(subptr, subptrend - subptr); - } - } /* End of $ processing */ - - /* Handle an escape sequence in extended mode. We can use check_escape() - to process \Q, \E, \c, \o, \x and \ followed by non-alphanumerics, but - the case-forcing escapes are not supported in pcre2_compile() so must be - recognized here. */ - - else if ((suboptions & PCRE2_SUBSTITUTE_EXTENDED) != 0 && - *ptr == CHAR_BACKSLASH) - { - int errorcode; - case_state new_forcecase = { PCRE2_SUBSTITUTE_CASE_NONE, FALSE }; - - if (ptr < repend - 1) switch (ptr[1]) - { - case CHAR_L: - new_forcecase.to_case = PCRE2_SUBSTITUTE_CASE_LOWER; - new_forcecase.single_char = FALSE; - ptr += 2; - break; - - case CHAR_l: - new_forcecase.to_case = PCRE2_SUBSTITUTE_CASE_LOWER; - new_forcecase.single_char = TRUE; - ptr += 2; - if (ptr + 2 < repend && ptr[0] == CHAR_BACKSLASH && ptr[1] == CHAR_U) - { - /* Perl reverse-title-casing feature for \l\U */ - new_forcecase.to_case = PCRE2_SUBSTITUTE_CASE_REVERSE_TITLE_FIRST; - new_forcecase.single_char = FALSE; - ptr += 2; - } - break; - - case CHAR_U: - new_forcecase.to_case = PCRE2_SUBSTITUTE_CASE_UPPER; - new_forcecase.single_char = FALSE; - ptr += 2; - break; - - case CHAR_u: - new_forcecase.to_case = PCRE2_SUBSTITUTE_CASE_TITLE_FIRST; - new_forcecase.single_char = TRUE; - ptr += 2; - if (ptr + 2 < repend && ptr[0] == CHAR_BACKSLASH && ptr[1] == CHAR_L) - { - /* Perl title-casing feature for \u\L */ - new_forcecase.to_case = PCRE2_SUBSTITUTE_CASE_TITLE_FIRST; - new_forcecase.single_char = FALSE; - ptr += 2; - } - break; - - default: - break; - } - - if (new_forcecase.to_case != PCRE2_SUBSTITUTE_CASE_NONE) - { - SETFORCECASE: - - /* If the substitute_case_callout is unset, our case-forcing is done - immediately. If there is a callout however, then its action is delayed - until all the characters have been collected. - - Apply the callout now, before we set the new casing mode. */ - - if (substitute_case_callout != NULL && - forcecase.to_case != PCRE2_SUBSTITUTE_CASE_NONE) - DELAYEDFORCECASE(); - - forcecase = new_forcecase; - casestart_offset = buff_offset; - casestart_extra_needed = extra_needed; - continue; - } - - ptr++; /* Point after \ */ - rc = PRIV(check_escape)(&ptr, repend, &ch, &errorcode, - code->overall_options, code->extra_options, code->top_bracket, FALSE, NULL); - if (errorcode != 0) goto BADESCAPE; - - switch(rc) - { - case ESC_E: - goto SETFORCECASE; - - case ESC_Q: - escaped_literal = TRUE; - continue; - - case 0: /* Data character */ - case ESC_b: /* \b is backspace in a substitution */ - case ESC_v: /* \v is vertical tab in a substitution */ - - if (rc == ESC_b) ch = CHAR_BS; - if (rc == ESC_v) ch = CHAR_VT; - -#ifdef SUPPORT_UNICODE - if (utf) chlen = PRIV(ord2utf)(ch, temp); else -#endif - { - temp[0] = ch; - chlen = 1; - } - - if (forcecase.to_case != PCRE2_SUBSTITUTE_CASE_NONE && - substitute_case_callout == NULL) - CHECKCASECPY_DEFAULT(temp, chlen); - else - CHECKMEMCPY(temp, chlen); - continue; - - case ESC_g: - { - PCRE2_SIZE name_len; - PCRE2_SPTR name_start; - - /* Parse the \g form (\g already handled by check_escape) */ - if (ptr >= repend || *ptr != CHAR_LESS_THAN_SIGN) - goto BADESCAPE; - ++ptr; - - name_start = ptr; - if (!read_name_subst(&ptr, repend, utf, code->tables + ctypes_offset)) - goto BADESCAPE; - name_len = ptr - name_start; - - if (ptr >= repend || *ptr != CHAR_GREATER_THAN_SIGN) - goto BADESCAPE; - ++ptr; - - special = 0; - group = -1; - memcpy(name, name_start, CU2BYTES(name_len)); - name[name_len] = 0; - goto GROUP_SUBSTITUTE; - } - - default: - if (rc < 0) - { - special = 0; - group = -rc - 1; - goto GROUP_SUBSTITUTE; - } - goto BADESCAPE; - } - } /* End of backslash processing */ - - /* Handle a literal code unit */ - - else - { - PCRE2_SPTR ch_start; - - LOADLITERAL: - ch_start = ptr; - GETCHARINCTEST(ch, ptr); /* Get character value, increment pointer */ - (void) ch; - - if (forcecase.to_case != PCRE2_SUBSTITUTE_CASE_NONE && - substitute_case_callout == NULL) - CHECKCASECPY_DEFAULT(ch_start, ptr - ch_start); - else - CHECKMEMCPY(ch_start, ptr - ch_start); - } /* End handling a literal code unit */ - } /* End of loop for scanning the replacement. */ - - /* If the substitute_case_callout is unset, our case-forcing is done - immediately. If there is a callout however, then its action is delayed - until all the characters have been collected. - - We now clean up any trailing section of the replacement for which we deferred - the case-forcing. */ - - if (substitute_case_callout != NULL && - forcecase.to_case != PCRE2_SUBSTITUTE_CASE_NONE) - DELAYEDFORCECASE(); - - /* The replacement has been copied to the output, or its size has been - remembered. Handle the callout if there is one. */ - - if (mcontext != NULL && mcontext->substitute_callout != NULL) - { - /* If we an actual (non-simulated) replacement, do the callout. */ - - if (!overflowed) - { - scb.subscount = subs; - scb.output_offsets[1] = buff_offset; - rc = mcontext->substitute_callout(&scb, - mcontext->substitute_callout_data); - - /* A non-zero return means cancel this substitution. Instead, copy the - matched string fragment. */ - - if (rc != 0) - { - PCRE2_SIZE newlength = scb.output_offsets[1] - scb.output_offsets[0]; - PCRE2_SIZE oldlength = ovector[1] - ovector[0]; - - buff_offset -= newlength; - lengthleft += newlength; - if (!replacement_only) CHECKMEMCPY(subject + ovector[0], oldlength); - - /* A negative return means do not do any more. */ - - if (rc < 0) suboptions &= (~PCRE2_SUBSTITUTE_GLOBAL); - } - } - - /* In this interesting case, we cannot do the callout, so it's hard to - estimate the required buffer size. What callers want is to be able to make - two calls to pcre2_substitute(), once with PCRE2_SUBSTITUTE_OVERFLOW_LENGTH - to discover the buffer size, and then a second and final call. Older - versions of PCRE2 violated this assumption, by proceding as if the callout - had returned zero - but on the second call to pcre2_substitute() it could - return non-zero and then overflow the buffer again. Callers probably don't - want to keep on looping to incrementally discover the buffer size. */ - - else - { - PCRE2_SIZE newlength_buf = buff_offset - scb.output_offsets[0]; - PCRE2_SIZE newlength_extra = extra_needed - sub_start_extra_needed; - PCRE2_SIZE newlength = - (newlength_extra > ~(PCRE2_SIZE)0 - newlength_buf)? /* Integer overflow */ - ~(PCRE2_SIZE)0 : newlength_buf + newlength_extra; /* Cap the addition */ - PCRE2_SIZE oldlength = ovector[1] - ovector[0]; - - /* Be pessimistic: request whichever buffer size is larger out of - accepting or rejecting the substitution. */ - - if (oldlength > newlength) - { - PCRE2_SIZE additional = oldlength - newlength; - if (additional > ~(PCRE2_SIZE)0 - extra_needed) /* Integer overflow */ - goto TOOLARGEREPLACE; - extra_needed += additional; - } - - /* Proceed as if the callout did not return a negative. A negative - effectively rejects all future substitutions, but we want to examine them - pessimistically. */ - } - } - - /* Exit the global loop if we are not in global mode, or if pcre2_next_match() - indicates we have reached the end of the subject. */ - - if ((suboptions & PCRE2_SUBSTITUTE_GLOBAL) == 0 || - !pcre2_next_match(match_data, &start_offset, &goptions)) - { - start_offset = ovector[1]; - break; - } - - /* Verify that pcre2_next_match() has not done a bumpalong (because we have - already returned PCRE2_ERROR_BADSUBSPATTERN for \K in lookarounds). - - We would otherwise have to memcpy the fragment spanning from ovector[1] to the - new start_offset.*/ - - PCRE2_ASSERT(start_offset == ovector[1]); - - } /* End of global loop */ - -/* Copy the rest of the subject unless not required, and terminate the output -with a binary zero. */ - -if (!replacement_only) - { - fraglength = length - start_offset; - CHECKMEMCPY(subject + start_offset, fraglength); - } - -temp[0] = 0; -CHECKMEMCPY(temp, 1); - -/* If overflowed is set it means the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH is set, -and matching has carried on after a full buffer, in order to compute the length -needed. Otherwise, an overflow generates an immediate error return. */ - -if (overflowed) - { - rc = PCRE2_ERROR_NOMEMORY; - - if (extra_needed > ~(PCRE2_SIZE)0 - buff_length) /* Integer overflow */ - goto TOOLARGEREPLACE; - *blength = buff_length + extra_needed; - } - -/* After a successful execution, return the number of substitutions and set the -length of buffer used, excluding the trailing zero. */ - -else - { - rc = subs; - *blength = buff_offset - 1; - } - -EXIT: -if (internal_match_data != NULL) pcre2_match_data_free(internal_match_data); - else match_data->rc = rc; -return rc; - -NOROOM: -rc = PCRE2_ERROR_NOMEMORY; -goto EXIT; - -CASEERROR: -rc = PCRE2_ERROR_REPLACECASE; -goto EXIT; - -TOOLARGEREPLACE: -rc = PCRE2_ERROR_TOOLARGEREPLACE; -goto EXIT; - -BAD: -rc = PCRE2_ERROR_BADREPLACEMENT; -goto PTREXIT; - -BADESCAPE: -rc = PCRE2_ERROR_BADREPESCAPE; - -PTREXIT: -*blength = (PCRE2_SIZE)(ptr - replacement); -goto EXIT; -} - -/* End of pcre2_substitute.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_substring.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_substring.c deleted file mode 100644 index f68b464..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_substring.c +++ /dev/null @@ -1,553 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Copy named captured string to given buffer * -*************************************************/ - -/* This function copies a single captured substring into a given buffer, -identifying it by name. If the regex permits duplicate names, the first -substring that is set is chosen. - -Arguments: - match_data points to the match data - stringname the name of the required substring - buffer where to put the substring - sizeptr the size of the buffer, updated to the size of the substring - -Returns: if successful: zero - if not successful, a negative error code: - (1) an error from nametable_scan() - (2) an error from copy_bynumber() - (3) PCRE2_ERROR_UNAVAILABLE: no group is in ovector - (4) PCRE2_ERROR_UNSET: all named groups in ovector are unset -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_copy_byname(pcre2_match_data *match_data, PCRE2_SPTR stringname, - PCRE2_UCHAR *buffer, PCRE2_SIZE *sizeptr) -{ -PCRE2_SPTR first, last, entry; -int failrc, entrysize; -if (match_data->matchedby == PCRE2_MATCHEDBY_DFA_INTERPRETER) - return PCRE2_ERROR_DFA_UFUNC; -entrysize = pcre2_substring_nametable_scan(match_data->code, stringname, - &first, &last); -if (entrysize < 0) return entrysize; -failrc = PCRE2_ERROR_UNAVAILABLE; -for (entry = first; entry <= last; entry += entrysize) - { - uint32_t n = GET2(entry, 0); - if (n < match_data->oveccount) - { - if (match_data->ovector[n*2] != PCRE2_UNSET) - return pcre2_substring_copy_bynumber(match_data, n, buffer, sizeptr); - failrc = PCRE2_ERROR_UNSET; - } - } -return failrc; -} - - - -/************************************************* -* Copy numbered captured string to given buffer * -*************************************************/ - -/* This function copies a single captured substring into a given buffer, -identifying it by number. - -Arguments: - match_data points to the match data - stringnumber the number of the required substring - buffer where to put the substring - sizeptr the size of the buffer, updated to the size of the substring - -Returns: if successful: 0 - if not successful, a negative error code: - PCRE2_ERROR_NOMEMORY: buffer too small - PCRE2_ERROR_NOSUBSTRING: no such substring - PCRE2_ERROR_UNAVAILABLE: ovector too small - PCRE2_ERROR_UNSET: substring is not set -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_copy_bynumber(pcre2_match_data *match_data, - uint32_t stringnumber, PCRE2_UCHAR *buffer, PCRE2_SIZE *sizeptr) -{ -int rc; -PCRE2_SIZE size; -rc = pcre2_substring_length_bynumber(match_data, stringnumber, &size); -if (rc < 0) return rc; -if (size + 1 > *sizeptr) return PCRE2_ERROR_NOMEMORY; -if (size != 0) memcpy(buffer, match_data->subject + match_data->ovector[stringnumber*2], - CU2BYTES(size)); -buffer[size] = 0; -*sizeptr = size; -return 0; -} - - - -/************************************************* -* Extract named captured string * -*************************************************/ - -/* This function copies a single captured substring, identified by name, into -new memory. If the regex permits duplicate names, the first substring that is -set is chosen. - -Arguments: - match_data pointer to match_data - stringname the name of the required substring - stringptr where to put the pointer to the new memory - sizeptr where to put the length of the substring - -Returns: if successful: zero - if not successful, a negative value: - (1) an error from nametable_scan() - (2) an error from get_bynumber() - (3) PCRE2_ERROR_UNAVAILABLE: no group is in ovector - (4) PCRE2_ERROR_UNSET: all named groups in ovector are unset -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_get_byname(pcre2_match_data *match_data, - PCRE2_SPTR stringname, PCRE2_UCHAR **stringptr, PCRE2_SIZE *sizeptr) -{ -PCRE2_SPTR first, last, entry; -int failrc, entrysize; -if (match_data->matchedby == PCRE2_MATCHEDBY_DFA_INTERPRETER) - return PCRE2_ERROR_DFA_UFUNC; -entrysize = pcre2_substring_nametable_scan(match_data->code, stringname, - &first, &last); -if (entrysize < 0) return entrysize; -failrc = PCRE2_ERROR_UNAVAILABLE; -for (entry = first; entry <= last; entry += entrysize) - { - uint32_t n = GET2(entry, 0); - if (n < match_data->oveccount) - { - if (match_data->ovector[n*2] != PCRE2_UNSET) - return pcre2_substring_get_bynumber(match_data, n, stringptr, sizeptr); - failrc = PCRE2_ERROR_UNSET; - } - } -return failrc; -} - - - -/************************************************* -* Extract captured string to new memory * -*************************************************/ - -/* This function copies a single captured substring into a piece of new -memory. - -Arguments: - match_data points to match data - stringnumber the number of the required substring - stringptr where to put a pointer to the new memory - sizeptr where to put the size of the substring - -Returns: if successful: 0 - if not successful, a negative error code: - PCRE2_ERROR_NOMEMORY: failed to get memory - PCRE2_ERROR_NOSUBSTRING: no such substring - PCRE2_ERROR_UNAVAILABLE: ovector too small - PCRE2_ERROR_UNSET: substring is not set -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_get_bynumber(pcre2_match_data *match_data, - uint32_t stringnumber, PCRE2_UCHAR **stringptr, PCRE2_SIZE *sizeptr) -{ -int rc; -PCRE2_SIZE size; -PCRE2_UCHAR *yield; -rc = pcre2_substring_length_bynumber(match_data, stringnumber, &size); -if (rc < 0) return rc; -yield = PRIV(memctl_malloc)(sizeof(pcre2_memctl) + - (size + 1)*PCRE2_CODE_UNIT_WIDTH, (pcre2_memctl *)match_data); -if (yield == NULL) return PCRE2_ERROR_NOMEMORY; -yield = (PCRE2_UCHAR *)(((char *)yield) + sizeof(pcre2_memctl)); -if (size != 0) memcpy(yield, match_data->subject + match_data->ovector[stringnumber*2], - CU2BYTES(size)); -yield[size] = 0; -*stringptr = yield; -*sizeptr = size; -return 0; -} - - - -/************************************************* -* Free memory obtained by get_substring * -*************************************************/ - -/* -Argument: the result of a previous pcre2_substring_get_byxxx() -Returns: nothing -*/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_substring_free(PCRE2_UCHAR *string) -{ -if (string != NULL) - { - pcre2_memctl *memctl = (pcre2_memctl *)((char *)string - sizeof(pcre2_memctl)); - memctl->free(memctl, memctl->memory_data); - } -} - - - -/************************************************* -* Get length of a named substring * -*************************************************/ - -/* This function returns the length of a named captured substring. If the regex -permits duplicate names, the first substring that is set is chosen. - -Arguments: - match_data pointer to match data - stringname the name of the required substring - sizeptr where to put the length, if not NULL - -Returns: 0 if successful, else a negative error number -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_length_byname(pcre2_match_data *match_data, - PCRE2_SPTR stringname, PCRE2_SIZE *sizeptr) -{ -PCRE2_SPTR first, last, entry; -int failrc, entrysize; -if (match_data->matchedby == PCRE2_MATCHEDBY_DFA_INTERPRETER) - return PCRE2_ERROR_DFA_UFUNC; -entrysize = pcre2_substring_nametable_scan(match_data->code, stringname, - &first, &last); -if (entrysize < 0) return entrysize; -failrc = PCRE2_ERROR_UNAVAILABLE; -for (entry = first; entry <= last; entry += entrysize) - { - uint32_t n = GET2(entry, 0); - if (n < match_data->oveccount) - { - if (match_data->ovector[n*2] != PCRE2_UNSET) - return pcre2_substring_length_bynumber(match_data, n, sizeptr); - failrc = PCRE2_ERROR_UNSET; - } - } -return failrc; -} - - - -/************************************************* -* Get length of a numbered substring * -*************************************************/ - -/* This function returns the length of a captured substring. If the start is -beyond the end (which can happen when \K is used in an assertion), it sets the -length to zero. - -Arguments: - match_data pointer to match data - stringnumber the number of the required substring - sizeptr where to put the length, if not NULL - -Returns: if successful: 0 - if not successful, a negative error code: - PCRE2_ERROR_NOSUBSTRING: no such substring - PCRE2_ERROR_UNAVAILABLE: ovector is too small - PCRE2_ERROR_UNSET: substring is not set - PCRE2_ERROR_INVALIDOFFSET: internal error, should not occur -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_length_bynumber(pcre2_match_data *match_data, - uint32_t stringnumber, PCRE2_SIZE *sizeptr) -{ -PCRE2_SIZE left, right; -int count = match_data->rc; -if (count == PCRE2_ERROR_PARTIAL) - { - if (stringnumber > 0) return PCRE2_ERROR_PARTIAL; - count = 0; - } -else if (count < 0) return count; /* Match failed */ - -if (match_data->matchedby != PCRE2_MATCHEDBY_DFA_INTERPRETER) - { - if (stringnumber > match_data->code->top_bracket) - return PCRE2_ERROR_NOSUBSTRING; - if (stringnumber >= match_data->oveccount) - return PCRE2_ERROR_UNAVAILABLE; - if (match_data->ovector[stringnumber*2] == PCRE2_UNSET) - return PCRE2_ERROR_UNSET; - } -else /* Matched using pcre2_dfa_match() */ - { - if (stringnumber >= match_data->oveccount) return PCRE2_ERROR_UNAVAILABLE; - if (count != 0 && stringnumber >= (uint32_t)count) return PCRE2_ERROR_UNSET; - } - -left = match_data->ovector[stringnumber*2]; -right = match_data->ovector[stringnumber*2+1]; -/* LCOV_EXCL_START - this appears to be unreachable, as the ovector and -subject_length should always be set consistently, no matter what misbehaviour -the caller has committed. */ -if (left > match_data->subject_length || right > match_data->subject_length) - { - PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INVALIDOFFSET; - } -/* LCOV_EXCL_STOP */ -if (sizeptr != NULL) *sizeptr = (left > right)? 0 : right - left; -return 0; -} - - - -/************************************************* -* Extract all captured strings to new memory * -*************************************************/ - -/* This function gets one chunk of memory and builds a list of pointers and all -the captured substrings in it. A NULL pointer is put on the end of the list. -The substrings are zero-terminated, but also, if the final argument is -non-NULL, a list of lengths is also returned. This allows binary data to be -handled. - -Arguments: - match_data points to the match data - listptr set to point to the list of pointers - lengthsptr set to point to the list of lengths (may be NULL) - -Returns: if successful: 0 - if not successful, a negative error code: - PCRE2_ERROR_NOMEMORY: failed to get memory, - or a match failure code -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_list_get(pcre2_match_data *match_data, PCRE2_UCHAR ***listptr, - PCRE2_SIZE **lengthsptr) -{ -int i, count, count2; -PCRE2_SIZE size; -PCRE2_SIZE *lensp; -pcre2_memctl *memp; -PCRE2_UCHAR **listp; -PCRE2_UCHAR *sp; -PCRE2_SIZE *ovector; - -if ((count = match_data->rc) < 0) return count; /* Match failed */ -if (count == 0) count = match_data->oveccount; /* Ovector too small */ - -count2 = 2*count; -ovector = match_data->ovector; -size = sizeof(pcre2_memctl) + sizeof(PCRE2_UCHAR *); /* For final NULL */ -if (lengthsptr != NULL) size += sizeof(PCRE2_SIZE) * count; /* For lengths */ - -for (i = 0; i < count2; i += 2) - { - size += sizeof(PCRE2_UCHAR *) + CU2BYTES(1); - if (ovector[i+1] > ovector[i]) size += CU2BYTES(ovector[i+1] - ovector[i]); - } - -memp = PRIV(memctl_malloc)(size, (pcre2_memctl *)match_data); -if (memp == NULL) return PCRE2_ERROR_NOMEMORY; - -*listptr = listp = (PCRE2_UCHAR **)((char *)memp + sizeof(pcre2_memctl)); -lensp = (PCRE2_SIZE *)((char *)listp + sizeof(PCRE2_UCHAR *) * (count + 1)); - -if (lengthsptr == NULL) - { - sp = (PCRE2_UCHAR *)lensp; - lensp = NULL; - } -else - { - *lengthsptr = lensp; - sp = (PCRE2_UCHAR *)((char *)lensp + sizeof(PCRE2_SIZE) * count); - } - -for (i = 0; i < count2; i += 2) - { - size = (ovector[i+1] > ovector[i])? (ovector[i+1] - ovector[i]) : 0; - - /* Size == 0 includes the case when the capture is unset. Avoid adding - PCRE2_UNSET to match_data->subject because it overflows, even though with - zero size calling memcpy() is harmless. */ - - if (size != 0) memcpy(sp, match_data->subject + ovector[i], CU2BYTES(size)); - *listp++ = sp; - if (lensp != NULL) *lensp++ = size; - sp += size; - *sp++ = 0; - } - -*listp = NULL; -return 0; -} - - - -/************************************************* -* Free memory obtained by substring_list_get * -*************************************************/ - -/* -Argument: the result of a previous pcre2_substring_list_get() -Returns: nothing -*/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_substring_list_free(PCRE2_UCHAR **list) -{ -if (list != NULL) - { - pcre2_memctl *memctl = (pcre2_memctl *)((char *)list - sizeof(pcre2_memctl)); - memctl->free(memctl, memctl->memory_data); - } -} - - - -/************************************************* -* Find (multiple) entries for named string * -*************************************************/ - -/* This function scans the nametable for a given name, using binary chop. It -returns either two pointers to the entries in the table, or, if no pointers are -given, the number of a unique group with the given name. If duplicate names are -permitted, and the name is not unique, an error is generated. - -Arguments: - code the compiled regex - stringname the name whose entries required - firstptr where to put the pointer to the first entry - lastptr where to put the pointer to the last entry - -Returns: PCRE2_ERROR_NOSUBSTRING if the name is not found - otherwise, if firstptr and lastptr are NULL: - a group number for a unique substring - else PCRE2_ERROR_NOUNIQUESUBSTRING - otherwise: - the length of each entry, having set firstptr and lastptr -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_nametable_scan(const pcre2_code *code, PCRE2_SPTR stringname, - PCRE2_SPTR *firstptr, PCRE2_SPTR *lastptr) -{ -uint16_t bot = 0; -uint16_t top = code->name_count; -uint16_t entrysize = code->name_entry_size; -PCRE2_SPTR nametable = (PCRE2_SPTR)((const char *)code + sizeof(pcre2_real_code)); - -while (top > bot) - { - uint16_t mid = (top + bot) / 2; - PCRE2_SPTR entry = nametable + entrysize*mid; - int c = PRIV(strcmp)(stringname, entry + IMM2_SIZE); - if (c == 0) - { - PCRE2_SPTR first; - PCRE2_SPTR last; - PCRE2_SPTR lastentry; - lastentry = nametable + entrysize * (code->name_count - 1); - first = last = entry; - while (first > nametable) - { - if (PRIV(strcmp)(stringname, (first - entrysize + IMM2_SIZE)) != 0) break; - first -= entrysize; - } - while (last < lastentry) - { - if (PRIV(strcmp)(stringname, (last + entrysize + IMM2_SIZE)) != 0) break; - last += entrysize; - } - if (firstptr == NULL) return (first == last)? - (int)GET2(entry, 0) : PCRE2_ERROR_NOUNIQUESUBSTRING; - *firstptr = first; - *lastptr = last; - return entrysize; - } - if (c > 0) bot = mid + 1; else top = mid; - } - -return PCRE2_ERROR_NOSUBSTRING; -} - - -/************************************************* -* Find number for named string * -*************************************************/ - -/* This function is a convenience wrapper for pcre2_substring_nametable_scan() -when it is known that names are unique. If there are duplicate names, it is not -defined which number is returned. - -Arguments: - code the compiled regex - stringname the name whose number is required - -Returns: the number of the named parenthesis, or a negative number - PCRE2_ERROR_NOSUBSTRING if not found - PCRE2_ERROR_NOUNIQUESUBSTRING if not unique -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_number_from_name(const pcre2_code *code, - PCRE2_SPTR stringname) -{ -return pcre2_substring_nametable_scan(code, stringname, NULL, NULL); -} - -/* End of pcre2_substring.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_tables.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_tables.c deleted file mode 100644 index 0b9b43b..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_tables.c +++ /dev/null @@ -1,310 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains some fixed tables that are used by more than one of the -PCRE2 code modules. The tables are also #included by the pcre2test program, -which uses macros to change their names from _pcre2_xxx to xxxx, thereby -avoiding name clashes with the library. In this case, PCRE2_PCRE2TEST is -defined. */ - - -#if !defined(PCRE2_PCRE2TEST) && !defined(PCRE2_DFTABLES) && \ - !defined(PCRE2_PCRE2POSIX) /* We're compiling the library */ -#include "pcre2_internal.h" -#endif - - -/* Utility macros */ -#define ARR_SIZE(x) sizeof(x)/sizeof(x[0]) - - -#if !defined(PCRE2_PCRE2TEST) && !defined(PCRE2_DFTABLES) && \ - !defined(PCRE2_PCRE2POSIX) - -/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that -the definition is next to the definition of the opcodes in pcre2_internal.h. -This is mode-dependent, so it is skipped when this file is included by -pcre2test. */ - -const uint8_t PRIV(OP_lengths)[] = { OP_LENGTHS }; - -/* Tables of horizontal and vertical whitespace characters, suitable for -adding to classes. */ - -const uint32_t PRIV(hspace_list)[] = { HSPACE_LIST }; -const uint32_t PRIV(vspace_list)[] = { VSPACE_LIST }; - -#endif /* !PCRE2_PCRE2TEST && !PCRE2_DFTABLES && !PCRE2_PCRE2POSIX */ - - -#if !defined(PCRE2_DFTABLES) && !defined(PCRE2_PCRE2POSIX) - -/* These tables are the pairs of delimiters that are valid for callout string -arguments. For each starting delimiter there must be a matching ending -delimiter, which in fact is different only for bracket-like delimiters. */ - -const uint32_t PRIV(callout_start_delims)[] = { - CHAR_GRAVE_ACCENT, CHAR_APOSTROPHE, CHAR_QUOTATION_MARK, - CHAR_CIRCUMFLEX_ACCENT, CHAR_PERCENT_SIGN, CHAR_NUMBER_SIGN, - CHAR_DOLLAR_SIGN, CHAR_LEFT_CURLY_BRACKET, 0 }; - -const uint32_t PRIV(callout_end_delims[]) = { - CHAR_GRAVE_ACCENT, CHAR_APOSTROPHE, CHAR_QUOTATION_MARK, - CHAR_CIRCUMFLEX_ACCENT, CHAR_PERCENT_SIGN, CHAR_NUMBER_SIGN, - CHAR_DOLLAR_SIGN, CHAR_RIGHT_CURLY_BRACKET, 0 }; - -#endif /* !PCRE2_DFTABLES && !PCRE2_PCRE2POSIX */ - - -/************************************************* -* Tables for UTF-8 support * -*************************************************/ - -/* These tables are required by pcre2test in 16- or 32-bit mode, as well -as for the library in 8-bit mode, because pcre2test uses UTF-8 internally for -handling wide characters. */ - -#if defined PCRE2_PCRE2TEST || \ - (!defined(PCRE2_DFTABLES) && !defined(PCRE2_PCRE2POSIX) && \ - defined SUPPORT_UNICODE && \ - defined PCRE2_CODE_UNIT_WIDTH && \ - PCRE2_CODE_UNIT_WIDTH == 8) - -/* These are the breakpoints for different numbers of bytes in a UTF-8 -character. */ - -const int PRIV(utf8_table1)[] = - { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff }; - -const unsigned PRIV(utf8_table1_size) = ARR_SIZE(PRIV(utf8_table1)); - -/* These are the indicator bits and the mask for the data bits to set in the -first byte of a character, indexed by the number of additional bytes. */ - -const int PRIV(utf8_table2)[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc }; -const int PRIV(utf8_table3)[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01 }; - -/* Table of the number of extra bytes, indexed by the first byte masked with -0x3f. The highest number for a valid UTF-8 first byte is in fact 0x3d. */ - -const uint8_t PRIV(utf8_table4)[] = { - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 }; - -#endif /* UTF-8 support needed */ - -/* Tables concerned with Unicode properties are relevant only when Unicode -support is enabled. See also the pcre2_ucptables_inc.h file, which is generated by -a Python script from Unicode data files. */ - -#if !defined(PCRE2_DFTABLES) && !defined(PCRE2_PCRE2POSIX) && \ - defined(SUPPORT_UNICODE) - -/* Table to translate from particular type value to the general value. */ - -const uint32_t PRIV(ucp_gentype)[] = { - ucp_C, ucp_C, ucp_C, ucp_C, ucp_C, /* Cc, Cf, Cn, Co, Cs */ - ucp_L, ucp_L, ucp_L, ucp_L, ucp_L, /* Ll, Lu, Lm, Lo, Lt */ - ucp_M, ucp_M, ucp_M, /* Mc, Me, Mn */ - ucp_N, ucp_N, ucp_N, /* Nd, Nl, No */ - ucp_P, ucp_P, ucp_P, ucp_P, ucp_P, /* Pc, Pd, Pe, Pf, Pi */ - ucp_P, ucp_P, /* Ps, Po */ - ucp_S, ucp_S, ucp_S, ucp_S, /* Sc, Sk, Sm, So */ - ucp_Z, ucp_Z, ucp_Z /* Zl, Zp, Zs */ -}; - -/* This table encodes the rules for finding the end of an extended grapheme -cluster. Every code point has a grapheme break property which is one of the -ucp_gbXX values defined in pcre2_ucp.h. These changed between Unicode versions -10 and 11. The 2-dimensional table is indexed by the properties of two adjacent -code points. The left property selects a word from the table, and the right -property selects a bit from that word like this: - - PRIV(ucp_gbtable)[left-property] & (1u << right-property) - -The value is non-zero if a grapheme break is NOT permitted between the relevant -two code points. The breaking rules are as follows: - -1. Break at the start and end of text (pretty obviously). - -2. Do not break between a CR and LF; otherwise, break before and after - controls. - -3. Do not break Hangul syllable sequences, the rules for which are: - - L may be followed by L, V, LV or LVT - LV or V may be followed by V or T - LVT or T may be followed by T - -4. Do not break before extending characters or zero-width-joiner (ZWJ). - -The following rules are only for extended grapheme clusters (but that's what we -are implementing). - -5. Do not break before SpacingMarks. - -6. Do not break after Prepend characters. - -7. Do not break within emoji modifier sequences or emoji zwj sequences. That - is, do not break between characters with the Extended_Pictographic property - if a ZWJ intervenes. Extend characters are allowed between the characters; - this cannot be represented in this table, the code has to deal with it. - -8. Do not break within emoji flag sequences. That is, do not break between - regional indicator (RI) symbols if there are an odd number of RI characters - before the break point. This table encodes "join RI characters"; the code - has to deal with checking for previous adjoining RIs. - -9. Otherwise, break everywhere. -*/ - -#define ESZ (1< -#endif - -/* PCRE2_ASSERT(x) can be used to inject an assert() for conditions -that the code below doesn't support. It is a NOP for non debug builds -but in debug builds will print information about the location of the -code where it triggered and crash. - -It is meant to work like assert(), and therefore the expression used -should indicate what the expected state is, and shouldn't have any -side-effects. */ - -#if defined(HAVE_ASSERT_H) && !defined(NDEBUG) -#define PCRE2_ASSERT(x) assert(x) -#else -#define PCRE2_ASSERT(x) do \ -{ \ - if (!(x)) \ - { \ - fprintf(stderr, "Assertion failed at " __FILE__ ":%d\n", __LINE__); \ - abort(); \ - } \ -} while(0) -#endif - -/* LCOV_EXCL_START */ - -/* PCRE2_UNREACHABLE() can be used to mark locations on the code that -shouldn't be reached. In non debug builds is defined as a hint for -the compiler to eliminate any code after it, so it is useful also for -performance reasons, but should be used with care because if it is -ever reached will trigger Undefined Behaviour and if you are lucky a -crash. In debug builds it will report the location where it was triggered -and crash. One important point to consider when using this macro, is -that it is only implemented for a few compilers, and therefore can't -be relied on to always be active either, so if it is followed by some -code it is important to make sure that the whole thing is safe to -use even if the macro is not there (ex: make sure there is a `break` -after it if used at the end of a `case`) and to test your code also -with a configuration where the macro will be a NOP. */ - -#if defined(HAVE_ASSERT_H) && !defined(NDEBUG) -#define PCRE2_UNREACHABLE() \ -assert(((void)"Execution reached unexpected point", 0)) -#else -#define PCRE2_UNREACHABLE() do \ -{ \ -fprintf(stderr, "Execution reached unexpected point at " __FILE__ \ - ":%d\n", __LINE__); \ -abort(); \ -} while(0) -#endif - -/* PCRE2_DEBUG_UNREACHABLE() is a debug only version of the previous -macro. It is meant to be used in places where the code is handling -an error situation in code that shouldn't be reached, but that has -some sort of fallback code to normally handle the error. When in -doubt you should use this instead of the previous macro. Like in -the previous case, it is a good idea to document as much as possible -the reason and the actions that should be taken if it ever triggers. */ - -#define PCRE2_DEBUG_UNREACHABLE() PCRE2_UNREACHABLE() - -/* LCOV_EXCL_STOP */ - -#endif /* PCRE2_DEBUG */ - -#ifndef PCRE2_ASSERT -#define PCRE2_ASSERT(x) do {} while(0) -#endif - -/* LCOV_EXCL_START */ - -#ifndef PCRE2_DEBUG_UNREACHABLE -#define PCRE2_DEBUG_UNREACHABLE() do {} while(0) -#endif - -#ifndef PCRE2_UNREACHABLE -#ifdef HAVE_BUILTIN_UNREACHABLE -#define PCRE2_UNREACHABLE() __builtin_unreachable() -#elif defined(HAVE_BUILTIN_ASSUME) -#define PCRE2_UNREACHABLE() __assume(0) -#else -#define PCRE2_UNREACHABLE() do {} while(0) -#endif -#endif /* !PCRE2_UNREACHABLE */ - -/* LCOV_EXCL_STOP */ - -/* We define this fallthrough macro for suppressing -Wimplicit-fallthrough warnings. -Clang only allows this via an attribute, whereas other compilers (eg. GCC) match attributes -and also specially-formatted comments. - -This macro should be used with no following semicolon, and ideally with a comment: */ - -/* PCRE2_FALLTHROUGH */ /* Fall through */ - -#ifndef PCRE2_FALLTHROUGH - -#if defined(__cplusplus) && __cplusplus >= 202002L && \ - defined(__has_cpp_attribute) -/* Standards-compatible C++ variant. */ -#if __has_cpp_attribute(fallthrough) -#define PCRE2_FALLTHROUGH [[fallthrough]]; -#endif -#elif !defined(__cplusplus) && \ - defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L && \ - defined(__has_c_attribute) -/* Standards-compatible C variant. */ -#if __has_c_attribute(fallthrough) -#define PCRE2_FALLTHROUGH [[fallthrough]]; -#endif -#elif ((defined(__clang__) && __clang_major__ >= 10) || \ - (defined(__GNUC__) && __GNUC__ >= 7)) && \ - defined(__has_attribute) -/* Clang and GCC syntax. Rule out old versions because apparently Clang at - least has a broken implementation of __has_attribute. */ -#if __has_attribute(fallthrough) -#define PCRE2_FALLTHROUGH __attribute__((fallthrough)); -#endif -#endif - -#endif /* !PCRE2_FALLTHROUGH */ - -#ifndef PCRE2_FALLTHROUGH -#define PCRE2_FALLTHROUGH -#endif - -#endif /* PCRE2_UTIL_H_IDEMPOTENT_GUARD */ - -/* End of pcre2_util.h */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_valid_utf.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_valid_utf.c deleted file mode 100644 index 3fac931..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_valid_utf.c +++ /dev/null @@ -1,397 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2020 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains an internal function for validating UTF character -strings. This file is also #included by the pcre2test program, which uses -macros to change names from _pcre2_xxx to xxxx, thereby avoiding name clashes -with the library. In this case, PCRE2_PCRE2TEST is defined. */ - - -#ifndef PCRE2_PCRE2TEST /* We're compiling the library */ -#include "pcre2_internal.h" -#endif /* PCRE2_PCRE2TEST */ - - - -#ifndef SUPPORT_UNICODE -/************************************************* -* Dummy function when Unicode is not supported * -*************************************************/ - -/* This function should never be called when Unicode is not supported. */ - -int -PRIV(valid_utf)(PCRE2_SPTR string, PCRE2_SIZE length, PCRE2_SIZE *erroroffset) -{ -(void)string; -(void)length; -(void)erroroffset; -return 0; -} -#else /* UTF is supported */ - - - -/************************************************* -* Validate a UTF string * -*************************************************/ - -/* This function is called (optionally) at the start of compile or match, to -check that a supposed UTF string is actually valid. The early check means -that subsequent code can assume it is dealing with a valid string. The check -can be turned off for maximum performance, but the consequences of supplying an -invalid string are then undefined. - -Arguments: - string points to the string - length length of string - errp pointer to an error position offset variable - -Returns: == 0 if the string is a valid UTF string - != 0 otherwise, setting the offset of the bad character -*/ - -int -PRIV(valid_utf)(PCRE2_SPTR string, PCRE2_SIZE length, PCRE2_SIZE *erroroffset) -{ -PCRE2_SPTR p; -uint32_t c; - -/* ----------------- Check a UTF-8 string ----------------- */ - -#if PCRE2_CODE_UNIT_WIDTH == 8 - -/* Originally, this function checked according to RFC 2279, allowing for values -in the range 0 to 0x7fffffff, up to 6 bytes long, but ensuring that they were -in the canonical format. Once somebody had pointed out RFC 3629 to me (it -obsoletes 2279), additional restrictions were applied. The values are now -limited to be between 0 and 0x0010ffff, no more than 4 bytes long, and the -subrange 0xd000 to 0xdfff is excluded. However, the format of 5-byte and 6-byte -characters is still checked. Error returns are as follows: - -PCRE2_ERROR_UTF8_ERR1 Missing 1 byte at the end of the string -PCRE2_ERROR_UTF8_ERR2 Missing 2 bytes at the end of the string -PCRE2_ERROR_UTF8_ERR3 Missing 3 bytes at the end of the string -PCRE2_ERROR_UTF8_ERR4 Missing 4 bytes at the end of the string -PCRE2_ERROR_UTF8_ERR5 Missing 5 bytes at the end of the string -PCRE2_ERROR_UTF8_ERR6 2nd-byte's two top bits are not 0x80 -PCRE2_ERROR_UTF8_ERR7 3rd-byte's two top bits are not 0x80 -PCRE2_ERROR_UTF8_ERR8 4th-byte's two top bits are not 0x80 -PCRE2_ERROR_UTF8_ERR9 5th-byte's two top bits are not 0x80 -PCRE2_ERROR_UTF8_ERR10 6th-byte's two top bits are not 0x80 -PCRE2_ERROR_UTF8_ERR11 5-byte character is not permitted by RFC 3629 -PCRE2_ERROR_UTF8_ERR12 6-byte character is not permitted by RFC 3629 -PCRE2_ERROR_UTF8_ERR13 4-byte character with value > 0x10ffff is not permitted -PCRE2_ERROR_UTF8_ERR14 3-byte character with value 0xd800-0xdfff is not permitted -PCRE2_ERROR_UTF8_ERR15 Overlong 2-byte sequence -PCRE2_ERROR_UTF8_ERR16 Overlong 3-byte sequence -PCRE2_ERROR_UTF8_ERR17 Overlong 4-byte sequence -PCRE2_ERROR_UTF8_ERR18 Overlong 5-byte sequence (won't ever occur) -PCRE2_ERROR_UTF8_ERR19 Overlong 6-byte sequence (won't ever occur) -PCRE2_ERROR_UTF8_ERR20 Isolated 0x80 byte (not within UTF-8 character) -PCRE2_ERROR_UTF8_ERR21 Byte with the illegal value 0xfe or 0xff -*/ - -for (p = string; length > 0; p++) - { - uint32_t ab, d; - - c = *p; - length--; - - if (c < 128) continue; /* ASCII character */ - - if (c < 0xc0) /* Isolated 10xx xxxx byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string); - return PCRE2_ERROR_UTF8_ERR20; - } - - if (c >= 0xfe) /* Invalid 0xfe or 0xff bytes */ - { - *erroroffset = (PCRE2_SIZE)(p - string); - return PCRE2_ERROR_UTF8_ERR21; - } - - ab = PRIV(utf8_table4)[c & 0x3f]; /* Number of additional bytes (1-5) */ - if (length < ab) /* Missing bytes */ - { - *erroroffset = (PCRE2_SIZE)(p - string); - switch(ab - length) - { - case 1: return PCRE2_ERROR_UTF8_ERR1; - case 2: return PCRE2_ERROR_UTF8_ERR2; - case 3: return PCRE2_ERROR_UTF8_ERR3; - case 4: return PCRE2_ERROR_UTF8_ERR4; - case 5: return PCRE2_ERROR_UTF8_ERR5; - } - } - length -= ab; /* Length remaining */ - - /* Check top bits in the second byte */ - - if (((d = *(++p)) & 0xc0) != 0x80) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 1; - return PCRE2_ERROR_UTF8_ERR6; - } - - /* For each length, check that the remaining bytes start with the 0x80 bit - set and not the 0x40 bit. Then check for an overlong sequence, and for the - excluded range 0xd800 to 0xdfff. */ - - switch (ab) - { - /* 2-byte character. No further bytes to check for 0x80. Check first byte - for for xx00 000x (overlong sequence). */ - - case 1: if ((c & 0x3e) == 0) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 1; - return PCRE2_ERROR_UTF8_ERR15; - } - break; - - /* 3-byte character. Check third byte for 0x80. Then check first 2 bytes - for 1110 0000, xx0x xxxx (overlong sequence) or - 1110 1101, 1010 xxxx (0xd800 - 0xdfff) */ - - case 2: - if ((*(++p) & 0xc0) != 0x80) /* Third byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 2; - return PCRE2_ERROR_UTF8_ERR7; - } - if (c == 0xe0 && (d & 0x20) == 0) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 2; - return PCRE2_ERROR_UTF8_ERR16; - } - if (c == 0xed && d >= 0xa0) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 2; - return PCRE2_ERROR_UTF8_ERR14; - } - break; - - /* 4-byte character. Check 3rd and 4th bytes for 0x80. Then check first 2 - bytes for for 1111 0000, xx00 xxxx (overlong sequence), then check for a - character greater than 0x0010ffff (f4 8f bf bf) */ - - case 3: - if ((*(++p) & 0xc0) != 0x80) /* Third byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 2; - return PCRE2_ERROR_UTF8_ERR7; - } - if ((*(++p) & 0xc0) != 0x80) /* Fourth byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 3; - return PCRE2_ERROR_UTF8_ERR8; - } - if (c == 0xf0 && (d & 0x30) == 0) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 3; - return PCRE2_ERROR_UTF8_ERR17; - } - if (c > 0xf4 || (c == 0xf4 && d > 0x8f)) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 3; - return PCRE2_ERROR_UTF8_ERR13; - } - break; - - /* 5-byte and 6-byte characters are not allowed by RFC 3629, and will be - rejected by the length test below. However, we do the appropriate tests - here so that overlong sequences get diagnosed, and also in case there is - ever an option for handling these larger code points. */ - - /* 5-byte character. Check 3rd, 4th, and 5th bytes for 0x80. Then check for - 1111 1000, xx00 0xxx */ - - case 4: - if ((*(++p) & 0xc0) != 0x80) /* Third byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 2; - return PCRE2_ERROR_UTF8_ERR7; - } - if ((*(++p) & 0xc0) != 0x80) /* Fourth byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 3; - return PCRE2_ERROR_UTF8_ERR8; - } - if ((*(++p) & 0xc0) != 0x80) /* Fifth byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 4; - return PCRE2_ERROR_UTF8_ERR9; - } - if (c == 0xf8 && (d & 0x38) == 0) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 4; - return PCRE2_ERROR_UTF8_ERR18; - } - break; - - /* 6-byte character. Check 3rd-6th bytes for 0x80. Then check for - 1111 1100, xx00 00xx. */ - - case 5: - if ((*(++p) & 0xc0) != 0x80) /* Third byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 2; - return PCRE2_ERROR_UTF8_ERR7; - } - if ((*(++p) & 0xc0) != 0x80) /* Fourth byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 3; - return PCRE2_ERROR_UTF8_ERR8; - } - if ((*(++p) & 0xc0) != 0x80) /* Fifth byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 4; - return PCRE2_ERROR_UTF8_ERR9; - } - if ((*(++p) & 0xc0) != 0x80) /* Sixth byte */ - { - *erroroffset = (PCRE2_SIZE)(p - string) - 5; - return PCRE2_ERROR_UTF8_ERR10; - } - if (c == 0xfc && (d & 0x3c) == 0) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 5; - return PCRE2_ERROR_UTF8_ERR19; - } - break; - } - - /* Character is valid under RFC 2279, but 4-byte and 5-byte characters are - excluded by RFC 3629. The pointer p is currently at the last byte of the - character. */ - - if (ab > 3) - { - *erroroffset = (PCRE2_SIZE)(p - string) - ab; - return (ab == 4)? PCRE2_ERROR_UTF8_ERR11 : PCRE2_ERROR_UTF8_ERR12; - } - } -return 0; - - -/* ----------------- Check a UTF-16 string ----------------- */ - -#elif PCRE2_CODE_UNIT_WIDTH == 16 - -/* There's not so much work, nor so many errors, for UTF-16. -PCRE2_ERROR_UTF16_ERR1 Missing low surrogate at the end of the string -PCRE2_ERROR_UTF16_ERR2 Invalid low surrogate -PCRE2_ERROR_UTF16_ERR3 Isolated low surrogate -*/ - -for (p = string; length > 0; p++) - { - c = *p; - length--; - - if ((c & 0xf800) != 0xd800) - { - /* Normal UTF-16 code point. Neither high nor low surrogate. */ - } - else if ((c & 0x0400) == 0) - { - /* High surrogate. Must be a followed by a low surrogate. */ - if (length == 0) - { - *erroroffset = (PCRE2_SIZE)(p - string); - return PCRE2_ERROR_UTF16_ERR1; - } - p++; - length--; - if ((*p & 0xfc00) != 0xdc00) - { - *erroroffset = (PCRE2_SIZE)(p - string) - 1; - return PCRE2_ERROR_UTF16_ERR2; - } - } - else - { - /* Isolated low surrogate. Always an error. */ - *erroroffset = (PCRE2_SIZE)(p - string); - return PCRE2_ERROR_UTF16_ERR3; - } - } -return 0; - - - -/* ----------------- Check a UTF-32 string ----------------- */ - -#else - -/* There is very little to do for a UTF-32 string. -PCRE2_ERROR_UTF32_ERR1 Surrogate character -PCRE2_ERROR_UTF32_ERR2 Character > 0x10ffff -*/ - -for (p = string; length > 0; length--, p++) - { - c = *p; - if ((c & 0xfffff800u) != 0xd800u) - { - /* Normal UTF-32 code point. Neither high nor low surrogate. */ - if (c > 0x10ffffu) - { - *erroroffset = (PCRE2_SIZE)(p - string); - return PCRE2_ERROR_UTF32_ERR2; - } - } - else - { - /* A surrogate */ - *erroroffset = (PCRE2_SIZE)(p - string); - return PCRE2_ERROR_UTF32_ERR1; - } - } -return 0; -#endif /* CODE_UNIT_WIDTH */ -} -#endif /* SUPPORT_UNICODE */ - -/* End of pcre2_valid_utf.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_xclass.c b/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_xclass.c deleted file mode 100644 index 7bcae34..0000000 --- a/vendor/libgit2-sys/libgit2/deps/pcre2/pcre2_xclass.c +++ /dev/null @@ -1,547 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - - -/* This module contains two internal functions that are used to match -OP_XCLASS and OP_ECLASS. It is used by pcre2_auto_possessify() and by both -pcre2_match() and pcre2_dfa_match(). */ - - -#include "pcre2_internal.h" - - - -/************************************************* -* Match character against an XCLASS * -*************************************************/ - -/* This function is called to match a character against an extended class that -might contain codepoints above 255 and/or Unicode properties. - -Arguments: - c the character - data points to the flag code unit of the XCLASS data - utf TRUE if in UTF mode - -Returns: TRUE if character matches, else FALSE -*/ - -BOOL -PRIV(xclass)(uint32_t c, PCRE2_SPTR data, const uint8_t *char_lists_end, BOOL utf) -{ -/* Update PRIV(update_classbits) when this function is changed. */ -PCRE2_UCHAR t; -BOOL not_negated = (*data & XCL_NOT) == 0; -uint32_t type, max_index, min_index, value; -const uint8_t *next_char; - -#if PCRE2_CODE_UNIT_WIDTH == 8 -/* In 8 bit mode, this must always be TRUE. Help the compiler to know that. */ -utf = TRUE; -#endif - -/* Code points < 256 are matched against a bitmap, if one is present. */ - -if ((*data++ & XCL_MAP) != 0) - { - if (c < 256) - return (((const uint8_t *)data)[c/8] & (1u << (c&7))) != 0; - /* Skip bitmap. */ - data += 32 / sizeof(PCRE2_UCHAR); - } - -/* Match against the list of Unicode properties. We won't ever -encounter XCL_PROP or XCL_NOTPROP when UTF support is not compiled. */ -#ifdef SUPPORT_UNICODE -if (*data == XCL_PROP || *data == XCL_NOTPROP) - { - /* The UCD record is the same for all properties. */ - const ucd_record *prop = GET_UCD(c); - - do - { - int chartype; - BOOL isprop = (*data++) == XCL_PROP; - BOOL ok; - - switch(*data) - { - case PT_LAMP: - chartype = prop->chartype; - if ((chartype == ucp_Lu || chartype == ucp_Ll || - chartype == ucp_Lt) == isprop) return not_negated; - break; - - case PT_GC: - if ((data[1] == PRIV(ucp_gentype)[prop->chartype]) == isprop) - return not_negated; - break; - - case PT_PC: - if ((data[1] == prop->chartype) == isprop) return not_negated; - break; - - case PT_SC: - if ((data[1] == prop->script) == isprop) return not_negated; - break; - - case PT_SCX: - ok = (data[1] == prop->script || - MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), data[1]) != 0); - if (ok == isprop) return not_negated; - break; - - case PT_ALNUM: - chartype = prop->chartype; - if ((PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N) == isprop) - return not_negated; - break; - - /* Perl space used to exclude VT, but from Perl 5.18 it is included, - which means that Perl space and POSIX space are now identical. PCRE - was changed at release 8.34. */ - - case PT_SPACE: /* Perl space */ - case PT_PXSPACE: /* POSIX space */ - switch(c) - { - HSPACE_CASES: - VSPACE_CASES: - if (isprop) return not_negated; - break; - - default: - if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == isprop) - return not_negated; - break; - } - break; - - case PT_WORD: - chartype = prop->chartype; - if ((PRIV(ucp_gentype)[chartype] == ucp_L || - PRIV(ucp_gentype)[chartype] == ucp_N || - chartype == ucp_Mn || chartype == ucp_Pc) == isprop) - return not_negated; - break; - - case PT_UCNC: - if (c < 0xa0) - { - if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT || - c == CHAR_GRAVE_ACCENT) == isprop) - return not_negated; - } - else - { - if ((c < 0xd800 || c > 0xdfff) == isprop) - return not_negated; - } - break; - - case PT_BIDICL: - if ((UCD_BIDICLASS_PROP(prop) == data[1]) == isprop) - return not_negated; - break; - - case PT_BOOL: - ok = MAPBIT(PRIV(ucd_boolprop_sets) + - UCD_BPROPS_PROP(prop), data[1]) != 0; - if (ok == isprop) return not_negated; - break; - - /* The following three properties can occur only in an XCLASS, as there - is no \p or \P coding for them. */ - - /* Graphic character. Implement this as not Z (space or separator) and - not C (other), except for Cf (format) with a few exceptions. This seems - to be what Perl does. The exceptional characters are: - - U+061C Arabic Letter Mark - U+180E Mongolian Vowel Separator - U+2066 - U+2069 Various "isolate"s - */ - - case PT_PXGRAPH: - chartype = prop->chartype; - if ((PRIV(ucp_gentype)[chartype] != ucp_Z && - (PRIV(ucp_gentype)[chartype] != ucp_C || - (chartype == ucp_Cf && - c != 0x061c && c != 0x180e && (c < 0x2066 || c > 0x2069)) - )) == isprop) - return not_negated; - break; - - /* Printable character: same as graphic, with the addition of Zs, i.e. - not Zl and not Zp, and U+180E. */ - - case PT_PXPRINT: - chartype = prop->chartype; - if ((chartype != ucp_Zl && - chartype != ucp_Zp && - (PRIV(ucp_gentype)[chartype] != ucp_C || - (chartype == ucp_Cf && - c != 0x061c && (c < 0x2066 || c > 0x2069)) - )) == isprop) - return not_negated; - break; - - /* Punctuation: all Unicode punctuation, plus ASCII characters that - Unicode treats as symbols rather than punctuation, for Perl - compatibility (these are $+<=>^`|~). */ - - case PT_PXPUNCT: - chartype = prop->chartype; - if ((PRIV(ucp_gentype)[chartype] == ucp_P || - (c < 128 && PRIV(ucp_gentype)[chartype] == ucp_S)) == isprop) - return not_negated; - break; - - /* Perl has two sets of hex digits */ - - case PT_PXXDIGIT: - if (((c >= CHAR_0 && c <= CHAR_9) || - (c >= CHAR_A && c <= CHAR_F) || - (c >= CHAR_a && c <= CHAR_f) || - (c >= 0xff10 && c <= 0xff19) || /* Fullwidth digits */ - (c >= 0xff21 && c <= 0xff26) || /* Fullwidth letters */ - (c >= 0xff41 && c <= 0xff46)) == isprop) - return not_negated; - break; - - /* This should never occur, but compilers may mutter if there is no - default. */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return FALSE; - /* LCOV_EXCL_STOP */ - } - - data += 2; - } - while (*data == XCL_PROP || *data == XCL_NOTPROP); - } -#else - (void)utf; /* Avoid compiler warning */ -#endif /* SUPPORT_UNICODE */ - -/* Match against large chars or ranges that end with a large char. */ -if (*data < XCL_LIST) - { - while ((t = *data++) != XCL_END) - { - uint32_t x, y; - -#ifdef SUPPORT_UNICODE - if (utf) - { - GETCHARINC(x, data); /* macro generates multiple statements */ - } - else -#endif - x = *data++; - - if (t == XCL_SINGLE) - { - /* Since character ranges follow the properties, and they are - sorted, early return is possible for all characters <= x. */ - if (c <= x) return (c == x) ? not_negated : !not_negated; - continue; - } - - PCRE2_ASSERT(t == XCL_RANGE); -#ifdef SUPPORT_UNICODE - if (utf) - { - GETCHARINC(y, data); /* macro generates multiple statements */ - } - else -#endif - y = *data++; - - /* Since character ranges follow the properties, and they are - sorted, early return is possible for all characters <= y. */ - if (c <= y) return (c >= x) ? not_negated : !not_negated; - } - - return !not_negated; /* char did not match */ - } - -#if PCRE2_CODE_UNIT_WIDTH == 8 -type = (uint32_t)(data[0] << 8) | data[1]; -data += 2; -#else -type = data[0]; -data++; -#endif /* CODE_UNIT_WIDTH */ - -/* Align characters. */ -next_char = char_lists_end - (GET(data, 0) << 1); -type &= XCL_TYPE_MASK; - -/* Alignment check. */ -PCRE2_ASSERT(((uintptr_t)next_char & 0x1) == 0); - -if (c >= XCL_CHAR_LIST_HIGH_16_START) - { - max_index = type & XCL_ITEM_COUNT_MASK; - if (max_index == XCL_ITEM_COUNT_MASK) - { - max_index = *(const uint16_t*)next_char; - PCRE2_ASSERT(max_index >= XCL_ITEM_COUNT_MASK); - next_char += 2; - } - - next_char += max_index << 1; - type >>= XCL_TYPE_BIT_LEN; - } - -if (c < XCL_CHAR_LIST_LOW_32_START) - { - max_index = type & XCL_ITEM_COUNT_MASK; - - c = (uint16_t)((c << XCL_CHAR_SHIFT) | XCL_CHAR_END); - - if (max_index == XCL_ITEM_COUNT_MASK) - { - max_index = *(const uint16_t*)next_char; - PCRE2_ASSERT(max_index >= XCL_ITEM_COUNT_MASK); - next_char += 2; - } - - if (max_index == 0 || c < *(const uint16_t*)next_char) - return ((type & XCL_BEGIN_WITH_RANGE) != 0) == not_negated; - - min_index = 0; - value = ((const uint16_t*)next_char)[--max_index]; - if (c >= value) - return (value == c || (value & XCL_CHAR_END) == 0) == not_negated; - - max_index--; - - /* Binary search of a range. */ - while (TRUE) - { - uint32_t mid_index = (min_index + max_index) >> 1; - value = ((const uint16_t*)next_char)[mid_index]; - - if (c < value) - max_index = mid_index - 1; - else if (((const uint16_t*)next_char)[mid_index + 1] <= c) - min_index = mid_index + 1; - else - return (value == c || (value & XCL_CHAR_END) == 0) == not_negated; - } - } - -/* Skip the 16 bit ranges. */ -max_index = type & XCL_ITEM_COUNT_MASK; -if (max_index == XCL_ITEM_COUNT_MASK) - { - max_index = *(const uint16_t*)next_char; - PCRE2_ASSERT(max_index >= XCL_ITEM_COUNT_MASK); - next_char += 2; - } - -next_char += (max_index << 1); -type >>= XCL_TYPE_BIT_LEN; - -/* Alignment check. */ -PCRE2_ASSERT(((uintptr_t)next_char & 0x3) == 0); - -max_index = type & XCL_ITEM_COUNT_MASK; - -#if PCRE2_CODE_UNIT_WIDTH == 32 -if (c >= XCL_CHAR_LIST_HIGH_32_START) - { - if (max_index == XCL_ITEM_COUNT_MASK) - { - max_index = *(const uint32_t*)next_char; - PCRE2_ASSERT(max_index >= XCL_ITEM_COUNT_MASK); - next_char += 4; - } - - next_char += max_index << 2; - type >>= XCL_TYPE_BIT_LEN; - max_index = type & XCL_ITEM_COUNT_MASK; - } -#endif - -c = (uint32_t)((c << XCL_CHAR_SHIFT) | XCL_CHAR_END); - -if (max_index == XCL_ITEM_COUNT_MASK) - { - max_index = *(const uint32_t*)next_char; - next_char += 4; - } - -if (max_index == 0 || c < *(const uint32_t*)next_char) - return ((type & XCL_BEGIN_WITH_RANGE) != 0) == not_negated; - -min_index = 0; -value = ((const uint32_t*)next_char)[--max_index]; -if (c >= value) - return (value == c || (value & XCL_CHAR_END) == 0) == not_negated; - -max_index--; - -/* Binary search of a range. */ -while (TRUE) - { - uint32_t mid_index = (min_index + max_index) >> 1; - value = ((const uint32_t*)next_char)[mid_index]; - - if (c < value) - max_index = mid_index - 1; - else if (((const uint32_t*)next_char)[mid_index + 1] <= c) - min_index = mid_index + 1; - else - return (value == c || (value & XCL_CHAR_END) == 0) == not_negated; - } -} - - - -/************************************************* -* Match character against an ECLASS * -*************************************************/ - -/* This function is called to match a character against an extended class -used for describing characters using boolean operations on sets. - -Arguments: - c the character - data_start points to the start of the ECLASS data - data_end points one-past-the-last of the ECLASS data - utf TRUE if in UTF mode - -Returns: TRUE if character matches, else FALSE -*/ - -BOOL -PRIV(eclass)(uint32_t c, PCRE2_SPTR data_start, PCRE2_SPTR data_end, - const uint8_t *char_lists_end, BOOL utf) -{ -PCRE2_SPTR ptr = data_start; -PCRE2_UCHAR flags; -uint32_t stack = 0; -int stack_depth = 0; - -PCRE2_ASSERT(data_start < data_end); -flags = *ptr++; -PCRE2_ASSERT((flags & ECL_MAP) == 0 || - (data_end - ptr) >= 32 / (int)sizeof(PCRE2_UCHAR)); - -/* Code points < 256 are matched against a bitmap, if one is present. -Otherwise all codepoints are checked later. */ - -if ((flags & ECL_MAP) != 0) - { - if (c < 256) - return (((const uint8_t *)ptr)[c/8] & (1u << (c&7))) != 0; - - /* Skip the bitmap. */ - ptr += 32 / sizeof(PCRE2_UCHAR); - } - -/* Do a little loop, until we reach the end of the ECLASS. */ -while (ptr < data_end) - { - switch (*ptr) - { - case ECL_AND: - ++ptr; - stack = (stack >> 1) & (stack | ~(uint32_t)1u); - PCRE2_ASSERT(stack_depth >= 2); - --stack_depth; - break; - - case ECL_OR: - ++ptr; - stack = (stack >> 1) | (stack & (uint32_t)1u); - PCRE2_ASSERT(stack_depth >= 2); - --stack_depth; - break; - - case ECL_XOR: - ++ptr; - stack = (stack >> 1) ^ (stack & (uint32_t)1u); - PCRE2_ASSERT(stack_depth >= 2); - --stack_depth; - break; - - case ECL_NOT: - ++ptr; - stack ^= (uint32_t)1u; - PCRE2_ASSERT(stack_depth >= 1); - break; - - case ECL_XCLASS: - { - uint32_t matched = PRIV(xclass)(c, ptr + 1 + LINK_SIZE, char_lists_end, utf); - - ptr += GET(ptr, 1); - stack = (stack << 1) | matched; - ++stack_depth; - break; - } - - /* This should never occur, but compilers may mutter if there is no - default. */ - - /* LCOV_EXCL_START */ - default: - PCRE2_DEBUG_UNREACHABLE(); - return FALSE; - /* LCOV_EXCL_STOP */ - } - } - -PCRE2_ASSERT(stack_depth == 1); -(void)stack_depth; /* Ignore unused variable, if assertions are disabled. */ - -/* The final bit left on the stack now holds the match result. */ -return (stack & 1u) != 0; -} - -/* End of pcre2_xclass.c */ diff --git a/vendor/libgit2-sys/libgit2/deps/winhttp/CMakeLists.txt b/vendor/libgit2-sys/libgit2/deps/winhttp/CMakeLists.txt deleted file mode 100644 index 1a87989..0000000 --- a/vendor/libgit2-sys/libgit2/deps/winhttp/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -find_program(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH) -if(NOT DLLTOOL) - message(FATAL_ERROR "Could not find dlltool command") -endif() - -set(LIBWINHTTP_PATH "${PROJECT_BINARY_DIR}/deps/winhttp") -set(LIBWINHTTP_PATH ${LIBWINHTTP_PATH} PARENT_SCOPE) -file(MAKE_DIRECTORY ${LIBWINHTTP_PATH}) - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(WINHTTP_DEF "winhttp64.def") -else() - set(WINHTTP_DEF "winhttp.def") -endif() - -add_custom_command( - OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a - COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a - DEPENDS ${WINHTTP_DEF} - WORKING_DIRECTORY ${LIBWINHTTP_PATH}) - -set_source_files_properties( - ${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c - PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a) diff --git a/vendor/libgit2-sys/libgit2/deps/winhttp/COPYING.GPL b/vendor/libgit2-sys/libgit2/deps/winhttp/COPYING.GPL deleted file mode 100644 index da695eb..0000000 --- a/vendor/libgit2-sys/libgit2/deps/winhttp/COPYING.GPL +++ /dev/null @@ -1,993 +0,0 @@ - libgit2 is Copyright (C) the libgit2 contributors, - unless otherwise stated. See the AUTHORS file for details. - - Note that the only valid version of the GPL as far as this project - is concerned is _this_ particular version of the license (ie v2, not - v2.2 or v3.x or whatever), unless explicitly otherwise stated. - ----------------------------------------------------------------------- - - LINKING EXCEPTION - - In addition to the permissions in the GNU General Public License, - the authors give you unlimited permission to link the compiled - version of this library into combinations with other programs, - and to distribute those combinations without any restriction - coming from the use of this file. (The General Public License - restrictions do apply in other respects; for example, they cover - modification of the file, and distribution when not linked into - a combined executable.) - ----------------------------------------------------------------------- - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. - ----------------------------------------------------------------------- - -The bundled ZLib code is licensed under the ZLib license: - -Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - ----------------------------------------------------------------------- - -The Clar framework is licensed under the ISC license: - -Copyright (c) 2011-2015 Vicent Marti - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ----------------------------------------------------------------------- - -The regex library (deps/regex/) is licensed under the GNU LGPL -(available at the end of this file). - -Definitions for data structures and routines for the regular -expression library. - -Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006,2008 -Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with the GNU C Library; if not, write to the Free -Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - ----------------------------------------------------------------------- - -The bundled winhttp definition files (deps/winhttp/) are licensed under -the GNU LGPL (available at the end of this file). - -Copyright (C) 2007 Francois Gouget - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - ----------------------------------------------------------------------- - - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - ----------------------------------------------------------------------- - -The bundled SHA1 collision detection code is licensed under the MIT license: - -MIT License - -Copyright (c) 2017: - Marc Stevens - Cryptology Group - Centrum Wiskunde & Informatica - P.O. Box 94079, 1090 GB Amsterdam, Netherlands - marc@marc-stevens.nl - - Dan Shumow - Microsoft Research - danshu@microsoft.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/libgit2-sys/libgit2/deps/winhttp/COPYING.LGPL b/vendor/libgit2-sys/libgit2/deps/winhttp/COPYING.LGPL deleted file mode 100644 index 4362b49..0000000 --- a/vendor/libgit2-sys/libgit2/deps/winhttp/COPYING.LGPL +++ /dev/null @@ -1,502 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/vendor/libgit2-sys/libgit2/deps/winhttp/urlmon.h b/vendor/libgit2-sys/libgit2/deps/winhttp/urlmon.h deleted file mode 100644 index 4143d50..0000000 --- a/vendor/libgit2-sys/libgit2/deps/winhttp/urlmon.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#if defined(__MINGW_VERSION) || defined(__MINGW32_VERSION) - -#ifndef __CUSTOM_URLMON_H -#define __CUSTOM_URLMON_H - -typedef struct IInternetSecurityManager IInternetSecurityManager; - -typedef struct IInternetSecurityManagerVtbl -{ - HRESULT(STDMETHODCALLTYPE *QueryInterface)(IInternetSecurityManager *, REFIID, void **); - ULONG(STDMETHODCALLTYPE *AddRef)(IInternetSecurityManager *); - ULONG(STDMETHODCALLTYPE *Release)(IInternetSecurityManager *); - LPVOID SetSecuritySite; - LPVOID GetSecuritySite; - HRESULT(STDMETHODCALLTYPE *MapUrlToZone)(IInternetSecurityManager *, LPCWSTR, DWORD *, DWORD); - LPVOID GetSecurityId; - LPVOID ProcessUrlAction; - LPVOID QueryCustomPolicy; - LPVOID SetZoneMapping; - LPVOID GetZoneMappings; -} IInternetSecurityManagerVtbl; - -struct IInternetSecurityManager -{ - CONST_VTBL struct IInternetSecurityManagerVtbl *lpVtbl; -}; - -#define URLZONE_LOCAL_MACHINE 0 -#define URLZONE_INTRANET 1 -#define URLZONE_TRUSTED 2 - -#endif /* __CUSTOM_URLMON_H */ - -#else - -#include_next - -#endif diff --git a/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp.def b/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp.def deleted file mode 100644 index eecce59..0000000 --- a/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp.def +++ /dev/null @@ -1,29 +0,0 @@ -LIBRARY WINHTTP -EXPORTS -WinHttpAddRequestHeaders@16 -WinHttpCheckPlatform@0 -WinHttpCloseHandle@4 -WinHttpConnect@16 -WinHttpCrackUrl@16 -WinHttpCreateUrl@16 -WinHttpDetectAutoProxyConfigUrl@8 -WinHttpGetDefaultProxyConfiguration@4 -WinHttpGetIEProxyConfigForCurrentUser@4 -WinHttpGetProxyForUrl@16 -WinHttpOpen@20 -WinHttpOpenRequest@28 -WinHttpQueryAuthSchemes@16 -WinHttpQueryDataAvailable@8 -WinHttpQueryHeaders@24 -WinHttpQueryOption@16 -WinHttpReadData@16 -WinHttpReceiveResponse@8 -WinHttpSendRequest@28 -WinHttpSetCredentials@24 -WinHttpSetDefaultProxyConfiguration@4 -WinHttpSetOption@16 -WinHttpSetStatusCallback@16 -WinHttpSetTimeouts@20 -WinHttpTimeFromSystemTime@8 -WinHttpTimeToSystemTime@8 -WinHttpWriteData@16 diff --git a/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp.h b/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp.h deleted file mode 100644 index b7fef1c..0000000 --- a/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp.h +++ /dev/null @@ -1,594 +0,0 @@ -/* - * Copyright (C) 2007 Francois Gouget - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#if defined(__MINGW_VERSION) || defined(__MINGW32_VERSION) - -#ifndef __WINE_WINHTTP_H -#define __WINE_WINHTTP_H - -#ifdef _WIN64 -#include -#else -#include -#endif - -#define WINHTTPAPI -#define BOOLAPI WINHTTPAPI BOOL WINAPI - - -typedef LPVOID HINTERNET; -typedef HINTERNET *LPHINTERNET; - -#define INTERNET_DEFAULT_PORT 0 -#define INTERNET_DEFAULT_HTTP_PORT 80 -#define INTERNET_DEFAULT_HTTPS_PORT 443 -typedef WORD INTERNET_PORT; -typedef INTERNET_PORT *LPINTERNET_PORT; - -#define INTERNET_SCHEME_HTTP 1 -#define INTERNET_SCHEME_HTTPS 2 -typedef int INTERNET_SCHEME, *LPINTERNET_SCHEME; - -#define ICU_ESCAPE 0x80000000 - -/* flags for WinHttpOpen */ -#define WINHTTP_FLAG_ASYNC 0x10000000 - -/* flags for WinHttpOpenRequest */ -#define WINHTTP_FLAG_ESCAPE_PERCENT 0x00000004 -#define WINHTTP_FLAG_NULL_CODEPAGE 0x00000008 -#define WINHTTP_FLAG_ESCAPE_DISABLE 0x00000040 -#define WINHTTP_FLAG_ESCAPE_DISABLE_QUERY 0x00000080 -#define WINHTTP_FLAG_BYPASS_PROXY_CACHE 0x00000100 -#define WINHTTP_FLAG_REFRESH WINHTTP_FLAG_BYPASS_PROXY_CACHE -#define WINHTTP_FLAG_SECURE 0x00800000 - -#define WINHTTP_ACCESS_TYPE_DEFAULT_PROXY 0 -#define WINHTTP_ACCESS_TYPE_NO_PROXY 1 -#define WINHTTP_ACCESS_TYPE_NAMED_PROXY 3 - -#define WINHTTP_NO_PROXY_NAME NULL -#define WINHTTP_NO_PROXY_BYPASS NULL - -#define WINHTTP_NO_REFERER NULL -#define WINHTTP_DEFAULT_ACCEPT_TYPES NULL - -#define WINHTTP_NO_ADDITIONAL_HEADERS NULL -#define WINHTTP_NO_REQUEST_DATA NULL - -#define WINHTTP_HEADER_NAME_BY_INDEX NULL -#define WINHTTP_NO_OUTPUT_BUFFER NULL -#define WINHTTP_NO_HEADER_INDEX NULL - -#define WINHTTP_ADDREQ_INDEX_MASK 0x0000FFFF -#define WINHTTP_ADDREQ_FLAGS_MASK 0xFFFF0000 -#define WINHTTP_ADDREQ_FLAG_ADD_IF_NEW 0x10000000 -#define WINHTTP_ADDREQ_FLAG_ADD 0x20000000 -#define WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA 0x40000000 -#define WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON 0x01000000 -#define WINHTTP_ADDREQ_FLAG_COALESCE WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA -#define WINHTTP_ADDREQ_FLAG_REPLACE 0x80000000 - -#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0 - -/* flags for WinHttp{Set/Query}Options */ -#define WINHTTP_FIRST_OPTION WINHTTP_OPTION_CALLBACK -#define WINHTTP_OPTION_CALLBACK 1 -#define WINHTTP_OPTION_RESOLVE_TIMEOUT 2 -#define WINHTTP_OPTION_CONNECT_TIMEOUT 3 -#define WINHTTP_OPTION_CONNECT_RETRIES 4 -#define WINHTTP_OPTION_SEND_TIMEOUT 5 -#define WINHTTP_OPTION_RECEIVE_TIMEOUT 6 -#define WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT 7 -#define WINHTTP_OPTION_HANDLE_TYPE 9 -#define WINHTTP_OPTION_READ_BUFFER_SIZE 12 -#define WINHTTP_OPTION_WRITE_BUFFER_SIZE 13 -#define WINHTTP_OPTION_PARENT_HANDLE 21 -#define WINHTTP_OPTION_EXTENDED_ERROR 24 -#define WINHTTP_OPTION_SECURITY_FLAGS 31 -#define WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT 32 -#define WINHTTP_OPTION_URL 34 -#define WINHTTP_OPTION_SECURITY_KEY_BITNESS 36 -#define WINHTTP_OPTION_PROXY 38 -#define WINHTTP_OPTION_USER_AGENT 41 -#define WINHTTP_OPTION_CONTEXT_VALUE 45 -#define WINHTTP_OPTION_CLIENT_CERT_CONTEXT 47 -#define WINHTTP_OPTION_REQUEST_PRIORITY 58 -#define WINHTTP_OPTION_HTTP_VERSION 59 -#define WINHTTP_OPTION_DISABLE_FEATURE 63 -#define WINHTTP_OPTION_CODEPAGE 68 -#define WINHTTP_OPTION_MAX_CONNS_PER_SERVER 73 -#define WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER 74 -#define WINHTTP_OPTION_AUTOLOGON_POLICY 77 -#define WINHTTP_OPTION_SERVER_CERT_CONTEXT 78 -#define WINHTTP_OPTION_ENABLE_FEATURE 79 -#define WINHTTP_OPTION_WORKER_THREAD_COUNT 80 -#define WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT 81 -#define WINHTTP_OPTION_PASSPORT_COBRANDING_URL 82 -#define WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH 83 -#define WINHTTP_OPTION_SECURE_PROTOCOLS 84 -#define WINHTTP_OPTION_ENABLETRACING 85 -#define WINHTTP_OPTION_PASSPORT_SIGN_OUT 86 -#define WINHTTP_OPTION_PASSPORT_RETURN_URL 87 -#define WINHTTP_OPTION_REDIRECT_POLICY 88 -#define WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS 89 -#define WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE 90 -#define WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE 91 -#define WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE 92 -#define WINHTTP_OPTION_CONNECTION_INFO 93 -#define WINHTTP_OPTION_CLIENT_CERT_ISSUER_LIST 94 -#define WINHTTP_OPTION_SPN 96 -#define WINHTTP_OPTION_GLOBAL_PROXY_CREDS 97 -#define WINHTTP_OPTION_GLOBAL_SERVER_CREDS 98 -#define WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT 99 -#define WINHTTP_OPTION_REJECT_USERPWD_IN_URL 100 -#define WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS 101 -#define WINHTTP_LAST_OPTION WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS -#define WINHTTP_OPTION_USERNAME 0x1000 -#define WINHTTP_OPTION_PASSWORD 0x1001 -#define WINHTTP_OPTION_PROXY_USERNAME 0x1002 -#define WINHTTP_OPTION_PROXY_PASSWORD 0x1003 - -#define WINHTTP_CONNS_PER_SERVER_UNLIMITED 0xFFFFFFFF - -#define WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM 0 -#define WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW 1 -#define WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH 2 -#define WINHTTP_AUTOLOGON_SECURITY_LEVEL_DEFAULT WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM - -#define WINHTTP_OPTION_REDIRECT_POLICY_NEVER 0 -#define WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP 1 -#define WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS 2 -#define WINHTTP_OPTION_REDIRECT_POLICY_LAST WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS -#define WINHTTP_OPTION_REDIRECT_POLICY_DEFAULT WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP - -#define WINHTTP_DISABLE_PASSPORT_AUTH 0x00000000 -#define WINHTTP_ENABLE_PASSPORT_AUTH 0x10000000 -#define WINHTTP_DISABLE_PASSPORT_KEYRING 0x20000000 -#define WINHTTP_ENABLE_PASSPORT_KEYRING 0x40000000 - -#define WINHTTP_DISABLE_COOKIES 0x00000001 -#define WINHTTP_DISABLE_REDIRECTS 0x00000002 -#define WINHTTP_DISABLE_AUTHENTICATION 0x00000004 -#define WINHTTP_DISABLE_KEEP_ALIVE 0x00000008 -#define WINHTTP_ENABLE_SSL_REVOCATION 0x00000001 -#define WINHTTP_ENABLE_SSL_REVERT_IMPERSONATION 0x00000002 -#define WINHTTP_DISABLE_SPN_SERVER_PORT 0x00000000 -#define WINHTTP_ENABLE_SPN_SERVER_PORT 0x00000001 -#define WINHTTP_OPTION_SPN_MASK WINHTTP_ENABLE_SPN_SERVER_PORT - -/* Options for WinHttpOpenRequest */ -#define WINHTTP_NO_REFERER NULL -#define WINHTTP_DEFAULT_ACCEPT_TYPES NULL - -/* Options for WinHttpSendRequest */ -#define WINHTTP_NO_ADDITIONAL_HEADERS NULL -#define WINHTTP_NO_REQUEST_DATA NULL - -/* WinHTTP error codes */ -#define WINHTTP_ERROR_BASE 12000 -#define ERROR_WINHTTP_OUT_OF_HANDLES (WINHTTP_ERROR_BASE + 1) -#define ERROR_WINHTTP_TIMEOUT (WINHTTP_ERROR_BASE + 2) -#define ERROR_WINHTTP_INTERNAL_ERROR (WINHTTP_ERROR_BASE + 4) -#define ERROR_WINHTTP_INVALID_URL (WINHTTP_ERROR_BASE + 5) -#define ERROR_WINHTTP_UNRECOGNIZED_SCHEME (WINHTTP_ERROR_BASE + 6) -#define ERROR_WINHTTP_NAME_NOT_RESOLVED (WINHTTP_ERROR_BASE + 7) -#define ERROR_WINHTTP_INVALID_OPTION (WINHTTP_ERROR_BASE + 9) -#define ERROR_WINHTTP_OPTION_NOT_SETTABLE (WINHTTP_ERROR_BASE + 11) -#define ERROR_WINHTTP_SHUTDOWN (WINHTTP_ERROR_BASE + 12) -#define ERROR_WINHTTP_LOGIN_FAILURE (WINHTTP_ERROR_BASE + 15) -#define ERROR_WINHTTP_OPERATION_CANCELLED (WINHTTP_ERROR_BASE + 17) -#define ERROR_WINHTTP_INCORRECT_HANDLE_TYPE (WINHTTP_ERROR_BASE + 18) -#define ERROR_WINHTTP_INCORRECT_HANDLE_STATE (WINHTTP_ERROR_BASE + 19) -#define ERROR_WINHTTP_CANNOT_CONNECT (WINHTTP_ERROR_BASE + 29) -#define ERROR_WINHTTP_CONNECTION_ERROR (WINHTTP_ERROR_BASE + 30) -#define ERROR_WINHTTP_RESEND_REQUEST (WINHTTP_ERROR_BASE + 32) -#define ERROR_WINHTTP_SECURE_CERT_DATE_INVALID (WINHTTP_ERROR_BASE + 37) -#define ERROR_WINHTTP_SECURE_CERT_CN_INVALID (WINHTTP_ERROR_BASE + 38) -#define ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED (WINHTTP_ERROR_BASE + 44) -#define ERROR_WINHTTP_SECURE_INVALID_CA (WINHTTP_ERROR_BASE + 45) -#define ERROR_WINHTTP_SECURE_CERT_REV_FAILED (WINHTTP_ERROR_BASE + 57) -#define ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN (WINHTTP_ERROR_BASE + 100) -#define ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND (WINHTTP_ERROR_BASE + 101) -#define ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND (WINHTTP_ERROR_BASE + 102) -#define ERROR_WINHTTP_CANNOT_CALL_AFTER_OPEN (WINHTTP_ERROR_BASE + 103) -#define ERROR_WINHTTP_HEADER_NOT_FOUND (WINHTTP_ERROR_BASE + 150) -#define ERROR_WINHTTP_INVALID_SERVER_RESPONSE (WINHTTP_ERROR_BASE + 152) -#define ERROR_WINHTTP_INVALID_HEADER (WINHTTP_ERROR_BASE + 153) -#define ERROR_WINHTTP_INVALID_QUERY_REQUEST (WINHTTP_ERROR_BASE + 154) -#define ERROR_WINHTTP_HEADER_ALREADY_EXISTS (WINHTTP_ERROR_BASE + 155) -#define ERROR_WINHTTP_REDIRECT_FAILED (WINHTTP_ERROR_BASE + 156) -#define ERROR_WINHTTP_SECURE_CHANNEL_ERROR (WINHTTP_ERROR_BASE + 157) -#define ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT (WINHTTP_ERROR_BASE + 166) -#define ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT (WINHTTP_ERROR_BASE + 167) -#define ERROR_WINHTTP_SECURE_INVALID_CERT (WINHTTP_ERROR_BASE + 169) -#define ERROR_WINHTTP_SECURE_CERT_REVOKED (WINHTTP_ERROR_BASE + 170) -#define ERROR_WINHTTP_NOT_INITIALIZED (WINHTTP_ERROR_BASE + 172) -#define ERROR_WINHTTP_SECURE_FAILURE (WINHTTP_ERROR_BASE + 175) -#define ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR (WINHTTP_ERROR_BASE + 178) -#define ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE (WINHTTP_ERROR_BASE + 179) -#define ERROR_WINHTTP_AUTODETECTION_FAILED (WINHTTP_ERROR_BASE + 180) -#define ERROR_WINHTTP_HEADER_COUNT_EXCEEDED (WINHTTP_ERROR_BASE + 181) -#define ERROR_WINHTTP_HEADER_SIZE_OVERFLOW (WINHTTP_ERROR_BASE + 182) -#define ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW (WINHTTP_ERROR_BASE + 183) -#define ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW (WINHTTP_ERROR_BASE + 184) -#define ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY (WINHTTP_ERROR_BASE + 185) -#define ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY (WINHTTP_ERROR_BASE + 186) -#define WINHTTP_ERROR_LAST (WINHTTP_ERROR_BASE + 186) - -/* WinHttp status codes */ -#define HTTP_STATUS_CONTINUE 100 -#define HTTP_STATUS_SWITCH_PROTOCOLS 101 -#define HTTP_STATUS_OK 200 -#define HTTP_STATUS_CREATED 201 -#define HTTP_STATUS_ACCEPTED 202 -#define HTTP_STATUS_PARTIAL 203 -#define HTTP_STATUS_NO_CONTENT 204 -#define HTTP_STATUS_RESET_CONTENT 205 -#define HTTP_STATUS_PARTIAL_CONTENT 206 -#define HTTP_STATUS_WEBDAV_MULTI_STATUS 207 -#define HTTP_STATUS_AMBIGUOUS 300 -#define HTTP_STATUS_MOVED 301 -#define HTTP_STATUS_REDIRECT 302 -#define HTTP_STATUS_REDIRECT_METHOD 303 -#define HTTP_STATUS_NOT_MODIFIED 304 -#define HTTP_STATUS_USE_PROXY 305 -#define HTTP_STATUS_REDIRECT_KEEP_VERB 307 -#define HTTP_STATUS_BAD_REQUEST 400 -#define HTTP_STATUS_DENIED 401 -#define HTTP_STATUS_PAYMENT_REQ 402 -#define HTTP_STATUS_FORBIDDEN 403 -#define HTTP_STATUS_NOT_FOUND 404 -#define HTTP_STATUS_BAD_METHOD 405 -#define HTTP_STATUS_NONE_ACCEPTABLE 406 -#define HTTP_STATUS_PROXY_AUTH_REQ 407 -#define HTTP_STATUS_REQUEST_TIMEOUT 408 -#define HTTP_STATUS_CONFLICT 409 -#define HTTP_STATUS_GONE 410 -#define HTTP_STATUS_LENGTH_REQUIRED 411 -#define HTTP_STATUS_PRECOND_FAILED 412 -#define HTTP_STATUS_REQUEST_TOO_LARGE 413 -#define HTTP_STATUS_URI_TOO_LONG 414 -#define HTTP_STATUS_UNSUPPORTED_MEDIA 415 -#define HTTP_STATUS_RETRY_WITH 449 -#define HTTP_STATUS_SERVER_ERROR 500 -#define HTTP_STATUS_NOT_SUPPORTED 501 -#define HTTP_STATUS_BAD_GATEWAY 502 -#define HTTP_STATUS_SERVICE_UNAVAIL 503 -#define HTTP_STATUS_GATEWAY_TIMEOUT 504 -#define HTTP_STATUS_VERSION_NOT_SUP 505 -#define HTTP_STATUS_FIRST HTTP_STATUS_CONTINUE -#define HTTP_STATUS_LAST HTTP_STATUS_VERSION_NOT_SUP - -#define SECURITY_FLAG_IGNORE_UNKNOWN_CA 0x00000100 -#define SECURITY_FLAG_IGNORE_CERT_DATE_INVALID 0x00002000 -#define SECURITY_FLAG_IGNORE_CERT_CN_INVALID 0x00001000 -#define SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE 0x00000200 -#define SECURITY_FLAG_SECURE 0x00000001 -#define SECURITY_FLAG_STRENGTH_WEAK 0x10000000 -#define SECURITY_FLAG_STRENGTH_MEDIUM 0x40000000 -#define SECURITY_FLAG_STRENGTH_STRONG 0x20000000 - -#define ICU_NO_ENCODE 0x20000000 -#define ICU_DECODE 0x10000000 -#define ICU_NO_META 0x08000000 -#define ICU_ENCODE_SPACES_ONLY 0x04000000 -#define ICU_BROWSER_MODE 0x02000000 -#define ICU_ENCODE_PERCENT 0x00001000 - -/* Query flags */ -#define WINHTTP_QUERY_MIME_VERSION 0 -#define WINHTTP_QUERY_CONTENT_TYPE 1 -#define WINHTTP_QUERY_CONTENT_TRANSFER_ENCODING 2 -#define WINHTTP_QUERY_CONTENT_ID 3 -#define WINHTTP_QUERY_CONTENT_DESCRIPTION 4 -#define WINHTTP_QUERY_CONTENT_LENGTH 5 -#define WINHTTP_QUERY_CONTENT_LANGUAGE 6 -#define WINHTTP_QUERY_ALLOW 7 -#define WINHTTP_QUERY_PUBLIC 8 -#define WINHTTP_QUERY_DATE 9 -#define WINHTTP_QUERY_EXPIRES 10 -#define WINHTTP_QUERY_LAST_MODIFIED 11 -#define WINHTTP_QUERY_MESSAGE_ID 12 -#define WINHTTP_QUERY_URI 13 -#define WINHTTP_QUERY_DERIVED_FROM 14 -#define WINHTTP_QUERY_COST 15 -#define WINHTTP_QUERY_LINK 16 -#define WINHTTP_QUERY_PRAGMA 17 -#define WINHTTP_QUERY_VERSION 18 -#define WINHTTP_QUERY_STATUS_CODE 19 -#define WINHTTP_QUERY_STATUS_TEXT 20 -#define WINHTTP_QUERY_RAW_HEADERS 21 -#define WINHTTP_QUERY_RAW_HEADERS_CRLF 22 -#define WINHTTP_QUERY_CONNECTION 23 -#define WINHTTP_QUERY_ACCEPT 24 -#define WINHTTP_QUERY_ACCEPT_CHARSET 25 -#define WINHTTP_QUERY_ACCEPT_ENCODING 26 -#define WINHTTP_QUERY_ACCEPT_LANGUAGE 27 -#define WINHTTP_QUERY_AUTHORIZATION 28 -#define WINHTTP_QUERY_CONTENT_ENCODING 29 -#define WINHTTP_QUERY_FORWARDED 30 -#define WINHTTP_QUERY_FROM 31 -#define WINHTTP_QUERY_IF_MODIFIED_SINCE 32 -#define WINHTTP_QUERY_LOCATION 33 -#define WINHTTP_QUERY_ORIG_URI 34 -#define WINHTTP_QUERY_REFERER 35 -#define WINHTTP_QUERY_RETRY_AFTER 36 -#define WINHTTP_QUERY_SERVER 37 -#define WINHTTP_QUERY_TITLE 38 -#define WINHTTP_QUERY_USER_AGENT 39 -#define WINHTTP_QUERY_WWW_AUTHENTICATE 40 -#define WINHTTP_QUERY_PROXY_AUTHENTICATE 41 -#define WINHTTP_QUERY_ACCEPT_RANGES 42 -#define WINHTTP_QUERY_SET_COOKIE 43 -#define WINHTTP_QUERY_COOKIE 44 -#define WINHTTP_QUERY_REQUEST_METHOD 45 -#define WINHTTP_QUERY_REFRESH 46 -#define WINHTTP_QUERY_CONTENT_DISPOSITION 47 -#define WINHTTP_QUERY_AGE 48 -#define WINHTTP_QUERY_CACHE_CONTROL 49 -#define WINHTTP_QUERY_CONTENT_BASE 50 -#define WINHTTP_QUERY_CONTENT_LOCATION 51 -#define WINHTTP_QUERY_CONTENT_MD5 52 -#define WINHTTP_QUERY_CONTENT_RANGE 53 -#define WINHTTP_QUERY_ETAG 54 -#define WINHTTP_QUERY_HOST 55 -#define WINHTTP_QUERY_IF_MATCH 56 -#define WINHTTP_QUERY_IF_NONE_MATCH 57 -#define WINHTTP_QUERY_IF_RANGE 58 -#define WINHTTP_QUERY_IF_UNMODIFIED_SINCE 59 -#define WINHTTP_QUERY_MAX_FORWARDS 60 -#define WINHTTP_QUERY_PROXY_AUTHORIZATION 61 -#define WINHTTP_QUERY_RANGE 62 -#define WINHTTP_QUERY_TRANSFER_ENCODING 63 -#define WINHTTP_QUERY_UPGRADE 64 -#define WINHTTP_QUERY_VARY 65 -#define WINHTTP_QUERY_VIA 66 -#define WINHTTP_QUERY_WARNING 67 -#define WINHTTP_QUERY_EXPECT 68 -#define WINHTTP_QUERY_PROXY_CONNECTION 69 -#define WINHTTP_QUERY_UNLESS_MODIFIED_SINCE 70 -#define WINHTTP_QUERY_PROXY_SUPPORT 75 -#define WINHTTP_QUERY_AUTHENTICATION_INFO 76 -#define WINHTTP_QUERY_PASSPORT_URLS 77 -#define WINHTTP_QUERY_PASSPORT_CONFIG 78 -#define WINHTTP_QUERY_MAX 78 -#define WINHTTP_QUERY_CUSTOM 65535 -#define WINHTTP_QUERY_FLAG_REQUEST_HEADERS 0x80000000 -#define WINHTTP_QUERY_FLAG_SYSTEMTIME 0x40000000 -#define WINHTTP_QUERY_FLAG_NUMBER 0x20000000 - -/* Callback options */ -#define WINHTTP_CALLBACK_STATUS_RESOLVING_NAME 0x00000001 -#define WINHTTP_CALLBACK_STATUS_NAME_RESOLVED 0x00000002 -#define WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER 0x00000004 -#define WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER 0x00000008 -#define WINHTTP_CALLBACK_STATUS_SENDING_REQUEST 0x00000010 -#define WINHTTP_CALLBACK_STATUS_REQUEST_SENT 0x00000020 -#define WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE 0x00000040 -#define WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED 0x00000080 -#define WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION 0x00000100 -#define WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED 0x00000200 -#define WINHTTP_CALLBACK_STATUS_HANDLE_CREATED 0x00000400 -#define WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING 0x00000800 -#define WINHTTP_CALLBACK_STATUS_DETECTING_PROXY 0x00001000 -#define WINHTTP_CALLBACK_STATUS_REDIRECT 0x00004000 -#define WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE 0x00008000 -#define WINHTTP_CALLBACK_STATUS_SECURE_FAILURE 0x00010000 -#define WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE 0x00020000 -#define WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE 0x00040000 -#define WINHTTP_CALLBACK_STATUS_READ_COMPLETE 0x00080000 -#define WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE 0x00100000 -#define WINHTTP_CALLBACK_STATUS_REQUEST_ERROR 0x00200000 -#define WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE 0x00400000 -#define WINHTTP_CALLBACK_FLAG_RESOLVE_NAME (WINHTTP_CALLBACK_STATUS_RESOLVING_NAME | WINHTTP_CALLBACK_STATUS_NAME_RESOLVED) -#define WINHTTP_CALLBACK_FLAG_CONNECT_TO_SERVER (WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER | WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER) -#define WINHTTP_CALLBACK_FLAG_SEND_REQUEST (WINHTTP_CALLBACK_STATUS_SENDING_REQUEST | WINHTTP_CALLBACK_STATUS_REQUEST_SENT) -#define WINHTTP_CALLBACK_FLAG_RECEIVE_RESPONSE (WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE | WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED) -#define WINHTTP_CALLBACK_FLAG_CLOSE_CONNECTION (WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION | WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED) -#define WINHTTP_CALLBACK_FLAG_HANDLES (WINHTTP_CALLBACK_STATUS_HANDLE_CREATED | WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING) -#define WINHTTP_CALLBACK_FLAG_DETECTING_PROXY WINHTTP_CALLBACK_STATUS_DETECTING_PROXY -#define WINHTTP_CALLBACK_FLAG_REDIRECT WINHTTP_CALLBACK_STATUS_REDIRECT -#define WINHTTP_CALLBACK_FLAG_INTERMEDIATE_RESPONSE WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE -#define WINHTTP_CALLBACK_FLAG_SECURE_FAILURE WINHTTP_CALLBACK_STATUS_SECURE_FAILURE -#define WINHTTP_CALLBACK_FLAG_SENDREQUEST_COMPLETE WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE -#define WINHTTP_CALLBACK_FLAG_HEADERS_AVAILABLE WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE -#define WINHTTP_CALLBACK_FLAG_DATA_AVAILABLE WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE -#define WINHTTP_CALLBACK_FLAG_READ_COMPLETE WINHTTP_CALLBACK_STATUS_READ_COMPLETE -#define WINHTTP_CALLBACK_FLAG_WRITE_COMPLETE WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE -#define WINHTTP_CALLBACK_FLAG_REQUEST_ERROR WINHTTP_CALLBACK_STATUS_REQUEST_ERROR -#define WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS (WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE | WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE \ - | WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE | WINHTTP_CALLBACK_STATUS_READ_COMPLETE \ - | WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE | WINHTTP_CALLBACK_STATUS_REQUEST_ERROR) -#define WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS 0xffffffff -#define WINHTTP_INVALID_STATUS_CALLBACK ((WINHTTP_STATUS_CALLBACK)(-1)) - -#define API_RECEIVE_RESPONSE (1) -#define API_QUERY_DATA_AVAILABLE (2) -#define API_READ_DATA (3) -#define API_WRITE_DATA (4) -#define API_SEND_REQUEST (5) - -#define WINHTTP_HANDLE_TYPE_SESSION 1 -#define WINHTTP_HANDLE_TYPE_CONNECT 2 -#define WINHTTP_HANDLE_TYPE_REQUEST 3 - -#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED 0x00000001 -#define WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT 0x00000002 -#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED 0x00000004 -#define WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA 0x00000008 -#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID 0x00000010 -#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID 0x00000020 -#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE 0x00000040 -#define WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR 0x80000000 - -#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 0x00000008 -#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 0x00000020 -#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 0x00000080 -#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 0x00000200 -#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800 -#define WINHTTP_FLAG_SECURE_PROTOCOL_ALL (WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 | WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1) - -#define WINHTTP_AUTH_SCHEME_BASIC 0x00000001 -#define WINHTTP_AUTH_SCHEME_NTLM 0x00000002 -#define WINHTTP_AUTH_SCHEME_PASSPORT 0x00000004 -#define WINHTTP_AUTH_SCHEME_DIGEST 0x00000008 -#define WINHTTP_AUTH_SCHEME_NEGOTIATE 0x00000010 - -#define WINHTTP_AUTH_TARGET_SERVER 0x00000000 -#define WINHTTP_AUTH_TARGET_PROXY 0x00000001 - -#define WINHTTP_TIME_FORMAT_BUFSIZE 62 - -typedef struct -{ - DWORD dwStructSize; - LPWSTR lpszScheme; - DWORD dwSchemeLength; - INTERNET_SCHEME nScheme; - LPWSTR lpszHostName; - DWORD dwHostNameLength; - INTERNET_PORT nPort; - LPWSTR lpszUserName; - DWORD dwUserNameLength; - LPWSTR lpszPassword; - DWORD dwPasswordLength; - LPWSTR lpszUrlPath; - DWORD dwUrlPathLength; - LPWSTR lpszExtraInfo; - DWORD dwExtraInfoLength; -} URL_COMPONENTS, *LPURL_COMPONENTS; -typedef URL_COMPONENTS URL_COMPONENTSW; -typedef LPURL_COMPONENTS LPURL_COMPONENTSW; - -typedef struct -{ - DWORD_PTR dwResult; - DWORD dwError; -} WINHTTP_ASYNC_RESULT, *LPWINHTTP_ASYNC_RESULT; - -typedef struct -{ - FILETIME ftExpiry; - FILETIME ftStart; - LPWSTR lpszSubjectInfo; - LPWSTR lpszIssuerInfo; - LPWSTR lpszProtocolName; - LPWSTR lpszSignatureAlgName; - LPWSTR lpszEncryptionAlgName; - DWORD dwKeySize; -} WINHTTP_CERTIFICATE_INFO; - -typedef struct -{ - DWORD dwAccessType; - LPWSTR lpszProxy; - LPWSTR lpszProxyBypass; -} WINHTTP_PROXY_INFO, *LPWINHTTP_PROXY_INFO; -typedef WINHTTP_PROXY_INFO WINHTTP_PROXY_INFOW; -typedef LPWINHTTP_PROXY_INFO LPWINHTTP_PROXY_INFOW; - -typedef struct -{ - BOOL fAutoDetect; - LPWSTR lpszAutoConfigUrl; - LPWSTR lpszProxy; - LPWSTR lpszProxyBypass; -} WINHTTP_CURRENT_USER_IE_PROXY_CONFIG; - -typedef VOID (CALLBACK *WINHTTP_STATUS_CALLBACK)(HINTERNET,DWORD_PTR,DWORD,LPVOID,DWORD); - -#define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001 -#define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002 - -#define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001 -#define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002 -#define WINHTTP_AUTOPROXY_RUN_INPROCESS 0x00010000 -#define WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY 0x00020000 - -typedef struct -{ - DWORD dwFlags; - DWORD dwAutoDetectFlags; - LPCWSTR lpszAutoConfigUrl; - LPVOID lpvReserved; - DWORD dwReserved; - BOOL fAutoLogonIfChallenged; -} WINHTTP_AUTOPROXY_OPTIONS; - -typedef struct -{ - DWORD dwMajorVersion; - DWORD dwMinorVersion; -} HTTP_VERSION_INFO, *LPHTTP_VERSION_INFO; - -#ifdef _WS2DEF_ -typedef struct -{ - DWORD cbSize; - SOCKADDR_STORAGE LocalAddress; - SOCKADDR_STORAGE RemoteAddress; -} WINHTTP_CONNECTION_INFO; -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -BOOL WINAPI WinHttpAddRequestHeaders(HINTERNET,LPCWSTR,DWORD,DWORD); -BOOL WINAPI WinHttpDetectAutoProxyConfigUrl(DWORD,LPWSTR*); -BOOL WINAPI WinHttpCheckPlatform(void); -BOOL WINAPI WinHttpCloseHandle(HINTERNET); -HINTERNET WINAPI WinHttpConnect(HINTERNET,LPCWSTR,INTERNET_PORT,DWORD); -BOOL WINAPI WinHttpCrackUrl(LPCWSTR,DWORD,DWORD,LPURL_COMPONENTS); -BOOL WINAPI WinHttpCreateUrl(LPURL_COMPONENTS,DWORD,LPWSTR,LPDWORD); -BOOL WINAPI WinHttpGetDefaultProxyConfiguration(WINHTTP_PROXY_INFO*); -BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG*); -BOOL WINAPI WinHttpGetProxyForUrl(HINTERNET,LPCWSTR,WINHTTP_AUTOPROXY_OPTIONS*,WINHTTP_PROXY_INFO*); -HINTERNET WINAPI WinHttpOpen(LPCWSTR,DWORD,LPCWSTR,LPCWSTR,DWORD); -HINTERNET WINAPI WinHttpOpenRequest(HINTERNET,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR*,DWORD); -BOOL WINAPI WinHttpQueryAuthParams(HINTERNET,DWORD,LPVOID*); -BOOL WINAPI WinHttpQueryAuthSchemes(HINTERNET,LPDWORD,LPDWORD,LPDWORD); -BOOL WINAPI WinHttpQueryDataAvailable(HINTERNET,LPDWORD); -BOOL WINAPI WinHttpQueryHeaders(HINTERNET,DWORD,LPCWSTR,LPVOID,LPDWORD,LPDWORD); -BOOL WINAPI WinHttpQueryOption(HINTERNET,DWORD,LPVOID,LPDWORD); -BOOL WINAPI WinHttpReadData(HINTERNET,LPVOID,DWORD,LPDWORD); -BOOL WINAPI WinHttpReceiveResponse(HINTERNET,LPVOID); -BOOL WINAPI WinHttpSendRequest(HINTERNET,LPCWSTR,DWORD,LPVOID,DWORD,DWORD,DWORD_PTR); -BOOL WINAPI WinHttpSetDefaultProxyConfiguration(WINHTTP_PROXY_INFO*); -BOOL WINAPI WinHttpSetCredentials(HINTERNET,DWORD,DWORD,LPCWSTR,LPCWSTR,LPVOID); -BOOL WINAPI WinHttpSetOption(HINTERNET,DWORD,LPVOID,DWORD); -WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback(HINTERNET,WINHTTP_STATUS_CALLBACK,DWORD,DWORD_PTR); -BOOL WINAPI WinHttpSetTimeouts(HINTERNET,int,int,int,int); -BOOL WINAPI WinHttpTimeFromSystemTime(const SYSTEMTIME *,LPWSTR); -BOOL WINAPI WinHttpTimeToSystemTime(LPCWSTR,SYSTEMTIME*); -BOOL WINAPI WinHttpWriteData(HINTERNET,LPCVOID,DWORD,LPDWORD); - -#ifdef __cplusplus -} -#endif - -#include - -#endif /* __WINE_WINHTTP_H */ - -#else - -#include_next - -#endif diff --git a/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp64.def b/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp64.def deleted file mode 100644 index bfad3a0..0000000 --- a/vendor/libgit2-sys/libgit2/deps/winhttp/winhttp64.def +++ /dev/null @@ -1,29 +0,0 @@ -LIBRARY WINHTTP -EXPORTS -WinHttpAddRequestHeaders -WinHttpCheckPlatform -WinHttpCloseHandle -WinHttpConnect -WinHttpCrackUrl -WinHttpCreateUrl -WinHttpDetectAutoProxyConfigUrl -WinHttpGetDefaultProxyConfiguration -WinHttpGetIEProxyConfigForCurrentUser -WinHttpGetProxyForUrl -WinHttpOpen -WinHttpOpenRequest -WinHttpQueryAuthSchemes -WinHttpQueryDataAvailable -WinHttpQueryHeaders -WinHttpQueryOption -WinHttpReadData -WinHttpReceiveResponse -WinHttpSendRequest -WinHttpSetCredentials -WinHttpSetDefaultProxyConfiguration -WinHttpSetOption -WinHttpSetStatusCallback -WinHttpSetTimeouts -WinHttpTimeFromSystemTime -WinHttpTimeToSystemTime -WinHttpWriteData diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/CMakeLists.txt b/vendor/libgit2-sys/libgit2/deps/xdiff/CMakeLists.txt deleted file mode 100644 index 82af0fa..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ - -file(GLOB SRC_XDIFF "*.c" "*.h") -list(SORT SRC_XDIFF) - -add_library(xdiff OBJECT ${SRC_XDIFF}) -target_include_directories(xdiff SYSTEM PRIVATE - "${PROJECT_SOURCE_DIR}/include" - "${PROJECT_SOURCE_DIR}/src/util" - "${PROJECT_BINARY_DIR}/gen_headers" - ${LIBGIT2_SYSTEM_INCLUDES} - ${LIBGIT2_DEPENDENCY_INCLUDES}) - -# the xdiff dependency is not (yet) warning-free, disable warnings -# as errors for the xdiff sources until we've sorted them out -if(MSVC) - set_source_files_properties(xdiffi.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xemit.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xhistogram.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xmerge.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xutils.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xpatience.c PROPERTIES COMPILE_FLAGS -WX-) -else() - set_source_files_properties(xdiffi.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter") - set_source_files_properties(xemit.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter") - set_source_files_properties(xhistogram.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") - set_source_files_properties(xutils.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") - set_source_files_properties(xpatience.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") -endif() diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/git-xdiff.h b/vendor/libgit2-sys/libgit2/deps/xdiff/git-xdiff.h deleted file mode 100644 index 1450ab3..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/git-xdiff.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -/* - * This file provides the necessary indirection between xdiff and - * libgit2. libgit2-specific functionality should live here, so - * that git and libgit2 can share a common xdiff implementation. - */ - -#ifndef INCLUDE_git_xdiff_h__ -#define INCLUDE_git_xdiff_h__ - -#include "regexp.h" - -/* Work around C90-conformance issues */ -#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) -# if defined(_MSC_VER) -# define inline __inline -# elif defined(__GNUC__) -# define inline __inline__ -# else -# define inline -# endif -#endif - -#define XDL_UNUSED GIT_UNUSED_ARG - -#define xdl_malloc(x) git__malloc(x) -#define xdl_calloc(n, sz) git__calloc(n, sz) -#define xdl_free(ptr) git__free(ptr) -#define xdl_realloc(ptr, x) git__realloc(ptr, x) - -#define XDL_BUG(msg) GIT_ASSERT(!msg) - -#define xdl_regex_t git_regexp -#define xdl_regmatch_t git_regmatch - -GIT_INLINE(int) xdl_regexec_buf( - const xdl_regex_t *preg, const char *buf, size_t size, - size_t nmatch, xdl_regmatch_t pmatch[], int eflags) -{ - GIT_UNUSED(preg); - GIT_UNUSED(buf); - GIT_UNUSED(size); - GIT_UNUSED(nmatch); - GIT_UNUSED(pmatch); - GIT_UNUSED(eflags); - GIT_ASSERT("not implemented"); - return -1; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xdiff.h b/vendor/libgit2-sys/libgit2/deps/xdiff/xdiff.h deleted file mode 100644 index fb47f63..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xdiff.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#if !defined(XDIFF_H) -#define XDIFF_H - -#ifdef __cplusplus -extern "C" { -#endif /* #ifdef __cplusplus */ - -#include "git-xdiff.h" - -/* xpparm_t.flags */ -#define XDF_NEED_MINIMAL (1 << 0) - -#define XDF_IGNORE_WHITESPACE (1 << 1) -#define XDF_IGNORE_WHITESPACE_CHANGE (1 << 2) -#define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 3) -#define XDF_IGNORE_CR_AT_EOL (1 << 4) -#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | \ - XDF_IGNORE_WHITESPACE_CHANGE | \ - XDF_IGNORE_WHITESPACE_AT_EOL | \ - XDF_IGNORE_CR_AT_EOL) - -#define XDF_IGNORE_BLANK_LINES (1 << 7) - -#define XDF_PATIENCE_DIFF (1 << 14) -#define XDF_HISTOGRAM_DIFF (1 << 15) -#define XDF_DIFF_ALGORITHM_MASK (XDF_PATIENCE_DIFF | XDF_HISTOGRAM_DIFF) -#define XDF_DIFF_ALG(x) ((x) & XDF_DIFF_ALGORITHM_MASK) - -#define XDF_INDENT_HEURISTIC (1 << 23) - -/* xdemitconf_t.flags */ -#define XDL_EMIT_FUNCNAMES (1 << 0) -#define XDL_EMIT_NO_HUNK_HDR (1 << 1) -#define XDL_EMIT_FUNCCONTEXT (1 << 2) - -/* merge simplification levels */ -#define XDL_MERGE_MINIMAL 0 -#define XDL_MERGE_EAGER 1 -#define XDL_MERGE_ZEALOUS 2 -#define XDL_MERGE_ZEALOUS_ALNUM 3 - -/* merge favor modes */ -#define XDL_MERGE_FAVOR_OURS 1 -#define XDL_MERGE_FAVOR_THEIRS 2 -#define XDL_MERGE_FAVOR_UNION 3 - -/* merge output styles */ -#define XDL_MERGE_DIFF3 1 -#define XDL_MERGE_ZEALOUS_DIFF3 2 - -typedef struct s_mmfile { - char *ptr; - long size; -} mmfile_t; - -typedef struct s_mmbuffer { - char *ptr; - long size; -} mmbuffer_t; - -typedef struct s_xpparam { - unsigned long flags; - - /* -I */ - xdl_regex_t **ignore_regex; - size_t ignore_regex_nr; - - /* See Documentation/diff-options.txt. */ - char **anchors; - size_t anchors_nr; -} xpparam_t; - -typedef struct s_xdemitcb { - void *priv; - int (*out_hunk)(void *, - long old_begin, long old_nr, - long new_begin, long new_nr, - const char *func, long funclen); - int (*out_line)(void *, mmbuffer_t *, int); -} xdemitcb_t; - -typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv); - -typedef int (*xdl_emit_hunk_consume_func_t)(long start_a, long count_a, - long start_b, long count_b, - void *cb_data); - -typedef struct s_xdemitconf { - long ctxlen; - long interhunkctxlen; - unsigned long flags; - find_func_t find_func; - void *find_func_priv; - xdl_emit_hunk_consume_func_t hunk_func; -} xdemitconf_t; - -typedef struct s_bdiffparam { - long bsize; -} bdiffparam_t; - - -void *xdl_mmfile_first(mmfile_t *mmf, long *size); -long xdl_mmfile_size(mmfile_t *mmf); - -int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, - xdemitconf_t const *xecfg, xdemitcb_t *ecb); - -typedef struct s_xmparam { - xpparam_t xpp; - int marker_size; - int level; - int favor; - int style; - const char *ancestor; /* label for orig */ - const char *file1; /* label for mf1 */ - const char *file2; /* label for mf2 */ -} xmparam_t; - -#define DEFAULT_CONFLICT_MARKER_SIZE 7 - -int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2, - xmparam_t const *xmp, mmbuffer_t *result); - -#ifdef __cplusplus -} -#endif /* #ifdef __cplusplus */ - -#endif /* #if !defined(XDIFF_H) */ diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xdiffi.c b/vendor/libgit2-sys/libgit2/deps/xdiff/xdiffi.c deleted file mode 100644 index ea36143..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xdiffi.c +++ /dev/null @@ -1,1089 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#include "xinclude.h" - -#define XDL_MAX_COST_MIN 256 -#define XDL_HEUR_MIN_COST 256 -#define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1) -#define XDL_SNAKE_CNT 20 -#define XDL_K_HEUR 4 - -typedef struct s_xdpsplit { - long i1, i2; - int min_lo, min_hi; -} xdpsplit_t; - -/* - * See "An O(ND) Difference Algorithm and its Variations", by Eugene Myers. - * Basically considers a "box" (off1, off2, lim1, lim2) and scan from both - * the forward diagonal starting from (off1, off2) and the backward diagonal - * starting from (lim1, lim2). If the K values on the same diagonal crosses - * returns the furthest point of reach. We might encounter expensive edge cases - * using this algorithm, so a little bit of heuristic is needed to cut the - * search and to return a suboptimal point. - */ -static long xdl_split(unsigned long const *ha1, long off1, long lim1, - unsigned long const *ha2, long off2, long lim2, - long *kvdf, long *kvdb, int need_min, xdpsplit_t *spl, - xdalgoenv_t *xenv) { - long dmin = off1 - lim2, dmax = lim1 - off2; - long fmid = off1 - off2, bmid = lim1 - lim2; - long odd = (fmid - bmid) & 1; - long fmin = fmid, fmax = fmid; - long bmin = bmid, bmax = bmid; - long ec, d, i1, i2, prev1, best, dd, v, k; - - /* - * Set initial diagonal values for both forward and backward path. - */ - kvdf[fmid] = off1; - kvdb[bmid] = lim1; - - for (ec = 1;; ec++) { - int got_snake = 0; - - /* - * We need to extend the diagonal "domain" by one. If the next - * values exits the box boundaries we need to change it in the - * opposite direction because (max - min) must be a power of - * two. - * - * Also we initialize the external K value to -1 so that we can - * avoid extra conditions in the check inside the core loop. - */ - if (fmin > dmin) - kvdf[--fmin - 1] = -1; - else - ++fmin; - if (fmax < dmax) - kvdf[++fmax + 1] = -1; - else - --fmax; - - for (d = fmax; d >= fmin; d -= 2) { - if (kvdf[d - 1] >= kvdf[d + 1]) - i1 = kvdf[d - 1] + 1; - else - i1 = kvdf[d + 1]; - prev1 = i1; - i2 = i1 - d; - for (; i1 < lim1 && i2 < lim2 && ha1[i1] == ha2[i2]; i1++, i2++); - if (i1 - prev1 > xenv->snake_cnt) - got_snake = 1; - kvdf[d] = i1; - if (odd && bmin <= d && d <= bmax && kvdb[d] <= i1) { - spl->i1 = i1; - spl->i2 = i2; - spl->min_lo = spl->min_hi = 1; - return ec; - } - } - - /* - * We need to extend the diagonal "domain" by one. If the next - * values exits the box boundaries we need to change it in the - * opposite direction because (max - min) must be a power of - * two. - * - * Also we initialize the external K value to -1 so that we can - * avoid extra conditions in the check inside the core loop. - */ - if (bmin > dmin) - kvdb[--bmin - 1] = XDL_LINE_MAX; - else - ++bmin; - if (bmax < dmax) - kvdb[++bmax + 1] = XDL_LINE_MAX; - else - --bmax; - - for (d = bmax; d >= bmin; d -= 2) { - if (kvdb[d - 1] < kvdb[d + 1]) - i1 = kvdb[d - 1]; - else - i1 = kvdb[d + 1] - 1; - prev1 = i1; - i2 = i1 - d; - for (; i1 > off1 && i2 > off2 && ha1[i1 - 1] == ha2[i2 - 1]; i1--, i2--); - if (prev1 - i1 > xenv->snake_cnt) - got_snake = 1; - kvdb[d] = i1; - if (!odd && fmin <= d && d <= fmax && i1 <= kvdf[d]) { - spl->i1 = i1; - spl->i2 = i2; - spl->min_lo = spl->min_hi = 1; - return ec; - } - } - - if (need_min) - continue; - - /* - * If the edit cost is above the heuristic trigger and if - * we got a good snake, we sample current diagonals to see - * if some of them have reached an "interesting" path. Our - * measure is a function of the distance from the diagonal - * corner (i1 + i2) penalized with the distance from the - * mid diagonal itself. If this value is above the current - * edit cost times a magic factor (XDL_K_HEUR) we consider - * it interesting. - */ - if (got_snake && ec > xenv->heur_min) { - for (best = 0, d = fmax; d >= fmin; d -= 2) { - dd = d > fmid ? d - fmid: fmid - d; - i1 = kvdf[d]; - i2 = i1 - d; - v = (i1 - off1) + (i2 - off2) - dd; - - if (v > XDL_K_HEUR * ec && v > best && - off1 + xenv->snake_cnt <= i1 && i1 < lim1 && - off2 + xenv->snake_cnt <= i2 && i2 < lim2) { - for (k = 1; ha1[i1 - k] == ha2[i2 - k]; k++) - if (k == xenv->snake_cnt) { - best = v; - spl->i1 = i1; - spl->i2 = i2; - break; - } - } - } - if (best > 0) { - spl->min_lo = 1; - spl->min_hi = 0; - return ec; - } - - for (best = 0, d = bmax; d >= bmin; d -= 2) { - dd = d > bmid ? d - bmid: bmid - d; - i1 = kvdb[d]; - i2 = i1 - d; - v = (lim1 - i1) + (lim2 - i2) - dd; - - if (v > XDL_K_HEUR * ec && v > best && - off1 < i1 && i1 <= lim1 - xenv->snake_cnt && - off2 < i2 && i2 <= lim2 - xenv->snake_cnt) { - for (k = 0; ha1[i1 + k] == ha2[i2 + k]; k++) - if (k == xenv->snake_cnt - 1) { - best = v; - spl->i1 = i1; - spl->i2 = i2; - break; - } - } - } - if (best > 0) { - spl->min_lo = 0; - spl->min_hi = 1; - return ec; - } - } - - /* - * Enough is enough. We spent too much time here and now we - * collect the furthest reaching path using the (i1 + i2) - * measure. - */ - if (ec >= xenv->mxcost) { - long fbest, fbest1, bbest, bbest1; - - fbest = fbest1 = -1; - for (d = fmax; d >= fmin; d -= 2) { - i1 = XDL_MIN(kvdf[d], lim1); - i2 = i1 - d; - if (lim2 < i2) - i1 = lim2 + d, i2 = lim2; - if (fbest < i1 + i2) { - fbest = i1 + i2; - fbest1 = i1; - } - } - - bbest = bbest1 = XDL_LINE_MAX; - for (d = bmax; d >= bmin; d -= 2) { - i1 = XDL_MAX(off1, kvdb[d]); - i2 = i1 - d; - if (i2 < off2) - i1 = off2 + d, i2 = off2; - if (i1 + i2 < bbest) { - bbest = i1 + i2; - bbest1 = i1; - } - } - - if ((lim1 + lim2) - bbest < fbest - (off1 + off2)) { - spl->i1 = fbest1; - spl->i2 = fbest - fbest1; - spl->min_lo = 1; - spl->min_hi = 0; - } else { - spl->i1 = bbest1; - spl->i2 = bbest - bbest1; - spl->min_lo = 0; - spl->min_hi = 1; - } - return ec; - } - } -} - - -/* - * Rule: "Divide et Impera" (divide & conquer). Recursively split the box in - * sub-boxes by calling the box splitting function. Note that the real job - * (marking changed lines) is done in the two boundary reaching checks. - */ -int xdl_recs_cmp(diffdata_t *dd1, long off1, long lim1, - diffdata_t *dd2, long off2, long lim2, - long *kvdf, long *kvdb, int need_min, xdalgoenv_t *xenv) { - unsigned long const *ha1 = dd1->ha, *ha2 = dd2->ha; - - /* - * Shrink the box by walking through each diagonal snake (SW and NE). - */ - for (; off1 < lim1 && off2 < lim2 && ha1[off1] == ha2[off2]; off1++, off2++); - for (; off1 < lim1 && off2 < lim2 && ha1[lim1 - 1] == ha2[lim2 - 1]; lim1--, lim2--); - - /* - * If one dimension is empty, then all records on the other one must - * be obviously changed. - */ - if (off1 == lim1) { - char *rchg2 = dd2->rchg; - long *rindex2 = dd2->rindex; - - for (; off2 < lim2; off2++) - rchg2[rindex2[off2]] = 1; - } else if (off2 == lim2) { - char *rchg1 = dd1->rchg; - long *rindex1 = dd1->rindex; - - for (; off1 < lim1; off1++) - rchg1[rindex1[off1]] = 1; - } else { - xdpsplit_t spl; - spl.i1 = spl.i2 = 0; - - /* - * Divide ... - */ - if (xdl_split(ha1, off1, lim1, ha2, off2, lim2, kvdf, kvdb, - need_min, &spl, xenv) < 0) { - - return -1; - } - - /* - * ... et Impera. - */ - if (xdl_recs_cmp(dd1, off1, spl.i1, dd2, off2, spl.i2, - kvdf, kvdb, spl.min_lo, xenv) < 0 || - xdl_recs_cmp(dd1, spl.i1, lim1, dd2, spl.i2, lim2, - kvdf, kvdb, spl.min_hi, xenv) < 0) { - - return -1; - } - } - - return 0; -} - - -int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, - xdfenv_t *xe) { - long ndiags; - long *kvd, *kvdf, *kvdb; - xdalgoenv_t xenv; - diffdata_t dd1, dd2; - int res; - - if (xdl_prepare_env(mf1, mf2, xpp, xe) < 0) - return -1; - - if (XDF_DIFF_ALG(xpp->flags) == XDF_PATIENCE_DIFF) { - res = xdl_do_patience_diff(xpp, xe); - goto out; - } - - if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF) { - res = xdl_do_histogram_diff(xpp, xe); - goto out; - } - - /* - * Allocate and setup K vectors to be used by the differential - * algorithm. - * - * One is to store the forward path and one to store the backward path. - */ - ndiags = xe->xdf1.nreff + xe->xdf2.nreff + 3; - if (!XDL_ALLOC_ARRAY(kvd, 2 * ndiags + 2)) { - - xdl_free_env(xe); - return -1; - } - kvdf = kvd; - kvdb = kvdf + ndiags; - kvdf += xe->xdf2.nreff + 1; - kvdb += xe->xdf2.nreff + 1; - - xenv.mxcost = xdl_bogosqrt(ndiags); - if (xenv.mxcost < XDL_MAX_COST_MIN) - xenv.mxcost = XDL_MAX_COST_MIN; - xenv.snake_cnt = XDL_SNAKE_CNT; - xenv.heur_min = XDL_HEUR_MIN_COST; - - dd1.nrec = xe->xdf1.nreff; - dd1.ha = xe->xdf1.ha; - dd1.rchg = xe->xdf1.rchg; - dd1.rindex = xe->xdf1.rindex; - dd2.nrec = xe->xdf2.nreff; - dd2.ha = xe->xdf2.ha; - dd2.rchg = xe->xdf2.rchg; - dd2.rindex = xe->xdf2.rindex; - - res = xdl_recs_cmp(&dd1, 0, dd1.nrec, &dd2, 0, dd2.nrec, - kvdf, kvdb, (xpp->flags & XDF_NEED_MINIMAL) != 0, - &xenv); - xdl_free(kvd); - out: - if (res < 0) - xdl_free_env(xe); - - return res; -} - - -static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, long chg2) { - xdchange_t *xch; - - if (!(xch = (xdchange_t *) xdl_malloc(sizeof(xdchange_t)))) - return NULL; - - xch->next = xscr; - xch->i1 = i1; - xch->i2 = i2; - xch->chg1 = chg1; - xch->chg2 = chg2; - xch->ignore = 0; - - return xch; -} - - -static int recs_match(xrecord_t *rec1, xrecord_t *rec2) -{ - return (rec1->ha == rec2->ha); -} - -/* - * If a line is indented more than this, get_indent() just returns this value. - * This avoids having to do absurd amounts of work for data that are not - * human-readable text, and also ensures that the output of get_indent fits - * within an int. - */ -#define MAX_INDENT 200 - -/* - * Return the amount of indentation of the specified line, treating TAB as 8 - * columns. Return -1 if line is empty or contains only whitespace. Clamp the - * output value at MAX_INDENT. - */ -static int get_indent(xrecord_t *rec) -{ - long i; - int ret = 0; - - for (i = 0; i < rec->size; i++) { - char c = rec->ptr[i]; - - if (!XDL_ISSPACE(c)) - return ret; - else if (c == ' ') - ret += 1; - else if (c == '\t') - ret += 8 - ret % 8; - /* ignore other whitespace characters */ - - if (ret >= MAX_INDENT) - return MAX_INDENT; - } - - /* The line contains only whitespace. */ - return -1; -} - -/* - * If more than this number of consecutive blank rows are found, just return - * this value. This avoids requiring O(N^2) work for pathological cases, and - * also ensures that the output of score_split fits in an int. - */ -#define MAX_BLANKS 20 - -/* Characteristics measured about a hypothetical split position. */ -struct split_measurement { - /* - * Is the split at the end of the file (aside from any blank lines)? - */ - int end_of_file; - - /* - * How much is the line immediately following the split indented (or -1 - * if the line is blank): - */ - int indent; - - /* - * How many consecutive lines above the split are blank? - */ - int pre_blank; - - /* - * How much is the nearest non-blank line above the split indented (or - * -1 if there is no such line)? - */ - int pre_indent; - - /* - * How many lines after the line following the split are blank? - */ - int post_blank; - - /* - * How much is the nearest non-blank line after the line following the - * split indented (or -1 if there is no such line)? - */ - int post_indent; -}; - -struct split_score { - /* The effective indent of this split (smaller is preferred). */ - int effective_indent; - - /* Penalty for this split (smaller is preferred). */ - int penalty; -}; - -/* - * Fill m with information about a hypothetical split of xdf above line split. - */ -static void measure_split(const xdfile_t *xdf, long split, - struct split_measurement *m) -{ - long i; - - if (split >= xdf->nrec) { - m->end_of_file = 1; - m->indent = -1; - } else { - m->end_of_file = 0; - m->indent = get_indent(xdf->recs[split]); - } - - m->pre_blank = 0; - m->pre_indent = -1; - for (i = split - 1; i >= 0; i--) { - m->pre_indent = get_indent(xdf->recs[i]); - if (m->pre_indent != -1) - break; - m->pre_blank += 1; - if (m->pre_blank == MAX_BLANKS) { - m->pre_indent = 0; - break; - } - } - - m->post_blank = 0; - m->post_indent = -1; - for (i = split + 1; i < xdf->nrec; i++) { - m->post_indent = get_indent(xdf->recs[i]); - if (m->post_indent != -1) - break; - m->post_blank += 1; - if (m->post_blank == MAX_BLANKS) { - m->post_indent = 0; - break; - } - } -} - -/* - * The empirically-determined weight factors used by score_split() below. - * Larger values means that the position is a less favorable place to split. - * - * Note that scores are only ever compared against each other, so multiplying - * all of these weight/penalty values by the same factor wouldn't change the - * heuristic's behavior. Still, we need to set that arbitrary scale *somehow*. - * In practice, these numbers are chosen to be large enough that they can be - * adjusted relative to each other with sufficient precision despite using - * integer math. - */ - -/* Penalty if there are no non-blank lines before the split */ -#define START_OF_FILE_PENALTY 1 - -/* Penalty if there are no non-blank lines after the split */ -#define END_OF_FILE_PENALTY 21 - -/* Multiplier for the number of blank lines around the split */ -#define TOTAL_BLANK_WEIGHT (-30) - -/* Multiplier for the number of blank lines after the split */ -#define POST_BLANK_WEIGHT 6 - -/* - * Penalties applied if the line is indented more than its predecessor - */ -#define RELATIVE_INDENT_PENALTY (-4) -#define RELATIVE_INDENT_WITH_BLANK_PENALTY 10 - -/* - * Penalties applied if the line is indented less than both its predecessor and - * its successor - */ -#define RELATIVE_OUTDENT_PENALTY 24 -#define RELATIVE_OUTDENT_WITH_BLANK_PENALTY 17 - -/* - * Penalties applied if the line is indented less than its predecessor but not - * less than its successor - */ -#define RELATIVE_DEDENT_PENALTY 23 -#define RELATIVE_DEDENT_WITH_BLANK_PENALTY 17 - -/* - * We only consider whether the sum of the effective indents for splits are - * less than (-1), equal to (0), or greater than (+1) each other. The resulting - * value is multiplied by the following weight and combined with the penalty to - * determine the better of two scores. - */ -#define INDENT_WEIGHT 60 - -/* - * How far do we slide a hunk at most? - */ -#define INDENT_HEURISTIC_MAX_SLIDING 100 - -/* - * Compute a badness score for the hypothetical split whose measurements are - * stored in m. The weight factors were determined empirically using the tools - * and corpus described in - * - * https://github.com/mhagger/diff-slider-tools - * - * Also see that project if you want to improve the weights based on, for - * example, a larger or more diverse corpus. - */ -static void score_add_split(const struct split_measurement *m, struct split_score *s) -{ - /* - * A place to accumulate penalty factors (positive makes this index more - * favored): - */ - int post_blank, total_blank, indent, any_blanks; - - if (m->pre_indent == -1 && m->pre_blank == 0) - s->penalty += START_OF_FILE_PENALTY; - - if (m->end_of_file) - s->penalty += END_OF_FILE_PENALTY; - - /* - * Set post_blank to the number of blank lines following the split, - * including the line immediately after the split: - */ - post_blank = (m->indent == -1) ? 1 + m->post_blank : 0; - total_blank = m->pre_blank + post_blank; - - /* Penalties based on nearby blank lines: */ - s->penalty += TOTAL_BLANK_WEIGHT * total_blank; - s->penalty += POST_BLANK_WEIGHT * post_blank; - - if (m->indent != -1) - indent = m->indent; - else - indent = m->post_indent; - - any_blanks = (total_blank != 0); - - /* Note that the effective indent is -1 at the end of the file: */ - s->effective_indent += indent; - - if (indent == -1) { - /* No additional adjustments needed. */ - } else if (m->pre_indent == -1) { - /* No additional adjustments needed. */ - } else if (indent > m->pre_indent) { - /* - * The line is indented more than its predecessor. - */ - s->penalty += any_blanks ? - RELATIVE_INDENT_WITH_BLANK_PENALTY : - RELATIVE_INDENT_PENALTY; - } else if (indent == m->pre_indent) { - /* - * The line has the same indentation level as its predecessor. - * No additional adjustments needed. - */ - } else { - /* - * The line is indented less than its predecessor. It could be - * the block terminator of the previous block, but it could - * also be the start of a new block (e.g., an "else" block, or - * maybe the previous block didn't have a block terminator). - * Try to distinguish those cases based on what comes next: - */ - if (m->post_indent != -1 && m->post_indent > indent) { - /* - * The following line is indented more. So it is likely - * that this line is the start of a block. - */ - s->penalty += any_blanks ? - RELATIVE_OUTDENT_WITH_BLANK_PENALTY : - RELATIVE_OUTDENT_PENALTY; - } else { - /* - * That was probably the end of a block. - */ - s->penalty += any_blanks ? - RELATIVE_DEDENT_WITH_BLANK_PENALTY : - RELATIVE_DEDENT_PENALTY; - } - } -} - -static int score_cmp(struct split_score *s1, struct split_score *s2) -{ - /* -1 if s1.effective_indent < s2->effective_indent, etc. */ - int cmp_indents = ((s1->effective_indent > s2->effective_indent) - - (s1->effective_indent < s2->effective_indent)); - - return INDENT_WEIGHT * cmp_indents + (s1->penalty - s2->penalty); -} - -/* - * Represent a group of changed lines in an xdfile_t (i.e., a contiguous group - * of lines that was inserted or deleted from the corresponding version of the - * file). We consider there to be such a group at the beginning of the file, at - * the end of the file, and between any two unchanged lines, though most such - * groups will usually be empty. - * - * If the first line in a group is equal to the line following the group, then - * the group can be slid down. Similarly, if the last line in a group is equal - * to the line preceding the group, then the group can be slid up. See - * group_slide_down() and group_slide_up(). - * - * Note that loops that are testing for changed lines in xdf->rchg do not need - * index bounding since the array is prepared with a zero at position -1 and N. - */ -struct xdlgroup { - /* - * The index of the first changed line in the group, or the index of - * the unchanged line above which the (empty) group is located. - */ - long start; - - /* - * The index of the first unchanged line after the group. For an empty - * group, end is equal to start. - */ - long end; -}; - -/* - * Initialize g to point at the first group in xdf. - */ -static void group_init(xdfile_t *xdf, struct xdlgroup *g) -{ - g->start = g->end = 0; - while (xdf->rchg[g->end]) - g->end++; -} - -/* - * Move g to describe the next (possibly empty) group in xdf and return 0. If g - * is already at the end of the file, do nothing and return -1. - */ -static inline int group_next(xdfile_t *xdf, struct xdlgroup *g) -{ - if (g->end == xdf->nrec) - return -1; - - g->start = g->end + 1; - for (g->end = g->start; xdf->rchg[g->end]; g->end++) - ; - - return 0; -} - -/* - * Move g to describe the previous (possibly empty) group in xdf and return 0. - * If g is already at the beginning of the file, do nothing and return -1. - */ -static inline int group_previous(xdfile_t *xdf, struct xdlgroup *g) -{ - if (g->start == 0) - return -1; - - g->end = g->start - 1; - for (g->start = g->end; xdf->rchg[g->start - 1]; g->start--) - ; - - return 0; -} - -/* - * If g can be slid toward the end of the file, do so, and if it bumps into a - * following group, expand this group to include it. Return 0 on success or -1 - * if g cannot be slid down. - */ -static int group_slide_down(xdfile_t *xdf, struct xdlgroup *g) -{ - if (g->end < xdf->nrec && - recs_match(xdf->recs[g->start], xdf->recs[g->end])) { - xdf->rchg[g->start++] = 0; - xdf->rchg[g->end++] = 1; - - while (xdf->rchg[g->end]) - g->end++; - - return 0; - } else { - return -1; - } -} - -/* - * If g can be slid toward the beginning of the file, do so, and if it bumps - * into a previous group, expand this group to include it. Return 0 on success - * or -1 if g cannot be slid up. - */ -static int group_slide_up(xdfile_t *xdf, struct xdlgroup *g) -{ - if (g->start > 0 && - recs_match(xdf->recs[g->start - 1], xdf->recs[g->end - 1])) { - xdf->rchg[--g->start] = 1; - xdf->rchg[--g->end] = 0; - - while (xdf->rchg[g->start - 1]) - g->start--; - - return 0; - } else { - return -1; - } -} - -/* - * Move back and forward change groups for a consistent and pretty diff output. - * This also helps in finding joinable change groups and reducing the diff - * size. - */ -int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { - struct xdlgroup g, go; - long earliest_end, end_matching_other; - long groupsize; - - group_init(xdf, &g); - group_init(xdfo, &go); - - while (1) { - /* - * If the group is empty in the to-be-compacted file, skip it: - */ - if (g.end == g.start) - goto next; - - /* - * Now shift the change up and then down as far as possible in - * each direction. If it bumps into any other changes, merge - * them. - */ - do { - groupsize = g.end - g.start; - - /* - * Keep track of the last "end" index that causes this - * group to align with a group of changed lines in the - * other file. -1 indicates that we haven't found such - * a match yet: - */ - end_matching_other = -1; - - /* Shift the group backward as much as possible: */ - while (!group_slide_up(xdf, &g)) - if (group_previous(xdfo, &go)) - XDL_BUG("group sync broken sliding up"); - - /* - * This is this highest that this group can be shifted. - * Record its end index: - */ - earliest_end = g.end; - - if (go.end > go.start) - end_matching_other = g.end; - - /* Now shift the group forward as far as possible: */ - while (1) { - if (group_slide_down(xdf, &g)) - break; - if (group_next(xdfo, &go)) - XDL_BUG("group sync broken sliding down"); - - if (go.end > go.start) - end_matching_other = g.end; - } - } while (groupsize != g.end - g.start); - - /* - * If the group can be shifted, then we can possibly use this - * freedom to produce a more intuitive diff. - * - * The group is currently shifted as far down as possible, so - * the heuristics below only have to handle upwards shifts. - */ - - if (g.end == earliest_end) { - /* no shifting was possible */ - } else if (end_matching_other != -1) { - /* - * Move the possibly merged group of changes back to - * line up with the last group of changes from the - * other file that it can align with. - */ - while (go.end == go.start) { - if (group_slide_up(xdf, &g)) - XDL_BUG("match disappeared"); - if (group_previous(xdfo, &go)) - XDL_BUG("group sync broken sliding to match"); - } - } else if (flags & XDF_INDENT_HEURISTIC) { - /* - * Indent heuristic: a group of pure add/delete lines - * implies two splits, one between the end of the - * "before" context and the start of the group, and - * another between the end of the group and the - * beginning of the "after" context. Some splits are - * aesthetically better and some are worse. We compute - * a badness "score" for each split, and add the scores - * for the two splits to define a "score" for each - * position that the group can be shifted to. Then we - * pick the shift with the lowest score. - */ - long shift, best_shift = -1; - struct split_score best_score; - - shift = earliest_end; - if (g.end - groupsize - 1 > shift) - shift = g.end - groupsize - 1; - if (g.end - INDENT_HEURISTIC_MAX_SLIDING > shift) - shift = g.end - INDENT_HEURISTIC_MAX_SLIDING; - for (; shift <= g.end; shift++) { - struct split_measurement m; - struct split_score score = {0, 0}; - - measure_split(xdf, shift, &m); - score_add_split(&m, &score); - measure_split(xdf, shift - groupsize, &m); - score_add_split(&m, &score); - if (best_shift == -1 || - score_cmp(&score, &best_score) <= 0) { - best_score.effective_indent = score.effective_indent; - best_score.penalty = score.penalty; - best_shift = shift; - } - } - - while (g.end > best_shift) { - if (group_slide_up(xdf, &g)) - XDL_BUG("best shift unreached"); - if (group_previous(xdfo, &go)) - XDL_BUG("group sync broken sliding to blank line"); - } - } - - next: - /* Move past the just-processed group: */ - if (group_next(xdf, &g)) - break; - if (group_next(xdfo, &go)) - XDL_BUG("group sync broken moving to next group"); - } - - if (!group_next(xdfo, &go)) - XDL_BUG("group sync broken at end of file"); - - return 0; -} - - -int xdl_build_script(xdfenv_t *xe, xdchange_t **xscr) { - xdchange_t *cscr = NULL, *xch; - char *rchg1 = xe->xdf1.rchg, *rchg2 = xe->xdf2.rchg; - long i1, i2, l1, l2; - - /* - * Trivial. Collects "groups" of changes and creates an edit script. - */ - for (i1 = xe->xdf1.nrec, i2 = xe->xdf2.nrec; i1 >= 0 || i2 >= 0; i1--, i2--) - if (rchg1[i1 - 1] || rchg2[i2 - 1]) { - for (l1 = i1; rchg1[i1 - 1]; i1--); - for (l2 = i2; rchg2[i2 - 1]; i2--); - - if (!(xch = xdl_add_change(cscr, i1, i2, l1 - i1, l2 - i2))) { - xdl_free_script(cscr); - return -1; - } - cscr = xch; - } - - *xscr = cscr; - - return 0; -} - - -void xdl_free_script(xdchange_t *xscr) { - xdchange_t *xch; - - while ((xch = xscr) != NULL) { - xscr = xscr->next; - xdl_free(xch); - } -} - -static int xdl_call_hunk_func(xdfenv_t *xe XDL_UNUSED, xdchange_t *xscr, xdemitcb_t *ecb, - xdemitconf_t const *xecfg) -{ - xdchange_t *xch, *xche; - - for (xch = xscr; xch; xch = xche->next) { - xche = xdl_get_hunk(&xch, xecfg); - if (!xch) - break; - if (xecfg->hunk_func(xch->i1, xche->i1 + xche->chg1 - xch->i1, - xch->i2, xche->i2 + xche->chg2 - xch->i2, - ecb->priv) < 0) - return -1; - } - return 0; -} - -static void xdl_mark_ignorable_lines(xdchange_t *xscr, xdfenv_t *xe, long flags) -{ - xdchange_t *xch; - - for (xch = xscr; xch; xch = xch->next) { - int ignore = 1; - xrecord_t **rec; - long i; - - rec = &xe->xdf1.recs[xch->i1]; - for (i = 0; i < xch->chg1 && ignore; i++) - ignore = xdl_blankline(rec[i]->ptr, rec[i]->size, flags); - - rec = &xe->xdf2.recs[xch->i2]; - for (i = 0; i < xch->chg2 && ignore; i++) - ignore = xdl_blankline(rec[i]->ptr, rec[i]->size, flags); - - xch->ignore = ignore; - } -} - -static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) { - xdl_regmatch_t regmatch; - int i; - - for (i = 0; i < xpp->ignore_regex_nr; i++) - if (!xdl_regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1, - ®match, 0)) - return 1; - - return 0; -} - -static void xdl_mark_ignorable_regex(xdchange_t *xscr, const xdfenv_t *xe, - xpparam_t const *xpp) -{ - xdchange_t *xch; - - for (xch = xscr; xch; xch = xch->next) { - xrecord_t **rec; - int ignore = 1; - long i; - - /* - * Do not override --ignore-blank-lines. - */ - if (xch->ignore) - continue; - - rec = &xe->xdf1.recs[xch->i1]; - for (i = 0; i < xch->chg1 && ignore; i++) - ignore = record_matches_regex(rec[i], xpp); - - rec = &xe->xdf2.recs[xch->i2]; - for (i = 0; i < xch->chg2 && ignore; i++) - ignore = record_matches_regex(rec[i], xpp); - - xch->ignore = ignore; - } -} - -int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, - xdemitconf_t const *xecfg, xdemitcb_t *ecb) { - xdchange_t *xscr; - xdfenv_t xe; - emit_func_t ef = xecfg->hunk_func ? xdl_call_hunk_func : xdl_emit_diff; - - if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) { - - return -1; - } - if (xdl_change_compact(&xe.xdf1, &xe.xdf2, xpp->flags) < 0 || - xdl_change_compact(&xe.xdf2, &xe.xdf1, xpp->flags) < 0 || - xdl_build_script(&xe, &xscr) < 0) { - - xdl_free_env(&xe); - return -1; - } - if (xscr) { - if (xpp->flags & XDF_IGNORE_BLANK_LINES) - xdl_mark_ignorable_lines(xscr, &xe, xpp->flags); - - if (xpp->ignore_regex) - xdl_mark_ignorable_regex(xscr, &xe, xpp); - - if (ef(&xe, xscr, ecb, xecfg) < 0) { - - xdl_free_script(xscr); - xdl_free_env(&xe); - return -1; - } - xdl_free_script(xscr); - } - xdl_free_env(&xe); - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xdiffi.h b/vendor/libgit2-sys/libgit2/deps/xdiff/xdiffi.h deleted file mode 100644 index 126c9d8..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xdiffi.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#if !defined(XDIFFI_H) -#define XDIFFI_H - - -typedef struct s_diffdata { - long nrec; - unsigned long const *ha; - long *rindex; - char *rchg; -} diffdata_t; - -typedef struct s_xdalgoenv { - long mxcost; - long snake_cnt; - long heur_min; -} xdalgoenv_t; - -typedef struct s_xdchange { - struct s_xdchange *next; - long i1, i2; - long chg1, chg2; - int ignore; -} xdchange_t; - - - -int xdl_recs_cmp(diffdata_t *dd1, long off1, long lim1, - diffdata_t *dd2, long off2, long lim2, - long *kvdf, long *kvdb, int need_min, xdalgoenv_t *xenv); -int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, - xdfenv_t *xe); -int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags); -int xdl_build_script(xdfenv_t *xe, xdchange_t **xscr); -void xdl_free_script(xdchange_t *xscr); -int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, - xdemitconf_t const *xecfg); -int xdl_do_patience_diff(xpparam_t const *xpp, xdfenv_t *env); -int xdl_do_histogram_diff(xpparam_t const *xpp, xdfenv_t *env); - -#endif /* #if !defined(XDIFFI_H) */ diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xemit.c b/vendor/libgit2-sys/libgit2/deps/xdiff/xemit.c deleted file mode 100644 index 75f0fe4..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xemit.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#include "xinclude.h" - -static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec) { - - *rec = xdf->recs[ri]->ptr; - - return xdf->recs[ri]->size; -} - - -static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) { - long size, psize = strlen(pre); - char const *rec; - - size = xdl_get_rec(xdf, ri, &rec); - if (xdl_emit_diffrec(rec, size, pre, psize, ecb) < 0) { - - return -1; - } - - return 0; -} - - -/* - * Starting at the passed change atom, find the latest change atom to be included - * inside the differential hunk according to the specified configuration. - * Also advance xscr if the first changes must be discarded. - */ -xdchange_t *xdl_get_hunk(xdchange_t **xscr, xdemitconf_t const *xecfg) -{ - xdchange_t *xch, *xchp, *lxch; - long max_common = 2 * xecfg->ctxlen + xecfg->interhunkctxlen; - long max_ignorable = xecfg->ctxlen; - unsigned long ignored = 0; /* number of ignored blank lines */ - - /* remove ignorable changes that are too far before other changes */ - for (xchp = *xscr; xchp && xchp->ignore; xchp = xchp->next) { - xch = xchp->next; - - if (xch == NULL || - xch->i1 - (xchp->i1 + xchp->chg1) >= max_ignorable) - *xscr = xch; - } - - if (!*xscr) - return NULL; - - lxch = *xscr; - - for (xchp = *xscr, xch = xchp->next; xch; xchp = xch, xch = xch->next) { - long distance = xch->i1 - (xchp->i1 + xchp->chg1); - if (distance > max_common) - break; - - if (distance < max_ignorable && (!xch->ignore || lxch == xchp)) { - lxch = xch; - ignored = 0; - } else if (distance < max_ignorable && xch->ignore) { - ignored += xch->chg2; - } else if (lxch != xchp && - xch->i1 + ignored - (lxch->i1 + lxch->chg1) > max_common) { - break; - } else if (!xch->ignore) { - lxch = xch; - ignored = 0; - } else { - ignored += xch->chg2; - } - } - - return lxch; -} - - -static long def_ff(const char *rec, long len, char *buf, long sz) -{ - if (len > 0 && - (isalpha((unsigned char)*rec) || /* identifier? */ - *rec == '_' || /* also identifier? */ - *rec == '$')) { /* identifiers from VMS and other esoterico */ - if (len > sz) - len = sz; - while (0 < len && isspace((unsigned char)rec[len - 1])) - len--; - memcpy(buf, rec, len); - return len; - } - return -1; -} - -static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri, - char *buf, long sz) -{ - const char *rec; - long len = xdl_get_rec(xdf, ri, &rec); - if (!xecfg->find_func) - return def_ff(rec, len, buf, sz); - return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv); -} - -static int is_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri) -{ - char dummy[1]; - return match_func_rec(xdf, xecfg, ri, dummy, sizeof(dummy)) >= 0; -} - -struct func_line { - long len; - char buf[80]; -}; - -static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg, - struct func_line *func_line, long start, long limit) -{ - long l, size, step = (start > limit) ? -1 : 1; - char *buf, dummy[1]; - - buf = func_line ? func_line->buf : dummy; - size = func_line ? sizeof(func_line->buf) : sizeof(dummy); - - for (l = start; l != limit && 0 <= l && l < xe->xdf1.nrec; l += step) { - long len = match_func_rec(&xe->xdf1, xecfg, l, buf, size); - if (len >= 0) { - if (func_line) - func_line->len = len; - return l; - } - } - return -1; -} - -static int is_empty_rec(xdfile_t *xdf, long ri) -{ - const char *rec; - long len = xdl_get_rec(xdf, ri, &rec); - - while (len > 0 && XDL_ISSPACE(*rec)) { - rec++; - len--; - } - return !len; -} - -int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, - xdemitconf_t const *xecfg) { - long s1, s2, e1, e2, lctx; - xdchange_t *xch, *xche; - long funclineprev = -1; - struct func_line func_line = { 0 }; - - for (xch = xscr; xch; xch = xche->next) { - xdchange_t *xchp = xch; - xche = xdl_get_hunk(&xch, xecfg); - if (!xch) - break; - -pre_context_calculation: - s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0); - s2 = XDL_MAX(xch->i2 - xecfg->ctxlen, 0); - - if (xecfg->flags & XDL_EMIT_FUNCCONTEXT) { - long fs1, i1 = xch->i1; - - /* Appended chunk? */ - if (i1 >= xe->xdf1.nrec) { - long i2 = xch->i2; - - /* - * We don't need additional context if - * a whole function was added. - */ - while (i2 < xe->xdf2.nrec) { - if (is_func_rec(&xe->xdf2, xecfg, i2)) - goto post_context_calculation; - i2++; - } - - /* - * Otherwise get more context from the - * pre-image. - */ - i1 = xe->xdf1.nrec - 1; - } - - fs1 = get_func_line(xe, xecfg, NULL, i1, -1); - while (fs1 > 0 && !is_empty_rec(&xe->xdf1, fs1 - 1) && - !is_func_rec(&xe->xdf1, xecfg, fs1 - 1)) - fs1--; - if (fs1 < 0) - fs1 = 0; - if (fs1 < s1) { - s2 = XDL_MAX(s2 - (s1 - fs1), 0); - s1 = fs1; - - /* - * Did we extend context upwards into an - * ignored change? - */ - while (xchp != xch && - xchp->i1 + xchp->chg1 <= s1 && - xchp->i2 + xchp->chg2 <= s2) - xchp = xchp->next; - - /* If so, show it after all. */ - if (xchp != xch) { - xch = xchp; - goto pre_context_calculation; - } - } - } - - post_context_calculation: - lctx = xecfg->ctxlen; - lctx = XDL_MIN(lctx, xe->xdf1.nrec - (xche->i1 + xche->chg1)); - lctx = XDL_MIN(lctx, xe->xdf2.nrec - (xche->i2 + xche->chg2)); - - e1 = xche->i1 + xche->chg1 + lctx; - e2 = xche->i2 + xche->chg2 + lctx; - - if (xecfg->flags & XDL_EMIT_FUNCCONTEXT) { - long fe1 = get_func_line(xe, xecfg, NULL, - xche->i1 + xche->chg1, - xe->xdf1.nrec); - while (fe1 > 0 && is_empty_rec(&xe->xdf1, fe1 - 1)) - fe1--; - if (fe1 < 0) - fe1 = xe->xdf1.nrec; - if (fe1 > e1) { - e2 = XDL_MIN(e2 + (fe1 - e1), xe->xdf2.nrec); - e1 = fe1; - } - - /* - * Overlap with next change? Then include it - * in the current hunk and start over to find - * its new end. - */ - if (xche->next) { - long l = XDL_MIN(xche->next->i1, - xe->xdf1.nrec - 1); - if (l - xecfg->ctxlen <= e1 || - get_func_line(xe, xecfg, NULL, l, e1) < 0) { - xche = xche->next; - goto post_context_calculation; - } - } - } - - /* - * Emit current hunk header. - */ - - if (xecfg->flags & XDL_EMIT_FUNCNAMES) { - get_func_line(xe, xecfg, &func_line, - s1 - 1, funclineprev); - funclineprev = s1 - 1; - } - if (!(xecfg->flags & XDL_EMIT_NO_HUNK_HDR) && - xdl_emit_hunk_hdr(s1 + 1, e1 - s1, s2 + 1, e2 - s2, - func_line.buf, func_line.len, ecb) < 0) - return -1; - - /* - * Emit pre-context. - */ - for (; s2 < xch->i2; s2++) - if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0) - return -1; - - for (s1 = xch->i1, s2 = xch->i2;; xch = xch->next) { - /* - * Merge previous with current change atom. - */ - for (; s1 < xch->i1 && s2 < xch->i2; s1++, s2++) - if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0) - return -1; - - /* - * Removes lines from the first file. - */ - for (s1 = xch->i1; s1 < xch->i1 + xch->chg1; s1++) - if (xdl_emit_record(&xe->xdf1, s1, "-", ecb) < 0) - return -1; - - /* - * Adds lines from the second file. - */ - for (s2 = xch->i2; s2 < xch->i2 + xch->chg2; s2++) - if (xdl_emit_record(&xe->xdf2, s2, "+", ecb) < 0) - return -1; - - if (xch == xche) - break; - s1 = xch->i1 + xch->chg1; - s2 = xch->i2 + xch->chg2; - } - - /* - * Emit post-context. - */ - for (s2 = xche->i2 + xche->chg2; s2 < e2; s2++) - if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0) - return -1; - } - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xemit.h b/vendor/libgit2-sys/libgit2/deps/xdiff/xemit.h deleted file mode 100644 index 1b9887e..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xemit.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#if !defined(XEMIT_H) -#define XEMIT_H - - -typedef int (*emit_func_t)(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, - xdemitconf_t const *xecfg); - -xdchange_t *xdl_get_hunk(xdchange_t **xscr, xdemitconf_t const *xecfg); -int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, - xdemitconf_t const *xecfg); - - - -#endif /* #if !defined(XEMIT_H) */ diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xhistogram.c b/vendor/libgit2-sys/libgit2/deps/xdiff/xhistogram.c deleted file mode 100644 index 16a8fe2..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xhistogram.c +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (C) 2010, Google Inc. - * and other copyright owners as documented in JGit's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "xinclude.h" - -#define MAX_PTR UINT_MAX -#define MAX_CNT UINT_MAX - -#define LINE_END(n) (line##n + count##n - 1) -#define LINE_END_PTR(n) (*line##n + *count##n - 1) - -struct histindex { - struct record { - unsigned int ptr, cnt; - struct record *next; - } **records, /* an occurrence */ - **line_map; /* map of line to record chain */ - chastore_t rcha; - unsigned int *next_ptrs; - unsigned int table_bits, - records_size, - line_map_size; - - unsigned int max_chain_length, - key_shift, - ptr_shift; - - unsigned int cnt, - has_common; - - xdfenv_t *env; - xpparam_t const *xpp; -}; - -struct region { - unsigned int begin1, end1; - unsigned int begin2, end2; -}; - -#define LINE_MAP(i, a) (i->line_map[(a) - i->ptr_shift]) - -#define NEXT_PTR(index, ptr) \ - (index->next_ptrs[(ptr) - index->ptr_shift]) - -#define CNT(index, ptr) \ - ((LINE_MAP(index, ptr))->cnt) - -#define REC(env, s, l) \ - (env->xdf##s.recs[l - 1]) - -static int cmp_recs(xrecord_t *r1, xrecord_t *r2) -{ - return r1->ha == r2->ha; - -} - -#define CMP(i, s1, l1, s2, l2) \ - (cmp_recs(REC(i->env, s1, l1), REC(i->env, s2, l2))) - -#define TABLE_HASH(index, side, line) \ - XDL_HASHLONG((REC(index->env, side, line))->ha, index->table_bits) - -static int scanA(struct histindex *index, int line1, int count1) -{ - unsigned int ptr, tbl_idx; - unsigned int chain_len; - struct record **rec_chain, *rec; - - for (ptr = LINE_END(1); line1 <= ptr; ptr--) { - tbl_idx = TABLE_HASH(index, 1, ptr); - rec_chain = index->records + tbl_idx; - rec = *rec_chain; - - chain_len = 0; - while (rec) { - if (CMP(index, 1, rec->ptr, 1, ptr)) { - /* - * ptr is identical to another element. Insert - * it onto the front of the existing element - * chain. - */ - NEXT_PTR(index, ptr) = rec->ptr; - rec->ptr = ptr; - /* cap rec->cnt at MAX_CNT */ - rec->cnt = XDL_MIN(MAX_CNT, rec->cnt + 1); - LINE_MAP(index, ptr) = rec; - goto continue_scan; - } - - rec = rec->next; - chain_len++; - } - - if (chain_len == index->max_chain_length) - return -1; - - /* - * This is the first time we have ever seen this particular - * element in the sequence. Construct a new chain for it. - */ - if (!(rec = xdl_cha_alloc(&index->rcha))) - return -1; - rec->ptr = ptr; - rec->cnt = 1; - rec->next = *rec_chain; - *rec_chain = rec; - LINE_MAP(index, ptr) = rec; - -continue_scan: - ; /* no op */ - } - - return 0; -} - -static int try_lcs(struct histindex *index, struct region *lcs, int b_ptr, - int line1, int count1, int line2, int count2) -{ - unsigned int b_next = b_ptr + 1; - struct record *rec = index->records[TABLE_HASH(index, 2, b_ptr)]; - unsigned int as, ae, bs, be, np, rc; - int should_break; - - for (; rec; rec = rec->next) { - if (rec->cnt > index->cnt) { - if (!index->has_common) - index->has_common = CMP(index, 1, rec->ptr, 2, b_ptr); - continue; - } - - as = rec->ptr; - if (!CMP(index, 1, as, 2, b_ptr)) - continue; - - index->has_common = 1; - for (;;) { - should_break = 0; - np = NEXT_PTR(index, as); - bs = b_ptr; - ae = as; - be = bs; - rc = rec->cnt; - - while (line1 < as && line2 < bs - && CMP(index, 1, as - 1, 2, bs - 1)) { - as--; - bs--; - if (1 < rc) - rc = XDL_MIN(rc, CNT(index, as)); - } - while (ae < LINE_END(1) && be < LINE_END(2) - && CMP(index, 1, ae + 1, 2, be + 1)) { - ae++; - be++; - if (1 < rc) - rc = XDL_MIN(rc, CNT(index, ae)); - } - - if (b_next <= be) - b_next = be + 1; - if (lcs->end1 - lcs->begin1 < ae - as || rc < index->cnt) { - lcs->begin1 = as; - lcs->begin2 = bs; - lcs->end1 = ae; - lcs->end2 = be; - index->cnt = rc; - } - - if (np == 0) - break; - - while (np <= ae) { - np = NEXT_PTR(index, np); - if (np == 0) { - should_break = 1; - break; - } - } - - if (should_break) - break; - - as = np; - } - } - return b_next; -} - -static int fall_back_to_classic_diff(xpparam_t const *xpp, xdfenv_t *env, - int line1, int count1, int line2, int count2) -{ - xpparam_t xpparam; - - memset(&xpparam, 0, sizeof(xpparam)); - xpparam.flags = xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; - - return xdl_fall_back_diff(env, &xpparam, - line1, count1, line2, count2); -} - -static inline void free_index(struct histindex *index) -{ - xdl_free(index->records); - xdl_free(index->line_map); - xdl_free(index->next_ptrs); - xdl_cha_free(&index->rcha); -} - -static int find_lcs(xpparam_t const *xpp, xdfenv_t *env, - struct region *lcs, - int line1, int count1, int line2, int count2) -{ - int b_ptr; - int ret = -1; - struct histindex index; - - memset(&index, 0, sizeof(index)); - - index.env = env; - index.xpp = xpp; - - index.records = NULL; - index.line_map = NULL; - /* in case of early xdl_cha_free() */ - index.rcha.head = NULL; - - index.table_bits = xdl_hashbits(count1); - index.records_size = 1 << index.table_bits; - if (!XDL_CALLOC_ARRAY(index.records, index.records_size)) - goto cleanup; - - index.line_map_size = count1; - if (!XDL_CALLOC_ARRAY(index.line_map, index.line_map_size)) - goto cleanup; - - if (!XDL_CALLOC_ARRAY(index.next_ptrs, index.line_map_size)) - goto cleanup; - - /* lines / 4 + 1 comes from xprepare.c:xdl_prepare_ctx() */ - if (xdl_cha_init(&index.rcha, sizeof(struct record), count1 / 4 + 1) < 0) - goto cleanup; - - index.ptr_shift = line1; - index.max_chain_length = 64; - - if (scanA(&index, line1, count1)) - goto cleanup; - - index.cnt = index.max_chain_length + 1; - - for (b_ptr = line2; b_ptr <= LINE_END(2); ) - b_ptr = try_lcs(&index, lcs, b_ptr, line1, count1, line2, count2); - - if (index.has_common && index.max_chain_length < index.cnt) - ret = 1; - else - ret = 0; - -cleanup: - free_index(&index); - return ret; -} - -static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env, - int line1, int count1, int line2, int count2) -{ - struct region lcs; - int lcs_found; - int result; -redo: - result = -1; - - if (count1 <= 0 && count2 <= 0) - return 0; - - if (LINE_END(1) >= MAX_PTR) - return -1; - - if (!count1) { - while(count2--) - env->xdf2.rchg[line2++ - 1] = 1; - return 0; - } else if (!count2) { - while(count1--) - env->xdf1.rchg[line1++ - 1] = 1; - return 0; - } - - memset(&lcs, 0, sizeof(lcs)); - lcs_found = find_lcs(xpp, env, &lcs, line1, count1, line2, count2); - if (lcs_found < 0) - goto out; - else if (lcs_found) - result = fall_back_to_classic_diff(xpp, env, line1, count1, line2, count2); - else { - if (lcs.begin1 == 0 && lcs.begin2 == 0) { - while (count1--) - env->xdf1.rchg[line1++ - 1] = 1; - while (count2--) - env->xdf2.rchg[line2++ - 1] = 1; - result = 0; - } else { - result = histogram_diff(xpp, env, - line1, lcs.begin1 - line1, - line2, lcs.begin2 - line2); - if (result) - goto out; - /* - * result = histogram_diff(xpp, env, - * lcs.end1 + 1, LINE_END(1) - lcs.end1, - * lcs.end2 + 1, LINE_END(2) - lcs.end2); - * but let's optimize tail recursion ourself: - */ - count1 = LINE_END(1) - lcs.end1; - line1 = lcs.end1 + 1; - count2 = LINE_END(2) - lcs.end2; - line2 = lcs.end2 + 1; - goto redo; - } - } -out: - return result; -} - -int xdl_do_histogram_diff(xpparam_t const *xpp, xdfenv_t *env) -{ - return histogram_diff(xpp, env, - env->xdf1.dstart + 1, env->xdf1.dend - env->xdf1.dstart + 1, - env->xdf2.dstart + 1, env->xdf2.dend - env->xdf2.dstart + 1); -} diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xinclude.h b/vendor/libgit2-sys/libgit2/deps/xdiff/xinclude.h deleted file mode 100644 index 75db1d8..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xinclude.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#if !defined(XINCLUDE_H) -#define XINCLUDE_H - -#include "git-xdiff.h" -#include "xmacros.h" -#include "xdiff.h" -#include "xtypes.h" -#include "xutils.h" -#include "xprepare.h" -#include "xdiffi.h" -#include "xemit.h" - - -#endif /* #if !defined(XINCLUDE_H) */ diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xmacros.h b/vendor/libgit2-sys/libgit2/deps/xdiff/xmacros.h deleted file mode 100644 index 8487bb3..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xmacros.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#if !defined(XMACROS_H) -#define XMACROS_H - - - - -#define XDL_MIN(a, b) ((a) < (b) ? (a): (b)) -#define XDL_MAX(a, b) ((a) > (b) ? (a): (b)) -#define XDL_ABS(v) ((v) >= 0 ? (v): -(v)) -#define XDL_ISDIGIT(c) ((c) >= '0' && (c) <= '9') -#define XDL_ISSPACE(c) (isspace((unsigned char)(c))) -#define XDL_ADDBITS(v,b) ((v) + ((v) >> (b))) -#define XDL_MASKBITS(b) ((1UL << (b)) - 1) -#define XDL_HASHLONG(v,b) (XDL_ADDBITS((unsigned long)(v), b) & XDL_MASKBITS(b)) -#define XDL_LE32_PUT(p, v) \ -do { \ - unsigned char *__p = (unsigned char *) (p); \ - *__p++ = (unsigned char) (v); \ - *__p++ = (unsigned char) ((v) >> 8); \ - *__p++ = (unsigned char) ((v) >> 16); \ - *__p = (unsigned char) ((v) >> 24); \ -} while (0) -#define XDL_LE32_GET(p, v) \ -do { \ - unsigned char const *__p = (unsigned char const *) (p); \ - (v) = (unsigned long) __p[0] | ((unsigned long) __p[1]) << 8 | \ - ((unsigned long) __p[2]) << 16 | ((unsigned long) __p[3]) << 24; \ -} while (0) - -/* Allocate an array of nr elements, returns NULL on failure */ -#define XDL_ALLOC_ARRAY(p, nr) \ - ((p) = SIZE_MAX / sizeof(*(p)) >= (size_t)(nr) \ - ? xdl_malloc((nr) * sizeof(*(p))) \ - : NULL) - -/* Allocate an array of nr zeroed out elements, returns NULL on failure */ -#define XDL_CALLOC_ARRAY(p, nr) ((p) = xdl_calloc(nr, sizeof(*(p)))) - -/* - * Ensure array p can accommodate at least nr elements, growing the - * array and updating alloc (which is the number of allocated - * elements) as necessary. Frees p and returns -1 on failure, returns - * 0 on success - */ -#define XDL_ALLOC_GROW(p, nr, alloc) \ - (-!((nr) <= (alloc) || \ - ((p) = xdl_alloc_grow_helper((p), (nr), &(alloc), sizeof(*(p)))))) - -#endif /* #if !defined(XMACROS_H) */ diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xmerge.c b/vendor/libgit2-sys/libgit2/deps/xdiff/xmerge.c deleted file mode 100644 index 1b1903c..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xmerge.c +++ /dev/null @@ -1,743 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003-2006 Davide Libenzi, Johannes E. Schindelin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#include "xinclude.h" - -typedef struct s_xdmerge { - struct s_xdmerge *next; - /* - * 0 = conflict, - * 1 = no conflict, take first, - * 2 = no conflict, take second. - * 3 = no conflict, take both. - */ - int mode; - /* - * These point at the respective postimages. E.g. is - * how side #1 wants to change the common ancestor; if there is no - * overlap, lines before i1 in the postimage of side #1 appear - * in the merge result as a region touched by neither side. - */ - long i1, i2; - long chg1, chg2; - /* - * These point at the preimage; of course there is just one - * preimage, that is from the shared common ancestor. - */ - long i0; - long chg0; -} xdmerge_t; - -static int xdl_append_merge(xdmerge_t **merge, int mode, - long i0, long chg0, - long i1, long chg1, - long i2, long chg2) -{ - xdmerge_t *m = *merge; - if (m && (i1 <= m->i1 + m->chg1 || i2 <= m->i2 + m->chg2)) { - if (mode != m->mode) - m->mode = 0; - m->chg0 = i0 + chg0 - m->i0; - m->chg1 = i1 + chg1 - m->i1; - m->chg2 = i2 + chg2 - m->i2; - } else { - m = xdl_malloc(sizeof(xdmerge_t)); - if (!m) - return -1; - m->next = NULL; - m->mode = mode; - m->i0 = i0; - m->chg0 = chg0; - m->i1 = i1; - m->chg1 = chg1; - m->i2 = i2; - m->chg2 = chg2; - if (*merge) - (*merge)->next = m; - *merge = m; - } - return 0; -} - -static int xdl_cleanup_merge(xdmerge_t *c) -{ - int count = 0; - xdmerge_t *next_c; - - /* were there conflicts? */ - for (; c; c = next_c) { - if (c->mode == 0) - count++; - next_c = c->next; - xdl_free(c); - } - return count; -} - -static int xdl_merge_cmp_lines(xdfenv_t *xe1, int i1, xdfenv_t *xe2, int i2, - int line_count, long flags) -{ - int i; - xrecord_t **rec1 = xe1->xdf2.recs + i1; - xrecord_t **rec2 = xe2->xdf2.recs + i2; - - for (i = 0; i < line_count; i++) { - int result = xdl_recmatch(rec1[i]->ptr, rec1[i]->size, - rec2[i]->ptr, rec2[i]->size, flags); - if (!result) - return -1; - } - return 0; -} - -static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest) -{ - xrecord_t **recs; - int size = 0; - - recs = (use_orig ? xe->xdf1.recs : xe->xdf2.recs) + i; - - if (count < 1) - return 0; - - for (i = 0; i < count; size += recs[i++]->size) - if (dest) - memcpy(dest + size, recs[i]->ptr, recs[i]->size); - if (add_nl) { - i = recs[count - 1]->size; - if (i == 0 || recs[count - 1]->ptr[i - 1] != '\n') { - if (needs_cr) { - if (dest) - dest[size] = '\r'; - size++; - } - - if (dest) - dest[size] = '\n'; - size++; - } - } - return size; -} - -static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest) -{ - return xdl_recs_copy_0(0, xe, i, count, needs_cr, add_nl, dest); -} - -static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest) -{ - return xdl_recs_copy_0(1, xe, i, count, needs_cr, add_nl, dest); -} - -/* - * Returns 1 if the i'th line ends in CR/LF (if it is the last line and - * has no eol, the preceding line, if any), 0 if it ends in LF-only, and - * -1 if the line ending cannot be determined. - */ -static int is_eol_crlf(xdfile_t *file, int i) -{ - long size; - - if (i < file->nrec - 1) - /* All lines before the last *must* end in LF */ - return (size = file->recs[i]->size) > 1 && - file->recs[i]->ptr[size - 2] == '\r'; - if (!file->nrec) - /* Cannot determine eol style from empty file */ - return -1; - if ((size = file->recs[i]->size) && - file->recs[i]->ptr[size - 1] == '\n') - /* Last line; ends in LF; Is it CR/LF? */ - return size > 1 && - file->recs[i]->ptr[size - 2] == '\r'; - if (!i) - /* The only line has no eol */ - return -1; - /* Determine eol from second-to-last line */ - return (size = file->recs[i - 1]->size) > 1 && - file->recs[i - 1]->ptr[size - 2] == '\r'; -} - -static int is_cr_needed(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t *m) -{ - int needs_cr; - - /* Match post-images' preceding, or first, lines' end-of-line style */ - needs_cr = is_eol_crlf(&xe1->xdf2, m->i1 ? m->i1 - 1 : 0); - if (needs_cr) - needs_cr = is_eol_crlf(&xe2->xdf2, m->i2 ? m->i2 - 1 : 0); - /* Look at pre-image's first line, unless we already settled on LF */ - if (needs_cr) - needs_cr = is_eol_crlf(&xe1->xdf1, 0); - /* If still undecided, use LF-only */ - return needs_cr < 0 ? 0 : needs_cr; -} - -static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1, - xdfenv_t *xe2, const char *name2, - const char *name3, - int size, int i, int style, - xdmerge_t *m, char *dest, int marker_size) -{ - int marker1_size = (name1 ? strlen(name1) + 1 : 0); - int marker2_size = (name2 ? strlen(name2) + 1 : 0); - int marker3_size = (name3 ? strlen(name3) + 1 : 0); - int needs_cr = is_cr_needed(xe1, xe2, m); - - if (marker_size <= 0) - marker_size = DEFAULT_CONFLICT_MARKER_SIZE; - - /* Before conflicting part */ - size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0, - dest ? dest + size : NULL); - - if (!dest) { - size += marker_size + 1 + needs_cr + marker1_size; - } else { - memset(dest + size, '<', marker_size); - size += marker_size; - if (marker1_size) { - dest[size] = ' '; - memcpy(dest + size + 1, name1, marker1_size - 1); - size += marker1_size; - } - if (needs_cr) - dest[size++] = '\r'; - dest[size++] = '\n'; - } - - /* Postimage from side #1 */ - size += xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, 1, - dest ? dest + size : NULL); - - if (style == XDL_MERGE_DIFF3 || style == XDL_MERGE_ZEALOUS_DIFF3) { - /* Shared preimage */ - if (!dest) { - size += marker_size + 1 + needs_cr + marker3_size; - } else { - memset(dest + size, '|', marker_size); - size += marker_size; - if (marker3_size) { - dest[size] = ' '; - memcpy(dest + size + 1, name3, marker3_size - 1); - size += marker3_size; - } - if (needs_cr) - dest[size++] = '\r'; - dest[size++] = '\n'; - } - size += xdl_orig_copy(xe1, m->i0, m->chg0, needs_cr, 1, - dest ? dest + size : NULL); - } - - if (!dest) { - size += marker_size + 1 + needs_cr; - } else { - memset(dest + size, '=', marker_size); - size += marker_size; - if (needs_cr) - dest[size++] = '\r'; - dest[size++] = '\n'; - } - - /* Postimage from side #2 */ - size += xdl_recs_copy(xe2, m->i2, m->chg2, needs_cr, 1, - dest ? dest + size : NULL); - if (!dest) { - size += marker_size + 1 + needs_cr + marker2_size; - } else { - memset(dest + size, '>', marker_size); - size += marker_size; - if (marker2_size) { - dest[size] = ' '; - memcpy(dest + size + 1, name2, marker2_size - 1); - size += marker2_size; - } - if (needs_cr) - dest[size++] = '\r'; - dest[size++] = '\n'; - } - return size; -} - -static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1, - xdfenv_t *xe2, const char *name2, - const char *ancestor_name, - int favor, - xdmerge_t *m, char *dest, int style, - int marker_size) -{ - int size, i; - - for (size = i = 0; m; m = m->next) { - if (favor && !m->mode) - m->mode = favor; - - if (m->mode == 0) - size = fill_conflict_hunk(xe1, name1, xe2, name2, - ancestor_name, - size, i, style, m, dest, - marker_size); - else if (m->mode & 3) { - /* Before conflicting part */ - size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0, - dest ? dest + size : NULL); - /* Postimage from side #1 */ - if (m->mode & 1) { - int needs_cr = is_cr_needed(xe1, xe2, m); - - size += xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, (m->mode & 2), - dest ? dest + size : NULL); - } - /* Postimage from side #2 */ - if (m->mode & 2) - size += xdl_recs_copy(xe2, m->i2, m->chg2, 0, 0, - dest ? dest + size : NULL); - } else - continue; - i = m->i1 + m->chg1; - } - size += xdl_recs_copy(xe1, i, xe1->xdf2.nrec - i, 0, 0, - dest ? dest + size : NULL); - return size; -} - -static int recmatch(xrecord_t *rec1, xrecord_t *rec2, unsigned long flags) -{ - return xdl_recmatch(rec1->ptr, rec1->size, - rec2->ptr, rec2->size, flags); -} - -/* - * Remove any common lines from the beginning and end of the conflicted region. - */ -static void xdl_refine_zdiff3_conflicts(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t *m, - xpparam_t const *xpp) -{ - xrecord_t **rec1 = xe1->xdf2.recs, **rec2 = xe2->xdf2.recs; - for (; m; m = m->next) { - /* let's handle just the conflicts */ - if (m->mode) - continue; - - while(m->chg1 && m->chg2 && - recmatch(rec1[m->i1], rec2[m->i2], xpp->flags)) { - m->chg1--; - m->chg2--; - m->i1++; - m->i2++; - } - while (m->chg1 && m->chg2 && - recmatch(rec1[m->i1 + m->chg1 - 1], - rec2[m->i2 + m->chg2 - 1], xpp->flags)) { - m->chg1--; - m->chg2--; - } - } -} - -/* - * Sometimes, changes are not quite identical, but differ in only a few - * lines. Try hard to show only these few lines as conflicting. - */ -static int xdl_refine_conflicts(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t *m, - xpparam_t const *xpp) -{ - for (; m; m = m->next) { - mmfile_t t1, t2; - xdfenv_t xe; - xdchange_t *xscr, *x; - int i1 = m->i1, i2 = m->i2; - - /* let's handle just the conflicts */ - if (m->mode) - continue; - - /* no sense refining a conflict when one side is empty */ - if (m->chg1 == 0 || m->chg2 == 0) - continue; - - /* - * This probably does not work outside git, since - * we have a very simple mmfile structure. - */ - t1.ptr = (char *)xe1->xdf2.recs[m->i1]->ptr; - t1.size = xe1->xdf2.recs[m->i1 + m->chg1 - 1]->ptr - + xe1->xdf2.recs[m->i1 + m->chg1 - 1]->size - t1.ptr; - t2.ptr = (char *)xe2->xdf2.recs[m->i2]->ptr; - t2.size = xe2->xdf2.recs[m->i2 + m->chg2 - 1]->ptr - + xe2->xdf2.recs[m->i2 + m->chg2 - 1]->size - t2.ptr; - if (xdl_do_diff(&t1, &t2, xpp, &xe) < 0) - return -1; - if (xdl_change_compact(&xe.xdf1, &xe.xdf2, xpp->flags) < 0 || - xdl_change_compact(&xe.xdf2, &xe.xdf1, xpp->flags) < 0 || - xdl_build_script(&xe, &xscr) < 0) { - xdl_free_env(&xe); - return -1; - } - if (!xscr) { - /* If this happens, the changes are identical. */ - xdl_free_env(&xe); - m->mode = 4; - continue; - } - x = xscr; - m->i1 = xscr->i1 + i1; - m->chg1 = xscr->chg1; - m->i2 = xscr->i2 + i2; - m->chg2 = xscr->chg2; - while (xscr->next) { - xdmerge_t *m2 = xdl_malloc(sizeof(xdmerge_t)); - if (!m2) { - xdl_free_env(&xe); - xdl_free_script(x); - return -1; - } - xscr = xscr->next; - m2->next = m->next; - m->next = m2; - m = m2; - m->mode = 0; - m->i1 = xscr->i1 + i1; - m->chg1 = xscr->chg1; - m->i2 = xscr->i2 + i2; - m->chg2 = xscr->chg2; - } - xdl_free_env(&xe); - xdl_free_script(x); - } - return 0; -} - -static int line_contains_alnum(const char *ptr, long size) -{ - while (size--) - if (isalnum((unsigned char)*(ptr++))) - return 1; - return 0; -} - -static int lines_contain_alnum(xdfenv_t *xe, int i, int chg) -{ - for (; chg; chg--, i++) - if (line_contains_alnum(xe->xdf2.recs[i]->ptr, - xe->xdf2.recs[i]->size)) - return 1; - return 0; -} - -/* - * This function merges m and m->next, marking everything between those hunks - * as conflicting, too. - */ -static void xdl_merge_two_conflicts(xdmerge_t *m) -{ - xdmerge_t *next_m = m->next; - m->chg1 = next_m->i1 + next_m->chg1 - m->i1; - m->chg2 = next_m->i2 + next_m->chg2 - m->i2; - m->next = next_m->next; - xdl_free(next_m); -} - -/* - * If there are less than 3 non-conflicting lines between conflicts, - * it appears simpler -- because it takes up less (or as many) lines -- - * if the lines are moved into the conflicts. - */ -static int xdl_simplify_non_conflicts(xdfenv_t *xe1, xdmerge_t *m, - int simplify_if_no_alnum) -{ - int result = 0; - - if (!m) - return result; - for (;;) { - xdmerge_t *next_m = m->next; - int begin, end; - - if (!next_m) - return result; - - begin = m->i1 + m->chg1; - end = next_m->i1; - - if (m->mode != 0 || next_m->mode != 0 || - (end - begin > 3 && - (!simplify_if_no_alnum || - lines_contain_alnum(xe1, begin, end - begin)))) { - m = next_m; - } else { - result++; - xdl_merge_two_conflicts(m); - } - } -} - -/* - * level == 0: mark all overlapping changes as conflict - * level == 1: mark overlapping changes as conflict only if not identical - * level == 2: analyze non-identical changes for minimal conflict set - * level == 3: analyze non-identical changes for minimal conflict set, but - * treat hunks not containing any letter or number as conflicting - * - * returns < 0 on error, == 0 for no conflicts, else number of conflicts - */ -static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, - xdfenv_t *xe2, xdchange_t *xscr2, - xmparam_t const *xmp, mmbuffer_t *result) -{ - xdmerge_t *changes, *c; - xpparam_t const *xpp = &xmp->xpp; - const char *const ancestor_name = xmp->ancestor; - const char *const name1 = xmp->file1; - const char *const name2 = xmp->file2; - int i0, i1, i2, chg0, chg1, chg2; - int level = xmp->level; - int style = xmp->style; - int favor = xmp->favor; - - /* - * XDL_MERGE_DIFF3 does not attempt to refine conflicts by looking - * at common areas of sides 1 & 2, because the base (side 0) does - * not match and is being shown. Similarly, simplification of - * non-conflicts is also skipped due to the skipping of conflict - * refinement. - * - * XDL_MERGE_ZEALOUS_DIFF3, on the other hand, will attempt to - * refine conflicts looking for common areas of sides 1 & 2. - * However, since the base is being shown and does not match, - * it will only look for common areas at the beginning or end - * of the conflict block. Since XDL_MERGE_ZEALOUS_DIFF3's - * conflict refinement is much more limited in this fashion, the - * conflict simplification will be skipped. - */ - if (style == XDL_MERGE_DIFF3 || style == XDL_MERGE_ZEALOUS_DIFF3) { - /* - * "diff3 -m" output does not make sense for anything - * more aggressive than XDL_MERGE_EAGER. - */ - if (XDL_MERGE_EAGER < level) - level = XDL_MERGE_EAGER; - } - - c = changes = NULL; - - while (xscr1 && xscr2) { - if (!changes) - changes = c; - if (xscr1->i1 + xscr1->chg1 < xscr2->i1) { - i0 = xscr1->i1; - i1 = xscr1->i2; - i2 = xscr2->i2 - xscr2->i1 + xscr1->i1; - chg0 = xscr1->chg1; - chg1 = xscr1->chg2; - chg2 = xscr1->chg1; - if (xdl_append_merge(&c, 1, - i0, chg0, i1, chg1, i2, chg2)) { - xdl_cleanup_merge(changes); - return -1; - } - xscr1 = xscr1->next; - continue; - } - if (xscr2->i1 + xscr2->chg1 < xscr1->i1) { - i0 = xscr2->i1; - i1 = xscr1->i2 - xscr1->i1 + xscr2->i1; - i2 = xscr2->i2; - chg0 = xscr2->chg1; - chg1 = xscr2->chg1; - chg2 = xscr2->chg2; - if (xdl_append_merge(&c, 2, - i0, chg0, i1, chg1, i2, chg2)) { - xdl_cleanup_merge(changes); - return -1; - } - xscr2 = xscr2->next; - continue; - } - if (level == XDL_MERGE_MINIMAL || xscr1->i1 != xscr2->i1 || - xscr1->chg1 != xscr2->chg1 || - xscr1->chg2 != xscr2->chg2 || - xdl_merge_cmp_lines(xe1, xscr1->i2, - xe2, xscr2->i2, - xscr1->chg2, xpp->flags)) { - /* conflict */ - int off = xscr1->i1 - xscr2->i1; - int ffo = off + xscr1->chg1 - xscr2->chg1; - - i0 = xscr1->i1; - i1 = xscr1->i2; - i2 = xscr2->i2; - if (off > 0) { - i0 -= off; - i1 -= off; - } - else - i2 += off; - chg0 = xscr1->i1 + xscr1->chg1 - i0; - chg1 = xscr1->i2 + xscr1->chg2 - i1; - chg2 = xscr2->i2 + xscr2->chg2 - i2; - if (ffo < 0) { - chg0 -= ffo; - chg1 -= ffo; - } else - chg2 += ffo; - if (xdl_append_merge(&c, 0, - i0, chg0, i1, chg1, i2, chg2)) { - xdl_cleanup_merge(changes); - return -1; - } - } - - i1 = xscr1->i1 + xscr1->chg1; - i2 = xscr2->i1 + xscr2->chg1; - - if (i1 >= i2) - xscr2 = xscr2->next; - if (i2 >= i1) - xscr1 = xscr1->next; - } - while (xscr1) { - if (!changes) - changes = c; - i0 = xscr1->i1; - i1 = xscr1->i2; - i2 = xscr1->i1 + xe2->xdf2.nrec - xe2->xdf1.nrec; - chg0 = xscr1->chg1; - chg1 = xscr1->chg2; - chg2 = xscr1->chg1; - if (xdl_append_merge(&c, 1, - i0, chg0, i1, chg1, i2, chg2)) { - xdl_cleanup_merge(changes); - return -1; - } - xscr1 = xscr1->next; - } - while (xscr2) { - if (!changes) - changes = c; - i0 = xscr2->i1; - i1 = xscr2->i1 + xe1->xdf2.nrec - xe1->xdf1.nrec; - i2 = xscr2->i2; - chg0 = xscr2->chg1; - chg1 = xscr2->chg1; - chg2 = xscr2->chg2; - if (xdl_append_merge(&c, 2, - i0, chg0, i1, chg1, i2, chg2)) { - xdl_cleanup_merge(changes); - return -1; - } - xscr2 = xscr2->next; - } - if (!changes) - changes = c; - /* refine conflicts */ - if (style == XDL_MERGE_ZEALOUS_DIFF3) { - xdl_refine_zdiff3_conflicts(xe1, xe2, changes, xpp); - } else if (XDL_MERGE_ZEALOUS <= level && - (xdl_refine_conflicts(xe1, xe2, changes, xpp) < 0 || - xdl_simplify_non_conflicts(xe1, changes, - XDL_MERGE_ZEALOUS < level) < 0)) { - xdl_cleanup_merge(changes); - return -1; - } - /* output */ - if (result) { - int marker_size = xmp->marker_size; - int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2, - ancestor_name, - favor, changes, NULL, style, - marker_size); - result->ptr = xdl_malloc(size); - if (!result->ptr) { - xdl_cleanup_merge(changes); - return -1; - } - result->size = size; - xdl_fill_merge_buffer(xe1, name1, xe2, name2, - ancestor_name, favor, changes, - result->ptr, style, marker_size); - } - return xdl_cleanup_merge(changes); -} - -int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2, - xmparam_t const *xmp, mmbuffer_t *result) -{ - xdchange_t *xscr1 = NULL, *xscr2 = NULL; - xdfenv_t xe1, xe2; - int status = -1; - xpparam_t const *xpp = &xmp->xpp; - - result->ptr = NULL; - result->size = 0; - - if (xdl_do_diff(orig, mf1, xpp, &xe1) < 0) - return -1; - - if (xdl_do_diff(orig, mf2, xpp, &xe2) < 0) - goto free_xe1; /* avoid double free of xe2 */ - - if (xdl_change_compact(&xe1.xdf1, &xe1.xdf2, xpp->flags) < 0 || - xdl_change_compact(&xe1.xdf2, &xe1.xdf1, xpp->flags) < 0 || - xdl_build_script(&xe1, &xscr1) < 0) - goto out; - - if (xdl_change_compact(&xe2.xdf1, &xe2.xdf2, xpp->flags) < 0 || - xdl_change_compact(&xe2.xdf2, &xe2.xdf1, xpp->flags) < 0 || - xdl_build_script(&xe2, &xscr2) < 0) - goto out; - - if (!xscr1) { - if (mf2->size) { - result->ptr = xdl_malloc(mf2->size); - if (!result->ptr) - goto out; - memcpy(result->ptr, mf2->ptr, mf2->size); - result->size = mf2->size; - } - status = 0; - } else if (!xscr2) { - if (mf1->size) { - result->ptr = xdl_malloc(mf1->size); - if (!result->ptr) - goto out; - memcpy(result->ptr, mf1->ptr, mf1->size); - result->size = mf1->size; - } - status = 0; - } else { - status = xdl_do_merge(&xe1, xscr1, - &xe2, xscr2, - xmp, result); - } - out: - xdl_free_script(xscr1); - xdl_free_script(xscr2); - - xdl_free_env(&xe2); - free_xe1: - xdl_free_env(&xe1); - - return status; -} diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xpatience.c b/vendor/libgit2-sys/libgit2/deps/xdiff/xpatience.c deleted file mode 100644 index a2d8955..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xpatience.c +++ /dev/null @@ -1,373 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003-2016 Davide Libenzi, Johannes E. Schindelin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ -#include "xinclude.h" - -/* - * The basic idea of patience diff is to find lines that are unique in - * both files. These are intuitively the ones that we want to see as - * common lines. - * - * The maximal ordered sequence of such line pairs (where ordered means - * that the order in the sequence agrees with the order of the lines in - * both files) naturally defines an initial set of common lines. - * - * Now, the algorithm tries to extend the set of common lines by growing - * the line ranges where the files have identical lines. - * - * Between those common lines, the patience diff algorithm is applied - * recursively, until no unique line pairs can be found; these line ranges - * are handled by the well-known Myers algorithm. - */ - -#define NON_UNIQUE ULONG_MAX - -/* - * This is a hash mapping from line hash to line numbers in the first and - * second file. - */ -struct hashmap { - int nr, alloc; - struct entry { - unsigned long hash; - /* - * 0 = unused entry, 1 = first line, 2 = second, etc. - * line2 is NON_UNIQUE if the line is not unique - * in either the first or the second file. - */ - unsigned long line1, line2; - /* - * "next" & "previous" are used for the longest common - * sequence; - * initially, "next" reflects only the order in file1. - */ - struct entry *next, *previous; - - /* - * If 1, this entry can serve as an anchor. See - * Documentation/diff-options.txt for more information. - */ - unsigned anchor : 1; - } *entries, *first, *last; - /* were common records found? */ - unsigned long has_matches; - xdfenv_t *env; - xpparam_t const *xpp; -}; - -static int is_anchor(xpparam_t const *xpp, const char *line) -{ - int i; - for (i = 0; i < xpp->anchors_nr; i++) { - if (!strncmp(line, xpp->anchors[i], strlen(xpp->anchors[i]))) - return 1; - } - return 0; -} - -/* The argument "pass" is 1 for the first file, 2 for the second. */ -static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map, - int pass) -{ - xrecord_t **records = pass == 1 ? - map->env->xdf1.recs : map->env->xdf2.recs; - xrecord_t *record = records[line - 1]; - /* - * After xdl_prepare_env() (or more precisely, due to - * xdl_classify_record()), the "ha" member of the records (AKA lines) - * is _not_ the hash anymore, but a linearized version of it. In - * other words, the "ha" member is guaranteed to start with 0 and - * the second record's ha can only be 0 or 1, etc. - * - * So we multiply ha by 2 in the hope that the hashing was - * "unique enough". - */ - int index = (int)((record->ha << 1) % map->alloc); - - while (map->entries[index].line1) { - if (map->entries[index].hash != record->ha) { - if (++index >= map->alloc) - index = 0; - continue; - } - if (pass == 2) - map->has_matches = 1; - if (pass == 1 || map->entries[index].line2) - map->entries[index].line2 = NON_UNIQUE; - else - map->entries[index].line2 = line; - return; - } - if (pass == 2) - return; - map->entries[index].line1 = line; - map->entries[index].hash = record->ha; - map->entries[index].anchor = is_anchor(xpp, map->env->xdf1.recs[line - 1]->ptr); - if (!map->first) - map->first = map->entries + index; - if (map->last) { - map->last->next = map->entries + index; - map->entries[index].previous = map->last; - } - map->last = map->entries + index; - map->nr++; -} - -/* - * This function has to be called for each recursion into the inter-hunk - * parts, as previously non-unique lines can become unique when being - * restricted to a smaller part of the files. - * - * It is assumed that env has been prepared using xdl_prepare(). - */ -static int fill_hashmap(xpparam_t const *xpp, xdfenv_t *env, - struct hashmap *result, - int line1, int count1, int line2, int count2) -{ - result->xpp = xpp; - result->env = env; - - /* We know exactly how large we want the hash map */ - result->alloc = count1 * 2; - if (!XDL_CALLOC_ARRAY(result->entries, result->alloc)) - return -1; - - /* First, fill with entries from the first file */ - while (count1--) - insert_record(xpp, line1++, result, 1); - - /* Then search for matches in the second file */ - while (count2--) - insert_record(xpp, line2++, result, 2); - - return 0; -} - -/* - * Find the longest sequence with a smaller last element (meaning a smaller - * line2, as we construct the sequence with entries ordered by line1). - */ -static int binary_search(struct entry **sequence, int longest, - struct entry *entry) -{ - int left = -1, right = longest; - - while (left + 1 < right) { - int middle = left + (right - left) / 2; - /* by construction, no two entries can be equal */ - if (sequence[middle]->line2 > entry->line2) - right = middle; - else - left = middle; - } - /* return the index in "sequence", _not_ the sequence length */ - return left; -} - -/* - * The idea is to start with the list of common unique lines sorted by - * the order in file1. For each of these pairs, the longest (partial) - * sequence whose last element's line2 is smaller is determined. - * - * For efficiency, the sequences are kept in a list containing exactly one - * item per sequence length: the sequence with the smallest last - * element (in terms of line2). - */ -static int find_longest_common_sequence(struct hashmap *map, struct entry **res) -{ - struct entry **sequence; - int longest = 0, i; - struct entry *entry; - - /* - * If not -1, this entry in sequence must never be overridden. - * Therefore, overriding entries before this has no effect, so - * do not do that either. - */ - int anchor_i = -1; - - if (!XDL_ALLOC_ARRAY(sequence, map->nr)) - return -1; - - for (entry = map->first; entry; entry = entry->next) { - if (!entry->line2 || entry->line2 == NON_UNIQUE) - continue; - i = binary_search(sequence, longest, entry); - entry->previous = i < 0 ? NULL : sequence[i]; - ++i; - if (i <= anchor_i) - continue; - sequence[i] = entry; - if (entry->anchor) { - anchor_i = i; - longest = anchor_i + 1; - } else if (i == longest) { - longest++; - } - } - - /* No common unique lines were found */ - if (!longest) { - *res = NULL; - xdl_free(sequence); - return 0; - } - - /* Iterate starting at the last element, adjusting the "next" members */ - entry = sequence[longest - 1]; - entry->next = NULL; - while (entry->previous) { - entry->previous->next = entry; - entry = entry->previous; - } - *res = entry; - xdl_free(sequence); - return 0; -} - -static int match(struct hashmap *map, int line1, int line2) -{ - xrecord_t *record1 = map->env->xdf1.recs[line1 - 1]; - xrecord_t *record2 = map->env->xdf2.recs[line2 - 1]; - return record1->ha == record2->ha; -} - -static int patience_diff(xpparam_t const *xpp, xdfenv_t *env, - int line1, int count1, int line2, int count2); - -static int walk_common_sequence(struct hashmap *map, struct entry *first, - int line1, int count1, int line2, int count2) -{ - int end1 = line1 + count1, end2 = line2 + count2; - int next1, next2; - - for (;;) { - /* Try to grow the line ranges of common lines */ - if (first) { - next1 = first->line1; - next2 = first->line2; - while (next1 > line1 && next2 > line2 && - match(map, next1 - 1, next2 - 1)) { - next1--; - next2--; - } - } else { - next1 = end1; - next2 = end2; - } - while (line1 < next1 && line2 < next2 && - match(map, line1, line2)) { - line1++; - line2++; - } - - /* Recurse */ - if (next1 > line1 || next2 > line2) { - if (patience_diff(map->xpp, map->env, - line1, next1 - line1, - line2, next2 - line2)) - return -1; - } - - if (!first) - return 0; - - while (first->next && - first->next->line1 == first->line1 + 1 && - first->next->line2 == first->line2 + 1) - first = first->next; - - line1 = first->line1 + 1; - line2 = first->line2 + 1; - - first = first->next; - } -} - -static int fall_back_to_classic_diff(struct hashmap *map, - int line1, int count1, int line2, int count2) -{ - xpparam_t xpp; - - memset(&xpp, 0, sizeof(xpp)); - xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; - - return xdl_fall_back_diff(map->env, &xpp, - line1, count1, line2, count2); -} - -/* - * Recursively find the longest common sequence of unique lines, - * and if none was found, ask xdl_do_diff() to do the job. - * - * This function assumes that env was prepared with xdl_prepare_env(). - */ -static int patience_diff(xpparam_t const *xpp, xdfenv_t *env, - int line1, int count1, int line2, int count2) -{ - struct hashmap map; - struct entry *first; - int result = 0; - - /* trivial case: one side is empty */ - if (!count1) { - while(count2--) - env->xdf2.rchg[line2++ - 1] = 1; - return 0; - } else if (!count2) { - while(count1--) - env->xdf1.rchg[line1++ - 1] = 1; - return 0; - } - - memset(&map, 0, sizeof(map)); - if (fill_hashmap(xpp, env, &map, - line1, count1, line2, count2)) - return -1; - - /* are there any matching lines at all? */ - if (!map.has_matches) { - while(count1--) - env->xdf1.rchg[line1++ - 1] = 1; - while(count2--) - env->xdf2.rchg[line2++ - 1] = 1; - xdl_free(map.entries); - return 0; - } - - result = find_longest_common_sequence(&map, &first); - if (result) - goto out; - if (first) - result = walk_common_sequence(&map, first, - line1, count1, line2, count2); - else - result = fall_back_to_classic_diff(&map, - line1, count1, line2, count2); - out: - xdl_free(map.entries); - return result; -} - -int xdl_do_patience_diff(xpparam_t const *xpp, xdfenv_t *env) -{ - return patience_diff(xpp, env, 1, env->xdf1.nrec, 1, env->xdf2.nrec); -} diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xprepare.c b/vendor/libgit2-sys/libgit2/deps/xdiff/xprepare.c deleted file mode 100644 index c84549f..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xprepare.c +++ /dev/null @@ -1,461 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#include "xinclude.h" - - -#define XDL_KPDIS_RUN 4 -#define XDL_MAX_EQLIMIT 1024 -#define XDL_SIMSCAN_WINDOW 100 -#define XDL_GUESS_NLINES1 256 -#define XDL_GUESS_NLINES2 20 - - -typedef struct s_xdlclass { - struct s_xdlclass *next; - unsigned long ha; - char const *line; - long size; - long idx; - long len1, len2; -} xdlclass_t; - -typedef struct s_xdlclassifier { - unsigned int hbits; - long hsize; - xdlclass_t **rchash; - chastore_t ncha; - xdlclass_t **rcrecs; - long alloc; - long count; - long flags; -} xdlclassifier_t; - - - - -static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags); -static void xdl_free_classifier(xdlclassifier_t *cf); -static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t **rhash, - unsigned int hbits, xrecord_t *rec); -static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp, - xdlclassifier_t *cf, xdfile_t *xdf); -static void xdl_free_ctx(xdfile_t *xdf); -static int xdl_clean_mmatch(char const *dis, long i, long s, long e); -static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2); -static int xdl_trim_ends(xdfile_t *xdf1, xdfile_t *xdf2); -static int xdl_optimize_ctxs(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2); - - - - -static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) { - cf->flags = flags; - - cf->hbits = xdl_hashbits((unsigned int) size); - cf->hsize = 1 << cf->hbits; - - if (xdl_cha_init(&cf->ncha, sizeof(xdlclass_t), size / 4 + 1) < 0) { - - return -1; - } - if (!XDL_CALLOC_ARRAY(cf->rchash, cf->hsize)) { - - xdl_cha_free(&cf->ncha); - return -1; - } - - cf->alloc = size; - if (!XDL_ALLOC_ARRAY(cf->rcrecs, cf->alloc)) { - - xdl_free(cf->rchash); - xdl_cha_free(&cf->ncha); - return -1; - } - - cf->count = 0; - - return 0; -} - - -static void xdl_free_classifier(xdlclassifier_t *cf) { - - xdl_free(cf->rcrecs); - xdl_free(cf->rchash); - xdl_cha_free(&cf->ncha); -} - - -static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t **rhash, - unsigned int hbits, xrecord_t *rec) { - long hi; - char const *line; - xdlclass_t *rcrec; - - line = rec->ptr; - hi = (long) XDL_HASHLONG(rec->ha, cf->hbits); - for (rcrec = cf->rchash[hi]; rcrec; rcrec = rcrec->next) - if (rcrec->ha == rec->ha && - xdl_recmatch(rcrec->line, rcrec->size, - rec->ptr, rec->size, cf->flags)) - break; - - if (!rcrec) { - if (!(rcrec = xdl_cha_alloc(&cf->ncha))) { - - return -1; - } - rcrec->idx = cf->count++; - if (XDL_ALLOC_GROW(cf->rcrecs, cf->count, cf->alloc)) - return -1; - cf->rcrecs[rcrec->idx] = rcrec; - rcrec->line = line; - rcrec->size = rec->size; - rcrec->ha = rec->ha; - rcrec->len1 = rcrec->len2 = 0; - rcrec->next = cf->rchash[hi]; - cf->rchash[hi] = rcrec; - } - - (pass == 1) ? rcrec->len1++ : rcrec->len2++; - - rec->ha = (unsigned long) rcrec->idx; - - hi = (long) XDL_HASHLONG(rec->ha, hbits); - rec->next = rhash[hi]; - rhash[hi] = rec; - - return 0; -} - - -static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp, - xdlclassifier_t *cf, xdfile_t *xdf) { - unsigned int hbits; - long nrec, hsize, bsize; - unsigned long hav; - char const *blk, *cur, *top, *prev; - xrecord_t *crec; - xrecord_t **recs; - xrecord_t **rhash; - unsigned long *ha; - char *rchg; - long *rindex; - - ha = NULL; - rindex = NULL; - rchg = NULL; - rhash = NULL; - recs = NULL; - - if (xdl_cha_init(&xdf->rcha, sizeof(xrecord_t), narec / 4 + 1) < 0) - goto abort; - if (!XDL_ALLOC_ARRAY(recs, narec)) - goto abort; - - hbits = xdl_hashbits((unsigned int) narec); - hsize = 1 << hbits; - if (!XDL_CALLOC_ARRAY(rhash, hsize)) - goto abort; - - nrec = 0; - if ((cur = blk = xdl_mmfile_first(mf, &bsize))) { - for (top = blk + bsize; cur < top; ) { - prev = cur; - hav = xdl_hash_record(&cur, top, xpp->flags); - if (XDL_ALLOC_GROW(recs, nrec + 1, narec)) - goto abort; - if (!(crec = xdl_cha_alloc(&xdf->rcha))) - goto abort; - crec->ptr = prev; - crec->size = (long) (cur - prev); - crec->ha = hav; - recs[nrec++] = crec; - if (xdl_classify_record(pass, cf, rhash, hbits, crec) < 0) - goto abort; - } - } - - if (!XDL_CALLOC_ARRAY(rchg, nrec + 2)) - goto abort; - - if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) && - (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF)) { - if (!XDL_ALLOC_ARRAY(rindex, nrec + 1)) - goto abort; - if (!XDL_ALLOC_ARRAY(ha, nrec + 1)) - goto abort; - } - - xdf->nrec = nrec; - xdf->recs = recs; - xdf->hbits = hbits; - xdf->rhash = rhash; - xdf->rchg = rchg + 1; - xdf->rindex = rindex; - xdf->nreff = 0; - xdf->ha = ha; - xdf->dstart = 0; - xdf->dend = nrec - 1; - - return 0; - -abort: - xdl_free(ha); - xdl_free(rindex); - xdl_free(rchg); - xdl_free(rhash); - xdl_free(recs); - xdl_cha_free(&xdf->rcha); - return -1; -} - - -static void xdl_free_ctx(xdfile_t *xdf) { - - xdl_free(xdf->rhash); - xdl_free(xdf->rindex); - xdl_free(xdf->rchg - 1); - xdl_free(xdf->ha); - xdl_free(xdf->recs); - xdl_cha_free(&xdf->rcha); -} - - -int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, - xdfenv_t *xe) { - long enl1, enl2, sample; - xdlclassifier_t cf; - - memset(&cf, 0, sizeof(cf)); - - /* - * For histogram diff, we can afford a smaller sample size and - * thus a poorer estimate of the number of lines, as the hash - * table (rhash) won't be filled up/grown. The number of lines - * (nrecs) will be updated correctly anyway by - * xdl_prepare_ctx(). - */ - sample = (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF - ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1); - - enl1 = xdl_guess_lines(mf1, sample) + 1; - enl2 = xdl_guess_lines(mf2, sample) + 1; - - if (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) - return -1; - - if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) { - - xdl_free_classifier(&cf); - return -1; - } - if (xdl_prepare_ctx(2, mf2, enl2, xpp, &cf, &xe->xdf2) < 0) { - - xdl_free_ctx(&xe->xdf1); - xdl_free_classifier(&cf); - return -1; - } - - if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) && - (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) && - xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) { - - xdl_free_ctx(&xe->xdf2); - xdl_free_ctx(&xe->xdf1); - xdl_free_classifier(&cf); - return -1; - } - - xdl_free_classifier(&cf); - - return 0; -} - - -void xdl_free_env(xdfenv_t *xe) { - - xdl_free_ctx(&xe->xdf2); - xdl_free_ctx(&xe->xdf1); -} - - -static int xdl_clean_mmatch(char const *dis, long i, long s, long e) { - long r, rdis0, rpdis0, rdis1, rpdis1; - - /* - * Limits the window the is examined during the similar-lines - * scan. The loops below stops when dis[i - r] == 1 (line that - * has no match), but there are corner cases where the loop - * proceed all the way to the extremities by causing huge - * performance penalties in case of big files. - */ - if (i - s > XDL_SIMSCAN_WINDOW) - s = i - XDL_SIMSCAN_WINDOW; - if (e - i > XDL_SIMSCAN_WINDOW) - e = i + XDL_SIMSCAN_WINDOW; - - /* - * Scans the lines before 'i' to find a run of lines that either - * have no match (dis[j] == 0) or have multiple matches (dis[j] > 1). - * Note that we always call this function with dis[i] > 1, so the - * current line (i) is already a multimatch line. - */ - for (r = 1, rdis0 = 0, rpdis0 = 1; (i - r) >= s; r++) { - if (!dis[i - r]) - rdis0++; - else if (dis[i - r] == 2) - rpdis0++; - else - break; - } - /* - * If the run before the line 'i' found only multimatch lines, we - * return 0 and hence we don't make the current line (i) discarded. - * We want to discard multimatch lines only when they appear in the - * middle of runs with nomatch lines (dis[j] == 0). - */ - if (rdis0 == 0) - return 0; - for (r = 1, rdis1 = 0, rpdis1 = 1; (i + r) <= e; r++) { - if (!dis[i + r]) - rdis1++; - else if (dis[i + r] == 2) - rpdis1++; - else - break; - } - /* - * If the run after the line 'i' found only multimatch lines, we - * return 0 and hence we don't make the current line (i) discarded. - */ - if (rdis1 == 0) - return 0; - rdis1 += rdis0; - rpdis1 += rpdis0; - - return rpdis1 * XDL_KPDIS_RUN < (rpdis1 + rdis1); -} - - -/* - * Try to reduce the problem complexity, discard records that have no - * matches on the other file. Also, lines that have multiple matches - * might be potentially discarded if they happear in a run of discardable. - */ -static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) { - long i, nm, nreff, mlim; - xrecord_t **recs; - xdlclass_t *rcrec; - char *dis, *dis1, *dis2; - - if (!XDL_CALLOC_ARRAY(dis, xdf1->nrec + xdf2->nrec + 2)) - return -1; - dis1 = dis; - dis2 = dis1 + xdf1->nrec + 1; - - if ((mlim = xdl_bogosqrt(xdf1->nrec)) > XDL_MAX_EQLIMIT) - mlim = XDL_MAX_EQLIMIT; - for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; i <= xdf1->dend; i++, recs++) { - rcrec = cf->rcrecs[(*recs)->ha]; - nm = rcrec ? rcrec->len2 : 0; - dis1[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1; - } - - if ((mlim = xdl_bogosqrt(xdf2->nrec)) > XDL_MAX_EQLIMIT) - mlim = XDL_MAX_EQLIMIT; - for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart]; i <= xdf2->dend; i++, recs++) { - rcrec = cf->rcrecs[(*recs)->ha]; - nm = rcrec ? rcrec->len1 : 0; - dis2[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1; - } - - for (nreff = 0, i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; - i <= xdf1->dend; i++, recs++) { - if (dis1[i] == 1 || - (dis1[i] == 2 && !xdl_clean_mmatch(dis1, i, xdf1->dstart, xdf1->dend))) { - xdf1->rindex[nreff] = i; - xdf1->ha[nreff] = (*recs)->ha; - nreff++; - } else - xdf1->rchg[i] = 1; - } - xdf1->nreff = nreff; - - for (nreff = 0, i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart]; - i <= xdf2->dend; i++, recs++) { - if (dis2[i] == 1 || - (dis2[i] == 2 && !xdl_clean_mmatch(dis2, i, xdf2->dstart, xdf2->dend))) { - xdf2->rindex[nreff] = i; - xdf2->ha[nreff] = (*recs)->ha; - nreff++; - } else - xdf2->rchg[i] = 1; - } - xdf2->nreff = nreff; - - xdl_free(dis); - - return 0; -} - - -/* - * Early trim initial and terminal matching records. - */ -static int xdl_trim_ends(xdfile_t *xdf1, xdfile_t *xdf2) { - long i, lim; - xrecord_t **recs1, **recs2; - - recs1 = xdf1->recs; - recs2 = xdf2->recs; - for (i = 0, lim = XDL_MIN(xdf1->nrec, xdf2->nrec); i < lim; - i++, recs1++, recs2++) - if ((*recs1)->ha != (*recs2)->ha) - break; - - xdf1->dstart = xdf2->dstart = i; - - recs1 = xdf1->recs + xdf1->nrec - 1; - recs2 = xdf2->recs + xdf2->nrec - 1; - for (lim -= i, i = 0; i < lim; i++, recs1--, recs2--) - if ((*recs1)->ha != (*recs2)->ha) - break; - - xdf1->dend = xdf1->nrec - i - 1; - xdf2->dend = xdf2->nrec - i - 1; - - return 0; -} - - -static int xdl_optimize_ctxs(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) { - - if (xdl_trim_ends(xdf1, xdf2) < 0 || - xdl_cleanup_records(cf, xdf1, xdf2) < 0) { - - return -1; - } - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xprepare.h b/vendor/libgit2-sys/libgit2/deps/xdiff/xprepare.h deleted file mode 100644 index 947d9fc..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xprepare.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#if !defined(XPREPARE_H) -#define XPREPARE_H - - - -int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, - xdfenv_t *xe); -void xdl_free_env(xdfenv_t *xe); - - - -#endif /* #if !defined(XPREPARE_H) */ diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xtypes.h b/vendor/libgit2-sys/libgit2/deps/xdiff/xtypes.h deleted file mode 100644 index 8442bd4..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xtypes.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#if !defined(XTYPES_H) -#define XTYPES_H - - - -typedef struct s_chanode { - struct s_chanode *next; - long icurr; -} chanode_t; - -typedef struct s_chastore { - chanode_t *head, *tail; - long isize, nsize; - chanode_t *ancur; - chanode_t *sncur; - long scurr; -} chastore_t; - -typedef struct s_xrecord { - struct s_xrecord *next; - char const *ptr; - long size; - unsigned long ha; -} xrecord_t; - -typedef struct s_xdfile { - chastore_t rcha; - long nrec; - unsigned int hbits; - xrecord_t **rhash; - long dstart, dend; - xrecord_t **recs; - char *rchg; - long *rindex; - long nreff; - unsigned long *ha; -} xdfile_t; - -typedef struct s_xdfenv { - xdfile_t xdf1, xdf2; -} xdfenv_t; - - - -#endif /* #if !defined(XTYPES_H) */ diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xutils.c b/vendor/libgit2-sys/libgit2/deps/xdiff/xutils.c deleted file mode 100644 index 9e36f24..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xutils.c +++ /dev/null @@ -1,451 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#include "xinclude.h" - - -long xdl_bogosqrt(long n) { - long i; - - /* - * Classical integer square root approximation using shifts. - */ - for (i = 1; n > 0; n >>= 2) - i <<= 1; - - return i; -} - - -int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, - xdemitcb_t *ecb) { - int i = 2; - mmbuffer_t mb[3]; - - mb[0].ptr = (char *) pre; - mb[0].size = psize; - mb[1].ptr = (char *) rec; - mb[1].size = size; - if (size > 0 && rec[size - 1] != '\n') { - mb[2].ptr = (char *) "\n\\ No newline at end of file\n"; - mb[2].size = strlen(mb[2].ptr); - i++; - } - if (ecb->out_line(ecb->priv, mb, i) < 0) { - - return -1; - } - - return 0; -} - -void *xdl_mmfile_first(mmfile_t *mmf, long *size) -{ - *size = mmf->size; - return mmf->ptr; -} - - -long xdl_mmfile_size(mmfile_t *mmf) -{ - return mmf->size; -} - - -int xdl_cha_init(chastore_t *cha, long isize, long icount) { - - cha->head = cha->tail = NULL; - cha->isize = isize; - cha->nsize = icount * isize; - cha->ancur = cha->sncur = NULL; - cha->scurr = 0; - - return 0; -} - - -void xdl_cha_free(chastore_t *cha) { - chanode_t *cur, *tmp; - - for (cur = cha->head; (tmp = cur) != NULL;) { - cur = cur->next; - xdl_free(tmp); - } -} - - -void *xdl_cha_alloc(chastore_t *cha) { - chanode_t *ancur; - void *data; - - if (!(ancur = cha->ancur) || ancur->icurr == cha->nsize) { - if (!(ancur = (chanode_t *) xdl_malloc(sizeof(chanode_t) + cha->nsize))) { - - return NULL; - } - ancur->icurr = 0; - ancur->next = NULL; - if (cha->tail) - cha->tail->next = ancur; - if (!cha->head) - cha->head = ancur; - cha->tail = ancur; - cha->ancur = ancur; - } - - data = (char *) ancur + sizeof(chanode_t) + ancur->icurr; - ancur->icurr += cha->isize; - - return data; -} - -long xdl_guess_lines(mmfile_t *mf, long sample) { - long nl = 0, size, tsize = 0; - char const *data, *cur, *top; - - if ((cur = data = xdl_mmfile_first(mf, &size))) { - for (top = data + size; nl < sample && cur < top; ) { - nl++; - if (!(cur = memchr(cur, '\n', top - cur))) - cur = top; - else - cur++; - } - tsize += (long) (cur - data); - } - - if (nl && tsize) - nl = xdl_mmfile_size(mf) / (tsize / nl); - - return nl + 1; -} - -int xdl_blankline(const char *line, long size, long flags) -{ - long i; - - if (!(flags & XDF_WHITESPACE_FLAGS)) - return (size <= 1); - - for (i = 0; i < size && XDL_ISSPACE(line[i]); i++) - ; - - return (i == size); -} - -/* - * Have we eaten everything on the line, except for an optional - * CR at the very end? - */ -static int ends_with_optional_cr(const char *l, long s, long i) -{ - int complete = s && l[s-1] == '\n'; - - if (complete) - s--; - if (s == i) - return 1; - /* do not ignore CR at the end of an incomplete line */ - if (complete && s == i + 1 && l[i] == '\r') - return 1; - return 0; -} - -int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags) -{ - int i1, i2; - - if (s1 == s2 && !memcmp(l1, l2, s1)) - return 1; - if (!(flags & XDF_WHITESPACE_FLAGS)) - return 0; - - i1 = 0; - i2 = 0; - - /* - * -w matches everything that matches with -b, and -b in turn - * matches everything that matches with --ignore-space-at-eol, - * which in turn matches everything that matches with --ignore-cr-at-eol. - * - * Each flavor of ignoring needs different logic to skip whitespaces - * while we have both sides to compare. - */ - if (flags & XDF_IGNORE_WHITESPACE) { - goto skip_ws; - while (i1 < s1 && i2 < s2) { - if (l1[i1++] != l2[i2++]) - return 0; - skip_ws: - while (i1 < s1 && XDL_ISSPACE(l1[i1])) - i1++; - while (i2 < s2 && XDL_ISSPACE(l2[i2])) - i2++; - } - } else if (flags & XDF_IGNORE_WHITESPACE_CHANGE) { - while (i1 < s1 && i2 < s2) { - if (XDL_ISSPACE(l1[i1]) && XDL_ISSPACE(l2[i2])) { - /* Skip matching spaces and try again */ - while (i1 < s1 && XDL_ISSPACE(l1[i1])) - i1++; - while (i2 < s2 && XDL_ISSPACE(l2[i2])) - i2++; - continue; - } - if (l1[i1++] != l2[i2++]) - return 0; - } - } else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL) { - while (i1 < s1 && i2 < s2 && l1[i1] == l2[i2]) { - i1++; - i2++; - } - } else if (flags & XDF_IGNORE_CR_AT_EOL) { - /* Find the first difference and see how the line ends */ - while (i1 < s1 && i2 < s2 && l1[i1] == l2[i2]) { - i1++; - i2++; - } - return (ends_with_optional_cr(l1, s1, i1) && - ends_with_optional_cr(l2, s2, i2)); - } - - /* - * After running out of one side, the remaining side must have - * nothing but whitespace for the lines to match. Note that - * ignore-whitespace-at-eol case may break out of the loop - * while there still are characters remaining on both lines. - */ - if (i1 < s1) { - while (i1 < s1 && XDL_ISSPACE(l1[i1])) - i1++; - if (s1 != i1) - return 0; - } - if (i2 < s2) { - while (i2 < s2 && XDL_ISSPACE(l2[i2])) - i2++; - return (s2 == i2); - } - return 1; -} - -static unsigned long xdl_hash_record_with_whitespace(char const **data, - char const *top, long flags) { - unsigned long ha = 5381; - char const *ptr = *data; - int cr_at_eol_only = (flags & XDF_WHITESPACE_FLAGS) == XDF_IGNORE_CR_AT_EOL; - - for (; ptr < top && *ptr != '\n'; ptr++) { - if (cr_at_eol_only) { - /* do not ignore CR at the end of an incomplete line */ - if (*ptr == '\r' && - (ptr + 1 < top && ptr[1] == '\n')) - continue; - } - else if (XDL_ISSPACE(*ptr)) { - const char *ptr2 = ptr; - int at_eol; - while (ptr + 1 < top && XDL_ISSPACE(ptr[1]) - && ptr[1] != '\n') - ptr++; - at_eol = (top <= ptr + 1 || ptr[1] == '\n'); - if (flags & XDF_IGNORE_WHITESPACE) - ; /* already handled */ - else if (flags & XDF_IGNORE_WHITESPACE_CHANGE - && !at_eol) { - ha += (ha << 5); - ha ^= (unsigned long) ' '; - } - else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL - && !at_eol) { - while (ptr2 != ptr + 1) { - ha += (ha << 5); - ha ^= (unsigned long) *ptr2; - ptr2++; - } - } - continue; - } - ha += (ha << 5); - ha ^= (unsigned long) *ptr; - } - *data = ptr < top ? ptr + 1: ptr; - - return ha; -} - -unsigned long xdl_hash_record(char const **data, char const *top, long flags) { - unsigned long ha = 5381; - char const *ptr = *data; - - if (flags & XDF_WHITESPACE_FLAGS) - return xdl_hash_record_with_whitespace(data, top, flags); - - for (; ptr < top && *ptr != '\n'; ptr++) { - ha += (ha << 5); - ha ^= (unsigned long) *ptr; - } - *data = ptr < top ? ptr + 1: ptr; - - return ha; -} - -unsigned int xdl_hashbits(unsigned int size) { - unsigned int val = 1, bits = 0; - - for (; val < size && bits < CHAR_BIT * sizeof(unsigned int); val <<= 1, bits++); - return bits ? bits: 1; -} - - -int xdl_num_out(char *out, long val) { - char *ptr, *str = out; - char buf[32]; - - ptr = buf + sizeof(buf) - 1; - *ptr = '\0'; - if (val < 0) { - *--ptr = '-'; - val = -val; - } - for (; val && ptr > buf; val /= 10) - *--ptr = "0123456789"[val % 10]; - if (*ptr) - for (; *ptr; ptr++, str++) - *str = *ptr; - else - *str++ = '0'; - *str = '\0'; - - return str - out; -} - -static int xdl_format_hunk_hdr(long s1, long c1, long s2, long c2, - const char *func, long funclen, - xdemitcb_t *ecb) { - int nb = 0; - mmbuffer_t mb; - char buf[128]; - - memcpy(buf, "@@ -", 4); - nb += 4; - - nb += xdl_num_out(buf + nb, c1 ? s1: s1 - 1); - - if (c1 != 1) { - memcpy(buf + nb, ",", 1); - nb += 1; - - nb += xdl_num_out(buf + nb, c1); - } - - memcpy(buf + nb, " +", 2); - nb += 2; - - nb += xdl_num_out(buf + nb, c2 ? s2: s2 - 1); - - if (c2 != 1) { - memcpy(buf + nb, ",", 1); - nb += 1; - - nb += xdl_num_out(buf + nb, c2); - } - - memcpy(buf + nb, " @@", 3); - nb += 3; - if (func && funclen) { - buf[nb++] = ' '; - if (funclen > sizeof(buf) - nb - 1) - funclen = sizeof(buf) - nb - 1; - memcpy(buf + nb, func, funclen); - nb += funclen; - } - buf[nb++] = '\n'; - - mb.ptr = buf; - mb.size = nb; - if (ecb->out_line(ecb->priv, &mb, 1) < 0) - return -1; - return 0; -} - -int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, - const char *func, long funclen, - xdemitcb_t *ecb) { - if (!ecb->out_hunk) - return xdl_format_hunk_hdr(s1, c1, s2, c2, func, funclen, ecb); - if (ecb->out_hunk(ecb->priv, - c1 ? s1 : s1 - 1, c1, - c2 ? s2 : s2 - 1, c2, - func, funclen) < 0) - return -1; - return 0; -} - -int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp, - int line1, int count1, int line2, int count2) -{ - /* - * This probably does not work outside Git, since - * we have a very simple mmfile structure. - * - * Note: ideally, we would reuse the prepared environment, but - * the libxdiff interface does not (yet) allow for diffing only - * ranges of lines instead of the whole files. - */ - mmfile_t subfile1, subfile2; - xdfenv_t env; - - subfile1.ptr = (char *)diff_env->xdf1.recs[line1 - 1]->ptr; - subfile1.size = diff_env->xdf1.recs[line1 + count1 - 2]->ptr + - diff_env->xdf1.recs[line1 + count1 - 2]->size - subfile1.ptr; - subfile2.ptr = (char *)diff_env->xdf2.recs[line2 - 1]->ptr; - subfile2.size = diff_env->xdf2.recs[line2 + count2 - 2]->ptr + - diff_env->xdf2.recs[line2 + count2 - 2]->size - subfile2.ptr; - if (xdl_do_diff(&subfile1, &subfile2, xpp, &env) < 0) - return -1; - - memcpy(diff_env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1); - memcpy(diff_env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2); - - xdl_free_env(&env); - - return 0; -} - -void* xdl_alloc_grow_helper(void *p, long nr, long *alloc, size_t size) -{ - void *tmp = NULL; - size_t n = ((LONG_MAX - 16) / 2 >= *alloc) ? 2 * *alloc + 16 : LONG_MAX; - if (nr > n) - n = nr; - if (SIZE_MAX / size >= n) - tmp = xdl_realloc(p, n * size); - if (tmp) { - *alloc = n; - } else { - xdl_free(p); - *alloc = 0; - } - return tmp; -} diff --git a/vendor/libgit2-sys/libgit2/deps/xdiff/xutils.h b/vendor/libgit2-sys/libgit2/deps/xdiff/xutils.h deleted file mode 100644 index fd0bba9..0000000 --- a/vendor/libgit2-sys/libgit2/deps/xdiff/xutils.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see - * . - * - * Davide Libenzi - * - */ - -#if !defined(XUTILS_H) -#define XUTILS_H - - - -long xdl_bogosqrt(long n); -int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, - xdemitcb_t *ecb); -int xdl_cha_init(chastore_t *cha, long isize, long icount); -void xdl_cha_free(chastore_t *cha); -void *xdl_cha_alloc(chastore_t *cha); -long xdl_guess_lines(mmfile_t *mf, long sample); -int xdl_blankline(const char *line, long size, long flags); -int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags); -unsigned long xdl_hash_record(char const **data, char const *top, long flags); -unsigned int xdl_hashbits(unsigned int size); -int xdl_num_out(char *out, long val); -int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, - const char *func, long funclen, xdemitcb_t *ecb); -int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp, - int line1, int count1, int line2, int count2); - -/* Do not call this function, use XDL_ALLOC_GROW instead */ -void* xdl_alloc_grow_helper(void* p, long nr, long* alloc, size_t size); - -#endif /* #if !defined(XUTILS_H) */ diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/CMakeLists.txt b/vendor/libgit2-sys/libgit2/deps/zlib/CMakeLists.txt deleted file mode 100644 index 078ce69..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -disable_warnings(implicit-fallthrough) -add_definitions(-DNO_VIZ -DSTDC -DNO_GZIP -DHAVE_SYS_TYPES_H -DHAVE_STDINT_H -DHAVE_STDDEF_H) - -if(MINGW OR MSYS) - add_definitions(-DZ_HAVE_UNISTD_H -D_LFS64_LARGEFILE -D_LARGEFILE64_SOURCE=1) -endif() - -file(GLOB SRC_ZLIB "*.c" "*.h") -list(SORT SRC_ZLIB) -include_directories(".") -add_library(zlib OBJECT ${SRC_ZLIB}) diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/LICENSE b/vendor/libgit2-sys/libgit2/deps/zlib/LICENSE deleted file mode 100644 index ab8ee6f..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright notice: - - (C) 1995-2022 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/adler32.c b/vendor/libgit2-sys/libgit2/deps/zlib/adler32.c deleted file mode 100644 index 04b81d2..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/adler32.c +++ /dev/null @@ -1,164 +0,0 @@ -/* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-2011, 2016 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zutil.h" - -#define BASE 65521U /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} -#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); -#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); -#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); -#define DO16(buf) DO8(buf,0); DO8(buf,8); - -/* use NO_DIVIDE if your processor does not do division in hardware -- - try it both ways to see which is faster */ -#ifdef NO_DIVIDE -/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 - (thank you to John Reiser for pointing this out) */ -# define CHOP(a) \ - do { \ - unsigned long tmp = a >> 16; \ - a &= 0xffffUL; \ - a += (tmp << 4) - tmp; \ - } while (0) -# define MOD28(a) \ - do { \ - CHOP(a); \ - if (a >= BASE) a -= BASE; \ - } while (0) -# define MOD(a) \ - do { \ - CHOP(a); \ - MOD28(a); \ - } while (0) -# define MOD63(a) \ - do { /* this assumes a is not negative */ \ - z_off64_t tmp = a >> 32; \ - a &= 0xffffffffL; \ - a += (tmp << 8) - (tmp << 5) + tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - if (a >= BASE) a -= BASE; \ - } while (0) -#else -# define MOD(a) a %= BASE -# define MOD28(a) a %= BASE -# define MOD63(a) a %= BASE -#endif - -/* ========================================================================= */ -uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) { - unsigned long sum2; - unsigned n; - - /* split Adler-32 into component sums */ - sum2 = (adler >> 16) & 0xffff; - adler &= 0xffff; - - /* in case user likes doing a byte at a time, keep it fast */ - if (len == 1) { - adler += buf[0]; - if (adler >= BASE) - adler -= BASE; - sum2 += adler; - if (sum2 >= BASE) - sum2 -= BASE; - return adler | (sum2 << 16); - } - - /* initial Adler-32 value (deferred check for len == 1 speed) */ - if (buf == Z_NULL) - return 1L; - - /* in case short lengths are provided, keep it somewhat fast */ - if (len < 16) { - while (len--) { - adler += *buf++; - sum2 += adler; - } - if (adler >= BASE) - adler -= BASE; - MOD28(sum2); /* only added so many BASE's */ - return adler | (sum2 << 16); - } - - /* do length NMAX blocks -- requires just one modulo operation */ - while (len >= NMAX) { - len -= NMAX; - n = NMAX / 16; /* NMAX is divisible by 16 */ - do { - DO16(buf); /* 16 sums unrolled */ - buf += 16; - } while (--n); - MOD(adler); - MOD(sum2); - } - - /* do remaining bytes (less than NMAX, still just one modulo) */ - if (len) { /* avoid modulos if none remaining */ - while (len >= 16) { - len -= 16; - DO16(buf); - buf += 16; - } - while (len--) { - adler += *buf++; - sum2 += adler; - } - MOD(adler); - MOD(sum2); - } - - /* return recombined sums */ - return adler | (sum2 << 16); -} - -/* ========================================================================= */ -uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { - return adler32_z(adler, buf, len); -} - -/* ========================================================================= */ -local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) { - unsigned long sum1; - unsigned long sum2; - unsigned rem; - - /* for negative len, return invalid adler32 as a clue for debugging */ - if (len2 < 0) - return 0xffffffffUL; - - /* the derivation of this formula is left as an exercise for the reader */ - MOD63(len2); /* assumes len2 >= 0 */ - rem = (unsigned)len2; - sum1 = adler1 & 0xffff; - sum2 = rem * sum1; - MOD(sum2); - sum1 += (adler2 & 0xffff) + BASE - 1; - sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; - if (sum1 >= BASE) sum1 -= BASE; - if (sum1 >= BASE) sum1 -= BASE; - if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1); - if (sum2 >= BASE) sum2 -= BASE; - return sum1 | (sum2 << 16); -} - -/* ========================================================================= */ -uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) { - return adler32_combine_(adler1, adler2, len2); -} - -uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) { - return adler32_combine_(adler1, adler2, len2); -} diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/crc32.c b/vendor/libgit2-sys/libgit2/deps/zlib/crc32.c deleted file mode 100644 index 6c38f5c..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/crc32.c +++ /dev/null @@ -1,1049 +0,0 @@ -/* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2022 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * This interleaved implementation of a CRC makes use of pipelined multiple - * arithmetic-logic units, commonly found in modern CPU cores. It is due to - * Kadatch and Jenkins (2010). See doc/crc-doc.1.0.pdf in this distribution. - */ - -/* @(#) $Id$ */ - -/* - Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore - protection on the static variables used to control the first-use generation - of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should - first call get_crc_table() to initialize the tables before allowing more than - one thread to use crc32(). - - MAKECRCH can be #defined to write out crc32.h. A main() routine is also - produced, so that this one source file can be compiled to an executable. - */ - -#ifdef MAKECRCH -# include -# ifndef DYNAMIC_CRC_TABLE -# define DYNAMIC_CRC_TABLE -# endif /* !DYNAMIC_CRC_TABLE */ -#endif /* MAKECRCH */ - -#include "zutil.h" /* for Z_U4, Z_U8, z_crc_t, and FAR definitions */ - - /* - A CRC of a message is computed on N braids of words in the message, where - each word consists of W bytes (4 or 8). If N is 3, for example, then three - running sparse CRCs are calculated respectively on each braid, at these - indices in the array of words: 0, 3, 6, ..., 1, 4, 7, ..., and 2, 5, 8, ... - This is done starting at a word boundary, and continues until as many blocks - of N * W bytes as are available have been processed. The results are combined - into a single CRC at the end. For this code, N must be in the range 1..6 and - W must be 4 or 8. The upper limit on N can be increased if desired by adding - more #if blocks, extending the patterns apparent in the code. In addition, - crc32.h would need to be regenerated, if the maximum N value is increased. - - N and W are chosen empirically by benchmarking the execution time on a given - processor. The choices for N and W below were based on testing on Intel Kaby - Lake i7, AMD Ryzen 7, ARM Cortex-A57, Sparc64-VII, PowerPC POWER9, and MIPS64 - Octeon II processors. The Intel, AMD, and ARM processors were all fastest - with N=5, W=8. The Sparc, PowerPC, and MIPS64 were all fastest at N=5, W=4. - They were all tested with either gcc or clang, all using the -O3 optimization - level. Your mileage may vary. - */ - -/* Define N */ -#ifdef Z_TESTN -# define N Z_TESTN -#else -# define N 5 -#endif -#if N < 1 || N > 6 -# error N must be in 1..6 -#endif - -/* - z_crc_t must be at least 32 bits. z_word_t must be at least as long as - z_crc_t. It is assumed here that z_word_t is either 32 bits or 64 bits, and - that bytes are eight bits. - */ - -/* - Define W and the associated z_word_t type. If W is not defined, then a - braided calculation is not used, and the associated tables and code are not - compiled. - */ -#ifdef Z_TESTW -# if Z_TESTW-1 != -1 -# define W Z_TESTW -# endif -#else -# ifdef MAKECRCH -# define W 8 /* required for MAKECRCH */ -# else -# if defined(__x86_64__) || defined(__aarch64__) -# define W 8 -# else -# define W 4 -# endif -# endif -#endif -#ifdef W -# if W == 8 && defined(Z_U8) - typedef Z_U8 z_word_t; -# elif defined(Z_U4) -# undef W -# define W 4 - typedef Z_U4 z_word_t; -# else -# undef W -# endif -#endif - -/* If available, use the ARM processor CRC32 instruction. */ -#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8 -# define ARMCRC32 -#endif - -#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) -/* - Swap the bytes in a z_word_t to convert between little and big endian. Any - self-respecting compiler will optimize this to a single machine byte-swap - instruction, if one is available. This assumes that word_t is either 32 bits - or 64 bits. - */ -local z_word_t byte_swap(z_word_t word) { -# if W == 8 - return - (word & 0xff00000000000000) >> 56 | - (word & 0xff000000000000) >> 40 | - (word & 0xff0000000000) >> 24 | - (word & 0xff00000000) >> 8 | - (word & 0xff000000) << 8 | - (word & 0xff0000) << 24 | - (word & 0xff00) << 40 | - (word & 0xff) << 56; -# else /* W == 4 */ - return - (word & 0xff000000) >> 24 | - (word & 0xff0000) >> 8 | - (word & 0xff00) << 8 | - (word & 0xff) << 24; -# endif -} -#endif - -#ifdef DYNAMIC_CRC_TABLE -/* ========================================================================= - * Table of powers of x for combining CRC-32s, filled in by make_crc_table() - * below. - */ - local z_crc_t FAR x2n_table[32]; -#else -/* ========================================================================= - * Tables for byte-wise and braided CRC-32 calculations, and a table of powers - * of x for combining CRC-32s, all made by make_crc_table(). - */ -# include "crc32.h" -#endif - -/* CRC polynomial. */ -#define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ - -/* - Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, - reflected. For speed, this requires that a not be zero. - */ -local z_crc_t multmodp(z_crc_t a, z_crc_t b) { - z_crc_t m, p; - - m = (z_crc_t)1 << 31; - p = 0; - for (;;) { - if (a & m) { - p ^= b; - if ((a & (m - 1)) == 0) - break; - } - m >>= 1; - b = b & 1 ? (b >> 1) ^ POLY : b >> 1; - } - return p; -} - -/* - Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been - initialized. - */ -local z_crc_t x2nmodp(z_off64_t n, unsigned k) { - z_crc_t p; - - p = (z_crc_t)1 << 31; /* x^0 == 1 */ - while (n) { - if (n & 1) - p = multmodp(x2n_table[k & 31], p); - n >>= 1; - k++; - } - return p; -} - -#ifdef DYNAMIC_CRC_TABLE -/* ========================================================================= - * Build the tables for byte-wise and braided CRC-32 calculations, and a table - * of powers of x for combining CRC-32s. - */ -local z_crc_t FAR crc_table[256]; -#ifdef W - local z_word_t FAR crc_big_table[256]; - local z_crc_t FAR crc_braid_table[W][256]; - local z_word_t FAR crc_braid_big_table[W][256]; - local void braid(z_crc_t [][256], z_word_t [][256], int, int); -#endif -#ifdef MAKECRCH - local void write_table(FILE *, const z_crc_t FAR *, int); - local void write_table32hi(FILE *, const z_word_t FAR *, int); - local void write_table64(FILE *, const z_word_t FAR *, int); -#endif /* MAKECRCH */ - -/* - Define a once() function depending on the availability of atomics. If this is - compiled with DYNAMIC_CRC_TABLE defined, and if CRCs will be computed in - multiple threads, and if atomics are not available, then get_crc_table() must - be called to initialize the tables and must return before any threads are - allowed to compute or combine CRCs. - */ - -/* Definition of once functionality. */ -typedef struct once_s once_t; - -/* Check for the availability of atomics. */ -#if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ - !defined(__STDC_NO_ATOMICS__) - -#include - -/* Structure for once(), which must be initialized with ONCE_INIT. */ -struct once_s { - atomic_flag begun; - atomic_int done; -}; -#define ONCE_INIT {ATOMIC_FLAG_INIT, 0} - -/* - Run the provided init() function exactly once, even if multiple threads - invoke once() at the same time. The state must be a once_t initialized with - ONCE_INIT. - */ -local void once(once_t *state, void (*init)(void)) { - if (!atomic_load(&state->done)) { - if (atomic_flag_test_and_set(&state->begun)) - while (!atomic_load(&state->done)) - ; - else { - init(); - atomic_store(&state->done, 1); - } - } -} - -#else /* no atomics */ - -/* Structure for once(), which must be initialized with ONCE_INIT. */ -struct once_s { - volatile int begun; - volatile int done; -}; -#define ONCE_INIT {0, 0} - -/* Test and set. Alas, not atomic, but tries to minimize the period of - vulnerability. */ -local int test_and_set(int volatile *flag) { - int was; - - was = *flag; - *flag = 1; - return was; -} - -/* Run the provided init() function once. This is not thread-safe. */ -local void once(once_t *state, void (*init)(void)) { - if (!state->done) { - if (test_and_set(&state->begun)) - while (!state->done) - ; - else { - init(); - state->done = 1; - } - } -} - -#endif - -/* State for once(). */ -local once_t made = ONCE_INIT; - -/* - Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: - x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. - - Polynomials over GF(2) are represented in binary, one bit per coefficient, - with the lowest powers in the most significant bit. Then adding polynomials - is just exclusive-or, and multiplying a polynomial by x is a right shift by - one. If we call the above polynomial p, and represent a byte as the - polynomial q, also with the lowest power in the most significant bit (so the - byte 0xb1 is the polynomial x^7+x^3+x^2+1), then the CRC is (q*x^32) mod p, - where a mod b means the remainder after dividing a by b. - - This calculation is done using the shift-register method of multiplying and - taking the remainder. The register is initialized to zero, and for each - incoming bit, x^32 is added mod p to the register if the bit is a one (where - x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x - (which is shifting right by one and adding x^32 mod p if the bit shifted out - is a one). We start with the highest power (least significant bit) of q and - repeat for all eight bits of q. - - The table is simply the CRC of all possible eight bit values. This is all the - information needed to generate CRCs on data a byte at a time for all - combinations of CRC register values and incoming bytes. - */ - -local void make_crc_table(void) { - unsigned i, j, n; - z_crc_t p; - - /* initialize the CRC of bytes tables */ - for (i = 0; i < 256; i++) { - p = i; - for (j = 0; j < 8; j++) - p = p & 1 ? (p >> 1) ^ POLY : p >> 1; - crc_table[i] = p; -#ifdef W - crc_big_table[i] = byte_swap(p); -#endif - } - - /* initialize the x^2^n mod p(x) table */ - p = (z_crc_t)1 << 30; /* x^1 */ - x2n_table[0] = p; - for (n = 1; n < 32; n++) - x2n_table[n] = p = multmodp(p, p); - -#ifdef W - /* initialize the braiding tables -- needs x2n_table[] */ - braid(crc_braid_table, crc_braid_big_table, N, W); -#endif - -#ifdef MAKECRCH - { - /* - The crc32.h header file contains tables for both 32-bit and 64-bit - z_word_t's, and so requires a 64-bit type be available. In that case, - z_word_t must be defined to be 64-bits. This code then also generates - and writes out the tables for the case that z_word_t is 32 bits. - */ -#if !defined(W) || W != 8 -# error Need a 64-bit integer type in order to generate crc32.h. -#endif - FILE *out; - int k, n; - z_crc_t ltl[8][256]; - z_word_t big[8][256]; - - out = fopen("crc32.h", "w"); - if (out == NULL) return; - - /* write out little-endian CRC table to crc32.h */ - fprintf(out, - "/* crc32.h -- tables for rapid CRC calculation\n" - " * Generated automatically by crc32.c\n */\n" - "\n" - "local const z_crc_t FAR crc_table[] = {\n" - " "); - write_table(out, crc_table, 256); - fprintf(out, - "};\n"); - - /* write out big-endian CRC table for 64-bit z_word_t to crc32.h */ - fprintf(out, - "\n" - "#ifdef W\n" - "\n" - "#if W == 8\n" - "\n" - "local const z_word_t FAR crc_big_table[] = {\n" - " "); - write_table64(out, crc_big_table, 256); - fprintf(out, - "};\n"); - - /* write out big-endian CRC table for 32-bit z_word_t to crc32.h */ - fprintf(out, - "\n" - "#else /* W == 4 */\n" - "\n" - "local const z_word_t FAR crc_big_table[] = {\n" - " "); - write_table32hi(out, crc_big_table, 256); - fprintf(out, - "};\n" - "\n" - "#endif\n"); - - /* write out braid tables for each value of N */ - for (n = 1; n <= 6; n++) { - fprintf(out, - "\n" - "#if N == %d\n", n); - - /* compute braid tables for this N and 64-bit word_t */ - braid(ltl, big, n, 8); - - /* write out braid tables for 64-bit z_word_t to crc32.h */ - fprintf(out, - "\n" - "#if W == 8\n" - "\n" - "local const z_crc_t FAR crc_braid_table[][256] = {\n"); - for (k = 0; k < 8; k++) { - fprintf(out, " {"); - write_table(out, ltl[k], 256); - fprintf(out, "}%s", k < 7 ? ",\n" : ""); - } - fprintf(out, - "};\n" - "\n" - "local const z_word_t FAR crc_braid_big_table[][256] = {\n"); - for (k = 0; k < 8; k++) { - fprintf(out, " {"); - write_table64(out, big[k], 256); - fprintf(out, "}%s", k < 7 ? ",\n" : ""); - } - fprintf(out, - "};\n"); - - /* compute braid tables for this N and 32-bit word_t */ - braid(ltl, big, n, 4); - - /* write out braid tables for 32-bit z_word_t to crc32.h */ - fprintf(out, - "\n" - "#else /* W == 4 */\n" - "\n" - "local const z_crc_t FAR crc_braid_table[][256] = {\n"); - for (k = 0; k < 4; k++) { - fprintf(out, " {"); - write_table(out, ltl[k], 256); - fprintf(out, "}%s", k < 3 ? ",\n" : ""); - } - fprintf(out, - "};\n" - "\n" - "local const z_word_t FAR crc_braid_big_table[][256] = {\n"); - for (k = 0; k < 4; k++) { - fprintf(out, " {"); - write_table32hi(out, big[k], 256); - fprintf(out, "}%s", k < 3 ? ",\n" : ""); - } - fprintf(out, - "};\n" - "\n" - "#endif\n" - "\n" - "#endif\n"); - } - fprintf(out, - "\n" - "#endif\n"); - - /* write out zeros operator table to crc32.h */ - fprintf(out, - "\n" - "local const z_crc_t FAR x2n_table[] = {\n" - " "); - write_table(out, x2n_table, 32); - fprintf(out, - "};\n"); - fclose(out); - } -#endif /* MAKECRCH */ -} - -#ifdef MAKECRCH - -/* - Write the 32-bit values in table[0..k-1] to out, five per line in - hexadecimal separated by commas. - */ -local void write_table(FILE *out, const z_crc_t FAR *table, int k) { - int n; - - for (n = 0; n < k; n++) - fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ", - (unsigned long)(table[n]), - n == k - 1 ? "" : (n % 5 == 4 ? ",\n" : ", ")); -} - -/* - Write the high 32-bits of each value in table[0..k-1] to out, five per line - in hexadecimal separated by commas. - */ -local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) { - int n; - - for (n = 0; n < k; n++) - fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ", - (unsigned long)(table[n] >> 32), - n == k - 1 ? "" : (n % 5 == 4 ? ",\n" : ", ")); -} - -/* - Write the 64-bit values in table[0..k-1] to out, three per line in - hexadecimal separated by commas. This assumes that if there is a 64-bit - type, then there is also a long long integer type, and it is at least 64 - bits. If not, then the type cast and format string can be adjusted - accordingly. - */ -local void write_table64(FILE *out, const z_word_t FAR *table, int k) { - int n; - - for (n = 0; n < k; n++) - fprintf(out, "%s0x%016llx%s", n == 0 || n % 3 ? "" : " ", - (unsigned long long)(table[n]), - n == k - 1 ? "" : (n % 3 == 2 ? ",\n" : ", ")); -} - -/* Actually do the deed. */ -int main(void) { - make_crc_table(); - return 0; -} - -#endif /* MAKECRCH */ - -#ifdef W -/* - Generate the little and big-endian braid tables for the given n and z_word_t - size w. Each array must have room for w blocks of 256 elements. - */ -local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) { - int k; - z_crc_t i, p, q; - for (k = 0; k < w; k++) { - p = x2nmodp((n * w + 3 - k) << 3, 0); - ltl[k][0] = 0; - big[w - 1 - k][0] = 0; - for (i = 1; i < 256; i++) { - ltl[k][i] = q = multmodp(i << 24, p); - big[w - 1 - k][i] = byte_swap(q); - } - } -} -#endif - -#endif /* DYNAMIC_CRC_TABLE */ - -/* ========================================================================= - * This function can be used by asm versions of crc32(), and to force the - * generation of the CRC tables in a threaded application. - */ -const z_crc_t FAR * ZEXPORT get_crc_table(void) { -#ifdef DYNAMIC_CRC_TABLE - once(&made, make_crc_table); -#endif /* DYNAMIC_CRC_TABLE */ - return (const z_crc_t FAR *)crc_table; -} - -/* ========================================================================= - * Use ARM machine instructions if available. This will compute the CRC about - * ten times faster than the braided calculation. This code does not check for - * the presence of the CRC instruction at run time. __ARM_FEATURE_CRC32 will - * only be defined if the compilation specifies an ARM processor architecture - * that has the instructions. For example, compiling with -march=armv8.1-a or - * -march=armv8-a+crc, or -march=native if the compile machine has the crc32 - * instructions. - */ -#ifdef ARMCRC32 - -/* - Constants empirically determined to maximize speed. These values are from - measurements on a Cortex-A57. Your mileage may vary. - */ -#define Z_BATCH 3990 /* number of words in a batch */ -#define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */ -#define Z_BATCH_MIN 800 /* fewest words in a final batch */ - -unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, - z_size_t len) { - z_crc_t val; - z_word_t crc1, crc2; - const z_word_t *word; - z_word_t val0, val1, val2; - z_size_t last, last2, i; - z_size_t num; - - /* Return initial CRC, if requested. */ - if (buf == Z_NULL) return 0; - -#ifdef DYNAMIC_CRC_TABLE - once(&made, make_crc_table); -#endif /* DYNAMIC_CRC_TABLE */ - - /* Pre-condition the CRC */ - crc = (~crc) & 0xffffffff; - - /* Compute the CRC up to a word boundary. */ - while (len && ((z_size_t)buf & 7) != 0) { - len--; - val = *buf++; - __asm__ volatile("crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(val)); - } - - /* Prepare to compute the CRC on full 64-bit words word[0..num-1]. */ - word = (z_word_t const *)buf; - num = len >> 3; - len &= 7; - - /* Do three interleaved CRCs to realize the throughput of one crc32x - instruction per cycle. Each CRC is calculated on Z_BATCH words. The - three CRCs are combined into a single CRC after each set of batches. */ - while (num >= 3 * Z_BATCH) { - crc1 = 0; - crc2 = 0; - for (i = 0; i < Z_BATCH; i++) { - val0 = word[i]; - val1 = word[i + Z_BATCH]; - val2 = word[i + 2 * Z_BATCH]; - __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0)); - __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc1) : "r"(val1)); - __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc2) : "r"(val2)); - } - word += 3 * Z_BATCH; - num -= 3 * Z_BATCH; - crc = multmodp(Z_BATCH_ZEROS, crc) ^ crc1; - crc = multmodp(Z_BATCH_ZEROS, crc) ^ crc2; - } - - /* Do one last smaller batch with the remaining words, if there are enough - to pay for the combination of CRCs. */ - last = num / 3; - if (last >= Z_BATCH_MIN) { - last2 = last << 1; - crc1 = 0; - crc2 = 0; - for (i = 0; i < last; i++) { - val0 = word[i]; - val1 = word[i + last]; - val2 = word[i + last2]; - __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0)); - __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc1) : "r"(val1)); - __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc2) : "r"(val2)); - } - word += 3 * last; - num -= 3 * last; - val = x2nmodp(last, 6); - crc = multmodp(val, crc) ^ crc1; - crc = multmodp(val, crc) ^ crc2; - } - - /* Compute the CRC on any remaining words. */ - for (i = 0; i < num; i++) { - val0 = word[i]; - __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0)); - } - word += num; - - /* Complete the CRC on any remaining bytes. */ - buf = (const unsigned char FAR *)word; - while (len) { - len--; - val = *buf++; - __asm__ volatile("crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(val)); - } - - /* Return the CRC, post-conditioned. */ - return crc ^ 0xffffffff; -} - -#else - -#ifdef W - -/* - Return the CRC of the W bytes in the word_t data, taking the - least-significant byte of the word as the first byte of data, without any pre - or post conditioning. This is used to combine the CRCs of each braid. - */ -local z_crc_t crc_word(z_word_t data) { - int k; - for (k = 0; k < W; k++) - data = (data >> 8) ^ crc_table[data & 0xff]; - return (z_crc_t)data; -} - -local z_word_t crc_word_big(z_word_t data) { - int k; - for (k = 0; k < W; k++) - data = (data << 8) ^ - crc_big_table[(data >> ((W - 1) << 3)) & 0xff]; - return data; -} - -#endif - -/* ========================================================================= */ -unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, - z_size_t len) { - /* Return initial CRC, if requested. */ - if (buf == Z_NULL) return 0; - -#ifdef DYNAMIC_CRC_TABLE - once(&made, make_crc_table); -#endif /* DYNAMIC_CRC_TABLE */ - - /* Pre-condition the CRC */ - crc = (~crc) & 0xffffffff; - -#ifdef W - - /* If provided enough bytes, do a braided CRC calculation. */ - if (len >= N * W + W - 1) { - z_size_t blks; - z_word_t const *words; - unsigned endian; - int k; - - /* Compute the CRC up to a z_word_t boundary. */ - while (len && ((z_size_t)buf & (W - 1)) != 0) { - len--; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - } - - /* Compute the CRC on as many N z_word_t blocks as are available. */ - blks = len / (N * W); - len -= blks * N * W; - words = (z_word_t const *)buf; - - /* Do endian check at execution time instead of compile time, since ARM - processors can change the endianness at execution time. If the - compiler knows what the endianness will be, it can optimize out the - check and the unused branch. */ - endian = 1; - if (*(unsigned char *)&endian) { - /* Little endian. */ - - z_crc_t crc0; - z_word_t word0; -#if N > 1 - z_crc_t crc1; - z_word_t word1; -#if N > 2 - z_crc_t crc2; - z_word_t word2; -#if N > 3 - z_crc_t crc3; - z_word_t word3; -#if N > 4 - z_crc_t crc4; - z_word_t word4; -#if N > 5 - z_crc_t crc5; - z_word_t word5; -#endif -#endif -#endif -#endif -#endif - - /* Initialize the CRC for each braid. */ - crc0 = crc; -#if N > 1 - crc1 = 0; -#if N > 2 - crc2 = 0; -#if N > 3 - crc3 = 0; -#if N > 4 - crc4 = 0; -#if N > 5 - crc5 = 0; -#endif -#endif -#endif -#endif -#endif - - /* - Process the first blks-1 blocks, computing the CRCs on each braid - independently. - */ - while (--blks) { - /* Load the word for each braid into registers. */ - word0 = crc0 ^ words[0]; -#if N > 1 - word1 = crc1 ^ words[1]; -#if N > 2 - word2 = crc2 ^ words[2]; -#if N > 3 - word3 = crc3 ^ words[3]; -#if N > 4 - word4 = crc4 ^ words[4]; -#if N > 5 - word5 = crc5 ^ words[5]; -#endif -#endif -#endif -#endif -#endif - words += N; - - /* Compute and update the CRC for each word. The loop should - get unrolled. */ - crc0 = crc_braid_table[0][word0 & 0xff]; -#if N > 1 - crc1 = crc_braid_table[0][word1 & 0xff]; -#if N > 2 - crc2 = crc_braid_table[0][word2 & 0xff]; -#if N > 3 - crc3 = crc_braid_table[0][word3 & 0xff]; -#if N > 4 - crc4 = crc_braid_table[0][word4 & 0xff]; -#if N > 5 - crc5 = crc_braid_table[0][word5 & 0xff]; -#endif -#endif -#endif -#endif -#endif - for (k = 1; k < W; k++) { - crc0 ^= crc_braid_table[k][(word0 >> (k << 3)) & 0xff]; -#if N > 1 - crc1 ^= crc_braid_table[k][(word1 >> (k << 3)) & 0xff]; -#if N > 2 - crc2 ^= crc_braid_table[k][(word2 >> (k << 3)) & 0xff]; -#if N > 3 - crc3 ^= crc_braid_table[k][(word3 >> (k << 3)) & 0xff]; -#if N > 4 - crc4 ^= crc_braid_table[k][(word4 >> (k << 3)) & 0xff]; -#if N > 5 - crc5 ^= crc_braid_table[k][(word5 >> (k << 3)) & 0xff]; -#endif -#endif -#endif -#endif -#endif - } - } - - /* - Process the last block, combining the CRCs of the N braids at the - same time. - */ - crc = crc_word(crc0 ^ words[0]); -#if N > 1 - crc = crc_word(crc1 ^ words[1] ^ crc); -#if N > 2 - crc = crc_word(crc2 ^ words[2] ^ crc); -#if N > 3 - crc = crc_word(crc3 ^ words[3] ^ crc); -#if N > 4 - crc = crc_word(crc4 ^ words[4] ^ crc); -#if N > 5 - crc = crc_word(crc5 ^ words[5] ^ crc); -#endif -#endif -#endif -#endif -#endif - words += N; - } - else { - /* Big endian. */ - - z_word_t crc0, word0, comb; -#if N > 1 - z_word_t crc1, word1; -#if N > 2 - z_word_t crc2, word2; -#if N > 3 - z_word_t crc3, word3; -#if N > 4 - z_word_t crc4, word4; -#if N > 5 - z_word_t crc5, word5; -#endif -#endif -#endif -#endif -#endif - - /* Initialize the CRC for each braid. */ - crc0 = byte_swap(crc); -#if N > 1 - crc1 = 0; -#if N > 2 - crc2 = 0; -#if N > 3 - crc3 = 0; -#if N > 4 - crc4 = 0; -#if N > 5 - crc5 = 0; -#endif -#endif -#endif -#endif -#endif - - /* - Process the first blks-1 blocks, computing the CRCs on each braid - independently. - */ - while (--blks) { - /* Load the word for each braid into registers. */ - word0 = crc0 ^ words[0]; -#if N > 1 - word1 = crc1 ^ words[1]; -#if N > 2 - word2 = crc2 ^ words[2]; -#if N > 3 - word3 = crc3 ^ words[3]; -#if N > 4 - word4 = crc4 ^ words[4]; -#if N > 5 - word5 = crc5 ^ words[5]; -#endif -#endif -#endif -#endif -#endif - words += N; - - /* Compute and update the CRC for each word. The loop should - get unrolled. */ - crc0 = crc_braid_big_table[0][word0 & 0xff]; -#if N > 1 - crc1 = crc_braid_big_table[0][word1 & 0xff]; -#if N > 2 - crc2 = crc_braid_big_table[0][word2 & 0xff]; -#if N > 3 - crc3 = crc_braid_big_table[0][word3 & 0xff]; -#if N > 4 - crc4 = crc_braid_big_table[0][word4 & 0xff]; -#if N > 5 - crc5 = crc_braid_big_table[0][word5 & 0xff]; -#endif -#endif -#endif -#endif -#endif - for (k = 1; k < W; k++) { - crc0 ^= crc_braid_big_table[k][(word0 >> (k << 3)) & 0xff]; -#if N > 1 - crc1 ^= crc_braid_big_table[k][(word1 >> (k << 3)) & 0xff]; -#if N > 2 - crc2 ^= crc_braid_big_table[k][(word2 >> (k << 3)) & 0xff]; -#if N > 3 - crc3 ^= crc_braid_big_table[k][(word3 >> (k << 3)) & 0xff]; -#if N > 4 - crc4 ^= crc_braid_big_table[k][(word4 >> (k << 3)) & 0xff]; -#if N > 5 - crc5 ^= crc_braid_big_table[k][(word5 >> (k << 3)) & 0xff]; -#endif -#endif -#endif -#endif -#endif - } - } - - /* - Process the last block, combining the CRCs of the N braids at the - same time. - */ - comb = crc_word_big(crc0 ^ words[0]); -#if N > 1 - comb = crc_word_big(crc1 ^ words[1] ^ comb); -#if N > 2 - comb = crc_word_big(crc2 ^ words[2] ^ comb); -#if N > 3 - comb = crc_word_big(crc3 ^ words[3] ^ comb); -#if N > 4 - comb = crc_word_big(crc4 ^ words[4] ^ comb); -#if N > 5 - comb = crc_word_big(crc5 ^ words[5] ^ comb); -#endif -#endif -#endif -#endif -#endif - words += N; - crc = byte_swap(comb); - } - - /* - Update the pointer to the remaining bytes to process. - */ - buf = (unsigned char const *)words; - } - -#endif /* W */ - - /* Complete the computation of the CRC on any remaining bytes. */ - while (len >= 8) { - len -= 8; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - } - while (len) { - len--; - crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff]; - } - - /* Return the CRC, post-conditioned. */ - return crc ^ 0xffffffff; -} - -#endif - -/* ========================================================================= */ -unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, - uInt len) { - return crc32_z(crc, buf, len); -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { -#ifdef DYNAMIC_CRC_TABLE - once(&made, make_crc_table); -#endif /* DYNAMIC_CRC_TABLE */ - return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff); -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) { - return crc32_combine64(crc1, crc2, (z_off64_t)len2); -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { -#ifdef DYNAMIC_CRC_TABLE - once(&made, make_crc_table); -#endif /* DYNAMIC_CRC_TABLE */ - return x2nmodp(len2, 3); -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen(z_off_t len2) { - return crc32_combine_gen64((z_off64_t)len2); -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) { - return multmodp(op, crc1) ^ (crc2 & 0xffffffff); -} diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/crc32.h b/vendor/libgit2-sys/libgit2/deps/zlib/crc32.h deleted file mode 100644 index 137df68..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/crc32.h +++ /dev/null @@ -1,9446 +0,0 @@ -/* crc32.h -- tables for rapid CRC calculation - * Generated automatically by crc32.c - */ - -local const z_crc_t FAR crc_table[] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, - 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, - 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, - 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, - 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, - 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, - 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, - 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, - 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, - 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, - 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, - 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, - 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, - 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, - 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, - 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, - 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, - 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, - 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, - 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, - 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, - 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, - 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, - 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, - 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, - 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, - 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, - 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, - 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, - 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, - 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, - 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, - 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, - 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, - 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, - 0x2d02ef8d}; - -#ifdef W - -#if W == 8 - -local const z_word_t FAR crc_big_table[] = { - 0x0000000000000000, 0x9630077700000000, 0x2c610eee00000000, - 0xba51099900000000, 0x19c46d0700000000, 0x8ff46a7000000000, - 0x35a563e900000000, 0xa395649e00000000, 0x3288db0e00000000, - 0xa4b8dc7900000000, 0x1ee9d5e000000000, 0x88d9d29700000000, - 0x2b4cb60900000000, 0xbd7cb17e00000000, 0x072db8e700000000, - 0x911dbf9000000000, 0x6410b71d00000000, 0xf220b06a00000000, - 0x4871b9f300000000, 0xde41be8400000000, 0x7dd4da1a00000000, - 0xebe4dd6d00000000, 0x51b5d4f400000000, 0xc785d38300000000, - 0x56986c1300000000, 0xc0a86b6400000000, 0x7af962fd00000000, - 0xecc9658a00000000, 0x4f5c011400000000, 0xd96c066300000000, - 0x633d0ffa00000000, 0xf50d088d00000000, 0xc8206e3b00000000, - 0x5e10694c00000000, 0xe44160d500000000, 0x727167a200000000, - 0xd1e4033c00000000, 0x47d4044b00000000, 0xfd850dd200000000, - 0x6bb50aa500000000, 0xfaa8b53500000000, 0x6c98b24200000000, - 0xd6c9bbdb00000000, 0x40f9bcac00000000, 0xe36cd83200000000, - 0x755cdf4500000000, 0xcf0dd6dc00000000, 0x593dd1ab00000000, - 0xac30d92600000000, 0x3a00de5100000000, 0x8051d7c800000000, - 0x1661d0bf00000000, 0xb5f4b42100000000, 0x23c4b35600000000, - 0x9995bacf00000000, 0x0fa5bdb800000000, 0x9eb8022800000000, - 0x0888055f00000000, 0xb2d90cc600000000, 0x24e90bb100000000, - 0x877c6f2f00000000, 0x114c685800000000, 0xab1d61c100000000, - 0x3d2d66b600000000, 0x9041dc7600000000, 0x0671db0100000000, - 0xbc20d29800000000, 0x2a10d5ef00000000, 0x8985b17100000000, - 0x1fb5b60600000000, 0xa5e4bf9f00000000, 0x33d4b8e800000000, - 0xa2c9077800000000, 0x34f9000f00000000, 0x8ea8099600000000, - 0x18980ee100000000, 0xbb0d6a7f00000000, 0x2d3d6d0800000000, - 0x976c649100000000, 0x015c63e600000000, 0xf4516b6b00000000, - 0x62616c1c00000000, 0xd830658500000000, 0x4e0062f200000000, - 0xed95066c00000000, 0x7ba5011b00000000, 0xc1f4088200000000, - 0x57c40ff500000000, 0xc6d9b06500000000, 0x50e9b71200000000, - 0xeab8be8b00000000, 0x7c88b9fc00000000, 0xdf1ddd6200000000, - 0x492dda1500000000, 0xf37cd38c00000000, 0x654cd4fb00000000, - 0x5861b24d00000000, 0xce51b53a00000000, 0x7400bca300000000, - 0xe230bbd400000000, 0x41a5df4a00000000, 0xd795d83d00000000, - 0x6dc4d1a400000000, 0xfbf4d6d300000000, 0x6ae9694300000000, - 0xfcd96e3400000000, 0x468867ad00000000, 0xd0b860da00000000, - 0x732d044400000000, 0xe51d033300000000, 0x5f4c0aaa00000000, - 0xc97c0ddd00000000, 0x3c71055000000000, 0xaa41022700000000, - 0x10100bbe00000000, 0x86200cc900000000, 0x25b5685700000000, - 0xb3856f2000000000, 0x09d466b900000000, 0x9fe461ce00000000, - 0x0ef9de5e00000000, 0x98c9d92900000000, 0x2298d0b000000000, - 0xb4a8d7c700000000, 0x173db35900000000, 0x810db42e00000000, - 0x3b5cbdb700000000, 0xad6cbac000000000, 0x2083b8ed00000000, - 0xb6b3bf9a00000000, 0x0ce2b60300000000, 0x9ad2b17400000000, - 0x3947d5ea00000000, 0xaf77d29d00000000, 0x1526db0400000000, - 0x8316dc7300000000, 0x120b63e300000000, 0x843b649400000000, - 0x3e6a6d0d00000000, 0xa85a6a7a00000000, 0x0bcf0ee400000000, - 0x9dff099300000000, 0x27ae000a00000000, 0xb19e077d00000000, - 0x44930ff000000000, 0xd2a3088700000000, 0x68f2011e00000000, - 0xfec2066900000000, 0x5d5762f700000000, 0xcb67658000000000, - 0x71366c1900000000, 0xe7066b6e00000000, 0x761bd4fe00000000, - 0xe02bd38900000000, 0x5a7ada1000000000, 0xcc4add6700000000, - 0x6fdfb9f900000000, 0xf9efbe8e00000000, 0x43beb71700000000, - 0xd58eb06000000000, 0xe8a3d6d600000000, 0x7e93d1a100000000, - 0xc4c2d83800000000, 0x52f2df4f00000000, 0xf167bbd100000000, - 0x6757bca600000000, 0xdd06b53f00000000, 0x4b36b24800000000, - 0xda2b0dd800000000, 0x4c1b0aaf00000000, 0xf64a033600000000, - 0x607a044100000000, 0xc3ef60df00000000, 0x55df67a800000000, - 0xef8e6e3100000000, 0x79be694600000000, 0x8cb361cb00000000, - 0x1a8366bc00000000, 0xa0d26f2500000000, 0x36e2685200000000, - 0x95770ccc00000000, 0x03470bbb00000000, 0xb916022200000000, - 0x2f26055500000000, 0xbe3bbac500000000, 0x280bbdb200000000, - 0x925ab42b00000000, 0x046ab35c00000000, 0xa7ffd7c200000000, - 0x31cfd0b500000000, 0x8b9ed92c00000000, 0x1daede5b00000000, - 0xb0c2649b00000000, 0x26f263ec00000000, 0x9ca36a7500000000, - 0x0a936d0200000000, 0xa906099c00000000, 0x3f360eeb00000000, - 0x8567077200000000, 0x1357000500000000, 0x824abf9500000000, - 0x147ab8e200000000, 0xae2bb17b00000000, 0x381bb60c00000000, - 0x9b8ed29200000000, 0x0dbed5e500000000, 0xb7efdc7c00000000, - 0x21dfdb0b00000000, 0xd4d2d38600000000, 0x42e2d4f100000000, - 0xf8b3dd6800000000, 0x6e83da1f00000000, 0xcd16be8100000000, - 0x5b26b9f600000000, 0xe177b06f00000000, 0x7747b71800000000, - 0xe65a088800000000, 0x706a0fff00000000, 0xca3b066600000000, - 0x5c0b011100000000, 0xff9e658f00000000, 0x69ae62f800000000, - 0xd3ff6b6100000000, 0x45cf6c1600000000, 0x78e20aa000000000, - 0xeed20dd700000000, 0x5483044e00000000, 0xc2b3033900000000, - 0x612667a700000000, 0xf71660d000000000, 0x4d47694900000000, - 0xdb776e3e00000000, 0x4a6ad1ae00000000, 0xdc5ad6d900000000, - 0x660bdf4000000000, 0xf03bd83700000000, 0x53aebca900000000, - 0xc59ebbde00000000, 0x7fcfb24700000000, 0xe9ffb53000000000, - 0x1cf2bdbd00000000, 0x8ac2baca00000000, 0x3093b35300000000, - 0xa6a3b42400000000, 0x0536d0ba00000000, 0x9306d7cd00000000, - 0x2957de5400000000, 0xbf67d92300000000, 0x2e7a66b300000000, - 0xb84a61c400000000, 0x021b685d00000000, 0x942b6f2a00000000, - 0x37be0bb400000000, 0xa18e0cc300000000, 0x1bdf055a00000000, - 0x8def022d00000000}; - -#else /* W == 4 */ - -local const z_word_t FAR crc_big_table[] = { - 0x00000000, 0x96300777, 0x2c610eee, 0xba510999, 0x19c46d07, - 0x8ff46a70, 0x35a563e9, 0xa395649e, 0x3288db0e, 0xa4b8dc79, - 0x1ee9d5e0, 0x88d9d297, 0x2b4cb609, 0xbd7cb17e, 0x072db8e7, - 0x911dbf90, 0x6410b71d, 0xf220b06a, 0x4871b9f3, 0xde41be84, - 0x7dd4da1a, 0xebe4dd6d, 0x51b5d4f4, 0xc785d383, 0x56986c13, - 0xc0a86b64, 0x7af962fd, 0xecc9658a, 0x4f5c0114, 0xd96c0663, - 0x633d0ffa, 0xf50d088d, 0xc8206e3b, 0x5e10694c, 0xe44160d5, - 0x727167a2, 0xd1e4033c, 0x47d4044b, 0xfd850dd2, 0x6bb50aa5, - 0xfaa8b535, 0x6c98b242, 0xd6c9bbdb, 0x40f9bcac, 0xe36cd832, - 0x755cdf45, 0xcf0dd6dc, 0x593dd1ab, 0xac30d926, 0x3a00de51, - 0x8051d7c8, 0x1661d0bf, 0xb5f4b421, 0x23c4b356, 0x9995bacf, - 0x0fa5bdb8, 0x9eb80228, 0x0888055f, 0xb2d90cc6, 0x24e90bb1, - 0x877c6f2f, 0x114c6858, 0xab1d61c1, 0x3d2d66b6, 0x9041dc76, - 0x0671db01, 0xbc20d298, 0x2a10d5ef, 0x8985b171, 0x1fb5b606, - 0xa5e4bf9f, 0x33d4b8e8, 0xa2c90778, 0x34f9000f, 0x8ea80996, - 0x18980ee1, 0xbb0d6a7f, 0x2d3d6d08, 0x976c6491, 0x015c63e6, - 0xf4516b6b, 0x62616c1c, 0xd8306585, 0x4e0062f2, 0xed95066c, - 0x7ba5011b, 0xc1f40882, 0x57c40ff5, 0xc6d9b065, 0x50e9b712, - 0xeab8be8b, 0x7c88b9fc, 0xdf1ddd62, 0x492dda15, 0xf37cd38c, - 0x654cd4fb, 0x5861b24d, 0xce51b53a, 0x7400bca3, 0xe230bbd4, - 0x41a5df4a, 0xd795d83d, 0x6dc4d1a4, 0xfbf4d6d3, 0x6ae96943, - 0xfcd96e34, 0x468867ad, 0xd0b860da, 0x732d0444, 0xe51d0333, - 0x5f4c0aaa, 0xc97c0ddd, 0x3c710550, 0xaa410227, 0x10100bbe, - 0x86200cc9, 0x25b56857, 0xb3856f20, 0x09d466b9, 0x9fe461ce, - 0x0ef9de5e, 0x98c9d929, 0x2298d0b0, 0xb4a8d7c7, 0x173db359, - 0x810db42e, 0x3b5cbdb7, 0xad6cbac0, 0x2083b8ed, 0xb6b3bf9a, - 0x0ce2b603, 0x9ad2b174, 0x3947d5ea, 0xaf77d29d, 0x1526db04, - 0x8316dc73, 0x120b63e3, 0x843b6494, 0x3e6a6d0d, 0xa85a6a7a, - 0x0bcf0ee4, 0x9dff0993, 0x27ae000a, 0xb19e077d, 0x44930ff0, - 0xd2a30887, 0x68f2011e, 0xfec20669, 0x5d5762f7, 0xcb676580, - 0x71366c19, 0xe7066b6e, 0x761bd4fe, 0xe02bd389, 0x5a7ada10, - 0xcc4add67, 0x6fdfb9f9, 0xf9efbe8e, 0x43beb717, 0xd58eb060, - 0xe8a3d6d6, 0x7e93d1a1, 0xc4c2d838, 0x52f2df4f, 0xf167bbd1, - 0x6757bca6, 0xdd06b53f, 0x4b36b248, 0xda2b0dd8, 0x4c1b0aaf, - 0xf64a0336, 0x607a0441, 0xc3ef60df, 0x55df67a8, 0xef8e6e31, - 0x79be6946, 0x8cb361cb, 0x1a8366bc, 0xa0d26f25, 0x36e26852, - 0x95770ccc, 0x03470bbb, 0xb9160222, 0x2f260555, 0xbe3bbac5, - 0x280bbdb2, 0x925ab42b, 0x046ab35c, 0xa7ffd7c2, 0x31cfd0b5, - 0x8b9ed92c, 0x1daede5b, 0xb0c2649b, 0x26f263ec, 0x9ca36a75, - 0x0a936d02, 0xa906099c, 0x3f360eeb, 0x85670772, 0x13570005, - 0x824abf95, 0x147ab8e2, 0xae2bb17b, 0x381bb60c, 0x9b8ed292, - 0x0dbed5e5, 0xb7efdc7c, 0x21dfdb0b, 0xd4d2d386, 0x42e2d4f1, - 0xf8b3dd68, 0x6e83da1f, 0xcd16be81, 0x5b26b9f6, 0xe177b06f, - 0x7747b718, 0xe65a0888, 0x706a0fff, 0xca3b0666, 0x5c0b0111, - 0xff9e658f, 0x69ae62f8, 0xd3ff6b61, 0x45cf6c16, 0x78e20aa0, - 0xeed20dd7, 0x5483044e, 0xc2b30339, 0x612667a7, 0xf71660d0, - 0x4d476949, 0xdb776e3e, 0x4a6ad1ae, 0xdc5ad6d9, 0x660bdf40, - 0xf03bd837, 0x53aebca9, 0xc59ebbde, 0x7fcfb247, 0xe9ffb530, - 0x1cf2bdbd, 0x8ac2baca, 0x3093b353, 0xa6a3b424, 0x0536d0ba, - 0x9306d7cd, 0x2957de54, 0xbf67d923, 0x2e7a66b3, 0xb84a61c4, - 0x021b685d, 0x942b6f2a, 0x37be0bb4, 0xa18e0cc3, 0x1bdf055a, - 0x8def022d}; - -#endif - -#if N == 1 - -#if W == 8 - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0xccaa009e, 0x4225077d, 0x8e8f07e3, 0x844a0efa, - 0x48e00e64, 0xc66f0987, 0x0ac50919, 0xd3e51bb5, 0x1f4f1b2b, - 0x91c01cc8, 0x5d6a1c56, 0x57af154f, 0x9b0515d1, 0x158a1232, - 0xd92012ac, 0x7cbb312b, 0xb01131b5, 0x3e9e3656, 0xf23436c8, - 0xf8f13fd1, 0x345b3f4f, 0xbad438ac, 0x767e3832, 0xaf5e2a9e, - 0x63f42a00, 0xed7b2de3, 0x21d12d7d, 0x2b142464, 0xe7be24fa, - 0x69312319, 0xa59b2387, 0xf9766256, 0x35dc62c8, 0xbb53652b, - 0x77f965b5, 0x7d3c6cac, 0xb1966c32, 0x3f196bd1, 0xf3b36b4f, - 0x2a9379e3, 0xe639797d, 0x68b67e9e, 0xa41c7e00, 0xaed97719, - 0x62737787, 0xecfc7064, 0x205670fa, 0x85cd537d, 0x496753e3, - 0xc7e85400, 0x0b42549e, 0x01875d87, 0xcd2d5d19, 0x43a25afa, - 0x8f085a64, 0x562848c8, 0x9a824856, 0x140d4fb5, 0xd8a74f2b, - 0xd2624632, 0x1ec846ac, 0x9047414f, 0x5ced41d1, 0x299dc2ed, - 0xe537c273, 0x6bb8c590, 0xa712c50e, 0xadd7cc17, 0x617dcc89, - 0xeff2cb6a, 0x2358cbf4, 0xfa78d958, 0x36d2d9c6, 0xb85dde25, - 0x74f7debb, 0x7e32d7a2, 0xb298d73c, 0x3c17d0df, 0xf0bdd041, - 0x5526f3c6, 0x998cf358, 0x1703f4bb, 0xdba9f425, 0xd16cfd3c, - 0x1dc6fda2, 0x9349fa41, 0x5fe3fadf, 0x86c3e873, 0x4a69e8ed, - 0xc4e6ef0e, 0x084cef90, 0x0289e689, 0xce23e617, 0x40ace1f4, - 0x8c06e16a, 0xd0eba0bb, 0x1c41a025, 0x92cea7c6, 0x5e64a758, - 0x54a1ae41, 0x980baedf, 0x1684a93c, 0xda2ea9a2, 0x030ebb0e, - 0xcfa4bb90, 0x412bbc73, 0x8d81bced, 0x8744b5f4, 0x4beeb56a, - 0xc561b289, 0x09cbb217, 0xac509190, 0x60fa910e, 0xee7596ed, - 0x22df9673, 0x281a9f6a, 0xe4b09ff4, 0x6a3f9817, 0xa6959889, - 0x7fb58a25, 0xb31f8abb, 0x3d908d58, 0xf13a8dc6, 0xfbff84df, - 0x37558441, 0xb9da83a2, 0x7570833c, 0x533b85da, 0x9f918544, - 0x111e82a7, 0xddb48239, 0xd7718b20, 0x1bdb8bbe, 0x95548c5d, - 0x59fe8cc3, 0x80de9e6f, 0x4c749ef1, 0xc2fb9912, 0x0e51998c, - 0x04949095, 0xc83e900b, 0x46b197e8, 0x8a1b9776, 0x2f80b4f1, - 0xe32ab46f, 0x6da5b38c, 0xa10fb312, 0xabcaba0b, 0x6760ba95, - 0xe9efbd76, 0x2545bde8, 0xfc65af44, 0x30cfafda, 0xbe40a839, - 0x72eaa8a7, 0x782fa1be, 0xb485a120, 0x3a0aa6c3, 0xf6a0a65d, - 0xaa4de78c, 0x66e7e712, 0xe868e0f1, 0x24c2e06f, 0x2e07e976, - 0xe2ade9e8, 0x6c22ee0b, 0xa088ee95, 0x79a8fc39, 0xb502fca7, - 0x3b8dfb44, 0xf727fbda, 0xfde2f2c3, 0x3148f25d, 0xbfc7f5be, - 0x736df520, 0xd6f6d6a7, 0x1a5cd639, 0x94d3d1da, 0x5879d144, - 0x52bcd85d, 0x9e16d8c3, 0x1099df20, 0xdc33dfbe, 0x0513cd12, - 0xc9b9cd8c, 0x4736ca6f, 0x8b9ccaf1, 0x8159c3e8, 0x4df3c376, - 0xc37cc495, 0x0fd6c40b, 0x7aa64737, 0xb60c47a9, 0x3883404a, - 0xf42940d4, 0xfeec49cd, 0x32464953, 0xbcc94eb0, 0x70634e2e, - 0xa9435c82, 0x65e95c1c, 0xeb665bff, 0x27cc5b61, 0x2d095278, - 0xe1a352e6, 0x6f2c5505, 0xa386559b, 0x061d761c, 0xcab77682, - 0x44387161, 0x889271ff, 0x825778e6, 0x4efd7878, 0xc0727f9b, - 0x0cd87f05, 0xd5f86da9, 0x19526d37, 0x97dd6ad4, 0x5b776a4a, - 0x51b26353, 0x9d1863cd, 0x1397642e, 0xdf3d64b0, 0x83d02561, - 0x4f7a25ff, 0xc1f5221c, 0x0d5f2282, 0x079a2b9b, 0xcb302b05, - 0x45bf2ce6, 0x89152c78, 0x50353ed4, 0x9c9f3e4a, 0x121039a9, - 0xdeba3937, 0xd47f302e, 0x18d530b0, 0x965a3753, 0x5af037cd, - 0xff6b144a, 0x33c114d4, 0xbd4e1337, 0x71e413a9, 0x7b211ab0, - 0xb78b1a2e, 0x39041dcd, 0xf5ae1d53, 0x2c8e0fff, 0xe0240f61, - 0x6eab0882, 0xa201081c, 0xa8c40105, 0x646e019b, 0xeae10678, - 0x264b06e6}, - {0x00000000, 0xa6770bb4, 0x979f1129, 0x31e81a9d, 0xf44f2413, - 0x52382fa7, 0x63d0353a, 0xc5a73e8e, 0x33ef4e67, 0x959845d3, - 0xa4705f4e, 0x020754fa, 0xc7a06a74, 0x61d761c0, 0x503f7b5d, - 0xf64870e9, 0x67de9cce, 0xc1a9977a, 0xf0418de7, 0x56368653, - 0x9391b8dd, 0x35e6b369, 0x040ea9f4, 0xa279a240, 0x5431d2a9, - 0xf246d91d, 0xc3aec380, 0x65d9c834, 0xa07ef6ba, 0x0609fd0e, - 0x37e1e793, 0x9196ec27, 0xcfbd399c, 0x69ca3228, 0x582228b5, - 0xfe552301, 0x3bf21d8f, 0x9d85163b, 0xac6d0ca6, 0x0a1a0712, - 0xfc5277fb, 0x5a257c4f, 0x6bcd66d2, 0xcdba6d66, 0x081d53e8, - 0xae6a585c, 0x9f8242c1, 0x39f54975, 0xa863a552, 0x0e14aee6, - 0x3ffcb47b, 0x998bbfcf, 0x5c2c8141, 0xfa5b8af5, 0xcbb39068, - 0x6dc49bdc, 0x9b8ceb35, 0x3dfbe081, 0x0c13fa1c, 0xaa64f1a8, - 0x6fc3cf26, 0xc9b4c492, 0xf85cde0f, 0x5e2bd5bb, 0x440b7579, - 0xe27c7ecd, 0xd3946450, 0x75e36fe4, 0xb044516a, 0x16335ade, - 0x27db4043, 0x81ac4bf7, 0x77e43b1e, 0xd19330aa, 0xe07b2a37, - 0x460c2183, 0x83ab1f0d, 0x25dc14b9, 0x14340e24, 0xb2430590, - 0x23d5e9b7, 0x85a2e203, 0xb44af89e, 0x123df32a, 0xd79acda4, - 0x71edc610, 0x4005dc8d, 0xe672d739, 0x103aa7d0, 0xb64dac64, - 0x87a5b6f9, 0x21d2bd4d, 0xe47583c3, 0x42028877, 0x73ea92ea, - 0xd59d995e, 0x8bb64ce5, 0x2dc14751, 0x1c295dcc, 0xba5e5678, - 0x7ff968f6, 0xd98e6342, 0xe86679df, 0x4e11726b, 0xb8590282, - 0x1e2e0936, 0x2fc613ab, 0x89b1181f, 0x4c162691, 0xea612d25, - 0xdb8937b8, 0x7dfe3c0c, 0xec68d02b, 0x4a1fdb9f, 0x7bf7c102, - 0xdd80cab6, 0x1827f438, 0xbe50ff8c, 0x8fb8e511, 0x29cfeea5, - 0xdf879e4c, 0x79f095f8, 0x48188f65, 0xee6f84d1, 0x2bc8ba5f, - 0x8dbfb1eb, 0xbc57ab76, 0x1a20a0c2, 0x8816eaf2, 0x2e61e146, - 0x1f89fbdb, 0xb9fef06f, 0x7c59cee1, 0xda2ec555, 0xebc6dfc8, - 0x4db1d47c, 0xbbf9a495, 0x1d8eaf21, 0x2c66b5bc, 0x8a11be08, - 0x4fb68086, 0xe9c18b32, 0xd82991af, 0x7e5e9a1b, 0xefc8763c, - 0x49bf7d88, 0x78576715, 0xde206ca1, 0x1b87522f, 0xbdf0599b, - 0x8c184306, 0x2a6f48b2, 0xdc27385b, 0x7a5033ef, 0x4bb82972, - 0xedcf22c6, 0x28681c48, 0x8e1f17fc, 0xbff70d61, 0x198006d5, - 0x47abd36e, 0xe1dcd8da, 0xd034c247, 0x7643c9f3, 0xb3e4f77d, - 0x1593fcc9, 0x247be654, 0x820cede0, 0x74449d09, 0xd23396bd, - 0xe3db8c20, 0x45ac8794, 0x800bb91a, 0x267cb2ae, 0x1794a833, - 0xb1e3a387, 0x20754fa0, 0x86024414, 0xb7ea5e89, 0x119d553d, - 0xd43a6bb3, 0x724d6007, 0x43a57a9a, 0xe5d2712e, 0x139a01c7, - 0xb5ed0a73, 0x840510ee, 0x22721b5a, 0xe7d525d4, 0x41a22e60, - 0x704a34fd, 0xd63d3f49, 0xcc1d9f8b, 0x6a6a943f, 0x5b828ea2, - 0xfdf58516, 0x3852bb98, 0x9e25b02c, 0xafcdaab1, 0x09baa105, - 0xfff2d1ec, 0x5985da58, 0x686dc0c5, 0xce1acb71, 0x0bbdf5ff, - 0xadcafe4b, 0x9c22e4d6, 0x3a55ef62, 0xabc30345, 0x0db408f1, - 0x3c5c126c, 0x9a2b19d8, 0x5f8c2756, 0xf9fb2ce2, 0xc813367f, - 0x6e643dcb, 0x982c4d22, 0x3e5b4696, 0x0fb35c0b, 0xa9c457bf, - 0x6c636931, 0xca146285, 0xfbfc7818, 0x5d8b73ac, 0x03a0a617, - 0xa5d7ada3, 0x943fb73e, 0x3248bc8a, 0xf7ef8204, 0x519889b0, - 0x6070932d, 0xc6079899, 0x304fe870, 0x9638e3c4, 0xa7d0f959, - 0x01a7f2ed, 0xc400cc63, 0x6277c7d7, 0x539fdd4a, 0xf5e8d6fe, - 0x647e3ad9, 0xc209316d, 0xf3e12bf0, 0x55962044, 0x90311eca, - 0x3646157e, 0x07ae0fe3, 0xa1d90457, 0x579174be, 0xf1e67f0a, - 0xc00e6597, 0x66796e23, 0xa3de50ad, 0x05a95b19, 0x34414184, - 0x92364a30}, - {0x00000000, 0xcb5cd3a5, 0x4dc8a10b, 0x869472ae, 0x9b914216, - 0x50cd91b3, 0xd659e31d, 0x1d0530b8, 0xec53826d, 0x270f51c8, - 0xa19b2366, 0x6ac7f0c3, 0x77c2c07b, 0xbc9e13de, 0x3a0a6170, - 0xf156b2d5, 0x03d6029b, 0xc88ad13e, 0x4e1ea390, 0x85427035, - 0x9847408d, 0x531b9328, 0xd58fe186, 0x1ed33223, 0xef8580f6, - 0x24d95353, 0xa24d21fd, 0x6911f258, 0x7414c2e0, 0xbf481145, - 0x39dc63eb, 0xf280b04e, 0x07ac0536, 0xccf0d693, 0x4a64a43d, - 0x81387798, 0x9c3d4720, 0x57619485, 0xd1f5e62b, 0x1aa9358e, - 0xebff875b, 0x20a354fe, 0xa6372650, 0x6d6bf5f5, 0x706ec54d, - 0xbb3216e8, 0x3da66446, 0xf6fab7e3, 0x047a07ad, 0xcf26d408, - 0x49b2a6a6, 0x82ee7503, 0x9feb45bb, 0x54b7961e, 0xd223e4b0, - 0x197f3715, 0xe82985c0, 0x23755665, 0xa5e124cb, 0x6ebdf76e, - 0x73b8c7d6, 0xb8e41473, 0x3e7066dd, 0xf52cb578, 0x0f580a6c, - 0xc404d9c9, 0x4290ab67, 0x89cc78c2, 0x94c9487a, 0x5f959bdf, - 0xd901e971, 0x125d3ad4, 0xe30b8801, 0x28575ba4, 0xaec3290a, - 0x659ffaaf, 0x789aca17, 0xb3c619b2, 0x35526b1c, 0xfe0eb8b9, - 0x0c8e08f7, 0xc7d2db52, 0x4146a9fc, 0x8a1a7a59, 0x971f4ae1, - 0x5c439944, 0xdad7ebea, 0x118b384f, 0xe0dd8a9a, 0x2b81593f, - 0xad152b91, 0x6649f834, 0x7b4cc88c, 0xb0101b29, 0x36846987, - 0xfdd8ba22, 0x08f40f5a, 0xc3a8dcff, 0x453cae51, 0x8e607df4, - 0x93654d4c, 0x58399ee9, 0xdeadec47, 0x15f13fe2, 0xe4a78d37, - 0x2ffb5e92, 0xa96f2c3c, 0x6233ff99, 0x7f36cf21, 0xb46a1c84, - 0x32fe6e2a, 0xf9a2bd8f, 0x0b220dc1, 0xc07ede64, 0x46eaacca, - 0x8db67f6f, 0x90b34fd7, 0x5bef9c72, 0xdd7beedc, 0x16273d79, - 0xe7718fac, 0x2c2d5c09, 0xaab92ea7, 0x61e5fd02, 0x7ce0cdba, - 0xb7bc1e1f, 0x31286cb1, 0xfa74bf14, 0x1eb014d8, 0xd5ecc77d, - 0x5378b5d3, 0x98246676, 0x852156ce, 0x4e7d856b, 0xc8e9f7c5, - 0x03b52460, 0xf2e396b5, 0x39bf4510, 0xbf2b37be, 0x7477e41b, - 0x6972d4a3, 0xa22e0706, 0x24ba75a8, 0xefe6a60d, 0x1d661643, - 0xd63ac5e6, 0x50aeb748, 0x9bf264ed, 0x86f75455, 0x4dab87f0, - 0xcb3ff55e, 0x006326fb, 0xf135942e, 0x3a69478b, 0xbcfd3525, - 0x77a1e680, 0x6aa4d638, 0xa1f8059d, 0x276c7733, 0xec30a496, - 0x191c11ee, 0xd240c24b, 0x54d4b0e5, 0x9f886340, 0x828d53f8, - 0x49d1805d, 0xcf45f2f3, 0x04192156, 0xf54f9383, 0x3e134026, - 0xb8873288, 0x73dbe12d, 0x6eded195, 0xa5820230, 0x2316709e, - 0xe84aa33b, 0x1aca1375, 0xd196c0d0, 0x5702b27e, 0x9c5e61db, - 0x815b5163, 0x4a0782c6, 0xcc93f068, 0x07cf23cd, 0xf6999118, - 0x3dc542bd, 0xbb513013, 0x700de3b6, 0x6d08d30e, 0xa65400ab, - 0x20c07205, 0xeb9ca1a0, 0x11e81eb4, 0xdab4cd11, 0x5c20bfbf, - 0x977c6c1a, 0x8a795ca2, 0x41258f07, 0xc7b1fda9, 0x0ced2e0c, - 0xfdbb9cd9, 0x36e74f7c, 0xb0733dd2, 0x7b2fee77, 0x662adecf, - 0xad760d6a, 0x2be27fc4, 0xe0beac61, 0x123e1c2f, 0xd962cf8a, - 0x5ff6bd24, 0x94aa6e81, 0x89af5e39, 0x42f38d9c, 0xc467ff32, - 0x0f3b2c97, 0xfe6d9e42, 0x35314de7, 0xb3a53f49, 0x78f9ecec, - 0x65fcdc54, 0xaea00ff1, 0x28347d5f, 0xe368aefa, 0x16441b82, - 0xdd18c827, 0x5b8cba89, 0x90d0692c, 0x8dd55994, 0x46898a31, - 0xc01df89f, 0x0b412b3a, 0xfa1799ef, 0x314b4a4a, 0xb7df38e4, - 0x7c83eb41, 0x6186dbf9, 0xaada085c, 0x2c4e7af2, 0xe712a957, - 0x15921919, 0xdececabc, 0x585ab812, 0x93066bb7, 0x8e035b0f, - 0x455f88aa, 0xc3cbfa04, 0x089729a1, 0xf9c19b74, 0x329d48d1, - 0xb4093a7f, 0x7f55e9da, 0x6250d962, 0xa90c0ac7, 0x2f987869, - 0xe4c4abcc}, - {0x00000000, 0x3d6029b0, 0x7ac05360, 0x47a07ad0, 0xf580a6c0, - 0xc8e08f70, 0x8f40f5a0, 0xb220dc10, 0x30704bc1, 0x0d106271, - 0x4ab018a1, 0x77d03111, 0xc5f0ed01, 0xf890c4b1, 0xbf30be61, - 0x825097d1, 0x60e09782, 0x5d80be32, 0x1a20c4e2, 0x2740ed52, - 0x95603142, 0xa80018f2, 0xefa06222, 0xd2c04b92, 0x5090dc43, - 0x6df0f5f3, 0x2a508f23, 0x1730a693, 0xa5107a83, 0x98705333, - 0xdfd029e3, 0xe2b00053, 0xc1c12f04, 0xfca106b4, 0xbb017c64, - 0x866155d4, 0x344189c4, 0x0921a074, 0x4e81daa4, 0x73e1f314, - 0xf1b164c5, 0xccd14d75, 0x8b7137a5, 0xb6111e15, 0x0431c205, - 0x3951ebb5, 0x7ef19165, 0x4391b8d5, 0xa121b886, 0x9c419136, - 0xdbe1ebe6, 0xe681c256, 0x54a11e46, 0x69c137f6, 0x2e614d26, - 0x13016496, 0x9151f347, 0xac31daf7, 0xeb91a027, 0xd6f18997, - 0x64d15587, 0x59b17c37, 0x1e1106e7, 0x23712f57, 0x58f35849, - 0x659371f9, 0x22330b29, 0x1f532299, 0xad73fe89, 0x9013d739, - 0xd7b3ade9, 0xead38459, 0x68831388, 0x55e33a38, 0x124340e8, - 0x2f236958, 0x9d03b548, 0xa0639cf8, 0xe7c3e628, 0xdaa3cf98, - 0x3813cfcb, 0x0573e67b, 0x42d39cab, 0x7fb3b51b, 0xcd93690b, - 0xf0f340bb, 0xb7533a6b, 0x8a3313db, 0x0863840a, 0x3503adba, - 0x72a3d76a, 0x4fc3feda, 0xfde322ca, 0xc0830b7a, 0x872371aa, - 0xba43581a, 0x9932774d, 0xa4525efd, 0xe3f2242d, 0xde920d9d, - 0x6cb2d18d, 0x51d2f83d, 0x167282ed, 0x2b12ab5d, 0xa9423c8c, - 0x9422153c, 0xd3826fec, 0xeee2465c, 0x5cc29a4c, 0x61a2b3fc, - 0x2602c92c, 0x1b62e09c, 0xf9d2e0cf, 0xc4b2c97f, 0x8312b3af, - 0xbe729a1f, 0x0c52460f, 0x31326fbf, 0x7692156f, 0x4bf23cdf, - 0xc9a2ab0e, 0xf4c282be, 0xb362f86e, 0x8e02d1de, 0x3c220dce, - 0x0142247e, 0x46e25eae, 0x7b82771e, 0xb1e6b092, 0x8c869922, - 0xcb26e3f2, 0xf646ca42, 0x44661652, 0x79063fe2, 0x3ea64532, - 0x03c66c82, 0x8196fb53, 0xbcf6d2e3, 0xfb56a833, 0xc6368183, - 0x74165d93, 0x49767423, 0x0ed60ef3, 0x33b62743, 0xd1062710, - 0xec660ea0, 0xabc67470, 0x96a65dc0, 0x248681d0, 0x19e6a860, - 0x5e46d2b0, 0x6326fb00, 0xe1766cd1, 0xdc164561, 0x9bb63fb1, - 0xa6d61601, 0x14f6ca11, 0x2996e3a1, 0x6e369971, 0x5356b0c1, - 0x70279f96, 0x4d47b626, 0x0ae7ccf6, 0x3787e546, 0x85a73956, - 0xb8c710e6, 0xff676a36, 0xc2074386, 0x4057d457, 0x7d37fde7, - 0x3a978737, 0x07f7ae87, 0xb5d77297, 0x88b75b27, 0xcf1721f7, - 0xf2770847, 0x10c70814, 0x2da721a4, 0x6a075b74, 0x576772c4, - 0xe547aed4, 0xd8278764, 0x9f87fdb4, 0xa2e7d404, 0x20b743d5, - 0x1dd76a65, 0x5a7710b5, 0x67173905, 0xd537e515, 0xe857cca5, - 0xaff7b675, 0x92979fc5, 0xe915e8db, 0xd475c16b, 0x93d5bbbb, - 0xaeb5920b, 0x1c954e1b, 0x21f567ab, 0x66551d7b, 0x5b3534cb, - 0xd965a31a, 0xe4058aaa, 0xa3a5f07a, 0x9ec5d9ca, 0x2ce505da, - 0x11852c6a, 0x562556ba, 0x6b457f0a, 0x89f57f59, 0xb49556e9, - 0xf3352c39, 0xce550589, 0x7c75d999, 0x4115f029, 0x06b58af9, - 0x3bd5a349, 0xb9853498, 0x84e51d28, 0xc34567f8, 0xfe254e48, - 0x4c059258, 0x7165bbe8, 0x36c5c138, 0x0ba5e888, 0x28d4c7df, - 0x15b4ee6f, 0x521494bf, 0x6f74bd0f, 0xdd54611f, 0xe03448af, - 0xa794327f, 0x9af41bcf, 0x18a48c1e, 0x25c4a5ae, 0x6264df7e, - 0x5f04f6ce, 0xed242ade, 0xd044036e, 0x97e479be, 0xaa84500e, - 0x4834505d, 0x755479ed, 0x32f4033d, 0x0f942a8d, 0xbdb4f69d, - 0x80d4df2d, 0xc774a5fd, 0xfa148c4d, 0x78441b9c, 0x4524322c, - 0x028448fc, 0x3fe4614c, 0x8dc4bd5c, 0xb0a494ec, 0xf704ee3c, - 0xca64c78c}, - {0x00000000, 0xb8bc6765, 0xaa09c88b, 0x12b5afee, 0x8f629757, - 0x37def032, 0x256b5fdc, 0x9dd738b9, 0xc5b428ef, 0x7d084f8a, - 0x6fbde064, 0xd7018701, 0x4ad6bfb8, 0xf26ad8dd, 0xe0df7733, - 0x58631056, 0x5019579f, 0xe8a530fa, 0xfa109f14, 0x42acf871, - 0xdf7bc0c8, 0x67c7a7ad, 0x75720843, 0xcdce6f26, 0x95ad7f70, - 0x2d111815, 0x3fa4b7fb, 0x8718d09e, 0x1acfe827, 0xa2738f42, - 0xb0c620ac, 0x087a47c9, 0xa032af3e, 0x188ec85b, 0x0a3b67b5, - 0xb28700d0, 0x2f503869, 0x97ec5f0c, 0x8559f0e2, 0x3de59787, - 0x658687d1, 0xdd3ae0b4, 0xcf8f4f5a, 0x7733283f, 0xeae41086, - 0x525877e3, 0x40edd80d, 0xf851bf68, 0xf02bf8a1, 0x48979fc4, - 0x5a22302a, 0xe29e574f, 0x7f496ff6, 0xc7f50893, 0xd540a77d, - 0x6dfcc018, 0x359fd04e, 0x8d23b72b, 0x9f9618c5, 0x272a7fa0, - 0xbafd4719, 0x0241207c, 0x10f48f92, 0xa848e8f7, 0x9b14583d, - 0x23a83f58, 0x311d90b6, 0x89a1f7d3, 0x1476cf6a, 0xaccaa80f, - 0xbe7f07e1, 0x06c36084, 0x5ea070d2, 0xe61c17b7, 0xf4a9b859, - 0x4c15df3c, 0xd1c2e785, 0x697e80e0, 0x7bcb2f0e, 0xc377486b, - 0xcb0d0fa2, 0x73b168c7, 0x6104c729, 0xd9b8a04c, 0x446f98f5, - 0xfcd3ff90, 0xee66507e, 0x56da371b, 0x0eb9274d, 0xb6054028, - 0xa4b0efc6, 0x1c0c88a3, 0x81dbb01a, 0x3967d77f, 0x2bd27891, - 0x936e1ff4, 0x3b26f703, 0x839a9066, 0x912f3f88, 0x299358ed, - 0xb4446054, 0x0cf80731, 0x1e4da8df, 0xa6f1cfba, 0xfe92dfec, - 0x462eb889, 0x549b1767, 0xec277002, 0x71f048bb, 0xc94c2fde, - 0xdbf98030, 0x6345e755, 0x6b3fa09c, 0xd383c7f9, 0xc1366817, - 0x798a0f72, 0xe45d37cb, 0x5ce150ae, 0x4e54ff40, 0xf6e89825, - 0xae8b8873, 0x1637ef16, 0x048240f8, 0xbc3e279d, 0x21e91f24, - 0x99557841, 0x8be0d7af, 0x335cb0ca, 0xed59b63b, 0x55e5d15e, - 0x47507eb0, 0xffec19d5, 0x623b216c, 0xda874609, 0xc832e9e7, - 0x708e8e82, 0x28ed9ed4, 0x9051f9b1, 0x82e4565f, 0x3a58313a, - 0xa78f0983, 0x1f336ee6, 0x0d86c108, 0xb53aa66d, 0xbd40e1a4, - 0x05fc86c1, 0x1749292f, 0xaff54e4a, 0x322276f3, 0x8a9e1196, - 0x982bbe78, 0x2097d91d, 0x78f4c94b, 0xc048ae2e, 0xd2fd01c0, - 0x6a4166a5, 0xf7965e1c, 0x4f2a3979, 0x5d9f9697, 0xe523f1f2, - 0x4d6b1905, 0xf5d77e60, 0xe762d18e, 0x5fdeb6eb, 0xc2098e52, - 0x7ab5e937, 0x680046d9, 0xd0bc21bc, 0x88df31ea, 0x3063568f, - 0x22d6f961, 0x9a6a9e04, 0x07bda6bd, 0xbf01c1d8, 0xadb46e36, - 0x15080953, 0x1d724e9a, 0xa5ce29ff, 0xb77b8611, 0x0fc7e174, - 0x9210d9cd, 0x2aacbea8, 0x38191146, 0x80a57623, 0xd8c66675, - 0x607a0110, 0x72cfaefe, 0xca73c99b, 0x57a4f122, 0xef189647, - 0xfdad39a9, 0x45115ecc, 0x764dee06, 0xcef18963, 0xdc44268d, - 0x64f841e8, 0xf92f7951, 0x41931e34, 0x5326b1da, 0xeb9ad6bf, - 0xb3f9c6e9, 0x0b45a18c, 0x19f00e62, 0xa14c6907, 0x3c9b51be, - 0x842736db, 0x96929935, 0x2e2efe50, 0x2654b999, 0x9ee8defc, - 0x8c5d7112, 0x34e11677, 0xa9362ece, 0x118a49ab, 0x033fe645, - 0xbb838120, 0xe3e09176, 0x5b5cf613, 0x49e959fd, 0xf1553e98, - 0x6c820621, 0xd43e6144, 0xc68bceaa, 0x7e37a9cf, 0xd67f4138, - 0x6ec3265d, 0x7c7689b3, 0xc4caeed6, 0x591dd66f, 0xe1a1b10a, - 0xf3141ee4, 0x4ba87981, 0x13cb69d7, 0xab770eb2, 0xb9c2a15c, - 0x017ec639, 0x9ca9fe80, 0x241599e5, 0x36a0360b, 0x8e1c516e, - 0x866616a7, 0x3eda71c2, 0x2c6fde2c, 0x94d3b949, 0x090481f0, - 0xb1b8e695, 0xa30d497b, 0x1bb12e1e, 0x43d23e48, 0xfb6e592d, - 0xe9dbf6c3, 0x516791a6, 0xccb0a91f, 0x740cce7a, 0x66b96194, - 0xde0506f1}, - {0x00000000, 0x01c26a37, 0x0384d46e, 0x0246be59, 0x0709a8dc, - 0x06cbc2eb, 0x048d7cb2, 0x054f1685, 0x0e1351b8, 0x0fd13b8f, - 0x0d9785d6, 0x0c55efe1, 0x091af964, 0x08d89353, 0x0a9e2d0a, - 0x0b5c473d, 0x1c26a370, 0x1de4c947, 0x1fa2771e, 0x1e601d29, - 0x1b2f0bac, 0x1aed619b, 0x18abdfc2, 0x1969b5f5, 0x1235f2c8, - 0x13f798ff, 0x11b126a6, 0x10734c91, 0x153c5a14, 0x14fe3023, - 0x16b88e7a, 0x177ae44d, 0x384d46e0, 0x398f2cd7, 0x3bc9928e, - 0x3a0bf8b9, 0x3f44ee3c, 0x3e86840b, 0x3cc03a52, 0x3d025065, - 0x365e1758, 0x379c7d6f, 0x35dac336, 0x3418a901, 0x3157bf84, - 0x3095d5b3, 0x32d36bea, 0x331101dd, 0x246be590, 0x25a98fa7, - 0x27ef31fe, 0x262d5bc9, 0x23624d4c, 0x22a0277b, 0x20e69922, - 0x2124f315, 0x2a78b428, 0x2bbade1f, 0x29fc6046, 0x283e0a71, - 0x2d711cf4, 0x2cb376c3, 0x2ef5c89a, 0x2f37a2ad, 0x709a8dc0, - 0x7158e7f7, 0x731e59ae, 0x72dc3399, 0x7793251c, 0x76514f2b, - 0x7417f172, 0x75d59b45, 0x7e89dc78, 0x7f4bb64f, 0x7d0d0816, - 0x7ccf6221, 0x798074a4, 0x78421e93, 0x7a04a0ca, 0x7bc6cafd, - 0x6cbc2eb0, 0x6d7e4487, 0x6f38fade, 0x6efa90e9, 0x6bb5866c, - 0x6a77ec5b, 0x68315202, 0x69f33835, 0x62af7f08, 0x636d153f, - 0x612bab66, 0x60e9c151, 0x65a6d7d4, 0x6464bde3, 0x662203ba, - 0x67e0698d, 0x48d7cb20, 0x4915a117, 0x4b531f4e, 0x4a917579, - 0x4fde63fc, 0x4e1c09cb, 0x4c5ab792, 0x4d98dda5, 0x46c49a98, - 0x4706f0af, 0x45404ef6, 0x448224c1, 0x41cd3244, 0x400f5873, - 0x4249e62a, 0x438b8c1d, 0x54f16850, 0x55330267, 0x5775bc3e, - 0x56b7d609, 0x53f8c08c, 0x523aaabb, 0x507c14e2, 0x51be7ed5, - 0x5ae239e8, 0x5b2053df, 0x5966ed86, 0x58a487b1, 0x5deb9134, - 0x5c29fb03, 0x5e6f455a, 0x5fad2f6d, 0xe1351b80, 0xe0f771b7, - 0xe2b1cfee, 0xe373a5d9, 0xe63cb35c, 0xe7fed96b, 0xe5b86732, - 0xe47a0d05, 0xef264a38, 0xeee4200f, 0xeca29e56, 0xed60f461, - 0xe82fe2e4, 0xe9ed88d3, 0xebab368a, 0xea695cbd, 0xfd13b8f0, - 0xfcd1d2c7, 0xfe976c9e, 0xff5506a9, 0xfa1a102c, 0xfbd87a1b, - 0xf99ec442, 0xf85cae75, 0xf300e948, 0xf2c2837f, 0xf0843d26, - 0xf1465711, 0xf4094194, 0xf5cb2ba3, 0xf78d95fa, 0xf64fffcd, - 0xd9785d60, 0xd8ba3757, 0xdafc890e, 0xdb3ee339, 0xde71f5bc, - 0xdfb39f8b, 0xddf521d2, 0xdc374be5, 0xd76b0cd8, 0xd6a966ef, - 0xd4efd8b6, 0xd52db281, 0xd062a404, 0xd1a0ce33, 0xd3e6706a, - 0xd2241a5d, 0xc55efe10, 0xc49c9427, 0xc6da2a7e, 0xc7184049, - 0xc25756cc, 0xc3953cfb, 0xc1d382a2, 0xc011e895, 0xcb4dafa8, - 0xca8fc59f, 0xc8c97bc6, 0xc90b11f1, 0xcc440774, 0xcd866d43, - 0xcfc0d31a, 0xce02b92d, 0x91af9640, 0x906dfc77, 0x922b422e, - 0x93e92819, 0x96a63e9c, 0x976454ab, 0x9522eaf2, 0x94e080c5, - 0x9fbcc7f8, 0x9e7eadcf, 0x9c381396, 0x9dfa79a1, 0x98b56f24, - 0x99770513, 0x9b31bb4a, 0x9af3d17d, 0x8d893530, 0x8c4b5f07, - 0x8e0de15e, 0x8fcf8b69, 0x8a809dec, 0x8b42f7db, 0x89044982, - 0x88c623b5, 0x839a6488, 0x82580ebf, 0x801eb0e6, 0x81dcdad1, - 0x8493cc54, 0x8551a663, 0x8717183a, 0x86d5720d, 0xa9e2d0a0, - 0xa820ba97, 0xaa6604ce, 0xaba46ef9, 0xaeeb787c, 0xaf29124b, - 0xad6fac12, 0xacadc625, 0xa7f18118, 0xa633eb2f, 0xa4755576, - 0xa5b73f41, 0xa0f829c4, 0xa13a43f3, 0xa37cfdaa, 0xa2be979d, - 0xb5c473d0, 0xb40619e7, 0xb640a7be, 0xb782cd89, 0xb2cddb0c, - 0xb30fb13b, 0xb1490f62, 0xb08b6555, 0xbbd72268, 0xba15485f, - 0xb853f606, 0xb9919c31, 0xbcde8ab4, 0xbd1ce083, 0xbf5a5eda, - 0xbe9834ed}, - {0x00000000, 0x191b3141, 0x32366282, 0x2b2d53c3, 0x646cc504, - 0x7d77f445, 0x565aa786, 0x4f4196c7, 0xc8d98a08, 0xd1c2bb49, - 0xfaefe88a, 0xe3f4d9cb, 0xacb54f0c, 0xb5ae7e4d, 0x9e832d8e, - 0x87981ccf, 0x4ac21251, 0x53d92310, 0x78f470d3, 0x61ef4192, - 0x2eaed755, 0x37b5e614, 0x1c98b5d7, 0x05838496, 0x821b9859, - 0x9b00a918, 0xb02dfadb, 0xa936cb9a, 0xe6775d5d, 0xff6c6c1c, - 0xd4413fdf, 0xcd5a0e9e, 0x958424a2, 0x8c9f15e3, 0xa7b24620, - 0xbea97761, 0xf1e8e1a6, 0xe8f3d0e7, 0xc3de8324, 0xdac5b265, - 0x5d5daeaa, 0x44469feb, 0x6f6bcc28, 0x7670fd69, 0x39316bae, - 0x202a5aef, 0x0b07092c, 0x121c386d, 0xdf4636f3, 0xc65d07b2, - 0xed705471, 0xf46b6530, 0xbb2af3f7, 0xa231c2b6, 0x891c9175, - 0x9007a034, 0x179fbcfb, 0x0e848dba, 0x25a9de79, 0x3cb2ef38, - 0x73f379ff, 0x6ae848be, 0x41c51b7d, 0x58de2a3c, 0xf0794f05, - 0xe9627e44, 0xc24f2d87, 0xdb541cc6, 0x94158a01, 0x8d0ebb40, - 0xa623e883, 0xbf38d9c2, 0x38a0c50d, 0x21bbf44c, 0x0a96a78f, - 0x138d96ce, 0x5ccc0009, 0x45d73148, 0x6efa628b, 0x77e153ca, - 0xbabb5d54, 0xa3a06c15, 0x888d3fd6, 0x91960e97, 0xded79850, - 0xc7cca911, 0xece1fad2, 0xf5facb93, 0x7262d75c, 0x6b79e61d, - 0x4054b5de, 0x594f849f, 0x160e1258, 0x0f152319, 0x243870da, - 0x3d23419b, 0x65fd6ba7, 0x7ce65ae6, 0x57cb0925, 0x4ed03864, - 0x0191aea3, 0x188a9fe2, 0x33a7cc21, 0x2abcfd60, 0xad24e1af, - 0xb43fd0ee, 0x9f12832d, 0x8609b26c, 0xc94824ab, 0xd05315ea, - 0xfb7e4629, 0xe2657768, 0x2f3f79f6, 0x362448b7, 0x1d091b74, - 0x04122a35, 0x4b53bcf2, 0x52488db3, 0x7965de70, 0x607eef31, - 0xe7e6f3fe, 0xfefdc2bf, 0xd5d0917c, 0xcccba03d, 0x838a36fa, - 0x9a9107bb, 0xb1bc5478, 0xa8a76539, 0x3b83984b, 0x2298a90a, - 0x09b5fac9, 0x10aecb88, 0x5fef5d4f, 0x46f46c0e, 0x6dd93fcd, - 0x74c20e8c, 0xf35a1243, 0xea412302, 0xc16c70c1, 0xd8774180, - 0x9736d747, 0x8e2de606, 0xa500b5c5, 0xbc1b8484, 0x71418a1a, - 0x685abb5b, 0x4377e898, 0x5a6cd9d9, 0x152d4f1e, 0x0c367e5f, - 0x271b2d9c, 0x3e001cdd, 0xb9980012, 0xa0833153, 0x8bae6290, - 0x92b553d1, 0xddf4c516, 0xc4eff457, 0xefc2a794, 0xf6d996d5, - 0xae07bce9, 0xb71c8da8, 0x9c31de6b, 0x852aef2a, 0xca6b79ed, - 0xd37048ac, 0xf85d1b6f, 0xe1462a2e, 0x66de36e1, 0x7fc507a0, - 0x54e85463, 0x4df36522, 0x02b2f3e5, 0x1ba9c2a4, 0x30849167, - 0x299fa026, 0xe4c5aeb8, 0xfdde9ff9, 0xd6f3cc3a, 0xcfe8fd7b, - 0x80a96bbc, 0x99b25afd, 0xb29f093e, 0xab84387f, 0x2c1c24b0, - 0x350715f1, 0x1e2a4632, 0x07317773, 0x4870e1b4, 0x516bd0f5, - 0x7a468336, 0x635db277, 0xcbfad74e, 0xd2e1e60f, 0xf9ccb5cc, - 0xe0d7848d, 0xaf96124a, 0xb68d230b, 0x9da070c8, 0x84bb4189, - 0x03235d46, 0x1a386c07, 0x31153fc4, 0x280e0e85, 0x674f9842, - 0x7e54a903, 0x5579fac0, 0x4c62cb81, 0x8138c51f, 0x9823f45e, - 0xb30ea79d, 0xaa1596dc, 0xe554001b, 0xfc4f315a, 0xd7626299, - 0xce7953d8, 0x49e14f17, 0x50fa7e56, 0x7bd72d95, 0x62cc1cd4, - 0x2d8d8a13, 0x3496bb52, 0x1fbbe891, 0x06a0d9d0, 0x5e7ef3ec, - 0x4765c2ad, 0x6c48916e, 0x7553a02f, 0x3a1236e8, 0x230907a9, - 0x0824546a, 0x113f652b, 0x96a779e4, 0x8fbc48a5, 0xa4911b66, - 0xbd8a2a27, 0xf2cbbce0, 0xebd08da1, 0xc0fdde62, 0xd9e6ef23, - 0x14bce1bd, 0x0da7d0fc, 0x268a833f, 0x3f91b27e, 0x70d024b9, - 0x69cb15f8, 0x42e6463b, 0x5bfd777a, 0xdc656bb5, 0xc57e5af4, - 0xee530937, 0xf7483876, 0xb809aeb1, 0xa1129ff0, 0x8a3fcc33, - 0x9324fd72}, - {0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, - 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, - 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, - 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, - 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, - 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, - 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, - 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, - 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, - 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, - 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, - 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, - 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, - 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, - 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, - 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, - 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, - 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, - 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, - 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, - 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, - 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, - 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, - 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, - 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, - 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, - 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, - 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, - 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, - 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, - 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, - 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, - 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, - 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, - 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, - 0x2d02ef8d}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x0000000000000000, 0x9630077700000000, 0x2c610eee00000000, - 0xba51099900000000, 0x19c46d0700000000, 0x8ff46a7000000000, - 0x35a563e900000000, 0xa395649e00000000, 0x3288db0e00000000, - 0xa4b8dc7900000000, 0x1ee9d5e000000000, 0x88d9d29700000000, - 0x2b4cb60900000000, 0xbd7cb17e00000000, 0x072db8e700000000, - 0x911dbf9000000000, 0x6410b71d00000000, 0xf220b06a00000000, - 0x4871b9f300000000, 0xde41be8400000000, 0x7dd4da1a00000000, - 0xebe4dd6d00000000, 0x51b5d4f400000000, 0xc785d38300000000, - 0x56986c1300000000, 0xc0a86b6400000000, 0x7af962fd00000000, - 0xecc9658a00000000, 0x4f5c011400000000, 0xd96c066300000000, - 0x633d0ffa00000000, 0xf50d088d00000000, 0xc8206e3b00000000, - 0x5e10694c00000000, 0xe44160d500000000, 0x727167a200000000, - 0xd1e4033c00000000, 0x47d4044b00000000, 0xfd850dd200000000, - 0x6bb50aa500000000, 0xfaa8b53500000000, 0x6c98b24200000000, - 0xd6c9bbdb00000000, 0x40f9bcac00000000, 0xe36cd83200000000, - 0x755cdf4500000000, 0xcf0dd6dc00000000, 0x593dd1ab00000000, - 0xac30d92600000000, 0x3a00de5100000000, 0x8051d7c800000000, - 0x1661d0bf00000000, 0xb5f4b42100000000, 0x23c4b35600000000, - 0x9995bacf00000000, 0x0fa5bdb800000000, 0x9eb8022800000000, - 0x0888055f00000000, 0xb2d90cc600000000, 0x24e90bb100000000, - 0x877c6f2f00000000, 0x114c685800000000, 0xab1d61c100000000, - 0x3d2d66b600000000, 0x9041dc7600000000, 0x0671db0100000000, - 0xbc20d29800000000, 0x2a10d5ef00000000, 0x8985b17100000000, - 0x1fb5b60600000000, 0xa5e4bf9f00000000, 0x33d4b8e800000000, - 0xa2c9077800000000, 0x34f9000f00000000, 0x8ea8099600000000, - 0x18980ee100000000, 0xbb0d6a7f00000000, 0x2d3d6d0800000000, - 0x976c649100000000, 0x015c63e600000000, 0xf4516b6b00000000, - 0x62616c1c00000000, 0xd830658500000000, 0x4e0062f200000000, - 0xed95066c00000000, 0x7ba5011b00000000, 0xc1f4088200000000, - 0x57c40ff500000000, 0xc6d9b06500000000, 0x50e9b71200000000, - 0xeab8be8b00000000, 0x7c88b9fc00000000, 0xdf1ddd6200000000, - 0x492dda1500000000, 0xf37cd38c00000000, 0x654cd4fb00000000, - 0x5861b24d00000000, 0xce51b53a00000000, 0x7400bca300000000, - 0xe230bbd400000000, 0x41a5df4a00000000, 0xd795d83d00000000, - 0x6dc4d1a400000000, 0xfbf4d6d300000000, 0x6ae9694300000000, - 0xfcd96e3400000000, 0x468867ad00000000, 0xd0b860da00000000, - 0x732d044400000000, 0xe51d033300000000, 0x5f4c0aaa00000000, - 0xc97c0ddd00000000, 0x3c71055000000000, 0xaa41022700000000, - 0x10100bbe00000000, 0x86200cc900000000, 0x25b5685700000000, - 0xb3856f2000000000, 0x09d466b900000000, 0x9fe461ce00000000, - 0x0ef9de5e00000000, 0x98c9d92900000000, 0x2298d0b000000000, - 0xb4a8d7c700000000, 0x173db35900000000, 0x810db42e00000000, - 0x3b5cbdb700000000, 0xad6cbac000000000, 0x2083b8ed00000000, - 0xb6b3bf9a00000000, 0x0ce2b60300000000, 0x9ad2b17400000000, - 0x3947d5ea00000000, 0xaf77d29d00000000, 0x1526db0400000000, - 0x8316dc7300000000, 0x120b63e300000000, 0x843b649400000000, - 0x3e6a6d0d00000000, 0xa85a6a7a00000000, 0x0bcf0ee400000000, - 0x9dff099300000000, 0x27ae000a00000000, 0xb19e077d00000000, - 0x44930ff000000000, 0xd2a3088700000000, 0x68f2011e00000000, - 0xfec2066900000000, 0x5d5762f700000000, 0xcb67658000000000, - 0x71366c1900000000, 0xe7066b6e00000000, 0x761bd4fe00000000, - 0xe02bd38900000000, 0x5a7ada1000000000, 0xcc4add6700000000, - 0x6fdfb9f900000000, 0xf9efbe8e00000000, 0x43beb71700000000, - 0xd58eb06000000000, 0xe8a3d6d600000000, 0x7e93d1a100000000, - 0xc4c2d83800000000, 0x52f2df4f00000000, 0xf167bbd100000000, - 0x6757bca600000000, 0xdd06b53f00000000, 0x4b36b24800000000, - 0xda2b0dd800000000, 0x4c1b0aaf00000000, 0xf64a033600000000, - 0x607a044100000000, 0xc3ef60df00000000, 0x55df67a800000000, - 0xef8e6e3100000000, 0x79be694600000000, 0x8cb361cb00000000, - 0x1a8366bc00000000, 0xa0d26f2500000000, 0x36e2685200000000, - 0x95770ccc00000000, 0x03470bbb00000000, 0xb916022200000000, - 0x2f26055500000000, 0xbe3bbac500000000, 0x280bbdb200000000, - 0x925ab42b00000000, 0x046ab35c00000000, 0xa7ffd7c200000000, - 0x31cfd0b500000000, 0x8b9ed92c00000000, 0x1daede5b00000000, - 0xb0c2649b00000000, 0x26f263ec00000000, 0x9ca36a7500000000, - 0x0a936d0200000000, 0xa906099c00000000, 0x3f360eeb00000000, - 0x8567077200000000, 0x1357000500000000, 0x824abf9500000000, - 0x147ab8e200000000, 0xae2bb17b00000000, 0x381bb60c00000000, - 0x9b8ed29200000000, 0x0dbed5e500000000, 0xb7efdc7c00000000, - 0x21dfdb0b00000000, 0xd4d2d38600000000, 0x42e2d4f100000000, - 0xf8b3dd6800000000, 0x6e83da1f00000000, 0xcd16be8100000000, - 0x5b26b9f600000000, 0xe177b06f00000000, 0x7747b71800000000, - 0xe65a088800000000, 0x706a0fff00000000, 0xca3b066600000000, - 0x5c0b011100000000, 0xff9e658f00000000, 0x69ae62f800000000, - 0xd3ff6b6100000000, 0x45cf6c1600000000, 0x78e20aa000000000, - 0xeed20dd700000000, 0x5483044e00000000, 0xc2b3033900000000, - 0x612667a700000000, 0xf71660d000000000, 0x4d47694900000000, - 0xdb776e3e00000000, 0x4a6ad1ae00000000, 0xdc5ad6d900000000, - 0x660bdf4000000000, 0xf03bd83700000000, 0x53aebca900000000, - 0xc59ebbde00000000, 0x7fcfb24700000000, 0xe9ffb53000000000, - 0x1cf2bdbd00000000, 0x8ac2baca00000000, 0x3093b35300000000, - 0xa6a3b42400000000, 0x0536d0ba00000000, 0x9306d7cd00000000, - 0x2957de5400000000, 0xbf67d92300000000, 0x2e7a66b300000000, - 0xb84a61c400000000, 0x021b685d00000000, 0x942b6f2a00000000, - 0x37be0bb400000000, 0xa18e0cc300000000, 0x1bdf055a00000000, - 0x8def022d00000000}, - {0x0000000000000000, 0x41311b1900000000, 0x8262363200000000, - 0xc3532d2b00000000, 0x04c56c6400000000, 0x45f4777d00000000, - 0x86a75a5600000000, 0xc796414f00000000, 0x088ad9c800000000, - 0x49bbc2d100000000, 0x8ae8effa00000000, 0xcbd9f4e300000000, - 0x0c4fb5ac00000000, 0x4d7eaeb500000000, 0x8e2d839e00000000, - 0xcf1c988700000000, 0x5112c24a00000000, 0x1023d95300000000, - 0xd370f47800000000, 0x9241ef6100000000, 0x55d7ae2e00000000, - 0x14e6b53700000000, 0xd7b5981c00000000, 0x9684830500000000, - 0x59981b8200000000, 0x18a9009b00000000, 0xdbfa2db000000000, - 0x9acb36a900000000, 0x5d5d77e600000000, 0x1c6c6cff00000000, - 0xdf3f41d400000000, 0x9e0e5acd00000000, 0xa224849500000000, - 0xe3159f8c00000000, 0x2046b2a700000000, 0x6177a9be00000000, - 0xa6e1e8f100000000, 0xe7d0f3e800000000, 0x2483dec300000000, - 0x65b2c5da00000000, 0xaaae5d5d00000000, 0xeb9f464400000000, - 0x28cc6b6f00000000, 0x69fd707600000000, 0xae6b313900000000, - 0xef5a2a2000000000, 0x2c09070b00000000, 0x6d381c1200000000, - 0xf33646df00000000, 0xb2075dc600000000, 0x715470ed00000000, - 0x30656bf400000000, 0xf7f32abb00000000, 0xb6c231a200000000, - 0x75911c8900000000, 0x34a0079000000000, 0xfbbc9f1700000000, - 0xba8d840e00000000, 0x79dea92500000000, 0x38efb23c00000000, - 0xff79f37300000000, 0xbe48e86a00000000, 0x7d1bc54100000000, - 0x3c2ade5800000000, 0x054f79f000000000, 0x447e62e900000000, - 0x872d4fc200000000, 0xc61c54db00000000, 0x018a159400000000, - 0x40bb0e8d00000000, 0x83e823a600000000, 0xc2d938bf00000000, - 0x0dc5a03800000000, 0x4cf4bb2100000000, 0x8fa7960a00000000, - 0xce968d1300000000, 0x0900cc5c00000000, 0x4831d74500000000, - 0x8b62fa6e00000000, 0xca53e17700000000, 0x545dbbba00000000, - 0x156ca0a300000000, 0xd63f8d8800000000, 0x970e969100000000, - 0x5098d7de00000000, 0x11a9ccc700000000, 0xd2fae1ec00000000, - 0x93cbfaf500000000, 0x5cd7627200000000, 0x1de6796b00000000, - 0xdeb5544000000000, 0x9f844f5900000000, 0x58120e1600000000, - 0x1923150f00000000, 0xda70382400000000, 0x9b41233d00000000, - 0xa76bfd6500000000, 0xe65ae67c00000000, 0x2509cb5700000000, - 0x6438d04e00000000, 0xa3ae910100000000, 0xe29f8a1800000000, - 0x21cca73300000000, 0x60fdbc2a00000000, 0xafe124ad00000000, - 0xeed03fb400000000, 0x2d83129f00000000, 0x6cb2098600000000, - 0xab2448c900000000, 0xea1553d000000000, 0x29467efb00000000, - 0x687765e200000000, 0xf6793f2f00000000, 0xb748243600000000, - 0x741b091d00000000, 0x352a120400000000, 0xf2bc534b00000000, - 0xb38d485200000000, 0x70de657900000000, 0x31ef7e6000000000, - 0xfef3e6e700000000, 0xbfc2fdfe00000000, 0x7c91d0d500000000, - 0x3da0cbcc00000000, 0xfa368a8300000000, 0xbb07919a00000000, - 0x7854bcb100000000, 0x3965a7a800000000, 0x4b98833b00000000, - 0x0aa9982200000000, 0xc9fab50900000000, 0x88cbae1000000000, - 0x4f5def5f00000000, 0x0e6cf44600000000, 0xcd3fd96d00000000, - 0x8c0ec27400000000, 0x43125af300000000, 0x022341ea00000000, - 0xc1706cc100000000, 0x804177d800000000, 0x47d7369700000000, - 0x06e62d8e00000000, 0xc5b500a500000000, 0x84841bbc00000000, - 0x1a8a417100000000, 0x5bbb5a6800000000, 0x98e8774300000000, - 0xd9d96c5a00000000, 0x1e4f2d1500000000, 0x5f7e360c00000000, - 0x9c2d1b2700000000, 0xdd1c003e00000000, 0x120098b900000000, - 0x533183a000000000, 0x9062ae8b00000000, 0xd153b59200000000, - 0x16c5f4dd00000000, 0x57f4efc400000000, 0x94a7c2ef00000000, - 0xd596d9f600000000, 0xe9bc07ae00000000, 0xa88d1cb700000000, - 0x6bde319c00000000, 0x2aef2a8500000000, 0xed796bca00000000, - 0xac4870d300000000, 0x6f1b5df800000000, 0x2e2a46e100000000, - 0xe136de6600000000, 0xa007c57f00000000, 0x6354e85400000000, - 0x2265f34d00000000, 0xe5f3b20200000000, 0xa4c2a91b00000000, - 0x6791843000000000, 0x26a09f2900000000, 0xb8aec5e400000000, - 0xf99fdefd00000000, 0x3accf3d600000000, 0x7bfde8cf00000000, - 0xbc6ba98000000000, 0xfd5ab29900000000, 0x3e099fb200000000, - 0x7f3884ab00000000, 0xb0241c2c00000000, 0xf115073500000000, - 0x32462a1e00000000, 0x7377310700000000, 0xb4e1704800000000, - 0xf5d06b5100000000, 0x3683467a00000000, 0x77b25d6300000000, - 0x4ed7facb00000000, 0x0fe6e1d200000000, 0xccb5ccf900000000, - 0x8d84d7e000000000, 0x4a1296af00000000, 0x0b238db600000000, - 0xc870a09d00000000, 0x8941bb8400000000, 0x465d230300000000, - 0x076c381a00000000, 0xc43f153100000000, 0x850e0e2800000000, - 0x42984f6700000000, 0x03a9547e00000000, 0xc0fa795500000000, - 0x81cb624c00000000, 0x1fc5388100000000, 0x5ef4239800000000, - 0x9da70eb300000000, 0xdc9615aa00000000, 0x1b0054e500000000, - 0x5a314ffc00000000, 0x996262d700000000, 0xd85379ce00000000, - 0x174fe14900000000, 0x567efa5000000000, 0x952dd77b00000000, - 0xd41ccc6200000000, 0x138a8d2d00000000, 0x52bb963400000000, - 0x91e8bb1f00000000, 0xd0d9a00600000000, 0xecf37e5e00000000, - 0xadc2654700000000, 0x6e91486c00000000, 0x2fa0537500000000, - 0xe836123a00000000, 0xa907092300000000, 0x6a54240800000000, - 0x2b653f1100000000, 0xe479a79600000000, 0xa548bc8f00000000, - 0x661b91a400000000, 0x272a8abd00000000, 0xe0bccbf200000000, - 0xa18dd0eb00000000, 0x62defdc000000000, 0x23efe6d900000000, - 0xbde1bc1400000000, 0xfcd0a70d00000000, 0x3f838a2600000000, - 0x7eb2913f00000000, 0xb924d07000000000, 0xf815cb6900000000, - 0x3b46e64200000000, 0x7a77fd5b00000000, 0xb56b65dc00000000, - 0xf45a7ec500000000, 0x370953ee00000000, 0x763848f700000000, - 0xb1ae09b800000000, 0xf09f12a100000000, 0x33cc3f8a00000000, - 0x72fd249300000000}, - {0x0000000000000000, 0x376ac20100000000, 0x6ed4840300000000, - 0x59be460200000000, 0xdca8090700000000, 0xebc2cb0600000000, - 0xb27c8d0400000000, 0x85164f0500000000, 0xb851130e00000000, - 0x8f3bd10f00000000, 0xd685970d00000000, 0xe1ef550c00000000, - 0x64f91a0900000000, 0x5393d80800000000, 0x0a2d9e0a00000000, - 0x3d475c0b00000000, 0x70a3261c00000000, 0x47c9e41d00000000, - 0x1e77a21f00000000, 0x291d601e00000000, 0xac0b2f1b00000000, - 0x9b61ed1a00000000, 0xc2dfab1800000000, 0xf5b5691900000000, - 0xc8f2351200000000, 0xff98f71300000000, 0xa626b11100000000, - 0x914c731000000000, 0x145a3c1500000000, 0x2330fe1400000000, - 0x7a8eb81600000000, 0x4de47a1700000000, 0xe0464d3800000000, - 0xd72c8f3900000000, 0x8e92c93b00000000, 0xb9f80b3a00000000, - 0x3cee443f00000000, 0x0b84863e00000000, 0x523ac03c00000000, - 0x6550023d00000000, 0x58175e3600000000, 0x6f7d9c3700000000, - 0x36c3da3500000000, 0x01a9183400000000, 0x84bf573100000000, - 0xb3d5953000000000, 0xea6bd33200000000, 0xdd01113300000000, - 0x90e56b2400000000, 0xa78fa92500000000, 0xfe31ef2700000000, - 0xc95b2d2600000000, 0x4c4d622300000000, 0x7b27a02200000000, - 0x2299e62000000000, 0x15f3242100000000, 0x28b4782a00000000, - 0x1fdeba2b00000000, 0x4660fc2900000000, 0x710a3e2800000000, - 0xf41c712d00000000, 0xc376b32c00000000, 0x9ac8f52e00000000, - 0xada2372f00000000, 0xc08d9a7000000000, 0xf7e7587100000000, - 0xae591e7300000000, 0x9933dc7200000000, 0x1c25937700000000, - 0x2b4f517600000000, 0x72f1177400000000, 0x459bd57500000000, - 0x78dc897e00000000, 0x4fb64b7f00000000, 0x16080d7d00000000, - 0x2162cf7c00000000, 0xa474807900000000, 0x931e427800000000, - 0xcaa0047a00000000, 0xfdcac67b00000000, 0xb02ebc6c00000000, - 0x87447e6d00000000, 0xdefa386f00000000, 0xe990fa6e00000000, - 0x6c86b56b00000000, 0x5bec776a00000000, 0x0252316800000000, - 0x3538f36900000000, 0x087faf6200000000, 0x3f156d6300000000, - 0x66ab2b6100000000, 0x51c1e96000000000, 0xd4d7a66500000000, - 0xe3bd646400000000, 0xba03226600000000, 0x8d69e06700000000, - 0x20cbd74800000000, 0x17a1154900000000, 0x4e1f534b00000000, - 0x7975914a00000000, 0xfc63de4f00000000, 0xcb091c4e00000000, - 0x92b75a4c00000000, 0xa5dd984d00000000, 0x989ac44600000000, - 0xaff0064700000000, 0xf64e404500000000, 0xc124824400000000, - 0x4432cd4100000000, 0x73580f4000000000, 0x2ae6494200000000, - 0x1d8c8b4300000000, 0x5068f15400000000, 0x6702335500000000, - 0x3ebc755700000000, 0x09d6b75600000000, 0x8cc0f85300000000, - 0xbbaa3a5200000000, 0xe2147c5000000000, 0xd57ebe5100000000, - 0xe839e25a00000000, 0xdf53205b00000000, 0x86ed665900000000, - 0xb187a45800000000, 0x3491eb5d00000000, 0x03fb295c00000000, - 0x5a456f5e00000000, 0x6d2fad5f00000000, 0x801b35e100000000, - 0xb771f7e000000000, 0xeecfb1e200000000, 0xd9a573e300000000, - 0x5cb33ce600000000, 0x6bd9fee700000000, 0x3267b8e500000000, - 0x050d7ae400000000, 0x384a26ef00000000, 0x0f20e4ee00000000, - 0x569ea2ec00000000, 0x61f460ed00000000, 0xe4e22fe800000000, - 0xd388ede900000000, 0x8a36abeb00000000, 0xbd5c69ea00000000, - 0xf0b813fd00000000, 0xc7d2d1fc00000000, 0x9e6c97fe00000000, - 0xa90655ff00000000, 0x2c101afa00000000, 0x1b7ad8fb00000000, - 0x42c49ef900000000, 0x75ae5cf800000000, 0x48e900f300000000, - 0x7f83c2f200000000, 0x263d84f000000000, 0x115746f100000000, - 0x944109f400000000, 0xa32bcbf500000000, 0xfa958df700000000, - 0xcdff4ff600000000, 0x605d78d900000000, 0x5737bad800000000, - 0x0e89fcda00000000, 0x39e33edb00000000, 0xbcf571de00000000, - 0x8b9fb3df00000000, 0xd221f5dd00000000, 0xe54b37dc00000000, - 0xd80c6bd700000000, 0xef66a9d600000000, 0xb6d8efd400000000, - 0x81b22dd500000000, 0x04a462d000000000, 0x33cea0d100000000, - 0x6a70e6d300000000, 0x5d1a24d200000000, 0x10fe5ec500000000, - 0x27949cc400000000, 0x7e2adac600000000, 0x494018c700000000, - 0xcc5657c200000000, 0xfb3c95c300000000, 0xa282d3c100000000, - 0x95e811c000000000, 0xa8af4dcb00000000, 0x9fc58fca00000000, - 0xc67bc9c800000000, 0xf1110bc900000000, 0x740744cc00000000, - 0x436d86cd00000000, 0x1ad3c0cf00000000, 0x2db902ce00000000, - 0x4096af9100000000, 0x77fc6d9000000000, 0x2e422b9200000000, - 0x1928e99300000000, 0x9c3ea69600000000, 0xab54649700000000, - 0xf2ea229500000000, 0xc580e09400000000, 0xf8c7bc9f00000000, - 0xcfad7e9e00000000, 0x9613389c00000000, 0xa179fa9d00000000, - 0x246fb59800000000, 0x1305779900000000, 0x4abb319b00000000, - 0x7dd1f39a00000000, 0x3035898d00000000, 0x075f4b8c00000000, - 0x5ee10d8e00000000, 0x698bcf8f00000000, 0xec9d808a00000000, - 0xdbf7428b00000000, 0x8249048900000000, 0xb523c68800000000, - 0x88649a8300000000, 0xbf0e588200000000, 0xe6b01e8000000000, - 0xd1dadc8100000000, 0x54cc938400000000, 0x63a6518500000000, - 0x3a18178700000000, 0x0d72d58600000000, 0xa0d0e2a900000000, - 0x97ba20a800000000, 0xce0466aa00000000, 0xf96ea4ab00000000, - 0x7c78ebae00000000, 0x4b1229af00000000, 0x12ac6fad00000000, - 0x25c6adac00000000, 0x1881f1a700000000, 0x2feb33a600000000, - 0x765575a400000000, 0x413fb7a500000000, 0xc429f8a000000000, - 0xf3433aa100000000, 0xaafd7ca300000000, 0x9d97bea200000000, - 0xd073c4b500000000, 0xe71906b400000000, 0xbea740b600000000, - 0x89cd82b700000000, 0x0cdbcdb200000000, 0x3bb10fb300000000, - 0x620f49b100000000, 0x55658bb000000000, 0x6822d7bb00000000, - 0x5f4815ba00000000, 0x06f653b800000000, 0x319c91b900000000, - 0xb48adebc00000000, 0x83e01cbd00000000, 0xda5e5abf00000000, - 0xed3498be00000000}, - {0x0000000000000000, 0x6567bcb800000000, 0x8bc809aa00000000, - 0xeeafb51200000000, 0x5797628f00000000, 0x32f0de3700000000, - 0xdc5f6b2500000000, 0xb938d79d00000000, 0xef28b4c500000000, - 0x8a4f087d00000000, 0x64e0bd6f00000000, 0x018701d700000000, - 0xb8bfd64a00000000, 0xddd86af200000000, 0x3377dfe000000000, - 0x5610635800000000, 0x9f57195000000000, 0xfa30a5e800000000, - 0x149f10fa00000000, 0x71f8ac4200000000, 0xc8c07bdf00000000, - 0xada7c76700000000, 0x4308727500000000, 0x266fcecd00000000, - 0x707fad9500000000, 0x1518112d00000000, 0xfbb7a43f00000000, - 0x9ed0188700000000, 0x27e8cf1a00000000, 0x428f73a200000000, - 0xac20c6b000000000, 0xc9477a0800000000, 0x3eaf32a000000000, - 0x5bc88e1800000000, 0xb5673b0a00000000, 0xd00087b200000000, - 0x6938502f00000000, 0x0c5fec9700000000, 0xe2f0598500000000, - 0x8797e53d00000000, 0xd187866500000000, 0xb4e03add00000000, - 0x5a4f8fcf00000000, 0x3f28337700000000, 0x8610e4ea00000000, - 0xe377585200000000, 0x0dd8ed4000000000, 0x68bf51f800000000, - 0xa1f82bf000000000, 0xc49f974800000000, 0x2a30225a00000000, - 0x4f579ee200000000, 0xf66f497f00000000, 0x9308f5c700000000, - 0x7da740d500000000, 0x18c0fc6d00000000, 0x4ed09f3500000000, - 0x2bb7238d00000000, 0xc518969f00000000, 0xa07f2a2700000000, - 0x1947fdba00000000, 0x7c20410200000000, 0x928ff41000000000, - 0xf7e848a800000000, 0x3d58149b00000000, 0x583fa82300000000, - 0xb6901d3100000000, 0xd3f7a18900000000, 0x6acf761400000000, - 0x0fa8caac00000000, 0xe1077fbe00000000, 0x8460c30600000000, - 0xd270a05e00000000, 0xb7171ce600000000, 0x59b8a9f400000000, - 0x3cdf154c00000000, 0x85e7c2d100000000, 0xe0807e6900000000, - 0x0e2fcb7b00000000, 0x6b4877c300000000, 0xa20f0dcb00000000, - 0xc768b17300000000, 0x29c7046100000000, 0x4ca0b8d900000000, - 0xf5986f4400000000, 0x90ffd3fc00000000, 0x7e5066ee00000000, - 0x1b37da5600000000, 0x4d27b90e00000000, 0x284005b600000000, - 0xc6efb0a400000000, 0xa3880c1c00000000, 0x1ab0db8100000000, - 0x7fd7673900000000, 0x9178d22b00000000, 0xf41f6e9300000000, - 0x03f7263b00000000, 0x66909a8300000000, 0x883f2f9100000000, - 0xed58932900000000, 0x546044b400000000, 0x3107f80c00000000, - 0xdfa84d1e00000000, 0xbacff1a600000000, 0xecdf92fe00000000, - 0x89b82e4600000000, 0x67179b5400000000, 0x027027ec00000000, - 0xbb48f07100000000, 0xde2f4cc900000000, 0x3080f9db00000000, - 0x55e7456300000000, 0x9ca03f6b00000000, 0xf9c783d300000000, - 0x176836c100000000, 0x720f8a7900000000, 0xcb375de400000000, - 0xae50e15c00000000, 0x40ff544e00000000, 0x2598e8f600000000, - 0x73888bae00000000, 0x16ef371600000000, 0xf840820400000000, - 0x9d273ebc00000000, 0x241fe92100000000, 0x4178559900000000, - 0xafd7e08b00000000, 0xcab05c3300000000, 0x3bb659ed00000000, - 0x5ed1e55500000000, 0xb07e504700000000, 0xd519ecff00000000, - 0x6c213b6200000000, 0x094687da00000000, 0xe7e932c800000000, - 0x828e8e7000000000, 0xd49eed2800000000, 0xb1f9519000000000, - 0x5f56e48200000000, 0x3a31583a00000000, 0x83098fa700000000, - 0xe66e331f00000000, 0x08c1860d00000000, 0x6da63ab500000000, - 0xa4e140bd00000000, 0xc186fc0500000000, 0x2f29491700000000, - 0x4a4ef5af00000000, 0xf376223200000000, 0x96119e8a00000000, - 0x78be2b9800000000, 0x1dd9972000000000, 0x4bc9f47800000000, - 0x2eae48c000000000, 0xc001fdd200000000, 0xa566416a00000000, - 0x1c5e96f700000000, 0x79392a4f00000000, 0x97969f5d00000000, - 0xf2f123e500000000, 0x05196b4d00000000, 0x607ed7f500000000, - 0x8ed162e700000000, 0xebb6de5f00000000, 0x528e09c200000000, - 0x37e9b57a00000000, 0xd946006800000000, 0xbc21bcd000000000, - 0xea31df8800000000, 0x8f56633000000000, 0x61f9d62200000000, - 0x049e6a9a00000000, 0xbda6bd0700000000, 0xd8c101bf00000000, - 0x366eb4ad00000000, 0x5309081500000000, 0x9a4e721d00000000, - 0xff29cea500000000, 0x11867bb700000000, 0x74e1c70f00000000, - 0xcdd9109200000000, 0xa8beac2a00000000, 0x4611193800000000, - 0x2376a58000000000, 0x7566c6d800000000, 0x10017a6000000000, - 0xfeaecf7200000000, 0x9bc973ca00000000, 0x22f1a45700000000, - 0x479618ef00000000, 0xa939adfd00000000, 0xcc5e114500000000, - 0x06ee4d7600000000, 0x6389f1ce00000000, 0x8d2644dc00000000, - 0xe841f86400000000, 0x51792ff900000000, 0x341e934100000000, - 0xdab1265300000000, 0xbfd69aeb00000000, 0xe9c6f9b300000000, - 0x8ca1450b00000000, 0x620ef01900000000, 0x07694ca100000000, - 0xbe519b3c00000000, 0xdb36278400000000, 0x3599929600000000, - 0x50fe2e2e00000000, 0x99b9542600000000, 0xfcdee89e00000000, - 0x12715d8c00000000, 0x7716e13400000000, 0xce2e36a900000000, - 0xab498a1100000000, 0x45e63f0300000000, 0x208183bb00000000, - 0x7691e0e300000000, 0x13f65c5b00000000, 0xfd59e94900000000, - 0x983e55f100000000, 0x2106826c00000000, 0x44613ed400000000, - 0xaace8bc600000000, 0xcfa9377e00000000, 0x38417fd600000000, - 0x5d26c36e00000000, 0xb389767c00000000, 0xd6eecac400000000, - 0x6fd61d5900000000, 0x0ab1a1e100000000, 0xe41e14f300000000, - 0x8179a84b00000000, 0xd769cb1300000000, 0xb20e77ab00000000, - 0x5ca1c2b900000000, 0x39c67e0100000000, 0x80fea99c00000000, - 0xe599152400000000, 0x0b36a03600000000, 0x6e511c8e00000000, - 0xa716668600000000, 0xc271da3e00000000, 0x2cde6f2c00000000, - 0x49b9d39400000000, 0xf081040900000000, 0x95e6b8b100000000, - 0x7b490da300000000, 0x1e2eb11b00000000, 0x483ed24300000000, - 0x2d596efb00000000, 0xc3f6dbe900000000, 0xa691675100000000, - 0x1fa9b0cc00000000, 0x7ace0c7400000000, 0x9461b96600000000, - 0xf10605de00000000}, - {0x0000000000000000, 0xb029603d00000000, 0x6053c07a00000000, - 0xd07aa04700000000, 0xc0a680f500000000, 0x708fe0c800000000, - 0xa0f5408f00000000, 0x10dc20b200000000, 0xc14b703000000000, - 0x7162100d00000000, 0xa118b04a00000000, 0x1131d07700000000, - 0x01edf0c500000000, 0xb1c490f800000000, 0x61be30bf00000000, - 0xd197508200000000, 0x8297e06000000000, 0x32be805d00000000, - 0xe2c4201a00000000, 0x52ed402700000000, 0x4231609500000000, - 0xf21800a800000000, 0x2262a0ef00000000, 0x924bc0d200000000, - 0x43dc905000000000, 0xf3f5f06d00000000, 0x238f502a00000000, - 0x93a6301700000000, 0x837a10a500000000, 0x3353709800000000, - 0xe329d0df00000000, 0x5300b0e200000000, 0x042fc1c100000000, - 0xb406a1fc00000000, 0x647c01bb00000000, 0xd455618600000000, - 0xc489413400000000, 0x74a0210900000000, 0xa4da814e00000000, - 0x14f3e17300000000, 0xc564b1f100000000, 0x754dd1cc00000000, - 0xa537718b00000000, 0x151e11b600000000, 0x05c2310400000000, - 0xb5eb513900000000, 0x6591f17e00000000, 0xd5b8914300000000, - 0x86b821a100000000, 0x3691419c00000000, 0xe6ebe1db00000000, - 0x56c281e600000000, 0x461ea15400000000, 0xf637c16900000000, - 0x264d612e00000000, 0x9664011300000000, 0x47f3519100000000, - 0xf7da31ac00000000, 0x27a091eb00000000, 0x9789f1d600000000, - 0x8755d16400000000, 0x377cb15900000000, 0xe706111e00000000, - 0x572f712300000000, 0x4958f35800000000, 0xf971936500000000, - 0x290b332200000000, 0x9922531f00000000, 0x89fe73ad00000000, - 0x39d7139000000000, 0xe9adb3d700000000, 0x5984d3ea00000000, - 0x8813836800000000, 0x383ae35500000000, 0xe840431200000000, - 0x5869232f00000000, 0x48b5039d00000000, 0xf89c63a000000000, - 0x28e6c3e700000000, 0x98cfa3da00000000, 0xcbcf133800000000, - 0x7be6730500000000, 0xab9cd34200000000, 0x1bb5b37f00000000, - 0x0b6993cd00000000, 0xbb40f3f000000000, 0x6b3a53b700000000, - 0xdb13338a00000000, 0x0a84630800000000, 0xbaad033500000000, - 0x6ad7a37200000000, 0xdafec34f00000000, 0xca22e3fd00000000, - 0x7a0b83c000000000, 0xaa71238700000000, 0x1a5843ba00000000, - 0x4d77329900000000, 0xfd5e52a400000000, 0x2d24f2e300000000, - 0x9d0d92de00000000, 0x8dd1b26c00000000, 0x3df8d25100000000, - 0xed82721600000000, 0x5dab122b00000000, 0x8c3c42a900000000, - 0x3c15229400000000, 0xec6f82d300000000, 0x5c46e2ee00000000, - 0x4c9ac25c00000000, 0xfcb3a26100000000, 0x2cc9022600000000, - 0x9ce0621b00000000, 0xcfe0d2f900000000, 0x7fc9b2c400000000, - 0xafb3128300000000, 0x1f9a72be00000000, 0x0f46520c00000000, - 0xbf6f323100000000, 0x6f15927600000000, 0xdf3cf24b00000000, - 0x0eaba2c900000000, 0xbe82c2f400000000, 0x6ef862b300000000, - 0xded1028e00000000, 0xce0d223c00000000, 0x7e24420100000000, - 0xae5ee24600000000, 0x1e77827b00000000, 0x92b0e6b100000000, - 0x2299868c00000000, 0xf2e326cb00000000, 0x42ca46f600000000, - 0x5216664400000000, 0xe23f067900000000, 0x3245a63e00000000, - 0x826cc60300000000, 0x53fb968100000000, 0xe3d2f6bc00000000, - 0x33a856fb00000000, 0x838136c600000000, 0x935d167400000000, - 0x2374764900000000, 0xf30ed60e00000000, 0x4327b63300000000, - 0x102706d100000000, 0xa00e66ec00000000, 0x7074c6ab00000000, - 0xc05da69600000000, 0xd081862400000000, 0x60a8e61900000000, - 0xb0d2465e00000000, 0x00fb266300000000, 0xd16c76e100000000, - 0x614516dc00000000, 0xb13fb69b00000000, 0x0116d6a600000000, - 0x11caf61400000000, 0xa1e3962900000000, 0x7199366e00000000, - 0xc1b0565300000000, 0x969f277000000000, 0x26b6474d00000000, - 0xf6cce70a00000000, 0x46e5873700000000, 0x5639a78500000000, - 0xe610c7b800000000, 0x366a67ff00000000, 0x864307c200000000, - 0x57d4574000000000, 0xe7fd377d00000000, 0x3787973a00000000, - 0x87aef70700000000, 0x9772d7b500000000, 0x275bb78800000000, - 0xf72117cf00000000, 0x470877f200000000, 0x1408c71000000000, - 0xa421a72d00000000, 0x745b076a00000000, 0xc472675700000000, - 0xd4ae47e500000000, 0x648727d800000000, 0xb4fd879f00000000, - 0x04d4e7a200000000, 0xd543b72000000000, 0x656ad71d00000000, - 0xb510775a00000000, 0x0539176700000000, 0x15e537d500000000, - 0xa5cc57e800000000, 0x75b6f7af00000000, 0xc59f979200000000, - 0xdbe815e900000000, 0x6bc175d400000000, 0xbbbbd59300000000, - 0x0b92b5ae00000000, 0x1b4e951c00000000, 0xab67f52100000000, - 0x7b1d556600000000, 0xcb34355b00000000, 0x1aa365d900000000, - 0xaa8a05e400000000, 0x7af0a5a300000000, 0xcad9c59e00000000, - 0xda05e52c00000000, 0x6a2c851100000000, 0xba56255600000000, - 0x0a7f456b00000000, 0x597ff58900000000, 0xe95695b400000000, - 0x392c35f300000000, 0x890555ce00000000, 0x99d9757c00000000, - 0x29f0154100000000, 0xf98ab50600000000, 0x49a3d53b00000000, - 0x983485b900000000, 0x281de58400000000, 0xf86745c300000000, - 0x484e25fe00000000, 0x5892054c00000000, 0xe8bb657100000000, - 0x38c1c53600000000, 0x88e8a50b00000000, 0xdfc7d42800000000, - 0x6feeb41500000000, 0xbf94145200000000, 0x0fbd746f00000000, - 0x1f6154dd00000000, 0xaf4834e000000000, 0x7f3294a700000000, - 0xcf1bf49a00000000, 0x1e8ca41800000000, 0xaea5c42500000000, - 0x7edf646200000000, 0xcef6045f00000000, 0xde2a24ed00000000, - 0x6e0344d000000000, 0xbe79e49700000000, 0x0e5084aa00000000, - 0x5d50344800000000, 0xed79547500000000, 0x3d03f43200000000, - 0x8d2a940f00000000, 0x9df6b4bd00000000, 0x2ddfd48000000000, - 0xfda574c700000000, 0x4d8c14fa00000000, 0x9c1b447800000000, - 0x2c32244500000000, 0xfc48840200000000, 0x4c61e43f00000000, - 0x5cbdc48d00000000, 0xec94a4b000000000, 0x3cee04f700000000, - 0x8cc764ca00000000}, - {0x0000000000000000, 0xa5d35ccb00000000, 0x0ba1c84d00000000, - 0xae72948600000000, 0x1642919b00000000, 0xb391cd5000000000, - 0x1de359d600000000, 0xb830051d00000000, 0x6d8253ec00000000, - 0xc8510f2700000000, 0x66239ba100000000, 0xc3f0c76a00000000, - 0x7bc0c27700000000, 0xde139ebc00000000, 0x70610a3a00000000, - 0xd5b256f100000000, 0x9b02d60300000000, 0x3ed18ac800000000, - 0x90a31e4e00000000, 0x3570428500000000, 0x8d40479800000000, - 0x28931b5300000000, 0x86e18fd500000000, 0x2332d31e00000000, - 0xf68085ef00000000, 0x5353d92400000000, 0xfd214da200000000, - 0x58f2116900000000, 0xe0c2147400000000, 0x451148bf00000000, - 0xeb63dc3900000000, 0x4eb080f200000000, 0x3605ac0700000000, - 0x93d6f0cc00000000, 0x3da4644a00000000, 0x9877388100000000, - 0x20473d9c00000000, 0x8594615700000000, 0x2be6f5d100000000, - 0x8e35a91a00000000, 0x5b87ffeb00000000, 0xfe54a32000000000, - 0x502637a600000000, 0xf5f56b6d00000000, 0x4dc56e7000000000, - 0xe81632bb00000000, 0x4664a63d00000000, 0xe3b7faf600000000, - 0xad077a0400000000, 0x08d426cf00000000, 0xa6a6b24900000000, - 0x0375ee8200000000, 0xbb45eb9f00000000, 0x1e96b75400000000, - 0xb0e423d200000000, 0x15377f1900000000, 0xc08529e800000000, - 0x6556752300000000, 0xcb24e1a500000000, 0x6ef7bd6e00000000, - 0xd6c7b87300000000, 0x7314e4b800000000, 0xdd66703e00000000, - 0x78b52cf500000000, 0x6c0a580f00000000, 0xc9d904c400000000, - 0x67ab904200000000, 0xc278cc8900000000, 0x7a48c99400000000, - 0xdf9b955f00000000, 0x71e901d900000000, 0xd43a5d1200000000, - 0x01880be300000000, 0xa45b572800000000, 0x0a29c3ae00000000, - 0xaffa9f6500000000, 0x17ca9a7800000000, 0xb219c6b300000000, - 0x1c6b523500000000, 0xb9b80efe00000000, 0xf7088e0c00000000, - 0x52dbd2c700000000, 0xfca9464100000000, 0x597a1a8a00000000, - 0xe14a1f9700000000, 0x4499435c00000000, 0xeaebd7da00000000, - 0x4f388b1100000000, 0x9a8adde000000000, 0x3f59812b00000000, - 0x912b15ad00000000, 0x34f8496600000000, 0x8cc84c7b00000000, - 0x291b10b000000000, 0x8769843600000000, 0x22bad8fd00000000, - 0x5a0ff40800000000, 0xffdca8c300000000, 0x51ae3c4500000000, - 0xf47d608e00000000, 0x4c4d659300000000, 0xe99e395800000000, - 0x47ecadde00000000, 0xe23ff11500000000, 0x378da7e400000000, - 0x925efb2f00000000, 0x3c2c6fa900000000, 0x99ff336200000000, - 0x21cf367f00000000, 0x841c6ab400000000, 0x2a6efe3200000000, - 0x8fbda2f900000000, 0xc10d220b00000000, 0x64de7ec000000000, - 0xcaacea4600000000, 0x6f7fb68d00000000, 0xd74fb39000000000, - 0x729cef5b00000000, 0xdcee7bdd00000000, 0x793d271600000000, - 0xac8f71e700000000, 0x095c2d2c00000000, 0xa72eb9aa00000000, - 0x02fde56100000000, 0xbacde07c00000000, 0x1f1ebcb700000000, - 0xb16c283100000000, 0x14bf74fa00000000, 0xd814b01e00000000, - 0x7dc7ecd500000000, 0xd3b5785300000000, 0x7666249800000000, - 0xce56218500000000, 0x6b857d4e00000000, 0xc5f7e9c800000000, - 0x6024b50300000000, 0xb596e3f200000000, 0x1045bf3900000000, - 0xbe372bbf00000000, 0x1be4777400000000, 0xa3d4726900000000, - 0x06072ea200000000, 0xa875ba2400000000, 0x0da6e6ef00000000, - 0x4316661d00000000, 0xe6c53ad600000000, 0x48b7ae5000000000, - 0xed64f29b00000000, 0x5554f78600000000, 0xf087ab4d00000000, - 0x5ef53fcb00000000, 0xfb26630000000000, 0x2e9435f100000000, - 0x8b47693a00000000, 0x2535fdbc00000000, 0x80e6a17700000000, - 0x38d6a46a00000000, 0x9d05f8a100000000, 0x33776c2700000000, - 0x96a430ec00000000, 0xee111c1900000000, 0x4bc240d200000000, - 0xe5b0d45400000000, 0x4063889f00000000, 0xf8538d8200000000, - 0x5d80d14900000000, 0xf3f245cf00000000, 0x5621190400000000, - 0x83934ff500000000, 0x2640133e00000000, 0x883287b800000000, - 0x2de1db7300000000, 0x95d1de6e00000000, 0x300282a500000000, - 0x9e70162300000000, 0x3ba34ae800000000, 0x7513ca1a00000000, - 0xd0c096d100000000, 0x7eb2025700000000, 0xdb615e9c00000000, - 0x63515b8100000000, 0xc682074a00000000, 0x68f093cc00000000, - 0xcd23cf0700000000, 0x189199f600000000, 0xbd42c53d00000000, - 0x133051bb00000000, 0xb6e30d7000000000, 0x0ed3086d00000000, - 0xab0054a600000000, 0x0572c02000000000, 0xa0a19ceb00000000, - 0xb41ee81100000000, 0x11cdb4da00000000, 0xbfbf205c00000000, - 0x1a6c7c9700000000, 0xa25c798a00000000, 0x078f254100000000, - 0xa9fdb1c700000000, 0x0c2eed0c00000000, 0xd99cbbfd00000000, - 0x7c4fe73600000000, 0xd23d73b000000000, 0x77ee2f7b00000000, - 0xcfde2a6600000000, 0x6a0d76ad00000000, 0xc47fe22b00000000, - 0x61acbee000000000, 0x2f1c3e1200000000, 0x8acf62d900000000, - 0x24bdf65f00000000, 0x816eaa9400000000, 0x395eaf8900000000, - 0x9c8df34200000000, 0x32ff67c400000000, 0x972c3b0f00000000, - 0x429e6dfe00000000, 0xe74d313500000000, 0x493fa5b300000000, - 0xececf97800000000, 0x54dcfc6500000000, 0xf10fa0ae00000000, - 0x5f7d342800000000, 0xfaae68e300000000, 0x821b441600000000, - 0x27c818dd00000000, 0x89ba8c5b00000000, 0x2c69d09000000000, - 0x9459d58d00000000, 0x318a894600000000, 0x9ff81dc000000000, - 0x3a2b410b00000000, 0xef9917fa00000000, 0x4a4a4b3100000000, - 0xe438dfb700000000, 0x41eb837c00000000, 0xf9db866100000000, - 0x5c08daaa00000000, 0xf27a4e2c00000000, 0x57a912e700000000, - 0x1919921500000000, 0xbccacede00000000, 0x12b85a5800000000, - 0xb76b069300000000, 0x0f5b038e00000000, 0xaa885f4500000000, - 0x04facbc300000000, 0xa129970800000000, 0x749bc1f900000000, - 0xd1489d3200000000, 0x7f3a09b400000000, 0xdae9557f00000000, - 0x62d9506200000000, 0xc70a0ca900000000, 0x6978982f00000000, - 0xccabc4e400000000}, - {0x0000000000000000, 0xb40b77a600000000, 0x29119f9700000000, - 0x9d1ae83100000000, 0x13244ff400000000, 0xa72f385200000000, - 0x3a35d06300000000, 0x8e3ea7c500000000, 0x674eef3300000000, - 0xd345989500000000, 0x4e5f70a400000000, 0xfa54070200000000, - 0x746aa0c700000000, 0xc061d76100000000, 0x5d7b3f5000000000, - 0xe97048f600000000, 0xce9cde6700000000, 0x7a97a9c100000000, - 0xe78d41f000000000, 0x5386365600000000, 0xddb8919300000000, - 0x69b3e63500000000, 0xf4a90e0400000000, 0x40a279a200000000, - 0xa9d2315400000000, 0x1dd946f200000000, 0x80c3aec300000000, - 0x34c8d96500000000, 0xbaf67ea000000000, 0x0efd090600000000, - 0x93e7e13700000000, 0x27ec969100000000, 0x9c39bdcf00000000, - 0x2832ca6900000000, 0xb528225800000000, 0x012355fe00000000, - 0x8f1df23b00000000, 0x3b16859d00000000, 0xa60c6dac00000000, - 0x12071a0a00000000, 0xfb7752fc00000000, 0x4f7c255a00000000, - 0xd266cd6b00000000, 0x666dbacd00000000, 0xe8531d0800000000, - 0x5c586aae00000000, 0xc142829f00000000, 0x7549f53900000000, - 0x52a563a800000000, 0xe6ae140e00000000, 0x7bb4fc3f00000000, - 0xcfbf8b9900000000, 0x41812c5c00000000, 0xf58a5bfa00000000, - 0x6890b3cb00000000, 0xdc9bc46d00000000, 0x35eb8c9b00000000, - 0x81e0fb3d00000000, 0x1cfa130c00000000, 0xa8f164aa00000000, - 0x26cfc36f00000000, 0x92c4b4c900000000, 0x0fde5cf800000000, - 0xbbd52b5e00000000, 0x79750b4400000000, 0xcd7e7ce200000000, - 0x506494d300000000, 0xe46fe37500000000, 0x6a5144b000000000, - 0xde5a331600000000, 0x4340db2700000000, 0xf74bac8100000000, - 0x1e3be47700000000, 0xaa3093d100000000, 0x372a7be000000000, - 0x83210c4600000000, 0x0d1fab8300000000, 0xb914dc2500000000, - 0x240e341400000000, 0x900543b200000000, 0xb7e9d52300000000, - 0x03e2a28500000000, 0x9ef84ab400000000, 0x2af33d1200000000, - 0xa4cd9ad700000000, 0x10c6ed7100000000, 0x8ddc054000000000, - 0x39d772e600000000, 0xd0a73a1000000000, 0x64ac4db600000000, - 0xf9b6a58700000000, 0x4dbdd22100000000, 0xc38375e400000000, - 0x7788024200000000, 0xea92ea7300000000, 0x5e999dd500000000, - 0xe54cb68b00000000, 0x5147c12d00000000, 0xcc5d291c00000000, - 0x78565eba00000000, 0xf668f97f00000000, 0x42638ed900000000, - 0xdf7966e800000000, 0x6b72114e00000000, 0x820259b800000000, - 0x36092e1e00000000, 0xab13c62f00000000, 0x1f18b18900000000, - 0x9126164c00000000, 0x252d61ea00000000, 0xb83789db00000000, - 0x0c3cfe7d00000000, 0x2bd068ec00000000, 0x9fdb1f4a00000000, - 0x02c1f77b00000000, 0xb6ca80dd00000000, 0x38f4271800000000, - 0x8cff50be00000000, 0x11e5b88f00000000, 0xa5eecf2900000000, - 0x4c9e87df00000000, 0xf895f07900000000, 0x658f184800000000, - 0xd1846fee00000000, 0x5fbac82b00000000, 0xebb1bf8d00000000, - 0x76ab57bc00000000, 0xc2a0201a00000000, 0xf2ea168800000000, - 0x46e1612e00000000, 0xdbfb891f00000000, 0x6ff0feb900000000, - 0xe1ce597c00000000, 0x55c52eda00000000, 0xc8dfc6eb00000000, - 0x7cd4b14d00000000, 0x95a4f9bb00000000, 0x21af8e1d00000000, - 0xbcb5662c00000000, 0x08be118a00000000, 0x8680b64f00000000, - 0x328bc1e900000000, 0xaf9129d800000000, 0x1b9a5e7e00000000, - 0x3c76c8ef00000000, 0x887dbf4900000000, 0x1567577800000000, - 0xa16c20de00000000, 0x2f52871b00000000, 0x9b59f0bd00000000, - 0x0643188c00000000, 0xb2486f2a00000000, 0x5b3827dc00000000, - 0xef33507a00000000, 0x7229b84b00000000, 0xc622cfed00000000, - 0x481c682800000000, 0xfc171f8e00000000, 0x610df7bf00000000, - 0xd506801900000000, 0x6ed3ab4700000000, 0xdad8dce100000000, - 0x47c234d000000000, 0xf3c9437600000000, 0x7df7e4b300000000, - 0xc9fc931500000000, 0x54e67b2400000000, 0xe0ed0c8200000000, - 0x099d447400000000, 0xbd9633d200000000, 0x208cdbe300000000, - 0x9487ac4500000000, 0x1ab90b8000000000, 0xaeb27c2600000000, - 0x33a8941700000000, 0x87a3e3b100000000, 0xa04f752000000000, - 0x1444028600000000, 0x895eeab700000000, 0x3d559d1100000000, - 0xb36b3ad400000000, 0x07604d7200000000, 0x9a7aa54300000000, - 0x2e71d2e500000000, 0xc7019a1300000000, 0x730aedb500000000, - 0xee10058400000000, 0x5a1b722200000000, 0xd425d5e700000000, - 0x602ea24100000000, 0xfd344a7000000000, 0x493f3dd600000000, - 0x8b9f1dcc00000000, 0x3f946a6a00000000, 0xa28e825b00000000, - 0x1685f5fd00000000, 0x98bb523800000000, 0x2cb0259e00000000, - 0xb1aacdaf00000000, 0x05a1ba0900000000, 0xecd1f2ff00000000, - 0x58da855900000000, 0xc5c06d6800000000, 0x71cb1ace00000000, - 0xfff5bd0b00000000, 0x4bfecaad00000000, 0xd6e4229c00000000, - 0x62ef553a00000000, 0x4503c3ab00000000, 0xf108b40d00000000, - 0x6c125c3c00000000, 0xd8192b9a00000000, 0x56278c5f00000000, - 0xe22cfbf900000000, 0x7f3613c800000000, 0xcb3d646e00000000, - 0x224d2c9800000000, 0x96465b3e00000000, 0x0b5cb30f00000000, - 0xbf57c4a900000000, 0x3169636c00000000, 0x856214ca00000000, - 0x1878fcfb00000000, 0xac738b5d00000000, 0x17a6a00300000000, - 0xa3add7a500000000, 0x3eb73f9400000000, 0x8abc483200000000, - 0x0482eff700000000, 0xb089985100000000, 0x2d93706000000000, - 0x999807c600000000, 0x70e84f3000000000, 0xc4e3389600000000, - 0x59f9d0a700000000, 0xedf2a70100000000, 0x63cc00c400000000, - 0xd7c7776200000000, 0x4add9f5300000000, 0xfed6e8f500000000, - 0xd93a7e6400000000, 0x6d3109c200000000, 0xf02be1f300000000, - 0x4420965500000000, 0xca1e319000000000, 0x7e15463600000000, - 0xe30fae0700000000, 0x5704d9a100000000, 0xbe74915700000000, - 0x0a7fe6f100000000, 0x97650ec000000000, 0x236e796600000000, - 0xad50dea300000000, 0x195ba90500000000, 0x8441413400000000, - 0x304a369200000000}, - {0x0000000000000000, 0x9e00aacc00000000, 0x7d07254200000000, - 0xe3078f8e00000000, 0xfa0e4a8400000000, 0x640ee04800000000, - 0x87096fc600000000, 0x1909c50a00000000, 0xb51be5d300000000, - 0x2b1b4f1f00000000, 0xc81cc09100000000, 0x561c6a5d00000000, - 0x4f15af5700000000, 0xd115059b00000000, 0x32128a1500000000, - 0xac1220d900000000, 0x2b31bb7c00000000, 0xb53111b000000000, - 0x56369e3e00000000, 0xc83634f200000000, 0xd13ff1f800000000, - 0x4f3f5b3400000000, 0xac38d4ba00000000, 0x32387e7600000000, - 0x9e2a5eaf00000000, 0x002af46300000000, 0xe32d7bed00000000, - 0x7d2dd12100000000, 0x6424142b00000000, 0xfa24bee700000000, - 0x1923316900000000, 0x87239ba500000000, 0x566276f900000000, - 0xc862dc3500000000, 0x2b6553bb00000000, 0xb565f97700000000, - 0xac6c3c7d00000000, 0x326c96b100000000, 0xd16b193f00000000, - 0x4f6bb3f300000000, 0xe379932a00000000, 0x7d7939e600000000, - 0x9e7eb66800000000, 0x007e1ca400000000, 0x1977d9ae00000000, - 0x8777736200000000, 0x6470fcec00000000, 0xfa70562000000000, - 0x7d53cd8500000000, 0xe353674900000000, 0x0054e8c700000000, - 0x9e54420b00000000, 0x875d870100000000, 0x195d2dcd00000000, - 0xfa5aa24300000000, 0x645a088f00000000, 0xc848285600000000, - 0x5648829a00000000, 0xb54f0d1400000000, 0x2b4fa7d800000000, - 0x324662d200000000, 0xac46c81e00000000, 0x4f41479000000000, - 0xd141ed5c00000000, 0xedc29d2900000000, 0x73c237e500000000, - 0x90c5b86b00000000, 0x0ec512a700000000, 0x17ccd7ad00000000, - 0x89cc7d6100000000, 0x6acbf2ef00000000, 0xf4cb582300000000, - 0x58d978fa00000000, 0xc6d9d23600000000, 0x25de5db800000000, - 0xbbdef77400000000, 0xa2d7327e00000000, 0x3cd798b200000000, - 0xdfd0173c00000000, 0x41d0bdf000000000, 0xc6f3265500000000, - 0x58f38c9900000000, 0xbbf4031700000000, 0x25f4a9db00000000, - 0x3cfd6cd100000000, 0xa2fdc61d00000000, 0x41fa499300000000, - 0xdffae35f00000000, 0x73e8c38600000000, 0xede8694a00000000, - 0x0eefe6c400000000, 0x90ef4c0800000000, 0x89e6890200000000, - 0x17e623ce00000000, 0xf4e1ac4000000000, 0x6ae1068c00000000, - 0xbba0ebd000000000, 0x25a0411c00000000, 0xc6a7ce9200000000, - 0x58a7645e00000000, 0x41aea15400000000, 0xdfae0b9800000000, - 0x3ca9841600000000, 0xa2a92eda00000000, 0x0ebb0e0300000000, - 0x90bba4cf00000000, 0x73bc2b4100000000, 0xedbc818d00000000, - 0xf4b5448700000000, 0x6ab5ee4b00000000, 0x89b261c500000000, - 0x17b2cb0900000000, 0x909150ac00000000, 0x0e91fa6000000000, - 0xed9675ee00000000, 0x7396df2200000000, 0x6a9f1a2800000000, - 0xf49fb0e400000000, 0x17983f6a00000000, 0x899895a600000000, - 0x258ab57f00000000, 0xbb8a1fb300000000, 0x588d903d00000000, - 0xc68d3af100000000, 0xdf84fffb00000000, 0x4184553700000000, - 0xa283dab900000000, 0x3c83707500000000, 0xda853b5300000000, - 0x4485919f00000000, 0xa7821e1100000000, 0x3982b4dd00000000, - 0x208b71d700000000, 0xbe8bdb1b00000000, 0x5d8c549500000000, - 0xc38cfe5900000000, 0x6f9ede8000000000, 0xf19e744c00000000, - 0x1299fbc200000000, 0x8c99510e00000000, 0x9590940400000000, - 0x0b903ec800000000, 0xe897b14600000000, 0x76971b8a00000000, - 0xf1b4802f00000000, 0x6fb42ae300000000, 0x8cb3a56d00000000, - 0x12b30fa100000000, 0x0bbacaab00000000, 0x95ba606700000000, - 0x76bdefe900000000, 0xe8bd452500000000, 0x44af65fc00000000, - 0xdaafcf3000000000, 0x39a840be00000000, 0xa7a8ea7200000000, - 0xbea12f7800000000, 0x20a185b400000000, 0xc3a60a3a00000000, - 0x5da6a0f600000000, 0x8ce74daa00000000, 0x12e7e76600000000, - 0xf1e068e800000000, 0x6fe0c22400000000, 0x76e9072e00000000, - 0xe8e9ade200000000, 0x0bee226c00000000, 0x95ee88a000000000, - 0x39fca87900000000, 0xa7fc02b500000000, 0x44fb8d3b00000000, - 0xdafb27f700000000, 0xc3f2e2fd00000000, 0x5df2483100000000, - 0xbef5c7bf00000000, 0x20f56d7300000000, 0xa7d6f6d600000000, - 0x39d65c1a00000000, 0xdad1d39400000000, 0x44d1795800000000, - 0x5dd8bc5200000000, 0xc3d8169e00000000, 0x20df991000000000, - 0xbedf33dc00000000, 0x12cd130500000000, 0x8ccdb9c900000000, - 0x6fca364700000000, 0xf1ca9c8b00000000, 0xe8c3598100000000, - 0x76c3f34d00000000, 0x95c47cc300000000, 0x0bc4d60f00000000, - 0x3747a67a00000000, 0xa9470cb600000000, 0x4a40833800000000, - 0xd44029f400000000, 0xcd49ecfe00000000, 0x5349463200000000, - 0xb04ec9bc00000000, 0x2e4e637000000000, 0x825c43a900000000, - 0x1c5ce96500000000, 0xff5b66eb00000000, 0x615bcc2700000000, - 0x7852092d00000000, 0xe652a3e100000000, 0x05552c6f00000000, - 0x9b5586a300000000, 0x1c761d0600000000, 0x8276b7ca00000000, - 0x6171384400000000, 0xff71928800000000, 0xe678578200000000, - 0x7878fd4e00000000, 0x9b7f72c000000000, 0x057fd80c00000000, - 0xa96df8d500000000, 0x376d521900000000, 0xd46add9700000000, - 0x4a6a775b00000000, 0x5363b25100000000, 0xcd63189d00000000, - 0x2e64971300000000, 0xb0643ddf00000000, 0x6125d08300000000, - 0xff257a4f00000000, 0x1c22f5c100000000, 0x82225f0d00000000, - 0x9b2b9a0700000000, 0x052b30cb00000000, 0xe62cbf4500000000, - 0x782c158900000000, 0xd43e355000000000, 0x4a3e9f9c00000000, - 0xa939101200000000, 0x3739bade00000000, 0x2e307fd400000000, - 0xb030d51800000000, 0x53375a9600000000, 0xcd37f05a00000000, - 0x4a146bff00000000, 0xd414c13300000000, 0x37134ebd00000000, - 0xa913e47100000000, 0xb01a217b00000000, 0x2e1a8bb700000000, - 0xcd1d043900000000, 0x531daef500000000, 0xff0f8e2c00000000, - 0x610f24e000000000, 0x8208ab6e00000000, 0x1c0801a200000000, - 0x0501c4a800000000, 0x9b016e6400000000, 0x7806e1ea00000000, - 0xe6064b2600000000}}; - -#else /* W == 4 */ - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0xb8bc6765, 0xaa09c88b, 0x12b5afee, 0x8f629757, - 0x37def032, 0x256b5fdc, 0x9dd738b9, 0xc5b428ef, 0x7d084f8a, - 0x6fbde064, 0xd7018701, 0x4ad6bfb8, 0xf26ad8dd, 0xe0df7733, - 0x58631056, 0x5019579f, 0xe8a530fa, 0xfa109f14, 0x42acf871, - 0xdf7bc0c8, 0x67c7a7ad, 0x75720843, 0xcdce6f26, 0x95ad7f70, - 0x2d111815, 0x3fa4b7fb, 0x8718d09e, 0x1acfe827, 0xa2738f42, - 0xb0c620ac, 0x087a47c9, 0xa032af3e, 0x188ec85b, 0x0a3b67b5, - 0xb28700d0, 0x2f503869, 0x97ec5f0c, 0x8559f0e2, 0x3de59787, - 0x658687d1, 0xdd3ae0b4, 0xcf8f4f5a, 0x7733283f, 0xeae41086, - 0x525877e3, 0x40edd80d, 0xf851bf68, 0xf02bf8a1, 0x48979fc4, - 0x5a22302a, 0xe29e574f, 0x7f496ff6, 0xc7f50893, 0xd540a77d, - 0x6dfcc018, 0x359fd04e, 0x8d23b72b, 0x9f9618c5, 0x272a7fa0, - 0xbafd4719, 0x0241207c, 0x10f48f92, 0xa848e8f7, 0x9b14583d, - 0x23a83f58, 0x311d90b6, 0x89a1f7d3, 0x1476cf6a, 0xaccaa80f, - 0xbe7f07e1, 0x06c36084, 0x5ea070d2, 0xe61c17b7, 0xf4a9b859, - 0x4c15df3c, 0xd1c2e785, 0x697e80e0, 0x7bcb2f0e, 0xc377486b, - 0xcb0d0fa2, 0x73b168c7, 0x6104c729, 0xd9b8a04c, 0x446f98f5, - 0xfcd3ff90, 0xee66507e, 0x56da371b, 0x0eb9274d, 0xb6054028, - 0xa4b0efc6, 0x1c0c88a3, 0x81dbb01a, 0x3967d77f, 0x2bd27891, - 0x936e1ff4, 0x3b26f703, 0x839a9066, 0x912f3f88, 0x299358ed, - 0xb4446054, 0x0cf80731, 0x1e4da8df, 0xa6f1cfba, 0xfe92dfec, - 0x462eb889, 0x549b1767, 0xec277002, 0x71f048bb, 0xc94c2fde, - 0xdbf98030, 0x6345e755, 0x6b3fa09c, 0xd383c7f9, 0xc1366817, - 0x798a0f72, 0xe45d37cb, 0x5ce150ae, 0x4e54ff40, 0xf6e89825, - 0xae8b8873, 0x1637ef16, 0x048240f8, 0xbc3e279d, 0x21e91f24, - 0x99557841, 0x8be0d7af, 0x335cb0ca, 0xed59b63b, 0x55e5d15e, - 0x47507eb0, 0xffec19d5, 0x623b216c, 0xda874609, 0xc832e9e7, - 0x708e8e82, 0x28ed9ed4, 0x9051f9b1, 0x82e4565f, 0x3a58313a, - 0xa78f0983, 0x1f336ee6, 0x0d86c108, 0xb53aa66d, 0xbd40e1a4, - 0x05fc86c1, 0x1749292f, 0xaff54e4a, 0x322276f3, 0x8a9e1196, - 0x982bbe78, 0x2097d91d, 0x78f4c94b, 0xc048ae2e, 0xd2fd01c0, - 0x6a4166a5, 0xf7965e1c, 0x4f2a3979, 0x5d9f9697, 0xe523f1f2, - 0x4d6b1905, 0xf5d77e60, 0xe762d18e, 0x5fdeb6eb, 0xc2098e52, - 0x7ab5e937, 0x680046d9, 0xd0bc21bc, 0x88df31ea, 0x3063568f, - 0x22d6f961, 0x9a6a9e04, 0x07bda6bd, 0xbf01c1d8, 0xadb46e36, - 0x15080953, 0x1d724e9a, 0xa5ce29ff, 0xb77b8611, 0x0fc7e174, - 0x9210d9cd, 0x2aacbea8, 0x38191146, 0x80a57623, 0xd8c66675, - 0x607a0110, 0x72cfaefe, 0xca73c99b, 0x57a4f122, 0xef189647, - 0xfdad39a9, 0x45115ecc, 0x764dee06, 0xcef18963, 0xdc44268d, - 0x64f841e8, 0xf92f7951, 0x41931e34, 0x5326b1da, 0xeb9ad6bf, - 0xb3f9c6e9, 0x0b45a18c, 0x19f00e62, 0xa14c6907, 0x3c9b51be, - 0x842736db, 0x96929935, 0x2e2efe50, 0x2654b999, 0x9ee8defc, - 0x8c5d7112, 0x34e11677, 0xa9362ece, 0x118a49ab, 0x033fe645, - 0xbb838120, 0xe3e09176, 0x5b5cf613, 0x49e959fd, 0xf1553e98, - 0x6c820621, 0xd43e6144, 0xc68bceaa, 0x7e37a9cf, 0xd67f4138, - 0x6ec3265d, 0x7c7689b3, 0xc4caeed6, 0x591dd66f, 0xe1a1b10a, - 0xf3141ee4, 0x4ba87981, 0x13cb69d7, 0xab770eb2, 0xb9c2a15c, - 0x017ec639, 0x9ca9fe80, 0x241599e5, 0x36a0360b, 0x8e1c516e, - 0x866616a7, 0x3eda71c2, 0x2c6fde2c, 0x94d3b949, 0x090481f0, - 0xb1b8e695, 0xa30d497b, 0x1bb12e1e, 0x43d23e48, 0xfb6e592d, - 0xe9dbf6c3, 0x516791a6, 0xccb0a91f, 0x740cce7a, 0x66b96194, - 0xde0506f1}, - {0x00000000, 0x01c26a37, 0x0384d46e, 0x0246be59, 0x0709a8dc, - 0x06cbc2eb, 0x048d7cb2, 0x054f1685, 0x0e1351b8, 0x0fd13b8f, - 0x0d9785d6, 0x0c55efe1, 0x091af964, 0x08d89353, 0x0a9e2d0a, - 0x0b5c473d, 0x1c26a370, 0x1de4c947, 0x1fa2771e, 0x1e601d29, - 0x1b2f0bac, 0x1aed619b, 0x18abdfc2, 0x1969b5f5, 0x1235f2c8, - 0x13f798ff, 0x11b126a6, 0x10734c91, 0x153c5a14, 0x14fe3023, - 0x16b88e7a, 0x177ae44d, 0x384d46e0, 0x398f2cd7, 0x3bc9928e, - 0x3a0bf8b9, 0x3f44ee3c, 0x3e86840b, 0x3cc03a52, 0x3d025065, - 0x365e1758, 0x379c7d6f, 0x35dac336, 0x3418a901, 0x3157bf84, - 0x3095d5b3, 0x32d36bea, 0x331101dd, 0x246be590, 0x25a98fa7, - 0x27ef31fe, 0x262d5bc9, 0x23624d4c, 0x22a0277b, 0x20e69922, - 0x2124f315, 0x2a78b428, 0x2bbade1f, 0x29fc6046, 0x283e0a71, - 0x2d711cf4, 0x2cb376c3, 0x2ef5c89a, 0x2f37a2ad, 0x709a8dc0, - 0x7158e7f7, 0x731e59ae, 0x72dc3399, 0x7793251c, 0x76514f2b, - 0x7417f172, 0x75d59b45, 0x7e89dc78, 0x7f4bb64f, 0x7d0d0816, - 0x7ccf6221, 0x798074a4, 0x78421e93, 0x7a04a0ca, 0x7bc6cafd, - 0x6cbc2eb0, 0x6d7e4487, 0x6f38fade, 0x6efa90e9, 0x6bb5866c, - 0x6a77ec5b, 0x68315202, 0x69f33835, 0x62af7f08, 0x636d153f, - 0x612bab66, 0x60e9c151, 0x65a6d7d4, 0x6464bde3, 0x662203ba, - 0x67e0698d, 0x48d7cb20, 0x4915a117, 0x4b531f4e, 0x4a917579, - 0x4fde63fc, 0x4e1c09cb, 0x4c5ab792, 0x4d98dda5, 0x46c49a98, - 0x4706f0af, 0x45404ef6, 0x448224c1, 0x41cd3244, 0x400f5873, - 0x4249e62a, 0x438b8c1d, 0x54f16850, 0x55330267, 0x5775bc3e, - 0x56b7d609, 0x53f8c08c, 0x523aaabb, 0x507c14e2, 0x51be7ed5, - 0x5ae239e8, 0x5b2053df, 0x5966ed86, 0x58a487b1, 0x5deb9134, - 0x5c29fb03, 0x5e6f455a, 0x5fad2f6d, 0xe1351b80, 0xe0f771b7, - 0xe2b1cfee, 0xe373a5d9, 0xe63cb35c, 0xe7fed96b, 0xe5b86732, - 0xe47a0d05, 0xef264a38, 0xeee4200f, 0xeca29e56, 0xed60f461, - 0xe82fe2e4, 0xe9ed88d3, 0xebab368a, 0xea695cbd, 0xfd13b8f0, - 0xfcd1d2c7, 0xfe976c9e, 0xff5506a9, 0xfa1a102c, 0xfbd87a1b, - 0xf99ec442, 0xf85cae75, 0xf300e948, 0xf2c2837f, 0xf0843d26, - 0xf1465711, 0xf4094194, 0xf5cb2ba3, 0xf78d95fa, 0xf64fffcd, - 0xd9785d60, 0xd8ba3757, 0xdafc890e, 0xdb3ee339, 0xde71f5bc, - 0xdfb39f8b, 0xddf521d2, 0xdc374be5, 0xd76b0cd8, 0xd6a966ef, - 0xd4efd8b6, 0xd52db281, 0xd062a404, 0xd1a0ce33, 0xd3e6706a, - 0xd2241a5d, 0xc55efe10, 0xc49c9427, 0xc6da2a7e, 0xc7184049, - 0xc25756cc, 0xc3953cfb, 0xc1d382a2, 0xc011e895, 0xcb4dafa8, - 0xca8fc59f, 0xc8c97bc6, 0xc90b11f1, 0xcc440774, 0xcd866d43, - 0xcfc0d31a, 0xce02b92d, 0x91af9640, 0x906dfc77, 0x922b422e, - 0x93e92819, 0x96a63e9c, 0x976454ab, 0x9522eaf2, 0x94e080c5, - 0x9fbcc7f8, 0x9e7eadcf, 0x9c381396, 0x9dfa79a1, 0x98b56f24, - 0x99770513, 0x9b31bb4a, 0x9af3d17d, 0x8d893530, 0x8c4b5f07, - 0x8e0de15e, 0x8fcf8b69, 0x8a809dec, 0x8b42f7db, 0x89044982, - 0x88c623b5, 0x839a6488, 0x82580ebf, 0x801eb0e6, 0x81dcdad1, - 0x8493cc54, 0x8551a663, 0x8717183a, 0x86d5720d, 0xa9e2d0a0, - 0xa820ba97, 0xaa6604ce, 0xaba46ef9, 0xaeeb787c, 0xaf29124b, - 0xad6fac12, 0xacadc625, 0xa7f18118, 0xa633eb2f, 0xa4755576, - 0xa5b73f41, 0xa0f829c4, 0xa13a43f3, 0xa37cfdaa, 0xa2be979d, - 0xb5c473d0, 0xb40619e7, 0xb640a7be, 0xb782cd89, 0xb2cddb0c, - 0xb30fb13b, 0xb1490f62, 0xb08b6555, 0xbbd72268, 0xba15485f, - 0xb853f606, 0xb9919c31, 0xbcde8ab4, 0xbd1ce083, 0xbf5a5eda, - 0xbe9834ed}, - {0x00000000, 0x191b3141, 0x32366282, 0x2b2d53c3, 0x646cc504, - 0x7d77f445, 0x565aa786, 0x4f4196c7, 0xc8d98a08, 0xd1c2bb49, - 0xfaefe88a, 0xe3f4d9cb, 0xacb54f0c, 0xb5ae7e4d, 0x9e832d8e, - 0x87981ccf, 0x4ac21251, 0x53d92310, 0x78f470d3, 0x61ef4192, - 0x2eaed755, 0x37b5e614, 0x1c98b5d7, 0x05838496, 0x821b9859, - 0x9b00a918, 0xb02dfadb, 0xa936cb9a, 0xe6775d5d, 0xff6c6c1c, - 0xd4413fdf, 0xcd5a0e9e, 0x958424a2, 0x8c9f15e3, 0xa7b24620, - 0xbea97761, 0xf1e8e1a6, 0xe8f3d0e7, 0xc3de8324, 0xdac5b265, - 0x5d5daeaa, 0x44469feb, 0x6f6bcc28, 0x7670fd69, 0x39316bae, - 0x202a5aef, 0x0b07092c, 0x121c386d, 0xdf4636f3, 0xc65d07b2, - 0xed705471, 0xf46b6530, 0xbb2af3f7, 0xa231c2b6, 0x891c9175, - 0x9007a034, 0x179fbcfb, 0x0e848dba, 0x25a9de79, 0x3cb2ef38, - 0x73f379ff, 0x6ae848be, 0x41c51b7d, 0x58de2a3c, 0xf0794f05, - 0xe9627e44, 0xc24f2d87, 0xdb541cc6, 0x94158a01, 0x8d0ebb40, - 0xa623e883, 0xbf38d9c2, 0x38a0c50d, 0x21bbf44c, 0x0a96a78f, - 0x138d96ce, 0x5ccc0009, 0x45d73148, 0x6efa628b, 0x77e153ca, - 0xbabb5d54, 0xa3a06c15, 0x888d3fd6, 0x91960e97, 0xded79850, - 0xc7cca911, 0xece1fad2, 0xf5facb93, 0x7262d75c, 0x6b79e61d, - 0x4054b5de, 0x594f849f, 0x160e1258, 0x0f152319, 0x243870da, - 0x3d23419b, 0x65fd6ba7, 0x7ce65ae6, 0x57cb0925, 0x4ed03864, - 0x0191aea3, 0x188a9fe2, 0x33a7cc21, 0x2abcfd60, 0xad24e1af, - 0xb43fd0ee, 0x9f12832d, 0x8609b26c, 0xc94824ab, 0xd05315ea, - 0xfb7e4629, 0xe2657768, 0x2f3f79f6, 0x362448b7, 0x1d091b74, - 0x04122a35, 0x4b53bcf2, 0x52488db3, 0x7965de70, 0x607eef31, - 0xe7e6f3fe, 0xfefdc2bf, 0xd5d0917c, 0xcccba03d, 0x838a36fa, - 0x9a9107bb, 0xb1bc5478, 0xa8a76539, 0x3b83984b, 0x2298a90a, - 0x09b5fac9, 0x10aecb88, 0x5fef5d4f, 0x46f46c0e, 0x6dd93fcd, - 0x74c20e8c, 0xf35a1243, 0xea412302, 0xc16c70c1, 0xd8774180, - 0x9736d747, 0x8e2de606, 0xa500b5c5, 0xbc1b8484, 0x71418a1a, - 0x685abb5b, 0x4377e898, 0x5a6cd9d9, 0x152d4f1e, 0x0c367e5f, - 0x271b2d9c, 0x3e001cdd, 0xb9980012, 0xa0833153, 0x8bae6290, - 0x92b553d1, 0xddf4c516, 0xc4eff457, 0xefc2a794, 0xf6d996d5, - 0xae07bce9, 0xb71c8da8, 0x9c31de6b, 0x852aef2a, 0xca6b79ed, - 0xd37048ac, 0xf85d1b6f, 0xe1462a2e, 0x66de36e1, 0x7fc507a0, - 0x54e85463, 0x4df36522, 0x02b2f3e5, 0x1ba9c2a4, 0x30849167, - 0x299fa026, 0xe4c5aeb8, 0xfdde9ff9, 0xd6f3cc3a, 0xcfe8fd7b, - 0x80a96bbc, 0x99b25afd, 0xb29f093e, 0xab84387f, 0x2c1c24b0, - 0x350715f1, 0x1e2a4632, 0x07317773, 0x4870e1b4, 0x516bd0f5, - 0x7a468336, 0x635db277, 0xcbfad74e, 0xd2e1e60f, 0xf9ccb5cc, - 0xe0d7848d, 0xaf96124a, 0xb68d230b, 0x9da070c8, 0x84bb4189, - 0x03235d46, 0x1a386c07, 0x31153fc4, 0x280e0e85, 0x674f9842, - 0x7e54a903, 0x5579fac0, 0x4c62cb81, 0x8138c51f, 0x9823f45e, - 0xb30ea79d, 0xaa1596dc, 0xe554001b, 0xfc4f315a, 0xd7626299, - 0xce7953d8, 0x49e14f17, 0x50fa7e56, 0x7bd72d95, 0x62cc1cd4, - 0x2d8d8a13, 0x3496bb52, 0x1fbbe891, 0x06a0d9d0, 0x5e7ef3ec, - 0x4765c2ad, 0x6c48916e, 0x7553a02f, 0x3a1236e8, 0x230907a9, - 0x0824546a, 0x113f652b, 0x96a779e4, 0x8fbc48a5, 0xa4911b66, - 0xbd8a2a27, 0xf2cbbce0, 0xebd08da1, 0xc0fdde62, 0xd9e6ef23, - 0x14bce1bd, 0x0da7d0fc, 0x268a833f, 0x3f91b27e, 0x70d024b9, - 0x69cb15f8, 0x42e6463b, 0x5bfd777a, 0xdc656bb5, 0xc57e5af4, - 0xee530937, 0xf7483876, 0xb809aeb1, 0xa1129ff0, 0x8a3fcc33, - 0x9324fd72}, - {0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, - 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, - 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, - 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, - 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, - 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, - 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, - 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, - 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, - 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, - 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, - 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, - 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, - 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, - 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, - 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, - 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, - 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, - 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, - 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, - 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, - 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, - 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, - 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, - 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, - 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, - 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, - 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, - 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, - 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, - 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, - 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, - 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, - 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, - 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, - 0x2d02ef8d}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x00000000, 0x96300777, 0x2c610eee, 0xba510999, 0x19c46d07, - 0x8ff46a70, 0x35a563e9, 0xa395649e, 0x3288db0e, 0xa4b8dc79, - 0x1ee9d5e0, 0x88d9d297, 0x2b4cb609, 0xbd7cb17e, 0x072db8e7, - 0x911dbf90, 0x6410b71d, 0xf220b06a, 0x4871b9f3, 0xde41be84, - 0x7dd4da1a, 0xebe4dd6d, 0x51b5d4f4, 0xc785d383, 0x56986c13, - 0xc0a86b64, 0x7af962fd, 0xecc9658a, 0x4f5c0114, 0xd96c0663, - 0x633d0ffa, 0xf50d088d, 0xc8206e3b, 0x5e10694c, 0xe44160d5, - 0x727167a2, 0xd1e4033c, 0x47d4044b, 0xfd850dd2, 0x6bb50aa5, - 0xfaa8b535, 0x6c98b242, 0xd6c9bbdb, 0x40f9bcac, 0xe36cd832, - 0x755cdf45, 0xcf0dd6dc, 0x593dd1ab, 0xac30d926, 0x3a00de51, - 0x8051d7c8, 0x1661d0bf, 0xb5f4b421, 0x23c4b356, 0x9995bacf, - 0x0fa5bdb8, 0x9eb80228, 0x0888055f, 0xb2d90cc6, 0x24e90bb1, - 0x877c6f2f, 0x114c6858, 0xab1d61c1, 0x3d2d66b6, 0x9041dc76, - 0x0671db01, 0xbc20d298, 0x2a10d5ef, 0x8985b171, 0x1fb5b606, - 0xa5e4bf9f, 0x33d4b8e8, 0xa2c90778, 0x34f9000f, 0x8ea80996, - 0x18980ee1, 0xbb0d6a7f, 0x2d3d6d08, 0x976c6491, 0x015c63e6, - 0xf4516b6b, 0x62616c1c, 0xd8306585, 0x4e0062f2, 0xed95066c, - 0x7ba5011b, 0xc1f40882, 0x57c40ff5, 0xc6d9b065, 0x50e9b712, - 0xeab8be8b, 0x7c88b9fc, 0xdf1ddd62, 0x492dda15, 0xf37cd38c, - 0x654cd4fb, 0x5861b24d, 0xce51b53a, 0x7400bca3, 0xe230bbd4, - 0x41a5df4a, 0xd795d83d, 0x6dc4d1a4, 0xfbf4d6d3, 0x6ae96943, - 0xfcd96e34, 0x468867ad, 0xd0b860da, 0x732d0444, 0xe51d0333, - 0x5f4c0aaa, 0xc97c0ddd, 0x3c710550, 0xaa410227, 0x10100bbe, - 0x86200cc9, 0x25b56857, 0xb3856f20, 0x09d466b9, 0x9fe461ce, - 0x0ef9de5e, 0x98c9d929, 0x2298d0b0, 0xb4a8d7c7, 0x173db359, - 0x810db42e, 0x3b5cbdb7, 0xad6cbac0, 0x2083b8ed, 0xb6b3bf9a, - 0x0ce2b603, 0x9ad2b174, 0x3947d5ea, 0xaf77d29d, 0x1526db04, - 0x8316dc73, 0x120b63e3, 0x843b6494, 0x3e6a6d0d, 0xa85a6a7a, - 0x0bcf0ee4, 0x9dff0993, 0x27ae000a, 0xb19e077d, 0x44930ff0, - 0xd2a30887, 0x68f2011e, 0xfec20669, 0x5d5762f7, 0xcb676580, - 0x71366c19, 0xe7066b6e, 0x761bd4fe, 0xe02bd389, 0x5a7ada10, - 0xcc4add67, 0x6fdfb9f9, 0xf9efbe8e, 0x43beb717, 0xd58eb060, - 0xe8a3d6d6, 0x7e93d1a1, 0xc4c2d838, 0x52f2df4f, 0xf167bbd1, - 0x6757bca6, 0xdd06b53f, 0x4b36b248, 0xda2b0dd8, 0x4c1b0aaf, - 0xf64a0336, 0x607a0441, 0xc3ef60df, 0x55df67a8, 0xef8e6e31, - 0x79be6946, 0x8cb361cb, 0x1a8366bc, 0xa0d26f25, 0x36e26852, - 0x95770ccc, 0x03470bbb, 0xb9160222, 0x2f260555, 0xbe3bbac5, - 0x280bbdb2, 0x925ab42b, 0x046ab35c, 0xa7ffd7c2, 0x31cfd0b5, - 0x8b9ed92c, 0x1daede5b, 0xb0c2649b, 0x26f263ec, 0x9ca36a75, - 0x0a936d02, 0xa906099c, 0x3f360eeb, 0x85670772, 0x13570005, - 0x824abf95, 0x147ab8e2, 0xae2bb17b, 0x381bb60c, 0x9b8ed292, - 0x0dbed5e5, 0xb7efdc7c, 0x21dfdb0b, 0xd4d2d386, 0x42e2d4f1, - 0xf8b3dd68, 0x6e83da1f, 0xcd16be81, 0x5b26b9f6, 0xe177b06f, - 0x7747b718, 0xe65a0888, 0x706a0fff, 0xca3b0666, 0x5c0b0111, - 0xff9e658f, 0x69ae62f8, 0xd3ff6b61, 0x45cf6c16, 0x78e20aa0, - 0xeed20dd7, 0x5483044e, 0xc2b30339, 0x612667a7, 0xf71660d0, - 0x4d476949, 0xdb776e3e, 0x4a6ad1ae, 0xdc5ad6d9, 0x660bdf40, - 0xf03bd837, 0x53aebca9, 0xc59ebbde, 0x7fcfb247, 0xe9ffb530, - 0x1cf2bdbd, 0x8ac2baca, 0x3093b353, 0xa6a3b424, 0x0536d0ba, - 0x9306d7cd, 0x2957de54, 0xbf67d923, 0x2e7a66b3, 0xb84a61c4, - 0x021b685d, 0x942b6f2a, 0x37be0bb4, 0xa18e0cc3, 0x1bdf055a, - 0x8def022d}, - {0x00000000, 0x41311b19, 0x82623632, 0xc3532d2b, 0x04c56c64, - 0x45f4777d, 0x86a75a56, 0xc796414f, 0x088ad9c8, 0x49bbc2d1, - 0x8ae8effa, 0xcbd9f4e3, 0x0c4fb5ac, 0x4d7eaeb5, 0x8e2d839e, - 0xcf1c9887, 0x5112c24a, 0x1023d953, 0xd370f478, 0x9241ef61, - 0x55d7ae2e, 0x14e6b537, 0xd7b5981c, 0x96848305, 0x59981b82, - 0x18a9009b, 0xdbfa2db0, 0x9acb36a9, 0x5d5d77e6, 0x1c6c6cff, - 0xdf3f41d4, 0x9e0e5acd, 0xa2248495, 0xe3159f8c, 0x2046b2a7, - 0x6177a9be, 0xa6e1e8f1, 0xe7d0f3e8, 0x2483dec3, 0x65b2c5da, - 0xaaae5d5d, 0xeb9f4644, 0x28cc6b6f, 0x69fd7076, 0xae6b3139, - 0xef5a2a20, 0x2c09070b, 0x6d381c12, 0xf33646df, 0xb2075dc6, - 0x715470ed, 0x30656bf4, 0xf7f32abb, 0xb6c231a2, 0x75911c89, - 0x34a00790, 0xfbbc9f17, 0xba8d840e, 0x79dea925, 0x38efb23c, - 0xff79f373, 0xbe48e86a, 0x7d1bc541, 0x3c2ade58, 0x054f79f0, - 0x447e62e9, 0x872d4fc2, 0xc61c54db, 0x018a1594, 0x40bb0e8d, - 0x83e823a6, 0xc2d938bf, 0x0dc5a038, 0x4cf4bb21, 0x8fa7960a, - 0xce968d13, 0x0900cc5c, 0x4831d745, 0x8b62fa6e, 0xca53e177, - 0x545dbbba, 0x156ca0a3, 0xd63f8d88, 0x970e9691, 0x5098d7de, - 0x11a9ccc7, 0xd2fae1ec, 0x93cbfaf5, 0x5cd76272, 0x1de6796b, - 0xdeb55440, 0x9f844f59, 0x58120e16, 0x1923150f, 0xda703824, - 0x9b41233d, 0xa76bfd65, 0xe65ae67c, 0x2509cb57, 0x6438d04e, - 0xa3ae9101, 0xe29f8a18, 0x21cca733, 0x60fdbc2a, 0xafe124ad, - 0xeed03fb4, 0x2d83129f, 0x6cb20986, 0xab2448c9, 0xea1553d0, - 0x29467efb, 0x687765e2, 0xf6793f2f, 0xb7482436, 0x741b091d, - 0x352a1204, 0xf2bc534b, 0xb38d4852, 0x70de6579, 0x31ef7e60, - 0xfef3e6e7, 0xbfc2fdfe, 0x7c91d0d5, 0x3da0cbcc, 0xfa368a83, - 0xbb07919a, 0x7854bcb1, 0x3965a7a8, 0x4b98833b, 0x0aa99822, - 0xc9fab509, 0x88cbae10, 0x4f5def5f, 0x0e6cf446, 0xcd3fd96d, - 0x8c0ec274, 0x43125af3, 0x022341ea, 0xc1706cc1, 0x804177d8, - 0x47d73697, 0x06e62d8e, 0xc5b500a5, 0x84841bbc, 0x1a8a4171, - 0x5bbb5a68, 0x98e87743, 0xd9d96c5a, 0x1e4f2d15, 0x5f7e360c, - 0x9c2d1b27, 0xdd1c003e, 0x120098b9, 0x533183a0, 0x9062ae8b, - 0xd153b592, 0x16c5f4dd, 0x57f4efc4, 0x94a7c2ef, 0xd596d9f6, - 0xe9bc07ae, 0xa88d1cb7, 0x6bde319c, 0x2aef2a85, 0xed796bca, - 0xac4870d3, 0x6f1b5df8, 0x2e2a46e1, 0xe136de66, 0xa007c57f, - 0x6354e854, 0x2265f34d, 0xe5f3b202, 0xa4c2a91b, 0x67918430, - 0x26a09f29, 0xb8aec5e4, 0xf99fdefd, 0x3accf3d6, 0x7bfde8cf, - 0xbc6ba980, 0xfd5ab299, 0x3e099fb2, 0x7f3884ab, 0xb0241c2c, - 0xf1150735, 0x32462a1e, 0x73773107, 0xb4e17048, 0xf5d06b51, - 0x3683467a, 0x77b25d63, 0x4ed7facb, 0x0fe6e1d2, 0xccb5ccf9, - 0x8d84d7e0, 0x4a1296af, 0x0b238db6, 0xc870a09d, 0x8941bb84, - 0x465d2303, 0x076c381a, 0xc43f1531, 0x850e0e28, 0x42984f67, - 0x03a9547e, 0xc0fa7955, 0x81cb624c, 0x1fc53881, 0x5ef42398, - 0x9da70eb3, 0xdc9615aa, 0x1b0054e5, 0x5a314ffc, 0x996262d7, - 0xd85379ce, 0x174fe149, 0x567efa50, 0x952dd77b, 0xd41ccc62, - 0x138a8d2d, 0x52bb9634, 0x91e8bb1f, 0xd0d9a006, 0xecf37e5e, - 0xadc26547, 0x6e91486c, 0x2fa05375, 0xe836123a, 0xa9070923, - 0x6a542408, 0x2b653f11, 0xe479a796, 0xa548bc8f, 0x661b91a4, - 0x272a8abd, 0xe0bccbf2, 0xa18dd0eb, 0x62defdc0, 0x23efe6d9, - 0xbde1bc14, 0xfcd0a70d, 0x3f838a26, 0x7eb2913f, 0xb924d070, - 0xf815cb69, 0x3b46e642, 0x7a77fd5b, 0xb56b65dc, 0xf45a7ec5, - 0x370953ee, 0x763848f7, 0xb1ae09b8, 0xf09f12a1, 0x33cc3f8a, - 0x72fd2493}, - {0x00000000, 0x376ac201, 0x6ed48403, 0x59be4602, 0xdca80907, - 0xebc2cb06, 0xb27c8d04, 0x85164f05, 0xb851130e, 0x8f3bd10f, - 0xd685970d, 0xe1ef550c, 0x64f91a09, 0x5393d808, 0x0a2d9e0a, - 0x3d475c0b, 0x70a3261c, 0x47c9e41d, 0x1e77a21f, 0x291d601e, - 0xac0b2f1b, 0x9b61ed1a, 0xc2dfab18, 0xf5b56919, 0xc8f23512, - 0xff98f713, 0xa626b111, 0x914c7310, 0x145a3c15, 0x2330fe14, - 0x7a8eb816, 0x4de47a17, 0xe0464d38, 0xd72c8f39, 0x8e92c93b, - 0xb9f80b3a, 0x3cee443f, 0x0b84863e, 0x523ac03c, 0x6550023d, - 0x58175e36, 0x6f7d9c37, 0x36c3da35, 0x01a91834, 0x84bf5731, - 0xb3d59530, 0xea6bd332, 0xdd011133, 0x90e56b24, 0xa78fa925, - 0xfe31ef27, 0xc95b2d26, 0x4c4d6223, 0x7b27a022, 0x2299e620, - 0x15f32421, 0x28b4782a, 0x1fdeba2b, 0x4660fc29, 0x710a3e28, - 0xf41c712d, 0xc376b32c, 0x9ac8f52e, 0xada2372f, 0xc08d9a70, - 0xf7e75871, 0xae591e73, 0x9933dc72, 0x1c259377, 0x2b4f5176, - 0x72f11774, 0x459bd575, 0x78dc897e, 0x4fb64b7f, 0x16080d7d, - 0x2162cf7c, 0xa4748079, 0x931e4278, 0xcaa0047a, 0xfdcac67b, - 0xb02ebc6c, 0x87447e6d, 0xdefa386f, 0xe990fa6e, 0x6c86b56b, - 0x5bec776a, 0x02523168, 0x3538f369, 0x087faf62, 0x3f156d63, - 0x66ab2b61, 0x51c1e960, 0xd4d7a665, 0xe3bd6464, 0xba032266, - 0x8d69e067, 0x20cbd748, 0x17a11549, 0x4e1f534b, 0x7975914a, - 0xfc63de4f, 0xcb091c4e, 0x92b75a4c, 0xa5dd984d, 0x989ac446, - 0xaff00647, 0xf64e4045, 0xc1248244, 0x4432cd41, 0x73580f40, - 0x2ae64942, 0x1d8c8b43, 0x5068f154, 0x67023355, 0x3ebc7557, - 0x09d6b756, 0x8cc0f853, 0xbbaa3a52, 0xe2147c50, 0xd57ebe51, - 0xe839e25a, 0xdf53205b, 0x86ed6659, 0xb187a458, 0x3491eb5d, - 0x03fb295c, 0x5a456f5e, 0x6d2fad5f, 0x801b35e1, 0xb771f7e0, - 0xeecfb1e2, 0xd9a573e3, 0x5cb33ce6, 0x6bd9fee7, 0x3267b8e5, - 0x050d7ae4, 0x384a26ef, 0x0f20e4ee, 0x569ea2ec, 0x61f460ed, - 0xe4e22fe8, 0xd388ede9, 0x8a36abeb, 0xbd5c69ea, 0xf0b813fd, - 0xc7d2d1fc, 0x9e6c97fe, 0xa90655ff, 0x2c101afa, 0x1b7ad8fb, - 0x42c49ef9, 0x75ae5cf8, 0x48e900f3, 0x7f83c2f2, 0x263d84f0, - 0x115746f1, 0x944109f4, 0xa32bcbf5, 0xfa958df7, 0xcdff4ff6, - 0x605d78d9, 0x5737bad8, 0x0e89fcda, 0x39e33edb, 0xbcf571de, - 0x8b9fb3df, 0xd221f5dd, 0xe54b37dc, 0xd80c6bd7, 0xef66a9d6, - 0xb6d8efd4, 0x81b22dd5, 0x04a462d0, 0x33cea0d1, 0x6a70e6d3, - 0x5d1a24d2, 0x10fe5ec5, 0x27949cc4, 0x7e2adac6, 0x494018c7, - 0xcc5657c2, 0xfb3c95c3, 0xa282d3c1, 0x95e811c0, 0xa8af4dcb, - 0x9fc58fca, 0xc67bc9c8, 0xf1110bc9, 0x740744cc, 0x436d86cd, - 0x1ad3c0cf, 0x2db902ce, 0x4096af91, 0x77fc6d90, 0x2e422b92, - 0x1928e993, 0x9c3ea696, 0xab546497, 0xf2ea2295, 0xc580e094, - 0xf8c7bc9f, 0xcfad7e9e, 0x9613389c, 0xa179fa9d, 0x246fb598, - 0x13057799, 0x4abb319b, 0x7dd1f39a, 0x3035898d, 0x075f4b8c, - 0x5ee10d8e, 0x698bcf8f, 0xec9d808a, 0xdbf7428b, 0x82490489, - 0xb523c688, 0x88649a83, 0xbf0e5882, 0xe6b01e80, 0xd1dadc81, - 0x54cc9384, 0x63a65185, 0x3a181787, 0x0d72d586, 0xa0d0e2a9, - 0x97ba20a8, 0xce0466aa, 0xf96ea4ab, 0x7c78ebae, 0x4b1229af, - 0x12ac6fad, 0x25c6adac, 0x1881f1a7, 0x2feb33a6, 0x765575a4, - 0x413fb7a5, 0xc429f8a0, 0xf3433aa1, 0xaafd7ca3, 0x9d97bea2, - 0xd073c4b5, 0xe71906b4, 0xbea740b6, 0x89cd82b7, 0x0cdbcdb2, - 0x3bb10fb3, 0x620f49b1, 0x55658bb0, 0x6822d7bb, 0x5f4815ba, - 0x06f653b8, 0x319c91b9, 0xb48adebc, 0x83e01cbd, 0xda5e5abf, - 0xed3498be}, - {0x00000000, 0x6567bcb8, 0x8bc809aa, 0xeeafb512, 0x5797628f, - 0x32f0de37, 0xdc5f6b25, 0xb938d79d, 0xef28b4c5, 0x8a4f087d, - 0x64e0bd6f, 0x018701d7, 0xb8bfd64a, 0xddd86af2, 0x3377dfe0, - 0x56106358, 0x9f571950, 0xfa30a5e8, 0x149f10fa, 0x71f8ac42, - 0xc8c07bdf, 0xada7c767, 0x43087275, 0x266fcecd, 0x707fad95, - 0x1518112d, 0xfbb7a43f, 0x9ed01887, 0x27e8cf1a, 0x428f73a2, - 0xac20c6b0, 0xc9477a08, 0x3eaf32a0, 0x5bc88e18, 0xb5673b0a, - 0xd00087b2, 0x6938502f, 0x0c5fec97, 0xe2f05985, 0x8797e53d, - 0xd1878665, 0xb4e03add, 0x5a4f8fcf, 0x3f283377, 0x8610e4ea, - 0xe3775852, 0x0dd8ed40, 0x68bf51f8, 0xa1f82bf0, 0xc49f9748, - 0x2a30225a, 0x4f579ee2, 0xf66f497f, 0x9308f5c7, 0x7da740d5, - 0x18c0fc6d, 0x4ed09f35, 0x2bb7238d, 0xc518969f, 0xa07f2a27, - 0x1947fdba, 0x7c204102, 0x928ff410, 0xf7e848a8, 0x3d58149b, - 0x583fa823, 0xb6901d31, 0xd3f7a189, 0x6acf7614, 0x0fa8caac, - 0xe1077fbe, 0x8460c306, 0xd270a05e, 0xb7171ce6, 0x59b8a9f4, - 0x3cdf154c, 0x85e7c2d1, 0xe0807e69, 0x0e2fcb7b, 0x6b4877c3, - 0xa20f0dcb, 0xc768b173, 0x29c70461, 0x4ca0b8d9, 0xf5986f44, - 0x90ffd3fc, 0x7e5066ee, 0x1b37da56, 0x4d27b90e, 0x284005b6, - 0xc6efb0a4, 0xa3880c1c, 0x1ab0db81, 0x7fd76739, 0x9178d22b, - 0xf41f6e93, 0x03f7263b, 0x66909a83, 0x883f2f91, 0xed589329, - 0x546044b4, 0x3107f80c, 0xdfa84d1e, 0xbacff1a6, 0xecdf92fe, - 0x89b82e46, 0x67179b54, 0x027027ec, 0xbb48f071, 0xde2f4cc9, - 0x3080f9db, 0x55e74563, 0x9ca03f6b, 0xf9c783d3, 0x176836c1, - 0x720f8a79, 0xcb375de4, 0xae50e15c, 0x40ff544e, 0x2598e8f6, - 0x73888bae, 0x16ef3716, 0xf8408204, 0x9d273ebc, 0x241fe921, - 0x41785599, 0xafd7e08b, 0xcab05c33, 0x3bb659ed, 0x5ed1e555, - 0xb07e5047, 0xd519ecff, 0x6c213b62, 0x094687da, 0xe7e932c8, - 0x828e8e70, 0xd49eed28, 0xb1f95190, 0x5f56e482, 0x3a31583a, - 0x83098fa7, 0xe66e331f, 0x08c1860d, 0x6da63ab5, 0xa4e140bd, - 0xc186fc05, 0x2f294917, 0x4a4ef5af, 0xf3762232, 0x96119e8a, - 0x78be2b98, 0x1dd99720, 0x4bc9f478, 0x2eae48c0, 0xc001fdd2, - 0xa566416a, 0x1c5e96f7, 0x79392a4f, 0x97969f5d, 0xf2f123e5, - 0x05196b4d, 0x607ed7f5, 0x8ed162e7, 0xebb6de5f, 0x528e09c2, - 0x37e9b57a, 0xd9460068, 0xbc21bcd0, 0xea31df88, 0x8f566330, - 0x61f9d622, 0x049e6a9a, 0xbda6bd07, 0xd8c101bf, 0x366eb4ad, - 0x53090815, 0x9a4e721d, 0xff29cea5, 0x11867bb7, 0x74e1c70f, - 0xcdd91092, 0xa8beac2a, 0x46111938, 0x2376a580, 0x7566c6d8, - 0x10017a60, 0xfeaecf72, 0x9bc973ca, 0x22f1a457, 0x479618ef, - 0xa939adfd, 0xcc5e1145, 0x06ee4d76, 0x6389f1ce, 0x8d2644dc, - 0xe841f864, 0x51792ff9, 0x341e9341, 0xdab12653, 0xbfd69aeb, - 0xe9c6f9b3, 0x8ca1450b, 0x620ef019, 0x07694ca1, 0xbe519b3c, - 0xdb362784, 0x35999296, 0x50fe2e2e, 0x99b95426, 0xfcdee89e, - 0x12715d8c, 0x7716e134, 0xce2e36a9, 0xab498a11, 0x45e63f03, - 0x208183bb, 0x7691e0e3, 0x13f65c5b, 0xfd59e949, 0x983e55f1, - 0x2106826c, 0x44613ed4, 0xaace8bc6, 0xcfa9377e, 0x38417fd6, - 0x5d26c36e, 0xb389767c, 0xd6eecac4, 0x6fd61d59, 0x0ab1a1e1, - 0xe41e14f3, 0x8179a84b, 0xd769cb13, 0xb20e77ab, 0x5ca1c2b9, - 0x39c67e01, 0x80fea99c, 0xe5991524, 0x0b36a036, 0x6e511c8e, - 0xa7166686, 0xc271da3e, 0x2cde6f2c, 0x49b9d394, 0xf0810409, - 0x95e6b8b1, 0x7b490da3, 0x1e2eb11b, 0x483ed243, 0x2d596efb, - 0xc3f6dbe9, 0xa6916751, 0x1fa9b0cc, 0x7ace0c74, 0x9461b966, - 0xf10605de}}; - -#endif - -#endif - -#if N == 2 - -#if W == 8 - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0xae689191, 0x87a02563, 0x29c8b4f2, 0xd4314c87, - 0x7a59dd16, 0x539169e4, 0xfdf9f875, 0x73139f4f, 0xdd7b0ede, - 0xf4b3ba2c, 0x5adb2bbd, 0xa722d3c8, 0x094a4259, 0x2082f6ab, - 0x8eea673a, 0xe6273e9e, 0x484faf0f, 0x61871bfd, 0xcfef8a6c, - 0x32167219, 0x9c7ee388, 0xb5b6577a, 0x1bdec6eb, 0x9534a1d1, - 0x3b5c3040, 0x129484b2, 0xbcfc1523, 0x4105ed56, 0xef6d7cc7, - 0xc6a5c835, 0x68cd59a4, 0x173f7b7d, 0xb957eaec, 0x909f5e1e, - 0x3ef7cf8f, 0xc30e37fa, 0x6d66a66b, 0x44ae1299, 0xeac68308, - 0x642ce432, 0xca4475a3, 0xe38cc151, 0x4de450c0, 0xb01da8b5, - 0x1e753924, 0x37bd8dd6, 0x99d51c47, 0xf11845e3, 0x5f70d472, - 0x76b86080, 0xd8d0f111, 0x25290964, 0x8b4198f5, 0xa2892c07, - 0x0ce1bd96, 0x820bdaac, 0x2c634b3d, 0x05abffcf, 0xabc36e5e, - 0x563a962b, 0xf85207ba, 0xd19ab348, 0x7ff222d9, 0x2e7ef6fa, - 0x8016676b, 0xa9ded399, 0x07b64208, 0xfa4fba7d, 0x54272bec, - 0x7def9f1e, 0xd3870e8f, 0x5d6d69b5, 0xf305f824, 0xdacd4cd6, - 0x74a5dd47, 0x895c2532, 0x2734b4a3, 0x0efc0051, 0xa09491c0, - 0xc859c864, 0x663159f5, 0x4ff9ed07, 0xe1917c96, 0x1c6884e3, - 0xb2001572, 0x9bc8a180, 0x35a03011, 0xbb4a572b, 0x1522c6ba, - 0x3cea7248, 0x9282e3d9, 0x6f7b1bac, 0xc1138a3d, 0xe8db3ecf, - 0x46b3af5e, 0x39418d87, 0x97291c16, 0xbee1a8e4, 0x10893975, - 0xed70c100, 0x43185091, 0x6ad0e463, 0xc4b875f2, 0x4a5212c8, - 0xe43a8359, 0xcdf237ab, 0x639aa63a, 0x9e635e4f, 0x300bcfde, - 0x19c37b2c, 0xb7abeabd, 0xdf66b319, 0x710e2288, 0x58c6967a, - 0xf6ae07eb, 0x0b57ff9e, 0xa53f6e0f, 0x8cf7dafd, 0x229f4b6c, - 0xac752c56, 0x021dbdc7, 0x2bd50935, 0x85bd98a4, 0x784460d1, - 0xd62cf140, 0xffe445b2, 0x518cd423, 0x5cfdedf4, 0xf2957c65, - 0xdb5dc897, 0x75355906, 0x88cca173, 0x26a430e2, 0x0f6c8410, - 0xa1041581, 0x2fee72bb, 0x8186e32a, 0xa84e57d8, 0x0626c649, - 0xfbdf3e3c, 0x55b7afad, 0x7c7f1b5f, 0xd2178ace, 0xbadad36a, - 0x14b242fb, 0x3d7af609, 0x93126798, 0x6eeb9fed, 0xc0830e7c, - 0xe94bba8e, 0x47232b1f, 0xc9c94c25, 0x67a1ddb4, 0x4e696946, - 0xe001f8d7, 0x1df800a2, 0xb3909133, 0x9a5825c1, 0x3430b450, - 0x4bc29689, 0xe5aa0718, 0xcc62b3ea, 0x620a227b, 0x9ff3da0e, - 0x319b4b9f, 0x1853ff6d, 0xb63b6efc, 0x38d109c6, 0x96b99857, - 0xbf712ca5, 0x1119bd34, 0xece04541, 0x4288d4d0, 0x6b406022, - 0xc528f1b3, 0xade5a817, 0x038d3986, 0x2a458d74, 0x842d1ce5, - 0x79d4e490, 0xd7bc7501, 0xfe74c1f3, 0x501c5062, 0xdef63758, - 0x709ea6c9, 0x5956123b, 0xf73e83aa, 0x0ac77bdf, 0xa4afea4e, - 0x8d675ebc, 0x230fcf2d, 0x72831b0e, 0xdceb8a9f, 0xf5233e6d, - 0x5b4baffc, 0xa6b25789, 0x08dac618, 0x211272ea, 0x8f7ae37b, - 0x01908441, 0xaff815d0, 0x8630a122, 0x285830b3, 0xd5a1c8c6, - 0x7bc95957, 0x5201eda5, 0xfc697c34, 0x94a42590, 0x3accb401, - 0x130400f3, 0xbd6c9162, 0x40956917, 0xeefdf886, 0xc7354c74, - 0x695ddde5, 0xe7b7badf, 0x49df2b4e, 0x60179fbc, 0xce7f0e2d, - 0x3386f658, 0x9dee67c9, 0xb426d33b, 0x1a4e42aa, 0x65bc6073, - 0xcbd4f1e2, 0xe21c4510, 0x4c74d481, 0xb18d2cf4, 0x1fe5bd65, - 0x362d0997, 0x98459806, 0x16afff3c, 0xb8c76ead, 0x910fda5f, - 0x3f674bce, 0xc29eb3bb, 0x6cf6222a, 0x453e96d8, 0xeb560749, - 0x839b5eed, 0x2df3cf7c, 0x043b7b8e, 0xaa53ea1f, 0x57aa126a, - 0xf9c283fb, 0xd00a3709, 0x7e62a698, 0xf088c1a2, 0x5ee05033, - 0x7728e4c1, 0xd9407550, 0x24b98d25, 0x8ad11cb4, 0xa319a846, - 0x0d7139d7}, - {0x00000000, 0xb9fbdbe8, 0xa886b191, 0x117d6a79, 0x8a7c6563, - 0x3387be8b, 0x22fad4f2, 0x9b010f1a, 0xcf89cc87, 0x7672176f, - 0x670f7d16, 0xdef4a6fe, 0x45f5a9e4, 0xfc0e720c, 0xed731875, - 0x5488c39d, 0x44629f4f, 0xfd9944a7, 0xece42ede, 0x551ff536, - 0xce1efa2c, 0x77e521c4, 0x66984bbd, 0xdf639055, 0x8beb53c8, - 0x32108820, 0x236de259, 0x9a9639b1, 0x019736ab, 0xb86ced43, - 0xa911873a, 0x10ea5cd2, 0x88c53e9e, 0x313ee576, 0x20438f0f, - 0x99b854e7, 0x02b95bfd, 0xbb428015, 0xaa3fea6c, 0x13c43184, - 0x474cf219, 0xfeb729f1, 0xefca4388, 0x56319860, 0xcd30977a, - 0x74cb4c92, 0x65b626eb, 0xdc4dfd03, 0xcca7a1d1, 0x755c7a39, - 0x64211040, 0xdddacba8, 0x46dbc4b2, 0xff201f5a, 0xee5d7523, - 0x57a6aecb, 0x032e6d56, 0xbad5b6be, 0xaba8dcc7, 0x1253072f, - 0x89520835, 0x30a9d3dd, 0x21d4b9a4, 0x982f624c, 0xcafb7b7d, - 0x7300a095, 0x627dcaec, 0xdb861104, 0x40871e1e, 0xf97cc5f6, - 0xe801af8f, 0x51fa7467, 0x0572b7fa, 0xbc896c12, 0xadf4066b, - 0x140fdd83, 0x8f0ed299, 0x36f50971, 0x27886308, 0x9e73b8e0, - 0x8e99e432, 0x37623fda, 0x261f55a3, 0x9fe48e4b, 0x04e58151, - 0xbd1e5ab9, 0xac6330c0, 0x1598eb28, 0x411028b5, 0xf8ebf35d, - 0xe9969924, 0x506d42cc, 0xcb6c4dd6, 0x7297963e, 0x63eafc47, - 0xda1127af, 0x423e45e3, 0xfbc59e0b, 0xeab8f472, 0x53432f9a, - 0xc8422080, 0x71b9fb68, 0x60c49111, 0xd93f4af9, 0x8db78964, - 0x344c528c, 0x253138f5, 0x9ccae31d, 0x07cbec07, 0xbe3037ef, - 0xaf4d5d96, 0x16b6867e, 0x065cdaac, 0xbfa70144, 0xaeda6b3d, - 0x1721b0d5, 0x8c20bfcf, 0x35db6427, 0x24a60e5e, 0x9d5dd5b6, - 0xc9d5162b, 0x702ecdc3, 0x6153a7ba, 0xd8a87c52, 0x43a97348, - 0xfa52a8a0, 0xeb2fc2d9, 0x52d41931, 0x4e87f0bb, 0xf77c2b53, - 0xe601412a, 0x5ffa9ac2, 0xc4fb95d8, 0x7d004e30, 0x6c7d2449, - 0xd586ffa1, 0x810e3c3c, 0x38f5e7d4, 0x29888dad, 0x90735645, - 0x0b72595f, 0xb28982b7, 0xa3f4e8ce, 0x1a0f3326, 0x0ae56ff4, - 0xb31eb41c, 0xa263de65, 0x1b98058d, 0x80990a97, 0x3962d17f, - 0x281fbb06, 0x91e460ee, 0xc56ca373, 0x7c97789b, 0x6dea12e2, - 0xd411c90a, 0x4f10c610, 0xf6eb1df8, 0xe7967781, 0x5e6dac69, - 0xc642ce25, 0x7fb915cd, 0x6ec47fb4, 0xd73fa45c, 0x4c3eab46, - 0xf5c570ae, 0xe4b81ad7, 0x5d43c13f, 0x09cb02a2, 0xb030d94a, - 0xa14db333, 0x18b668db, 0x83b767c1, 0x3a4cbc29, 0x2b31d650, - 0x92ca0db8, 0x8220516a, 0x3bdb8a82, 0x2aa6e0fb, 0x935d3b13, - 0x085c3409, 0xb1a7efe1, 0xa0da8598, 0x19215e70, 0x4da99ded, - 0xf4524605, 0xe52f2c7c, 0x5cd4f794, 0xc7d5f88e, 0x7e2e2366, - 0x6f53491f, 0xd6a892f7, 0x847c8bc6, 0x3d87502e, 0x2cfa3a57, - 0x9501e1bf, 0x0e00eea5, 0xb7fb354d, 0xa6865f34, 0x1f7d84dc, - 0x4bf54741, 0xf20e9ca9, 0xe373f6d0, 0x5a882d38, 0xc1892222, - 0x7872f9ca, 0x690f93b3, 0xd0f4485b, 0xc01e1489, 0x79e5cf61, - 0x6898a518, 0xd1637ef0, 0x4a6271ea, 0xf399aa02, 0xe2e4c07b, - 0x5b1f1b93, 0x0f97d80e, 0xb66c03e6, 0xa711699f, 0x1eeab277, - 0x85ebbd6d, 0x3c106685, 0x2d6d0cfc, 0x9496d714, 0x0cb9b558, - 0xb5426eb0, 0xa43f04c9, 0x1dc4df21, 0x86c5d03b, 0x3f3e0bd3, - 0x2e4361aa, 0x97b8ba42, 0xc33079df, 0x7acba237, 0x6bb6c84e, - 0xd24d13a6, 0x494c1cbc, 0xf0b7c754, 0xe1caad2d, 0x583176c5, - 0x48db2a17, 0xf120f1ff, 0xe05d9b86, 0x59a6406e, 0xc2a74f74, - 0x7b5c949c, 0x6a21fee5, 0xd3da250d, 0x8752e690, 0x3ea93d78, - 0x2fd45701, 0x962f8ce9, 0x0d2e83f3, 0xb4d5581b, 0xa5a83262, - 0x1c53e98a}, - {0x00000000, 0x9d0fe176, 0xe16ec4ad, 0x7c6125db, 0x19ac8f1b, - 0x84a36e6d, 0xf8c24bb6, 0x65cdaac0, 0x33591e36, 0xae56ff40, - 0xd237da9b, 0x4f383bed, 0x2af5912d, 0xb7fa705b, 0xcb9b5580, - 0x5694b4f6, 0x66b23c6c, 0xfbbddd1a, 0x87dcf8c1, 0x1ad319b7, - 0x7f1eb377, 0xe2115201, 0x9e7077da, 0x037f96ac, 0x55eb225a, - 0xc8e4c32c, 0xb485e6f7, 0x298a0781, 0x4c47ad41, 0xd1484c37, - 0xad2969ec, 0x3026889a, 0xcd6478d8, 0x506b99ae, 0x2c0abc75, - 0xb1055d03, 0xd4c8f7c3, 0x49c716b5, 0x35a6336e, 0xa8a9d218, - 0xfe3d66ee, 0x63328798, 0x1f53a243, 0x825c4335, 0xe791e9f5, - 0x7a9e0883, 0x06ff2d58, 0x9bf0cc2e, 0xabd644b4, 0x36d9a5c2, - 0x4ab88019, 0xd7b7616f, 0xb27acbaf, 0x2f752ad9, 0x53140f02, - 0xce1bee74, 0x988f5a82, 0x0580bbf4, 0x79e19e2f, 0xe4ee7f59, - 0x8123d599, 0x1c2c34ef, 0x604d1134, 0xfd42f042, 0x41b9f7f1, - 0xdcb61687, 0xa0d7335c, 0x3dd8d22a, 0x581578ea, 0xc51a999c, - 0xb97bbc47, 0x24745d31, 0x72e0e9c7, 0xefef08b1, 0x938e2d6a, - 0x0e81cc1c, 0x6b4c66dc, 0xf64387aa, 0x8a22a271, 0x172d4307, - 0x270bcb9d, 0xba042aeb, 0xc6650f30, 0x5b6aee46, 0x3ea74486, - 0xa3a8a5f0, 0xdfc9802b, 0x42c6615d, 0x1452d5ab, 0x895d34dd, - 0xf53c1106, 0x6833f070, 0x0dfe5ab0, 0x90f1bbc6, 0xec909e1d, - 0x719f7f6b, 0x8cdd8f29, 0x11d26e5f, 0x6db34b84, 0xf0bcaaf2, - 0x95710032, 0x087ee144, 0x741fc49f, 0xe91025e9, 0xbf84911f, - 0x228b7069, 0x5eea55b2, 0xc3e5b4c4, 0xa6281e04, 0x3b27ff72, - 0x4746daa9, 0xda493bdf, 0xea6fb345, 0x77605233, 0x0b0177e8, - 0x960e969e, 0xf3c33c5e, 0x6eccdd28, 0x12adf8f3, 0x8fa21985, - 0xd936ad73, 0x44394c05, 0x385869de, 0xa55788a8, 0xc09a2268, - 0x5d95c31e, 0x21f4e6c5, 0xbcfb07b3, 0x8373efe2, 0x1e7c0e94, - 0x621d2b4f, 0xff12ca39, 0x9adf60f9, 0x07d0818f, 0x7bb1a454, - 0xe6be4522, 0xb02af1d4, 0x2d2510a2, 0x51443579, 0xcc4bd40f, - 0xa9867ecf, 0x34899fb9, 0x48e8ba62, 0xd5e75b14, 0xe5c1d38e, - 0x78ce32f8, 0x04af1723, 0x99a0f655, 0xfc6d5c95, 0x6162bde3, - 0x1d039838, 0x800c794e, 0xd698cdb8, 0x4b972cce, 0x37f60915, - 0xaaf9e863, 0xcf3442a3, 0x523ba3d5, 0x2e5a860e, 0xb3556778, - 0x4e17973a, 0xd318764c, 0xaf795397, 0x3276b2e1, 0x57bb1821, - 0xcab4f957, 0xb6d5dc8c, 0x2bda3dfa, 0x7d4e890c, 0xe041687a, - 0x9c204da1, 0x012facd7, 0x64e20617, 0xf9ede761, 0x858cc2ba, - 0x188323cc, 0x28a5ab56, 0xb5aa4a20, 0xc9cb6ffb, 0x54c48e8d, - 0x3109244d, 0xac06c53b, 0xd067e0e0, 0x4d680196, 0x1bfcb560, - 0x86f35416, 0xfa9271cd, 0x679d90bb, 0x02503a7b, 0x9f5fdb0d, - 0xe33efed6, 0x7e311fa0, 0xc2ca1813, 0x5fc5f965, 0x23a4dcbe, - 0xbeab3dc8, 0xdb669708, 0x4669767e, 0x3a0853a5, 0xa707b2d3, - 0xf1930625, 0x6c9ce753, 0x10fdc288, 0x8df223fe, 0xe83f893e, - 0x75306848, 0x09514d93, 0x945eace5, 0xa478247f, 0x3977c509, - 0x4516e0d2, 0xd81901a4, 0xbdd4ab64, 0x20db4a12, 0x5cba6fc9, - 0xc1b58ebf, 0x97213a49, 0x0a2edb3f, 0x764ffee4, 0xeb401f92, - 0x8e8db552, 0x13825424, 0x6fe371ff, 0xf2ec9089, 0x0fae60cb, - 0x92a181bd, 0xeec0a466, 0x73cf4510, 0x1602efd0, 0x8b0d0ea6, - 0xf76c2b7d, 0x6a63ca0b, 0x3cf77efd, 0xa1f89f8b, 0xdd99ba50, - 0x40965b26, 0x255bf1e6, 0xb8541090, 0xc435354b, 0x593ad43d, - 0x691c5ca7, 0xf413bdd1, 0x8872980a, 0x157d797c, 0x70b0d3bc, - 0xedbf32ca, 0x91de1711, 0x0cd1f667, 0x5a454291, 0xc74aa3e7, - 0xbb2b863c, 0x2624674a, 0x43e9cd8a, 0xdee62cfc, 0xa2870927, - 0x3f88e851}, - {0x00000000, 0xdd96d985, 0x605cb54b, 0xbdca6cce, 0xc0b96a96, - 0x1d2fb313, 0xa0e5dfdd, 0x7d730658, 0x5a03d36d, 0x87950ae8, - 0x3a5f6626, 0xe7c9bfa3, 0x9abab9fb, 0x472c607e, 0xfae60cb0, - 0x2770d535, 0xb407a6da, 0x69917f5f, 0xd45b1391, 0x09cdca14, - 0x74becc4c, 0xa92815c9, 0x14e27907, 0xc974a082, 0xee0475b7, - 0x3392ac32, 0x8e58c0fc, 0x53ce1979, 0x2ebd1f21, 0xf32bc6a4, - 0x4ee1aa6a, 0x937773ef, 0xb37e4bf5, 0x6ee89270, 0xd322febe, - 0x0eb4273b, 0x73c72163, 0xae51f8e6, 0x139b9428, 0xce0d4dad, - 0xe97d9898, 0x34eb411d, 0x89212dd3, 0x54b7f456, 0x29c4f20e, - 0xf4522b8b, 0x49984745, 0x940e9ec0, 0x0779ed2f, 0xdaef34aa, - 0x67255864, 0xbab381e1, 0xc7c087b9, 0x1a565e3c, 0xa79c32f2, - 0x7a0aeb77, 0x5d7a3e42, 0x80ece7c7, 0x3d268b09, 0xe0b0528c, - 0x9dc354d4, 0x40558d51, 0xfd9fe19f, 0x2009381a, 0xbd8d91ab, - 0x601b482e, 0xddd124e0, 0x0047fd65, 0x7d34fb3d, 0xa0a222b8, - 0x1d684e76, 0xc0fe97f3, 0xe78e42c6, 0x3a189b43, 0x87d2f78d, - 0x5a442e08, 0x27372850, 0xfaa1f1d5, 0x476b9d1b, 0x9afd449e, - 0x098a3771, 0xd41ceef4, 0x69d6823a, 0xb4405bbf, 0xc9335de7, - 0x14a58462, 0xa96fe8ac, 0x74f93129, 0x5389e41c, 0x8e1f3d99, - 0x33d55157, 0xee4388d2, 0x93308e8a, 0x4ea6570f, 0xf36c3bc1, - 0x2efae244, 0x0ef3da5e, 0xd36503db, 0x6eaf6f15, 0xb339b690, - 0xce4ab0c8, 0x13dc694d, 0xae160583, 0x7380dc06, 0x54f00933, - 0x8966d0b6, 0x34acbc78, 0xe93a65fd, 0x944963a5, 0x49dfba20, - 0xf415d6ee, 0x29830f6b, 0xbaf47c84, 0x6762a501, 0xdaa8c9cf, - 0x073e104a, 0x7a4d1612, 0xa7dbcf97, 0x1a11a359, 0xc7877adc, - 0xe0f7afe9, 0x3d61766c, 0x80ab1aa2, 0x5d3dc327, 0x204ec57f, - 0xfdd81cfa, 0x40127034, 0x9d84a9b1, 0xa06a2517, 0x7dfcfc92, - 0xc036905c, 0x1da049d9, 0x60d34f81, 0xbd459604, 0x008ffaca, - 0xdd19234f, 0xfa69f67a, 0x27ff2fff, 0x9a354331, 0x47a39ab4, - 0x3ad09cec, 0xe7464569, 0x5a8c29a7, 0x871af022, 0x146d83cd, - 0xc9fb5a48, 0x74313686, 0xa9a7ef03, 0xd4d4e95b, 0x094230de, - 0xb4885c10, 0x691e8595, 0x4e6e50a0, 0x93f88925, 0x2e32e5eb, - 0xf3a43c6e, 0x8ed73a36, 0x5341e3b3, 0xee8b8f7d, 0x331d56f8, - 0x13146ee2, 0xce82b767, 0x7348dba9, 0xaede022c, 0xd3ad0474, - 0x0e3bddf1, 0xb3f1b13f, 0x6e6768ba, 0x4917bd8f, 0x9481640a, - 0x294b08c4, 0xf4ddd141, 0x89aed719, 0x54380e9c, 0xe9f26252, - 0x3464bbd7, 0xa713c838, 0x7a8511bd, 0xc74f7d73, 0x1ad9a4f6, - 0x67aaa2ae, 0xba3c7b2b, 0x07f617e5, 0xda60ce60, 0xfd101b55, - 0x2086c2d0, 0x9d4cae1e, 0x40da779b, 0x3da971c3, 0xe03fa846, - 0x5df5c488, 0x80631d0d, 0x1de7b4bc, 0xc0716d39, 0x7dbb01f7, - 0xa02dd872, 0xdd5ede2a, 0x00c807af, 0xbd026b61, 0x6094b2e4, - 0x47e467d1, 0x9a72be54, 0x27b8d29a, 0xfa2e0b1f, 0x875d0d47, - 0x5acbd4c2, 0xe701b80c, 0x3a976189, 0xa9e01266, 0x7476cbe3, - 0xc9bca72d, 0x142a7ea8, 0x695978f0, 0xb4cfa175, 0x0905cdbb, - 0xd493143e, 0xf3e3c10b, 0x2e75188e, 0x93bf7440, 0x4e29adc5, - 0x335aab9d, 0xeecc7218, 0x53061ed6, 0x8e90c753, 0xae99ff49, - 0x730f26cc, 0xcec54a02, 0x13539387, 0x6e2095df, 0xb3b64c5a, - 0x0e7c2094, 0xd3eaf911, 0xf49a2c24, 0x290cf5a1, 0x94c6996f, - 0x495040ea, 0x342346b2, 0xe9b59f37, 0x547ff3f9, 0x89e92a7c, - 0x1a9e5993, 0xc7088016, 0x7ac2ecd8, 0xa754355d, 0xda273305, - 0x07b1ea80, 0xba7b864e, 0x67ed5fcb, 0x409d8afe, 0x9d0b537b, - 0x20c13fb5, 0xfd57e630, 0x8024e068, 0x5db239ed, 0xe0785523, - 0x3dee8ca6}, - {0x00000000, 0x9ba54c6f, 0xec3b9e9f, 0x779ed2f0, 0x03063b7f, - 0x98a37710, 0xef3da5e0, 0x7498e98f, 0x060c76fe, 0x9da93a91, - 0xea37e861, 0x7192a40e, 0x050a4d81, 0x9eaf01ee, 0xe931d31e, - 0x72949f71, 0x0c18edfc, 0x97bda193, 0xe0237363, 0x7b863f0c, - 0x0f1ed683, 0x94bb9aec, 0xe325481c, 0x78800473, 0x0a149b02, - 0x91b1d76d, 0xe62f059d, 0x7d8a49f2, 0x0912a07d, 0x92b7ec12, - 0xe5293ee2, 0x7e8c728d, 0x1831dbf8, 0x83949797, 0xf40a4567, - 0x6faf0908, 0x1b37e087, 0x8092ace8, 0xf70c7e18, 0x6ca93277, - 0x1e3dad06, 0x8598e169, 0xf2063399, 0x69a37ff6, 0x1d3b9679, - 0x869eda16, 0xf10008e6, 0x6aa54489, 0x14293604, 0x8f8c7a6b, - 0xf812a89b, 0x63b7e4f4, 0x172f0d7b, 0x8c8a4114, 0xfb1493e4, - 0x60b1df8b, 0x122540fa, 0x89800c95, 0xfe1ede65, 0x65bb920a, - 0x11237b85, 0x8a8637ea, 0xfd18e51a, 0x66bda975, 0x3063b7f0, - 0xabc6fb9f, 0xdc58296f, 0x47fd6500, 0x33658c8f, 0xa8c0c0e0, - 0xdf5e1210, 0x44fb5e7f, 0x366fc10e, 0xadca8d61, 0xda545f91, - 0x41f113fe, 0x3569fa71, 0xaeccb61e, 0xd95264ee, 0x42f72881, - 0x3c7b5a0c, 0xa7de1663, 0xd040c493, 0x4be588fc, 0x3f7d6173, - 0xa4d82d1c, 0xd346ffec, 0x48e3b383, 0x3a772cf2, 0xa1d2609d, - 0xd64cb26d, 0x4de9fe02, 0x3971178d, 0xa2d45be2, 0xd54a8912, - 0x4eefc57d, 0x28526c08, 0xb3f72067, 0xc469f297, 0x5fccbef8, - 0x2b545777, 0xb0f11b18, 0xc76fc9e8, 0x5cca8587, 0x2e5e1af6, - 0xb5fb5699, 0xc2658469, 0x59c0c806, 0x2d582189, 0xb6fd6de6, - 0xc163bf16, 0x5ac6f379, 0x244a81f4, 0xbfefcd9b, 0xc8711f6b, - 0x53d45304, 0x274cba8b, 0xbce9f6e4, 0xcb772414, 0x50d2687b, - 0x2246f70a, 0xb9e3bb65, 0xce7d6995, 0x55d825fa, 0x2140cc75, - 0xbae5801a, 0xcd7b52ea, 0x56de1e85, 0x60c76fe0, 0xfb62238f, - 0x8cfcf17f, 0x1759bd10, 0x63c1549f, 0xf86418f0, 0x8ffaca00, - 0x145f866f, 0x66cb191e, 0xfd6e5571, 0x8af08781, 0x1155cbee, - 0x65cd2261, 0xfe686e0e, 0x89f6bcfe, 0x1253f091, 0x6cdf821c, - 0xf77ace73, 0x80e41c83, 0x1b4150ec, 0x6fd9b963, 0xf47cf50c, - 0x83e227fc, 0x18476b93, 0x6ad3f4e2, 0xf176b88d, 0x86e86a7d, - 0x1d4d2612, 0x69d5cf9d, 0xf27083f2, 0x85ee5102, 0x1e4b1d6d, - 0x78f6b418, 0xe353f877, 0x94cd2a87, 0x0f6866e8, 0x7bf08f67, - 0xe055c308, 0x97cb11f8, 0x0c6e5d97, 0x7efac2e6, 0xe55f8e89, - 0x92c15c79, 0x09641016, 0x7dfcf999, 0xe659b5f6, 0x91c76706, - 0x0a622b69, 0x74ee59e4, 0xef4b158b, 0x98d5c77b, 0x03708b14, - 0x77e8629b, 0xec4d2ef4, 0x9bd3fc04, 0x0076b06b, 0x72e22f1a, - 0xe9476375, 0x9ed9b185, 0x057cfdea, 0x71e41465, 0xea41580a, - 0x9ddf8afa, 0x067ac695, 0x50a4d810, 0xcb01947f, 0xbc9f468f, - 0x273a0ae0, 0x53a2e36f, 0xc807af00, 0xbf997df0, 0x243c319f, - 0x56a8aeee, 0xcd0de281, 0xba933071, 0x21367c1e, 0x55ae9591, - 0xce0bd9fe, 0xb9950b0e, 0x22304761, 0x5cbc35ec, 0xc7197983, - 0xb087ab73, 0x2b22e71c, 0x5fba0e93, 0xc41f42fc, 0xb381900c, - 0x2824dc63, 0x5ab04312, 0xc1150f7d, 0xb68bdd8d, 0x2d2e91e2, - 0x59b6786d, 0xc2133402, 0xb58de6f2, 0x2e28aa9d, 0x489503e8, - 0xd3304f87, 0xa4ae9d77, 0x3f0bd118, 0x4b933897, 0xd03674f8, - 0xa7a8a608, 0x3c0dea67, 0x4e997516, 0xd53c3979, 0xa2a2eb89, - 0x3907a7e6, 0x4d9f4e69, 0xd63a0206, 0xa1a4d0f6, 0x3a019c99, - 0x448dee14, 0xdf28a27b, 0xa8b6708b, 0x33133ce4, 0x478bd56b, - 0xdc2e9904, 0xabb04bf4, 0x3015079b, 0x428198ea, 0xd924d485, - 0xaeba0675, 0x351f4a1a, 0x4187a395, 0xda22effa, 0xadbc3d0a, - 0x36197165}, - {0x00000000, 0xc18edfc0, 0x586cb9c1, 0x99e26601, 0xb0d97382, - 0x7157ac42, 0xe8b5ca43, 0x293b1583, 0xbac3e145, 0x7b4d3e85, - 0xe2af5884, 0x23218744, 0x0a1a92c7, 0xcb944d07, 0x52762b06, - 0x93f8f4c6, 0xaef6c4cb, 0x6f781b0b, 0xf69a7d0a, 0x3714a2ca, - 0x1e2fb749, 0xdfa16889, 0x46430e88, 0x87cdd148, 0x1435258e, - 0xd5bbfa4e, 0x4c599c4f, 0x8dd7438f, 0xa4ec560c, 0x656289cc, - 0xfc80efcd, 0x3d0e300d, 0x869c8fd7, 0x47125017, 0xdef03616, - 0x1f7ee9d6, 0x3645fc55, 0xf7cb2395, 0x6e294594, 0xafa79a54, - 0x3c5f6e92, 0xfdd1b152, 0x6433d753, 0xa5bd0893, 0x8c861d10, - 0x4d08c2d0, 0xd4eaa4d1, 0x15647b11, 0x286a4b1c, 0xe9e494dc, - 0x7006f2dd, 0xb1882d1d, 0x98b3389e, 0x593de75e, 0xc0df815f, - 0x01515e9f, 0x92a9aa59, 0x53277599, 0xcac51398, 0x0b4bcc58, - 0x2270d9db, 0xe3fe061b, 0x7a1c601a, 0xbb92bfda, 0xd64819ef, - 0x17c6c62f, 0x8e24a02e, 0x4faa7fee, 0x66916a6d, 0xa71fb5ad, - 0x3efdd3ac, 0xff730c6c, 0x6c8bf8aa, 0xad05276a, 0x34e7416b, - 0xf5699eab, 0xdc528b28, 0x1ddc54e8, 0x843e32e9, 0x45b0ed29, - 0x78bedd24, 0xb93002e4, 0x20d264e5, 0xe15cbb25, 0xc867aea6, - 0x09e97166, 0x900b1767, 0x5185c8a7, 0xc27d3c61, 0x03f3e3a1, - 0x9a1185a0, 0x5b9f5a60, 0x72a44fe3, 0xb32a9023, 0x2ac8f622, - 0xeb4629e2, 0x50d49638, 0x915a49f8, 0x08b82ff9, 0xc936f039, - 0xe00de5ba, 0x21833a7a, 0xb8615c7b, 0x79ef83bb, 0xea17777d, - 0x2b99a8bd, 0xb27bcebc, 0x73f5117c, 0x5ace04ff, 0x9b40db3f, - 0x02a2bd3e, 0xc32c62fe, 0xfe2252f3, 0x3fac8d33, 0xa64eeb32, - 0x67c034f2, 0x4efb2171, 0x8f75feb1, 0x169798b0, 0xd7194770, - 0x44e1b3b6, 0x856f6c76, 0x1c8d0a77, 0xdd03d5b7, 0xf438c034, - 0x35b61ff4, 0xac5479f5, 0x6ddaa635, 0x77e1359f, 0xb66fea5f, - 0x2f8d8c5e, 0xee03539e, 0xc738461d, 0x06b699dd, 0x9f54ffdc, - 0x5eda201c, 0xcd22d4da, 0x0cac0b1a, 0x954e6d1b, 0x54c0b2db, - 0x7dfba758, 0xbc757898, 0x25971e99, 0xe419c159, 0xd917f154, - 0x18992e94, 0x817b4895, 0x40f59755, 0x69ce82d6, 0xa8405d16, - 0x31a23b17, 0xf02ce4d7, 0x63d41011, 0xa25acfd1, 0x3bb8a9d0, - 0xfa367610, 0xd30d6393, 0x1283bc53, 0x8b61da52, 0x4aef0592, - 0xf17dba48, 0x30f36588, 0xa9110389, 0x689fdc49, 0x41a4c9ca, - 0x802a160a, 0x19c8700b, 0xd846afcb, 0x4bbe5b0d, 0x8a3084cd, - 0x13d2e2cc, 0xd25c3d0c, 0xfb67288f, 0x3ae9f74f, 0xa30b914e, - 0x62854e8e, 0x5f8b7e83, 0x9e05a143, 0x07e7c742, 0xc6691882, - 0xef520d01, 0x2edcd2c1, 0xb73eb4c0, 0x76b06b00, 0xe5489fc6, - 0x24c64006, 0xbd242607, 0x7caaf9c7, 0x5591ec44, 0x941f3384, - 0x0dfd5585, 0xcc738a45, 0xa1a92c70, 0x6027f3b0, 0xf9c595b1, - 0x384b4a71, 0x11705ff2, 0xd0fe8032, 0x491ce633, 0x889239f3, - 0x1b6acd35, 0xdae412f5, 0x430674f4, 0x8288ab34, 0xabb3beb7, - 0x6a3d6177, 0xf3df0776, 0x3251d8b6, 0x0f5fe8bb, 0xced1377b, - 0x5733517a, 0x96bd8eba, 0xbf869b39, 0x7e0844f9, 0xe7ea22f8, - 0x2664fd38, 0xb59c09fe, 0x7412d63e, 0xedf0b03f, 0x2c7e6fff, - 0x05457a7c, 0xc4cba5bc, 0x5d29c3bd, 0x9ca71c7d, 0x2735a3a7, - 0xe6bb7c67, 0x7f591a66, 0xbed7c5a6, 0x97ecd025, 0x56620fe5, - 0xcf8069e4, 0x0e0eb624, 0x9df642e2, 0x5c789d22, 0xc59afb23, - 0x041424e3, 0x2d2f3160, 0xeca1eea0, 0x754388a1, 0xb4cd5761, - 0x89c3676c, 0x484db8ac, 0xd1afdead, 0x1021016d, 0x391a14ee, - 0xf894cb2e, 0x6176ad2f, 0xa0f872ef, 0x33008629, 0xf28e59e9, - 0x6b6c3fe8, 0xaae2e028, 0x83d9f5ab, 0x42572a6b, 0xdbb54c6a, - 0x1a3b93aa}, - {0x00000000, 0xefc26b3e, 0x04f5d03d, 0xeb37bb03, 0x09eba07a, - 0xe629cb44, 0x0d1e7047, 0xe2dc1b79, 0x13d740f4, 0xfc152bca, - 0x172290c9, 0xf8e0fbf7, 0x1a3ce08e, 0xf5fe8bb0, 0x1ec930b3, - 0xf10b5b8d, 0x27ae81e8, 0xc86cead6, 0x235b51d5, 0xcc993aeb, - 0x2e452192, 0xc1874aac, 0x2ab0f1af, 0xc5729a91, 0x3479c11c, - 0xdbbbaa22, 0x308c1121, 0xdf4e7a1f, 0x3d926166, 0xd2500a58, - 0x3967b15b, 0xd6a5da65, 0x4f5d03d0, 0xa09f68ee, 0x4ba8d3ed, - 0xa46ab8d3, 0x46b6a3aa, 0xa974c894, 0x42437397, 0xad8118a9, - 0x5c8a4324, 0xb348281a, 0x587f9319, 0xb7bdf827, 0x5561e35e, - 0xbaa38860, 0x51943363, 0xbe56585d, 0x68f38238, 0x8731e906, - 0x6c065205, 0x83c4393b, 0x61182242, 0x8eda497c, 0x65edf27f, - 0x8a2f9941, 0x7b24c2cc, 0x94e6a9f2, 0x7fd112f1, 0x901379cf, - 0x72cf62b6, 0x9d0d0988, 0x763ab28b, 0x99f8d9b5, 0x9eba07a0, - 0x71786c9e, 0x9a4fd79d, 0x758dbca3, 0x9751a7da, 0x7893cce4, - 0x93a477e7, 0x7c661cd9, 0x8d6d4754, 0x62af2c6a, 0x89989769, - 0x665afc57, 0x8486e72e, 0x6b448c10, 0x80733713, 0x6fb15c2d, - 0xb9148648, 0x56d6ed76, 0xbde15675, 0x52233d4b, 0xb0ff2632, - 0x5f3d4d0c, 0xb40af60f, 0x5bc89d31, 0xaac3c6bc, 0x4501ad82, - 0xae361681, 0x41f47dbf, 0xa32866c6, 0x4cea0df8, 0xa7ddb6fb, - 0x481fddc5, 0xd1e70470, 0x3e256f4e, 0xd512d44d, 0x3ad0bf73, - 0xd80ca40a, 0x37cecf34, 0xdcf97437, 0x333b1f09, 0xc2304484, - 0x2df22fba, 0xc6c594b9, 0x2907ff87, 0xcbdbe4fe, 0x24198fc0, - 0xcf2e34c3, 0x20ec5ffd, 0xf6498598, 0x198beea6, 0xf2bc55a5, - 0x1d7e3e9b, 0xffa225e2, 0x10604edc, 0xfb57f5df, 0x14959ee1, - 0xe59ec56c, 0x0a5cae52, 0xe16b1551, 0x0ea97e6f, 0xec756516, - 0x03b70e28, 0xe880b52b, 0x0742de15, 0xe6050901, 0x09c7623f, - 0xe2f0d93c, 0x0d32b202, 0xefeea97b, 0x002cc245, 0xeb1b7946, - 0x04d91278, 0xf5d249f5, 0x1a1022cb, 0xf12799c8, 0x1ee5f2f6, - 0xfc39e98f, 0x13fb82b1, 0xf8cc39b2, 0x170e528c, 0xc1ab88e9, - 0x2e69e3d7, 0xc55e58d4, 0x2a9c33ea, 0xc8402893, 0x278243ad, - 0xccb5f8ae, 0x23779390, 0xd27cc81d, 0x3dbea323, 0xd6891820, - 0x394b731e, 0xdb976867, 0x34550359, 0xdf62b85a, 0x30a0d364, - 0xa9580ad1, 0x469a61ef, 0xadaddaec, 0x426fb1d2, 0xa0b3aaab, - 0x4f71c195, 0xa4467a96, 0x4b8411a8, 0xba8f4a25, 0x554d211b, - 0xbe7a9a18, 0x51b8f126, 0xb364ea5f, 0x5ca68161, 0xb7913a62, - 0x5853515c, 0x8ef68b39, 0x6134e007, 0x8a035b04, 0x65c1303a, - 0x871d2b43, 0x68df407d, 0x83e8fb7e, 0x6c2a9040, 0x9d21cbcd, - 0x72e3a0f3, 0x99d41bf0, 0x761670ce, 0x94ca6bb7, 0x7b080089, - 0x903fbb8a, 0x7ffdd0b4, 0x78bf0ea1, 0x977d659f, 0x7c4ade9c, - 0x9388b5a2, 0x7154aedb, 0x9e96c5e5, 0x75a17ee6, 0x9a6315d8, - 0x6b684e55, 0x84aa256b, 0x6f9d9e68, 0x805ff556, 0x6283ee2f, - 0x8d418511, 0x66763e12, 0x89b4552c, 0x5f118f49, 0xb0d3e477, - 0x5be45f74, 0xb426344a, 0x56fa2f33, 0xb938440d, 0x520fff0e, - 0xbdcd9430, 0x4cc6cfbd, 0xa304a483, 0x48331f80, 0xa7f174be, - 0x452d6fc7, 0xaaef04f9, 0x41d8bffa, 0xae1ad4c4, 0x37e20d71, - 0xd820664f, 0x3317dd4c, 0xdcd5b672, 0x3e09ad0b, 0xd1cbc635, - 0x3afc7d36, 0xd53e1608, 0x24354d85, 0xcbf726bb, 0x20c09db8, - 0xcf02f686, 0x2ddeedff, 0xc21c86c1, 0x292b3dc2, 0xc6e956fc, - 0x104c8c99, 0xff8ee7a7, 0x14b95ca4, 0xfb7b379a, 0x19a72ce3, - 0xf66547dd, 0x1d52fcde, 0xf29097e0, 0x039bcc6d, 0xec59a753, - 0x076e1c50, 0xe8ac776e, 0x0a706c17, 0xe5b20729, 0x0e85bc2a, - 0xe147d714}, - {0x00000000, 0x177b1443, 0x2ef62886, 0x398d3cc5, 0x5dec510c, - 0x4a97454f, 0x731a798a, 0x64616dc9, 0xbbd8a218, 0xaca3b65b, - 0x952e8a9e, 0x82559edd, 0xe634f314, 0xf14fe757, 0xc8c2db92, - 0xdfb9cfd1, 0xacc04271, 0xbbbb5632, 0x82366af7, 0x954d7eb4, - 0xf12c137d, 0xe657073e, 0xdfda3bfb, 0xc8a12fb8, 0x1718e069, - 0x0063f42a, 0x39eec8ef, 0x2e95dcac, 0x4af4b165, 0x5d8fa526, - 0x640299e3, 0x73798da0, 0x82f182a3, 0x958a96e0, 0xac07aa25, - 0xbb7cbe66, 0xdf1dd3af, 0xc866c7ec, 0xf1ebfb29, 0xe690ef6a, - 0x392920bb, 0x2e5234f8, 0x17df083d, 0x00a41c7e, 0x64c571b7, - 0x73be65f4, 0x4a335931, 0x5d484d72, 0x2e31c0d2, 0x394ad491, - 0x00c7e854, 0x17bcfc17, 0x73dd91de, 0x64a6859d, 0x5d2bb958, - 0x4a50ad1b, 0x95e962ca, 0x82927689, 0xbb1f4a4c, 0xac645e0f, - 0xc80533c6, 0xdf7e2785, 0xe6f31b40, 0xf1880f03, 0xde920307, - 0xc9e91744, 0xf0642b81, 0xe71f3fc2, 0x837e520b, 0x94054648, - 0xad887a8d, 0xbaf36ece, 0x654aa11f, 0x7231b55c, 0x4bbc8999, - 0x5cc79dda, 0x38a6f013, 0x2fdde450, 0x1650d895, 0x012bccd6, - 0x72524176, 0x65295535, 0x5ca469f0, 0x4bdf7db3, 0x2fbe107a, - 0x38c50439, 0x014838fc, 0x16332cbf, 0xc98ae36e, 0xdef1f72d, - 0xe77ccbe8, 0xf007dfab, 0x9466b262, 0x831da621, 0xba909ae4, - 0xadeb8ea7, 0x5c6381a4, 0x4b1895e7, 0x7295a922, 0x65eebd61, - 0x018fd0a8, 0x16f4c4eb, 0x2f79f82e, 0x3802ec6d, 0xe7bb23bc, - 0xf0c037ff, 0xc94d0b3a, 0xde361f79, 0xba5772b0, 0xad2c66f3, - 0x94a15a36, 0x83da4e75, 0xf0a3c3d5, 0xe7d8d796, 0xde55eb53, - 0xc92eff10, 0xad4f92d9, 0xba34869a, 0x83b9ba5f, 0x94c2ae1c, - 0x4b7b61cd, 0x5c00758e, 0x658d494b, 0x72f65d08, 0x169730c1, - 0x01ec2482, 0x38611847, 0x2f1a0c04, 0x6655004f, 0x712e140c, - 0x48a328c9, 0x5fd83c8a, 0x3bb95143, 0x2cc24500, 0x154f79c5, - 0x02346d86, 0xdd8da257, 0xcaf6b614, 0xf37b8ad1, 0xe4009e92, - 0x8061f35b, 0x971ae718, 0xae97dbdd, 0xb9eccf9e, 0xca95423e, - 0xddee567d, 0xe4636ab8, 0xf3187efb, 0x97791332, 0x80020771, - 0xb98f3bb4, 0xaef42ff7, 0x714de026, 0x6636f465, 0x5fbbc8a0, - 0x48c0dce3, 0x2ca1b12a, 0x3bdaa569, 0x025799ac, 0x152c8def, - 0xe4a482ec, 0xf3df96af, 0xca52aa6a, 0xdd29be29, 0xb948d3e0, - 0xae33c7a3, 0x97befb66, 0x80c5ef25, 0x5f7c20f4, 0x480734b7, - 0x718a0872, 0x66f11c31, 0x029071f8, 0x15eb65bb, 0x2c66597e, - 0x3b1d4d3d, 0x4864c09d, 0x5f1fd4de, 0x6692e81b, 0x71e9fc58, - 0x15889191, 0x02f385d2, 0x3b7eb917, 0x2c05ad54, 0xf3bc6285, - 0xe4c776c6, 0xdd4a4a03, 0xca315e40, 0xae503389, 0xb92b27ca, - 0x80a61b0f, 0x97dd0f4c, 0xb8c70348, 0xafbc170b, 0x96312bce, - 0x814a3f8d, 0xe52b5244, 0xf2504607, 0xcbdd7ac2, 0xdca66e81, - 0x031fa150, 0x1464b513, 0x2de989d6, 0x3a929d95, 0x5ef3f05c, - 0x4988e41f, 0x7005d8da, 0x677ecc99, 0x14074139, 0x037c557a, - 0x3af169bf, 0x2d8a7dfc, 0x49eb1035, 0x5e900476, 0x671d38b3, - 0x70662cf0, 0xafdfe321, 0xb8a4f762, 0x8129cba7, 0x9652dfe4, - 0xf233b22d, 0xe548a66e, 0xdcc59aab, 0xcbbe8ee8, 0x3a3681eb, - 0x2d4d95a8, 0x14c0a96d, 0x03bbbd2e, 0x67dad0e7, 0x70a1c4a4, - 0x492cf861, 0x5e57ec22, 0x81ee23f3, 0x969537b0, 0xaf180b75, - 0xb8631f36, 0xdc0272ff, 0xcb7966bc, 0xf2f45a79, 0xe58f4e3a, - 0x96f6c39a, 0x818dd7d9, 0xb800eb1c, 0xaf7bff5f, 0xcb1a9296, - 0xdc6186d5, 0xe5ecba10, 0xf297ae53, 0x2d2e6182, 0x3a5575c1, - 0x03d84904, 0x14a35d47, 0x70c2308e, 0x67b924cd, 0x5e341808, - 0x494f0c4b}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x0000000000000000, 0x43147b1700000000, 0x8628f62e00000000, - 0xc53c8d3900000000, 0x0c51ec5d00000000, 0x4f45974a00000000, - 0x8a791a7300000000, 0xc96d616400000000, 0x18a2d8bb00000000, - 0x5bb6a3ac00000000, 0x9e8a2e9500000000, 0xdd9e558200000000, - 0x14f334e600000000, 0x57e74ff100000000, 0x92dbc2c800000000, - 0xd1cfb9df00000000, 0x7142c0ac00000000, 0x3256bbbb00000000, - 0xf76a368200000000, 0xb47e4d9500000000, 0x7d132cf100000000, - 0x3e0757e600000000, 0xfb3bdadf00000000, 0xb82fa1c800000000, - 0x69e0181700000000, 0x2af4630000000000, 0xefc8ee3900000000, - 0xacdc952e00000000, 0x65b1f44a00000000, 0x26a58f5d00000000, - 0xe399026400000000, 0xa08d797300000000, 0xa382f18200000000, - 0xe0968a9500000000, 0x25aa07ac00000000, 0x66be7cbb00000000, - 0xafd31ddf00000000, 0xecc766c800000000, 0x29fbebf100000000, - 0x6aef90e600000000, 0xbb20293900000000, 0xf834522e00000000, - 0x3d08df1700000000, 0x7e1ca40000000000, 0xb771c56400000000, - 0xf465be7300000000, 0x3159334a00000000, 0x724d485d00000000, - 0xd2c0312e00000000, 0x91d44a3900000000, 0x54e8c70000000000, - 0x17fcbc1700000000, 0xde91dd7300000000, 0x9d85a66400000000, - 0x58b92b5d00000000, 0x1bad504a00000000, 0xca62e99500000000, - 0x8976928200000000, 0x4c4a1fbb00000000, 0x0f5e64ac00000000, - 0xc63305c800000000, 0x85277edf00000000, 0x401bf3e600000000, - 0x030f88f100000000, 0x070392de00000000, 0x4417e9c900000000, - 0x812b64f000000000, 0xc23f1fe700000000, 0x0b527e8300000000, - 0x4846059400000000, 0x8d7a88ad00000000, 0xce6ef3ba00000000, - 0x1fa14a6500000000, 0x5cb5317200000000, 0x9989bc4b00000000, - 0xda9dc75c00000000, 0x13f0a63800000000, 0x50e4dd2f00000000, - 0x95d8501600000000, 0xd6cc2b0100000000, 0x7641527200000000, - 0x3555296500000000, 0xf069a45c00000000, 0xb37ddf4b00000000, - 0x7a10be2f00000000, 0x3904c53800000000, 0xfc38480100000000, - 0xbf2c331600000000, 0x6ee38ac900000000, 0x2df7f1de00000000, - 0xe8cb7ce700000000, 0xabdf07f000000000, 0x62b2669400000000, - 0x21a61d8300000000, 0xe49a90ba00000000, 0xa78eebad00000000, - 0xa481635c00000000, 0xe795184b00000000, 0x22a9957200000000, - 0x61bdee6500000000, 0xa8d08f0100000000, 0xebc4f41600000000, - 0x2ef8792f00000000, 0x6dec023800000000, 0xbc23bbe700000000, - 0xff37c0f000000000, 0x3a0b4dc900000000, 0x791f36de00000000, - 0xb07257ba00000000, 0xf3662cad00000000, 0x365aa19400000000, - 0x754eda8300000000, 0xd5c3a3f000000000, 0x96d7d8e700000000, - 0x53eb55de00000000, 0x10ff2ec900000000, 0xd9924fad00000000, - 0x9a8634ba00000000, 0x5fbab98300000000, 0x1caec29400000000, - 0xcd617b4b00000000, 0x8e75005c00000000, 0x4b498d6500000000, - 0x085df67200000000, 0xc130971600000000, 0x8224ec0100000000, - 0x4718613800000000, 0x040c1a2f00000000, 0x4f00556600000000, - 0x0c142e7100000000, 0xc928a34800000000, 0x8a3cd85f00000000, - 0x4351b93b00000000, 0x0045c22c00000000, 0xc5794f1500000000, - 0x866d340200000000, 0x57a28ddd00000000, 0x14b6f6ca00000000, - 0xd18a7bf300000000, 0x929e00e400000000, 0x5bf3618000000000, - 0x18e71a9700000000, 0xdddb97ae00000000, 0x9ecfecb900000000, - 0x3e4295ca00000000, 0x7d56eedd00000000, 0xb86a63e400000000, - 0xfb7e18f300000000, 0x3213799700000000, 0x7107028000000000, - 0xb43b8fb900000000, 0xf72ff4ae00000000, 0x26e04d7100000000, - 0x65f4366600000000, 0xa0c8bb5f00000000, 0xe3dcc04800000000, - 0x2ab1a12c00000000, 0x69a5da3b00000000, 0xac99570200000000, - 0xef8d2c1500000000, 0xec82a4e400000000, 0xaf96dff300000000, - 0x6aaa52ca00000000, 0x29be29dd00000000, 0xe0d348b900000000, - 0xa3c733ae00000000, 0x66fbbe9700000000, 0x25efc58000000000, - 0xf4207c5f00000000, 0xb734074800000000, 0x72088a7100000000, - 0x311cf16600000000, 0xf871900200000000, 0xbb65eb1500000000, - 0x7e59662c00000000, 0x3d4d1d3b00000000, 0x9dc0644800000000, - 0xded41f5f00000000, 0x1be8926600000000, 0x58fce97100000000, - 0x9191881500000000, 0xd285f30200000000, 0x17b97e3b00000000, - 0x54ad052c00000000, 0x8562bcf300000000, 0xc676c7e400000000, - 0x034a4add00000000, 0x405e31ca00000000, 0x893350ae00000000, - 0xca272bb900000000, 0x0f1ba68000000000, 0x4c0fdd9700000000, - 0x4803c7b800000000, 0x0b17bcaf00000000, 0xce2b319600000000, - 0x8d3f4a8100000000, 0x44522be500000000, 0x074650f200000000, - 0xc27addcb00000000, 0x816ea6dc00000000, 0x50a11f0300000000, - 0x13b5641400000000, 0xd689e92d00000000, 0x959d923a00000000, - 0x5cf0f35e00000000, 0x1fe4884900000000, 0xdad8057000000000, - 0x99cc7e6700000000, 0x3941071400000000, 0x7a557c0300000000, - 0xbf69f13a00000000, 0xfc7d8a2d00000000, 0x3510eb4900000000, - 0x7604905e00000000, 0xb3381d6700000000, 0xf02c667000000000, - 0x21e3dfaf00000000, 0x62f7a4b800000000, 0xa7cb298100000000, - 0xe4df529600000000, 0x2db233f200000000, 0x6ea648e500000000, - 0xab9ac5dc00000000, 0xe88ebecb00000000, 0xeb81363a00000000, - 0xa8954d2d00000000, 0x6da9c01400000000, 0x2ebdbb0300000000, - 0xe7d0da6700000000, 0xa4c4a17000000000, 0x61f82c4900000000, - 0x22ec575e00000000, 0xf323ee8100000000, 0xb037959600000000, - 0x750b18af00000000, 0x361f63b800000000, 0xff7202dc00000000, - 0xbc6679cb00000000, 0x795af4f200000000, 0x3a4e8fe500000000, - 0x9ac3f69600000000, 0xd9d78d8100000000, 0x1ceb00b800000000, - 0x5fff7baf00000000, 0x96921acb00000000, 0xd58661dc00000000, - 0x10baece500000000, 0x53ae97f200000000, 0x82612e2d00000000, - 0xc175553a00000000, 0x0449d80300000000, 0x475da31400000000, - 0x8e30c27000000000, 0xcd24b96700000000, 0x0818345e00000000, - 0x4b0c4f4900000000}, - {0x0000000000000000, 0x3e6bc2ef00000000, 0x3dd0f50400000000, - 0x03bb37eb00000000, 0x7aa0eb0900000000, 0x44cb29e600000000, - 0x47701e0d00000000, 0x791bdce200000000, 0xf440d71300000000, - 0xca2b15fc00000000, 0xc990221700000000, 0xf7fbe0f800000000, - 0x8ee03c1a00000000, 0xb08bfef500000000, 0xb330c91e00000000, - 0x8d5b0bf100000000, 0xe881ae2700000000, 0xd6ea6cc800000000, - 0xd5515b2300000000, 0xeb3a99cc00000000, 0x9221452e00000000, - 0xac4a87c100000000, 0xaff1b02a00000000, 0x919a72c500000000, - 0x1cc1793400000000, 0x22aabbdb00000000, 0x21118c3000000000, - 0x1f7a4edf00000000, 0x6661923d00000000, 0x580a50d200000000, - 0x5bb1673900000000, 0x65daa5d600000000, 0xd0035d4f00000000, - 0xee689fa000000000, 0xedd3a84b00000000, 0xd3b86aa400000000, - 0xaaa3b64600000000, 0x94c874a900000000, 0x9773434200000000, - 0xa91881ad00000000, 0x24438a5c00000000, 0x1a2848b300000000, - 0x19937f5800000000, 0x27f8bdb700000000, 0x5ee3615500000000, - 0x6088a3ba00000000, 0x6333945100000000, 0x5d5856be00000000, - 0x3882f36800000000, 0x06e9318700000000, 0x0552066c00000000, - 0x3b39c48300000000, 0x4222186100000000, 0x7c49da8e00000000, - 0x7ff2ed6500000000, 0x41992f8a00000000, 0xccc2247b00000000, - 0xf2a9e69400000000, 0xf112d17f00000000, 0xcf79139000000000, - 0xb662cf7200000000, 0x88090d9d00000000, 0x8bb23a7600000000, - 0xb5d9f89900000000, 0xa007ba9e00000000, 0x9e6c787100000000, - 0x9dd74f9a00000000, 0xa3bc8d7500000000, 0xdaa7519700000000, - 0xe4cc937800000000, 0xe777a49300000000, 0xd91c667c00000000, - 0x54476d8d00000000, 0x6a2caf6200000000, 0x6997988900000000, - 0x57fc5a6600000000, 0x2ee7868400000000, 0x108c446b00000000, - 0x1337738000000000, 0x2d5cb16f00000000, 0x488614b900000000, - 0x76edd65600000000, 0x7556e1bd00000000, 0x4b3d235200000000, - 0x3226ffb000000000, 0x0c4d3d5f00000000, 0x0ff60ab400000000, - 0x319dc85b00000000, 0xbcc6c3aa00000000, 0x82ad014500000000, - 0x811636ae00000000, 0xbf7df44100000000, 0xc66628a300000000, - 0xf80dea4c00000000, 0xfbb6dda700000000, 0xc5dd1f4800000000, - 0x7004e7d100000000, 0x4e6f253e00000000, 0x4dd412d500000000, - 0x73bfd03a00000000, 0x0aa40cd800000000, 0x34cfce3700000000, - 0x3774f9dc00000000, 0x091f3b3300000000, 0x844430c200000000, - 0xba2ff22d00000000, 0xb994c5c600000000, 0x87ff072900000000, - 0xfee4dbcb00000000, 0xc08f192400000000, 0xc3342ecf00000000, - 0xfd5fec2000000000, 0x988549f600000000, 0xa6ee8b1900000000, - 0xa555bcf200000000, 0x9b3e7e1d00000000, 0xe225a2ff00000000, - 0xdc4e601000000000, 0xdff557fb00000000, 0xe19e951400000000, - 0x6cc59ee500000000, 0x52ae5c0a00000000, 0x51156be100000000, - 0x6f7ea90e00000000, 0x166575ec00000000, 0x280eb70300000000, - 0x2bb580e800000000, 0x15de420700000000, 0x010905e600000000, - 0x3f62c70900000000, 0x3cd9f0e200000000, 0x02b2320d00000000, - 0x7ba9eeef00000000, 0x45c22c0000000000, 0x46791beb00000000, - 0x7812d90400000000, 0xf549d2f500000000, 0xcb22101a00000000, - 0xc89927f100000000, 0xf6f2e51e00000000, 0x8fe939fc00000000, - 0xb182fb1300000000, 0xb239ccf800000000, 0x8c520e1700000000, - 0xe988abc100000000, 0xd7e3692e00000000, 0xd4585ec500000000, - 0xea339c2a00000000, 0x932840c800000000, 0xad43822700000000, - 0xaef8b5cc00000000, 0x9093772300000000, 0x1dc87cd200000000, - 0x23a3be3d00000000, 0x201889d600000000, 0x1e734b3900000000, - 0x676897db00000000, 0x5903553400000000, 0x5ab862df00000000, - 0x64d3a03000000000, 0xd10a58a900000000, 0xef619a4600000000, - 0xecdaadad00000000, 0xd2b16f4200000000, 0xabaab3a000000000, - 0x95c1714f00000000, 0x967a46a400000000, 0xa811844b00000000, - 0x254a8fba00000000, 0x1b214d5500000000, 0x189a7abe00000000, - 0x26f1b85100000000, 0x5fea64b300000000, 0x6181a65c00000000, - 0x623a91b700000000, 0x5c51535800000000, 0x398bf68e00000000, - 0x07e0346100000000, 0x045b038a00000000, 0x3a30c16500000000, - 0x432b1d8700000000, 0x7d40df6800000000, 0x7efbe88300000000, - 0x40902a6c00000000, 0xcdcb219d00000000, 0xf3a0e37200000000, - 0xf01bd49900000000, 0xce70167600000000, 0xb76bca9400000000, - 0x8900087b00000000, 0x8abb3f9000000000, 0xb4d0fd7f00000000, - 0xa10ebf7800000000, 0x9f657d9700000000, 0x9cde4a7c00000000, - 0xa2b5889300000000, 0xdbae547100000000, 0xe5c5969e00000000, - 0xe67ea17500000000, 0xd815639a00000000, 0x554e686b00000000, - 0x6b25aa8400000000, 0x689e9d6f00000000, 0x56f55f8000000000, - 0x2fee836200000000, 0x1185418d00000000, 0x123e766600000000, - 0x2c55b48900000000, 0x498f115f00000000, 0x77e4d3b000000000, - 0x745fe45b00000000, 0x4a3426b400000000, 0x332ffa5600000000, - 0x0d4438b900000000, 0x0eff0f5200000000, 0x3094cdbd00000000, - 0xbdcfc64c00000000, 0x83a404a300000000, 0x801f334800000000, - 0xbe74f1a700000000, 0xc76f2d4500000000, 0xf904efaa00000000, - 0xfabfd84100000000, 0xc4d41aae00000000, 0x710de23700000000, - 0x4f6620d800000000, 0x4cdd173300000000, 0x72b6d5dc00000000, - 0x0bad093e00000000, 0x35c6cbd100000000, 0x367dfc3a00000000, - 0x08163ed500000000, 0x854d352400000000, 0xbb26f7cb00000000, - 0xb89dc02000000000, 0x86f602cf00000000, 0xffedde2d00000000, - 0xc1861cc200000000, 0xc23d2b2900000000, 0xfc56e9c600000000, - 0x998c4c1000000000, 0xa7e78eff00000000, 0xa45cb91400000000, - 0x9a377bfb00000000, 0xe32ca71900000000, 0xdd4765f600000000, - 0xdefc521d00000000, 0xe09790f200000000, 0x6dcc9b0300000000, - 0x53a759ec00000000, 0x501c6e0700000000, 0x6e77ace800000000, - 0x176c700a00000000, 0x2907b2e500000000, 0x2abc850e00000000, - 0x14d747e100000000}, - {0x0000000000000000, 0xc0df8ec100000000, 0xc1b96c5800000000, - 0x0166e29900000000, 0x8273d9b000000000, 0x42ac577100000000, - 0x43cab5e800000000, 0x83153b2900000000, 0x45e1c3ba00000000, - 0x853e4d7b00000000, 0x8458afe200000000, 0x4487212300000000, - 0xc7921a0a00000000, 0x074d94cb00000000, 0x062b765200000000, - 0xc6f4f89300000000, 0xcbc4f6ae00000000, 0x0b1b786f00000000, - 0x0a7d9af600000000, 0xcaa2143700000000, 0x49b72f1e00000000, - 0x8968a1df00000000, 0x880e434600000000, 0x48d1cd8700000000, - 0x8e25351400000000, 0x4efabbd500000000, 0x4f9c594c00000000, - 0x8f43d78d00000000, 0x0c56eca400000000, 0xcc89626500000000, - 0xcdef80fc00000000, 0x0d300e3d00000000, 0xd78f9c8600000000, - 0x1750124700000000, 0x1636f0de00000000, 0xd6e97e1f00000000, - 0x55fc453600000000, 0x9523cbf700000000, 0x9445296e00000000, - 0x549aa7af00000000, 0x926e5f3c00000000, 0x52b1d1fd00000000, - 0x53d7336400000000, 0x9308bda500000000, 0x101d868c00000000, - 0xd0c2084d00000000, 0xd1a4ead400000000, 0x117b641500000000, - 0x1c4b6a2800000000, 0xdc94e4e900000000, 0xddf2067000000000, - 0x1d2d88b100000000, 0x9e38b39800000000, 0x5ee73d5900000000, - 0x5f81dfc000000000, 0x9f5e510100000000, 0x59aaa99200000000, - 0x9975275300000000, 0x9813c5ca00000000, 0x58cc4b0b00000000, - 0xdbd9702200000000, 0x1b06fee300000000, 0x1a601c7a00000000, - 0xdabf92bb00000000, 0xef1948d600000000, 0x2fc6c61700000000, - 0x2ea0248e00000000, 0xee7faa4f00000000, 0x6d6a916600000000, - 0xadb51fa700000000, 0xacd3fd3e00000000, 0x6c0c73ff00000000, - 0xaaf88b6c00000000, 0x6a2705ad00000000, 0x6b41e73400000000, - 0xab9e69f500000000, 0x288b52dc00000000, 0xe854dc1d00000000, - 0xe9323e8400000000, 0x29edb04500000000, 0x24ddbe7800000000, - 0xe40230b900000000, 0xe564d22000000000, 0x25bb5ce100000000, - 0xa6ae67c800000000, 0x6671e90900000000, 0x67170b9000000000, - 0xa7c8855100000000, 0x613c7dc200000000, 0xa1e3f30300000000, - 0xa085119a00000000, 0x605a9f5b00000000, 0xe34fa47200000000, - 0x23902ab300000000, 0x22f6c82a00000000, 0xe22946eb00000000, - 0x3896d45000000000, 0xf8495a9100000000, 0xf92fb80800000000, - 0x39f036c900000000, 0xbae50de000000000, 0x7a3a832100000000, - 0x7b5c61b800000000, 0xbb83ef7900000000, 0x7d7717ea00000000, - 0xbda8992b00000000, 0xbcce7bb200000000, 0x7c11f57300000000, - 0xff04ce5a00000000, 0x3fdb409b00000000, 0x3ebda20200000000, - 0xfe622cc300000000, 0xf35222fe00000000, 0x338dac3f00000000, - 0x32eb4ea600000000, 0xf234c06700000000, 0x7121fb4e00000000, - 0xb1fe758f00000000, 0xb098971600000000, 0x704719d700000000, - 0xb6b3e14400000000, 0x766c6f8500000000, 0x770a8d1c00000000, - 0xb7d503dd00000000, 0x34c038f400000000, 0xf41fb63500000000, - 0xf57954ac00000000, 0x35a6da6d00000000, 0x9f35e17700000000, - 0x5fea6fb600000000, 0x5e8c8d2f00000000, 0x9e5303ee00000000, - 0x1d4638c700000000, 0xdd99b60600000000, 0xdcff549f00000000, - 0x1c20da5e00000000, 0xdad422cd00000000, 0x1a0bac0c00000000, - 0x1b6d4e9500000000, 0xdbb2c05400000000, 0x58a7fb7d00000000, - 0x987875bc00000000, 0x991e972500000000, 0x59c119e400000000, - 0x54f117d900000000, 0x942e991800000000, 0x95487b8100000000, - 0x5597f54000000000, 0xd682ce6900000000, 0x165d40a800000000, - 0x173ba23100000000, 0xd7e42cf000000000, 0x1110d46300000000, - 0xd1cf5aa200000000, 0xd0a9b83b00000000, 0x107636fa00000000, - 0x93630dd300000000, 0x53bc831200000000, 0x52da618b00000000, - 0x9205ef4a00000000, 0x48ba7df100000000, 0x8865f33000000000, - 0x890311a900000000, 0x49dc9f6800000000, 0xcac9a44100000000, - 0x0a162a8000000000, 0x0b70c81900000000, 0xcbaf46d800000000, - 0x0d5bbe4b00000000, 0xcd84308a00000000, 0xcce2d21300000000, - 0x0c3d5cd200000000, 0x8f2867fb00000000, 0x4ff7e93a00000000, - 0x4e910ba300000000, 0x8e4e856200000000, 0x837e8b5f00000000, - 0x43a1059e00000000, 0x42c7e70700000000, 0x821869c600000000, - 0x010d52ef00000000, 0xc1d2dc2e00000000, 0xc0b43eb700000000, - 0x006bb07600000000, 0xc69f48e500000000, 0x0640c62400000000, - 0x072624bd00000000, 0xc7f9aa7c00000000, 0x44ec915500000000, - 0x84331f9400000000, 0x8555fd0d00000000, 0x458a73cc00000000, - 0x702ca9a100000000, 0xb0f3276000000000, 0xb195c5f900000000, - 0x714a4b3800000000, 0xf25f701100000000, 0x3280fed000000000, - 0x33e61c4900000000, 0xf339928800000000, 0x35cd6a1b00000000, - 0xf512e4da00000000, 0xf474064300000000, 0x34ab888200000000, - 0xb7beb3ab00000000, 0x77613d6a00000000, 0x7607dff300000000, - 0xb6d8513200000000, 0xbbe85f0f00000000, 0x7b37d1ce00000000, - 0x7a51335700000000, 0xba8ebd9600000000, 0x399b86bf00000000, - 0xf944087e00000000, 0xf822eae700000000, 0x38fd642600000000, - 0xfe099cb500000000, 0x3ed6127400000000, 0x3fb0f0ed00000000, - 0xff6f7e2c00000000, 0x7c7a450500000000, 0xbca5cbc400000000, - 0xbdc3295d00000000, 0x7d1ca79c00000000, 0xa7a3352700000000, - 0x677cbbe600000000, 0x661a597f00000000, 0xa6c5d7be00000000, - 0x25d0ec9700000000, 0xe50f625600000000, 0xe46980cf00000000, - 0x24b60e0e00000000, 0xe242f69d00000000, 0x229d785c00000000, - 0x23fb9ac500000000, 0xe324140400000000, 0x60312f2d00000000, - 0xa0eea1ec00000000, 0xa188437500000000, 0x6157cdb400000000, - 0x6c67c38900000000, 0xacb84d4800000000, 0xaddeafd100000000, - 0x6d01211000000000, 0xee141a3900000000, 0x2ecb94f800000000, - 0x2fad766100000000, 0xef72f8a000000000, 0x2986003300000000, - 0xe9598ef200000000, 0xe83f6c6b00000000, 0x28e0e2aa00000000, - 0xabf5d98300000000, 0x6b2a574200000000, 0x6a4cb5db00000000, - 0xaa933b1a00000000}, - {0x0000000000000000, 0x6f4ca59b00000000, 0x9f9e3bec00000000, - 0xf0d29e7700000000, 0x7f3b060300000000, 0x1077a39800000000, - 0xe0a53def00000000, 0x8fe9987400000000, 0xfe760c0600000000, - 0x913aa99d00000000, 0x61e837ea00000000, 0x0ea4927100000000, - 0x814d0a0500000000, 0xee01af9e00000000, 0x1ed331e900000000, - 0x719f947200000000, 0xfced180c00000000, 0x93a1bd9700000000, - 0x637323e000000000, 0x0c3f867b00000000, 0x83d61e0f00000000, - 0xec9abb9400000000, 0x1c4825e300000000, 0x7304807800000000, - 0x029b140a00000000, 0x6dd7b19100000000, 0x9d052fe600000000, - 0xf2498a7d00000000, 0x7da0120900000000, 0x12ecb79200000000, - 0xe23e29e500000000, 0x8d728c7e00000000, 0xf8db311800000000, - 0x9797948300000000, 0x67450af400000000, 0x0809af6f00000000, - 0x87e0371b00000000, 0xe8ac928000000000, 0x187e0cf700000000, - 0x7732a96c00000000, 0x06ad3d1e00000000, 0x69e1988500000000, - 0x993306f200000000, 0xf67fa36900000000, 0x79963b1d00000000, - 0x16da9e8600000000, 0xe60800f100000000, 0x8944a56a00000000, - 0x0436291400000000, 0x6b7a8c8f00000000, 0x9ba812f800000000, - 0xf4e4b76300000000, 0x7b0d2f1700000000, 0x14418a8c00000000, - 0xe49314fb00000000, 0x8bdfb16000000000, 0xfa40251200000000, - 0x950c808900000000, 0x65de1efe00000000, 0x0a92bb6500000000, - 0x857b231100000000, 0xea37868a00000000, 0x1ae518fd00000000, - 0x75a9bd6600000000, 0xf0b7633000000000, 0x9ffbc6ab00000000, - 0x6f2958dc00000000, 0x0065fd4700000000, 0x8f8c653300000000, - 0xe0c0c0a800000000, 0x10125edf00000000, 0x7f5efb4400000000, - 0x0ec16f3600000000, 0x618dcaad00000000, 0x915f54da00000000, - 0xfe13f14100000000, 0x71fa693500000000, 0x1eb6ccae00000000, - 0xee6452d900000000, 0x8128f74200000000, 0x0c5a7b3c00000000, - 0x6316dea700000000, 0x93c440d000000000, 0xfc88e54b00000000, - 0x73617d3f00000000, 0x1c2dd8a400000000, 0xecff46d300000000, - 0x83b3e34800000000, 0xf22c773a00000000, 0x9d60d2a100000000, - 0x6db24cd600000000, 0x02fee94d00000000, 0x8d17713900000000, - 0xe25bd4a200000000, 0x12894ad500000000, 0x7dc5ef4e00000000, - 0x086c522800000000, 0x6720f7b300000000, 0x97f269c400000000, - 0xf8becc5f00000000, 0x7757542b00000000, 0x181bf1b000000000, - 0xe8c96fc700000000, 0x8785ca5c00000000, 0xf61a5e2e00000000, - 0x9956fbb500000000, 0x698465c200000000, 0x06c8c05900000000, - 0x8921582d00000000, 0xe66dfdb600000000, 0x16bf63c100000000, - 0x79f3c65a00000000, 0xf4814a2400000000, 0x9bcdefbf00000000, - 0x6b1f71c800000000, 0x0453d45300000000, 0x8bba4c2700000000, - 0xe4f6e9bc00000000, 0x142477cb00000000, 0x7b68d25000000000, - 0x0af7462200000000, 0x65bbe3b900000000, 0x95697dce00000000, - 0xfa25d85500000000, 0x75cc402100000000, 0x1a80e5ba00000000, - 0xea527bcd00000000, 0x851ede5600000000, 0xe06fc76000000000, - 0x8f2362fb00000000, 0x7ff1fc8c00000000, 0x10bd591700000000, - 0x9f54c16300000000, 0xf01864f800000000, 0x00cafa8f00000000, - 0x6f865f1400000000, 0x1e19cb6600000000, 0x71556efd00000000, - 0x8187f08a00000000, 0xeecb551100000000, 0x6122cd6500000000, - 0x0e6e68fe00000000, 0xfebcf68900000000, 0x91f0531200000000, - 0x1c82df6c00000000, 0x73ce7af700000000, 0x831ce48000000000, - 0xec50411b00000000, 0x63b9d96f00000000, 0x0cf57cf400000000, - 0xfc27e28300000000, 0x936b471800000000, 0xe2f4d36a00000000, - 0x8db876f100000000, 0x7d6ae88600000000, 0x12264d1d00000000, - 0x9dcfd56900000000, 0xf28370f200000000, 0x0251ee8500000000, - 0x6d1d4b1e00000000, 0x18b4f67800000000, 0x77f853e300000000, - 0x872acd9400000000, 0xe866680f00000000, 0x678ff07b00000000, - 0x08c355e000000000, 0xf811cb9700000000, 0x975d6e0c00000000, - 0xe6c2fa7e00000000, 0x898e5fe500000000, 0x795cc19200000000, - 0x1610640900000000, 0x99f9fc7d00000000, 0xf6b559e600000000, - 0x0667c79100000000, 0x692b620a00000000, 0xe459ee7400000000, - 0x8b154bef00000000, 0x7bc7d59800000000, 0x148b700300000000, - 0x9b62e87700000000, 0xf42e4dec00000000, 0x04fcd39b00000000, - 0x6bb0760000000000, 0x1a2fe27200000000, 0x756347e900000000, - 0x85b1d99e00000000, 0xeafd7c0500000000, 0x6514e47100000000, - 0x0a5841ea00000000, 0xfa8adf9d00000000, 0x95c67a0600000000, - 0x10d8a45000000000, 0x7f9401cb00000000, 0x8f469fbc00000000, - 0xe00a3a2700000000, 0x6fe3a25300000000, 0x00af07c800000000, - 0xf07d99bf00000000, 0x9f313c2400000000, 0xeeaea85600000000, - 0x81e20dcd00000000, 0x713093ba00000000, 0x1e7c362100000000, - 0x9195ae5500000000, 0xfed90bce00000000, 0x0e0b95b900000000, - 0x6147302200000000, 0xec35bc5c00000000, 0x837919c700000000, - 0x73ab87b000000000, 0x1ce7222b00000000, 0x930eba5f00000000, - 0xfc421fc400000000, 0x0c9081b300000000, 0x63dc242800000000, - 0x1243b05a00000000, 0x7d0f15c100000000, 0x8ddd8bb600000000, - 0xe2912e2d00000000, 0x6d78b65900000000, 0x023413c200000000, - 0xf2e68db500000000, 0x9daa282e00000000, 0xe803954800000000, - 0x874f30d300000000, 0x779daea400000000, 0x18d10b3f00000000, - 0x9738934b00000000, 0xf87436d000000000, 0x08a6a8a700000000, - 0x67ea0d3c00000000, 0x1675994e00000000, 0x79393cd500000000, - 0x89eba2a200000000, 0xe6a7073900000000, 0x694e9f4d00000000, - 0x06023ad600000000, 0xf6d0a4a100000000, 0x999c013a00000000, - 0x14ee8d4400000000, 0x7ba228df00000000, 0x8b70b6a800000000, - 0xe43c133300000000, 0x6bd58b4700000000, 0x04992edc00000000, - 0xf44bb0ab00000000, 0x9b07153000000000, 0xea98814200000000, - 0x85d424d900000000, 0x7506baae00000000, 0x1a4a1f3500000000, - 0x95a3874100000000, 0xfaef22da00000000, 0x0a3dbcad00000000, - 0x6571193600000000}, - {0x0000000000000000, 0x85d996dd00000000, 0x4bb55c6000000000, - 0xce6ccabd00000000, 0x966ab9c000000000, 0x13b32f1d00000000, - 0xdddfe5a000000000, 0x5806737d00000000, 0x6dd3035a00000000, - 0xe80a958700000000, 0x26665f3a00000000, 0xa3bfc9e700000000, - 0xfbb9ba9a00000000, 0x7e602c4700000000, 0xb00ce6fa00000000, - 0x35d5702700000000, 0xdaa607b400000000, 0x5f7f916900000000, - 0x91135bd400000000, 0x14cacd0900000000, 0x4cccbe7400000000, - 0xc91528a900000000, 0x0779e21400000000, 0x82a074c900000000, - 0xb77504ee00000000, 0x32ac923300000000, 0xfcc0588e00000000, - 0x7919ce5300000000, 0x211fbd2e00000000, 0xa4c62bf300000000, - 0x6aaae14e00000000, 0xef73779300000000, 0xf54b7eb300000000, - 0x7092e86e00000000, 0xbefe22d300000000, 0x3b27b40e00000000, - 0x6321c77300000000, 0xe6f851ae00000000, 0x28949b1300000000, - 0xad4d0dce00000000, 0x98987de900000000, 0x1d41eb3400000000, - 0xd32d218900000000, 0x56f4b75400000000, 0x0ef2c42900000000, - 0x8b2b52f400000000, 0x4547984900000000, 0xc09e0e9400000000, - 0x2fed790700000000, 0xaa34efda00000000, 0x6458256700000000, - 0xe181b3ba00000000, 0xb987c0c700000000, 0x3c5e561a00000000, - 0xf2329ca700000000, 0x77eb0a7a00000000, 0x423e7a5d00000000, - 0xc7e7ec8000000000, 0x098b263d00000000, 0x8c52b0e000000000, - 0xd454c39d00000000, 0x518d554000000000, 0x9fe19ffd00000000, - 0x1a38092000000000, 0xab918dbd00000000, 0x2e481b6000000000, - 0xe024d1dd00000000, 0x65fd470000000000, 0x3dfb347d00000000, - 0xb822a2a000000000, 0x764e681d00000000, 0xf397fec000000000, - 0xc6428ee700000000, 0x439b183a00000000, 0x8df7d28700000000, - 0x082e445a00000000, 0x5028372700000000, 0xd5f1a1fa00000000, - 0x1b9d6b4700000000, 0x9e44fd9a00000000, 0x71378a0900000000, - 0xf4ee1cd400000000, 0x3a82d66900000000, 0xbf5b40b400000000, - 0xe75d33c900000000, 0x6284a51400000000, 0xace86fa900000000, - 0x2931f97400000000, 0x1ce4895300000000, 0x993d1f8e00000000, - 0x5751d53300000000, 0xd28843ee00000000, 0x8a8e309300000000, - 0x0f57a64e00000000, 0xc13b6cf300000000, 0x44e2fa2e00000000, - 0x5edaf30e00000000, 0xdb0365d300000000, 0x156faf6e00000000, - 0x90b639b300000000, 0xc8b04ace00000000, 0x4d69dc1300000000, - 0x830516ae00000000, 0x06dc807300000000, 0x3309f05400000000, - 0xb6d0668900000000, 0x78bcac3400000000, 0xfd653ae900000000, - 0xa563499400000000, 0x20badf4900000000, 0xeed615f400000000, - 0x6b0f832900000000, 0x847cf4ba00000000, 0x01a5626700000000, - 0xcfc9a8da00000000, 0x4a103e0700000000, 0x12164d7a00000000, - 0x97cfdba700000000, 0x59a3111a00000000, 0xdc7a87c700000000, - 0xe9aff7e000000000, 0x6c76613d00000000, 0xa21aab8000000000, - 0x27c33d5d00000000, 0x7fc54e2000000000, 0xfa1cd8fd00000000, - 0x3470124000000000, 0xb1a9849d00000000, 0x17256aa000000000, - 0x92fcfc7d00000000, 0x5c9036c000000000, 0xd949a01d00000000, - 0x814fd36000000000, 0x049645bd00000000, 0xcafa8f0000000000, - 0x4f2319dd00000000, 0x7af669fa00000000, 0xff2fff2700000000, - 0x3143359a00000000, 0xb49aa34700000000, 0xec9cd03a00000000, - 0x694546e700000000, 0xa7298c5a00000000, 0x22f01a8700000000, - 0xcd836d1400000000, 0x485afbc900000000, 0x8636317400000000, - 0x03efa7a900000000, 0x5be9d4d400000000, 0xde30420900000000, - 0x105c88b400000000, 0x95851e6900000000, 0xa0506e4e00000000, - 0x2589f89300000000, 0xebe5322e00000000, 0x6e3ca4f300000000, - 0x363ad78e00000000, 0xb3e3415300000000, 0x7d8f8bee00000000, - 0xf8561d3300000000, 0xe26e141300000000, 0x67b782ce00000000, - 0xa9db487300000000, 0x2c02deae00000000, 0x7404add300000000, - 0xf1dd3b0e00000000, 0x3fb1f1b300000000, 0xba68676e00000000, - 0x8fbd174900000000, 0x0a64819400000000, 0xc4084b2900000000, - 0x41d1ddf400000000, 0x19d7ae8900000000, 0x9c0e385400000000, - 0x5262f2e900000000, 0xd7bb643400000000, 0x38c813a700000000, - 0xbd11857a00000000, 0x737d4fc700000000, 0xf6a4d91a00000000, - 0xaea2aa6700000000, 0x2b7b3cba00000000, 0xe517f60700000000, - 0x60ce60da00000000, 0x551b10fd00000000, 0xd0c2862000000000, - 0x1eae4c9d00000000, 0x9b77da4000000000, 0xc371a93d00000000, - 0x46a83fe000000000, 0x88c4f55d00000000, 0x0d1d638000000000, - 0xbcb4e71d00000000, 0x396d71c000000000, 0xf701bb7d00000000, - 0x72d82da000000000, 0x2ade5edd00000000, 0xaf07c80000000000, - 0x616b02bd00000000, 0xe4b2946000000000, 0xd167e44700000000, - 0x54be729a00000000, 0x9ad2b82700000000, 0x1f0b2efa00000000, - 0x470d5d8700000000, 0xc2d4cb5a00000000, 0x0cb801e700000000, - 0x8961973a00000000, 0x6612e0a900000000, 0xe3cb767400000000, - 0x2da7bcc900000000, 0xa87e2a1400000000, 0xf078596900000000, - 0x75a1cfb400000000, 0xbbcd050900000000, 0x3e1493d400000000, - 0x0bc1e3f300000000, 0x8e18752e00000000, 0x4074bf9300000000, - 0xc5ad294e00000000, 0x9dab5a3300000000, 0x1872ccee00000000, - 0xd61e065300000000, 0x53c7908e00000000, 0x49ff99ae00000000, - 0xcc260f7300000000, 0x024ac5ce00000000, 0x8793531300000000, - 0xdf95206e00000000, 0x5a4cb6b300000000, 0x94207c0e00000000, - 0x11f9ead300000000, 0x242c9af400000000, 0xa1f50c2900000000, - 0x6f99c69400000000, 0xea40504900000000, 0xb246233400000000, - 0x379fb5e900000000, 0xf9f37f5400000000, 0x7c2ae98900000000, - 0x93599e1a00000000, 0x168008c700000000, 0xd8ecc27a00000000, - 0x5d3554a700000000, 0x053327da00000000, 0x80eab10700000000, - 0x4e867bba00000000, 0xcb5fed6700000000, 0xfe8a9d4000000000, - 0x7b530b9d00000000, 0xb53fc12000000000, 0x30e657fd00000000, - 0x68e0248000000000, 0xed39b25d00000000, 0x235578e000000000, - 0xa68cee3d00000000}, - {0x0000000000000000, 0x76e10f9d00000000, 0xadc46ee100000000, - 0xdb25617c00000000, 0x1b8fac1900000000, 0x6d6ea38400000000, - 0xb64bc2f800000000, 0xc0aacd6500000000, 0x361e593300000000, - 0x40ff56ae00000000, 0x9bda37d200000000, 0xed3b384f00000000, - 0x2d91f52a00000000, 0x5b70fab700000000, 0x80559bcb00000000, - 0xf6b4945600000000, 0x6c3cb26600000000, 0x1addbdfb00000000, - 0xc1f8dc8700000000, 0xb719d31a00000000, 0x77b31e7f00000000, - 0x015211e200000000, 0xda77709e00000000, 0xac967f0300000000, - 0x5a22eb5500000000, 0x2cc3e4c800000000, 0xf7e685b400000000, - 0x81078a2900000000, 0x41ad474c00000000, 0x374c48d100000000, - 0xec6929ad00000000, 0x9a88263000000000, 0xd87864cd00000000, - 0xae996b5000000000, 0x75bc0a2c00000000, 0x035d05b100000000, - 0xc3f7c8d400000000, 0xb516c74900000000, 0x6e33a63500000000, - 0x18d2a9a800000000, 0xee663dfe00000000, 0x9887326300000000, - 0x43a2531f00000000, 0x35435c8200000000, 0xf5e991e700000000, - 0x83089e7a00000000, 0x582dff0600000000, 0x2eccf09b00000000, - 0xb444d6ab00000000, 0xc2a5d93600000000, 0x1980b84a00000000, - 0x6f61b7d700000000, 0xafcb7ab200000000, 0xd92a752f00000000, - 0x020f145300000000, 0x74ee1bce00000000, 0x825a8f9800000000, - 0xf4bb800500000000, 0x2f9ee17900000000, 0x597feee400000000, - 0x99d5238100000000, 0xef342c1c00000000, 0x34114d6000000000, - 0x42f042fd00000000, 0xf1f7b94100000000, 0x8716b6dc00000000, - 0x5c33d7a000000000, 0x2ad2d83d00000000, 0xea78155800000000, - 0x9c991ac500000000, 0x47bc7bb900000000, 0x315d742400000000, - 0xc7e9e07200000000, 0xb108efef00000000, 0x6a2d8e9300000000, - 0x1ccc810e00000000, 0xdc664c6b00000000, 0xaa8743f600000000, - 0x71a2228a00000000, 0x07432d1700000000, 0x9dcb0b2700000000, - 0xeb2a04ba00000000, 0x300f65c600000000, 0x46ee6a5b00000000, - 0x8644a73e00000000, 0xf0a5a8a300000000, 0x2b80c9df00000000, - 0x5d61c64200000000, 0xabd5521400000000, 0xdd345d8900000000, - 0x06113cf500000000, 0x70f0336800000000, 0xb05afe0d00000000, - 0xc6bbf19000000000, 0x1d9e90ec00000000, 0x6b7f9f7100000000, - 0x298fdd8c00000000, 0x5f6ed21100000000, 0x844bb36d00000000, - 0xf2aabcf000000000, 0x3200719500000000, 0x44e17e0800000000, - 0x9fc41f7400000000, 0xe92510e900000000, 0x1f9184bf00000000, - 0x69708b2200000000, 0xb255ea5e00000000, 0xc4b4e5c300000000, - 0x041e28a600000000, 0x72ff273b00000000, 0xa9da464700000000, - 0xdf3b49da00000000, 0x45b36fea00000000, 0x3352607700000000, - 0xe877010b00000000, 0x9e960e9600000000, 0x5e3cc3f300000000, - 0x28ddcc6e00000000, 0xf3f8ad1200000000, 0x8519a28f00000000, - 0x73ad36d900000000, 0x054c394400000000, 0xde69583800000000, - 0xa88857a500000000, 0x68229ac000000000, 0x1ec3955d00000000, - 0xc5e6f42100000000, 0xb307fbbc00000000, 0xe2ef738300000000, - 0x940e7c1e00000000, 0x4f2b1d6200000000, 0x39ca12ff00000000, - 0xf960df9a00000000, 0x8f81d00700000000, 0x54a4b17b00000000, - 0x2245bee600000000, 0xd4f12ab000000000, 0xa210252d00000000, - 0x7935445100000000, 0x0fd44bcc00000000, 0xcf7e86a900000000, - 0xb99f893400000000, 0x62bae84800000000, 0x145be7d500000000, - 0x8ed3c1e500000000, 0xf832ce7800000000, 0x2317af0400000000, - 0x55f6a09900000000, 0x955c6dfc00000000, 0xe3bd626100000000, - 0x3898031d00000000, 0x4e790c8000000000, 0xb8cd98d600000000, - 0xce2c974b00000000, 0x1509f63700000000, 0x63e8f9aa00000000, - 0xa34234cf00000000, 0xd5a33b5200000000, 0x0e865a2e00000000, - 0x786755b300000000, 0x3a97174e00000000, 0x4c7618d300000000, - 0x975379af00000000, 0xe1b2763200000000, 0x2118bb5700000000, - 0x57f9b4ca00000000, 0x8cdcd5b600000000, 0xfa3dda2b00000000, - 0x0c894e7d00000000, 0x7a6841e000000000, 0xa14d209c00000000, - 0xd7ac2f0100000000, 0x1706e26400000000, 0x61e7edf900000000, - 0xbac28c8500000000, 0xcc23831800000000, 0x56aba52800000000, - 0x204aaab500000000, 0xfb6fcbc900000000, 0x8d8ec45400000000, - 0x4d24093100000000, 0x3bc506ac00000000, 0xe0e067d000000000, - 0x9601684d00000000, 0x60b5fc1b00000000, 0x1654f38600000000, - 0xcd7192fa00000000, 0xbb909d6700000000, 0x7b3a500200000000, - 0x0ddb5f9f00000000, 0xd6fe3ee300000000, 0xa01f317e00000000, - 0x1318cac200000000, 0x65f9c55f00000000, 0xbedca42300000000, - 0xc83dabbe00000000, 0x089766db00000000, 0x7e76694600000000, - 0xa553083a00000000, 0xd3b207a700000000, 0x250693f100000000, - 0x53e79c6c00000000, 0x88c2fd1000000000, 0xfe23f28d00000000, - 0x3e893fe800000000, 0x4868307500000000, 0x934d510900000000, - 0xe5ac5e9400000000, 0x7f2478a400000000, 0x09c5773900000000, - 0xd2e0164500000000, 0xa40119d800000000, 0x64abd4bd00000000, - 0x124adb2000000000, 0xc96fba5c00000000, 0xbf8eb5c100000000, - 0x493a219700000000, 0x3fdb2e0a00000000, 0xe4fe4f7600000000, - 0x921f40eb00000000, 0x52b58d8e00000000, 0x2454821300000000, - 0xff71e36f00000000, 0x8990ecf200000000, 0xcb60ae0f00000000, - 0xbd81a19200000000, 0x66a4c0ee00000000, 0x1045cf7300000000, - 0xd0ef021600000000, 0xa60e0d8b00000000, 0x7d2b6cf700000000, - 0x0bca636a00000000, 0xfd7ef73c00000000, 0x8b9ff8a100000000, - 0x50ba99dd00000000, 0x265b964000000000, 0xe6f15b2500000000, - 0x901054b800000000, 0x4b3535c400000000, 0x3dd43a5900000000, - 0xa75c1c6900000000, 0xd1bd13f400000000, 0x0a98728800000000, - 0x7c797d1500000000, 0xbcd3b07000000000, 0xca32bfed00000000, - 0x1117de9100000000, 0x67f6d10c00000000, 0x9142455a00000000, - 0xe7a34ac700000000, 0x3c862bbb00000000, 0x4a67242600000000, - 0x8acde94300000000, 0xfc2ce6de00000000, 0x270987a200000000, - 0x51e8883f00000000}, - {0x0000000000000000, 0xe8dbfbb900000000, 0x91b186a800000000, - 0x796a7d1100000000, 0x63657c8a00000000, 0x8bbe873300000000, - 0xf2d4fa2200000000, 0x1a0f019b00000000, 0x87cc89cf00000000, - 0x6f17727600000000, 0x167d0f6700000000, 0xfea6f4de00000000, - 0xe4a9f54500000000, 0x0c720efc00000000, 0x751873ed00000000, - 0x9dc3885400000000, 0x4f9f624400000000, 0xa74499fd00000000, - 0xde2ee4ec00000000, 0x36f51f5500000000, 0x2cfa1ece00000000, - 0xc421e57700000000, 0xbd4b986600000000, 0x559063df00000000, - 0xc853eb8b00000000, 0x2088103200000000, 0x59e26d2300000000, - 0xb139969a00000000, 0xab36970100000000, 0x43ed6cb800000000, - 0x3a8711a900000000, 0xd25cea1000000000, 0x9e3ec58800000000, - 0x76e53e3100000000, 0x0f8f432000000000, 0xe754b89900000000, - 0xfd5bb90200000000, 0x158042bb00000000, 0x6cea3faa00000000, - 0x8431c41300000000, 0x19f24c4700000000, 0xf129b7fe00000000, - 0x8843caef00000000, 0x6098315600000000, 0x7a9730cd00000000, - 0x924ccb7400000000, 0xeb26b66500000000, 0x03fd4ddc00000000, - 0xd1a1a7cc00000000, 0x397a5c7500000000, 0x4010216400000000, - 0xa8cbdadd00000000, 0xb2c4db4600000000, 0x5a1f20ff00000000, - 0x23755dee00000000, 0xcbaea65700000000, 0x566d2e0300000000, - 0xbeb6d5ba00000000, 0xc7dca8ab00000000, 0x2f07531200000000, - 0x3508528900000000, 0xddd3a93000000000, 0xa4b9d42100000000, - 0x4c622f9800000000, 0x7d7bfbca00000000, 0x95a0007300000000, - 0xecca7d6200000000, 0x041186db00000000, 0x1e1e874000000000, - 0xf6c57cf900000000, 0x8faf01e800000000, 0x6774fa5100000000, - 0xfab7720500000000, 0x126c89bc00000000, 0x6b06f4ad00000000, - 0x83dd0f1400000000, 0x99d20e8f00000000, 0x7109f53600000000, - 0x0863882700000000, 0xe0b8739e00000000, 0x32e4998e00000000, - 0xda3f623700000000, 0xa3551f2600000000, 0x4b8ee49f00000000, - 0x5181e50400000000, 0xb95a1ebd00000000, 0xc03063ac00000000, - 0x28eb981500000000, 0xb528104100000000, 0x5df3ebf800000000, - 0x249996e900000000, 0xcc426d5000000000, 0xd64d6ccb00000000, - 0x3e96977200000000, 0x47fcea6300000000, 0xaf2711da00000000, - 0xe3453e4200000000, 0x0b9ec5fb00000000, 0x72f4b8ea00000000, - 0x9a2f435300000000, 0x802042c800000000, 0x68fbb97100000000, - 0x1191c46000000000, 0xf94a3fd900000000, 0x6489b78d00000000, - 0x8c524c3400000000, 0xf538312500000000, 0x1de3ca9c00000000, - 0x07eccb0700000000, 0xef3730be00000000, 0x965d4daf00000000, - 0x7e86b61600000000, 0xacda5c0600000000, 0x4401a7bf00000000, - 0x3d6bdaae00000000, 0xd5b0211700000000, 0xcfbf208c00000000, - 0x2764db3500000000, 0x5e0ea62400000000, 0xb6d55d9d00000000, - 0x2b16d5c900000000, 0xc3cd2e7000000000, 0xbaa7536100000000, - 0x527ca8d800000000, 0x4873a94300000000, 0xa0a852fa00000000, - 0xd9c22feb00000000, 0x3119d45200000000, 0xbbf0874e00000000, - 0x532b7cf700000000, 0x2a4101e600000000, 0xc29afa5f00000000, - 0xd895fbc400000000, 0x304e007d00000000, 0x49247d6c00000000, - 0xa1ff86d500000000, 0x3c3c0e8100000000, 0xd4e7f53800000000, - 0xad8d882900000000, 0x4556739000000000, 0x5f59720b00000000, - 0xb78289b200000000, 0xcee8f4a300000000, 0x26330f1a00000000, - 0xf46fe50a00000000, 0x1cb41eb300000000, 0x65de63a200000000, - 0x8d05981b00000000, 0x970a998000000000, 0x7fd1623900000000, - 0x06bb1f2800000000, 0xee60e49100000000, 0x73a36cc500000000, - 0x9b78977c00000000, 0xe212ea6d00000000, 0x0ac911d400000000, - 0x10c6104f00000000, 0xf81debf600000000, 0x817796e700000000, - 0x69ac6d5e00000000, 0x25ce42c600000000, 0xcd15b97f00000000, - 0xb47fc46e00000000, 0x5ca43fd700000000, 0x46ab3e4c00000000, - 0xae70c5f500000000, 0xd71ab8e400000000, 0x3fc1435d00000000, - 0xa202cb0900000000, 0x4ad930b000000000, 0x33b34da100000000, - 0xdb68b61800000000, 0xc167b78300000000, 0x29bc4c3a00000000, - 0x50d6312b00000000, 0xb80dca9200000000, 0x6a51208200000000, - 0x828adb3b00000000, 0xfbe0a62a00000000, 0x133b5d9300000000, - 0x09345c0800000000, 0xe1efa7b100000000, 0x9885daa000000000, - 0x705e211900000000, 0xed9da94d00000000, 0x054652f400000000, - 0x7c2c2fe500000000, 0x94f7d45c00000000, 0x8ef8d5c700000000, - 0x66232e7e00000000, 0x1f49536f00000000, 0xf792a8d600000000, - 0xc68b7c8400000000, 0x2e50873d00000000, 0x573afa2c00000000, - 0xbfe1019500000000, 0xa5ee000e00000000, 0x4d35fbb700000000, - 0x345f86a600000000, 0xdc847d1f00000000, 0x4147f54b00000000, - 0xa99c0ef200000000, 0xd0f673e300000000, 0x382d885a00000000, - 0x222289c100000000, 0xcaf9727800000000, 0xb3930f6900000000, - 0x5b48f4d000000000, 0x89141ec000000000, 0x61cfe57900000000, - 0x18a5986800000000, 0xf07e63d100000000, 0xea71624a00000000, - 0x02aa99f300000000, 0x7bc0e4e200000000, 0x931b1f5b00000000, - 0x0ed8970f00000000, 0xe6036cb600000000, 0x9f6911a700000000, - 0x77b2ea1e00000000, 0x6dbdeb8500000000, 0x8566103c00000000, - 0xfc0c6d2d00000000, 0x14d7969400000000, 0x58b5b90c00000000, - 0xb06e42b500000000, 0xc9043fa400000000, 0x21dfc41d00000000, - 0x3bd0c58600000000, 0xd30b3e3f00000000, 0xaa61432e00000000, - 0x42bab89700000000, 0xdf7930c300000000, 0x37a2cb7a00000000, - 0x4ec8b66b00000000, 0xa6134dd200000000, 0xbc1c4c4900000000, - 0x54c7b7f000000000, 0x2dadcae100000000, 0xc576315800000000, - 0x172adb4800000000, 0xfff120f100000000, 0x869b5de000000000, - 0x6e40a65900000000, 0x744fa7c200000000, 0x9c945c7b00000000, - 0xe5fe216a00000000, 0x0d25dad300000000, 0x90e6528700000000, - 0x783da93e00000000, 0x0157d42f00000000, 0xe98c2f9600000000, - 0xf3832e0d00000000, 0x1b58d5b400000000, 0x6232a8a500000000, - 0x8ae9531c00000000}, - {0x0000000000000000, 0x919168ae00000000, 0x6325a08700000000, - 0xf2b4c82900000000, 0x874c31d400000000, 0x16dd597a00000000, - 0xe469915300000000, 0x75f8f9fd00000000, 0x4f9f137300000000, - 0xde0e7bdd00000000, 0x2cbab3f400000000, 0xbd2bdb5a00000000, - 0xc8d322a700000000, 0x59424a0900000000, 0xabf6822000000000, - 0x3a67ea8e00000000, 0x9e3e27e600000000, 0x0faf4f4800000000, - 0xfd1b876100000000, 0x6c8aefcf00000000, 0x1972163200000000, - 0x88e37e9c00000000, 0x7a57b6b500000000, 0xebc6de1b00000000, - 0xd1a1349500000000, 0x40305c3b00000000, 0xb284941200000000, - 0x2315fcbc00000000, 0x56ed054100000000, 0xc77c6def00000000, - 0x35c8a5c600000000, 0xa459cd6800000000, 0x7d7b3f1700000000, - 0xecea57b900000000, 0x1e5e9f9000000000, 0x8fcff73e00000000, - 0xfa370ec300000000, 0x6ba6666d00000000, 0x9912ae4400000000, - 0x0883c6ea00000000, 0x32e42c6400000000, 0xa37544ca00000000, - 0x51c18ce300000000, 0xc050e44d00000000, 0xb5a81db000000000, - 0x2439751e00000000, 0xd68dbd3700000000, 0x471cd59900000000, - 0xe34518f100000000, 0x72d4705f00000000, 0x8060b87600000000, - 0x11f1d0d800000000, 0x6409292500000000, 0xf598418b00000000, - 0x072c89a200000000, 0x96bde10c00000000, 0xacda0b8200000000, - 0x3d4b632c00000000, 0xcfffab0500000000, 0x5e6ec3ab00000000, - 0x2b963a5600000000, 0xba0752f800000000, 0x48b39ad100000000, - 0xd922f27f00000000, 0xfaf67e2e00000000, 0x6b67168000000000, - 0x99d3dea900000000, 0x0842b60700000000, 0x7dba4ffa00000000, - 0xec2b275400000000, 0x1e9fef7d00000000, 0x8f0e87d300000000, - 0xb5696d5d00000000, 0x24f805f300000000, 0xd64ccdda00000000, - 0x47dda57400000000, 0x32255c8900000000, 0xa3b4342700000000, - 0x5100fc0e00000000, 0xc09194a000000000, 0x64c859c800000000, - 0xf559316600000000, 0x07edf94f00000000, 0x967c91e100000000, - 0xe384681c00000000, 0x721500b200000000, 0x80a1c89b00000000, - 0x1130a03500000000, 0x2b574abb00000000, 0xbac6221500000000, - 0x4872ea3c00000000, 0xd9e3829200000000, 0xac1b7b6f00000000, - 0x3d8a13c100000000, 0xcf3edbe800000000, 0x5eafb34600000000, - 0x878d413900000000, 0x161c299700000000, 0xe4a8e1be00000000, - 0x7539891000000000, 0x00c170ed00000000, 0x9150184300000000, - 0x63e4d06a00000000, 0xf275b8c400000000, 0xc812524a00000000, - 0x59833ae400000000, 0xab37f2cd00000000, 0x3aa69a6300000000, - 0x4f5e639e00000000, 0xdecf0b3000000000, 0x2c7bc31900000000, - 0xbdeaabb700000000, 0x19b366df00000000, 0x88220e7100000000, - 0x7a96c65800000000, 0xeb07aef600000000, 0x9eff570b00000000, - 0x0f6e3fa500000000, 0xfddaf78c00000000, 0x6c4b9f2200000000, - 0x562c75ac00000000, 0xc7bd1d0200000000, 0x3509d52b00000000, - 0xa498bd8500000000, 0xd160447800000000, 0x40f12cd600000000, - 0xb245e4ff00000000, 0x23d48c5100000000, 0xf4edfd5c00000000, - 0x657c95f200000000, 0x97c85ddb00000000, 0x0659357500000000, - 0x73a1cc8800000000, 0xe230a42600000000, 0x10846c0f00000000, - 0x811504a100000000, 0xbb72ee2f00000000, 0x2ae3868100000000, - 0xd8574ea800000000, 0x49c6260600000000, 0x3c3edffb00000000, - 0xadafb75500000000, 0x5f1b7f7c00000000, 0xce8a17d200000000, - 0x6ad3daba00000000, 0xfb42b21400000000, 0x09f67a3d00000000, - 0x9867129300000000, 0xed9feb6e00000000, 0x7c0e83c000000000, - 0x8eba4be900000000, 0x1f2b234700000000, 0x254cc9c900000000, - 0xb4dda16700000000, 0x4669694e00000000, 0xd7f801e000000000, - 0xa200f81d00000000, 0x339190b300000000, 0xc125589a00000000, - 0x50b4303400000000, 0x8996c24b00000000, 0x1807aae500000000, - 0xeab362cc00000000, 0x7b220a6200000000, 0x0edaf39f00000000, - 0x9f4b9b3100000000, 0x6dff531800000000, 0xfc6e3bb600000000, - 0xc609d13800000000, 0x5798b99600000000, 0xa52c71bf00000000, - 0x34bd191100000000, 0x4145e0ec00000000, 0xd0d4884200000000, - 0x2260406b00000000, 0xb3f128c500000000, 0x17a8e5ad00000000, - 0x86398d0300000000, 0x748d452a00000000, 0xe51c2d8400000000, - 0x90e4d47900000000, 0x0175bcd700000000, 0xf3c174fe00000000, - 0x62501c5000000000, 0x5837f6de00000000, 0xc9a69e7000000000, - 0x3b12565900000000, 0xaa833ef700000000, 0xdf7bc70a00000000, - 0x4eeaafa400000000, 0xbc5e678d00000000, 0x2dcf0f2300000000, - 0x0e1b837200000000, 0x9f8aebdc00000000, 0x6d3e23f500000000, - 0xfcaf4b5b00000000, 0x8957b2a600000000, 0x18c6da0800000000, - 0xea72122100000000, 0x7be37a8f00000000, 0x4184900100000000, - 0xd015f8af00000000, 0x22a1308600000000, 0xb330582800000000, - 0xc6c8a1d500000000, 0x5759c97b00000000, 0xa5ed015200000000, - 0x347c69fc00000000, 0x9025a49400000000, 0x01b4cc3a00000000, - 0xf300041300000000, 0x62916cbd00000000, 0x1769954000000000, - 0x86f8fdee00000000, 0x744c35c700000000, 0xe5dd5d6900000000, - 0xdfbab7e700000000, 0x4e2bdf4900000000, 0xbc9f176000000000, - 0x2d0e7fce00000000, 0x58f6863300000000, 0xc967ee9d00000000, - 0x3bd326b400000000, 0xaa424e1a00000000, 0x7360bc6500000000, - 0xe2f1d4cb00000000, 0x10451ce200000000, 0x81d4744c00000000, - 0xf42c8db100000000, 0x65bde51f00000000, 0x97092d3600000000, - 0x0698459800000000, 0x3cffaf1600000000, 0xad6ec7b800000000, - 0x5fda0f9100000000, 0xce4b673f00000000, 0xbbb39ec200000000, - 0x2a22f66c00000000, 0xd8963e4500000000, 0x490756eb00000000, - 0xed5e9b8300000000, 0x7ccff32d00000000, 0x8e7b3b0400000000, - 0x1fea53aa00000000, 0x6a12aa5700000000, 0xfb83c2f900000000, - 0x09370ad000000000, 0x98a6627e00000000, 0xa2c188f000000000, - 0x3350e05e00000000, 0xc1e4287700000000, 0x507540d900000000, - 0x258db92400000000, 0xb41cd18a00000000, 0x46a819a300000000, - 0xd739710d00000000}}; - -#else /* W == 4 */ - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0xccaa009e, 0x4225077d, 0x8e8f07e3, 0x844a0efa, - 0x48e00e64, 0xc66f0987, 0x0ac50919, 0xd3e51bb5, 0x1f4f1b2b, - 0x91c01cc8, 0x5d6a1c56, 0x57af154f, 0x9b0515d1, 0x158a1232, - 0xd92012ac, 0x7cbb312b, 0xb01131b5, 0x3e9e3656, 0xf23436c8, - 0xf8f13fd1, 0x345b3f4f, 0xbad438ac, 0x767e3832, 0xaf5e2a9e, - 0x63f42a00, 0xed7b2de3, 0x21d12d7d, 0x2b142464, 0xe7be24fa, - 0x69312319, 0xa59b2387, 0xf9766256, 0x35dc62c8, 0xbb53652b, - 0x77f965b5, 0x7d3c6cac, 0xb1966c32, 0x3f196bd1, 0xf3b36b4f, - 0x2a9379e3, 0xe639797d, 0x68b67e9e, 0xa41c7e00, 0xaed97719, - 0x62737787, 0xecfc7064, 0x205670fa, 0x85cd537d, 0x496753e3, - 0xc7e85400, 0x0b42549e, 0x01875d87, 0xcd2d5d19, 0x43a25afa, - 0x8f085a64, 0x562848c8, 0x9a824856, 0x140d4fb5, 0xd8a74f2b, - 0xd2624632, 0x1ec846ac, 0x9047414f, 0x5ced41d1, 0x299dc2ed, - 0xe537c273, 0x6bb8c590, 0xa712c50e, 0xadd7cc17, 0x617dcc89, - 0xeff2cb6a, 0x2358cbf4, 0xfa78d958, 0x36d2d9c6, 0xb85dde25, - 0x74f7debb, 0x7e32d7a2, 0xb298d73c, 0x3c17d0df, 0xf0bdd041, - 0x5526f3c6, 0x998cf358, 0x1703f4bb, 0xdba9f425, 0xd16cfd3c, - 0x1dc6fda2, 0x9349fa41, 0x5fe3fadf, 0x86c3e873, 0x4a69e8ed, - 0xc4e6ef0e, 0x084cef90, 0x0289e689, 0xce23e617, 0x40ace1f4, - 0x8c06e16a, 0xd0eba0bb, 0x1c41a025, 0x92cea7c6, 0x5e64a758, - 0x54a1ae41, 0x980baedf, 0x1684a93c, 0xda2ea9a2, 0x030ebb0e, - 0xcfa4bb90, 0x412bbc73, 0x8d81bced, 0x8744b5f4, 0x4beeb56a, - 0xc561b289, 0x09cbb217, 0xac509190, 0x60fa910e, 0xee7596ed, - 0x22df9673, 0x281a9f6a, 0xe4b09ff4, 0x6a3f9817, 0xa6959889, - 0x7fb58a25, 0xb31f8abb, 0x3d908d58, 0xf13a8dc6, 0xfbff84df, - 0x37558441, 0xb9da83a2, 0x7570833c, 0x533b85da, 0x9f918544, - 0x111e82a7, 0xddb48239, 0xd7718b20, 0x1bdb8bbe, 0x95548c5d, - 0x59fe8cc3, 0x80de9e6f, 0x4c749ef1, 0xc2fb9912, 0x0e51998c, - 0x04949095, 0xc83e900b, 0x46b197e8, 0x8a1b9776, 0x2f80b4f1, - 0xe32ab46f, 0x6da5b38c, 0xa10fb312, 0xabcaba0b, 0x6760ba95, - 0xe9efbd76, 0x2545bde8, 0xfc65af44, 0x30cfafda, 0xbe40a839, - 0x72eaa8a7, 0x782fa1be, 0xb485a120, 0x3a0aa6c3, 0xf6a0a65d, - 0xaa4de78c, 0x66e7e712, 0xe868e0f1, 0x24c2e06f, 0x2e07e976, - 0xe2ade9e8, 0x6c22ee0b, 0xa088ee95, 0x79a8fc39, 0xb502fca7, - 0x3b8dfb44, 0xf727fbda, 0xfde2f2c3, 0x3148f25d, 0xbfc7f5be, - 0x736df520, 0xd6f6d6a7, 0x1a5cd639, 0x94d3d1da, 0x5879d144, - 0x52bcd85d, 0x9e16d8c3, 0x1099df20, 0xdc33dfbe, 0x0513cd12, - 0xc9b9cd8c, 0x4736ca6f, 0x8b9ccaf1, 0x8159c3e8, 0x4df3c376, - 0xc37cc495, 0x0fd6c40b, 0x7aa64737, 0xb60c47a9, 0x3883404a, - 0xf42940d4, 0xfeec49cd, 0x32464953, 0xbcc94eb0, 0x70634e2e, - 0xa9435c82, 0x65e95c1c, 0xeb665bff, 0x27cc5b61, 0x2d095278, - 0xe1a352e6, 0x6f2c5505, 0xa386559b, 0x061d761c, 0xcab77682, - 0x44387161, 0x889271ff, 0x825778e6, 0x4efd7878, 0xc0727f9b, - 0x0cd87f05, 0xd5f86da9, 0x19526d37, 0x97dd6ad4, 0x5b776a4a, - 0x51b26353, 0x9d1863cd, 0x1397642e, 0xdf3d64b0, 0x83d02561, - 0x4f7a25ff, 0xc1f5221c, 0x0d5f2282, 0x079a2b9b, 0xcb302b05, - 0x45bf2ce6, 0x89152c78, 0x50353ed4, 0x9c9f3e4a, 0x121039a9, - 0xdeba3937, 0xd47f302e, 0x18d530b0, 0x965a3753, 0x5af037cd, - 0xff6b144a, 0x33c114d4, 0xbd4e1337, 0x71e413a9, 0x7b211ab0, - 0xb78b1a2e, 0x39041dcd, 0xf5ae1d53, 0x2c8e0fff, 0xe0240f61, - 0x6eab0882, 0xa201081c, 0xa8c40105, 0x646e019b, 0xeae10678, - 0x264b06e6}, - {0x00000000, 0xa6770bb4, 0x979f1129, 0x31e81a9d, 0xf44f2413, - 0x52382fa7, 0x63d0353a, 0xc5a73e8e, 0x33ef4e67, 0x959845d3, - 0xa4705f4e, 0x020754fa, 0xc7a06a74, 0x61d761c0, 0x503f7b5d, - 0xf64870e9, 0x67de9cce, 0xc1a9977a, 0xf0418de7, 0x56368653, - 0x9391b8dd, 0x35e6b369, 0x040ea9f4, 0xa279a240, 0x5431d2a9, - 0xf246d91d, 0xc3aec380, 0x65d9c834, 0xa07ef6ba, 0x0609fd0e, - 0x37e1e793, 0x9196ec27, 0xcfbd399c, 0x69ca3228, 0x582228b5, - 0xfe552301, 0x3bf21d8f, 0x9d85163b, 0xac6d0ca6, 0x0a1a0712, - 0xfc5277fb, 0x5a257c4f, 0x6bcd66d2, 0xcdba6d66, 0x081d53e8, - 0xae6a585c, 0x9f8242c1, 0x39f54975, 0xa863a552, 0x0e14aee6, - 0x3ffcb47b, 0x998bbfcf, 0x5c2c8141, 0xfa5b8af5, 0xcbb39068, - 0x6dc49bdc, 0x9b8ceb35, 0x3dfbe081, 0x0c13fa1c, 0xaa64f1a8, - 0x6fc3cf26, 0xc9b4c492, 0xf85cde0f, 0x5e2bd5bb, 0x440b7579, - 0xe27c7ecd, 0xd3946450, 0x75e36fe4, 0xb044516a, 0x16335ade, - 0x27db4043, 0x81ac4bf7, 0x77e43b1e, 0xd19330aa, 0xe07b2a37, - 0x460c2183, 0x83ab1f0d, 0x25dc14b9, 0x14340e24, 0xb2430590, - 0x23d5e9b7, 0x85a2e203, 0xb44af89e, 0x123df32a, 0xd79acda4, - 0x71edc610, 0x4005dc8d, 0xe672d739, 0x103aa7d0, 0xb64dac64, - 0x87a5b6f9, 0x21d2bd4d, 0xe47583c3, 0x42028877, 0x73ea92ea, - 0xd59d995e, 0x8bb64ce5, 0x2dc14751, 0x1c295dcc, 0xba5e5678, - 0x7ff968f6, 0xd98e6342, 0xe86679df, 0x4e11726b, 0xb8590282, - 0x1e2e0936, 0x2fc613ab, 0x89b1181f, 0x4c162691, 0xea612d25, - 0xdb8937b8, 0x7dfe3c0c, 0xec68d02b, 0x4a1fdb9f, 0x7bf7c102, - 0xdd80cab6, 0x1827f438, 0xbe50ff8c, 0x8fb8e511, 0x29cfeea5, - 0xdf879e4c, 0x79f095f8, 0x48188f65, 0xee6f84d1, 0x2bc8ba5f, - 0x8dbfb1eb, 0xbc57ab76, 0x1a20a0c2, 0x8816eaf2, 0x2e61e146, - 0x1f89fbdb, 0xb9fef06f, 0x7c59cee1, 0xda2ec555, 0xebc6dfc8, - 0x4db1d47c, 0xbbf9a495, 0x1d8eaf21, 0x2c66b5bc, 0x8a11be08, - 0x4fb68086, 0xe9c18b32, 0xd82991af, 0x7e5e9a1b, 0xefc8763c, - 0x49bf7d88, 0x78576715, 0xde206ca1, 0x1b87522f, 0xbdf0599b, - 0x8c184306, 0x2a6f48b2, 0xdc27385b, 0x7a5033ef, 0x4bb82972, - 0xedcf22c6, 0x28681c48, 0x8e1f17fc, 0xbff70d61, 0x198006d5, - 0x47abd36e, 0xe1dcd8da, 0xd034c247, 0x7643c9f3, 0xb3e4f77d, - 0x1593fcc9, 0x247be654, 0x820cede0, 0x74449d09, 0xd23396bd, - 0xe3db8c20, 0x45ac8794, 0x800bb91a, 0x267cb2ae, 0x1794a833, - 0xb1e3a387, 0x20754fa0, 0x86024414, 0xb7ea5e89, 0x119d553d, - 0xd43a6bb3, 0x724d6007, 0x43a57a9a, 0xe5d2712e, 0x139a01c7, - 0xb5ed0a73, 0x840510ee, 0x22721b5a, 0xe7d525d4, 0x41a22e60, - 0x704a34fd, 0xd63d3f49, 0xcc1d9f8b, 0x6a6a943f, 0x5b828ea2, - 0xfdf58516, 0x3852bb98, 0x9e25b02c, 0xafcdaab1, 0x09baa105, - 0xfff2d1ec, 0x5985da58, 0x686dc0c5, 0xce1acb71, 0x0bbdf5ff, - 0xadcafe4b, 0x9c22e4d6, 0x3a55ef62, 0xabc30345, 0x0db408f1, - 0x3c5c126c, 0x9a2b19d8, 0x5f8c2756, 0xf9fb2ce2, 0xc813367f, - 0x6e643dcb, 0x982c4d22, 0x3e5b4696, 0x0fb35c0b, 0xa9c457bf, - 0x6c636931, 0xca146285, 0xfbfc7818, 0x5d8b73ac, 0x03a0a617, - 0xa5d7ada3, 0x943fb73e, 0x3248bc8a, 0xf7ef8204, 0x519889b0, - 0x6070932d, 0xc6079899, 0x304fe870, 0x9638e3c4, 0xa7d0f959, - 0x01a7f2ed, 0xc400cc63, 0x6277c7d7, 0x539fdd4a, 0xf5e8d6fe, - 0x647e3ad9, 0xc209316d, 0xf3e12bf0, 0x55962044, 0x90311eca, - 0x3646157e, 0x07ae0fe3, 0xa1d90457, 0x579174be, 0xf1e67f0a, - 0xc00e6597, 0x66796e23, 0xa3de50ad, 0x05a95b19, 0x34414184, - 0x92364a30}, - {0x00000000, 0xcb5cd3a5, 0x4dc8a10b, 0x869472ae, 0x9b914216, - 0x50cd91b3, 0xd659e31d, 0x1d0530b8, 0xec53826d, 0x270f51c8, - 0xa19b2366, 0x6ac7f0c3, 0x77c2c07b, 0xbc9e13de, 0x3a0a6170, - 0xf156b2d5, 0x03d6029b, 0xc88ad13e, 0x4e1ea390, 0x85427035, - 0x9847408d, 0x531b9328, 0xd58fe186, 0x1ed33223, 0xef8580f6, - 0x24d95353, 0xa24d21fd, 0x6911f258, 0x7414c2e0, 0xbf481145, - 0x39dc63eb, 0xf280b04e, 0x07ac0536, 0xccf0d693, 0x4a64a43d, - 0x81387798, 0x9c3d4720, 0x57619485, 0xd1f5e62b, 0x1aa9358e, - 0xebff875b, 0x20a354fe, 0xa6372650, 0x6d6bf5f5, 0x706ec54d, - 0xbb3216e8, 0x3da66446, 0xf6fab7e3, 0x047a07ad, 0xcf26d408, - 0x49b2a6a6, 0x82ee7503, 0x9feb45bb, 0x54b7961e, 0xd223e4b0, - 0x197f3715, 0xe82985c0, 0x23755665, 0xa5e124cb, 0x6ebdf76e, - 0x73b8c7d6, 0xb8e41473, 0x3e7066dd, 0xf52cb578, 0x0f580a6c, - 0xc404d9c9, 0x4290ab67, 0x89cc78c2, 0x94c9487a, 0x5f959bdf, - 0xd901e971, 0x125d3ad4, 0xe30b8801, 0x28575ba4, 0xaec3290a, - 0x659ffaaf, 0x789aca17, 0xb3c619b2, 0x35526b1c, 0xfe0eb8b9, - 0x0c8e08f7, 0xc7d2db52, 0x4146a9fc, 0x8a1a7a59, 0x971f4ae1, - 0x5c439944, 0xdad7ebea, 0x118b384f, 0xe0dd8a9a, 0x2b81593f, - 0xad152b91, 0x6649f834, 0x7b4cc88c, 0xb0101b29, 0x36846987, - 0xfdd8ba22, 0x08f40f5a, 0xc3a8dcff, 0x453cae51, 0x8e607df4, - 0x93654d4c, 0x58399ee9, 0xdeadec47, 0x15f13fe2, 0xe4a78d37, - 0x2ffb5e92, 0xa96f2c3c, 0x6233ff99, 0x7f36cf21, 0xb46a1c84, - 0x32fe6e2a, 0xf9a2bd8f, 0x0b220dc1, 0xc07ede64, 0x46eaacca, - 0x8db67f6f, 0x90b34fd7, 0x5bef9c72, 0xdd7beedc, 0x16273d79, - 0xe7718fac, 0x2c2d5c09, 0xaab92ea7, 0x61e5fd02, 0x7ce0cdba, - 0xb7bc1e1f, 0x31286cb1, 0xfa74bf14, 0x1eb014d8, 0xd5ecc77d, - 0x5378b5d3, 0x98246676, 0x852156ce, 0x4e7d856b, 0xc8e9f7c5, - 0x03b52460, 0xf2e396b5, 0x39bf4510, 0xbf2b37be, 0x7477e41b, - 0x6972d4a3, 0xa22e0706, 0x24ba75a8, 0xefe6a60d, 0x1d661643, - 0xd63ac5e6, 0x50aeb748, 0x9bf264ed, 0x86f75455, 0x4dab87f0, - 0xcb3ff55e, 0x006326fb, 0xf135942e, 0x3a69478b, 0xbcfd3525, - 0x77a1e680, 0x6aa4d638, 0xa1f8059d, 0x276c7733, 0xec30a496, - 0x191c11ee, 0xd240c24b, 0x54d4b0e5, 0x9f886340, 0x828d53f8, - 0x49d1805d, 0xcf45f2f3, 0x04192156, 0xf54f9383, 0x3e134026, - 0xb8873288, 0x73dbe12d, 0x6eded195, 0xa5820230, 0x2316709e, - 0xe84aa33b, 0x1aca1375, 0xd196c0d0, 0x5702b27e, 0x9c5e61db, - 0x815b5163, 0x4a0782c6, 0xcc93f068, 0x07cf23cd, 0xf6999118, - 0x3dc542bd, 0xbb513013, 0x700de3b6, 0x6d08d30e, 0xa65400ab, - 0x20c07205, 0xeb9ca1a0, 0x11e81eb4, 0xdab4cd11, 0x5c20bfbf, - 0x977c6c1a, 0x8a795ca2, 0x41258f07, 0xc7b1fda9, 0x0ced2e0c, - 0xfdbb9cd9, 0x36e74f7c, 0xb0733dd2, 0x7b2fee77, 0x662adecf, - 0xad760d6a, 0x2be27fc4, 0xe0beac61, 0x123e1c2f, 0xd962cf8a, - 0x5ff6bd24, 0x94aa6e81, 0x89af5e39, 0x42f38d9c, 0xc467ff32, - 0x0f3b2c97, 0xfe6d9e42, 0x35314de7, 0xb3a53f49, 0x78f9ecec, - 0x65fcdc54, 0xaea00ff1, 0x28347d5f, 0xe368aefa, 0x16441b82, - 0xdd18c827, 0x5b8cba89, 0x90d0692c, 0x8dd55994, 0x46898a31, - 0xc01df89f, 0x0b412b3a, 0xfa1799ef, 0x314b4a4a, 0xb7df38e4, - 0x7c83eb41, 0x6186dbf9, 0xaada085c, 0x2c4e7af2, 0xe712a957, - 0x15921919, 0xdececabc, 0x585ab812, 0x93066bb7, 0x8e035b0f, - 0x455f88aa, 0xc3cbfa04, 0x089729a1, 0xf9c19b74, 0x329d48d1, - 0xb4093a7f, 0x7f55e9da, 0x6250d962, 0xa90c0ac7, 0x2f987869, - 0xe4c4abcc}, - {0x00000000, 0x3d6029b0, 0x7ac05360, 0x47a07ad0, 0xf580a6c0, - 0xc8e08f70, 0x8f40f5a0, 0xb220dc10, 0x30704bc1, 0x0d106271, - 0x4ab018a1, 0x77d03111, 0xc5f0ed01, 0xf890c4b1, 0xbf30be61, - 0x825097d1, 0x60e09782, 0x5d80be32, 0x1a20c4e2, 0x2740ed52, - 0x95603142, 0xa80018f2, 0xefa06222, 0xd2c04b92, 0x5090dc43, - 0x6df0f5f3, 0x2a508f23, 0x1730a693, 0xa5107a83, 0x98705333, - 0xdfd029e3, 0xe2b00053, 0xc1c12f04, 0xfca106b4, 0xbb017c64, - 0x866155d4, 0x344189c4, 0x0921a074, 0x4e81daa4, 0x73e1f314, - 0xf1b164c5, 0xccd14d75, 0x8b7137a5, 0xb6111e15, 0x0431c205, - 0x3951ebb5, 0x7ef19165, 0x4391b8d5, 0xa121b886, 0x9c419136, - 0xdbe1ebe6, 0xe681c256, 0x54a11e46, 0x69c137f6, 0x2e614d26, - 0x13016496, 0x9151f347, 0xac31daf7, 0xeb91a027, 0xd6f18997, - 0x64d15587, 0x59b17c37, 0x1e1106e7, 0x23712f57, 0x58f35849, - 0x659371f9, 0x22330b29, 0x1f532299, 0xad73fe89, 0x9013d739, - 0xd7b3ade9, 0xead38459, 0x68831388, 0x55e33a38, 0x124340e8, - 0x2f236958, 0x9d03b548, 0xa0639cf8, 0xe7c3e628, 0xdaa3cf98, - 0x3813cfcb, 0x0573e67b, 0x42d39cab, 0x7fb3b51b, 0xcd93690b, - 0xf0f340bb, 0xb7533a6b, 0x8a3313db, 0x0863840a, 0x3503adba, - 0x72a3d76a, 0x4fc3feda, 0xfde322ca, 0xc0830b7a, 0x872371aa, - 0xba43581a, 0x9932774d, 0xa4525efd, 0xe3f2242d, 0xde920d9d, - 0x6cb2d18d, 0x51d2f83d, 0x167282ed, 0x2b12ab5d, 0xa9423c8c, - 0x9422153c, 0xd3826fec, 0xeee2465c, 0x5cc29a4c, 0x61a2b3fc, - 0x2602c92c, 0x1b62e09c, 0xf9d2e0cf, 0xc4b2c97f, 0x8312b3af, - 0xbe729a1f, 0x0c52460f, 0x31326fbf, 0x7692156f, 0x4bf23cdf, - 0xc9a2ab0e, 0xf4c282be, 0xb362f86e, 0x8e02d1de, 0x3c220dce, - 0x0142247e, 0x46e25eae, 0x7b82771e, 0xb1e6b092, 0x8c869922, - 0xcb26e3f2, 0xf646ca42, 0x44661652, 0x79063fe2, 0x3ea64532, - 0x03c66c82, 0x8196fb53, 0xbcf6d2e3, 0xfb56a833, 0xc6368183, - 0x74165d93, 0x49767423, 0x0ed60ef3, 0x33b62743, 0xd1062710, - 0xec660ea0, 0xabc67470, 0x96a65dc0, 0x248681d0, 0x19e6a860, - 0x5e46d2b0, 0x6326fb00, 0xe1766cd1, 0xdc164561, 0x9bb63fb1, - 0xa6d61601, 0x14f6ca11, 0x2996e3a1, 0x6e369971, 0x5356b0c1, - 0x70279f96, 0x4d47b626, 0x0ae7ccf6, 0x3787e546, 0x85a73956, - 0xb8c710e6, 0xff676a36, 0xc2074386, 0x4057d457, 0x7d37fde7, - 0x3a978737, 0x07f7ae87, 0xb5d77297, 0x88b75b27, 0xcf1721f7, - 0xf2770847, 0x10c70814, 0x2da721a4, 0x6a075b74, 0x576772c4, - 0xe547aed4, 0xd8278764, 0x9f87fdb4, 0xa2e7d404, 0x20b743d5, - 0x1dd76a65, 0x5a7710b5, 0x67173905, 0xd537e515, 0xe857cca5, - 0xaff7b675, 0x92979fc5, 0xe915e8db, 0xd475c16b, 0x93d5bbbb, - 0xaeb5920b, 0x1c954e1b, 0x21f567ab, 0x66551d7b, 0x5b3534cb, - 0xd965a31a, 0xe4058aaa, 0xa3a5f07a, 0x9ec5d9ca, 0x2ce505da, - 0x11852c6a, 0x562556ba, 0x6b457f0a, 0x89f57f59, 0xb49556e9, - 0xf3352c39, 0xce550589, 0x7c75d999, 0x4115f029, 0x06b58af9, - 0x3bd5a349, 0xb9853498, 0x84e51d28, 0xc34567f8, 0xfe254e48, - 0x4c059258, 0x7165bbe8, 0x36c5c138, 0x0ba5e888, 0x28d4c7df, - 0x15b4ee6f, 0x521494bf, 0x6f74bd0f, 0xdd54611f, 0xe03448af, - 0xa794327f, 0x9af41bcf, 0x18a48c1e, 0x25c4a5ae, 0x6264df7e, - 0x5f04f6ce, 0xed242ade, 0xd044036e, 0x97e479be, 0xaa84500e, - 0x4834505d, 0x755479ed, 0x32f4033d, 0x0f942a8d, 0xbdb4f69d, - 0x80d4df2d, 0xc774a5fd, 0xfa148c4d, 0x78441b9c, 0x4524322c, - 0x028448fc, 0x3fe4614c, 0x8dc4bd5c, 0xb0a494ec, 0xf704ee3c, - 0xca64c78c}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x00000000, 0xb029603d, 0x6053c07a, 0xd07aa047, 0xc0a680f5, - 0x708fe0c8, 0xa0f5408f, 0x10dc20b2, 0xc14b7030, 0x7162100d, - 0xa118b04a, 0x1131d077, 0x01edf0c5, 0xb1c490f8, 0x61be30bf, - 0xd1975082, 0x8297e060, 0x32be805d, 0xe2c4201a, 0x52ed4027, - 0x42316095, 0xf21800a8, 0x2262a0ef, 0x924bc0d2, 0x43dc9050, - 0xf3f5f06d, 0x238f502a, 0x93a63017, 0x837a10a5, 0x33537098, - 0xe329d0df, 0x5300b0e2, 0x042fc1c1, 0xb406a1fc, 0x647c01bb, - 0xd4556186, 0xc4894134, 0x74a02109, 0xa4da814e, 0x14f3e173, - 0xc564b1f1, 0x754dd1cc, 0xa537718b, 0x151e11b6, 0x05c23104, - 0xb5eb5139, 0x6591f17e, 0xd5b89143, 0x86b821a1, 0x3691419c, - 0xe6ebe1db, 0x56c281e6, 0x461ea154, 0xf637c169, 0x264d612e, - 0x96640113, 0x47f35191, 0xf7da31ac, 0x27a091eb, 0x9789f1d6, - 0x8755d164, 0x377cb159, 0xe706111e, 0x572f7123, 0x4958f358, - 0xf9719365, 0x290b3322, 0x9922531f, 0x89fe73ad, 0x39d71390, - 0xe9adb3d7, 0x5984d3ea, 0x88138368, 0x383ae355, 0xe8404312, - 0x5869232f, 0x48b5039d, 0xf89c63a0, 0x28e6c3e7, 0x98cfa3da, - 0xcbcf1338, 0x7be67305, 0xab9cd342, 0x1bb5b37f, 0x0b6993cd, - 0xbb40f3f0, 0x6b3a53b7, 0xdb13338a, 0x0a846308, 0xbaad0335, - 0x6ad7a372, 0xdafec34f, 0xca22e3fd, 0x7a0b83c0, 0xaa712387, - 0x1a5843ba, 0x4d773299, 0xfd5e52a4, 0x2d24f2e3, 0x9d0d92de, - 0x8dd1b26c, 0x3df8d251, 0xed827216, 0x5dab122b, 0x8c3c42a9, - 0x3c152294, 0xec6f82d3, 0x5c46e2ee, 0x4c9ac25c, 0xfcb3a261, - 0x2cc90226, 0x9ce0621b, 0xcfe0d2f9, 0x7fc9b2c4, 0xafb31283, - 0x1f9a72be, 0x0f46520c, 0xbf6f3231, 0x6f159276, 0xdf3cf24b, - 0x0eaba2c9, 0xbe82c2f4, 0x6ef862b3, 0xded1028e, 0xce0d223c, - 0x7e244201, 0xae5ee246, 0x1e77827b, 0x92b0e6b1, 0x2299868c, - 0xf2e326cb, 0x42ca46f6, 0x52166644, 0xe23f0679, 0x3245a63e, - 0x826cc603, 0x53fb9681, 0xe3d2f6bc, 0x33a856fb, 0x838136c6, - 0x935d1674, 0x23747649, 0xf30ed60e, 0x4327b633, 0x102706d1, - 0xa00e66ec, 0x7074c6ab, 0xc05da696, 0xd0818624, 0x60a8e619, - 0xb0d2465e, 0x00fb2663, 0xd16c76e1, 0x614516dc, 0xb13fb69b, - 0x0116d6a6, 0x11caf614, 0xa1e39629, 0x7199366e, 0xc1b05653, - 0x969f2770, 0x26b6474d, 0xf6cce70a, 0x46e58737, 0x5639a785, - 0xe610c7b8, 0x366a67ff, 0x864307c2, 0x57d45740, 0xe7fd377d, - 0x3787973a, 0x87aef707, 0x9772d7b5, 0x275bb788, 0xf72117cf, - 0x470877f2, 0x1408c710, 0xa421a72d, 0x745b076a, 0xc4726757, - 0xd4ae47e5, 0x648727d8, 0xb4fd879f, 0x04d4e7a2, 0xd543b720, - 0x656ad71d, 0xb510775a, 0x05391767, 0x15e537d5, 0xa5cc57e8, - 0x75b6f7af, 0xc59f9792, 0xdbe815e9, 0x6bc175d4, 0xbbbbd593, - 0x0b92b5ae, 0x1b4e951c, 0xab67f521, 0x7b1d5566, 0xcb34355b, - 0x1aa365d9, 0xaa8a05e4, 0x7af0a5a3, 0xcad9c59e, 0xda05e52c, - 0x6a2c8511, 0xba562556, 0x0a7f456b, 0x597ff589, 0xe95695b4, - 0x392c35f3, 0x890555ce, 0x99d9757c, 0x29f01541, 0xf98ab506, - 0x49a3d53b, 0x983485b9, 0x281de584, 0xf86745c3, 0x484e25fe, - 0x5892054c, 0xe8bb6571, 0x38c1c536, 0x88e8a50b, 0xdfc7d428, - 0x6feeb415, 0xbf941452, 0x0fbd746f, 0x1f6154dd, 0xaf4834e0, - 0x7f3294a7, 0xcf1bf49a, 0x1e8ca418, 0xaea5c425, 0x7edf6462, - 0xcef6045f, 0xde2a24ed, 0x6e0344d0, 0xbe79e497, 0x0e5084aa, - 0x5d503448, 0xed795475, 0x3d03f432, 0x8d2a940f, 0x9df6b4bd, - 0x2ddfd480, 0xfda574c7, 0x4d8c14fa, 0x9c1b4478, 0x2c322445, - 0xfc488402, 0x4c61e43f, 0x5cbdc48d, 0xec94a4b0, 0x3cee04f7, - 0x8cc764ca}, - {0x00000000, 0xa5d35ccb, 0x0ba1c84d, 0xae729486, 0x1642919b, - 0xb391cd50, 0x1de359d6, 0xb830051d, 0x6d8253ec, 0xc8510f27, - 0x66239ba1, 0xc3f0c76a, 0x7bc0c277, 0xde139ebc, 0x70610a3a, - 0xd5b256f1, 0x9b02d603, 0x3ed18ac8, 0x90a31e4e, 0x35704285, - 0x8d404798, 0x28931b53, 0x86e18fd5, 0x2332d31e, 0xf68085ef, - 0x5353d924, 0xfd214da2, 0x58f21169, 0xe0c21474, 0x451148bf, - 0xeb63dc39, 0x4eb080f2, 0x3605ac07, 0x93d6f0cc, 0x3da4644a, - 0x98773881, 0x20473d9c, 0x85946157, 0x2be6f5d1, 0x8e35a91a, - 0x5b87ffeb, 0xfe54a320, 0x502637a6, 0xf5f56b6d, 0x4dc56e70, - 0xe81632bb, 0x4664a63d, 0xe3b7faf6, 0xad077a04, 0x08d426cf, - 0xa6a6b249, 0x0375ee82, 0xbb45eb9f, 0x1e96b754, 0xb0e423d2, - 0x15377f19, 0xc08529e8, 0x65567523, 0xcb24e1a5, 0x6ef7bd6e, - 0xd6c7b873, 0x7314e4b8, 0xdd66703e, 0x78b52cf5, 0x6c0a580f, - 0xc9d904c4, 0x67ab9042, 0xc278cc89, 0x7a48c994, 0xdf9b955f, - 0x71e901d9, 0xd43a5d12, 0x01880be3, 0xa45b5728, 0x0a29c3ae, - 0xaffa9f65, 0x17ca9a78, 0xb219c6b3, 0x1c6b5235, 0xb9b80efe, - 0xf7088e0c, 0x52dbd2c7, 0xfca94641, 0x597a1a8a, 0xe14a1f97, - 0x4499435c, 0xeaebd7da, 0x4f388b11, 0x9a8adde0, 0x3f59812b, - 0x912b15ad, 0x34f84966, 0x8cc84c7b, 0x291b10b0, 0x87698436, - 0x22bad8fd, 0x5a0ff408, 0xffdca8c3, 0x51ae3c45, 0xf47d608e, - 0x4c4d6593, 0xe99e3958, 0x47ecadde, 0xe23ff115, 0x378da7e4, - 0x925efb2f, 0x3c2c6fa9, 0x99ff3362, 0x21cf367f, 0x841c6ab4, - 0x2a6efe32, 0x8fbda2f9, 0xc10d220b, 0x64de7ec0, 0xcaacea46, - 0x6f7fb68d, 0xd74fb390, 0x729cef5b, 0xdcee7bdd, 0x793d2716, - 0xac8f71e7, 0x095c2d2c, 0xa72eb9aa, 0x02fde561, 0xbacde07c, - 0x1f1ebcb7, 0xb16c2831, 0x14bf74fa, 0xd814b01e, 0x7dc7ecd5, - 0xd3b57853, 0x76662498, 0xce562185, 0x6b857d4e, 0xc5f7e9c8, - 0x6024b503, 0xb596e3f2, 0x1045bf39, 0xbe372bbf, 0x1be47774, - 0xa3d47269, 0x06072ea2, 0xa875ba24, 0x0da6e6ef, 0x4316661d, - 0xe6c53ad6, 0x48b7ae50, 0xed64f29b, 0x5554f786, 0xf087ab4d, - 0x5ef53fcb, 0xfb266300, 0x2e9435f1, 0x8b47693a, 0x2535fdbc, - 0x80e6a177, 0x38d6a46a, 0x9d05f8a1, 0x33776c27, 0x96a430ec, - 0xee111c19, 0x4bc240d2, 0xe5b0d454, 0x4063889f, 0xf8538d82, - 0x5d80d149, 0xf3f245cf, 0x56211904, 0x83934ff5, 0x2640133e, - 0x883287b8, 0x2de1db73, 0x95d1de6e, 0x300282a5, 0x9e701623, - 0x3ba34ae8, 0x7513ca1a, 0xd0c096d1, 0x7eb20257, 0xdb615e9c, - 0x63515b81, 0xc682074a, 0x68f093cc, 0xcd23cf07, 0x189199f6, - 0xbd42c53d, 0x133051bb, 0xb6e30d70, 0x0ed3086d, 0xab0054a6, - 0x0572c020, 0xa0a19ceb, 0xb41ee811, 0x11cdb4da, 0xbfbf205c, - 0x1a6c7c97, 0xa25c798a, 0x078f2541, 0xa9fdb1c7, 0x0c2eed0c, - 0xd99cbbfd, 0x7c4fe736, 0xd23d73b0, 0x77ee2f7b, 0xcfde2a66, - 0x6a0d76ad, 0xc47fe22b, 0x61acbee0, 0x2f1c3e12, 0x8acf62d9, - 0x24bdf65f, 0x816eaa94, 0x395eaf89, 0x9c8df342, 0x32ff67c4, - 0x972c3b0f, 0x429e6dfe, 0xe74d3135, 0x493fa5b3, 0xececf978, - 0x54dcfc65, 0xf10fa0ae, 0x5f7d3428, 0xfaae68e3, 0x821b4416, - 0x27c818dd, 0x89ba8c5b, 0x2c69d090, 0x9459d58d, 0x318a8946, - 0x9ff81dc0, 0x3a2b410b, 0xef9917fa, 0x4a4a4b31, 0xe438dfb7, - 0x41eb837c, 0xf9db8661, 0x5c08daaa, 0xf27a4e2c, 0x57a912e7, - 0x19199215, 0xbccacede, 0x12b85a58, 0xb76b0693, 0x0f5b038e, - 0xaa885f45, 0x04facbc3, 0xa1299708, 0x749bc1f9, 0xd1489d32, - 0x7f3a09b4, 0xdae9557f, 0x62d95062, 0xc70a0ca9, 0x6978982f, - 0xccabc4e4}, - {0x00000000, 0xb40b77a6, 0x29119f97, 0x9d1ae831, 0x13244ff4, - 0xa72f3852, 0x3a35d063, 0x8e3ea7c5, 0x674eef33, 0xd3459895, - 0x4e5f70a4, 0xfa540702, 0x746aa0c7, 0xc061d761, 0x5d7b3f50, - 0xe97048f6, 0xce9cde67, 0x7a97a9c1, 0xe78d41f0, 0x53863656, - 0xddb89193, 0x69b3e635, 0xf4a90e04, 0x40a279a2, 0xa9d23154, - 0x1dd946f2, 0x80c3aec3, 0x34c8d965, 0xbaf67ea0, 0x0efd0906, - 0x93e7e137, 0x27ec9691, 0x9c39bdcf, 0x2832ca69, 0xb5282258, - 0x012355fe, 0x8f1df23b, 0x3b16859d, 0xa60c6dac, 0x12071a0a, - 0xfb7752fc, 0x4f7c255a, 0xd266cd6b, 0x666dbacd, 0xe8531d08, - 0x5c586aae, 0xc142829f, 0x7549f539, 0x52a563a8, 0xe6ae140e, - 0x7bb4fc3f, 0xcfbf8b99, 0x41812c5c, 0xf58a5bfa, 0x6890b3cb, - 0xdc9bc46d, 0x35eb8c9b, 0x81e0fb3d, 0x1cfa130c, 0xa8f164aa, - 0x26cfc36f, 0x92c4b4c9, 0x0fde5cf8, 0xbbd52b5e, 0x79750b44, - 0xcd7e7ce2, 0x506494d3, 0xe46fe375, 0x6a5144b0, 0xde5a3316, - 0x4340db27, 0xf74bac81, 0x1e3be477, 0xaa3093d1, 0x372a7be0, - 0x83210c46, 0x0d1fab83, 0xb914dc25, 0x240e3414, 0x900543b2, - 0xb7e9d523, 0x03e2a285, 0x9ef84ab4, 0x2af33d12, 0xa4cd9ad7, - 0x10c6ed71, 0x8ddc0540, 0x39d772e6, 0xd0a73a10, 0x64ac4db6, - 0xf9b6a587, 0x4dbdd221, 0xc38375e4, 0x77880242, 0xea92ea73, - 0x5e999dd5, 0xe54cb68b, 0x5147c12d, 0xcc5d291c, 0x78565eba, - 0xf668f97f, 0x42638ed9, 0xdf7966e8, 0x6b72114e, 0x820259b8, - 0x36092e1e, 0xab13c62f, 0x1f18b189, 0x9126164c, 0x252d61ea, - 0xb83789db, 0x0c3cfe7d, 0x2bd068ec, 0x9fdb1f4a, 0x02c1f77b, - 0xb6ca80dd, 0x38f42718, 0x8cff50be, 0x11e5b88f, 0xa5eecf29, - 0x4c9e87df, 0xf895f079, 0x658f1848, 0xd1846fee, 0x5fbac82b, - 0xebb1bf8d, 0x76ab57bc, 0xc2a0201a, 0xf2ea1688, 0x46e1612e, - 0xdbfb891f, 0x6ff0feb9, 0xe1ce597c, 0x55c52eda, 0xc8dfc6eb, - 0x7cd4b14d, 0x95a4f9bb, 0x21af8e1d, 0xbcb5662c, 0x08be118a, - 0x8680b64f, 0x328bc1e9, 0xaf9129d8, 0x1b9a5e7e, 0x3c76c8ef, - 0x887dbf49, 0x15675778, 0xa16c20de, 0x2f52871b, 0x9b59f0bd, - 0x0643188c, 0xb2486f2a, 0x5b3827dc, 0xef33507a, 0x7229b84b, - 0xc622cfed, 0x481c6828, 0xfc171f8e, 0x610df7bf, 0xd5068019, - 0x6ed3ab47, 0xdad8dce1, 0x47c234d0, 0xf3c94376, 0x7df7e4b3, - 0xc9fc9315, 0x54e67b24, 0xe0ed0c82, 0x099d4474, 0xbd9633d2, - 0x208cdbe3, 0x9487ac45, 0x1ab90b80, 0xaeb27c26, 0x33a89417, - 0x87a3e3b1, 0xa04f7520, 0x14440286, 0x895eeab7, 0x3d559d11, - 0xb36b3ad4, 0x07604d72, 0x9a7aa543, 0x2e71d2e5, 0xc7019a13, - 0x730aedb5, 0xee100584, 0x5a1b7222, 0xd425d5e7, 0x602ea241, - 0xfd344a70, 0x493f3dd6, 0x8b9f1dcc, 0x3f946a6a, 0xa28e825b, - 0x1685f5fd, 0x98bb5238, 0x2cb0259e, 0xb1aacdaf, 0x05a1ba09, - 0xecd1f2ff, 0x58da8559, 0xc5c06d68, 0x71cb1ace, 0xfff5bd0b, - 0x4bfecaad, 0xd6e4229c, 0x62ef553a, 0x4503c3ab, 0xf108b40d, - 0x6c125c3c, 0xd8192b9a, 0x56278c5f, 0xe22cfbf9, 0x7f3613c8, - 0xcb3d646e, 0x224d2c98, 0x96465b3e, 0x0b5cb30f, 0xbf57c4a9, - 0x3169636c, 0x856214ca, 0x1878fcfb, 0xac738b5d, 0x17a6a003, - 0xa3add7a5, 0x3eb73f94, 0x8abc4832, 0x0482eff7, 0xb0899851, - 0x2d937060, 0x999807c6, 0x70e84f30, 0xc4e33896, 0x59f9d0a7, - 0xedf2a701, 0x63cc00c4, 0xd7c77762, 0x4add9f53, 0xfed6e8f5, - 0xd93a7e64, 0x6d3109c2, 0xf02be1f3, 0x44209655, 0xca1e3190, - 0x7e154636, 0xe30fae07, 0x5704d9a1, 0xbe749157, 0x0a7fe6f1, - 0x97650ec0, 0x236e7966, 0xad50dea3, 0x195ba905, 0x84414134, - 0x304a3692}, - {0x00000000, 0x9e00aacc, 0x7d072542, 0xe3078f8e, 0xfa0e4a84, - 0x640ee048, 0x87096fc6, 0x1909c50a, 0xb51be5d3, 0x2b1b4f1f, - 0xc81cc091, 0x561c6a5d, 0x4f15af57, 0xd115059b, 0x32128a15, - 0xac1220d9, 0x2b31bb7c, 0xb53111b0, 0x56369e3e, 0xc83634f2, - 0xd13ff1f8, 0x4f3f5b34, 0xac38d4ba, 0x32387e76, 0x9e2a5eaf, - 0x002af463, 0xe32d7bed, 0x7d2dd121, 0x6424142b, 0xfa24bee7, - 0x19233169, 0x87239ba5, 0x566276f9, 0xc862dc35, 0x2b6553bb, - 0xb565f977, 0xac6c3c7d, 0x326c96b1, 0xd16b193f, 0x4f6bb3f3, - 0xe379932a, 0x7d7939e6, 0x9e7eb668, 0x007e1ca4, 0x1977d9ae, - 0x87777362, 0x6470fcec, 0xfa705620, 0x7d53cd85, 0xe3536749, - 0x0054e8c7, 0x9e54420b, 0x875d8701, 0x195d2dcd, 0xfa5aa243, - 0x645a088f, 0xc8482856, 0x5648829a, 0xb54f0d14, 0x2b4fa7d8, - 0x324662d2, 0xac46c81e, 0x4f414790, 0xd141ed5c, 0xedc29d29, - 0x73c237e5, 0x90c5b86b, 0x0ec512a7, 0x17ccd7ad, 0x89cc7d61, - 0x6acbf2ef, 0xf4cb5823, 0x58d978fa, 0xc6d9d236, 0x25de5db8, - 0xbbdef774, 0xa2d7327e, 0x3cd798b2, 0xdfd0173c, 0x41d0bdf0, - 0xc6f32655, 0x58f38c99, 0xbbf40317, 0x25f4a9db, 0x3cfd6cd1, - 0xa2fdc61d, 0x41fa4993, 0xdffae35f, 0x73e8c386, 0xede8694a, - 0x0eefe6c4, 0x90ef4c08, 0x89e68902, 0x17e623ce, 0xf4e1ac40, - 0x6ae1068c, 0xbba0ebd0, 0x25a0411c, 0xc6a7ce92, 0x58a7645e, - 0x41aea154, 0xdfae0b98, 0x3ca98416, 0xa2a92eda, 0x0ebb0e03, - 0x90bba4cf, 0x73bc2b41, 0xedbc818d, 0xf4b54487, 0x6ab5ee4b, - 0x89b261c5, 0x17b2cb09, 0x909150ac, 0x0e91fa60, 0xed9675ee, - 0x7396df22, 0x6a9f1a28, 0xf49fb0e4, 0x17983f6a, 0x899895a6, - 0x258ab57f, 0xbb8a1fb3, 0x588d903d, 0xc68d3af1, 0xdf84fffb, - 0x41845537, 0xa283dab9, 0x3c837075, 0xda853b53, 0x4485919f, - 0xa7821e11, 0x3982b4dd, 0x208b71d7, 0xbe8bdb1b, 0x5d8c5495, - 0xc38cfe59, 0x6f9ede80, 0xf19e744c, 0x1299fbc2, 0x8c99510e, - 0x95909404, 0x0b903ec8, 0xe897b146, 0x76971b8a, 0xf1b4802f, - 0x6fb42ae3, 0x8cb3a56d, 0x12b30fa1, 0x0bbacaab, 0x95ba6067, - 0x76bdefe9, 0xe8bd4525, 0x44af65fc, 0xdaafcf30, 0x39a840be, - 0xa7a8ea72, 0xbea12f78, 0x20a185b4, 0xc3a60a3a, 0x5da6a0f6, - 0x8ce74daa, 0x12e7e766, 0xf1e068e8, 0x6fe0c224, 0x76e9072e, - 0xe8e9ade2, 0x0bee226c, 0x95ee88a0, 0x39fca879, 0xa7fc02b5, - 0x44fb8d3b, 0xdafb27f7, 0xc3f2e2fd, 0x5df24831, 0xbef5c7bf, - 0x20f56d73, 0xa7d6f6d6, 0x39d65c1a, 0xdad1d394, 0x44d17958, - 0x5dd8bc52, 0xc3d8169e, 0x20df9910, 0xbedf33dc, 0x12cd1305, - 0x8ccdb9c9, 0x6fca3647, 0xf1ca9c8b, 0xe8c35981, 0x76c3f34d, - 0x95c47cc3, 0x0bc4d60f, 0x3747a67a, 0xa9470cb6, 0x4a408338, - 0xd44029f4, 0xcd49ecfe, 0x53494632, 0xb04ec9bc, 0x2e4e6370, - 0x825c43a9, 0x1c5ce965, 0xff5b66eb, 0x615bcc27, 0x7852092d, - 0xe652a3e1, 0x05552c6f, 0x9b5586a3, 0x1c761d06, 0x8276b7ca, - 0x61713844, 0xff719288, 0xe6785782, 0x7878fd4e, 0x9b7f72c0, - 0x057fd80c, 0xa96df8d5, 0x376d5219, 0xd46add97, 0x4a6a775b, - 0x5363b251, 0xcd63189d, 0x2e649713, 0xb0643ddf, 0x6125d083, - 0xff257a4f, 0x1c22f5c1, 0x82225f0d, 0x9b2b9a07, 0x052b30cb, - 0xe62cbf45, 0x782c1589, 0xd43e3550, 0x4a3e9f9c, 0xa9391012, - 0x3739bade, 0x2e307fd4, 0xb030d518, 0x53375a96, 0xcd37f05a, - 0x4a146bff, 0xd414c133, 0x37134ebd, 0xa913e471, 0xb01a217b, - 0x2e1a8bb7, 0xcd1d0439, 0x531daef5, 0xff0f8e2c, 0x610f24e0, - 0x8208ab6e, 0x1c0801a2, 0x0501c4a8, 0x9b016e64, 0x7806e1ea, - 0xe6064b26}}; - -#endif - -#endif - -#if N == 3 - -#if W == 8 - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0x81256527, 0xd93bcc0f, 0x581ea928, 0x69069e5f, - 0xe823fb78, 0xb03d5250, 0x31183777, 0xd20d3cbe, 0x53285999, - 0x0b36f0b1, 0x8a139596, 0xbb0ba2e1, 0x3a2ec7c6, 0x62306eee, - 0xe3150bc9, 0x7f6b7f3d, 0xfe4e1a1a, 0xa650b332, 0x2775d615, - 0x166de162, 0x97488445, 0xcf562d6d, 0x4e73484a, 0xad664383, - 0x2c4326a4, 0x745d8f8c, 0xf578eaab, 0xc460dddc, 0x4545b8fb, - 0x1d5b11d3, 0x9c7e74f4, 0xfed6fe7a, 0x7ff39b5d, 0x27ed3275, - 0xa6c85752, 0x97d06025, 0x16f50502, 0x4eebac2a, 0xcfcec90d, - 0x2cdbc2c4, 0xadfea7e3, 0xf5e00ecb, 0x74c56bec, 0x45dd5c9b, - 0xc4f839bc, 0x9ce69094, 0x1dc3f5b3, 0x81bd8147, 0x0098e460, - 0x58864d48, 0xd9a3286f, 0xe8bb1f18, 0x699e7a3f, 0x3180d317, - 0xb0a5b630, 0x53b0bdf9, 0xd295d8de, 0x8a8b71f6, 0x0bae14d1, - 0x3ab623a6, 0xbb934681, 0xe38defa9, 0x62a88a8e, 0x26dcfab5, - 0xa7f99f92, 0xffe736ba, 0x7ec2539d, 0x4fda64ea, 0xceff01cd, - 0x96e1a8e5, 0x17c4cdc2, 0xf4d1c60b, 0x75f4a32c, 0x2dea0a04, - 0xaccf6f23, 0x9dd75854, 0x1cf23d73, 0x44ec945b, 0xc5c9f17c, - 0x59b78588, 0xd892e0af, 0x808c4987, 0x01a92ca0, 0x30b11bd7, - 0xb1947ef0, 0xe98ad7d8, 0x68afb2ff, 0x8bbab936, 0x0a9fdc11, - 0x52817539, 0xd3a4101e, 0xe2bc2769, 0x6399424e, 0x3b87eb66, - 0xbaa28e41, 0xd80a04cf, 0x592f61e8, 0x0131c8c0, 0x8014ade7, - 0xb10c9a90, 0x3029ffb7, 0x6837569f, 0xe91233b8, 0x0a073871, - 0x8b225d56, 0xd33cf47e, 0x52199159, 0x6301a62e, 0xe224c309, - 0xba3a6a21, 0x3b1f0f06, 0xa7617bf2, 0x26441ed5, 0x7e5ab7fd, - 0xff7fd2da, 0xce67e5ad, 0x4f42808a, 0x175c29a2, 0x96794c85, - 0x756c474c, 0xf449226b, 0xac578b43, 0x2d72ee64, 0x1c6ad913, - 0x9d4fbc34, 0xc551151c, 0x4474703b, 0x4db9f56a, 0xcc9c904d, - 0x94823965, 0x15a75c42, 0x24bf6b35, 0xa59a0e12, 0xfd84a73a, - 0x7ca1c21d, 0x9fb4c9d4, 0x1e91acf3, 0x468f05db, 0xc7aa60fc, - 0xf6b2578b, 0x779732ac, 0x2f899b84, 0xaeacfea3, 0x32d28a57, - 0xb3f7ef70, 0xebe94658, 0x6acc237f, 0x5bd41408, 0xdaf1712f, - 0x82efd807, 0x03cabd20, 0xe0dfb6e9, 0x61fad3ce, 0x39e47ae6, - 0xb8c11fc1, 0x89d928b6, 0x08fc4d91, 0x50e2e4b9, 0xd1c7819e, - 0xb36f0b10, 0x324a6e37, 0x6a54c71f, 0xeb71a238, 0xda69954f, - 0x5b4cf068, 0x03525940, 0x82773c67, 0x616237ae, 0xe0475289, - 0xb859fba1, 0x397c9e86, 0x0864a9f1, 0x8941ccd6, 0xd15f65fe, - 0x507a00d9, 0xcc04742d, 0x4d21110a, 0x153fb822, 0x941add05, - 0xa502ea72, 0x24278f55, 0x7c39267d, 0xfd1c435a, 0x1e094893, - 0x9f2c2db4, 0xc732849c, 0x4617e1bb, 0x770fd6cc, 0xf62ab3eb, - 0xae341ac3, 0x2f117fe4, 0x6b650fdf, 0xea406af8, 0xb25ec3d0, - 0x337ba6f7, 0x02639180, 0x8346f4a7, 0xdb585d8f, 0x5a7d38a8, - 0xb9683361, 0x384d5646, 0x6053ff6e, 0xe1769a49, 0xd06ead3e, - 0x514bc819, 0x09556131, 0x88700416, 0x140e70e2, 0x952b15c5, - 0xcd35bced, 0x4c10d9ca, 0x7d08eebd, 0xfc2d8b9a, 0xa43322b2, - 0x25164795, 0xc6034c5c, 0x4726297b, 0x1f388053, 0x9e1de574, - 0xaf05d203, 0x2e20b724, 0x763e1e0c, 0xf71b7b2b, 0x95b3f1a5, - 0x14969482, 0x4c883daa, 0xcdad588d, 0xfcb56ffa, 0x7d900add, - 0x258ea3f5, 0xa4abc6d2, 0x47becd1b, 0xc69ba83c, 0x9e850114, - 0x1fa06433, 0x2eb85344, 0xaf9d3663, 0xf7839f4b, 0x76a6fa6c, - 0xead88e98, 0x6bfdebbf, 0x33e34297, 0xb2c627b0, 0x83de10c7, - 0x02fb75e0, 0x5ae5dcc8, 0xdbc0b9ef, 0x38d5b226, 0xb9f0d701, - 0xe1ee7e29, 0x60cb1b0e, 0x51d32c79, 0xd0f6495e, 0x88e8e076, - 0x09cd8551}, - {0x00000000, 0x9b73ead4, 0xed96d3e9, 0x76e5393d, 0x005ca193, - 0x9b2f4b47, 0xedca727a, 0x76b998ae, 0x00b94326, 0x9bcaa9f2, - 0xed2f90cf, 0x765c7a1b, 0x00e5e2b5, 0x9b960861, 0xed73315c, - 0x7600db88, 0x0172864c, 0x9a016c98, 0xece455a5, 0x7797bf71, - 0x012e27df, 0x9a5dcd0b, 0xecb8f436, 0x77cb1ee2, 0x01cbc56a, - 0x9ab82fbe, 0xec5d1683, 0x772efc57, 0x019764f9, 0x9ae48e2d, - 0xec01b710, 0x77725dc4, 0x02e50c98, 0x9996e64c, 0xef73df71, - 0x740035a5, 0x02b9ad0b, 0x99ca47df, 0xef2f7ee2, 0x745c9436, - 0x025c4fbe, 0x992fa56a, 0xefca9c57, 0x74b97683, 0x0200ee2d, - 0x997304f9, 0xef963dc4, 0x74e5d710, 0x03978ad4, 0x98e46000, - 0xee01593d, 0x7572b3e9, 0x03cb2b47, 0x98b8c193, 0xee5df8ae, - 0x752e127a, 0x032ec9f2, 0x985d2326, 0xeeb81a1b, 0x75cbf0cf, - 0x03726861, 0x980182b5, 0xeee4bb88, 0x7597515c, 0x05ca1930, - 0x9eb9f3e4, 0xe85ccad9, 0x732f200d, 0x0596b8a3, 0x9ee55277, - 0xe8006b4a, 0x7373819e, 0x05735a16, 0x9e00b0c2, 0xe8e589ff, - 0x7396632b, 0x052ffb85, 0x9e5c1151, 0xe8b9286c, 0x73cac2b8, - 0x04b89f7c, 0x9fcb75a8, 0xe92e4c95, 0x725da641, 0x04e43eef, - 0x9f97d43b, 0xe972ed06, 0x720107d2, 0x0401dc5a, 0x9f72368e, - 0xe9970fb3, 0x72e4e567, 0x045d7dc9, 0x9f2e971d, 0xe9cbae20, - 0x72b844f4, 0x072f15a8, 0x9c5cff7c, 0xeab9c641, 0x71ca2c95, - 0x0773b43b, 0x9c005eef, 0xeae567d2, 0x71968d06, 0x0796568e, - 0x9ce5bc5a, 0xea008567, 0x71736fb3, 0x07caf71d, 0x9cb91dc9, - 0xea5c24f4, 0x712fce20, 0x065d93e4, 0x9d2e7930, 0xebcb400d, - 0x70b8aad9, 0x06013277, 0x9d72d8a3, 0xeb97e19e, 0x70e40b4a, - 0x06e4d0c2, 0x9d973a16, 0xeb72032b, 0x7001e9ff, 0x06b87151, - 0x9dcb9b85, 0xeb2ea2b8, 0x705d486c, 0x0b943260, 0x90e7d8b4, - 0xe602e189, 0x7d710b5d, 0x0bc893f3, 0x90bb7927, 0xe65e401a, - 0x7d2daace, 0x0b2d7146, 0x905e9b92, 0xe6bba2af, 0x7dc8487b, - 0x0b71d0d5, 0x90023a01, 0xe6e7033c, 0x7d94e9e8, 0x0ae6b42c, - 0x91955ef8, 0xe77067c5, 0x7c038d11, 0x0aba15bf, 0x91c9ff6b, - 0xe72cc656, 0x7c5f2c82, 0x0a5ff70a, 0x912c1dde, 0xe7c924e3, - 0x7cbace37, 0x0a035699, 0x9170bc4d, 0xe7958570, 0x7ce66fa4, - 0x09713ef8, 0x9202d42c, 0xe4e7ed11, 0x7f9407c5, 0x092d9f6b, - 0x925e75bf, 0xe4bb4c82, 0x7fc8a656, 0x09c87dde, 0x92bb970a, - 0xe45eae37, 0x7f2d44e3, 0x0994dc4d, 0x92e73699, 0xe4020fa4, - 0x7f71e570, 0x0803b8b4, 0x93705260, 0xe5956b5d, 0x7ee68189, - 0x085f1927, 0x932cf3f3, 0xe5c9cace, 0x7eba201a, 0x08bafb92, - 0x93c91146, 0xe52c287b, 0x7e5fc2af, 0x08e65a01, 0x9395b0d5, - 0xe57089e8, 0x7e03633c, 0x0e5e2b50, 0x952dc184, 0xe3c8f8b9, - 0x78bb126d, 0x0e028ac3, 0x95716017, 0xe394592a, 0x78e7b3fe, - 0x0ee76876, 0x959482a2, 0xe371bb9f, 0x7802514b, 0x0ebbc9e5, - 0x95c82331, 0xe32d1a0c, 0x785ef0d8, 0x0f2cad1c, 0x945f47c8, - 0xe2ba7ef5, 0x79c99421, 0x0f700c8f, 0x9403e65b, 0xe2e6df66, - 0x799535b2, 0x0f95ee3a, 0x94e604ee, 0xe2033dd3, 0x7970d707, - 0x0fc94fa9, 0x94baa57d, 0xe25f9c40, 0x792c7694, 0x0cbb27c8, - 0x97c8cd1c, 0xe12df421, 0x7a5e1ef5, 0x0ce7865b, 0x97946c8f, - 0xe17155b2, 0x7a02bf66, 0x0c0264ee, 0x97718e3a, 0xe194b707, - 0x7ae75dd3, 0x0c5ec57d, 0x972d2fa9, 0xe1c81694, 0x7abbfc40, - 0x0dc9a184, 0x96ba4b50, 0xe05f726d, 0x7b2c98b9, 0x0d950017, - 0x96e6eac3, 0xe003d3fe, 0x7b70392a, 0x0d70e2a2, 0x96030876, - 0xe0e6314b, 0x7b95db9f, 0x0d2c4331, 0x965fa9e5, 0xe0ba90d8, - 0x7bc97a0c}, - {0x00000000, 0x172864c0, 0x2e50c980, 0x3978ad40, 0x5ca19300, - 0x4b89f7c0, 0x72f15a80, 0x65d93e40, 0xb9432600, 0xae6b42c0, - 0x9713ef80, 0x803b8b40, 0xe5e2b500, 0xf2cad1c0, 0xcbb27c80, - 0xdc9a1840, 0xa9f74a41, 0xbedf2e81, 0x87a783c1, 0x908fe701, - 0xf556d941, 0xe27ebd81, 0xdb0610c1, 0xcc2e7401, 0x10b46c41, - 0x079c0881, 0x3ee4a5c1, 0x29ccc101, 0x4c15ff41, 0x5b3d9b81, - 0x624536c1, 0x756d5201, 0x889f92c3, 0x9fb7f603, 0xa6cf5b43, - 0xb1e73f83, 0xd43e01c3, 0xc3166503, 0xfa6ec843, 0xed46ac83, - 0x31dcb4c3, 0x26f4d003, 0x1f8c7d43, 0x08a41983, 0x6d7d27c3, - 0x7a554303, 0x432dee43, 0x54058a83, 0x2168d882, 0x3640bc42, - 0x0f381102, 0x181075c2, 0x7dc94b82, 0x6ae12f42, 0x53998202, - 0x44b1e6c2, 0x982bfe82, 0x8f039a42, 0xb67b3702, 0xa15353c2, - 0xc48a6d82, 0xd3a20942, 0xeadaa402, 0xfdf2c0c2, 0xca4e23c7, - 0xdd664707, 0xe41eea47, 0xf3368e87, 0x96efb0c7, 0x81c7d407, - 0xb8bf7947, 0xaf971d87, 0x730d05c7, 0x64256107, 0x5d5dcc47, - 0x4a75a887, 0x2fac96c7, 0x3884f207, 0x01fc5f47, 0x16d43b87, - 0x63b96986, 0x74910d46, 0x4de9a006, 0x5ac1c4c6, 0x3f18fa86, - 0x28309e46, 0x11483306, 0x066057c6, 0xdafa4f86, 0xcdd22b46, - 0xf4aa8606, 0xe382e2c6, 0x865bdc86, 0x9173b846, 0xa80b1506, - 0xbf2371c6, 0x42d1b104, 0x55f9d5c4, 0x6c817884, 0x7ba91c44, - 0x1e702204, 0x095846c4, 0x3020eb84, 0x27088f44, 0xfb929704, - 0xecbaf3c4, 0xd5c25e84, 0xc2ea3a44, 0xa7330404, 0xb01b60c4, - 0x8963cd84, 0x9e4ba944, 0xeb26fb45, 0xfc0e9f85, 0xc57632c5, - 0xd25e5605, 0xb7876845, 0xa0af0c85, 0x99d7a1c5, 0x8effc505, - 0x5265dd45, 0x454db985, 0x7c3514c5, 0x6b1d7005, 0x0ec44e45, - 0x19ec2a85, 0x209487c5, 0x37bce305, 0x4fed41cf, 0x58c5250f, - 0x61bd884f, 0x7695ec8f, 0x134cd2cf, 0x0464b60f, 0x3d1c1b4f, - 0x2a347f8f, 0xf6ae67cf, 0xe186030f, 0xd8feae4f, 0xcfd6ca8f, - 0xaa0ff4cf, 0xbd27900f, 0x845f3d4f, 0x9377598f, 0xe61a0b8e, - 0xf1326f4e, 0xc84ac20e, 0xdf62a6ce, 0xbabb988e, 0xad93fc4e, - 0x94eb510e, 0x83c335ce, 0x5f592d8e, 0x4871494e, 0x7109e40e, - 0x662180ce, 0x03f8be8e, 0x14d0da4e, 0x2da8770e, 0x3a8013ce, - 0xc772d30c, 0xd05ab7cc, 0xe9221a8c, 0xfe0a7e4c, 0x9bd3400c, - 0x8cfb24cc, 0xb583898c, 0xa2abed4c, 0x7e31f50c, 0x691991cc, - 0x50613c8c, 0x4749584c, 0x2290660c, 0x35b802cc, 0x0cc0af8c, - 0x1be8cb4c, 0x6e85994d, 0x79adfd8d, 0x40d550cd, 0x57fd340d, - 0x32240a4d, 0x250c6e8d, 0x1c74c3cd, 0x0b5ca70d, 0xd7c6bf4d, - 0xc0eedb8d, 0xf99676cd, 0xeebe120d, 0x8b672c4d, 0x9c4f488d, - 0xa537e5cd, 0xb21f810d, 0x85a36208, 0x928b06c8, 0xabf3ab88, - 0xbcdbcf48, 0xd902f108, 0xce2a95c8, 0xf7523888, 0xe07a5c48, - 0x3ce04408, 0x2bc820c8, 0x12b08d88, 0x0598e948, 0x6041d708, - 0x7769b3c8, 0x4e111e88, 0x59397a48, 0x2c542849, 0x3b7c4c89, - 0x0204e1c9, 0x152c8509, 0x70f5bb49, 0x67dddf89, 0x5ea572c9, - 0x498d1609, 0x95170e49, 0x823f6a89, 0xbb47c7c9, 0xac6fa309, - 0xc9b69d49, 0xde9ef989, 0xe7e654c9, 0xf0ce3009, 0x0d3cf0cb, - 0x1a14940b, 0x236c394b, 0x34445d8b, 0x519d63cb, 0x46b5070b, - 0x7fcdaa4b, 0x68e5ce8b, 0xb47fd6cb, 0xa357b20b, 0x9a2f1f4b, - 0x8d077b8b, 0xe8de45cb, 0xfff6210b, 0xc68e8c4b, 0xd1a6e88b, - 0xa4cbba8a, 0xb3e3de4a, 0x8a9b730a, 0x9db317ca, 0xf86a298a, - 0xef424d4a, 0xd63ae00a, 0xc11284ca, 0x1d889c8a, 0x0aa0f84a, - 0x33d8550a, 0x24f031ca, 0x41290f8a, 0x56016b4a, 0x6f79c60a, - 0x7851a2ca}, - {0x00000000, 0x9fda839e, 0xe4c4017d, 0x7b1e82e3, 0x12f904bb, - 0x8d238725, 0xf63d05c6, 0x69e78658, 0x25f20976, 0xba288ae8, - 0xc136080b, 0x5eec8b95, 0x370b0dcd, 0xa8d18e53, 0xd3cf0cb0, - 0x4c158f2e, 0x4be412ec, 0xd43e9172, 0xaf201391, 0x30fa900f, - 0x591d1657, 0xc6c795c9, 0xbdd9172a, 0x220394b4, 0x6e161b9a, - 0xf1cc9804, 0x8ad21ae7, 0x15089979, 0x7cef1f21, 0xe3359cbf, - 0x982b1e5c, 0x07f19dc2, 0x97c825d8, 0x0812a646, 0x730c24a5, - 0xecd6a73b, 0x85312163, 0x1aeba2fd, 0x61f5201e, 0xfe2fa380, - 0xb23a2cae, 0x2de0af30, 0x56fe2dd3, 0xc924ae4d, 0xa0c32815, - 0x3f19ab8b, 0x44072968, 0xdbddaaf6, 0xdc2c3734, 0x43f6b4aa, - 0x38e83649, 0xa732b5d7, 0xced5338f, 0x510fb011, 0x2a1132f2, - 0xb5cbb16c, 0xf9de3e42, 0x6604bddc, 0x1d1a3f3f, 0x82c0bca1, - 0xeb273af9, 0x74fdb967, 0x0fe33b84, 0x9039b81a, 0xf4e14df1, - 0x6b3bce6f, 0x10254c8c, 0x8fffcf12, 0xe618494a, 0x79c2cad4, - 0x02dc4837, 0x9d06cba9, 0xd1134487, 0x4ec9c719, 0x35d745fa, - 0xaa0dc664, 0xc3ea403c, 0x5c30c3a2, 0x272e4141, 0xb8f4c2df, - 0xbf055f1d, 0x20dfdc83, 0x5bc15e60, 0xc41bddfe, 0xadfc5ba6, - 0x3226d838, 0x49385adb, 0xd6e2d945, 0x9af7566b, 0x052dd5f5, - 0x7e335716, 0xe1e9d488, 0x880e52d0, 0x17d4d14e, 0x6cca53ad, - 0xf310d033, 0x63296829, 0xfcf3ebb7, 0x87ed6954, 0x1837eaca, - 0x71d06c92, 0xee0aef0c, 0x95146def, 0x0aceee71, 0x46db615f, - 0xd901e2c1, 0xa21f6022, 0x3dc5e3bc, 0x542265e4, 0xcbf8e67a, - 0xb0e66499, 0x2f3ce707, 0x28cd7ac5, 0xb717f95b, 0xcc097bb8, - 0x53d3f826, 0x3a347e7e, 0xa5eefde0, 0xdef07f03, 0x412afc9d, - 0x0d3f73b3, 0x92e5f02d, 0xe9fb72ce, 0x7621f150, 0x1fc67708, - 0x801cf496, 0xfb027675, 0x64d8f5eb, 0x32b39da3, 0xad691e3d, - 0xd6779cde, 0x49ad1f40, 0x204a9918, 0xbf901a86, 0xc48e9865, - 0x5b541bfb, 0x174194d5, 0x889b174b, 0xf38595a8, 0x6c5f1636, - 0x05b8906e, 0x9a6213f0, 0xe17c9113, 0x7ea6128d, 0x79578f4f, - 0xe68d0cd1, 0x9d938e32, 0x02490dac, 0x6bae8bf4, 0xf474086a, - 0x8f6a8a89, 0x10b00917, 0x5ca58639, 0xc37f05a7, 0xb8618744, - 0x27bb04da, 0x4e5c8282, 0xd186011c, 0xaa9883ff, 0x35420061, - 0xa57bb87b, 0x3aa13be5, 0x41bfb906, 0xde653a98, 0xb782bcc0, - 0x28583f5e, 0x5346bdbd, 0xcc9c3e23, 0x8089b10d, 0x1f533293, - 0x644db070, 0xfb9733ee, 0x9270b5b6, 0x0daa3628, 0x76b4b4cb, - 0xe96e3755, 0xee9faa97, 0x71452909, 0x0a5babea, 0x95812874, - 0xfc66ae2c, 0x63bc2db2, 0x18a2af51, 0x87782ccf, 0xcb6da3e1, - 0x54b7207f, 0x2fa9a29c, 0xb0732102, 0xd994a75a, 0x464e24c4, - 0x3d50a627, 0xa28a25b9, 0xc652d052, 0x598853cc, 0x2296d12f, - 0xbd4c52b1, 0xd4abd4e9, 0x4b715777, 0x306fd594, 0xafb5560a, - 0xe3a0d924, 0x7c7a5aba, 0x0764d859, 0x98be5bc7, 0xf159dd9f, - 0x6e835e01, 0x159ddce2, 0x8a475f7c, 0x8db6c2be, 0x126c4120, - 0x6972c3c3, 0xf6a8405d, 0x9f4fc605, 0x0095459b, 0x7b8bc778, - 0xe45144e6, 0xa844cbc8, 0x379e4856, 0x4c80cab5, 0xd35a492b, - 0xbabdcf73, 0x25674ced, 0x5e79ce0e, 0xc1a34d90, 0x519af58a, - 0xce407614, 0xb55ef4f7, 0x2a847769, 0x4363f131, 0xdcb972af, - 0xa7a7f04c, 0x387d73d2, 0x7468fcfc, 0xebb27f62, 0x90acfd81, - 0x0f767e1f, 0x6691f847, 0xf94b7bd9, 0x8255f93a, 0x1d8f7aa4, - 0x1a7ee766, 0x85a464f8, 0xfebae61b, 0x61606585, 0x0887e3dd, - 0x975d6043, 0xec43e2a0, 0x7399613e, 0x3f8cee10, 0xa0566d8e, - 0xdb48ef6d, 0x44926cf3, 0x2d75eaab, 0xb2af6935, 0xc9b1ebd6, - 0x566b6848}, - {0x00000000, 0x65673b46, 0xcace768c, 0xafa94dca, 0x4eedeb59, - 0x2b8ad01f, 0x84239dd5, 0xe144a693, 0x9ddbd6b2, 0xf8bcedf4, - 0x5715a03e, 0x32729b78, 0xd3363deb, 0xb65106ad, 0x19f84b67, - 0x7c9f7021, 0xe0c6ab25, 0x85a19063, 0x2a08dda9, 0x4f6fe6ef, - 0xae2b407c, 0xcb4c7b3a, 0x64e536f0, 0x01820db6, 0x7d1d7d97, - 0x187a46d1, 0xb7d30b1b, 0xd2b4305d, 0x33f096ce, 0x5697ad88, - 0xf93ee042, 0x9c59db04, 0x1afc500b, 0x7f9b6b4d, 0xd0322687, - 0xb5551dc1, 0x5411bb52, 0x31768014, 0x9edfcdde, 0xfbb8f698, - 0x872786b9, 0xe240bdff, 0x4de9f035, 0x288ecb73, 0xc9ca6de0, - 0xacad56a6, 0x03041b6c, 0x6663202a, 0xfa3afb2e, 0x9f5dc068, - 0x30f48da2, 0x5593b6e4, 0xb4d71077, 0xd1b02b31, 0x7e1966fb, - 0x1b7e5dbd, 0x67e12d9c, 0x028616da, 0xad2f5b10, 0xc8486056, - 0x290cc6c5, 0x4c6bfd83, 0xe3c2b049, 0x86a58b0f, 0x35f8a016, - 0x509f9b50, 0xff36d69a, 0x9a51eddc, 0x7b154b4f, 0x1e727009, - 0xb1db3dc3, 0xd4bc0685, 0xa82376a4, 0xcd444de2, 0x62ed0028, - 0x078a3b6e, 0xe6ce9dfd, 0x83a9a6bb, 0x2c00eb71, 0x4967d037, - 0xd53e0b33, 0xb0593075, 0x1ff07dbf, 0x7a9746f9, 0x9bd3e06a, - 0xfeb4db2c, 0x511d96e6, 0x347aada0, 0x48e5dd81, 0x2d82e6c7, - 0x822bab0d, 0xe74c904b, 0x060836d8, 0x636f0d9e, 0xccc64054, - 0xa9a17b12, 0x2f04f01d, 0x4a63cb5b, 0xe5ca8691, 0x80adbdd7, - 0x61e91b44, 0x048e2002, 0xab276dc8, 0xce40568e, 0xb2df26af, - 0xd7b81de9, 0x78115023, 0x1d766b65, 0xfc32cdf6, 0x9955f6b0, - 0x36fcbb7a, 0x539b803c, 0xcfc25b38, 0xaaa5607e, 0x050c2db4, - 0x606b16f2, 0x812fb061, 0xe4488b27, 0x4be1c6ed, 0x2e86fdab, - 0x52198d8a, 0x377eb6cc, 0x98d7fb06, 0xfdb0c040, 0x1cf466d3, - 0x79935d95, 0xd63a105f, 0xb35d2b19, 0x6bf1402c, 0x0e967b6a, - 0xa13f36a0, 0xc4580de6, 0x251cab75, 0x407b9033, 0xefd2ddf9, - 0x8ab5e6bf, 0xf62a969e, 0x934dadd8, 0x3ce4e012, 0x5983db54, - 0xb8c77dc7, 0xdda04681, 0x72090b4b, 0x176e300d, 0x8b37eb09, - 0xee50d04f, 0x41f99d85, 0x249ea6c3, 0xc5da0050, 0xa0bd3b16, - 0x0f1476dc, 0x6a734d9a, 0x16ec3dbb, 0x738b06fd, 0xdc224b37, - 0xb9457071, 0x5801d6e2, 0x3d66eda4, 0x92cfa06e, 0xf7a89b28, - 0x710d1027, 0x146a2b61, 0xbbc366ab, 0xdea45ded, 0x3fe0fb7e, - 0x5a87c038, 0xf52e8df2, 0x9049b6b4, 0xecd6c695, 0x89b1fdd3, - 0x2618b019, 0x437f8b5f, 0xa23b2dcc, 0xc75c168a, 0x68f55b40, - 0x0d926006, 0x91cbbb02, 0xf4ac8044, 0x5b05cd8e, 0x3e62f6c8, - 0xdf26505b, 0xba416b1d, 0x15e826d7, 0x708f1d91, 0x0c106db0, - 0x697756f6, 0xc6de1b3c, 0xa3b9207a, 0x42fd86e9, 0x279abdaf, - 0x8833f065, 0xed54cb23, 0x5e09e03a, 0x3b6edb7c, 0x94c796b6, - 0xf1a0adf0, 0x10e40b63, 0x75833025, 0xda2a7def, 0xbf4d46a9, - 0xc3d23688, 0xa6b50dce, 0x091c4004, 0x6c7b7b42, 0x8d3fddd1, - 0xe858e697, 0x47f1ab5d, 0x2296901b, 0xbecf4b1f, 0xdba87059, - 0x74013d93, 0x116606d5, 0xf022a046, 0x95459b00, 0x3aecd6ca, - 0x5f8bed8c, 0x23149dad, 0x4673a6eb, 0xe9daeb21, 0x8cbdd067, - 0x6df976f4, 0x089e4db2, 0xa7370078, 0xc2503b3e, 0x44f5b031, - 0x21928b77, 0x8e3bc6bd, 0xeb5cfdfb, 0x0a185b68, 0x6f7f602e, - 0xc0d62de4, 0xa5b116a2, 0xd92e6683, 0xbc495dc5, 0x13e0100f, - 0x76872b49, 0x97c38dda, 0xf2a4b69c, 0x5d0dfb56, 0x386ac010, - 0xa4331b14, 0xc1542052, 0x6efd6d98, 0x0b9a56de, 0xeadef04d, - 0x8fb9cb0b, 0x201086c1, 0x4577bd87, 0x39e8cda6, 0x5c8ff6e0, - 0xf326bb2a, 0x9641806c, 0x770526ff, 0x12621db9, 0xbdcb5073, - 0xd8ac6b35}, - {0x00000000, 0xd7e28058, 0x74b406f1, 0xa35686a9, 0xe9680de2, - 0x3e8a8dba, 0x9ddc0b13, 0x4a3e8b4b, 0x09a11d85, 0xde439ddd, - 0x7d151b74, 0xaaf79b2c, 0xe0c91067, 0x372b903f, 0x947d1696, - 0x439f96ce, 0x13423b0a, 0xc4a0bb52, 0x67f63dfb, 0xb014bda3, - 0xfa2a36e8, 0x2dc8b6b0, 0x8e9e3019, 0x597cb041, 0x1ae3268f, - 0xcd01a6d7, 0x6e57207e, 0xb9b5a026, 0xf38b2b6d, 0x2469ab35, - 0x873f2d9c, 0x50ddadc4, 0x26847614, 0xf166f64c, 0x523070e5, - 0x85d2f0bd, 0xcfec7bf6, 0x180efbae, 0xbb587d07, 0x6cbafd5f, - 0x2f256b91, 0xf8c7ebc9, 0x5b916d60, 0x8c73ed38, 0xc64d6673, - 0x11afe62b, 0xb2f96082, 0x651be0da, 0x35c64d1e, 0xe224cd46, - 0x41724bef, 0x9690cbb7, 0xdcae40fc, 0x0b4cc0a4, 0xa81a460d, - 0x7ff8c655, 0x3c67509b, 0xeb85d0c3, 0x48d3566a, 0x9f31d632, - 0xd50f5d79, 0x02eddd21, 0xa1bb5b88, 0x7659dbd0, 0x4d08ec28, - 0x9aea6c70, 0x39bcead9, 0xee5e6a81, 0xa460e1ca, 0x73826192, - 0xd0d4e73b, 0x07366763, 0x44a9f1ad, 0x934b71f5, 0x301df75c, - 0xe7ff7704, 0xadc1fc4f, 0x7a237c17, 0xd975fabe, 0x0e977ae6, - 0x5e4ad722, 0x89a8577a, 0x2afed1d3, 0xfd1c518b, 0xb722dac0, - 0x60c05a98, 0xc396dc31, 0x14745c69, 0x57ebcaa7, 0x80094aff, - 0x235fcc56, 0xf4bd4c0e, 0xbe83c745, 0x6961471d, 0xca37c1b4, - 0x1dd541ec, 0x6b8c9a3c, 0xbc6e1a64, 0x1f389ccd, 0xc8da1c95, - 0x82e497de, 0x55061786, 0xf650912f, 0x21b21177, 0x622d87b9, - 0xb5cf07e1, 0x16998148, 0xc17b0110, 0x8b458a5b, 0x5ca70a03, - 0xfff18caa, 0x28130cf2, 0x78cea136, 0xaf2c216e, 0x0c7aa7c7, - 0xdb98279f, 0x91a6acd4, 0x46442c8c, 0xe512aa25, 0x32f02a7d, - 0x716fbcb3, 0xa68d3ceb, 0x05dbba42, 0xd2393a1a, 0x9807b151, - 0x4fe53109, 0xecb3b7a0, 0x3b5137f8, 0x9a11d850, 0x4df35808, - 0xeea5dea1, 0x39475ef9, 0x7379d5b2, 0xa49b55ea, 0x07cdd343, - 0xd02f531b, 0x93b0c5d5, 0x4452458d, 0xe704c324, 0x30e6437c, - 0x7ad8c837, 0xad3a486f, 0x0e6ccec6, 0xd98e4e9e, 0x8953e35a, - 0x5eb16302, 0xfde7e5ab, 0x2a0565f3, 0x603beeb8, 0xb7d96ee0, - 0x148fe849, 0xc36d6811, 0x80f2fedf, 0x57107e87, 0xf446f82e, - 0x23a47876, 0x699af33d, 0xbe787365, 0x1d2ef5cc, 0xcacc7594, - 0xbc95ae44, 0x6b772e1c, 0xc821a8b5, 0x1fc328ed, 0x55fda3a6, - 0x821f23fe, 0x2149a557, 0xf6ab250f, 0xb534b3c1, 0x62d63399, - 0xc180b530, 0x16623568, 0x5c5cbe23, 0x8bbe3e7b, 0x28e8b8d2, - 0xff0a388a, 0xafd7954e, 0x78351516, 0xdb6393bf, 0x0c8113e7, - 0x46bf98ac, 0x915d18f4, 0x320b9e5d, 0xe5e91e05, 0xa67688cb, - 0x71940893, 0xd2c28e3a, 0x05200e62, 0x4f1e8529, 0x98fc0571, - 0x3baa83d8, 0xec480380, 0xd7193478, 0x00fbb420, 0xa3ad3289, - 0x744fb2d1, 0x3e71399a, 0xe993b9c2, 0x4ac53f6b, 0x9d27bf33, - 0xdeb829fd, 0x095aa9a5, 0xaa0c2f0c, 0x7deeaf54, 0x37d0241f, - 0xe032a447, 0x436422ee, 0x9486a2b6, 0xc45b0f72, 0x13b98f2a, - 0xb0ef0983, 0x670d89db, 0x2d330290, 0xfad182c8, 0x59870461, - 0x8e658439, 0xcdfa12f7, 0x1a1892af, 0xb94e1406, 0x6eac945e, - 0x24921f15, 0xf3709f4d, 0x502619e4, 0x87c499bc, 0xf19d426c, - 0x267fc234, 0x8529449d, 0x52cbc4c5, 0x18f54f8e, 0xcf17cfd6, - 0x6c41497f, 0xbba3c927, 0xf83c5fe9, 0x2fdedfb1, 0x8c885918, - 0x5b6ad940, 0x1154520b, 0xc6b6d253, 0x65e054fa, 0xb202d4a2, - 0xe2df7966, 0x353df93e, 0x966b7f97, 0x4189ffcf, 0x0bb77484, - 0xdc55f4dc, 0x7f037275, 0xa8e1f22d, 0xeb7e64e3, 0x3c9ce4bb, - 0x9fca6212, 0x4828e24a, 0x02166901, 0xd5f4e959, 0x76a26ff0, - 0xa140efa8}, - {0x00000000, 0xef52b6e1, 0x05d46b83, 0xea86dd62, 0x0ba8d706, - 0xe4fa61e7, 0x0e7cbc85, 0xe12e0a64, 0x1751ae0c, 0xf80318ed, - 0x1285c58f, 0xfdd7736e, 0x1cf9790a, 0xf3abcfeb, 0x192d1289, - 0xf67fa468, 0x2ea35c18, 0xc1f1eaf9, 0x2b77379b, 0xc425817a, - 0x250b8b1e, 0xca593dff, 0x20dfe09d, 0xcf8d567c, 0x39f2f214, - 0xd6a044f5, 0x3c269997, 0xd3742f76, 0x325a2512, 0xdd0893f3, - 0x378e4e91, 0xd8dcf870, 0x5d46b830, 0xb2140ed1, 0x5892d3b3, - 0xb7c06552, 0x56ee6f36, 0xb9bcd9d7, 0x533a04b5, 0xbc68b254, - 0x4a17163c, 0xa545a0dd, 0x4fc37dbf, 0xa091cb5e, 0x41bfc13a, - 0xaeed77db, 0x446baab9, 0xab391c58, 0x73e5e428, 0x9cb752c9, - 0x76318fab, 0x9963394a, 0x784d332e, 0x971f85cf, 0x7d9958ad, - 0x92cbee4c, 0x64b44a24, 0x8be6fcc5, 0x616021a7, 0x8e329746, - 0x6f1c9d22, 0x804e2bc3, 0x6ac8f6a1, 0x859a4040, 0xba8d7060, - 0x55dfc681, 0xbf591be3, 0x500bad02, 0xb125a766, 0x5e771187, - 0xb4f1cce5, 0x5ba37a04, 0xaddcde6c, 0x428e688d, 0xa808b5ef, - 0x475a030e, 0xa674096a, 0x4926bf8b, 0xa3a062e9, 0x4cf2d408, - 0x942e2c78, 0x7b7c9a99, 0x91fa47fb, 0x7ea8f11a, 0x9f86fb7e, - 0x70d44d9f, 0x9a5290fd, 0x7500261c, 0x837f8274, 0x6c2d3495, - 0x86abe9f7, 0x69f95f16, 0x88d75572, 0x6785e393, 0x8d033ef1, - 0x62518810, 0xe7cbc850, 0x08997eb1, 0xe21fa3d3, 0x0d4d1532, - 0xec631f56, 0x0331a9b7, 0xe9b774d5, 0x06e5c234, 0xf09a665c, - 0x1fc8d0bd, 0xf54e0ddf, 0x1a1cbb3e, 0xfb32b15a, 0x146007bb, - 0xfee6dad9, 0x11b46c38, 0xc9689448, 0x263a22a9, 0xccbcffcb, - 0x23ee492a, 0xc2c0434e, 0x2d92f5af, 0xc71428cd, 0x28469e2c, - 0xde393a44, 0x316b8ca5, 0xdbed51c7, 0x34bfe726, 0xd591ed42, - 0x3ac35ba3, 0xd04586c1, 0x3f173020, 0xae6be681, 0x41395060, - 0xabbf8d02, 0x44ed3be3, 0xa5c33187, 0x4a918766, 0xa0175a04, - 0x4f45ece5, 0xb93a488d, 0x5668fe6c, 0xbcee230e, 0x53bc95ef, - 0xb2929f8b, 0x5dc0296a, 0xb746f408, 0x581442e9, 0x80c8ba99, - 0x6f9a0c78, 0x851cd11a, 0x6a4e67fb, 0x8b606d9f, 0x6432db7e, - 0x8eb4061c, 0x61e6b0fd, 0x97991495, 0x78cba274, 0x924d7f16, - 0x7d1fc9f7, 0x9c31c393, 0x73637572, 0x99e5a810, 0x76b71ef1, - 0xf32d5eb1, 0x1c7fe850, 0xf6f93532, 0x19ab83d3, 0xf88589b7, - 0x17d73f56, 0xfd51e234, 0x120354d5, 0xe47cf0bd, 0x0b2e465c, - 0xe1a89b3e, 0x0efa2ddf, 0xefd427bb, 0x0086915a, 0xea004c38, - 0x0552fad9, 0xdd8e02a9, 0x32dcb448, 0xd85a692a, 0x3708dfcb, - 0xd626d5af, 0x3974634e, 0xd3f2be2c, 0x3ca008cd, 0xcadfaca5, - 0x258d1a44, 0xcf0bc726, 0x205971c7, 0xc1777ba3, 0x2e25cd42, - 0xc4a31020, 0x2bf1a6c1, 0x14e696e1, 0xfbb42000, 0x1132fd62, - 0xfe604b83, 0x1f4e41e7, 0xf01cf706, 0x1a9a2a64, 0xf5c89c85, - 0x03b738ed, 0xece58e0c, 0x0663536e, 0xe931e58f, 0x081fefeb, - 0xe74d590a, 0x0dcb8468, 0xe2993289, 0x3a45caf9, 0xd5177c18, - 0x3f91a17a, 0xd0c3179b, 0x31ed1dff, 0xdebfab1e, 0x3439767c, - 0xdb6bc09d, 0x2d1464f5, 0xc246d214, 0x28c00f76, 0xc792b997, - 0x26bcb3f3, 0xc9ee0512, 0x2368d870, 0xcc3a6e91, 0x49a02ed1, - 0xa6f29830, 0x4c744552, 0xa326f3b3, 0x4208f9d7, 0xad5a4f36, - 0x47dc9254, 0xa88e24b5, 0x5ef180dd, 0xb1a3363c, 0x5b25eb5e, - 0xb4775dbf, 0x555957db, 0xba0be13a, 0x508d3c58, 0xbfdf8ab9, - 0x670372c9, 0x8851c428, 0x62d7194a, 0x8d85afab, 0x6caba5cf, - 0x83f9132e, 0x697fce4c, 0x862d78ad, 0x7052dcc5, 0x9f006a24, - 0x7586b746, 0x9ad401a7, 0x7bfa0bc3, 0x94a8bd22, 0x7e2e6040, - 0x917cd6a1}, - {0x00000000, 0x87a6cb43, 0xd43c90c7, 0x539a5b84, 0x730827cf, - 0xf4aeec8c, 0xa734b708, 0x20927c4b, 0xe6104f9e, 0x61b684dd, - 0x322cdf59, 0xb58a141a, 0x95186851, 0x12bea312, 0x4124f896, - 0xc68233d5, 0x1751997d, 0x90f7523e, 0xc36d09ba, 0x44cbc2f9, - 0x6459beb2, 0xe3ff75f1, 0xb0652e75, 0x37c3e536, 0xf141d6e3, - 0x76e71da0, 0x257d4624, 0xa2db8d67, 0x8249f12c, 0x05ef3a6f, - 0x567561eb, 0xd1d3aaa8, 0x2ea332fa, 0xa905f9b9, 0xfa9fa23d, - 0x7d39697e, 0x5dab1535, 0xda0dde76, 0x899785f2, 0x0e314eb1, - 0xc8b37d64, 0x4f15b627, 0x1c8feda3, 0x9b2926e0, 0xbbbb5aab, - 0x3c1d91e8, 0x6f87ca6c, 0xe821012f, 0x39f2ab87, 0xbe5460c4, - 0xedce3b40, 0x6a68f003, 0x4afa8c48, 0xcd5c470b, 0x9ec61c8f, - 0x1960d7cc, 0xdfe2e419, 0x58442f5a, 0x0bde74de, 0x8c78bf9d, - 0xaceac3d6, 0x2b4c0895, 0x78d65311, 0xff709852, 0x5d4665f4, - 0xdae0aeb7, 0x897af533, 0x0edc3e70, 0x2e4e423b, 0xa9e88978, - 0xfa72d2fc, 0x7dd419bf, 0xbb562a6a, 0x3cf0e129, 0x6f6abaad, - 0xe8cc71ee, 0xc85e0da5, 0x4ff8c6e6, 0x1c629d62, 0x9bc45621, - 0x4a17fc89, 0xcdb137ca, 0x9e2b6c4e, 0x198da70d, 0x391fdb46, - 0xbeb91005, 0xed234b81, 0x6a8580c2, 0xac07b317, 0x2ba17854, - 0x783b23d0, 0xff9de893, 0xdf0f94d8, 0x58a95f9b, 0x0b33041f, - 0x8c95cf5c, 0x73e5570e, 0xf4439c4d, 0xa7d9c7c9, 0x207f0c8a, - 0x00ed70c1, 0x874bbb82, 0xd4d1e006, 0x53772b45, 0x95f51890, - 0x1253d3d3, 0x41c98857, 0xc66f4314, 0xe6fd3f5f, 0x615bf41c, - 0x32c1af98, 0xb56764db, 0x64b4ce73, 0xe3120530, 0xb0885eb4, - 0x372e95f7, 0x17bce9bc, 0x901a22ff, 0xc380797b, 0x4426b238, - 0x82a481ed, 0x05024aae, 0x5698112a, 0xd13eda69, 0xf1aca622, - 0x760a6d61, 0x259036e5, 0xa236fda6, 0xba8ccbe8, 0x3d2a00ab, - 0x6eb05b2f, 0xe916906c, 0xc984ec27, 0x4e222764, 0x1db87ce0, - 0x9a1eb7a3, 0x5c9c8476, 0xdb3a4f35, 0x88a014b1, 0x0f06dff2, - 0x2f94a3b9, 0xa83268fa, 0xfba8337e, 0x7c0ef83d, 0xaddd5295, - 0x2a7b99d6, 0x79e1c252, 0xfe470911, 0xded5755a, 0x5973be19, - 0x0ae9e59d, 0x8d4f2ede, 0x4bcd1d0b, 0xcc6bd648, 0x9ff18dcc, - 0x1857468f, 0x38c53ac4, 0xbf63f187, 0xecf9aa03, 0x6b5f6140, - 0x942ff912, 0x13893251, 0x401369d5, 0xc7b5a296, 0xe727dedd, - 0x6081159e, 0x331b4e1a, 0xb4bd8559, 0x723fb68c, 0xf5997dcf, - 0xa603264b, 0x21a5ed08, 0x01379143, 0x86915a00, 0xd50b0184, - 0x52adcac7, 0x837e606f, 0x04d8ab2c, 0x5742f0a8, 0xd0e43beb, - 0xf07647a0, 0x77d08ce3, 0x244ad767, 0xa3ec1c24, 0x656e2ff1, - 0xe2c8e4b2, 0xb152bf36, 0x36f47475, 0x1666083e, 0x91c0c37d, - 0xc25a98f9, 0x45fc53ba, 0xe7caae1c, 0x606c655f, 0x33f63edb, - 0xb450f598, 0x94c289d3, 0x13644290, 0x40fe1914, 0xc758d257, - 0x01dae182, 0x867c2ac1, 0xd5e67145, 0x5240ba06, 0x72d2c64d, - 0xf5740d0e, 0xa6ee568a, 0x21489dc9, 0xf09b3761, 0x773dfc22, - 0x24a7a7a6, 0xa3016ce5, 0x839310ae, 0x0435dbed, 0x57af8069, - 0xd0094b2a, 0x168b78ff, 0x912db3bc, 0xc2b7e838, 0x4511237b, - 0x65835f30, 0xe2259473, 0xb1bfcff7, 0x361904b4, 0xc9699ce6, - 0x4ecf57a5, 0x1d550c21, 0x9af3c762, 0xba61bb29, 0x3dc7706a, - 0x6e5d2bee, 0xe9fbe0ad, 0x2f79d378, 0xa8df183b, 0xfb4543bf, - 0x7ce388fc, 0x5c71f4b7, 0xdbd73ff4, 0x884d6470, 0x0febaf33, - 0xde38059b, 0x599eced8, 0x0a04955c, 0x8da25e1f, 0xad302254, - 0x2a96e917, 0x790cb293, 0xfeaa79d0, 0x38284a05, 0xbf8e8146, - 0xec14dac2, 0x6bb21181, 0x4b206dca, 0xcc86a689, 0x9f1cfd0d, - 0x18ba364e}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x0000000000000000, 0x43cba68700000000, 0xc7903cd400000000, - 0x845b9a5300000000, 0xcf27087300000000, 0x8cecaef400000000, - 0x08b734a700000000, 0x4b7c922000000000, 0x9e4f10e600000000, - 0xdd84b66100000000, 0x59df2c3200000000, 0x1a148ab500000000, - 0x5168189500000000, 0x12a3be1200000000, 0x96f8244100000000, - 0xd53382c600000000, 0x7d99511700000000, 0x3e52f79000000000, - 0xba096dc300000000, 0xf9c2cb4400000000, 0xb2be596400000000, - 0xf175ffe300000000, 0x752e65b000000000, 0x36e5c33700000000, - 0xe3d641f100000000, 0xa01de77600000000, 0x24467d2500000000, - 0x678ddba200000000, 0x2cf1498200000000, 0x6f3aef0500000000, - 0xeb61755600000000, 0xa8aad3d100000000, 0xfa32a32e00000000, - 0xb9f905a900000000, 0x3da29ffa00000000, 0x7e69397d00000000, - 0x3515ab5d00000000, 0x76de0dda00000000, 0xf285978900000000, - 0xb14e310e00000000, 0x647db3c800000000, 0x27b6154f00000000, - 0xa3ed8f1c00000000, 0xe026299b00000000, 0xab5abbbb00000000, - 0xe8911d3c00000000, 0x6cca876f00000000, 0x2f0121e800000000, - 0x87abf23900000000, 0xc46054be00000000, 0x403bceed00000000, - 0x03f0686a00000000, 0x488cfa4a00000000, 0x0b475ccd00000000, - 0x8f1cc69e00000000, 0xccd7601900000000, 0x19e4e2df00000000, - 0x5a2f445800000000, 0xde74de0b00000000, 0x9dbf788c00000000, - 0xd6c3eaac00000000, 0x95084c2b00000000, 0x1153d67800000000, - 0x529870ff00000000, 0xf465465d00000000, 0xb7aee0da00000000, - 0x33f57a8900000000, 0x703edc0e00000000, 0x3b424e2e00000000, - 0x7889e8a900000000, 0xfcd272fa00000000, 0xbf19d47d00000000, - 0x6a2a56bb00000000, 0x29e1f03c00000000, 0xadba6a6f00000000, - 0xee71cce800000000, 0xa50d5ec800000000, 0xe6c6f84f00000000, - 0x629d621c00000000, 0x2156c49b00000000, 0x89fc174a00000000, - 0xca37b1cd00000000, 0x4e6c2b9e00000000, 0x0da78d1900000000, - 0x46db1f3900000000, 0x0510b9be00000000, 0x814b23ed00000000, - 0xc280856a00000000, 0x17b307ac00000000, 0x5478a12b00000000, - 0xd0233b7800000000, 0x93e89dff00000000, 0xd8940fdf00000000, - 0x9b5fa95800000000, 0x1f04330b00000000, 0x5ccf958c00000000, - 0x0e57e57300000000, 0x4d9c43f400000000, 0xc9c7d9a700000000, - 0x8a0c7f2000000000, 0xc170ed0000000000, 0x82bb4b8700000000, - 0x06e0d1d400000000, 0x452b775300000000, 0x9018f59500000000, - 0xd3d3531200000000, 0x5788c94100000000, 0x14436fc600000000, - 0x5f3ffde600000000, 0x1cf45b6100000000, 0x98afc13200000000, - 0xdb6467b500000000, 0x73ceb46400000000, 0x300512e300000000, - 0xb45e88b000000000, 0xf7952e3700000000, 0xbce9bc1700000000, - 0xff221a9000000000, 0x7b7980c300000000, 0x38b2264400000000, - 0xed81a48200000000, 0xae4a020500000000, 0x2a11985600000000, - 0x69da3ed100000000, 0x22a6acf100000000, 0x616d0a7600000000, - 0xe536902500000000, 0xa6fd36a200000000, 0xe8cb8cba00000000, - 0xab002a3d00000000, 0x2f5bb06e00000000, 0x6c9016e900000000, - 0x27ec84c900000000, 0x6427224e00000000, 0xe07cb81d00000000, - 0xa3b71e9a00000000, 0x76849c5c00000000, 0x354f3adb00000000, - 0xb114a08800000000, 0xf2df060f00000000, 0xb9a3942f00000000, - 0xfa6832a800000000, 0x7e33a8fb00000000, 0x3df80e7c00000000, - 0x9552ddad00000000, 0xd6997b2a00000000, 0x52c2e17900000000, - 0x110947fe00000000, 0x5a75d5de00000000, 0x19be735900000000, - 0x9de5e90a00000000, 0xde2e4f8d00000000, 0x0b1dcd4b00000000, - 0x48d66bcc00000000, 0xcc8df19f00000000, 0x8f46571800000000, - 0xc43ac53800000000, 0x87f163bf00000000, 0x03aaf9ec00000000, - 0x40615f6b00000000, 0x12f92f9400000000, 0x5132891300000000, - 0xd569134000000000, 0x96a2b5c700000000, 0xddde27e700000000, - 0x9e15816000000000, 0x1a4e1b3300000000, 0x5985bdb400000000, - 0x8cb63f7200000000, 0xcf7d99f500000000, 0x4b2603a600000000, - 0x08eda52100000000, 0x4391370100000000, 0x005a918600000000, - 0x84010bd500000000, 0xc7caad5200000000, 0x6f607e8300000000, - 0x2cabd80400000000, 0xa8f0425700000000, 0xeb3be4d000000000, - 0xa04776f000000000, 0xe38cd07700000000, 0x67d74a2400000000, - 0x241ceca300000000, 0xf12f6e6500000000, 0xb2e4c8e200000000, - 0x36bf52b100000000, 0x7574f43600000000, 0x3e08661600000000, - 0x7dc3c09100000000, 0xf9985ac200000000, 0xba53fc4500000000, - 0x1caecae700000000, 0x5f656c6000000000, 0xdb3ef63300000000, - 0x98f550b400000000, 0xd389c29400000000, 0x9042641300000000, - 0x1419fe4000000000, 0x57d258c700000000, 0x82e1da0100000000, - 0xc12a7c8600000000, 0x4571e6d500000000, 0x06ba405200000000, - 0x4dc6d27200000000, 0x0e0d74f500000000, 0x8a56eea600000000, - 0xc99d482100000000, 0x61379bf000000000, 0x22fc3d7700000000, - 0xa6a7a72400000000, 0xe56c01a300000000, 0xae10938300000000, - 0xeddb350400000000, 0x6980af5700000000, 0x2a4b09d000000000, - 0xff788b1600000000, 0xbcb32d9100000000, 0x38e8b7c200000000, - 0x7b23114500000000, 0x305f836500000000, 0x739425e200000000, - 0xf7cfbfb100000000, 0xb404193600000000, 0xe69c69c900000000, - 0xa557cf4e00000000, 0x210c551d00000000, 0x62c7f39a00000000, - 0x29bb61ba00000000, 0x6a70c73d00000000, 0xee2b5d6e00000000, - 0xade0fbe900000000, 0x78d3792f00000000, 0x3b18dfa800000000, - 0xbf4345fb00000000, 0xfc88e37c00000000, 0xb7f4715c00000000, - 0xf43fd7db00000000, 0x70644d8800000000, 0x33afeb0f00000000, - 0x9b0538de00000000, 0xd8ce9e5900000000, 0x5c95040a00000000, - 0x1f5ea28d00000000, 0x542230ad00000000, 0x17e9962a00000000, - 0x93b20c7900000000, 0xd079aafe00000000, 0x054a283800000000, - 0x46818ebf00000000, 0xc2da14ec00000000, 0x8111b26b00000000, - 0xca6d204b00000000, 0x89a686cc00000000, 0x0dfd1c9f00000000, - 0x4e36ba1800000000}, - {0x0000000000000000, 0xe1b652ef00000000, 0x836bd40500000000, - 0x62dd86ea00000000, 0x06d7a80b00000000, 0xe761fae400000000, - 0x85bc7c0e00000000, 0x640a2ee100000000, 0x0cae511700000000, - 0xed1803f800000000, 0x8fc5851200000000, 0x6e73d7fd00000000, - 0x0a79f91c00000000, 0xebcfabf300000000, 0x89122d1900000000, - 0x68a47ff600000000, 0x185ca32e00000000, 0xf9eaf1c100000000, - 0x9b37772b00000000, 0x7a8125c400000000, 0x1e8b0b2500000000, - 0xff3d59ca00000000, 0x9de0df2000000000, 0x7c568dcf00000000, - 0x14f2f23900000000, 0xf544a0d600000000, 0x9799263c00000000, - 0x762f74d300000000, 0x12255a3200000000, 0xf39308dd00000000, - 0x914e8e3700000000, 0x70f8dcd800000000, 0x30b8465d00000000, - 0xd10e14b200000000, 0xb3d3925800000000, 0x5265c0b700000000, - 0x366fee5600000000, 0xd7d9bcb900000000, 0xb5043a5300000000, - 0x54b268bc00000000, 0x3c16174a00000000, 0xdda045a500000000, - 0xbf7dc34f00000000, 0x5ecb91a000000000, 0x3ac1bf4100000000, - 0xdb77edae00000000, 0xb9aa6b4400000000, 0x581c39ab00000000, - 0x28e4e57300000000, 0xc952b79c00000000, 0xab8f317600000000, - 0x4a39639900000000, 0x2e334d7800000000, 0xcf851f9700000000, - 0xad58997d00000000, 0x4ceecb9200000000, 0x244ab46400000000, - 0xc5fce68b00000000, 0xa721606100000000, 0x4697328e00000000, - 0x229d1c6f00000000, 0xc32b4e8000000000, 0xa1f6c86a00000000, - 0x40409a8500000000, 0x60708dba00000000, 0x81c6df5500000000, - 0xe31b59bf00000000, 0x02ad0b5000000000, 0x66a725b100000000, - 0x8711775e00000000, 0xe5ccf1b400000000, 0x047aa35b00000000, - 0x6cdedcad00000000, 0x8d688e4200000000, 0xefb508a800000000, - 0x0e035a4700000000, 0x6a0974a600000000, 0x8bbf264900000000, - 0xe962a0a300000000, 0x08d4f24c00000000, 0x782c2e9400000000, - 0x999a7c7b00000000, 0xfb47fa9100000000, 0x1af1a87e00000000, - 0x7efb869f00000000, 0x9f4dd47000000000, 0xfd90529a00000000, - 0x1c26007500000000, 0x74827f8300000000, 0x95342d6c00000000, - 0xf7e9ab8600000000, 0x165ff96900000000, 0x7255d78800000000, - 0x93e3856700000000, 0xf13e038d00000000, 0x1088516200000000, - 0x50c8cbe700000000, 0xb17e990800000000, 0xd3a31fe200000000, - 0x32154d0d00000000, 0x561f63ec00000000, 0xb7a9310300000000, - 0xd574b7e900000000, 0x34c2e50600000000, 0x5c669af000000000, - 0xbdd0c81f00000000, 0xdf0d4ef500000000, 0x3ebb1c1a00000000, - 0x5ab132fb00000000, 0xbb07601400000000, 0xd9dae6fe00000000, - 0x386cb41100000000, 0x489468c900000000, 0xa9223a2600000000, - 0xcbffbccc00000000, 0x2a49ee2300000000, 0x4e43c0c200000000, - 0xaff5922d00000000, 0xcd2814c700000000, 0x2c9e462800000000, - 0x443a39de00000000, 0xa58c6b3100000000, 0xc751eddb00000000, - 0x26e7bf3400000000, 0x42ed91d500000000, 0xa35bc33a00000000, - 0xc18645d000000000, 0x2030173f00000000, 0x81e66bae00000000, - 0x6050394100000000, 0x028dbfab00000000, 0xe33bed4400000000, - 0x8731c3a500000000, 0x6687914a00000000, 0x045a17a000000000, - 0xe5ec454f00000000, 0x8d483ab900000000, 0x6cfe685600000000, - 0x0e23eebc00000000, 0xef95bc5300000000, 0x8b9f92b200000000, - 0x6a29c05d00000000, 0x08f446b700000000, 0xe942145800000000, - 0x99bac88000000000, 0x780c9a6f00000000, 0x1ad11c8500000000, - 0xfb674e6a00000000, 0x9f6d608b00000000, 0x7edb326400000000, - 0x1c06b48e00000000, 0xfdb0e66100000000, 0x9514999700000000, - 0x74a2cb7800000000, 0x167f4d9200000000, 0xf7c91f7d00000000, - 0x93c3319c00000000, 0x7275637300000000, 0x10a8e59900000000, - 0xf11eb77600000000, 0xb15e2df300000000, 0x50e87f1c00000000, - 0x3235f9f600000000, 0xd383ab1900000000, 0xb78985f800000000, - 0x563fd71700000000, 0x34e251fd00000000, 0xd554031200000000, - 0xbdf07ce400000000, 0x5c462e0b00000000, 0x3e9ba8e100000000, - 0xdf2dfa0e00000000, 0xbb27d4ef00000000, 0x5a91860000000000, - 0x384c00ea00000000, 0xd9fa520500000000, 0xa9028edd00000000, - 0x48b4dc3200000000, 0x2a695ad800000000, 0xcbdf083700000000, - 0xafd526d600000000, 0x4e63743900000000, 0x2cbef2d300000000, - 0xcd08a03c00000000, 0xa5acdfca00000000, 0x441a8d2500000000, - 0x26c70bcf00000000, 0xc771592000000000, 0xa37b77c100000000, - 0x42cd252e00000000, 0x2010a3c400000000, 0xc1a6f12b00000000, - 0xe196e61400000000, 0x0020b4fb00000000, 0x62fd321100000000, - 0x834b60fe00000000, 0xe7414e1f00000000, 0x06f71cf000000000, - 0x642a9a1a00000000, 0x859cc8f500000000, 0xed38b70300000000, - 0x0c8ee5ec00000000, 0x6e53630600000000, 0x8fe531e900000000, - 0xebef1f0800000000, 0x0a594de700000000, 0x6884cb0d00000000, - 0x893299e200000000, 0xf9ca453a00000000, 0x187c17d500000000, - 0x7aa1913f00000000, 0x9b17c3d000000000, 0xff1ded3100000000, - 0x1eabbfde00000000, 0x7c76393400000000, 0x9dc06bdb00000000, - 0xf564142d00000000, 0x14d246c200000000, 0x760fc02800000000, - 0x97b992c700000000, 0xf3b3bc2600000000, 0x1205eec900000000, - 0x70d8682300000000, 0x916e3acc00000000, 0xd12ea04900000000, - 0x3098f2a600000000, 0x5245744c00000000, 0xb3f326a300000000, - 0xd7f9084200000000, 0x364f5aad00000000, 0x5492dc4700000000, - 0xb5248ea800000000, 0xdd80f15e00000000, 0x3c36a3b100000000, - 0x5eeb255b00000000, 0xbf5d77b400000000, 0xdb57595500000000, - 0x3ae10bba00000000, 0x583c8d5000000000, 0xb98adfbf00000000, - 0xc972036700000000, 0x28c4518800000000, 0x4a19d76200000000, - 0xabaf858d00000000, 0xcfa5ab6c00000000, 0x2e13f98300000000, - 0x4cce7f6900000000, 0xad782d8600000000, 0xc5dc527000000000, - 0x246a009f00000000, 0x46b7867500000000, 0xa701d49a00000000, - 0xc30bfa7b00000000, 0x22bda89400000000, 0x40602e7e00000000, - 0xa1d67c9100000000}, - {0x0000000000000000, 0x5880e2d700000000, 0xf106b47400000000, - 0xa98656a300000000, 0xe20d68e900000000, 0xba8d8a3e00000000, - 0x130bdc9d00000000, 0x4b8b3e4a00000000, 0x851da10900000000, - 0xdd9d43de00000000, 0x741b157d00000000, 0x2c9bf7aa00000000, - 0x6710c9e000000000, 0x3f902b3700000000, 0x96167d9400000000, - 0xce969f4300000000, 0x0a3b421300000000, 0x52bba0c400000000, - 0xfb3df66700000000, 0xa3bd14b000000000, 0xe8362afa00000000, - 0xb0b6c82d00000000, 0x19309e8e00000000, 0x41b07c5900000000, - 0x8f26e31a00000000, 0xd7a601cd00000000, 0x7e20576e00000000, - 0x26a0b5b900000000, 0x6d2b8bf300000000, 0x35ab692400000000, - 0x9c2d3f8700000000, 0xc4addd5000000000, 0x1476842600000000, - 0x4cf666f100000000, 0xe570305200000000, 0xbdf0d28500000000, - 0xf67beccf00000000, 0xaefb0e1800000000, 0x077d58bb00000000, - 0x5ffdba6c00000000, 0x916b252f00000000, 0xc9ebc7f800000000, - 0x606d915b00000000, 0x38ed738c00000000, 0x73664dc600000000, - 0x2be6af1100000000, 0x8260f9b200000000, 0xdae01b6500000000, - 0x1e4dc63500000000, 0x46cd24e200000000, 0xef4b724100000000, - 0xb7cb909600000000, 0xfc40aedc00000000, 0xa4c04c0b00000000, - 0x0d461aa800000000, 0x55c6f87f00000000, 0x9b50673c00000000, - 0xc3d085eb00000000, 0x6a56d34800000000, 0x32d6319f00000000, - 0x795d0fd500000000, 0x21dded0200000000, 0x885bbba100000000, - 0xd0db597600000000, 0x28ec084d00000000, 0x706cea9a00000000, - 0xd9eabc3900000000, 0x816a5eee00000000, 0xcae160a400000000, - 0x9261827300000000, 0x3be7d4d000000000, 0x6367360700000000, - 0xadf1a94400000000, 0xf5714b9300000000, 0x5cf71d3000000000, - 0x0477ffe700000000, 0x4ffcc1ad00000000, 0x177c237a00000000, - 0xbefa75d900000000, 0xe67a970e00000000, 0x22d74a5e00000000, - 0x7a57a88900000000, 0xd3d1fe2a00000000, 0x8b511cfd00000000, - 0xc0da22b700000000, 0x985ac06000000000, 0x31dc96c300000000, - 0x695c741400000000, 0xa7caeb5700000000, 0xff4a098000000000, - 0x56cc5f2300000000, 0x0e4cbdf400000000, 0x45c783be00000000, - 0x1d47616900000000, 0xb4c137ca00000000, 0xec41d51d00000000, - 0x3c9a8c6b00000000, 0x641a6ebc00000000, 0xcd9c381f00000000, - 0x951cdac800000000, 0xde97e48200000000, 0x8617065500000000, - 0x2f9150f600000000, 0x7711b22100000000, 0xb9872d6200000000, - 0xe107cfb500000000, 0x4881991600000000, 0x10017bc100000000, - 0x5b8a458b00000000, 0x030aa75c00000000, 0xaa8cf1ff00000000, - 0xf20c132800000000, 0x36a1ce7800000000, 0x6e212caf00000000, - 0xc7a77a0c00000000, 0x9f2798db00000000, 0xd4aca69100000000, - 0x8c2c444600000000, 0x25aa12e500000000, 0x7d2af03200000000, - 0xb3bc6f7100000000, 0xeb3c8da600000000, 0x42badb0500000000, - 0x1a3a39d200000000, 0x51b1079800000000, 0x0931e54f00000000, - 0xa0b7b3ec00000000, 0xf837513b00000000, 0x50d8119a00000000, - 0x0858f34d00000000, 0xa1dea5ee00000000, 0xf95e473900000000, - 0xb2d5797300000000, 0xea559ba400000000, 0x43d3cd0700000000, - 0x1b532fd000000000, 0xd5c5b09300000000, 0x8d45524400000000, - 0x24c304e700000000, 0x7c43e63000000000, 0x37c8d87a00000000, - 0x6f483aad00000000, 0xc6ce6c0e00000000, 0x9e4e8ed900000000, - 0x5ae3538900000000, 0x0263b15e00000000, 0xabe5e7fd00000000, - 0xf365052a00000000, 0xb8ee3b6000000000, 0xe06ed9b700000000, - 0x49e88f1400000000, 0x11686dc300000000, 0xdffef28000000000, - 0x877e105700000000, 0x2ef846f400000000, 0x7678a42300000000, - 0x3df39a6900000000, 0x657378be00000000, 0xccf52e1d00000000, - 0x9475ccca00000000, 0x44ae95bc00000000, 0x1c2e776b00000000, - 0xb5a821c800000000, 0xed28c31f00000000, 0xa6a3fd5500000000, - 0xfe231f8200000000, 0x57a5492100000000, 0x0f25abf600000000, - 0xc1b334b500000000, 0x9933d66200000000, 0x30b580c100000000, - 0x6835621600000000, 0x23be5c5c00000000, 0x7b3ebe8b00000000, - 0xd2b8e82800000000, 0x8a380aff00000000, 0x4e95d7af00000000, - 0x1615357800000000, 0xbf9363db00000000, 0xe713810c00000000, - 0xac98bf4600000000, 0xf4185d9100000000, 0x5d9e0b3200000000, - 0x051ee9e500000000, 0xcb8876a600000000, 0x9308947100000000, - 0x3a8ec2d200000000, 0x620e200500000000, 0x29851e4f00000000, - 0x7105fc9800000000, 0xd883aa3b00000000, 0x800348ec00000000, - 0x783419d700000000, 0x20b4fb0000000000, 0x8932ada300000000, - 0xd1b24f7400000000, 0x9a39713e00000000, 0xc2b993e900000000, - 0x6b3fc54a00000000, 0x33bf279d00000000, 0xfd29b8de00000000, - 0xa5a95a0900000000, 0x0c2f0caa00000000, 0x54afee7d00000000, - 0x1f24d03700000000, 0x47a432e000000000, 0xee22644300000000, - 0xb6a2869400000000, 0x720f5bc400000000, 0x2a8fb91300000000, - 0x8309efb000000000, 0xdb890d6700000000, 0x9002332d00000000, - 0xc882d1fa00000000, 0x6104875900000000, 0x3984658e00000000, - 0xf712facd00000000, 0xaf92181a00000000, 0x06144eb900000000, - 0x5e94ac6e00000000, 0x151f922400000000, 0x4d9f70f300000000, - 0xe419265000000000, 0xbc99c48700000000, 0x6c429df100000000, - 0x34c27f2600000000, 0x9d44298500000000, 0xc5c4cb5200000000, - 0x8e4ff51800000000, 0xd6cf17cf00000000, 0x7f49416c00000000, - 0x27c9a3bb00000000, 0xe95f3cf800000000, 0xb1dfde2f00000000, - 0x1859888c00000000, 0x40d96a5b00000000, 0x0b52541100000000, - 0x53d2b6c600000000, 0xfa54e06500000000, 0xa2d402b200000000, - 0x6679dfe200000000, 0x3ef93d3500000000, 0x977f6b9600000000, - 0xcfff894100000000, 0x8474b70b00000000, 0xdcf455dc00000000, - 0x7572037f00000000, 0x2df2e1a800000000, 0xe3647eeb00000000, - 0xbbe49c3c00000000, 0x1262ca9f00000000, 0x4ae2284800000000, - 0x0169160200000000, 0x59e9f4d500000000, 0xf06fa27600000000, - 0xa8ef40a100000000}, - {0x0000000000000000, 0x463b676500000000, 0x8c76ceca00000000, - 0xca4da9af00000000, 0x59ebed4e00000000, 0x1fd08a2b00000000, - 0xd59d238400000000, 0x93a644e100000000, 0xb2d6db9d00000000, - 0xf4edbcf800000000, 0x3ea0155700000000, 0x789b723200000000, - 0xeb3d36d300000000, 0xad0651b600000000, 0x674bf81900000000, - 0x21709f7c00000000, 0x25abc6e000000000, 0x6390a18500000000, - 0xa9dd082a00000000, 0xefe66f4f00000000, 0x7c402bae00000000, - 0x3a7b4ccb00000000, 0xf036e56400000000, 0xb60d820100000000, - 0x977d1d7d00000000, 0xd1467a1800000000, 0x1b0bd3b700000000, - 0x5d30b4d200000000, 0xce96f03300000000, 0x88ad975600000000, - 0x42e03ef900000000, 0x04db599c00000000, 0x0b50fc1a00000000, - 0x4d6b9b7f00000000, 0x872632d000000000, 0xc11d55b500000000, - 0x52bb115400000000, 0x1480763100000000, 0xdecddf9e00000000, - 0x98f6b8fb00000000, 0xb986278700000000, 0xffbd40e200000000, - 0x35f0e94d00000000, 0x73cb8e2800000000, 0xe06dcac900000000, - 0xa656adac00000000, 0x6c1b040300000000, 0x2a20636600000000, - 0x2efb3afa00000000, 0x68c05d9f00000000, 0xa28df43000000000, - 0xe4b6935500000000, 0x7710d7b400000000, 0x312bb0d100000000, - 0xfb66197e00000000, 0xbd5d7e1b00000000, 0x9c2de16700000000, - 0xda16860200000000, 0x105b2fad00000000, 0x566048c800000000, - 0xc5c60c2900000000, 0x83fd6b4c00000000, 0x49b0c2e300000000, - 0x0f8ba58600000000, 0x16a0f83500000000, 0x509b9f5000000000, - 0x9ad636ff00000000, 0xdced519a00000000, 0x4f4b157b00000000, - 0x0970721e00000000, 0xc33ddbb100000000, 0x8506bcd400000000, - 0xa47623a800000000, 0xe24d44cd00000000, 0x2800ed6200000000, - 0x6e3b8a0700000000, 0xfd9dcee600000000, 0xbba6a98300000000, - 0x71eb002c00000000, 0x37d0674900000000, 0x330b3ed500000000, - 0x753059b000000000, 0xbf7df01f00000000, 0xf946977a00000000, - 0x6ae0d39b00000000, 0x2cdbb4fe00000000, 0xe6961d5100000000, - 0xa0ad7a3400000000, 0x81dde54800000000, 0xc7e6822d00000000, - 0x0dab2b8200000000, 0x4b904ce700000000, 0xd836080600000000, - 0x9e0d6f6300000000, 0x5440c6cc00000000, 0x127ba1a900000000, - 0x1df0042f00000000, 0x5bcb634a00000000, 0x9186cae500000000, - 0xd7bdad8000000000, 0x441be96100000000, 0x02208e0400000000, - 0xc86d27ab00000000, 0x8e5640ce00000000, 0xaf26dfb200000000, - 0xe91db8d700000000, 0x2350117800000000, 0x656b761d00000000, - 0xf6cd32fc00000000, 0xb0f6559900000000, 0x7abbfc3600000000, - 0x3c809b5300000000, 0x385bc2cf00000000, 0x7e60a5aa00000000, - 0xb42d0c0500000000, 0xf2166b6000000000, 0x61b02f8100000000, - 0x278b48e400000000, 0xedc6e14b00000000, 0xabfd862e00000000, - 0x8a8d195200000000, 0xccb67e3700000000, 0x06fbd79800000000, - 0x40c0b0fd00000000, 0xd366f41c00000000, 0x955d937900000000, - 0x5f103ad600000000, 0x192b5db300000000, 0x2c40f16b00000000, - 0x6a7b960e00000000, 0xa0363fa100000000, 0xe60d58c400000000, - 0x75ab1c2500000000, 0x33907b4000000000, 0xf9ddd2ef00000000, - 0xbfe6b58a00000000, 0x9e962af600000000, 0xd8ad4d9300000000, - 0x12e0e43c00000000, 0x54db835900000000, 0xc77dc7b800000000, - 0x8146a0dd00000000, 0x4b0b097200000000, 0x0d306e1700000000, - 0x09eb378b00000000, 0x4fd050ee00000000, 0x859df94100000000, - 0xc3a69e2400000000, 0x5000dac500000000, 0x163bbda000000000, - 0xdc76140f00000000, 0x9a4d736a00000000, 0xbb3dec1600000000, - 0xfd068b7300000000, 0x374b22dc00000000, 0x717045b900000000, - 0xe2d6015800000000, 0xa4ed663d00000000, 0x6ea0cf9200000000, - 0x289ba8f700000000, 0x27100d7100000000, 0x612b6a1400000000, - 0xab66c3bb00000000, 0xed5da4de00000000, 0x7efbe03f00000000, - 0x38c0875a00000000, 0xf28d2ef500000000, 0xb4b6499000000000, - 0x95c6d6ec00000000, 0xd3fdb18900000000, 0x19b0182600000000, - 0x5f8b7f4300000000, 0xcc2d3ba200000000, 0x8a165cc700000000, - 0x405bf56800000000, 0x0660920d00000000, 0x02bbcb9100000000, - 0x4480acf400000000, 0x8ecd055b00000000, 0xc8f6623e00000000, - 0x5b5026df00000000, 0x1d6b41ba00000000, 0xd726e81500000000, - 0x911d8f7000000000, 0xb06d100c00000000, 0xf656776900000000, - 0x3c1bdec600000000, 0x7a20b9a300000000, 0xe986fd4200000000, - 0xafbd9a2700000000, 0x65f0338800000000, 0x23cb54ed00000000, - 0x3ae0095e00000000, 0x7cdb6e3b00000000, 0xb696c79400000000, - 0xf0ada0f100000000, 0x630be41000000000, 0x2530837500000000, - 0xef7d2ada00000000, 0xa9464dbf00000000, 0x8836d2c300000000, - 0xce0db5a600000000, 0x04401c0900000000, 0x427b7b6c00000000, - 0xd1dd3f8d00000000, 0x97e658e800000000, 0x5dabf14700000000, - 0x1b90962200000000, 0x1f4bcfbe00000000, 0x5970a8db00000000, - 0x933d017400000000, 0xd506661100000000, 0x46a022f000000000, - 0x009b459500000000, 0xcad6ec3a00000000, 0x8ced8b5f00000000, - 0xad9d142300000000, 0xeba6734600000000, 0x21ebdae900000000, - 0x67d0bd8c00000000, 0xf476f96d00000000, 0xb24d9e0800000000, - 0x780037a700000000, 0x3e3b50c200000000, 0x31b0f54400000000, - 0x778b922100000000, 0xbdc63b8e00000000, 0xfbfd5ceb00000000, - 0x685b180a00000000, 0x2e607f6f00000000, 0xe42dd6c000000000, - 0xa216b1a500000000, 0x83662ed900000000, 0xc55d49bc00000000, - 0x0f10e01300000000, 0x492b877600000000, 0xda8dc39700000000, - 0x9cb6a4f200000000, 0x56fb0d5d00000000, 0x10c06a3800000000, - 0x141b33a400000000, 0x522054c100000000, 0x986dfd6e00000000, - 0xde569a0b00000000, 0x4df0deea00000000, 0x0bcbb98f00000000, - 0xc186102000000000, 0x87bd774500000000, 0xa6cde83900000000, - 0xe0f68f5c00000000, 0x2abb26f300000000, 0x6c80419600000000, - 0xff26057700000000, 0xb91d621200000000, 0x7350cbbd00000000, - 0x356bacd800000000}, - {0x0000000000000000, 0x9e83da9f00000000, 0x7d01c4e400000000, - 0xe3821e7b00000000, 0xbb04f91200000000, 0x2587238d00000000, - 0xc6053df600000000, 0x5886e76900000000, 0x7609f22500000000, - 0xe88a28ba00000000, 0x0b0836c100000000, 0x958bec5e00000000, - 0xcd0d0b3700000000, 0x538ed1a800000000, 0xb00ccfd300000000, - 0x2e8f154c00000000, 0xec12e44b00000000, 0x72913ed400000000, - 0x911320af00000000, 0x0f90fa3000000000, 0x57161d5900000000, - 0xc995c7c600000000, 0x2a17d9bd00000000, 0xb494032200000000, - 0x9a1b166e00000000, 0x0498ccf100000000, 0xe71ad28a00000000, - 0x7999081500000000, 0x211fef7c00000000, 0xbf9c35e300000000, - 0x5c1e2b9800000000, 0xc29df10700000000, 0xd825c89700000000, - 0x46a6120800000000, 0xa5240c7300000000, 0x3ba7d6ec00000000, - 0x6321318500000000, 0xfda2eb1a00000000, 0x1e20f56100000000, - 0x80a32ffe00000000, 0xae2c3ab200000000, 0x30afe02d00000000, - 0xd32dfe5600000000, 0x4dae24c900000000, 0x1528c3a000000000, - 0x8bab193f00000000, 0x6829074400000000, 0xf6aadddb00000000, - 0x34372cdc00000000, 0xaab4f64300000000, 0x4936e83800000000, - 0xd7b532a700000000, 0x8f33d5ce00000000, 0x11b00f5100000000, - 0xf232112a00000000, 0x6cb1cbb500000000, 0x423edef900000000, - 0xdcbd046600000000, 0x3f3f1a1d00000000, 0xa1bcc08200000000, - 0xf93a27eb00000000, 0x67b9fd7400000000, 0x843be30f00000000, - 0x1ab8399000000000, 0xf14de1f400000000, 0x6fce3b6b00000000, - 0x8c4c251000000000, 0x12cfff8f00000000, 0x4a4918e600000000, - 0xd4cac27900000000, 0x3748dc0200000000, 0xa9cb069d00000000, - 0x874413d100000000, 0x19c7c94e00000000, 0xfa45d73500000000, - 0x64c60daa00000000, 0x3c40eac300000000, 0xa2c3305c00000000, - 0x41412e2700000000, 0xdfc2f4b800000000, 0x1d5f05bf00000000, - 0x83dcdf2000000000, 0x605ec15b00000000, 0xfedd1bc400000000, - 0xa65bfcad00000000, 0x38d8263200000000, 0xdb5a384900000000, - 0x45d9e2d600000000, 0x6b56f79a00000000, 0xf5d52d0500000000, - 0x1657337e00000000, 0x88d4e9e100000000, 0xd0520e8800000000, - 0x4ed1d41700000000, 0xad53ca6c00000000, 0x33d010f300000000, - 0x2968296300000000, 0xb7ebf3fc00000000, 0x5469ed8700000000, - 0xcaea371800000000, 0x926cd07100000000, 0x0cef0aee00000000, - 0xef6d149500000000, 0x71eece0a00000000, 0x5f61db4600000000, - 0xc1e201d900000000, 0x22601fa200000000, 0xbce3c53d00000000, - 0xe465225400000000, 0x7ae6f8cb00000000, 0x9964e6b000000000, - 0x07e73c2f00000000, 0xc57acd2800000000, 0x5bf917b700000000, - 0xb87b09cc00000000, 0x26f8d35300000000, 0x7e7e343a00000000, - 0xe0fdeea500000000, 0x037ff0de00000000, 0x9dfc2a4100000000, - 0xb3733f0d00000000, 0x2df0e59200000000, 0xce72fbe900000000, - 0x50f1217600000000, 0x0877c61f00000000, 0x96f41c8000000000, - 0x757602fb00000000, 0xebf5d86400000000, 0xa39db33200000000, - 0x3d1e69ad00000000, 0xde9c77d600000000, 0x401fad4900000000, - 0x18994a2000000000, 0x861a90bf00000000, 0x65988ec400000000, - 0xfb1b545b00000000, 0xd594411700000000, 0x4b179b8800000000, - 0xa89585f300000000, 0x36165f6c00000000, 0x6e90b80500000000, - 0xf013629a00000000, 0x13917ce100000000, 0x8d12a67e00000000, - 0x4f8f577900000000, 0xd10c8de600000000, 0x328e939d00000000, - 0xac0d490200000000, 0xf48bae6b00000000, 0x6a0874f400000000, - 0x898a6a8f00000000, 0x1709b01000000000, 0x3986a55c00000000, - 0xa7057fc300000000, 0x448761b800000000, 0xda04bb2700000000, - 0x82825c4e00000000, 0x1c0186d100000000, 0xff8398aa00000000, - 0x6100423500000000, 0x7bb87ba500000000, 0xe53ba13a00000000, - 0x06b9bf4100000000, 0x983a65de00000000, 0xc0bc82b700000000, - 0x5e3f582800000000, 0xbdbd465300000000, 0x233e9ccc00000000, - 0x0db1898000000000, 0x9332531f00000000, 0x70b04d6400000000, - 0xee3397fb00000000, 0xb6b5709200000000, 0x2836aa0d00000000, - 0xcbb4b47600000000, 0x55376ee900000000, 0x97aa9fee00000000, - 0x0929457100000000, 0xeaab5b0a00000000, 0x7428819500000000, - 0x2cae66fc00000000, 0xb22dbc6300000000, 0x51afa21800000000, - 0xcf2c788700000000, 0xe1a36dcb00000000, 0x7f20b75400000000, - 0x9ca2a92f00000000, 0x022173b000000000, 0x5aa794d900000000, - 0xc4244e4600000000, 0x27a6503d00000000, 0xb9258aa200000000, - 0x52d052c600000000, 0xcc53885900000000, 0x2fd1962200000000, - 0xb1524cbd00000000, 0xe9d4abd400000000, 0x7757714b00000000, - 0x94d56f3000000000, 0x0a56b5af00000000, 0x24d9a0e300000000, - 0xba5a7a7c00000000, 0x59d8640700000000, 0xc75bbe9800000000, - 0x9fdd59f100000000, 0x015e836e00000000, 0xe2dc9d1500000000, - 0x7c5f478a00000000, 0xbec2b68d00000000, 0x20416c1200000000, - 0xc3c3726900000000, 0x5d40a8f600000000, 0x05c64f9f00000000, - 0x9b45950000000000, 0x78c78b7b00000000, 0xe64451e400000000, - 0xc8cb44a800000000, 0x56489e3700000000, 0xb5ca804c00000000, - 0x2b495ad300000000, 0x73cfbdba00000000, 0xed4c672500000000, - 0x0ece795e00000000, 0x904da3c100000000, 0x8af59a5100000000, - 0x147640ce00000000, 0xf7f45eb500000000, 0x6977842a00000000, - 0x31f1634300000000, 0xaf72b9dc00000000, 0x4cf0a7a700000000, - 0xd2737d3800000000, 0xfcfc687400000000, 0x627fb2eb00000000, - 0x81fdac9000000000, 0x1f7e760f00000000, 0x47f8916600000000, - 0xd97b4bf900000000, 0x3af9558200000000, 0xa47a8f1d00000000, - 0x66e77e1a00000000, 0xf864a48500000000, 0x1be6bafe00000000, - 0x8565606100000000, 0xdde3870800000000, 0x43605d9700000000, - 0xa0e243ec00000000, 0x3e61997300000000, 0x10ee8c3f00000000, - 0x8e6d56a000000000, 0x6def48db00000000, 0xf36c924400000000, - 0xabea752d00000000, 0x3569afb200000000, 0xd6ebb1c900000000, - 0x48686b5600000000}, - {0x0000000000000000, 0xc064281700000000, 0x80c9502e00000000, - 0x40ad783900000000, 0x0093a15c00000000, 0xc0f7894b00000000, - 0x805af17200000000, 0x403ed96500000000, 0x002643b900000000, - 0xc0426bae00000000, 0x80ef139700000000, 0x408b3b8000000000, - 0x00b5e2e500000000, 0xc0d1caf200000000, 0x807cb2cb00000000, - 0x40189adc00000000, 0x414af7a900000000, 0x812edfbe00000000, - 0xc183a78700000000, 0x01e78f9000000000, 0x41d956f500000000, - 0x81bd7ee200000000, 0xc11006db00000000, 0x01742ecc00000000, - 0x416cb41000000000, 0x81089c0700000000, 0xc1a5e43e00000000, - 0x01c1cc2900000000, 0x41ff154c00000000, 0x819b3d5b00000000, - 0xc136456200000000, 0x01526d7500000000, 0xc3929f8800000000, - 0x03f6b79f00000000, 0x435bcfa600000000, 0x833fe7b100000000, - 0xc3013ed400000000, 0x036516c300000000, 0x43c86efa00000000, - 0x83ac46ed00000000, 0xc3b4dc3100000000, 0x03d0f42600000000, - 0x437d8c1f00000000, 0x8319a40800000000, 0xc3277d6d00000000, - 0x0343557a00000000, 0x43ee2d4300000000, 0x838a055400000000, - 0x82d8682100000000, 0x42bc403600000000, 0x0211380f00000000, - 0xc275101800000000, 0x824bc97d00000000, 0x422fe16a00000000, - 0x0282995300000000, 0xc2e6b14400000000, 0x82fe2b9800000000, - 0x429a038f00000000, 0x02377bb600000000, 0xc25353a100000000, - 0x826d8ac400000000, 0x4209a2d300000000, 0x02a4daea00000000, - 0xc2c0f2fd00000000, 0xc7234eca00000000, 0x074766dd00000000, - 0x47ea1ee400000000, 0x878e36f300000000, 0xc7b0ef9600000000, - 0x07d4c78100000000, 0x4779bfb800000000, 0x871d97af00000000, - 0xc7050d7300000000, 0x0761256400000000, 0x47cc5d5d00000000, - 0x87a8754a00000000, 0xc796ac2f00000000, 0x07f2843800000000, - 0x475ffc0100000000, 0x873bd41600000000, 0x8669b96300000000, - 0x460d917400000000, 0x06a0e94d00000000, 0xc6c4c15a00000000, - 0x86fa183f00000000, 0x469e302800000000, 0x0633481100000000, - 0xc657600600000000, 0x864ffada00000000, 0x462bd2cd00000000, - 0x0686aaf400000000, 0xc6e282e300000000, 0x86dc5b8600000000, - 0x46b8739100000000, 0x06150ba800000000, 0xc67123bf00000000, - 0x04b1d14200000000, 0xc4d5f95500000000, 0x8478816c00000000, - 0x441ca97b00000000, 0x0422701e00000000, 0xc446580900000000, - 0x84eb203000000000, 0x448f082700000000, 0x049792fb00000000, - 0xc4f3baec00000000, 0x845ec2d500000000, 0x443aeac200000000, - 0x040433a700000000, 0xc4601bb000000000, 0x84cd638900000000, - 0x44a94b9e00000000, 0x45fb26eb00000000, 0x859f0efc00000000, - 0xc53276c500000000, 0x05565ed200000000, 0x456887b700000000, - 0x850cafa000000000, 0xc5a1d79900000000, 0x05c5ff8e00000000, - 0x45dd655200000000, 0x85b94d4500000000, 0xc514357c00000000, - 0x05701d6b00000000, 0x454ec40e00000000, 0x852aec1900000000, - 0xc587942000000000, 0x05e3bc3700000000, 0xcf41ed4f00000000, - 0x0f25c55800000000, 0x4f88bd6100000000, 0x8fec957600000000, - 0xcfd24c1300000000, 0x0fb6640400000000, 0x4f1b1c3d00000000, - 0x8f7f342a00000000, 0xcf67aef600000000, 0x0f0386e100000000, - 0x4faefed800000000, 0x8fcad6cf00000000, 0xcff40faa00000000, - 0x0f9027bd00000000, 0x4f3d5f8400000000, 0x8f59779300000000, - 0x8e0b1ae600000000, 0x4e6f32f100000000, 0x0ec24ac800000000, - 0xcea662df00000000, 0x8e98bbba00000000, 0x4efc93ad00000000, - 0x0e51eb9400000000, 0xce35c38300000000, 0x8e2d595f00000000, - 0x4e49714800000000, 0x0ee4097100000000, 0xce80216600000000, - 0x8ebef80300000000, 0x4edad01400000000, 0x0e77a82d00000000, - 0xce13803a00000000, 0x0cd372c700000000, 0xccb75ad000000000, - 0x8c1a22e900000000, 0x4c7e0afe00000000, 0x0c40d39b00000000, - 0xcc24fb8c00000000, 0x8c8983b500000000, 0x4cedaba200000000, - 0x0cf5317e00000000, 0xcc91196900000000, 0x8c3c615000000000, - 0x4c58494700000000, 0x0c66902200000000, 0xcc02b83500000000, - 0x8cafc00c00000000, 0x4ccbe81b00000000, 0x4d99856e00000000, - 0x8dfdad7900000000, 0xcd50d54000000000, 0x0d34fd5700000000, - 0x4d0a243200000000, 0x8d6e0c2500000000, 0xcdc3741c00000000, - 0x0da75c0b00000000, 0x4dbfc6d700000000, 0x8ddbeec000000000, - 0xcd7696f900000000, 0x0d12beee00000000, 0x4d2c678b00000000, - 0x8d484f9c00000000, 0xcde537a500000000, 0x0d811fb200000000, - 0x0862a38500000000, 0xc8068b9200000000, 0x88abf3ab00000000, - 0x48cfdbbc00000000, 0x08f102d900000000, 0xc8952ace00000000, - 0x883852f700000000, 0x485c7ae000000000, 0x0844e03c00000000, - 0xc820c82b00000000, 0x888db01200000000, 0x48e9980500000000, - 0x08d7416000000000, 0xc8b3697700000000, 0x881e114e00000000, - 0x487a395900000000, 0x4928542c00000000, 0x894c7c3b00000000, - 0xc9e1040200000000, 0x09852c1500000000, 0x49bbf57000000000, - 0x89dfdd6700000000, 0xc972a55e00000000, 0x09168d4900000000, - 0x490e179500000000, 0x896a3f8200000000, 0xc9c747bb00000000, - 0x09a36fac00000000, 0x499db6c900000000, 0x89f99ede00000000, - 0xc954e6e700000000, 0x0930cef000000000, 0xcbf03c0d00000000, - 0x0b94141a00000000, 0x4b396c2300000000, 0x8b5d443400000000, - 0xcb639d5100000000, 0x0b07b54600000000, 0x4baacd7f00000000, - 0x8bcee56800000000, 0xcbd67fb400000000, 0x0bb257a300000000, - 0x4b1f2f9a00000000, 0x8b7b078d00000000, 0xcb45dee800000000, - 0x0b21f6ff00000000, 0x4b8c8ec600000000, 0x8be8a6d100000000, - 0x8abacba400000000, 0x4adee3b300000000, 0x0a739b8a00000000, - 0xca17b39d00000000, 0x8a296af800000000, 0x4a4d42ef00000000, - 0x0ae03ad600000000, 0xca8412c100000000, 0x8a9c881d00000000, - 0x4af8a00a00000000, 0x0a55d83300000000, 0xca31f02400000000, - 0x8a0f294100000000, 0x4a6b015600000000, 0x0ac6796f00000000, - 0xcaa2517800000000}, - {0x0000000000000000, 0xd4ea739b00000000, 0xe9d396ed00000000, - 0x3d39e57600000000, 0x93a15c0000000000, 0x474b2f9b00000000, - 0x7a72caed00000000, 0xae98b97600000000, 0x2643b90000000000, - 0xf2a9ca9b00000000, 0xcf902fed00000000, 0x1b7a5c7600000000, - 0xb5e2e50000000000, 0x6108969b00000000, 0x5c3173ed00000000, - 0x88db007600000000, 0x4c86720100000000, 0x986c019a00000000, - 0xa555e4ec00000000, 0x71bf977700000000, 0xdf272e0100000000, - 0x0bcd5d9a00000000, 0x36f4b8ec00000000, 0xe21ecb7700000000, - 0x6ac5cb0100000000, 0xbe2fb89a00000000, 0x83165dec00000000, - 0x57fc2e7700000000, 0xf964970100000000, 0x2d8ee49a00000000, - 0x10b701ec00000000, 0xc45d727700000000, 0x980ce50200000000, - 0x4ce6969900000000, 0x71df73ef00000000, 0xa535007400000000, - 0x0badb90200000000, 0xdf47ca9900000000, 0xe27e2fef00000000, - 0x36945c7400000000, 0xbe4f5c0200000000, 0x6aa52f9900000000, - 0x579ccaef00000000, 0x8376b97400000000, 0x2dee000200000000, - 0xf904739900000000, 0xc43d96ef00000000, 0x10d7e57400000000, - 0xd48a970300000000, 0x0060e49800000000, 0x3d5901ee00000000, - 0xe9b3727500000000, 0x472bcb0300000000, 0x93c1b89800000000, - 0xaef85dee00000000, 0x7a122e7500000000, 0xf2c92e0300000000, - 0x26235d9800000000, 0x1b1ab8ee00000000, 0xcff0cb7500000000, - 0x6168720300000000, 0xb582019800000000, 0x88bbe4ee00000000, - 0x5c51977500000000, 0x3019ca0500000000, 0xe4f3b99e00000000, - 0xd9ca5ce800000000, 0x0d202f7300000000, 0xa3b8960500000000, - 0x7752e59e00000000, 0x4a6b00e800000000, 0x9e81737300000000, - 0x165a730500000000, 0xc2b0009e00000000, 0xff89e5e800000000, - 0x2b63967300000000, 0x85fb2f0500000000, 0x51115c9e00000000, - 0x6c28b9e800000000, 0xb8c2ca7300000000, 0x7c9fb80400000000, - 0xa875cb9f00000000, 0x954c2ee900000000, 0x41a65d7200000000, - 0xef3ee40400000000, 0x3bd4979f00000000, 0x06ed72e900000000, - 0xd207017200000000, 0x5adc010400000000, 0x8e36729f00000000, - 0xb30f97e900000000, 0x67e5e47200000000, 0xc97d5d0400000000, - 0x1d972e9f00000000, 0x20aecbe900000000, 0xf444b87200000000, - 0xa8152f0700000000, 0x7cff5c9c00000000, 0x41c6b9ea00000000, - 0x952cca7100000000, 0x3bb4730700000000, 0xef5e009c00000000, - 0xd267e5ea00000000, 0x068d967100000000, 0x8e56960700000000, - 0x5abce59c00000000, 0x678500ea00000000, 0xb36f737100000000, - 0x1df7ca0700000000, 0xc91db99c00000000, 0xf4245cea00000000, - 0x20ce2f7100000000, 0xe4935d0600000000, 0x30792e9d00000000, - 0x0d40cbeb00000000, 0xd9aab87000000000, 0x7732010600000000, - 0xa3d8729d00000000, 0x9ee197eb00000000, 0x4a0be47000000000, - 0xc2d0e40600000000, 0x163a979d00000000, 0x2b0372eb00000000, - 0xffe9017000000000, 0x5171b80600000000, 0x859bcb9d00000000, - 0xb8a22eeb00000000, 0x6c485d7000000000, 0x6032940b00000000, - 0xb4d8e79000000000, 0x89e102e600000000, 0x5d0b717d00000000, - 0xf393c80b00000000, 0x2779bb9000000000, 0x1a405ee600000000, - 0xceaa2d7d00000000, 0x46712d0b00000000, 0x929b5e9000000000, - 0xafa2bbe600000000, 0x7b48c87d00000000, 0xd5d0710b00000000, - 0x013a029000000000, 0x3c03e7e600000000, 0xe8e9947d00000000, - 0x2cb4e60a00000000, 0xf85e959100000000, 0xc56770e700000000, - 0x118d037c00000000, 0xbf15ba0a00000000, 0x6bffc99100000000, - 0x56c62ce700000000, 0x822c5f7c00000000, 0x0af75f0a00000000, - 0xde1d2c9100000000, 0xe324c9e700000000, 0x37ceba7c00000000, - 0x9956030a00000000, 0x4dbc709100000000, 0x708595e700000000, - 0xa46fe67c00000000, 0xf83e710900000000, 0x2cd4029200000000, - 0x11ede7e400000000, 0xc507947f00000000, 0x6b9f2d0900000000, - 0xbf755e9200000000, 0x824cbbe400000000, 0x56a6c87f00000000, - 0xde7dc80900000000, 0x0a97bb9200000000, 0x37ae5ee400000000, - 0xe3442d7f00000000, 0x4ddc940900000000, 0x9936e79200000000, - 0xa40f02e400000000, 0x70e5717f00000000, 0xb4b8030800000000, - 0x6052709300000000, 0x5d6b95e500000000, 0x8981e67e00000000, - 0x27195f0800000000, 0xf3f32c9300000000, 0xcecac9e500000000, - 0x1a20ba7e00000000, 0x92fbba0800000000, 0x4611c99300000000, - 0x7b282ce500000000, 0xafc25f7e00000000, 0x015ae60800000000, - 0xd5b0959300000000, 0xe88970e500000000, 0x3c63037e00000000, - 0x502b5e0e00000000, 0x84c12d9500000000, 0xb9f8c8e300000000, - 0x6d12bb7800000000, 0xc38a020e00000000, 0x1760719500000000, - 0x2a5994e300000000, 0xfeb3e77800000000, 0x7668e70e00000000, - 0xa282949500000000, 0x9fbb71e300000000, 0x4b51027800000000, - 0xe5c9bb0e00000000, 0x3123c89500000000, 0x0c1a2de300000000, - 0xd8f05e7800000000, 0x1cad2c0f00000000, 0xc8475f9400000000, - 0xf57ebae200000000, 0x2194c97900000000, 0x8f0c700f00000000, - 0x5be6039400000000, 0x66dfe6e200000000, 0xb235957900000000, - 0x3aee950f00000000, 0xee04e69400000000, 0xd33d03e200000000, - 0x07d7707900000000, 0xa94fc90f00000000, 0x7da5ba9400000000, - 0x409c5fe200000000, 0x94762c7900000000, 0xc827bb0c00000000, - 0x1ccdc89700000000, 0x21f42de100000000, 0xf51e5e7a00000000, - 0x5b86e70c00000000, 0x8f6c949700000000, 0xb25571e100000000, - 0x66bf027a00000000, 0xee64020c00000000, 0x3a8e719700000000, - 0x07b794e100000000, 0xd35de77a00000000, 0x7dc55e0c00000000, - 0xa92f2d9700000000, 0x9416c8e100000000, 0x40fcbb7a00000000, - 0x84a1c90d00000000, 0x504bba9600000000, 0x6d725fe000000000, - 0xb9982c7b00000000, 0x1700950d00000000, 0xc3eae69600000000, - 0xfed303e000000000, 0x2a39707b00000000, 0xa2e2700d00000000, - 0x7608039600000000, 0x4b31e6e000000000, 0x9fdb957b00000000, - 0x31432c0d00000000, 0xe5a95f9600000000, 0xd890bae000000000, - 0x0c7ac97b00000000}, - {0x0000000000000000, 0x2765258100000000, 0x0fcc3bd900000000, - 0x28a91e5800000000, 0x5f9e066900000000, 0x78fb23e800000000, - 0x50523db000000000, 0x7737183100000000, 0xbe3c0dd200000000, - 0x9959285300000000, 0xb1f0360b00000000, 0x9695138a00000000, - 0xe1a20bbb00000000, 0xc6c72e3a00000000, 0xee6e306200000000, - 0xc90b15e300000000, 0x3d7f6b7f00000000, 0x1a1a4efe00000000, - 0x32b350a600000000, 0x15d6752700000000, 0x62e16d1600000000, - 0x4584489700000000, 0x6d2d56cf00000000, 0x4a48734e00000000, - 0x834366ad00000000, 0xa426432c00000000, 0x8c8f5d7400000000, - 0xabea78f500000000, 0xdcdd60c400000000, 0xfbb8454500000000, - 0xd3115b1d00000000, 0xf4747e9c00000000, 0x7afed6fe00000000, - 0x5d9bf37f00000000, 0x7532ed2700000000, 0x5257c8a600000000, - 0x2560d09700000000, 0x0205f51600000000, 0x2aaceb4e00000000, - 0x0dc9cecf00000000, 0xc4c2db2c00000000, 0xe3a7fead00000000, - 0xcb0ee0f500000000, 0xec6bc57400000000, 0x9b5cdd4500000000, - 0xbc39f8c400000000, 0x9490e69c00000000, 0xb3f5c31d00000000, - 0x4781bd8100000000, 0x60e4980000000000, 0x484d865800000000, - 0x6f28a3d900000000, 0x181fbbe800000000, 0x3f7a9e6900000000, - 0x17d3803100000000, 0x30b6a5b000000000, 0xf9bdb05300000000, - 0xded895d200000000, 0xf6718b8a00000000, 0xd114ae0b00000000, - 0xa623b63a00000000, 0x814693bb00000000, 0xa9ef8de300000000, - 0x8e8aa86200000000, 0xb5fadc2600000000, 0x929ff9a700000000, - 0xba36e7ff00000000, 0x9d53c27e00000000, 0xea64da4f00000000, - 0xcd01ffce00000000, 0xe5a8e19600000000, 0xc2cdc41700000000, - 0x0bc6d1f400000000, 0x2ca3f47500000000, 0x040aea2d00000000, - 0x236fcfac00000000, 0x5458d79d00000000, 0x733df21c00000000, - 0x5b94ec4400000000, 0x7cf1c9c500000000, 0x8885b75900000000, - 0xafe092d800000000, 0x87498c8000000000, 0xa02ca90100000000, - 0xd71bb13000000000, 0xf07e94b100000000, 0xd8d78ae900000000, - 0xffb2af6800000000, 0x36b9ba8b00000000, 0x11dc9f0a00000000, - 0x3975815200000000, 0x1e10a4d300000000, 0x6927bce200000000, - 0x4e42996300000000, 0x66eb873b00000000, 0x418ea2ba00000000, - 0xcf040ad800000000, 0xe8612f5900000000, 0xc0c8310100000000, - 0xe7ad148000000000, 0x909a0cb100000000, 0xb7ff293000000000, - 0x9f56376800000000, 0xb83312e900000000, 0x7138070a00000000, - 0x565d228b00000000, 0x7ef43cd300000000, 0x5991195200000000, - 0x2ea6016300000000, 0x09c324e200000000, 0x216a3aba00000000, - 0x060f1f3b00000000, 0xf27b61a700000000, 0xd51e442600000000, - 0xfdb75a7e00000000, 0xdad27fff00000000, 0xade567ce00000000, - 0x8a80424f00000000, 0xa2295c1700000000, 0x854c799600000000, - 0x4c476c7500000000, 0x6b2249f400000000, 0x438b57ac00000000, - 0x64ee722d00000000, 0x13d96a1c00000000, 0x34bc4f9d00000000, - 0x1c1551c500000000, 0x3b70744400000000, 0x6af5b94d00000000, - 0x4d909ccc00000000, 0x6539829400000000, 0x425ca71500000000, - 0x356bbf2400000000, 0x120e9aa500000000, 0x3aa784fd00000000, - 0x1dc2a17c00000000, 0xd4c9b49f00000000, 0xf3ac911e00000000, - 0xdb058f4600000000, 0xfc60aac700000000, 0x8b57b2f600000000, - 0xac32977700000000, 0x849b892f00000000, 0xa3feacae00000000, - 0x578ad23200000000, 0x70eff7b300000000, 0x5846e9eb00000000, - 0x7f23cc6a00000000, 0x0814d45b00000000, 0x2f71f1da00000000, - 0x07d8ef8200000000, 0x20bdca0300000000, 0xe9b6dfe000000000, - 0xced3fa6100000000, 0xe67ae43900000000, 0xc11fc1b800000000, - 0xb628d98900000000, 0x914dfc0800000000, 0xb9e4e25000000000, - 0x9e81c7d100000000, 0x100b6fb300000000, 0x376e4a3200000000, - 0x1fc7546a00000000, 0x38a271eb00000000, 0x4f9569da00000000, - 0x68f04c5b00000000, 0x4059520300000000, 0x673c778200000000, - 0xae37626100000000, 0x895247e000000000, 0xa1fb59b800000000, - 0x869e7c3900000000, 0xf1a9640800000000, 0xd6cc418900000000, - 0xfe655fd100000000, 0xd9007a5000000000, 0x2d7404cc00000000, - 0x0a11214d00000000, 0x22b83f1500000000, 0x05dd1a9400000000, - 0x72ea02a500000000, 0x558f272400000000, 0x7d26397c00000000, - 0x5a431cfd00000000, 0x9348091e00000000, 0xb42d2c9f00000000, - 0x9c8432c700000000, 0xbbe1174600000000, 0xccd60f7700000000, - 0xebb32af600000000, 0xc31a34ae00000000, 0xe47f112f00000000, - 0xdf0f656b00000000, 0xf86a40ea00000000, 0xd0c35eb200000000, - 0xf7a67b3300000000, 0x8091630200000000, 0xa7f4468300000000, - 0x8f5d58db00000000, 0xa8387d5a00000000, 0x613368b900000000, - 0x46564d3800000000, 0x6eff536000000000, 0x499a76e100000000, - 0x3ead6ed000000000, 0x19c84b5100000000, 0x3161550900000000, - 0x1604708800000000, 0xe2700e1400000000, 0xc5152b9500000000, - 0xedbc35cd00000000, 0xcad9104c00000000, 0xbdee087d00000000, - 0x9a8b2dfc00000000, 0xb22233a400000000, 0x9547162500000000, - 0x5c4c03c600000000, 0x7b29264700000000, 0x5380381f00000000, - 0x74e51d9e00000000, 0x03d205af00000000, 0x24b7202e00000000, - 0x0c1e3e7600000000, 0x2b7b1bf700000000, 0xa5f1b39500000000, - 0x8294961400000000, 0xaa3d884c00000000, 0x8d58adcd00000000, - 0xfa6fb5fc00000000, 0xdd0a907d00000000, 0xf5a38e2500000000, - 0xd2c6aba400000000, 0x1bcdbe4700000000, 0x3ca89bc600000000, - 0x1401859e00000000, 0x3364a01f00000000, 0x4453b82e00000000, - 0x63369daf00000000, 0x4b9f83f700000000, 0x6cfaa67600000000, - 0x988ed8ea00000000, 0xbfebfd6b00000000, 0x9742e33300000000, - 0xb027c6b200000000, 0xc710de8300000000, 0xe075fb0200000000, - 0xc8dce55a00000000, 0xefb9c0db00000000, 0x26b2d53800000000, - 0x01d7f0b900000000, 0x297eeee100000000, 0x0e1bcb6000000000, - 0x792cd35100000000, 0x5e49f6d000000000, 0x76e0e88800000000, - 0x5185cd0900000000}}; - -#else /* W == 4 */ - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0x9ba54c6f, 0xec3b9e9f, 0x779ed2f0, 0x03063b7f, - 0x98a37710, 0xef3da5e0, 0x7498e98f, 0x060c76fe, 0x9da93a91, - 0xea37e861, 0x7192a40e, 0x050a4d81, 0x9eaf01ee, 0xe931d31e, - 0x72949f71, 0x0c18edfc, 0x97bda193, 0xe0237363, 0x7b863f0c, - 0x0f1ed683, 0x94bb9aec, 0xe325481c, 0x78800473, 0x0a149b02, - 0x91b1d76d, 0xe62f059d, 0x7d8a49f2, 0x0912a07d, 0x92b7ec12, - 0xe5293ee2, 0x7e8c728d, 0x1831dbf8, 0x83949797, 0xf40a4567, - 0x6faf0908, 0x1b37e087, 0x8092ace8, 0xf70c7e18, 0x6ca93277, - 0x1e3dad06, 0x8598e169, 0xf2063399, 0x69a37ff6, 0x1d3b9679, - 0x869eda16, 0xf10008e6, 0x6aa54489, 0x14293604, 0x8f8c7a6b, - 0xf812a89b, 0x63b7e4f4, 0x172f0d7b, 0x8c8a4114, 0xfb1493e4, - 0x60b1df8b, 0x122540fa, 0x89800c95, 0xfe1ede65, 0x65bb920a, - 0x11237b85, 0x8a8637ea, 0xfd18e51a, 0x66bda975, 0x3063b7f0, - 0xabc6fb9f, 0xdc58296f, 0x47fd6500, 0x33658c8f, 0xa8c0c0e0, - 0xdf5e1210, 0x44fb5e7f, 0x366fc10e, 0xadca8d61, 0xda545f91, - 0x41f113fe, 0x3569fa71, 0xaeccb61e, 0xd95264ee, 0x42f72881, - 0x3c7b5a0c, 0xa7de1663, 0xd040c493, 0x4be588fc, 0x3f7d6173, - 0xa4d82d1c, 0xd346ffec, 0x48e3b383, 0x3a772cf2, 0xa1d2609d, - 0xd64cb26d, 0x4de9fe02, 0x3971178d, 0xa2d45be2, 0xd54a8912, - 0x4eefc57d, 0x28526c08, 0xb3f72067, 0xc469f297, 0x5fccbef8, - 0x2b545777, 0xb0f11b18, 0xc76fc9e8, 0x5cca8587, 0x2e5e1af6, - 0xb5fb5699, 0xc2658469, 0x59c0c806, 0x2d582189, 0xb6fd6de6, - 0xc163bf16, 0x5ac6f379, 0x244a81f4, 0xbfefcd9b, 0xc8711f6b, - 0x53d45304, 0x274cba8b, 0xbce9f6e4, 0xcb772414, 0x50d2687b, - 0x2246f70a, 0xb9e3bb65, 0xce7d6995, 0x55d825fa, 0x2140cc75, - 0xbae5801a, 0xcd7b52ea, 0x56de1e85, 0x60c76fe0, 0xfb62238f, - 0x8cfcf17f, 0x1759bd10, 0x63c1549f, 0xf86418f0, 0x8ffaca00, - 0x145f866f, 0x66cb191e, 0xfd6e5571, 0x8af08781, 0x1155cbee, - 0x65cd2261, 0xfe686e0e, 0x89f6bcfe, 0x1253f091, 0x6cdf821c, - 0xf77ace73, 0x80e41c83, 0x1b4150ec, 0x6fd9b963, 0xf47cf50c, - 0x83e227fc, 0x18476b93, 0x6ad3f4e2, 0xf176b88d, 0x86e86a7d, - 0x1d4d2612, 0x69d5cf9d, 0xf27083f2, 0x85ee5102, 0x1e4b1d6d, - 0x78f6b418, 0xe353f877, 0x94cd2a87, 0x0f6866e8, 0x7bf08f67, - 0xe055c308, 0x97cb11f8, 0x0c6e5d97, 0x7efac2e6, 0xe55f8e89, - 0x92c15c79, 0x09641016, 0x7dfcf999, 0xe659b5f6, 0x91c76706, - 0x0a622b69, 0x74ee59e4, 0xef4b158b, 0x98d5c77b, 0x03708b14, - 0x77e8629b, 0xec4d2ef4, 0x9bd3fc04, 0x0076b06b, 0x72e22f1a, - 0xe9476375, 0x9ed9b185, 0x057cfdea, 0x71e41465, 0xea41580a, - 0x9ddf8afa, 0x067ac695, 0x50a4d810, 0xcb01947f, 0xbc9f468f, - 0x273a0ae0, 0x53a2e36f, 0xc807af00, 0xbf997df0, 0x243c319f, - 0x56a8aeee, 0xcd0de281, 0xba933071, 0x21367c1e, 0x55ae9591, - 0xce0bd9fe, 0xb9950b0e, 0x22304761, 0x5cbc35ec, 0xc7197983, - 0xb087ab73, 0x2b22e71c, 0x5fba0e93, 0xc41f42fc, 0xb381900c, - 0x2824dc63, 0x5ab04312, 0xc1150f7d, 0xb68bdd8d, 0x2d2e91e2, - 0x59b6786d, 0xc2133402, 0xb58de6f2, 0x2e28aa9d, 0x489503e8, - 0xd3304f87, 0xa4ae9d77, 0x3f0bd118, 0x4b933897, 0xd03674f8, - 0xa7a8a608, 0x3c0dea67, 0x4e997516, 0xd53c3979, 0xa2a2eb89, - 0x3907a7e6, 0x4d9f4e69, 0xd63a0206, 0xa1a4d0f6, 0x3a019c99, - 0x448dee14, 0xdf28a27b, 0xa8b6708b, 0x33133ce4, 0x478bd56b, - 0xdc2e9904, 0xabb04bf4, 0x3015079b, 0x428198ea, 0xd924d485, - 0xaeba0675, 0x351f4a1a, 0x4187a395, 0xda22effa, 0xadbc3d0a, - 0x36197165}, - {0x00000000, 0xc18edfc0, 0x586cb9c1, 0x99e26601, 0xb0d97382, - 0x7157ac42, 0xe8b5ca43, 0x293b1583, 0xbac3e145, 0x7b4d3e85, - 0xe2af5884, 0x23218744, 0x0a1a92c7, 0xcb944d07, 0x52762b06, - 0x93f8f4c6, 0xaef6c4cb, 0x6f781b0b, 0xf69a7d0a, 0x3714a2ca, - 0x1e2fb749, 0xdfa16889, 0x46430e88, 0x87cdd148, 0x1435258e, - 0xd5bbfa4e, 0x4c599c4f, 0x8dd7438f, 0xa4ec560c, 0x656289cc, - 0xfc80efcd, 0x3d0e300d, 0x869c8fd7, 0x47125017, 0xdef03616, - 0x1f7ee9d6, 0x3645fc55, 0xf7cb2395, 0x6e294594, 0xafa79a54, - 0x3c5f6e92, 0xfdd1b152, 0x6433d753, 0xa5bd0893, 0x8c861d10, - 0x4d08c2d0, 0xd4eaa4d1, 0x15647b11, 0x286a4b1c, 0xe9e494dc, - 0x7006f2dd, 0xb1882d1d, 0x98b3389e, 0x593de75e, 0xc0df815f, - 0x01515e9f, 0x92a9aa59, 0x53277599, 0xcac51398, 0x0b4bcc58, - 0x2270d9db, 0xe3fe061b, 0x7a1c601a, 0xbb92bfda, 0xd64819ef, - 0x17c6c62f, 0x8e24a02e, 0x4faa7fee, 0x66916a6d, 0xa71fb5ad, - 0x3efdd3ac, 0xff730c6c, 0x6c8bf8aa, 0xad05276a, 0x34e7416b, - 0xf5699eab, 0xdc528b28, 0x1ddc54e8, 0x843e32e9, 0x45b0ed29, - 0x78bedd24, 0xb93002e4, 0x20d264e5, 0xe15cbb25, 0xc867aea6, - 0x09e97166, 0x900b1767, 0x5185c8a7, 0xc27d3c61, 0x03f3e3a1, - 0x9a1185a0, 0x5b9f5a60, 0x72a44fe3, 0xb32a9023, 0x2ac8f622, - 0xeb4629e2, 0x50d49638, 0x915a49f8, 0x08b82ff9, 0xc936f039, - 0xe00de5ba, 0x21833a7a, 0xb8615c7b, 0x79ef83bb, 0xea17777d, - 0x2b99a8bd, 0xb27bcebc, 0x73f5117c, 0x5ace04ff, 0x9b40db3f, - 0x02a2bd3e, 0xc32c62fe, 0xfe2252f3, 0x3fac8d33, 0xa64eeb32, - 0x67c034f2, 0x4efb2171, 0x8f75feb1, 0x169798b0, 0xd7194770, - 0x44e1b3b6, 0x856f6c76, 0x1c8d0a77, 0xdd03d5b7, 0xf438c034, - 0x35b61ff4, 0xac5479f5, 0x6ddaa635, 0x77e1359f, 0xb66fea5f, - 0x2f8d8c5e, 0xee03539e, 0xc738461d, 0x06b699dd, 0x9f54ffdc, - 0x5eda201c, 0xcd22d4da, 0x0cac0b1a, 0x954e6d1b, 0x54c0b2db, - 0x7dfba758, 0xbc757898, 0x25971e99, 0xe419c159, 0xd917f154, - 0x18992e94, 0x817b4895, 0x40f59755, 0x69ce82d6, 0xa8405d16, - 0x31a23b17, 0xf02ce4d7, 0x63d41011, 0xa25acfd1, 0x3bb8a9d0, - 0xfa367610, 0xd30d6393, 0x1283bc53, 0x8b61da52, 0x4aef0592, - 0xf17dba48, 0x30f36588, 0xa9110389, 0x689fdc49, 0x41a4c9ca, - 0x802a160a, 0x19c8700b, 0xd846afcb, 0x4bbe5b0d, 0x8a3084cd, - 0x13d2e2cc, 0xd25c3d0c, 0xfb67288f, 0x3ae9f74f, 0xa30b914e, - 0x62854e8e, 0x5f8b7e83, 0x9e05a143, 0x07e7c742, 0xc6691882, - 0xef520d01, 0x2edcd2c1, 0xb73eb4c0, 0x76b06b00, 0xe5489fc6, - 0x24c64006, 0xbd242607, 0x7caaf9c7, 0x5591ec44, 0x941f3384, - 0x0dfd5585, 0xcc738a45, 0xa1a92c70, 0x6027f3b0, 0xf9c595b1, - 0x384b4a71, 0x11705ff2, 0xd0fe8032, 0x491ce633, 0x889239f3, - 0x1b6acd35, 0xdae412f5, 0x430674f4, 0x8288ab34, 0xabb3beb7, - 0x6a3d6177, 0xf3df0776, 0x3251d8b6, 0x0f5fe8bb, 0xced1377b, - 0x5733517a, 0x96bd8eba, 0xbf869b39, 0x7e0844f9, 0xe7ea22f8, - 0x2664fd38, 0xb59c09fe, 0x7412d63e, 0xedf0b03f, 0x2c7e6fff, - 0x05457a7c, 0xc4cba5bc, 0x5d29c3bd, 0x9ca71c7d, 0x2735a3a7, - 0xe6bb7c67, 0x7f591a66, 0xbed7c5a6, 0x97ecd025, 0x56620fe5, - 0xcf8069e4, 0x0e0eb624, 0x9df642e2, 0x5c789d22, 0xc59afb23, - 0x041424e3, 0x2d2f3160, 0xeca1eea0, 0x754388a1, 0xb4cd5761, - 0x89c3676c, 0x484db8ac, 0xd1afdead, 0x1021016d, 0x391a14ee, - 0xf894cb2e, 0x6176ad2f, 0xa0f872ef, 0x33008629, 0xf28e59e9, - 0x6b6c3fe8, 0xaae2e028, 0x83d9f5ab, 0x42572a6b, 0xdbb54c6a, - 0x1a3b93aa}, - {0x00000000, 0xefc26b3e, 0x04f5d03d, 0xeb37bb03, 0x09eba07a, - 0xe629cb44, 0x0d1e7047, 0xe2dc1b79, 0x13d740f4, 0xfc152bca, - 0x172290c9, 0xf8e0fbf7, 0x1a3ce08e, 0xf5fe8bb0, 0x1ec930b3, - 0xf10b5b8d, 0x27ae81e8, 0xc86cead6, 0x235b51d5, 0xcc993aeb, - 0x2e452192, 0xc1874aac, 0x2ab0f1af, 0xc5729a91, 0x3479c11c, - 0xdbbbaa22, 0x308c1121, 0xdf4e7a1f, 0x3d926166, 0xd2500a58, - 0x3967b15b, 0xd6a5da65, 0x4f5d03d0, 0xa09f68ee, 0x4ba8d3ed, - 0xa46ab8d3, 0x46b6a3aa, 0xa974c894, 0x42437397, 0xad8118a9, - 0x5c8a4324, 0xb348281a, 0x587f9319, 0xb7bdf827, 0x5561e35e, - 0xbaa38860, 0x51943363, 0xbe56585d, 0x68f38238, 0x8731e906, - 0x6c065205, 0x83c4393b, 0x61182242, 0x8eda497c, 0x65edf27f, - 0x8a2f9941, 0x7b24c2cc, 0x94e6a9f2, 0x7fd112f1, 0x901379cf, - 0x72cf62b6, 0x9d0d0988, 0x763ab28b, 0x99f8d9b5, 0x9eba07a0, - 0x71786c9e, 0x9a4fd79d, 0x758dbca3, 0x9751a7da, 0x7893cce4, - 0x93a477e7, 0x7c661cd9, 0x8d6d4754, 0x62af2c6a, 0x89989769, - 0x665afc57, 0x8486e72e, 0x6b448c10, 0x80733713, 0x6fb15c2d, - 0xb9148648, 0x56d6ed76, 0xbde15675, 0x52233d4b, 0xb0ff2632, - 0x5f3d4d0c, 0xb40af60f, 0x5bc89d31, 0xaac3c6bc, 0x4501ad82, - 0xae361681, 0x41f47dbf, 0xa32866c6, 0x4cea0df8, 0xa7ddb6fb, - 0x481fddc5, 0xd1e70470, 0x3e256f4e, 0xd512d44d, 0x3ad0bf73, - 0xd80ca40a, 0x37cecf34, 0xdcf97437, 0x333b1f09, 0xc2304484, - 0x2df22fba, 0xc6c594b9, 0x2907ff87, 0xcbdbe4fe, 0x24198fc0, - 0xcf2e34c3, 0x20ec5ffd, 0xf6498598, 0x198beea6, 0xf2bc55a5, - 0x1d7e3e9b, 0xffa225e2, 0x10604edc, 0xfb57f5df, 0x14959ee1, - 0xe59ec56c, 0x0a5cae52, 0xe16b1551, 0x0ea97e6f, 0xec756516, - 0x03b70e28, 0xe880b52b, 0x0742de15, 0xe6050901, 0x09c7623f, - 0xe2f0d93c, 0x0d32b202, 0xefeea97b, 0x002cc245, 0xeb1b7946, - 0x04d91278, 0xf5d249f5, 0x1a1022cb, 0xf12799c8, 0x1ee5f2f6, - 0xfc39e98f, 0x13fb82b1, 0xf8cc39b2, 0x170e528c, 0xc1ab88e9, - 0x2e69e3d7, 0xc55e58d4, 0x2a9c33ea, 0xc8402893, 0x278243ad, - 0xccb5f8ae, 0x23779390, 0xd27cc81d, 0x3dbea323, 0xd6891820, - 0x394b731e, 0xdb976867, 0x34550359, 0xdf62b85a, 0x30a0d364, - 0xa9580ad1, 0x469a61ef, 0xadaddaec, 0x426fb1d2, 0xa0b3aaab, - 0x4f71c195, 0xa4467a96, 0x4b8411a8, 0xba8f4a25, 0x554d211b, - 0xbe7a9a18, 0x51b8f126, 0xb364ea5f, 0x5ca68161, 0xb7913a62, - 0x5853515c, 0x8ef68b39, 0x6134e007, 0x8a035b04, 0x65c1303a, - 0x871d2b43, 0x68df407d, 0x83e8fb7e, 0x6c2a9040, 0x9d21cbcd, - 0x72e3a0f3, 0x99d41bf0, 0x761670ce, 0x94ca6bb7, 0x7b080089, - 0x903fbb8a, 0x7ffdd0b4, 0x78bf0ea1, 0x977d659f, 0x7c4ade9c, - 0x9388b5a2, 0x7154aedb, 0x9e96c5e5, 0x75a17ee6, 0x9a6315d8, - 0x6b684e55, 0x84aa256b, 0x6f9d9e68, 0x805ff556, 0x6283ee2f, - 0x8d418511, 0x66763e12, 0x89b4552c, 0x5f118f49, 0xb0d3e477, - 0x5be45f74, 0xb426344a, 0x56fa2f33, 0xb938440d, 0x520fff0e, - 0xbdcd9430, 0x4cc6cfbd, 0xa304a483, 0x48331f80, 0xa7f174be, - 0x452d6fc7, 0xaaef04f9, 0x41d8bffa, 0xae1ad4c4, 0x37e20d71, - 0xd820664f, 0x3317dd4c, 0xdcd5b672, 0x3e09ad0b, 0xd1cbc635, - 0x3afc7d36, 0xd53e1608, 0x24354d85, 0xcbf726bb, 0x20c09db8, - 0xcf02f686, 0x2ddeedff, 0xc21c86c1, 0x292b3dc2, 0xc6e956fc, - 0x104c8c99, 0xff8ee7a7, 0x14b95ca4, 0xfb7b379a, 0x19a72ce3, - 0xf66547dd, 0x1d52fcde, 0xf29097e0, 0x039bcc6d, 0xec59a753, - 0x076e1c50, 0xe8ac776e, 0x0a706c17, 0xe5b20729, 0x0e85bc2a, - 0xe147d714}, - {0x00000000, 0x177b1443, 0x2ef62886, 0x398d3cc5, 0x5dec510c, - 0x4a97454f, 0x731a798a, 0x64616dc9, 0xbbd8a218, 0xaca3b65b, - 0x952e8a9e, 0x82559edd, 0xe634f314, 0xf14fe757, 0xc8c2db92, - 0xdfb9cfd1, 0xacc04271, 0xbbbb5632, 0x82366af7, 0x954d7eb4, - 0xf12c137d, 0xe657073e, 0xdfda3bfb, 0xc8a12fb8, 0x1718e069, - 0x0063f42a, 0x39eec8ef, 0x2e95dcac, 0x4af4b165, 0x5d8fa526, - 0x640299e3, 0x73798da0, 0x82f182a3, 0x958a96e0, 0xac07aa25, - 0xbb7cbe66, 0xdf1dd3af, 0xc866c7ec, 0xf1ebfb29, 0xe690ef6a, - 0x392920bb, 0x2e5234f8, 0x17df083d, 0x00a41c7e, 0x64c571b7, - 0x73be65f4, 0x4a335931, 0x5d484d72, 0x2e31c0d2, 0x394ad491, - 0x00c7e854, 0x17bcfc17, 0x73dd91de, 0x64a6859d, 0x5d2bb958, - 0x4a50ad1b, 0x95e962ca, 0x82927689, 0xbb1f4a4c, 0xac645e0f, - 0xc80533c6, 0xdf7e2785, 0xe6f31b40, 0xf1880f03, 0xde920307, - 0xc9e91744, 0xf0642b81, 0xe71f3fc2, 0x837e520b, 0x94054648, - 0xad887a8d, 0xbaf36ece, 0x654aa11f, 0x7231b55c, 0x4bbc8999, - 0x5cc79dda, 0x38a6f013, 0x2fdde450, 0x1650d895, 0x012bccd6, - 0x72524176, 0x65295535, 0x5ca469f0, 0x4bdf7db3, 0x2fbe107a, - 0x38c50439, 0x014838fc, 0x16332cbf, 0xc98ae36e, 0xdef1f72d, - 0xe77ccbe8, 0xf007dfab, 0x9466b262, 0x831da621, 0xba909ae4, - 0xadeb8ea7, 0x5c6381a4, 0x4b1895e7, 0x7295a922, 0x65eebd61, - 0x018fd0a8, 0x16f4c4eb, 0x2f79f82e, 0x3802ec6d, 0xe7bb23bc, - 0xf0c037ff, 0xc94d0b3a, 0xde361f79, 0xba5772b0, 0xad2c66f3, - 0x94a15a36, 0x83da4e75, 0xf0a3c3d5, 0xe7d8d796, 0xde55eb53, - 0xc92eff10, 0xad4f92d9, 0xba34869a, 0x83b9ba5f, 0x94c2ae1c, - 0x4b7b61cd, 0x5c00758e, 0x658d494b, 0x72f65d08, 0x169730c1, - 0x01ec2482, 0x38611847, 0x2f1a0c04, 0x6655004f, 0x712e140c, - 0x48a328c9, 0x5fd83c8a, 0x3bb95143, 0x2cc24500, 0x154f79c5, - 0x02346d86, 0xdd8da257, 0xcaf6b614, 0xf37b8ad1, 0xe4009e92, - 0x8061f35b, 0x971ae718, 0xae97dbdd, 0xb9eccf9e, 0xca95423e, - 0xddee567d, 0xe4636ab8, 0xf3187efb, 0x97791332, 0x80020771, - 0xb98f3bb4, 0xaef42ff7, 0x714de026, 0x6636f465, 0x5fbbc8a0, - 0x48c0dce3, 0x2ca1b12a, 0x3bdaa569, 0x025799ac, 0x152c8def, - 0xe4a482ec, 0xf3df96af, 0xca52aa6a, 0xdd29be29, 0xb948d3e0, - 0xae33c7a3, 0x97befb66, 0x80c5ef25, 0x5f7c20f4, 0x480734b7, - 0x718a0872, 0x66f11c31, 0x029071f8, 0x15eb65bb, 0x2c66597e, - 0x3b1d4d3d, 0x4864c09d, 0x5f1fd4de, 0x6692e81b, 0x71e9fc58, - 0x15889191, 0x02f385d2, 0x3b7eb917, 0x2c05ad54, 0xf3bc6285, - 0xe4c776c6, 0xdd4a4a03, 0xca315e40, 0xae503389, 0xb92b27ca, - 0x80a61b0f, 0x97dd0f4c, 0xb8c70348, 0xafbc170b, 0x96312bce, - 0x814a3f8d, 0xe52b5244, 0xf2504607, 0xcbdd7ac2, 0xdca66e81, - 0x031fa150, 0x1464b513, 0x2de989d6, 0x3a929d95, 0x5ef3f05c, - 0x4988e41f, 0x7005d8da, 0x677ecc99, 0x14074139, 0x037c557a, - 0x3af169bf, 0x2d8a7dfc, 0x49eb1035, 0x5e900476, 0x671d38b3, - 0x70662cf0, 0xafdfe321, 0xb8a4f762, 0x8129cba7, 0x9652dfe4, - 0xf233b22d, 0xe548a66e, 0xdcc59aab, 0xcbbe8ee8, 0x3a3681eb, - 0x2d4d95a8, 0x14c0a96d, 0x03bbbd2e, 0x67dad0e7, 0x70a1c4a4, - 0x492cf861, 0x5e57ec22, 0x81ee23f3, 0x969537b0, 0xaf180b75, - 0xb8631f36, 0xdc0272ff, 0xcb7966bc, 0xf2f45a79, 0xe58f4e3a, - 0x96f6c39a, 0x818dd7d9, 0xb800eb1c, 0xaf7bff5f, 0xcb1a9296, - 0xdc6186d5, 0xe5ecba10, 0xf297ae53, 0x2d2e6182, 0x3a5575c1, - 0x03d84904, 0x14a35d47, 0x70c2308e, 0x67b924cd, 0x5e341808, - 0x494f0c4b}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x00000000, 0x43147b17, 0x8628f62e, 0xc53c8d39, 0x0c51ec5d, - 0x4f45974a, 0x8a791a73, 0xc96d6164, 0x18a2d8bb, 0x5bb6a3ac, - 0x9e8a2e95, 0xdd9e5582, 0x14f334e6, 0x57e74ff1, 0x92dbc2c8, - 0xd1cfb9df, 0x7142c0ac, 0x3256bbbb, 0xf76a3682, 0xb47e4d95, - 0x7d132cf1, 0x3e0757e6, 0xfb3bdadf, 0xb82fa1c8, 0x69e01817, - 0x2af46300, 0xefc8ee39, 0xacdc952e, 0x65b1f44a, 0x26a58f5d, - 0xe3990264, 0xa08d7973, 0xa382f182, 0xe0968a95, 0x25aa07ac, - 0x66be7cbb, 0xafd31ddf, 0xecc766c8, 0x29fbebf1, 0x6aef90e6, - 0xbb202939, 0xf834522e, 0x3d08df17, 0x7e1ca400, 0xb771c564, - 0xf465be73, 0x3159334a, 0x724d485d, 0xd2c0312e, 0x91d44a39, - 0x54e8c700, 0x17fcbc17, 0xde91dd73, 0x9d85a664, 0x58b92b5d, - 0x1bad504a, 0xca62e995, 0x89769282, 0x4c4a1fbb, 0x0f5e64ac, - 0xc63305c8, 0x85277edf, 0x401bf3e6, 0x030f88f1, 0x070392de, - 0x4417e9c9, 0x812b64f0, 0xc23f1fe7, 0x0b527e83, 0x48460594, - 0x8d7a88ad, 0xce6ef3ba, 0x1fa14a65, 0x5cb53172, 0x9989bc4b, - 0xda9dc75c, 0x13f0a638, 0x50e4dd2f, 0x95d85016, 0xd6cc2b01, - 0x76415272, 0x35552965, 0xf069a45c, 0xb37ddf4b, 0x7a10be2f, - 0x3904c538, 0xfc384801, 0xbf2c3316, 0x6ee38ac9, 0x2df7f1de, - 0xe8cb7ce7, 0xabdf07f0, 0x62b26694, 0x21a61d83, 0xe49a90ba, - 0xa78eebad, 0xa481635c, 0xe795184b, 0x22a99572, 0x61bdee65, - 0xa8d08f01, 0xebc4f416, 0x2ef8792f, 0x6dec0238, 0xbc23bbe7, - 0xff37c0f0, 0x3a0b4dc9, 0x791f36de, 0xb07257ba, 0xf3662cad, - 0x365aa194, 0x754eda83, 0xd5c3a3f0, 0x96d7d8e7, 0x53eb55de, - 0x10ff2ec9, 0xd9924fad, 0x9a8634ba, 0x5fbab983, 0x1caec294, - 0xcd617b4b, 0x8e75005c, 0x4b498d65, 0x085df672, 0xc1309716, - 0x8224ec01, 0x47186138, 0x040c1a2f, 0x4f005566, 0x0c142e71, - 0xc928a348, 0x8a3cd85f, 0x4351b93b, 0x0045c22c, 0xc5794f15, - 0x866d3402, 0x57a28ddd, 0x14b6f6ca, 0xd18a7bf3, 0x929e00e4, - 0x5bf36180, 0x18e71a97, 0xdddb97ae, 0x9ecfecb9, 0x3e4295ca, - 0x7d56eedd, 0xb86a63e4, 0xfb7e18f3, 0x32137997, 0x71070280, - 0xb43b8fb9, 0xf72ff4ae, 0x26e04d71, 0x65f43666, 0xa0c8bb5f, - 0xe3dcc048, 0x2ab1a12c, 0x69a5da3b, 0xac995702, 0xef8d2c15, - 0xec82a4e4, 0xaf96dff3, 0x6aaa52ca, 0x29be29dd, 0xe0d348b9, - 0xa3c733ae, 0x66fbbe97, 0x25efc580, 0xf4207c5f, 0xb7340748, - 0x72088a71, 0x311cf166, 0xf8719002, 0xbb65eb15, 0x7e59662c, - 0x3d4d1d3b, 0x9dc06448, 0xded41f5f, 0x1be89266, 0x58fce971, - 0x91918815, 0xd285f302, 0x17b97e3b, 0x54ad052c, 0x8562bcf3, - 0xc676c7e4, 0x034a4add, 0x405e31ca, 0x893350ae, 0xca272bb9, - 0x0f1ba680, 0x4c0fdd97, 0x4803c7b8, 0x0b17bcaf, 0xce2b3196, - 0x8d3f4a81, 0x44522be5, 0x074650f2, 0xc27addcb, 0x816ea6dc, - 0x50a11f03, 0x13b56414, 0xd689e92d, 0x959d923a, 0x5cf0f35e, - 0x1fe48849, 0xdad80570, 0x99cc7e67, 0x39410714, 0x7a557c03, - 0xbf69f13a, 0xfc7d8a2d, 0x3510eb49, 0x7604905e, 0xb3381d67, - 0xf02c6670, 0x21e3dfaf, 0x62f7a4b8, 0xa7cb2981, 0xe4df5296, - 0x2db233f2, 0x6ea648e5, 0xab9ac5dc, 0xe88ebecb, 0xeb81363a, - 0xa8954d2d, 0x6da9c014, 0x2ebdbb03, 0xe7d0da67, 0xa4c4a170, - 0x61f82c49, 0x22ec575e, 0xf323ee81, 0xb0379596, 0x750b18af, - 0x361f63b8, 0xff7202dc, 0xbc6679cb, 0x795af4f2, 0x3a4e8fe5, - 0x9ac3f696, 0xd9d78d81, 0x1ceb00b8, 0x5fff7baf, 0x96921acb, - 0xd58661dc, 0x10baece5, 0x53ae97f2, 0x82612e2d, 0xc175553a, - 0x0449d803, 0x475da314, 0x8e30c270, 0xcd24b967, 0x0818345e, - 0x4b0c4f49}, - {0x00000000, 0x3e6bc2ef, 0x3dd0f504, 0x03bb37eb, 0x7aa0eb09, - 0x44cb29e6, 0x47701e0d, 0x791bdce2, 0xf440d713, 0xca2b15fc, - 0xc9902217, 0xf7fbe0f8, 0x8ee03c1a, 0xb08bfef5, 0xb330c91e, - 0x8d5b0bf1, 0xe881ae27, 0xd6ea6cc8, 0xd5515b23, 0xeb3a99cc, - 0x9221452e, 0xac4a87c1, 0xaff1b02a, 0x919a72c5, 0x1cc17934, - 0x22aabbdb, 0x21118c30, 0x1f7a4edf, 0x6661923d, 0x580a50d2, - 0x5bb16739, 0x65daa5d6, 0xd0035d4f, 0xee689fa0, 0xedd3a84b, - 0xd3b86aa4, 0xaaa3b646, 0x94c874a9, 0x97734342, 0xa91881ad, - 0x24438a5c, 0x1a2848b3, 0x19937f58, 0x27f8bdb7, 0x5ee36155, - 0x6088a3ba, 0x63339451, 0x5d5856be, 0x3882f368, 0x06e93187, - 0x0552066c, 0x3b39c483, 0x42221861, 0x7c49da8e, 0x7ff2ed65, - 0x41992f8a, 0xccc2247b, 0xf2a9e694, 0xf112d17f, 0xcf791390, - 0xb662cf72, 0x88090d9d, 0x8bb23a76, 0xb5d9f899, 0xa007ba9e, - 0x9e6c7871, 0x9dd74f9a, 0xa3bc8d75, 0xdaa75197, 0xe4cc9378, - 0xe777a493, 0xd91c667c, 0x54476d8d, 0x6a2caf62, 0x69979889, - 0x57fc5a66, 0x2ee78684, 0x108c446b, 0x13377380, 0x2d5cb16f, - 0x488614b9, 0x76edd656, 0x7556e1bd, 0x4b3d2352, 0x3226ffb0, - 0x0c4d3d5f, 0x0ff60ab4, 0x319dc85b, 0xbcc6c3aa, 0x82ad0145, - 0x811636ae, 0xbf7df441, 0xc66628a3, 0xf80dea4c, 0xfbb6dda7, - 0xc5dd1f48, 0x7004e7d1, 0x4e6f253e, 0x4dd412d5, 0x73bfd03a, - 0x0aa40cd8, 0x34cfce37, 0x3774f9dc, 0x091f3b33, 0x844430c2, - 0xba2ff22d, 0xb994c5c6, 0x87ff0729, 0xfee4dbcb, 0xc08f1924, - 0xc3342ecf, 0xfd5fec20, 0x988549f6, 0xa6ee8b19, 0xa555bcf2, - 0x9b3e7e1d, 0xe225a2ff, 0xdc4e6010, 0xdff557fb, 0xe19e9514, - 0x6cc59ee5, 0x52ae5c0a, 0x51156be1, 0x6f7ea90e, 0x166575ec, - 0x280eb703, 0x2bb580e8, 0x15de4207, 0x010905e6, 0x3f62c709, - 0x3cd9f0e2, 0x02b2320d, 0x7ba9eeef, 0x45c22c00, 0x46791beb, - 0x7812d904, 0xf549d2f5, 0xcb22101a, 0xc89927f1, 0xf6f2e51e, - 0x8fe939fc, 0xb182fb13, 0xb239ccf8, 0x8c520e17, 0xe988abc1, - 0xd7e3692e, 0xd4585ec5, 0xea339c2a, 0x932840c8, 0xad438227, - 0xaef8b5cc, 0x90937723, 0x1dc87cd2, 0x23a3be3d, 0x201889d6, - 0x1e734b39, 0x676897db, 0x59035534, 0x5ab862df, 0x64d3a030, - 0xd10a58a9, 0xef619a46, 0xecdaadad, 0xd2b16f42, 0xabaab3a0, - 0x95c1714f, 0x967a46a4, 0xa811844b, 0x254a8fba, 0x1b214d55, - 0x189a7abe, 0x26f1b851, 0x5fea64b3, 0x6181a65c, 0x623a91b7, - 0x5c515358, 0x398bf68e, 0x07e03461, 0x045b038a, 0x3a30c165, - 0x432b1d87, 0x7d40df68, 0x7efbe883, 0x40902a6c, 0xcdcb219d, - 0xf3a0e372, 0xf01bd499, 0xce701676, 0xb76bca94, 0x8900087b, - 0x8abb3f90, 0xb4d0fd7f, 0xa10ebf78, 0x9f657d97, 0x9cde4a7c, - 0xa2b58893, 0xdbae5471, 0xe5c5969e, 0xe67ea175, 0xd815639a, - 0x554e686b, 0x6b25aa84, 0x689e9d6f, 0x56f55f80, 0x2fee8362, - 0x1185418d, 0x123e7666, 0x2c55b489, 0x498f115f, 0x77e4d3b0, - 0x745fe45b, 0x4a3426b4, 0x332ffa56, 0x0d4438b9, 0x0eff0f52, - 0x3094cdbd, 0xbdcfc64c, 0x83a404a3, 0x801f3348, 0xbe74f1a7, - 0xc76f2d45, 0xf904efaa, 0xfabfd841, 0xc4d41aae, 0x710de237, - 0x4f6620d8, 0x4cdd1733, 0x72b6d5dc, 0x0bad093e, 0x35c6cbd1, - 0x367dfc3a, 0x08163ed5, 0x854d3524, 0xbb26f7cb, 0xb89dc020, - 0x86f602cf, 0xffedde2d, 0xc1861cc2, 0xc23d2b29, 0xfc56e9c6, - 0x998c4c10, 0xa7e78eff, 0xa45cb914, 0x9a377bfb, 0xe32ca719, - 0xdd4765f6, 0xdefc521d, 0xe09790f2, 0x6dcc9b03, 0x53a759ec, - 0x501c6e07, 0x6e77ace8, 0x176c700a, 0x2907b2e5, 0x2abc850e, - 0x14d747e1}, - {0x00000000, 0xc0df8ec1, 0xc1b96c58, 0x0166e299, 0x8273d9b0, - 0x42ac5771, 0x43cab5e8, 0x83153b29, 0x45e1c3ba, 0x853e4d7b, - 0x8458afe2, 0x44872123, 0xc7921a0a, 0x074d94cb, 0x062b7652, - 0xc6f4f893, 0xcbc4f6ae, 0x0b1b786f, 0x0a7d9af6, 0xcaa21437, - 0x49b72f1e, 0x8968a1df, 0x880e4346, 0x48d1cd87, 0x8e253514, - 0x4efabbd5, 0x4f9c594c, 0x8f43d78d, 0x0c56eca4, 0xcc896265, - 0xcdef80fc, 0x0d300e3d, 0xd78f9c86, 0x17501247, 0x1636f0de, - 0xd6e97e1f, 0x55fc4536, 0x9523cbf7, 0x9445296e, 0x549aa7af, - 0x926e5f3c, 0x52b1d1fd, 0x53d73364, 0x9308bda5, 0x101d868c, - 0xd0c2084d, 0xd1a4ead4, 0x117b6415, 0x1c4b6a28, 0xdc94e4e9, - 0xddf20670, 0x1d2d88b1, 0x9e38b398, 0x5ee73d59, 0x5f81dfc0, - 0x9f5e5101, 0x59aaa992, 0x99752753, 0x9813c5ca, 0x58cc4b0b, - 0xdbd97022, 0x1b06fee3, 0x1a601c7a, 0xdabf92bb, 0xef1948d6, - 0x2fc6c617, 0x2ea0248e, 0xee7faa4f, 0x6d6a9166, 0xadb51fa7, - 0xacd3fd3e, 0x6c0c73ff, 0xaaf88b6c, 0x6a2705ad, 0x6b41e734, - 0xab9e69f5, 0x288b52dc, 0xe854dc1d, 0xe9323e84, 0x29edb045, - 0x24ddbe78, 0xe40230b9, 0xe564d220, 0x25bb5ce1, 0xa6ae67c8, - 0x6671e909, 0x67170b90, 0xa7c88551, 0x613c7dc2, 0xa1e3f303, - 0xa085119a, 0x605a9f5b, 0xe34fa472, 0x23902ab3, 0x22f6c82a, - 0xe22946eb, 0x3896d450, 0xf8495a91, 0xf92fb808, 0x39f036c9, - 0xbae50de0, 0x7a3a8321, 0x7b5c61b8, 0xbb83ef79, 0x7d7717ea, - 0xbda8992b, 0xbcce7bb2, 0x7c11f573, 0xff04ce5a, 0x3fdb409b, - 0x3ebda202, 0xfe622cc3, 0xf35222fe, 0x338dac3f, 0x32eb4ea6, - 0xf234c067, 0x7121fb4e, 0xb1fe758f, 0xb0989716, 0x704719d7, - 0xb6b3e144, 0x766c6f85, 0x770a8d1c, 0xb7d503dd, 0x34c038f4, - 0xf41fb635, 0xf57954ac, 0x35a6da6d, 0x9f35e177, 0x5fea6fb6, - 0x5e8c8d2f, 0x9e5303ee, 0x1d4638c7, 0xdd99b606, 0xdcff549f, - 0x1c20da5e, 0xdad422cd, 0x1a0bac0c, 0x1b6d4e95, 0xdbb2c054, - 0x58a7fb7d, 0x987875bc, 0x991e9725, 0x59c119e4, 0x54f117d9, - 0x942e9918, 0x95487b81, 0x5597f540, 0xd682ce69, 0x165d40a8, - 0x173ba231, 0xd7e42cf0, 0x1110d463, 0xd1cf5aa2, 0xd0a9b83b, - 0x107636fa, 0x93630dd3, 0x53bc8312, 0x52da618b, 0x9205ef4a, - 0x48ba7df1, 0x8865f330, 0x890311a9, 0x49dc9f68, 0xcac9a441, - 0x0a162a80, 0x0b70c819, 0xcbaf46d8, 0x0d5bbe4b, 0xcd84308a, - 0xcce2d213, 0x0c3d5cd2, 0x8f2867fb, 0x4ff7e93a, 0x4e910ba3, - 0x8e4e8562, 0x837e8b5f, 0x43a1059e, 0x42c7e707, 0x821869c6, - 0x010d52ef, 0xc1d2dc2e, 0xc0b43eb7, 0x006bb076, 0xc69f48e5, - 0x0640c624, 0x072624bd, 0xc7f9aa7c, 0x44ec9155, 0x84331f94, - 0x8555fd0d, 0x458a73cc, 0x702ca9a1, 0xb0f32760, 0xb195c5f9, - 0x714a4b38, 0xf25f7011, 0x3280fed0, 0x33e61c49, 0xf3399288, - 0x35cd6a1b, 0xf512e4da, 0xf4740643, 0x34ab8882, 0xb7beb3ab, - 0x77613d6a, 0x7607dff3, 0xb6d85132, 0xbbe85f0f, 0x7b37d1ce, - 0x7a513357, 0xba8ebd96, 0x399b86bf, 0xf944087e, 0xf822eae7, - 0x38fd6426, 0xfe099cb5, 0x3ed61274, 0x3fb0f0ed, 0xff6f7e2c, - 0x7c7a4505, 0xbca5cbc4, 0xbdc3295d, 0x7d1ca79c, 0xa7a33527, - 0x677cbbe6, 0x661a597f, 0xa6c5d7be, 0x25d0ec97, 0xe50f6256, - 0xe46980cf, 0x24b60e0e, 0xe242f69d, 0x229d785c, 0x23fb9ac5, - 0xe3241404, 0x60312f2d, 0xa0eea1ec, 0xa1884375, 0x6157cdb4, - 0x6c67c389, 0xacb84d48, 0xaddeafd1, 0x6d012110, 0xee141a39, - 0x2ecb94f8, 0x2fad7661, 0xef72f8a0, 0x29860033, 0xe9598ef2, - 0xe83f6c6b, 0x28e0e2aa, 0xabf5d983, 0x6b2a5742, 0x6a4cb5db, - 0xaa933b1a}, - {0x00000000, 0x6f4ca59b, 0x9f9e3bec, 0xf0d29e77, 0x7f3b0603, - 0x1077a398, 0xe0a53def, 0x8fe99874, 0xfe760c06, 0x913aa99d, - 0x61e837ea, 0x0ea49271, 0x814d0a05, 0xee01af9e, 0x1ed331e9, - 0x719f9472, 0xfced180c, 0x93a1bd97, 0x637323e0, 0x0c3f867b, - 0x83d61e0f, 0xec9abb94, 0x1c4825e3, 0x73048078, 0x029b140a, - 0x6dd7b191, 0x9d052fe6, 0xf2498a7d, 0x7da01209, 0x12ecb792, - 0xe23e29e5, 0x8d728c7e, 0xf8db3118, 0x97979483, 0x67450af4, - 0x0809af6f, 0x87e0371b, 0xe8ac9280, 0x187e0cf7, 0x7732a96c, - 0x06ad3d1e, 0x69e19885, 0x993306f2, 0xf67fa369, 0x79963b1d, - 0x16da9e86, 0xe60800f1, 0x8944a56a, 0x04362914, 0x6b7a8c8f, - 0x9ba812f8, 0xf4e4b763, 0x7b0d2f17, 0x14418a8c, 0xe49314fb, - 0x8bdfb160, 0xfa402512, 0x950c8089, 0x65de1efe, 0x0a92bb65, - 0x857b2311, 0xea37868a, 0x1ae518fd, 0x75a9bd66, 0xf0b76330, - 0x9ffbc6ab, 0x6f2958dc, 0x0065fd47, 0x8f8c6533, 0xe0c0c0a8, - 0x10125edf, 0x7f5efb44, 0x0ec16f36, 0x618dcaad, 0x915f54da, - 0xfe13f141, 0x71fa6935, 0x1eb6ccae, 0xee6452d9, 0x8128f742, - 0x0c5a7b3c, 0x6316dea7, 0x93c440d0, 0xfc88e54b, 0x73617d3f, - 0x1c2dd8a4, 0xecff46d3, 0x83b3e348, 0xf22c773a, 0x9d60d2a1, - 0x6db24cd6, 0x02fee94d, 0x8d177139, 0xe25bd4a2, 0x12894ad5, - 0x7dc5ef4e, 0x086c5228, 0x6720f7b3, 0x97f269c4, 0xf8becc5f, - 0x7757542b, 0x181bf1b0, 0xe8c96fc7, 0x8785ca5c, 0xf61a5e2e, - 0x9956fbb5, 0x698465c2, 0x06c8c059, 0x8921582d, 0xe66dfdb6, - 0x16bf63c1, 0x79f3c65a, 0xf4814a24, 0x9bcdefbf, 0x6b1f71c8, - 0x0453d453, 0x8bba4c27, 0xe4f6e9bc, 0x142477cb, 0x7b68d250, - 0x0af74622, 0x65bbe3b9, 0x95697dce, 0xfa25d855, 0x75cc4021, - 0x1a80e5ba, 0xea527bcd, 0x851ede56, 0xe06fc760, 0x8f2362fb, - 0x7ff1fc8c, 0x10bd5917, 0x9f54c163, 0xf01864f8, 0x00cafa8f, - 0x6f865f14, 0x1e19cb66, 0x71556efd, 0x8187f08a, 0xeecb5511, - 0x6122cd65, 0x0e6e68fe, 0xfebcf689, 0x91f05312, 0x1c82df6c, - 0x73ce7af7, 0x831ce480, 0xec50411b, 0x63b9d96f, 0x0cf57cf4, - 0xfc27e283, 0x936b4718, 0xe2f4d36a, 0x8db876f1, 0x7d6ae886, - 0x12264d1d, 0x9dcfd569, 0xf28370f2, 0x0251ee85, 0x6d1d4b1e, - 0x18b4f678, 0x77f853e3, 0x872acd94, 0xe866680f, 0x678ff07b, - 0x08c355e0, 0xf811cb97, 0x975d6e0c, 0xe6c2fa7e, 0x898e5fe5, - 0x795cc192, 0x16106409, 0x99f9fc7d, 0xf6b559e6, 0x0667c791, - 0x692b620a, 0xe459ee74, 0x8b154bef, 0x7bc7d598, 0x148b7003, - 0x9b62e877, 0xf42e4dec, 0x04fcd39b, 0x6bb07600, 0x1a2fe272, - 0x756347e9, 0x85b1d99e, 0xeafd7c05, 0x6514e471, 0x0a5841ea, - 0xfa8adf9d, 0x95c67a06, 0x10d8a450, 0x7f9401cb, 0x8f469fbc, - 0xe00a3a27, 0x6fe3a253, 0x00af07c8, 0xf07d99bf, 0x9f313c24, - 0xeeaea856, 0x81e20dcd, 0x713093ba, 0x1e7c3621, 0x9195ae55, - 0xfed90bce, 0x0e0b95b9, 0x61473022, 0xec35bc5c, 0x837919c7, - 0x73ab87b0, 0x1ce7222b, 0x930eba5f, 0xfc421fc4, 0x0c9081b3, - 0x63dc2428, 0x1243b05a, 0x7d0f15c1, 0x8ddd8bb6, 0xe2912e2d, - 0x6d78b659, 0x023413c2, 0xf2e68db5, 0x9daa282e, 0xe8039548, - 0x874f30d3, 0x779daea4, 0x18d10b3f, 0x9738934b, 0xf87436d0, - 0x08a6a8a7, 0x67ea0d3c, 0x1675994e, 0x79393cd5, 0x89eba2a2, - 0xe6a70739, 0x694e9f4d, 0x06023ad6, 0xf6d0a4a1, 0x999c013a, - 0x14ee8d44, 0x7ba228df, 0x8b70b6a8, 0xe43c1333, 0x6bd58b47, - 0x04992edc, 0xf44bb0ab, 0x9b071530, 0xea988142, 0x85d424d9, - 0x7506baae, 0x1a4a1f35, 0x95a38741, 0xfaef22da, 0x0a3dbcad, - 0x65711936}}; - -#endif - -#endif - -#if N == 4 - -#if W == 8 - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0xf1da05aa, 0x38c50d15, 0xc91f08bf, 0x718a1a2a, - 0x80501f80, 0x494f173f, 0xb8951295, 0xe3143454, 0x12ce31fe, - 0xdbd13941, 0x2a0b3ceb, 0x929e2e7e, 0x63442bd4, 0xaa5b236b, - 0x5b8126c1, 0x1d596ee9, 0xec836b43, 0x259c63fc, 0xd4466656, - 0x6cd374c3, 0x9d097169, 0x541679d6, 0xa5cc7c7c, 0xfe4d5abd, - 0x0f975f17, 0xc68857a8, 0x37525202, 0x8fc74097, 0x7e1d453d, - 0xb7024d82, 0x46d84828, 0x3ab2ddd2, 0xcb68d878, 0x0277d0c7, - 0xf3add56d, 0x4b38c7f8, 0xbae2c252, 0x73fdcaed, 0x8227cf47, - 0xd9a6e986, 0x287cec2c, 0xe163e493, 0x10b9e139, 0xa82cf3ac, - 0x59f6f606, 0x90e9feb9, 0x6133fb13, 0x27ebb33b, 0xd631b691, - 0x1f2ebe2e, 0xeef4bb84, 0x5661a911, 0xa7bbacbb, 0x6ea4a404, - 0x9f7ea1ae, 0xc4ff876f, 0x352582c5, 0xfc3a8a7a, 0x0de08fd0, - 0xb5759d45, 0x44af98ef, 0x8db09050, 0x7c6a95fa, 0x7565bba4, - 0x84bfbe0e, 0x4da0b6b1, 0xbc7ab31b, 0x04efa18e, 0xf535a424, - 0x3c2aac9b, 0xcdf0a931, 0x96718ff0, 0x67ab8a5a, 0xaeb482e5, - 0x5f6e874f, 0xe7fb95da, 0x16219070, 0xdf3e98cf, 0x2ee49d65, - 0x683cd54d, 0x99e6d0e7, 0x50f9d858, 0xa123ddf2, 0x19b6cf67, - 0xe86ccacd, 0x2173c272, 0xd0a9c7d8, 0x8b28e119, 0x7af2e4b3, - 0xb3edec0c, 0x4237e9a6, 0xfaa2fb33, 0x0b78fe99, 0xc267f626, - 0x33bdf38c, 0x4fd76676, 0xbe0d63dc, 0x77126b63, 0x86c86ec9, - 0x3e5d7c5c, 0xcf8779f6, 0x06987149, 0xf74274e3, 0xacc35222, - 0x5d195788, 0x94065f37, 0x65dc5a9d, 0xdd494808, 0x2c934da2, - 0xe58c451d, 0x145640b7, 0x528e089f, 0xa3540d35, 0x6a4b058a, - 0x9b910020, 0x230412b5, 0xd2de171f, 0x1bc11fa0, 0xea1b1a0a, - 0xb19a3ccb, 0x40403961, 0x895f31de, 0x78853474, 0xc01026e1, - 0x31ca234b, 0xf8d52bf4, 0x090f2e5e, 0xeacb7748, 0x1b1172e2, - 0xd20e7a5d, 0x23d47ff7, 0x9b416d62, 0x6a9b68c8, 0xa3846077, - 0x525e65dd, 0x09df431c, 0xf80546b6, 0x311a4e09, 0xc0c04ba3, - 0x78555936, 0x898f5c9c, 0x40905423, 0xb14a5189, 0xf79219a1, - 0x06481c0b, 0xcf5714b4, 0x3e8d111e, 0x8618038b, 0x77c20621, - 0xbedd0e9e, 0x4f070b34, 0x14862df5, 0xe55c285f, 0x2c4320e0, - 0xdd99254a, 0x650c37df, 0x94d63275, 0x5dc93aca, 0xac133f60, - 0xd079aa9a, 0x21a3af30, 0xe8bca78f, 0x1966a225, 0xa1f3b0b0, - 0x5029b51a, 0x9936bda5, 0x68ecb80f, 0x336d9ece, 0xc2b79b64, - 0x0ba893db, 0xfa729671, 0x42e784e4, 0xb33d814e, 0x7a2289f1, - 0x8bf88c5b, 0xcd20c473, 0x3cfac1d9, 0xf5e5c966, 0x043fcccc, - 0xbcaade59, 0x4d70dbf3, 0x846fd34c, 0x75b5d6e6, 0x2e34f027, - 0xdfeef58d, 0x16f1fd32, 0xe72bf898, 0x5fbeea0d, 0xae64efa7, - 0x677be718, 0x96a1e2b2, 0x9faeccec, 0x6e74c946, 0xa76bc1f9, - 0x56b1c453, 0xee24d6c6, 0x1ffed36c, 0xd6e1dbd3, 0x273bde79, - 0x7cbaf8b8, 0x8d60fd12, 0x447ff5ad, 0xb5a5f007, 0x0d30e292, - 0xfceae738, 0x35f5ef87, 0xc42fea2d, 0x82f7a205, 0x732da7af, - 0xba32af10, 0x4be8aaba, 0xf37db82f, 0x02a7bd85, 0xcbb8b53a, - 0x3a62b090, 0x61e39651, 0x903993fb, 0x59269b44, 0xa8fc9eee, - 0x10698c7b, 0xe1b389d1, 0x28ac816e, 0xd97684c4, 0xa51c113e, - 0x54c61494, 0x9dd91c2b, 0x6c031981, 0xd4960b14, 0x254c0ebe, - 0xec530601, 0x1d8903ab, 0x4608256a, 0xb7d220c0, 0x7ecd287f, - 0x8f172dd5, 0x37823f40, 0xc6583aea, 0x0f473255, 0xfe9d37ff, - 0xb8457fd7, 0x499f7a7d, 0x808072c2, 0x715a7768, 0xc9cf65fd, - 0x38156057, 0xf10a68e8, 0x00d06d42, 0x5b514b83, 0xaa8b4e29, - 0x63944696, 0x924e433c, 0x2adb51a9, 0xdb015403, 0x121e5cbc, - 0xe3c45916}, - {0x00000000, 0x0ee7e8d1, 0x1dcfd1a2, 0x13283973, 0x3b9fa344, - 0x35784b95, 0x265072e6, 0x28b79a37, 0x773f4688, 0x79d8ae59, - 0x6af0972a, 0x64177ffb, 0x4ca0e5cc, 0x42470d1d, 0x516f346e, - 0x5f88dcbf, 0xee7e8d10, 0xe09965c1, 0xf3b15cb2, 0xfd56b463, - 0xd5e12e54, 0xdb06c685, 0xc82efff6, 0xc6c91727, 0x9941cb98, - 0x97a62349, 0x848e1a3a, 0x8a69f2eb, 0xa2de68dc, 0xac39800d, - 0xbf11b97e, 0xb1f651af, 0x078c1c61, 0x096bf4b0, 0x1a43cdc3, - 0x14a42512, 0x3c13bf25, 0x32f457f4, 0x21dc6e87, 0x2f3b8656, - 0x70b35ae9, 0x7e54b238, 0x6d7c8b4b, 0x639b639a, 0x4b2cf9ad, - 0x45cb117c, 0x56e3280f, 0x5804c0de, 0xe9f29171, 0xe71579a0, - 0xf43d40d3, 0xfadaa802, 0xd26d3235, 0xdc8adae4, 0xcfa2e397, - 0xc1450b46, 0x9ecdd7f9, 0x902a3f28, 0x8302065b, 0x8de5ee8a, - 0xa55274bd, 0xabb59c6c, 0xb89da51f, 0xb67a4dce, 0x0f1838c2, - 0x01ffd013, 0x12d7e960, 0x1c3001b1, 0x34879b86, 0x3a607357, - 0x29484a24, 0x27afa2f5, 0x78277e4a, 0x76c0969b, 0x65e8afe8, - 0x6b0f4739, 0x43b8dd0e, 0x4d5f35df, 0x5e770cac, 0x5090e47d, - 0xe166b5d2, 0xef815d03, 0xfca96470, 0xf24e8ca1, 0xdaf91696, - 0xd41efe47, 0xc736c734, 0xc9d12fe5, 0x9659f35a, 0x98be1b8b, - 0x8b9622f8, 0x8571ca29, 0xadc6501e, 0xa321b8cf, 0xb00981bc, - 0xbeee696d, 0x089424a3, 0x0673cc72, 0x155bf501, 0x1bbc1dd0, - 0x330b87e7, 0x3dec6f36, 0x2ec45645, 0x2023be94, 0x7fab622b, - 0x714c8afa, 0x6264b389, 0x6c835b58, 0x4434c16f, 0x4ad329be, - 0x59fb10cd, 0x571cf81c, 0xe6eaa9b3, 0xe80d4162, 0xfb257811, - 0xf5c290c0, 0xdd750af7, 0xd392e226, 0xc0badb55, 0xce5d3384, - 0x91d5ef3b, 0x9f3207ea, 0x8c1a3e99, 0x82fdd648, 0xaa4a4c7f, - 0xa4ada4ae, 0xb7859ddd, 0xb962750c, 0x1e307184, 0x10d79955, - 0x03ffa026, 0x0d1848f7, 0x25afd2c0, 0x2b483a11, 0x38600362, - 0x3687ebb3, 0x690f370c, 0x67e8dfdd, 0x74c0e6ae, 0x7a270e7f, - 0x52909448, 0x5c777c99, 0x4f5f45ea, 0x41b8ad3b, 0xf04efc94, - 0xfea91445, 0xed812d36, 0xe366c5e7, 0xcbd15fd0, 0xc536b701, - 0xd61e8e72, 0xd8f966a3, 0x8771ba1c, 0x899652cd, 0x9abe6bbe, - 0x9459836f, 0xbcee1958, 0xb209f189, 0xa121c8fa, 0xafc6202b, - 0x19bc6de5, 0x175b8534, 0x0473bc47, 0x0a945496, 0x2223cea1, - 0x2cc42670, 0x3fec1f03, 0x310bf7d2, 0x6e832b6d, 0x6064c3bc, - 0x734cfacf, 0x7dab121e, 0x551c8829, 0x5bfb60f8, 0x48d3598b, - 0x4634b15a, 0xf7c2e0f5, 0xf9250824, 0xea0d3157, 0xe4ead986, - 0xcc5d43b1, 0xc2baab60, 0xd1929213, 0xdf757ac2, 0x80fda67d, - 0x8e1a4eac, 0x9d3277df, 0x93d59f0e, 0xbb620539, 0xb585ede8, - 0xa6add49b, 0xa84a3c4a, 0x11284946, 0x1fcfa197, 0x0ce798e4, - 0x02007035, 0x2ab7ea02, 0x245002d3, 0x37783ba0, 0x399fd371, - 0x66170fce, 0x68f0e71f, 0x7bd8de6c, 0x753f36bd, 0x5d88ac8a, - 0x536f445b, 0x40477d28, 0x4ea095f9, 0xff56c456, 0xf1b12c87, - 0xe29915f4, 0xec7efd25, 0xc4c96712, 0xca2e8fc3, 0xd906b6b0, - 0xd7e15e61, 0x886982de, 0x868e6a0f, 0x95a6537c, 0x9b41bbad, - 0xb3f6219a, 0xbd11c94b, 0xae39f038, 0xa0de18e9, 0x16a45527, - 0x1843bdf6, 0x0b6b8485, 0x058c6c54, 0x2d3bf663, 0x23dc1eb2, - 0x30f427c1, 0x3e13cf10, 0x619b13af, 0x6f7cfb7e, 0x7c54c20d, - 0x72b32adc, 0x5a04b0eb, 0x54e3583a, 0x47cb6149, 0x492c8998, - 0xf8dad837, 0xf63d30e6, 0xe5150995, 0xebf2e144, 0xc3457b73, - 0xcda293a2, 0xde8aaad1, 0xd06d4200, 0x8fe59ebf, 0x8102766e, - 0x922a4f1d, 0x9ccda7cc, 0xb47a3dfb, 0xba9dd52a, 0xa9b5ec59, - 0xa7520488}, - {0x00000000, 0x3c60e308, 0x78c1c610, 0x44a12518, 0xf1838c20, - 0xcde36f28, 0x89424a30, 0xb522a938, 0x38761e01, 0x0416fd09, - 0x40b7d811, 0x7cd73b19, 0xc9f59221, 0xf5957129, 0xb1345431, - 0x8d54b739, 0x70ec3c02, 0x4c8cdf0a, 0x082dfa12, 0x344d191a, - 0x816fb022, 0xbd0f532a, 0xf9ae7632, 0xc5ce953a, 0x489a2203, - 0x74fac10b, 0x305be413, 0x0c3b071b, 0xb919ae23, 0x85794d2b, - 0xc1d86833, 0xfdb88b3b, 0xe1d87804, 0xddb89b0c, 0x9919be14, - 0xa5795d1c, 0x105bf424, 0x2c3b172c, 0x689a3234, 0x54fad13c, - 0xd9ae6605, 0xe5ce850d, 0xa16fa015, 0x9d0f431d, 0x282dea25, - 0x144d092d, 0x50ec2c35, 0x6c8ccf3d, 0x91344406, 0xad54a70e, - 0xe9f58216, 0xd595611e, 0x60b7c826, 0x5cd72b2e, 0x18760e36, - 0x2416ed3e, 0xa9425a07, 0x9522b90f, 0xd1839c17, 0xede37f1f, - 0x58c1d627, 0x64a1352f, 0x20001037, 0x1c60f33f, 0x18c1f649, - 0x24a11541, 0x60003059, 0x5c60d351, 0xe9427a69, 0xd5229961, - 0x9183bc79, 0xade35f71, 0x20b7e848, 0x1cd70b40, 0x58762e58, - 0x6416cd50, 0xd1346468, 0xed548760, 0xa9f5a278, 0x95954170, - 0x682dca4b, 0x544d2943, 0x10ec0c5b, 0x2c8cef53, 0x99ae466b, - 0xa5cea563, 0xe16f807b, 0xdd0f6373, 0x505bd44a, 0x6c3b3742, - 0x289a125a, 0x14faf152, 0xa1d8586a, 0x9db8bb62, 0xd9199e7a, - 0xe5797d72, 0xf9198e4d, 0xc5796d45, 0x81d8485d, 0xbdb8ab55, - 0x089a026d, 0x34fae165, 0x705bc47d, 0x4c3b2775, 0xc16f904c, - 0xfd0f7344, 0xb9ae565c, 0x85ceb554, 0x30ec1c6c, 0x0c8cff64, - 0x482dda7c, 0x744d3974, 0x89f5b24f, 0xb5955147, 0xf134745f, - 0xcd549757, 0x78763e6f, 0x4416dd67, 0x00b7f87f, 0x3cd71b77, - 0xb183ac4e, 0x8de34f46, 0xc9426a5e, 0xf5228956, 0x4000206e, - 0x7c60c366, 0x38c1e67e, 0x04a10576, 0x3183ec92, 0x0de30f9a, - 0x49422a82, 0x7522c98a, 0xc00060b2, 0xfc6083ba, 0xb8c1a6a2, - 0x84a145aa, 0x09f5f293, 0x3595119b, 0x71343483, 0x4d54d78b, - 0xf8767eb3, 0xc4169dbb, 0x80b7b8a3, 0xbcd75bab, 0x416fd090, - 0x7d0f3398, 0x39ae1680, 0x05cef588, 0xb0ec5cb0, 0x8c8cbfb8, - 0xc82d9aa0, 0xf44d79a8, 0x7919ce91, 0x45792d99, 0x01d80881, - 0x3db8eb89, 0x889a42b1, 0xb4faa1b9, 0xf05b84a1, 0xcc3b67a9, - 0xd05b9496, 0xec3b779e, 0xa89a5286, 0x94fab18e, 0x21d818b6, - 0x1db8fbbe, 0x5919dea6, 0x65793dae, 0xe82d8a97, 0xd44d699f, - 0x90ec4c87, 0xac8caf8f, 0x19ae06b7, 0x25cee5bf, 0x616fc0a7, - 0x5d0f23af, 0xa0b7a894, 0x9cd74b9c, 0xd8766e84, 0xe4168d8c, - 0x513424b4, 0x6d54c7bc, 0x29f5e2a4, 0x159501ac, 0x98c1b695, - 0xa4a1559d, 0xe0007085, 0xdc60938d, 0x69423ab5, 0x5522d9bd, - 0x1183fca5, 0x2de31fad, 0x29421adb, 0x1522f9d3, 0x5183dccb, - 0x6de33fc3, 0xd8c196fb, 0xe4a175f3, 0xa00050eb, 0x9c60b3e3, - 0x113404da, 0x2d54e7d2, 0x69f5c2ca, 0x559521c2, 0xe0b788fa, - 0xdcd76bf2, 0x98764eea, 0xa416ade2, 0x59ae26d9, 0x65cec5d1, - 0x216fe0c9, 0x1d0f03c1, 0xa82daaf9, 0x944d49f1, 0xd0ec6ce9, - 0xec8c8fe1, 0x61d838d8, 0x5db8dbd0, 0x1919fec8, 0x25791dc0, - 0x905bb4f8, 0xac3b57f0, 0xe89a72e8, 0xd4fa91e0, 0xc89a62df, - 0xf4fa81d7, 0xb05ba4cf, 0x8c3b47c7, 0x3919eeff, 0x05790df7, - 0x41d828ef, 0x7db8cbe7, 0xf0ec7cde, 0xcc8c9fd6, 0x882dbace, - 0xb44d59c6, 0x016ff0fe, 0x3d0f13f6, 0x79ae36ee, 0x45ced5e6, - 0xb8765edd, 0x8416bdd5, 0xc0b798cd, 0xfcd77bc5, 0x49f5d2fd, - 0x759531f5, 0x313414ed, 0x0d54f7e5, 0x800040dc, 0xbc60a3d4, - 0xf8c186cc, 0xc4a165c4, 0x7183ccfc, 0x4de32ff4, 0x09420aec, - 0x3522e9e4}, - {0x00000000, 0x6307d924, 0xc60fb248, 0xa5086b6c, 0x576e62d1, - 0x3469bbf5, 0x9161d099, 0xf26609bd, 0xaedcc5a2, 0xcddb1c86, - 0x68d377ea, 0x0bd4aece, 0xf9b2a773, 0x9ab57e57, 0x3fbd153b, - 0x5cbacc1f, 0x86c88d05, 0xe5cf5421, 0x40c73f4d, 0x23c0e669, - 0xd1a6efd4, 0xb2a136f0, 0x17a95d9c, 0x74ae84b8, 0x281448a7, - 0x4b139183, 0xee1bfaef, 0x8d1c23cb, 0x7f7a2a76, 0x1c7df352, - 0xb975983e, 0xda72411a, 0xd6e01c4b, 0xb5e7c56f, 0x10efae03, - 0x73e87727, 0x818e7e9a, 0xe289a7be, 0x4781ccd2, 0x248615f6, - 0x783cd9e9, 0x1b3b00cd, 0xbe336ba1, 0xdd34b285, 0x2f52bb38, - 0x4c55621c, 0xe95d0970, 0x8a5ad054, 0x5028914e, 0x332f486a, - 0x96272306, 0xf520fa22, 0x0746f39f, 0x64412abb, 0xc14941d7, - 0xa24e98f3, 0xfef454ec, 0x9df38dc8, 0x38fbe6a4, 0x5bfc3f80, - 0xa99a363d, 0xca9def19, 0x6f958475, 0x0c925d51, 0x76b13ed7, - 0x15b6e7f3, 0xb0be8c9f, 0xd3b955bb, 0x21df5c06, 0x42d88522, - 0xe7d0ee4e, 0x84d7376a, 0xd86dfb75, 0xbb6a2251, 0x1e62493d, - 0x7d659019, 0x8f0399a4, 0xec044080, 0x490c2bec, 0x2a0bf2c8, - 0xf079b3d2, 0x937e6af6, 0x3676019a, 0x5571d8be, 0xa717d103, - 0xc4100827, 0x6118634b, 0x021fba6f, 0x5ea57670, 0x3da2af54, - 0x98aac438, 0xfbad1d1c, 0x09cb14a1, 0x6acccd85, 0xcfc4a6e9, - 0xacc37fcd, 0xa051229c, 0xc356fbb8, 0x665e90d4, 0x055949f0, - 0xf73f404d, 0x94389969, 0x3130f205, 0x52372b21, 0x0e8de73e, - 0x6d8a3e1a, 0xc8825576, 0xab858c52, 0x59e385ef, 0x3ae45ccb, - 0x9fec37a7, 0xfcebee83, 0x2699af99, 0x459e76bd, 0xe0961dd1, - 0x8391c4f5, 0x71f7cd48, 0x12f0146c, 0xb7f87f00, 0xd4ffa624, - 0x88456a3b, 0xeb42b31f, 0x4e4ad873, 0x2d4d0157, 0xdf2b08ea, - 0xbc2cd1ce, 0x1924baa2, 0x7a236386, 0xed627dae, 0x8e65a48a, - 0x2b6dcfe6, 0x486a16c2, 0xba0c1f7f, 0xd90bc65b, 0x7c03ad37, - 0x1f047413, 0x43beb80c, 0x20b96128, 0x85b10a44, 0xe6b6d360, - 0x14d0dadd, 0x77d703f9, 0xd2df6895, 0xb1d8b1b1, 0x6baaf0ab, - 0x08ad298f, 0xada542e3, 0xcea29bc7, 0x3cc4927a, 0x5fc34b5e, - 0xfacb2032, 0x99ccf916, 0xc5763509, 0xa671ec2d, 0x03798741, - 0x607e5e65, 0x921857d8, 0xf11f8efc, 0x5417e590, 0x37103cb4, - 0x3b8261e5, 0x5885b8c1, 0xfd8dd3ad, 0x9e8a0a89, 0x6cec0334, - 0x0febda10, 0xaae3b17c, 0xc9e46858, 0x955ea447, 0xf6597d63, - 0x5351160f, 0x3056cf2b, 0xc230c696, 0xa1371fb2, 0x043f74de, - 0x6738adfa, 0xbd4aece0, 0xde4d35c4, 0x7b455ea8, 0x1842878c, - 0xea248e31, 0x89235715, 0x2c2b3c79, 0x4f2ce55d, 0x13962942, - 0x7091f066, 0xd5999b0a, 0xb69e422e, 0x44f84b93, 0x27ff92b7, - 0x82f7f9db, 0xe1f020ff, 0x9bd34379, 0xf8d49a5d, 0x5ddcf131, - 0x3edb2815, 0xccbd21a8, 0xafbaf88c, 0x0ab293e0, 0x69b54ac4, - 0x350f86db, 0x56085fff, 0xf3003493, 0x9007edb7, 0x6261e40a, - 0x01663d2e, 0xa46e5642, 0xc7698f66, 0x1d1bce7c, 0x7e1c1758, - 0xdb147c34, 0xb813a510, 0x4a75acad, 0x29727589, 0x8c7a1ee5, - 0xef7dc7c1, 0xb3c70bde, 0xd0c0d2fa, 0x75c8b996, 0x16cf60b2, - 0xe4a9690f, 0x87aeb02b, 0x22a6db47, 0x41a10263, 0x4d335f32, - 0x2e348616, 0x8b3ced7a, 0xe83b345e, 0x1a5d3de3, 0x795ae4c7, - 0xdc528fab, 0xbf55568f, 0xe3ef9a90, 0x80e843b4, 0x25e028d8, - 0x46e7f1fc, 0xb481f841, 0xd7862165, 0x728e4a09, 0x1189932d, - 0xcbfbd237, 0xa8fc0b13, 0x0df4607f, 0x6ef3b95b, 0x9c95b0e6, - 0xff9269c2, 0x5a9a02ae, 0x399ddb8a, 0x65271795, 0x0620ceb1, - 0xa328a5dd, 0xc02f7cf9, 0x32497544, 0x514eac60, 0xf446c70c, - 0x97411e28}, - {0x00000000, 0x01b5fd1d, 0x036bfa3a, 0x02de0727, 0x06d7f474, - 0x07620969, 0x05bc0e4e, 0x0409f353, 0x0dafe8e8, 0x0c1a15f5, - 0x0ec412d2, 0x0f71efcf, 0x0b781c9c, 0x0acde181, 0x0813e6a6, - 0x09a61bbb, 0x1b5fd1d0, 0x1aea2ccd, 0x18342bea, 0x1981d6f7, - 0x1d8825a4, 0x1c3dd8b9, 0x1ee3df9e, 0x1f562283, 0x16f03938, - 0x1745c425, 0x159bc302, 0x142e3e1f, 0x1027cd4c, 0x11923051, - 0x134c3776, 0x12f9ca6b, 0x36bfa3a0, 0x370a5ebd, 0x35d4599a, - 0x3461a487, 0x306857d4, 0x31ddaac9, 0x3303adee, 0x32b650f3, - 0x3b104b48, 0x3aa5b655, 0x387bb172, 0x39ce4c6f, 0x3dc7bf3c, - 0x3c724221, 0x3eac4506, 0x3f19b81b, 0x2de07270, 0x2c558f6d, - 0x2e8b884a, 0x2f3e7557, 0x2b378604, 0x2a827b19, 0x285c7c3e, - 0x29e98123, 0x204f9a98, 0x21fa6785, 0x232460a2, 0x22919dbf, - 0x26986eec, 0x272d93f1, 0x25f394d6, 0x244669cb, 0x6d7f4740, - 0x6ccaba5d, 0x6e14bd7a, 0x6fa14067, 0x6ba8b334, 0x6a1d4e29, - 0x68c3490e, 0x6976b413, 0x60d0afa8, 0x616552b5, 0x63bb5592, - 0x620ea88f, 0x66075bdc, 0x67b2a6c1, 0x656ca1e6, 0x64d95cfb, - 0x76209690, 0x77956b8d, 0x754b6caa, 0x74fe91b7, 0x70f762e4, - 0x71429ff9, 0x739c98de, 0x722965c3, 0x7b8f7e78, 0x7a3a8365, - 0x78e48442, 0x7951795f, 0x7d588a0c, 0x7ced7711, 0x7e337036, - 0x7f868d2b, 0x5bc0e4e0, 0x5a7519fd, 0x58ab1eda, 0x591ee3c7, - 0x5d171094, 0x5ca2ed89, 0x5e7ceaae, 0x5fc917b3, 0x566f0c08, - 0x57daf115, 0x5504f632, 0x54b10b2f, 0x50b8f87c, 0x510d0561, - 0x53d30246, 0x5266ff5b, 0x409f3530, 0x412ac82d, 0x43f4cf0a, - 0x42413217, 0x4648c144, 0x47fd3c59, 0x45233b7e, 0x4496c663, - 0x4d30ddd8, 0x4c8520c5, 0x4e5b27e2, 0x4feedaff, 0x4be729ac, - 0x4a52d4b1, 0x488cd396, 0x49392e8b, 0xdafe8e80, 0xdb4b739d, - 0xd99574ba, 0xd82089a7, 0xdc297af4, 0xdd9c87e9, 0xdf4280ce, - 0xdef77dd3, 0xd7516668, 0xd6e49b75, 0xd43a9c52, 0xd58f614f, - 0xd186921c, 0xd0336f01, 0xd2ed6826, 0xd358953b, 0xc1a15f50, - 0xc014a24d, 0xc2caa56a, 0xc37f5877, 0xc776ab24, 0xc6c35639, - 0xc41d511e, 0xc5a8ac03, 0xcc0eb7b8, 0xcdbb4aa5, 0xcf654d82, - 0xced0b09f, 0xcad943cc, 0xcb6cbed1, 0xc9b2b9f6, 0xc80744eb, - 0xec412d20, 0xedf4d03d, 0xef2ad71a, 0xee9f2a07, 0xea96d954, - 0xeb232449, 0xe9fd236e, 0xe848de73, 0xe1eec5c8, 0xe05b38d5, - 0xe2853ff2, 0xe330c2ef, 0xe73931bc, 0xe68ccca1, 0xe452cb86, - 0xe5e7369b, 0xf71efcf0, 0xf6ab01ed, 0xf47506ca, 0xf5c0fbd7, - 0xf1c90884, 0xf07cf599, 0xf2a2f2be, 0xf3170fa3, 0xfab11418, - 0xfb04e905, 0xf9daee22, 0xf86f133f, 0xfc66e06c, 0xfdd31d71, - 0xff0d1a56, 0xfeb8e74b, 0xb781c9c0, 0xb63434dd, 0xb4ea33fa, - 0xb55fcee7, 0xb1563db4, 0xb0e3c0a9, 0xb23dc78e, 0xb3883a93, - 0xba2e2128, 0xbb9bdc35, 0xb945db12, 0xb8f0260f, 0xbcf9d55c, - 0xbd4c2841, 0xbf922f66, 0xbe27d27b, 0xacde1810, 0xad6be50d, - 0xafb5e22a, 0xae001f37, 0xaa09ec64, 0xabbc1179, 0xa962165e, - 0xa8d7eb43, 0xa171f0f8, 0xa0c40de5, 0xa21a0ac2, 0xa3aff7df, - 0xa7a6048c, 0xa613f991, 0xa4cdfeb6, 0xa57803ab, 0x813e6a60, - 0x808b977d, 0x8255905a, 0x83e06d47, 0x87e99e14, 0x865c6309, - 0x8482642e, 0x85379933, 0x8c918288, 0x8d247f95, 0x8ffa78b2, - 0x8e4f85af, 0x8a4676fc, 0x8bf38be1, 0x892d8cc6, 0x889871db, - 0x9a61bbb0, 0x9bd446ad, 0x990a418a, 0x98bfbc97, 0x9cb64fc4, - 0x9d03b2d9, 0x9fddb5fe, 0x9e6848e3, 0x97ce5358, 0x967bae45, - 0x94a5a962, 0x9510547f, 0x9119a72c, 0x90ac5a31, 0x92725d16, - 0x93c7a00b}, - {0x00000000, 0x6e8c1b41, 0xdd183682, 0xb3942dc3, 0x61416b45, - 0x0fcd7004, 0xbc595dc7, 0xd2d54686, 0xc282d68a, 0xac0ecdcb, - 0x1f9ae008, 0x7116fb49, 0xa3c3bdcf, 0xcd4fa68e, 0x7edb8b4d, - 0x1057900c, 0x5e74ab55, 0x30f8b014, 0x836c9dd7, 0xede08696, - 0x3f35c010, 0x51b9db51, 0xe22df692, 0x8ca1edd3, 0x9cf67ddf, - 0xf27a669e, 0x41ee4b5d, 0x2f62501c, 0xfdb7169a, 0x933b0ddb, - 0x20af2018, 0x4e233b59, 0xbce956aa, 0xd2654deb, 0x61f16028, - 0x0f7d7b69, 0xdda83def, 0xb32426ae, 0x00b00b6d, 0x6e3c102c, - 0x7e6b8020, 0x10e79b61, 0xa373b6a2, 0xcdffade3, 0x1f2aeb65, - 0x71a6f024, 0xc232dde7, 0xacbec6a6, 0xe29dfdff, 0x8c11e6be, - 0x3f85cb7d, 0x5109d03c, 0x83dc96ba, 0xed508dfb, 0x5ec4a038, - 0x3048bb79, 0x201f2b75, 0x4e933034, 0xfd071df7, 0x938b06b6, - 0x415e4030, 0x2fd25b71, 0x9c4676b2, 0xf2ca6df3, 0xa2a3ab15, - 0xcc2fb054, 0x7fbb9d97, 0x113786d6, 0xc3e2c050, 0xad6edb11, - 0x1efaf6d2, 0x7076ed93, 0x60217d9f, 0x0ead66de, 0xbd394b1d, - 0xd3b5505c, 0x016016da, 0x6fec0d9b, 0xdc782058, 0xb2f43b19, - 0xfcd70040, 0x925b1b01, 0x21cf36c2, 0x4f432d83, 0x9d966b05, - 0xf31a7044, 0x408e5d87, 0x2e0246c6, 0x3e55d6ca, 0x50d9cd8b, - 0xe34de048, 0x8dc1fb09, 0x5f14bd8f, 0x3198a6ce, 0x820c8b0d, - 0xec80904c, 0x1e4afdbf, 0x70c6e6fe, 0xc352cb3d, 0xadded07c, - 0x7f0b96fa, 0x11878dbb, 0xa213a078, 0xcc9fbb39, 0xdcc82b35, - 0xb2443074, 0x01d01db7, 0x6f5c06f6, 0xbd894070, 0xd3055b31, - 0x609176f2, 0x0e1d6db3, 0x403e56ea, 0x2eb24dab, 0x9d266068, - 0xf3aa7b29, 0x217f3daf, 0x4ff326ee, 0xfc670b2d, 0x92eb106c, - 0x82bc8060, 0xec309b21, 0x5fa4b6e2, 0x3128ada3, 0xe3fdeb25, - 0x8d71f064, 0x3ee5dda7, 0x5069c6e6, 0x9e36506b, 0xf0ba4b2a, - 0x432e66e9, 0x2da27da8, 0xff773b2e, 0x91fb206f, 0x226f0dac, - 0x4ce316ed, 0x5cb486e1, 0x32389da0, 0x81acb063, 0xef20ab22, - 0x3df5eda4, 0x5379f6e5, 0xe0eddb26, 0x8e61c067, 0xc042fb3e, - 0xaecee07f, 0x1d5acdbc, 0x73d6d6fd, 0xa103907b, 0xcf8f8b3a, - 0x7c1ba6f9, 0x1297bdb8, 0x02c02db4, 0x6c4c36f5, 0xdfd81b36, - 0xb1540077, 0x638146f1, 0x0d0d5db0, 0xbe997073, 0xd0156b32, - 0x22df06c1, 0x4c531d80, 0xffc73043, 0x914b2b02, 0x439e6d84, - 0x2d1276c5, 0x9e865b06, 0xf00a4047, 0xe05dd04b, 0x8ed1cb0a, - 0x3d45e6c9, 0x53c9fd88, 0x811cbb0e, 0xef90a04f, 0x5c048d8c, - 0x328896cd, 0x7cabad94, 0x1227b6d5, 0xa1b39b16, 0xcf3f8057, - 0x1deac6d1, 0x7366dd90, 0xc0f2f053, 0xae7eeb12, 0xbe297b1e, - 0xd0a5605f, 0x63314d9c, 0x0dbd56dd, 0xdf68105b, 0xb1e40b1a, - 0x027026d9, 0x6cfc3d98, 0x3c95fb7e, 0x5219e03f, 0xe18dcdfc, - 0x8f01d6bd, 0x5dd4903b, 0x33588b7a, 0x80cca6b9, 0xee40bdf8, - 0xfe172df4, 0x909b36b5, 0x230f1b76, 0x4d830037, 0x9f5646b1, - 0xf1da5df0, 0x424e7033, 0x2cc26b72, 0x62e1502b, 0x0c6d4b6a, - 0xbff966a9, 0xd1757de8, 0x03a03b6e, 0x6d2c202f, 0xdeb80dec, - 0xb03416ad, 0xa06386a1, 0xceef9de0, 0x7d7bb023, 0x13f7ab62, - 0xc122ede4, 0xafaef6a5, 0x1c3adb66, 0x72b6c027, 0x807cadd4, - 0xeef0b695, 0x5d649b56, 0x33e88017, 0xe13dc691, 0x8fb1ddd0, - 0x3c25f013, 0x52a9eb52, 0x42fe7b5e, 0x2c72601f, 0x9fe64ddc, - 0xf16a569d, 0x23bf101b, 0x4d330b5a, 0xfea72699, 0x902b3dd8, - 0xde080681, 0xb0841dc0, 0x03103003, 0x6d9c2b42, 0xbf496dc4, - 0xd1c57685, 0x62515b46, 0x0cdd4007, 0x1c8ad00b, 0x7206cb4a, - 0xc192e689, 0xaf1efdc8, 0x7dcbbb4e, 0x1347a00f, 0xa0d38dcc, - 0xce5f968d}, - {0x00000000, 0xe71da697, 0x154a4b6f, 0xf257edf8, 0x2a9496de, - 0xcd893049, 0x3fdeddb1, 0xd8c37b26, 0x55292dbc, 0xb2348b2b, - 0x406366d3, 0xa77ec044, 0x7fbdbb62, 0x98a01df5, 0x6af7f00d, - 0x8dea569a, 0xaa525b78, 0x4d4ffdef, 0xbf181017, 0x5805b680, - 0x80c6cda6, 0x67db6b31, 0x958c86c9, 0x7291205e, 0xff7b76c4, - 0x1866d053, 0xea313dab, 0x0d2c9b3c, 0xd5efe01a, 0x32f2468d, - 0xc0a5ab75, 0x27b80de2, 0x8fd5b0b1, 0x68c81626, 0x9a9ffbde, - 0x7d825d49, 0xa541266f, 0x425c80f8, 0xb00b6d00, 0x5716cb97, - 0xdafc9d0d, 0x3de13b9a, 0xcfb6d662, 0x28ab70f5, 0xf0680bd3, - 0x1775ad44, 0xe52240bc, 0x023fe62b, 0x2587ebc9, 0xc29a4d5e, - 0x30cda0a6, 0xd7d00631, 0x0f137d17, 0xe80edb80, 0x1a593678, - 0xfd4490ef, 0x70aec675, 0x97b360e2, 0x65e48d1a, 0x82f92b8d, - 0x5a3a50ab, 0xbd27f63c, 0x4f701bc4, 0xa86dbd53, 0xc4da6723, - 0x23c7c1b4, 0xd1902c4c, 0x368d8adb, 0xee4ef1fd, 0x0953576a, - 0xfb04ba92, 0x1c191c05, 0x91f34a9f, 0x76eeec08, 0x84b901f0, - 0x63a4a767, 0xbb67dc41, 0x5c7a7ad6, 0xae2d972e, 0x493031b9, - 0x6e883c5b, 0x89959acc, 0x7bc27734, 0x9cdfd1a3, 0x441caa85, - 0xa3010c12, 0x5156e1ea, 0xb64b477d, 0x3ba111e7, 0xdcbcb770, - 0x2eeb5a88, 0xc9f6fc1f, 0x11358739, 0xf62821ae, 0x047fcc56, - 0xe3626ac1, 0x4b0fd792, 0xac127105, 0x5e459cfd, 0xb9583a6a, - 0x619b414c, 0x8686e7db, 0x74d10a23, 0x93ccacb4, 0x1e26fa2e, - 0xf93b5cb9, 0x0b6cb141, 0xec7117d6, 0x34b26cf0, 0xd3afca67, - 0x21f8279f, 0xc6e58108, 0xe15d8cea, 0x06402a7d, 0xf417c785, - 0x130a6112, 0xcbc91a34, 0x2cd4bca3, 0xde83515b, 0x399ef7cc, - 0xb474a156, 0x536907c1, 0xa13eea39, 0x46234cae, 0x9ee03788, - 0x79fd911f, 0x8baa7ce7, 0x6cb7da70, 0x52c5c807, 0xb5d86e90, - 0x478f8368, 0xa09225ff, 0x78515ed9, 0x9f4cf84e, 0x6d1b15b6, - 0x8a06b321, 0x07ece5bb, 0xe0f1432c, 0x12a6aed4, 0xf5bb0843, - 0x2d787365, 0xca65d5f2, 0x3832380a, 0xdf2f9e9d, 0xf897937f, - 0x1f8a35e8, 0xedddd810, 0x0ac07e87, 0xd20305a1, 0x351ea336, - 0xc7494ece, 0x2054e859, 0xadbebec3, 0x4aa31854, 0xb8f4f5ac, - 0x5fe9533b, 0x872a281d, 0x60378e8a, 0x92606372, 0x757dc5e5, - 0xdd1078b6, 0x3a0dde21, 0xc85a33d9, 0x2f47954e, 0xf784ee68, - 0x109948ff, 0xe2cea507, 0x05d30390, 0x8839550a, 0x6f24f39d, - 0x9d731e65, 0x7a6eb8f2, 0xa2adc3d4, 0x45b06543, 0xb7e788bb, - 0x50fa2e2c, 0x774223ce, 0x905f8559, 0x620868a1, 0x8515ce36, - 0x5dd6b510, 0xbacb1387, 0x489cfe7f, 0xaf8158e8, 0x226b0e72, - 0xc576a8e5, 0x3721451d, 0xd03ce38a, 0x08ff98ac, 0xefe23e3b, - 0x1db5d3c3, 0xfaa87554, 0x961faf24, 0x710209b3, 0x8355e44b, - 0x644842dc, 0xbc8b39fa, 0x5b969f6d, 0xa9c17295, 0x4edcd402, - 0xc3368298, 0x242b240f, 0xd67cc9f7, 0x31616f60, 0xe9a21446, - 0x0ebfb2d1, 0xfce85f29, 0x1bf5f9be, 0x3c4df45c, 0xdb5052cb, - 0x2907bf33, 0xce1a19a4, 0x16d96282, 0xf1c4c415, 0x039329ed, - 0xe48e8f7a, 0x6964d9e0, 0x8e797f77, 0x7c2e928f, 0x9b333418, - 0x43f04f3e, 0xa4ede9a9, 0x56ba0451, 0xb1a7a2c6, 0x19ca1f95, - 0xfed7b902, 0x0c8054fa, 0xeb9df26d, 0x335e894b, 0xd4432fdc, - 0x2614c224, 0xc10964b3, 0x4ce33229, 0xabfe94be, 0x59a97946, - 0xbeb4dfd1, 0x6677a4f7, 0x816a0260, 0x733def98, 0x9420490f, - 0xb39844ed, 0x5485e27a, 0xa6d20f82, 0x41cfa915, 0x990cd233, - 0x7e1174a4, 0x8c46995c, 0x6b5b3fcb, 0xe6b16951, 0x01accfc6, - 0xf3fb223e, 0x14e684a9, 0xcc25ff8f, 0x2b385918, 0xd96fb4e0, - 0x3e721277}, - {0x00000000, 0xa58b900e, 0x9066265d, 0x35edb653, 0xfbbd4afb, - 0x5e36daf5, 0x6bdb6ca6, 0xce50fca8, 0x2c0b93b7, 0x898003b9, - 0xbc6db5ea, 0x19e625e4, 0xd7b6d94c, 0x723d4942, 0x47d0ff11, - 0xe25b6f1f, 0x5817276e, 0xfd9cb760, 0xc8710133, 0x6dfa913d, - 0xa3aa6d95, 0x0621fd9b, 0x33cc4bc8, 0x9647dbc6, 0x741cb4d9, - 0xd19724d7, 0xe47a9284, 0x41f1028a, 0x8fa1fe22, 0x2a2a6e2c, - 0x1fc7d87f, 0xba4c4871, 0xb02e4edc, 0x15a5ded2, 0x20486881, - 0x85c3f88f, 0x4b930427, 0xee189429, 0xdbf5227a, 0x7e7eb274, - 0x9c25dd6b, 0x39ae4d65, 0x0c43fb36, 0xa9c86b38, 0x67989790, - 0xc213079e, 0xf7feb1cd, 0x527521c3, 0xe83969b2, 0x4db2f9bc, - 0x785f4fef, 0xddd4dfe1, 0x13842349, 0xb60fb347, 0x83e20514, - 0x2669951a, 0xc432fa05, 0x61b96a0b, 0x5454dc58, 0xf1df4c56, - 0x3f8fb0fe, 0x9a0420f0, 0xafe996a3, 0x0a6206ad, 0xbb2d9bf9, - 0x1ea60bf7, 0x2b4bbda4, 0x8ec02daa, 0x4090d102, 0xe51b410c, - 0xd0f6f75f, 0x757d6751, 0x9726084e, 0x32ad9840, 0x07402e13, - 0xa2cbbe1d, 0x6c9b42b5, 0xc910d2bb, 0xfcfd64e8, 0x5976f4e6, - 0xe33abc97, 0x46b12c99, 0x735c9aca, 0xd6d70ac4, 0x1887f66c, - 0xbd0c6662, 0x88e1d031, 0x2d6a403f, 0xcf312f20, 0x6ababf2e, - 0x5f57097d, 0xfadc9973, 0x348c65db, 0x9107f5d5, 0xa4ea4386, - 0x0161d388, 0x0b03d525, 0xae88452b, 0x9b65f378, 0x3eee6376, - 0xf0be9fde, 0x55350fd0, 0x60d8b983, 0xc553298d, 0x27084692, - 0x8283d69c, 0xb76e60cf, 0x12e5f0c1, 0xdcb50c69, 0x793e9c67, - 0x4cd32a34, 0xe958ba3a, 0x5314f24b, 0xf69f6245, 0xc372d416, - 0x66f94418, 0xa8a9b8b0, 0x0d2228be, 0x38cf9eed, 0x9d440ee3, - 0x7f1f61fc, 0xda94f1f2, 0xef7947a1, 0x4af2d7af, 0x84a22b07, - 0x2129bb09, 0x14c40d5a, 0xb14f9d54, 0xad2a31b3, 0x08a1a1bd, - 0x3d4c17ee, 0x98c787e0, 0x56977b48, 0xf31ceb46, 0xc6f15d15, - 0x637acd1b, 0x8121a204, 0x24aa320a, 0x11478459, 0xb4cc1457, - 0x7a9ce8ff, 0xdf1778f1, 0xeafacea2, 0x4f715eac, 0xf53d16dd, - 0x50b686d3, 0x655b3080, 0xc0d0a08e, 0x0e805c26, 0xab0bcc28, - 0x9ee67a7b, 0x3b6dea75, 0xd936856a, 0x7cbd1564, 0x4950a337, - 0xecdb3339, 0x228bcf91, 0x87005f9f, 0xb2ede9cc, 0x176679c2, - 0x1d047f6f, 0xb88fef61, 0x8d625932, 0x28e9c93c, 0xe6b93594, - 0x4332a59a, 0x76df13c9, 0xd35483c7, 0x310fecd8, 0x94847cd6, - 0xa169ca85, 0x04e25a8b, 0xcab2a623, 0x6f39362d, 0x5ad4807e, - 0xff5f1070, 0x45135801, 0xe098c80f, 0xd5757e5c, 0x70feee52, - 0xbeae12fa, 0x1b2582f4, 0x2ec834a7, 0x8b43a4a9, 0x6918cbb6, - 0xcc935bb8, 0xf97eedeb, 0x5cf57de5, 0x92a5814d, 0x372e1143, - 0x02c3a710, 0xa748371e, 0x1607aa4a, 0xb38c3a44, 0x86618c17, - 0x23ea1c19, 0xedbae0b1, 0x483170bf, 0x7ddcc6ec, 0xd85756e2, - 0x3a0c39fd, 0x9f87a9f3, 0xaa6a1fa0, 0x0fe18fae, 0xc1b17306, - 0x643ae308, 0x51d7555b, 0xf45cc555, 0x4e108d24, 0xeb9b1d2a, - 0xde76ab79, 0x7bfd3b77, 0xb5adc7df, 0x102657d1, 0x25cbe182, - 0x8040718c, 0x621b1e93, 0xc7908e9d, 0xf27d38ce, 0x57f6a8c0, - 0x99a65468, 0x3c2dc466, 0x09c07235, 0xac4be23b, 0xa629e496, - 0x03a27498, 0x364fc2cb, 0x93c452c5, 0x5d94ae6d, 0xf81f3e63, - 0xcdf28830, 0x6879183e, 0x8a227721, 0x2fa9e72f, 0x1a44517c, - 0xbfcfc172, 0x719f3dda, 0xd414add4, 0xe1f91b87, 0x44728b89, - 0xfe3ec3f8, 0x5bb553f6, 0x6e58e5a5, 0xcbd375ab, 0x05838903, - 0xa008190d, 0x95e5af5e, 0x306e3f50, 0xd235504f, 0x77bec041, - 0x42537612, 0xe7d8e61c, 0x29881ab4, 0x8c038aba, 0xb9ee3ce9, - 0x1c65ace7}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x0000000000000000, 0x0e908ba500000000, 0x5d26669000000000, - 0x53b6ed3500000000, 0xfb4abdfb00000000, 0xf5da365e00000000, - 0xa66cdb6b00000000, 0xa8fc50ce00000000, 0xb7930b2c00000000, - 0xb903808900000000, 0xeab56dbc00000000, 0xe425e61900000000, - 0x4cd9b6d700000000, 0x42493d7200000000, 0x11ffd04700000000, - 0x1f6f5be200000000, 0x6e27175800000000, 0x60b79cfd00000000, - 0x330171c800000000, 0x3d91fa6d00000000, 0x956daaa300000000, - 0x9bfd210600000000, 0xc84bcc3300000000, 0xc6db479600000000, - 0xd9b41c7400000000, 0xd72497d100000000, 0x84927ae400000000, - 0x8a02f14100000000, 0x22fea18f00000000, 0x2c6e2a2a00000000, - 0x7fd8c71f00000000, 0x71484cba00000000, 0xdc4e2eb000000000, - 0xd2dea51500000000, 0x8168482000000000, 0x8ff8c38500000000, - 0x2704934b00000000, 0x299418ee00000000, 0x7a22f5db00000000, - 0x74b27e7e00000000, 0x6bdd259c00000000, 0x654dae3900000000, - 0x36fb430c00000000, 0x386bc8a900000000, 0x9097986700000000, - 0x9e0713c200000000, 0xcdb1fef700000000, 0xc321755200000000, - 0xb26939e800000000, 0xbcf9b24d00000000, 0xef4f5f7800000000, - 0xe1dfd4dd00000000, 0x4923841300000000, 0x47b30fb600000000, - 0x1405e28300000000, 0x1a95692600000000, 0x05fa32c400000000, - 0x0b6ab96100000000, 0x58dc545400000000, 0x564cdff100000000, - 0xfeb08f3f00000000, 0xf020049a00000000, 0xa396e9af00000000, - 0xad06620a00000000, 0xf99b2dbb00000000, 0xf70ba61e00000000, - 0xa4bd4b2b00000000, 0xaa2dc08e00000000, 0x02d1904000000000, - 0x0c411be500000000, 0x5ff7f6d000000000, 0x51677d7500000000, - 0x4e08269700000000, 0x4098ad3200000000, 0x132e400700000000, - 0x1dbecba200000000, 0xb5429b6c00000000, 0xbbd210c900000000, - 0xe864fdfc00000000, 0xe6f4765900000000, 0x97bc3ae300000000, - 0x992cb14600000000, 0xca9a5c7300000000, 0xc40ad7d600000000, - 0x6cf6871800000000, 0x62660cbd00000000, 0x31d0e18800000000, - 0x3f406a2d00000000, 0x202f31cf00000000, 0x2ebfba6a00000000, - 0x7d09575f00000000, 0x7399dcfa00000000, 0xdb658c3400000000, - 0xd5f5079100000000, 0x8643eaa400000000, 0x88d3610100000000, - 0x25d5030b00000000, 0x2b4588ae00000000, 0x78f3659b00000000, - 0x7663ee3e00000000, 0xde9fbef000000000, 0xd00f355500000000, - 0x83b9d86000000000, 0x8d2953c500000000, 0x9246082700000000, - 0x9cd6838200000000, 0xcf606eb700000000, 0xc1f0e51200000000, - 0x690cb5dc00000000, 0x679c3e7900000000, 0x342ad34c00000000, - 0x3aba58e900000000, 0x4bf2145300000000, 0x45629ff600000000, - 0x16d472c300000000, 0x1844f96600000000, 0xb0b8a9a800000000, - 0xbe28220d00000000, 0xed9ecf3800000000, 0xe30e449d00000000, - 0xfc611f7f00000000, 0xf2f194da00000000, 0xa14779ef00000000, - 0xafd7f24a00000000, 0x072ba28400000000, 0x09bb292100000000, - 0x5a0dc41400000000, 0x549d4fb100000000, 0xb3312aad00000000, - 0xbda1a10800000000, 0xee174c3d00000000, 0xe087c79800000000, - 0x487b975600000000, 0x46eb1cf300000000, 0x155df1c600000000, - 0x1bcd7a6300000000, 0x04a2218100000000, 0x0a32aa2400000000, - 0x5984471100000000, 0x5714ccb400000000, 0xffe89c7a00000000, - 0xf17817df00000000, 0xa2cefaea00000000, 0xac5e714f00000000, - 0xdd163df500000000, 0xd386b65000000000, 0x80305b6500000000, - 0x8ea0d0c000000000, 0x265c800e00000000, 0x28cc0bab00000000, - 0x7b7ae69e00000000, 0x75ea6d3b00000000, 0x6a8536d900000000, - 0x6415bd7c00000000, 0x37a3504900000000, 0x3933dbec00000000, - 0x91cf8b2200000000, 0x9f5f008700000000, 0xcce9edb200000000, - 0xc279661700000000, 0x6f7f041d00000000, 0x61ef8fb800000000, - 0x3259628d00000000, 0x3cc9e92800000000, 0x9435b9e600000000, - 0x9aa5324300000000, 0xc913df7600000000, 0xc78354d300000000, - 0xd8ec0f3100000000, 0xd67c849400000000, 0x85ca69a100000000, - 0x8b5ae20400000000, 0x23a6b2ca00000000, 0x2d36396f00000000, - 0x7e80d45a00000000, 0x70105fff00000000, 0x0158134500000000, - 0x0fc898e000000000, 0x5c7e75d500000000, 0x52eefe7000000000, - 0xfa12aebe00000000, 0xf482251b00000000, 0xa734c82e00000000, - 0xa9a4438b00000000, 0xb6cb186900000000, 0xb85b93cc00000000, - 0xebed7ef900000000, 0xe57df55c00000000, 0x4d81a59200000000, - 0x43112e3700000000, 0x10a7c30200000000, 0x1e3748a700000000, - 0x4aaa071600000000, 0x443a8cb300000000, 0x178c618600000000, - 0x191cea2300000000, 0xb1e0baed00000000, 0xbf70314800000000, - 0xecc6dc7d00000000, 0xe25657d800000000, 0xfd390c3a00000000, - 0xf3a9879f00000000, 0xa01f6aaa00000000, 0xae8fe10f00000000, - 0x0673b1c100000000, 0x08e33a6400000000, 0x5b55d75100000000, - 0x55c55cf400000000, 0x248d104e00000000, 0x2a1d9beb00000000, - 0x79ab76de00000000, 0x773bfd7b00000000, 0xdfc7adb500000000, - 0xd157261000000000, 0x82e1cb2500000000, 0x8c71408000000000, - 0x931e1b6200000000, 0x9d8e90c700000000, 0xce387df200000000, - 0xc0a8f65700000000, 0x6854a69900000000, 0x66c42d3c00000000, - 0x3572c00900000000, 0x3be24bac00000000, 0x96e429a600000000, - 0x9874a20300000000, 0xcbc24f3600000000, 0xc552c49300000000, - 0x6dae945d00000000, 0x633e1ff800000000, 0x3088f2cd00000000, - 0x3e18796800000000, 0x2177228a00000000, 0x2fe7a92f00000000, - 0x7c51441a00000000, 0x72c1cfbf00000000, 0xda3d9f7100000000, - 0xd4ad14d400000000, 0x871bf9e100000000, 0x898b724400000000, - 0xf8c33efe00000000, 0xf653b55b00000000, 0xa5e5586e00000000, - 0xab75d3cb00000000, 0x0389830500000000, 0x0d1908a000000000, - 0x5eafe59500000000, 0x503f6e3000000000, 0x4f5035d200000000, - 0x41c0be7700000000, 0x1276534200000000, 0x1ce6d8e700000000, - 0xb41a882900000000, 0xba8a038c00000000, 0xe93ceeb900000000, - 0xe7ac651c00000000}, - {0x0000000000000000, 0x97a61de700000000, 0x6f4b4a1500000000, - 0xf8ed57f200000000, 0xde96942a00000000, 0x493089cd00000000, - 0xb1ddde3f00000000, 0x267bc3d800000000, 0xbc2d295500000000, - 0x2b8b34b200000000, 0xd366634000000000, 0x44c07ea700000000, - 0x62bbbd7f00000000, 0xf51da09800000000, 0x0df0f76a00000000, - 0x9a56ea8d00000000, 0x785b52aa00000000, 0xeffd4f4d00000000, - 0x171018bf00000000, 0x80b6055800000000, 0xa6cdc68000000000, - 0x316bdb6700000000, 0xc9868c9500000000, 0x5e20917200000000, - 0xc4767bff00000000, 0x53d0661800000000, 0xab3d31ea00000000, - 0x3c9b2c0d00000000, 0x1ae0efd500000000, 0x8d46f23200000000, - 0x75aba5c000000000, 0xe20db82700000000, 0xb1b0d58f00000000, - 0x2616c86800000000, 0xdefb9f9a00000000, 0x495d827d00000000, - 0x6f2641a500000000, 0xf8805c4200000000, 0x006d0bb000000000, - 0x97cb165700000000, 0x0d9dfcda00000000, 0x9a3be13d00000000, - 0x62d6b6cf00000000, 0xf570ab2800000000, 0xd30b68f000000000, - 0x44ad751700000000, 0xbc4022e500000000, 0x2be63f0200000000, - 0xc9eb872500000000, 0x5e4d9ac200000000, 0xa6a0cd3000000000, - 0x3106d0d700000000, 0x177d130f00000000, 0x80db0ee800000000, - 0x7836591a00000000, 0xef9044fd00000000, 0x75c6ae7000000000, - 0xe260b39700000000, 0x1a8de46500000000, 0x8d2bf98200000000, - 0xab503a5a00000000, 0x3cf627bd00000000, 0xc41b704f00000000, - 0x53bd6da800000000, 0x2367dac400000000, 0xb4c1c72300000000, - 0x4c2c90d100000000, 0xdb8a8d3600000000, 0xfdf14eee00000000, - 0x6a57530900000000, 0x92ba04fb00000000, 0x051c191c00000000, - 0x9f4af39100000000, 0x08ecee7600000000, 0xf001b98400000000, - 0x67a7a46300000000, 0x41dc67bb00000000, 0xd67a7a5c00000000, - 0x2e972dae00000000, 0xb931304900000000, 0x5b3c886e00000000, - 0xcc9a958900000000, 0x3477c27b00000000, 0xa3d1df9c00000000, - 0x85aa1c4400000000, 0x120c01a300000000, 0xeae1565100000000, - 0x7d474bb600000000, 0xe711a13b00000000, 0x70b7bcdc00000000, - 0x885aeb2e00000000, 0x1ffcf6c900000000, 0x3987351100000000, - 0xae2128f600000000, 0x56cc7f0400000000, 0xc16a62e300000000, - 0x92d70f4b00000000, 0x057112ac00000000, 0xfd9c455e00000000, - 0x6a3a58b900000000, 0x4c419b6100000000, 0xdbe7868600000000, - 0x230ad17400000000, 0xb4accc9300000000, 0x2efa261e00000000, - 0xb95c3bf900000000, 0x41b16c0b00000000, 0xd61771ec00000000, - 0xf06cb23400000000, 0x67caafd300000000, 0x9f27f82100000000, - 0x0881e5c600000000, 0xea8c5de100000000, 0x7d2a400600000000, - 0x85c717f400000000, 0x12610a1300000000, 0x341ac9cb00000000, - 0xa3bcd42c00000000, 0x5b5183de00000000, 0xccf79e3900000000, - 0x56a174b400000000, 0xc107695300000000, 0x39ea3ea100000000, - 0xae4c234600000000, 0x8837e09e00000000, 0x1f91fd7900000000, - 0xe77caa8b00000000, 0x70dab76c00000000, 0x07c8c55200000000, - 0x906ed8b500000000, 0x68838f4700000000, 0xff2592a000000000, - 0xd95e517800000000, 0x4ef84c9f00000000, 0xb6151b6d00000000, - 0x21b3068a00000000, 0xbbe5ec0700000000, 0x2c43f1e000000000, - 0xd4aea61200000000, 0x4308bbf500000000, 0x6573782d00000000, - 0xf2d565ca00000000, 0x0a38323800000000, 0x9d9e2fdf00000000, - 0x7f9397f800000000, 0xe8358a1f00000000, 0x10d8dded00000000, - 0x877ec00a00000000, 0xa10503d200000000, 0x36a31e3500000000, - 0xce4e49c700000000, 0x59e8542000000000, 0xc3bebead00000000, - 0x5418a34a00000000, 0xacf5f4b800000000, 0x3b53e95f00000000, - 0x1d282a8700000000, 0x8a8e376000000000, 0x7263609200000000, - 0xe5c57d7500000000, 0xb67810dd00000000, 0x21de0d3a00000000, - 0xd9335ac800000000, 0x4e95472f00000000, 0x68ee84f700000000, - 0xff48991000000000, 0x07a5cee200000000, 0x9003d30500000000, - 0x0a55398800000000, 0x9df3246f00000000, 0x651e739d00000000, - 0xf2b86e7a00000000, 0xd4c3ada200000000, 0x4365b04500000000, - 0xbb88e7b700000000, 0x2c2efa5000000000, 0xce23427700000000, - 0x59855f9000000000, 0xa168086200000000, 0x36ce158500000000, - 0x10b5d65d00000000, 0x8713cbba00000000, 0x7ffe9c4800000000, - 0xe85881af00000000, 0x720e6b2200000000, 0xe5a876c500000000, - 0x1d45213700000000, 0x8ae33cd000000000, 0xac98ff0800000000, - 0x3b3ee2ef00000000, 0xc3d3b51d00000000, 0x5475a8fa00000000, - 0x24af1f9600000000, 0xb309027100000000, 0x4be4558300000000, - 0xdc42486400000000, 0xfa398bbc00000000, 0x6d9f965b00000000, - 0x9572c1a900000000, 0x02d4dc4e00000000, 0x988236c300000000, - 0x0f242b2400000000, 0xf7c97cd600000000, 0x606f613100000000, - 0x4614a2e900000000, 0xd1b2bf0e00000000, 0x295fe8fc00000000, - 0xbef9f51b00000000, 0x5cf44d3c00000000, 0xcb5250db00000000, - 0x33bf072900000000, 0xa4191ace00000000, 0x8262d91600000000, - 0x15c4c4f100000000, 0xed29930300000000, 0x7a8f8ee400000000, - 0xe0d9646900000000, 0x777f798e00000000, 0x8f922e7c00000000, - 0x1834339b00000000, 0x3e4ff04300000000, 0xa9e9eda400000000, - 0x5104ba5600000000, 0xc6a2a7b100000000, 0x951fca1900000000, - 0x02b9d7fe00000000, 0xfa54800c00000000, 0x6df29deb00000000, - 0x4b895e3300000000, 0xdc2f43d400000000, 0x24c2142600000000, - 0xb36409c100000000, 0x2932e34c00000000, 0xbe94feab00000000, - 0x4679a95900000000, 0xd1dfb4be00000000, 0xf7a4776600000000, - 0x60026a8100000000, 0x98ef3d7300000000, 0x0f49209400000000, - 0xed4498b300000000, 0x7ae2855400000000, 0x820fd2a600000000, - 0x15a9cf4100000000, 0x33d20c9900000000, 0xa474117e00000000, - 0x5c99468c00000000, 0xcb3f5b6b00000000, 0x5169b1e600000000, - 0xc6cfac0100000000, 0x3e22fbf300000000, 0xa984e61400000000, - 0x8fff25cc00000000, 0x1859382b00000000, 0xe0b46fd900000000, - 0x7712723e00000000}, - {0x0000000000000000, 0x411b8c6e00000000, 0x823618dd00000000, - 0xc32d94b300000000, 0x456b416100000000, 0x0470cd0f00000000, - 0xc75d59bc00000000, 0x8646d5d200000000, 0x8ad682c200000000, - 0xcbcd0eac00000000, 0x08e09a1f00000000, 0x49fb167100000000, - 0xcfbdc3a300000000, 0x8ea64fcd00000000, 0x4d8bdb7e00000000, - 0x0c90571000000000, 0x55ab745e00000000, 0x14b0f83000000000, - 0xd79d6c8300000000, 0x9686e0ed00000000, 0x10c0353f00000000, - 0x51dbb95100000000, 0x92f62de200000000, 0xd3eda18c00000000, - 0xdf7df69c00000000, 0x9e667af200000000, 0x5d4bee4100000000, - 0x1c50622f00000000, 0x9a16b7fd00000000, 0xdb0d3b9300000000, - 0x1820af2000000000, 0x593b234e00000000, 0xaa56e9bc00000000, - 0xeb4d65d200000000, 0x2860f16100000000, 0x697b7d0f00000000, - 0xef3da8dd00000000, 0xae2624b300000000, 0x6d0bb00000000000, - 0x2c103c6e00000000, 0x20806b7e00000000, 0x619be71000000000, - 0xa2b673a300000000, 0xe3adffcd00000000, 0x65eb2a1f00000000, - 0x24f0a67100000000, 0xe7dd32c200000000, 0xa6c6beac00000000, - 0xfffd9de200000000, 0xbee6118c00000000, 0x7dcb853f00000000, - 0x3cd0095100000000, 0xba96dc8300000000, 0xfb8d50ed00000000, - 0x38a0c45e00000000, 0x79bb483000000000, 0x752b1f2000000000, - 0x3430934e00000000, 0xf71d07fd00000000, 0xb6068b9300000000, - 0x30405e4100000000, 0x715bd22f00000000, 0xb276469c00000000, - 0xf36dcaf200000000, 0x15aba3a200000000, 0x54b02fcc00000000, - 0x979dbb7f00000000, 0xd686371100000000, 0x50c0e2c300000000, - 0x11db6ead00000000, 0xd2f6fa1e00000000, 0x93ed767000000000, - 0x9f7d216000000000, 0xde66ad0e00000000, 0x1d4b39bd00000000, - 0x5c50b5d300000000, 0xda16600100000000, 0x9b0dec6f00000000, - 0x582078dc00000000, 0x193bf4b200000000, 0x4000d7fc00000000, - 0x011b5b9200000000, 0xc236cf2100000000, 0x832d434f00000000, - 0x056b969d00000000, 0x44701af300000000, 0x875d8e4000000000, - 0xc646022e00000000, 0xcad6553e00000000, 0x8bcdd95000000000, - 0x48e04de300000000, 0x09fbc18d00000000, 0x8fbd145f00000000, - 0xcea6983100000000, 0x0d8b0c8200000000, 0x4c9080ec00000000, - 0xbffd4a1e00000000, 0xfee6c67000000000, 0x3dcb52c300000000, - 0x7cd0dead00000000, 0xfa960b7f00000000, 0xbb8d871100000000, - 0x78a013a200000000, 0x39bb9fcc00000000, 0x352bc8dc00000000, - 0x743044b200000000, 0xb71dd00100000000, 0xf6065c6f00000000, - 0x704089bd00000000, 0x315b05d300000000, 0xf276916000000000, - 0xb36d1d0e00000000, 0xea563e4000000000, 0xab4db22e00000000, - 0x6860269d00000000, 0x297baaf300000000, 0xaf3d7f2100000000, - 0xee26f34f00000000, 0x2d0b67fc00000000, 0x6c10eb9200000000, - 0x6080bc8200000000, 0x219b30ec00000000, 0xe2b6a45f00000000, - 0xa3ad283100000000, 0x25ebfde300000000, 0x64f0718d00000000, - 0xa7dde53e00000000, 0xe6c6695000000000, 0x6b50369e00000000, - 0x2a4bbaf000000000, 0xe9662e4300000000, 0xa87da22d00000000, - 0x2e3b77ff00000000, 0x6f20fb9100000000, 0xac0d6f2200000000, - 0xed16e34c00000000, 0xe186b45c00000000, 0xa09d383200000000, - 0x63b0ac8100000000, 0x22ab20ef00000000, 0xa4edf53d00000000, - 0xe5f6795300000000, 0x26dbede000000000, 0x67c0618e00000000, - 0x3efb42c000000000, 0x7fe0ceae00000000, 0xbccd5a1d00000000, - 0xfdd6d67300000000, 0x7b9003a100000000, 0x3a8b8fcf00000000, - 0xf9a61b7c00000000, 0xb8bd971200000000, 0xb42dc00200000000, - 0xf5364c6c00000000, 0x361bd8df00000000, 0x770054b100000000, - 0xf146816300000000, 0xb05d0d0d00000000, 0x737099be00000000, - 0x326b15d000000000, 0xc106df2200000000, 0x801d534c00000000, - 0x4330c7ff00000000, 0x022b4b9100000000, 0x846d9e4300000000, - 0xc576122d00000000, 0x065b869e00000000, 0x47400af000000000, - 0x4bd05de000000000, 0x0acbd18e00000000, 0xc9e6453d00000000, - 0x88fdc95300000000, 0x0ebb1c8100000000, 0x4fa090ef00000000, - 0x8c8d045c00000000, 0xcd96883200000000, 0x94adab7c00000000, - 0xd5b6271200000000, 0x169bb3a100000000, 0x57803fcf00000000, - 0xd1c6ea1d00000000, 0x90dd667300000000, 0x53f0f2c000000000, - 0x12eb7eae00000000, 0x1e7b29be00000000, 0x5f60a5d000000000, - 0x9c4d316300000000, 0xdd56bd0d00000000, 0x5b1068df00000000, - 0x1a0be4b100000000, 0xd926700200000000, 0x983dfc6c00000000, - 0x7efb953c00000000, 0x3fe0195200000000, 0xfccd8de100000000, - 0xbdd6018f00000000, 0x3b90d45d00000000, 0x7a8b583300000000, - 0xb9a6cc8000000000, 0xf8bd40ee00000000, 0xf42d17fe00000000, - 0xb5369b9000000000, 0x761b0f2300000000, 0x3700834d00000000, - 0xb146569f00000000, 0xf05ddaf100000000, 0x33704e4200000000, - 0x726bc22c00000000, 0x2b50e16200000000, 0x6a4b6d0c00000000, - 0xa966f9bf00000000, 0xe87d75d100000000, 0x6e3ba00300000000, - 0x2f202c6d00000000, 0xec0db8de00000000, 0xad1634b000000000, - 0xa18663a000000000, 0xe09defce00000000, 0x23b07b7d00000000, - 0x62abf71300000000, 0xe4ed22c100000000, 0xa5f6aeaf00000000, - 0x66db3a1c00000000, 0x27c0b67200000000, 0xd4ad7c8000000000, - 0x95b6f0ee00000000, 0x569b645d00000000, 0x1780e83300000000, - 0x91c63de100000000, 0xd0ddb18f00000000, 0x13f0253c00000000, - 0x52eba95200000000, 0x5e7bfe4200000000, 0x1f60722c00000000, - 0xdc4de69f00000000, 0x9d566af100000000, 0x1b10bf2300000000, - 0x5a0b334d00000000, 0x9926a7fe00000000, 0xd83d2b9000000000, - 0x810608de00000000, 0xc01d84b000000000, 0x0330100300000000, - 0x422b9c6d00000000, 0xc46d49bf00000000, 0x8576c5d100000000, - 0x465b516200000000, 0x0740dd0c00000000, 0x0bd08a1c00000000, - 0x4acb067200000000, 0x89e692c100000000, 0xc8fd1eaf00000000, - 0x4ebbcb7d00000000, 0x0fa0471300000000, 0xcc8dd3a000000000, - 0x8d965fce00000000}, - {0x0000000000000000, 0x1dfdb50100000000, 0x3afa6b0300000000, - 0x2707de0200000000, 0x74f4d70600000000, 0x6909620700000000, - 0x4e0ebc0500000000, 0x53f3090400000000, 0xe8e8af0d00000000, - 0xf5151a0c00000000, 0xd212c40e00000000, 0xcfef710f00000000, - 0x9c1c780b00000000, 0x81e1cd0a00000000, 0xa6e6130800000000, - 0xbb1ba60900000000, 0xd0d15f1b00000000, 0xcd2cea1a00000000, - 0xea2b341800000000, 0xf7d6811900000000, 0xa425881d00000000, - 0xb9d83d1c00000000, 0x9edfe31e00000000, 0x8322561f00000000, - 0x3839f01600000000, 0x25c4451700000000, 0x02c39b1500000000, - 0x1f3e2e1400000000, 0x4ccd271000000000, 0x5130921100000000, - 0x76374c1300000000, 0x6bcaf91200000000, 0xa0a3bf3600000000, - 0xbd5e0a3700000000, 0x9a59d43500000000, 0x87a4613400000000, - 0xd457683000000000, 0xc9aadd3100000000, 0xeead033300000000, - 0xf350b63200000000, 0x484b103b00000000, 0x55b6a53a00000000, - 0x72b17b3800000000, 0x6f4cce3900000000, 0x3cbfc73d00000000, - 0x2142723c00000000, 0x0645ac3e00000000, 0x1bb8193f00000000, - 0x7072e02d00000000, 0x6d8f552c00000000, 0x4a888b2e00000000, - 0x57753e2f00000000, 0x0486372b00000000, 0x197b822a00000000, - 0x3e7c5c2800000000, 0x2381e92900000000, 0x989a4f2000000000, - 0x8567fa2100000000, 0xa260242300000000, 0xbf9d912200000000, - 0xec6e982600000000, 0xf1932d2700000000, 0xd694f32500000000, - 0xcb69462400000000, 0x40477f6d00000000, 0x5dbaca6c00000000, - 0x7abd146e00000000, 0x6740a16f00000000, 0x34b3a86b00000000, - 0x294e1d6a00000000, 0x0e49c36800000000, 0x13b4766900000000, - 0xa8afd06000000000, 0xb552656100000000, 0x9255bb6300000000, - 0x8fa80e6200000000, 0xdc5b076600000000, 0xc1a6b26700000000, - 0xe6a16c6500000000, 0xfb5cd96400000000, 0x9096207600000000, - 0x8d6b957700000000, 0xaa6c4b7500000000, 0xb791fe7400000000, - 0xe462f77000000000, 0xf99f427100000000, 0xde989c7300000000, - 0xc365297200000000, 0x787e8f7b00000000, 0x65833a7a00000000, - 0x4284e47800000000, 0x5f79517900000000, 0x0c8a587d00000000, - 0x1177ed7c00000000, 0x3670337e00000000, 0x2b8d867f00000000, - 0xe0e4c05b00000000, 0xfd19755a00000000, 0xda1eab5800000000, - 0xc7e31e5900000000, 0x9410175d00000000, 0x89eda25c00000000, - 0xaeea7c5e00000000, 0xb317c95f00000000, 0x080c6f5600000000, - 0x15f1da5700000000, 0x32f6045500000000, 0x2f0bb15400000000, - 0x7cf8b85000000000, 0x61050d5100000000, 0x4602d35300000000, - 0x5bff665200000000, 0x30359f4000000000, 0x2dc82a4100000000, - 0x0acff44300000000, 0x1732414200000000, 0x44c1484600000000, - 0x593cfd4700000000, 0x7e3b234500000000, 0x63c6964400000000, - 0xd8dd304d00000000, 0xc520854c00000000, 0xe2275b4e00000000, - 0xffdaee4f00000000, 0xac29e74b00000000, 0xb1d4524a00000000, - 0x96d38c4800000000, 0x8b2e394900000000, 0x808efeda00000000, - 0x9d734bdb00000000, 0xba7495d900000000, 0xa78920d800000000, - 0xf47a29dc00000000, 0xe9879cdd00000000, 0xce8042df00000000, - 0xd37df7de00000000, 0x686651d700000000, 0x759be4d600000000, - 0x529c3ad400000000, 0x4f618fd500000000, 0x1c9286d100000000, - 0x016f33d000000000, 0x2668edd200000000, 0x3b9558d300000000, - 0x505fa1c100000000, 0x4da214c000000000, 0x6aa5cac200000000, - 0x77587fc300000000, 0x24ab76c700000000, 0x3956c3c600000000, - 0x1e511dc400000000, 0x03aca8c500000000, 0xb8b70ecc00000000, - 0xa54abbcd00000000, 0x824d65cf00000000, 0x9fb0d0ce00000000, - 0xcc43d9ca00000000, 0xd1be6ccb00000000, 0xf6b9b2c900000000, - 0xeb4407c800000000, 0x202d41ec00000000, 0x3dd0f4ed00000000, - 0x1ad72aef00000000, 0x072a9fee00000000, 0x54d996ea00000000, - 0x492423eb00000000, 0x6e23fde900000000, 0x73de48e800000000, - 0xc8c5eee100000000, 0xd5385be000000000, 0xf23f85e200000000, - 0xefc230e300000000, 0xbc3139e700000000, 0xa1cc8ce600000000, - 0x86cb52e400000000, 0x9b36e7e500000000, 0xf0fc1ef700000000, - 0xed01abf600000000, 0xca0675f400000000, 0xd7fbc0f500000000, - 0x8408c9f100000000, 0x99f57cf000000000, 0xbef2a2f200000000, - 0xa30f17f300000000, 0x1814b1fa00000000, 0x05e904fb00000000, - 0x22eedaf900000000, 0x3f136ff800000000, 0x6ce066fc00000000, - 0x711dd3fd00000000, 0x561a0dff00000000, 0x4be7b8fe00000000, - 0xc0c981b700000000, 0xdd3434b600000000, 0xfa33eab400000000, - 0xe7ce5fb500000000, 0xb43d56b100000000, 0xa9c0e3b000000000, - 0x8ec73db200000000, 0x933a88b300000000, 0x28212eba00000000, - 0x35dc9bbb00000000, 0x12db45b900000000, 0x0f26f0b800000000, - 0x5cd5f9bc00000000, 0x41284cbd00000000, 0x662f92bf00000000, - 0x7bd227be00000000, 0x1018deac00000000, 0x0de56bad00000000, - 0x2ae2b5af00000000, 0x371f00ae00000000, 0x64ec09aa00000000, - 0x7911bcab00000000, 0x5e1662a900000000, 0x43ebd7a800000000, - 0xf8f071a100000000, 0xe50dc4a000000000, 0xc20a1aa200000000, - 0xdff7afa300000000, 0x8c04a6a700000000, 0x91f913a600000000, - 0xb6fecda400000000, 0xab0378a500000000, 0x606a3e8100000000, - 0x7d978b8000000000, 0x5a90558200000000, 0x476de08300000000, - 0x149ee98700000000, 0x09635c8600000000, 0x2e64828400000000, - 0x3399378500000000, 0x8882918c00000000, 0x957f248d00000000, - 0xb278fa8f00000000, 0xaf854f8e00000000, 0xfc76468a00000000, - 0xe18bf38b00000000, 0xc68c2d8900000000, 0xdb71988800000000, - 0xb0bb619a00000000, 0xad46d49b00000000, 0x8a410a9900000000, - 0x97bcbf9800000000, 0xc44fb69c00000000, 0xd9b2039d00000000, - 0xfeb5dd9f00000000, 0xe348689e00000000, 0x5853ce9700000000, - 0x45ae7b9600000000, 0x62a9a59400000000, 0x7f54109500000000, - 0x2ca7199100000000, 0x315aac9000000000, 0x165d729200000000, - 0x0ba0c79300000000}, - {0x0000000000000000, 0x24d9076300000000, 0x48b20fc600000000, - 0x6c6b08a500000000, 0xd1626e5700000000, 0xf5bb693400000000, - 0x99d0619100000000, 0xbd0966f200000000, 0xa2c5dcae00000000, - 0x861cdbcd00000000, 0xea77d36800000000, 0xceaed40b00000000, - 0x73a7b2f900000000, 0x577eb59a00000000, 0x3b15bd3f00000000, - 0x1fccba5c00000000, 0x058dc88600000000, 0x2154cfe500000000, - 0x4d3fc74000000000, 0x69e6c02300000000, 0xd4efa6d100000000, - 0xf036a1b200000000, 0x9c5da91700000000, 0xb884ae7400000000, - 0xa748142800000000, 0x8391134b00000000, 0xeffa1bee00000000, - 0xcb231c8d00000000, 0x762a7a7f00000000, 0x52f37d1c00000000, - 0x3e9875b900000000, 0x1a4172da00000000, 0x4b1ce0d600000000, - 0x6fc5e7b500000000, 0x03aeef1000000000, 0x2777e87300000000, - 0x9a7e8e8100000000, 0xbea789e200000000, 0xd2cc814700000000, - 0xf615862400000000, 0xe9d93c7800000000, 0xcd003b1b00000000, - 0xa16b33be00000000, 0x85b234dd00000000, 0x38bb522f00000000, - 0x1c62554c00000000, 0x70095de900000000, 0x54d05a8a00000000, - 0x4e91285000000000, 0x6a482f3300000000, 0x0623279600000000, - 0x22fa20f500000000, 0x9ff3460700000000, 0xbb2a416400000000, - 0xd74149c100000000, 0xf3984ea200000000, 0xec54f4fe00000000, - 0xc88df39d00000000, 0xa4e6fb3800000000, 0x803ffc5b00000000, - 0x3d369aa900000000, 0x19ef9dca00000000, 0x7584956f00000000, - 0x515d920c00000000, 0xd73eb17600000000, 0xf3e7b61500000000, - 0x9f8cbeb000000000, 0xbb55b9d300000000, 0x065cdf2100000000, - 0x2285d84200000000, 0x4eeed0e700000000, 0x6a37d78400000000, - 0x75fb6dd800000000, 0x51226abb00000000, 0x3d49621e00000000, - 0x1990657d00000000, 0xa499038f00000000, 0x804004ec00000000, - 0xec2b0c4900000000, 0xc8f20b2a00000000, 0xd2b379f000000000, - 0xf66a7e9300000000, 0x9a01763600000000, 0xbed8715500000000, - 0x03d117a700000000, 0x270810c400000000, 0x4b63186100000000, - 0x6fba1f0200000000, 0x7076a55e00000000, 0x54afa23d00000000, - 0x38c4aa9800000000, 0x1c1dadfb00000000, 0xa114cb0900000000, - 0x85cdcc6a00000000, 0xe9a6c4cf00000000, 0xcd7fc3ac00000000, - 0x9c2251a000000000, 0xb8fb56c300000000, 0xd4905e6600000000, - 0xf049590500000000, 0x4d403ff700000000, 0x6999389400000000, - 0x05f2303100000000, 0x212b375200000000, 0x3ee78d0e00000000, - 0x1a3e8a6d00000000, 0x765582c800000000, 0x528c85ab00000000, - 0xef85e35900000000, 0xcb5ce43a00000000, 0xa737ec9f00000000, - 0x83eeebfc00000000, 0x99af992600000000, 0xbd769e4500000000, - 0xd11d96e000000000, 0xf5c4918300000000, 0x48cdf77100000000, - 0x6c14f01200000000, 0x007ff8b700000000, 0x24a6ffd400000000, - 0x3b6a458800000000, 0x1fb342eb00000000, 0x73d84a4e00000000, - 0x57014d2d00000000, 0xea082bdf00000000, 0xced12cbc00000000, - 0xa2ba241900000000, 0x8663237a00000000, 0xae7d62ed00000000, - 0x8aa4658e00000000, 0xe6cf6d2b00000000, 0xc2166a4800000000, - 0x7f1f0cba00000000, 0x5bc60bd900000000, 0x37ad037c00000000, - 0x1374041f00000000, 0x0cb8be4300000000, 0x2861b92000000000, - 0x440ab18500000000, 0x60d3b6e600000000, 0xdddad01400000000, - 0xf903d77700000000, 0x9568dfd200000000, 0xb1b1d8b100000000, - 0xabf0aa6b00000000, 0x8f29ad0800000000, 0xe342a5ad00000000, - 0xc79ba2ce00000000, 0x7a92c43c00000000, 0x5e4bc35f00000000, - 0x3220cbfa00000000, 0x16f9cc9900000000, 0x093576c500000000, - 0x2dec71a600000000, 0x4187790300000000, 0x655e7e6000000000, - 0xd857189200000000, 0xfc8e1ff100000000, 0x90e5175400000000, - 0xb43c103700000000, 0xe561823b00000000, 0xc1b8855800000000, - 0xadd38dfd00000000, 0x890a8a9e00000000, 0x3403ec6c00000000, - 0x10daeb0f00000000, 0x7cb1e3aa00000000, 0x5868e4c900000000, - 0x47a45e9500000000, 0x637d59f600000000, 0x0f16515300000000, - 0x2bcf563000000000, 0x96c630c200000000, 0xb21f37a100000000, - 0xde743f0400000000, 0xfaad386700000000, 0xe0ec4abd00000000, - 0xc4354dde00000000, 0xa85e457b00000000, 0x8c87421800000000, - 0x318e24ea00000000, 0x1557238900000000, 0x793c2b2c00000000, - 0x5de52c4f00000000, 0x4229961300000000, 0x66f0917000000000, - 0x0a9b99d500000000, 0x2e429eb600000000, 0x934bf84400000000, - 0xb792ff2700000000, 0xdbf9f78200000000, 0xff20f0e100000000, - 0x7943d39b00000000, 0x5d9ad4f800000000, 0x31f1dc5d00000000, - 0x1528db3e00000000, 0xa821bdcc00000000, 0x8cf8baaf00000000, - 0xe093b20a00000000, 0xc44ab56900000000, 0xdb860f3500000000, - 0xff5f085600000000, 0x933400f300000000, 0xb7ed079000000000, - 0x0ae4616200000000, 0x2e3d660100000000, 0x42566ea400000000, - 0x668f69c700000000, 0x7cce1b1d00000000, 0x58171c7e00000000, - 0x347c14db00000000, 0x10a513b800000000, 0xadac754a00000000, - 0x8975722900000000, 0xe51e7a8c00000000, 0xc1c77def00000000, - 0xde0bc7b300000000, 0xfad2c0d000000000, 0x96b9c87500000000, - 0xb260cf1600000000, 0x0f69a9e400000000, 0x2bb0ae8700000000, - 0x47dba62200000000, 0x6302a14100000000, 0x325f334d00000000, - 0x1686342e00000000, 0x7aed3c8b00000000, 0x5e343be800000000, - 0xe33d5d1a00000000, 0xc7e45a7900000000, 0xab8f52dc00000000, - 0x8f5655bf00000000, 0x909aefe300000000, 0xb443e88000000000, - 0xd828e02500000000, 0xfcf1e74600000000, 0x41f881b400000000, - 0x652186d700000000, 0x094a8e7200000000, 0x2d93891100000000, - 0x37d2fbcb00000000, 0x130bfca800000000, 0x7f60f40d00000000, - 0x5bb9f36e00000000, 0xe6b0959c00000000, 0xc26992ff00000000, - 0xae029a5a00000000, 0x8adb9d3900000000, 0x9517276500000000, - 0xb1ce200600000000, 0xdda528a300000000, 0xf97c2fc000000000, - 0x4475493200000000, 0x60ac4e5100000000, 0x0cc746f400000000, - 0x281e419700000000}, - {0x0000000000000000, 0x08e3603c00000000, 0x10c6c17800000000, - 0x1825a14400000000, 0x208c83f100000000, 0x286fe3cd00000000, - 0x304a428900000000, 0x38a922b500000000, 0x011e763800000000, - 0x09fd160400000000, 0x11d8b74000000000, 0x193bd77c00000000, - 0x2192f5c900000000, 0x297195f500000000, 0x315434b100000000, - 0x39b7548d00000000, 0x023cec7000000000, 0x0adf8c4c00000000, - 0x12fa2d0800000000, 0x1a194d3400000000, 0x22b06f8100000000, - 0x2a530fbd00000000, 0x3276aef900000000, 0x3a95cec500000000, - 0x03229a4800000000, 0x0bc1fa7400000000, 0x13e45b3000000000, - 0x1b073b0c00000000, 0x23ae19b900000000, 0x2b4d798500000000, - 0x3368d8c100000000, 0x3b8bb8fd00000000, 0x0478d8e100000000, - 0x0c9bb8dd00000000, 0x14be199900000000, 0x1c5d79a500000000, - 0x24f45b1000000000, 0x2c173b2c00000000, 0x34329a6800000000, - 0x3cd1fa5400000000, 0x0566aed900000000, 0x0d85cee500000000, - 0x15a06fa100000000, 0x1d430f9d00000000, 0x25ea2d2800000000, - 0x2d094d1400000000, 0x352cec5000000000, 0x3dcf8c6c00000000, - 0x0644349100000000, 0x0ea754ad00000000, 0x1682f5e900000000, - 0x1e6195d500000000, 0x26c8b76000000000, 0x2e2bd75c00000000, - 0x360e761800000000, 0x3eed162400000000, 0x075a42a900000000, - 0x0fb9229500000000, 0x179c83d100000000, 0x1f7fe3ed00000000, - 0x27d6c15800000000, 0x2f35a16400000000, 0x3710002000000000, - 0x3ff3601c00000000, 0x49f6c11800000000, 0x4115a12400000000, - 0x5930006000000000, 0x51d3605c00000000, 0x697a42e900000000, - 0x619922d500000000, 0x79bc839100000000, 0x715fe3ad00000000, - 0x48e8b72000000000, 0x400bd71c00000000, 0x582e765800000000, - 0x50cd166400000000, 0x686434d100000000, 0x608754ed00000000, - 0x78a2f5a900000000, 0x7041959500000000, 0x4bca2d6800000000, - 0x43294d5400000000, 0x5b0cec1000000000, 0x53ef8c2c00000000, - 0x6b46ae9900000000, 0x63a5cea500000000, 0x7b806fe100000000, - 0x73630fdd00000000, 0x4ad45b5000000000, 0x42373b6c00000000, - 0x5a129a2800000000, 0x52f1fa1400000000, 0x6a58d8a100000000, - 0x62bbb89d00000000, 0x7a9e19d900000000, 0x727d79e500000000, - 0x4d8e19f900000000, 0x456d79c500000000, 0x5d48d88100000000, - 0x55abb8bd00000000, 0x6d029a0800000000, 0x65e1fa3400000000, - 0x7dc45b7000000000, 0x75273b4c00000000, 0x4c906fc100000000, - 0x44730ffd00000000, 0x5c56aeb900000000, 0x54b5ce8500000000, - 0x6c1cec3000000000, 0x64ff8c0c00000000, 0x7cda2d4800000000, - 0x74394d7400000000, 0x4fb2f58900000000, 0x475195b500000000, - 0x5f7434f100000000, 0x579754cd00000000, 0x6f3e767800000000, - 0x67dd164400000000, 0x7ff8b70000000000, 0x771bd73c00000000, - 0x4eac83b100000000, 0x464fe38d00000000, 0x5e6a42c900000000, - 0x568922f500000000, 0x6e20004000000000, 0x66c3607c00000000, - 0x7ee6c13800000000, 0x7605a10400000000, 0x92ec833100000000, - 0x9a0fe30d00000000, 0x822a424900000000, 0x8ac9227500000000, - 0xb26000c000000000, 0xba8360fc00000000, 0xa2a6c1b800000000, - 0xaa45a18400000000, 0x93f2f50900000000, 0x9b11953500000000, - 0x8334347100000000, 0x8bd7544d00000000, 0xb37e76f800000000, - 0xbb9d16c400000000, 0xa3b8b78000000000, 0xab5bd7bc00000000, - 0x90d06f4100000000, 0x98330f7d00000000, 0x8016ae3900000000, - 0x88f5ce0500000000, 0xb05cecb000000000, 0xb8bf8c8c00000000, - 0xa09a2dc800000000, 0xa8794df400000000, 0x91ce197900000000, - 0x992d794500000000, 0x8108d80100000000, 0x89ebb83d00000000, - 0xb1429a8800000000, 0xb9a1fab400000000, 0xa1845bf000000000, - 0xa9673bcc00000000, 0x96945bd000000000, 0x9e773bec00000000, - 0x86529aa800000000, 0x8eb1fa9400000000, 0xb618d82100000000, - 0xbefbb81d00000000, 0xa6de195900000000, 0xae3d796500000000, - 0x978a2de800000000, 0x9f694dd400000000, 0x874cec9000000000, - 0x8faf8cac00000000, 0xb706ae1900000000, 0xbfe5ce2500000000, - 0xa7c06f6100000000, 0xaf230f5d00000000, 0x94a8b7a000000000, - 0x9c4bd79c00000000, 0x846e76d800000000, 0x8c8d16e400000000, - 0xb424345100000000, 0xbcc7546d00000000, 0xa4e2f52900000000, - 0xac01951500000000, 0x95b6c19800000000, 0x9d55a1a400000000, - 0x857000e000000000, 0x8d9360dc00000000, 0xb53a426900000000, - 0xbdd9225500000000, 0xa5fc831100000000, 0xad1fe32d00000000, - 0xdb1a422900000000, 0xd3f9221500000000, 0xcbdc835100000000, - 0xc33fe36d00000000, 0xfb96c1d800000000, 0xf375a1e400000000, - 0xeb5000a000000000, 0xe3b3609c00000000, 0xda04341100000000, - 0xd2e7542d00000000, 0xcac2f56900000000, 0xc221955500000000, - 0xfa88b7e000000000, 0xf26bd7dc00000000, 0xea4e769800000000, - 0xe2ad16a400000000, 0xd926ae5900000000, 0xd1c5ce6500000000, - 0xc9e06f2100000000, 0xc1030f1d00000000, 0xf9aa2da800000000, - 0xf1494d9400000000, 0xe96cecd000000000, 0xe18f8cec00000000, - 0xd838d86100000000, 0xd0dbb85d00000000, 0xc8fe191900000000, - 0xc01d792500000000, 0xf8b45b9000000000, 0xf0573bac00000000, - 0xe8729ae800000000, 0xe091fad400000000, 0xdf629ac800000000, - 0xd781faf400000000, 0xcfa45bb000000000, 0xc7473b8c00000000, - 0xffee193900000000, 0xf70d790500000000, 0xef28d84100000000, - 0xe7cbb87d00000000, 0xde7cecf000000000, 0xd69f8ccc00000000, - 0xceba2d8800000000, 0xc6594db400000000, 0xfef06f0100000000, - 0xf6130f3d00000000, 0xee36ae7900000000, 0xe6d5ce4500000000, - 0xdd5e76b800000000, 0xd5bd168400000000, 0xcd98b7c000000000, - 0xc57bd7fc00000000, 0xfdd2f54900000000, 0xf531957500000000, - 0xed14343100000000, 0xe5f7540d00000000, 0xdc40008000000000, - 0xd4a360bc00000000, 0xcc86c1f800000000, 0xc465a1c400000000, - 0xfccc837100000000, 0xf42fe34d00000000, 0xec0a420900000000, - 0xe4e9223500000000}, - {0x0000000000000000, 0xd1e8e70e00000000, 0xa2d1cf1d00000000, - 0x7339281300000000, 0x44a39f3b00000000, 0x954b783500000000, - 0xe672502600000000, 0x379ab72800000000, 0x88463f7700000000, - 0x59aed87900000000, 0x2a97f06a00000000, 0xfb7f176400000000, - 0xcce5a04c00000000, 0x1d0d474200000000, 0x6e346f5100000000, - 0xbfdc885f00000000, 0x108d7eee00000000, 0xc16599e000000000, - 0xb25cb1f300000000, 0x63b456fd00000000, 0x542ee1d500000000, - 0x85c606db00000000, 0xf6ff2ec800000000, 0x2717c9c600000000, - 0x98cb419900000000, 0x4923a69700000000, 0x3a1a8e8400000000, - 0xebf2698a00000000, 0xdc68dea200000000, 0x0d8039ac00000000, - 0x7eb911bf00000000, 0xaf51f6b100000000, 0x611c8c0700000000, - 0xb0f46b0900000000, 0xc3cd431a00000000, 0x1225a41400000000, - 0x25bf133c00000000, 0xf457f43200000000, 0x876edc2100000000, - 0x56863b2f00000000, 0xe95ab37000000000, 0x38b2547e00000000, - 0x4b8b7c6d00000000, 0x9a639b6300000000, 0xadf92c4b00000000, - 0x7c11cb4500000000, 0x0f28e35600000000, 0xdec0045800000000, - 0x7191f2e900000000, 0xa07915e700000000, 0xd3403df400000000, - 0x02a8dafa00000000, 0x35326dd200000000, 0xe4da8adc00000000, - 0x97e3a2cf00000000, 0x460b45c100000000, 0xf9d7cd9e00000000, - 0x283f2a9000000000, 0x5b06028300000000, 0x8aeee58d00000000, - 0xbd7452a500000000, 0x6c9cb5ab00000000, 0x1fa59db800000000, - 0xce4d7ab600000000, 0xc238180f00000000, 0x13d0ff0100000000, - 0x60e9d71200000000, 0xb101301c00000000, 0x869b873400000000, - 0x5773603a00000000, 0x244a482900000000, 0xf5a2af2700000000, - 0x4a7e277800000000, 0x9b96c07600000000, 0xe8afe86500000000, - 0x39470f6b00000000, 0x0eddb84300000000, 0xdf355f4d00000000, - 0xac0c775e00000000, 0x7de4905000000000, 0xd2b566e100000000, - 0x035d81ef00000000, 0x7064a9fc00000000, 0xa18c4ef200000000, - 0x9616f9da00000000, 0x47fe1ed400000000, 0x34c736c700000000, - 0xe52fd1c900000000, 0x5af3599600000000, 0x8b1bbe9800000000, - 0xf822968b00000000, 0x29ca718500000000, 0x1e50c6ad00000000, - 0xcfb821a300000000, 0xbc8109b000000000, 0x6d69eebe00000000, - 0xa324940800000000, 0x72cc730600000000, 0x01f55b1500000000, - 0xd01dbc1b00000000, 0xe7870b3300000000, 0x366fec3d00000000, - 0x4556c42e00000000, 0x94be232000000000, 0x2b62ab7f00000000, - 0xfa8a4c7100000000, 0x89b3646200000000, 0x585b836c00000000, - 0x6fc1344400000000, 0xbe29d34a00000000, 0xcd10fb5900000000, - 0x1cf81c5700000000, 0xb3a9eae600000000, 0x62410de800000000, - 0x117825fb00000000, 0xc090c2f500000000, 0xf70a75dd00000000, - 0x26e292d300000000, 0x55dbbac000000000, 0x84335dce00000000, - 0x3befd59100000000, 0xea07329f00000000, 0x993e1a8c00000000, - 0x48d6fd8200000000, 0x7f4c4aaa00000000, 0xaea4ada400000000, - 0xdd9d85b700000000, 0x0c7562b900000000, 0x8471301e00000000, - 0x5599d71000000000, 0x26a0ff0300000000, 0xf748180d00000000, - 0xc0d2af2500000000, 0x113a482b00000000, 0x6203603800000000, - 0xb3eb873600000000, 0x0c370f6900000000, 0xdddfe86700000000, - 0xaee6c07400000000, 0x7f0e277a00000000, 0x4894905200000000, - 0x997c775c00000000, 0xea455f4f00000000, 0x3badb84100000000, - 0x94fc4ef000000000, 0x4514a9fe00000000, 0x362d81ed00000000, - 0xe7c566e300000000, 0xd05fd1cb00000000, 0x01b736c500000000, - 0x728e1ed600000000, 0xa366f9d800000000, 0x1cba718700000000, - 0xcd52968900000000, 0xbe6bbe9a00000000, 0x6f83599400000000, - 0x5819eebc00000000, 0x89f109b200000000, 0xfac821a100000000, - 0x2b20c6af00000000, 0xe56dbc1900000000, 0x34855b1700000000, - 0x47bc730400000000, 0x9654940a00000000, 0xa1ce232200000000, - 0x7026c42c00000000, 0x031fec3f00000000, 0xd2f70b3100000000, - 0x6d2b836e00000000, 0xbcc3646000000000, 0xcffa4c7300000000, - 0x1e12ab7d00000000, 0x29881c5500000000, 0xf860fb5b00000000, - 0x8b59d34800000000, 0x5ab1344600000000, 0xf5e0c2f700000000, - 0x240825f900000000, 0x57310dea00000000, 0x86d9eae400000000, - 0xb1435dcc00000000, 0x60abbac200000000, 0x139292d100000000, - 0xc27a75df00000000, 0x7da6fd8000000000, 0xac4e1a8e00000000, - 0xdf77329d00000000, 0x0e9fd59300000000, 0x390562bb00000000, - 0xe8ed85b500000000, 0x9bd4ada600000000, 0x4a3c4aa800000000, - 0x4649281100000000, 0x97a1cf1f00000000, 0xe498e70c00000000, - 0x3570000200000000, 0x02eab72a00000000, 0xd302502400000000, - 0xa03b783700000000, 0x71d39f3900000000, 0xce0f176600000000, - 0x1fe7f06800000000, 0x6cded87b00000000, 0xbd363f7500000000, - 0x8aac885d00000000, 0x5b446f5300000000, 0x287d474000000000, - 0xf995a04e00000000, 0x56c456ff00000000, 0x872cb1f100000000, - 0xf41599e200000000, 0x25fd7eec00000000, 0x1267c9c400000000, - 0xc38f2eca00000000, 0xb0b606d900000000, 0x615ee1d700000000, - 0xde82698800000000, 0x0f6a8e8600000000, 0x7c53a69500000000, - 0xadbb419b00000000, 0x9a21f6b300000000, 0x4bc911bd00000000, - 0x38f039ae00000000, 0xe918dea000000000, 0x2755a41600000000, - 0xf6bd431800000000, 0x85846b0b00000000, 0x546c8c0500000000, - 0x63f63b2d00000000, 0xb21edc2300000000, 0xc127f43000000000, - 0x10cf133e00000000, 0xaf139b6100000000, 0x7efb7c6f00000000, - 0x0dc2547c00000000, 0xdc2ab37200000000, 0xebb0045a00000000, - 0x3a58e35400000000, 0x4961cb4700000000, 0x98892c4900000000, - 0x37d8daf800000000, 0xe6303df600000000, 0x950915e500000000, - 0x44e1f2eb00000000, 0x737b45c300000000, 0xa293a2cd00000000, - 0xd1aa8ade00000000, 0x00426dd000000000, 0xbf9ee58f00000000, - 0x6e76028100000000, 0x1d4f2a9200000000, 0xcca7cd9c00000000, - 0xfb3d7ab400000000, 0x2ad59dba00000000, 0x59ecb5a900000000, - 0x880452a700000000}, - {0x0000000000000000, 0xaa05daf100000000, 0x150dc53800000000, - 0xbf081fc900000000, 0x2a1a8a7100000000, 0x801f508000000000, - 0x3f174f4900000000, 0x951295b800000000, 0x543414e300000000, - 0xfe31ce1200000000, 0x4139d1db00000000, 0xeb3c0b2a00000000, - 0x7e2e9e9200000000, 0xd42b446300000000, 0x6b235baa00000000, - 0xc126815b00000000, 0xe96e591d00000000, 0x436b83ec00000000, - 0xfc639c2500000000, 0x566646d400000000, 0xc374d36c00000000, - 0x6971099d00000000, 0xd679165400000000, 0x7c7ccca500000000, - 0xbd5a4dfe00000000, 0x175f970f00000000, 0xa85788c600000000, - 0x0252523700000000, 0x9740c78f00000000, 0x3d451d7e00000000, - 0x824d02b700000000, 0x2848d84600000000, 0xd2ddb23a00000000, - 0x78d868cb00000000, 0xc7d0770200000000, 0x6dd5adf300000000, - 0xf8c7384b00000000, 0x52c2e2ba00000000, 0xedcafd7300000000, - 0x47cf278200000000, 0x86e9a6d900000000, 0x2cec7c2800000000, - 0x93e463e100000000, 0x39e1b91000000000, 0xacf32ca800000000, - 0x06f6f65900000000, 0xb9fee99000000000, 0x13fb336100000000, - 0x3bb3eb2700000000, 0x91b631d600000000, 0x2ebe2e1f00000000, - 0x84bbf4ee00000000, 0x11a9615600000000, 0xbbacbba700000000, - 0x04a4a46e00000000, 0xaea17e9f00000000, 0x6f87ffc400000000, - 0xc582253500000000, 0x7a8a3afc00000000, 0xd08fe00d00000000, - 0x459d75b500000000, 0xef98af4400000000, 0x5090b08d00000000, - 0xfa956a7c00000000, 0xa4bb657500000000, 0x0ebebf8400000000, - 0xb1b6a04d00000000, 0x1bb37abc00000000, 0x8ea1ef0400000000, - 0x24a435f500000000, 0x9bac2a3c00000000, 0x31a9f0cd00000000, - 0xf08f719600000000, 0x5a8aab6700000000, 0xe582b4ae00000000, - 0x4f876e5f00000000, 0xda95fbe700000000, 0x7090211600000000, - 0xcf983edf00000000, 0x659de42e00000000, 0x4dd53c6800000000, - 0xe7d0e69900000000, 0x58d8f95000000000, 0xf2dd23a100000000, - 0x67cfb61900000000, 0xcdca6ce800000000, 0x72c2732100000000, - 0xd8c7a9d000000000, 0x19e1288b00000000, 0xb3e4f27a00000000, - 0x0cecedb300000000, 0xa6e9374200000000, 0x33fba2fa00000000, - 0x99fe780b00000000, 0x26f667c200000000, 0x8cf3bd3300000000, - 0x7666d74f00000000, 0xdc630dbe00000000, 0x636b127700000000, - 0xc96ec88600000000, 0x5c7c5d3e00000000, 0xf67987cf00000000, - 0x4971980600000000, 0xe37442f700000000, 0x2252c3ac00000000, - 0x8857195d00000000, 0x375f069400000000, 0x9d5adc6500000000, - 0x084849dd00000000, 0xa24d932c00000000, 0x1d458ce500000000, - 0xb740561400000000, 0x9f088e5200000000, 0x350d54a300000000, - 0x8a054b6a00000000, 0x2000919b00000000, 0xb512042300000000, - 0x1f17ded200000000, 0xa01fc11b00000000, 0x0a1a1bea00000000, - 0xcb3c9ab100000000, 0x6139404000000000, 0xde315f8900000000, - 0x7434857800000000, 0xe12610c000000000, 0x4b23ca3100000000, - 0xf42bd5f800000000, 0x5e2e0f0900000000, 0x4877cbea00000000, - 0xe272111b00000000, 0x5d7a0ed200000000, 0xf77fd42300000000, - 0x626d419b00000000, 0xc8689b6a00000000, 0x776084a300000000, - 0xdd655e5200000000, 0x1c43df0900000000, 0xb64605f800000000, - 0x094e1a3100000000, 0xa34bc0c000000000, 0x3659557800000000, - 0x9c5c8f8900000000, 0x2354904000000000, 0x89514ab100000000, - 0xa11992f700000000, 0x0b1c480600000000, 0xb41457cf00000000, - 0x1e118d3e00000000, 0x8b03188600000000, 0x2106c27700000000, - 0x9e0eddbe00000000, 0x340b074f00000000, 0xf52d861400000000, - 0x5f285ce500000000, 0xe020432c00000000, 0x4a2599dd00000000, - 0xdf370c6500000000, 0x7532d69400000000, 0xca3ac95d00000000, - 0x603f13ac00000000, 0x9aaa79d000000000, 0x30afa32100000000, - 0x8fa7bce800000000, 0x25a2661900000000, 0xb0b0f3a100000000, - 0x1ab5295000000000, 0xa5bd369900000000, 0x0fb8ec6800000000, - 0xce9e6d3300000000, 0x649bb7c200000000, 0xdb93a80b00000000, - 0x719672fa00000000, 0xe484e74200000000, 0x4e813db300000000, - 0xf189227a00000000, 0x5b8cf88b00000000, 0x73c420cd00000000, - 0xd9c1fa3c00000000, 0x66c9e5f500000000, 0xcccc3f0400000000, - 0x59deaabc00000000, 0xf3db704d00000000, 0x4cd36f8400000000, - 0xe6d6b57500000000, 0x27f0342e00000000, 0x8df5eedf00000000, - 0x32fdf11600000000, 0x98f82be700000000, 0x0deabe5f00000000, - 0xa7ef64ae00000000, 0x18e77b6700000000, 0xb2e2a19600000000, - 0xecccae9f00000000, 0x46c9746e00000000, 0xf9c16ba700000000, - 0x53c4b15600000000, 0xc6d624ee00000000, 0x6cd3fe1f00000000, - 0xd3dbe1d600000000, 0x79de3b2700000000, 0xb8f8ba7c00000000, - 0x12fd608d00000000, 0xadf57f4400000000, 0x07f0a5b500000000, - 0x92e2300d00000000, 0x38e7eafc00000000, 0x87eff53500000000, - 0x2dea2fc400000000, 0x05a2f78200000000, 0xafa72d7300000000, - 0x10af32ba00000000, 0xbaaae84b00000000, 0x2fb87df300000000, - 0x85bda70200000000, 0x3ab5b8cb00000000, 0x90b0623a00000000, - 0x5196e36100000000, 0xfb93399000000000, 0x449b265900000000, - 0xee9efca800000000, 0x7b8c691000000000, 0xd189b3e100000000, - 0x6e81ac2800000000, 0xc48476d900000000, 0x3e111ca500000000, - 0x9414c65400000000, 0x2b1cd99d00000000, 0x8119036c00000000, - 0x140b96d400000000, 0xbe0e4c2500000000, 0x010653ec00000000, - 0xab03891d00000000, 0x6a25084600000000, 0xc020d2b700000000, - 0x7f28cd7e00000000, 0xd52d178f00000000, 0x403f823700000000, - 0xea3a58c600000000, 0x5532470f00000000, 0xff379dfe00000000, - 0xd77f45b800000000, 0x7d7a9f4900000000, 0xc272808000000000, - 0x68775a7100000000, 0xfd65cfc900000000, 0x5760153800000000, - 0xe8680af100000000, 0x426dd00000000000, 0x834b515b00000000, - 0x294e8baa00000000, 0x9646946300000000, 0x3c434e9200000000, - 0xa951db2a00000000, 0x035401db00000000, 0xbc5c1e1200000000, - 0x1659c4e300000000}}; - -#else /* W == 4 */ - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0xae689191, 0x87a02563, 0x29c8b4f2, 0xd4314c87, - 0x7a59dd16, 0x539169e4, 0xfdf9f875, 0x73139f4f, 0xdd7b0ede, - 0xf4b3ba2c, 0x5adb2bbd, 0xa722d3c8, 0x094a4259, 0x2082f6ab, - 0x8eea673a, 0xe6273e9e, 0x484faf0f, 0x61871bfd, 0xcfef8a6c, - 0x32167219, 0x9c7ee388, 0xb5b6577a, 0x1bdec6eb, 0x9534a1d1, - 0x3b5c3040, 0x129484b2, 0xbcfc1523, 0x4105ed56, 0xef6d7cc7, - 0xc6a5c835, 0x68cd59a4, 0x173f7b7d, 0xb957eaec, 0x909f5e1e, - 0x3ef7cf8f, 0xc30e37fa, 0x6d66a66b, 0x44ae1299, 0xeac68308, - 0x642ce432, 0xca4475a3, 0xe38cc151, 0x4de450c0, 0xb01da8b5, - 0x1e753924, 0x37bd8dd6, 0x99d51c47, 0xf11845e3, 0x5f70d472, - 0x76b86080, 0xd8d0f111, 0x25290964, 0x8b4198f5, 0xa2892c07, - 0x0ce1bd96, 0x820bdaac, 0x2c634b3d, 0x05abffcf, 0xabc36e5e, - 0x563a962b, 0xf85207ba, 0xd19ab348, 0x7ff222d9, 0x2e7ef6fa, - 0x8016676b, 0xa9ded399, 0x07b64208, 0xfa4fba7d, 0x54272bec, - 0x7def9f1e, 0xd3870e8f, 0x5d6d69b5, 0xf305f824, 0xdacd4cd6, - 0x74a5dd47, 0x895c2532, 0x2734b4a3, 0x0efc0051, 0xa09491c0, - 0xc859c864, 0x663159f5, 0x4ff9ed07, 0xe1917c96, 0x1c6884e3, - 0xb2001572, 0x9bc8a180, 0x35a03011, 0xbb4a572b, 0x1522c6ba, - 0x3cea7248, 0x9282e3d9, 0x6f7b1bac, 0xc1138a3d, 0xe8db3ecf, - 0x46b3af5e, 0x39418d87, 0x97291c16, 0xbee1a8e4, 0x10893975, - 0xed70c100, 0x43185091, 0x6ad0e463, 0xc4b875f2, 0x4a5212c8, - 0xe43a8359, 0xcdf237ab, 0x639aa63a, 0x9e635e4f, 0x300bcfde, - 0x19c37b2c, 0xb7abeabd, 0xdf66b319, 0x710e2288, 0x58c6967a, - 0xf6ae07eb, 0x0b57ff9e, 0xa53f6e0f, 0x8cf7dafd, 0x229f4b6c, - 0xac752c56, 0x021dbdc7, 0x2bd50935, 0x85bd98a4, 0x784460d1, - 0xd62cf140, 0xffe445b2, 0x518cd423, 0x5cfdedf4, 0xf2957c65, - 0xdb5dc897, 0x75355906, 0x88cca173, 0x26a430e2, 0x0f6c8410, - 0xa1041581, 0x2fee72bb, 0x8186e32a, 0xa84e57d8, 0x0626c649, - 0xfbdf3e3c, 0x55b7afad, 0x7c7f1b5f, 0xd2178ace, 0xbadad36a, - 0x14b242fb, 0x3d7af609, 0x93126798, 0x6eeb9fed, 0xc0830e7c, - 0xe94bba8e, 0x47232b1f, 0xc9c94c25, 0x67a1ddb4, 0x4e696946, - 0xe001f8d7, 0x1df800a2, 0xb3909133, 0x9a5825c1, 0x3430b450, - 0x4bc29689, 0xe5aa0718, 0xcc62b3ea, 0x620a227b, 0x9ff3da0e, - 0x319b4b9f, 0x1853ff6d, 0xb63b6efc, 0x38d109c6, 0x96b99857, - 0xbf712ca5, 0x1119bd34, 0xece04541, 0x4288d4d0, 0x6b406022, - 0xc528f1b3, 0xade5a817, 0x038d3986, 0x2a458d74, 0x842d1ce5, - 0x79d4e490, 0xd7bc7501, 0xfe74c1f3, 0x501c5062, 0xdef63758, - 0x709ea6c9, 0x5956123b, 0xf73e83aa, 0x0ac77bdf, 0xa4afea4e, - 0x8d675ebc, 0x230fcf2d, 0x72831b0e, 0xdceb8a9f, 0xf5233e6d, - 0x5b4baffc, 0xa6b25789, 0x08dac618, 0x211272ea, 0x8f7ae37b, - 0x01908441, 0xaff815d0, 0x8630a122, 0x285830b3, 0xd5a1c8c6, - 0x7bc95957, 0x5201eda5, 0xfc697c34, 0x94a42590, 0x3accb401, - 0x130400f3, 0xbd6c9162, 0x40956917, 0xeefdf886, 0xc7354c74, - 0x695ddde5, 0xe7b7badf, 0x49df2b4e, 0x60179fbc, 0xce7f0e2d, - 0x3386f658, 0x9dee67c9, 0xb426d33b, 0x1a4e42aa, 0x65bc6073, - 0xcbd4f1e2, 0xe21c4510, 0x4c74d481, 0xb18d2cf4, 0x1fe5bd65, - 0x362d0997, 0x98459806, 0x16afff3c, 0xb8c76ead, 0x910fda5f, - 0x3f674bce, 0xc29eb3bb, 0x6cf6222a, 0x453e96d8, 0xeb560749, - 0x839b5eed, 0x2df3cf7c, 0x043b7b8e, 0xaa53ea1f, 0x57aa126a, - 0xf9c283fb, 0xd00a3709, 0x7e62a698, 0xf088c1a2, 0x5ee05033, - 0x7728e4c1, 0xd9407550, 0x24b98d25, 0x8ad11cb4, 0xa319a846, - 0x0d7139d7}, - {0x00000000, 0xb9fbdbe8, 0xa886b191, 0x117d6a79, 0x8a7c6563, - 0x3387be8b, 0x22fad4f2, 0x9b010f1a, 0xcf89cc87, 0x7672176f, - 0x670f7d16, 0xdef4a6fe, 0x45f5a9e4, 0xfc0e720c, 0xed731875, - 0x5488c39d, 0x44629f4f, 0xfd9944a7, 0xece42ede, 0x551ff536, - 0xce1efa2c, 0x77e521c4, 0x66984bbd, 0xdf639055, 0x8beb53c8, - 0x32108820, 0x236de259, 0x9a9639b1, 0x019736ab, 0xb86ced43, - 0xa911873a, 0x10ea5cd2, 0x88c53e9e, 0x313ee576, 0x20438f0f, - 0x99b854e7, 0x02b95bfd, 0xbb428015, 0xaa3fea6c, 0x13c43184, - 0x474cf219, 0xfeb729f1, 0xefca4388, 0x56319860, 0xcd30977a, - 0x74cb4c92, 0x65b626eb, 0xdc4dfd03, 0xcca7a1d1, 0x755c7a39, - 0x64211040, 0xdddacba8, 0x46dbc4b2, 0xff201f5a, 0xee5d7523, - 0x57a6aecb, 0x032e6d56, 0xbad5b6be, 0xaba8dcc7, 0x1253072f, - 0x89520835, 0x30a9d3dd, 0x21d4b9a4, 0x982f624c, 0xcafb7b7d, - 0x7300a095, 0x627dcaec, 0xdb861104, 0x40871e1e, 0xf97cc5f6, - 0xe801af8f, 0x51fa7467, 0x0572b7fa, 0xbc896c12, 0xadf4066b, - 0x140fdd83, 0x8f0ed299, 0x36f50971, 0x27886308, 0x9e73b8e0, - 0x8e99e432, 0x37623fda, 0x261f55a3, 0x9fe48e4b, 0x04e58151, - 0xbd1e5ab9, 0xac6330c0, 0x1598eb28, 0x411028b5, 0xf8ebf35d, - 0xe9969924, 0x506d42cc, 0xcb6c4dd6, 0x7297963e, 0x63eafc47, - 0xda1127af, 0x423e45e3, 0xfbc59e0b, 0xeab8f472, 0x53432f9a, - 0xc8422080, 0x71b9fb68, 0x60c49111, 0xd93f4af9, 0x8db78964, - 0x344c528c, 0x253138f5, 0x9ccae31d, 0x07cbec07, 0xbe3037ef, - 0xaf4d5d96, 0x16b6867e, 0x065cdaac, 0xbfa70144, 0xaeda6b3d, - 0x1721b0d5, 0x8c20bfcf, 0x35db6427, 0x24a60e5e, 0x9d5dd5b6, - 0xc9d5162b, 0x702ecdc3, 0x6153a7ba, 0xd8a87c52, 0x43a97348, - 0xfa52a8a0, 0xeb2fc2d9, 0x52d41931, 0x4e87f0bb, 0xf77c2b53, - 0xe601412a, 0x5ffa9ac2, 0xc4fb95d8, 0x7d004e30, 0x6c7d2449, - 0xd586ffa1, 0x810e3c3c, 0x38f5e7d4, 0x29888dad, 0x90735645, - 0x0b72595f, 0xb28982b7, 0xa3f4e8ce, 0x1a0f3326, 0x0ae56ff4, - 0xb31eb41c, 0xa263de65, 0x1b98058d, 0x80990a97, 0x3962d17f, - 0x281fbb06, 0x91e460ee, 0xc56ca373, 0x7c97789b, 0x6dea12e2, - 0xd411c90a, 0x4f10c610, 0xf6eb1df8, 0xe7967781, 0x5e6dac69, - 0xc642ce25, 0x7fb915cd, 0x6ec47fb4, 0xd73fa45c, 0x4c3eab46, - 0xf5c570ae, 0xe4b81ad7, 0x5d43c13f, 0x09cb02a2, 0xb030d94a, - 0xa14db333, 0x18b668db, 0x83b767c1, 0x3a4cbc29, 0x2b31d650, - 0x92ca0db8, 0x8220516a, 0x3bdb8a82, 0x2aa6e0fb, 0x935d3b13, - 0x085c3409, 0xb1a7efe1, 0xa0da8598, 0x19215e70, 0x4da99ded, - 0xf4524605, 0xe52f2c7c, 0x5cd4f794, 0xc7d5f88e, 0x7e2e2366, - 0x6f53491f, 0xd6a892f7, 0x847c8bc6, 0x3d87502e, 0x2cfa3a57, - 0x9501e1bf, 0x0e00eea5, 0xb7fb354d, 0xa6865f34, 0x1f7d84dc, - 0x4bf54741, 0xf20e9ca9, 0xe373f6d0, 0x5a882d38, 0xc1892222, - 0x7872f9ca, 0x690f93b3, 0xd0f4485b, 0xc01e1489, 0x79e5cf61, - 0x6898a518, 0xd1637ef0, 0x4a6271ea, 0xf399aa02, 0xe2e4c07b, - 0x5b1f1b93, 0x0f97d80e, 0xb66c03e6, 0xa711699f, 0x1eeab277, - 0x85ebbd6d, 0x3c106685, 0x2d6d0cfc, 0x9496d714, 0x0cb9b558, - 0xb5426eb0, 0xa43f04c9, 0x1dc4df21, 0x86c5d03b, 0x3f3e0bd3, - 0x2e4361aa, 0x97b8ba42, 0xc33079df, 0x7acba237, 0x6bb6c84e, - 0xd24d13a6, 0x494c1cbc, 0xf0b7c754, 0xe1caad2d, 0x583176c5, - 0x48db2a17, 0xf120f1ff, 0xe05d9b86, 0x59a6406e, 0xc2a74f74, - 0x7b5c949c, 0x6a21fee5, 0xd3da250d, 0x8752e690, 0x3ea93d78, - 0x2fd45701, 0x962f8ce9, 0x0d2e83f3, 0xb4d5581b, 0xa5a83262, - 0x1c53e98a}, - {0x00000000, 0x9d0fe176, 0xe16ec4ad, 0x7c6125db, 0x19ac8f1b, - 0x84a36e6d, 0xf8c24bb6, 0x65cdaac0, 0x33591e36, 0xae56ff40, - 0xd237da9b, 0x4f383bed, 0x2af5912d, 0xb7fa705b, 0xcb9b5580, - 0x5694b4f6, 0x66b23c6c, 0xfbbddd1a, 0x87dcf8c1, 0x1ad319b7, - 0x7f1eb377, 0xe2115201, 0x9e7077da, 0x037f96ac, 0x55eb225a, - 0xc8e4c32c, 0xb485e6f7, 0x298a0781, 0x4c47ad41, 0xd1484c37, - 0xad2969ec, 0x3026889a, 0xcd6478d8, 0x506b99ae, 0x2c0abc75, - 0xb1055d03, 0xd4c8f7c3, 0x49c716b5, 0x35a6336e, 0xa8a9d218, - 0xfe3d66ee, 0x63328798, 0x1f53a243, 0x825c4335, 0xe791e9f5, - 0x7a9e0883, 0x06ff2d58, 0x9bf0cc2e, 0xabd644b4, 0x36d9a5c2, - 0x4ab88019, 0xd7b7616f, 0xb27acbaf, 0x2f752ad9, 0x53140f02, - 0xce1bee74, 0x988f5a82, 0x0580bbf4, 0x79e19e2f, 0xe4ee7f59, - 0x8123d599, 0x1c2c34ef, 0x604d1134, 0xfd42f042, 0x41b9f7f1, - 0xdcb61687, 0xa0d7335c, 0x3dd8d22a, 0x581578ea, 0xc51a999c, - 0xb97bbc47, 0x24745d31, 0x72e0e9c7, 0xefef08b1, 0x938e2d6a, - 0x0e81cc1c, 0x6b4c66dc, 0xf64387aa, 0x8a22a271, 0x172d4307, - 0x270bcb9d, 0xba042aeb, 0xc6650f30, 0x5b6aee46, 0x3ea74486, - 0xa3a8a5f0, 0xdfc9802b, 0x42c6615d, 0x1452d5ab, 0x895d34dd, - 0xf53c1106, 0x6833f070, 0x0dfe5ab0, 0x90f1bbc6, 0xec909e1d, - 0x719f7f6b, 0x8cdd8f29, 0x11d26e5f, 0x6db34b84, 0xf0bcaaf2, - 0x95710032, 0x087ee144, 0x741fc49f, 0xe91025e9, 0xbf84911f, - 0x228b7069, 0x5eea55b2, 0xc3e5b4c4, 0xa6281e04, 0x3b27ff72, - 0x4746daa9, 0xda493bdf, 0xea6fb345, 0x77605233, 0x0b0177e8, - 0x960e969e, 0xf3c33c5e, 0x6eccdd28, 0x12adf8f3, 0x8fa21985, - 0xd936ad73, 0x44394c05, 0x385869de, 0xa55788a8, 0xc09a2268, - 0x5d95c31e, 0x21f4e6c5, 0xbcfb07b3, 0x8373efe2, 0x1e7c0e94, - 0x621d2b4f, 0xff12ca39, 0x9adf60f9, 0x07d0818f, 0x7bb1a454, - 0xe6be4522, 0xb02af1d4, 0x2d2510a2, 0x51443579, 0xcc4bd40f, - 0xa9867ecf, 0x34899fb9, 0x48e8ba62, 0xd5e75b14, 0xe5c1d38e, - 0x78ce32f8, 0x04af1723, 0x99a0f655, 0xfc6d5c95, 0x6162bde3, - 0x1d039838, 0x800c794e, 0xd698cdb8, 0x4b972cce, 0x37f60915, - 0xaaf9e863, 0xcf3442a3, 0x523ba3d5, 0x2e5a860e, 0xb3556778, - 0x4e17973a, 0xd318764c, 0xaf795397, 0x3276b2e1, 0x57bb1821, - 0xcab4f957, 0xb6d5dc8c, 0x2bda3dfa, 0x7d4e890c, 0xe041687a, - 0x9c204da1, 0x012facd7, 0x64e20617, 0xf9ede761, 0x858cc2ba, - 0x188323cc, 0x28a5ab56, 0xb5aa4a20, 0xc9cb6ffb, 0x54c48e8d, - 0x3109244d, 0xac06c53b, 0xd067e0e0, 0x4d680196, 0x1bfcb560, - 0x86f35416, 0xfa9271cd, 0x679d90bb, 0x02503a7b, 0x9f5fdb0d, - 0xe33efed6, 0x7e311fa0, 0xc2ca1813, 0x5fc5f965, 0x23a4dcbe, - 0xbeab3dc8, 0xdb669708, 0x4669767e, 0x3a0853a5, 0xa707b2d3, - 0xf1930625, 0x6c9ce753, 0x10fdc288, 0x8df223fe, 0xe83f893e, - 0x75306848, 0x09514d93, 0x945eace5, 0xa478247f, 0x3977c509, - 0x4516e0d2, 0xd81901a4, 0xbdd4ab64, 0x20db4a12, 0x5cba6fc9, - 0xc1b58ebf, 0x97213a49, 0x0a2edb3f, 0x764ffee4, 0xeb401f92, - 0x8e8db552, 0x13825424, 0x6fe371ff, 0xf2ec9089, 0x0fae60cb, - 0x92a181bd, 0xeec0a466, 0x73cf4510, 0x1602efd0, 0x8b0d0ea6, - 0xf76c2b7d, 0x6a63ca0b, 0x3cf77efd, 0xa1f89f8b, 0xdd99ba50, - 0x40965b26, 0x255bf1e6, 0xb8541090, 0xc435354b, 0x593ad43d, - 0x691c5ca7, 0xf413bdd1, 0x8872980a, 0x157d797c, 0x70b0d3bc, - 0xedbf32ca, 0x91de1711, 0x0cd1f667, 0x5a454291, 0xc74aa3e7, - 0xbb2b863c, 0x2624674a, 0x43e9cd8a, 0xdee62cfc, 0xa2870927, - 0x3f88e851}, - {0x00000000, 0xdd96d985, 0x605cb54b, 0xbdca6cce, 0xc0b96a96, - 0x1d2fb313, 0xa0e5dfdd, 0x7d730658, 0x5a03d36d, 0x87950ae8, - 0x3a5f6626, 0xe7c9bfa3, 0x9abab9fb, 0x472c607e, 0xfae60cb0, - 0x2770d535, 0xb407a6da, 0x69917f5f, 0xd45b1391, 0x09cdca14, - 0x74becc4c, 0xa92815c9, 0x14e27907, 0xc974a082, 0xee0475b7, - 0x3392ac32, 0x8e58c0fc, 0x53ce1979, 0x2ebd1f21, 0xf32bc6a4, - 0x4ee1aa6a, 0x937773ef, 0xb37e4bf5, 0x6ee89270, 0xd322febe, - 0x0eb4273b, 0x73c72163, 0xae51f8e6, 0x139b9428, 0xce0d4dad, - 0xe97d9898, 0x34eb411d, 0x89212dd3, 0x54b7f456, 0x29c4f20e, - 0xf4522b8b, 0x49984745, 0x940e9ec0, 0x0779ed2f, 0xdaef34aa, - 0x67255864, 0xbab381e1, 0xc7c087b9, 0x1a565e3c, 0xa79c32f2, - 0x7a0aeb77, 0x5d7a3e42, 0x80ece7c7, 0x3d268b09, 0xe0b0528c, - 0x9dc354d4, 0x40558d51, 0xfd9fe19f, 0x2009381a, 0xbd8d91ab, - 0x601b482e, 0xddd124e0, 0x0047fd65, 0x7d34fb3d, 0xa0a222b8, - 0x1d684e76, 0xc0fe97f3, 0xe78e42c6, 0x3a189b43, 0x87d2f78d, - 0x5a442e08, 0x27372850, 0xfaa1f1d5, 0x476b9d1b, 0x9afd449e, - 0x098a3771, 0xd41ceef4, 0x69d6823a, 0xb4405bbf, 0xc9335de7, - 0x14a58462, 0xa96fe8ac, 0x74f93129, 0x5389e41c, 0x8e1f3d99, - 0x33d55157, 0xee4388d2, 0x93308e8a, 0x4ea6570f, 0xf36c3bc1, - 0x2efae244, 0x0ef3da5e, 0xd36503db, 0x6eaf6f15, 0xb339b690, - 0xce4ab0c8, 0x13dc694d, 0xae160583, 0x7380dc06, 0x54f00933, - 0x8966d0b6, 0x34acbc78, 0xe93a65fd, 0x944963a5, 0x49dfba20, - 0xf415d6ee, 0x29830f6b, 0xbaf47c84, 0x6762a501, 0xdaa8c9cf, - 0x073e104a, 0x7a4d1612, 0xa7dbcf97, 0x1a11a359, 0xc7877adc, - 0xe0f7afe9, 0x3d61766c, 0x80ab1aa2, 0x5d3dc327, 0x204ec57f, - 0xfdd81cfa, 0x40127034, 0x9d84a9b1, 0xa06a2517, 0x7dfcfc92, - 0xc036905c, 0x1da049d9, 0x60d34f81, 0xbd459604, 0x008ffaca, - 0xdd19234f, 0xfa69f67a, 0x27ff2fff, 0x9a354331, 0x47a39ab4, - 0x3ad09cec, 0xe7464569, 0x5a8c29a7, 0x871af022, 0x146d83cd, - 0xc9fb5a48, 0x74313686, 0xa9a7ef03, 0xd4d4e95b, 0x094230de, - 0xb4885c10, 0x691e8595, 0x4e6e50a0, 0x93f88925, 0x2e32e5eb, - 0xf3a43c6e, 0x8ed73a36, 0x5341e3b3, 0xee8b8f7d, 0x331d56f8, - 0x13146ee2, 0xce82b767, 0x7348dba9, 0xaede022c, 0xd3ad0474, - 0x0e3bddf1, 0xb3f1b13f, 0x6e6768ba, 0x4917bd8f, 0x9481640a, - 0x294b08c4, 0xf4ddd141, 0x89aed719, 0x54380e9c, 0xe9f26252, - 0x3464bbd7, 0xa713c838, 0x7a8511bd, 0xc74f7d73, 0x1ad9a4f6, - 0x67aaa2ae, 0xba3c7b2b, 0x07f617e5, 0xda60ce60, 0xfd101b55, - 0x2086c2d0, 0x9d4cae1e, 0x40da779b, 0x3da971c3, 0xe03fa846, - 0x5df5c488, 0x80631d0d, 0x1de7b4bc, 0xc0716d39, 0x7dbb01f7, - 0xa02dd872, 0xdd5ede2a, 0x00c807af, 0xbd026b61, 0x6094b2e4, - 0x47e467d1, 0x9a72be54, 0x27b8d29a, 0xfa2e0b1f, 0x875d0d47, - 0x5acbd4c2, 0xe701b80c, 0x3a976189, 0xa9e01266, 0x7476cbe3, - 0xc9bca72d, 0x142a7ea8, 0x695978f0, 0xb4cfa175, 0x0905cdbb, - 0xd493143e, 0xf3e3c10b, 0x2e75188e, 0x93bf7440, 0x4e29adc5, - 0x335aab9d, 0xeecc7218, 0x53061ed6, 0x8e90c753, 0xae99ff49, - 0x730f26cc, 0xcec54a02, 0x13539387, 0x6e2095df, 0xb3b64c5a, - 0x0e7c2094, 0xd3eaf911, 0xf49a2c24, 0x290cf5a1, 0x94c6996f, - 0x495040ea, 0x342346b2, 0xe9b59f37, 0x547ff3f9, 0x89e92a7c, - 0x1a9e5993, 0xc7088016, 0x7ac2ecd8, 0xa754355d, 0xda273305, - 0x07b1ea80, 0xba7b864e, 0x67ed5fcb, 0x409d8afe, 0x9d0b537b, - 0x20c13fb5, 0xfd57e630, 0x8024e068, 0x5db239ed, 0xe0785523, - 0x3dee8ca6}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x00000000, 0x85d996dd, 0x4bb55c60, 0xce6ccabd, 0x966ab9c0, - 0x13b32f1d, 0xdddfe5a0, 0x5806737d, 0x6dd3035a, 0xe80a9587, - 0x26665f3a, 0xa3bfc9e7, 0xfbb9ba9a, 0x7e602c47, 0xb00ce6fa, - 0x35d57027, 0xdaa607b4, 0x5f7f9169, 0x91135bd4, 0x14cacd09, - 0x4cccbe74, 0xc91528a9, 0x0779e214, 0x82a074c9, 0xb77504ee, - 0x32ac9233, 0xfcc0588e, 0x7919ce53, 0x211fbd2e, 0xa4c62bf3, - 0x6aaae14e, 0xef737793, 0xf54b7eb3, 0x7092e86e, 0xbefe22d3, - 0x3b27b40e, 0x6321c773, 0xe6f851ae, 0x28949b13, 0xad4d0dce, - 0x98987de9, 0x1d41eb34, 0xd32d2189, 0x56f4b754, 0x0ef2c429, - 0x8b2b52f4, 0x45479849, 0xc09e0e94, 0x2fed7907, 0xaa34efda, - 0x64582567, 0xe181b3ba, 0xb987c0c7, 0x3c5e561a, 0xf2329ca7, - 0x77eb0a7a, 0x423e7a5d, 0xc7e7ec80, 0x098b263d, 0x8c52b0e0, - 0xd454c39d, 0x518d5540, 0x9fe19ffd, 0x1a380920, 0xab918dbd, - 0x2e481b60, 0xe024d1dd, 0x65fd4700, 0x3dfb347d, 0xb822a2a0, - 0x764e681d, 0xf397fec0, 0xc6428ee7, 0x439b183a, 0x8df7d287, - 0x082e445a, 0x50283727, 0xd5f1a1fa, 0x1b9d6b47, 0x9e44fd9a, - 0x71378a09, 0xf4ee1cd4, 0x3a82d669, 0xbf5b40b4, 0xe75d33c9, - 0x6284a514, 0xace86fa9, 0x2931f974, 0x1ce48953, 0x993d1f8e, - 0x5751d533, 0xd28843ee, 0x8a8e3093, 0x0f57a64e, 0xc13b6cf3, - 0x44e2fa2e, 0x5edaf30e, 0xdb0365d3, 0x156faf6e, 0x90b639b3, - 0xc8b04ace, 0x4d69dc13, 0x830516ae, 0x06dc8073, 0x3309f054, - 0xb6d06689, 0x78bcac34, 0xfd653ae9, 0xa5634994, 0x20badf49, - 0xeed615f4, 0x6b0f8329, 0x847cf4ba, 0x01a56267, 0xcfc9a8da, - 0x4a103e07, 0x12164d7a, 0x97cfdba7, 0x59a3111a, 0xdc7a87c7, - 0xe9aff7e0, 0x6c76613d, 0xa21aab80, 0x27c33d5d, 0x7fc54e20, - 0xfa1cd8fd, 0x34701240, 0xb1a9849d, 0x17256aa0, 0x92fcfc7d, - 0x5c9036c0, 0xd949a01d, 0x814fd360, 0x049645bd, 0xcafa8f00, - 0x4f2319dd, 0x7af669fa, 0xff2fff27, 0x3143359a, 0xb49aa347, - 0xec9cd03a, 0x694546e7, 0xa7298c5a, 0x22f01a87, 0xcd836d14, - 0x485afbc9, 0x86363174, 0x03efa7a9, 0x5be9d4d4, 0xde304209, - 0x105c88b4, 0x95851e69, 0xa0506e4e, 0x2589f893, 0xebe5322e, - 0x6e3ca4f3, 0x363ad78e, 0xb3e34153, 0x7d8f8bee, 0xf8561d33, - 0xe26e1413, 0x67b782ce, 0xa9db4873, 0x2c02deae, 0x7404add3, - 0xf1dd3b0e, 0x3fb1f1b3, 0xba68676e, 0x8fbd1749, 0x0a648194, - 0xc4084b29, 0x41d1ddf4, 0x19d7ae89, 0x9c0e3854, 0x5262f2e9, - 0xd7bb6434, 0x38c813a7, 0xbd11857a, 0x737d4fc7, 0xf6a4d91a, - 0xaea2aa67, 0x2b7b3cba, 0xe517f607, 0x60ce60da, 0x551b10fd, - 0xd0c28620, 0x1eae4c9d, 0x9b77da40, 0xc371a93d, 0x46a83fe0, - 0x88c4f55d, 0x0d1d6380, 0xbcb4e71d, 0x396d71c0, 0xf701bb7d, - 0x72d82da0, 0x2ade5edd, 0xaf07c800, 0x616b02bd, 0xe4b29460, - 0xd167e447, 0x54be729a, 0x9ad2b827, 0x1f0b2efa, 0x470d5d87, - 0xc2d4cb5a, 0x0cb801e7, 0x8961973a, 0x6612e0a9, 0xe3cb7674, - 0x2da7bcc9, 0xa87e2a14, 0xf0785969, 0x75a1cfb4, 0xbbcd0509, - 0x3e1493d4, 0x0bc1e3f3, 0x8e18752e, 0x4074bf93, 0xc5ad294e, - 0x9dab5a33, 0x1872ccee, 0xd61e0653, 0x53c7908e, 0x49ff99ae, - 0xcc260f73, 0x024ac5ce, 0x87935313, 0xdf95206e, 0x5a4cb6b3, - 0x94207c0e, 0x11f9ead3, 0x242c9af4, 0xa1f50c29, 0x6f99c694, - 0xea405049, 0xb2462334, 0x379fb5e9, 0xf9f37f54, 0x7c2ae989, - 0x93599e1a, 0x168008c7, 0xd8ecc27a, 0x5d3554a7, 0x053327da, - 0x80eab107, 0x4e867bba, 0xcb5fed67, 0xfe8a9d40, 0x7b530b9d, - 0xb53fc120, 0x30e657fd, 0x68e02480, 0xed39b25d, 0x235578e0, - 0xa68cee3d}, - {0x00000000, 0x76e10f9d, 0xadc46ee1, 0xdb25617c, 0x1b8fac19, - 0x6d6ea384, 0xb64bc2f8, 0xc0aacd65, 0x361e5933, 0x40ff56ae, - 0x9bda37d2, 0xed3b384f, 0x2d91f52a, 0x5b70fab7, 0x80559bcb, - 0xf6b49456, 0x6c3cb266, 0x1addbdfb, 0xc1f8dc87, 0xb719d31a, - 0x77b31e7f, 0x015211e2, 0xda77709e, 0xac967f03, 0x5a22eb55, - 0x2cc3e4c8, 0xf7e685b4, 0x81078a29, 0x41ad474c, 0x374c48d1, - 0xec6929ad, 0x9a882630, 0xd87864cd, 0xae996b50, 0x75bc0a2c, - 0x035d05b1, 0xc3f7c8d4, 0xb516c749, 0x6e33a635, 0x18d2a9a8, - 0xee663dfe, 0x98873263, 0x43a2531f, 0x35435c82, 0xf5e991e7, - 0x83089e7a, 0x582dff06, 0x2eccf09b, 0xb444d6ab, 0xc2a5d936, - 0x1980b84a, 0x6f61b7d7, 0xafcb7ab2, 0xd92a752f, 0x020f1453, - 0x74ee1bce, 0x825a8f98, 0xf4bb8005, 0x2f9ee179, 0x597feee4, - 0x99d52381, 0xef342c1c, 0x34114d60, 0x42f042fd, 0xf1f7b941, - 0x8716b6dc, 0x5c33d7a0, 0x2ad2d83d, 0xea781558, 0x9c991ac5, - 0x47bc7bb9, 0x315d7424, 0xc7e9e072, 0xb108efef, 0x6a2d8e93, - 0x1ccc810e, 0xdc664c6b, 0xaa8743f6, 0x71a2228a, 0x07432d17, - 0x9dcb0b27, 0xeb2a04ba, 0x300f65c6, 0x46ee6a5b, 0x8644a73e, - 0xf0a5a8a3, 0x2b80c9df, 0x5d61c642, 0xabd55214, 0xdd345d89, - 0x06113cf5, 0x70f03368, 0xb05afe0d, 0xc6bbf190, 0x1d9e90ec, - 0x6b7f9f71, 0x298fdd8c, 0x5f6ed211, 0x844bb36d, 0xf2aabcf0, - 0x32007195, 0x44e17e08, 0x9fc41f74, 0xe92510e9, 0x1f9184bf, - 0x69708b22, 0xb255ea5e, 0xc4b4e5c3, 0x041e28a6, 0x72ff273b, - 0xa9da4647, 0xdf3b49da, 0x45b36fea, 0x33526077, 0xe877010b, - 0x9e960e96, 0x5e3cc3f3, 0x28ddcc6e, 0xf3f8ad12, 0x8519a28f, - 0x73ad36d9, 0x054c3944, 0xde695838, 0xa88857a5, 0x68229ac0, - 0x1ec3955d, 0xc5e6f421, 0xb307fbbc, 0xe2ef7383, 0x940e7c1e, - 0x4f2b1d62, 0x39ca12ff, 0xf960df9a, 0x8f81d007, 0x54a4b17b, - 0x2245bee6, 0xd4f12ab0, 0xa210252d, 0x79354451, 0x0fd44bcc, - 0xcf7e86a9, 0xb99f8934, 0x62bae848, 0x145be7d5, 0x8ed3c1e5, - 0xf832ce78, 0x2317af04, 0x55f6a099, 0x955c6dfc, 0xe3bd6261, - 0x3898031d, 0x4e790c80, 0xb8cd98d6, 0xce2c974b, 0x1509f637, - 0x63e8f9aa, 0xa34234cf, 0xd5a33b52, 0x0e865a2e, 0x786755b3, - 0x3a97174e, 0x4c7618d3, 0x975379af, 0xe1b27632, 0x2118bb57, - 0x57f9b4ca, 0x8cdcd5b6, 0xfa3dda2b, 0x0c894e7d, 0x7a6841e0, - 0xa14d209c, 0xd7ac2f01, 0x1706e264, 0x61e7edf9, 0xbac28c85, - 0xcc238318, 0x56aba528, 0x204aaab5, 0xfb6fcbc9, 0x8d8ec454, - 0x4d240931, 0x3bc506ac, 0xe0e067d0, 0x9601684d, 0x60b5fc1b, - 0x1654f386, 0xcd7192fa, 0xbb909d67, 0x7b3a5002, 0x0ddb5f9f, - 0xd6fe3ee3, 0xa01f317e, 0x1318cac2, 0x65f9c55f, 0xbedca423, - 0xc83dabbe, 0x089766db, 0x7e766946, 0xa553083a, 0xd3b207a7, - 0x250693f1, 0x53e79c6c, 0x88c2fd10, 0xfe23f28d, 0x3e893fe8, - 0x48683075, 0x934d5109, 0xe5ac5e94, 0x7f2478a4, 0x09c57739, - 0xd2e01645, 0xa40119d8, 0x64abd4bd, 0x124adb20, 0xc96fba5c, - 0xbf8eb5c1, 0x493a2197, 0x3fdb2e0a, 0xe4fe4f76, 0x921f40eb, - 0x52b58d8e, 0x24548213, 0xff71e36f, 0x8990ecf2, 0xcb60ae0f, - 0xbd81a192, 0x66a4c0ee, 0x1045cf73, 0xd0ef0216, 0xa60e0d8b, - 0x7d2b6cf7, 0x0bca636a, 0xfd7ef73c, 0x8b9ff8a1, 0x50ba99dd, - 0x265b9640, 0xe6f15b25, 0x901054b8, 0x4b3535c4, 0x3dd43a59, - 0xa75c1c69, 0xd1bd13f4, 0x0a987288, 0x7c797d15, 0xbcd3b070, - 0xca32bfed, 0x1117de91, 0x67f6d10c, 0x9142455a, 0xe7a34ac7, - 0x3c862bbb, 0x4a672426, 0x8acde943, 0xfc2ce6de, 0x270987a2, - 0x51e8883f}, - {0x00000000, 0xe8dbfbb9, 0x91b186a8, 0x796a7d11, 0x63657c8a, - 0x8bbe8733, 0xf2d4fa22, 0x1a0f019b, 0x87cc89cf, 0x6f177276, - 0x167d0f67, 0xfea6f4de, 0xe4a9f545, 0x0c720efc, 0x751873ed, - 0x9dc38854, 0x4f9f6244, 0xa74499fd, 0xde2ee4ec, 0x36f51f55, - 0x2cfa1ece, 0xc421e577, 0xbd4b9866, 0x559063df, 0xc853eb8b, - 0x20881032, 0x59e26d23, 0xb139969a, 0xab369701, 0x43ed6cb8, - 0x3a8711a9, 0xd25cea10, 0x9e3ec588, 0x76e53e31, 0x0f8f4320, - 0xe754b899, 0xfd5bb902, 0x158042bb, 0x6cea3faa, 0x8431c413, - 0x19f24c47, 0xf129b7fe, 0x8843caef, 0x60983156, 0x7a9730cd, - 0x924ccb74, 0xeb26b665, 0x03fd4ddc, 0xd1a1a7cc, 0x397a5c75, - 0x40102164, 0xa8cbdadd, 0xb2c4db46, 0x5a1f20ff, 0x23755dee, - 0xcbaea657, 0x566d2e03, 0xbeb6d5ba, 0xc7dca8ab, 0x2f075312, - 0x35085289, 0xddd3a930, 0xa4b9d421, 0x4c622f98, 0x7d7bfbca, - 0x95a00073, 0xecca7d62, 0x041186db, 0x1e1e8740, 0xf6c57cf9, - 0x8faf01e8, 0x6774fa51, 0xfab77205, 0x126c89bc, 0x6b06f4ad, - 0x83dd0f14, 0x99d20e8f, 0x7109f536, 0x08638827, 0xe0b8739e, - 0x32e4998e, 0xda3f6237, 0xa3551f26, 0x4b8ee49f, 0x5181e504, - 0xb95a1ebd, 0xc03063ac, 0x28eb9815, 0xb5281041, 0x5df3ebf8, - 0x249996e9, 0xcc426d50, 0xd64d6ccb, 0x3e969772, 0x47fcea63, - 0xaf2711da, 0xe3453e42, 0x0b9ec5fb, 0x72f4b8ea, 0x9a2f4353, - 0x802042c8, 0x68fbb971, 0x1191c460, 0xf94a3fd9, 0x6489b78d, - 0x8c524c34, 0xf5383125, 0x1de3ca9c, 0x07eccb07, 0xef3730be, - 0x965d4daf, 0x7e86b616, 0xacda5c06, 0x4401a7bf, 0x3d6bdaae, - 0xd5b02117, 0xcfbf208c, 0x2764db35, 0x5e0ea624, 0xb6d55d9d, - 0x2b16d5c9, 0xc3cd2e70, 0xbaa75361, 0x527ca8d8, 0x4873a943, - 0xa0a852fa, 0xd9c22feb, 0x3119d452, 0xbbf0874e, 0x532b7cf7, - 0x2a4101e6, 0xc29afa5f, 0xd895fbc4, 0x304e007d, 0x49247d6c, - 0xa1ff86d5, 0x3c3c0e81, 0xd4e7f538, 0xad8d8829, 0x45567390, - 0x5f59720b, 0xb78289b2, 0xcee8f4a3, 0x26330f1a, 0xf46fe50a, - 0x1cb41eb3, 0x65de63a2, 0x8d05981b, 0x970a9980, 0x7fd16239, - 0x06bb1f28, 0xee60e491, 0x73a36cc5, 0x9b78977c, 0xe212ea6d, - 0x0ac911d4, 0x10c6104f, 0xf81debf6, 0x817796e7, 0x69ac6d5e, - 0x25ce42c6, 0xcd15b97f, 0xb47fc46e, 0x5ca43fd7, 0x46ab3e4c, - 0xae70c5f5, 0xd71ab8e4, 0x3fc1435d, 0xa202cb09, 0x4ad930b0, - 0x33b34da1, 0xdb68b618, 0xc167b783, 0x29bc4c3a, 0x50d6312b, - 0xb80dca92, 0x6a512082, 0x828adb3b, 0xfbe0a62a, 0x133b5d93, - 0x09345c08, 0xe1efa7b1, 0x9885daa0, 0x705e2119, 0xed9da94d, - 0x054652f4, 0x7c2c2fe5, 0x94f7d45c, 0x8ef8d5c7, 0x66232e7e, - 0x1f49536f, 0xf792a8d6, 0xc68b7c84, 0x2e50873d, 0x573afa2c, - 0xbfe10195, 0xa5ee000e, 0x4d35fbb7, 0x345f86a6, 0xdc847d1f, - 0x4147f54b, 0xa99c0ef2, 0xd0f673e3, 0x382d885a, 0x222289c1, - 0xcaf97278, 0xb3930f69, 0x5b48f4d0, 0x89141ec0, 0x61cfe579, - 0x18a59868, 0xf07e63d1, 0xea71624a, 0x02aa99f3, 0x7bc0e4e2, - 0x931b1f5b, 0x0ed8970f, 0xe6036cb6, 0x9f6911a7, 0x77b2ea1e, - 0x6dbdeb85, 0x8566103c, 0xfc0c6d2d, 0x14d79694, 0x58b5b90c, - 0xb06e42b5, 0xc9043fa4, 0x21dfc41d, 0x3bd0c586, 0xd30b3e3f, - 0xaa61432e, 0x42bab897, 0xdf7930c3, 0x37a2cb7a, 0x4ec8b66b, - 0xa6134dd2, 0xbc1c4c49, 0x54c7b7f0, 0x2dadcae1, 0xc5763158, - 0x172adb48, 0xfff120f1, 0x869b5de0, 0x6e40a659, 0x744fa7c2, - 0x9c945c7b, 0xe5fe216a, 0x0d25dad3, 0x90e65287, 0x783da93e, - 0x0157d42f, 0xe98c2f96, 0xf3832e0d, 0x1b58d5b4, 0x6232a8a5, - 0x8ae9531c}, - {0x00000000, 0x919168ae, 0x6325a087, 0xf2b4c829, 0x874c31d4, - 0x16dd597a, 0xe4699153, 0x75f8f9fd, 0x4f9f1373, 0xde0e7bdd, - 0x2cbab3f4, 0xbd2bdb5a, 0xc8d322a7, 0x59424a09, 0xabf68220, - 0x3a67ea8e, 0x9e3e27e6, 0x0faf4f48, 0xfd1b8761, 0x6c8aefcf, - 0x19721632, 0x88e37e9c, 0x7a57b6b5, 0xebc6de1b, 0xd1a13495, - 0x40305c3b, 0xb2849412, 0x2315fcbc, 0x56ed0541, 0xc77c6def, - 0x35c8a5c6, 0xa459cd68, 0x7d7b3f17, 0xecea57b9, 0x1e5e9f90, - 0x8fcff73e, 0xfa370ec3, 0x6ba6666d, 0x9912ae44, 0x0883c6ea, - 0x32e42c64, 0xa37544ca, 0x51c18ce3, 0xc050e44d, 0xb5a81db0, - 0x2439751e, 0xd68dbd37, 0x471cd599, 0xe34518f1, 0x72d4705f, - 0x8060b876, 0x11f1d0d8, 0x64092925, 0xf598418b, 0x072c89a2, - 0x96bde10c, 0xacda0b82, 0x3d4b632c, 0xcfffab05, 0x5e6ec3ab, - 0x2b963a56, 0xba0752f8, 0x48b39ad1, 0xd922f27f, 0xfaf67e2e, - 0x6b671680, 0x99d3dea9, 0x0842b607, 0x7dba4ffa, 0xec2b2754, - 0x1e9fef7d, 0x8f0e87d3, 0xb5696d5d, 0x24f805f3, 0xd64ccdda, - 0x47dda574, 0x32255c89, 0xa3b43427, 0x5100fc0e, 0xc09194a0, - 0x64c859c8, 0xf5593166, 0x07edf94f, 0x967c91e1, 0xe384681c, - 0x721500b2, 0x80a1c89b, 0x1130a035, 0x2b574abb, 0xbac62215, - 0x4872ea3c, 0xd9e38292, 0xac1b7b6f, 0x3d8a13c1, 0xcf3edbe8, - 0x5eafb346, 0x878d4139, 0x161c2997, 0xe4a8e1be, 0x75398910, - 0x00c170ed, 0x91501843, 0x63e4d06a, 0xf275b8c4, 0xc812524a, - 0x59833ae4, 0xab37f2cd, 0x3aa69a63, 0x4f5e639e, 0xdecf0b30, - 0x2c7bc319, 0xbdeaabb7, 0x19b366df, 0x88220e71, 0x7a96c658, - 0xeb07aef6, 0x9eff570b, 0x0f6e3fa5, 0xfddaf78c, 0x6c4b9f22, - 0x562c75ac, 0xc7bd1d02, 0x3509d52b, 0xa498bd85, 0xd1604478, - 0x40f12cd6, 0xb245e4ff, 0x23d48c51, 0xf4edfd5c, 0x657c95f2, - 0x97c85ddb, 0x06593575, 0x73a1cc88, 0xe230a426, 0x10846c0f, - 0x811504a1, 0xbb72ee2f, 0x2ae38681, 0xd8574ea8, 0x49c62606, - 0x3c3edffb, 0xadafb755, 0x5f1b7f7c, 0xce8a17d2, 0x6ad3daba, - 0xfb42b214, 0x09f67a3d, 0x98671293, 0xed9feb6e, 0x7c0e83c0, - 0x8eba4be9, 0x1f2b2347, 0x254cc9c9, 0xb4dda167, 0x4669694e, - 0xd7f801e0, 0xa200f81d, 0x339190b3, 0xc125589a, 0x50b43034, - 0x8996c24b, 0x1807aae5, 0xeab362cc, 0x7b220a62, 0x0edaf39f, - 0x9f4b9b31, 0x6dff5318, 0xfc6e3bb6, 0xc609d138, 0x5798b996, - 0xa52c71bf, 0x34bd1911, 0x4145e0ec, 0xd0d48842, 0x2260406b, - 0xb3f128c5, 0x17a8e5ad, 0x86398d03, 0x748d452a, 0xe51c2d84, - 0x90e4d479, 0x0175bcd7, 0xf3c174fe, 0x62501c50, 0x5837f6de, - 0xc9a69e70, 0x3b125659, 0xaa833ef7, 0xdf7bc70a, 0x4eeaafa4, - 0xbc5e678d, 0x2dcf0f23, 0x0e1b8372, 0x9f8aebdc, 0x6d3e23f5, - 0xfcaf4b5b, 0x8957b2a6, 0x18c6da08, 0xea721221, 0x7be37a8f, - 0x41849001, 0xd015f8af, 0x22a13086, 0xb3305828, 0xc6c8a1d5, - 0x5759c97b, 0xa5ed0152, 0x347c69fc, 0x9025a494, 0x01b4cc3a, - 0xf3000413, 0x62916cbd, 0x17699540, 0x86f8fdee, 0x744c35c7, - 0xe5dd5d69, 0xdfbab7e7, 0x4e2bdf49, 0xbc9f1760, 0x2d0e7fce, - 0x58f68633, 0xc967ee9d, 0x3bd326b4, 0xaa424e1a, 0x7360bc65, - 0xe2f1d4cb, 0x10451ce2, 0x81d4744c, 0xf42c8db1, 0x65bde51f, - 0x97092d36, 0x06984598, 0x3cffaf16, 0xad6ec7b8, 0x5fda0f91, - 0xce4b673f, 0xbbb39ec2, 0x2a22f66c, 0xd8963e45, 0x490756eb, - 0xed5e9b83, 0x7ccff32d, 0x8e7b3b04, 0x1fea53aa, 0x6a12aa57, - 0xfb83c2f9, 0x09370ad0, 0x98a6627e, 0xa2c188f0, 0x3350e05e, - 0xc1e42877, 0x507540d9, 0x258db924, 0xb41cd18a, 0x46a819a3, - 0xd739710d}}; - -#endif - -#endif - -#if N == 5 - -#if W == 8 - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0xaf449247, 0x85f822cf, 0x2abcb088, 0xd08143df, - 0x7fc5d198, 0x55796110, 0xfa3df357, 0x7a7381ff, 0xd53713b8, - 0xff8ba330, 0x50cf3177, 0xaaf2c220, 0x05b65067, 0x2f0ae0ef, - 0x804e72a8, 0xf4e703fe, 0x5ba391b9, 0x711f2131, 0xde5bb376, - 0x24664021, 0x8b22d266, 0xa19e62ee, 0x0edaf0a9, 0x8e948201, - 0x21d01046, 0x0b6ca0ce, 0xa4283289, 0x5e15c1de, 0xf1515399, - 0xdbede311, 0x74a97156, 0x32bf01bd, 0x9dfb93fa, 0xb7472372, - 0x1803b135, 0xe23e4262, 0x4d7ad025, 0x67c660ad, 0xc882f2ea, - 0x48cc8042, 0xe7881205, 0xcd34a28d, 0x627030ca, 0x984dc39d, - 0x370951da, 0x1db5e152, 0xb2f17315, 0xc6580243, 0x691c9004, - 0x43a0208c, 0xece4b2cb, 0x16d9419c, 0xb99dd3db, 0x93216353, - 0x3c65f114, 0xbc2b83bc, 0x136f11fb, 0x39d3a173, 0x96973334, - 0x6caac063, 0xc3ee5224, 0xe952e2ac, 0x461670eb, 0x657e037a, - 0xca3a913d, 0xe08621b5, 0x4fc2b3f2, 0xb5ff40a5, 0x1abbd2e2, - 0x3007626a, 0x9f43f02d, 0x1f0d8285, 0xb04910c2, 0x9af5a04a, - 0x35b1320d, 0xcf8cc15a, 0x60c8531d, 0x4a74e395, 0xe53071d2, - 0x91990084, 0x3edd92c3, 0x1461224b, 0xbb25b00c, 0x4118435b, - 0xee5cd11c, 0xc4e06194, 0x6ba4f3d3, 0xebea817b, 0x44ae133c, - 0x6e12a3b4, 0xc15631f3, 0x3b6bc2a4, 0x942f50e3, 0xbe93e06b, - 0x11d7722c, 0x57c102c7, 0xf8859080, 0xd2392008, 0x7d7db24f, - 0x87404118, 0x2804d35f, 0x02b863d7, 0xadfcf190, 0x2db28338, - 0x82f6117f, 0xa84aa1f7, 0x070e33b0, 0xfd33c0e7, 0x527752a0, - 0x78cbe228, 0xd78f706f, 0xa3260139, 0x0c62937e, 0x26de23f6, - 0x899ab1b1, 0x73a742e6, 0xdce3d0a1, 0xf65f6029, 0x591bf26e, - 0xd95580c6, 0x76111281, 0x5cada209, 0xf3e9304e, 0x09d4c319, - 0xa690515e, 0x8c2ce1d6, 0x23687391, 0xcafc06f4, 0x65b894b3, - 0x4f04243b, 0xe040b67c, 0x1a7d452b, 0xb539d76c, 0x9f8567e4, - 0x30c1f5a3, 0xb08f870b, 0x1fcb154c, 0x3577a5c4, 0x9a333783, - 0x600ec4d4, 0xcf4a5693, 0xe5f6e61b, 0x4ab2745c, 0x3e1b050a, - 0x915f974d, 0xbbe327c5, 0x14a7b582, 0xee9a46d5, 0x41ded492, - 0x6b62641a, 0xc426f65d, 0x446884f5, 0xeb2c16b2, 0xc190a63a, - 0x6ed4347d, 0x94e9c72a, 0x3bad556d, 0x1111e5e5, 0xbe5577a2, - 0xf8430749, 0x5707950e, 0x7dbb2586, 0xd2ffb7c1, 0x28c24496, - 0x8786d6d1, 0xad3a6659, 0x027ef41e, 0x823086b6, 0x2d7414f1, - 0x07c8a479, 0xa88c363e, 0x52b1c569, 0xfdf5572e, 0xd749e7a6, - 0x780d75e1, 0x0ca404b7, 0xa3e096f0, 0x895c2678, 0x2618b43f, - 0xdc254768, 0x7361d52f, 0x59dd65a7, 0xf699f7e0, 0x76d78548, - 0xd993170f, 0xf32fa787, 0x5c6b35c0, 0xa656c697, 0x091254d0, - 0x23aee458, 0x8cea761f, 0xaf82058e, 0x00c697c9, 0x2a7a2741, - 0x853eb506, 0x7f034651, 0xd047d416, 0xfafb649e, 0x55bff6d9, - 0xd5f18471, 0x7ab51636, 0x5009a6be, 0xff4d34f9, 0x0570c7ae, - 0xaa3455e9, 0x8088e561, 0x2fcc7726, 0x5b650670, 0xf4219437, - 0xde9d24bf, 0x71d9b6f8, 0x8be445af, 0x24a0d7e8, 0x0e1c6760, - 0xa158f527, 0x2116878f, 0x8e5215c8, 0xa4eea540, 0x0baa3707, - 0xf197c450, 0x5ed35617, 0x746fe69f, 0xdb2b74d8, 0x9d3d0433, - 0x32799674, 0x18c526fc, 0xb781b4bb, 0x4dbc47ec, 0xe2f8d5ab, - 0xc8446523, 0x6700f764, 0xe74e85cc, 0x480a178b, 0x62b6a703, - 0xcdf23544, 0x37cfc613, 0x988b5454, 0xb237e4dc, 0x1d73769b, - 0x69da07cd, 0xc69e958a, 0xec222502, 0x4366b745, 0xb95b4412, - 0x161fd655, 0x3ca366dd, 0x93e7f49a, 0x13a98632, 0xbced1475, - 0x9651a4fd, 0x391536ba, 0xc328c5ed, 0x6c6c57aa, 0x46d0e722, - 0xe9947565}, - {0x00000000, 0x4e890ba9, 0x9d121752, 0xd39b1cfb, 0xe15528e5, - 0xafdc234c, 0x7c473fb7, 0x32ce341e, 0x19db578b, 0x57525c22, - 0x84c940d9, 0xca404b70, 0xf88e7f6e, 0xb60774c7, 0x659c683c, - 0x2b156395, 0x33b6af16, 0x7d3fa4bf, 0xaea4b844, 0xe02db3ed, - 0xd2e387f3, 0x9c6a8c5a, 0x4ff190a1, 0x01789b08, 0x2a6df89d, - 0x64e4f334, 0xb77fefcf, 0xf9f6e466, 0xcb38d078, 0x85b1dbd1, - 0x562ac72a, 0x18a3cc83, 0x676d5e2c, 0x29e45585, 0xfa7f497e, - 0xb4f642d7, 0x863876c9, 0xc8b17d60, 0x1b2a619b, 0x55a36a32, - 0x7eb609a7, 0x303f020e, 0xe3a41ef5, 0xad2d155c, 0x9fe32142, - 0xd16a2aeb, 0x02f13610, 0x4c783db9, 0x54dbf13a, 0x1a52fa93, - 0xc9c9e668, 0x8740edc1, 0xb58ed9df, 0xfb07d276, 0x289cce8d, - 0x6615c524, 0x4d00a6b1, 0x0389ad18, 0xd012b1e3, 0x9e9bba4a, - 0xac558e54, 0xe2dc85fd, 0x31479906, 0x7fce92af, 0xcedabc58, - 0x8053b7f1, 0x53c8ab0a, 0x1d41a0a3, 0x2f8f94bd, 0x61069f14, - 0xb29d83ef, 0xfc148846, 0xd701ebd3, 0x9988e07a, 0x4a13fc81, - 0x049af728, 0x3654c336, 0x78ddc89f, 0xab46d464, 0xe5cfdfcd, - 0xfd6c134e, 0xb3e518e7, 0x607e041c, 0x2ef70fb5, 0x1c393bab, - 0x52b03002, 0x812b2cf9, 0xcfa22750, 0xe4b744c5, 0xaa3e4f6c, - 0x79a55397, 0x372c583e, 0x05e26c20, 0x4b6b6789, 0x98f07b72, - 0xd67970db, 0xa9b7e274, 0xe73ee9dd, 0x34a5f526, 0x7a2cfe8f, - 0x48e2ca91, 0x066bc138, 0xd5f0ddc3, 0x9b79d66a, 0xb06cb5ff, - 0xfee5be56, 0x2d7ea2ad, 0x63f7a904, 0x51399d1a, 0x1fb096b3, - 0xcc2b8a48, 0x82a281e1, 0x9a014d62, 0xd48846cb, 0x07135a30, - 0x499a5199, 0x7b546587, 0x35dd6e2e, 0xe64672d5, 0xa8cf797c, - 0x83da1ae9, 0xcd531140, 0x1ec80dbb, 0x50410612, 0x628f320c, - 0x2c0639a5, 0xff9d255e, 0xb1142ef7, 0x46c47ef1, 0x084d7558, - 0xdbd669a3, 0x955f620a, 0xa7915614, 0xe9185dbd, 0x3a834146, - 0x740a4aef, 0x5f1f297a, 0x119622d3, 0xc20d3e28, 0x8c843581, - 0xbe4a019f, 0xf0c30a36, 0x235816cd, 0x6dd11d64, 0x7572d1e7, - 0x3bfbda4e, 0xe860c6b5, 0xa6e9cd1c, 0x9427f902, 0xdaaef2ab, - 0x0935ee50, 0x47bce5f9, 0x6ca9866c, 0x22208dc5, 0xf1bb913e, - 0xbf329a97, 0x8dfcae89, 0xc375a520, 0x10eeb9db, 0x5e67b272, - 0x21a920dd, 0x6f202b74, 0xbcbb378f, 0xf2323c26, 0xc0fc0838, - 0x8e750391, 0x5dee1f6a, 0x136714c3, 0x38727756, 0x76fb7cff, - 0xa5606004, 0xebe96bad, 0xd9275fb3, 0x97ae541a, 0x443548e1, - 0x0abc4348, 0x121f8fcb, 0x5c968462, 0x8f0d9899, 0xc1849330, - 0xf34aa72e, 0xbdc3ac87, 0x6e58b07c, 0x20d1bbd5, 0x0bc4d840, - 0x454dd3e9, 0x96d6cf12, 0xd85fc4bb, 0xea91f0a5, 0xa418fb0c, - 0x7783e7f7, 0x390aec5e, 0x881ec2a9, 0xc697c900, 0x150cd5fb, - 0x5b85de52, 0x694bea4c, 0x27c2e1e5, 0xf459fd1e, 0xbad0f6b7, - 0x91c59522, 0xdf4c9e8b, 0x0cd78270, 0x425e89d9, 0x7090bdc7, - 0x3e19b66e, 0xed82aa95, 0xa30ba13c, 0xbba86dbf, 0xf5216616, - 0x26ba7aed, 0x68337144, 0x5afd455a, 0x14744ef3, 0xc7ef5208, - 0x896659a1, 0xa2733a34, 0xecfa319d, 0x3f612d66, 0x71e826cf, - 0x432612d1, 0x0daf1978, 0xde340583, 0x90bd0e2a, 0xef739c85, - 0xa1fa972c, 0x72618bd7, 0x3ce8807e, 0x0e26b460, 0x40afbfc9, - 0x9334a332, 0xddbda89b, 0xf6a8cb0e, 0xb821c0a7, 0x6bbadc5c, - 0x2533d7f5, 0x17fde3eb, 0x5974e842, 0x8aeff4b9, 0xc466ff10, - 0xdcc53393, 0x924c383a, 0x41d724c1, 0x0f5e2f68, 0x3d901b76, - 0x731910df, 0xa0820c24, 0xee0b078d, 0xc51e6418, 0x8b976fb1, - 0x580c734a, 0x168578e3, 0x244b4cfd, 0x6ac24754, 0xb9595baf, - 0xf7d05006}, - {0x00000000, 0x8d88fde2, 0xc060fd85, 0x4de80067, 0x5bb0fd4b, - 0xd63800a9, 0x9bd000ce, 0x1658fd2c, 0xb761fa96, 0x3ae90774, - 0x77010713, 0xfa89faf1, 0xecd107dd, 0x6159fa3f, 0x2cb1fa58, - 0xa13907ba, 0xb5b2f36d, 0x383a0e8f, 0x75d20ee8, 0xf85af30a, - 0xee020e26, 0x638af3c4, 0x2e62f3a3, 0xa3ea0e41, 0x02d309fb, - 0x8f5bf419, 0xc2b3f47e, 0x4f3b099c, 0x5963f4b0, 0xd4eb0952, - 0x99030935, 0x148bf4d7, 0xb014e09b, 0x3d9c1d79, 0x70741d1e, - 0xfdfce0fc, 0xeba41dd0, 0x662ce032, 0x2bc4e055, 0xa64c1db7, - 0x07751a0d, 0x8afde7ef, 0xc715e788, 0x4a9d1a6a, 0x5cc5e746, - 0xd14d1aa4, 0x9ca51ac3, 0x112de721, 0x05a613f6, 0x882eee14, - 0xc5c6ee73, 0x484e1391, 0x5e16eebd, 0xd39e135f, 0x9e761338, - 0x13feeeda, 0xb2c7e960, 0x3f4f1482, 0x72a714e5, 0xff2fe907, - 0xe977142b, 0x64ffe9c9, 0x2917e9ae, 0xa49f144c, 0xbb58c777, - 0x36d03a95, 0x7b383af2, 0xf6b0c710, 0xe0e83a3c, 0x6d60c7de, - 0x2088c7b9, 0xad003a5b, 0x0c393de1, 0x81b1c003, 0xcc59c064, - 0x41d13d86, 0x5789c0aa, 0xda013d48, 0x97e93d2f, 0x1a61c0cd, - 0x0eea341a, 0x8362c9f8, 0xce8ac99f, 0x4302347d, 0x555ac951, - 0xd8d234b3, 0x953a34d4, 0x18b2c936, 0xb98bce8c, 0x3403336e, - 0x79eb3309, 0xf463ceeb, 0xe23b33c7, 0x6fb3ce25, 0x225bce42, - 0xafd333a0, 0x0b4c27ec, 0x86c4da0e, 0xcb2cda69, 0x46a4278b, - 0x50fcdaa7, 0xdd742745, 0x909c2722, 0x1d14dac0, 0xbc2ddd7a, - 0x31a52098, 0x7c4d20ff, 0xf1c5dd1d, 0xe79d2031, 0x6a15ddd3, - 0x27fdddb4, 0xaa752056, 0xbefed481, 0x33762963, 0x7e9e2904, - 0xf316d4e6, 0xe54e29ca, 0x68c6d428, 0x252ed44f, 0xa8a629ad, - 0x099f2e17, 0x8417d3f5, 0xc9ffd392, 0x44772e70, 0x522fd35c, - 0xdfa72ebe, 0x924f2ed9, 0x1fc7d33b, 0xadc088af, 0x2048754d, - 0x6da0752a, 0xe02888c8, 0xf67075e4, 0x7bf88806, 0x36108861, - 0xbb987583, 0x1aa17239, 0x97298fdb, 0xdac18fbc, 0x5749725e, - 0x41118f72, 0xcc997290, 0x817172f7, 0x0cf98f15, 0x18727bc2, - 0x95fa8620, 0xd8128647, 0x559a7ba5, 0x43c28689, 0xce4a7b6b, - 0x83a27b0c, 0x0e2a86ee, 0xaf138154, 0x229b7cb6, 0x6f737cd1, - 0xe2fb8133, 0xf4a37c1f, 0x792b81fd, 0x34c3819a, 0xb94b7c78, - 0x1dd46834, 0x905c95d6, 0xddb495b1, 0x503c6853, 0x4664957f, - 0xcbec689d, 0x860468fa, 0x0b8c9518, 0xaab592a2, 0x273d6f40, - 0x6ad56f27, 0xe75d92c5, 0xf1056fe9, 0x7c8d920b, 0x3165926c, - 0xbced6f8e, 0xa8669b59, 0x25ee66bb, 0x680666dc, 0xe58e9b3e, - 0xf3d66612, 0x7e5e9bf0, 0x33b69b97, 0xbe3e6675, 0x1f0761cf, - 0x928f9c2d, 0xdf679c4a, 0x52ef61a8, 0x44b79c84, 0xc93f6166, - 0x84d76101, 0x095f9ce3, 0x16984fd8, 0x9b10b23a, 0xd6f8b25d, - 0x5b704fbf, 0x4d28b293, 0xc0a04f71, 0x8d484f16, 0x00c0b2f4, - 0xa1f9b54e, 0x2c7148ac, 0x619948cb, 0xec11b529, 0xfa494805, - 0x77c1b5e7, 0x3a29b580, 0xb7a14862, 0xa32abcb5, 0x2ea24157, - 0x634a4130, 0xeec2bcd2, 0xf89a41fe, 0x7512bc1c, 0x38fabc7b, - 0xb5724199, 0x144b4623, 0x99c3bbc1, 0xd42bbba6, 0x59a34644, - 0x4ffbbb68, 0xc273468a, 0x8f9b46ed, 0x0213bb0f, 0xa68caf43, - 0x2b0452a1, 0x66ec52c6, 0xeb64af24, 0xfd3c5208, 0x70b4afea, - 0x3d5caf8d, 0xb0d4526f, 0x11ed55d5, 0x9c65a837, 0xd18da850, - 0x5c0555b2, 0x4a5da89e, 0xc7d5557c, 0x8a3d551b, 0x07b5a8f9, - 0x133e5c2e, 0x9eb6a1cc, 0xd35ea1ab, 0x5ed65c49, 0x488ea165, - 0xc5065c87, 0x88ee5ce0, 0x0566a102, 0xa45fa6b8, 0x29d75b5a, - 0x643f5b3d, 0xe9b7a6df, 0xffef5bf3, 0x7267a611, 0x3f8fa676, - 0xb2075b94}, - {0x00000000, 0x80f0171f, 0xda91287f, 0x5a613f60, 0x6e5356bf, - 0xeea341a0, 0xb4c27ec0, 0x343269df, 0xdca6ad7e, 0x5c56ba61, - 0x06378501, 0x86c7921e, 0xb2f5fbc1, 0x3205ecde, 0x6864d3be, - 0xe894c4a1, 0x623c5cbd, 0xe2cc4ba2, 0xb8ad74c2, 0x385d63dd, - 0x0c6f0a02, 0x8c9f1d1d, 0xd6fe227d, 0x560e3562, 0xbe9af1c3, - 0x3e6ae6dc, 0x640bd9bc, 0xe4fbcea3, 0xd0c9a77c, 0x5039b063, - 0x0a588f03, 0x8aa8981c, 0xc478b97a, 0x4488ae65, 0x1ee99105, - 0x9e19861a, 0xaa2befc5, 0x2adbf8da, 0x70bac7ba, 0xf04ad0a5, - 0x18de1404, 0x982e031b, 0xc24f3c7b, 0x42bf2b64, 0x768d42bb, - 0xf67d55a4, 0xac1c6ac4, 0x2cec7ddb, 0xa644e5c7, 0x26b4f2d8, - 0x7cd5cdb8, 0xfc25daa7, 0xc817b378, 0x48e7a467, 0x12869b07, - 0x92768c18, 0x7ae248b9, 0xfa125fa6, 0xa07360c6, 0x208377d9, - 0x14b11e06, 0x94410919, 0xce203679, 0x4ed02166, 0x538074b5, - 0xd37063aa, 0x89115cca, 0x09e14bd5, 0x3dd3220a, 0xbd233515, - 0xe7420a75, 0x67b21d6a, 0x8f26d9cb, 0x0fd6ced4, 0x55b7f1b4, - 0xd547e6ab, 0xe1758f74, 0x6185986b, 0x3be4a70b, 0xbb14b014, - 0x31bc2808, 0xb14c3f17, 0xeb2d0077, 0x6bdd1768, 0x5fef7eb7, - 0xdf1f69a8, 0x857e56c8, 0x058e41d7, 0xed1a8576, 0x6dea9269, - 0x378bad09, 0xb77bba16, 0x8349d3c9, 0x03b9c4d6, 0x59d8fbb6, - 0xd928eca9, 0x97f8cdcf, 0x1708dad0, 0x4d69e5b0, 0xcd99f2af, - 0xf9ab9b70, 0x795b8c6f, 0x233ab30f, 0xa3caa410, 0x4b5e60b1, - 0xcbae77ae, 0x91cf48ce, 0x113f5fd1, 0x250d360e, 0xa5fd2111, - 0xff9c1e71, 0x7f6c096e, 0xf5c49172, 0x7534866d, 0x2f55b90d, - 0xafa5ae12, 0x9b97c7cd, 0x1b67d0d2, 0x4106efb2, 0xc1f6f8ad, - 0x29623c0c, 0xa9922b13, 0xf3f31473, 0x7303036c, 0x47316ab3, - 0xc7c17dac, 0x9da042cc, 0x1d5055d3, 0xa700e96a, 0x27f0fe75, - 0x7d91c115, 0xfd61d60a, 0xc953bfd5, 0x49a3a8ca, 0x13c297aa, - 0x933280b5, 0x7ba64414, 0xfb56530b, 0xa1376c6b, 0x21c77b74, - 0x15f512ab, 0x950505b4, 0xcf643ad4, 0x4f942dcb, 0xc53cb5d7, - 0x45cca2c8, 0x1fad9da8, 0x9f5d8ab7, 0xab6fe368, 0x2b9ff477, - 0x71fecb17, 0xf10edc08, 0x199a18a9, 0x996a0fb6, 0xc30b30d6, - 0x43fb27c9, 0x77c94e16, 0xf7395909, 0xad586669, 0x2da87176, - 0x63785010, 0xe388470f, 0xb9e9786f, 0x39196f70, 0x0d2b06af, - 0x8ddb11b0, 0xd7ba2ed0, 0x574a39cf, 0xbfdefd6e, 0x3f2eea71, - 0x654fd511, 0xe5bfc20e, 0xd18dabd1, 0x517dbcce, 0x0b1c83ae, - 0x8bec94b1, 0x01440cad, 0x81b41bb2, 0xdbd524d2, 0x5b2533cd, - 0x6f175a12, 0xefe74d0d, 0xb586726d, 0x35766572, 0xdde2a1d3, - 0x5d12b6cc, 0x077389ac, 0x87839eb3, 0xb3b1f76c, 0x3341e073, - 0x6920df13, 0xe9d0c80c, 0xf4809ddf, 0x74708ac0, 0x2e11b5a0, - 0xaee1a2bf, 0x9ad3cb60, 0x1a23dc7f, 0x4042e31f, 0xc0b2f400, - 0x282630a1, 0xa8d627be, 0xf2b718de, 0x72470fc1, 0x4675661e, - 0xc6857101, 0x9ce44e61, 0x1c14597e, 0x96bcc162, 0x164cd67d, - 0x4c2de91d, 0xccddfe02, 0xf8ef97dd, 0x781f80c2, 0x227ebfa2, - 0xa28ea8bd, 0x4a1a6c1c, 0xcaea7b03, 0x908b4463, 0x107b537c, - 0x24493aa3, 0xa4b92dbc, 0xfed812dc, 0x7e2805c3, 0x30f824a5, - 0xb00833ba, 0xea690cda, 0x6a991bc5, 0x5eab721a, 0xde5b6505, - 0x843a5a65, 0x04ca4d7a, 0xec5e89db, 0x6cae9ec4, 0x36cfa1a4, - 0xb63fb6bb, 0x820ddf64, 0x02fdc87b, 0x589cf71b, 0xd86ce004, - 0x52c47818, 0xd2346f07, 0x88555067, 0x08a54778, 0x3c972ea7, - 0xbc6739b8, 0xe60606d8, 0x66f611c7, 0x8e62d566, 0x0e92c279, - 0x54f3fd19, 0xd403ea06, 0xe03183d9, 0x60c194c6, 0x3aa0aba6, - 0xba50bcb9}, - {0x00000000, 0x9570d495, 0xf190af6b, 0x64e07bfe, 0x38505897, - 0xad208c02, 0xc9c0f7fc, 0x5cb02369, 0x70a0b12e, 0xe5d065bb, - 0x81301e45, 0x1440cad0, 0x48f0e9b9, 0xdd803d2c, 0xb96046d2, - 0x2c109247, 0xe141625c, 0x7431b6c9, 0x10d1cd37, 0x85a119a2, - 0xd9113acb, 0x4c61ee5e, 0x288195a0, 0xbdf14135, 0x91e1d372, - 0x049107e7, 0x60717c19, 0xf501a88c, 0xa9b18be5, 0x3cc15f70, - 0x5821248e, 0xcd51f01b, 0x19f3c2f9, 0x8c83166c, 0xe8636d92, - 0x7d13b907, 0x21a39a6e, 0xb4d34efb, 0xd0333505, 0x4543e190, - 0x695373d7, 0xfc23a742, 0x98c3dcbc, 0x0db30829, 0x51032b40, - 0xc473ffd5, 0xa093842b, 0x35e350be, 0xf8b2a0a5, 0x6dc27430, - 0x09220fce, 0x9c52db5b, 0xc0e2f832, 0x55922ca7, 0x31725759, - 0xa40283cc, 0x8812118b, 0x1d62c51e, 0x7982bee0, 0xecf26a75, - 0xb042491c, 0x25329d89, 0x41d2e677, 0xd4a232e2, 0x33e785f2, - 0xa6975167, 0xc2772a99, 0x5707fe0c, 0x0bb7dd65, 0x9ec709f0, - 0xfa27720e, 0x6f57a69b, 0x434734dc, 0xd637e049, 0xb2d79bb7, - 0x27a74f22, 0x7b176c4b, 0xee67b8de, 0x8a87c320, 0x1ff717b5, - 0xd2a6e7ae, 0x47d6333b, 0x233648c5, 0xb6469c50, 0xeaf6bf39, - 0x7f866bac, 0x1b661052, 0x8e16c4c7, 0xa2065680, 0x37768215, - 0x5396f9eb, 0xc6e62d7e, 0x9a560e17, 0x0f26da82, 0x6bc6a17c, - 0xfeb675e9, 0x2a14470b, 0xbf64939e, 0xdb84e860, 0x4ef43cf5, - 0x12441f9c, 0x8734cb09, 0xe3d4b0f7, 0x76a46462, 0x5ab4f625, - 0xcfc422b0, 0xab24594e, 0x3e548ddb, 0x62e4aeb2, 0xf7947a27, - 0x937401d9, 0x0604d54c, 0xcb552557, 0x5e25f1c2, 0x3ac58a3c, - 0xafb55ea9, 0xf3057dc0, 0x6675a955, 0x0295d2ab, 0x97e5063e, - 0xbbf59479, 0x2e8540ec, 0x4a653b12, 0xdf15ef87, 0x83a5ccee, - 0x16d5187b, 0x72356385, 0xe745b710, 0x67cf0be4, 0xf2bfdf71, - 0x965fa48f, 0x032f701a, 0x5f9f5373, 0xcaef87e6, 0xae0ffc18, - 0x3b7f288d, 0x176fbaca, 0x821f6e5f, 0xe6ff15a1, 0x738fc134, - 0x2f3fe25d, 0xba4f36c8, 0xdeaf4d36, 0x4bdf99a3, 0x868e69b8, - 0x13febd2d, 0x771ec6d3, 0xe26e1246, 0xbede312f, 0x2baee5ba, - 0x4f4e9e44, 0xda3e4ad1, 0xf62ed896, 0x635e0c03, 0x07be77fd, - 0x92cea368, 0xce7e8001, 0x5b0e5494, 0x3fee2f6a, 0xaa9efbff, - 0x7e3cc91d, 0xeb4c1d88, 0x8fac6676, 0x1adcb2e3, 0x466c918a, - 0xd31c451f, 0xb7fc3ee1, 0x228cea74, 0x0e9c7833, 0x9becaca6, - 0xff0cd758, 0x6a7c03cd, 0x36cc20a4, 0xa3bcf431, 0xc75c8fcf, - 0x522c5b5a, 0x9f7dab41, 0x0a0d7fd4, 0x6eed042a, 0xfb9dd0bf, - 0xa72df3d6, 0x325d2743, 0x56bd5cbd, 0xc3cd8828, 0xefdd1a6f, - 0x7aadcefa, 0x1e4db504, 0x8b3d6191, 0xd78d42f8, 0x42fd966d, - 0x261ded93, 0xb36d3906, 0x54288e16, 0xc1585a83, 0xa5b8217d, - 0x30c8f5e8, 0x6c78d681, 0xf9080214, 0x9de879ea, 0x0898ad7f, - 0x24883f38, 0xb1f8ebad, 0xd5189053, 0x406844c6, 0x1cd867af, - 0x89a8b33a, 0xed48c8c4, 0x78381c51, 0xb569ec4a, 0x201938df, - 0x44f94321, 0xd18997b4, 0x8d39b4dd, 0x18496048, 0x7ca91bb6, - 0xe9d9cf23, 0xc5c95d64, 0x50b989f1, 0x3459f20f, 0xa129269a, - 0xfd9905f3, 0x68e9d166, 0x0c09aa98, 0x99797e0d, 0x4ddb4cef, - 0xd8ab987a, 0xbc4be384, 0x293b3711, 0x758b1478, 0xe0fbc0ed, - 0x841bbb13, 0x116b6f86, 0x3d7bfdc1, 0xa80b2954, 0xcceb52aa, - 0x599b863f, 0x052ba556, 0x905b71c3, 0xf4bb0a3d, 0x61cbdea8, - 0xac9a2eb3, 0x39eafa26, 0x5d0a81d8, 0xc87a554d, 0x94ca7624, - 0x01baa2b1, 0x655ad94f, 0xf02a0dda, 0xdc3a9f9d, 0x494a4b08, - 0x2daa30f6, 0xb8dae463, 0xe46ac70a, 0x711a139f, 0x15fa6861, - 0x808abcf4}, - {0x00000000, 0xcf9e17c8, 0x444d29d1, 0x8bd33e19, 0x889a53a2, - 0x4704446a, 0xccd77a73, 0x03496dbb, 0xca45a105, 0x05dbb6cd, - 0x8e0888d4, 0x41969f1c, 0x42dff2a7, 0x8d41e56f, 0x0692db76, - 0xc90cccbe, 0x4ffa444b, 0x80645383, 0x0bb76d9a, 0xc4297a52, - 0xc76017e9, 0x08fe0021, 0x832d3e38, 0x4cb329f0, 0x85bfe54e, - 0x4a21f286, 0xc1f2cc9f, 0x0e6cdb57, 0x0d25b6ec, 0xc2bba124, - 0x49689f3d, 0x86f688f5, 0x9ff48896, 0x506a9f5e, 0xdbb9a147, - 0x1427b68f, 0x176edb34, 0xd8f0ccfc, 0x5323f2e5, 0x9cbde52d, - 0x55b12993, 0x9a2f3e5b, 0x11fc0042, 0xde62178a, 0xdd2b7a31, - 0x12b56df9, 0x996653e0, 0x56f84428, 0xd00eccdd, 0x1f90db15, - 0x9443e50c, 0x5bddf2c4, 0x58949f7f, 0x970a88b7, 0x1cd9b6ae, - 0xd347a166, 0x1a4b6dd8, 0xd5d57a10, 0x5e064409, 0x919853c1, - 0x92d13e7a, 0x5d4f29b2, 0xd69c17ab, 0x19020063, 0xe498176d, - 0x2b0600a5, 0xa0d53ebc, 0x6f4b2974, 0x6c0244cf, 0xa39c5307, - 0x284f6d1e, 0xe7d17ad6, 0x2eddb668, 0xe143a1a0, 0x6a909fb9, - 0xa50e8871, 0xa647e5ca, 0x69d9f202, 0xe20acc1b, 0x2d94dbd3, - 0xab625326, 0x64fc44ee, 0xef2f7af7, 0x20b16d3f, 0x23f80084, - 0xec66174c, 0x67b52955, 0xa82b3e9d, 0x6127f223, 0xaeb9e5eb, - 0x256adbf2, 0xeaf4cc3a, 0xe9bda181, 0x2623b649, 0xadf08850, - 0x626e9f98, 0x7b6c9ffb, 0xb4f28833, 0x3f21b62a, 0xf0bfa1e2, - 0xf3f6cc59, 0x3c68db91, 0xb7bbe588, 0x7825f240, 0xb1293efe, - 0x7eb72936, 0xf564172f, 0x3afa00e7, 0x39b36d5c, 0xf62d7a94, - 0x7dfe448d, 0xb2605345, 0x3496dbb0, 0xfb08cc78, 0x70dbf261, - 0xbf45e5a9, 0xbc0c8812, 0x73929fda, 0xf841a1c3, 0x37dfb60b, - 0xfed37ab5, 0x314d6d7d, 0xba9e5364, 0x750044ac, 0x76492917, - 0xb9d73edf, 0x320400c6, 0xfd9a170e, 0x1241289b, 0xdddf3f53, - 0x560c014a, 0x99921682, 0x9adb7b39, 0x55456cf1, 0xde9652e8, - 0x11084520, 0xd804899e, 0x179a9e56, 0x9c49a04f, 0x53d7b787, - 0x509eda3c, 0x9f00cdf4, 0x14d3f3ed, 0xdb4de425, 0x5dbb6cd0, - 0x92257b18, 0x19f64501, 0xd66852c9, 0xd5213f72, 0x1abf28ba, - 0x916c16a3, 0x5ef2016b, 0x97fecdd5, 0x5860da1d, 0xd3b3e404, - 0x1c2df3cc, 0x1f649e77, 0xd0fa89bf, 0x5b29b7a6, 0x94b7a06e, - 0x8db5a00d, 0x422bb7c5, 0xc9f889dc, 0x06669e14, 0x052ff3af, - 0xcab1e467, 0x4162da7e, 0x8efccdb6, 0x47f00108, 0x886e16c0, - 0x03bd28d9, 0xcc233f11, 0xcf6a52aa, 0x00f44562, 0x8b277b7b, - 0x44b96cb3, 0xc24fe446, 0x0dd1f38e, 0x8602cd97, 0x499cda5f, - 0x4ad5b7e4, 0x854ba02c, 0x0e989e35, 0xc10689fd, 0x080a4543, - 0xc794528b, 0x4c476c92, 0x83d97b5a, 0x809016e1, 0x4f0e0129, - 0xc4dd3f30, 0x0b4328f8, 0xf6d93ff6, 0x3947283e, 0xb2941627, - 0x7d0a01ef, 0x7e436c54, 0xb1dd7b9c, 0x3a0e4585, 0xf590524d, - 0x3c9c9ef3, 0xf302893b, 0x78d1b722, 0xb74fa0ea, 0xb406cd51, - 0x7b98da99, 0xf04be480, 0x3fd5f348, 0xb9237bbd, 0x76bd6c75, - 0xfd6e526c, 0x32f045a4, 0x31b9281f, 0xfe273fd7, 0x75f401ce, - 0xba6a1606, 0x7366dab8, 0xbcf8cd70, 0x372bf369, 0xf8b5e4a1, - 0xfbfc891a, 0x34629ed2, 0xbfb1a0cb, 0x702fb703, 0x692db760, - 0xa6b3a0a8, 0x2d609eb1, 0xe2fe8979, 0xe1b7e4c2, 0x2e29f30a, - 0xa5facd13, 0x6a64dadb, 0xa3681665, 0x6cf601ad, 0xe7253fb4, - 0x28bb287c, 0x2bf245c7, 0xe46c520f, 0x6fbf6c16, 0xa0217bde, - 0x26d7f32b, 0xe949e4e3, 0x629adafa, 0xad04cd32, 0xae4da089, - 0x61d3b741, 0xea008958, 0x259e9e90, 0xec92522e, 0x230c45e6, - 0xa8df7bff, 0x67416c37, 0x6408018c, 0xab961644, 0x2045285d, - 0xefdb3f95}, - {0x00000000, 0x24825136, 0x4904a26c, 0x6d86f35a, 0x920944d8, - 0xb68b15ee, 0xdb0de6b4, 0xff8fb782, 0xff638ff1, 0xdbe1dec7, - 0xb6672d9d, 0x92e57cab, 0x6d6acb29, 0x49e89a1f, 0x246e6945, - 0x00ec3873, 0x25b619a3, 0x01344895, 0x6cb2bbcf, 0x4830eaf9, - 0xb7bf5d7b, 0x933d0c4d, 0xfebbff17, 0xda39ae21, 0xdad59652, - 0xfe57c764, 0x93d1343e, 0xb7536508, 0x48dcd28a, 0x6c5e83bc, - 0x01d870e6, 0x255a21d0, 0x4b6c3346, 0x6fee6270, 0x0268912a, - 0x26eac01c, 0xd965779e, 0xfde726a8, 0x9061d5f2, 0xb4e384c4, - 0xb40fbcb7, 0x908ded81, 0xfd0b1edb, 0xd9894fed, 0x2606f86f, - 0x0284a959, 0x6f025a03, 0x4b800b35, 0x6eda2ae5, 0x4a587bd3, - 0x27de8889, 0x035cd9bf, 0xfcd36e3d, 0xd8513f0b, 0xb5d7cc51, - 0x91559d67, 0x91b9a514, 0xb53bf422, 0xd8bd0778, 0xfc3f564e, - 0x03b0e1cc, 0x2732b0fa, 0x4ab443a0, 0x6e361296, 0x96d8668c, - 0xb25a37ba, 0xdfdcc4e0, 0xfb5e95d6, 0x04d12254, 0x20537362, - 0x4dd58038, 0x6957d10e, 0x69bbe97d, 0x4d39b84b, 0x20bf4b11, - 0x043d1a27, 0xfbb2ada5, 0xdf30fc93, 0xb2b60fc9, 0x96345eff, - 0xb36e7f2f, 0x97ec2e19, 0xfa6add43, 0xdee88c75, 0x21673bf7, - 0x05e56ac1, 0x6863999b, 0x4ce1c8ad, 0x4c0df0de, 0x688fa1e8, - 0x050952b2, 0x218b0384, 0xde04b406, 0xfa86e530, 0x9700166a, - 0xb382475c, 0xddb455ca, 0xf93604fc, 0x94b0f7a6, 0xb032a690, - 0x4fbd1112, 0x6b3f4024, 0x06b9b37e, 0x223be248, 0x22d7da3b, - 0x06558b0d, 0x6bd37857, 0x4f512961, 0xb0de9ee3, 0x945ccfd5, - 0xf9da3c8f, 0xdd586db9, 0xf8024c69, 0xdc801d5f, 0xb106ee05, - 0x9584bf33, 0x6a0b08b1, 0x4e895987, 0x230faadd, 0x078dfbeb, - 0x0761c398, 0x23e392ae, 0x4e6561f4, 0x6ae730c2, 0x95688740, - 0xb1ead676, 0xdc6c252c, 0xf8ee741a, 0xf6c1cb59, 0xd2439a6f, - 0xbfc56935, 0x9b473803, 0x64c88f81, 0x404adeb7, 0x2dcc2ded, - 0x094e7cdb, 0x09a244a8, 0x2d20159e, 0x40a6e6c4, 0x6424b7f2, - 0x9bab0070, 0xbf295146, 0xd2afa21c, 0xf62df32a, 0xd377d2fa, - 0xf7f583cc, 0x9a737096, 0xbef121a0, 0x417e9622, 0x65fcc714, - 0x087a344e, 0x2cf86578, 0x2c145d0b, 0x08960c3d, 0x6510ff67, - 0x4192ae51, 0xbe1d19d3, 0x9a9f48e5, 0xf719bbbf, 0xd39bea89, - 0xbdadf81f, 0x992fa929, 0xf4a95a73, 0xd02b0b45, 0x2fa4bcc7, - 0x0b26edf1, 0x66a01eab, 0x42224f9d, 0x42ce77ee, 0x664c26d8, - 0x0bcad582, 0x2f4884b4, 0xd0c73336, 0xf4456200, 0x99c3915a, - 0xbd41c06c, 0x981be1bc, 0xbc99b08a, 0xd11f43d0, 0xf59d12e6, - 0x0a12a564, 0x2e90f452, 0x43160708, 0x6794563e, 0x67786e4d, - 0x43fa3f7b, 0x2e7ccc21, 0x0afe9d17, 0xf5712a95, 0xd1f37ba3, - 0xbc7588f9, 0x98f7d9cf, 0x6019add5, 0x449bfce3, 0x291d0fb9, - 0x0d9f5e8f, 0xf210e90d, 0xd692b83b, 0xbb144b61, 0x9f961a57, - 0x9f7a2224, 0xbbf87312, 0xd67e8048, 0xf2fcd17e, 0x0d7366fc, - 0x29f137ca, 0x4477c490, 0x60f595a6, 0x45afb476, 0x612de540, - 0x0cab161a, 0x2829472c, 0xd7a6f0ae, 0xf324a198, 0x9ea252c2, - 0xba2003f4, 0xbacc3b87, 0x9e4e6ab1, 0xf3c899eb, 0xd74ac8dd, - 0x28c57f5f, 0x0c472e69, 0x61c1dd33, 0x45438c05, 0x2b759e93, - 0x0ff7cfa5, 0x62713cff, 0x46f36dc9, 0xb97cda4b, 0x9dfe8b7d, - 0xf0787827, 0xd4fa2911, 0xd4161162, 0xf0944054, 0x9d12b30e, - 0xb990e238, 0x461f55ba, 0x629d048c, 0x0f1bf7d6, 0x2b99a6e0, - 0x0ec38730, 0x2a41d606, 0x47c7255c, 0x6345746a, 0x9ccac3e8, - 0xb84892de, 0xd5ce6184, 0xf14c30b2, 0xf1a008c1, 0xd52259f7, - 0xb8a4aaad, 0x9c26fb9b, 0x63a94c19, 0x472b1d2f, 0x2aadee75, - 0x0e2fbf43}, - {0x00000000, 0x36f290f3, 0x6de521e6, 0x5b17b115, 0xdbca43cc, - 0xed38d33f, 0xb62f622a, 0x80ddf2d9, 0x6ce581d9, 0x5a17112a, - 0x0100a03f, 0x37f230cc, 0xb72fc215, 0x81dd52e6, 0xdacae3f3, - 0xec387300, 0xd9cb03b2, 0xef399341, 0xb42e2254, 0x82dcb2a7, - 0x0201407e, 0x34f3d08d, 0x6fe46198, 0x5916f16b, 0xb52e826b, - 0x83dc1298, 0xd8cba38d, 0xee39337e, 0x6ee4c1a7, 0x58165154, - 0x0301e041, 0x35f370b2, 0x68e70125, 0x5e1591d6, 0x050220c3, - 0x33f0b030, 0xb32d42e9, 0x85dfd21a, 0xdec8630f, 0xe83af3fc, - 0x040280fc, 0x32f0100f, 0x69e7a11a, 0x5f1531e9, 0xdfc8c330, - 0xe93a53c3, 0xb22de2d6, 0x84df7225, 0xb12c0297, 0x87de9264, - 0xdcc92371, 0xea3bb382, 0x6ae6415b, 0x5c14d1a8, 0x070360bd, - 0x31f1f04e, 0xddc9834e, 0xeb3b13bd, 0xb02ca2a8, 0x86de325b, - 0x0603c082, 0x30f15071, 0x6be6e164, 0x5d147197, 0xd1ce024a, - 0xe73c92b9, 0xbc2b23ac, 0x8ad9b35f, 0x0a044186, 0x3cf6d175, - 0x67e16060, 0x5113f093, 0xbd2b8393, 0x8bd91360, 0xd0cea275, - 0xe63c3286, 0x66e1c05f, 0x501350ac, 0x0b04e1b9, 0x3df6714a, - 0x080501f8, 0x3ef7910b, 0x65e0201e, 0x5312b0ed, 0xd3cf4234, - 0xe53dd2c7, 0xbe2a63d2, 0x88d8f321, 0x64e08021, 0x521210d2, - 0x0905a1c7, 0x3ff73134, 0xbf2ac3ed, 0x89d8531e, 0xd2cfe20b, - 0xe43d72f8, 0xb929036f, 0x8fdb939c, 0xd4cc2289, 0xe23eb27a, - 0x62e340a3, 0x5411d050, 0x0f066145, 0x39f4f1b6, 0xd5cc82b6, - 0xe33e1245, 0xb829a350, 0x8edb33a3, 0x0e06c17a, 0x38f45189, - 0x63e3e09c, 0x5511706f, 0x60e200dd, 0x5610902e, 0x0d07213b, - 0x3bf5b1c8, 0xbb284311, 0x8ddad3e2, 0xd6cd62f7, 0xe03ff204, - 0x0c078104, 0x3af511f7, 0x61e2a0e2, 0x57103011, 0xd7cdc2c8, - 0xe13f523b, 0xba28e32e, 0x8cda73dd, 0x78ed02d5, 0x4e1f9226, - 0x15082333, 0x23fab3c0, 0xa3274119, 0x95d5d1ea, 0xcec260ff, - 0xf830f00c, 0x1408830c, 0x22fa13ff, 0x79eda2ea, 0x4f1f3219, - 0xcfc2c0c0, 0xf9305033, 0xa227e126, 0x94d571d5, 0xa1260167, - 0x97d49194, 0xccc32081, 0xfa31b072, 0x7aec42ab, 0x4c1ed258, - 0x1709634d, 0x21fbf3be, 0xcdc380be, 0xfb31104d, 0xa026a158, - 0x96d431ab, 0x1609c372, 0x20fb5381, 0x7bece294, 0x4d1e7267, - 0x100a03f0, 0x26f89303, 0x7def2216, 0x4b1db2e5, 0xcbc0403c, - 0xfd32d0cf, 0xa62561da, 0x90d7f129, 0x7cef8229, 0x4a1d12da, - 0x110aa3cf, 0x27f8333c, 0xa725c1e5, 0x91d75116, 0xcac0e003, - 0xfc3270f0, 0xc9c10042, 0xff3390b1, 0xa42421a4, 0x92d6b157, - 0x120b438e, 0x24f9d37d, 0x7fee6268, 0x491cf29b, 0xa524819b, - 0x93d61168, 0xc8c1a07d, 0xfe33308e, 0x7eeec257, 0x481c52a4, - 0x130be3b1, 0x25f97342, 0xa923009f, 0x9fd1906c, 0xc4c62179, - 0xf234b18a, 0x72e94353, 0x441bd3a0, 0x1f0c62b5, 0x29fef246, - 0xc5c68146, 0xf33411b5, 0xa823a0a0, 0x9ed13053, 0x1e0cc28a, - 0x28fe5279, 0x73e9e36c, 0x451b739f, 0x70e8032d, 0x461a93de, - 0x1d0d22cb, 0x2bffb238, 0xab2240e1, 0x9dd0d012, 0xc6c76107, - 0xf035f1f4, 0x1c0d82f4, 0x2aff1207, 0x71e8a312, 0x471a33e1, - 0xc7c7c138, 0xf13551cb, 0xaa22e0de, 0x9cd0702d, 0xc1c401ba, - 0xf7369149, 0xac21205c, 0x9ad3b0af, 0x1a0e4276, 0x2cfcd285, - 0x77eb6390, 0x4119f363, 0xad218063, 0x9bd31090, 0xc0c4a185, - 0xf6363176, 0x76ebc3af, 0x4019535c, 0x1b0ee249, 0x2dfc72ba, - 0x180f0208, 0x2efd92fb, 0x75ea23ee, 0x4318b31d, 0xc3c541c4, - 0xf537d137, 0xae206022, 0x98d2f0d1, 0x74ea83d1, 0x42181322, - 0x190fa237, 0x2ffd32c4, 0xaf20c01d, 0x99d250ee, 0xc2c5e1fb, - 0xf4377108}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x0000000000000000, 0xf390f23600000000, 0xe621e56d00000000, - 0x15b1175b00000000, 0xcc43cadb00000000, 0x3fd338ed00000000, - 0x2a622fb600000000, 0xd9f2dd8000000000, 0xd981e56c00000000, - 0x2a11175a00000000, 0x3fa0000100000000, 0xcc30f23700000000, - 0x15c22fb700000000, 0xe652dd8100000000, 0xf3e3cada00000000, - 0x007338ec00000000, 0xb203cbd900000000, 0x419339ef00000000, - 0x54222eb400000000, 0xa7b2dc8200000000, 0x7e40010200000000, - 0x8dd0f33400000000, 0x9861e46f00000000, 0x6bf1165900000000, - 0x6b822eb500000000, 0x9812dc8300000000, 0x8da3cbd800000000, - 0x7e3339ee00000000, 0xa7c1e46e00000000, 0x5451165800000000, - 0x41e0010300000000, 0xb270f33500000000, 0x2501e76800000000, - 0xd691155e00000000, 0xc320020500000000, 0x30b0f03300000000, - 0xe9422db300000000, 0x1ad2df8500000000, 0x0f63c8de00000000, - 0xfcf33ae800000000, 0xfc80020400000000, 0x0f10f03200000000, - 0x1aa1e76900000000, 0xe931155f00000000, 0x30c3c8df00000000, - 0xc3533ae900000000, 0xd6e22db200000000, 0x2572df8400000000, - 0x97022cb100000000, 0x6492de8700000000, 0x7123c9dc00000000, - 0x82b33bea00000000, 0x5b41e66a00000000, 0xa8d1145c00000000, - 0xbd60030700000000, 0x4ef0f13100000000, 0x4e83c9dd00000000, - 0xbd133beb00000000, 0xa8a22cb000000000, 0x5b32de8600000000, - 0x82c0030600000000, 0x7150f13000000000, 0x64e1e66b00000000, - 0x9771145d00000000, 0x4a02ced100000000, 0xb9923ce700000000, - 0xac232bbc00000000, 0x5fb3d98a00000000, 0x8641040a00000000, - 0x75d1f63c00000000, 0x6060e16700000000, 0x93f0135100000000, - 0x93832bbd00000000, 0x6013d98b00000000, 0x75a2ced000000000, - 0x86323ce600000000, 0x5fc0e16600000000, 0xac50135000000000, - 0xb9e1040b00000000, 0x4a71f63d00000000, 0xf801050800000000, - 0x0b91f73e00000000, 0x1e20e06500000000, 0xedb0125300000000, - 0x3442cfd300000000, 0xc7d23de500000000, 0xd2632abe00000000, - 0x21f3d88800000000, 0x2180e06400000000, 0xd210125200000000, - 0xc7a1050900000000, 0x3431f73f00000000, 0xedc32abf00000000, - 0x1e53d88900000000, 0x0be2cfd200000000, 0xf8723de400000000, - 0x6f0329b900000000, 0x9c93db8f00000000, 0x8922ccd400000000, - 0x7ab23ee200000000, 0xa340e36200000000, 0x50d0115400000000, - 0x4561060f00000000, 0xb6f1f43900000000, 0xb682ccd500000000, - 0x45123ee300000000, 0x50a329b800000000, 0xa333db8e00000000, - 0x7ac1060e00000000, 0x8951f43800000000, 0x9ce0e36300000000, - 0x6f70115500000000, 0xdd00e26000000000, 0x2e90105600000000, - 0x3b21070d00000000, 0xc8b1f53b00000000, 0x114328bb00000000, - 0xe2d3da8d00000000, 0xf762cdd600000000, 0x04f23fe000000000, - 0x0481070c00000000, 0xf711f53a00000000, 0xe2a0e26100000000, - 0x1130105700000000, 0xc8c2cdd700000000, 0x3b523fe100000000, - 0x2ee328ba00000000, 0xdd73da8c00000000, 0xd502ed7800000000, - 0x26921f4e00000000, 0x3323081500000000, 0xc0b3fa2300000000, - 0x194127a300000000, 0xead1d59500000000, 0xff60c2ce00000000, - 0x0cf030f800000000, 0x0c83081400000000, 0xff13fa2200000000, - 0xeaa2ed7900000000, 0x19321f4f00000000, 0xc0c0c2cf00000000, - 0x335030f900000000, 0x26e127a200000000, 0xd571d59400000000, - 0x670126a100000000, 0x9491d49700000000, 0x8120c3cc00000000, - 0x72b031fa00000000, 0xab42ec7a00000000, 0x58d21e4c00000000, - 0x4d63091700000000, 0xbef3fb2100000000, 0xbe80c3cd00000000, - 0x4d1031fb00000000, 0x58a126a000000000, 0xab31d49600000000, - 0x72c3091600000000, 0x8153fb2000000000, 0x94e2ec7b00000000, - 0x67721e4d00000000, 0xf0030a1000000000, 0x0393f82600000000, - 0x1622ef7d00000000, 0xe5b21d4b00000000, 0x3c40c0cb00000000, - 0xcfd032fd00000000, 0xda6125a600000000, 0x29f1d79000000000, - 0x2982ef7c00000000, 0xda121d4a00000000, 0xcfa30a1100000000, - 0x3c33f82700000000, 0xe5c125a700000000, 0x1651d79100000000, - 0x03e0c0ca00000000, 0xf07032fc00000000, 0x4200c1c900000000, - 0xb19033ff00000000, 0xa42124a400000000, 0x57b1d69200000000, - 0x8e430b1200000000, 0x7dd3f92400000000, 0x6862ee7f00000000, - 0x9bf21c4900000000, 0x9b8124a500000000, 0x6811d69300000000, - 0x7da0c1c800000000, 0x8e3033fe00000000, 0x57c2ee7e00000000, - 0xa4521c4800000000, 0xb1e30b1300000000, 0x4273f92500000000, - 0x9f0023a900000000, 0x6c90d19f00000000, 0x7921c6c400000000, - 0x8ab134f200000000, 0x5343e97200000000, 0xa0d31b4400000000, - 0xb5620c1f00000000, 0x46f2fe2900000000, 0x4681c6c500000000, - 0xb51134f300000000, 0xa0a023a800000000, 0x5330d19e00000000, - 0x8ac20c1e00000000, 0x7952fe2800000000, 0x6ce3e97300000000, - 0x9f731b4500000000, 0x2d03e87000000000, 0xde931a4600000000, - 0xcb220d1d00000000, 0x38b2ff2b00000000, 0xe14022ab00000000, - 0x12d0d09d00000000, 0x0761c7c600000000, 0xf4f135f000000000, - 0xf4820d1c00000000, 0x0712ff2a00000000, 0x12a3e87100000000, - 0xe1331a4700000000, 0x38c1c7c700000000, 0xcb5135f100000000, - 0xdee022aa00000000, 0x2d70d09c00000000, 0xba01c4c100000000, - 0x499136f700000000, 0x5c2021ac00000000, 0xafb0d39a00000000, - 0x76420e1a00000000, 0x85d2fc2c00000000, 0x9063eb7700000000, - 0x63f3194100000000, 0x638021ad00000000, 0x9010d39b00000000, - 0x85a1c4c000000000, 0x763136f600000000, 0xafc3eb7600000000, - 0x5c53194000000000, 0x49e20e1b00000000, 0xba72fc2d00000000, - 0x08020f1800000000, 0xfb92fd2e00000000, 0xee23ea7500000000, - 0x1db3184300000000, 0xc441c5c300000000, 0x37d137f500000000, - 0x226020ae00000000, 0xd1f0d29800000000, 0xd183ea7400000000, - 0x2213184200000000, 0x37a20f1900000000, 0xc432fd2f00000000, - 0x1dc020af00000000, 0xee50d29900000000, 0xfbe1c5c200000000, - 0x087137f400000000}, - {0x0000000000000000, 0x3651822400000000, 0x6ca2044900000000, - 0x5af3866d00000000, 0xd844099200000000, 0xee158bb600000000, - 0xb4e60ddb00000000, 0x82b78fff00000000, 0xf18f63ff00000000, - 0xc7dee1db00000000, 0x9d2d67b600000000, 0xab7ce59200000000, - 0x29cb6a6d00000000, 0x1f9ae84900000000, 0x45696e2400000000, - 0x7338ec0000000000, 0xa319b62500000000, 0x9548340100000000, - 0xcfbbb26c00000000, 0xf9ea304800000000, 0x7b5dbfb700000000, - 0x4d0c3d9300000000, 0x17ffbbfe00000000, 0x21ae39da00000000, - 0x5296d5da00000000, 0x64c757fe00000000, 0x3e34d19300000000, - 0x086553b700000000, 0x8ad2dc4800000000, 0xbc835e6c00000000, - 0xe670d80100000000, 0xd0215a2500000000, 0x46336c4b00000000, - 0x7062ee6f00000000, 0x2a91680200000000, 0x1cc0ea2600000000, - 0x9e7765d900000000, 0xa826e7fd00000000, 0xf2d5619000000000, - 0xc484e3b400000000, 0xb7bc0fb400000000, 0x81ed8d9000000000, - 0xdb1e0bfd00000000, 0xed4f89d900000000, 0x6ff8062600000000, - 0x59a9840200000000, 0x035a026f00000000, 0x350b804b00000000, - 0xe52ada6e00000000, 0xd37b584a00000000, 0x8988de2700000000, - 0xbfd95c0300000000, 0x3d6ed3fc00000000, 0x0b3f51d800000000, - 0x51ccd7b500000000, 0x679d559100000000, 0x14a5b99100000000, - 0x22f43bb500000000, 0x7807bdd800000000, 0x4e563ffc00000000, - 0xcce1b00300000000, 0xfab0322700000000, 0xa043b44a00000000, - 0x9612366e00000000, 0x8c66d89600000000, 0xba375ab200000000, - 0xe0c4dcdf00000000, 0xd6955efb00000000, 0x5422d10400000000, - 0x6273532000000000, 0x3880d54d00000000, 0x0ed1576900000000, - 0x7de9bb6900000000, 0x4bb8394d00000000, 0x114bbf2000000000, - 0x271a3d0400000000, 0xa5adb2fb00000000, 0x93fc30df00000000, - 0xc90fb6b200000000, 0xff5e349600000000, 0x2f7f6eb300000000, - 0x192eec9700000000, 0x43dd6afa00000000, 0x758ce8de00000000, - 0xf73b672100000000, 0xc16ae50500000000, 0x9b99636800000000, - 0xadc8e14c00000000, 0xdef00d4c00000000, 0xe8a18f6800000000, - 0xb252090500000000, 0x84038b2100000000, 0x06b404de00000000, - 0x30e586fa00000000, 0x6a16009700000000, 0x5c4782b300000000, - 0xca55b4dd00000000, 0xfc0436f900000000, 0xa6f7b09400000000, - 0x90a632b000000000, 0x1211bd4f00000000, 0x24403f6b00000000, - 0x7eb3b90600000000, 0x48e23b2200000000, 0x3bdad72200000000, - 0x0d8b550600000000, 0x5778d36b00000000, 0x6129514f00000000, - 0xe39edeb000000000, 0xd5cf5c9400000000, 0x8f3cdaf900000000, - 0xb96d58dd00000000, 0x694c02f800000000, 0x5f1d80dc00000000, - 0x05ee06b100000000, 0x33bf849500000000, 0xb1080b6a00000000, - 0x8759894e00000000, 0xddaa0f2300000000, 0xebfb8d0700000000, - 0x98c3610700000000, 0xae92e32300000000, 0xf461654e00000000, - 0xc230e76a00000000, 0x4087689500000000, 0x76d6eab100000000, - 0x2c256cdc00000000, 0x1a74eef800000000, 0x59cbc1f600000000, - 0x6f9a43d200000000, 0x3569c5bf00000000, 0x0338479b00000000, - 0x818fc86400000000, 0xb7de4a4000000000, 0xed2dcc2d00000000, - 0xdb7c4e0900000000, 0xa844a20900000000, 0x9e15202d00000000, - 0xc4e6a64000000000, 0xf2b7246400000000, 0x7000ab9b00000000, - 0x465129bf00000000, 0x1ca2afd200000000, 0x2af32df600000000, - 0xfad277d300000000, 0xcc83f5f700000000, 0x9670739a00000000, - 0xa021f1be00000000, 0x22967e4100000000, 0x14c7fc6500000000, - 0x4e347a0800000000, 0x7865f82c00000000, 0x0b5d142c00000000, - 0x3d0c960800000000, 0x67ff106500000000, 0x51ae924100000000, - 0xd3191dbe00000000, 0xe5489f9a00000000, 0xbfbb19f700000000, - 0x89ea9bd300000000, 0x1ff8adbd00000000, 0x29a92f9900000000, - 0x735aa9f400000000, 0x450b2bd000000000, 0xc7bca42f00000000, - 0xf1ed260b00000000, 0xab1ea06600000000, 0x9d4f224200000000, - 0xee77ce4200000000, 0xd8264c6600000000, 0x82d5ca0b00000000, - 0xb484482f00000000, 0x3633c7d000000000, 0x006245f400000000, - 0x5a91c39900000000, 0x6cc041bd00000000, 0xbce11b9800000000, - 0x8ab099bc00000000, 0xd0431fd100000000, 0xe6129df500000000, - 0x64a5120a00000000, 0x52f4902e00000000, 0x0807164300000000, - 0x3e56946700000000, 0x4d6e786700000000, 0x7b3ffa4300000000, - 0x21cc7c2e00000000, 0x179dfe0a00000000, 0x952a71f500000000, - 0xa37bf3d100000000, 0xf98875bc00000000, 0xcfd9f79800000000, - 0xd5ad196000000000, 0xe3fc9b4400000000, 0xb90f1d2900000000, - 0x8f5e9f0d00000000, 0x0de910f200000000, 0x3bb892d600000000, - 0x614b14bb00000000, 0x571a969f00000000, 0x24227a9f00000000, - 0x1273f8bb00000000, 0x48807ed600000000, 0x7ed1fcf200000000, - 0xfc66730d00000000, 0xca37f12900000000, 0x90c4774400000000, - 0xa695f56000000000, 0x76b4af4500000000, 0x40e52d6100000000, - 0x1a16ab0c00000000, 0x2c47292800000000, 0xaef0a6d700000000, - 0x98a124f300000000, 0xc252a29e00000000, 0xf40320ba00000000, - 0x873bccba00000000, 0xb16a4e9e00000000, 0xeb99c8f300000000, - 0xddc84ad700000000, 0x5f7fc52800000000, 0x692e470c00000000, - 0x33ddc16100000000, 0x058c434500000000, 0x939e752b00000000, - 0xa5cff70f00000000, 0xff3c716200000000, 0xc96df34600000000, - 0x4bda7cb900000000, 0x7d8bfe9d00000000, 0x277878f000000000, - 0x1129fad400000000, 0x621116d400000000, 0x544094f000000000, - 0x0eb3129d00000000, 0x38e290b900000000, 0xba551f4600000000, - 0x8c049d6200000000, 0xd6f71b0f00000000, 0xe0a6992b00000000, - 0x3087c30e00000000, 0x06d6412a00000000, 0x5c25c74700000000, - 0x6a74456300000000, 0xe8c3ca9c00000000, 0xde9248b800000000, - 0x8461ced500000000, 0xb2304cf100000000, 0xc108a0f100000000, - 0xf75922d500000000, 0xadaaa4b800000000, 0x9bfb269c00000000, - 0x194ca96300000000, 0x2f1d2b4700000000, 0x75eead2a00000000, - 0x43bf2f0e00000000}, - {0x0000000000000000, 0xc8179ecf00000000, 0xd1294d4400000000, - 0x193ed38b00000000, 0xa2539a8800000000, 0x6a44044700000000, - 0x737ad7cc00000000, 0xbb6d490300000000, 0x05a145ca00000000, - 0xcdb6db0500000000, 0xd488088e00000000, 0x1c9f964100000000, - 0xa7f2df4200000000, 0x6fe5418d00000000, 0x76db920600000000, - 0xbecc0cc900000000, 0x4b44fa4f00000000, 0x8353648000000000, - 0x9a6db70b00000000, 0x527a29c400000000, 0xe91760c700000000, - 0x2100fe0800000000, 0x383e2d8300000000, 0xf029b34c00000000, - 0x4ee5bf8500000000, 0x86f2214a00000000, 0x9fccf2c100000000, - 0x57db6c0e00000000, 0xecb6250d00000000, 0x24a1bbc200000000, - 0x3d9f684900000000, 0xf588f68600000000, 0x9688f49f00000000, - 0x5e9f6a5000000000, 0x47a1b9db00000000, 0x8fb6271400000000, - 0x34db6e1700000000, 0xfcccf0d800000000, 0xe5f2235300000000, - 0x2de5bd9c00000000, 0x9329b15500000000, 0x5b3e2f9a00000000, - 0x4200fc1100000000, 0x8a1762de00000000, 0x317a2bdd00000000, - 0xf96db51200000000, 0xe053669900000000, 0x2844f85600000000, - 0xddcc0ed000000000, 0x15db901f00000000, 0x0ce5439400000000, - 0xc4f2dd5b00000000, 0x7f9f945800000000, 0xb7880a9700000000, - 0xaeb6d91c00000000, 0x66a147d300000000, 0xd86d4b1a00000000, - 0x107ad5d500000000, 0x0944065e00000000, 0xc153989100000000, - 0x7a3ed19200000000, 0xb2294f5d00000000, 0xab179cd600000000, - 0x6300021900000000, 0x6d1798e400000000, 0xa500062b00000000, - 0xbc3ed5a000000000, 0x74294b6f00000000, 0xcf44026c00000000, - 0x07539ca300000000, 0x1e6d4f2800000000, 0xd67ad1e700000000, - 0x68b6dd2e00000000, 0xa0a143e100000000, 0xb99f906a00000000, - 0x71880ea500000000, 0xcae547a600000000, 0x02f2d96900000000, - 0x1bcc0ae200000000, 0xd3db942d00000000, 0x265362ab00000000, - 0xee44fc6400000000, 0xf77a2fef00000000, 0x3f6db12000000000, - 0x8400f82300000000, 0x4c1766ec00000000, 0x5529b56700000000, - 0x9d3e2ba800000000, 0x23f2276100000000, 0xebe5b9ae00000000, - 0xf2db6a2500000000, 0x3accf4ea00000000, 0x81a1bde900000000, - 0x49b6232600000000, 0x5088f0ad00000000, 0x989f6e6200000000, - 0xfb9f6c7b00000000, 0x3388f2b400000000, 0x2ab6213f00000000, - 0xe2a1bff000000000, 0x59ccf6f300000000, 0x91db683c00000000, - 0x88e5bbb700000000, 0x40f2257800000000, 0xfe3e29b100000000, - 0x3629b77e00000000, 0x2f1764f500000000, 0xe700fa3a00000000, - 0x5c6db33900000000, 0x947a2df600000000, 0x8d44fe7d00000000, - 0x455360b200000000, 0xb0db963400000000, 0x78cc08fb00000000, - 0x61f2db7000000000, 0xa9e545bf00000000, 0x12880cbc00000000, - 0xda9f927300000000, 0xc3a141f800000000, 0x0bb6df3700000000, - 0xb57ad3fe00000000, 0x7d6d4d3100000000, 0x64539eba00000000, - 0xac44007500000000, 0x1729497600000000, 0xdf3ed7b900000000, - 0xc600043200000000, 0x0e179afd00000000, 0x9b28411200000000, - 0x533fdfdd00000000, 0x4a010c5600000000, 0x8216929900000000, - 0x397bdb9a00000000, 0xf16c455500000000, 0xe85296de00000000, - 0x2045081100000000, 0x9e8904d800000000, 0x569e9a1700000000, - 0x4fa0499c00000000, 0x87b7d75300000000, 0x3cda9e5000000000, - 0xf4cd009f00000000, 0xedf3d31400000000, 0x25e44ddb00000000, - 0xd06cbb5d00000000, 0x187b259200000000, 0x0145f61900000000, - 0xc95268d600000000, 0x723f21d500000000, 0xba28bf1a00000000, - 0xa3166c9100000000, 0x6b01f25e00000000, 0xd5cdfe9700000000, - 0x1dda605800000000, 0x04e4b3d300000000, 0xccf32d1c00000000, - 0x779e641f00000000, 0xbf89fad000000000, 0xa6b7295b00000000, - 0x6ea0b79400000000, 0x0da0b58d00000000, 0xc5b72b4200000000, - 0xdc89f8c900000000, 0x149e660600000000, 0xaff32f0500000000, - 0x67e4b1ca00000000, 0x7eda624100000000, 0xb6cdfc8e00000000, - 0x0801f04700000000, 0xc0166e8800000000, 0xd928bd0300000000, - 0x113f23cc00000000, 0xaa526acf00000000, 0x6245f40000000000, - 0x7b7b278b00000000, 0xb36cb94400000000, 0x46e44fc200000000, - 0x8ef3d10d00000000, 0x97cd028600000000, 0x5fda9c4900000000, - 0xe4b7d54a00000000, 0x2ca04b8500000000, 0x359e980e00000000, - 0xfd8906c100000000, 0x43450a0800000000, 0x8b5294c700000000, - 0x926c474c00000000, 0x5a7bd98300000000, 0xe116908000000000, - 0x29010e4f00000000, 0x303fddc400000000, 0xf828430b00000000, - 0xf63fd9f600000000, 0x3e28473900000000, 0x271694b200000000, - 0xef010a7d00000000, 0x546c437e00000000, 0x9c7bddb100000000, - 0x85450e3a00000000, 0x4d5290f500000000, 0xf39e9c3c00000000, - 0x3b8902f300000000, 0x22b7d17800000000, 0xeaa04fb700000000, - 0x51cd06b400000000, 0x99da987b00000000, 0x80e44bf000000000, - 0x48f3d53f00000000, 0xbd7b23b900000000, 0x756cbd7600000000, - 0x6c526efd00000000, 0xa445f03200000000, 0x1f28b93100000000, - 0xd73f27fe00000000, 0xce01f47500000000, 0x06166aba00000000, - 0xb8da667300000000, 0x70cdf8bc00000000, 0x69f32b3700000000, - 0xa1e4b5f800000000, 0x1a89fcfb00000000, 0xd29e623400000000, - 0xcba0b1bf00000000, 0x03b72f7000000000, 0x60b72d6900000000, - 0xa8a0b3a600000000, 0xb19e602d00000000, 0x7989fee200000000, - 0xc2e4b7e100000000, 0x0af3292e00000000, 0x13cdfaa500000000, - 0xdbda646a00000000, 0x651668a300000000, 0xad01f66c00000000, - 0xb43f25e700000000, 0x7c28bb2800000000, 0xc745f22b00000000, - 0x0f526ce400000000, 0x166cbf6f00000000, 0xde7b21a000000000, - 0x2bf3d72600000000, 0xe3e449e900000000, 0xfada9a6200000000, - 0x32cd04ad00000000, 0x89a04dae00000000, 0x41b7d36100000000, - 0x588900ea00000000, 0x909e9e2500000000, 0x2e5292ec00000000, - 0xe6450c2300000000, 0xff7bdfa800000000, 0x376c416700000000, - 0x8c01086400000000, 0x441696ab00000000, 0x5d28452000000000, - 0x953fdbef00000000}, - {0x0000000000000000, 0x95d4709500000000, 0x6baf90f100000000, - 0xfe7be06400000000, 0x9758503800000000, 0x028c20ad00000000, - 0xfcf7c0c900000000, 0x6923b05c00000000, 0x2eb1a07000000000, - 0xbb65d0e500000000, 0x451e308100000000, 0xd0ca401400000000, - 0xb9e9f04800000000, 0x2c3d80dd00000000, 0xd24660b900000000, - 0x4792102c00000000, 0x5c6241e100000000, 0xc9b6317400000000, - 0x37cdd11000000000, 0xa219a18500000000, 0xcb3a11d900000000, - 0x5eee614c00000000, 0xa095812800000000, 0x3541f1bd00000000, - 0x72d3e19100000000, 0xe707910400000000, 0x197c716000000000, - 0x8ca801f500000000, 0xe58bb1a900000000, 0x705fc13c00000000, - 0x8e24215800000000, 0x1bf051cd00000000, 0xf9c2f31900000000, - 0x6c16838c00000000, 0x926d63e800000000, 0x07b9137d00000000, - 0x6e9aa32100000000, 0xfb4ed3b400000000, 0x053533d000000000, - 0x90e1434500000000, 0xd773536900000000, 0x42a723fc00000000, - 0xbcdcc39800000000, 0x2908b30d00000000, 0x402b035100000000, - 0xd5ff73c400000000, 0x2b8493a000000000, 0xbe50e33500000000, - 0xa5a0b2f800000000, 0x3074c26d00000000, 0xce0f220900000000, - 0x5bdb529c00000000, 0x32f8e2c000000000, 0xa72c925500000000, - 0x5957723100000000, 0xcc8302a400000000, 0x8b11128800000000, - 0x1ec5621d00000000, 0xe0be827900000000, 0x756af2ec00000000, - 0x1c4942b000000000, 0x899d322500000000, 0x77e6d24100000000, - 0xe232a2d400000000, 0xf285e73300000000, 0x675197a600000000, - 0x992a77c200000000, 0x0cfe075700000000, 0x65ddb70b00000000, - 0xf009c79e00000000, 0x0e7227fa00000000, 0x9ba6576f00000000, - 0xdc34474300000000, 0x49e037d600000000, 0xb79bd7b200000000, - 0x224fa72700000000, 0x4b6c177b00000000, 0xdeb867ee00000000, - 0x20c3878a00000000, 0xb517f71f00000000, 0xaee7a6d200000000, - 0x3b33d64700000000, 0xc548362300000000, 0x509c46b600000000, - 0x39bff6ea00000000, 0xac6b867f00000000, 0x5210661b00000000, - 0xc7c4168e00000000, 0x805606a200000000, 0x1582763700000000, - 0xebf9965300000000, 0x7e2de6c600000000, 0x170e569a00000000, - 0x82da260f00000000, 0x7ca1c66b00000000, 0xe975b6fe00000000, - 0x0b47142a00000000, 0x9e9364bf00000000, 0x60e884db00000000, - 0xf53cf44e00000000, 0x9c1f441200000000, 0x09cb348700000000, - 0xf7b0d4e300000000, 0x6264a47600000000, 0x25f6b45a00000000, - 0xb022c4cf00000000, 0x4e5924ab00000000, 0xdb8d543e00000000, - 0xb2aee46200000000, 0x277a94f700000000, 0xd901749300000000, - 0x4cd5040600000000, 0x572555cb00000000, 0xc2f1255e00000000, - 0x3c8ac53a00000000, 0xa95eb5af00000000, 0xc07d05f300000000, - 0x55a9756600000000, 0xabd2950200000000, 0x3e06e59700000000, - 0x7994f5bb00000000, 0xec40852e00000000, 0x123b654a00000000, - 0x87ef15df00000000, 0xeecca58300000000, 0x7b18d51600000000, - 0x8563357200000000, 0x10b745e700000000, 0xe40bcf6700000000, - 0x71dfbff200000000, 0x8fa45f9600000000, 0x1a702f0300000000, - 0x73539f5f00000000, 0xe687efca00000000, 0x18fc0fae00000000, - 0x8d287f3b00000000, 0xcaba6f1700000000, 0x5f6e1f8200000000, - 0xa115ffe600000000, 0x34c18f7300000000, 0x5de23f2f00000000, - 0xc8364fba00000000, 0x364dafde00000000, 0xa399df4b00000000, - 0xb8698e8600000000, 0x2dbdfe1300000000, 0xd3c61e7700000000, - 0x46126ee200000000, 0x2f31debe00000000, 0xbae5ae2b00000000, - 0x449e4e4f00000000, 0xd14a3eda00000000, 0x96d82ef600000000, - 0x030c5e6300000000, 0xfd77be0700000000, 0x68a3ce9200000000, - 0x01807ece00000000, 0x94540e5b00000000, 0x6a2fee3f00000000, - 0xfffb9eaa00000000, 0x1dc93c7e00000000, 0x881d4ceb00000000, - 0x7666ac8f00000000, 0xe3b2dc1a00000000, 0x8a916c4600000000, - 0x1f451cd300000000, 0xe13efcb700000000, 0x74ea8c2200000000, - 0x33789c0e00000000, 0xa6acec9b00000000, 0x58d70cff00000000, - 0xcd037c6a00000000, 0xa420cc3600000000, 0x31f4bca300000000, - 0xcf8f5cc700000000, 0x5a5b2c5200000000, 0x41ab7d9f00000000, - 0xd47f0d0a00000000, 0x2a04ed6e00000000, 0xbfd09dfb00000000, - 0xd6f32da700000000, 0x43275d3200000000, 0xbd5cbd5600000000, - 0x2888cdc300000000, 0x6f1addef00000000, 0xfacead7a00000000, - 0x04b54d1e00000000, 0x91613d8b00000000, 0xf8428dd700000000, - 0x6d96fd4200000000, 0x93ed1d2600000000, 0x06396db300000000, - 0x168e285400000000, 0x835a58c100000000, 0x7d21b8a500000000, - 0xe8f5c83000000000, 0x81d6786c00000000, 0x140208f900000000, - 0xea79e89d00000000, 0x7fad980800000000, 0x383f882400000000, - 0xadebf8b100000000, 0x539018d500000000, 0xc644684000000000, - 0xaf67d81c00000000, 0x3ab3a88900000000, 0xc4c848ed00000000, - 0x511c387800000000, 0x4aec69b500000000, 0xdf38192000000000, - 0x2143f94400000000, 0xb49789d100000000, 0xddb4398d00000000, - 0x4860491800000000, 0xb61ba97c00000000, 0x23cfd9e900000000, - 0x645dc9c500000000, 0xf189b95000000000, 0x0ff2593400000000, - 0x9a2629a100000000, 0xf30599fd00000000, 0x66d1e96800000000, - 0x98aa090c00000000, 0x0d7e799900000000, 0xef4cdb4d00000000, - 0x7a98abd800000000, 0x84e34bbc00000000, 0x11373b2900000000, - 0x78148b7500000000, 0xedc0fbe000000000, 0x13bb1b8400000000, - 0x866f6b1100000000, 0xc1fd7b3d00000000, 0x54290ba800000000, - 0xaa52ebcc00000000, 0x3f869b5900000000, 0x56a52b0500000000, - 0xc3715b9000000000, 0x3d0abbf400000000, 0xa8decb6100000000, - 0xb32e9aac00000000, 0x26faea3900000000, 0xd8810a5d00000000, - 0x4d557ac800000000, 0x2476ca9400000000, 0xb1a2ba0100000000, - 0x4fd95a6500000000, 0xda0d2af000000000, 0x9d9f3adc00000000, - 0x084b4a4900000000, 0xf630aa2d00000000, 0x63e4dab800000000, - 0x0ac76ae400000000, 0x9f131a7100000000, 0x6168fa1500000000, - 0xf4bc8a8000000000}, - {0x0000000000000000, 0x1f17f08000000000, 0x7f2891da00000000, - 0x603f615a00000000, 0xbf56536e00000000, 0xa041a3ee00000000, - 0xc07ec2b400000000, 0xdf69323400000000, 0x7eada6dc00000000, - 0x61ba565c00000000, 0x0185370600000000, 0x1e92c78600000000, - 0xc1fbf5b200000000, 0xdeec053200000000, 0xbed3646800000000, - 0xa1c494e800000000, 0xbd5c3c6200000000, 0xa24bcce200000000, - 0xc274adb800000000, 0xdd635d3800000000, 0x020a6f0c00000000, - 0x1d1d9f8c00000000, 0x7d22fed600000000, 0x62350e5600000000, - 0xc3f19abe00000000, 0xdce66a3e00000000, 0xbcd90b6400000000, - 0xa3cefbe400000000, 0x7ca7c9d000000000, 0x63b0395000000000, - 0x038f580a00000000, 0x1c98a88a00000000, 0x7ab978c400000000, - 0x65ae884400000000, 0x0591e91e00000000, 0x1a86199e00000000, - 0xc5ef2baa00000000, 0xdaf8db2a00000000, 0xbac7ba7000000000, - 0xa5d04af000000000, 0x0414de1800000000, 0x1b032e9800000000, - 0x7b3c4fc200000000, 0x642bbf4200000000, 0xbb428d7600000000, - 0xa4557df600000000, 0xc46a1cac00000000, 0xdb7dec2c00000000, - 0xc7e544a600000000, 0xd8f2b42600000000, 0xb8cdd57c00000000, - 0xa7da25fc00000000, 0x78b317c800000000, 0x67a4e74800000000, - 0x079b861200000000, 0x188c769200000000, 0xb948e27a00000000, - 0xa65f12fa00000000, 0xc66073a000000000, 0xd977832000000000, - 0x061eb11400000000, 0x1909419400000000, 0x793620ce00000000, - 0x6621d04e00000000, 0xb574805300000000, 0xaa6370d300000000, - 0xca5c118900000000, 0xd54be10900000000, 0x0a22d33d00000000, - 0x153523bd00000000, 0x750a42e700000000, 0x6a1db26700000000, - 0xcbd9268f00000000, 0xd4ced60f00000000, 0xb4f1b75500000000, - 0xabe647d500000000, 0x748f75e100000000, 0x6b98856100000000, - 0x0ba7e43b00000000, 0x14b014bb00000000, 0x0828bc3100000000, - 0x173f4cb100000000, 0x77002deb00000000, 0x6817dd6b00000000, - 0xb77eef5f00000000, 0xa8691fdf00000000, 0xc8567e8500000000, - 0xd7418e0500000000, 0x76851aed00000000, 0x6992ea6d00000000, - 0x09ad8b3700000000, 0x16ba7bb700000000, 0xc9d3498300000000, - 0xd6c4b90300000000, 0xb6fbd85900000000, 0xa9ec28d900000000, - 0xcfcdf89700000000, 0xd0da081700000000, 0xb0e5694d00000000, - 0xaff299cd00000000, 0x709babf900000000, 0x6f8c5b7900000000, - 0x0fb33a2300000000, 0x10a4caa300000000, 0xb1605e4b00000000, - 0xae77aecb00000000, 0xce48cf9100000000, 0xd15f3f1100000000, - 0x0e360d2500000000, 0x1121fda500000000, 0x711e9cff00000000, - 0x6e096c7f00000000, 0x7291c4f500000000, 0x6d86347500000000, - 0x0db9552f00000000, 0x12aea5af00000000, 0xcdc7979b00000000, - 0xd2d0671b00000000, 0xb2ef064100000000, 0xadf8f6c100000000, - 0x0c3c622900000000, 0x132b92a900000000, 0x7314f3f300000000, - 0x6c03037300000000, 0xb36a314700000000, 0xac7dc1c700000000, - 0xcc42a09d00000000, 0xd355501d00000000, 0x6ae900a700000000, - 0x75fef02700000000, 0x15c1917d00000000, 0x0ad661fd00000000, - 0xd5bf53c900000000, 0xcaa8a34900000000, 0xaa97c21300000000, - 0xb580329300000000, 0x1444a67b00000000, 0x0b5356fb00000000, - 0x6b6c37a100000000, 0x747bc72100000000, 0xab12f51500000000, - 0xb405059500000000, 0xd43a64cf00000000, 0xcb2d944f00000000, - 0xd7b53cc500000000, 0xc8a2cc4500000000, 0xa89dad1f00000000, - 0xb78a5d9f00000000, 0x68e36fab00000000, 0x77f49f2b00000000, - 0x17cbfe7100000000, 0x08dc0ef100000000, 0xa9189a1900000000, - 0xb60f6a9900000000, 0xd6300bc300000000, 0xc927fb4300000000, - 0x164ec97700000000, 0x095939f700000000, 0x696658ad00000000, - 0x7671a82d00000000, 0x1050786300000000, 0x0f4788e300000000, - 0x6f78e9b900000000, 0x706f193900000000, 0xaf062b0d00000000, - 0xb011db8d00000000, 0xd02ebad700000000, 0xcf394a5700000000, - 0x6efddebf00000000, 0x71ea2e3f00000000, 0x11d54f6500000000, - 0x0ec2bfe500000000, 0xd1ab8dd100000000, 0xcebc7d5100000000, - 0xae831c0b00000000, 0xb194ec8b00000000, 0xad0c440100000000, - 0xb21bb48100000000, 0xd224d5db00000000, 0xcd33255b00000000, - 0x125a176f00000000, 0x0d4de7ef00000000, 0x6d7286b500000000, - 0x7265763500000000, 0xd3a1e2dd00000000, 0xccb6125d00000000, - 0xac89730700000000, 0xb39e838700000000, 0x6cf7b1b300000000, - 0x73e0413300000000, 0x13df206900000000, 0x0cc8d0e900000000, - 0xdf9d80f400000000, 0xc08a707400000000, 0xa0b5112e00000000, - 0xbfa2e1ae00000000, 0x60cbd39a00000000, 0x7fdc231a00000000, - 0x1fe3424000000000, 0x00f4b2c000000000, 0xa130262800000000, - 0xbe27d6a800000000, 0xde18b7f200000000, 0xc10f477200000000, - 0x1e66754600000000, 0x017185c600000000, 0x614ee49c00000000, - 0x7e59141c00000000, 0x62c1bc9600000000, 0x7dd64c1600000000, - 0x1de92d4c00000000, 0x02feddcc00000000, 0xdd97eff800000000, - 0xc2801f7800000000, 0xa2bf7e2200000000, 0xbda88ea200000000, - 0x1c6c1a4a00000000, 0x037beaca00000000, 0x63448b9000000000, - 0x7c537b1000000000, 0xa33a492400000000, 0xbc2db9a400000000, - 0xdc12d8fe00000000, 0xc305287e00000000, 0xa524f83000000000, - 0xba3308b000000000, 0xda0c69ea00000000, 0xc51b996a00000000, - 0x1a72ab5e00000000, 0x05655bde00000000, 0x655a3a8400000000, - 0x7a4dca0400000000, 0xdb895eec00000000, 0xc49eae6c00000000, - 0xa4a1cf3600000000, 0xbbb63fb600000000, 0x64df0d8200000000, - 0x7bc8fd0200000000, 0x1bf79c5800000000, 0x04e06cd800000000, - 0x1878c45200000000, 0x076f34d200000000, 0x6750558800000000, - 0x7847a50800000000, 0xa72e973c00000000, 0xb83967bc00000000, - 0xd80606e600000000, 0xc711f66600000000, 0x66d5628e00000000, - 0x79c2920e00000000, 0x19fdf35400000000, 0x06ea03d400000000, - 0xd98331e000000000, 0xc694c16000000000, 0xa6aba03a00000000, - 0xb9bc50ba00000000}, - {0x0000000000000000, 0xe2fd888d00000000, 0x85fd60c000000000, - 0x6700e84d00000000, 0x4bfdb05b00000000, 0xa90038d600000000, - 0xce00d09b00000000, 0x2cfd581600000000, 0x96fa61b700000000, - 0x7407e93a00000000, 0x1307017700000000, 0xf1fa89fa00000000, - 0xdd07d1ec00000000, 0x3ffa596100000000, 0x58fab12c00000000, - 0xba0739a100000000, 0x6df3b2b500000000, 0x8f0e3a3800000000, - 0xe80ed27500000000, 0x0af35af800000000, 0x260e02ee00000000, - 0xc4f38a6300000000, 0xa3f3622e00000000, 0x410eeaa300000000, - 0xfb09d30200000000, 0x19f45b8f00000000, 0x7ef4b3c200000000, - 0x9c093b4f00000000, 0xb0f4635900000000, 0x5209ebd400000000, - 0x3509039900000000, 0xd7f48b1400000000, 0x9be014b000000000, - 0x791d9c3d00000000, 0x1e1d747000000000, 0xfce0fcfd00000000, - 0xd01da4eb00000000, 0x32e02c6600000000, 0x55e0c42b00000000, - 0xb71d4ca600000000, 0x0d1a750700000000, 0xefe7fd8a00000000, - 0x88e715c700000000, 0x6a1a9d4a00000000, 0x46e7c55c00000000, - 0xa41a4dd100000000, 0xc31aa59c00000000, 0x21e72d1100000000, - 0xf613a60500000000, 0x14ee2e8800000000, 0x73eec6c500000000, - 0x91134e4800000000, 0xbdee165e00000000, 0x5f139ed300000000, - 0x3813769e00000000, 0xdaeefe1300000000, 0x60e9c7b200000000, - 0x82144f3f00000000, 0xe514a77200000000, 0x07e92fff00000000, - 0x2b1477e900000000, 0xc9e9ff6400000000, 0xaee9172900000000, - 0x4c149fa400000000, 0x77c758bb00000000, 0x953ad03600000000, - 0xf23a387b00000000, 0x10c7b0f600000000, 0x3c3ae8e000000000, - 0xdec7606d00000000, 0xb9c7882000000000, 0x5b3a00ad00000000, - 0xe13d390c00000000, 0x03c0b18100000000, 0x64c059cc00000000, - 0x863dd14100000000, 0xaac0895700000000, 0x483d01da00000000, - 0x2f3de99700000000, 0xcdc0611a00000000, 0x1a34ea0e00000000, - 0xf8c9628300000000, 0x9fc98ace00000000, 0x7d34024300000000, - 0x51c95a5500000000, 0xb334d2d800000000, 0xd4343a9500000000, - 0x36c9b21800000000, 0x8cce8bb900000000, 0x6e33033400000000, - 0x0933eb7900000000, 0xebce63f400000000, 0xc7333be200000000, - 0x25ceb36f00000000, 0x42ce5b2200000000, 0xa033d3af00000000, - 0xec274c0b00000000, 0x0edac48600000000, 0x69da2ccb00000000, - 0x8b27a44600000000, 0xa7dafc5000000000, 0x452774dd00000000, - 0x22279c9000000000, 0xc0da141d00000000, 0x7add2dbc00000000, - 0x9820a53100000000, 0xff204d7c00000000, 0x1dddc5f100000000, - 0x31209de700000000, 0xd3dd156a00000000, 0xb4ddfd2700000000, - 0x562075aa00000000, 0x81d4febe00000000, 0x6329763300000000, - 0x04299e7e00000000, 0xe6d416f300000000, 0xca294ee500000000, - 0x28d4c66800000000, 0x4fd42e2500000000, 0xad29a6a800000000, - 0x172e9f0900000000, 0xf5d3178400000000, 0x92d3ffc900000000, - 0x702e774400000000, 0x5cd32f5200000000, 0xbe2ea7df00000000, - 0xd92e4f9200000000, 0x3bd3c71f00000000, 0xaf88c0ad00000000, - 0x4d75482000000000, 0x2a75a06d00000000, 0xc88828e000000000, - 0xe47570f600000000, 0x0688f87b00000000, 0x6188103600000000, - 0x837598bb00000000, 0x3972a11a00000000, 0xdb8f299700000000, - 0xbc8fc1da00000000, 0x5e72495700000000, 0x728f114100000000, - 0x907299cc00000000, 0xf772718100000000, 0x158ff90c00000000, - 0xc27b721800000000, 0x2086fa9500000000, 0x478612d800000000, - 0xa57b9a5500000000, 0x8986c24300000000, 0x6b7b4ace00000000, - 0x0c7ba28300000000, 0xee862a0e00000000, 0x548113af00000000, - 0xb67c9b2200000000, 0xd17c736f00000000, 0x3381fbe200000000, - 0x1f7ca3f400000000, 0xfd812b7900000000, 0x9a81c33400000000, - 0x787c4bb900000000, 0x3468d41d00000000, 0xd6955c9000000000, - 0xb195b4dd00000000, 0x53683c5000000000, 0x7f95644600000000, - 0x9d68eccb00000000, 0xfa68048600000000, 0x18958c0b00000000, - 0xa292b5aa00000000, 0x406f3d2700000000, 0x276fd56a00000000, - 0xc5925de700000000, 0xe96f05f100000000, 0x0b928d7c00000000, - 0x6c92653100000000, 0x8e6fedbc00000000, 0x599b66a800000000, - 0xbb66ee2500000000, 0xdc66066800000000, 0x3e9b8ee500000000, - 0x1266d6f300000000, 0xf09b5e7e00000000, 0x979bb63300000000, - 0x75663ebe00000000, 0xcf61071f00000000, 0x2d9c8f9200000000, - 0x4a9c67df00000000, 0xa861ef5200000000, 0x849cb74400000000, - 0x66613fc900000000, 0x0161d78400000000, 0xe39c5f0900000000, - 0xd84f981600000000, 0x3ab2109b00000000, 0x5db2f8d600000000, - 0xbf4f705b00000000, 0x93b2284d00000000, 0x714fa0c000000000, - 0x164f488d00000000, 0xf4b2c00000000000, 0x4eb5f9a100000000, - 0xac48712c00000000, 0xcb48996100000000, 0x29b511ec00000000, - 0x054849fa00000000, 0xe7b5c17700000000, 0x80b5293a00000000, - 0x6248a1b700000000, 0xb5bc2aa300000000, 0x5741a22e00000000, - 0x30414a6300000000, 0xd2bcc2ee00000000, 0xfe419af800000000, - 0x1cbc127500000000, 0x7bbcfa3800000000, 0x994172b500000000, - 0x23464b1400000000, 0xc1bbc39900000000, 0xa6bb2bd400000000, - 0x4446a35900000000, 0x68bbfb4f00000000, 0x8a4673c200000000, - 0xed469b8f00000000, 0x0fbb130200000000, 0x43af8ca600000000, - 0xa152042b00000000, 0xc652ec6600000000, 0x24af64eb00000000, - 0x08523cfd00000000, 0xeaafb47000000000, 0x8daf5c3d00000000, - 0x6f52d4b000000000, 0xd555ed1100000000, 0x37a8659c00000000, - 0x50a88dd100000000, 0xb255055c00000000, 0x9ea85d4a00000000, - 0x7c55d5c700000000, 0x1b553d8a00000000, 0xf9a8b50700000000, - 0x2e5c3e1300000000, 0xcca1b69e00000000, 0xaba15ed300000000, - 0x495cd65e00000000, 0x65a18e4800000000, 0x875c06c500000000, - 0xe05cee8800000000, 0x02a1660500000000, 0xb8a65fa400000000, - 0x5a5bd72900000000, 0x3d5b3f6400000000, 0xdfa6b7e900000000, - 0xf35befff00000000, 0x11a6677200000000, 0x76a68f3f00000000, - 0x945b07b200000000}, - {0x0000000000000000, 0xa90b894e00000000, 0x5217129d00000000, - 0xfb1c9bd300000000, 0xe52855e100000000, 0x4c23dcaf00000000, - 0xb73f477c00000000, 0x1e34ce3200000000, 0x8b57db1900000000, - 0x225c525700000000, 0xd940c98400000000, 0x704b40ca00000000, - 0x6e7f8ef800000000, 0xc77407b600000000, 0x3c689c6500000000, - 0x9563152b00000000, 0x16afb63300000000, 0xbfa43f7d00000000, - 0x44b8a4ae00000000, 0xedb32de000000000, 0xf387e3d200000000, - 0x5a8c6a9c00000000, 0xa190f14f00000000, 0x089b780100000000, - 0x9df86d2a00000000, 0x34f3e46400000000, 0xcfef7fb700000000, - 0x66e4f6f900000000, 0x78d038cb00000000, 0xd1dbb18500000000, - 0x2ac72a5600000000, 0x83cca31800000000, 0x2c5e6d6700000000, - 0x8555e42900000000, 0x7e497ffa00000000, 0xd742f6b400000000, - 0xc976388600000000, 0x607db1c800000000, 0x9b612a1b00000000, - 0x326aa35500000000, 0xa709b67e00000000, 0x0e023f3000000000, - 0xf51ea4e300000000, 0x5c152dad00000000, 0x4221e39f00000000, - 0xeb2a6ad100000000, 0x1036f10200000000, 0xb93d784c00000000, - 0x3af1db5400000000, 0x93fa521a00000000, 0x68e6c9c900000000, - 0xc1ed408700000000, 0xdfd98eb500000000, 0x76d207fb00000000, - 0x8dce9c2800000000, 0x24c5156600000000, 0xb1a6004d00000000, - 0x18ad890300000000, 0xe3b112d000000000, 0x4aba9b9e00000000, - 0x548e55ac00000000, 0xfd85dce200000000, 0x0699473100000000, - 0xaf92ce7f00000000, 0x58bcdace00000000, 0xf1b7538000000000, - 0x0aabc85300000000, 0xa3a0411d00000000, 0xbd948f2f00000000, - 0x149f066100000000, 0xef839db200000000, 0x468814fc00000000, - 0xd3eb01d700000000, 0x7ae0889900000000, 0x81fc134a00000000, - 0x28f79a0400000000, 0x36c3543600000000, 0x9fc8dd7800000000, - 0x64d446ab00000000, 0xcddfcfe500000000, 0x4e136cfd00000000, - 0xe718e5b300000000, 0x1c047e6000000000, 0xb50ff72e00000000, - 0xab3b391c00000000, 0x0230b05200000000, 0xf92c2b8100000000, - 0x5027a2cf00000000, 0xc544b7e400000000, 0x6c4f3eaa00000000, - 0x9753a57900000000, 0x3e582c3700000000, 0x206ce20500000000, - 0x89676b4b00000000, 0x727bf09800000000, 0xdb7079d600000000, - 0x74e2b7a900000000, 0xdde93ee700000000, 0x26f5a53400000000, - 0x8ffe2c7a00000000, 0x91cae24800000000, 0x38c16b0600000000, - 0xc3ddf0d500000000, 0x6ad6799b00000000, 0xffb56cb000000000, - 0x56bee5fe00000000, 0xada27e2d00000000, 0x04a9f76300000000, - 0x1a9d395100000000, 0xb396b01f00000000, 0x488a2bcc00000000, - 0xe181a28200000000, 0x624d019a00000000, 0xcb4688d400000000, - 0x305a130700000000, 0x99519a4900000000, 0x8765547b00000000, - 0x2e6edd3500000000, 0xd57246e600000000, 0x7c79cfa800000000, - 0xe91ada8300000000, 0x401153cd00000000, 0xbb0dc81e00000000, - 0x1206415000000000, 0x0c328f6200000000, 0xa539062c00000000, - 0x5e259dff00000000, 0xf72e14b100000000, 0xf17ec44600000000, - 0x58754d0800000000, 0xa369d6db00000000, 0x0a625f9500000000, - 0x145691a700000000, 0xbd5d18e900000000, 0x4641833a00000000, - 0xef4a0a7400000000, 0x7a291f5f00000000, 0xd322961100000000, - 0x283e0dc200000000, 0x8135848c00000000, 0x9f014abe00000000, - 0x360ac3f000000000, 0xcd16582300000000, 0x641dd16d00000000, - 0xe7d1727500000000, 0x4edafb3b00000000, 0xb5c660e800000000, - 0x1ccde9a600000000, 0x02f9279400000000, 0xabf2aeda00000000, - 0x50ee350900000000, 0xf9e5bc4700000000, 0x6c86a96c00000000, - 0xc58d202200000000, 0x3e91bbf100000000, 0x979a32bf00000000, - 0x89aefc8d00000000, 0x20a575c300000000, 0xdbb9ee1000000000, - 0x72b2675e00000000, 0xdd20a92100000000, 0x742b206f00000000, - 0x8f37bbbc00000000, 0x263c32f200000000, 0x3808fcc000000000, - 0x9103758e00000000, 0x6a1fee5d00000000, 0xc314671300000000, - 0x5677723800000000, 0xff7cfb7600000000, 0x046060a500000000, - 0xad6be9eb00000000, 0xb35f27d900000000, 0x1a54ae9700000000, - 0xe148354400000000, 0x4843bc0a00000000, 0xcb8f1f1200000000, - 0x6284965c00000000, 0x99980d8f00000000, 0x309384c100000000, - 0x2ea74af300000000, 0x87acc3bd00000000, 0x7cb0586e00000000, - 0xd5bbd12000000000, 0x40d8c40b00000000, 0xe9d34d4500000000, - 0x12cfd69600000000, 0xbbc45fd800000000, 0xa5f091ea00000000, - 0x0cfb18a400000000, 0xf7e7837700000000, 0x5eec0a3900000000, - 0xa9c21e8800000000, 0x00c997c600000000, 0xfbd50c1500000000, - 0x52de855b00000000, 0x4cea4b6900000000, 0xe5e1c22700000000, - 0x1efd59f400000000, 0xb7f6d0ba00000000, 0x2295c59100000000, - 0x8b9e4cdf00000000, 0x7082d70c00000000, 0xd9895e4200000000, - 0xc7bd907000000000, 0x6eb6193e00000000, 0x95aa82ed00000000, - 0x3ca10ba300000000, 0xbf6da8bb00000000, 0x166621f500000000, - 0xed7aba2600000000, 0x4471336800000000, 0x5a45fd5a00000000, - 0xf34e741400000000, 0x0852efc700000000, 0xa159668900000000, - 0x343a73a200000000, 0x9d31faec00000000, 0x662d613f00000000, - 0xcf26e87100000000, 0xd112264300000000, 0x7819af0d00000000, - 0x830534de00000000, 0x2a0ebd9000000000, 0x859c73ef00000000, - 0x2c97faa100000000, 0xd78b617200000000, 0x7e80e83c00000000, - 0x60b4260e00000000, 0xc9bfaf4000000000, 0x32a3349300000000, - 0x9ba8bddd00000000, 0x0ecba8f600000000, 0xa7c021b800000000, - 0x5cdcba6b00000000, 0xf5d7332500000000, 0xebe3fd1700000000, - 0x42e8745900000000, 0xb9f4ef8a00000000, 0x10ff66c400000000, - 0x9333c5dc00000000, 0x3a384c9200000000, 0xc124d74100000000, - 0x682f5e0f00000000, 0x761b903d00000000, 0xdf10197300000000, - 0x240c82a000000000, 0x8d070bee00000000, 0x18641ec500000000, - 0xb16f978b00000000, 0x4a730c5800000000, 0xe378851600000000, - 0xfd4c4b2400000000, 0x5447c26a00000000, 0xaf5b59b900000000, - 0x0650d0f700000000}, - {0x0000000000000000, 0x479244af00000000, 0xcf22f88500000000, - 0x88b0bc2a00000000, 0xdf4381d000000000, 0x98d1c57f00000000, - 0x1061795500000000, 0x57f33dfa00000000, 0xff81737a00000000, - 0xb81337d500000000, 0x30a38bff00000000, 0x7731cf5000000000, - 0x20c2f2aa00000000, 0x6750b60500000000, 0xefe00a2f00000000, - 0xa8724e8000000000, 0xfe03e7f400000000, 0xb991a35b00000000, - 0x31211f7100000000, 0x76b35bde00000000, 0x2140662400000000, - 0x66d2228b00000000, 0xee629ea100000000, 0xa9f0da0e00000000, - 0x0182948e00000000, 0x4610d02100000000, 0xcea06c0b00000000, - 0x893228a400000000, 0xdec1155e00000000, 0x995351f100000000, - 0x11e3eddb00000000, 0x5671a97400000000, 0xbd01bf3200000000, - 0xfa93fb9d00000000, 0x722347b700000000, 0x35b1031800000000, - 0x62423ee200000000, 0x25d07a4d00000000, 0xad60c66700000000, - 0xeaf282c800000000, 0x4280cc4800000000, 0x051288e700000000, - 0x8da234cd00000000, 0xca30706200000000, 0x9dc34d9800000000, - 0xda51093700000000, 0x52e1b51d00000000, 0x1573f1b200000000, - 0x430258c600000000, 0x04901c6900000000, 0x8c20a04300000000, - 0xcbb2e4ec00000000, 0x9c41d91600000000, 0xdbd39db900000000, - 0x5363219300000000, 0x14f1653c00000000, 0xbc832bbc00000000, - 0xfb116f1300000000, 0x73a1d33900000000, 0x3433979600000000, - 0x63c0aa6c00000000, 0x2452eec300000000, 0xace252e900000000, - 0xeb70164600000000, 0x7a037e6500000000, 0x3d913aca00000000, - 0xb52186e000000000, 0xf2b3c24f00000000, 0xa540ffb500000000, - 0xe2d2bb1a00000000, 0x6a62073000000000, 0x2df0439f00000000, - 0x85820d1f00000000, 0xc21049b000000000, 0x4aa0f59a00000000, - 0x0d32b13500000000, 0x5ac18ccf00000000, 0x1d53c86000000000, - 0x95e3744a00000000, 0xd27130e500000000, 0x8400999100000000, - 0xc392dd3e00000000, 0x4b22611400000000, 0x0cb025bb00000000, - 0x5b43184100000000, 0x1cd15cee00000000, 0x9461e0c400000000, - 0xd3f3a46b00000000, 0x7b81eaeb00000000, 0x3c13ae4400000000, - 0xb4a3126e00000000, 0xf33156c100000000, 0xa4c26b3b00000000, - 0xe3502f9400000000, 0x6be093be00000000, 0x2c72d71100000000, - 0xc702c15700000000, 0x809085f800000000, 0x082039d200000000, - 0x4fb27d7d00000000, 0x1841408700000000, 0x5fd3042800000000, - 0xd763b80200000000, 0x90f1fcad00000000, 0x3883b22d00000000, - 0x7f11f68200000000, 0xf7a14aa800000000, 0xb0330e0700000000, - 0xe7c033fd00000000, 0xa052775200000000, 0x28e2cb7800000000, - 0x6f708fd700000000, 0x390126a300000000, 0x7e93620c00000000, - 0xf623de2600000000, 0xb1b19a8900000000, 0xe642a77300000000, - 0xa1d0e3dc00000000, 0x29605ff600000000, 0x6ef21b5900000000, - 0xc68055d900000000, 0x8112117600000000, 0x09a2ad5c00000000, - 0x4e30e9f300000000, 0x19c3d40900000000, 0x5e5190a600000000, - 0xd6e12c8c00000000, 0x9173682300000000, 0xf406fcca00000000, - 0xb394b86500000000, 0x3b24044f00000000, 0x7cb640e000000000, - 0x2b457d1a00000000, 0x6cd739b500000000, 0xe467859f00000000, - 0xa3f5c13000000000, 0x0b878fb000000000, 0x4c15cb1f00000000, - 0xc4a5773500000000, 0x8337339a00000000, 0xd4c40e6000000000, - 0x93564acf00000000, 0x1be6f6e500000000, 0x5c74b24a00000000, - 0x0a051b3e00000000, 0x4d975f9100000000, 0xc527e3bb00000000, - 0x82b5a71400000000, 0xd5469aee00000000, 0x92d4de4100000000, - 0x1a64626b00000000, 0x5df626c400000000, 0xf584684400000000, - 0xb2162ceb00000000, 0x3aa690c100000000, 0x7d34d46e00000000, - 0x2ac7e99400000000, 0x6d55ad3b00000000, 0xe5e5111100000000, - 0xa27755be00000000, 0x490743f800000000, 0x0e95075700000000, - 0x8625bb7d00000000, 0xc1b7ffd200000000, 0x9644c22800000000, - 0xd1d6868700000000, 0x59663aad00000000, 0x1ef47e0200000000, - 0xb686308200000000, 0xf114742d00000000, 0x79a4c80700000000, - 0x3e368ca800000000, 0x69c5b15200000000, 0x2e57f5fd00000000, - 0xa6e749d700000000, 0xe1750d7800000000, 0xb704a40c00000000, - 0xf096e0a300000000, 0x78265c8900000000, 0x3fb4182600000000, - 0x684725dc00000000, 0x2fd5617300000000, 0xa765dd5900000000, - 0xe0f799f600000000, 0x4885d77600000000, 0x0f1793d900000000, - 0x87a72ff300000000, 0xc0356b5c00000000, 0x97c656a600000000, - 0xd054120900000000, 0x58e4ae2300000000, 0x1f76ea8c00000000, - 0x8e0582af00000000, 0xc997c60000000000, 0x41277a2a00000000, - 0x06b53e8500000000, 0x5146037f00000000, 0x16d447d000000000, - 0x9e64fbfa00000000, 0xd9f6bf5500000000, 0x7184f1d500000000, - 0x3616b57a00000000, 0xbea6095000000000, 0xf9344dff00000000, - 0xaec7700500000000, 0xe95534aa00000000, 0x61e5888000000000, - 0x2677cc2f00000000, 0x7006655b00000000, 0x379421f400000000, - 0xbf249dde00000000, 0xf8b6d97100000000, 0xaf45e48b00000000, - 0xe8d7a02400000000, 0x60671c0e00000000, 0x27f558a100000000, - 0x8f87162100000000, 0xc815528e00000000, 0x40a5eea400000000, - 0x0737aa0b00000000, 0x50c497f100000000, 0x1756d35e00000000, - 0x9fe66f7400000000, 0xd8742bdb00000000, 0x33043d9d00000000, - 0x7496793200000000, 0xfc26c51800000000, 0xbbb481b700000000, - 0xec47bc4d00000000, 0xabd5f8e200000000, 0x236544c800000000, - 0x64f7006700000000, 0xcc854ee700000000, 0x8b170a4800000000, - 0x03a7b66200000000, 0x4435f2cd00000000, 0x13c6cf3700000000, - 0x54548b9800000000, 0xdce437b200000000, 0x9b76731d00000000, - 0xcd07da6900000000, 0x8a959ec600000000, 0x022522ec00000000, - 0x45b7664300000000, 0x12445bb900000000, 0x55d61f1600000000, - 0xdd66a33c00000000, 0x9af4e79300000000, 0x3286a91300000000, - 0x7514edbc00000000, 0xfda4519600000000, 0xba36153900000000, - 0xedc528c300000000, 0xaa576c6c00000000, 0x22e7d04600000000, - 0x657594e900000000}}; - -#else /* W == 4 */ - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0x65673b46, 0xcace768c, 0xafa94dca, 0x4eedeb59, - 0x2b8ad01f, 0x84239dd5, 0xe144a693, 0x9ddbd6b2, 0xf8bcedf4, - 0x5715a03e, 0x32729b78, 0xd3363deb, 0xb65106ad, 0x19f84b67, - 0x7c9f7021, 0xe0c6ab25, 0x85a19063, 0x2a08dda9, 0x4f6fe6ef, - 0xae2b407c, 0xcb4c7b3a, 0x64e536f0, 0x01820db6, 0x7d1d7d97, - 0x187a46d1, 0xb7d30b1b, 0xd2b4305d, 0x33f096ce, 0x5697ad88, - 0xf93ee042, 0x9c59db04, 0x1afc500b, 0x7f9b6b4d, 0xd0322687, - 0xb5551dc1, 0x5411bb52, 0x31768014, 0x9edfcdde, 0xfbb8f698, - 0x872786b9, 0xe240bdff, 0x4de9f035, 0x288ecb73, 0xc9ca6de0, - 0xacad56a6, 0x03041b6c, 0x6663202a, 0xfa3afb2e, 0x9f5dc068, - 0x30f48da2, 0x5593b6e4, 0xb4d71077, 0xd1b02b31, 0x7e1966fb, - 0x1b7e5dbd, 0x67e12d9c, 0x028616da, 0xad2f5b10, 0xc8486056, - 0x290cc6c5, 0x4c6bfd83, 0xe3c2b049, 0x86a58b0f, 0x35f8a016, - 0x509f9b50, 0xff36d69a, 0x9a51eddc, 0x7b154b4f, 0x1e727009, - 0xb1db3dc3, 0xd4bc0685, 0xa82376a4, 0xcd444de2, 0x62ed0028, - 0x078a3b6e, 0xe6ce9dfd, 0x83a9a6bb, 0x2c00eb71, 0x4967d037, - 0xd53e0b33, 0xb0593075, 0x1ff07dbf, 0x7a9746f9, 0x9bd3e06a, - 0xfeb4db2c, 0x511d96e6, 0x347aada0, 0x48e5dd81, 0x2d82e6c7, - 0x822bab0d, 0xe74c904b, 0x060836d8, 0x636f0d9e, 0xccc64054, - 0xa9a17b12, 0x2f04f01d, 0x4a63cb5b, 0xe5ca8691, 0x80adbdd7, - 0x61e91b44, 0x048e2002, 0xab276dc8, 0xce40568e, 0xb2df26af, - 0xd7b81de9, 0x78115023, 0x1d766b65, 0xfc32cdf6, 0x9955f6b0, - 0x36fcbb7a, 0x539b803c, 0xcfc25b38, 0xaaa5607e, 0x050c2db4, - 0x606b16f2, 0x812fb061, 0xe4488b27, 0x4be1c6ed, 0x2e86fdab, - 0x52198d8a, 0x377eb6cc, 0x98d7fb06, 0xfdb0c040, 0x1cf466d3, - 0x79935d95, 0xd63a105f, 0xb35d2b19, 0x6bf1402c, 0x0e967b6a, - 0xa13f36a0, 0xc4580de6, 0x251cab75, 0x407b9033, 0xefd2ddf9, - 0x8ab5e6bf, 0xf62a969e, 0x934dadd8, 0x3ce4e012, 0x5983db54, - 0xb8c77dc7, 0xdda04681, 0x72090b4b, 0x176e300d, 0x8b37eb09, - 0xee50d04f, 0x41f99d85, 0x249ea6c3, 0xc5da0050, 0xa0bd3b16, - 0x0f1476dc, 0x6a734d9a, 0x16ec3dbb, 0x738b06fd, 0xdc224b37, - 0xb9457071, 0x5801d6e2, 0x3d66eda4, 0x92cfa06e, 0xf7a89b28, - 0x710d1027, 0x146a2b61, 0xbbc366ab, 0xdea45ded, 0x3fe0fb7e, - 0x5a87c038, 0xf52e8df2, 0x9049b6b4, 0xecd6c695, 0x89b1fdd3, - 0x2618b019, 0x437f8b5f, 0xa23b2dcc, 0xc75c168a, 0x68f55b40, - 0x0d926006, 0x91cbbb02, 0xf4ac8044, 0x5b05cd8e, 0x3e62f6c8, - 0xdf26505b, 0xba416b1d, 0x15e826d7, 0x708f1d91, 0x0c106db0, - 0x697756f6, 0xc6de1b3c, 0xa3b9207a, 0x42fd86e9, 0x279abdaf, - 0x8833f065, 0xed54cb23, 0x5e09e03a, 0x3b6edb7c, 0x94c796b6, - 0xf1a0adf0, 0x10e40b63, 0x75833025, 0xda2a7def, 0xbf4d46a9, - 0xc3d23688, 0xa6b50dce, 0x091c4004, 0x6c7b7b42, 0x8d3fddd1, - 0xe858e697, 0x47f1ab5d, 0x2296901b, 0xbecf4b1f, 0xdba87059, - 0x74013d93, 0x116606d5, 0xf022a046, 0x95459b00, 0x3aecd6ca, - 0x5f8bed8c, 0x23149dad, 0x4673a6eb, 0xe9daeb21, 0x8cbdd067, - 0x6df976f4, 0x089e4db2, 0xa7370078, 0xc2503b3e, 0x44f5b031, - 0x21928b77, 0x8e3bc6bd, 0xeb5cfdfb, 0x0a185b68, 0x6f7f602e, - 0xc0d62de4, 0xa5b116a2, 0xd92e6683, 0xbc495dc5, 0x13e0100f, - 0x76872b49, 0x97c38dda, 0xf2a4b69c, 0x5d0dfb56, 0x386ac010, - 0xa4331b14, 0xc1542052, 0x6efd6d98, 0x0b9a56de, 0xeadef04d, - 0x8fb9cb0b, 0x201086c1, 0x4577bd87, 0x39e8cda6, 0x5c8ff6e0, - 0xf326bb2a, 0x9641806c, 0x770526ff, 0x12621db9, 0xbdcb5073, - 0xd8ac6b35}, - {0x00000000, 0xd7e28058, 0x74b406f1, 0xa35686a9, 0xe9680de2, - 0x3e8a8dba, 0x9ddc0b13, 0x4a3e8b4b, 0x09a11d85, 0xde439ddd, - 0x7d151b74, 0xaaf79b2c, 0xe0c91067, 0x372b903f, 0x947d1696, - 0x439f96ce, 0x13423b0a, 0xc4a0bb52, 0x67f63dfb, 0xb014bda3, - 0xfa2a36e8, 0x2dc8b6b0, 0x8e9e3019, 0x597cb041, 0x1ae3268f, - 0xcd01a6d7, 0x6e57207e, 0xb9b5a026, 0xf38b2b6d, 0x2469ab35, - 0x873f2d9c, 0x50ddadc4, 0x26847614, 0xf166f64c, 0x523070e5, - 0x85d2f0bd, 0xcfec7bf6, 0x180efbae, 0xbb587d07, 0x6cbafd5f, - 0x2f256b91, 0xf8c7ebc9, 0x5b916d60, 0x8c73ed38, 0xc64d6673, - 0x11afe62b, 0xb2f96082, 0x651be0da, 0x35c64d1e, 0xe224cd46, - 0x41724bef, 0x9690cbb7, 0xdcae40fc, 0x0b4cc0a4, 0xa81a460d, - 0x7ff8c655, 0x3c67509b, 0xeb85d0c3, 0x48d3566a, 0x9f31d632, - 0xd50f5d79, 0x02eddd21, 0xa1bb5b88, 0x7659dbd0, 0x4d08ec28, - 0x9aea6c70, 0x39bcead9, 0xee5e6a81, 0xa460e1ca, 0x73826192, - 0xd0d4e73b, 0x07366763, 0x44a9f1ad, 0x934b71f5, 0x301df75c, - 0xe7ff7704, 0xadc1fc4f, 0x7a237c17, 0xd975fabe, 0x0e977ae6, - 0x5e4ad722, 0x89a8577a, 0x2afed1d3, 0xfd1c518b, 0xb722dac0, - 0x60c05a98, 0xc396dc31, 0x14745c69, 0x57ebcaa7, 0x80094aff, - 0x235fcc56, 0xf4bd4c0e, 0xbe83c745, 0x6961471d, 0xca37c1b4, - 0x1dd541ec, 0x6b8c9a3c, 0xbc6e1a64, 0x1f389ccd, 0xc8da1c95, - 0x82e497de, 0x55061786, 0xf650912f, 0x21b21177, 0x622d87b9, - 0xb5cf07e1, 0x16998148, 0xc17b0110, 0x8b458a5b, 0x5ca70a03, - 0xfff18caa, 0x28130cf2, 0x78cea136, 0xaf2c216e, 0x0c7aa7c7, - 0xdb98279f, 0x91a6acd4, 0x46442c8c, 0xe512aa25, 0x32f02a7d, - 0x716fbcb3, 0xa68d3ceb, 0x05dbba42, 0xd2393a1a, 0x9807b151, - 0x4fe53109, 0xecb3b7a0, 0x3b5137f8, 0x9a11d850, 0x4df35808, - 0xeea5dea1, 0x39475ef9, 0x7379d5b2, 0xa49b55ea, 0x07cdd343, - 0xd02f531b, 0x93b0c5d5, 0x4452458d, 0xe704c324, 0x30e6437c, - 0x7ad8c837, 0xad3a486f, 0x0e6ccec6, 0xd98e4e9e, 0x8953e35a, - 0x5eb16302, 0xfde7e5ab, 0x2a0565f3, 0x603beeb8, 0xb7d96ee0, - 0x148fe849, 0xc36d6811, 0x80f2fedf, 0x57107e87, 0xf446f82e, - 0x23a47876, 0x699af33d, 0xbe787365, 0x1d2ef5cc, 0xcacc7594, - 0xbc95ae44, 0x6b772e1c, 0xc821a8b5, 0x1fc328ed, 0x55fda3a6, - 0x821f23fe, 0x2149a557, 0xf6ab250f, 0xb534b3c1, 0x62d63399, - 0xc180b530, 0x16623568, 0x5c5cbe23, 0x8bbe3e7b, 0x28e8b8d2, - 0xff0a388a, 0xafd7954e, 0x78351516, 0xdb6393bf, 0x0c8113e7, - 0x46bf98ac, 0x915d18f4, 0x320b9e5d, 0xe5e91e05, 0xa67688cb, - 0x71940893, 0xd2c28e3a, 0x05200e62, 0x4f1e8529, 0x98fc0571, - 0x3baa83d8, 0xec480380, 0xd7193478, 0x00fbb420, 0xa3ad3289, - 0x744fb2d1, 0x3e71399a, 0xe993b9c2, 0x4ac53f6b, 0x9d27bf33, - 0xdeb829fd, 0x095aa9a5, 0xaa0c2f0c, 0x7deeaf54, 0x37d0241f, - 0xe032a447, 0x436422ee, 0x9486a2b6, 0xc45b0f72, 0x13b98f2a, - 0xb0ef0983, 0x670d89db, 0x2d330290, 0xfad182c8, 0x59870461, - 0x8e658439, 0xcdfa12f7, 0x1a1892af, 0xb94e1406, 0x6eac945e, - 0x24921f15, 0xf3709f4d, 0x502619e4, 0x87c499bc, 0xf19d426c, - 0x267fc234, 0x8529449d, 0x52cbc4c5, 0x18f54f8e, 0xcf17cfd6, - 0x6c41497f, 0xbba3c927, 0xf83c5fe9, 0x2fdedfb1, 0x8c885918, - 0x5b6ad940, 0x1154520b, 0xc6b6d253, 0x65e054fa, 0xb202d4a2, - 0xe2df7966, 0x353df93e, 0x966b7f97, 0x4189ffcf, 0x0bb77484, - 0xdc55f4dc, 0x7f037275, 0xa8e1f22d, 0xeb7e64e3, 0x3c9ce4bb, - 0x9fca6212, 0x4828e24a, 0x02166901, 0xd5f4e959, 0x76a26ff0, - 0xa140efa8}, - {0x00000000, 0xef52b6e1, 0x05d46b83, 0xea86dd62, 0x0ba8d706, - 0xe4fa61e7, 0x0e7cbc85, 0xe12e0a64, 0x1751ae0c, 0xf80318ed, - 0x1285c58f, 0xfdd7736e, 0x1cf9790a, 0xf3abcfeb, 0x192d1289, - 0xf67fa468, 0x2ea35c18, 0xc1f1eaf9, 0x2b77379b, 0xc425817a, - 0x250b8b1e, 0xca593dff, 0x20dfe09d, 0xcf8d567c, 0x39f2f214, - 0xd6a044f5, 0x3c269997, 0xd3742f76, 0x325a2512, 0xdd0893f3, - 0x378e4e91, 0xd8dcf870, 0x5d46b830, 0xb2140ed1, 0x5892d3b3, - 0xb7c06552, 0x56ee6f36, 0xb9bcd9d7, 0x533a04b5, 0xbc68b254, - 0x4a17163c, 0xa545a0dd, 0x4fc37dbf, 0xa091cb5e, 0x41bfc13a, - 0xaeed77db, 0x446baab9, 0xab391c58, 0x73e5e428, 0x9cb752c9, - 0x76318fab, 0x9963394a, 0x784d332e, 0x971f85cf, 0x7d9958ad, - 0x92cbee4c, 0x64b44a24, 0x8be6fcc5, 0x616021a7, 0x8e329746, - 0x6f1c9d22, 0x804e2bc3, 0x6ac8f6a1, 0x859a4040, 0xba8d7060, - 0x55dfc681, 0xbf591be3, 0x500bad02, 0xb125a766, 0x5e771187, - 0xb4f1cce5, 0x5ba37a04, 0xaddcde6c, 0x428e688d, 0xa808b5ef, - 0x475a030e, 0xa674096a, 0x4926bf8b, 0xa3a062e9, 0x4cf2d408, - 0x942e2c78, 0x7b7c9a99, 0x91fa47fb, 0x7ea8f11a, 0x9f86fb7e, - 0x70d44d9f, 0x9a5290fd, 0x7500261c, 0x837f8274, 0x6c2d3495, - 0x86abe9f7, 0x69f95f16, 0x88d75572, 0x6785e393, 0x8d033ef1, - 0x62518810, 0xe7cbc850, 0x08997eb1, 0xe21fa3d3, 0x0d4d1532, - 0xec631f56, 0x0331a9b7, 0xe9b774d5, 0x06e5c234, 0xf09a665c, - 0x1fc8d0bd, 0xf54e0ddf, 0x1a1cbb3e, 0xfb32b15a, 0x146007bb, - 0xfee6dad9, 0x11b46c38, 0xc9689448, 0x263a22a9, 0xccbcffcb, - 0x23ee492a, 0xc2c0434e, 0x2d92f5af, 0xc71428cd, 0x28469e2c, - 0xde393a44, 0x316b8ca5, 0xdbed51c7, 0x34bfe726, 0xd591ed42, - 0x3ac35ba3, 0xd04586c1, 0x3f173020, 0xae6be681, 0x41395060, - 0xabbf8d02, 0x44ed3be3, 0xa5c33187, 0x4a918766, 0xa0175a04, - 0x4f45ece5, 0xb93a488d, 0x5668fe6c, 0xbcee230e, 0x53bc95ef, - 0xb2929f8b, 0x5dc0296a, 0xb746f408, 0x581442e9, 0x80c8ba99, - 0x6f9a0c78, 0x851cd11a, 0x6a4e67fb, 0x8b606d9f, 0x6432db7e, - 0x8eb4061c, 0x61e6b0fd, 0x97991495, 0x78cba274, 0x924d7f16, - 0x7d1fc9f7, 0x9c31c393, 0x73637572, 0x99e5a810, 0x76b71ef1, - 0xf32d5eb1, 0x1c7fe850, 0xf6f93532, 0x19ab83d3, 0xf88589b7, - 0x17d73f56, 0xfd51e234, 0x120354d5, 0xe47cf0bd, 0x0b2e465c, - 0xe1a89b3e, 0x0efa2ddf, 0xefd427bb, 0x0086915a, 0xea004c38, - 0x0552fad9, 0xdd8e02a9, 0x32dcb448, 0xd85a692a, 0x3708dfcb, - 0xd626d5af, 0x3974634e, 0xd3f2be2c, 0x3ca008cd, 0xcadfaca5, - 0x258d1a44, 0xcf0bc726, 0x205971c7, 0xc1777ba3, 0x2e25cd42, - 0xc4a31020, 0x2bf1a6c1, 0x14e696e1, 0xfbb42000, 0x1132fd62, - 0xfe604b83, 0x1f4e41e7, 0xf01cf706, 0x1a9a2a64, 0xf5c89c85, - 0x03b738ed, 0xece58e0c, 0x0663536e, 0xe931e58f, 0x081fefeb, - 0xe74d590a, 0x0dcb8468, 0xe2993289, 0x3a45caf9, 0xd5177c18, - 0x3f91a17a, 0xd0c3179b, 0x31ed1dff, 0xdebfab1e, 0x3439767c, - 0xdb6bc09d, 0x2d1464f5, 0xc246d214, 0x28c00f76, 0xc792b997, - 0x26bcb3f3, 0xc9ee0512, 0x2368d870, 0xcc3a6e91, 0x49a02ed1, - 0xa6f29830, 0x4c744552, 0xa326f3b3, 0x4208f9d7, 0xad5a4f36, - 0x47dc9254, 0xa88e24b5, 0x5ef180dd, 0xb1a3363c, 0x5b25eb5e, - 0xb4775dbf, 0x555957db, 0xba0be13a, 0x508d3c58, 0xbfdf8ab9, - 0x670372c9, 0x8851c428, 0x62d7194a, 0x8d85afab, 0x6caba5cf, - 0x83f9132e, 0x697fce4c, 0x862d78ad, 0x7052dcc5, 0x9f006a24, - 0x7586b746, 0x9ad401a7, 0x7bfa0bc3, 0x94a8bd22, 0x7e2e6040, - 0x917cd6a1}, - {0x00000000, 0x87a6cb43, 0xd43c90c7, 0x539a5b84, 0x730827cf, - 0xf4aeec8c, 0xa734b708, 0x20927c4b, 0xe6104f9e, 0x61b684dd, - 0x322cdf59, 0xb58a141a, 0x95186851, 0x12bea312, 0x4124f896, - 0xc68233d5, 0x1751997d, 0x90f7523e, 0xc36d09ba, 0x44cbc2f9, - 0x6459beb2, 0xe3ff75f1, 0xb0652e75, 0x37c3e536, 0xf141d6e3, - 0x76e71da0, 0x257d4624, 0xa2db8d67, 0x8249f12c, 0x05ef3a6f, - 0x567561eb, 0xd1d3aaa8, 0x2ea332fa, 0xa905f9b9, 0xfa9fa23d, - 0x7d39697e, 0x5dab1535, 0xda0dde76, 0x899785f2, 0x0e314eb1, - 0xc8b37d64, 0x4f15b627, 0x1c8feda3, 0x9b2926e0, 0xbbbb5aab, - 0x3c1d91e8, 0x6f87ca6c, 0xe821012f, 0x39f2ab87, 0xbe5460c4, - 0xedce3b40, 0x6a68f003, 0x4afa8c48, 0xcd5c470b, 0x9ec61c8f, - 0x1960d7cc, 0xdfe2e419, 0x58442f5a, 0x0bde74de, 0x8c78bf9d, - 0xaceac3d6, 0x2b4c0895, 0x78d65311, 0xff709852, 0x5d4665f4, - 0xdae0aeb7, 0x897af533, 0x0edc3e70, 0x2e4e423b, 0xa9e88978, - 0xfa72d2fc, 0x7dd419bf, 0xbb562a6a, 0x3cf0e129, 0x6f6abaad, - 0xe8cc71ee, 0xc85e0da5, 0x4ff8c6e6, 0x1c629d62, 0x9bc45621, - 0x4a17fc89, 0xcdb137ca, 0x9e2b6c4e, 0x198da70d, 0x391fdb46, - 0xbeb91005, 0xed234b81, 0x6a8580c2, 0xac07b317, 0x2ba17854, - 0x783b23d0, 0xff9de893, 0xdf0f94d8, 0x58a95f9b, 0x0b33041f, - 0x8c95cf5c, 0x73e5570e, 0xf4439c4d, 0xa7d9c7c9, 0x207f0c8a, - 0x00ed70c1, 0x874bbb82, 0xd4d1e006, 0x53772b45, 0x95f51890, - 0x1253d3d3, 0x41c98857, 0xc66f4314, 0xe6fd3f5f, 0x615bf41c, - 0x32c1af98, 0xb56764db, 0x64b4ce73, 0xe3120530, 0xb0885eb4, - 0x372e95f7, 0x17bce9bc, 0x901a22ff, 0xc380797b, 0x4426b238, - 0x82a481ed, 0x05024aae, 0x5698112a, 0xd13eda69, 0xf1aca622, - 0x760a6d61, 0x259036e5, 0xa236fda6, 0xba8ccbe8, 0x3d2a00ab, - 0x6eb05b2f, 0xe916906c, 0xc984ec27, 0x4e222764, 0x1db87ce0, - 0x9a1eb7a3, 0x5c9c8476, 0xdb3a4f35, 0x88a014b1, 0x0f06dff2, - 0x2f94a3b9, 0xa83268fa, 0xfba8337e, 0x7c0ef83d, 0xaddd5295, - 0x2a7b99d6, 0x79e1c252, 0xfe470911, 0xded5755a, 0x5973be19, - 0x0ae9e59d, 0x8d4f2ede, 0x4bcd1d0b, 0xcc6bd648, 0x9ff18dcc, - 0x1857468f, 0x38c53ac4, 0xbf63f187, 0xecf9aa03, 0x6b5f6140, - 0x942ff912, 0x13893251, 0x401369d5, 0xc7b5a296, 0xe727dedd, - 0x6081159e, 0x331b4e1a, 0xb4bd8559, 0x723fb68c, 0xf5997dcf, - 0xa603264b, 0x21a5ed08, 0x01379143, 0x86915a00, 0xd50b0184, - 0x52adcac7, 0x837e606f, 0x04d8ab2c, 0x5742f0a8, 0xd0e43beb, - 0xf07647a0, 0x77d08ce3, 0x244ad767, 0xa3ec1c24, 0x656e2ff1, - 0xe2c8e4b2, 0xb152bf36, 0x36f47475, 0x1666083e, 0x91c0c37d, - 0xc25a98f9, 0x45fc53ba, 0xe7caae1c, 0x606c655f, 0x33f63edb, - 0xb450f598, 0x94c289d3, 0x13644290, 0x40fe1914, 0xc758d257, - 0x01dae182, 0x867c2ac1, 0xd5e67145, 0x5240ba06, 0x72d2c64d, - 0xf5740d0e, 0xa6ee568a, 0x21489dc9, 0xf09b3761, 0x773dfc22, - 0x24a7a7a6, 0xa3016ce5, 0x839310ae, 0x0435dbed, 0x57af8069, - 0xd0094b2a, 0x168b78ff, 0x912db3bc, 0xc2b7e838, 0x4511237b, - 0x65835f30, 0xe2259473, 0xb1bfcff7, 0x361904b4, 0xc9699ce6, - 0x4ecf57a5, 0x1d550c21, 0x9af3c762, 0xba61bb29, 0x3dc7706a, - 0x6e5d2bee, 0xe9fbe0ad, 0x2f79d378, 0xa8df183b, 0xfb4543bf, - 0x7ce388fc, 0x5c71f4b7, 0xdbd73ff4, 0x884d6470, 0x0febaf33, - 0xde38059b, 0x599eced8, 0x0a04955c, 0x8da25e1f, 0xad302254, - 0x2a96e917, 0x790cb293, 0xfeaa79d0, 0x38284a05, 0xbf8e8146, - 0xec14dac2, 0x6bb21181, 0x4b206dca, 0xcc86a689, 0x9f1cfd0d, - 0x18ba364e}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x00000000, 0x43cba687, 0xc7903cd4, 0x845b9a53, 0xcf270873, - 0x8cecaef4, 0x08b734a7, 0x4b7c9220, 0x9e4f10e6, 0xdd84b661, - 0x59df2c32, 0x1a148ab5, 0x51681895, 0x12a3be12, 0x96f82441, - 0xd53382c6, 0x7d995117, 0x3e52f790, 0xba096dc3, 0xf9c2cb44, - 0xb2be5964, 0xf175ffe3, 0x752e65b0, 0x36e5c337, 0xe3d641f1, - 0xa01de776, 0x24467d25, 0x678ddba2, 0x2cf14982, 0x6f3aef05, - 0xeb617556, 0xa8aad3d1, 0xfa32a32e, 0xb9f905a9, 0x3da29ffa, - 0x7e69397d, 0x3515ab5d, 0x76de0dda, 0xf2859789, 0xb14e310e, - 0x647db3c8, 0x27b6154f, 0xa3ed8f1c, 0xe026299b, 0xab5abbbb, - 0xe8911d3c, 0x6cca876f, 0x2f0121e8, 0x87abf239, 0xc46054be, - 0x403bceed, 0x03f0686a, 0x488cfa4a, 0x0b475ccd, 0x8f1cc69e, - 0xccd76019, 0x19e4e2df, 0x5a2f4458, 0xde74de0b, 0x9dbf788c, - 0xd6c3eaac, 0x95084c2b, 0x1153d678, 0x529870ff, 0xf465465d, - 0xb7aee0da, 0x33f57a89, 0x703edc0e, 0x3b424e2e, 0x7889e8a9, - 0xfcd272fa, 0xbf19d47d, 0x6a2a56bb, 0x29e1f03c, 0xadba6a6f, - 0xee71cce8, 0xa50d5ec8, 0xe6c6f84f, 0x629d621c, 0x2156c49b, - 0x89fc174a, 0xca37b1cd, 0x4e6c2b9e, 0x0da78d19, 0x46db1f39, - 0x0510b9be, 0x814b23ed, 0xc280856a, 0x17b307ac, 0x5478a12b, - 0xd0233b78, 0x93e89dff, 0xd8940fdf, 0x9b5fa958, 0x1f04330b, - 0x5ccf958c, 0x0e57e573, 0x4d9c43f4, 0xc9c7d9a7, 0x8a0c7f20, - 0xc170ed00, 0x82bb4b87, 0x06e0d1d4, 0x452b7753, 0x9018f595, - 0xd3d35312, 0x5788c941, 0x14436fc6, 0x5f3ffde6, 0x1cf45b61, - 0x98afc132, 0xdb6467b5, 0x73ceb464, 0x300512e3, 0xb45e88b0, - 0xf7952e37, 0xbce9bc17, 0xff221a90, 0x7b7980c3, 0x38b22644, - 0xed81a482, 0xae4a0205, 0x2a119856, 0x69da3ed1, 0x22a6acf1, - 0x616d0a76, 0xe5369025, 0xa6fd36a2, 0xe8cb8cba, 0xab002a3d, - 0x2f5bb06e, 0x6c9016e9, 0x27ec84c9, 0x6427224e, 0xe07cb81d, - 0xa3b71e9a, 0x76849c5c, 0x354f3adb, 0xb114a088, 0xf2df060f, - 0xb9a3942f, 0xfa6832a8, 0x7e33a8fb, 0x3df80e7c, 0x9552ddad, - 0xd6997b2a, 0x52c2e179, 0x110947fe, 0x5a75d5de, 0x19be7359, - 0x9de5e90a, 0xde2e4f8d, 0x0b1dcd4b, 0x48d66bcc, 0xcc8df19f, - 0x8f465718, 0xc43ac538, 0x87f163bf, 0x03aaf9ec, 0x40615f6b, - 0x12f92f94, 0x51328913, 0xd5691340, 0x96a2b5c7, 0xddde27e7, - 0x9e158160, 0x1a4e1b33, 0x5985bdb4, 0x8cb63f72, 0xcf7d99f5, - 0x4b2603a6, 0x08eda521, 0x43913701, 0x005a9186, 0x84010bd5, - 0xc7caad52, 0x6f607e83, 0x2cabd804, 0xa8f04257, 0xeb3be4d0, - 0xa04776f0, 0xe38cd077, 0x67d74a24, 0x241ceca3, 0xf12f6e65, - 0xb2e4c8e2, 0x36bf52b1, 0x7574f436, 0x3e086616, 0x7dc3c091, - 0xf9985ac2, 0xba53fc45, 0x1caecae7, 0x5f656c60, 0xdb3ef633, - 0x98f550b4, 0xd389c294, 0x90426413, 0x1419fe40, 0x57d258c7, - 0x82e1da01, 0xc12a7c86, 0x4571e6d5, 0x06ba4052, 0x4dc6d272, - 0x0e0d74f5, 0x8a56eea6, 0xc99d4821, 0x61379bf0, 0x22fc3d77, - 0xa6a7a724, 0xe56c01a3, 0xae109383, 0xeddb3504, 0x6980af57, - 0x2a4b09d0, 0xff788b16, 0xbcb32d91, 0x38e8b7c2, 0x7b231145, - 0x305f8365, 0x739425e2, 0xf7cfbfb1, 0xb4041936, 0xe69c69c9, - 0xa557cf4e, 0x210c551d, 0x62c7f39a, 0x29bb61ba, 0x6a70c73d, - 0xee2b5d6e, 0xade0fbe9, 0x78d3792f, 0x3b18dfa8, 0xbf4345fb, - 0xfc88e37c, 0xb7f4715c, 0xf43fd7db, 0x70644d88, 0x33afeb0f, - 0x9b0538de, 0xd8ce9e59, 0x5c95040a, 0x1f5ea28d, 0x542230ad, - 0x17e9962a, 0x93b20c79, 0xd079aafe, 0x054a2838, 0x46818ebf, - 0xc2da14ec, 0x8111b26b, 0xca6d204b, 0x89a686cc, 0x0dfd1c9f, - 0x4e36ba18}, - {0x00000000, 0xe1b652ef, 0x836bd405, 0x62dd86ea, 0x06d7a80b, - 0xe761fae4, 0x85bc7c0e, 0x640a2ee1, 0x0cae5117, 0xed1803f8, - 0x8fc58512, 0x6e73d7fd, 0x0a79f91c, 0xebcfabf3, 0x89122d19, - 0x68a47ff6, 0x185ca32e, 0xf9eaf1c1, 0x9b37772b, 0x7a8125c4, - 0x1e8b0b25, 0xff3d59ca, 0x9de0df20, 0x7c568dcf, 0x14f2f239, - 0xf544a0d6, 0x9799263c, 0x762f74d3, 0x12255a32, 0xf39308dd, - 0x914e8e37, 0x70f8dcd8, 0x30b8465d, 0xd10e14b2, 0xb3d39258, - 0x5265c0b7, 0x366fee56, 0xd7d9bcb9, 0xb5043a53, 0x54b268bc, - 0x3c16174a, 0xdda045a5, 0xbf7dc34f, 0x5ecb91a0, 0x3ac1bf41, - 0xdb77edae, 0xb9aa6b44, 0x581c39ab, 0x28e4e573, 0xc952b79c, - 0xab8f3176, 0x4a396399, 0x2e334d78, 0xcf851f97, 0xad58997d, - 0x4ceecb92, 0x244ab464, 0xc5fce68b, 0xa7216061, 0x4697328e, - 0x229d1c6f, 0xc32b4e80, 0xa1f6c86a, 0x40409a85, 0x60708dba, - 0x81c6df55, 0xe31b59bf, 0x02ad0b50, 0x66a725b1, 0x8711775e, - 0xe5ccf1b4, 0x047aa35b, 0x6cdedcad, 0x8d688e42, 0xefb508a8, - 0x0e035a47, 0x6a0974a6, 0x8bbf2649, 0xe962a0a3, 0x08d4f24c, - 0x782c2e94, 0x999a7c7b, 0xfb47fa91, 0x1af1a87e, 0x7efb869f, - 0x9f4dd470, 0xfd90529a, 0x1c260075, 0x74827f83, 0x95342d6c, - 0xf7e9ab86, 0x165ff969, 0x7255d788, 0x93e38567, 0xf13e038d, - 0x10885162, 0x50c8cbe7, 0xb17e9908, 0xd3a31fe2, 0x32154d0d, - 0x561f63ec, 0xb7a93103, 0xd574b7e9, 0x34c2e506, 0x5c669af0, - 0xbdd0c81f, 0xdf0d4ef5, 0x3ebb1c1a, 0x5ab132fb, 0xbb076014, - 0xd9dae6fe, 0x386cb411, 0x489468c9, 0xa9223a26, 0xcbffbccc, - 0x2a49ee23, 0x4e43c0c2, 0xaff5922d, 0xcd2814c7, 0x2c9e4628, - 0x443a39de, 0xa58c6b31, 0xc751eddb, 0x26e7bf34, 0x42ed91d5, - 0xa35bc33a, 0xc18645d0, 0x2030173f, 0x81e66bae, 0x60503941, - 0x028dbfab, 0xe33bed44, 0x8731c3a5, 0x6687914a, 0x045a17a0, - 0xe5ec454f, 0x8d483ab9, 0x6cfe6856, 0x0e23eebc, 0xef95bc53, - 0x8b9f92b2, 0x6a29c05d, 0x08f446b7, 0xe9421458, 0x99bac880, - 0x780c9a6f, 0x1ad11c85, 0xfb674e6a, 0x9f6d608b, 0x7edb3264, - 0x1c06b48e, 0xfdb0e661, 0x95149997, 0x74a2cb78, 0x167f4d92, - 0xf7c91f7d, 0x93c3319c, 0x72756373, 0x10a8e599, 0xf11eb776, - 0xb15e2df3, 0x50e87f1c, 0x3235f9f6, 0xd383ab19, 0xb78985f8, - 0x563fd717, 0x34e251fd, 0xd5540312, 0xbdf07ce4, 0x5c462e0b, - 0x3e9ba8e1, 0xdf2dfa0e, 0xbb27d4ef, 0x5a918600, 0x384c00ea, - 0xd9fa5205, 0xa9028edd, 0x48b4dc32, 0x2a695ad8, 0xcbdf0837, - 0xafd526d6, 0x4e637439, 0x2cbef2d3, 0xcd08a03c, 0xa5acdfca, - 0x441a8d25, 0x26c70bcf, 0xc7715920, 0xa37b77c1, 0x42cd252e, - 0x2010a3c4, 0xc1a6f12b, 0xe196e614, 0x0020b4fb, 0x62fd3211, - 0x834b60fe, 0xe7414e1f, 0x06f71cf0, 0x642a9a1a, 0x859cc8f5, - 0xed38b703, 0x0c8ee5ec, 0x6e536306, 0x8fe531e9, 0xebef1f08, - 0x0a594de7, 0x6884cb0d, 0x893299e2, 0xf9ca453a, 0x187c17d5, - 0x7aa1913f, 0x9b17c3d0, 0xff1ded31, 0x1eabbfde, 0x7c763934, - 0x9dc06bdb, 0xf564142d, 0x14d246c2, 0x760fc028, 0x97b992c7, - 0xf3b3bc26, 0x1205eec9, 0x70d86823, 0x916e3acc, 0xd12ea049, - 0x3098f2a6, 0x5245744c, 0xb3f326a3, 0xd7f90842, 0x364f5aad, - 0x5492dc47, 0xb5248ea8, 0xdd80f15e, 0x3c36a3b1, 0x5eeb255b, - 0xbf5d77b4, 0xdb575955, 0x3ae10bba, 0x583c8d50, 0xb98adfbf, - 0xc9720367, 0x28c45188, 0x4a19d762, 0xabaf858d, 0xcfa5ab6c, - 0x2e13f983, 0x4cce7f69, 0xad782d86, 0xc5dc5270, 0x246a009f, - 0x46b78675, 0xa701d49a, 0xc30bfa7b, 0x22bda894, 0x40602e7e, - 0xa1d67c91}, - {0x00000000, 0x5880e2d7, 0xf106b474, 0xa98656a3, 0xe20d68e9, - 0xba8d8a3e, 0x130bdc9d, 0x4b8b3e4a, 0x851da109, 0xdd9d43de, - 0x741b157d, 0x2c9bf7aa, 0x6710c9e0, 0x3f902b37, 0x96167d94, - 0xce969f43, 0x0a3b4213, 0x52bba0c4, 0xfb3df667, 0xa3bd14b0, - 0xe8362afa, 0xb0b6c82d, 0x19309e8e, 0x41b07c59, 0x8f26e31a, - 0xd7a601cd, 0x7e20576e, 0x26a0b5b9, 0x6d2b8bf3, 0x35ab6924, - 0x9c2d3f87, 0xc4addd50, 0x14768426, 0x4cf666f1, 0xe5703052, - 0xbdf0d285, 0xf67beccf, 0xaefb0e18, 0x077d58bb, 0x5ffdba6c, - 0x916b252f, 0xc9ebc7f8, 0x606d915b, 0x38ed738c, 0x73664dc6, - 0x2be6af11, 0x8260f9b2, 0xdae01b65, 0x1e4dc635, 0x46cd24e2, - 0xef4b7241, 0xb7cb9096, 0xfc40aedc, 0xa4c04c0b, 0x0d461aa8, - 0x55c6f87f, 0x9b50673c, 0xc3d085eb, 0x6a56d348, 0x32d6319f, - 0x795d0fd5, 0x21dded02, 0x885bbba1, 0xd0db5976, 0x28ec084d, - 0x706cea9a, 0xd9eabc39, 0x816a5eee, 0xcae160a4, 0x92618273, - 0x3be7d4d0, 0x63673607, 0xadf1a944, 0xf5714b93, 0x5cf71d30, - 0x0477ffe7, 0x4ffcc1ad, 0x177c237a, 0xbefa75d9, 0xe67a970e, - 0x22d74a5e, 0x7a57a889, 0xd3d1fe2a, 0x8b511cfd, 0xc0da22b7, - 0x985ac060, 0x31dc96c3, 0x695c7414, 0xa7caeb57, 0xff4a0980, - 0x56cc5f23, 0x0e4cbdf4, 0x45c783be, 0x1d476169, 0xb4c137ca, - 0xec41d51d, 0x3c9a8c6b, 0x641a6ebc, 0xcd9c381f, 0x951cdac8, - 0xde97e482, 0x86170655, 0x2f9150f6, 0x7711b221, 0xb9872d62, - 0xe107cfb5, 0x48819916, 0x10017bc1, 0x5b8a458b, 0x030aa75c, - 0xaa8cf1ff, 0xf20c1328, 0x36a1ce78, 0x6e212caf, 0xc7a77a0c, - 0x9f2798db, 0xd4aca691, 0x8c2c4446, 0x25aa12e5, 0x7d2af032, - 0xb3bc6f71, 0xeb3c8da6, 0x42badb05, 0x1a3a39d2, 0x51b10798, - 0x0931e54f, 0xa0b7b3ec, 0xf837513b, 0x50d8119a, 0x0858f34d, - 0xa1dea5ee, 0xf95e4739, 0xb2d57973, 0xea559ba4, 0x43d3cd07, - 0x1b532fd0, 0xd5c5b093, 0x8d455244, 0x24c304e7, 0x7c43e630, - 0x37c8d87a, 0x6f483aad, 0xc6ce6c0e, 0x9e4e8ed9, 0x5ae35389, - 0x0263b15e, 0xabe5e7fd, 0xf365052a, 0xb8ee3b60, 0xe06ed9b7, - 0x49e88f14, 0x11686dc3, 0xdffef280, 0x877e1057, 0x2ef846f4, - 0x7678a423, 0x3df39a69, 0x657378be, 0xccf52e1d, 0x9475ccca, - 0x44ae95bc, 0x1c2e776b, 0xb5a821c8, 0xed28c31f, 0xa6a3fd55, - 0xfe231f82, 0x57a54921, 0x0f25abf6, 0xc1b334b5, 0x9933d662, - 0x30b580c1, 0x68356216, 0x23be5c5c, 0x7b3ebe8b, 0xd2b8e828, - 0x8a380aff, 0x4e95d7af, 0x16153578, 0xbf9363db, 0xe713810c, - 0xac98bf46, 0xf4185d91, 0x5d9e0b32, 0x051ee9e5, 0xcb8876a6, - 0x93089471, 0x3a8ec2d2, 0x620e2005, 0x29851e4f, 0x7105fc98, - 0xd883aa3b, 0x800348ec, 0x783419d7, 0x20b4fb00, 0x8932ada3, - 0xd1b24f74, 0x9a39713e, 0xc2b993e9, 0x6b3fc54a, 0x33bf279d, - 0xfd29b8de, 0xa5a95a09, 0x0c2f0caa, 0x54afee7d, 0x1f24d037, - 0x47a432e0, 0xee226443, 0xb6a28694, 0x720f5bc4, 0x2a8fb913, - 0x8309efb0, 0xdb890d67, 0x9002332d, 0xc882d1fa, 0x61048759, - 0x3984658e, 0xf712facd, 0xaf92181a, 0x06144eb9, 0x5e94ac6e, - 0x151f9224, 0x4d9f70f3, 0xe4192650, 0xbc99c487, 0x6c429df1, - 0x34c27f26, 0x9d442985, 0xc5c4cb52, 0x8e4ff518, 0xd6cf17cf, - 0x7f49416c, 0x27c9a3bb, 0xe95f3cf8, 0xb1dfde2f, 0x1859888c, - 0x40d96a5b, 0x0b525411, 0x53d2b6c6, 0xfa54e065, 0xa2d402b2, - 0x6679dfe2, 0x3ef93d35, 0x977f6b96, 0xcfff8941, 0x8474b70b, - 0xdcf455dc, 0x7572037f, 0x2df2e1a8, 0xe3647eeb, 0xbbe49c3c, - 0x1262ca9f, 0x4ae22848, 0x01691602, 0x59e9f4d5, 0xf06fa276, - 0xa8ef40a1}, - {0x00000000, 0x463b6765, 0x8c76ceca, 0xca4da9af, 0x59ebed4e, - 0x1fd08a2b, 0xd59d2384, 0x93a644e1, 0xb2d6db9d, 0xf4edbcf8, - 0x3ea01557, 0x789b7232, 0xeb3d36d3, 0xad0651b6, 0x674bf819, - 0x21709f7c, 0x25abc6e0, 0x6390a185, 0xa9dd082a, 0xefe66f4f, - 0x7c402bae, 0x3a7b4ccb, 0xf036e564, 0xb60d8201, 0x977d1d7d, - 0xd1467a18, 0x1b0bd3b7, 0x5d30b4d2, 0xce96f033, 0x88ad9756, - 0x42e03ef9, 0x04db599c, 0x0b50fc1a, 0x4d6b9b7f, 0x872632d0, - 0xc11d55b5, 0x52bb1154, 0x14807631, 0xdecddf9e, 0x98f6b8fb, - 0xb9862787, 0xffbd40e2, 0x35f0e94d, 0x73cb8e28, 0xe06dcac9, - 0xa656adac, 0x6c1b0403, 0x2a206366, 0x2efb3afa, 0x68c05d9f, - 0xa28df430, 0xe4b69355, 0x7710d7b4, 0x312bb0d1, 0xfb66197e, - 0xbd5d7e1b, 0x9c2de167, 0xda168602, 0x105b2fad, 0x566048c8, - 0xc5c60c29, 0x83fd6b4c, 0x49b0c2e3, 0x0f8ba586, 0x16a0f835, - 0x509b9f50, 0x9ad636ff, 0xdced519a, 0x4f4b157b, 0x0970721e, - 0xc33ddbb1, 0x8506bcd4, 0xa47623a8, 0xe24d44cd, 0x2800ed62, - 0x6e3b8a07, 0xfd9dcee6, 0xbba6a983, 0x71eb002c, 0x37d06749, - 0x330b3ed5, 0x753059b0, 0xbf7df01f, 0xf946977a, 0x6ae0d39b, - 0x2cdbb4fe, 0xe6961d51, 0xa0ad7a34, 0x81dde548, 0xc7e6822d, - 0x0dab2b82, 0x4b904ce7, 0xd8360806, 0x9e0d6f63, 0x5440c6cc, - 0x127ba1a9, 0x1df0042f, 0x5bcb634a, 0x9186cae5, 0xd7bdad80, - 0x441be961, 0x02208e04, 0xc86d27ab, 0x8e5640ce, 0xaf26dfb2, - 0xe91db8d7, 0x23501178, 0x656b761d, 0xf6cd32fc, 0xb0f65599, - 0x7abbfc36, 0x3c809b53, 0x385bc2cf, 0x7e60a5aa, 0xb42d0c05, - 0xf2166b60, 0x61b02f81, 0x278b48e4, 0xedc6e14b, 0xabfd862e, - 0x8a8d1952, 0xccb67e37, 0x06fbd798, 0x40c0b0fd, 0xd366f41c, - 0x955d9379, 0x5f103ad6, 0x192b5db3, 0x2c40f16b, 0x6a7b960e, - 0xa0363fa1, 0xe60d58c4, 0x75ab1c25, 0x33907b40, 0xf9ddd2ef, - 0xbfe6b58a, 0x9e962af6, 0xd8ad4d93, 0x12e0e43c, 0x54db8359, - 0xc77dc7b8, 0x8146a0dd, 0x4b0b0972, 0x0d306e17, 0x09eb378b, - 0x4fd050ee, 0x859df941, 0xc3a69e24, 0x5000dac5, 0x163bbda0, - 0xdc76140f, 0x9a4d736a, 0xbb3dec16, 0xfd068b73, 0x374b22dc, - 0x717045b9, 0xe2d60158, 0xa4ed663d, 0x6ea0cf92, 0x289ba8f7, - 0x27100d71, 0x612b6a14, 0xab66c3bb, 0xed5da4de, 0x7efbe03f, - 0x38c0875a, 0xf28d2ef5, 0xb4b64990, 0x95c6d6ec, 0xd3fdb189, - 0x19b01826, 0x5f8b7f43, 0xcc2d3ba2, 0x8a165cc7, 0x405bf568, - 0x0660920d, 0x02bbcb91, 0x4480acf4, 0x8ecd055b, 0xc8f6623e, - 0x5b5026df, 0x1d6b41ba, 0xd726e815, 0x911d8f70, 0xb06d100c, - 0xf6567769, 0x3c1bdec6, 0x7a20b9a3, 0xe986fd42, 0xafbd9a27, - 0x65f03388, 0x23cb54ed, 0x3ae0095e, 0x7cdb6e3b, 0xb696c794, - 0xf0ada0f1, 0x630be410, 0x25308375, 0xef7d2ada, 0xa9464dbf, - 0x8836d2c3, 0xce0db5a6, 0x04401c09, 0x427b7b6c, 0xd1dd3f8d, - 0x97e658e8, 0x5dabf147, 0x1b909622, 0x1f4bcfbe, 0x5970a8db, - 0x933d0174, 0xd5066611, 0x46a022f0, 0x009b4595, 0xcad6ec3a, - 0x8ced8b5f, 0xad9d1423, 0xeba67346, 0x21ebdae9, 0x67d0bd8c, - 0xf476f96d, 0xb24d9e08, 0x780037a7, 0x3e3b50c2, 0x31b0f544, - 0x778b9221, 0xbdc63b8e, 0xfbfd5ceb, 0x685b180a, 0x2e607f6f, - 0xe42dd6c0, 0xa216b1a5, 0x83662ed9, 0xc55d49bc, 0x0f10e013, - 0x492b8776, 0xda8dc397, 0x9cb6a4f2, 0x56fb0d5d, 0x10c06a38, - 0x141b33a4, 0x522054c1, 0x986dfd6e, 0xde569a0b, 0x4df0deea, - 0x0bcbb98f, 0xc1861020, 0x87bd7745, 0xa6cde839, 0xe0f68f5c, - 0x2abb26f3, 0x6c804196, 0xff260577, 0xb91d6212, 0x7350cbbd, - 0x356bacd8}}; - -#endif - -#endif - -#if N == 6 - -#if W == 8 - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0x3db1ecdc, 0x7b63d9b8, 0x46d23564, 0xf6c7b370, - 0xcb765fac, 0x8da46ac8, 0xb0158614, 0x36fe60a1, 0x0b4f8c7d, - 0x4d9db919, 0x702c55c5, 0xc039d3d1, 0xfd883f0d, 0xbb5a0a69, - 0x86ebe6b5, 0x6dfcc142, 0x504d2d9e, 0x169f18fa, 0x2b2ef426, - 0x9b3b7232, 0xa68a9eee, 0xe058ab8a, 0xdde94756, 0x5b02a1e3, - 0x66b34d3f, 0x2061785b, 0x1dd09487, 0xadc51293, 0x9074fe4f, - 0xd6a6cb2b, 0xeb1727f7, 0xdbf98284, 0xe6486e58, 0xa09a5b3c, - 0x9d2bb7e0, 0x2d3e31f4, 0x108fdd28, 0x565de84c, 0x6bec0490, - 0xed07e225, 0xd0b60ef9, 0x96643b9d, 0xabd5d741, 0x1bc05155, - 0x2671bd89, 0x60a388ed, 0x5d126431, 0xb60543c6, 0x8bb4af1a, - 0xcd669a7e, 0xf0d776a2, 0x40c2f0b6, 0x7d731c6a, 0x3ba1290e, - 0x0610c5d2, 0x80fb2367, 0xbd4acfbb, 0xfb98fadf, 0xc6291603, - 0x763c9017, 0x4b8d7ccb, 0x0d5f49af, 0x30eea573, 0x6c820349, - 0x5133ef95, 0x17e1daf1, 0x2a50362d, 0x9a45b039, 0xa7f45ce5, - 0xe1266981, 0xdc97855d, 0x5a7c63e8, 0x67cd8f34, 0x211fba50, - 0x1cae568c, 0xacbbd098, 0x910a3c44, 0xd7d80920, 0xea69e5fc, - 0x017ec20b, 0x3ccf2ed7, 0x7a1d1bb3, 0x47acf76f, 0xf7b9717b, - 0xca089da7, 0x8cdaa8c3, 0xb16b441f, 0x3780a2aa, 0x0a314e76, - 0x4ce37b12, 0x715297ce, 0xc14711da, 0xfcf6fd06, 0xba24c862, - 0x879524be, 0xb77b81cd, 0x8aca6d11, 0xcc185875, 0xf1a9b4a9, - 0x41bc32bd, 0x7c0dde61, 0x3adfeb05, 0x076e07d9, 0x8185e16c, - 0xbc340db0, 0xfae638d4, 0xc757d408, 0x7742521c, 0x4af3bec0, - 0x0c218ba4, 0x31906778, 0xda87408f, 0xe736ac53, 0xa1e49937, - 0x9c5575eb, 0x2c40f3ff, 0x11f11f23, 0x57232a47, 0x6a92c69b, - 0xec79202e, 0xd1c8ccf2, 0x971af996, 0xaaab154a, 0x1abe935e, - 0x270f7f82, 0x61dd4ae6, 0x5c6ca63a, 0xd9040692, 0xe4b5ea4e, - 0xa267df2a, 0x9fd633f6, 0x2fc3b5e2, 0x1272593e, 0x54a06c5a, - 0x69118086, 0xeffa6633, 0xd24b8aef, 0x9499bf8b, 0xa9285357, - 0x193dd543, 0x248c399f, 0x625e0cfb, 0x5fefe027, 0xb4f8c7d0, - 0x89492b0c, 0xcf9b1e68, 0xf22af2b4, 0x423f74a0, 0x7f8e987c, - 0x395cad18, 0x04ed41c4, 0x8206a771, 0xbfb74bad, 0xf9657ec9, - 0xc4d49215, 0x74c11401, 0x4970f8dd, 0x0fa2cdb9, 0x32132165, - 0x02fd8416, 0x3f4c68ca, 0x799e5dae, 0x442fb172, 0xf43a3766, - 0xc98bdbba, 0x8f59eede, 0xb2e80202, 0x3403e4b7, 0x09b2086b, - 0x4f603d0f, 0x72d1d1d3, 0xc2c457c7, 0xff75bb1b, 0xb9a78e7f, - 0x841662a3, 0x6f014554, 0x52b0a988, 0x14629cec, 0x29d37030, - 0x99c6f624, 0xa4771af8, 0xe2a52f9c, 0xdf14c340, 0x59ff25f5, - 0x644ec929, 0x229cfc4d, 0x1f2d1091, 0xaf389685, 0x92897a59, - 0xd45b4f3d, 0xe9eaa3e1, 0xb58605db, 0x8837e907, 0xcee5dc63, - 0xf35430bf, 0x4341b6ab, 0x7ef05a77, 0x38226f13, 0x059383cf, - 0x8378657a, 0xbec989a6, 0xf81bbcc2, 0xc5aa501e, 0x75bfd60a, - 0x480e3ad6, 0x0edc0fb2, 0x336de36e, 0xd87ac499, 0xe5cb2845, - 0xa3191d21, 0x9ea8f1fd, 0x2ebd77e9, 0x130c9b35, 0x55deae51, - 0x686f428d, 0xee84a438, 0xd33548e4, 0x95e77d80, 0xa856915c, - 0x18431748, 0x25f2fb94, 0x6320cef0, 0x5e91222c, 0x6e7f875f, - 0x53ce6b83, 0x151c5ee7, 0x28adb23b, 0x98b8342f, 0xa509d8f3, - 0xe3dbed97, 0xde6a014b, 0x5881e7fe, 0x65300b22, 0x23e23e46, - 0x1e53d29a, 0xae46548e, 0x93f7b852, 0xd5258d36, 0xe89461ea, - 0x0383461d, 0x3e32aac1, 0x78e09fa5, 0x45517379, 0xf544f56d, - 0xc8f519b1, 0x8e272cd5, 0xb396c009, 0x357d26bc, 0x08ccca60, - 0x4e1eff04, 0x73af13d8, 0xc3ba95cc, 0xfe0b7910, 0xb8d94c74, - 0x8568a0a8}, - {0x00000000, 0x69790b65, 0xd2f216ca, 0xbb8b1daf, 0x7e952bd5, - 0x17ec20b0, 0xac673d1f, 0xc51e367a, 0xfd2a57aa, 0x94535ccf, - 0x2fd84160, 0x46a14a05, 0x83bf7c7f, 0xeac6771a, 0x514d6ab5, - 0x383461d0, 0x2125a915, 0x485ca270, 0xf3d7bfdf, 0x9aaeb4ba, - 0x5fb082c0, 0x36c989a5, 0x8d42940a, 0xe43b9f6f, 0xdc0ffebf, - 0xb576f5da, 0x0efde875, 0x6784e310, 0xa29ad56a, 0xcbe3de0f, - 0x7068c3a0, 0x1911c8c5, 0x424b522a, 0x2b32594f, 0x90b944e0, - 0xf9c04f85, 0x3cde79ff, 0x55a7729a, 0xee2c6f35, 0x87556450, - 0xbf610580, 0xd6180ee5, 0x6d93134a, 0x04ea182f, 0xc1f42e55, - 0xa88d2530, 0x1306389f, 0x7a7f33fa, 0x636efb3f, 0x0a17f05a, - 0xb19cedf5, 0xd8e5e690, 0x1dfbd0ea, 0x7482db8f, 0xcf09c620, - 0xa670cd45, 0x9e44ac95, 0xf73da7f0, 0x4cb6ba5f, 0x25cfb13a, - 0xe0d18740, 0x89a88c25, 0x3223918a, 0x5b5a9aef, 0x8496a454, - 0xedefaf31, 0x5664b29e, 0x3f1db9fb, 0xfa038f81, 0x937a84e4, - 0x28f1994b, 0x4188922e, 0x79bcf3fe, 0x10c5f89b, 0xab4ee534, - 0xc237ee51, 0x0729d82b, 0x6e50d34e, 0xd5dbcee1, 0xbca2c584, - 0xa5b30d41, 0xccca0624, 0x77411b8b, 0x1e3810ee, 0xdb262694, - 0xb25f2df1, 0x09d4305e, 0x60ad3b3b, 0x58995aeb, 0x31e0518e, - 0x8a6b4c21, 0xe3124744, 0x260c713e, 0x4f757a5b, 0xf4fe67f4, - 0x9d876c91, 0xc6ddf67e, 0xafa4fd1b, 0x142fe0b4, 0x7d56ebd1, - 0xb848ddab, 0xd131d6ce, 0x6abacb61, 0x03c3c004, 0x3bf7a1d4, - 0x528eaab1, 0xe905b71e, 0x807cbc7b, 0x45628a01, 0x2c1b8164, - 0x97909ccb, 0xfee997ae, 0xe7f85f6b, 0x8e81540e, 0x350a49a1, - 0x5c7342c4, 0x996d74be, 0xf0147fdb, 0x4b9f6274, 0x22e66911, - 0x1ad208c1, 0x73ab03a4, 0xc8201e0b, 0xa159156e, 0x64472314, - 0x0d3e2871, 0xb6b535de, 0xdfcc3ebb, 0xd25c4ee9, 0xbb25458c, - 0x00ae5823, 0x69d75346, 0xacc9653c, 0xc5b06e59, 0x7e3b73f6, - 0x17427893, 0x2f761943, 0x460f1226, 0xfd840f89, 0x94fd04ec, - 0x51e33296, 0x389a39f3, 0x8311245c, 0xea682f39, 0xf379e7fc, - 0x9a00ec99, 0x218bf136, 0x48f2fa53, 0x8deccc29, 0xe495c74c, - 0x5f1edae3, 0x3667d186, 0x0e53b056, 0x672abb33, 0xdca1a69c, - 0xb5d8adf9, 0x70c69b83, 0x19bf90e6, 0xa2348d49, 0xcb4d862c, - 0x90171cc3, 0xf96e17a6, 0x42e50a09, 0x2b9c016c, 0xee823716, - 0x87fb3c73, 0x3c7021dc, 0x55092ab9, 0x6d3d4b69, 0x0444400c, - 0xbfcf5da3, 0xd6b656c6, 0x13a860bc, 0x7ad16bd9, 0xc15a7676, - 0xa8237d13, 0xb132b5d6, 0xd84bbeb3, 0x63c0a31c, 0x0ab9a879, - 0xcfa79e03, 0xa6de9566, 0x1d5588c9, 0x742c83ac, 0x4c18e27c, - 0x2561e919, 0x9eeaf4b6, 0xf793ffd3, 0x328dc9a9, 0x5bf4c2cc, - 0xe07fdf63, 0x8906d406, 0x56caeabd, 0x3fb3e1d8, 0x8438fc77, - 0xed41f712, 0x285fc168, 0x4126ca0d, 0xfaadd7a2, 0x93d4dcc7, - 0xabe0bd17, 0xc299b672, 0x7912abdd, 0x106ba0b8, 0xd57596c2, - 0xbc0c9da7, 0x07878008, 0x6efe8b6d, 0x77ef43a8, 0x1e9648cd, - 0xa51d5562, 0xcc645e07, 0x097a687d, 0x60036318, 0xdb887eb7, - 0xb2f175d2, 0x8ac51402, 0xe3bc1f67, 0x583702c8, 0x314e09ad, - 0xf4503fd7, 0x9d2934b2, 0x26a2291d, 0x4fdb2278, 0x1481b897, - 0x7df8b3f2, 0xc673ae5d, 0xaf0aa538, 0x6a149342, 0x036d9827, - 0xb8e68588, 0xd19f8eed, 0xe9abef3d, 0x80d2e458, 0x3b59f9f7, - 0x5220f292, 0x973ec4e8, 0xfe47cf8d, 0x45ccd222, 0x2cb5d947, - 0x35a41182, 0x5cdd1ae7, 0xe7560748, 0x8e2f0c2d, 0x4b313a57, - 0x22483132, 0x99c32c9d, 0xf0ba27f8, 0xc88e4628, 0xa1f74d4d, - 0x1a7c50e2, 0x73055b87, 0xb61b6dfd, 0xdf626698, 0x64e97b37, - 0x0d907052}, - {0x00000000, 0x7fc99b93, 0xff933726, 0x805aacb5, 0x2457680d, - 0x5b9ef39e, 0xdbc45f2b, 0xa40dc4b8, 0x48aed01a, 0x37674b89, - 0xb73de73c, 0xc8f47caf, 0x6cf9b817, 0x13302384, 0x936a8f31, - 0xeca314a2, 0x915da034, 0xee943ba7, 0x6ece9712, 0x11070c81, - 0xb50ac839, 0xcac353aa, 0x4a99ff1f, 0x3550648c, 0xd9f3702e, - 0xa63aebbd, 0x26604708, 0x59a9dc9b, 0xfda41823, 0x826d83b0, - 0x02372f05, 0x7dfeb496, 0xf9ca4629, 0x8603ddba, 0x0659710f, - 0x7990ea9c, 0xdd9d2e24, 0xa254b5b7, 0x220e1902, 0x5dc78291, - 0xb1649633, 0xcead0da0, 0x4ef7a115, 0x313e3a86, 0x9533fe3e, - 0xeafa65ad, 0x6aa0c918, 0x1569528b, 0x6897e61d, 0x175e7d8e, - 0x9704d13b, 0xe8cd4aa8, 0x4cc08e10, 0x33091583, 0xb353b936, - 0xcc9a22a5, 0x20393607, 0x5ff0ad94, 0xdfaa0121, 0xa0639ab2, - 0x046e5e0a, 0x7ba7c599, 0xfbfd692c, 0x8434f2bf, 0x28e58a13, - 0x572c1180, 0xd776bd35, 0xa8bf26a6, 0x0cb2e21e, 0x737b798d, - 0xf321d538, 0x8ce84eab, 0x604b5a09, 0x1f82c19a, 0x9fd86d2f, - 0xe011f6bc, 0x441c3204, 0x3bd5a997, 0xbb8f0522, 0xc4469eb1, - 0xb9b82a27, 0xc671b1b4, 0x462b1d01, 0x39e28692, 0x9def422a, - 0xe226d9b9, 0x627c750c, 0x1db5ee9f, 0xf116fa3d, 0x8edf61ae, - 0x0e85cd1b, 0x714c5688, 0xd5419230, 0xaa8809a3, 0x2ad2a516, - 0x551b3e85, 0xd12fcc3a, 0xaee657a9, 0x2ebcfb1c, 0x5175608f, - 0xf578a437, 0x8ab13fa4, 0x0aeb9311, 0x75220882, 0x99811c20, - 0xe64887b3, 0x66122b06, 0x19dbb095, 0xbdd6742d, 0xc21fefbe, - 0x4245430b, 0x3d8cd898, 0x40726c0e, 0x3fbbf79d, 0xbfe15b28, - 0xc028c0bb, 0x64250403, 0x1bec9f90, 0x9bb63325, 0xe47fa8b6, - 0x08dcbc14, 0x77152787, 0xf74f8b32, 0x888610a1, 0x2c8bd419, - 0x53424f8a, 0xd318e33f, 0xacd178ac, 0x51cb1426, 0x2e028fb5, - 0xae582300, 0xd191b893, 0x759c7c2b, 0x0a55e7b8, 0x8a0f4b0d, - 0xf5c6d09e, 0x1965c43c, 0x66ac5faf, 0xe6f6f31a, 0x993f6889, - 0x3d32ac31, 0x42fb37a2, 0xc2a19b17, 0xbd680084, 0xc096b412, - 0xbf5f2f81, 0x3f058334, 0x40cc18a7, 0xe4c1dc1f, 0x9b08478c, - 0x1b52eb39, 0x649b70aa, 0x88386408, 0xf7f1ff9b, 0x77ab532e, - 0x0862c8bd, 0xac6f0c05, 0xd3a69796, 0x53fc3b23, 0x2c35a0b0, - 0xa801520f, 0xd7c8c99c, 0x57926529, 0x285bfeba, 0x8c563a02, - 0xf39fa191, 0x73c50d24, 0x0c0c96b7, 0xe0af8215, 0x9f661986, - 0x1f3cb533, 0x60f52ea0, 0xc4f8ea18, 0xbb31718b, 0x3b6bdd3e, - 0x44a246ad, 0x395cf23b, 0x469569a8, 0xc6cfc51d, 0xb9065e8e, - 0x1d0b9a36, 0x62c201a5, 0xe298ad10, 0x9d513683, 0x71f22221, - 0x0e3bb9b2, 0x8e611507, 0xf1a88e94, 0x55a54a2c, 0x2a6cd1bf, - 0xaa367d0a, 0xd5ffe699, 0x792e9e35, 0x06e705a6, 0x86bda913, - 0xf9743280, 0x5d79f638, 0x22b06dab, 0xa2eac11e, 0xdd235a8d, - 0x31804e2f, 0x4e49d5bc, 0xce137909, 0xb1dae29a, 0x15d72622, - 0x6a1ebdb1, 0xea441104, 0x958d8a97, 0xe8733e01, 0x97baa592, - 0x17e00927, 0x682992b4, 0xcc24560c, 0xb3edcd9f, 0x33b7612a, - 0x4c7efab9, 0xa0ddee1b, 0xdf147588, 0x5f4ed93d, 0x208742ae, - 0x848a8616, 0xfb431d85, 0x7b19b130, 0x04d02aa3, 0x80e4d81c, - 0xff2d438f, 0x7f77ef3a, 0x00be74a9, 0xa4b3b011, 0xdb7a2b82, - 0x5b208737, 0x24e91ca4, 0xc84a0806, 0xb7839395, 0x37d93f20, - 0x4810a4b3, 0xec1d600b, 0x93d4fb98, 0x138e572d, 0x6c47ccbe, - 0x11b97828, 0x6e70e3bb, 0xee2a4f0e, 0x91e3d49d, 0x35ee1025, - 0x4a278bb6, 0xca7d2703, 0xb5b4bc90, 0x5917a832, 0x26de33a1, - 0xa6849f14, 0xd94d0487, 0x7d40c03f, 0x02895bac, 0x82d3f719, - 0xfd1a6c8a}, - {0x00000000, 0xa396284c, 0x9c5d56d9, 0x3fcb7e95, 0xe3cbabf3, - 0x405d83bf, 0x7f96fd2a, 0xdc00d566, 0x1ce651a7, 0xbf7079eb, - 0x80bb077e, 0x232d2f32, 0xff2dfa54, 0x5cbbd218, 0x6370ac8d, - 0xc0e684c1, 0x39cca34e, 0x9a5a8b02, 0xa591f597, 0x0607dddb, - 0xda0708bd, 0x799120f1, 0x465a5e64, 0xe5cc7628, 0x252af2e9, - 0x86bcdaa5, 0xb977a430, 0x1ae18c7c, 0xc6e1591a, 0x65777156, - 0x5abc0fc3, 0xf92a278f, 0x7399469c, 0xd00f6ed0, 0xefc41045, - 0x4c523809, 0x9052ed6f, 0x33c4c523, 0x0c0fbbb6, 0xaf9993fa, - 0x6f7f173b, 0xcce93f77, 0xf32241e2, 0x50b469ae, 0x8cb4bcc8, - 0x2f229484, 0x10e9ea11, 0xb37fc25d, 0x4a55e5d2, 0xe9c3cd9e, - 0xd608b30b, 0x759e9b47, 0xa99e4e21, 0x0a08666d, 0x35c318f8, - 0x965530b4, 0x56b3b475, 0xf5259c39, 0xcaeee2ac, 0x6978cae0, - 0xb5781f86, 0x16ee37ca, 0x2925495f, 0x8ab36113, 0xe7328d38, - 0x44a4a574, 0x7b6fdbe1, 0xd8f9f3ad, 0x04f926cb, 0xa76f0e87, - 0x98a47012, 0x3b32585e, 0xfbd4dc9f, 0x5842f4d3, 0x67898a46, - 0xc41fa20a, 0x181f776c, 0xbb895f20, 0x844221b5, 0x27d409f9, - 0xdefe2e76, 0x7d68063a, 0x42a378af, 0xe13550e3, 0x3d358585, - 0x9ea3adc9, 0xa168d35c, 0x02fefb10, 0xc2187fd1, 0x618e579d, - 0x5e452908, 0xfdd30144, 0x21d3d422, 0x8245fc6e, 0xbd8e82fb, - 0x1e18aab7, 0x94abcba4, 0x373de3e8, 0x08f69d7d, 0xab60b531, - 0x77606057, 0xd4f6481b, 0xeb3d368e, 0x48ab1ec2, 0x884d9a03, - 0x2bdbb24f, 0x1410ccda, 0xb786e496, 0x6b8631f0, 0xc81019bc, - 0xf7db6729, 0x544d4f65, 0xad6768ea, 0x0ef140a6, 0x313a3e33, - 0x92ac167f, 0x4eacc319, 0xed3aeb55, 0xd2f195c0, 0x7167bd8c, - 0xb181394d, 0x12171101, 0x2ddc6f94, 0x8e4a47d8, 0x524a92be, - 0xf1dcbaf2, 0xce17c467, 0x6d81ec2b, 0x15141c31, 0xb682347d, - 0x89494ae8, 0x2adf62a4, 0xf6dfb7c2, 0x55499f8e, 0x6a82e11b, - 0xc914c957, 0x09f24d96, 0xaa6465da, 0x95af1b4f, 0x36393303, - 0xea39e665, 0x49afce29, 0x7664b0bc, 0xd5f298f0, 0x2cd8bf7f, - 0x8f4e9733, 0xb085e9a6, 0x1313c1ea, 0xcf13148c, 0x6c853cc0, - 0x534e4255, 0xf0d86a19, 0x303eeed8, 0x93a8c694, 0xac63b801, - 0x0ff5904d, 0xd3f5452b, 0x70636d67, 0x4fa813f2, 0xec3e3bbe, - 0x668d5aad, 0xc51b72e1, 0xfad00c74, 0x59462438, 0x8546f15e, - 0x26d0d912, 0x191ba787, 0xba8d8fcb, 0x7a6b0b0a, 0xd9fd2346, - 0xe6365dd3, 0x45a0759f, 0x99a0a0f9, 0x3a3688b5, 0x05fdf620, - 0xa66bde6c, 0x5f41f9e3, 0xfcd7d1af, 0xc31caf3a, 0x608a8776, - 0xbc8a5210, 0x1f1c7a5c, 0x20d704c9, 0x83412c85, 0x43a7a844, - 0xe0318008, 0xdffafe9d, 0x7c6cd6d1, 0xa06c03b7, 0x03fa2bfb, - 0x3c31556e, 0x9fa77d22, 0xf2269109, 0x51b0b945, 0x6e7bc7d0, - 0xcdedef9c, 0x11ed3afa, 0xb27b12b6, 0x8db06c23, 0x2e26446f, - 0xeec0c0ae, 0x4d56e8e2, 0x729d9677, 0xd10bbe3b, 0x0d0b6b5d, - 0xae9d4311, 0x91563d84, 0x32c015c8, 0xcbea3247, 0x687c1a0b, - 0x57b7649e, 0xf4214cd2, 0x282199b4, 0x8bb7b1f8, 0xb47ccf6d, - 0x17eae721, 0xd70c63e0, 0x749a4bac, 0x4b513539, 0xe8c71d75, - 0x34c7c813, 0x9751e05f, 0xa89a9eca, 0x0b0cb686, 0x81bfd795, - 0x2229ffd9, 0x1de2814c, 0xbe74a900, 0x62747c66, 0xc1e2542a, - 0xfe292abf, 0x5dbf02f3, 0x9d598632, 0x3ecfae7e, 0x0104d0eb, - 0xa292f8a7, 0x7e922dc1, 0xdd04058d, 0xe2cf7b18, 0x41595354, - 0xb87374db, 0x1be55c97, 0x242e2202, 0x87b80a4e, 0x5bb8df28, - 0xf82ef764, 0xc7e589f1, 0x6473a1bd, 0xa495257c, 0x07030d30, - 0x38c873a5, 0x9b5e5be9, 0x475e8e8f, 0xe4c8a6c3, 0xdb03d856, - 0x7895f01a}, - {0x00000000, 0x2a283862, 0x545070c4, 0x7e7848a6, 0xa8a0e188, - 0x8288d9ea, 0xfcf0914c, 0xd6d8a92e, 0x8a30c551, 0xa018fd33, - 0xde60b595, 0xf4488df7, 0x229024d9, 0x08b81cbb, 0x76c0541d, - 0x5ce86c7f, 0xcf108ce3, 0xe538b481, 0x9b40fc27, 0xb168c445, - 0x67b06d6b, 0x4d985509, 0x33e01daf, 0x19c825cd, 0x452049b2, - 0x6f0871d0, 0x11703976, 0x3b580114, 0xed80a83a, 0xc7a89058, - 0xb9d0d8fe, 0x93f8e09c, 0x45501f87, 0x6f7827e5, 0x11006f43, - 0x3b285721, 0xedf0fe0f, 0xc7d8c66d, 0xb9a08ecb, 0x9388b6a9, - 0xcf60dad6, 0xe548e2b4, 0x9b30aa12, 0xb1189270, 0x67c03b5e, - 0x4de8033c, 0x33904b9a, 0x19b873f8, 0x8a409364, 0xa068ab06, - 0xde10e3a0, 0xf438dbc2, 0x22e072ec, 0x08c84a8e, 0x76b00228, - 0x5c983a4a, 0x00705635, 0x2a586e57, 0x542026f1, 0x7e081e93, - 0xa8d0b7bd, 0x82f88fdf, 0xfc80c779, 0xd6a8ff1b, 0x8aa03f0e, - 0xa088076c, 0xdef04fca, 0xf4d877a8, 0x2200de86, 0x0828e6e4, - 0x7650ae42, 0x5c789620, 0x0090fa5f, 0x2ab8c23d, 0x54c08a9b, - 0x7ee8b2f9, 0xa8301bd7, 0x821823b5, 0xfc606b13, 0xd6485371, - 0x45b0b3ed, 0x6f988b8f, 0x11e0c329, 0x3bc8fb4b, 0xed105265, - 0xc7386a07, 0xb94022a1, 0x93681ac3, 0xcf8076bc, 0xe5a84ede, - 0x9bd00678, 0xb1f83e1a, 0x67209734, 0x4d08af56, 0x3370e7f0, - 0x1958df92, 0xcff02089, 0xe5d818eb, 0x9ba0504d, 0xb188682f, - 0x6750c101, 0x4d78f963, 0x3300b1c5, 0x192889a7, 0x45c0e5d8, - 0x6fe8ddba, 0x1190951c, 0x3bb8ad7e, 0xed600450, 0xc7483c32, - 0xb9307494, 0x93184cf6, 0x00e0ac6a, 0x2ac89408, 0x54b0dcae, - 0x7e98e4cc, 0xa8404de2, 0x82687580, 0xfc103d26, 0xd6380544, - 0x8ad0693b, 0xa0f85159, 0xde8019ff, 0xf4a8219d, 0x227088b3, - 0x0858b0d1, 0x7620f877, 0x5c08c015, 0xce31785d, 0xe419403f, - 0x9a610899, 0xb04930fb, 0x669199d5, 0x4cb9a1b7, 0x32c1e911, - 0x18e9d173, 0x4401bd0c, 0x6e29856e, 0x1051cdc8, 0x3a79f5aa, - 0xeca15c84, 0xc68964e6, 0xb8f12c40, 0x92d91422, 0x0121f4be, - 0x2b09ccdc, 0x5571847a, 0x7f59bc18, 0xa9811536, 0x83a92d54, - 0xfdd165f2, 0xd7f95d90, 0x8b1131ef, 0xa139098d, 0xdf41412b, - 0xf5697949, 0x23b1d067, 0x0999e805, 0x77e1a0a3, 0x5dc998c1, - 0x8b6167da, 0xa1495fb8, 0xdf31171e, 0xf5192f7c, 0x23c18652, - 0x09e9be30, 0x7791f696, 0x5db9cef4, 0x0151a28b, 0x2b799ae9, - 0x5501d24f, 0x7f29ea2d, 0xa9f14303, 0x83d97b61, 0xfda133c7, - 0xd7890ba5, 0x4471eb39, 0x6e59d35b, 0x10219bfd, 0x3a09a39f, - 0xecd10ab1, 0xc6f932d3, 0xb8817a75, 0x92a94217, 0xce412e68, - 0xe469160a, 0x9a115eac, 0xb03966ce, 0x66e1cfe0, 0x4cc9f782, - 0x32b1bf24, 0x18998746, 0x44914753, 0x6eb97f31, 0x10c13797, - 0x3ae90ff5, 0xec31a6db, 0xc6199eb9, 0xb861d61f, 0x9249ee7d, - 0xcea18202, 0xe489ba60, 0x9af1f2c6, 0xb0d9caa4, 0x6601638a, - 0x4c295be8, 0x3251134e, 0x18792b2c, 0x8b81cbb0, 0xa1a9f3d2, - 0xdfd1bb74, 0xf5f98316, 0x23212a38, 0x0909125a, 0x77715afc, - 0x5d59629e, 0x01b10ee1, 0x2b993683, 0x55e17e25, 0x7fc94647, - 0xa911ef69, 0x8339d70b, 0xfd419fad, 0xd769a7cf, 0x01c158d4, - 0x2be960b6, 0x55912810, 0x7fb91072, 0xa961b95c, 0x8349813e, - 0xfd31c998, 0xd719f1fa, 0x8bf19d85, 0xa1d9a5e7, 0xdfa1ed41, - 0xf589d523, 0x23517c0d, 0x0979446f, 0x77010cc9, 0x5d2934ab, - 0xced1d437, 0xe4f9ec55, 0x9a81a4f3, 0xb0a99c91, 0x667135bf, - 0x4c590ddd, 0x3221457b, 0x18097d19, 0x44e11166, 0x6ec92904, - 0x10b161a2, 0x3a9959c0, 0xec41f0ee, 0xc669c88c, 0xb811802a, - 0x9239b848}, - {0x00000000, 0x4713f6fb, 0x8e27edf6, 0xc9341b0d, 0xc73eddad, - 0x802d2b56, 0x4919305b, 0x0e0ac6a0, 0x550cbd1b, 0x121f4be0, - 0xdb2b50ed, 0x9c38a616, 0x923260b6, 0xd521964d, 0x1c158d40, - 0x5b067bbb, 0xaa197a36, 0xed0a8ccd, 0x243e97c0, 0x632d613b, - 0x6d27a79b, 0x2a345160, 0xe3004a6d, 0xa413bc96, 0xff15c72d, - 0xb80631d6, 0x71322adb, 0x3621dc20, 0x382b1a80, 0x7f38ec7b, - 0xb60cf776, 0xf11f018d, 0x8f43f22d, 0xc85004d6, 0x01641fdb, - 0x4677e920, 0x487d2f80, 0x0f6ed97b, 0xc65ac276, 0x8149348d, - 0xda4f4f36, 0x9d5cb9cd, 0x5468a2c0, 0x137b543b, 0x1d71929b, - 0x5a626460, 0x93567f6d, 0xd4458996, 0x255a881b, 0x62497ee0, - 0xab7d65ed, 0xec6e9316, 0xe26455b6, 0xa577a34d, 0x6c43b840, - 0x2b504ebb, 0x70563500, 0x3745c3fb, 0xfe71d8f6, 0xb9622e0d, - 0xb768e8ad, 0xf07b1e56, 0x394f055b, 0x7e5cf3a0, 0xc5f6e21b, - 0x82e514e0, 0x4bd10fed, 0x0cc2f916, 0x02c83fb6, 0x45dbc94d, - 0x8cefd240, 0xcbfc24bb, 0x90fa5f00, 0xd7e9a9fb, 0x1eddb2f6, - 0x59ce440d, 0x57c482ad, 0x10d77456, 0xd9e36f5b, 0x9ef099a0, - 0x6fef982d, 0x28fc6ed6, 0xe1c875db, 0xa6db8320, 0xa8d14580, - 0xefc2b37b, 0x26f6a876, 0x61e55e8d, 0x3ae32536, 0x7df0d3cd, - 0xb4c4c8c0, 0xf3d73e3b, 0xfdddf89b, 0xbace0e60, 0x73fa156d, - 0x34e9e396, 0x4ab51036, 0x0da6e6cd, 0xc492fdc0, 0x83810b3b, - 0x8d8bcd9b, 0xca983b60, 0x03ac206d, 0x44bfd696, 0x1fb9ad2d, - 0x58aa5bd6, 0x919e40db, 0xd68db620, 0xd8877080, 0x9f94867b, - 0x56a09d76, 0x11b36b8d, 0xe0ac6a00, 0xa7bf9cfb, 0x6e8b87f6, - 0x2998710d, 0x2792b7ad, 0x60814156, 0xa9b55a5b, 0xeea6aca0, - 0xb5a0d71b, 0xf2b321e0, 0x3b873aed, 0x7c94cc16, 0x729e0ab6, - 0x358dfc4d, 0xfcb9e740, 0xbbaa11bb, 0x509cc277, 0x178f348c, - 0xdebb2f81, 0x99a8d97a, 0x97a21fda, 0xd0b1e921, 0x1985f22c, - 0x5e9604d7, 0x05907f6c, 0x42838997, 0x8bb7929a, 0xcca46461, - 0xc2aea2c1, 0x85bd543a, 0x4c894f37, 0x0b9ab9cc, 0xfa85b841, - 0xbd964eba, 0x74a255b7, 0x33b1a34c, 0x3dbb65ec, 0x7aa89317, - 0xb39c881a, 0xf48f7ee1, 0xaf89055a, 0xe89af3a1, 0x21aee8ac, - 0x66bd1e57, 0x68b7d8f7, 0x2fa42e0c, 0xe6903501, 0xa183c3fa, - 0xdfdf305a, 0x98ccc6a1, 0x51f8ddac, 0x16eb2b57, 0x18e1edf7, - 0x5ff21b0c, 0x96c60001, 0xd1d5f6fa, 0x8ad38d41, 0xcdc07bba, - 0x04f460b7, 0x43e7964c, 0x4ded50ec, 0x0afea617, 0xc3cabd1a, - 0x84d94be1, 0x75c64a6c, 0x32d5bc97, 0xfbe1a79a, 0xbcf25161, - 0xb2f897c1, 0xf5eb613a, 0x3cdf7a37, 0x7bcc8ccc, 0x20caf777, - 0x67d9018c, 0xaeed1a81, 0xe9feec7a, 0xe7f42ada, 0xa0e7dc21, - 0x69d3c72c, 0x2ec031d7, 0x956a206c, 0xd279d697, 0x1b4dcd9a, - 0x5c5e3b61, 0x5254fdc1, 0x15470b3a, 0xdc731037, 0x9b60e6cc, - 0xc0669d77, 0x87756b8c, 0x4e417081, 0x0952867a, 0x075840da, - 0x404bb621, 0x897fad2c, 0xce6c5bd7, 0x3f735a5a, 0x7860aca1, - 0xb154b7ac, 0xf6474157, 0xf84d87f7, 0xbf5e710c, 0x766a6a01, - 0x31799cfa, 0x6a7fe741, 0x2d6c11ba, 0xe4580ab7, 0xa34bfc4c, - 0xad413aec, 0xea52cc17, 0x2366d71a, 0x647521e1, 0x1a29d241, - 0x5d3a24ba, 0x940e3fb7, 0xd31dc94c, 0xdd170fec, 0x9a04f917, - 0x5330e21a, 0x142314e1, 0x4f256f5a, 0x083699a1, 0xc10282ac, - 0x86117457, 0x881bb2f7, 0xcf08440c, 0x063c5f01, 0x412fa9fa, - 0xb030a877, 0xf7235e8c, 0x3e174581, 0x7904b37a, 0x770e75da, - 0x301d8321, 0xf929982c, 0xbe3a6ed7, 0xe53c156c, 0xa22fe397, - 0x6b1bf89a, 0x2c080e61, 0x2202c8c1, 0x65113e3a, 0xac252537, - 0xeb36d3cc}, - {0x00000000, 0xa13984ee, 0x99020f9d, 0x383b8b73, 0xe975197b, - 0x484c9d95, 0x707716e6, 0xd14e9208, 0x099b34b7, 0xa8a2b059, - 0x90993b2a, 0x31a0bfc4, 0xe0ee2dcc, 0x41d7a922, 0x79ec2251, - 0xd8d5a6bf, 0x1336696e, 0xb20fed80, 0x8a3466f3, 0x2b0de21d, - 0xfa437015, 0x5b7af4fb, 0x63417f88, 0xc278fb66, 0x1aad5dd9, - 0xbb94d937, 0x83af5244, 0x2296d6aa, 0xf3d844a2, 0x52e1c04c, - 0x6ada4b3f, 0xcbe3cfd1, 0x266cd2dc, 0x87555632, 0xbf6edd41, - 0x1e5759af, 0xcf19cba7, 0x6e204f49, 0x561bc43a, 0xf72240d4, - 0x2ff7e66b, 0x8ece6285, 0xb6f5e9f6, 0x17cc6d18, 0xc682ff10, - 0x67bb7bfe, 0x5f80f08d, 0xfeb97463, 0x355abbb2, 0x94633f5c, - 0xac58b42f, 0x0d6130c1, 0xdc2fa2c9, 0x7d162627, 0x452dad54, - 0xe41429ba, 0x3cc18f05, 0x9df80beb, 0xa5c38098, 0x04fa0476, - 0xd5b4967e, 0x748d1290, 0x4cb699e3, 0xed8f1d0d, 0x4cd9a5b8, - 0xede02156, 0xd5dbaa25, 0x74e22ecb, 0xa5acbcc3, 0x0495382d, - 0x3caeb35e, 0x9d9737b0, 0x4542910f, 0xe47b15e1, 0xdc409e92, - 0x7d791a7c, 0xac378874, 0x0d0e0c9a, 0x353587e9, 0x940c0307, - 0x5fefccd6, 0xfed64838, 0xc6edc34b, 0x67d447a5, 0xb69ad5ad, - 0x17a35143, 0x2f98da30, 0x8ea15ede, 0x5674f861, 0xf74d7c8f, - 0xcf76f7fc, 0x6e4f7312, 0xbf01e11a, 0x1e3865f4, 0x2603ee87, - 0x873a6a69, 0x6ab57764, 0xcb8cf38a, 0xf3b778f9, 0x528efc17, - 0x83c06e1f, 0x22f9eaf1, 0x1ac26182, 0xbbfbe56c, 0x632e43d3, - 0xc217c73d, 0xfa2c4c4e, 0x5b15c8a0, 0x8a5b5aa8, 0x2b62de46, - 0x13595535, 0xb260d1db, 0x79831e0a, 0xd8ba9ae4, 0xe0811197, - 0x41b89579, 0x90f60771, 0x31cf839f, 0x09f408ec, 0xa8cd8c02, - 0x70182abd, 0xd121ae53, 0xe91a2520, 0x4823a1ce, 0x996d33c6, - 0x3854b728, 0x006f3c5b, 0xa156b8b5, 0x99b34b70, 0x388acf9e, - 0x00b144ed, 0xa188c003, 0x70c6520b, 0xd1ffd6e5, 0xe9c45d96, - 0x48fdd978, 0x90287fc7, 0x3111fb29, 0x092a705a, 0xa813f4b4, - 0x795d66bc, 0xd864e252, 0xe05f6921, 0x4166edcf, 0x8a85221e, - 0x2bbca6f0, 0x13872d83, 0xb2bea96d, 0x63f03b65, 0xc2c9bf8b, - 0xfaf234f8, 0x5bcbb016, 0x831e16a9, 0x22279247, 0x1a1c1934, - 0xbb259dda, 0x6a6b0fd2, 0xcb528b3c, 0xf369004f, 0x525084a1, - 0xbfdf99ac, 0x1ee61d42, 0x26dd9631, 0x87e412df, 0x56aa80d7, - 0xf7930439, 0xcfa88f4a, 0x6e910ba4, 0xb644ad1b, 0x177d29f5, - 0x2f46a286, 0x8e7f2668, 0x5f31b460, 0xfe08308e, 0xc633bbfd, - 0x670a3f13, 0xace9f0c2, 0x0dd0742c, 0x35ebff5f, 0x94d27bb1, - 0x459ce9b9, 0xe4a56d57, 0xdc9ee624, 0x7da762ca, 0xa572c475, - 0x044b409b, 0x3c70cbe8, 0x9d494f06, 0x4c07dd0e, 0xed3e59e0, - 0xd505d293, 0x743c567d, 0xd56aeec8, 0x74536a26, 0x4c68e155, - 0xed5165bb, 0x3c1ff7b3, 0x9d26735d, 0xa51df82e, 0x04247cc0, - 0xdcf1da7f, 0x7dc85e91, 0x45f3d5e2, 0xe4ca510c, 0x3584c304, - 0x94bd47ea, 0xac86cc99, 0x0dbf4877, 0xc65c87a6, 0x67650348, - 0x5f5e883b, 0xfe670cd5, 0x2f299edd, 0x8e101a33, 0xb62b9140, - 0x171215ae, 0xcfc7b311, 0x6efe37ff, 0x56c5bc8c, 0xf7fc3862, - 0x26b2aa6a, 0x878b2e84, 0xbfb0a5f7, 0x1e892119, 0xf3063c14, - 0x523fb8fa, 0x6a043389, 0xcb3db767, 0x1a73256f, 0xbb4aa181, - 0x83712af2, 0x2248ae1c, 0xfa9d08a3, 0x5ba48c4d, 0x639f073e, - 0xc2a683d0, 0x13e811d8, 0xb2d19536, 0x8aea1e45, 0x2bd39aab, - 0xe030557a, 0x4109d194, 0x79325ae7, 0xd80bde09, 0x09454c01, - 0xa87cc8ef, 0x9047439c, 0x317ec772, 0xe9ab61cd, 0x4892e523, - 0x70a96e50, 0xd190eabe, 0x00de78b6, 0xa1e7fc58, 0x99dc772b, - 0x38e5f3c5}, - {0x00000000, 0xe81790a1, 0x0b5e2703, 0xe349b7a2, 0x16bc4e06, - 0xfeabdea7, 0x1de26905, 0xf5f5f9a4, 0x2d789c0c, 0xc56f0cad, - 0x2626bb0f, 0xce312bae, 0x3bc4d20a, 0xd3d342ab, 0x309af509, - 0xd88d65a8, 0x5af13818, 0xb2e6a8b9, 0x51af1f1b, 0xb9b88fba, - 0x4c4d761e, 0xa45ae6bf, 0x4713511d, 0xaf04c1bc, 0x7789a414, - 0x9f9e34b5, 0x7cd78317, 0x94c013b6, 0x6135ea12, 0x89227ab3, - 0x6a6bcd11, 0x827c5db0, 0xb5e27030, 0x5df5e091, 0xbebc5733, - 0x56abc792, 0xa35e3e36, 0x4b49ae97, 0xa8001935, 0x40178994, - 0x989aec3c, 0x708d7c9d, 0x93c4cb3f, 0x7bd35b9e, 0x8e26a23a, - 0x6631329b, 0x85788539, 0x6d6f1598, 0xef134828, 0x0704d889, - 0xe44d6f2b, 0x0c5aff8a, 0xf9af062e, 0x11b8968f, 0xf2f1212d, - 0x1ae6b18c, 0xc26bd424, 0x2a7c4485, 0xc935f327, 0x21226386, - 0xd4d79a22, 0x3cc00a83, 0xdf89bd21, 0x379e2d80, 0xb0b5e621, - 0x58a27680, 0xbbebc122, 0x53fc5183, 0xa609a827, 0x4e1e3886, - 0xad578f24, 0x45401f85, 0x9dcd7a2d, 0x75daea8c, 0x96935d2e, - 0x7e84cd8f, 0x8b71342b, 0x6366a48a, 0x802f1328, 0x68388389, - 0xea44de39, 0x02534e98, 0xe11af93a, 0x090d699b, 0xfcf8903f, - 0x14ef009e, 0xf7a6b73c, 0x1fb1279d, 0xc73c4235, 0x2f2bd294, - 0xcc626536, 0x2475f597, 0xd1800c33, 0x39979c92, 0xdade2b30, - 0x32c9bb91, 0x05579611, 0xed4006b0, 0x0e09b112, 0xe61e21b3, - 0x13ebd817, 0xfbfc48b6, 0x18b5ff14, 0xf0a26fb5, 0x282f0a1d, - 0xc0389abc, 0x23712d1e, 0xcb66bdbf, 0x3e93441b, 0xd684d4ba, - 0x35cd6318, 0xdddaf3b9, 0x5fa6ae09, 0xb7b13ea8, 0x54f8890a, - 0xbcef19ab, 0x491ae00f, 0xa10d70ae, 0x4244c70c, 0xaa5357ad, - 0x72de3205, 0x9ac9a2a4, 0x79801506, 0x919785a7, 0x64627c03, - 0x8c75eca2, 0x6f3c5b00, 0x872bcba1, 0xba1aca03, 0x520d5aa2, - 0xb144ed00, 0x59537da1, 0xaca68405, 0x44b114a4, 0xa7f8a306, - 0x4fef33a7, 0x9762560f, 0x7f75c6ae, 0x9c3c710c, 0x742be1ad, - 0x81de1809, 0x69c988a8, 0x8a803f0a, 0x6297afab, 0xe0ebf21b, - 0x08fc62ba, 0xebb5d518, 0x03a245b9, 0xf657bc1d, 0x1e402cbc, - 0xfd099b1e, 0x151e0bbf, 0xcd936e17, 0x2584feb6, 0xc6cd4914, - 0x2edad9b5, 0xdb2f2011, 0x3338b0b0, 0xd0710712, 0x386697b3, - 0x0ff8ba33, 0xe7ef2a92, 0x04a69d30, 0xecb10d91, 0x1944f435, - 0xf1536494, 0x121ad336, 0xfa0d4397, 0x2280263f, 0xca97b69e, - 0x29de013c, 0xc1c9919d, 0x343c6839, 0xdc2bf898, 0x3f624f3a, - 0xd775df9b, 0x5509822b, 0xbd1e128a, 0x5e57a528, 0xb6403589, - 0x43b5cc2d, 0xaba25c8c, 0x48ebeb2e, 0xa0fc7b8f, 0x78711e27, - 0x90668e86, 0x732f3924, 0x9b38a985, 0x6ecd5021, 0x86dac080, - 0x65937722, 0x8d84e783, 0x0aaf2c22, 0xe2b8bc83, 0x01f10b21, - 0xe9e69b80, 0x1c136224, 0xf404f285, 0x174d4527, 0xff5ad586, - 0x27d7b02e, 0xcfc0208f, 0x2c89972d, 0xc49e078c, 0x316bfe28, - 0xd97c6e89, 0x3a35d92b, 0xd222498a, 0x505e143a, 0xb849849b, - 0x5b003339, 0xb317a398, 0x46e25a3c, 0xaef5ca9d, 0x4dbc7d3f, - 0xa5abed9e, 0x7d268836, 0x95311897, 0x7678af35, 0x9e6f3f94, - 0x6b9ac630, 0x838d5691, 0x60c4e133, 0x88d37192, 0xbf4d5c12, - 0x575accb3, 0xb4137b11, 0x5c04ebb0, 0xa9f11214, 0x41e682b5, - 0xa2af3517, 0x4ab8a5b6, 0x9235c01e, 0x7a2250bf, 0x996be71d, - 0x717c77bc, 0x84898e18, 0x6c9e1eb9, 0x8fd7a91b, 0x67c039ba, - 0xe5bc640a, 0x0dabf4ab, 0xeee24309, 0x06f5d3a8, 0xf3002a0c, - 0x1b17baad, 0xf85e0d0f, 0x10499dae, 0xc8c4f806, 0x20d368a7, - 0xc39adf05, 0x2b8d4fa4, 0xde78b600, 0x366f26a1, 0xd5269103, - 0x3d3101a2}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x0000000000000000, 0xa19017e800000000, 0x03275e0b00000000, - 0xa2b749e300000000, 0x064ebc1600000000, 0xa7deabfe00000000, - 0x0569e21d00000000, 0xa4f9f5f500000000, 0x0c9c782d00000000, - 0xad0c6fc500000000, 0x0fbb262600000000, 0xae2b31ce00000000, - 0x0ad2c43b00000000, 0xab42d3d300000000, 0x09f59a3000000000, - 0xa8658dd800000000, 0x1838f15a00000000, 0xb9a8e6b200000000, - 0x1b1faf5100000000, 0xba8fb8b900000000, 0x1e764d4c00000000, - 0xbfe65aa400000000, 0x1d51134700000000, 0xbcc104af00000000, - 0x14a4897700000000, 0xb5349e9f00000000, 0x1783d77c00000000, - 0xb613c09400000000, 0x12ea356100000000, 0xb37a228900000000, - 0x11cd6b6a00000000, 0xb05d7c8200000000, 0x3070e2b500000000, - 0x91e0f55d00000000, 0x3357bcbe00000000, 0x92c7ab5600000000, - 0x363e5ea300000000, 0x97ae494b00000000, 0x351900a800000000, - 0x9489174000000000, 0x3cec9a9800000000, 0x9d7c8d7000000000, - 0x3fcbc49300000000, 0x9e5bd37b00000000, 0x3aa2268e00000000, - 0x9b32316600000000, 0x3985788500000000, 0x98156f6d00000000, - 0x284813ef00000000, 0x89d8040700000000, 0x2b6f4de400000000, - 0x8aff5a0c00000000, 0x2e06aff900000000, 0x8f96b81100000000, - 0x2d21f1f200000000, 0x8cb1e61a00000000, 0x24d46bc200000000, - 0x85447c2a00000000, 0x27f335c900000000, 0x8663222100000000, - 0x229ad7d400000000, 0x830ac03c00000000, 0x21bd89df00000000, - 0x802d9e3700000000, 0x21e6b5b000000000, 0x8076a25800000000, - 0x22c1ebbb00000000, 0x8351fc5300000000, 0x27a809a600000000, - 0x86381e4e00000000, 0x248f57ad00000000, 0x851f404500000000, - 0x2d7acd9d00000000, 0x8ceada7500000000, 0x2e5d939600000000, - 0x8fcd847e00000000, 0x2b34718b00000000, 0x8aa4666300000000, - 0x28132f8000000000, 0x8983386800000000, 0x39de44ea00000000, - 0x984e530200000000, 0x3af91ae100000000, 0x9b690d0900000000, - 0x3f90f8fc00000000, 0x9e00ef1400000000, 0x3cb7a6f700000000, - 0x9d27b11f00000000, 0x35423cc700000000, 0x94d22b2f00000000, - 0x366562cc00000000, 0x97f5752400000000, 0x330c80d100000000, - 0x929c973900000000, 0x302bdeda00000000, 0x91bbc93200000000, - 0x1196570500000000, 0xb00640ed00000000, 0x12b1090e00000000, - 0xb3211ee600000000, 0x17d8eb1300000000, 0xb648fcfb00000000, - 0x14ffb51800000000, 0xb56fa2f000000000, 0x1d0a2f2800000000, - 0xbc9a38c000000000, 0x1e2d712300000000, 0xbfbd66cb00000000, - 0x1b44933e00000000, 0xbad484d600000000, 0x1863cd3500000000, - 0xb9f3dadd00000000, 0x09aea65f00000000, 0xa83eb1b700000000, - 0x0a89f85400000000, 0xab19efbc00000000, 0x0fe01a4900000000, - 0xae700da100000000, 0x0cc7444200000000, 0xad5753aa00000000, - 0x0532de7200000000, 0xa4a2c99a00000000, 0x0615807900000000, - 0xa785979100000000, 0x037c626400000000, 0xa2ec758c00000000, - 0x005b3c6f00000000, 0xa1cb2b8700000000, 0x03ca1aba00000000, - 0xa25a0d5200000000, 0x00ed44b100000000, 0xa17d535900000000, - 0x0584a6ac00000000, 0xa414b14400000000, 0x06a3f8a700000000, - 0xa733ef4f00000000, 0x0f56629700000000, 0xaec6757f00000000, - 0x0c713c9c00000000, 0xade12b7400000000, 0x0918de8100000000, - 0xa888c96900000000, 0x0a3f808a00000000, 0xabaf976200000000, - 0x1bf2ebe000000000, 0xba62fc0800000000, 0x18d5b5eb00000000, - 0xb945a20300000000, 0x1dbc57f600000000, 0xbc2c401e00000000, - 0x1e9b09fd00000000, 0xbf0b1e1500000000, 0x176e93cd00000000, - 0xb6fe842500000000, 0x1449cdc600000000, 0xb5d9da2e00000000, - 0x11202fdb00000000, 0xb0b0383300000000, 0x120771d000000000, - 0xb397663800000000, 0x33baf80f00000000, 0x922aefe700000000, - 0x309da60400000000, 0x910db1ec00000000, 0x35f4441900000000, - 0x946453f100000000, 0x36d31a1200000000, 0x97430dfa00000000, - 0x3f26802200000000, 0x9eb697ca00000000, 0x3c01de2900000000, - 0x9d91c9c100000000, 0x39683c3400000000, 0x98f82bdc00000000, - 0x3a4f623f00000000, 0x9bdf75d700000000, 0x2b82095500000000, - 0x8a121ebd00000000, 0x28a5575e00000000, 0x893540b600000000, - 0x2dccb54300000000, 0x8c5ca2ab00000000, 0x2eebeb4800000000, - 0x8f7bfca000000000, 0x271e717800000000, 0x868e669000000000, - 0x24392f7300000000, 0x85a9389b00000000, 0x2150cd6e00000000, - 0x80c0da8600000000, 0x2277936500000000, 0x83e7848d00000000, - 0x222caf0a00000000, 0x83bcb8e200000000, 0x210bf10100000000, - 0x809be6e900000000, 0x2462131c00000000, 0x85f204f400000000, - 0x27454d1700000000, 0x86d55aff00000000, 0x2eb0d72700000000, - 0x8f20c0cf00000000, 0x2d97892c00000000, 0x8c079ec400000000, - 0x28fe6b3100000000, 0x896e7cd900000000, 0x2bd9353a00000000, - 0x8a4922d200000000, 0x3a145e5000000000, 0x9b8449b800000000, - 0x3933005b00000000, 0x98a317b300000000, 0x3c5ae24600000000, - 0x9dcaf5ae00000000, 0x3f7dbc4d00000000, 0x9eedaba500000000, - 0x3688267d00000000, 0x9718319500000000, 0x35af787600000000, - 0x943f6f9e00000000, 0x30c69a6b00000000, 0x91568d8300000000, - 0x33e1c46000000000, 0x9271d38800000000, 0x125c4dbf00000000, - 0xb3cc5a5700000000, 0x117b13b400000000, 0xb0eb045c00000000, - 0x1412f1a900000000, 0xb582e64100000000, 0x1735afa200000000, - 0xb6a5b84a00000000, 0x1ec0359200000000, 0xbf50227a00000000, - 0x1de76b9900000000, 0xbc777c7100000000, 0x188e898400000000, - 0xb91e9e6c00000000, 0x1ba9d78f00000000, 0xba39c06700000000, - 0x0a64bce500000000, 0xabf4ab0d00000000, 0x0943e2ee00000000, - 0xa8d3f50600000000, 0x0c2a00f300000000, 0xadba171b00000000, - 0x0f0d5ef800000000, 0xae9d491000000000, 0x06f8c4c800000000, - 0xa768d32000000000, 0x05df9ac300000000, 0xa44f8d2b00000000, - 0x00b678de00000000, 0xa1266f3600000000, 0x039126d500000000, - 0xa201313d00000000}, - {0x0000000000000000, 0xee8439a100000000, 0x9d0f029900000000, - 0x738b3b3800000000, 0x7b1975e900000000, 0x959d4c4800000000, - 0xe616777000000000, 0x08924ed100000000, 0xb7349b0900000000, - 0x59b0a2a800000000, 0x2a3b999000000000, 0xc4bfa03100000000, - 0xcc2deee000000000, 0x22a9d74100000000, 0x5122ec7900000000, - 0xbfa6d5d800000000, 0x6e69361300000000, 0x80ed0fb200000000, - 0xf366348a00000000, 0x1de20d2b00000000, 0x157043fa00000000, - 0xfbf47a5b00000000, 0x887f416300000000, 0x66fb78c200000000, - 0xd95dad1a00000000, 0x37d994bb00000000, 0x4452af8300000000, - 0xaad6962200000000, 0xa244d8f300000000, 0x4cc0e15200000000, - 0x3f4bda6a00000000, 0xd1cfe3cb00000000, 0xdcd26c2600000000, - 0x3256558700000000, 0x41dd6ebf00000000, 0xaf59571e00000000, - 0xa7cb19cf00000000, 0x494f206e00000000, 0x3ac41b5600000000, - 0xd44022f700000000, 0x6be6f72f00000000, 0x8562ce8e00000000, - 0xf6e9f5b600000000, 0x186dcc1700000000, 0x10ff82c600000000, - 0xfe7bbb6700000000, 0x8df0805f00000000, 0x6374b9fe00000000, - 0xb2bb5a3500000000, 0x5c3f639400000000, 0x2fb458ac00000000, - 0xc130610d00000000, 0xc9a22fdc00000000, 0x2726167d00000000, - 0x54ad2d4500000000, 0xba2914e400000000, 0x058fc13c00000000, - 0xeb0bf89d00000000, 0x9880c3a500000000, 0x7604fa0400000000, - 0x7e96b4d500000000, 0x90128d7400000000, 0xe399b64c00000000, - 0x0d1d8fed00000000, 0xb8a5d94c00000000, 0x5621e0ed00000000, - 0x25aadbd500000000, 0xcb2ee27400000000, 0xc3bcaca500000000, - 0x2d38950400000000, 0x5eb3ae3c00000000, 0xb037979d00000000, - 0x0f91424500000000, 0xe1157be400000000, 0x929e40dc00000000, - 0x7c1a797d00000000, 0x748837ac00000000, 0x9a0c0e0d00000000, - 0xe987353500000000, 0x07030c9400000000, 0xd6ccef5f00000000, - 0x3848d6fe00000000, 0x4bc3edc600000000, 0xa547d46700000000, - 0xadd59ab600000000, 0x4351a31700000000, 0x30da982f00000000, - 0xde5ea18e00000000, 0x61f8745600000000, 0x8f7c4df700000000, - 0xfcf776cf00000000, 0x12734f6e00000000, 0x1ae101bf00000000, - 0xf465381e00000000, 0x87ee032600000000, 0x696a3a8700000000, - 0x6477b56a00000000, 0x8af38ccb00000000, 0xf978b7f300000000, - 0x17fc8e5200000000, 0x1f6ec08300000000, 0xf1eaf92200000000, - 0x8261c21a00000000, 0x6ce5fbbb00000000, 0xd3432e6300000000, - 0x3dc717c200000000, 0x4e4c2cfa00000000, 0xa0c8155b00000000, - 0xa85a5b8a00000000, 0x46de622b00000000, 0x3555591300000000, - 0xdbd160b200000000, 0x0a1e837900000000, 0xe49abad800000000, - 0x971181e000000000, 0x7995b84100000000, 0x7107f69000000000, - 0x9f83cf3100000000, 0xec08f40900000000, 0x028ccda800000000, - 0xbd2a187000000000, 0x53ae21d100000000, 0x20251ae900000000, - 0xcea1234800000000, 0xc6336d9900000000, 0x28b7543800000000, - 0x5b3c6f0000000000, 0xb5b856a100000000, 0x704bb39900000000, - 0x9ecf8a3800000000, 0xed44b10000000000, 0x03c088a100000000, - 0x0b52c67000000000, 0xe5d6ffd100000000, 0x965dc4e900000000, - 0x78d9fd4800000000, 0xc77f289000000000, 0x29fb113100000000, - 0x5a702a0900000000, 0xb4f413a800000000, 0xbc665d7900000000, - 0x52e264d800000000, 0x21695fe000000000, 0xcfed664100000000, - 0x1e22858a00000000, 0xf0a6bc2b00000000, 0x832d871300000000, - 0x6da9beb200000000, 0x653bf06300000000, 0x8bbfc9c200000000, - 0xf834f2fa00000000, 0x16b0cb5b00000000, 0xa9161e8300000000, - 0x4792272200000000, 0x34191c1a00000000, 0xda9d25bb00000000, - 0xd20f6b6a00000000, 0x3c8b52cb00000000, 0x4f0069f300000000, - 0xa184505200000000, 0xac99dfbf00000000, 0x421de61e00000000, - 0x3196dd2600000000, 0xdf12e48700000000, 0xd780aa5600000000, - 0x390493f700000000, 0x4a8fa8cf00000000, 0xa40b916e00000000, - 0x1bad44b600000000, 0xf5297d1700000000, 0x86a2462f00000000, - 0x68267f8e00000000, 0x60b4315f00000000, 0x8e3008fe00000000, - 0xfdbb33c600000000, 0x133f0a6700000000, 0xc2f0e9ac00000000, - 0x2c74d00d00000000, 0x5fffeb3500000000, 0xb17bd29400000000, - 0xb9e99c4500000000, 0x576da5e400000000, 0x24e69edc00000000, - 0xca62a77d00000000, 0x75c472a500000000, 0x9b404b0400000000, - 0xe8cb703c00000000, 0x064f499d00000000, 0x0edd074c00000000, - 0xe0593eed00000000, 0x93d205d500000000, 0x7d563c7400000000, - 0xc8ee6ad500000000, 0x266a537400000000, 0x55e1684c00000000, - 0xbb6551ed00000000, 0xb3f71f3c00000000, 0x5d73269d00000000, - 0x2ef81da500000000, 0xc07c240400000000, 0x7fdaf1dc00000000, - 0x915ec87d00000000, 0xe2d5f34500000000, 0x0c51cae400000000, - 0x04c3843500000000, 0xea47bd9400000000, 0x99cc86ac00000000, - 0x7748bf0d00000000, 0xa6875cc600000000, 0x4803656700000000, - 0x3b885e5f00000000, 0xd50c67fe00000000, 0xdd9e292f00000000, - 0x331a108e00000000, 0x40912bb600000000, 0xae15121700000000, - 0x11b3c7cf00000000, 0xff37fe6e00000000, 0x8cbcc55600000000, - 0x6238fcf700000000, 0x6aaab22600000000, 0x842e8b8700000000, - 0xf7a5b0bf00000000, 0x1921891e00000000, 0x143c06f300000000, - 0xfab83f5200000000, 0x8933046a00000000, 0x67b73dcb00000000, - 0x6f25731a00000000, 0x81a14abb00000000, 0xf22a718300000000, - 0x1cae482200000000, 0xa3089dfa00000000, 0x4d8ca45b00000000, - 0x3e079f6300000000, 0xd083a6c200000000, 0xd811e81300000000, - 0x3695d1b200000000, 0x451eea8a00000000, 0xab9ad32b00000000, - 0x7a5530e000000000, 0x94d1094100000000, 0xe75a327900000000, - 0x09de0bd800000000, 0x014c450900000000, 0xefc87ca800000000, - 0x9c43479000000000, 0x72c77e3100000000, 0xcd61abe900000000, - 0x23e5924800000000, 0x506ea97000000000, 0xbeea90d100000000, - 0xb678de0000000000, 0x58fce7a100000000, 0x2b77dc9900000000, - 0xc5f3e53800000000}, - {0x0000000000000000, 0xfbf6134700000000, 0xf6ed278e00000000, - 0x0d1b34c900000000, 0xaddd3ec700000000, 0x562b2d8000000000, - 0x5b30194900000000, 0xa0c60a0e00000000, 0x1bbd0c5500000000, - 0xe04b1f1200000000, 0xed502bdb00000000, 0x16a6389c00000000, - 0xb660329200000000, 0x4d9621d500000000, 0x408d151c00000000, - 0xbb7b065b00000000, 0x367a19aa00000000, 0xcd8c0aed00000000, - 0xc0973e2400000000, 0x3b612d6300000000, 0x9ba7276d00000000, - 0x6051342a00000000, 0x6d4a00e300000000, 0x96bc13a400000000, - 0x2dc715ff00000000, 0xd63106b800000000, 0xdb2a327100000000, - 0x20dc213600000000, 0x801a2b3800000000, 0x7bec387f00000000, - 0x76f70cb600000000, 0x8d011ff100000000, 0x2df2438f00000000, - 0xd60450c800000000, 0xdb1f640100000000, 0x20e9774600000000, - 0x802f7d4800000000, 0x7bd96e0f00000000, 0x76c25ac600000000, - 0x8d34498100000000, 0x364f4fda00000000, 0xcdb95c9d00000000, - 0xc0a2685400000000, 0x3b547b1300000000, 0x9b92711d00000000, - 0x6064625a00000000, 0x6d7f569300000000, 0x968945d400000000, - 0x1b885a2500000000, 0xe07e496200000000, 0xed657dab00000000, - 0x16936eec00000000, 0xb65564e200000000, 0x4da377a500000000, - 0x40b8436c00000000, 0xbb4e502b00000000, 0x0035567000000000, - 0xfbc3453700000000, 0xf6d871fe00000000, 0x0d2e62b900000000, - 0xade868b700000000, 0x561e7bf000000000, 0x5b054f3900000000, - 0xa0f35c7e00000000, 0x1be2f6c500000000, 0xe014e58200000000, - 0xed0fd14b00000000, 0x16f9c20c00000000, 0xb63fc80200000000, - 0x4dc9db4500000000, 0x40d2ef8c00000000, 0xbb24fccb00000000, - 0x005ffa9000000000, 0xfba9e9d700000000, 0xf6b2dd1e00000000, - 0x0d44ce5900000000, 0xad82c45700000000, 0x5674d71000000000, - 0x5b6fe3d900000000, 0xa099f09e00000000, 0x2d98ef6f00000000, - 0xd66efc2800000000, 0xdb75c8e100000000, 0x2083dba600000000, - 0x8045d1a800000000, 0x7bb3c2ef00000000, 0x76a8f62600000000, - 0x8d5ee56100000000, 0x3625e33a00000000, 0xcdd3f07d00000000, - 0xc0c8c4b400000000, 0x3b3ed7f300000000, 0x9bf8ddfd00000000, - 0x600eceba00000000, 0x6d15fa7300000000, 0x96e3e93400000000, - 0x3610b54a00000000, 0xcde6a60d00000000, 0xc0fd92c400000000, - 0x3b0b818300000000, 0x9bcd8b8d00000000, 0x603b98ca00000000, - 0x6d20ac0300000000, 0x96d6bf4400000000, 0x2dadb91f00000000, - 0xd65baa5800000000, 0xdb409e9100000000, 0x20b68dd600000000, - 0x807087d800000000, 0x7b86949f00000000, 0x769da05600000000, - 0x8d6bb31100000000, 0x006aace000000000, 0xfb9cbfa700000000, - 0xf6878b6e00000000, 0x0d71982900000000, 0xadb7922700000000, - 0x5641816000000000, 0x5b5ab5a900000000, 0xa0aca6ee00000000, - 0x1bd7a0b500000000, 0xe021b3f200000000, 0xed3a873b00000000, - 0x16cc947c00000000, 0xb60a9e7200000000, 0x4dfc8d3500000000, - 0x40e7b9fc00000000, 0xbb11aabb00000000, 0x77c29c5000000000, - 0x8c348f1700000000, 0x812fbbde00000000, 0x7ad9a89900000000, - 0xda1fa29700000000, 0x21e9b1d000000000, 0x2cf2851900000000, - 0xd704965e00000000, 0x6c7f900500000000, 0x9789834200000000, - 0x9a92b78b00000000, 0x6164a4cc00000000, 0xc1a2aec200000000, - 0x3a54bd8500000000, 0x374f894c00000000, 0xccb99a0b00000000, - 0x41b885fa00000000, 0xba4e96bd00000000, 0xb755a27400000000, - 0x4ca3b13300000000, 0xec65bb3d00000000, 0x1793a87a00000000, - 0x1a889cb300000000, 0xe17e8ff400000000, 0x5a0589af00000000, - 0xa1f39ae800000000, 0xace8ae2100000000, 0x571ebd6600000000, - 0xf7d8b76800000000, 0x0c2ea42f00000000, 0x013590e600000000, - 0xfac383a100000000, 0x5a30dfdf00000000, 0xa1c6cc9800000000, - 0xacddf85100000000, 0x572beb1600000000, 0xf7ede11800000000, - 0x0c1bf25f00000000, 0x0100c69600000000, 0xfaf6d5d100000000, - 0x418dd38a00000000, 0xba7bc0cd00000000, 0xb760f40400000000, - 0x4c96e74300000000, 0xec50ed4d00000000, 0x17a6fe0a00000000, - 0x1abdcac300000000, 0xe14bd98400000000, 0x6c4ac67500000000, - 0x97bcd53200000000, 0x9aa7e1fb00000000, 0x6151f2bc00000000, - 0xc197f8b200000000, 0x3a61ebf500000000, 0x377adf3c00000000, - 0xcc8ccc7b00000000, 0x77f7ca2000000000, 0x8c01d96700000000, - 0x811aedae00000000, 0x7aecfee900000000, 0xda2af4e700000000, - 0x21dce7a000000000, 0x2cc7d36900000000, 0xd731c02e00000000, - 0x6c206a9500000000, 0x97d679d200000000, 0x9acd4d1b00000000, - 0x613b5e5c00000000, 0xc1fd545200000000, 0x3a0b471500000000, - 0x371073dc00000000, 0xcce6609b00000000, 0x779d66c000000000, - 0x8c6b758700000000, 0x8170414e00000000, 0x7a86520900000000, - 0xda40580700000000, 0x21b64b4000000000, 0x2cad7f8900000000, - 0xd75b6cce00000000, 0x5a5a733f00000000, 0xa1ac607800000000, - 0xacb754b100000000, 0x574147f600000000, 0xf7874df800000000, - 0x0c715ebf00000000, 0x016a6a7600000000, 0xfa9c793100000000, - 0x41e77f6a00000000, 0xba116c2d00000000, 0xb70a58e400000000, - 0x4cfc4ba300000000, 0xec3a41ad00000000, 0x17cc52ea00000000, - 0x1ad7662300000000, 0xe121756400000000, 0x41d2291a00000000, - 0xba243a5d00000000, 0xb73f0e9400000000, 0x4cc91dd300000000, - 0xec0f17dd00000000, 0x17f9049a00000000, 0x1ae2305300000000, - 0xe114231400000000, 0x5a6f254f00000000, 0xa199360800000000, - 0xac8202c100000000, 0x5774118600000000, 0xf7b21b8800000000, - 0x0c4408cf00000000, 0x015f3c0600000000, 0xfaa92f4100000000, - 0x77a830b000000000, 0x8c5e23f700000000, 0x8145173e00000000, - 0x7ab3047900000000, 0xda750e7700000000, 0x21831d3000000000, - 0x2c9829f900000000, 0xd76e3abe00000000, 0x6c153ce500000000, - 0x97e32fa200000000, 0x9af81b6b00000000, 0x610e082c00000000, - 0xc1c8022200000000, 0x3a3e116500000000, 0x372525ac00000000, - 0xccd336eb00000000}, - {0x0000000000000000, 0x6238282a00000000, 0xc470505400000000, - 0xa648787e00000000, 0x88e1a0a800000000, 0xead9888200000000, - 0x4c91f0fc00000000, 0x2ea9d8d600000000, 0x51c5308a00000000, - 0x33fd18a000000000, 0x95b560de00000000, 0xf78d48f400000000, - 0xd924902200000000, 0xbb1cb80800000000, 0x1d54c07600000000, - 0x7f6ce85c00000000, 0xe38c10cf00000000, 0x81b438e500000000, - 0x27fc409b00000000, 0x45c468b100000000, 0x6b6db06700000000, - 0x0955984d00000000, 0xaf1de03300000000, 0xcd25c81900000000, - 0xb249204500000000, 0xd071086f00000000, 0x7639701100000000, - 0x1401583b00000000, 0x3aa880ed00000000, 0x5890a8c700000000, - 0xfed8d0b900000000, 0x9ce0f89300000000, 0x871f504500000000, - 0xe527786f00000000, 0x436f001100000000, 0x2157283b00000000, - 0x0ffef0ed00000000, 0x6dc6d8c700000000, 0xcb8ea0b900000000, - 0xa9b6889300000000, 0xd6da60cf00000000, 0xb4e248e500000000, - 0x12aa309b00000000, 0x709218b100000000, 0x5e3bc06700000000, - 0x3c03e84d00000000, 0x9a4b903300000000, 0xf873b81900000000, - 0x6493408a00000000, 0x06ab68a000000000, 0xa0e310de00000000, - 0xc2db38f400000000, 0xec72e02200000000, 0x8e4ac80800000000, - 0x2802b07600000000, 0x4a3a985c00000000, 0x3556700000000000, - 0x576e582a00000000, 0xf126205400000000, 0x931e087e00000000, - 0xbdb7d0a800000000, 0xdf8ff88200000000, 0x79c780fc00000000, - 0x1bffa8d600000000, 0x0e3fa08a00000000, 0x6c0788a000000000, - 0xca4ff0de00000000, 0xa877d8f400000000, 0x86de002200000000, - 0xe4e6280800000000, 0x42ae507600000000, 0x2096785c00000000, - 0x5ffa900000000000, 0x3dc2b82a00000000, 0x9b8ac05400000000, - 0xf9b2e87e00000000, 0xd71b30a800000000, 0xb523188200000000, - 0x136b60fc00000000, 0x715348d600000000, 0xedb3b04500000000, - 0x8f8b986f00000000, 0x29c3e01100000000, 0x4bfbc83b00000000, - 0x655210ed00000000, 0x076a38c700000000, 0xa12240b900000000, - 0xc31a689300000000, 0xbc7680cf00000000, 0xde4ea8e500000000, - 0x7806d09b00000000, 0x1a3ef8b100000000, 0x3497206700000000, - 0x56af084d00000000, 0xf0e7703300000000, 0x92df581900000000, - 0x8920f0cf00000000, 0xeb18d8e500000000, 0x4d50a09b00000000, - 0x2f6888b100000000, 0x01c1506700000000, 0x63f9784d00000000, - 0xc5b1003300000000, 0xa789281900000000, 0xd8e5c04500000000, - 0xbadde86f00000000, 0x1c95901100000000, 0x7eadb83b00000000, - 0x500460ed00000000, 0x323c48c700000000, 0x947430b900000000, - 0xf64c189300000000, 0x6aace00000000000, 0x0894c82a00000000, - 0xaedcb05400000000, 0xcce4987e00000000, 0xe24d40a800000000, - 0x8075688200000000, 0x263d10fc00000000, 0x440538d600000000, - 0x3b69d08a00000000, 0x5951f8a000000000, 0xff1980de00000000, - 0x9d21a8f400000000, 0xb388702200000000, 0xd1b0580800000000, - 0x77f8207600000000, 0x15c0085c00000000, 0x5d7831ce00000000, - 0x3f4019e400000000, 0x9908619a00000000, 0xfb3049b000000000, - 0xd599916600000000, 0xb7a1b94c00000000, 0x11e9c13200000000, - 0x73d1e91800000000, 0x0cbd014400000000, 0x6e85296e00000000, - 0xc8cd511000000000, 0xaaf5793a00000000, 0x845ca1ec00000000, - 0xe66489c600000000, 0x402cf1b800000000, 0x2214d99200000000, - 0xbef4210100000000, 0xdccc092b00000000, 0x7a84715500000000, - 0x18bc597f00000000, 0x361581a900000000, 0x542da98300000000, - 0xf265d1fd00000000, 0x905df9d700000000, 0xef31118b00000000, - 0x8d0939a100000000, 0x2b4141df00000000, 0x497969f500000000, - 0x67d0b12300000000, 0x05e8990900000000, 0xa3a0e17700000000, - 0xc198c95d00000000, 0xda67618b00000000, 0xb85f49a100000000, - 0x1e1731df00000000, 0x7c2f19f500000000, 0x5286c12300000000, - 0x30bee90900000000, 0x96f6917700000000, 0xf4ceb95d00000000, - 0x8ba2510100000000, 0xe99a792b00000000, 0x4fd2015500000000, - 0x2dea297f00000000, 0x0343f1a900000000, 0x617bd98300000000, - 0xc733a1fd00000000, 0xa50b89d700000000, 0x39eb714400000000, - 0x5bd3596e00000000, 0xfd9b211000000000, 0x9fa3093a00000000, - 0xb10ad1ec00000000, 0xd332f9c600000000, 0x757a81b800000000, - 0x1742a99200000000, 0x682e41ce00000000, 0x0a1669e400000000, - 0xac5e119a00000000, 0xce6639b000000000, 0xe0cfe16600000000, - 0x82f7c94c00000000, 0x24bfb13200000000, 0x4687991800000000, - 0x5347914400000000, 0x317fb96e00000000, 0x9737c11000000000, - 0xf50fe93a00000000, 0xdba631ec00000000, 0xb99e19c600000000, - 0x1fd661b800000000, 0x7dee499200000000, 0x0282a1ce00000000, - 0x60ba89e400000000, 0xc6f2f19a00000000, 0xa4cad9b000000000, - 0x8a63016600000000, 0xe85b294c00000000, 0x4e13513200000000, - 0x2c2b791800000000, 0xb0cb818b00000000, 0xd2f3a9a100000000, - 0x74bbd1df00000000, 0x1683f9f500000000, 0x382a212300000000, - 0x5a12090900000000, 0xfc5a717700000000, 0x9e62595d00000000, - 0xe10eb10100000000, 0x8336992b00000000, 0x257ee15500000000, - 0x4746c97f00000000, 0x69ef11a900000000, 0x0bd7398300000000, - 0xad9f41fd00000000, 0xcfa769d700000000, 0xd458c10100000000, - 0xb660e92b00000000, 0x1028915500000000, 0x7210b97f00000000, - 0x5cb961a900000000, 0x3e81498300000000, 0x98c931fd00000000, - 0xfaf119d700000000, 0x859df18b00000000, 0xe7a5d9a100000000, - 0x41eda1df00000000, 0x23d589f500000000, 0x0d7c512300000000, - 0x6f44790900000000, 0xc90c017700000000, 0xab34295d00000000, - 0x37d4d1ce00000000, 0x55ecf9e400000000, 0xf3a4819a00000000, - 0x919ca9b000000000, 0xbf35716600000000, 0xdd0d594c00000000, - 0x7b45213200000000, 0x197d091800000000, 0x6611e14400000000, - 0x0429c96e00000000, 0xa261b11000000000, 0xc059993a00000000, - 0xeef041ec00000000, 0x8cc869c600000000, 0x2a8011b800000000, - 0x48b8399200000000}, - {0x0000000000000000, 0x4c2896a300000000, 0xd9565d9c00000000, - 0x957ecb3f00000000, 0xf3abcbe300000000, 0xbf835d4000000000, - 0x2afd967f00000000, 0x66d500dc00000000, 0xa751e61c00000000, - 0xeb7970bf00000000, 0x7e07bb8000000000, 0x322f2d2300000000, - 0x54fa2dff00000000, 0x18d2bb5c00000000, 0x8dac706300000000, - 0xc184e6c000000000, 0x4ea3cc3900000000, 0x028b5a9a00000000, - 0x97f591a500000000, 0xdbdd070600000000, 0xbd0807da00000000, - 0xf120917900000000, 0x645e5a4600000000, 0x2876cce500000000, - 0xe9f22a2500000000, 0xa5dabc8600000000, 0x30a477b900000000, - 0x7c8ce11a00000000, 0x1a59e1c600000000, 0x5671776500000000, - 0xc30fbc5a00000000, 0x8f272af900000000, 0x9c46997300000000, - 0xd06e0fd000000000, 0x4510c4ef00000000, 0x0938524c00000000, - 0x6fed529000000000, 0x23c5c43300000000, 0xb6bb0f0c00000000, - 0xfa9399af00000000, 0x3b177f6f00000000, 0x773fe9cc00000000, - 0xe24122f300000000, 0xae69b45000000000, 0xc8bcb48c00000000, - 0x8494222f00000000, 0x11eae91000000000, 0x5dc27fb300000000, - 0xd2e5554a00000000, 0x9ecdc3e900000000, 0x0bb308d600000000, - 0x479b9e7500000000, 0x214e9ea900000000, 0x6d66080a00000000, - 0xf818c33500000000, 0xb430559600000000, 0x75b4b35600000000, - 0x399c25f500000000, 0xace2eeca00000000, 0xe0ca786900000000, - 0x861f78b500000000, 0xca37ee1600000000, 0x5f49252900000000, - 0x1361b38a00000000, 0x388d32e700000000, 0x74a5a44400000000, - 0xe1db6f7b00000000, 0xadf3f9d800000000, 0xcb26f90400000000, - 0x870e6fa700000000, 0x1270a49800000000, 0x5e58323b00000000, - 0x9fdcd4fb00000000, 0xd3f4425800000000, 0x468a896700000000, - 0x0aa21fc400000000, 0x6c771f1800000000, 0x205f89bb00000000, - 0xb521428400000000, 0xf909d42700000000, 0x762efede00000000, - 0x3a06687d00000000, 0xaf78a34200000000, 0xe35035e100000000, - 0x8585353d00000000, 0xc9ada39e00000000, 0x5cd368a100000000, - 0x10fbfe0200000000, 0xd17f18c200000000, 0x9d578e6100000000, - 0x0829455e00000000, 0x4401d3fd00000000, 0x22d4d32100000000, - 0x6efc458200000000, 0xfb828ebd00000000, 0xb7aa181e00000000, - 0xa4cbab9400000000, 0xe8e33d3700000000, 0x7d9df60800000000, - 0x31b560ab00000000, 0x5760607700000000, 0x1b48f6d400000000, - 0x8e363deb00000000, 0xc21eab4800000000, 0x039a4d8800000000, - 0x4fb2db2b00000000, 0xdacc101400000000, 0x96e486b700000000, - 0xf031866b00000000, 0xbc1910c800000000, 0x2967dbf700000000, - 0x654f4d5400000000, 0xea6867ad00000000, 0xa640f10e00000000, - 0x333e3a3100000000, 0x7f16ac9200000000, 0x19c3ac4e00000000, - 0x55eb3aed00000000, 0xc095f1d200000000, 0x8cbd677100000000, - 0x4d3981b100000000, 0x0111171200000000, 0x946fdc2d00000000, - 0xd8474a8e00000000, 0xbe924a5200000000, 0xf2badcf100000000, - 0x67c417ce00000000, 0x2bec816d00000000, 0x311c141500000000, - 0x7d3482b600000000, 0xe84a498900000000, 0xa462df2a00000000, - 0xc2b7dff600000000, 0x8e9f495500000000, 0x1be1826a00000000, - 0x57c914c900000000, 0x964df20900000000, 0xda6564aa00000000, - 0x4f1baf9500000000, 0x0333393600000000, 0x65e639ea00000000, - 0x29ceaf4900000000, 0xbcb0647600000000, 0xf098f2d500000000, - 0x7fbfd82c00000000, 0x33974e8f00000000, 0xa6e985b000000000, - 0xeac1131300000000, 0x8c1413cf00000000, 0xc03c856c00000000, - 0x55424e5300000000, 0x196ad8f000000000, 0xd8ee3e3000000000, - 0x94c6a89300000000, 0x01b863ac00000000, 0x4d90f50f00000000, - 0x2b45f5d300000000, 0x676d637000000000, 0xf213a84f00000000, - 0xbe3b3eec00000000, 0xad5a8d6600000000, 0xe1721bc500000000, - 0x740cd0fa00000000, 0x3824465900000000, 0x5ef1468500000000, - 0x12d9d02600000000, 0x87a71b1900000000, 0xcb8f8dba00000000, - 0x0a0b6b7a00000000, 0x4623fdd900000000, 0xd35d36e600000000, - 0x9f75a04500000000, 0xf9a0a09900000000, 0xb588363a00000000, - 0x20f6fd0500000000, 0x6cde6ba600000000, 0xe3f9415f00000000, - 0xafd1d7fc00000000, 0x3aaf1cc300000000, 0x76878a6000000000, - 0x10528abc00000000, 0x5c7a1c1f00000000, 0xc904d72000000000, - 0x852c418300000000, 0x44a8a74300000000, 0x088031e000000000, - 0x9dfefadf00000000, 0xd1d66c7c00000000, 0xb7036ca000000000, - 0xfb2bfa0300000000, 0x6e55313c00000000, 0x227da79f00000000, - 0x099126f200000000, 0x45b9b05100000000, 0xd0c77b6e00000000, - 0x9cefedcd00000000, 0xfa3aed1100000000, 0xb6127bb200000000, - 0x236cb08d00000000, 0x6f44262e00000000, 0xaec0c0ee00000000, - 0xe2e8564d00000000, 0x77969d7200000000, 0x3bbe0bd100000000, - 0x5d6b0b0d00000000, 0x11439dae00000000, 0x843d569100000000, - 0xc815c03200000000, 0x4732eacb00000000, 0x0b1a7c6800000000, - 0x9e64b75700000000, 0xd24c21f400000000, 0xb499212800000000, - 0xf8b1b78b00000000, 0x6dcf7cb400000000, 0x21e7ea1700000000, - 0xe0630cd700000000, 0xac4b9a7400000000, 0x3935514b00000000, - 0x751dc7e800000000, 0x13c8c73400000000, 0x5fe0519700000000, - 0xca9e9aa800000000, 0x86b60c0b00000000, 0x95d7bf8100000000, - 0xd9ff292200000000, 0x4c81e21d00000000, 0x00a974be00000000, - 0x667c746200000000, 0x2a54e2c100000000, 0xbf2a29fe00000000, - 0xf302bf5d00000000, 0x3286599d00000000, 0x7eaecf3e00000000, - 0xebd0040100000000, 0xa7f892a200000000, 0xc12d927e00000000, - 0x8d0504dd00000000, 0x187bcfe200000000, 0x5453594100000000, - 0xdb7473b800000000, 0x975ce51b00000000, 0x02222e2400000000, - 0x4e0ab88700000000, 0x28dfb85b00000000, 0x64f72ef800000000, - 0xf189e5c700000000, 0xbda1736400000000, 0x7c2595a400000000, - 0x300d030700000000, 0xa573c83800000000, 0xe95b5e9b00000000, - 0x8f8e5e4700000000, 0xc3a6c8e400000000, 0x56d803db00000000, - 0x1af0957800000000}, - {0x0000000000000000, 0x939bc97f00000000, 0x263793ff00000000, - 0xb5ac5a8000000000, 0x0d68572400000000, 0x9ef39e5b00000000, - 0x2b5fc4db00000000, 0xb8c40da400000000, 0x1ad0ae4800000000, - 0x894b673700000000, 0x3ce73db700000000, 0xaf7cf4c800000000, - 0x17b8f96c00000000, 0x8423301300000000, 0x318f6a9300000000, - 0xa214a3ec00000000, 0x34a05d9100000000, 0xa73b94ee00000000, - 0x1297ce6e00000000, 0x810c071100000000, 0x39c80ab500000000, - 0xaa53c3ca00000000, 0x1fff994a00000000, 0x8c64503500000000, - 0x2e70f3d900000000, 0xbdeb3aa600000000, 0x0847602600000000, - 0x9bdca95900000000, 0x2318a4fd00000000, 0xb0836d8200000000, - 0x052f370200000000, 0x96b4fe7d00000000, 0x2946caf900000000, - 0xbadd038600000000, 0x0f71590600000000, 0x9cea907900000000, - 0x242e9ddd00000000, 0xb7b554a200000000, 0x02190e2200000000, - 0x9182c75d00000000, 0x339664b100000000, 0xa00dadce00000000, - 0x15a1f74e00000000, 0x863a3e3100000000, 0x3efe339500000000, - 0xad65faea00000000, 0x18c9a06a00000000, 0x8b52691500000000, - 0x1de6976800000000, 0x8e7d5e1700000000, 0x3bd1049700000000, - 0xa84acde800000000, 0x108ec04c00000000, 0x8315093300000000, - 0x36b953b300000000, 0xa5229acc00000000, 0x0736392000000000, - 0x94adf05f00000000, 0x2101aadf00000000, 0xb29a63a000000000, - 0x0a5e6e0400000000, 0x99c5a77b00000000, 0x2c69fdfb00000000, - 0xbff2348400000000, 0x138ae52800000000, 0x80112c5700000000, - 0x35bd76d700000000, 0xa626bfa800000000, 0x1ee2b20c00000000, - 0x8d797b7300000000, 0x38d521f300000000, 0xab4ee88c00000000, - 0x095a4b6000000000, 0x9ac1821f00000000, 0x2f6dd89f00000000, - 0xbcf611e000000000, 0x04321c4400000000, 0x97a9d53b00000000, - 0x22058fbb00000000, 0xb19e46c400000000, 0x272ab8b900000000, - 0xb4b171c600000000, 0x011d2b4600000000, 0x9286e23900000000, - 0x2a42ef9d00000000, 0xb9d926e200000000, 0x0c757c6200000000, - 0x9feeb51d00000000, 0x3dfa16f100000000, 0xae61df8e00000000, - 0x1bcd850e00000000, 0x88564c7100000000, 0x309241d500000000, - 0xa30988aa00000000, 0x16a5d22a00000000, 0x853e1b5500000000, - 0x3acc2fd100000000, 0xa957e6ae00000000, 0x1cfbbc2e00000000, - 0x8f60755100000000, 0x37a478f500000000, 0xa43fb18a00000000, - 0x1193eb0a00000000, 0x8208227500000000, 0x201c819900000000, - 0xb38748e600000000, 0x062b126600000000, 0x95b0db1900000000, - 0x2d74d6bd00000000, 0xbeef1fc200000000, 0x0b43454200000000, - 0x98d88c3d00000000, 0x0e6c724000000000, 0x9df7bb3f00000000, - 0x285be1bf00000000, 0xbbc028c000000000, 0x0304256400000000, - 0x909fec1b00000000, 0x2533b69b00000000, 0xb6a87fe400000000, - 0x14bcdc0800000000, 0x8727157700000000, 0x328b4ff700000000, - 0xa110868800000000, 0x19d48b2c00000000, 0x8a4f425300000000, - 0x3fe318d300000000, 0xac78d1ac00000000, 0x2614cb5100000000, - 0xb58f022e00000000, 0x002358ae00000000, 0x93b891d100000000, - 0x2b7c9c7500000000, 0xb8e7550a00000000, 0x0d4b0f8a00000000, - 0x9ed0c6f500000000, 0x3cc4651900000000, 0xaf5fac6600000000, - 0x1af3f6e600000000, 0x89683f9900000000, 0x31ac323d00000000, - 0xa237fb4200000000, 0x179ba1c200000000, 0x840068bd00000000, - 0x12b496c000000000, 0x812f5fbf00000000, 0x3483053f00000000, - 0xa718cc4000000000, 0x1fdcc1e400000000, 0x8c47089b00000000, - 0x39eb521b00000000, 0xaa709b6400000000, 0x0864388800000000, - 0x9bfff1f700000000, 0x2e53ab7700000000, 0xbdc8620800000000, - 0x050c6fac00000000, 0x9697a6d300000000, 0x233bfc5300000000, - 0xb0a0352c00000000, 0x0f5201a800000000, 0x9cc9c8d700000000, - 0x2965925700000000, 0xbafe5b2800000000, 0x023a568c00000000, - 0x91a19ff300000000, 0x240dc57300000000, 0xb7960c0c00000000, - 0x1582afe000000000, 0x8619669f00000000, 0x33b53c1f00000000, - 0xa02ef56000000000, 0x18eaf8c400000000, 0x8b7131bb00000000, - 0x3edd6b3b00000000, 0xad46a24400000000, 0x3bf25c3900000000, - 0xa869954600000000, 0x1dc5cfc600000000, 0x8e5e06b900000000, - 0x369a0b1d00000000, 0xa501c26200000000, 0x10ad98e200000000, - 0x8336519d00000000, 0x2122f27100000000, 0xb2b93b0e00000000, - 0x0715618e00000000, 0x948ea8f100000000, 0x2c4aa55500000000, - 0xbfd16c2a00000000, 0x0a7d36aa00000000, 0x99e6ffd500000000, - 0x359e2e7900000000, 0xa605e70600000000, 0x13a9bd8600000000, - 0x803274f900000000, 0x38f6795d00000000, 0xab6db02200000000, - 0x1ec1eaa200000000, 0x8d5a23dd00000000, 0x2f4e803100000000, - 0xbcd5494e00000000, 0x097913ce00000000, 0x9ae2dab100000000, - 0x2226d71500000000, 0xb1bd1e6a00000000, 0x041144ea00000000, - 0x978a8d9500000000, 0x013e73e800000000, 0x92a5ba9700000000, - 0x2709e01700000000, 0xb492296800000000, 0x0c5624cc00000000, - 0x9fcdedb300000000, 0x2a61b73300000000, 0xb9fa7e4c00000000, - 0x1beedda000000000, 0x887514df00000000, 0x3dd94e5f00000000, - 0xae42872000000000, 0x16868a8400000000, 0x851d43fb00000000, - 0x30b1197b00000000, 0xa32ad00400000000, 0x1cd8e48000000000, - 0x8f432dff00000000, 0x3aef777f00000000, 0xa974be0000000000, - 0x11b0b3a400000000, 0x822b7adb00000000, 0x3787205b00000000, - 0xa41ce92400000000, 0x06084ac800000000, 0x959383b700000000, - 0x203fd93700000000, 0xb3a4104800000000, 0x0b601dec00000000, - 0x98fbd49300000000, 0x2d578e1300000000, 0xbecc476c00000000, - 0x2878b91100000000, 0xbbe3706e00000000, 0x0e4f2aee00000000, - 0x9dd4e39100000000, 0x2510ee3500000000, 0xb68b274a00000000, - 0x03277dca00000000, 0x90bcb4b500000000, 0x32a8175900000000, - 0xa133de2600000000, 0x149f84a600000000, 0x87044dd900000000, - 0x3fc0407d00000000, 0xac5b890200000000, 0x19f7d38200000000, - 0x8a6c1afd00000000}, - {0x0000000000000000, 0x650b796900000000, 0xca16f2d200000000, - 0xaf1d8bbb00000000, 0xd52b957e00000000, 0xb020ec1700000000, - 0x1f3d67ac00000000, 0x7a361ec500000000, 0xaa572afd00000000, - 0xcf5c539400000000, 0x6041d82f00000000, 0x054aa14600000000, - 0x7f7cbf8300000000, 0x1a77c6ea00000000, 0xb56a4d5100000000, - 0xd061343800000000, 0x15a9252100000000, 0x70a25c4800000000, - 0xdfbfd7f300000000, 0xbab4ae9a00000000, 0xc082b05f00000000, - 0xa589c93600000000, 0x0a94428d00000000, 0x6f9f3be400000000, - 0xbffe0fdc00000000, 0xdaf576b500000000, 0x75e8fd0e00000000, - 0x10e3846700000000, 0x6ad59aa200000000, 0x0fdee3cb00000000, - 0xa0c3687000000000, 0xc5c8111900000000, 0x2a524b4200000000, - 0x4f59322b00000000, 0xe044b99000000000, 0x854fc0f900000000, - 0xff79de3c00000000, 0x9a72a75500000000, 0x356f2cee00000000, - 0x5064558700000000, 0x800561bf00000000, 0xe50e18d600000000, - 0x4a13936d00000000, 0x2f18ea0400000000, 0x552ef4c100000000, - 0x30258da800000000, 0x9f38061300000000, 0xfa337f7a00000000, - 0x3ffb6e6300000000, 0x5af0170a00000000, 0xf5ed9cb100000000, - 0x90e6e5d800000000, 0xead0fb1d00000000, 0x8fdb827400000000, - 0x20c609cf00000000, 0x45cd70a600000000, 0x95ac449e00000000, - 0xf0a73df700000000, 0x5fbab64c00000000, 0x3ab1cf2500000000, - 0x4087d1e000000000, 0x258ca88900000000, 0x8a91233200000000, - 0xef9a5a5b00000000, 0x54a4968400000000, 0x31afefed00000000, - 0x9eb2645600000000, 0xfbb91d3f00000000, 0x818f03fa00000000, - 0xe4847a9300000000, 0x4b99f12800000000, 0x2e92884100000000, - 0xfef3bc7900000000, 0x9bf8c51000000000, 0x34e54eab00000000, - 0x51ee37c200000000, 0x2bd8290700000000, 0x4ed3506e00000000, - 0xe1cedbd500000000, 0x84c5a2bc00000000, 0x410db3a500000000, - 0x2406cacc00000000, 0x8b1b417700000000, 0xee10381e00000000, - 0x942626db00000000, 0xf12d5fb200000000, 0x5e30d40900000000, - 0x3b3bad6000000000, 0xeb5a995800000000, 0x8e51e03100000000, - 0x214c6b8a00000000, 0x444712e300000000, 0x3e710c2600000000, - 0x5b7a754f00000000, 0xf467fef400000000, 0x916c879d00000000, - 0x7ef6ddc600000000, 0x1bfda4af00000000, 0xb4e02f1400000000, - 0xd1eb567d00000000, 0xabdd48b800000000, 0xced631d100000000, - 0x61cbba6a00000000, 0x04c0c30300000000, 0xd4a1f73b00000000, - 0xb1aa8e5200000000, 0x1eb705e900000000, 0x7bbc7c8000000000, - 0x018a624500000000, 0x64811b2c00000000, 0xcb9c909700000000, - 0xae97e9fe00000000, 0x6b5ff8e700000000, 0x0e54818e00000000, - 0xa1490a3500000000, 0xc442735c00000000, 0xbe746d9900000000, - 0xdb7f14f000000000, 0x74629f4b00000000, 0x1169e62200000000, - 0xc108d21a00000000, 0xa403ab7300000000, 0x0b1e20c800000000, - 0x6e1559a100000000, 0x1423476400000000, 0x71283e0d00000000, - 0xde35b5b600000000, 0xbb3eccdf00000000, 0xe94e5cd200000000, - 0x8c4525bb00000000, 0x2358ae0000000000, 0x4653d76900000000, - 0x3c65c9ac00000000, 0x596eb0c500000000, 0xf6733b7e00000000, - 0x9378421700000000, 0x4319762f00000000, 0x26120f4600000000, - 0x890f84fd00000000, 0xec04fd9400000000, 0x9632e35100000000, - 0xf3399a3800000000, 0x5c24118300000000, 0x392f68ea00000000, - 0xfce779f300000000, 0x99ec009a00000000, 0x36f18b2100000000, - 0x53faf24800000000, 0x29ccec8d00000000, 0x4cc795e400000000, - 0xe3da1e5f00000000, 0x86d1673600000000, 0x56b0530e00000000, - 0x33bb2a6700000000, 0x9ca6a1dc00000000, 0xf9add8b500000000, - 0x839bc67000000000, 0xe690bf1900000000, 0x498d34a200000000, - 0x2c864dcb00000000, 0xc31c179000000000, 0xa6176ef900000000, - 0x090ae54200000000, 0x6c019c2b00000000, 0x163782ee00000000, - 0x733cfb8700000000, 0xdc21703c00000000, 0xb92a095500000000, - 0x694b3d6d00000000, 0x0c40440400000000, 0xa35dcfbf00000000, - 0xc656b6d600000000, 0xbc60a81300000000, 0xd96bd17a00000000, - 0x76765ac100000000, 0x137d23a800000000, 0xd6b532b100000000, - 0xb3be4bd800000000, 0x1ca3c06300000000, 0x79a8b90a00000000, - 0x039ea7cf00000000, 0x6695dea600000000, 0xc988551d00000000, - 0xac832c7400000000, 0x7ce2184c00000000, 0x19e9612500000000, - 0xb6f4ea9e00000000, 0xd3ff93f700000000, 0xa9c98d3200000000, - 0xccc2f45b00000000, 0x63df7fe000000000, 0x06d4068900000000, - 0xbdeaca5600000000, 0xd8e1b33f00000000, 0x77fc388400000000, - 0x12f741ed00000000, 0x68c15f2800000000, 0x0dca264100000000, - 0xa2d7adfa00000000, 0xc7dcd49300000000, 0x17bde0ab00000000, - 0x72b699c200000000, 0xddab127900000000, 0xb8a06b1000000000, - 0xc29675d500000000, 0xa79d0cbc00000000, 0x0880870700000000, - 0x6d8bfe6e00000000, 0xa843ef7700000000, 0xcd48961e00000000, - 0x62551da500000000, 0x075e64cc00000000, 0x7d687a0900000000, - 0x1863036000000000, 0xb77e88db00000000, 0xd275f1b200000000, - 0x0214c58a00000000, 0x671fbce300000000, 0xc802375800000000, - 0xad094e3100000000, 0xd73f50f400000000, 0xb234299d00000000, - 0x1d29a22600000000, 0x7822db4f00000000, 0x97b8811400000000, - 0xf2b3f87d00000000, 0x5dae73c600000000, 0x38a50aaf00000000, - 0x4293146a00000000, 0x27986d0300000000, 0x8885e6b800000000, - 0xed8e9fd100000000, 0x3defabe900000000, 0x58e4d28000000000, - 0xf7f9593b00000000, 0x92f2205200000000, 0xe8c43e9700000000, - 0x8dcf47fe00000000, 0x22d2cc4500000000, 0x47d9b52c00000000, - 0x8211a43500000000, 0xe71add5c00000000, 0x480756e700000000, - 0x2d0c2f8e00000000, 0x573a314b00000000, 0x3231482200000000, - 0x9d2cc39900000000, 0xf827baf000000000, 0x28468ec800000000, - 0x4d4df7a100000000, 0xe2507c1a00000000, 0x875b057300000000, - 0xfd6d1bb600000000, 0x986662df00000000, 0x377be96400000000, - 0x5270900d00000000}, - {0x0000000000000000, 0xdcecb13d00000000, 0xb8d9637b00000000, - 0x6435d24600000000, 0x70b3c7f600000000, 0xac5f76cb00000000, - 0xc86aa48d00000000, 0x148615b000000000, 0xa160fe3600000000, - 0x7d8c4f0b00000000, 0x19b99d4d00000000, 0xc5552c7000000000, - 0xd1d339c000000000, 0x0d3f88fd00000000, 0x690a5abb00000000, - 0xb5e6eb8600000000, 0x42c1fc6d00000000, 0x9e2d4d5000000000, - 0xfa189f1600000000, 0x26f42e2b00000000, 0x32723b9b00000000, - 0xee9e8aa600000000, 0x8aab58e000000000, 0x5647e9dd00000000, - 0xe3a1025b00000000, 0x3f4db36600000000, 0x5b78612000000000, - 0x8794d01d00000000, 0x9312c5ad00000000, 0x4ffe749000000000, - 0x2bcba6d600000000, 0xf72717eb00000000, 0x8482f9db00000000, - 0x586e48e600000000, 0x3c5b9aa000000000, 0xe0b72b9d00000000, - 0xf4313e2d00000000, 0x28dd8f1000000000, 0x4ce85d5600000000, - 0x9004ec6b00000000, 0x25e207ed00000000, 0xf90eb6d000000000, - 0x9d3b649600000000, 0x41d7d5ab00000000, 0x5551c01b00000000, - 0x89bd712600000000, 0xed88a36000000000, 0x3164125d00000000, - 0xc64305b600000000, 0x1aafb48b00000000, 0x7e9a66cd00000000, - 0xa276d7f000000000, 0xb6f0c24000000000, 0x6a1c737d00000000, - 0x0e29a13b00000000, 0xd2c5100600000000, 0x6723fb8000000000, - 0xbbcf4abd00000000, 0xdffa98fb00000000, 0x031629c600000000, - 0x17903c7600000000, 0xcb7c8d4b00000000, 0xaf495f0d00000000, - 0x73a5ee3000000000, 0x4903826c00000000, 0x95ef335100000000, - 0xf1dae11700000000, 0x2d36502a00000000, 0x39b0459a00000000, - 0xe55cf4a700000000, 0x816926e100000000, 0x5d8597dc00000000, - 0xe8637c5a00000000, 0x348fcd6700000000, 0x50ba1f2100000000, - 0x8c56ae1c00000000, 0x98d0bbac00000000, 0x443c0a9100000000, - 0x2009d8d700000000, 0xfce569ea00000000, 0x0bc27e0100000000, - 0xd72ecf3c00000000, 0xb31b1d7a00000000, 0x6ff7ac4700000000, - 0x7b71b9f700000000, 0xa79d08ca00000000, 0xc3a8da8c00000000, - 0x1f446bb100000000, 0xaaa2803700000000, 0x764e310a00000000, - 0x127be34c00000000, 0xce97527100000000, 0xda1147c100000000, - 0x06fdf6fc00000000, 0x62c824ba00000000, 0xbe24958700000000, - 0xcd817bb700000000, 0x116dca8a00000000, 0x755818cc00000000, - 0xa9b4a9f100000000, 0xbd32bc4100000000, 0x61de0d7c00000000, - 0x05ebdf3a00000000, 0xd9076e0700000000, 0x6ce1858100000000, - 0xb00d34bc00000000, 0xd438e6fa00000000, 0x08d457c700000000, - 0x1c52427700000000, 0xc0bef34a00000000, 0xa48b210c00000000, - 0x7867903100000000, 0x8f4087da00000000, 0x53ac36e700000000, - 0x3799e4a100000000, 0xeb75559c00000000, 0xfff3402c00000000, - 0x231ff11100000000, 0x472a235700000000, 0x9bc6926a00000000, - 0x2e2079ec00000000, 0xf2ccc8d100000000, 0x96f91a9700000000, - 0x4a15abaa00000000, 0x5e93be1a00000000, 0x827f0f2700000000, - 0xe64add6100000000, 0x3aa66c5c00000000, 0x920604d900000000, - 0x4eeab5e400000000, 0x2adf67a200000000, 0xf633d69f00000000, - 0xe2b5c32f00000000, 0x3e59721200000000, 0x5a6ca05400000000, - 0x8680116900000000, 0x3366faef00000000, 0xef8a4bd200000000, - 0x8bbf999400000000, 0x575328a900000000, 0x43d53d1900000000, - 0x9f398c2400000000, 0xfb0c5e6200000000, 0x27e0ef5f00000000, - 0xd0c7f8b400000000, 0x0c2b498900000000, 0x681e9bcf00000000, - 0xb4f22af200000000, 0xa0743f4200000000, 0x7c988e7f00000000, - 0x18ad5c3900000000, 0xc441ed0400000000, 0x71a7068200000000, - 0xad4bb7bf00000000, 0xc97e65f900000000, 0x1592d4c400000000, - 0x0114c17400000000, 0xddf8704900000000, 0xb9cda20f00000000, - 0x6521133200000000, 0x1684fd0200000000, 0xca684c3f00000000, - 0xae5d9e7900000000, 0x72b12f4400000000, 0x66373af400000000, - 0xbadb8bc900000000, 0xdeee598f00000000, 0x0202e8b200000000, - 0xb7e4033400000000, 0x6b08b20900000000, 0x0f3d604f00000000, - 0xd3d1d17200000000, 0xc757c4c200000000, 0x1bbb75ff00000000, - 0x7f8ea7b900000000, 0xa362168400000000, 0x5445016f00000000, - 0x88a9b05200000000, 0xec9c621400000000, 0x3070d32900000000, - 0x24f6c69900000000, 0xf81a77a400000000, 0x9c2fa5e200000000, - 0x40c314df00000000, 0xf525ff5900000000, 0x29c94e6400000000, - 0x4dfc9c2200000000, 0x91102d1f00000000, 0x859638af00000000, - 0x597a899200000000, 0x3d4f5bd400000000, 0xe1a3eae900000000, - 0xdb0586b500000000, 0x07e9378800000000, 0x63dce5ce00000000, - 0xbf3054f300000000, 0xabb6414300000000, 0x775af07e00000000, - 0x136f223800000000, 0xcf83930500000000, 0x7a65788300000000, - 0xa689c9be00000000, 0xc2bc1bf800000000, 0x1e50aac500000000, - 0x0ad6bf7500000000, 0xd63a0e4800000000, 0xb20fdc0e00000000, - 0x6ee36d3300000000, 0x99c47ad800000000, 0x4528cbe500000000, - 0x211d19a300000000, 0xfdf1a89e00000000, 0xe977bd2e00000000, - 0x359b0c1300000000, 0x51aede5500000000, 0x8d426f6800000000, - 0x38a484ee00000000, 0xe44835d300000000, 0x807de79500000000, - 0x5c9156a800000000, 0x4817431800000000, 0x94fbf22500000000, - 0xf0ce206300000000, 0x2c22915e00000000, 0x5f877f6e00000000, - 0x836bce5300000000, 0xe75e1c1500000000, 0x3bb2ad2800000000, - 0x2f34b89800000000, 0xf3d809a500000000, 0x97eddbe300000000, - 0x4b016ade00000000, 0xfee7815800000000, 0x220b306500000000, - 0x463ee22300000000, 0x9ad2531e00000000, 0x8e5446ae00000000, - 0x52b8f79300000000, 0x368d25d500000000, 0xea6194e800000000, - 0x1d46830300000000, 0xc1aa323e00000000, 0xa59fe07800000000, - 0x7973514500000000, 0x6df544f500000000, 0xb119f5c800000000, - 0xd52c278e00000000, 0x09c096b300000000, 0xbc267d3500000000, - 0x60cacc0800000000, 0x04ff1e4e00000000, 0xd813af7300000000, - 0xcc95bac300000000, 0x10790bfe00000000, 0x744cd9b800000000, - 0xa8a0688500000000}}; - -#else /* W == 4 */ - -local const z_crc_t FAR crc_braid_table[][256] = { - {0x00000000, 0x81256527, 0xd93bcc0f, 0x581ea928, 0x69069e5f, - 0xe823fb78, 0xb03d5250, 0x31183777, 0xd20d3cbe, 0x53285999, - 0x0b36f0b1, 0x8a139596, 0xbb0ba2e1, 0x3a2ec7c6, 0x62306eee, - 0xe3150bc9, 0x7f6b7f3d, 0xfe4e1a1a, 0xa650b332, 0x2775d615, - 0x166de162, 0x97488445, 0xcf562d6d, 0x4e73484a, 0xad664383, - 0x2c4326a4, 0x745d8f8c, 0xf578eaab, 0xc460dddc, 0x4545b8fb, - 0x1d5b11d3, 0x9c7e74f4, 0xfed6fe7a, 0x7ff39b5d, 0x27ed3275, - 0xa6c85752, 0x97d06025, 0x16f50502, 0x4eebac2a, 0xcfcec90d, - 0x2cdbc2c4, 0xadfea7e3, 0xf5e00ecb, 0x74c56bec, 0x45dd5c9b, - 0xc4f839bc, 0x9ce69094, 0x1dc3f5b3, 0x81bd8147, 0x0098e460, - 0x58864d48, 0xd9a3286f, 0xe8bb1f18, 0x699e7a3f, 0x3180d317, - 0xb0a5b630, 0x53b0bdf9, 0xd295d8de, 0x8a8b71f6, 0x0bae14d1, - 0x3ab623a6, 0xbb934681, 0xe38defa9, 0x62a88a8e, 0x26dcfab5, - 0xa7f99f92, 0xffe736ba, 0x7ec2539d, 0x4fda64ea, 0xceff01cd, - 0x96e1a8e5, 0x17c4cdc2, 0xf4d1c60b, 0x75f4a32c, 0x2dea0a04, - 0xaccf6f23, 0x9dd75854, 0x1cf23d73, 0x44ec945b, 0xc5c9f17c, - 0x59b78588, 0xd892e0af, 0x808c4987, 0x01a92ca0, 0x30b11bd7, - 0xb1947ef0, 0xe98ad7d8, 0x68afb2ff, 0x8bbab936, 0x0a9fdc11, - 0x52817539, 0xd3a4101e, 0xe2bc2769, 0x6399424e, 0x3b87eb66, - 0xbaa28e41, 0xd80a04cf, 0x592f61e8, 0x0131c8c0, 0x8014ade7, - 0xb10c9a90, 0x3029ffb7, 0x6837569f, 0xe91233b8, 0x0a073871, - 0x8b225d56, 0xd33cf47e, 0x52199159, 0x6301a62e, 0xe224c309, - 0xba3a6a21, 0x3b1f0f06, 0xa7617bf2, 0x26441ed5, 0x7e5ab7fd, - 0xff7fd2da, 0xce67e5ad, 0x4f42808a, 0x175c29a2, 0x96794c85, - 0x756c474c, 0xf449226b, 0xac578b43, 0x2d72ee64, 0x1c6ad913, - 0x9d4fbc34, 0xc551151c, 0x4474703b, 0x4db9f56a, 0xcc9c904d, - 0x94823965, 0x15a75c42, 0x24bf6b35, 0xa59a0e12, 0xfd84a73a, - 0x7ca1c21d, 0x9fb4c9d4, 0x1e91acf3, 0x468f05db, 0xc7aa60fc, - 0xf6b2578b, 0x779732ac, 0x2f899b84, 0xaeacfea3, 0x32d28a57, - 0xb3f7ef70, 0xebe94658, 0x6acc237f, 0x5bd41408, 0xdaf1712f, - 0x82efd807, 0x03cabd20, 0xe0dfb6e9, 0x61fad3ce, 0x39e47ae6, - 0xb8c11fc1, 0x89d928b6, 0x08fc4d91, 0x50e2e4b9, 0xd1c7819e, - 0xb36f0b10, 0x324a6e37, 0x6a54c71f, 0xeb71a238, 0xda69954f, - 0x5b4cf068, 0x03525940, 0x82773c67, 0x616237ae, 0xe0475289, - 0xb859fba1, 0x397c9e86, 0x0864a9f1, 0x8941ccd6, 0xd15f65fe, - 0x507a00d9, 0xcc04742d, 0x4d21110a, 0x153fb822, 0x941add05, - 0xa502ea72, 0x24278f55, 0x7c39267d, 0xfd1c435a, 0x1e094893, - 0x9f2c2db4, 0xc732849c, 0x4617e1bb, 0x770fd6cc, 0xf62ab3eb, - 0xae341ac3, 0x2f117fe4, 0x6b650fdf, 0xea406af8, 0xb25ec3d0, - 0x337ba6f7, 0x02639180, 0x8346f4a7, 0xdb585d8f, 0x5a7d38a8, - 0xb9683361, 0x384d5646, 0x6053ff6e, 0xe1769a49, 0xd06ead3e, - 0x514bc819, 0x09556131, 0x88700416, 0x140e70e2, 0x952b15c5, - 0xcd35bced, 0x4c10d9ca, 0x7d08eebd, 0xfc2d8b9a, 0xa43322b2, - 0x25164795, 0xc6034c5c, 0x4726297b, 0x1f388053, 0x9e1de574, - 0xaf05d203, 0x2e20b724, 0x763e1e0c, 0xf71b7b2b, 0x95b3f1a5, - 0x14969482, 0x4c883daa, 0xcdad588d, 0xfcb56ffa, 0x7d900add, - 0x258ea3f5, 0xa4abc6d2, 0x47becd1b, 0xc69ba83c, 0x9e850114, - 0x1fa06433, 0x2eb85344, 0xaf9d3663, 0xf7839f4b, 0x76a6fa6c, - 0xead88e98, 0x6bfdebbf, 0x33e34297, 0xb2c627b0, 0x83de10c7, - 0x02fb75e0, 0x5ae5dcc8, 0xdbc0b9ef, 0x38d5b226, 0xb9f0d701, - 0xe1ee7e29, 0x60cb1b0e, 0x51d32c79, 0xd0f6495e, 0x88e8e076, - 0x09cd8551}, - {0x00000000, 0x9b73ead4, 0xed96d3e9, 0x76e5393d, 0x005ca193, - 0x9b2f4b47, 0xedca727a, 0x76b998ae, 0x00b94326, 0x9bcaa9f2, - 0xed2f90cf, 0x765c7a1b, 0x00e5e2b5, 0x9b960861, 0xed73315c, - 0x7600db88, 0x0172864c, 0x9a016c98, 0xece455a5, 0x7797bf71, - 0x012e27df, 0x9a5dcd0b, 0xecb8f436, 0x77cb1ee2, 0x01cbc56a, - 0x9ab82fbe, 0xec5d1683, 0x772efc57, 0x019764f9, 0x9ae48e2d, - 0xec01b710, 0x77725dc4, 0x02e50c98, 0x9996e64c, 0xef73df71, - 0x740035a5, 0x02b9ad0b, 0x99ca47df, 0xef2f7ee2, 0x745c9436, - 0x025c4fbe, 0x992fa56a, 0xefca9c57, 0x74b97683, 0x0200ee2d, - 0x997304f9, 0xef963dc4, 0x74e5d710, 0x03978ad4, 0x98e46000, - 0xee01593d, 0x7572b3e9, 0x03cb2b47, 0x98b8c193, 0xee5df8ae, - 0x752e127a, 0x032ec9f2, 0x985d2326, 0xeeb81a1b, 0x75cbf0cf, - 0x03726861, 0x980182b5, 0xeee4bb88, 0x7597515c, 0x05ca1930, - 0x9eb9f3e4, 0xe85ccad9, 0x732f200d, 0x0596b8a3, 0x9ee55277, - 0xe8006b4a, 0x7373819e, 0x05735a16, 0x9e00b0c2, 0xe8e589ff, - 0x7396632b, 0x052ffb85, 0x9e5c1151, 0xe8b9286c, 0x73cac2b8, - 0x04b89f7c, 0x9fcb75a8, 0xe92e4c95, 0x725da641, 0x04e43eef, - 0x9f97d43b, 0xe972ed06, 0x720107d2, 0x0401dc5a, 0x9f72368e, - 0xe9970fb3, 0x72e4e567, 0x045d7dc9, 0x9f2e971d, 0xe9cbae20, - 0x72b844f4, 0x072f15a8, 0x9c5cff7c, 0xeab9c641, 0x71ca2c95, - 0x0773b43b, 0x9c005eef, 0xeae567d2, 0x71968d06, 0x0796568e, - 0x9ce5bc5a, 0xea008567, 0x71736fb3, 0x07caf71d, 0x9cb91dc9, - 0xea5c24f4, 0x712fce20, 0x065d93e4, 0x9d2e7930, 0xebcb400d, - 0x70b8aad9, 0x06013277, 0x9d72d8a3, 0xeb97e19e, 0x70e40b4a, - 0x06e4d0c2, 0x9d973a16, 0xeb72032b, 0x7001e9ff, 0x06b87151, - 0x9dcb9b85, 0xeb2ea2b8, 0x705d486c, 0x0b943260, 0x90e7d8b4, - 0xe602e189, 0x7d710b5d, 0x0bc893f3, 0x90bb7927, 0xe65e401a, - 0x7d2daace, 0x0b2d7146, 0x905e9b92, 0xe6bba2af, 0x7dc8487b, - 0x0b71d0d5, 0x90023a01, 0xe6e7033c, 0x7d94e9e8, 0x0ae6b42c, - 0x91955ef8, 0xe77067c5, 0x7c038d11, 0x0aba15bf, 0x91c9ff6b, - 0xe72cc656, 0x7c5f2c82, 0x0a5ff70a, 0x912c1dde, 0xe7c924e3, - 0x7cbace37, 0x0a035699, 0x9170bc4d, 0xe7958570, 0x7ce66fa4, - 0x09713ef8, 0x9202d42c, 0xe4e7ed11, 0x7f9407c5, 0x092d9f6b, - 0x925e75bf, 0xe4bb4c82, 0x7fc8a656, 0x09c87dde, 0x92bb970a, - 0xe45eae37, 0x7f2d44e3, 0x0994dc4d, 0x92e73699, 0xe4020fa4, - 0x7f71e570, 0x0803b8b4, 0x93705260, 0xe5956b5d, 0x7ee68189, - 0x085f1927, 0x932cf3f3, 0xe5c9cace, 0x7eba201a, 0x08bafb92, - 0x93c91146, 0xe52c287b, 0x7e5fc2af, 0x08e65a01, 0x9395b0d5, - 0xe57089e8, 0x7e03633c, 0x0e5e2b50, 0x952dc184, 0xe3c8f8b9, - 0x78bb126d, 0x0e028ac3, 0x95716017, 0xe394592a, 0x78e7b3fe, - 0x0ee76876, 0x959482a2, 0xe371bb9f, 0x7802514b, 0x0ebbc9e5, - 0x95c82331, 0xe32d1a0c, 0x785ef0d8, 0x0f2cad1c, 0x945f47c8, - 0xe2ba7ef5, 0x79c99421, 0x0f700c8f, 0x9403e65b, 0xe2e6df66, - 0x799535b2, 0x0f95ee3a, 0x94e604ee, 0xe2033dd3, 0x7970d707, - 0x0fc94fa9, 0x94baa57d, 0xe25f9c40, 0x792c7694, 0x0cbb27c8, - 0x97c8cd1c, 0xe12df421, 0x7a5e1ef5, 0x0ce7865b, 0x97946c8f, - 0xe17155b2, 0x7a02bf66, 0x0c0264ee, 0x97718e3a, 0xe194b707, - 0x7ae75dd3, 0x0c5ec57d, 0x972d2fa9, 0xe1c81694, 0x7abbfc40, - 0x0dc9a184, 0x96ba4b50, 0xe05f726d, 0x7b2c98b9, 0x0d950017, - 0x96e6eac3, 0xe003d3fe, 0x7b70392a, 0x0d70e2a2, 0x96030876, - 0xe0e6314b, 0x7b95db9f, 0x0d2c4331, 0x965fa9e5, 0xe0ba90d8, - 0x7bc97a0c}, - {0x00000000, 0x172864c0, 0x2e50c980, 0x3978ad40, 0x5ca19300, - 0x4b89f7c0, 0x72f15a80, 0x65d93e40, 0xb9432600, 0xae6b42c0, - 0x9713ef80, 0x803b8b40, 0xe5e2b500, 0xf2cad1c0, 0xcbb27c80, - 0xdc9a1840, 0xa9f74a41, 0xbedf2e81, 0x87a783c1, 0x908fe701, - 0xf556d941, 0xe27ebd81, 0xdb0610c1, 0xcc2e7401, 0x10b46c41, - 0x079c0881, 0x3ee4a5c1, 0x29ccc101, 0x4c15ff41, 0x5b3d9b81, - 0x624536c1, 0x756d5201, 0x889f92c3, 0x9fb7f603, 0xa6cf5b43, - 0xb1e73f83, 0xd43e01c3, 0xc3166503, 0xfa6ec843, 0xed46ac83, - 0x31dcb4c3, 0x26f4d003, 0x1f8c7d43, 0x08a41983, 0x6d7d27c3, - 0x7a554303, 0x432dee43, 0x54058a83, 0x2168d882, 0x3640bc42, - 0x0f381102, 0x181075c2, 0x7dc94b82, 0x6ae12f42, 0x53998202, - 0x44b1e6c2, 0x982bfe82, 0x8f039a42, 0xb67b3702, 0xa15353c2, - 0xc48a6d82, 0xd3a20942, 0xeadaa402, 0xfdf2c0c2, 0xca4e23c7, - 0xdd664707, 0xe41eea47, 0xf3368e87, 0x96efb0c7, 0x81c7d407, - 0xb8bf7947, 0xaf971d87, 0x730d05c7, 0x64256107, 0x5d5dcc47, - 0x4a75a887, 0x2fac96c7, 0x3884f207, 0x01fc5f47, 0x16d43b87, - 0x63b96986, 0x74910d46, 0x4de9a006, 0x5ac1c4c6, 0x3f18fa86, - 0x28309e46, 0x11483306, 0x066057c6, 0xdafa4f86, 0xcdd22b46, - 0xf4aa8606, 0xe382e2c6, 0x865bdc86, 0x9173b846, 0xa80b1506, - 0xbf2371c6, 0x42d1b104, 0x55f9d5c4, 0x6c817884, 0x7ba91c44, - 0x1e702204, 0x095846c4, 0x3020eb84, 0x27088f44, 0xfb929704, - 0xecbaf3c4, 0xd5c25e84, 0xc2ea3a44, 0xa7330404, 0xb01b60c4, - 0x8963cd84, 0x9e4ba944, 0xeb26fb45, 0xfc0e9f85, 0xc57632c5, - 0xd25e5605, 0xb7876845, 0xa0af0c85, 0x99d7a1c5, 0x8effc505, - 0x5265dd45, 0x454db985, 0x7c3514c5, 0x6b1d7005, 0x0ec44e45, - 0x19ec2a85, 0x209487c5, 0x37bce305, 0x4fed41cf, 0x58c5250f, - 0x61bd884f, 0x7695ec8f, 0x134cd2cf, 0x0464b60f, 0x3d1c1b4f, - 0x2a347f8f, 0xf6ae67cf, 0xe186030f, 0xd8feae4f, 0xcfd6ca8f, - 0xaa0ff4cf, 0xbd27900f, 0x845f3d4f, 0x9377598f, 0xe61a0b8e, - 0xf1326f4e, 0xc84ac20e, 0xdf62a6ce, 0xbabb988e, 0xad93fc4e, - 0x94eb510e, 0x83c335ce, 0x5f592d8e, 0x4871494e, 0x7109e40e, - 0x662180ce, 0x03f8be8e, 0x14d0da4e, 0x2da8770e, 0x3a8013ce, - 0xc772d30c, 0xd05ab7cc, 0xe9221a8c, 0xfe0a7e4c, 0x9bd3400c, - 0x8cfb24cc, 0xb583898c, 0xa2abed4c, 0x7e31f50c, 0x691991cc, - 0x50613c8c, 0x4749584c, 0x2290660c, 0x35b802cc, 0x0cc0af8c, - 0x1be8cb4c, 0x6e85994d, 0x79adfd8d, 0x40d550cd, 0x57fd340d, - 0x32240a4d, 0x250c6e8d, 0x1c74c3cd, 0x0b5ca70d, 0xd7c6bf4d, - 0xc0eedb8d, 0xf99676cd, 0xeebe120d, 0x8b672c4d, 0x9c4f488d, - 0xa537e5cd, 0xb21f810d, 0x85a36208, 0x928b06c8, 0xabf3ab88, - 0xbcdbcf48, 0xd902f108, 0xce2a95c8, 0xf7523888, 0xe07a5c48, - 0x3ce04408, 0x2bc820c8, 0x12b08d88, 0x0598e948, 0x6041d708, - 0x7769b3c8, 0x4e111e88, 0x59397a48, 0x2c542849, 0x3b7c4c89, - 0x0204e1c9, 0x152c8509, 0x70f5bb49, 0x67dddf89, 0x5ea572c9, - 0x498d1609, 0x95170e49, 0x823f6a89, 0xbb47c7c9, 0xac6fa309, - 0xc9b69d49, 0xde9ef989, 0xe7e654c9, 0xf0ce3009, 0x0d3cf0cb, - 0x1a14940b, 0x236c394b, 0x34445d8b, 0x519d63cb, 0x46b5070b, - 0x7fcdaa4b, 0x68e5ce8b, 0xb47fd6cb, 0xa357b20b, 0x9a2f1f4b, - 0x8d077b8b, 0xe8de45cb, 0xfff6210b, 0xc68e8c4b, 0xd1a6e88b, - 0xa4cbba8a, 0xb3e3de4a, 0x8a9b730a, 0x9db317ca, 0xf86a298a, - 0xef424d4a, 0xd63ae00a, 0xc11284ca, 0x1d889c8a, 0x0aa0f84a, - 0x33d8550a, 0x24f031ca, 0x41290f8a, 0x56016b4a, 0x6f79c60a, - 0x7851a2ca}, - {0x00000000, 0x9fda839e, 0xe4c4017d, 0x7b1e82e3, 0x12f904bb, - 0x8d238725, 0xf63d05c6, 0x69e78658, 0x25f20976, 0xba288ae8, - 0xc136080b, 0x5eec8b95, 0x370b0dcd, 0xa8d18e53, 0xd3cf0cb0, - 0x4c158f2e, 0x4be412ec, 0xd43e9172, 0xaf201391, 0x30fa900f, - 0x591d1657, 0xc6c795c9, 0xbdd9172a, 0x220394b4, 0x6e161b9a, - 0xf1cc9804, 0x8ad21ae7, 0x15089979, 0x7cef1f21, 0xe3359cbf, - 0x982b1e5c, 0x07f19dc2, 0x97c825d8, 0x0812a646, 0x730c24a5, - 0xecd6a73b, 0x85312163, 0x1aeba2fd, 0x61f5201e, 0xfe2fa380, - 0xb23a2cae, 0x2de0af30, 0x56fe2dd3, 0xc924ae4d, 0xa0c32815, - 0x3f19ab8b, 0x44072968, 0xdbddaaf6, 0xdc2c3734, 0x43f6b4aa, - 0x38e83649, 0xa732b5d7, 0xced5338f, 0x510fb011, 0x2a1132f2, - 0xb5cbb16c, 0xf9de3e42, 0x6604bddc, 0x1d1a3f3f, 0x82c0bca1, - 0xeb273af9, 0x74fdb967, 0x0fe33b84, 0x9039b81a, 0xf4e14df1, - 0x6b3bce6f, 0x10254c8c, 0x8fffcf12, 0xe618494a, 0x79c2cad4, - 0x02dc4837, 0x9d06cba9, 0xd1134487, 0x4ec9c719, 0x35d745fa, - 0xaa0dc664, 0xc3ea403c, 0x5c30c3a2, 0x272e4141, 0xb8f4c2df, - 0xbf055f1d, 0x20dfdc83, 0x5bc15e60, 0xc41bddfe, 0xadfc5ba6, - 0x3226d838, 0x49385adb, 0xd6e2d945, 0x9af7566b, 0x052dd5f5, - 0x7e335716, 0xe1e9d488, 0x880e52d0, 0x17d4d14e, 0x6cca53ad, - 0xf310d033, 0x63296829, 0xfcf3ebb7, 0x87ed6954, 0x1837eaca, - 0x71d06c92, 0xee0aef0c, 0x95146def, 0x0aceee71, 0x46db615f, - 0xd901e2c1, 0xa21f6022, 0x3dc5e3bc, 0x542265e4, 0xcbf8e67a, - 0xb0e66499, 0x2f3ce707, 0x28cd7ac5, 0xb717f95b, 0xcc097bb8, - 0x53d3f826, 0x3a347e7e, 0xa5eefde0, 0xdef07f03, 0x412afc9d, - 0x0d3f73b3, 0x92e5f02d, 0xe9fb72ce, 0x7621f150, 0x1fc67708, - 0x801cf496, 0xfb027675, 0x64d8f5eb, 0x32b39da3, 0xad691e3d, - 0xd6779cde, 0x49ad1f40, 0x204a9918, 0xbf901a86, 0xc48e9865, - 0x5b541bfb, 0x174194d5, 0x889b174b, 0xf38595a8, 0x6c5f1636, - 0x05b8906e, 0x9a6213f0, 0xe17c9113, 0x7ea6128d, 0x79578f4f, - 0xe68d0cd1, 0x9d938e32, 0x02490dac, 0x6bae8bf4, 0xf474086a, - 0x8f6a8a89, 0x10b00917, 0x5ca58639, 0xc37f05a7, 0xb8618744, - 0x27bb04da, 0x4e5c8282, 0xd186011c, 0xaa9883ff, 0x35420061, - 0xa57bb87b, 0x3aa13be5, 0x41bfb906, 0xde653a98, 0xb782bcc0, - 0x28583f5e, 0x5346bdbd, 0xcc9c3e23, 0x8089b10d, 0x1f533293, - 0x644db070, 0xfb9733ee, 0x9270b5b6, 0x0daa3628, 0x76b4b4cb, - 0xe96e3755, 0xee9faa97, 0x71452909, 0x0a5babea, 0x95812874, - 0xfc66ae2c, 0x63bc2db2, 0x18a2af51, 0x87782ccf, 0xcb6da3e1, - 0x54b7207f, 0x2fa9a29c, 0xb0732102, 0xd994a75a, 0x464e24c4, - 0x3d50a627, 0xa28a25b9, 0xc652d052, 0x598853cc, 0x2296d12f, - 0xbd4c52b1, 0xd4abd4e9, 0x4b715777, 0x306fd594, 0xafb5560a, - 0xe3a0d924, 0x7c7a5aba, 0x0764d859, 0x98be5bc7, 0xf159dd9f, - 0x6e835e01, 0x159ddce2, 0x8a475f7c, 0x8db6c2be, 0x126c4120, - 0x6972c3c3, 0xf6a8405d, 0x9f4fc605, 0x0095459b, 0x7b8bc778, - 0xe45144e6, 0xa844cbc8, 0x379e4856, 0x4c80cab5, 0xd35a492b, - 0xbabdcf73, 0x25674ced, 0x5e79ce0e, 0xc1a34d90, 0x519af58a, - 0xce407614, 0xb55ef4f7, 0x2a847769, 0x4363f131, 0xdcb972af, - 0xa7a7f04c, 0x387d73d2, 0x7468fcfc, 0xebb27f62, 0x90acfd81, - 0x0f767e1f, 0x6691f847, 0xf94b7bd9, 0x8255f93a, 0x1d8f7aa4, - 0x1a7ee766, 0x85a464f8, 0xfebae61b, 0x61606585, 0x0887e3dd, - 0x975d6043, 0xec43e2a0, 0x7399613e, 0x3f8cee10, 0xa0566d8e, - 0xdb48ef6d, 0x44926cf3, 0x2d75eaab, 0xb2af6935, 0xc9b1ebd6, - 0x566b6848}}; - -local const z_word_t FAR crc_braid_big_table[][256] = { - {0x00000000, 0x9e83da9f, 0x7d01c4e4, 0xe3821e7b, 0xbb04f912, - 0x2587238d, 0xc6053df6, 0x5886e769, 0x7609f225, 0xe88a28ba, - 0x0b0836c1, 0x958bec5e, 0xcd0d0b37, 0x538ed1a8, 0xb00ccfd3, - 0x2e8f154c, 0xec12e44b, 0x72913ed4, 0x911320af, 0x0f90fa30, - 0x57161d59, 0xc995c7c6, 0x2a17d9bd, 0xb4940322, 0x9a1b166e, - 0x0498ccf1, 0xe71ad28a, 0x79990815, 0x211fef7c, 0xbf9c35e3, - 0x5c1e2b98, 0xc29df107, 0xd825c897, 0x46a61208, 0xa5240c73, - 0x3ba7d6ec, 0x63213185, 0xfda2eb1a, 0x1e20f561, 0x80a32ffe, - 0xae2c3ab2, 0x30afe02d, 0xd32dfe56, 0x4dae24c9, 0x1528c3a0, - 0x8bab193f, 0x68290744, 0xf6aadddb, 0x34372cdc, 0xaab4f643, - 0x4936e838, 0xd7b532a7, 0x8f33d5ce, 0x11b00f51, 0xf232112a, - 0x6cb1cbb5, 0x423edef9, 0xdcbd0466, 0x3f3f1a1d, 0xa1bcc082, - 0xf93a27eb, 0x67b9fd74, 0x843be30f, 0x1ab83990, 0xf14de1f4, - 0x6fce3b6b, 0x8c4c2510, 0x12cfff8f, 0x4a4918e6, 0xd4cac279, - 0x3748dc02, 0xa9cb069d, 0x874413d1, 0x19c7c94e, 0xfa45d735, - 0x64c60daa, 0x3c40eac3, 0xa2c3305c, 0x41412e27, 0xdfc2f4b8, - 0x1d5f05bf, 0x83dcdf20, 0x605ec15b, 0xfedd1bc4, 0xa65bfcad, - 0x38d82632, 0xdb5a3849, 0x45d9e2d6, 0x6b56f79a, 0xf5d52d05, - 0x1657337e, 0x88d4e9e1, 0xd0520e88, 0x4ed1d417, 0xad53ca6c, - 0x33d010f3, 0x29682963, 0xb7ebf3fc, 0x5469ed87, 0xcaea3718, - 0x926cd071, 0x0cef0aee, 0xef6d1495, 0x71eece0a, 0x5f61db46, - 0xc1e201d9, 0x22601fa2, 0xbce3c53d, 0xe4652254, 0x7ae6f8cb, - 0x9964e6b0, 0x07e73c2f, 0xc57acd28, 0x5bf917b7, 0xb87b09cc, - 0x26f8d353, 0x7e7e343a, 0xe0fdeea5, 0x037ff0de, 0x9dfc2a41, - 0xb3733f0d, 0x2df0e592, 0xce72fbe9, 0x50f12176, 0x0877c61f, - 0x96f41c80, 0x757602fb, 0xebf5d864, 0xa39db332, 0x3d1e69ad, - 0xde9c77d6, 0x401fad49, 0x18994a20, 0x861a90bf, 0x65988ec4, - 0xfb1b545b, 0xd5944117, 0x4b179b88, 0xa89585f3, 0x36165f6c, - 0x6e90b805, 0xf013629a, 0x13917ce1, 0x8d12a67e, 0x4f8f5779, - 0xd10c8de6, 0x328e939d, 0xac0d4902, 0xf48bae6b, 0x6a0874f4, - 0x898a6a8f, 0x1709b010, 0x3986a55c, 0xa7057fc3, 0x448761b8, - 0xda04bb27, 0x82825c4e, 0x1c0186d1, 0xff8398aa, 0x61004235, - 0x7bb87ba5, 0xe53ba13a, 0x06b9bf41, 0x983a65de, 0xc0bc82b7, - 0x5e3f5828, 0xbdbd4653, 0x233e9ccc, 0x0db18980, 0x9332531f, - 0x70b04d64, 0xee3397fb, 0xb6b57092, 0x2836aa0d, 0xcbb4b476, - 0x55376ee9, 0x97aa9fee, 0x09294571, 0xeaab5b0a, 0x74288195, - 0x2cae66fc, 0xb22dbc63, 0x51afa218, 0xcf2c7887, 0xe1a36dcb, - 0x7f20b754, 0x9ca2a92f, 0x022173b0, 0x5aa794d9, 0xc4244e46, - 0x27a6503d, 0xb9258aa2, 0x52d052c6, 0xcc538859, 0x2fd19622, - 0xb1524cbd, 0xe9d4abd4, 0x7757714b, 0x94d56f30, 0x0a56b5af, - 0x24d9a0e3, 0xba5a7a7c, 0x59d86407, 0xc75bbe98, 0x9fdd59f1, - 0x015e836e, 0xe2dc9d15, 0x7c5f478a, 0xbec2b68d, 0x20416c12, - 0xc3c37269, 0x5d40a8f6, 0x05c64f9f, 0x9b459500, 0x78c78b7b, - 0xe64451e4, 0xc8cb44a8, 0x56489e37, 0xb5ca804c, 0x2b495ad3, - 0x73cfbdba, 0xed4c6725, 0x0ece795e, 0x904da3c1, 0x8af59a51, - 0x147640ce, 0xf7f45eb5, 0x6977842a, 0x31f16343, 0xaf72b9dc, - 0x4cf0a7a7, 0xd2737d38, 0xfcfc6874, 0x627fb2eb, 0x81fdac90, - 0x1f7e760f, 0x47f89166, 0xd97b4bf9, 0x3af95582, 0xa47a8f1d, - 0x66e77e1a, 0xf864a485, 0x1be6bafe, 0x85656061, 0xdde38708, - 0x43605d97, 0xa0e243ec, 0x3e619973, 0x10ee8c3f, 0x8e6d56a0, - 0x6def48db, 0xf36c9244, 0xabea752d, 0x3569afb2, 0xd6ebb1c9, - 0x48686b56}, - {0x00000000, 0xc0642817, 0x80c9502e, 0x40ad7839, 0x0093a15c, - 0xc0f7894b, 0x805af172, 0x403ed965, 0x002643b9, 0xc0426bae, - 0x80ef1397, 0x408b3b80, 0x00b5e2e5, 0xc0d1caf2, 0x807cb2cb, - 0x40189adc, 0x414af7a9, 0x812edfbe, 0xc183a787, 0x01e78f90, - 0x41d956f5, 0x81bd7ee2, 0xc11006db, 0x01742ecc, 0x416cb410, - 0x81089c07, 0xc1a5e43e, 0x01c1cc29, 0x41ff154c, 0x819b3d5b, - 0xc1364562, 0x01526d75, 0xc3929f88, 0x03f6b79f, 0x435bcfa6, - 0x833fe7b1, 0xc3013ed4, 0x036516c3, 0x43c86efa, 0x83ac46ed, - 0xc3b4dc31, 0x03d0f426, 0x437d8c1f, 0x8319a408, 0xc3277d6d, - 0x0343557a, 0x43ee2d43, 0x838a0554, 0x82d86821, 0x42bc4036, - 0x0211380f, 0xc2751018, 0x824bc97d, 0x422fe16a, 0x02829953, - 0xc2e6b144, 0x82fe2b98, 0x429a038f, 0x02377bb6, 0xc25353a1, - 0x826d8ac4, 0x4209a2d3, 0x02a4daea, 0xc2c0f2fd, 0xc7234eca, - 0x074766dd, 0x47ea1ee4, 0x878e36f3, 0xc7b0ef96, 0x07d4c781, - 0x4779bfb8, 0x871d97af, 0xc7050d73, 0x07612564, 0x47cc5d5d, - 0x87a8754a, 0xc796ac2f, 0x07f28438, 0x475ffc01, 0x873bd416, - 0x8669b963, 0x460d9174, 0x06a0e94d, 0xc6c4c15a, 0x86fa183f, - 0x469e3028, 0x06334811, 0xc6576006, 0x864ffada, 0x462bd2cd, - 0x0686aaf4, 0xc6e282e3, 0x86dc5b86, 0x46b87391, 0x06150ba8, - 0xc67123bf, 0x04b1d142, 0xc4d5f955, 0x8478816c, 0x441ca97b, - 0x0422701e, 0xc4465809, 0x84eb2030, 0x448f0827, 0x049792fb, - 0xc4f3baec, 0x845ec2d5, 0x443aeac2, 0x040433a7, 0xc4601bb0, - 0x84cd6389, 0x44a94b9e, 0x45fb26eb, 0x859f0efc, 0xc53276c5, - 0x05565ed2, 0x456887b7, 0x850cafa0, 0xc5a1d799, 0x05c5ff8e, - 0x45dd6552, 0x85b94d45, 0xc514357c, 0x05701d6b, 0x454ec40e, - 0x852aec19, 0xc5879420, 0x05e3bc37, 0xcf41ed4f, 0x0f25c558, - 0x4f88bd61, 0x8fec9576, 0xcfd24c13, 0x0fb66404, 0x4f1b1c3d, - 0x8f7f342a, 0xcf67aef6, 0x0f0386e1, 0x4faefed8, 0x8fcad6cf, - 0xcff40faa, 0x0f9027bd, 0x4f3d5f84, 0x8f597793, 0x8e0b1ae6, - 0x4e6f32f1, 0x0ec24ac8, 0xcea662df, 0x8e98bbba, 0x4efc93ad, - 0x0e51eb94, 0xce35c383, 0x8e2d595f, 0x4e497148, 0x0ee40971, - 0xce802166, 0x8ebef803, 0x4edad014, 0x0e77a82d, 0xce13803a, - 0x0cd372c7, 0xccb75ad0, 0x8c1a22e9, 0x4c7e0afe, 0x0c40d39b, - 0xcc24fb8c, 0x8c8983b5, 0x4cedaba2, 0x0cf5317e, 0xcc911969, - 0x8c3c6150, 0x4c584947, 0x0c669022, 0xcc02b835, 0x8cafc00c, - 0x4ccbe81b, 0x4d99856e, 0x8dfdad79, 0xcd50d540, 0x0d34fd57, - 0x4d0a2432, 0x8d6e0c25, 0xcdc3741c, 0x0da75c0b, 0x4dbfc6d7, - 0x8ddbeec0, 0xcd7696f9, 0x0d12beee, 0x4d2c678b, 0x8d484f9c, - 0xcde537a5, 0x0d811fb2, 0x0862a385, 0xc8068b92, 0x88abf3ab, - 0x48cfdbbc, 0x08f102d9, 0xc8952ace, 0x883852f7, 0x485c7ae0, - 0x0844e03c, 0xc820c82b, 0x888db012, 0x48e99805, 0x08d74160, - 0xc8b36977, 0x881e114e, 0x487a3959, 0x4928542c, 0x894c7c3b, - 0xc9e10402, 0x09852c15, 0x49bbf570, 0x89dfdd67, 0xc972a55e, - 0x09168d49, 0x490e1795, 0x896a3f82, 0xc9c747bb, 0x09a36fac, - 0x499db6c9, 0x89f99ede, 0xc954e6e7, 0x0930cef0, 0xcbf03c0d, - 0x0b94141a, 0x4b396c23, 0x8b5d4434, 0xcb639d51, 0x0b07b546, - 0x4baacd7f, 0x8bcee568, 0xcbd67fb4, 0x0bb257a3, 0x4b1f2f9a, - 0x8b7b078d, 0xcb45dee8, 0x0b21f6ff, 0x4b8c8ec6, 0x8be8a6d1, - 0x8abacba4, 0x4adee3b3, 0x0a739b8a, 0xca17b39d, 0x8a296af8, - 0x4a4d42ef, 0x0ae03ad6, 0xca8412c1, 0x8a9c881d, 0x4af8a00a, - 0x0a55d833, 0xca31f024, 0x8a0f2941, 0x4a6b0156, 0x0ac6796f, - 0xcaa25178}, - {0x00000000, 0xd4ea739b, 0xe9d396ed, 0x3d39e576, 0x93a15c00, - 0x474b2f9b, 0x7a72caed, 0xae98b976, 0x2643b900, 0xf2a9ca9b, - 0xcf902fed, 0x1b7a5c76, 0xb5e2e500, 0x6108969b, 0x5c3173ed, - 0x88db0076, 0x4c867201, 0x986c019a, 0xa555e4ec, 0x71bf9777, - 0xdf272e01, 0x0bcd5d9a, 0x36f4b8ec, 0xe21ecb77, 0x6ac5cb01, - 0xbe2fb89a, 0x83165dec, 0x57fc2e77, 0xf9649701, 0x2d8ee49a, - 0x10b701ec, 0xc45d7277, 0x980ce502, 0x4ce69699, 0x71df73ef, - 0xa5350074, 0x0badb902, 0xdf47ca99, 0xe27e2fef, 0x36945c74, - 0xbe4f5c02, 0x6aa52f99, 0x579ccaef, 0x8376b974, 0x2dee0002, - 0xf9047399, 0xc43d96ef, 0x10d7e574, 0xd48a9703, 0x0060e498, - 0x3d5901ee, 0xe9b37275, 0x472bcb03, 0x93c1b898, 0xaef85dee, - 0x7a122e75, 0xf2c92e03, 0x26235d98, 0x1b1ab8ee, 0xcff0cb75, - 0x61687203, 0xb5820198, 0x88bbe4ee, 0x5c519775, 0x3019ca05, - 0xe4f3b99e, 0xd9ca5ce8, 0x0d202f73, 0xa3b89605, 0x7752e59e, - 0x4a6b00e8, 0x9e817373, 0x165a7305, 0xc2b0009e, 0xff89e5e8, - 0x2b639673, 0x85fb2f05, 0x51115c9e, 0x6c28b9e8, 0xb8c2ca73, - 0x7c9fb804, 0xa875cb9f, 0x954c2ee9, 0x41a65d72, 0xef3ee404, - 0x3bd4979f, 0x06ed72e9, 0xd2070172, 0x5adc0104, 0x8e36729f, - 0xb30f97e9, 0x67e5e472, 0xc97d5d04, 0x1d972e9f, 0x20aecbe9, - 0xf444b872, 0xa8152f07, 0x7cff5c9c, 0x41c6b9ea, 0x952cca71, - 0x3bb47307, 0xef5e009c, 0xd267e5ea, 0x068d9671, 0x8e569607, - 0x5abce59c, 0x678500ea, 0xb36f7371, 0x1df7ca07, 0xc91db99c, - 0xf4245cea, 0x20ce2f71, 0xe4935d06, 0x30792e9d, 0x0d40cbeb, - 0xd9aab870, 0x77320106, 0xa3d8729d, 0x9ee197eb, 0x4a0be470, - 0xc2d0e406, 0x163a979d, 0x2b0372eb, 0xffe90170, 0x5171b806, - 0x859bcb9d, 0xb8a22eeb, 0x6c485d70, 0x6032940b, 0xb4d8e790, - 0x89e102e6, 0x5d0b717d, 0xf393c80b, 0x2779bb90, 0x1a405ee6, - 0xceaa2d7d, 0x46712d0b, 0x929b5e90, 0xafa2bbe6, 0x7b48c87d, - 0xd5d0710b, 0x013a0290, 0x3c03e7e6, 0xe8e9947d, 0x2cb4e60a, - 0xf85e9591, 0xc56770e7, 0x118d037c, 0xbf15ba0a, 0x6bffc991, - 0x56c62ce7, 0x822c5f7c, 0x0af75f0a, 0xde1d2c91, 0xe324c9e7, - 0x37ceba7c, 0x9956030a, 0x4dbc7091, 0x708595e7, 0xa46fe67c, - 0xf83e7109, 0x2cd40292, 0x11ede7e4, 0xc507947f, 0x6b9f2d09, - 0xbf755e92, 0x824cbbe4, 0x56a6c87f, 0xde7dc809, 0x0a97bb92, - 0x37ae5ee4, 0xe3442d7f, 0x4ddc9409, 0x9936e792, 0xa40f02e4, - 0x70e5717f, 0xb4b80308, 0x60527093, 0x5d6b95e5, 0x8981e67e, - 0x27195f08, 0xf3f32c93, 0xcecac9e5, 0x1a20ba7e, 0x92fbba08, - 0x4611c993, 0x7b282ce5, 0xafc25f7e, 0x015ae608, 0xd5b09593, - 0xe88970e5, 0x3c63037e, 0x502b5e0e, 0x84c12d95, 0xb9f8c8e3, - 0x6d12bb78, 0xc38a020e, 0x17607195, 0x2a5994e3, 0xfeb3e778, - 0x7668e70e, 0xa2829495, 0x9fbb71e3, 0x4b510278, 0xe5c9bb0e, - 0x3123c895, 0x0c1a2de3, 0xd8f05e78, 0x1cad2c0f, 0xc8475f94, - 0xf57ebae2, 0x2194c979, 0x8f0c700f, 0x5be60394, 0x66dfe6e2, - 0xb2359579, 0x3aee950f, 0xee04e694, 0xd33d03e2, 0x07d77079, - 0xa94fc90f, 0x7da5ba94, 0x409c5fe2, 0x94762c79, 0xc827bb0c, - 0x1ccdc897, 0x21f42de1, 0xf51e5e7a, 0x5b86e70c, 0x8f6c9497, - 0xb25571e1, 0x66bf027a, 0xee64020c, 0x3a8e7197, 0x07b794e1, - 0xd35de77a, 0x7dc55e0c, 0xa92f2d97, 0x9416c8e1, 0x40fcbb7a, - 0x84a1c90d, 0x504bba96, 0x6d725fe0, 0xb9982c7b, 0x1700950d, - 0xc3eae696, 0xfed303e0, 0x2a39707b, 0xa2e2700d, 0x76080396, - 0x4b31e6e0, 0x9fdb957b, 0x31432c0d, 0xe5a95f96, 0xd890bae0, - 0x0c7ac97b}, - {0x00000000, 0x27652581, 0x0fcc3bd9, 0x28a91e58, 0x5f9e0669, - 0x78fb23e8, 0x50523db0, 0x77371831, 0xbe3c0dd2, 0x99592853, - 0xb1f0360b, 0x9695138a, 0xe1a20bbb, 0xc6c72e3a, 0xee6e3062, - 0xc90b15e3, 0x3d7f6b7f, 0x1a1a4efe, 0x32b350a6, 0x15d67527, - 0x62e16d16, 0x45844897, 0x6d2d56cf, 0x4a48734e, 0x834366ad, - 0xa426432c, 0x8c8f5d74, 0xabea78f5, 0xdcdd60c4, 0xfbb84545, - 0xd3115b1d, 0xf4747e9c, 0x7afed6fe, 0x5d9bf37f, 0x7532ed27, - 0x5257c8a6, 0x2560d097, 0x0205f516, 0x2aaceb4e, 0x0dc9cecf, - 0xc4c2db2c, 0xe3a7fead, 0xcb0ee0f5, 0xec6bc574, 0x9b5cdd45, - 0xbc39f8c4, 0x9490e69c, 0xb3f5c31d, 0x4781bd81, 0x60e49800, - 0x484d8658, 0x6f28a3d9, 0x181fbbe8, 0x3f7a9e69, 0x17d38031, - 0x30b6a5b0, 0xf9bdb053, 0xded895d2, 0xf6718b8a, 0xd114ae0b, - 0xa623b63a, 0x814693bb, 0xa9ef8de3, 0x8e8aa862, 0xb5fadc26, - 0x929ff9a7, 0xba36e7ff, 0x9d53c27e, 0xea64da4f, 0xcd01ffce, - 0xe5a8e196, 0xc2cdc417, 0x0bc6d1f4, 0x2ca3f475, 0x040aea2d, - 0x236fcfac, 0x5458d79d, 0x733df21c, 0x5b94ec44, 0x7cf1c9c5, - 0x8885b759, 0xafe092d8, 0x87498c80, 0xa02ca901, 0xd71bb130, - 0xf07e94b1, 0xd8d78ae9, 0xffb2af68, 0x36b9ba8b, 0x11dc9f0a, - 0x39758152, 0x1e10a4d3, 0x6927bce2, 0x4e429963, 0x66eb873b, - 0x418ea2ba, 0xcf040ad8, 0xe8612f59, 0xc0c83101, 0xe7ad1480, - 0x909a0cb1, 0xb7ff2930, 0x9f563768, 0xb83312e9, 0x7138070a, - 0x565d228b, 0x7ef43cd3, 0x59911952, 0x2ea60163, 0x09c324e2, - 0x216a3aba, 0x060f1f3b, 0xf27b61a7, 0xd51e4426, 0xfdb75a7e, - 0xdad27fff, 0xade567ce, 0x8a80424f, 0xa2295c17, 0x854c7996, - 0x4c476c75, 0x6b2249f4, 0x438b57ac, 0x64ee722d, 0x13d96a1c, - 0x34bc4f9d, 0x1c1551c5, 0x3b707444, 0x6af5b94d, 0x4d909ccc, - 0x65398294, 0x425ca715, 0x356bbf24, 0x120e9aa5, 0x3aa784fd, - 0x1dc2a17c, 0xd4c9b49f, 0xf3ac911e, 0xdb058f46, 0xfc60aac7, - 0x8b57b2f6, 0xac329777, 0x849b892f, 0xa3feacae, 0x578ad232, - 0x70eff7b3, 0x5846e9eb, 0x7f23cc6a, 0x0814d45b, 0x2f71f1da, - 0x07d8ef82, 0x20bdca03, 0xe9b6dfe0, 0xced3fa61, 0xe67ae439, - 0xc11fc1b8, 0xb628d989, 0x914dfc08, 0xb9e4e250, 0x9e81c7d1, - 0x100b6fb3, 0x376e4a32, 0x1fc7546a, 0x38a271eb, 0x4f9569da, - 0x68f04c5b, 0x40595203, 0x673c7782, 0xae376261, 0x895247e0, - 0xa1fb59b8, 0x869e7c39, 0xf1a96408, 0xd6cc4189, 0xfe655fd1, - 0xd9007a50, 0x2d7404cc, 0x0a11214d, 0x22b83f15, 0x05dd1a94, - 0x72ea02a5, 0x558f2724, 0x7d26397c, 0x5a431cfd, 0x9348091e, - 0xb42d2c9f, 0x9c8432c7, 0xbbe11746, 0xccd60f77, 0xebb32af6, - 0xc31a34ae, 0xe47f112f, 0xdf0f656b, 0xf86a40ea, 0xd0c35eb2, - 0xf7a67b33, 0x80916302, 0xa7f44683, 0x8f5d58db, 0xa8387d5a, - 0x613368b9, 0x46564d38, 0x6eff5360, 0x499a76e1, 0x3ead6ed0, - 0x19c84b51, 0x31615509, 0x16047088, 0xe2700e14, 0xc5152b95, - 0xedbc35cd, 0xcad9104c, 0xbdee087d, 0x9a8b2dfc, 0xb22233a4, - 0x95471625, 0x5c4c03c6, 0x7b292647, 0x5380381f, 0x74e51d9e, - 0x03d205af, 0x24b7202e, 0x0c1e3e76, 0x2b7b1bf7, 0xa5f1b395, - 0x82949614, 0xaa3d884c, 0x8d58adcd, 0xfa6fb5fc, 0xdd0a907d, - 0xf5a38e25, 0xd2c6aba4, 0x1bcdbe47, 0x3ca89bc6, 0x1401859e, - 0x3364a01f, 0x4453b82e, 0x63369daf, 0x4b9f83f7, 0x6cfaa676, - 0x988ed8ea, 0xbfebfd6b, 0x9742e333, 0xb027c6b2, 0xc710de83, - 0xe075fb02, 0xc8dce55a, 0xefb9c0db, 0x26b2d538, 0x01d7f0b9, - 0x297eeee1, 0x0e1bcb60, 0x792cd351, 0x5e49f6d0, 0x76e0e888, - 0x5185cd09}}; - -#endif - -#endif - -#endif - -local const z_crc_t FAR x2n_table[] = { - 0x40000000, 0x20000000, 0x08000000, 0x00800000, 0x00008000, - 0xedb88320, 0xb1e6b092, 0xa06a2517, 0xed627dae, 0x88d14467, - 0xd7bbfe6a, 0xec447f11, 0x8e7ea170, 0x6427800e, 0x4d47bae0, - 0x09fe548f, 0x83852d0f, 0x30362f1a, 0x7b5a9cc3, 0x31fec169, - 0x9fec022a, 0x6c8dedc4, 0x15d6874d, 0x5fde7a4e, 0xbad90e37, - 0x2e4e5eef, 0x4eaba214, 0xa8a472c0, 0x429a969e, 0x148d302a, - 0xc40ba6d0, 0xc4e22c3c}; diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/deflate.c b/vendor/libgit2-sys/libgit2/deps/zlib/deflate.c deleted file mode 100644 index 012ea81..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/deflate.c +++ /dev/null @@ -1,2139 +0,0 @@ -/* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process depends on being able to identify portions - * of the input text which are identical to earlier input (within a - * sliding window trailing behind the input currently being processed). - * - * The most straightforward technique turns out to be the fastest for - * most input files: try all possible matches and select the longest. - * The key feature of this algorithm is that insertions into the string - * dictionary are very simple and thus fast, and deletions are avoided - * completely. Insertions are performed at each input character, whereas - * string matches are performed only when the previous match ends. So it - * is preferable to spend more time in matches to allow very fast string - * insertions and avoid deletions. The matching algorithm for small - * strings is inspired from that of Rabin & Karp. A brute force approach - * is used to find longer strings when a small match has been found. - * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze - * (by Leonid Broukhis). - * A previous version of this file used a more sophisticated algorithm - * (by Fiala and Greene) which is guaranteed to run in linear amortized - * time, but has a larger average cost, uses more memory and is patented. - * However the F&G algorithm may be faster for some highly redundant - * files if the parameter max_chain_length (described below) is too large. - * - * ACKNOWLEDGEMENTS - * - * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and - * I found it in 'freeze' written by Leonid Broukhis. - * Thanks to many people for bug reports and testing. - * - * REFERENCES - * - * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in http://tools.ietf.org/html/rfc1951 - * - * A description of the Rabin and Karp algorithm is given in the book - * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. - * - * Fiala,E.R., and Greene,D.H. - * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 - * - */ - -/* @(#) $Id$ */ - -#include "deflate.h" - -const char deflate_copyright[] = - " deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -typedef enum { - need_more, /* block not completed, need more input or more output */ - block_done, /* block flush performed */ - finish_started, /* finish started, need only more output at next deflate */ - finish_done /* finish done, accept no more input or output */ -} block_state; - -typedef block_state (*compress_func)(deflate_state *s, int flush); -/* Compression function. Returns the block state after the call. */ - -local block_state deflate_stored(deflate_state *s, int flush); -local block_state deflate_fast(deflate_state *s, int flush); -#ifndef FASTEST -local block_state deflate_slow(deflate_state *s, int flush); -#endif -local block_state deflate_rle(deflate_state *s, int flush); -local block_state deflate_huff(deflate_state *s, int flush); - -/* =========================================================================== - * Local data - */ - -#define NIL 0 -/* Tail of hash chains */ - -#ifndef TOO_FAR -# define TOO_FAR 4096 -#endif -/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ - -/* Values for max_lazy_match, good_match and max_chain_length, depending on - * the desired pack level (0..9). The values given below have been tuned to - * exclude worst case performance for pathological files. Better values may be - * found for specific files. - */ -typedef struct config_s { - ush good_length; /* reduce lazy search above this match length */ - ush max_lazy; /* do not perform lazy search above this match length */ - ush nice_length; /* quit search above this match length */ - ush max_chain; - compress_func func; -} config; - -#ifdef FASTEST -local const config configuration_table[2] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ -#else -local const config configuration_table[10] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ -/* 2 */ {4, 5, 16, 8, deflate_fast}, -/* 3 */ {4, 6, 32, 32, deflate_fast}, - -/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ -/* 5 */ {8, 16, 32, 32, deflate_slow}, -/* 6 */ {8, 16, 128, 128, deflate_slow}, -/* 7 */ {8, 32, 128, 256, deflate_slow}, -/* 8 */ {32, 128, 258, 1024, deflate_slow}, -/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ -#endif - -/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 - * For deflate_fast() (levels <= 3) good is ignored and lazy has a different - * meaning. - */ - -/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ -#define RANK(f) (((f) * 2) - ((f) > 4 ? 9 : 0)) - -/* =========================================================================== - * Update a hash value with the given input byte - * IN assertion: all calls to UPDATE_HASH are made with consecutive input - * characters, so that a running hash key can be computed from the previous - * key instead of complete recalculation each time. - */ -#define UPDATE_HASH(s,h,c) (h = (((h) << s->hash_shift) ^ (c)) & s->hash_mask) - - -/* =========================================================================== - * Insert string str in the dictionary and set match_head to the previous head - * of the hash chain (the most recent string with same hash key). Return - * the previous length of the hash chain. - * If this file is compiled with -DFASTEST, the compression level is forced - * to 1, and no hash chains are maintained. - * IN assertion: all calls to INSERT_STRING are made with consecutive input - * characters and the first MIN_MATCH bytes of str are valid (except for - * the last MIN_MATCH-1 bytes of the input file). - */ -#ifdef FASTEST -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#else -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#endif - -/* =========================================================================== - * Initialize the hash table (avoiding 64K overflow for 16 bit systems). - * prev[] will be initialized on the fly. - */ -#define CLEAR_HASH(s) \ - do { \ - s->head[s->hash_size - 1] = NIL; \ - zmemzero((Bytef *)s->head, \ - (unsigned)(s->hash_size - 1)*sizeof(*s->head)); \ - } while (0) - -/* =========================================================================== - * Slide the hash table when sliding the window down (could be avoided with 32 - * bit values at the expense of memory usage). We slide even when level == 0 to - * keep the hash table consistent if we switch back to level > 0 later. - */ -#if defined(__has_feature) -# if __has_feature(memory_sanitizer) - __attribute__((no_sanitize("memory"))) -# endif -#endif -local void slide_hash(deflate_state *s) { - unsigned n, m; - Posf *p; - uInt wsize = s->w_size; - - n = s->hash_size; - p = &s->head[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m - wsize : NIL); - } while (--n); - n = wsize; -#ifndef FASTEST - p = &s->prev[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m - wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); -#endif -} - -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) { - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return len; -} - -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(deflate_state *s) { - unsigned n; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize + MAX_DIST(s)) { - - zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - if (s->insert > s->strstart) - s->insert = s->strstart; - slide_hash(s); - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - -/* ========================================================================= */ -int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, - int stream_size) { - return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, version, stream_size); - /* To do: ignore strm->next_in if we use it as window */ -} - -/* ========================================================================= */ -int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, - int windowBits, int memLevel, int strategy, - const char *version, int stream_size) { - deflate_state *s; - int wrap = 1; - static const char my_version[] = ZLIB_VERSION; - - if (version == Z_NULL || version[0] != my_version[0] || - stream_size != sizeof(z_stream)) { - return Z_VERSION_ERROR; - } - if (strm == Z_NULL) return Z_STREAM_ERROR; - - strm->msg = Z_NULL; - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - - if (windowBits < 0) { /* suppress zlib wrapper */ - wrap = 0; - if (windowBits < -15) - return Z_STREAM_ERROR; - windowBits = -windowBits; - } -#ifdef GZIP - else if (windowBits > 15) { - wrap = 2; /* write gzip wrapper instead */ - windowBits -= 16; - } -#endif - if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) { - return Z_STREAM_ERROR; - } - if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; - s->status = INIT_STATE; /* to pass state test in deflateReset() */ - - s->wrap = wrap; - s->gzhead = Z_NULL; - s->w_bits = (uInt)windowBits; - s->w_size = 1 << s->w_bits; - s->w_mask = s->w_size - 1; - - s->hash_bits = (uInt)memLevel + 7; - s->hash_size = 1 << s->hash_bits; - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH); - - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - - s->high_water = 0; /* nothing written to s->window yet */ - - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - - /* We overlay pending_buf and sym_buf. This works since the average size - * for length/distance pairs over any compressed block is assured to be 31 - * bits or less. - * - * Analysis: The longest fixed codes are a length code of 8 bits plus 5 - * extra bits, for lengths 131 to 257. The longest fixed distance codes are - * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest - * possible fixed-codes length/distance pair is then 31 bits total. - * - * sym_buf starts one-fourth of the way into pending_buf. So there are - * three bytes in sym_buf for every four bytes in pending_buf. Each symbol - * in sym_buf is three bytes -- two for the distance and one for the - * literal/length. As each symbol is consumed, the pointer to the next - * sym_buf value to read moves forward three bytes. From that symbol, up to - * 31 bits are written to pending_buf. The closest the written pending_buf - * bits gets to the next sym_buf symbol to read is just before the last - * code is written. At that time, 31*(n - 2) bits have been written, just - * after 24*(n - 2) bits have been consumed from sym_buf. sym_buf starts at - * 8*n bits into pending_buf. (Note that the symbol buffer fills when n - 1 - * symbols are written.) The closest the writing gets to what is unread is - * then n + 14 bits. Here n is lit_bufsize, which is 16384 by default, and - * can range from 128 to 32768. - * - * Therefore, at a minimum, there are 142 bits of space between what is - * written and what is read in the overlain buffers, so the symbols cannot - * be overwritten by the compressed data. That space is actually 139 bits, - * due to the three-bit fixed-code block header. - * - * That covers the case where either Z_FIXED is specified, forcing fixed - * codes, or when the use of fixed codes is chosen, because that choice - * results in a smaller compressed block than dynamic codes. That latter - * condition then assures that the above analysis also covers all dynamic - * blocks. A dynamic-code block will only be chosen to be emitted if it has - * fewer bits than a fixed-code block would for the same set of symbols. - * Therefore its average symbol length is assured to be less than 31. So - * the compressed data for a dynamic block also cannot overwrite the - * symbols from which it is being constructed. - */ - - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS); - s->pending_buf_size = (ulg)s->lit_bufsize * 4; - - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - s->status = FINISH_STATE; - strm->msg = ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); - return Z_MEM_ERROR; - } -#ifdef LIT_MEM - s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1)); - s->l_buf = s->pending_buf + (s->lit_bufsize << 2); - s->sym_end = s->lit_bufsize - 1; -#else - s->sym_buf = s->pending_buf + s->lit_bufsize; - s->sym_end = (s->lit_bufsize - 1) * 3; -#endif - /* We avoid equality with lit_bufsize*3 because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to - * 64K-1 bytes. - */ - - s->level = level; - s->strategy = strategy; - s->method = (Byte)method; - - return deflateReset(strm); -} - -/* ========================================================================= - * Check for a valid deflate stream state. Return 0 if ok, 1 if not. - */ -local int deflateStateCheck(z_streamp strm) { - deflate_state *s; - if (strm == Z_NULL || - strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) - return 1; - s = strm->state; - if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE && -#ifdef GZIP - s->status != GZIP_STATE && -#endif - s->status != EXTRA_STATE && - s->status != NAME_STATE && - s->status != COMMENT_STATE && - s->status != HCRC_STATE && - s->status != BUSY_STATE && - s->status != FINISH_STATE)) - return 1; - return 0; -} - -/* ========================================================================= */ -int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength) { - deflate_state *s; - uInt str, n; - int wrap; - unsigned avail; - z_const unsigned char *next; - - if (deflateStateCheck(strm) || dictionary == Z_NULL) - return Z_STREAM_ERROR; - s = strm->state; - wrap = s->wrap; - if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) - return Z_STREAM_ERROR; - - /* when using zlib wrappers, compute Adler-32 for provided dictionary */ - if (wrap == 1) - strm->adler = adler32(strm->adler, dictionary, dictLength); - s->wrap = 0; /* avoid computing Adler-32 in read_buf */ - - /* if dictionary would fill window, just replace the history */ - if (dictLength >= s->w_size) { - if (wrap == 0) { /* already empty otherwise */ - CLEAR_HASH(s); - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - dictionary += dictLength - s->w_size; /* use the tail */ - dictLength = s->w_size; - } - - /* insert dictionary into window and hash */ - avail = strm->avail_in; - next = strm->next_in; - strm->avail_in = dictLength; - strm->next_in = (z_const Bytef *)dictionary; - fill_window(s); - while (s->lookahead >= MIN_MATCH) { - str = s->strstart; - n = s->lookahead - (MIN_MATCH-1); - do { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - } while (--n); - s->strstart = str; - s->lookahead = MIN_MATCH-1; - fill_window(s); - } - s->strstart += s->lookahead; - s->block_start = (long)s->strstart; - s->insert = s->lookahead; - s->lookahead = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - strm->next_in = next; - strm->avail_in = avail; - s->wrap = wrap; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, - uInt *dictLength) { - deflate_state *s; - uInt len; - - if (deflateStateCheck(strm)) - return Z_STREAM_ERROR; - s = strm->state; - len = s->strstart + s->lookahead; - if (len > s->w_size) - len = s->w_size; - if (dictionary != Z_NULL && len) - zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len); - if (dictLength != Z_NULL) - *dictLength = len; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateResetKeep(z_streamp strm) { - deflate_state *s; - - if (deflateStateCheck(strm)) { - return Z_STREAM_ERROR; - } - - strm->total_in = strm->total_out = 0; - strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ - strm->data_type = Z_UNKNOWN; - - s = (deflate_state *)strm->state; - s->pending = 0; - s->pending_out = s->pending_buf; - - if (s->wrap < 0) { - s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ - } - s->status = -#ifdef GZIP - s->wrap == 2 ? GZIP_STATE : -#endif - INIT_STATE; - strm->adler = -#ifdef GZIP - s->wrap == 2 ? crc32(0L, Z_NULL, 0) : -#endif - adler32(0L, Z_NULL, 0); - s->last_flush = -2; - - _tr_init(s); - - return Z_OK; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init(deflate_state *s) { - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -} - -/* ========================================================================= */ -int ZEXPORT deflateReset(z_streamp strm) { - int ret; - - ret = deflateResetKeep(strm); - if (ret == Z_OK) - lm_init(strm->state); - return ret; -} - -/* ========================================================================= */ -int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { - if (deflateStateCheck(strm) || strm->state->wrap != 2) - return Z_STREAM_ERROR; - strm->state->gzhead = head; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - if (pending != Z_NULL) - *pending = strm->state->pending; - if (bits != Z_NULL) - *bits = strm->state->bi_valid; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { - deflate_state *s; - int put; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - s = strm->state; -#ifdef LIT_MEM - if (bits < 0 || bits > 16 || - (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3)) - return Z_BUF_ERROR; -#else - if (bits < 0 || bits > 16 || - s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) - return Z_BUF_ERROR; -#endif - do { - put = Buf_size - s->bi_valid; - if (put > bits) - put = bits; - s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); - s->bi_valid += put; - _tr_flush_bits(s); - value >>= put; - bits -= put; - } while (bits); - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { - deflate_state *s; - compress_func func; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - s = strm->state; - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - func = configuration_table[s->level].func; - - if ((strategy != s->strategy || func != configuration_table[level].func) && - s->last_flush != -2) { - /* Flush the last buffer: */ - int err = deflate(strm, Z_BLOCK); - if (err == Z_STREAM_ERROR) - return err; - if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead) - return Z_BUF_ERROR; - } - if (s->level != level) { - if (s->level == 0 && s->matches != 0) { - if (s->matches == 1) - slide_hash(s); - else - CLEAR_HASH(s); - s->matches = 0; - } - s->level = level; - s->max_lazy_match = configuration_table[level].max_lazy; - s->good_match = configuration_table[level].good_length; - s->nice_match = configuration_table[level].nice_length; - s->max_chain_length = configuration_table[level].max_chain; - } - s->strategy = strategy; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, - int nice_length, int max_chain) { - deflate_state *s; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - s = strm->state; - s->good_match = (uInt)good_length; - s->max_lazy_match = (uInt)max_lazy; - s->nice_match = nice_length; - s->max_chain_length = (uInt)max_chain; - return Z_OK; -} - -/* ========================================================================= - * For the default windowBits of 15 and memLevel of 8, this function returns a - * close to exact, as well as small, upper bound on the compressed size. This - * is an expansion of ~0.03%, plus a small constant. - * - * For any setting other than those defaults for windowBits and memLevel, one - * of two worst case bounds is returned. This is at most an expansion of ~4% or - * ~13%, plus a small constant. - * - * Both the 0.03% and 4% derive from the overhead of stored blocks. The first - * one is for stored blocks of 16383 bytes (memLevel == 8), whereas the second - * is for stored blocks of 127 bytes (the worst case memLevel == 1). The - * expansion results from five bytes of header for each stored block. - * - * The larger expansion of 13% results from a window size less than or equal to - * the symbols buffer size (windowBits <= memLevel + 7). In that case some of - * the data being compressed may have slid out of the sliding window, impeding - * a stored block from being emitted. Then the only choice is a fixed or - * dynamic block, where a fixed block limits the maximum expansion to 9 bits - * per 8-bit byte, plus 10 bits for every block. The smallest block size for - * which this can occur is 255 (memLevel == 2). - * - * Shifts are used to approximate divisions, for speed. - */ -uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { - deflate_state *s; - uLong fixedlen, storelen, wraplen; - - /* upper bound for fixed blocks with 9-bit literals and length 255 - (memLevel == 2, which is the lowest that may not use stored blocks) -- - ~13% overhead plus a small constant */ - fixedlen = sourceLen + (sourceLen >> 3) + (sourceLen >> 8) + - (sourceLen >> 9) + 4; - - /* upper bound for stored blocks with length 127 (memLevel == 1) -- - ~4% overhead plus a small constant */ - storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) + - (sourceLen >> 11) + 7; - - /* if can't get parameters, return larger bound plus a zlib wrapper */ - if (deflateStateCheck(strm)) - return (fixedlen > storelen ? fixedlen : storelen) + 6; - - /* compute wrapper length */ - s = strm->state; - switch (s->wrap) { - case 0: /* raw deflate */ - wraplen = 0; - break; - case 1: /* zlib wrapper */ - wraplen = 6 + (s->strstart ? 4 : 0); - break; -#ifdef GZIP - case 2: /* gzip wrapper */ - wraplen = 18; - if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ - Bytef *str; - if (s->gzhead->extra != Z_NULL) - wraplen += 2 + s->gzhead->extra_len; - str = s->gzhead->name; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - str = s->gzhead->comment; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - if (s->gzhead->hcrc) - wraplen += 2; - } - break; -#endif - default: /* for compiler happiness */ - wraplen = 6; - } - - /* if not default parameters, return one of the conservative bounds */ - if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + - wraplen; - - /* default settings: return tight bound for that case -- ~0.03% overhead - plus a small constant */ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13 - 6 + wraplen; -} - -/* ========================================================================= - * Put a short in the pending buffer. The 16-bit value is put in MSB order. - * IN assertion: the stream state is correct and there is enough room in - * pending_buf. - */ -local void putShortMSB(deflate_state *s, uInt b) { - put_byte(s, (Byte)(b >> 8)); - put_byte(s, (Byte)(b & 0xff)); -} - -/* ========================================================================= - * Flush as much pending output as possible. All deflate() output, except for - * some deflate_stored() output, goes through this function so some - * applications may wish to modify it to avoid allocating a large - * strm->next_out buffer and copying into it. (See also read_buf()). - */ -local void flush_pending(z_streamp strm) { - unsigned len; - deflate_state *s = strm->state; - - _tr_flush_bits(s); - len = s->pending; - if (len > strm->avail_out) len = strm->avail_out; - if (len == 0) return; - - zmemcpy(strm->next_out, s->pending_out, len); - strm->next_out += len; - s->pending_out += len; - strm->total_out += len; - strm->avail_out -= len; - s->pending -= len; - if (s->pending == 0) { - s->pending_out = s->pending_buf; - } -} - -/* =========================================================================== - * Update the header CRC with the bytes s->pending_buf[beg..s->pending - 1]. - */ -#define HCRC_UPDATE(beg) \ - do { \ - if (s->gzhead->hcrc && s->pending > (beg)) \ - strm->adler = crc32(strm->adler, s->pending_buf + (beg), \ - s->pending - (beg)); \ - } while (0) - -/* ========================================================================= */ -int ZEXPORT deflate(z_streamp strm, int flush) { - int old_flush; /* value of flush param for previous deflate call */ - deflate_state *s; - - if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; - } - s = strm->state; - - if (strm->next_out == Z_NULL || - (strm->avail_in != 0 && strm->next_in == Z_NULL) || - (s->status == FINISH_STATE && flush != Z_FINISH)) { - ERR_RETURN(strm, Z_STREAM_ERROR); - } - if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); - - old_flush = s->last_flush; - s->last_flush = flush; - - /* Flush as much pending output as possible */ - if (s->pending != 0) { - flush_pending(strm); - if (strm->avail_out == 0) { - /* Since avail_out is 0, deflate will be called again with - * more output space, but possibly with both pending and - * avail_in equal to zero. There won't be anything to do, - * but this is not an error situation so make sure we - * return OK instead of BUF_ERROR at next call of deflate: - */ - s->last_flush = -1; - return Z_OK; - } - - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Z_FINISH, we keep - * returning Z_STREAM_END instead of Z_BUF_ERROR. - */ - } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && - flush != Z_FINISH) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* User must not provide more input after the first FINISH: */ - if (s->status == FINISH_STATE && strm->avail_in != 0) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* Write the header */ - if (s->status == INIT_STATE && s->wrap == 0) - s->status = BUSY_STATE; - if (s->status == INIT_STATE) { - /* zlib header */ - uInt header = (Z_DEFLATED + ((s->w_bits - 8) << 4)) << 8; - uInt level_flags; - - if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) - level_flags = 0; - else if (s->level < 6) - level_flags = 1; - else if (s->level == 6) - level_flags = 2; - else - level_flags = 3; - header |= (level_flags << 6); - if (s->strstart != 0) header |= PRESET_DICT; - header += 31 - (header % 31); - - putShortMSB(s, header); - - /* Save the adler32 of the preset dictionary: */ - if (s->strstart != 0) { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - strm->adler = adler32(0L, Z_NULL, 0); - s->status = BUSY_STATE; - - /* Compression must start with an empty pending buffer */ - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - } -#ifdef GZIP - if (s->status == GZIP_STATE) { - /* gzip header */ - strm->adler = crc32(0L, Z_NULL, 0); - put_byte(s, 31); - put_byte(s, 139); - put_byte(s, 8); - if (s->gzhead == Z_NULL) { - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, OS_CODE); - s->status = BUSY_STATE; - - /* Compression must start with an empty pending buffer */ - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - } - else { - put_byte(s, (s->gzhead->text ? 1 : 0) + - (s->gzhead->hcrc ? 2 : 0) + - (s->gzhead->extra == Z_NULL ? 0 : 4) + - (s->gzhead->name == Z_NULL ? 0 : 8) + - (s->gzhead->comment == Z_NULL ? 0 : 16) - ); - put_byte(s, (Byte)(s->gzhead->time & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, s->gzhead->os & 0xff); - if (s->gzhead->extra != Z_NULL) { - put_byte(s, s->gzhead->extra_len & 0xff); - put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); - } - if (s->gzhead->hcrc) - strm->adler = crc32(strm->adler, s->pending_buf, - s->pending); - s->gzindex = 0; - s->status = EXTRA_STATE; - } - } - if (s->status == EXTRA_STATE) { - if (s->gzhead->extra != Z_NULL) { - ulg beg = s->pending; /* start of bytes to update crc */ - uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex; - while (s->pending + left > s->pending_buf_size) { - uInt copy = s->pending_buf_size - s->pending; - zmemcpy(s->pending_buf + s->pending, - s->gzhead->extra + s->gzindex, copy); - s->pending = s->pending_buf_size; - HCRC_UPDATE(beg); - s->gzindex += copy; - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - beg = 0; - left -= copy; - } - zmemcpy(s->pending_buf + s->pending, - s->gzhead->extra + s->gzindex, left); - s->pending += left; - HCRC_UPDATE(beg); - s->gzindex = 0; - } - s->status = NAME_STATE; - } - if (s->status == NAME_STATE) { - if (s->gzhead->name != Z_NULL) { - ulg beg = s->pending; /* start of bytes to update crc */ - int val; - do { - if (s->pending == s->pending_buf_size) { - HCRC_UPDATE(beg); - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - beg = 0; - } - val = s->gzhead->name[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - HCRC_UPDATE(beg); - s->gzindex = 0; - } - s->status = COMMENT_STATE; - } - if (s->status == COMMENT_STATE) { - if (s->gzhead->comment != Z_NULL) { - ulg beg = s->pending; /* start of bytes to update crc */ - int val; - do { - if (s->pending == s->pending_buf_size) { - HCRC_UPDATE(beg); - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - beg = 0; - } - val = s->gzhead->comment[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - HCRC_UPDATE(beg); - } - s->status = HCRC_STATE; - } - if (s->status == HCRC_STATE) { - if (s->gzhead->hcrc) { - if (s->pending + 2 > s->pending_buf_size) { - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - } - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - strm->adler = crc32(0L, Z_NULL, 0); - } - s->status = BUSY_STATE; - - /* Compression must start with an empty pending buffer */ - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - } -#endif - - /* Start a new block or continue the current one. - */ - if (strm->avail_in != 0 || s->lookahead != 0 || - (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - block_state bstate; - - bstate = s->level == 0 ? deflate_stored(s, flush) : - s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : - s->strategy == Z_RLE ? deflate_rle(s, flush) : - (*(configuration_table[s->level].func))(s, flush); - - if (bstate == finish_started || bstate == finish_done) { - s->status = FINISH_STATE; - } - if (bstate == need_more || bstate == finish_started) { - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ - } - return Z_OK; - /* If flush != Z_NO_FLUSH && avail_out == 0, the next call - * of deflate should use the same flush parameter to make sure - * that the flush is complete. So we don't have to output an - * empty block here, this will be done at next call. This also - * ensures that for a very small output buffer, we emit at most - * one empty block. - */ - } - if (bstate == block_done) { - if (flush == Z_PARTIAL_FLUSH) { - _tr_align(s); - } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ - _tr_stored_block(s, (char*)0, 0L, 0); - /* For a full flush, this empty block will be recognized - * as a special marker by inflate_sync(). - */ - if (flush == Z_FULL_FLUSH) { - CLEAR_HASH(s); /* forget history */ - if (s->lookahead == 0) { - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - } - } - flush_pending(strm); - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ - return Z_OK; - } - } - } - - if (flush != Z_FINISH) return Z_OK; - if (s->wrap <= 0) return Z_STREAM_END; - - /* Write the trailer */ -#ifdef GZIP - if (s->wrap == 2) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); - put_byte(s, (Byte)(strm->total_in & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); - } - else -#endif - { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - flush_pending(strm); - /* If avail_out is zero, the application will call deflate again - * to flush the rest. - */ - if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ - return s->pending != 0 ? Z_OK : Z_STREAM_END; -} - -/* ========================================================================= */ -int ZEXPORT deflateEnd(z_streamp strm) { - int status; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - - status = strm->state->status; - - /* Deallocate in reverse order of allocations: */ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); - TRY_FREE(strm, strm->state->window); - - ZFREE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; -} - -/* ========================================================================= - * Copy the source state to the destination state. - * To simplify the source, this is not supported for 16-bit MSDOS (which - * doesn't have enough memory anyway to duplicate compression states). - */ -int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { -#ifdef MAXSEG_64K - (void)dest; - (void)source; - return Z_STREAM_ERROR; -#else - deflate_state *ds; - deflate_state *ss; - - - if (deflateStateCheck(source) || dest == Z_NULL) { - return Z_STREAM_ERROR; - } - - ss = source->state; - - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - - ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; - zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); - ds->strm = dest; - - ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS); - - if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || - ds->pending_buf == Z_NULL) { - deflateEnd (dest); - return Z_MEM_ERROR; - } - /* following zmemcpy do not work for 16-bit MSDOS */ - zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS); - - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); -#ifdef LIT_MEM - ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1)); - ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2); -#else - ds->sym_buf = ds->pending_buf + ds->lit_bufsize; -#endif - - ds->l_desc.dyn_tree = ds->dyn_ltree; - ds->d_desc.dyn_tree = ds->dyn_dtree; - ds->bl_desc.dyn_tree = ds->bl_tree; - - return Z_OK; -#endif /* MAXSEG_64K */ -} - -#ifndef FASTEST -/* =========================================================================== - * Set match_start to the longest match starting at the given string and - * return its length. Matches shorter or equal to prev_length are discarded, - * in which case the result is equal to prev_length and match_start is - * garbage. - * IN assertions: cur_match is the head of the hash chain for the current - * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 - * OUT assertion: the match length is not greater than s->lookahead. - */ -local uInt longest_match(deflate_state *s, IPos cur_match) { - unsigned chain_length = s->max_chain_length;/* max hash chain length */ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - int best_len = (int)s->prev_length; /* best match length so far */ - int nice_match = s->nice_match; /* stop if match long enough */ - IPos limit = s->strstart > (IPos)MAX_DIST(s) ? - s->strstart - (IPos)MAX_DIST(s) : NIL; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - Posf *prev = s->prev; - uInt wmask = s->w_mask; - -#ifdef UNALIGNED_OK - /* Compare two bytes at a time. Note: this is not always beneficial. - * Try with and without -DUNALIGNED_OK to check. - */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - register ush scan_start = *(ushf*)scan; - register ush scan_end = *(ushf*)(scan + best_len - 1); -#else - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len - 1]; - register Byte scan_end = scan[best_len]; -#endif - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - /* Do not waste too much time if we already have a good match: */ - if (s->prev_length >= s->good_match) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead; - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "need lookahead"); - - do { - Assert(cur_match < s->strstart, "no future"); - match = s->window + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2. Note that the checks below - * for insufficient lookahead only occur occasionally for performance - * reasons. Therefore uninitialized memory will be accessed, and - * conditional jumps will be made that depend on those values. - * However the length of the match is limited to the lookahead, so - * the output of deflate is not affected by the uninitialized values. - */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) - /* This code assumes sizeof(unsigned short) == 2. Do not use - * UNALIGNED_OK if your compiler uses a different size. - */ - if (*(ushf*)(match + best_len - 1) != scan_end || - *(ushf*)match != scan_start) continue; - - /* It is not necessary to compare scan[2] and match[2] since they are - * always equal when the other bytes match, given that the hash keys - * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart + 3, + 5, up to strstart + 257. We check for insufficient - * lookahead only every 4th comparison; the 128th check will be made - * at strstart + 257. If MAX_MATCH-2 is not a multiple of 8, it is - * necessary to put more guard bytes at the end of the window, or - * to check more often for insufficient lookahead. - */ - Assert(scan[2] == match[2], "scan[2]?"); - scan++, match++; - do { - } while (*(ushf*)(scan += 2) == *(ushf*)(match += 2) && - *(ushf*)(scan += 2) == *(ushf*)(match += 2) && - *(ushf*)(scan += 2) == *(ushf*)(match += 2) && - *(ushf*)(scan += 2) == *(ushf*)(match += 2) && - scan < strend); - /* The funny "do {}" generates better code on most compilers */ - - /* Here, scan <= window + strstart + 257 */ - Assert(scan <= s->window + (unsigned)(s->window_size - 1), - "wild scan"); - if (*scan == *match) scan++; - - len = (MAX_MATCH - 1) - (int)(strend - scan); - scan = strend - (MAX_MATCH-1); - -#else /* UNALIGNED_OK */ - - if (match[best_len] != scan_end || - match[best_len - 1] != scan_end1 || - *match != *scan || - *++match != scan[1]) continue; - - /* The check at best_len - 1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart + 258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window + (unsigned)(s->window_size - 1), - "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - scan = strend - MAX_MATCH; - -#endif /* UNALIGNED_OK */ - - if (len > best_len) { - s->match_start = cur_match; - best_len = len; - if (len >= nice_match) break; -#ifdef UNALIGNED_OK - scan_end = *(ushf*)(scan + best_len - 1); -#else - scan_end1 = scan[best_len - 1]; - scan_end = scan[best_len]; -#endif - } - } while ((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if ((uInt)best_len <= s->lookahead) return (uInt)best_len; - return s->lookahead; -} - -#else /* FASTEST */ - -/* --------------------------------------------------------------------------- - * Optimized version for FASTEST only - */ -local uInt longest_match(deflate_state *s, IPos cur_match) { - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "need lookahead"); - - Assert(cur_match < s->strstart, "no future"); - - match = s->window + cur_match; - - /* Return failure if the match length is less than 2: - */ - if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; - - /* The check at best_len - 1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match += 2; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart + 258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window + (unsigned)(s->window_size - 1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - - if (len < MIN_MATCH) return MIN_MATCH - 1; - - s->match_start = cur_match; - return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; -} - -#endif /* FASTEST */ - -#ifdef ZLIB_DEBUG - -#define EQUAL 0 -/* result of memcmp for equal strings */ - -/* =========================================================================== - * Check that the match at match_start is indeed a match. - */ -local void check_match(deflate_state *s, IPos start, IPos match, int length) { - /* check that the match is indeed a match */ - Bytef *back = s->window + (int)match, *here = s->window + start; - IPos len = length; - if (match == (IPos)-1) { - /* match starts one byte before the current window -- just compare the - subsequent length-1 bytes */ - back++; - here++; - len--; - } - if (zmemcmp(back, here, len) != EQUAL) { - fprintf(stderr, " start %u, match %d, length %d\n", - start, (int)match, length); - do { - fprintf(stderr, "(%02x %02x)", *back++, *here++); - } while (--len != 0); - z_error("invalid match"); - } - if (z_verbose > 1) { - fprintf(stderr,"\\[%d,%d]", start - match, length); - do { putc(s->window[start++], stderr); } while (--length != 0); - } -} -#else -# define check_match(s, start, match, length) -#endif /* ZLIB_DEBUG */ - -/* =========================================================================== - * Flush the current block, with given end-of-file flag. - * IN assertion: strstart is set to the end of the current match. - */ -#define FLUSH_BLOCK_ONLY(s, last) { \ - _tr_flush_block(s, (s->block_start >= 0L ? \ - (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), \ - (ulg)((long)s->strstart - s->block_start), \ - (last)); \ - s->block_start = s->strstart; \ - flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ -} - -/* Same but force premature exit if necessary. */ -#define FLUSH_BLOCK(s, last) { \ - FLUSH_BLOCK_ONLY(s, last); \ - if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ -} - -/* Maximum stored block length in deflate format (not including header). */ -#define MAX_STORED 65535 - -/* Minimum of a and b. */ -#define MIN(a, b) ((a) > (b) ? (b) : (a)) - -/* =========================================================================== - * Copy without compression as much as possible from the input stream, return - * the current block state. - * - * In case deflateParams() is used to later switch to a non-zero compression - * level, s->matches (otherwise unused when storing) keeps track of the number - * of hash table slides to perform. If s->matches is 1, then one hash table - * slide will be done when switching. If s->matches is 2, the maximum value - * allowed here, then the hash table will be cleared, since two or more slides - * is the same as a clear. - * - * deflate_stored() is written to minimize the number of times an input byte is - * copied. It is most efficient with large input and output buffers, which - * maximizes the opportunities to have a single copy from next_in to next_out. - */ -local block_state deflate_stored(deflate_state *s, int flush) { - /* Smallest worthy block size when not flushing or finishing. By default - * this is 32K. This can be as small as 507 bytes for memLevel == 1. For - * large input and output buffers, the stored block size will be larger. - */ - unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size); - - /* Copy as many min_block or larger stored blocks directly to next_out as - * possible. If flushing, copy the remaining available input to next_out as - * stored blocks, if there is enough space. - */ - unsigned len, left, have, last = 0; - unsigned used = s->strm->avail_in; - do { - /* Set len to the maximum size block that we can copy directly with the - * available input data and output space. Set left to how much of that - * would be copied from what's left in the window. - */ - len = MAX_STORED; /* maximum deflate stored block length */ - have = (s->bi_valid + 42) >> 3; /* number of header bytes */ - if (s->strm->avail_out < have) /* need room for header */ - break; - /* maximum stored block length that will fit in avail_out: */ - have = s->strm->avail_out - have; - left = s->strstart - s->block_start; /* bytes left in window */ - if (len > (ulg)left + s->strm->avail_in) - len = left + s->strm->avail_in; /* limit len to the input */ - if (len > have) - len = have; /* limit len to the output */ - - /* If the stored block would be less than min_block in length, or if - * unable to copy all of the available input when flushing, then try - * copying to the window and the pending buffer instead. Also don't - * write an empty block when flushing -- deflate() does that. - */ - if (len < min_block && ((len == 0 && flush != Z_FINISH) || - flush == Z_NO_FLUSH || - len != left + s->strm->avail_in)) - break; - - /* Make a dummy stored block in pending to get the header bytes, - * including any pending bits. This also updates the debugging counts. - */ - last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0; - _tr_stored_block(s, (char *)0, 0L, last); - - /* Replace the lengths in the dummy stored block with len. */ - s->pending_buf[s->pending - 4] = len; - s->pending_buf[s->pending - 3] = len >> 8; - s->pending_buf[s->pending - 2] = ~len; - s->pending_buf[s->pending - 1] = ~len >> 8; - - /* Write the stored block header bytes. */ - flush_pending(s->strm); - -#ifdef ZLIB_DEBUG - /* Update debugging counts for the data about to be copied. */ - s->compressed_len += len << 3; - s->bits_sent += len << 3; -#endif - - /* Copy uncompressed bytes from the window to next_out. */ - if (left) { - if (left > len) - left = len; - zmemcpy(s->strm->next_out, s->window + s->block_start, left); - s->strm->next_out += left; - s->strm->avail_out -= left; - s->strm->total_out += left; - s->block_start += left; - len -= left; - } - - /* Copy uncompressed bytes directly from next_in to next_out, updating - * the check value. - */ - if (len) { - read_buf(s->strm, s->strm->next_out, len); - s->strm->next_out += len; - s->strm->avail_out -= len; - s->strm->total_out += len; - } - } while (last == 0); - - /* Update the sliding window with the last s->w_size bytes of the copied - * data, or append all of the copied data to the existing window if less - * than s->w_size bytes were copied. Also update the number of bytes to - * insert in the hash tables, in the event that deflateParams() switches to - * a non-zero compression level. - */ - used -= s->strm->avail_in; /* number of input bytes directly copied */ - if (used) { - /* If any input was used, then no unused input remains in the window, - * therefore s->block_start == s->strstart. - */ - if (used >= s->w_size) { /* supplant the previous history */ - s->matches = 2; /* clear hash */ - zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size); - s->strstart = s->w_size; - s->insert = s->strstart; - } - else { - if (s->window_size - s->strstart <= used) { - /* Slide the window down. */ - s->strstart -= s->w_size; - zmemcpy(s->window, s->window + s->w_size, s->strstart); - if (s->matches < 2) - s->matches++; /* add a pending slide_hash() */ - if (s->insert > s->strstart) - s->insert = s->strstart; - } - zmemcpy(s->window + s->strstart, s->strm->next_in - used, used); - s->strstart += used; - s->insert += MIN(used, s->w_size - s->insert); - } - s->block_start = s->strstart; - } - if (s->high_water < s->strstart) - s->high_water = s->strstart; - - /* If the last block was written to next_out, then done. */ - if (last) - return finish_done; - - /* If flushing and all input has been consumed, then done. */ - if (flush != Z_NO_FLUSH && flush != Z_FINISH && - s->strm->avail_in == 0 && (long)s->strstart == s->block_start) - return block_done; - - /* Fill the window with any remaining input. */ - have = s->window_size - s->strstart; - if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) { - /* Slide the window down. */ - s->block_start -= s->w_size; - s->strstart -= s->w_size; - zmemcpy(s->window, s->window + s->w_size, s->strstart); - if (s->matches < 2) - s->matches++; /* add a pending slide_hash() */ - have += s->w_size; /* more space now */ - if (s->insert > s->strstart) - s->insert = s->strstart; - } - if (have > s->strm->avail_in) - have = s->strm->avail_in; - if (have) { - read_buf(s->strm, s->window + s->strstart, have); - s->strstart += have; - s->insert += MIN(have, s->w_size - s->insert); - } - if (s->high_water < s->strstart) - s->high_water = s->strstart; - - /* There was not enough avail_out to write a complete worthy or flushed - * stored block to next_out. Write a stored block to pending instead, if we - * have enough input for a worthy block, or if flushing and there is enough - * room for the remaining input as a stored block in the pending buffer. - */ - have = (s->bi_valid + 42) >> 3; /* number of header bytes */ - /* maximum stored block length that will fit in pending: */ - have = MIN(s->pending_buf_size - have, MAX_STORED); - min_block = MIN(have, s->w_size); - left = s->strstart - s->block_start; - if (left >= min_block || - ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH && - s->strm->avail_in == 0 && left <= have)) { - len = MIN(left, have); - last = flush == Z_FINISH && s->strm->avail_in == 0 && - len == left ? 1 : 0; - _tr_stored_block(s, (charf *)s->window + s->block_start, len, last); - s->block_start += len; - flush_pending(s->strm); - } - - /* We've done all we can with the available input and output. */ - return last ? finish_started : need_more; -} - -/* =========================================================================== - * Compress as much as possible from the input stream, return the current - * block state. - * This function does not perform lazy evaluation of matches and inserts - * new strings in the dictionary only for unmatched strings or for short - * matches. It is used only for the fast compression options. - */ -local block_state deflate_fast(deflate_state *s, int flush) { - IPos hash_head; /* head of the hash chain */ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart + 2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - * At this point we have always match_length < MIN_MATCH - */ - if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - } - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->match_start, s->match_length); - - _tr_tally_dist(s, s->strstart - s->match_start, - s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - - /* Insert new strings in the hash table only if the match length - * is not too large. This saves time but degrades compression. - */ -#ifndef FASTEST - if (s->match_length <= s->max_insert_length && - s->lookahead >= MIN_MATCH) { - s->match_length--; /* string at strstart already in table */ - do { - s->strstart++; - INSERT_STRING(s, s->strstart, hash_head); - /* strstart never exceeds WSIZE-MAX_MATCH, so there are - * always MIN_MATCH bytes ahead. - */ - } while (--s->match_length != 0); - s->strstart++; - } else -#endif - { - s->strstart += s->match_length; - s->match_length = 0; - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ - } - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit(s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->sym_next) - FLUSH_BLOCK(s, 0); - return block_done; -} - -#ifndef FASTEST -/* =========================================================================== - * Same as above, but achieves better compression. We use a lazy - * evaluation for matches: a match is finally adopted only if there is - * no better match at the next window position. - */ -local block_state deflate_slow(deflate_state *s, int flush) { - IPos hash_head; /* head of hash chain */ - int bflush; /* set if current block must be flushed */ - - /* Process the input block. */ - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart + 2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - */ - s->prev_length = s->match_length, s->prev_match = s->match_start; - s->match_length = MIN_MATCH-1; - - if (hash_head != NIL && s->prev_length < s->max_lazy_match && - s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - - if (s->match_length <= 5 && (s->strategy == Z_FILTERED -#if TOO_FAR <= 32767 - || (s->match_length == MIN_MATCH && - s->strstart - s->match_start > TOO_FAR) -#endif - )) { - - /* If prev_match is also MIN_MATCH, match_start is garbage - * but we will ignore the current match anyway. - */ - s->match_length = MIN_MATCH-1; - } - } - /* If there was a match at the previous step and the current - * match is not better, output the previous match: - */ - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { - uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; - /* Do not insert strings in hash table beyond this. */ - - check_match(s, s->strstart - 1, s->prev_match, s->prev_length); - - _tr_tally_dist(s, s->strstart - 1 - s->prev_match, - s->prev_length - MIN_MATCH, bflush); - - /* Insert in hash table all strings up to the end of the match. - * strstart - 1 and strstart are already inserted. If there is not - * enough lookahead, the last two strings are not inserted in - * the hash table. - */ - s->lookahead -= s->prev_length - 1; - s->prev_length -= 2; - do { - if (++s->strstart <= max_insert) { - INSERT_STRING(s, s->strstart, hash_head); - } - } while (--s->prev_length != 0); - s->match_available = 0; - s->match_length = MIN_MATCH-1; - s->strstart++; - - if (bflush) FLUSH_BLOCK(s, 0); - - } else if (s->match_available) { - /* If there was no match at the previous position, output a - * single literal. If there was a match but the current match - * is longer, truncate the previous match to a single literal. - */ - Tracevv((stderr,"%c", s->window[s->strstart - 1])); - _tr_tally_lit(s, s->window[s->strstart - 1], bflush); - if (bflush) { - FLUSH_BLOCK_ONLY(s, 0); - } - s->strstart++; - s->lookahead--; - if (s->strm->avail_out == 0) return need_more; - } else { - /* There is no previous match to compare with, wait for - * the next step to decide. - */ - s->match_available = 1; - s->strstart++; - s->lookahead--; - } - } - Assert (flush != Z_NO_FLUSH, "no flush?"); - if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart - 1])); - _tr_tally_lit(s, s->window[s->strstart - 1], bflush); - s->match_available = 0; - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->sym_next) - FLUSH_BLOCK(s, 0); - return block_done; -} -#endif /* FASTEST */ - -/* =========================================================================== - * For Z_RLE, simply look for runs of bytes, generate matches only of distance - * one. Do not maintain a hash table. (It will be regenerated if this run of - * deflate switches away from Z_RLE.) - */ -local block_state deflate_rle(deflate_state *s, int flush) { - int bflush; /* set if current block must be flushed */ - uInt prev; /* byte at distance one to match */ - Bytef *scan, *strend; /* scan goes up to strend for length of run */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the longest run, plus one for the unrolled loop. - */ - if (s->lookahead <= MAX_MATCH) { - fill_window(s); - if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* See how many times the previous byte repeats */ - s->match_length = 0; - if (s->lookahead >= MIN_MATCH && s->strstart > 0) { - scan = s->window + s->strstart - 1; - prev = *scan; - if (prev == *++scan && prev == *++scan && prev == *++scan) { - strend = s->window + s->strstart + MAX_MATCH; - do { - } while (prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - scan < strend); - s->match_length = MAX_MATCH - (uInt)(strend - scan); - if (s->match_length > s->lookahead) - s->match_length = s->lookahead; - } - Assert(scan <= s->window + (uInt)(s->window_size - 1), - "wild scan"); - } - - /* Emit match if have run of MIN_MATCH or longer, else emit literal */ - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, s->match_length); - - _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - s->strstart += s->match_length; - s->match_length = 0; - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit(s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->sym_next) - FLUSH_BLOCK(s, 0); - return block_done; -} - -/* =========================================================================== - * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. - * (It will be regenerated if this run of deflate switches away from Huffman.) - */ -local block_state deflate_huff(deflate_state *s, int flush) { - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we have a literal to write. */ - if (s->lookahead == 0) { - fill_window(s); - if (s->lookahead == 0) { - if (flush == Z_NO_FLUSH) - return need_more; - break; /* flush the current block */ - } - } - - /* Output a literal byte */ - s->match_length = 0; - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit(s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->sym_next) - FLUSH_BLOCK(s, 0); - return block_done; -} diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/deflate.h b/vendor/libgit2-sys/libgit2/deps/zlib/deflate.h deleted file mode 100644 index 300c6ad..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/deflate.h +++ /dev/null @@ -1,377 +0,0 @@ -/* deflate.h -- internal compression state - * Copyright (C) 1995-2024 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef DEFLATE_H -#define DEFLATE_H - -#include "zutil.h" - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer creation by deflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip encoding - should be left enabled. */ -#ifndef NO_GZIP -# define GZIP -#endif - -/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at - the cost of a larger memory footprint */ -/* #define LIT_MEM */ - -/* =========================================================================== - * Internal compression state. - */ - -#define LENGTH_CODES 29 -/* number of length codes, not counting the special END_BLOCK code */ - -#define LITERALS 256 -/* number of literal bytes 0..255 */ - -#define L_CODES (LITERALS+1+LENGTH_CODES) -/* number of Literal or Length codes, including the END_BLOCK code */ - -#define D_CODES 30 -/* number of distance codes */ - -#define BL_CODES 19 -/* number of codes used to transfer the bit lengths */ - -#define HEAP_SIZE (2*L_CODES+1) -/* maximum heap size */ - -#define MAX_BITS 15 -/* All codes must not exceed MAX_BITS bits */ - -#define Buf_size 16 -/* size of bit buffer in bi_buf */ - -#define INIT_STATE 42 /* zlib header -> BUSY_STATE */ -#ifdef GZIP -# define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */ -#endif -#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */ -#define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */ -#define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */ -#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */ -#define BUSY_STATE 113 /* deflate -> FINISH_STATE */ -#define FINISH_STATE 666 /* stream complete */ -/* Stream status */ - - -/* Data structure describing a single value and its code string. */ -typedef struct ct_data_s { - union { - ush freq; /* frequency count */ - ush code; /* bit string */ - } fc; - union { - ush dad; /* father node in Huffman tree */ - ush len; /* length of bit string */ - } dl; -} FAR ct_data; - -#define Freq fc.freq -#define Code fc.code -#define Dad dl.dad -#define Len dl.len - -typedef struct static_tree_desc_s static_tree_desc; - -typedef struct tree_desc_s { - ct_data *dyn_tree; /* the dynamic tree */ - int max_code; /* largest code with non zero frequency */ - const static_tree_desc *stat_desc; /* the corresponding static tree */ -} FAR tree_desc; - -typedef ush Pos; -typedef Pos FAR Posf; -typedef unsigned IPos; - -/* A Pos is an index in the character window. We use short instead of int to - * save space in the various tables. IPos is used only for parameter passing. - */ - -typedef struct internal_state { - z_streamp strm; /* pointer back to this zlib stream */ - int status; /* as the name implies */ - Bytef *pending_buf; /* output still pending */ - ulg pending_buf_size; /* size of pending_buf */ - Bytef *pending_out; /* next pending byte to output to the stream */ - ulg pending; /* nb of bytes in the pending buffer */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - gz_headerp gzhead; /* gzip header information to write */ - ulg gzindex; /* where in extra, name, or comment */ - Byte method; /* can only be DEFLATED */ - int last_flush; /* value of flush param for previous deflate call */ - - /* used by deflate.c: */ - - uInt w_size; /* LZ77 window size (32K by default) */ - uInt w_bits; /* log2(w_size) (8..16) */ - uInt w_mask; /* w_size - 1 */ - - Bytef *window; - /* Sliding window. Input bytes are read into the second half of the window, - * and move to the first half later to keep a dictionary of at least wSize - * bytes. With this organization, matches are limited to a distance of - * wSize-MAX_MATCH bytes, but this ensures that IO is always - * performed with a length multiple of the block size. Also, it limits - * the window size to 64K, which is quite useful on MSDOS. - * To do: use the user input buffer as sliding window. - */ - - ulg window_size; - /* Actual size of window: 2*wSize, except when the user input buffer - * is directly used as sliding window. - */ - - Posf *prev; - /* Link to older string with same hash index. To limit the size of this - * array to 64K, this link is maintained only for the last 32K strings. - * An index in this array is thus a window index modulo 32K. - */ - - Posf *head; /* Heads of the hash chains or NIL. */ - - uInt ins_h; /* hash index of string to be inserted */ - uInt hash_size; /* number of elements in hash table */ - uInt hash_bits; /* log2(hash_size) */ - uInt hash_mask; /* hash_size-1 */ - - uInt hash_shift; - /* Number of bits by which ins_h must be shifted at each input - * step. It must be such that after MIN_MATCH steps, the oldest - * byte no longer takes part in the hash key, that is: - * hash_shift * MIN_MATCH >= hash_bits - */ - - long block_start; - /* Window position at the beginning of the current output block. Gets - * negative when the window is moved backwards. - */ - - uInt match_length; /* length of best match */ - IPos prev_match; /* previous match */ - int match_available; /* set if previous match exists */ - uInt strstart; /* start of string to insert */ - uInt match_start; /* start of matching string */ - uInt lookahead; /* number of valid bytes ahead in window */ - - uInt prev_length; - /* Length of the best match at previous step. Matches not greater than this - * are discarded. This is used in the lazy match evaluation. - */ - - uInt max_chain_length; - /* To speed up deflation, hash chains are never searched beyond this - * length. A higher limit improves compression ratio but degrades the - * speed. - */ - - uInt max_lazy_match; - /* Attempt to find a better match only when the current match is strictly - * smaller than this value. This mechanism is used only for compression - * levels >= 4. - */ -# define max_insert_length max_lazy_match - /* Insert new strings in the hash table only if the match length is not - * greater than this length. This saves time but degrades compression. - * max_insert_length is used only for compression levels <= 3. - */ - - int level; /* compression level (1..9) */ - int strategy; /* favor or force Huffman coding*/ - - uInt good_match; - /* Use a faster search when the previous match is longer than this */ - - int nice_match; /* Stop searching when current match exceeds this */ - - /* used by trees.c: */ - /* Didn't use ct_data typedef below to suppress compiler warning */ - struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ - struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ - struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ - - struct tree_desc_s l_desc; /* desc. for literal tree */ - struct tree_desc_s d_desc; /* desc. for distance tree */ - struct tree_desc_s bl_desc; /* desc. for bit length tree */ - - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ - int heap_len; /* number of elements in the heap */ - int heap_max; /* element of largest frequency */ - /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. - * The same heap array is used to build all trees. - */ - - uch depth[2*L_CODES+1]; - /* Depth of each subtree used as tie breaker for trees of equal frequency - */ - -#ifdef LIT_MEM -# define LIT_BUFS 5 - ushf *d_buf; /* buffer for distances */ - uchf *l_buf; /* buffer for literals/lengths */ -#else -# define LIT_BUFS 4 - uchf *sym_buf; /* buffer for distances and literals/lengths */ -#endif - - uInt lit_bufsize; - /* Size of match buffer for literals/lengths. There are 4 reasons for - * limiting lit_bufsize to 64K: - * - frequencies can be kept in 16 bit counters - * - if compression is not successful for the first block, all input - * data is still in the window so we can still emit a stored block even - * when input comes from standard input. (This can also be done for - * all blocks if lit_bufsize is not greater than 32K.) - * - if compression is not successful for a file smaller than 64K, we can - * even emit a stored file instead of a stored block (saving 5 bytes). - * This is applicable only for zip (not gzip or zlib). - * - creating new Huffman trees less frequently may not provide fast - * adaptation to changes in the input data statistics. (Take for - * example a binary file with poorly compressible code followed by - * a highly compressible string table.) Smaller buffer sizes give - * fast adaptation but have of course the overhead of transmitting - * trees more frequently. - * - I can't count above 4 - */ - - uInt sym_next; /* running index in symbol buffer */ - uInt sym_end; /* symbol table full when sym_next reaches this */ - - ulg opt_len; /* bit length of current block with optimal trees */ - ulg static_len; /* bit length of current block with static trees */ - uInt matches; /* number of string matches in current block */ - uInt insert; /* bytes at end of window left to insert */ - -#ifdef ZLIB_DEBUG - ulg compressed_len; /* total bit length of compressed file mod 2^32 */ - ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ -#endif - - ush bi_buf; - /* Output buffer. bits are inserted starting at the bottom (least - * significant bits). - */ - int bi_valid; - /* Number of valid bits in bi_buf. All bits above the last valid bit - * are always zero. - */ - - ulg high_water; - /* High water mark offset in window for initialized bytes -- bytes above - * this are set to zero in order to avoid memory check warnings when - * longest match routines access bytes past the input. This is then - * updated to the new high water mark. - */ - -} FAR deflate_state; - -/* Output a byte on the stream. - * IN assertion: there is enough room in pending_buf. - */ -#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);} - - -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) -/* Minimum amount of lookahead, except at the end of the input file. - * See deflate.c for comments about the MIN_MATCH+1. - */ - -#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) -/* In order to simplify the code, particularly on 16 bit machines, match - * distances are limited to MAX_DIST instead of WSIZE. - */ - -#define WIN_INIT MAX_MATCH -/* Number of bytes after end of data in window to initialize in order to avoid - memory checker errors from longest match routines */ - - /* in trees.c */ -void ZLIB_INTERNAL _tr_init(deflate_state *s); -int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc); -void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, - ulg stored_len, int last); -void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s); -void ZLIB_INTERNAL _tr_align(deflate_state *s); -void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, - ulg stored_len, int last); - -#define d_code(dist) \ - ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) -/* Mapping from a distance to a distance code. dist is the distance - 1 and - * must not have side effects. _dist_code[256] and _dist_code[257] are never - * used. - */ - -#ifndef ZLIB_DEBUG -/* Inline versions of _tr_tally for speed: */ - -#if defined(GEN_TREES_H) || !defined(STDC) - extern uch ZLIB_INTERNAL _length_code[]; - extern uch ZLIB_INTERNAL _dist_code[]; -#else - extern const uch ZLIB_INTERNAL _length_code[]; - extern const uch ZLIB_INTERNAL _dist_code[]; -#endif - -#ifdef LIT_MEM -# define _tr_tally_lit(s, c, flush) \ - { uch cc = (c); \ - s->d_buf[s->sym_next] = 0; \ - s->l_buf[s->sym_next++] = cc; \ - s->dyn_ltree[cc].Freq++; \ - flush = (s->sym_next == s->sym_end); \ - } -# define _tr_tally_dist(s, distance, length, flush) \ - { uch len = (uch)(length); \ - ush dist = (ush)(distance); \ - s->d_buf[s->sym_next] = dist; \ - s->l_buf[s->sym_next++] = len; \ - dist--; \ - s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ - s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->sym_next == s->sym_end); \ - } -#else -# define _tr_tally_lit(s, c, flush) \ - { uch cc = (c); \ - s->sym_buf[s->sym_next++] = 0; \ - s->sym_buf[s->sym_next++] = 0; \ - s->sym_buf[s->sym_next++] = cc; \ - s->dyn_ltree[cc].Freq++; \ - flush = (s->sym_next == s->sym_end); \ - } -# define _tr_tally_dist(s, distance, length, flush) \ - { uch len = (uch)(length); \ - ush dist = (ush)(distance); \ - s->sym_buf[s->sym_next++] = (uch)dist; \ - s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \ - s->sym_buf[s->sym_next++] = len; \ - dist--; \ - s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ - s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->sym_next == s->sym_end); \ - } -#endif -#else -# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) -# define _tr_tally_dist(s, distance, length, flush) \ - flush = _tr_tally(s, distance, length) -#endif - -#endif /* DEFLATE_H */ diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/gzguts.h b/vendor/libgit2-sys/libgit2/deps/zlib/gzguts.h deleted file mode 100644 index eba7208..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/gzguts.h +++ /dev/null @@ -1,214 +0,0 @@ -/* gzguts.h -- zlib internal header definitions for gz* operations - * Copyright (C) 2004-2024 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#ifdef _LARGEFILE64_SOURCE -# ifndef _LARGEFILE_SOURCE -# define _LARGEFILE_SOURCE 1 -# endif -# undef _FILE_OFFSET_BITS -# undef _TIME_BITS -#endif - -#ifdef HAVE_HIDDEN -# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) -#else -# define ZLIB_INTERNAL -#endif - -#include -#include "zlib.h" -#ifdef STDC -# include -# include -# include -#endif - -#ifndef _POSIX_SOURCE -# define _POSIX_SOURCE -#endif -#include - -#ifdef _WIN32 -# include -#endif - -#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) -# include -#endif - -#if defined(_WIN32) -# define WIDECHAR -#endif - -#ifdef WINAPI_FAMILY -# define open _open -# define read _read -# define write _write -# define close _close -#endif - -#ifdef NO_DEFLATE /* for compatibility with old definition */ -# define NO_GZCOMPRESS -#endif - -#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#if defined(__CYGWIN__) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#ifndef HAVE_VSNPRINTF -# ifdef MSDOS -/* vsnprintf may exist on some MS-DOS compilers (DJGPP?), - but for now we just assume it doesn't. */ -# define NO_vsnprintf -# endif -# ifdef __TURBOC__ -# define NO_vsnprintf -# endif -# ifdef WIN32 -/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ -# if !defined(vsnprintf) && !defined(NO_vsnprintf) -# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) -# define vsnprintf _vsnprintf -# endif -# endif -# endif -# ifdef __SASC -# define NO_vsnprintf -# endif -# ifdef VMS -# define NO_vsnprintf -# endif -# ifdef __OS400__ -# define NO_vsnprintf -# endif -# ifdef __MVS__ -# define NO_vsnprintf -# endif -#endif - -/* unlike snprintf (which is required in C99), _snprintf does not guarantee - null termination of the result -- however this is only used in gzlib.c where - the result is assured to fit in the space provided */ -#if defined(_MSC_VER) && _MSC_VER < 1900 -# define snprintf _snprintf -#endif - -#ifndef local -# define local static -#endif -/* since "static" is used to mean two completely different things in C, we - define "local" for the non-static meaning of "static", for readability - (compile with -Dlocal if your debugger can't find static symbols) */ - -/* gz* functions always use library allocation functions */ -#ifndef STDC - extern voidp malloc(uInt size); - extern void free(voidpf ptr); -#endif - -/* get errno and strerror definition */ -#if defined UNDER_CE -# include -# define zstrerror() gz_strwinerror((DWORD)GetLastError()) -#else -# ifndef NO_STRERROR -# include -# define zstrerror() strerror(errno) -# else -# define zstrerror() "stdio error (consult errno)" -# endif -#endif - -/* provide prototypes for these when building zlib without LFS */ -#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 - ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); - ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); - ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); - ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); -#endif - -/* default memLevel */ -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif - -/* default i/o buffer size -- double this for output when reading (this and - twice this must be able to fit in an unsigned type) */ -#define GZBUFSIZE 8192 - -/* gzip modes, also provide a little integrity check on the passed structure */ -#define GZ_NONE 0 -#define GZ_READ 7247 -#define GZ_WRITE 31153 -#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ - -/* values for gz_state how */ -#define LOOK 0 /* look for a gzip header */ -#define COPY 1 /* copy input directly */ -#define GZIP 2 /* decompress a gzip stream */ - -/* internal gzip file state data structure */ -typedef struct { - /* exposed contents for gzgetc() macro */ - struct gzFile_s x; /* "x" for exposed */ - /* x.have: number of bytes available at x.next */ - /* x.next: next output data to deliver or write */ - /* x.pos: current position in uncompressed data */ - /* used for both reading and writing */ - int mode; /* see gzip modes above */ - int fd; /* file descriptor */ - char *path; /* path or fd for error messages */ - unsigned size; /* buffer size, zero if not allocated yet */ - unsigned want; /* requested buffer size, default is GZBUFSIZE */ - unsigned char *in; /* input buffer (double-sized when writing) */ - unsigned char *out; /* output buffer (double-sized when reading) */ - int direct; /* 0 if processing gzip, 1 if transparent */ - /* just for reading */ - int how; /* 0: get header, 1: copy, 2: decompress */ - z_off64_t start; /* where the gzip data started, for rewinding */ - int eof; /* true if end of input file reached */ - int past; /* true if read requested past end */ - /* just for writing */ - int level; /* compression level */ - int strategy; /* compression strategy */ - int reset; /* true if a reset is pending after a Z_FINISH */ - /* seek request */ - z_off64_t skip; /* amount to skip (already rewound if backwards) */ - int seek; /* true if seek request pending */ - /* error information */ - int err; /* error code */ - char *msg; /* error message */ - /* zlib inflate or deflate stream */ - z_stream strm; /* stream structure in-place (not a pointer) */ -} gz_state; -typedef gz_state FAR *gz_statep; - -/* shared functions */ -void ZLIB_INTERNAL gz_error(gz_statep, int, const char *); -#if defined UNDER_CE -char ZLIB_INTERNAL *gz_strwinerror(DWORD error); -#endif - -/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t - value -- needed when comparing unsigned to z_off64_t, which is signed - (possible z_off64_t types off_t, off64_t, and long are all signed) */ -unsigned ZLIB_INTERNAL gz_intmax(void); -#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/infback.c b/vendor/libgit2-sys/libgit2/deps/zlib/infback.c deleted file mode 100644 index e7b25b3..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/infback.c +++ /dev/null @@ -1,628 +0,0 @@ -/* infback.c -- inflate using a call-back interface - * Copyright (C) 1995-2022 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - This code is largely copied from inflate.c. Normally either infback.o or - inflate.o would be linked into an application--not both. The interface - with inffast.c is retained so that optimized assembler-coded versions of - inflate_fast() can be used with either inflate.c or infback.c. - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -/* - strm provides memory allocation functions in zalloc and zfree, or - Z_NULL to use the library memory allocation functions. - - windowBits is in the range 8..15, and window is a user-supplied - window and output buffer that is 2**windowBits bytes. - */ -int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, - unsigned char FAR *window, const char *version, - int stream_size) { - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL || window == Z_NULL || - windowBits < 8 || windowBits > 15) - return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - state = (struct inflate_state FAR *)ZALLOC(strm, 1, - sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; - state->dmax = 32768U; - state->wbits = (uInt)windowBits; - state->wsize = 1U << windowBits; - state->window = window; - state->wnext = 0; - state->whave = 0; - state->sane = 1; - return Z_OK; -} - -/* - Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. - */ -local void fixedtables(struct inflate_state FAR *state) { -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#else /* !BUILDFIXED */ -# include "inffixed.h" -#endif /* BUILDFIXED */ - state->lencode = lenfix; - state->lenbits = 9; - state->distcode = distfix; - state->distbits = 5; -} - -/* Macros for inflateBack(): */ - -/* Load returned state from inflate_fast() */ -#define LOAD() \ - do { \ - put = strm->next_out; \ - left = strm->avail_out; \ - next = strm->next_in; \ - have = strm->avail_in; \ - hold = state->hold; \ - bits = state->bits; \ - } while (0) - -/* Set state from registers for inflate_fast() */ -#define RESTORE() \ - do { \ - strm->next_out = put; \ - strm->avail_out = left; \ - strm->next_in = next; \ - strm->avail_in = have; \ - state->hold = hold; \ - state->bits = bits; \ - } while (0) - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Assure that some input is available. If input is requested, but denied, - then return a Z_BUF_ERROR from inflateBack(). */ -#define PULL() \ - do { \ - if (have == 0) { \ - have = in(in_desc, &next); \ - if (have == 0) { \ - next = Z_NULL; \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflateBack() - with an error if there is no input available. */ -#define PULLBYTE() \ - do { \ - PULL(); \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflateBack() with - an error. */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n < 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* Assure that some output space is available, by writing out the window - if it's full. If the write fails, return from inflateBack() with a - Z_BUF_ERROR. */ -#define ROOM() \ - do { \ - if (left == 0) { \ - put = state->window; \ - left = state->wsize; \ - state->whave = left; \ - if (out(out_desc, put, left)) { \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* - strm provides the memory allocation functions and window buffer on input, - and provides information on the unused input on return. For Z_DATA_ERROR - returns, strm will also provide an error message. - - in() and out() are the call-back input and output functions. When - inflateBack() needs more input, it calls in(). When inflateBack() has - filled the window with output, or when it completes with data in the - window, it calls out() to write out the data. The application must not - change the provided input until in() is called again or inflateBack() - returns. The application must not change the window/output buffer until - inflateBack() returns. - - in() and out() are called with a descriptor parameter provided in the - inflateBack() call. This parameter can be a structure that provides the - information required to do the read or write, as well as accumulated - information on the input and output such as totals and check values. - - in() should return zero on failure. out() should return non-zero on - failure. If either in() or out() fails, than inflateBack() returns a - Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it - was in() or out() that caused in the error. Otherwise, inflateBack() - returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format - error, or Z_MEM_ERROR if it could not allocate memory for the state. - inflateBack() can also return Z_STREAM_ERROR if the input parameters - are not correct, i.e. strm is Z_NULL or the state was not initialized. - */ -int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc) { - struct inflate_state FAR *state; - z_const unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have, left; /* available input and output */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - /* Check that the strm exists and that the state was initialized */ - if (strm == Z_NULL || strm->state == Z_NULL) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* Reset the state */ - strm->msg = Z_NULL; - state->mode = TYPE; - state->last = 0; - state->whave = 0; - next = strm->next_in; - have = next != Z_NULL ? strm->avail_in : 0; - hold = 0; - bits = 0; - put = state->window; - left = state->wsize; - - /* Inflate until end of block marked as last */ - for (;;) - switch (state->mode) { - case TYPE: - /* determine and dispatch block type */ - if (state->last) { - BYTEBITS(); - state->mode = DONE; - break; - } - NEEDBITS(3); - state->last = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - state->last ? " (last)" : "")); - state->mode = STORED; - break; - case 1: /* fixed block */ - fixedtables(state); - Tracev((stderr, "inflate: fixed codes block%s\n", - state->last ? " (last)" : "")); - state->mode = LEN; /* decode codes */ - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - state->last ? " (last)" : "")); - state->mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - state->mode = BAD; - } - DROPBITS(2); - break; - - case STORED: - /* get and verify stored block length */ - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - state->mode = BAD; - break; - } - state->length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %u\n", - state->length)); - INITBITS(); - - /* copy stored block from input to output */ - while (state->length != 0) { - copy = state->length; - PULL(); - ROOM(); - if (copy > have) copy = have; - if (copy > left) copy = left; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - state->length -= copy; - } - Tracev((stderr, "inflate: stored end\n")); - state->mode = TYPE; - break; - - case TABLE: - /* get dynamic table entries descriptor */ - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); -#ifndef PKZIP_BUG_WORKAROUND - if (state->nlen > 286 || state->ndist > 30) { - strm->msg = (char *)"too many length or distance symbols"; - state->mode = BAD; - break; - } -#endif - Tracev((stderr, "inflate: table sizes ok\n")); - - /* get code length code lengths (not a typo) */ - state->have = 0; - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 7; - ret = inflate_table(CODES, state->lens, 19, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - - /* get length and distance code code lengths */ - state->have = 0; - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - len = (unsigned)(state->lens[state->have - 1]); - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (state->mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - state->mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 9; - ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - state->mode = BAD; - break; - } - state->distcode = (code const FAR *)(state->next); - state->distbits = 6; - ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, - &(state->next), &(state->distbits), state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - state->mode = LEN; - /* fallthrough */ - - case LEN: - /* use inflate_fast() if we have enough input and output */ - if (have >= 6 && left >= 258) { - RESTORE(); - if (state->whave < state->wsize) - state->whave = state->wsize - left; - inflate_fast(strm, state->wsize); - LOAD(); - break; - } - - /* get a literal, length, or end-of-block code */ - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - state->length = (unsigned)here.val; - - /* process literal */ - if (here.op == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - ROOM(); - *put++ = (unsigned char)(state->length); - left--; - state->mode = LEN; - break; - } - - /* process end of block */ - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - state->mode = TYPE; - break; - } - - /* invalid code */ - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - - /* length code -- get extra bits, if any */ - state->extra = (unsigned)(here.op) & 15; - if (state->extra != 0) { - NEEDBITS(state->extra); - state->length += BITS(state->extra); - DROPBITS(state->extra); - } - Tracevv((stderr, "inflate: length %u\n", state->length)); - - /* get distance code */ - for (;;) { - here = state->distcode[BITS(state->distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - state->offset = (unsigned)here.val; - - /* get distance extra bits, if any */ - state->extra = (unsigned)(here.op) & 15; - if (state->extra != 0) { - NEEDBITS(state->extra); - state->offset += BITS(state->extra); - DROPBITS(state->extra); - } - if (state->offset > state->wsize - (state->whave < state->wsize ? - left : 0)) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } - Tracevv((stderr, "inflate: distance %u\n", state->offset)); - - /* copy match from window to output */ - do { - ROOM(); - copy = state->wsize - state->offset; - if (copy < left) { - from = put + copy; - copy = left - copy; - } - else { - from = put - state->offset; - copy = left; - } - if (copy > state->length) copy = state->length; - state->length -= copy; - left -= copy; - do { - *put++ = *from++; - } while (--copy); - } while (state->length != 0); - break; - - case DONE: - /* inflate stream terminated properly */ - ret = Z_STREAM_END; - goto inf_leave; - - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - - default: - /* can't happen, but makes compilers happy */ - ret = Z_STREAM_ERROR; - goto inf_leave; - } - - /* Write leftover output and return unused input */ - inf_leave: - if (left < state->wsize) { - if (out(out_desc, state->window, state->wsize - left) && - ret == Z_STREAM_END) - ret = Z_BUF_ERROR; - } - strm->next_in = next; - strm->avail_in = have; - return ret; -} - -int ZEXPORT inflateBackEnd(z_streamp strm) { - if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) - return Z_STREAM_ERROR; - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/inffast.c b/vendor/libgit2-sys/libgit2/deps/zlib/inffast.c deleted file mode 100644 index 9354676..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/inffast.c +++ /dev/null @@ -1,320 +0,0 @@ -/* inffast.c -- fast decoding - * Copyright (C) 1995-2017 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -#ifdef ASMINF -# pragma message("Assembler code may have bugs -- use at your own risk") -#else - -/* - Decode literal, length, and distance codes and write out the resulting - literal and match bytes until either not enough input or output is - available, an end-of-block is encountered, or a data error is encountered. - When large enough input and output buffers are supplied to inflate(), for - example, a 16K input buffer and a 64K output buffer, more than 95% of the - inflate execution time is spent in this routine. - - Entry assumptions: - - state->mode == LEN - strm->avail_in >= 6 - strm->avail_out >= 258 - start >= strm->avail_out - state->bits < 8 - - On return, state->mode is one of: - - LEN -- ran out of enough output space or enough available input - TYPE -- reached end of block code, inflate() to interpret next block - BAD -- error in block data - - Notes: - - - The maximum input bits used by a length/distance pair is 15 bits for the - length code, 5 bits for the length extra, 15 bits for the distance code, - and 13 bits for the distance extra. This totals 48 bits, or six bytes. - Therefore if strm->avail_in >= 6, then there is enough input to avoid - checking for available input while decoding. - - - The maximum bytes that a single length/distance pair can output is 258 - bytes, which is the maximum length that can be coded. inflate_fast() - requires strm->avail_out >= 258 for each loop to avoid checking for - output space. - */ -void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { - struct inflate_state FAR *state; - z_const unsigned char FAR *in; /* local strm->next_in */ - z_const unsigned char FAR *last; /* have enough input while in < last */ - unsigned char FAR *out; /* local strm->next_out */ - unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ - unsigned char FAR *end; /* while out < end, enough space available */ -#ifdef INFLATE_STRICT - unsigned dmax; /* maximum distance from zlib header */ -#endif - unsigned wsize; /* window size or zero if not using window */ - unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ - unsigned long hold; /* local strm->hold */ - unsigned bits; /* local strm->bits */ - code const FAR *lcode; /* local strm->lencode */ - code const FAR *dcode; /* local strm->distcode */ - unsigned lmask; /* mask for first level of length codes */ - unsigned dmask; /* mask for first level of distance codes */ - code const *here; /* retrieved table entry */ - unsigned op; /* code bits, operation, extra bits, or */ - /* window position, window bytes to copy */ - unsigned len; /* match length, unused bytes */ - unsigned dist; /* match distance */ - unsigned char FAR *from; /* where to copy match from */ - - /* copy state to local variables */ - state = (struct inflate_state FAR *)strm->state; - in = strm->next_in; - last = in + (strm->avail_in - 5); - out = strm->next_out; - beg = out - (start - strm->avail_out); - end = out + (strm->avail_out - 257); -#ifdef INFLATE_STRICT - dmax = state->dmax; -#endif - wsize = state->wsize; - whave = state->whave; - wnext = state->wnext; - window = state->window; - hold = state->hold; - bits = state->bits; - lcode = state->lencode; - dcode = state->distcode; - lmask = (1U << state->lenbits) - 1; - dmask = (1U << state->distbits) - 1; - - /* decode literals and length/distances until end-of-block or not enough - input data or output space */ - do { - if (bits < 15) { - hold += (unsigned long)(*in++) << bits; - bits += 8; - hold += (unsigned long)(*in++) << bits; - bits += 8; - } - here = lcode + (hold & lmask); - dolen: - op = (unsigned)(here->bits); - hold >>= op; - bits -= op; - op = (unsigned)(here->op); - if (op == 0) { /* literal */ - Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here->val)); - *out++ = (unsigned char)(here->val); - } - else if (op & 16) { /* length base */ - len = (unsigned)(here->val); - op &= 15; /* number of extra bits */ - if (op) { - if (bits < op) { - hold += (unsigned long)(*in++) << bits; - bits += 8; - } - len += (unsigned)hold & ((1U << op) - 1); - hold >>= op; - bits -= op; - } - Tracevv((stderr, "inflate: length %u\n", len)); - if (bits < 15) { - hold += (unsigned long)(*in++) << bits; - bits += 8; - hold += (unsigned long)(*in++) << bits; - bits += 8; - } - here = dcode + (hold & dmask); - dodist: - op = (unsigned)(here->bits); - hold >>= op; - bits -= op; - op = (unsigned)(here->op); - if (op & 16) { /* distance base */ - dist = (unsigned)(here->val); - op &= 15; /* number of extra bits */ - if (bits < op) { - hold += (unsigned long)(*in++) << bits; - bits += 8; - if (bits < op) { - hold += (unsigned long)(*in++) << bits; - bits += 8; - } - } - dist += (unsigned)hold & ((1U << op) - 1); -#ifdef INFLATE_STRICT - if (dist > dmax) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#endif - hold >>= op; - bits -= op; - Tracevv((stderr, "inflate: distance %u\n", dist)); - op = (unsigned)(out - beg); /* max distance in output */ - if (dist > op) { /* see if copy from window */ - op = dist - op; /* distance back in window */ - if (op > whave) { - if (state->sane) { - strm->msg = - (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - if (len <= op - whave) { - do { - *out++ = 0; - } while (--len); - continue; - } - len -= op - whave; - do { - *out++ = 0; - } while (--op > whave); - if (op == 0) { - from = out - dist; - do { - *out++ = *from++; - } while (--len); - continue; - } -#endif - } - from = window; - if (wnext == 0) { /* very common case */ - from += wsize - op; - if (op < len) { /* some from window */ - len -= op; - do { - *out++ = *from++; - } while (--op); - from = out - dist; /* rest from output */ - } - } - else if (wnext < op) { /* wrap around window */ - from += wsize + wnext - op; - op -= wnext; - if (op < len) { /* some from end of window */ - len -= op; - do { - *out++ = *from++; - } while (--op); - from = window; - if (wnext < len) { /* some from start of window */ - op = wnext; - len -= op; - do { - *out++ = *from++; - } while (--op); - from = out - dist; /* rest from output */ - } - } - } - else { /* contiguous in window */ - from += wnext - op; - if (op < len) { /* some from window */ - len -= op; - do { - *out++ = *from++; - } while (--op); - from = out - dist; /* rest from output */ - } - } - while (len > 2) { - *out++ = *from++; - *out++ = *from++; - *out++ = *from++; - len -= 3; - } - if (len) { - *out++ = *from++; - if (len > 1) - *out++ = *from++; - } - } - else { - from = out - dist; /* copy direct from output */ - do { /* minimum length is three */ - *out++ = *from++; - *out++ = *from++; - *out++ = *from++; - len -= 3; - } while (len > 2); - if (len) { - *out++ = *from++; - if (len > 1) - *out++ = *from++; - } - } - } - else if ((op & 64) == 0) { /* 2nd level distance code */ - here = dcode + here->val + (hold & ((1U << op) - 1)); - goto dodist; - } - else { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - } - else if ((op & 64) == 0) { /* 2nd level length code */ - here = lcode + here->val + (hold & ((1U << op) - 1)); - goto dolen; - } - else if (op & 32) { /* end-of-block */ - Tracevv((stderr, "inflate: end of block\n")); - state->mode = TYPE; - break; - } - else { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - } while (in < last && out < end); - - /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ - len = bits >> 3; - in -= len; - bits -= len << 3; - hold &= (1U << bits) - 1; - - /* update state and return */ - strm->next_in = in; - strm->next_out = out; - strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); - strm->avail_out = (unsigned)(out < end ? - 257 + (end - out) : 257 - (out - end)); - state->hold = hold; - state->bits = bits; - return; -} - -/* - inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): - - Using bit fields for code structure - - Different op definition to avoid & for extra bits (do & for table bits) - - Three separate decoding do-loops for direct, window, and wnext == 0 - - Special case for distance > 1 copies to do overlapped load and store copy - - Explicit branch predictions (based on measured branch probabilities) - - Deferring match copy and interspersed it with decoding subsequent codes - - Swapping literal/length else - - Swapping window/direct else - - Larger unrolled copy loops (three is about right) - - Moving len -= 3 statement into middle of loop - */ - -#endif /* !ASMINF */ diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/inffast.h b/vendor/libgit2-sys/libgit2/deps/zlib/inffast.h deleted file mode 100644 index 49c6d15..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/inffast.h +++ /dev/null @@ -1,11 +0,0 @@ -/* inffast.h -- header to use inffast.c - * Copyright (C) 1995-2003, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start); diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/inffixed.h b/vendor/libgit2-sys/libgit2/deps/zlib/inffixed.h deleted file mode 100644 index d628327..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/inffixed.h +++ /dev/null @@ -1,94 +0,0 @@ - /* inffixed.h -- table for decoding fixed codes - * Generated automatically by makefixed(). - */ - - /* WARNING: this file should *not* be used by applications. - It is part of the implementation of this library and is - subject to change. Applications should only use zlib.h. - */ - - static const code lenfix[512] = { - {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, - {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, - {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, - {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, - {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, - {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, - {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, - {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, - {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, - {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, - {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, - {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, - {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, - {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, - {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, - {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, - {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, - {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, - {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, - {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, - {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, - {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, - {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, - {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, - {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, - {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, - {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, - {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, - {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, - {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, - {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, - {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, - {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, - {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, - {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, - {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, - {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, - {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, - {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, - {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, - {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, - {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, - {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, - {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, - {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, - {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, - {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, - {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, - {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, - {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, - {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, - {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, - {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, - {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, - {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, - {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, - {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, - {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, - {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, - {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, - {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, - {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, - {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, - {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, - {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, - {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, - {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, - {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, - {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, - {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, - {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, - {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, - {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, - {0,9,255} - }; - - static const code distfix[32] = { - {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, - {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, - {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, - {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, - {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, - {22,5,193},{64,5,0} - }; diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/inflate.c b/vendor/libgit2-sys/libgit2/deps/zlib/inflate.c deleted file mode 100644 index 94ecff0..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/inflate.c +++ /dev/null @@ -1,1526 +0,0 @@ -/* inflate.c -- zlib decompression - * Copyright (C) 1995-2022 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * Change history: - * - * 1.2.beta0 24 Nov 2002 - * - First version -- complete rewrite of inflate to simplify code, avoid - * creation of window when not needed, minimize use of window when it is - * needed, make inffast.c even faster, implement gzip decoding, and to - * improve code readability and style over the previous zlib inflate code - * - * 1.2.beta1 25 Nov 2002 - * - Use pointers for available input and output checking in inffast.c - * - Remove input and output counters in inffast.c - * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 - * - Remove unnecessary second byte pull from length extra in inffast.c - * - Unroll direct copy to three copies per loop in inffast.c - * - * 1.2.beta2 4 Dec 2002 - * - Change external routine names to reduce potential conflicts - * - Correct filename to inffixed.h for fixed tables in inflate.c - * - Make hbuf[] unsigned char to match parameter type in inflate.c - * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) - * to avoid negation problem on Alphas (64 bit) in inflate.c - * - * 1.2.beta3 22 Dec 2002 - * - Add comments on state->bits assertion in inffast.c - * - Add comments on op field in inftrees.h - * - Fix bug in reuse of allocated window after inflateReset() - * - Remove bit fields--back to byte structure for speed - * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths - * - Change post-increments to pre-increments in inflate_fast(), PPC biased? - * - Add compile time option, POSTINC, to use post-increments instead (Intel?) - * - Make MATCH copy in inflate() much faster for when inflate_fast() not used - * - Use local copies of stream next and avail values, as well as local bit - * buffer and bit count in inflate()--for speed when inflate_fast() not used - * - * 1.2.beta4 1 Jan 2003 - * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings - * - Move a comment on output buffer sizes from inffast.c to inflate.c - * - Add comments in inffast.c to introduce the inflate_fast() routine - * - Rearrange window copies in inflate_fast() for speed and simplification - * - Unroll last copy for window match in inflate_fast() - * - Use local copies of window variables in inflate_fast() for speed - * - Pull out common wnext == 0 case for speed in inflate_fast() - * - Make op and len in inflate_fast() unsigned for consistency - * - Add FAR to lcode and dcode declarations in inflate_fast() - * - Simplified bad distance check in inflate_fast() - * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new - * source file infback.c to provide a call-back interface to inflate for - * programs like gzip and unzip -- uses window as output buffer to avoid - * window copying - * - * 1.2.beta5 1 Jan 2003 - * - Improved inflateBack() interface to allow the caller to provide initial - * input in strm. - * - Fixed stored blocks bug in inflateBack() - * - * 1.2.beta6 4 Jan 2003 - * - Added comments in inffast.c on effectiveness of POSTINC - * - Typecasting all around to reduce compiler warnings - * - Changed loops from while (1) or do {} while (1) to for (;;), again to - * make compilers happy - * - Changed type of window in inflateBackInit() to unsigned char * - * - * 1.2.beta7 27 Jan 2003 - * - Changed many types to unsigned or unsigned short to avoid warnings - * - Added inflateCopy() function - * - * 1.2.0 9 Mar 2003 - * - Changed inflateBack() interface to provide separate opaque descriptors - * for the in() and out() functions - * - Changed inflateBack() argument and in_func typedef to swap the length - * and buffer address return values for the input function - * - Check next_in and next_out for Z_NULL on entry to inflate() - * - * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -#ifdef MAKEFIXED -# ifndef BUILDFIXED -# define BUILDFIXED -# endif -#endif - -local int inflateStateCheck(z_streamp strm) { - struct inflate_state FAR *state; - if (strm == Z_NULL || - strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) - return 1; - state = (struct inflate_state FAR *)strm->state; - if (state == Z_NULL || state->strm != strm || - state->mode < HEAD || state->mode > SYNC) - return 1; - return 0; -} - -int ZEXPORT inflateResetKeep(z_streamp strm) { - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - strm->total_in = strm->total_out = state->total = 0; - strm->msg = Z_NULL; - if (state->wrap) /* to support ill-conceived Java test suite */ - strm->adler = state->wrap & 1; - state->mode = HEAD; - state->last = 0; - state->havedict = 0; - state->flags = -1; - state->dmax = 32768U; - state->head = Z_NULL; - state->hold = 0; - state->bits = 0; - state->lencode = state->distcode = state->next = state->codes; - state->sane = 1; - state->back = -1; - Tracev((stderr, "inflate: reset\n")); - return Z_OK; -} - -int ZEXPORT inflateReset(z_streamp strm) { - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - state->wsize = 0; - state->whave = 0; - state->wnext = 0; - return inflateResetKeep(strm); -} - -int ZEXPORT inflateReset2(z_streamp strm, int windowBits) { - int wrap; - struct inflate_state FAR *state; - - /* get the state */ - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* extract wrap request from windowBits parameter */ - if (windowBits < 0) { - if (windowBits < -15) - return Z_STREAM_ERROR; - wrap = 0; - windowBits = -windowBits; - } - else { - wrap = (windowBits >> 4) + 5; -#ifdef GUNZIP - if (windowBits < 48) - windowBits &= 15; -#endif - } - - /* set number of window bits, free window if different */ - if (windowBits && (windowBits < 8 || windowBits > 15)) - return Z_STREAM_ERROR; - if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { - ZFREE(strm, state->window); - state->window = Z_NULL; - } - - /* update state and reset the rest of it */ - state->wrap = wrap; - state->wbits = (unsigned)windowBits; - return inflateReset(strm); -} - -int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, - const char *version, int stream_size) { - int ret; - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL) return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - state = (struct inflate_state FAR *) - ZALLOC(strm, 1, sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; - state->strm = strm; - state->window = Z_NULL; - state->mode = HEAD; /* to pass state test in inflateReset2() */ - ret = inflateReset2(strm, windowBits); - if (ret != Z_OK) { - ZFREE(strm, state); - strm->state = Z_NULL; - } - return ret; -} - -int ZEXPORT inflateInit_(z_streamp strm, const char *version, - int stream_size) { - return inflateInit2_(strm, DEF_WBITS, version, stream_size); -} - -int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) { - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - if (bits == 0) - return Z_OK; - state = (struct inflate_state FAR *)strm->state; - if (bits < 0) { - state->hold = 0; - state->bits = 0; - return Z_OK; - } - if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR; - value &= (1L << bits) - 1; - state->hold += (unsigned)value << state->bits; - state->bits += (uInt)bits; - return Z_OK; -} - -/* - Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. - */ -local void fixedtables(struct inflate_state FAR *state) { -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#else /* !BUILDFIXED */ -# include "inffixed.h" -#endif /* BUILDFIXED */ - state->lencode = lenfix; - state->lenbits = 9; - state->distcode = distfix; - state->distbits = 5; -} - -#ifdef MAKEFIXED -#include - -/* - Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also - defines BUILDFIXED, so the tables are built on the fly. makefixed() writes - those tables to stdout, which would be piped to inffixed.h. A small program - can simply call makefixed to do this: - - void makefixed(void); - - int main(void) - { - makefixed(); - return 0; - } - - Then that can be linked with zlib built with MAKEFIXED defined and run: - - a.out > inffixed.h - */ -void makefixed(void) -{ - unsigned low, size; - struct inflate_state state; - - fixedtables(&state); - puts(" /* inffixed.h -- table for decoding fixed codes"); - puts(" * Generated automatically by makefixed()."); - puts(" */"); - puts(""); - puts(" /* WARNING: this file should *not* be used by applications."); - puts(" It is part of the implementation of this library and is"); - puts(" subject to change. Applications should only use zlib.h."); - puts(" */"); - puts(""); - size = 1U << 9; - printf(" static const code lenfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 7) == 0) printf("\n "); - printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, - state.lencode[low].bits, state.lencode[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); - size = 1U << 5; - printf("\n static const code distfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 6) == 0) printf("\n "); - printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, - state.distcode[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); -} -#endif /* MAKEFIXED */ - -/* - Update the window with the last wsize (normally 32K) bytes written before - returning. If window does not exist yet, create it. This is only called - when a window is already in use, or when output has been written during this - inflate call, but the end of the deflate stream has not been reached yet. - It is also called to create a window for dictionary data when a dictionary - is loaded. - - Providing output buffers larger than 32K to inflate() should provide a speed - advantage, since only the last 32K of output is copied to the sliding window - upon return from inflate(), and since all distances after the first 32K of - output will fall in the output data, making match copies simpler and faster. - The advantage may be dependent on the size of the processor's data caches. - */ -local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) { - struct inflate_state FAR *state; - unsigned dist; - - state = (struct inflate_state FAR *)strm->state; - - /* if it hasn't been done already, allocate space for the window */ - if (state->window == Z_NULL) { - state->window = (unsigned char FAR *) - ZALLOC(strm, 1U << state->wbits, - sizeof(unsigned char)); - if (state->window == Z_NULL) return 1; - } - - /* if window not in use yet, initialize */ - if (state->wsize == 0) { - state->wsize = 1U << state->wbits; - state->wnext = 0; - state->whave = 0; - } - - /* copy state->wsize or less output bytes into the circular window */ - if (copy >= state->wsize) { - zmemcpy(state->window, end - state->wsize, state->wsize); - state->wnext = 0; - state->whave = state->wsize; - } - else { - dist = state->wsize - state->wnext; - if (dist > copy) dist = copy; - zmemcpy(state->window + state->wnext, end - copy, dist); - copy -= dist; - if (copy) { - zmemcpy(state->window, end - copy, copy); - state->wnext = copy; - state->whave = state->wsize; - } - else { - state->wnext += dist; - if (state->wnext == state->wsize) state->wnext = 0; - if (state->whave < state->wsize) state->whave += dist; - } - } - return 0; -} - -/* Macros for inflate(): */ - -/* check function to use adler32() for zlib or crc32() for gzip */ -#ifdef GUNZIP -# define UPDATE_CHECK(check, buf, len) \ - (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) -#else -# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len) -#endif - -/* check macros for header crc */ -#ifdef GUNZIP -# define CRC2(check, word) \ - do { \ - hbuf[0] = (unsigned char)(word); \ - hbuf[1] = (unsigned char)((word) >> 8); \ - check = crc32(check, hbuf, 2); \ - } while (0) - -# define CRC4(check, word) \ - do { \ - hbuf[0] = (unsigned char)(word); \ - hbuf[1] = (unsigned char)((word) >> 8); \ - hbuf[2] = (unsigned char)((word) >> 16); \ - hbuf[3] = (unsigned char)((word) >> 24); \ - check = crc32(check, hbuf, 4); \ - } while (0) -#endif - -/* Load registers with state in inflate() for speed */ -#define LOAD() \ - do { \ - put = strm->next_out; \ - left = strm->avail_out; \ - next = strm->next_in; \ - have = strm->avail_in; \ - hold = state->hold; \ - bits = state->bits; \ - } while (0) - -/* Restore state from registers in inflate() */ -#define RESTORE() \ - do { \ - strm->next_out = put; \ - strm->avail_out = left; \ - strm->next_in = next; \ - strm->avail_in = have; \ - state->hold = hold; \ - state->bits = bits; \ - } while (0) - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflate() - if there is no input available. */ -#define PULLBYTE() \ - do { \ - if (have == 0) goto inf_leave; \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflate(). */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n < 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* - inflate() uses a state machine to process as much input data and generate as - much output data as possible before returning. The state machine is - structured roughly as follows: - - for (;;) switch (state) { - ... - case STATEn: - if (not enough input data or output space to make progress) - return; - ... make progress ... - state = STATEm; - break; - ... - } - - so when inflate() is called again, the same case is attempted again, and - if the appropriate resources are provided, the machine proceeds to the - next state. The NEEDBITS() macro is usually the way the state evaluates - whether it can proceed or should return. NEEDBITS() does the return if - the requested bits are not available. The typical use of the BITS macros - is: - - NEEDBITS(n); - ... do something with BITS(n) ... - DROPBITS(n); - - where NEEDBITS(n) either returns from inflate() if there isn't enough - input left to load n bits into the accumulator, or it continues. BITS(n) - gives the low n bits in the accumulator. When done, DROPBITS(n) drops - the low n bits off the accumulator. INITBITS() clears the accumulator - and sets the number of available bits to zero. BYTEBITS() discards just - enough bits to put the accumulator on a byte boundary. After BYTEBITS() - and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. - - NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return - if there is no input available. The decoding of variable length codes uses - PULLBYTE() directly in order to pull just enough bytes to decode the next - code, and no more. - - Some states loop until they get enough input, making sure that enough - state information is maintained to continue the loop where it left off - if NEEDBITS() returns in the loop. For example, want, need, and keep - would all have to actually be part of the saved state in case NEEDBITS() - returns: - - case STATEw: - while (want < need) { - NEEDBITS(n); - keep[want++] = BITS(n); - DROPBITS(n); - } - state = STATEx; - case STATEx: - - As shown above, if the next state is also the next case, then the break - is omitted. - - A state may also return if there is not enough output space available to - complete that state. Those states are copying stored data, writing a - literal byte, and copying a matching string. - - When returning, a "goto inf_leave" is used to update the total counters, - update the check value, and determine whether any progress has been made - during that inflate() call in order to return the proper return code. - Progress is defined as a change in either strm->avail_in or strm->avail_out. - When there is a window, goto inf_leave will update the window with the last - output written. If a goto inf_leave occurs in the middle of decompression - and there is no window currently, goto inf_leave will create one and copy - output to the window for the next call of inflate(). - - In this implementation, the flush parameter of inflate() only affects the - return code (per zlib.h). inflate() always writes as much as possible to - strm->next_out, given the space available and the provided input--the effect - documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers - the allocation of and copying into a sliding window until necessary, which - provides the effect documented in zlib.h for Z_FINISH when the entire input - stream available. So the only thing the flush parameter actually does is: - when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it - will return Z_BUF_ERROR if it has not reached the end of the stream. - */ - -int ZEXPORT inflate(z_streamp strm, int flush) { - struct inflate_state FAR *state; - z_const unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have, left; /* available input and output */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned in, out; /* save starting available input and output */ - unsigned copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ -#ifdef GUNZIP - unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ -#endif - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - if (inflateStateCheck(strm) || strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0)) - return Z_STREAM_ERROR; - - state = (struct inflate_state FAR *)strm->state; - if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ - LOAD(); - in = have; - out = left; - ret = Z_OK; - for (;;) - switch (state->mode) { - case HEAD: - if (state->wrap == 0) { - state->mode = TYPEDO; - break; - } - NEEDBITS(16); -#ifdef GUNZIP - if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ - if (state->wbits == 0) - state->wbits = 15; - state->check = crc32(0L, Z_NULL, 0); - CRC2(state->check, hold); - INITBITS(); - state->mode = FLAGS; - break; - } - if (state->head != Z_NULL) - state->head->done = -1; - if (!(state->wrap & 1) || /* check if zlib header allowed */ -#else - if ( -#endif - ((BITS(8) << 8) + (hold >> 8)) % 31) { - strm->msg = (char *)"incorrect header check"; - state->mode = BAD; - break; - } - if (BITS(4) != Z_DEFLATED) { - strm->msg = (char *)"unknown compression method"; - state->mode = BAD; - break; - } - DROPBITS(4); - len = BITS(4) + 8; - if (state->wbits == 0) - state->wbits = len; - if (len > 15 || len > state->wbits) { - strm->msg = (char *)"invalid window size"; - state->mode = BAD; - break; - } - state->dmax = 1U << len; - state->flags = 0; /* indicate zlib header */ - Tracev((stderr, "inflate: zlib header ok\n")); - strm->adler = state->check = adler32(0L, Z_NULL, 0); - state->mode = hold & 0x200 ? DICTID : TYPE; - INITBITS(); - break; -#ifdef GUNZIP - case FLAGS: - NEEDBITS(16); - state->flags = (int)(hold); - if ((state->flags & 0xff) != Z_DEFLATED) { - strm->msg = (char *)"unknown compression method"; - state->mode = BAD; - break; - } - if (state->flags & 0xe000) { - strm->msg = (char *)"unknown header flags set"; - state->mode = BAD; - break; - } - if (state->head != Z_NULL) - state->head->text = (int)((hold >> 8) & 1); - if ((state->flags & 0x0200) && (state->wrap & 4)) - CRC2(state->check, hold); - INITBITS(); - state->mode = TIME; - /* fallthrough */ - case TIME: - NEEDBITS(32); - if (state->head != Z_NULL) - state->head->time = hold; - if ((state->flags & 0x0200) && (state->wrap & 4)) - CRC4(state->check, hold); - INITBITS(); - state->mode = OS; - /* fallthrough */ - case OS: - NEEDBITS(16); - if (state->head != Z_NULL) { - state->head->xflags = (int)(hold & 0xff); - state->head->os = (int)(hold >> 8); - } - if ((state->flags & 0x0200) && (state->wrap & 4)) - CRC2(state->check, hold); - INITBITS(); - state->mode = EXLEN; - /* fallthrough */ - case EXLEN: - if (state->flags & 0x0400) { - NEEDBITS(16); - state->length = (unsigned)(hold); - if (state->head != Z_NULL) - state->head->extra_len = (unsigned)hold; - if ((state->flags & 0x0200) && (state->wrap & 4)) - CRC2(state->check, hold); - INITBITS(); - } - else if (state->head != Z_NULL) - state->head->extra = Z_NULL; - state->mode = EXTRA; - /* fallthrough */ - case EXTRA: - if (state->flags & 0x0400) { - copy = state->length; - if (copy > have) copy = have; - if (copy) { - if (state->head != Z_NULL && - state->head->extra != Z_NULL && - (len = state->head->extra_len - state->length) < - state->head->extra_max) { - zmemcpy(state->head->extra + len, next, - len + copy > state->head->extra_max ? - state->head->extra_max - len : copy); - } - if ((state->flags & 0x0200) && (state->wrap & 4)) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - state->length -= copy; - } - if (state->length) goto inf_leave; - } - state->length = 0; - state->mode = NAME; - /* fallthrough */ - case NAME: - if (state->flags & 0x0800) { - if (have == 0) goto inf_leave; - copy = 0; - do { - len = (unsigned)(next[copy++]); - if (state->head != Z_NULL && - state->head->name != Z_NULL && - state->length < state->head->name_max) - state->head->name[state->length++] = (Bytef)len; - } while (len && copy < have); - if ((state->flags & 0x0200) && (state->wrap & 4)) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - if (len) goto inf_leave; - } - else if (state->head != Z_NULL) - state->head->name = Z_NULL; - state->length = 0; - state->mode = COMMENT; - /* fallthrough */ - case COMMENT: - if (state->flags & 0x1000) { - if (have == 0) goto inf_leave; - copy = 0; - do { - len = (unsigned)(next[copy++]); - if (state->head != Z_NULL && - state->head->comment != Z_NULL && - state->length < state->head->comm_max) - state->head->comment[state->length++] = (Bytef)len; - } while (len && copy < have); - if ((state->flags & 0x0200) && (state->wrap & 4)) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - if (len) goto inf_leave; - } - else if (state->head != Z_NULL) - state->head->comment = Z_NULL; - state->mode = HCRC; - /* fallthrough */ - case HCRC: - if (state->flags & 0x0200) { - NEEDBITS(16); - if ((state->wrap & 4) && hold != (state->check & 0xffff)) { - strm->msg = (char *)"header crc mismatch"; - state->mode = BAD; - break; - } - INITBITS(); - } - if (state->head != Z_NULL) { - state->head->hcrc = (int)((state->flags >> 9) & 1); - state->head->done = 1; - } - strm->adler = state->check = crc32(0L, Z_NULL, 0); - state->mode = TYPE; - break; -#endif - case DICTID: - NEEDBITS(32); - strm->adler = state->check = ZSWAP32(hold); - INITBITS(); - state->mode = DICT; - /* fallthrough */ - case DICT: - if (state->havedict == 0) { - RESTORE(); - return Z_NEED_DICT; - } - strm->adler = state->check = adler32(0L, Z_NULL, 0); - state->mode = TYPE; - /* fallthrough */ - case TYPE: - if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; - /* fallthrough */ - case TYPEDO: - if (state->last) { - BYTEBITS(); - state->mode = CHECK; - break; - } - NEEDBITS(3); - state->last = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - state->last ? " (last)" : "")); - state->mode = STORED; - break; - case 1: /* fixed block */ - fixedtables(state); - Tracev((stderr, "inflate: fixed codes block%s\n", - state->last ? " (last)" : "")); - state->mode = LEN_; /* decode codes */ - if (flush == Z_TREES) { - DROPBITS(2); - goto inf_leave; - } - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - state->last ? " (last)" : "")); - state->mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - state->mode = BAD; - } - DROPBITS(2); - break; - case STORED: - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - state->mode = BAD; - break; - } - state->length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %u\n", - state->length)); - INITBITS(); - state->mode = COPY_; - if (flush == Z_TREES) goto inf_leave; - /* fallthrough */ - case COPY_: - state->mode = COPY; - /* fallthrough */ - case COPY: - copy = state->length; - if (copy) { - if (copy > have) copy = have; - if (copy > left) copy = left; - if (copy == 0) goto inf_leave; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - state->length -= copy; - break; - } - Tracev((stderr, "inflate: stored end\n")); - state->mode = TYPE; - break; - case TABLE: - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); -#ifndef PKZIP_BUG_WORKAROUND - if (state->nlen > 286 || state->ndist > 30) { - strm->msg = (char *)"too many length or distance symbols"; - state->mode = BAD; - break; - } -#endif - Tracev((stderr, "inflate: table sizes ok\n")); - state->have = 0; - state->mode = LENLENS; - /* fallthrough */ - case LENLENS: - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - state->lencode = (const code FAR *)(state->next); - state->lenbits = 7; - ret = inflate_table(CODES, state->lens, 19, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - state->have = 0; - state->mode = CODELENS; - /* fallthrough */ - case CODELENS: - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - len = state->lens[state->have - 1]; - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (state->mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - state->mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - state->lencode = (const code FAR *)(state->next); - state->lenbits = 9; - ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - state->mode = BAD; - break; - } - state->distcode = (const code FAR *)(state->next); - state->distbits = 6; - ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, - &(state->next), &(state->distbits), state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - state->mode = LEN_; - if (flush == Z_TREES) goto inf_leave; - /* fallthrough */ - case LEN_: - state->mode = LEN; - /* fallthrough */ - case LEN: - if (have >= 6 && left >= 258) { - RESTORE(); - inflate_fast(strm, out); - LOAD(); - if (state->mode == TYPE) - state->back = -1; - break; - } - state->back = 0; - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - state->back += last.bits; - } - DROPBITS(here.bits); - state->back += here.bits; - state->length = (unsigned)here.val; - if ((int)(here.op) == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - state->mode = LIT; - break; - } - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - state->back = -1; - state->mode = TYPE; - break; - } - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - state->extra = (unsigned)(here.op) & 15; - state->mode = LENEXT; - /* fallthrough */ - case LENEXT: - if (state->extra) { - NEEDBITS(state->extra); - state->length += BITS(state->extra); - DROPBITS(state->extra); - state->back += state->extra; - } - Tracevv((stderr, "inflate: length %u\n", state->length)); - state->was = state->length; - state->mode = DIST; - /* fallthrough */ - case DIST: - for (;;) { - here = state->distcode[BITS(state->distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - state->back += last.bits; - } - DROPBITS(here.bits); - state->back += here.bits; - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - state->offset = (unsigned)here.val; - state->extra = (unsigned)(here.op) & 15; - state->mode = DISTEXT; - /* fallthrough */ - case DISTEXT: - if (state->extra) { - NEEDBITS(state->extra); - state->offset += BITS(state->extra); - DROPBITS(state->extra); - state->back += state->extra; - } -#ifdef INFLATE_STRICT - if (state->offset > state->dmax) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#endif - Tracevv((stderr, "inflate: distance %u\n", state->offset)); - state->mode = MATCH; - /* fallthrough */ - case MATCH: - if (left == 0) goto inf_leave; - copy = out - left; - if (state->offset > copy) { /* copy from window */ - copy = state->offset - copy; - if (copy > state->whave) { - if (state->sane) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - Trace((stderr, "inflate.c too far\n")); - copy -= state->whave; - if (copy > state->length) copy = state->length; - if (copy > left) copy = left; - left -= copy; - state->length -= copy; - do { - *put++ = 0; - } while (--copy); - if (state->length == 0) state->mode = LEN; - break; -#endif - } - if (copy > state->wnext) { - copy -= state->wnext; - from = state->window + (state->wsize - copy); - } - else - from = state->window + (state->wnext - copy); - if (copy > state->length) copy = state->length; - } - else { /* copy from output */ - from = put - state->offset; - copy = state->length; - } - if (copy > left) copy = left; - left -= copy; - state->length -= copy; - do { - *put++ = *from++; - } while (--copy); - if (state->length == 0) state->mode = LEN; - break; - case LIT: - if (left == 0) goto inf_leave; - *put++ = (unsigned char)(state->length); - left--; - state->mode = LEN; - break; - case CHECK: - if (state->wrap) { - NEEDBITS(32); - out -= left; - strm->total_out += out; - state->total += out; - if ((state->wrap & 4) && out) - strm->adler = state->check = - UPDATE_CHECK(state->check, put - out, out); - out = left; - if ((state->wrap & 4) && ( -#ifdef GUNZIP - state->flags ? hold : -#endif - ZSWAP32(hold)) != state->check) { - strm->msg = (char *)"incorrect data check"; - state->mode = BAD; - break; - } - INITBITS(); - Tracev((stderr, "inflate: check matches trailer\n")); - } -#ifdef GUNZIP - state->mode = LENGTH; - /* fallthrough */ - case LENGTH: - if (state->wrap && state->flags) { - NEEDBITS(32); - if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) { - strm->msg = (char *)"incorrect length check"; - state->mode = BAD; - break; - } - INITBITS(); - Tracev((stderr, "inflate: length matches trailer\n")); - } -#endif - state->mode = DONE; - /* fallthrough */ - case DONE: - ret = Z_STREAM_END; - goto inf_leave; - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - case MEM: - return Z_MEM_ERROR; - case SYNC: - /* fallthrough */ - default: - return Z_STREAM_ERROR; - } - - /* - Return from inflate(), updating the total counts and the check value. - If there was no progress during the inflate() call, return a buffer - error. Call updatewindow() to create and/or update the window state. - Note: a memory error from inflate() is non-recoverable. - */ - inf_leave: - RESTORE(); - if (state->wsize || (out != strm->avail_out && state->mode < BAD && - (state->mode < CHECK || flush != Z_FINISH))) - if (updatewindow(strm, strm->next_out, out - strm->avail_out)) { - state->mode = MEM; - return Z_MEM_ERROR; - } - in -= strm->avail_in; - out -= strm->avail_out; - strm->total_in += in; - strm->total_out += out; - state->total += out; - if ((state->wrap & 4) && out) - strm->adler = state->check = - UPDATE_CHECK(state->check, strm->next_out - out, out); - strm->data_type = (int)state->bits + (state->last ? 64 : 0) + - (state->mode == TYPE ? 128 : 0) + - (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); - if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) - ret = Z_BUF_ERROR; - return ret; -} - -int ZEXPORT inflateEnd(z_streamp strm) { - struct inflate_state FAR *state; - if (inflateStateCheck(strm)) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (state->window != Z_NULL) ZFREE(strm, state->window); - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} - -int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, - uInt *dictLength) { - struct inflate_state FAR *state; - - /* check state */ - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* copy dictionary */ - if (state->whave && dictionary != Z_NULL) { - zmemcpy(dictionary, state->window + state->wnext, - state->whave - state->wnext); - zmemcpy(dictionary + state->whave - state->wnext, - state->window, state->wnext); - } - if (dictLength != Z_NULL) - *dictLength = state->whave; - return Z_OK; -} - -int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength) { - struct inflate_state FAR *state; - unsigned long dictid; - int ret; - - /* check state */ - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (state->wrap != 0 && state->mode != DICT) - return Z_STREAM_ERROR; - - /* check for correct dictionary identifier */ - if (state->mode == DICT) { - dictid = adler32(0L, Z_NULL, 0); - dictid = adler32(dictid, dictionary, dictLength); - if (dictid != state->check) - return Z_DATA_ERROR; - } - - /* copy dictionary to window using updatewindow(), which will amend the - existing dictionary if appropriate */ - ret = updatewindow(strm, dictionary + dictLength, dictLength); - if (ret) { - state->mode = MEM; - return Z_MEM_ERROR; - } - state->havedict = 1; - Tracev((stderr, "inflate: dictionary set\n")); - return Z_OK; -} - -int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) { - struct inflate_state FAR *state; - - /* check state */ - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; - - /* save header structure */ - state->head = head; - head->done = 0; - return Z_OK; -} - -/* - Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found - or when out of input. When called, *have is the number of pattern bytes - found in order so far, in 0..3. On return *have is updated to the new - state. If on return *have equals four, then the pattern was found and the - return value is how many bytes were read including the last byte of the - pattern. If *have is less than four, then the pattern has not been found - yet and the return value is len. In the latter case, syncsearch() can be - called again with more data and the *have state. *have is initialized to - zero for the first call. - */ -local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, - unsigned len) { - unsigned got; - unsigned next; - - got = *have; - next = 0; - while (next < len && got < 4) { - if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) - got++; - else if (buf[next]) - got = 0; - else - got = 4 - got; - next++; - } - *have = got; - return next; -} - -int ZEXPORT inflateSync(z_streamp strm) { - unsigned len; /* number of bytes to look at or looked at */ - int flags; /* temporary to save header status */ - unsigned long in, out; /* temporary to save total_in and total_out */ - unsigned char buf[4]; /* to restore bit buffer to byte string */ - struct inflate_state FAR *state; - - /* check parameters */ - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; - - /* if first time, start search in bit buffer */ - if (state->mode != SYNC) { - state->mode = SYNC; - state->hold >>= state->bits & 7; - state->bits -= state->bits & 7; - len = 0; - while (state->bits >= 8) { - buf[len++] = (unsigned char)(state->hold); - state->hold >>= 8; - state->bits -= 8; - } - state->have = 0; - syncsearch(&(state->have), buf, len); - } - - /* search available input */ - len = syncsearch(&(state->have), strm->next_in, strm->avail_in); - strm->avail_in -= len; - strm->next_in += len; - strm->total_in += len; - - /* return no joy or set up to restart inflate() on a new block */ - if (state->have != 4) return Z_DATA_ERROR; - if (state->flags == -1) - state->wrap = 0; /* if no header yet, treat as raw */ - else - state->wrap &= ~4; /* no point in computing a check value now */ - flags = state->flags; - in = strm->total_in; out = strm->total_out; - inflateReset(strm); - strm->total_in = in; strm->total_out = out; - state->flags = flags; - state->mode = TYPE; - return Z_OK; -} - -/* - Returns true if inflate is currently at the end of a block generated by - Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP - implementation to provide an additional safety check. PPP uses - Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored - block. When decompressing, PPP checks that at the end of input packet, - inflate is waiting for these length bytes. - */ -int ZEXPORT inflateSyncPoint(z_streamp strm) { - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - return state->mode == STORED && state->bits == 0; -} - -int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { - struct inflate_state FAR *state; - struct inflate_state FAR *copy; - unsigned char FAR *window; - unsigned wsize; - - /* check input */ - if (inflateStateCheck(source) || dest == Z_NULL) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)source->state; - - /* allocate space */ - copy = (struct inflate_state FAR *) - ZALLOC(source, 1, sizeof(struct inflate_state)); - if (copy == Z_NULL) return Z_MEM_ERROR; - window = Z_NULL; - if (state->window != Z_NULL) { - window = (unsigned char FAR *) - ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); - if (window == Z_NULL) { - ZFREE(source, copy); - return Z_MEM_ERROR; - } - } - - /* copy state */ - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); - copy->strm = dest; - if (state->lencode >= state->codes && - state->lencode <= state->codes + ENOUGH - 1) { - copy->lencode = copy->codes + (state->lencode - state->codes); - copy->distcode = copy->codes + (state->distcode - state->codes); - } - copy->next = copy->codes + (state->next - state->codes); - if (window != Z_NULL) { - wsize = 1U << state->wbits; - zmemcpy(window, state->window, wsize); - } - copy->window = window; - dest->state = (struct internal_state FAR *)copy; - return Z_OK; -} - -int ZEXPORT inflateUndermine(z_streamp strm, int subvert) { - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - state->sane = !subvert; - return Z_OK; -#else - (void)subvert; - state->sane = 1; - return Z_DATA_ERROR; -#endif -} - -int ZEXPORT inflateValidate(z_streamp strm, int check) { - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (check && state->wrap) - state->wrap |= 4; - else - state->wrap &= ~4; - return Z_OK; -} - -long ZEXPORT inflateMark(z_streamp strm) { - struct inflate_state FAR *state; - - if (inflateStateCheck(strm)) - return -(1L << 16); - state = (struct inflate_state FAR *)strm->state; - return (long)(((unsigned long)((long)state->back)) << 16) + - (state->mode == COPY ? state->length : - (state->mode == MATCH ? state->was - state->length : 0)); -} - -unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) { - struct inflate_state FAR *state; - if (inflateStateCheck(strm)) return (unsigned long)-1; - state = (struct inflate_state FAR *)strm->state; - return (unsigned long)(state->next - state->codes); -} diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/inflate.h b/vendor/libgit2-sys/libgit2/deps/zlib/inflate.h deleted file mode 100644 index f127b6b..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/inflate.h +++ /dev/null @@ -1,126 +0,0 @@ -/* inflate.h -- internal inflate state definition - * Copyright (C) 1995-2019 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer decoding by inflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip decoding - should be left enabled. */ -#ifndef NO_GZIP -# define GUNZIP -#endif - -/* Possible inflate modes between inflate() calls */ -typedef enum { - HEAD = 16180, /* i: waiting for magic header */ - FLAGS, /* i: waiting for method and flags (gzip) */ - TIME, /* i: waiting for modification time (gzip) */ - OS, /* i: waiting for extra flags and operating system (gzip) */ - EXLEN, /* i: waiting for extra length (gzip) */ - EXTRA, /* i: waiting for extra bytes (gzip) */ - NAME, /* i: waiting for end of file name (gzip) */ - COMMENT, /* i: waiting for end of comment (gzip) */ - HCRC, /* i: waiting for header crc (gzip) */ - DICTID, /* i: waiting for dictionary check value */ - DICT, /* waiting for inflateSetDictionary() call */ - TYPE, /* i: waiting for type bits, including last-flag bit */ - TYPEDO, /* i: same, but skip check to exit inflate on new block */ - STORED, /* i: waiting for stored size (length and complement) */ - COPY_, /* i/o: same as COPY below, but only first time in */ - COPY, /* i/o: waiting for input or output to copy stored block */ - TABLE, /* i: waiting for dynamic block table lengths */ - LENLENS, /* i: waiting for code length code lengths */ - CODELENS, /* i: waiting for length/lit and distance code lengths */ - LEN_, /* i: same as LEN below, but only first time in */ - LEN, /* i: waiting for length/lit/eob code */ - LENEXT, /* i: waiting for length extra bits */ - DIST, /* i: waiting for distance code */ - DISTEXT, /* i: waiting for distance extra bits */ - MATCH, /* o: waiting for output space to copy string */ - LIT, /* o: waiting for output space to write literal */ - CHECK, /* i: waiting for 32-bit check value */ - LENGTH, /* i: waiting for 32-bit length (gzip) */ - DONE, /* finished check, done -- remain here until reset */ - BAD, /* got a data error -- remain here until reset */ - MEM, /* got an inflate() memory error -- remain here until reset */ - SYNC /* looking for synchronization bytes to restart inflate() */ -} inflate_mode; - -/* - State transitions between above modes - - - (most modes can go to BAD or MEM on error -- not shown for clarity) - - Process header: - HEAD -> (gzip) or (zlib) or (raw) - (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> - HCRC -> TYPE - (zlib) -> DICTID or TYPE - DICTID -> DICT -> TYPE - (raw) -> TYPEDO - Read deflate blocks: - TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK - STORED -> COPY_ -> COPY -> TYPE - TABLE -> LENLENS -> CODELENS -> LEN_ - LEN_ -> LEN - Read deflate codes in fixed or dynamic block: - LEN -> LENEXT or LIT or TYPE - LENEXT -> DIST -> DISTEXT -> MATCH -> LEN - LIT -> LEN - Process trailer: - CHECK -> LENGTH -> DONE - */ - -/* State maintained between inflate() calls -- approximately 7K bytes, not - including the allocated sliding window, which is up to 32K bytes. */ -struct inflate_state { - z_streamp strm; /* pointer back to this zlib stream */ - inflate_mode mode; /* current inflate mode */ - int last; /* true if processing last block */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip, - bit 2 true to validate check value */ - int havedict; /* true if dictionary provided */ - int flags; /* gzip header method and flags, 0 if zlib, or - -1 if raw or no header yet */ - unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ - unsigned long check; /* protected copy of check value */ - unsigned long total; /* protected copy of output count */ - gz_headerp head; /* where to save gzip header information */ - /* sliding window */ - unsigned wbits; /* log base 2 of requested window size */ - unsigned wsize; /* window size or zero if not using window */ - unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if needed */ - /* bit accumulator */ - unsigned long hold; /* input bit accumulator */ - unsigned bits; /* number of bits in "in" */ - /* for string and stored block copying */ - unsigned length; /* literal or length of data to copy */ - unsigned offset; /* distance back to copy string from */ - /* for table and code decoding */ - unsigned extra; /* extra bits needed */ - /* fixed and dynamic code tables */ - code const FAR *lencode; /* starting table for length/literal codes */ - code const FAR *distcode; /* starting table for distance codes */ - unsigned lenbits; /* index bits for lencode */ - unsigned distbits; /* index bits for distcode */ - /* dynamic table building */ - unsigned ncode; /* number of code length code lengths */ - unsigned nlen; /* number of length code lengths */ - unsigned ndist; /* number of distance code lengths */ - unsigned have; /* number of code lengths in lens[] */ - code FAR *next; /* next available space in codes[] */ - unsigned short lens[320]; /* temporary storage for code lengths */ - unsigned short work[288]; /* work area for code table building */ - code codes[ENOUGH]; /* space for code tables */ - int sane; /* if false, allow invalid distance too far */ - int back; /* bits back of last unprocessed length/lit */ - unsigned was; /* initial length of match */ -}; diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/inftrees.c b/vendor/libgit2-sys/libgit2/deps/zlib/inftrees.c deleted file mode 100644 index 98cfe16..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/inftrees.c +++ /dev/null @@ -1,299 +0,0 @@ -/* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2024 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" - -#define MAXBITS 15 - -const char inflate_copyright[] = - " inflate 1.3.1 Copyright 1995-2024 Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* - Build a set of tables to decode the provided canonical Huffman code. - The code lengths are lens[0..codes-1]. The result starts at *table, - whose indices are 0..2^bits-1. work is a writable array of at least - lens shorts, which is used as a work area. type is the type of code - to be generated, CODES, LENS, or DISTS. On return, zero is success, - -1 is an invalid code, and +1 means that ENOUGH isn't enough. table - on return points to the next available entry's address. bits is the - requested root table index bits, and on return it is the actual root - table index bits. It will differ if the request is greater than the - longest code or if it is less than the shortest code. - */ -int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work) { - unsigned len; /* a code's length in bits */ - unsigned sym; /* index of code symbols */ - unsigned min, max; /* minimum and maximum code lengths */ - unsigned root; /* number of index bits for root table */ - unsigned curr; /* number of index bits for current table */ - unsigned drop; /* code bits to drop for sub-table */ - int left; /* number of prefix codes available */ - unsigned used; /* code entries in table used */ - unsigned huff; /* Huffman code */ - unsigned incr; /* for incrementing code, index */ - unsigned fill; /* index for replicating entries */ - unsigned low; /* low bits for current root entry */ - unsigned mask; /* mask for low root bits */ - code here; /* table entry for duplication */ - code FAR *next; /* next available space in table */ - const unsigned short FAR *base; /* base value table to use */ - const unsigned short FAR *extra; /* extra bits table to use */ - unsigned match; /* use base and extra for symbol >= match */ - unsigned short count[MAXBITS+1]; /* number of codes of each length */ - unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ - static const unsigned short lbase[31] = { /* Length codes 257..285 base */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; - static const unsigned short lext[31] = { /* Length codes 257..285 extra */ - 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 77}; - static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577, 0, 0}; - static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ - 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, - 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, - 28, 28, 29, 29, 64, 64}; - - /* - Process a set of code lengths to create a canonical Huffman code. The - code lengths are lens[0..codes-1]. Each length corresponds to the - symbols 0..codes-1. The Huffman code is generated by first sorting the - symbols by length from short to long, and retaining the symbol order - for codes with equal lengths. Then the code starts with all zero bits - for the first code of the shortest length, and the codes are integer - increments for the same length, and zeros are appended as the length - increases. For the deflate format, these bits are stored backwards - from their more natural integer increment ordering, and so when the - decoding tables are built in the large loop below, the integer codes - are incremented backwards. - - This routine assumes, but does not check, that all of the entries in - lens[] are in the range 0..MAXBITS. The caller must assure this. - 1..MAXBITS is interpreted as that code length. zero means that that - symbol does not occur in this code. - - The codes are sorted by computing a count of codes for each length, - creating from that a table of starting indices for each length in the - sorted table, and then entering the symbols in order in the sorted - table. The sorted table is work[], with that space being provided by - the caller. - - The length counts are used for other purposes as well, i.e. finding - the minimum and maximum length codes, determining if there are any - codes at all, checking for a valid set of lengths, and looking ahead - at length counts to determine sub-table sizes when building the - decoding tables. - */ - - /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ - for (len = 0; len <= MAXBITS; len++) - count[len] = 0; - for (sym = 0; sym < codes; sym++) - count[lens[sym]]++; - - /* bound code lengths, force root to be within code lengths */ - root = *bits; - for (max = MAXBITS; max >= 1; max--) - if (count[max] != 0) break; - if (root > max) root = max; - if (max == 0) { /* no symbols to code at all */ - here.op = (unsigned char)64; /* invalid code marker */ - here.bits = (unsigned char)1; - here.val = (unsigned short)0; - *(*table)++ = here; /* make a table to force an error */ - *(*table)++ = here; - *bits = 1; - return 0; /* no symbols, but wait for decoding to report error */ - } - for (min = 1; min < max; min++) - if (count[min] != 0) break; - if (root < min) root = min; - - /* check for an over-subscribed or incomplete set of lengths */ - left = 1; - for (len = 1; len <= MAXBITS; len++) { - left <<= 1; - left -= count[len]; - if (left < 0) return -1; /* over-subscribed */ - } - if (left > 0 && (type == CODES || max != 1)) - return -1; /* incomplete set */ - - /* generate offsets into symbol table for each length for sorting */ - offs[1] = 0; - for (len = 1; len < MAXBITS; len++) - offs[len + 1] = offs[len] + count[len]; - - /* sort symbols by length, by symbol order within each length */ - for (sym = 0; sym < codes; sym++) - if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; - - /* - Create and fill in decoding tables. In this loop, the table being - filled is at next and has curr index bits. The code being used is huff - with length len. That code is converted to an index by dropping drop - bits off of the bottom. For codes where len is less than drop + curr, - those top drop + curr - len bits are incremented through all values to - fill the table with replicated entries. - - root is the number of index bits for the root table. When len exceeds - root, sub-tables are created pointed to by the root entry with an index - of the low root bits of huff. This is saved in low to check for when a - new sub-table should be started. drop is zero when the root table is - being filled, and drop is root when sub-tables are being filled. - - When a new sub-table is needed, it is necessary to look ahead in the - code lengths to determine what size sub-table is needed. The length - counts are used for this, and so count[] is decremented as codes are - entered in the tables. - - used keeps track of how many table entries have been allocated from the - provided *table space. It is checked for LENS and DIST tables against - the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in - the initial root table size constants. See the comments in inftrees.h - for more information. - - sym increments through all symbols, and the loop terminates when - all codes of length max, i.e. all codes, have been processed. This - routine permits incomplete codes, so another loop after this one fills - in the rest of the decoding tables with invalid code markers. - */ - - /* set up for code type */ - switch (type) { - case CODES: - base = extra = work; /* dummy value--not used */ - match = 20; - break; - case LENS: - base = lbase; - extra = lext; - match = 257; - break; - default: /* DISTS */ - base = dbase; - extra = dext; - match = 0; - } - - /* initialize state for loop */ - huff = 0; /* starting code */ - sym = 0; /* starting code symbol */ - len = min; /* starting code length */ - next = *table; /* current table to fill in */ - curr = root; /* current table index bits */ - drop = 0; /* current bits to drop from code for index */ - low = (unsigned)(-1); /* trigger new sub-table when len > root */ - used = 1U << root; /* use root table entries */ - mask = used - 1; /* mask for comparing low */ - - /* check available table space */ - if ((type == LENS && used > ENOUGH_LENS) || - (type == DISTS && used > ENOUGH_DISTS)) - return 1; - - /* process all codes and make table entries */ - for (;;) { - /* create table entry */ - here.bits = (unsigned char)(len - drop); - if (work[sym] + 1U < match) { - here.op = (unsigned char)0; - here.val = work[sym]; - } - else if (work[sym] >= match) { - here.op = (unsigned char)(extra[work[sym] - match]); - here.val = base[work[sym] - match]; - } - else { - here.op = (unsigned char)(32 + 64); /* end of block */ - here.val = 0; - } - - /* replicate for those indices with low len bits equal to huff */ - incr = 1U << (len - drop); - fill = 1U << curr; - min = fill; /* save offset to next table */ - do { - fill -= incr; - next[(huff >> drop) + fill] = here; - } while (fill != 0); - - /* backwards increment the len-bit code huff */ - incr = 1U << (len - 1); - while (huff & incr) - incr >>= 1; - if (incr != 0) { - huff &= incr - 1; - huff += incr; - } - else - huff = 0; - - /* go to next symbol, update count, len */ - sym++; - if (--(count[len]) == 0) { - if (len == max) break; - len = lens[work[sym]]; - } - - /* create new sub-table if needed */ - if (len > root && (huff & mask) != low) { - /* if first time, transition to sub-tables */ - if (drop == 0) - drop = root; - - /* increment past last table */ - next += min; /* here min is 1 << curr */ - - /* determine length of next table */ - curr = len - drop; - left = (int)(1 << curr); - while (curr + drop < max) { - left -= count[curr + drop]; - if (left <= 0) break; - curr++; - left <<= 1; - } - - /* check for enough space */ - used += 1U << curr; - if ((type == LENS && used > ENOUGH_LENS) || - (type == DISTS && used > ENOUGH_DISTS)) - return 1; - - /* point entry in root table to sub-table */ - low = huff & mask; - (*table)[low].op = (unsigned char)curr; - (*table)[low].bits = (unsigned char)root; - (*table)[low].val = (unsigned short)(next - *table); - } - } - - /* fill in remaining table entry if code is incomplete (guaranteed to have - at most one remaining entry, since if the code is incomplete, the - maximum code length that was allowed to get this far is one bit) */ - if (huff != 0) { - here.op = (unsigned char)64; /* invalid code marker */ - here.bits = (unsigned char)(len - drop); - here.val = (unsigned short)0; - next[huff] = here; - } - - /* set return parameters */ - *table += used; - *bits = root; - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/inftrees.h b/vendor/libgit2-sys/libgit2/deps/zlib/inftrees.h deleted file mode 100644 index 396f74b..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/inftrees.h +++ /dev/null @@ -1,62 +0,0 @@ -/* inftrees.h -- header to use inftrees.c - * Copyright (C) 1995-2005, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* Structure for decoding tables. Each entry provides either the - information needed to do the operation requested by the code that - indexed that table entry, or it provides a pointer to another - table that indexes more bits of the code. op indicates whether - the entry is a pointer to another table, a literal, a length or - distance, an end-of-block, or an invalid code. For a table - pointer, the low four bits of op is the number of index bits of - that table. For a length or distance, the low four bits of op - is the number of extra bits to get after the code. bits is - the number of bits in this code or part of the code to drop off - of the bit buffer. val is the actual byte to output in the case - of a literal, the base length or distance, or the offset from - the current table to the next table. Each entry is four bytes. */ -typedef struct { - unsigned char op; /* operation, extra bits, table bits */ - unsigned char bits; /* bits in this part of the code */ - unsigned short val; /* offset in table or code value */ -} code; - -/* op values as set by inflate_table(): - 00000000 - literal - 0000tttt - table link, tttt != 0 is the number of table index bits - 0001eeee - length or distance, eeee is the number of extra bits - 01100000 - end of block - 01000000 - invalid code - */ - -/* Maximum size of the dynamic table. The maximum number of code structures is - 1444, which is the sum of 852 for literal/length codes and 592 for distance - codes. These values were found by exhaustive searches using the program - examples/enough.c found in the zlib distribution. The arguments to that - program are the number of symbols, the initial root table size, and the - maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns 852, and "enough 30 6 15" for distance codes returns 592. The - initial root table size (9 or 6) is found in the fifth argument of the - inflate_table() calls in inflate.c and infback.c. If the root table size is - changed, then these maximum sizes would be need to be recalculated and - updated. */ -#define ENOUGH_LENS 852 -#define ENOUGH_DISTS 592 -#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) - -/* Type of code to build for inflate_table() */ -typedef enum { - CODES, - LENS, - DISTS -} codetype; - -int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work); diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/trees.c b/vendor/libgit2-sys/libgit2/deps/zlib/trees.c deleted file mode 100644 index 6a523ef..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/trees.c +++ /dev/null @@ -1,1117 +0,0 @@ -/* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2024 Jean-loup Gailly - * detect_data_type() function provided freely by Cosmin Truta, 2006 - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process uses several Huffman trees. The more - * common source values are represented by shorter bit sequences. - * - * Each code tree is stored in a compressed form which is itself - * a Huffman encoding of the lengths of all the code strings (in - * ascending order by source values). The actual code strings are - * reconstructed from the lengths in the inflate process, as described - * in the deflate specification. - * - * REFERENCES - * - * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". - * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc - * - * Storer, James A. - * Data Compression: Methods and Theory, pp. 49-50. - * Computer Science Press, 1988. ISBN 0-7167-8156-5. - * - * Sedgewick, R. - * Algorithms, p290. - * Addison-Wesley, 1983. ISBN 0-201-06672-6. - */ - -/* @(#) $Id$ */ - -/* #define GEN_TREES_H */ - -#include "deflate.h" - -#ifdef ZLIB_DEBUG -# include -#endif - -/* =========================================================================== - * Constants - */ - -#define MAX_BL_BITS 7 -/* Bit length codes must not exceed MAX_BL_BITS bits */ - -#define END_BLOCK 256 -/* end of block literal code */ - -#define REP_3_6 16 -/* repeat previous bit length 3-6 times (2 bits of repeat count) */ - -#define REPZ_3_10 17 -/* repeat a zero length 3-10 times (3 bits of repeat count) */ - -#define REPZ_11_138 18 -/* repeat a zero length 11-138 times (7 bits of repeat count) */ - -local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ - = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; - -local const int extra_dbits[D_CODES] /* extra bits for each distance code */ - = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; - -local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ - = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; - -local const uch bl_order[BL_CODES] - = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; -/* The lengths of the bit length codes are sent in order of decreasing - * probability, to avoid transmitting the lengths for unused bit length codes. - */ - -/* =========================================================================== - * Local data. These are initialized only once. - */ - -#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ - -#if defined(GEN_TREES_H) || !defined(STDC) -/* non ANSI compilers may not accept trees.h */ - -local ct_data static_ltree[L_CODES+2]; -/* The static literal tree. Since the bit lengths are imposed, there is no - * need for the L_CODES extra codes used during heap construction. However - * The codes 286 and 287 are needed to build a canonical tree (see _tr_init - * below). - */ - -local ct_data static_dtree[D_CODES]; -/* The static distance tree. (Actually a trivial tree since all codes use - * 5 bits.) - */ - -uch _dist_code[DIST_CODE_LEN]; -/* Distance codes. The first 256 values correspond to the distances - * 3 .. 258, the last 256 values correspond to the top 8 bits of - * the 15 bit distances. - */ - -uch _length_code[MAX_MATCH-MIN_MATCH+1]; -/* length code for each normalized match length (0 == MIN_MATCH) */ - -local int base_length[LENGTH_CODES]; -/* First normalized length for each code (0 = MIN_MATCH) */ - -local int base_dist[D_CODES]; -/* First normalized distance for each code (0 = distance of 1) */ - -#else -# include "trees.h" -#endif /* GEN_TREES_H */ - -struct static_tree_desc_s { - const ct_data *static_tree; /* static tree or NULL */ - const intf *extra_bits; /* extra bits for each code or NULL */ - int extra_base; /* base index for extra_bits */ - int elems; /* max number of elements in the tree */ - int max_length; /* max bit length for the codes */ -}; - -#ifdef NO_INIT_GLOBAL_POINTERS -# define TCONST -#else -# define TCONST const -#endif - -local TCONST static_tree_desc static_l_desc = -{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; - -local TCONST static_tree_desc static_d_desc = -{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; - -local TCONST static_tree_desc static_bl_desc = -{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; - -/* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(unsigned code, int len) { - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(deflate_state *s) { - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(deflate_state *s) { - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->bits_sent = (s->bits_sent + 7) & ~7; -#endif -} - -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) { - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - unsigned code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits - 1]) << 1; - next_code[bits] = (ush)code; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, - "inconsistent bit counts"); - Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); - - for (n = 0; n <= max_code; n++) { - int len = tree[n].Len; - if (len == 0) continue; - /* Now reverse the bits */ - tree[n].Code = (ush)bi_reverse(next_code[len]++, len); - - Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", - n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1)); - } -} - -#ifdef GEN_TREES_H -local void gen_trees_header(void); -#endif - -#ifndef ZLIB_DEBUG -# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) - /* Send a code of the given tree. c and tree must not have side effects */ - -#else /* !ZLIB_DEBUG */ -# define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ - send_bits(s, tree[c].Code, tree[c].Len); } -#endif - -/* =========================================================================== - * Send a value on a given number of bits. - * IN assertion: length <= 16 and value fits in length bits. - */ -#ifdef ZLIB_DEBUG -local void send_bits(deflate_state *s, int value, int length) { - Tracevv((stderr," l %2d v %4x ", length, value)); - Assert(length > 0 && length <= 15, "invalid length"); - s->bits_sent += (ulg)length; - - /* If not enough room in bi_buf, use (valid) bits from bi_buf and - * (16 - bi_valid) bits from value, leaving (width - (16 - bi_valid)) - * unused bits in value. - */ - if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (ush)value << s->bi_valid; - put_short(s, s->bi_buf); - s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); - s->bi_valid += length - Buf_size; - } else { - s->bi_buf |= (ush)value << s->bi_valid; - s->bi_valid += length; - } -} -#else /* !ZLIB_DEBUG */ - -#define send_bits(s, value, length) \ -{ int len = length;\ - if (s->bi_valid > (int)Buf_size - len) {\ - int val = (int)value;\ - s->bi_buf |= (ush)val << s->bi_valid;\ - put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ - s->bi_valid += len - Buf_size;\ - } else {\ - s->bi_buf |= (ush)(value) << s->bi_valid;\ - s->bi_valid += len;\ - }\ -} -#endif /* ZLIB_DEBUG */ - - -/* the arguments must not have side effects */ - -/* =========================================================================== - * Initialize the various 'constant' tables. - */ -local void tr_static_init(void) { -#if defined(GEN_TREES_H) || !defined(STDC) - static int static_init_done = 0; - int n; /* iterates over tree elements */ - int bits; /* bit counter */ - int length; /* length value */ - int code; /* code value */ - int dist; /* distance index */ - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - if (static_init_done) return; - - /* For some embedded targets, global variables are not initialized: */ -#ifdef NO_INIT_GLOBAL_POINTERS - static_l_desc.static_tree = static_ltree; - static_l_desc.extra_bits = extra_lbits; - static_d_desc.static_tree = static_dtree; - static_d_desc.extra_bits = extra_dbits; - static_bl_desc.extra_bits = extra_blbits; -#endif - - /* Initialize the mapping length (0..255) -> length code (0..28) */ - length = 0; - for (code = 0; code < LENGTH_CODES-1; code++) { - base_length[code] = length; - for (n = 0; n < (1 << extra_lbits[code]); n++) { - _length_code[length++] = (uch)code; - } - } - Assert (length == 256, "tr_static_init: length != 256"); - /* Note that the length 255 (match length 258) can be represented - * in two different ways: code 284 + 5 bits or code 285, so we - * overwrite length_code[255] to use the best encoding: - */ - _length_code[length - 1] = (uch)code; - - /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ - dist = 0; - for (code = 0 ; code < 16; code++) { - base_dist[code] = dist; - for (n = 0; n < (1 << extra_dbits[code]); n++) { - _dist_code[dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: dist != 256"); - dist >>= 7; /* from now on, all distances are divided by 128 */ - for ( ; code < D_CODES; code++) { - base_dist[code] = dist << 7; - for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) { - _dist_code[256 + dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: 256 + dist != 512"); - - /* Construct the codes of the static literal tree */ - for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; - n = 0; - while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; - while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; - while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; - while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; - /* Codes 286 and 287 do not exist, but we must include them in the - * tree construction to get a canonical Huffman tree (longest code - * all ones) - */ - gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); - - /* The static distance tree is trivial: */ - for (n = 0; n < D_CODES; n++) { - static_dtree[n].Len = 5; - static_dtree[n].Code = bi_reverse((unsigned)n, 5); - } - static_init_done = 1; - -# ifdef GEN_TREES_H - gen_trees_header(); -# endif -#endif /* defined(GEN_TREES_H) || !defined(STDC) */ -} - -/* =========================================================================== - * Generate the file trees.h describing the static trees. - */ -#ifdef GEN_TREES_H -# ifndef ZLIB_DEBUG -# include -# endif - -# define SEPARATOR(i, last, width) \ - ((i) == (last)? "\n};\n\n" : \ - ((i) % (width) == (width) - 1 ? ",\n" : ", ")) - -void gen_trees_header(void) { - FILE *header = fopen("trees.h", "w"); - int i; - - Assert (header != NULL, "Can't open trees.h"); - fprintf(header, - "/* header created automatically with -DGEN_TREES_H */\n\n"); - - fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); - for (i = 0; i < L_CODES+2; i++) { - fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, - static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); - } - - fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, - static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); - } - - fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); - for (i = 0; i < DIST_CODE_LEN; i++) { - fprintf(header, "%2u%s", _dist_code[i], - SEPARATOR(i, DIST_CODE_LEN-1, 20)); - } - - fprintf(header, - "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); - for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { - fprintf(header, "%2u%s", _length_code[i], - SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); - } - - fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); - for (i = 0; i < LENGTH_CODES; i++) { - fprintf(header, "%1u%s", base_length[i], - SEPARATOR(i, LENGTH_CODES-1, 20)); - } - - fprintf(header, "local const int base_dist[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "%5u%s", base_dist[i], - SEPARATOR(i, D_CODES-1, 10)); - } - - fclose(header); -} -#endif /* GEN_TREES_H */ - -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(deflate_state *s) { - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->sym_next = s->matches = 0; -} - -/* =========================================================================== - * Initialize the tree data structures for a new zlib stream. - */ -void ZLIB_INTERNAL _tr_init(deflate_state *s) { - tr_static_init(); - - s->l_desc.dyn_tree = s->dyn_ltree; - s->l_desc.stat_desc = &static_l_desc; - - s->d_desc.dyn_tree = s->dyn_dtree; - s->d_desc.stat_desc = &static_d_desc; - - s->bl_desc.dyn_tree = s->bl_tree; - s->bl_desc.stat_desc = &static_bl_desc; - - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->compressed_len = 0L; - s->bits_sent = 0L; -#endif - - /* Initialize the first block of the first file: */ - init_block(s); -} - -#define SMALLEST 1 -/* Index within the heap array of least frequent node in the Huffman tree */ - - -/* =========================================================================== - * Remove the smallest element from the heap and recreate the heap with - * one less element. Updates heap and heap_len. - */ -#define pqremove(s, tree, top) \ -{\ - top = s->heap[SMALLEST]; \ - s->heap[SMALLEST] = s->heap[s->heap_len--]; \ - pqdownheap(s, tree, SMALLEST); \ -} - -/* =========================================================================== - * Compares to subtrees, using the tree depth as tie breaker when - * the subtrees have equal frequency. This minimizes the worst case length. - */ -#define smaller(tree, n, m, depth) \ - (tree[n].Freq < tree[m].Freq || \ - (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) - -/* =========================================================================== - * Restore the heap property by moving down the tree starting at node k, - * exchanging a node with the smallest of its two sons if necessary, stopping - * when the heap property is re-established (each father smaller than its - * two sons). - */ -local void pqdownheap(deflate_state *s, ct_data *tree, int k) { - int v = s->heap[k]; - int j = k << 1; /* left son of k */ - while (j <= s->heap_len) { - /* Set j to the smallest of the two sons: */ - if (j < s->heap_len && - smaller(tree, s->heap[j + 1], s->heap[j], s->depth)) { - j++; - } - /* Exit if v is smaller than both sons */ - if (smaller(tree, v, s->heap[j], s->depth)) break; - - /* Exchange v with the smallest son */ - s->heap[k] = s->heap[j]; k = j; - - /* And continue down the tree, setting j to the left son of k */ - j <<= 1; - } - s->heap[k] = v; -} - -/* =========================================================================== - * Compute the optimal bit lengths for a tree and update the total bit length - * for the current block. - * IN assertion: the fields freq and dad are set, heap[heap_max] and - * above are the tree nodes sorted by increasing frequency. - * OUT assertions: the field len is set to the optimal bit length, the - * array bl_count contains the frequencies for each bit length. - * The length opt_len is updated; static_len is also updated if stree is - * not null. - */ -local void gen_bitlen(deflate_state *s, tree_desc *desc) { - ct_data *tree = desc->dyn_tree; - int max_code = desc->max_code; - const ct_data *stree = desc->stat_desc->static_tree; - const intf *extra = desc->stat_desc->extra_bits; - int base = desc->stat_desc->extra_base; - int max_length = desc->stat_desc->max_length; - int h; /* heap index */ - int n, m; /* iterate over the tree elements */ - int bits; /* bit length */ - int xbits; /* extra bits */ - ush f; /* frequency */ - int overflow = 0; /* number of elements with bit length too large */ - - for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ - - for (h = s->heap_max + 1; h < HEAP_SIZE; h++) { - n = s->heap[h]; - bits = tree[tree[n].Dad].Len + 1; - if (bits > max_length) bits = max_length, overflow++; - tree[n].Len = (ush)bits; - /* We overwrite tree[n].Dad which is no longer needed */ - - if (n > max_code) continue; /* not a leaf node */ - - s->bl_count[bits]++; - xbits = 0; - if (n >= base) xbits = extra[n - base]; - f = tree[n].Freq; - s->opt_len += (ulg)f * (unsigned)(bits + xbits); - if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits); - } - if (overflow == 0) return; - - Tracev((stderr,"\nbit length overflow\n")); - /* This happens for example on obj2 and pic of the Calgary corpus */ - - /* Find the first bit length which could increase: */ - do { - bits = max_length - 1; - while (s->bl_count[bits] == 0) bits--; - s->bl_count[bits]--; /* move one leaf down the tree */ - s->bl_count[bits + 1] += 2; /* move one overflow item as its brother */ - s->bl_count[max_length]--; - /* The brother of the overflow item also moves one step up, - * but this does not affect bl_count[max_length] - */ - overflow -= 2; - } while (overflow > 0); - - /* Now recompute all bit lengths, scanning in increasing frequency. - * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - * lengths instead of fixing only the wrong ones. This idea is taken - * from 'ar' written by Haruhiko Okumura.) - */ - for (bits = max_length; bits != 0; bits--) { - n = s->bl_count[bits]; - while (n != 0) { - m = s->heap[--h]; - if (m > max_code) continue; - if ((unsigned) tree[m].Len != (unsigned) bits) { - Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); - s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq; - tree[m].Len = (ush)bits; - } - n--; - } - } -} - -#ifdef DUMP_BL_TREE -# include -#endif - -/* =========================================================================== - * Construct one Huffman tree and assigns the code bit strings and lengths. - * Update the total bit length for the current block. - * IN assertion: the field freq is set for all tree elements. - * OUT assertions: the fields len and code are set to the optimal bit length - * and corresponding code. The length opt_len is updated; static_len is - * also updated if stree is not null. The field max_code is set. - */ -local void build_tree(deflate_state *s, tree_desc *desc) { - ct_data *tree = desc->dyn_tree; - const ct_data *stree = desc->stat_desc->static_tree; - int elems = desc->stat_desc->elems; - int n, m; /* iterate over heap elements */ - int max_code = -1; /* largest code with non zero frequency */ - int node; /* new node being created */ - - /* Construct the initial heap, with least frequent element in - * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n + 1]. - * heap[0] is not used. - */ - s->heap_len = 0, s->heap_max = HEAP_SIZE; - - for (n = 0; n < elems; n++) { - if (tree[n].Freq != 0) { - s->heap[++(s->heap_len)] = max_code = n; - s->depth[n] = 0; - } else { - tree[n].Len = 0; - } - } - - /* The pkzip format requires that at least one distance code exists, - * and that at least one bit should be sent even if there is only one - * possible code. So to avoid special checks later on we force at least - * two codes of non zero frequency. - */ - while (s->heap_len < 2) { - node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); - tree[node].Freq = 1; - s->depth[node] = 0; - s->opt_len--; if (stree) s->static_len -= stree[node].Len; - /* node is 0 or 1 so it does not have extra bits */ - } - desc->max_code = max_code; - - /* The elements heap[heap_len/2 + 1 .. heap_len] are leaves of the tree, - * establish sub-heaps of increasing lengths: - */ - for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); - - /* Construct the Huffman tree by repeatedly combining the least two - * frequent nodes. - */ - node = elems; /* next internal node of the tree */ - do { - pqremove(s, tree, n); /* n = node of least frequency */ - m = s->heap[SMALLEST]; /* m = node of next least frequency */ - - s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ - s->heap[--(s->heap_max)] = m; - - /* Create a new node father of n and m */ - tree[node].Freq = tree[n].Freq + tree[m].Freq; - s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? - s->depth[n] : s->depth[m]) + 1); - tree[n].Dad = tree[m].Dad = (ush)node; -#ifdef DUMP_BL_TREE - if (tree == s->bl_tree) { - fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", - node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); - } -#endif - /* and insert the new node in the heap */ - s->heap[SMALLEST] = node++; - pqdownheap(s, tree, SMALLEST); - - } while (s->heap_len >= 2); - - s->heap[--(s->heap_max)] = s->heap[SMALLEST]; - - /* At this point, the fields freq and dad are set. We can now - * generate the bit lengths. - */ - gen_bitlen(s, (tree_desc *)desc); - - /* The field len is now set, we can generate the bit codes */ - gen_codes ((ct_data *)tree, max_code, s->bl_count); -} - -/* =========================================================================== - * Scan a literal or distance tree to determine the frequencies of the codes - * in the bit length tree. - */ -local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - if (nextlen == 0) max_count = 138, min_count = 3; - tree[max_code + 1].Len = (ush)0xffff; /* guard */ - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n + 1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - s->bl_tree[curlen].Freq += count; - } else if (curlen != 0) { - if (curlen != prevlen) s->bl_tree[curlen].Freq++; - s->bl_tree[REP_3_6].Freq++; - } else if (count <= 10) { - s->bl_tree[REPZ_3_10].Freq++; - } else { - s->bl_tree[REPZ_11_138].Freq++; - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Send a literal or distance tree in compressed form, using the codes in - * bl_tree. - */ -local void send_tree(deflate_state *s, ct_data *tree, int max_code) { - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - /* tree[max_code + 1].Len = -1; */ /* guard already set */ - if (nextlen == 0) max_count = 138, min_count = 3; - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n + 1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - do { send_code(s, curlen, s->bl_tree); } while (--count != 0); - - } else if (curlen != 0) { - if (curlen != prevlen) { - send_code(s, curlen, s->bl_tree); count--; - } - Assert(count >= 3 && count <= 6, " 3_6?"); - send_code(s, REP_3_6, s->bl_tree); send_bits(s, count - 3, 2); - - } else if (count <= 10) { - send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count - 3, 3); - - } else { - send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count - 11, 7); - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Construct the Huffman tree for the bit lengths and return the index in - * bl_order of the last bit length code to send. - */ -local int build_bl_tree(deflate_state *s) { - int max_blindex; /* index of last bit length code of non zero freq */ - - /* Determine the bit length frequencies for literal and distance trees */ - scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); - scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); - - /* Build the bit length tree: */ - build_tree(s, (tree_desc *)(&(s->bl_desc))); - /* opt_len now includes the length of the tree representations, except the - * lengths of the bit lengths codes and the 5 + 5 + 4 bits for the counts. - */ - - /* Determine the number of bit length codes to send. The pkzip format - * requires that at least 4 bit length codes be sent. (appnote.txt says - * 3 but the actual value used is 4.) - */ - for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { - if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; - } - /* Update opt_len to include the bit length tree and counts */ - s->opt_len += 3*((ulg)max_blindex + 1) + 5 + 5 + 4; - Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", - s->opt_len, s->static_len)); - - return max_blindex; -} - -/* =========================================================================== - * Send the header for a block using dynamic Huffman trees: the counts, the - * lengths of the bit length codes, the literal tree and the distance tree. - * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. - */ -local void send_all_trees(deflate_state *s, int lcodes, int dcodes, - int blcodes) { - int rank; /* index in bl_order */ - - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); - Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, - "too many codes"); - Tracev((stderr, "\nbl counts: ")); - send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes - 1, 5); - send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */ - for (rank = 0; rank < blcodes; rank++) { - Tracev((stderr, "\nbl code %2d ", bl_order[rank])); - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); - } - Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_ltree, lcodes - 1); /* literal tree */ - Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_dtree, dcodes - 1); /* distance tree */ - Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); -} - -/* =========================================================================== - * Send a stored block - */ -void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, - ulg stored_len, int last) { - send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */ - bi_windup(s); /* align on byte boundary */ - put_short(s, (ush)stored_len); - put_short(s, (ush)~stored_len); - if (stored_len) - zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len); - s->pending += stored_len; -#ifdef ZLIB_DEBUG - s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; - s->compressed_len += (stored_len + 4) << 3; - s->bits_sent += 2*16; - s->bits_sent += stored_len << 3; -#endif -} - -/* =========================================================================== - * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) - */ -void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) { - bi_flush(s); -} - -/* =========================================================================== - * Send one empty static block to give enough lookahead for inflate. - * This takes 10 bits, of which 7 may remain in the bit buffer. - */ -void ZLIB_INTERNAL _tr_align(deflate_state *s) { - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef ZLIB_DEBUG - s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ -#endif - bi_flush(s); -} - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(deflate_state *s, const ct_data *ltree, - const ct_data *dtree) { - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in symbol buffers */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->sym_next != 0) do { -#ifdef LIT_MEM - dist = s->d_buf[sx]; - lc = s->l_buf[sx++]; -#else - dist = s->sym_buf[sx++] & 0xff; - dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; - lc = s->sym_buf[sx++]; -#endif - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code + LITERALS + 1, ltree); /* send length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= (unsigned)base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check for no overlay of pending_buf on needed symbols */ -#ifdef LIT_MEM - Assert(s->pending < 2 * (s->lit_bufsize + sx), "pendingBuf overflow"); -#else - Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); -#endif - - } while (sx < s->sym_next); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "block list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type(deflate_state *s) { - /* block_mask is the bit mask of block-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long block_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("block-listed") bytes. */ - for (n = 0; n <= 31; n++, block_mask >>= 1) - if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("allow-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "block-listed" or "allow-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and write out the encoded block. - */ -void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, - ulg stored_len, int last) { - ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ - int max_blindex = 0; /* index of last bit length code of non zero freq */ - - /* Build the Huffman trees unless a stored block is forced */ - if (s->level > 0) { - - /* Check if the file is binary or text */ - if (s->strm->data_type == Z_UNKNOWN) - s->strm->data_type = detect_data_type(s); - - /* Construct the literal and distance trees */ - build_tree(s, (tree_desc *)(&(s->l_desc))); - Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - - build_tree(s, (tree_desc *)(&(s->d_desc))); - Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - /* At this point, opt_len and static_len are the total bit lengths of - * the compressed block data, excluding the tree representations. - */ - - /* Build the bit length tree for the above two trees, and get the index - * in bl_order of the last bit length code to send. - */ - max_blindex = build_bl_tree(s); - - /* Determine the best encoding. Compute the block lengths in bytes. */ - opt_lenb = (s->opt_len + 3 + 7) >> 3; - static_lenb = (s->static_len + 3 + 7) >> 3; - - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", - opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, - s->sym_next / 3)); - -#ifndef FORCE_STATIC - if (static_lenb <= opt_lenb || s->strategy == Z_FIXED) -#endif - opt_lenb = static_lenb; - - } else { - Assert(buf != (char*)0, "lost buf"); - opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ - } - -#ifdef FORCE_STORED - if (buf != (char*)0) { /* force stored block */ -#else - if (stored_len + 4 <= opt_lenb && buf != (char*)0) { - /* 4: two words for the lengths */ -#endif - /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. - * Otherwise we can't have processed more than WSIZE input bytes since - * the last block flush, because compression would have been - * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to - * transform a block into a stored block. - */ - _tr_stored_block(s, buf, stored_len, last); - - } else if (static_lenb == opt_lenb) { - send_bits(s, (STATIC_TREES<<1) + last, 3); - compress_block(s, (const ct_data *)static_ltree, - (const ct_data *)static_dtree); -#ifdef ZLIB_DEBUG - s->compressed_len += 3 + s->static_len; -#endif - } else { - send_bits(s, (DYN_TREES<<1) + last, 3); - send_all_trees(s, s->l_desc.max_code + 1, s->d_desc.max_code + 1, - max_blindex + 1); - compress_block(s, (const ct_data *)s->dyn_ltree, - (const ct_data *)s->dyn_dtree); -#ifdef ZLIB_DEBUG - s->compressed_len += 3 + s->opt_len; -#endif - } - Assert (s->compressed_len == s->bits_sent, "bad compressed size"); - /* The above check is made mod 2^32, for files larger than 512 MB - * and uLong implemented on 32 bits. - */ - init_block(s); - - if (last) { - bi_windup(s); -#ifdef ZLIB_DEBUG - s->compressed_len += 7; /* align on byte boundary */ -#endif - } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len >> 3, - s->compressed_len - 7*last)); -} - -/* =========================================================================== - * Save the match info and tally the frequency counts. Return true if - * the current block must be flushed. - */ -int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { -#ifdef LIT_MEM - s->d_buf[s->sym_next] = (ush)dist; - s->l_buf[s->sym_next++] = (uch)lc; -#else - s->sym_buf[s->sym_next++] = (uch)dist; - s->sym_buf[s->sym_next++] = (uch)(dist >> 8); - s->sym_buf[s->sym_next++] = (uch)lc; -#endif - if (dist == 0) { - /* lc is the unmatched char */ - s->dyn_ltree[lc].Freq++; - } else { - s->matches++; - /* Here, lc is the match length - MIN_MATCH */ - dist--; /* dist = match distance - 1 */ - Assert((ush)dist < (ush)MAX_DIST(s) && - (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); - - s->dyn_ltree[_length_code[lc] + LITERALS + 1].Freq++; - s->dyn_dtree[d_code(dist)].Freq++; - } - return (s->sym_next == s->sym_end); -} diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/trees.h b/vendor/libgit2-sys/libgit2/deps/zlib/trees.h deleted file mode 100644 index d35639d..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/trees.h +++ /dev/null @@ -1,128 +0,0 @@ -/* header created automatically with -DGEN_TREES_H */ - -local const ct_data static_ltree[L_CODES+2] = { -{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, -{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, -{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, -{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, -{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, -{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, -{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, -{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, -{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, -{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, -{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, -{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, -{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, -{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, -{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, -{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, -{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, -{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, -{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, -{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, -{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, -{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, -{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, -{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, -{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, -{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, -{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, -{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, -{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, -{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, -{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, -{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, -{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, -{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, -{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, -{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, -{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, -{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, -{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, -{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, -{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, -{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, -{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, -{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, -{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, -{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, -{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, -{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, -{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, -{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, -{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, -{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, -{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, -{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, -{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, -{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, -{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, -{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} -}; - -local const ct_data static_dtree[D_CODES] = { -{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, -{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, -{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, -{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, -{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, -{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} -}; - -const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { - 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, - 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, -10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, -11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, -12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, -18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 -}; - -const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, -13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, -17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, -19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, -21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, -22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 -}; - -local const int base_length[LENGTH_CODES] = { -0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, -64, 80, 96, 112, 128, 160, 192, 224, 0 -}; - -local const int base_dist[D_CODES] = { - 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, - 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, - 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 -}; - diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/zconf.h b/vendor/libgit2-sys/libgit2/deps/zlib/zconf.h deleted file mode 100644 index 62adc8d..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/zconf.h +++ /dev/null @@ -1,543 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef ZCONF_H -#define ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - * Even better than compiling with -DZ_PREFIX would be to use configure to set - * this permanently in zconf.h using "./configure --zprefix". - */ -#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ -# define Z_PREFIX_SET - -/* all linked symbols and init macros */ -# define _dist_code z__dist_code -# define _length_code z__length_code -# define _tr_align z__tr_align -# define _tr_flush_bits z__tr_flush_bits -# define _tr_flush_block z__tr_flush_block -# define _tr_init z__tr_init -# define _tr_stored_block z__tr_stored_block -# define _tr_tally z__tr_tally -# define adler32 z_adler32 -# define adler32_combine z_adler32_combine -# define adler32_combine64 z_adler32_combine64 -# define adler32_z z_adler32_z -# ifndef Z_SOLO -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# endif -# define crc32 z_crc32 -# define crc32_combine z_crc32_combine -# define crc32_combine64 z_crc32_combine64 -# define crc32_combine_gen z_crc32_combine_gen -# define crc32_combine_gen64 z_crc32_combine_gen64 -# define crc32_combine_op z_crc32_combine_op -# define crc32_z z_crc32_z -# define deflate z_deflate -# define deflateBound z_deflateBound -# define deflateCopy z_deflateCopy -# define deflateEnd z_deflateEnd -# define deflateGetDictionary z_deflateGetDictionary -# define deflateInit z_deflateInit -# define deflateInit2 z_deflateInit2 -# define deflateInit2_ z_deflateInit2_ -# define deflateInit_ z_deflateInit_ -# define deflateParams z_deflateParams -# define deflatePending z_deflatePending -# define deflatePrime z_deflatePrime -# define deflateReset z_deflateReset -# define deflateResetKeep z_deflateResetKeep -# define deflateSetDictionary z_deflateSetDictionary -# define deflateSetHeader z_deflateSetHeader -# define deflateTune z_deflateTune -# define deflate_copyright z_deflate_copyright -# define get_crc_table z_get_crc_table -# ifndef Z_SOLO -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzfread z_gzfread -# define gzfwrite z_gzfwrite -# define gzgetc z_gzgetc -# define gzgetc_ z_gzgetc_ -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# ifdef _WIN32 -# define gzopen_w z_gzopen_w -# endif -# define gzprintf z_gzprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzvprintf z_gzvprintf -# define gzwrite z_gzwrite -# endif -# define inflate z_inflate -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd -# define inflateBackInit z_inflateBackInit -# define inflateBackInit_ z_inflateBackInit_ -# define inflateCodesUsed z_inflateCodesUsed -# define inflateCopy z_inflateCopy -# define inflateEnd z_inflateEnd -# define inflateGetDictionary z_inflateGetDictionary -# define inflateGetHeader z_inflateGetHeader -# define inflateInit z_inflateInit -# define inflateInit2 z_inflateInit2 -# define inflateInit2_ z_inflateInit2_ -# define inflateInit_ z_inflateInit_ -# define inflateMark z_inflateMark -# define inflatePrime z_inflatePrime -# define inflateReset z_inflateReset -# define inflateReset2 z_inflateReset2 -# define inflateResetKeep z_inflateResetKeep -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateUndermine z_inflateUndermine -# define inflateValidate z_inflateValidate -# define inflate_copyright z_inflate_copyright -# define inflate_fast z_inflate_fast -# define inflate_table z_inflate_table -# ifndef Z_SOLO -# define uncompress z_uncompress -# define uncompress2 z_uncompress2 -# endif -# define zError z_zError -# ifndef Z_SOLO -# define zcalloc z_zcalloc -# define zcfree z_zcfree -# endif -# define zlibCompileFlags z_zlibCompileFlags -# define zlibVersion z_zlibVersion - -/* all zlib typedefs in zlib.h and zconf.h */ -# define Byte z_Byte -# define Bytef z_Bytef -# define alloc_func z_alloc_func -# define charf z_charf -# define free_func z_free_func -# ifndef Z_SOLO -# define gzFile z_gzFile -# endif -# define gz_header z_gz_header -# define gz_headerp z_gz_headerp -# define in_func z_in_func -# define intf z_intf -# define out_func z_out_func -# define uInt z_uInt -# define uIntf z_uIntf -# define uLong z_uLong -# define uLongf z_uLongf -# define voidp z_voidp -# define voidpc z_voidpc -# define voidpf z_voidpf - -/* all zlib structs in zlib.h and zconf.h */ -# define gz_header_s z_gz_header_s -# define internal_state z_internal_state - -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -#if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const -#else -# define z_const -#endif - -#ifdef Z_SOLO -# ifdef _WIN64 - typedef unsigned long long z_size_t; -# else - typedef unsigned long z_size_t; -# endif -#else -# define z_longlong long long -# if defined(NO_SIZE_T) - typedef unsigned NO_SIZE_T z_size_t; -# elif defined(STDC) -# include - typedef size_t z_size_t; -# else - typedef unsigned long z_size_t; -# endif -# undef z_longlong -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus about 7 kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) -# include -# if (UINT_MAX == 0xffffffffUL) -# define Z_U4 unsigned -# elif (ULONG_MAX == 0xffffffffUL) -# define Z_U4 unsigned long -# elif (USHRT_MAX == 0xffffffffUL) -# define Z_U4 unsigned short -# endif -#endif - -#ifdef Z_U4 - typedef Z_U4 z_crc_t; -#else - typedef unsigned long z_crc_t; -#endif - -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_UNISTD_H -#endif - -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_STDARG_H -#endif - -#ifdef STDC -# ifndef Z_SOLO -# include /* for off_t */ -# endif -#endif - -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -# include /* for va_list */ -# endif -#endif - -#ifdef _WIN32 -# ifndef Z_SOLO -# include /* for wchar_t */ -# endif -#endif - -/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and - * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even - * though the former does not conform to the LFS document), but considering - * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as - * equivalently requesting no 64-bit operations - */ -#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 -# undef _LARGEFILE64_SOURCE -#endif - -#ifndef Z_HAVE_UNISTD_H -# ifdef __WATCOMC__ -# define Z_HAVE_UNISTD_H -# endif -#endif -#ifndef Z_HAVE_UNISTD_H -# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32) -# define Z_HAVE_UNISTD_H -# endif -#endif -#ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) -# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ -# ifdef VMS -# include /* for off_t */ -# endif -# ifndef z_off_t -# define z_off_t off_t -# endif -# endif -#endif - -#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 -# define Z_LFS64 -#endif - -#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) -# define Z_LARGE64 -#endif - -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) -# define Z_WANT64 -#endif - -#if !defined(SEEK_SET) && !defined(Z_SOLO) -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif - -#ifndef z_off_t -# define z_off_t long -#endif - -#if !defined(_WIN32) && defined(Z_LARGE64) -# define z_off64_t off64_t -#else -# if defined(_WIN32) && !defined(__GNUC__) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) - #pragma map(deflateInit_,"DEIN") - #pragma map(deflateInit2_,"DEIN2") - #pragma map(deflateEnd,"DEEND") - #pragma map(deflateBound,"DEBND") - #pragma map(inflateInit_,"ININ") - #pragma map(inflateInit2_,"ININ2") - #pragma map(inflateEnd,"INEND") - #pragma map(inflateSync,"INSY") - #pragma map(inflateSetDictionary,"INSEDI") - #pragma map(compressBound,"CMBND") - #pragma map(inflate_table,"INTABL") - #pragma map(inflate_fast,"INFA") - #pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/zlib.h b/vendor/libgit2-sys/libgit2/deps/zlib/zlib.h deleted file mode 100644 index 8d4b932..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/zlib.h +++ /dev/null @@ -1,1938 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.3.1, January 22nd, 2024 - - Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef ZLIB_H -#define ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.3.1" -#define ZLIB_VERNUM 0x1310 -#define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 3 -#define ZLIB_VER_REVISION 1 -#define ZLIB_VER_SUBREVISION 0 - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed data. - This version of the library supports only one compression method (deflation) - but other algorithms will be added later and will have the same stream - interface. - - Compression can be done in a single step if the buffers are large enough, - or can be done by repeated calls of the compression function. In the latter - case, the application must provide more input and/or consume the output - (providing more output space) before each call. - - The compressed data format used by default by the in-memory functions is - the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped - around a deflate stream, which is itself documented in RFC 1951. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio using the functions that start - with "gz". The gzip format is different from the zlib format. gzip is a - gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. - - This library can optionally read and write gzip and raw deflate streams in - memory as well. - - The zlib format was designed to be compact and fast for use in memory - and on communications channels. The gzip format was designed for single- - file compression on file systems, has a larger header than zlib to maintain - directory information, and uses a different, slower check method than zlib. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never crash - even in the case of corrupted input. -*/ - -typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size); -typedef void (*free_func)(voidpf opaque, voidpf address); - -struct internal_state; - -typedef struct z_stream_s { - z_const Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total number of input bytes read so far */ - - Bytef *next_out; /* next output byte will go here */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total number of bytes output so far */ - - z_const char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: binary or text - for deflate, or the decoding state for inflate */ - uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - gzip header information passed to and from zlib routines. See RFC 1952 - for more details on the meanings of these fields. -*/ -typedef struct gz_header_s { - int text; /* true if compressed data believed to be text */ - uLong time; /* modification time */ - int xflags; /* extra flags (not used when writing a gzip file) */ - int os; /* operating system */ - Bytef *extra; /* pointer to extra field or Z_NULL if none */ - uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ - uInt extra_max; /* space at extra (only when reading header) */ - Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ - uInt name_max; /* space at name (only when reading header) */ - Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ - uInt comm_max; /* space at comment (only when reading header) */ - int hcrc; /* true if there was or will be a header crc */ - int done; /* true when done reading gzip header (not used - when writing a gzip file) */ -} gz_header; - -typedef gz_header FAR *gz_headerp; - -/* - The application must update next_in and avail_in when avail_in has dropped - to zero. It must update next_out and avail_out when avail_out has dropped - to zero. The application must initialize zalloc, zfree and opaque before - calling the init function. All other fields are set by the compression - library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. In that case, zlib is thread-safe. When zalloc and zfree are - Z_NULL on entry to the initialization function, they are set to internal - routines that use the standard library functions malloc() and free(). - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this if - the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers - returned by zalloc for objects of exactly 65536 bytes *must* have their - offset normalized to zero. The default allocation function provided by this - library ensures this (see zutil.c). To reduce memory requirements and avoid - any allocation of 64K objects, at the expense of compression ratio, compile - the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or progress - reports. After compression, total_in holds the total size of the - uncompressed data and may be saved for use by the decompressor (particularly - if the decompressor wants to decompress everything in a single step). -*/ - - /* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -#define Z_BLOCK 5 -#define Z_TREES 6 -/* Allowed flush values; see deflate() and inflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative values - * are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_RLE 3 -#define Z_FIXED 4 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_TEXT 1 -#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ -#define Z_UNKNOWN 2 -/* Possible values of the data_type field for deflate() */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - - - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion(void); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is not - compatible with the zlib.h header file used by the application. This check - is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. If - zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. total_in, total_out, adler, and msg are initialized. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at all - (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION - requests a default compromise between speed and compression (currently - equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if level is not a valid compression level, or - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). msg is set to null - if there is no error message. deflateInit does not perform any compression: - this will be done by deflate(). -*/ - - -ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Generate more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary. Some output may be provided even if - flush is zero. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming more - output, and updating avail_in or avail_out accordingly; avail_out should - never be zero before the call. The application can consume the compressed - output when it wants, for example when the output buffer is full (avail_out - == 0), or after each call of deflate(). If deflate returns Z_OK and with - zero avail_out, it must be called again after making room in the output - buffer because there might be more output pending. See deflatePending(), - which can be used if desired to determine whether or not there is more output - in that case. - - Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to - decide how much data to accumulate before producing output, in order to - maximize compression. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In - particular avail_in is zero after the call if enough output space has been - provided before the call.) Flushing may degrade compression for some - compression algorithms and so it should be used only when necessary. This - completes the current deflate block and follows it with an empty stored block - that is three bits plus filler bits to the next byte, followed by four bytes - (00 00 ff ff). - - If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the - output buffer, but the output is not aligned to a byte boundary. All of the - input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. - This completes the current deflate block and follows it with an empty fixed - codes block that is 10 bits long. This assures that enough bytes are output - in order for the decompressor to finish the block before the empty fixed - codes block. - - If flush is set to Z_BLOCK, a deflate block is completed and emitted, as - for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to - seven bits of the current block are held to be written as the next byte after - the next deflate block is completed. In this case, the decompressor may not - be provided enough bits at this point in order to complete decompression of - the data provided so far to the compressor. It may need to wait for the next - block to be emitted. This is for advanced applications that need to control - the emission of deflate blocks. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six when the flush marker begins, in order to avoid - repeated flush markers upon calling deflate() again when avail_out == 0. - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there was - enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this - function must be called again with Z_FINISH and more output space (updated - avail_out) but no more input data, until it returns with Z_STREAM_END or an - error. After deflate has returned Z_STREAM_END, the only possible operations - on the stream are deflateReset or deflateEnd. - - Z_FINISH can be used in the first deflate call after deflateInit if all the - compression is to be done in a single step. In order to complete in one - call, avail_out must be at least the value returned by deflateBound (see - below). Then deflate is guaranteed to return Z_STREAM_END. If not enough - output space is provided, deflate will not return Z_STREAM_END, and it must - be called again as described above. - - deflate() sets strm->adler to the Adler-32 checksum of all input read - so far (that is, total_in bytes). If a gzip stream is being generated, then - strm->adler will be the CRC-32 checksum of the input read so far. (See - deflateInit2 below.) - - deflate() may update strm->data_type if it can make a good guess about - the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is - considered binary. This field is only for information purposes and does not - affect the compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was Z_NULL or the state was inadvertently written over - by the application), or Z_BUF_ERROR if no progress is possible (for example - avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and - deflate() can be called again with more input and more output space to - continue compressing. -*/ - - -ZEXTERN int ZEXPORT deflateEnd(z_streamp strm); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any pending - output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, msg - may be set but then points to a static string (which must not be - deallocated). -*/ - - -/* -ZEXTERN int ZEXPORT inflateInit(z_streamp strm); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. In the current version of inflate, the provided input is not - read or consumed. The allocation of a sliding window will be deferred to - the first call of inflate (if the decompression does not complete on the - first call). If zalloc and zfree are set to Z_NULL, inflateInit updates - them to use default allocation functions. total_in, total_out, adler, and - msg are initialized. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller, or Z_STREAM_ERROR if the parameters are - invalid, such as a null pointer to the structure. msg is set to null if - there is no error message. inflateInit does not perform any decompression. - Actual decompression will be done by inflate(). So next_in, and avail_in, - next_out, and avail_out are unused and unchanged. The current - implementation of inflateInit() does not process any header information -- - that is deferred until inflate() is called. -*/ - - -ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), then next_in and avail_in are updated - accordingly, and processing will resume at this point for the next call of - inflate(). - - - Generate more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there is - no more input data or no more space in the output buffer (see below about - the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming more - output, and updating the next_* and avail_* values accordingly. If the - caller of inflate() does not provide both available input and available - output space, it is possible that there will be no progress made. The - application can consume the uncompressed output when it wants, for example - when the output buffer is full (avail_out == 0), or after each call of - inflate(). If inflate returns Z_OK and with zero avail_out, it must be - called again after making room in the output buffer because there might be - more output pending. - - The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, - Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much - output as possible to the output buffer. Z_BLOCK requests that inflate() - stop if and when it gets to the next deflate block boundary. When decoding - the zlib or gzip format, this will cause inflate() to return immediately - after the header and before the first block. When doing a raw inflate, - inflate() will go ahead and process the first block, and will return when it - gets to the end of that block, or when it runs out of data. - - The Z_BLOCK option assists in appending to or combining deflate streams. - To assist in this, on return inflate() always sets strm->data_type to the - number of unused bits in the last byte taken from strm->next_in, plus 64 if - inflate() is currently decoding the last block in the deflate stream, plus - 128 if inflate() returned immediately after decoding an end-of-block code or - decoding the complete header up to just before the first byte of the deflate - stream. The end-of-block will not be indicated until all of the uncompressed - data from that block has been written to strm->next_out. The number of - unused bits may in general be greater than seven, except when bit 7 of - data_type is set, in which case the number of unused bits will be less than - eight. data_type is set as noted here every time inflate() returns for all - flush options, and so can be used to determine the amount of currently - consumed input in bits. - - The Z_TREES option behaves as Z_BLOCK does, but it also returns when the - end of each deflate block header is reached, before any actual data in that - block is decoded. This allows the caller to determine the length of the - deflate block header for later use in random access within a deflate block. - 256 is added to the value of strm->data_type when inflate() returns - immediately after reaching the end of the deflate block header. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step (a - single call of inflate), the parameter flush should be set to Z_FINISH. In - this case all pending input is processed and all pending output is flushed; - avail_out must be large enough to hold all of the uncompressed data for the - operation to complete. (The size of the uncompressed data may have been - saved by the compressor for this purpose.) The use of Z_FINISH is not - required to perform an inflation in one step. However it may be used to - inform inflate that a faster approach can be used for the single inflate() - call. Z_FINISH also informs inflate to not maintain a sliding window if the - stream completes, which reduces inflate's memory footprint. If the stream - does not complete, either because not all of the stream is provided or not - enough output space is provided, then a sliding window will be allocated and - inflate() can be called again to continue the operation as if Z_NO_FLUSH had - been used. - - In this implementation, inflate() always flushes as much output as - possible to the output buffer, and always uses the faster approach on the - first call. So the effects of the flush parameter in this implementation are - on the return value of inflate() as noted below, when inflate() returns early - when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of - memory for a sliding window when Z_FINISH is used. - - If a preset dictionary is needed after this call (see inflateSetDictionary - below), inflate sets strm->adler to the Adler-32 checksum of the dictionary - chosen by the compressor and returns Z_NEED_DICT; otherwise it sets - strm->adler to the Adler-32 checksum of all output produced so far (that is, - total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described - below. At the end of the stream, inflate() checks that its computed Adler-32 - checksum is equal to that saved by the compressor and returns Z_STREAM_END - only if the checksum is correct. - - inflate() can decompress and check either zlib-wrapped or gzip-wrapped - deflate data. The header type is detected automatically, if requested when - initializing with inflateInit2(). Any information contained in the gzip - header is not retained unless inflateGetHeader() is used. When processing - gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output - produced so far. The CRC-32 is checked against the gzip trailer, as is the - uncompressed length, modulo 2^32. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect check - value, in which case strm->msg points to a string with a more specific - error), Z_STREAM_ERROR if the stream structure was inconsistent (for example - next_in or next_out was Z_NULL, or the state was inadvertently written over - by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR - if no progress was possible or if there was not enough room in the output - buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and - inflate() can be called again with more input and more output space to - continue decompressing. If Z_DATA_ERROR is returned, the application may - then call inflateSync() to look for a good compression block if a partial - recovery of the data is to be attempted. -*/ - - -ZEXTERN int ZEXPORT inflateEnd(z_streamp strm); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any pending - output. - - inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state - was inconsistent. -*/ - - - /* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2(z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy); - - This is another version of deflateInit with more compression options. The - fields zalloc, zfree and opaque must be initialized before by the caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - For the current implementation of deflate(), a windowBits value of 8 (a - window size of 256 bytes) is not supported. As a result, a request for 8 - will result in 9 (a 512-byte window). In that case, providing 8 to - inflateInit2() will result in an error when the zlib header with 9 is - checked against the initialization of inflate(). The remedy is to not use 8 - with deflateInit2() with this initialization, or at least in that case use 9 - with inflateInit2(). - - windowBits can also be -8..-15 for raw deflate. In this case, -windowBits - determines the window size. deflate() will then generate raw deflate data - with no zlib header or trailer, and will not compute a check value. - - windowBits can also be greater than 15 for optional gzip encoding. Add - 16 to windowBits to write a simple gzip header and trailer around the - compressed data instead of a zlib wrapper. The gzip header will have no - file name, no extra data, no comment, no modification time (set to zero), no - header crc, and the operating system will be set to the appropriate value, - if the operating system was determined at compile time. If a gzip stream is - being written, strm->adler is a CRC-32 instead of an Adler-32. - - For raw deflate or gzip encoding, a request for a 256-byte window is - rejected as invalid, since only the zlib header provides a means of - transmitting the window size to the decompressor. - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but is - slow and reduces compression ratio; memLevel=9 uses maximum memory for - optimal speed. The default value is 8. See zconf.h for total memory usage - as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match), or Z_RLE to limit match distances to one (run-length - encoding). Filtered data consists mostly of small values with a somewhat - random distribution. In this case, the compression algorithm is tuned to - compress them better. The effect of Z_FILTERED is to force more Huffman - coding and less string matching; it is somewhat intermediate between - Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as - fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The - strategy parameter only affects the compression ratio but not the - correctness of the compressed output even if it is not set appropriately. - Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler - decoder for special applications. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid - method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is - incompatible with the version assumed by the caller (ZLIB_VERSION). msg is - set to null if there is no error message. deflateInit2 does not perform any - compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, - const Bytef *dictionary, - uInt dictLength); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. When using the zlib format, this - function must be called immediately after deflateInit, deflateInit2 or - deflateReset, and before any call of deflate. When doing raw deflate, this - function must be called either before any call of deflate, or immediately - after the completion of a deflate block, i.e. after all input has been - consumed and all output has been delivered when using any of the flush - options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The - compressor and decompressor must use exactly the same dictionary (see - inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size - provided in deflateInit or deflateInit2. Thus the strings most likely to be - useful should be put at the end of the dictionary, not at the front. In - addition, the current implementation of deflate will use at most the window - size minus 262 bytes of the provided dictionary. - - Upon return of this function, strm->adler is set to the Adler-32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The Adler-32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) If a raw deflate was requested, then the - Adler-32 value is not computed and strm->adler is not set. - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if not at a block boundary for raw deflate). deflateSetDictionary does - not perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, - Bytef *dictionary, - uInt *dictLength); -/* - Returns the sliding dictionary being maintained by deflate. dictLength is - set to the number of bytes in the dictionary, and that many bytes are copied - to dictionary. dictionary must have enough space, where 32768 bytes is - always enough. If deflateGetDictionary() is called with dictionary equal to - Z_NULL, then only the dictionary length is returned, and nothing is copied. - Similarly, if dictLength is Z_NULL, then it is not set. - - deflateGetDictionary() may return a length less than the window size, even - when more than the window size in input has been provided. It may return up - to 258 bytes less in that case, due to how zlib's implementation of deflate - manages the sliding window and lookahead for matches, where matches can be - up to 258 bytes long. If the application needs the last window-size bytes of - input, then that would need to be saved by the application outside of zlib. - - deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the - stream state is inconsistent. -*/ - -ZEXTERN int ZEXPORT deflateCopy(z_streamp dest, - z_streamp source); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and can - consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being Z_NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset(z_streamp strm); -/* - This function is equivalent to deflateEnd followed by deflateInit, but - does not free and reallocate the internal compression state. The stream - will leave the compression level and any other attributes that may have been - set unchanged. total_in, total_out, adler, and msg are initialized. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams(z_streamp strm, - int level, - int strategy); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2(). This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different strategy. - If the compression approach (which is a function of the level) or the - strategy is changed, and if there have been any deflate() calls since the - state was initialized or reset, then the input available so far is - compressed with the old level and strategy using deflate(strm, Z_BLOCK). - There are three approaches for the compression levels 0, 1..3, and 4..9 - respectively. The new level and strategy will take effect at the next call - of deflate(). - - If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does - not have enough output space to complete, then the parameter change will not - take effect. In this case, deflateParams() can be called again with the - same parameters and more output space to try again. - - In order to assure a change in the parameters on the first try, the - deflate stream should be flushed using deflate() with Z_BLOCK or other flush - request until strm.avail_out is not zero, before calling deflateParams(). - Then no more input data should be provided before the deflateParams() call. - If this is done, the old level and strategy will be applied to the data - compressed before deflateParams(), and the new level and strategy will be - applied to the data compressed after deflateParams(). - - deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream - state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if - there was not enough output space to complete the compression of the - available input data before a change in the strategy or approach. Note that - in the case of a Z_BUF_ERROR, the parameters are not changed. A return - value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be - retried with more output space. -*/ - -ZEXTERN int ZEXPORT deflateTune(z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain); -/* - Fine tune deflate's internal compression parameters. This should only be - used by someone who understands the algorithm used by zlib's deflate for - searching for the best matching string, and even then only by the most - fanatic optimizer trying to squeeze out the last compressed bit for their - specific input data. Read the deflate.c source code for the meaning of the - max_lazy, good_length, nice_length, and max_chain parameters. - - deflateTune() can be called after deflateInit() or deflateInit2(), and - returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. - */ - -ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, - uLong sourceLen); -/* - deflateBound() returns an upper bound on the compressed size after - deflation of sourceLen bytes. It must be called after deflateInit() or - deflateInit2(), and after deflateSetHeader(), if used. This would be used - to allocate an output buffer for deflation in a single pass, and so would be - called before deflate(). If that first deflate() call is provided the - sourceLen input bytes, an output buffer allocated to the size returned by - deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed - to return Z_STREAM_END. Note that it is possible for the compressed size to - be larger than the value returned by deflateBound() if flush options other - than Z_FINISH or Z_NO_FLUSH are used. -*/ - -ZEXTERN int ZEXPORT deflatePending(z_streamp strm, - unsigned *pending, - int *bits); -/* - deflatePending() returns the number of bytes and bits of output that have - been generated, but not yet provided in the available output. The bytes not - provided would be due to the available output space having being consumed. - The number of bits of output not provided are between 0 and 7, where they - await more bits to join them in order to fill out a full byte. If pending - or bits are Z_NULL, then those values are not set. - - deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. - */ - -ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, - int bits, - int value); -/* - deflatePrime() inserts bits in the deflate output stream. The intent - is that this function is used to start off the deflate output with the bits - leftover from a previous deflate stream when appending to it. As such, this - function can only be used for raw deflate, and must be used before the first - deflate() call after a deflateInit2() or deflateReset(). bits must be less - than or equal to 16, and that many of the least significant bits of value - will be inserted in the output. - - deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough - room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the - source stream state was inconsistent. -*/ - -ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, - gz_headerp head); -/* - deflateSetHeader() provides gzip header information for when a gzip - stream is requested by deflateInit2(). deflateSetHeader() may be called - after deflateInit2() or deflateReset() and before the first call of - deflate(). The text, time, os, extra field, name, and comment information - in the provided gz_header structure are written to the gzip header (xflag is - ignored -- the extra flags are set according to the compression level). The - caller must assure that, if not Z_NULL, name and comment are terminated with - a zero byte, and that if extra is not Z_NULL, that extra_len bytes are - available there. If hcrc is true, a gzip header crc is included. Note that - the current versions of the command-line version of gzip (up through version - 1.3.x) do not support header crc's, and will report that it is a "multi-part - gzip file" and give up. - - If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to the current operating system, with no - extra, name, or comment fields. The gzip header is returned to the default - state by deflateReset(). - - deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2(z_streamp strm, - int windowBits); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. windowBits must be greater than or equal to the windowBits value - provided to deflateInit2() while compressing, or it must be equal to 15 if - deflateInit2() was not used. If a compressed stream with a larger window - size is given as input, inflate() will return with the error code - Z_DATA_ERROR instead of trying to allocate a larger window. - - windowBits can also be zero to request that inflate use the window size in - the zlib header of the compressed stream. - - windowBits can also be -8..-15 for raw inflate. In this case, -windowBits - determines the window size. inflate() will then process raw deflate data, - not looking for a zlib or gzip header, not generating a check value, and not - looking for any check values for comparison at the end of the stream. This - is for use with other formats that use the deflate compressed data format - such as zip. Those formats provide their own check values. If a custom - format is developed using the raw deflate format for compressed data, it is - recommended that a check value such as an Adler-32 or a CRC-32 be applied to - the uncompressed data as is done in the zlib, gzip, and zip formats. For - most applications, the zlib format should be used as is. Note that comments - above on the use in deflateInit2() applies to the magnitude of windowBits. - - windowBits can also be greater than 15 for optional gzip decoding. Add - 32 to windowBits to enable zlib and gzip decoding with automatic header - detection, or add 16 to decode only the gzip format (the zlib format will - return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a - CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see - below), inflate() will *not* automatically decode concatenated gzip members. - inflate() will return Z_STREAM_END at the end of the gzip member. The state - would need to be reset to continue decoding a subsequent gzip member. This - *must* be done if there is more data after a gzip member, in order for the - decompression to be compliant with the gzip standard (RFC 1952). - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller, or Z_STREAM_ERROR if the parameters are - invalid, such as a null pointer to the structure. msg is set to null if - there is no error message. inflateInit2 does not perform any decompression - apart from possibly reading the zlib header if present: actual decompression - will be done by inflate(). (So next_in and avail_in may be modified, but - next_out and avail_out are unused and unchanged.) The current implementation - of inflateInit2() does not process any header information -- that is - deferred until inflate() is called. -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, - const Bytef *dictionary, - uInt dictLength); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate, - if that call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the Adler-32 value returned by that call of inflate. - The compressor and decompressor must use exactly the same dictionary (see - deflateSetDictionary). For raw inflate, this function can be called at any - time to set the dictionary. If the provided dictionary is smaller than the - window and there is already data in the window, then the provided dictionary - will amend what's there. The application must insure that the dictionary - that was used for compression is provided. - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect Adler-32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, - Bytef *dictionary, - uInt *dictLength); -/* - Returns the sliding dictionary being maintained by inflate. dictLength is - set to the number of bytes in the dictionary, and that many bytes are copied - to dictionary. dictionary must have enough space, where 32768 bytes is - always enough. If inflateGetDictionary() is called with dictionary equal to - Z_NULL, then only the dictionary length is returned, and nothing is copied. - Similarly, if dictLength is Z_NULL, then it is not set. - - inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the - stream state is inconsistent. -*/ - -ZEXTERN int ZEXPORT inflateSync(z_streamp strm); -/* - Skips invalid compressed data until a possible full flush point (see above - for the description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync searches for a 00 00 FF FF pattern in the compressed data. - All full flush points have this pattern, but not all occurrences of this - pattern are full flush points. - - inflateSync returns Z_OK if a possible full flush point has been found, - Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point - has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current value of total_in - which indicates where valid compressed data was found. In the error case, - the application may repeatedly call inflateSync, providing more input each - time, until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, - z_streamp source); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when randomly accessing a large stream. The - first pass through the stream can periodically record the inflate state, - allowing restarting inflate at those points when randomly accessing the - stream. - - inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being Z_NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT inflateReset(z_streamp strm); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate the internal decompression state. The - stream will keep attributes that may have been set by inflateInit2. - total_in, total_out, adler, and msg are initialized. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL). -*/ - -ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, - int windowBits); -/* - This function is the same as inflateReset, but it also permits changing - the wrap and window size requests. The windowBits parameter is interpreted - the same as it is for inflateInit2. If the window size is changed, then the - memory allocated for the window is freed, and the window will be reallocated - by inflate() if needed. - - inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL), or if - the windowBits parameter is invalid. -*/ - -ZEXTERN int ZEXPORT inflatePrime(z_streamp strm, - int bits, - int value); -/* - This function inserts bits in the inflate input stream. The intent is - that this function is used to start inflating at a bit position in the - middle of a byte. The provided bits will be used before any bytes are used - from next_in. This function should only be used with raw inflate, and - should be used before the first inflate() call after inflateInit2() or - inflateReset(). bits must be less than or equal to 16, and that many of the - least significant bits of value will be inserted in the input. - - If bits is negative, then the input stream bit buffer is emptied. Then - inflatePrime() can be called again to put bits in the buffer. This is used - to clear out bits leftover after feeding inflate a block description prior - to feeding inflate codes. - - inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -ZEXTERN long ZEXPORT inflateMark(z_streamp strm); -/* - This function returns two values, one in the lower 16 bits of the return - value, and the other in the remaining upper bits, obtained by shifting the - return value down 16 bits. If the upper value is -1 and the lower value is - zero, then inflate() is currently decoding information outside of a block. - If the upper value is -1 and the lower value is non-zero, then inflate is in - the middle of a stored block, with the lower value equaling the number of - bytes from the input remaining to copy. If the upper value is not -1, then - it is the number of bits back from the current bit position in the input of - the code (literal or length/distance pair) currently being processed. In - that case the lower value is the number of bytes already emitted for that - code. - - A code is being processed if inflate is waiting for more input to complete - decoding of the code, or if it has completed decoding but is waiting for - more output space to write the literal or match data. - - inflateMark() is used to mark locations in the input data for random - access, which may be at bit positions, and to note those cases where the - output of a code may span boundaries of random access blocks. The current - location in the input stream can be determined from avail_in and data_type - as noted in the description for the Z_BLOCK flush parameter for inflate. - - inflateMark returns the value noted above, or -65536 if the provided - source stream state was inconsistent. -*/ - -ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, - gz_headerp head); -/* - inflateGetHeader() requests that gzip header information be stored in the - provided gz_header structure. inflateGetHeader() may be called after - inflateInit2() or inflateReset(), and before the first call of inflate(). - As inflate() processes the gzip stream, head->done is zero until the header - is completed, at which time head->done is set to one. If a zlib stream is - being decoded, then head->done is set to -1 to indicate that there will be - no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be - used to force inflate() to return immediately after header processing is - complete and before any actual data is decompressed. - - The text, time, xflags, and os fields are filled in with the gzip header - contents. hcrc is set to true if there is a header CRC. (The header CRC - was valid if done is set to one.) If extra is not Z_NULL, then extra_max - contains the maximum number of bytes to write to extra. Once done is true, - extra_len contains the actual extra field length, and extra contains the - extra field, or that field truncated if extra_max is less than extra_len. - If name is not Z_NULL, then up to name_max characters are written there, - terminated with a zero unless the length is greater than name_max. If - comment is not Z_NULL, then up to comm_max characters are written there, - terminated with a zero unless the length is greater than comm_max. When any - of extra, name, or comment are not Z_NULL and the respective field is not - present in the header, then that field is set to Z_NULL to signal its - absence. This allows the use of deflateSetHeader() with the returned - structure to duplicate the header. However if those fields are set to - allocated memory, then the application will need to save those pointers - elsewhere so that they can be eventually freed. - - If inflateGetHeader is not used, then the header information is simply - discarded. The header is always checked for validity, including the header - CRC if present. inflateReset() will reset the process to discard the header - information. The application would need to call inflateGetHeader() again to - retrieve the header from the next gzip stream. - - inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits, - unsigned char FAR *window); - - Initialize the internal stream state for decompression using inflateBack() - calls. The fields zalloc, zfree and opaque in strm must be initialized - before the call. If zalloc and zfree are Z_NULL, then the default library- - derived memory allocation routines are used. windowBits is the base two - logarithm of the window size, in the range 8..15. window is a caller - supplied buffer of that size. Except for special applications where it is - assured that deflate was used with small window sizes, windowBits must be 15 - and a 32K byte window must be supplied to be able to decompress general - deflate streams. - - See inflateBack() for the usage of these routines. - - inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of - the parameters are invalid, Z_MEM_ERROR if the internal state could not be - allocated, or Z_VERSION_ERROR if the version of the library does not match - the version of the header file. -*/ - -typedef unsigned (*in_func)(void FAR *, - z_const unsigned char FAR * FAR *); -typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned); - -ZEXTERN int ZEXPORT inflateBack(z_streamp strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc); -/* - inflateBack() does a raw inflate with a single call using a call-back - interface for input and output. This is potentially more efficient than - inflate() for file i/o applications, in that it avoids copying between the - output and the sliding window by simply making the window itself the output - buffer. inflate() can be faster on modern CPUs when used with large - buffers. inflateBack() trusts the application to not change the output - buffer passed by the output function, at least until inflateBack() returns. - - inflateBackInit() must be called first to allocate the internal state - and to initialize the state with the user-provided window buffer. - inflateBack() may then be used multiple times to inflate a complete, raw - deflate stream with each call. inflateBackEnd() is then called to free the - allocated state. - - A raw deflate stream is one with no zlib or gzip header or trailer. - This routine would normally be used in a utility that reads zip or gzip - files and writes out uncompressed files. The utility would decode the - header and process the trailer on its own, hence this routine expects only - the raw deflate stream to decompress. This is different from the default - behavior of inflate(), which expects a zlib header and trailer around the - deflate stream. - - inflateBack() uses two subroutines supplied by the caller that are then - called by inflateBack() for input and output. inflateBack() calls those - routines until it reads a complete deflate stream and writes out all of the - uncompressed data, or until it encounters an error. The function's - parameters and return types are defined above in the in_func and out_func - typedefs. inflateBack() will call in(in_desc, &buf) which should return the - number of bytes of provided input, and a pointer to that input in buf. If - there is no input available, in() must return zero -- buf is ignored in that - case -- and inflateBack() will return a buffer error. inflateBack() will - call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. - out() should return zero on success, or non-zero on failure. If out() - returns non-zero, inflateBack() will return with an error. Neither in() nor - out() are permitted to change the contents of the window provided to - inflateBackInit(), which is also the buffer that out() uses to write from. - The length written by out() will be at most the window size. Any non-zero - amount of input may be provided by in(). - - For convenience, inflateBack() can be provided input on the first call by - setting strm->next_in and strm->avail_in. If that input is exhausted, then - in() will be called. Therefore strm->next_in must be initialized before - calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called - immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in - must also be initialized, and then if strm->avail_in is not zero, input will - initially be taken from strm->next_in[0 .. strm->avail_in - 1]. - - The in_desc and out_desc parameters of inflateBack() is passed as the - first parameter of in() and out() respectively when they are called. These - descriptors can be optionally used to pass any information that the caller- - supplied in() and out() functions need to do their job. - - On return, inflateBack() will set strm->next_in and strm->avail_in to - pass back any unused input that was provided by the last in() call. The - return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR - if in() or out() returned an error, Z_DATA_ERROR if there was a format error - in the deflate stream (in which case strm->msg is set to indicate the nature - of the error), or Z_STREAM_ERROR if the stream was not properly initialized. - In the case of Z_BUF_ERROR, an input or output error can be distinguished - using strm->next_in which will be Z_NULL only if in() returned an error. If - strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning - non-zero. (in() will always be called before out(), so strm->next_in is - assured to be defined if out() returns non-zero.) Note that inflateBack() - cannot return Z_OK. -*/ - -ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm); -/* - All memory allocated by inflateBackInit() is freed. - - inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream - state was inconsistent. -*/ - -ZEXTERN uLong ZEXPORT zlibCompileFlags(void); -/* Return flags indicating compile-time options. - - Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: - 1.0: size of uInt - 3.2: size of uLong - 5.4: size of voidpf (pointer) - 7.6: size of z_off_t - - Compiler, assembler, and debug options: - 8: ZLIB_DEBUG - 9: ASMV or ASMINF -- use ASM code - 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention - 11: 0 (reserved) - - One-time table building (smaller code, but not thread-safe if true): - 12: BUILDFIXED -- build static block decoding tables when needed - 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed - 14,15: 0 (reserved) - - Library content (indicates missing functionality): - 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking - deflate code when not needed) - 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect - and decode gzip streams (to avoid linking crc code) - 18-19: 0 (reserved) - - Operation variations (changes in library functionality): - 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate - 21: FASTEST -- deflate algorithm with only one, lowest compression level - 22,23: 0 (reserved) - - The sprintf variant used by gzprintf (zero is best): - 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format - 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! - 26: 0 = returns value, 1 = void -- 1 means inferred string length returned - - Remainder: - 27-31: 0 (reserved) - */ - -#ifndef Z_SOLO - - /* utility functions */ - -/* - The following utility functions are implemented on top of the basic - stream-oriented functions. To simplify the interface, some default options - are assumed (compression level and memory usage, standard memory allocation - functions). The source code of these utility functions can be modified if - you need special options. -*/ - -ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total size - of the destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed data. compress() is equivalent to compress2() with a level - parameter of Z_DEFAULT_COMPRESSION. - - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed data. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); -/* - compressBound() returns an upper bound on the compressed size after - compress() or compress2() on sourceLen bytes. It would be used before a - compress() or compress2() call to allocate the destination buffer. -*/ - -ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total size - of the destination buffer, which must be large enough to hold the entire - uncompressed data. (The size of the uncompressed data must have been saved - previously by the compressor and transmitted to the decompressor by some - mechanism outside the scope of this compression library.) Upon exit, destLen - is the actual size of the uncompressed data. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In - the case where there is not enough room, uncompress() will fill the output - buffer with the uncompressed data up to that point. -*/ - -ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, - const Bytef *source, uLong *sourceLen); -/* - Same as uncompress, except that sourceLen is a pointer, where the - length of the source is *sourceLen. On return, *sourceLen is the number of - source bytes consumed. -*/ - - /* gzip file access functions */ - -/* - This library supports reading and writing files in gzip (.gz) format with - an interface similar to that of stdio, using the functions that start with - "gz". The gzip format is different from the zlib format. gzip is a gzip - wrapper, documented in RFC 1952, wrapped around a deflate stream. -*/ - -typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ - -/* -ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode); - - Open the gzip (.gz) file at path for reading and decompressing, or - compressing and writing. The mode parameter is as in fopen ("rb" or "wb") - but can also include a compression level ("wb9") or a strategy: 'f' for - filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h", - 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression - as in "wb9F". (See the description of deflateInit2 for more information - about the strategy parameter.) 'T' will request transparent writing or - appending with no compression and not using the gzip format. - - "a" can be used instead of "w" to request that the gzip stream that will - be written be appended to the file. "+" will result in an error, since - reading and writing to the same gzip file is not supported. The addition of - "x" when writing will create the file exclusively, which fails if the file - already exists. On systems that support it, the addition of "e" when - reading or writing will set the flag to close the file on an execve() call. - - These functions, as well as gzip, will read and decode a sequence of gzip - streams in a file. The append function of gzopen() can be used to create - such a file. (Also see gzflush() for another way to do this.) When - appending, gzopen does not test whether the file begins with a gzip stream, - nor does it look for the end of the gzip streams to begin appending. gzopen - will simply append a gzip stream to the existing file. - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. When - reading, this will be detected automatically by looking for the magic two- - byte gzip header. - - gzopen returns NULL if the file could not be opened, if there was - insufficient memory to allocate the gzFile state, or if an invalid mode was - specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). - errno can be checked to determine if the reason gzopen failed was that the - file could not be opened. -*/ - -ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode); -/* - Associate a gzFile with the file descriptor fd. File descriptors are - obtained from calls like open, dup, creat, pipe or fileno (if the file has - been previously opened with fopen). The mode parameter is as in gzopen. - - The next call of gzclose on the returned gzFile will also close the file - descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor - fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, - mode);. The duplicated descriptor should be saved to avoid a leak, since - gzdopen does not close fd if it fails. If you are using fileno() to get the - file descriptor from a FILE *, then you will have to use dup() to avoid - double-close()ing the file descriptor. Both gzclose() and fclose() will - close the associated file descriptor, so they need to have different file - descriptors. - - gzdopen returns NULL if there was insufficient memory to allocate the - gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not - provided, or '+' was provided), or if fd is -1. The file descriptor is not - used until the next gz* read, write, seek, or close operation, so gzdopen - will not detect if fd is invalid (unless fd is -1). -*/ - -ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size); -/* - Set the internal buffer size used by this library's functions for file to - size. The default buffer size is 8192 bytes. This function must be called - after gzopen() or gzdopen(), and before any other calls that read or write - the file. The buffer memory allocation is always deferred to the first read - or write. Three times that size in buffer space is allocated. A larger - buffer size of, for example, 64K or 128K bytes will noticeably increase the - speed of decompression (reading). - - The new buffer size also affects the maximum length for gzprintf(). - - gzbuffer() returns 0 on success, or -1 on failure, such as being called - too late. -*/ - -ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy); -/* - Dynamically update the compression level and strategy for file. See the - description of deflateInit2 for the meaning of these parameters. Previously - provided data is flushed before applying the parameter changes. - - gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not - opened for writing, Z_ERRNO if there is an error writing the flushed data, - or Z_MEM_ERROR if there is a memory allocation error. -*/ - -ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len); -/* - Read and decompress up to len uncompressed bytes from file into buf. If - the input file is not in gzip format, gzread copies the given number of - bytes into the buffer directly from the file. - - After reaching the end of a gzip stream in the input, gzread will continue - to read, looking for another gzip stream. Any number of gzip streams may be - concatenated in the input file, and will all be decompressed by gzread(). - If something other than a gzip stream is encountered after a gzip stream, - that remaining trailing garbage is ignored (and no error is returned). - - gzread can be used to read a gzip file that is being concurrently written. - Upon reaching the end of the input, gzread will return with the available - data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then - gzclearerr can be used to clear the end of file indicator in order to permit - gzread to be tried again. Z_OK indicates that a gzip stream was completed - on the last gzread. Z_BUF_ERROR indicates that the input file ended in the - middle of a gzip stream. Note that gzread does not return -1 in the event - of an incomplete gzip stream. This error is deferred until gzclose(), which - will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip - stream. Alternatively, gzerror can be used before gzclose to detect this - case. - - gzread returns the number of uncompressed bytes actually read, less than - len for end of file, or -1 for error. If len is too large to fit in an int, - then nothing is read, -1 is returned, and the error state is set to - Z_STREAM_ERROR. -*/ - -ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, - gzFile file); -/* - Read and decompress up to nitems items of size size from file into buf, - otherwise operating as gzread() does. This duplicates the interface of - stdio's fread(), with size_t request and return types. If the library - defines size_t, then z_size_t is identical to size_t. If not, then z_size_t - is an unsigned integer type that can contain a pointer. - - gzfread() returns the number of full items read of size size, or zero if - the end of the file was reached and a full item could not be read, or if - there was an error. gzerror() must be consulted if zero is returned in - order to determine if there was an error. If the multiplication of size and - nitems overflows, i.e. the product does not fit in a z_size_t, then nothing - is read, zero is returned, and the error state is set to Z_STREAM_ERROR. - - In the event that the end of file is reached and only a partial item is - available at the end, i.e. the remaining uncompressed data length is not a - multiple of size, then the final partial item is nevertheless read into buf - and the end-of-file flag is set. The length of the partial item read is not - provided, but could be inferred from the result of gztell(). This behavior - is the same as the behavior of fread() implementations in common libraries, - but it prevents the direct use of gzfread() to read a concurrently written - file, resetting and retrying on end-of-file, when size is not 1. -*/ - -ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); -/* - Compress and write the len uncompressed bytes at buf to file. gzwrite - returns the number of uncompressed bytes written or 0 in case of error. -*/ - -ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, - z_size_t nitems, gzFile file); -/* - Compress and write nitems items of size size from buf to file, duplicating - the interface of stdio's fwrite(), with size_t request and return types. If - the library defines size_t, then z_size_t is identical to size_t. If not, - then z_size_t is an unsigned integer type that can contain a pointer. - - gzfwrite() returns the number of full items written of size size, or zero - if there was an error. If the multiplication of size and nitems overflows, - i.e. the product does not fit in a z_size_t, then nothing is written, zero - is returned, and the error state is set to Z_STREAM_ERROR. -*/ - -ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...); -/* - Convert, format, compress, and write the arguments (...) to file under - control of the string format, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written, or a negative zlib error code in case - of error. The number of uncompressed bytes written is limited to 8191, or - one less than the buffer size given to gzbuffer(). The caller should assure - that this limit is not exceeded. If it is exceeded, then gzprintf() will - return an error (0) with nothing written. In this case, there may also be a - buffer overflow with unpredictable consequences, which is possible only if - zlib was compiled with the insecure functions sprintf() or vsprintf(), - because the secure snprintf() or vsnprintf() functions were not available. - This can be determined using zlibCompileFlags(). -*/ - -ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); -/* - Compress and write the given null-terminated string s to file, excluding - the terminating null character. - - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); -/* - Read and decompress bytes from file into buf, until len-1 characters are - read, or until a newline character is read and transferred to buf, or an - end-of-file condition is encountered. If any characters are read or if len - is one, the string is terminated with a null character. If no characters - are read due to an end-of-file or len is less than one, then the buffer is - left untouched. - - gzgets returns buf which is a null-terminated string, or it returns NULL - for end-of-file or in case of error. If there was an error, the contents at - buf are indeterminate. -*/ - -ZEXTERN int ZEXPORT gzputc(gzFile file, int c); -/* - Compress and write c, converted to an unsigned char, into file. gzputc - returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc(gzFile file); -/* - Read and decompress one byte from file. gzgetc returns this byte or -1 - in case of end of file or error. This is implemented as a macro for speed. - As such, it does not do all of the checking the other functions do. I.e. - it does not check to see if file is NULL, nor whether the structure file - points to has been clobbered or not. -*/ - -ZEXTERN int ZEXPORT gzungetc(int c, gzFile file); -/* - Push c back onto the stream for file to be read as the first character on - the next read. At least one character of push-back is always allowed. - gzungetc() returns the character pushed, or -1 on failure. gzungetc() will - fail if c is -1, and may fail if a character has been pushed but not read - yet. If gzungetc is used immediately after gzopen or gzdopen, at least the - output buffer size of pushed characters is allowed. (See gzbuffer above.) - The pushed character will be discarded if the stream is repositioned with - gzseek() or gzrewind(). -*/ - -ZEXTERN int ZEXPORT gzflush(gzFile file, int flush); -/* - Flush all pending output to file. The parameter flush is as in the - deflate() function. The return value is the zlib error number (see function - gzerror below). gzflush is only permitted when writing. - - If the flush parameter is Z_FINISH, the remaining data is written and the - gzip stream is completed in the output. If gzwrite() is called again, a new - gzip stream will be started in the output. gzread() is able to read such - concatenated gzip streams. - - gzflush should be called only when strictly necessary because it will - degrade compression if called too often. -*/ - -/* -ZEXTERN z_off_t ZEXPORT gzseek(gzFile file, - z_off_t offset, int whence); - - Set the starting position to offset relative to whence for the next gzread - or gzwrite on file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind(gzFile file); -/* - Rewind file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET). -*/ - -/* -ZEXTERN z_off_t ZEXPORT gztell(gzFile file); - - Return the starting position for the next gzread or gzwrite on file. - This position represents a number of bytes in the uncompressed data stream, - and is zero when starting, even if appending or reading a gzip stream from - the middle of a file using gzdopen(). - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -/* -ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file); - - Return the current compressed (actual) read or write offset of file. This - offset includes the count of bytes that precede the gzip stream, for example - when appending or when using gzdopen() for reading. When reading, the - offset does not include as yet unused buffered input. This information can - be used for a progress indicator. On error, gzoffset() returns -1. -*/ - -ZEXTERN int ZEXPORT gzeof(gzFile file); -/* - Return true (1) if the end-of-file indicator for file has been set while - reading, false (0) otherwise. Note that the end-of-file indicator is set - only if the read tried to go past the end of the input, but came up short. - Therefore, just like feof(), gzeof() may return false even if there is no - more data to read, in the event that the last read request was for the exact - number of bytes remaining in the input file. This will happen if the input - file size is an exact multiple of the buffer size. - - If gzeof() returns true, then the read functions will return no more data, - unless the end-of-file indicator is reset by gzclearerr() and the input file - has grown since the previous end of file was detected. -*/ - -ZEXTERN int ZEXPORT gzdirect(gzFile file); -/* - Return true (1) if file is being copied directly while reading, or false - (0) if file is a gzip stream being decompressed. - - If the input file is empty, gzdirect() will return true, since the input - does not contain a gzip stream. - - If gzdirect() is used immediately after gzopen() or gzdopen() it will - cause buffers to be allocated to allow reading the file to determine if it - is a gzip file. Therefore if gzbuffer() is used, it should be called before - gzdirect(). - - When writing, gzdirect() returns true (1) if transparent writing was - requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: - gzdirect() is not needed when writing. Transparent writing must be - explicitly requested, so the application already knows the answer. When - linking statically, using gzdirect() will include all of the zlib code for - gzip file reading and decompression, which may not be desired.) -*/ - -ZEXTERN int ZEXPORT gzclose(gzFile file); -/* - Flush all pending output for file, if necessary, close file and - deallocate the (de)compression state. Note that once file is closed, you - cannot call gzerror with file, since its structures have been deallocated. - gzclose must not be called more than once on the same file, just as free - must not be called more than once on the same allocation. - - gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a - file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the - last read ended in the middle of a gzip stream, or Z_OK on success. -*/ - -ZEXTERN int ZEXPORT gzclose_r(gzFile file); -ZEXTERN int ZEXPORT gzclose_w(gzFile file); -/* - Same as gzclose(), but gzclose_r() is only for use when reading, and - gzclose_w() is only for use when writing or appending. The advantage to - using these instead of gzclose() is that they avoid linking in zlib - compression or decompression code that is not used when only reading or only - writing respectively. If gzclose() is used, then both compression and - decompression code will be included the application when linking to a static - zlib library. -*/ - -ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); -/* - Return the error message for the last error which occurred on file. - errnum is set to zlib error number. If an error occurred in the file system - and not in the compression library, errnum is set to Z_ERRNO and the - application may consult errno to get the exact error code. - - The application must not modify the returned string. Future calls to - this function may invalidate the previously returned string. If file is - closed, then the string previously returned by gzerror will no longer be - available. - - gzerror() should be used to distinguish errors from end-of-file for those - functions above that do not distinguish those cases in their return values. -*/ - -ZEXTERN void ZEXPORT gzclearerr(gzFile file); -/* - Clear the error and end-of-file flags for file. This is analogous to the - clearerr() function in stdio. This is useful for continuing to read a gzip - file that is being written concurrently. -*/ - -#endif /* !Z_SOLO */ - - /* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the compression - library. -*/ - -ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len); -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. An Adler-32 value is in the range of a 32-bit - unsigned integer. If buf is Z_NULL, this function returns the required - initial value for the checksum. - - An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed - much faster. - - Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, - z_size_t len); -/* - Same as adler32(), but with a size_t length. -*/ - -/* -ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, - z_off_t len2); - - Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 - and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for - each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of - seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note - that the z_off_t type (like off_t) is a signed integer. If len2 is - negative, the result has no meaning or utility. -*/ - -ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len); -/* - Update a running CRC-32 with the bytes buf[0..len-1] and return the - updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. - If buf is Z_NULL, this function returns the required initial value for the - crc. Pre- and post-conditioning (one's complement) is performed within this - function so it shouldn't be done by the application. - - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - -ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, - z_size_t len); -/* - Same as crc32(), but with a size_t length. -*/ - -/* -ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); - - Combine two CRC-32 check values into one. For two sequences of bytes, - seq1 and seq2 with lengths len1 and len2, CRC-32 check values were - calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 - check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. len2 must be non-negative. -*/ - -/* -ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); - - Return the operator corresponding to length len2, to be used with - crc32_combine_op(). len2 must be non-negative. -*/ - -ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); -/* - Give the same result as crc32_combine(), using op in place of len2. op is - is generated from len2 by crc32_combine_gen(). This will be faster than - crc32_combine() if the generated op is used more than once. -*/ - - - /* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, - const char *version, int stream_size); -ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, - const char *version, int stream_size); -ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size); -ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, - const char *version, int stream_size); -ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size); -#ifdef Z_PREFIX_SET -# define z_deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) -# define z_inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) -# define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) -# define z_inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ - (int)sizeof(z_stream)) -# define z_inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, (int)sizeof(z_stream)) -#else -# define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) -# define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) -# define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) -# define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ - (int)sizeof(z_stream)) -# define inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, (int)sizeof(z_stream)) -#endif - -#ifndef Z_SOLO - -/* gzgetc() macro and its supporting function and exposed data structure. Note - * that the real internal state is much larger than the exposed structure. - * This abbreviated structure exposes just enough for the gzgetc() macro. The - * user should not mess with these exposed elements, since their names or - * behavior could change in the future, perhaps even capriciously. They can - * only be used by the gzgetc() macro. You have been warned. - */ -struct gzFile_s { - unsigned have; - unsigned char *next; - z_off64_t pos; -}; -ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ -#ifdef Z_PREFIX_SET -# undef z_gzgetc -# define z_gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) -#else -# define gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) -#endif - -/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or - * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if - * both are true, the application gets the *64 functions, and the regular - * functions are changed to 64 bits) -- in case these are set on systems - * without large file support, _LFS64_LARGEFILE must also be true - */ -#ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); - ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); - ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); - ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); - ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); - ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); -#endif - -#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) -# ifdef Z_PREFIX_SET -# define z_gzopen z_gzopen64 -# define z_gzseek z_gzseek64 -# define z_gztell z_gztell64 -# define z_gzoffset z_gzoffset64 -# define z_adler32_combine z_adler32_combine64 -# define z_crc32_combine z_crc32_combine64 -# define z_crc32_combine_gen z_crc32_combine_gen64 -# else -# define gzopen gzopen64 -# define gzseek gzseek64 -# define gztell gztell64 -# define gzoffset gzoffset64 -# define adler32_combine adler32_combine64 -# define crc32_combine crc32_combine64 -# define crc32_combine_gen crc32_combine_gen64 -# endif -# ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); - ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); - ZEXTERN z_off_t ZEXPORT gztell64(gzFile); - ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); - ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); -# endif -#else - ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); - ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); - ZEXTERN z_off_t ZEXPORT gztell(gzFile); - ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); - ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); -#endif - -#else /* Z_SOLO */ - - ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); - -#endif /* !Z_SOLO */ - -/* undocumented functions */ -ZEXTERN const char * ZEXPORT zError(int); -ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void); -ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); -ZEXTERN int ZEXPORT inflateValidate(z_streamp, int); -ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); -ZEXTERN int ZEXPORT inflateResetKeep(z_streamp); -ZEXTERN int ZEXPORT deflateResetKeep(z_streamp); -#if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, - const char *mode); -#endif -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, - const char *format, - va_list va); -# endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* ZLIB_H */ diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/zutil.c b/vendor/libgit2-sys/libgit2/deps/zlib/zutil.c deleted file mode 100644 index b1c5d2d..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/zutil.c +++ /dev/null @@ -1,299 +0,0 @@ -/* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-2017 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zutil.h" -#ifndef Z_SOLO -# include "gzguts.h" -#endif - -z_const char * const z_errmsg[10] = { - (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */ - (z_const char *)"stream end", /* Z_STREAM_END 1 */ - (z_const char *)"", /* Z_OK 0 */ - (z_const char *)"file error", /* Z_ERRNO (-1) */ - (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */ - (z_const char *)"data error", /* Z_DATA_ERROR (-3) */ - (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */ - (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */ - (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */ - (z_const char *)"" -}; - - -const char * ZEXPORT zlibVersion(void) { - return ZLIB_VERSION; -} - -uLong ZEXPORT zlibCompileFlags(void) { - uLong flags; - - flags = 0; - switch ((int)(sizeof(uInt))) { - case 2: break; - case 4: flags += 1; break; - case 8: flags += 2; break; - default: flags += 3; - } - switch ((int)(sizeof(uLong))) { - case 2: break; - case 4: flags += 1 << 2; break; - case 8: flags += 2 << 2; break; - default: flags += 3 << 2; - } - switch ((int)(sizeof(voidpf))) { - case 2: break; - case 4: flags += 1 << 4; break; - case 8: flags += 2 << 4; break; - default: flags += 3 << 4; - } - switch ((int)(sizeof(z_off_t))) { - case 2: break; - case 4: flags += 1 << 6; break; - case 8: flags += 2 << 6; break; - default: flags += 3 << 6; - } -#ifdef ZLIB_DEBUG - flags += 1 << 8; -#endif - /* -#if defined(ASMV) || defined(ASMINF) - flags += 1 << 9; -#endif - */ -#ifdef ZLIB_WINAPI - flags += 1 << 10; -#endif -#ifdef BUILDFIXED - flags += 1 << 12; -#endif -#ifdef DYNAMIC_CRC_TABLE - flags += 1 << 13; -#endif -#ifdef NO_GZCOMPRESS - flags += 1L << 16; -#endif -#ifdef NO_GZIP - flags += 1L << 17; -#endif -#ifdef PKZIP_BUG_WORKAROUND - flags += 1L << 20; -#endif -#ifdef FASTEST - flags += 1L << 21; -#endif -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifdef NO_vsnprintf - flags += 1L << 25; -# ifdef HAS_vsprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_vsnprintf_void - flags += 1L << 26; -# endif -# endif -#else - flags += 1L << 24; -# ifdef NO_snprintf - flags += 1L << 25; -# ifdef HAS_sprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_snprintf_void - flags += 1L << 26; -# endif -# endif -#endif - return flags; -} - -#ifdef ZLIB_DEBUG -#include -# ifndef verbose -# define verbose 0 -# endif -int ZLIB_INTERNAL z_verbose = verbose; - -void ZLIB_INTERNAL z_error(char *m) { - fprintf(stderr, "%s\n", m); - exit(1); -} -#endif - -/* exported to allow conversion of error code to string for compress() and - * uncompress() - */ -const char * ZEXPORT zError(int err) { - return ERR_MSG(err); -} - -#if defined(_WIN32_WCE) && _WIN32_WCE < 0x800 - /* The older Microsoft C Run-Time Library for Windows CE doesn't have - * errno. We define it as a global variable to simplify porting. - * Its value is always 0 and should not be used. - */ - int errno = 0; -#endif - -#ifndef HAVE_MEMCPY - -void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) { - if (len == 0) return; - do { - *dest++ = *source++; /* ??? to be unrolled */ - } while (--len != 0); -} - -int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) { - uInt j; - - for (j = 0; j < len; j++) { - if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; - } - return 0; -} - -void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) { - if (len == 0) return; - do { - *dest++ = 0; /* ??? to be unrolled */ - } while (--len != 0); -} -#endif - -#ifndef Z_SOLO - -#ifdef SYS16BIT - -#ifdef __TURBOC__ -/* Turbo C in 16-bit mode */ - -# define MY_ZCALLOC - -/* Turbo C malloc() does not allow dynamic allocation of 64K bytes - * and farmalloc(64K) returns a pointer with an offset of 8, so we - * must fix the pointer. Warning: the pointer must be put back to its - * original form in order to free it, use zcfree(). - */ - -#define MAX_PTR 10 -/* 10*64K = 640K */ - -local int next_ptr = 0; - -typedef struct ptr_table_s { - voidpf org_ptr; - voidpf new_ptr; -} ptr_table; - -local ptr_table table[MAX_PTR]; -/* This table is used to remember the original form of pointers - * to large buffers (64K). Such pointers are normalized with a zero offset. - * Since MSDOS is not a preemptive multitasking OS, this table is not - * protected from concurrent access. This hack doesn't work anyway on - * a protected system like OS/2. Use Microsoft C instead. - */ - -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { - voidpf buf; - ulg bsize = (ulg)items*size; - - (void)opaque; - - /* If we allocate less than 65520 bytes, we assume that farmalloc - * will return a usable pointer which doesn't have to be normalized. - */ - if (bsize < 65520L) { - buf = farmalloc(bsize); - if (*(ush*)&buf != 0) return buf; - } else { - buf = farmalloc(bsize + 16L); - } - if (buf == NULL || next_ptr >= MAX_PTR) return NULL; - table[next_ptr].org_ptr = buf; - - /* Normalize the pointer to seg:0 */ - *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; - *(ush*)&buf = 0; - table[next_ptr++].new_ptr = buf; - return buf; -} - -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { - int n; - - (void)opaque; - - if (*(ush*)&ptr != 0) { /* object < 64K */ - farfree(ptr); - return; - } - /* Find the original pointer */ - for (n = 0; n < next_ptr; n++) { - if (ptr != table[n].new_ptr) continue; - - farfree(table[n].org_ptr); - while (++n < next_ptr) { - table[n-1] = table[n]; - } - next_ptr--; - return; - } - Assert(0, "zcfree: ptr not found"); -} - -#endif /* __TURBOC__ */ - - -#ifdef M_I86 -/* Microsoft C in 16-bit mode */ - -# define MY_ZCALLOC - -#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) -# define _halloc halloc -# define _hfree hfree -#endif - -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) { - (void)opaque; - return _halloc((long)items, size); -} - -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { - (void)opaque; - _hfree(ptr); -} - -#endif /* M_I86 */ - -#endif /* SYS16BIT */ - - -#ifndef MY_ZCALLOC /* Any system without a special alloc function */ - -#ifndef STDC -extern voidp malloc(uInt size); -extern voidp calloc(uInt items, uInt size); -extern void free(voidpf ptr); -#endif - -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { - (void)opaque; - return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : - (voidpf)calloc(items, size); -} - -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { - (void)opaque; - free(ptr); -} - -#endif /* MY_ZCALLOC */ - -#endif /* !Z_SOLO */ diff --git a/vendor/libgit2-sys/libgit2/deps/zlib/zutil.h b/vendor/libgit2-sys/libgit2/deps/zlib/zutil.h deleted file mode 100644 index 48dd7fe..0000000 --- a/vendor/libgit2-sys/libgit2/deps/zlib/zutil.h +++ /dev/null @@ -1,254 +0,0 @@ -/* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef ZUTIL_H -#define ZUTIL_H - -#ifdef HAVE_HIDDEN -# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) -#else -# define ZLIB_INTERNAL -#endif - -#include "zlib.h" - -#if defined(STDC) && !defined(Z_SOLO) -# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) -# include -# endif -# include -# include -#endif - -#ifndef local -# define local static -#endif -/* since "static" is used to mean two completely different things in C, we - define "local" for the non-static meaning of "static", for readability - (compile with -Dlocal if your debugger can't find static symbols) */ - -typedef unsigned char uch; -typedef uch FAR uchf; -typedef unsigned short ush; -typedef ush FAR ushf; -typedef unsigned long ulg; - -#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC) -# include -# if (ULONG_MAX == 0xffffffffffffffff) -# define Z_U8 unsigned long -# elif (ULLONG_MAX == 0xffffffffffffffff) -# define Z_U8 unsigned long long -# elif (UINT_MAX == 0xffffffffffffffff) -# define Z_U8 unsigned -# endif -#endif - -extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ -/* (size given to avoid silly warnings with Visual C++) */ - -#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)] - -#define ERR_RETURN(strm,err) \ - return (strm->msg = ERR_MSG(err), (err)) -/* To be used only when the state is known to be valid */ - - /* common constants */ - -#ifndef DEF_WBITS -# define DEF_WBITS MAX_WBITS -#endif -/* default windowBits for decompression. MAX_WBITS is for compression only */ - -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -/* default memLevel */ - -#define STORED_BLOCK 0 -#define STATIC_TREES 1 -#define DYN_TREES 2 -/* The three kinds of block type */ - -#define MIN_MATCH 3 -#define MAX_MATCH 258 -/* The minimum and maximum match lengths */ - -#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - - /* target dependencies */ - -#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) -# define OS_CODE 0x00 -# ifndef Z_SOLO -# if defined(__TURBOC__) || defined(__BORLANDC__) -# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) - /* Allow compilation with ANSI keywords only enabled */ - void _Cdecl farfree( void *block ); - void *_Cdecl farmalloc( unsigned long nbytes ); -# else -# include -# endif -# else /* MSC or DJGPP */ -# include -# endif -# endif -#endif - -#ifdef AMIGA -# define OS_CODE 1 -#endif - -#if defined(VAXC) || defined(VMS) -# define OS_CODE 2 -# define F_OPEN(name, mode) \ - fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") -#endif - -#ifdef __370__ -# if __TARGET_LIB__ < 0x20000000 -# define OS_CODE 4 -# elif __TARGET_LIB__ < 0x40000000 -# define OS_CODE 11 -# else -# define OS_CODE 8 -# endif -#endif - -#if defined(ATARI) || defined(atarist) -# define OS_CODE 5 -#endif - -#ifdef OS2 -# define OS_CODE 6 -# if defined(M_I86) && !defined(Z_SOLO) -# include -# endif -#endif - -#if defined(MACOS) -# define OS_CODE 7 -#endif - -#ifdef __acorn -# define OS_CODE 13 -#endif - -#if defined(WIN32) && !defined(__CYGWIN__) -# define OS_CODE 10 -#endif - -#ifdef _BEOS_ -# define OS_CODE 16 -#endif - -#ifdef __TOS_OS400__ -# define OS_CODE 18 -#endif - -#ifdef __APPLE__ -# define OS_CODE 19 -#endif - -#if defined(__BORLANDC__) && !defined(MSDOS) - #pragma warn -8004 - #pragma warn -8008 - #pragma warn -8066 -#endif - -/* provide prototypes for these when building zlib without LFS */ -#if !defined(_WIN32) && \ - (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); -#endif - - /* common defaults */ - -#ifndef OS_CODE -# define OS_CODE 3 /* assume Unix */ -#endif - -#ifndef F_OPEN -# define F_OPEN(name, mode) fopen((name), (mode)) -#endif - - /* functions */ - -#if defined(pyr) || defined(Z_SOLO) -# define NO_MEMCPY -#endif -#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) - /* Use our own functions for small and medium model with MSC <= 5.0. - * You may have to use the same strategy for Borland C (untested). - * The __SC__ check is for Symantec. - */ -# define NO_MEMCPY -#endif -#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) -# define HAVE_MEMCPY -#endif -#ifdef HAVE_MEMCPY -# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ -# define zmemcpy _fmemcpy -# define zmemcmp _fmemcmp -# define zmemzero(dest, len) _fmemset(dest, 0, len) -# else -# define zmemcpy memcpy -# define zmemcmp memcmp -# define zmemzero(dest, len) memset(dest, 0, len) -# endif -#else - void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len); - int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len); - void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len); -#endif - -/* Diagnostic functions */ -#ifdef ZLIB_DEBUG -# include - extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error(char *m); -# define Assert(cond,msg) {if(!(cond)) z_error(msg);} -# define Trace(x) {if (z_verbose>=0) fprintf x ;} -# define Tracev(x) {if (z_verbose>0) fprintf x ;} -# define Tracevv(x) {if (z_verbose>1) fprintf x ;} -# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} -# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} -#else -# define Assert(cond,msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c,x) -# define Tracecv(c,x) -#endif - -#ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, - unsigned size); - void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr); -#endif - -#define ZALLOC(strm, items, size) \ - (*((strm)->zalloc))((strm)->opaque, (items), (size)) -#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) -#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} - -/* Reverse the bytes in a 32-bit value */ -#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ - (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) - -#endif /* ZUTIL_H */ diff --git a/vendor/libgit2-sys/libgit2/git.git-authors b/vendor/libgit2-sys/libgit2/git.git-authors deleted file mode 100644 index d9a9114..0000000 --- a/vendor/libgit2-sys/libgit2/git.git-authors +++ /dev/null @@ -1,77 +0,0 @@ -# This document lists the authors that have given voice to -# their decision regarding relicensing the GPL'd code from -# git.git to the GPL + gcc-exception license used by libgit2. -# -# Note that the permission is given for libgit2 use only. For -# other uses, you must ask each of the contributors yourself. -# -# To show the owners of a file in git.git, one can run the -# following command: -# -# git blame -C -C -M -- file | \ -# sed -e 's/[^(]*(\([^0-9]*\).*/\1/' -e 's/[\t ]*$//' | \ -# sort | uniq -c | sort -nr -# -# If everyone on the list that produces are on the list in -# the recently added file "git.git-authors", it *should* be -# safe to include that code in libgit2, but make sure to -# read the file to ensure the code doesn't originate from -# somewhere else. -# -# The format of this list is -# "ok/no/ask/???""Author""" -# -# "ok" means the author consents to relicensing all their -# contributed code (possibly with some exceptions) -# "no" means the author does not consent -# "ask" means that the contributor wants to give/withhold -# their consent on a patch-by-patch basis. -# "???" means the person is a prominent contributor who has -# not yet made their standpoint clear. -# -# Please try to keep the list alphabetically ordered. It will -# help in case we get all 600-ish git.git authors on it. -# -# (Paul Kocher is the author of the mozilla-sha1 implementation -# but has otherwise not contributed to git.) -# -ok Adam Simpkins (http transport) -ok Adrian Johnson -ok Alexey Shumkin -ok Andreas Ericsson -ok Antoine Pelisse -ok Boyd Lynn Gerber -ok Brandon Casey -ok Brian Downing -ok Brian Gernhardt -ok Christian Couder -ok Daniel Barkalow -ok Elijah Newren -ok Florian Forster -ok Gustaf Hendeby -ok Holger Weiss -ok Jeff King -ok Johannes Schindelin -ok Johannes Sixt -ask Jonathan Nieder -ok Jonathan Tan -ok Junio C Hamano -ok Kristian Høgsberg -ok Linus Torvalds -ok Lukas Sandström -ok Matthieu Moy -ok Michael Haggerty -ok Nicolas Pitre -ok Paolo Bonzini -ok Paul Kocher -ok Peter Hagervall -ok Petr Onderka -ok Pierre Habouzit -ok Pieter de Bie -ok René Scharfe -ok Sebastian Schuberth -ok Shawn O. Pearce -ok Steffen Prohaska -ok Sven Verdoolaege -ask Thomas Rast (ok before 6-Oct-2013) -ok Torsten Bögershausen diff --git a/vendor/libgit2-sys/libgit2/include/git2.h b/vendor/libgit2-sys/libgit2/include/git2.h deleted file mode 100644 index 3457e5f..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_git_git_h__ -#define INCLUDE_git_git_h__ - -#include "git2/annotated_commit.h" -#include "git2/apply.h" -#include "git2/attr.h" -#include "git2/blob.h" -#include "git2/blame.h" -#include "git2/branch.h" -#include "git2/buffer.h" -#include "git2/cert.h" -#include "git2/checkout.h" -#include "git2/cherrypick.h" -#include "git2/clone.h" -#include "git2/commit.h" -#include "git2/common.h" -#include "git2/config.h" -#include "git2/credential.h" -#include "git2/deprecated.h" -#include "git2/describe.h" -#include "git2/diff.h" -#include "git2/email.h" -#include "git2/errors.h" -#include "git2/experimental.h" -#include "git2/filter.h" -#include "git2/global.h" -#include "git2/graph.h" -#include "git2/ignore.h" -#include "git2/index.h" -#include "git2/indexer.h" -#include "git2/mailmap.h" -#include "git2/merge.h" -#include "git2/message.h" -#include "git2/net.h" -#include "git2/notes.h" -#include "git2/object.h" -#include "git2/odb.h" -#include "git2/odb_backend.h" -#include "git2/oid.h" -#include "git2/pack.h" -#include "git2/patch.h" -#include "git2/pathspec.h" -#include "git2/proxy.h" -#include "git2/rebase.h" -#include "git2/refdb.h" -#include "git2/reflog.h" -#include "git2/refs.h" -#include "git2/refspec.h" -#include "git2/remote.h" -#include "git2/repository.h" -#include "git2/reset.h" -#include "git2/revert.h" -#include "git2/revparse.h" -#include "git2/revwalk.h" -#include "git2/signature.h" -#include "git2/stash.h" -#include "git2/status.h" -#include "git2/submodule.h" -#include "git2/tag.h" -#include "git2/transport.h" -#include "git2/transaction.h" -#include "git2/tree.h" -#include "git2/types.h" -#include "git2/version.h" -#include "git2/worktree.h" - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/annotated_commit.h b/vendor/libgit2-sys/libgit2/include/git2/annotated_commit.h deleted file mode 100644 index 04f3b1c..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/annotated_commit.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_annotated_commit_h__ -#define INCLUDE_git_annotated_commit_h__ - -#include "common.h" -#include "repository.h" -#include "types.h" - -/** - * @file git2/annotated_commit.h - * @brief A commit and information about how it was looked up by the user. - * @defgroup git_annotated_commit Git annotated commit routines - * @ingroup Git - * - * An "annotated commit" is a commit that contains information about - * how the commit was resolved, which can be used for maintaining the - * user's "intent" through commands like merge and rebase. For example, - * if a user wants to "merge HEAD" then an annotated commit is used to - * both contain the HEAD commit _and_ the fact that it was resolved as - * the HEAD ref. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Creates a `git_annotated_commit` from the given reference. - * The resulting git_annotated_commit must be freed with - * `git_annotated_commit_free`. - * - * @param[out] out pointer to store the git_annotated_commit result in - * @param repo repository that contains the given reference - * @param ref reference to use to lookup the git_annotated_commit - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_annotated_commit_from_ref( - git_annotated_commit **out, - git_repository *repo, - const git_reference *ref); - -/** - * Creates a `git_annotated_commit` from the given fetch head data. - * The resulting git_annotated_commit must be freed with - * `git_annotated_commit_free`. - * - * @param[out] out pointer to store the git_annotated_commit result in - * @param repo repository that contains the given commit - * @param branch_name name of the (remote) branch - * @param remote_url url of the remote - * @param id the commit object id of the remote branch - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_annotated_commit_from_fetchhead( - git_annotated_commit **out, - git_repository *repo, - const char *branch_name, - const char *remote_url, - const git_oid *id); - -/** - * Creates a `git_annotated_commit` from the given commit id. - * The resulting git_annotated_commit must be freed with - * `git_annotated_commit_free`. - * - * An annotated commit contains information about how it was - * looked up, which may be useful for functions like merge or - * rebase to provide context to the operation. For example, - * conflict files will include the name of the source or target - * branches being merged. It is therefore preferable to use the - * most specific function (eg `git_annotated_commit_from_ref`) - * instead of this one when that data is known. - * - * @param[out] out pointer to store the git_annotated_commit result in - * @param repo repository that contains the given commit - * @param id the commit object id to lookup - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_annotated_commit_lookup( - git_annotated_commit **out, - git_repository *repo, - const git_oid *id); - -/** - * Creates a `git_annotated_commit` from a revision string. - * - * See `man gitrevisions`, or - * http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for - * information on the syntax accepted. - * - * @param[out] out pointer to store the git_annotated_commit result in - * @param repo repository that contains the given commit - * @param revspec the extended sha syntax string to use to lookup the commit - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_annotated_commit_from_revspec( - git_annotated_commit **out, - git_repository *repo, - const char *revspec); - -/** - * Gets the commit ID that the given `git_annotated_commit` refers to. - * - * @param commit the given annotated commit - * @return commit id - */ -GIT_EXTERN(const git_oid *) git_annotated_commit_id( - const git_annotated_commit *commit); - -/** - * Get the refname that the given `git_annotated_commit` refers to. - * - * @param commit the given annotated commit - * @return ref name. - */ -GIT_EXTERN(const char *) git_annotated_commit_ref( - const git_annotated_commit *commit); - -/** - * Frees a `git_annotated_commit`. - * - * @param commit annotated commit to free - */ -GIT_EXTERN(void) git_annotated_commit_free( - git_annotated_commit *commit); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/apply.h b/vendor/libgit2-sys/libgit2/include/git2/apply.h deleted file mode 100644 index 7ab939d..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/apply.h +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_apply_h__ -#define INCLUDE_git_apply_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "diff.h" - -/** - * @file git2/apply.h - * @brief Apply patches to the working directory or index - * @defgroup git_apply Git patch application routines - * @ingroup Git - * - * Mechanisms to apply a patch to the index, the working directory, - * or both. - * @{ - */ -GIT_BEGIN_DECL - -/** - * When applying a patch, callback that will be made per delta (file). - * - * When the callback: - * - returns < 0, the apply process will be aborted. - * - returns > 0, the delta will not be applied, but the apply process - * continues - * - returns 0, the delta is applied, and the apply process continues. - * - * @param delta The delta to be applied - * @param payload User-specified payload - * @return 0 if the delta is applied, < 0 if the apply process will be aborted - * or > 0 if the delta will not be applied. - */ -typedef int GIT_CALLBACK(git_apply_delta_cb)( - const git_diff_delta *delta, - void *payload); - -/** - * When applying a patch, callback that will be made per hunk. - * - * When the callback: - * - returns < 0, the apply process will be aborted. - * - returns > 0, the hunk will not be applied, but the apply process - * continues - * - returns 0, the hunk is applied, and the apply process continues. - * - * @param hunk The hunk to be applied - * @param payload User-specified payload - * @return 0 if the hunk is applied, < 0 if the apply process will be aborted - * or > 0 if the hunk will not be applied. - */ -typedef int GIT_CALLBACK(git_apply_hunk_cb)( - const git_diff_hunk *hunk, - void *payload); - -/** - * Flags controlling the behavior of `git_apply`. - * - * When the callback: - * - returns < 0, the apply process will be aborted. - * - returns > 0, the hunk will not be applied, but the apply process - * continues - * - returns 0, the hunk is applied, and the apply process continues. - */ -typedef enum { - /** - * Don't actually make changes, just test that the patch applies. - * This is the equivalent of `git apply --check`. - */ - GIT_APPLY_CHECK = (1 << 0) -} git_apply_flags_t; - -/** - * Apply options structure. - * - * When the callback: - * - returns < 0, the apply process will be aborted. - * - returns > 0, the hunk will not be applied, but the apply process - * continues - * - returns 0, the hunk is applied, and the apply process continues. - * - * Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can - * use `git_apply_options_init`. - * - * @see git_apply_to_tree - * @see git_apply - */ -typedef struct { - unsigned int version; /**< The version */ - - /** When applying a patch, callback that will be made per delta (file). */ - git_apply_delta_cb delta_cb; - - /** When applying a patch, callback that will be made per hunk. */ - git_apply_hunk_cb hunk_cb; - - /** Payload passed to both `delta_cb` & `hunk_cb`. */ - void *payload; - - /** Bitmask of `git_apply_flags_t` */ - unsigned int flags; -} git_apply_options; - -/** Current version for the `git_apply_options` structure */ -#define GIT_APPLY_OPTIONS_VERSION 1 - -/** Static constructor for `git_apply_options` */ -#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION} - -/** - * Initialize git_apply_options structure - * - * Initialize a `git_apply_options` with default values. Equivalent to creating - * an instance with GIT_APPLY_OPTIONS_INIT. - * - * @param opts The `git_apply_options` struct to initialize. - * @param version The struct version; pass `GIT_APPLY_OPTIONS_VERSION` - * @return 0 on success or -1 on failure. - */ -GIT_EXTERN(int) git_apply_options_init(git_apply_options *opts, unsigned int version); - -/** - * Apply a `git_diff` to a `git_tree`, and return the resulting image - * as an index. - * - * @param out the postimage of the application - * @param repo the repository to apply - * @param preimage the tree to apply the diff to - * @param diff the diff to apply - * @param options the options for the apply (or null for defaults) - * @return 0 or an error code - */ -GIT_EXTERN(int) git_apply_to_tree( - git_index **out, - git_repository *repo, - git_tree *preimage, - git_diff *diff, - const git_apply_options *options); - -/** Possible application locations for git_apply */ -typedef enum { - /** - * Apply the patch to the workdir, leaving the index untouched. - * This is the equivalent of `git apply` with no location argument. - */ - GIT_APPLY_LOCATION_WORKDIR = 0, - - /** - * Apply the patch to the index, leaving the working directory - * untouched. This is the equivalent of `git apply --cached`. - */ - GIT_APPLY_LOCATION_INDEX = 1, - - /** - * Apply the patch to both the working directory and the index. - * This is the equivalent of `git apply --index`. - */ - GIT_APPLY_LOCATION_BOTH = 2 -} git_apply_location_t; - -/** - * Apply a `git_diff` to the given repository, making changes directly - * in the working directory, the index, or both. - * - * @param repo the repository to apply to - * @param diff the diff to apply - * @param location the location to apply (workdir, index or both) - * @param options the options for the apply (or null for defaults) - * @return 0 or an error code - */ -GIT_EXTERN(int) git_apply( - git_repository *repo, - git_diff *diff, - git_apply_location_t location, - const git_apply_options *options); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/attr.h b/vendor/libgit2-sys/libgit2/include/git2/attr.h deleted file mode 100644 index e5216fe..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/attr.h +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_attr_h__ -#define INCLUDE_git_attr_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/attr.h - * @brief Attribute management routines - * @defgroup git_attr Git attribute management routines - * @ingroup Git - * - * Attributes specify additional information about how git should - * handle particular paths - for example, they may indicate whether - * a particular filter is applied, like LFS or line ending conversions. - * @{ - */ -GIT_BEGIN_DECL - -/** - * GIT_ATTR_TRUE checks if an attribute is set on. In core git - * parlance, this the value for "Set" attributes. - * - * For example, if the attribute file contains: - * - * *.c foo - * - * Then for file `xyz.c` looking up attribute "foo" gives a value for - * which `GIT_ATTR_TRUE(value)` is true. - */ -#define GIT_ATTR_IS_TRUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_TRUE) - -/** - * GIT_ATTR_FALSE checks if an attribute is set off. In core git - * parlance, this is the value for attributes that are "Unset" (not to - * be confused with values that a "Unspecified"). - * - * For example, if the attribute file contains: - * - * *.h -foo - * - * Then for file `zyx.h` looking up attribute "foo" gives a value for - * which `GIT_ATTR_FALSE(value)` is true. - */ -#define GIT_ATTR_IS_FALSE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_FALSE) - -/** - * GIT_ATTR_UNSPECIFIED checks if an attribute is unspecified. This - * may be due to the attribute not being mentioned at all or because - * the attribute was explicitly set unspecified via the `!` operator. - * - * For example, if the attribute file contains: - * - * *.c foo - * *.h -foo - * onefile.c !foo - * - * Then for `onefile.c` looking up attribute "foo" yields a value with - * `GIT_ATTR_UNSPECIFIED(value)` of true. Also, looking up "foo" on - * file `onefile.rb` or looking up "bar" on any file will all give - * `GIT_ATTR_UNSPECIFIED(value)` of true. - */ -#define GIT_ATTR_IS_UNSPECIFIED(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_UNSPECIFIED) - -/** - * GIT_ATTR_HAS_VALUE checks if an attribute is set to a value (as - * opposed to TRUE, FALSE or UNSPECIFIED). This would be the case if - * for a file with something like: - * - * *.txt eol=lf - * - * Given this, looking up "eol" for `onefile.txt` will give back the - * string "lf" and `GIT_ATTR_SET_TO_VALUE(attr)` will return true. - */ -#define GIT_ATTR_HAS_VALUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_STRING) - -/** - * Possible states for an attribute - */ -typedef enum { - GIT_ATTR_VALUE_UNSPECIFIED = 0, /**< The attribute has been left unspecified */ - GIT_ATTR_VALUE_TRUE, /**< The attribute has been set */ - GIT_ATTR_VALUE_FALSE, /**< The attribute has been unset */ - GIT_ATTR_VALUE_STRING /**< This attribute has a value */ -} git_attr_value_t; - -/** - * Return the value type for a given attribute. - * - * This can be either `TRUE`, `FALSE`, `UNSPECIFIED` (if the attribute - * was not set at all), or `VALUE`, if the attribute was set to an - * actual string. - * - * If the attribute has a `VALUE` string, it can be accessed normally - * as a NULL-terminated C string. - * - * @param attr The attribute - * @return the value type for the attribute - */ -GIT_EXTERN(git_attr_value_t) git_attr_value(const char *attr); - -/** - * Check attribute flags: Reading values from index and working directory. - * - * When checking attributes, it is possible to check attribute files - * in both the working directory (if there is one) and the index (if - * there is one). You can explicitly choose where to check and in - * which order using the following flags. - * - * Core git usually checks the working directory then the index, - * except during a checkout when it checks the index first. It will - * use index only for creating archives or for a bare repo (if an - * index has been specified for the bare repo). - */ - -/** Examine attribute in working directory, then index */ -#define GIT_ATTR_CHECK_FILE_THEN_INDEX 0 -/** Examine attribute in index, then working directory */ -#define GIT_ATTR_CHECK_INDEX_THEN_FILE 1 -/** Examine attributes only in the index */ -#define GIT_ATTR_CHECK_INDEX_ONLY 2 - -/** - * Check attribute flags: controlling extended attribute behavior. - * - * Normally, attribute checks include looking in the /etc (or system - * equivalent) directory for a `gitattributes` file. Passing the - * `GIT_ATTR_CHECK_NO_SYSTEM` flag will cause attribute checks to - * ignore that file. - * - * Passing the `GIT_ATTR_CHECK_INCLUDE_HEAD` flag will use attributes - * from a `.gitattributes` file in the repository at the HEAD revision. - * - * Passing the `GIT_ATTR_CHECK_INCLUDE_COMMIT` flag will use attributes - * from a `.gitattributes` file in a specific commit. - */ - -/** Ignore system attributes */ -#define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2) -/** Honor `.gitattributes` in the HEAD revision */ -#define GIT_ATTR_CHECK_INCLUDE_HEAD (1 << 3) -/** Honor `.gitattributes` in a specific commit */ -#define GIT_ATTR_CHECK_INCLUDE_COMMIT (1 << 4) - -/** -* An options structure for querying attributes. -*/ -typedef struct { - unsigned int version; - - /** A combination of GIT_ATTR_CHECK flags */ - unsigned int flags; - -#ifdef GIT_DEPRECATE_HARD - void *reserved; -#else - git_oid *commit_id; -#endif - - /** - * The commit to load attributes from, when - * `GIT_ATTR_CHECK_INCLUDE_COMMIT` is specified. - */ - git_oid attr_commit_id; -} git_attr_options; - -/** Current version for the `git_attr_options` structure */ -#define GIT_ATTR_OPTIONS_VERSION 1 - -/** Static constructor for `git_attr_options` */ -#define GIT_ATTR_OPTIONS_INIT {GIT_ATTR_OPTIONS_VERSION} - -/** - * Look up the value of one git attribute for path. - * - * @param value_out Output of the value of the attribute. Use the GIT_ATTR_... - * macros to test for TRUE, FALSE, UNSPECIFIED, etc. or just - * use the string value for attributes set to a value. You - * should NOT modify or free this value. - * @param repo The repository containing the path. - * @param flags A combination of GIT_ATTR_CHECK... flags. - * @param path The path to check for attributes. Relative paths are - * interpreted relative to the repo root. The file does - * not have to exist, but if it does not, then it will be - * treated as a plain file (not a directory). - * @param name The name of the attribute to look up. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_attr_get( - const char **value_out, - git_repository *repo, - uint32_t flags, - const char *path, - const char *name); - -/** - * Look up the value of one git attribute for path with extended options. - * - * @param value_out Output of the value of the attribute. Use the GIT_ATTR_... - * macros to test for TRUE, FALSE, UNSPECIFIED, etc. or just - * use the string value for attributes set to a value. You - * should NOT modify or free this value. - * @param repo The repository containing the path. - * @param opts The `git_attr_options` to use when querying these attributes. - * @param path The path to check for attributes. Relative paths are - * interpreted relative to the repo root. The file does - * not have to exist, but if it does not, then it will be - * treated as a plain file (not a directory). - * @param name The name of the attribute to look up. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_attr_get_ext( - const char **value_out, - git_repository *repo, - git_attr_options *opts, - const char *path, - const char *name); - -/** - * Look up a list of git attributes for path. - * - * Use this if you have a known list of attributes that you want to - * look up in a single call. This is somewhat more efficient than - * calling `git_attr_get()` multiple times. - * - * For example, you might write: - * - * const char *attrs[] = { "crlf", "diff", "foo" }; - * const char **values[3]; - * git_attr_get_many(values, repo, 0, "my/fun/file.c", 3, attrs); - * - * Then you could loop through the 3 values to get the settings for - * the three attributes you asked about. - * - * @param values_out An array of num_attr entries that will have string - * pointers written into it for the values of the attributes. - * You should not modify or free the values that are written - * into this array (although of course, you should free the - * array itself if you allocated it). - * @param repo The repository containing the path. - * @param flags A combination of GIT_ATTR_CHECK... flags. - * @param path The path inside the repo to check attributes. This - * does not have to exist, but if it does not, then - * it will be treated as a plain file (i.e. not a directory). - * @param num_attr The number of attributes being looked up - * @param names An array of num_attr strings containing attribute names. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_attr_get_many( - const char **values_out, - git_repository *repo, - uint32_t flags, - const char *path, - size_t num_attr, - const char **names); - -/** - * Look up a list of git attributes for path with extended options. - * - * @param values_out An array of num_attr entries that will have string - * pointers written into it for the values of the attributes. - * You should not modify or free the values that are written - * into this array (although of course, you should free the - * array itself if you allocated it). - * @param repo The repository containing the path. - * @param opts The `git_attr_options` to use when querying these attributes. - * @param path The path inside the repo to check attributes. This - * does not have to exist, but if it does not, then - * it will be treated as a plain file (i.e. not a directory). - * @param num_attr The number of attributes being looked up - * @param names An array of num_attr strings containing attribute names. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_attr_get_many_ext( - const char **values_out, - git_repository *repo, - git_attr_options *opts, - const char *path, - size_t num_attr, - const char **names); - -/** - * The callback used with git_attr_foreach. - * - * This callback will be invoked only once per attribute name, even if there - * are multiple rules for a given file. The highest priority rule will be - * used. - * - * @see git_attr_foreach. - * - * @param name The attribute name. - * @param value The attribute value. May be NULL if the attribute is explicitly - * set to UNSPECIFIED using the '!' sign. - * @param payload A user-specified pointer. - * @return 0 to continue looping, non-zero to stop. This value will be returned - * from git_attr_foreach. - */ -typedef int GIT_CALLBACK(git_attr_foreach_cb)(const char *name, const char *value, void *payload); - -/** - * Loop over all the git attributes for a path. - * - * @param repo The repository containing the path. - * @param flags A combination of GIT_ATTR_CHECK... flags. - * @param path Path inside the repo to check attributes. This does not have - * to exist, but if it does not, then it will be treated as a - * plain file (i.e. not a directory). - * @param callback Function to invoke on each attribute name and value. - * See git_attr_foreach_cb. - * @param payload Passed on as extra parameter to callback function. - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_attr_foreach( - git_repository *repo, - uint32_t flags, - const char *path, - git_attr_foreach_cb callback, - void *payload); - -/** - * Loop over all the git attributes for a path with extended options. - * - * @param repo The repository containing the path. - * @param opts The `git_attr_options` to use when querying these attributes. - * @param path Path inside the repo to check attributes. This does not have - * to exist, but if it does not, then it will be treated as a - * plain file (i.e. not a directory). - * @param callback Function to invoke on each attribute name and value. - * See git_attr_foreach_cb. - * @param payload Passed on as extra parameter to callback function. - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_attr_foreach_ext( - git_repository *repo, - git_attr_options *opts, - const char *path, - git_attr_foreach_cb callback, - void *payload); - -/** - * Flush the gitattributes cache. - * - * Call this if you have reason to believe that the attributes files on - * disk no longer match the cached contents of memory. This will cause - * the attributes files to be reloaded the next time that an attribute - * access function is called. - * - * @param repo The repository containing the gitattributes cache - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_attr_cache_flush( - git_repository *repo); - -/** - * Add a macro definition. - * - * Macros will automatically be loaded from the top level `.gitattributes` - * file of the repository (plus the built-in "binary" macro). This - * function allows you to add others. For example, to add the default - * macro, you would call: - * - * git_attr_add_macro(repo, "binary", "-diff -crlf"); - * - * @param repo The repository to add the macro in. - * @param name The name of the macro. - * @param values The value for the macro. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_attr_add_macro( - git_repository *repo, - const char *name, - const char *values); - -/** @} */ -GIT_END_DECL -#endif - diff --git a/vendor/libgit2-sys/libgit2/include/git2/blame.h b/vendor/libgit2-sys/libgit2/include/git2/blame.h deleted file mode 100644 index f3e6692..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/blame.h +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_git_blame_h__ -#define INCLUDE_git_blame_h__ - -#include "common.h" -#include "oid.h" - -/** - * @file git2/blame.h - * @brief Specify a file's most recent changes per-line - * @defgroup git_blame Git blame routines - * @ingroup Git - * - * Producing a "blame" (or "annotated history") decorates individual - * lines in a file with the commit that introduced that particular line - * of changes. This can be useful to indicate when and why a particular - * change was made. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Flags for indicating option behavior for git_blame APIs. - */ -typedef enum { - /** Normal blame, the default */ - GIT_BLAME_NORMAL = 0, - - /** - * Track lines that have moved within a file (like `git blame -M`). - * - * This is not yet implemented and reserved for future use. - */ - GIT_BLAME_TRACK_COPIES_SAME_FILE = (1<<0), - - /** - * Track lines that have moved across files in the same commit - * (like `git blame -C`). - * - * This is not yet implemented and reserved for future use. - */ - GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES = (1<<1), - - /** - * Track lines that have been copied from another file that exists - * in the same commit (like `git blame -CC`). Implies SAME_FILE. - * - * This is not yet implemented and reserved for future use. - */ - GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES = (1<<2), - - /** - * Track lines that have been copied from another file that exists in - * *any* commit (like `git blame -CCC`). Implies SAME_COMMIT_COPIES. - * - * This is not yet implemented and reserved for future use. - */ - GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES = (1<<3), - - /** - * Restrict the search of commits to those reachable following only - * the first parents. - */ - GIT_BLAME_FIRST_PARENT = (1<<4), - - /** - * Use mailmap file to map author and committer names and email - * addresses to canonical real names and email addresses. The - * mailmap will be read from the working directory, or HEAD in a - * bare repository. - */ - GIT_BLAME_USE_MAILMAP = (1<<5), - - /** Ignore whitespace differences */ - GIT_BLAME_IGNORE_WHITESPACE = (1<<6) -} git_blame_flag_t; - -/** - * Blame options structure - * - * Initialize with `GIT_BLAME_OPTIONS_INIT`. Alternatively, you can - * use `git_blame_options_init`. - * - */ -typedef struct git_blame_options { - unsigned int version; - - /** A combination of `git_blame_flag_t` */ - unsigned int flags; - - /** - * The lower bound on the number of alphanumeric characters that - * must be detected as moving/copying within a file for it to - * associate those lines with the parent commit. The default value - * is 20. - * - * This value only takes effect if any of the `GIT_BLAME_TRACK_COPIES_*` - * flags are specified. - */ - uint16_t min_match_characters; - - /** The id of the newest commit to consider. The default is HEAD. */ - git_oid newest_commit; - - /** - * The id of the oldest commit to consider. - * The default is the first commit encountered with a NULL parent. - */ - git_oid oldest_commit; - - /** - * The first line in the file to blame. - * The default is 1 (line numbers start with 1). - */ - size_t min_line; - - /** - * The last line in the file to blame. - * The default is the last line of the file. - */ - size_t max_line; -} git_blame_options; - -/** Current version for the `git_blame_options` structure */ -#define GIT_BLAME_OPTIONS_VERSION 1 - -/** Static constructor for `git_blame_options` */ -#define GIT_BLAME_OPTIONS_INIT {GIT_BLAME_OPTIONS_VERSION} - -/** - * Initialize git_blame_options structure - * - * Initializes a `git_blame_options` with default values. Equivalent to creating - * an instance with GIT_BLAME_OPTIONS_INIT. - * - * @param opts The `git_blame_options` struct to initialize. - * @param version The struct version; pass `GIT_BLAME_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_blame_options_init( - git_blame_options *opts, - unsigned int version); - -/** - * Structure that represents a blame hunk. - */ -typedef struct git_blame_hunk { - /** - * The number of lines in this hunk. - */ - size_t lines_in_hunk; - - /** - * The OID of the commit where this line was last changed. - */ - git_oid final_commit_id; - - /** - * The 1-based line number where this hunk begins, in the final version - * of the file. - */ - size_t final_start_line_number; - - /** - * The author of `final_commit_id`. If `GIT_BLAME_USE_MAILMAP` has been - * specified, it will contain the canonical real name and email address. - */ - git_signature *final_signature; - - /** - * The committer of `final_commit_id`. If `GIT_BLAME_USE_MAILMAP` has - * been specified, it will contain the canonical real name and email - * address. - */ - git_signature *final_committer; - - /** - * The OID of the commit where this hunk was found. - * This will usually be the same as `final_commit_id`, except when - * `GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES` has been specified. - */ - git_oid orig_commit_id; - - /** - * The path to the file where this hunk originated, as of the commit - * specified by `orig_commit_id`. - */ - const char *orig_path; - - /** - * The 1-based line number where this hunk begins in the file named by - * `orig_path` in the commit specified by `orig_commit_id`. - */ - size_t orig_start_line_number; - - /** - * The author of `orig_commit_id`. If `GIT_BLAME_USE_MAILMAP` has been - * specified, it will contain the canonical real name and email address. - */ - git_signature *orig_signature; - - /** - * The committer of `orig_commit_id`. If `GIT_BLAME_USE_MAILMAP` has - * been specified, it will contain the canonical real name and email - * address. - */ - git_signature *orig_committer; - - /* - * The summary of the commit. - */ - const char *summary; - - /** - * The 1 iff the hunk has been tracked to a boundary commit (the root, - * or the commit specified in git_blame_options.oldest_commit) - */ - char boundary; -} git_blame_hunk; - -/** - * Structure that represents a line in a blamed file. - */ -typedef struct git_blame_line { - const char *ptr; - size_t len; -} git_blame_line; - -/** Opaque structure to hold blame results */ -typedef struct git_blame git_blame; - -/** - * Gets the number of lines that exist in the blame structure. - * - * @param blame The blame structure to query. - * @return The number of line. - */ -GIT_EXTERN(size_t) git_blame_linecount(git_blame *blame); - -/** - * Gets the number of hunks that exist in the blame structure. - * - * @param blame The blame structure to query. - * @return The number of hunks. - */ -GIT_EXTERN(size_t) git_blame_hunkcount(git_blame *blame); - -/** - * Gets the blame hunk at the given index. - * - * @param blame the blame structure to query - * @param index index of the hunk to retrieve - * @return the hunk at the given index, or NULL on error - */ -GIT_EXTERN(const git_blame_hunk *) git_blame_hunk_byindex( - git_blame *blame, - size_t index); - -/** - * Gets the hunk that relates to the given line number in the newest - * commit. - * - * @param blame the blame structure to query - * @param lineno the (1-based) line number to find a hunk for - * @return the hunk that contains the given line, or NULL on error - */ -GIT_EXTERN(const git_blame_hunk *) git_blame_hunk_byline( - git_blame *blame, - size_t lineno); - -/** - * Gets the information about the line in the blame. - * - * @param blame the blame structure to query - * @param idx the (1-based) line number - * @return the blamed line, or NULL on error - */ -GIT_EXTERN(const git_blame_line *) git_blame_line_byindex( - git_blame *blame, - size_t idx); - -#ifndef GIT_DEPRECATE_HARD -/** - * Gets the number of hunks that exist in the blame structure. - * - * @param blame The blame structure to query. - * @return The number of hunks. - */ - -GIT_EXTERN(uint32_t) git_blame_get_hunk_count(git_blame *blame); - -/** - * Gets the blame hunk at the given index. - * - * @param blame the blame structure to query - * @param index index of the hunk to retrieve - * @return the hunk at the given index, or NULL on error - */ -GIT_EXTERN(const git_blame_hunk *) git_blame_get_hunk_byindex( - git_blame *blame, - uint32_t index); - -/** - * Gets the hunk that relates to the given line number in the newest commit. - * - * @param blame the blame structure to query - * @param lineno the (1-based) line number to find a hunk for - * @return the hunk that contains the given line, or NULL on error - */ -GIT_EXTERN(const git_blame_hunk *) git_blame_get_hunk_byline( - git_blame *blame, - size_t lineno); -#endif - -/** - * Get the blame for a single file in the repository. - * - * @param out pointer that will receive the blame object - * @param repo repository whose history is to be walked - * @param path path to file to consider - * @param options options for the blame operation or NULL - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_blame_file( - git_blame **out, - git_repository *repo, - const char *path, - git_blame_options *options); - -/** - * Get the blame for a single file in the repository, using the specified - * buffer contents as the uncommitted changes of the file (the working - * directory contents). - * - * @param out pointer that will receive the blame object - * @param repo repository whose history is to be walked - * @param path path to file to consider - * @param contents the uncommitted changes - * @param contents_len the length of the changes buffer - * @param options options for the blame operation or NULL - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_blame_file_from_buffer( - git_blame **out, - git_repository *repo, - const char *path, - const char *contents, - size_t contents_len, - git_blame_options *options); - -/** - * Get blame data for a file that has been modified in memory. The `blame` - * parameter is a pre-calculated blame for the in-odb history of the file. - * This means that once a file blame is completed (which can be expensive), - * updating the buffer blame is very fast. - * - * Lines that differ between the buffer and the committed version are - * marked as having a zero OID for their final_commit_id. - * - * @param out pointer that will receive the resulting blame data - * @param base cached blame from the history of the file (usually the output - * from git_blame_file) - * @param buffer the (possibly) modified contents of the file - * @param buffer_len number of valid bytes in the buffer - * @return 0 on success, or an error code. (use git_error_last for information - * about the error) - */ -GIT_EXTERN(int) git_blame_buffer( - git_blame **out, - git_blame *base, - const char *buffer, - size_t buffer_len); - -/** - * Free memory allocated by git_blame_file or git_blame_buffer. - * - * @param blame the blame structure to free - */ -GIT_EXTERN(void) git_blame_free(git_blame *blame); - -/** @} */ -GIT_END_DECL -#endif - diff --git a/vendor/libgit2-sys/libgit2/include/git2/blob.h b/vendor/libgit2-sys/libgit2/include/git2/blob.h deleted file mode 100644 index 0ed1685..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/blob.h +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_blob_h__ -#define INCLUDE_git_blob_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "object.h" -#include "buffer.h" - -/** - * @file git2/blob.h - * @brief A blob represents a file in a git repository. - * @defgroup git_blob Git blob load and write routines - * @ingroup Git - * - * A blob represents a file in a git repository. This is the raw data - * as it is stored in the repository itself. Blobs may be "filtered" - * to produce the on-disk content. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a blob object from a repository. - * - * @param[out] blob pointer to the looked up blob - * @param repo the repo to use when locating the blob. - * @param id identity of the blob to locate. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_blob_lookup( - git_blob **blob, - git_repository *repo, - const git_oid *id); - -/** - * Lookup a blob object from a repository, - * given a prefix of its identifier (short id). - * - * @see git_object_lookup_prefix - * - * @param[out] blob pointer to the looked up blob - * @param repo the repo to use when locating the blob. - * @param id identity of the blob to locate. - * @param len the length of the short identifier - * @return 0 or an error code - */ -GIT_EXTERN(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len); - -/** - * Close an open blob - * - * This is a wrapper around git_object_free() - * - * IMPORTANT: - * It *is* necessary to call this method when you stop - * using a blob. Failure to do so will cause a memory leak. - * - * @param blob the blob to close - */ -GIT_EXTERN(void) git_blob_free(git_blob *blob); - -/** - * Get the id of a blob. - * - * @param blob a previously loaded blob. - * @return SHA1 hash for this blob. - */ -GIT_EXTERN(const git_oid *) git_blob_id(const git_blob *blob); - -/** - * Get the repository that contains the blob. - * - * @param blob A previously loaded blob. - * @return Repository that contains this blob. - */ -GIT_EXTERN(git_repository *) git_blob_owner(const git_blob *blob); - -/** - * Get a read-only buffer with the raw content of a blob. - * - * A pointer to the raw content of a blob is returned; - * this pointer is owned internally by the object and shall - * not be free'd. The pointer may be invalidated at a later - * time. - * - * @param blob pointer to the blob - * @return @type `unsigned char *` the pointer, or NULL on error - */ -GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob); - -/** - * Get the size in bytes of the contents of a blob - * - * @param blob pointer to the blob - * @return size in bytes - */ -GIT_EXTERN(git_object_size_t) git_blob_rawsize(const git_blob *blob); - -/** - * Flags to control the functionality of `git_blob_filter`. - * - * @flags - */ -typedef enum { - /** When set, filters will not be applied to binary files. */ - GIT_BLOB_FILTER_CHECK_FOR_BINARY = (1 << 0), - - /** - * When set, filters will not load configuration from the - * system-wide `gitattributes` in `/etc` (or system equivalent). - */ - GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES = (1 << 1), - - /** - * When set, filters will be loaded from a `.gitattributes` file - * in the HEAD commit. - */ - GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD = (1 << 2), - - /** - * When set, filters will be loaded from a `.gitattributes` file - * in the specified commit. - */ - GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3) -} git_blob_filter_flag_t; - -/** - * The options used when applying filter options to a file. - * - * Initialize with `GIT_BLOB_FILTER_OPTIONS_INIT`. Alternatively, you can - * use `git_blob_filter_options_init`. - * - * @options[version] GIT_BLOB_FILTER_OPTIONS_VERSION - * @options[init_macro] GIT_BLOB_FILTER_OPTIONS_INIT - * @options[init_function] git_blob_filter_options_init - */ -typedef struct { - /** Version number of the options structure. */ - int version; - - /** - * Flags to control the filtering process, see `git_blob_filter_flag_t` above. - * - * @type[flags] git_blob_filter_flag_t - */ - uint32_t flags; - -#ifdef GIT_DEPRECATE_HARD - /** - * Unused and reserved for ABI compatibility. - * - * @deprecated this value should not be set - */ - void *reserved; -#else - /** - * This value is unused and reserved for API compatibility. - * - * @deprecated this value should not be set - */ - git_oid *commit_id; -#endif - - /** - * The commit to load attributes from, when - * `GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT` is specified. - */ - git_oid attr_commit_id; -} git_blob_filter_options; - -/** - * The current version number for the `git_blob_filter_options` structure ABI. - */ -#define GIT_BLOB_FILTER_OPTIONS_VERSION 1 - -/** - * The default values for `git_blob_filter_options`. - */ -#define GIT_BLOB_FILTER_OPTIONS_INIT { \ - GIT_BLOB_FILTER_OPTIONS_VERSION, \ - GIT_BLOB_FILTER_CHECK_FOR_BINARY \ - } - -/** - * Initialize git_blob_filter_options structure - * - * Initializes a `git_blob_filter_options` with default values. Equivalent - * to creating an instance with `GIT_BLOB_FILTER_OPTIONS_INIT`. - * - * @param opts The `git_blob_filter_options` struct to initialize. - * @param version The struct version; pass GIT_BLOB_FILTER_OPTIONS_VERSION - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_blob_filter_options_init( - git_blob_filter_options *opts, - unsigned int version); - -/** - * Get a buffer with the filtered content of a blob. - * - * This applies filters as if the blob was being checked out to the - * working directory under the specified filename. This may apply - * CRLF filtering or other types of changes depending on the file - * attributes set for the blob and the content detected in it. - * - * The output is written into a `git_buf` which the caller must dispose - * when done (via `git_buf_dispose`). - * - * If no filters need to be applied, then the `out` buffer will just - * be populated with a pointer to the raw content of the blob. In - * that case, be careful to *not* free the blob until done with the - * buffer or copy it into memory you own. - * - * @param out The git_buf to be filled in - * @param blob Pointer to the blob - * @param as_path Path used for file attribute lookups, etc. - * @param opts Options to use for filtering the blob - * @return @type[enum] git_error_code 0 on success or an error code - */ -GIT_EXTERN(int) git_blob_filter( - git_buf *out, - git_blob *blob, - const char *as_path, - git_blob_filter_options *opts); - -/** - * Read a file from the working folder of a repository and write it - * to the object database. - * - * @param[out] id return the id of the written blob - * @param repo repository where the blob will be written. - * this repository cannot be bare - * @param relative_path file from which the blob will be created, - * relative to the repository's working dir - * @return 0 or an error code - */ -GIT_EXTERN(int) git_blob_create_from_workdir(git_oid *id, git_repository *repo, const char *relative_path); - -/** - * Read a file from the filesystem (not necessarily inside the - * working folder of the repository) and write it to the object - * database. - * - * @param[out] id return the id of the written blob - * @param repo repository where the blob will be written. - * this repository can be bare or not - * @param path file from which the blob will be created - * @return 0 or an error code - */ -GIT_EXTERN(int) git_blob_create_from_disk( - git_oid *id, - git_repository *repo, - const char *path); - -/** - * Create a stream to write a new blob into the object database. - * - * This function may need to buffer the data on disk and will in - * general not be the right choice if you know the size of the data - * to write. If you have data in memory, use - * `git_blob_create_from_buffer()`. If you do not, but know the size of - * the contents (and don't want/need to perform filtering), use - * `git_odb_open_wstream()`. - * - * Don't close this stream yourself but pass it to - * `git_blob_create_from_stream_commit()` to commit the write to the - * object db and get the object id. - * - * If the `hintpath` parameter is filled, it will be used to determine - * what git filters should be applied to the object before it is written - * to the object database. - * - * @param[out] out the stream into which to write - * @param repo Repository where the blob will be written. - * This repository can be bare or not. - * @param hintpath If not NULL, will be used to select data filters - * to apply onto the content of the blob to be created. - * @return 0 or error code - */ -GIT_EXTERN(int) git_blob_create_from_stream( - git_writestream **out, - git_repository *repo, - const char *hintpath); - -/** - * Close the stream and finalize writing the blob to the object database. - * - * The stream will be closed and freed. - * - * @param[out] out the id of the new blob - * @param stream the stream to close - * @return 0 or an error code - */ -GIT_EXTERN(int) git_blob_create_from_stream_commit( - git_oid *out, - git_writestream *stream); - -/** - * Write an in-memory buffer to the object database as a blob. - * - * @param[out] id return the id of the written blob - * @param repo repository where the blob will be written - * @param buffer data to be written into the blob - * @param len length of the data - * @return 0 or an error code - */ -GIT_EXTERN(int) git_blob_create_from_buffer( - git_oid *id, git_repository *repo, const void *buffer, size_t len); - -/** - * Determine if the blob content is most likely binary or not. - * - * The heuristic used to guess if a file is binary is taken from core git: - * Searching for NUL bytes and looking for a reasonable ratio of printable - * to non-printable characters among the first 8000 bytes. - * - * @param blob The blob which content should be analyzed - * @return @type bool 1 if the content of the blob is detected - * as binary; 0 otherwise. - */ -GIT_EXTERN(int) git_blob_is_binary(const git_blob *blob); - -/** - * Determine if the given content is most certainly binary or not; - * this is the same mechanism used by `git_blob_is_binary` but only - * looking at raw data. - * - * @param data The blob data which content should be analyzed - * @param len The length of the data - * @return 1 if the content of the blob is detected - * as binary; 0 otherwise. - */ -GIT_EXTERN(int) git_blob_data_is_binary(const char *data, size_t len); - -/** - * Create an in-memory copy of a blob. The copy must be explicitly - * free'd or it will leak. - * - * @param[out] out Pointer to store the copy of the object - * @param source Original object to copy - * @return 0. - */ -GIT_EXTERN(int) git_blob_dup(git_blob **out, git_blob *source); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/branch.h b/vendor/libgit2-sys/libgit2/include/git2/branch.h deleted file mode 100644 index 56d737d..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/branch.h +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_branch_h__ -#define INCLUDE_git_branch_h__ - -#include "common.h" -#include "oid.h" -#include "types.h" - -/** - * @file git2/branch.h - * @brief Branch creation and handling - * @defgroup git_branch Git branch management - * @ingroup Git - * - * A branch is a specific type of reference, at any particular time, - * a git working directory typically is said to have a branch "checked out", - * meaning that commits that are created will be made "on" a branch. - * This occurs by updating the branch reference to point to the new - * commit. The checked out branch is indicated by the `HEAD` meta-ref. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create a new branch pointing at a target commit - * - * A new direct reference will be created pointing to - * this target commit. If `force` is true and a reference - * already exists with the given name, it'll be replaced. - * - * The returned reference must be freed by the user. - * - * The branch name will be checked for validity. - * See `git_tag_create()` for rules about valid names. - * - * @param out Pointer where to store the underlying reference. - * @param repo the repository to create the branch in. - * @param branch_name Name for the branch; this name is - * validated for consistency. It should also not conflict with - * an already existing branch name. - * @param target Commit to which this branch should point. This object - * must belong to the given `repo`. - * @param force Overwrite existing branch. - * @return 0, GIT_EINVALIDSPEC or an error code. - * A proper reference is written in the refs/heads namespace - * pointing to the provided target commit. - */ -GIT_EXTERN(int) git_branch_create( - git_reference **out, - git_repository *repo, - const char *branch_name, - const git_commit *target, - int force); - -/** - * Create a new branch pointing at a target commit - * - * This behaves like `git_branch_create()` but takes an annotated - * commit, which lets you specify which extended sha syntax string was - * specified by a user, allowing for more exact reflog messages. - * - * @param ref_out Pointer where to store the underlying reference. - * @param repo the repository to create the branch in. - * @param branch_name Name for the branch; this name is - * validated for consistency. It should also not conflict with - * an already existing branch name. - * @param target Annotated commit to which this branch should point. This - * object must belong to the given `repo`. - * @param force Overwrite existing branch. - * @return 0, GIT_EINVALIDSPEC or an error code. - */ -GIT_EXTERN(int) git_branch_create_from_annotated( - git_reference **ref_out, - git_repository *repo, - const char *branch_name, - const git_annotated_commit *target, - int force); - -/** - * Delete an existing branch reference. - * - * Note that if the deletion succeeds, the reference object will not - * be valid anymore, and should be freed immediately by the user using - * `git_reference_free()`. - * - * @param branch A valid reference representing a branch - * @return 0 on success, or an error code. - */ -GIT_EXTERN(int) git_branch_delete(git_reference *branch); - -/** Iterator type for branches */ -typedef struct git_branch_iterator git_branch_iterator; - -/** - * Create an iterator which loops over the requested branches. - * - * @param out the iterator - * @param repo Repository where to find the branches. - * @param list_flags Filtering flags for the branch - * listing. Valid values are GIT_BRANCH_LOCAL, GIT_BRANCH_REMOTE - * or GIT_BRANCH_ALL. - * - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_branch_iterator_new( - git_branch_iterator **out, - git_repository *repo, - git_branch_t list_flags); - -/** - * Retrieve the next branch from the iterator - * - * @param out the reference - * @param out_type the type of branch (local or remote-tracking) - * @param iter the branch iterator - * @return 0 on success, GIT_ITEROVER if there are no more branches or an error code. - */ -GIT_EXTERN(int) git_branch_next(git_reference **out, git_branch_t *out_type, git_branch_iterator *iter); - -/** - * Free a branch iterator - * - * @param iter the iterator to free - */ -GIT_EXTERN(void) git_branch_iterator_free(git_branch_iterator *iter); - -/** - * Move/rename an existing local branch reference. - * - * The new branch name will be checked for validity. - * See `git_tag_create()` for rules about valid names. - * - * Note that if the move succeeds, the old reference object will not - * be valid anymore, and should be freed immediately by the user using - * `git_reference_free()`. - * - * @param out New reference object for the updated name. - * - * @param branch Current underlying reference of the branch. - * - * @param new_branch_name Target name of the branch once the move - * is performed; this name is validated for consistency. - * - * @param force Overwrite existing branch. - * - * @return 0 on success, GIT_EINVALIDSPEC or an error code. - */ -GIT_EXTERN(int) git_branch_move( - git_reference **out, - git_reference *branch, - const char *new_branch_name, - int force); - -/** - * Lookup a branch by its name in a repository. - * - * The generated reference must be freed by the user. - * The branch name will be checked for validity. - * - * @see git_tag_create for rules about valid names. - * - * @param out pointer to the looked-up branch reference - * @param repo the repository to look up the branch - * @param branch_name Name of the branch to be looked-up; - * this name is validated for consistency. - * @param branch_type Type of the considered branch. This should - * be valued with either GIT_BRANCH_LOCAL or GIT_BRANCH_REMOTE. - * - * @return 0 on success; GIT_ENOTFOUND when no matching branch - * exists, GIT_EINVALIDSPEC, otherwise an error code. - */ -GIT_EXTERN(int) git_branch_lookup( - git_reference **out, - git_repository *repo, - const char *branch_name, - git_branch_t branch_type); - -/** - * Get the branch name - * - * Given a reference object, this will check that it really is a branch (ie. - * it lives under "refs/heads/" or "refs/remotes/"), and return the branch part - * of it. - * - * @param out Pointer to the abbreviated reference name. - * Owned by ref, do not free. - * - * @param ref A reference object, ideally pointing to a branch - * - * @return 0 on success; GIT_EINVALID if the reference isn't either a local or - * remote branch, otherwise an error code. - */ -GIT_EXTERN(int) git_branch_name( - const char **out, - const git_reference *ref); - -/** - * Get the upstream of a branch - * - * Given a reference, this will return a new reference object corresponding - * to its remote tracking branch. The reference must be a local branch. - * - * @see git_branch_upstream_name for details on the resolution. - * - * @param out Pointer where to store the retrieved reference. - * @param branch Current underlying reference of the branch. - * - * @return 0 on success; GIT_ENOTFOUND when no remote tracking - * reference exists, otherwise an error code. - */ -GIT_EXTERN(int) git_branch_upstream( - git_reference **out, - const git_reference *branch); - -/** - * Set a branch's upstream branch - * - * This will update the configuration to set the branch named `branch_name` as the upstream of `branch`. - * Pass a NULL name to unset the upstream information. - * - * @note the actual tracking reference must have been already created for the - * operation to succeed. - * - * @param branch the branch to configure - * @param branch_name remote-tracking or local branch to set as upstream. - * - * @return @type git_error_t 0 on success; GIT_ENOTFOUND if there's no branch named `branch_name` - * or an error code - */ -GIT_EXTERN(int) git_branch_set_upstream( - git_reference *branch, - const char *branch_name); - -/** - * Get the upstream name of a branch - * - * Given a local branch, this will return its remote-tracking branch information, - * as a full reference name, ie. "feature/nice" would become - * "refs/remote/origin/feature/nice", depending on that branch's configuration. - * - * @param out the buffer into which the name will be written. - * @param repo the repository where the branches live. - * @param refname reference name of the local branch. - * - * @return 0 on success, GIT_ENOTFOUND when no remote tracking reference exists, - * or an error code. - */ -GIT_EXTERN(int) git_branch_upstream_name( - git_buf *out, - git_repository *repo, - const char *refname); - -/** - * Determine if HEAD points to the given branch - * - * @param branch A reference to a local branch. - * - * @return 1 if HEAD points at the branch, 0 if it isn't, or a negative value - * as an error code. - */ -GIT_EXTERN(int) git_branch_is_head( - const git_reference *branch); - -/** - * Determine if any HEAD points to the current branch - * - * This will iterate over all known linked repositories (usually in the form of - * worktrees) and report whether any HEAD is pointing at the current branch. - * - * @param branch A reference to a local branch. - * - * @return 1 if branch is checked out, 0 if it isn't, an error code otherwise. - */ -GIT_EXTERN(int) git_branch_is_checked_out( - const git_reference *branch); - -/** - * Find the remote name of a remote-tracking branch - * - * This will return the name of the remote whose fetch refspec is matching - * the given branch. E.g. given a branch "refs/remotes/test/master", it will - * extract the "test" part. If refspecs from multiple remotes match, - * the function will return GIT_EAMBIGUOUS. - * - * @param out The buffer into which the name will be written. - * @param repo The repository where the branch lives. - * @param refname complete name of the remote tracking branch. - * - * @return 0 on success, GIT_ENOTFOUND when no matching remote was found, - * GIT_EAMBIGUOUS when the branch maps to several remotes, - * otherwise an error code. - */ -GIT_EXTERN(int) git_branch_remote_name( - git_buf *out, - git_repository *repo, - const char *refname); - -/** - * Retrieve the upstream remote of a local branch - * - * This will return the currently configured "branch.*.remote" for a given - * branch. This branch must be local. - * - * @param buf the buffer into which to write the name - * @param repo the repository in which to look - * @param refname the full name of the branch - * @return 0 or an error code - */ - GIT_EXTERN(int) git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname); - -/** - * Retrieve the upstream merge of a local branch - * - * This will return the currently configured "branch.*.merge" for a given - * branch. This branch must be local. - * - * @param buf the buffer into which to write the name - * @param repo the repository in which to look - * @param refname the full name of the branch - * @return 0 or an error code - */ - GIT_EXTERN(int) git_branch_upstream_merge(git_buf *buf, git_repository *repo, const char *refname); - -/** - * Determine whether a branch name is valid, meaning that (when prefixed - * with `refs/heads/`) that it is a valid reference name, and that any - * additional branch name restrictions are imposed (eg, it cannot start - * with a `-`). - * - * @param valid output pointer to set with validity of given branch name - * @param name a branch name to test - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_branch_name_is_valid(int *valid, const char *name); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/buffer.h b/vendor/libgit2-sys/libgit2/include/git2/buffer.h deleted file mode 100644 index 3fe4f85..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/buffer.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_buf_h__ -#define INCLUDE_git_buf_h__ - -#include "common.h" - -/** - * @file git2/buffer.h - * @brief A data structure to return data to callers - * @ingroup Git - * - * The `git_buf` buffer is used to return arbitrary data - typically - * strings - to callers. Callers are responsible for freeing the memory - * in a buffer with the `git_buf_dispose` function. - * @{ - */ -GIT_BEGIN_DECL - -/** - * A data buffer for exporting data from libgit2 - * - * Sometimes libgit2 wants to return an allocated data buffer to the - * caller and have the caller take responsibility for freeing that memory. - * To make ownership clear in these cases, libgit2 uses `git_buf` to - * return this data. Callers should use `git_buf_dispose()` to release - * the memory when they are done. - * - * A `git_buf` contains a pointer to a NUL-terminated C string, and - * the length of the string (not including the NUL terminator). - */ -typedef struct { - /** - * The buffer contents. `ptr` points to the start of the buffer - * being returned. The buffer's length (in bytes) is specified - * by the `size` member of the structure, and contains a NUL - * terminator at position `(size + 1)`. - */ - char *ptr; - - /** - * This field is reserved and unused. - */ - size_t reserved; - - /** - * The length (in bytes) of the buffer pointed to by `ptr`, - * not including a NUL terminator. - */ - size_t size; -} git_buf; - -/** - * Use to initialize a `git_buf` before passing it to a function that - * will populate it. - */ -#define GIT_BUF_INIT { NULL, 0, 0 } - -/** - * Free the memory referred to by the git_buf. - * - * Note that this does not free the `git_buf` itself, just the memory - * pointed to by `buffer->ptr`. - * - * @param buffer The buffer to deallocate - */ -GIT_EXTERN(void) git_buf_dispose(git_buf *buffer); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/cert.h b/vendor/libgit2-sys/libgit2/include/git2/cert.h deleted file mode 100644 index 7b91b63..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/cert.h +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_cert_h__ -#define INCLUDE_git_cert_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/cert.h - * @brief TLS and SSH certificate handling - * @defgroup git_cert Certificate objects - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Type of host certificate structure that is passed to the check callback - */ -typedef enum git_cert_t { - /** - * No information about the certificate is available. This may - * happen when using curl. - */ - GIT_CERT_NONE, - /** - * The `data` argument to the callback will be a pointer to - * the DER-encoded data. - */ - GIT_CERT_X509, - /** - * The `data` argument to the callback will be a pointer to a - * `git_cert_hostkey` structure. - */ - GIT_CERT_HOSTKEY_LIBSSH2, - /** - * The `data` argument to the callback will be a pointer to a - * `git_strarray` with `name:content` strings containing - * information about the certificate. This is used when using - * curl. - */ - GIT_CERT_STRARRAY -} git_cert_t; - -/** - * Parent type for `git_cert_hostkey` and `git_cert_x509`. - */ -struct git_cert { - /** - * Type of certificate. A `GIT_CERT_` value. - */ - git_cert_t cert_type; -}; - -/** - * Callback for the user's custom certificate checks. - * - * @param cert The host certificate - * @param valid Whether the libgit2 checks (OpenSSL or WinHTTP) think - * this certificate is valid - * @param host Hostname of the host libgit2 connected to - * @param payload Payload provided by the caller - * @return 0 to proceed with the connection, < 0 to fail the connection - * or > 0 to indicate that the callback refused to act and that - * the existing validity determination should be honored - */ -typedef int GIT_CALLBACK(git_transport_certificate_check_cb)(git_cert *cert, int valid, const char *host, void *payload); - -/** - * Type of SSH host fingerprint - */ -typedef enum { - /** MD5 is available */ - GIT_CERT_SSH_MD5 = (1 << 0), - /** SHA-1 is available */ - GIT_CERT_SSH_SHA1 = (1 << 1), - /** SHA-256 is available */ - GIT_CERT_SSH_SHA256 = (1 << 2), - /** Raw hostkey is available */ - GIT_CERT_SSH_RAW = (1 << 3) -} git_cert_ssh_t; - -typedef enum { - /** The raw key is of an unknown type. */ - GIT_CERT_SSH_RAW_TYPE_UNKNOWN = 0, - /** The raw key is an RSA key. */ - GIT_CERT_SSH_RAW_TYPE_RSA = 1, - /** The raw key is a DSS key. */ - GIT_CERT_SSH_RAW_TYPE_DSS = 2, - /** The raw key is a ECDSA 256 key. */ - GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_256 = 3, - /** The raw key is a ECDSA 384 key. */ - GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_384 = 4, - /** The raw key is a ECDSA 521 key. */ - GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_521 = 5, - /** The raw key is a ED25519 key. */ - GIT_CERT_SSH_RAW_TYPE_KEY_ED25519 = 6 -} git_cert_ssh_raw_type_t; - -/** - * Hostkey information taken from libssh2 - */ -typedef struct { - git_cert parent; /**< The parent cert */ - - /** - * A bitmask containing the available fields. - */ - git_cert_ssh_t type; - - /** - * Hostkey hash. If `type` has `GIT_CERT_SSH_MD5` set, this will - * have the MD5 hash of the hostkey. - */ - unsigned char hash_md5[16]; - - /** - * Hostkey hash. If `type` has `GIT_CERT_SSH_SHA1` set, this will - * have the SHA-1 hash of the hostkey. - */ - unsigned char hash_sha1[20]; - - /** - * Hostkey hash. If `type` has `GIT_CERT_SSH_SHA256` set, this will - * have the SHA-256 hash of the hostkey. - */ - unsigned char hash_sha256[32]; - - /** - * Raw hostkey type. If `type` has `GIT_CERT_SSH_RAW` set, this will - * have the type of the raw hostkey. - */ - git_cert_ssh_raw_type_t raw_type; - - /** - * Pointer to the raw hostkey. If `type` has `GIT_CERT_SSH_RAW` set, - * this will have the raw contents of the hostkey. - */ - const char *hostkey; - - /** - * Raw hostkey length. If `type` has `GIT_CERT_SSH_RAW` set, this will - * have the length of the raw contents of the hostkey. - */ - size_t hostkey_len; -} git_cert_hostkey; - -/** - * X.509 certificate information - */ -typedef struct { - git_cert parent; /**< The parent cert */ - - /** - * Pointer to the X.509 certificate data - */ - void *data; - - /** - * Length of the memory block pointed to by `data`. - */ - size_t len; -} git_cert_x509; - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/checkout.h b/vendor/libgit2-sys/libgit2/include/git2/checkout.h deleted file mode 100644 index bdea928..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/checkout.h +++ /dev/null @@ -1,468 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_checkout_h__ -#define INCLUDE_git_checkout_h__ - -#include "common.h" -#include "types.h" -#include "diff.h" - -/** - * @file git2/checkout.h - * @brief Update the contents of the working directory - * @defgroup git_checkout Git checkout routines - * @ingroup Git - * - * Update the contents of the working directory, or a subset of the - * files in the working directory, to point to the data in the index - * or a specific commit. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Checkout behavior flags - * - * In libgit2, checkout is used to update the working directory and index - * to match a target tree. Unlike git checkout, it does not move the HEAD - * commit for you - use `git_repository_set_head` or the like to do that. - * - * Checkout looks at (up to) four things: the "target" tree you want to - * check out, the "baseline" tree of what was checked out previously, the - * working directory for actual files, and the index for staged changes. - * - * You give checkout one of two strategies for update: - * - * - `GIT_CHECKOUT_SAFE` is the default, and similar to git's default, - * which will make modifications that will not lose changes in the - * working directory. - * - * | target == baseline | target != baseline | - * ---------------------|-----------------------|----------------------| - * workdir == baseline | no action | create, update, or | - * | | delete file | - * ---------------------|-----------------------|----------------------| - * workdir exists and | no action | conflict (notify | - * is != baseline | notify dirty MODIFIED | and cancel checkout) | - * ---------------------|-----------------------|----------------------| - * workdir missing, | notify dirty DELETED | create file | - * baseline present | | | - * ---------------------|-----------------------|----------------------| - * - * - `GIT_CHECKOUT_FORCE` will take any action to make the working - * directory match the target (including potentially discarding - * modified files). - * - * To emulate `git checkout`, use `GIT_CHECKOUT_SAFE` with a checkout - * notification callback (see below) that displays information about dirty - * files. The default behavior will cancel checkout on conflicts. - * - * To emulate `git checkout-index`, use `GIT_CHECKOUT_SAFE` with a - * notification callback that cancels the operation if a dirty-but-existing - * file is found in the working directory. This core git command isn't - * quite "force" but is sensitive about some types of changes. - * - * To emulate `git checkout -f`, use `GIT_CHECKOUT_FORCE`. - * - * - * There are some additional flags to modify the behavior of checkout: - * - * - `GIT_CHECKOUT_DRY_RUN` is a dry-run strategy that checks for conflicts, - * etc., but doesn't make any actual changes. - * - * - GIT_CHECKOUT_ALLOW_CONFLICTS makes SAFE mode apply safe file updates - * even if there are conflicts (instead of cancelling the checkout). - * - * - GIT_CHECKOUT_REMOVE_UNTRACKED means remove untracked files (i.e. not - * in target, baseline, or index, and not ignored) from the working dir. - * - * - GIT_CHECKOUT_REMOVE_IGNORED means remove ignored files (that are also - * untracked) from the working directory as well. - * - * - GIT_CHECKOUT_UPDATE_ONLY means to only update the content of files that - * already exist. Files will not be created nor deleted. This just skips - * applying adds, deletes, and typechanges. - * - * - GIT_CHECKOUT_DONT_UPDATE_INDEX prevents checkout from writing the - * updated files' information to the index. - * - * - Normally, checkout will reload the index and git attributes from disk - * before any operations. GIT_CHECKOUT_NO_REFRESH prevents this reload. - * - * - Unmerged index entries are conflicts. GIT_CHECKOUT_SKIP_UNMERGED skips - * files with unmerged index entries instead. GIT_CHECKOUT_USE_OURS and - * GIT_CHECKOUT_USE_THEIRS to proceed with the checkout using either the - * stage 2 ("ours") or stage 3 ("theirs") version of files in the index. - * - * - GIT_CHECKOUT_DONT_OVERWRITE_IGNORED prevents ignored files from being - * overwritten. Normally, files that are ignored in the working directory - * are not considered "precious" and may be overwritten if the checkout - * target contains that file. - * - * - GIT_CHECKOUT_DONT_REMOVE_EXISTING prevents checkout from removing - * files or folders that fold to the same name on case insensitive - * filesystems. This can cause files to retain their existing names - * and write through existing symbolic links. - * - * @flags - */ -typedef enum { - /** - * Allow safe updates that cannot overwrite uncommitted data. - * If the uncommitted changes don't conflict with the checked - * out files, the checkout will still proceed, leaving the - * changes intact. - */ - GIT_CHECKOUT_SAFE = 0, - - /** - * Allow all updates to force working directory to look like - * the index, potentially losing data in the process. - */ - GIT_CHECKOUT_FORCE = (1u << 1), - - /** Allow checkout to recreate missing files */ - GIT_CHECKOUT_RECREATE_MISSING = (1u << 2), - - /** Allow checkout to make safe updates even if conflicts are found */ - GIT_CHECKOUT_ALLOW_CONFLICTS = (1u << 4), - - /** Remove untracked files not in index (that are not ignored) */ - GIT_CHECKOUT_REMOVE_UNTRACKED = (1u << 5), - - /** Remove ignored files not in index */ - GIT_CHECKOUT_REMOVE_IGNORED = (1u << 6), - - /** Only update existing files, don't create new ones */ - GIT_CHECKOUT_UPDATE_ONLY = (1u << 7), - - /** - * Normally checkout updates index entries as it goes; this stops that. - * Implies `GIT_CHECKOUT_DONT_WRITE_INDEX`. - */ - GIT_CHECKOUT_DONT_UPDATE_INDEX = (1u << 8), - - /** Don't refresh index/config/etc before doing checkout */ - GIT_CHECKOUT_NO_REFRESH = (1u << 9), - - /** Allow checkout to skip unmerged files */ - GIT_CHECKOUT_SKIP_UNMERGED = (1u << 10), - /** For unmerged files, checkout stage 2 from index */ - GIT_CHECKOUT_USE_OURS = (1u << 11), - /** For unmerged files, checkout stage 3 from index */ - GIT_CHECKOUT_USE_THEIRS = (1u << 12), - - /** Treat pathspec as simple list of exact match file paths */ - GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH = (1u << 13), - - /** Ignore directories in use, they will be left empty */ - GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES = (1u << 18), - - /** Don't overwrite ignored files that exist in the checkout target */ - GIT_CHECKOUT_DONT_OVERWRITE_IGNORED = (1u << 19), - - /** Write normal merge files for conflicts */ - GIT_CHECKOUT_CONFLICT_STYLE_MERGE = (1u << 20), - - /** Include common ancestor data in diff3 format files for conflicts */ - GIT_CHECKOUT_CONFLICT_STYLE_DIFF3 = (1u << 21), - - /** Don't overwrite existing files or folders */ - GIT_CHECKOUT_DONT_REMOVE_EXISTING = (1u << 22), - - /** Normally checkout writes the index upon completion; this prevents that. */ - GIT_CHECKOUT_DONT_WRITE_INDEX = (1u << 23), - - /** - * Perform a "dry run", reporting what _would_ be done but - * without actually making changes in the working directory - * or the index. - */ - GIT_CHECKOUT_DRY_RUN = (1u << 24), - - /** Include common ancestor data in zdiff3 format for conflicts */ - GIT_CHECKOUT_CONFLICT_STYLE_ZDIFF3 = (1u << 25), - - /** - * Do not do a checkout and do not fire callbacks; this is primarily - * useful only for internal functions that will perform the - * checkout themselves but need to pass checkout options into - * another function, for example, `git_clone`. - */ - GIT_CHECKOUT_NONE = (1u << 30), - - /* - * THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED - */ - - /** Recursively checkout submodules with same options (NOT IMPLEMENTED) */ - GIT_CHECKOUT_UPDATE_SUBMODULES = (1u << 16), - /** Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED) */ - GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17) -} git_checkout_strategy_t; - -/** - * Checkout notification flags - * - * Checkout will invoke an options notification callback (`notify_cb`) for - * certain cases - you pick which ones via `notify_flags`: - * - * Returning a non-zero value from this callback will cancel the checkout. - * The non-zero return value will be propagated back and returned by the - * git_checkout_... call. - * - * Notification callbacks are made prior to modifying any files on disk, - * so canceling on any notification will still happen prior to any files - * being modified. - * - * @flags - */ -typedef enum { - GIT_CHECKOUT_NOTIFY_NONE = 0, - - /** - * Invokes checkout on conflicting paths. - */ - GIT_CHECKOUT_NOTIFY_CONFLICT = (1u << 0), - - /** - * Notifies about "dirty" files, i.e. those that do not need an update - * but no longer match the baseline. Core git displays these files when - * checkout runs, but won't stop the checkout. - */ - GIT_CHECKOUT_NOTIFY_DIRTY = (1u << 1), - - /** - * Sends notification for any file changed. - */ - GIT_CHECKOUT_NOTIFY_UPDATED = (1u << 2), - - /** - * Notifies about untracked files. - */ - GIT_CHECKOUT_NOTIFY_UNTRACKED = (1u << 3), - - /** - * Notifies about ignored files. - */ - GIT_CHECKOUT_NOTIFY_IGNORED = (1u << 4), - - GIT_CHECKOUT_NOTIFY_ALL = 0x0FFFFu -} git_checkout_notify_t; - -/** Checkout performance-reporting structure */ -typedef struct { - size_t mkdir_calls; - size_t stat_calls; - size_t chmod_calls; -} git_checkout_perfdata; - -/** - * Checkout notification callback function. - * - * @param why the notification reason - * @param path the path to the file being checked out - * @param baseline the baseline's diff file information - * @param target the checkout target diff file information - * @param workdir the working directory diff file information - * @param payload the user-supplied callback payload - * @return 0 on success, or an error code - */ -typedef int GIT_CALLBACK(git_checkout_notify_cb)( - git_checkout_notify_t why, - const char *path, - const git_diff_file *baseline, - const git_diff_file *target, - const git_diff_file *workdir, - void *payload); - -/** - * Checkout progress notification function. - * - * @param path the path to the file being checked out - * @param completed_steps number of checkout steps completed - * @param total_steps number of total steps in the checkout process - * @param payload the user-supplied callback payload - */ -typedef void GIT_CALLBACK(git_checkout_progress_cb)( - const char *path, - size_t completed_steps, - size_t total_steps, - void *payload); - -/** - * Checkout performance data reporting function. - * - * @param perfdata the performance data for the checkout - * @param payload the user-supplied callback payload - */ -typedef void GIT_CALLBACK(git_checkout_perfdata_cb)( - const git_checkout_perfdata *perfdata, - void *payload); - -/** - * Checkout options structure - * - * Initialize with `GIT_CHECKOUT_OPTIONS_INIT`. Alternatively, you can - * use `git_checkout_options_init`. - * - * @options[version] GIT_CHECKOUT_OPTIONS_VERSION - * @options[init_macro] GIT_CHECKOUT_OPTIONS_INIT - * @options[init_function] git_checkout_options_init - */ -typedef struct git_checkout_options { - unsigned int version; /**< The version */ - - /** - * Checkout strategy. Default is a safe checkout. - * - * @type[flags] git_checkout_strategy_t - */ - unsigned int checkout_strategy; /**< default will be a safe checkout */ - - int disable_filters; /**< don't apply filters like CRLF conversion */ - unsigned int dir_mode; /**< default is 0755 */ - unsigned int file_mode; /**< default is 0644 or 0755 as dictated by blob */ - int file_open_flags; /**< default is O_CREAT | O_TRUNC | O_WRONLY */ - - /** - * Checkout notification flags specify what operations the notify - * callback is invoked for. - * - * @type[flags] git_checkout_notify_t - */ - unsigned int notify_flags; - - /** - * Optional callback to get notifications on specific file states. - * @see git_checkout_notify_t - */ - git_checkout_notify_cb notify_cb; - - /** Payload passed to notify_cb */ - void *notify_payload; - - /** Optional callback to notify the consumer of checkout progress. */ - git_checkout_progress_cb progress_cb; - - /** Payload passed to progress_cb */ - void *progress_payload; - - /** - * A list of wildmatch patterns or paths. - * - * By default, all paths are processed. If you pass an array of wildmatch - * patterns, those will be used to filter which paths should be taken into - * account. - * - * Use GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH to treat as a simple list. - */ - git_strarray paths; - - /** - * The expected content of the working directory; defaults to HEAD. - * - * If the working directory does not match this baseline information, - * that will produce a checkout conflict. - */ - git_tree *baseline; - - /** - * Like `baseline` above, though expressed as an index. This - * option overrides `baseline`. - */ - git_index *baseline_index; - - const char *target_directory; /**< alternative checkout path to workdir */ - - const char *ancestor_label; /**< the name of the common ancestor side of conflicts */ - const char *our_label; /**< the name of the "our" side of conflicts */ - const char *their_label; /**< the name of the "their" side of conflicts */ - - /** Optional callback to notify the consumer of performance data. */ - git_checkout_perfdata_cb perfdata_cb; - - /** Payload passed to perfdata_cb */ - void *perfdata_payload; -} git_checkout_options; - - -/** Current version for the `git_checkout_options` structure */ -#define GIT_CHECKOUT_OPTIONS_VERSION 1 - -/** Static constructor for `git_checkout_options` */ -#define GIT_CHECKOUT_OPTIONS_INIT { GIT_CHECKOUT_OPTIONS_VERSION } - -/** - * Initialize git_checkout_options structure - * - * Initializes a `git_checkout_options` with default values. Equivalent to creating - * an instance with GIT_CHECKOUT_OPTIONS_INIT. - * - * @param opts The `git_checkout_options` struct to initialize. - * @param version The struct version; pass `GIT_CHECKOUT_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_checkout_options_init( - git_checkout_options *opts, - unsigned int version); - -/** - * Updates files in the index and the working tree to match the content of - * the commit pointed at by HEAD. - * - * Note that this is _not_ the correct mechanism used to switch branches; - * do not change your `HEAD` and then call this method, that would leave - * you with checkout conflicts since your working directory would then - * appear to be dirty. Instead, checkout the target of the branch and - * then update `HEAD` using `git_repository_set_head` to point to the - * branch you checked out. - * - * @param repo repository to check out (must be non-bare) - * @param opts specifies checkout options (may be NULL) - * @return 0 on success, GIT_EUNBORNBRANCH if HEAD points to a non - * existing branch, non-zero value returned by `notify_cb`, or - * other error code < 0 (use git_error_last for error details) - */ -GIT_EXTERN(int) git_checkout_head( - git_repository *repo, - const git_checkout_options *opts); - -/** - * Updates files in the working tree to match the content of the index. - * - * @param repo repository into which to check out (must be non-bare) - * @param index index to be checked out (or NULL to use repository index) - * @param opts specifies checkout options (may be NULL) - * @return 0 on success, non-zero return value from `notify_cb`, or error - * code < 0 (use git_error_last for error details) - */ -GIT_EXTERN(int) git_checkout_index( - git_repository *repo, - git_index *index, - const git_checkout_options *opts); - -/** - * Updates files in the index and working tree to match the content of the - * tree pointed at by the treeish. - * - * @param repo repository to check out (must be non-bare) - * @param treeish a commit, tag or tree which content will be used to update - * the working directory (or NULL to use HEAD) - * @param opts specifies checkout options (may be NULL) - * @return 0 on success, non-zero return value from `notify_cb`, or error - * code < 0 (use git_error_last for error details) - */ -GIT_EXTERN(int) git_checkout_tree( - git_repository *repo, - const git_object *treeish, - const git_checkout_options *opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/cherrypick.h b/vendor/libgit2-sys/libgit2/include/git2/cherrypick.h deleted file mode 100644 index e6cf99e..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/cherrypick.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_cherrypick_h__ -#define INCLUDE_git_cherrypick_h__ - -#include "common.h" -#include "types.h" -#include "merge.h" - -/** - * @file git2/cherrypick.h - * @brief Cherry-pick the contents of an individual commit - * @defgroup git_cherrypick Git cherry-pick routines - * @ingroup Git - * - * "Cherry-pick" will attempts to re-apply the changes in an - * individual commit to the current index and working directory. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Cherry-pick options - */ -typedef struct { - unsigned int version; - - /** For merge commits, the "mainline" is treated as the parent. */ - unsigned int mainline; - - git_merge_options merge_opts; /**< Options for the merging */ - git_checkout_options checkout_opts; /**< Options for the checkout */ -} git_cherrypick_options; - -/** Current version for the `git_cherrypick_options` structure */ -#define GIT_CHERRYPICK_OPTIONS_VERSION 1 - -/** Static constructor for `git_cherrypick_options` */ -#define GIT_CHERRYPICK_OPTIONS_INIT { \ - GIT_CHERRYPICK_OPTIONS_VERSION, 0, \ - GIT_MERGE_OPTIONS_INIT, GIT_CHECKOUT_OPTIONS_INIT } - -/** - * Initialize git_cherrypick_options structure - * - * Initializes a `git_cherrypick_options` with default values. Equivalent to creating - * an instance with GIT_CHERRYPICK_OPTIONS_INIT. - * - * @param opts The `git_cherrypick_options` struct to initialize. - * @param version The struct version; pass `GIT_CHERRYPICK_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_cherrypick_options_init( - git_cherrypick_options *opts, - unsigned int version); - -/** - * Cherry-picks the given commit against the given "our" commit, producing an - * index that reflects the result of the cherry-pick. - * - * The returned index must be freed explicitly with `git_index_free`. - * - * @param out pointer to store the index result in - * @param repo the repository that contains the given commits - * @param cherrypick_commit the commit to cherry-pick - * @param our_commit the commit to cherry-pick against (eg, HEAD) - * @param mainline the parent of the `cherrypick_commit`, if it is a merge - * @param merge_options the merge options (or null for defaults) - * @return zero on success, -1 on failure. - */ -GIT_EXTERN(int) git_cherrypick_commit( - git_index **out, - git_repository *repo, - git_commit *cherrypick_commit, - git_commit *our_commit, - unsigned int mainline, - const git_merge_options *merge_options); - -/** - * Cherry-pick the given commit, producing changes in the index and working directory. - * - * @param repo the repository to cherry-pick - * @param commit the commit to cherry-pick - * @param cherrypick_options the cherry-pick options (or null for defaults) - * @return zero on success, -1 on failure. - */ -GIT_EXTERN(int) git_cherrypick( - git_repository *repo, - git_commit *commit, - const git_cherrypick_options *cherrypick_options); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/clone.h b/vendor/libgit2-sys/libgit2/include/git2/clone.h deleted file mode 100644 index b7a47ab..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/clone.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_clone_h__ -#define INCLUDE_git_clone_h__ - -#include "common.h" -#include "types.h" -#include "indexer.h" -#include "checkout.h" -#include "remote.h" -#include "transport.h" - - -/** - * @file git2/clone.h - * @brief Clone a remote repository to the local disk - * @defgroup git_clone Git cloning routines - * @ingroup Git - * - * Clone will take a remote repository - located on a remote server - * accessible by HTTPS or SSH, or a repository located elsewhere on - * the local disk - and place a copy in the given local path. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Options for bypassing the git-aware transport on clone. Bypassing - * it means that instead of a fetch, libgit2 will copy the object - * database directory instead of figuring out what it needs, which is - * faster. If possible, it will hardlink the files to save space. - */ -typedef enum { - /** - * Auto-detect (default), libgit2 will bypass the git-aware - * transport for local paths, but use a normal fetch for - * `file://` urls. - */ - GIT_CLONE_LOCAL_AUTO, - /** - * Bypass the git-aware transport even for a `file://` url. - */ - GIT_CLONE_LOCAL, - /** - * Do no bypass the git-aware transport - */ - GIT_CLONE_NO_LOCAL, - /** - * Bypass the git-aware transport, but do not try to use - * hardlinks. - */ - GIT_CLONE_LOCAL_NO_LINKS -} git_clone_local_t; - -/** - * The signature of a function matching git_remote_create, with an additional - * void* as a callback payload. - * - * Callers of git_clone may provide a function matching this signature to override - * the remote creation and customization process during a clone operation. - * - * @param[out] out the resulting remote - * @param repo the repository in which to create the remote - * @param name the remote's name - * @param url the remote's url - * @param payload an opaque payload - * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code - */ -typedef int GIT_CALLBACK(git_remote_create_cb)( - git_remote **out, - git_repository *repo, - const char *name, - const char *url, - void *payload); - -/** - * The signature of a function matching git_repository_init, with an - * additional void * as callback payload. - * - * Callers of git_clone my provide a function matching this signature - * to override the repository creation and customization process - * during a clone operation. - * - * @param[out] out the resulting repository - * @param path path in which to create the repository - * @param bare whether the repository is bare. This is the value from the clone options - * @param payload payload specified by the options - * @return 0, or a negative value to indicate error - */ -typedef int GIT_CALLBACK(git_repository_create_cb)( - git_repository **out, - const char *path, - int bare, - void *payload); - -/** - * Clone options structure - * - * Initialize with `GIT_CLONE_OPTIONS_INIT`. Alternatively, you can - * use `git_clone_options_init`. - * - * @options[version] GIT_CLONE_OPTIONS_VERSION - * @options[init_macro] GIT_CLONE_OPTIONS_INIT - * @options[init_function] git_clone_options_init - */ -typedef struct git_clone_options { - unsigned int version; - - /** - * These options are passed to the checkout step. To disable - * checkout, set the `checkout_strategy` to `GIT_CHECKOUT_NONE` - * or `GIT_CHECKOUT_DRY_RUN`. - */ - git_checkout_options checkout_opts; - - /** - * Options which control the fetch, including callbacks. - * - * The callbacks are used for reporting fetch progress, and for acquiring - * credentials in the event they are needed. - */ - git_fetch_options fetch_opts; - - /** - * Set to zero (false) to create a standard repo, or non-zero - * for a bare repo - */ - int bare; - - /** - * Whether to use a fetch or copy the object database. - */ - git_clone_local_t local; - - /** - * The name of the branch to checkout. NULL means use the - * remote's default branch. - */ - const char *checkout_branch; - - /** - * A callback used to create the new repository into which to - * clone. If NULL, the 'bare' field will be used to determine - * whether to create a bare repository. - */ - git_repository_create_cb repository_cb; - - /** - * An opaque payload to pass to the git_repository creation callback. - * This parameter is ignored unless repository_cb is non-NULL. - */ - void *repository_cb_payload; - - /** - * A callback used to create the git_remote, prior to its being - * used to perform the clone operation. See the documentation for - * git_remote_create_cb for details. This parameter may be NULL, - * indicating that git_clone should provide default behavior. - */ - git_remote_create_cb remote_cb; - - /** - * An opaque payload to pass to the git_remote creation callback. - * This parameter is ignored unless remote_cb is non-NULL. - */ - void *remote_cb_payload; -} git_clone_options; - -/** Current version for the `git_clone_options` structure */ -#define GIT_CLONE_OPTIONS_VERSION 1 - -/** Static constructor for `git_clone_options` */ -#define GIT_CLONE_OPTIONS_INIT \ - { GIT_CLONE_OPTIONS_VERSION, \ - GIT_CHECKOUT_OPTIONS_INIT, \ - GIT_FETCH_OPTIONS_INIT } - -/** - * Initialize git_clone_options structure - * - * Initializes a `git_clone_options` with default values. Equivalent to creating - * an instance with GIT_CLONE_OPTIONS_INIT. - * - * @param opts The `git_clone_options` struct to initialize. - * @param version The struct version; pass `GIT_CLONE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_clone_options_init( - git_clone_options *opts, - unsigned int version); - -/** - * Clone a remote repository. - * - * By default this creates its repository and initial remote to match - * git's defaults. You can use the options in the callback to - * customize how these are created. - * - * Note that the libgit2 library _must_ be initialized using - * `git_libgit2_init` before any APIs can be called, including - * this one. - * - * @param[out] out pointer that will receive the resulting repository object - * @param url the remote repository to clone - * @param local_path local directory to clone to - * @param options configuration options for the clone. If NULL, the - * function works as though GIT_OPTIONS_INIT were passed. - * @return 0 on success, any non-zero return value from a callback - * function, or a negative value to indicate an error (use - * `git_error_last` for a detailed error message) - */ -GIT_EXTERN(int) git_clone( - git_repository **out, - const char *url, - const char *local_path, - const git_clone_options *options); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/commit.h b/vendor/libgit2-sys/libgit2/include/git2/commit.h deleted file mode 100644 index b998e18..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/commit.h +++ /dev/null @@ -1,675 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_commit_h__ -#define INCLUDE_git_commit_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "object.h" - -/** - * @file git2/commit.h - * @brief A representation of a set of changes in the repository - * @defgroup git_commit Git commit parsing, formatting routines - * @ingroup Git - * - * A commit represents a set of changes made to the files within a - * repository, and metadata about who made the changes, and when the - * changes were made. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a commit object from a repository. - * - * The returned object should be released with `git_commit_free` when no - * longer needed. - * - * @param commit pointer to the looked up commit - * @param repo the repo to use when locating the commit. - * @param id identity of the commit to locate. If the object is - * an annotated tag it will be peeled back to the commit. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_lookup( - git_commit **commit, git_repository *repo, const git_oid *id); - -/** - * Lookup a commit object from a repository, given a prefix of its - * identifier (short id). - * - * The returned object should be released with `git_commit_free` when no - * longer needed. - * - * @see git_object_lookup_prefix - * - * @param commit pointer to the looked up commit - * @param repo the repo to use when locating the commit. - * @param id identity of the commit to locate. If the object is - * an annotated tag it will be peeled back to the commit. - * @param len the length of the short identifier - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_lookup_prefix( - git_commit **commit, git_repository *repo, const git_oid *id, size_t len); - -/** - * Close an open commit - * - * This is a wrapper around git_object_free() - * - * IMPORTANT: - * It *is* necessary to call this method when you stop - * using a commit. Failure to do so will cause a memory leak. - * - * @param commit the commit to close - */ - -GIT_EXTERN(void) git_commit_free(git_commit *commit); - -/** - * Get the id of a commit. - * - * @param commit a previously loaded commit. - * @return object identity for the commit. - */ -GIT_EXTERN(const git_oid *) git_commit_id(const git_commit *commit); - -/** - * Get the repository that contains the commit. - * - * @param commit A previously loaded commit. - * @return Repository that contains this commit. - */ -GIT_EXTERN(git_repository *) git_commit_owner(const git_commit *commit); - -/** - * Get the encoding for the message of a commit, - * as a string representing a standard encoding name. - * - * The encoding may be NULL if the `encoding` header - * in the commit is missing; in that case UTF-8 is assumed. - * - * @param commit a previously loaded commit. - * @return NULL, or the encoding - */ -GIT_EXTERN(const char *) git_commit_message_encoding(const git_commit *commit); - -/** - * Get the full message of a commit. - * - * The returned message will be slightly prettified by removing any - * potential leading newlines. - * - * @param commit a previously loaded commit. - * @return the message of a commit - */ -GIT_EXTERN(const char *) git_commit_message(const git_commit *commit); - -/** - * Get the full raw message of a commit. - * - * @param commit a previously loaded commit. - * @return the raw message of a commit - */ -GIT_EXTERN(const char *) git_commit_message_raw(const git_commit *commit); - -/** - * Get the short "summary" of the git commit message. - * - * The returned message is the summary of the commit, comprising the - * first paragraph of the message with whitespace trimmed and squashed. - * - * @param commit a previously loaded commit. - * @return the summary of a commit or NULL on error - */ -GIT_EXTERN(const char *) git_commit_summary(git_commit *commit); - -/** - * Get the long "body" of the git commit message. - * - * The returned message is the body of the commit, comprising - * everything but the first paragraph of the message. Leading and - * trailing whitespaces are trimmed. - * - * @param commit a previously loaded commit. - * @return the body of a commit or NULL when no the message only - * consists of a summary - */ -GIT_EXTERN(const char *) git_commit_body(git_commit *commit); - -/** - * Get the commit time (i.e. committer time) of a commit. - * - * @param commit a previously loaded commit. - * @return the time of a commit - */ -GIT_EXTERN(git_time_t) git_commit_time(const git_commit *commit); - -/** - * Get the commit timezone offset (i.e. committer's preferred timezone) of a commit. - * - * @param commit a previously loaded commit. - * @return positive or negative timezone offset, in minutes from UTC - */ -GIT_EXTERN(int) git_commit_time_offset(const git_commit *commit); - -/** - * Get the committer of a commit. - * - * @param commit a previously loaded commit. - * @return the committer of a commit - */ -GIT_EXTERN(const git_signature *) git_commit_committer(const git_commit *commit); - -/** - * Get the author of a commit. - * - * @param commit a previously loaded commit. - * @return the author of a commit - */ -GIT_EXTERN(const git_signature *) git_commit_author(const git_commit *commit); - -/** - * Get the committer of a commit, using the mailmap to map names and email - * addresses to canonical real names and email addresses. - * - * Call `git_signature_free` to free the signature. - * - * @param out a pointer to store the resolved signature. - * @param commit a previously loaded commit. - * @param mailmap the mailmap to resolve with. (may be NULL) - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_committer_with_mailmap( - git_signature **out, const git_commit *commit, const git_mailmap *mailmap); - -/** - * Get the author of a commit, using the mailmap to map names and email - * addresses to canonical real names and email addresses. - * - * Call `git_signature_free` to free the signature. - * - * @param out a pointer to store the resolved signature. - * @param commit a previously loaded commit. - * @param mailmap the mailmap to resolve with. (may be NULL) - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_author_with_mailmap( - git_signature **out, const git_commit *commit, const git_mailmap *mailmap); - -/** - * Get the full raw text of the commit header. - * - * @param commit a previously loaded commit - * @return the header text of the commit - */ -GIT_EXTERN(const char *) git_commit_raw_header(const git_commit *commit); - -/** - * Get the tree pointed to by a commit. - * - * @param tree_out pointer where to store the tree object - * @param commit a previously loaded commit. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, const git_commit *commit); - -/** - * Get the id of the tree pointed to by a commit. This differs from - * `git_commit_tree` in that no attempts are made to fetch an object - * from the ODB. - * - * @param commit a previously loaded commit. - * @return the id of tree pointed to by commit. - */ -GIT_EXTERN(const git_oid *) git_commit_tree_id(const git_commit *commit); - -/** - * Get the number of parents of this commit - * - * @param commit a previously loaded commit. - * @return integer of count of parents - */ -GIT_EXTERN(unsigned int) git_commit_parentcount(const git_commit *commit); - -/** - * Get the specified parent of the commit. - * - * @param out Pointer where to store the parent commit - * @param commit a previously loaded commit. - * @param n the position of the parent (from 0 to `parentcount`) - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_parent( - git_commit **out, - const git_commit *commit, - unsigned int n); - -/** - * Get the oid of a specified parent for a commit. This is different from - * `git_commit_parent`, which will attempt to load the parent commit from - * the ODB. - * - * @param commit a previously loaded commit. - * @param n the position of the parent (from 0 to `parentcount`) - * @return the id of the parent, NULL on error. - */ -GIT_EXTERN(const git_oid *) git_commit_parent_id( - const git_commit *commit, - unsigned int n); - -/** - * Get the commit object that is the th generation ancestor - * of the named commit object, following only the first parents. - * The returned commit has to be freed by the caller. - * - * Passing `0` as the generation number returns another instance of the - * base commit itself. - * - * @param ancestor Pointer where to store the ancestor commit - * @param commit a previously loaded commit. - * @param n the requested generation - * @return 0 on success; GIT_ENOTFOUND if no matching ancestor exists - * or an error code - */ -GIT_EXTERN(int) git_commit_nth_gen_ancestor( - git_commit **ancestor, - const git_commit *commit, - unsigned int n); - -/** - * Get an arbitrary header field - * - * @param out the buffer to fill; existing content will be - * overwritten - * @param commit the commit to look in - * @param field the header field to return - * @return 0 on succeess, GIT_ENOTFOUND if the field does not exist, - * or an error code - */ -GIT_EXTERN(int) git_commit_header_field(git_buf *out, const git_commit *commit, const char *field); - -/** - * Extract the signature from a commit - * - * If the id is not for a commit, the error class will be - * `GIT_ERROR_INVALID`. If the commit does not have a signature, the - * error class will be `GIT_ERROR_OBJECT`. - * - * @param signature the signature block; existing content will be - * overwritten - * @param signed_data signed data; this is the commit contents minus the signature block; - * existing content will be overwritten - * @param repo the repository in which the commit exists - * @param commit_id the commit from which to extract the data - * @param field the name of the header field containing the signature - * block; pass `NULL` to extract the default 'gpgsig' - * @return 0 on success, GIT_ENOTFOUND if the id is not for a commit - * or the commit does not have a signature. - */ -GIT_EXTERN(int) git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_repository *repo, git_oid *commit_id, const char *field); - -/** - * Create new commit in the repository from a list of `git_object` pointers - * - * The message will **not** be cleaned up automatically. You can do that - * with the `git_message_prettify()` function. - * - * @param id Pointer in which to store the OID of the newly created commit - * - * @param repo Repository where to store the commit - * - * @param update_ref If not NULL, name of the reference that - * will be updated to point to this commit. If the reference - * is not direct, it will be resolved to a direct reference. - * Use "HEAD" to update the HEAD of the current branch and - * make it point to this commit. If the reference doesn't - * exist yet, it will be created. If it does exist, the first - * parent must be the tip of this branch. - * - * @param author Signature with author and author time of commit - * - * @param committer Signature with committer and * commit time of commit - * - * @param message_encoding The encoding for the message in the - * commit, represented with a standard encoding name. - * E.g. "UTF-8". If NULL, no encoding header is written and - * UTF-8 is assumed. - * - * @param message Full message for this commit - * - * @param tree An instance of a `git_tree` object that will - * be used as the tree for the commit. This tree object must - * also be owned by the given `repo`. - * - * @param parent_count Number of parents for this commit - * - * @param parents Array of `parent_count` pointers to `git_commit` - * objects that will be used as the parents for this commit. This - * array may be NULL if `parent_count` is 0 (root commit). All the - * given commits must be owned by the `repo`. - * - * @return 0 or an error code - * The created commit will be written to the Object Database and - * the given reference will be updated to point to it - */ -GIT_EXTERN(int) git_commit_create( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - const git_commit *parents[]); - -/** - * Create new commit in the repository using a variable argument list. - * - * The message will **not** be cleaned up automatically. You can do that - * with the `git_message_prettify()` function. - * - * The parents for the commit are specified as a variable list of pointers - * to `const git_commit *`. Note that this is a convenience method which may - * not be safe to export for certain languages or compilers - * - * All other parameters remain the same as `git_commit_create()`. - * - * @param id Pointer in which to store the OID of the newly created commit - * - * @param repo Repository where to store the commit - * - * @param update_ref If not NULL, name of the reference that - * will be updated to point to this commit. If the reference - * is not direct, it will be resolved to a direct reference. - * Use "HEAD" to update the HEAD of the current branch and - * make it point to this commit. If the reference doesn't - * exist yet, it will be created. If it does exist, the first - * parent must be the tip of this branch. - * - * @param author Signature with author and author time of commit - * - * @param committer Signature with committer and * commit time of commit - * - * @param message_encoding The encoding for the message in the - * commit, represented with a standard encoding name. - * E.g. "UTF-8". If NULL, no encoding header is written and - * UTF-8 is assumed. - * - * @param message Full message for this commit - * - * @param tree An instance of a `git_tree` object that will - * be used as the tree for the commit. This tree object must - * also be owned by the given `repo`. - * - * @param parent_count Number of parents for this commit - * - * @return 0 or an error code - * The created commit will be written to the Object Database and - * the given reference will be updated to point to it - */ -GIT_EXTERN(int) git_commit_create_v( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - ...); - -typedef struct { - unsigned int version; - - /** - * Flags for creating the commit. - * - * If `allow_empty_commit` is specified, a commit with no changes - * from the prior commit (and "empty" commit) is allowed. Otherwise, - * commit creation will be stopped. - */ - unsigned int allow_empty_commit : 1; - - /** The commit author, or NULL for the default. */ - const git_signature *author; - - /** The committer, or NULL for the default. */ - const git_signature *committer; - - /** Encoding for the commit message; leave NULL for default. */ - const char *message_encoding; -} git_commit_create_options; - -/** Current version for the `git_commit_create_options` structure */ -#define GIT_COMMIT_CREATE_OPTIONS_VERSION 1 - -/** Static constructor for `git_commit_create_options` */ -#define GIT_COMMIT_CREATE_OPTIONS_INIT { GIT_COMMIT_CREATE_OPTIONS_VERSION } - -/** - * Commits the staged changes in the repository; this is a near analog to - * `git commit -m message`. - * - * By default, empty commits are not allowed. - * - * @param id pointer to store the new commit's object id - * @param repo repository to commit changes in - * @param message the commit message - * @param opts options for creating the commit - * @return 0 on success, GIT_EUNCHANGED if there were no changes to commit, or an error code - */ -GIT_EXTERN(int) git_commit_create_from_stage( - git_oid *id, - git_repository *repo, - const char *message, - const git_commit_create_options *opts); - -/** - * Amend an existing commit by replacing only non-NULL values. - * - * This creates a new commit that is exactly the same as the old commit, - * except that any non-NULL values will be updated. The new commit has - * the same parents as the old commit. - * - * The `update_ref` value works as in the regular `git_commit_create()`, - * updating the ref to point to the newly rewritten commit. If you want - * to amend a commit that is not currently the tip of the branch and then - * rewrite the following commits to reach a ref, pass this as NULL and - * update the rest of the commit chain and ref separately. - * - * Unlike `git_commit_create()`, the `author`, `committer`, `message`, - * `message_encoding`, and `tree` parameters can be NULL in which case this - * will use the values from the original `commit_to_amend`. - * - * All parameters have the same meanings as in `git_commit_create()`. - * - * @param id Pointer in which to store the OID of the newly created commit - * - * @param commit_to_amend The commit to amend - * - * @param update_ref If not NULL, name of the reference that - * will be updated to point to this commit. If the reference - * is not direct, it will be resolved to a direct reference. - * Use "HEAD" to update the HEAD of the current branch and - * make it point to this commit. If the reference doesn't - * exist yet, it will be created. If it does exist, the first - * parent must be the tip of this branch. - * - * @param author Signature with author and author time of commit - * - * @param committer Signature with committer and * commit time of commit - * - * @param message_encoding The encoding for the message in the - * commit, represented with a standard encoding name. - * E.g. "UTF-8". If NULL, no encoding header is written and - * UTF-8 is assumed. - * - * @param message Full message for this commit - * - * @param tree An instance of a `git_tree` object that will - * be used as the tree for the commit. This tree object must - * also be owned by the given `repo`. - * - * @return 0 or an error code - * The created commit will be written to the Object Database and - * the given reference will be updated to point to it - */ -GIT_EXTERN(int) git_commit_amend( - git_oid *id, - const git_commit *commit_to_amend, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree); - -/** - * Create a commit and write it into a buffer - * - * Create a commit as with `git_commit_create()` but instead of - * writing it to the objectdb, write the contents of the object into a - * buffer. - * - * @param out the buffer into which to write the commit object content - * - * @param repo Repository where the referenced tree and parents live - * - * @param author Signature with author and author time of commit - * - * @param committer Signature with committer and * commit time of commit - * - * @param message_encoding The encoding for the message in the - * commit, represented with a standard encoding name. - * E.g. "UTF-8". If NULL, no encoding header is written and - * UTF-8 is assumed. - * - * @param message Full message for this commit - * - * @param tree An instance of a `git_tree` object that will - * be used as the tree for the commit. This tree object must - * also be owned by the given `repo`. - * - * @param parent_count Number of parents for this commit - * - * @param parents Array of `parent_count` pointers to `git_commit` - * objects that will be used as the parents for this commit. This - * array may be NULL if `parent_count` is 0 (root commit). All the - * given commits must be owned by the `repo`. - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_create_buffer( - git_buf *out, - git_repository *repo, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - const git_commit *parents[]); - -/** - * Create a commit object from the given buffer and signature - * - * Given the unsigned commit object's contents, its signature and the - * header field in which to store the signature, attach the signature - * to the commit and write it into the given repository. - * - * @param out the resulting commit id - * @param repo the repository to create the commit in. - * @param commit_content the content of the unsigned commit object - * @param signature the signature to add to the commit. Leave `NULL` - * to create a commit without adding a signature field. - * @param signature_field which header field should contain this - * signature. Leave `NULL` for the default of "gpgsig" - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_create_with_signature( - git_oid *out, - git_repository *repo, - const char *commit_content, - const char *signature, - const char *signature_field); - -/** - * Create an in-memory copy of a commit. The copy must be explicitly - * free'd or it will leak. - * - * @param out Pointer to store the copy of the commit - * @param source Original commit to copy - * @return 0 - */ -GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source); - -/** - * Commit creation callback: used when a function is going to create - * commits (for example, in `git_rebase_commit`) to allow callers to - * override the commit creation behavior. For example, users may - * wish to sign commits by providing this information to - * `git_commit_create_buffer`, signing that buffer, then calling - * `git_commit_create_with_signature`. The resultant commit id - * should be set in the `out` object id parameter. - * - * @param out pointer that this callback will populate with the object - * id of the commit that is created - * @param author the author name and time of the commit - * @param committer the committer name and time of the commit - * @param message_encoding the encoding of the given message, or NULL - * to assume UTF8 - * @param message the commit message - * @param tree the tree to be committed - * @param parent_count the number of parents for this commit - * @param parents the commit parents - * @param payload the payload pointer in the rebase options - * @return 0 if this callback has created the commit and populated the out - * parameter, GIT_PASSTHROUGH if the callback has not created a - * commit and wants the calling function to create the commit as - * if no callback had been specified, any other value to stop - * and return a failure - */ -typedef int (*git_commit_create_cb)( - git_oid *out, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - const git_commit *parents[], - void *payload); - -/** An array of commits returned from the library */ -typedef struct git_commitarray { - git_commit *const *commits; - size_t count; -} git_commitarray; - -/** - * Free the commits contained in a commit array. This method should - * be called on `git_commitarray` objects that were provided by the - * library. Not doing so will result in a memory leak. - * - * This does not free the `git_commitarray` itself, since the library - * will never allocate that object directly itself. - * - * @param array The git_commitarray that contains commits to free - */ -GIT_EXTERN(void) git_commitarray_dispose(git_commitarray *array); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/common.h b/vendor/libgit2-sys/libgit2/include/git2/common.h deleted file mode 100644 index 70f51a8..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/common.h +++ /dev/null @@ -1,586 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_common_h__ -#define INCLUDE_git_common_h__ - -#include -#include - -#ifdef __cplusplus - /** Start declarations in C mode for C++ compatibility */ -# define GIT_BEGIN_DECL extern "C" { - /** End declarations in C mode */ -# define GIT_END_DECL } -#else - /** Start declarations in C mode */ -# define GIT_BEGIN_DECL /* empty */ - /** End declarations in C mode */ -# define GIT_END_DECL /* empty */ -#endif - -#if defined(_MSC_VER) && _MSC_VER < 1800 -# include -#elif !defined(__CLANG_INTTYPES_H) -# include -#endif - -#ifdef DOCURIUM -/* - * This is so clang's doc parser acknowledges comments on functions - * with size_t parameters. - */ -typedef size_t size_t; -#endif - -/** Declare a public function exported for application use. */ -#if __GNUC__ >= 4 -# define GIT_EXTERN(type) extern \ - __attribute__((visibility("default"))) \ - type -#elif defined(_MSC_VER) -# define GIT_EXTERN(type) __declspec(dllexport) type __cdecl -#else -# define GIT_EXTERN(type) extern type -#endif - -/** Declare a callback function for application use. */ -#if defined(_MSC_VER) -# define GIT_CALLBACK(name) (__cdecl *name) -#else -# define GIT_CALLBACK(name) (*name) -#endif - -/** Declare a function as deprecated. */ -#if defined(__GNUC__) -# define GIT_DEPRECATED(func) \ - __attribute__((deprecated)) \ - __attribute__((used)) \ - func -#elif defined(_MSC_VER) -# define GIT_DEPRECATED(func) __declspec(deprecated) func -#else -# define GIT_DEPRECATED(func) func -#endif - -/** Declare a function's takes printf style arguments. */ -#ifdef __GNUC__ -# define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b))) -#else -# define GIT_FORMAT_PRINTF(a,b) /* empty */ -#endif - -#ifdef __amigaos4__ -#include -#endif - -/** - * @file git2/common.h - * @brief Base platform functionality - * @defgroup git_common Git common platform definitions - * @ingroup Git - * - * Common platform functionality including introspecting libgit2 - * itself - information like how it was built, and the current - * running version. - * @{ - */ - -GIT_BEGIN_DECL - -/** - * The separator used in path list strings (ie like in the PATH - * environment variable). A semi-colon ";" is used on Windows and - * AmigaOS, and a colon ":" for all other systems. - */ -#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(AMIGA) -# define GIT_PATH_LIST_SEPARATOR ';' -#else -# define GIT_PATH_LIST_SEPARATOR ':' -#endif - -/** - * The maximum length of a valid git path. - */ -#define GIT_PATH_MAX 4096 - -/** - * Return the version of the libgit2 library - * being currently used. - * - * @param major Store the major version number - * @param minor Store the minor version number - * @param rev Store the revision (patch) number - * @return 0 on success or an error code on failure - */ -GIT_EXTERN(int) git_libgit2_version(int *major, int *minor, int *rev); - -/** - * Return the prerelease state of the libgit2 library currently being - * used. For nightly builds during active development, this will be - * "alpha". Releases may have a "beta" or release candidate ("rc1", - * "rc2", etc) prerelease. For a final release, this function returns - * NULL. - * - * @return the name of the prerelease state or NULL - */ -GIT_EXTERN(const char *) git_libgit2_prerelease(void); - -/** - * Configurable features of libgit2; either optional settings (like - * threading), or features that can be enabled by one of a number of - * different backend "providers" (like HTTPS, which can be provided by - * OpenSSL, mbedTLS, or system libraries). - */ -typedef enum { - /** - * libgit2 is thread-aware and can be used from multiple threads - * (as described in the documentation). - */ - GIT_FEATURE_THREADS = (1 << 0), - - /** HTTPS remotes */ - GIT_FEATURE_HTTPS = (1 << 1), - - /** SSH remotes */ - GIT_FEATURE_SSH = (1 << 2), - - /** Sub-second resolution in index timestamps */ - GIT_FEATURE_NSEC = (1 << 3), - - /** HTTP parsing; always available */ - GIT_FEATURE_HTTP_PARSER = (1 << 4), - - /** Regular expression support; always available */ - GIT_FEATURE_REGEX = (1 << 5), - - /** Internationalization support for filename translation */ - GIT_FEATURE_I18N = (1 << 6), - - /** NTLM support over HTTPS */ - GIT_FEATURE_AUTH_NTLM = (1 << 7), - - /** Kerberos (SPNEGO) authentication support over HTTPS */ - GIT_FEATURE_AUTH_NEGOTIATE = (1 << 8), - - /** zlib support; always available */ - GIT_FEATURE_COMPRESSION = (1 << 9), - - /** SHA1 object support; always available */ - GIT_FEATURE_SHA1 = (1 << 10), - - /** SHA256 object support */ - GIT_FEATURE_SHA256 = (1 << 11) -} git_feature_t; - -/** - * Query compile time options for libgit2. - * - * @return A combination of GIT_FEATURE_* values. - */ -GIT_EXTERN(int) git_libgit2_features(void); - -/** - * Query the backend details for the compile-time feature in libgit2. - * - * This will return the "backend" for the feature, which is useful for - * things like HTTPS or SSH support, that can have multiple backends - * that could be compiled in. - * - * For example, when libgit2 is compiled with dynamic OpenSSL support, - * the feature backend will be `openssl-dynamic`. The feature backend - * names reflect the compilation options specified to the build system - * (though in all lower case). The backend _may_ be "builtin" for - * features that are provided by libgit2 itself. - * - * If the feature is not supported by the library, this API returns - * `NULL`. - * - * @param feature the feature to query details for - * @return the provider details, or NULL if the feature is not supported - */ -GIT_EXTERN(const char *) git_libgit2_feature_backend( - git_feature_t feature); - -/** - * Global library options - * - * These are used to select which global option to set or get and are - * used in `git_libgit2_opts()`. - */ -typedef enum { - GIT_OPT_GET_MWINDOW_SIZE, - GIT_OPT_SET_MWINDOW_SIZE, - GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, - GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, - GIT_OPT_GET_SEARCH_PATH, - GIT_OPT_SET_SEARCH_PATH, - GIT_OPT_SET_CACHE_OBJECT_LIMIT, - GIT_OPT_SET_CACHE_MAX_SIZE, - GIT_OPT_ENABLE_CACHING, - GIT_OPT_GET_CACHED_MEMORY, - GIT_OPT_GET_TEMPLATE_PATH, - GIT_OPT_SET_TEMPLATE_PATH, - GIT_OPT_SET_SSL_CERT_LOCATIONS, - GIT_OPT_SET_USER_AGENT, - GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, - GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, - GIT_OPT_SET_SSL_CIPHERS, - GIT_OPT_GET_USER_AGENT, - GIT_OPT_ENABLE_OFS_DELTA, - GIT_OPT_ENABLE_FSYNC_GITDIR, - GIT_OPT_GET_WINDOWS_SHAREMODE, - GIT_OPT_SET_WINDOWS_SHAREMODE, - GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, - GIT_OPT_SET_ALLOCATOR, - GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, - GIT_OPT_GET_PACK_MAX_OBJECTS, - GIT_OPT_SET_PACK_MAX_OBJECTS, - GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, - GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, - GIT_OPT_GET_MWINDOW_FILE_LIMIT, - GIT_OPT_SET_MWINDOW_FILE_LIMIT, - GIT_OPT_SET_ODB_PACKED_PRIORITY, - GIT_OPT_SET_ODB_LOOSE_PRIORITY, - GIT_OPT_GET_EXTENSIONS, - GIT_OPT_SET_EXTENSIONS, - GIT_OPT_GET_OWNER_VALIDATION, - GIT_OPT_SET_OWNER_VALIDATION, - GIT_OPT_GET_HOMEDIR, - GIT_OPT_SET_HOMEDIR, - GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, - GIT_OPT_GET_SERVER_CONNECT_TIMEOUT, - GIT_OPT_SET_SERVER_TIMEOUT, - GIT_OPT_GET_SERVER_TIMEOUT, - GIT_OPT_SET_USER_AGENT_PRODUCT, - GIT_OPT_GET_USER_AGENT_PRODUCT, - GIT_OPT_ADD_SSL_X509_CERT, - GIT_OPT_GET_PACK_MAX_OBJECT_SIZE, - GIT_OPT_SET_PACK_MAX_OBJECT_SIZE -} git_libgit2_opt_t; - -/** - * Set or query a library global option - * - * Available options: - * - * * opts(GIT_OPT_GET_MWINDOW_SIZE, size_t *): - * - * > Get the maximum mmap window size - * - * * opts(GIT_OPT_SET_MWINDOW_SIZE, size_t): - * - * > Set the maximum mmap window size - * - * * opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, size_t *): - * - * > Get the maximum memory that will be mapped in total by the library - * - * * opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, size_t): - * - * > Set the maximum amount of memory that can be mapped at any time - * > by the library - * - * * opts(GIT_OPT_GET_MWINDOW_FILE_LIMIT, size_t *): - * - * > Get the maximum number of files that will be mapped at any time by the - * > library - * - * * opts(GIT_OPT_SET_MWINDOW_FILE_LIMIT, size_t): - * - * > Set the maximum number of files that can be mapped at any time - * > by the library. The default (0) is unlimited. - * - * * opts(GIT_OPT_GET_SEARCH_PATH, int level, git_buf *buf) - * - * > Get the search path for a given level of config data. "level" must - * > be one of `GIT_CONFIG_LEVEL_SYSTEM`, `GIT_CONFIG_LEVEL_GLOBAL`, - * > `GIT_CONFIG_LEVEL_XDG`, or `GIT_CONFIG_LEVEL_PROGRAMDATA`. - * > The search path is written to the `out` buffer. - * - * * opts(GIT_OPT_SET_SEARCH_PATH, int level, const char *path) - * - * > Set the search path for a level of config data. The search path - * > applied to shared attributes and ignore files, too. - * > - * > - `path` lists directories delimited by GIT_PATH_LIST_SEPARATOR. - * > Pass NULL to reset to the default (generally based on environment - * > variables). Use magic path `$PATH` to include the old value - * > of the path (if you want to prepend or append, for instance). - * > - * > - `level` must be `GIT_CONFIG_LEVEL_SYSTEM`, - * > `GIT_CONFIG_LEVEL_GLOBAL`, `GIT_CONFIG_LEVEL_XDG`, or - * > `GIT_CONFIG_LEVEL_PROGRAMDATA`. - * - * * opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, git_object_t type, size_t size) - * - * > Set the maximum data size for the given type of object to be - * > considered eligible for caching in memory. Setting to value to - * > zero means that that type of object will not be cached. - * > Defaults to 0 for GIT_OBJECT_BLOB (i.e. won't cache blobs) and 4k - * > for GIT_OBJECT_COMMIT, GIT_OBJECT_TREE, and GIT_OBJECT_TAG. - * - * * opts(GIT_OPT_SET_CACHE_MAX_SIZE, ssize_t max_storage_bytes) - * - * > Set the maximum total data size that will be cached in memory - * > across all repositories before libgit2 starts evicting objects - * > from the cache. This is a soft limit, in that the library might - * > briefly exceed it, but will start aggressively evicting objects - * > from cache when that happens. The default cache size is 256MB. - * - * * opts(GIT_OPT_ENABLE_CACHING, int enabled) - * - * > Enable or disable caching completely. - * > - * > Because caches are repository-specific, disabling the cache - * > cannot immediately clear all cached objects, but each cache will - * > be cleared on the next attempt to update anything in it. - * - * * opts(GIT_OPT_GET_CACHED_MEMORY, ssize_t *current, ssize_t *allowed) - * - * > Get the current bytes in cache and the maximum that would be - * > allowed in the cache. - * - * * opts(GIT_OPT_GET_TEMPLATE_PATH, git_buf *out) - * - * > Get the default template path. - * > The path is written to the `out` buffer. - * - * * opts(GIT_OPT_SET_TEMPLATE_PATH, const char *path) - * - * > Set the default template path. - * > - * > - `path` directory of template. - * - * * opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, const char *file, const char *path) - * - * > Set the SSL certificate-authority locations. - * > - * > - `file` is the location of a file containing several - * > certificates concatenated together. - * > - `path` is the location of a directory holding several - * > certificates, one per file. - * > - * > Calling `GIT_OPT_ADD_SSL_X509_CERT` may override the - * > data in `path`. - * > - * > Either parameter may be `NULL`, but not both. - * - * * opts(GIT_OPT_ADD_SSL_X509_CERT, const X509 *cert) - * - * > Add a raw X509 certificate into the SSL certs store. - * > This certificate is only used by libgit2 invocations - * > during the application lifetime and is not persisted - * > to disk. This certificate cannot be removed from the - * > application once is has been added. - * > - * > - `cert` is the raw X509 cert will be added to cert store. - * - * * opts(GIT_OPT_SET_USER_AGENT, const char *user_agent) - * - * > Set the value of the comment section of the User-Agent header. - * > This can be information about your product and its version. - * > By default this is "libgit2" followed by the libgit2 version. - * > - * > This value will be appended to User-Agent _product_, which - * > is typically set to "git/2.0". - * > - * > Set to the empty string ("") to not send any information in the - * > comment section, or set to NULL to restore the default. - * - * * opts(GIT_OPT_GET_USER_AGENT, git_buf *out) - * - * > Get the value of the User-Agent header. - * > The User-Agent is written to the `out` buffer. - * - * * opts(GIT_OPT_SET_USER_AGENT_PRODUCT, const char *user_agent_product) - * - * > Set the value of the product portion of the User-Agent header. - * > This defaults to "git/2.0", for compatibility with other git - * > clients. It is recommended to keep this as git/ for - * > compatibility with servers that do user-agent detection. - * > - * > Set to the empty string ("") to not send any user-agent string, - * > or set to NULL to restore the default. - * - * * opts(GIT_OPT_GET_USER_AGENT_PRODUCT, git_buf *out) - * - * > Get the value of the User-Agent product header. - * > The User-Agent product is written to the `out` buffer. - * - * * opts(GIT_OPT_SET_WINDOWS_SHAREMODE, unsigned long value) - * - * > Set the share mode used when opening files on Windows. - * > For more information, see the documentation for CreateFile. - * > The default is: FILE_SHARE_READ | FILE_SHARE_WRITE. This is - * > ignored and unused on non-Windows platforms. - * - * * opts(GIT_OPT_GET_WINDOWS_SHAREMODE, unsigned long *value) - * - * > Get the share mode used when opening files on Windows. - * - * * opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled) - * - * > Enable strict input validation when creating new objects - * > to ensure that all inputs to the new objects are valid. For - * > example, when this is enabled, the parent(s) and tree inputs - * > will be validated when creating a new commit. This defaults - * > to enabled. - * - * * opts(GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, int enabled) - * - * > Validate the target of a symbolic ref when creating it. For - * > example, `foobar` is not a valid ref, therefore `foobar` is - * > not a valid target for a symbolic ref by default, whereas - * > `refs/heads/foobar` is. Disabling this bypasses validation - * > so that an arbitrary strings such as `foobar` can be used - * > for a symbolic ref target. This defaults to enabled. - * - * * opts(GIT_OPT_SET_SSL_CIPHERS, const char *ciphers) - * - * > Set the SSL ciphers use for HTTPS connections. - * > - * > - `ciphers` is the list of ciphers that are eanbled. - * - * * opts(GIT_OPT_ENABLE_OFS_DELTA, int enabled) - * - * > Enable or disable the use of "offset deltas" when creating packfiles, - * > and the negotiation of them when talking to a remote server. - * > Offset deltas store a delta base location as an offset into the - * > packfile from the current location, which provides a shorter encoding - * > and thus smaller resultant packfiles. - * > Packfiles containing offset deltas can still be read. - * > This defaults to enabled. - * - * * opts(GIT_OPT_ENABLE_FSYNC_GITDIR, int enabled) - * - * > Enable synchronized writes of files in the gitdir using `fsync` - * > (or the platform equivalent) to ensure that new object data - * > is written to permanent storage, not simply cached. This - * > defaults to disabled. - * - * opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, int enabled) - * - * > Enable strict verification of object hashsums when reading - * > objects from disk. This may impact performance due to an - * > additional checksum calculation on each object. This defaults - * > to enabled. - * - * opts(GIT_OPT_SET_ALLOCATOR, git_allocator *allocator) - * - * > Set the memory allocator to a different memory allocator. This - * > allocator will then be used to make all memory allocations for - * > libgit2 operations. If the given `allocator` is NULL, then the - * > system default will be restored. - * - * opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, int enabled) - * - * > Ensure that there are no unsaved changes in the index before - * > beginning any operation that reloads the index from disk (eg, - * > checkout). If there are unsaved changes, the instruction will - * > fail. (Using the FORCE flag to checkout will still overwrite - * > these changes.) - * - * opts(GIT_OPT_GET_PACK_MAX_OBJECTS, size_t *out) - * - * > Get the maximum number of objects libgit2 will allow in a pack - * > file when downloading a pack file from a remote. This can be - * > used to limit maximum memory usage when fetching from an untrusted - * > remote. - * - * opts(GIT_OPT_SET_PACK_MAX_OBJECTS, size_t objects) - * - * > Set the maximum number of objects libgit2 will allow in a pack - * > file when downloading a pack file from a remote. - * - * opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, int enabled) - * > This will cause .keep file existence checks to be skipped when - * > accessing packfiles, which can help performance with remote filesystems. - * - * opts(GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, int enabled) - * > When connecting to a server using NTLM or Negotiate - * > authentication, use expect/continue when POSTing data. - * > This option is not available on Windows. - * - * opts(GIT_OPT_SET_ODB_PACKED_PRIORITY, int priority) - * > Override the default priority of the packed ODB backend which - * > is added when default backends are assigned to a repository - * - * opts(GIT_OPT_SET_ODB_LOOSE_PRIORITY, int priority) - * > Override the default priority of the loose ODB backend which - * > is added when default backends are assigned to a repository - * - * opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out) - * > Returns the list of git extensions that are supported. This - * > is the list of built-in extensions supported by libgit2 and - * > custom extensions that have been added with - * > `GIT_OPT_SET_EXTENSIONS`. Extensions that have been negated - * > will not be returned. The returned list should be released - * > with `git_strarray_dispose`. - * - * opts(GIT_OPT_SET_EXTENSIONS, const char **extensions, size_t len) - * > Set that the given git extensions are supported by the caller. - * > Extensions supported by libgit2 may be negated by prefixing - * > them with a `!`. For example: setting extensions to - * > { "!noop", "newext" } indicates that the caller does not want - * > to support repositories with the `noop` extension but does want - * > to support repositories with the `newext` extension. - * - * opts(GIT_OPT_GET_OWNER_VALIDATION, int *enabled) - * > Gets the owner validation setting for repository - * > directories. - * - * opts(GIT_OPT_SET_OWNER_VALIDATION, int enabled) - * > Set that repository directories should be owned by the current - * > user. The default is to validate ownership. - * - * opts(GIT_OPT_GET_HOMEDIR, git_buf *out) - * > Gets the current user's home directory, as it will be used - * > for file lookups. The path is written to the `out` buffer. - * - * opts(GIT_OPT_SET_HOMEDIR, const char *path) - * > Sets the directory used as the current user's home directory, - * > for file lookups. - * > - * > - `path` directory of home directory. - * - * opts(GIT_OPT_GET_SERVER_CONNECT_TIMEOUT, int *timeout) - * > Gets the timeout (in milliseconds) to attempt connections to - * > a remote server. - * - * opts(GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, int timeout) - * > Sets the timeout (in milliseconds) to attempt connections to - * > a remote server. Set to 0 to use the system default. Note that - * > this may not be able to be configured longer than the system - * > default, typically 75 seconds. - * - * opts(GIT_OPT_GET_SERVER_TIMEOUT, int *timeout) - * > Gets the timeout (in milliseconds) for reading from and writing - * > to a remote server. - * - * opts(GIT_OPT_SET_SERVER_TIMEOUT, int timeout) - * > Sets the timeout (in milliseconds) for reading from and writing - * > to a remote server. Set to 0 to use the system default. - * - * opts(GIT_OPT_GET_PACK_MAX_OBJECT_SIZE, size_t *out) - * > Gets the maximum size of a declared packfile object. This can - * > be used to limit maximum memory usage when fetching from a - * > remote. - * - * opts(GIT_OPT_SET_PACK_MAX_OBJECT_SIZE, size_t object_size) - * > Set the maximum size of an object that libgit2 will allow in - * > a pack file when downloading a pack file from a remote. - * > The default is 2 GiB. - * - * @param option Option key - * @return 0 on success, <0 on failure - */ -GIT_EXTERN(int) git_libgit2_opts(int option, ...); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/config.h b/vendor/libgit2-sys/libgit2/include/git2/config.h deleted file mode 100644 index f9c2667..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/config.h +++ /dev/null @@ -1,852 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_config_h__ -#define INCLUDE_git_config_h__ - -#include "common.h" -#include "types.h" -#include "buffer.h" - -/** - * @file git2/config.h - * @brief Per-repository, per-user or per-system configuration - * @defgroup git_config Git config management routines - * @ingroup Git - * - * Git configuration affects the operation of the version control - * system, and can be specified on a per-repository basis, in user - * settings, or at the system level. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Priority level of a config file. - * - * These priority levels correspond to the natural escalation logic - * (from higher to lower) when reading or searching for config entries - * in git.git. Meaning that for the same key, the configuration in - * the local configuration is preferred over the configuration in - * the system configuration file. - * - * Callers can add their own custom configuration, beginning at the - * `GIT_CONFIG_LEVEL_APP` level. - * - * Writes, by default, occur in the highest priority level backend - * that is writable. This ordering can be overridden with - * `git_config_set_writeorder`. - * - * git_config_open_default() and git_repository_config() honor those - * priority levels as well. - * - * @see git_config_open_default - * @see git_repository_config - */ -typedef enum { - /** - * System-wide on Windows, for compatibility with "Portable Git". - */ - GIT_CONFIG_LEVEL_PROGRAMDATA = 1, - - /** - * System-wide configuration file; `/etc/gitconfig` on Linux. - */ - GIT_CONFIG_LEVEL_SYSTEM = 2, - - /** - * XDG compatible configuration file; typically - * `~/.config/git/config`. - */ - GIT_CONFIG_LEVEL_XDG = 3, - - /** - * Global configuration file is the user-specific configuration; - * typically `~/.gitconfig`. - */ - GIT_CONFIG_LEVEL_GLOBAL = 4, - - /** - * Local configuration, the repository-specific configuration file; - * typically `$GIT_DIR/config`. - */ - GIT_CONFIG_LEVEL_LOCAL = 5, - - /** - * Worktree-specific configuration; typically - * `$GIT_DIR/config.worktree`. - */ - GIT_CONFIG_LEVEL_WORKTREE = 6, - - /** - * Application-specific configuration file. Callers into libgit2 - * can add their own configuration beginning at this level. - */ - GIT_CONFIG_LEVEL_APP = 7, - - /** - * Not a configuration level; callers can use this value when - * querying configuration levels to specify that they want to - * have data from the highest-level currently configuration. - * This can be used to indicate that callers want the most - * specific config file available that actually is loaded. - */ - GIT_CONFIG_HIGHEST_LEVEL = -1 -} git_config_level_t; - -/** - * An entry in a configuration file - */ -typedef struct git_config_entry { - /** Name of the configuration entry (normalized). */ - const char *name; - - /** Literal (string) value of the entry. */ - const char *value; - - /** The type of backend that this entry exists in (eg, "file"). */ - const char *backend_type; - - /** - * The path to the origin of this entry. For config files, this is - * the path to the file. - */ - const char *origin_path; - - /** Depth of includes where this variable was found. */ - unsigned int include_depth; - - /** Configuration level for the file this was found in. */ - git_config_level_t level; -} git_config_entry; - -/** - * Free a config entry. - * - * @param entry The entry to free. - */ -GIT_EXTERN(void) git_config_entry_free(git_config_entry *entry); - -/** - * A config enumeration callback. - * - * @param entry the entry currently being enumerated - * @param payload a user-specified pointer - * @return non-zero to terminate the iteration. - */ -typedef int GIT_CALLBACK(git_config_foreach_cb)(const git_config_entry *entry, void *payload); - -/** - * An opaque structure for a configuration iterator. - */ -typedef struct git_config_iterator git_config_iterator; - -/** - * Config var type - */ -typedef enum { - GIT_CONFIGMAP_FALSE = 0, - GIT_CONFIGMAP_TRUE = 1, - GIT_CONFIGMAP_INT32, - GIT_CONFIGMAP_STRING -} git_configmap_t; - -/** - * Mapping from config variables to values. - */ -typedef struct { - git_configmap_t type; - const char *str_match; - int map_value; -} git_configmap; - -/** - * Locate the path to the global configuration file - * - * The user or global configuration file is usually - * located in `$HOME/.gitconfig`. - * - * This method will try to guess the full path to that - * file, if the file exists. The returned path - * may be used on any `git_config` call to load the - * global configuration file. - * - * This method will not guess the path to the xdg compatible - * config file (`.config/git/config`). - * - * @param out Pointer to a user-allocated git_buf in which to store the path - * @return 0 if a global configuration file has been found. Its path will be stored in `out`. - */ -GIT_EXTERN(int) git_config_find_global(git_buf *out); - -/** - * Locate the path to the global xdg compatible configuration file - * - * The xdg compatible configuration file is usually - * located in `$HOME/.config/git/config`. - * - * This method will try to guess the full path to that - * file, if the file exists. The returned path - * may be used on any `git_config` call to load the - * xdg compatible configuration file. - * - * @param out Pointer to a user-allocated git_buf in which to store the path - * @return 0 if a xdg compatible configuration file has been - * found. Its path will be stored in `out`. - */ -GIT_EXTERN(int) git_config_find_xdg(git_buf *out); - -/** - * Locate the path to the system configuration file - * - * If `/etc/gitconfig` doesn't exist, it will look for - * `%PROGRAMFILES%\Git\etc\gitconfig`. - * - * @param out Pointer to a user-allocated git_buf in which to store the path - * @return 0 if a system configuration file has been - * found. Its path will be stored in `out`. - */ -GIT_EXTERN(int) git_config_find_system(git_buf *out); - -/** - * Locate the path to the configuration file in ProgramData - * - * Look for the file in `%PROGRAMDATA%\Git\config` used by portable git. - * - * @param out Pointer to a user-allocated git_buf in which to store the path - * @return 0 if a ProgramData configuration file has been - * found. Its path will be stored in `out`. - */ -GIT_EXTERN(int) git_config_find_programdata(git_buf *out); - -/** - * Open the global, XDG and system configuration files - * - * Utility wrapper that finds the global, XDG and system configuration files - * and opens them into a single prioritized config object that can be - * used when accessing default config data outside a repository. - * - * @param out Pointer to store the config instance - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_open_default(git_config **out); - -/** - * Allocate a new configuration object - * - * This object is empty, so you have to add a file to it before you - * can do anything with it. - * - * @param out pointer to the new configuration - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_new(git_config **out); - -/** - * Add an on-disk config file instance to an existing config - * - * The on-disk file pointed at by `path` will be opened and - * parsed; it's expected to be a native Git config file following - * the default Git config syntax (see man git-config). - * - * If the file does not exist, the file will still be added and it - * will be created the first time we write to it. - * - * Note that the configuration object will free the file - * automatically. - * - * Further queries on this config object will access each - * of the config file instances in order (instances with - * a higher priority level will be accessed first). - * - * @param cfg the configuration to add the file to - * @param path path to the configuration file to add - * @param level the priority level of the backend - * @param repo optional repository to allow parsing of - * conditional includes - * @param force replace config file at the given priority level - * @return 0 on success, GIT_EEXISTS when adding more than one file - * for a given priority level (and force_replace set to 0), - * GIT_ENOTFOUND when the file doesn't exist or error code - */ -GIT_EXTERN(int) git_config_add_file_ondisk( - git_config *cfg, - const char *path, - git_config_level_t level, - const git_repository *repo, - int force); - -/** - * Create a new config instance containing a single on-disk file - * - * This method is a simple utility wrapper for the following sequence - * of calls: - * - git_config_new - * - git_config_add_file_ondisk - * - * @param out The configuration instance to create - * @param path Path to the on-disk file to open - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_config_open_ondisk(git_config **out, const char *path); - -/** - * Build a single-level focused config object from a multi-level one. - * - * The returned config object can be used to perform get/set/delete operations - * on a single specific level. - * - * Getting several times the same level from the same parent multi-level config - * will return different config instances, but containing the same config_file - * instance. - * - * @param out The configuration instance to create - * @param parent Multi-level config to search for the given level - * @param level Configuration level to search for - * @return 0, GIT_ENOTFOUND if the passed level cannot be found in the - * multi-level parent config, or an error code - */ -GIT_EXTERN(int) git_config_open_level( - git_config **out, - const git_config *parent, - git_config_level_t level); - -/** - * Open the global/XDG configuration file according to git's rules - * - * Git allows you to store your global configuration at - * `$HOME/.gitconfig` or `$XDG_CONFIG_HOME/git/config`. For backwards - * compatibility, the XDG file shouldn't be used unless the use has - * created it explicitly. With this function you'll open the correct - * one to write to. - * - * @param out pointer in which to store the config object - * @param config the config object in which to look - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_open_global(git_config **out, git_config *config); - -/** - * Set the write order for configuration backends. By default, the - * write ordering does not match the read ordering; for example, the - * worktree configuration is a high-priority for reading, but is not - * written to unless explicitly chosen. - * - * @param cfg the configuration to change write order of - * @param levels the ordering of levels for writing - * @param len the length of the levels array - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_set_writeorder( - git_config *cfg, - git_config_level_t *levels, - size_t len); - -/** - * Create a snapshot of the configuration - * - * Create a snapshot of the current state of a configuration, which - * allows you to look into a consistent view of the configuration for - * looking up complex values (e.g. a remote, submodule). - * - * The string returned when querying such a config object is valid - * until it is freed. - * - * @param out pointer in which to store the snapshot config object - * @param config configuration to snapshot - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_snapshot(git_config **out, git_config *config); - -/** - * Free the configuration and its associated memory and files - * - * @param cfg the configuration to free - */ -GIT_EXTERN(void) git_config_free(git_config *cfg); - -/** - * Get the git_config_entry of a config variable. - * - * Free the git_config_entry after use with `git_config_entry_free()`. - * - * @param out pointer to the variable git_config_entry - * @param cfg where to look for the variable - * @param name the variable's name - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_get_entry( - git_config_entry **out, - const git_config *cfg, - const char *name); - -/** - * Get the value of an integer config variable. - * - * All config files will be looked into, in the order of their - * defined level. A higher level means a higher priority. The - * first occurrence of the variable will be returned here. - * - * @param out pointer to the variable where the value should be stored - * @param cfg where to look for the variable - * @param name the variable's name - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_get_int32(int32_t *out, const git_config *cfg, const char *name); - -/** - * Get the value of a long integer config variable. - * - * All config files will be looked into, in the order of their - * defined level. A higher level means a higher priority. The - * first occurrence of the variable will be returned here. - * - * @param out pointer to the variable where the value should be stored - * @param cfg where to look for the variable - * @param name the variable's name - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_get_int64(int64_t *out, const git_config *cfg, const char *name); - -/** - * Get the value of a boolean config variable. - * - * This function uses the usual C convention of 0 being false and - * anything else true. - * - * All config files will be looked into, in the order of their - * defined level. A higher level means a higher priority. The - * first occurrence of the variable will be returned here. - * - * @param out pointer to the variable where the value should be stored - * @param cfg where to look for the variable - * @param name the variable's name - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_get_bool(int *out, const git_config *cfg, const char *name); - -/** - * Get the value of a path config variable. - * - * A leading '~' will be expanded to the global search path (which - * defaults to the user's home directory but can be overridden via - * `git_libgit2_opts()`. - * - * All config files will be looked into, in the order of their - * defined level. A higher level means a higher priority. The - * first occurrence of the variable will be returned here. - * - * @param out the buffer in which to store the result - * @param cfg where to look for the variable - * @param name the variable's name - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_get_path(git_buf *out, const git_config *cfg, const char *name); - -/** - * Get the value of a string config variable. - * - * This function can only be used on snapshot config objects. The - * string is owned by the config and should not be freed by the - * user. The pointer will be valid until the config is freed. - * - * All config files will be looked into, in the order of their - * defined level. A higher level means a higher priority. The - * first occurrence of the variable will be returned here. - * - * @param out pointer to the string - * @param cfg where to look for the variable - * @param name the variable's name - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, const char *name); - -/** - * Get the value of a string config variable. - * - * The value of the config will be copied into the buffer. - * - * All config files will be looked into, in the order of their - * defined level. A higher level means a higher priority. The - * first occurrence of the variable will be returned here. - * - * @param out buffer in which to store the string - * @param cfg where to look for the variable - * @param name the variable's name - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_get_string_buf(git_buf *out, const git_config *cfg, const char *name); - -/** - * Get each value of a multivar in a foreach callback - * - * The callback will be called on each variable found - * - * The regular expression is applied case-sensitively on the normalized form of - * the variable name: the section and variable parts are lower-cased. The - * subsection is left unchanged. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param regexp regular expression to filter which variables we're - * interested in. Use NULL to indicate all - * @param callback the function to be called on each value of the variable - * @param payload opaque pointer to pass to the callback - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_get_multivar_foreach(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload); - -/** - * Get each value of a multivar - * - * The regular expression is applied case-sensitively on the normalized form of - * the variable name: the section and variable parts are lower-cased. The - * subsection is left unchanged. - * - * @param out pointer to store the iterator - * @param cfg where to look for the variable - * @param name the variable's name - * @param regexp regular expression to filter which variables we're - * interested in. Use NULL to indicate all - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_multivar_iterator_new(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp); - -/** - * Return the current entry and advance the iterator - * - * The pointers returned by this function are valid until the next call - * to `git_config_next` or until the iterator is freed. - * - * @param entry pointer to store the entry - * @param iter the iterator - * @return 0 or an error code. GIT_ITEROVER if the iteration has completed - */ -GIT_EXTERN(int) git_config_next(git_config_entry **entry, git_config_iterator *iter); - -/** - * Free a config iterator - * - * @param iter the iterator to free - */ -GIT_EXTERN(void) git_config_iterator_free(git_config_iterator *iter); - -/** - * Set the value of an integer config variable in the config file - * with the highest level (usually the local one). - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param value Integer value for the variable - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_set_int32(git_config *cfg, const char *name, int32_t value); - -/** - * Set the value of a long integer config variable in the config file - * with the highest level (usually the local one). - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param value Long integer value for the variable - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_set_int64(git_config *cfg, const char *name, int64_t value); - -/** - * Set the value of a boolean config variable in the config file - * with the highest level (usually the local one). - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param value the value to store - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value); - -/** - * Set the value of a string config variable in the config file - * with the highest level (usually the local one). - * - * A copy of the string is made and the user is free to use it - * afterwards. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param value the string to store. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value); - -/** - * Set a multivar in the local config file. - * - * The regular expression is applied case-sensitively on the value. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param regexp a regular expression to indicate which values to replace - * @param value the new value. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value); - -/** - * Delete a config variable from the config file - * with the highest level (usually the local one). - * - * @param cfg the configuration - * @param name the variable to delete - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_delete_entry(git_config *cfg, const char *name); - -/** - * Deletes one or several entries from a multivar in the local config file. - * - * The regular expression is applied case-sensitively on the value. - * - * @param cfg where to look for the variables - * @param name the variable's name - * @param regexp a regular expression to indicate which values to delete - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_delete_multivar(git_config *cfg, const char *name, const char *regexp); - -/** - * Perform an operation on each config variable. - * - * The callback receives the normalized name and value of each variable - * in the config backend, and the data pointer passed to this function. - * If the callback returns a non-zero value, the function stops iterating - * and returns that value to the caller. - * - * The pointers passed to the callback are only valid as long as the - * iteration is ongoing. - * - * @param cfg where to get the variables from - * @param callback the function to call on each variable - * @param payload the data to pass to the callback - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_config_foreach( - const git_config *cfg, - git_config_foreach_cb callback, - void *payload); - -/** - * Iterate over all the config variables - * - * Use `git_config_next` to advance the iteration and - * `git_config_iterator_free` when done. - * - * @param out pointer to store the iterator - * @param cfg where to get the variables from - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_iterator_new(git_config_iterator **out, const git_config *cfg); - -/** - * Iterate over all the config variables whose name matches a pattern - * - * Use `git_config_next` to advance the iteration and - * `git_config_iterator_free` when done. - * - * The regular expression is applied case-sensitively on the normalized form of - * the variable name: the section and variable parts are lower-cased. The - * subsection is left unchanged. - * - * @param out pointer to store the iterator - * @param cfg where to ge the variables from - * @param regexp regular expression to match the names - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_iterator_glob_new(git_config_iterator **out, const git_config *cfg, const char *regexp); - -/** - * Perform an operation on each config variable matching a regular expression. - * - * This behaves like `git_config_foreach` with an additional filter of a - * regular expression that filters which config keys are passed to the - * callback. - * - * The regular expression is applied case-sensitively on the normalized form of - * the variable name: the section and variable parts are lower-cased. The - * subsection is left unchanged. - * - * The regular expression is applied case-sensitively on the normalized form of - * the variable name: the case-insensitive parts are lower-case. - * - * @param cfg where to get the variables from - * @param regexp regular expression to match against config names - * @param callback the function to call on each variable - * @param payload the data to pass to the callback - * @return 0 or the return value of the callback which didn't return 0 - */ -GIT_EXTERN(int) git_config_foreach_match( - const git_config *cfg, - const char *regexp, - git_config_foreach_cb callback, - void *payload); - -/** - * Query the value of a config variable and return it mapped to - * an integer constant. - * - * This is a helper method to easily map different possible values - * to a variable to integer constants that easily identify them. - * - * A mapping array looks as follows: - * - * git_configmap autocrlf_mapping[] = { - * {GIT_CVAR_FALSE, NULL, GIT_AUTO_CRLF_FALSE}, - * {GIT_CVAR_TRUE, NULL, GIT_AUTO_CRLF_TRUE}, - * {GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT}, - * {GIT_CVAR_STRING, "default", GIT_AUTO_CRLF_DEFAULT}}; - * - * On any "false" value for the variable (e.g. "false", "FALSE", "no"), the - * mapping will store `GIT_AUTO_CRLF_FALSE` in the `out` parameter. - * - * The same thing applies for any "true" value such as "true", "yes" or "1", storing - * the `GIT_AUTO_CRLF_TRUE` variable. - * - * Otherwise, if the value matches the string "input" (with case insensitive comparison), - * the given constant will be stored in `out`, and likewise for "default". - * - * If not a single match can be made to store in `out`, an error code will be - * returned. - * - * @param out place to store the result of the mapping - * @param cfg config file to get the variables from - * @param name name of the config variable to lookup - * @param maps array of `git_configmap` objects specifying the possible mappings - * @param map_n number of mapping objects in `maps` - * @return 0 on success, error code otherwise - */ -GIT_EXTERN(int) git_config_get_mapped( - int *out, - const git_config *cfg, - const char *name, - const git_configmap *maps, - size_t map_n); - -/** - * Maps a string value to an integer constant - * - * @param out place to store the result of the parsing - * @param maps array of `git_configmap` objects specifying the possible mappings - * @param map_n number of mapping objects in `maps` - * @param value value to parse - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_lookup_map_value( - int *out, - const git_configmap *maps, - size_t map_n, - const char *value); - -/** - * Parse a string value as a bool. - * - * Valid values for true are: 'true', 'yes', 'on', 1 or any - * number different from 0 - * Valid values for false are: 'false', 'no', 'off', 0 - * - * @param out place to store the result of the parsing - * @param value value to parse - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_parse_bool(int *out, const char *value); - -/** - * Parse a string value as an int32. - * - * An optional value suffix of 'k', 'm', or 'g' will - * cause the value to be multiplied by 1024, 1048576, - * or 1073741824 prior to output. - * - * @param out place to store the result of the parsing - * @param value value to parse - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_parse_int32(int32_t *out, const char *value); - -/** - * Parse a string value as an int64. - * - * An optional value suffix of 'k', 'm', or 'g' will - * cause the value to be multiplied by 1024, 1048576, - * or 1073741824 prior to output. - * - * @param out place to store the result of the parsing - * @param value value to parse - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value); - -/** - * Parse a string value as a path. - * - * A leading '~' will be expanded to the global search path (which - * defaults to the user's home directory but can be overridden via - * `git_libgit2_opts()`. - * - * If the value does not begin with a tilde, the input will be - * returned. - * - * @param out placae to store the result of parsing - * @param value the path to evaluate - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_parse_path(git_buf *out, const char *value); - -/** - * Perform an operation on each config variable in a given config backend, - * matching a regular expression. - * - * This behaves like `git_config_foreach_match` except that only config - * entries from the given backend entry are enumerated. - * - * The regular expression is applied case-sensitively on the normalized form of - * the variable name: the section and variable parts are lower-cased. The - * subsection is left unchanged. - * - * @param backend where to get the variables from - * @param regexp regular expression to match against config names (can be NULL) - * @param callback the function to call on each variable - * @param payload the data to pass to the callback - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_config_backend_foreach_match( - git_config_backend *backend, - const char *regexp, - git_config_foreach_cb callback, - void *payload); - - -/** - * Lock the backend with the highest priority - * - * Locking disallows anybody else from writing to that backend. Any - * updates made after locking will not be visible to a reader until - * the file is unlocked. - * - * You can apply the changes by calling `git_transaction_commit()` - * before freeing the transaction. Either of these actions will unlock - * the config. - * - * @param tx the resulting transaction, use this to commit or undo the - * changes - * @param cfg the configuration in which to lock - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_lock(git_transaction **tx, git_config *cfg); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/cred_helpers.h b/vendor/libgit2-sys/libgit2/include/git2/cred_helpers.h deleted file mode 100644 index 3721b6d..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/cred_helpers.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_cred_helpers_h__ -#define INCLUDE_git_cred_helpers_h__ - -/* These declarations have moved. */ -#ifndef GIT_DEPRECATE_HARD -# include "git2/credential_helpers.h" -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/credential.h b/vendor/libgit2-sys/libgit2/include/git2/credential.h deleted file mode 100644 index 33755ca..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/credential.h +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_credential_h__ -#define INCLUDE_git_credential_h__ - -#include "common.h" - -/** - * @file git2/credential.h - * @brief Authentication and credential management - * @defgroup git_credential Authentication & credential management - * @ingroup Git - * - * Credentials specify how to authenticate to a remote system - * over HTTPS or SSH. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Supported credential types - * - * This represents the various types of authentication methods supported by - * the library. - */ -typedef enum { - /** - * A vanilla user/password request - * @see git_credential_userpass_plaintext_new - */ - GIT_CREDENTIAL_USERPASS_PLAINTEXT = (1u << 0), - - /** - * An SSH key-based authentication request - * @see git_credential_ssh_key_new - */ - GIT_CREDENTIAL_SSH_KEY = (1u << 1), - - /** - * An SSH key-based authentication request, with a custom signature - * @see git_credential_ssh_custom_new - */ - GIT_CREDENTIAL_SSH_CUSTOM = (1u << 2), - - /** - * An NTLM/Negotiate-based authentication request. - * @see git_credential_default - */ - GIT_CREDENTIAL_DEFAULT = (1u << 3), - - /** - * An SSH interactive authentication request - * @see git_credential_ssh_interactive_new - */ - GIT_CREDENTIAL_SSH_INTERACTIVE = (1u << 4), - - /** - * Username-only authentication request - * - * Used as a pre-authentication step if the underlying transport - * (eg. SSH, with no username in its URL) does not know which username - * to use. - * - * @see git_credential_username_new - */ - GIT_CREDENTIAL_USERNAME = (1u << 5), - - /** - * An SSH key-based authentication request - * - * Allows credentials to be read from memory instead of files. - * Note that because of differences in crypto backend support, it might - * not be functional. - * - * @see git_credential_ssh_key_memory_new - */ - GIT_CREDENTIAL_SSH_MEMORY = (1u << 6) -} git_credential_t; - -/** - * The base structure for all credential types - */ -typedef struct git_credential git_credential; - -typedef struct git_credential_userpass_plaintext git_credential_userpass_plaintext; - -/** Username-only credential information */ -typedef struct git_credential_username git_credential_username; - -/** A key for NTLM/Kerberos "default" credentials */ -typedef struct git_credential git_credential_default; - -/** - * A ssh key from disk - */ -typedef struct git_credential_ssh_key git_credential_ssh_key; - -/** - * Keyboard-interactive based ssh authentication - */ -typedef struct git_credential_ssh_interactive git_credential_ssh_interactive; - -/** - * A key with a custom signature function - */ -typedef struct git_credential_ssh_custom git_credential_ssh_custom; - -/** - * Credential acquisition callback. - * - * This callback is usually involved any time another system might need - * authentication. As such, you are expected to provide a valid - * git_credential object back, depending on allowed_types (a - * git_credential_t bitmask). - * - * Note that most authentication details are your responsibility - this - * callback will be called until the authentication succeeds, or you report - * an error. As such, it's easy to get in a loop if you fail to stop providing - * the same incorrect credentials. - * - * @param[out] out The newly created credential object. - * @param url The resource for which we are demanding a credential. - * @param username_from_url The username that was embedded in a "user\@host" - * remote url, or NULL if not included. - * @param allowed_types A bitmask stating which credential types are OK to return. - * @param payload The payload provided when specifying this callback. - * @return 0 for success, < 0 to indicate an error, > 0 to indicate - * no credential was acquired - */ -typedef int GIT_CALLBACK(git_credential_acquire_cb)( - git_credential **out, - const char *url, - const char *username_from_url, - unsigned int allowed_types, - void *payload); - -/** - * Free a credential. - * - * This is only necessary if you own the object; that is, if you are a - * transport. - * - * @param cred the object to free - */ -GIT_EXTERN(void) git_credential_free(git_credential *cred); - -/** - * Check whether a credential object contains username information. - * - * @param cred object to check - * @return 1 if the credential object has non-NULL username, 0 otherwise - */ -GIT_EXTERN(int) git_credential_has_username(git_credential *cred); - -/** - * Return the username associated with a credential object. - * - * @param cred object to check - * @return the credential username, or NULL if not applicable - */ -GIT_EXTERN(const char *) git_credential_get_username(git_credential *cred); - -/** - * Create a new plain-text username and password credential object. - * The supplied credential parameter will be internally duplicated. - * - * @param out The newly created credential object. - * @param username The username of the credential. - * @param password The password of the credential. - * @return 0 for success or an error code for failure - */ -GIT_EXTERN(int) git_credential_userpass_plaintext_new( - git_credential **out, - const char *username, - const char *password); - -/** - * Create a "default" credential usable for Negotiate mechanisms like NTLM - * or Kerberos authentication. - * - * @param out The newly created credential object. - * @return 0 for success or an error code for failure - */ -GIT_EXTERN(int) git_credential_default_new(git_credential **out); - -/** - * Create a credential to specify a username. - * - * This is used with ssh authentication to query for the username if - * none is specified in the url. - * - * @param out The newly created credential object. - * @param username The username to authenticate with - * @return 0 for success or an error code for failure - */ -GIT_EXTERN(int) git_credential_username_new(git_credential **out, const char *username); - -/** - * Create a new passphrase-protected ssh key credential object. - * The supplied credential parameter will be internally duplicated. - * - * @param out The newly created credential object. - * @param username username to use to authenticate - * @param publickey The path to the public key of the credential. - * @param privatekey The path to the private key of the credential. - * @param passphrase The passphrase of the credential. - * @return 0 for success or an error code for failure - */ -GIT_EXTERN(int) git_credential_ssh_key_new( - git_credential **out, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase); - -/** - * Create a new ssh key credential object reading the keys from memory. - * - * @param out The newly created credential object. - * @param username username to use to authenticate. - * @param publickey The public key of the credential. - * @param privatekey The private key of the credential. - * @param passphrase The passphrase of the credential. - * @return 0 for success or an error code for failure - */ -GIT_EXTERN(int) git_credential_ssh_key_memory_new( - git_credential **out, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase); - -/* - * If the user hasn't included libssh2.h before git2.h, we need to - * define a few types for the callback signatures. - */ -#ifndef LIBSSH2_VERSION -typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION; -typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT LIBSSH2_USERAUTH_KBDINT_PROMPT; -typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE LIBSSH2_USERAUTH_KBDINT_RESPONSE; -#endif - -/** - * Callback for interactive SSH credentials. - * - * @param name the name - * @param name_len the length of the name - * @param instruction the authentication instruction - * @param instruction_len the length of the instruction - * @param num_prompts the number of prompts - * @param prompts the prompts - * @param responses the responses - * @param abstract the abstract - */ -typedef void GIT_CALLBACK(git_credential_ssh_interactive_cb)( - const char *name, - int name_len, - const char *instruction, int instruction_len, - int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, - LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, - void **abstract); - - -/** - * Create a new ssh keyboard-interactive based credential object. - * The supplied credential parameter will be internally duplicated. - * - * @param out The newly created credential object. - * @param username Username to use to authenticate. - * @param prompt_callback The callback method used for prompts. - * @param payload Additional data to pass to the callback. - * @return 0 for success or an error code for failure. - */ -GIT_EXTERN(int) git_credential_ssh_interactive_new( - git_credential **out, - const char *username, - git_credential_ssh_interactive_cb prompt_callback, - void *payload); - -/** - * Create a new ssh key credential object used for querying an ssh-agent. - * The supplied credential parameter will be internally duplicated. - * - * @param out The newly created credential object. - * @param username username to use to authenticate - * @return 0 for success or an error code for failure - */ -GIT_EXTERN(int) git_credential_ssh_key_from_agent( - git_credential **out, - const char *username); - -/** - * Callback for credential signing. - * - * @param session the libssh2 session - * @param sig the signature - * @param sig_len the length of the signature - * @param data the data - * @param data_len the length of the data - * @param abstract the abstract - * @return 0 for success, < 0 to indicate an error, > 0 to indicate - * no credential was acquired - */ -typedef int GIT_CALLBACK(git_credential_sign_cb)( - LIBSSH2_SESSION *session, - unsigned char **sig, size_t *sig_len, - const unsigned char *data, size_t data_len, - void **abstract); - -/** - * Create an ssh key credential with a custom signing function. - * - * This lets you use your own function to sign the challenge. - * - * This function and its credential type is provided for completeness - * and wraps `libssh2_userauth_publickey()`, which is undocumented. - * - * The supplied credential parameter will be internally duplicated. - * - * @param out The newly created credential object. - * @param username username to use to authenticate - * @param publickey The bytes of the public key. - * @param publickey_len The length of the public key in bytes. - * @param sign_callback The callback method to sign the data during the challenge. - * @param payload Additional data to pass to the callback. - * @return 0 for success or an error code for failure - */ -GIT_EXTERN(int) git_credential_ssh_custom_new( - git_credential **out, - const char *username, - const char *publickey, - size_t publickey_len, - git_credential_sign_cb sign_callback, - void *payload); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/credential_helpers.h b/vendor/libgit2-sys/libgit2/include/git2/credential_helpers.h deleted file mode 100644 index 706558d..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/credential_helpers.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_credential_helpers_h__ -#define INCLUDE_git_credential_helpers_h__ - -#include "transport.h" - -/** - * @file git2/credential_helpers.h - * @brief Utility functions for credential management - * @defgroup git_credential_helpers credential management helpers - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Payload for git_credential_userpass_plaintext. - */ -typedef struct git_credential_userpass_payload { - const char *username; - const char *password; -} git_credential_userpass_payload; - - -/** - * Stock callback usable as a git_credential_acquire_cb. This calls - * git_cred_userpass_plaintext_new unless the protocol has not specified - * `GIT_CREDENTIAL_USERPASS_PLAINTEXT` as an allowed type. - * - * @param out The newly created credential object. - * @param url The resource for which we are demanding a credential. - * @param user_from_url The username that was embedded in a "user\@host" - * remote url, or NULL if not included. - * @param allowed_types A bitmask stating which credential types are OK to return. - * @param payload The payload provided when specifying this callback. (This is - * interpreted as a `git_credential_userpass_payload*`.) - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_credential_userpass( - git_credential **out, - const char *url, - const char *user_from_url, - unsigned int allowed_types, - void *payload); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/deprecated.h b/vendor/libgit2-sys/libgit2/include/git2/deprecated.h deleted file mode 100644 index c547b75..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/deprecated.h +++ /dev/null @@ -1,1069 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_deprecated_h__ -#define INCLUDE_git_deprecated_h__ - -#include "attr.h" -#include "config.h" -#include "common.h" -#include "blame.h" -#include "buffer.h" -#include "checkout.h" -#include "cherrypick.h" -#include "clone.h" -#include "describe.h" -#include "diff.h" -#include "errors.h" -#include "filter.h" -#include "index.h" -#include "indexer.h" -#include "merge.h" -#include "object.h" -#include "proxy.h" -#include "refs.h" -#include "rebase.h" -#include "remote.h" -#include "trace.h" -#include "repository.h" -#include "revert.h" -#include "revparse.h" -#include "stash.h" -#include "status.h" -#include "submodule.h" -#include "worktree.h" -#include "credential.h" -#include "credential_helpers.h" - -/* - * Users can avoid deprecated functions by defining `GIT_DEPRECATE_HARD`. - */ -#ifndef GIT_DEPRECATE_HARD - -/* - * The credential structures are now opaque by default, and their - * definition has moved into the `sys/credential.h` header; include - * them here for backward compatibility. - */ -#include "sys/credential.h" - -/** - * @file git2/deprecated.h - * @brief Deprecated functions and values - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** @name Deprecated Attribute Constants - * - * These enumeration values are retained for backward compatibility. - * The newer versions of these functions should be preferred in all - * new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** @deprecated use GIT_ATTR_VALUE_UNSPECIFIED */ -#define GIT_ATTR_UNSPECIFIED_T GIT_ATTR_VALUE_UNSPECIFIED -/** @deprecated use GIT_ATTR_VALUE_TRUE */ -#define GIT_ATTR_TRUE_T GIT_ATTR_VALUE_TRUE -/** @deprecated use GIT_ATTR_VALUE_FALSE */ -#define GIT_ATTR_FALSE_T GIT_ATTR_VALUE_FALSE -/** @deprecated use GIT_ATTR_VALUE_STRING */ -#define GIT_ATTR_VALUE_T GIT_ATTR_VALUE_STRING - -/** @deprecated use GIT_ATTR_IS_TRUE */ -#define GIT_ATTR_TRUE(attr) GIT_ATTR_IS_TRUE(attr) -/** @deprecated use GIT_ATTR_IS_FALSE */ -#define GIT_ATTR_FALSE(attr) GIT_ATTR_IS_FALSE(attr) -/** @deprecated use GIT_ATTR_IS_UNSPECIFIED */ -#define GIT_ATTR_UNSPECIFIED(attr) GIT_ATTR_IS_UNSPECIFIED(attr) - -/** @deprecated use git_attr_value_t */ -typedef git_attr_value_t git_attr_t; - -/**@}*/ - -/** @name Deprecated Blob Functions and Constants - * - * These functions and enumeration values are retained for backward - * compatibility. The newer versions of these functions and values - * should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** @deprecated use GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD */ -#define GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD - -GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path); -GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path); -GIT_EXTERN(int) git_blob_create_fromstream( - git_writestream **out, - git_repository *repo, - const char *hintpath); -GIT_EXTERN(int) git_blob_create_fromstream_commit( - git_oid *out, - git_writestream *stream); -GIT_EXTERN(int) git_blob_create_frombuffer( - git_oid *id, git_repository *repo, const void *buffer, size_t len); - -/** Deprecated in favor of `git_blob_filter`. - * - * @deprecated Use git_blob_filter - * @see git_blob_filter - */ -GIT_EXTERN(int) git_blob_filtered_content( - git_buf *out, - git_blob *blob, - const char *as_path, - int check_for_binary_data); - -/**@}*/ - -/** @name Deprecated Filter Functions - * - * These functions are retained for backward compatibility. The - * newer versions of these functions should be preferred in all - * new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** Deprecated in favor of `git_filter_list_stream_buffer`. - * - * @deprecated Use git_filter_list_stream_buffer - * @see Use git_filter_list_stream_buffer - */ -GIT_EXTERN(int) git_filter_list_stream_data( - git_filter_list *filters, - git_buf *data, - git_writestream *target); - -/** Deprecated in favor of `git_filter_list_apply_to_buffer`. - * - * @deprecated Use git_filter_list_apply_to_buffer - * @see Use git_filter_list_apply_to_buffer - */ -GIT_EXTERN(int) git_filter_list_apply_to_data( - git_buf *out, - git_filter_list *filters, - git_buf *in); - -/**@}*/ - -/** @name Deprecated Tree Functions - * - * These functions are retained for backward compatibility. The - * newer versions of these functions and values should be preferred - * in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** - * Write the contents of the tree builder as a tree object. - * This is an alias of `git_treebuilder_write` and is preserved - * for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Use git_treebuilder_write - * @see git_treebuilder_write - */ -GIT_EXTERN(int) git_treebuilder_write_with_buffer( - git_oid *oid, git_treebuilder *bld, git_buf *tree); - -/**@}*/ - -/** @name Deprecated Buffer Functions - * - * These functions and enumeration values are retained for backward - * compatibility. The newer versions of these functions should be - * preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** - * Static initializer for git_buf from static buffer - */ -#define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) } - -/** - * Resize the buffer allocation to make more space. - * - * This will attempt to grow the buffer to accommodate the target size. - * - * If the buffer refers to memory that was not allocated by libgit2 (i.e. - * the `asize` field is zero), then `ptr` will be replaced with a newly - * allocated block of data. Be careful so that memory allocated by the - * caller is not lost. As a special variant, if you pass `target_size` as - * 0 and the memory is not allocated by libgit2, this will allocate a new - * buffer of size `size` and copy the external data into it. - * - * Currently, this will never shrink a buffer, only expand it. - * - * If the allocation fails, this will return an error and the buffer will be - * marked as invalid for future operations, invaliding the contents. - * - * @param buffer The buffer to be resized; may or may not be allocated yet - * @param target_size The desired available size - * @return 0 on success, -1 on allocation failure - */ -GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size); - -/** - * Set buffer to a copy of some raw data. - * - * @param buffer The buffer to set - * @param data The data to copy into the buffer - * @param datalen The length of the data to copy into the buffer - * @return 0 on success, -1 on allocation failure - */ -GIT_EXTERN(int) git_buf_set( - git_buf *buffer, const void *data, size_t datalen); - -/** -* Check quickly if buffer looks like it contains binary data -* -* @param buf Buffer to check -* @return 1 if buffer looks like non-text data -*/ -GIT_EXTERN(int) git_buf_is_binary(const git_buf *buf); - -/** -* Check quickly if buffer contains a NUL byte -* -* @param buf Buffer to check -* @return 1 if buffer contains a NUL byte -*/ -GIT_EXTERN(int) git_buf_contains_nul(const git_buf *buf); - -/** - * Free the memory referred to by the git_buf. This is an alias of - * `git_buf_dispose` and is preserved for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Use git_buf_dispose - * @see git_buf_dispose - */ -GIT_EXTERN(void) git_buf_free(git_buf *buffer); - -/**@}*/ - -/** @name Deprecated Commit Definitions - */ -/**@{*/ - -/** - * Provide a commit signature during commit creation. - * - * Callers should instead define a `git_commit_create_cb` that - * generates a commit buffer using `git_commit_create_buffer`, sign - * that buffer and call `git_commit_create_with_signature`. - * - * @deprecated use a `git_commit_create_cb` instead - */ -typedef int (*git_commit_signing_cb)( - git_buf *signature, - git_buf *signature_field, - const char *commit_content, - void *payload); - -/**@}*/ - -/** @name Deprecated Config Functions and Constants - */ -/**@{*/ - -/** @deprecated use GIT_CONFIGMAP_FALSE */ -#define GIT_CVAR_FALSE GIT_CONFIGMAP_FALSE -/** @deprecated use GIT_CONFIGMAP_TRUE */ -#define GIT_CVAR_TRUE GIT_CONFIGMAP_TRUE -/** @deprecated use GIT_CONFIGMAP_INT32 */ -#define GIT_CVAR_INT32 GIT_CONFIGMAP_INT32 -/** @deprecated use GIT_CONFIGMAP_STRING */ -#define GIT_CVAR_STRING GIT_CONFIGMAP_STRING - -/** @deprecated use git_cvar_map */ -typedef git_configmap git_cvar_map; - -/**@}*/ - -/** @name Deprecated Diff Functions and Constants - * - * These functions and enumeration values are retained for backward - * compatibility. The newer versions of these functions and values - * should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** - * Formatting options for diff e-mail generation - */ -typedef enum { - /** Normal patch, the default */ - GIT_DIFF_FORMAT_EMAIL_NONE = 0, - - /** Don't insert "[PATCH]" in the subject header*/ - GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0) -} git_diff_format_email_flags_t; - -/** - * Options for controlling the formatting of the generated e-mail. - * - * @deprecated use `git_email_create_options` - */ -typedef struct { - unsigned int version; - - /** see `git_diff_format_email_flags_t` above */ - uint32_t flags; - - /** This patch number */ - size_t patch_no; - - /** Total number of patches in this series */ - size_t total_patches; - - /** id to use for the commit */ - const git_oid *id; - - /** Summary of the change */ - const char *summary; - - /** Commit message's body */ - const char *body; - - /** Author of the change */ - const git_signature *author; -} git_diff_format_email_options; - -/** @deprecated use `git_email_create_options` */ -#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION 1 -/** @deprecated use `git_email_create_options` */ -#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT {GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, 0, 1, 1, NULL, NULL, NULL, NULL} - -/** - * Create an e-mail ready patch from a diff. - * - * @deprecated git_email_create_from_diff - * @see git_email_create_from_diff - */ -GIT_EXTERN(int) git_diff_format_email( - git_buf *out, - git_diff *diff, - const git_diff_format_email_options *opts); - -/** - * Create an e-mail ready patch for a commit. - * - * @deprecated git_email_create_from_commit - * @see git_email_create_from_commit - */ -GIT_EXTERN(int) git_diff_commit_as_email( - git_buf *out, - git_repository *repo, - git_commit *commit, - size_t patch_no, - size_t total_patches, - uint32_t flags, - const git_diff_options *diff_opts); - -/** - * Initialize git_diff_format_email_options structure - * - * Initializes a `git_diff_format_email_options` with default values. Equivalent - * to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT. - * - * @param opts The `git_blame_options` struct to initialize. - * @param version The struct version; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_diff_format_email_options_init( - git_diff_format_email_options *opts, - unsigned int version); - -/**@}*/ - -/** @name Deprecated Error Functions and Constants - * - * These functions and enumeration values are retained for backward - * compatibility. The newer versions of these functions and values - * should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** @deprecated use `GIT_ERROR_NONE` */ -#define GITERR_NONE GIT_ERROR_NONE -/** @deprecated use `GIT_ERROR_NOMEMORY` */ -#define GITERR_NOMEMORY GIT_ERROR_NOMEMORY -/** @deprecated use `GIT_ERROR_OS` */ -#define GITERR_OS GIT_ERROR_OS -/** @deprecated use `GIT_ERROR_INVALID` */ -#define GITERR_INVALID GIT_ERROR_INVALID -/** @deprecated use `GIT_ERROR_REFERENCE` */ -#define GITERR_REFERENCE GIT_ERROR_REFERENCE -/** @deprecated use `GIT_ERROR_ZLIB` */ -#define GITERR_ZLIB GIT_ERROR_ZLIB -/** @deprecated use `GIT_ERROR_REPOSITORY` */ -#define GITERR_REPOSITORY GIT_ERROR_REPOSITORY -/** @deprecated use `GIT_ERROR_CONFIG` */ -#define GITERR_CONFIG GIT_ERROR_CONFIG -/** @deprecated use `GIT_ERROR_REGEX` */ -#define GITERR_REGEX GIT_ERROR_REGEX -/** @deprecated use `GIT_ERROR_ODB` */ -#define GITERR_ODB GIT_ERROR_ODB -/** @deprecated use `GIT_ERROR_INDEX` */ -#define GITERR_INDEX GIT_ERROR_INDEX -/** @deprecated use `GIT_ERROR_OBJECT` */ -#define GITERR_OBJECT GIT_ERROR_OBJECT -/** @deprecated use `GIT_ERROR_NET` */ -#define GITERR_NET GIT_ERROR_NET -/** @deprecated use `GIT_ERROR_TAG` */ -#define GITERR_TAG GIT_ERROR_TAG -/** @deprecated use `GIT_ERROR_TREE` */ -#define GITERR_TREE GIT_ERROR_TREE -/** @deprecated use `GIT_ERROR_INDEXER` */ -#define GITERR_INDEXER GIT_ERROR_INDEXER -/** @deprecated use `GIT_ERROR_SSL` */ -#define GITERR_SSL GIT_ERROR_SSL -/** @deprecated use `GIT_ERROR_SUBMODULE` */ -#define GITERR_SUBMODULE GIT_ERROR_SUBMODULE -/** @deprecated use `GIT_ERROR_THREAD` */ -#define GITERR_THREAD GIT_ERROR_THREAD -/** @deprecated use `GIT_ERROR_STASH` */ -#define GITERR_STASH GIT_ERROR_STASH -/** @deprecated use `GIT_ERROR_CHECKOUT` */ -#define GITERR_CHECKOUT GIT_ERROR_CHECKOUT -/** @deprecated use `GIT_ERROR_FETCHHEAD` */ -#define GITERR_FETCHHEAD GIT_ERROR_FETCHHEAD -/** @deprecated use `GIT_ERROR_MERGE` */ -#define GITERR_MERGE GIT_ERROR_MERGE -/** @deprecated use `GIT_ERROR_SSH` */ -#define GITERR_SSH GIT_ERROR_SSH -/** @deprecated use `GIT_ERROR_FILTER` */ -#define GITERR_FILTER GIT_ERROR_FILTER -/** @deprecated use `GIT_ERROR_REVERT` */ -#define GITERR_REVERT GIT_ERROR_REVERT -/** @deprecated use `GIT_ERROR_CALLBACK` */ -#define GITERR_CALLBACK GIT_ERROR_CALLBACK -/** @deprecated use `GIT_ERROR_CHERRYPICK` */ -#define GITERR_CHERRYPICK GIT_ERROR_CHERRYPICK -/** @deprecated use `GIT_ERROR_DESCRIBE` */ -#define GITERR_DESCRIBE GIT_ERROR_DESCRIBE -/** @deprecated use `GIT_ERROR_REBASE` */ -#define GITERR_REBASE GIT_ERROR_REBASE -/** @deprecated use `GIT_ERROR_FILESYSTEM` */ -#define GITERR_FILESYSTEM GIT_ERROR_FILESYSTEM -/** @deprecated use `GIT_ERROR_PATCH` */ -#define GITERR_PATCH GIT_ERROR_PATCH -/** @deprecated use `GIT_ERROR_WORKTREE` */ -#define GITERR_WORKTREE GIT_ERROR_WORKTREE -/** @deprecated use `GIT_ERROR_SHA1` */ -#define GITERR_SHA1 GIT_ERROR_SHA1 -/** @deprecated use `GIT_ERROR_SHA` */ -#define GIT_ERROR_SHA1 GIT_ERROR_SHA - -/** - * Return the last `git_error` object that was generated for the - * current thread. This is an alias of `git_error_last` and is - * preserved for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Use git_error_last - * @see git_error_last - */ -GIT_EXTERN(const git_error *) giterr_last(void); - -/** - * Clear the last error. This is an alias of `git_error_clear` and is - * preserved for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Use git_error_clear - * @see git_error_clear - */ -GIT_EXTERN(void) giterr_clear(void); - -/** - * Sets the error message to the given string. This is an alias of - * `git_error_set_str` and is preserved for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Use git_error_set_str - * @see git_error_set_str - */ -GIT_EXTERN(void) giterr_set_str(int error_class, const char *string); - -/** - * Indicates that an out-of-memory situation occurred. This is an alias - * of `git_error_set_oom` and is preserved for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Use git_error_set_oom - * @see git_error_set_oom - */ -GIT_EXTERN(void) giterr_set_oom(void); - -/**@}*/ - -/** @name Deprecated Index Functions and Constants - * - * These functions and enumeration values are retained for backward - * compatibility. The newer versions of these values should be - * preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/* The git_idxentry_extended_flag_t enum */ -/** @deprecated use `GIT_INDEX_ENTRY_NAMEMASK` */ -#define GIT_IDXENTRY_NAMEMASK GIT_INDEX_ENTRY_NAMEMASK -/** @deprecated use `GIT_INDEX_ENTRY_STAGEMASK` */ -#define GIT_IDXENTRY_STAGEMASK GIT_INDEX_ENTRY_STAGEMASK -/** @deprecated use `GIT_INDEX_ENTRY_STAGESHIFT` */ -#define GIT_IDXENTRY_STAGESHIFT GIT_INDEX_ENTRY_STAGESHIFT - -/* The git_indxentry_flag_t enum */ -/** @deprecated use `GIT_INDEX_ENTRY_EXTENDED` */ -#define GIT_IDXENTRY_EXTENDED GIT_INDEX_ENTRY_EXTENDED -/** @deprecated use `GIT_INDEX_ENTRY_VALID` */ -#define GIT_IDXENTRY_VALID GIT_INDEX_ENTRY_VALID - -/** @deprecated use `GIT_INDEX_ENTRY_STAGE` */ -#define GIT_IDXENTRY_STAGE(E) GIT_INDEX_ENTRY_STAGE(E) -/** @deprecated use `GIT_INDEX_ENTRY_STAGE_SET` */ -#define GIT_IDXENTRY_STAGE_SET(E,S) GIT_INDEX_ENTRY_STAGE_SET(E,S) - -/* The git_idxentry_extended_flag_t enum */ -/** @deprecated use `GIT_INDEX_ENTRY_INTENT_TO_ADD` */ -#define GIT_IDXENTRY_INTENT_TO_ADD GIT_INDEX_ENTRY_INTENT_TO_ADD -/** @deprecated use `GIT_INDEX_ENTRY_SKIP_WORKTREE` */ -#define GIT_IDXENTRY_SKIP_WORKTREE GIT_INDEX_ENTRY_SKIP_WORKTREE -/** @deprecated use `GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE` */ -#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_EXTENDED2 (1 << 15) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_UPDATE (1 << 0) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_REMOVE (1 << 1) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_UPTODATE (1 << 2) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_ADDED (1 << 3) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_HASHED (1 << 4) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_UNHASHED (1 << 5) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_WT_REMOVE (1 << 6) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_CONFLICTED (1 << 7) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_UNPACKED (1 << 8) -/** @deprecated this value is not public */ -#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9) - -/* The git_index_capability_t enum */ -/** @deprecated use `GIT_INDEX_CAPABILITY_IGNORE_CASE` */ -#define GIT_INDEXCAP_IGNORE_CASE GIT_INDEX_CAPABILITY_IGNORE_CASE -/** @deprecated use `GIT_INDEX_CAPABILITY_NO_FILEMODE` */ -#define GIT_INDEXCAP_NO_FILEMODE GIT_INDEX_CAPABILITY_NO_FILEMODE -/** @deprecated use `GIT_INDEX_CAPABILITY_NO_SYMLINKS` */ -#define GIT_INDEXCAP_NO_SYMLINKS GIT_INDEX_CAPABILITY_NO_SYMLINKS -/** @deprecated use `GIT_INDEX_CAPABILITY_FROM_OWNER` */ -#define GIT_INDEXCAP_FROM_OWNER GIT_INDEX_CAPABILITY_FROM_OWNER - -GIT_EXTERN(int) git_index_add_frombuffer( - git_index *index, - const git_index_entry *entry, - const void *buffer, size_t len); - -/**@}*/ - -/** @name Deprecated Object Constants - * - * These enumeration values are retained for backward compatibility. The - * newer versions of these values should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** @deprecate use `git_object_t` */ -#define git_otype git_object_t - -/** @deprecate use `GIT_OBJECT_ANY` */ -#define GIT_OBJ_ANY GIT_OBJECT_ANY -/** @deprecate use `GIT_OBJECT_INVALID` */ -#define GIT_OBJ_BAD GIT_OBJECT_INVALID -/** @deprecated this value is not public */ -#define GIT_OBJ__EXT1 0 -/** @deprecate use `GIT_OBJECT_COMMIT` */ -#define GIT_OBJ_COMMIT GIT_OBJECT_COMMIT -/** @deprecate use `GIT_OBJECT_TREE` */ -#define GIT_OBJ_TREE GIT_OBJECT_TREE -/** @deprecate use `GIT_OBJECT_BLOB` */ -#define GIT_OBJ_BLOB GIT_OBJECT_BLOB -/** @deprecate use `GIT_OBJECT_TAG` */ -#define GIT_OBJ_TAG GIT_OBJECT_TAG -/** @deprecated this value is not public */ -#define GIT_OBJ__EXT2 5 -/** @deprecate use `GIT_OBJECT_OFS_DELTA` */ -#define GIT_OBJ_OFS_DELTA GIT_OBJECT_OFS_DELTA -/** @deprecate use `GIT_OBJECT_REF_DELTA` */ -#define GIT_OBJ_REF_DELTA GIT_OBJECT_REF_DELTA - -/** - * Get the size in bytes for the structure which - * acts as an in-memory representation of any given - * object type. - * - * For all the core types, this would the equivalent - * of calling `sizeof(git_commit)` if the core types - * were not opaque on the external API. - * - * @param type object type to get its size - * @return size in bytes of the object - */ -GIT_EXTERN(size_t) git_object__size(git_object_t type); - -/**@}*/ - -/** @name Deprecated Remote Functions - * - * These functions are retained for backward compatibility. The newer - * versions of these functions should be preferred in all new code. - * - * There is no plan to remove these backward compatibility functions at - * this time. - */ -/**@{*/ - -/** - * Ensure the remote name is well-formed. - * - * @deprecated Use git_remote_name_is_valid - * @param remote_name name to be checked. - * @return 1 if the reference name is acceptable; 0 if it isn't - */ -GIT_EXTERN(int) git_remote_is_valid_name(const char *remote_name); - -/**@}*/ - -/** @name Deprecated Reference Functions and Constants - * - * These functions and enumeration values are retained for backward - * compatibility. The newer versions of these values should be - * preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - - /** Basic type of any Git reference. */ -/** @deprecate use `git_reference_t` */ -#define git_ref_t git_reference_t -/** @deprecate use `git_reference_format_t` */ -#define git_reference_normalize_t git_reference_format_t - -/** @deprecate use `GIT_REFERENCE_INVALID` */ -#define GIT_REF_INVALID GIT_REFERENCE_INVALID -/** @deprecate use `GIT_REFERENCE_DIRECT` */ -#define GIT_REF_OID GIT_REFERENCE_DIRECT -/** @deprecate use `GIT_REFERENCE_SYMBOLIC` */ -#define GIT_REF_SYMBOLIC GIT_REFERENCE_SYMBOLIC -/** @deprecate use `GIT_REFERENCE_ALL` */ -#define GIT_REF_LISTALL GIT_REFERENCE_ALL - -/** @deprecate use `GIT_REFERENCE_FORMAT_NORMAL` */ -#define GIT_REF_FORMAT_NORMAL GIT_REFERENCE_FORMAT_NORMAL -/** @deprecate use `GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL` */ -#define GIT_REF_FORMAT_ALLOW_ONELEVEL GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL -/** @deprecate use `GIT_REFERENCE_FORMAT_REFSPEC_PATTERN` */ -#define GIT_REF_FORMAT_REFSPEC_PATTERN GIT_REFERENCE_FORMAT_REFSPEC_PATTERN -/** @deprecate use `GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND` */ -#define GIT_REF_FORMAT_REFSPEC_SHORTHAND GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND - -/** - * Ensure the reference name is well-formed. - * - * Valid reference names must follow one of two patterns: - * - * 1. Top-level names must contain only capital letters and underscores, - * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). - * 2. Names prefixed with "refs/" can be almost anything. You must avoid - * the characters '~', '^', ':', '\\', '?', '[', and '*', and the - * sequences ".." and "@{" which have special meaning to revparse. - * - * @deprecated Use git_reference_name_is_valid - * @param refname name to be checked. - * @return 1 if the reference name is acceptable; 0 if it isn't - */ -GIT_EXTERN(int) git_reference_is_valid_name(const char *refname); - -GIT_EXTERN(int) git_tag_create_frombuffer( - git_oid *oid, - git_repository *repo, - const char *buffer, - int force); - -/**@}*/ - -/** @name Deprecated Revspec Constants - * - * These enumeration values are retained for backward compatibility. - * The newer versions of these values should be preferred in all new - * code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -typedef git_revspec_t git_revparse_mode_t; - -/** @deprecated use `GIT_REVSPEC_SINGLE` */ -#define GIT_REVPARSE_SINGLE GIT_REVSPEC_SINGLE -/** @deprecated use `GIT_REVSPEC_RANGE` */ -#define GIT_REVPARSE_RANGE GIT_REVSPEC_RANGE -/** @deprecated use `GIT_REVSPEC_MERGE_BASE` */ -#define GIT_REVPARSE_MERGE_BASE GIT_REVSPEC_MERGE_BASE - -/**@}*/ - -/** @name Deprecated Credential Types - * - * These types are retained for backward compatibility. The newer - * versions of these values should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -typedef git_credential git_cred; -typedef git_credential_userpass_plaintext git_cred_userpass_plaintext; -typedef git_credential_username git_cred_username; -typedef git_credential_default git_cred_default; -typedef git_credential_ssh_key git_cred_ssh_key; -typedef git_credential_ssh_interactive git_cred_ssh_interactive; -typedef git_credential_ssh_custom git_cred_ssh_custom; - -typedef git_credential_acquire_cb git_cred_acquire_cb; -typedef git_credential_sign_cb git_cred_sign_callback; -typedef git_credential_sign_cb git_cred_sign_cb; -typedef git_credential_ssh_interactive_cb git_cred_ssh_interactive_callback; -typedef git_credential_ssh_interactive_cb git_cred_ssh_interactive_cb; - -/** @deprecated use `git_credential_t` */ -#define git_credtype_t git_credential_t - -/** @deprecated use `GIT_CREDENTIAL_USERPASS_PLAINTEXT` */ -#define GIT_CREDTYPE_USERPASS_PLAINTEXT GIT_CREDENTIAL_USERPASS_PLAINTEXT -/** @deprecated use `GIT_CREDENTIAL_SSH_KEY` */ -#define GIT_CREDTYPE_SSH_KEY GIT_CREDENTIAL_SSH_KEY -/** @deprecated use `GIT_CREDENTIAL_SSH_CUSTOM` */ -#define GIT_CREDTYPE_SSH_CUSTOM GIT_CREDENTIAL_SSH_CUSTOM -/** @deprecated use `GIT_CREDENTIAL_DEFAULT` */ -#define GIT_CREDTYPE_DEFAULT GIT_CREDENTIAL_DEFAULT -/** @deprecated use `GIT_CREDENTIAL_SSH_INTERACTIVE` */ -#define GIT_CREDTYPE_SSH_INTERACTIVE GIT_CREDENTIAL_SSH_INTERACTIVE -/** @deprecated use `GIT_CREDENTIAL_USERNAME` */ -#define GIT_CREDTYPE_USERNAME GIT_CREDENTIAL_USERNAME -/** @deprecated use `GIT_CREDENTIAL_SSH_MEMORY` */ -#define GIT_CREDTYPE_SSH_MEMORY GIT_CREDENTIAL_SSH_MEMORY - -GIT_EXTERN(void) git_cred_free(git_credential *cred); -GIT_EXTERN(int) git_cred_has_username(git_credential *cred); -GIT_EXTERN(const char *) git_cred_get_username(git_credential *cred); -GIT_EXTERN(int) git_cred_userpass_plaintext_new( - git_credential **out, - const char *username, - const char *password); -GIT_EXTERN(int) git_cred_default_new(git_credential **out); -GIT_EXTERN(int) git_cred_username_new(git_credential **out, const char *username); -GIT_EXTERN(int) git_cred_ssh_key_new( - git_credential **out, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase); -GIT_EXTERN(int) git_cred_ssh_key_memory_new( - git_credential **out, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase); -GIT_EXTERN(int) git_cred_ssh_interactive_new( - git_credential **out, - const char *username, - git_credential_ssh_interactive_cb prompt_callback, - void *payload); -GIT_EXTERN(int) git_cred_ssh_key_from_agent( - git_credential **out, - const char *username); -GIT_EXTERN(int) git_cred_ssh_custom_new( - git_credential **out, - const char *username, - const char *publickey, - size_t publickey_len, - git_credential_sign_cb sign_callback, - void *payload); - -/* Deprecated Credential Helper Types */ - -typedef git_credential_userpass_payload git_cred_userpass_payload; - -GIT_EXTERN(int) git_cred_userpass( - git_credential **out, - const char *url, - const char *user_from_url, - unsigned int allowed_types, - void *payload); - -/**@}*/ - -/** @name Deprecated Trace Callback Types - * - * These types are retained for backward compatibility. The newer - * versions of these values should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -typedef git_trace_cb git_trace_callback; - -/**@}*/ - -/** @name Deprecated Object ID Types - * - * These types are retained for backward compatibility. The newer - * versions of these values should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -#ifndef GIT_EXPERIMENTAL_SHA256 -/** Deprecated OID "raw size" definition */ -# define GIT_OID_RAWSZ GIT_OID_SHA1_SIZE -/** Deprecated OID "hex size" definition */ -# define GIT_OID_HEXSZ GIT_OID_SHA1_HEXSIZE -/** Deprecated OID "hex zero" definition */ -# define GIT_OID_HEX_ZERO GIT_OID_SHA1_HEXZERO -#endif - -GIT_EXTERN(int) git_oid_iszero(const git_oid *id); - -/**@}*/ - -/** @name Deprecated OID Array Functions - * - * These types are retained for backward compatibility. The newer - * versions of these values should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** - * Free the memory referred to by the git_oidarray. This is an alias of - * `git_oidarray_dispose` and is preserved for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Use git_oidarray_dispose - * @see git_oidarray_dispose - */ -GIT_EXTERN(void) git_oidarray_free(git_oidarray *array); - -/**@}*/ - -/** @name Deprecated Transfer Progress Types - * - * These types are retained for backward compatibility. The newer - * versions of these values should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** - * This structure is used to provide callers information about the - * progress of indexing a packfile. - * - * This type is deprecated, but there is no plan to remove this - * type definition at this time. - */ -typedef git_indexer_progress git_transfer_progress; - -/** - * Type definition for progress callbacks during indexing. - * - * This type is deprecated, but there is no plan to remove this - * type definition at this time. - */ -typedef git_indexer_progress_cb git_transfer_progress_cb; - -/** - * Type definition for push transfer progress callbacks. - * - * This type is deprecated, but there is no plan to remove this - * type definition at this time. - */ -typedef git_push_transfer_progress_cb git_push_transfer_progress; - - /** The type of a remote completion event */ -#define git_remote_completion_type git_remote_completion_t - -/** - * Callback for listing the remote heads - */ -typedef int GIT_CALLBACK(git_headlist_cb)(git_remote_head *rhead, void *payload); - -/**@}*/ - -/** @name Deprecated String Array Functions - * - * These types are retained for backward compatibility. The newer - * versions of these values should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** - * Copy a string array object from source to target. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @param tgt target - * @param src source - * @return 0 on success, < 0 on allocation failure - */ -GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src); - -/** - * Free the memory referred to by the git_strarray. This is an alias of - * `git_strarray_dispose` and is preserved for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Use git_strarray_dispose - * @see git_strarray_dispose - */ -GIT_EXTERN(void) git_strarray_free(git_strarray *array); - -/**@}*/ - -/** @name Deprecated Version Constants - * - * These constants are retained for backward compatibility. The newer - * versions of these constants should be preferred in all new code. - * - * There is no plan to remove these backward compatibility constants at - * this time. - */ -/**@{*/ - -#define LIBGIT2_VER_MAJOR LIBGIT2_VERSION_MAJOR -#define LIBGIT2_VER_MINOR LIBGIT2_VERSION_MINOR -#define LIBGIT2_VER_REVISION LIBGIT2_VERSION_REVISION -#define LIBGIT2_VER_PATCH LIBGIT2_VERSION_PATCH -#define LIBGIT2_VER_PRERELEASE LIBGIT2_VERSION_PRERELEASE - -/**@}*/ - -/** @name Deprecated Options Initialization Functions - * - * These functions are retained for backward compatibility. The newer - * versions of these functions should be preferred in all new code. - * - * There is no plan to remove these backward compatibility functions at - * this time. - */ -/**@{*/ - -GIT_EXTERN(int) git_blame_init_options(git_blame_options *opts, unsigned int version); -GIT_EXTERN(int) git_checkout_init_options(git_checkout_options *opts, unsigned int version); -GIT_EXTERN(int) git_cherrypick_init_options(git_cherrypick_options *opts, unsigned int version); -GIT_EXTERN(int) git_clone_init_options(git_clone_options *opts, unsigned int version); -GIT_EXTERN(int) git_describe_init_options(git_describe_options *opts, unsigned int version); -GIT_EXTERN(int) git_describe_init_format_options(git_describe_format_options *opts, unsigned int version); -GIT_EXTERN(int) git_diff_init_options(git_diff_options *opts, unsigned int version); -GIT_EXTERN(int) git_diff_find_init_options(git_diff_find_options *opts, unsigned int version); -GIT_EXTERN(int) git_diff_format_email_init_options(git_diff_format_email_options *opts, unsigned int version); -GIT_EXTERN(int) git_diff_patchid_init_options(git_diff_patchid_options *opts, unsigned int version); -GIT_EXTERN(int) git_fetch_init_options(git_fetch_options *opts, unsigned int version); -GIT_EXTERN(int) git_indexer_init_options(git_indexer_options *opts, unsigned int version); -GIT_EXTERN(int) git_merge_init_options(git_merge_options *opts, unsigned int version); -GIT_EXTERN(int) git_merge_file_init_input(git_merge_file_input *input, unsigned int version); -GIT_EXTERN(int) git_merge_file_init_options(git_merge_file_options *opts, unsigned int version); -GIT_EXTERN(int) git_proxy_init_options(git_proxy_options *opts, unsigned int version); -GIT_EXTERN(int) git_push_init_options(git_push_options *opts, unsigned int version); -GIT_EXTERN(int) git_rebase_init_options(git_rebase_options *opts, unsigned int version); -GIT_EXTERN(int) git_remote_create_init_options(git_remote_create_options *opts, unsigned int version); -GIT_EXTERN(int) git_repository_init_init_options(git_repository_init_options *opts, unsigned int version); -GIT_EXTERN(int) git_revert_init_options(git_revert_options *opts, unsigned int version); -GIT_EXTERN(int) git_stash_apply_init_options(git_stash_apply_options *opts, unsigned int version); -GIT_EXTERN(int) git_status_init_options(git_status_options *opts, unsigned int version); -GIT_EXTERN(int) git_submodule_update_init_options(git_submodule_update_options *opts, unsigned int version); -GIT_EXTERN(int) git_worktree_add_init_options(git_worktree_add_options *opts, unsigned int version); -GIT_EXTERN(int) git_worktree_prune_init_options(git_worktree_prune_options *opts, unsigned int version); - -/**@}*/ - -/** @} */ -GIT_END_DECL - -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/describe.h b/vendor/libgit2-sys/libgit2/include/git2/describe.h deleted file mode 100644 index 938c470..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/describe.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_describe_h__ -#define INCLUDE_git_describe_h__ - -#include "common.h" -#include "types.h" -#include "buffer.h" - -/** - * @file git2/describe.h - * @brief Describe a commit in reference to tags - * @defgroup git_describe Git describing routines - * @ingroup Git - * @{ - * - * Describe a commit, showing information about how the current commit - * relates to the tags. This can be useful for showing how the current - * commit has changed from a particular tagged version of the repository. - */ -GIT_BEGIN_DECL - -/** - * Reference lookup strategy - * - * These behave like the --tags and --all options to git-describe, - * namely they say to look for any reference in either refs/tags/ or - * refs/ respectively. - */ -typedef enum { - GIT_DESCRIBE_DEFAULT, - GIT_DESCRIBE_TAGS, - GIT_DESCRIBE_ALL -} git_describe_strategy_t; - -/** - * Describe options structure - * - * Initialize with `GIT_DESCRIBE_OPTIONS_INIT`. Alternatively, you can - * use `git_describe_options_init`. - * - */ -typedef struct git_describe_options { - unsigned int version; - - unsigned int max_candidates_tags; /**< default: 10 */ - unsigned int describe_strategy; /**< default: GIT_DESCRIBE_DEFAULT */ - const char *pattern; - /** - * When calculating the distance from the matching tag or - * reference, only walk down the first-parent ancestry. - */ - int only_follow_first_parent; - /** - * If no matching tag or reference is found, the describe - * operation would normally fail. If this option is set, it - * will instead fall back to showing the full id of the - * commit. - */ - int show_commit_oid_as_fallback; -} git_describe_options; - -/** Default maximum candidate tags */ -#define GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS 10 -/** Default abbreviated size */ -#define GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE 7 - -/** Current version for the `git_describe_options` structure */ -#define GIT_DESCRIBE_OPTIONS_VERSION 1 - -/** Static constructor for `git_describe_options` */ -#define GIT_DESCRIBE_OPTIONS_INIT { \ - GIT_DESCRIBE_OPTIONS_VERSION, \ - GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS, \ -} - -/** - * Initialize git_describe_options structure - * - * Initializes a `git_describe_options` with default values. Equivalent to creating - * an instance with GIT_DESCRIBE_OPTIONS_INIT. - * - * @param opts The `git_describe_options` struct to initialize. - * @param version The struct version; pass `GIT_DESCRIBE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_describe_options_init(git_describe_options *opts, unsigned int version); - -/** - * Describe format options structure - * - * Initialize with `GIT_DESCRIBE_FORMAT_OPTIONS_INIT`. Alternatively, you can - * use `git_describe_format_options_init`. - * - */ -typedef struct { - unsigned int version; - - /** - * Size of the abbreviated commit id to use. This value is the - * lower bound for the length of the abbreviated string. The - * default is 7. - */ - unsigned int abbreviated_size; - - /** - * Set to use the long format even when a shorter name could be used. - */ - int always_use_long_format; - - /** - * If the workdir is dirty and this is set, this string will - * be appended to the description string. - */ - const char *dirty_suffix; -} git_describe_format_options; - -/** Current version for the `git_describe_format_options` structure */ -#define GIT_DESCRIBE_FORMAT_OPTIONS_VERSION 1 - -/** Static constructor for `git_describe_format_options` */ -#define GIT_DESCRIBE_FORMAT_OPTIONS_INIT { \ - GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, \ - GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE, \ - } - -/** - * Initialize git_describe_format_options structure - * - * Initializes a `git_describe_format_options` with default values. Equivalent to creating - * an instance with GIT_DESCRIBE_FORMAT_OPTIONS_INIT. - * - * @param opts The `git_describe_format_options` struct to initialize. - * @param version The struct version; pass `GIT_DESCRIBE_FORMAT_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_describe_format_options_init(git_describe_format_options *opts, unsigned int version); - -/** - * A struct that stores the result of a describe operation. - */ -typedef struct git_describe_result git_describe_result; - -/** - * Describe a commit - * - * Perform the describe operation on the given committish object. - * - * @param result pointer to store the result. You must free this once - * you're done with it. - * @param committish a committish to describe - * @param opts the lookup options (or NULL for defaults) - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_describe_commit( - git_describe_result **result, - git_object *committish, - git_describe_options *opts); - -/** - * Describe a commit - * - * Perform the describe operation on the current commit and the - * worktree. After performing describe on HEAD, a status is run and the - * description is considered to be dirty if there are. - * - * @param out pointer to store the result. You must free this once - * you're done with it. - * @param repo the repository in which to perform the describe - * @param opts the lookup options (or NULL for defaults) - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_describe_workdir( - git_describe_result **out, - git_repository *repo, - git_describe_options *opts); - -/** - * Print the describe result to a buffer - * - * @param out The buffer to store the result - * @param result the result from `git_describe_commit()` or - * `git_describe_workdir()`. - * @param opts the formatting options (or NULL for defaults) - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_describe_format( - git_buf *out, - const git_describe_result *result, - const git_describe_format_options *opts); - -/** - * Free the describe result. - * - * @param result The result to free. - */ -GIT_EXTERN(void) git_describe_result_free(git_describe_result *result); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/diff.h b/vendor/libgit2-sys/libgit2/include/git2/diff.h deleted file mode 100644 index b12e8ab..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/diff.h +++ /dev/null @@ -1,1507 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_diff_h__ -#define INCLUDE_git_diff_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "tree.h" -#include "refs.h" - -/** - * @file git2/diff.h - * @brief Indicate the differences between two versions of the repository - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Flags for diff options. A combination of these flags can be passed - * in via the `flags` value in the `git_diff_options`. - */ -typedef enum { - /** Normal diff, the default */ - GIT_DIFF_NORMAL = 0, - - /* - * Options controlling which files will be in the diff - */ - - /** Reverse the sides of the diff */ - GIT_DIFF_REVERSE = (1u << 0), - - /** Include ignored files in the diff */ - GIT_DIFF_INCLUDE_IGNORED = (1u << 1), - - /** Even with GIT_DIFF_INCLUDE_IGNORED, an entire ignored directory - * will be marked with only a single entry in the diff; this flag - * adds all files under the directory as IGNORED entries, too. - */ - GIT_DIFF_RECURSE_IGNORED_DIRS = (1u << 2), - - /** Include untracked files in the diff */ - GIT_DIFF_INCLUDE_UNTRACKED = (1u << 3), - - /** Even with GIT_DIFF_INCLUDE_UNTRACKED, an entire untracked - * directory will be marked with only a single entry in the diff - * (a la what core Git does in `git status`); this flag adds *all* - * files under untracked directories as UNTRACKED entries, too. - */ - GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1u << 4), - - /** Include unmodified files in the diff */ - GIT_DIFF_INCLUDE_UNMODIFIED = (1u << 5), - - /** Normally, a type change between files will be converted into a - * DELETED record for the old and an ADDED record for the new; this - * options enabled the generation of TYPECHANGE delta records. - */ - GIT_DIFF_INCLUDE_TYPECHANGE = (1u << 6), - - /** Even with GIT_DIFF_INCLUDE_TYPECHANGE, blob->tree changes still - * generally show as a DELETED blob. This flag tries to correctly - * label blob->tree transitions as TYPECHANGE records with new_file's - * mode set to tree. Note: the tree SHA will not be available. - */ - GIT_DIFF_INCLUDE_TYPECHANGE_TREES = (1u << 7), - - /** Ignore file mode changes */ - GIT_DIFF_IGNORE_FILEMODE = (1u << 8), - - /** Treat all submodules as unmodified */ - GIT_DIFF_IGNORE_SUBMODULES = (1u << 9), - - /** Use case insensitive filename comparisons */ - GIT_DIFF_IGNORE_CASE = (1u << 10), - - /** May be combined with `GIT_DIFF_IGNORE_CASE` to specify that a file - * that has changed case will be returned as an add/delete pair. - */ - GIT_DIFF_INCLUDE_CASECHANGE = (1u << 11), - - /** If the pathspec is set in the diff options, this flags indicates - * that the paths will be treated as literal paths instead of - * fnmatch patterns. Each path in the list must either be a full - * path to a file or a directory. (A trailing slash indicates that - * the path will _only_ match a directory). If a directory is - * specified, all children will be included. - */ - GIT_DIFF_DISABLE_PATHSPEC_MATCH = (1u << 12), - - /** Disable updating of the `binary` flag in delta records. This is - * useful when iterating over a diff if you don't need hunk and data - * callbacks and want to avoid having to load file completely. - */ - GIT_DIFF_SKIP_BINARY_CHECK = (1u << 13), - - /** When diff finds an untracked directory, to match the behavior of - * core Git, it scans the contents for IGNORED and UNTRACKED files. - * If *all* contents are IGNORED, then the directory is IGNORED; if - * any contents are not IGNORED, then the directory is UNTRACKED. - * This is extra work that may not matter in many cases. This flag - * turns off that scan and immediately labels an untracked directory - * as UNTRACKED (changing the behavior to not match core Git). - */ - GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS = (1u << 14), - - /** When diff finds a file in the working directory with stat - * information different from the index, but the OID ends up being the - * same, write the correct stat information into the index. Note: - * without this flag, diff will always leave the index untouched. - */ - GIT_DIFF_UPDATE_INDEX = (1u << 15), - - /** Include unreadable files in the diff */ - GIT_DIFF_INCLUDE_UNREADABLE = (1u << 16), - - /** Include unreadable files in the diff */ - GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 17), - - /* - * Options controlling how output will be generated - */ - - /** Use a heuristic that takes indentation and whitespace into account - * which generally can produce better diffs when dealing with ambiguous - * diff hunks. - */ - GIT_DIFF_INDENT_HEURISTIC = (1u << 18), - - /** Ignore blank lines */ - GIT_DIFF_IGNORE_BLANK_LINES = (1u << 19), - - /** Treat all files as text, disabling binary attributes & detection */ - GIT_DIFF_FORCE_TEXT = (1u << 20), - /** Treat all files as binary, disabling text diffs */ - GIT_DIFF_FORCE_BINARY = (1u << 21), - - /** Ignore all whitespace */ - GIT_DIFF_IGNORE_WHITESPACE = (1u << 22), - /** Ignore changes in amount of whitespace */ - GIT_DIFF_IGNORE_WHITESPACE_CHANGE = (1u << 23), - /** Ignore whitespace at end of line */ - GIT_DIFF_IGNORE_WHITESPACE_EOL = (1u << 24), - - /** When generating patch text, include the content of untracked - * files. This automatically turns on GIT_DIFF_INCLUDE_UNTRACKED but - * it does not turn on GIT_DIFF_RECURSE_UNTRACKED_DIRS. Add that - * flag if you want the content of every single UNTRACKED file. - */ - GIT_DIFF_SHOW_UNTRACKED_CONTENT = (1u << 25), - - /** When generating output, include the names of unmodified files if - * they are included in the git_diff. Normally these are skipped in - * the formats that list files (e.g. name-only, name-status, raw). - * Even with this, these will not be included in patch format. - */ - GIT_DIFF_SHOW_UNMODIFIED = (1u << 26), - - /** Use the "patience diff" algorithm */ - GIT_DIFF_PATIENCE = (1u << 28), - /** Take extra time to find minimal diff */ - GIT_DIFF_MINIMAL = (1u << 29), - - /** Include the necessary deflate / delta information so that `git-apply` - * can apply given diff information to binary files. - */ - GIT_DIFF_SHOW_BINARY = (1u << 30) -} git_diff_option_t; - -/** - * The diff object that contains all individual file deltas. - * - * A `diff` represents the cumulative list of differences between two - * snapshots of a repository (possibly filtered by a set of file name - * patterns). - * - * Calculating diffs is generally done in two phases: building a list of - * diffs then traversing it. This makes is easier to share logic across - * the various types of diffs (tree vs tree, workdir vs index, etc.), and - * also allows you to insert optional diff post-processing phases, - * such as rename detection, in between the steps. When you are done with - * a diff object, it must be freed. - * - * This is an opaque structure which will be allocated by one of the diff - * generator functions below (such as `git_diff_tree_to_tree`). You are - * responsible for releasing the object memory when done, using the - * `git_diff_free()` function. - * - */ -typedef struct git_diff git_diff; - -/** - * Flags for the delta object and the file objects on each side. - * - * These flags are used for both the `flags` value of the `git_diff_delta` - * and the flags for the `git_diff_file` objects representing the old and - * new sides of the delta. Values outside of this public range should be - * considered reserved for internal or future use. - */ -typedef enum { - GIT_DIFF_FLAG_BINARY = (1u << 0), /**< file(s) treated as binary data */ - GIT_DIFF_FLAG_NOT_BINARY = (1u << 1), /**< file(s) treated as text data */ - GIT_DIFF_FLAG_VALID_ID = (1u << 2), /**< `id` value is known correct */ - GIT_DIFF_FLAG_EXISTS = (1u << 3), /**< file exists at this side of the delta */ - GIT_DIFF_FLAG_VALID_SIZE = (1u << 4) /**< file size value is known correct */ -} git_diff_flag_t; - -/** - * What type of change is described by a git_diff_delta? - * - * `GIT_DELTA_RENAMED` and `GIT_DELTA_COPIED` will only show up if you run - * `git_diff_find_similar()` on the diff object. - * - * `GIT_DELTA_TYPECHANGE` only shows up given `GIT_DIFF_INCLUDE_TYPECHANGE` - * in the option flags (otherwise type changes will be split into ADDED / - * DELETED pairs). - */ -typedef enum { - GIT_DELTA_UNMODIFIED = 0, /**< no changes */ - GIT_DELTA_ADDED = 1, /**< entry does not exist in old version */ - GIT_DELTA_DELETED = 2, /**< entry does not exist in new version */ - GIT_DELTA_MODIFIED = 3, /**< entry content changed between old and new */ - GIT_DELTA_RENAMED = 4, /**< entry was renamed between old and new */ - GIT_DELTA_COPIED = 5, /**< entry was copied from another old entry */ - GIT_DELTA_IGNORED = 6, /**< entry is ignored item in workdir */ - GIT_DELTA_UNTRACKED = 7, /**< entry is untracked item in workdir */ - GIT_DELTA_TYPECHANGE = 8, /**< type of entry changed between old and new */ - GIT_DELTA_UNREADABLE = 9, /**< entry is unreadable */ - GIT_DELTA_CONFLICTED = 10 /**< entry in the index is conflicted */ -} git_delta_t; - -/** - * Description of one side of a delta. - * - * Although this is called a "file", it could represent a file, a symbolic - * link, a submodule commit id, or even a tree (although that only if you - * are tracking type changes or ignored/untracked directories). - */ -typedef struct { - /** - * The `git_oid` of the item. If the entry represents an - * absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta), - * then the oid will be zeroes. - */ - git_oid id; - - /** - * The NUL-terminated path to the entry relative to the working - * directory of the repository. - */ - const char *path; - - /** - * The size of the entry in bytes. - */ - git_object_size_t size; - - /** - * A combination of the `git_diff_flag_t` types - */ - uint32_t flags; - - /** - * Roughly, the stat() `st_mode` value for the item. This will - * be restricted to one of the `git_filemode_t` values. - */ - uint16_t mode; - - /** - * Represents the known length of the `id` field, when - * converted to a hex string. It is generally `GIT_OID_SHA1_HEXSIZE`, unless this - * delta was created from reading a patch file, in which case it may be - * abbreviated to something reasonable, like 7 characters. - */ - uint16_t id_abbrev; -} git_diff_file; - -/** - * Description of changes to one entry. - * - * A `delta` is a file pair with an old and new revision. The old version - * may be absent if the file was just created and the new version may be - * absent if the file was deleted. A diff is mostly just a list of deltas. - * - * When iterating over a diff, this will be passed to most callbacks and - * you can use the contents to understand exactly what has changed. - * - * The `old_file` represents the "from" side of the diff and the `new_file` - * represents to "to" side of the diff. What those means depend on the - * function that was used to generate the diff and will be documented below. - * You can also use the `GIT_DIFF_REVERSE` flag to flip it around. - * - * Although the two sides of the delta are named "old_file" and "new_file", - * they actually may correspond to entries that represent a file, a symbolic - * link, a submodule commit id, or even a tree (if you are tracking type - * changes or ignored/untracked directories). - * - * Under some circumstances, in the name of efficiency, not all fields will - * be filled in, but we generally try to fill in as much as possible. One - * example is that the "flags" field may not have either the `BINARY` or the - * `NOT_BINARY` flag set to avoid examining file contents if you do not pass - * in hunk and/or line callbacks to the diff foreach iteration function. It - * will just use the git attributes for those files. - * - * The similarity score is zero unless you call `git_diff_find_similar()` - * which does a similarity analysis of files in the diff. Use that - * function to do rename and copy detection, and to split heavily modified - * files in add/delete pairs. After that call, deltas with a status of - * GIT_DELTA_RENAMED or GIT_DELTA_COPIED will have a similarity score - * between 0 and 100 indicating how similar the old and new sides are. - * - * If you ask `git_diff_find_similar` to find heavily modified files to - * break, but to not *actually* break the records, then GIT_DELTA_MODIFIED - * records may have a non-zero similarity score if the self-similarity is - * below the split threshold. To display this value like core Git, invert - * the score (a la `printf("M%03d", 100 - delta->similarity)`). - */ -typedef struct { - git_delta_t status; - uint32_t flags; /**< git_diff_flag_t values */ - uint16_t similarity; /**< for RENAMED and COPIED, value 0-100 */ - uint16_t nfiles; /**< number of files in this delta */ - git_diff_file old_file; - git_diff_file new_file; -} git_diff_delta; - -/** - * Diff notification callback function. - * - * The callback will be called for each file, just before the `git_diff_delta` - * gets inserted into the diff. - * - * When the callback: - * - returns < 0, the diff process will be aborted. - * - returns > 0, the delta will not be inserted into the diff, but the - * diff process continues. - * - returns 0, the delta is inserted into the diff, and the diff process - * continues. - * - * @param diff_so_far the diff structure as it currently exists - * @param delta_to_add the delta that is to be added - * @param matched_pathspec the pathspec - * @param payload the user-specified callback payload - * @return 0 on success, 1 to skip this delta, or an error code - */ -typedef int GIT_CALLBACK(git_diff_notify_cb)( - const git_diff *diff_so_far, - const git_diff_delta *delta_to_add, - const char *matched_pathspec, - void *payload); - -/** - * Diff progress callback. - * - * Called before each file comparison. - * - * @param diff_so_far The diff being generated. - * @param old_path The path to the old file or NULL. - * @param new_path The path to the new file or NULL. - * @param payload the user-specified callback payload - * @return 0 or an error code - */ -typedef int GIT_CALLBACK(git_diff_progress_cb)( - const git_diff *diff_so_far, - const char *old_path, - const char *new_path, - void *payload); - -/** - * Structure describing options about how the diff should be executed. - * - * Setting all values of the structure to zero will yield the default - * values. Similarly, passing NULL for the options structure will - * give the defaults. The default values are marked below. - * - */ -typedef struct { - unsigned int version; /**< version for the struct */ - - /** - * A combination of `git_diff_option_t` values above. - * Defaults to GIT_DIFF_NORMAL - */ - uint32_t flags; - - /* options controlling which files are in the diff */ - - /** Overrides the submodule ignore setting for all submodules in the diff. */ - git_submodule_ignore_t ignore_submodules; - - /** - * An array of paths / fnmatch patterns to constrain diff. - * All paths are included by default. - */ - git_strarray pathspec; - - /** - * An optional callback function, notifying the consumer of changes to - * the diff as new deltas are added. - */ - git_diff_notify_cb notify_cb; - - /** - * An optional callback function, notifying the consumer of which files - * are being examined as the diff is generated. - */ - git_diff_progress_cb progress_cb; - - /** The payload to pass to the callback functions. */ - void *payload; - - /* options controlling how to diff text is generated */ - - /** - * The number of unchanged lines that define the boundary of a hunk - * (and to display before and after). Defaults to 3. - */ - uint32_t context_lines; - /** - * The maximum number of unchanged lines between hunk boundaries before - * the hunks will be merged into one. Defaults to 0. - */ - uint32_t interhunk_lines; - - /** - * The object ID type to emit in diffs; this is used by functions - * that operate without a repository - namely `git_diff_buffers`, - * or `git_diff_blobs` and `git_diff_blob_to_buffer` when one blob - * is `NULL`. - * - * This may be omitted (set to `0`). If a repository is available, - * the object ID format of the repository will be used. If no - * repository is available then the default is `GIT_OID_SHA`. - * - * If this is specified and a repository is available, then the - * specified `oid_type` must match the repository's object ID - * format. - */ - git_oid_t oid_type; - - /** - * The abbreviation length to use when formatting object ids. - * Defaults to the value of 'core.abbrev' from the config, or 7 if unset. - */ - uint16_t id_abbrev; - - /** - * A size (in bytes) above which a blob will be marked as binary - * automatically; pass a negative value to disable. - * Defaults to 512MB. - */ - git_off_t max_size; - - /** - * The virtual "directory" prefix for old file names in hunk headers. - * Default is "a". - */ - const char *old_prefix; - - /** - * The virtual "directory" prefix for new file names in hunk headers. - * Defaults to "b". - */ - const char *new_prefix; -} git_diff_options; - -/** The current version of the diff options structure */ -#define GIT_DIFF_OPTIONS_VERSION 1 - -/** Stack initializer for diff options. Alternatively use - * `git_diff_options_init` programmatic initialization. - */ -#define GIT_DIFF_OPTIONS_INIT \ - {GIT_DIFF_OPTIONS_VERSION, 0, GIT_SUBMODULE_IGNORE_UNSPECIFIED, {NULL,0}, NULL, NULL, NULL, 3} - -/** - * Initialize git_diff_options structure - * - * Initializes a `git_diff_options` with default values. Equivalent to creating - * an instance with GIT_DIFF_OPTIONS_INIT. - * - * @param opts The `git_diff_options` struct to initialize. - * @param version The struct version; pass `GIT_DIFF_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_diff_options_init( - git_diff_options *opts, - unsigned int version); - -/** - * When iterating over a diff, callback that will be made per file. - * - * @param delta A pointer to the delta data for the file - * @param progress Goes from 0 to 1 over the diff - * @param payload User-specified pointer from foreach function - * @return 0 or an error code - */ -typedef int GIT_CALLBACK(git_diff_file_cb)( - const git_diff_delta *delta, - float progress, - void *payload); - -/** Maximum size of the hunk header */ -#define GIT_DIFF_HUNK_HEADER_SIZE 128 - -/** - * When producing a binary diff, the binary data returned will be - * either the deflated full ("literal") contents of the file, or - * the deflated binary delta between the two sides (whichever is - * smaller). - */ -typedef enum { - /** There is no binary delta. */ - GIT_DIFF_BINARY_NONE, - - /** The binary data is the literal contents of the file. */ - GIT_DIFF_BINARY_LITERAL, - - /** The binary data is the delta from one side to the other. */ - GIT_DIFF_BINARY_DELTA -} git_diff_binary_t; - -/** The contents of one of the files in a binary diff. */ -typedef struct { - /** The type of binary data for this file. */ - git_diff_binary_t type; - - /** The binary data, deflated. */ - const char *data; - - /** The length of the binary data. */ - size_t datalen; - - /** The length of the binary data after inflation. */ - size_t inflatedlen; -} git_diff_binary_file; - -/** - * Structure describing the binary contents of a diff. - * - * A `binary` file / delta is a file (or pair) for which no text diffs - * should be generated. A diff can contain delta entries that are - * binary, but no diff content will be output for those files. There is - * a base heuristic for binary detection and you can further tune the - * behavior with git attributes or diff flags and option settings. - */ -typedef struct { - /** - * Whether there is data in this binary structure or not. - * - * If this is `1`, then this was produced and included binary content. - * If this is `0` then this was generated knowing only that a binary - * file changed but without providing the data, probably from a patch - * that said `Binary files a/file.txt and b/file.txt differ`. - */ - unsigned int contains_data; - git_diff_binary_file old_file; /**< The contents of the old file. */ - git_diff_binary_file new_file; /**< The contents of the new file. */ -} git_diff_binary; - -/** - * When iterating over a diff, callback that will be made for - * binary content within the diff. - * - * @param delta the delta - * @param binary the binary content - * @param payload the user-specified callback payload - * @return 0 or an error code - */ -typedef int GIT_CALLBACK(git_diff_binary_cb)( - const git_diff_delta *delta, - const git_diff_binary *binary, - void *payload); - -/** - * Structure describing a hunk of a diff. - * - * A `hunk` is a span of modified lines in a delta along with some stable - * surrounding context. You can configure the amount of context and other - * properties of how hunks are generated. Each hunk also comes with a - * header that described where it starts and ends in both the old and new - * versions in the delta. - */ -typedef struct { - int old_start; /**< Starting line number in old_file */ - int old_lines; /**< Number of lines in old_file */ - int new_start; /**< Starting line number in new_file */ - int new_lines; /**< Number of lines in new_file */ - size_t header_len; /**< Number of bytes in header text */ - char header[GIT_DIFF_HUNK_HEADER_SIZE]; /**< Header text, NUL-byte terminated */ -} git_diff_hunk; - -/** - * When iterating over a diff, callback that will be made per hunk. - * - * @param delta the delta - * @param hunk the hunk - * @param payload the user-specified callback payload - * @return 0 or an error code - */ -typedef int GIT_CALLBACK(git_diff_hunk_cb)( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - void *payload); - -/** - * Line origin constants. - * - * These values describe where a line came from and will be passed to - * the git_diff_line_cb when iterating over a diff. There are some - * special origin constants at the end that are used for the text - * output callbacks to demarcate lines that are actually part of - * the file or hunk headers. - */ -typedef enum { - /* These values will be sent to `git_diff_line_cb` along with the line */ - GIT_DIFF_LINE_CONTEXT = ' ', - GIT_DIFF_LINE_ADDITION = '+', - GIT_DIFF_LINE_DELETION = '-', - - GIT_DIFF_LINE_CONTEXT_EOFNL = '=', /**< Both files have no LF at end */ - GIT_DIFF_LINE_ADD_EOFNL = '>', /**< Old has no LF at end, new does */ - GIT_DIFF_LINE_DEL_EOFNL = '<', /**< Old has LF at end, new does not */ - - /* The following values will only be sent to a `git_diff_line_cb` when - * the content of a diff is being formatted through `git_diff_print`. - */ - GIT_DIFF_LINE_FILE_HDR = 'F', - GIT_DIFF_LINE_HUNK_HDR = 'H', - GIT_DIFF_LINE_BINARY = 'B' /**< For "Binary files x and y differ" */ -} git_diff_line_t; - -/** - * Structure describing a line (or data span) of a diff. - * - * A `line` is a range of characters inside a hunk. It could be a context - * line (i.e. in both old and new versions), an added line (i.e. only in - * the new version), or a removed line (i.e. only in the old version). - * Unfortunately, we don't know anything about the encoding of data in the - * file being diffed, so we cannot tell you much about the line content. - * Line data will not be NUL-byte terminated, however, because it will be - * just a span of bytes inside the larger file. - */ -typedef struct { - char origin; /**< A git_diff_line_t value */ - int old_lineno; /**< Line number in old file or -1 for added line */ - int new_lineno; /**< Line number in new file or -1 for deleted line */ - int num_lines; /**< Number of newline characters in content */ - size_t content_len; /**< Number of bytes of data */ - git_off_t content_offset; /**< Offset in the original file to the content */ - const char *content; /**< Pointer to diff text, not NUL-byte terminated */ -} git_diff_line; - -/** - * When iterating over a diff, callback that will be made per text diff - * line. In this context, the provided range will be NULL. - * - * When printing a diff, callback that will be made to output each line - * of text. This uses some extra GIT_DIFF_LINE_... constants for output - * of lines of file and hunk headers. - * - * @param delta the delta that contains the line - * @param hunk the hunk that contains the line - * @param line the line in the diff - * @param payload the user-specified callback payload - * @return 0 or an error code - */ -typedef int GIT_CALLBACK(git_diff_line_cb)( - const git_diff_delta *delta, /**< delta that contains this data */ - const git_diff_hunk *hunk, /**< hunk containing this data */ - const git_diff_line *line, /**< line data */ - void *payload); /**< user reference data */ - -/** - * Flags to control the behavior of diff rename/copy detection. - */ -typedef enum { - /** Obey `diff.renames`. Overridden by any other GIT_DIFF_FIND_... flag. */ - GIT_DIFF_FIND_BY_CONFIG = 0, - - /** Look for renames? (`--find-renames`) */ - GIT_DIFF_FIND_RENAMES = (1u << 0), - - /** Consider old side of MODIFIED for renames? (`--break-rewrites=N`) */ - GIT_DIFF_FIND_RENAMES_FROM_REWRITES = (1u << 1), - - /** Look for copies? (a la `--find-copies`). */ - GIT_DIFF_FIND_COPIES = (1u << 2), - - /** Consider UNMODIFIED as copy sources? (`--find-copies-harder`). - * - * For this to work correctly, use GIT_DIFF_INCLUDE_UNMODIFIED when - * the initial `git_diff` is being generated. - */ - GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED = (1u << 3), - - /** Mark significant rewrites for split (`--break-rewrites=/M`) */ - GIT_DIFF_FIND_REWRITES = (1u << 4), - /** Actually split large rewrites into delete/add pairs */ - GIT_DIFF_BREAK_REWRITES = (1u << 5), - /** Mark rewrites for split and break into delete/add pairs */ - GIT_DIFF_FIND_AND_BREAK_REWRITES = - (GIT_DIFF_FIND_REWRITES | GIT_DIFF_BREAK_REWRITES), - - /** Find renames/copies for UNTRACKED items in working directory. - * - * For this to work correctly, use GIT_DIFF_INCLUDE_UNTRACKED when the - * initial `git_diff` is being generated (and obviously the diff must - * be against the working directory for this to make sense). - */ - GIT_DIFF_FIND_FOR_UNTRACKED = (1u << 6), - - /** Turn on all finding features. */ - GIT_DIFF_FIND_ALL = (0x0ff), - - /** Measure similarity ignoring leading whitespace (default) */ - GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE = 0, - /** Measure similarity ignoring all whitespace */ - GIT_DIFF_FIND_IGNORE_WHITESPACE = (1u << 12), - /** Measure similarity including all data */ - GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE = (1u << 13), - /** Measure similarity only by comparing SHAs (fast and cheap) */ - GIT_DIFF_FIND_EXACT_MATCH_ONLY = (1u << 14), - - /** Do not break rewrites unless they contribute to a rename. - * - * Normally, GIT_DIFF_FIND_AND_BREAK_REWRITES will measure the self- - * similarity of modified files and split the ones that have changed a - * lot into a DELETE / ADD pair. Then the sides of that pair will be - * considered candidates for rename and copy detection. - * - * If you add this flag in and the split pair is *not* used for an - * actual rename or copy, then the modified record will be restored to - * a regular MODIFIED record instead of being split. - */ - GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY = (1u << 15), - - /** Remove any UNMODIFIED deltas after find_similar is done. - * - * Using GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED to emulate the - * --find-copies-harder behavior requires building a diff with the - * GIT_DIFF_INCLUDE_UNMODIFIED flag. If you do not want UNMODIFIED - * records in the final result, pass this flag to have them removed. - */ - GIT_DIFF_FIND_REMOVE_UNMODIFIED = (1u << 16) -} git_diff_find_t; - -/** - * Pluggable similarity metric - */ -typedef struct { - int GIT_CALLBACK(file_signature)( - void **out, const git_diff_file *file, - const char *fullpath, void *payload); - int GIT_CALLBACK(buffer_signature)( - void **out, const git_diff_file *file, - const char *buf, size_t buflen, void *payload); - void GIT_CALLBACK(free_signature)(void *sig, void *payload); - int GIT_CALLBACK(similarity)(int *score, void *siga, void *sigb, void *payload); - void *payload; -} git_diff_similarity_metric; - -/** - * Control behavior of rename and copy detection - * - * These options mostly mimic parameters that can be passed to git-diff. - */ -typedef struct { - unsigned int version; - - /** - * Combination of git_diff_find_t values (default GIT_DIFF_FIND_BY_CONFIG). - * NOTE: if you don't explicitly set this, `diff.renames` could be set - * to false, resulting in `git_diff_find_similar` doing nothing. - */ - uint32_t flags; - - /** - * Threshold above which similar files will be considered renames. - * This is equivalent to the -M option. Defaults to 50. - */ - uint16_t rename_threshold; - - /** - * Threshold below which similar files will be eligible to be a rename source. - * This is equivalent to the first part of the -B option. Defaults to 50. - */ - uint16_t rename_from_rewrite_threshold; - - /** - * Threshold above which similar files will be considered copies. - * This is equivalent to the -C option. Defaults to 50. - */ - uint16_t copy_threshold; - - /** - * Threshold below which similar files will be split into a delete/add pair. - * This is equivalent to the last part of the -B option. Defaults to 60. - */ - uint16_t break_rewrite_threshold; - - /** - * Maximum number of matches to consider for a particular file. - * - * This is a little different from the `-l` option from Git because we - * will still process up to this many matches before abandoning the search. - * Defaults to 1000. - */ - size_t rename_limit; - - /** - * The `metric` option allows you to plug in a custom similarity metric. - * - * Set it to NULL to use the default internal metric. - * - * The default metric is based on sampling hashes of ranges of data in - * the file, which is a pretty good similarity approximation that should - * work fairly well for both text and binary data while still being - * pretty fast with a fixed memory overhead. - */ - git_diff_similarity_metric *metric; -} git_diff_find_options; - -/** Current version for the `git_diff_find_options` structure */ -#define GIT_DIFF_FIND_OPTIONS_VERSION 1 - -/** Static constructor for `git_diff_find_options` */ -#define GIT_DIFF_FIND_OPTIONS_INIT {GIT_DIFF_FIND_OPTIONS_VERSION} - -/** - * Initialize git_diff_find_options structure - * - * Initializes a `git_diff_find_options` with default values. Equivalent to creating - * an instance with GIT_DIFF_FIND_OPTIONS_INIT. - * - * @param opts The `git_diff_find_options` struct to initialize. - * @param version The struct version; pass `GIT_DIFF_FIND_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_diff_find_options_init( - git_diff_find_options *opts, - unsigned int version); - -/** @name Diff Generator Functions - * - * These are the functions you would use to create (or destroy) a - * git_diff from various objects in a repository. - */ -/**@{*/ - -/** - * Deallocate a diff. - * - * @param diff The previously created diff; cannot be used after free. - */ -GIT_EXTERN(void) git_diff_free(git_diff *diff); - -/** - * Create a diff with the difference between two tree objects. - * - * This is equivalent to `git diff ` - * - * The first tree will be used for the "old_file" side of the delta and the - * second tree will be used for the "new_file" side of the delta. You can - * pass NULL to indicate an empty tree, although it is an error to pass - * NULL for both the `old_tree` and `new_tree`. - * - * @param diff Output pointer to a git_diff pointer to be allocated. - * @param repo The repository containing the trees. - * @param old_tree A git_tree object to diff from, or NULL for empty tree. - * @param new_tree A git_tree object to diff to, or NULL for empty tree. - * @param opts Structure with options to influence diff or NULL for defaults. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_diff_tree_to_tree( - git_diff **diff, - git_repository *repo, - git_tree *old_tree, - git_tree *new_tree, - const git_diff_options *opts); - -/** - * Create a diff between a tree and repository index. - * - * This is equivalent to `git diff --cached ` or if you pass - * the HEAD tree, then like `git diff --cached`. - * - * The tree you pass will be used for the "old_file" side of the delta, and - * the index will be used for the "new_file" side of the delta. - * - * If you pass NULL for the index, then the existing index of the `repo` - * will be used. In this case, the index will be refreshed from disk - * (if it has changed) before the diff is generated. - * - * @param diff Output pointer to a git_diff pointer to be allocated. - * @param repo The repository containing the tree and index. - * @param old_tree A git_tree object to diff from, or NULL for empty tree. - * @param index The index to diff with; repo index used if NULL. - * @param opts Structure with options to influence diff or NULL for defaults. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_diff_tree_to_index( - git_diff **diff, - git_repository *repo, - git_tree *old_tree, - git_index *index, - const git_diff_options *opts); - -/** - * Create a diff between the repository index and the workdir directory. - * - * This matches the `git diff` command. See the note below on - * `git_diff_tree_to_workdir` for a discussion of the difference between - * `git diff` and `git diff HEAD` and how to emulate a `git diff ` - * using libgit2. - * - * The index will be used for the "old_file" side of the delta, and the - * working directory will be used for the "new_file" side of the delta. - * - * If you pass NULL for the index, then the existing index of the `repo` - * will be used. In this case, the index will be refreshed from disk - * (if it has changed) before the diff is generated. - * - * @param diff Output pointer to a git_diff pointer to be allocated. - * @param repo The repository. - * @param index The index to diff from; repo index used if NULL. - * @param opts Structure with options to influence diff or NULL for defaults. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_diff_index_to_workdir( - git_diff **diff, - git_repository *repo, - git_index *index, - const git_diff_options *opts); - -/** - * Create a diff between a tree and the working directory. - * - * The tree you provide will be used for the "old_file" side of the delta, - * and the working directory will be used for the "new_file" side. - * - * This is not the same as `git diff ` or `git diff-index - * `. Those commands use information from the index, whereas this - * function strictly returns the differences between the tree and the files - * in the working directory, regardless of the state of the index. Use - * `git_diff_tree_to_workdir_with_index` to emulate those commands. - * - * To see difference between this and `git_diff_tree_to_workdir_with_index`, - * consider the example of a staged file deletion where the file has then - * been put back into the working dir and further modified. The - * tree-to-workdir diff for that file is 'modified', but `git diff` would - * show status 'deleted' since there is a staged delete. - * - * @param diff A pointer to a git_diff pointer that will be allocated. - * @param repo The repository containing the tree. - * @param old_tree A git_tree object to diff from, or NULL for empty tree. - * @param opts Structure with options to influence diff or NULL for defaults. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_diff_tree_to_workdir( - git_diff **diff, - git_repository *repo, - git_tree *old_tree, - const git_diff_options *opts); - -/** - * Create a diff between a tree and the working directory using index data - * to account for staged deletes, tracked files, etc. - * - * This emulates `git diff ` by diffing the tree to the index and - * the index to the working directory and blending the results into a - * single diff that includes staged deleted, etc. - * - * @param diff A pointer to a git_diff pointer that will be allocated. - * @param repo The repository containing the tree. - * @param old_tree A git_tree object to diff from, or NULL for empty tree. - * @param opts Structure with options to influence diff or NULL for defaults. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_diff_tree_to_workdir_with_index( - git_diff **diff, - git_repository *repo, - git_tree *old_tree, - const git_diff_options *opts); - -/** - * Create a diff with the difference between two index objects. - * - * The first index will be used for the "old_file" side of the delta and the - * second index will be used for the "new_file" side of the delta. - * - * @param diff Output pointer to a git_diff pointer to be allocated. - * @param repo The repository containing the indexes. - * @param old_index A git_index object to diff from. - * @param new_index A git_index object to diff to. - * @param opts Structure with options to influence diff or NULL for defaults. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_diff_index_to_index( - git_diff **diff, - git_repository *repo, - git_index *old_index, - git_index *new_index, - const git_diff_options *opts); - -/** - * Merge one diff into another. - * - * This merges items from the "from" list into the "onto" list. The - * resulting diff will have all items that appear in either list. - * If an item appears in both lists, then it will be "merged" to appear - * as if the old version was from the "onto" list and the new version - * is from the "from" list (with the exception that if the item has a - * pending DELETE in the middle, then it will show as deleted). - * - * @param onto Diff to merge into. - * @param from Diff to merge. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_diff_merge( - git_diff *onto, - const git_diff *from); - -/** - * Transform a diff marking file renames, copies, etc. - * - * This modifies a diff in place, replacing old entries that look - * like renames or copies with new entries reflecting those changes. - * This also will, if requested, break modified files into add/remove - * pairs if the amount of change is above a threshold. - * - * @param diff diff to run detection algorithms on - * @param options Control how detection should be run, NULL for defaults - * @return 0 on success, -1 on failure - */ -GIT_EXTERN(int) git_diff_find_similar( - git_diff *diff, - const git_diff_find_options *options); - -/**@}*/ - - -/** @name Diff Processor Functions - * - * These are the functions you apply to a diff to process it - * or read it in some way. - */ -/**@{*/ - -/** - * Query how many diff records are there in a diff. - * - * @param diff A git_diff generated by one of the above functions - * @return Count of number of deltas in the list - */ -GIT_EXTERN(size_t) git_diff_num_deltas(const git_diff *diff); - -/** - * Query how many diff deltas are there in a diff filtered by type. - * - * This works just like `git_diff_num_deltas()` with an extra parameter - * that is a `git_delta_t` and returns just the count of how many deltas - * match that particular type. - * - * @param diff A git_diff generated by one of the above functions - * @param type A git_delta_t value to filter the count - * @return Count of number of deltas matching delta_t type - */ -GIT_EXTERN(size_t) git_diff_num_deltas_of_type( - const git_diff *diff, git_delta_t type); - -/** - * Return the diff delta for an entry in the diff list. - * - * The `git_diff_delta` pointer points to internal data and you do not - * have to release it when you are done with it. It will go away when - * the * `git_diff` (or any associated `git_patch`) goes away. - * - * Note that the flags on the delta related to whether it has binary - * content or not may not be set if there are no attributes set for the - * file and there has been no reason to load the file data at this point. - * For now, if you need those flags to be up to date, your only option is - * to either use `git_diff_foreach` or create a `git_patch`. - * - * @param diff Diff list object - * @param idx Index into diff list - * @return Pointer to git_diff_delta (or NULL if `idx` out of range) - */ -GIT_EXTERN(const git_diff_delta *) git_diff_get_delta( - const git_diff *diff, size_t idx); - -/** - * Check if deltas are sorted case sensitively or insensitively. - * - * @param diff diff to check - * @return 0 if case sensitive, 1 if case is ignored - */ -GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff *diff); - -/** - * Loop over all deltas in a diff issuing callbacks. - * - * This will iterate through all of the files described in a diff. You - * should provide a file callback to learn about each file. - * - * The "hunk" and "line" callbacks are optional, and the text diff of the - * files will only be calculated if they are not NULL. Of course, these - * callbacks will not be invoked for binary files on the diff or for - * files whose only changed is a file mode change. - * - * Returning a non-zero value from any of the callbacks will terminate - * the iteration and return the value to the user. - * - * @param diff A git_diff generated by one of the above functions. - * @param file_cb Callback function to make per file in the diff. - * @param binary_cb Optional callback to make for binary files. - * @param hunk_cb Optional callback to make per hunk of text diff. This - * callback is called to describe a range of lines in the - * diff. It will not be issued for binary files. - * @param line_cb Optional callback to make per line of diff text. This - * same callback will be made for context lines, added, and - * removed lines, and even for a deleted trailing newline. - * @param payload Reference pointer that will be passed to your callbacks. - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_diff_foreach( - git_diff *diff, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb line_cb, - void *payload); - -/** - * Look up the single character abbreviation for a delta status code. - * - * When you run `git diff --name-status` it uses single letter codes in - * the output such as 'A' for added, 'D' for deleted, 'M' for modified, - * etc. This function converts a git_delta_t value into these letters for - * your own purposes. GIT_DELTA_UNTRACKED will return a space (i.e. ' '). - * - * @param status The git_delta_t value to look up - * @return The single character label for that code - */ -GIT_EXTERN(char) git_diff_status_char(git_delta_t status); - -/** - * Possible output formats for diff data - */ -typedef enum { - GIT_DIFF_FORMAT_PATCH = 1u, /**< full git diff */ - GIT_DIFF_FORMAT_PATCH_HEADER = 2u, /**< just the file headers of patch */ - GIT_DIFF_FORMAT_RAW = 3u, /**< like git diff --raw */ - GIT_DIFF_FORMAT_NAME_ONLY = 4u, /**< like git diff --name-only */ - GIT_DIFF_FORMAT_NAME_STATUS = 5u, /**< like git diff --name-status */ - GIT_DIFF_FORMAT_PATCH_ID = 6u /**< git diff as used by git patch-id */ -} git_diff_format_t; - -/** - * Iterate over a diff generating formatted text output. - * - * Returning a non-zero value from the callbacks will terminate the - * iteration and return the non-zero value to the caller. - * - * @param diff A git_diff generated by one of the above functions. - * @param format A git_diff_format_t value to pick the text format. - * @param print_cb Callback to make per line of diff text. - * @param payload Reference pointer that will be passed to your callback. - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_diff_print( - git_diff *diff, - git_diff_format_t format, - git_diff_line_cb print_cb, - void *payload); - -/** - * Produce the complete formatted text output from a diff into a - * buffer. - * - * @param out A pointer to a user-allocated git_buf that will - * contain the diff text - * @param diff A git_diff generated by one of the above functions. - * @param format A git_diff_format_t value to pick the text format. - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_diff_to_buf( - git_buf *out, - git_diff *diff, - git_diff_format_t format); - -/**@}*/ - -/* - * Low-level file comparison, invoking callbacks per difference. - */ - -/** - * Directly run a diff on two blobs. - * - * Compared to a file, a blob lacks some contextual information. As such, - * the `git_diff_file` given to the callback will have some fake data; i.e. - * `mode` will be 0 and `path` will be NULL. - * - * NULL is allowed for either `old_blob` or `new_blob` and will be treated - * as an empty blob, with the `oid` set to NULL in the `git_diff_file` data. - * Passing NULL for both blobs is a noop; no callbacks will be made at all. - * - * We do run a binary content check on the blob content and if either blob - * looks like binary data, the `git_diff_delta` binary attribute will be set - * to 1 and no call to the hunk_cb nor line_cb will be made (unless you pass - * `GIT_DIFF_FORCE_TEXT` of course). - * - * @param old_blob Blob for old side of diff, or NULL for empty blob - * @param old_as_path Treat old blob as if it had this filename; can be NULL - * @param new_blob Blob for new side of diff, or NULL for empty blob - * @param new_as_path Treat new blob as if it had this filename; can be NULL - * @param options Options for diff, or NULL for default options - * @param file_cb Callback for "file"; made once if there is a diff; can be NULL - * @param binary_cb Callback for binary files; can be NULL - * @param hunk_cb Callback for each hunk in diff; can be NULL - * @param line_cb Callback for each line in diff; can be NULL - * @param payload Payload passed to each callback function - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_diff_blobs( - const git_blob *old_blob, - const char *old_as_path, - const git_blob *new_blob, - const char *new_as_path, - const git_diff_options *options, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb line_cb, - void *payload); - -/** - * Directly run a diff between a blob and a buffer. - * - * As with `git_diff_blobs`, comparing a blob and buffer lacks some context, - * so the `git_diff_file` parameters to the callbacks will be faked a la the - * rules for `git_diff_blobs()`. - * - * Passing NULL for `old_blob` will be treated as an empty blob (i.e. the - * `file_cb` will be invoked with GIT_DELTA_ADDED and the diff will be the - * entire content of the buffer added). Passing NULL to the buffer will do - * the reverse, with GIT_DELTA_REMOVED and blob content removed. - * - * @param old_blob Blob for old side of diff, or NULL for empty blob - * @param old_as_path Treat old blob as if it had this filename; can be NULL - * @param buffer Raw data for new side of diff, or NULL for empty - * @param buffer_len Length of raw data for new side of diff - * @param buffer_as_path Treat buffer as if it had this filename; can be NULL - * @param options Options for diff, or NULL for default options - * @param file_cb Callback for "file"; made once if there is a diff; can be NULL - * @param binary_cb Callback for binary files; can be NULL - * @param hunk_cb Callback for each hunk in diff; can be NULL - * @param line_cb Callback for each line in diff; can be NULL - * @param payload Payload passed to each callback function - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_diff_blob_to_buffer( - const git_blob *old_blob, - const char *old_as_path, - const char *buffer, - size_t buffer_len, - const char *buffer_as_path, - const git_diff_options *options, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb line_cb, - void *payload); - -/** - * Directly run a diff between two buffers. - * - * Even more than with `git_diff_blobs`, comparing two buffer lacks - * context, so the `git_diff_file` parameters to the callbacks will be - * faked a la the rules for `git_diff_blobs()`. - * - * @param old_buffer Raw data for old side of diff, or NULL for empty - * @param old_len Length of the raw data for old side of the diff - * @param old_as_path Treat old buffer as if it had this filename; can be NULL - * @param new_buffer Raw data for new side of diff, or NULL for empty - * @param new_len Length of raw data for new side of diff - * @param new_as_path Treat buffer as if it had this filename; can be NULL - * @param options Options for diff, or NULL for default options - * @param file_cb Callback for "file"; made once if there is a diff; can be NULL - * @param binary_cb Callback for binary files; can be NULL - * @param hunk_cb Callback for each hunk in diff; can be NULL - * @param line_cb Callback for each line in diff; can be NULL - * @param payload Payload passed to each callback function - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_diff_buffers( - const void *old_buffer, - size_t old_len, - const char *old_as_path, - const void *new_buffer, - size_t new_len, - const char *new_as_path, - const git_diff_options *options, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb line_cb, - void *payload); - -/* Patch file parsing. */ - -/** - * Options for parsing a diff / patch file. - */ -typedef struct { - unsigned int version; - git_oid_t oid_type; -} git_diff_parse_options; - -/** The current version of the diff parse options structure */ -#define GIT_DIFF_PARSE_OPTIONS_VERSION 1 - -/** Stack initializer for diff parse options. Alternatively use - * `git_diff_parse_options_init` programmatic initialization. - */ -#define GIT_DIFF_PARSE_OPTIONS_INIT \ - { GIT_DIFF_PARSE_OPTIONS_VERSION, GIT_OID_DEFAULT } - -/** - * Read the contents of a git patch file into a `git_diff` object. - * - * The diff object produced is similar to the one that would be - * produced if you actually produced it computationally by comparing - * two trees, however there may be subtle differences. For example, - * a patch file likely contains abbreviated object IDs, so the - * object IDs in a `git_diff_delta` produced by this function will - * also be abbreviated. - * - * This function will only read patch files created by a git - * implementation, it will not read unified diffs produced by - * the `diff` program, nor any other types of patch files. - * - * @param out A pointer to a git_diff pointer that will be allocated. - * @param content The contents of a patch file - * @param content_len The length of the patch file contents - * @return 0 or an error code - */ -GIT_EXTERN(int) git_diff_from_buffer( - git_diff **out, - const char *content, - size_t content_len -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_diff_parse_options *opts -#endif - ); - -/** - * This is an opaque structure which is allocated by `git_diff_get_stats`. - * You are responsible for releasing the object memory when done, using the - * `git_diff_stats_free()` function. - */ -typedef struct git_diff_stats git_diff_stats; - -/** - * Formatting options for diff stats - */ -typedef enum { - /** No stats*/ - GIT_DIFF_STATS_NONE = 0, - - /** Full statistics, equivalent of `--stat` */ - GIT_DIFF_STATS_FULL = (1u << 0), - - /** Short statistics, equivalent of `--shortstat` */ - GIT_DIFF_STATS_SHORT = (1u << 1), - - /** Number statistics, equivalent of `--numstat` */ - GIT_DIFF_STATS_NUMBER = (1u << 2), - - /** Extended header information such as creations, renames and mode changes, equivalent of `--summary` */ - GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3) -} git_diff_stats_format_t; - -/** - * Accumulate diff statistics for all patches. - * - * @param out Structure containing the diff statistics. - * @param diff A git_diff generated by one of the above functions. - * @return 0 on success; non-zero on error - */ -GIT_EXTERN(int) git_diff_get_stats( - git_diff_stats **out, - git_diff *diff); - -/** - * Get the total number of files changed in a diff - * - * @param stats A `git_diff_stats` generated by one of the above functions. - * @return total number of files changed in the diff - */ -GIT_EXTERN(size_t) git_diff_stats_files_changed( - const git_diff_stats *stats); - -/** - * Get the total number of insertions in a diff - * - * @param stats A `git_diff_stats` generated by one of the above functions. - * @return total number of insertions in the diff - */ -GIT_EXTERN(size_t) git_diff_stats_insertions( - const git_diff_stats *stats); - -/** - * Get the total number of deletions in a diff - * - * @param stats A `git_diff_stats` generated by one of the above functions. - * @return total number of deletions in the diff - */ -GIT_EXTERN(size_t) git_diff_stats_deletions( - const git_diff_stats *stats); - -/** - * Print diff statistics to a `git_buf`. - * - * @param out buffer to store the formatted diff statistics in. - * @param stats A `git_diff_stats` generated by one of the above functions. - * @param format Formatting option. - * @param width Target width for output (only affects GIT_DIFF_STATS_FULL) - * @return 0 on success; non-zero on error - */ -GIT_EXTERN(int) git_diff_stats_to_buf( - git_buf *out, - const git_diff_stats *stats, - git_diff_stats_format_t format, - size_t width); - -/** - * Deallocate a `git_diff_stats`. - * - * @param stats The previously created statistics object; - * cannot be used after free. - */ -GIT_EXTERN(void) git_diff_stats_free(git_diff_stats *stats); - -/** - * Patch ID options structure - * - * Initialize with `GIT_PATCHID_OPTIONS_INIT`. Alternatively, you can - * use `git_diff_patchid_options_init`. - * - */ -typedef struct git_diff_patchid_options { - unsigned int version; -} git_diff_patchid_options; - -/** Current version for the `git_diff_patchid_options` structure */ -#define GIT_DIFF_PATCHID_OPTIONS_VERSION 1 - -/** Static constructor for `git_diff_patchid_options` */ -#define GIT_DIFF_PATCHID_OPTIONS_INIT { GIT_DIFF_PATCHID_OPTIONS_VERSION } - -/** - * Initialize git_diff_patchid_options structure - * - * Initializes a `git_diff_patchid_options` with default values. Equivalent to - * creating an instance with `GIT_DIFF_PATCHID_OPTIONS_INIT`. - * - * @param opts The `git_diff_patchid_options` struct to initialize. - * @param version The struct version; pass `GIT_DIFF_PATCHID_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_diff_patchid_options_init( - git_diff_patchid_options *opts, - unsigned int version); - -/** - * Calculate the patch ID for the given patch. - * - * Calculate a stable patch ID for the given patch by summing the - * hash of the file diffs, ignoring whitespace and line numbers. - * This can be used to derive whether two diffs are the same with - * a high probability. - * - * Currently, this function only calculates stable patch IDs, as - * defined in git-patch-id(1), and should in fact generate the - * same IDs as the upstream git project does. - * - * @param out Pointer where the calculated patch ID should be stored - * @param diff The diff to calculate the ID for - * @param opts Options for how to calculate the patch ID. This is - * intended for future changes, as currently no options are - * available. - * @return 0 on success, an error code otherwise. - */ -GIT_EXTERN(int) git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/email.h b/vendor/libgit2-sys/libgit2/include/git2/email.h deleted file mode 100644 index ad37e42..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/email.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_email_h__ -#define INCLUDE_git_email_h__ - -#include "common.h" -#include "diff.h" - -/** - * @file git2/email.h - * @brief Produce email-ready patches - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Formatting options for diff e-mail generation - */ -typedef enum { - /** Normal patch, the default */ - GIT_EMAIL_CREATE_DEFAULT = 0, - - /** Do not include patch numbers in the subject prefix. */ - GIT_EMAIL_CREATE_OMIT_NUMBERS = (1u << 0), - - /** - * Include numbers in the subject prefix even when the - * patch is for a single commit (1/1). - */ - GIT_EMAIL_CREATE_ALWAYS_NUMBER = (1u << 1), - - /** Do not perform rename or similarity detection. */ - GIT_EMAIL_CREATE_NO_RENAMES = (1u << 2) -} git_email_create_flags_t; - -/** - * Options for controlling the formatting of the generated e-mail. - */ -typedef struct { - unsigned int version; - - /** see `git_email_create_flags_t` above */ - uint32_t flags; - - /** Options to use when creating diffs */ - git_diff_options diff_opts; - - /** Options for finding similarities within diffs */ - git_diff_find_options diff_find_opts; - - /** - * The subject prefix, by default "PATCH". If set to an empty - * string ("") then only the patch numbers will be shown in the - * prefix. If the subject_prefix is empty and patch numbers - * are not being shown, the prefix will be omitted entirely. - */ - const char *subject_prefix; - - /** - * The starting patch number; this cannot be 0. By default, - * this is 1. - */ - size_t start_number; - - /** The "re-roll" number. By default, there is no re-roll. */ - size_t reroll_number; -} git_email_create_options; - -/** Current version for the `git_email_create_options` structure */ -#define GIT_EMAIL_CREATE_OPTIONS_VERSION 1 - -/** Static constructor for `git_email_create_options` - * - * By default, our options include rename detection and binary - * diffs to match `git format-patch`. - */ -#define GIT_EMAIL_CREATE_OPTIONS_INIT \ -{ \ - GIT_EMAIL_CREATE_OPTIONS_VERSION, \ - GIT_EMAIL_CREATE_DEFAULT, \ - { GIT_DIFF_OPTIONS_VERSION, GIT_DIFF_SHOW_BINARY, GIT_SUBMODULE_IGNORE_UNSPECIFIED, {NULL,0}, NULL, NULL, NULL, 3 }, \ - GIT_DIFF_FIND_OPTIONS_INIT \ -} - -/** - * Create a diff for a commit in mbox format for sending via email. - * The commit must not be a merge commit. - * - * @param out buffer to store the e-mail patch in - * @param commit commit to create a patch for - * @param opts email creation options - * @return 0 or an error code - */ -GIT_EXTERN(int) git_email_create_from_commit( - git_buf *out, - git_commit *commit, - const git_email_create_options *opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/errors.h b/vendor/libgit2-sys/libgit2/include/git2/errors.h deleted file mode 100644 index 1141390..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/errors.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_errors_h__ -#define INCLUDE_git_errors_h__ - -#include "common.h" - -/** - * @file git2/errors.h - * @brief Error handling routines and variables - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Generic return codes */ -typedef enum { - /** - * No error occurred; the call was successful. - */ - GIT_OK = 0, - - /** - * An error occurred; call `git_error_last` for more information. - */ - GIT_ERROR = -1, - - GIT_ENOTFOUND = -3, /**< Requested object could not be found. */ - GIT_EEXISTS = -4, /**< Object exists preventing operation. */ - GIT_EAMBIGUOUS = -5, /**< More than one object matches. */ - GIT_EBUFS = -6, /**< Output buffer too short to hold data. */ - - /** - * GIT_EUSER is a special error that is never generated by libgit2 - * code. You can return it from a callback (e.g to stop an iteration) - * to know that it was generated by the callback and not by libgit2. - */ - GIT_EUSER = -7, - - GIT_EBAREREPO = -8, /**< Operation not allowed on bare repository. */ - GIT_EUNBORNBRANCH = -9, /**< HEAD refers to branch with no commits. */ - GIT_EUNMERGED = -10, /**< Merge in progress prevented operation */ - GIT_ENONFASTFORWARD = -11, /**< Reference was not fast-forwardable */ - GIT_EINVALIDSPEC = -12, /**< Name/ref spec was not in a valid format */ - GIT_ECONFLICT = -13, /**< Checkout conflicts prevented operation */ - GIT_ELOCKED = -14, /**< Lock file prevented operation */ - GIT_EMODIFIED = -15, /**< Reference value does not match expected */ - GIT_EAUTH = -16, /**< Authentication error */ - GIT_ECERTIFICATE = -17, /**< Server certificate is invalid */ - GIT_EAPPLIED = -18, /**< Patch/merge has already been applied */ - GIT_EPEEL = -19, /**< The requested peel operation is not possible */ - GIT_EEOF = -20, /**< Unexpected EOF */ - GIT_EINVALID = -21, /**< Invalid operation or input */ - GIT_EUNCOMMITTED = -22, /**< Uncommitted changes in index prevented operation */ - GIT_EDIRECTORY = -23, /**< The operation is not valid for a directory */ - GIT_EMERGECONFLICT = -24, /**< A merge conflict exists and cannot continue */ - - GIT_PASSTHROUGH = -30, /**< A user-configured callback refused to act */ - GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */ - GIT_RETRY = -32, /**< Internal only */ - GIT_EMISMATCH = -33, /**< Hashsum mismatch in object */ - GIT_EINDEXDIRTY = -34, /**< Unsaved changes in the index would be overwritten */ - GIT_EAPPLYFAIL = -35, /**< Patch application failed */ - GIT_EOWNER = -36, /**< The object is not owned by the current user */ - GIT_TIMEOUT = -37, /**< The operation timed out */ - GIT_EUNCHANGED = -38, /**< There were no changes */ - GIT_ENOTSUPPORTED = -39, /**< An option is not supported */ - GIT_EREADONLY = -40 /**< The subject is read-only */ -} git_error_code; - -/** - * Error classes are the category of error. They reflect the area of the - * code where an error occurred. - */ -typedef enum { - GIT_ERROR_NONE = 0, - GIT_ERROR_NOMEMORY, - GIT_ERROR_OS, - GIT_ERROR_INVALID, - GIT_ERROR_REFERENCE, - GIT_ERROR_ZLIB, - GIT_ERROR_REPOSITORY, - GIT_ERROR_CONFIG, - GIT_ERROR_REGEX, - GIT_ERROR_ODB, - GIT_ERROR_INDEX, - GIT_ERROR_OBJECT, - GIT_ERROR_NET, - GIT_ERROR_TAG, - GIT_ERROR_TREE, - GIT_ERROR_INDEXER, - GIT_ERROR_SSL, - GIT_ERROR_SUBMODULE, - GIT_ERROR_THREAD, - GIT_ERROR_STASH, - GIT_ERROR_CHECKOUT, - GIT_ERROR_FETCHHEAD, - GIT_ERROR_MERGE, - GIT_ERROR_SSH, - GIT_ERROR_FILTER, - GIT_ERROR_REVERT, - GIT_ERROR_CALLBACK, - GIT_ERROR_CHERRYPICK, - GIT_ERROR_DESCRIBE, - GIT_ERROR_REBASE, - GIT_ERROR_FILESYSTEM, - GIT_ERROR_PATCH, - GIT_ERROR_WORKTREE, - GIT_ERROR_SHA, - GIT_ERROR_HTTP, - GIT_ERROR_INTERNAL, - GIT_ERROR_GRAFTS -} git_error_t; - -/** - * Structure to store extra details of the last error that occurred. - * - * This is kept on a per-thread basis if GIT_THREADS was defined when the - * library was build, otherwise one is kept globally for the library - */ -typedef struct { - char *message; /**< The error message for the last error. */ - int klass; /**< The category of the last error. @type git_error_t */ -} git_error; - -/** - * Return the last `git_error` object that was generated for the - * current thread. - * - * This function will never return NULL. - * - * Callers should not rely on this to determine whether an error has - * occurred. For error checking, callers should examine the return - * codes of libgit2 functions. - * - * This call can only reliably report error messages when an error - * has occurred. (It may contain stale information if it is called - * after a different function that succeeds.) - * - * The memory for this object is managed by libgit2. It should not - * be freed. - * - * @return A pointer to a `git_error` object that describes the error. - */ -GIT_EXTERN(const git_error *) git_error_last(void); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/experimental.h b/vendor/libgit2-sys/libgit2/include/git2/experimental.h deleted file mode 100644 index 06435f9..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/experimental.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_experimental_h__ -#define INCLUDE_experimental_h__ - -/* - * This file exists to support users who build libgit2 with a bespoke - * build system and do not use our cmake configuration. Normally, cmake - * will create `experimental.h` from the `experimental.h.in` file and - * will include the generated file instead of this one. For non-cmake - * users, we bundle this `experimental.h` file which will be used - * instead. - */ - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/filter.h b/vendor/libgit2-sys/libgit2/include/git2/filter.h deleted file mode 100644 index cf6c5f5..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/filter.h +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_filter_h__ -#define INCLUDE_git_filter_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "buffer.h" - -/** - * @file git2/filter.h - * @brief Filters modify files during checkout or commit - * @ingroup Git - * - * During checkout, filters update a file from a "canonical" state to - * a format appropriate for the local filesystem; during commit, filters - * produce the canonical state. For example, on Windows, the line ending - * filters _may_ take a canonical state (with Unix-style newlines) in - * the repository, and place the contents on-disk with Windows-style - * `\r\n` line endings. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Filters are applied in one of two directions: smudging - which is - * exporting a file from the Git object database to the working directory, - * and cleaning - which is importing a file from the working directory to - * the Git object database. These values control which direction of - * change is being applied. - */ -typedef enum { - GIT_FILTER_TO_WORKTREE = 0, - GIT_FILTER_SMUDGE = GIT_FILTER_TO_WORKTREE, - GIT_FILTER_TO_ODB = 1, - GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB -} git_filter_mode_t; - -/** - * Filter option flags. - */ -typedef enum { - GIT_FILTER_DEFAULT = 0u, - - /** Don't error for `safecrlf` violations, allow them to continue. */ - GIT_FILTER_ALLOW_UNSAFE = (1u << 0), - - /** Don't load `/etc/gitattributes` (or the system equivalent) */ - GIT_FILTER_NO_SYSTEM_ATTRIBUTES = (1u << 1), - - /** Load attributes from `.gitattributes` in the root of HEAD */ - GIT_FILTER_ATTRIBUTES_FROM_HEAD = (1u << 2), - - /** - * Load attributes from `.gitattributes` in a given commit. - * This can only be specified in a `git_filter_options`. - */ - GIT_FILTER_ATTRIBUTES_FROM_COMMIT = (1u << 3) -} git_filter_flag_t; - -/** - * Filtering options - */ -typedef struct { - unsigned int version; - - /** See `git_filter_flag_t` above */ - uint32_t flags; - -#ifdef GIT_DEPRECATE_HARD - void *reserved; -#else - git_oid *commit_id; -#endif - - /** - * The commit to load attributes from, when - * `GIT_FILTER_ATTRIBUTES_FROM_COMMIT` is specified. - */ - git_oid attr_commit_id; -} git_filter_options; - -/** Current version for the `git_filter_options` structure */ -#define GIT_FILTER_OPTIONS_VERSION 1 - -/** Static constructor for `git_filter_options` */ -#define GIT_FILTER_OPTIONS_INIT {GIT_FILTER_OPTIONS_VERSION} - -/** - * A filter that can transform file data - * - * This represents a filter that can be used to transform or even replace - * file data. Libgit2 includes one built in filter and it is possible to - * write your own (see git2/sys/filter.h for information on that). - * - * The two builtin filters are: - * - * * "crlf" which uses the complex rules with the "text", "eol", and - * "crlf" file attributes to decide how to convert between LF and CRLF - * line endings - * * "ident" which replaces "$Id$" in a blob with "$Id: $" upon - * checkout and replaced "$Id: $" with "$Id$" on checkin. - */ -typedef struct git_filter git_filter; - -/** - * List of filters to be applied - * - * This represents a list of filters to be applied to a file / blob. You - * can build the list with one call, apply it with another, and dispose it - * with a third. In typical usage, there are not many occasions where a - * git_filter_list is needed directly since the library will generally - * handle conversions for you, but it can be convenient to be able to - * build and apply the list sometimes. - */ -typedef struct git_filter_list git_filter_list; - -/** - * Load the filter list for a given path. - * - * This will return 0 (success) but set the output git_filter_list to NULL - * if no filters are requested for the given file. - * - * @param filters Output newly created git_filter_list (or NULL) - * @param repo Repository object that contains `path` - * @param blob The blob to which the filter will be applied (if known) - * @param path Relative path of the file to be filtered - * @param mode Filtering direction (WT->ODB or ODB->WT) - * @param flags Combination of `git_filter_flag_t` flags - * @return 0 on success (which could still return NULL if no filters are - * needed for the requested file), <0 on error - */ -GIT_EXTERN(int) git_filter_list_load( - git_filter_list **filters, - git_repository *repo, - git_blob *blob, /* can be NULL */ - const char *path, - git_filter_mode_t mode, - uint32_t flags); - -/** - * Load the filter list for a given path. - * - * This will return 0 (success) but set the output git_filter_list to NULL - * if no filters are requested for the given file. - * - * @param filters Output newly created git_filter_list (or NULL) - * @param repo Repository object that contains `path` - * @param blob The blob to which the filter will be applied (if known) - * @param path Relative path of the file to be filtered - * @param mode Filtering direction (WT->ODB or ODB->WT) - * @param opts The `git_filter_options` to use when loading filters - * @return 0 on success (which could still return NULL if no filters are - * needed for the requested file), <0 on error - */ -GIT_EXTERN(int) git_filter_list_load_ext( - git_filter_list **filters, - git_repository *repo, - git_blob *blob, - const char *path, - git_filter_mode_t mode, - git_filter_options *opts); - -/** - * Query the filter list to see if a given filter (by name) will run. - * The built-in filters "crlf" and "ident" can be queried, otherwise this - * is the name of the filter specified by the filter attribute. - * - * This will return 0 if the given filter is not in the list, or 1 if - * the filter will be applied. - * - * @param filters A loaded git_filter_list (or NULL) - * @param name The name of the filter to query - * @return 1 if the filter is in the list, 0 otherwise - */ -GIT_EXTERN(int) git_filter_list_contains( - git_filter_list *filters, - const char *name); - -/** - * Apply filter list to a data buffer. - * - * @param out Buffer to store the result of the filtering - * @param filters A loaded git_filter_list (or NULL) - * @param in Buffer containing the data to filter - * @param in_len The length of the input buffer - * @return 0 on success, an error code otherwise - */ -GIT_EXTERN(int) git_filter_list_apply_to_buffer( - git_buf *out, - git_filter_list *filters, - const char *in, - size_t in_len); - -/** - * Apply a filter list to the contents of a file on disk - * - * @param out buffer into which to store the filtered file - * @param filters the list of filters to apply - * @param repo the repository in which to perform the filtering - * @param path the path of the file to filter, a relative path will be - * taken as relative to the workdir - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_filter_list_apply_to_file( - git_buf *out, - git_filter_list *filters, - git_repository *repo, - const char *path); - -/** - * Apply a filter list to the contents of a blob - * - * @param out buffer into which to store the filtered file - * @param filters the list of filters to apply - * @param blob the blob to filter - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_filter_list_apply_to_blob( - git_buf *out, - git_filter_list *filters, - git_blob *blob); - -/** - * Apply a filter list to an arbitrary buffer as a stream - * - * @param filters the list of filters to apply - * @param buffer the buffer to filter - * @param len the size of the buffer - * @param target the stream into which the data will be written - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_filter_list_stream_buffer( - git_filter_list *filters, - const char *buffer, - size_t len, - git_writestream *target); - -/** - * Apply a filter list to a file as a stream - * - * @param filters the list of filters to apply - * @param repo the repository in which to perform the filtering - * @param path the path of the file to filter, a relative path will be - * taken as relative to the workdir - * @param target the stream into which the data will be written - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_filter_list_stream_file( - git_filter_list *filters, - git_repository *repo, - const char *path, - git_writestream *target); - -/** - * Apply a filter list to a blob as a stream - * - * @param filters the list of filters to apply - * @param blob the blob to filter - * @param target the stream into which the data will be written - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_filter_list_stream_blob( - git_filter_list *filters, - git_blob *blob, - git_writestream *target); - -/** - * Free a git_filter_list - * - * @param filters A git_filter_list created by `git_filter_list_load` - */ -GIT_EXTERN(void) git_filter_list_free(git_filter_list *filters); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/global.h b/vendor/libgit2-sys/libgit2/include/git2/global.h deleted file mode 100644 index f15eb2d..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/global.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_global_h__ -#define INCLUDE_git_global_h__ - -#include "common.h" - -/** - * @file git2/global.h - * @brief libgit2 library initializer and shutdown functionality - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Init the global state - * - * This function must be called before any other libgit2 function in - * order to set up global state and threading. - * - * This function may be called multiple times - it will return the number - * of times the initialization has been called (including this one) that have - * not subsequently been shutdown. - * - * @return the number of initializations of the library, or an error code. - */ -GIT_EXTERN(int) git_libgit2_init(void); - -/** - * Shutdown the global state - * - * Clean up the global state and threading context after calling it as - * many times as `git_libgit2_init()` was called - it will return the - * number of remainining initializations that have not been shutdown - * (after this one). - * - * @return the number of remaining initializations of the library, or an - * error code. - */ -GIT_EXTERN(int) git_libgit2_shutdown(void); - -/** @} */ -GIT_END_DECL - -#endif - diff --git a/vendor/libgit2-sys/libgit2/include/git2/graph.h b/vendor/libgit2-sys/libgit2/include/git2/graph.h deleted file mode 100644 index 1792020..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/graph.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_graph_h__ -#define INCLUDE_git_graph_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/graph.h - * @brief Graph traversal routines - * @defgroup git_revwalk Git graph traversal routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Count the number of unique commits between two commit objects - * - * There is no need for branches containing the commits to have any - * upstream relationship, but it helps to think of one as a branch and - * the other as its upstream, the `ahead` and `behind` values will be - * what git would report for the branches. - * - * @param ahead number of unique from commits in `upstream` - * @param behind number of unique from commits in `local` - * @param repo the repository where the commits exist - * @param local the commit for local - * @param upstream the commit for upstream - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_graph_ahead_behind(size_t *ahead, size_t *behind, git_repository *repo, const git_oid *local, const git_oid *upstream); - - -/** - * Determine if a commit is the descendant of another commit. - * - * Note that a commit is not considered a descendant of itself, in contrast - * to `git merge-base --is-ancestor`. - * - * @param repo the repository where the commits exist - * @param commit a previously loaded commit - * @param ancestor a potential ancestor commit - * @return 1 if the given commit is a descendant of the potential ancestor, - * 0 if not, error code otherwise. - */ -GIT_EXTERN(int) git_graph_descendant_of( - git_repository *repo, - const git_oid *commit, - const git_oid *ancestor); - -/** - * Determine if a commit is reachable from any of a list of commits by - * following parent edges. - * - * @param repo the repository where the commits exist - * @param commit a previously loaded commit - * @param descendant_array oids of the commits - * @param length the number of commits in the provided `descendant_array` - * @return 1 if the given commit is an ancestor of any of the given potential - * descendants, 0 if not, error code otherwise. - */ -GIT_EXTERN(int) git_graph_reachable_from_any( - git_repository *repo, - const git_oid *commit, - const git_oid descendant_array[], - size_t length); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/ignore.h b/vendor/libgit2-sys/libgit2/include/git2/ignore.h deleted file mode 100644 index 730f221..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/ignore.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_ignore_h__ -#define INCLUDE_git_ignore_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/ignore.h - * @brief Ignore particular untracked files - * @ingroup Git - * @{ - * - * When examining the repository status, git can optionally ignore - * specified untracked files. - */ -GIT_BEGIN_DECL - -/** - * Add ignore rules for a repository. - * - * Excludesfile rules (i.e. .gitignore rules) are generally read from - * .gitignore files in the repository tree or from a shared system file - * only if a "core.excludesfile" config value is set. The library also - * keeps a set of per-repository internal ignores that can be configured - * in-memory and will not persist. This function allows you to add to - * that internal rules list. - * - * Example usage: - * - * error = git_ignore_add_rule(myrepo, "*.c\ndir/\nFile with space\n"); - * - * This would add three rules to the ignores. - * - * @param repo The repository to add ignore rules to. - * @param rules Text of rules, the contents to add on a .gitignore file. - * It is okay to have multiple rules in the text; if so, - * each rule should be terminated with a newline. - * @return 0 on success - */ -GIT_EXTERN(int) git_ignore_add_rule( - git_repository *repo, - const char *rules); - -/** - * Clear ignore rules that were explicitly added. - * - * Resets to the default internal ignore rules. This will not turn off - * rules in .gitignore files that actually exist in the filesystem. - * - * The default internal ignores ignore ".", ".." and ".git" entries. - * - * @param repo The repository to remove ignore rules from. - * @return 0 on success - */ -GIT_EXTERN(int) git_ignore_clear_internal_rules( - git_repository *repo); - -/** - * Test if the ignore rules apply to a given path. - * - * This function checks the ignore rules to see if they would apply to the - * given file. This indicates if the file would be ignored regardless of - * whether the file is already in the index or committed to the repository. - * - * One way to think of this is if you were to do "git check-ignore --no-index" - * on the given file, would it be shown or not? - * - * @param ignored boolean returning 0 if the file is not ignored, 1 if it is - * @param repo a repository object - * @param path the file to check ignores for, relative to the repo's workdir. - * @return 0 if ignore rules could be processed for the file (regardless - * of whether it exists or not), or an error < 0 if they could not. - */ -GIT_EXTERN(int) git_ignore_path_is_ignored( - int *ignored, - git_repository *repo, - const char *path); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/index.h b/vendor/libgit2-sys/libgit2/include/git2/index.h deleted file mode 100644 index 9ff2442..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/index.h +++ /dev/null @@ -1,933 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_index_h__ -#define INCLUDE_git_index_h__ - -#include "common.h" -#include "indexer.h" -#include "types.h" -#include "oid.h" -#include "strarray.h" - -/** - * @file git2/index.h - * @brief Index (aka "cache" aka "staging area") - * @defgroup git_index Git index parsing and manipulation routines - * @ingroup Git - * - * The index (or "cache", or "staging area") is the contents of the - * next commit. In addition, the index stores other data, such as - * conflicts that occurred during the last merge operation, and - * the "treecache" to speed up various on-disk operations. - * @{ - */ -GIT_BEGIN_DECL - -/** Time structure used in a git index entry */ -typedef struct { - int32_t seconds; - /* nsec should not be stored as time_t compatible */ - uint32_t nanoseconds; -} git_index_time; - -/** - * In-memory representation of a file entry in the index. - * - * This is a public structure that represents a file entry in the index. - * The meaning of the fields corresponds to core Git's documentation (in - * "Documentation/gitformat-index.adoc"). - * - * The `flags` field consists of a number of bit fields which can be - * accessed via the first set of `GIT_INDEX_ENTRY_...` bitmasks below. - * These flags are all read from and persisted to disk. - * - * The `flags_extended` field also has a number of bit fields which can be - * accessed via the later `GIT_INDEX_ENTRY_...` bitmasks below. Some of - * these flags are read from and written to disk, but some are set aside - * for in-memory only reference. - * - * Note that the time and size fields are truncated to 32 bits. This - * is enough to detect changes, which is enough for the index to - * function as a cache, but it should not be taken as an authoritative - * source for that data. - */ -typedef struct git_index_entry { - git_index_time ctime; - git_index_time mtime; - - uint32_t dev; - uint32_t ino; - uint32_t mode; - uint32_t uid; - uint32_t gid; - uint32_t file_size; - - git_oid id; - - uint16_t flags; - uint16_t flags_extended; - - const char *path; -} git_index_entry; - -/** - * Bitmasks for on-disk fields of `git_index_entry`'s `flags` - * - * These bitmasks match the four fields in the `git_index_entry` `flags` - * value both in memory and on disk. You can use them to interpret the - * data in the `flags`. - */ - -/** Mask for name length */ -#define GIT_INDEX_ENTRY_NAMEMASK (0x0fff) -/** Mask for index entry stage */ -#define GIT_INDEX_ENTRY_STAGEMASK (0x3000) -/** Shift bits for index entry */ -#define GIT_INDEX_ENTRY_STAGESHIFT 12 - -/** - * Flags for index entries - */ -typedef enum { - GIT_INDEX_ENTRY_EXTENDED = (0x4000), - GIT_INDEX_ENTRY_VALID = (0x8000) -} git_index_entry_flag_t; - -/** - * Macro to get the stage value (0 for the "main index", or a conflict - * value) from an index entry. - */ -#define GIT_INDEX_ENTRY_STAGE(E) \ - (((E)->flags & GIT_INDEX_ENTRY_STAGEMASK) >> GIT_INDEX_ENTRY_STAGESHIFT) - -/** - * Macro to set the stage value (0 for the "main index", or a conflict - * value) for an index entry. - */ -#define GIT_INDEX_ENTRY_STAGE_SET(E,S) do { \ - (E)->flags = ((E)->flags & ~GIT_INDEX_ENTRY_STAGEMASK) | \ - (((S) & 0x03) << GIT_INDEX_ENTRY_STAGESHIFT); } while (0) - -/** - * Bitmasks for on-disk fields of `git_index_entry`'s `flags_extended` - * - * In memory, the `flags_extended` fields are divided into two parts: the - * fields that are read from and written to disk, and other fields that - * in-memory only and used by libgit2. Only the flags in - * `GIT_INDEX_ENTRY_EXTENDED_FLAGS` will get saved on-disk. - * - * Thee first three bitmasks match the three fields in the - * `git_index_entry` `flags_extended` value that belong on disk. You - * can use them to interpret the data in the `flags_extended`. - * - * The rest of the bitmasks match the other fields in the `git_index_entry` - * `flags_extended` value that are only used in-memory by libgit2. - * You can use them to interpret the data in the `flags_extended`. - * - */ -typedef enum { - GIT_INDEX_ENTRY_INTENT_TO_ADD = (1 << 13), - GIT_INDEX_ENTRY_SKIP_WORKTREE = (1 << 14), - - GIT_INDEX_ENTRY_EXTENDED_FLAGS = (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE), - - GIT_INDEX_ENTRY_UPTODATE = (1 << 2) -} git_index_entry_extended_flag_t; - -/** Capabilities of system that affect index actions. */ -typedef enum { - GIT_INDEX_CAPABILITY_IGNORE_CASE = 1, - GIT_INDEX_CAPABILITY_NO_FILEMODE = 2, - GIT_INDEX_CAPABILITY_NO_SYMLINKS = 4, - GIT_INDEX_CAPABILITY_FROM_OWNER = -1 -} git_index_capability_t; - - -/** - * Callback for APIs that add/remove/update files matching pathspec - * - * @param path the path - * @param matched_pathspec the given pathspec - * @param payload the user-specified payload - * @return 0 to continue with the index operation, positive number to skip this file for the index operation, negative number on failure - */ -typedef int GIT_CALLBACK(git_index_matched_path_cb)( - const char *path, const char *matched_pathspec, void *payload); - -/** Flags for APIs that add files matching pathspec */ -typedef enum { - GIT_INDEX_ADD_DEFAULT = 0, - GIT_INDEX_ADD_FORCE = (1u << 0), - GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = (1u << 1), - GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2) -} git_index_add_option_t; - -/** Git index stage states */ -typedef enum { - /** - * Match any index stage. - * - * Some index APIs take a stage to match; pass this value to match - * any entry matching the path regardless of stage. - */ - GIT_INDEX_STAGE_ANY = -1, - - /** A normal staged file in the index. */ - GIT_INDEX_STAGE_NORMAL = 0, - - /** The ancestor side of a conflict. */ - GIT_INDEX_STAGE_ANCESTOR = 1, - - /** The "ours" side of a conflict. */ - GIT_INDEX_STAGE_OURS = 2, - - /** The "theirs" side of a conflict. */ - GIT_INDEX_STAGE_THEIRS = 3 -} git_index_stage_t; - -#ifdef GIT_EXPERIMENTAL_SHA256 - -/** - * The options for opening or creating an index. - * - * Initialize with `GIT_INDEX_OPTIONS_INIT`. Alternatively, you can - * use `git_index_options_init`. - * - * @options[version] GIT_INDEX_OPTIONS_VERSION - * @options[init_macro] GIT_INDEX_OPTIONS_INIT - * @options[init_function] git_index_options_init - */ -typedef struct git_index_options { - unsigned int version; /**< The version */ - - /** - * The object ID type for the object IDs that exist in the index. - * - * If this is not specified, this defaults to `GIT_OID_SHA1`. - */ - git_oid_t oid_type; -} git_index_options; - -/** Current version for the `git_index_options` structure */ -#define GIT_INDEX_OPTIONS_VERSION 1 - -/** Static constructor for `git_index_options` */ -#define GIT_INDEX_OPTIONS_INIT { GIT_INDEX_OPTIONS_VERSION } - -/** - * Initialize git_index_options structure - * - * Initializes a `git_index_options` with default values. Equivalent to creating - * an instance with GIT_INDEX_OPTIONS_INIT. - * - * @param opts The `git_index_options` struct to initialize. - * @param version The struct version; pass `GIT_INDEX_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_index_options_init( - git_index_options *opts, - unsigned int version); - -/** - * Creates a new bare Git index object, without a repository to back - * it. This index object is capable of storing SHA256 objects. - * - * @param index_out the pointer for the new index - * @param index_path the path to the index file in disk - * @param opts the options for opening the index, or NULL - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_open( - git_index **index_out, - const char *index_path, - const git_index_options *opts); - -/** - * Create an in-memory index object. - * - * @param index_out the pointer for the new index - * @param opts the options for opening the index, or NULL - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_new(git_index **index_out, const git_index_options *opts); - -#else - -/** - * Create a new bare Git index object as a memory representation - * of the Git index file in 'index_path', without a repository - * to back it. - * - * Since there is no ODB or working directory behind this index, - * any Index methods which rely on these (e.g. index_add_bypath) - * will fail with the GIT_ERROR error code. - * - * If you need to access the index of an actual repository, - * use the `git_repository_index` wrapper. - * - * The index must be freed once it's no longer in use. - * - * @param index_out the pointer for the new index - * @param index_path the path to the index file in disk - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_open(git_index **index_out, const char *index_path); - -/** - * Create an in-memory index object. - * - * This index object cannot be read/written to the filesystem, - * but may be used to perform in-memory index operations. - * - * The index must be freed once it's no longer in use. - * - * @param index_out the pointer for the new index - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_new(git_index **index_out); - -#endif - -/** - * Free an existing index object. - * - * @param index an existing index object - */ -GIT_EXTERN(void) git_index_free(git_index *index); - -/** - * Get the repository this index relates to - * - * @param index The index - * @return A pointer to the repository - */ -GIT_EXTERN(git_repository *) git_index_owner(const git_index *index); - -/** - * Read index capabilities flags. - * - * @param index An existing index object - * @return A combination of GIT_INDEX_CAPABILITY values - */ -GIT_EXTERN(int) git_index_caps(const git_index *index); - -/** - * Set index capabilities flags. - * - * If you pass `GIT_INDEX_CAPABILITY_FROM_OWNER` for the caps, then - * capabilities will be read from the config of the owner object, - * looking at `core.ignorecase`, `core.filemode`, `core.symlinks`. - * - * @param index An existing index object - * @param caps A combination of GIT_INDEX_CAPABILITY values - * @return 0 on success, -1 on failure - */ -GIT_EXTERN(int) git_index_set_caps(git_index *index, int caps); - -/** - * Get index on-disk version. - * - * Valid return values are 2, 3, or 4. If 3 is returned, an index - * with version 2 may be written instead, if the extension data in - * version 3 is not necessary. - * - * @param index An existing index object - * @return the index version - */ -GIT_EXTERN(unsigned int) git_index_version(git_index *index); - -/** - * Set index on-disk version. - * - * Valid values are 2, 3, or 4. If 2 is given, git_index_write may - * write an index with version 3 instead, if necessary to accurately - * represent the index. - * - * @param index An existing index object - * @param version The new version number - * @return 0 on success, -1 on failure - */ -GIT_EXTERN(int) git_index_set_version(git_index *index, unsigned int version); - -/** - * Update the contents of an existing index object in memory by reading - * from the hard disk. - * - * If `force` is true, this performs a "hard" read that discards in-memory - * changes and always reloads the on-disk index data. If there is no - * on-disk version, the index will be cleared. - * - * If `force` is false, this does a "soft" read that reloads the index - * data from disk only if it has changed since the last time it was - * loaded. Purely in-memory index data will be untouched. Be aware: if - * there are changes on disk, unwritten in-memory changes are discarded. - * - * @param index an existing index object - * @param force if true, always reload, vs. only read if file has changed - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_read(git_index *index, int force); - -/** - * Write an existing index object from memory back to disk - * using an atomic file lock. - * - * @param index an existing index object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_write(git_index *index); - -/** - * Get the full path to the index file on disk. - * - * @param index an existing index object - * @return path to index file or NULL for in-memory index - */ -GIT_EXTERN(const char *) git_index_path(const git_index *index); - -#ifndef GIT_DEPRECATE_HARD -/** - * Get the checksum of the index - * - * This checksum is the SHA-1 hash over the index file (except the - * last 20 bytes which are the checksum itself). In cases where the - * index does not exist on-disk, it will be zeroed out. - * - * @deprecated this function is deprecated with no replacement - * @param index an existing index object - * @return a pointer to the checksum of the index - */ -GIT_EXTERN(const git_oid *) git_index_checksum(git_index *index); -#endif - -/** - * Read a tree into the index file with stats - * - * The current index contents will be replaced by the specified tree. - * - * @param index an existing index object - * @param tree tree to read - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_read_tree(git_index *index, const git_tree *tree); - -/** - * Write the index as a tree - * - * This method will scan the index and write a representation - * of its current state back to disk; it recursively creates - * tree objects for each of the subtrees stored in the index, - * but only returns the OID of the root tree. This is the OID - * that can be used e.g. to create a commit. - * - * The index instance cannot be bare, and needs to be associated - * to an existing repository. - * - * The index must not contain any file in conflict. - * - * @param out Pointer where to store the OID of the written tree - * @param index Index to write - * @return 0 on success, GIT_EUNMERGED when the index is not clean - * or an error code - */ -GIT_EXTERN(int) git_index_write_tree(git_oid *out, git_index *index); - -/** - * Write the index as a tree to the given repository - * - * This method will do the same as `git_index_write_tree`, but - * letting the user choose the repository where the tree will - * be written. - * - * The index must not contain any file in conflict. - * - * @param out Pointer where to store OID of the written tree - * @param index Index to write - * @param repo Repository where to write the tree - * @return 0 on success, GIT_EUNMERGED when the index is not clean - * or an error code - */ -GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repository *repo); - -/**@}*/ - -/** @name Raw Index Entry Functions - * - * These functions work on index entries, and allow for raw manipulation - * of the entries. - */ -/**@{*/ - -/* Index entry manipulation */ - -/** - * Get the count of entries currently in the index - * - * @param index an existing index object - * @return integer of count of current entries - */ -GIT_EXTERN(size_t) git_index_entrycount(const git_index *index); - -/** - * Clear the contents (all the entries) of an index object. - * - * This clears the index object in memory; changes must be explicitly - * written to disk for them to take effect persistently. - * - * @param index an existing index object - * @return 0 on success, error code < 0 on failure - */ -GIT_EXTERN(int) git_index_clear(git_index *index); - -/** - * Get a pointer to one of the entries in the index - * - * The entry is not modifiable and should not be freed. Because the - * `git_index_entry` struct is a publicly defined struct, you should - * be able to make your own permanent copy of the data if necessary. - * - * @param index an existing index object - * @param n the position of the entry - * @return a pointer to the entry; NULL if out of bounds - */ -GIT_EXTERN(const git_index_entry *) git_index_get_byindex( - git_index *index, size_t n); - -/** - * Get a pointer to one of the entries in the index - * - * The entry is not modifiable and should not be freed. Because the - * `git_index_entry` struct is a publicly defined struct, you should - * be able to make your own permanent copy of the data if necessary. - * - * @param index an existing index object - * @param path path to search - * @param stage stage to search - * @return a pointer to the entry; NULL if it was not found - */ -GIT_EXTERN(const git_index_entry *) git_index_get_bypath( - git_index *index, const char *path, int stage); - -/** - * Remove an entry from the index - * - * @param index an existing index object - * @param path path to search - * @param stage stage to search - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_remove(git_index *index, const char *path, int stage); - -/** - * Remove all entries from the index under a given directory - * - * @param index an existing index object - * @param dir container directory path - * @param stage stage to search - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_remove_directory( - git_index *index, const char *dir, int stage); - -/** - * Add or update an index entry from an in-memory struct - * - * If a previous index entry exists that has the same path and stage - * as the given 'source_entry', it will be replaced. Otherwise, the - * 'source_entry' will be added. - * - * A full copy (including the 'path' string) of the given - * 'source_entry' will be inserted on the index. - * - * @param index an existing index object - * @param source_entry new entry object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_entry); - -/** - * Return the stage number from a git index entry - * - * This entry is calculated from the entry's flag attribute like this: - * - * (entry->flags & GIT_INDEX_ENTRY_STAGEMASK) >> GIT_INDEX_ENTRY_STAGESHIFT - * - * @param entry The entry - * @return the stage number - */ -GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry); - -/** - * Return whether the given index entry is a conflict (has a high stage - * entry). This is simply shorthand for `git_index_entry_stage > 0`. - * - * @param entry The entry - * @return 1 if the entry is a conflict entry, 0 otherwise - */ -GIT_EXTERN(int) git_index_entry_is_conflict(const git_index_entry *entry); - -/**@}*/ - -/** @name Index Entry Iteration Functions - * - * These functions provide an iterator for index entries. - */ -/**@{*/ - -/** - * Create an iterator that will return every entry contained in the - * index at the time of creation. Entries are returned in order, - * sorted by path. This iterator is backed by a snapshot that allows - * callers to modify the index while iterating without affecting the - * iterator. - * - * @param iterator_out The newly created iterator - * @param index The index to iterate - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_index_iterator_new( - git_index_iterator **iterator_out, - git_index *index); - -/** - * Return the next index entry in-order from the iterator. - * - * @param out Pointer to store the index entry in - * @param iterator The iterator - * @return 0, GIT_ITEROVER on iteration completion or an error code - */ -GIT_EXTERN(int) git_index_iterator_next( - const git_index_entry **out, - git_index_iterator *iterator); - -/** - * Free the index iterator - * - * @param iterator The iterator to free - */ -GIT_EXTERN(void) git_index_iterator_free(git_index_iterator *iterator); - -/**@}*/ - -/** @name Workdir Index Entry Functions - * - * These functions work on index entries specifically in the working - * directory (ie, stage 0). - */ -/**@{*/ - -/** - * Add or update an index entry from a file on disk - * - * The file `path` must be relative to the repository's - * working folder and must be readable. - * - * This method will fail in bare index instances. - * - * This forces the file to be added to the index, not looking - * at gitignore rules. Those rules can be evaluated through - * the git_status APIs (in status.h) before calling this. - * - * If this file currently is the result of a merge conflict, this - * file will no longer be marked as conflicting. The data about - * the conflict will be moved to the "resolve undo" (REUC) section. - * - * @param index an existing index object - * @param path filename to add - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path); - -/** - * Add or update an index entry from a buffer in memory - * - * This method will create a blob in the repository that owns the - * index and then add the index entry to the index. The `path` of the - * entry represents the position of the blob relative to the - * repository's root folder. - * - * If a previous index entry exists that has the same path as the - * given 'entry', it will be replaced. Otherwise, the 'entry' will be - * added. - * - * This forces the file to be added to the index, not looking - * at gitignore rules. Those rules can be evaluated through - * the git_status APIs (in status.h) before calling this. - * - * If this file currently is the result of a merge conflict, this - * file will no longer be marked as conflicting. The data about - * the conflict will be moved to the "resolve undo" (REUC) section. - * - * @param index an existing index object - * @param entry filename to add - * @param buffer data to be written into the blob - * @param len length of the data - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_add_from_buffer( - git_index *index, - const git_index_entry *entry, - const void *buffer, size_t len); - -/** - * Remove an index entry corresponding to a file on disk - * - * The file `path` must be relative to the repository's - * working folder. It may exist. - * - * If this file currently is the result of a merge conflict, this - * file will no longer be marked as conflicting. The data about - * the conflict will be moved to the "resolve undo" (REUC) section. - * - * @param index an existing index object - * @param path filename to remove - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path); - -/** - * Add or update index entries matching files in the working directory. - * - * This method will fail in bare index instances. - * - * The `pathspec` is a list of file names or shell glob patterns that will - * be matched against files in the repository's working directory. Each - * file that matches will be added to the index (either updating an - * existing entry or adding a new entry). You can disable glob expansion - * and force exact matching with the `GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH` - * flag. - * - * Files that are ignored will be skipped (unlike `git_index_add_bypath`). - * If a file is already tracked in the index, then it *will* be updated - * even if it is ignored. Pass the `GIT_INDEX_ADD_FORCE` flag to skip - * the checking of ignore rules. - * - * To emulate `git add -A` and generate an error if the pathspec contains - * the exact path of an ignored file (when not using FORCE), add the - * `GIT_INDEX_ADD_CHECK_PATHSPEC` flag. This checks that each entry - * in the `pathspec` that is an exact match to a filename on disk is - * either not ignored or already in the index. If this check fails, the - * function will return GIT_EINVALIDSPEC. - * - * To emulate `git add -A` with the "dry-run" option, just use a callback - * function that always returns a positive value. See below for details. - * - * If any files are currently the result of a merge conflict, those files - * will no longer be marked as conflicting. The data about the conflicts - * will be moved to the "resolve undo" (REUC) section. - * - * If you provide a callback function, it will be invoked on each matching - * item in the working directory immediately *before* it is added to / - * updated in the index. Returning zero will add the item to the index, - * greater than zero will skip the item, and less than zero will abort the - * scan and return that value to the caller. - * - * @param index an existing index object - * @param pathspec array of path patterns - * @param flags combination of git_index_add_option_t flags - * @param callback notification callback for each added/updated path (also - * gets index of matching pathspec entry); can be NULL; - * return 0 to add, >0 to skip, <0 to abort scan. - * @param payload payload passed through to callback function - * @return 0 on success, negative callback return value, or error code - */ -GIT_EXTERN(int) git_index_add_all( - git_index *index, - const git_strarray *pathspec, - unsigned int flags, - git_index_matched_path_cb callback, - void *payload); - -/** - * Remove all matching index entries. - * - * If you provide a callback function, it will be invoked on each matching - * item in the index immediately *before* it is removed. Return 0 to - * remove the item, > 0 to skip the item, and < 0 to abort the scan. - * - * @param index An existing index object - * @param pathspec array of path patterns - * @param callback notification callback for each removed path (also - * gets index of matching pathspec entry); can be NULL; - * return 0 to add, >0 to skip, <0 to abort scan. - * @param payload payload passed through to callback function - * @return 0 on success, negative callback return value, or error code - */ -GIT_EXTERN(int) git_index_remove_all( - git_index *index, - const git_strarray *pathspec, - git_index_matched_path_cb callback, - void *payload); - -/** - * Update all index entries to match the working directory - * - * This method will fail in bare index instances. - * - * This scans the existing index entries and synchronizes them with the - * working directory, deleting them if the corresponding working directory - * file no longer exists otherwise updating the information (including - * adding the latest version of file to the ODB if needed). - * - * If you provide a callback function, it will be invoked on each matching - * item in the index immediately *before* it is updated (either refreshed - * or removed depending on working directory state). Return 0 to proceed - * with updating the item, > 0 to skip the item, and < 0 to abort the scan. - * - * @param index An existing index object - * @param pathspec array of path patterns - * @param callback notification callback for each updated path (also - * gets index of matching pathspec entry); can be NULL; - * return 0 to add, >0 to skip, <0 to abort scan. - * @param payload payload passed through to callback function - * @return 0 on success, negative callback return value, or error code - */ -GIT_EXTERN(int) git_index_update_all( - git_index *index, - const git_strarray *pathspec, - git_index_matched_path_cb callback, - void *payload); - -/** - * Find the first position of any entries which point to given - * path in the Git index. - * - * @param at_pos the address to which the position of the index entry is written (optional) - * @param index an existing index object - * @param path path to search - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *path); - -/** - * Find the first position of any entries matching a prefix. To find the first position - * of a path inside a given folder, suffix the prefix with a '/'. - * - * @param at_pos the address to which the position of the index entry is written (optional) - * @param index an existing index object - * @param prefix the prefix to search for - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_find_prefix(size_t *at_pos, git_index *index, const char *prefix); - -/**@}*/ - -/** @name Conflict Index Entry Functions - * - * These functions work on conflict index entries specifically (ie, stages 1-3) - */ -/**@{*/ - -/** - * Add or update index entries to represent a conflict. Any staged - * entries that exist at the given paths will be removed. - * - * The entries are the entries from the tree included in the merge. Any - * entry may be null to indicate that that file was not present in the - * trees during the merge. For example, ancestor_entry may be NULL to - * indicate that a file was added in both branches and must be resolved. - * - * @param index an existing index object - * @param ancestor_entry the entry data for the ancestor of the conflict - * @param our_entry the entry data for our side of the merge conflict - * @param their_entry the entry data for their side of the merge conflict - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_conflict_add( - git_index *index, - const git_index_entry *ancestor_entry, - const git_index_entry *our_entry, - const git_index_entry *their_entry); - -/** - * Get the index entries that represent a conflict of a single file. - * - * The entries are not modifiable and should not be freed. Because the - * `git_index_entry` struct is a publicly defined struct, you should - * be able to make your own permanent copy of the data if necessary. - * - * @param ancestor_out Pointer to store the ancestor entry - * @param our_out Pointer to store the our entry - * @param their_out Pointer to store the their entry - * @param index an existing index object - * @param path path to search - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_conflict_get( - const git_index_entry **ancestor_out, - const git_index_entry **our_out, - const git_index_entry **their_out, - git_index *index, - const char *path); - -/** - * Removes the index entries that represent a conflict of a single file. - * - * @param index an existing index object - * @param path path to remove conflicts for - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_conflict_remove(git_index *index, const char *path); - -/** - * Remove all conflicts in the index (entries with a stage greater than 0). - * - * @param index an existing index object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_conflict_cleanup(git_index *index); - -/** - * Determine if the index contains entries representing file conflicts. - * - * @param index An existing index object. - * @return 1 if at least one conflict is found, 0 otherwise. - */ -GIT_EXTERN(int) git_index_has_conflicts(const git_index *index); - -/** - * Create an iterator for the conflicts in the index. - * - * The index must not be modified while iterating; the results are undefined. - * - * @param iterator_out The newly created conflict iterator - * @param index The index to scan - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_conflict_iterator_new( - git_index_conflict_iterator **iterator_out, - git_index *index); - -/** - * Returns the current conflict (ancestor, ours and theirs entry) and - * advance the iterator internally to the next value. - * - * @param ancestor_out Pointer to store the ancestor side of the conflict - * @param our_out Pointer to store our side of the conflict - * @param their_out Pointer to store their side of the conflict - * @param iterator The conflict iterator. - * @return 0 (no error), GIT_ITEROVER (iteration is done) or an error code - * (negative value) - */ -GIT_EXTERN(int) git_index_conflict_next( - const git_index_entry **ancestor_out, - const git_index_entry **our_out, - const git_index_entry **their_out, - git_index_conflict_iterator *iterator); - -/** - * Frees a `git_index_conflict_iterator`. - * - * @param iterator pointer to the iterator - */ -GIT_EXTERN(void) git_index_conflict_iterator_free( - git_index_conflict_iterator *iterator); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/indexer.h b/vendor/libgit2-sys/libgit2/include/git2/indexer.h deleted file mode 100644 index 9aaedc3..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/indexer.h +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_indexer_h__ -#define INCLUDE_git_indexer_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/indexer.h - * @brief Packfile indexing - * @ingroup Git - * @{ - * - * Indexing is the operation of taking a packfile - which is simply a - * collection of unordered commits - and producing an "index" so that - * one can lookup a commit in the packfile by object ID. - */ -GIT_BEGIN_DECL - -/** A git indexer object */ -typedef struct git_indexer git_indexer; - -/** - * This structure is used to provide callers information about the - * progress of indexing a packfile, either directly or part of a - * fetch or clone that downloads a packfile. - */ -typedef struct git_indexer_progress { - /** number of objects in the packfile being indexed */ - unsigned int total_objects; - - /** received objects that have been hashed */ - unsigned int indexed_objects; - - /** received_objects: objects which have been downloaded */ - unsigned int received_objects; - - /** - * locally-available objects that have been injected in order - * to fix a thin pack - */ - unsigned int local_objects; - - /** number of deltas in the packfile being indexed */ - unsigned int total_deltas; - - /** received deltas that have been indexed */ - unsigned int indexed_deltas; - - /** size of the packfile received up to now */ - size_t received_bytes; -} git_indexer_progress; - -/** - * Type for progress callbacks during indexing. Return a value less - * than zero to cancel the indexing or download. - * - * @param stats Structure containing information about the state of the transfer - * @param payload Payload provided by caller - * @return 0 on success or an error code - */ -typedef int GIT_CALLBACK(git_indexer_progress_cb)(const git_indexer_progress *stats, void *payload); - -/** - * Options for indexer configuration - */ -typedef struct git_indexer_options { - unsigned int version; - -#ifdef GIT_EXPERIMENTAL_SHA256 - /** permissions to use creating packfile or 0 for defaults */ - unsigned int mode; - - /** the type of object ids in the packfile or 0 for SHA1 */ - git_oid_t oid_type; - - /** - * object database from which to read base objects when - * fixing thin packs. This can be NULL if there are no thin - * packs; if a thin pack is encountered, an error will be - * returned if there are bases missing. - */ - git_odb *odb; -#endif - - /** progress_cb function to call with progress information */ - git_indexer_progress_cb progress_cb; - - /** progress_cb_payload payload for the progress callback */ - void *progress_cb_payload; - - /** Do connectivity checks for the received pack */ - unsigned char verify; -} git_indexer_options; - -/** Current version for the `git_indexer_options` structure */ -#define GIT_INDEXER_OPTIONS_VERSION 1 - -/** Static constructor for `git_indexer_options` */ -#define GIT_INDEXER_OPTIONS_INIT { GIT_INDEXER_OPTIONS_VERSION } - -/** - * Initializes a `git_indexer_options` with default values. Equivalent to - * creating an instance with GIT_INDEXER_OPTIONS_INIT. - * - * @param opts the `git_indexer_options` struct to initialize. - * @param version Version of struct; pass `GIT_INDEXER_OPTIONS_VERSION` - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_indexer_options_init( - git_indexer_options *opts, - unsigned int version); - -#ifdef GIT_EXPERIMENTAL_SHA256 -/** - * Create a new indexer instance - * - * @param out where to store the indexer instance - * @param path to the directory where the packfile should be stored - * @param opts the options to create the indexer with - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_indexer_new( - git_indexer **out, - const char *path, - git_indexer_options *opts); -#else -/** - * Create a new indexer instance - * - * @param out where to store the indexer instance - * @param path to the directory where the packfile should be stored - * @param mode permissions to use creating packfile or 0 for defaults - * @param odb object database from which to read base objects when - * fixing thin packs. Pass NULL if no thin pack is expected (an error - * will be returned if there are bases missing) - * @param opts Optional structure containing additional options. See - * `git_indexer_options` above. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_indexer_new( - git_indexer **out, - const char *path, - unsigned int mode, - git_odb *odb, - git_indexer_options *opts); -#endif - -/** - * Add data to the indexer - * - * @param idx the indexer - * @param data the data to add - * @param size the size of the data in bytes - * @param stats stat storage - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_indexer_append(git_indexer *idx, const void *data, size_t size, git_indexer_progress *stats); - -/** - * Finalize the pack and index - * - * Resolve any pending deltas and write out the index file - * - * @param idx the indexer - * @param stats Stat storage. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_indexer_commit(git_indexer *idx, git_indexer_progress *stats); - -#ifndef GIT_DEPRECATE_HARD -/** - * Get the packfile's hash - * - * A packfile's name is derived from the sorted hashing of all object - * names. This is only correct after the index has been finalized. - * - * @deprecated use git_indexer_name - * @param idx the indexer instance - * @return the packfile's hash - */ -GIT_EXTERN(const git_oid *) git_indexer_hash(const git_indexer *idx); -#endif - -/** - * Get the unique name for the resulting packfile. - * - * The packfile's name is derived from the packfile's content. - * This is only correct after the index has been finalized. - * - * @param idx the indexer instance - * @return a NUL terminated string for the packfile name - */ -GIT_EXTERN(const char *) git_indexer_name(const git_indexer *idx); - -/** - * Free the indexer and its resources - * - * @param idx the indexer to free - */ -GIT_EXTERN(void) git_indexer_free(git_indexer *idx); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/mailmap.h b/vendor/libgit2-sys/libgit2/include/git2/mailmap.h deleted file mode 100644 index fd6ae71..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/mailmap.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_mailmap_h__ -#define INCLUDE_git_mailmap_h__ - -#include "common.h" -#include "types.h" -#include "buffer.h" - -/** - * @file git2/mailmap.h - * @brief Mailmaps provide alternate email addresses for users - * @defgroup git_mailmap Git mailmap routines - * @ingroup Git - * @{ - * - * A mailmap can be used to specify alternate email addresses for - * repository committers or authors. This allows systems to map - * commits made using different email addresses to the same logical - * person. - */ -GIT_BEGIN_DECL - -/** - * Allocate a new mailmap object. - * - * This object is empty, so you'll have to add a mailmap file before you can do - * anything with it. The mailmap must be freed with 'git_mailmap_free'. - * - * @param out pointer to store the new mailmap - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_mailmap_new(git_mailmap **out); - -/** - * Free the mailmap and its associated memory. - * - * @param mm the mailmap to free - */ -GIT_EXTERN(void) git_mailmap_free(git_mailmap *mm); - -/** - * Add a single entry to the given mailmap object. If the entry already exists, - * it will be replaced with the new entry. - * - * @param mm mailmap to add the entry to - * @param real_name the real name to use, or NULL - * @param real_email the real email to use, or NULL - * @param replace_name the name to replace, or NULL - * @param replace_email the email to replace - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_mailmap_add_entry( - git_mailmap *mm, const char *real_name, const char *real_email, - const char *replace_name, const char *replace_email); - -/** - * Create a new mailmap instance containing a single mailmap file - * - * @param out pointer to store the new mailmap - * @param buf buffer to parse the mailmap from - * @param len the length of the input buffer - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_mailmap_from_buffer( - git_mailmap **out, const char *buf, size_t len); - -/** - * Create a new mailmap instance from a repository, loading mailmap files based - * on the repository's configuration. - * - * Mailmaps are loaded in the following order: - * 1. '.mailmap' in the root of the repository's working directory, if present. - * 2. The blob object identified by the 'mailmap.blob' config entry, if set. - * [NOTE: 'mailmap.blob' defaults to 'HEAD:.mailmap' in bare repositories] - * 3. The path in the 'mailmap.file' config entry, if set. - * - * @param out pointer to store the new mailmap - * @param repo repository to load mailmap information from - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_mailmap_from_repository( - git_mailmap **out, git_repository *repo); - -/** - * Resolve a name and email to the corresponding real name and email. - * - * The lifetime of the strings are tied to `mm`, `name`, and `email` parameters. - * - * @param real_name pointer to store the real name - * @param real_email pointer to store the real email - * @param mm the mailmap to perform a lookup with (may be NULL) - * @param name the name to look up - * @param email the email to look up - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_mailmap_resolve( - const char **real_name, const char **real_email, - const git_mailmap *mm, const char *name, const char *email); - -/** - * Resolve a signature to use real names and emails with a mailmap. - * - * Call `git_signature_free()` to free the data. - * - * @param out new signature - * @param mm mailmap to resolve with - * @param sig signature to resolve - * @return 0 or an error code - */ -GIT_EXTERN(int) git_mailmap_resolve_signature( - git_signature **out, const git_mailmap *mm, const git_signature *sig); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/merge.h b/vendor/libgit2-sys/libgit2/include/git2/merge.h deleted file mode 100644 index 2e3a73e..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/merge.h +++ /dev/null @@ -1,673 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_merge_h__ -#define INCLUDE_git_merge_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "oidarray.h" -#include "checkout.h" -#include "index.h" -#include "annotated_commit.h" - -/** - * @file git2/merge.h - * @brief Merge re-joins diverging branches of history - * @defgroup git_merge Git merge routines - * @ingroup Git - * - * Merge will take two commits and attempt to produce a commit that - * includes the changes that were made in both branches. - * @{ - */ -GIT_BEGIN_DECL - -/** - * The file inputs to `git_merge_file`. Callers should populate the - * `git_merge_file_input` structure with descriptions of the files in - * each side of the conflict for use in producing the merge file. - */ -typedef struct { - unsigned int version; - - /** Pointer to the contents of the file. */ - const char *ptr; - - /** Size of the contents pointed to in `ptr`. */ - size_t size; - - /** File name of the conflicted file, or `NULL` to not merge the path. */ - const char *path; - - /** File mode of the conflicted file, or `0` to not merge the mode. */ - unsigned int mode; -} git_merge_file_input; - -/** Current version for the `git_merge_file_input_options` structure */ -#define GIT_MERGE_FILE_INPUT_VERSION 1 - -/** Static constructor for `git_merge_file_input_options` */ -#define GIT_MERGE_FILE_INPUT_INIT {GIT_MERGE_FILE_INPUT_VERSION} - -/** - * Initializes a `git_merge_file_input` with default values. Equivalent to - * creating an instance with GIT_MERGE_FILE_INPUT_INIT. - * - * @param opts the `git_merge_file_input` instance to initialize. - * @param version the version of the struct; you should pass - * `GIT_MERGE_FILE_INPUT_VERSION` here. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_merge_file_input_init( - git_merge_file_input *opts, - unsigned int version); - -/** - * Flags for `git_merge` options. A combination of these flags can be - * passed in via the `flags` value in the `git_merge_options`. - */ -typedef enum { - /** - * Detect renames that occur between the common ancestor and the "ours" - * side or the common ancestor and the "theirs" side. This will enable - * the ability to merge between a modified and renamed file. - */ - GIT_MERGE_FIND_RENAMES = (1 << 0), - - /** - * If a conflict occurs, exit immediately instead of attempting to - * continue resolving conflicts. The merge operation will fail with - * GIT_EMERGECONFLICT and no index will be returned. - */ - GIT_MERGE_FAIL_ON_CONFLICT = (1 << 1), - - /** - * Do not write the REUC extension on the generated index - */ - GIT_MERGE_SKIP_REUC = (1 << 2), - - /** - * If the commits being merged have multiple merge bases, do not build - * a recursive merge base (by merging the multiple merge bases), - * instead simply use the first base. This flag provides a similar - * merge base to `git-merge-resolve`. - */ - GIT_MERGE_NO_RECURSIVE = (1 << 3), - - /** - * Treat this merge as if it is to produce the virtual base - * of a recursive merge. This will ensure that there are - * no conflicts, any conflicting regions will keep conflict - * markers in the merge result. - */ - GIT_MERGE_VIRTUAL_BASE = (1 << 4) -} git_merge_flag_t; - -/** - * Merge file favor options for `git_merge_options` instruct the file-level - * merging functionality how to deal with conflicting regions of the files. - */ -typedef enum { - /** - * When a region of a file is changed in both branches, a conflict - * will be recorded in the index so that `git_checkout` can produce - * a merge file with conflict markers in the working directory. - * This is the default. - */ - GIT_MERGE_FILE_FAVOR_NORMAL = 0, - - /** - * When a region of a file is changed in both branches, the file - * created in the index will contain the "ours" side of any conflicting - * region. The index will not record a conflict. - */ - GIT_MERGE_FILE_FAVOR_OURS = 1, - - /** - * When a region of a file is changed in both branches, the file - * created in the index will contain the "theirs" side of any conflicting - * region. The index will not record a conflict. - */ - GIT_MERGE_FILE_FAVOR_THEIRS = 2, - - /** - * When a region of a file is changed in both branches, the file - * created in the index will contain each unique line from each side, - * which has the result of combining both files. The index will not - * record a conflict. - */ - GIT_MERGE_FILE_FAVOR_UNION = 3 -} git_merge_file_favor_t; - -/** - * File merging flags - */ -typedef enum { - /** Defaults */ - GIT_MERGE_FILE_DEFAULT = 0, - - /** Create standard conflicted merge files */ - GIT_MERGE_FILE_STYLE_MERGE = (1 << 0), - - /** Create diff3-style files */ - GIT_MERGE_FILE_STYLE_DIFF3 = (1 << 1), - - /** Condense non-alphanumeric regions for simplified diff file */ - GIT_MERGE_FILE_SIMPLIFY_ALNUM = (1 << 2), - - /** Ignore all whitespace */ - GIT_MERGE_FILE_IGNORE_WHITESPACE = (1 << 3), - - /** Ignore changes in amount of whitespace */ - GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE = (1 << 4), - - /** Ignore whitespace at end of line */ - GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL = (1 << 5), - - /** Use the "patience diff" algorithm */ - GIT_MERGE_FILE_DIFF_PATIENCE = (1 << 6), - - /** Take extra time to find minimal diff */ - GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7), - - /** Create zdiff3 ("zealous diff3")-style files */ - GIT_MERGE_FILE_STYLE_ZDIFF3 = (1 << 8), - - /** - * Do not produce file conflicts when common regions have - * changed; keep the conflict markers in the file and accept - * that as the merge result. - */ - GIT_MERGE_FILE_ACCEPT_CONFLICTS = (1 << 9) -} git_merge_file_flag_t; - -/** Default size for conflict markers */ -#define GIT_MERGE_CONFLICT_MARKER_SIZE 7 - -/** - * Options for merging a file - */ -typedef struct { - unsigned int version; - - /** - * Label for the ancestor file side of the conflict which will be prepended - * to labels in diff3-format merge files. - */ - const char *ancestor_label; - - /** - * Label for our file side of the conflict which will be prepended - * to labels in merge files. - */ - const char *our_label; - - /** - * Label for their file side of the conflict which will be prepended - * to labels in merge files. - */ - const char *their_label; - - /** The file to favor in region conflicts. */ - git_merge_file_favor_t favor; - - /** see `git_merge_file_flag_t` above */ - uint32_t flags; - - /** The size of conflict markers (eg, "<<<<<<<"). Default is - * GIT_MERGE_CONFLICT_MARKER_SIZE. */ - unsigned short marker_size; -} git_merge_file_options; - -/** Current version for the `git_merge_file_options` structure */ -#define GIT_MERGE_FILE_OPTIONS_VERSION 1 - -/** Static constructor for `git_merge_file_options` */ -#define GIT_MERGE_FILE_OPTIONS_INIT {GIT_MERGE_FILE_OPTIONS_VERSION} - -/** - * Initialize git_merge_file_options structure - * - * Initializes a `git_merge_file_options` with default values. Equivalent to - * creating an instance with `GIT_MERGE_FILE_OPTIONS_INIT`. - * - * @param opts The `git_merge_file_options` struct to initialize. - * @param version The struct version; pass `GIT_MERGE_FILE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_merge_file_options_init(git_merge_file_options *opts, unsigned int version); - -/** - * Information about file-level merging - */ -typedef struct { - /** - * True if the output was automerged, false if the output contains - * conflict markers. - */ - unsigned int automergeable; - - /** - * The path that the resultant merge file should use, or NULL if a - * filename conflict would occur. - */ - const char *path; - - /** The mode that the resultant merge file should use. */ - unsigned int mode; - - /** The contents of the merge. */ - const char *ptr; - - /** The length of the merge contents. */ - size_t len; -} git_merge_file_result; - -/** - * Merging options - */ -typedef struct { - unsigned int version; - - /** See `git_merge_flag_t` above */ - uint32_t flags; - - /** - * Similarity to consider a file renamed (default 50). If - * `GIT_MERGE_FIND_RENAMES` is enabled, added files will be compared - * with deleted files to determine their similarity. Files that are - * more similar than the rename threshold (percentage-wise) will be - * treated as a rename. - */ - unsigned int rename_threshold; - - /** - * Maximum similarity sources to examine for renames (default 200). - * If the number of rename candidates (add / delete pairs) is greater - * than this value, inexact rename detection is aborted. - * - * This setting overrides the `merge.renameLimit` configuration value. - */ - unsigned int target_limit; - - /** Pluggable similarity metric; pass NULL to use internal metric */ - git_diff_similarity_metric *metric; - - /** - * Maximum number of times to merge common ancestors to build a - * virtual merge base when faced with criss-cross merges. When this - * limit is reached, the next ancestor will simply be used instead of - * attempting to merge it. The default is unlimited. - */ - unsigned int recursion_limit; - - /** - * Default merge driver to be used when both sides of a merge have - * changed. The default is the `text` driver. - */ - const char *default_driver; - - /** - * Flags for handling conflicting content, to be used with the standard - * (`text`) merge driver. - */ - git_merge_file_favor_t file_favor; - - /** see `git_merge_file_flag_t` above */ - uint32_t file_flags; -} git_merge_options; - -/** Current version for the `git_merge_options` structure */ -#define GIT_MERGE_OPTIONS_VERSION 1 - -/** Static constructor for `git_merge_options` */ -#define GIT_MERGE_OPTIONS_INIT { \ - GIT_MERGE_OPTIONS_VERSION, GIT_MERGE_FIND_RENAMES } - -/** - * Initialize git_merge_options structure - * - * Initializes a `git_merge_options` with default values. Equivalent to - * creating an instance with `GIT_MERGE_OPTIONS_INIT`. - * - * @param opts The `git_merge_options` struct to initialize. - * @param version The struct version; pass `GIT_MERGE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_merge_options_init(git_merge_options *opts, unsigned int version); - -/** - * The results of `git_merge_analysis` indicate the merge opportunities. - */ -typedef enum { - /** No merge is possible. (Unused.) */ - GIT_MERGE_ANALYSIS_NONE = 0, - - /** - * A "normal" merge; both HEAD and the given merge input have diverged - * from their common ancestor. The divergent commits must be merged. - */ - GIT_MERGE_ANALYSIS_NORMAL = (1 << 0), - - /** - * All given merge inputs are reachable from HEAD, meaning the - * repository is up-to-date and no merge needs to be performed. - */ - GIT_MERGE_ANALYSIS_UP_TO_DATE = (1 << 1), - - /** - * The given merge input is a fast-forward from HEAD and no merge - * needs to be performed. Instead, the client can check out the - * given merge input. - */ - GIT_MERGE_ANALYSIS_FASTFORWARD = (1 << 2), - - /** - * The HEAD of the current repository is "unborn" and does not point to - * a valid commit. No merge can be performed, but the caller may wish - * to simply set HEAD to the target commit(s). - */ - GIT_MERGE_ANALYSIS_UNBORN = (1 << 3) -} git_merge_analysis_t; - -/** - * The user's stated preference for merges. - */ -typedef enum { - /** - * No configuration was found that suggests a preferred behavior for - * merge. - */ - GIT_MERGE_PREFERENCE_NONE = 0, - - /** - * There is a `merge.ff=false` configuration setting, suggesting that - * the user does not want to allow a fast-forward merge. - */ - GIT_MERGE_PREFERENCE_NO_FASTFORWARD = (1 << 0), - - /** - * There is a `merge.ff=only` configuration setting, suggesting that - * the user only wants fast-forward merges. - */ - GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY = (1 << 1) -} git_merge_preference_t; - -/** - * Analyzes the given branch(es) and determines the opportunities for - * merging them into the HEAD of the repository. - * - * @param analysis_out analysis enumeration that the result is written into - * @param preference_out One of the `git_merge_preference_t` flag. - * @param repo the repository to merge - * @param their_heads the heads to merge into - * @param their_heads_len the number of heads to merge - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_merge_analysis( - git_merge_analysis_t *analysis_out, - git_merge_preference_t *preference_out, - git_repository *repo, - const git_annotated_commit **their_heads, - size_t their_heads_len); - -/** - * Analyzes the given branch(es) and determines the opportunities for - * merging them into a reference. - * - * @param analysis_out analysis enumeration that the result is written into - * @param preference_out One of the `git_merge_preference_t` flag. - * @param repo the repository to merge - * @param our_ref the reference to perform the analysis from - * @param their_heads the heads to merge into - * @param their_heads_len the number of heads to merge - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_merge_analysis_for_ref( - git_merge_analysis_t *analysis_out, - git_merge_preference_t *preference_out, - git_repository *repo, - git_reference *our_ref, - const git_annotated_commit **their_heads, - size_t their_heads_len); - -/** - * Find a merge base between two commits - * - * @param out the OID of a merge base between 'one' and 'two' - * @param repo the repository where the commits exist - * @param one one of the commits - * @param two the other commit - * @return 0 on success, GIT_ENOTFOUND if not found or error code - */ -GIT_EXTERN(int) git_merge_base( - git_oid *out, - git_repository *repo, - const git_oid *one, - const git_oid *two); - -/** - * Find merge bases between two commits - * - * @param out array in which to store the resulting ids - * @param repo the repository where the commits exist - * @param one one of the commits - * @param two the other commit - * @return 0 on success, GIT_ENOTFOUND if not found or error code - */ -GIT_EXTERN(int) git_merge_bases( - git_oidarray *out, - git_repository *repo, - const git_oid *one, - const git_oid *two); - -/** - * Find a merge base given a list of commits - * - * @param out the OID of a merge base considering all the commits - * @param repo the repository where the commits exist - * @param length The number of commits in the provided `input_array` - * @param input_array oids of the commits - * @return Zero on success; GIT_ENOTFOUND or -1 on failure. - */ -GIT_EXTERN(int) git_merge_base_many( - git_oid *out, - git_repository *repo, - size_t length, - const git_oid input_array[]); - -/** - * Find all merge bases given a list of commits - * - * This behaves similar to [`git merge-base`](https://git-scm.com/docs/git-merge-base#_discussion). - * - * Given three commits `a`, `b`, and `c`, `merge_base_many` - * will compute a hypothetical commit `m`, which is a merge between `b` - * and `c`. - - * For example, with the following topology: - * ```text - * o---o---o---o---C - * / - * / o---o---o---B - * / / - * ---2---1---o---o---o---A - * ``` - * - * the result of `merge_base_many` given `a`, `b`, and `c` is 1. This is - * because the equivalent topology with the imaginary merge commit `m` - * between `b` and `c` is: - * ```text - * o---o---o---o---o - * / \ - * / o---o---o---o---M - * / / - * ---2---1---o---o---o---A - * ``` - * - * and the result of `merge_base_many` given `a` and `m` is 1. - * - * If you're looking to recieve the common ancestor between all the - * given commits, use `merge_base_octopus`. - * - * @param out array in which to store the resulting ids - * @param repo the repository where the commits exist - * @param length The number of commits in the provided `input_array` - * @param input_array oids of the commits - * @return Zero on success; GIT_ENOTFOUND or -1 on failure. - */ -GIT_EXTERN(int) git_merge_bases_many( - git_oidarray *out, - git_repository *repo, - size_t length, - const git_oid input_array[]); - -/** - * Find a merge base in preparation for an octopus merge - * - * @param out the OID of a merge base considering all the commits - * @param repo the repository where the commits exist - * @param length The number of commits in the provided `input_array` - * @param input_array oids of the commits - * @return Zero on success; GIT_ENOTFOUND or -1 on failure. - */ -GIT_EXTERN(int) git_merge_base_octopus( - git_oid *out, - git_repository *repo, - size_t length, - const git_oid input_array[]); - -/** - * Merge two files as they exist in the in-memory data structures, using - * the given common ancestor as the baseline, producing a - * `git_merge_file_result` that reflects the merge result. The - * `git_merge_file_result` must be freed with `git_merge_file_result_free`. - * - * Note that this function does not reference a repository and any - * configuration must be passed as `git_merge_file_options`. - * - * @param out The git_merge_file_result to be filled in - * @param ancestor The contents of the ancestor file - * @param ours The contents of the file in "our" side - * @param theirs The contents of the file in "their" side - * @param opts The merge file options or `NULL` for defaults - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_merge_file( - git_merge_file_result *out, - const git_merge_file_input *ancestor, - const git_merge_file_input *ours, - const git_merge_file_input *theirs, - const git_merge_file_options *opts); - -/** - * Merge two files as they exist in the index, using the given common - * ancestor as the baseline, producing a `git_merge_file_result` that - * reflects the merge result. The `git_merge_file_result` must be - * freed with `git_merge_file_result_free`. - * - * At least one of `ancestor`, `ours`, or `theirs` must be non-null. - * - * @param out The git_merge_file_result to be filled in - * @param repo The repository - * @param ancestor The index entry for the ancestor file (stage level 1) - * @param ours The index entry for our file (stage level 2) - * @param theirs The index entry for their file (stage level 3) - * @param opts The merge file options or NULL - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_merge_file_from_index( - git_merge_file_result *out, - git_repository *repo, - const git_index_entry *ancestor, - const git_index_entry *ours, - const git_index_entry *theirs, - const git_merge_file_options *opts); - -/** - * Frees a `git_merge_file_result`. - * - * @param result The result to free or `NULL` - */ -GIT_EXTERN(void) git_merge_file_result_free(git_merge_file_result *result); - -/** - * Merge two trees, producing a `git_index` that reflects the result of - * the merge. The index may be written as-is to the working directory - * or checked out. If the index is to be converted to a tree, the caller - * should resolve any conflicts that arose as part of the merge. - * - * The returned index must be freed explicitly with `git_index_free`. - * - * @param out pointer to store the index result in - * @param repo repository that contains the given trees - * @param ancestor_tree the common ancestor between the trees (or null if none) - * @param our_tree the tree that reflects the destination tree - * @param their_tree the tree to merge in to `our_tree` - * @param opts the merge tree options (or null for defaults) - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_merge_trees( - git_index **out, - git_repository *repo, - const git_tree *ancestor_tree, - const git_tree *our_tree, - const git_tree *their_tree, - const git_merge_options *opts); - -/** - * Merge two commits, producing a `git_index` that reflects the result of - * the merge. The index may be written as-is to the working directory - * or checked out. If the index is to be converted to a tree, the caller - * should resolve any conflicts that arose as part of the merge. - * - * The returned index must be freed explicitly with `git_index_free`. - * - * @param out pointer to store the index result in - * @param repo repository that contains the given trees - * @param our_commit the commit that reflects the destination tree - * @param their_commit the commit to merge in to `our_commit` - * @param opts the merge tree options (or null for defaults) - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_merge_commits( - git_index **out, - git_repository *repo, - const git_commit *our_commit, - const git_commit *their_commit, - const git_merge_options *opts); - -/** - * Merges the given commit(s) into HEAD, writing the results into the working - * directory. Any changes are staged for commit and any conflicts are written - * to the index. Callers should inspect the repository's index after this - * completes, resolve any conflicts and prepare a commit. - * - * For compatibility with git, the repository is put into a merging - * state. Once the commit is done (or if the user wishes to abort), - * you should clear this state by calling - * `git_repository_state_cleanup()`. - * - * @param repo the repository to merge - * @param their_heads the heads to merge into - * @param their_heads_len the number of heads to merge - * @param merge_opts merge options - * @param checkout_opts checkout options - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_merge( - git_repository *repo, - const git_annotated_commit **their_heads, - size_t their_heads_len, - const git_merge_options *merge_opts, - const git_checkout_options *checkout_opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/message.h b/vendor/libgit2-sys/libgit2/include/git2/message.h deleted file mode 100644 index 874d027..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/message.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_message_h__ -#define INCLUDE_git_message_h__ - -#include "common.h" -#include "buffer.h" - -/** - * @file git2/message.h - * @brief Commit messages - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Clean up excess whitespace and make sure there is a trailing newline in the message. - * - * Optionally, it can remove lines which start with the comment character. - * - * @param out The user-allocated git_buf which will be filled with the - * cleaned up message. - * - * @param message The message to be prettified. - * - * @param strip_comments Non-zero to remove comment lines, 0 to leave them in. - * - * @param comment_char Comment character. Lines starting with this character - * are considered to be comments and removed if `strip_comments` is non-zero. - * - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_message_prettify(git_buf *out, const char *message, int strip_comments, char comment_char); - -/** - * Represents a single git message trailer. - */ -typedef struct { - const char *key; - const char *value; -} git_message_trailer; - -/** - * Represents an array of git message trailers. - * - * Struct members under the private comment are private, subject to change - * and should not be used by callers. - */ -typedef struct { - git_message_trailer *trailers; - size_t count; - - /* private */ - char *_trailer_block; -} git_message_trailer_array; - -/** - * Parse trailers out of a message, filling the array pointed to by +arr+. - * - * Trailers are key/value pairs in the last paragraph of a message, not - * including any patches or conflicts that may be present. - * - * @param arr A pre-allocated git_message_trailer_array struct to be filled in - * with any trailers found during parsing. - * @param message The message to be parsed - * @return 0 on success, or non-zero on error. - */ -GIT_EXTERN(int) git_message_trailers(git_message_trailer_array *arr, const char *message); - -/** - * Clean's up any allocated memory in the git_message_trailer_array filled by - * a call to git_message_trailers. - * - * @param arr The trailer to free. - */ -GIT_EXTERN(void) git_message_trailer_array_free(git_message_trailer_array *arr); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/net.h b/vendor/libgit2-sys/libgit2/include/git2/net.h deleted file mode 100644 index 93bdac4..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/net.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_net_h__ -#define INCLUDE_git_net_h__ - -#include "common.h" -#include "oid.h" -#include "types.h" - -/** - * @file git2/net.h - * @brief Low-level networking functionality - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Default git protocol port number */ -#define GIT_DEFAULT_PORT "9418" - -/** - * Direction of the connection. - * - * We need this because we need to know whether we should call - * git-upload-pack or git-receive-pack on the remote end when get_refs - * gets called. - */ -typedef enum { - GIT_DIRECTION_FETCH = 0, - GIT_DIRECTION_PUSH = 1 -} git_direction; - -/** - * Description of a reference advertised by a remote server, given out - * on `ls` calls. - */ -struct git_remote_head { - int local; /* available locally */ - git_oid oid; - git_oid loid; - char *name; - /** - * If the server send a symref mapping for this ref, this will - * point to the target. - */ - char *symref_target; -}; - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/notes.h b/vendor/libgit2-sys/libgit2/include/git2/notes.h deleted file mode 100644 index 3784d5f..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/notes.h +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_note_h__ -#define INCLUDE_git_note_h__ - -#include "oid.h" - -/** - * @file git2/notes.h - * @brief Notes are metadata attached to an object - * @defgroup git_note Git notes management routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Callback for git_note_foreach. - * - * @param blob_id object id of the blob containing the message - * @param annotated_object_id the id of the object being annotated - * @param payload user-specified data to the foreach function - * @return 0 on success, or a negative number on failure - */ -typedef int GIT_CALLBACK(git_note_foreach_cb)( - const git_oid *blob_id, - const git_oid *annotated_object_id, - void *payload); - -/** - * note iterator - */ -typedef struct git_iterator git_note_iterator; - -/** - * Creates a new iterator for notes - * - * The iterator must be freed manually by the user. - * - * @param out pointer to the iterator - * @param repo repository where to look up the note - * @param notes_ref canonical name of the reference to use (optional); defaults to - * "refs/notes/commits" - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_iterator_new( - git_note_iterator **out, - git_repository *repo, - const char *notes_ref); - -/** - * Creates a new iterator for notes from a commit - * - * The iterator must be freed manually by the user. - * - * @param out pointer to the iterator - * @param notes_commit a pointer to the notes commit object - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_commit_iterator_new( - git_note_iterator **out, - git_commit *notes_commit); - -/** - * Frees an git_note_iterator - * - * @param it pointer to the iterator - */ -GIT_EXTERN(void) git_note_iterator_free(git_note_iterator *it); - -/** - * Return the current item (note_id and annotated_id) and advance the iterator - * internally to the next value - * - * @param note_id id of blob containing the message - * @param annotated_id id of the git object being annotated - * @param it pointer to the iterator - * - * @return 0 (no error), GIT_ITEROVER (iteration is done) or an error code - * (negative value) - */ -GIT_EXTERN(int) git_note_next( - git_oid *note_id, - git_oid *annotated_id, - git_note_iterator *it); - - -/** - * Read the note for an object - * - * The note must be freed manually by the user. - * - * @param out pointer to the read note; NULL in case of error - * @param repo repository where to look up the note - * @param notes_ref canonical name of the reference to use (optional); defaults to - * "refs/notes/commits" - * @param oid OID of the git object to read the note from - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_read( - git_note **out, - git_repository *repo, - const char *notes_ref, - const git_oid *oid); - - -/** - * Read the note for an object from a note commit - * - * The note must be freed manually by the user. - * - * @param out pointer to the read note; NULL in case of error - * @param repo repository where to look up the note - * @param notes_commit a pointer to the notes commit object - * @param oid OID of the git object to read the note from - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_commit_read( - git_note **out, - git_repository *repo, - git_commit *notes_commit, - const git_oid *oid); - -/** - * Get the note author - * - * @param note the note - * @return the author - */ -GIT_EXTERN(const git_signature *) git_note_author(const git_note *note); - -/** - * Get the note committer - * - * @param note the note - * @return the committer - */ -GIT_EXTERN(const git_signature *) git_note_committer(const git_note *note); - - -/** - * Get the note message - * - * @param note the note - * @return the note message - */ -GIT_EXTERN(const char *) git_note_message(const git_note *note); - - -/** - * Get the note object's id - * - * @param note the note - * @return the note object's id - */ -GIT_EXTERN(const git_oid *) git_note_id(const git_note *note); - -/** - * Add a note for an object - * - * @param out pointer to store the OID (optional); NULL in case of error - * @param repo repository where to store the note - * @param notes_ref canonical name of the reference to use (optional); - * defaults to "refs/notes/commits" - * @param author signature of the notes commit author - * @param committer signature of the notes commit committer - * @param oid OID of the git object to decorate - * @param note Content of the note to add for object oid - * @param force Overwrite existing note - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_create( - git_oid *out, - git_repository *repo, - const char *notes_ref, - const git_signature *author, - const git_signature *committer, - const git_oid *oid, - const char *note, - int force); - -/** - * Add a note for an object from a commit - * - * This function will create a notes commit for a given object, - * the commit is a dangling commit, no reference is created. - * - * @param notes_commit_out pointer to store the commit (optional); - * NULL in case of error - * @param notes_blob_out a point to the id of a note blob (optional) - * @param repo repository where the note will live - * @param parent Pointer to parent note - * or NULL if this shall start a new notes tree - * @param author signature of the notes commit author - * @param committer signature of the notes commit committer - * @param oid OID of the git object to decorate - * @param note Content of the note to add for object oid - * @param allow_note_overwrite Overwrite existing note - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_commit_create( - git_oid *notes_commit_out, - git_oid *notes_blob_out, - git_repository *repo, - git_commit *parent, - const git_signature *author, - const git_signature *committer, - const git_oid *oid, - const char *note, - int allow_note_overwrite); - -/** - * Remove the note for an object - * - * @param repo repository where the note lives - * @param notes_ref canonical name of the reference to use (optional); - * defaults to "refs/notes/commits" - * @param author signature of the notes commit author - * @param committer signature of the notes commit committer - * @param oid OID of the git object to remove the note from - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_remove( - git_repository *repo, - const char *notes_ref, - const git_signature *author, - const git_signature *committer, - const git_oid *oid); - -/** - * Remove the note for an object - * - * @param notes_commit_out pointer to store the new notes commit (optional); - * NULL in case of error. - * When removing a note a new tree containing all notes - * sans the note to be removed is created and a new commit - * pointing to that tree is also created. - * In the case where the resulting tree is an empty tree - * a new commit pointing to this empty tree will be returned. - * @param repo repository where the note lives - * @param notes_commit a pointer to the notes commit object - * @param author signature of the notes commit author - * @param committer signature of the notes commit committer - * @param oid OID of the git object to remove the note from - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_commit_remove( - git_oid *notes_commit_out, - git_repository *repo, - git_commit *notes_commit, - const git_signature *author, - const git_signature *committer, - const git_oid *oid); - -/** - * Free a git_note object - * - * @param note git_note object - */ -GIT_EXTERN(void) git_note_free(git_note *note); - -/** - * Get the default notes reference for a repository - * - * @param out buffer in which to store the name of the default notes reference - * @param repo The Git repository - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_note_default_ref(git_buf *out, git_repository *repo); - -/** - * Loop over all the notes within a specified namespace - * and issue a callback for each one. - * - * @param repo Repository where to find the notes. - * - * @param notes_ref Reference to read from (optional); defaults to - * "refs/notes/commits". - * - * @param note_cb Callback to invoke per found annotation. Return non-zero - * to stop looping. - * - * @param payload Extra parameter to callback function. - * - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_note_foreach( - git_repository *repo, - const char *notes_ref, - git_note_foreach_cb note_cb, - void *payload); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/object.h b/vendor/libgit2-sys/libgit2/include/git2/object.h deleted file mode 100644 index 8a50239..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/object.h +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_object_h__ -#define INCLUDE_git_object_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "buffer.h" - -/** - * @file git2/object.h - * @brief Objects are blobs (files), trees (directories), commits, and annotated tags - * @defgroup git_object Git revision object management routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Maximum size of a git object */ -#define GIT_OBJECT_SIZE_MAX UINT64_MAX - -/** - * Lookup a reference to one of the objects in a repository. - * - * The generated reference is owned by the repository and - * should be closed with the `git_object_free` method - * instead of free'd manually. - * - * The 'type' parameter must match the type of the object - * in the odb; the method will fail otherwise. - * The special value 'GIT_OBJECT_ANY' may be passed to let - * the method guess the object's type. - * - * @param object pointer to the looked-up object - * @param repo the repository to look up the object - * @param id the unique identifier for the object - * @param type the type of the object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_object_lookup( - git_object **object, - git_repository *repo, - const git_oid *id, - git_object_t type); - -/** - * Lookup a reference to one of the objects in a repository, - * given a prefix of its identifier (short id). - * - * The object obtained will be so that its identifier - * matches the first 'len' hexadecimal characters - * (packets of 4 bits) of the given `id`. `len` must be - * at least `GIT_OID_MINPREFIXLEN`, and long enough to - * identify a unique object matching the prefix; otherwise - * the method will fail. - * - * The generated reference is owned by the repository and - * should be closed with the `git_object_free` method - * instead of free'd manually. - * - * The `type` parameter must match the type of the object - * in the odb; the method will fail otherwise. - * The special value `GIT_OBJECT_ANY` may be passed to let - * the method guess the object's type. - * - * @param object_out pointer where to store the looked-up object - * @param repo the repository to look up the object - * @param id a short identifier for the object - * @param len the length of the short identifier - * @param type the type of the object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_object_lookup_prefix( - git_object **object_out, - git_repository *repo, - const git_oid *id, - size_t len, - git_object_t type); - - -/** - * Lookup an object that represents a tree entry. - * - * @param out buffer that receives a pointer to the object (which must be freed - * by the caller) - * @param treeish root object that can be peeled to a tree - * @param path relative path from the root object to the desired object - * @param type type of object desired - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_object_lookup_bypath( - git_object **out, - const git_object *treeish, - const char *path, - git_object_t type); - -/** - * Get the id (SHA1) of a repository object - * - * @param obj the repository object - * @return the SHA1 id - */ -GIT_EXTERN(const git_oid *) git_object_id(const git_object *obj); - -/** - * Get a short abbreviated OID string for the object - * - * This starts at the "core.abbrev" length (default 7 characters) and - * iteratively extends to a longer string if that length is ambiguous. - * The result will be unambiguous (at least until new objects are added to - * the repository). - * - * @param out Buffer to write string into - * @param obj The object to get an ID for - * @return 0 on success, <0 for error - */ -GIT_EXTERN(int) git_object_short_id(git_buf *out, const git_object *obj); - -/** - * Get the object type of an object - * - * @param obj the repository object - * @return the object's type - */ -GIT_EXTERN(git_object_t) git_object_type(const git_object *obj); - -/** - * Get the repository that owns this object - * - * Freeing or calling `git_repository_close` on the - * returned pointer will invalidate the actual object. - * - * Any other operation may be run on the repository without - * affecting the object. - * - * @param obj the object - * @return the repository who owns this object - */ -GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj); - -/** - * Close an open object - * - * This method instructs the library to close an existing - * object; note that git_objects are owned and cached by the repository - * so the object may or may not be freed after this library call, - * depending on how aggressive is the caching mechanism used - * by the repository. - * - * IMPORTANT: - * It *is* necessary to call this method when you stop using - * an object. Failure to do so will cause a memory leak. - * - * @param object the object to close - */ -GIT_EXTERN(void) git_object_free(git_object *object); - -/** - * Convert an object type to its string representation. - * - * The result is a pointer to a string in static memory and - * should not be free()'ed. - * - * @param type object type to convert. - * @return the corresponding string representation. - */ -GIT_EXTERN(const char *) git_object_type2string(git_object_t type); - -/** - * Convert a string object type representation to it's git_object_t. - * - * @param str the string to convert. - * @return the corresponding git_object_t. - */ -GIT_EXTERN(git_object_t) git_object_string2type(const char *str); - -/** - * Determine if the given git_object_t is a valid loose object type. - * - * @param type object type to test. - * @return true if the type represents a valid loose object type, - * false otherwise. - */ -GIT_EXTERN(int) git_object_typeisloose(git_object_t type); - -/** - * Recursively peel an object until an object of the specified type is met. - * - * If the query cannot be satisfied due to the object model, - * GIT_EINVALIDSPEC will be returned (e.g. trying to peel a blob to a - * tree). - * - * If you pass `GIT_OBJECT_ANY` as the target type, then the object will - * be peeled until the type changes. A tag will be peeled until the - * referenced object is no longer a tag, and a commit will be peeled - * to a tree. Any other object type will return GIT_EINVALIDSPEC. - * - * If peeling a tag we discover an object which cannot be peeled to - * the target type due to the object model, GIT_EPEEL will be - * returned. - * - * You must free the returned object. - * - * @param peeled Pointer to the peeled git_object - * @param object The object to be processed - * @param target_type The type of the requested object (a GIT_OBJECT_ value) - * @return 0 on success, GIT_EINVALIDSPEC, GIT_EPEEL, or an error code - */ -GIT_EXTERN(int) git_object_peel( - git_object **peeled, - const git_object *object, - git_object_t target_type); - -/** - * Create an in-memory copy of a Git object. The copy must be - * explicitly free'd or it will leak. - * - * @param dest Pointer to store the copy of the object - * @param source Original object to copy - * @return 0 or an error code - */ -GIT_EXTERN(int) git_object_dup(git_object **dest, git_object *source); - -#ifdef GIT_EXPERIMENTAL_SHA256 -/** - * Analyzes a buffer of raw object content and determines its validity. - * Tree, commit, and tag objects will be parsed and ensured that they - * are valid, parseable content. (Blobs are always valid by definition.) - * An error message will be set with an informative message if the object - * is not valid. - * - * @warning This function is experimental and its signature may change in - * the future. - * - * @param valid Output pointer to set with validity of the object content - * @param buf The contents to validate - * @param len The length of the buffer - * @param object_type The type of the object in the buffer - * @param oid_type The object ID type for the OIDs in the given buffer - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_object_rawcontent_is_valid( - int *valid, - const char *buf, - size_t len, - git_object_t object_type, - git_oid_t oid_type); -#else -/** - * Analyzes a buffer of raw object content and determines its validity. - * Tree, commit, and tag objects will be parsed and ensured that they - * are valid, parseable content. (Blobs are always valid by definition.) - * An error message will be set with an informative message if the object - * is not valid. - * - * @warning This function is experimental and its signature may change in - * the future. - * - * @param[out] valid Output pointer to set with validity of the object content - * @param buf The contents to validate - * @param len The length of the buffer - * @param object_type The type of the object in the buffer - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_object_rawcontent_is_valid( - int *valid, - const char *buf, - size_t len, - git_object_t object_type); -#endif - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/odb.h b/vendor/libgit2-sys/libgit2/include/git2/odb.h deleted file mode 100644 index e809c36..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/odb.h +++ /dev/null @@ -1,696 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_odb_h__ -#define INCLUDE_git_odb_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "oidarray.h" -#include "indexer.h" - -/** - * @file git2/odb.h - * @brief An object database manages the storage of git objects - * @defgroup git_odb Git object database routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Flags controlling the behavior of ODB lookup operations */ -typedef enum { - /** - * Don't call `git_odb_refresh` if the lookup fails. Useful when doing - * a batch of lookup operations for objects that may legitimately not - * exist. When using this flag, you may wish to manually call - * `git_odb_refresh` before processing a batch of objects. - */ - GIT_ODB_LOOKUP_NO_REFRESH = (1 << 0) -} git_odb_lookup_flags_t; - -/** - * Function type for callbacks from git_odb_foreach. - * - * @param id an id of an object in the object database - * @param payload the payload from the initial call to git_odb_foreach - * @return 0 on success, or an error code - */ -typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload); - -/** Options for configuring a loose object backend. */ -typedef struct { - unsigned int version; /**< version for the struct */ - - /** - * Type of object IDs to use for this object database, or - * 0 for default (currently SHA1). - */ - git_oid_t oid_type; -} git_odb_options; - -/** The current version of the diff options structure */ -#define GIT_ODB_OPTIONS_VERSION 1 - -/** - * Stack initializer for odb options. Alternatively use - * `git_odb_options_init` programmatic initialization. - */ -#define GIT_ODB_OPTIONS_INIT { GIT_ODB_OPTIONS_VERSION } - -#ifdef GIT_EXPERIMENTAL_SHA256 - -/** - * Create a new object database with no backends. - * - * @param[out] odb location to store the database pointer, if opened. - * @param opts the options for this object database or NULL for defaults - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_new(git_odb **odb, const git_odb_options *opts); - -/** - * Create a new object database and automatically add loose and packed - * backends. - * - * @param[out] odb_out location to store the database pointer, if opened. - * Set to NULL if the open failed. - * @param objects_dir path of the backends' "objects" directory. - * @param opts the options for this object database or NULL for defaults - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_open( - git_odb **odb_out, - const char *objects_dir, - const git_odb_options *opts); - -#else - -/** - * Create a new object database with no backends. - * - * Before the ODB can be used for read/writing, a custom database - * backend must be manually added using `git_odb_add_backend()` - * - * @param[out] odb location to store the database pointer, if opened. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_new(git_odb **odb); - -/** - * Create a new object database and automatically add - * the two default backends: - * - * - git_odb_backend_loose: read and write loose object files - * from disk, assuming `objects_dir` as the Objects folder - * - * - git_odb_backend_pack: read objects from packfiles, - * assuming `objects_dir` as the Objects folder which - * contains a 'pack/' folder with the corresponding data - * - * @param[out] odb_out location to store the database pointer, if opened. - * Set to NULL if the open failed. - * @param objects_dir path of the backends' "objects" directory. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_open(git_odb **odb_out, const char *objects_dir); -#endif - -/** - * Add an on-disk alternate to an existing Object DB. - * - * Note that the added path must point to an `objects`, not - * to a full repository, to use it as an alternate store. - * - * Alternate backends are always checked for objects *after* - * all the main backends have been exhausted. - * - * Writing is disabled on alternate backends. - * - * @param odb database to add the backend to - * @param path path to the objects folder for the alternate - * @return 0 on success, error code otherwise - */ -GIT_EXTERN(int) git_odb_add_disk_alternate(git_odb *odb, const char *path); - -/** - * Close an open object database. - * - * @param db database pointer to close. If NULL no action is taken. - */ -GIT_EXTERN(void) git_odb_free(git_odb *db); - -/** - * Read an object from the database. - * - * This method queries all available ODB backends - * trying to read the given OID. - * - * The returned object is reference counted and - * internally cached, so it should be closed - * by the user once it's no longer in use. - * - * @param[out] obj pointer where to store the read object - * @param db database to search for the object in. - * @param id identity of the object to read. - * @return 0 if the object was read, GIT_ENOTFOUND if the object is - * not in the database. - */ -GIT_EXTERN(int) git_odb_read(git_odb_object **obj, git_odb *db, const git_oid *id); - -/** - * Read an object from the database, given a prefix - * of its identifier. - * - * This method queries all available ODB backends - * trying to match the 'len' first hexadecimal - * characters of the 'short_id'. - * The remaining (GIT_OID_SHA1_HEXSIZE-len)*4 bits of - * 'short_id' must be 0s. - * 'len' must be at least GIT_OID_MINPREFIXLEN, - * and the prefix must be long enough to identify - * a unique object in all the backends; the - * method will fail otherwise. - * - * The returned object is reference counted and - * internally cached, so it should be closed - * by the user once it's no longer in use. - * - * @param[out] obj pointer where to store the read object - * @param db database to search for the object in. - * @param short_id a prefix of the id of the object to read. - * @param len the length of the prefix - * @return 0 if the object was read, GIT_ENOTFOUND if the object is not in the - * database. GIT_EAMBIGUOUS if the prefix is ambiguous - * (several objects match the prefix) - */ -GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **obj, git_odb *db, const git_oid *short_id, size_t len); - -/** - * Read the header of an object from the database, without - * reading its full contents. - * - * The header includes the length and the type of an object. - * - * Note that most backends do not support reading only the header - * of an object, so the whole object will be read and then the - * header will be returned. - * - * @param[out] len_out pointer where to store the length - * @param[out] type_out pointer where to store the type - * @param db database to search for the object in. - * @param id identity of the object to read. - * @return 0 if the object was read, GIT_ENOTFOUND if the object is not - * in the database. - */ -GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_object_t *type_out, git_odb *db, const git_oid *id); - -/** - * Determine if the given object can be found in the object database. - * - * @param db database to be searched for the given object. - * @param id the object to search for. - * @return 1 if the object was found, 0 otherwise - */ -GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id); - -/** - * Determine if the given object can be found in the object database, with - * extended options. - * - * @param db database to be searched for the given object. - * @param id the object to search for. - * @param flags flags affecting the lookup (see `git_odb_lookup_flags_t`) - * @return 1 if the object was found, 0 otherwise - */ -GIT_EXTERN(int) git_odb_exists_ext(git_odb *db, const git_oid *id, unsigned int flags); - -/** - * Determine if an object can be found in the object database by an - * abbreviated object ID. - * - * @param out The full OID of the found object if just one is found. - * @param db The database to be searched for the given object. - * @param short_id A prefix of the id of the object to read. - * @param len The length of the prefix. - * @return 0 if found, GIT_ENOTFOUND if not found, GIT_EAMBIGUOUS if multiple - * matches were found, other value < 0 if there was a read error. - */ -GIT_EXTERN(int) git_odb_exists_prefix( - git_oid *out, git_odb *db, const git_oid *short_id, size_t len); - -/** - * The information about object IDs to query in `git_odb_expand_ids`, - * which will be populated upon return. - */ -typedef struct git_odb_expand_id { - /** The object ID to expand */ - git_oid id; - - /** - * The length of the object ID (in nibbles, or packets of 4 bits; the - * number of hex characters) - * */ - unsigned short length; - - /** - * The (optional) type of the object to search for; leave as `0` or set - * to `GIT_OBJECT_ANY` to query for any object matching the ID. - */ - git_object_t type; -} git_odb_expand_id; - -/** - * Determine if one or more objects can be found in the object database - * by their abbreviated object ID and type. - * - * The given array will be updated in place: for each abbreviated ID that is - * unique in the database, and of the given type (if specified), - * the full object ID, object ID length (`GIT_OID_SHA1_HEXSIZE`) and type will be - * written back to the array. For IDs that are not found (or are ambiguous), - * the array entry will be zeroed. - * - * Note that since this function operates on multiple objects, the - * underlying database will not be asked to be reloaded if an object is - * not found (which is unlike other object database operations.) - * - * @param db The database to be searched for the given objects. - * @param ids An array of short object IDs to search for - * @param count The length of the `ids` array - * @return 0 on success or an error code on failure - */ -GIT_EXTERN(int) git_odb_expand_ids( - git_odb *db, - git_odb_expand_id *ids, - size_t count); - -/** - * Refresh the object database to load newly added files. - * - * If the object databases have changed on disk while the library - * is running, this function will force a reload of the underlying - * indexes. - * - * Use this function when you're confident that an external - * application has tampered with the ODB. - * - * NOTE that it is not necessary to call this function at all. The - * library will automatically attempt to refresh the ODB - * when a lookup fails, to see if the looked up object exists - * on disk but hasn't been loaded yet. - * - * @param db database to refresh - * @return 0 on success, error code otherwise - */ -GIT_EXTERN(int) git_odb_refresh(git_odb *db); - -/** - * List all objects available in the database - * - * The callback will be called for each object available in the - * database. Note that the objects are likely to be returned in the index - * order, which would make accessing the objects in that order inefficient. - * Return a non-zero value from the callback to stop looping. - * - * @param db database to use - * @param cb the callback to call for each object - * @param payload data to pass to the callback - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_odb_foreach( - git_odb *db, - git_odb_foreach_cb cb, - void *payload); - -/** - * Write an object directly into the ODB - * - * This method writes a full object straight into the ODB. - * For most cases, it is preferred to write objects through a write - * stream, which is both faster and less memory intensive, specially - * for big objects. - * - * This method is provided for compatibility with custom backends - * which are not able to support streaming writes - * - * @param out pointer to store the OID result of the write - * @param odb object database where to store the object - * @param data @type `const unsigned char *` buffer with the data to store - * @param len size of the buffer - * @param type type of the data to store - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_object_t type); - -/** - * Open a stream to write an object into the ODB - * - * The type and final length of the object must be specified - * when opening the stream. - * - * The returned stream will be of type `GIT_STREAM_WRONLY`, and it - * won't be effective until `git_odb_stream_finalize_write` is called - * and returns without an error - * - * The stream must always be freed when done with `git_odb_stream_free` or - * will leak memory. - * - * @see git_odb_stream - * - * @param out pointer where to store the stream - * @param db object database where the stream will write - * @param size final size of the object that will be written - * @param type type of the object that will be written - * @return 0 if the stream was created; error code otherwise - */ -GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_object_size_t size, git_object_t type); - -/** - * Write to an odb stream - * - * This method will fail if the total number of received bytes exceeds the - * size declared with `git_odb_open_wstream()` - * - * @param stream the stream - * @param buffer the data to write - * @param len the buffer's length - * @return 0 if the write succeeded, error code otherwise - */ -GIT_EXTERN(int) git_odb_stream_write(git_odb_stream *stream, const char *buffer, size_t len); - -/** - * Finish writing to an odb stream - * - * The object will take its final name and will be available to the - * odb. - * - * This method will fail if the total number of received bytes - * differs from the size declared with `git_odb_open_wstream()` - * - * @param out pointer to store the resulting object's id - * @param stream the stream - * @return 0 on success, an error code otherwise - */ -GIT_EXTERN(int) git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream); - -/** - * Read from an odb stream - * - * Most backends don't implement streaming reads - * - * @param stream the stream - * @param buffer a user-allocated buffer to store the data in. - * @param len the buffer's length - * @return the number of bytes read if succeeded, error code otherwise - */ -GIT_EXTERN(int) git_odb_stream_read(git_odb_stream *stream, char *buffer, size_t len); - -/** - * Free an odb stream - * - * @param stream the stream to free - */ -GIT_EXTERN(void) git_odb_stream_free(git_odb_stream *stream); - -/** - * Open a stream to read an object from the ODB - * - * Note that most backends do *not* support streaming reads - * because they store their objects as compressed/delta'ed blobs. - * - * It's recommended to use `git_odb_read` instead, which is - * assured to work on all backends. - * - * The returned stream will be of type `GIT_STREAM_RDONLY` and - * will have the following methods: - * - * - stream->read: read `n` bytes from the stream - * - stream->free: free the stream - * - * The stream must always be free'd or will leak memory. - * - * @see git_odb_stream - * - * @param out pointer where to store the stream - * @param len pointer where to store the length of the object - * @param type pointer where to store the type of the object - * @param db object database where the stream will read from - * @param oid oid of the object the stream will read from - * @return 0 if the stream was created, error code otherwise - */ -GIT_EXTERN(int) git_odb_open_rstream( - git_odb_stream **out, - size_t *len, - git_object_t *type, - git_odb *db, - const git_oid *oid); - -/** - * Open a stream for writing a pack file to the ODB. - * - * If the ODB layer understands pack files, then the given - * packfile will likely be streamed directly to disk (and a - * corresponding index created). If the ODB layer does not - * understand pack files, the objects will be stored in whatever - * format the ODB layer uses. - * - * @see git_odb_writepack - * - * @param out pointer to the writepack functions - * @param db object database where the stream will read from - * @param progress_cb function to call with progress information. - * Be aware that this is called inline with network and indexing operations, - * so performance may be affected. - * @param progress_payload payload for the progress callback - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_odb_write_pack( - git_odb_writepack **out, - git_odb *db, - git_indexer_progress_cb progress_cb, - void *progress_payload); - -/** - * Write a `multi-pack-index` file from all the `.pack` files in the ODB. - * - * If the ODB layer understands pack files, then this will create a file called - * `multi-pack-index` next to the `.pack` and `.idx` files, which will contain - * an index of all objects stored in `.pack` files. This will allow for - * O(log n) lookup for n objects (regardless of how many packfiles there - * exist). - * - * @param db object database where the `multi-pack-index` file will be written. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_odb_write_multi_pack_index( - git_odb *db); - -#ifdef GIT_EXPERIMENTAL_SHA256 - -/** - * Generate the object ID (in SHA1 or SHA256 format) for a given data buffer. - * - * @param[out] oid the resulting object ID. - * @param data data to hash - * @param len size of the data - * @param object_type of the data to hash - * @param oid_type the oid type to hash to - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_hash( - git_oid *oid, - const void *data, - size_t len, - git_object_t object_type, - git_oid_t oid_type); - -/** - * Determine the object ID of a file on disk. - * - * @param[out] oid oid structure the result is written into. - * @param path file to read and determine object id for - * @param object_type of the data to hash - * @param oid_type the oid type to hash to - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_hashfile( - git_oid *oid, - const char *path, - git_object_t object_type, - git_oid_t oid_type); -#else - -/** - * Determine the object-ID (sha1 or sha256 hash) of a data buffer - * - * The resulting OID will be the identifier for the data buffer as if - * the data buffer it were to written to the ODB. - * - * @param[out] oid the resulting object-ID. - * @param data data to hash - * @param len size of the data - * @param object_type of the data to hash - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_hash(git_oid *oid, const void *data, size_t len, git_object_t object_type); - -/** - * Read a file from disk and fill a git_oid with the object id - * that the file would have if it were written to the Object - * Database as an object of the given type (w/o applying filters). - * Similar functionality to git.git's `git hash-object` without - * the `-w` flag, however, with the --no-filters flag. - * If you need filters, see git_repository_hashfile. - * - * @param[out] oid oid structure the result is written into. - * @param path file to read and determine object id for - * @param object_type of the data to hash - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_hashfile(git_oid *oid, const char *path, git_object_t object_type); - -#endif - -/** - * Create a copy of an odb_object - * - * The returned copy must be manually freed with `git_odb_object_free`. - * Note that because of an implementation detail, the returned copy will be - * the same pointer as `source`: the object is internally refcounted, so the - * copy still needs to be freed twice. - * - * @param dest pointer where to store the copy - * @param source object to copy - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_object_dup(git_odb_object **dest, git_odb_object *source); - -/** - * Close an ODB object - * - * This method must always be called once a `git_odb_object` is no - * longer needed, otherwise memory will leak. - * - * @param object object to close - */ -GIT_EXTERN(void) git_odb_object_free(git_odb_object *object); - -/** - * Return the OID of an ODB object - * - * This is the OID from which the object was read from - * - * @param object the object - * @return a pointer to the OID - */ -GIT_EXTERN(const git_oid *) git_odb_object_id(git_odb_object *object); - -/** - * Return the data of an ODB object - * - * This is the uncompressed, raw data as read from the ODB, - * without the leading header. - * - * This pointer is owned by the object and shall not be free'd. - * - * @param object the object - * @return @type `const unsigned char *` a pointer to the data - */ -GIT_EXTERN(const void *) git_odb_object_data(git_odb_object *object); - -/** - * Return the size of an ODB object - * - * This is the real size of the `data` buffer, not the - * actual size of the object. - * - * @param object the object - * @return the size - */ -GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object); - -/** - * Return the type of an ODB object - * - * @param object the object - * @return the type - */ -GIT_EXTERN(git_object_t) git_odb_object_type(git_odb_object *object); - -/** - * Add a custom backend to an existing Object DB - * - * The backends are checked in relative ordering, based on the - * value of the `priority` parameter. - * - * Read for more information. - * - * @param odb database to add the backend to - * @param backend pointer to a git_odb_backend instance - * @param priority Value for ordering the backends queue - * @return 0 on success, error code otherwise - */ -GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority); - -/** - * Add a custom backend to an existing Object DB; this - * backend will work as an alternate. - * - * Alternate backends are always checked for objects *after* - * all the main backends have been exhausted. - * - * The backends are checked in relative ordering, based on the - * value of the `priority` parameter. - * - * Writing is disabled on alternate backends. - * - * Read for more information. - * - * @param odb database to add the backend to - * @param backend pointer to a git_odb_backend instance - * @param priority Value for ordering the backends queue - * @return 0 on success, error code otherwise - */ -GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority); - -/** - * Get the number of ODB backend objects - * - * @param odb object database - * @return number of backends in the ODB - */ -GIT_EXTERN(size_t) git_odb_num_backends(git_odb *odb); - -/** - * Lookup an ODB backend object by index - * - * @param out output pointer to ODB backend at pos - * @param odb object database - * @param pos index into object database backend list - * @return 0 on success, GIT_ENOTFOUND if pos is invalid, other errors < 0 - */ -GIT_EXTERN(int) git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos); - -/** - * Set the git commit-graph for the ODB. - * - * After a successful call, the ownership of the cgraph parameter will be - * transferred to libgit2, and the caller should not free it. - * - * The commit-graph can also be unset by explicitly passing NULL as the cgraph - * parameter. - * - * @param odb object database - * @param cgraph the git commit-graph - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_odb_set_commit_graph(git_odb *odb, git_commit_graph *cgraph); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/odb_backend.h b/vendor/libgit2-sys/libgit2/include/git2/odb_backend.h deleted file mode 100644 index 88ca29f..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/odb_backend.h +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_odb_backend_h__ -#define INCLUDE_git_odb_backend_h__ - -#include "common.h" -#include "types.h" -#include "indexer.h" - -/** - * @file git2/backend.h - * @brief Object database backends manage the storage of git objects - * @defgroup git_odb Git object database routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Options for configuring a packfile object backend. */ -typedef struct { - unsigned int version; /**< version for the struct */ - - /** - * Type of object IDs to use for this object database, or - * 0 for default (currently SHA1). - */ - git_oid_t oid_type; -} git_odb_backend_pack_options; - -/** The current version of the diff options structure */ -#define GIT_ODB_BACKEND_PACK_OPTIONS_VERSION 1 - -/** - * Stack initializer for odb pack backend options. Alternatively use - * `git_odb_backend_pack_options_init` programmatic initialization. - */ -#define GIT_ODB_BACKEND_PACK_OPTIONS_INIT \ - { GIT_ODB_BACKEND_PACK_OPTIONS_VERSION } - -typedef enum { - GIT_ODB_BACKEND_LOOSE_FSYNC = (1 << 0) -} git_odb_backend_loose_flag_t; - -/** Options for configuring a loose object backend. */ -typedef struct { - unsigned int version; /**< version for the struct */ - - /** A combination of the `git_odb_backend_loose_flag_t` types. */ - uint32_t flags; - - /** - * zlib compression level to use (0-9), where 1 is the fastest - * at the expense of larger files, and 9 produces the best - * compression at the expense of speed. 0 indicates that no - * compression should be performed. -1 is the default (currently - * optimizing for speed). - */ - int compression_level; - - /** Permissions to use creating a directory or 0 for defaults */ - unsigned int dir_mode; - - /** Permissions to use creating a file or 0 for defaults */ - unsigned int file_mode; - - /** - * Type of object IDs to use for this object database, or - * 0 for default (currently SHA1). - */ - git_oid_t oid_type; -} git_odb_backend_loose_options; - -/** The current version of the diff options structure */ -#define GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION 1 - -/** - * Stack initializer for odb loose backend options. Alternatively use - * `git_odb_backend_loose_options_init` programmatic initialization. - */ -#define GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT \ - { GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION, 0, -1 } - -/* - * Constructors for in-box ODB backends. - */ - -#ifdef GIT_EXPERIMENTAL_SHA256 - -/** - * Create a backend for a directory containing packfiles. - * - * @param[out] out location to store the odb backend pointer - * @param objects_dir the Git repository's objects directory - * @param opts the options to use when creating the pack backend - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_backend_pack( - git_odb_backend **out, - const char *objects_dir, - const git_odb_backend_pack_options *opts); - -/** - * Create a backend for a single packfile. - * - * @param[out] out location to store the odb backend pointer - * @param index_file path to the packfile's .idx file - * @param opts the options to use when creating the pack backend - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_backend_one_pack( - git_odb_backend **out, - const char *index_file, - const git_odb_backend_pack_options *opts); - -/** - * Create a backend for loose objects - * - * @param[out] out location to store the odb backend pointer - * @param objects_dir the Git repository's objects directory - * @param opts options for the loose object backend or NULL - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_backend_loose( - git_odb_backend **out, - const char *objects_dir, - git_odb_backend_loose_options *opts); - -#else - -/** - * Create a backend for a directory containing packfiles. - * - * @param[out] out location to store the odb backend pointer - * @param objects_dir the Git repository's objects directory - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_backend_pack( - git_odb_backend **out, - const char *objects_dir); - -/** - * Create a backend out of a single packfile - * - * This can be useful for inspecting the contents of a single - * packfile. - * - * @param[out] out location to store the odb backend pointer - * @param index_file path to the packfile's .idx file - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_backend_one_pack( - git_odb_backend **out, - const char *index_file); - -/** - * Create a backend for loose objects - * - * @param[out] out location to store the odb backend pointer - * @param objects_dir the Git repository's objects directory - * @param compression_level zlib compression level (0-9), or -1 for the default - * @param do_fsync if non-zero, perform an fsync on write - * @param dir_mode permission to use when creating directories, or 0 for default - * @param file_mode permission to use when creating directories, or 0 for default - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_backend_loose( - git_odb_backend **out, - const char *objects_dir, - int compression_level, - int do_fsync, - unsigned int dir_mode, - unsigned int file_mode); - -#endif - -/** Streaming mode */ -typedef enum { - GIT_STREAM_RDONLY = (1 << 1), - GIT_STREAM_WRONLY = (1 << 2), - GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY) -} git_odb_stream_t; - -/** - * A stream to read/write from a backend. - * - * This represents a stream of data being written to or read from a - * backend. When writing, the frontend functions take care of - * calculating the object's id and all `finalize_write` needs to do is - * store the object with the id it is passed. - */ -struct git_odb_stream { - git_odb_backend *backend; - unsigned int mode; - void *hash_ctx; - -#ifdef GIT_EXPERIMENTAL_SHA256 - git_oid_t oid_type; -#endif - - git_object_size_t declared_size; - git_object_size_t received_bytes; - - /** - * Write at most `len` bytes into `buffer` and advance the stream. - */ - int GIT_CALLBACK(read)(git_odb_stream *stream, char *buffer, size_t len); - - /** - * Write `len` bytes from `buffer` into the stream. - */ - int GIT_CALLBACK(write)(git_odb_stream *stream, const char *buffer, size_t len); - - /** - * Store the contents of the stream as an object with the id - * specified in `oid`. - * - * This method might not be invoked if: - * - an error occurs earlier with the `write` callback, - * - the object referred to by `oid` already exists in any backend, or - * - the final number of received bytes differs from the size declared - * with `git_odb_open_wstream()` - */ - int GIT_CALLBACK(finalize_write)(git_odb_stream *stream, const git_oid *oid); - - /** - * Free the stream's memory. - * - * This method might be called without a call to `finalize_write` if - * an error occurs or if the object is already present in the ODB. - */ - void GIT_CALLBACK(free)(git_odb_stream *stream); -}; - -/** A stream to write a pack file to the ODB */ -struct git_odb_writepack { - git_odb_backend *backend; - - int GIT_CALLBACK(append)(git_odb_writepack *writepack, const void *data, size_t size, git_indexer_progress *stats); - int GIT_CALLBACK(commit)(git_odb_writepack *writepack, git_indexer_progress *stats); - void GIT_CALLBACK(free)(git_odb_writepack *writepack); -}; - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/oid.h b/vendor/libgit2-sys/libgit2/include/git2/oid.h deleted file mode 100644 index 8539b4e..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/oid.h +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_oid_h__ -#define INCLUDE_git_oid_h__ - -#include "common.h" -#include "experimental.h" - -/** - * @file git2/oid.h - * @brief Object IDs - * @defgroup git_oid Git object id routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** The type of object id. */ -typedef enum { - -#ifdef GIT_EXPERIMENTAL_SHA256 - GIT_OID_SHA1 = 1, /**< SHA1 */ - GIT_OID_SHA256 = 2 /**< SHA256 */ -#else - GIT_OID_SHA1 = 1 /**< SHA1 */ -#endif - -} git_oid_t; - -/* - * SHA1 is currently the only supported object ID type. - */ - -/** SHA1 is currently libgit2's default oid type. */ -#define GIT_OID_DEFAULT GIT_OID_SHA1 - -/** Size (in bytes) of a raw/binary sha1 oid */ -#define GIT_OID_SHA1_SIZE 20 -/** Size (in bytes) of a hex formatted sha1 oid */ -#define GIT_OID_SHA1_HEXSIZE (GIT_OID_SHA1_SIZE * 2) - -/** - * The binary representation of the null sha1 object ID. - */ -#ifndef GIT_EXPERIMENTAL_SHA256 -# define GIT_OID_SHA1_ZERO { { 0 } } -#else -# define GIT_OID_SHA1_ZERO { GIT_OID_SHA1, { 0 } } -#endif - -/** - * The string representation of the null sha1 object ID. - */ -#define GIT_OID_SHA1_HEXZERO "0000000000000000000000000000000000000000" - -/* - * Experimental SHA256 support is a breaking change to the API. - * This exists for application compatibility testing. - */ - -#ifdef GIT_EXPERIMENTAL_SHA256 - -/** Size (in bytes) of a raw/binary sha256 oid */ -# define GIT_OID_SHA256_SIZE 32 -/** Size (in bytes) of a hex formatted sha256 oid */ -# define GIT_OID_SHA256_HEXSIZE (GIT_OID_SHA256_SIZE * 2) - -/** - * The binary representation of the null sha256 object ID. - */ -# define GIT_OID_SHA256_ZERO { GIT_OID_SHA256, { 0 } } - -/** - * The string representation of the null sha256 object ID. - */ -# define GIT_OID_SHA256_HEXZERO "0000000000000000000000000000000000000000000000000000000000000000" - -#endif - -/** Maximum possible object ID size in raw format */ -#ifdef GIT_EXPERIMENTAL_SHA256 -# define GIT_OID_MAX_SIZE GIT_OID_SHA256_SIZE -#else -# define GIT_OID_MAX_SIZE GIT_OID_SHA1_SIZE -#endif - -/** Maximum possible object ID size in hex format */ -#ifdef GIT_EXPERIMENTAL_SHA256 -# define GIT_OID_MAX_HEXSIZE GIT_OID_SHA256_HEXSIZE -#else -# define GIT_OID_MAX_HEXSIZE GIT_OID_SHA1_HEXSIZE -#endif - -/** Minimum length (in number of hex characters, - * i.e. packets of 4 bits) of an oid prefix */ -#define GIT_OID_MINPREFIXLEN 4 - -/** Unique identity of any object (commit, tree, blob, tag). */ -typedef struct git_oid { - -#ifdef GIT_EXPERIMENTAL_SHA256 - /** type of object id */ - unsigned char type; -#endif - - /** raw binary formatted id */ - unsigned char id[GIT_OID_MAX_SIZE]; -} git_oid; - -#ifdef GIT_EXPERIMENTAL_SHA256 - -GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str, git_oid_t type); -GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type); -GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length, git_oid_t type); -GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type); - -#else - -/** - * Parse a hex formatted object id into a git_oid. - * - * The appropriate number of bytes for the given object ID type will - * be read from the string - 40 bytes for SHA1, 64 bytes for SHA256. - * The given string need not be NUL terminated. - * - * @param out oid structure the result is written into. - * @param str input hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (40 bytes for sha1, - * 256 bytes for sha256). - * @return 0 or an error code - */ -GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str); - -/** - * Parse a hex formatted NUL-terminated string into a git_oid. - * - * @param out oid structure the result is written into. - * @param str input hex string; must be null-terminated. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str); - -/** - * Parse N characters of a hex formatted object id into a git_oid. - * - * If N is odd, the last byte's high nibble will be read in and the - * low nibble set to zero. - * - * @param out oid structure the result is written into. - * @param str input hex string of at least size `length` - * @param length length of the input string - * @return 0 or an error code - */ -GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length); - -/** - * Copy an already raw oid into a git_oid structure. - * - * @param out oid structure the result is written into. - * @param raw the raw input bytes to be copied. - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw); - -#endif - -/** - * Format a git_oid into a hex string. - * - * @param out output hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (40 bytes for SHA1, - * 64 bytes for SHA256). Only the oid digits are written; - * a '\\0' terminator must be added by the caller if it is - * required. - * @param id oid structure to format. - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_oid_fmt(char *out, const git_oid *id); - -/** - * Format a git_oid into a partial hex string. - * - * @param out output hex string; you say how many bytes to write. - * If the number of bytes is > GIT_OID_SHA1_HEXSIZE, extra bytes - * will be zeroed; if not, a '\0' terminator is NOT added. - * @param n number of characters to write into out string - * @param id oid structure to format. - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_oid_nfmt(char *out, size_t n, const git_oid *id); - -/** - * Format a git_oid into a loose-object path string. - * - * The resulting string is "aa/...", where "aa" is the first two - * hex digits of the oid and "..." is the remaining 38 digits. - * - * @param out output hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (41 bytes for SHA1, - * 65 bytes for SHA256). Only the oid digits are written; - * a '\\0' terminator must be added by the caller if it - * is required. - * @param id oid structure to format. - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_oid_pathfmt(char *out, const git_oid *id); - -/** - * Format a git_oid into a statically allocated c-string. - * - * The c-string is owned by the library and should not be freed - * by the user. If libgit2 is built with thread support, the string - * will be stored in TLS (i.e. one buffer per thread) to allow for - * concurrent calls of the function. - * - * @param oid The oid structure to format - * @return the c-string or NULL on failure - */ -GIT_EXTERN(char *) git_oid_tostr_s(const git_oid *oid); - -/** - * Format a git_oid into a buffer as a hex format c-string. - * - * If the buffer is smaller than the size of a hex-formatted oid string - * plus an additional byte (GIT_OID_SHA_HEXSIZE + 1 for SHA1 or - * GIT_OID_SHA256_HEXSIZE + 1 for SHA256), then the resulting - * oid c-string will be truncated to n-1 characters (but will still be - * NUL-byte terminated). - * - * If there are any input parameter errors (out == NULL, n == 0, oid == - * NULL), then a pointer to an empty string is returned, so that the - * return value can always be printed. - * - * @param out the buffer into which the oid string is output. - * @param n the size of the out buffer. - * @param id the oid structure to format. - * @return the out buffer pointer, assuming no input parameter - * errors, otherwise a pointer to an empty string. - */ -GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *id); - -/** - * Copy an oid from one structure to another. - * - * @param out oid structure the result is written into. - * @param src oid structure to copy from. - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_oid_cpy(git_oid *out, const git_oid *src); - -/** - * Compare two oid structures. - * - * @param a first oid structure. - * @param b second oid structure. - * @return <0, 0, >0 if a < b, a == b, a > b. - */ -GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b); - -/** - * Compare two oid structures for equality - * - * @param a first oid structure. - * @param b second oid structure. - * @return true if equal, false otherwise - */ -GIT_EXTERN(int) git_oid_equal(const git_oid *a, const git_oid *b); - -/** - * Compare the first 'len' hexadecimal characters (packets of 4 bits) - * of two oid structures. - * - * @param a first oid structure. - * @param b second oid structure. - * @param len the number of hex chars to compare - * @return 0 in case of a match - */ -GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, size_t len); - -/** - * Check if an oid equals an hex formatted object id. - * - * @param id oid structure. - * @param str input hex string of an object id. - * @return 0 in case of a match, -1 otherwise. - */ -GIT_EXTERN(int) git_oid_streq(const git_oid *id, const char *str); - -/** - * Compare an oid to an hex formatted object id. - * - * @param id oid structure. - * @param str input hex string of an object id. - * @return -1 if str is not valid, <0 if id sorts before str, - * 0 if id matches str, >0 if id sorts after str. - */ -GIT_EXTERN(int) git_oid_strcmp(const git_oid *id, const char *str); - -/** - * Check is an oid is all zeros. - * - * @param id the object ID to check - * @return 1 if all zeros, 0 otherwise. - */ -GIT_EXTERN(int) git_oid_is_zero(const git_oid *id); - -/** - * OID Shortener object - */ -typedef struct git_oid_shorten git_oid_shorten; - -/** - * Create a new OID shortener. - * - * The OID shortener is used to process a list of OIDs - * in text form and return the shortest length that would - * uniquely identify all of them. - * - * E.g. look at the result of `git log --abbrev`. - * - * @param min_length The minimal length for all identifiers, - * which will be used even if shorter OIDs would still - * be unique. - * @return a `git_oid_shorten` instance, NULL if OOM - */ -GIT_EXTERN(git_oid_shorten *) git_oid_shorten_new(size_t min_length); - -/** - * Add a new OID to set of shortened OIDs and calculate - * the minimal length to uniquely identify all the OIDs in - * the set. - * - * The OID is expected to be a 40-char hexadecimal string. - * The OID is owned by the user and will not be modified - * or freed. - * - * For performance reasons, there is a hard-limit of how many - * OIDs can be added to a single set (around ~32000, assuming - * a mostly randomized distribution), which should be enough - * for any kind of program, and keeps the algorithm fast and - * memory-efficient. - * - * Attempting to add more than those OIDs will result in a - * GIT_ERROR_INVALID error - * - * @param os a `git_oid_shorten` instance - * @param text_id an OID in text form - * @return the minimal length to uniquely identify all OIDs - * added so far to the set; or an error code (<0) if an - * error occurs. - */ -GIT_EXTERN(int) git_oid_shorten_add(git_oid_shorten *os, const char *text_id); - -/** - * Free an OID shortener instance - * - * @param os a `git_oid_shorten` instance - */ -GIT_EXTERN(void) git_oid_shorten_free(git_oid_shorten *os); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/oidarray.h b/vendor/libgit2-sys/libgit2/include/git2/oidarray.h deleted file mode 100644 index e79a559..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/oidarray.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_oidarray_h__ -#define INCLUDE_git_oidarray_h__ - -#include "common.h" -#include "oid.h" - -/** - * @file git2/oidarray.h - * @brief An array of object IDs - * @defgroup git_oidarray Arrays of object IDs - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Array of object ids */ -typedef struct git_oidarray { - git_oid *ids; - size_t count; -} git_oidarray; - -/** - * Free the object IDs contained in an oid_array. This method should - * be called on `git_oidarray` objects that were provided by the - * library. Not doing so will result in a memory leak. - * - * This does not free the `git_oidarray` itself, since the library will - * never allocate that object directly itself. - * - * @param array git_oidarray from which to free oid data - */ -GIT_EXTERN(void) git_oidarray_dispose(git_oidarray *array); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/pack.h b/vendor/libgit2-sys/libgit2/include/git2/pack.h deleted file mode 100644 index 3837e04..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/pack.h +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_pack_h__ -#define INCLUDE_git_pack_h__ - -#include "common.h" -#include "oid.h" -#include "indexer.h" - -/** - * @file git2/pack.h - * @brief Git pack management routines - * - * Packing objects - * --------------- - * - * Creation of packfiles requires two steps: - * - * - First, insert all the objects you want to put into the packfile - * using `git_packbuilder_insert` and `git_packbuilder_insert_tree`. - * It's important to add the objects in recency order ("in the order - * that they are 'reachable' from head"). - * - * "ANY order will give you a working pack, ... [but it is] the thing - * that gives packs good locality. It keeps the objects close to the - * head (whether they are old or new, but they are _reachable_ from the - * head) at the head of the pack. So packs actually have absolutely - * _wonderful_ IO patterns." - Linus Torvalds - * git.git/Documentation/technical/pack-heuristics.txt - * - * - Second, use `git_packbuilder_write` or `git_packbuilder_foreach` to - * write the resulting packfile. - * - * libgit2 will take care of the delta ordering and generation. - * `git_packbuilder_set_threads` can be used to adjust the number of - * threads used for the process. - * - * See tests/pack/packbuilder.c for an example. - * - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Stages that are reported by the packbuilder progress callback. - */ -typedef enum { - GIT_PACKBUILDER_ADDING_OBJECTS = 0, - GIT_PACKBUILDER_DELTAFICATION = 1 -} git_packbuilder_stage_t; - -/** - * Initialize a new packbuilder - * - * @param out The new packbuilder object - * @param repo The repository - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_new(git_packbuilder **out, git_repository *repo); - -/** - * Set number of threads to spawn - * - * By default, libgit2 won't spawn any threads at all; - * when set to 0, libgit2 will autodetect the number of - * CPUs. - * - * @param pb The packbuilder - * @param n Number of threads to spawn - * @return number of actual threads to be used - */ -GIT_EXTERN(unsigned int) git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n); - -/** - * Insert a single object - * - * For an optimal pack it's mandatory to insert objects in recency order, - * commits followed by trees and blobs. - * - * @param pb The packbuilder - * @param id The oid of the commit - * @param name The name; might be NULL - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_insert(git_packbuilder *pb, const git_oid *id, const char *name); - -/** - * Insert a root tree object - * - * This will add the tree as well as all referenced trees and blobs. - * - * @param pb The packbuilder - * @param id The oid of the root tree - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *id); - -/** - * Insert a commit object - * - * This will add a commit as well as the completed referenced tree. - * - * @param pb The packbuilder - * @param id The oid of the commit - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *id); - -/** - * Insert objects as given by the walk - * - * Those commits and all objects they reference will be inserted into - * the packbuilder. - * - * @param pb the packbuilder - * @param walk the revwalk to use to fill the packbuilder - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk); - -/** - * Recursively insert an object and its referenced objects - * - * Insert the object as well as any object it references. - * - * @param pb the packbuilder - * @param id the id of the root object to insert - * @param name optional name for the object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name); - -/** - * Write the contents of the packfile to an in-memory buffer - * - * The contents of the buffer will become a valid packfile, even though there - * will be no attached index - * - * @param buf Buffer where to write the packfile - * @param pb The packbuilder - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb); - -/** - * Write the new pack and corresponding index file to path. - * - * @param pb The packbuilder - * @param path Path to the directory where the packfile and index should be stored, or NULL for default location - * @param mode permissions to use creating a packfile or 0 for defaults - * @param progress_cb function to call with progress information from the indexer (optional) - * @param progress_cb_payload payload for the progress callback (optional) - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_write( - git_packbuilder *pb, - const char *path, - unsigned int mode, - git_indexer_progress_cb progress_cb, - void *progress_cb_payload); - -#ifndef GIT_DEPRECATE_HARD -/** - * Get the packfile's hash - * - * A packfile's name is derived from the sorted hashing of all object - * names. This is only correct after the packfile has been written. - * - * @deprecated use git_packbuilder_name - * @param pb The packbuilder object - * @return 0 or an error code - */ -GIT_EXTERN(const git_oid *) git_packbuilder_hash(git_packbuilder *pb); -#endif - -/** - * Get the unique name for the resulting packfile. - * - * The packfile's name is derived from the packfile's content. - * This is only correct after the packfile has been written. - * - * @param pb the packbuilder instance - * @return a NUL terminated string for the packfile name - */ -GIT_EXTERN(const char *) git_packbuilder_name(git_packbuilder *pb); - -/** - * Callback used to iterate over packed objects - * - * @see git_packbuilder_foreach - * - * @param buf A pointer to the object's data - * @param size The size of the underlying object - * @param payload Payload passed to git_packbuilder_foreach - * @return non-zero to terminate the iteration - */ -typedef int GIT_CALLBACK(git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload); - -/** - * Create the new pack and pass each object to the callback - * - * @param pb the packbuilder - * @param cb the callback to call with each packed object's buffer - * @param payload the callback's data - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_foreach(git_packbuilder *pb, git_packbuilder_foreach_cb cb, void *payload); - -/** - * Get the total number of objects the packbuilder will write out - * - * @param pb the packbuilder - * @return the number of objects in the packfile - */ -GIT_EXTERN(size_t) git_packbuilder_object_count(git_packbuilder *pb); - -/** - * Get the number of objects the packbuilder has already written out - * - * @param pb the packbuilder - * @return the number of objects which have already been written - */ -GIT_EXTERN(size_t) git_packbuilder_written(git_packbuilder *pb); - -/** - * Packbuilder progress notification function. - * - * @param stage the stage of the packbuilder - * @param current the current object - * @param total the total number of objects - * @param payload the callback payload - * @return 0 on success or an error code - */ -typedef int GIT_CALLBACK(git_packbuilder_progress)( - int stage, - uint32_t current, - uint32_t total, - void *payload); - -/** - * Set the callbacks for a packbuilder - * - * @param pb The packbuilder object - * @param progress_cb Function to call with progress information during - * pack building. Be aware that this is called inline with pack building - * operations, so performance may be affected. - * When progress_cb returns an error, the pack building process will be - * aborted and the error will be returned from the invoked function. - * `pb` must then be freed. - * @param progress_cb_payload Payload for progress callback. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_packbuilder_set_callbacks( - git_packbuilder *pb, - git_packbuilder_progress progress_cb, - void *progress_cb_payload); - -/** - * Free the packbuilder and all associated data - * - * @param pb The packbuilder - */ -GIT_EXTERN(void) git_packbuilder_free(git_packbuilder *pb); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/patch.h b/vendor/libgit2-sys/libgit2/include/git2/patch.h deleted file mode 100644 index 7824821..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/patch.h +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_patch_h__ -#define INCLUDE_git_patch_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "diff.h" - -/** - * @file git2/patch.h - * @brief Patches store the textual diffs in a delta - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * The diff patch is used to store all the text diffs for a delta. - * - * You can easily loop over the content of patches and get information about - * them. - */ -typedef struct git_patch git_patch; - -/** - * Get the repository associated with this patch. May be NULL. - * - * @param patch the patch - * @return a pointer to the repository - */ -GIT_EXTERN(git_repository *) git_patch_owner(const git_patch *patch); - -/** - * Return a patch for an entry in the diff list. - * - * The `git_patch` is a newly created object contains the text diffs - * for the delta. You have to call `git_patch_free()` when you are - * done with it. You can use the patch object to loop over all the hunks - * and lines in the diff of the one delta. - * - * For an unchanged file or a binary file, no `git_patch` will be - * created, the output will be set to NULL, and the `binary` flag will be - * set true in the `git_diff_delta` structure. - * - * It is okay to pass NULL for either of the output parameters; if you pass - * NULL for the `git_patch`, then the text diff will not be calculated. - * - * @param out Output parameter for the delta patch object - * @param diff Diff list object - * @param idx Index into diff list - * @return 0 on success, other value < 0 on error - */ -GIT_EXTERN(int) git_patch_from_diff( - git_patch **out, git_diff *diff, size_t idx); - -/** - * Directly generate a patch from the difference between two blobs. - * - * This is just like `git_diff_blobs()` except it generates a patch object - * for the difference instead of directly making callbacks. You can use the - * standard `git_patch` accessor functions to read the patch data, and - * you must call `git_patch_free()` on the patch when done. - * - * @param out The generated patch; NULL on error - * @param old_blob Blob for old side of diff, or NULL for empty blob - * @param old_as_path Treat old blob as if it had this filename; can be NULL - * @param new_blob Blob for new side of diff, or NULL for empty blob - * @param new_as_path Treat new blob as if it had this filename; can be NULL - * @param opts Options for diff, or NULL for default options - * @return 0 on success or error code < 0 - */ -GIT_EXTERN(int) git_patch_from_blobs( - git_patch **out, - const git_blob *old_blob, - const char *old_as_path, - const git_blob *new_blob, - const char *new_as_path, - const git_diff_options *opts); - -/** - * Directly generate a patch from the difference between a blob and a buffer. - * - * This is just like `git_diff_blob_to_buffer()` except it generates a patch - * object for the difference instead of directly making callbacks. You can - * use the standard `git_patch` accessor functions to read the patch - * data, and you must call `git_patch_free()` on the patch when done. - * - * @param out The generated patch; NULL on error - * @param old_blob Blob for old side of diff, or NULL for empty blob - * @param old_as_path Treat old blob as if it had this filename; can be NULL - * @param buffer Raw data for new side of diff, or NULL for empty - * @param buffer_len Length of raw data for new side of diff - * @param buffer_as_path Treat buffer as if it had this filename; can be NULL - * @param opts Options for diff, or NULL for default options - * @return 0 on success or error code < 0 - */ -GIT_EXTERN(int) git_patch_from_blob_and_buffer( - git_patch **out, - const git_blob *old_blob, - const char *old_as_path, - const void *buffer, - size_t buffer_len, - const char *buffer_as_path, - const git_diff_options *opts); - -/** - * Directly generate a patch from the difference between two buffers. - * - * This is just like `git_diff_buffers()` except it generates a patch - * object for the difference instead of directly making callbacks. You can - * use the standard `git_patch` accessor functions to read the patch - * data, and you must call `git_patch_free()` on the patch when done. - * - * @param out The generated patch; NULL on error - * @param old_buffer Raw data for old side of diff, or NULL for empty - * @param old_len Length of the raw data for old side of the diff - * @param old_as_path Treat old buffer as if it had this filename; can be NULL - * @param new_buffer Raw data for new side of diff, or NULL for empty - * @param new_len Length of raw data for new side of diff - * @param new_as_path Treat buffer as if it had this filename; can be NULL - * @param opts Options for diff, or NULL for default options - * @return 0 on success or error code < 0 - */ -GIT_EXTERN(int) git_patch_from_buffers( - git_patch **out, - const void *old_buffer, - size_t old_len, - const char *old_as_path, - const void *new_buffer, - size_t new_len, - const char *new_as_path, - const git_diff_options *opts); - -/** - * Free a git_patch object. - * - * @param patch The patch to free. - */ -GIT_EXTERN(void) git_patch_free(git_patch *patch); - -/** - * Get the delta associated with a patch. This delta points to internal - * data and you do not have to release it when you are done with it. - * - * @param patch The patch in which to get the delta. - * @return The delta associated with the patch. - */ -GIT_EXTERN(const git_diff_delta *) git_patch_get_delta(const git_patch *patch); - -/** - * Get the number of hunks in a patch - * - * @param patch The patch in which to get the number of hunks. - * @return The number of hunks of the patch. - */ -GIT_EXTERN(size_t) git_patch_num_hunks(const git_patch *patch); - -/** - * Get line counts of each type in a patch. - * - * This helps imitate a diff --numstat type of output. For that purpose, - * you only need the `total_additions` and `total_deletions` values, but we - * include the `total_context` line count in case you want the total number - * of lines of diff output that will be generated. - * - * All outputs are optional. Pass NULL if you don't need a particular count. - * - * @param total_context Count of context lines in output, can be NULL. - * @param total_additions Count of addition lines in output, can be NULL. - * @param total_deletions Count of deletion lines in output, can be NULL. - * @param patch The git_patch object - * @return 0 on success, <0 on error - */ -GIT_EXTERN(int) git_patch_line_stats( - size_t *total_context, - size_t *total_additions, - size_t *total_deletions, - const git_patch *patch); - -/** - * Get the information about a hunk in a patch - * - * Given a patch and a hunk index into the patch, this returns detailed - * information about that hunk. Any of the output pointers can be passed - * as NULL if you don't care about that particular piece of information. - * - * @param out Output pointer to git_diff_hunk of hunk - * @param lines_in_hunk Output count of total lines in this hunk - * @param patch Input pointer to patch object - * @param hunk_idx Input index of hunk to get information about - * @return 0 on success, GIT_ENOTFOUND if hunk_idx out of range, <0 on error - */ -GIT_EXTERN(int) git_patch_get_hunk( - const git_diff_hunk **out, - size_t *lines_in_hunk, - git_patch *patch, - size_t hunk_idx); - -/** - * Get the number of lines in a hunk. - * - * @param patch The git_patch object - * @param hunk_idx Index of the hunk - * @return Number of lines in hunk or GIT_ENOTFOUND if invalid hunk index - */ -GIT_EXTERN(int) git_patch_num_lines_in_hunk( - const git_patch *patch, - size_t hunk_idx); - -/** - * Get data about a line in a hunk of a patch. - * - * Given a patch, a hunk index, and a line index in the hunk, this - * will return a lot of details about that line. If you pass a hunk - * index larger than the number of hunks or a line index larger than - * the number of lines in the hunk, this will return -1. - * - * @param out The git_diff_line data for this line - * @param patch The patch to look in - * @param hunk_idx The index of the hunk - * @param line_of_hunk The index of the line in the hunk - * @return 0 on success, <0 on failure - */ -GIT_EXTERN(int) git_patch_get_line_in_hunk( - const git_diff_line **out, - git_patch *patch, - size_t hunk_idx, - size_t line_of_hunk); - -/** - * Look up size of patch diff data in bytes - * - * This returns the raw size of the patch data. This only includes the - * actual data from the lines of the diff, not the file or hunk headers. - * - * If you pass `include_context` as true (non-zero), this will be the size - * of all of the diff output; if you pass it as false (zero), this will - * only include the actual changed lines (as if `context_lines` was 0). - * - * @param patch A git_patch representing changes to one file - * @param include_context Include context lines in size if non-zero - * @param include_hunk_headers Include hunk header lines if non-zero - * @param include_file_headers Include file header lines if non-zero - * @return The number of bytes of data - */ -GIT_EXTERN(size_t) git_patch_size( - git_patch *patch, - int include_context, - int include_hunk_headers, - int include_file_headers); - -/** - * Serialize the patch to text via callback. - * - * Returning a non-zero value from the callback will terminate the iteration - * and return that value to the caller. - * - * @param patch A git_patch representing changes to one file - * @param print_cb Callback function to output lines of the patch. Will be - * called for file headers, hunk headers, and diff lines. - * @param payload Reference pointer that will be passed to your callbacks. - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_patch_print( - git_patch *patch, - git_diff_line_cb print_cb, - void *payload); - -/** - * Get the content of a patch as a single diff text. - * - * @param out The git_buf to be filled in - * @param patch A git_patch representing changes to one file - * @return 0 on success, <0 on failure. - */ -GIT_EXTERN(int) git_patch_to_buf( - git_buf *out, - git_patch *patch); - -/**@}*/ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/pathspec.h b/vendor/libgit2-sys/libgit2/include/git2/pathspec.h deleted file mode 100644 index 6f6918c..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/pathspec.h +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_pathspec_h__ -#define INCLUDE_git_pathspec_h__ - -#include "common.h" -#include "types.h" -#include "strarray.h" -#include "diff.h" - -/** - * @file git2/pathspec.h - * @brief Specifiers for path matching - * @defgroup git_pathspec Specifiers for path matching - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Compiled pathspec - */ -typedef struct git_pathspec git_pathspec; - -/** - * List of filenames matching a pathspec - */ -typedef struct git_pathspec_match_list git_pathspec_match_list; - -/** - * Options controlling how pathspec match should be executed - */ -typedef enum { - GIT_PATHSPEC_DEFAULT = 0, - - /** - * GIT_PATHSPEC_IGNORE_CASE forces match to ignore case; otherwise - * match will use native case sensitivity of platform filesystem - */ - GIT_PATHSPEC_IGNORE_CASE = (1u << 0), - - /** - * GIT_PATHSPEC_USE_CASE forces case sensitive match; otherwise - * match will use native case sensitivity of platform filesystem - */ - GIT_PATHSPEC_USE_CASE = (1u << 1), - - /** - * GIT_PATHSPEC_NO_GLOB disables glob patterns and just uses simple - * string comparison for matching - */ - GIT_PATHSPEC_NO_GLOB = (1u << 2), - - /** - * GIT_PATHSPEC_NO_MATCH_ERROR means the match functions return error - * code GIT_ENOTFOUND if no matches are found; otherwise no matches is - * still success (return 0) but `git_pathspec_match_list_entrycount` - * will indicate 0 matches. - */ - GIT_PATHSPEC_NO_MATCH_ERROR = (1u << 3), - - /** - * GIT_PATHSPEC_FIND_FAILURES means that the `git_pathspec_match_list` - * should track which patterns matched which files so that at the end of - * the match we can identify patterns that did not match any files. - */ - GIT_PATHSPEC_FIND_FAILURES = (1u << 4), - - /** - * GIT_PATHSPEC_FAILURES_ONLY means that the `git_pathspec_match_list` - * does not need to keep the actual matching filenames. Use this to - * just test if there were any matches at all or in combination with - * GIT_PATHSPEC_FIND_FAILURES to validate a pathspec. - */ - GIT_PATHSPEC_FAILURES_ONLY = (1u << 5) -} git_pathspec_flag_t; - -/** - * Compile a pathspec - * - * @param out Output of the compiled pathspec - * @param pathspec A git_strarray of the paths to match - * @return 0 on success, <0 on failure - */ -GIT_EXTERN(int) git_pathspec_new( - git_pathspec **out, const git_strarray *pathspec); - -/** - * Free a pathspec - * - * @param ps The compiled pathspec - */ -GIT_EXTERN(void) git_pathspec_free(git_pathspec *ps); - -/** - * Try to match a path against a pathspec - * - * Unlike most of the other pathspec matching functions, this will not - * fall back on the native case-sensitivity for your platform. You must - * explicitly pass flags to control case sensitivity or else this will - * fall back on being case sensitive. - * - * @param ps The compiled pathspec - * @param flags Combination of git_pathspec_flag_t options to control match - * @param path The pathname to attempt to match - * @return 1 is path matches spec, 0 if it does not - */ -GIT_EXTERN(int) git_pathspec_matches_path( - const git_pathspec *ps, uint32_t flags, const char *path); - -/** - * Match a pathspec against the working directory of a repository. - * - * This matches the pathspec against the current files in the working - * directory of the repository. It is an error to invoke this on a bare - * repo. This handles git ignores (i.e. ignored files will not be - * considered to match the `pathspec` unless the file is tracked in the - * index). - * - * If `out` is not NULL, this returns a `git_patchspec_match_list`. That - * contains the list of all matched filenames (unless you pass the - * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of - * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES` - * flag). You must call `git_pathspec_match_list_free()` on this object. - * - * @param out Output list of matches; pass NULL to just get return value - * @param repo The repository in which to match; bare repo is an error - * @param flags Combination of git_pathspec_flag_t options to control match - * @param ps Pathspec to be matched - * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and - * the GIT_PATHSPEC_NO_MATCH_ERROR flag was given - */ -GIT_EXTERN(int) git_pathspec_match_workdir( - git_pathspec_match_list **out, - git_repository *repo, - uint32_t flags, - git_pathspec *ps); - -/** - * Match a pathspec against entries in an index. - * - * This matches the pathspec against the files in the repository index. - * - * NOTE: At the moment, the case sensitivity of this match is controlled - * by the current case-sensitivity of the index object itself and the - * USE_CASE and IGNORE_CASE flags will have no effect. This behavior will - * be corrected in a future release. - * - * If `out` is not NULL, this returns a `git_patchspec_match_list`. That - * contains the list of all matched filenames (unless you pass the - * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of - * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES` - * flag). You must call `git_pathspec_match_list_free()` on this object. - * - * @param out Output list of matches; pass NULL to just get return value - * @param index The index to match against - * @param flags Combination of git_pathspec_flag_t options to control match - * @param ps Pathspec to be matched - * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and - * the GIT_PATHSPEC_NO_MATCH_ERROR flag is used - */ -GIT_EXTERN(int) git_pathspec_match_index( - git_pathspec_match_list **out, - git_index *index, - uint32_t flags, - git_pathspec *ps); - -/** - * Match a pathspec against files in a tree. - * - * This matches the pathspec against the files in the given tree. - * - * If `out` is not NULL, this returns a `git_patchspec_match_list`. That - * contains the list of all matched filenames (unless you pass the - * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of - * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES` - * flag). You must call `git_pathspec_match_list_free()` on this object. - * - * @param out Output list of matches; pass NULL to just get return value - * @param tree The root-level tree to match against - * @param flags Combination of git_pathspec_flag_t options to control match - * @param ps Pathspec to be matched - * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and - * the GIT_PATHSPEC_NO_MATCH_ERROR flag is used - */ -GIT_EXTERN(int) git_pathspec_match_tree( - git_pathspec_match_list **out, - git_tree *tree, - uint32_t flags, - git_pathspec *ps); - -/** - * Match a pathspec against files in a diff list. - * - * This matches the pathspec against the files in the given diff list. - * - * If `out` is not NULL, this returns a `git_patchspec_match_list`. That - * contains the list of all matched filenames (unless you pass the - * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of - * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES` - * flag). You must call `git_pathspec_match_list_free()` on this object. - * - * @param out Output list of matches; pass NULL to just get return value - * @param diff A generated diff list - * @param flags Combination of git_pathspec_flag_t options to control match - * @param ps Pathspec to be matched - * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and - * the GIT_PATHSPEC_NO_MATCH_ERROR flag is used - */ -GIT_EXTERN(int) git_pathspec_match_diff( - git_pathspec_match_list **out, - git_diff *diff, - uint32_t flags, - git_pathspec *ps); - -/** - * Free memory associates with a git_pathspec_match_list - * - * @param m The git_pathspec_match_list to be freed - */ -GIT_EXTERN(void) git_pathspec_match_list_free(git_pathspec_match_list *m); - -/** - * Get the number of items in a match list. - * - * @param m The git_pathspec_match_list object - * @return Number of items in match list - */ -GIT_EXTERN(size_t) git_pathspec_match_list_entrycount( - const git_pathspec_match_list *m); - -/** - * Get a matching filename by position. - * - * This routine cannot be used if the match list was generated by - * `git_pathspec_match_diff`. If so, it will always return NULL. - * - * @param m The git_pathspec_match_list object - * @param pos The index into the list - * @return The filename of the match - */ -GIT_EXTERN(const char *) git_pathspec_match_list_entry( - const git_pathspec_match_list *m, size_t pos); - -/** - * Get a matching diff delta by position. - * - * This routine can only be used if the match list was generated by - * `git_pathspec_match_diff`. Otherwise it will always return NULL. - * - * @param m The git_pathspec_match_list object - * @param pos The index into the list - * @return The filename of the match - */ -GIT_EXTERN(const git_diff_delta *) git_pathspec_match_list_diff_entry( - const git_pathspec_match_list *m, size_t pos); - -/** - * Get the number of pathspec items that did not match. - * - * This will be zero unless you passed GIT_PATHSPEC_FIND_FAILURES when - * generating the git_pathspec_match_list. - * - * @param m The git_pathspec_match_list object - * @return Number of items in original pathspec that had no matches - */ -GIT_EXTERN(size_t) git_pathspec_match_list_failed_entrycount( - const git_pathspec_match_list *m); - -/** - * Get an original pathspec string that had no matches. - * - * This will be return NULL for positions out of range. - * - * @param m The git_pathspec_match_list object - * @param pos The index into the failed items - * @return The pathspec pattern that didn't match anything - */ -GIT_EXTERN(const char *) git_pathspec_match_list_failed_entry( - const git_pathspec_match_list *m, size_t pos); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/proxy.h b/vendor/libgit2-sys/libgit2/include/git2/proxy.h deleted file mode 100644 index fc8ffaa..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/proxy.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_proxy_h__ -#define INCLUDE_git_proxy_h__ - -#include "common.h" - -#include "cert.h" -#include "credential.h" - -/** - * @file git2/proxy.h - * @brief TLS proxies - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * The type of proxy to use. - */ -typedef enum { - /** - * Do not attempt to connect through a proxy - * - * If built against libcurl, it itself may attempt to connect - * to a proxy if the environment variables specify it. - */ - GIT_PROXY_NONE, - /** - * Try to auto-detect the proxy from the git configuration. - */ - GIT_PROXY_AUTO, - /** - * Connect via the URL given in the options - */ - GIT_PROXY_SPECIFIED -} git_proxy_t; - -/** - * Options for connecting through a proxy - * - * Note that not all types may be supported, depending on the platform - * and compilation options. - */ -typedef struct { - unsigned int version; - - /** - * The type of proxy to use, by URL, auto-detect. - */ - git_proxy_t type; - - /** - * The URL of the proxy. - */ - const char *url; - - /** - * This will be called if the remote host requires - * authentication in order to connect to it. - * - * Returning GIT_PASSTHROUGH will make libgit2 behave as - * though this field isn't set. - */ - git_credential_acquire_cb credentials; - - /** - * This will be called to let the user make the final decision of whether - * to allow the connection to proceed. Returns 0 to allow the connection - * or a negative value to indicate an error. - */ - git_transport_certificate_check_cb certificate_check; - - /** - * Payload to be provided to the credentials and certificate - * check callbacks. - */ - void *payload; -} git_proxy_options; - -/** Current version for the `git_proxy_options` structure */ -#define GIT_PROXY_OPTIONS_VERSION 1 - -/** Static constructor for `git_proxy_options` */ -#define GIT_PROXY_OPTIONS_INIT {GIT_PROXY_OPTIONS_VERSION} - -/** - * Initialize git_proxy_options structure - * - * Initializes a `git_proxy_options` with default values. Equivalent to - * creating an instance with `GIT_PROXY_OPTIONS_INIT`. - * - * @param opts The `git_proxy_options` struct to initialize. - * @param version The struct version; pass `GIT_PROXY_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_proxy_options_init(git_proxy_options *opts, unsigned int version); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/rebase.h b/vendor/libgit2-sys/libgit2/include/git2/rebase.h deleted file mode 100644 index 3fb3e57..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/rebase.h +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_rebase_h__ -#define INCLUDE_git_rebase_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "annotated_commit.h" -#include "merge.h" -#include "checkout.h" -#include "commit.h" - -/** - * @file git2/rebase.h - * @brief Rebase manipulates commits, placing them on a new parent - * @defgroup git_rebase Rebase manipulates commits, placing them on a new parent - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Rebase options - * - * Use to tell the rebase machinery how to operate. - */ -typedef struct { - unsigned int version; - - /** - * Used by `git_rebase_init`, this will instruct other clients working - * on this rebase that you want a quiet rebase experience, which they - * may choose to provide in an application-specific manner. This has no - * effect upon libgit2 directly, but is provided for interoperability - * between Git tools. - */ - int quiet; - - /** - * Used by `git_rebase_init`, this will begin an in-memory rebase, - * which will allow callers to step through the rebase operations and - * commit the rebased changes, but will not rewind HEAD or update the - * repository to be in a rebasing state. This will not interfere with - * the working directory (if there is one). - */ - int inmemory; - - /** - * Used by `git_rebase_finish`, this is the name of the notes reference - * used to rewrite notes for rebased commits when finishing the rebase; - * if NULL, the contents of the configuration option `notes.rewriteRef` - * is examined, unless the configuration option `notes.rewrite.rebase` - * is set to false. If `notes.rewriteRef` is also NULL, notes will - * not be rewritten. - */ - const char *rewrite_notes_ref; - - /** - * Options to control how trees are merged during `git_rebase_next`. - */ - git_merge_options merge_options; - - /** - * Options to control how files are written during `git_rebase_init`, - * `git_rebase_next` and `git_rebase_abort`. Note that during - * `abort`, these options will add an implied `GIT_CHECKOUT_FORCE` - * to match git semantics. - */ - git_checkout_options checkout_options; - - /** - * Optional callback that allows users to override commit - * creation in `git_rebase_commit`. If specified, users can - * create their own commit and provide the commit ID, which - * may be useful for signing commits or otherwise customizing - * the commit creation. - * - * If this callback returns `GIT_PASSTHROUGH`, then - * `git_rebase_commit` will continue to create the commit. - */ - git_commit_create_cb commit_create_cb; - -#ifdef GIT_DEPRECATE_HARD - void *reserved; -#else - /** - * If provided, this will be called with the commit content, allowing - * a signature to be added to the rebase commit. Can be skipped with - * GIT_PASSTHROUGH. If GIT_PASSTHROUGH is returned, a commit will be made - * without a signature. - * - * This field is only used when performing git_rebase_commit. - * - * This callback is not invoked if a `git_commit_create_cb` is - * specified. - * - * This callback is deprecated; users should provide a - * creation callback as `commit_create_cb` that produces a - * commit buffer, signs it, and commits it. - */ - int (*signing_cb)(git_buf *, git_buf *, const char *, void *); -#endif - - /** - * This will be passed to each of the callbacks in this struct - * as the last parameter. - */ - void *payload; -} git_rebase_options; - -/** - * Type of rebase operation in-progress after calling `git_rebase_next`. - */ -typedef enum { - /** - * The given commit is to be cherry-picked. The client should commit - * the changes and continue if there are no conflicts. - */ - GIT_REBASE_OPERATION_PICK = 0, - - /** - * The given commit is to be cherry-picked, but the client should prompt - * the user to provide an updated commit message. - */ - GIT_REBASE_OPERATION_REWORD, - - /** - * The given commit is to be cherry-picked, but the client should stop - * to allow the user to edit the changes before committing them. - */ - GIT_REBASE_OPERATION_EDIT, - - /** - * The given commit is to be squashed into the previous commit. The - * commit message will be merged with the previous message. - */ - GIT_REBASE_OPERATION_SQUASH, - - /** - * The given commit is to be squashed into the previous commit. The - * commit message from this commit will be discarded. - */ - GIT_REBASE_OPERATION_FIXUP, - - /** - * No commit will be cherry-picked. The client should run the given - * command and (if successful) continue. - */ - GIT_REBASE_OPERATION_EXEC -} git_rebase_operation_t; - -/** Current version for the `git_rebase_options` structure */ -#define GIT_REBASE_OPTIONS_VERSION 1 - -/** Static constructor for `git_rebase_options` */ -#define GIT_REBASE_OPTIONS_INIT \ - { GIT_REBASE_OPTIONS_VERSION, 0, 0, NULL, GIT_MERGE_OPTIONS_INIT, \ - GIT_CHECKOUT_OPTIONS_INIT, NULL, NULL } - -/** Indicates that a rebase operation is not (yet) in progress. */ -#define GIT_REBASE_NO_OPERATION SIZE_MAX - -/** - * A rebase operation - * - * Describes a single instruction/operation to be performed during the - * rebase. - */ -typedef struct { - /** The type of rebase operation. */ - git_rebase_operation_t type; - - /** - * The commit ID being cherry-picked. This will be populated for - * all operations except those of type `GIT_REBASE_OPERATION_EXEC`. - */ - const git_oid id; - - /** - * The executable the user has requested be run. This will only - * be populated for operations of type `GIT_REBASE_OPERATION_EXEC`. - */ - const char *exec; -} git_rebase_operation; - -/** - * Initialize git_rebase_options structure - * - * Initializes a `git_rebase_options` with default values. Equivalent to - * creating an instance with `GIT_REBASE_OPTIONS_INIT`. - * - * @param opts The `git_rebase_options` struct to initialize. - * @param version The struct version; pass `GIT_REBASE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_rebase_options_init( - git_rebase_options *opts, - unsigned int version); - -/** - * Initializes a rebase operation to rebase the changes in `branch` - * relative to `upstream` onto another branch. To begin the rebase - * process, call `git_rebase_next`. When you have finished with this - * object, call `git_rebase_free`. - * - * @param out Pointer to store the rebase object - * @param repo The repository to perform the rebase - * @param branch The terminal commit to rebase, or NULL to rebase the - * current branch - * @param upstream The commit to begin rebasing from, or NULL to rebase all - * reachable commits - * @param onto The branch to rebase onto, or NULL to rebase onto the given - * upstream - * @param opts Options to specify how rebase is performed, or NULL - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_rebase_init( - git_rebase **out, - git_repository *repo, - const git_annotated_commit *branch, - const git_annotated_commit *upstream, - const git_annotated_commit *onto, - const git_rebase_options *opts); - -/** - * Opens an existing rebase that was previously started by either an - * invocation of `git_rebase_init` or by another client. - * - * @param out Pointer to store the rebase object - * @param repo The repository that has a rebase in-progress - * @param opts Options to specify how rebase is performed - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_rebase_open( - git_rebase **out, - git_repository *repo, - const git_rebase_options *opts); - -/** - * Gets the original `HEAD` ref name for merge rebases. - * - * @param rebase The in-progress rebase. - * @return The original `HEAD` ref name - */ -GIT_EXTERN(const char *) git_rebase_orig_head_name(git_rebase *rebase); - -/** - * Gets the original `HEAD` id for merge rebases. - * - * @param rebase The in-progress rebase. - * @return The original `HEAD` id - */ -GIT_EXTERN(const git_oid *) git_rebase_orig_head_id(git_rebase *rebase); - -/** - * Gets the `onto` ref name for merge rebases. - * - * @param rebase The in-progress rebase. - * @return The `onto` ref name - */ -GIT_EXTERN(const char *) git_rebase_onto_name(git_rebase *rebase); - -/** - * Gets the `onto` id for merge rebases. - * - * @param rebase The in-progress rebase. - * @return The `onto` id - */ -GIT_EXTERN(const git_oid *) git_rebase_onto_id(git_rebase *rebase); - -/** - * Gets the count of rebase operations that are to be applied. - * - * @param rebase The in-progress rebase - * @return The number of rebase operations in total - */ -GIT_EXTERN(size_t) git_rebase_operation_entrycount(git_rebase *rebase); - -/** - * Gets the index of the rebase operation that is currently being applied. - * If the first operation has not yet been applied (because you have - * called `init` but not yet `next`) then this returns - * `GIT_REBASE_NO_OPERATION`. - * - * @param rebase The in-progress rebase - * @return The index of the rebase operation currently being applied. - */ -GIT_EXTERN(size_t) git_rebase_operation_current(git_rebase *rebase); - -/** - * Gets the rebase operation specified by the given index. - * - * @param rebase The in-progress rebase - * @param idx The index of the rebase operation to retrieve - * @return The rebase operation or NULL if `idx` was out of bounds - */ -GIT_EXTERN(git_rebase_operation *) git_rebase_operation_byindex( - git_rebase *rebase, - size_t idx); - -/** - * Performs the next rebase operation and returns the information about it. - * If the operation is one that applies a patch (which is any operation except - * GIT_REBASE_OPERATION_EXEC) then the patch will be applied and the index and - * working directory will be updated with the changes. If there are conflicts, - * you will need to address those before committing the changes. - * - * @param operation Pointer to store the rebase operation that is to be performed next - * @param rebase The rebase in progress - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_rebase_next( - git_rebase_operation **operation, - git_rebase *rebase); - -/** - * Gets the index produced by the last operation, which is the result - * of `git_rebase_next` and which will be committed by the next - * invocation of `git_rebase_commit`. This is useful for resolving - * conflicts in an in-memory rebase before committing them. You must - * call `git_index_free` when you are finished with this. - * - * This is only applicable for in-memory rebases; for rebases within - * a working directory, the changes were applied to the repository's - * index. - * - * @param index The result index of the last operation. - * @param rebase The in-progress rebase. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_rebase_inmemory_index( - git_index **index, - git_rebase *rebase); - -/** - * Commits the current patch. You must have resolved any conflicts that - * were introduced during the patch application from the `git_rebase_next` - * invocation. - * - * @param id Pointer in which to store the OID of the newly created commit - * @param rebase The rebase that is in-progress - * @param author The author of the updated commit, or NULL to keep the - * author from the original commit - * @param committer The committer of the rebase - * @param message_encoding The encoding for the message in the commit, - * represented with a standard encoding name. If message is NULL, - * this should also be NULL, and the encoding from the original - * commit will be maintained. If message is specified, this may be - * NULL to indicate that "UTF-8" is to be used. - * @param message The message for this commit, or NULL to use the message - * from the original commit. - * @return Zero on success, GIT_EUNMERGED if there are unmerged changes in - * the index, GIT_EAPPLIED if the current commit has already - * been applied to the upstream and there is nothing to commit, - * -1 on failure. - */ -GIT_EXTERN(int) git_rebase_commit( - git_oid *id, - git_rebase *rebase, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message); - -/** - * Aborts a rebase that is currently in progress, resetting the repository - * and working directory to their state before rebase began. - * - * @param rebase The rebase that is in-progress - * @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress, - * -1 on other errors. - */ -GIT_EXTERN(int) git_rebase_abort(git_rebase *rebase); - -/** - * Finishes a rebase that is currently in progress once all patches have - * been applied. - * - * @param rebase The rebase that is in-progress - * @param signature The identity that is finishing the rebase (optional) - * @return Zero on success; -1 on error - */ -GIT_EXTERN(int) git_rebase_finish( - git_rebase *rebase, - const git_signature *signature); - -/** - * Frees the `git_rebase` object. - * - * @param rebase The rebase object - */ -GIT_EXTERN(void) git_rebase_free(git_rebase *rebase); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/refdb.h b/vendor/libgit2-sys/libgit2/include/git2/refdb.h deleted file mode 100644 index 536ef10..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/refdb.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_refdb_h__ -#define INCLUDE_git_refdb_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "refs.h" - -/** - * @file git2/refdb.h - * @brief A database for references (branches and tags) - * @defgroup git_refdb A database for references (branches and tags) - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create a new reference database with no backends. - * - * Before the Ref DB can be used for read/writing, a custom database - * backend must be manually set using `git_refdb_set_backend()` - * - * @param out location to store the database pointer, if opened. - * Set to NULL if the open failed. - * @param repo the repository - * @return 0 or an error code - */ -GIT_EXTERN(int) git_refdb_new(git_refdb **out, git_repository *repo); - -/** - * Create a new reference database and automatically add - * the default backends: - * - * - git_refdb_dir: read and write loose and packed refs - * from disk, assuming the repository dir as the folder - * - * @param out location to store the database pointer, if opened. - * Set to NULL if the open failed. - * @param repo the repository - * @return 0 or an error code - */ -GIT_EXTERN(int) git_refdb_open(git_refdb **out, git_repository *repo); - -/** - * Suggests that the given refdb compress or optimize its references. - * This mechanism is implementation specific. For on-disk reference - * databases, for example, this may pack all loose references. - * - * @param refdb The reference database to optimize. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_refdb_compress(git_refdb *refdb); - -/** - * Close an open reference database. - * - * @param refdb reference database pointer or NULL - */ -GIT_EXTERN(void) git_refdb_free(git_refdb *refdb); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/reflog.h b/vendor/libgit2-sys/libgit2/include/git2/reflog.h deleted file mode 100644 index a0956c6..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/reflog.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_reflog_h__ -#define INCLUDE_git_reflog_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/reflog.h - * @brief Reference logs store how references change - * @defgroup git_reflog Reference logs store how references change - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Read the reflog for the given reference - * - * If there is no reflog file for the given - * reference yet, an empty reflog object will - * be returned. - * - * The reflog must be freed manually by using - * git_reflog_free(). - * - * @param out pointer to reflog - * @param repo the repository - * @param name reference to look up - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reflog_read(git_reflog **out, git_repository *repo, const char *name); - -/** - * Write an existing in-memory reflog object back to disk - * using an atomic file lock. - * - * @param reflog an existing reflog object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reflog_write(git_reflog *reflog); - -/** - * Add a new entry to the in-memory reflog. - * - * `msg` is optional and can be NULL. - * - * @param reflog an existing reflog object - * @param id the OID the reference is now pointing to - * @param committer the signature of the committer - * @param msg the reflog message - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *id, const git_signature *committer, const char *msg); - -/** - * Rename a reflog - * - * The reflog to be renamed is expected to already exist - * - * The new name will be checked for validity. - * See `git_reference_create_symbolic()` for rules about valid names. - * - * @param repo the repository - * @param old_name the old name of the reference - * @param name the new name of the reference - * @return 0 on success, GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_reflog_rename(git_repository *repo, const char *old_name, const char *name); - -/** - * Delete the reflog for the given reference - * - * @param repo the repository - * @param name the reflog to delete - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reflog_delete(git_repository *repo, const char *name); - -/** - * Get the number of log entries in a reflog - * - * @param reflog the previously loaded reflog - * @return the number of log entries - */ -GIT_EXTERN(size_t) git_reflog_entrycount(git_reflog *reflog); - -/** - * Lookup an entry by its index - * - * Requesting the reflog entry with an index of 0 (zero) will - * return the most recently created entry. - * - * @param reflog a previously loaded reflog - * @param idx the position of the entry to lookup. Should be greater than or - * equal to 0 (zero) and less than `git_reflog_entrycount()`. - * @return the entry; NULL if not found - */ -GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(const git_reflog *reflog, size_t idx); - -/** - * Remove an entry from the reflog by its index - * - * To ensure there's no gap in the log history, set `rewrite_previous_entry` - * param value to 1. When deleting entry `n`, member old_oid of entry `n-1` - * (if any) will be updated with the value of member new_oid of entry `n+1`. - * - * @param reflog a previously loaded reflog. - * - * @param idx the position of the entry to remove. Should be greater than or - * equal to 0 (zero) and less than `git_reflog_entrycount()`. - * - * @param rewrite_previous_entry 1 to rewrite the history; 0 otherwise. - * - * @return 0 on success, GIT_ENOTFOUND if the entry doesn't exist - * or an error code. - */ -GIT_EXTERN(int) git_reflog_drop( - git_reflog *reflog, - size_t idx, - int rewrite_previous_entry); - -/** - * Get the old oid - * - * @param entry a reflog entry - * @return the old oid - */ -GIT_EXTERN(const git_oid *) git_reflog_entry_id_old(const git_reflog_entry *entry); - -/** - * Get the new oid - * - * @param entry a reflog entry - * @return the new oid at this time - */ -GIT_EXTERN(const git_oid *) git_reflog_entry_id_new(const git_reflog_entry *entry); - -/** - * Get the committer of this entry - * - * @param entry a reflog entry - * @return the committer - */ -GIT_EXTERN(const git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry); - -/** - * Get the log message - * - * @param entry a reflog entry - * @return the log msg - */ -GIT_EXTERN(const char *) git_reflog_entry_message(const git_reflog_entry *entry); - -/** - * Free the reflog - * - * @param reflog reflog to free - */ -GIT_EXTERN(void) git_reflog_free(git_reflog *reflog); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/refs.h b/vendor/libgit2-sys/libgit2/include/git2/refs.h deleted file mode 100644 index d820f2a..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/refs.h +++ /dev/null @@ -1,774 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_refs_h__ -#define INCLUDE_git_refs_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "strarray.h" - -/** - * @file git2/refs.h - * @brief References point to a commit; generally these are branches and tags - * @defgroup git_reference References point to a commit; generally these are branches and tags - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a reference by name in a repository. - * - * The returned reference must be freed by the user. - * - * The name will be checked for validity. - * See `git_reference_symbolic_create()` for rules about valid names. - * - * @param[out] out pointer to the looked-up reference - * @param repo the repository to look up the reference - * @param name the long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...) - * @return 0 on success, GIT_ENOTFOUND, GIT_EINVALIDSPEC or an error code. - */ -GIT_EXTERN(int) git_reference_lookup(git_reference **out, git_repository *repo, const char *name); - -/** - * Lookup a reference by name and resolve immediately to OID. - * - * This function provides a quick way to resolve a reference name straight - * through to the object id that it refers to. This avoids having to - * allocate or free any `git_reference` objects for simple situations. - * - * The name will be checked for validity. - * See `git_reference_symbolic_create()` for rules about valid names. - * - * @param out Pointer to oid to be filled in - * @param repo The repository in which to look up the reference - * @param name The long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...) - * @return 0 on success, GIT_ENOTFOUND, GIT_EINVALIDSPEC or an error code. - */ -GIT_EXTERN(int) git_reference_name_to_id( - git_oid *out, git_repository *repo, const char *name); - -/** - * Lookup a reference by DWIMing its short name - * - * Apply the git precedence rules to the given shorthand to determine - * which reference the user is referring to. - * - * @param out pointer in which to store the reference - * @param repo the repository in which to look - * @param shorthand the short name for the reference - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, const char *shorthand); - -/** - * Conditionally create a new symbolic reference. - * - * A symbolic reference is a reference name that refers to another - * reference name. If the other name moves, the symbolic name will move, - * too. As a simple example, the "HEAD" reference might refer to - * "refs/heads/master" while on the "master" branch of a repository. - * - * The symbolic reference will be created in the repository and written to - * the disk. The generated reference object must be freed by the user. - * - * Valid reference names must follow one of two patterns: - * - * 1. Top-level names must contain only capital letters and underscores, - * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). - * 2. Names prefixed with "refs/" can be almost anything. You must avoid - * the characters '~', '^', ':', '\\', '?', '[', and '*', and the - * sequences ".." and "@{" which have special meaning to revparse. - * - * This function will return an error if a reference already exists with the - * given name unless `force` is true, in which case it will be overwritten. - * - * The message for the reflog will be ignored if the reference does - * not belong in the standard set (HEAD, branches and remote-tracking - * branches) and it does not have a reflog. - * - * It will return GIT_EMODIFIED if the reference's value at the time - * of updating does not match the one passed through `current_value` - * (i.e. if the ref has changed since the user read it). - * - * If `current_value` is all zeros, this function will return GIT_EMODIFIED - * if the ref already exists. - * - * @param out Pointer to the newly created reference - * @param repo Repository where that reference will live - * @param name The name of the reference - * @param target The target of the reference - * @param force Overwrite existing references - * @param current_value The expected value of the reference when updating - * @param log_message The one line long message to be appended to the reflog - * @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC, GIT_EMODIFIED or an error code - */ -GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *current_value, const char *log_message); - -/** - * Create a new symbolic reference. - * - * A symbolic reference is a reference name that refers to another - * reference name. If the other name moves, the symbolic name will move, - * too. As a simple example, the "HEAD" reference might refer to - * "refs/heads/master" while on the "master" branch of a repository. - * - * The symbolic reference will be created in the repository and written to - * the disk. The generated reference object must be freed by the user. - * - * Valid reference names must follow one of two patterns: - * - * 1. Top-level names must contain only capital letters and underscores, - * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). - * 2. Names prefixed with "refs/" can be almost anything. You must avoid - * the characters '~', '^', ':', '\\', '?', '[', and '*', and the - * sequences ".." and "@{" which have special meaning to revparse. - * - * This function will return an error if a reference already exists with the - * given name unless `force` is true, in which case it will be overwritten. - * - * The message for the reflog will be ignored if the reference does - * not belong in the standard set (HEAD, branches and remote-tracking - * branches) and it does not have a reflog. - * - * @param out Pointer to the newly created reference - * @param repo Repository where that reference will live - * @param name The name of the reference - * @param target The target of the reference - * @param force Overwrite existing references - * @param log_message The one line long message to be appended to the reflog - * @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *log_message); - -/** - * Create a new direct reference. - * - * A direct reference (also called an object id reference) refers directly - * to a specific object id (a.k.a. OID or SHA) in the repository. The id - * permanently refers to the object (although the reference itself can be - * moved). For example, in libgit2 the direct ref "refs/tags/v0.17.0" - * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977. - * - * The direct reference will be created in the repository and written to - * the disk. The generated reference object must be freed by the user. - * - * Valid reference names must follow one of two patterns: - * - * 1. Top-level names must contain only capital letters and underscores, - * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). - * 2. Names prefixed with "refs/" can be almost anything. You must avoid - * the characters '~', '^', ':', '\\', '?', '[', and '*', and the - * sequences ".." and "@{" which have special meaning to revparse. - * - * This function will return an error if a reference already exists with the - * given name unless `force` is true, in which case it will be overwritten. - * - * The message for the reflog will be ignored if the reference does - * not belong in the standard set (HEAD, branches and remote-tracking - * branches) and it does not have a reflog. - * - * @param out Pointer to the newly created reference - * @param repo Repository where that reference will live - * @param name The name of the reference - * @param id The object id pointed to by the reference. - * @param force Overwrite existing references - * @param log_message The one line long message to be appended to the reflog - * @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const char *log_message); - -/** - * Conditionally create new direct reference - * - * A direct reference (also called an object id reference) refers directly - * to a specific object id (a.k.a. OID or SHA) in the repository. The id - * permanently refers to the object (although the reference itself can be - * moved). For example, in libgit2 the direct ref "refs/tags/v0.17.0" - * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977. - * - * The direct reference will be created in the repository and written to - * the disk. The generated reference object must be freed by the user. - * - * Valid reference names must follow one of two patterns: - * - * 1. Top-level names must contain only capital letters and underscores, - * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). - * 2. Names prefixed with "refs/" can be almost anything. You must avoid - * the characters '~', '^', ':', '\\', '?', '[', and '*', and the - * sequences ".." and "@{" which have special meaning to revparse. - * - * This function will return an error if a reference already exists with the - * given name unless `force` is true, in which case it will be overwritten. - * - * The message for the reflog will be ignored if the reference does - * not belong in the standard set (HEAD, branches and remote-tracking - * branches) and it does not have a reflog. - * - * It will return GIT_EMODIFIED if the reference's value at the time - * of updating does not match the one passed through `current_id` - * (i.e. if the ref has changed since the user read it). - * - * @param out Pointer to the newly created reference - * @param repo Repository where that reference will live - * @param name The name of the reference - * @param id The object id pointed to by the reference. - * @param force Overwrite existing references - * @param current_id The expected value of the reference at the time of update - * @param log_message The one line long message to be appended to the reflog - * @return 0 on success, GIT_EMODIFIED if the value of the reference - * has changed, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *current_id, const char *log_message); - -/** - * Get the OID pointed to by a direct reference. - * - * Only available if the reference is direct (i.e. an object id reference, - * not a symbolic one). - * - * To find the OID of a symbolic ref, call `git_reference_resolve()` and - * then this function (or maybe use `git_reference_name_to_id()` to - * directly resolve a reference name all the way through to an OID). - * - * @param ref The reference - * @return a pointer to the oid if available, NULL otherwise - */ -GIT_EXTERN(const git_oid *) git_reference_target(const git_reference *ref); - -/** - * Return the peeled OID target of this reference. - * - * This peeled OID only applies to direct references that point to - * a hard Tag object: it is the result of peeling such Tag. - * - * @param ref The reference - * @return a pointer to the oid if available, NULL otherwise - */ -GIT_EXTERN(const git_oid *) git_reference_target_peel(const git_reference *ref); - -/** - * Get full name to the reference pointed to by a symbolic reference. - * - * Only available if the reference is symbolic. - * - * @param ref The reference - * @return a pointer to the name if available, NULL otherwise - */ -GIT_EXTERN(const char *) git_reference_symbolic_target(const git_reference *ref); - -/** - * Get the type of a reference. - * - * Either direct (GIT_REFERENCE_DIRECT) or symbolic (GIT_REFERENCE_SYMBOLIC) - * - * @param ref The reference - * @return the type - */ -GIT_EXTERN(git_reference_t) git_reference_type(const git_reference *ref); - -/** - * Get the full name of a reference. - * - * See `git_reference_symbolic_create()` for rules about valid names. - * - * @param ref The reference - * @return the full name for the ref - */ -GIT_EXTERN(const char *) git_reference_name(const git_reference *ref); - -/** - * Resolve a symbolic reference to a direct reference. - * - * This method iteratively peels a symbolic reference until it resolves to - * a direct reference to an OID. - * - * The peeled reference is returned in the `resolved_ref` argument, and - * must be freed manually once it's no longer needed. - * - * If a direct reference is passed as an argument, a copy of that - * reference is returned. This copy must be manually freed too. - * - * @param out Pointer to the peeled reference - * @param ref The reference - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reference_resolve(git_reference **out, const git_reference *ref); - -/** - * Get the repository where a reference resides. - * - * @param ref The reference - * @return a pointer to the repo - */ -GIT_EXTERN(git_repository *) git_reference_owner(const git_reference *ref); - -/** - * Create a new reference with the same name as the given reference but a - * different symbolic target. The reference must be a symbolic reference, - * otherwise this will fail. - * - * The new reference will be written to disk, overwriting the given reference. - * - * The target name will be checked for validity. - * See `git_reference_symbolic_create()` for rules about valid names. - * - * The message for the reflog will be ignored if the reference does - * not belong in the standard set (HEAD, branches and remote-tracking - * branches) and it does not have a reflog. - * - * @param out Pointer to the newly created reference - * @param ref The reference - * @param target The new target for the reference - * @param log_message The one line long message to be appended to the reflog - * @return 0 on success, GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_reference_symbolic_set_target( - git_reference **out, - git_reference *ref, - const char *target, - const char *log_message); - -/** - * Conditionally create a new reference with the same name as the given reference but a - * different OID target. The reference must be a direct reference, otherwise - * this will fail. - * - * The new reference will be written to disk, overwriting the given reference. - * - * @param out Pointer to the newly created reference - * @param ref The reference - * @param id The new target OID for the reference - * @param log_message The one line long message to be appended to the reflog - * @return 0 on success, GIT_EMODIFIED if the value of the reference - * has changed since it was read, or an error code - */ -GIT_EXTERN(int) git_reference_set_target( - git_reference **out, - git_reference *ref, - const git_oid *id, - const char *log_message); - -/** - * Rename an existing reference. - * - * This method works for both direct and symbolic references. - * - * The new name will be checked for validity. - * See `git_reference_symbolic_create()` for rules about valid names. - * - * If the `force` flag is not enabled, and there's already - * a reference with the given name, the renaming will fail. - * - * IMPORTANT: - * The user needs to write a proper reflog entry if the - * reflog is enabled for the repository. We only rename - * the reflog if it exists. - * - * @param[out] new_ref The new reference - * @param ref The reference to rename - * @param new_name The new name for the reference - * @param force Overwrite an existing reference - * @param log_message The one line long message to be appended to the reflog - * @return 0 on success, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code - * - */ -GIT_EXTERN(int) git_reference_rename( - git_reference **new_ref, - git_reference *ref, - const char *new_name, - int force, - const char *log_message); - -/** - * Delete an existing reference. - * - * This method works for both direct and symbolic references. The reference - * will be immediately removed on disk but the memory will not be freed. - * Callers must call `git_reference_free`. - * - * This function will return an error if the reference has changed - * from the time it was looked up. - * - * @param ref The reference to remove - * @return 0, GIT_EMODIFIED or an error code - */ -GIT_EXTERN(int) git_reference_delete(git_reference *ref); - -/** - * Delete an existing reference by name - * - * This method removes the named reference from the repository without - * looking at its old value. - * - * @param repo The repository to remove the reference from - * @param name The reference to remove - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reference_remove(git_repository *repo, const char *name); - -/** - * Fill a list with all the references that can be found in a repository. - * - * The string array will be filled with the names of all references; these - * values are owned by the user and should be free'd manually when no - * longer needed, using `git_strarray_free()`. - * - * @param array Pointer to a git_strarray structure where - * the reference names will be stored - * @param repo Repository where to find the refs - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo); - -/** - * Callback used to iterate over references - * - * @see git_reference_foreach - * - * @param reference The reference object - * @param payload Payload passed to git_reference_foreach - * @return non-zero to terminate the iteration - */ -typedef int GIT_CALLBACK(git_reference_foreach_cb)(git_reference *reference, void *payload); - -/** - * Callback used to iterate over reference names - * - * @see git_reference_foreach_name - * - * @param name The reference name - * @param payload Payload passed to git_reference_foreach_name - * @return non-zero to terminate the iteration - */ -typedef int GIT_CALLBACK(git_reference_foreach_name_cb)(const char *name, void *payload); - -/** - * Perform a callback on each reference in the repository. - * - * The `callback` function will be called for each reference in the - * repository, receiving the reference object and the `payload` value - * passed to this method. Returning a non-zero value from the callback - * will terminate the iteration. - * - * Note that the callback function is responsible to call `git_reference_free` - * on each reference passed to it. - * - * @param repo Repository where to find the refs - * @param callback Function which will be called for every listed ref - * @param payload Additional data to pass to the callback - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_reference_foreach( - git_repository *repo, - git_reference_foreach_cb callback, - void *payload); - -/** - * Perform a callback on the fully-qualified name of each reference. - * - * The `callback` function will be called for each reference in the - * repository, receiving the name of the reference and the `payload` value - * passed to this method. Returning a non-zero value from the callback - * will terminate the iteration. - * - * @param repo Repository where to find the refs - * @param callback Function which will be called for every listed ref name - * @param payload Additional data to pass to the callback - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_reference_foreach_name( - git_repository *repo, - git_reference_foreach_name_cb callback, - void *payload); - -/** - * Create a copy of an existing reference. - * - * Call `git_reference_free` to free the data. - * - * @param dest pointer where to store the copy - * @param source object to copy - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reference_dup(git_reference **dest, git_reference *source); - -/** - * Free the given reference. - * - * @param ref git_reference - */ -GIT_EXTERN(void) git_reference_free(git_reference *ref); - -/** - * Compare two references. - * - * @param ref1 The first git_reference - * @param ref2 The second git_reference - * @return 0 if the same, else a stable but meaningless ordering. - */ -GIT_EXTERN(int) git_reference_cmp( - const git_reference *ref1, - const git_reference *ref2); - -/** - * Create an iterator for the repo's references - * - * @param[out] out pointer in which to store the iterator - * @param repo the repository - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reference_iterator_new( - git_reference_iterator **out, - git_repository *repo); - -/** - * Create an iterator for the repo's references that match the - * specified glob - * - * @param out pointer in which to store the iterator - * @param repo the repository - * @param glob the glob to match against the reference names - * @return 0 or an error code - */ -GIT_EXTERN(int) git_reference_iterator_glob_new( - git_reference_iterator **out, - git_repository *repo, - const char *glob); - -/** - * Get the next reference - * - * @param[out] out pointer in which to store the reference - * @param iter the iterator - * @return 0, GIT_ITEROVER if there are no more; or an error code - */ -GIT_EXTERN(int) git_reference_next(git_reference **out, git_reference_iterator *iter); - -/** - * Get the next reference's name - * - * This function is provided for convenience in case only the names - * are interesting as it avoids the allocation of the `git_reference` - * object which `git_reference_next()` needs. - * - * @param out pointer in which to store the string - * @param iter the iterator - * @return 0, GIT_ITEROVER if there are no more; or an error code - */ -GIT_EXTERN(int) git_reference_next_name(const char **out, git_reference_iterator *iter); - -/** - * Free the iterator and its associated resources - * - * @param iter the iterator to free - */ -GIT_EXTERN(void) git_reference_iterator_free(git_reference_iterator *iter); - -/** - * Perform a callback on each reference in the repository whose name - * matches the given pattern. - * - * This function acts like `git_reference_foreach()` with an additional - * pattern match being applied to the reference name before issuing the - * callback function. See that function for more information. - * - * The pattern is matched using fnmatch or "glob" style where a '*' matches - * any sequence of letters, a '?' matches any letter, and square brackets - * can be used to define character ranges (such as "[0-9]" for digits). - * - * @param repo Repository where to find the refs - * @param glob Pattern to match (fnmatch-style) against reference name. - * @param callback Function which will be called for every listed ref - * @param payload Additional data to pass to the callback - * @return 0 on success, GIT_EUSER on non-zero callback, or error code - */ -GIT_EXTERN(int) git_reference_foreach_glob( - git_repository *repo, - const char *glob, - git_reference_foreach_name_cb callback, - void *payload); - -/** - * Check if a reflog exists for the specified reference. - * - * @param repo the repository - * @param refname the reference's name - * @return 0 when no reflog can be found, 1 when it exists; - * otherwise an error code. - */ -GIT_EXTERN(int) git_reference_has_log(git_repository *repo, const char *refname); - -/** - * Ensure there is a reflog for a particular reference. - * - * Make sure that successive updates to the reference will append to - * its log. - * - * @param repo the repository - * @param refname the reference's name - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_reference_ensure_log(git_repository *repo, const char *refname); - -/** - * Check if a reference is a local branch. - * - * @param ref A git reference - * - * @return 1 when the reference lives in the refs/heads - * namespace; 0 otherwise. - */ -GIT_EXTERN(int) git_reference_is_branch(const git_reference *ref); - -/** - * Check if a reference is a remote tracking branch - * - * @param ref A git reference - * - * @return 1 when the reference lives in the refs/remotes - * namespace; 0 otherwise. - */ -GIT_EXTERN(int) git_reference_is_remote(const git_reference *ref); - -/** - * Check if a reference is a tag - * - * @param ref A git reference - * - * @return 1 when the reference lives in the refs/tags - * namespace; 0 otherwise. - */ -GIT_EXTERN(int) git_reference_is_tag(const git_reference *ref); - -/** - * Check if a reference is a note - * - * @param ref A git reference - * - * @return 1 when the reference lives in the refs/notes - * namespace; 0 otherwise. - */ -GIT_EXTERN(int) git_reference_is_note(const git_reference *ref); - -/** - * Normalization options for reference lookup - */ -typedef enum { - /** - * No particular normalization. - */ - GIT_REFERENCE_FORMAT_NORMAL = 0u, - - /** - * Control whether one-level refnames are accepted - * (i.e., refnames that do not contain multiple /-separated - * components). Those are expected to be written only using - * uppercase letters and underscore (FETCH_HEAD, ...) - */ - GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL = (1u << 0), - - /** - * Interpret the provided name as a reference pattern for a - * refspec (as used with remote repositories). If this option - * is enabled, the name is allowed to contain a single * () - * in place of a one full pathname component - * (e.g., foo//bar but not foo/bar). - */ - GIT_REFERENCE_FORMAT_REFSPEC_PATTERN = (1u << 1), - - /** - * Interpret the name as part of a refspec in shorthand form - * so the `ONELEVEL` naming rules aren't enforced and 'master' - * becomes a valid name. - */ - GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2) -} git_reference_format_t; - -/** - * Normalize reference name and check validity. - * - * This will normalize the reference name by removing any leading slash - * '/' characters and collapsing runs of adjacent slashes between name - * components into a single slash. - * - * Once normalized, if the reference name is valid, it will be returned in - * the user allocated buffer. - * - * See `git_reference_symbolic_create()` for rules about valid names. - * - * @param buffer_out User allocated buffer to store normalized name - * @param buffer_size Size of buffer_out - * @param name Reference name to be checked. - * @param flags Flags to constrain name validation rules - see the - * GIT_REFERENCE_FORMAT constants above. - * @return 0 on success, GIT_EBUFS if buffer is too small, GIT_EINVALIDSPEC - * or an error code. - */ -GIT_EXTERN(int) git_reference_normalize_name( - char *buffer_out, - size_t buffer_size, - const char *name, - unsigned int flags); - -/** - * Recursively peel reference until object of the specified type is found. - * - * The retrieved `peeled` object is owned by the repository - * and should be closed with the `git_object_free` method. - * - * If you pass `GIT_OBJECT_ANY` as the target type, then the object - * will be peeled until a non-tag object is met. - * - * @param[out] out Pointer to the peeled git_object - * @param ref The reference to be processed - * @param type The type of the requested object (GIT_OBJECT_COMMIT, - * GIT_OBJECT_TAG, GIT_OBJECT_TREE, GIT_OBJECT_BLOB or GIT_OBJECT_ANY). - * @return 0 on success, GIT_EAMBIGUOUS, GIT_ENOTFOUND or an error code - */ -GIT_EXTERN(int) git_reference_peel( - git_object **out, - const git_reference *ref, - git_object_t type); - -/** - * Ensure the reference name is well-formed. - * - * Valid reference names must follow one of two patterns: - * - * 1. Top-level names must contain only capital letters and underscores, - * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). - * 2. Names prefixed with "refs/" can be almost anything. You must avoid - * the characters '~', '^', ':', '\\', '?', '[', and '*', and the - * sequences ".." and "@{" which have special meaning to revparse. - * - * @param valid output pointer to set with validity of given reference name - * @param refname name to be checked. - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_reference_name_is_valid(int *valid, const char *refname); - -/** - * Get the reference's short name - * - * This will transform the reference name into a name "human-readable" - * version. If no shortname is appropriate, it will return the full - * name. - * - * The memory is owned by the reference and must not be freed. - * - * @param ref a reference - * @return the human-readable version of the name - */ -GIT_EXTERN(const char *) git_reference_shorthand(const git_reference *ref); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/refspec.h b/vendor/libgit2-sys/libgit2/include/git2/refspec.h deleted file mode 100644 index 49d5f89..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/refspec.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_refspec_h__ -#define INCLUDE_git_refspec_h__ - -#include "common.h" -#include "types.h" -#include "net.h" -#include "buffer.h" - -/** - * @file git2/refspec.h - * @brief Refspecs map local references to remote references - * @defgroup git_refspec Refspecs map local references to remote references - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Parse a given refspec string - * - * @param refspec a pointer to hold the refspec handle - * @param input the refspec string - * @param is_fetch is this a refspec for a fetch - * @return 0 if the refspec string could be parsed, -1 otherwise - */ -GIT_EXTERN(int) git_refspec_parse(git_refspec **refspec, const char *input, int is_fetch); - -/** - * Free a refspec object which has been created by git_refspec_parse - * - * @param refspec the refspec object - */ -GIT_EXTERN(void) git_refspec_free(git_refspec *refspec); - -/** - * Get the source specifier - * - * @param refspec the refspec - * @return the refspec's source specifier - */ -GIT_EXTERN(const char *) git_refspec_src(const git_refspec *refspec); - -/** - * Get the destination specifier - * - * @param refspec the refspec - * @return the refspec's destination specifier - */ -GIT_EXTERN(const char *) git_refspec_dst(const git_refspec *refspec); - -/** - * Get the refspec's string - * - * @param refspec the refspec - * @return the refspec's original string - */ -GIT_EXTERN(const char *) git_refspec_string(const git_refspec *refspec); - -/** - * Get the force update setting - * - * @param refspec the refspec - * @return 1 if force update has been set, 0 otherwise - */ -GIT_EXTERN(int) git_refspec_force(const git_refspec *refspec); - -/** - * Get the refspec's direction. - * - * @param spec refspec - * @return GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH - */ -GIT_EXTERN(git_direction) git_refspec_direction(const git_refspec *spec); - -/** - * Check if a refspec's source descriptor matches a negative reference - * - * @param refspec the refspec - * @param refname the name of the reference to check - * @return 1 if the refspec matches, 0 otherwise - */ -GIT_EXTERN(int) git_refspec_src_matches_negative(const git_refspec *refspec, const char *refname); - -/** - * Check if a refspec's source descriptor matches a reference - * - * @param refspec the refspec - * @param refname the name of the reference to check - * @return 1 if the refspec matches, 0 otherwise - */ -GIT_EXTERN(int) git_refspec_src_matches(const git_refspec *refspec, const char *refname); - -/** - * Check if a refspec's destination descriptor matches a reference - * - * @param refspec the refspec - * @param refname the name of the reference to check - * @return 1 if the refspec matches, 0 otherwise - */ -GIT_EXTERN(int) git_refspec_dst_matches(const git_refspec *refspec, const char *refname); - -/** - * Transform a reference to its target following the refspec's rules - * - * @param out where to store the target name - * @param spec the refspec - * @param name the name of the reference to transform - * @return 0, GIT_EBUFS or another error - */ -GIT_EXTERN(int) git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name); - -/** - * Transform a target reference to its source reference following the refspec's rules - * - * @param out where to store the source reference name - * @param spec the refspec - * @param name the name of the reference to transform - * @return 0, GIT_EBUFS or another error - */ -GIT_EXTERN(int) git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/remote.h b/vendor/libgit2-sys/libgit2/include/git2/remote.h deleted file mode 100644 index e4254e0..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/remote.h +++ /dev/null @@ -1,1261 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_remote_h__ -#define INCLUDE_git_remote_h__ - -#include "common.h" -#include "repository.h" -#include "refspec.h" -#include "net.h" -#include "indexer.h" -#include "strarray.h" -#include "transport.h" -#include "pack.h" -#include "proxy.h" - -/** - * @file git2/remote.h - * @brief Remotes are where local repositories fetch from and push to - * @defgroup git_remote Remotes are where local repositories fetch from and push to - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Add a remote with the default fetch refspec to the repository's configuration. - * - * @param out the resulting remote - * @param repo the repository in which to create the remote - * @param name the remote's name - * @param url the remote's url - * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code - */ -GIT_EXTERN(int) git_remote_create( - git_remote **out, - git_repository *repo, - const char *name, - const char *url); - -/** - * Remote redirection settings; whether redirects to another host - * are permitted. By default, git will follow a redirect on the - * initial request (`/info/refs`), but not subsequent requests. - */ -typedef enum { - /** - * Do not follow any off-site redirects at any stage of - * the fetch or push. - */ - GIT_REMOTE_REDIRECT_NONE = (1 << 0), - - /** - * Allow off-site redirects only upon the initial request. - * This is the default. - */ - GIT_REMOTE_REDIRECT_INITIAL = (1 << 1), - - /** - * Allow redirects at any stage in the fetch or push. - */ - GIT_REMOTE_REDIRECT_ALL = (1 << 2) -} git_remote_redirect_t; - -/** - * Remote creation options flags - */ -typedef enum { - /** Ignore the repository apply.insteadOf configuration */ - GIT_REMOTE_CREATE_SKIP_INSTEADOF = (1 << 0), - - /** Don't build a fetchspec from the name if none is set */ - GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = (1 << 1) -} git_remote_create_flags; - -/** - * How to handle reference updates. - */ -typedef enum { - /* Write the fetch results to FETCH_HEAD. */ - GIT_REMOTE_UPDATE_FETCHHEAD = (1 << 0), - - /* Report unchanged tips in the update_refs callback. */ - GIT_REMOTE_UPDATE_REPORT_UNCHANGED = (1 << 1) -} git_remote_update_flags; - -/** - * Remote creation options structure - * - * Initialize with `GIT_REMOTE_CREATE_OPTIONS_INIT`. Alternatively, you can - * use `git_remote_create_options_init`. - * - */ -typedef struct git_remote_create_options { - unsigned int version; - - /** - * The repository that should own the remote. - * Setting this to NULL results in a detached remote. - */ - git_repository *repository; - - /** - * The remote's name. - * Setting this to NULL results in an in-memory/anonymous remote. - */ - const char *name; - - /** The fetchspec the remote should use. */ - const char *fetchspec; - - /** Additional flags for the remote. See git_remote_create_flags. */ - unsigned int flags; -} git_remote_create_options; - -/** Current version for the `git_remote_create_options` structure */ -#define GIT_REMOTE_CREATE_OPTIONS_VERSION 1 - -/** Static constructor for `git_remote_create_options` */ -#define GIT_REMOTE_CREATE_OPTIONS_INIT {GIT_REMOTE_CREATE_OPTIONS_VERSION} - -/** - * Initialize git_remote_create_options structure - * - * Initializes a `git_remote_create_options` with default values. Equivalent to - * creating an instance with `GIT_REMOTE_CREATE_OPTIONS_INIT`. - * - * @param opts The `git_remote_create_options` struct to initialize. - * @param version The struct version; pass `GIT_REMOTE_CREATE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_remote_create_options_init( - git_remote_create_options *opts, - unsigned int version); - -/** - * Create a remote, with options. - * - * This function allows more fine-grained control over the remote creation. - * - * Passing NULL as the opts argument will result in a detached remote. - * - * @param out the resulting remote - * @param url the remote's url - * @param opts the remote creation options - * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code - */ -GIT_EXTERN(int) git_remote_create_with_opts( - git_remote **out, - const char *url, - const git_remote_create_options *opts); - -/** - * Add a remote with the provided fetch refspec (or default if NULL) to the repository's - * configuration. - * - * @param out the resulting remote - * @param repo the repository in which to create the remote - * @param name the remote's name - * @param url the remote's url - * @param fetch the remote fetch value - * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code - */ -GIT_EXTERN(int) git_remote_create_with_fetchspec( - git_remote **out, - git_repository *repo, - const char *name, - const char *url, - const char *fetch); - -/** - * Create an anonymous remote - * - * Create a remote with the given url in-memory. You can use this when - * you have a URL instead of a remote's name. - * - * @param out pointer to the new remote objects - * @param repo the associated repository - * @param url the remote repository's URL - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_create_anonymous( - git_remote **out, - git_repository *repo, - const char *url); - -/** - * Create a remote without a connected local repo - * - * Create a remote with the given url in-memory. You can use this when - * you have a URL instead of a remote's name. - * - * Contrasted with git_remote_create_anonymous, a detached remote - * will not consider any repo configuration values (such as insteadof url - * substitutions). - * - * @param out pointer to the new remote objects - * @param url the remote repository's URL - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_create_detached( - git_remote **out, - const char *url); - -/** - * Get the information for a particular remote - * - * The name will be checked for validity. - * See `git_tag_create()` for rules about valid names. - * - * @param out pointer to the new remote object - * @param repo the associated repository - * @param name the remote's name - * @return 0, GIT_ENOTFOUND, GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_remote_lookup(git_remote **out, git_repository *repo, const char *name); - -/** - * Create a copy of an existing remote. All internal strings are also - * duplicated. Callbacks are not duplicated. - * - * Call `git_remote_free` to free the data. - * - * @param dest pointer where to store the copy - * @param source object to copy - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_dup(git_remote **dest, git_remote *source); - -/** - * Get the remote's repository - * - * @param remote the remote - * @return a pointer to the repository - */ -GIT_EXTERN(git_repository *) git_remote_owner(const git_remote *remote); - -/** - * Get the remote's name - * - * @param remote the remote - * @return a pointer to the name or NULL for in-memory remotes - */ -GIT_EXTERN(const char *) git_remote_name(const git_remote *remote); - -/** - * Get the remote's url - * - * If url.*.insteadOf has been configured for this URL, it will return - * the modified URL. This function does not consider if a push url has - * been configured for this remote (use `git_remote_pushurl` if needed). - * - * @param remote the remote - * @return a pointer to the url - */ -GIT_EXTERN(const char *) git_remote_url(const git_remote *remote); - -/** - * Get the remote's url for pushing. - * - * If url.*.pushInsteadOf has been configured for this URL, it - * will return the modified URL. If `git_remote_set_instance_pushurl` - * has been called for this remote, then that URL will be returned. - * - * @param remote the remote - * @return a pointer to the url or NULL if no special url for pushing is set - */ -GIT_EXTERN(const char *) git_remote_pushurl(const git_remote *remote); - -/** - * Set the remote's url in the configuration - * - * Remote objects already in memory will not be affected. This assumes - * the common case of a single-url remote and will otherwise return an error. - * - * @param repo the repository in which to perform the change - * @param remote the remote's name - * @param url the url to set - * @return 0 or an error value - */ -GIT_EXTERN(int) git_remote_set_url(git_repository *repo, const char *remote, const char *url); - -/** - * Set the remote's url for pushing in the configuration. - * - * Remote objects already in memory will not be affected. This assumes - * the common case of a single-url remote and will otherwise return an error. - * - * - * @param repo the repository in which to perform the change - * @param remote the remote's name - * @param url the url to set - * @return 0, or an error code - */ -GIT_EXTERN(int) git_remote_set_pushurl(git_repository *repo, const char *remote, const char *url); - -/** - * Set the url for this particular url instance. The URL in the - * configuration will be ignored, and will not be changed. - * - * @param remote the remote's name - * @param url the url to set - * @return 0 or an error value - */ -GIT_EXTERN(int) git_remote_set_instance_url(git_remote *remote, const char *url); - -/** - * Set the push url for this particular url instance. The URL in the - * configuration will be ignored, and will not be changed. - * - * @param remote the remote's name - * @param url the url to set - * @return 0 or an error value - */ -GIT_EXTERN(int) git_remote_set_instance_pushurl(git_remote *remote, const char *url); - -/** - * Add a fetch refspec to the remote's configuration - * - * Add the given refspec to the fetch list in the configuration. No - * loaded remote instances will be affected. - * - * @param repo the repository in which to change the configuration - * @param remote the name of the remote to change - * @param refspec the new fetch refspec - * @return 0, GIT_EINVALIDSPEC if refspec is invalid or an error value - */ -GIT_EXTERN(int) git_remote_add_fetch(git_repository *repo, const char *remote, const char *refspec); - -/** - * Get the remote's list of fetch refspecs - * - * The memory is owned by the user and should be freed with - * `git_strarray_free`. - * - * @param array pointer to the array in which to store the strings - * @param remote the remote to query - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_remote_get_fetch_refspecs(git_strarray *array, const git_remote *remote); - -/** - * Add a push refspec to the remote's configuration - * - * Add the given refspec to the push list in the configuration. No - * loaded remote instances will be affected. - * - * @param repo the repository in which to change the configuration - * @param remote the name of the remote to change - * @param refspec the new push refspec - * @return 0, GIT_EINVALIDSPEC if refspec is invalid or an error value - */ -GIT_EXTERN(int) git_remote_add_push(git_repository *repo, const char *remote, const char *refspec); - -/** - * Get the remote's list of push refspecs - * - * The memory is owned by the user and should be freed with - * `git_strarray_free`. - * - * @param array pointer to the array in which to store the strings - * @param remote the remote to query - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_remote_get_push_refspecs(git_strarray *array, const git_remote *remote); - -/** - * Get the number of refspecs for a remote - * - * @param remote the remote - * @return the amount of refspecs configured in this remote - */ -GIT_EXTERN(size_t) git_remote_refspec_count(const git_remote *remote); - -/** - * Get a refspec from the remote - * - * @param remote the remote to query - * @param n the refspec to get - * @return the nth refspec - */ -GIT_EXTERN(const git_refspec *)git_remote_get_refspec(const git_remote *remote, size_t n); - -/** - * Get the remote repository's reference advertisement list - * - * Get the list of references with which the server responds to a new - * connection. - * - * The remote (or more exactly its transport) must have connected to - * the remote repository. This list is available as soon as the - * connection to the remote is initiated and it remains available - * after disconnecting. - * - * The memory belongs to the remote. The pointer will be valid as long - * as a new connection is not initiated, but it is recommended that - * you make a copy in order to make use of the data. - * - * @param out pointer to the array - * @param size the number of remote heads - * @param remote the remote - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote); - -/** - * Check whether the remote is connected - * - * Check whether the remote's underlying transport is connected to the - * remote host. - * - * @param remote the remote - * @return 1 if it's connected, 0 otherwise. - */ -GIT_EXTERN(int) git_remote_connected(const git_remote *remote); - -/** - * Get the remote repository's object format. - * - * The remote (or more exactly its transport) must have connected to - * the remote repository. This format is available as soon as the - * connection to the remote is initiated and stays connected. - * - * @param out the resulting object format type - * @param remote the remote - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_remote_oid_type(git_oid_t *out, git_remote *remote); - -/** - * Cancel the operation - * - * At certain points in its operation, the network code checks whether - * the operation has been cancelled and if so stops the operation. - * - * @param remote the remote - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_remote_stop(git_remote *remote); - -/** - * Disconnect from the remote - * - * Close the connection to the remote. - * - * @param remote the remote to disconnect from - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_remote_disconnect(git_remote *remote); - -/** - * Free the memory associated with a remote - * - * This also disconnects from the remote, if the connection - * has not been closed yet (using git_remote_disconnect). - * - * @param remote the remote to free - */ -GIT_EXTERN(void) git_remote_free(git_remote *remote); - -/** - * Get a list of the configured remotes for a repo - * - * The string array must be freed by the user. - * - * @param out a string array which receives the names of the remotes - * @param repo the repository to query - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo); - -/** - * Argument to the completion callback which tells it which operation - * finished. - */ -typedef enum git_remote_completion_t { - GIT_REMOTE_COMPLETION_DOWNLOAD, - GIT_REMOTE_COMPLETION_INDEXING, - GIT_REMOTE_COMPLETION_ERROR -} git_remote_completion_t; - -/** - * Push network progress notification callback. - * - * @param current The number of objects pushed so far - * @param total The total number of objects to push - * @param bytes The number of bytes pushed - * @param payload The user-specified payload callback - * @return 0 or an error code to stop the transfer - */ -typedef int GIT_CALLBACK(git_push_transfer_progress_cb)( - unsigned int current, - unsigned int total, - size_t bytes, - void *payload); - -/** - * Represents an update which will be performed on the remote during push - */ -typedef struct { - /** - * The source name of the reference - */ - char *src_refname; - /** - * The name of the reference to update on the server - */ - char *dst_refname; - /** - * The current target of the reference - */ - git_oid src; - /** - * The new target for the reference - */ - git_oid dst; -} git_push_update; - -/** - * Callback used to inform of upcoming updates. - * - * @param updates an array containing the updates which will be sent - * as commands to the destination. - * @param len number of elements in `updates` - * @param payload Payload provided by the caller - * @return 0 or an error code to stop the push - */ -typedef int GIT_CALLBACK(git_push_negotiation)( - const git_push_update **updates, - size_t len, - void *payload); - -/** - * Callback used to inform of the update status from the remote. - * - * Called for each updated reference on push. If `status` is - * not `NULL`, the update was rejected by the remote server - * and `status` contains the reason given. - * - * @param refname refname specifying to the remote ref - * @param status status message sent from the remote - * @param data data provided by the caller - * @return 0 on success, otherwise an error - */ -typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, const char *status, void *data); - -#ifndef GIT_DEPRECATE_HARD -/** - * Callback to resolve URLs before connecting to remote - * - * If you return GIT_PASSTHROUGH, you don't need to write anything to - * url_resolved. - * - * @param url_resolved The buffer to write the resolved URL to - * @param url The URL to resolve - * @param direction GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH - * @param payload Payload provided by the caller - * @return 0 on success, GIT_PASSTHROUGH or an error - * @deprecated Use `git_remote_set_instance_url` - */ -typedef int GIT_CALLBACK(git_url_resolve_cb)(git_buf *url_resolved, const char *url, int direction, void *payload); -#endif - -/** - * Callback invoked immediately before we attempt to connect to the - * given url. Callers may change the URL before the connection by - * calling `git_remote_set_instance_url` in the callback. - * - * @param remote The remote to be connected - * @param direction GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH - * @param payload Payload provided by the caller - * @return 0 on success, or an error - */ -typedef int GIT_CALLBACK(git_remote_ready_cb)(git_remote *remote, int direction, void *payload); - -/** - * The callback settings structure - * - * Set the callbacks to be called by the remote when informing the user - * about the progress of the network operations. - */ -struct git_remote_callbacks { - unsigned int version; /**< The version */ - - /** - * Textual progress from the remote. Text send over the - * progress side-band will be passed to this function (this is - * the 'counting objects' output). - */ - git_transport_message_cb sideband_progress; - - /** - * Completion is called when different parts of the download - * process are done (currently unused). - */ - int GIT_CALLBACK(completion)(git_remote_completion_t type, - void *data); - - /** - * This will be called if the remote host requires - * authentication in order to connect to it. - * - * Returning GIT_PASSTHROUGH will make libgit2 behave as - * though this field isn't set. - */ - git_credential_acquire_cb credentials; - - /** - * This will be called to let the user make the final decision of whether - * to allow the connection to proceed. Returns 0 to allow the connection - * or a negative value to indicate an error. - */ - git_transport_certificate_check_cb certificate_check; - - /** - * During the download of new data, this will be regularly - * called with the current count of progress done by the - * indexer. - */ - git_indexer_progress_cb transfer_progress; - -#ifdef GIT_DEPRECATE_HARD - void *reserved_update_tips; -#else - /** - * Deprecated callback for reference updates, callers should - * set `update_refs` instead. This is retained for backward - * compatibility; if you specify both `update_refs` and - * `update_tips`, then only the `update_refs` function will - * be called. - * - * @deprecated the `update_refs` callback in this structure - * should be preferred - */ - int GIT_CALLBACK(update_tips)(const char *refname, - const git_oid *a, const git_oid *b, void *data); -#endif - - /** - * Function to call with progress information during pack - * building. Be aware that this is called inline with pack - * building operations, so performance may be affected. - */ - git_packbuilder_progress pack_progress; - - /** - * Function to call with progress information during the - * upload portion of a push. Be aware that this is called - * inline with pack building operations, so performance may be - * affected. - */ - git_push_transfer_progress_cb push_transfer_progress; - - /** - * See documentation of git_push_update_reference_cb - */ - git_push_update_reference_cb push_update_reference; - - /** - * Called once between the negotiation step and the upload. It - * provides information about what updates will be performed. - */ - git_push_negotiation push_negotiation; - - /** - * Create the transport to use for this operation. Leave NULL - * to auto-detect. - */ - git_transport_cb transport; - - /** - * Callback when the remote is ready to connect. - */ - git_remote_ready_cb remote_ready; - - /** - * This will be passed to each of the callbacks in this struct - * as the last parameter. - */ - void *payload; - -#ifdef GIT_DEPRECATE_HARD - void *reserved; -#else - /** - * Resolve URL before connecting to remote. - * The returned URL will be used to connect to the remote instead. - * - * This callback is deprecated; users should use - * git_remote_ready_cb and configure the instance URL instead. - */ - git_url_resolve_cb resolve_url; -#endif - - /** - * Each time a reference is updated locally, this function - * will be called with information about it. This should be - * preferred over the `update_tips` callback in this - * structure. - */ - int GIT_CALLBACK(update_refs)( - const char *refname, - const git_oid *a, - const git_oid *b, - git_refspec *spec, - void *data); -}; - -/** Current version for the `git_remote_callbacks_options` structure */ -#define GIT_REMOTE_CALLBACKS_VERSION 1 - -/** Static constructor for `git_remote_callbacks_options` */ -#define GIT_REMOTE_CALLBACKS_INIT {GIT_REMOTE_CALLBACKS_VERSION} - -/** - * Initializes a `git_remote_callbacks` with default values. Equivalent to - * creating an instance with GIT_REMOTE_CALLBACKS_INIT. - * - * @param opts the `git_remote_callbacks` struct to initialize - * @param version Version of struct; pass `GIT_REMOTE_CALLBACKS_VERSION` - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_remote_init_callbacks( - git_remote_callbacks *opts, - unsigned int version); - -/** Acceptable prune settings when fetching */ -typedef enum { - /** - * Use the setting from the configuration - */ - GIT_FETCH_PRUNE_UNSPECIFIED, - /** - * Force pruning on - */ - GIT_FETCH_PRUNE, - /** - * Force pruning off - */ - GIT_FETCH_NO_PRUNE -} git_fetch_prune_t; - -/** - * Automatic tag following option - * - * Lets us select the --tags option to use. - */ -typedef enum { - /** - * Use the setting from the configuration. - */ - GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED = 0, - /** - * Ask the server for tags pointing to objects we're already - * downloading. - */ - GIT_REMOTE_DOWNLOAD_TAGS_AUTO, - /** - * Don't ask for any tags beyond the refspecs. - */ - GIT_REMOTE_DOWNLOAD_TAGS_NONE, - /** - * Ask for all the tags. - */ - GIT_REMOTE_DOWNLOAD_TAGS_ALL -} git_remote_autotag_option_t; - -/** Constants for fetch depth (shallowness of fetch). */ -typedef enum { - /** The fetch is "full" (not shallow). This is the default. */ - GIT_FETCH_DEPTH_FULL = 0, - - /** The fetch should "unshallow" and fetch missing data. */ - GIT_FETCH_DEPTH_UNSHALLOW = 2147483647 -} git_fetch_depth_t; - -/** - * Fetch options structure. - * - * Zero out for defaults. Initialize with `GIT_FETCH_OPTIONS_INIT` macro to - * correctly set the `version` field. E.g. - * - * git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; - */ -typedef struct { - int version; - - /** - * Callbacks to use for this fetch operation - */ - git_remote_callbacks callbacks; - - /** - * Whether to perform a prune after the fetch - */ - git_fetch_prune_t prune; - - /** - * How to handle reference updates; see `git_remote_update_flags`. - */ - unsigned int update_fetchhead; - - /** - * Determines how to behave regarding tags on the remote, such - * as auto-downloading tags for objects we're downloading or - * downloading all of them. - * - * The default is to auto-follow tags. - */ - git_remote_autotag_option_t download_tags; - - /** - * Proxy options to use, by default no proxy is used. - */ - git_proxy_options proxy_opts; - - /** - * Depth of the fetch to perform, or `GIT_FETCH_DEPTH_FULL` - * (or `0`) for full history, or `GIT_FETCH_DEPTH_UNSHALLOW` - * to "unshallow" a shallow repository. - * - * The default is full (`GIT_FETCH_DEPTH_FULL` or `0`). - */ - int depth; - - /** - * Whether to allow off-site redirects. If this is not - * specified, the `http.followRedirects` configuration setting - * will be consulted. - */ - git_remote_redirect_t follow_redirects; - - /** - * Extra headers for this fetch operation - */ - git_strarray custom_headers; -} git_fetch_options; - -/** Current version for the `git_fetch_options` structure */ -#define GIT_FETCH_OPTIONS_VERSION 1 - -/** Static constructor for `git_fetch_options` */ -#define GIT_FETCH_OPTIONS_INIT { \ - GIT_FETCH_OPTIONS_VERSION, \ - GIT_REMOTE_CALLBACKS_INIT, \ - GIT_FETCH_PRUNE_UNSPECIFIED, \ - GIT_REMOTE_UPDATE_FETCHHEAD, \ - GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, \ - GIT_PROXY_OPTIONS_INIT } - -/** - * Initialize git_fetch_options structure - * - * Initializes a `git_fetch_options` with default values. Equivalent to - * creating an instance with `GIT_FETCH_OPTIONS_INIT`. - * - * @param opts The `git_fetch_options` struct to initialize. - * @param version The struct version; pass `GIT_FETCH_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_fetch_options_init( - git_fetch_options *opts, - unsigned int version); - - -/** - * Controls the behavior of a git_push object. - */ -typedef struct { - unsigned int version; - - /** - * If the transport being used to push to the remote requires the creation - * of a pack file, this controls the number of worker threads used by - * the packbuilder when creating that pack file to be sent to the remote. - * - * If set to 0, the packbuilder will auto-detect the number of threads - * to create. The default value is 1. - */ - unsigned int pb_parallelism; - - /** - * Callbacks to use for this push operation - */ - git_remote_callbacks callbacks; - - /** - * Proxy options to use, by default no proxy is used. - */ - git_proxy_options proxy_opts; - - /** - * Whether to allow off-site redirects. If this is not - * specified, the `http.followRedirects` configuration setting - * will be consulted. - */ - git_remote_redirect_t follow_redirects; - - /** - * Extra headers for this push operation - */ - git_strarray custom_headers; - - /** - * "Push options" to deliver to the remote. - */ - git_strarray remote_push_options; -} git_push_options; - -/** Current version for the `git_push_options` structure */ -#define GIT_PUSH_OPTIONS_VERSION 1 - -/** Static constructor for `git_push_options` */ -#define GIT_PUSH_OPTIONS_INIT { GIT_PUSH_OPTIONS_VERSION, 1, GIT_REMOTE_CALLBACKS_INIT, GIT_PROXY_OPTIONS_INIT } - -/** - * Initialize git_push_options structure - * - * Initializes a `git_push_options` with default values. Equivalent to - * creating an instance with `GIT_PUSH_OPTIONS_INIT`. - * - * @param opts The `git_push_options` struct to initialize. - * @param version The struct version; pass `GIT_PUSH_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_push_options_init( - git_push_options *opts, - unsigned int version); - -/** - * Remote creation options structure - * - * Initialize with `GIT_REMOTE_CREATE_OPTIONS_INIT`. Alternatively, you can - * use `git_remote_create_options_init`. - * - */ -typedef struct { - unsigned int version; - - /** Callbacks to use for this connection */ - git_remote_callbacks callbacks; - - /** HTTP Proxy settings */ - git_proxy_options proxy_opts; - - /** - * Whether to allow off-site redirects. If this is not - * specified, the `http.followRedirects` configuration setting - * will be consulted. - */ - git_remote_redirect_t follow_redirects; - - /** Extra HTTP headers to use in this connection */ - git_strarray custom_headers; -} git_remote_connect_options; - -/** Current version for the `git_remote_connect_options` structure */ -#define GIT_REMOTE_CONNECT_OPTIONS_VERSION 1 - -/** Static constructor for `git_remote_connect_options` */ -#define GIT_REMOTE_CONNECT_OPTIONS_INIT { \ - GIT_REMOTE_CONNECT_OPTIONS_VERSION, \ - GIT_REMOTE_CALLBACKS_INIT, \ - GIT_PROXY_OPTIONS_INIT } - -/** - * Initialize git_remote_connect_options structure. - * - * Initializes a `git_remote_connect_options` with default values. - * Equivalent to creating an instance with - * `GIT_REMOTE_CONNECT_OPTIONS_INIT`. - * - * @param opts The `git_remote_connect_options` struct to initialize. - * @param version The struct version; pass `GIT_REMOTE_CONNECT_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_remote_connect_options_init( - git_remote_connect_options *opts, - unsigned int version); - -/** - * Open a connection to a remote. - * - * The transport is selected based on the URL; the direction argument - * is due to a limitation of the git protocol which starts up a - * specific binary which can only do the one or the other. - * - * @param remote the remote to connect to - * @param direction GIT_DIRECTION_FETCH if you want to fetch or - * GIT_DIRECTION_PUSH if you want to push - * @param callbacks the callbacks to use for this connection - * @param proxy_opts proxy settings - * @param custom_headers extra HTTP headers to use in this connection - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_connect( - git_remote *remote, - git_direction direction, - const git_remote_callbacks *callbacks, - const git_proxy_options *proxy_opts, - const git_strarray *custom_headers); - -/** - * Open a connection to a remote with extended options. - * - * The transport is selected based on the URL; the direction argument - * is due to a limitation of the git protocol which starts up a - * specific binary which can only do the one or the other. - * - * The given options structure will form the defaults for connection - * options and callback setup. Callers may override these defaults - * by specifying `git_fetch_options` or `git_push_options` in - * subsequent calls. - * - * @param remote the remote to connect to - * @param direction GIT_DIRECTION_FETCH if you want to fetch or - * GIT_DIRECTION_PUSH if you want to push - * @param opts the remote connection options - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_connect_ext( - git_remote *remote, - git_direction direction, - const git_remote_connect_options *opts); - -/** - * Download and index the packfile. - * - * Connect to the remote if it hasn't been done yet, negotiate with - * the remote git which objects are missing, download and index the - * packfile. - * - * The .idx file will be created and both it and the packfile with be - * renamed to their final name. - * - * If options are specified and this remote is already connected then - * the existing remote connection options will be discarded and the - * remote will now use the new options. - * - * @param remote the remote - * @param refspecs the refspecs to use for this negotiation and - * download. Use NULL or an empty array to use the base refspecs - * @param opts the options to use for this fetch or NULL - * @return 0 or an error code - */ - GIT_EXTERN(int) git_remote_download( - git_remote *remote, - const git_strarray *refspecs, - const git_fetch_options *opts); - -/** - * Create a packfile and send it to the server - * - * Connect to the remote if it hasn't been done yet, negotiate with - * the remote git which objects are missing, create a packfile with - * the missing objects and send it. - * - * If options are specified and this remote is already connected then - * the existing remote connection options will be discarded and the - * remote will now use the new options. - * - * @param remote the remote - * @param refspecs the refspecs to use for this negotiation and - * upload. Use NULL or an empty array to use the base refspecs - * @param opts the options to use for this push - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_upload( - git_remote *remote, - const git_strarray *refspecs, - const git_push_options *opts); - -/** - * Update the tips to the new state. - * - * If callbacks are not specified then the callbacks specified to - * `git_remote_connect` will be used (if it was called). - * - * @param remote the remote to update - * @param callbacks pointer to the callback structure to use or NULL - * @param update_flags the git_remote_update_flags for these tips. - * @param download_tags what the behaviour for downloading tags is for this fetch. This is - * ignored for push. This must be the same value passed to `git_remote_download()`. - * @param reflog_message The message to insert into the reflogs. If - * NULL and fetching, the default is "fetch ", where is - * the name of the remote (or its url, for in-memory remotes). This - * parameter is ignored when pushing. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_update_tips( - git_remote *remote, - const git_remote_callbacks *callbacks, - unsigned int update_flags, - git_remote_autotag_option_t download_tags, - const char *reflog_message); - -/** - * Download new data and update tips. - * - * Convenience function to connect to a remote, download the data, - * disconnect and update the remote-tracking branches. - * - * If options are specified and this remote is already connected then - * the existing remote connection options will be discarded and the - * remote will now use the new options. - * - * @param remote the remote to fetch from - * @param refspecs the refspecs to use for this fetch. Pass NULL or an - * empty array to use the base refspecs. - * @param opts options to use for this fetch or NULL - * @param reflog_message The message to insert into the reflogs. If NULL, the - * default is "fetch" - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_fetch( - git_remote *remote, - const git_strarray *refspecs, - const git_fetch_options *opts, - const char *reflog_message); - -/** - * Prune tracking refs that are no longer present on remote. - * - * If callbacks are not specified then the callbacks specified to - * `git_remote_connect` will be used (if it was called). - * - * @param remote the remote to prune - * @param callbacks callbacks to use for this prune - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_prune( - git_remote *remote, - const git_remote_callbacks *callbacks); - -/** - * Perform a push. - * - * If options are specified and this remote is already connected then - * the existing remote connection options will be discarded and the - * remote will now use the new options. - * - * @param remote the remote to push to - * @param refspecs the refspecs to use for pushing. If NULL or an empty - * array, the configured refspecs will be used - * @param opts options to use for this push - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_remote_push( - git_remote *remote, - const git_strarray *refspecs, - const git_push_options *opts); - -/** - * Get the statistics structure that is filled in by the fetch operation. - * - * @param remote the remote to get statistics for - * @return the git_indexer_progress for the remote - */ -GIT_EXTERN(const git_indexer_progress *) git_remote_stats(git_remote *remote); - -/** - * Retrieve the tag auto-follow setting - * - * @param remote the remote to query - * @return the auto-follow setting - */ -GIT_EXTERN(git_remote_autotag_option_t) git_remote_autotag(const git_remote *remote); - -/** - * Set the remote's tag following setting. - * - * The change will be made in the configuration. No loaded remotes - * will be affected. - * - * @param repo the repository in which to make the change - * @param remote the name of the remote - * @param value the new value to take. - * @return 0, or an error code. - */ -GIT_EXTERN(int) git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_autotag_option_t value); - -/** - * Retrieve the ref-prune setting - * - * @param remote the remote to query - * @return the ref-prune setting - */ -GIT_EXTERN(int) git_remote_prune_refs(const git_remote *remote); - -/** - * Give the remote a new name - * - * All remote-tracking branches and configuration settings - * for the remote are updated. - * - * The new name will be checked for validity. - * See `git_tag_create()` for rules about valid names. - * - * No loaded instances of a the remote with the old name will change - * their name or their list of refspecs. - * - * @param problems non-default refspecs cannot be renamed and will be - * stored here for further processing by the caller. Always free this - * strarray on successful return. - * @param repo the repository in which to rename - * @param name the current name of the remote - * @param new_name the new name the remote should bear - * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code - */ -GIT_EXTERN(int) git_remote_rename( - git_strarray *problems, - git_repository *repo, - const char *name, - const char *new_name); - -/** - * Ensure the remote name is well-formed. - * - * @param valid output pointer to set with validity of given remote name - * @param remote_name name to be checked. - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_remote_name_is_valid(int *valid, const char *remote_name); - -/** -* Delete an existing persisted remote. -* -* All remote-tracking branches and configuration settings -* for the remote will be removed. -* -* @param repo the repository in which to act -* @param name the name of the remote to delete -* @return 0 on success, or an error code. -*/ -GIT_EXTERN(int) git_remote_delete(git_repository *repo, const char *name); - -/** - * Retrieve the name of the remote's default branch - * - * The default branch of a repository is the branch which HEAD points - * to. If the remote does not support reporting this information - * directly, it performs the guess as git does; that is, if there are - * multiple branches which point to the same commit, the first one is - * chosen. If the master branch is a candidate, it wins. - * - * This function must only be called after connecting. - * - * @param out the buffer in which to store the reference name - * @param remote the remote - * @return 0, GIT_ENOTFOUND if the remote does not have any references - * or none of them point to HEAD's commit, or an error message. - */ -GIT_EXTERN(int) git_remote_default_branch(git_buf *out, git_remote *remote); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/repository.h b/vendor/libgit2-sys/libgit2/include/git2/repository.h deleted file mode 100644 index b203576..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/repository.h +++ /dev/null @@ -1,1019 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_repository_h__ -#define INCLUDE_git_repository_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "odb.h" -#include "buffer.h" -#include "commit.h" - -/** - * @file git2/repository.h - * @brief The repository stores revisions for a source tree - * @defgroup git_repository The repository stores revisions for a source tree - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Open a git repository. - * - * The 'path' argument must point to either a git repository - * folder, or an existing work dir. - * - * The method will automatically detect if 'path' is a normal - * or bare repository or fail is 'path' is neither. - * - * Note that the libgit2 library _must_ be initialized using - * `git_libgit2_init` before any APIs can be called, including - * this one. - * - * @param[out] out pointer to the repo which will be opened - * @param path the path to the repository - * @return 0 or an error code - */ -GIT_EXTERN(int) git_repository_open(git_repository **out, const char *path); -/** - * Open working tree as a repository - * - * Open the working directory of the working tree as a normal - * repository that can then be worked on. - * - * @param out Output pointer containing opened repository - * @param wt Working tree to open - * @return 0 or an error code - */ -GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_worktree *wt); - -/** - * Create a "fake" repository to wrap an object database - * - * Create a repository object to wrap an object database to be used - * with the API when all you have is an object database. This doesn't - * have any paths associated with it, so use with care. - * - * @param out pointer to the repo - * @param odb the object database to wrap - * @return 0 or an error code - */ -GIT_EXTERN(int) git_repository_wrap_odb( - git_repository **out, - git_odb *odb); - -/** - * Look for a git repository and copy its path in the given buffer. - * The lookup start from base_path and walk across parent directories - * if nothing has been found. The lookup ends when the first repository - * is found, or when reaching a directory referenced in ceiling_dirs - * or when the filesystem changes (in case across_fs is true). - * - * The method will automatically detect if the repository is bare - * (if there is a repository). - * - * Note that the libgit2 library _must_ be initialized using - * `git_libgit2_init` before any APIs can be called, including - * this one. - * - * @param out A pointer to a user-allocated git_buf which will contain - * the found path. - * - * @param start_path The base path where the lookup starts. - * - * @param across_fs If true, then the lookup will not stop when a - * filesystem device change is detected while exploring parent directories. - * - * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR separated list of - * absolute symbolic link free paths. The lookup will stop when any - * of this paths is reached. Note that the lookup always performs on - * start_path no matter start_path appears in ceiling_dirs ceiling_dirs - * might be NULL (which is equivalent to an empty string) - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_repository_discover( - git_buf *out, - const char *start_path, - int across_fs, - const char *ceiling_dirs); - -/** - * Option flags for `git_repository_open_ext`. - */ -typedef enum { - /** - * Only open the repository if it can be immediately found in the - * start_path. Do not walk up from the start_path looking at parent - * directories. - */ - GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0), - - /** - * Unless this flag is set, open will not continue searching across - * filesystem boundaries (i.e. when `st_dev` changes from the `stat` - * system call). For example, searching in a user's home directory at - * "/home/user/source/" will not return "/.git/" as the found repo if - * "/" is a different filesystem than "/home". - */ - GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1), - - /** - * Open repository as a bare repo regardless of core.bare config, and - * defer loading config file for faster setup. - * Unlike `git_repository_open_bare`, this can follow gitlinks. - */ - GIT_REPOSITORY_OPEN_BARE = (1 << 2), - - /** - * Do not check for a repository by appending /.git to the start_path; - * only open the repository if start_path itself points to the git - * directory. - */ - GIT_REPOSITORY_OPEN_NO_DOTGIT = (1 << 3), - - /** - * Find and open a git repository, respecting the environment variables - * used by the git command-line tools. - * If set, `git_repository_open_ext` will ignore the other flags and - * the `ceiling_dirs` argument, and will allow a NULL `path` to use - * `GIT_DIR` or search from the current directory. - * The search for a repository will respect $GIT_CEILING_DIRECTORIES and - * $GIT_DISCOVERY_ACROSS_FILESYSTEM. The opened repository will - * respect $GIT_INDEX_FILE, $GIT_NAMESPACE, $GIT_OBJECT_DIRECTORY, and - * $GIT_ALTERNATE_OBJECT_DIRECTORIES. - * In the future, this flag will also cause `git_repository_open_ext` - * to respect $GIT_WORK_TREE and $GIT_COMMON_DIR; currently, - * `git_repository_open_ext` with this flag will error out if either - * $GIT_WORK_TREE or $GIT_COMMON_DIR is set. - */ - GIT_REPOSITORY_OPEN_FROM_ENV = (1 << 4) -} git_repository_open_flag_t; - -/** - * Find and open a repository with extended controls. - * - * Note that the libgit2 library _must_ be initialized using - * `git_libgit2_init` before any APIs can be called, including - * this one. - * - * @param[out] out Pointer to the repo which will be opened. This can - * actually be NULL if you only want to use the error code to - * see if a repo at this path could be opened. - * @param path Path to open as git repository. If the flags - * permit "searching", then this can be a path to a subdirectory - * inside the working directory of the repository. May be NULL if - * flags is GIT_REPOSITORY_OPEN_FROM_ENV. - * @param flags A combination of the GIT_REPOSITORY_OPEN flags above. - * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR delimited list of path - * prefixes at which the search for a containing repository should - * terminate. - * @return 0 on success, GIT_ENOTFOUND if no repository could be found, - * or -1 if there was a repository but open failed for some reason - * (such as repo corruption or system errors). - */ -GIT_EXTERN(int) git_repository_open_ext( - git_repository **out, - const char *path, - unsigned int flags, - const char *ceiling_dirs); - -/** - * Open a bare repository on the serverside. - * - * This is a fast open for bare repositories that will come in handy - * if you're e.g. hosting git repositories and need to access them - * efficiently - * - * Note that the libgit2 library _must_ be initialized using - * `git_libgit2_init` before any APIs can be called, including - * this one. - * - * @param[out] out Pointer to the repo which will be opened. - * @param bare_path Direct path to the bare repository - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_open_bare(git_repository **out, const char *bare_path); - -/** - * Free a previously allocated repository - * - * Note that after a repository is free'd, all the objects it has spawned - * will still exist until they are manually closed by the user - * with `git_object_free`, but accessing any of the attributes of - * an object without a backing repository will result in undefined - * behavior - * - * @param repo repository handle to close. If NULL nothing occurs. - */ -GIT_EXTERN(void) git_repository_free(git_repository *repo); - -/** - * Creates a new Git repository in the given folder. - * - * TODO: - * - Reinit the repository - * - * Note that the libgit2 library _must_ be initialized using - * `git_libgit2_init` before any APIs can be called, including - * this one. - * - * @param[out] out pointer to the repo which will be created or reinitialized - * @param path the path to the repository - * @param is_bare if true, a Git repository without a working directory is - * created at the pointed path. If false, provided path will be - * considered as the working directory into which the .git directory - * will be created. - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_repository_init( - git_repository **out, - const char *path, - unsigned is_bare); - -/** - * Option flags for `git_repository_init_ext`. - * - * These flags configure extra behaviors to `git_repository_init_ext`. - * In every case, the default behavior is the zero value (i.e. flag is - * not set). Just OR the flag values together for the `flags` parameter - * when initializing a new repo. - */ -typedef enum { - /** - * Create a bare repository with no working directory. - */ - GIT_REPOSITORY_INIT_BARE = (1u << 0), - - /** - * Return an GIT_EEXISTS error if the repo_path appears to already be - * an git repository. - */ - GIT_REPOSITORY_INIT_NO_REINIT = (1u << 1), - - /** - * Normally a "/.git/" will be appended to the repo path for - * non-bare repos (if it is not already there), but passing this flag - * prevents that behavior. - */ - GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1u << 2), - - /** - * Make the repo_path (and workdir_path) as needed. Init is always willing - * to create the ".git" directory even without this flag. This flag tells - * init to create the trailing component of the repo and workdir paths - * as needed. - */ - GIT_REPOSITORY_INIT_MKDIR = (1u << 3), - - /** - * Recursively make all components of the repo and workdir paths as - * necessary. - */ - GIT_REPOSITORY_INIT_MKPATH = (1u << 4), - - /** - * libgit2 normally uses internal templates to initialize a new repo. - * This flags enables external templates, looking the "template_path" from - * the options if set, or the `init.templatedir` global config if not, - * or falling back on "/usr/share/git-core/templates" if it exists. - */ - GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1u << 5), - - /** - * If an alternate workdir is specified, use relative paths for the gitdir - * and core.worktree. - */ - GIT_REPOSITORY_INIT_RELATIVE_GITLINK = (1u << 6) -} git_repository_init_flag_t; - -/** - * Mode options for `git_repository_init_ext`. - * - * Set the mode field of the `git_repository_init_options` structure - * either to the custom mode that you would like, or to one of the - * defined modes. - */ -typedef enum { - /** - * Use permissions configured by umask - the default. - */ - GIT_REPOSITORY_INIT_SHARED_UMASK = 0, - - /** - * Use "--shared=group" behavior, chmod'ing the new repo to be group - * writable and "g+sx" for sticky group assignment. - */ - GIT_REPOSITORY_INIT_SHARED_GROUP = 0002775, - - /** - * Use "--shared=all" behavior, adding world readability. - */ - GIT_REPOSITORY_INIT_SHARED_ALL = 0002777 -} git_repository_init_mode_t; - -/** - * Extended options structure for `git_repository_init_ext`. - * - * This contains extra options for `git_repository_init_ext` that enable - * additional initialization features. - */ -typedef struct { - unsigned int version; - - /** - * Combination of GIT_REPOSITORY_INIT flags above. - */ - uint32_t flags; - - /** - * Set to one of the standard GIT_REPOSITORY_INIT_SHARED_... constants - * above, or to a custom value that you would like. - */ - uint32_t mode; - - /** - * The path to the working dir or NULL for default (i.e. repo_path parent - * on non-bare repos). IF THIS IS RELATIVE PATH, IT WILL BE EVALUATED - * RELATIVE TO THE REPO_PATH. If this is not the "natural" working - * directory, a .git gitlink file will be created here linking to the - * repo_path. - */ - const char *workdir_path; - - /** - * If set, this will be used to initialize the "description" file in the - * repository, instead of using the template content. - */ - const char *description; - - /** - * When GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set, this contains - * the path to use for the template directory. If this is NULL, the config - * or default directory options will be used instead. - */ - const char *template_path; - - /** - * The name of the head to point HEAD at. If NULL, then this will be - * treated as "master" and the HEAD ref will be set to "refs/heads/master". - * If this begins with "refs/" it will be used verbatim; - * otherwise "refs/heads/" will be prefixed. - */ - const char *initial_head; - - /** - * If this is non-NULL, then after the rest of the repository - * initialization is completed, an "origin" remote will be added - * pointing to this URL. - */ - const char *origin_url; - -#ifdef GIT_EXPERIMENTAL_SHA256 - /** - * - * Type of object IDs to use for this repository, or 0 for - * default (currently SHA1). - */ - git_oid_t oid_type; -#endif -} git_repository_init_options; - -/** Current version for the `git_repository_init_options` structure */ -#define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1 - -/** Static constructor for `git_repository_init_options` */ -#define GIT_REPOSITORY_INIT_OPTIONS_INIT {GIT_REPOSITORY_INIT_OPTIONS_VERSION} - -/** - * Initialize git_repository_init_options structure - * - * Initializes a `git_repository_init_options` with default values. Equivalent to - * creating an instance with `GIT_REPOSITORY_INIT_OPTIONS_INIT`. - * - * @param opts The `git_repository_init_options` struct to initialize. - * @param version The struct version; pass `GIT_REPOSITORY_INIT_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_repository_init_options_init( - git_repository_init_options *opts, - unsigned int version); - -/** - * Create a new Git repository in the given folder with extended controls. - * - * This will initialize a new git repository (creating the repo_path - * if requested by flags) and working directory as needed. It will - * auto-detect the case sensitivity of the file system and if the - * file system supports file mode bits correctly. - * - * Note that the libgit2 library _must_ be initialized using - * `git_libgit2_init` before any APIs can be called, including - * this one. - * - * @param out Pointer to the repo which will be created or reinitialized. - * @param repo_path The path to the repository. - * @param opts Pointer to git_repository_init_options struct. - * @return 0 or an error code on failure. - */ -GIT_EXTERN(int) git_repository_init_ext( - git_repository **out, - const char *repo_path, - git_repository_init_options *opts); - -/** - * Retrieve and resolve the reference pointed at by HEAD. - * - * The returned `git_reference` will be owned by caller and - * `git_reference_free()` must be called when done with it to release the - * allocated memory and prevent a leak. - * - * @param[out] out pointer to the reference which will be retrieved - * @param repo a repository object - * - * @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing - * branch, GIT_ENOTFOUND when HEAD is missing; an error code otherwise - */ -GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo); - -/** - * Retrieve the referenced HEAD for the worktree - * - * @param out pointer to the reference which will be retrieved - * @param repo a repository object - * @param name name of the worktree to retrieve HEAD for - * @return 0 when successful, error-code otherwise - */ -GIT_EXTERN(int) git_repository_head_for_worktree(git_reference **out, git_repository *repo, - const char *name); - -/** - * Check if a repository's HEAD is detached - * - * A repository's HEAD is detached when it points directly to a commit - * instead of a branch. - * - * @param repo Repo to test - * @return 1 if HEAD is detached, 0 if it's not; error code if there - * was an error. - */ -GIT_EXTERN(int) git_repository_head_detached(git_repository *repo); - -/** - * Check if a worktree's HEAD is detached - * - * A worktree's HEAD is detached when it points directly to a - * commit instead of a branch. - * - * @param repo a repository object - * @param name name of the worktree to retrieve HEAD for - * @return 1 if HEAD is detached, 0 if its not; error code if - * there was an error - */ -GIT_EXTERN(int) git_repository_head_detached_for_worktree(git_repository *repo, - const char *name); - -/** - * Check if the current branch is unborn - * - * An unborn branch is one named from HEAD but which doesn't exist in - * the refs namespace, because it doesn't have any commit to point to. - * - * @param repo Repo to test - * @return 1 if the current branch is unborn, 0 if it's not; error - * code if there was an error - */ -GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo); - -/** - * Check if a repository is empty - * - * An empty repository has just been initialized and contains no references - * apart from HEAD, which must be pointing to the unborn master branch, - * or the branch specified for the repository in the `init.defaultBranch` - * configuration variable. - * - * @param repo Repo to test - * @return 1 if the repository is empty, 0 if it isn't, error code - * if the repository is corrupted - */ -GIT_EXTERN(int) git_repository_is_empty(git_repository *repo); - -/** - * List of items which belong to the git repository layout - */ -typedef enum { - GIT_REPOSITORY_ITEM_GITDIR, - GIT_REPOSITORY_ITEM_WORKDIR, - GIT_REPOSITORY_ITEM_COMMONDIR, - GIT_REPOSITORY_ITEM_INDEX, - GIT_REPOSITORY_ITEM_OBJECTS, - GIT_REPOSITORY_ITEM_REFS, - GIT_REPOSITORY_ITEM_PACKED_REFS, - GIT_REPOSITORY_ITEM_REMOTES, - GIT_REPOSITORY_ITEM_CONFIG, - GIT_REPOSITORY_ITEM_INFO, - GIT_REPOSITORY_ITEM_HOOKS, - GIT_REPOSITORY_ITEM_LOGS, - GIT_REPOSITORY_ITEM_MODULES, - GIT_REPOSITORY_ITEM_WORKTREES, - GIT_REPOSITORY_ITEM_WORKTREE_CONFIG, - GIT_REPOSITORY_ITEM__LAST -} git_repository_item_t; - -/** - * Get the location of a specific repository file or directory - * - * This function will retrieve the path of a specific repository - * item. It will thereby honor things like the repository's - * common directory, gitdir, etc. In case a file path cannot - * exist for a given item (e.g. the working directory of a bare - * repository), GIT_ENOTFOUND is returned. - * - * @param out Buffer to store the path at - * @param repo Repository to get path for - * @param item The repository item for which to retrieve the path - * @return 0, GIT_ENOTFOUND if the path cannot exist or an error code - */ -GIT_EXTERN(int) git_repository_item_path(git_buf *out, const git_repository *repo, git_repository_item_t item); - -/** - * Get the path of this repository - * - * This is the path of the `.git` folder for normal repositories, - * or of the repository itself for bare repositories. - * - * @param repo A repository object - * @return the path to the repository - */ -GIT_EXTERN(const char *) git_repository_path(const git_repository *repo); - -/** - * Get the path of the working directory for this repository - * - * If the repository is bare, this function will always return - * NULL. - * - * @param repo A repository object - * @return the path to the working dir, if it exists - */ -GIT_EXTERN(const char *) git_repository_workdir(const git_repository *repo); - -/** - * Get the path of the shared common directory for this repository. - * - * If the repository is bare, it is the root directory for the repository. - * If the repository is a worktree, it is the parent repo's gitdir. - * Otherwise, it is the gitdir. - * - * @param repo A repository object - * @return the path to the common dir - */ -GIT_EXTERN(const char *) git_repository_commondir(const git_repository *repo); - -/** - * Set the path to the working directory for this repository - * - * The working directory doesn't need to be the same one - * that contains the `.git` folder for this repository. - * - * If this repository is bare, setting its working directory - * will turn it into a normal repository, capable of performing - * all the common workdir operations (checkout, status, index - * manipulation, etc). - * - * @param repo A repository object - * @param workdir The path to a working directory - * @param update_gitlink Create/update gitlink in workdir and set config - * "core.worktree" (if workdir is not the parent of the .git directory) - * @return 0, or an error code - */ -GIT_EXTERN(int) git_repository_set_workdir( - git_repository *repo, const char *workdir, int update_gitlink); - -/** - * Check if a repository is bare - * - * @param repo Repo to test - * @return 1 if the repository is bare, 0 otherwise. - */ -GIT_EXTERN(int) git_repository_is_bare(const git_repository *repo); - -/** - * Check if a repository is a linked work tree - * - * @param repo Repo to test - * @return 1 if the repository is a linked work tree, 0 otherwise. - */ -GIT_EXTERN(int) git_repository_is_worktree(const git_repository *repo); - -/** - * Get the configuration file for this repository. - * - * If a configuration file has not been set, the default - * config set for the repository will be returned, including - * global and system configurations (if they are available). - * - * The configuration file must be freed once it's no longer - * being used by the user. - * - * @param out Pointer to store the loaded configuration - * @param repo A repository object - * @return 0, or an error code - */ -GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo); - -/** - * Get a snapshot of the repository's configuration - * - * Convenience function to take a snapshot from the repository's - * configuration. The contents of this snapshot will not change, - * even if the underlying config files are modified. - * - * The configuration file must be freed once it's no longer - * being used by the user. - * - * @param out Pointer to store the loaded configuration - * @param repo the repository - * @return 0, or an error code - */ -GIT_EXTERN(int) git_repository_config_snapshot(git_config **out, git_repository *repo); - -/** - * Get the Object Database for this repository. - * - * If a custom ODB has not been set, the default - * database for the repository will be returned (the one - * located in `.git/objects`). - * - * The ODB must be freed once it's no longer being used by - * the user. - * - * @param[out] out Pointer to store the loaded ODB - * @param repo A repository object - * @return 0, or an error code - */ -GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo); - -/** - * Get the Reference Database Backend for this repository. - * - * If a custom refsdb has not been set, the default database for - * the repository will be returned (the one that manipulates loose - * and packed references in the `.git` directory). - * - * The refdb must be freed once it's no longer being used by - * the user. - * - * @param[out] out Pointer to store the loaded refdb - * @param repo A repository object - * @return 0, or an error code - */ -GIT_EXTERN(int) git_repository_refdb(git_refdb **out, git_repository *repo); - -/** - * Get the Index file for this repository. - * - * If a custom index has not been set, the default - * index for the repository will be returned (the one - * located in `.git/index`). - * - * The index must be freed once it's no longer being used by - * the user. - * - * @param[out] out Pointer to store the loaded index - * @param repo A repository object - * @return 0, or an error code - */ -GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo); - -/** - * Retrieve git's prepared message - * - * Operations such as git revert/cherry-pick/merge with the -n option - * stop just short of creating a commit with the changes and save - * their prepared message in .git/MERGE_MSG so the next git-commit - * execution can present it to the user for them to amend if they - * wish. - * - * Use this function to get the contents of this file. Don't forget to - * remove the file after you create the commit. - * - * @param out git_buf to write data into - * @param repo Repository to read prepared message from - * @return 0, GIT_ENOTFOUND if no message exists or an error code - */ -GIT_EXTERN(int) git_repository_message(git_buf *out, git_repository *repo); - -/** - * Remove git's prepared message. - * - * Remove the message that `git_repository_message` retrieves. - * - * @param repo Repository to remove prepared message from. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_repository_message_remove(git_repository *repo); - -/** - * Remove all the metadata associated with an ongoing command like merge, - * revert, cherry-pick, etc. For example: MERGE_HEAD, MERGE_MSG, etc. - * - * @param repo A repository object - * @return 0 on success, or error - */ -GIT_EXTERN(int) git_repository_state_cleanup(git_repository *repo); - -/** - * Callback used to iterate over each FETCH_HEAD entry - * - * @see git_repository_fetchhead_foreach - * - * @param ref_name The reference name - * @param remote_url The remote URL - * @param oid The reference target OID - * @param is_merge Was the reference the result of a merge - * @param payload Payload passed to git_repository_fetchhead_foreach - * @return non-zero to terminate the iteration - */ -typedef int GIT_CALLBACK(git_repository_fetchhead_foreach_cb)(const char *ref_name, - const char *remote_url, - const git_oid *oid, - unsigned int is_merge, - void *payload); - -/** - * Invoke 'callback' for each entry in the given FETCH_HEAD file. - * - * Return a non-zero value from the callback to stop the loop. - * - * @param repo A repository object - * @param callback Callback function - * @param payload Pointer to callback data (optional) - * @return 0 on success, non-zero callback return value, GIT_ENOTFOUND if - * there is no FETCH_HEAD file, or other error code. - */ -GIT_EXTERN(int) git_repository_fetchhead_foreach( - git_repository *repo, - git_repository_fetchhead_foreach_cb callback, - void *payload); - -/** - * Callback used to iterate over each MERGE_HEAD entry - * - * @see git_repository_mergehead_foreach - * - * @param oid The merge OID - * @param payload Payload passed to git_repository_mergehead_foreach - * @return non-zero to terminate the iteration - */ -typedef int GIT_CALLBACK(git_repository_mergehead_foreach_cb)(const git_oid *oid, - void *payload); - -/** - * If a merge is in progress, invoke 'callback' for each commit ID in the - * MERGE_HEAD file. - * - * Return a non-zero value from the callback to stop the loop. - * - * @param repo A repository object - * @param callback Callback function - * @param payload Pointer to callback data (optional) - * @return 0 on success, non-zero callback return value, GIT_ENOTFOUND if - * there is no MERGE_HEAD file, or other error code. - */ -GIT_EXTERN(int) git_repository_mergehead_foreach( - git_repository *repo, - git_repository_mergehead_foreach_cb callback, - void *payload); - -/** - * Calculate hash of file using repository filtering rules. - * - * If you simply want to calculate the hash of a file on disk with no filters, - * you can just use the `git_odb_hashfile()` API. However, if you want to - * hash a file in the repository and you want to apply filtering rules (e.g. - * crlf filters) before generating the SHA, then use this function. - * - * Note: if the repository has `core.safecrlf` set to fail and the - * filtering triggers that failure, then this function will return an - * error and not calculate the hash of the file. - * - * @param out Output value of calculated SHA - * @param repo Repository pointer - * @param path Path to file on disk whose contents should be hashed. This - * may be an absolute path or a relative path, in which case it - * will be treated as a path within the working directory. - * @param type The object type to hash as (e.g. GIT_OBJECT_BLOB) - * @param as_path The path to use to look up filtering rules. If this is - * an empty string then no filters will be applied when - * calculating the hash. If this is `NULL` and the `path` - * parameter is a file within the repository's working - * directory, then the `path` will be used. - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_hashfile( - git_oid *out, - git_repository *repo, - const char *path, - git_object_t type, - const char *as_path); - -/** - * Make the repository HEAD point to the specified reference. - * - * If the provided reference points to a Tree or a Blob, the HEAD is - * unaltered and -1 is returned. - * - * If the provided reference points to a branch, the HEAD will point - * to that branch, staying attached, or become attached if it isn't yet. - * If the branch doesn't exist yet, no error will be return. The HEAD - * will then be attached to an unborn branch. - * - * Otherwise, the HEAD will be detached and will directly point to - * the Commit. - * - * @param repo Repository pointer - * @param refname Canonical name of the reference the HEAD should point at - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_set_head( - git_repository *repo, - const char *refname); - -/** - * Make the repository HEAD directly point to the Commit. - * - * If the provided committish cannot be found in the repository, the HEAD - * is unaltered and GIT_ENOTFOUND is returned. - * - * If the provided committish cannot be peeled into a commit, the HEAD - * is unaltered and -1 is returned. - * - * Otherwise, the HEAD will eventually be detached and will directly point to - * the peeled Commit. - * - * @param repo Repository pointer - * @param committish Object id of the Commit the HEAD should point to - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_set_head_detached( - git_repository *repo, - const git_oid *committish); - -/** - * Make the repository HEAD directly point to the Commit. - * - * This behaves like `git_repository_set_head_detached()` but takes an - * annotated commit, which lets you specify which extended sha syntax - * string was specified by a user, allowing for more exact reflog - * messages. - * - * See the documentation for `git_repository_set_head_detached()`. - * - * @param repo Repository pointer - * @param committish annotated commit to point HEAD to - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_set_head_detached_from_annotated( - git_repository *repo, - const git_annotated_commit *committish); - -/** - * Detach the HEAD. - * - * If the HEAD is already detached and points to a Commit, 0 is returned. - * - * If the HEAD is already detached and points to a Tag, the HEAD is - * updated into making it point to the peeled Commit, and 0 is returned. - * - * If the HEAD is already detached and points to a non committish, the HEAD is - * unaltered, and -1 is returned. - * - * Otherwise, the HEAD will be detached and point to the peeled Commit. - * - * @param repo Repository pointer - * @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing - * branch or an error code - */ -GIT_EXTERN(int) git_repository_detach_head( - git_repository *repo); - -/** - * Repository state - * - * These values represent possible states for the repository to be in, - * based on the current operation which is ongoing. - */ -typedef enum { - GIT_REPOSITORY_STATE_NONE, - GIT_REPOSITORY_STATE_MERGE, - GIT_REPOSITORY_STATE_REVERT, - GIT_REPOSITORY_STATE_REVERT_SEQUENCE, - GIT_REPOSITORY_STATE_CHERRYPICK, - GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE, - GIT_REPOSITORY_STATE_BISECT, - GIT_REPOSITORY_STATE_REBASE, - GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, - GIT_REPOSITORY_STATE_REBASE_MERGE, - GIT_REPOSITORY_STATE_APPLY_MAILBOX, - GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE -} git_repository_state_t; - -/** - * Determines the status of a git repository - ie, whether an operation - * (merge, cherry-pick, etc) is in progress. - * - * @param repo Repository pointer - * @return The state of the repository - */ -GIT_EXTERN(int) git_repository_state(git_repository *repo); - -/** - * Sets the active namespace for this Git Repository - * - * This namespace affects all reference operations for the repo. - * See `man gitnamespaces` - * - * @param repo The repo - * @param nmspace The namespace. This should not include the refs - * folder, e.g. to namespace all references under `refs/namespaces/foo/`, - * use `foo` as the namespace. - * @return 0 on success, -1 on error - */ -GIT_EXTERN(int) git_repository_set_namespace(git_repository *repo, const char *nmspace); - -/** - * Get the currently active namespace for this repository - * - * @param repo The repo - * @return the active namespace, or NULL if there isn't one - */ -GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo); - - -/** - * Determine if the repository was a shallow clone - * - * @param repo The repository - * @return 1 if shallow, zero if not - */ -GIT_EXTERN(int) git_repository_is_shallow(git_repository *repo); - -/** - * Retrieve the configured identity to use for reflogs - * - * The memory is owned by the repository and must not be freed by the - * user. - * - * @param[out] name where to store the pointer to the name - * @param[out] email where to store the pointer to the email - * @param repo the repository - * @return 0 or an error code - */ -GIT_EXTERN(int) git_repository_ident(const char **name, const char **email, const git_repository *repo); - -/** - * Set the identity to be used for writing reflogs - * - * If both are set, this name and email will be used to write to the - * reflog. Pass NULL to unset. When unset, the identity will be taken - * from the repository's configuration. - * - * @param repo the repository to configure - * @param name the name to use for the reflog entries - * @param email the email to use for the reflog entries - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_repository_set_ident(git_repository *repo, const char *name, const char *email); - -/** - * Gets the object type used by this repository. - * - * @param repo the repository - * @return the object id type - */ -GIT_EXTERN(git_oid_t) git_repository_oid_type(git_repository *repo); - -/** - * Gets the parents of the next commit, given the current repository state. - * Generally, this is the HEAD commit, except when performing a merge, in - * which case it is two or more commits. - * - * @param commits a `git_commitarray` that will contain the commit parents - * @param repo the repository - * @return 0 or an error code - */ -GIT_EXTERN(int) git_repository_commit_parents(git_commitarray *commits, git_repository *repo); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/reset.h b/vendor/libgit2-sys/libgit2/include/git2/reset.h deleted file mode 100644 index 0123f7c..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/reset.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_reset_h__ -#define INCLUDE_git_reset_h__ - -#include "common.h" -#include "types.h" -#include "strarray.h" -#include "checkout.h" - -/** - * @file git2/reset.h - * @brief Reset will update the local repository to a prior state - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Kinds of reset operation - */ -typedef enum { - GIT_RESET_SOFT = 1, /**< Move the head to the given commit */ - GIT_RESET_MIXED = 2, /**< SOFT plus reset index to the commit */ - GIT_RESET_HARD = 3 /**< MIXED plus changes in working tree discarded */ -} git_reset_t; - -/** - * Sets the current head to the specified commit oid and optionally - * resets the index and working tree to match. - * - * SOFT reset means the Head will be moved to the commit. - * - * MIXED reset will trigger a SOFT reset, plus the index will be replaced - * with the content of the commit tree. - * - * HARD reset will trigger a MIXED reset and the working directory will be - * replaced with the content of the index. (Untracked and ignored files - * will be left alone, however.) - * - * TODO: Implement remaining kinds of resets. - * - * @param repo Repository where to perform the reset operation. - * - * @param target Committish to which the Head should be moved to. This object - * must belong to the given `repo` and can either be a git_commit or a - * git_tag. When a git_tag is being passed, it should be dereferenceable - * to a git_commit which oid will be used as the target of the branch. - * - * @param reset_type Kind of reset operation to perform. - * - * @param checkout_opts Optional checkout options to be used for a HARD reset. - * The checkout_strategy field will be overridden (based on reset_type). - * This parameter can be used to propagate notify and progress callbacks. - * - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_reset( - git_repository *repo, - const git_object *target, - git_reset_t reset_type, - const git_checkout_options *checkout_opts); - -/** - * Sets the current head to the specified commit oid and optionally - * resets the index and working tree to match. - * - * This behaves like `git_reset()` but takes an annotated commit, - * which lets you specify which extended sha syntax string was - * specified by a user, allowing for more exact reflog messages. - * - * See the documentation for `git_reset()`. - * - * @param repo Repository where to perform the reset operation. - * - * @param target Annotated commit to which the Head should be moved to. - * This object must belong to the given `repo`, it will be dereferenced - * to a git_commit which oid will be used as the target of the branch. - * - * @param reset_type Kind of reset operation to perform. - * - * @param checkout_opts Optional checkout options to be used for a HARD reset. - * The checkout_strategy field will be overridden (based on reset_type). - * This parameter can be used to propagate notify and progress callbacks. - * - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_reset_from_annotated( - git_repository *repo, - const git_annotated_commit *target, - git_reset_t reset_type, - const git_checkout_options *checkout_opts); - -/** - * Updates some entries in the index from the target commit tree. - * - * The scope of the updated entries is determined by the paths - * being passed in the `pathspec` parameters. - * - * Passing a NULL `target` will result in removing - * entries in the index matching the provided pathspecs. - * - * @param repo Repository where to perform the reset operation. - * - * @param target The committish which content will be used to reset the content - * of the index. - * - * @param pathspecs List of pathspecs to operate on. - * - * @return 0 on success or an error code < 0 - */ -GIT_EXTERN(int) git_reset_default( - git_repository *repo, - const git_object *target, - const git_strarray* pathspecs); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/revert.h b/vendor/libgit2-sys/libgit2/include/git2/revert.h deleted file mode 100644 index ec51eca..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/revert.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_revert_h__ -#define INCLUDE_git_revert_h__ - -#include "common.h" -#include "types.h" -#include "merge.h" - -/** - * @file git2/revert.h - * @brief Cherry-pick the inverse of a change to "undo" its effects - * @defgroup git_revert Cherry-pick the inverse of a change to "undo" its effects - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Options for revert - */ -typedef struct { - unsigned int version; - - /** For merge commits, the "mainline" is treated as the parent. */ - unsigned int mainline; - - git_merge_options merge_opts; /**< Options for the merging */ - git_checkout_options checkout_opts; /**< Options for the checkout */ -} git_revert_options; - -/** Current version for the `git_revert_options` structure */ -#define GIT_REVERT_OPTIONS_VERSION 1 - -/** Static constructor for `git_revert_options` */ -#define GIT_REVERT_OPTIONS_INIT { \ - GIT_REVERT_OPTIONS_VERSION, 0, \ - GIT_MERGE_OPTIONS_INIT, GIT_CHECKOUT_OPTIONS_INIT } - -/** - * Initialize git_revert_options structure - * - * Initializes a `git_revert_options` with default values. Equivalent to - * creating an instance with `GIT_REVERT_OPTIONS_INIT`. - * - * @param opts The `git_revert_options` struct to initialize. - * @param version The struct version; pass `GIT_REVERT_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_revert_options_init( - git_revert_options *opts, - unsigned int version); - -/** - * Reverts the given commit against the given "our" commit, producing an - * index that reflects the result of the revert. - * - * The returned index must be freed explicitly with `git_index_free`. - * - * @param out pointer to store the index result in - * @param repo the repository that contains the given commits - * @param revert_commit the commit to revert - * @param our_commit the commit to revert against (eg, HEAD) - * @param mainline the parent of the revert commit, if it is a merge - * @param merge_options the merge options (or null for defaults) - * @return zero on success, -1 on failure. - */ -GIT_EXTERN(int) git_revert_commit( - git_index **out, - git_repository *repo, - git_commit *revert_commit, - git_commit *our_commit, - unsigned int mainline, - const git_merge_options *merge_options); - -/** - * Reverts the given commit, producing changes in the index and working directory. - * - * @param repo the repository to revert - * @param commit the commit to revert - * @param given_opts the revert options (or null for defaults) - * @return zero on success, -1 on failure. - */ -GIT_EXTERN(int) git_revert( - git_repository *repo, - git_commit *commit, - const git_revert_options *given_opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/revparse.h b/vendor/libgit2-sys/libgit2/include/git2/revparse.h deleted file mode 100644 index c14fe3d..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/revparse.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_revparse_h__ -#define INCLUDE_git_revparse_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/revparse.h - * @brief Parse the textual revision information - * @defgroup git_revparse Parse the textual revision information - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Find a single object, as specified by a revision string. - * - * See `man gitrevisions`, or - * http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for - * information on the syntax accepted. - * - * The returned object should be released with `git_object_free` when no - * longer needed. - * - * @param out pointer to output object - * @param repo the repository to search in - * @param spec the textual specification for an object - * @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS, GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_revparse_single( - git_object **out, git_repository *repo, const char *spec); - -/** - * Find a single object and intermediate reference by a revision string. - * - * See `man gitrevisions`, or - * http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for - * information on the syntax accepted. - * - * In some cases (`@{<-n>}` or `@{upstream}`), the expression may - * point to an intermediate reference. When such expressions are being passed - * in, `reference_out` will be valued as well. - * - * The returned object should be released with `git_object_free` and the - * returned reference with `git_reference_free` when no longer needed. - * - * @param object_out pointer to output object - * @param reference_out pointer to output reference or NULL - * @param repo the repository to search in - * @param spec the textual specification for an object - * @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS, GIT_EINVALIDSPEC - * or an error code - */ -GIT_EXTERN(int) git_revparse_ext( - git_object **object_out, - git_reference **reference_out, - git_repository *repo, - const char *spec); - -/** - * Revparse flags. These indicate the intended behavior of the spec passed to - * git_revparse. - */ -typedef enum { - /** The spec targeted a single object. */ - GIT_REVSPEC_SINGLE = 1 << 0, - /** The spec targeted a range of commits. */ - GIT_REVSPEC_RANGE = 1 << 1, - /** The spec used the '...' operator, which invokes special semantics. */ - GIT_REVSPEC_MERGE_BASE = 1 << 2 -} git_revspec_t; - -/** - * Git Revision Spec: output of a `git_revparse` operation - */ -typedef struct { - /** The left element of the revspec; must be freed by the user */ - git_object *from; - /** The right element of the revspec; must be freed by the user */ - git_object *to; - /** The intent of the revspec (i.e. `git_revspec_mode_t` flags) */ - unsigned int flags; -} git_revspec; - -/** - * Parse a revision string for `from`, `to`, and intent. - * - * See `man gitrevisions` or - * http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for - * information on the syntax accepted. - * - * @param revspec Pointer to an user-allocated git_revspec struct where - * the result of the rev-parse will be stored - * @param repo the repository to search in - * @param spec the rev-parse spec to parse - * @return 0 on success, GIT_INVALIDSPEC, GIT_ENOTFOUND, GIT_EAMBIGUOUS or an error code - */ -GIT_EXTERN(int) git_revparse( - git_revspec *revspec, - git_repository *repo, - const char *spec); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/revwalk.h b/vendor/libgit2-sys/libgit2/include/git2/revwalk.h deleted file mode 100644 index 7c4ac54..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/revwalk.h +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_revwalk_h__ -#define INCLUDE_git_revwalk_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/revwalk.h - * @brief Traverse (walk) the commit graph (revision history) - * @defgroup git_revwalk Traverse (walk) the commit graph (revision history) - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Flags to specify the sorting which a revwalk should perform. - */ -typedef enum { - /** - * Sort the output with the same default method from `git`: reverse - * chronological order. This is the default sorting for new walkers. - */ - GIT_SORT_NONE = 0, - - /** - * Sort the repository contents in topological order (no parents before - * all of its children are shown); this sorting mode can be combined - * with time sorting to produce `git`'s `--date-order``. - */ - GIT_SORT_TOPOLOGICAL = 1 << 0, - - /** - * Sort the repository contents by commit time; - * this sorting mode can be combined with - * topological sorting. - */ - GIT_SORT_TIME = 1 << 1, - - /** - * Iterate through the repository contents in reverse - * order; this sorting mode can be combined with - * any of the above. - */ - GIT_SORT_REVERSE = 1 << 2 -} git_sort_t; - -/** - * Allocate a new revision walker to iterate through a repo. - * - * This revision walker uses a custom memory pool and an internal - * commit cache, so it is relatively expensive to allocate. - * - * For maximum performance, this revision walker should be - * reused for different walks. - * - * This revision walker is *not* thread safe: it may only be - * used to walk a repository on a single thread; however, - * it is possible to have several revision walkers in - * several different threads walking the same repository. - * - * @param out pointer to the new revision walker - * @param repo the repo to walk through - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_new(git_revwalk **out, git_repository *repo); - -/** - * Reset the revision walker for reuse. - * - * This will clear all the pushed and hidden commits, and - * leave the walker in a blank state (just like at - * creation) ready to receive new commit pushes and - * start a new walk. - * - * The revision walk is automatically reset when a walk - * is over. - * - * @param walker handle to reset. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_reset(git_revwalk *walker); - -/** - * Add a new root for the traversal - * - * The pushed commit will be marked as one of the roots from which to - * start the walk. This commit may not be walked if it or a child is - * hidden. - * - * At least one commit must be pushed onto the walker before a walk - * can be started. - * - * The given id must belong to a committish on the walked - * repository. - * - * @param walk the walker being used for the traversal. - * @param id the oid of the commit to start from. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *id); - -/** - * Push matching references - * - * The OIDs pointed to by the references that match the given glob - * pattern will be pushed to the revision walker. - * - * A leading 'refs/' is implied if not present as well as a trailing - * '/\*' if the glob lacks '?', '\*' or '['. - * - * Any references matching this glob which do not point to a - * committish will be ignored. - * - * @param walk the walker being used for the traversal - * @param glob the glob pattern references should match - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_push_glob(git_revwalk *walk, const char *glob); - -/** - * Push the repository's HEAD - * - * @param walk the walker being used for the traversal - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk); - -/** - * Mark a commit (and its ancestors) uninteresting for the output. - * - * The given id must belong to a committish on the walked - * repository. - * - * The resolved commit and all its parents will be hidden from the - * output on the revision walk. - * - * @param walk the walker being used for the traversal. - * @param commit_id the oid of commit that will be ignored during the traversal - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *commit_id); - -/** - * Hide matching references. - * - * The OIDs pointed to by the references that match the given glob - * pattern and their ancestors will be hidden from the output on the - * revision walk. - * - * A leading 'refs/' is implied if not present as well as a trailing - * '/\*' if the glob lacks '?', '\*' or '['. - * - * Any references matching this glob which do not point to a - * committish will be ignored. - * - * @param walk the walker being used for the traversal - * @param glob the glob pattern references should match - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob); - -/** - * Hide the repository's HEAD - * - * @param walk the walker being used for the traversal - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk); - -/** - * Push the OID pointed to by a reference - * - * The reference must point to a committish. - * - * @param walk the walker being used for the traversal - * @param refname the reference to push - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_push_ref(git_revwalk *walk, const char *refname); - -/** - * Hide the OID pointed to by a reference - * - * The reference must point to a committish. - * - * @param walk the walker being used for the traversal - * @param refname the reference to hide - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname); - -/** - * Get the next commit from the revision walk. - * - * The initial call to this method is *not* blocking when - * iterating through a repo with a time-sorting mode. - * - * Iterating with Topological or inverted modes makes the initial - * call blocking to preprocess the commit list, but this block should be - * mostly unnoticeable on most repositories (topological preprocessing - * times at 0.3s on the git.git repo). - * - * The revision walker is reset when the walk is over. - * - * @param out Pointer where to store the oid of the next commit - * @param walk the walker to pop the commit from. - * @return 0 if the next commit was found; - * GIT_ITEROVER if there are no commits left to iterate - */ -GIT_EXTERN(int) git_revwalk_next(git_oid *out, git_revwalk *walk); - -/** - * Change the sorting mode when iterating through the - * repository's contents. - * - * Changing the sorting mode resets the walker. - * - * @param walk the walker being used for the traversal. - * @param sort_mode combination of GIT_SORT_XXX flags - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); - -/** - * Push and hide the respective endpoints of the given range. - * - * The range should be of the form - * .. - * where each is in the form accepted by 'git_revparse_single'. - * The left-hand commit will be hidden and the right-hand commit pushed. - * - * @param walk the walker being used for the traversal - * @param range the range - * @return 0 or an error code - * - */ -GIT_EXTERN(int) git_revwalk_push_range(git_revwalk *walk, const char *range); - -/** - * Simplify the history by first-parent - * - * No parents other than the first for each commit will be enqueued. - * - * @param walk The revision walker. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_revwalk_simplify_first_parent(git_revwalk *walk); - - -/** - * Free a revision walker previously allocated. - * - * @param walk traversal handle to close. If NULL nothing occurs. - */ -GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk); - -/** - * Return the repository on which this walker - * is operating. - * - * @param walk the revision walker - * @return the repository being walked - */ -GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk); - -/** - * This is a callback function that user can provide to hide a - * commit and its parents. If the callback function returns non-zero value, - * then this commit and its parents will be hidden. - * - * @param commit_id oid of Commit - * @param payload User-specified pointer to data to be passed as data payload - * @return non-zero to hide the commmit and it parent. - */ -typedef int GIT_CALLBACK(git_revwalk_hide_cb)( - const git_oid *commit_id, - void *payload); - -/** - * Adds, changes or removes a callback function to hide a commit and its parents - * - * @param walk the revision walker - * @param hide_cb callback function to hide a commit and its parents - * @param payload data payload to be passed to callback function - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_revwalk_add_hide_cb( - git_revwalk *walk, - git_revwalk_hide_cb hide_cb, - void *payload); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/signature.h b/vendor/libgit2-sys/libgit2/include/git2/signature.h deleted file mode 100644 index 20ec24b..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/signature.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_signature_h__ -#define INCLUDE_git_signature_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/signature.h - * @brief Signatures are the actor in a repository and when they acted - * @defgroup git_signature Git signature creation - * @ingroup Git - * - * Signatures contain the information about the actor (committer or - * author) in a repository, and the time that they performed the - * commit, or authoring. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create a new action signature. - * - * Call `git_signature_free()` to free the data. - * - * Note: angle brackets ('<' and '>') characters are not allowed - * to be used in either the `name` or the `email` parameter. - * - * @param out new signature, in case of error NULL - * @param name name of the person - * @param email email of the person - * @param time time (in seconds from epoch) when the action happened - * @param offset timezone offset (in minutes) for the time - * @return 0 or an error code - */ -GIT_EXTERN(int) git_signature_new(git_signature **out, const char *name, const char *email, git_time_t time, int offset); - -/** - * Create a new action signature with a timestamp of 'now'. - * - * Call `git_signature_free()` to free the data. - * - * @param out new signature, in case of error NULL - * @param name name of the person - * @param email email of the person - * @return 0 or an error code - */ -GIT_EXTERN(int) git_signature_now(git_signature **out, const char *name, const char *email); - -/** - * Create a new author and/or committer signatures with default - * information based on the configuration and environment variables. - * - * If `author_out` is set, it will be populated with the author - * information. The `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL` - * environment variables will be honored, and `user.name` and - * `user.email` configuration options will be honored if the - * environment variables are unset. For timestamps, `GIT_AUTHOR_DATE` - * will be used, otherwise the current time will be used. - * - * If `committer_out` is set, it will be populated with the - * committer information. The `GIT_COMMITTER_NAME` and - * `GIT_COMMITTER_EMAIL` environment variables will be honored, - * and `user.name` and `user.email` configuration options will - * be honored if the environment variables are unset. For timestamps, - * `GIT_COMMITTER_DATE` will be used, otherwise the current time will - * be used. - * - * If neither `GIT_AUTHOR_DATE` nor `GIT_COMMITTER_DATE` are set, - * both timestamps will be set to the same time. - * - * It will return `GIT_ENOTFOUND` if either the `user.name` or - * `user.email` are not set and there is no fallback from an environment - * variable. One of `author_out` or `committer_out` must be set. - * - * @param author_out pointer to set the author signature, or NULL - * @param committer_out pointer to set the committer signature, or NULL - * @param repo repository pointer - * @return 0 on success, GIT_ENOTFOUND if config is missing, or error code - */ -GIT_EXTERN(int) git_signature_default_from_env( - git_signature **author_out, - git_signature **committer_out, - git_repository *repo); - -/** - * Create a new action signature with default user and now timestamp. - * - * This looks up the user.name and user.email from the configuration and - * uses the current time as the timestamp, and creates a new signature - * based on that information. It will return GIT_ENOTFOUND if either the - * user.name or user.email are not set. - * - * Note that these do not examine environment variables, only the - * configuration files. Use `git_signature_default_from_env` to - * consider the environment variables. - * - * @param out new signature - * @param repo repository pointer - * @return 0 on success, GIT_ENOTFOUND if config is missing, or error code - */ -GIT_EXTERN(int) git_signature_default(git_signature **out, git_repository *repo); - -/** - * Create a new signature by parsing the given buffer, which is - * expected to be in the format "Real Name timestamp tzoffset", - * where `timestamp` is the number of seconds since the Unix epoch and - * `tzoffset` is the timezone offset in `hhmm` format (note the lack - * of a colon separator). - * - * @param out new signature - * @param buf signature string - * @return 0 on success, GIT_EINVALID if the signature is not parseable, or an error code - */ -GIT_EXTERN(int) git_signature_from_buffer(git_signature **out, const char *buf); - -/** - * Create a copy of an existing signature. All internal strings are also - * duplicated. - * - * Call `git_signature_free()` to free the data. - * - * @param dest pointer where to store the copy - * @param sig signature to duplicate - * @return 0 or an error code - */ -GIT_EXTERN(int) git_signature_dup(git_signature **dest, const git_signature *sig); - -/** - * Free an existing signature. - * - * Because the signature is not an opaque structure, it is legal to free it - * manually, but be sure to free the "name" and "email" strings in addition - * to the structure itself. - * - * @param sig signature to free - */ -GIT_EXTERN(void) git_signature_free(git_signature *sig); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/stash.h b/vendor/libgit2-sys/libgit2/include/git2/stash.h deleted file mode 100644 index ad28c32..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/stash.h +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_stash_h__ -#define INCLUDE_git_stash_h__ - -#include "common.h" -#include "types.h" -#include "checkout.h" - -/** - * @file git2/stash.h - * @brief Stashes stores some uncommitted state in the repository - * @ingroup Git - * - * Stashes stores some uncommitted state in the repository; generally - * this allows a user to stash some changes so that they can restore - * the working directory to an unmodified state. This can allow a - * developer to work on two different changes in parallel. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Stash flags - */ -typedef enum { - /** - * No option, default - */ - GIT_STASH_DEFAULT = 0, - - /** - * All changes already added to the index are left intact in - * the working directory - */ - GIT_STASH_KEEP_INDEX = (1 << 0), - - /** - * All untracked files are also stashed and then cleaned up - * from the working directory - */ - GIT_STASH_INCLUDE_UNTRACKED = (1 << 1), - - /** - * All ignored files are also stashed and then cleaned up from - * the working directory - */ - GIT_STASH_INCLUDE_IGNORED = (1 << 2), - - /** - * All changes in the index and working directory are left intact - */ - GIT_STASH_KEEP_ALL = (1 << 3) -} git_stash_flags; - -/** - * Save the local modifications to a new stash. - * - * @param out Object id of the commit containing the stashed state. - * This commit is also the target of the direct reference refs/stash. - * @param repo The owning repository. - * @param stasher The identity of the person performing the stashing. - * @param message Optional description along with the stashed state. - * @param flags Flags to control the stashing process. (see GIT_STASH_* above) - * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash, - * or error code. - */ -GIT_EXTERN(int) git_stash_save( - git_oid *out, - git_repository *repo, - const git_signature *stasher, - const char *message, - uint32_t flags); - -/** - * Stash save options structure - * - * Initialize with `GIT_STASH_SAVE_OPTIONS_INIT`. Alternatively, you can - * use `git_stash_save_options_init`. - * - */ -typedef struct git_stash_save_options { - unsigned int version; - - /** Flags to control the stashing process. (see GIT_STASH_* above) */ - uint32_t flags; - - /** The identity of the person performing the stashing. */ - const git_signature *stasher; - - /** Optional description along with the stashed state. */ - const char *message; - - /** Optional paths that control which files are stashed. */ - git_strarray paths; -} git_stash_save_options; - -/** Current version for the `git_stash_save_options` structure */ -#define GIT_STASH_SAVE_OPTIONS_VERSION 1 - -/** Static constructor for `git_stash_save_options` */ -#define GIT_STASH_SAVE_OPTIONS_INIT { GIT_STASH_SAVE_OPTIONS_VERSION } - -/** - * Initialize git_stash_save_options structure - * - * Initializes a `git_stash_save_options` with default values. Equivalent to - * creating an instance with `GIT_STASH_SAVE_OPTIONS_INIT`. - * - * @param opts The `git_stash_save_options` struct to initialize. - * @param version The struct version; pass `GIT_STASH_SAVE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_stash_save_options_init( - git_stash_save_options *opts, unsigned int version); - -/** - * Save the local modifications to a new stash, with options. - * - * @param out Object id of the commit containing the stashed state. - * This commit is also the target of the direct reference refs/stash. - * @param repo The owning repository. - * @param opts The stash options. - * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash, - * or error code. - */ -GIT_EXTERN(int) git_stash_save_with_opts( - git_oid *out, - git_repository *repo, - const git_stash_save_options *opts); - -/** Stash application flags. */ -typedef enum { - GIT_STASH_APPLY_DEFAULT = 0, - - /* Try to reinstate not only the working tree's changes, - * but also the index's changes. - */ - GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0) -} git_stash_apply_flags; - -/** Stash apply progression states */ -typedef enum { - GIT_STASH_APPLY_PROGRESS_NONE = 0, - - /** Loading the stashed data from the object database. */ - GIT_STASH_APPLY_PROGRESS_LOADING_STASH, - - /** The stored index is being analyzed. */ - GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX, - - /** The modified files are being analyzed. */ - GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED, - - /** The untracked and ignored files are being analyzed. */ - GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED, - - /** The untracked files are being written to disk. */ - GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED, - - /** The modified files are being written to disk. */ - GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED, - - /** The stash was applied successfully. */ - GIT_STASH_APPLY_PROGRESS_DONE -} git_stash_apply_progress_t; - -/** - * Stash application progress notification function. - * Return 0 to continue processing, or a negative value to - * abort the stash application. - * - * @param progress the progress information - * @param payload the user-specified payload to the apply function - * @return 0 on success, -1 on error - */ -typedef int GIT_CALLBACK(git_stash_apply_progress_cb)( - git_stash_apply_progress_t progress, - void *payload); - -/** - * Stash application options structure - * - * Initialize with `GIT_STASH_APPLY_OPTIONS_INIT`. Alternatively, you can - * use `git_stash_apply_options_init`. - * - */ -typedef struct git_stash_apply_options { - unsigned int version; - - /** See `git_stash_apply_flags`, above. */ - uint32_t flags; - - /** Options to use when writing files to the working directory. */ - git_checkout_options checkout_options; - - /** Optional callback to notify the consumer of application progress. */ - git_stash_apply_progress_cb progress_cb; - void *progress_payload; -} git_stash_apply_options; - -/** Current version for the `git_stash_apply_options` structure */ -#define GIT_STASH_APPLY_OPTIONS_VERSION 1 - -/** Static constructor for `git_stash_apply_options` */ -#define GIT_STASH_APPLY_OPTIONS_INIT { \ - GIT_STASH_APPLY_OPTIONS_VERSION, \ - GIT_STASH_APPLY_DEFAULT, \ - GIT_CHECKOUT_OPTIONS_INIT } - -/** - * Initialize git_stash_apply_options structure - * - * Initializes a `git_stash_apply_options` with default values. Equivalent to - * creating an instance with `GIT_STASH_APPLY_OPTIONS_INIT`. - * - * @param opts The `git_stash_apply_options` struct to initialize. - * @param version The struct version; pass `GIT_STASH_APPLY_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_stash_apply_options_init( - git_stash_apply_options *opts, unsigned int version); - -/** - * Apply a single stashed state from the stash list. - * - * If local changes in the working directory conflict with changes in the - * stash then GIT_EMERGECONFLICT will be returned. In this case, the index - * will always remain unmodified and all files in the working directory will - * remain unmodified. However, if you are restoring untracked files or - * ignored files and there is a conflict when applying the modified files, - * then those files will remain in the working directory. - * - * If passing the GIT_STASH_APPLY_REINSTATE_INDEX flag and there would be - * conflicts when reinstating the index, the function will return - * GIT_EMERGECONFLICT and both the working directory and index will be left - * unmodified. - * - * @param repo The owning repository. - * @param index The position within the stash list. 0 points to the - * most recent stashed state. - * @param options Optional options to control how stashes are applied. - * - * @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the - * given index, GIT_EMERGECONFLICT if changes exist in the working - * directory, or an error code - */ -GIT_EXTERN(int) git_stash_apply( - git_repository *repo, - size_t index, - const git_stash_apply_options *options); - -/** - * This is a callback function you can provide to iterate over all the - * stashed states that will be invoked per entry. - * - * @param index The position within the stash list. 0 points to the - * most recent stashed state. - * @param message The stash message. - * @param stash_id The commit oid of the stashed state. - * @param payload Extra parameter to callback function. - * @return 0 to continue iterating or non-zero to stop. - */ -typedef int GIT_CALLBACK(git_stash_cb)( - size_t index, - const char *message, - const git_oid *stash_id, - void *payload); - -/** - * Loop over all the stashed states and issue a callback for each one. - * - * If the callback returns a non-zero value, this will stop looping. - * - * @param repo Repository where to find the stash. - * - * @param callback Callback to invoke per found stashed state. The most - * recent stash state will be enumerated first. - * - * @param payload Extra parameter to callback function. - * - * @return 0 on success, non-zero callback return value, or error code. - */ -GIT_EXTERN(int) git_stash_foreach( - git_repository *repo, - git_stash_cb callback, - void *payload); - -/** - * Remove a single stashed state from the stash list. - * - * @param repo The owning repository. - * - * @param index The position within the stash list. 0 points to the - * most recent stashed state. - * - * @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given - * index, or error code. - */ -GIT_EXTERN(int) git_stash_drop( - git_repository *repo, - size_t index); - -/** - * Apply a single stashed state from the stash list and remove it from the list - * if successful. - * - * @param repo The owning repository. - * @param index The position within the stash list. 0 points to the - * most recent stashed state. - * @param options Optional options to control how stashes are applied. - * - * @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given - * index, or error code. (see git_stash_apply() above for details) -*/ -GIT_EXTERN(int) git_stash_pop( - git_repository *repo, - size_t index, - const git_stash_apply_options *options); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/status.h b/vendor/libgit2-sys/libgit2/include/git2/status.h deleted file mode 100644 index e13783b..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/status.h +++ /dev/null @@ -1,456 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_status_h__ -#define INCLUDE_git_status_h__ - -#include "common.h" -#include "types.h" -#include "strarray.h" -#include "diff.h" - -/** - * @file git2/status.h - * @brief Status indicates how a user has changed the working directory and index - * @defgroup git_status Git file status routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Status flags for a single file. - * - * A combination of these values will be returned to indicate the status of - * a file. Status compares the working directory, the index, and the - * current HEAD of the repository. The `GIT_STATUS_INDEX` set of flags - * represents the status of file in the index relative to the HEAD, and the - * `GIT_STATUS_WT` set of flags represent the status of the file in the - * working directory relative to the index. - */ -typedef enum { - GIT_STATUS_CURRENT = 0, - - GIT_STATUS_INDEX_NEW = (1u << 0), - GIT_STATUS_INDEX_MODIFIED = (1u << 1), - GIT_STATUS_INDEX_DELETED = (1u << 2), - GIT_STATUS_INDEX_RENAMED = (1u << 3), - GIT_STATUS_INDEX_TYPECHANGE = (1u << 4), - - GIT_STATUS_WT_NEW = (1u << 7), - GIT_STATUS_WT_MODIFIED = (1u << 8), - GIT_STATUS_WT_DELETED = (1u << 9), - GIT_STATUS_WT_TYPECHANGE = (1u << 10), - GIT_STATUS_WT_RENAMED = (1u << 11), - GIT_STATUS_WT_UNREADABLE = (1u << 12), - - GIT_STATUS_IGNORED = (1u << 14), - GIT_STATUS_CONFLICTED = (1u << 15) -} git_status_t; - -/** - * Function pointer to receive status on individual files - * - * @param path is the path to the file - * @param status_flags the `git_status_t` values for file's status - * @param payload the user-specified payload to the foreach function - * @return 0 on success, or a negative number on failure - */ -typedef int GIT_CALLBACK(git_status_cb)( - const char *path, unsigned int status_flags, void *payload); - -/** - * Select the files on which to report status. - * - * With `git_status_foreach_ext`, this will control which changes get - * callbacks. With `git_status_list_new`, these will control which - * changes are included in the list. - */ -typedef enum { - /** - * The default. This roughly matches `git status --porcelain` regarding - * which files are included and in what order. - */ - GIT_STATUS_SHOW_INDEX_AND_WORKDIR = 0, - - /** - * Only gives status based on HEAD to index comparison, not looking at - * working directory changes. - */ - GIT_STATUS_SHOW_INDEX_ONLY = 1, - - /** - * Only gives status based on index to working directory comparison, - * not comparing the index to the HEAD. - */ - GIT_STATUS_SHOW_WORKDIR_ONLY = 2 -} git_status_show_t; - -/** - * Flags to control status callbacks - * - * Calling `git_status_foreach()` is like calling the extended version - * with: GIT_STATUS_OPT_INCLUDE_IGNORED, GIT_STATUS_OPT_INCLUDE_UNTRACKED, - * and GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS. Those options are bundled - * together as `GIT_STATUS_OPT_DEFAULTS` if you want them as a baseline. - */ -typedef enum { - /** - * Says that callbacks should be made on untracked files. - * These will only be made if the workdir files are included in the status - * "show" option. - */ - GIT_STATUS_OPT_INCLUDE_UNTRACKED = (1u << 0), - - /** - * Says that ignored files get callbacks. - * Again, these callbacks will only be made if the workdir files are - * included in the status "show" option. - */ - GIT_STATUS_OPT_INCLUDE_IGNORED = (1u << 1), - - /** - * Indicates that callback should be made even on unmodified files. - */ - GIT_STATUS_OPT_INCLUDE_UNMODIFIED = (1u << 2), - - /** - * Indicates that submodules should be skipped. - * This only applies if there are no pending typechanges to the submodule - * (either from or to another type). - */ - GIT_STATUS_OPT_EXCLUDE_SUBMODULES = (1u << 3), - - /** - * Indicates that all files in untracked directories should be included. - * Normally if an entire directory is new, then just the top-level - * directory is included (with a trailing slash on the entry name). - * This flag says to include all of the individual files in the directory - * instead. - */ - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1u << 4), - - /** - * Indicates that the given path should be treated as a literal path, - * and not as a pathspec pattern. - */ - GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH = (1u << 5), - - /** - * Indicates that the contents of ignored directories should be included - * in the status. This is like doing `git ls-files -o -i --exclude-standard` - * with core git. - */ - GIT_STATUS_OPT_RECURSE_IGNORED_DIRS = (1u << 6), - - /** - * Indicates that rename detection should be processed between the head and - * the index and enables the GIT_STATUS_INDEX_RENAMED as a possible status - * flag. - */ - GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX = (1u << 7), - - /** - * Indicates that rename detection should be run between the index and the - * working directory and enabled GIT_STATUS_WT_RENAMED as a possible status - * flag. - */ - GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR = (1u << 8), - - /** - * Overrides the native case sensitivity for the file system and forces - * the output to be in case-sensitive order. - */ - GIT_STATUS_OPT_SORT_CASE_SENSITIVELY = (1u << 9), - - /** - * Overrides the native case sensitivity for the file system and forces - * the output to be in case-insensitive order. - */ - GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY = (1u << 10), - - /** - * Iindicates that rename detection should include rewritten files. - */ - GIT_STATUS_OPT_RENAMES_FROM_REWRITES = (1u << 11), - - /** - * Bypasses the default status behavior of doing a "soft" index reload - * (i.e. reloading the index data if the file on disk has been modified - * outside libgit2). - */ - GIT_STATUS_OPT_NO_REFRESH = (1u << 12), - - /** - * Tells libgit2 to refresh the stat cache in the index for files that are - * unchanged but have out of date stat einformation in the index. - * It will result in less work being done on subsequent calls to get status. - * This is mutually exclusive with the NO_REFRESH option. - */ - GIT_STATUS_OPT_UPDATE_INDEX = (1u << 13), - - /** - * Normally files that cannot be opened or read are ignored as - * these are often transient files; this option will return - * unreadable files as `GIT_STATUS_WT_UNREADABLE`. - */ - GIT_STATUS_OPT_INCLUDE_UNREADABLE = (1u << 14), - - /** - * Unreadable files will be detected and given the status - * untracked instead of unreadable. - */ - GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 15) -} git_status_opt_t; - -/** Default `git_status_opt_t` values */ -#define GIT_STATUS_OPT_DEFAULTS \ - (GIT_STATUS_OPT_INCLUDE_IGNORED | \ - GIT_STATUS_OPT_INCLUDE_UNTRACKED | \ - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS) - -/** - * Options to control how `git_status_foreach_ext()` will issue callbacks. - * - * Initialize with `GIT_STATUS_OPTIONS_INIT`. Alternatively, you can - * use `git_status_options_init`. - * - */ -typedef struct { - /** - * The struct version; pass `GIT_STATUS_OPTIONS_VERSION`. - */ - unsigned int version; - - /** - * The `show` value is one of the `git_status_show_t` constants that - * control which files to scan and in what order. The default is - * `GIT_STATUS_SHOW_INDEX_AND_WORKDIR`. - */ - git_status_show_t show; - - /** - * The `flags` value is an OR'ed combination of the - * `git_status_opt_t` values above. The default is - * `GIT_STATUS_OPT_DEFAULTS`, which matches git's default - * behavior. - */ - unsigned int flags; - - /** - * The `pathspec` is an array of path patterns to match (using - * fnmatch-style matching), or just an array of paths to match - * exactly if `GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH` is specified - * in the flags. - */ - git_strarray pathspec; - - /** - * The `baseline` is the tree to be used for comparison to the - * working directory and index; defaults to HEAD. - */ - git_tree *baseline; - - /** - * Threshold above which similar files will be considered renames. - * This is equivalent to the -M option. Defaults to 50. - */ - uint16_t rename_threshold; -} git_status_options; - -/** Current version for the `git_status_options` structure */ -#define GIT_STATUS_OPTIONS_VERSION 1 - -/** Static constructor for `git_status_options` */ -#define GIT_STATUS_OPTIONS_INIT {GIT_STATUS_OPTIONS_VERSION} - -/** - * Initialize git_status_options structure - * - * Initializes a `git_status_options` with default values. Equivalent to - * creating an instance with `GIT_STATUS_OPTIONS_INIT`. - * - * @param opts The `git_status_options` struct to initialize. - * @param version The struct version; pass `GIT_STATUS_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_status_options_init( - git_status_options *opts, - unsigned int version); - -/** - * A status entry, providing the differences between the file as it exists - * in HEAD and the index, and providing the differences between the index - * and the working directory. - * - * The `status` value provides the status flags for this file. - * - * The `head_to_index` value provides detailed information about the - * differences between the file in HEAD and the file in the index. - * - * The `index_to_workdir` value provides detailed information about the - * differences between the file in the index and the file in the - * working directory. - */ -typedef struct { - git_status_t status; - git_diff_delta *head_to_index; - git_diff_delta *index_to_workdir; -} git_status_entry; - - -/** - * Gather file statuses and run a callback for each one. - * - * The callback is passed the path of the file, the status (a combination of - * the `git_status_t` values above) and the `payload` data pointer passed - * into this function. - * - * If the callback returns a non-zero value, this function will stop looping - * and return that value to caller. - * - * @param repo A repository object - * @param callback The function to call on each file - * @param payload Pointer to pass through to callback function - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_status_foreach( - git_repository *repo, - git_status_cb callback, - void *payload); - -/** - * Gather file status information and run callbacks as requested. - * - * This is an extended version of the `git_status_foreach()` API that - * allows for more granular control over which paths will be processed and - * in what order. See the `git_status_options` structure for details - * about the additional controls that this makes available. - * - * Note that if a `pathspec` is given in the `git_status_options` to filter - * the status, then the results from rename detection (if you enable it) may - * not be accurate. To do rename detection properly, this must be called - * with no `pathspec` so that all files can be considered. - * - * @param repo Repository object - * @param opts Status options structure - * @param callback The function to call on each file - * @param payload Pointer to pass through to callback function - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_status_foreach_ext( - git_repository *repo, - const git_status_options *opts, - git_status_cb callback, - void *payload); - -/** - * Get file status for a single file. - * - * This tries to get status for the filename that you give. If no files - * match that name (in either the HEAD, index, or working directory), this - * returns GIT_ENOTFOUND. - * - * If the name matches multiple files (for example, if the `path` names a - * directory or if running on a case- insensitive filesystem and yet the - * HEAD has two entries that both match the path), then this returns - * GIT_EAMBIGUOUS because it cannot give correct results. - * - * This does not do any sort of rename detection. Renames require a set of - * targets and because of the path filtering, there is not enough - * information to check renames correctly. To check file status with rename - * detection, there is no choice but to do a full `git_status_list_new` and - * scan through looking for the path that you are interested in. - * - * @param status_flags Output combination of git_status_t values for file - * @param repo A repository object - * @param path The exact path to retrieve status for relative to the - * repository working directory - * @return 0 on success, GIT_ENOTFOUND if the file is not found in the HEAD, - * index, and work tree, GIT_EAMBIGUOUS if `path` matches multiple files - * or if it refers to a folder, and -1 on other errors. - */ -GIT_EXTERN(int) git_status_file( - unsigned int *status_flags, - git_repository *repo, - const char *path); - -/** - * Gather file status information and populate the `git_status_list`. - * - * Note that if a `pathspec` is given in the `git_status_options` to filter - * the status, then the results from rename detection (if you enable it) may - * not be accurate. To do rename detection properly, this must be called - * with no `pathspec` so that all files can be considered. - * - * @param out Pointer to store the status results in - * @param repo Repository object - * @param opts Status options structure - * @return 0 on success or error code - */ -GIT_EXTERN(int) git_status_list_new( - git_status_list **out, - git_repository *repo, - const git_status_options *opts); - -/** - * Gets the count of status entries in this list. - * - * If there are no changes in status (at least according the options given - * when the status list was created), this can return 0. - * - * @param statuslist Existing status list object - * @return the number of status entries - */ -GIT_EXTERN(size_t) git_status_list_entrycount( - git_status_list *statuslist); - -/** - * Get a pointer to one of the entries in the status list. - * - * The entry is not modifiable and should not be freed. - * - * @param statuslist Existing status list object - * @param idx Position of the entry - * @return Pointer to the entry; NULL if out of bounds - */ -GIT_EXTERN(const git_status_entry *) git_status_byindex( - git_status_list *statuslist, - size_t idx); - -/** - * Free an existing status list - * - * @param statuslist Existing status list object - */ -GIT_EXTERN(void) git_status_list_free( - git_status_list *statuslist); - -/** - * Test if the ignore rules apply to a given file. - * - * This function checks the ignore rules to see if they would apply to the - * given file. This indicates if the file would be ignored regardless of - * whether the file is already in the index or committed to the repository. - * - * One way to think of this is if you were to do "git add ." on the - * directory containing the file, would it be added or not? - * - * @param ignored Boolean returning 0 if the file is not ignored, 1 if it is - * @param repo A repository object - * @param path The file to check ignores for, rooted at the repo's workdir. - * @return 0 if ignore rules could be processed for the file (regardless - * of whether it exists or not), or an error < 0 if they could not. - */ -GIT_EXTERN(int) git_status_should_ignore( - int *ignored, - git_repository *repo, - const char *path); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/stdint.h b/vendor/libgit2-sys/libgit2/include/git2/stdint.h deleted file mode 100644 index 4f532e1..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/stdint.h +++ /dev/null @@ -1,249 +0,0 @@ -/* ISO C9x compliant stdint.h for Microsoft Visual Studio - * Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 - * - * Copyright (c) 2006-2008 Alexander Chemeris - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. The name of the author may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - *******************************************************************************/ - -#ifdef _MSC_VER /* [ */ - -#ifndef _MSC_STDINT_H_ /* [ */ -#define _MSC_STDINT_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include - -/* For Visual Studio 6 in C++ mode and for many Visual Studio versions when - * compiling for ARM we should wrap include with 'extern "C++" {}' - * or compiler give many errors like this: - * error C2733: second C linkage of overloaded function 'wmemchr' not allowed -*/ -#ifdef __cplusplus -extern "C" { -#endif -# include -#ifdef __cplusplus -} -#endif - -/* Define _W64 macros to mark types changing their size, like intptr_t. */ -#ifndef _W64 -# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 -# define _W64 __w64 -# else -# define _W64 -# endif -#endif - - -/* 7.18.1 Integer types - * - * 7.18.1.1 Exact-width integer types - * - * Visual Studio 6 and Embedded Visual C++ 4 doesn't - * realize that, e.g. char has the same size as __int8 - * so we give up on __intX for them. - */ -#if (_MSC_VER < 1300) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; -#else - typedef signed __int8 int8_t; - typedef signed __int16 int16_t; - typedef signed __int32 int32_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; -#endif -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; - - -/* 7.18.1.2 Minimum-width integer types */ -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -/* 7.18.1.3 Fastest minimum-width integer types */ -typedef int8_t int_fast8_t; -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef int64_t int_fast64_t; -typedef uint8_t uint_fast8_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; -typedef uint64_t uint_fast64_t; - -/* 7.18.1.4 Integer types capable of holding object pointers */ -#ifdef _WIN64 /* [ */ - typedef signed __int64 intptr_t; - typedef unsigned __int64 uintptr_t; -#else /* _WIN64 ][ */ - typedef _W64 signed int intptr_t; - typedef _W64 unsigned int uintptr_t; -#endif /* _WIN64 ] */ - -/* 7.18.1.5 Greatest-width integer types */ -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; - - -/* 7.18.2 Limits of specified-width integer types */ - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) /* [ See footnote 220 at page 257 and footnote 221 at page 259 */ - -/* 7.18.2.1 Limits of exact-width integer types */ -#define INT8_MIN ((int8_t)_I8_MIN) -#define INT8_MAX _I8_MAX -#define INT16_MIN ((int16_t)_I16_MIN) -#define INT16_MAX _I16_MAX -#define INT32_MIN ((int32_t)_I32_MIN) -#define INT32_MAX _I32_MAX -#define INT64_MIN ((int64_t)_I64_MIN) -#define INT64_MAX _I64_MAX -#define UINT8_MAX _UI8_MAX -#define UINT16_MAX _UI16_MAX -#define UINT32_MAX _UI32_MAX -#define UINT64_MAX _UI64_MAX - -/* 7.18.2.2 Limits of minimum-width integer types */ -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MIN INT64_MIN -#define INT_LEAST64_MAX INT64_MAX -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -/* 7.18.2.3 Limits of fastest minimum-width integer types */ -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MIN INT64_MIN -#define INT_FAST64_MAX INT64_MAX -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -/* 7.18.2.4 Limits of integer types capable of holding object pointers */ -#ifdef _WIN64 /* [ */ -# define INTPTR_MIN INT64_MIN -# define INTPTR_MAX INT64_MAX -# define UINTPTR_MAX UINT64_MAX -#else /* _WIN64 ][ */ -# define INTPTR_MIN INT32_MIN -# define INTPTR_MAX INT32_MAX -# define UINTPTR_MAX UINT32_MAX -#endif /* _WIN64 ] */ - -/* 7.18.2.5 Limits of greatest-width integer types */ -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -/* 7.18.3 Limits of other integer types */ - -#ifdef _WIN64 /* [ */ -# define PTRDIFF_MIN _I64_MIN -# define PTRDIFF_MAX _I64_MAX -#else /* _WIN64 ][ */ -# define PTRDIFF_MIN _I32_MIN -# define PTRDIFF_MAX _I32_MAX -#endif /* _WIN64 ] */ - -#define SIG_ATOMIC_MIN INT_MIN -#define SIG_ATOMIC_MAX INT_MAX - -#ifndef SIZE_MAX /* [ */ -# ifdef _WIN64 /* [ */ -# define SIZE_MAX _UI64_MAX -# else /* _WIN64 ][ */ -# define SIZE_MAX _UI32_MAX -# endif /* _WIN64 ] */ -#endif /* SIZE_MAX ] */ - -/* WCHAR_MIN and WCHAR_MAX are also defined in */ -#ifndef WCHAR_MIN /* [ */ -# define WCHAR_MIN 0 -#endif /* WCHAR_MIN ] */ -#ifndef WCHAR_MAX /* [ */ -# define WCHAR_MAX _UI16_MAX -#endif /* WCHAR_MAX ] */ - -#define WINT_MIN 0 -#define WINT_MAX _UI16_MAX - -#endif /* __STDC_LIMIT_MACROS ] */ - - -/* 7.18.4 Limits of other integer types */ - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) /* [ See footnote 224 at page 260 */ - -/* 7.18.4.1 Macros for minimum-width integer constants */ - -#define INT8_C(val) val##i8 -#define INT16_C(val) val##i16 -#define INT32_C(val) val##i32 -#define INT64_C(val) val##i64 - -#define UINT8_C(val) val##ui8 -#define UINT16_C(val) val##ui16 -#define UINT32_C(val) val##ui32 -#define UINT64_C(val) val##ui64 - -/* 7.18.4.2 Macros for greatest-width integer constants */ -#define INTMAX_C INT64_C -#define UINTMAX_C UINT64_C - -#endif /* __STDC_CONSTANT_MACROS ] */ - - -#endif /* _MSC_STDINT_H_ ] */ - -#endif /* _MSC_VER ] */ diff --git a/vendor/libgit2-sys/libgit2/include/git2/strarray.h b/vendor/libgit2-sys/libgit2/include/git2/strarray.h deleted file mode 100644 index dcb628a..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/strarray.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_strarray_h__ -#define INCLUDE_git_strarray_h__ - -#include "common.h" - -/** - * @file git2/strarray.h - * @brief An array of strings for the user to free - * @defgroup git_strarray An array of strings for the user to free - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Array of strings */ -typedef struct git_strarray { - char **strings; - size_t count; -} git_strarray; - -/** - * Free the strings contained in a string array. This method should - * be called on `git_strarray` objects that were provided by the - * library. Not doing so, will result in a memory leak. - * - * This does not free the `git_strarray` itself, since the library will - * never allocate that object directly itself. - * - * @param array The git_strarray that contains strings to free - */ -GIT_EXTERN(void) git_strarray_dispose(git_strarray *array); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/submodule.h b/vendor/libgit2-sys/libgit2/include/git2/submodule.h deleted file mode 100644 index 911b3ce..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/submodule.h +++ /dev/null @@ -1,679 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_submodule_h__ -#define INCLUDE_git_submodule_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "remote.h" -#include "checkout.h" - -/** - * @file git2/submodule.h - * @brief Submodules place another repository's contents within this one - * - * Submodule support in libgit2 builds a list of known submodules and keeps - * it in the repository. The list is built from the .gitmodules file, the - * .git/config file, the index, and the HEAD tree. Items in the working - * directory that look like submodules (i.e. a git repo) but are not - * mentioned in those places won't be tracked. - * - * @defgroup git_submodule Git submodule management routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Return codes for submodule status. - * - * A combination of these flags will be returned to describe the status of a - * submodule. Depending on the "ignore" property of the submodule, some of - * the flags may never be returned because they indicate changes that are - * supposed to be ignored. - * - * Submodule info is contained in 4 places: the HEAD tree, the index, config - * files (both .git/config and .gitmodules), and the working directory. Any - * or all of those places might be missing information about the submodule - * depending on what state the repo is in. We consider all four places to - * build the combination of status flags. - * - * There are four values that are not really status, but give basic info - * about what sources of submodule data are available. These will be - * returned even if ignore is set to "ALL". - * - * * IN_HEAD - superproject head contains submodule - * * IN_INDEX - superproject index contains submodule - * * IN_CONFIG - superproject gitmodules has submodule - * * IN_WD - superproject workdir has submodule - * - * The following values will be returned so long as ignore is not "ALL". - * - * * INDEX_ADDED - in index, not in head - * * INDEX_DELETED - in head, not in index - * * INDEX_MODIFIED - index and head don't match - * * WD_UNINITIALIZED - workdir contains empty directory - * * WD_ADDED - in workdir, not index - * * WD_DELETED - in index, not workdir - * * WD_MODIFIED - index and workdir head don't match - * - * The following can only be returned if ignore is "NONE" or "UNTRACKED". - * - * * WD_INDEX_MODIFIED - submodule workdir index is dirty - * * WD_WD_MODIFIED - submodule workdir has modified files - * - * Lastly, the following will only be returned for ignore "NONE". - * - * * WD_UNTRACKED - wd contains untracked files - */ -typedef enum { - GIT_SUBMODULE_STATUS_IN_HEAD = (1u << 0), - GIT_SUBMODULE_STATUS_IN_INDEX = (1u << 1), - GIT_SUBMODULE_STATUS_IN_CONFIG = (1u << 2), - GIT_SUBMODULE_STATUS_IN_WD = (1u << 3), - GIT_SUBMODULE_STATUS_INDEX_ADDED = (1u << 4), - GIT_SUBMODULE_STATUS_INDEX_DELETED = (1u << 5), - GIT_SUBMODULE_STATUS_INDEX_MODIFIED = (1u << 6), - GIT_SUBMODULE_STATUS_WD_UNINITIALIZED = (1u << 7), - GIT_SUBMODULE_STATUS_WD_ADDED = (1u << 8), - GIT_SUBMODULE_STATUS_WD_DELETED = (1u << 9), - GIT_SUBMODULE_STATUS_WD_MODIFIED = (1u << 10), - GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11), - GIT_SUBMODULE_STATUS_WD_WD_MODIFIED = (1u << 12), - GIT_SUBMODULE_STATUS_WD_UNTRACKED = (1u << 13) -} git_submodule_status_t; - -/** Submodule source bits */ -#define GIT_SUBMODULE_STATUS__IN_FLAGS 0x000Fu -/** Submodule index status */ -#define GIT_SUBMODULE_STATUS__INDEX_FLAGS 0x0070u -/** Submodule working directory status */ -#define GIT_SUBMODULE_STATUS__WD_FLAGS 0x3F80u - -/** Whether the submodule is modified */ -#define GIT_SUBMODULE_STATUS_IS_UNMODIFIED(S) \ - (((S) & ~GIT_SUBMODULE_STATUS__IN_FLAGS) == 0) - -/** Whether the submodule is modified (in the index) */ -#define GIT_SUBMODULE_STATUS_IS_INDEX_UNMODIFIED(S) \ - (((S) & GIT_SUBMODULE_STATUS__INDEX_FLAGS) == 0) - -/** Whether the submodule is modified (in the working directory) */ -#define GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(S) \ - (((S) & (GIT_SUBMODULE_STATUS__WD_FLAGS & \ - ~GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)) == 0) - -/** Whether the submodule working directory is dirty */ -#define GIT_SUBMODULE_STATUS_IS_WD_DIRTY(S) \ - (((S) & (GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED | \ - GIT_SUBMODULE_STATUS_WD_WD_MODIFIED | \ - GIT_SUBMODULE_STATUS_WD_UNTRACKED)) != 0) - -/** - * Function pointer to receive each submodule - * - * @param sm git_submodule currently being visited - * @param name name of the submodule - * @param payload value you passed to the foreach function as payload - * @return 0 on success or error code - */ -typedef int GIT_CALLBACK(git_submodule_cb)( - git_submodule *sm, const char *name, void *payload); - -/** - * Submodule update options structure - * - * Initialize with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`. Alternatively, you can - * use `git_submodule_update_options_init`. - * - */ -typedef struct git_submodule_update_options { - unsigned int version; - - /** - * These options are passed to the checkout step. To disable - * checkout, set the `checkout_strategy` to `GIT_CHECKOUT_NONE` - * or `GIT_CHECKOUT_DRY_RUN`. - */ - git_checkout_options checkout_opts; - - /** - * Options which control the fetch, including callbacks. - * - * The callbacks to use for reporting fetch progress, and for acquiring - * credentials in the event they are needed. - */ - git_fetch_options fetch_opts; - - /** - * Allow fetching from the submodule's default remote if the target - * commit isn't found. Enabled by default. - */ - int allow_fetch; -} git_submodule_update_options; - -/** Current version for the `git_submodule_update_options` structure */ -#define GIT_SUBMODULE_UPDATE_OPTIONS_VERSION 1 - -/** Static constructor for `git_submodule_update_options` */ -#define GIT_SUBMODULE_UPDATE_OPTIONS_INIT \ - { GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, \ - GIT_CHECKOUT_OPTIONS_INIT, \ - GIT_FETCH_OPTIONS_INIT, \ - 1 } - -/** - * Initialize git_submodule_update_options structure - * - * Initializes a `git_submodule_update_options` with default values. Equivalent to - * creating an instance with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`. - * - * @param opts The `git_submodule_update_options` struct to initialize. - * @param version The struct version; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_submodule_update_options_init( - git_submodule_update_options *opts, unsigned int version); - -/** - * Update a submodule. This will clone a missing submodule and - * checkout the subrepository to the commit specified in the index of - * the containing repository. If the submodule repository doesn't contain - * the target commit (e.g. because fetchRecurseSubmodules isn't set), then - * the submodule is fetched using the fetch options supplied in options. - * - * @param submodule Submodule object - * @param init If the submodule is not initialized, setting this flag to true - * will initialize the submodule before updating. Otherwise, this will - * return an error if attempting to update an uninitialized repository. - * but setting this to true forces them to be updated. - * @param options configuration options for the update. If NULL, the - * function works as though GIT_SUBMODULE_UPDATE_OPTIONS_INIT was passed. - * @return 0 on success, any non-zero return value from a callback - * function, or a negative value to indicate an error (use - * `git_error_last` for a detailed error message). - */ -GIT_EXTERN(int) git_submodule_update(git_submodule *submodule, int init, git_submodule_update_options *options); - -/** - * Lookup submodule information by name or path. - * - * Given either the submodule name or path (they are usually the same), this - * returns a structure describing the submodule. - * - * There are two expected error scenarios: - * - * - The submodule is not mentioned in the HEAD, the index, and the config, - * but does "exist" in the working directory (i.e. there is a subdirectory - * that appears to be a Git repository). In this case, this function - * returns GIT_EEXISTS to indicate a sub-repository exists but not in a - * state where a git_submodule can be instantiated. - * - The submodule is not mentioned in the HEAD, index, or config and the - * working directory doesn't contain a value git repo at that path. - * There may or may not be anything else at that path, but nothing that - * looks like a submodule. In this case, this returns GIT_ENOTFOUND. - * - * You must call `git_submodule_free` when done with the submodule. - * - * @param out Output ptr to submodule; pass NULL to just get return code - * @param repo The parent repository - * @param name The name of or path to the submodule; trailing slashes okay - * @return 0 on success, GIT_ENOTFOUND if submodule does not exist, - * GIT_EEXISTS if a repository is found in working directory only, - * -1 on other errors. - */ -GIT_EXTERN(int) git_submodule_lookup( - git_submodule **out, - git_repository *repo, - const char *name); - -/** - * Create an in-memory copy of a submodule. The copy must be explicitly - * free'd or it will leak. - * - * @param out Pointer to store the copy of the submodule. - * @param source Original submodule to copy. - * @return 0 - */ -GIT_EXTERN(int) git_submodule_dup(git_submodule **out, git_submodule *source); - -/** - * Release a submodule - * - * @param submodule Submodule object - */ -GIT_EXTERN(void) git_submodule_free(git_submodule *submodule); - -/** - * Iterate over all tracked submodules of a repository. - * - * See the note on `git_submodule` above. This iterates over the tracked - * submodules as described therein. - * - * If you are concerned about items in the working directory that look like - * submodules but are not tracked, the diff API will generate a diff record - * for workdir items that look like submodules but are not tracked, showing - * them as added in the workdir. Also, the status API will treat the entire - * subdirectory of a contained git repo as a single GIT_STATUS_WT_NEW item. - * - * @param repo The repository - * @param callback Function to be called with the name of each submodule. - * Return a non-zero value to terminate the iteration. - * @param payload Extra data to pass to callback - * @return 0 on success, -1 on error, or non-zero return value of callback - */ -GIT_EXTERN(int) git_submodule_foreach( - git_repository *repo, - git_submodule_cb callback, - void *payload); - -/** - * Set up a new git submodule for checkout. - * - * This does "git submodule add" up to the fetch and checkout of the - * submodule contents. It preps a new submodule, creates an entry in - * .gitmodules and creates an empty initialized repository either at the - * given path in the working directory or in .git/modules with a gitlink - * from the working directory to the new repo. - * - * To fully emulate "git submodule add" call this function, then open the - * submodule repo and perform the clone step as needed (if you don't need - * anything custom see `git_submodule_add_clone()`). Lastly, call - * `git_submodule_add_finalize()` to wrap up adding the new submodule and - * .gitmodules to the index to be ready to commit. - * - * You must call `git_submodule_free` on the submodule object when done. - * - * @param out The newly created submodule ready to open for clone - * @param repo The repository in which you want to create the submodule - * @param url URL for the submodule's remote - * @param path Path at which the submodule should be created - * @param use_gitlink Should workdir contain a gitlink to the repo in - * .git/modules vs. repo directly in workdir. - * @return 0 on success, GIT_EEXISTS if submodule already exists, - * -1 on other errors. - */ -GIT_EXTERN(int) git_submodule_add_setup( - git_submodule **out, - git_repository *repo, - const char *url, - const char *path, - int use_gitlink); - -/** - * Perform the clone step for a newly created submodule. - * - * This performs the necessary `git_clone` to setup a newly-created submodule. - * - * @param out The newly created repository object. Optional. - * @param submodule The submodule currently waiting for its clone. - * @param opts The options to use. - * - * @return 0 on success, -1 on other errors (see git_clone). - */ -GIT_EXTERN(int) git_submodule_clone( - git_repository **out, - git_submodule *submodule, - const git_submodule_update_options *opts); - -/** - * Resolve the setup of a new git submodule. - * - * This should be called on a submodule once you have called add setup - * and done the clone of the submodule. This adds the .gitmodules file - * and the newly cloned submodule to the index to be ready to be committed - * (but doesn't actually do the commit). - * - * @param submodule The submodule to finish adding. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_submodule_add_finalize(git_submodule *submodule); - -/** - * Add current submodule HEAD commit to index of superproject. - * - * @param submodule The submodule to add to the index - * @param write_index Boolean if this should immediately write the index - * file. If you pass this as false, you will have to get the - * git_index and explicitly call `git_index_write()` on it to - * save the change. - * @return 0 on success, <0 on failure - */ -GIT_EXTERN(int) git_submodule_add_to_index( - git_submodule *submodule, - int write_index); - -/** - * Get the containing repository for a submodule. - * - * This returns a pointer to the repository that contains the submodule. - * This is a just a reference to the repository that was passed to the - * original `git_submodule_lookup()` call, so if that repository has been - * freed, then this may be a dangling reference. - * - * @param submodule Pointer to submodule object - * @return Pointer to `git_repository` - */ -GIT_EXTERN(git_repository *) git_submodule_owner(git_submodule *submodule); - -/** - * Get the name of submodule. - * - * @param submodule Pointer to submodule object - * @return Pointer to the submodule name - */ -GIT_EXTERN(const char *) git_submodule_name(git_submodule *submodule); - -/** - * Get the path to the submodule. - * - * The path is almost always the same as the submodule name, but the - * two are actually not required to match. - * - * @param submodule Pointer to submodule object - * @return Pointer to the submodule path - */ -GIT_EXTERN(const char *) git_submodule_path(git_submodule *submodule); - -/** - * Get the URL for the submodule. - * - * @param submodule Pointer to submodule object - * @return Pointer to the submodule url - */ -GIT_EXTERN(const char *) git_submodule_url(git_submodule *submodule); - -/** - * Resolve a submodule url relative to the given repository. - * - * @param out buffer to store the absolute submodule url in - * @param repo Pointer to repository object - * @param url Relative url - * @return 0 or an error code - */ -GIT_EXTERN(int) git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *url); - -/** -* Get the branch for the submodule. -* -* @param submodule Pointer to submodule object -* @return Pointer to the submodule branch -*/ -GIT_EXTERN(const char *) git_submodule_branch(git_submodule *submodule); - -/** - * Set the branch for the submodule in the configuration - * - * After calling this, you may wish to call `git_submodule_sync()` to - * write the changes to the checked out submodule repository. - * - * @param repo the repository to affect - * @param name the name of the submodule to configure - * @param branch Branch that should be used for the submodule - * @return 0 on success, <0 on failure - */ -GIT_EXTERN(int) git_submodule_set_branch(git_repository *repo, const char *name, const char *branch); - -/** - * Set the URL for the submodule in the configuration - * - * - * After calling this, you may wish to call `git_submodule_sync()` to - * write the changes to the checked out submodule repository. - * - * @param repo the repository to affect - * @param name the name of the submodule to configure - * @param url URL that should be used for the submodule - * @return 0 on success, <0 on failure - */ -GIT_EXTERN(int) git_submodule_set_url(git_repository *repo, const char *name, const char *url); - -/** - * Get the OID for the submodule in the index. - * - * @param submodule Pointer to submodule object - * @return Pointer to git_oid or NULL if submodule is not in index. - */ -GIT_EXTERN(const git_oid *) git_submodule_index_id(git_submodule *submodule); - -/** - * Get the OID for the submodule in the current HEAD tree. - * - * @param submodule Pointer to submodule object - * @return Pointer to git_oid or NULL if submodule is not in the HEAD. - */ -GIT_EXTERN(const git_oid *) git_submodule_head_id(git_submodule *submodule); - -/** - * Get the OID for the submodule in the current working directory. - * - * This returns the OID that corresponds to looking up 'HEAD' in the checked - * out submodule. If there are pending changes in the index or anything - * else, this won't notice that. You should call `git_submodule_status()` - * for a more complete picture about the state of the working directory. - * - * @param submodule Pointer to submodule object - * @return Pointer to git_oid or NULL if submodule is not checked out. - */ -GIT_EXTERN(const git_oid *) git_submodule_wd_id(git_submodule *submodule); - -/** - * Get the ignore rule that will be used for the submodule. - * - * These values control the behavior of `git_submodule_status()` for this - * submodule. There are four ignore values: - * - * - **GIT_SUBMODULE_IGNORE_NONE** will consider any change to the contents - * of the submodule from a clean checkout to be dirty, including the - * addition of untracked files. This is the default if unspecified. - * - **GIT_SUBMODULE_IGNORE_UNTRACKED** examines the contents of the - * working tree (i.e. call `git_status_foreach()` on the submodule) but - * UNTRACKED files will not count as making the submodule dirty. - * - **GIT_SUBMODULE_IGNORE_DIRTY** means to only check if the HEAD of the - * submodule has moved for status. This is fast since it does not need to - * scan the working tree of the submodule at all. - * - **GIT_SUBMODULE_IGNORE_ALL** means not to open the submodule repo. - * The working directory will be consider clean so long as there is a - * checked out version present. - * - * @param submodule The submodule to check - * @return The current git_submodule_ignore_t valyue what will be used for - * this submodule. - */ -GIT_EXTERN(git_submodule_ignore_t) git_submodule_ignore( - git_submodule *submodule); - -/** - * Set the ignore rule for the submodule in the configuration - * - * This does not affect any currently-loaded instances. - * - * @param repo the repository to affect - * @param name the name of the submdule - * @param ignore The new value for the ignore rule - * @return 0 or an error code - */ -GIT_EXTERN(int) git_submodule_set_ignore( - git_repository *repo, - const char *name, - git_submodule_ignore_t ignore); - -/** - * Get the update rule that will be used for the submodule. - * - * This value controls the behavior of the `git submodule update` command. - * There are four useful values documented with `git_submodule_update_t`. - * - * @param submodule The submodule to check - * @return The current git_submodule_update_t value that will be used - * for this submodule. - */ -GIT_EXTERN(git_submodule_update_t) git_submodule_update_strategy( - git_submodule *submodule); - -/** - * Set the update rule for the submodule in the configuration - * - * This setting won't affect any existing instances. - * - * @param repo the repository to affect - * @param name the name of the submodule to configure - * @param update The new value to use - * @return 0 or an error code - */ -GIT_EXTERN(int) git_submodule_set_update( - git_repository *repo, - const char *name, - git_submodule_update_t update); - -/** - * Read the fetchRecurseSubmodules rule for a submodule. - * - * This accesses the submodule..fetchRecurseSubmodules value for - * the submodule that controls fetching behavior for the submodule. - * - * Note that at this time, libgit2 does not honor this setting and the - * fetch functionality current ignores submodules. - * - * @param submodule the submodule to examine - * @return the submodule recursion configuration - */ -GIT_EXTERN(git_submodule_recurse_t) git_submodule_fetch_recurse_submodules( - git_submodule *submodule); - -/** - * Set the fetchRecurseSubmodules rule for a submodule in the configuration - * - * This setting won't affect any existing instances. - * - * @param repo the repository to affect - * @param name the submodule to configure - * @param fetch_recurse_submodules the submodule recursion configuration - * @return old value for fetchRecurseSubmodules - */ -GIT_EXTERN(int) git_submodule_set_fetch_recurse_submodules( - git_repository *repo, - const char *name, - git_submodule_recurse_t fetch_recurse_submodules); - -/** - * Copy submodule info into ".git/config" file. - * - * Just like "git submodule init", this copies information about the - * submodule into ".git/config". You can use the accessor functions - * above to alter the in-memory git_submodule object and control what - * is written to the config, overriding what is in .gitmodules. - * - * @param submodule The submodule to write into the superproject config - * @param overwrite By default, existing entries will not be overwritten, - * but setting this to true forces them to be updated. - * @return 0 on success, <0 on failure. - */ -GIT_EXTERN(int) git_submodule_init(git_submodule *submodule, int overwrite); - -/** - * Set up the subrepository for a submodule in preparation for clone. - * - * This function can be called to init and set up a submodule - * repository from a submodule in preparation to clone it from - * its remote. - * - * @param out Output pointer to the created git repository. - * @param sm The submodule to create a new subrepository from. - * @param use_gitlink Should the workdir contain a gitlink to - * the repo in .git/modules vs. repo directly in workdir. - * @return 0 on success, <0 on failure. - */ -GIT_EXTERN(int) git_submodule_repo_init( - git_repository **out, - const git_submodule *sm, - int use_gitlink); - -/** - * Copy submodule remote info into submodule repo. - * - * This copies the information about the submodules URL into the checked out - * submodule config, acting like "git submodule sync". This is useful if - * you have altered the URL for the submodule (or it has been altered by a - * fetch of upstream changes) and you need to update your local repo. - * - * @param submodule The submodule to copy. - * @return 0 or an error code. - */ -GIT_EXTERN(int) git_submodule_sync(git_submodule *submodule); - -/** - * Open the repository for a submodule. - * - * This is a newly opened repository object. The caller is responsible for - * calling `git_repository_free()` on it when done. Multiple calls to this - * function will return distinct `git_repository` objects. This will only - * work if the submodule is checked out into the working directory. - * - * @param repo Pointer to the submodule repo which was opened - * @param submodule Submodule to be opened - * @return 0 on success, <0 if submodule repo could not be opened. - */ -GIT_EXTERN(int) git_submodule_open( - git_repository **repo, - git_submodule *submodule); - -/** - * Reread submodule info from config, index, and HEAD. - * - * Call this to reread cached submodule information for this submodule if - * you have reason to believe that it has changed. - * - * @param submodule The submodule to reload - * @param force Force reload even if the data doesn't seem out of date - * @return 0 on success, <0 on error - */ -GIT_EXTERN(int) git_submodule_reload(git_submodule *submodule, int force); - -/** - * Get the status for a submodule. - * - * This looks at a submodule and tries to determine the status. It - * will return a combination of the `GIT_SUBMODULE_STATUS` values above. - * How deeply it examines the working directory to do this will depend - * on the `git_submodule_ignore_t` value for the submodule. - * - * @param status Combination of `GIT_SUBMODULE_STATUS` flags - * @param repo the repository in which to look - * @param name name of the submodule - * @param ignore the ignore rules to follow - * @return 0 on success, <0 on error - */ -GIT_EXTERN(int) git_submodule_status( - unsigned int *status, - git_repository *repo, - const char *name, - git_submodule_ignore_t ignore); - -/** - * Get the locations of submodule information. - * - * This is a bit like a very lightweight version of `git_submodule_status`. - * It just returns a made of the first four submodule status values (i.e. - * the ones like GIT_SUBMODULE_STATUS_IN_HEAD, etc) that tell you where the - * submodule data comes from (i.e. the HEAD commit, gitmodules file, etc.). - * This can be useful if you want to know if the submodule is present in the - * working directory at this point in time, etc. - * - * @param location_status Combination of first four `GIT_SUBMODULE_STATUS` flags - * @param submodule Submodule for which to get status - * @return 0 on success, <0 on error - */ -GIT_EXTERN(int) git_submodule_location( - unsigned int *location_status, - git_submodule *submodule); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/alloc.h b/vendor/libgit2-sys/libgit2/include/git2/sys/alloc.h deleted file mode 100644 index 67506f2..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/alloc.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_sys_git_alloc_h__ -#define INCLUDE_sys_git_alloc_h__ - -#include "git2/common.h" - -/** - * @file git2/sys/alloc.h - * @brief Custom memory allocators - * @defgroup git_merge Git merge routines - * @ingroup Git - * - * Users can configure custom allocators; this is particularly - * interesting when running in constrained environments, when calling - * from another language, or during testing. - * @{ - */ -GIT_BEGIN_DECL - -/** - * An instance for a custom memory allocator - * - * Setting the pointers of this structure allows the developer to implement - * custom memory allocators. The global memory allocator can be set by using - * "GIT_OPT_SET_ALLOCATOR" with the `git_libgit2_opts` function. Keep in mind - * that all fields need to be set to a proper function. - */ -typedef struct { - /** Allocate `n` bytes of memory */ - void * GIT_CALLBACK(gmalloc)(size_t n, const char *file, int line); - - /** - * This function shall deallocate the old object `ptr` and return a - * pointer to a new object that has the size specified by `size`. In - * case `ptr` is `NULL`, a new array shall be allocated. - */ - void * GIT_CALLBACK(grealloc)(void *ptr, size_t size, const char *file, int line); - - /** - * This function shall free the memory pointed to by `ptr`. In case - * `ptr` is `NULL`, this shall be a no-op. - */ - void GIT_CALLBACK(gfree)(void *ptr); -} git_allocator; - -/** - * Initialize the allocator structure to use the `stdalloc` pointer. - * - * Set up the structure so that all of its members are using the standard - * "stdalloc" allocator functions. The structure can then be used with - * `git_allocator_setup`. - * - * @param allocator The allocator that is to be initialized. - * @return An error code or 0. - */ -int git_stdalloc_init_allocator(git_allocator *allocator); - -/** - * Initialize the allocator structure to use the `crtdbg` pointer. - * - * Set up the structure so that all of its members are using the "crtdbg" - * allocator functions. Note that this allocator is only available on Windows - * platforms and only if libgit2 is being compiled with "-DMSVC_CRTDBG". - * - * @param allocator The allocator that is to be initialized. - * @return An error code or 0. - */ -int git_win32_crtdbg_init_allocator(git_allocator *allocator); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/commit.h b/vendor/libgit2-sys/libgit2/include/git2/sys/commit.h deleted file mode 100644 index a8253c0..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/commit.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_commit_h__ -#define INCLUDE_sys_git_commit_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/oid.h" - -/** - * @file git2/sys/commit.h - * @brief Low-level Git commit creation - * @defgroup git_commit Low-level Git commit creation - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create new commit in the repository from a list of `git_oid` values. - * - * See documentation for `git_commit_create()` for information about the - * parameters, as the meaning is identical excepting that `tree` and - * `parents` now take `git_oid`. This is a dangerous API in that nor - * the `tree`, neither the `parents` list of `git_oid`s are checked for - * validity. - * - * @param id Pointer in which to store the OID of the newly created commit - * - * @param repo Repository where to store the commit - * - * @param update_ref If not NULL, name of the reference that - * will be updated to point to this commit. If the reference - * is not direct, it will be resolved to a direct reference. - * Use "HEAD" to update the HEAD of the current branch and - * make it point to this commit. If the reference doesn't - * exist yet, it will be created. If it does exist, the first - * parent must be the tip of this branch. - * - * @param author Signature with author and author time of commit - * - * @param committer Signature with committer and * commit time of commit - * - * @param message_encoding The encoding for the message in the - * commit, represented with a standard encoding name. - * E.g. "UTF-8". If NULL, no encoding header is written and - * UTF-8 is assumed. - * - * @param message Full message for this commit - * - * @param tree An instance of a `git_tree` object that will - * be used as the tree for the commit. This tree object must - * also be owned by the given `repo`. - * - * @param parent_count Number of parents for this commit - * - * @param parents Array of `parent_count` pointers to `git_commit` - * objects that will be used as the parents for this commit. This - * array may be NULL if `parent_count` is 0 (root commit). All the - * given commits must be owned by the `repo`. - * - * @return 0 or an error code - * The created commit will be written to the Object Database and - * the given reference will be updated to point to it - */ -GIT_EXTERN(int) git_commit_create_from_ids( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_oid *tree, - size_t parent_count, - const git_oid *parents[]); - -/** - * Callback function to return parents for commit. - * - * This is invoked with the count of the number of parents processed so far - * along with the user supplied payload. This should return a git_oid of - * the next parent or NULL if all parents have been provided. - * - * @param idx the index of the parent - * @param payload the user-specified payload - * @return the object id of the parent, or NULL if there are no further parents - */ -typedef const git_oid * GIT_CALLBACK(git_commit_parent_callback)(size_t idx, void *payload); - -/** - * Create a new commit in the repository with an callback to supply parents. - * - * See documentation for `git_commit_create()` for information about the - * parameters, as the meaning is identical excepting that `tree` takes a - * `git_oid` and doesn't check for validity, and `parent_cb` is invoked - * with `parent_payload` and should return `git_oid` values or NULL to - * indicate that all parents are accounted for. - * - * @param id Pointer in which to store the OID of the newly created commit - * - * @param repo Repository where to store the commit - * - * @param update_ref If not NULL, name of the reference that - * will be updated to point to this commit. If the reference - * is not direct, it will be resolved to a direct reference. - * Use "HEAD" to update the HEAD of the current branch and - * make it point to this commit. If the reference doesn't - * exist yet, it will be created. If it does exist, the first - * parent must be the tip of this branch. - * - * @param author Signature with author and author time of commit - * - * @param committer Signature with committer and * commit time of commit - * - * @param message_encoding The encoding for the message in the - * commit, represented with a standard encoding name. - * E.g. "UTF-8". If NULL, no encoding header is written and - * UTF-8 is assumed. - * - * @param message Full message for this commit - * - * @param tree An instance of a `git_tree` object that will - * be used as the tree for the commit. This tree object must - * also be owned by the given `repo`. - * - * @param parent_cb Callback to invoke to obtain parent information - * - * @param parent_payload User-specified payload to provide to the callback - * - * @return 0 or an error code - * The created commit will be written to the Object Database and - * the given reference will be updated to point to it - */ -GIT_EXTERN(int) git_commit_create_from_callback( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_oid *tree, - git_commit_parent_callback parent_cb, - void *parent_payload); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/commit_graph.h b/vendor/libgit2-sys/libgit2/include/git2/sys/commit_graph.h deleted file mode 100644 index ff547ef..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/commit_graph.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_commit_graph_h__ -#define INCLUDE_sys_git_commit_graph_h__ - -#include "git2/common.h" -#include "git2/types.h" - -/** - * @file git2/sys/commit_graph.h - * @brief Commit graphs store information about commit relationships - * @defgroup git_commit_graph Commit graphs - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Options structure for `git_commit_graph_open_new`. - * - * Initialize with `GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT`. Alternatively, - * you can use `git_commit_graph_open_options_init`. - */ -typedef struct { - unsigned int version; - -#ifdef GIT_EXPERIMENTAL_SHA256 - /** The object ID type that this commit graph contains. */ - git_oid_t oid_type; -#endif -} git_commit_graph_open_options; - -/** Current version for the `git_commit_graph_open_options` structure */ -#define GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION 1 - -/** Static constructor for `git_commit_graph_open_options` */ -#define GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT { \ - GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION \ - } - -/** - * Initialize git_commit_graph_open_options structure - * - * Initializes a `git_commit_graph_open_options` with default values. - * Equivalent to creating an instance with - * `GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT`. - * - * @param opts The `git_commit_graph_open_options` struct to initialize. - * @param version The struct version; pass `GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_commit_graph_open_options_init( - git_commit_graph_open_options *opts, - unsigned int version); - - -/** - * Opens a `git_commit_graph` from a path to an objects directory. - * - * This finds, opens, and validates the `commit-graph` file. - * - * @param cgraph_out the `git_commit_graph` struct to initialize. - * @param objects_dir the path to a git objects directory. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_commit_graph_open( - git_commit_graph **cgraph_out, - const char *objects_dir -#ifdef GIT_EXPERIMENTAL_SHA256 - , const git_commit_graph_open_options *options -#endif - ); - -/** - * Frees commit-graph data. This should only be called when memory allocated - * using `git_commit_graph_open` is not returned to libgit2 because it was not - * associated with the ODB through a successful call to - * `git_odb_set_commit_graph`. - * - * @param cgraph the commit-graph object to free. If NULL, no action is taken. - */ -GIT_EXTERN(void) git_commit_graph_free(git_commit_graph *cgraph); - - -/** - * The strategy to use when adding a new set of commits to a pre-existing - * commit-graph chain. - */ -typedef enum { - /** - * Do not split commit-graph files. The other split strategy-related option - * fields are ignored. - */ - GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0 -} git_commit_graph_split_strategy_t; - -/** - * Options structure for `git_commit_graph_writer_new`. - * - * Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively, - * you can use `git_commit_graph_writer_options_init`. - */ -typedef struct { - unsigned int version; - -#ifdef GIT_EXPERIMENTAL_SHA256 - /** The object ID type that this commit graph contains. */ - git_oid_t oid_type; -#endif - - /** - * The strategy to use when adding new commits to a pre-existing commit-graph - * chain. - */ - git_commit_graph_split_strategy_t split_strategy; - - /** - * The number of commits in level N is less than X times the number of - * commits in level N + 1. Default is 2. - */ - float size_multiple; - - /** - * The number of commits in level N + 1 is more than C commits. - * Default is 64000. - */ - size_t max_commits; -} git_commit_graph_writer_options; - -/** Current version for the `git_commit_graph_writer_options` structure */ -#define GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION 1 - -/** Static constructor for `git_commit_graph_writer_options` */ -#define GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT { \ - GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION \ - } - -/** - * Initialize git_commit_graph_writer_options structure - * - * Initializes a `git_commit_graph_writer_options` with default values. Equivalent to - * creating an instance with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. - * - * @param opts The `git_commit_graph_writer_options` struct to initialize. - * @param version The struct version; pass `GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_commit_graph_writer_options_init( - git_commit_graph_writer_options *opts, - unsigned int version); - -/** - * Create a new writer for `commit-graph` files. - * - * @param out Location to store the writer pointer. - * @param objects_info_dir The `objects/info` directory. - * The `commit-graph` file will be written in this directory. - * @param options The options for the commit graph writer. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_graph_writer_new( - git_commit_graph_writer **out, - const char *objects_info_dir, - const git_commit_graph_writer_options *options); - -/** - * Free the commit-graph writer and its resources. - * - * @param w The writer to free. If NULL no action is taken. - */ -GIT_EXTERN(void) git_commit_graph_writer_free(git_commit_graph_writer *w); - -/** - * Add an `.idx` file (associated to a packfile) to the writer. - * - * @param w The writer. - * @param repo The repository that owns the `.idx` file. - * @param idx_path The path of an `.idx` file. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_graph_writer_add_index_file( - git_commit_graph_writer *w, - git_repository *repo, - const char *idx_path); - -/** - * Add a revwalk to the writer. This will add all the commits from the revwalk - * to the commit-graph. - * - * @param w The writer. - * @param walk The git_revwalk. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_graph_writer_add_revwalk( - git_commit_graph_writer *w, - git_revwalk *walk); - -/** - * Write a `commit-graph` file to a file. - * - * @param w The writer - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_graph_writer_commit( - git_commit_graph_writer *w); - -/** - * Dump the contents of the `commit-graph` to an in-memory buffer. - * - * @param[out] buffer Buffer where to store the contents of the `commit-graph`. - * @param w The writer. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_graph_writer_dump( - git_buf *buffer, - git_commit_graph_writer *w); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/config.h b/vendor/libgit2-sys/libgit2/include/git2/sys/config.h deleted file mode 100644 index cc4a399..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/config.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_config_backend_h__ -#define INCLUDE_sys_git_config_backend_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/config.h" - -/** - * @file git2/sys/config.h - * @brief Custom configuration database backends - * @defgroup git_backend Custom configuration database backends - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * An entry in a configuration backend. This is provided so that - * backend implementors can have a mechanism to free their data. - */ -typedef struct git_config_backend_entry { - /** The base configuration entry */ - struct git_config_entry entry; - - /** - * Free function for this entry; for internal purposes. Callers - * should call `git_config_entry_free` to free data. - */ - void GIT_CALLBACK(free)(struct git_config_backend_entry *entry); -} git_config_backend_entry; - -/** - * Every iterator must have this struct as its first element, so the - * API can talk to it. You'd define your iterator as - * - * struct my_iterator { - * git_config_iterator parent; - * ... - * } - * - * and assign `iter->parent.backend` to your `git_config_backend`. - */ -struct git_config_iterator { - git_config_backend *backend; - unsigned int flags; - - /** - * Return the current entry and advance the iterator. The - * memory belongs to the library. - */ - int GIT_CALLBACK(next)(git_config_backend_entry **entry, git_config_iterator *iter); - - /** - * Free the iterator - */ - void GIT_CALLBACK(free)(git_config_iterator *iter); -}; - -/** - * Generic backend that implements the interface to - * access a configuration file - */ -struct git_config_backend { - unsigned int version; - /** True if this backend is for a snapshot */ - int readonly; - struct git_config *cfg; - - /* Open means open the file/database and parse if necessary */ - int GIT_CALLBACK(open)(struct git_config_backend *, git_config_level_t level, const git_repository *repo); - int GIT_CALLBACK(get)(struct git_config_backend *, const char *key, git_config_backend_entry **entry); - int GIT_CALLBACK(set)(struct git_config_backend *, const char *key, const char *value); - int GIT_CALLBACK(set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value); - int GIT_CALLBACK(del)(struct git_config_backend *, const char *key); - int GIT_CALLBACK(del_multivar)(struct git_config_backend *, const char *key, const char *regexp); - int GIT_CALLBACK(iterator)(git_config_iterator **, struct git_config_backend *); - /** Produce a read-only version of this backend */ - int GIT_CALLBACK(snapshot)(struct git_config_backend **, struct git_config_backend *); - /** - * Lock this backend. - * - * Prevent any writes to the data store backing this - * backend. Any updates must not be visible to any other - * readers. - */ - int GIT_CALLBACK(lock)(struct git_config_backend *); - /** - * Unlock the data store backing this backend. If success is - * true, the changes should be committed, otherwise rolled - * back. - */ - int GIT_CALLBACK(unlock)(struct git_config_backend *, int success); - void GIT_CALLBACK(free)(struct git_config_backend *); -}; - -/** Current version for the `git_config_backend_options` structure */ -#define GIT_CONFIG_BACKEND_VERSION 1 - -/** Static constructor for `git_config_backend_options` */ -#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION} - -/** - * Initializes a `git_config_backend` with default values. Equivalent to - * creating an instance with GIT_CONFIG_BACKEND_INIT. - * - * @param backend the `git_config_backend` struct to initialize. - * @param version Version of struct; pass `GIT_CONFIG_BACKEND_VERSION` - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_config_init_backend( - git_config_backend *backend, - unsigned int version); - -/** - * Add a generic config file instance to an existing config - * - * Note that the configuration object will free the file - * automatically. - * - * Further queries on this config object will access each - * of the config file instances in order (instances with - * a higher priority level will be accessed first). - * - * @param cfg the configuration to add the file to - * @param file the configuration file (backend) to add - * @param level the priority level of the backend - * @param repo optional repository to allow parsing of - * conditional includes - * @param force if a config file already exists for the given - * priority level, replace it - * @return 0 on success, GIT_EEXISTS when adding more than one file - * for a given priority level (and force_replace set to 0), or error code - */ -GIT_EXTERN(int) git_config_add_backend( - git_config *cfg, - git_config_backend *file, - git_config_level_t level, - const git_repository *repo, - int force); - -/** Options for in-memory configuration backends. */ -typedef struct { - unsigned int version; - - /** - * The type of this backend (eg, "command line"). If this is - * NULL, then this will be "in-memory". - */ - const char *backend_type; - - /** - * The path to the origin; if this is NULL then it will be - * left unset in the resulting configuration entries. - */ - const char *origin_path; -} git_config_backend_memory_options; - -/** Current version for the `git_config_backend_memory_options` structure */ -#define GIT_CONFIG_BACKEND_MEMORY_OPTIONS_VERSION 1 - -/** Static constructor for `git_config_backend_memory_options` */ -#define GIT_CONFIG_BACKEND_MEMORY_OPTIONS_INIT { GIT_CONFIG_BACKEND_MEMORY_OPTIONS_VERSION } - - -/** - * Create an in-memory configuration backend from a string in standard - * git configuration file format. - * - * @param out the new backend - * @param cfg the configuration that is to be parsed - * @param len the length of the string pointed to by `cfg` - * @param opts the options to initialize this backend with, or NULL - * @return 0 on success or an error code - */ -extern int git_config_backend_from_string( - git_config_backend **out, - const char *cfg, - size_t len, - git_config_backend_memory_options *opts); - -/** - * Create an in-memory configuration backend from a list of name/value - * pairs. - * - * @param out the new backend - * @param values the configuration values to set (in "key=value" format) - * @param len the length of the values array - * @param opts the options to initialize this backend with, or NULL - * @return 0 on success or an error code - */ -extern int git_config_backend_from_values( - git_config_backend **out, - const char **values, - size_t len, - git_config_backend_memory_options *opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/cred.h b/vendor/libgit2-sys/libgit2/include/git2/sys/cred.h deleted file mode 100644 index 4d2a59a..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/cred.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_cred_h__ -#define INCLUDE_sys_git_cred_h__ - -/* These declarations have moved. */ -#ifndef GIT_DEPRECATE_HARD -# include "git2/sys/credential.h" -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/credential.h b/vendor/libgit2-sys/libgit2/include/git2/sys/credential.h deleted file mode 100644 index 0d573a3..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/credential.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_credential_h__ -#define INCLUDE_sys_git_credential_h__ - -#include "git2/common.h" -#include "git2/credential.h" - -/** - * @file git2/sys/credential.h - * @brief Low-level credentials implementation - * @defgroup git_credential Low-level credentials implementation - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * The base structure for all credential types - */ -struct git_credential { - git_credential_t credtype; /**< A type of credential */ - - /** The deallocator for this type of credentials */ - void GIT_CALLBACK(free)(git_credential *cred); -}; - -/** A plaintext username and password */ -struct git_credential_userpass_plaintext { - git_credential parent; /**< The parent credential */ - char *username; /**< The username to authenticate as */ - char *password; /**< The password to use */ -}; - -/** Username-only credential information */ -struct git_credential_username { - git_credential parent; /**< The parent credential */ - char username[1]; /**< The username to authenticate as */ -}; - -/** - * A ssh key from disk - */ -struct git_credential_ssh_key { - git_credential parent; /**< The parent credential */ - char *username; /**< The username to authenticate as */ - char *publickey; /**< The path to a public key */ - char *privatekey; /**< The path to a private key */ - char *passphrase; /**< Passphrase to decrypt the private key */ -}; - -/** - * Keyboard-interactive based ssh authentication - */ -struct git_credential_ssh_interactive { - git_credential parent; /**< The parent credential */ - char *username; /**< The username to authenticate as */ - - /** - * Callback used for authentication. - */ - git_credential_ssh_interactive_cb prompt_callback; - - void *payload; /**< Payload passed to prompt_callback */ -}; - -/** - * A key with a custom signature function - */ -struct git_credential_ssh_custom { - git_credential parent; /**< The parent credential */ - char *username; /**< The username to authenticate as */ - char *publickey; /**< The public key data */ - size_t publickey_len; /**< Length of the public key */ - - /** - * Callback used to sign the data. - */ - git_credential_sign_cb sign_callback; - - void *payload; /**< Payload passed to prompt_callback */ -}; - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/diff.h b/vendor/libgit2-sys/libgit2/include/git2/sys/diff.h deleted file mode 100644 index a398f54..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/diff.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_diff_h__ -#define INCLUDE_sys_git_diff_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/oid.h" -#include "git2/diff.h" -#include "git2/status.h" - -/** - * @file git2/sys/diff.h - * @brief Low-level diff utilities - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Diff print callback that writes to a git_buf. - * - * This function is provided not for you to call it directly, but instead - * so you can use it as a function pointer to the `git_diff_print` or - * `git_patch_print` APIs. When using those APIs, you specify a callback - * to actually handle the diff and/or patch data. - * - * Use this callback to easily write that data to a `git_buf` buffer. You - * must pass a `git_buf *` value as the payload to the `git_diff_print` - * and/or `git_patch_print` function. The data will be appended to the - * buffer (after any existing content). - * - * @param delta the delta being processed - * @param hunk the hunk being processed - * @param line the line being processed - * @param payload the payload provided by the diff generator - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_diff_print_callback__to_buf( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - const git_diff_line *line, - void *payload); /**< payload must be a `git_buf *` */ - -/** - * Diff print callback that writes to stdio FILE handle. - * - * This function is provided not for you to call it directly, but instead - * so you can use it as a function pointer to the `git_diff_print` or - * `git_patch_print` APIs. When using those APIs, you specify a callback - * to actually handle the diff and/or patch data. - * - * Use this callback to easily write that data to a stdio FILE handle. You - * must pass a `FILE *` value (such as `stdout` or `stderr` or the return - * value from `fopen()`) as the payload to the `git_diff_print` - * and/or `git_patch_print` function. If you pass NULL, this will write - * data to `stdout`. - * - * @param delta the delta being processed - * @param hunk the hunk being processed - * @param line the line being processed - * @param payload the payload provided by the diff generator - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_diff_print_callback__to_file_handle( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - const git_diff_line *line, - void *payload); /**< payload must be a `FILE *` */ - - -/** - * Performance data from diffing - */ -typedef struct { - unsigned int version; - size_t stat_calls; /**< Number of stat() calls performed */ - size_t oid_calculations; /**< Number of ID calculations */ -} git_diff_perfdata; - -/** Current version for the `git_diff_perfdata_options` structure */ -#define GIT_DIFF_PERFDATA_VERSION 1 - -/** Static constructor for `git_diff_perfdata_options` */ -#define GIT_DIFF_PERFDATA_INIT {GIT_DIFF_PERFDATA_VERSION,0,0} - -/** - * Get performance data for a diff object. - * - * @param out Structure to be filled with diff performance data - * @param diff Diff to read performance data from - * @return 0 for success, <0 for error - */ -GIT_EXTERN(int) git_diff_get_perfdata( - git_diff_perfdata *out, const git_diff *diff); - -/** - * Get performance data for diffs from a git_status_list - * - * @param out Structure to be filled with diff performance data - * @param status Diff to read performance data from - * @return 0 for success, <0 for error - */ -GIT_EXTERN(int) git_status_list_get_perfdata( - git_diff_perfdata *out, const git_status_list *status); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/email.h b/vendor/libgit2-sys/libgit2/include/git2/sys/email.h deleted file mode 100644 index 26e792a..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/email.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_email_h__ -#define INCLUDE_sys_git_email_h__ - -#include "git2/common.h" -#include "git2/diff.h" -#include "git2/email.h" -#include "git2/types.h" - -/** - * @file git2/sys/email.h - * @brief Advanced git email creation routines - * @defgroup git_email Advanced git email creation routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create a diff for a commit in mbox format for sending via email. - * - * @param out buffer to store the e-mail patch in - * @param diff the changes to include in the email - * @param patch_idx the patch index - * @param patch_count the total number of patches that will be included - * @param commit_id the commit id for this change - * @param summary the commit message for this change - * @param body optional text to include above the diffstat - * @param author the person who authored this commit - * @param opts email creation options - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_email_create_from_diff( - git_buf *out, - git_diff *diff, - size_t patch_idx, - size_t patch_count, - const git_oid *commit_id, - const char *summary, - const char *body, - const git_signature *author, - const git_email_create_options *opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/errors.h b/vendor/libgit2-sys/libgit2/include/git2/sys/errors.h deleted file mode 100644 index 44e8ecb..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/errors.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_sys_git_errors_h__ -#define INCLUDE_sys_git_errors_h__ - -#include "git2/common.h" - -/** - * @file git2/sys/errors.h - * @brief Advanced error handling - * @ingroup Git - * - * Error handling for advanced consumers; those who use callbacks - * or those who create custom databases. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Clear the last library error that occurred for this thread. - */ -GIT_EXTERN(void) git_error_clear(void); - -/** - * Set the error message string for this thread, using `printf`-style - * formatting. - * - * This function is public so that custom ODB backends and the like can - * relay an error message through libgit2. Most regular users of libgit2 - * will never need to call this function -- actually, calling it in most - * circumstances (for example, calling from within a callback function) - * will just end up having the value overwritten by libgit2 internals. - * - * This error message is stored in thread-local storage and only applies - * to the particular thread that this libgit2 call is made from. - * - * @param error_class One of the `git_error_t` enum above describing the - * general subsystem that is responsible for the error. - * @param fmt The `printf`-style format string; subsequent arguments must - * be the arguments for the format string. - */ -GIT_EXTERN(void) git_error_set(int error_class, const char *fmt, ...) - GIT_FORMAT_PRINTF(2, 3); - -/** - * Set the error message string for this thread. This function is like - * `git_error_set` but takes a static string instead of a `printf`-style - * format. - * - * @param error_class One of the `git_error_t` enum above describing the - * general subsystem that is responsible for the error. - * @param string The error message to keep - * @return 0 on success or -1 on failure - */ -GIT_EXTERN(int) git_error_set_str(int error_class, const char *string); - -/** - * Set the error message to a special value for memory allocation failure. - * - * The normal `git_error_set_str()` function attempts to `strdup()` the - * string that is passed in. This is not a good idea when the error in - * question is a memory allocation failure. That circumstance has a - * special setter function that sets the error string to a known and - * statically allocated internal value. - */ -GIT_EXTERN(void) git_error_set_oom(void); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/filter.h b/vendor/libgit2-sys/libgit2/include/git2/sys/filter.h deleted file mode 100644 index 60466d1..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/filter.h +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_filter_h__ -#define INCLUDE_sys_git_filter_h__ - -#include "git2/filter.h" - -/** - * @file git2/sys/filter.h - * @brief Custom filter backends and plugins - * @defgroup git_backend Custom filter backends and plugins - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Look up a filter by name - * - * @param name The name of the filter - * @return Pointer to the filter object or NULL if not found - */ -GIT_EXTERN(git_filter *) git_filter_lookup(const char *name); - -/** The "crlf" filter */ -#define GIT_FILTER_CRLF "crlf" - -/** The "ident" filter */ -#define GIT_FILTER_IDENT "ident" - -/** - * This is priority that the internal CRLF filter will be registered with - */ -#define GIT_FILTER_CRLF_PRIORITY 0 - -/** - * This is priority that the internal ident filter will be registered with - */ -#define GIT_FILTER_IDENT_PRIORITY 100 - -/** - * This is priority to use with a custom filter to imitate a core Git - * filter driver, so that it will be run last on checkout and first on - * checkin. You do not have to use this, but it helps compatibility. - */ -#define GIT_FILTER_DRIVER_PRIORITY 200 - -/** - * Create a new empty filter list - * - * Normally you won't use this because `git_filter_list_load` will create - * the filter list for you, but you can use this in combination with the - * `git_filter_lookup` and `git_filter_list_push` functions to assemble - * your own chains of filters. - * - * @param out the filter list - * @param repo the repository to use for configuration - * @param mode the filter mode (direction) - * @param options the options - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_filter_list_new( - git_filter_list **out, - git_repository *repo, - git_filter_mode_t mode, - uint32_t options); - -/** - * Add a filter to a filter list with the given payload. - * - * Normally you won't have to do this because the filter list is created - * by calling the "check" function on registered filters when the filter - * attributes are set, but this does allow more direct manipulation of - * filter lists when desired. - * - * Note that normally the "check" function can set up a payload for the - * filter. Using this function, you can either pass in a payload if you - * know the expected payload format, or you can pass NULL. Some filters - * may fail with a NULL payload. Good luck! - * - * @param fl the filter list - * @param filter the filter to push - * @param payload the payload for the filter - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_filter_list_push( - git_filter_list *fl, git_filter *filter, void *payload); - -/** - * Look up how many filters are in the list - * - * We will attempt to apply all of these filters to any data passed in, - * but note that the filter apply action still has the option of skipping - * data that is passed in (for example, the CRLF filter will skip data - * that appears to be binary). - * - * @param fl A filter list - * @return The number of filters in the list - */ -GIT_EXTERN(size_t) git_filter_list_length(const git_filter_list *fl); - -/** - * A filter source represents a file/blob to be processed - */ -typedef struct git_filter_source git_filter_source; - -/** - * Get the repository that the source data is coming from. - * - * @param src the filter source - * @return the repository for the filter information - */ -GIT_EXTERN(git_repository *) git_filter_source_repo(const git_filter_source *src); - -/** - * Get the path that the source data is coming from. - * - * @param src the filter source - * @return the path that is being filtered - */ -GIT_EXTERN(const char *) git_filter_source_path(const git_filter_source *src); - -/** - * Get the file mode of the source file - * If the mode is unknown, this will return 0 - * - * @param src the filter source - * @return the file mode for the file being filtered - */ -GIT_EXTERN(uint16_t) git_filter_source_filemode(const git_filter_source *src); - -/** - * Get the OID of the source - * If the OID is unknown (often the case with GIT_FILTER_CLEAN) then - * this will return NULL. - * - * @param src the filter source - * @return the object id of the file being filtered - */ -GIT_EXTERN(const git_oid *) git_filter_source_id(const git_filter_source *src); - -/** - * Get the git_filter_mode_t to be used - * - * @param src the filter source - * @return the mode (direction) of the filter - */ -GIT_EXTERN(git_filter_mode_t) git_filter_source_mode(const git_filter_source *src); - -/** - * Get the combination git_filter_flag_t options to be applied - * - * @param src the filter source - * @return the flags of the filter - */ -GIT_EXTERN(uint32_t) git_filter_source_flags(const git_filter_source *src); - -/** - * Initialize callback on filter - * - * Specified as `filter.initialize`, this is an optional callback invoked - * before a filter is first used. It will be called once at most. - * - * If non-NULL, the filter's `initialize` callback will be invoked right - * before the first use of the filter, so you can defer expensive - * initialization operations (in case libgit2 is being used in a way that - * doesn't need the filter). - * - * @param self the filter to initialize - * @return 0 on success, negative number on failure - */ -typedef int GIT_CALLBACK(git_filter_init_fn)(git_filter *self); - -/** - * Shutdown callback on filter - * - * Specified as `filter.shutdown`, this is an optional callback invoked - * when the filter is unregistered or when libgit2 is shutting down. It - * will be called once at most and should release resources as needed. - * This may be called even if the `initialize` callback was not made. - * - * Typically this function will free the `git_filter` object itself. - * - * @param self the filter to shutdown - */ -typedef void GIT_CALLBACK(git_filter_shutdown_fn)(git_filter *self); - -/** - * Callback to decide if a given source needs this filter - * - * Specified as `filter.check`, this is an optional callback that checks - * if filtering is needed for a given source. - * - * It should return 0 if the filter should be applied (i.e. success), - * GIT_PASSTHROUGH if the filter should not be applied, or an error code - * to fail out of the filter processing pipeline and return to the caller. - * - * The `attr_values` will be set to the values of any attributes given in - * the filter definition. See `git_filter` below for more detail. - * - * The `payload` will be a pointer to a reference payload for the filter. - * This will start as NULL, but `check` can assign to this pointer for - * later use by the `stream` callback. Note that the value should be heap - * allocated (not stack), so that it doesn't go away before the `stream` - * callback can use it. If a filter allocates and assigns a value to the - * `payload`, it will need a `cleanup` callback to free the payload. - * - * @param self the filter check - * @param payload a data for future filter functions - * @param src the filter source - * @param attr_values the attribute values - * @return 0 on success or a negative value on error - */ -typedef int GIT_CALLBACK(git_filter_check_fn)( - git_filter *self, - void **payload, /* NULL on entry, may be set */ - const git_filter_source *src, - const char **attr_values); - -#ifndef GIT_DEPRECATE_HARD -/** - * Callback to actually perform the data filtering - * - * Specified as `filter.apply`, this is the callback that actually filters - * data. If it successfully writes the output, it should return 0. Like - * `check`, it can return GIT_PASSTHROUGH to indicate that the filter - * doesn't want to run. Other error codes will stop filter processing and - * return to the caller. - * - * The `payload` value will refer to any payload that was set by the - * `check` callback. It may be read from or written to as needed. - * - * @param self the filter check - * @param payload a data for future filter functions - * @param to the input buffer - * @param from the output buffer - * @param src the filter source - * @return 0 on success or a negative value on error - * @deprecated use git_filter_stream_fn - */ -typedef int GIT_CALLBACK(git_filter_apply_fn)( - git_filter *self, - void **payload, /* may be read and/or set */ - git_buf *to, - const git_buf *from, - const git_filter_source *src); -#endif - -/** - * Callback to perform the data filtering. - * - * Specified as `filter.stream`, this is a callback that filters data - * in a streaming manner. This function will provide a - * `git_writestream` that will the original data will be written to; - * with that data, the `git_writestream` will then perform the filter - * translation and stream the filtered data out to the `next` location. - * - * @param out the write stream - * @param self the filter - * @param payload a data for future filter functions - * @param src the filter source - * @param next the output stream - * @return 0 on success or a negative value on error - */ -typedef int GIT_CALLBACK(git_filter_stream_fn)( - git_writestream **out, - git_filter *self, - void **payload, - const git_filter_source *src, - git_writestream *next); - -/** - * Callback to clean up after filtering has been applied - * - * Specified as `filter.cleanup`, this is an optional callback invoked - * after the filter has been applied. If the `check`, `apply`, or - * `stream` callbacks allocated a `payload` to keep per-source filter - * state, use this callback to free that payload and release resources - * as required. - * - * @param self the filter - * @param payload a data for future filter functions - */ -typedef void GIT_CALLBACK(git_filter_cleanup_fn)( - git_filter *self, - void *payload); - -/** - * Filter structure used to register custom filters. - * - * To associate extra data with a filter, allocate extra data and put the - * `git_filter` struct at the start of your data buffer, then cast the - * `self` pointer to your larger structure when your callback is invoked. - */ -struct git_filter { - /** The `version` field should be set to `GIT_FILTER_VERSION`. */ - unsigned int version; - - /** - * A whitespace-separated list of attribute names to check for this - * filter (e.g. "eol crlf text"). If the attribute name is bare, it - * will be simply loaded and passed to the `check` callback. If it - * has a value (i.e. "name=value"), the attribute must match that - * value for the filter to be applied. The value may be a wildcard - * (eg, "name=*"), in which case the filter will be invoked for any - * value for the given attribute name. See the attribute parameter - * of the `check` callback for the attribute value that was specified. - */ - const char *attributes; - - /** Called when the filter is first used for any file. */ - git_filter_init_fn initialize; - - /** Called when the filter is removed or unregistered from the system. */ - git_filter_shutdown_fn shutdown; - - /** - * Called to determine whether the filter should be invoked for a - * given file. If this function returns `GIT_PASSTHROUGH` then the - * `stream` or `apply` functions will not be invoked and the - * contents will be passed through unmodified. - */ - git_filter_check_fn check; - -#ifdef GIT_DEPRECATE_HARD - void *reserved; -#else - /** - * Provided for backward compatibility; this will apply the - * filter to the given contents in a `git_buf`. Callers should - * provide a `stream` function instead. - */ - git_filter_apply_fn apply; -#endif - - /** - * Called to apply the filter, this function will provide a - * `git_writestream` that will the original data will be - * written to; with that data, the `git_writestream` will then - * perform the filter translation and stream the filtered data - * out to the `next` location. - */ - git_filter_stream_fn stream; - - /** Called when the system is done filtering for a file. */ - git_filter_cleanup_fn cleanup; -}; - -/** Current version for the `git_filter_options` structure */ -#define GIT_FILTER_VERSION 1 - -/** Static constructor for `git_filter_options` */ -#define GIT_FILTER_INIT {GIT_FILTER_VERSION} - -/** - * Initializes a `git_filter` with default values. Equivalent to - * creating an instance with GIT_FILTER_INIT. - * - * @param filter the `git_filter` struct to initialize. - * @param version Version the struct; pass `GIT_FILTER_VERSION` - * @return 0 on success; -1 on failure. - */ -GIT_EXTERN(int) git_filter_init(git_filter *filter, unsigned int version); - -/** - * Register a filter under a given name with a given priority. - * - * As mentioned elsewhere, the initialize callback will not be invoked - * immediately. It is deferred until the filter is used in some way. - * - * A filter's attribute checks and `check` and `stream` (or `apply`) - * callbacks will be issued in order of `priority` on smudge (to - * workdir), and in reverse order of `priority` on clean (to odb). - * - * Two filters are preregistered with libgit2: - * - GIT_FILTER_CRLF with priority 0 - * - GIT_FILTER_IDENT with priority 100 - * - * Currently the filter registry is not thread safe, so any registering or - * deregistering of filters must be done outside of any possible usage of - * the filters (i.e. during application setup or shutdown). - * - * @param name A name by which the filter can be referenced. Attempting - * to register with an in-use name will return GIT_EEXISTS. - * @param filter The filter definition. This pointer will be stored as is - * by libgit2 so it must be a durable allocation (either static - * or on the heap). - * @param priority The priority for filter application - * @return 0 on successful registry, error code <0 on failure - */ -GIT_EXTERN(int) git_filter_register( - const char *name, git_filter *filter, int priority); - -/** - * Remove the filter with the given name - * - * Attempting to remove the builtin libgit2 filters is not permitted and - * will return an error. - * - * Currently the filter registry is not thread safe, so any registering or - * deregistering of filters must be done outside of any possible usage of - * the filters (i.e. during application setup or shutdown). - * - * @param name The name under which the filter was registered - * @return 0 on success, error code <0 on failure - */ -GIT_EXTERN(int) git_filter_unregister(const char *name); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/hashsig.h b/vendor/libgit2-sys/libgit2/include/git2/sys/hashsig.h deleted file mode 100644 index 0d7be53..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/hashsig.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_hashsig_h__ -#define INCLUDE_sys_hashsig_h__ - -#include "git2/common.h" - -/** - * @file git2/sys/hashsig.h - * @brief Signatures for file similarity comparison - * @defgroup git_hashsig Git merge routines - * @ingroup Git - * - * Hash signatures are used for file similary comparison; this is - * used for git's rename handling. - * @{ - */ -GIT_BEGIN_DECL - -/** - * Similarity signature of arbitrary text content based on line hashes - */ -typedef struct git_hashsig git_hashsig; - -/** - * Options for hashsig computation - * - * The options GIT_HASHSIG_NORMAL, GIT_HASHSIG_IGNORE_WHITESPACE, - * GIT_HASHSIG_SMART_WHITESPACE are exclusive and should not be combined. - */ -typedef enum { - /** - * Use all data - */ - GIT_HASHSIG_NORMAL = 0, - - /** - * Ignore whitespace - */ - GIT_HASHSIG_IGNORE_WHITESPACE = (1 << 0), - - /** - * Ignore \r and all space after \n - */ - GIT_HASHSIG_SMART_WHITESPACE = (1 << 1), - - /** - * Allow hashing of small files - */ - GIT_HASHSIG_ALLOW_SMALL_FILES = (1 << 2) -} git_hashsig_option_t; - -/** - * Compute a similarity signature for a text buffer - * - * If you have passed the option GIT_HASHSIG_IGNORE_WHITESPACE, then the - * whitespace will be removed from the buffer while it is being processed, - * modifying the buffer in place. Sorry about that! - * - * @param out The computed similarity signature. - * @param buf The input buffer. - * @param buflen The input buffer size. - * @param opts The signature computation options (see above). - * @return 0 on success, GIT_EBUFS if the buffer doesn't contain enough data to - * compute a valid signature (unless GIT_HASHSIG_ALLOW_SMALL_FILES is set), or - * error code. - */ -GIT_EXTERN(int) git_hashsig_create( - git_hashsig **out, - const char *buf, - size_t buflen, - git_hashsig_option_t opts); - -/** - * Compute a similarity signature for a text file - * - * This walks through the file, only loading a maximum of 4K of file data at - * a time. Otherwise, it acts just like `git_hashsig_create`. - * - * @param out The computed similarity signature. - * @param path The path to the input file. - * @param opts The signature computation options (see above). - * @return 0 on success, GIT_EBUFS if the buffer doesn't contain enough data to - * compute a valid signature (unless GIT_HASHSIG_ALLOW_SMALL_FILES is set), or - * error code. - */ -GIT_EXTERN(int) git_hashsig_create_fromfile( - git_hashsig **out, - const char *path, - git_hashsig_option_t opts); - -/** - * Release memory for a content similarity signature - * - * @param sig The similarity signature to free. - */ -GIT_EXTERN(void) git_hashsig_free(git_hashsig *sig); - -/** - * Measure similarity score between two similarity signatures - * - * @param a The first similarity signature to compare. - * @param b The second similarity signature to compare. - * @return [0 to 100] on success as the similarity score, or error code. - */ -GIT_EXTERN(int) git_hashsig_compare( - const git_hashsig *a, - const git_hashsig *b); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/index.h b/vendor/libgit2-sys/libgit2/include/git2/sys/index.h deleted file mode 100644 index b3b86a0..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/index.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_index_h__ -#define INCLUDE_sys_git_index_h__ - -#include "git2/common.h" -#include "git2/types.h" - -/** - * @file git2/sys/index.h - * @brief Low-level index manipulation routines - * @defgroup git_index Low-level index manipulation routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Representation of a rename conflict entry in the index. */ -typedef struct git_index_name_entry { - char *ancestor; - char *ours; - char *theirs; -} git_index_name_entry; - -/** Representation of a resolve undo entry in the index. */ -typedef struct git_index_reuc_entry { - uint32_t mode[3]; - git_oid oid[3]; - char *path; -} git_index_reuc_entry; - -/** @name Conflict Name entry functions - * - * These functions work on rename conflict entries. - */ -/**@{*/ - -/** - * Get the count of filename conflict entries currently in the index. - * - * @param index an existing index object - * @return integer of count of current filename conflict entries - */ -GIT_EXTERN(size_t) git_index_name_entrycount(git_index *index); - -/** - * Get a filename conflict entry from the index. - * - * The returned entry is read-only and should not be modified - * or freed by the caller. - * - * @param index an existing index object - * @param n the position of the entry - * @return a pointer to the filename conflict entry; NULL if out of bounds - */ -GIT_EXTERN(const git_index_name_entry *) git_index_name_get_byindex( - git_index *index, size_t n); - -/** - * Record the filenames involved in a rename conflict. - * - * @param index an existing index object - * @param ancestor the path of the file as it existed in the ancestor - * @param ours the path of the file as it existed in our tree - * @param theirs the path of the file as it existed in their tree - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_index_name_add(git_index *index, - const char *ancestor, const char *ours, const char *theirs); - -/** - * Remove all filename conflict entries. - * - * @param index an existing index object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_name_clear(git_index *index); - -/**@}*/ - -/** @name Resolve Undo (REUC) index entry manipulation. - * - * These functions work on the Resolve Undo index extension and contains - * data about the original files that led to a merge conflict. - */ -/**@{*/ - -/** - * Get the count of resolve undo entries currently in the index. - * - * @param index an existing index object - * @return integer of count of current resolve undo entries - */ -GIT_EXTERN(size_t) git_index_reuc_entrycount(git_index *index); - -/** - * Finds the resolve undo entry that points to the given path in the Git - * index. - * - * @param at_pos the address to which the position of the reuc entry is written (optional) - * @param index an existing index object - * @param path path to search - * @return 0 if found, < 0 otherwise (GIT_ENOTFOUND) - */ -GIT_EXTERN(int) git_index_reuc_find(size_t *at_pos, git_index *index, const char *path); - -/** - * Get a resolve undo entry from the index. - * - * The returned entry is read-only and should not be modified - * or freed by the caller. - * - * @param index an existing index object - * @param path path to search - * @return the resolve undo entry; NULL if not found - */ -GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *index, const char *path); - -/** - * Get a resolve undo entry from the index. - * - * The returned entry is read-only and should not be modified - * or freed by the caller. - * - * @param index an existing index object - * @param n the position of the entry - * @return a pointer to the resolve undo entry; NULL if out of bounds - */ -GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *index, size_t n); - -/** - * Adds a resolve undo entry for a file based on the given parameters. - * - * The resolve undo entry contains the OIDs of files that were involved - * in a merge conflict after the conflict has been resolved. This allows - * conflicts to be re-resolved later. - * - * If there exists a resolve undo entry for the given path in the index, - * it will be removed. - * - * This method will fail in bare index instances. - * - * @param index an existing index object - * @param path filename to add - * @param ancestor_mode mode of the ancestor file - * @param ancestor_id oid of the ancestor file - * @param our_mode mode of our file - * @param our_id oid of our file - * @param their_mode mode of their file - * @param their_id oid of their file - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_reuc_add(git_index *index, const char *path, - int ancestor_mode, const git_oid *ancestor_id, - int our_mode, const git_oid *our_id, - int their_mode, const git_oid *their_id); - -/** - * Remove an resolve undo entry from the index - * - * @param index an existing index object - * @param n position of the resolve undo entry to remove - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n); - -/** - * Remove all resolve undo entries from the index - * - * @param index an existing index object - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_reuc_clear(git_index *index); - -/**@}*/ - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/mempack.h b/vendor/libgit2-sys/libgit2/include/git2/sys/mempack.h deleted file mode 100644 index be902be..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/mempack.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_odb_mempack_h__ -#define INCLUDE_sys_git_odb_mempack_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/oid.h" -#include "git2/odb.h" -#include "git2/buffer.h" - -/** - * @file git2/sys/mempack.h - * @brief A custom object database backend for storing objects in-memory - * @defgroup git_mempack A custom object database backend for storing objects in-memory - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Instantiate a new mempack backend. - * - * The backend must be added to an existing ODB with the highest - * priority. - * - * git_mempack_new(&mempacker); - * git_repository_odb(&odb, repository); - * git_odb_add_backend(odb, mempacker, 999); - * - * Once the backend has been loaded, all writes to the ODB will - * instead be queued in memory, and can be finalized with - * `git_mempack_dump`. - * - * Subsequent reads will also be served from the in-memory store - * to ensure consistency, until the memory store is dumped. - * - * @param out Pointer where to store the ODB backend - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_mempack_new(git_odb_backend **out); - -/** - * Write a thin packfile with the objects in the memory store. - * - * A thin packfile is a packfile that does not contain its transitive closure of - * references. This is useful for efficiently distributing additions to a - * repository over the network, but also finds use in the efficient bulk - * addition of objects to a repository, locally. - * - * This operation performs the (shallow) insert operations into the - * `git_packbuilder`, but does not write the packfile to disk; - * see `git_packbuilder_write_buf`. - * - * It also does not reset the in-memory object database; see `git_mempack_reset`. - * - * @param backend The mempack backend - * @param pb The packbuilder to use to write the packfile - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_mempack_write_thin_pack(git_odb_backend *backend, git_packbuilder *pb); - -/** - * Dump all the queued in-memory writes to a packfile. - * - * The contents of the packfile will be stored in the given buffer. - * It is the caller's responsibility to ensure that the generated - * packfile is available to the repository (e.g. by writing it - * to disk, or doing something crazy like distributing it across - * several copies of the repository over a network). - * - * Once the generated packfile is available to the repository, - * call `git_mempack_reset` to cleanup the memory store. - * - * Calling `git_mempack_reset` before the packfile has been - * written to disk will result in an inconsistent repository - * (the objects in the memory store won't be accessible). - * - * @param pack Buffer where to store the raw packfile - * @param repo The active repository where the backend is loaded - * @param backend The mempack backend - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *backend); - -/** - * Reset the memory packer by clearing all the queued objects. - * - * This assumes that `git_mempack_dump` has been called before to - * store all the queued objects into a single packfile. - * - * Alternatively, call `reset` without a previous dump to "undo" - * all the recently written objects, giving transaction-like - * semantics to the Git repository. - * - * @param backend The mempack backend - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_mempack_reset(git_odb_backend *backend); - -/** - * Get the total number of objects in mempack - * - * @param count The count of objects in the mempack - * @param backend The mempack backend - * @return 0 on success, or -1 on error - */ -GIT_EXTERN(int) git_mempack_object_count(size_t *count, git_odb_backend *backend); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/merge.h b/vendor/libgit2-sys/libgit2/include/git2/sys/merge.h deleted file mode 100644 index a9f5220..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/merge.h +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_merge_h__ -#define INCLUDE_sys_git_merge_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/index.h" -#include "git2/merge.h" - -/** - * @file git2/sys/merge.h - * @brief Custom merge drivers - * @defgroup git_merge Custom merge drivers - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * A "merge driver" is a mechanism that can be configured to handle - * conflict resolution for files changed in both the "ours" and "theirs" - * side of a merge. - */ -typedef struct git_merge_driver git_merge_driver; - -/** - * Look up a merge driver by name - * - * @param name The name of the merge driver - * @return Pointer to the merge driver object or NULL if not found - */ -GIT_EXTERN(git_merge_driver *) git_merge_driver_lookup(const char *name); - -/** The "text" merge driver */ -#define GIT_MERGE_DRIVER_TEXT "text" -/** The "binary" merge driver */ -#define GIT_MERGE_DRIVER_BINARY "binary" -/** The "union" merge driver */ -#define GIT_MERGE_DRIVER_UNION "union" - -/** - * A merge driver source represents the file to be merged - */ -typedef struct git_merge_driver_source git_merge_driver_source; - -/** - * Get the repository that the source data is coming from. - * - * @param src the merge driver source - * @return the repository - */ -GIT_EXTERN(git_repository *) git_merge_driver_source_repo( - const git_merge_driver_source *src); - -/** - * Gets the ancestor of the file to merge. - * - * @param src the merge driver source - * @return the ancestor or NULL if there was no ancestor - */ -GIT_EXTERN(const git_index_entry *) git_merge_driver_source_ancestor( - const git_merge_driver_source *src); - -/** - * Gets the ours side of the file to merge. - * - * @param src the merge driver source - * @return the ours side or NULL if there was no ours side - */ -GIT_EXTERN(const git_index_entry *) git_merge_driver_source_ours( - const git_merge_driver_source *src); - -/** - * Gets the theirs side of the file to merge. - * - * @param src the merge driver source - * @return the theirs side or NULL if there was no theirs side - */ -GIT_EXTERN(const git_index_entry *) git_merge_driver_source_theirs( - const git_merge_driver_source *src); - -/** - * Gets the merge file options that the merge was invoked with. - * - * @param src the merge driver source - * @return the options - */ -GIT_EXTERN(const git_merge_file_options *) git_merge_driver_source_file_options( - const git_merge_driver_source *src); - - -/** - * Initialize callback on merge driver - * - * Specified as `driver.initialize`, this is an optional callback invoked - * before a merge driver is first used. It will be called once at most - * per library lifetime. - * - * If non-NULL, the merge driver's `initialize` callback will be invoked - * right before the first use of the driver, so you can defer expensive - * initialization operations (in case libgit2 is being used in a way that - * doesn't need the merge driver). - * - * @param self the merge driver to initialize - * @return 0 on success, or a negative number on failure - */ -typedef int GIT_CALLBACK(git_merge_driver_init_fn)(git_merge_driver *self); - -/** - * Shutdown callback on merge driver - * - * Specified as `driver.shutdown`, this is an optional callback invoked - * when the merge driver is unregistered or when libgit2 is shutting down. - * It will be called once at most and should release resources as needed. - * This may be called even if the `initialize` callback was not made. - * - * Typically this function will free the `git_merge_driver` object itself. - * - * @param self the merge driver to shutdown - */ -typedef void GIT_CALLBACK(git_merge_driver_shutdown_fn)(git_merge_driver *self); - -/** - * Callback to perform the merge. - * - * Specified as `driver.apply`, this is the callback that actually does the - * merge. If it can successfully perform a merge, it should populate - * `path_out` with a pointer to the filename to accept, `mode_out` with - * the resultant mode, and `merged_out` with the buffer of the merged file - * and then return 0. If the driver returns `GIT_PASSTHROUGH`, then the - * default merge driver should instead be run. It can also return - * `GIT_EMERGECONFLICT` if the driver is not able to produce a merge result, - * and the file will remain conflicted. Any other errors will fail and - * return to the caller. - * - * The `filter_name` contains the name of the filter that was invoked, as - * specified by the file's attributes. - * - * The `src` contains the data about the file to be merged. - * - * @param self the merge driver - * @param path_out the resolved path - * @param mode_out the resolved mode - * @param merged_out the merged output contents - * @param filter_name the filter that was invoked - * @param src the data about the unmerged file - * @return 0 on success, or an error code - */ -typedef int GIT_CALLBACK(git_merge_driver_apply_fn)( - git_merge_driver *self, - const char **path_out, - uint32_t *mode_out, - git_buf *merged_out, - const char *filter_name, - const git_merge_driver_source *src); - -/** - * Merge driver structure used to register custom merge drivers. - * - * To associate extra data with a driver, allocate extra data and put the - * `git_merge_driver` struct at the start of your data buffer, then cast - * the `self` pointer to your larger structure when your callback is invoked. - */ -struct git_merge_driver { - /** The `version` should be set to `GIT_MERGE_DRIVER_VERSION`. */ - unsigned int version; - - /** Called when the merge driver is first used for any file. */ - git_merge_driver_init_fn initialize; - - /** Called when the merge driver is unregistered from the system. */ - git_merge_driver_shutdown_fn shutdown; - - /** - * Called to merge the contents of a conflict. If this function - * returns `GIT_PASSTHROUGH` then the default (`text`) merge driver - * will instead be invoked. If this function returns - * `GIT_EMERGECONFLICT` then the file will remain conflicted. - */ - git_merge_driver_apply_fn apply; -}; - -/** The version for the `git_merge_driver` */ -#define GIT_MERGE_DRIVER_VERSION 1 - -/** - * Register a merge driver under a given name. - * - * As mentioned elsewhere, the initialize callback will not be invoked - * immediately. It is deferred until the driver is used in some way. - * - * Currently the merge driver registry is not thread safe, so any - * registering or deregistering of merge drivers must be done outside of - * any possible usage of the drivers (i.e. during application setup or - * shutdown). - * - * @param name The name of this driver to match an attribute. Attempting - * to register with an in-use name will return GIT_EEXISTS. - * @param driver The merge driver definition. This pointer will be stored - * as is by libgit2 so it must be a durable allocation (either - * static or on the heap). - * @return 0 on successful registry, error code <0 on failure - */ -GIT_EXTERN(int) git_merge_driver_register( - const char *name, git_merge_driver *driver); - -/** - * Remove the merge driver with the given name. - * - * Attempting to remove the builtin libgit2 merge drivers is not permitted - * and will return an error. - * - * Currently the merge driver registry is not thread safe, so any - * registering or deregistering of drivers must be done outside of any - * possible usage of the drivers (i.e. during application setup or shutdown). - * - * @param name The name under which the merge driver was registered - * @return 0 on success, error code <0 on failure - */ -GIT_EXTERN(int) git_merge_driver_unregister(const char *name); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/midx.h b/vendor/libgit2-sys/libgit2/include/git2/sys/midx.h deleted file mode 100644 index b3a68af..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/midx.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_midx_h__ -#define INCLUDE_sys_git_midx_h__ - -#include "git2/common.h" -#include "git2/types.h" - -/** - * @file git2/sys/midx.h - * @brief Incremental multi-pack indexes - * @defgroup git_midx Incremental multi-pack indexes - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Options structure for `git_midx_writer_options`. - * - * Initialize with `GIT_MIDX_WRITER_OPTIONS_INIT`. Alternatively, - * you can use `git_midx_writer_options_init`. - */ -typedef struct { - unsigned int version; - -#ifdef GIT_EXPERIMENTAL_SHA256 - /** The object ID type that this commit graph contains. */ - git_oid_t oid_type; -#endif -} git_midx_writer_options; - -/** Current version for the `git_midx_writer_options` structure */ -#define GIT_MIDX_WRITER_OPTIONS_VERSION 1 - -/** Static constructor for `git_midx_writer_options` */ -#define GIT_MIDX_WRITER_OPTIONS_INIT { \ - GIT_MIDX_WRITER_OPTIONS_VERSION \ - } - -/** - * Initialize git_midx_writer_options structure - * - * Initializes a `git_midx_writer_options` with default values. - * Equivalent to creating an instance with - * `GIT_MIDX_WRITER_OPTIONS_INIT`. - * - * @param opts The `git_midx_writer_options` struct to initialize. - * @param version The struct version; pass `GIT_MIDX_WRITER_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_midx_writer_options_init( - git_midx_writer_options *opts, - unsigned int version); - -/** - * Create a new writer for `multi-pack-index` files. - * - * @param out location to store the writer pointer. - * @param pack_dir the directory where the `.pack` and `.idx` files are. The - * `multi-pack-index` file will be written in this directory, too. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_midx_writer_new( - git_midx_writer **out, - const char *pack_dir -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_midx_writer_options *options -#endif - ); - -/** - * Free the multi-pack-index writer and its resources. - * - * @param w the writer to free. If NULL no action is taken. - */ -GIT_EXTERN(void) git_midx_writer_free(git_midx_writer *w); - -/** - * Add an `.idx` file to the writer. - * - * @param w the writer - * @param idx_path the path of an `.idx` file. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_midx_writer_add( - git_midx_writer *w, - const char *idx_path); - -/** - * Write a `multi-pack-index` file to a file. - * - * @param w the writer - * @return 0 or an error code - */ -GIT_EXTERN(int) git_midx_writer_commit( - git_midx_writer *w); - -/** - * Dump the contents of the `multi-pack-index` to an in-memory buffer. - * - * @param midx Buffer where to store the contents of the `multi-pack-index`. - * @param w the writer - * @return 0 or an error code - */ -GIT_EXTERN(int) git_midx_writer_dump( - git_buf *midx, - git_midx_writer *w); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/odb_backend.h b/vendor/libgit2-sys/libgit2/include/git2/sys/odb_backend.h deleted file mode 100644 index 53d8d06..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/odb_backend.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_odb_backend_h__ -#define INCLUDE_sys_git_odb_backend_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/oid.h" -#include "git2/odb.h" - -/** - * @file git2/sys/odb_backend.h - * @brief Object database backends for custom object storage - * @defgroup git_backend Object database backends for custom object storage - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * An instance for a custom backend - */ -struct git_odb_backend { - unsigned int version; - git_odb *odb; - - /* read and read_prefix each return to libgit2 a buffer which - * will be freed later. The buffer should be allocated using - * the function git_odb_backend_data_alloc to ensure that libgit2 - * can safely free it later. */ - int GIT_CALLBACK(read)( - void **, size_t *, git_object_t *, git_odb_backend *, const git_oid *); - - /* To find a unique object given a prefix of its oid. The oid given - * must be so that the remaining (GIT_OID_SHA1_HEXSIZE - len)*4 bits are 0s. - */ - int GIT_CALLBACK(read_prefix)( - git_oid *, void **, size_t *, git_object_t *, - git_odb_backend *, const git_oid *, size_t); - - int GIT_CALLBACK(read_header)( - size_t *, git_object_t *, git_odb_backend *, const git_oid *); - - /** - * Write an object into the backend. The id of the object has - * already been calculated and is passed in. - */ - int GIT_CALLBACK(write)( - git_odb_backend *, const git_oid *, const void *, size_t, git_object_t); - - int GIT_CALLBACK(writestream)( - git_odb_stream **, git_odb_backend *, git_object_size_t, git_object_t); - - int GIT_CALLBACK(readstream)( - git_odb_stream **, size_t *, git_object_t *, - git_odb_backend *, const git_oid *); - - int GIT_CALLBACK(exists)( - git_odb_backend *, const git_oid *); - - int GIT_CALLBACK(exists_prefix)( - git_oid *, git_odb_backend *, const git_oid *, size_t); - - /** - * If the backend implements a refreshing mechanism, it should be exposed - * through this endpoint. Each call to `git_odb_refresh()` will invoke it. - * - * The odb layer will automatically call this when needed on failed - * lookups (ie. `exists()`, `read()`, `read_header()`). - */ - int GIT_CALLBACK(refresh)(git_odb_backend *); - - int GIT_CALLBACK(foreach)( - git_odb_backend *, git_odb_foreach_cb cb, void *payload); - - int GIT_CALLBACK(writepack)( - git_odb_writepack **, git_odb_backend *, git_odb *odb, - git_indexer_progress_cb progress_cb, void *progress_payload); - - /** - * If the backend supports pack files, this will create a - * `multi-pack-index` file which will contain an index of all objects - * across all the `.pack` files. - */ - int GIT_CALLBACK(writemidx)(git_odb_backend *); - - /** - * "Freshens" an already existing object, updating its last-used - * time. This occurs when `git_odb_write` was called, but the - * object already existed (and will not be re-written). The - * underlying implementation may want to update last-used timestamps. - * - * If callers implement this, they should return `0` if the object - * exists and was freshened, and non-zero otherwise. - */ - int GIT_CALLBACK(freshen)(git_odb_backend *, const git_oid *); - - /** - * Frees any resources held by the odb (including the `git_odb_backend` - * itself). An odb backend implementation must provide this function. - */ - void GIT_CALLBACK(free)(git_odb_backend *); -}; - -/** Current version for the `git_odb_backend_options` structure */ -#define GIT_ODB_BACKEND_VERSION 1 - -/** Static constructor for `git_odb_backend_options` */ -#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION} - -/** - * Initializes a `git_odb_backend` with default values. Equivalent to - * creating an instance with GIT_ODB_BACKEND_INIT. - * - * @param backend the `git_odb_backend` struct to initialize. - * @param version Version the struct; pass `GIT_ODB_BACKEND_VERSION` - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_odb_init_backend( - git_odb_backend *backend, - unsigned int version); - -/** - * Allocate data for an ODB object. Custom ODB backends may use this - * to provide data back to the ODB from their read function. This - * memory should not be freed once it is returned to libgit2. If a - * custom ODB uses this function but encounters an error and does not - * return this data to libgit2, then they should use the corresponding - * git_odb_backend_data_free function. - * - * @param backend the ODB backend that is allocating this memory - * @param len the number of bytes to allocate - * @return the allocated buffer on success or NULL if out of memory - */ -GIT_EXTERN(void *) git_odb_backend_data_alloc(git_odb_backend *backend, size_t len); - -/** - * Frees custom allocated ODB data. This should only be called when - * memory allocated using git_odb_backend_data_alloc is not returned - * to libgit2 because the backend encountered an error in the read - * function after allocation and did not return this data to libgit2. - * - * @param backend the ODB backend that is freeing this memory - * @param data the buffer to free - */ -GIT_EXTERN(void) git_odb_backend_data_free(git_odb_backend *backend, void *data); - - -/* - * Users can avoid deprecated functions by defining `GIT_DEPRECATE_HARD`. - */ -#ifndef GIT_DEPRECATE_HARD - -/** - * Allocate memory for an ODB object from a custom backend. This is - * an alias of `git_odb_backend_data_alloc` and is preserved for - * backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated git_odb_backend_data_alloc - * @see git_odb_backend_data_alloc - */ -GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len); - -#endif - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/openssl.h b/vendor/libgit2-sys/libgit2/include/git2/sys/openssl.h deleted file mode 100644 index 8b74a98..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/openssl.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_openssl_h__ -#define INCLUDE_git_openssl_h__ - -#include "git2/common.h" - -/** - * @file git2/sys/openssl.h - * @brief Custom OpenSSL functionality - * @defgroup git_openssl Custom OpenSSL functionality - * @{ - */ -GIT_BEGIN_DECL - -/** - * Initialize the OpenSSL locks - * - * OpenSSL requires the application to determine how it performs - * locking. - * - * This is a last-resort convenience function which libgit2 provides for - * allocating and initializing the locks as well as setting the - * locking function to use the system's native locking functions. - * - * The locking function will be cleared and the memory will be freed - * when you call git_threads_sutdown(). - * - * If your programming language has an OpenSSL package/bindings, it - * likely sets up locking. You should very strongly prefer that over - * this function. - * - * @return 0 on success, -1 if there are errors or if libgit2 was not - * built with OpenSSL and threading support. - */ -GIT_EXTERN(int) git_openssl_set_locking(void); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/path.h b/vendor/libgit2-sys/libgit2/include/git2/sys/path.h deleted file mode 100644 index 2963bca..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/path.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_sys_git_path_h__ -#define INCLUDE_sys_git_path_h__ - -#include "git2/common.h" - -/** - * @file git2/sys/path.h - * @brief Custom path handling - * @defgroup git_path Custom path handling - * @ingroup Git - * - * Merge will take two commits and attempt to produce a commit that - * includes the changes that were made in both branches. - * @{ - */ -GIT_BEGIN_DECL - -/** - * The kinds of git-specific files we know about. - * - * The order needs to stay the same to not break the `gitfiles` - * array in path.c - */ -typedef enum { - /** Check for the .gitignore file */ - GIT_PATH_GITFILE_GITIGNORE, - /** Check for the .gitmodules file */ - GIT_PATH_GITFILE_GITMODULES, - /** Check for the .gitattributes file */ - GIT_PATH_GITFILE_GITATTRIBUTES -} git_path_gitfile; - -/** - * The kinds of checks to perform according to which filesystem we are trying to - * protect. - */ -typedef enum { - /** Do both NTFS- and HFS-specific checks */ - GIT_PATH_FS_GENERIC, - /** Do NTFS-specific checks only */ - GIT_PATH_FS_NTFS, - /** Do HFS-specific checks only */ - GIT_PATH_FS_HFS -} git_path_fs; - -/** - * Check whether a path component corresponds to a .git$SUFFIX - * file. - * - * As some filesystems do special things to filenames when - * writing files to disk, you cannot always do a plain string - * comparison to verify whether a file name matches an expected - * path or not. This function can do the comparison for you, - * depending on the filesystem you're on. - * - * @param path the path component to check - * @param pathlen the length of `path` that is to be checked - * @param gitfile which file to check against - * @param fs which filesystem-specific checks to use - * @return 0 in case the file does not match, a positive value if - * it does; -1 in case of an error - */ -GIT_EXTERN(int) git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfile gitfile, git_path_fs fs); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/refdb_backend.h b/vendor/libgit2-sys/libgit2/include/git2/sys/refdb_backend.h deleted file mode 100644 index 813822a..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/refdb_backend.h +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_refdb_backend_h__ -#define INCLUDE_sys_git_refdb_backend_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/oid.h" - -/** - * @file git2/sys/refdb_backend.h - * @brief Custom reference database backends for refs storage - * @defgroup git_refdb_backend Custom reference database backends for refs storage - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - - -/** - * Every backend's iterator must have a pointer to itself as the first - * element, so the API can talk to it. You'd define your iterator as - * - * struct my_iterator { - * git_reference_iterator parent; - * ... - * } - * - * and assign `iter->parent.backend` to your `git_refdb_backend`. - */ -struct git_reference_iterator { - git_refdb *db; - - /** - * Return the current reference and advance the iterator. - */ - int GIT_CALLBACK(next)( - git_reference **ref, - git_reference_iterator *iter); - - /** - * Return the name of the current reference and advance the iterator - */ - int GIT_CALLBACK(next_name)( - const char **ref_name, - git_reference_iterator *iter); - - /** - * Free the iterator - */ - void GIT_CALLBACK(free)( - git_reference_iterator *iter); -}; - -/** An instance for a custom backend */ -struct git_refdb_backend { - unsigned int version; /**< The backend API version */ - - /** - * Queries the refdb backend for the existence of a reference. - * - * A refdb implementation must provide this function. - * - * @param exists The implementation shall set this to `0` if a ref does - * not exist, otherwise to `1`. - * @param ref_name The reference's name that should be checked for - * existence. - * @return `0` on success, a negative error value code. - */ - int GIT_CALLBACK(exists)( - int *exists, - git_refdb_backend *backend, - const char *ref_name); - - /** - * Queries the refdb backend for a given reference. - * - * A refdb implementation must provide this function. - * - * @param out The implementation shall set this to the allocated - * reference, if it could be found, otherwise to `NULL`. - * @param ref_name The reference's name that should be checked for - * existence. - * @return `0` on success, `GIT_ENOTFOUND` if the reference does - * exist, otherwise a negative error code. - */ - int GIT_CALLBACK(lookup)( - git_reference **out, - git_refdb_backend *backend, - const char *ref_name); - - /** - * Allocate an iterator object for the backend. - * - * A refdb implementation must provide this function. - * - * @param out The implementation shall set this to the allocated - * reference iterator. A custom structure may be used with an - * embedded `git_reference_iterator` structure. Both `next` - * and `next_name` functions of `git_reference_iterator` need - * to be populated. - * @param glob A pattern to filter references by. If given, the iterator - * shall only return references that match the glob when - * passed to `wildmatch`. - * @return `0` on success, otherwise a negative error code. - */ - int GIT_CALLBACK(iterator)( - git_reference_iterator **iter, - struct git_refdb_backend *backend, - const char *glob); - - /** - * Writes the given reference to the refdb. - * - * A refdb implementation must provide this function. - * - * @param ref The reference to persist. May either be a symbolic or - * direct reference. - * @param force Whether to write the reference if a reference with the - * same name already exists. - * @param who The person updating the reference. Shall be used to create - * a reflog entry. - * @param message The message detailing what kind of reference update is - * performed. Shall be used to create a reflog entry. - * @param old If not `NULL` and `force` is not set, then the - * implementation needs to ensure that the reference is currently at - * the given OID before writing the new value. If both `old` - * and `old_target` are `NULL`, then the reference should not - * exist at the point of writing. - * @param old_target If not `NULL` and `force` is not set, then the - * implementation needs to ensure that the symbolic - * reference is currently at the given target before - * writing the new value. If both `old` and - * `old_target` are `NULL`, then the reference should - * not exist at the point of writing. - * @return `0` on success, otherwise a negative error code. - */ - int GIT_CALLBACK(write)(git_refdb_backend *backend, - const git_reference *ref, int force, - const git_signature *who, const char *message, - const git_oid *old, const char *old_target); - - /** - * Rename a reference in the refdb. - * - * A refdb implementation must provide this function. - * - * @param out The implementation shall set this to the newly created - * reference or `NULL` on error. - * @param old_name The current name of the reference that is to be renamed. - * @param new_name The new name that the old reference shall be renamed to. - * @param force Whether to write the reference if a reference with the - * target name already exists. - * @param who The person updating the reference. Shall be used to create - * a reflog entry. - * @param message The message detailing what kind of reference update is - * performed. Shall be used to create a reflog entry. - * @return `0` on success, otherwise a negative error code. - */ - int GIT_CALLBACK(rename)( - git_reference **out, git_refdb_backend *backend, - const char *old_name, const char *new_name, int force, - const git_signature *who, const char *message); - - /** - * Deletes the given reference from the refdb. - * - * If it exists, its reflog should be deleted as well. - * - * A refdb implementation must provide this function. - * - * @param ref_name The name of the reference name that shall be deleted. - * @param old_id If not `NULL` and `force` is not set, then the - * implementation needs to ensure that the reference is currently at - * the given OID before writing the new value. - * @param old_target If not `NULL` and `force` is not set, then the - * implementation needs to ensure that the symbolic - * reference is currently at the given target before - * writing the new value. - * @return `0` on success, otherwise a negative error code. - */ - int GIT_CALLBACK(del)(git_refdb_backend *backend, const char *ref_name, const git_oid *old_id, const char *old_target); - - /** - * Suggests that the given refdb compress or optimize its references. - * - * This mechanism is implementation specific. For on-disk reference - * databases, this may pack all loose references. - * - * A refdb implementation may provide this function; if it is not - * provided, nothing will be done. - * - * @return `0` on success a negative error code otherwise - */ - int GIT_CALLBACK(compress)(git_refdb_backend *backend); - - /** - * Query whether a particular reference has a log (may be empty) - * - * Shall return 1 if it has a reflog, 0 it it doesn't and negative in - * case an error occurred. - * - * A refdb implementation must provide this function. - * - * @return `0` on success, `1` if the reflog for the given reference - * exists, a negative error code otherwise - */ - int GIT_CALLBACK(has_log)(git_refdb_backend *backend, const char *refname); - - /** - * Make sure a particular reference will have a reflog which - * will be appended to on writes. - * - * A refdb implementation must provide this function. - * - * @return `0` on success, a negative error code otherwise - */ - int GIT_CALLBACK(ensure_log)(git_refdb_backend *backend, const char *refname); - - /** - * Frees any resources held by the refdb (including the `git_refdb_backend` - * itself). - * - * A refdb backend implementation must provide this function. - */ - void GIT_CALLBACK(free)(git_refdb_backend *backend); - - /** - * Read the reflog for the given reference name. - * - * A refdb implementation must provide this function. - * - * @return `0` on success, a negative error code otherwise - */ - int GIT_CALLBACK(reflog_read)(git_reflog **out, git_refdb_backend *backend, const char *name); - - /** - * Write a reflog to disk. - * - * A refdb implementation must provide this function. - * - * @param reflog The complete reference log for a given reference. Note - * that this may contain entries that have already been - * written to disk. - * @return `0` on success, a negative error code otherwise - */ - int GIT_CALLBACK(reflog_write)(git_refdb_backend *backend, git_reflog *reflog); - - /** - * Rename a reflog. - * - * A refdb implementation must provide this function. - * - * @param old_name The name of old reference whose reflog shall be renamed from. - * @param new_name The name of new reference whose reflog shall be renamed to. - * @return `0` on success, a negative error code otherwise - */ - int GIT_CALLBACK(reflog_rename)(git_refdb_backend *_backend, const char *old_name, const char *new_name); - - /** - * Remove a reflog. - * - * A refdb implementation must provide this function. - * - * @param name The name of the reference whose reflog shall be deleted. - * @return `0` on success, a negative error code otherwise - */ - int GIT_CALLBACK(reflog_delete)(git_refdb_backend *backend, const char *name); - - /** - * Lock a reference. - * - * A refdb implementation may provide this function; if it is not - * provided, the transaction API will fail to work. - * - * @param payload_out Opaque parameter that will be passed verbosely to - * `unlock`. - * @param refname Reference that shall be locked. - * @return `0` on success, a negative error code otherwise - */ - int GIT_CALLBACK(lock)(void **payload_out, git_refdb_backend *backend, const char *refname); - - /** - * Unlock a reference. - * - * Only one of target or symbolic_target will be set. - * `success` will be true if the reference should be update, false if - * the lock must be discarded. - * - * A refdb implementation must provide this function if a `lock` - * implementation is provided. - * - * @param payload The payload returned by `lock`. - * @param success `1` if a reference should be updated, `2` if - * a reference should be deleted, `0` if the lock must be - * discarded. - * @param update_reflog `1` in case the reflog should be updated, `0` - * otherwise. - * @param ref The reference which should be unlocked. - * @param who The person updating the reference. Shall be used to create - * a reflog entry in case `update_reflog` is set. - * @param message The message detailing what kind of reference update is - * performed. Shall be used to create a reflog entry in - * case `update_reflog` is set. - * @return `0` on success, a negative error code otherwise - */ - int GIT_CALLBACK(unlock)(git_refdb_backend *backend, void *payload, int success, int update_reflog, - const git_reference *ref, const git_signature *sig, const char *message); -}; - -/** Current version for the `git_refdb_backend_options` structure */ -#define GIT_REFDB_BACKEND_VERSION 1 - -/** Static constructor for `git_refdb_backend_options` */ -#define GIT_REFDB_BACKEND_INIT {GIT_REFDB_BACKEND_VERSION} - -/** - * Initializes a `git_refdb_backend` with default values. Equivalent to - * creating an instance with GIT_REFDB_BACKEND_INIT. - * - * @param backend the `git_refdb_backend` struct to initialize - * @param version Version of struct; pass `GIT_REFDB_BACKEND_VERSION` - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_refdb_init_backend( - git_refdb_backend *backend, - unsigned int version); - -/** - * Constructors for default filesystem-based refdb backend - * - * Under normal usage, this is called for you when the repository is - * opened / created, but you can use this to explicitly construct a - * filesystem refdb backend for a repository. - * - * @param backend_out Output pointer to the git_refdb_backend object - * @param repo Git repository to access - * @return 0 on success, <0 error code on failure - */ -GIT_EXTERN(int) git_refdb_backend_fs( - git_refdb_backend **backend_out, - git_repository *repo); - -/** - * Sets the custom backend to an existing reference DB - * - * The `git_refdb` will take ownership of the `git_refdb_backend` so you - * should NOT free it after calling this function. - * - * @param refdb database to add the backend to - * @param backend pointer to a git_refdb_backend instance - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_refdb_set_backend( - git_refdb *refdb, - git_refdb_backend *backend); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/refs.h b/vendor/libgit2-sys/libgit2/include/git2/sys/refs.h deleted file mode 100644 index e434e67..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/refs.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_refdb_h__ -#define INCLUDE_sys_git_refdb_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/oid.h" - -/** - * @file git2/sys/refs.h - * @brief Low-level git reference creation - * @defgroup git_backend Low-level git reference creation - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create a new direct reference from an OID. - * - * @param name the reference name - * @param oid the object id for a direct reference - * @param peel the first non-tag object's OID, or NULL - * @return the created git_reference or NULL on error - */ -GIT_EXTERN(git_reference *) git_reference__alloc( - const char *name, - const git_oid *oid, - const git_oid *peel); - -/** - * Create a new symbolic reference. - * - * @param name the reference name - * @param target the target for a symbolic reference - * @return the created git_reference or NULL on error - */ -GIT_EXTERN(git_reference *) git_reference__alloc_symbolic( - const char *name, - const char *target); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/remote.h b/vendor/libgit2-sys/libgit2/include/git2/sys/remote.h deleted file mode 100644 index 476965d..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/remote.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_sys_git_remote_h -#define INCLUDE_sys_git_remote_h - -#include "git2/remote.h" - -/** - * @file git2/sys/remote.h - * @brief Low-level remote functionality for custom transports - * @defgroup git_remote Low-level remote functionality for custom transports - * @ingroup Git - * @{ -*/ - -GIT_BEGIN_DECL - -/** - * A remote's capabilities. - */ -typedef enum { - /** Remote supports fetching an advertised object by ID. */ - GIT_REMOTE_CAPABILITY_TIP_OID = (1 << 0), - - /** Remote supports fetching an individual reachable object. */ - GIT_REMOTE_CAPABILITY_REACHABLE_OID = (1 << 1), - - /** Remote supports push options. */ - GIT_REMOTE_CAPABILITY_PUSH_OPTIONS = (1 << 2), -} git_remote_capability_t; - -/** - * Disposes libgit2-initialized fields from a git_remote_connect_options. - * This should only be used for git_remote_connect_options returned by - * git_transport_remote_connect_options. - * - * Note that this does not free the `git_remote_connect_options` itself, just - * the memory pointed to by it. - * - * @param opts The `git_remote_connect_options` struct to dispose. - */ -GIT_EXTERN(void) git_remote_connect_options_dispose( - git_remote_connect_options *opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/repository.h b/vendor/libgit2-sys/libgit2/include/git2/sys/repository.h deleted file mode 100644 index 026ac8a..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/repository.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_repository_h__ -#define INCLUDE_sys_git_repository_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/oid.h" - -/** - * @file git2/sys/repository.h - * @brief Custom repository handling - * @defgroup git_repository Custom repository handling - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -#ifdef GIT_EXPERIMENTAL_SHA256 - -/** - * The options for creating an repository from scratch. - * - * Initialize with `GIT_REPOSITORY_NEW_OPTIONS_INIT`. Alternatively, - * you can use `git_repository_new_options_init`. - * - * @options[version] GIT_REPOSITORY_NEW_OPTIONS_VERSION - * @options[init_macro] GIT_REPOSITORY_NEW_OPTIONS_INIT - * @options[init_function] git_repository_new_options_init - */ -typedef struct git_repository_new_options { - unsigned int version; /**< The version */ - - /** - * The object ID type for the object IDs that exist in the index. - * - * If this is not specified, this defaults to `GIT_OID_SHA1`. - */ - git_oid_t oid_type; -} git_repository_new_options; - -/** Current version for the `git_repository_new_options` structure */ -#define GIT_REPOSITORY_NEW_OPTIONS_VERSION 1 - -/** Static constructor for `git_repository_new_options` */ -#define GIT_REPOSITORY_NEW_OPTIONS_INIT { GIT_REPOSITORY_NEW_OPTIONS_VERSION } - -/** - * Initialize git_repository_new_options structure - * - * Initializes a `git_repository_new_options` with default values. - * Equivalent to creating an instance with - * `GIT_REPOSITORY_NEW_OPTIONS_INIT`. - * - * @param opts The `git_repository_new_options` struct to initialize. - * @param version The struct version; pass `GIT_REPOSITORY_NEW_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_repository_new_options_init( - git_repository_new_options *opts, - unsigned int version); - -/** - * Create a new repository with no backends. - * - * @param[out] out The blank repository - * @param opts the options for repository creation, or NULL for defaults - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_new(git_repository **out, git_repository_new_options *opts); -#else - -/** - * Create a new repository with neither backends nor config object - * - * Note that this is only useful if you wish to associate the repository - * with a non-filesystem-backed object database and config store. - * - * Caveats: since this repository has no physical location, some systems - * can fail to function properly: locations under $GIT_DIR, $GIT_COMMON_DIR, - * or $GIT_INFO_DIR are impacted. - * - * @param[out] out The blank repository - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_new(git_repository **out); - -#endif - -/** - * Reset all the internal state in a repository. - * - * This will free all the mapped memory and internal objects - * of the repository and leave it in a "blank" state. - * - * There's no need to call this function directly unless you're - * trying to aggressively cleanup the repo before its - * deallocation. `git_repository_free` already performs this operation - * before deallocating the repo. - * - * @param repo The repository to clean up - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository__cleanup(git_repository *repo); - -/** - * Update the filesystem config settings for an open repository - * - * When a repository is initialized, config values are set based on the - * properties of the filesystem that the repository is on, such as - * "core.ignorecase", "core.filemode", "core.symlinks", etc. If the - * repository is moved to a new filesystem, these properties may no - * longer be correct and API calls may not behave as expected. This - * call reruns the phase of repository initialization that sets those - * properties to compensate for the current filesystem of the repo. - * - * @param repo A repository object - * @param recurse_submodules Should submodules be updated recursively - * @return 0 on success, < 0 on error - */ -GIT_EXTERN(int) git_repository_reinit_filesystem( - git_repository *repo, - int recurse_submodules); - -/** - * Set the configuration file for this repository - * - * This configuration file will be used for all configuration - * queries involving this repository. - * - * The repository will keep a reference to the config file; - * the user must still free the config after setting it - * to the repository, or it will leak. - * - * @param repo A repository object - * @param config A Config object - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_set_config(git_repository *repo, git_config *config); - -/** - * Set the Object Database for this repository - * - * The ODB will be used for all object-related operations - * involving this repository. - * - * The repository will keep a reference to the ODB; the user - * must still free the ODB object after setting it to the - * repository, or it will leak. - * - * @param repo A repository object - * @param odb An ODB object - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_set_odb(git_repository *repo, git_odb *odb); - -/** - * Set the Reference Database Backend for this repository - * - * The refdb will be used for all reference related operations - * involving this repository. - * - * The repository will keep a reference to the refdb; the user - * must still free the refdb object after setting it to the - * repository, or it will leak. - * - * @param repo A repository object - * @param refdb An refdb object - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_set_refdb(git_repository *repo, git_refdb *refdb); - -/** - * Set the index file for this repository - * - * This index will be used for all index-related operations - * involving this repository. - * - * The repository will keep a reference to the index file; - * the user must still free the index after setting it - * to the repository, or it will leak. - * - * @param repo A repository object - * @param index An index object - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_set_index(git_repository *repo, git_index *index); - -/** - * Set a repository to be bare. - * - * Clear the working directory and set core.bare to true. You may also - * want to call `git_repository_set_index(repo, NULL)` since a bare repo - * typically does not have an index, but this function will not do that - * for you. - * - * @param repo Repo to make bare - * @return 0 on success, <0 on failure - */ -GIT_EXTERN(int) git_repository_set_bare(git_repository *repo); - -/** - * Load and cache all submodules. - * - * Because the `.gitmodules` file is unstructured, loading submodules is an - * O(N) operation. Any operation (such as `git_rebase_init`) that requires - * accessing all submodules is O(N^2) in the number of submodules, if it - * has to look each one up individually. This function loads all submodules - * and caches them so that subsequent calls to `git_submodule_lookup` are O(1). - * - * @param repo the repository whose submodules will be cached. - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_submodule_cache_all( - git_repository *repo); - -/** - * Clear the submodule cache. - * - * Clear the submodule cache populated by `git_repository_submodule_cache_all`. - * If there is no cache, do nothing. - * - * The cache incorporates data from the repository's configuration, as well - * as the state of the working tree, the index, and HEAD. So any time any - * of these has changed, the cache might become invalid. - * - * @param repo the repository whose submodule cache will be cleared - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_submodule_cache_clear( - git_repository *repo); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/stream.h b/vendor/libgit2-sys/libgit2/include/git2/sys/stream.h deleted file mode 100644 index eabff68..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/stream.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sys_git_stream_h__ -#define INCLUDE_sys_git_stream_h__ - -#include "git2/common.h" -#include "git2/types.h" -#include "git2/proxy.h" - -/** - * @file git2/sys/stream.h - * @brief Streaming file I/O functionality - * @defgroup git_stream Streaming file I/O functionality - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Current version for the `git_stream` structures */ -#define GIT_STREAM_VERSION 1 - -/** - * Every stream must have this struct as its first element, so the - * API can talk to it. You'd define your stream as - * - * struct my_stream { - * git_stream parent; - * ... - * } - * - * and fill the functions - */ -typedef struct git_stream { - int version; - - unsigned int encrypted : 1, - proxy_support : 1; - - /** - * Timeout for read and write operations; can be set to `0` to - * block indefinitely. - */ - int timeout; - - /** - * Timeout to connect to the remote server; can be set to `0` - * to use the system defaults. This can be shorter than the - * system default - often 75 seconds - but cannot be longer. - */ - int connect_timeout; - - int GIT_CALLBACK(connect)(struct git_stream *); - int GIT_CALLBACK(certificate)(git_cert **, struct git_stream *); - int GIT_CALLBACK(set_proxy)(struct git_stream *, const git_proxy_options *proxy_opts); - ssize_t GIT_CALLBACK(read)(struct git_stream *, void *, size_t); - ssize_t GIT_CALLBACK(write)(struct git_stream *, const char *, size_t, int); - int GIT_CALLBACK(close)(struct git_stream *); - void GIT_CALLBACK(free)(struct git_stream *); -} git_stream; - -typedef struct { - /** The `version` field should be set to `GIT_STREAM_VERSION`. */ - int version; - - /** - * Called to create a new connection to a given host. - * - * @param out The created stream - * @param host The hostname to connect to; may be a hostname or - * IP address - * @param port The port to connect to; may be a port number or - * service name - * @return 0 or an error code - */ - int GIT_CALLBACK(init)(git_stream **out, const char *host, const char *port); - - /** - * Called to create a new connection on top of the given stream. If - * this is a TLS stream, then this function may be used to proxy a - * TLS stream over an HTTP CONNECT session. If this is unset, then - * HTTP CONNECT proxies will not be supported. - * - * @param out The created stream - * @param in An existing stream to add TLS to - * @param host The hostname that the stream is connected to, - * for certificate validation - * @return 0 or an error code - */ - int GIT_CALLBACK(wrap)(git_stream **out, git_stream *in, const char *host); -} git_stream_registration; - -/** - * The type of stream to register. - */ -typedef enum { - /** A standard (non-TLS) socket. */ - GIT_STREAM_STANDARD = 1, - - /** A TLS-encrypted socket. */ - GIT_STREAM_TLS = 2 -} git_stream_t; - -/** - * Register stream constructors for the library to use - * - * If a registration structure is already set, it will be overwritten. - * Pass `NULL` in order to deregister the current constructor and return - * to the system defaults. - * - * The type parameter may be a bitwise AND of types. - * - * @param type the type or types of stream to register - * @param registration the registration data - * @return 0 or an error code - */ -GIT_EXTERN(int) git_stream_register( - git_stream_t type, git_stream_registration *registration); - -#ifndef GIT_DEPRECATE_HARD - -/** @name Deprecated TLS Stream Registration Functions - * - * These functions are retained for backward compatibility. The newer - * versions of these values should be preferred in all new code. - * - * There is no plan to remove these backward compatibility values at - * this time. - */ -/**@{*/ - -/** - * @deprecated Provide a git_stream_registration to git_stream_register - * @see git_stream_registration - */ -typedef int GIT_CALLBACK(git_stream_cb)(git_stream **out, const char *host, const char *port); - -/** - * Register a TLS stream constructor for the library to use. This stream - * will not support HTTP CONNECT proxies. This internally calls - * `git_stream_register` and is preserved for backward compatibility. - * - * This function is deprecated, but there is no plan to remove this - * function at this time. - * - * @deprecated Provide a git_stream_registration to git_stream_register - * @see git_stream_register - */ -GIT_EXTERN(int) git_stream_register_tls(git_stream_cb ctor); - -/**@}*/ - -#endif - -/**@}*/ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/sys/transport.h b/vendor/libgit2-sys/libgit2/include/git2/sys/transport.h deleted file mode 100644 index 6a19024..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/sys/transport.h +++ /dev/null @@ -1,486 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_sys_git_transport_h -#define INCLUDE_sys_git_transport_h - -#include "git2/net.h" -#include "git2/oidarray.h" -#include "git2/proxy.h" -#include "git2/remote.h" -#include "git2/strarray.h" -#include "git2/transport.h" -#include "git2/types.h" - -/** - * @file git2/sys/transport.h - * @brief Custom transport registration interfaces and functions - * @defgroup git_transport Custom transport registration - * @ingroup Git - * - * Callers can override the default HTTPS or SSH implementation by - * specifying a custom transport. - * @{ - */ - -GIT_BEGIN_DECL - -/** - * The negotiation state during a fetch smart transport negotiation. - */ -typedef struct { - const git_remote_head * const *refs; - size_t refs_len; - git_oid *shallow_roots; - size_t shallow_roots_len; - int depth; -} git_fetch_negotiation; - -struct git_transport { - unsigned int version; /**< The struct version */ - - /** - * Connect the transport to the remote repository, using the given - * direction. - */ - int GIT_CALLBACK(connect)( - git_transport *transport, - const char *url, - int direction, - const git_remote_connect_options *connect_opts); - - /** - * Resets the connect options for the given transport. This - * is useful for updating settings or callbacks for an already - * connected transport. - */ - int GIT_CALLBACK(set_connect_opts)( - git_transport *transport, - const git_remote_connect_options *connect_opts); - - /** - * Gets the capabilities for this remote repository. - * - * This function may be called after a successful call to - * `connect()`. - */ - int GIT_CALLBACK(capabilities)( - unsigned int *capabilities, - git_transport *transport); - -#ifdef GIT_EXPERIMENTAL_SHA256 - /** - * Gets the object type for the remote repository. - * - * This function may be called after a successful call to - * `connect()`. - */ - int GIT_CALLBACK(oid_type)( - git_oid_t *object_type, - git_transport *transport); -#endif - - /** - * Get the list of available references in the remote repository. - * - * This function may be called after a successful call to - * `connect()`. The array returned is owned by the transport and - * must be kept valid until the next call to one of its functions. - */ - int GIT_CALLBACK(ls)( - const git_remote_head ***out, - size_t *size, - git_transport *transport); - - /** Executes the push whose context is in the git_push object. */ - int GIT_CALLBACK(push)( - git_transport *transport, - git_push *push); - - /** - * Negotiate a fetch with the remote repository. - * - * This function may be called after a successful call to `connect()`, - * when the direction is GIT_DIRECTION_FETCH. The function performs a - * negotiation to calculate the `wants` list for the fetch. - */ - int GIT_CALLBACK(negotiate_fetch)( - git_transport *transport, - git_repository *repo, - const git_fetch_negotiation *fetch_data); - - /** - * Return the shallow roots of the remote. - * - * This function may be called after a successful call to - * `negotiate_fetch`. - */ - int GIT_CALLBACK(shallow_roots)( - git_oidarray *out, - git_transport *transport); - - /** - * Start downloading the packfile from the remote repository. - * - * This function may be called after a successful call to - * negotiate_fetch(), when the direction is GIT_DIRECTION_FETCH. - */ - int GIT_CALLBACK(download_pack)( - git_transport *transport, - git_repository *repo, - git_indexer_progress *stats); - - /** Checks to see if the transport is connected */ - int GIT_CALLBACK(is_connected)(git_transport *transport); - - /** Cancels any outstanding transport operation */ - void GIT_CALLBACK(cancel)(git_transport *transport); - - /** - * Close the connection to the remote repository. - * - * This function is the reverse of connect() -- it terminates the - * connection to the remote end. - */ - int GIT_CALLBACK(close)(git_transport *transport); - - /** Frees/destructs the git_transport object. */ - void GIT_CALLBACK(free)(git_transport *transport); -}; - -/** Current version for the `git_transport` structure */ -#define GIT_TRANSPORT_VERSION 1 - -/** Static constructor for `git_transport` */ -#define GIT_TRANSPORT_INIT {GIT_TRANSPORT_VERSION} - -/** - * Initializes a `git_transport` with default values. Equivalent to - * creating an instance with GIT_TRANSPORT_INIT. - * - * @param opts the `git_transport` struct to initialize - * @param version Version of struct; pass `GIT_TRANSPORT_VERSION` - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_transport_init( - git_transport *opts, - unsigned int version); - -/** - * Function to use to create a transport from a URL. The transport database - * is scanned to find a transport that implements the scheme of the URI (i.e. - * git:// or http://) and a transport object is returned to the caller. - * - * @param out The newly created transport (out) - * @param owner The git_remote which will own this transport - * @param url The URL to connect to - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transport_new(git_transport **out, git_remote *owner, const char *url); - -/** - * Create an ssh transport with custom git command paths - * - * This is a factory function suitable for setting as the transport - * callback in a remote (or for a clone in the options). - * - * The payload argument must be a strarray pointer with the paths for - * the `git-upload-pack` and `git-receive-pack` at index 0 and 1. - * - * @param out the resulting transport - * @param owner the owning remote - * @param payload a strarray with the paths - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *payload); - -/** - * Add a custom transport definition, to be used in addition to the built-in - * set of transports that come with libgit2. - * - * The caller is responsible for synchronizing calls to git_transport_register - * and git_transport_unregister with other calls to the library that - * instantiate transports. - * - * @param prefix The scheme to match, eg "git" or "https" - * @param cb The callback used to create an instance of the transport - * @param param A fixed parameter to pass to cb at creation time - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transport_register( - const char *prefix, - git_transport_cb cb, - void *param); - -/** - * Unregister a custom transport definition which was previously registered - * with git_transport_register. - * - * The caller is responsible for synchronizing calls to git_transport_register - * and git_transport_unregister with other calls to the library that - * instantiate transports. - * - * @param prefix From the previous call to git_transport_register - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transport_unregister( - const char *prefix); - -/* Transports which come with libgit2 (match git_transport_cb). The expected - * value for "param" is listed in-line below. */ - -/** - * Create an instance of the dummy transport. - * - * @param out The newly created transport (out) - * @param owner The git_remote which will own this transport - * @param payload You must pass NULL for this parameter. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transport_dummy( - git_transport **out, - git_remote *owner, - /* NULL */ void *payload); - -/** - * Create an instance of the local transport. - * - * @param out The newly created transport (out) - * @param owner The git_remote which will own this transport - * @param payload You must pass NULL for this parameter. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transport_local( - git_transport **out, - git_remote *owner, - /* NULL */ void *payload); - -/** - * Create an instance of the smart transport. - * - * @param out The newly created transport (out) - * @param owner The git_remote which will own this transport - * @param payload A pointer to a git_smart_subtransport_definition - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transport_smart( - git_transport **out, - git_remote *owner, - /* (git_smart_subtransport_definition *) */ void *payload); - -/** - * Call the certificate check for this transport. - * - * @param transport a smart transport - * @param cert the certificate to pass to the caller - * @param valid whether we believe the certificate is valid - * @param hostname the hostname we connected to - * @return the return value of the callback: 0 for no error, GIT_PASSTHROUGH - * to indicate that there is no callback registered (or the callback - * refused to validate the certificate and callers should behave as - * if no callback was set), or < 0 for an error - */ -GIT_EXTERN(int) git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname); - -/** - * Call the credentials callback for this transport - * - * @param out the pointer where the creds are to be stored - * @param transport a smart transport - * @param user the user we saw on the url (if any) - * @param methods available methods for authentication - * @return the return value of the callback: 0 for no error, GIT_PASSTHROUGH - * to indicate that there is no callback registered (or the callback - * refused to provide credentials and callers should behave as if no - * callback was set), or < 0 for an error - */ -GIT_EXTERN(int) git_transport_smart_credentials(git_credential **out, git_transport *transport, const char *user, int methods); - -/** - * Get a copy of the remote connect options - * - * All data is copied and must be freed by the caller by calling - * `git_remote_connect_options_dispose`. - * - * @param out options struct to fill - * @param transport the transport to extract the data from. - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_transport_remote_connect_options( - git_remote_connect_options *out, - git_transport *transport); - -/* - *** End of base transport interface *** - *** Begin interface for subtransports for the smart transport *** - */ - -/** Actions that the smart transport can ask a subtransport to perform */ -typedef enum { - GIT_SERVICE_UPLOADPACK_LS = 1, - GIT_SERVICE_UPLOADPACK = 2, - GIT_SERVICE_RECEIVEPACK_LS = 3, - GIT_SERVICE_RECEIVEPACK = 4 -} git_smart_service_t; - -typedef struct git_smart_subtransport git_smart_subtransport; -typedef struct git_smart_subtransport_stream git_smart_subtransport_stream; - -/** - * A stream used by the smart transport to read and write data - * from a subtransport. - * - * This provides a customization point in case you need to - * support some other communication method. - */ -struct git_smart_subtransport_stream { - git_smart_subtransport *subtransport; /**< The owning subtransport */ - - /** - * Read available data from the stream. - * - * The implementation may read less than requested. - */ - int GIT_CALLBACK(read)( - git_smart_subtransport_stream *stream, - char *buffer, - size_t buf_size, - size_t *bytes_read); - - /** - * Write data to the stream - * - * The implementation must write all data or return an error. - */ - int GIT_CALLBACK(write)( - git_smart_subtransport_stream *stream, - const char *buffer, - size_t len); - - /** Free the stream */ - void GIT_CALLBACK(free)( - git_smart_subtransport_stream *stream); -}; - -/** - * An implementation of a subtransport which carries data for the - * smart transport - */ -struct git_smart_subtransport { - /** - * Setup a subtransport stream for the requested action. - */ - int GIT_CALLBACK(action)( - git_smart_subtransport_stream **out, - git_smart_subtransport *transport, - const char *url, - git_smart_service_t action); - - /** - * Close the subtransport. - * - * Subtransports are guaranteed a call to close() between - * calls to action(), except for the following two "natural" progressions - * of actions against a constant URL: - * - * - UPLOADPACK_LS -> UPLOADPACK - * - RECEIVEPACK_LS -> RECEIVEPACK - */ - int GIT_CALLBACK(close)(git_smart_subtransport *transport); - - /** Free the subtransport */ - void GIT_CALLBACK(free)(git_smart_subtransport *transport); -}; - -/** - * A function that creates a new subtransport for the smart transport - * - * @param out the smart subtransport - * @param owner the transport owner - * @param param the input parameter - * @return 0 on success, or an error code - */ -typedef int GIT_CALLBACK(git_smart_subtransport_cb)( - git_smart_subtransport **out, - git_transport *owner, - void *param); - -/** - * Definition for a "subtransport" - * - * The smart transport knows how to speak the git protocol, but it has no - * knowledge of how to establish a connection between it and another endpoint, - * or how to move data back and forth. For this, a subtransport interface is - * declared, and the smart transport delegates this work to the subtransports. - * - * Three subtransports are provided by libgit2: ssh, git, http(s). - * - * Subtransports can either be RPC = 0 (persistent connection) or RPC = 1 - * (request/response). The smart transport handles the differences in its own - * logic. The git subtransport is RPC = 0, while http is RPC = 1. - */ -typedef struct git_smart_subtransport_definition { - /** The function to use to create the git_smart_subtransport */ - git_smart_subtransport_cb callback; - - /** - * True if the protocol is stateless; false otherwise. For example, - * http:// is stateless, but git:// is not. - */ - unsigned rpc; - - /** User-specified parameter passed to the callback */ - void *param; -} git_smart_subtransport_definition; - -/* Smart transport subtransports that come with libgit2 */ - -/** - * Create an instance of the http subtransport. - * - * This subtransport also supports https. - * - * @param out The newly created subtransport - * @param owner The smart transport to own this subtransport - * @param param custom parameters for the subtransport - * @return 0 or an error code - */ -GIT_EXTERN(int) git_smart_subtransport_http( - git_smart_subtransport **out, - git_transport *owner, - void *param); - -/** - * Create an instance of the git subtransport. - * - * @param out The newly created subtransport - * @param owner The smart transport to own this subtransport - * @param param custom parameters for the subtransport - * @return 0 or an error code - */ -GIT_EXTERN(int) git_smart_subtransport_git( - git_smart_subtransport **out, - git_transport *owner, - void *param); - -/** - * Create an instance of the ssh subtransport. - * - * @param out The newly created subtransport - * @param owner The smart transport to own this subtransport - * @param param custom parameters for the subtransport - * @return 0 or an error code - */ -GIT_EXTERN(int) git_smart_subtransport_ssh( - git_smart_subtransport **out, - git_transport *owner, - void *param); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/tag.h b/vendor/libgit2-sys/libgit2/include/git2/tag.h deleted file mode 100644 index 3b0c12e..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/tag.h +++ /dev/null @@ -1,385 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_tag_h__ -#define INCLUDE_git_tag_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "object.h" -#include "strarray.h" - -/** - * @file git2/tag.h - * @brief A (nearly) immutable pointer to a commit; useful for versioning - * @defgroup git_tag Git tag management - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a tag object from the repository. - * - * @param out pointer to the looked up tag - * @param repo the repo to use when locating the tag. - * @param id identity of the tag to locate. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tag_lookup( - git_tag **out, git_repository *repo, const git_oid *id); - -/** - * Lookup a tag object from the repository, - * given a prefix of its identifier (short id). - * - * @see git_object_lookup_prefix - * - * @param out pointer to the looked up tag - * @param repo the repo to use when locating the tag. - * @param id identity of the tag to locate. - * @param len the length of the short identifier - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tag_lookup_prefix( - git_tag **out, git_repository *repo, const git_oid *id, size_t len); - -/** - * Close an open tag - * - * You can no longer use the git_tag pointer after this call. - * - * IMPORTANT: You MUST call this method when you are through with a tag to - * release memory. Failure to do so will cause a memory leak. - * - * @param tag the tag to close - */ -GIT_EXTERN(void) git_tag_free(git_tag *tag); - -/** - * Get the id of a tag. - * - * @param tag a previously loaded tag. - * @return object identity for the tag. - */ -GIT_EXTERN(const git_oid *) git_tag_id(const git_tag *tag); - -/** - * Get the repository that contains the tag. - * - * @param tag A previously loaded tag. - * @return Repository that contains this tag. - */ -GIT_EXTERN(git_repository *) git_tag_owner(const git_tag *tag); - -/** - * Get the tagged object of a tag - * - * This method performs a repository lookup for the - * given object and returns it - * - * @param target_out pointer where to store the target - * @param tag a previously loaded tag. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tag_target(git_object **target_out, const git_tag *tag); - -/** - * Get the OID of the tagged object of a tag - * - * @param tag a previously loaded tag. - * @return pointer to the OID - */ -GIT_EXTERN(const git_oid *) git_tag_target_id(const git_tag *tag); - -/** - * Get the type of a tag's tagged object - * - * @param tag a previously loaded tag. - * @return type of the tagged object - */ -GIT_EXTERN(git_object_t) git_tag_target_type(const git_tag *tag); - -/** - * Get the name of a tag - * - * @param tag a previously loaded tag. - * @return name of the tag - */ -GIT_EXTERN(const char *) git_tag_name(const git_tag *tag); - -/** - * Get the tagger (author) of a tag - * - * @param tag a previously loaded tag. - * @return reference to the tag's author or NULL when unspecified - */ -GIT_EXTERN(const git_signature *) git_tag_tagger(const git_tag *tag); - -/** - * Get the message of a tag - * - * @param tag a previously loaded tag. - * @return message of the tag or NULL when unspecified - */ -GIT_EXTERN(const char *) git_tag_message(const git_tag *tag); - - -/** - * Create a new tag in the repository from an object - * - * A new reference will also be created pointing to - * this tag object. If `force` is true and a reference - * already exists with the given name, it'll be replaced. - * - * The message will not be cleaned up. This can be achieved - * through `git_message_prettify()`. - * - * The tag name will be checked for validity. You must avoid - * the characters '~', '^', ':', '\\', '?', '[', and '*', and the - * sequences ".." and "@{" which have special meaning to revparse. - * - * @param oid Pointer where to store the OID of the - * newly created tag. If the tag already exists, this parameter - * will be the oid of the existing tag, and the function will - * return a GIT_EEXISTS error code. - * - * @param repo Repository where to store the tag - * - * @param tag_name Name for the tag; this name is validated - * for consistency. It should also not conflict with an - * already existing tag name - * - * @param target Object to which this tag points. This object - * must belong to the given `repo`. - * - * @param tagger Signature of the tagger for this tag, and - * of the tagging time - * - * @param message Full message for this tag - * - * @param force Overwrite existing references - * - * @return 0 on success, GIT_EINVALIDSPEC or an error code - * A tag object is written to the ODB, and a proper reference - * is written in the /refs/tags folder, pointing to it - */ -GIT_EXTERN(int) git_tag_create( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message, - int force); - -/** - * Create a new tag in the object database pointing to a git_object - * - * The message will not be cleaned up. This can be achieved - * through `git_message_prettify()`. - * - * @param oid Pointer where to store the OID of the - * newly created tag - * - * @param repo Repository where to store the tag - * - * @param tag_name Name for the tag - * - * @param target Object to which this tag points. This object - * must belong to the given `repo`. - * - * @param tagger Signature of the tagger for this tag, and - * of the tagging time - * - * @param message Full message for this tag - * - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_tag_annotation_create( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message); - -/** - * Create a new tag in the repository from a buffer - * - * @param oid Pointer where to store the OID of the newly created tag - * @param repo Repository where to store the tag - * @param buffer Raw tag data - * @param force Overwrite existing tags - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_tag_create_from_buffer( - git_oid *oid, - git_repository *repo, - const char *buffer, - int force); - -/** - * Create a new lightweight tag pointing at a target object - * - * A new direct reference will be created pointing to - * this target object. If `force` is true and a reference - * already exists with the given name, it'll be replaced. - * - * The tag name will be checked for validity. - * See `git_tag_create()` for rules about valid names. - * - * @param oid Pointer where to store the OID of the provided - * target object. If the tag already exists, this parameter - * will be filled with the oid of the existing pointed object - * and the function will return a GIT_EEXISTS error code. - * - * @param repo Repository where to store the lightweight tag - * - * @param tag_name Name for the tag; this name is validated - * for consistency. It should also not conflict with an - * already existing tag name - * - * @param target Object to which this tag points. This object - * must belong to the given `repo`. - * - * @param force Overwrite existing references - * - * @return 0 on success, GIT_EINVALIDSPEC or an error code - * A proper reference is written in the /refs/tags folder, - * pointing to the provided target object - */ -GIT_EXTERN(int) git_tag_create_lightweight( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - int force); - -/** - * Delete an existing tag reference. - * - * The tag name will be checked for validity. - * See `git_tag_create()` for rules about valid names. - * - * @param repo Repository where lives the tag - * - * @param tag_name Name of the tag to be deleted; - * this name is validated for consistency. - * - * @return 0 on success, GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_tag_delete( - git_repository *repo, - const char *tag_name); - -/** - * Fill a list with all the tags in the Repository - * - * The string array will be filled with the names of the - * matching tags; these values are owned by the user and - * should be free'd manually when no longer needed, using - * `git_strarray_free`. - * - * @param tag_names Pointer to a git_strarray structure where - * the tag names will be stored - * @param repo Repository where to find the tags - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tag_list( - git_strarray *tag_names, - git_repository *repo); - -/** - * Fill a list with all the tags in the Repository - * which name match a defined pattern - * - * If an empty pattern is provided, all the tags - * will be returned. - * - * The string array will be filled with the names of the - * matching tags; these values are owned by the user and - * should be free'd manually when no longer needed, using - * `git_strarray_free`. - * - * @param tag_names Pointer to a git_strarray structure where - * the tag names will be stored - * @param pattern Standard fnmatch pattern - * @param repo Repository where to find the tags - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tag_list_match( - git_strarray *tag_names, - const char *pattern, - git_repository *repo); - -/** - * Callback used to iterate over tag names - * - * @see git_tag_foreach - * - * @param name The tag name - * @param oid The tag's OID - * @param payload Payload passed to git_tag_foreach - * @return non-zero to terminate the iteration - */ -typedef int GIT_CALLBACK(git_tag_foreach_cb)(const char *name, git_oid *oid, void *payload); - -/** - * Call callback `cb' for each tag in the repository - * - * @param repo Repository - * @param callback Callback function - * @param payload Pointer to callback data (optional) - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_tag_foreach( - git_repository *repo, - git_tag_foreach_cb callback, - void *payload); - - -/** - * Recursively peel a tag until a non tag git_object is found - * - * The retrieved `tag_target` object is owned by the repository - * and should be closed with the `git_object_free` method. - * - * @param tag_target_out Pointer to the peeled git_object - * @param tag The tag to be processed - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tag_peel( - git_object **tag_target_out, - const git_tag *tag); - -/** - * Create an in-memory copy of a tag. The copy must be explicitly - * free'd or it will leak. - * - * @param out Pointer to store the copy of the tag - * @param source Original tag to copy - * @return 0 - */ -GIT_EXTERN(int) git_tag_dup(git_tag **out, git_tag *source); - -/** - * Determine whether a tag name is valid, meaning that (when prefixed - * with `refs/tags/`) that it is a valid reference name, and that any - * additional tag name restrictions are imposed (eg, it cannot start - * with a `-`). - * - * @param valid output pointer to set with validity of given tag name - * @param name a tag name to test - * @return 0 on success or an error code - */ -GIT_EXTERN(int) git_tag_name_is_valid(int *valid, const char *name); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/trace.h b/vendor/libgit2-sys/libgit2/include/git2/trace.h deleted file mode 100644 index 62cb87c..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/trace.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_trace_h__ -#define INCLUDE_git_trace_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/trace.h - * @brief Tracing functionality to introspect libgit2 in your application - * @defgroup git_trace Tracing functionality to introspect libgit2 in your application - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Available tracing levels. When tracing is set to a particular level, - * callers will be provided tracing at the given level and all lower levels. - */ -typedef enum { - /** No tracing will be performed. */ - GIT_TRACE_NONE = 0, - - /** Severe errors that may impact the program's execution */ - GIT_TRACE_FATAL = 1, - - /** Errors that do not impact the program's execution */ - GIT_TRACE_ERROR = 2, - - /** Warnings that suggest abnormal data */ - GIT_TRACE_WARN = 3, - - /** Informational messages about program execution */ - GIT_TRACE_INFO = 4, - - /** Detailed data that allows for debugging */ - GIT_TRACE_DEBUG = 5, - - /** Exceptionally detailed debugging data */ - GIT_TRACE_TRACE = 6 -} git_trace_level_t; - -/** - * An instance for a tracing function - * - * @param level the trace level - * @param msg the trace message - */ -typedef void GIT_CALLBACK(git_trace_cb)( - git_trace_level_t level, - const char *msg); - -/** - * Sets the system tracing configuration to the specified level with the - * specified callback. When system events occur at a level equal to, or - * lower than, the given level they will be reported to the given callback. - * - * @param level Level to set tracing to - * @param cb Function to call with trace data - * @return 0 or an error code - */ -GIT_EXTERN(int) git_trace_set(git_trace_level_t level, git_trace_cb cb); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/transaction.h b/vendor/libgit2-sys/libgit2/include/git2/transaction.h deleted file mode 100644 index 212d329..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/transaction.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_transaction_h__ -#define INCLUDE_git_transaction_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/transaction.h - * @brief Transactional reference handling - * @defgroup git_transaction Transactional reference handling - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create a new transaction object - * - * This does not lock anything, but sets up the transaction object to - * know from which repository to lock. - * - * @param out the resulting transaction - * @param repo the repository in which to lock - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transaction_new(git_transaction **out, git_repository *repo); - -/** - * Lock a reference - * - * Lock the specified reference. This is the first step to updating a - * reference. - * - * @param tx the transaction - * @param refname the reference to lock - * @return 0 or an error message - */ -GIT_EXTERN(int) git_transaction_lock_ref(git_transaction *tx, const char *refname); - -/** - * Set the target of a reference - * - * Set the target of the specified reference. This reference must be - * locked. - * - * @param tx the transaction - * @param refname reference to update - * @param target target to set the reference to - * @param sig signature to use in the reflog; pass NULL to read the identity from the config - * @param msg message to use in the reflog - * @return 0, GIT_ENOTFOUND if the reference is not among the locked ones, or an error code - */ -GIT_EXTERN(int) git_transaction_set_target(git_transaction *tx, const char *refname, const git_oid *target, const git_signature *sig, const char *msg); - -/** - * Set the target of a reference - * - * Set the target of the specified reference. This reference must be - * locked. - * - * @param tx the transaction - * @param refname reference to update - * @param target target to set the reference to - * @param sig signature to use in the reflog; pass NULL to read the identity from the config - * @param msg message to use in the reflog - * @return 0, GIT_ENOTFOUND if the reference is not among the locked ones, or an error code - */ -GIT_EXTERN(int) git_transaction_set_symbolic_target(git_transaction *tx, const char *refname, const char *target, const git_signature *sig, const char *msg); - -/** - * Set the reflog of a reference - * - * Set the specified reference's reflog. If this is combined with - * setting the target, that update won't be written to the reflog. - * - * @param tx the transaction - * @param refname the reference whose reflog to set - * @param reflog the reflog as it should be written out - * @return 0, GIT_ENOTFOUND if the reference is not among the locked ones, or an error code - */ -GIT_EXTERN(int) git_transaction_set_reflog(git_transaction *tx, const char *refname, const git_reflog *reflog); - -/** - * Remove a reference - * - * @param tx the transaction - * @param refname the reference to remove - * @return 0, GIT_ENOTFOUND if the reference is not among the locked ones, or an error code - */ -GIT_EXTERN(int) git_transaction_remove(git_transaction *tx, const char *refname); - -/** - * Commit the changes from the transaction - * - * Perform the changes that have been queued. The updates will be made - * one by one, and the first failure will stop the processing. - * - * @param tx the transaction - * @return 0 or an error code - */ -GIT_EXTERN(int) git_transaction_commit(git_transaction *tx); - -/** - * Free the resources allocated by this transaction - * - * If any references remain locked, they will be unlocked without any - * changes made to them. - * - * @param tx the transaction - */ -GIT_EXTERN(void) git_transaction_free(git_transaction *tx); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/transport.h b/vendor/libgit2-sys/libgit2/include/git2/transport.h deleted file mode 100644 index 04a7390..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/transport.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_transport_h__ -#define INCLUDE_git_transport_h__ - -#include "indexer.h" -#include "net.h" -#include "types.h" -#include "cert.h" -#include "credential.h" - -/** - * @file git2/transport.h - * @brief Transports are the low-level mechanism to connect to a remote server - * @defgroup git_transport Transports are the low-level mechanism to connect to a remote server - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Callback for messages received by the transport. - * - * Return a negative value to cancel the network operation. - * - * @param str The message from the transport - * @param len The length of the message - * @param payload Payload provided by the caller - * @return 0 on success or an error code - */ -typedef int GIT_CALLBACK(git_transport_message_cb)(const char *str, int len, void *payload); - -/** - * Signature of a function which creates a transport. - * - * @param out the transport generate - * @param owner the owner for the transport - * @param param the param to the transport creation - * @return 0 on success or an error code - */ -typedef int GIT_CALLBACK(git_transport_cb)(git_transport **out, git_remote *owner, void *param); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/tree.h b/vendor/libgit2-sys/libgit2/include/git2/tree.h deleted file mode 100644 index b8e2de2..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/tree.h +++ /dev/null @@ -1,486 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_tree_h__ -#define INCLUDE_git_tree_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "object.h" - -/** - * @file git2/tree.h - * @brief Trees are collections of files and folders to make up the repository hierarchy - * @defgroup git_tree Trees are collections of files and folders to make up the repository hierarchy - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a tree object from the repository. - * - * @param[out] out Pointer to the looked up tree - * @param repo The repo to use when locating the tree. - * @param id Identity of the tree to locate. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tree_lookup( - git_tree **out, git_repository *repo, const git_oid *id); - -/** - * Lookup a tree object from the repository, - * given a prefix of its identifier (short id). - * - * @see git_object_lookup_prefix - * - * @param out pointer to the looked up tree - * @param repo the repo to use when locating the tree. - * @param id identity of the tree to locate. - * @param len the length of the short identifier - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tree_lookup_prefix( - git_tree **out, - git_repository *repo, - const git_oid *id, - size_t len); - -/** - * Close an open tree - * - * You can no longer use the git_tree pointer after this call. - * - * IMPORTANT: You MUST call this method when you stop using a tree to - * release memory. Failure to do so will cause a memory leak. - * - * @param tree The tree to close - */ -GIT_EXTERN(void) git_tree_free(git_tree *tree); - -/** - * Get the id of a tree. - * - * @param tree a previously loaded tree. - * @return object identity for the tree. - */ -GIT_EXTERN(const git_oid *) git_tree_id(const git_tree *tree); - -/** - * Get the repository that contains the tree. - * - * @param tree A previously loaded tree. - * @return Repository that contains this tree. - */ -GIT_EXTERN(git_repository *) git_tree_owner(const git_tree *tree); - -/** - * Get the number of entries listed in a tree - * - * @param tree a previously loaded tree. - * @return the number of entries in the tree - */ -GIT_EXTERN(size_t) git_tree_entrycount(const git_tree *tree); - -/** - * Lookup a tree entry by its filename - * - * This returns a git_tree_entry that is owned by the git_tree. You don't - * have to free it, but you must not use it after the git_tree is released. - * - * @param tree a previously loaded tree. - * @param filename the filename of the desired entry - * @return the tree entry; NULL if not found - */ -GIT_EXTERN(const git_tree_entry *) git_tree_entry_byname( - const git_tree *tree, const char *filename); - -/** - * Lookup a tree entry by its position in the tree - * - * This returns a git_tree_entry that is owned by the git_tree. You don't - * have to free it, but you must not use it after the git_tree is released. - * - * @param tree a previously loaded tree. - * @param idx the position in the entry list - * @return the tree entry; NULL if not found - */ -GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex( - const git_tree *tree, size_t idx); - -/** - * Lookup a tree entry by SHA value. - * - * This returns a git_tree_entry that is owned by the git_tree. You don't - * have to free it, but you must not use it after the git_tree is released. - * - * Warning: this must examine every entry in the tree, so it is not fast. - * - * @param tree a previously loaded tree. - * @param id the sha being looked for - * @return the tree entry; NULL if not found - */ -GIT_EXTERN(const git_tree_entry *) git_tree_entry_byid( - const git_tree *tree, const git_oid *id); - -/** - * Retrieve a tree entry contained in a tree or in any of its subtrees, - * given its relative path. - * - * Unlike the other lookup functions, the returned tree entry is owned by - * the user and must be freed explicitly with `git_tree_entry_free()`. - * - * @param out Pointer where to store the tree entry - * @param root Previously loaded tree which is the root of the relative path - * @param path Path to the contained entry - * @return 0 on success; GIT_ENOTFOUND if the path does not exist - */ -GIT_EXTERN(int) git_tree_entry_bypath( - git_tree_entry **out, - const git_tree *root, - const char *path); - -/** - * Duplicate a tree entry - * - * Create a copy of a tree entry. The returned copy is owned by the user, - * and must be freed explicitly with `git_tree_entry_free()`. - * - * @param dest pointer where to store the copy - * @param source tree entry to duplicate - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tree_entry_dup(git_tree_entry **dest, const git_tree_entry *source); - -/** - * Free a user-owned tree entry - * - * IMPORTANT: This function is only needed for tree entries owned by the - * user, such as the ones returned by `git_tree_entry_dup()` or - * `git_tree_entry_bypath()`. - * - * @param entry The entry to free - */ -GIT_EXTERN(void) git_tree_entry_free(git_tree_entry *entry); - -/** - * Get the filename of a tree entry - * - * @param entry a tree entry - * @return the name of the file - */ -GIT_EXTERN(const char *) git_tree_entry_name(const git_tree_entry *entry); - -/** - * Get the id of the object pointed by the entry - * - * @param entry a tree entry - * @return the oid of the object - */ -GIT_EXTERN(const git_oid *) git_tree_entry_id(const git_tree_entry *entry); - -/** - * Get the type of the object pointed by the entry - * - * @param entry a tree entry - * @return the type of the pointed object - */ -GIT_EXTERN(git_object_t) git_tree_entry_type(const git_tree_entry *entry); - -/** - * Get the UNIX file attributes of a tree entry - * - * @param entry a tree entry - * @return filemode as an integer - */ -GIT_EXTERN(git_filemode_t) git_tree_entry_filemode(const git_tree_entry *entry); - -/** - * Get the raw UNIX file attributes of a tree entry - * - * This function does not perform any normalization and is only useful - * if you need to be able to recreate the original tree object. - * - * @param entry a tree entry - * @return filemode as an integer - */ - -GIT_EXTERN(git_filemode_t) git_tree_entry_filemode_raw(const git_tree_entry *entry); -/** - * Compare two tree entries - * - * @param e1 first tree entry - * @param e2 second tree entry - * @return <0 if e1 is before e2, 0 if e1 == e2, >0 if e1 is after e2 - */ -GIT_EXTERN(int) git_tree_entry_cmp(const git_tree_entry *e1, const git_tree_entry *e2); - -/** - * Convert a tree entry to the git_object it points to. - * - * You must call `git_object_free()` on the object when you are done with it. - * - * @param object_out pointer to the converted object - * @param repo repository where to lookup the pointed object - * @param entry a tree entry - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tree_entry_to_object( - git_object **object_out, - git_repository *repo, - const git_tree_entry *entry); - -/** - * Create a new tree builder. - * - * The tree builder can be used to create or modify trees in memory and - * write them as tree objects to the database. - * - * If the `source` parameter is not NULL, the tree builder will be - * initialized with the entries of the given tree. - * - * If the `source` parameter is NULL, the tree builder will start with no - * entries and will have to be filled manually. - * - * @param out Pointer where to store the tree builder - * @param repo Repository in which to store the object - * @param source Source tree to initialize the builder (optional) - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_treebuilder_new( - git_treebuilder **out, git_repository *repo, const git_tree *source); - -/** - * Clear all the entries in the builder - * - * @param bld Builder to clear - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_treebuilder_clear(git_treebuilder *bld); - -/** - * Get the number of entries listed in a treebuilder - * - * @param bld a previously loaded treebuilder. - * @return the number of entries in the treebuilder - */ -GIT_EXTERN(size_t) git_treebuilder_entrycount(git_treebuilder *bld); - -/** - * Free a tree builder - * - * This will clear all the entries and free to builder. - * Failing to free the builder after you're done using it - * will result in a memory leak - * - * @param bld Builder to free - */ -GIT_EXTERN(void) git_treebuilder_free(git_treebuilder *bld); - -/** - * Get an entry from the builder from its filename - * - * The returned entry is owned by the builder and should - * not be freed manually. - * - * @param bld Tree builder - * @param filename Name of the entry - * @return pointer to the entry; NULL if not found - */ -GIT_EXTERN(const git_tree_entry *) git_treebuilder_get( - git_treebuilder *bld, const char *filename); - -/** - * Add or update an entry to the builder - * - * Insert a new entry for `filename` in the builder with the - * given attributes. - * - * If an entry named `filename` already exists, its attributes - * will be updated with the given ones. - * - * The optional pointer `out` can be used to retrieve a pointer to the - * newly created/updated entry. Pass NULL if you do not need it. The - * pointer may not be valid past the next operation in this - * builder. Duplicate the entry if you want to keep it. - * - * By default the entry that you are inserting will be checked for - * validity; that it exists in the object database and is of the - * correct type. If you do not want this behavior, set the - * `GIT_OPT_ENABLE_STRICT_OBJECT_CREATION` library option to false. - * - * @param out Pointer to store the entry (optional) - * @param bld Tree builder - * @param filename Filename of the entry - * @param id SHA1 oid of the entry - * @param filemode Folder attributes of the entry. This parameter must - * be valued with one of the following entries: 0040000, 0100644, - * 0100755, 0120000 or 0160000. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_treebuilder_insert( - const git_tree_entry **out, - git_treebuilder *bld, - const char *filename, - const git_oid *id, - git_filemode_t filemode); - -/** - * Remove an entry from the builder by its filename - * - * @param bld Tree builder - * @param filename Filename of the entry to remove - * @return 0 or an error code - */ -GIT_EXTERN(int) git_treebuilder_remove( - git_treebuilder *bld, const char *filename); - -/** - * Callback for git_treebuilder_filter - * - * The return value is treated as a boolean, with zero indicating that the - * entry should be left alone and any non-zero value meaning that the - * entry should be removed from the treebuilder list (i.e. filtered out). - * - * @param entry the tree entry for the callback to examine - * @param payload the payload from the caller - * @return 0 to do nothing, non-zero to remove the entry - */ -typedef int GIT_CALLBACK(git_treebuilder_filter_cb)( - const git_tree_entry *entry, void *payload); - -/** - * Selectively remove entries in the tree - * - * The `filter` callback will be called for each entry in the tree with a - * pointer to the entry and the provided `payload`; if the callback returns - * non-zero, the entry will be filtered (removed from the builder). - * - * @param bld Tree builder - * @param filter Callback to filter entries - * @param payload Extra data to pass to filter callback - * @return 0 on success, non-zero callback return value, or error code - */ -GIT_EXTERN(int) git_treebuilder_filter( - git_treebuilder *bld, - git_treebuilder_filter_cb filter, - void *payload); - -/** - * Write the contents of the tree builder as a tree object - * - * The tree builder will be written to the given `repo`, and its - * identifying SHA1 hash will be stored in the `id` pointer. - * - * @param id Pointer to store the OID of the newly written tree - * @param bld Tree builder to write - * @return 0 or an error code - */ -GIT_EXTERN(int) git_treebuilder_write( - git_oid *id, git_treebuilder *bld); - -/** - * Callback for the tree traversal method. - * - * @param root the current (relative) root to the entry - * @param entry the tree entry - * @param payload the caller-provided callback payload - * @return a positive value to skip the entry, a negative value to stop the walk - */ -typedef int GIT_CALLBACK(git_treewalk_cb)( - const char *root, const git_tree_entry *entry, void *payload); - -/** Tree traversal modes */ -typedef enum { - GIT_TREEWALK_PRE = 0, /* Pre-order */ - GIT_TREEWALK_POST = 1 /* Post-order */ -} git_treewalk_mode; - -/** - * Traverse the entries in a tree and its subtrees in post or pre order. - * - * The entries will be traversed in the specified order, children subtrees - * will be automatically loaded as required, and the `callback` will be - * called once per entry with the current (relative) root for the entry and - * the entry data itself. - * - * If the callback returns a positive value, the passed entry will be - * skipped on the traversal (in pre mode). A negative value stops the walk. - * - * @param tree The tree to walk - * @param mode Traversal mode (pre or post-order) - * @param callback Function to call on each tree entry - * @param payload Opaque pointer to be passed on each callback - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tree_walk( - const git_tree *tree, - git_treewalk_mode mode, - git_treewalk_cb callback, - void *payload); - -/** - * Create an in-memory copy of a tree. The copy must be explicitly - * free'd or it will leak. - * - * @param out Pointer to store the copy of the tree - * @param source Original tree to copy - * @return 0 - */ -GIT_EXTERN(int) git_tree_dup(git_tree **out, git_tree *source); - -/** - * The kind of update to perform - */ -typedef enum { - /** Update or insert an entry at the specified path */ - GIT_TREE_UPDATE_UPSERT, - /** Remove an entry from the specified path */ - GIT_TREE_UPDATE_REMOVE -} git_tree_update_t; - -/** - * An action to perform during the update of a tree - */ -typedef struct { - /** Update action. If it's an removal, only the path is looked at */ - git_tree_update_t action; - /** The entry's id */ - git_oid id; - /** The filemode/kind of object */ - git_filemode_t filemode; - /** The full path from the root tree */ - const char *path; -} git_tree_update; - -/** - * Create a tree based on another one with the specified modifications - * - * Given the `baseline` perform the changes described in the list of - * `updates` and create a new tree. - * - * This function is optimized for common file/directory addition, removal and - * replacement in trees. It is much more efficient than reading the tree into a - * `git_index` and modifying that, but in exchange it is not as flexible. - * - * Deleting and adding the same entry is undefined behaviour, changing - * a tree to a blob or viceversa is not supported. - * - * @param out id of the new tree - * @param repo the repository in which to create the tree, must be the - * same as for `baseline` - * @param baseline the tree to base these changes on - * @param nupdates the number of elements in the update list - * @param updates the list of updates to perform - * @return 0 or an error code - */ -GIT_EXTERN(int) git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseline, size_t nupdates, const git_tree_update *updates); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/types.h b/vendor/libgit2-sys/libgit2/include/git2/types.h deleted file mode 100644 index a4afd18..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/types.h +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_types_h__ -#define INCLUDE_git_types_h__ - -#include "common.h" - -/** - * @file git2/types.h - * @brief libgit2 base & compatibility types - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Cross-platform compatibility types for off_t / time_t - * - * NOTE: This needs to be in a public header so that both the library - * implementation and client applications both agree on the same types. - * Otherwise we get undefined behavior. - * - * Use the "best" types that each platform provides. Currently we truncate - * these intermediate representations for compatibility with the git ABI, but - * if and when it changes to support 64 bit types, our code will naturally - * adapt. - * NOTE: These types should match those that are returned by our internal - * stat() functions, for all platforms. - */ -#include -#ifdef __amigaos4__ -#include -#endif - -#if defined(_MSC_VER) - -typedef __int64 git_off_t; -typedef __time64_t git_time_t; - -#elif defined(__MINGW32__) - -typedef off64_t git_off_t; -typedef __time64_t git_time_t; - -#elif defined(__HAIKU__) - -typedef __haiku_std_int64 git_off_t; -typedef __haiku_std_int64 git_time_t; - -#else /* POSIX */ - -/* - * Note: Can't use off_t since if a client program includes - * before us (directly or indirectly), they'll get 32 bit off_t in their client - * app, even though /we/ define _FILE_OFFSET_BITS=64. - */ -typedef int64_t git_off_t; -typedef int64_t git_time_t; /**< time in seconds from epoch */ - -#endif - -/** The maximum size of an object */ -typedef uint64_t git_object_size_t; - -#include "buffer.h" -#include "oid.h" - -/** Basic type (loose or packed) of any Git object. */ -typedef enum { - GIT_OBJECT_ANY = -2, /**< Object can be any of the following */ - GIT_OBJECT_INVALID = -1, /**< Object is invalid. */ - GIT_OBJECT_COMMIT = 1, /**< A commit object. */ - GIT_OBJECT_TREE = 2, /**< A tree (directory listing) object. */ - GIT_OBJECT_BLOB = 3, /**< A file revision object. */ - GIT_OBJECT_TAG = 4, /**< An annotated tag object. */ - GIT_OBJECT_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ - GIT_OBJECT_REF_DELTA = 7 /**< A delta, base is given by object id. */ -} git_object_t; - -/** - * An object database stores the objects (commit, trees, blobs, tags, - * etc) for a repository. - */ -typedef struct git_odb git_odb; - -/** A custom backend in an ODB */ -typedef struct git_odb_backend git_odb_backend; - -/** - * A "raw" object read from the object database. - */ -typedef struct git_odb_object git_odb_object; - -/** A stream to read/write from the ODB */ -typedef struct git_odb_stream git_odb_stream; - -/** A stream to write a packfile to the ODB */ -typedef struct git_odb_writepack git_odb_writepack; - -/** a writer for multi-pack-index files. */ -typedef struct git_midx_writer git_midx_writer; - -/** An open refs database handle. */ -typedef struct git_refdb git_refdb; - -/** A custom backend for refs */ -typedef struct git_refdb_backend git_refdb_backend; - -/** A git commit-graph */ -typedef struct git_commit_graph git_commit_graph; - -/** a writer for commit-graph files. */ -typedef struct git_commit_graph_writer git_commit_graph_writer; - -/** - * Representation of an existing git repository, - * including all its object contents - */ -typedef struct git_repository git_repository; - -/** Representation of a working tree */ -typedef struct git_worktree git_worktree; - -/** Representation of a generic object in a repository */ -typedef struct git_object git_object; - -/** Representation of an in-progress walk through the commits in a repo */ -typedef struct git_revwalk git_revwalk; - -/** Parsed representation of a tag object. */ -typedef struct git_tag git_tag; - -/** In-memory representation of a blob object. */ -typedef struct git_blob git_blob; - -/** Parsed representation of a commit object. */ -typedef struct git_commit git_commit; - -/** Representation of each one of the entries in a tree object. */ -typedef struct git_tree_entry git_tree_entry; - -/** Representation of a tree object. */ -typedef struct git_tree git_tree; - -/** Constructor for in-memory trees */ -typedef struct git_treebuilder git_treebuilder; - -/** Memory representation of an index file. */ -typedef struct git_index git_index; - -/** An iterator for entries in the index. */ -typedef struct git_index_iterator git_index_iterator; - -/** An iterator for conflicts in the index. */ -typedef struct git_index_conflict_iterator git_index_conflict_iterator; - -/** Memory representation of a set of config files */ -typedef struct git_config git_config; - -/** Interface to access a configuration file */ -typedef struct git_config_backend git_config_backend; - -/** Representation of a reference log entry */ -typedef struct git_reflog_entry git_reflog_entry; - -/** Representation of a reference log */ -typedef struct git_reflog git_reflog; - -/** Representation of a git note */ -typedef struct git_note git_note; - -/** Representation of a git packbuilder */ -typedef struct git_packbuilder git_packbuilder; - -/** Time in a signature */ -typedef struct git_time { - git_time_t time; /**< time in seconds from epoch */ - int offset; /**< timezone offset, in minutes */ - char sign; /**< indicator for questionable '-0000' offsets in signature */ -} git_time; - -/** An action signature (e.g. for committers, taggers, etc) */ -typedef struct git_signature { - char *name; /**< full name of the author */ - char *email; /**< email of the author */ - git_time when; /**< time when the action happened */ -} git_signature; - -/** In-memory representation of a reference. */ -typedef struct git_reference git_reference; - -/** Iterator for references */ -typedef struct git_reference_iterator git_reference_iterator; - -/** Transactional interface to references */ -typedef struct git_transaction git_transaction; - -/** - * Annotated commits are commits with additional metadata about how the - * commit was resolved, which can be used for maintaining the user's - * "intent" through commands like merge and rebase. - * - * For example, if a user wants to conceptually "merge `HEAD`", then the - * commit portion of an annotated commit will point to the `HEAD` commit, - * but the _annotation_ will denote the ref `HEAD`. This allows git to - * perform the internal bookkeeping so that the system knows both the - * content of what is being merged but also how the content was looked up - * so that it can be recorded in the reflog appropriately. - */ -typedef struct git_annotated_commit git_annotated_commit; - -/** Representation of a status collection */ -typedef struct git_status_list git_status_list; - -/** Representation of a rebase */ -typedef struct git_rebase git_rebase; - -/** Basic type of any Git reference. */ -typedef enum { - GIT_REFERENCE_INVALID = 0, /**< Invalid reference */ - GIT_REFERENCE_DIRECT = 1, /**< A reference that points at an object id */ - GIT_REFERENCE_SYMBOLIC = 2, /**< A reference that points at another reference */ - GIT_REFERENCE_ALL = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC -} git_reference_t; - -/** Basic type of any Git branch. */ -typedef enum { - GIT_BRANCH_LOCAL = 1, - GIT_BRANCH_REMOTE = 2, - GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE -} git_branch_t; - -/** Valid modes for index and tree entries. */ -typedef enum { - GIT_FILEMODE_UNREADABLE = 0000000, - GIT_FILEMODE_TREE = 0040000, - GIT_FILEMODE_BLOB = 0100644, - GIT_FILEMODE_BLOB_EXECUTABLE = 0100755, - GIT_FILEMODE_LINK = 0120000, - GIT_FILEMODE_COMMIT = 0160000 -} git_filemode_t; - -/** - * A refspec specifies the mapping between remote and local reference - * names when fetch or pushing. - */ -typedef struct git_refspec git_refspec; - -/** - * Git's idea of a remote repository. A remote can be anonymous (in - * which case it does not have backing configuration entries). - */ -typedef struct git_remote git_remote; - -/** - * Interface which represents a transport to communicate with a - * remote. - */ -typedef struct git_transport git_transport; - -/** - * Preparation for a push operation. Can be used to configure what to - * push and the level of parallelism of the packfile builder. - */ -typedef struct git_push git_push; - -/* documentation in the definition */ -typedef struct git_remote_head git_remote_head; -typedef struct git_remote_callbacks git_remote_callbacks; - -/** - * Parent type for `git_cert_hostkey` and `git_cert_x509`. - */ -typedef struct git_cert git_cert; - -/** - * Opaque structure representing a submodule. - */ -typedef struct git_submodule git_submodule; - -/** - * Submodule update values - * - * These values represent settings for the `submodule.$name.update` - * configuration value which says how to handle `git submodule update` for - * this submodule. The value is usually set in the ".gitmodules" file and - * copied to ".git/config" when the submodule is initialized. - * - * You can override this setting on a per-submodule basis with - * `git_submodule_set_update()` and write the changed value to disk using - * `git_submodule_save()`. If you have overwritten the value, you can - * revert it by passing `GIT_SUBMODULE_UPDATE_RESET` to the set function. - * - * The values are: - * - * - GIT_SUBMODULE_UPDATE_CHECKOUT: the default; when a submodule is - * updated, checkout the new detached HEAD to the submodule directory. - * - GIT_SUBMODULE_UPDATE_REBASE: update by rebasing the current checked - * out branch onto the commit from the superproject. - * - GIT_SUBMODULE_UPDATE_MERGE: update by merging the commit in the - * superproject into the current checkout out branch of the submodule. - * - GIT_SUBMODULE_UPDATE_NONE: do not update this submodule even when - * the commit in the superproject is updated. - * - GIT_SUBMODULE_UPDATE_DEFAULT: not used except as static initializer - * when we don't want any particular update rule to be specified. - */ -typedef enum { - GIT_SUBMODULE_UPDATE_CHECKOUT = 1, - GIT_SUBMODULE_UPDATE_REBASE = 2, - GIT_SUBMODULE_UPDATE_MERGE = 3, - GIT_SUBMODULE_UPDATE_NONE = 4, - - GIT_SUBMODULE_UPDATE_DEFAULT = 0 -} git_submodule_update_t; - -/** - * Submodule ignore values - * - * These values represent settings for the `submodule.$name.ignore` - * configuration value which says how deeply to look at the working - * directory when getting submodule status. - * - * You can override this value in memory on a per-submodule basis with - * `git_submodule_set_ignore()` and can write the changed value to disk - * with `git_submodule_save()`. If you have overwritten the value, you - * can revert to the on disk value by using `GIT_SUBMODULE_IGNORE_RESET`. - * - * The values are: - * - * - GIT_SUBMODULE_IGNORE_UNSPECIFIED: use the submodule's configuration - * - GIT_SUBMODULE_IGNORE_NONE: don't ignore any change - i.e. even an - * untracked file, will mark the submodule as dirty. Ignored files are - * still ignored, of course. - * - GIT_SUBMODULE_IGNORE_UNTRACKED: ignore untracked files; only changes - * to tracked files, or the index or the HEAD commit will matter. - * - GIT_SUBMODULE_IGNORE_DIRTY: ignore changes in the working directory, - * only considering changes if the HEAD of submodule has moved from the - * value in the superproject. - * - GIT_SUBMODULE_IGNORE_ALL: never check if the submodule is dirty - * - GIT_SUBMODULE_IGNORE_DEFAULT: not used except as static initializer - * when we don't want any particular ignore rule to be specified. - */ -typedef enum { - GIT_SUBMODULE_IGNORE_UNSPECIFIED = -1, /**< use the submodule's configuration */ - - GIT_SUBMODULE_IGNORE_NONE = 1, /**< any change or untracked == dirty */ - GIT_SUBMODULE_IGNORE_UNTRACKED = 2, /**< dirty if tracked files change */ - GIT_SUBMODULE_IGNORE_DIRTY = 3, /**< only dirty if HEAD moved */ - GIT_SUBMODULE_IGNORE_ALL = 4 /**< never dirty */ -} git_submodule_ignore_t; - -/** - * Options for submodule recurse. - * - * Represent the value of `submodule.$name.fetchRecurseSubmodules` - * - * * GIT_SUBMODULE_RECURSE_NO - do no recurse into submodules - * * GIT_SUBMODULE_RECURSE_YES - recurse into submodules - * * GIT_SUBMODULE_RECURSE_ONDEMAND - recurse into submodules only when - * commit not already in local clone - */ -typedef enum { - GIT_SUBMODULE_RECURSE_NO = 0, - GIT_SUBMODULE_RECURSE_YES = 1, - GIT_SUBMODULE_RECURSE_ONDEMAND = 2 -} git_submodule_recurse_t; - -typedef struct git_writestream git_writestream; - -/** A type to write in a streaming fashion, for example, for filters. */ -struct git_writestream { - int GIT_CALLBACK(write)(git_writestream *stream, const char *buffer, size_t len); - int GIT_CALLBACK(close)(git_writestream *stream); - void GIT_CALLBACK(free)(git_writestream *stream); -}; - -/** Representation of .mailmap file state. */ -typedef struct git_mailmap git_mailmap; - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/version.h b/vendor/libgit2-sys/libgit2/include/git2/version.h deleted file mode 100644 index 8f55ea1..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/version.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_version_h__ -#define INCLUDE_git_version_h__ - -#include "common.h" - -/** - * @file git2/version.h - * @brief The version of libgit2 - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * The version string for libgit2. This string follows semantic - * versioning (v2) guidelines. - */ -#define LIBGIT2_VERSION "1.9.7" - -/** The major version number for this version of libgit2. */ -#define LIBGIT2_VERSION_MAJOR 1 - -/** The minor version number for this version of libgit2. */ -#define LIBGIT2_VERSION_MINOR 9 - -/** The revision ("teeny") version number for this version of libgit2. */ -#define LIBGIT2_VERSION_REVISION 7 - -/** The Windows DLL patch number for this version of libgit2. */ -#define LIBGIT2_VERSION_PATCH 0 - -/** - * The prerelease string for this version of libgit2. For development - * (nightly) builds, this will be "alpha". For prereleases, this will be - * a prerelease name like "beta" or "rc1". For final releases, this will - * be `NULL`. - */ -#define LIBGIT2_VERSION_PRERELEASE NULL - -/** - * The library ABI soversion for this version of libgit2. This should - * only be changed when the library has a breaking ABI change, and so - * may not reflect the library's API version number. - */ -#define LIBGIT2_SOVERSION "1.9" - -/** - * An integer value representing the libgit2 version number. For example, - * libgit2 1.6.3 is 1060300. - */ -#define LIBGIT2_VERSION_NUMBER ( \ - (LIBGIT2_VERSION_MAJOR * 1000000) + \ - (LIBGIT2_VERSION_MINOR * 10000) + \ - (LIBGIT2_VERSION_REVISION * 100)) - -/** - * Compare the libgit2 version against a given version. Evaluates to true - * if the given major, minor, and revision values are greater than or equal - * to the currently running libgit2 version. For example: - * - * #if LIBGIT2_VERSION_CHECK(1, 6, 3) - * # error libgit2 version is >= 1.6.3 - * #endif - */ -#define LIBGIT2_VERSION_CHECK(major, minor, revision) \ - (LIBGIT2_VERSION_NUMBER >= ((major)*1000000)+((minor)*10000)+((revision)*100)) - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/include/git2/worktree.h b/vendor/libgit2-sys/libgit2/include/git2/worktree.h deleted file mode 100644 index fd37517..0000000 --- a/vendor/libgit2-sys/libgit2/include/git2/worktree.h +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git_worktree_h__ -#define INCLUDE_git_worktree_h__ - -#include "common.h" -#include "buffer.h" -#include "types.h" -#include "strarray.h" -#include "checkout.h" - -/** - * @file git2/worktree.h - * @brief Additional working directories for a repository - * @defgroup git_commit Additional working directories for a repository - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * List names of linked working trees - * - * The returned list should be released with `git_strarray_free` - * when no longer needed. - * - * @param out pointer to the array of working tree names - * @param repo the repo to use when listing working trees - * @return 0 or an error code - */ -GIT_EXTERN(int) git_worktree_list(git_strarray *out, git_repository *repo); - -/** - * Lookup a working tree by its name for a given repository - * - * @param out Output pointer to looked up worktree or `NULL` - * @param repo The repository containing worktrees - * @param name Name of the working tree to look up - * @return 0 or an error code - */ -GIT_EXTERN(int) git_worktree_lookup(git_worktree **out, git_repository *repo, const char *name); - -/** - * Open a worktree of a given repository - * - * If a repository is not the main tree but a worktree, this - * function will look up the worktree inside the parent - * repository and create a new `git_worktree` structure. - * - * @param out Out-pointer for the newly allocated worktree - * @param repo Repository to look up worktree for - * @return 0 or an error code - */ -GIT_EXTERN(int) git_worktree_open_from_repository(git_worktree **out, git_repository *repo); - -/** - * Free a previously allocated worktree - * - * @param wt worktree handle to close. If NULL nothing occurs. - */ -GIT_EXTERN(void) git_worktree_free(git_worktree *wt); - -/** - * Check if worktree is valid - * - * A valid worktree requires both the git data structures inside - * the linked parent repository and the linked working copy to be - * present. - * - * @param wt Worktree to check - * @return 0 when worktree is valid, error-code otherwise - */ -GIT_EXTERN(int) git_worktree_validate(const git_worktree *wt); - -/** - * Worktree add options structure - * - * Initialize with `GIT_WORKTREE_ADD_OPTIONS_INIT`. Alternatively, you can - * use `git_worktree_add_options_init`. - * - */ -typedef struct git_worktree_add_options { - unsigned int version; - - int lock; /**< lock newly created worktree */ - int checkout_existing; /**< allow checkout of existing branch matching worktree name */ - git_reference *ref; /**< reference to use for the new worktree HEAD */ - - /** - * Options for the checkout. - */ - git_checkout_options checkout_options; -} git_worktree_add_options; - -/** Current version for the `git_worktree_add_options` structure */ -#define GIT_WORKTREE_ADD_OPTIONS_VERSION 1 - -/** Static constructor for `git_worktree_add_options` */ -#define GIT_WORKTREE_ADD_OPTIONS_INIT { GIT_WORKTREE_ADD_OPTIONS_VERSION, \ - 0, 0, NULL, GIT_CHECKOUT_OPTIONS_INIT } - -/** - * Initialize git_worktree_add_options structure - * - * Initializes a `git_worktree_add_options` with default values. Equivalent to - * creating an instance with `GIT_WORKTREE_ADD_OPTIONS_INIT`. - * - * @param opts The `git_worktree_add_options` struct to initialize. - * @param version The struct version; pass `GIT_WORKTREE_ADD_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_worktree_add_options_init(git_worktree_add_options *opts, - unsigned int version); - -/** - * Add a new working tree - * - * Add a new working tree for the repository, that is create the - * required data structures inside the repository and check out - * the current HEAD at `path` - * - * @param out Output pointer containing new working tree - * @param repo Repository to create working tree for - * @param name Name of the working tree - * @param path Path to create working tree at - * @param opts Options to modify default behavior. May be NULL - * @return 0 or an error code - */ -GIT_EXTERN(int) git_worktree_add(git_worktree **out, git_repository *repo, - const char *name, const char *path, - const git_worktree_add_options *opts); - -/** - * Lock worktree if not already locked - * - * Lock a worktree, optionally specifying a reason why the linked - * working tree is being locked. - * - * @param wt Worktree to lock - * @param reason Reason why the working tree is being locked - * @return 0 on success, non-zero otherwise - */ -GIT_EXTERN(int) git_worktree_lock(git_worktree *wt, const char *reason); - -/** - * Unlock a locked worktree - * - * @param wt Worktree to unlock - * @return 0 on success, 1 if worktree was not locked, error-code - * otherwise - */ -GIT_EXTERN(int) git_worktree_unlock(git_worktree *wt); - -/** - * Check if worktree is locked - * - * A worktree may be locked if the linked working tree is stored - * on a portable device which is not available. - * - * @param reason Buffer to store reason in. If NULL no reason is stored. - * @param wt Worktree to check - * @return 0 when the working tree not locked, a value greater - * than zero if it is locked, less than zero if there was an - * error - */ -GIT_EXTERN(int) git_worktree_is_locked(git_buf *reason, const git_worktree *wt); - -/** - * Retrieve the name of the worktree - * - * @param wt Worktree to get the name for - * @return The worktree's name. The pointer returned is valid for the - * lifetime of the git_worktree - */ -GIT_EXTERN(const char *) git_worktree_name(const git_worktree *wt); - -/** - * Retrieve the filesystem path for the worktree - * - * @param wt Worktree to get the path for - * @return The worktree's filesystem path. The pointer returned - * is valid for the lifetime of the git_worktree. - */ -GIT_EXTERN(const char *) git_worktree_path(const git_worktree *wt); - -/** - * Flags which can be passed to git_worktree_prune to alter its - * behavior. - */ -typedef enum { - /* Prune working tree even if working tree is valid */ - GIT_WORKTREE_PRUNE_VALID = 1u << 0, - /* Prune working tree even if it is locked */ - GIT_WORKTREE_PRUNE_LOCKED = 1u << 1, - /* Prune checked out working tree */ - GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2 -} git_worktree_prune_t; - -/** - * Worktree prune options structure - * - * Initialize with `GIT_WORKTREE_PRUNE_OPTIONS_INIT`. Alternatively, you can - * use `git_worktree_prune_options_init`. - * - */ -typedef struct git_worktree_prune_options { - unsigned int version; - - /** A combination of `git_worktree_prune_t` */ - uint32_t flags; -} git_worktree_prune_options; - -/** Current version for the `git_worktree_prune_options` structure */ -#define GIT_WORKTREE_PRUNE_OPTIONS_VERSION 1 - -/** Static constructor for `git_worktree_prune_options` */ -#define GIT_WORKTREE_PRUNE_OPTIONS_INIT {GIT_WORKTREE_PRUNE_OPTIONS_VERSION,0} - -/** - * Initialize git_worktree_prune_options structure - * - * Initializes a `git_worktree_prune_options` with default values. Equivalent to - * creating an instance with `GIT_WORKTREE_PRUNE_OPTIONS_INIT`. - * - * @param opts The `git_worktree_prune_options` struct to initialize. - * @param version The struct version; pass `GIT_WORKTREE_PRUNE_OPTIONS_VERSION`. - * @return Zero on success; -1 on failure. - */ -GIT_EXTERN(int) git_worktree_prune_options_init( - git_worktree_prune_options *opts, - unsigned int version); - -/** - * Is the worktree prunable with the given options? - * - * A worktree is not prunable in the following scenarios: - * - * - the worktree is linking to a valid on-disk worktree. The - * `valid` member will cause this check to be ignored. - * - the worktree is locked. The `locked` flag will cause this - * check to be ignored. - * - * If the worktree is not valid and not locked or if the above - * flags have been passed in, this function will return a - * positive value. If the worktree is not prunable, an error - * message will be set (visible in `giterr_last`) with details about - * why. - * - * @param wt Worktree to check. - * @param opts The prunable options. - * @return 1 if the worktree is prunable, 0 otherwise, or an error code. - */ -GIT_EXTERN(int) git_worktree_is_prunable(git_worktree *wt, - git_worktree_prune_options *opts); - -/** - * Prune working tree - * - * Prune the working tree, that is remove the git data - * structures on disk. The repository will only be pruned of - * `git_worktree_is_prunable` succeeds. - * - * @param wt Worktree to prune - * @param opts Specifies which checks to override. See - * `git_worktree_is_prunable`. May be NULL - * @return 0 or an error code - */ -GIT_EXTERN(int) git_worktree_prune(git_worktree *wt, - git_worktree_prune_options *opts); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2-sys/libgit2/package.json b/vendor/libgit2-sys/libgit2/package.json deleted file mode 100644 index 695ac47..0000000 --- a/vendor/libgit2-sys/libgit2/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "libgit2", - "version": "1.9.7", - "repo": "https://github.com/libgit2/libgit2", - "description": " A cross-platform, linkable library implementation of Git that you can use in your application.", - "install": "mkdir build && cd build && cmake .. && cmake --build ." -} diff --git a/vendor/libgit2-sys/libgit2/script/api-docs/.gitignore b/vendor/libgit2-sys/libgit2/script/api-docs/.gitignore deleted file mode 100644 index c2658d7..0000000 --- a/vendor/libgit2-sys/libgit2/script/api-docs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/vendor/libgit2-sys/libgit2/script/api-docs/README.md b/vendor/libgit2-sys/libgit2/script/api-docs/README.md deleted file mode 100644 index fb329e2..0000000 --- a/vendor/libgit2-sys/libgit2/script/api-docs/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# API Documentation Generator - -These scripts generate the "raw API" specs and reference documentation -for [www.libgit2.org](https://libgit2.org/docs/reference). - -The "raw API" specs consists of JSON documents, on per -released version or branch, that describes the APIs. This is -suitable for creating documentation from, or may be useful for -language bindings as well. - -The reference documentation is documentation fragments for each -API in each version, ready to be included in the libgit2 documentation -website. diff --git a/vendor/libgit2-sys/libgit2/script/api-docs/api-generator.js b/vendor/libgit2-sys/libgit2/script/api-docs/api-generator.js deleted file mode 100755 index 47c928a..0000000 --- a/vendor/libgit2-sys/libgit2/script/api-docs/api-generator.js +++ /dev/null @@ -1,1558 +0,0 @@ -#!/usr/bin/env node - -const path = require('node:path'); -const child_process = require('node:child_process'); -const fs = require('node:fs').promises; -const util = require('node:util'); -const process = require('node:process'); - -const { program } = require('commander'); - -const includePath = (p) => `${p}/include`; -const ancientIncludePath = (p) => `${p}/src/git`; -const legacyIncludePath = (p) => `${p}/src/git2`; -const standardIncludePath = (p) => `${includePath(p)}/git2`; -const systemIncludePath = (p) => `${includePath(p)}/git2/sys`; - -const fileIgnoreList = [ 'stdint.h', 'inttypes.h' ]; -const apiIgnoreList = [ 'GIT_BEGIN_DECL', 'GIT_END_DECL', 'GIT_WIN32' ]; - -// Some older versions of libgit2 need some help with includes -const defaultIncludes = [ - 'checkout.h', 'common.h', 'diff.h', 'email.h', 'oidarray.h', 'merge.h', 'remote.h', 'types.h' -]; - -// We're unable to fully map `types.h` defined types into groups; -// provide some help. -const groupMap = { - 'filemode': 'tree', - 'treebuilder': 'tree', - 'note': 'notes', - 'packbuilder': 'pack', - 'reference': 'refs', - 'push': 'remote' }; - -async function headerPaths(p) { - const possibleIncludePaths = [ - ancientIncludePath(p), - legacyIncludePath(p), - standardIncludePath(p), - systemIncludePath(p) - ]; - - const includePaths = [ ]; - const paths = [ ]; - - for (const possibleIncludePath of possibleIncludePaths) { - try { - await fs.stat(possibleIncludePath); - includePaths.push(possibleIncludePath); - } - catch (e) { - if (e?.code !== 'ENOENT') { - throw e; - } - } - } - - if (!includePaths.length) { - throw new Error(`no include paths for ${p}`); - } - - for (const fullPath of includePaths) { - paths.push(...(await fs.readdir(fullPath)). - filter((filename) => filename.endsWith('.h')). - filter((filename) => !fileIgnoreList.includes(filename)). - filter((filename) => filename !== 'deprecated.h' || !options.deprecateHard). - map((filename) => `${fullPath}/${filename}`)); - } - - return paths; -} - -function trimPath(basePath, headerPath) { - const possibleIncludePaths = [ - ancientIncludePath(basePath), - legacyIncludePath(basePath), - standardIncludePath(basePath), - systemIncludePath(basePath) - ]; - - for (const possibleIncludePath of possibleIncludePaths) { - if (headerPath.startsWith(possibleIncludePath + '/')) { - return headerPath.substr(possibleIncludePath.length + 1); - } - } - - throw new Error("header path is not beneath include root"); -} - -function parseFileAst(path, ast) { - let currentFile = undefined; - const fileData = [ ]; - - for (const node of ast.inner) { - if (node.loc?.file && currentFile != node.loc.file) { - currentFile = node.loc.file; - } else if (node.loc?.spellingLoc?.file && currentFile != node.loc.spellingLoc.file) { - currentFile = node.loc.spellingLoc.file; - } - - if (currentFile != path) { - continue; - } - - fileData.push(node); - } - - return fileData; -} - -function includeBase(path) { - const segments = path.split('/'); - - while (segments.length > 1) { - if (segments[segments.length - 1] === 'git2' || - segments[segments.length - 1] === 'git') { - segments.pop(); - return segments.join('/'); - } - - segments.pop(); - } - - throw new Error(`could not resolve include base for ${path}`); -} - -function readAst(path, options) { - return new Promise((resolve, reject) => { - let errorMessage = ''; - const chunks = [ ]; - - const processArgs = [ path, '-Xclang', '-ast-dump=json', `-I${includeBase(path)}` ]; - - if (options?.deprecateHard) { - processArgs.push(`-DGIT_DEPRECATE_HARD`); - } - - if (options?.includeFiles) { - for (const file of options.includeFiles) { - processArgs.push(`-include`); - processArgs.push(file) - } - } - - const process = child_process.spawn('clang', processArgs); - - process.stderr.on('data', (message) => { - errorMessage += message; - }); - process.stdout.on('data', (chunk) => { - chunks.push(chunk); - }); - process.on('close', (code) => { - if (code != 0 && options.strict) { - reject(new Error(`clang exit code ${code}: ${errorMessage}`)); - } - else if (code != 0) { - resolve([ ]); - } - else { - const ast = JSON.parse(Buffer.concat(chunks).toString()); - resolve(parseFileAst(path, ast)); - } - }); - process.on('error', function (err) { - reject(err); - }); - }); -} - -async function readFile(path) { - const buf = await fs.readFile(path); - return buf.toString(); -} - -function ensure(message, test) { - if (!test) { - throw new Error(message); - } -} - -function ensureDefined(name, value) { - if (!value) { - throw new Error(`could not find ${name} for declaration`); - } - - return value; -} - -function groupifyId(location, id) { - if (!id) { - throw new Error(`could not find id in declaration`); - } - - if (!location || !location.file) { - throw new Error(`unspecified location`); - } - - return `${location.file}-${id}`; -} - -function blockCommentText(block) { - ensure('block does not have a single paragraph element', block.inner.length === 1 && block.inner[0].kind === 'ParagraphComment'); - return commentText(block.inner[0]); -} - -function richBlockCommentText(block) { - ensure('block does not have a single paragraph element', block.inner.length === 1 && block.inner[0].kind === 'ParagraphComment'); - return richCommentText(block.inner[0]); -} - -function paramCommentText(param) { - ensure('param does not have a single paragraph element', param.inner.length === 1 && param.inner[0].kind === 'ParagraphComment'); - return richCommentText(param.inner[0]); -} - -function appendCommentText(chunk) { - return chunk.startsWith(' ') ? "\n" + chunk : chunk; -} - -function commentText(para) { - let text = ''; - - for (const comment of para.inner) { - // docbook allows backslash escaped text, and reports it differently. - // we restore the literal `\`. - if (comment.kind === 'InlineCommandComment') { - text += `\\${comment.name}`; - } - else if (comment.kind === 'TextComment') { - text += text ? "\n" + comment.text : comment.text; - } else { - throw new Error(`unknown paragraph comment element: ${comment.kind}`); - } - } - - return text.trim(); -} - -function nextText(para, idx) { - if (!para.inner[idx + 1] || para.inner[idx + 1].kind !== 'TextComment') { - throw new Error("expected text comment"); - } - - return para.inner[idx + 1].text; -} - -function inlineCommandData(data, command) { - ensure(`${command} information does not follow @${command}`, data?.kind === 'TextComment'); - - const result = data.text.match(/^(?:\[([^\]]+)\])? ((?:[a-zA-Z0-9\_]+)|`[a-zA-Z0-9\_\* ]+`)(.*)/); - ensure(`${command} data does not follow @${command}`, result); - - const [ , attr, spec, remain ] = result; - return [ attr, spec.replace(/^`(.*)`$/, "$1"), remain ] -} - -function richCommentText(para) { - let text = ''; - let extendedType = undefined; - let subkind = undefined; - let versionMacro = undefined; - let initMacro = undefined; - let initFunction = undefined; - let lastComment = undefined; - - for (let i = 0; i < para.inner?.length; i++) { - const comment = para.inner[i]; - - if (comment.kind === 'InlineCommandComment' && - comment.name === 'type') { - const [ attr, data, remain ] = inlineCommandData(para.inner[++i], "type"); - - extendedType = { kind: attr, type: data }; - text += remain; - } - else if (comment.kind === 'InlineCommandComment' && - comment.name === 'flags') { - subkind = 'flags'; - } - else if (comment.kind === 'InlineCommandComment' && - comment.name === 'options') { - const [ attr, data, remain ] = inlineCommandData(para.inner[++i], "options"); - - if (attr === 'version') { - versionMacro = data; - } - else if (attr === 'init_macro') { - initMacro = data; - } - else if (attr === 'init_function') { - initFunction = data; - } - - subkind = 'options'; - text += remain; - } - // docbook allows backslash escaped text, and reports it differently. - // we restore the literal `\`. - else if (comment.kind === 'InlineCommandComment') { - text += `\\${comment.name}`; - } - else if (comment.kind === 'TextComment') { - // clang oddity: it breaks into two - // comment blocks, assuming that the trailing > should be a - // blockquote newline sort of thing. unbreak them. - if (comment.text.startsWith('>') && - lastComment && - lastComment.loc.offset + lastComment.text.length === comment.loc.offset) { - - text += comment.text; - } else { - text += text ? "\n" + comment.text : comment.text; - } - } - else if (comment.kind === 'HTMLStartTagComment' && comment.name === 'p') { - text += "\n"; - } - else { - throw new Error(`unknown paragraph comment element: ${comment.kind}`); - } - - lastComment = comment; - } - - return { - text: text.trim(), - extendedType: extendedType, - subkind: subkind, - versionMacro: versionMacro, - initMacro: initMacro, - initFunction: initFunction - } -} - -function join(arr, elem) { - if (arr) { - return [ ...arr, elem ]; - } - - return [ elem ]; -} - -function joinIfNotEmpty(arr, elem) { - if (!elem || elem === '') { - return arr; - } - - if (arr) { - return [ ...arr, elem ]; - } - - return [ elem ]; -} - -function pushIfNotEmpty(arr, elem) { - if (elem && elem !== '') { - arr.push(elem); - } -} - -function single(arr, fn, message) { - let result = undefined; - - if (!arr) { - return undefined; - } - - for (const match of arr.filter(fn)) { - if (result) { - throw new Error(`multiple matches in array for ${fn}${message ? ' (' + message + ')': ''}`); - } - - result = match; - } - - return result; -} - -function updateLocation(location, decl) { - location.file = trimBase(decl.loc?.spellingLoc?.file || decl.loc?.file) || location.file; - location.line = decl.loc?.spellingLoc?.line || decl.loc?.line || location.line; - location.column = decl.loc?.spellingLoc?.col || decl.loc?.col || location.column; - - return location; -} - -async function readFileLocation(startLocation, endLocation) { - if (startLocation.file != endLocation.file) { - throw new Error("cannot read across files"); - } - - const data = await fs.readFile(startLocation.file, "utf8"); - const lines = data.split(/\r?\n/).slice(startLocation.line - 1, endLocation.line); - - lines[lines.length - 1] = lines[lines.length - 1].slice(0, endLocation.column); - lines[0] = lines[0].slice(startLocation.column - 1); - - return lines -} - -function formatLines(lines) { - let result = ""; - let continuation = false; - - for (const i in lines) { - if (!continuation) { - lines[i] = lines[i].trimStart(); - } - - continuation = lines[i].endsWith("\\"); - - if (continuation) { - lines[i] = lines[i].slice(0, -1); - } else { - lines[i] = lines[i].trimEnd(); - } - - result += lines[i]; - } - - if (continuation) { - throw new Error("unterminated literal continuation"); - } - - return result; -} - -async function parseExternalRange(location, range) { - const startLocation = {...location}; - startLocation.file = trimBase(range.begin.spellingLoc.file || startLocation.file); - startLocation.line = range.begin.spellingLoc.line || startLocation.line; - startLocation.column = range.begin.spellingLoc.col || startLocation.column; - - const endLocation = {...startLocation}; - endLocation.file = trimBase(range.end.spellingLoc.file || endLocation.file); - endLocation.line = range.end.spellingLoc.line || endLocation.line; - endLocation.column = range.end.spellingLoc.col || endLocation.column; - - const lines = await readFileLocation(startLocation, endLocation); - - return formatLines(lines); -} - -async function parseLiteralRange(location, range) { - const startLocation = updateLocation({...location}, { loc: range.begin }); - const endLocation = updateLocation({...location}, { loc: range.end }); - - const lines = await readFileLocation(startLocation, endLocation); - - return formatLines(lines); -} - -async function parseRange(location, range) { - return range.begin.spellingLoc ? parseExternalRange(location, range) : parseLiteralRange(location, range); -} - -class ParserError extends Error { - constructor(message, location) { - if (!location) { - super(`${message} at (unknown)`); - } - else { - super(`${message} at ${location.file}:${location.line}`); - } - this.name = 'ParserError'; - } -} - -function validateParsing(test, message, location) { - if (!test) { - throw new ParserError(message, location); - } -} - -function parseComment(spec, location, comment, options) { - let result = { }; - let last = undefined; - - for (const c of comment.inner.filter(c => c.kind === 'ParagraphComment' || c.kind === 'VerbatimLineComment')) { - if (c.kind === 'ParagraphComment') { - const commentData = richCommentText(c); - - result.comment = joinIfNotEmpty(result.comment, commentData.text); - delete commentData.text; - - result = { ...result, ...commentData }; - } - else if (c.kind === 'VerbatimLineComment') { - result.comment = joinIfNotEmpty(result.comment, c.text.trim()); - } - else { - throw new Error(`unknown comment ${c.kind}`); - } - } - - for (const c of comment.inner.filter(c => c.kind !== 'ParagraphComment' && c.kind !== 'VerbatimLineComment')) { - if (c.kind === 'BlockCommandComment' && c.name === 'see') { - result.see = joinIfNotEmpty(result.see, blockCommentText(c)); - } - else if (c.kind === 'BlockCommandComment' && c.name === 'note') { - result.notes = joinIfNotEmpty(result.notes, blockCommentText(c)); - } - else if (c.kind === 'BlockCommandComment' && c.name === 'deprecated') { - result.deprecations = joinIfNotEmpty(result.deprecations, blockCommentText(c)); - } - else if (c.kind === 'BlockCommandComment' && c.name === 'warning') { - result.warnings = joinIfNotEmpty(result.warnings, blockCommentText(c)); - } - else if (c.kind === 'BlockCommandComment' && - (c.name === 'return' || (c.name === 'returns' && !options.strict))) { - const returnData = richBlockCommentText(c); - - result.returns = { - extendedType: returnData.extendedType, - comment: returnData.text - }; - } - else if (c.kind === 'ParamCommandComment') { - ensure('param has a name', c.param); - - const paramDetails = paramCommentText(c); - - result.params = join(result.params, { - name: c.param, - direction: c.direction, - values: paramDetails.type, - extendedType: paramDetails.extendedType, - comment: paramDetails.text - }); - } - else if (options.strict) { - if (c.kind === 'BlockCommandComment') { - throw new ParserError(`unknown block command comment ${c.name}`, location); - } - else if (c.kind === 'VerbatimBlockComment') { - throw new Error(`unknown verbatim command comment ${c.name}`, location); - } - else { - throw new Error(`unknown comment ${c.kind} in ${kind}`); - } - } - } - - return result; -} - -async function parseFunction(location, decl, options) { - let result = { - kind: 'function', - id: groupifyId(location, decl.id), - name: ensureDefined('name', decl.name), - location: {...location} - }; - - // prototype - const [ , returnType, ] = decl.type.qualType.match(/(.*?)(?: )?\((.*)\)$/) || [ ]; - ensureDefined('return type declaration', returnType); - result.returns = { type: returnType }; - - for (const paramDecl of decl.inner.filter(attr => attr.kind === 'ParmVarDecl')) { - updateLocation(location, paramDecl); - - const inner = paramDecl.inner || []; - const innerLocation = {...location}; - let paramAnnotations = undefined; - - for (const annotateDecl of inner.filter(attr => attr.kind === 'AnnotateAttr')) { - updateLocation(innerLocation, annotateDecl); - - paramAnnotations = join(paramAnnotations, await parseRange(innerLocation, annotateDecl.range)); - } - - result.params = join(result.params, { - name: paramDecl.name, - type: paramDecl.type.qualType, - annotations: paramAnnotations - }); - } - - // doc comment - const commentText = single(decl.inner, (attr => attr.kind === 'FullComment')); - - if (commentText) { - const commentData = parseComment(`function:${decl.name}`, location, commentText, options); - - if (result.params) { - if (options.strict && (!commentData.params || result.params.length > commentData.params.length)) { - throw new ParserError(`not all params are documented`, location); - } - - if (options.strict && result.params.length < commentData.params.length) { - throw new ParserError(`additional params are documented`, location); - } - } - - if (commentData.params) { - for (const i in result.params) { - let match; - - for (const j in commentData.params) { - if (result.params[i].name === commentData.params[j].name) { - match = j; - break; - } - } - - if (options.strict && (!match || match != i)) { - throw new ParserError( - `param documentation does not match param name '${result.params[i].name}'`, - location); - } - - if (match) { - result.params[i] = { ...result.params[i], ...commentData.params[match] }; - } - } - } else if (options.strict && result.params) { - throw new ParserError(`no params documented for ${decl.name}`, location); - } - - if (options.strict && !commentData.returns && result.returns.type != 'void') { - throw new ParserError(`return information is not documented for ${decl.name}`, location); - } - - result.returns = { ...result.returns, ...commentData.returns }; - - delete commentData.params; - delete commentData.returns; - - result = { ...result, ...commentData }; - } - else if (options.strict) { - throw new ParserError(`no documentation for function ${decl.name}`, location); - } - - return result; -} - -function parseEnum(location, decl, options) { - let result = { - kind: 'enum', - id: groupifyId(location, decl.id), - name: decl.name, - referenceName: decl.name ? `enum ${decl.name}` : undefined, - members: [ ], - comment: undefined, - location: {...location} - }; - - for (const member of decl.inner.filter(attr => attr.kind === 'EnumConstantDecl')) { - ensure('enum constant has a name', member.name); - - const explicitValue = single(member.inner, (attr => attr.kind === 'ConstantExpr')); - const implicitValue = single(member.inner, (attr => attr.kind === 'ImplicitCastExpr')); - const commentText = single(member.inner, (attr => attr.kind === 'FullComment')); - const commentData = commentText ? parseComment(`enum:${decl.name}:member:${member.name}`, location, commentText, options) : undefined; - - let value = undefined; - - if (explicitValue && explicitValue.value) { - value = explicitValue.value; - } else if (implicitValue) { - const innerExplicit = single(implicitValue.inner, (attr => attr.kind === 'ConstantExpr')); - - value = innerExplicit?.value; - } - - result.members.push({ - name: member.name, - value: value, - ...commentData - }); - } - - const commentText = single(decl.inner, (attr => attr.kind === 'FullComment')); - - if (commentText) { - result = { ...result, ...parseComment(`enum:${decl.name}`, location, commentText, options) }; - } - - return result; -} - -function resolveFunctionPointerTypedef(location, typedef) { - const signature = typedef.type.match(/^((?:const )?[^\s]+(?:\s+\*+)?)\s*\(\*\)\((.*)\)$/); - const [ , returnType, paramData ] = signature; - const params = paramData.split(/,\s+/); - - if (options.strict && (!typedef.params || params.length != typedef.params.length)) { - throw new ParserError(`not all params are documented for function pointer typedef ${typedef.name}`, typedef.location); - } - - if (!typedef.params) { - typedef.params = [ ]; - } - - for (const i in params) { - if (!typedef.params[i]) { - typedef.params[i] = { }; - } - - typedef.params[i].type = params[i]; - } - - if (typedef.returns === undefined && returnType === 'void') { - typedef.returns = { type: 'void' }; - } - else if (typedef.returns !== undefined) { - typedef.returns.type = returnType; - } - else if (options.strict) { - throw new ParserError(`return type is not documented for function pointer typedef ${typedef.name}`, typedef.location); - } -} - -function parseTypedef(location, decl, options) { - updateLocation(location, decl); - - let result = { - kind: 'typedef', - id: groupifyId(location, decl.id), - name: ensureDefined('name', decl.name), - type: ensureDefined('type.qualType', decl.type.qualType), - targetId: undefined, - comment: undefined, - location: {...location} - }; - - const elaborated = single(decl.inner, (attr => attr.kind === 'ElaboratedType')); - if (elaborated !== undefined && elaborated.ownedTagDecl?.id) { - result.targetId = groupifyId(location, elaborated.ownedTagDecl?.id); - } - - const commentText = single(decl.inner, (attr => attr.kind === 'FullComment')); - - if (commentText) { - const commentData = parseComment(`typedef:${decl.name}`, location, commentText, options); - result = { ...result, ...commentData }; - } - - if (isFunctionPointer(result.type)) { - resolveFunctionPointerTypedef(location, result); - } - - return result; -} - -function parseStruct(location, decl, options) { - let result = { - kind: 'struct', - id: groupifyId(location, decl.id), - name: decl.name, - referenceName: decl.name ? `struct ${decl.name}` : undefined, - comment: undefined, - members: [ ], - location: {...location} - }; - - for (const member of decl.inner.filter(attr => attr.kind === 'FieldDecl')) { - let memberData = { - 'name': member.name, - 'type': member.type.qualType - }; - - const commentText = single(member.inner, (attr => attr.kind === 'FullComment')); - - if (commentText) { - memberData = {...memberData, ...parseComment(`struct:${decl.name}:member:${member.name}`, location, commentText, options)}; - } - - result.members.push(memberData); - } - - const commentText = single(decl.inner, (attr => attr.kind === 'FullComment')); - - if (commentText) { - const commentData = parseComment(`struct:${decl.name}`, location, commentText, options); - result = { ...result, ...commentData }; - } - - return result; -} - -function newResults() { - return { - all: [ ], - functions: [ ], - enums: [ ], - typedefs: [ ], - structs: [ ], - macros: [ ] - }; -}; - -const returnMap = { }; -const paramMap = { }; - -function simplifyType(givenType) { - let type = givenType; - - if (type.startsWith('const ')) { - type = type.substring(6); - } - - while (type.endsWith('*') && type !== 'void *' && type !== 'char *') { - type = type.substring(0, type.length - 1).trim(); - } - - if (!type.length) { - throw new Error(`invalid type: ${result.returns.extendedType || result.returns.type}`); - } - - return type; -} - -function createAndPush(arr, name, value) { - if (!arr[name]) { - arr[name] = [ ]; - } - - if (arr[name].length && arr[name][arr[name].length - 1] === value) { - return; - } - - arr[name].push(value); -} - -function addReturn(result) { - if (!result.returns) { - return; - } - - let type = simplifyType(result.returns.extendedType?.type || result.returns.type); - - createAndPush(returnMap, type, result.name); -} - -function addParameters(result) { - if (!result.params) { - return; - } - - for (const param of result.params) { - let type = param.extendedType?.type || param.type; - - if (!type && options.strict) { - throw new Error(`parameter ${result.name} erroneously documented when not specified`); - } else if (!type) { - continue; - } - - type = simplifyType(type); - - if (param.direction === 'out') { - createAndPush(returnMap, type, result.name); - } - else { - createAndPush(paramMap, type, result.name); - } - } -} - -function addResult(results, result) { - results[`${result.kind}s`].push(result); - results.all.push(result); - - addReturn(result); - addParameters(result); -} - -function mergeResults(one, two) { - const results = newResults(); - - for (const inst of Object.keys(results)) { - results[inst].push(...one[inst]); - results[inst].push(...two[inst]); - } - - return results; -} - -function getById(results, id) { - ensure("id is set", id !== undefined); - return single(results.all.all, (item => item.id === id), id); -} - -function getByKindAndName(results, kind, name) { - ensure("kind is set", kind !== undefined); - ensure("name is set", name !== undefined); - return single(results.all[`${kind}s`], (item => item.name === name), name); -} - -function getByName(results, name) { - ensure("name is set", name !== undefined); - return single(results.all.all, (item => item.name === name), name); -} - -function isFunctionPointer(type) { - return type.match(/^(?:const )?[A-Za-z0-9_]+\s+\**\(\*/); -} - -function resolveCallbacks(results) { - // expand callback types - for (const fn of results.all.functions) { - for (const param of fn.params || [ ]) { - const typedef = getByName(results, param.type); - - if (typedef === undefined) { - continue; - } - - param.referenceType = typedef.type; - } - } - - for (const struct of results.all.structs) { - for (const member of struct.members) { - const typedef = getByKindAndName(results, 'typedef', member.type); - - if (typedef === undefined) { - continue; - } - - member.referenceType = typedef.type; - } - } -} - -function trimBase(path) { - if (!path) { - return path; - } - - for (const segment of [ 'git2', 'git' ]) { - const base = [ includeBase(path), segment ].join('/'); - - if (path.startsWith(base + '/')) { - return path.substr(base.length + 1); - } - } - - throw new Error(`header path ${path} is not beneath standard root`); -} - -function resolveTypedefs(results) { - for (const typedef of results.all.typedefs) { - let target = typedef.targetId ? getById(results, typedef.targetId) : undefined; - - if (target) { - // update the target's preferred name with the short name - target.referenceName = typedef.name; - - if (target.name === undefined) { - target.name = typedef.name; - } - } - else if (typedef.type.startsWith('struct ')) { - const path = typedef.location.file; - - /* - * See if this is actually a typedef to a declared struct, - * then it is not actually opaque. - */ - if (results.all.structs.filter(fn => fn.name === typedef.name).length > 0) { - typedef.opaque = false; - continue; - } - - opaque = { - kind: 'struct', - id: groupifyId(typedef.location, typedef.id), - name: typedef.name, - referenceName: typedef.type, - opaque: true, - comment: typedef.comment, - location: typedef.location, - group: typedef.group - }; - - addResult(results.files[path], opaque); - addResult(results.all, opaque); - } - else if (isFunctionPointer(typedef.type) || - typedef.type === 'int64_t' || - typedef.type === 'uint64_t') { - // standard types - // TODO : make these a list - } - else { - typedef.kind = 'alias'; - typedef.typedef = true; - } - } -} - -function lastCommentIsGroupDelimiter(decls) { - if (decls[decls.length - 1].inner && - decls[decls.length - 1].inner.length > 0) { - return lastCommentIsGroupDelimiter(decls[decls.length - 1].inner); - } - - if (decls.length >= 2 && - decls[decls.length - 1].kind.endsWith('Comment') && - decls[decls.length - 2].kind.endsWith('Comment') && - decls[decls.length - 2].text === '@' && - decls[decls.length - 1].text === '{') { - return true; - } - - return false; -} - -async function parseAst(decls, options) { - const location = { - file: undefined, - line: undefined, - column: undefined - }; - - const results = newResults(); - - /* The first decl might have picked up the javadoc _for the file - * itself_ based on the file's structure. Remove it. - */ - if (decls.length && decls[0].inner && - decls[0].inner.length > 0 && - decls[0].inner[0].kind === 'FullComment' && - lastCommentIsGroupDelimiter(decls[0].inner[0].inner)) { - updateLocation(location, decls[0]); - delete decls[0].inner[0]; - } - - for (const decl of decls) { - updateLocation(location, decl); - - ensureDefined('kind', decl.kind); - - if (decl.kind === 'FunctionDecl') { - addResult(results, await parseFunction({...location}, decl, options)); - } - else if (decl.kind === 'EnumDecl') { - addResult(results, parseEnum({...location}, decl, options)); - } - else if (decl.kind === 'TypedefDecl') { - addResult(results, parseTypedef({...location}, decl, options)); - } - else if (decl.kind === 'RecordDecl' && decl.tagUsed === 'struct') { - if (decl.completeDefinition) { - addResult(results, parseStruct({...location}, decl, options)); - } - } - else if (decl.kind === 'VarDecl') { - if (options.strict) { - throw new Error(`unsupported variable declaration ${decl.kind}`); - } - } - else { - throw new Error(`unknown declaration type ${decl.kind}`); - } - } - - return results; -} - -function parseCommentForMacro(lines, macroIdx, name) { - let startIdx = -1, endIdx = 0; - const commentLines = [ ]; - - while (macroIdx > 0 && - (line = lines[macroIdx - 1].trim()) && - (line.trim() === '' || - line.trim().endsWith('\\') || - line.trim().match(/^#\s*if\s+/) || - line.trim().startsWith('#ifdef ') || - line.trim().startsWith('#ifndef ') || - line.trim().startsWith('#elif ') || - line.trim().startsWith('#else ') || - line.trim().match(/^#\s*define\s+${name}\s+/))) { - macroIdx--; - } - - if (macroIdx > 0 && lines[macroIdx - 1].trim().endsWith('*/')) { - endIdx = macroIdx - 1; - } else { - return ''; - } - - for (let i = endIdx; i >= 0; i--) { - if (lines[i].trim().startsWith('/**')) { - startIdx = i; - break; - } - else if (lines[i].trim().startsWith('/*')) { - break; - } - } - - if (startIdx < 0) { - return ''; - } - - for (let i = startIdx; i <= endIdx; i++) { - let line = lines[i].trim(); - - if (i == startIdx) { - line = line.replace(/^\s*\/\*\*\s*/, ''); - } - - if (i === endIdx) { - line = line.replace(/\s*\*\/\s*$/, ''); - } - - if (i != startIdx) { - line = line.replace(/^\s*\*\s*/, ''); - } - - if (i == startIdx && (line === '@{' || line.startsWith("@{ "))) { - return ''; - } - - if (line === '') { - continue; - } - - commentLines.push(line); - } - - return commentLines.join(' '); -} - -async function parseInfo(data) { - const fileHeader = data.match(/(.*)\n+GIT_BEGIN_DECL.*/s); - const headerLines = fileHeader ? fileHeader[1].split(/\n/) : [ ]; - - let lines = [ ]; - const detailsLines = [ ]; - - let summary = undefined; - let endIdx = headerLines.length - 1; - - for (let i = headerLines.length - 1; i >= 0; i--) { - let line = headerLines[i].trim(); - - if (line.match(/^\s*\*\/\s*$/)) { - endIdx = i; - } - - if (line.match(/^\/\*\*(\s+.*)?$/)) { - lines = headerLines.slice(i + 1, endIdx); - break; - } - else if (line.match(/^\/\*(\s+.*)?$/)) { - break; - } - } - - for (let line of lines) { - line = line.replace(/^\s\*/, ''); - line = line.trim(); - - const comment = line.match(/^\@(\w+|{)\s*(.*)/); - - if (comment) { - if (comment[1] === 'brief') { - summary = comment[2]; - } - } - else if (line != '') { - detailsLines.push(line); - } - } - - const details = detailsLines.length > 0 ? detailsLines.join("\n") : undefined; - - return { - 'summary': summary, - 'details': details - }; -} - -async function parseMacros(path, data, options) { - const results = newResults(); - const lines = data.split(/\r?\n/); - - const macros = { }; - - for (let i = 0; i < lines.length; i++) { - const macro = lines[i].match(/^(\s*#\s*define\s+)([^\s\(]+)(\([^\)]+\))?\s*(.*)/); - let more = false; - - if (!macro) { - continue; - } - - let [ , prefix, name, args, value ] = macro; - - if (name.startsWith('INCLUDE_') || name.startsWith('_INCLUDE_')) { - continue; - } - - if (args) { - name = name + args; - } - - if (macros[name]) { - continue; - } - - macros[name] = true; - - value = value.trim(); - - if (value.endsWith('\\')) { - value = value.substring(0, value.length - 1).trim(); - more = true; - } - - while (more) { - more = false; - - let line = lines[++i]; - - if (line.endsWith('\\')) { - line = line.substring(0, line.length - 1); - more = true; - } - - value += ' ' + line.trim(); - } - - const comment = parseCommentForMacro(lines, i, name); - const location = { - file: path, - line: i + 1, - column: prefix.length + 1, - }; - - if (options.strict && !comment) { - throw new ParserError(`no comment for ${name}`, location); - } - - addResult(results, { - kind: 'macro', - name: name, - location: location, - value: value, - comment: comment, - }); - } - - return results; -} - -function resolveUngroupedTypes(results) { - const groups = { }; - - for (const result of results.all.all) { - result.group = result.location.file; - - if (result.group.endsWith('.h')) { - result.group = result.group.substring(0, result.group.length - 2); - groups[result.group] = true; - } - } - - for (const result of results.all.all) { - if (result.location.file === 'types.h' && - result.name.startsWith('git_')) { - let possibleGroup = result.name.substring(4); - - do { - if (groupMap[possibleGroup]) { - result.group = groupMap[possibleGroup]; - break; - } - else if (groups[possibleGroup]) { - result.group = possibleGroup; - break; - } - else if (groups[`sys/${possibleGroup}`]) { - result.group = `sys/${possibleGroup}`; - break; - } - - let match = possibleGroup.match(/^(.*)_[^_]+$/); - - if (!match) { - break; - } - - possibleGroup = match[1]; - } while (true); - } - } -} - -function resolveReturns(results) { - for (const result of results.all.all) { - result.returnedBy = returnMap[result.name]; - } -} - -function resolveParameters(results) { - for (const result of results.all.all) { - result.parameterTo = paramMap[result.name]; - } -} - -async function parseHeaders(sourcePath, options) { - const results = { all: newResults(), files: { } }; - - for (const fullPath of await headerPaths(sourcePath)) { - const path = trimPath(sourcePath, fullPath); - const fileContents = await readFile(fullPath); - - const ast = await parseAst(await readAst(fullPath, options), options); - const macros = await parseMacros(path, fileContents, options); - const info = await parseInfo(fileContents); - - const filedata = mergeResults(ast, macros); - - filedata['info'] = info; - - results.files[path] = filedata; - results.all = mergeResults(results.all, filedata); - } - - resolveCallbacks(results); - resolveTypedefs(results); - - resolveUngroupedTypes(results); - - resolveReturns(results); - resolveParameters(results); - - return results; -} - -function isFunctionPointer(type) { - return type.match(/^(const\s+)?[A-Za-z0-9_]+\s+\*?\(\*/); -} -function isEnum(type) { - return type.match(/^enum\s+/); -} -function isStruct(type) { - return type.match(/^struct\s+/); -} - -/* - * We keep the `all` arrays around so that we can lookup; drop them - * for the end result. - */ -function simplify(results) { - const simplified = { - 'info': { }, - 'groups': { } - }; - - results.all.all.sort((a, b) => { - if (!a.group) { - throw new Error(`missing group for api ${a.name}`); - } - - if (!b.group) { - throw new Error(`missing group for api ${b.name}`); - } - - const aSystem = a.group.startsWith('sys/'); - const aName = aSystem ? a.group.substr(4) : a.group; - - const bSystem = b.group.startsWith('sys/'); - const bName = bSystem ? b.group.substr(4) : b.group; - - if (aName !== bName) { - return aName.localeCompare(bName); - } - - if (aSystem !== bSystem) { - return aSystem ? 1 : -1; - } - - if (a.location.file !== b.location.file) { - return a.location.file.localeCompare(b.location.file); - } - - if (a.location.line !== b.location.line) { - return a.location.line - b.location.line; - } - - return a.location.column - b.location.column; - }); - - for (const api of results.all.all) { - delete api.id; - delete api.targetId; - - const type = api.referenceType || api.type; - - if (api.kind === 'typedef' && isFunctionPointer(type)) { - api.kind = 'callback'; - api.typedef = true; - } - else if (api.kind === 'typedef' && (!isEnum(type) && !isStruct(type))) { - api.kind = 'alias'; - api.typedef = true; - } - else if (api.kind === 'typedef') { - continue; - } - - if (apiIgnoreList.includes(api.name)) { - continue; - } - - // TODO: do a warning where there's a redefinition of a symbol - // There are occasions where we redefine a symbol. First, our - // parser is not smart enough to know #ifdef's around #define's. - // But also we declared `git_email_create_from_diff` twice (in - // email.h and sys/email.h) for several releases. - - if (!simplified['groups'][api.group]) { - simplified['groups'][api.group] = { }; - simplified['groups'][api.group].apis = { }; - simplified['groups'][api.group].info = results.files[`${api.group}.h`].info; - } - - simplified['groups'][api.group].apis[api.name] = api; - } - - return simplified; -} - -function joinArguments(next, previous) { - if (previous) { - return [...previous, next]; - } - return [next]; -} - -async function findIncludes() { - const includes = [ ]; - - for (const possible of defaultIncludes) { - const includeFile = `${docsPath}/include/git2/${possible}`; - - try { - await fs.stat(includeFile); - includes.push(`git2/${possible}`); - } - catch (e) { - if (e?.code !== 'ENOENT') { - throw e; - } - } - } - - return includes; -} - -async function execGit(path, command) { - const process = child_process.spawn('git', command, { cwd: path }); - const chunks = [ ]; - - return new Promise((resolve, reject) => { - process.stdout.on('data', (chunk) => { - chunks.push(chunk); - }); - process.on('close', (code) => { - resolve(code == 0 ? Buffer.concat(chunks).toString() : undefined); - }); - process.on('error', function (err) { - reject(err); - }); - }); -} - -async function readMetadata(path) { - let commit = await execGit(path, [ 'rev-parse', 'HEAD' ]); - - if (commit) { - commit = commit.trimEnd(); - } - - let version = await execGit(path, [ 'describe', '--tags', '--exact' ]); - - if (!version) { - const ref = await execGit(path, [ 'describe', '--all', '--exact' ]); - - if (ref && ref.startsWith('heads/')) { - version = ref.substr(6); - } - } - - if (version) { - version = version.trimEnd(); - } - - return { - 'version': version, - 'commit': commit - }; -} - -program.option('--output ') - .option('--include ', undefined, joinArguments) - .option('--no-includes') - .option('--deprecate-hard') - .option('--validate-only') - .option('--strict'); -program.parse(); - -const options = program.opts(); - -if (program.args.length != 1) { - console.error(`usage: ${path.basename(process.argv[1])} docs`); - process.exit(1); -} - -const docsPath = program.args[0]; - -if (options['include'] && !options['includes']) { - console.error(`usage: cannot combined --include with --no-include`); - process.exit(1); -} - -(async () => { - try { - if (options['include']) { - includes = options['include']; - } - else if (!options['includes']) { - includes = [ ]; - } - else { - includes = await findIncludes(); - } - - const parseOptions = { - deprecateHard: options.deprecateHard || false, - includeFiles: includes, - strict: options.strict || false - }; - - const results = await parseHeaders(docsPath, parseOptions); - const metadata = await readMetadata(docsPath); - - const simplified = simplify(results); - simplified['info'] = metadata; - - if (!options.validateOnly) { - console.log(JSON.stringify(simplified, null, 2)); - } - } catch (e) { - console.error(e); - process.exit(1); - } -})(); diff --git a/vendor/libgit2-sys/libgit2/script/api-docs/docs-generator.js b/vendor/libgit2-sys/libgit2/script/api-docs/docs-generator.js deleted file mode 100755 index dcf25e5..0000000 --- a/vendor/libgit2-sys/libgit2/script/api-docs/docs-generator.js +++ /dev/null @@ -1,1417 +0,0 @@ -#!/usr/bin/env node - -const markdownit = require('markdown-it'); -const { program } = require('commander'); - -const path = require('node:path'); -const fs = require('node:fs/promises'); -const process = require('node:process'); - -const githubPath = 'https://github.com/libgit2/libgit2'; - -const linkPrefix = '/docs/reference'; - -const projectTitle = 'libgit2'; -const includePath = 'include/git2'; - -const fileDenylist = [ 'stdint.h' ]; -const showVersions = true; - -const defaultBranch = 'main'; - -const markdown = markdownit(); -const markdownDefaults = { - code_inline: markdown.renderer.rules.code_inline -}; -markdown.renderer.rules.code_inline = (tokens, idx, options, env, self) => { - const version = env.__version || defaultBranch; - - const code = tokens[idx].content; - const text = `${nowrap(sanitize(tokens[idx].content))}`; - const link = linkForCode(version, code, text); - - return link ? link : text; -}; - -// globals -const apiData = { }; -const versions = [ ]; -const versionDeltas = { }; - -function produceVersionPicker(version, classes, cb) { - let content = ""; - - if (!showVersions) { - return content; - } - - content += `
\n`; - content += ` Version:\n`; - content += ` \n`; - - content += `
\n`; - - return content; -} - -function produceBreadcrumb(version, api, type) { - let content = ""; - let group = api.group; - let sys = false; - - if (group.endsWith('.h')) { - group = group.substr(0, group.length - 2); - } - - let groupTitle = group; - - if (groupTitle.startsWith('sys/')) { - groupTitle = groupTitle.substr(4); - groupTitle += ' (advanced)'; - } - - content += `
\n`; - content += ` \n`; - content += `
\n`; - - return content; -} - -function produceHeader(version, api, type) { - let content = ""; - - content += `
\n`; - content += `

${api.name}

\n`; - - content += produceAttributes(version, api, type); - content += produceSearchArea(version, type); - - content += produceVersionPicker(version, - `apiHeaderVersionSelect ${type}HeaderVersionSelect`, - (v) => { - const versionedApi = selectApi(v, (i => i.name === api.name)); - return versionedApi ? linkFor(v, versionedApi) : undefined; - }); - - content += `
\n`; - content += `\n`; - - return content; -} - -function produceAttributes(version, api, type) { - let content = ""; - - if (api.deprecations) { - content += ` Deprecated\n`; - } - - return content; -} - -function produceDescription(version, desc, type) { - let content = ""; - - if (! desc.comment) { - return content; - } - - content += `\n`; - content += `
\n`; - - for (const para of Array.isArray(desc.comment) ? desc.comment : [ desc.comment ]) { - content += ` ${markdown.render(para, { __version: version })}\n`; - } - - content += `
\n`; - - return content; -} - -function produceList(version, api, type, listType) { - let content = ""; - - if (!api[listType]) { - return content; - } - - const listTypeUpper = listType.charAt(0).toUpperCase() + listType.slice(1); - const listTypeTitle = listTypeUpper.replaceAll(/(.)([A-Z])/g, (match, one, two) => { return one + ' ' + two; }); - - content += `\n`; - content += `

${listTypeTitle}

\n`; - - content += `
\n`; - content += `
    \n`; - - for (const item of api[listType]) { - content += `
  • \n`; - content += ` ${linkText(version, item)}\n`; - content += `
  • \n`; - } - - content += `
\n`; - content += `
\n`; - - return content; -} - -function produceNotes(version, api, type) { - return produceList(version, api, type, 'notes'); -} - -function produceSeeAlso(version, api, type) { - return produceList(version, api, type, 'deprecated'); -} - -function produceSeeAlso(version, api, type) { - return produceList(version, api, type, 'see'); -} - -function produceWarnings(version, api, type) { - return produceList(version, api, type, 'warnings'); -} - -function produceDeprecations(version, api, type) { - return produceList(version, api, type, 'deprecations'); -} - -function produceGitHubLink(version, api, type) { - if (!api || !api.location || !api.location.file) { - return undefined; - } - - let file = api.location.file; - - let link = githubPath + '/blob/' + version + '/' + includePath + '/' + file; - - if (api.location.line) { - link += '#L' + api.location.line; - } - - return link; -} - -function produceSignatureForFunction(version, api, type) { - let content = ""; - let paramCount = 0; - - let prefix = type === 'callback' ? 'typedef' : ''; - const returnType = api.returns?.type || 'int'; - - const githubLink = produceGitHubLink(version, api, type); - - content += `\n`; - - content += `

Signature

\n`; - - if (githubLink) { - content += ` \n`; - } - - content += `
\n`; - - content += ` ${prefix ? prefix + ' ' : ''}${returnType}`; - content += returnType.endsWith('*') ? '' : ' '; - content += `${api.name}(`; - - for (const param of api.params || [ ]) { - content += (paramCount++ > 0) ? ', ' : ''; - - if (!param.type && options.strict) { - throw new Error(`param ${param.name} has no type for function ${api.name}`); - } - else if (!param.type) { - continue; - } - - content += ``; - content += `${param.type}`; - content += param.type.endsWith('*') ? '' : ' '; - - if (param.name) { - content += `${param.name}`; - } - - content += ``; - } - - content += `);\n`; - content += `
\n`; - - return content; -} - -function produceFunctionParameters(version, api, type) { - let content = ""; - - if (!api.params || api.params.length == 0) { - return content; - } - - content += `\n`; - - content += `

Parameters

\n`; - content += `
\n`; - - for (const param of api.params) { - let direction = param.direction || 'in'; - direction = direction.charAt(0).toUpperCase() + direction.slice(1); - - if (!param.type && options.strict) { - throw new Error(`param ${param.name} has no type for function ${api.name}`); - } - else if (!param.type) { - continue; - } - - content += `
\n`; - content += `
\n`; - content += ` ${linkType(version, param.type)}\n`; - content += `
\n`; - - if (param.extendedType) { - content += `
\n`; - content += ` ${linkType(version, param.extendedType.type)}\n`; - content += `
\n`; - } - - content += `
\n`; - - content += ` ${direction}\n`; - content += `
\n`; - - if (param.name) { - content += `
\n`; - content += ` ${param.name}\n`; - content += `
\n`; - } - - content += `
\n`; - content += ` ${render(version, param.comment)}\n`; - content += `
\n`; - content += `
\n`; - } - - content += `
\n`; - - return content; -} - -function produceFunctionReturn(version, api, type) { - let content = ""; - - if (api.returns && api.returns.type && api.returns.type !== 'void') { - content += `\n`; - content += `

Returns

\n`; - content += `
\n`; - content += `
\n`; - content += ` ${linkType(version, api.returns.type)}\n`; - content += `
\n`; - content += `
\n`; - content += ` ${render(version, api.returns.comment)}\n`; - content += `
\n`; - content += `
\n`; - } - - return content; -} - -function produceSignatureForObject(version, api, type) { - let content = ""; - - const githubLink = produceGitHubLink(version, api, type); - - content += `\n`; - - content += `

Signature

\n`; - - if (githubLink) { - content += ` \n`; - } - - content += `
\n`; - content += ` typedef ${api.referenceName} ${api.name}\n`; - content += `
\n`; - - return content; -} - -function produceSignatureForStruct(version, api, type) { - let content = ""; - - const githubLink = produceGitHubLink(version, api, type); - - content += `\n`; - - content += `

Signature

\n`; - - if (githubLink) { - content += ` \n`; - } - - const typedef = api.name.startsWith('struct') ? '' : 'typedef '; - - content += `
\n`; - content += ` ${typedef}struct ${api.name} {\n`; - - for (const member of api.members || [ ]) { - content += ``; - content += `${member.type}`; - content += member.type.endsWith('*') ? '' : ' '; - - if (member.name) { - content += `${member.name}`; - } - - content += `\n`; - } - - content += ` };\n`; - content += `
\n`; - - return content; -} - -function isOctalEnum(version, api, type) { - return api.name === 'git_filemode_t'; -} - -function isFlagsEnum(version, api, type) { - // TODO: also handle the flags metadata instead of always just guessing - if (type !== 'enum') { - return false; - } - - let largest = 0; - - for (const member of api.members) { - if (member.value === undefined) { - return false; - } - - if (member.value && (member.value & (member.value - 1))) { - return false; - } - - largest = member.value; - } - - return (largest > 1); -} - -function flagsOctal(v) { - const n = parseInt(v); - return n ? `0${n.toString(8)}` : 0; -} - -function flagsValue(v) { - if (v === '0') { - return '0'; - } - - return `(1 << ${Math.log2(v)})`; -} - -function produceMembers(version, api, type) { - let content = ""; - let value = 0; - - if (!api.members || api.members.length == 0) { - return ""; - } - - let title = type === 'enum' ? 'Values' : 'Members'; - const isOctal = isOctalEnum(version, api, type); - const isFlags = isFlagsEnum(version, api, type); - - content += `\n`; - - content += `

${title}

\n`; - - const githubLink = api.kind === 'struct' ? undefined : produceGitHubLink(version, api, type); - - if (githubLink) { - content += ` \n`; - } - - content += `
\n`; - - for (const member of api.members) { - value = member.value ? member.value : value; - - content += `
\n`; - - if (type === 'struct') { - content += `
\n`; - content += ` ${linkType(version, member.type)}\n`; - content += `
\n`; - } - - content += `
\n`; - content += ` ${member.name}\n`; - content += `
\n`; - - if (type === 'enum') { - const enumValue = isOctal ? flagsOctal(value) : (isFlags ? flagsValue(value) : value); - - content += `
\n`; - content += ` ${enumValue}\n`; - content += `
\n`; - } - - content += `
\n`; - content += ` ${render(version, member.comment)}\n`; - content += `
\n`; - content += `
\n`; - - value++; - } - - content += `
\n`; - - return content; -} - -function produceReturnedBy(version, api, type) { - return produceList(version, api, type, 'returnedBy'); -} - -function produceParameterTo(version, api, type) { - return produceList(version, api, type, 'parameterTo'); -} - -function produceVersionDeltas(version, api, type) { - let content = ''; - - if (!showVersions) { - return content; - } - - const deltas = versionDeltas[api.name]; - if (!deltas) { - throw new Error(`no version information for ${api.kind} ${api.name}`); - } - - content += `

Versions

\n`; - content += `
\n`; - content += `
    \n`; - - for (const idx in deltas) { - const item = deltas[idx]; - - if (idx == deltas.length - 1) { - content += `
  • \n`; - } else if (item.changed) { - content += `
  • \n`; - } else { - content += `
  • \n`; - } - - content += ` ${item.version}\n`; - content += `
  • \n`; - } - - content += `
\n`; - content += `
\n`; - - return content; -} - -async function layout(data) { - let layout; - - if (options.layout) { - layout = await fs.readFile(options.layout); - } - else if (options.jekyllLayout) { - layout = `---\ntitle: {{title}}\nlayout: ${options.jekyllLayout}\n---\n\n{{content}}`; - } - else { - return data.content; - } - - return layout.toString().replaceAll(/{{([a-z]+)}}/g, (match, p1) => data[p1] || ""); -} - -function produceSearchArea(version, type) { - let content = ""; - - content += `\n`; - content += ` \n`; - content += ` \n`; - - content += `
\n`; - content += ` \n`; - content += `
\n`; - content += `
\n`; - content += `
\n`; - content += `\n`; - - return content; -} - -async function produceDocumentationForApi(version, api, type) { - let content = ""; - - content += `
\n`; - - content += produceBreadcrumb(version, api, type); - content += produceHeader(version, api, type); - content += produceDescription(version, api, type); - content += produceNotes(version, api, type); - content += produceDeprecations(version, api, type); - content += produceSeeAlso(version, api, type); - content += produceWarnings(version, api, type); - content += produceSignature(version, api, type); - content += produceMembers(version, api, type); - content += produceFunctionParameters(version, api, type); - content += produceFunctionReturn(version, api, type); - content += produceReturnedBy(version, api, type); - content += produceParameterTo(version, api, type); - content += produceVersionDeltas(version, api, type); - - content += `
\n`; - - - const name = (type === 'macro' && api.name.includes('(')) ? - api.name.replace(/\(.*/, '') : api.name; - - const groupDir = `${outputPath}/${version}/${api.group}`; - const filename = `${groupDir}/${name}.html`; - - await fs.mkdir(groupDir, { recursive: true }); - await fs.writeFile(filename, await layout({ - title: `${api.name} (${projectTitle} ${version})`, - content: content - })); -} - -function selectApi(version, cb) { - const allApis = allApisForVersion(version, apiData[version]['groups']); - - for (const name in allApis) { - const api = allApis[name]; - - if (cb(api)) { - return api; - } - } - - return undefined; -} - -function apiFor(version, type) { - return selectApi(version, ((api) => api.name === type)); -} - -function linkFor(version, api) { - const name = (api.kind === 'macro' && api.name.includes('(')) ? - api.name.replace(/\(.*/, '') : api.name; - - return `${linkPrefix}/${version}/${api.group}/${name}.html`; -} - -function linkForCode(version, code, text) { - let api = selectApi(version, ((api) => api.name === code)); - let valueDecl = undefined; - - const apisForVersion = allApisForVersion(version, apiData[version]['groups']); - - if (!api) { - for (const enumDecl of Object.values(apisForVersion).filter(api => api.kind === 'enum')) { - const member = enumDecl.members.filter((m) => m.name === code); - - if (member && member[0]) { - api = enumDecl; - valueDecl = member[0]; - break; - } - } - } - - if (!api) { - return undefined; - } - - const kind = internalKind(version, api); - let link = linkFor(version, api); - - if (valueDecl) { - link += `#${valueDecl.name}`; - } - - if (!text) { - text = `${sanitize(code)}`; - } - - return `${text}`; -} - -function linkType(version, given) { - let type = given; - - if ((content = given.match(/^(?:const\s+)?([A-Za-z0-9_]+)(?:\s+\*+)?/))) { - type = content[1]; - } - - const api = apiFor(version, type); - - if (api) { - return `${given}`; - } - - return given; -} - -function linkText(version, str) { - const api = apiFor(version, str); - - if (api) { - return `${str}`; - } - - return sanitize(str); -} - -function render(version, str) { - let content = [ ]; - - if (!str) { - return ''; - } - - for (const s of Array.isArray(str) ? str : [ str ] ) { - content.push(markdown.render(s, { __version: version }).replaceAll(/\s+/g, ' ')); - } - - return content.join(' '); -} - -function nowrap(text) { - text = text.replaceAll(' ', ' '); - text = `${text}`; - return text; -} - -function sanitize(str) { - let content = [ ]; - - if (!str) { - return ''; - } - - for (const s of Array.isArray(str) ? str : [ str ] ) { - content.push(s.replaceAll('&', '&') - .replaceAll('<', '<') - .replaceAll('>', '>') - .replaceAll('{', '{') - .replaceAll('}', '}')); - } - - return content.join(' '); -} - -function produceSignatureForAlias(version, api, type) { - let content = ""; - - const githubLink = produceGitHubLink(version, api, type); - - content += `

Signature

\n`; - - if (githubLink) { - content += ` \n`; - } - - content += `
\n`; - content += ` typedef ${api.name} ${api.type};`; - content += `
\n`; - - return content; -} - -function produceSignatureForMacro(version, api, type) { - let content = ""; - - const githubLink = produceGitHubLink(version, api, type); - - content += `

Signature

\n`; - - if (githubLink) { - content += ` \n`; - } - - content += `
\n`; - content += ` #define ${api.name} ${sanitize(api.value)}`; - content += `
\n`; - - return content; -} - -function produceSignature(version, api, type) { - if (type === 'macro') { - return produceSignatureForMacro(version, api, type); - } - else if (type === 'alias') { - return produceSignatureForAlias(version, api, type); - } - else if (type === 'function' || type === 'callback') { - return produceSignatureForFunction(version, api, type); - } - else if (type === 'object') { - return produceSignatureForObject(version, api, type); - } - else if (type === 'struct') { - return produceSignatureForStruct(version, api, type); - } - else if (type === 'struct' || type === 'enum') { - return ""; - } - else { - throw new Error(`unknown type: ${api.kind}`); - } -} - -function isFunctionPointer(type) { - return type.match(/^(const\s+)?[A-Za-z0-9_]+\s+\*?\(\*/); -} - -function isEnum(type) { - return type.match(/^enum\s+/); -} - -function isStruct(type) { - return type.match(/^struct\s+/); -} - -function internalKind(version, api) { - if (api.kind === 'struct' && api.opaque) { - return 'object'; - } - - return api.kind; -} - -function externalKind(kind) { - if (kind === 'object') { - return 'struct'; - } - - return kind; -} - -async function produceIndexForGroup(version, group, versionApis) { - let content = ""; - - if (versionApis['groups'][group].apis.length == 0) { - return; - } - - const apis = Object.values(versionApis['groups'][group].apis); - - let fileName = group; - if (fileName.endsWith('.h')) { - fileName = fileName.substr(0, fileName.length - 2); - } - - const system = fileName.startsWith('sys/'); - let groupName = system ? fileName.substr(4) : fileName; - - content += `
\n`; - - content += `
\n`; - content += ` \n`; - content += `
\n`; - - content += `
\n`; - content += `

${groupName}

\n`; - - content += produceSearchArea(version, 'group'); - content += produceVersionPicker(version, "groupHeaderVersionSelect", (v) => { - if (apiData[v]['groups'][group]) { - return `${linkPrefix}/${v}/${groupName}/index.html`; - } - return undefined; - }); - - content += `
\n`; - - let details = undefined; - - if (versionApis['groups'][group].info?.details) { - details = markdown.render(versionApis['groups'][group].info.details, { __version: version }); - } else if (versionApis['groups'][group].info?.summary) { - details = versionApis['groups'][group].info.summary; - } - - if (details) { - content += `
\n`; - content += ` ${details}\n`; - content += `
\n`; - } - - for (const kind of [ 'object', 'struct', 'macro', 'enum', 'callback', 'alias', 'function' ]) { - content += produceIndexForApiKind(version, apis.filter(api => { - if (kind === 'object') { - return api.kind === 'struct' && api.opaque; - } - else if (kind === 'struct') { - return api.kind === 'struct' && !api.opaque; - } - else { - return api.kind === kind; - } - }), kind); - } - - content += `
\n`; - - const groupsDir = `${outputPath}/${version}/${fileName}`; - const filename = `${groupsDir}/index.html`; - - await fs.mkdir(groupsDir, { recursive: true }); - await fs.writeFile(filename, await layout({ - title: `${groupName} APIs (${projectTitle} ${version})`, - content: content - })); -} - -async function produceDocumentationForApis(version, apiData) { - const apis = allApisForVersion(version, apiData['groups']); - - for (const func of Object.values(apis).filter(api => api.kind === 'function')) { - await produceDocumentationForApi(version, func, 'function'); - } - - for (const struct of Object.values(apis).filter(api => api.kind === 'struct')) { - await produceDocumentationForApi(version, struct, internalKind(version, struct)); - } - - for (const e of Object.values(apis).filter(api => api.kind === 'enum')) { - await produceDocumentationForApi(version, e, 'enum'); - } - - for (const callback of Object.values(apis).filter(api => api.kind === 'callback')) { - await produceDocumentationForApi(version, callback, 'callback'); - } - - for (const alias of Object.values(apis).filter(api => api.kind === 'alias')) { - await produceDocumentationForApi(version, alias, 'alias'); - } - - for (const macro of Object.values(apis).filter(api => api.kind === 'macro')) { - await produceDocumentationForApi(version, macro, 'macro'); - } -} - -function produceIndexForApiKind(version, apis, kind) { - let content = ""; - - if (!apis || !apis.length) { - return content; - } - - let kindUpper = kind.charAt(0).toUpperCase() + kind.slice(1); - kindUpper += (kind === 'alias') ? 'es' : 's'; - - content += `\n`; - content += `

${kindUpper}

\n`; - - content += `
\n`; - - for (const item of apis) { - if (item.changed) { - content += `
\n`; - } else { - content += `
\n`; - } - - content += `
\n`; - content += ` \n`; - content += ` ${item.name}\n`; - content += ` \n`; - content += `
\n`; - - let shortComment = Array.isArray(item.comment) ? item.comment[0] : item.comment; - shortComment = shortComment || ''; - - shortComment = shortComment.replace(/\..*/, ''); - - content += `
\n`; - content += ` ${render(version, shortComment)}\n`; - content += `
\n`; - content += `
\n`; - } - - content += `
\n`; - - return content; -} - -function versionIndexContent(version, apiData) { - let content = ""; - let hasSystem = false; - - content += `
\n`; - content += `
\n`; - content += `

${projectTitle} ${version}

\n`; - - content += produceSearchArea(version, 'version'); - content += produceVersionPicker(version, "versionHeaderVersionSelect", - (v) => `${linkPrefix}/${v}/index.html`); - - content += `
\n`; - - content += `\n`; - content += `

Groups

\n`; - content += `
    \n`; - - for (const group of Object.keys(apiData['groups']).sort((a, b) => { - if (a.startsWith('sys/')) { return 1; } - if (b.startsWith('sys/')) { return -1; } - return a.localeCompare(b); - }).map(fn => { - let n = fn; - let sys = false; - - if (n.endsWith('.h')) { - n = n.substr(0, n.length - 2); - } - - if (n.startsWith('sys/')) { - n = n.substr(4); - sys = true; - } - - return { - name: n, filename: fn, system: sys, info: apiData['groups'][fn].info, apis: apiData['groups'][fn] - }; - }).filter(filedata => { - return Object.keys(filedata.apis).length > 0 && !fileDenylist.includes(filedata.filename); - })) { - if (group.system && !hasSystem) { - hasSystem = true; - - content += `
\n`; - content += `\n`; - content += `

System Groups (Advanced)

\n`; - content += `
    \n`; - } - - let link = `${linkPrefix}/${version}/`; - link += group.system ? `sys/` : ''; - link += group.name; - link += `/index.html`; - - content += `
  • \n`; - content += `
    \n`; - content += ` \n`; - content += ` ${group.name}\n`; - content += ` \n`; - content += `
    \n`; - - if (group.info?.summary) { - content += `
    \n`; - content += ` ${group.info.summary}`; - content += `
    \n`; - } - - content += `
  • \n`; - } - - content += `
\n`; - - content += `
\n`; - - return content; -} - -async function produceDocumentationIndex(version, apiData) { - const content = versionIndexContent(version, apiData); - - const versionDir = `${outputPath}/${version}`; - const filename = `${versionDir}/index.html`; - - await fs.mkdir(versionDir, { recursive: true }); - await fs.writeFile(filename, await layout({ - title: `APIs (${projectTitle} ${version})`, - content: content - })); -} - -async function documentationIsUpToDateForVersion(version, apiData) { - try { - const existingMetadata = JSON.parse(await fs.readFile(`${outputPath}/${version}/.metadata`)); - return existingMetadata?.commit === apiData.info.commit; - } - catch (e) { - } - - return false; -} - -async function produceDocumentationMetadata(version, apiData) { - const versionDir = `${outputPath}/${version}`; - const filename = `${versionDir}/.metadata`; - - await fs.mkdir(versionDir, { recursive: true }); - await fs.writeFile(filename, JSON.stringify(apiData.info, null, 2) + "\n"); -} - -async function cleanupOldDocumentation(version) { - const versionDir = `${outputPath}/${version}`; - - for (const fn of await fs.readdir(versionDir)) { - if (fn === '.metadata') { - continue; - } - - const path = `${versionDir}/${fn}`; - await fs.rm(path, { recursive: true }); - } -} - -async function produceDocumentationForVersion(version, apiData) { - if (!options.force && await documentationIsUpToDateForVersion(version, apiData)) { - if (options.verbose) { - console.log(`Documentation exists for ${version} at version ${apiData.info.commit.substr(0, 7)}; skipping...`); - } - - return; - } - - if (options.verbose) { - console.log(`Producing documentation for ${version}...`); - } - - await cleanupOldDocumentation(version); - - await produceDocumentationForApis(version, apiData); - - for (const group in apiData['groups']) { - await produceIndexForGroup(version, group, apiData); - } - - await produceDocumentationIndex(version, apiData); - - await produceDocumentationMetadata(version, apiData); -} - -function versionDeltaData(version, api) { - const base = { version: version, api: api }; - - if (api.kind === 'function') { - return { - ...base, - returns: api.returns?.type || 'int', - params: api.params?.map((p) => p.type) || [ 'void' ] - }; - } - else if (api.kind === 'enum') { - return { - ...base, - members: api.members?.map((m) => { return { 'name': m.name, 'value': m.value } }) - }; - } - else if (api.kind === 'callback') { - return { ...base, }; - } - else if (api.kind === 'alias') { - return { ...base, }; - } - else if (api.kind === 'struct') { - return { - ...base, - members: api.members?.map((m) => { return { 'name': m.name, 'type': m.type } }) - }; - } - else if (api.kind === 'macro') { - return { - ...base, - name: api.name, - value: api.value - }; - } - else { - throw new Error(`unknown api kind: '${api.kind}'`); - } -} - -function deltasEqual(a, b) { - const unversionedA = { ...a }; - const unversionedB = { ...b }; - - delete unversionedA.version; - delete unversionedA.api; - delete unversionedA.changed; - delete unversionedB.version; - delete unversionedB.api; - delete unversionedB.changed; - - return JSON.stringify(unversionedA) === JSON.stringify(unversionedB); -} - -const apiForVersionCache = { }; -function allApisForVersion(version, apiData) { - if (apiForVersionCache[version]) { - return apiForVersionCache[version]; - } - - let result = { }; - for (const file in apiData['groups']) { - result = { ...result, ...apiData['groups'][file].apis }; - } - - apiForVersionCache[version] = result; - return result; -} - -function seedVersionApis(apiData) { - for (const version in apiData) { - allApisForVersion(version, apiData[version]); - } -} - -function calculateVersionDeltas(apiData) { - for (const version in apiData) { - const apisForVersion = allApisForVersion(version, apiData[version]); - - for (const api in apisForVersion) { - if (!versionDeltas[api]) { - versionDeltas[api] = [ ]; - } - - versionDeltas[api].push(versionDeltaData(version, apisForVersion[api])); - } - } - - for (const api in versionDeltas) { - const count = versionDeltas[api].length; - - versionDeltas[api][count - 1].changed = true; - - for (let i = count - 2; i >= 0; i--) { - versionDeltas[api][i].changed = !deltasEqual(versionDeltas[api][i], versionDeltas[api][i + 1]); - } - } -} - -async function produceSearch(versions) { - if (options.verbose) { - console.log(`Producing search page...`); - } - - let content = ""; - - content += `\n`; - content += `\n`; - content += `\n`; - content += `\n`; - - content += `\n`; - - content += ` \n`; - - const filename = `${outputPath}/search.html`; - - await fs.mkdir(outputPath, { recursive: true }); - await fs.writeFile(filename, await layout({ - title: `API search (${projectTitle})`, - content: content - })); -} - -async function produceMainIndex(versions) { - const versionDefault = versions[0]; - - if (options.verbose) { - console.log(`Producing documentation index...`); - } - - let content = ""; - - content += `\n`; - content += `\n`; - - content += versionIndexContent(versionDefault, apiData[versionDefault]); - - const filename = `${outputPath}/index.html`; - - await fs.mkdir(outputPath, { recursive: true }); - await fs.writeFile(filename, await layout({ - title: `APIs (${projectTitle} ${versionDefault})`, - content: content - })); -} - -function versionSort(a, b) { - if (a === b) { - return 0; - } - - const aVersion = a.match(/^v(\d+)(?:\.(\d+)(?:\.(\d+)(?:\.(\d+))?)?)?(?:-(.*))?$/); - const bVersion = b.match(/^v(\d+)(?:\.(\d+)(?:\.(\d+)(?:\.(\d+))?)?)?(?:-(.*))?$/); - - if (!aVersion && !bVersion) { - return a.localeCompare(b); - } - else if (aVersion && !bVersion) { - return -1; - } - else if (!aVersion && bVersion) { - return 1; - } - - for (let i = 1; i < 5; i++) { - if (!aVersion[i] && !bVersion[i]) { - break; - } - else if (aVersion[i] && !bVersion[i]) { - return 1; - } - else if (!aVersion[i] && bVersion[i]) { - return -1; - } - else if (aVersion[i] !== bVersion[i]) { - return aVersion[i] - bVersion[i]; - } - } - - if (aVersion[5] && !bVersion[5]) { - return -1; - } - else if (!aVersion[5] && bVersion[5]) { - return 1; - } - else if (aVersion[5] && bVersion[5]) { - return aVersion[5].localeCompare(bVersion[5]); - } - - return 0; -} - -program.option('--output ') - .option('--layout ') - .option('--jekyll-layout ') - .option('--version ') - .option('--verbose') - .option('--force') - .option('--strict'); -program.parse(); - -const options = program.opts(); - -if (program.args.length != 2) { - console.error(`usage: ${path.basename(process.argv[1])} raw_api_dir output_dir`); - process.exit(1); -} - -const docsPath = program.args[0]; -const outputPath = program.args[1]; - -(async () => { - try { - const v = options.version ? options.version : - (await fs.readdir(docsPath)) - .filter(a => a.endsWith('.json')) - .map(a => a.replace(/\.json$/, '')); - - versions.push(...v.sort(versionSort).reverse()); - - for (const version of versions) { - if (options.verbose) { - console.log(`Reading documentation data for ${version}...`); - } - - apiData[version] = JSON.parse(await fs.readFile(`${docsPath}/${version}.json`)); - } - - if (showVersions) { - if (options.verbose) { - console.log(`Calculating version deltas...`); - } - - calculateVersionDeltas(apiData); - } - - for (const version of versions) { - await produceDocumentationForVersion(version, apiData[version]); - } - - await produceSearch(versions); - await produceMainIndex(versions); - } catch (e) { - console.error(e); - process.exit(1); - } -})(); diff --git a/vendor/libgit2-sys/libgit2/script/api-docs/generate b/vendor/libgit2-sys/libgit2/script/api-docs/generate deleted file mode 100755 index 76f3d8c..0000000 --- a/vendor/libgit2-sys/libgit2/script/api-docs/generate +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash -# -# Usage: generate repo_path output_path -# -# Example: generate https://github.com/libgit2/libgit2 path_to_output -# to clone the repository from GitHub and produce documentation; -# the repo_path can also be a local path - -set -eo pipefail - -source_path=$(mktemp -d) -verbose= -force= - -for var in "$@"; do - if [ "${var}" == "--verbose" ]; then - verbose=true - elif [ "${var}" == "--force" ]; then - force=true - elif [ "${repo_path}" == "" ]; then - repo_path="${var}" - elif [ "${output_path}" == "" ]; then - output_path="${var}" - else - repo_path="" - output_path="" - fi -done - -if [ "${repo_path}" = "" -o "${output_path}" = "" ]; then - echo "usage: $0 [--verbose] [--force] repo_path output_path" 1>&2 - exit 1 -fi - -function do_checkout { - if [ "$1" = "" ]; then - echo "usage: $0 source_path" 1>&2 - exit 1 - fi - - if [ "${verbose}" ]; then - echo ":: Checking out source trees..." - echo "" - fi - - source_path=$1 - - mkdir -p "${source_path}" - git clone "${repo_path}" "${source_path}/main" --no-checkout - ( cd "${source_path}/main" && git sparse-checkout set --no-cone 'include/*' ) - ( cd "${source_path}/main" && git read-tree origin/main ) - ( cd "${source_path}/main" && git checkout -- include ) - - for tag in $(git --git-dir="${source_path}/main/.git" tag -l); do - git --git-dir="${source_path}/main/.git" worktree add -f "${source_path}/${tag}" "${tag}" --no-checkout - ( cd "${source_path}/${tag}" && git sparse-checkout set --no-cone 'include/*' ) - ( cd "${source_path}/${tag}" && git read-tree HEAD ) - - if [ "${tag}" == "v0.1.0" ]; then - ( cd "${source_path}/${tag}" && git checkout -- src/git ) - elif [ "${tag}" == "v0.2.0" -o "${tag}" == "v0.3.0" ]; then - ( cd "${source_path}/${tag}" && git checkout -- src/git2 ) - else - ( cd "${source_path}/${tag}" && git checkout -- include ) - fi - done -} - -do_checkout ${source_path} - -if [ "${verbose}" ]; then - echo "" - echo ":: Generating raw API documentation..." - echo "" -fi - -for version in ${source_path}/*; do - version=$(echo "${version}" | sed -e "s/.*\///") - commit=$( cd "${source_path}/${version}" && git rev-parse HEAD ) - - if [ -f "${output_path}/api/${version}.json" ]; then - existing_commit=$(jq -r .info.commit < "${output_path}/api/${version}.json") - - if [ "${existing_commit}" == "${commit}" -a ! "${force}" ]; then - if [ "${verbose}" ]; then - echo "Raw API documentation for ${version} exists; skipping..." - fi - - continue - fi - fi - - echo "Generating raw API documentation for ${version}..." - mkdir -p "${output_path}/api" - node ./api-generator.js "${source_path}/${version}" > "${output_path}/api/${version}.json" -done - -if [ "${verbose}" ]; then - echo "" - echo ":: Generating HTML documentation..." - echo "" -fi - -search_options="" -docs_options="" -if [ "${verbose}" ]; then - search_options="${search_options} --verbose" - docs_options="${docs_options} --verbose" -fi -if [ "${force}" ]; then - docs_options="${docs_options} --force" -fi - -node ./search-generator.js ${search_options} "${output_path}/api" "${output_path}/search-index" -node ./docs-generator.js ${docs_options} --jekyll-layout default "${output_path}/api" "${output_path}/reference" diff --git a/vendor/libgit2-sys/libgit2/script/api-docs/package-lock.json b/vendor/libgit2-sys/libgit2/script/api-docs/package-lock.json deleted file mode 100644 index 3ba2226..0000000 --- a/vendor/libgit2-sys/libgit2/script/api-docs/package-lock.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "name": "api-docs", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "dependencies": { - "commander": "^12.1.0", - "markdown-it": "^14.1.0", - "minisearch": "^7.1.1" - } - }, - "node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" - }, - "node_modules/commander": { - "version": "12.1.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", - "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", - "engines": { - "node": ">=18" - } - }, - "node_modules/entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "engines": { - "node": ">=0.12" - }, - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } - }, - "node_modules/linkify-it": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", - "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", - "dependencies": { - "uc.micro": "^2.0.0" - } - }, - "node_modules/markdown-it": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz", - "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==", - "dependencies": { - "argparse": "^2.0.1", - "entities": "^4.4.0", - "linkify-it": "^5.0.0", - "mdurl": "^2.0.0", - "punycode.js": "^2.3.1", - "uc.micro": "^2.1.0" - }, - "bin": { - "markdown-it": "bin/markdown-it.mjs" - } - }, - "node_modules/mdurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", - "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==" - }, - "node_modules/minisearch": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/minisearch/-/minisearch-7.1.1.tgz", - "integrity": "sha512-b3YZEYCEH4EdCAtYP7OlDyx7FdPwNzuNwLQ34SfJpM9dlbBZzeXndGavTrC+VCiRWomL21SWfMc6SCKO/U2ZNw==" - }, - "node_modules/punycode.js": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", - "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", - "engines": { - "node": ">=6" - } - }, - "node_modules/uc.micro": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", - "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==" - } - } -} diff --git a/vendor/libgit2-sys/libgit2/script/api-docs/package.json b/vendor/libgit2-sys/libgit2/script/api-docs/package.json deleted file mode 100644 index 67a6fe7..0000000 --- a/vendor/libgit2-sys/libgit2/script/api-docs/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "dependencies": { - "commander": "^12.1.0", - "markdown-it": "^14.1.0", - "minisearch": "^7.1.1" - } -} diff --git a/vendor/libgit2-sys/libgit2/script/api-docs/search-generator.js b/vendor/libgit2-sys/libgit2/script/api-docs/search-generator.js deleted file mode 100755 index cad73f9..0000000 --- a/vendor/libgit2-sys/libgit2/script/api-docs/search-generator.js +++ /dev/null @@ -1,212 +0,0 @@ -#!/usr/bin/env node - -const markdownit = require('markdown-it'); -const { program } = require('commander'); -const minisearch = require('minisearch'); - -const path = require('node:path'); -const fs = require('node:fs/promises'); - -const linkPrefix = '/docs/reference'; - -const defaultBranch = 'main'; - -function uniqueifyId(api, nodes) { - let suffix = "", i = 1; - - while (true) { - const possibleId = `${api.kind}-${api.name}${suffix}`; - let collision = false; - - for (const item of nodes) { - if (item.id === possibleId) { - collision = true; - break; - } - } - - if (!collision) { - return possibleId; - } - - suffix = `-${++i}`; - } -} - -async function produceSearchIndex(version, apiData) { - const nodes = [ ]; - - for (const group in apiData['groups']) { - for (const name in apiData['groups'][group]['apis']) { - const api = apiData['groups'][group]['apis'][name]; - - let displayName = name; - - if (api.kind === 'macro') { - displayName = displayName.replace(/\(.*/, ''); - } - - const apiSearchData = { - id: uniqueifyId(api, nodes), - name: displayName, - group: group, - kind: api.kind - }; - - apiSearchData.description = Array.isArray(api.comment) ? - api.comment[0] : api.comment; - - let detail = ""; - - if (api.kind === 'macro') { - detail = api.value; - } - else if (api.kind === 'alias') { - detail = api.type; - } - else { - let details = undefined; - - if (api.kind === 'struct' || api.kind === 'enum') { - details = api.members; - } - else if (api.kind === 'function' || api.kind === 'callback') { - details = api.params; - } - else { - throw new Error(`unknown api type '${api.kind}'`); - } - - for (const item of details || [ ]) { - if (detail.length > 0) { - detail += ' '; - } - - detail += item.name; - - if (item.comment) { - detail += ' '; - detail += item.comment; - } - } - - if (api.kind === 'function' || api.kind === 'callback') { - if (detail.length > 0 && api.returns?.type) { - detail += ' ' + api.returns.type; - } - - if (detail.length > 0 && api.returns?.comment) { - detail += ' ' + api.returns.comment; - } - } - } - - detail = detail.replaceAll(/\s+/g, ' ') - .replaceAll(/[\"\'\`]/g, ''); - - apiSearchData.detail = detail; - - nodes.push(apiSearchData); - } - } - - const index = new minisearch({ - fields: [ 'name', 'description', 'detail' ], - storeFields: [ 'name', 'group', 'kind', 'description' ], - searchOptions: { boost: { name: 5, description: 2 } } - }); - - index.addAll(nodes); - - const filename = `${outputPath}/${version}.json`; - await fs.mkdir(outputPath, { recursive: true }); - await fs.writeFile(filename, JSON.stringify(index, null, 2)); -} - -function versionSort(a, b) { - if (a === b) { - return 0; - } - - const aVersion = a.match(/^v(\d+)(?:\.(\d+)(?:\.(\d+)(?:\.(\d+))?)?)?(?:-(.*))?$/); - const bVersion = b.match(/^v(\d+)(?:\.(\d+)(?:\.(\d+)(?:\.(\d+))?)?)?(?:-(.*))?$/); - - if (!aVersion && !bVersion) { - return a.localeCompare(b); - } - else if (aVersion && !bVersion) { - return -1; - } - else if (!aVersion && bVersion) { - return 1; - } - - for (let i = 1; i < 5; i++) { - if (!aVersion[i] && !bVersion[i]) { - break; - } - else if (aVersion[i] && !bVersion[i]) { - return 1; - } - else if (!aVersion[i] && bVersion[i]) { - return -1; - } - else if (aVersion[i] !== bVersion[i]) { - return aVersion[i] - bVersion[i]; - } - } - - if (aVersion[5] && !bVersion[5]) { - return -1; - } - else if (!aVersion[5] && bVersion[5]) { - return 1; - } - else if (aVersion[5] && bVersion[5]) { - return aVersion[5].localeCompare(bVersion[5]); - } - - return 0; -} - -program.option('--verbose') - .option('--version '); -program.parse(); - -const options = program.opts(); - -if (program.args.length != 2) { - console.error(`usage: ${path.basename(process.argv[1])} raw_api_dir output_dir`); - process.exit(1); -} - -const docsPath = program.args[0]; -const outputPath = program.args[1]; - -(async () => { - try { - const v = options.version ? options.version : - (await fs.readdir(docsPath)) - .filter(a => a.endsWith('.json')) - .map(a => a.replace(/\.json$/, '')); - - const versions = v.sort(versionSort).reverse(); - - for (const version of versions) { - if (options.verbose) { - console.log(`Reading documentation data for ${version}...`); - } - - const apiData = JSON.parse(await fs.readFile(`${docsPath}/${version}.json`)); - - if (options.verbose) { - console.log(`Creating minisearch index for ${version}...`); - } - - await produceSearchIndex(version, apiData); - } - } catch (e) { - console.error(e); - process.exit(1); - } -})(); diff --git a/vendor/libgit2-sys/libgit2/script/backport.sh b/vendor/libgit2-sys/libgit2/script/backport.sh deleted file mode 100755 index 3c2f899..0000000 --- a/vendor/libgit2-sys/libgit2/script/backport.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -if test $# -eq 0 -then - echo "USAGE: $0 <#PR> [<#PR>...]" - exit -fi - -commits= - -for pr in $* -do - mergecommit=$(git rev-parse ":/Merge pull request #$pr" || exit 1) - mergebase=$(git merge-base "$mergecommit"^1 "$mergecommit"^2 || exit 1) - - commits="$commits $(git rev-list --reverse "$mergecommit"^2 ^"$mergebase")" -done - -echo "Cherry-picking the following commits:" -git rev-list --no-walk --oneline $commits -echo - -git cherry-pick $commits diff --git a/vendor/libgit2-sys/libgit2/script/leaks.sh b/vendor/libgit2-sys/libgit2/script/leaks.sh deleted file mode 100755 index 4ae748c..0000000 --- a/vendor/libgit2-sys/libgit2/script/leaks.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -export MallocStackLogging=1 -export MallocScribble=1 -export MallocLogFile=/dev/null -# Exclude known Apple Security framework leak in CryptKit::FEEKeyInfoProvider -# which occurs during SSL/TLS handshakes and is not in libgit2's control -export CLAR_AT_EXIT="leaks -quiet -exclude=SSLHandshake \$PPID" -exec "$@" diff --git a/vendor/libgit2-sys/libgit2/script/release.py b/vendor/libgit2-sys/libgit2/script/release.py deleted file mode 100755 index 1a240de..0000000 --- a/vendor/libgit2-sys/libgit2/script/release.py +++ /dev/null @@ -1,191 +0,0 @@ -#!/usr/bin/env python - -from collections import namedtuple - -import argparse -import base64 -import copy -import json -import subprocess -import sys -import urllib.parse -import urllib.request -import urllib.error - -class Error(Exception): - pass - -class Version(object): - def __init__(self, version): - versions = version.split(sep='.') - if len(versions) < 2 or len(versions) > 3: - raise Error("Invalid version string '{}'".format(version)) - self.major = int(versions[0]) - self.minor = int(versions[1]) - self.revision = int(versions[2]) if len(versions) == 3 else 0 - - def __str__(self): - return '{}.{}.{}'.format(self.major, self.minor, self.revision) - - def __eq__(self, other): - return self.major == other.major and self.minor == other.minor and self.revision == other.revision - -def verify_version(version): - expected = { - 'VERSION': [ '"{}"'.format(version), None ], - 'VER_MAJOR': [ str(version.major), None ], - 'VER_MINOR': [ str(version.minor), None ], - 'VER_REVISION': [ str(version.revision), None ], - 'VER_PATCH': [ '0', None ], - 'SOVERSION': [ '"{}.{}"'.format(version.major, version.minor), None ], - } - - # Parse CMakeLists - with open('CMakeLists.txt') as f: - for line in f.readlines(): - if line.startswith('project(libgit2 VERSION "{}"'.format(version)): - break - else: - raise Error("cmake: invalid project definition") - - # Parse version.h - with open('include/git2/version.h') as f: - lines = f.readlines() - - for key in expected.keys(): - define = '#define LIBGIT2_{} '.format(key) - for line in lines: - if line.startswith(define): - expected[key][1] = line[len(define):].strip() - break - else: - raise Error("version.h: missing define for '{}'".format(key)) - - for k, v in expected.items(): - if v[0] != v[1]: - raise Error("version.h: define '{}' does not match (got '{}', expected '{}')".format(k, v[0], v[1])) - - with open('package.json') as f: - pkg = json.load(f) - - try: - pkg_version = Version(pkg["version"]) - except KeyError as err: - raise Error("package.json: missing the field {}".format(err)) - - if pkg_version != version: - raise Error("package.json: version does not match (got '{}', expected '{}')".format(pkg_version, version)) - -def generate_relnotes(tree, version): - with open('docs/changelog.md') as f: - lines = f.readlines() - - if not lines[0].startswith('v'): - raise Error("changelog.md: missing section for v{}".format(version)) - try: - v = Version(lines[0][1:].strip()) - except: - raise Error("changelog.md: invalid version string {}".format(lines[0].strip())) - if v != version: - raise Error("changelog.md: changelog version doesn't match (got {}, expected {})".format(v, version)) - if not lines[1].startswith('----'): - raise Error("changelog.md: missing version header") - if lines[2] != '\n': - raise Error("changelog.md: missing newline after version header") - - for i, line in enumerate(lines[3:]): - if not line.startswith('v'): - continue - try: - Version(line[1:].strip()) - break - except: - continue - else: - raise Error("changelog.md: cannot find section header of preceding release") - - return ''.join(lines[3:i + 3]).strip() - -def git(*args): - process = subprocess.run([ 'git', *args ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if process.returncode != 0: - raise Error('Failed executing git {}: {}'.format(' '.join(args), process.stderr.decode())) - return process.stdout - -def post(url, data, contenttype, user, password): - request = urllib.request.Request(url, data=data) - request.add_header('Accept', 'application/json') - request.add_header('Content-Type', contenttype) - request.add_header('Content-Length', len(data)) - request.add_header('Authorization', 'Basic ' + base64.b64encode('{}:{}'.format(user, password).encode()).decode()) - - try: - response = urllib.request.urlopen(request) - if response.getcode() != 201: - raise Error("POST to '{}' failed: {}".format(url, response.reason)) - except urllib.error.URLError as e: - raise Error("POST to '{}' failed: {}".format(url, e)) - data = json.load(response) - - return data - -def generate_asset(version, tree, archive_format): - Asset = namedtuple('Asset', ['name', 'label', 'mimetype', 'data']) - mimetype = 'application/{}'.format('gzip' if archive_format == 'tar.gz' else 'zip') - return Asset( - "libgit2-{}.{}".format(version, archive_format), "Release sources: libgit2-{}.{}".format(version, archive_format), mimetype, - git('archive', '--format', archive_format, '--prefix', 'libgit2-{}/'.format(version), tree) - ) - -def release(args): - params = { - "tag_name": 'v' + str(args.version), - "name": 'libgit2 v' + str(args.version), - "target_commitish": git('rev-parse', args.tree).decode().strip(), - "body": generate_relnotes(args.tree, args.version), - } - assets = [ - generate_asset(args.version, args.tree, 'tar.gz'), - generate_asset(args.version, args.tree, 'zip'), - ] - - if args.dryrun: - for k, v in params.items(): - print('{}: {}'.format(k, v)) - for asset in assets: - print('asset: name={}, label={}, mimetype={}, bytes={}'.format(asset.name, asset.label, asset.mimetype, len(asset.data))) - return - - try: - url = 'https://api.github.com/repos/{}/releases'.format(args.repository) - response = post(url, json.dumps(params).encode(), 'application/json', args.user, args.password) - except Error as e: - raise Error('Could not create release: ' + str(e)) - - for asset in assets: - try: - url = list(urllib.parse.urlparse(response['upload_url'].split('{?')[0])) - url[4] = urllib.parse.urlencode({ 'name': asset.name, 'label': asset.label }) - post(urllib.parse.urlunparse(url), asset.data, asset.mimetype, args.user, args.password) - except Error as e: - raise Error('Could not upload asset: ' + str(e)) - -def main(): - parser = argparse.ArgumentParser(description='Create a libgit2 release') - parser.add_argument('--tree', default='HEAD', help='tree to create release for (default: HEAD)') - parser.add_argument('--dryrun', action='store_true', help='generate release, but do not post it') - parser.add_argument('--repository', default='libgit2/libgit2', help='GitHub repository to create repository in') - parser.add_argument('--user', help='user to authenticate as') - parser.add_argument('--password', help='password to authenticate with') - parser.add_argument('version', type=Version, help='version of the new release') - args = parser.parse_args() - - verify_version(args.version) - release(args) - -if __name__ == '__main__': - try: - main() - except Error as e: - print(e) - sys.exit(1) diff --git a/vendor/libgit2-sys/libgit2/script/sanitizers.supp b/vendor/libgit2-sys/libgit2/script/sanitizers.supp deleted file mode 100644 index 4e0e9be..0000000 --- a/vendor/libgit2-sys/libgit2/script/sanitizers.supp +++ /dev/null @@ -1,4 +0,0 @@ -[undefined] -# This library allows unaligned access on Intel-like processors. Prevent UBSan -# from complaining about that. -fun:sha1_compression_states diff --git a/vendor/libgit2-sys/libgit2/script/thread-sanitizer.supp b/vendor/libgit2-sys/libgit2/script/thread-sanitizer.supp deleted file mode 100644 index 97d2304..0000000 --- a/vendor/libgit2-sys/libgit2/script/thread-sanitizer.supp +++ /dev/null @@ -1,26 +0,0 @@ -# In attr_file_free, the locks are acquired in the opposite order in which they -# are normally acquired. This is probably something worth fixing to have a -# consistent lock hierarchy that is easy to understand. -deadlock:attr_cache_lock - -# git_mwindow_file_register has the possibility of evicting some files from the -# global cache. In order to avoid races and closing files that are currently -# being accessed, before evicting any file it will attempt to acquire that -# file's lock. Finally, git_mwindow_file_register is typically called with a -# file lock held, because the caller will use the fd in the mwf immediately -# after registering it. This causes ThreadSanitizer to observe different orders -# of acquisition of the mutex (which implies a possibility of a deadlock), -# _but_ since the files are added to the cache after other files have been -# evicted, there cannot be a case where mwf A is trying to be registered while -# evicting mwf B concurrently and viceversa: at most one of them can be present -# in the cache. -deadlock:git_mwindow_file_register - -# When invoking the time/timezone functions from git_signature_now(), they -# access libc methods that need to be instrumented to correctly analyze the -# data races. -called_from_lib:libc.so.6 - -# TODO(#5592): Investigate and fix this. It can be triggered by the `thread` -# test suite. -race:git_filter_list__load_ext diff --git a/vendor/libgit2-sys/libgit2/script/user_model.c b/vendor/libgit2-sys/libgit2/script/user_model.c deleted file mode 100644 index 4942527..0000000 --- a/vendor/libgit2-sys/libgit2/script/user_model.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -void *realloc(void *ptr, size_t size); -void *memmove(void *dest, const void *src, size_t n); -size_t strlen(const char *s); - -typedef struct va_list_str *va_list; - -typedef struct git_vector { - void **contents; - size_t length; -} git_vector; - -typedef struct git_buf { - char *ptr; - size_t asize, size; -} git_buf; - -int git_vector_insert(git_vector *v, void *element) -{ - if (!v) - __coverity_panic__(); - - v->contents = realloc(v->contents, ++v->length); - if (!v->contents) - __coverity_panic__(); - v->contents[v->length] = element; - - return 0; -} - -int git_buf_len(const struct git_buf *buf) -{ - return strlen(buf->ptr); -} - -int git_buf_vprintf(git_buf *buf, const char *format, va_list ap) -{ - char ch, *s; - size_t len; - - __coverity_string_null_sink__(format); - __coverity_string_size_sink__(format); - - ch = *format; - ch = *(char *)ap; - - buf->ptr = __coverity_alloc__(len); - __coverity_writeall__(buf->ptr); - buf->size = len; - - return 0; -} - -int git_buf_put(git_buf *buf, const char *data, size_t len) -{ - buf->ptr = __coverity_alloc__(buf->size + len + 1); - memmove(buf->ptr + buf->size, data, len); - buf->size += len; - buf->ptr[buf->size + len] = 0; - return 0; -} - -int git_buf_set(git_buf *buf, const void *data, size_t len) -{ - buf->ptr = __coverity_alloc__(len + 1); - memmove(buf->ptr, data, len); - buf->size = len + 1; - return 0; -} - -void clar__fail( - const char *file, - int line, - const char *error, - const char *description, - int should_abort) -{ - if (should_abort) - __coverity_panic__(); -} - -void clar__assert( - int condition, - const char *file, - int line, - const char *error, - const char *description, - int should_abort) -{ - if (!condition && should_abort) - __coverity_panic__(); -} diff --git a/vendor/libgit2-sys/libgit2/script/user_nodefs.h b/vendor/libgit2-sys/libgit2/script/user_nodefs.h deleted file mode 100644 index b6e2df3..0000000 --- a/vendor/libgit2-sys/libgit2/script/user_nodefs.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#nodef GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { __coverity_panic__(); } -#nodef GIT_ERROR_CHECK_ALLOC_BUF(buf) if (buf == NULL || git_buf_oom(buf)) { __coverity_panic__(); } - -#nodef GITERR_CHECK_ALLOC_ADD(out, one, two) \ - if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { __coverity_panic__(); } - -#nodef GITERR_CHECK_ALLOC_ADD3(out, one, two, three) \ - if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { __coverity_panic__(); } - -#nodef GITERR_CHECK_ALLOC_ADD4(out, one, two, three, four) \ - if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { __coverity_panic__(); } - -#nodef GITERR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \ - if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { __coverity_panic__(); } - -#nodef GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) { __coverity_panic__(); } - -#nodef LOOKS_LIKE_DRIVE_PREFIX(S) (strlen(S) >= 2 && git__isalpha((S)[0]) && (S)[1] == ':') - -#nodef git_vector_foreach(v, iter, elem) \ - for ((iter) = 0; (v)->contents != NULL && (iter) < (v)->length && ((elem) = (v)->contents[(iter)], 1); (iter)++ ) - -#nodef git_vector_rforeach(v, iter, elem) \ - for ((iter) = (v)->length - 1; (v)->contents != NULL && (iter) < SIZE_MAX && ((elem) = (v)->contents[(iter)], 1); (iter)-- ) diff --git a/vendor/libgit2-sys/libgit2/script/valgrind.sh b/vendor/libgit2-sys/libgit2/script/valgrind.sh deleted file mode 100755 index aacd767..0000000 --- a/vendor/libgit2-sys/libgit2/script/valgrind.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -exec valgrind --leak-check=full --show-reachable=yes --child-silent-after-fork=yes --error-exitcode=125 --num-callers=50 --suppressions="$(dirname "${BASH_SOURCE[0]}")/valgrind.supp" "$@" diff --git a/vendor/libgit2-sys/libgit2/script/valgrind.supp b/vendor/libgit2-sys/libgit2/script/valgrind.supp deleted file mode 100644 index 79e8378..0000000 --- a/vendor/libgit2-sys/libgit2/script/valgrind.supp +++ /dev/null @@ -1,261 +0,0 @@ -{ - ignore-zlib-errors-cond - Memcheck:Cond - obj:*libz.so* -} - -{ - ignore-giterror-set-leak - Memcheck:Leak - ... - fun:giterror_set -} - -{ - ignore-git-global-state-leak - Memcheck:Leak - ... - fun:git__global_state -} - -{ - ignore-openssl-ssl-leak - Memcheck:Leak - ... - obj:*libssl.so* - ... -} - -{ - ignore-openssl-crypto-leak - Memcheck:Leak - ... - obj:*libcrypto.so* - ... -} - -{ - ignore-openssl-crypto-cond - Memcheck:Cond - obj:*libcrypto.so* - ... -} - -{ - ignore-openssl-init-leak - Memcheck:Leak - ... - fun:git_openssl_stream_global_init - ... -} - -{ - ignore-openssl-legacy-init-leak - Memcheck:Leak - ... - fun:OPENSSL_init_ssl__legacy - ... -} - -{ - ignore-openssl-malloc-leak - Memcheck:Leak - ... - fun:git_openssl_malloc - ... -} - -{ - ignore-openssl-realloc-leak - Memcheck:Leak - ... - fun:git_openssl_realloc - ... -} - -{ - ignore-glibc-getaddrinfo-cache - Memcheck:Leak - ... - fun:__check_pf -} - -{ - ignore-glibc-getaddrinfo-fn - Memcheck:Leak - ... - fun:getaddrinfo -} - -{ - ignore-curl-global-init - Memcheck:Leak - ... - fun:curl_global_init -} - -{ - ignore-libssh2-init - Memcheck:Leak - ... - fun:gcry_control - fun:libssh2_init - ... -} - -{ - ignore-libssh2-session-create - Memcheck:Leak - ... - fun:_git_ssh_session_create - ... -} - -{ - ignore-libssh2-setup-conn - Memcheck:Leak - ... - fun:_git_ssh_setup_conn - ... -} - -{ - ignore-libssh2-gcrypt-control-leak - Memcheck:Leak - ... - fun:gcry_control - obj:*libssh2.so* -} - -{ - ignore-libssh2-gcrypt-mpinew-leak - Memcheck:Leak - ... - fun:gcry_mpi_new - obj:*libssh2.so* -} - -{ - ignore-libssh2-gcrypt-mpiscan-leak - Memcheck:Leak - ... - fun:gcry_mpi_scan - obj:*libssh2.so* - ... -} - -{ - ignore-libssh2-gcrypt-randomize-leak - Memcheck:Leak - ... - fun:gcry_randomize - obj:*libssh2.so* -} - -{ - ignore-libssh2-gcrypt-sexpfindtoken-leak - Memcheck:Leak - ... - fun:gcry_sexp_find_token - obj:*libssh2.so* -} - -{ - ignore-libssh2-gcrypt-pksign-leak - Memcheck:Leak - ... - fun:gcry_pk_sign - obj:*libssh2.so* -} - -{ - ignore-libssh2-gcrypt-session-handshake - Memcheck:Leak - ... - obj:*libssh2.so* - obj:*libssh2.so* - fun:libssh2_session_handshake - ... -} - -{ - ignore-openssl-undefined-in-read - Memcheck:Cond - ... - obj:*libssl.so* - ... - fun:openssl_read - ... -} - -{ - ignore-openssl-undefined-in-connect - Memcheck:Cond - ... - obj:*libssl.so* - ... - fun:openssl_connect - ... -} - -{ - ignore-openssl-undefined-in-connect - Memcheck:Cond - ... - obj:*libcrypto.so* - ... - fun:openssl_connect - ... -} - -{ - ignore-libssh2-rsa-sha1-sign - Memcheck:Leak - ... - obj:*libgcrypt.so* - fun:_libssh2_rsa_sha1_sign - ... -} - -{ - ignore-libssh2-kexinit - Memcheck:Leak - ... - obj:*libssh2.so* - fun:kexinit - ... -} - -{ - ignore-noai6ai_cached-double-free - Memcheck:Free - fun:free - fun:__libc_freeres - ... - fun:exit - ... -} - -{ - ignore-libcrypto-uninitialized-read-for-entropy - Memcheck:Value8 - ... - obj:*libcrypto.so* - ... -} - -{ - ignore-dlopen-leak - Memcheck:Leak - ... - fun:dlopen - ... -} - -{ - ignore-dlopen-leak - Memcheck:Leak - ... - fun:_dlerror_run - ... -} diff --git a/vendor/libgit2-sys/libgit2/src/CMakeLists.txt b/vendor/libgit2-sys/libgit2/src/CMakeLists.txt deleted file mode 100644 index 73c46e2..0000000 --- a/vendor/libgit2-sys/libgit2/src/CMakeLists.txt +++ /dev/null @@ -1,216 +0,0 @@ -# The main libgit2 source tree: this CMakeLists.txt identifies platform -# support and includes the subprojects that make up core libgit2 support. - -# -# Optional build configuration settings -# - -if(DEPRECATE_HARD) - add_definitions(-DGIT_DEPRECATE_HARD) -endif() - -if(USE_LEAK_CHECKER STREQUAL "valgrind") - add_definitions(-DVALGRIND) -endif() - -# -# Optional debugging functionality -# - -if(DEBUG_POOL) - set(GIT_DEBUG_POOL 1) -endif() -add_feature_info(debugpool GIT_DEBUG_POOL "debug pool allocator") - -if(DEBUG_STRICT_ALLOC) - set(GIT_DEBUG_STRICT_ALLOC 1) -endif() -add_feature_info(debugalloc GIT_DEBUG_STRICT_ALLOC "debug strict allocators") - -if(DEBUG_STRICT_OPEN) - set(GIT_DEBUG_STRICT_OPEN 1) -endif() -add_feature_info(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open") - -# -# Optional feature enablement -# - -include(SelectGSSAPI) -include(SelectHTTPSBackend) -include(SelectHashes) -include(SelectHTTPParser) -include(SelectRegex) -include(SelectXdiff) -include(SelectSSH) -include(SelectZlib) - -# -# Platform support -# - -# futimes/futimens - -if(HAVE_FUTIMENS) - set(GIT_USE_FUTIMENS 1) -endif () -add_feature_info(futimens GIT_USE_FUTIMENS "futimens support") - -# qsort - -# old-style FreeBSD qsort_r() has the 'context' parameter as the first argument -# of the comparison function: -check_prototype_definition_safe(qsort_r - "void (qsort_r)(void *base, size_t nmemb, size_t size, void *context, int (*compar)(void *, const void *, const void *))" - "" "stdlib.h" GIT_QSORT_BSD) - -# GNU or POSIX qsort_r() has the 'context' parameter as the last argument of the -# comparison function: -check_prototype_definition_safe(qsort_r - "void (qsort_r)(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *context)" - "" "stdlib.h" GIT_QSORT_GNU) - -# C11 qsort_s() has the 'context' parameter as the last argument of the -# comparison function, and returns an error status: -check_prototype_definition_safe(qsort_s - "errno_t (qsort_s)(void *base, rsize_t nmemb, rsize_t size, int (*compar)(const void *, const void *, void *), void *context)" - "0" "stdlib.h" GIT_QSORT_C11) - -# MSC qsort_s() has the 'context' parameter as the first argument of the -# comparison function, and as the last argument of qsort_s(): -check_prototype_definition_safe(qsort_s - "void (qsort_s)(void *base, size_t num, size_t width, int (*compare )(void *, const void *, const void *), void *context)" - "" "stdlib.h" GIT_QSORT_MSC) - -# random / entropy data - -check_symbol_exists(getentropy unistd.h GIT_RAND_GETENTROPY) -check_symbol_exists(getloadavg stdlib.h GIT_RAND_GETLOADAVG) - -# poll - -if(WIN32) - set(GIT_IO_WSAPOLL 1) -else() - check_symbol_exists(poll poll.h GIT_IO_POLL) - check_symbol_exists(select sys/select.h GIT_IO_SELECT) -endif() - -# determine architecture of the machine - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(GIT_ARCH_64 1) -elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(GIT_ARCH_32 1) -elseif(CMAKE_SIZEOF_VOID_P) - message(FATAL_ERROR "Unsupported architecture (pointer size is ${CMAKE_SIZEOF_VOID_P} bytes)") -else() - message(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)") -endif() - -# nanosecond mtime/ctime support - -if(USE_NSEC) - set(GIT_USE_NSEC 1) -endif() - -# high-resolution stat support - -if(HAVE_STRUCT_STAT_ST_MTIM) - set(GIT_USE_STAT_MTIM 1) -elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC) - set(GIT_USE_STAT_MTIMESPEC 1) -elseif(HAVE_STRUCT_STAT_ST_MTIME_NSEC) - set(GIT_USE_STAT_MTIME_NSEC 1) -endif() - -# realtime support - -check_library_exists(rt clock_gettime "time.h" NEED_LIBRT) - -if(NEED_LIBRT AND NOT CMAKE_SYSTEM_NAME MATCHES "iOS") - list(APPEND LIBGIT2_SYSTEM_LIBS rt) - list(APPEND LIBGIT2_PC_LIBS "-lrt") -endif() - -# platform libraries - -if(WIN32) - list(APPEND LIBGIT2_SYSTEM_LIBS "ws2_32" "secur32") - list(APPEND LIBGIT2_PC_LIBS "-lws2_32" "-lsecur32") -endif() - -if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") - list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl) - list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl") -endif() - -if(CMAKE_SYSTEM_NAME MATCHES "Haiku") - list(APPEND LIBGIT2_SYSTEM_LIBS gnu network) - list(APPEND LIBGIT2_PC_LIBS "-lgnu -lnetwork") -endif() - -if(AMIGA) - add_definitions(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP) -endif() - -# threads - -if(USE_THREADS) - if(NOT WIN32) - find_package(Threads REQUIRED) - list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT}) - list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT}) - endif() - - set(GIT_THREADS 1) -endif() -add_feature_info(threadsafe USE_THREADS "threadsafe support") - -# -# Optional bundled features -# - -# ntlmclient -if(USE_NTLMCLIENT) - set(GIT_NTLM 1) - add_subdirectory("${PROJECT_SOURCE_DIR}/deps/ntlmclient" "${PROJECT_BINARY_DIR}/deps/ntlmclient") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/ntlmclient") - list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$") -endif() -add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix") - -# -# Optional external dependencies - -# iconv -if(USE_ICONV) - find_package(IntlIconv) -endif() -if(ICONV_FOUND) - set(GIT_USE_ICONV 1) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR}) - list(APPEND LIBGIT2_SYSTEM_LIBS ${ICONV_LIBRARIES}) - list(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES}) -endif() -add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support") - -# -# Include child projects -# - -add_subdirectory(libgit2) -add_subdirectory(util) - -if(BUILD_CLI AND NOT CMAKE_SYSTEM_NAME MATCHES "iOS") - add_subdirectory(cli) -endif() - -# re-export these to the root so that peer projects (tests, fuzzers, -# examples) can use them -set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE) -set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE) -set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE) -set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE) -set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE) -set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE) diff --git a/vendor/libgit2-sys/libgit2/src/README.md b/vendor/libgit2-sys/libgit2/src/README.md deleted file mode 100644 index 10b86c1..0000000 --- a/vendor/libgit2-sys/libgit2/src/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# libgit2 sources - -This is the source that makes up the core of libgit2 and its related -projects. - -* `cli` - A git-compatible command-line interface that uses libgit2. -* `libgit2` - This is the libgit2 project, a cross-platform, linkable library - implementation of Git that you can use in your application. -* `util` - A shared utility library for these projects. diff --git a/vendor/libgit2-sys/libgit2/src/cli/CMakeLists.txt b/vendor/libgit2-sys/libgit2/src/cli/CMakeLists.txt deleted file mode 100644 index 517ede8..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -set(CLI_INCLUDES - "${libgit2_SOURCE_DIR}/src/util" - "${libgit2_SOURCE_DIR}/src/cli" - "${libgit2_SOURCE_DIR}/include" - "${libgit2_BINARY_DIR}/gen_headers" - "${LIBGIT2_DEPENDENCY_INCLUDES}" - "${LIBGIT2_SYSTEM_INCLUDES}") - -if(WIN32 AND NOT CYGWIN) - file(GLOB CLI_SRC_OS win32/*.c) - list(SORT CLI_SRC_OS) -else() - file(GLOB CLI_SRC_OS unix/*.c) - list(SORT CLI_SRC_OS) -endif() - -file(GLOB CLI_SRC_C *.c *.h) -list(SORT CLI_SRC_C) - -# -# The CLI currently needs to be statically linked against libgit2 because -# the utility library uses libgit2's thread-local error buffers. TODO: -# remove this dependency and allow us to dynamically link against libgit2. -# - -if(BUILD_CLI STREQUAL "dynamic") - set(CLI_LIBGIT2_LIBRARY libgit2package) -else() - set(CLI_LIBGIT2_OBJECTS $) -endif() - -# -# Compile and link the CLI -# - -add_executable(git2_cli ${CLI_SRC_C} ${CLI_SRC_OS} ${CLI_OBJECTS} - $ - ${CLI_LIBGIT2_OBJECTS} - ${LIBGIT2_DEPENDENCY_OBJECTS}) -target_link_libraries(git2_cli ${CLI_LIBGIT2_LIBRARY} ${LIBGIT2_SYSTEM_LIBS}) - -set_target_properties(git2_cli PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR}) -set_target_properties(git2_cli PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME}) - -ide_split_sources(git2_cli) - -target_include_directories(git2_cli PRIVATE ${CLI_INCLUDES}) - -if(MSVC_IDE) - # Precompiled headers - set_target_properties(git2_cli PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") - set_source_files_properties(win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h") -endif() - -install(TARGETS git2_cli RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/vendor/libgit2-sys/libgit2/src/cli/README.md b/vendor/libgit2-sys/libgit2/src/cli/README.md deleted file mode 100644 index 3087c39..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# cli - -A git-compatible command-line interface that uses libgit2. - -## Adding commands - -1. Individual commands have a `main`-like top-level entrypoint. For example: - - ```c - int cmd_help(int argc, char **argv) - ``` - - Although this is the same signature as `main`, commands are not built as - individual standalone executables, they'll be linked into the main cli. - (Though there may be an option for command executables to be built as - standalone executables in the future.) - -2. Commands are prototyped in `cmd.h` and added to `main.c`'s list of - commands (`cli_cmds[]`). Commands should be specified with their name, - entrypoint and a brief description that can be printed in `git help`. - This is done because commands are linked into the main cli. - -3. Commands should accept a `--help` option that displays their help - information. This will be shown when a user runs ` --help` and - when a user runs `help `. - diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd.c b/vendor/libgit2-sys/libgit2/src/cli/cmd.c deleted file mode 100644 index 0b1fafb..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" -#include "cmd.h" - -const cli_cmd_spec *cli_cmd_spec_byname(const char *name) -{ - const cli_cmd_spec *cmd; - - for (cmd = cli_cmds; cmd->name; cmd++) { - if (!strcmp(cmd->name, name)) - return cmd; - } - - return NULL; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd.h b/vendor/libgit2-sys/libgit2/src/cli/cmd.h deleted file mode 100644 index 194a0b5..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef CLI_cmd_h__ -#define CLI_cmd_h__ - -/* Command definitions */ -typedef struct { - const char *name; - int (*fn)(int argc, char **argv); - const char *desc; -} cli_cmd_spec; - -/* Options that are common to all commands (eg --help, --git-dir) */ -extern const cli_opt_spec cli_common_opts[]; - -/* All the commands supported by the CLI */ -extern const cli_cmd_spec cli_cmds[]; - -/* Find a command by name */ -extern const cli_cmd_spec *cli_cmd_spec_byname(const char *name); - -/* Commands */ -extern int cmd_blame(int argc, char **argv); -extern int cmd_cat_file(int argc, char **argv); -extern int cmd_clone(int argc, char **argv); -extern int cmd_config(int argc, char **argv); -extern int cmd_hash_object(int argc, char **argv); -extern int cmd_help(int argc, char **argv); -extern int cmd_index_pack(int argc, char **argv); -extern int cmd_init(int argc, char **argv); - -#endif /* CLI_cmd_h__ */ diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd_blame.c b/vendor/libgit2-sys/libgit2/src/cli/cmd_blame.c deleted file mode 100644 index 180a948..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd_blame.c +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include -#include "common.h" -#include "cmd.h" -#include "error.h" -#include "sighandler.h" -#include "progress.h" - -#include "fs_path.h" -#include "futils.h" -#include "date.h" -#include "hashmap.h" - -#define COMMAND_NAME "blame" - -static char *file; -static int porcelain, line_porcelain; - -static const cli_opt_spec opts[] = { - CLI_COMMON_OPT, - - { CLI_OPT_TYPE_SWITCH, "porcelain", 'p', &porcelain, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "show machine readable output" }, - { CLI_OPT_TYPE_SWITCH, "line-porcelain", 0, &line_porcelain, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "show individual lines in machine readable output" }, - { CLI_OPT_TYPE_LITERAL }, - { CLI_OPT_TYPE_ARG, "file", 0, &file, 0, - CLI_OPT_USAGE_REQUIRED, "file", "file to blame" }, - - { 0 } -}; - -static void print_help(void) -{ - cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0); - printf("\n"); - - printf("Show the origin of each line of a file.\n"); - printf("\n"); - - printf("Options:\n"); - - cli_opt_help_fprint(stdout, opts); -} - -static int strintlen(size_t n) -{ - int len = 1; - - while (n > 10) { - n /= 10; - len++; - - if (len == INT_MAX) - break; - } - - return len; -} - -static int fmt_date(git_str *out, git_time_t time, int offset) -{ - time_t t; - struct tm gmt; - - GIT_ASSERT_ARG(out); - - t = (time_t)(time + offset * 60); - - if (p_gmtime_r(&t, &gmt) == NULL) - return -1; - - return git_str_printf(out, "%.4u-%02u-%02u %02u:%02u:%02u %+03d%02d", - gmt.tm_year + 1900, gmt.tm_mon + 1, gmt.tm_mday, - gmt.tm_hour, gmt.tm_min, gmt.tm_sec, - offset / 60, offset % 60); -} - -static int print_standard(git_blame *blame) -{ - size_t max_line_number = 0; - int max_lineno_len, max_line_len, max_author_len = 0, max_path_len = 0; - const char *last_path = NULL; - const git_blame_line *line; - bool paths_differ = false; - git_str date_str = GIT_STR_INIT; - size_t i; - int ret = 0; - - /* Compute the maximum size of things */ - for (i = 0; i < git_blame_hunkcount(blame); i++) { - const git_blame_hunk *hunk = git_blame_hunk_byindex(blame, i); - size_t hunk_author_len = strlen(hunk->orig_signature->name); - size_t hunk_path_len = strlen(hunk->orig_path); - size_t hunk_max_line_number = - hunk->orig_start_line_number + hunk->lines_in_hunk; - - if (hunk_max_line_number > max_line_number) - max_line_number = hunk_max_line_number; - - if (hunk_author_len > INT_MAX) - max_author_len = INT_MAX; - else if ((int)hunk_author_len > max_author_len) - max_author_len = (int)hunk_author_len; - - if (hunk_path_len > INT_MAX) - hunk_path_len = INT_MAX; - else if ((int)hunk_path_len > max_path_len) - max_path_len = (int)hunk_path_len; - - if (!paths_differ && last_path != NULL && - strcmp(last_path, hunk->orig_path) != 0) { - paths_differ = true; - } - - last_path = hunk->orig_path; - } - - max_lineno_len = strintlen(max_line_number); - - max_author_len--; - - for (i = 1; i < git_blame_linecount(blame); i++) { - const git_blame_hunk *hunk = git_blame_hunk_byline(blame, i); - int oid_abbrev; - - if (!hunk) - break; - - oid_abbrev = hunk->boundary ? 7 : 8; - printf("%s%.*s ", hunk->boundary ? "^" : "", - oid_abbrev, git_oid_tostr_s(&hunk->orig_commit_id)); - - if (paths_differ) - printf("%-*.*s ", max_path_len, max_path_len, hunk->orig_path); - - git_str_clear(&date_str); - if (fmt_date(&date_str, - hunk->orig_signature->when.time, - hunk->orig_signature->when.offset) < 0) { - ret = cli_error_git(); - goto done; - } - - if ((line = git_blame_line_byindex(blame, i)) == NULL) { - ret = cli_error_git(); - goto done; - } - - max_line_len = (int)min(line->len, INT_MAX); - - printf("(%-*.*s %s %*" PRIuZ ") %.*s" , - max_author_len, max_author_len, hunk->orig_signature->name, - date_str.ptr, - max_lineno_len, i, - max_line_len, line->ptr); - printf("\n"); - } - -done: - git_str_dispose(&date_str); - return ret; -} - -GIT_INLINE(uint32_t) oid_hashcode(const git_oid *oid) -{ - uint32_t hash; - memcpy(&hash, oid->id, sizeof(uint32_t)); - return hash; -} - -GIT_HASHSET_SETUP(git_blame_commitmap, const git_oid *, oid_hashcode, git_oid_equal); - -static int print_porcelain(git_blame *blame) -{ - git_blame_commitmap seen_ids = GIT_HASHSET_INIT; - size_t i, j; - - for (i = 0; i < git_blame_hunkcount(blame); i++) { - const git_blame_line *line; - const git_blame_hunk *hunk = git_blame_hunk_byindex(blame, i); - - for (j = 0; j < hunk->lines_in_hunk; j++) { - size_t line_number = hunk->final_start_line_number + j; - bool seen = git_blame_commitmap_contains(&seen_ids, &hunk->orig_commit_id); - - printf("%s %" PRIuZ " %" PRIuZ, - git_oid_tostr_s(&hunk->orig_commit_id), - hunk->orig_start_line_number + j, - hunk->final_start_line_number + j); - - if (!j) - printf(" %" PRIuZ, hunk->lines_in_hunk); - - printf("\n"); - - if ((!j && !seen) || line_porcelain) { - printf("author %s\n", hunk->orig_signature->name); - printf("author-mail <%s>\n", hunk->orig_signature->email); - printf("author-time %" PRId64 "\n", hunk->orig_signature->when.time); - printf("author-tz %+03d%02d\n", - hunk->orig_signature->when.offset / 60, - hunk->orig_signature->when.offset % 60); - - printf("committer %s\n", hunk->orig_committer->name); - printf("committer-mail <%s>\n", hunk->orig_committer->email); - printf("committer-time %" PRId64 "\n", hunk->orig_committer->when.time); - printf("committer-tz %+03d%02d\n", - hunk->orig_committer->when.offset / 60, - hunk->orig_committer->when.offset % 60); - - printf("summary %s\n", hunk->summary); - - /* TODO: previous */ - - printf("filename %s\n", hunk->orig_path); - } - - if ((line = git_blame_line_byindex(blame, line_number)) == NULL) - return cli_error_git(); - - printf("\t%.*s\n", (int)min(line->len, INT_MAX), - line->ptr); - - if (!seen) - git_blame_commitmap_add(&seen_ids, &hunk->orig_commit_id); - } - } - - git_blame_commitmap_dispose(&seen_ids); - return 0; -} - -int cmd_blame(int argc, char **argv) -{ - cli_repository_open_options open_opts = { argv + 1, argc - 1 }; - git_blame_options blame_opts = GIT_BLAME_OPTIONS_INIT; - git_repository *repo = NULL; - git_str workdir_path = GIT_STR_INIT; - git_blame *blame = NULL; - cli_opt invalid_opt; - int ret = 0; - - blame_opts.flags |= GIT_BLAME_USE_MAILMAP; - - if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) - return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); - - if (cli_opt__show_help) { - print_help(); - return 0; - } - - if (!file) { - ret = cli_error_usage("you must specify a file to blame"); - goto done; - } - - if (cli_repository_open(&repo, &open_opts) < 0) - return cli_error_git(); - - if ((ret = cli_resolve_path(&workdir_path, repo, file)) != 0) - goto done; - - if (git_blame_file(&blame, repo, workdir_path.ptr, &blame_opts) < 0) { - ret = cli_error_git(); - goto done; - } - - if (porcelain || line_porcelain) - ret = print_porcelain(blame); - else - ret = print_standard(blame); - -done: - git_str_dispose(&workdir_path); - git_blame_free(blame); - git_repository_free(repo); - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd_cat_file.c b/vendor/libgit2-sys/libgit2/src/cli/cmd_cat_file.c deleted file mode 100644 index 95a0240..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd_cat_file.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include "common.h" -#include "cmd.h" - -#define COMMAND_NAME "cat-file" - -typedef enum { - DISPLAY_CONTENT = 0, - DISPLAY_EXISTS, - DISPLAY_PRETTY, - DISPLAY_SIZE, - DISPLAY_TYPE -} display_t; - -static int display = DISPLAY_CONTENT; -static char *type_name, *object_spec; - -static const cli_opt_spec opts[] = { - CLI_COMMON_OPT, - - { CLI_OPT_TYPE_SWITCH, NULL, 't', &display, DISPLAY_TYPE, - CLI_OPT_USAGE_REQUIRED, NULL, "display the type of the object" }, - { CLI_OPT_TYPE_SWITCH, NULL, 's', &display, DISPLAY_SIZE, - CLI_OPT_USAGE_CHOICE, NULL, "display the size of the object" }, - { CLI_OPT_TYPE_SWITCH, NULL, 'e', &display, DISPLAY_EXISTS, - CLI_OPT_USAGE_CHOICE, NULL, "displays nothing unless the object is corrupt" }, - { CLI_OPT_TYPE_SWITCH, NULL, 'p', &display, DISPLAY_PRETTY, - CLI_OPT_USAGE_CHOICE, NULL, "pretty-print the object" }, - { CLI_OPT_TYPE_ARG, "type", 0, &type_name, 0, - CLI_OPT_USAGE_CHOICE, "type", "the type of object to display" }, - { CLI_OPT_TYPE_ARG, "object", 0, &object_spec, 0, - CLI_OPT_USAGE_REQUIRED, "object", "the object to display" }, - { 0 }, -}; - -static void print_help(void) -{ - cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0); - printf("\n"); - - printf("Display the content for the given object in the repository.\n"); - printf("\n"); - - printf("Options:\n"); - - cli_opt_help_fprint(stdout, opts); -} - -static int print_odb(git_object *object, display_t display) -{ - git_odb *odb = NULL; - git_odb_object *odb_object = NULL; - const unsigned char *content; - git_object_size_t size; - int ret = 0; - - /* - * Our parsed blobs retain the raw content; all other objects are - * parsed into a working representation. To get the raw content, - * we need to do an ODB lookup. (Thankfully, this should be cached - * in-memory from our last call.) - */ - if (git_object_type(object) == GIT_OBJECT_BLOB) { - content = git_blob_rawcontent((git_blob *)object); - size = git_blob_rawsize((git_blob *)object); - } else { - if (git_repository_odb(&odb, git_object_owner(object)) < 0 || - git_odb_read(&odb_object, odb, git_object_id(object)) < 0) { - ret = cli_error_git(); - goto done; - } - - content = git_odb_object_data(odb_object); - size = git_odb_object_size(odb_object); - } - - switch (display) { - case DISPLAY_SIZE: - if (printf("%" PRIu64 "\n", size) < 0) - ret = cli_error_os(); - break; - case DISPLAY_CONTENT: - if (p_write(fileno(stdout), content, (size_t)size) < 0) - ret = cli_error_os(); - break; - default: - GIT_ASSERT(0); - } - -done: - git_odb_object_free(odb_object); - git_odb_free(odb); - return ret; -} - -static int print_type(git_object *object) -{ - if (printf("%s\n", git_object_type2string(git_object_type(object))) < 0) - return cli_error_os(); - - return 0; -} - -static int print_pretty(git_object *object) -{ - const git_tree_entry *entry; - size_t i, count; - - /* - * Only trees are stored in an unreadable format and benefit from - * pretty-printing. - */ - if (git_object_type(object) != GIT_OBJECT_TREE) - return print_odb(object, DISPLAY_CONTENT); - - for (i = 0, count = git_tree_entrycount((git_tree *)object); i < count; i++) { - entry = git_tree_entry_byindex((git_tree *)object, i); - - if (printf("%06o %s %s\t%s\n", - git_tree_entry_filemode_raw(entry), - git_object_type2string(git_tree_entry_type(entry)), - git_oid_tostr_s(git_tree_entry_id(entry)), - git_tree_entry_name(entry)) < 0) - return cli_error_os(); - } - - return 0; -} - -int cmd_cat_file(int argc, char **argv) -{ - cli_repository_open_options open_opts = { argv + 1, argc - 1}; - git_repository *repo = NULL; - git_object *object = NULL; - git_object_t type; - cli_opt invalid_opt; - int giterr, ret = 0; - - if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) - return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); - - if (cli_opt__show_help) { - print_help(); - return 0; - } - - if (cli_repository_open(&repo, &open_opts) < 0) - return cli_error_git(); - - if ((giterr = git_revparse_single(&object, repo, object_spec)) < 0) { - if (display == DISPLAY_EXISTS && giterr == GIT_ENOTFOUND) - ret = 1; - else - ret = cli_error_git(); - - goto done; - } - - if (type_name) { - git_object *peeled; - - if ((type = git_object_string2type(type_name)) == GIT_OBJECT_INVALID) { - ret = cli_error_usage("invalid object type '%s'", type_name); - goto done; - } - - if (git_object_peel(&peeled, object, type) < 0) { - ret = cli_error_git(); - goto done; - } - - git_object_free(object); - object = peeled; - } - - switch (display) { - case DISPLAY_EXISTS: - ret = 0; - break; - case DISPLAY_TYPE: - ret = print_type(object); - break; - case DISPLAY_PRETTY: - ret = print_pretty(object); - break; - default: - ret = print_odb(object, display); - break; - } - -done: - git_object_free(object); - git_repository_free(repo); - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd_clone.c b/vendor/libgit2-sys/libgit2/src/cli/cmd_clone.c deleted file mode 100644 index c18cb28..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd_clone.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include -#include "common.h" -#include "cmd.h" -#include "error.h" -#include "sighandler.h" -#include "progress.h" - -#include "fs_path.h" -#include "futils.h" - -#define COMMAND_NAME "clone" - -static char *branch, *remote_path, *local_path, *depth; -static int quiet, checkout = 1, bare; -static bool local_path_exists; -static cli_progress progress = CLI_PROGRESS_INIT; - -static const cli_opt_spec opts[] = { - CLI_COMMON_OPT, - - { CLI_OPT_TYPE_SWITCH, "quiet", 'q', &quiet, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "display the type of the object" }, - { CLI_OPT_TYPE_SWITCH, "no-checkout", 'n', &checkout, 0, - CLI_OPT_USAGE_DEFAULT, NULL, "don't checkout HEAD" }, - { CLI_OPT_TYPE_SWITCH, "bare", 0, &bare, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "don't create a working directory" }, - { CLI_OPT_TYPE_VALUE, "branch", 'b', &branch, 0, - CLI_OPT_USAGE_DEFAULT, "name", "branch to check out" }, - { CLI_OPT_TYPE_VALUE, "depth", 0, &depth, 0, - CLI_OPT_USAGE_DEFAULT, "depth", "commit depth to check out " }, - { CLI_OPT_TYPE_LITERAL }, - { CLI_OPT_TYPE_ARG, "repository", 0, &remote_path, 0, - CLI_OPT_USAGE_REQUIRED, "repository", "repository path" }, - { CLI_OPT_TYPE_ARG, "directory", 0, &local_path, 0, - CLI_OPT_USAGE_DEFAULT, "directory", "directory to clone into" }, - { 0 } -}; - -static void print_help(void) -{ - cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0); - printf("\n"); - - printf("Clone a repository into a new directory.\n"); - printf("\n"); - - printf("Options:\n"); - - cli_opt_help_fprint(stdout, opts); -} - -static char *compute_local_path(const char *orig_path) -{ - const char *slash; - char *local_path; - - if ((slash = strrchr(orig_path, '/')) == NULL && - (slash = strrchr(orig_path, '\\')) == NULL) - local_path = git__strdup(orig_path); - else - local_path = git__strdup(slash + 1); - - return local_path; -} - -static int compute_depth(const char *depth) -{ - int64_t i; - const char *endptr; - - if (!depth) - return 0; - - if (git__strntol64(&i, depth, strlen(depth), &endptr, 10) < 0 || i < 0 || i > INT_MAX || *endptr) { - fprintf(stderr, "fatal: depth '%s' is not valid.\n", depth); - exit(128); - } - - return (int)i; -} - -static bool validate_local_path(const char *path) -{ - if (!git_fs_path_exists(path)) - return false; - - if (!git_fs_path_isdir(path) || !git_fs_path_is_empty_dir(path)) { - fprintf(stderr, "fatal: destination path '%s' already exists and is not an empty directory.\n", - path); - exit(128); - } - - return true; -} - -static void cleanup(void) -{ - int rmdir_flags = GIT_RMDIR_REMOVE_FILES; - - cli_progress_abort(&progress); - - if (local_path_exists) - rmdir_flags |= GIT_RMDIR_SKIP_ROOT; - - if (!git_fs_path_isdir(local_path)) - return; - - git_futils_rmdir_r(local_path, NULL, rmdir_flags); -} - -static void interrupt_cleanup(void) -{ - cleanup(); - exit(130); -} - -int cmd_clone(int argc, char **argv) -{ - git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; - git_repository *repo = NULL; - cli_opt invalid_opt; - char *computed_path = NULL; - int ret = 0; - - if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) - return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); - - if (cli_opt__show_help) { - print_help(); - return 0; - } - - if (!remote_path) { - ret = cli_error_usage("you must specify a repository to clone"); - goto done; - } - - clone_opts.bare = !!bare; - clone_opts.checkout_branch = branch; - clone_opts.fetch_opts.depth = compute_depth(depth); - - if (!checkout) - clone_opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_NONE; - - if (!local_path) - local_path = computed_path = compute_local_path(remote_path); - - local_path_exists = validate_local_path(local_path); - - cli_sighandler_set_interrupt(interrupt_cleanup); - - if (!local_path_exists && - git_futils_mkdir(local_path, 0777, 0) < 0) { - ret = cli_error_git(); - goto done; - } - - if (!quiet) { - clone_opts.fetch_opts.callbacks.sideband_progress = cli_progress_fetch_sideband; - clone_opts.fetch_opts.callbacks.transfer_progress = cli_progress_fetch_transfer; - clone_opts.fetch_opts.callbacks.payload = &progress; - - clone_opts.checkout_opts.progress_cb = cli_progress_checkout; - clone_opts.checkout_opts.progress_payload = &progress; - - printf("Cloning into '%s'...\n", local_path); - } - - if (git_clone(&repo, remote_path, local_path, &clone_opts) < 0) { - cleanup(); - ret = cli_error_git(); - goto done; - } - - cli_progress_finish(&progress); - -done: - cli_progress_dispose(&progress); - git__free(computed_path); - git_repository_free(repo); - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd_config.c b/vendor/libgit2-sys/libgit2/src/cli/cmd_config.c deleted file mode 100644 index 9056e81..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd_config.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include - -#include "common.h" -#include "cmd.h" - -#define COMMAND_NAME "config" - -typedef enum { - ACTION_NONE = 0, - ACTION_GET, - ACTION_ADD, - ACTION_REPLACE_ALL, - ACTION_LIST -} action_t; - -static action_t action = ACTION_NONE; -static int show_origin; -static int show_scope; -static int null_separator; -static int config_level; -static char *config_filename; -static char *name, *value, *value_pattern; - -static const cli_opt_spec opts[] = { - CLI_COMMON_OPT, \ - - { CLI_OPT_TYPE_SWITCH, "null", 'z', &null_separator, 1, - 0, NULL, "use NUL as a separator" }, - - { CLI_OPT_TYPE_SWITCH, "system", 0, &config_level, GIT_CONFIG_LEVEL_SYSTEM, - 0, NULL, "read/write to system configuration" }, - { CLI_OPT_TYPE_SWITCH, "global", 0, &config_level, GIT_CONFIG_LEVEL_GLOBAL, - CLI_OPT_USAGE_CHOICE, NULL, "read/write to global configuration" }, - { CLI_OPT_TYPE_SWITCH, "local", 0, &config_level, GIT_CONFIG_LEVEL_LOCAL, - CLI_OPT_USAGE_CHOICE, NULL, "read/write to local configuration" }, - { CLI_OPT_TYPE_VALUE, "file", 0, &config_filename, 0, - CLI_OPT_USAGE_CHOICE, "filename", "read/write to specified configuration file" }, - - { CLI_OPT_TYPE_SWITCH, "get", 0, &action, ACTION_GET, - CLI_OPT_USAGE_REQUIRED, NULL, "get a configuration value" }, - { CLI_OPT_TYPE_SWITCH, "add", 0, &action, ACTION_ADD, - CLI_OPT_USAGE_CHOICE, NULL, "add a configuration value" }, - { CLI_OPT_TYPE_SWITCH, "replace-all", 0, &action, ACTION_REPLACE_ALL, - CLI_OPT_USAGE_CHOICE, NULL, "add a configuration value, replacing any old values" }, - { CLI_OPT_TYPE_SWITCH, "list", 'l', &action, ACTION_LIST, - CLI_OPT_USAGE_CHOICE | CLI_OPT_USAGE_SHOW_LONG, - NULL, "list all configuration entries" }, - { CLI_OPT_TYPE_SWITCH, "show-origin", 0, &show_origin, 1, - 0, NULL, "show origin of configuration" }, - { CLI_OPT_TYPE_SWITCH, "show-scope", 0, &show_scope, 1, - 0, NULL, "show scope of configuration" }, - { CLI_OPT_TYPE_ARG, "name", 0, &name, 0, - 0, "name", "name of configuration entry" }, - { CLI_OPT_TYPE_ARG, "value", 0, &value, 0, - 0, "value", "value of configuration entry" }, - { CLI_OPT_TYPE_ARG, "regexp", 0, &value_pattern, 0, - 0, "regexp", "regular expression of values to replace" }, - { 0 }, -}; - -static void print_help(void) -{ - cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0); - printf("\n"); - - printf("Query and set configuration options.\n"); - printf("\n"); - - printf("Options:\n"); - - cli_opt_help_fprint(stdout, opts); -} - -static int get_config(git_config *config) -{ - git_buf value = GIT_BUF_INIT; - char sep = null_separator ? '\0' : '\n'; - int error; - - error = git_config_get_string_buf(&value, config, name); - - if (error && error != GIT_ENOTFOUND) - return cli_error_git(); - - else if (error == GIT_ENOTFOUND) - return 1; - - printf("%s%c", value.ptr, sep); - return 0; -} - -static int add_config(git_config *config) -{ - if (git_config_set_multivar(config, name, "$^", value) < 0) - return cli_error_git(); - - return 0; -} - -static int replace_all_config(git_config *config) -{ - if (git_config_set_multivar(config, name, value_pattern ? value_pattern : ".*", value) < 0) - return cli_error_git(); - - return 0; -} - -static const char *level_name(git_config_level_t level) -{ - switch (level) { - case GIT_CONFIG_LEVEL_PROGRAMDATA: - return "programdata"; - case GIT_CONFIG_LEVEL_SYSTEM: - return "system"; - case GIT_CONFIG_LEVEL_XDG: - return "global"; - case GIT_CONFIG_LEVEL_GLOBAL: - return "global"; - case GIT_CONFIG_LEVEL_LOCAL: - return "local"; - case GIT_CONFIG_LEVEL_APP: - return "command"; - default: - return "unknown"; - } -} - -static int list_config(git_config *config) -{ - git_config_iterator *iterator; - git_config_entry *entry; - char data_separator = null_separator ? '\0' : '\t'; - char kv_separator = null_separator ? '\n' : '='; - char entry_separator = null_separator ? '\0' : '\n'; - int error; - - if (git_config_iterator_new(&iterator, config) < 0) - return cli_error_git(); - - while ((error = git_config_next(&entry, iterator)) == 0) { - if (show_scope) - printf("%s%c", - level_name(entry->level), - data_separator); - - if (show_origin) - printf("%s%s%s%c", - entry->backend_type ? entry->backend_type : "", - entry->backend_type && entry->origin_path ? ":" : "", - entry->origin_path ? entry->origin_path : "", - data_separator); - - printf("%s%c%s%c", entry->name, kv_separator, entry->value, - entry_separator); - } - - if (error != GIT_ITEROVER) - return cli_error_git(); - - git_config_iterator_free(iterator); - return 0; -} - -int cmd_config(int argc, char **argv) -{ - git_repository *repo = NULL; - git_config *config = NULL; - cli_repository_open_options open_opts = { argv + 1, argc - 1}; - cli_opt invalid_opt; - int ret = 0; - - if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) - return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); - - if (cli_opt__show_help) { - print_help(); - return 0; - } - - if (config_filename) { - if (git_config_new(&config) < 0 || - git_config_add_file_ondisk(config, config_filename, - GIT_CONFIG_LEVEL_APP, NULL, 0) < 0) { - ret = cli_error_git(); - goto done; - } - } else { - if (cli_repository_open(&repo, &open_opts) < 0 || - git_repository_config(&config, repo) < 0) { - ret = cli_error_git(); - goto done; - } - - if (config_level && - git_config_open_level(&config, config, config_level) < 0) { - ret = cli_error_git(); - goto done; - } - } - - switch (action) { - case ACTION_ADD: - if (!name || !value || value_pattern) - ret = cli_error_usage("%s --add requires two arguments", COMMAND_NAME); - else - ret = add_config(config); - break; - case ACTION_REPLACE_ALL: - if (!name || !value) - ret = cli_error_usage("%s --replace-all requires two or three arguments", COMMAND_NAME); - else - ret = replace_all_config(config); - break; - case ACTION_GET: - if (!name) - ret = cli_error_usage("%s --get requires an argument", COMMAND_NAME); - else - ret = get_config(config); - break; - case ACTION_LIST: - if (name) - ret = cli_error_usage("%s --list does not take an argument", COMMAND_NAME); - else - ret = list_config(config); - break; - default: - ret = cli_error_usage("unknown action"); - } - -done: - git_config_free(config); - git_repository_free(repo); - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd_hash_object.c b/vendor/libgit2-sys/libgit2/src/cli/cmd_hash_object.c deleted file mode 100644 index 94e7eb9..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd_hash_object.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include "common.h" -#include "cmd.h" - -#include "futils.h" - -#define COMMAND_NAME "hash-object" - -static char *type_name; -static int write_object, read_stdin, literally; -static char **filenames; - -static const cli_opt_spec opts[] = { - CLI_COMMON_OPT, - - { CLI_OPT_TYPE_VALUE, NULL, 't', &type_name, 0, - CLI_OPT_USAGE_DEFAULT, "type", "the type of object to hash (default: \"blob\")" }, - { CLI_OPT_TYPE_SWITCH, NULL, 'w', &write_object, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "write the object to the object database" }, - { CLI_OPT_TYPE_SWITCH, "literally", 0, &literally, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "do not validate the object contents" }, - { CLI_OPT_TYPE_SWITCH, "stdin", 0, &read_stdin, 1, - CLI_OPT_USAGE_REQUIRED, NULL, "read content from stdin" }, - { CLI_OPT_TYPE_ARGS, "file", 0, &filenames, 0, - CLI_OPT_USAGE_CHOICE, "file", "the file (or files) to read and hash" }, - { 0 }, -}; - -static void print_help(void) -{ - cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0); - printf("\n"); - - printf("Compute the object ID for a given file and optionally write that file\nto the object database.\n"); - printf("\n"); - - printf("Options:\n"); - - cli_opt_help_fprint(stdout, opts); -} - -static int hash_buf( - git_odb *odb, - git_str *buf, - git_object_t object_type, - git_oid_t oid_type) -{ - git_oid oid; - - if (!literally) { - int valid = 0; - -#ifdef GIT_EXPERIMENTAL_SHA256 - if (git_object_rawcontent_is_valid(&valid, buf->ptr, buf->size, object_type, oid_type) < 0 || !valid) - return cli_error_git(); -#else - GIT_UNUSED(oid_type); - - if (git_object_rawcontent_is_valid(&valid, buf->ptr, buf->size, object_type) < 0 || !valid) - return cli_error_git(); -#endif - } - - if (write_object) { - if (git_odb_write(&oid, odb, buf->ptr, buf->size, object_type) < 0) - return cli_error_git(); - } else { -#ifdef GIT_EXPERIMENTAL_SHA256 - if (git_odb_hash(&oid, buf->ptr, buf->size, object_type, GIT_OID_SHA1) < 0) - return cli_error_git(); -#else - if (git_odb_hash(&oid, buf->ptr, buf->size, object_type) < 0) - return cli_error_git(); -#endif - } - - if (printf("%s\n", git_oid_tostr_s(&oid)) < 0) - return cli_error_os(); - - return 0; -} - -int cmd_hash_object(int argc, char **argv) -{ - cli_repository_open_options open_opts = { argv + 1, argc - 1}; - git_repository *repo = NULL; - git_odb *odb = NULL; - git_oid_t oid_type; - git_str buf = GIT_STR_INIT; - cli_opt invalid_opt; - git_object_t object_type = GIT_OBJECT_BLOB; - char **filename; - int ret = 0; - - if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) - return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); - - if (cli_opt__show_help) { - print_help(); - return 0; - } - - if (type_name && (object_type = git_object_string2type(type_name)) == GIT_OBJECT_INVALID) - return cli_error_usage("invalid object type '%s'", type_name); - - if (write_object && - (cli_repository_open(&repo, &open_opts) < 0 || - git_repository_odb(&odb, repo) < 0)) { - ret = cli_error_git(); - goto done; - } - - oid_type = git_repository_oid_type(repo); - - /* - * TODO: we're reading blobs, we shouldn't pull them all into main - * memory, we should just stream them into the odb instead. - * (Or create a `git_odb_writefile` API.) - */ - if (read_stdin) { - if (git_futils_readbuffer_fd_full(&buf, fileno(stdin)) < 0) { - ret = cli_error_git(); - goto done; - } - - if ((ret = hash_buf(odb, &buf, object_type, oid_type)) != 0) - goto done; - } else { - for (filename = filenames; *filename; filename++) { - if (git_futils_readbuffer(&buf, *filename) < 0) { - ret = cli_error_git(); - goto done; - } - - if ((ret = hash_buf(odb, &buf, object_type, oid_type)) != 0) - goto done; - } - } - -done: - git_str_dispose(&buf); - git_odb_free(odb); - git_repository_free(repo); - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd_help.c b/vendor/libgit2-sys/libgit2/src/cli/cmd_help.c deleted file mode 100644 index c01163d..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd_help.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include -#include "common.h" -#include "cmd.h" - -#define COMMAND_NAME "help" - -static char *command; - -static const cli_opt_spec opts[] = { - CLI_COMMON_OPT, - - { CLI_OPT_TYPE_ARG, "command", 0, &command, 0, - CLI_OPT_USAGE_DEFAULT, "command", "the command to show help for" }, - { 0 }, -}; - -static int print_help(void) -{ - cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, CLI_OPT_USAGE_SHOW_HIDDEN); - printf("\n"); - - printf("Display help information about %s. If a command is specified, help\n", PROGRAM_NAME); - printf("about that command will be shown. Otherwise, general information about\n"); - printf("%s will be shown, including the commands available.\n", PROGRAM_NAME); - - return 0; -} - -static int print_commands(void) -{ - const cli_cmd_spec *cmd; - - cli_opt_usage_fprint(stdout, PROGRAM_NAME, NULL, cli_common_opts, CLI_OPT_USAGE_SHOW_HIDDEN); - printf("\n"); - - printf("These are the %s commands available:\n\n", PROGRAM_NAME); - - for (cmd = cli_cmds; cmd->name; cmd++) - printf(" %-11s %s\n", cmd->name, cmd->desc); - - printf("\nSee '%s help ' for more information on a specific command.\n", PROGRAM_NAME); - - return 0; -} - -int cmd_help(int argc, char **argv) -{ - char *fake_args[2]; - const cli_cmd_spec *cmd; - cli_opt invalid_opt; - - if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) - return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); - - /* Show the meta-help */ - if (cli_opt__show_help) - return print_help(); - - /* We were not asked to show help for a specific command. */ - if (!command) - return print_commands(); - - /* - * If we were asked for help for a command (eg, `help `), - * delegate back to that command's `--help` option. This lets - * commands own their help. Emulate the command-line arguments - * that would invoke ` --help` and invoke that command. - */ - fake_args[0] = command; - fake_args[1] = "--help"; - - if ((cmd = cli_cmd_spec_byname(command)) == NULL) - return cli_error("'%s' is not a %s command. See '%s help'.", - command, PROGRAM_NAME, PROGRAM_NAME); - - return cmd->fn(2, fake_args); -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd_index_pack.c b/vendor/libgit2-sys/libgit2/src/cli/cmd_index_pack.c deleted file mode 100644 index 6a67990..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd_index_pack.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include "common.h" -#include "cmd.h" -#include "progress.h" - -#define COMMAND_NAME "index-pack" - -#define BUFFER_SIZE (1024 * 1024) - -static int verbose, read_stdin; -static char *filename; -static cli_progress progress = CLI_PROGRESS_INIT; - -static const cli_opt_spec opts[] = { - CLI_COMMON_OPT, - - { CLI_OPT_TYPE_SWITCH, "verbose", 'v', &verbose, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "display progress output" }, - - { CLI_OPT_TYPE_LITERAL }, - - { CLI_OPT_TYPE_SWITCH, "stdin", 0, &read_stdin, 1, - CLI_OPT_USAGE_REQUIRED, NULL, "read from stdin" }, - { CLI_OPT_TYPE_ARG, "pack-file", 0, &filename, 0, - CLI_OPT_USAGE_CHOICE, "pack-file", "packfile path" }, - - { 0 }, -}; - -static void print_help(void) -{ - cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0); - printf("\n"); - - printf("Indexes a packfile and writes the index to disk.\n"); - printf("\n"); - - printf("Options:\n"); - - cli_opt_help_fprint(stdout, opts); -} - -int cmd_index_pack(int argc, char **argv) -{ - cli_opt invalid_opt; - git_indexer *idx = NULL; - git_indexer_options idx_opts = GIT_INDEXER_OPTIONS_INIT; - git_indexer_progress stats = {0}; - char buf[BUFFER_SIZE]; - ssize_t read_len; - int fd, ret; - - if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) - return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); - - if (cli_opt__show_help) { - print_help(); - return 0; - } - - if (verbose) { - idx_opts.progress_cb = cli_progress_indexer; - idx_opts.progress_cb_payload = &progress; - } - - if (read_stdin) { - fd = fileno(stdin); - } else if ((fd = p_open(filename, O_RDONLY)) < 0) { - ret = cli_error_git(); - goto done; - } - -#ifdef GIT_EXPERIMENTAL_SHA256 - idx_opts.oid_type = GIT_OID_SHA1; - - ret = git_indexer_new(&idx, ".", &idx_opts); -#else - ret = git_indexer_new(&idx, ".", 0, NULL, &idx_opts); -#endif - - if (ret < 0) { - ret = cli_error_git(); - goto done; - } - - while ((read_len = p_read(fd, buf, sizeof(buf))) > 0) { - if (git_indexer_append(idx, buf, (size_t)read_len, &stats) < 0) { - ret = cli_error_git(); - goto done; - } - } - - if (git_indexer_commit(idx, &stats) < 0) { - ret = cli_error_git(); - goto done; - } - - cli_progress_finish(&progress); - -done: - if (!read_stdin && fd >= 0) - p_close(fd); - - cli_progress_dispose(&progress); - git_indexer_free(idx); - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/cmd_init.c b/vendor/libgit2-sys/libgit2/src/cli/cmd_init.c deleted file mode 100644 index b646896..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/cmd_init.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include -#include "common.h" -#include "cmd.h" -#include "error.h" -#include "sighandler.h" -#include "progress.h" - -#include "fs_path.h" -#include "futils.h" - -#define COMMAND_NAME "init" - -static char *branch, *git_dir, *template_dir, *path; -static int quiet, bare; - -static const cli_opt_spec opts[] = { - CLI_COMMON_OPT, - - { CLI_OPT_TYPE_SWITCH, "quiet", 'q', &quiet, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "quiet mode; don't display informational messages" }, - { CLI_OPT_TYPE_SWITCH, "bare", 0, &bare, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "don't create a working directory" }, - { CLI_OPT_TYPE_VALUE, "initial-branch", 'b', &branch, 0, - CLI_OPT_USAGE_DEFAULT, "name", "initial branch name" }, - { CLI_OPT_TYPE_VALUE, "separate-git-dir", 0, &git_dir, 0, - CLI_OPT_USAGE_DEFAULT, "git-dir", "path to separate git directory" }, - { CLI_OPT_TYPE_VALUE, "template", 0, &template_dir, 0, - CLI_OPT_USAGE_DEFAULT, "template-dir", "path to git directory templates" }, - { CLI_OPT_TYPE_LITERAL }, - { CLI_OPT_TYPE_ARG, "directory", 0, &path, 0, - CLI_OPT_USAGE_DEFAULT, "directory", "directory to create repository in" }, - { 0 } -}; - -static void print_help(void) -{ - cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0); - printf("\n"); - - printf("Create a new git repository.\n"); - printf("\n"); - - printf("Options:\n"); - - cli_opt_help_fprint(stdout, opts); -} - -int cmd_init(int argc, char **argv) -{ - git_repository *repo = NULL; - git_repository_init_options init_opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; - cli_opt invalid_opt; - const char *repo_path; - int ret = 0; - - if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) - return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); - - if (cli_opt__show_help) { - print_help(); - return 0; - } - - init_opts.flags |= GIT_REPOSITORY_INIT_MKPATH | - GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; - - if (bare && git_dir) - return cli_error_usage("the '--bare' and '--separate-git-dir' options cannot be used together"); - - if (bare) - init_opts.flags |= GIT_REPOSITORY_INIT_BARE; - - init_opts.template_path = template_dir; - init_opts.initial_head = branch; - - if (git_dir) { - init_opts.flags |= GIT_REPOSITORY_INIT_NO_DOTGIT_DIR; - init_opts.workdir_path = path; - - repo_path = git_dir; - } else { - repo_path = path; - } - - if (git_repository_init_ext(&repo, repo_path, &init_opts) < 0) { - ret = cli_error_git(); - } else if (!quiet) { - printf("Initialized empty Git repository in %s\n", - git_repository_path(repo)); - } - - git_repository_free(repo); - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/common.c b/vendor/libgit2-sys/libgit2/src/cli/common.c deleted file mode 100644 index dbeefea..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/common.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include - -#include "git2_util.h" -#include "vector.h" -#include "fs_path.h" - -#include "common.h" -#include "error.h" - -static int parse_option(cli_opt *opt, void *data) -{ - git_str kv = GIT_STR_INIT, env = GIT_STR_INIT; - git_vector *cmdline_config = data; - int error = 0; - - if (opt->spec && opt->spec->alias == 'c') { - if (git_str_puts(&kv, opt->value) < 0) { - error = cli_error_git(); - goto done; - } - } - - else if (opt->spec && !strcmp(opt->spec->name, "config-env")) { - char *val = strchr(opt->value, '='); - - if (val == NULL || *(val + 1) == '\0') { - error = cli_error("invalid config format: '%s'", opt->value); - goto done; - } - - if (git_str_put(&kv, opt->value, (val - opt->value)) < 0) { - error = cli_error_git(); - goto done; - } - - val++; - - if ((error = git__getenv(&env, val)) == GIT_ENOTFOUND) { - error = cli_error("missing environment variable '%s' for configuration '%s'", val, kv.ptr); - goto done; - } else if (error) { - error = cli_error_git(); - goto done; - } - - if (git_str_putc(&kv, '=') < 0 || - git_str_puts(&kv, env.ptr) < 0) { - error = cli_error_git(); - goto done; - } - } - - if (kv.size > 0 && - git_vector_insert(cmdline_config, git_str_detach(&kv)) < 0) - error = cli_error_git(); - -done: - git_str_dispose(&env); - git_str_dispose(&kv); - return error; -} - -static int parse_common_options( - git_repository *repo, - cli_repository_open_options *opts) -{ - cli_opt_spec common_opts[] = { - { CLI_COMMON_OPT_CONFIG }, - { CLI_COMMON_OPT_CONFIG_ENV }, - { 0 } - }; - git_config_backend_memory_options config_opts = - GIT_CONFIG_BACKEND_MEMORY_OPTIONS_INIT; - git_vector cmdline = GIT_VECTOR_INIT; - git_config *config = NULL; - git_config_backend *backend = NULL; - int error = 0; - - config_opts.backend_type = "command line"; - - if ((error = cli_opt_foreach(common_opts, opts->args, - opts->args_len, CLI_OPT_PARSE_GNU, parse_option, - &cmdline)) < 0) - goto done; - - if (git_vector_length(&cmdline) == 0) - goto done; - - if (git_repository_config(&config, repo) < 0 || - git_config_backend_from_values(&backend, - (const char **)cmdline.contents, cmdline.length, - &config_opts) < 0 || - git_config_add_backend(config, backend, GIT_CONFIG_LEVEL_APP, - repo, 0) < 0) - error = cli_error_git(); - -done: - if (error && backend) - backend->free(backend); - git_config_free(config); - git_vector_dispose_deep(&cmdline); - return error; -} - -int cli_repository_open( - git_repository **out, - cli_repository_open_options *opts) -{ - git_repository *repo; - - if (git_repository_open_ext(&repo, ".", GIT_REPOSITORY_OPEN_FROM_ENV, NULL) < 0) - return -1; - - if (opts && parse_common_options(repo, opts) < 0) - return -1; - - *out = repo; - return 0; -} - -/* - * This resolves paths - not _pathspecs_ like git - it accepts an absolute - * path (to a path within the repository working directory) or a path - * relative to the current directory. - */ -int cli_resolve_path(git_str *out, git_repository *repo, const char *given_path) -{ - git_str path = GIT_STR_INIT; - int error = 0; - - if (!git_fs_path_is_absolute(given_path)) { - char cwd[GIT_PATH_MAX]; - - if (p_getcwd(cwd, GIT_PATH_MAX) < 0) - error = cli_error_os(); - else if (git_str_puts(&path, cwd) < 0 || - git_fs_path_apply_relative(&path, given_path) < 0) - error = cli_error_git(); - - if (error) - goto done; - } else if (git_str_puts(&path, given_path) < 0) { - error = cli_error_git(); - goto done; - } - - error = git_fs_path_make_relative(&path, git_repository_workdir(repo)); - - if (error == GIT_ENOTFOUND) - error = cli_error("path '%s' is not inside the git repository '%s'", - given_path, git_repository_workdir(repo)); - else if (error < 0) - error = cli_error_git(); - else - git_str_swap(out, &path); - -done: - git_str_dispose(&path); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/common.h b/vendor/libgit2-sys/libgit2/src/cli/common.h deleted file mode 100644 index 330f776..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/common.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef CLI_common_h__ -#define CLI_common_h__ - -#define PROGRAM_NAME "git2" - -#include "git2_util.h" - -#include "error.h" -#include "opt.h" -#include "opt_usage.h" - -/* - * Common command arguments. - */ - -extern int cli_opt__show_help; -extern int cli_opt__use_pager; - -#define CLI_COMMON_OPT_HELP \ - CLI_OPT_TYPE_SWITCH, "help", 0, &cli_opt__show_help, 1, \ - CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, \ - NULL, "display help information" -#define CLI_COMMON_OPT_CONFIG \ - CLI_OPT_TYPE_VALUE, NULL, 'c', NULL, 0, \ - CLI_OPT_USAGE_HIDDEN, \ - "key=value", "add configuration value" -#define CLI_COMMON_OPT_CONFIG_ENV \ - CLI_OPT_TYPE_VALUE, "config-env", 0, NULL, 0, \ - CLI_OPT_USAGE_HIDDEN, \ - "key=value", "set configuration value to environment variable" -#define CLI_COMMON_OPT_NO_PAGER \ - CLI_OPT_TYPE_SWITCH, "no-pager", 0, &cli_opt__use_pager, 0, \ - CLI_OPT_USAGE_HIDDEN, \ - NULL, "don't paginate multi-page output" - -#define CLI_COMMON_OPT \ - { CLI_COMMON_OPT_HELP }, \ - { CLI_COMMON_OPT_CONFIG }, \ - { CLI_COMMON_OPT_CONFIG_ENV }, \ - { CLI_COMMON_OPT_NO_PAGER } - -typedef struct { - char **args; - int args_len; -} cli_repository_open_options; - -extern int cli_repository_open( - git_repository **out, - cli_repository_open_options *opts); - -extern int cli_resolve_path( - git_str *out, - git_repository *repo, - const char *given_path); - -#endif /* CLI_common_h__ */ diff --git a/vendor/libgit2-sys/libgit2/src/cli/error.h b/vendor/libgit2-sys/libgit2/src/cli/error.h deleted file mode 100644 index abf8a51..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/error.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef CLI_error_h__ -#define CLI_error_h__ - -#include "common.h" -#include - -#define CLI_EXIT_OK 0 -#define CLI_EXIT_ERROR 1 -#define CLI_EXIT_OS 128 -#define CLI_EXIT_GIT 128 -#define CLI_EXIT_USAGE 129 - -#define cli_error__print(fmt) do { \ - va_list ap; \ - va_start(ap, fmt); \ - fprintf(stderr, "%s: ", PROGRAM_NAME); \ - vfprintf(stderr, fmt, ap); \ - fprintf(stderr, "\n"); \ - va_end(ap); \ - } while(0) - -GIT_INLINE(int) cli_error(const char *fmt, ...) -{ - cli_error__print(fmt); - return CLI_EXIT_ERROR; -} - -GIT_INLINE(int) cli_error_usage(const char *fmt, ...) -{ - cli_error__print(fmt); - return CLI_EXIT_USAGE; -} - -GIT_INLINE(int) cli_error_git(void) -{ - const git_error *err = git_error_last(); - fprintf(stderr, "%s: %s\n", PROGRAM_NAME, - err ? err->message : "unknown error"); - return CLI_EXIT_GIT; -} - -#define cli_error_os() (perror(PROGRAM_NAME), CLI_EXIT_OS) - -#endif /* CLI_error_h__ */ diff --git a/vendor/libgit2-sys/libgit2/src/cli/main.c b/vendor/libgit2-sys/libgit2/src/cli/main.c deleted file mode 100644 index be913ba..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/main.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include -#include "common.h" -#include "cmd.h" - -int cli_opt__show_help = 0; -int cli_opt__use_pager = 1; - -static int show_version = 0; -static char *command = NULL; -static char **args = NULL; - -const cli_opt_spec cli_common_opts[] = { - CLI_COMMON_OPT, - - { CLI_OPT_TYPE_SWITCH, "version", 0, &show_version, 1, - CLI_OPT_USAGE_DEFAULT, NULL, "display the version" }, - { CLI_OPT_TYPE_ARG, "command", 0, &command, 0, - CLI_OPT_USAGE_REQUIRED, "command", "the command to run" }, - { CLI_OPT_TYPE_ARGS, "args", 0, &args, 0, - CLI_OPT_USAGE_DEFAULT, "args", "arguments for the command" }, - { 0 } -}; - -const cli_cmd_spec cli_cmds[] = { - { "blame", cmd_blame, "Show the origin of each line of a file" }, - { "cat-file", cmd_cat_file, "Display an object in the repository" }, - { "clone", cmd_clone, "Clone a repository into a new directory" }, - { "config", cmd_config, "View or set configuration values " }, - { "hash-object", cmd_hash_object, "Hash a raw object and product its object ID" }, - { "help", cmd_help, "Display help information" }, - { "index-pack", cmd_index_pack, "Create an index for a packfile" }, - { "init", cmd_init, "Create a new git repository" }, - { NULL } -}; - -/* - * Reorder the argv as it was given, since git has the notion of global - * options (like `--help` or `-c key=val`) that we want to pass to the - * subcommand, and that can appear early in the arguments, before the - * command name. Put the command-name in argv[1] to allow easier parsing. - */ -static void reorder_args(char **argv, size_t first) -{ - char *tmp; - size_t i; - - if (first == 1) - return; - - tmp = argv[first]; - - for (i = first; i > 1; i--) - argv[i] = argv[i - 1]; - - argv[1] = tmp; -} - -/* - * When invoked without a command, or just with `--help`, we invoke - * the help command; but we want to preserve only arguments that would - * be useful for that. - */ -static void help_args(int *argc, char **argv) -{ - cli_opt__show_help = 0; - - argv[0] = "help"; - *argc = 1; -} - -int main(int argc, char **argv) -{ - const cli_cmd_spec *cmd; - cli_opt_parser optparser; - cli_opt opt; - int ret = 0; - - if (git_libgit2_init() < 0) { - cli_error("failed to initialize libgit2"); - exit(CLI_EXIT_GIT); - } - - cli_opt_parser_init(&optparser, cli_common_opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU); - - /* Parse the top-level (common) options and command information */ - while (cli_opt_parser_next(&opt, &optparser)) { - if (!opt.spec) { - cli_opt_status_fprint(stderr, PROGRAM_NAME, &opt); - cli_opt_usage_fprint(stderr, PROGRAM_NAME, NULL, cli_common_opts, CLI_OPT_USAGE_SHOW_HIDDEN); - ret = CLI_EXIT_USAGE; - goto done; - } - - /* - * When we see a command, stop parsing and capture the - * remaining arguments as args for the command itself. - */ - if (command) { - reorder_args(argv, optparser.idx); - break; - } - } - - if (show_version) { - printf("%s version %s\n", PROGRAM_NAME, LIBGIT2_VERSION); - goto done; - } - - if (!command) { - help_args(&argc, argv); - ret = cmd_help(argc, argv); - goto done; - } - - if ((cmd = cli_cmd_spec_byname(command)) == NULL) { - ret = cli_error("'%s' is not a %s command. See '%s help'.", - command, PROGRAM_NAME, PROGRAM_NAME); - goto done; - } - - ret = cmd->fn(argc - 1, &argv[1]); - -done: - git_libgit2_shutdown(); - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/opt.c b/vendor/libgit2-sys/libgit2/src/cli/opt.c deleted file mode 100644 index c5def19..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/opt.c +++ /dev/null @@ -1,695 +0,0 @@ -/* - * Copyright (c), Edward Thomson - * All rights reserved. - * - * This file is part of adopt, distributed under the MIT license. - * For full terms and conditions, see the included LICENSE file. - * - * THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT. - * - * This file was produced by using the `rename.pl` script included with - * adopt. The command-line specified was: - * - * ./rename.pl cli_opt --filename=opt --include=common.h --inline=GIT_INLINE --header-guard=CLI_opt_h__ --lowercase-status --without-usage - */ - -#include -#include -#include -#include -#include - -#if defined(__sun) || defined(__illumos__) || defined(__CYGWIN__) -# include -#endif - -#include "common.h" -#include "opt.h" - -#ifdef _WIN32 -# include -#else -# include -# include -#endif - -#ifdef _MSC_VER -# define alloca _alloca -#endif - -#define spec_is_option_type(x) \ - ((x)->type == CLI_OPT_TYPE_BOOL || \ - (x)->type == CLI_OPT_TYPE_SWITCH || \ - (x)->type == CLI_OPT_TYPE_VALUE) - -GIT_INLINE(const cli_opt_spec *) spec_for_long( - int *is_negated, - int *has_value, - const char **value, - const cli_opt_parser *parser, - const char *arg) -{ - const cli_opt_spec *spec; - const char *eql; - size_t eql_pos; - - eql = strchr(arg, '='); - eql_pos = (eql = strchr(arg, '=')) ? (size_t)(eql - arg) : strlen(arg); - - for (spec = parser->specs; spec->type; ++spec) { - /* Handle -- (everything after this is literal) */ - if (spec->type == CLI_OPT_TYPE_LITERAL && arg[0] == '\0') - return spec; - - /* Handle --no-option arguments for bool types */ - if (spec->type == CLI_OPT_TYPE_BOOL && - strncmp(arg, "no-", 3) == 0 && - strcmp(arg + 3, spec->name) == 0) { - *is_negated = 1; - return spec; - } - - /* Handle the typical --option arguments */ - if (spec_is_option_type(spec) && - spec->name && - strcmp(arg, spec->name) == 0) - return spec; - - /* Handle --option=value arguments */ - if (spec->type == CLI_OPT_TYPE_VALUE && - spec->name && eql && - strncmp(arg, spec->name, eql_pos) == 0 && - spec->name[eql_pos] == '\0') { - *has_value = 1; - *value = arg[eql_pos + 1] ? &arg[eql_pos + 1] : NULL; - return spec; - } - } - - return NULL; -} - -GIT_INLINE(const cli_opt_spec *) spec_for_short( - const char **value, - const cli_opt_parser *parser, - const char *arg) -{ - const cli_opt_spec *spec; - - for (spec = parser->specs; spec->type; ++spec) { - /* Handle -svalue short options with a value */ - if (spec->type == CLI_OPT_TYPE_VALUE && - arg[0] == spec->alias && - arg[1] != '\0') { - *value = &arg[1]; - return spec; - } - - /* Handle typical -s short options */ - if (arg[0] == spec->alias) { - *value = NULL; - return spec; - } - } - - return NULL; -} - -GIT_INLINE(const cli_opt_spec *) spec_for_arg(cli_opt_parser *parser) -{ - const cli_opt_spec *spec; - size_t args = 0; - - for (spec = parser->specs; spec->type; ++spec) { - if (spec->type == CLI_OPT_TYPE_ARG) { - if (args == parser->arg_idx) { - parser->arg_idx++; - return spec; - } - - args++; - } - - if (spec->type == CLI_OPT_TYPE_ARGS && args == parser->arg_idx) - return spec; - } - - return NULL; -} - -GIT_INLINE(int) spec_is_choice(const cli_opt_spec *spec) -{ - return ((spec + 1)->type && - ((spec + 1)->usage & CLI_OPT_USAGE_CHOICE)); -} - -/* - * If we have a choice with switches and bare arguments, and we see - * the switch, then we no longer expect the bare argument. - */ -GIT_INLINE(void) consume_choices(const cli_opt_spec *spec, cli_opt_parser *parser) -{ - /* back up to the beginning of the choices */ - while (spec->type && (spec->usage & CLI_OPT_USAGE_CHOICE)) - --spec; - - if (!spec_is_choice(spec)) - return; - - do { - if (spec->type == CLI_OPT_TYPE_ARG) - parser->arg_idx++; - ++spec; - } while(spec->type && (spec->usage & CLI_OPT_USAGE_CHOICE)); -} - -static cli_opt_status_t parse_long(cli_opt *opt, cli_opt_parser *parser) -{ - const cli_opt_spec *spec; - char *arg = parser->args[parser->idx++]; - const char *value = NULL; - int is_negated = 0, has_value = 0; - - opt->arg = arg; - - if ((spec = spec_for_long(&is_negated, &has_value, &value, parser, &arg[2])) == NULL) { - opt->spec = NULL; - opt->status = CLI_OPT_STATUS_UNKNOWN_OPTION; - goto done; - } - - opt->spec = spec; - - /* Future options parsed as literal */ - if (spec->type == CLI_OPT_TYPE_LITERAL) - parser->in_literal = 1; - - /* --bool or --no-bool */ - else if (spec->type == CLI_OPT_TYPE_BOOL && spec->value) - *((int *)spec->value) = !is_negated; - - /* --accumulate */ - else if (spec->type == CLI_OPT_TYPE_ACCUMULATOR && spec->value) - *((int *)spec->value) += spec->switch_value ? spec->switch_value : 1; - - /* --switch */ - else if (spec->type == CLI_OPT_TYPE_SWITCH && spec->value) - *((int *)spec->value) = spec->switch_value; - - /* Parse values as "--foo=bar" or "--foo bar" */ - else if (spec->type == CLI_OPT_TYPE_VALUE) { - if (has_value) - opt->value = (char *)value; - else if ((parser->idx + 1) <= parser->args_len) - opt->value = parser->args[parser->idx++]; - - if (spec->value) - *((char **)spec->value) = opt->value; - } - - /* Required argument was not provided */ - if (spec->type == CLI_OPT_TYPE_VALUE && - !opt->value && - !(spec->usage & CLI_OPT_USAGE_VALUE_OPTIONAL)) - opt->status = CLI_OPT_STATUS_MISSING_VALUE; - else - opt->status = CLI_OPT_STATUS_OK; - - consume_choices(opt->spec, parser); - -done: - return opt->status; -} - -static cli_opt_status_t parse_short(cli_opt *opt, cli_opt_parser *parser) -{ - const cli_opt_spec *spec; - char *arg = parser->args[parser->idx++]; - const char *value; - - opt->arg = arg; - - if ((spec = spec_for_short(&value, parser, &arg[1 + parser->in_short])) == NULL) { - opt->spec = NULL; - opt->status = CLI_OPT_STATUS_UNKNOWN_OPTION; - goto done; - } - - opt->spec = spec; - - if (spec->type == CLI_OPT_TYPE_BOOL && spec->value) - *((int *)spec->value) = 1; - - else if (spec->type == CLI_OPT_TYPE_ACCUMULATOR && spec->value) - *((int *)spec->value) += spec->switch_value ? spec->switch_value : 1; - - else if (spec->type == CLI_OPT_TYPE_SWITCH && spec->value) - *((int *)spec->value) = spec->switch_value; - - /* Parse values as "-ifoo" or "-i foo" */ - else if (spec->type == CLI_OPT_TYPE_VALUE) { - if (value) - opt->value = (char *)value; - else if ((parser->idx + 1) <= parser->args_len) - opt->value = parser->args[parser->idx++]; - - if (spec->value) - *((char **)spec->value) = opt->value; - } - - /* - * Handle compressed short arguments, like "-fbcd"; see if there's - * another character after the one we processed. If not, advance - * the parser index. - */ - if (spec->type != CLI_OPT_TYPE_VALUE && arg[2 + parser->in_short] != '\0') { - parser->in_short++; - parser->idx--; - } else { - parser->in_short = 0; - } - - /* Required argument was not provided */ - if (spec->type == CLI_OPT_TYPE_VALUE && !opt->value) - opt->status = CLI_OPT_STATUS_MISSING_VALUE; - else - opt->status = CLI_OPT_STATUS_OK; - - consume_choices(opt->spec, parser); - -done: - return opt->status; -} - -static cli_opt_status_t parse_arg(cli_opt *opt, cli_opt_parser *parser) -{ - const cli_opt_spec *spec = spec_for_arg(parser); - - opt->spec = spec; - opt->arg = parser->args[parser->idx]; - - if (!spec) { - parser->idx++; - opt->status = CLI_OPT_STATUS_UNKNOWN_OPTION; - } else if (spec->type == CLI_OPT_TYPE_ARGS) { - if (spec->value) - *((char ***)spec->value) = &parser->args[parser->idx]; - - /* - * We have started a list of arguments; the remainder of - * given arguments need not be examined. - */ - parser->in_args = (parser->args_len - parser->idx); - parser->idx = parser->args_len; - opt->args_len = parser->in_args; - opt->status = CLI_OPT_STATUS_OK; - } else { - if (spec->value) - *((char **)spec->value) = parser->args[parser->idx]; - - parser->idx++; - opt->status = CLI_OPT_STATUS_OK; - } - - return opt->status; -} - -static int support_gnu_style(unsigned int flags) -{ - if ((flags & CLI_OPT_PARSE_FORCE_GNU) != 0) - return 1; - - if ((flags & CLI_OPT_PARSE_GNU) == 0) - return 0; - - /* TODO: Windows */ -#if defined(_WIN32) && defined(UNICODE) - if (_wgetenv(L"POSIXLY_CORRECT") != NULL) - return 0; -#else - if (getenv("POSIXLY_CORRECT") != NULL) - return 0; -#endif - - return 1; -} - -void cli_opt_parser_init( - cli_opt_parser *parser, - const cli_opt_spec specs[], - char **args, - size_t args_len, - unsigned int flags) -{ - assert(parser); - - memset(parser, 0x0, sizeof(cli_opt_parser)); - - parser->specs = specs; - parser->args = args; - parser->args_len = args_len; - parser->flags = flags; - - parser->needs_sort = support_gnu_style(flags); -} - -GIT_INLINE(const cli_opt_spec *) spec_for_sort( - int *needs_value, - const cli_opt_parser *parser, - const char *arg) -{ - int is_negated, has_value = 0; - const char *value = NULL; - const cli_opt_spec *spec = NULL; - size_t idx = 0; - - *needs_value = 0; - - if (strncmp(arg, "--", 2) == 0) { - spec = spec_for_long(&is_negated, &has_value, &value, parser, &arg[2]); - *needs_value = !has_value; - } - - else if (strncmp(arg, "-", 1) == 0) { - spec = spec_for_short(&value, parser, &arg[1]); - - /* - * Advance through compressed short arguments to see if - * the last one has a value, eg "-xvffilename". - */ - while (spec && !value && arg[1 + ++idx] != '\0') - spec = spec_for_short(&value, parser, &arg[1 + idx]); - - *needs_value = (value == NULL); - } - - return spec; -} - -/* - * Some parsers allow for handling arguments like "file1 --help file2"; - * this is done by re-sorting the arguments in-place; emulate that. - */ -static int sort_gnu_style(cli_opt_parser *parser) -{ - size_t i, j, insert_idx = parser->idx, offset; - const cli_opt_spec *spec; - char *option, *value; - int needs_value, changed = 0; - - parser->needs_sort = 0; - - for (i = parser->idx; i < parser->args_len; i++) { - spec = spec_for_sort(&needs_value, parser, parser->args[i]); - - /* Not a "-" or "--" prefixed option. No change. */ - if (!spec) - continue; - - /* A "--" alone means remaining args are literal. */ - if (spec->type == CLI_OPT_TYPE_LITERAL) - break; - - option = parser->args[i]; - - /* - * If the argument is a value type and doesn't already - * have a value (eg "--foo=bar" or "-fbar") then we need - * to copy the next argument as its value. - */ - if (spec->type == CLI_OPT_TYPE_VALUE && needs_value) { - /* - * A required value is not provided; set parser - * index to this value so that we fail on it. - */ - if (i + 1 >= parser->args_len) { - parser->idx = i; - return 1; - } - - value = parser->args[i + 1]; - offset = 1; - } else { - value = NULL; - offset = 0; - } - - /* Caller error if args[0] is an option. */ - if (i == 0) - return 0; - - /* Shift args up one (or two) and insert the option */ - for (j = i; j > insert_idx; j--) - parser->args[j + offset] = parser->args[j - 1]; - - parser->args[insert_idx] = option; - - if (value) - parser->args[insert_idx + 1] = value; - - insert_idx += (1 + offset); - i += offset; - - changed = 1; - } - - return changed; -} - -cli_opt_status_t cli_opt_parser_next(cli_opt *opt, cli_opt_parser *parser) -{ - assert(opt && parser); - - memset(opt, 0x0, sizeof(cli_opt)); - - if (parser->idx >= parser->args_len) { - opt->args_len = parser->in_args; - return CLI_OPT_STATUS_DONE; - } - - /* Handle options in long form, those beginning with "--" */ - if (strncmp(parser->args[parser->idx], "--", 2) == 0 && - !parser->in_short && - !parser->in_literal) - return parse_long(opt, parser); - - /* Handle options in short form, those beginning with "-" */ - else if (parser->in_short || - (strncmp(parser->args[parser->idx], "-", 1) == 0 && - !parser->in_literal)) - return parse_short(opt, parser); - - /* - * We've reached the first "bare" argument. In POSIX mode, all - * remaining items on the command line are arguments. In GNU - * mode, there may be long or short options after this. Sort any - * options up to this position then re-parse the current position. - */ - if (parser->needs_sort && sort_gnu_style(parser)) - return cli_opt_parser_next(opt, parser); - - return parse_arg(opt, parser); -} - -GIT_INLINE(int) spec_included(const cli_opt_spec **specs, const cli_opt_spec *spec) -{ - const cli_opt_spec **i; - - for (i = specs; *i; ++i) { - if (spec == *i) - return 1; - } - - return 0; -} - -static cli_opt_status_t validate_required( - cli_opt *opt, - const cli_opt_spec specs[], - const cli_opt_spec **given_specs) -{ - const cli_opt_spec *spec, *required; - int given; - - /* - * Iterate over the possible specs to identify requirements and - * ensure that those have been given on the command-line. - * Note that we can have required *choices*, where one in a - * list of choices must be specified. - */ - for (spec = specs, required = NULL, given = 0; spec->type; ++spec) { - if (!required && (spec->usage & CLI_OPT_USAGE_REQUIRED)) { - required = spec; - given = 0; - } else if (!required) { - continue; - } - - if (!given) - given = spec_included(given_specs, spec); - - /* - * Validate the requirement unless we're in a required - * choice. In that case, keep the required state and - * validate at the end of the choice list. - */ - if (!spec_is_choice(spec)) { - if (!given) { - opt->spec = required; - opt->status = CLI_OPT_STATUS_MISSING_ARGUMENT; - break; - } - - required = NULL; - given = 0; - } - } - - return opt->status; -} - -cli_opt_status_t cli_opt_parse( - cli_opt *opt, - const cli_opt_spec specs[], - char **args, - size_t args_len, - unsigned int flags) -{ - cli_opt_parser parser; - const cli_opt_spec **given_specs; - size_t given_idx = 0; - - cli_opt_parser_init(&parser, specs, args, args_len, flags); - - given_specs = alloca(sizeof(const cli_opt_spec *) * (args_len + 1)); - - while (cli_opt_parser_next(opt, &parser)) { - if (opt->status != CLI_OPT_STATUS_OK && - opt->status != CLI_OPT_STATUS_DONE) - return opt->status; - - if ((opt->spec->usage & CLI_OPT_USAGE_STOP_PARSING)) - return (opt->status = CLI_OPT_STATUS_DONE); - - given_specs[given_idx++] = opt->spec; - } - - given_specs[given_idx] = NULL; - - return validate_required(opt, specs, given_specs); -} - -int cli_opt_foreach( - const cli_opt_spec specs[], - char **args, - size_t args_len, - unsigned int flags, - int (*callback)(cli_opt *, void *), - void *callback_data) -{ - cli_opt_parser parser; - cli_opt opt; - int ret; - - cli_opt_parser_init(&parser, specs, args, args_len, flags); - - while (cli_opt_parser_next(&opt, &parser)) { - if ((ret = callback(&opt, callback_data)) != 0) - return ret; - } - - return 0; -} - -static int spec_name_fprint(FILE *file, const cli_opt_spec *spec) -{ - int error; - - if (spec->type == CLI_OPT_TYPE_ARG) - error = fprintf(file, "%s", spec->value_name); - else if (spec->type == CLI_OPT_TYPE_ARGS) - error = fprintf(file, "%s", spec->value_name); - else if (spec->alias && !(spec->usage & CLI_OPT_USAGE_SHOW_LONG)) - error = fprintf(file, "-%c", spec->alias); - else - error = fprintf(file, "--%s", spec->name); - - return error; -} - -int cli_opt_status_fprint( - FILE *file, - const char *command, - const cli_opt *opt) -{ - const cli_opt_spec *choice; - int error; - - if (command && (error = fprintf(file, "%s: ", command)) < 0) - return error; - - switch (opt->status) { - case CLI_OPT_STATUS_DONE: - error = fprintf(file, "finished processing arguments (no error)\n"); - break; - case CLI_OPT_STATUS_OK: - error = fprintf(file, "no error\n"); - break; - case CLI_OPT_STATUS_UNKNOWN_OPTION: - error = fprintf(file, "unknown option: %s\n", opt->arg); - break; - case CLI_OPT_STATUS_MISSING_VALUE: - if ((error = fprintf(file, "argument '")) < 0 || - (error = spec_name_fprint(file, opt->spec)) < 0 || - (error = fprintf(file, "' requires a value.\n")) < 0) - break; - break; - case CLI_OPT_STATUS_MISSING_ARGUMENT: - if (spec_is_choice(opt->spec)) { - int is_choice = 1; - - if (spec_is_choice((opt->spec)+1)) - error = fprintf(file, "one of"); - else - error = fprintf(file, "either"); - - if (error < 0) - break; - - for (choice = opt->spec; is_choice; ++choice) { - is_choice = spec_is_choice(choice); - - if (!is_choice) - error = fprintf(file, " or"); - else if (choice != opt->spec) - error = fprintf(file, ","); - - if ((error < 0) || - (error = fprintf(file, " '")) < 0 || - (error = spec_name_fprint(file, choice)) < 0 || - (error = fprintf(file, "'")) < 0) - break; - - if (!spec_is_choice(choice)) - break; - } - - if ((error < 0) || - (error = fprintf(file, " is required.\n")) < 0) - break; - } else { - if ((error = fprintf(file, "argument '")) < 0 || - (error = spec_name_fprint(file, opt->spec)) < 0 || - (error = fprintf(file, "' is required.\n")) < 0) - break; - } - - break; - default: - error = fprintf(file, "unknown status: %d\n", opt->status); - break; - } - - return error; -} - diff --git a/vendor/libgit2-sys/libgit2/src/cli/opt.h b/vendor/libgit2-sys/libgit2/src/cli/opt.h deleted file mode 100644 index 226f74d..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/opt.h +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Copyright (c), Edward Thomson - * All rights reserved. - * - * This file is part of adopt, distributed under the MIT license. - * For full terms and conditions, see the included LICENSE file. - * - * THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT. - * - * This file was produced by using the `rename.pl` script included with - * adopt. The command-line specified was: - * - * ./rename.pl cli_opt --filename=opt --include=common.h --inline=GIT_INLINE --header-guard=CLI_opt_h__ --lowercase-status --without-usage - */ - -#ifndef CLI_opt_h__ -#define CLI_opt_h__ - -#include -#include - -/** - * The type of argument to be parsed. - */ -typedef enum { - CLI_OPT_TYPE_NONE = 0, - - /** - * An option that, when specified, sets a given value to true. - * This is useful for options like "--debug". A negation - * option (beginning with "no-") is implicitly specified; for - * example "--no-debug". The `value` pointer in the returned - * option will be set to `1` when this is specified, and set to - * `0` when the negation "no-" option is specified. - */ - CLI_OPT_TYPE_BOOL, - - /** - * An option that, when specified, sets the given `value` pointer - * to the specified `switch_value`. This is useful for booleans - * where you do not want the implicit negation that comes with an - * `CLI_OPT_TYPE_BOOL`, or for switches that multiplex a value, like - * setting a mode. For example, `--read` may set the `value` to - * `MODE_READ` and `--write` may set the `value` to `MODE_WRITE`. - */ - CLI_OPT_TYPE_SWITCH, - - /** - * An option that, when specified, increments the given - * `value` by the given `switch_value`. This can be specified - * multiple times to continue to increment the `value`. - * (For example, "-vvv" to set verbosity to 3.) - */ - CLI_OPT_TYPE_ACCUMULATOR, - - /** - * An option that takes a value, for example `-n value`, - * `-nvalue`, `--name value` or `--name=value`. - */ - CLI_OPT_TYPE_VALUE, - - /** - * A bare "--" that indicates that arguments following this are - * literal. This allows callers to specify things that might - * otherwise look like options, for example to operate on a file - * named "-rf" then you can invoke "program -- -rf" to treat - * "-rf" as an argument not an option. - */ - CLI_OPT_TYPE_LITERAL, - - /** - * A single argument, not an option. When options are exhausted, - * arguments will be matches in the order that they're specified - * in the spec list. For example, if two `CLI_OPT_TYPE_ARGS` are - * specified, `input_file` and `output_file`, then the first bare - * argument on the command line will be `input_file` and the - * second will be `output_file`. - */ - CLI_OPT_TYPE_ARG, - - /** - * A collection of arguments. This is useful when you want to take - * a list of arguments, for example, multiple paths. When specified, - * the value will be set to the first argument in the list. - */ - CLI_OPT_TYPE_ARGS, -} cli_opt_type_t; - -/** - * Additional information about an option, including parsing - * restrictions and usage information to be displayed to the end-user. - */ -typedef enum { - /** Defaults for the argument. */ - CLI_OPT_USAGE_DEFAULT = 0, - - /** This argument is required. */ - CLI_OPT_USAGE_REQUIRED = (1u << 0), - - /** - * This is a multiple choice argument, combined with the previous - * argument. For example, when the previous argument is `-f` and - * this optional is applied to an argument of type `-b` then one - * of `-f` or `-b` may be specified. - */ - CLI_OPT_USAGE_CHOICE = (1u << 1), - - /** - * This argument short-circuits the remainder of parsing. - * Useful for arguments like `--help`. - */ - CLI_OPT_USAGE_STOP_PARSING = (1u << 2), - - /** The argument's value is optional ("-n" or "-n foo") */ - CLI_OPT_USAGE_VALUE_OPTIONAL = (1u << 3), - - /** This argument should not be displayed in usage. */ - CLI_OPT_USAGE_HIDDEN = (1u << 4), - - /** In usage, show the long format instead of the abbreviated format. */ - CLI_OPT_USAGE_SHOW_LONG = (1u << 5), -} cli_opt_usage_t; - -typedef enum { - /** Default parsing behavior. */ - CLI_OPT_PARSE_DEFAULT = 0, - - /** - * Parse with GNU `getopt_long` style behavior, where options can - * be intermixed with arguments at any position (for example, - * "file1 --help file2".) Like `getopt_long`, this can mutate the - * arguments given. - */ - CLI_OPT_PARSE_GNU = (1u << 0), - - /** - * Force GNU `getopt_long` style behavior; the `POSIXLY_CORRECT` - * environment variable is ignored. - */ - CLI_OPT_PARSE_FORCE_GNU = (1u << 1), -} cli_opt_flag_t; - -/** Specification for an available option. */ -typedef struct cli_opt_spec { - /** Type of option expected. */ - cli_opt_type_t type; - - /** Name of the long option. */ - const char *name; - - /** The alias is the short (one-character) option alias. */ - const char alias; - - /** - * If this spec is of type `CLI_OPT_TYPE_BOOL`, this is a pointer - * to an `int` that will be set to `1` if the option is specified. - * - * If this spec is of type `CLI_OPT_TYPE_SWITCH`, this is a pointer - * to an `int` that will be set to the opt's `switch_value` (below) - * when this option is specified. - * - * If this spec is of type `CLI_OPT_TYPE_ACCUMULATOR`, this is a - * pointer to an `int` that will be incremented by the opt's - * `switch_value` (below). If no `switch_value` is provided then - * the value will be incremented by 1. - * - * If this spec is of type `CLI_OPT_TYPE_VALUE`, - * `CLI_OPT_TYPE_VALUE_OPTIONAL`, or `CLI_OPT_TYPE_ARG`, this is - * a pointer to a `char *` that will be set to the value - * specified on the command line. - * - * If this spec is of type `CLI_OPT_TYPE_ARGS`, this is a pointer - * to a `char **` that will be set to the remaining values - * specified on the command line. - */ - void *value; - - /** - * If this spec is of type `CLI_OPT_TYPE_SWITCH`, this is the value - * to set in the option's `value` pointer when it is specified. If - * this spec is of type `CLI_OPT_TYPE_ACCUMULATOR`, this is the value - * to increment in the option's `value` pointer when it is - * specified. This is ignored for other opt types. - */ - int switch_value; - - /** - * Optional usage flags that change parsing behavior and how - * usage information is shown to the end-user. - */ - uint32_t usage; - - /** - * The name of the value, provided when creating usage information. - * This is required only for the functions that display usage - * information and only when a spec is of type `CLI_OPT_TYPE_VALUE, - * `CLI_OPT_TYPE_ARG` or `CLI_OPT_TYPE_ARGS``. - */ - const char *value_name; - - /** - * Optional short description of the option to display to the - * end-user. This is only used when creating usage information. - */ - const char *help; -} cli_opt_spec; - -/** Return value for `cli_opt_parser_next`. */ -typedef enum { - /** Parsing is complete; there are no more arguments. */ - CLI_OPT_STATUS_DONE = 0, - - /** - * This argument was parsed correctly; the `opt` structure is - * populated and the value pointer has been set. - */ - CLI_OPT_STATUS_OK = 1, - - /** - * The argument could not be parsed correctly, it does not match - * any of the specifications provided. - */ - CLI_OPT_STATUS_UNKNOWN_OPTION = 2, - - /** - * The argument matched a spec of type `CLI_OPT_VALUE`, but no value - * was provided. - */ - CLI_OPT_STATUS_MISSING_VALUE = 3, - - /** A required argument was not provided. */ - CLI_OPT_STATUS_MISSING_ARGUMENT = 4, -} cli_opt_status_t; - -/** An option provided on the command-line. */ -typedef struct cli_opt { - /** The status of parsing the most recent argument. */ - cli_opt_status_t status; - - /** - * The specification that was provided on the command-line, or - * `NULL` if the argument did not match an `cli_opt_spec`. - */ - const cli_opt_spec *spec; - - /** - * The argument as it was specified on the command-line, including - * dashes, eg, `-f` or `--foo`. - */ - char *arg; - - /** - * If the spec is of type `CLI_OPT_VALUE` or `CLI_OPT_VALUE_OPTIONAL`, - * this is the value provided to the argument. - */ - char *value; - - /** - * If the argument is of type `CLI_OPT_ARGS`, this is the number of - * arguments remaining. This value is persisted even when parsing - * is complete and `status` == `CLI_OPT_STATUS_DONE`. - */ - size_t args_len; -} cli_opt; - -/* The internal parser state. Callers should not modify this structure. */ -typedef struct cli_opt_parser { - const cli_opt_spec *specs; - char **args; - size_t args_len; - unsigned int flags; - - /* Parser state */ - size_t idx; - size_t arg_idx; - size_t in_args; - size_t in_short; - unsigned int needs_sort : 1, - in_literal : 1; -} cli_opt_parser; - -/** - * Parses all the command-line arguments and updates all the options using - * the pointers provided. Parsing stops on any invalid argument and - * information about the failure will be provided in the opt argument. - * - * This is the simplest way to parse options; it handles the initialization - * (`parser_init`) and looping (`parser_next`). - * - * @param opt The The `cli_opt` information that failed parsing - * @param specs A NULL-terminated array of `cli_opt_spec`s that can be parsed - * @param args The arguments that will be parsed - * @param args_len The length of arguments to be parsed - * @param flags The `cli_opt_flag_t flags for parsing - */ -cli_opt_status_t cli_opt_parse( - cli_opt *opt, - const cli_opt_spec specs[], - char **args, - size_t args_len, - unsigned int flags); - -/** - * Quickly executes the given callback for each argument. - * - * @param specs A NULL-terminated array of `cli_opt_spec`s that can be parsed - * @param args The arguments that will be parsed - * @param args_len The length of arguments to be parsed - * @param flags The `cli_opt_flag_t flags for parsing - * @param callback The callback to invoke for each specified option - * @param callback_data Data to be provided to the callback - */ -int cli_opt_foreach( - const cli_opt_spec specs[], - char **args, - size_t args_len, - unsigned int flags, - int (*callback)(cli_opt *, void *), - void *callback_data); - -/** - * Initializes a parser that parses the given arguments according to the - * given specifications. - * - * @param parser The `cli_opt_parser` that will be initialized - * @param specs A NULL-terminated array of `cli_opt_spec`s that can be parsed - * @param args The arguments that will be parsed - * @param args_len The length of arguments to be parsed - * @param flags The `cli_opt_flag_t flags for parsing - */ -void cli_opt_parser_init( - cli_opt_parser *parser, - const cli_opt_spec specs[], - char **args, - size_t args_len, - unsigned int flags); - -/** - * Parses the next command-line argument and places the information about - * the argument into the given `opt` data. - * - * @param opt The `cli_opt` information parsed from the argument - * @param parser An `cli_opt_parser` that has been initialized with - * `cli_opt_parser_init` - * @return true if the caller should continue iterating, or 0 if there are - * no arguments left to process. - */ -cli_opt_status_t cli_opt_parser_next( - cli_opt *opt, - cli_opt_parser *parser); - -/** - * Prints the status after parsing the most recent argument. This is - * useful for printing an error message when an unknown argument was - * specified, or when an argument was specified without a value. - * - * @param file The file to print information to - * @param command The name of the command to use when printing (optional) - * @param opt The option that failed to parse - * @return 0 on success, -1 on failure - */ -int cli_opt_status_fprint( - FILE *file, - const char *command, - const cli_opt *opt); - -#endif /* CLI_opt_h__ */ diff --git a/vendor/libgit2-sys/libgit2/src/cli/opt_usage.c b/vendor/libgit2-sys/libgit2/src/cli/opt_usage.c deleted file mode 100644 index 5b6aee9..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/opt_usage.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" -#include "str.h" - -#define is_switch_or_value(spec) \ - ((spec)->type == CLI_OPT_TYPE_SWITCH || \ - (spec)->type == CLI_OPT_TYPE_VALUE) - -static int print_spec_args(git_str *out, const cli_opt_spec *spec) -{ - GIT_ASSERT(!is_switch_or_value(spec)); - - if (spec->type == CLI_OPT_TYPE_ARG) - return git_str_printf(out, "<%s>", spec->value_name); - if (spec->type == CLI_OPT_TYPE_ARGS) - return git_str_printf(out, "<%s>...", spec->value_name); - if (spec->type == CLI_OPT_TYPE_LITERAL) - return git_str_printf(out, "--"); - - GIT_ASSERT(!"unknown option spec type"); - return -1; -} - -GIT_INLINE(int) print_spec_alias(git_str *out, const cli_opt_spec *spec) -{ - GIT_ASSERT(is_switch_or_value(spec) && spec->alias); - - if (spec->type == CLI_OPT_TYPE_VALUE && - !(spec->usage & CLI_OPT_USAGE_VALUE_OPTIONAL)) - return git_str_printf(out, "-%c <%s>", spec->alias, spec->value_name); - else if (spec->type == CLI_OPT_TYPE_VALUE) - return git_str_printf(out, "-%c [<%s>]", spec->alias, spec->value_name); - else - return git_str_printf(out, "-%c", spec->alias); -} - -GIT_INLINE(int) print_spec_name(git_str *out, const cli_opt_spec *spec) -{ - GIT_ASSERT(is_switch_or_value(spec) && spec->name); - - if (spec->type == CLI_OPT_TYPE_VALUE && - !(spec->usage & CLI_OPT_USAGE_VALUE_OPTIONAL)) - return git_str_printf(out, "--%s=<%s>", spec->name, spec->value_name); - else if (spec->type == CLI_OPT_TYPE_VALUE) - return git_str_printf(out, "--%s[=<%s>]", spec->name, spec->value_name); - else - return git_str_printf(out, "--%s", spec->name); -} - -GIT_INLINE(int) print_spec_full(git_str *out, const cli_opt_spec *spec) -{ - int error = 0; - - if (is_switch_or_value(spec)) { - if (spec->alias) - error |= print_spec_alias(out, spec); - - if (spec->alias && spec->name) - error |= git_str_printf(out, ", "); - - if (spec->name) - error |= print_spec_name(out, spec); - } else { - error |= print_spec_args(out, spec); - } - - return error; -} - -GIT_INLINE(int) print_spec(git_str *out, const cli_opt_spec *spec) -{ - if (is_switch_or_value(spec)) { - if (spec->alias && !(spec->usage & CLI_OPT_USAGE_SHOW_LONG)) - return print_spec_alias(out, spec); - else - return print_spec_name(out, spec); - } - - return print_spec_args(out, spec); -} - -/* - * This is similar to adopt's function, but modified to understand - * that we have a command ("git") and a "subcommand" ("checkout"). - * It also understands a terminal's line length and wrap appropriately, - * using a `git_str` for storage. - */ -int cli_opt_usage_fprint( - FILE *file, - const char *command, - const char *subcommand, - const cli_opt_spec specs[], - unsigned int print_flags) -{ - git_str usage = GIT_BUF_INIT, opt = GIT_BUF_INIT; - const cli_opt_spec *spec; - size_t i, prefixlen, linelen; - bool choice = false, next_choice = false, optional = false; - int error; - - /* TODO: query actual console width. */ - int console_width = 78; - - if ((error = git_str_printf(&usage, "usage: %s", command)) < 0) - goto done; - - if (subcommand && - (error = git_str_printf(&usage, " %s", subcommand)) < 0) - goto done; - - linelen = git_str_len(&usage); - prefixlen = linelen + 1; - - for (spec = specs; spec->type; ++spec) { - if (!choice) - optional = !(spec->usage & CLI_OPT_USAGE_REQUIRED); - - next_choice = !!((spec + 1)->usage & CLI_OPT_USAGE_CHOICE); - - if ((spec->usage & CLI_OPT_USAGE_HIDDEN) && - !(print_flags & CLI_OPT_USAGE_SHOW_HIDDEN)) - continue; - - if (choice) - git_str_putc(&opt, '|'); - else - git_str_clear(&opt); - - if (optional && !choice) - git_str_putc(&opt, '['); - if (!optional && !choice && next_choice) - git_str_putc(&opt, '('); - - if ((error = print_spec(&opt, spec)) < 0) - goto done; - - if (!optional && choice && !next_choice) - git_str_putc(&opt, ')'); - else if (optional && !next_choice) - git_str_putc(&opt, ']'); - - if ((choice = next_choice)) - continue; - - if (git_str_oom(&opt)) { - error = -1; - goto done; - } - - if (linelen > prefixlen && - console_width > 0 && - linelen + git_str_len(&opt) + 1 > (size_t)console_width) { - git_str_putc(&usage, '\n'); - - for (i = 0; i < prefixlen; i++) - git_str_putc(&usage, ' '); - - linelen = prefixlen; - } - - git_str_putc(&usage, ' '); - linelen += git_str_len(&opt) + 1; - - git_str_puts(&usage, git_str_cstr(&opt)); - - if (git_str_oom(&usage)) { - error = -1; - goto done; - } - } - - error = fprintf(file, "%s\n", git_str_cstr(&usage)); - -done: - error = (error < 0) ? -1 : 0; - - git_str_dispose(&usage); - git_str_dispose(&opt); - return error; -} - -int cli_opt_usage_error( - const char *subcommand, - const cli_opt_spec specs[], - const cli_opt *invalid_opt) -{ - cli_opt_status_fprint(stderr, PROGRAM_NAME, invalid_opt); - cli_opt_usage_fprint(stderr, PROGRAM_NAME, subcommand, specs, 0); - return CLI_EXIT_USAGE; -} - -int cli_opt_help_fprint( - FILE *file, - const cli_opt_spec specs[]) -{ - git_str help = GIT_BUF_INIT; - const cli_opt_spec *spec; - bool required = true; - int error = 0; - - /* Display required arguments first */ - for (spec = specs; spec->type; ++spec) { - if ((spec->usage & CLI_OPT_USAGE_HIDDEN) || - (spec->type == CLI_OPT_TYPE_LITERAL)) - continue; - - required = ((spec->usage & CLI_OPT_USAGE_REQUIRED) || - ((spec->usage & CLI_OPT_USAGE_CHOICE) && required)); - - if (!required) - continue; - - git_str_printf(&help, " "); - - if ((error = print_spec_full(&help, spec)) < 0) - goto done; - - git_str_printf(&help, "\n"); - - if (spec->help) - git_str_printf(&help, " %s\n", spec->help); - } - - /* Display the remaining arguments */ - for (spec = specs; spec->type; ++spec) { - if ((spec->usage & CLI_OPT_USAGE_HIDDEN) || - (spec->type == CLI_OPT_TYPE_LITERAL)) - continue; - - required = ((spec->usage & CLI_OPT_USAGE_REQUIRED) || - ((spec->usage & CLI_OPT_USAGE_CHOICE) && required)); - - if (required) - continue; - - git_str_printf(&help, " "); - - if ((error = print_spec_full(&help, spec)) < 0) - goto done; - - git_str_printf(&help, "\n"); - - if (spec->help) - git_str_printf(&help, " %s\n", spec->help); - } - - if (git_str_oom(&help) || - p_write(fileno(file), help.ptr, help.size) < 0) - error = -1; - -done: - error = (error < 0) ? -1 : 0; - - git_str_dispose(&help); - return error; -} - diff --git a/vendor/libgit2-sys/libgit2/src/cli/opt_usage.h b/vendor/libgit2-sys/libgit2/src/cli/opt_usage.h deleted file mode 100644 index b9b75b8..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/opt_usage.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef CLI_opt_usage_h__ -#define CLI_opt_usage_h__ - -typedef enum { - CLI_OPT_USAGE_SHOW_HIDDEN = (1 << 0), -} cli_opt_usage_flags; - -/** - * Prints usage information to the given file handle. - * - * @param file The file to print information to - * @param command The name of the command to use when printing - * @param subcommand The name of the subcommand (eg "checkout") to use when printing, or NULL to skip - * @param specs The specifications allowed by the command - * @return 0 on success, -1 on failure - */ -int cli_opt_usage_fprint( - FILE *file, - const char *command, - const char *subcommand, - const cli_opt_spec specs[], - unsigned int print_flags); - -int cli_opt_usage_error( - const char *subcommand, - const cli_opt_spec specs[], - const cli_opt *invalid_opt); - -int cli_opt_help_fprint( - FILE *file, - const cli_opt_spec specs[]); - -#endif /* CLI_opt_usage_h__ */ diff --git a/vendor/libgit2-sys/libgit2/src/cli/progress.c b/vendor/libgit2-sys/libgit2/src/cli/progress.c deleted file mode 100644 index d975b09..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/progress.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include -#include - -#include "progress.h" -#include "error.h" - -/* - * Show updates to the percentage and number of objects received - * separately from the throughput to give an accurate progress while - * avoiding too much noise on the screen. (In milliseconds.) - */ -#define PROGRESS_UPDATE_TIME 60 -#define THROUGHPUT_UPDATE_TIME 500 - -#define is_nl(c) ((c) == '\r' || (c) == '\n') - -#define return_os_error(msg) do { \ - git_error_set(GIT_ERROR_OS, "%s", msg); return -1; } while(0) - -GIT_INLINE(size_t) no_nl_len(const char *str, size_t len) -{ - size_t i = 0; - - while (i < len && !is_nl(str[i])) - i++; - - return i; -} - -GIT_INLINE(size_t) nl_len(bool *has_nl, const char *str, size_t len) -{ - size_t i = no_nl_len(str, len); - - *has_nl = false; - - while (i < len && is_nl(str[i])) { - *has_nl = true; - i++; - } - - return i; -} - -static int progress_write(cli_progress *progress, bool force, git_str *line) -{ - bool has_nl; - size_t no_nl = no_nl_len(line->ptr, line->size); - size_t nl = nl_len(&has_nl, line->ptr + no_nl, line->size - no_nl); - uint64_t now = git_time_monotonic(); - size_t i; - - /* Avoid spamming the console with progress updates */ - if (!force && line->ptr[line->size - 1] != '\n' && progress->last_update) { - if (now - progress->last_update < PROGRESS_UPDATE_TIME) { - git_str_clear(&progress->deferred); - git_str_put(&progress->deferred, line->ptr, line->size); - return git_str_oom(&progress->deferred) ? -1 : 0; - } - } - - /* - * If there's something on this line already (eg, a progress line - * with only a trailing `\r` that we'll print over) then we need - * to really print over it in case we're writing a shorter line. - */ - if (printf("%.*s", (int)no_nl, line->ptr) < 0) - return_os_error("could not print status"); - - if (progress->onscreen.size) { - for (i = no_nl; i < progress->onscreen.size; i++) { - if (printf(" ") < 0) - return_os_error("could not print status"); - } - } - - if (printf("%.*s", (int)nl, line->ptr + no_nl) < 0 || - fflush(stdout) != 0) - return_os_error("could not print status"); - - git_str_clear(&progress->onscreen); - - if (line->ptr[line->size - 1] == '\n') { - progress->last_update = 0; - } else { - git_str_put(&progress->onscreen, line->ptr, line->size); - progress->last_update = now; - } - - git_str_clear(&progress->deferred); - return git_str_oom(&progress->onscreen) ? -1 : 0; -} - -static int progress_printf(cli_progress *progress, bool force, const char *fmt, ...) - GIT_FORMAT_PRINTF(3, 4); - -int progress_printf(cli_progress *progress, bool force, const char *fmt, ...) -{ - git_str buf = GIT_BUF_INIT; - va_list ap; - int error; - - va_start(ap, fmt); - error = git_str_vprintf(&buf, fmt, ap); - va_end(ap); - - if (error < 0) - return error; - - error = progress_write(progress, force, &buf); - - git_str_dispose(&buf); - return error; -} - -static int progress_complete(cli_progress *progress) -{ - if (progress->deferred.size) - progress_write(progress, true, &progress->deferred); - - if (progress->onscreen.size) - if (printf("\n") < 0) - return_os_error("could not print status"); - - git_str_clear(&progress->deferred); - git_str_clear(&progress->onscreen); - progress->last_update = 0; - progress->action_start = 0; - progress->action_finish = 0; - - return 0; -} - -GIT_INLINE(int) percent(size_t completed, size_t total) -{ - if (total == 0) - return (completed == 0) ? 100 : 0; - - return (int)(((double)completed / (double)total) * 100); -} - -int cli_progress_fetch_sideband(const char *str, int len, void *payload) -{ - cli_progress *progress = (cli_progress *)payload; - size_t remain; - - if (len <= 0) - return 0; - - /* Accumulate the sideband data, then print it line-at-a-time. */ - if (git_str_put(&progress->sideband, str, len) < 0) - return -1; - - str = progress->sideband.ptr; - remain = progress->sideband.size; - - while (remain) { - bool has_nl; - size_t line_len = nl_len(&has_nl, str, remain); - - if (!has_nl) - break; - - if (line_len < INT_MAX) { - int error = progress_printf(progress, true, - "remote: %.*s", (int)line_len, str); - - if (error < 0) - return error; - } - - str += line_len; - remain -= line_len; - } - - git_str_consume_bytes(&progress->sideband, (progress->sideband.size - remain)); - - return 0; -} - -static int fetch_receiving( - cli_progress *progress, - const git_indexer_progress *stats) -{ - char *recv_units[] = { "B", "KiB", "MiB", "GiB", "TiB", NULL }; - char *rate_units[] = { "B/s", "KiB/s", "MiB/s", "GiB/s", "TiB/s", NULL }; - uint64_t now, elapsed; - - double recv_len, rate; - size_t recv_unit_idx = 0, rate_unit_idx = 0; - bool done = (stats->received_objects == stats->total_objects); - - if (!progress->action_start) - progress->action_start = git_time_monotonic(); - - if (done && progress->action_finish) - now = progress->action_finish; - else if (done) - progress->action_finish = now = git_time_monotonic(); - else - now = git_time_monotonic(); - - if (progress->throughput_update && - now - progress->throughput_update < THROUGHPUT_UPDATE_TIME) { - elapsed = progress->throughput_update - - progress->action_start; - recv_len = progress->throughput_bytes; - } else { - elapsed = now - progress->action_start; - recv_len = (double)stats->received_bytes; - - progress->throughput_update = now; - progress->throughput_bytes = recv_len; - } - - rate = elapsed ? recv_len / elapsed : 0; - - while (recv_len > 1024 && recv_units[recv_unit_idx+1]) { - recv_len /= 1024; - recv_unit_idx++; - } - - while (rate > 1024 && rate_units[rate_unit_idx+1]) { - rate /= 1024; - rate_unit_idx++; - } - - return progress_printf(progress, false, - "Receiving objects: %3d%% (%d/%d), %.2f %s | %.2f %s%s\r", - percent(stats->received_objects, stats->total_objects), - stats->received_objects, - stats->total_objects, - recv_len, recv_units[recv_unit_idx], - rate, rate_units[rate_unit_idx], - done ? ", done." : ""); -} - -static int indexer_indexing( - cli_progress *progress, - const git_indexer_progress *stats) -{ - bool done = (stats->received_objects == stats->total_objects); - - return progress_printf(progress, false, - "Indexing objects: %3d%% (%d/%d)%s\r", - percent(stats->received_objects, stats->total_objects), - stats->received_objects, - stats->total_objects, - done ? ", done." : ""); -} - -static int indexer_resolving( - cli_progress *progress, - const git_indexer_progress *stats) -{ - bool done = (stats->indexed_deltas == stats->total_deltas); - - return progress_printf(progress, false, - "Resolving deltas: %3d%% (%d/%d)%s\r", - percent(stats->indexed_deltas, stats->total_deltas), - stats->indexed_deltas, stats->total_deltas, - done ? ", done." : ""); -} - -int cli_progress_fetch_transfer(const git_indexer_progress *stats, void *payload) -{ - cli_progress *progress = (cli_progress *)payload; - int error = 0; - - switch (progress->action) { - case CLI_PROGRESS_NONE: - progress->action = CLI_PROGRESS_RECEIVING; - /* fall through */ - - case CLI_PROGRESS_RECEIVING: - if ((error = fetch_receiving(progress, stats)) < 0) - break; - - /* - * Upgrade from receiving to resolving; do this after the - * final call to cli_progress_fetch_receiving (above) to - * ensure that we've printed a final "done" string after - * any sideband data. - */ - if (!stats->indexed_deltas) - break; - - progress_complete(progress); - progress->action = CLI_PROGRESS_RESOLVING; - /* fall through */ - - case CLI_PROGRESS_RESOLVING: - error = indexer_resolving(progress, stats); - break; - - default: - /* should not be reached */ - GIT_ASSERT(!"unexpected progress state"); - } - - return error; -} - -int cli_progress_indexer( - const git_indexer_progress *stats, - void *payload) -{ - cli_progress *progress = (cli_progress *)payload; - int error = 0; - - switch (progress->action) { - case CLI_PROGRESS_NONE: - progress->action = CLI_PROGRESS_INDEXING; - /* fall through */ - - case CLI_PROGRESS_INDEXING: - if ((error = indexer_indexing(progress, stats)) < 0) - break; - - if (stats->indexed_deltas == stats->total_deltas) - break; - - progress_complete(progress); - progress->action = CLI_PROGRESS_RESOLVING; - /* fall through */ - - case CLI_PROGRESS_RESOLVING: - error = indexer_resolving(progress, stats); - break; - - default: - /* should not be reached */ - GIT_ASSERT(!"unexpected progress state"); - } - - return error; -} - -void cli_progress_checkout( - const char *path, - size_t completed_steps, - size_t total_steps, - void *payload) -{ - cli_progress *progress = (cli_progress *)payload; - bool done = (completed_steps == total_steps); - - GIT_UNUSED(path); - - if (progress->action != CLI_PROGRESS_CHECKING_OUT) { - progress_complete(progress); - progress->action = CLI_PROGRESS_CHECKING_OUT; - } - - progress_printf(progress, false, - "Checking out files: %3d%% (%" PRIuZ "/%" PRIuZ ")%s\r", - percent(completed_steps, total_steps), - completed_steps, total_steps, - done ? ", done." : ""); -} - -int cli_progress_abort(cli_progress *progress) -{ - if (progress->onscreen.size > 0 && printf("\n") < 0) - return_os_error("could not print status"); - - return 0; -} - -int cli_progress_finish(cli_progress *progress) -{ - int error = progress->action ? progress_complete(progress) : 0; - - progress->action = 0; - return error; -} - -void cli_progress_dispose(cli_progress *progress) -{ - if (progress == NULL) - return; - - git_str_dispose(&progress->sideband); - git_str_dispose(&progress->onscreen); - git_str_dispose(&progress->deferred); - - memset(progress, 0, sizeof(cli_progress)); -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/progress.h b/vendor/libgit2-sys/libgit2/src/cli/progress.h deleted file mode 100644 index f08d68f..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/progress.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef CLI_progress_h__ -#define CLI_progress_h__ - -#include -#include "str.h" - -/* - * A general purpose set of progress printing functions. An individual - * `cli_progress` object is capable of displaying progress for a single - * function, even if that function displays multiple pieces of progress - * (like `git_clone`). `cli_progress_finish` should be called after - * any function invocation to re-set state. - */ - -typedef enum { - CLI_PROGRESS_NONE, - CLI_PROGRESS_RECEIVING, - CLI_PROGRESS_INDEXING, - CLI_PROGRESS_RESOLVING, - CLI_PROGRESS_CHECKING_OUT -} cli_progress_t; - -typedef struct { - cli_progress_t action; - - /* Actions may time themselves (eg fetch) but are not required to */ - uint64_t action_start; - uint64_t action_finish; - - /* Last console update, avoid too frequent updates. */ - uint64_t last_update; - - /* Accumulators for partial output and deferred updates. */ - git_str sideband; - git_str onscreen; - git_str deferred; - - /* Last update about throughput */ - uint64_t throughput_update; - double throughput_bytes; -} cli_progress; - -#define CLI_PROGRESS_INIT { 0 } - -/** - * Prints sideband data from fetch to the console. Suitable for a - * `sideband_progress` callback for `git_fetch_options`. - * - * @param str The sideband string - * @param len The length of the sideband string - * @param payload A pointer to the cli_progress - * @return 0 on success, -1 on failure - */ -extern int cli_progress_fetch_sideband( - const char *str, - int len, - void *payload); - -/** - * Prints fetch transfer statistics to the console. Suitable for a - * `transfer_progress` callback for `git_fetch_options`. - * - * @param stats The indexer stats - * @param payload A pointer to the cli_progress - * @return 0 on success, -1 on failure - */ -extern int cli_progress_fetch_transfer( - const git_indexer_progress *stats, - void *payload); - -/** - * Prints indexer progress to the console. Suitable for a - * `progress_cb` callback for `git_indexer_options`. - * - * @param stats The indexer stats - * @param payload A pointer to the cli_progress - */ -extern int cli_progress_indexer( - const git_indexer_progress *stats, - void *payload); - -/** - * Prints checkout progress to the console. Suitable for a - * `progress_cb` callback for `git_checkout_options`. - * - * @param path The path being written - * @param completed_steps The completed checkout steps - * @param total_steps The total number of checkout steps - * @param payload A pointer to the cli_progress - */ -extern void cli_progress_checkout( - const char *path, - size_t completed_steps, - size_t total_steps, - void *payload); - -/** - * Stop displaying progress quickly; suitable for stopping an application - * quickly. Does not display any lines that were buffered, just gets the - * console back to a sensible place. - * - * @param progress The progress information - * @return 0 on success, -1 on failure - */ -extern int cli_progress_abort(cli_progress *progress); - -/** - * Finishes displaying progress; flushes any buffered output. - * - * @param progress The progress information - * @return 0 on success, -1 on failure - */ -extern int cli_progress_finish(cli_progress *progress); - -/** - * Disposes the progress information. - * - * @param progress The progress information - */ -extern void cli_progress_dispose(cli_progress *progress); - -#endif /* CLI_progress_h__ */ diff --git a/vendor/libgit2-sys/libgit2/src/cli/sighandler.h b/vendor/libgit2-sys/libgit2/src/cli/sighandler.h deleted file mode 100644 index 877223e..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/sighandler.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef CLI_sighandler_h__ -#define CLI_sighandler_h__ - -/** - * Sets up a signal handler that will run when the process is interrupted - * (via SIGINT on POSIX or Control-C or Control-Break on Windows). - * - * @param handler The function to run on interrupt - * @return 0 on success, -1 on failure - */ -int cli_sighandler_set_interrupt(void (*handler)(void)); - -#endif /* CLI_sighandler_h__ */ diff --git a/vendor/libgit2-sys/libgit2/src/cli/unix/sighandler.c b/vendor/libgit2-sys/libgit2/src/cli/unix/sighandler.c deleted file mode 100644 index 05ac867..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/unix/sighandler.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include -#include "git2_util.h" -#include "common.h" -#include "sighandler.h" - -static void (*interrupt_handler)(void) = NULL; - -static void interrupt_proxy(int signal) -{ - GIT_UNUSED(signal); - interrupt_handler(); -} - -int cli_sighandler_set_interrupt(void (*handler)(void)) -{ - void (*result)(int); - - if ((interrupt_handler = handler) != NULL) - result = signal(SIGINT, interrupt_proxy); - else - result = signal(SIGINT, SIG_DFL); - - if (result == SIG_ERR) { - git_error_set(GIT_ERROR_OS, "could not set signal handler"); - return -1; - } - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/cli/win32/precompiled.c b/vendor/libgit2-sys/libgit2/src/cli/win32/precompiled.c deleted file mode 100644 index 5f656a4..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/win32/precompiled.c +++ /dev/null @@ -1 +0,0 @@ -#include "precompiled.h" diff --git a/vendor/libgit2-sys/libgit2/src/cli/win32/precompiled.h b/vendor/libgit2-sys/libgit2/src/cli/win32/precompiled.h deleted file mode 100644 index 031370e..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/win32/precompiled.h +++ /dev/null @@ -1,3 +0,0 @@ -#include - -#include "common.h" diff --git a/vendor/libgit2-sys/libgit2/src/cli/win32/sighandler.c b/vendor/libgit2-sys/libgit2/src/cli/win32/sighandler.c deleted file mode 100644 index 05a67fb..0000000 --- a/vendor/libgit2-sys/libgit2/src/cli/win32/sighandler.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" -#include - -#include "sighandler.h" - -static void (*interrupt_handler)(void) = NULL; - -static BOOL WINAPI interrupt_proxy(DWORD signal) -{ - GIT_UNUSED(signal); - interrupt_handler(); - return TRUE; -} - -int cli_sighandler_set_interrupt(void (*handler)(void)) -{ - BOOL result; - - if ((interrupt_handler = handler) != NULL) - result = SetConsoleCtrlHandler(interrupt_proxy, FALSE); - else - result = SetConsoleCtrlHandler(NULL, FALSE); - - if (!result) { - git_error_set(GIT_ERROR_OS, "could not set control control handler"); - return -1; - } - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/CMakeLists.txt b/vendor/libgit2-sys/libgit2/src/libgit2/CMakeLists.txt deleted file mode 100644 index 8045dde..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/CMakeLists.txt +++ /dev/null @@ -1,156 +0,0 @@ -# libgit2: the shared library: this CMakeLists.txt compiles the core -# git library functionality. - -add_library(libgit2 OBJECT) - -include(PkgBuildConfig) -include(CMakePackageConfigHelpers) - -set(LIBGIT2_INCLUDES - "${PROJECT_SOURCE_DIR}/src/libgit2" - "${PROJECT_SOURCE_DIR}/src/util" - "${PROJECT_SOURCE_DIR}/include" - "${PROJECT_BINARY_DIR}/gen_headers") - -# Collect sourcefiles -file(GLOB SRC_H - "${PROJECT_SOURCE_DIR}/include/git2.h" - "${PROJECT_SOURCE_DIR}/include/git2/*.h" - "${PROJECT_SOURCE_DIR}/include/git2/sys/*.h") -list(SORT SRC_H) -target_sources(libgit2 PRIVATE ${SRC_H}) - -file(GLOB SRC_GIT2 *.c *.h - streams/*.c streams/*.h - transports/*.c transports/*.h) -list(SORT SRC_GIT2) -target_sources(libgit2 PRIVATE ${SRC_GIT2}) - -if(WIN32 AND NOT CYGWIN) - # Add resource information on Windows - set(SRC_RC "git2.rc") -endif() - -if(APPLE) - # The old Secure Transport API has been deprecated in macOS 10.15. - set_source_files_properties(streams/stransport.c PROPERTIES COMPILE_FLAGS -Wno-deprecated) -endif() - -ide_split_sources(libgit2) -list(APPEND LIBGIT2_OBJECTS $ $ ${LIBGIT2_DEPENDENCY_OBJECTS}) -list(APPEND LIBGIT2_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES}) - -target_include_directories(libgit2 - PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} - PUBLIC $ - $) - -target_include_directories(libgit2 SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) - -set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE) -set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE) -set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE) -set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE) -set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE) -set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE) - -# -# Compile and link libgit2 -# - -if (NOT BUILD_SHARED_LIBS AND XCODE_VERSION) - # This is required for Xcode to actually create the static libgit2 library - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.c "") - list(APPEND LIBGIT2_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/dummy.c) -endif() - -add_library(libgit2package ${SRC_RC} ${LIBGIT2_OBJECTS}) -target_link_libraries(libgit2package ${LIBGIT2_SYSTEM_LIBS}) -target_include_directories(libgit2package SYSTEM PRIVATE ${LIBGIT2_INCLUDES}) -target_include_directories(libgit2package INTERFACE $) - -set_target_properties(libgit2package PROPERTIES C_STANDARD 90) -set_target_properties(libgit2package PROPERTIES C_EXTENSIONS OFF) -set_target_properties(libgit2package PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set_target_properties(libgit2package PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set_target_properties(libgit2package PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) - -ide_split_sources(libgit2package) - -if(SONAME) - set_target_properties(libgit2package PROPERTIES VERSION ${libgit2_VERSION}) - set_target_properties(libgit2package PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}") - if(LIBGIT2_FILENAME) - target_compile_definitions(libgit2package PRIVATE LIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\") - set_target_properties(libgit2package PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME}) - elseif(DEFINED LIBGIT2_PREFIX) - set_target_properties(libgit2package PROPERTIES PREFIX "${LIBGIT2_PREFIX}") - endif() -endif() - -pkg_build_config(NAME "lib${LIBGIT2_FILENAME}" - VERSION ${libgit2_VERSION} - DESCRIPTION "The git library, take 2" - LIBS_SELF ${LIBGIT2_FILENAME} - PRIVATE_LIBS ${LIBGIT2_PC_LIBS} - REQUIRES ${LIBGIT2_PC_REQUIRES}) - -if(MSVC_IDE) - # Precompiled headers - set_target_properties(libgit2package PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") - set_source_files_properties(win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h") -endif() - -# support experimental features and functionality - -configure_file(experimental.h.in "${PROJECT_BINARY_DIR}/gen_headers/experimental.h") - -# translate filenames in the headers so that they match the install directory -# (allows for side-by-side installs of libgit2 and libgit2-experimental.) - -foreach(HEADER_SOURCE ${SRC_H}) - file(RELATIVE_PATH HEADER_RELATIVE ${PROJECT_SOURCE_DIR} ${HEADER_SOURCE}) - string(REGEX REPLACE "^include\/git2" "include/${LIBGIT2_FILENAME}" HEADER_RELATIVE ${HEADER_RELATIVE}) - - file(READ "${HEADER_SOURCE}" HEADER_CONTENTS) - string(REGEX REPLACE "#include \"git2\/" "#include \"${LIBGIT2_FILENAME}/" HEADER_CONTENTS "${HEADER_CONTENTS}") - - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${HEADER_RELATIVE}.tmp" "${HEADER_CONTENTS}") - configure_file("${CMAKE_CURRENT_BINARY_DIR}/${HEADER_RELATIVE}.tmp" "${PROJECT_BINARY_DIR}/${HEADER_RELATIVE}" COPYONLY) -endforeach() - -configure_file("${PROJECT_BINARY_DIR}/gen_headers/experimental.h" "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}/experimental.h" COPYONLY) - -# cmake package targets - -set(LIBGIT2_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") - -write_basic_package_version_file( - "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake" - VERSION ${PROJECT_VERSION} - COMPATIBILITY SameMajorVersion) - -configure_file(config.cmake.in - "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake" - @ONLY) - -install(FILES - "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake" - "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") -install( - EXPORT ${LIBGIT2_TARGETS_EXPORT_NAME} - NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - -# Install - -install(TARGETS libgit2package - EXPORT ${LIBGIT2_TARGETS_EXPORT_NAME} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(FILES "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}.h" - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(DIRECTORY "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}" - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/annotated_commit.c b/vendor/libgit2-sys/libgit2/src/libgit2/annotated_commit.c deleted file mode 100644 index c5c8ace..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/annotated_commit.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "annotated_commit.h" - -#include "refs.h" -#include "cache.h" - -#include "git2/commit.h" -#include "git2/refs.h" -#include "git2/repository.h" -#include "git2/annotated_commit.h" -#include "git2/revparse.h" -#include "git2/tree.h" -#include "git2/index.h" - -static int annotated_commit_init( - git_annotated_commit **out, - git_commit *commit, - const char *description) -{ - git_annotated_commit *annotated_commit; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(commit); - - *out = NULL; - - annotated_commit = git__calloc(1, sizeof(git_annotated_commit)); - GIT_ERROR_CHECK_ALLOC(annotated_commit); - - annotated_commit->type = GIT_ANNOTATED_COMMIT_REAL; - - if ((error = git_commit_dup(&annotated_commit->commit, commit)) < 0) - goto done; - - git_oid_tostr(annotated_commit->id_str, GIT_OID_MAX_HEXSIZE + 1, - git_commit_id(commit)); - - if (!description) - description = annotated_commit->id_str; - - annotated_commit->description = git__strdup(description); - GIT_ERROR_CHECK_ALLOC(annotated_commit->description); - -done: - if (!error) - *out = annotated_commit; - - return error; -} - -static int annotated_commit_init_from_id( - git_annotated_commit **out, - git_repository *repo, - const git_oid *id, - const char *description) -{ - git_commit *commit = NULL; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(id); - - *out = NULL; - - if ((error = git_commit_lookup(&commit, repo, id)) < 0) - goto done; - - error = annotated_commit_init(out, commit, description); - -done: - git_commit_free(commit); - return error; -} - -int git_annotated_commit_lookup( - git_annotated_commit **out, - git_repository *repo, - const git_oid *id) -{ - return annotated_commit_init_from_id(out, repo, id, NULL); -} - -int git_annotated_commit_from_commit( - git_annotated_commit **out, - git_commit *commit) -{ - return annotated_commit_init(out, commit, NULL); -} - -int git_annotated_commit_from_revspec( - git_annotated_commit **out, - git_repository *repo, - const char *revspec) -{ - git_object *obj, *commit; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(revspec); - - if ((error = git_revparse_single(&obj, repo, revspec)) < 0) - return error; - - if ((error = git_object_peel(&commit, obj, GIT_OBJECT_COMMIT))) { - git_object_free(obj); - return error; - } - - error = annotated_commit_init(out, (git_commit *)commit, revspec); - - git_object_free(obj); - git_object_free(commit); - - return error; -} - -int git_annotated_commit_from_ref( - git_annotated_commit **out, - git_repository *repo, - const git_reference *ref) -{ - git_object *peeled; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(ref); - - *out = NULL; - - if ((error = git_reference_peel(&peeled, ref, GIT_OBJECT_COMMIT)) < 0) - return error; - - error = annotated_commit_init_from_id(out, - repo, - git_object_id(peeled), - git_reference_name(ref)); - - if (!error) { - (*out)->ref_name = git__strdup(git_reference_name(ref)); - GIT_ERROR_CHECK_ALLOC((*out)->ref_name); - } - - git_object_free(peeled); - return error; -} - -int git_annotated_commit_from_head( - git_annotated_commit **out, - git_repository *repo) -{ - git_reference *head; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - *out = NULL; - - if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0) - return -1; - - error = git_annotated_commit_from_ref(out, repo, head); - - git_reference_free(head); - return error; -} - -int git_annotated_commit_from_fetchhead( - git_annotated_commit **out, - git_repository *repo, - const char *branch_name, - const char *remote_url, - const git_oid *id) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(branch_name); - GIT_ASSERT_ARG(remote_url); - GIT_ASSERT_ARG(id); - - if (annotated_commit_init_from_id(out, repo, id, branch_name) < 0) - return -1; - - (*out)->ref_name = git__strdup(branch_name); - GIT_ERROR_CHECK_ALLOC((*out)->ref_name); - - (*out)->remote_url = git__strdup(remote_url); - GIT_ERROR_CHECK_ALLOC((*out)->remote_url); - - return 0; -} - - -const git_oid *git_annotated_commit_id( - const git_annotated_commit *annotated_commit) -{ - GIT_ASSERT_ARG_WITH_RETVAL(annotated_commit, NULL); - return git_commit_id(annotated_commit->commit); -} - -const char *git_annotated_commit_ref( - const git_annotated_commit *annotated_commit) -{ - GIT_ASSERT_ARG_WITH_RETVAL(annotated_commit, NULL); - return annotated_commit->ref_name; -} - -void git_annotated_commit_free(git_annotated_commit *annotated_commit) -{ - if (annotated_commit == NULL) - return; - - switch (annotated_commit->type) { - case GIT_ANNOTATED_COMMIT_REAL: - git_commit_free(annotated_commit->commit); - git_tree_free(annotated_commit->tree); - git__free((char *)annotated_commit->description); - git__free((char *)annotated_commit->ref_name); - git__free((char *)annotated_commit->remote_url); - break; - case GIT_ANNOTATED_COMMIT_VIRTUAL: - git_index_free(annotated_commit->index); - git_array_clear(annotated_commit->parents); - break; - default: - abort(); - } - - git__free(annotated_commit); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/annotated_commit.h b/vendor/libgit2-sys/libgit2/src/libgit2/annotated_commit.h deleted file mode 100644 index 1f805fe..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/annotated_commit.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_annotated_commit_h__ -#define INCLUDE_annotated_commit_h__ - -#include "common.h" - -#include "oidarray.h" - -#include "git2/oid.h" - -typedef enum { - GIT_ANNOTATED_COMMIT_REAL = 1, - GIT_ANNOTATED_COMMIT_VIRTUAL = 2 -} git_annotated_commit_t; - -/** - * Internal structure for merge inputs. An annotated commit is generally - * "real" and backed by an actual commit in the repository, but merge will - * internally create "virtual" commits that are in-memory intermediate - * commits backed by an index. - */ -struct git_annotated_commit { - git_annotated_commit_t type; - - /* real commit */ - git_commit *commit; - git_tree *tree; - - /* virtual commit structure */ - git_index *index; - git_array_oid_t parents; - - /* how this commit was looked up */ - const char *description; - - const char *ref_name; - const char *remote_url; - - char id_str[GIT_OID_MAX_HEXSIZE + 1]; -}; - -extern int git_annotated_commit_from_head(git_annotated_commit **out, - git_repository *repo); -extern int git_annotated_commit_from_commit(git_annotated_commit **out, - git_commit *commit); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/apply.c b/vendor/libgit2-sys/libgit2/src/libgit2/apply.c deleted file mode 100644 index 07e502d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/apply.c +++ /dev/null @@ -1,896 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2/apply.h" -#include "git2/patch.h" -#include "git2/filter.h" -#include "git2/blob.h" -#include "git2/index.h" -#include "git2/checkout.h" -#include "git2/repository.h" -#include "array.h" -#include "patch.h" -#include "futils.h" -#include "delta.h" -#include "zstream.h" -#include "reader.h" -#include "index.h" -#include "repository.h" -#include "hashmap_str.h" -#include "apply.h" - -typedef struct { - /* The lines that we allocate ourself are allocated out of the pool. - * (Lines may have been allocated out of the diff.) - */ - git_pool pool; - git_vector lines; -} patch_image; - -static int apply_err(const char *fmt, ...) GIT_FORMAT_PRINTF(1, 2); -static int apply_err(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - git_error_vset(GIT_ERROR_PATCH, fmt, ap); - va_end(ap); - - return GIT_EAPPLYFAIL; -} - -static void patch_line_init( - git_diff_line *out, - const char *in, - size_t in_len, - size_t in_offset) -{ - out->content = in; - out->content_len = in_len; - out->content_offset = in_offset; -} - -#define PATCH_IMAGE_INIT { GIT_POOL_INIT, GIT_VECTOR_INIT } - -static int patch_image_init_fromstr( - patch_image *out, const char *in, size_t in_len) -{ - git_diff_line *line; - const char *start, *end; - - memset(out, 0x0, sizeof(patch_image)); - - if (git_pool_init(&out->pool, sizeof(git_diff_line)) < 0) - return -1; - - if (!in_len) - return 0; - - for (start = in; start < in + in_len; start = end) { - end = memchr(start, '\n', in_len - (start - in)); - - if (end == NULL) - end = in + in_len; - - else if (end < in + in_len) - end++; - - line = git_pool_mallocz(&out->pool, 1); - GIT_ERROR_CHECK_ALLOC(line); - - if (git_vector_insert(&out->lines, line) < 0) - return -1; - - patch_line_init(line, start, (end - start), (start - in)); - } - - return 0; -} - -static void patch_image_free(patch_image *image) -{ - if (image == NULL) - return; - - git_pool_clear(&image->pool); - git_vector_dispose(&image->lines); -} - -static bool match_hunk( - patch_image *image, - patch_image *preimage, - size_t linenum) -{ - bool match = 0; - size_t i; - - /* Ensure this hunk is within the image boundaries. */ - if (git_vector_length(&preimage->lines) + linenum > - git_vector_length(&image->lines)) - return 0; - - match = 1; - - /* Check exact match. */ - for (i = 0; i < git_vector_length(&preimage->lines); i++) { - git_diff_line *preimage_line = git_vector_get(&preimage->lines, i); - git_diff_line *image_line = git_vector_get(&image->lines, linenum + i); - - if (preimage_line->content_len != image_line->content_len || - memcmp(preimage_line->content, image_line->content, image_line->content_len) != 0) { - match = 0; - break; - } - } - - return match; -} - -static bool find_hunk_linenum( - size_t *out, - patch_image *image, - patch_image *preimage, - size_t linenum) -{ - size_t max = git_vector_length(&image->lines); - bool match; - - if (linenum > max) - linenum = max; - - match = match_hunk(image, preimage, linenum); - - *out = linenum; - return match; -} - -static int update_hunk( - patch_image *image, - size_t linenum, - patch_image *preimage, - patch_image *postimage) -{ - size_t postlen = git_vector_length(&postimage->lines); - size_t prelen = git_vector_length(&preimage->lines); - size_t i; - int error = 0; - - if (postlen > prelen) - error = git_vector_insert_null( - &image->lines, linenum, (postlen - prelen)); - else if (prelen > postlen) - error = git_vector_remove_range( - &image->lines, linenum, (prelen - postlen)); - - if (error) { - git_error_set_oom(); - return -1; - } - - for (i = 0; i < git_vector_length(&postimage->lines); i++) { - image->lines.contents[linenum + i] = - git_vector_get(&postimage->lines, i); - } - - return 0; -} - -typedef struct { - git_apply_options opts; - size_t skipped_new_lines; - size_t skipped_old_lines; -} apply_hunks_ctx; - -static int apply_hunk( - patch_image *image, - git_patch *patch, - git_patch_hunk *hunk, - apply_hunks_ctx *ctx) -{ - patch_image preimage = PATCH_IMAGE_INIT, postimage = PATCH_IMAGE_INIT; - size_t line_num, i; - int error = 0; - - if (ctx->opts.hunk_cb) { - error = ctx->opts.hunk_cb(&hunk->hunk, ctx->opts.payload); - - if (error) { - if (error > 0) { - ctx->skipped_new_lines += hunk->hunk.new_lines; - ctx->skipped_old_lines += hunk->hunk.old_lines; - error = 0; - } - - goto done; - } - } - - for (i = 0; i < hunk->line_count; i++) { - size_t linenum = hunk->line_start + i; - git_diff_line *line = git_array_get(patch->lines, linenum), *prev; - - if (!line) { - error = apply_err("preimage does not contain line %"PRIuZ, linenum); - goto done; - } - - switch (line->origin) { - case GIT_DIFF_LINE_CONTEXT_EOFNL: - case GIT_DIFF_LINE_DEL_EOFNL: - case GIT_DIFF_LINE_ADD_EOFNL: - prev = i ? git_array_get(patch->lines, linenum - 1) : NULL; - if (prev && prev->content[prev->content_len - 1] == '\n') - prev->content_len -= 1; - break; - case GIT_DIFF_LINE_CONTEXT: - if ((error = git_vector_insert(&preimage.lines, line)) < 0 || - (error = git_vector_insert(&postimage.lines, line)) < 0) - goto done; - break; - case GIT_DIFF_LINE_DELETION: - if ((error = git_vector_insert(&preimage.lines, line)) < 0) - goto done; - break; - case GIT_DIFF_LINE_ADDITION: - if ((error = git_vector_insert(&postimage.lines, line)) < 0) - goto done; - break; - } - } - - if (hunk->hunk.new_start) { - line_num = hunk->hunk.new_start - - ctx->skipped_new_lines + - ctx->skipped_old_lines - - 1; - } else { - line_num = 0; - } - - if (!find_hunk_linenum(&line_num, image, &preimage, line_num)) { - error = apply_err("hunk at line %d did not apply", - hunk->hunk.new_start); - goto done; - } - - error = update_hunk(image, line_num, &preimage, &postimage); - -done: - patch_image_free(&preimage); - patch_image_free(&postimage); - - return error; -} - -static int apply_hunks( - git_str *out, - const char *source, - size_t source_len, - git_patch *patch, - apply_hunks_ctx *ctx) -{ - git_patch_hunk *hunk; - git_diff_line *line; - patch_image image; - size_t i; - int error = 0; - - if ((error = patch_image_init_fromstr(&image, source, source_len)) < 0) - goto done; - - git_array_foreach(patch->hunks, i, hunk) { - if ((error = apply_hunk(&image, patch, hunk, ctx)) < 0) - goto done; - } - - git_vector_foreach(&image.lines, i, line) - git_str_put(out, line->content, line->content_len); - -done: - patch_image_free(&image); - - return error; -} - -static int apply_binary_delta( - git_str *out, - const char *source, - size_t source_len, - git_diff_binary_file *binary_file) -{ - git_str inflated = GIT_STR_INIT; - int error = 0; - - /* no diff means identical contents */ - if (binary_file->datalen == 0) - return git_str_put(out, source, source_len); - - error = git_zstream_inflatebuf(&inflated, - binary_file->data, binary_file->datalen); - - if (!error && inflated.size != binary_file->inflatedlen) { - error = apply_err("inflated delta does not match expected length"); - git_str_dispose(out); - } - - if (error < 0) - goto done; - - if (binary_file->type == GIT_DIFF_BINARY_DELTA) { - void *data; - size_t data_len; - - error = git_delta_apply(&data, &data_len, (void *)source, source_len, - (void *)inflated.ptr, inflated.size); - - out->ptr = data; - out->size = data_len; - out->asize = data_len; - } - else if (binary_file->type == GIT_DIFF_BINARY_LITERAL) { - git_str_swap(out, &inflated); - } - else { - error = apply_err("unknown binary delta type"); - goto done; - } - -done: - git_str_dispose(&inflated); - return error; -} - -static int apply_binary( - git_str *out, - const char *source, - size_t source_len, - git_patch *patch) -{ - git_str reverse = GIT_STR_INIT; - int error = 0; - - if (!patch->binary.contains_data) { - error = apply_err("patch does not contain binary data"); - goto done; - } - - if (!patch->binary.old_file.datalen && !patch->binary.new_file.datalen) - goto done; - - /* first, apply the new_file delta to the given source */ - if ((error = apply_binary_delta(out, source, source_len, - &patch->binary.new_file)) < 0) - goto done; - - /* second, apply the old_file delta to sanity check the result */ - if ((error = apply_binary_delta(&reverse, out->ptr, out->size, - &patch->binary.old_file)) < 0) - goto done; - - /* Verify that the resulting file with the reverse patch applied matches the source file */ - if (source_len != reverse.size || - (source_len && memcmp(source, reverse.ptr, source_len) != 0)) { - error = apply_err("binary patch did not apply cleanly"); - goto done; - } - -done: - if (error < 0) - git_str_dispose(out); - - git_str_dispose(&reverse); - return error; -} - -int git_apply__patch( - git_str *contents_out, - char **filename_out, - unsigned int *mode_out, - const char *source, - size_t source_len, - git_patch *patch, - const git_apply_options *given_opts) -{ - apply_hunks_ctx ctx = { GIT_APPLY_OPTIONS_INIT }; - char *filename = NULL; - unsigned int mode = 0; - int error = 0; - - GIT_ASSERT_ARG(contents_out); - GIT_ASSERT_ARG(filename_out); - GIT_ASSERT_ARG(mode_out); - GIT_ASSERT_ARG(source || !source_len); - GIT_ASSERT_ARG(patch); - - if (given_opts) - memcpy(&ctx.opts, given_opts, sizeof(git_apply_options)); - - *filename_out = NULL; - *mode_out = 0; - - if (patch->delta->status != GIT_DELTA_DELETED) { - const git_diff_file *newfile = &patch->delta->new_file; - - filename = git__strdup(newfile->path); - mode = newfile->mode ? - newfile->mode : GIT_FILEMODE_BLOB; - } - - if (patch->delta->flags & GIT_DIFF_FLAG_BINARY) - error = apply_binary(contents_out, source, source_len, patch); - else if (patch->hunks.size) - error = apply_hunks(contents_out, source, source_len, patch, &ctx); - else - error = git_str_put(contents_out, source, source_len); - - if (error) - goto done; - - if (patch->delta->status == GIT_DELTA_DELETED && - git_str_len(contents_out) > 0) { - error = apply_err("removal patch leaves file contents"); - goto done; - } - - *filename_out = filename; - *mode_out = mode; - -done: - if (error < 0) - git__free(filename); - - return error; -} - -static int apply_one( - git_repository *repo, - git_reader *preimage_reader, - git_index *preimage, - git_reader *postimage_reader, - git_index *postimage, - git_diff *diff, - git_hashset_str *removed_paths, - size_t i, - const git_apply_options *opts) -{ - git_patch *patch = NULL; - git_str pre_contents = GIT_STR_INIT, post_contents = GIT_STR_INIT; - const git_diff_delta *delta; - char *filename = NULL; - unsigned int mode; - git_oid pre_id, post_id; - git_filemode_t pre_filemode; - git_index_entry pre_entry, post_entry; - bool skip_preimage = false; - int error; - - if ((error = git_patch_from_diff(&patch, diff, i)) < 0) - goto done; - - delta = git_patch_get_delta(patch); - - if (opts->delta_cb) { - error = opts->delta_cb(delta, opts->payload); - - if (error) { - if (error > 0) - error = 0; - - goto done; - } - } - - /* - * Ensure that the file has not been deleted or renamed if we're - * applying a modification delta. - */ - if (delta->status != GIT_DELTA_RENAMED && - delta->status != GIT_DELTA_ADDED) { - if (git_hashset_str_contains(removed_paths, delta->old_file.path)) { - error = apply_err("path '%s' has been renamed or deleted", delta->old_file.path); - goto done; - } - } - - /* - * We may be applying a second delta to an already seen file. If so, - * use the already modified data in the postimage instead of the - * content from the index or working directory. (Don't do this in - * the case of a rename, which must be specified before additional - * deltas since we apply deltas to the target filename.) - */ - if (delta->status != GIT_DELTA_RENAMED) { - if ((error = git_reader_read(&pre_contents, &pre_id, &pre_filemode, - postimage_reader, delta->old_file.path)) == 0) { - skip_preimage = true; - } else if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } else { - goto done; - } - } - - if (!skip_preimage && delta->status != GIT_DELTA_ADDED) { - error = git_reader_read(&pre_contents, &pre_id, &pre_filemode, - preimage_reader, delta->old_file.path); - - /* ENOTFOUND means the preimage was not found; apply failed. */ - if (error == GIT_ENOTFOUND) - error = GIT_EAPPLYFAIL; - - /* When applying to BOTH, the index did not match the workdir. */ - if (error == GIT_READER_MISMATCH) - error = apply_err("%s: does not match index", delta->old_file.path); - - if (error < 0) - goto done; - - /* - * We need to populate the preimage data structure with the - * contents that we are using as the preimage for this file. - * This allows us to apply patches to files that have been - * modified in the working directory. During checkout, - * we will use this expected preimage as the baseline, and - * limit checkout to only the paths affected by patch - * application. (Without this, we would fail to write the - * postimage contents to any file that had been modified - * from HEAD on-disk, even if the patch application succeeded.) - * Use the contents from the delta where available - some - * fields may not be available, like the old file mode (eg in - * an exact rename situation) so trust the patch parsing to - * validate and use the preimage data in that case. - */ - if (preimage) { - memset(&pre_entry, 0, sizeof(git_index_entry)); - pre_entry.path = delta->old_file.path; - pre_entry.mode = delta->old_file.mode ? delta->old_file.mode : pre_filemode; - git_oid_cpy(&pre_entry.id, &pre_id); - - if ((error = git_index_add(preimage, &pre_entry)) < 0) - goto done; - } - } - - if (delta->status != GIT_DELTA_DELETED) { - if ((error = git_apply__patch(&post_contents, &filename, &mode, - pre_contents.ptr, pre_contents.size, patch, opts)) < 0 || - (error = git_blob_create_from_buffer(&post_id, repo, - post_contents.ptr, post_contents.size)) < 0) - goto done; - - memset(&post_entry, 0, sizeof(git_index_entry)); - post_entry.path = filename; - post_entry.mode = mode; - git_oid_cpy(&post_entry.id, &post_id); - - if ((error = git_index_add(postimage, &post_entry)) < 0) - goto done; - } - - if (delta->status == GIT_DELTA_RENAMED || - delta->status == GIT_DELTA_DELETED) - error = git_hashset_str_add(removed_paths, delta->old_file.path); - - if (delta->status == GIT_DELTA_RENAMED || - delta->status == GIT_DELTA_ADDED) - git_hashset_str_remove(removed_paths, delta->new_file.path); - -done: - git_str_dispose(&pre_contents); - git_str_dispose(&post_contents); - git__free(filename); - git_patch_free(patch); - - return error; -} - -static int apply_deltas( - git_repository *repo, - git_reader *pre_reader, - git_index *preimage, - git_reader *post_reader, - git_index *postimage, - git_diff *diff, - const git_apply_options *opts) -{ - git_hashset_str removed_paths = GIT_HASHSET_INIT; - size_t i; - int error = 0; - - for (i = 0; i < git_diff_num_deltas(diff); i++) { - if ((error = apply_one(repo, pre_reader, preimage, post_reader, postimage, diff, &removed_paths, i, opts)) < 0) - goto done; - } - -done: - git_hashset_str_dispose(&removed_paths); - return error; -} - -int git_apply_to_tree( - git_index **out, - git_repository *repo, - git_tree *preimage, - git_diff *diff, - const git_apply_options *given_opts) -{ - git_index *postimage = NULL; - git_reader *pre_reader = NULL, *post_reader = NULL; - git_apply_options opts = GIT_APPLY_OPTIONS_INIT; - const git_diff_delta *delta; - size_t i; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(preimage); - GIT_ASSERT_ARG(diff); - - *out = NULL; - - if (given_opts) - memcpy(&opts, given_opts, sizeof(git_apply_options)); - - if ((error = git_reader_for_tree(&pre_reader, preimage)) < 0) - goto done; - - /* - * put the current tree into the postimage as-is - the diff will - * replace any entries contained therein - */ - if ((error = git_index__new(&postimage, repo->oid_type)) < 0 || - (error = git_index_read_tree(postimage, preimage)) < 0 || - (error = git_reader_for_index(&post_reader, repo, postimage)) < 0) - goto done; - - /* - * Remove the old paths from the index before applying diffs - - * we need to do a full pass to remove them before adding deltas, - * in order to handle rename situations. - */ - for (i = 0; i < git_diff_num_deltas(diff); i++) { - delta = git_diff_get_delta(diff, i); - - if (delta->status == GIT_DELTA_DELETED || - delta->status == GIT_DELTA_RENAMED) { - if ((error = git_index_remove(postimage, - delta->old_file.path, 0)) < 0) - goto done; - } - } - - if ((error = apply_deltas(repo, pre_reader, NULL, post_reader, postimage, diff, &opts)) < 0) - goto done; - - *out = postimage; - -done: - if (error < 0) - git_index_free(postimage); - - git_reader_free(pre_reader); - git_reader_free(post_reader); - - return error; -} - -static int git_apply__to_workdir( - git_repository *repo, - git_diff *diff, - git_index *preimage, - git_index *postimage, - git_apply_location_t location, - git_apply_options *opts) -{ - git_vector paths = GIT_VECTOR_INIT; - git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; - const git_diff_delta *delta; - size_t i; - int error; - - GIT_UNUSED(opts); - - /* - * Limit checkout to the paths affected by the diff; this ensures - * that other modifications in the working directory are unaffected. - */ - if ((error = git_vector_init(&paths, git_diff_num_deltas(diff), NULL)) < 0) - goto done; - - for (i = 0; i < git_diff_num_deltas(diff); i++) { - delta = git_diff_get_delta(diff, i); - - if ((error = git_vector_insert(&paths, (void *)delta->old_file.path)) < 0) - goto done; - - if (strcmp(delta->old_file.path, delta->new_file.path) && - (error = git_vector_insert(&paths, (void *)delta->new_file.path)) < 0) - goto done; - } - - checkout_opts.checkout_strategy |= GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH; - checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_WRITE_INDEX; - - if (location == GIT_APPLY_LOCATION_WORKDIR) - checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_UPDATE_INDEX; - - checkout_opts.paths.strings = (char **)paths.contents; - checkout_opts.paths.count = paths.length; - - checkout_opts.baseline_index = preimage; - - error = git_checkout_index(repo, postimage, &checkout_opts); - -done: - git_vector_dispose(&paths); - return error; -} - -static int git_apply__to_index( - git_repository *repo, - git_diff *diff, - git_index *preimage, - git_index *postimage, - git_apply_options *opts) -{ - git_index *index = NULL; - const git_diff_delta *delta; - const git_index_entry *entry; - size_t i; - int error; - - GIT_UNUSED(preimage); - GIT_UNUSED(opts); - - if ((error = git_repository_index(&index, repo)) < 0) - goto done; - - /* Remove deleted (or renamed) paths from the index. */ - for (i = 0; i < git_diff_num_deltas(diff); i++) { - delta = git_diff_get_delta(diff, i); - - if (delta->status == GIT_DELTA_DELETED || - delta->status == GIT_DELTA_RENAMED) { - if ((error = git_index_remove(index, delta->old_file.path, 0)) < 0) - goto done; - } - } - - /* Then add the changes back to the index. */ - for (i = 0; i < git_index_entrycount(postimage); i++) { - entry = git_index_get_byindex(postimage, i); - - if ((error = git_index_add(index, entry)) < 0) - goto done; - } - -done: - git_index_free(index); - return error; -} - -int git_apply_options_init(git_apply_options *opts, unsigned int version) -{ - GIT_ASSERT_ARG(opts); - - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_apply_options, GIT_APPLY_OPTIONS_INIT); - return 0; -} - -/* - * Handle the three application options ("locations"): - * - * GIT_APPLY_LOCATION_WORKDIR: the default, emulates `git apply`. - * Applies the diff only to the workdir items and ignores the index - * entirely. - * - * GIT_APPLY_LOCATION_INDEX: emulates `git apply --cached`. - * Applies the diff only to the index items and ignores the workdir - * completely. - * - * GIT_APPLY_LOCATION_BOTH: emulates `git apply --index`. - * Applies the diff to both the index items and the working directory - * items. - */ - -int git_apply( - git_repository *repo, - git_diff *diff, - git_apply_location_t location, - const git_apply_options *given_opts) -{ - git_indexwriter indexwriter = GIT_INDEXWRITER_INIT; - git_index *index = NULL, *preimage = NULL, *postimage = NULL; - git_reader *pre_reader = NULL, *post_reader = NULL; - git_apply_options opts = GIT_APPLY_OPTIONS_INIT; - int error = GIT_EINVALID; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(diff); - - GIT_ERROR_CHECK_VERSION( - given_opts, GIT_APPLY_OPTIONS_VERSION, "git_apply_options"); - - if (given_opts) - memcpy(&opts, given_opts, sizeof(git_apply_options)); - - /* - * by default, we apply a patch directly to the working directory; - * in `--cached` or `--index` mode, we apply to the contents already - * in the index. - */ - switch (location) { - case GIT_APPLY_LOCATION_BOTH: - error = git_reader_for_workdir(&pre_reader, repo, true); - break; - case GIT_APPLY_LOCATION_INDEX: - error = git_reader_for_index(&pre_reader, repo, NULL); - break; - case GIT_APPLY_LOCATION_WORKDIR: - error = git_reader_for_workdir(&pre_reader, repo, false); - break; - default: - GIT_ASSERT(false); - } - - if (error < 0) - goto done; - - /* - * Build the preimage and postimage (differences). Note that - * this is not the complete preimage or postimage, it only - * contains the files affected by the patch. We want to avoid - * having the full repo index, so we will limit our checkout - * to only write these files that were affected by the diff. - */ - if ((error = git_index__new(&preimage, repo->oid_type)) < 0 || - (error = git_index__new(&postimage, repo->oid_type)) < 0 || - (error = git_reader_for_index(&post_reader, repo, postimage)) < 0) - goto done; - - if (!(opts.flags & GIT_APPLY_CHECK)) - if ((error = git_repository_index(&index, repo)) < 0 || - (error = git_indexwriter_init(&indexwriter, index)) < 0) - goto done; - - if ((error = apply_deltas(repo, pre_reader, preimage, post_reader, postimage, diff, &opts)) < 0) - goto done; - - if ((opts.flags & GIT_APPLY_CHECK)) - goto done; - - switch (location) { - case GIT_APPLY_LOCATION_BOTH: - error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts); - break; - case GIT_APPLY_LOCATION_INDEX: - error = git_apply__to_index(repo, diff, preimage, postimage, &opts); - break; - case GIT_APPLY_LOCATION_WORKDIR: - error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts); - break; - default: - GIT_ASSERT(false); - } - - if (error < 0) - goto done; - - error = git_indexwriter_commit(&indexwriter); - -done: - git_indexwriter_cleanup(&indexwriter); - git_index_free(postimage); - git_index_free(preimage); - git_index_free(index); - git_reader_free(pre_reader); - git_reader_free(post_reader); - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/apply.h b/vendor/libgit2-sys/libgit2/src/libgit2/apply.h deleted file mode 100644 index e990a71..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/apply.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_apply_h__ -#define INCLUDE_apply_h__ - -#include "common.h" - -#include "git2/patch.h" -#include "git2/apply.h" -#include "str.h" - -extern int git_apply__patch( - git_str *out, - char **filename, - unsigned int *mode, - const char *source, - size_t source_len, - git_patch *patch, - const git_apply_options *opts); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/attr.c b/vendor/libgit2-sys/libgit2/src/libgit2/attr.c deleted file mode 100644 index 8d096d7..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/attr.c +++ /dev/null @@ -1,717 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "attr.h" - -#include "repository.h" -#include "sysdir.h" -#include "config.h" -#include "attr_file.h" -#include "ignore.h" -#include "git2/oid.h" -#include "hashmap_str.h" -#include - -const char *git_attr__true = "[internal]__TRUE__"; -const char *git_attr__false = "[internal]__FALSE__"; -const char *git_attr__unset = "[internal]__UNSET__"; - -git_attr_value_t git_attr_value(const char *attr) -{ - if (attr == NULL || attr == git_attr__unset) - return GIT_ATTR_VALUE_UNSPECIFIED; - - if (attr == git_attr__true) - return GIT_ATTR_VALUE_TRUE; - - if (attr == git_attr__false) - return GIT_ATTR_VALUE_FALSE; - - return GIT_ATTR_VALUE_STRING; -} - -static int collect_attr_files( - git_repository *repo, - git_attr_session *attr_session, - git_attr_options *opts, - const char *path, - git_vector *files); - -static void release_attr_files(git_vector *files); - -int git_attr_get_ext( - const char **value, - git_repository *repo, - git_attr_options *opts, - const char *pathname, - const char *name) -{ - int error; - git_attr_path path; - git_vector files = GIT_VECTOR_INIT; - size_t i, j; - git_attr_file *file; - git_attr_name attr; - git_attr_rule *rule; - git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN; - - GIT_ASSERT_ARG(value); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - GIT_ERROR_CHECK_VERSION(opts, GIT_ATTR_OPTIONS_VERSION, "git_attr_options"); - - *value = NULL; - - if (git_repository_is_bare(repo)) - dir_flag = GIT_DIR_FLAG_FALSE; - - if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), dir_flag) < 0) - return -1; - - if ((error = collect_attr_files(repo, NULL, opts, pathname, &files)) < 0) - goto cleanup; - - memset(&attr, 0, sizeof(attr)); - attr.name = name; - attr.name_hash = git_attr_file__name_hash(name); - - git_vector_foreach(&files, i, file) { - - git_attr_file__foreach_matching_rule(file, &path, j, rule) { - size_t pos; - - if (!git_vector_bsearch(&pos, &rule->assigns, &attr)) { - *value = ((git_attr_assignment *)git_vector_get( - &rule->assigns, pos))->value; - goto cleanup; - } - } - } - -cleanup: - release_attr_files(&files); - git_attr_path__free(&path); - - return error; -} - -int git_attr_get( - const char **value, - git_repository *repo, - uint32_t flags, - const char *pathname, - const char *name) -{ - git_attr_options opts = GIT_ATTR_OPTIONS_INIT; - - opts.flags = flags; - - return git_attr_get_ext(value, repo, &opts, pathname, name); -} - - -typedef struct { - git_attr_name name; - git_attr_assignment *found; -} attr_get_many_info; - -int git_attr_get_many_with_session( - const char **values, - git_repository *repo, - git_attr_session *attr_session, - git_attr_options *opts, - const char *pathname, - size_t num_attr, - const char **names) -{ - int error; - git_attr_path path; - git_vector files = GIT_VECTOR_INIT; - size_t i, j, k; - git_attr_file *file; - git_attr_rule *rule; - attr_get_many_info *info = NULL; - size_t num_found = 0; - git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN; - - if (!num_attr) - return 0; - - GIT_ASSERT_ARG(values); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(pathname); - GIT_ASSERT_ARG(names); - GIT_ERROR_CHECK_VERSION(opts, GIT_ATTR_OPTIONS_VERSION, "git_attr_options"); - - if (git_repository_is_bare(repo)) - dir_flag = GIT_DIR_FLAG_FALSE; - - if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), dir_flag) < 0) - return -1; - - if ((error = collect_attr_files(repo, attr_session, opts, pathname, &files)) < 0) - goto cleanup; - - info = git__calloc(num_attr, sizeof(attr_get_many_info)); - GIT_ERROR_CHECK_ALLOC(info); - - git_vector_foreach(&files, i, file) { - - git_attr_file__foreach_matching_rule(file, &path, j, rule) { - - for (k = 0; k < num_attr; k++) { - size_t pos; - - if (info[k].found != NULL) /* already found assignment */ - continue; - - if (!info[k].name.name) { - info[k].name.name = names[k]; - info[k].name.name_hash = git_attr_file__name_hash(names[k]); - } - - if (!git_vector_bsearch(&pos, &rule->assigns, &info[k].name)) { - info[k].found = (git_attr_assignment *) - git_vector_get(&rule->assigns, pos); - values[k] = info[k].found->value; - - if (++num_found == num_attr) - goto cleanup; - } - } - } - } - - for (k = 0; k < num_attr; k++) { - if (!info[k].found) - values[k] = NULL; - } - -cleanup: - release_attr_files(&files); - git_attr_path__free(&path); - git__free(info); - - return error; -} - -int git_attr_get_many( - const char **values, - git_repository *repo, - uint32_t flags, - const char *pathname, - size_t num_attr, - const char **names) -{ - git_attr_options opts = GIT_ATTR_OPTIONS_INIT; - - opts.flags = flags; - - return git_attr_get_many_with_session( - values, repo, NULL, &opts, pathname, num_attr, names); -} - -int git_attr_get_many_ext( - const char **values, - git_repository *repo, - git_attr_options *opts, - const char *pathname, - size_t num_attr, - const char **names) -{ - return git_attr_get_many_with_session( - values, repo, NULL, opts, pathname, num_attr, names); -} - -int git_attr_foreach( - git_repository *repo, - uint32_t flags, - const char *pathname, - int (*callback)(const char *name, const char *value, void *payload), - void *payload) -{ - git_attr_options opts = GIT_ATTR_OPTIONS_INIT; - - opts.flags = flags; - - return git_attr_foreach_ext(repo, &opts, pathname, callback, payload); -} - -int git_attr_foreach_ext( - git_repository *repo, - git_attr_options *opts, - const char *pathname, - int (*callback)(const char *name, const char *value, void *payload), - void *payload) -{ - int error; - git_attr_path path; - git_vector files = GIT_VECTOR_INIT; - size_t i, j, k; - git_attr_file *file; - git_attr_rule *rule; - git_attr_assignment *assign; - git_hashset_str seen = GIT_HASHSET_INIT; - git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(callback); - GIT_ERROR_CHECK_VERSION(opts, GIT_ATTR_OPTIONS_VERSION, "git_attr_options"); - - if (git_repository_is_bare(repo)) - dir_flag = GIT_DIR_FLAG_FALSE; - - if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), dir_flag) < 0) - return -1; - - if ((error = collect_attr_files(repo, NULL, opts, pathname, &files)) < 0) - goto cleanup; - - git_vector_foreach(&files, i, file) { - - git_attr_file__foreach_matching_rule(file, &path, j, rule) { - - git_vector_foreach(&rule->assigns, k, assign) { - /* skip if higher priority assignment was already seen */ - if (git_hashset_str_contains(&seen, assign->name)) - continue; - - if ((error = git_hashset_str_add(&seen, assign->name)) < 0) - goto cleanup; - - error = callback(assign->name, assign->value, payload); - if (error) { - git_error_set_after_callback(error); - goto cleanup; - } - } - } - } - -cleanup: - git_hashset_str_dispose(&seen); - release_attr_files(&files); - git_attr_path__free(&path); - - return error; -} - -static int preload_attr_source( - git_repository *repo, - git_attr_session *attr_session, - git_attr_file_source *source) -{ - int error; - git_attr_file *preload = NULL; - - if (!source) - return 0; - - error = git_attr_cache__get(&preload, repo, attr_session, source, - git_attr_file__parse_buffer, true); - - if (!error) - git_attr_file__free(preload); - - return error; -} - -GIT_INLINE(int) preload_attr_file( - git_repository *repo, - git_attr_session *attr_session, - const char *base, - const char *filename) -{ - git_attr_file_source source = { GIT_ATTR_FILE_SOURCE_FILE }; - - if (!filename) - return 0; - - source.base = base; - source.filename = filename; - - return preload_attr_source(repo, attr_session, &source); -} - -static int system_attr_file( - git_str *out, - git_attr_session *attr_session) -{ - int error; - - if (!attr_session) { - error = git_sysdir_find_system_file(out, GIT_ATTR_FILE_SYSTEM); - - if (error == GIT_ENOTFOUND) - git_error_clear(); - - return error; - } - - if (!attr_session->init_sysdir) { - error = git_sysdir_find_system_file(&attr_session->sysdir, GIT_ATTR_FILE_SYSTEM); - - if (error == GIT_ENOTFOUND) - git_error_clear(); - else if (error) - return error; - - attr_session->init_sysdir = 1; - } - - if (attr_session->sysdir.size == 0) - return GIT_ENOTFOUND; - - /* We can safely provide a git_str with no allocation (asize == 0) to - * a consumer. This allows them to treat this as a regular `git_str`, - * but their call to `git_str_dispose` will not attempt to free it. - */ - git_str_attach_notowned( - out, attr_session->sysdir.ptr, attr_session->sysdir.size); - return 0; -} - -static int attr_setup( - git_repository *repo, - git_attr_session *attr_session, - git_attr_options *opts) -{ - git_str system = GIT_STR_INIT, info = GIT_STR_INIT; - git_attr_file_source index_source = { GIT_ATTR_FILE_SOURCE_INDEX, NULL, GIT_ATTR_FILE, NULL }; - git_attr_file_source head_source = { GIT_ATTR_FILE_SOURCE_HEAD, NULL, GIT_ATTR_FILE, NULL }; - git_attr_file_source commit_source = { GIT_ATTR_FILE_SOURCE_COMMIT, NULL, GIT_ATTR_FILE, NULL }; - git_attr_cache *attrcache; - const char *attr_cfg_file = NULL; - git_index *idx = NULL; - const char *workdir; - int error = 0; - - if (attr_session && attr_session->init_setup) - return 0; - - if ((error = git_attr_cache__init(repo)) < 0) - return error; - - /* - * Preload attribute files that could contain macros so the - * definitions will be available for later file parsing. - */ - - if ((error = system_attr_file(&system, attr_session)) < 0 || - (error = preload_attr_file(repo, attr_session, NULL, system.ptr)) < 0) { - if (error != GIT_ENOTFOUND) - goto out; - - error = 0; - } - - if ((attrcache = git_repository_attr_cache(repo)) != NULL) - attr_cfg_file = git_attr_cache_attributesfile(attrcache); - - if ((error = preload_attr_file(repo, attr_session, NULL, attr_cfg_file)) < 0) - goto out; - - if ((error = git_repository__item_path(&info, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || - (error = preload_attr_file(repo, attr_session, info.ptr, GIT_ATTR_FILE_INREPO)) < 0) { - if (error != GIT_ENOTFOUND) - goto out; - - error = 0; - } - - if ((workdir = git_repository_workdir(repo)) != NULL && - (error = preload_attr_file(repo, attr_session, workdir, GIT_ATTR_FILE)) < 0) - goto out; - - if ((error = git_repository_index__weakptr(&idx, repo)) < 0 || - (error = preload_attr_source(repo, attr_session, &index_source)) < 0) { - if (error != GIT_ENOTFOUND) - goto out; - - error = 0; - } - - if ((opts && (opts->flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0) && - (error = preload_attr_source(repo, attr_session, &head_source)) < 0) - goto out; - - if ((opts && (opts->flags & GIT_ATTR_CHECK_INCLUDE_COMMIT) != 0)) { -#ifndef GIT_DEPRECATE_HARD - if (opts->commit_id) - commit_source.commit_id = opts->commit_id; - else -#endif - commit_source.commit_id = &opts->attr_commit_id; - - if ((error = preload_attr_source(repo, attr_session, &commit_source)) < 0) - goto out; - } - - if (attr_session) - attr_session->init_setup = 1; - -out: - git_str_dispose(&system); - git_str_dispose(&info); - - return error; -} - -int git_attr_add_macro( - git_repository *repo, - const char *name, - const char *values) -{ - int error; - git_attr_rule *macro = NULL; - git_attr_cache *attrcache; - git_pool *pool; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - if ((error = git_attr_cache__init(repo)) < 0) - return error; - - macro = git__calloc(1, sizeof(git_attr_rule)); - GIT_ERROR_CHECK_ALLOC(macro); - - attrcache = git_repository_attr_cache(repo); - pool = git_attr_cache_pool(attrcache); - - macro->match.pattern = git_pool_strdup(pool, name); - GIT_ERROR_CHECK_ALLOC(macro->match.pattern); - - macro->match.length = strlen(macro->match.pattern); - macro->match.flags = GIT_ATTR_FNMATCH_MACRO; - - error = git_attr_assignment__parse(repo, pool, ¯o->assigns, &values); - - if (!error) - error = git_attr_cache__insert_macro(repo, macro); - - if (error < 0) - git_attr_rule__free(macro); - - return error; -} - -typedef struct { - git_repository *repo; - git_attr_session *attr_session; - git_attr_options *opts; - const char *workdir; - git_index *index; - git_vector *files; -} attr_walk_up_info; - -static int attr_decide_sources( - uint32_t flags, - bool has_wd, - bool has_index, - git_attr_file_source_t *srcs) -{ - int count = 0; - - switch (flags & 0x03) { - case GIT_ATTR_CHECK_FILE_THEN_INDEX: - if (has_wd) - srcs[count++] = GIT_ATTR_FILE_SOURCE_FILE; - if (has_index) - srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX; - break; - case GIT_ATTR_CHECK_INDEX_THEN_FILE: - if (has_index) - srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX; - if (has_wd) - srcs[count++] = GIT_ATTR_FILE_SOURCE_FILE; - break; - case GIT_ATTR_CHECK_INDEX_ONLY: - if (has_index) - srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX; - break; - } - - if ((flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0) - srcs[count++] = GIT_ATTR_FILE_SOURCE_HEAD; - - if ((flags & GIT_ATTR_CHECK_INCLUDE_COMMIT) != 0) - srcs[count++] = GIT_ATTR_FILE_SOURCE_COMMIT; - - return count; -} - -static int push_attr_source( - git_repository *repo, - git_attr_session *attr_session, - git_vector *list, - git_attr_file_source *source, - bool allow_macros) -{ - int error = 0; - git_attr_file *file = NULL; - - error = git_attr_cache__get(&file, repo, attr_session, - source, - git_attr_file__parse_buffer, - allow_macros); - - if (error < 0) - return error; - - if (file != NULL) { - if ((error = git_vector_insert(list, file)) < 0) - git_attr_file__free(file); - } - - return error; -} - -GIT_INLINE(int) push_attr_file( - git_repository *repo, - git_attr_session *attr_session, - git_vector *list, - const char *base, - const char *filename) -{ - git_attr_file_source source = { GIT_ATTR_FILE_SOURCE_FILE, base, filename }; - return push_attr_source(repo, attr_session, list, &source, true); -} - -static int push_one_attr(void *ref, const char *path) -{ - attr_walk_up_info *info = (attr_walk_up_info *)ref; - git_attr_file_source_t src[GIT_ATTR_FILE_NUM_SOURCES]; - int error = 0, n_src, i; - bool allow_macros; - - n_src = attr_decide_sources(info->opts ? info->opts->flags : 0, - info->workdir != NULL, - info->index != NULL, - src); - - allow_macros = info->workdir ? !strcmp(info->workdir, path) : false; - - for (i = 0; !error && i < n_src; ++i) { - git_attr_file_source source = { src[i], path, GIT_ATTR_FILE }; - - if (src[i] == GIT_ATTR_FILE_SOURCE_COMMIT && info->opts) { -#ifndef GIT_DEPRECATE_HARD - if (info->opts->commit_id) - source.commit_id = info->opts->commit_id; - else -#endif - source.commit_id = &info->opts->attr_commit_id; - } - - error = push_attr_source(info->repo, info->attr_session, info->files, - &source, allow_macros); - } - - return error; -} - -static void release_attr_files(git_vector *files) -{ - size_t i; - git_attr_file *file; - - git_vector_foreach(files, i, file) { - git_attr_file__free(file); - files->contents[i] = NULL; - } - git_vector_dispose(files); -} - -static int collect_attr_files( - git_repository *repo, - git_attr_session *attr_session, - git_attr_options *opts, - const char *path, - git_vector *files) -{ - int error = 0; - git_str dir = GIT_STR_INIT, attrfile = GIT_STR_INIT; - const char *workdir = git_repository_workdir(repo); - git_attr_cache *attrcache; - const char *attr_cfg_file = NULL; - attr_walk_up_info info = { NULL }; - - GIT_ASSERT(!git_fs_path_is_absolute(path)); - - if ((error = attr_setup(repo, attr_session, opts)) < 0) - return error; - - /* Resolve path in a non-bare repo */ - if (workdir != NULL) { - if (!(error = git_repository_workdir_path(&dir, repo, path))) - error = git_fs_path_find_dir(&dir); - } - else { - error = git_fs_path_dirname_r(&dir, path); - } - - if (error < 0) - goto cleanup; - - /* in precedence order highest to lowest: - * - $GIT_DIR/info/attributes - * - path components with .gitattributes - * - config core.attributesfile - * - $GIT_PREFIX/etc/gitattributes - */ - - if ((error = git_repository__item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || - (error = push_attr_file(repo, attr_session, files, attrfile.ptr, GIT_ATTR_FILE_INREPO)) < 0) { - if (error != GIT_ENOTFOUND) - goto cleanup; - } - - info.repo = repo; - info.attr_session = attr_session; - info.opts = opts; - info.workdir = workdir; - if (git_repository_index__weakptr(&info.index, repo) < 0) - git_error_clear(); /* no error even if there is no index */ - info.files = files; - - if (!strcmp(dir.ptr, ".")) - error = push_one_attr(&info, ""); - else - error = git_fs_path_walk_up(&dir, workdir, push_one_attr, &info); - - if (error < 0) - goto cleanup; - - if ((attrcache = git_repository_attr_cache(repo)) != NULL) - attr_cfg_file = git_attr_cache_attributesfile(attrcache); - - - if (attr_cfg_file) { - error = push_attr_file(repo, attr_session, files, NULL, attr_cfg_file); - - if (error < 0) - goto cleanup; - } - - if (!opts || (opts->flags & GIT_ATTR_CHECK_NO_SYSTEM) == 0) { - error = system_attr_file(&dir, attr_session); - - if (!error) - error = push_attr_file(repo, attr_session, files, NULL, dir.ptr); - else if (error == GIT_ENOTFOUND) - error = 0; - } - - cleanup: - if (error < 0) - release_attr_files(files); - git_str_dispose(&attrfile); - git_str_dispose(&dir); - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/attr.h b/vendor/libgit2-sys/libgit2/src/libgit2/attr.h deleted file mode 100644 index 9775652..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/attr.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_attr_h__ -#define INCLUDE_attr_h__ - -#include "common.h" - -#include "attr_file.h" -#include "attrcache.h" - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/attr_file.c b/vendor/libgit2-sys/libgit2/src/libgit2/attr_file.c deleted file mode 100644 index d52a115..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/attr_file.c +++ /dev/null @@ -1,1039 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "attr_file.h" - -#include "repository.h" -#include "filebuf.h" -#include "attrcache.h" -#include "git2/blob.h" -#include "git2/tree.h" -#include "blob.h" -#include "index.h" -#include "wildmatch.h" -#include - -static void attr_file_free(git_attr_file *file) -{ - bool unlock = !git_mutex_lock(&file->lock); - git_attr_file__clear_rules(file, false); - git_pool_clear(&file->pool); - if (unlock) - git_mutex_unlock(&file->lock); - git_mutex_free(&file->lock); - - git__memzero(file, sizeof(*file)); - git__free(file); -} - -int git_attr_file__new( - git_attr_file **out, - git_attr_file_entry *entry, - git_attr_file_source *source) -{ - git_attr_file *attrs = git__calloc(1, sizeof(git_attr_file)); - GIT_ERROR_CHECK_ALLOC(attrs); - - if (git_mutex_init(&attrs->lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to initialize lock"); - goto on_error; - } - - if (git_pool_init(&attrs->pool, 1) < 0) - goto on_error; - - GIT_REFCOUNT_INC(attrs); - attrs->entry = entry; - memcpy(&attrs->source, source, sizeof(git_attr_file_source)); - *out = attrs; - return 0; - -on_error: - git__free(attrs); - return -1; -} - -int git_attr_file__clear_rules(git_attr_file *file, bool need_lock) -{ - unsigned int i; - git_attr_rule *rule; - - if (need_lock && git_mutex_lock(&file->lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock attribute file"); - return -1; - } - - git_vector_foreach(&file->rules, i, rule) - git_attr_rule__free(rule); - git_vector_dispose(&file->rules); - - if (need_lock) - git_mutex_unlock(&file->lock); - - return 0; -} - -void git_attr_file__free(git_attr_file *file) -{ - if (!file) - return; - GIT_REFCOUNT_DEC(file, attr_file_free); -} - -static int attr_file_oid_from_index( - git_oid *oid, git_repository *repo, const char *path) -{ - int error; - git_index *idx; - size_t pos; - const git_index_entry *entry; - - if ((error = git_repository_index__weakptr(&idx, repo)) < 0 || - (error = git_index__find_pos(&pos, idx, path, 0, 0)) < 0) - return error; - - if (!(entry = git_index_get_byindex(idx, pos))) - return GIT_ENOTFOUND; - - *oid = entry->id; - return 0; -} - -int git_attr_file__load( - git_attr_file **out, - git_repository *repo, - git_attr_session *attr_session, - git_attr_file_entry *entry, - git_attr_file_source *source, - git_attr_file_parser parser, - bool allow_macros) -{ - int error = 0; - git_commit *commit = NULL; - git_tree *tree = NULL; - git_tree_entry *tree_entry = NULL; - git_blob *blob = NULL; - git_str content = GIT_STR_INIT; - const char *content_str; - git_attr_file *file; - struct stat st; - bool nonexistent = false; - int bom_offset; - git_str_bom_t bom; - git_oid id; - git_object_size_t blobsize; - - *out = NULL; - - switch (source->type) { - case GIT_ATTR_FILE_SOURCE_MEMORY: - /* in-memory attribute file doesn't need data */ - break; - case GIT_ATTR_FILE_SOURCE_INDEX: { - if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 || - (error = git_blob_lookup(&blob, repo, &id)) < 0) - return error; - - /* Do not assume that data straight from the ODB is NULL-terminated; - * copy the contents of a file to a buffer to work on */ - blobsize = git_blob_rawsize(blob); - - GIT_ERROR_CHECK_BLOBSIZE(blobsize); - if (blobsize > GIT_ATTR_MAX_FILE_SIZE) /* TODO: issue warning when warning API is available */ - goto cleanup; - git_str_put(&content, git_blob_rawcontent(blob), (size_t)blobsize); - break; - } - case GIT_ATTR_FILE_SOURCE_FILE: { - int fd = -1; - - /* For open or read errors, pretend that we got ENOTFOUND. */ - /* TODO: issue warning when warning API is available */ - - if (p_stat(entry->fullpath, &st) < 0 || - S_ISDIR(st.st_mode) || - (fd = git_futils_open_ro(entry->fullpath)) < 0 || - (st.st_size > GIT_ATTR_MAX_FILE_SIZE) || - (error = git_futils_readbuffer_fd(&content, fd, (size_t)st.st_size)) < 0) - nonexistent = true; - - if (fd >= 0) - p_close(fd); - - break; - } - case GIT_ATTR_FILE_SOURCE_HEAD: - case GIT_ATTR_FILE_SOURCE_COMMIT: { - if (source->type == GIT_ATTR_FILE_SOURCE_COMMIT) { - if ((error = git_commit_lookup(&commit, repo, source->commit_id)) < 0 || - (error = git_commit_tree(&tree, commit)) < 0) - goto cleanup; - } else { - if ((error = git_repository_head_tree(&tree, repo)) < 0) - goto cleanup; - } - - if ((error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0) { - /* - * If the attributes file does not exist, we can - * cache an empty file for this commit to prevent - * needless future lookups. - */ - if (error == GIT_ENOTFOUND) { - error = 0; - break; - } - - goto cleanup; - } - - if ((error = git_blob_lookup(&blob, repo, git_tree_entry_id(tree_entry))) < 0) - goto cleanup; - - /* - * Do not assume that data straight from the ODB is NULL-terminated; - * copy the contents of a file to a buffer to work on. - */ - blobsize = git_blob_rawsize(blob); - - GIT_ERROR_CHECK_BLOBSIZE(blobsize); - if (blobsize > GIT_ATTR_MAX_FILE_SIZE) /* TODO: issue warning when warning API is available */ - goto cleanup; - if ((error = git_str_put(&content, - git_blob_rawcontent(blob), (size_t)blobsize)) < 0) - goto cleanup; - - break; - } - default: - git_error_set(GIT_ERROR_INVALID, "unknown file source %d", source->type); - return -1; - } - - if ((error = git_attr_file__new(&file, entry, source)) < 0) - goto cleanup; - - /* advance over a UTF8 BOM */ - content_str = git_str_cstr(&content); - bom_offset = git_str_detect_bom(&bom, &content); - - if (bom == GIT_STR_BOM_UTF8) - content_str += bom_offset; - - /* store the key of the attr_reader; don't bother with cache - * invalidation during the same attr reader session. - */ - if (attr_session) - file->session_key = attr_session->key; - - if (parser && (error = parser(repo, file, content_str, allow_macros)) < 0) { - git_attr_file__free(file); - goto cleanup; - } - - /* write cache breakers */ - if (nonexistent) - file->nonexistent = 1; - else if (source->type == GIT_ATTR_FILE_SOURCE_INDEX) - git_oid_cpy(&file->cache_data.oid, git_blob_id(blob)); - else if (source->type == GIT_ATTR_FILE_SOURCE_HEAD) - git_oid_cpy(&file->cache_data.oid, git_tree_id(tree)); - else if (source->type == GIT_ATTR_FILE_SOURCE_COMMIT) - git_oid_cpy(&file->cache_data.oid, git_tree_id(tree)); - else if (source->type == GIT_ATTR_FILE_SOURCE_FILE) - git_futils_filestamp_set_from_stat(&file->cache_data.stamp, &st); - /* else always cacheable */ - - *out = file; - -cleanup: - git_blob_free(blob); - git_tree_entry_free(tree_entry); - git_tree_free(tree); - git_commit_free(commit); - git_str_dispose(&content); - - return error; -} - -int git_attr_file__out_of_date( - git_repository *repo, - git_attr_session *attr_session, - git_attr_file *file, - git_attr_file_source *source) -{ - if (!file) - return 1; - - /* we are never out of date if we just created this data in the same - * attr_session; otherwise, nonexistent files must be invalidated - */ - if (attr_session && attr_session->key == file->session_key) - return 0; - else if (file->nonexistent) - return 1; - - switch (file->source.type) { - case GIT_ATTR_FILE_SOURCE_MEMORY: - return 0; - - case GIT_ATTR_FILE_SOURCE_FILE: - return git_futils_filestamp_check( - &file->cache_data.stamp, file->entry->fullpath); - - case GIT_ATTR_FILE_SOURCE_INDEX: { - int error; - git_oid id; - - if ((error = attr_file_oid_from_index( - &id, repo, file->entry->path)) < 0) - return error; - - return (git_oid__cmp(&file->cache_data.oid, &id) != 0); - } - - case GIT_ATTR_FILE_SOURCE_HEAD: { - git_tree *tree = NULL; - int error = git_repository_head_tree(&tree, repo); - - if (error < 0) - return error; - - error = (git_oid__cmp(&file->cache_data.oid, git_tree_id(tree)) != 0); - - git_tree_free(tree); - return error; - } - - case GIT_ATTR_FILE_SOURCE_COMMIT: { - git_commit *commit = NULL; - git_tree *tree = NULL; - int error; - - if ((error = git_commit_lookup(&commit, repo, source->commit_id)) < 0) - return error; - - error = git_commit_tree(&tree, commit); - git_commit_free(commit); - - if (error < 0) - return error; - - error = (git_oid__cmp(&file->cache_data.oid, git_tree_id(tree)) != 0); - - git_tree_free(tree); - return error; - } - - default: - git_error_set(GIT_ERROR_INVALID, "invalid file type %d", file->source.type); - return -1; - } -} - -static int sort_by_hash_and_name(const void *a_raw, const void *b_raw); -static void git_attr_rule__clear(git_attr_rule *rule); -static bool parse_optimized_patterns( - git_attr_fnmatch *spec, - git_pool *pool, - const char *pattern); - -int git_attr_file__parse_buffer( - git_repository *repo, git_attr_file *attrs, const char *data, bool allow_macros) -{ - const char *scan = data, *context = NULL; - git_attr_rule *rule = NULL; - int ignorecase = 0, error = 0; - - /* If subdir file path, convert context for file paths */ - if (attrs->entry && git_fs_path_root(attrs->entry->path) < 0 && - !git__suffixcmp(attrs->entry->path, "/" GIT_ATTR_FILE)) - context = attrs->entry->path; - - if (git_mutex_lock(&attrs->lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock attribute file"); - return -1; - } - - while (!error && *scan) { - /* Allocate rule if needed, otherwise re-use previous rule */ - if (!rule) { - rule = git__calloc(1, sizeof(*rule)); - GIT_ERROR_CHECK_ALLOC(rule); - } else - git_attr_rule__clear(rule); - - rule->match.flags = GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO; - - /* Parse the next "pattern attr attr attr" line */ - if ((error = git_attr_fnmatch__parse(&rule->match, &attrs->pool, context, &scan)) < 0 || - (error = git_attr_assignment__parse(repo, &attrs->pool, &rule->assigns, &scan)) < 0) - { - if (error != GIT_ENOTFOUND) - goto out; - error = 0; - continue; - } - - if (repo && - (error = git_repository__configmap_lookup(&ignorecase, repo, GIT_CONFIGMAP_IGNORECASE)) < 0) - goto out; - - if (ignorecase) - rule->match.flags |= GIT_ATTR_FNMATCH_ICASE; - - if (rule->match.flags & GIT_ATTR_FNMATCH_MACRO) { - /* TODO: warning if macro found in file below repo root */ - if (!allow_macros) - continue; - if ((error = git_attr_cache__insert_macro(repo, rule)) < 0) - goto out; - } else if ((error = git_vector_insert(&attrs->rules, rule)) < 0) - goto out; - - rule = NULL; - } - -out: - git_mutex_unlock(&attrs->lock); - git_attr_rule__free(rule); - - return error; -} - -uint32_t git_attr_file__name_hash(const char *name) -{ - uint32_t h = 5381; - int c; - - GIT_ASSERT_ARG(name); - - while ((c = (int)*name++) != 0) - h = ((h << 5) + h) + c; - return h; -} - -int git_attr_file__lookup_one( - git_attr_file *file, - git_attr_path *path, - const char *attr, - const char **value) -{ - size_t i; - git_attr_name name; - git_attr_rule *rule; - - *value = NULL; - - name.name = attr; - name.name_hash = git_attr_file__name_hash(attr); - - git_attr_file__foreach_matching_rule(file, path, i, rule) { - size_t pos; - - if (!git_vector_bsearch(&pos, &rule->assigns, &name)) { - *value = ((git_attr_assignment *) - git_vector_get(&rule->assigns, pos))->value; - break; - } - } - - return 0; -} - -int git_attr_file__load_standalone(git_attr_file **out, const char *path) -{ - git_str content = GIT_STR_INIT; - git_attr_file_source source = { GIT_ATTR_FILE_SOURCE_FILE }; - git_attr_file *file = NULL; - int error; - - if ((error = git_futils_readbuffer(&content, path)) < 0) - goto out; - - /* - * Because the cache entry is allocated from the file's own pool, we - * don't have to free it - freeing file+pool will free cache entry, too. - */ - - if ((error = git_attr_file__new(&file, NULL, &source)) < 0 || - (error = git_attr_file__parse_buffer(NULL, file, content.ptr, true)) < 0 || - (error = git_attr_cache__alloc_file_entry(&file->entry, NULL, NULL, path, &file->pool)) < 0) - goto out; - - *out = file; -out: - if (error < 0) - git_attr_file__free(file); - git_str_dispose(&content); - - return error; -} - -bool git_attr_fnmatch__match( - git_attr_fnmatch *match, - git_attr_path *path) -{ - const char *relpath = path->path; - const char *filename; - int flags = 0; - - /* - * If the rule was generated in a subdirectory, we must only - * use it for paths inside that directory. We can thus return - * a non-match if the prefixes don't match. - */ - if (match->containing_dir) { - if (match->flags & GIT_ATTR_FNMATCH_ICASE) { - if (git__prefixcmp_icase(path->path, match->containing_dir)) - return 0; - } else { - if (git__prefixcmp(path->path, match->containing_dir)) - return 0; - } - - relpath += match->containing_dir_length; - } - - if (match->flags & GIT_ATTR_FNMATCH_ICASE) - flags |= WM_CASEFOLD; - - if (match->flags & GIT_ATTR_FNMATCH_FULLPATH) { - filename = relpath; - flags |= WM_PATHNAME; - } else { - filename = path->basename; - } - - if ((match->flags & GIT_ATTR_FNMATCH_DIRECTORY) && !path->is_dir) { - bool samename; - - /* - * for attribute checks or checks at the root of this match's - * containing_dir (or root of the repository if no containing_dir), - * do not match. - */ - if (!(match->flags & GIT_ATTR_FNMATCH_IGNORE) || - path->basename == relpath) - return false; - - /* fail match if this is a file with same name as ignored folder */ - samename = (match->flags & GIT_ATTR_FNMATCH_ICASE) ? - !strcasecmp(match->pattern, relpath) : - !strcmp(match->pattern, relpath); - - if (samename) - return false; - - return (wildmatch(match->pattern, relpath, flags) == WM_MATCH); - } - - return (wildmatch(match->pattern, filename, flags) == WM_MATCH); -} - -bool git_attr_rule__match( - git_attr_rule *rule, - git_attr_path *path) -{ - bool matched = git_attr_fnmatch__match(&rule->match, path); - - if (rule->match.flags & GIT_ATTR_FNMATCH_NEGATIVE) - matched = !matched; - - return matched; -} - -git_attr_assignment *git_attr_rule__lookup_assignment( - git_attr_rule *rule, const char *name) -{ - size_t pos; - git_attr_name key; - key.name = name; - key.name_hash = git_attr_file__name_hash(name); - - if (git_vector_bsearch(&pos, &rule->assigns, &key)) - return NULL; - - return git_vector_get(&rule->assigns, pos); -} - -int git_attr_path__init( - git_attr_path *info, - const char *path, - const char *base, - git_dir_flag dir_flag) -{ - ssize_t root; - - /* build full path as best we can */ - git_str_init(&info->full, 0); - - if (git_fs_path_join_unrooted(&info->full, path, base, &root) < 0) - return -1; - - info->path = info->full.ptr + root; - - /* remove trailing slashes */ - while (info->full.size > 0) { - if (info->full.ptr[info->full.size - 1] != '/') - break; - info->full.size--; - } - info->full.ptr[info->full.size] = '\0'; - - /* skip leading slashes in path */ - while (*info->path == '/') - info->path++; - - /* find trailing basename component */ - info->basename = strrchr(info->path, '/'); - if (info->basename) - info->basename++; - if (!info->basename || !*info->basename) - info->basename = info->path; - - switch (dir_flag) - { - case GIT_DIR_FLAG_FALSE: - info->is_dir = 0; - break; - - case GIT_DIR_FLAG_TRUE: - info->is_dir = 1; - break; - - case GIT_DIR_FLAG_UNKNOWN: - default: - info->is_dir = (int)git_fs_path_isdir(info->full.ptr); - break; - } - - return 0; -} - -void git_attr_path__free(git_attr_path *info) -{ - git_str_dispose(&info->full); - info->path = NULL; - info->basename = NULL; -} - -/* - * From gitattributes(5): - * - * Patterns have the following format: - * - * - A blank line matches no files, so it can serve as a separator for - * readability. - * - * - A line starting with # serves as a comment. - * - * - An optional prefix ! which negates the pattern; any matching file - * excluded by a previous pattern will become included again. If a negated - * pattern matches, this will override lower precedence patterns sources. - * - * - If the pattern ends with a slash, it is removed for the purpose of the - * following description, but it would only find a match with a directory. In - * other words, foo/ will match a directory foo and paths underneath it, but - * will not match a regular file or a symbolic link foo (this is consistent - * with the way how pathspec works in general in git). - * - * - If the pattern does not contain a slash /, git treats it as a shell glob - * pattern and checks for a match against the pathname without leading - * directories. - * - * - Otherwise, git treats the pattern as a shell glob suitable for consumption - * by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will - * not match a / in the pathname. For example, "Documentation/\*.html" matches - * "Documentation/git.html" but not "Documentation/ppc/ppc.html". A leading - * slash matches the beginning of the pathname; for example, "/\*.c" matches - * "cat-file.c" but not "mozilla-sha1/sha1.c". - */ - -/* - * Determine the length of trailing spaces. Escaped spaces do not count as - * trailing whitespace. - */ -static size_t trailing_space_length(const char *p, size_t len) -{ - size_t n, i; - for (n = len; n; n--) { - if (p[n-1] != ' ' && p[n-1] != '\t') - break; - - /* - * Count escape-characters before space. In case where it's an - * even number of escape characters, then the escape char itself - * is escaped and the whitespace is an unescaped whitespace. - * Otherwise, the last escape char is not escaped and the - * whitespace in an escaped whitespace. - */ - i = n; - while (i > 1 && p[i-2] == '\\') - i--; - if ((n - i) % 2) - break; - } - return len - n; -} - -static size_t unescape_spaces(char *str) -{ - char *scan, *pos = str; - bool escaped = false; - - if (!str) - return 0; - - for (scan = str; *scan; scan++) { - if (!escaped && *scan == '\\') { - escaped = true; - continue; - } - - /* Only insert the escape character for escaped non-spaces */ - if (escaped && !git__isspace(*scan)) - *pos++ = '\\'; - - *pos++ = *scan; - escaped = false; - } - - if (pos != scan) - *pos = '\0'; - - return (pos - str); -} - -/* - * This will return 0 if the spec was filled out, - * GIT_ENOTFOUND if the fnmatch does not require matching, or - * another error code there was an actual problem. - */ -int git_attr_fnmatch__parse( - git_attr_fnmatch *spec, - git_pool *pool, - const char *context, - const char **base) -{ - const char *pattern, *scan; - int slash_count, allow_space; - bool escaped; - - GIT_ASSERT_ARG(spec); - GIT_ASSERT_ARG(base && *base); - - if (parse_optimized_patterns(spec, pool, *base)) - return 0; - - spec->flags = (spec->flags & GIT_ATTR_FNMATCH__INCOMING); - allow_space = ((spec->flags & GIT_ATTR_FNMATCH_ALLOWSPACE) != 0); - - pattern = *base; - - while (!allow_space && git__isspace(*pattern)) - pattern++; - - if (!*pattern || *pattern == '#' || *pattern == '\n' || - (*pattern == '\r' && *(pattern + 1) == '\n')) { - *base = git__next_line(pattern); - return GIT_ENOTFOUND; - } - - if (*pattern == '[' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWMACRO) != 0) { - if (strncmp(pattern, "[attr]", 6) == 0) { - spec->flags = spec->flags | GIT_ATTR_FNMATCH_MACRO; - pattern += 6; - } - /* else a character range like [a-e]* which is accepted */ - } - - if (*pattern == '!' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWNEG) != 0) { - spec->flags = spec->flags | GIT_ATTR_FNMATCH_NEGATIVE; - pattern++; - } - - slash_count = 0; - escaped = false; - /* Scan until a non-escaped whitespace. */ - for (scan = pattern; *scan != '\0'; ++scan) { - char c = *scan; - - if (c == '\\' && !escaped) { - escaped = true; - continue; - } else if (git__isspace(c) && !escaped) { - if (!allow_space || (c != ' ' && c != '\t' && c != '\r')) - break; - } else if (c == '/') { - spec->flags = spec->flags | GIT_ATTR_FNMATCH_FULLPATH; - slash_count++; - - if (slash_count == 1 && pattern == scan) - pattern++; - } else if (git__iswildcard(c) && !escaped) { - /* remember if we see an unescaped wildcard in pattern */ - spec->flags = spec->flags | GIT_ATTR_FNMATCH_HASWILD; - } - - escaped = false; - } - - *base = scan; - - if ((spec->length = scan - pattern) == 0) - return GIT_ENOTFOUND; - - /* - * Remove one trailing \r in case this is a CRLF delimited - * file, in the case of Icon\r\r\n, we still leave the first - * \r there to match against. - */ - if (pattern[spec->length - 1] == '\r') - if (--spec->length == 0) - return GIT_ENOTFOUND; - - /* Remove trailing spaces. */ - spec->length -= trailing_space_length(pattern, spec->length); - - if (spec->length == 0) - return GIT_ENOTFOUND; - - if (pattern[spec->length - 1] == '/') { - spec->length--; - spec->flags = spec->flags | GIT_ATTR_FNMATCH_DIRECTORY; - if (--slash_count <= 0) - spec->flags = spec->flags & ~GIT_ATTR_FNMATCH_FULLPATH; - } - - if (context) { - const char *slash = strrchr(context, '/'); - size_t len; - if (slash) { - /* include the slash for easier matching */ - len = slash - context + 1; - spec->containing_dir = git_pool_strndup(pool, context, len); - spec->containing_dir_length = len; - } - } - - spec->pattern = git_pool_strndup(pool, pattern, spec->length); - - if (!spec->pattern) { - *base = git__next_line(pattern); - return -1; - } else { - /* strip '\' that might have been used for internal whitespace */ - spec->length = unescape_spaces(spec->pattern); - } - - return 0; -} - -static bool parse_optimized_patterns( - git_attr_fnmatch *spec, - git_pool *pool, - const char *pattern) -{ - if (!pattern[1] && (pattern[0] == '*' || pattern[0] == '.')) { - spec->flags = GIT_ATTR_FNMATCH_MATCH_ALL; - spec->pattern = git_pool_strndup(pool, pattern, 1); - spec->length = 1; - - return true; - } - - return false; -} - -static int sort_by_hash_and_name(const void *a_raw, const void *b_raw) -{ - const git_attr_name *a = a_raw; - const git_attr_name *b = b_raw; - - if (b->name_hash < a->name_hash) - return 1; - else if (b->name_hash > a->name_hash) - return -1; - else - return strcmp(b->name, a->name); -} - -static void git_attr_assignment__free(git_attr_assignment *assign) -{ - /* name and value are stored in a git_pool associated with the - * git_attr_file, so they do not need to be freed here - */ - assign->name = NULL; - assign->value = NULL; - git__free(assign); -} - -static int merge_assignments(void **old_raw, void *new_raw) -{ - git_attr_assignment **old = (git_attr_assignment **)old_raw; - git_attr_assignment *new = (git_attr_assignment *)new_raw; - - GIT_REFCOUNT_DEC(*old, git_attr_assignment__free); - *old = new; - return GIT_EEXISTS; -} - -int git_attr_assignment__parse( - git_repository *repo, - git_pool *pool, - git_vector *assigns, - const char **base) -{ - int error; - const char *scan = *base; - git_attr_assignment *assign = NULL; - - GIT_ASSERT_ARG(assigns && !assigns->length); - - git_vector_set_cmp(assigns, sort_by_hash_and_name); - - while (*scan && *scan != '\n') { - const char *name_start, *value_start; - - /* skip leading blanks */ - while (git__isspace(*scan) && *scan != '\n') scan++; - - /* allocate assign if needed */ - if (!assign) { - assign = git__calloc(1, sizeof(git_attr_assignment)); - GIT_ERROR_CHECK_ALLOC(assign); - GIT_REFCOUNT_INC(assign); - } - - assign->name_hash = 5381; - assign->value = git_attr__true; - - /* look for magic name prefixes */ - if (*scan == '-') { - assign->value = git_attr__false; - scan++; - } else if (*scan == '!') { - assign->value = git_attr__unset; /* explicit unspecified state */ - scan++; - } else if (*scan == '#') /* comment rest of line */ - break; - - /* find the name */ - name_start = scan; - while (*scan && !git__isspace(*scan) && *scan != '=') { - assign->name_hash = - ((assign->name_hash << 5) + assign->name_hash) + *scan; - scan++; - } - if (scan == name_start) { - /* must have found lone prefix (" - ") or leading = ("=foo") - * or end of buffer -- advance until whitespace and continue - */ - while (*scan && !git__isspace(*scan)) scan++; - continue; - } - - /* allocate permanent storage for name */ - assign->name = git_pool_strndup(pool, name_start, scan - name_start); - GIT_ERROR_CHECK_ALLOC(assign->name); - - /* if there is an equals sign, find the value */ - if (*scan == '=') { - for (value_start = ++scan; *scan && !git__isspace(*scan); ++scan); - - /* if we found a value, allocate permanent storage for it */ - if (scan > value_start) { - assign->value = git_pool_strndup(pool, value_start, scan - value_start); - GIT_ERROR_CHECK_ALLOC(assign->value); - } - } - - /* expand macros (if given a repo with a macro cache) */ - if (repo != NULL && assign->value == git_attr__true) { - git_attr_rule *macro = - git_attr_cache__lookup_macro(repo, assign->name); - - if (macro != NULL) { - unsigned int i; - git_attr_assignment *massign; - - git_vector_foreach(¯o->assigns, i, massign) { - GIT_REFCOUNT_INC(massign); - - error = git_vector_insert_sorted( - assigns, massign, &merge_assignments); - if (error < 0 && error != GIT_EEXISTS) { - git_attr_assignment__free(assign); - return error; - } - } - } - } - - /* insert allocated assign into vector */ - error = git_vector_insert_sorted(assigns, assign, &merge_assignments); - if (error < 0 && error != GIT_EEXISTS) - return error; - - /* clear assign since it is now "owned" by the vector */ - assign = NULL; - } - - if (assign != NULL) - git_attr_assignment__free(assign); - - *base = git__next_line(scan); - - return (assigns->length == 0) ? GIT_ENOTFOUND : 0; -} - -static void git_attr_rule__clear(git_attr_rule *rule) -{ - unsigned int i; - git_attr_assignment *assign; - - if (!rule) - return; - - if (!(rule->match.flags & GIT_ATTR_FNMATCH_IGNORE)) { - git_vector_foreach(&rule->assigns, i, assign) - GIT_REFCOUNT_DEC(assign, git_attr_assignment__free); - git_vector_dispose(&rule->assigns); - } - - /* match.pattern is stored in a git_pool, so no need to free */ - rule->match.pattern = NULL; - rule->match.length = 0; -} - -void git_attr_rule__free(git_attr_rule *rule) -{ - git_attr_rule__clear(rule); - git__free(rule); -} - -int git_attr_session__init(git_attr_session *session, git_repository *repo) -{ - GIT_ASSERT_ARG(repo); - - memset(session, 0, sizeof(*session)); - session->key = git_atomic32_inc(&repo->attr_session_key); - - return 0; -} - -void git_attr_session__free(git_attr_session *session) -{ - if (!session) - return; - - git_str_dispose(&session->sysdir); - git_str_dispose(&session->tmp); - - memset(session, 0, sizeof(git_attr_session)); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/attr_file.h b/vendor/libgit2-sys/libgit2/src/libgit2/attr_file.h deleted file mode 100644 index 8025359..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/attr_file.h +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_attr_file_h__ -#define INCLUDE_attr_file_h__ - -#include "common.h" - -#include "git2/oid.h" -#include "git2/attr.h" -#include "vector.h" -#include "pool.h" -#include "str.h" -#include "futils.h" - -#define GIT_ATTR_FILE ".gitattributes" -#define GIT_ATTR_FILE_INREPO "attributes" -#define GIT_ATTR_FILE_SYSTEM "gitattributes" -#define GIT_ATTR_FILE_XDG "attributes" - -#define GIT_ATTR_MAX_FILE_SIZE 100 * 1024 * 1024 - -#define GIT_ATTR_FNMATCH_NEGATIVE (1U << 0) -#define GIT_ATTR_FNMATCH_DIRECTORY (1U << 1) -#define GIT_ATTR_FNMATCH_FULLPATH (1U << 2) -#define GIT_ATTR_FNMATCH_MACRO (1U << 3) -#define GIT_ATTR_FNMATCH_IGNORE (1U << 4) -#define GIT_ATTR_FNMATCH_HASWILD (1U << 5) -#define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6) -#define GIT_ATTR_FNMATCH_ICASE (1U << 7) -#define GIT_ATTR_FNMATCH_MATCH_ALL (1U << 8) -#define GIT_ATTR_FNMATCH_ALLOWNEG (1U << 9) -#define GIT_ATTR_FNMATCH_ALLOWMACRO (1U << 10) - -#define GIT_ATTR_FNMATCH__INCOMING \ - (GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO) - -typedef enum { - GIT_ATTR_FILE_SOURCE_MEMORY = 0, - GIT_ATTR_FILE_SOURCE_FILE = 1, - GIT_ATTR_FILE_SOURCE_INDEX = 2, - GIT_ATTR_FILE_SOURCE_HEAD = 3, - GIT_ATTR_FILE_SOURCE_COMMIT = 4, - - GIT_ATTR_FILE_NUM_SOURCES = 5 -} git_attr_file_source_t; - -typedef struct { - /* The source location for the attribute file. */ - git_attr_file_source_t type; - - /* - * The filename of the attribute file to read (relative to the - * given base path). - */ - const char *base; - const char *filename; - - /* - * The commit ID when the given source type is a commit (or NULL - * for the repository's HEAD commit.) - */ - git_oid *commit_id; -} git_attr_file_source; - -extern const char *git_attr__true; -extern const char *git_attr__false; -extern const char *git_attr__unset; - -typedef struct { - char *pattern; - size_t length; - char *containing_dir; - size_t containing_dir_length; - unsigned int flags; -} git_attr_fnmatch; - -typedef struct { - git_attr_fnmatch match; - git_vector assigns; /* vector of */ -} git_attr_rule; - -typedef struct { - git_refcount unused; - const char *name; - uint32_t name_hash; -} git_attr_name; - -typedef struct { - git_refcount rc; /* for macros */ - char *name; - uint32_t name_hash; - const char *value; -} git_attr_assignment; - -typedef struct git_attr_file_entry git_attr_file_entry; - -typedef struct { - git_refcount rc; - git_mutex lock; - git_attr_file_entry *entry; - git_attr_file_source source; - git_vector rules; /* vector of or */ - git_pool pool; - unsigned int nonexistent:1; - int session_key; - union { - git_oid oid; - git_futils_filestamp stamp; - } cache_data; -} git_attr_file; - -struct git_attr_file_entry { - git_attr_file *file[GIT_ATTR_FILE_NUM_SOURCES]; - const char *path; /* points into fullpath */ - char fullpath[GIT_FLEX_ARRAY]; -}; - -typedef struct { - git_str full; - char *path; - char *basename; - int is_dir; -} git_attr_path; - -/* A git_attr_session can provide an "instance" of reading, to prevent cache - * invalidation during a single operation instance (like checkout). - */ - -typedef struct { - int key; - unsigned int init_setup:1, - init_sysdir:1; - git_str sysdir; - git_str tmp; -} git_attr_session; - -extern int git_attr_session__init(git_attr_session *attr_session, git_repository *repo); -extern void git_attr_session__free(git_attr_session *session); - -extern int git_attr_get_many_with_session( - const char **values_out, - git_repository *repo, - git_attr_session *attr_session, - git_attr_options *opts, - const char *path, - size_t num_attr, - const char **names); - -typedef int (*git_attr_file_parser)( - git_repository *repo, - git_attr_file *file, - const char *data, - bool allow_macros); - -/* - * git_attr_file API - */ - -int git_attr_file__new( - git_attr_file **out, - git_attr_file_entry *entry, - git_attr_file_source *source); - -void git_attr_file__free(git_attr_file *file); - -int git_attr_file__load( - git_attr_file **out, - git_repository *repo, - git_attr_session *attr_session, - git_attr_file_entry *ce, - git_attr_file_source *source, - git_attr_file_parser parser, - bool allow_macros); - -int git_attr_file__load_standalone( - git_attr_file **out, const char *path); - -int git_attr_file__out_of_date( - git_repository *repo, git_attr_session *session, git_attr_file *file, git_attr_file_source *source); - -int git_attr_file__parse_buffer( - git_repository *repo, git_attr_file *attrs, const char *data, bool allow_macros); - -int git_attr_file__clear_rules( - git_attr_file *file, bool need_lock); - -int git_attr_file__lookup_one( - git_attr_file *file, - git_attr_path *path, - const char *attr, - const char **value); - -/* loop over rules in file from bottom to top */ -#define git_attr_file__foreach_matching_rule(file, path, iter, rule) \ - git_vector_rforeach(&(file)->rules, (iter), (rule)) \ - if (git_attr_rule__match((rule), (path))) - -uint32_t git_attr_file__name_hash(const char *name); - - -/* - * other utilities - */ - -extern int git_attr_fnmatch__parse( - git_attr_fnmatch *spec, - git_pool *pool, - const char *source, - const char **base); - -extern bool git_attr_fnmatch__match( - git_attr_fnmatch *rule, - git_attr_path *path); - -extern void git_attr_rule__free(git_attr_rule *rule); - -extern bool git_attr_rule__match( - git_attr_rule *rule, - git_attr_path *path); - -extern git_attr_assignment *git_attr_rule__lookup_assignment( - git_attr_rule *rule, const char *name); - -typedef enum { GIT_DIR_FLAG_TRUE = 1, GIT_DIR_FLAG_FALSE = 0, GIT_DIR_FLAG_UNKNOWN = -1 } git_dir_flag; - -extern int git_attr_path__init( - git_attr_path *out, - const char *path, - const char *base, - git_dir_flag is_dir); -extern void git_attr_path__free(git_attr_path *info); - -extern int git_attr_assignment__parse( - git_repository *repo, /* needed to expand macros */ - git_pool *pool, - git_vector *assigns, - const char **scan); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/attrcache.c b/vendor/libgit2-sys/libgit2/src/libgit2/attrcache.c deleted file mode 100644 index 2a82214..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/attrcache.c +++ /dev/null @@ -1,514 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "attrcache.h" - -#include "repository.h" -#include "attr_file.h" -#include "config.h" -#include "sysdir.h" -#include "ignore.h" -#include "path.h" -#include "hashmap_str.h" - -GIT_HASHMAP_STR_SETUP(git_attr_cache_filemap, git_attr_file_entry *); -GIT_HASHMAP_STR_SETUP(git_attr_cache_macromap, git_attr_rule *); - -struct git_attr_cache { - char *cfg_attr_file; /* cached value of core.attributesfile */ - char *cfg_excl_file; /* cached value of core.excludesfile */ - - /* hash path to git_attr_file_entry records */ - git_attr_cache_filemap files; - /* hash name to git_attr_rule */ - git_attr_cache_macromap macros; - - git_mutex lock; - git_pool pool; -}; - -const char *git_attr_cache_attributesfile(git_attr_cache *cache) -{ - return cache->cfg_attr_file; -} - -const char *git_attr_cache_excludesfile(git_attr_cache *cache) -{ - return cache->cfg_excl_file; -} - -git_pool *git_attr_cache_pool(git_attr_cache *cache) -{ - return &cache->pool; -} - -GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache) -{ - GIT_UNUSED(cache); /* avoid warning if threading is off */ - - if (git_mutex_lock(&cache->lock) < 0) { - git_error_set(GIT_ERROR_OS, "unable to get attr cache lock"); - return -1; - } - return 0; -} - -GIT_INLINE(void) attr_cache_unlock(git_attr_cache *cache) -{ - GIT_UNUSED(cache); /* avoid warning if threading is off */ - git_mutex_unlock(&cache->lock); -} - -GIT_INLINE(git_attr_file_entry *) attr_cache_lookup_entry( - git_attr_cache *cache, const char *path) -{ - git_attr_file_entry *result; - - if (git_attr_cache_filemap_get(&result, &cache->files, path) == 0) - return result; - - return NULL; -} - -int git_attr_cache__alloc_file_entry( - git_attr_file_entry **out, - git_repository *repo, - const char *base, - const char *path, - git_pool *pool) -{ - git_str fullpath_str = GIT_STR_INIT; - size_t baselen = 0, pathlen = strlen(path); - size_t cachesize = sizeof(git_attr_file_entry) + pathlen + 1; - git_attr_file_entry *ce; - - if (base != NULL && git_fs_path_root(path) < 0) { - baselen = strlen(base); - cachesize += baselen; - - if (baselen && base[baselen - 1] != '/') - cachesize++; - } - - ce = git_pool_mallocz(pool, cachesize); - GIT_ERROR_CHECK_ALLOC(ce); - - if (baselen) { - memcpy(ce->fullpath, base, baselen); - - if (base[baselen - 1] != '/') - ce->fullpath[baselen++] = '/'; - } - memcpy(&ce->fullpath[baselen], path, pathlen); - - fullpath_str.ptr = ce->fullpath; - fullpath_str.size = pathlen + baselen; - - if (git_path_validate_str_length(repo, &fullpath_str) < 0) - return -1; - - ce->path = &ce->fullpath[baselen]; - *out = ce; - - return 0; -} - -/* call with attrcache locked */ -static int attr_cache_make_entry( - git_attr_file_entry **out, git_repository *repo, const char *path) -{ - git_attr_cache *cache = git_repository_attr_cache(repo); - git_attr_file_entry *entry = NULL; - int error; - - if ((error = git_attr_cache__alloc_file_entry(&entry, repo, - git_repository_workdir(repo), path, &cache->pool)) < 0) - return error; - - if ((error = git_attr_cache_filemap_put(&cache->files, entry->path, entry)) < 0) - return error; - - *out = entry; - return error; -} - -/* insert entry or replace existing if we raced with another thread */ -static int attr_cache_upsert(git_attr_cache *cache, git_attr_file *file) -{ - git_attr_file_entry *entry; - git_attr_file *old; - - if (attr_cache_lock(cache) < 0) - return -1; - - entry = attr_cache_lookup_entry(cache, file->entry->path); - - GIT_REFCOUNT_OWN(file, entry); - GIT_REFCOUNT_INC(file); - - /* - * Replace the existing value if another thread has - * created it in the meantime. - */ - old = git_atomic_swap(entry->file[file->source.type], file); - - if (old) { - GIT_REFCOUNT_OWN(old, NULL); - git_attr_file__free(old); - } - - attr_cache_unlock(cache); - return 0; -} - -static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file) -{ - int error = 0; - git_attr_file_entry *entry; - git_attr_file *oldfile = NULL; - - if (!file) - return 0; - - if ((error = attr_cache_lock(cache)) < 0) - return error; - - if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL) - oldfile = git_atomic_compare_and_swap(&entry->file[file->source.type], file, NULL); - - attr_cache_unlock(cache); - - if (oldfile == file) { - GIT_REFCOUNT_OWN(file, NULL); - git_attr_file__free(file); - } - - return error; -} - -/* Look up cache entry and file. - * - If entry is not present, create it while the cache is locked. - * - If file is present, increment refcount before returning it, so the - * cache can be unlocked and it won't go away. - */ -static int attr_cache_lookup( - git_attr_file **out_file, - git_attr_file_entry **out_entry, - git_repository *repo, - git_attr_session *attr_session, - git_attr_file_source *source) -{ - int error = 0; - git_str path = GIT_STR_INIT; - const char *wd = git_repository_workdir(repo); - const char *filename; - git_attr_cache *cache = git_repository_attr_cache(repo); - git_attr_file_entry *entry = NULL; - git_attr_file *file = NULL; - - /* join base and path as needed */ - if (source->base != NULL && git_fs_path_root(source->filename) < 0) { - git_str *p = attr_session ? &attr_session->tmp : &path; - - if (git_str_joinpath(p, source->base, source->filename) < 0 || - git_path_validate_str_length(repo, p) < 0) - return -1; - - filename = p->ptr; - } else { - filename = source->filename; - } - - if (wd && !git__prefixcmp(filename, wd)) - filename += strlen(wd); - - /* check cache for existing entry */ - if ((error = attr_cache_lock(cache)) < 0) - goto cleanup; - - entry = attr_cache_lookup_entry(cache, filename); - - if (!entry) { - error = attr_cache_make_entry(&entry, repo, filename); - } else if (entry->file[source->type] != NULL) { - file = entry->file[source->type]; - GIT_REFCOUNT_INC(file); - } - - attr_cache_unlock(cache); - -cleanup: - *out_file = file; - *out_entry = entry; - - git_str_dispose(&path); - return error; -} - -int git_attr_cache__get( - git_attr_file **out, - git_repository *repo, - git_attr_session *attr_session, - git_attr_file_source *source, - git_attr_file_parser parser, - bool allow_macros) -{ - int error = 0; - git_attr_cache *cache = git_repository_attr_cache(repo); - git_attr_file_entry *entry = NULL; - git_attr_file *file = NULL, *updated = NULL; - - if ((error = attr_cache_lookup(&file, &entry, repo, attr_session, source)) < 0) - return error; - - /* load file if we don't have one or if existing one is out of date */ - if (!file || - (error = git_attr_file__out_of_date(repo, attr_session, file, source)) > 0) - error = git_attr_file__load(&updated, repo, attr_session, - entry, source, parser, - allow_macros); - - /* if we loaded the file, insert into and/or update cache */ - if (updated) { - if ((error = attr_cache_upsert(cache, updated)) < 0) { - git_attr_file__free(updated); - } else { - git_attr_file__free(file); /* offset incref from lookup */ - file = updated; - } - } - - /* if file could not be loaded */ - if (error < 0) { - /* remove existing entry */ - if (file) { - attr_cache_remove(cache, file); - git_attr_file__free(file); /* offset incref from lookup */ - file = NULL; - } - /* no error if file simply doesn't exist */ - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - } - - *out = file; - return error; -} - -bool git_attr_cache__is_cached( - git_repository *repo, - git_attr_file_source_t source_type, - const char *filename) -{ - git_attr_cache *cache = git_repository_attr_cache(repo); - git_attr_file_entry *entry; - - if (!cache) - return false; - - if (git_attr_cache_filemap_get(&entry, &cache->files, filename) != 0) - return false; - - return entry && (entry->file[source_type] != NULL); -} - - -static int attr_cache__lookup_path( - char **out, git_config *cfg, const char *key, const char *fallback) -{ - git_str buf = GIT_STR_INIT; - int error; - git_config_entry *entry = NULL; - - *out = NULL; - - if ((error = git_config__lookup_entry(&entry, cfg, key, false)) < 0) - return error; - - if (entry) { - const char *cfgval = entry->value; - - /* expand leading ~/ as needed */ - if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') { - if (! (error = git_sysdir_expand_homedir_file(&buf, &cfgval[2]))) - *out = git_str_detach(&buf); - } else if (cfgval) { - *out = git__strdup(cfgval); - } - } - else if (!git_sysdir_find_xdg_file(&buf, fallback)) { - *out = git_str_detach(&buf); - } - - git_config_entry_free(entry); - git_str_dispose(&buf); - - return error; -} - -static void attr_cache__free(git_attr_cache *cache) -{ - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - git_attr_rule *rule; - git_attr_file_entry *entry; - bool unlock; - - if (!cache) - return; - - unlock = (attr_cache_lock(cache) == 0); - - while (git_attr_cache_filemap_iterate(&iter, NULL, &entry, &cache->files) == 0) { - git_attr_file *file; - size_t i; - - for (i = 0; i < GIT_ATTR_FILE_NUM_SOURCES; i++) { - if ((file = git_atomic_swap(entry->file[i], NULL)) != NULL) { - GIT_REFCOUNT_OWN(file, NULL); - git_attr_file__free(file); - } - } - } - - iter = GIT_HASHMAP_ITER_INIT; - while (git_attr_cache_macromap_iterate(&iter, NULL, &rule, &cache->macros) == 0) - git_attr_rule__free(rule); - - git_attr_cache_filemap_dispose(&cache->files); - git_attr_cache_macromap_dispose(&cache->macros); - - git_pool_clear(&cache->pool); - - git__free(cache->cfg_attr_file); - cache->cfg_attr_file = NULL; - - git__free(cache->cfg_excl_file); - cache->cfg_excl_file = NULL; - - if (unlock) - attr_cache_unlock(cache); - git_mutex_free(&cache->lock); - - git__free(cache); -} - -int git_attr_cache__init(git_repository *repo) -{ - int ret = 0; - git_attr_cache *cache = git_repository_attr_cache(repo); - git_config *cfg = NULL; - - if (cache) - return 0; - - cache = git__calloc(1, sizeof(git_attr_cache)); - GIT_ERROR_CHECK_ALLOC(cache); - - /* set up lock */ - if (git_mutex_init(&cache->lock) < 0) { - git_error_set(GIT_ERROR_OS, "unable to initialize lock for attr cache"); - git__free(cache); - return -1; - } - - if ((ret = git_repository_config_snapshot(&cfg, repo)) < 0) - goto cancel; - - /* cache config settings for attributes and ignores */ - ret = attr_cache__lookup_path( - &cache->cfg_attr_file, cfg, GIT_ATTR_CONFIG, GIT_ATTR_FILE_XDG); - if (ret < 0) - goto cancel; - - ret = attr_cache__lookup_path( - &cache->cfg_excl_file, cfg, GIT_IGNORE_CONFIG, GIT_IGNORE_FILE_XDG); - if (ret < 0) - goto cancel; - - /* allocate hashtable for attribute and ignore file contents, - * hashtable for attribute macros, and string pool - */ - if ((ret = git_pool_init(&cache->pool, 1)) < 0) - goto cancel; - - if (git_atomic_compare_and_swap(&repo->attrcache, NULL, cache) != NULL) - goto cancel; /* raced with another thread, free this but no error */ - - git_config_free(cfg); - - /* insert default macros */ - return git_attr_add_macro(repo, "binary", "-diff -merge -text -crlf"); - -cancel: - attr_cache__free(cache); - git_config_free(cfg); - return ret; -} - -int git_attr_cache_flush(git_repository *repo) -{ - git_attr_cache *cache; - - /* this could be done less expensively, but for now, we'll just free - * the entire attrcache and let the next use reinitialize it... - */ - if (repo && (cache = git_atomic_swap(repo->attrcache, NULL)) != NULL) - attr_cache__free(cache); - - return 0; -} - -int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro) -{ - git_attr_cache *cache = git_repository_attr_cache(repo); - git_attr_rule *preexisting; - bool locked = false; - int error = 0; - - /* - * Callers assume that if we return success, that the - * macro will have been adopted by the attributes cache. - * Thus, we have to free the macro here if it's not being - * added to the cache. - * - * TODO: generate warning log if (macro->assigns.length == 0) - */ - if (macro->assigns.length == 0) { - git_attr_rule__free(macro); - goto out; - } - - if ((error = attr_cache_lock(cache)) < 0) - goto out; - locked = true; - - if (git_attr_cache_macromap_get(&preexisting, &cache->macros, macro->match.pattern) == 0) - git_attr_rule__free(preexisting); - - if ((error = git_attr_cache_macromap_put(&cache->macros, macro->match.pattern, macro)) < 0) - goto out; - -out: - if (locked) - attr_cache_unlock(cache); - return error; -} - -git_attr_rule *git_attr_cache__lookup_macro( - git_repository *repo, const char *name) -{ - git_attr_cache *cache = git_repository_attr_cache(repo); - git_attr_rule *rule; - - if (!cache || - git_attr_cache_macromap_get(&rule, &cache->macros, name) != 0) - return NULL; - - return rule; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/attrcache.h b/vendor/libgit2-sys/libgit2/src/libgit2/attrcache.h deleted file mode 100644 index 2693278..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/attrcache.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_attrcache_h__ -#define INCLUDE_attrcache_h__ - -#include "common.h" - -#include "attr_file.h" - -#define GIT_ATTR_CONFIG "core.attributesfile" -#define GIT_IGNORE_CONFIG "core.excludesfile" - -typedef struct git_attr_cache git_attr_cache; - -extern int git_attr_cache__init(git_repository *repo); - -extern const char *git_attr_cache_attributesfile(git_attr_cache *ac); -extern const char *git_attr_cache_excludesfile(git_attr_cache *ac); -extern git_pool *git_attr_cache_pool(git_attr_cache *ac); - -/* get file - loading and reload as needed */ -extern int git_attr_cache__get( - git_attr_file **file, - git_repository *repo, - git_attr_session *attr_session, - git_attr_file_source *source, - git_attr_file_parser parser, - bool allow_macros); - -extern bool git_attr_cache__is_cached( - git_repository *repo, - git_attr_file_source_t source_type, - const char *filename); - -extern int git_attr_cache__alloc_file_entry( - git_attr_file_entry **out, - git_repository *repo, - const char *base, - const char *path, - git_pool *pool); - -extern int git_attr_cache__insert_macro( - git_repository *repo, git_attr_rule *macro); - -extern git_attr_rule *git_attr_cache__lookup_macro( - git_repository *repo, const char *name); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/blame.c b/vendor/libgit2-sys/libgit2/src/libgit2/blame.c deleted file mode 100644 index e31b9d5..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/blame.c +++ /dev/null @@ -1,658 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "blame.h" - -#include "git2/commit.h" -#include "git2/revparse.h" -#include "git2/revwalk.h" -#include "git2/tree.h" -#include "git2/diff.h" -#include "git2/blob.h" -#include "git2/signature.h" -#include "git2/mailmap.h" -#include "util.h" -#include "repository.h" -#include "blame_git.h" - -static int hunk_byfinalline_search_cmp(const void *key, const void *entry) -{ - git_blame_hunk *hunk = (git_blame_hunk*)entry; - - size_t lineno = *(size_t*)key; - size_t lines_in_hunk = hunk->lines_in_hunk; - size_t final_start_line_number = hunk->final_start_line_number; - - if (lineno < final_start_line_number) - return -1; - if (lineno >= final_start_line_number + lines_in_hunk) - return 1; - return 0; -} - -static int paths_cmp(const void *a, const void *b) { return git__strcmp((char*)a, (char*)b); } -static int hunk_cmp(const void *_a, const void *_b) -{ - git_blame_hunk *a = (git_blame_hunk*)_a, - *b = (git_blame_hunk*)_b; - - if (a->final_start_line_number > b->final_start_line_number) - return 1; - else if (a->final_start_line_number < b->final_start_line_number) - return -1; - else - return 0; -} - -static bool hunk_ends_at_or_before_line(git_blame_hunk *hunk, size_t line) -{ - return line >= (hunk->final_start_line_number + hunk->lines_in_hunk - 1); -} - -static bool hunk_starts_at_or_after_line(git_blame_hunk *hunk, size_t line) -{ - return line <= hunk->final_start_line_number; -} - -static git_blame_hunk *new_hunk( - size_t start, - size_t lines, - size_t orig_start, - const char *path, - git_blame *blame) -{ - git_blame_hunk *hunk = git__calloc(1, sizeof(git_blame_hunk)); - if (!hunk) return NULL; - - hunk->lines_in_hunk = lines; - hunk->final_start_line_number = start; - hunk->orig_start_line_number = orig_start; - hunk->orig_path = path ? git__strdup(path) : NULL; - git_oid_clear(&hunk->orig_commit_id, blame->repository->oid_type); - git_oid_clear(&hunk->final_commit_id, blame->repository->oid_type); - - return hunk; -} - -static void free_hunk(git_blame_hunk *hunk) -{ - git__free((char *)hunk->orig_path); - git__free((char *)hunk->summary); - git_signature_free(hunk->final_signature); - git_signature_free(hunk->final_committer); - git_signature_free(hunk->orig_signature); - git_signature_free(hunk->orig_committer); - git__free(hunk); -} - -static git_blame_hunk *dup_hunk(git_blame_hunk *hunk, git_blame *blame) -{ - git_blame_hunk *newhunk = new_hunk( - hunk->final_start_line_number, - hunk->lines_in_hunk, - hunk->orig_start_line_number, - hunk->orig_path, - blame); - - if (!newhunk) - return NULL; - - git_oid_cpy(&newhunk->orig_commit_id, &hunk->orig_commit_id); - git_oid_cpy(&newhunk->final_commit_id, &hunk->final_commit_id); - newhunk->boundary = hunk->boundary; - - if (git_signature_dup(&newhunk->final_signature, hunk->final_signature) < 0 || - git_signature_dup(&newhunk->final_committer, hunk->final_committer) < 0 || - git_signature_dup(&newhunk->orig_signature, hunk->orig_signature) < 0 || - git_signature_dup(&newhunk->orig_committer, hunk->orig_committer) < 0 || - (newhunk->summary = git__strdup(hunk->summary)) == NULL) { - free_hunk(newhunk); - return NULL; - } - - return newhunk; -} - -/* Starting with the hunk that includes start_line, shift all following hunks' - * final_start_line by shift_by lines */ -static void shift_hunks_by(git_vector *v, size_t start_line, int shift_by) -{ - size_t i; - for (i = 0; i < v->length; i++) { - git_blame_hunk *hunk = (git_blame_hunk*)v->contents[i]; - if(hunk->final_start_line_number < start_line){ - continue; - } - hunk->final_start_line_number += shift_by; - } -} - -git_blame *git_blame__alloc( - git_repository *repo, - git_blame_options opts, - const char *path) -{ - git_blame *gbr = git__calloc(1, sizeof(git_blame)); - if (!gbr) - return NULL; - - gbr->repository = repo; - gbr->options = opts; - - if (git_vector_init(&gbr->hunks, 8, hunk_cmp) < 0 || - git_vector_init(&gbr->paths, 8, paths_cmp) < 0 || - (gbr->path = git__strdup(path)) == NULL || - git_vector_insert(&gbr->paths, git__strdup(path)) < 0) { - git_blame_free(gbr); - return NULL; - } - - if (opts.flags & GIT_BLAME_USE_MAILMAP && - git_mailmap_from_repository(&gbr->mailmap, repo) < 0) { - git_blame_free(gbr); - return NULL; - } - - return gbr; -} - -void git_blame_free(git_blame *blame) -{ - size_t i; - git_blame_hunk *hunk; - - if (!blame) return; - - git_vector_foreach(&blame->hunks, i, hunk) - free_hunk(hunk); - - git_vector_dispose(&blame->hunks); - git_array_clear(blame->lines); - - git_vector_dispose_deep(&blame->paths); - - git_array_clear(blame->line_index); - - git_mailmap_free(blame->mailmap); - - git__free(blame->path); - git_blob_free(blame->final_blob); - git__free(blame); -} - -size_t git_blame_hunkcount(git_blame *blame) -{ - GIT_ASSERT_ARG(blame); - - return blame->hunks.length; -} - -size_t git_blame_linecount(git_blame *blame) -{ - GIT_ASSERT_ARG(blame); - - return git_array_size(blame->line_index); -} - -const git_blame_line *git_blame_line_byindex( - git_blame *blame, - size_t idx) -{ - GIT_ASSERT_ARG_WITH_RETVAL(blame, NULL); - GIT_ASSERT_WITH_RETVAL(idx > 0 && idx <= git_array_size(blame->line_index), NULL); - - return git_array_get(blame->lines, idx - 1); -} - -const git_blame_hunk *git_blame_hunk_byindex( - git_blame *blame, - size_t index) -{ - GIT_ASSERT_ARG_WITH_RETVAL(blame, NULL); - return git_vector_get(&blame->hunks, index); -} - -const git_blame_hunk *git_blame_hunk_byline( - git_blame *blame, - size_t lineno) -{ - size_t i, new_lineno = lineno; - - GIT_ASSERT_ARG_WITH_RETVAL(blame, NULL); - - if (git_vector_bsearch2(&i, &blame->hunks, - hunk_byfinalline_search_cmp, &new_lineno) != 0) - return NULL; - - return git_blame_hunk_byindex(blame, i); -} - -#ifndef GIT_DEPRECATE_HARD -uint32_t git_blame_get_hunk_count(git_blame *blame) -{ - size_t count = git_blame_hunkcount(blame); - GIT_ASSERT(count < UINT32_MAX); - return (uint32_t)count; -} - -const git_blame_hunk *git_blame_get_hunk_byindex( - git_blame *blame, - uint32_t index) -{ - return git_blame_hunk_byindex(blame, index); -} - -const git_blame_hunk *git_blame_get_hunk_byline( - git_blame *blame, - size_t lineno) -{ - return git_blame_hunk_byline(blame, lineno); -} -#endif - -static int normalize_options( - git_blame_options *out, - const git_blame_options *in, - git_repository *repo) -{ - git_blame_options dummy = GIT_BLAME_OPTIONS_INIT; - if (!in) in = &dummy; - - memcpy(out, in, sizeof(git_blame_options)); - - /* No newest_commit => HEAD */ - if (git_oid_is_zero(&out->newest_commit)) { - if (git_reference_name_to_id(&out->newest_commit, repo, "HEAD") < 0) { - return -1; - } - } - - /* min_line 0 really means 1 */ - if (!out->min_line) out->min_line = 1; - /* max_line 0 really means N, but we don't know N yet */ - - /* Fix up option implications */ - if (out->flags & GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES) - out->flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES; - if (out->flags & GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES) - out->flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES; - if (out->flags & GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES) - out->flags |= GIT_BLAME_TRACK_COPIES_SAME_FILE; - - return 0; -} - -static git_blame_hunk *split_hunk_in_vector( - git_vector *vec, - git_blame_hunk *hunk, - size_t rel_line, - bool return_new, - git_blame *blame) -{ - size_t new_line_count; - git_blame_hunk *nh; - - /* Don't split if already at a boundary */ - if (rel_line <= 0 || - rel_line >= hunk->lines_in_hunk) - { - return hunk; - } - - new_line_count = hunk->lines_in_hunk - rel_line; - nh = new_hunk(hunk->final_start_line_number + rel_line, - new_line_count, hunk->orig_start_line_number + rel_line, - hunk->orig_path, blame); - - if (!nh) - return NULL; - - git_oid_cpy(&nh->final_commit_id, &hunk->final_commit_id); - git_oid_cpy(&nh->orig_commit_id, &hunk->orig_commit_id); - - /* Adjust hunk that was split */ - hunk->lines_in_hunk -= new_line_count; - git_vector_insert_sorted(vec, nh, NULL); - { - git_blame_hunk *ret = return_new ? nh : hunk; - return ret; - } -} - -/* - * Construct a list of char indices for where lines begin - * Adapted from core git: - * https://github.com/gitster/git/blob/be5c9fb9049ed470e7005f159bb923a5f4de1309/builtin/blame.c#L1760-L1789 - */ -static int index_blob_lines(git_blame *blame) -{ - const char *buf = blame->final_buf; - size_t len = blame->final_buf_size; - int num = 0, incomplete = 0, bol = 1; - git_blame_line *line = NULL; - size_t *i; - - if (len && buf[len-1] != '\n') - incomplete++; /* incomplete line at the end */ - - while (len--) { - if (bol) { - i = git_array_alloc(blame->line_index); - GIT_ERROR_CHECK_ALLOC(i); - *i = buf - blame->final_buf; - - GIT_ASSERT(line == NULL); - line = git_array_alloc(blame->lines); - GIT_ERROR_CHECK_ALLOC(line); - - line->ptr = buf; - bol = 0; - } - - if (*buf++ == '\n') { - GIT_ASSERT(line); - line->len = (buf - line->ptr) - 1; - line = NULL; - - num++; - bol = 1; - } - } - - i = git_array_alloc(blame->line_index); - GIT_ERROR_CHECK_ALLOC(i); - *i = buf - blame->final_buf; - - if (!bol) { - GIT_ASSERT(line); - line->len = buf - line->ptr; - line = NULL; - } - - GIT_ASSERT(!line); - - blame->num_lines = num + incomplete; - return blame->num_lines; -} - -static git_blame_hunk *hunk_from_entry(git_blame__entry *e, git_blame *blame) -{ - const char *summary; - git_blame_hunk *h = new_hunk( - e->lno+1, e->num_lines, e->s_lno+1, e->suspect->path, - blame); - - if (!h) - return NULL; - - git_oid_cpy(&h->final_commit_id, git_commit_id(e->suspect->commit)); - git_oid_cpy(&h->orig_commit_id, git_commit_id(e->suspect->commit)); - - if (git_commit_author_with_mailmap( - &h->final_signature, e->suspect->commit, blame->mailmap) < 0 || - git_commit_committer_with_mailmap( - &h->final_committer, e->suspect->commit, blame->mailmap) < 0 || - git_signature_dup(&h->orig_signature, h->final_signature) < 0 || - git_signature_dup(&h->orig_committer, h->final_committer) < 0 || - (summary = git_commit_summary(e->suspect->commit)) == NULL || - (h->summary = git__strdup(summary)) == NULL) { - free_hunk(h); - return NULL; - } - - h->boundary = e->is_boundary ? 1 : 0; - return h; -} - -static int load_blob(git_blame *blame) -{ - int error; - - if (blame->final_blob) return 0; - - error = git_commit_lookup(&blame->final, blame->repository, &blame->options.newest_commit); - if (error < 0) - goto cleanup; - error = git_object_lookup_bypath((git_object**)&blame->final_blob, - (git_object*)blame->final, blame->path, GIT_OBJECT_BLOB); - -cleanup: - return error; -} - -static int blame_internal(git_blame *blame) -{ - int error; - git_blame__entry *ent = NULL; - git_blame__origin *o; - - if ((error = load_blob(blame)) < 0 || - (error = git_blame__get_origin(&o, blame, blame->final, blame->path)) < 0) - goto on_error; - - if (git_blob_rawsize(blame->final_blob) > SIZE_MAX) { - git_error_set(GIT_ERROR_NOMEMORY, "blob is too large to blame"); - error = -1; - goto on_error; - } - - blame->final_buf = git_blob_rawcontent(blame->final_blob); - blame->final_buf_size = (size_t)git_blob_rawsize(blame->final_blob); - - ent = git__calloc(1, sizeof(git_blame__entry)); - GIT_ERROR_CHECK_ALLOC(ent); - - ent->num_lines = index_blob_lines(blame); - ent->lno = blame->options.min_line - 1; - ent->num_lines = ent->num_lines - blame->options.min_line + 1; - if (blame->options.max_line > 0) - ent->num_lines = blame->options.max_line - blame->options.min_line + 1; - ent->s_lno = ent->lno; - ent->suspect = o; - - blame->ent = ent; - - if ((error = git_blame__like_git(blame, blame->options.flags)) < 0) - goto on_error; - - for (ent = blame->ent; ent; ent = ent->next) { - git_blame_hunk *h = hunk_from_entry(ent, blame); - - if (!h) { - error = -1; - goto on_error; - } - - git_vector_insert(&blame->hunks, h); - } - -on_error: - for (ent = blame->ent; ent; ) { - git_blame__entry *next = ent->next; - git_blame__free_entry(ent); - ent = next; - } - - return error; -} - -/******************************************************************************* - * File blaming - ******************************************************************************/ - -int git_blame_file( - git_blame **out, - git_repository *repo, - const char *path, - git_blame_options *options) -{ - int error = -1; - git_blame_options normOptions = GIT_BLAME_OPTIONS_INIT; - git_blame *blame = NULL; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(path); - - if ((error = normalize_options(&normOptions, options, repo)) < 0) - goto on_error; - - blame = git_blame__alloc(repo, normOptions, path); - GIT_ERROR_CHECK_ALLOC(blame); - - if ((error = load_blob(blame)) < 0) - goto on_error; - - if ((error = blame_internal(blame)) < 0) - goto on_error; - - *out = blame; - return 0; - -on_error: - git_blame_free(blame); - return error; -} - -/******************************************************************************* - * Buffer blaming - *******************************************************************************/ - -static bool hunk_is_bufferblame(git_blame_hunk *hunk) -{ - return hunk && git_oid_is_zero(&hunk->final_commit_id); -} - -static int buffer_hunk_cb( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - void *payload) -{ - git_blame *blame = (git_blame*)payload; - uint32_t wedge_line; - - GIT_UNUSED(delta); - - wedge_line = (hunk->new_start >= hunk->old_start || hunk->old_lines==0) ? hunk->new_start : hunk->old_start; - blame->current_diff_line = wedge_line; - blame->current_hunk = (git_blame_hunk*)git_blame_hunk_byline(blame, wedge_line); - if (!blame->current_hunk) { - /* Line added at the end of the file */ - blame->current_hunk = new_hunk(wedge_line, 0, wedge_line, - blame->path, blame); - blame->current_diff_line++; - GIT_ERROR_CHECK_ALLOC(blame->current_hunk); - git_vector_insert(&blame->hunks, blame->current_hunk); - } else if (!hunk_starts_at_or_after_line(blame->current_hunk, wedge_line)){ - /* If this hunk doesn't start between existing hunks, split a hunk up so it does */ - blame->current_hunk = split_hunk_in_vector(&blame->hunks, blame->current_hunk, - wedge_line - blame->current_hunk->final_start_line_number, true, - blame); - GIT_ERROR_CHECK_ALLOC(blame->current_hunk); - } - - return 0; -} - -static int ptrs_equal_cmp(const void *a, const void *b) { return ab ? 1 : 0; } -static int buffer_line_cb( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - const git_diff_line *line, - void *payload) -{ - git_blame *blame = (git_blame*)payload; - - GIT_UNUSED(delta); - GIT_UNUSED(hunk); - GIT_UNUSED(line); - - if (line->origin == GIT_DIFF_LINE_ADDITION) { - if (hunk_is_bufferblame(blame->current_hunk) && - hunk_ends_at_or_before_line(blame->current_hunk, blame->current_diff_line)) { - /* Append to the current buffer-blame hunk */ - blame->current_hunk->lines_in_hunk++; - shift_hunks_by(&blame->hunks, blame->current_diff_line, 1); - } else { - /* Create a new buffer-blame hunk with this line */ - shift_hunks_by(&blame->hunks, blame->current_diff_line, 1); - blame->current_hunk = new_hunk(blame->current_diff_line, 1, 0, blame->path, blame); - GIT_ERROR_CHECK_ALLOC(blame->current_hunk); - git_vector_insert_sorted(&blame->hunks, blame->current_hunk, NULL); - } - blame->current_diff_line++; - } - - if (line->origin == GIT_DIFF_LINE_DELETION) { - /* Trim the line from the current hunk; remove it if it's now empty */ - size_t shift_base = blame->current_diff_line + blame->current_hunk->lines_in_hunk; - - if (--(blame->current_hunk->lines_in_hunk) == 0) { - size_t i; - size_t i_next; - if (!git_vector_search2(&i, &blame->hunks, ptrs_equal_cmp, blame->current_hunk)) { - git_vector_remove(&blame->hunks, i); - free_hunk(blame->current_hunk); - i_next = min( i , blame->hunks.length -1); - blame->current_hunk = (git_blame_hunk*)git_blame_hunk_byindex(blame, (uint32_t)i_next); - } - } - shift_hunks_by(&blame->hunks, shift_base, -1); - } - return 0; -} - -int git_blame_buffer( - git_blame **out, - git_blame *reference, - const char *buffer, - size_t buffer_len) -{ - git_blame *blame; - git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT; - size_t i; - git_blame_hunk *hunk; - - diffopts.context_lines = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(reference); - GIT_ASSERT_ARG(buffer && buffer_len); - - blame = git_blame__alloc(reference->repository, reference->options, reference->path); - GIT_ERROR_CHECK_ALLOC(blame); - - /* Duplicate all of the hunk structures in the reference blame */ - git_vector_foreach(&reference->hunks, i, hunk) { - git_blame_hunk *h = dup_hunk(hunk, blame); - GIT_ERROR_CHECK_ALLOC(h); - - git_vector_insert(&blame->hunks, h); - } - - /* Diff to the reference blob */ - git_diff_blob_to_buffer(reference->final_blob, blame->path, - buffer, buffer_len, blame->path, &diffopts, - NULL, NULL, buffer_hunk_cb, buffer_line_cb, blame); - - *out = blame; - return 0; -} - -int git_blame_options_init(git_blame_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_blame_options, GIT_BLAME_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_blame_init_options(git_blame_options *opts, unsigned int version) -{ - return git_blame_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/blame.h b/vendor/libgit2-sys/libgit2/src/libgit2/blame.h deleted file mode 100644 index 152834e..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/blame.h +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef INCLUDE_blame_h__ -#define INCLUDE_blame_h__ - -#include "common.h" - -#include "git2/blame.h" -#include "vector.h" -#include "diff.h" -#include "array.h" -#include "git2/oid.h" - -/* - * One blob in a commit that is being suspected - */ -typedef struct git_blame__origin { - int refcnt; - struct git_blame__origin *previous; - git_commit *commit; - git_blob *blob; - char path[GIT_FLEX_ARRAY]; -} git_blame__origin; - -/* - * Each group of lines is described by a git_blame__entry; it can be split - * as we pass blame to the parents. They form a linked list in the - * scoreboard structure, sorted by the target line number. - */ -typedef struct git_blame__entry { - struct git_blame__entry *prev; - struct git_blame__entry *next; - - /* the first line of this group in the final image; - * internally all line numbers are 0 based. - */ - size_t lno; - - /* how many lines this group has */ - size_t num_lines; - - /* the commit that introduced this group into the final image */ - git_blame__origin *suspect; - - /* true if the suspect is truly guilty; false while we have not - * checked if the group came from one of its parents. - */ - bool guilty; - - /* true if the entry has been scanned for copies in the current parent - */ - bool scanned; - - /* the line number of the first line of this group in the - * suspect's file; internally all line numbers are 0 based. - */ - size_t s_lno; - - /* how significant this entry is -- cached to avoid - * scanning the lines over and over. - */ - unsigned score; - - /* Whether this entry has been tracked to a boundary commit. - */ - bool is_boundary; -} git_blame__entry; - -struct git_blame { - char *path; - git_repository *repository; - git_mailmap *mailmap; - git_blame_options options; - - git_vector hunks; - git_array_t(git_blame_line) lines; - git_vector paths; - - git_blob *final_blob; - git_array_t(size_t) line_index; - - size_t current_diff_line; - git_blame_hunk *current_hunk; - - /* Scoreboard fields */ - git_commit *final; - git_blame__entry *ent; - int num_lines; - const char *final_buf; - size_t final_buf_size; -}; - -git_blame *git_blame__alloc( - git_repository *repo, - git_blame_options opts, - const char *path); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/blame_git.c b/vendor/libgit2-sys/libgit2/src/libgit2/blame_git.c deleted file mode 100644 index 69897b3..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/blame_git.c +++ /dev/null @@ -1,684 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "blame_git.h" - -#include "commit.h" -#include "blob.h" -#include "diff_xdiff.h" - -/* - * Origin is refcounted and usually we keep the blob contents to be - * reused. - */ -static git_blame__origin *origin_incref(git_blame__origin *o) -{ - if (o) - o->refcnt++; - return o; -} - -static void origin_decref(git_blame__origin *o) -{ - if (o && --o->refcnt <= 0) { - if (o->previous) - origin_decref(o->previous); - git_blob_free(o->blob); - git_commit_free(o->commit); - git__free(o); - } -} - -/* Given a commit and a path in it, create a new origin structure. */ -static int make_origin(git_blame__origin **out, git_commit *commit, const char *path) -{ - git_blame__origin *o; - git_object *blob; - size_t path_len = strlen(path), alloc_len; - int error = 0; - - if ((error = git_object_lookup_bypath(&blob, (git_object*)commit, - path, GIT_OBJECT_BLOB)) < 0) - return error; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*o), path_len); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); - o = git__calloc(1, alloc_len); - GIT_ERROR_CHECK_ALLOC(o); - - o->commit = commit; - o->blob = (git_blob *) blob; - o->refcnt = 1; - strcpy(o->path, path); - - *out = o; - - return 0; -} - -/* Locate an existing origin or create a new one. */ -int git_blame__get_origin( - git_blame__origin **out, - git_blame *blame, - git_commit *commit, - const char *path) -{ - git_blame__entry *e; - - for (e = blame->ent; e; e = e->next) { - if (e->suspect->commit == commit && !strcmp(e->suspect->path, path)) { - *out = origin_incref(e->suspect); - } - } - return make_origin(out, commit, path); -} - -typedef struct blame_chunk_cb_data { - git_blame *blame; - git_blame__origin *target; - git_blame__origin *parent; - long tlno; - long plno; -}blame_chunk_cb_data; - -static bool same_suspect(git_blame__origin *a, git_blame__origin *b) -{ - if (a == b) - return true; - if (git_oid_cmp(git_commit_id(a->commit), git_commit_id(b->commit))) - return false; - return 0 == strcmp(a->path, b->path); -} - -/* find the line number of the last line the target is suspected for */ -static bool find_last_in_target(size_t *out, git_blame *blame, git_blame__origin *target) -{ - git_blame__entry *e; - size_t last_in_target = 0; - bool found = false; - - *out = 0; - - for (e=blame->ent; e; e=e->next) { - if (e->guilty || !same_suspect(e->suspect, target)) - continue; - if (last_in_target < e->s_lno + e->num_lines) { - found = true; - last_in_target = e->s_lno + e->num_lines; - } - } - - *out = last_in_target; - return found; -} - -/* - * It is known that lines between tlno to same came from parent, and e - * has an overlap with that range. it also is known that parent's - * line plno corresponds to e's line tlno. - * - * <---- e -----> - * <------> (entirely within) - * <------------> (extends past) - * <------------> (starts before) - * <------------------> (entirely encloses) - * - * Split e into potentially three parts; before this chunk, the chunk - * to be blamed for the parent, and after that portion. - */ -static void split_overlap(git_blame__entry *split, git_blame__entry *e, - size_t tlno, size_t plno, size_t same, git_blame__origin *parent) -{ - size_t chunk_end_lno; - - if (e->s_lno < tlno) { - /* there is a pre-chunk part not blamed on the parent */ - split[0].suspect = origin_incref(e->suspect); - split[0].lno = e->lno; - split[0].s_lno = e->s_lno; - split[0].num_lines = tlno - e->s_lno; - split[1].lno = e->lno + tlno - e->s_lno; - split[1].s_lno = plno; - } else { - split[1].lno = e->lno; - split[1].s_lno = plno + (e->s_lno - tlno); - } - - if (same < e->s_lno + e->num_lines) { - /* there is a post-chunk part not blamed on parent */ - split[2].suspect = origin_incref(e->suspect); - split[2].lno = e->lno + (same - e->s_lno); - split[2].s_lno = e->s_lno + (same - e->s_lno); - split[2].num_lines = e->s_lno + e->num_lines - same; - chunk_end_lno = split[2].lno; - } else { - chunk_end_lno = e->lno + e->num_lines; - } - split[1].num_lines = chunk_end_lno - split[1].lno; - - /* - * if it turns out there is nothing to blame the parent for, forget about - * the splitting. !split[1].suspect signals this. - */ - if (split[1].num_lines < 1) - return; - split[1].suspect = origin_incref(parent); -} - -/* - * Link in a new blame entry to the scoreboard. Entries that cover the same - * line range have been removed from the scoreboard previously. - */ -static void add_blame_entry(git_blame *blame, git_blame__entry *e) -{ - git_blame__entry *ent, *prev = NULL; - - origin_incref(e->suspect); - - for (ent = blame->ent; ent && ent->lno < e->lno; ent = ent->next) - prev = ent; - - /* prev, if not NULL, is the last one that is below e */ - e->prev = prev; - if (prev) { - e->next = prev->next; - prev->next = e; - } else { - e->next = blame->ent; - blame->ent = e; - } - if (e->next) - e->next->prev = e; -} - -/* - * src typically is on-stack; we want to copy the information in it to - * a malloced blame_entry that is already on the linked list of the scoreboard. - * The origin of dst loses a refcnt while the origin of src gains one. - */ -static void dup_entry(git_blame__entry *dst, git_blame__entry *src) -{ - git_blame__entry *p, *n; - - p = dst->prev; - n = dst->next; - origin_incref(src->suspect); - origin_decref(dst->suspect); - memcpy(dst, src, sizeof(*src)); - dst->prev = p; - dst->next = n; - dst->score = 0; -} - -/* - * split_overlap() divided an existing blame e into up to three parts in split. - * Adjust the linked list of blames in the scoreboard to reflect the split. - */ -static int split_blame(git_blame *blame, git_blame__entry *split, git_blame__entry *e) -{ - git_blame__entry *new_entry; - - if (split[0].suspect && split[2].suspect) { - /* The first part (reuse storage for the existing entry e */ - dup_entry(e, &split[0]); - - /* The last part -- me */ - new_entry = git__malloc(sizeof(*new_entry)); - GIT_ERROR_CHECK_ALLOC(new_entry); - memcpy(new_entry, &(split[2]), sizeof(git_blame__entry)); - add_blame_entry(blame, new_entry); - - /* ... and the middle part -- parent */ - new_entry = git__malloc(sizeof(*new_entry)); - GIT_ERROR_CHECK_ALLOC(new_entry); - memcpy(new_entry, &(split[1]), sizeof(git_blame__entry)); - add_blame_entry(blame, new_entry); - } else if (!split[0].suspect && !split[2].suspect) { - /* - * The parent covers the entire area; reuse storage for e and replace it - * with the parent - */ - dup_entry(e, &split[1]); - } else if (split[0].suspect) { - /* me and then parent */ - dup_entry(e, &split[0]); - new_entry = git__malloc(sizeof(*new_entry)); - GIT_ERROR_CHECK_ALLOC(new_entry); - memcpy(new_entry, &(split[1]), sizeof(git_blame__entry)); - add_blame_entry(blame, new_entry); - } else { - /* parent and then me */ - dup_entry(e, &split[1]); - new_entry = git__malloc(sizeof(*new_entry)); - GIT_ERROR_CHECK_ALLOC(new_entry); - memcpy(new_entry, &(split[2]), sizeof(git_blame__entry)); - add_blame_entry(blame, new_entry); - } - - return 0; -} - -/* - * After splitting the blame, the origins used by the on-stack blame_entry - * should lose one refcnt each. - */ -static void decref_split(git_blame__entry *split) -{ - int i; - for (i=0; i<3; i++) - origin_decref(split[i].suspect); -} - -/* - * Helper for blame_chunk(). blame_entry e is known to overlap with the patch - * hunk; split it and pass blame to the parent. - */ -static int blame_overlap( - git_blame *blame, - git_blame__entry *e, - size_t tlno, - size_t plno, - size_t same, - git_blame__origin *parent) -{ - git_blame__entry split[3] = {{0}}; - - split_overlap(split, e, tlno, plno, same, parent); - if (split[1].suspect) - if (split_blame(blame, split, e) < 0) - return -1; - decref_split(split); - - return 0; -} - -/* - * Process one hunk from the patch between the current suspect for blame_entry - * e and its parent. Find and split the overlap, and pass blame to the - * overlapping part to the parent. - */ -static int blame_chunk( - git_blame *blame, - size_t tlno, - size_t plno, - size_t same, - git_blame__origin *target, - git_blame__origin *parent) -{ - git_blame__entry *e; - - for (e = blame->ent; e; e = e->next) { - if (e->guilty || !same_suspect(e->suspect, target)) - continue; - if (same <= e->s_lno) - continue; - if (tlno < e->s_lno + e->num_lines) { - if (blame_overlap(blame, e, tlno, plno, same, parent) < 0) - return -1; - } - } - - return 0; -} - -static int my_emit( - long start_a, long count_a, - long start_b, long count_b, - void *cb_data) -{ - blame_chunk_cb_data *d = (blame_chunk_cb_data *)cb_data; - - if (blame_chunk(d->blame, d->tlno, d->plno, start_b, d->target, d->parent) < 0) - return -1; - d->plno = start_a + count_a; - d->tlno = start_b + count_b; - - return 0; -} - -static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx) -{ - const int blk = 1024; - long trimmed = 0, recovered = 0; - char *ap = a->ptr + a->size; - char *bp = b->ptr + b->size; - long smaller = (long)((a->size < b->size) ? a->size : b->size); - - if (ctx) - return; - - while (blk + trimmed <= smaller && !memcmp(ap - blk, bp - blk, blk)) { - trimmed += blk; - ap -= blk; - bp -= blk; - } - - while (recovered < trimmed) - if (ap[recovered++] == '\n') - break; - a->size -= trimmed - recovered; - b->size -= trimmed - recovered; -} - -static int diff_hunks(mmfile_t file_a, mmfile_t file_b, void *cb_data, git_blame_options *options) -{ - xdemitconf_t xecfg = {0}; - xdemitcb_t ecb = {0}; - xpparam_t xpp = {0}; - - if (options->flags & GIT_BLAME_IGNORE_WHITESPACE) - xpp.flags |= XDF_IGNORE_WHITESPACE; - - xecfg.hunk_func = my_emit; - ecb.priv = cb_data; - - trim_common_tail(&file_a, &file_b, 0); - - if (file_a.size > GIT_XDIFF_MAX_SIZE || - file_b.size > GIT_XDIFF_MAX_SIZE) { - git_error_set(GIT_ERROR_INVALID, "file too large to blame"); - return -1; - } - - return xdl_diff(&file_a, &file_b, &xpp, &xecfg, &ecb); -} - -static void fill_origin_blob(git_blame__origin *o, mmfile_t *file) -{ - memset(file, 0, sizeof(*file)); - if (o->blob) { - file->ptr = (char*)git_blob_rawcontent(o->blob); - file->size = (long)git_blob_rawsize(o->blob); - } -} - -static int pass_blame_to_parent( - git_blame *blame, - git_blame__origin *target, - git_blame__origin *parent) -{ - size_t last_in_target; - mmfile_t file_p, file_o; - blame_chunk_cb_data d = { blame, target, parent, 0, 0 }; - - if (!find_last_in_target(&last_in_target, blame, target)) - return 1; /* nothing remains for this target */ - - fill_origin_blob(parent, &file_p); - fill_origin_blob(target, &file_o); - - if (diff_hunks(file_p, file_o, &d, &blame->options) < 0) - return -1; - - /* The reset (i.e. anything after tlno) are the same as the parent */ - if (blame_chunk(blame, d.tlno, d.plno, last_in_target, target, parent) < 0) - return -1; - - return 0; -} - -static int paths_on_dup(void **old, void *new) -{ - GIT_UNUSED(old); - git__free(new); - return -1; -} - -static git_blame__origin *find_origin( - git_blame *blame, - git_commit *parent, - git_blame__origin *origin) -{ - git_blame__origin *porigin = NULL; - git_diff *difflist = NULL; - git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT; - git_tree *otree=NULL, *ptree=NULL; - - /* Get the trees from this commit and its parent */ - if (0 != git_commit_tree(&otree, origin->commit) || - 0 != git_commit_tree(&ptree, parent)) - goto cleanup; - - /* Configure the diff */ - diffopts.context_lines = 0; - diffopts.flags = GIT_DIFF_SKIP_BINARY_CHECK; - - /* Check to see if files we're interested have changed */ - diffopts.pathspec.count = blame->paths.length; - diffopts.pathspec.strings = (char**)blame->paths.contents; - if (0 != git_diff_tree_to_tree(&difflist, blame->repository, ptree, otree, &diffopts)) - goto cleanup; - - if (!git_diff_num_deltas(difflist)) { - /* No changes; copy data */ - git_blame__get_origin(&porigin, blame, parent, origin->path); - } else { - git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT; - int i; - - /* Generate a full diff between the two trees */ - git_diff_free(difflist); - diffopts.pathspec.count = 0; - if (0 != git_diff_tree_to_tree(&difflist, blame->repository, ptree, otree, &diffopts)) - goto cleanup; - - /* Let diff find renames */ - findopts.flags = GIT_DIFF_FIND_RENAMES; - if (0 != git_diff_find_similar(difflist, &findopts)) - goto cleanup; - - /* Find one that matches */ - for (i=0; i<(int)git_diff_num_deltas(difflist); i++) { - const git_diff_delta *delta = git_diff_get_delta(difflist, i); - - if (!git_vector_bsearch(NULL, &blame->paths, delta->new_file.path)) - { - git_vector_insert_sorted(&blame->paths, (void*)git__strdup(delta->old_file.path), - paths_on_dup); - make_origin(&porigin, parent, delta->old_file.path); - } - } - } - -cleanup: - git_diff_free(difflist); - git_tree_free(otree); - git_tree_free(ptree); - return porigin; -} - -/* - * The blobs of origin and porigin exactly match, so everything origin is - * suspected for can be blamed on the parent. - */ -static int pass_whole_blame(git_blame *blame, - git_blame__origin *origin, git_blame__origin *porigin) -{ - git_blame__entry *e; - - if (!porigin->blob && - git_object_lookup((git_object**)&porigin->blob, blame->repository, - git_blob_id(origin->blob), GIT_OBJECT_BLOB) < 0) - return -1; - for (e=blame->ent; e; e=e->next) { - if (!same_suspect(e->suspect, origin)) - continue; - origin_incref(porigin); - origin_decref(e->suspect); - e->suspect = porigin; - } - - return 0; -} - -static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt) -{ - git_commit *commit = origin->commit; - int i, num_parents; - git_blame__origin *sg_buf[16]; - git_blame__origin *porigin, **sg_origin = sg_buf; - int ret, error = 0; - - num_parents = git_commit_parentcount(commit); - if (!git_oid_cmp(git_commit_id(commit), &blame->options.oldest_commit)) - /* Stop at oldest specified commit */ - num_parents = 0; - else if (opt & GIT_BLAME_FIRST_PARENT && num_parents > 1) - /* Limit search to the first parent */ - num_parents = 1; - - if (!num_parents) { - git_oid_cpy(&blame->options.oldest_commit, git_commit_id(commit)); - goto finish; - } else if (num_parents < (int)ARRAY_SIZE(sg_buf)) - memset(sg_buf, 0, sizeof(sg_buf)); - else { - sg_origin = git__calloc(num_parents, sizeof(*sg_origin)); - GIT_ERROR_CHECK_ALLOC(sg_origin); - } - - for (i=0; icommit, i)) < 0) - goto finish; - porigin = find_origin(blame, p, origin); - - if (!porigin) { - /* - * We only have to decrement the parent's - * reference count when no porigin has - * been created, as otherwise the commit - * is assigned to the created object. - */ - git_commit_free(p); - continue; - } - if (porigin->blob && origin->blob && - !git_oid_cmp(git_blob_id(porigin->blob), git_blob_id(origin->blob))) { - error = pass_whole_blame(blame, origin, porigin); - origin_decref(porigin); - goto finish; - } - for (j = same = 0; jblob), git_blob_id(porigin->blob))) { - same = 1; - break; - } - if (!same) - sg_origin[i] = porigin; - else - origin_decref(porigin); - } - - /* Standard blame */ - for (i=0; iprevious) { - origin_incref(porigin); - origin->previous = porigin; - } - - if ((ret = pass_blame_to_parent(blame, origin, porigin)) != 0) { - if (ret < 0) - error = -1; - - goto finish; - } - } - - /* TODO: optionally find moves in parents' files */ - - /* TODO: optionally find copies in parents' files */ - -finish: - for (i=0; i pair), - * merge them together. - */ -static void coalesce(git_blame *blame) -{ - git_blame__entry *ent, *next; - - for (ent=blame->ent; ent && (next = ent->next); ent = next) { - if (same_suspect(ent->suspect, next->suspect) && - ent->guilty == next->guilty && - ent->s_lno + ent->num_lines == next->s_lno) - { - ent->num_lines += next->num_lines; - ent->next = next->next; - if (ent->next) - ent->next->prev = ent; - origin_decref(next->suspect); - git__free(next); - ent->score = 0; - next = ent; /* again */ - } - } -} - -int git_blame__like_git(git_blame *blame, uint32_t opt) -{ - int error = 0; - - while (true) { - git_blame__entry *ent; - git_blame__origin *suspect = NULL; - - /* Find a suspect to break down */ - for (ent = blame->ent; !suspect && ent; ent = ent->next) - if (!ent->guilty) - suspect = ent->suspect; - if (!suspect) - break; - - /* We'll use this suspect later in the loop, so hold on to it for now. */ - origin_incref(suspect); - - if ((error = pass_blame(blame, suspect, opt)) < 0) - break; - - /* Take responsibility for the remaining entries */ - for (ent = blame->ent; ent; ent = ent->next) { - if (same_suspect(ent->suspect, suspect)) { - ent->guilty = true; - ent->is_boundary = !git_oid_cmp( - git_commit_id(suspect->commit), - &blame->options.oldest_commit); - } - } - origin_decref(suspect); - } - - if (!error) - coalesce(blame); - - return error; -} - -void git_blame__free_entry(git_blame__entry *ent) -{ - if (!ent) return; - origin_decref(ent->suspect); - git__free(ent); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/blame_git.h b/vendor/libgit2-sys/libgit2/src/libgit2/blame_git.h deleted file mode 100644 index 48b85a2..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/blame_git.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_blame_git__ -#define INCLUDE_blame_git__ - -#include "common.h" - -#include "blame.h" - -int git_blame__get_origin( - git_blame__origin **out, - git_blame *sb, - git_commit *commit, - const char *path); -void git_blame__free_entry(git_blame__entry *ent); -int git_blame__like_git(git_blame *sb, uint32_t flags); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/blob.c b/vendor/libgit2-sys/libgit2/src/libgit2/blob.c deleted file mode 100644 index 5cfd747..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/blob.c +++ /dev/null @@ -1,530 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "blob.h" - -#include "git2/common.h" -#include "git2/object.h" -#include "git2/repository.h" -#include "git2/odb_backend.h" - -#include "buf.h" -#include "filebuf.h" -#include "filter.h" - -const void *git_blob_rawcontent(const git_blob *blob) -{ - GIT_ASSERT_ARG_WITH_RETVAL(blob, NULL); - - if (blob->raw) - return blob->data.raw.data; - else - return git_odb_object_data(blob->data.odb); -} - -git_object_size_t git_blob_rawsize(const git_blob *blob) -{ - GIT_ASSERT_ARG(blob); - - if (blob->raw) - return blob->data.raw.size; - else - return (git_object_size_t)git_odb_object_size(blob->data.odb); -} - -int git_blob__getbuf(git_str *buffer, git_blob *blob) -{ - git_object_size_t size = git_blob_rawsize(blob); - - GIT_ERROR_CHECK_BLOBSIZE(size); - return git_str_set(buffer, git_blob_rawcontent(blob), (size_t)size); -} - -void git_blob__free(void *_blob) -{ - git_blob *blob = (git_blob *) _blob; - if (!blob->raw) - git_odb_object_free(blob->data.odb); - git__free(blob); -} - -int git_blob__parse_raw(void *_blob, const char *data, size_t size, git_oid_t oid_type) -{ - git_blob *blob = (git_blob *) _blob; - - GIT_ASSERT_ARG(blob); - GIT_UNUSED(oid_type); - - blob->raw = 1; - blob->data.raw.data = data; - blob->data.raw.size = size; - return 0; -} - -int git_blob__parse(void *_blob, git_odb_object *odb_obj, git_oid_t oid_type) -{ - git_blob *blob = (git_blob *) _blob; - - GIT_ASSERT_ARG(blob); - GIT_UNUSED(oid_type); - - git_cached_obj_incref((git_cached_obj *)odb_obj); - blob->raw = 0; - blob->data.odb = odb_obj; - return 0; -} - -int git_blob_create_from_buffer( - git_oid *id, git_repository *repo, const void *buffer, size_t len) -{ - int error; - git_odb *odb; - git_odb_stream *stream; - - GIT_ASSERT_ARG(id); - GIT_ASSERT_ARG(repo); - - if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 || - (error = git_odb_open_wstream(&stream, odb, len, GIT_OBJECT_BLOB)) < 0) - return error; - - if ((error = git_odb_stream_write(stream, buffer, len)) == 0) - error = git_odb_stream_finalize_write(id, stream); - - git_odb_stream_free(stream); - return error; -} - -static int write_file_stream( - git_oid *id, git_odb *odb, const char *path, git_object_size_t file_size) -{ - int fd, error; - char buffer[GIT_BUFSIZE_FILEIO]; - git_odb_stream *stream = NULL; - ssize_t read_len = -1; - git_object_size_t written = 0; - - if ((error = git_odb_open_wstream( - &stream, odb, file_size, GIT_OBJECT_BLOB)) < 0) - return error; - - if ((fd = git_futils_open_ro(path)) < 0) { - git_odb_stream_free(stream); - return -1; - } - - while (!error && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) { - error = git_odb_stream_write(stream, buffer, read_len); - written += read_len; - } - - p_close(fd); - - if (written != file_size || read_len < 0) { - git_error_set(GIT_ERROR_OS, "failed to read file into stream"); - error = -1; - } - - if (!error) - error = git_odb_stream_finalize_write(id, stream); - - git_odb_stream_free(stream); - return error; -} - -static int write_file_filtered( - git_oid *id, - git_object_size_t *size, - git_odb *odb, - const char *full_path, - git_filter_list *fl, - git_repository* repo) -{ - int error; - git_str tgt = GIT_STR_INIT; - - error = git_filter_list__apply_to_file(&tgt, fl, repo, full_path); - - /* Write the file to disk if it was properly filtered */ - if (!error) { - *size = tgt.size; - - error = git_odb_write(id, odb, tgt.ptr, tgt.size, GIT_OBJECT_BLOB); - } - - git_str_dispose(&tgt); - return error; -} - -static int write_symlink( - git_oid *id, git_odb *odb, const char *path, size_t link_size) -{ - char *link_data; - ssize_t read_len; - int error; - - link_data = git__malloc(link_size); - GIT_ERROR_CHECK_ALLOC(link_data); - - read_len = p_readlink(path, link_data, link_size); - if (read_len != (ssize_t)link_size) { - git_error_set(GIT_ERROR_OS, "failed to create blob: cannot read symlink '%s'", path); - git__free(link_data); - return -1; - } - - error = git_odb_write(id, odb, (void *)link_data, link_size, GIT_OBJECT_BLOB); - git__free(link_data); - return error; -} - -int git_blob__create_from_paths( - git_oid *id, - struct stat *out_st, - git_repository *repo, - const char *content_path, - const char *hint_path, - mode_t hint_mode, - bool try_load_filters) -{ - int error; - struct stat st; - git_odb *odb = NULL; - git_object_size_t size; - mode_t mode; - git_str path = GIT_STR_INIT; - - GIT_ASSERT_ARG(hint_path || !try_load_filters); - - if (!content_path) { - if (git_repository_workdir_path(&path, repo, hint_path) < 0) - return -1; - - content_path = path.ptr; - } - - if ((error = git_fs_path_lstat(content_path, &st)) < 0 || - (error = git_repository_odb(&odb, repo)) < 0) - goto done; - - if (S_ISDIR(st.st_mode)) { - git_error_set(GIT_ERROR_ODB, "cannot create blob from '%s': it is a directory", content_path); - error = GIT_EDIRECTORY; - goto done; - } - - if (out_st) - memcpy(out_st, &st, sizeof(st)); - - size = st.st_size; - mode = hint_mode ? hint_mode : st.st_mode; - - if (S_ISLNK(mode)) { - error = write_symlink(id, odb, content_path, (size_t)size); - } else { - git_filter_list *fl = NULL; - - if (try_load_filters) - /* Load the filters for writing this file to the ODB */ - error = git_filter_list_load( - &fl, repo, NULL, hint_path, - GIT_FILTER_TO_ODB, GIT_FILTER_DEFAULT); - - if (error < 0) - /* well, that didn't work */; - else if (fl == NULL) - /* No filters need to be applied to the document: we can stream - * directly from disk */ - error = write_file_stream(id, odb, content_path, size); - else { - /* We need to apply one or more filters */ - error = write_file_filtered(id, &size, odb, content_path, fl, repo); - - git_filter_list_free(fl); - } - - /* - * TODO: eventually support streaming filtered files, for files - * which are bigger than a given threshold. This is not a priority - * because applying a filter in streaming mode changes the final - * size of the blob, and without knowing its final size, the blob - * cannot be written in stream mode to the ODB. - * - * The plan is to do streaming writes to a tempfile on disk and then - * opening streaming that file to the ODB, using - * `write_file_stream`. - * - * CAREFULLY DESIGNED APIS YO - */ - } - -done: - git_odb_free(odb); - git_str_dispose(&path); - - return error; -} - -int git_blob_create_from_workdir( - git_oid *id, git_repository *repo, const char *path) -{ - return git_blob__create_from_paths(id, NULL, repo, NULL, path, 0, true); -} - -int git_blob_create_from_disk( - git_oid *id, git_repository *repo, const char *path) -{ - int error; - git_str full_path = GIT_STR_INIT; - const char *workdir, *hintpath = NULL; - - if ((error = git_fs_path_prettify(&full_path, path, NULL)) < 0) { - git_str_dispose(&full_path); - return error; - } - - workdir = git_repository_workdir(repo); - - if (workdir && !git__prefixcmp(full_path.ptr, workdir)) - hintpath = full_path.ptr + strlen(workdir); - - error = git_blob__create_from_paths( - id, NULL, repo, git_str_cstr(&full_path), hintpath, 0, !!hintpath); - - git_str_dispose(&full_path); - return error; -} - -typedef struct { - git_writestream parent; - git_filebuf fbuf; - git_repository *repo; - char *hintpath; -} blob_writestream; - -static int blob_writestream_close(git_writestream *_stream) -{ - blob_writestream *stream = (blob_writestream *) _stream; - - git_filebuf_cleanup(&stream->fbuf); - return 0; -} - -static void blob_writestream_free(git_writestream *_stream) -{ - blob_writestream *stream = (blob_writestream *) _stream; - - git_filebuf_cleanup(&stream->fbuf); - git__free(stream->hintpath); - git__free(stream); -} - -static int blob_writestream_write(git_writestream *_stream, const char *buffer, size_t len) -{ - blob_writestream *stream = (blob_writestream *) _stream; - - return git_filebuf_write(&stream->fbuf, buffer, len); -} - -int git_blob_create_from_stream(git_writestream **out, git_repository *repo, const char *hintpath) -{ - int error; - git_str path = GIT_STR_INIT; - blob_writestream *stream; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - stream = git__calloc(1, sizeof(blob_writestream)); - GIT_ERROR_CHECK_ALLOC(stream); - - if (hintpath) { - stream->hintpath = git__strdup(hintpath); - GIT_ERROR_CHECK_ALLOC(stream->hintpath); - } - - stream->repo = repo; - stream->parent.write = blob_writestream_write; - stream->parent.close = blob_writestream_close; - stream->parent.free = blob_writestream_free; - - if ((error = git_repository__item_path(&path, repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0 - || (error = git_str_joinpath(&path, path.ptr, "streamed")) < 0) - goto cleanup; - - if ((error = git_filebuf_open_withsize(&stream->fbuf, git_str_cstr(&path), GIT_FILEBUF_TEMPORARY, - 0666, 2 * 1024 * 1024)) < 0) - goto cleanup; - - *out = (git_writestream *) stream; - -cleanup: - if (error < 0) - blob_writestream_free((git_writestream *) stream); - - git_str_dispose(&path); - return error; -} - -int git_blob_create_from_stream_commit(git_oid *out, git_writestream *_stream) -{ - int error; - blob_writestream *stream = (blob_writestream *) _stream; - - /* - * We can make this more officient by avoiding writing to - * disk, but for now let's re-use the helper functions we - * have. - */ - if ((error = git_filebuf_flush(&stream->fbuf)) < 0) - goto cleanup; - - error = git_blob__create_from_paths(out, NULL, stream->repo, stream->fbuf.path_lock, - stream->hintpath, 0, !!stream->hintpath); - -cleanup: - blob_writestream_free(_stream); - return error; - -} - -int git_blob_is_binary(const git_blob *blob) -{ - git_str content = GIT_STR_INIT; - git_object_size_t size; - - GIT_ASSERT_ARG(blob); - - size = git_blob_rawsize(blob); - - git_str_attach_notowned(&content, git_blob_rawcontent(blob), - (size_t)min(size, GIT_FILTER_BYTES_TO_CHECK_NUL)); - return git_str_is_binary(&content); -} - -int git_blob_data_is_binary(const char *str, size_t len) -{ - git_str content = GIT_STR_INIT; - - git_str_attach_notowned(&content, str, len); - - return git_str_is_binary(&content); -} - -int git_blob_filter_options_init( - git_blob_filter_options *opts, - unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version, - git_blob_filter_options, GIT_BLOB_FILTER_OPTIONS_INIT); - return 0; -} - -int git_blob_filter( - git_buf *out, - git_blob *blob, - const char *path, - git_blob_filter_options *given_opts) -{ - git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT; - git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT; - git_filter_list *fl = NULL; - int error = 0; - - GIT_ASSERT_ARG(blob); - GIT_ASSERT_ARG(path); - GIT_ASSERT_ARG(out); - - GIT_ERROR_CHECK_VERSION( - given_opts, GIT_BLOB_FILTER_OPTIONS_VERSION, "git_blob_filter_options"); - - if (given_opts != NULL) - memcpy(&opts, given_opts, sizeof(git_blob_filter_options)); - - if ((opts.flags & GIT_BLOB_FILTER_CHECK_FOR_BINARY) != 0 && - git_blob_is_binary(blob)) - return 0; - - if ((opts.flags & GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES) != 0) - filter_opts.flags |= GIT_FILTER_NO_SYSTEM_ATTRIBUTES; - - if ((opts.flags & GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD) != 0) - filter_opts.flags |= GIT_FILTER_ATTRIBUTES_FROM_HEAD; - - if ((opts.flags & GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT) != 0) { - filter_opts.flags |= GIT_FILTER_ATTRIBUTES_FROM_COMMIT; - -#ifndef GIT_DEPRECATE_HARD - if (opts.commit_id) - git_oid_cpy(&filter_opts.attr_commit_id, opts.commit_id); - else -#endif - git_oid_cpy(&filter_opts.attr_commit_id, &opts.attr_commit_id); - } - - if (!(error = git_filter_list_load_ext( - &fl, git_blob_owner(blob), blob, path, - GIT_FILTER_TO_WORKTREE, &filter_opts))) { - - error = git_filter_list_apply_to_blob(out, fl, blob); - - git_filter_list_free(fl); - } - - return error; -} - -/* Deprecated functions */ - -#ifndef GIT_DEPRECATE_HARD -int git_blob_create_frombuffer( - git_oid *id, git_repository *repo, const void *buffer, size_t len) -{ - return git_blob_create_from_buffer(id, repo, buffer, len); -} - -int git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path) -{ - return git_blob_create_from_workdir(id, repo, relative_path); -} - -int git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path) -{ - return git_blob_create_from_disk(id, repo, path); -} - -int git_blob_create_fromstream( - git_writestream **out, - git_repository *repo, - const char *hintpath) -{ - return git_blob_create_from_stream(out, repo, hintpath); -} - -int git_blob_create_fromstream_commit( - git_oid *out, - git_writestream *stream) -{ - return git_blob_create_from_stream_commit(out, stream); -} - -int git_blob_filtered_content( - git_buf *out, - git_blob *blob, - const char *path, - int check_for_binary_data) -{ - git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT; - - if (check_for_binary_data) - opts.flags |= GIT_BLOB_FILTER_CHECK_FOR_BINARY; - else - opts.flags &= ~GIT_BLOB_FILTER_CHECK_FOR_BINARY; - - return git_blob_filter(out, blob, path, &opts); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/blob.h b/vendor/libgit2-sys/libgit2/src/libgit2/blob.h deleted file mode 100644 index d6c9dd9..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/blob.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_blob_h__ -#define INCLUDE_blob_h__ - -#include "common.h" - -#include "git2/blob.h" -#include "repository.h" -#include "odb.h" -#include "futils.h" - -struct git_blob { - git_object object; - - union { - git_odb_object *odb; - struct { - const char *data; - git_object_size_t size; - } raw; - } data; - unsigned int raw:1; -}; - -#define GIT_ERROR_CHECK_BLOBSIZE(n) \ - do { \ - if (!git__is_sizet(n)) { \ - git_error_set(GIT_ERROR_NOMEMORY, "blob contents too large to fit in memory"); \ - return -1; \ - } \ - } while(0) - -void git_blob__free(void *blob); -int git_blob__parse(void *blob, git_odb_object *obj, git_oid_t oid_type); -int git_blob__parse_raw(void *blob, const char *data, size_t size, git_oid_t oid_type); -int git_blob__getbuf(git_str *buffer, git_blob *blob); - -extern int git_blob__create_from_paths( - git_oid *out_oid, - struct stat *out_st, - git_repository *repo, - const char *full_path, - const char *hint_path, - mode_t hint_mode, - bool apply_filters); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/branch.c b/vendor/libgit2-sys/libgit2/src/libgit2/branch.c deleted file mode 100644 index 9a31c9c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/branch.c +++ /dev/null @@ -1,823 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "branch.h" - -#include "buf.h" -#include "commit.h" -#include "tag.h" -#include "config.h" -#include "refspec.h" -#include "refs.h" -#include "remote.h" -#include "annotated_commit.h" -#include "worktree.h" - -#include "git2/branch.h" - -static int retrieve_branch_reference( - git_reference **branch_reference_out, - git_repository *repo, - const char *branch_name, - bool is_remote) -{ - git_reference *branch = NULL; - int error = 0; - char *prefix; - git_str ref_name = GIT_STR_INIT; - - prefix = is_remote ? GIT_REFS_REMOTES_DIR : GIT_REFS_HEADS_DIR; - - if ((error = git_str_joinpath(&ref_name, prefix, branch_name)) < 0) - /* OOM */; - else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0) - git_error_set( - GIT_ERROR_REFERENCE, "cannot locate %s branch '%s'", - is_remote ? "remote-tracking" : "local", branch_name); - - *branch_reference_out = branch; /* will be NULL on error */ - - git_str_dispose(&ref_name); - return error; -} - -static int not_a_local_branch(const char *reference_name) -{ - git_error_set( - GIT_ERROR_INVALID, - "reference '%s' is not a local branch.", reference_name); - return -1; -} - -static bool branch_name_is_valid(const char *branch_name) -{ - /* - * Discourage branch name starting with dash, - * https://github.com/git/git/commit/6348624010888b - * and discourage HEAD as branch name, - * https://github.com/git/git/commit/a625b092cc5994 - */ - return branch_name[0] != '-' && git__strcmp(branch_name, "HEAD"); -} - -static int create_branch( - git_reference **ref_out, - git_repository *repository, - const char *branch_name, - const git_commit *commit, - const char *from, - int force) -{ - int is_unmovable_head = 0; - git_reference *branch = NULL; - git_str canonical_branch_name = GIT_STR_INIT, - log_message = GIT_STR_INIT; - int error = -1; - int bare = git_repository_is_bare(repository); - - GIT_ASSERT_ARG(branch_name); - GIT_ASSERT_ARG(commit); - GIT_ASSERT_ARG(ref_out); - GIT_ASSERT_ARG(git_commit_owner(commit) == repository); - - if (!branch_name_is_valid(branch_name)) { - git_error_set(GIT_ERROR_REFERENCE, "'%s' is not a valid branch name", branch_name); - error = -1; - goto cleanup; - } - - if (force && !bare && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) { - error = git_branch_is_head(branch); - git_reference_free(branch); - branch = NULL; - - if (error < 0) - goto cleanup; - - is_unmovable_head = error; - } - - if (is_unmovable_head && force) { - git_error_set(GIT_ERROR_REFERENCE, "cannot force update branch '%s' as it is " - "the current HEAD of the repository.", branch_name); - error = -1; - goto cleanup; - } - - if (git_str_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0) - goto cleanup; - - if (git_str_printf(&log_message, "branch: Created from %s", from) < 0) - goto cleanup; - - error = git_reference_create(&branch, repository, - git_str_cstr(&canonical_branch_name), git_commit_id(commit), force, - git_str_cstr(&log_message)); - - if (!error) - *ref_out = branch; - -cleanup: - git_str_dispose(&canonical_branch_name); - git_str_dispose(&log_message); - return error; -} - -int git_branch_create( - git_reference **ref_out, - git_repository *repository, - const char *branch_name, - const git_commit *commit, - int force) -{ - char commit_id[GIT_OID_MAX_HEXSIZE + 1]; - - git_oid_tostr(commit_id, GIT_OID_MAX_HEXSIZE + 1, git_commit_id(commit)); - return create_branch(ref_out, repository, branch_name, commit, commit_id, force); -} - -int git_branch_create_from_annotated( - git_reference **ref_out, - git_repository *repository, - const char *branch_name, - const git_annotated_commit *commit, - int force) -{ - return create_branch(ref_out, - repository, branch_name, commit->commit, commit->description, force); -} - -static int branch_is_checked_out(git_repository *worktree, void *payload) -{ - git_reference *branch = (git_reference *) payload; - git_reference *head = NULL; - int error; - - if (git_repository_is_bare(worktree)) - return 0; - - if ((error = git_reference_lookup(&head, worktree, GIT_HEAD_FILE)) < 0) { - if (error == GIT_ENOTFOUND) - error = 0; - goto out; - } - - if (git_reference_type(head) != GIT_REFERENCE_SYMBOLIC) - goto out; - - error = !git__strcmp(head->target.symbolic, branch->name); - -out: - git_reference_free(head); - return error; -} - -int git_branch_is_checked_out(const git_reference *branch) -{ - GIT_ASSERT_ARG(branch); - - if (!git_reference_is_branch(branch)) - return 0; - return git_repository_foreach_worktree(git_reference_owner(branch), - branch_is_checked_out, (void *)branch) == 1; -} - -int git_branch_delete(git_reference *branch) -{ - int is_head; - git_str config_section = GIT_STR_INIT; - int error = -1; - - GIT_ASSERT_ARG(branch); - - if (!git_reference_is_branch(branch) && !git_reference_is_remote(branch)) { - git_error_set(GIT_ERROR_INVALID, "reference '%s' is not a valid branch.", - git_reference_name(branch)); - return GIT_ENOTFOUND; - } - - if ((is_head = git_branch_is_head(branch)) < 0) - return is_head; - - if (is_head) { - git_error_set(GIT_ERROR_REFERENCE, "cannot delete branch '%s' as it is " - "the current HEAD of the repository.", git_reference_name(branch)); - return -1; - } - - if (git_reference_is_branch(branch) && git_branch_is_checked_out(branch)) { - git_error_set(GIT_ERROR_REFERENCE, "Cannot delete branch '%s' as it is " - "the current HEAD of a linked repository.", git_reference_name(branch)); - return -1; - } - - if (git_str_join(&config_section, '.', "branch", - git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)) < 0) - goto on_error; - - if (git_config_rename_section( - git_reference_owner(branch), git_str_cstr(&config_section), NULL) < 0) - goto on_error; - - error = git_reference_delete(branch); - -on_error: - git_str_dispose(&config_section); - return error; -} - -typedef struct { - git_reference_iterator *iter; - unsigned int flags; -} branch_iter; - -int git_branch_next(git_reference **out, git_branch_t *out_type, git_branch_iterator *_iter) -{ - branch_iter *iter = (branch_iter *) _iter; - git_reference *ref; - int error; - - while ((error = git_reference_next(&ref, iter->iter)) == 0) { - if ((iter->flags & GIT_BRANCH_LOCAL) && - !git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR)) { - *out = ref; - *out_type = GIT_BRANCH_LOCAL; - - return 0; - } else if ((iter->flags & GIT_BRANCH_REMOTE) && - !git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR)) { - *out = ref; - *out_type = GIT_BRANCH_REMOTE; - - return 0; - } else { - git_reference_free(ref); - } - } - - return error; -} - -int git_branch_iterator_new( - git_branch_iterator **out, - git_repository *repo, - git_branch_t list_flags) -{ - branch_iter *iter; - - iter = git__calloc(1, sizeof(branch_iter)); - GIT_ERROR_CHECK_ALLOC(iter); - - iter->flags = list_flags; - - if (git_reference_iterator_new(&iter->iter, repo) < 0) { - git__free(iter); - return -1; - } - - *out = (git_branch_iterator *) iter; - - return 0; -} - -void git_branch_iterator_free(git_branch_iterator *_iter) -{ - branch_iter *iter = (branch_iter *) _iter; - - if (iter == NULL) - return; - - git_reference_iterator_free(iter->iter); - git__free(iter); -} - -int git_branch_move( - git_reference **out, - git_reference *branch, - const char *new_branch_name, - int force) -{ - git_str new_reference_name = GIT_STR_INIT, - old_config_section = GIT_STR_INIT, - new_config_section = GIT_STR_INIT, - log_message = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(branch); - GIT_ASSERT_ARG(new_branch_name); - - if (!git_reference_is_branch(branch)) - return not_a_local_branch(git_reference_name(branch)); - - if ((error = git_str_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0) - goto done; - - if ((error = git_str_printf(&log_message, "branch: renamed %s to %s", - git_reference_name(branch), git_str_cstr(&new_reference_name))) < 0) - goto done; - - /* first update ref then config so failure won't trash config */ - - error = git_reference_rename( - out, branch, git_str_cstr(&new_reference_name), force, - git_str_cstr(&log_message)); - if (error < 0) - goto done; - - git_str_join(&old_config_section, '.', "branch", - git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)); - git_str_join(&new_config_section, '.', "branch", new_branch_name); - - error = git_config_rename_section( - git_reference_owner(branch), - git_str_cstr(&old_config_section), - git_str_cstr(&new_config_section)); - -done: - git_str_dispose(&new_reference_name); - git_str_dispose(&old_config_section); - git_str_dispose(&new_config_section); - git_str_dispose(&log_message); - - return error; -} - -int git_branch_lookup( - git_reference **ref_out, - git_repository *repo, - const char *branch_name, - git_branch_t branch_type) -{ - int error = -1; - - GIT_ASSERT_ARG(ref_out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(branch_name); - - switch (branch_type) { - case GIT_BRANCH_LOCAL: - case GIT_BRANCH_REMOTE: - error = retrieve_branch_reference(ref_out, repo, branch_name, branch_type == GIT_BRANCH_REMOTE); - break; - case GIT_BRANCH_ALL: - error = retrieve_branch_reference(ref_out, repo, branch_name, false); - if (error == GIT_ENOTFOUND) - error = retrieve_branch_reference(ref_out, repo, branch_name, true); - break; - default: - GIT_ASSERT(false); - } - return error; -} - -int git_branch_name( - const char **out, - const git_reference *ref) -{ - const char *branch_name; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(ref); - - branch_name = ref->name; - - if (git_reference_is_branch(ref)) { - branch_name += strlen(GIT_REFS_HEADS_DIR); - } else if (git_reference_is_remote(ref)) { - branch_name += strlen(GIT_REFS_REMOTES_DIR); - } else { - git_error_set(GIT_ERROR_INVALID, - "reference '%s' is neither a local nor a remote branch.", ref->name); - return -1; - } - *out = branch_name; - return 0; -} - -static int retrieve_upstream_configuration( - git_str *out, - const git_config *config, - const char *canonical_branch_name, - const char *format) -{ - git_str buf = GIT_STR_INIT; - int error; - - if (git_str_printf(&buf, format, - canonical_branch_name + strlen(GIT_REFS_HEADS_DIR)) < 0) - return -1; - - error = git_config__get_string_buf(out, config, git_str_cstr(&buf)); - git_str_dispose(&buf); - return error; -} - -int git_branch_upstream_name( - git_buf *out, - git_repository *repo, - const char *refname) -{ - GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_name, repo, refname); -} - -int git_branch__upstream_name( - git_str *out, - git_repository *repo, - const char *refname) -{ - git_str remote_name = GIT_STR_INIT; - git_str merge_name = GIT_STR_INIT; - git_str buf = GIT_STR_INIT; - int error = -1; - git_remote *remote = NULL; - const git_refspec *refspec; - git_config *config; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(refname); - - if (!git_reference__is_branch(refname)) - return not_a_local_branch(refname); - - if ((error = git_repository_config_snapshot(&config, repo)) < 0) - return error; - - if ((error = retrieve_upstream_configuration( - &remote_name, config, refname, "branch.%s.remote")) < 0) - goto cleanup; - - if ((error = retrieve_upstream_configuration( - &merge_name, config, refname, "branch.%s.merge")) < 0) - goto cleanup; - - if (git_str_len(&remote_name) == 0 || git_str_len(&merge_name) == 0) { - git_error_set(GIT_ERROR_REFERENCE, - "branch '%s' does not have an upstream", refname); - error = GIT_ENOTFOUND; - goto cleanup; - } - - if (strcmp(".", git_str_cstr(&remote_name)) != 0) { - if ((error = git_remote_lookup(&remote, repo, git_str_cstr(&remote_name))) < 0) - goto cleanup; - - refspec = git_remote__matching_refspec(remote, git_str_cstr(&merge_name)); - if (!refspec) { - error = GIT_ENOTFOUND; - goto cleanup; - } - - if (git_refspec__transform(&buf, refspec, git_str_cstr(&merge_name)) < 0) - goto cleanup; - } else - if (git_str_set(&buf, git_str_cstr(&merge_name), git_str_len(&merge_name)) < 0) - goto cleanup; - - git_str_swap(out, &buf); - -cleanup: - git_config_free(config); - git_remote_free(remote); - git_str_dispose(&remote_name); - git_str_dispose(&merge_name); - git_str_dispose(&buf); - return error; -} - -static int git_branch_upstream_with_format( - git_str *out, - git_repository *repo, - const char *refname, - const char *format, - const char *format_name) -{ - git_config *cfg; - int error; - - if (!git_reference__is_branch(refname)) - return not_a_local_branch(refname); - - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 || - (error = retrieve_upstream_configuration(out, cfg, refname, format)) < 0) - return error; - - if (git_str_len(out) == 0) { - git_error_set(GIT_ERROR_REFERENCE, "branch '%s' does not have an upstream %s", refname, format_name); - error = GIT_ENOTFOUND; - } - - return error; -} - -int git_branch_upstream_remote( - git_buf *out, - git_repository *repo, - const char *refname) -{ - GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_remote, repo, refname); -} - -int git_branch__upstream_remote( - git_str *out, - git_repository *repo, - const char *refname) -{ - return git_branch_upstream_with_format(out, repo, refname, "branch.%s.remote", "remote"); -} - -int git_branch_upstream_merge( - git_buf *out, - git_repository *repo, - const char *refname) -{ - GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_merge, repo, refname); -} - -int git_branch__upstream_merge( - git_str *out, - git_repository *repo, - const char *refname) -{ - return git_branch_upstream_with_format(out, repo, refname, "branch.%s.merge", "merge"); -} - -int git_branch_remote_name( - git_buf *out, - git_repository *repo, - const char *refname) -{ - GIT_BUF_WRAP_PRIVATE(out, git_branch__remote_name, repo, refname); -} - -int git_branch__remote_name( - git_str *out, - git_repository *repo, - const char *refname) -{ - git_strarray remote_list = {0}; - size_t i; - git_remote *remote; - const git_refspec *fetchspec; - int error = 0; - char *remote_name = NULL; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(refname); - - /* Verify that this is a remote branch */ - if (!git_reference__is_remote(refname)) { - git_error_set(GIT_ERROR_INVALID, "reference '%s' is not a remote branch.", - refname); - error = GIT_ERROR; - goto cleanup; - } - - /* Get the remotes */ - if ((error = git_remote_list(&remote_list, repo)) < 0) - goto cleanup; - - /* Find matching remotes */ - for (i = 0; i < remote_list.count; i++) { - if ((error = git_remote_lookup(&remote, repo, remote_list.strings[i])) < 0) - continue; - - fetchspec = git_remote__matching_dst_refspec(remote, refname); - if (fetchspec) { - /* If we have not already set out yet, then set - * it to the matching remote name. Otherwise - * multiple remotes match this reference, and it - * is ambiguous. */ - if (!remote_name) { - remote_name = remote_list.strings[i]; - } else { - git_remote_free(remote); - - git_error_set(GIT_ERROR_REFERENCE, - "reference '%s' is ambiguous", refname); - error = GIT_EAMBIGUOUS; - goto cleanup; - } - } - - git_remote_free(remote); - } - - if (remote_name) { - git_str_clear(out); - error = git_str_puts(out, remote_name); - } else { - git_error_set(GIT_ERROR_REFERENCE, - "could not determine remote for '%s'", refname); - error = GIT_ENOTFOUND; - } - -cleanup: - if (error < 0) - git_str_dispose(out); - - git_strarray_dispose(&remote_list); - return error; -} - -int git_branch_upstream( - git_reference **tracking_out, - const git_reference *branch) -{ - int error; - git_str tracking_name = GIT_STR_INIT; - - if ((error = git_branch__upstream_name(&tracking_name, - git_reference_owner(branch), git_reference_name(branch))) < 0) - return error; - - error = git_reference_lookup( - tracking_out, - git_reference_owner(branch), - git_str_cstr(&tracking_name)); - - git_str_dispose(&tracking_name); - return error; -} - -static int unset_upstream(git_config *config, const char *shortname) -{ - git_str buf = GIT_STR_INIT; - - if (git_str_printf(&buf, "branch.%s.remote", shortname) < 0) - return -1; - - if (git_config_delete_entry(config, git_str_cstr(&buf)) < 0) - goto on_error; - - git_str_clear(&buf); - if (git_str_printf(&buf, "branch.%s.merge", shortname) < 0) - goto on_error; - - if (git_config_delete_entry(config, git_str_cstr(&buf)) < 0) - goto on_error; - - git_str_dispose(&buf); - return 0; - -on_error: - git_str_dispose(&buf); - return -1; -} - -int git_branch_set_upstream(git_reference *branch, const char *branch_name) -{ - git_str key = GIT_STR_INIT, remote_name = GIT_STR_INIT, merge_refspec = GIT_STR_INIT; - git_reference *upstream; - git_repository *repo; - git_remote *remote = NULL; - git_config *config; - const char *refname, *shortname; - int local, error; - const git_refspec *fetchspec; - - refname = git_reference_name(branch); - if (!git_reference__is_branch(refname)) - return not_a_local_branch(refname); - - if (git_repository_config__weakptr(&config, git_reference_owner(branch)) < 0) - return -1; - - shortname = refname + strlen(GIT_REFS_HEADS_DIR); - - /* We're unsetting, delegate and bail-out */ - if (branch_name == NULL) - return unset_upstream(config, shortname); - - repo = git_reference_owner(branch); - - /* First we need to resolve name to a branch */ - if (git_branch_lookup(&upstream, repo, branch_name, GIT_BRANCH_LOCAL) == 0) - local = 1; - else if (git_branch_lookup(&upstream, repo, branch_name, GIT_BRANCH_REMOTE) == 0) - local = 0; - else { - git_error_set(GIT_ERROR_REFERENCE, - "cannot set upstream for branch '%s'", shortname); - return GIT_ENOTFOUND; - } - - /* - * If it's a local-tracking branch, its remote is "." (as "the local - * repository"), and the branch name is simply the refname. - * Otherwise we need to figure out what the remote-tracking branch's - * name on the remote is and use that. - */ - if (local) - error = git_str_puts(&remote_name, "."); - else - error = git_branch__remote_name(&remote_name, repo, git_reference_name(upstream)); - - if (error < 0) - goto on_error; - - /* Update the upstream branch config with the new name */ - if (git_str_printf(&key, "branch.%s.remote", shortname) < 0) - goto on_error; - - if (git_config_set_string(config, git_str_cstr(&key), git_str_cstr(&remote_name)) < 0) - goto on_error; - - if (local) { - /* A local branch uses the upstream refname directly */ - if (git_str_puts(&merge_refspec, git_reference_name(upstream)) < 0) - goto on_error; - } else { - /* We transform the upstream branch name according to the remote's refspecs */ - if (git_remote_lookup(&remote, repo, git_str_cstr(&remote_name)) < 0) - goto on_error; - - fetchspec = git_remote__matching_dst_refspec(remote, git_reference_name(upstream)); - if (!fetchspec || git_refspec__rtransform(&merge_refspec, fetchspec, git_reference_name(upstream)) < 0) - goto on_error; - - git_remote_free(remote); - remote = NULL; - } - - /* Update the merge branch config with the refspec */ - git_str_clear(&key); - if (git_str_printf(&key, "branch.%s.merge", shortname) < 0) - goto on_error; - - if (git_config_set_string(config, git_str_cstr(&key), git_str_cstr(&merge_refspec)) < 0) - goto on_error; - - git_reference_free(upstream); - git_str_dispose(&key); - git_str_dispose(&remote_name); - git_str_dispose(&merge_refspec); - - return 0; - -on_error: - git_reference_free(upstream); - git_str_dispose(&key); - git_str_dispose(&remote_name); - git_str_dispose(&merge_refspec); - git_remote_free(remote); - - return -1; -} - -int git_branch_is_head( - const git_reference *branch) -{ - git_reference *head; - bool is_same = false; - int error; - - GIT_ASSERT_ARG(branch); - - if (!git_reference_is_branch(branch)) - return false; - - error = git_repository_head(&head, git_reference_owner(branch)); - - if (error == GIT_EUNBORNBRANCH || error == GIT_ENOTFOUND) - return false; - - if (error < 0) - return -1; - - is_same = strcmp( - git_reference_name(branch), - git_reference_name(head)) == 0; - - git_reference_free(head); - - return is_same; -} - -int git_branch_name_is_valid(int *valid, const char *name) -{ - git_str ref_name = GIT_STR_INIT; - int error = 0; - - GIT_ASSERT(valid); - - *valid = 0; - - if (!name || !branch_name_is_valid(name)) - goto done; - - if ((error = git_str_puts(&ref_name, GIT_REFS_HEADS_DIR)) < 0 || - (error = git_str_puts(&ref_name, name)) < 0) - goto done; - - error = git_reference_name_is_valid(valid, ref_name.ptr); - -done: - git_str_dispose(&ref_name); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/branch.h b/vendor/libgit2-sys/libgit2/src/libgit2/branch.h deleted file mode 100644 index b4db42a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/branch.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_branch_h__ -#define INCLUDE_branch_h__ - -#include "common.h" - -#include "str.h" - -int git_branch__remote_name( - git_str *out, - git_repository *repo, - const char *refname); -int git_branch__upstream_remote( - git_str *out, - git_repository *repo, - const char *refname); -int git_branch__upstream_merge( - git_str *out, - git_repository *repo, - const char *refname); -int git_branch__upstream_name( - git_str *tracking_name, - git_repository *repo, - const char *canonical_branch_name); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/buf.c b/vendor/libgit2-sys/libgit2/src/libgit2/buf.c deleted file mode 100644 index 652f5dd..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/buf.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "buf.h" -#include "common.h" - -int git_buf_sanitize(git_buf *buf) -{ - GIT_ASSERT_ARG(buf); - - if (buf->reserved > 0) - buf->ptr[0] = '\0'; - else - buf->ptr = git_str__initstr; - - buf->size = 0; - return 0; -} - -int git_buf_tostr(git_str *out, git_buf *buf) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(buf); - - if (git_buf_sanitize(buf) < 0) - return -1; - - out->ptr = buf->ptr; - out->asize = buf->reserved; - out->size = buf->size; - - buf->ptr = git_str__initstr; - buf->reserved = 0; - buf->size = 0; - - return 0; -} - -int git_buf_fromstr(git_buf *out, git_str *str) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(str); - - out->ptr = str->ptr; - out->reserved = str->asize; - out->size = str->size; - - str->ptr = git_str__initstr; - str->asize = 0; - str->size = 0; - - return 0; -} - -void git_buf_dispose(git_buf *buf) -{ - if (!buf) - return; - - if (buf->ptr != git_str__initstr) - git__free(buf->ptr); - - buf->ptr = git_str__initstr; - buf->reserved = 0; - buf->size = 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_buf_grow(git_buf *buffer, size_t target_size) -{ - char *newptr; - - if (buffer->reserved >= target_size) - return 0; - - if (buffer->ptr == git_str__initstr) - newptr = git__malloc(target_size); - else - newptr = git__realloc(buffer->ptr, target_size); - - if (!newptr) - return -1; - - buffer->ptr = newptr; - buffer->reserved = target_size; - return 0; -} - -int git_buf_set(git_buf *buffer, const void *data, size_t datalen) -{ - size_t alloclen; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, datalen, 1); - - if (git_buf_grow(buffer, alloclen) < 0) - return -1; - - memmove(buffer->ptr, data, datalen); - buffer->size = datalen; - buffer->ptr[buffer->size] = '\0'; - - return 0; -} - -int git_buf_is_binary(const git_buf *buf) -{ - git_str str = GIT_STR_INIT_CONST(buf->ptr, buf->size); - return git_str_is_binary(&str); -} - -int git_buf_contains_nul(const git_buf *buf) -{ - git_str str = GIT_STR_INIT_CONST(buf->ptr, buf->size); - return git_str_contains_nul(&str); -} - -void git_buf_free(git_buf *buffer) -{ - git_buf_dispose(buffer); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/buf.h b/vendor/libgit2-sys/libgit2/src/libgit2/buf.h deleted file mode 100644 index 4bc7f27..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/buf.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_buf_h__ -#define INCLUDE_buf_h__ - -#include "git2/buffer.h" -#include "common.h" - -/* - * Adapts a private API that takes a `git_str` into a public API that - * takes a `git_buf`. - */ - -#define GIT_BUF_WRAP_PRIVATE(buf, fn, ...) \ - { \ - git_str str = GIT_STR_INIT; \ - int error; \ - if ((error = git_buf_tostr(&str, buf)) == 0 && \ - (error = fn(&str, __VA_ARGS__)) == 0) \ - error = git_buf_fromstr(buf, &str); \ - git_str_dispose(&str); \ - return error; \ -} - -/** - * "Sanitizes" a buffer from user input. This simply ensures that the - * `git_buf` has nice defaults if the user didn't set the members to - * anything, so that if we return early we don't leave it populated - * with nonsense. - */ -extern int git_buf_sanitize(git_buf *from_user); - -/** - * Populate a `git_str` from a `git_buf` for passing to libgit2 internal - * functions. Sanitizes the given `git_buf` before proceeding. The - * `git_buf` will no longer point to this memory. - */ -extern int git_buf_tostr(git_str *out, git_buf *buf); - -/** - * Populate a `git_buf` from a `git_str` for returning to a user. - * The `git_str` will no longer point to this memory. - */ -extern int git_buf_fromstr(git_buf *out, git_str *str); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/cache.c b/vendor/libgit2-sys/libgit2/src/libgit2/cache.c deleted file mode 100644 index 629c563..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/cache.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "cache.h" - -#include "repository.h" -#include "commit.h" -#include "thread.h" -#include "util.h" -#include "odb.h" -#include "object.h" -#include "git2/oid.h" -#include "hashmap_oid.h" - -GIT_HASHMAP_OID_FUNCTIONS(git_cache_oidmap, GIT_HASHMAP_INLINE, git_cached_obj *); - -bool git_cache__enabled = true; -ssize_t git_cache__max_storage = (256 * 1024 * 1024); -git_atomic_ssize git_cache__current_storage = {0}; - -static size_t git_cache__max_object_size[8] = { - 0, /* GIT_OBJECT__EXT1 */ - 4096, /* GIT_OBJECT_COMMIT */ - 4096, /* GIT_OBJECT_TREE */ - 0, /* GIT_OBJECT_BLOB */ - 4096, /* GIT_OBJECT_TAG */ - 0, /* GIT_OBJECT__EXT2 */ - 0, /* GIT_OBJECT_OFS_DELTA */ - 0 /* GIT_OBJECT_REF_DELTA */ -}; - -int git_cache_set_max_object_size(git_object_t type, size_t size) -{ - if (type < 0 || (size_t)type >= ARRAY_SIZE(git_cache__max_object_size)) { - git_error_set(GIT_ERROR_INVALID, "type out of range"); - return -1; - } - - git_cache__max_object_size[type] = size; - return 0; -} - -int git_cache_init(git_cache *cache) -{ - memset(cache, 0, sizeof(*cache)); - - if (git_rwlock_init(&cache->lock)) { - git_error_set(GIT_ERROR_OS, "failed to initialize cache rwlock"); - return -1; - } - - return 0; -} - -/* called with lock */ -static void clear_cache(git_cache *cache) -{ - git_cached_obj *evict = NULL; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - if (git_cache_size(cache) == 0) - return; - - while (git_cache_oidmap_iterate(&iter, NULL, &evict, &cache->map) == 0) - git_cached_obj_decref(evict); - - git_cache_oidmap_clear(&cache->map); - git_atomic_ssize_add(&git_cache__current_storage, -cache->used_memory); - cache->used_memory = 0; -} - -void git_cache_clear(git_cache *cache) -{ - if (git_rwlock_wrlock(&cache->lock) < 0) - return; - - clear_cache(cache); - - git_rwlock_wrunlock(&cache->lock); -} - -size_t git_cache_size(git_cache *cache) -{ - return git_cache_oidmap_size(&cache->map); -} - -void git_cache_dispose(git_cache *cache) -{ - git_cache_clear(cache); - git_cache_oidmap_dispose(&cache->map); - git_rwlock_free(&cache->lock); - git__memzero(cache, sizeof(*cache)); -} - -/* Called with lock */ -static void cache_evict_entries(git_cache *cache) -{ - size_t evict_count = git_cache_size(cache) / 2048; - ssize_t evicted_memory = 0; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - if (evict_count < 8) - evict_count = 8; - - /* do not infinite loop if there's not enough entries to evict */ - if (evict_count > git_cache_size(cache)) { - clear_cache(cache); - return; - } - - while (evict_count > 0) { - const git_oid *key; - git_cached_obj *evict; - - if (git_cache_oidmap_iterate(&iter, &key, &evict, &cache->map) != 0) - break; - - evict_count--; - evicted_memory += evict->size; - git_cache_oidmap_remove(&cache->map, key); - git_cached_obj_decref(evict); - } - - cache->used_memory -= evicted_memory; - git_atomic_ssize_add(&git_cache__current_storage, -evicted_memory); -} - -static bool cache_should_store(git_object_t object_type, size_t object_size) -{ - size_t max_size = git_cache__max_object_size[object_type]; - return git_cache__enabled && object_size < max_size; -} - -static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags) -{ - git_cached_obj *entry = NULL; - - if (!git_cache__enabled || git_rwlock_rdlock(&cache->lock) < 0) - return NULL; - - if (git_cache_oidmap_get(&entry, &cache->map, oid) == 0) { - if (flags && entry->flags != flags) { - entry = NULL; - } else { - git_cached_obj_incref(entry); - } - } - - git_rwlock_rdunlock(&cache->lock); - - return entry; -} - -static void *cache_store(git_cache *cache, git_cached_obj *entry) -{ - git_cached_obj *stored_entry; - - git_cached_obj_incref(entry); - - if (!git_cache__enabled && cache->used_memory > 0) { - git_cache_clear(cache); - return entry; - } - - if (!cache_should_store(entry->type, entry->size)) - return entry; - - if (git_rwlock_wrlock(&cache->lock) < 0) - return entry; - - /* soften the load on the cache */ - if (git_atomic_ssize_get(&git_cache__current_storage) > git_cache__max_storage) - cache_evict_entries(cache); - - /* not found */ - if (git_cache_oidmap_get(&stored_entry, &cache->map, &entry->oid) != 0) { - if (git_cache_oidmap_put(&cache->map, &entry->oid, entry) == 0) { - git_cached_obj_incref(entry); - cache->used_memory += entry->size; - git_atomic_ssize_add(&git_cache__current_storage, (ssize_t)entry->size); - } - } - /* found */ - else { - if (stored_entry->flags == entry->flags) { - git_cached_obj_decref(entry); - git_cached_obj_incref(stored_entry); - entry = stored_entry; - } else if (stored_entry->flags == GIT_CACHE_STORE_RAW && - entry->flags == GIT_CACHE_STORE_PARSED) { - if (git_cache_oidmap_put(&cache->map, &entry->oid, entry) == 0) { - git_cached_obj_decref(stored_entry); - git_cached_obj_incref(entry); - } else { - git_cached_obj_decref(entry); - git_cached_obj_incref(stored_entry); - entry = stored_entry; - } - } else { - /* NO OP */ - } - } - - git_rwlock_wrunlock(&cache->lock); - return entry; -} - -void *git_cache_store_raw(git_cache *cache, git_odb_object *entry) -{ - entry->cached.flags = GIT_CACHE_STORE_RAW; - return cache_store(cache, (git_cached_obj *)entry); -} - -void *git_cache_store_parsed(git_cache *cache, git_object *entry) -{ - entry->cached.flags = GIT_CACHE_STORE_PARSED; - return cache_store(cache, (git_cached_obj *)entry); -} - -git_odb_object *git_cache_get_raw(git_cache *cache, const git_oid *oid) -{ - return cache_get(cache, oid, GIT_CACHE_STORE_RAW); -} - -git_object *git_cache_get_parsed(git_cache *cache, const git_oid *oid) -{ - return cache_get(cache, oid, GIT_CACHE_STORE_PARSED); -} - -void *git_cache_get_any(git_cache *cache, const git_oid *oid) -{ - return cache_get(cache, oid, GIT_CACHE_STORE_ANY); -} - -void git_cached_obj_decref(void *_obj) -{ - git_cached_obj *obj = _obj; - - if (git_atomic32_dec(&obj->refcount) == 0) { - switch (obj->flags) { - case GIT_CACHE_STORE_RAW: - git_odb_object__free(_obj); - break; - - case GIT_CACHE_STORE_PARSED: - git_object__free(_obj); - break; - - default: - git__free(_obj); - break; - } - } -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/cache.h b/vendor/libgit2-sys/libgit2/src/libgit2/cache.h deleted file mode 100644 index 4c14013..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/cache.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_cache_h__ -#define INCLUDE_cache_h__ - -#include "common.h" - -#include "git2/common.h" -#include "git2/oid.h" -#include "git2/odb.h" - -#include "thread.h" -#include "hashmap_oid.h" - -enum { - GIT_CACHE_STORE_ANY = 0, - GIT_CACHE_STORE_RAW = 1, - GIT_CACHE_STORE_PARSED = 2 -}; - -typedef struct { - git_oid oid; - int16_t type; /* git_object_t value */ - uint16_t flags; /* GIT_CACHE_STORE value */ - size_t size; - git_atomic32 refcount; -} git_cached_obj; - -GIT_HASHMAP_OID_STRUCT(git_cache_oidmap, git_cached_obj *); - -typedef struct { - git_cache_oidmap map; - git_rwlock lock; - ssize_t used_memory; -} git_cache; - -extern bool git_cache__enabled; -extern ssize_t git_cache__max_storage; -extern git_atomic_ssize git_cache__current_storage; - -int git_cache_set_max_object_size(git_object_t type, size_t size); - -int git_cache_init(git_cache *cache); -void git_cache_dispose(git_cache *cache); -void git_cache_clear(git_cache *cache); -size_t git_cache_size(git_cache *cache); - -void *git_cache_store_raw(git_cache *cache, git_odb_object *entry); -void *git_cache_store_parsed(git_cache *cache, git_object *entry); - -git_odb_object *git_cache_get_raw(git_cache *cache, const git_oid *oid); -git_object *git_cache_get_parsed(git_cache *cache, const git_oid *oid); -void *git_cache_get_any(git_cache *cache, const git_oid *oid); - -GIT_INLINE(void) git_cached_obj_incref(void *_obj) -{ - git_cached_obj *obj = _obj; - git_atomic32_inc(&obj->refcount); -} - -void git_cached_obj_decref(void *_obj); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/checkout.c b/vendor/libgit2-sys/libgit2/src/libgit2/checkout.c deleted file mode 100644 index f4b1ea9..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/checkout.c +++ /dev/null @@ -1,2823 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "checkout.h" - -#include "git2/repository.h" -#include "git2/refs.h" -#include "git2/tree.h" -#include "git2/blob.h" -#include "git2/config.h" -#include "git2/diff.h" -#include "git2/submodule.h" -#include "git2/sys/index.h" -#include "git2/sys/filter.h" -#include "git2/merge.h" - -#include "refs.h" -#include "repository.h" -#include "index.h" -#include "filter.h" -#include "blob.h" -#include "diff.h" -#include "diff_generate.h" -#include "pathspec.h" -#include "diff_xdiff.h" -#include "fs_path.h" -#include "attr.h" -#include "pool.h" -#include "path.h" -#include "hashmap_str.h" - -/* See docs/checkout-internals.md for more information */ - -enum { - CHECKOUT_ACTION__NONE = 0, - CHECKOUT_ACTION__REMOVE = 1, - CHECKOUT_ACTION__UPDATE_BLOB = 2, - CHECKOUT_ACTION__UPDATE_SUBMODULE = 4, - CHECKOUT_ACTION__CONFLICT = 8, - CHECKOUT_ACTION__REMOVE_CONFLICT = 16, - CHECKOUT_ACTION__UPDATE_CONFLICT = 32, - CHECKOUT_ACTION__MAX = 32, - CHECKOUT_ACTION__REMOVE_AND_UPDATE = - (CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE) -}; - -typedef struct { - git_repository *repo; - git_iterator *target; - git_diff *diff; - git_checkout_options opts; - bool opts_free_baseline; - char *pfx; - git_index *index; - git_pool pool; - git_vector removes; - git_vector remove_conflicts; - git_vector update_conflicts; - git_vector *update_reuc; - git_vector *update_names; - git_str target_path; - size_t target_len; - git_str tmp; - unsigned int strategy; - int can_symlink; - int respect_filemode; - bool reload_submodules; - size_t total_steps; - size_t completed_steps; - git_checkout_perfdata perfdata; - git_hashset_str mkdir_pathcache; - git_attr_session attr_session; -} checkout_data; - -typedef struct { - const git_index_entry *ancestor; - const git_index_entry *ours; - const git_index_entry *theirs; - - unsigned int name_collision:1, - directoryfile:1, - one_to_two:1, - binary:1, - submodule:1; -} checkout_conflictdata; - -static int checkout_notify( - checkout_data *data, - git_checkout_notify_t why, - const git_diff_delta *delta, - const git_index_entry *wditem) -{ - git_diff_file wdfile; - const git_diff_file *baseline = NULL, *target = NULL, *workdir = NULL; - const char *path = NULL; - - if (!data->opts.notify_cb || - (why & data->opts.notify_flags) == 0) - return 0; - - if (wditem) { - memset(&wdfile, 0, sizeof(wdfile)); - - git_oid_cpy(&wdfile.id, &wditem->id); - wdfile.path = wditem->path; - wdfile.size = wditem->file_size; - wdfile.flags = GIT_DIFF_FLAG_VALID_ID; - wdfile.mode = wditem->mode; - - workdir = &wdfile; - - path = wditem->path; - } - - if (delta) { - switch (delta->status) { - case GIT_DELTA_UNMODIFIED: - case GIT_DELTA_MODIFIED: - case GIT_DELTA_TYPECHANGE: - default: - baseline = &delta->old_file; - target = &delta->new_file; - break; - case GIT_DELTA_ADDED: - case GIT_DELTA_IGNORED: - case GIT_DELTA_UNTRACKED: - case GIT_DELTA_UNREADABLE: - target = &delta->new_file; - break; - case GIT_DELTA_DELETED: - baseline = &delta->old_file; - break; - } - - path = delta->old_file.path; - } - - { - int error = data->opts.notify_cb( - why, path, baseline, target, workdir, data->opts.notify_payload); - - return git_error_set_after_callback_function( - error, "git_checkout notification"); - } -} - -GIT_INLINE(bool) is_workdir_base_or_new( - const git_oid *workdir_id, - const git_diff_file *baseitem, - const git_diff_file *newitem) -{ - return (git_oid__cmp(&baseitem->id, workdir_id) == 0 || - git_oid__cmp(&newitem->id, workdir_id) == 0); -} - -GIT_INLINE(bool) is_filemode_changed(git_filemode_t a, git_filemode_t b, int respect_filemode) -{ - /* If core.filemode = false, ignore links in the repository and executable bit changes */ - if (!respect_filemode) { - if (a == S_IFLNK) - a = GIT_FILEMODE_BLOB; - if (b == S_IFLNK) - b = GIT_FILEMODE_BLOB; - - a &= ~0111; - b &= ~0111; - } - - return (a != b); -} - -static bool checkout_is_workdir_modified( - checkout_data *data, - const git_diff_file *baseitem, - const git_diff_file *newitem, - const git_index_entry *wditem) -{ - git_oid oid; - const git_index_entry *ie; - - /* handle "modified" submodule */ - if (wditem->mode == GIT_FILEMODE_COMMIT) { - git_submodule *sm; - unsigned int sm_status = 0; - const git_oid *sm_oid = NULL; - bool rval = false; - - if (git_submodule_lookup(&sm, data->repo, wditem->path) < 0) { - git_error_clear(); - return true; - } - - if (git_submodule_status(&sm_status, data->repo, wditem->path, GIT_SUBMODULE_IGNORE_UNSPECIFIED) < 0 || - GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status)) - rval = true; - else if ((sm_oid = git_submodule_wd_id(sm)) == NULL) - rval = false; - else - rval = (git_oid__cmp(&baseitem->id, sm_oid) != 0); - - git_submodule_free(sm); - return rval; - } - - /* - * Look at the cache to decide if the workdir is modified: if the - * cache contents match the workdir contents, then we do not need - * to examine the working directory directly, instead we can - * examine the cache to see if _it_ has been modified. This allows - * us to avoid touching the disk. - */ - ie = git_index_get_bypath(data->index, wditem->path, 0); - - if (ie != NULL && - !git_index_entry_newer_than_index(ie, data->index) && - git_index_time_eq(&wditem->mtime, &ie->mtime) && - wditem->file_size == ie->file_size && - !is_filemode_changed(wditem->mode, ie->mode, data->respect_filemode)) { - - /* The workdir is modified iff the index entry is modified */ - return !is_workdir_base_or_new(&ie->id, baseitem, newitem) || - is_filemode_changed(baseitem->mode, ie->mode, data->respect_filemode); - } - - /* depending on where base is coming from, we may or may not know - * the actual size of the data, so we can't rely on this shortcut. - */ - if (baseitem->size && wditem->file_size != baseitem->size) - return true; - - /* if the workdir item is a directory, it cannot be a modified file */ - if (S_ISDIR(wditem->mode)) - return false; - - if (is_filemode_changed(baseitem->mode, wditem->mode, data->respect_filemode)) - return true; - - if (git_diff__oid_for_entry(&oid, data->diff, wditem, wditem->mode, NULL) < 0) - return false; - - /* Allow the checkout if the workdir is not modified *or* if the checkout - * target's contents are already in the working directory. - */ - return !is_workdir_base_or_new(&oid, baseitem, newitem); -} - -#define CHECKOUT_ACTION_IF(FLAG,YES,NO) \ - ((data->strategy & GIT_CHECKOUT_##FLAG) ? CHECKOUT_ACTION__##YES : CHECKOUT_ACTION__##NO) - -static int checkout_action_common( - int *action, - checkout_data *data, - const git_diff_delta *delta, - const git_index_entry *wd) -{ - git_checkout_notify_t notify = GIT_CHECKOUT_NOTIFY_NONE; - - if ((data->strategy & GIT_CHECKOUT_UPDATE_ONLY) != 0) - *action = (*action & ~CHECKOUT_ACTION__REMOVE); - - if ((*action & CHECKOUT_ACTION__UPDATE_BLOB) != 0) { - if (S_ISGITLINK(delta->new_file.mode)) - *action = (*action & ~CHECKOUT_ACTION__UPDATE_BLOB) | - CHECKOUT_ACTION__UPDATE_SUBMODULE; - - /* to "update" a symlink, we must remove the old one first */ - if (delta->new_file.mode == GIT_FILEMODE_LINK && wd != NULL) - *action |= CHECKOUT_ACTION__REMOVE; - - /* if the file is on disk and doesn't match our mode, force update */ - if (wd && - GIT_PERMS_IS_EXEC(wd->mode) != GIT_PERMS_IS_EXEC(delta->new_file.mode)) - *action |= CHECKOUT_ACTION__REMOVE; - - notify = GIT_CHECKOUT_NOTIFY_UPDATED; - } - - if ((*action & CHECKOUT_ACTION__CONFLICT) != 0) - notify = GIT_CHECKOUT_NOTIFY_CONFLICT; - - return checkout_notify(data, notify, delta, wd); -} - -static int checkout_action_no_wd( - int *action, - checkout_data *data, - const git_diff_delta *delta) -{ - int error = 0; - - *action = CHECKOUT_ACTION__NONE; - - if ((data->strategy & GIT_CHECKOUT_NONE)) - return 0; - - switch (delta->status) { - case GIT_DELTA_UNMODIFIED: /* case 12 */ - error = checkout_notify(data, GIT_CHECKOUT_NOTIFY_DIRTY, delta, NULL); - if (error) - return error; - *action = CHECKOUT_ACTION_IF(RECREATE_MISSING, UPDATE_BLOB, NONE); - break; - case GIT_DELTA_ADDED: /* case 2 or 28 (and 5 but not really) */ - *action = CHECKOUT_ACTION__UPDATE_BLOB; - break; - case GIT_DELTA_MODIFIED: /* case 13 (and 35 but not really) */ - *action = CHECKOUT_ACTION_IF(RECREATE_MISSING, UPDATE_BLOB, CONFLICT); - break; - case GIT_DELTA_TYPECHANGE: /* case 21 (B->T) and 28 (T->B)*/ - if (delta->new_file.mode == GIT_FILEMODE_TREE) - *action = CHECKOUT_ACTION__UPDATE_BLOB; - break; - case GIT_DELTA_DELETED: /* case 8 or 25 */ - *action = CHECKOUT_ACTION__REMOVE; - break; - default: /* impossible */ - break; - } - - return checkout_action_common(action, data, delta, NULL); -} - -static int checkout_target_fullpath( - git_str **out, checkout_data *data, const char *path) -{ - git_str_truncate(&data->target_path, data->target_len); - - if (path && git_str_puts(&data->target_path, path) < 0) - return -1; - - if (git_path_validate_str_length(data->repo, &data->target_path) < 0) - return -1; - - *out = &data->target_path; - - return 0; -} - -static bool wd_item_is_removable( - checkout_data *data, const git_index_entry *wd) -{ - git_str *full; - - if (wd->mode != GIT_FILEMODE_TREE) - return true; - - if (checkout_target_fullpath(&full, data, wd->path) < 0) - return false; - - return !full || !git_fs_path_contains(full, DOT_GIT); -} - -static int checkout_queue_remove(checkout_data *data, const char *path) -{ - char *copy = git_pool_strdup(&data->pool, path); - GIT_ERROR_CHECK_ALLOC(copy); - return git_vector_insert(&data->removes, copy); -} - -/* note that this advances the iterator over the wd item */ -static int checkout_action_wd_only( - checkout_data *data, - git_iterator *workdir, - const git_index_entry **wditem, - git_vector *pathspec) -{ - int error = 0; - bool remove = false; - git_checkout_notify_t notify = GIT_CHECKOUT_NOTIFY_NONE; - const git_index_entry *wd = *wditem; - - if (!git_pathspec__match( - pathspec, wd->path, - (data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0, - git_iterator_ignore_case(workdir), NULL, NULL)) { - - if (wd->mode == GIT_FILEMODE_TREE) - return git_iterator_advance_into(wditem, workdir); - else - return git_iterator_advance(wditem, workdir); - } - - /* check if item is tracked in the index but not in the checkout diff */ - if (data->index != NULL) { - size_t pos; - - error = git_index__find_pos( - &pos, data->index, wd->path, 0, GIT_INDEX_STAGE_ANY); - - if (wd->mode != GIT_FILEMODE_TREE) { - if (!error) { /* found by git_index__find_pos call */ - notify = GIT_CHECKOUT_NOTIFY_DIRTY; - remove = ((data->strategy & GIT_CHECKOUT_FORCE) != 0); - } else if (error != GIT_ENOTFOUND) - return error; - else - error = 0; /* git_index__find_pos does not set error msg */ - } else { - /* for tree entries, we have to see if there are any index - * entries that are contained inside that tree - */ - const git_index_entry *e = git_index_get_byindex(data->index, pos); - - if (e != NULL && data->diff->pfxcomp(e->path, wd->path) == 0) - return git_iterator_advance_into(wditem, workdir); - } - } - - if (notify != GIT_CHECKOUT_NOTIFY_NONE) { - /* if we found something in the index, notify and advance */ - if ((error = checkout_notify(data, notify, NULL, wd)) != 0) - return error; - - if (remove && wd_item_is_removable(data, wd)) - error = checkout_queue_remove(data, wd->path); - - if (!error) - error = git_iterator_advance(wditem, workdir); - } else { - /* untracked or ignored - can't know which until we advance through */ - bool over = false, removable = wd_item_is_removable(data, wd); - git_iterator_status_t untracked_state; - - /* copy the entry for issuing notification callback later */ - git_index_entry saved_wd = *wd; - git_str_sets(&data->tmp, wd->path); - saved_wd.path = data->tmp.ptr; - - error = git_iterator_advance_over( - wditem, &untracked_state, workdir); - if (error == GIT_ITEROVER) - over = true; - else if (error < 0) - return error; - - if (untracked_state == GIT_ITERATOR_STATUS_IGNORED) { - notify = GIT_CHECKOUT_NOTIFY_IGNORED; - remove = ((data->strategy & GIT_CHECKOUT_REMOVE_IGNORED) != 0); - } else { - notify = GIT_CHECKOUT_NOTIFY_UNTRACKED; - remove = ((data->strategy & GIT_CHECKOUT_REMOVE_UNTRACKED) != 0); - } - - if ((error = checkout_notify(data, notify, NULL, &saved_wd)) != 0) - return error; - - if (remove && removable) - error = checkout_queue_remove(data, saved_wd.path); - - if (!error && over) /* restore ITEROVER if needed */ - error = GIT_ITEROVER; - } - - return error; -} - -static bool submodule_is_config_only( - checkout_data *data, - const char *path) -{ - git_submodule *sm = NULL; - unsigned int sm_loc = 0; - bool rval = false; - - if (git_submodule_lookup(&sm, data->repo, path) < 0) - return true; - - if (git_submodule_location(&sm_loc, sm) < 0 || - sm_loc == GIT_SUBMODULE_STATUS_IN_CONFIG) - rval = true; - - git_submodule_free(sm); - - return rval; -} - -static bool checkout_is_empty_dir(checkout_data *data, const char *path) -{ - git_str *fullpath; - - if (checkout_target_fullpath(&fullpath, data, path) < 0) - return false; - - return git_fs_path_is_empty_dir(fullpath->ptr); -} - -static int checkout_action_with_wd( - int *action, - checkout_data *data, - const git_diff_delta *delta, - git_iterator *workdir, - const git_index_entry *wd) -{ - *action = CHECKOUT_ACTION__NONE; - - if ((data->strategy & GIT_CHECKOUT_NONE)) - return 0; - - switch (delta->status) { - case GIT_DELTA_UNMODIFIED: /* case 14/15 or 33 */ - if (checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd)) { - GIT_ERROR_CHECK_ERROR( - checkout_notify(data, GIT_CHECKOUT_NOTIFY_DIRTY, delta, wd) ); - *action = CHECKOUT_ACTION_IF(FORCE, UPDATE_BLOB, NONE); - } - break; - case GIT_DELTA_ADDED: /* case 3, 4 or 6 */ - if (git_iterator_current_is_ignored(workdir)) - *action = CHECKOUT_ACTION_IF(DONT_OVERWRITE_IGNORED, CONFLICT, UPDATE_BLOB); - else - *action = CHECKOUT_ACTION_IF(FORCE, UPDATE_BLOB, CONFLICT); - break; - case GIT_DELTA_DELETED: /* case 9 or 10 (or 26 but not really) */ - if (checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd)) - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE, CONFLICT); - else - *action = CHECKOUT_ACTION__REMOVE; - break; - case GIT_DELTA_MODIFIED: /* case 16, 17, 18 (or 36 but not really) */ - if (wd->mode != GIT_FILEMODE_COMMIT && - checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd)) - *action = CHECKOUT_ACTION_IF(FORCE, UPDATE_BLOB, CONFLICT); - else - *action = CHECKOUT_ACTION__UPDATE_BLOB; - break; - case GIT_DELTA_TYPECHANGE: /* case 22, 23, 29, 30 */ - if (delta->old_file.mode == GIT_FILEMODE_TREE) { - if (wd->mode == GIT_FILEMODE_TREE) - /* either deleting items in old tree will delete the wd dir, - * or we'll get a conflict when we attempt blob update... - */ - *action = CHECKOUT_ACTION__UPDATE_BLOB; - else if (wd->mode == GIT_FILEMODE_COMMIT) { - /* workdir is possibly a "phantom" submodule - treat as a - * tree if the only submodule info came from the config - */ - if (submodule_is_config_only(data, wd->path)) - *action = CHECKOUT_ACTION__UPDATE_BLOB; - else - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, CONFLICT); - } else - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE, CONFLICT); - } - else if (checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd)) - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, CONFLICT); - else - *action = CHECKOUT_ACTION__REMOVE_AND_UPDATE; - - /* don't update if the typechange is to a tree */ - if (delta->new_file.mode == GIT_FILEMODE_TREE) - *action = (*action & ~CHECKOUT_ACTION__UPDATE_BLOB); - break; - default: /* impossible */ - break; - } - - return checkout_action_common(action, data, delta, wd); -} - -static int checkout_action_with_wd_blocker( - int *action, - checkout_data *data, - const git_diff_delta *delta, - const git_index_entry *wd) -{ - *action = CHECKOUT_ACTION__NONE; - - if ((data->strategy & GIT_CHECKOUT_NONE)) - return 0; - - switch (delta->status) { - case GIT_DELTA_UNMODIFIED: - /* should show delta as dirty / deleted */ - GIT_ERROR_CHECK_ERROR( - checkout_notify(data, GIT_CHECKOUT_NOTIFY_DIRTY, delta, wd) ); - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, NONE); - break; - case GIT_DELTA_ADDED: - case GIT_DELTA_MODIFIED: - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, CONFLICT); - break; - case GIT_DELTA_DELETED: - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE, CONFLICT); - break; - case GIT_DELTA_TYPECHANGE: - /* not 100% certain about this... */ - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, CONFLICT); - break; - default: /* impossible */ - break; - } - - return checkout_action_common(action, data, delta, wd); -} - -static int checkout_action_with_wd_dir( - int *action, - checkout_data *data, - const git_diff_delta *delta, - git_iterator *workdir, - const git_index_entry *wd) -{ - *action = CHECKOUT_ACTION__NONE; - - if ((data->strategy & GIT_CHECKOUT_NONE)) - return 0; - - switch (delta->status) { - case GIT_DELTA_UNMODIFIED: /* case 19 or 24 (or 34 but not really) */ - GIT_ERROR_CHECK_ERROR( - checkout_notify(data, GIT_CHECKOUT_NOTIFY_DIRTY, delta, NULL)); - GIT_ERROR_CHECK_ERROR( - checkout_notify(data, GIT_CHECKOUT_NOTIFY_UNTRACKED, NULL, wd)); - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, NONE); - break; - case GIT_DELTA_ADDED:/* case 4 (and 7 for dir) */ - case GIT_DELTA_MODIFIED: /* case 20 (or 37 but not really) */ - if (delta->old_file.mode == GIT_FILEMODE_COMMIT) - /* expected submodule (and maybe found one) */; - else if (delta->new_file.mode != GIT_FILEMODE_TREE) - *action = git_iterator_current_is_ignored(workdir) ? - CHECKOUT_ACTION_IF(DONT_OVERWRITE_IGNORED, CONFLICT, REMOVE_AND_UPDATE) : - CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, CONFLICT); - break; - case GIT_DELTA_DELETED: /* case 11 (and 27 for dir) */ - if (delta->old_file.mode != GIT_FILEMODE_TREE) - GIT_ERROR_CHECK_ERROR( - checkout_notify(data, GIT_CHECKOUT_NOTIFY_UNTRACKED, NULL, wd)); - break; - case GIT_DELTA_TYPECHANGE: /* case 24 or 31 */ - if (delta->old_file.mode == GIT_FILEMODE_TREE) { - /* For typechange from dir, remove dir and add blob, but it is - * not safe to remove dir if it contains modified files. - * However, safely removing child files will remove the parent - * directory if is it left empty, so we can defer removing the - * dir and it will succeed if no children are left. - */ - *action = CHECKOUT_ACTION__UPDATE_BLOB; - } - else if (delta->new_file.mode != GIT_FILEMODE_TREE) - /* For typechange to dir, dir is already created so no action */ - *action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, CONFLICT); - break; - default: /* impossible */ - break; - } - - return checkout_action_common(action, data, delta, wd); -} - -static int checkout_action_with_wd_dir_empty( - int *action, - checkout_data *data, - const git_diff_delta *delta) -{ - int error = checkout_action_no_wd(action, data, delta); - - /* We can always safely remove an empty directory. */ - if (error == 0 && *action != CHECKOUT_ACTION__NONE) - *action |= CHECKOUT_ACTION__REMOVE; - - return error; -} - -static int checkout_action( - int *action, - checkout_data *data, - git_diff_delta *delta, - git_iterator *workdir, - const git_index_entry **wditem, - git_vector *pathspec) -{ - int cmp = -1, error; - int (*strcomp)(const char *, const char *) = data->diff->strcomp; - int (*pfxcomp)(const char *str, const char *pfx) = data->diff->pfxcomp; - int (*advance)(const git_index_entry **, git_iterator *) = NULL; - - /* move workdir iterator to follow along with deltas */ - - while (1) { - const git_index_entry *wd = *wditem; - - if (!wd) - return checkout_action_no_wd(action, data, delta); - - cmp = strcomp(wd->path, delta->old_file.path); - - /* 1. wd before delta ("a/a" before "a/b") - * 2. wd prefixes delta & should expand ("a/" before "a/b") - * 3. wd prefixes delta & cannot expand ("a/b" before "a/b/c") - * 4. wd equals delta ("a/b" and "a/b") - * 5. wd after delta & delta prefixes wd ("a/b/c" after "a/b/" or "a/b") - * 6. wd after delta ("a/c" after "a/b") - */ - - if (cmp < 0) { - cmp = pfxcomp(delta->old_file.path, wd->path); - - if (cmp == 0) { - if (wd->mode == GIT_FILEMODE_TREE) { - /* case 2 - entry prefixed by workdir tree */ - error = git_iterator_advance_into(wditem, workdir); - if (error < 0 && error != GIT_ITEROVER) - goto done; - continue; - } - - /* case 3 maybe - wd contains non-dir where dir expected */ - if (delta->old_file.path[strlen(wd->path)] == '/') { - error = checkout_action_with_wd_blocker( - action, data, delta, wd); - advance = git_iterator_advance; - goto done; - } - } - - /* case 1 - handle wd item (if it matches pathspec) */ - error = checkout_action_wd_only(data, workdir, wditem, pathspec); - if (error && error != GIT_ITEROVER) - goto done; - continue; - } - - if (cmp == 0) { - /* case 4 */ - error = checkout_action_with_wd(action, data, delta, workdir, wd); - advance = git_iterator_advance; - goto done; - } - - cmp = pfxcomp(wd->path, delta->old_file.path); - - if (cmp == 0) { /* case 5 */ - if (wd->path[strlen(delta->old_file.path)] != '/') - return checkout_action_no_wd(action, data, delta); - - if (delta->status == GIT_DELTA_TYPECHANGE) { - if (delta->old_file.mode == GIT_FILEMODE_TREE) { - error = checkout_action_with_wd(action, data, delta, workdir, wd); - advance = git_iterator_advance_into; - goto done; - } - - if (delta->new_file.mode == GIT_FILEMODE_TREE || - delta->new_file.mode == GIT_FILEMODE_COMMIT || - delta->old_file.mode == GIT_FILEMODE_COMMIT) - { - error = checkout_action_with_wd(action, data, delta, workdir, wd); - advance = git_iterator_advance; - goto done; - } - } - - return checkout_is_empty_dir(data, wd->path) ? - checkout_action_with_wd_dir_empty(action, data, delta) : - checkout_action_with_wd_dir(action, data, delta, workdir, wd); - } - - /* case 6 - wd is after delta */ - return checkout_action_no_wd(action, data, delta); - } - -done: - if (!error && advance != NULL && - (error = advance(wditem, workdir)) < 0) { - *wditem = NULL; - if (error == GIT_ITEROVER) - error = 0; - } - - return error; -} - -static int checkout_remaining_wd_items( - checkout_data *data, - git_iterator *workdir, - const git_index_entry *wd, - git_vector *spec) -{ - int error = 0; - - while (wd && !error) - error = checkout_action_wd_only(data, workdir, &wd, spec); - - if (error == GIT_ITEROVER) - error = 0; - - return error; -} - -GIT_INLINE(int) checkout_idxentry_cmp( - const git_index_entry *a, - const git_index_entry *b) -{ - if (!a && !b) - return 0; - else if (!a && b) - return -1; - else if(a && !b) - return 1; - else - return strcmp(a->path, b->path); -} - -static int checkout_conflictdata_cmp(const void *a, const void *b) -{ - const checkout_conflictdata *ca = a; - const checkout_conflictdata *cb = b; - int diff; - - if ((diff = checkout_idxentry_cmp(ca->ancestor, cb->ancestor)) == 0 && - (diff = checkout_idxentry_cmp(ca->ours, cb->theirs)) == 0) - diff = checkout_idxentry_cmp(ca->theirs, cb->theirs); - - return diff; -} - -static int checkout_conflictdata_empty( - const git_vector *conflicts, size_t idx, void *payload) -{ - checkout_conflictdata *conflict; - - GIT_UNUSED(payload); - - if ((conflict = git_vector_get(conflicts, idx)) == NULL) - return -1; - - if (conflict->ancestor || conflict->ours || conflict->theirs) - return 0; - - git__free(conflict); - return 1; -} - -GIT_INLINE(bool) conflict_pathspec_match( - checkout_data *data, - git_iterator *workdir, - git_vector *pathspec, - const git_index_entry *ancestor, - const git_index_entry *ours, - const git_index_entry *theirs) -{ - /* if the pathspec matches ours *or* theirs, proceed */ - if (ours && git_pathspec__match(pathspec, ours->path, - (data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0, - git_iterator_ignore_case(workdir), NULL, NULL)) - return true; - - if (theirs && git_pathspec__match(pathspec, theirs->path, - (data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0, - git_iterator_ignore_case(workdir), NULL, NULL)) - return true; - - if (ancestor && git_pathspec__match(pathspec, ancestor->path, - (data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0, - git_iterator_ignore_case(workdir), NULL, NULL)) - return true; - - return false; -} - -GIT_INLINE(int) checkout_conflict_detect_submodule(checkout_conflictdata *conflict) -{ - conflict->submodule = ((conflict->ancestor && S_ISGITLINK(conflict->ancestor->mode)) || - (conflict->ours && S_ISGITLINK(conflict->ours->mode)) || - (conflict->theirs && S_ISGITLINK(conflict->theirs->mode))); - return 0; -} - -GIT_INLINE(int) checkout_conflict_detect_binary(git_repository *repo, checkout_conflictdata *conflict) -{ - git_blob *ancestor_blob = NULL, *our_blob = NULL, *their_blob = NULL; - int error = 0; - - if (conflict->submodule) - return 0; - - if (conflict->ancestor) { - if ((error = git_blob_lookup(&ancestor_blob, repo, &conflict->ancestor->id)) < 0) - goto done; - - conflict->binary = git_blob_is_binary(ancestor_blob); - } - - if (!conflict->binary && conflict->ours) { - if ((error = git_blob_lookup(&our_blob, repo, &conflict->ours->id)) < 0) - goto done; - - conflict->binary = git_blob_is_binary(our_blob); - } - - if (!conflict->binary && conflict->theirs) { - if ((error = git_blob_lookup(&their_blob, repo, &conflict->theirs->id)) < 0) - goto done; - - conflict->binary = git_blob_is_binary(their_blob); - } - -done: - git_blob_free(ancestor_blob); - git_blob_free(our_blob); - git_blob_free(their_blob); - - return error; -} - -static int checkout_conflict_append_update( - const git_index_entry *ancestor, - const git_index_entry *ours, - const git_index_entry *theirs, - void *payload) -{ - checkout_data *data = payload; - checkout_conflictdata *conflict; - int error; - - conflict = git__calloc(1, sizeof(checkout_conflictdata)); - GIT_ERROR_CHECK_ALLOC(conflict); - - conflict->ancestor = ancestor; - conflict->ours = ours; - conflict->theirs = theirs; - - if ((error = checkout_conflict_detect_submodule(conflict)) < 0 || - (error = checkout_conflict_detect_binary(data->repo, conflict)) < 0) - { - git__free(conflict); - return error; - } - - if (git_vector_insert(&data->update_conflicts, conflict)) - return -1; - - return 0; -} - -static int checkout_conflicts_foreach( - checkout_data *data, - git_index *index, - git_iterator *workdir, - git_vector *pathspec, - int (*cb)(const git_index_entry *, const git_index_entry *, const git_index_entry *, void *), - void *payload) -{ - git_index_conflict_iterator *iterator = NULL; - const git_index_entry *ancestor, *ours, *theirs; - int error = 0; - - if ((error = git_index_conflict_iterator_new(&iterator, index)) < 0) - goto done; - - /* Collect the conflicts */ - while ((error = git_index_conflict_next(&ancestor, &ours, &theirs, iterator)) == 0) { - if (!conflict_pathspec_match(data, workdir, pathspec, ancestor, ours, theirs)) - continue; - - if ((error = cb(ancestor, ours, theirs, payload)) < 0) - goto done; - } - - if (error == GIT_ITEROVER) - error = 0; - -done: - git_index_conflict_iterator_free(iterator); - - return error; -} - -static int checkout_conflicts_load(checkout_data *data, git_iterator *workdir, git_vector *pathspec) -{ - git_index *index; - - /* Only write conflicts from sources that have them: indexes. */ - if ((index = git_iterator_index(data->target)) == NULL) - return 0; - - data->update_conflicts._cmp = checkout_conflictdata_cmp; - - if (checkout_conflicts_foreach(data, index, workdir, pathspec, checkout_conflict_append_update, data) < 0) - return -1; - - /* Collect the REUC and NAME entries */ - data->update_reuc = &index->reuc; - data->update_names = &index->names; - - return 0; -} - -GIT_INLINE(int) checkout_conflicts_cmp_entry( - const char *path, - const git_index_entry *entry) -{ - return strcmp((const char *)path, entry->path); -} - -static int checkout_conflicts_cmp_ancestor(const void *p, const void *c) -{ - const char *path = p; - const checkout_conflictdata *conflict = c; - - if (!conflict->ancestor) - return 1; - - return checkout_conflicts_cmp_entry(path, conflict->ancestor); -} - -static checkout_conflictdata *checkout_conflicts_search_ancestor( - checkout_data *data, - const char *path) -{ - size_t pos; - - if (git_vector_bsearch2(&pos, &data->update_conflicts, checkout_conflicts_cmp_ancestor, path) < 0) - return NULL; - - return git_vector_get(&data->update_conflicts, pos); -} - -static checkout_conflictdata *checkout_conflicts_search_branch( - checkout_data *data, - const char *path) -{ - checkout_conflictdata *conflict; - size_t i; - - git_vector_foreach(&data->update_conflicts, i, conflict) { - int cmp = -1; - - if (conflict->ancestor) - break; - - if (conflict->ours) - cmp = checkout_conflicts_cmp_entry(path, conflict->ours); - else if (conflict->theirs) - cmp = checkout_conflicts_cmp_entry(path, conflict->theirs); - - if (cmp == 0) - return conflict; - } - - return NULL; -} - -static int checkout_conflicts_load_byname_entry( - checkout_conflictdata **ancestor_out, - checkout_conflictdata **ours_out, - checkout_conflictdata **theirs_out, - checkout_data *data, - const git_index_name_entry *name_entry) -{ - checkout_conflictdata *ancestor, *ours = NULL, *theirs = NULL; - int error = 0; - - *ancestor_out = NULL; - *ours_out = NULL; - *theirs_out = NULL; - - if (!name_entry->ancestor) { - git_error_set(GIT_ERROR_INDEX, "a NAME entry exists without an ancestor"); - error = -1; - goto done; - } - - if (!name_entry->ours && !name_entry->theirs) { - git_error_set(GIT_ERROR_INDEX, "a NAME entry exists without an ours or theirs"); - error = -1; - goto done; - } - - if ((ancestor = checkout_conflicts_search_ancestor(data, - name_entry->ancestor)) == NULL) { - git_error_set(GIT_ERROR_INDEX, - "a NAME entry referenced ancestor entry '%s' which does not exist in the main index", - name_entry->ancestor); - error = -1; - goto done; - } - - if (name_entry->ours) { - if (strcmp(name_entry->ancestor, name_entry->ours) == 0) - ours = ancestor; - else if ((ours = checkout_conflicts_search_branch(data, name_entry->ours)) == NULL || - ours->ours == NULL) { - git_error_set(GIT_ERROR_INDEX, - "a NAME entry referenced our entry '%s' which does not exist in the main index", - name_entry->ours); - error = -1; - goto done; - } - } - - if (name_entry->theirs) { - if (strcmp(name_entry->ancestor, name_entry->theirs) == 0) - theirs = ancestor; - else if (name_entry->ours && strcmp(name_entry->ours, name_entry->theirs) == 0) - theirs = ours; - else if ((theirs = checkout_conflicts_search_branch(data, name_entry->theirs)) == NULL || - theirs->theirs == NULL) { - git_error_set(GIT_ERROR_INDEX, - "a NAME entry referenced their entry '%s' which does not exist in the main index", - name_entry->theirs); - error = -1; - goto done; - } - } - - *ancestor_out = ancestor; - *ours_out = ours; - *theirs_out = theirs; - -done: - return error; -} - -static int checkout_conflicts_coalesce_renames( - checkout_data *data) -{ - git_index *index; - const git_index_name_entry *name_entry; - checkout_conflictdata *ancestor_conflict, *our_conflict, *their_conflict; - size_t i, names; - int error = 0; - - if ((index = git_iterator_index(data->target)) == NULL) - return 0; - - /* Juggle entries based on renames */ - names = git_index_name_entrycount(index); - - for (i = 0; i < names; i++) { - name_entry = git_index_name_get_byindex(index, i); - - if ((error = checkout_conflicts_load_byname_entry( - &ancestor_conflict, &our_conflict, &their_conflict, - data, name_entry)) < 0) - goto done; - - if (our_conflict && our_conflict != ancestor_conflict) { - ancestor_conflict->ours = our_conflict->ours; - our_conflict->ours = NULL; - - if (our_conflict->theirs) - our_conflict->name_collision = 1; - - if (our_conflict->name_collision) - ancestor_conflict->name_collision = 1; - } - - if (their_conflict && their_conflict != ancestor_conflict) { - ancestor_conflict->theirs = their_conflict->theirs; - their_conflict->theirs = NULL; - - if (their_conflict->ours) - their_conflict->name_collision = 1; - - if (their_conflict->name_collision) - ancestor_conflict->name_collision = 1; - } - - if (our_conflict && our_conflict != ancestor_conflict && - their_conflict && their_conflict != ancestor_conflict) - ancestor_conflict->one_to_two = 1; - } - - git_vector_remove_matching( - &data->update_conflicts, checkout_conflictdata_empty, NULL); - -done: - return error; -} - -static int checkout_conflicts_mark_directoryfile( - checkout_data *data) -{ - git_index *index; - checkout_conflictdata *conflict; - const git_index_entry *entry; - size_t i, j, len; - const char *path; - int prefixed, error = 0; - - if ((index = git_iterator_index(data->target)) == NULL) - return 0; - - len = git_index_entrycount(index); - - /* Find d/f conflicts */ - git_vector_foreach(&data->update_conflicts, i, conflict) { - if ((conflict->ours && conflict->theirs) || - (!conflict->ours && !conflict->theirs)) - continue; - - path = conflict->ours ? - conflict->ours->path : conflict->theirs->path; - - if ((error = git_index_find(&j, index, path)) < 0) { - if (error == GIT_ENOTFOUND) - git_error_set(GIT_ERROR_INDEX, - "index inconsistency, could not find entry for expected conflict '%s'", path); - - goto done; - } - - for (; j < len; j++) { - if ((entry = git_index_get_byindex(index, j)) == NULL) { - git_error_set(GIT_ERROR_INDEX, - "index inconsistency, truncated index while loading expected conflict '%s'", path); - error = -1; - goto done; - } - - prefixed = git_fs_path_equal_or_prefixed(path, entry->path, NULL); - - if (prefixed == GIT_FS_PATH_EQUAL) - continue; - - if (prefixed == GIT_FS_PATH_PREFIX) - conflict->directoryfile = 1; - - break; - } - } - -done: - return error; -} - -static int checkout_get_update_conflicts( - checkout_data *data, - git_iterator *workdir, - git_vector *pathspec) -{ - int error = 0; - - if (data->strategy & GIT_CHECKOUT_SKIP_UNMERGED) - return 0; - - if ((error = checkout_conflicts_load(data, workdir, pathspec)) < 0 || - (error = checkout_conflicts_coalesce_renames(data)) < 0 || - (error = checkout_conflicts_mark_directoryfile(data)) < 0) - goto done; - -done: - return error; -} - -static int checkout_conflict_append_remove( - const git_index_entry *ancestor, - const git_index_entry *ours, - const git_index_entry *theirs, - void *payload) -{ - checkout_data *data = payload; - const char *name; - - GIT_ASSERT_ARG(ancestor || ours || theirs); - - if (ancestor) - name = git__strdup(ancestor->path); - else if (ours) - name = git__strdup(ours->path); - else if (theirs) - name = git__strdup(theirs->path); - else - abort(); - - GIT_ERROR_CHECK_ALLOC(name); - - return git_vector_insert(&data->remove_conflicts, (char *)name); -} - -static int checkout_get_remove_conflicts( - checkout_data *data, - git_iterator *workdir, - git_vector *pathspec) -{ - if ((data->strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) != 0) - return 0; - - return checkout_conflicts_foreach(data, data->index, workdir, pathspec, checkout_conflict_append_remove, data); -} - -static int checkout_verify_paths( - git_repository *repo, - int action, - git_diff_delta *delta) -{ - unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS; - - if (action & CHECKOUT_ACTION__REMOVE) { - if (!git_path_is_valid(repo, delta->old_file.path, delta->old_file.mode, flags)) { - git_error_set(GIT_ERROR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path); - return -1; - } - } - - if (action & ~CHECKOUT_ACTION__REMOVE) { - if (!git_path_is_valid(repo, delta->new_file.path, delta->new_file.mode, flags)) { - git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path); - return -1; - } - } - - return 0; -} - -static int checkout_get_actions( - uint32_t **actions_ptr, - size_t **counts_ptr, - checkout_data *data, - git_iterator *workdir) -{ - int error = 0, act; - const git_index_entry *wditem; - git_vector pathspec = GIT_VECTOR_INIT, *deltas; - git_pool pathpool; - git_diff_delta *delta; - size_t i, *counts = NULL; - uint32_t *actions = NULL; - - if (git_pool_init(&pathpool, 1) < 0) - return -1; - - if (data->opts.paths.count > 0 && - git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0) - return -1; - - if ((error = git_iterator_current(&wditem, workdir)) < 0 && - error != GIT_ITEROVER) - goto fail; - - deltas = &data->diff->deltas; - - *counts_ptr = counts = git__calloc(CHECKOUT_ACTION__MAX+1, sizeof(size_t)); - *actions_ptr = actions = git__calloc( - deltas->length ? deltas->length : 1, sizeof(uint32_t)); - if (!counts || !actions) { - error = -1; - goto fail; - } - - git_vector_foreach(deltas, i, delta) { - if ((error = checkout_action(&act, data, delta, workdir, &wditem, &pathspec)) == 0) - error = checkout_verify_paths(data->repo, act, delta); - - if (error != 0) - goto fail; - - actions[i] = act; - - if (act & CHECKOUT_ACTION__REMOVE) - counts[CHECKOUT_ACTION__REMOVE]++; - if (act & CHECKOUT_ACTION__UPDATE_BLOB) - counts[CHECKOUT_ACTION__UPDATE_BLOB]++; - if (act & CHECKOUT_ACTION__UPDATE_SUBMODULE) - counts[CHECKOUT_ACTION__UPDATE_SUBMODULE]++; - if (act & CHECKOUT_ACTION__CONFLICT) - counts[CHECKOUT_ACTION__CONFLICT]++; - } - - error = checkout_remaining_wd_items(data, workdir, wditem, &pathspec); - if (error) - goto fail; - - counts[CHECKOUT_ACTION__REMOVE] += data->removes.length; - - if (counts[CHECKOUT_ACTION__CONFLICT] > 0 && - (data->strategy & GIT_CHECKOUT_ALLOW_CONFLICTS) == 0) { - git_error_set(GIT_ERROR_CHECKOUT, "%"PRIuZ" %s checkout", - counts[CHECKOUT_ACTION__CONFLICT], - counts[CHECKOUT_ACTION__CONFLICT] == 1 ? - "conflict prevents" : "conflicts prevent"); - error = GIT_ECONFLICT; - goto fail; - } - - - if ((error = checkout_get_remove_conflicts(data, workdir, &pathspec)) < 0 || - (error = checkout_get_update_conflicts(data, workdir, &pathspec)) < 0) - goto fail; - - counts[CHECKOUT_ACTION__REMOVE_CONFLICT] = git_vector_length(&data->remove_conflicts); - counts[CHECKOUT_ACTION__UPDATE_CONFLICT] = git_vector_length(&data->update_conflicts); - - git_pathspec__vfree(&pathspec); - git_pool_clear(&pathpool); - - return 0; - -fail: - *counts_ptr = NULL; - git__free(counts); - *actions_ptr = NULL; - git__free(actions); - - git_pathspec__vfree(&pathspec); - git_pool_clear(&pathpool); - - return error; -} - -static bool should_remove_existing(checkout_data *data) -{ - int ignorecase; - - if (git_repository__configmap_lookup(&ignorecase, data->repo, GIT_CONFIGMAP_IGNORECASE) < 0) { - ignorecase = 0; - } - - return (ignorecase && - (data->strategy & GIT_CHECKOUT_DONT_REMOVE_EXISTING) == 0); -} - -#define MKDIR_NORMAL \ - GIT_MKDIR_PATH | GIT_MKDIR_VERIFY_DIR -#define MKDIR_REMOVE_EXISTING \ - MKDIR_NORMAL | GIT_MKDIR_REMOVE_FILES | GIT_MKDIR_REMOVE_SYMLINKS - -static int checkout_mkdir( - checkout_data *data, - const char *path, - const char *base, - mode_t mode, - unsigned int flags) -{ - struct git_futils_mkdir_options mkdir_opts = {0}; - int error; - - if (git_pool_is_initialized(&data->pool)) { - mkdir_opts.cache_pool = &data->pool; - mkdir_opts.cache_pathset = &data->mkdir_pathcache; - } - - error = git_futils_mkdir_relative( - path, base, mode, flags, &mkdir_opts); - - data->perfdata.mkdir_calls += mkdir_opts.perfdata.mkdir_calls; - data->perfdata.stat_calls += mkdir_opts.perfdata.stat_calls; - data->perfdata.chmod_calls += mkdir_opts.perfdata.chmod_calls; - - return error; -} - -static int mkpath2file( - checkout_data *data, const char *path, unsigned int mode) -{ - struct stat st; - bool remove_existing = should_remove_existing(data); - unsigned int flags = - (remove_existing ? MKDIR_REMOVE_EXISTING : MKDIR_NORMAL) | - GIT_MKDIR_SKIP_LAST; - int error; - - if ((error = checkout_mkdir( - data, path, data->opts.target_directory, mode, flags)) < 0) - return error; - - if (remove_existing) { - data->perfdata.stat_calls++; - - if (p_lstat(path, &st) == 0) { - - /* Some file, symlink or folder already exists at this name. - * We would have removed it in remove_the_old unless we're on - * a case inensitive filesystem (or the user has asked us not - * to). Remove the similarly named file to write the new. - */ - error = git_futils_rmdir_r(path, NULL, GIT_RMDIR_REMOVE_FILES); - } else if (errno != ENOENT) { - git_error_set(GIT_ERROR_OS, "failed to stat '%s'", path); - return GIT_EEXISTS; - } else { - git_error_clear(); - } - } - - return error; -} - -struct checkout_stream { - git_writestream base; - const char *path; - int fd; - int open; -}; - -static int checkout_stream_write( - git_writestream *s, const char *buffer, size_t len) -{ - struct checkout_stream *stream = (struct checkout_stream *)s; - int ret; - - if ((ret = p_write(stream->fd, buffer, len)) < 0) - git_error_set(GIT_ERROR_OS, "could not write to '%s'", stream->path); - - return ret; -} - -static int checkout_stream_close(git_writestream *s) -{ - struct checkout_stream *stream = (struct checkout_stream *)s; - - GIT_ASSERT_ARG(stream); - GIT_ASSERT_ARG(stream->open); - - stream->open = 0; - return p_close(stream->fd); -} - -static void checkout_stream_free(git_writestream *s) -{ - GIT_UNUSED(s); -} - -static int blob_content_to_file( - checkout_data *data, - struct stat *st, - git_blob *blob, - const char *path, - const char *hint_path, - mode_t entry_filemode) -{ - int flags = data->opts.file_open_flags; - mode_t file_mode = data->opts.file_mode ? - data->opts.file_mode : entry_filemode; - git_filter_session filter_session = GIT_FILTER_SESSION_INIT; - struct checkout_stream writer; - mode_t mode; - git_filter_list *fl = NULL; - int fd; - int error = 0; - - GIT_ASSERT(hint_path != NULL); - - if ((error = mkpath2file(data, path, data->opts.dir_mode)) < 0) - return error; - - if (flags <= 0) - flags = O_CREAT | O_TRUNC | O_WRONLY; - if (!(mode = file_mode)) - mode = GIT_FILEMODE_BLOB; - - if ((fd = p_open(path, flags, mode)) < 0) { - git_error_set(GIT_ERROR_OS, "could not open '%s' for writing", path); - return fd; - } - - filter_session.attr_session = &data->attr_session; - filter_session.temp_buf = &data->tmp; - - if (!data->opts.disable_filters && - (error = git_filter_list__load( - &fl, data->repo, blob, hint_path, - GIT_FILTER_TO_WORKTREE, &filter_session))) { - p_close(fd); - return error; - } - - /* setup the writer */ - memset(&writer, 0, sizeof(struct checkout_stream)); - writer.base.write = checkout_stream_write; - writer.base.close = checkout_stream_close; - writer.base.free = checkout_stream_free; - writer.path = path; - writer.fd = fd; - writer.open = 1; - - error = git_filter_list_stream_blob(fl, blob, &writer.base); - - GIT_ASSERT(writer.open == 0); - - git_filter_list_free(fl); - - if (error < 0) - return error; - - if (st) { - data->perfdata.stat_calls++; - - if ((error = p_stat(path, st)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to stat '%s'", path); - return error; - } - - st->st_mode = entry_filemode; - } - - return 0; -} - -static int blob_content_to_link( - checkout_data *data, - struct stat *st, - git_blob *blob, - const char *path) -{ - git_str linktarget = GIT_STR_INIT; - int error; - - if ((error = mkpath2file(data, path, data->opts.dir_mode)) < 0) - return error; - - if ((error = git_blob__getbuf(&linktarget, blob)) < 0) - return error; - - if (data->can_symlink) { - if ((error = p_symlink(git_str_cstr(&linktarget), path)) < 0) - git_error_set(GIT_ERROR_OS, "could not create symlink %s", path); - } else { - error = git_futils_fake_symlink(git_str_cstr(&linktarget), path); - } - - if (!error) { - data->perfdata.stat_calls++; - - if ((error = p_lstat(path, st)) < 0) - git_error_set(GIT_ERROR_CHECKOUT, "could not stat symlink %s", path); - - st->st_mode = GIT_FILEMODE_LINK; - } - - git_str_dispose(&linktarget); - - return error; -} - -static int checkout_update_index( - checkout_data *data, - const git_diff_file *file, - struct stat *st) -{ - git_index_entry entry; - - if (!data->index) - return 0; - - memset(&entry, 0, sizeof(entry)); - entry.path = (char *)file->path; /* cast to prevent warning */ - git_index_entry__init_from_stat(&entry, st, true); - git_oid_cpy(&entry.id, &file->id); - - return git_index_add(data->index, &entry); -} - -static int checkout_submodule_update_index( - checkout_data *data, - const git_diff_file *file) -{ - git_str *fullpath; - struct stat st; - - /* update the index unless prevented */ - if ((data->strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) != 0) - return 0; - - if (checkout_target_fullpath(&fullpath, data, file->path) < 0) - return -1; - - data->perfdata.stat_calls++; - if (p_stat(fullpath->ptr, &st) < 0) { - git_error_set( - GIT_ERROR_CHECKOUT, "could not stat submodule %s\n", file->path); - return GIT_ENOTFOUND; - } - - st.st_mode = GIT_FILEMODE_COMMIT; - - return checkout_update_index(data, file, &st); -} - -static int checkout_submodule( - checkout_data *data, - const git_diff_file *file) -{ - bool remove_existing = should_remove_existing(data); - int error = 0; - - /* Until submodules are supported, UPDATE_ONLY means do nothing here */ - if ((data->strategy & GIT_CHECKOUT_UPDATE_ONLY) != 0) - return 0; - - if ((error = checkout_mkdir( - data, - file->path, data->opts.target_directory, data->opts.dir_mode, - remove_existing ? MKDIR_REMOVE_EXISTING : MKDIR_NORMAL)) < 0) - return error; - - if ((error = git_submodule_lookup(NULL, data->repo, file->path)) < 0) { - /* I've observed repos with submodules in the tree that do not - * have a .gitmodules - core Git just makes an empty directory - */ - if (error == GIT_ENOTFOUND) { - git_error_clear(); - return checkout_submodule_update_index(data, file); - } - - return error; - } - - /* TODO: Support checkout_strategy options. Two circumstances: - * 1 - submodule already checked out, but we need to move the HEAD - * to the new OID, or - * 2 - submodule not checked out and we should recursively check it out - * - * Checkout will not execute a pull on the submodule, but a clone - * command should probably be able to. Do we need a submodule callback? - */ - - return checkout_submodule_update_index(data, file); -} - -static void report_progress( - checkout_data *data, - const char *path) -{ - if (data->opts.progress_cb) - data->opts.progress_cb( - path, data->completed_steps, data->total_steps, - data->opts.progress_payload); -} - -static int checkout_safe_for_update_only( - checkout_data *data, const char *path, mode_t expected_mode) -{ - struct stat st; - - data->perfdata.stat_calls++; - - if (p_lstat(path, &st) < 0) { - /* if doesn't exist, then no error and no update */ - if (errno == ENOENT || errno == ENOTDIR) - return 0; - - /* otherwise, stat error and no update */ - git_error_set(GIT_ERROR_OS, "failed to stat '%s'", path); - return -1; - } - - /* only safe for update if this is the same type of file */ - if ((st.st_mode & ~0777) == (expected_mode & ~0777)) - return 1; - - return 0; -} - -static int checkout_write_content( - checkout_data *data, - const git_oid *oid, - const char *full_path, - const char *hint_path, - unsigned int mode, - struct stat *st) -{ - int error = 0; - git_blob *blob; - - if ((error = git_blob_lookup(&blob, data->repo, oid)) < 0) - return error; - - if (S_ISLNK(mode)) - error = blob_content_to_link(data, st, blob, full_path); - else - error = blob_content_to_file(data, st, blob, full_path, hint_path, mode); - - git_blob_free(blob); - - /* if we try to create the blob and an existing directory blocks it from - * being written, then there must have been a typechange conflict in a - * parent directory - suppress the error and try to continue. - */ - if ((data->strategy & GIT_CHECKOUT_ALLOW_CONFLICTS) != 0 && - (error == GIT_ENOTFOUND || error == GIT_EEXISTS)) - { - git_error_clear(); - error = 0; - } - - return error; -} - -static int checkout_blob( - checkout_data *data, - const git_diff_file *file) -{ - git_str *fullpath; - struct stat st; - int error = 0; - - if (checkout_target_fullpath(&fullpath, data, file->path) < 0) - return -1; - - if ((data->strategy & GIT_CHECKOUT_UPDATE_ONLY) != 0) { - int rval = checkout_safe_for_update_only( - data, fullpath->ptr, file->mode); - - if (rval <= 0) - return rval; - } - - error = checkout_write_content( - data, &file->id, fullpath->ptr, file->path, file->mode, &st); - - /* update the index unless prevented */ - if (!error && (data->strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) == 0) - error = checkout_update_index(data, file, &st); - - /* update the submodule data if this was a new .gitmodules file */ - if (!error && strcmp(file->path, ".gitmodules") == 0) - data->reload_submodules = true; - - return error; -} - -static int checkout_remove_the_old( - unsigned int *actions, - checkout_data *data) -{ - int error = 0; - git_diff_delta *delta; - const char *str; - size_t i; - git_str *fullpath; - uint32_t flg = GIT_RMDIR_EMPTY_PARENTS | - GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS; - - if (data->opts.checkout_strategy & GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES) - flg |= GIT_RMDIR_SKIP_NONEMPTY; - - if (checkout_target_fullpath(&fullpath, data, NULL) < 0) - return -1; - - git_vector_foreach(&data->diff->deltas, i, delta) { - if (actions[i] & CHECKOUT_ACTION__REMOVE) { - error = git_futils_rmdir_r( - delta->old_file.path, fullpath->ptr, flg); - - if (error < 0) - return error; - - data->completed_steps++; - report_progress(data, delta->old_file.path); - - if ((actions[i] & CHECKOUT_ACTION__UPDATE_BLOB) == 0 && - (data->strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) == 0 && - data->index != NULL) - { - (void)git_index_remove(data->index, delta->old_file.path, 0); - } - } - } - - git_vector_foreach(&data->removes, i, str) { - error = git_futils_rmdir_r(str, fullpath->ptr, flg); - if (error < 0) - return error; - - data->completed_steps++; - report_progress(data, str); - - if ((data->strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) == 0 && - data->index != NULL) - { - if (str[strlen(str) - 1] == '/') - (void)git_index_remove_directory(data->index, str, 0); - else - (void)git_index_remove(data->index, str, 0); - } - } - - return 0; -} - -static int checkout_create_the_new( - unsigned int *actions, - checkout_data *data) -{ - int error = 0; - git_diff_delta *delta; - size_t i; - - git_vector_foreach(&data->diff->deltas, i, delta) { - if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB && !S_ISLNK(delta->new_file.mode)) { - if ((error = checkout_blob(data, &delta->new_file)) < 0) - return error; - data->completed_steps++; - report_progress(data, delta->new_file.path); - } - } - - git_vector_foreach(&data->diff->deltas, i, delta) { - if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB && S_ISLNK(delta->new_file.mode)) { - if ((error = checkout_blob(data, &delta->new_file)) < 0) - return error; - data->completed_steps++; - report_progress(data, delta->new_file.path); - } - } - - return 0; -} - -static int checkout_create_submodules( - unsigned int *actions, - checkout_data *data) -{ - git_diff_delta *delta; - size_t i; - - git_vector_foreach(&data->diff->deltas, i, delta) { - if (actions[i] & CHECKOUT_ACTION__UPDATE_SUBMODULE) { - int error = checkout_submodule(data, &delta->new_file); - if (error < 0) - return error; - - data->completed_steps++; - report_progress(data, delta->new_file.path); - } - } - - return 0; -} - -static int checkout_lookup_head_tree(git_tree **out, git_repository *repo) -{ - int error = 0; - git_reference *ref = NULL; - git_object *head; - - if (!(error = git_repository_head(&ref, repo)) && - !(error = git_reference_peel(&head, ref, GIT_OBJECT_TREE))) - *out = (git_tree *)head; - - git_reference_free(ref); - - return error; -} - - -static int conflict_entry_name( - git_str *out, - const char *side_name, - const char *filename) -{ - if (git_str_puts(out, side_name) < 0 || - git_str_putc(out, ':') < 0 || - git_str_puts(out, filename) < 0) - return -1; - - return 0; -} - -static int checkout_path_suffixed(git_str *path, const char *suffix) -{ - size_t path_len; - int i = 0, error = 0; - - if ((error = git_str_putc(path, '~')) < 0 || (error = git_str_puts(path, suffix)) < 0) - return -1; - - path_len = git_str_len(path); - - while (git_fs_path_exists(git_str_cstr(path)) && i < INT_MAX) { - git_str_truncate(path, path_len); - - if ((error = git_str_putc(path, '_')) < 0 || - (error = git_str_printf(path, "%d", i)) < 0) - return error; - - i++; - } - - if (i == INT_MAX) { - git_str_truncate(path, path_len); - - git_error_set(GIT_ERROR_CHECKOUT, "could not write '%s': working directory file exists", path->ptr); - return GIT_EEXISTS; - } - - return 0; -} - -static int checkout_write_entry( - checkout_data *data, - checkout_conflictdata *conflict, - const git_index_entry *side) -{ - const char *hint_path = NULL, *suffix; - git_str *fullpath; - struct stat st; - int error; - - GIT_ASSERT(side == conflict->ours || side == conflict->theirs); - - if (checkout_target_fullpath(&fullpath, data, side->path) < 0) - return -1; - - if ((conflict->name_collision || conflict->directoryfile) && - (data->strategy & GIT_CHECKOUT_USE_OURS) == 0 && - (data->strategy & GIT_CHECKOUT_USE_THEIRS) == 0) { - - if (side == conflict->ours) - suffix = data->opts.our_label ? data->opts.our_label : - "ours"; - else - suffix = data->opts.their_label ? data->opts.their_label : - "theirs"; - - if (checkout_path_suffixed(fullpath, suffix) < 0) - return -1; - } - - hint_path = side->path; - - if ((data->strategy & GIT_CHECKOUT_UPDATE_ONLY) != 0 && - (error = checkout_safe_for_update_only(data, fullpath->ptr, side->mode)) <= 0) - return error; - - if (!S_ISGITLINK(side->mode)) - return checkout_write_content(data, - &side->id, fullpath->ptr, hint_path, side->mode, &st); - - return 0; -} - -static int checkout_write_entries( - checkout_data *data, - checkout_conflictdata *conflict) -{ - int error = 0; - - if ((error = checkout_write_entry(data, conflict, conflict->ours)) >= 0) - error = checkout_write_entry(data, conflict, conflict->theirs); - - return error; -} - -static int checkout_merge_path( - git_str *out, - checkout_data *data, - checkout_conflictdata *conflict, - git_merge_file_result *result) -{ - const char *our_label_raw, *their_label_raw, *suffix; - int error = 0; - - if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 || - (error = git_path_validate_str_length(data->repo, out)) < 0) - return error; - - /* Most conflicts simply use the filename in the index */ - if (!conflict->name_collision) - return 0; - - /* Rename 2->1 conflicts need the branch name appended */ - our_label_raw = data->opts.our_label ? data->opts.our_label : "ours"; - their_label_raw = data->opts.their_label ? data->opts.their_label : "theirs"; - suffix = strcmp(result->path, conflict->ours->path) == 0 ? our_label_raw : their_label_raw; - - if ((error = checkout_path_suffixed(out, suffix)) < 0) - return error; - - return 0; -} - -static int checkout_write_merge( - checkout_data *data, - checkout_conflictdata *conflict) -{ - git_str our_label = GIT_STR_INIT, their_label = GIT_STR_INIT, - path_suffixed = GIT_STR_INIT, path_workdir = GIT_STR_INIT, - in_data = GIT_STR_INIT, out_data = GIT_STR_INIT; - git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT; - git_merge_file_result result = {0}; - git_filebuf output = GIT_FILEBUF_INIT; - git_filter_list *fl = NULL; - git_filter_session filter_session = GIT_FILTER_SESSION_INIT; - int error = 0; - - if (data->opts.checkout_strategy & GIT_CHECKOUT_CONFLICT_STYLE_DIFF3) - opts.flags |= GIT_MERGE_FILE_STYLE_DIFF3; - - if (data->opts.checkout_strategy & GIT_CHECKOUT_CONFLICT_STYLE_ZDIFF3) - opts.flags |= GIT_MERGE_FILE_STYLE_ZDIFF3; - - opts.ancestor_label = data->opts.ancestor_label ? - data->opts.ancestor_label : "ancestor"; - opts.our_label = data->opts.our_label ? - data->opts.our_label : "ours"; - opts.their_label = data->opts.their_label ? - data->opts.their_label : "theirs"; - - /* If all the paths are identical, decorate the diff3 file with the branch - * names. Otherwise, append branch_name:path. - */ - if (conflict->ours && conflict->theirs && - strcmp(conflict->ours->path, conflict->theirs->path) != 0) { - - if ((error = conflict_entry_name( - &our_label, opts.our_label, conflict->ours->path)) < 0 || - (error = conflict_entry_name( - &their_label, opts.their_label, conflict->theirs->path)) < 0) - goto done; - - opts.our_label = git_str_cstr(&our_label); - opts.their_label = git_str_cstr(&their_label); - } - - if ((error = git_merge_file_from_index(&result, data->repo, - conflict->ancestor, conflict->ours, conflict->theirs, &opts)) < 0) - goto done; - - if (result.path == NULL || result.mode == 0) { - git_error_set(GIT_ERROR_CHECKOUT, "could not merge contents of file"); - error = GIT_ECONFLICT; - goto done; - } - - if ((error = checkout_merge_path(&path_workdir, data, conflict, &result)) < 0) - goto done; - - if ((data->strategy & GIT_CHECKOUT_UPDATE_ONLY) != 0 && - (error = checkout_safe_for_update_only(data, git_str_cstr(&path_workdir), result.mode)) <= 0) - goto done; - - if (!data->opts.disable_filters) { - in_data.ptr = (char *)result.ptr; - in_data.size = result.len; - - filter_session.attr_session = &data->attr_session; - filter_session.temp_buf = &data->tmp; - - if ((error = git_filter_list__load( - &fl, data->repo, NULL, result.path, - GIT_FILTER_TO_WORKTREE, &filter_session)) < 0 || - (error = git_filter_list__convert_buf(&out_data, fl, &in_data)) < 0) - goto done; - } else { - out_data.ptr = (char *)result.ptr; - out_data.size = result.len; - } - - if ((error = mkpath2file(data, path_workdir.ptr, data->opts.dir_mode)) < 0 || - (error = git_filebuf_open(&output, git_str_cstr(&path_workdir), GIT_FILEBUF_DO_NOT_BUFFER, result.mode)) < 0 || - (error = git_filebuf_write(&output, out_data.ptr, out_data.size)) < 0 || - (error = git_filebuf_commit(&output)) < 0) - goto done; - -done: - git_filter_list_free(fl); - - git_str_dispose(&out_data); - git_str_dispose(&our_label); - git_str_dispose(&their_label); - - git_merge_file_result_free(&result); - git_str_dispose(&path_workdir); - git_str_dispose(&path_suffixed); - - return error; -} - -static int checkout_conflict_add( - checkout_data *data, - const git_index_entry *conflict) -{ - int error = git_index_remove(data->index, conflict->path, 0); - - if (error == GIT_ENOTFOUND) - git_error_clear(); - else if (error < 0) - return error; - - return git_index_add(data->index, conflict); -} - -static int checkout_conflict_update_index( - checkout_data *data, - checkout_conflictdata *conflict) -{ - int error = 0; - - if (conflict->ancestor) - error = checkout_conflict_add(data, conflict->ancestor); - - if (!error && conflict->ours) - error = checkout_conflict_add(data, conflict->ours); - - if (!error && conflict->theirs) - error = checkout_conflict_add(data, conflict->theirs); - - return error; -} - -static int checkout_create_conflicts(checkout_data *data) -{ - checkout_conflictdata *conflict; - size_t i; - int error = 0; - - git_vector_foreach(&data->update_conflicts, i, conflict) { - - /* Both deleted: nothing to do */ - if (conflict->ours == NULL && conflict->theirs == NULL) - error = 0; - - else if ((data->strategy & GIT_CHECKOUT_USE_OURS) && - conflict->ours) - error = checkout_write_entry(data, conflict, conflict->ours); - else if ((data->strategy & GIT_CHECKOUT_USE_THEIRS) && - conflict->theirs) - error = checkout_write_entry(data, conflict, conflict->theirs); - - /* Ignore the other side of name collisions. */ - else if ((data->strategy & GIT_CHECKOUT_USE_OURS) && - !conflict->ours && conflict->name_collision) - error = 0; - else if ((data->strategy & GIT_CHECKOUT_USE_THEIRS) && - !conflict->theirs && conflict->name_collision) - error = 0; - - /* For modify/delete, name collisions and d/f conflicts, write - * the file (potentially with the name mangled. - */ - else if (conflict->ours != NULL && conflict->theirs == NULL) - error = checkout_write_entry(data, conflict, conflict->ours); - else if (conflict->ours == NULL && conflict->theirs != NULL) - error = checkout_write_entry(data, conflict, conflict->theirs); - - /* Add/add conflicts and rename 1->2 conflicts, write the - * ours/theirs sides (potentially name mangled). - */ - else if (conflict->one_to_two) - error = checkout_write_entries(data, conflict); - - /* If all sides are links, write the ours side */ - else if (S_ISLNK(conflict->ours->mode) && - S_ISLNK(conflict->theirs->mode)) - error = checkout_write_entry(data, conflict, conflict->ours); - /* Link/file conflicts, write the file side */ - else if (S_ISLNK(conflict->ours->mode)) - error = checkout_write_entry(data, conflict, conflict->theirs); - else if (S_ISLNK(conflict->theirs->mode)) - error = checkout_write_entry(data, conflict, conflict->ours); - - /* If any side is a gitlink, do nothing. */ - else if (conflict->submodule) - error = 0; - - /* If any side is binary, write the ours side */ - else if (conflict->binary) - error = checkout_write_entry(data, conflict, conflict->ours); - - else if (!error) - error = checkout_write_merge(data, conflict); - - /* Update the index extensions (REUC and NAME) if we're checking - * out a different index. (Otherwise just leave them there.) - */ - if (!error && (data->strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) == 0) - error = checkout_conflict_update_index(data, conflict); - - if (error) - break; - - data->completed_steps++; - report_progress(data, - conflict->ours ? conflict->ours->path : - (conflict->theirs ? conflict->theirs->path : conflict->ancestor->path)); - } - - return error; -} - -static int checkout_remove_conflicts(checkout_data *data) -{ - const char *conflict; - size_t i; - - git_vector_foreach(&data->remove_conflicts, i, conflict) { - if (git_index_conflict_remove(data->index, conflict) < 0) - return -1; - - data->completed_steps++; - } - - return 0; -} - -static int checkout_extensions_update_index(checkout_data *data) -{ - const git_index_reuc_entry *reuc_entry; - const git_index_name_entry *name_entry; - size_t i; - int error = 0; - - if ((data->strategy & GIT_CHECKOUT_UPDATE_ONLY) != 0) - return 0; - - if (data->update_reuc) { - git_vector_foreach(data->update_reuc, i, reuc_entry) { - if ((error = git_index_reuc_add(data->index, reuc_entry->path, - reuc_entry->mode[0], &reuc_entry->oid[0], - reuc_entry->mode[1], &reuc_entry->oid[1], - reuc_entry->mode[2], &reuc_entry->oid[2])) < 0) - goto done; - } - } - - if (data->update_names) { - git_vector_foreach(data->update_names, i, name_entry) { - if ((error = git_index_name_add(data->index, name_entry->ancestor, - name_entry->ours, name_entry->theirs)) < 0) - goto done; - } - } - -done: - return error; -} - -static void checkout_data_clear(checkout_data *data) -{ - if (data->opts_free_baseline) { - git_tree_free(data->opts.baseline); - data->opts.baseline = NULL; - } - - git_vector_dispose(&data->removes); - git_pool_clear(&data->pool); - - git_vector_dispose_deep(&data->remove_conflicts); - git_vector_dispose_deep(&data->update_conflicts); - - git__free(data->pfx); - data->pfx = NULL; - - git_str_dispose(&data->target_path); - git_str_dispose(&data->tmp); - - git_index_free(data->index); - data->index = NULL; - - git_hashset_str_dispose(&data->mkdir_pathcache); - - git_attr_session__free(&data->attr_session); -} - -static int validate_target_directory(checkout_data *data) -{ - int error; - - if ((error = git_path_validate_length(data->repo, data->opts.target_directory)) < 0) - return error; - - if (git_fs_path_isdir(data->opts.target_directory)) - return 0; - - error = checkout_mkdir(data, data->opts.target_directory, NULL, - GIT_DIR_MODE, GIT_MKDIR_VERIFY_DIR); - - return error; -} - -static int checkout_data_init( - checkout_data *data, - git_iterator *target, - const git_checkout_options *proposed) -{ - int error = 0; - git_repository *repo = git_iterator_owner(target); - - memset(data, 0, sizeof(*data)); - - if (!repo) { - git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout nothing"); - return -1; - } - - if ((!proposed || !proposed->target_directory) && - (error = git_repository__ensure_not_bare(repo, "checkout")) < 0) - return error; - - data->repo = repo; - data->target = target; - - GIT_ERROR_CHECK_VERSION( - proposed, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options"); - - if (!proposed) - GIT_INIT_STRUCTURE(&data->opts, GIT_CHECKOUT_OPTIONS_VERSION); - else - memmove(&data->opts, proposed, sizeof(git_checkout_options)); - - if (!data->opts.target_directory) - data->opts.target_directory = git_repository_workdir(repo); - else if ((error = validate_target_directory(data)) < 0) - goto cleanup; - - if ((error = git_repository_index(&data->index, data->repo)) < 0) - goto cleanup; - - /* refresh config and index content unless NO_REFRESH is given */ - if ((data->opts.checkout_strategy & GIT_CHECKOUT_NO_REFRESH) == 0) { - git_config *cfg; - - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0) - goto cleanup; - - /* Reload the repository index (unless we're checking out the - * index; then it has the changes we're trying to check out - * and those should not be overwritten.) - */ - if (data->index != git_iterator_index(target)) { - if (data->opts.checkout_strategy & GIT_CHECKOUT_FORCE) { - /* When forcing, we can blindly re-read the index */ - if ((error = git_index_read(data->index, false)) < 0) - goto cleanup; - } else { - /* - * When not being forced, we need to check for unresolved - * conflicts and unsaved changes in the index before - * proceeding. - */ - if (git_index_has_conflicts(data->index)) { - error = GIT_ECONFLICT; - git_error_set(GIT_ERROR_CHECKOUT, - "unresolved conflicts exist in the index"); - goto cleanup; - } - - if ((error = git_index_read_safely(data->index)) < 0) - goto cleanup; - } - - /* clean conflict data in the current index */ - git_index_name_clear(data->index); - git_index_reuc_clear(data->index); - } - } - - /* if you are forcing, allow all safe updates, plus recreate missing */ - if ((data->opts.checkout_strategy & GIT_CHECKOUT_FORCE) != 0) - data->opts.checkout_strategy |= GIT_CHECKOUT_RECREATE_MISSING; - - /* if the repository does not actually have an index file, then this - * is an initial checkout (perhaps from clone), so we allow safe updates - */ - if (!data->index->on_disk) - data->opts.checkout_strategy |= GIT_CHECKOUT_RECREATE_MISSING; - - data->strategy = data->opts.checkout_strategy; - - /* opts->disable_filters is false by default */ - - if (!data->opts.dir_mode) - data->opts.dir_mode = GIT_DIR_MODE; - - if (!data->opts.file_open_flags) - data->opts.file_open_flags = O_CREAT | O_TRUNC | O_WRONLY; - - data->pfx = git_pathspec_prefix(&data->opts.paths); - - if ((error = git_repository__configmap_lookup( - &data->can_symlink, repo, GIT_CONFIGMAP_SYMLINKS)) < 0) - goto cleanup; - - if ((error = git_repository__configmap_lookup( - &data->respect_filemode, repo, GIT_CONFIGMAP_FILEMODE)) < 0) - goto cleanup; - - if (!data->opts.baseline && !data->opts.baseline_index) { - data->opts_free_baseline = true; - error = 0; - - /* if we don't have an index, this is an initial checkout and - * should be against an empty baseline - */ - if (data->index->on_disk) - error = checkout_lookup_head_tree(&data->opts.baseline, repo); - - if (error == GIT_EUNBORNBRANCH) { - error = 0; - git_error_clear(); - } - - if (error < 0) - goto cleanup; - } - - if ((data->opts.checkout_strategy & - (GIT_CHECKOUT_CONFLICT_STYLE_MERGE | GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)) == 0) { - git_config_entry *conflict_style = NULL; - git_config *cfg = NULL; - - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 || - (error = git_config_get_entry(&conflict_style, cfg, "merge.conflictstyle")) < 0 || - error == GIT_ENOTFOUND) - ; - else if (error) - goto cleanup; - else if (strcmp(conflict_style->value, "merge") == 0) - data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_MERGE; - else if (strcmp(conflict_style->value, "diff3") == 0) - data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_DIFF3; - else if (strcmp(conflict_style->value, "zdiff3") == 0) - data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_ZDIFF3; - else { - git_error_set(GIT_ERROR_CHECKOUT, "unknown style '%s' given for 'merge.conflictstyle'", - conflict_style->value); - error = -1; - git_config_entry_free(conflict_style); - goto cleanup; - } - git_config_entry_free(conflict_style); - } - - if ((error = git_pool_init(&data->pool, 1)) < 0 || - (error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 || - (error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 || - (error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 || - (error = git_str_puts(&data->target_path, data->opts.target_directory)) < 0 || - (error = git_fs_path_to_dir(&data->target_path)) < 0) - goto cleanup; - - data->target_len = git_str_len(&data->target_path); - - git_attr_session__init(&data->attr_session, data->repo); - -cleanup: - if (error < 0) - checkout_data_clear(data); - - return error; -} - -#define CHECKOUT_INDEX_DONT_WRITE_MASK \ - (GIT_CHECKOUT_DONT_UPDATE_INDEX | GIT_CHECKOUT_DONT_WRITE_INDEX) - -GIT_INLINE(void) setup_pathspecs( - git_iterator_options *iter_opts, - const git_checkout_options *checkout_opts) -{ - if (checkout_opts && - (checkout_opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) { - iter_opts->pathlist.count = checkout_opts->paths.count; - iter_opts->pathlist.strings = checkout_opts->paths.strings; - } -} - -int git_checkout_iterator( - git_iterator *target, - git_index *index, - const git_checkout_options *opts) -{ - int error = 0; - git_iterator *baseline = NULL, *workdir = NULL; - git_iterator_options baseline_opts = GIT_ITERATOR_OPTIONS_INIT, - workdir_opts = GIT_ITERATOR_OPTIONS_INIT; - checkout_data data = {0}; - git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; - uint32_t *actions = NULL; - size_t *counts = NULL; - - /* initialize structures and options */ - error = checkout_data_init(&data, target, opts); - if (error < 0) - return error; - - diff_opts.flags = - GIT_DIFF_INCLUDE_UNMODIFIED | - GIT_DIFF_INCLUDE_UNREADABLE | - GIT_DIFF_INCLUDE_UNTRACKED | - GIT_DIFF_RECURSE_UNTRACKED_DIRS | /* needed to match baseline */ - GIT_DIFF_INCLUDE_IGNORED | - GIT_DIFF_INCLUDE_TYPECHANGE | - GIT_DIFF_INCLUDE_TYPECHANGE_TREES | - GIT_DIFF_SKIP_BINARY_CHECK | - GIT_DIFF_INCLUDE_CASECHANGE; - if (data.opts.checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) - diff_opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH; - if (data.opts.paths.count > 0) - diff_opts.pathspec = data.opts.paths; - - /* set up iterators */ - - workdir_opts.flags = git_iterator_ignore_case(target) ? - GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE; - workdir_opts.flags |= GIT_ITERATOR_DONT_AUTOEXPAND; - workdir_opts.start = data.pfx; - workdir_opts.end = data.pfx; - - setup_pathspecs(&workdir_opts, opts); - - if ((error = git_iterator_reset_range(target, data.pfx, data.pfx)) < 0 || - (error = git_iterator_for_workdir_ext( - &workdir, data.repo, data.opts.target_directory, index, NULL, - &workdir_opts)) < 0) - goto cleanup; - - baseline_opts.flags = git_iterator_ignore_case(target) ? - GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE; - baseline_opts.start = data.pfx; - baseline_opts.end = data.pfx; - - setup_pathspecs(&baseline_opts, opts); - - if (data.opts.baseline_index) { - if ((error = git_iterator_for_index( - &baseline, git_index_owner(data.opts.baseline_index), - data.opts.baseline_index, &baseline_opts)) < 0) - goto cleanup; - } else { - if ((error = git_iterator_for_tree( - &baseline, data.opts.baseline, &baseline_opts)) < 0) - goto cleanup; - } - - /* Should not have case insensitivity mismatch */ - GIT_ASSERT(git_iterator_ignore_case(workdir) == git_iterator_ignore_case(baseline)); - - /* Generate baseline-to-target diff which will include an entry for - * every possible update that might need to be made. - */ - if ((error = git_diff__from_iterators( - &data.diff, data.repo, baseline, target, &diff_opts)) < 0) - goto cleanup; - - /* Loop through diff (and working directory iterator) building a list of - * actions to be taken, plus look for conflicts and send notifications, - * then loop through conflicts. - */ - if ((error = checkout_get_actions(&actions, &counts, &data, workdir)) != 0) - goto cleanup; - - if (data.strategy & GIT_CHECKOUT_DRY_RUN) - goto cleanup; - - data.total_steps = counts[CHECKOUT_ACTION__REMOVE] + - counts[CHECKOUT_ACTION__REMOVE_CONFLICT] + - counts[CHECKOUT_ACTION__UPDATE_BLOB] + - counts[CHECKOUT_ACTION__UPDATE_SUBMODULE] + - counts[CHECKOUT_ACTION__UPDATE_CONFLICT]; - - report_progress(&data, NULL); /* establish 0 baseline */ - - /* To deal with some order dependencies, perform remaining checkout - * in three passes: removes, then update blobs, then update submodules. - */ - if (counts[CHECKOUT_ACTION__REMOVE] > 0 && - (error = checkout_remove_the_old(actions, &data)) < 0) - goto cleanup; - - if (counts[CHECKOUT_ACTION__REMOVE_CONFLICT] > 0 && - (error = checkout_remove_conflicts(&data)) < 0) - goto cleanup; - - if (counts[CHECKOUT_ACTION__UPDATE_BLOB] > 0 && - (error = checkout_create_the_new(actions, &data)) < 0) - goto cleanup; - - if (counts[CHECKOUT_ACTION__UPDATE_SUBMODULE] > 0 && - (error = checkout_create_submodules(actions, &data)) < 0) - goto cleanup; - - if (counts[CHECKOUT_ACTION__UPDATE_CONFLICT] > 0 && - (error = checkout_create_conflicts(&data)) < 0) - goto cleanup; - - if (data.index != git_iterator_index(target) && - (error = checkout_extensions_update_index(&data)) < 0) - goto cleanup; - - GIT_ASSERT(data.completed_steps == data.total_steps); - - if (data.opts.perfdata_cb) - data.opts.perfdata_cb(&data.perfdata, data.opts.perfdata_payload); - -cleanup: - if (!error && data.index != NULL && - (data.strategy & CHECKOUT_INDEX_DONT_WRITE_MASK) == 0) - error = git_index_write(data.index); - - git_diff_free(data.diff); - git_iterator_free(workdir); - git_iterator_free(baseline); - git__free(actions); - git__free(counts); - checkout_data_clear(&data); - - return error; -} - -int git_checkout_index( - git_repository *repo, - git_index *index, - const git_checkout_options *opts) -{ - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - int error, owned = 0; - git_iterator *index_i; - - if (!index && !repo) { - git_error_set(GIT_ERROR_CHECKOUT, - "must provide either repository or index to checkout"); - return -1; - } - - if (index && repo && - git_index_owner(index) && - git_index_owner(index) != repo) { - git_error_set(GIT_ERROR_CHECKOUT, - "index to checkout does not match repository"); - return -1; - } else if(index && repo && !git_index_owner(index)) { - GIT_REFCOUNT_OWN(index, repo); - owned = 1; - } - - if (!repo) - repo = git_index_owner(index); - - if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0) - return error; - GIT_REFCOUNT_INC(index); - - setup_pathspecs(&iter_opts, opts); - - if (!(error = git_iterator_for_index(&index_i, repo, index, &iter_opts))) - error = git_checkout_iterator(index_i, index, opts); - - if (owned) - GIT_REFCOUNT_OWN(index, NULL); - - git_iterator_free(index_i); - git_index_free(index); - - return error; -} - -int git_checkout_tree( - git_repository *repo, - const git_object *treeish, - const git_checkout_options *opts) -{ - int error; - git_index *index; - git_tree *tree = NULL; - git_iterator *tree_i = NULL; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - - if (!treeish && !repo) { - git_error_set(GIT_ERROR_CHECKOUT, - "must provide either repository or tree to checkout"); - return -1; - } - if (treeish && repo && git_object_owner(treeish) != repo) { - git_error_set(GIT_ERROR_CHECKOUT, - "object to checkout does not match repository"); - return -1; - } - - if (!repo) - repo = git_object_owner(treeish); - - if (treeish) { - if (git_object_peel((git_object **)&tree, treeish, GIT_OBJECT_TREE) < 0) { - git_error_set( - GIT_ERROR_CHECKOUT, "provided object cannot be peeled to a tree"); - return -1; - } - } - else { - if ((error = checkout_lookup_head_tree(&tree, repo)) < 0) { - if (error != GIT_EUNBORNBRANCH) - git_error_set( - GIT_ERROR_CHECKOUT, - "HEAD could not be peeled to a tree and no treeish given"); - return error; - } - } - - if ((error = git_repository_index(&index, repo)) < 0) - return error; - - setup_pathspecs(&iter_opts, opts); - - if (!(error = git_iterator_for_tree(&tree_i, tree, &iter_opts))) - error = git_checkout_iterator(tree_i, index, opts); - - git_iterator_free(tree_i); - git_index_free(index); - git_tree_free(tree); - - return error; -} - -int git_checkout_head( - git_repository *repo, - const git_checkout_options *opts) -{ - GIT_ASSERT_ARG(repo); - - return git_checkout_tree(repo, NULL, opts); -} - -int git_checkout_options_init(git_checkout_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_checkout_options, GIT_CHECKOUT_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_checkout_init_options(git_checkout_options *opts, unsigned int version) -{ - return git_checkout_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/checkout.h b/vendor/libgit2-sys/libgit2/src/libgit2/checkout.h deleted file mode 100644 index e613325..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/checkout.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_checkout_h__ -#define INCLUDE_checkout_h__ - -#include "common.h" - -#include "git2/checkout.h" -#include "iterator.h" - -/** - * Update the working directory to match the target iterator. The - * expected baseline value can be passed in via the checkout options - * or else will default to the HEAD commit. - */ -extern int git_checkout_iterator( - git_iterator *target, - git_index *index, - const git_checkout_options *opts); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/cherrypick.c b/vendor/libgit2-sys/libgit2/src/libgit2/cherrypick.c deleted file mode 100644 index 5613701..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/cherrypick.c +++ /dev/null @@ -1,241 +0,0 @@ -/* -* Copyright (C) the libgit2 contributors. All rights reserved. -* -* This file is part of libgit2, distributed under the GNU GPL v2 with -* a Linking Exception. For full terms see the included COPYING file. -*/ - -#include "common.h" - -#include "repository.h" -#include "filebuf.h" -#include "merge.h" -#include "vector.h" -#include "index.h" - -#include "git2/types.h" -#include "git2/merge.h" -#include "git2/cherrypick.h" -#include "git2/commit.h" -#include "git2/sys/commit.h" - -#define GIT_CHERRYPICK_FILE_MODE 0666 - -static int write_cherrypick_head( - git_repository *repo, - const char *commit_oidstr) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - int error = 0; - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 && - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) >= 0 && - (error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0) - error = git_filebuf_commit(&file); - - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - return error; -} - -static int write_merge_msg( - git_repository *repo, - const char *commit_msg) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - int error = 0; - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 || - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) < 0 || - (error = git_filebuf_printf(&file, "%s", commit_msg)) < 0) - goto cleanup; - - error = git_filebuf_commit(&file); - -cleanup: - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - return error; -} - -static int cherrypick_normalize_opts( - git_repository *repo, - git_cherrypick_options *opts, - const git_cherrypick_options *given, - const char *their_label) -{ - int error = 0; - unsigned int default_checkout_strategy = GIT_CHECKOUT_ALLOW_CONFLICTS; - - GIT_UNUSED(repo); - - if (given != NULL) - memcpy(opts, given, sizeof(git_cherrypick_options)); - else { - git_cherrypick_options default_opts = GIT_CHERRYPICK_OPTIONS_INIT; - memcpy(opts, &default_opts, sizeof(git_cherrypick_options)); - } - - if (!opts->checkout_opts.checkout_strategy) - opts->checkout_opts.checkout_strategy = default_checkout_strategy; - - if (!opts->checkout_opts.our_label) - opts->checkout_opts.our_label = "HEAD"; - - if (!opts->checkout_opts.their_label) - opts->checkout_opts.their_label = their_label; - - return error; -} - -static int cherrypick_state_cleanup(git_repository *repo) -{ - const char *state_files[] = { GIT_CHERRYPICK_HEAD_FILE, GIT_MERGE_MSG_FILE }; - - return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files)); -} - -static int cherrypick_seterr(git_commit *commit, const char *fmt) -{ - char commit_oidstr[GIT_OID_MAX_HEXSIZE + 1]; - - git_error_set(GIT_ERROR_CHERRYPICK, fmt, - git_oid_tostr(commit_oidstr, GIT_OID_MAX_HEXSIZE + 1, git_commit_id(commit))); - - return -1; -} - -int git_cherrypick_commit( - git_index **out, - git_repository *repo, - git_commit *cherrypick_commit, - git_commit *our_commit, - unsigned int mainline, - const git_merge_options *merge_opts) -{ - git_commit *parent_commit = NULL; - git_tree *parent_tree = NULL, *our_tree = NULL, *cherrypick_tree = NULL; - int parent = 0, error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(cherrypick_commit); - GIT_ASSERT_ARG(our_commit); - - if (git_commit_parentcount(cherrypick_commit) > 1) { - if (!mainline) - return cherrypick_seterr(cherrypick_commit, - "mainline branch is not specified but %s is a merge commit"); - - parent = mainline; - } else { - if (mainline) - return cherrypick_seterr(cherrypick_commit, - "mainline branch specified but %s is not a merge commit"); - - parent = git_commit_parentcount(cherrypick_commit); - } - - if (parent && - ((error = git_commit_parent(&parent_commit, cherrypick_commit, (parent - 1))) < 0 || - (error = git_commit_tree(&parent_tree, parent_commit)) < 0)) - goto done; - - if ((error = git_commit_tree(&cherrypick_tree, cherrypick_commit)) < 0 || - (error = git_commit_tree(&our_tree, our_commit)) < 0) - goto done; - - error = git_merge_trees(out, repo, parent_tree, our_tree, cherrypick_tree, merge_opts); - -done: - git_tree_free(parent_tree); - git_tree_free(our_tree); - git_tree_free(cherrypick_tree); - git_commit_free(parent_commit); - - return error; -} - -int git_cherrypick( - git_repository *repo, - git_commit *commit, - const git_cherrypick_options *given_opts) -{ - git_cherrypick_options opts; - git_reference *our_ref = NULL; - git_commit *our_commit = NULL; - char commit_oidstr[GIT_OID_MAX_HEXSIZE + 1]; - const char *commit_msg, *commit_summary; - git_str their_label = GIT_STR_INIT; - git_index *index = NULL; - git_indexwriter indexwriter = GIT_INDEXWRITER_INIT; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(commit); - - GIT_ERROR_CHECK_VERSION(given_opts, GIT_CHERRYPICK_OPTIONS_VERSION, "git_cherrypick_options"); - - if ((error = git_repository__ensure_not_bare(repo, "cherry-pick")) < 0) - return error; - - if ((commit_msg = git_commit_message(commit)) == NULL || - (commit_summary = git_commit_summary(commit)) == NULL) { - error = -1; - goto on_error; - } - - git_oid_nfmt(commit_oidstr, sizeof(commit_oidstr), git_commit_id(commit)); - - if ((error = write_merge_msg(repo, commit_msg)) < 0 || - (error = git_str_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 || - (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_str_cstr(&their_label))) < 0 || - (error = git_indexwriter_init_for_operation(&indexwriter, repo, &opts.checkout_opts.checkout_strategy)) < 0 || - (error = write_cherrypick_head(repo, commit_oidstr)) < 0 || - (error = git_repository_head(&our_ref, repo)) < 0 || - (error = git_reference_peel((git_object **)&our_commit, our_ref, GIT_OBJECT_COMMIT)) < 0 || - (error = git_cherrypick_commit(&index, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 || - (error = git_merge__check_result(repo, index)) < 0 || - (error = git_merge__append_conflicts_to_merge_msg(repo, index)) < 0 || - (error = git_checkout_index(repo, index, &opts.checkout_opts)) < 0 || - (error = git_indexwriter_commit(&indexwriter)) < 0) - goto on_error; - - goto done; - -on_error: - cherrypick_state_cleanup(repo); - -done: - git_indexwriter_cleanup(&indexwriter); - git_index_free(index); - git_commit_free(our_commit); - git_reference_free(our_ref); - git_str_dispose(&their_label); - - return error; -} - -int git_cherrypick_options_init( - git_cherrypick_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_cherrypick_options, GIT_CHERRYPICK_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_cherrypick_init_options( - git_cherrypick_options *opts, unsigned int version) -{ - return git_cherrypick_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/clone.c b/vendor/libgit2-sys/libgit2/src/libgit2/clone.c deleted file mode 100644 index 63b6b99..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/clone.c +++ /dev/null @@ -1,712 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "clone.h" - -#include "git2/clone.h" -#include "git2/remote.h" -#include "git2/revparse.h" -#include "git2/branch.h" -#include "git2/config.h" -#include "git2/checkout.h" -#include "git2/commit.h" -#include "git2/tree.h" - -#include "checkout.h" -#include "remote.h" -#include "futils.h" -#include "refs.h" -#include "fs_path.h" -#include "repository.h" -#include "odb.h" -#include "net.h" - -static int create_branch( - git_reference **branch, - git_repository *repo, - const git_oid *target, - const char *name, - const char *log_message) -{ - git_commit *head_obj = NULL; - git_reference *branch_ref = NULL; - git_str refname = GIT_STR_INIT; - int error; - - /* Find the target commit */ - if ((error = git_commit_lookup(&head_obj, repo, target)) < 0) - return error; - - /* Create the new branch */ - if ((error = git_str_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0) - return error; - - error = git_reference_create(&branch_ref, repo, git_str_cstr(&refname), target, 0, log_message); - git_str_dispose(&refname); - git_commit_free(head_obj); - - if (!error) - *branch = branch_ref; - else - git_reference_free(branch_ref); - - return error; -} - -static int setup_tracking_config( - git_repository *repo, - const char *branch_name, - const char *remote_name, - const char *merge_target) -{ - git_config *cfg; - git_str remote_key = GIT_STR_INIT, merge_key = GIT_STR_INIT; - int error = -1; - - if (git_repository_config__weakptr(&cfg, repo) < 0) - return -1; - - if (git_str_printf(&remote_key, "branch.%s.remote", branch_name) < 0) - goto cleanup; - - if (git_str_printf(&merge_key, "branch.%s.merge", branch_name) < 0) - goto cleanup; - - if (git_config_set_string(cfg, git_str_cstr(&remote_key), remote_name) < 0) - goto cleanup; - - if (git_config_set_string(cfg, git_str_cstr(&merge_key), merge_target) < 0) - goto cleanup; - - error = 0; - -cleanup: - git_str_dispose(&remote_key); - git_str_dispose(&merge_key); - return error; -} - -static int create_tracking_branch( - git_reference **branch, - git_repository *repo, - const git_oid *target, - const char *branch_name, - const char *log_message) -{ - int error; - - if ((error = create_branch(branch, repo, target, branch_name, log_message)) < 0) - return error; - - return setup_tracking_config( - repo, - branch_name, - GIT_REMOTE_ORIGIN, - git_reference_name(*branch)); -} - -static int update_head_to_new_branch( - git_repository *repo, - const git_oid *target, - const char *name, - const char *reflog_message) -{ - git_reference *tracking_branch = NULL; - int error; - - if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR)) - name += strlen(GIT_REFS_HEADS_DIR); - - error = create_tracking_branch(&tracking_branch, repo, target, name, - reflog_message); - - if (!error) - error = git_repository_set_head( - repo, git_reference_name(tracking_branch)); - - git_reference_free(tracking_branch); - - /* if it already existed, then the user's refspec created it for us, ignore it' */ - if (error == GIT_EEXISTS) - error = 0; - - return error; -} - -static int update_head_to_default(git_repository *repo) -{ - git_str initialbranch = GIT_STR_INIT; - const char *branch_name; - int error = 0; - - if ((error = git_repository_initialbranch(&initialbranch, repo)) < 0) - goto done; - - if (git__prefixcmp(initialbranch.ptr, GIT_REFS_HEADS_DIR) != 0) { - git_error_set(GIT_ERROR_INVALID, "invalid initial branch '%s'", initialbranch.ptr); - error = -1; - goto done; - } - - branch_name = initialbranch.ptr + strlen(GIT_REFS_HEADS_DIR); - - error = setup_tracking_config(repo, branch_name, GIT_REMOTE_ORIGIN, - initialbranch.ptr); - -done: - git_str_dispose(&initialbranch); - return error; -} - -static int update_remote_head( - git_repository *repo, - git_remote *remote, - git_str *target, - const char *reflog_message) -{ - git_refspec *refspec; - git_reference *remote_head = NULL; - git_str remote_head_name = GIT_STR_INIT; - git_str remote_branch_name = GIT_STR_INIT; - int error; - - /* Determine the remote tracking ref name from the local branch */ - refspec = git_remote__matching_refspec(remote, git_str_cstr(target)); - - if (refspec == NULL) { - git_error_set(GIT_ERROR_NET, "the remote's default branch does not fit the refspec configuration"); - error = GIT_EINVALIDSPEC; - goto cleanup; - } - - if ((error = git_refspec__transform( - &remote_branch_name, - refspec, - git_str_cstr(target))) < 0) - goto cleanup; - - if ((error = git_str_printf(&remote_head_name, - "%s%s/%s", - GIT_REFS_REMOTES_DIR, - git_remote_name(remote), - GIT_HEAD_FILE)) < 0) - goto cleanup; - - error = git_reference_symbolic_create( - &remote_head, - repo, - git_str_cstr(&remote_head_name), - git_str_cstr(&remote_branch_name), - true, - reflog_message); - -cleanup: - git_reference_free(remote_head); - git_str_dispose(&remote_branch_name); - git_str_dispose(&remote_head_name); - return error; -} - -static int update_head_to_remote( - git_repository *repo, - git_remote *remote, - const char *reflog_message) -{ - int error = 0; - size_t refs_len; - const git_remote_head *remote_head, **refs; - const git_oid *remote_head_id; - git_str branch = GIT_STR_INIT; - - if ((error = git_remote_ls(&refs, &refs_len, remote)) < 0) - return error; - - /* We cloned an empty repository or one with an unborn HEAD */ - if (refs_len == 0 || strcmp(refs[0]->name, GIT_HEAD_FILE)) - return update_head_to_default(repo); - - /* We know we have HEAD, let's see where it points */ - remote_head = refs[0]; - GIT_ASSERT(remote_head); - - remote_head_id = &remote_head->oid; - - error = git_remote__default_branch(&branch, remote); - if (error == GIT_ENOTFOUND) { - error = git_repository_set_head_detached( - repo, remote_head_id); - goto cleanup; - } - - if ((error = update_remote_head(repo, remote, &branch, reflog_message)) < 0) - goto cleanup; - - error = update_head_to_new_branch( - repo, - remote_head_id, - git_str_cstr(&branch), - reflog_message); - -cleanup: - git_str_dispose(&branch); - - return error; -} - -static int update_head_to_branch( - git_repository *repo, - git_remote *remote, - const char *branch, - const char *reflog_message) -{ - int retcode; - git_str remote_branch_name = GIT_STR_INIT; - git_reference *remote_ref = NULL; - git_str default_branch = GIT_STR_INIT; - - GIT_ASSERT_ARG(remote); - GIT_ASSERT_ARG(branch); - - if ((retcode = git_str_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s", - git_remote_name(remote), branch)) < 0 ) - goto cleanup; - - if ((retcode = git_reference_lookup(&remote_ref, repo, git_str_cstr(&remote_branch_name))) < 0) - goto cleanup; - - if ((retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch, - reflog_message)) < 0) - goto cleanup; - - retcode = git_remote__default_branch(&default_branch, remote); - - if (retcode == GIT_ENOTFOUND) - retcode = 0; - else if (retcode) - goto cleanup; - - if (!git_remote__matching_refspec(remote, git_str_cstr(&default_branch))) - goto cleanup; - - retcode = update_remote_head(repo, remote, &default_branch, reflog_message); - -cleanup: - git_reference_free(remote_ref); - git_str_dispose(&remote_branch_name); - git_str_dispose(&default_branch); - return retcode; -} - -static int default_repository_create(git_repository **out, const char *path, int bare, void *payload) -{ - GIT_UNUSED(payload); - - return git_repository_init(out, path, bare); -} - -static int default_remote_create( - git_remote **out, - git_repository *repo, - const char *name, - const char *url, - void *payload) -{ - GIT_UNUSED(payload); - - return git_remote_create(out, repo, name, url); -} - -/* - * submodules? - */ - -static int create_and_configure_origin( - git_remote **out, - git_repository *repo, - const char *url, - const git_clone_options *options) -{ - int error; - git_remote *origin = NULL; - char buf[GIT_PATH_MAX]; - git_remote_create_cb remote_create = options->remote_cb; - void *payload = options->remote_cb_payload; - - /* If the path is local and exists it should be the absolute path. */ - if (!git_net_str_is_url(url) && git_fs_path_root(url) < 0 && - git_fs_path_exists(url)) { - if (p_realpath(url, buf) == NULL) - return -1; - - url = buf; - } - - if (!remote_create) { - remote_create = default_remote_create; - payload = NULL; - } - - if ((error = remote_create(&origin, repo, "origin", url, payload)) < 0) - goto on_error; - - *out = origin; - return 0; - -on_error: - git_remote_free(origin); - return error; -} - -static int should_checkout( - bool *out, - git_repository *repo, - bool is_bare, - const git_clone_options *opts) -{ - int error; - - if (!opts || is_bare || - opts->checkout_opts.checkout_strategy == GIT_CHECKOUT_NONE) { - *out = false; - return 0; - } - - if ((error = git_repository_head_unborn(repo)) < 0) - return error; - - *out = !error; - return 0; -} - -static int checkout_branch( - git_repository *repo, - git_remote *remote, - const git_clone_options *opts, - const char *reflog_message) -{ - bool checkout; - int error; - - if (opts->checkout_branch) - error = update_head_to_branch(repo, remote, opts->checkout_branch, reflog_message); - /* Point HEAD to the same ref as the remote's head */ - else - error = update_head_to_remote(repo, remote, reflog_message); - - if (error < 0) - return error; - - if ((error = should_checkout(&checkout, repo, git_repository_is_bare(repo), opts)) < 0) - return error; - - if (checkout) - error = git_checkout_head(repo, &opts->checkout_opts); - - return error; -} - -static int clone_into( - git_repository *repo, - git_remote *_remote, - const git_clone_options *opts) -{ - git_str reflog_message = GIT_STR_INIT; - git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; - git_remote *remote; - git_oid_t oid_type; - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(_remote); - - if (!git_repository_is_empty(repo)) { - git_error_set(GIT_ERROR_INVALID, "the repository is not empty"); - return -1; - } - - if ((error = git_remote_dup(&remote, _remote)) < 0) - return error; - - if ((error = git_remote_connect_options__from_fetch_opts(&connect_opts, remote, &opts->fetch_opts)) < 0) - goto cleanup; - - git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote)); - - /* - * Connect to the server so that we can identify the remote - * object format. - */ - - if ((error = git_remote_connect_ext(remote, GIT_DIRECTION_FETCH, - &connect_opts)) < 0) - goto cleanup; - - if ((error = git_remote_oid_type(&oid_type, remote)) < 0 || - (error = git_repository__set_objectformat(repo, oid_type)) < 0) - goto cleanup; - - if ((error = git_remote_fetch(remote, NULL, &opts->fetch_opts, git_str_cstr(&reflog_message))) != 0) - goto cleanup; - - error = checkout_branch(repo, remote, opts, git_str_cstr(&reflog_message)); - -cleanup: - git_remote_free(remote); - git_remote_connect_options_dispose(&connect_opts); - git_str_dispose(&reflog_message); - - return error; -} - -static bool can_link(const char *src, const char *dst, int link) -{ -#ifdef GIT_WIN32 - GIT_UNUSED(src); - GIT_UNUSED(dst); - GIT_UNUSED(link); - return false; -#else - - struct stat st_src, st_dst; - - if (!link) - return false; - - if (p_stat(src, &st_src) < 0) - return false; - - if (p_stat(dst, &st_dst) < 0) - return false; - - return st_src.st_dev == st_dst.st_dev; -#endif -} - -static int clone_local_into( - git_repository *repo, - git_remote *remote, - const git_clone_options *opts) -{ - int error, flags; - git_repository *src; - git_str src_odb = GIT_STR_INIT, dst_odb = GIT_STR_INIT, src_path = GIT_STR_INIT; - git_str reflog_message = GIT_STR_INIT; - bool link = (opts && opts->local != GIT_CLONE_LOCAL_NO_LINKS); - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(remote); - - if (!git_repository_is_empty(repo)) { - git_error_set(GIT_ERROR_INVALID, "the repository is not empty"); - return -1; - } - - /* - * Let's figure out what path we should use for the source - * repo, if it's not rooted, the path should be relative to - * the repository's worktree/gitdir. - */ - if ((error = git_fs_path_from_url_or_path(&src_path, git_remote_url(remote))) < 0) - return error; - - /* Copy .git/objects/ from the source to the target */ - if ((error = git_repository_open(&src, git_str_cstr(&src_path))) < 0) { - git_str_dispose(&src_path); - return error; - } - - /* Propagate the source repository's object format to the target - * so that it can read the copied object database. */ - if ((error = git_repository__set_objectformat( - repo, git_repository_oid_type(src))) < 0) - goto cleanup; - - if (git_repository__item_path(&src_odb, src, GIT_REPOSITORY_ITEM_OBJECTS) < 0 || - git_repository__item_path(&dst_odb, repo, GIT_REPOSITORY_ITEM_OBJECTS) < 0) { - error = -1; - goto cleanup; - } - - flags = 0; - if (can_link(git_repository_path(src), git_repository_path(repo), link)) - flags |= GIT_CPDIR_LINK_FILES; - - error = git_futils_cp_r(git_str_cstr(&src_odb), git_str_cstr(&dst_odb), - flags, GIT_OBJECT_DIR_MODE); - - /* - * can_link() doesn't catch all variations, so if we hit an - * error and did want to link, let's try again without trying - * to link. - */ - if (error < 0 && link) { - flags &= ~GIT_CPDIR_LINK_FILES; - error = git_futils_cp_r(git_str_cstr(&src_odb), git_str_cstr(&dst_odb), - flags, GIT_OBJECT_DIR_MODE); - } - - if (error < 0) - goto cleanup; - - git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote)); - - if ((error = git_remote_fetch(remote, NULL, &opts->fetch_opts, git_str_cstr(&reflog_message))) != 0) - goto cleanup; - - error = checkout_branch(repo, remote, opts, git_str_cstr(&reflog_message)); - -cleanup: - git_str_dispose(&reflog_message); - git_str_dispose(&src_path); - git_str_dispose(&src_odb); - git_str_dispose(&dst_odb); - git_repository_free(src); - return error; -} - -int git_clone__should_clone_local( - bool *out, - const char *url_or_path, - git_clone_local_t local) -{ - git_str fromurl = GIT_STR_INIT; - - *out = false; - - if (local == GIT_CLONE_NO_LOCAL) - return 0; - - if (git_net_str_is_url(url_or_path)) { - /* If GIT_CLONE_LOCAL_AUTO is specified, any url should - * be treated as remote */ - if (local == GIT_CLONE_LOCAL_AUTO || - !git_fs_path_is_local_file_url(url_or_path)) - return 0; - - if (git_fs_path_fromurl(&fromurl, url_or_path) < 0) - return -1; - - *out = git_fs_path_isdir(git_str_cstr(&fromurl)); - git_str_dispose(&fromurl); - } else { - *out = git_fs_path_isdir(url_or_path); - } - - return 0; -} - -static int clone_repo( - git_repository **out, - const char *url, - const char *local_path, - const git_clone_options *given_opts, - int use_existing) -{ - int error = 0; - git_repository *repo = NULL; - git_remote *origin; - git_clone_options options = GIT_CLONE_OPTIONS_INIT; - uint32_t rmdir_flags = GIT_RMDIR_REMOVE_FILES; - git_repository_create_cb repository_cb; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(url); - GIT_ASSERT_ARG(local_path); - - if (given_opts) - memcpy(&options, given_opts, sizeof(git_clone_options)); - - GIT_ERROR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options"); - - /* enforce some behavior on fetch */ - options.fetch_opts.update_fetchhead = 0; - - if (!options.fetch_opts.depth) - options.fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL; - - /* Only clone to a new directory or an empty directory */ - if (git_fs_path_exists(local_path) && !use_existing && !git_fs_path_is_empty_dir(local_path)) { - git_error_set(GIT_ERROR_INVALID, - "'%s' exists and is not an empty directory", local_path); - return GIT_EEXISTS; - } - - /* Only remove the root directory on failure if we create it */ - if (git_fs_path_exists(local_path)) - rmdir_flags |= GIT_RMDIR_SKIP_ROOT; - - if (options.repository_cb) - repository_cb = options.repository_cb; - else - repository_cb = default_repository_create; - - if ((error = repository_cb(&repo, local_path, options.bare, options.repository_cb_payload)) < 0) - return error; - - if (!(error = create_and_configure_origin(&origin, repo, url, &options))) { - bool clone_local; - - if ((error = git_clone__should_clone_local(&clone_local, url, options.local)) < 0) { - git_remote_free(origin); - return error; - } - - if (clone_local) - error = clone_local_into(repo, origin, &options); - else - error = clone_into(repo, origin, &options); - - git_remote_free(origin); - } - - if (error != 0) { - git_error *last_error; - git_error_save(&last_error); - - git_repository_free(repo); - repo = NULL; - - (void)git_futils_rmdir_r(local_path, NULL, rmdir_flags); - - git_error_restore(last_error); - } - - *out = repo; - return error; -} - -int git_clone( - git_repository **out, - const char *url, - const char *local_path, - const git_clone_options *options) -{ - return clone_repo(out, url, local_path, options, 0); -} - -int git_clone__submodule( - git_repository **out, - const char *url, - const char *local_path, - const git_clone_options *options) -{ - return clone_repo(out, url, local_path, options, 1); -} - -int git_clone_options_init(git_clone_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_clone_options, GIT_CLONE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_clone_init_options(git_clone_options *opts, unsigned int version) -{ - return git_clone_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/clone.h b/vendor/libgit2-sys/libgit2/src/libgit2/clone.h deleted file mode 100644 index fde796f..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/clone.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_clone_h__ -#define INCLUDE_clone_h__ - -#include "common.h" - -#include "git2/clone.h" - -extern int git_clone__submodule(git_repository **out, - const char *url, const char *local_path, - const git_clone_options *_options); - -extern int git_clone__should_clone_local( - bool *out, - const char *url, - git_clone_local_t local); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/commit.c b/vendor/libgit2-sys/libgit2/src/libgit2/commit.c deleted file mode 100644 index 6332792..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/commit.c +++ /dev/null @@ -1,1191 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "commit.h" - -#include "git2/common.h" -#include "git2/object.h" -#include "git2/repository.h" -#include "git2/signature.h" -#include "git2/mailmap.h" -#include "git2/sys/commit.h" - -#include "buf.h" -#include "odb.h" -#include "commit.h" -#include "signature.h" -#include "refs.h" -#include "object.h" -#include "array.h" -#include "oidarray.h" -#include "grafts.h" - -void git_commit__free(void *_commit) -{ - git_commit *commit = _commit; - - git_array_clear(commit->parent_ids); - - git_signature_free(commit->author); - git_signature_free(commit->committer); - - git__free(commit->raw_header); - git__free(commit->raw_message); - git__free(commit->message_encoding); - git__free(commit->summary); - git__free(commit->body); - - git__free(commit); -} - -static int git_commit__create_buffer_internal( - git_str *out, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_oid *tree, - git_array_oid_t *parents) -{ - size_t i = 0; - const git_oid *parent; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(tree); - - if (git_object__write_oid_header(out, "tree ", tree) < 0) - goto on_error; - - for (i = 0; i < git_array_size(*parents); i++) { - parent = git_array_get(*parents, i); - if (git_object__write_oid_header(out, "parent ", parent) < 0) - goto on_error; - } - - git_signature__writebuf(out, "author ", author); - git_signature__writebuf(out, "committer ", committer); - - if (message_encoding != NULL) - git_str_printf(out, "encoding %s\n", message_encoding); - - git_str_putc(out, '\n'); - - if (git_str_puts(out, message) < 0) - goto on_error; - - return 0; - -on_error: - git_str_dispose(out); - return -1; -} - -static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *repo, const git_oid *tree, - git_commit_parent_callback parent_cb, void *parent_payload, - const git_oid *current_id, bool validate) -{ - size_t i; - int error; - git_oid *parent_cpy; - const git_oid *parent; - - if (validate && !git_object__is_valid(repo, tree, GIT_OBJECT_TREE)) - return -1; - - i = 0; - while ((parent = parent_cb(i, parent_payload)) != NULL) { - if (validate && !git_object__is_valid(repo, parent, GIT_OBJECT_COMMIT)) { - error = -1; - goto on_error; - } - - parent_cpy = git_array_alloc(*parents); - GIT_ERROR_CHECK_ALLOC(parent_cpy); - - git_oid_cpy(parent_cpy, parent); - i++; - } - - if (current_id && (parents->size == 0 || git_oid_cmp(current_id, git_array_get(*parents, 0)))) { - git_error_set(GIT_ERROR_OBJECT, "failed to create commit: current tip is not the first parent"); - error = GIT_EMODIFIED; - goto on_error; - } - - return 0; - -on_error: - git_array_clear(*parents); - return error; -} - -static int git_commit__create_internal( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_oid *tree, - git_commit_parent_callback parent_cb, - void *parent_payload, - bool validate) -{ - int error; - git_odb *odb; - git_reference *ref = NULL; - git_str buf = GIT_STR_INIT; - const git_oid *current_id = NULL; - git_array_oid_t parents = GIT_ARRAY_INIT; - - if (update_ref) { - error = git_reference_lookup_resolved(&ref, repo, update_ref, 10); - if (error < 0 && error != GIT_ENOTFOUND) - return error; - } - git_error_clear(); - - if (ref) - current_id = git_reference_target(ref); - - if ((error = validate_tree_and_parents(&parents, repo, tree, parent_cb, parent_payload, current_id, validate)) < 0) - goto cleanup; - - error = git_commit__create_buffer_internal(&buf, author, committer, - message_encoding, message, tree, - &parents); - - if (error < 0) - goto cleanup; - - if (git_repository_odb__weakptr(&odb, repo) < 0) - goto cleanup; - - if (git_odb__freshen(odb, tree) < 0) - goto cleanup; - - if (git_odb_write(id, odb, buf.ptr, buf.size, GIT_OBJECT_COMMIT) < 0) - goto cleanup; - - - if (update_ref != NULL) { - error = git_reference__update_for_commit( - repo, ref, update_ref, id, "commit"); - goto cleanup; - } - -cleanup: - git_array_clear(parents); - git_reference_free(ref); - git_str_dispose(&buf); - return error; -} - -int git_commit_create_from_callback( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_oid *tree, - git_commit_parent_callback parent_cb, - void *parent_payload) -{ - return git_commit__create_internal( - id, repo, update_ref, author, committer, message_encoding, message, - tree, parent_cb, parent_payload, true); -} - -typedef struct { - size_t total; - va_list args; -} commit_parent_varargs; - -static const git_oid *commit_parent_from_varargs(size_t curr, void *payload) -{ - commit_parent_varargs *data = payload; - const git_commit *commit; - if (curr >= data->total) - return NULL; - commit = va_arg(data->args, const git_commit *); - return commit ? git_commit_id(commit) : NULL; -} - -int git_commit_create_v( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - ...) -{ - int error = 0; - commit_parent_varargs data; - - GIT_ASSERT_ARG(tree); - GIT_ASSERT_ARG(git_tree_owner(tree) == repo); - - data.total = parent_count; - va_start(data.args, parent_count); - - error = git_commit__create_internal( - id, repo, update_ref, author, committer, - message_encoding, message, git_tree_id(tree), - commit_parent_from_varargs, &data, false); - - va_end(data.args); - return error; -} - -typedef struct { - size_t total; - const git_oid **parents; -} commit_parent_oids; - -static const git_oid *commit_parent_from_ids(size_t curr, void *payload) -{ - commit_parent_oids *data = payload; - return (curr < data->total) ? data->parents[curr] : NULL; -} - -int git_commit_create_from_ids( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_oid *tree, - size_t parent_count, - const git_oid *parents[]) -{ - commit_parent_oids data = { parent_count, parents }; - - return git_commit__create_internal( - id, repo, update_ref, author, committer, - message_encoding, message, tree, - commit_parent_from_ids, &data, true); -} - -typedef struct { - size_t total; - const git_commit **parents; - git_repository *repo; -} commit_parent_data; - -static const git_oid *commit_parent_from_array(size_t curr, void *payload) -{ - commit_parent_data *data = payload; - const git_commit *commit; - if (curr >= data->total) - return NULL; - commit = data->parents[curr]; - if (git_commit_owner(commit) != data->repo) - return NULL; - return git_commit_id(commit); -} - -int git_commit_create( - git_oid *id, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - const git_commit *parents[]) -{ - commit_parent_data data = { parent_count, parents, repo }; - - GIT_ASSERT_ARG(tree); - GIT_ASSERT_ARG(git_tree_owner(tree) == repo); - - return git_commit__create_internal( - id, repo, update_ref, author, committer, - message_encoding, message, git_tree_id(tree), - commit_parent_from_array, &data, false); -} - -static const git_oid *commit_parent_for_amend(size_t curr, void *payload) -{ - const git_commit *commit_to_amend = payload; - if (curr >= git_array_size(commit_to_amend->parent_ids)) - return NULL; - return git_array_get(commit_to_amend->parent_ids, curr); -} - -int git_commit_amend( - git_oid *id, - const git_commit *commit_to_amend, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree) -{ - git_repository *repo; - git_oid tree_id; - git_reference *ref = NULL; - int error; - - GIT_ASSERT_ARG(id); - GIT_ASSERT_ARG(commit_to_amend); - - repo = git_commit_owner(commit_to_amend); - - if (!author) - author = git_commit_author(commit_to_amend); - if (!committer) - committer = git_commit_committer(commit_to_amend); - if (!message_encoding) - message_encoding = git_commit_message_encoding(commit_to_amend); - if (!message) - message = git_commit_message(commit_to_amend); - - if (!tree) { - git_tree *old_tree; - GIT_ERROR_CHECK_ERROR( git_commit_tree(&old_tree, commit_to_amend) ); - git_oid_cpy(&tree_id, git_tree_id(old_tree)); - git_tree_free(old_tree); - } else { - GIT_ASSERT_ARG(git_tree_owner(tree) == repo); - git_oid_cpy(&tree_id, git_tree_id(tree)); - } - - if (update_ref) { - if ((error = git_reference_lookup_resolved(&ref, repo, update_ref, 5)) < 0) - return error; - - if (git_oid_cmp(git_commit_id(commit_to_amend), git_reference_target(ref))) { - git_reference_free(ref); - git_error_set(GIT_ERROR_REFERENCE, "commit to amend is not the tip of the given branch"); - return -1; - } - } - - error = git_commit__create_internal( - id, repo, NULL, author, committer, message_encoding, message, - &tree_id, commit_parent_for_amend, (void *)commit_to_amend, false); - - if (!error && update_ref) { - error = git_reference__update_for_commit( - repo, ref, NULL, id, "commit"); - git_reference_free(ref); - } - - return error; -} - -static int commit_parse( - git_commit *commit, - const char *data, - size_t size, - git_commit__parse_options *opts) -{ - const char *buffer_start = data, *buffer; - const char *buffer_end = buffer_start + size; - git_oid parent_id; - size_t header_len; - git_signature dummy_sig; - int error; - - GIT_ASSERT_ARG(commit); - GIT_ASSERT_ARG(data); - GIT_ASSERT_ARG(opts); - - buffer = buffer_start; - - /* Allocate for one, which will allow not to realloc 90% of the time */ - git_array_init_to_size(commit->parent_ids, 1); - GIT_ERROR_CHECK_ARRAY(commit->parent_ids); - - /* The tree is always the first field */ - if (!(opts->flags & GIT_COMMIT_PARSE_QUICK)) { - if (git_object__parse_oid_header(&commit->tree_id, - &buffer, buffer_end, "tree ", - opts->oid_type) < 0) - goto bad_buffer; - } else { - size_t tree_len = strlen("tree ") + git_oid_hexsize(opts->oid_type) + 1; - - if (buffer + tree_len > buffer_end) - goto bad_buffer; - buffer += tree_len; - } - - while (git_object__parse_oid_header(&parent_id, - &buffer, buffer_end, "parent ", - opts->oid_type) == 0) { - git_oid *new_id = git_array_alloc(commit->parent_ids); - GIT_ERROR_CHECK_ALLOC(new_id); - - git_oid_cpy(new_id, &parent_id); - } - - if (!opts || !(opts->flags & GIT_COMMIT_PARSE_QUICK)) { - commit->author = git__malloc(sizeof(git_signature)); - GIT_ERROR_CHECK_ALLOC(commit->author); - - if ((error = git_signature__parse(commit->author, &buffer, buffer_end, "author ", '\n')) < 0) - return error; - } - - /* Some tools create multiple author fields, ignore the extra ones */ - while (!git__prefixncmp(buffer, buffer_end - buffer, "author ")) { - if ((error = git_signature__parse(&dummy_sig, &buffer, buffer_end, "author ", '\n')) < 0) - return error; - - git__free(dummy_sig.name); - git__free(dummy_sig.email); - } - - /* Always parse the committer; we need the commit time */ - commit->committer = git__malloc(sizeof(git_signature)); - GIT_ERROR_CHECK_ALLOC(commit->committer); - - if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n')) < 0) - return error; - - if (opts && opts->flags & GIT_COMMIT_PARSE_QUICK) - return 0; - - /* Parse add'l header entries */ - while (buffer < buffer_end) { - const char *eoln = buffer; - if (buffer[-1] == '\n' && buffer[0] == '\n') - break; - - while (eoln < buffer_end && *eoln != '\n') - ++eoln; - - if (git__prefixncmp(buffer, buffer_end - buffer, "encoding ") == 0) { - buffer += strlen("encoding "); - - commit->message_encoding = git__strndup(buffer, eoln - buffer); - GIT_ERROR_CHECK_ALLOC(commit->message_encoding); - } - - if (eoln < buffer_end && *eoln == '\n') - ++eoln; - buffer = eoln; - } - - header_len = buffer - buffer_start; - commit->raw_header = git__strndup(buffer_start, header_len); - GIT_ERROR_CHECK_ALLOC(commit->raw_header); - - /* point "buffer" to data after header, +1 for the final LF */ - buffer = buffer_start + header_len + 1; - - /* extract commit message */ - if (buffer <= buffer_end) - commit->raw_message = git__strndup(buffer, buffer_end - buffer); - else - commit->raw_message = git__strdup(""); - GIT_ERROR_CHECK_ALLOC(commit->raw_message); - - return 0; - -bad_buffer: - git_error_set(GIT_ERROR_OBJECT, "failed to parse bad commit object"); - return GIT_EINVALID; -} - -int git_commit__parse( - void *commit, - git_odb_object *odb_obj, - git_oid_t oid_type) -{ - git_commit__parse_options parse_options = {0}; - parse_options.oid_type = oid_type; - - return git_commit__parse_ext(commit, odb_obj, &parse_options); -} - -int git_commit__parse_raw( - void *commit, - const char *data, - size_t size, - git_oid_t oid_type) -{ - git_commit__parse_options parse_options = {0}; - parse_options.oid_type = oid_type; - - return commit_parse(commit, data, size, &parse_options); -} - -static int assign_commit_parents_from_graft(git_commit *commit, git_commit_graft *graft) { - size_t idx; - git_oid *oid; - - git_array_clear(commit->parent_ids); - git_array_init_to_size(commit->parent_ids, git_array_size(graft->parents)); - git_array_foreach(graft->parents, idx, oid) { - git_oid *id = git_array_alloc(commit->parent_ids); - GIT_ERROR_CHECK_ALLOC(id); - - git_oid_cpy(id, oid); - } - - return 0; -} - -int git_commit__parse_ext( - git_commit *commit, - git_odb_object *odb_obj, - git_commit__parse_options *parse_opts) -{ - git_repository *repo = git_object_owner((git_object *)commit); - git_commit_graft *graft; - int error; - - if ((error = commit_parse(commit, git_odb_object_data(odb_obj), - git_odb_object_size(odb_obj), parse_opts)) < 0) - return error; - - /* Perform necessary grafts */ - if (git_grafts_get(&graft, repo->grafts, git_odb_object_id(odb_obj)) != 0 && - git_grafts_get(&graft, repo->shallow_grafts, git_odb_object_id(odb_obj)) != 0) - return 0; - - return assign_commit_parents_from_graft(commit, graft); -} - -#define GIT_COMMIT_GETTER(_rvalue, _name, _return, _invalid) \ - _rvalue git_commit_##_name(const git_commit *commit) \ - {\ - GIT_ASSERT_ARG_WITH_RETVAL(commit, _invalid); \ - return _return; \ - } - -GIT_COMMIT_GETTER(const git_signature *, author, commit->author, NULL) -GIT_COMMIT_GETTER(const git_signature *, committer, commit->committer, NULL) -GIT_COMMIT_GETTER(const char *, message_raw, commit->raw_message, NULL) -GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding, NULL) -GIT_COMMIT_GETTER(const char *, raw_header, commit->raw_header, NULL) -GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time, INT64_MIN) -GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset, -1) -GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)git_array_size(commit->parent_ids), 0) -GIT_COMMIT_GETTER(const git_oid *, tree_id, &commit->tree_id, NULL) - -const char *git_commit_message(const git_commit *commit) -{ - const char *message; - - GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL); - - message = commit->raw_message; - - /* trim leading newlines from raw message */ - while (*message && *message == '\n') - ++message; - - return message; -} - -const char *git_commit_summary(git_commit *commit) -{ - git_str summary = GIT_STR_INIT; - const char *msg, *space, *next; - bool space_contains_newline = false; - - GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL); - - if (!commit->summary) { - for (msg = git_commit_message(commit), space = NULL; *msg; ++msg) { - char next_character = msg[0]; - /* stop processing at the end of the first paragraph */ - if (next_character == '\n') { - if (!msg[1]) - break; - if (msg[1] == '\n') - break; - /* stop processing if next line contains only whitespace */ - next = msg + 1; - while (*next && git__isspace_nonlf(*next)) { - ++next; - } - if (!*next || *next == '\n') - break; - } - /* record the beginning of contiguous whitespace runs */ - if (git__isspace(next_character)) { - if(space == NULL) { - space = msg; - space_contains_newline = false; - } - space_contains_newline |= next_character == '\n'; - } - /* the next character is non-space */ - else { - /* process any recorded whitespace */ - if (space) { - if(space_contains_newline) - git_str_putc(&summary, ' '); /* if the space contains a newline, collapse to ' ' */ - else - git_str_put(&summary, space, (msg - space)); /* otherwise copy it */ - space = NULL; - } - /* copy the next character */ - git_str_putc(&summary, next_character); - } - } - - commit->summary = git_str_detach(&summary); - if (!commit->summary) - commit->summary = git__strdup(""); - } - - return commit->summary; -} - -const char *git_commit_body(git_commit *commit) -{ - const char *msg, *end; - - GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL); - - if (!commit->body) { - /* search for end of summary */ - for (msg = git_commit_message(commit); *msg; ++msg) - if (msg[0] == '\n' && (!msg[1] || msg[1] == '\n')) - break; - - /* trim leading and trailing whitespace */ - for (; *msg; ++msg) - if (!git__isspace(*msg)) - break; - for (end = msg + strlen(msg) - 1; msg <= end; --end) - if (!git__isspace(*end)) - break; - - if (*msg) - commit->body = git__strndup(msg, end - msg + 1); - } - - return commit->body; -} - -int git_commit_tree(git_tree **tree_out, const git_commit *commit) -{ - GIT_ASSERT_ARG(commit); - return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_id); -} - -const git_oid *git_commit_parent_id( - const git_commit *commit, unsigned int n) -{ - GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL); - - return git_array_get(commit->parent_ids, n); -} - -int git_commit_parent( - git_commit **parent, const git_commit *commit, unsigned int n) -{ - const git_oid *parent_id; - GIT_ASSERT_ARG(commit); - - parent_id = git_commit_parent_id(commit, n); - if (parent_id == NULL) { - git_error_set(GIT_ERROR_INVALID, "parent %u does not exist", n); - return GIT_ENOTFOUND; - } - - return git_commit_lookup(parent, commit->object.repo, parent_id); -} - -int git_commit_nth_gen_ancestor( - git_commit **ancestor, - const git_commit *commit, - unsigned int n) -{ - git_commit *current, *parent = NULL; - int error; - - GIT_ASSERT_ARG(ancestor); - GIT_ASSERT_ARG(commit); - - if (git_commit_dup(¤t, (git_commit *)commit) < 0) - return -1; - - if (n == 0) { - *ancestor = current; - return 0; - } - - while (n--) { - error = git_commit_parent(&parent, current, 0); - - git_commit_free(current); - - if (error < 0) - return error; - - current = parent; - } - - *ancestor = parent; - return 0; -} - -int git_commit_header_field( - git_buf *out, - const git_commit *commit, - const char *field) -{ - GIT_BUF_WRAP_PRIVATE(out, git_commit__header_field, commit, field); -} - -int git_commit__header_field( - git_str *out, - const git_commit *commit, - const char *field) -{ - const char *eol, *buf = commit->raw_header; - - git_str_clear(out); - - while ((eol = strchr(buf, '\n'))) { - /* We can skip continuations here */ - if (buf[0] == ' ') { - buf = eol + 1; - continue; - } - - /* Skip until we find the field we're after */ - if (git__prefixcmp(buf, field)) { - buf = eol + 1; - continue; - } - - buf += strlen(field); - /* Check that we're not matching a prefix but the field itself */ - if (buf[0] != ' ') { - buf = eol + 1; - continue; - } - - buf++; /* skip the SP */ - - git_str_put(out, buf, eol - buf); - if (git_str_oom(out)) - goto oom; - - /* If the next line starts with SP, it's multi-line, we must continue */ - while (eol[1] == ' ') { - git_str_putc(out, '\n'); - buf = eol + 2; - eol = strchr(buf, '\n'); - if (!eol) - goto malformed; - - git_str_put(out, buf, eol - buf); - } - - if (git_str_oom(out)) - goto oom; - - return 0; - } - - git_error_set(GIT_ERROR_OBJECT, "no such field '%s'", field); - return GIT_ENOTFOUND; - -malformed: - git_error_set(GIT_ERROR_OBJECT, "malformed header"); - return -1; -oom: - git_error_set_oom(); - return -1; -} - -int git_commit_extract_signature( - git_buf *signature_out, - git_buf *signed_data_out, - git_repository *repo, - git_oid *commit_id, - const char *field) -{ - git_str signature = GIT_STR_INIT, signed_data = GIT_STR_INIT; - int error; - - if ((error = git_buf_tostr(&signature, signature_out)) < 0 || - (error = git_buf_tostr(&signed_data, signed_data_out)) < 0 || - (error = git_commit__extract_signature(&signature, &signed_data, repo, commit_id, field)) < 0 || - (error = git_buf_fromstr(signature_out, &signature)) < 0 || - (error = git_buf_fromstr(signed_data_out, &signed_data)) < 0) - goto done; - -done: - git_str_dispose(&signature); - git_str_dispose(&signed_data); - return error; -} - -int git_commit__extract_signature( - git_str *signature, - git_str *signed_data, - git_repository *repo, - git_oid *commit_id, - const char *field) -{ - git_odb_object *obj; - git_odb *odb; - const char *buf; - const char *h, *eol; - int error; - - git_str_clear(signature); - git_str_clear(signed_data); - - if (!field) - field = "gpgsig"; - - if ((error = git_repository_odb__weakptr(&odb, repo)) < 0) - return error; - - if ((error = git_odb_read(&obj, odb, commit_id)) < 0) - return error; - - if (obj->cached.type != GIT_OBJECT_COMMIT) { - git_error_set(GIT_ERROR_INVALID, "the requested type does not match the type in the ODB"); - error = GIT_ENOTFOUND; - goto cleanup; - } - - buf = git_odb_object_data(obj); - - while ((h = strchr(buf, '\n')) && h[1] != '\0') { - h++; - if (git__prefixcmp(buf, field)) { - if (git_str_put(signed_data, buf, h - buf) < 0) - return -1; - - buf = h; - continue; - } - - h = buf; - h += strlen(field); - eol = strchr(h, '\n'); - if (h[0] != ' ') { - buf = h; - continue; - } - if (!eol) - goto malformed; - - h++; /* skip the SP */ - - git_str_put(signature, h, eol - h); - if (git_str_oom(signature)) - goto oom; - - /* If the next line starts with SP, it's multi-line, we must continue */ - while (eol[1] == ' ') { - git_str_putc(signature, '\n'); - h = eol + 2; - eol = strchr(h, '\n'); - if (!eol) - goto malformed; - - git_str_put(signature, h, eol - h); - } - - if (git_str_oom(signature)) - goto oom; - - error = git_str_puts(signed_data, eol+1); - git_odb_object_free(obj); - return error; - } - - git_error_set(GIT_ERROR_OBJECT, "this commit is not signed"); - error = GIT_ENOTFOUND; - goto cleanup; - -malformed: - git_error_set(GIT_ERROR_OBJECT, "malformed header"); - error = -1; - goto cleanup; -oom: - git_error_set_oom(); - error = -1; - goto cleanup; - -cleanup: - git_odb_object_free(obj); - git_str_clear(signature); - git_str_clear(signed_data); - return error; -} - -int git_commit_create_buffer( - git_buf *out, - git_repository *repo, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - const git_commit *parents[]) -{ - GIT_BUF_WRAP_PRIVATE(out, git_commit__create_buffer, repo, - author, committer, message_encoding, message, - tree, parent_count, parents); -} - -int git_commit__create_buffer( - git_str *out, - git_repository *repo, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - const git_commit *parents[]) -{ - int error; - commit_parent_data data = { parent_count, parents, repo }; - git_array_oid_t parents_arr = GIT_ARRAY_INIT; - const git_oid *tree_id; - - GIT_ASSERT_ARG(tree); - GIT_ASSERT_ARG(git_tree_owner(tree) == repo); - - tree_id = git_tree_id(tree); - - if ((error = validate_tree_and_parents(&parents_arr, repo, tree_id, commit_parent_from_array, &data, NULL, true)) < 0) - return error; - - error = git_commit__create_buffer_internal( - out, author, committer, - message_encoding, message, tree_id, - &parents_arr); - - git_array_clear(parents_arr); - return error; -} - -/** - * Append to 'out' properly marking continuations when there's a newline in 'content' - */ -static int format_header_field(git_str *out, const char *field, const char *content) -{ - const char *lf; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(field); - GIT_ASSERT_ARG(content); - - git_str_puts(out, field); - git_str_putc(out, ' '); - - while ((lf = strchr(content, '\n')) != NULL) { - git_str_put(out, content, lf - content); - git_str_puts(out, "\n "); - content = lf + 1; - } - - git_str_puts(out, content); - git_str_putc(out, '\n'); - - return git_str_oom(out) ? -1 : 0; -} - -static const git_oid *commit_parent_from_commit(size_t n, void *payload) -{ - const git_commit *commit = (const git_commit *) payload; - - return git_array_get(commit->parent_ids, n); - -} - -int git_commit_create_with_signature( - git_oid *out, - git_repository *repo, - const char *commit_content, - const char *signature, - const char *signature_field) -{ - git_odb *odb; - int error = 0; - const char *field; - const char *header_end; - git_str commit = GIT_STR_INIT; - git_commit *parsed; - git_array_oid_t parents = GIT_ARRAY_INIT; - git_commit__parse_options parse_opts = {0}; - - parse_opts.oid_type = repo->oid_type; - - /* The first step is to verify that all the tree and parents exist */ - parsed = git__calloc(1, sizeof(git_commit)); - GIT_ERROR_CHECK_ALLOC(parsed); - if (commit_parse(parsed, commit_content, strlen(commit_content), &parse_opts) < 0) { - error = -1; - goto cleanup; - } - - if ((error = validate_tree_and_parents(&parents, repo, &parsed->tree_id, commit_parent_from_commit, parsed, NULL, true)) < 0) - goto cleanup; - - git_array_clear(parents); - - /* Then we start appending by identifying the end of the commit header */ - header_end = strstr(commit_content, "\n\n"); - if (!header_end) { - git_error_set(GIT_ERROR_INVALID, "malformed commit contents"); - error = -1; - goto cleanup; - } - - /* The header ends after the first LF */ - header_end++; - git_str_put(&commit, commit_content, header_end - commit_content); - - if (signature != NULL) { - field = signature_field ? signature_field : "gpgsig"; - - if ((error = format_header_field(&commit, field, signature)) < 0) - goto cleanup; - } - - git_str_puts(&commit, header_end); - - if (git_str_oom(&commit)) - return -1; - - if ((error = git_repository_odb__weakptr(&odb, repo)) < 0) - goto cleanup; - - if ((error = git_odb_write(out, odb, commit.ptr, commit.size, GIT_OBJECT_COMMIT)) < 0) - goto cleanup; - -cleanup: - git_commit__free(parsed); - git_str_dispose(&commit); - return error; -} - -int git_commit_create_from_stage( - git_oid *out, - git_repository *repo, - const char *message, - const git_commit_create_options *given_opts) -{ - git_commit_create_options opts = GIT_COMMIT_CREATE_OPTIONS_INIT; - git_signature *default_signature = NULL; - const git_signature *author, *committer; - git_index *index = NULL; - git_diff *diff = NULL; - git_oid tree_id; - git_tree *head_tree = NULL, *tree = NULL; - git_commitarray parents = { 0 }; - int error = -1; - - GIT_ASSERT_ARG(out && repo); - - if (given_opts) - memcpy(&opts, given_opts, sizeof(git_commit_create_options)); - - author = opts.author; - committer = opts.committer; - - if (!author || !committer) { - if (git_signature_default(&default_signature, repo) < 0) - goto done; - - if (!author) - author = default_signature; - - if (!committer) - committer = default_signature; - } - - if (git_repository_index(&index, repo) < 0) - goto done; - - if (!opts.allow_empty_commit) { - error = git_repository_head_tree(&head_tree, repo); - - if (error && error != GIT_EUNBORNBRANCH) - goto done; - - error = -1; - - if (git_diff_tree_to_index(&diff, repo, head_tree, index, NULL) < 0) - goto done; - - if (git_diff_num_deltas(diff) == 0) { - git_error_set(GIT_ERROR_REPOSITORY, - "no changes are staged for commit"); - error = GIT_EUNCHANGED; - goto done; - } - } - - if (git_index_write_tree(&tree_id, index) < 0 || - git_tree_lookup(&tree, repo, &tree_id) < 0 || - git_repository_commit_parents(&parents, repo) < 0) - goto done; - - error = git_commit_create(out, repo, "HEAD", author, committer, - opts.message_encoding, message, - tree, parents.count, - (const git_commit **)parents.commits); - -done: - git_commitarray_dispose(&parents); - git_signature_free(default_signature); - git_tree_free(tree); - git_tree_free(head_tree); - git_diff_free(diff); - git_index_free(index); - return error; -} - -int git_commit_committer_with_mailmap( - git_signature **out, const git_commit *commit, const git_mailmap *mailmap) -{ - return git_mailmap_resolve_signature(out, mailmap, commit->committer); -} - -int git_commit_author_with_mailmap( - git_signature **out, const git_commit *commit, const git_mailmap *mailmap) -{ - return git_mailmap_resolve_signature(out, mailmap, commit->author); -} - -void git_commitarray_dispose(git_commitarray *array) -{ - size_t i; - - if (array == NULL) - return; - - for (i = 0; i < array->count; i++) - git_commit_free(array->commits[i]); - - git__free((git_commit **)array->commits); - - memset(array, 0, sizeof(*array)); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/commit.h b/vendor/libgit2-sys/libgit2/src/libgit2/commit.h deleted file mode 100644 index c25fee3..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/commit.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_commit_h__ -#define INCLUDE_commit_h__ - -#include "common.h" - -#include "git2/commit.h" -#include "tree.h" -#include "repository.h" -#include "array.h" - -#include - -struct git_commit { - git_object object; - - git_array_t(git_oid) parent_ids; - git_oid tree_id; - - git_signature *author; - git_signature *committer; - - char *message_encoding; - char *raw_message; - char *raw_header; - - char *summary; - char *body; -}; - -typedef struct { - git_oid_t oid_type; - unsigned int flags; -} git_commit__parse_options; - -typedef enum { - /** Only parse parents and committer info */ - GIT_COMMIT_PARSE_QUICK = (1 << 0) -} git_commit__parse_flags; - -int git_commit__header_field( - git_str *out, - const git_commit *commit, - const char *field); - -int git_commit__extract_signature( - git_str *signature, - git_str *signed_data, - git_repository *repo, - git_oid *commit_id, - const char *field); - -int git_commit__create_buffer( - git_str *out, - git_repository *repo, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - size_t parent_count, - const git_commit *parents[]); - -int git_commit__parse( - void *commit, - git_odb_object *obj, - git_oid_t oid_type); - -int git_commit__parse_raw( - void *commit, - const char *data, - size_t size, - git_oid_t oid_type); - -int git_commit__parse_ext( - git_commit *commit, - git_odb_object *odb_obj, - git_commit__parse_options *parse_opts); - -void git_commit__free(void *commit); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/commit_graph.c b/vendor/libgit2-sys/libgit2/src/libgit2/commit_graph.c deleted file mode 100644 index a1d8174..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/commit_graph.c +++ /dev/null @@ -1,1319 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "commit_graph.h" - -#include "array.h" -#include "buf.h" -#include "filebuf.h" -#include "futils.h" -#include "hash.h" -#include "oidarray.h" -#include "pack.h" -#include "repository.h" -#include "revwalk.h" - -#define GIT_COMMIT_GRAPH_MISSING_PARENT 0x70000000 -#define GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX 0x3FFFFFFF -#define GIT_COMMIT_GRAPH_GENERATION_NUMBER_INFINITY 0xFFFFFFFF - -#define COMMIT_GRAPH_SIGNATURE 0x43475048 /* "CGPH" */ -#define COMMIT_GRAPH_VERSION 1 -#define COMMIT_GRAPH_OBJECT_ID_VERSION 1 - -struct git_commit_graph_header { - uint32_t signature; - uint8_t version; - uint8_t object_id_version; - uint8_t chunks; - uint8_t base_graph_files; -}; - -#define COMMIT_GRAPH_OID_FANOUT_ID 0x4f494446 /* "OIDF" */ -#define COMMIT_GRAPH_OID_LOOKUP_ID 0x4f49444c /* "OIDL" */ -#define COMMIT_GRAPH_COMMIT_DATA_ID 0x43444154 /* "CDAT" */ -#define COMMIT_GRAPH_EXTRA_EDGE_LIST_ID 0x45444745 /* "EDGE" */ -#define COMMIT_GRAPH_BLOOM_FILTER_INDEX_ID 0x42494458 /* "BIDX" */ -#define COMMIT_GRAPH_BLOOM_FILTER_DATA_ID 0x42444154 /* "BDAT" */ - -struct git_commit_graph_chunk { - off64_t offset; - size_t length; -}; - -typedef git_array_t(size_t) parent_index_array_t; - -struct packed_commit { - size_t index; - git_oid sha1; - git_oid tree_oid; - uint32_t generation; - git_time_t commit_time; - git_array_oid_t parents; - parent_index_array_t parent_indices; -}; - -static void packed_commit_free(struct packed_commit *p) -{ - if (!p) - return; - - git_array_clear(p->parents); - git_array_clear(p->parent_indices); - git__free(p); -} - -static struct packed_commit *packed_commit_new(git_commit *commit) -{ - unsigned int i, parentcount = git_commit_parentcount(commit); - struct packed_commit *p = git__calloc(1, sizeof(struct packed_commit)); - if (!p) - goto cleanup; - - git_array_init_to_size(p->parents, parentcount); - if (parentcount && !p->parents.ptr) - goto cleanup; - - if (git_oid_cpy(&p->sha1, git_commit_id(commit)) < 0) - goto cleanup; - if (git_oid_cpy(&p->tree_oid, git_commit_tree_id(commit)) < 0) - goto cleanup; - p->commit_time = git_commit_time(commit); - - for (i = 0; i < parentcount; ++i) { - git_oid *parent_id = git_array_alloc(p->parents); - if (!parent_id) - goto cleanup; - if (git_oid_cpy(parent_id, git_commit_parent_id(commit, i)) < 0) - goto cleanup; - } - - return p; - -cleanup: - packed_commit_free(p); - return NULL; -} - -typedef int (*commit_graph_write_cb)(const char *buf, size_t size, void *cb_data); - -static int commit_graph_error(const char *message) -{ - git_error_set(GIT_ERROR_ODB, "invalid commit-graph file - %s", message); - return -1; -} - -static int commit_graph_parse_oid_fanout( - git_commit_graph_file *file, - const unsigned char *data, - struct git_commit_graph_chunk *chunk_oid_fanout) -{ - uint32_t i, nr; - if (chunk_oid_fanout->offset == 0) - return commit_graph_error("missing OID Fanout chunk"); - if (chunk_oid_fanout->length == 0) - return commit_graph_error("empty OID Fanout chunk"); - if (chunk_oid_fanout->length != 256 * 4) - return commit_graph_error("OID Fanout chunk has wrong length"); - - file->oid_fanout = (const uint32_t *)(data + chunk_oid_fanout->offset); - nr = 0; - for (i = 0; i < 256; ++i) { - uint32_t n = ntohl(file->oid_fanout[i]); - if (n < nr) - return commit_graph_error("index is non-monotonic"); - nr = n; - } - file->num_commits = nr; - return 0; -} - -static int commit_graph_parse_oid_lookup( - git_commit_graph_file *file, - const unsigned char *data, - struct git_commit_graph_chunk *chunk_oid_lookup) -{ - uint32_t i; - unsigned char *oid, *prev_oid, zero_oid[GIT_OID_MAX_SIZE] = {0}; - size_t oid_size; - - oid_size = git_oid_size(file->oid_type); - - if (chunk_oid_lookup->offset == 0) - return commit_graph_error("missing OID Lookup chunk"); - if (chunk_oid_lookup->length == 0) - return commit_graph_error("empty OID Lookup chunk"); - if (chunk_oid_lookup->length != file->num_commits * oid_size) - return commit_graph_error("OID Lookup chunk has wrong length"); - - file->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset); - prev_oid = zero_oid; - for (i = 0; i < file->num_commits; ++i, oid += oid_size) { - if (git_oid_raw_cmp(prev_oid, oid, oid_size) >= 0) - return commit_graph_error("OID Lookup index is non-monotonic"); - prev_oid = oid; - } - - return 0; -} - -static int commit_graph_parse_commit_data( - git_commit_graph_file *file, - const unsigned char *data, - struct git_commit_graph_chunk *chunk_commit_data) -{ - size_t oid_size = git_oid_size(file->oid_type); - - if (chunk_commit_data->offset == 0) - return commit_graph_error("missing Commit Data chunk"); - if (chunk_commit_data->length == 0) - return commit_graph_error("empty Commit Data chunk"); - if (chunk_commit_data->length != file->num_commits * (oid_size + 16)) - return commit_graph_error("Commit Data chunk has wrong length"); - - file->commit_data = data + chunk_commit_data->offset; - - return 0; -} - -static int commit_graph_parse_extra_edge_list( - git_commit_graph_file *file, - const unsigned char *data, - struct git_commit_graph_chunk *chunk_extra_edge_list) -{ - if (chunk_extra_edge_list->length == 0) - return 0; - if (chunk_extra_edge_list->length % 4 != 0) - return commit_graph_error("malformed Extra Edge List chunk"); - - file->extra_edge_list = data + chunk_extra_edge_list->offset; - file->num_extra_edge_list = chunk_extra_edge_list->length / 4; - - return 0; -} - -int git_commit_graph_file_parse( - git_commit_graph_file *file, - const unsigned char *data, - size_t size) -{ - struct git_commit_graph_header *hdr; - const unsigned char *chunk_hdr; - struct git_commit_graph_chunk *last_chunk; - uint32_t i; - uint64_t last_chunk_offset, chunk_offset, trailer_offset; - size_t checksum_size; - int error; - struct git_commit_graph_chunk chunk_oid_fanout = {0}, chunk_oid_lookup = {0}, - chunk_commit_data = {0}, chunk_extra_edge_list = {0}, - chunk_unsupported = {0}; - - GIT_ASSERT_ARG(file); - - checksum_size = git_oid_size(file->oid_type); - - if (size < sizeof(struct git_commit_graph_header) + checksum_size) - return commit_graph_error("commit-graph is too short"); - - hdr = ((struct git_commit_graph_header *)data); - - if (hdr->signature != htonl(COMMIT_GRAPH_SIGNATURE) || hdr->version != COMMIT_GRAPH_VERSION - || hdr->object_id_version != COMMIT_GRAPH_OBJECT_ID_VERSION) { - return commit_graph_error("unsupported commit-graph version"); - } - if (hdr->chunks == 0) - return commit_graph_error("no chunks in commit-graph"); - - /* - * The very first chunk's offset should be after the header, all the chunk - * headers, and a special zero chunk. - */ - last_chunk_offset = sizeof(struct git_commit_graph_header) + (1 + hdr->chunks) * 12; - trailer_offset = size - checksum_size; - - if (trailer_offset < last_chunk_offset) - return commit_graph_error("wrong commit-graph size"); - memcpy(file->checksum, (data + trailer_offset), checksum_size); - - chunk_hdr = data + sizeof(struct git_commit_graph_header); - last_chunk = NULL; - for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) { - chunk_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32 - | ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 8)))); - if (chunk_offset < last_chunk_offset) - return commit_graph_error("chunks are non-monotonic"); - if (chunk_offset >= trailer_offset) - return commit_graph_error("chunks extend beyond the trailer"); - if (last_chunk != NULL) - last_chunk->length = (size_t)(chunk_offset - last_chunk_offset); - last_chunk_offset = chunk_offset; - - switch (ntohl(*((uint32_t *)(chunk_hdr + 0)))) { - case COMMIT_GRAPH_OID_FANOUT_ID: - chunk_oid_fanout.offset = last_chunk_offset; - last_chunk = &chunk_oid_fanout; - break; - - case COMMIT_GRAPH_OID_LOOKUP_ID: - chunk_oid_lookup.offset = last_chunk_offset; - last_chunk = &chunk_oid_lookup; - break; - - case COMMIT_GRAPH_COMMIT_DATA_ID: - chunk_commit_data.offset = last_chunk_offset; - last_chunk = &chunk_commit_data; - break; - - case COMMIT_GRAPH_EXTRA_EDGE_LIST_ID: - chunk_extra_edge_list.offset = last_chunk_offset; - last_chunk = &chunk_extra_edge_list; - break; - - case COMMIT_GRAPH_BLOOM_FILTER_INDEX_ID: - case COMMIT_GRAPH_BLOOM_FILTER_DATA_ID: - chunk_unsupported.offset = last_chunk_offset; - last_chunk = &chunk_unsupported; - break; - - default: - return commit_graph_error("unrecognized chunk ID"); - } - } - last_chunk->length = (size_t)(trailer_offset - last_chunk_offset); - - error = commit_graph_parse_oid_fanout(file, data, &chunk_oid_fanout); - if (error < 0) - return error; - error = commit_graph_parse_oid_lookup(file, data, &chunk_oid_lookup); - if (error < 0) - return error; - error = commit_graph_parse_commit_data(file, data, &chunk_commit_data); - if (error < 0) - return error; - error = commit_graph_parse_extra_edge_list(file, data, &chunk_extra_edge_list); - if (error < 0) - return error; - - return 0; -} - -int git_commit_graph_new( - git_commit_graph **cgraph_out, - const char *objects_dir, - bool open_file, - git_oid_t oid_type) -{ - git_commit_graph *cgraph = NULL; - int error = 0; - - GIT_ASSERT_ARG(cgraph_out); - GIT_ASSERT_ARG(objects_dir); - GIT_ASSERT_ARG(oid_type); - - cgraph = git__calloc(1, sizeof(git_commit_graph)); - GIT_ERROR_CHECK_ALLOC(cgraph); - - cgraph->oid_type = oid_type; - - error = git_str_joinpath(&cgraph->filename, objects_dir, "info/commit-graph"); - if (error < 0) - goto error; - - if (open_file) { - error = git_commit_graph_file_open(&cgraph->file, - git_str_cstr(&cgraph->filename), oid_type); - - if (error < 0) - goto error; - - cgraph->checked = 1; - } - - *cgraph_out = cgraph; - return 0; - -error: - git_commit_graph_free(cgraph); - return error; -} - -int git_commit_graph_validate(git_commit_graph *cgraph) { - unsigned char checksum[GIT_HASH_MAX_SIZE]; - git_hash_algorithm_t checksum_type; - size_t checksum_size, trailer_offset; - - checksum_type = git_oid_algorithm(cgraph->oid_type); - checksum_size = git_hash_size(checksum_type); - trailer_offset = cgraph->file->graph_map.len - checksum_size; - - if (cgraph->file->graph_map.len < checksum_size) - return commit_graph_error("map length too small"); - - if (git_hash_buf(checksum, cgraph->file->graph_map.data, trailer_offset, checksum_type) < 0) - return commit_graph_error("could not calculate signature"); - if (memcmp(checksum, cgraph->file->checksum, checksum_size) != 0) - return commit_graph_error("index signature mismatch"); - - return 0; -} - -int git_commit_graph_open( - git_commit_graph **cgraph_out, - const char *objects_dir -#ifdef GIT_EXPERIMENTAL_SHA256 - , const git_commit_graph_open_options *opts -#endif - ) -{ - git_oid_t oid_type; - int error; - -#ifdef GIT_EXPERIMENTAL_SHA256 - GIT_ERROR_CHECK_VERSION(opts, - GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION, - "git_commit_graph_open_options"); - - oid_type = opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT; - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); -#else - oid_type = GIT_OID_SHA1; -#endif - - error = git_commit_graph_new(cgraph_out, objects_dir, true, - oid_type); - - if (!error) - return git_commit_graph_validate(*cgraph_out); - - return error; -} - -int git_commit_graph_file_open( - git_commit_graph_file **file_out, - const char *path, - git_oid_t oid_type) -{ - git_commit_graph_file *file; - git_file fd = -1; - size_t cgraph_size; - struct stat st; - int error; - - /* TODO: properly open the file without access time using O_NOATIME */ - fd = git_futils_open_ro(path); - if (fd < 0) - return fd; - - if (p_fstat(fd, &st) < 0) { - p_close(fd); - git_error_set(GIT_ERROR_ODB, "commit-graph file not found - '%s'", path); - return GIT_ENOTFOUND; - } - - if (!S_ISREG(st.st_mode) || !git__is_sizet(st.st_size)) { - p_close(fd); - git_error_set(GIT_ERROR_ODB, "invalid pack index '%s'", path); - return GIT_ENOTFOUND; - } - cgraph_size = (size_t)st.st_size; - - file = git__calloc(1, sizeof(git_commit_graph_file)); - GIT_ERROR_CHECK_ALLOC(file); - - file->oid_type = oid_type; - - error = git_futils_mmap_ro(&file->graph_map, fd, 0, cgraph_size); - p_close(fd); - if (error < 0) { - git_commit_graph_file_free(file); - return error; - } - - if ((error = git_commit_graph_file_parse(file, file->graph_map.data, cgraph_size)) < 0) { - git_commit_graph_file_free(file); - return error; - } - - *file_out = file; - return 0; -} - -int git_commit_graph_get_file( - git_commit_graph_file **file_out, - git_commit_graph *cgraph) -{ - if (!cgraph->checked) { - int error = 0; - git_commit_graph_file *result = NULL; - - /* We only check once, no matter the result. */ - cgraph->checked = 1; - - /* Best effort */ - error = git_commit_graph_file_open(&result, - git_str_cstr(&cgraph->filename), cgraph->oid_type); - - if (error < 0) - return error; - - cgraph->file = result; - } - if (!cgraph->file) - return GIT_ENOTFOUND; - - *file_out = cgraph->file; - return 0; -} - -void git_commit_graph_refresh(git_commit_graph *cgraph) -{ - if (!cgraph->checked) - return; - - if (cgraph->file - && git_commit_graph_file_needs_refresh(cgraph->file, git_str_cstr(&cgraph->filename))) { - /* We just free the commit graph. The next time it is requested, it will be - * re-loaded. */ - git_commit_graph_file_free(cgraph->file); - cgraph->file = NULL; - } - /* Force a lazy re-check next time it is needed. */ - cgraph->checked = 0; -} - -static int git_commit_graph_entry_get_byindex( - git_commit_graph_entry *e, - const git_commit_graph_file *file, - size_t pos) -{ - const unsigned char *commit_data; - size_t oid_size = git_oid_size(file->oid_type); - - GIT_ASSERT_ARG(e); - GIT_ASSERT_ARG(file); - - if (pos >= file->num_commits) { - git_error_set(GIT_ERROR_INVALID, "commit index %zu does not exist", pos); - return GIT_ENOTFOUND; - } - - commit_data = file->commit_data + pos * (oid_size + 4 * sizeof(uint32_t)); - git_oid__fromraw(&e->tree_oid, commit_data, file->oid_type); - e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + oid_size))); - e->parent_indices[1] = ntohl( - *((uint32_t *)(commit_data + oid_size + sizeof(uint32_t)))); - e->parent_count = (e->parent_indices[0] != GIT_COMMIT_GRAPH_MISSING_PARENT) - + (e->parent_indices[1] != GIT_COMMIT_GRAPH_MISSING_PARENT); - e->generation = ntohl(*((uint32_t *)(commit_data + oid_size + 2 * sizeof(uint32_t)))); - e->commit_time = ntohl(*((uint32_t *)(commit_data + oid_size + 3 * sizeof(uint32_t)))); - - e->commit_time |= (e->generation & UINT64_C(0x3)) << UINT64_C(32); - e->generation >>= 2u; - if (e->parent_indices[1] & 0x80000000u) { - uint32_t extra_edge_list_pos = e->parent_indices[1] & 0x7fffffff; - - /* Make sure we're not being sent out of bounds */ - if (extra_edge_list_pos >= file->num_extra_edge_list) { - git_error_set(GIT_ERROR_INVALID, - "commit %u does not exist", - extra_edge_list_pos); - return GIT_ENOTFOUND; - } - - e->extra_parents_index = extra_edge_list_pos; - while (extra_edge_list_pos < file->num_extra_edge_list - && (ntohl(*( - (uint32_t *)(file->extra_edge_list - + extra_edge_list_pos * sizeof(uint32_t)))) - & 0x80000000u) - == 0) { - extra_edge_list_pos++; - e->parent_count++; - } - } - - git_oid__fromraw(&e->sha1, &file->oid_lookup[pos * oid_size], file->oid_type); - return 0; -} - -bool git_commit_graph_file_needs_refresh(const git_commit_graph_file *file, const char *path) -{ - git_file fd = -1; - struct stat st; - ssize_t bytes_read; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - size_t checksum_size = git_oid_size(file->oid_type); - - /* TODO: properly open the file without access time using O_NOATIME */ - fd = git_futils_open_ro(path); - if (fd < 0) - return true; - - if (p_fstat(fd, &st) < 0) { - p_close(fd); - return true; - } - - if (!S_ISREG(st.st_mode) || !git__is_sizet(st.st_size) - || (size_t)st.st_size != file->graph_map.len) { - p_close(fd); - return true; - } - - bytes_read = p_pread(fd, checksum, checksum_size, st.st_size - checksum_size); - p_close(fd); - if (bytes_read != (ssize_t)checksum_size) - return true; - - return (memcmp(checksum, file->checksum, checksum_size) != 0); -} - -int git_commit_graph_entry_find( - git_commit_graph_entry *e, - const git_commit_graph_file *file, - const git_oid *short_oid, - size_t len) -{ - int pos, found = 0; - uint32_t hi, lo; - const unsigned char *current = NULL; - size_t oid_size, oid_hexsize; - - GIT_ASSERT_ARG(e); - GIT_ASSERT_ARG(file); - GIT_ASSERT_ARG(short_oid); - - oid_size = git_oid_size(file->oid_type); - oid_hexsize = git_oid_hexsize(file->oid_type); - - hi = ntohl(file->oid_fanout[(int)short_oid->id[0]]); - lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(file->oid_fanout[(int)short_oid->id[0] - 1])); - - pos = git_pack__lookup_id(file->oid_lookup, oid_size, lo, hi, - short_oid->id, file->oid_type); - - if (pos >= 0) { - /* An object matching exactly the oid was found */ - found = 1; - current = file->oid_lookup + (pos * oid_size); - } else { - /* No object was found */ - /* pos refers to the object with the "closest" oid to short_oid */ - pos = -1 - pos; - if (pos < (int)file->num_commits) { - current = file->oid_lookup + (pos * oid_size); - - if (!git_oid_raw_ncmp(short_oid->id, current, len)) - found = 1; - } - } - - if (found && len != oid_hexsize && pos + 1 < (int)file->num_commits) { - /* Check for ambiguousity */ - const unsigned char *next = current + oid_size; - - if (!git_oid_raw_ncmp(short_oid->id, next, len)) - found = 2; - } - - if (!found) - return git_odb__error_notfound( - "failed to find offset for commit-graph index entry", short_oid, len); - if (found > 1) - return git_odb__error_ambiguous( - "found multiple offsets for commit-graph index entry"); - - return git_commit_graph_entry_get_byindex(e, file, pos); -} - -int git_commit_graph_entry_parent( - git_commit_graph_entry *parent, - const git_commit_graph_file *file, - const git_commit_graph_entry *entry, - size_t n) -{ - GIT_ASSERT_ARG(parent); - GIT_ASSERT_ARG(file); - - if (n >= entry->parent_count) { - git_error_set(GIT_ERROR_INVALID, "parent index %zu does not exist", n); - return GIT_ENOTFOUND; - } - - if (n == 0 || (n == 1 && entry->parent_count == 2)) - return git_commit_graph_entry_get_byindex(parent, file, entry->parent_indices[n]); - - return git_commit_graph_entry_get_byindex( - parent, - file, - ntohl( - *(uint32_t *)(file->extra_edge_list - + (entry->extra_parents_index + n - 1) - * sizeof(uint32_t))) - & 0x7fffffff); -} - -int git_commit_graph_file_close(git_commit_graph_file *file) -{ - GIT_ASSERT_ARG(file); - - if (file->graph_map.data) - git_futils_mmap_free(&file->graph_map); - - return 0; -} - -void git_commit_graph_free(git_commit_graph *cgraph) -{ - if (!cgraph) - return; - - git_str_dispose(&cgraph->filename); - git_commit_graph_file_free(cgraph->file); - git__free(cgraph); -} - -void git_commit_graph_file_free(git_commit_graph_file *file) -{ - if (!file) - return; - - git_commit_graph_file_close(file); - git__free(file); -} - -static int packed_commit__cmp(const void *a_, const void *b_) -{ - const struct packed_commit *a = a_; - const struct packed_commit *b = b_; - return git_oid_cmp(&a->sha1, &b->sha1); -} - -int git_commit_graph_writer_options_init( - git_commit_graph_writer_options *opts, - unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, - version, - git_commit_graph_writer_options, - GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT); - return 0; -} - -int git_commit_graph_writer_new( - git_commit_graph_writer **out, - const char *objects_info_dir, - const git_commit_graph_writer_options *opts - ) -{ - git_commit_graph_writer *w; - git_oid_t oid_type; - -#ifdef GIT_EXPERIMENTAL_SHA256 - GIT_ERROR_CHECK_VERSION(opts, - GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION, - "git_commit_graph_writer_options"); - - oid_type = opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT; - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); -#else - GIT_UNUSED(opts); - oid_type = GIT_OID_SHA1; -#endif - - GIT_ASSERT_ARG(out && objects_info_dir); - - w = git__calloc(1, sizeof(git_commit_graph_writer)); - GIT_ERROR_CHECK_ALLOC(w); - - w->oid_type = oid_type; - - if (git_str_sets(&w->objects_info_dir, objects_info_dir) < 0) { - git__free(w); - return -1; - } - - if (git_vector_init(&w->commits, 0, packed_commit__cmp) < 0) { - git_str_dispose(&w->objects_info_dir); - git__free(w); - return -1; - } - - *out = w; - return 0; -} - -void git_commit_graph_writer_free(git_commit_graph_writer *w) -{ - struct packed_commit *packed_commit; - size_t i; - - if (!w) - return; - - git_vector_foreach (&w->commits, i, packed_commit) - packed_commit_free(packed_commit); - git_vector_dispose(&w->commits); - git_str_dispose(&w->objects_info_dir); - git__free(w); -} - -struct object_entry_cb_state { - git_repository *repo; - git_odb *db; - git_vector *commits; -}; - -static int object_entry__cb(const git_oid *id, void *data) -{ - struct object_entry_cb_state *state = (struct object_entry_cb_state *)data; - git_commit *commit = NULL; - struct packed_commit *packed_commit = NULL; - size_t header_len; - git_object_t header_type; - int error = 0; - - error = git_odb_read_header(&header_len, &header_type, state->db, id); - if (error < 0) - return error; - - if (header_type != GIT_OBJECT_COMMIT) - return 0; - - error = git_commit_lookup(&commit, state->repo, id); - if (error < 0) - return error; - - packed_commit = packed_commit_new(commit); - git_commit_free(commit); - GIT_ERROR_CHECK_ALLOC(packed_commit); - - error = git_vector_insert(state->commits, packed_commit); - if (error < 0) { - packed_commit_free(packed_commit); - return error; - } - - return 0; -} - -int git_commit_graph_writer_add_index_file( - git_commit_graph_writer *w, - git_repository *repo, - const char *idx_path) -{ - int error; - struct git_pack_file *p = NULL; - struct object_entry_cb_state state = {0}; - state.repo = repo; - state.commits = &w->commits; - - error = git_repository_odb(&state.db, repo); - if (error < 0) - goto cleanup; - - error = git_mwindow_get_pack(&p, idx_path, repo->oid_type); - if (error < 0) - goto cleanup; - - error = git_pack_foreach_entry(p, object_entry__cb, &state); - if (error < 0) - goto cleanup; - -cleanup: - if (p) - git_mwindow_put_pack(p); - git_odb_free(state.db); - return error; -} - -int git_commit_graph_writer_add_revwalk(git_commit_graph_writer *w, git_revwalk *walk) -{ - int error; - git_oid id; - git_repository *repo = git_revwalk_repository(walk); - git_commit *commit; - struct packed_commit *packed_commit; - - while ((git_revwalk_next(&id, walk)) == 0) { - error = git_commit_lookup(&commit, repo, &id); - if (error < 0) - return error; - - packed_commit = packed_commit_new(commit); - git_commit_free(commit); - GIT_ERROR_CHECK_ALLOC(packed_commit); - - error = git_vector_insert(&w->commits, packed_commit); - if (error < 0) { - packed_commit_free(packed_commit); - return error; - } - } - - return 0; -} - -enum generation_number_commit_state { - GENERATION_NUMBER_COMMIT_STATE_UNVISITED = 0, - GENERATION_NUMBER_COMMIT_STATE_ADDED = 1, - GENERATION_NUMBER_COMMIT_STATE_EXPANDED = 2, - GENERATION_NUMBER_COMMIT_STATE_VISITED = 3 -}; - -GIT_HASHMAP_OID_SETUP(git_commit_graph_oidmap, struct packed_commit *); - -static int compute_generation_numbers(git_vector *commits) -{ - git_array_t(size_t) index_stack = GIT_ARRAY_INIT; - size_t i, j; - size_t *parent_idx; - enum generation_number_commit_state *commit_states = NULL; - struct packed_commit *child_packed_commit; - git_commit_graph_oidmap packed_commit_map = GIT_HASHMAP_INIT; - int error = 0; - - /* First populate the parent indices fields */ - git_vector_foreach (commits, i, child_packed_commit) { - child_packed_commit->index = i; - error = git_commit_graph_oidmap_put(&packed_commit_map, - &child_packed_commit->sha1, child_packed_commit); - if (error < 0) - goto cleanup; - } - - git_vector_foreach (commits, i, child_packed_commit) { - size_t parent_i, *parent_idx_ptr; - struct packed_commit *parent_packed_commit; - git_oid *parent_id; - git_array_init_to_size( - child_packed_commit->parent_indices, - git_array_size(child_packed_commit->parents)); - if (git_array_size(child_packed_commit->parents) - && !child_packed_commit->parent_indices.ptr) { - error = -1; - goto cleanup; - } - git_array_foreach (child_packed_commit->parents, parent_i, parent_id) { - if (git_commit_graph_oidmap_get(&parent_packed_commit, &packed_commit_map, parent_id) != 0) { - git_error_set(GIT_ERROR_ODB, - "parent commit %s not found in commit graph", - git_oid_tostr_s(parent_id)); - error = GIT_ENOTFOUND; - goto cleanup; - } - parent_idx_ptr = git_array_alloc(child_packed_commit->parent_indices); - if (!parent_idx_ptr) { - error = -1; - goto cleanup; - } - *parent_idx_ptr = parent_packed_commit->index; - } - } - - /* - * We copy all the commits to the stack and then during visitation, - * each node can be added up to two times to the stack. - */ - git_array_init_to_size(index_stack, 3 * git_vector_length(commits)); - if (!index_stack.ptr) { - error = -1; - goto cleanup; - } - - commit_states = (enum generation_number_commit_state *)git__calloc( - git_vector_length(commits), sizeof(enum generation_number_commit_state)); - if (!commit_states) { - error = -1; - goto cleanup; - } - - /* - * Perform a Post-Order traversal so that all parent nodes are fully - * visited before the child node. - */ - git_vector_foreach (commits, i, child_packed_commit) - *(size_t *)git_array_alloc(index_stack) = i; - - while (git_array_size(index_stack)) { - size_t *index_ptr = git_array_pop(index_stack); - i = *index_ptr; - child_packed_commit = git_vector_get(commits, i); - - if (commit_states[i] == GENERATION_NUMBER_COMMIT_STATE_VISITED) { - /* This commit has already been fully visited. */ - continue; - } - if (commit_states[i] == GENERATION_NUMBER_COMMIT_STATE_EXPANDED) { - /* All of the commits parents have been visited. */ - child_packed_commit->generation = 0; - git_array_foreach (child_packed_commit->parent_indices, j, parent_idx) { - struct packed_commit *parent = git_vector_get(commits, *parent_idx); - if (child_packed_commit->generation < parent->generation) - child_packed_commit->generation = parent->generation; - } - if (child_packed_commit->generation - < GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX) { - ++child_packed_commit->generation; - } - commit_states[i] = GENERATION_NUMBER_COMMIT_STATE_VISITED; - continue; - } - - /* - * This is the first time we see this commit. We need - * to visit all its parents before we can fully visit - * it. - */ - if (git_array_size(child_packed_commit->parent_indices) == 0) { - /* - * Special case: if the commit has no parents, there's - * no need to add it to the stack just to immediately - * remove it. - */ - commit_states[i] = GENERATION_NUMBER_COMMIT_STATE_VISITED; - child_packed_commit->generation = 1; - continue; - } - - /* - * Add this current commit again so that it is visited - * again once all its children have been visited. - */ - *(size_t *)git_array_alloc(index_stack) = i; - git_array_foreach (child_packed_commit->parent_indices, j, parent_idx) { - if (commit_states[*parent_idx] - != GENERATION_NUMBER_COMMIT_STATE_UNVISITED) { - /* This commit has already been considered. */ - continue; - } - - commit_states[*parent_idx] = GENERATION_NUMBER_COMMIT_STATE_ADDED; - *(size_t *)git_array_alloc(index_stack) = *parent_idx; - } - commit_states[i] = GENERATION_NUMBER_COMMIT_STATE_EXPANDED; - } - -cleanup: - git_commit_graph_oidmap_dispose(&packed_commit_map); - git__free(commit_states); - git_array_clear(index_stack); - - return error; -} - -static int write_offset(off64_t offset, commit_graph_write_cb write_cb, void *cb_data) -{ - int error; - uint32_t word; - - word = htonl((uint32_t)((offset >> 32) & 0xffffffffu)); - error = write_cb((const char *)&word, sizeof(word), cb_data); - if (error < 0) - return error; - word = htonl((uint32_t)((offset >> 0) & 0xffffffffu)); - error = write_cb((const char *)&word, sizeof(word), cb_data); - if (error < 0) - return error; - - return 0; -} - -static int write_chunk_header( - int chunk_id, - off64_t offset, - commit_graph_write_cb write_cb, - void *cb_data) -{ - uint32_t word = htonl(chunk_id); - int error = write_cb((const char *)&word, sizeof(word), cb_data); - if (error < 0) - return error; - return write_offset(offset, write_cb, cb_data); -} - -static int commit_graph_write_buf(const char *buf, size_t size, void *data) -{ - git_str *b = (git_str *)data; - return git_str_put(b, buf, size); -} - -struct commit_graph_write_hash_context { - commit_graph_write_cb write_cb; - void *cb_data; - git_hash_ctx *ctx; -}; - -static int commit_graph_write_hash(const char *buf, size_t size, void *data) -{ - struct commit_graph_write_hash_context *ctx = data; - int error; - - if (ctx->ctx) { - error = git_hash_update(ctx->ctx, buf, size); - - if (error < 0) - return error; - } - - return ctx->write_cb(buf, size, ctx->cb_data); -} - -static void packed_commit_free_dup(void *packed_commit) -{ - packed_commit_free(packed_commit); -} - -static int commit_graph_write( - git_commit_graph_writer *w, - commit_graph_write_cb write_cb, - void *cb_data) -{ - int error = 0; - size_t i; - struct packed_commit *packed_commit; - struct git_commit_graph_header hdr = {0}; - uint32_t oid_fanout_count; - uint32_t extra_edge_list_count; - uint32_t oid_fanout[256]; - off64_t offset; - git_str oid_lookup = GIT_STR_INIT, commit_data = GIT_STR_INIT, - extra_edge_list = GIT_STR_INIT; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - git_hash_algorithm_t checksum_type; - size_t checksum_size, oid_size; - git_hash_ctx ctx; - struct commit_graph_write_hash_context hash_cb_data = {0}; - - hdr.signature = htonl(COMMIT_GRAPH_SIGNATURE); - hdr.version = COMMIT_GRAPH_VERSION; - hdr.object_id_version = COMMIT_GRAPH_OBJECT_ID_VERSION; - hdr.chunks = 0; - hdr.base_graph_files = 0; - hash_cb_data.write_cb = write_cb; - hash_cb_data.cb_data = cb_data; - hash_cb_data.ctx = &ctx; - - oid_size = git_oid_size(w->oid_type); - checksum_type = git_oid_algorithm(w->oid_type); - checksum_size = git_hash_size(checksum_type); - - error = git_hash_ctx_init(&ctx, checksum_type); - if (error < 0) - return error; - cb_data = &hash_cb_data; - write_cb = commit_graph_write_hash; - - /* Sort the commits. */ - git_vector_sort(&w->commits); - git_vector_uniq(&w->commits, packed_commit_free_dup); - error = compute_generation_numbers(&w->commits); - if (error < 0) - goto cleanup; - - /* Fill the OID Fanout table. */ - oid_fanout_count = 0; - for (i = 0; i < 256; i++) { - while (oid_fanout_count < git_vector_length(&w->commits) && - (packed_commit = (struct packed_commit *)git_vector_get(&w->commits, oid_fanout_count)) && - packed_commit->sha1.id[0] <= i) - ++oid_fanout_count; - oid_fanout[i] = htonl(oid_fanout_count); - } - - /* Fill the OID Lookup table. */ - git_vector_foreach (&w->commits, i, packed_commit) { - error = git_str_put(&oid_lookup, - (const char *)&packed_commit->sha1.id, - oid_size); - - if (error < 0) - goto cleanup; - } - - /* Fill the Commit Data and Extra Edge List tables. */ - extra_edge_list_count = 0; - git_vector_foreach (&w->commits, i, packed_commit) { - uint64_t commit_time; - uint32_t generation; - uint32_t word; - size_t *packed_index; - unsigned int parentcount = (unsigned int)git_array_size(packed_commit->parents); - - error = git_str_put(&commit_data, - (const char *)&packed_commit->tree_oid.id, - oid_size); - - if (error < 0) - goto cleanup; - - if (parentcount == 0) { - word = htonl(GIT_COMMIT_GRAPH_MISSING_PARENT); - } else { - packed_index = git_array_get(packed_commit->parent_indices, 0); - word = htonl((uint32_t)*packed_index); - } - error = git_str_put(&commit_data, (const char *)&word, sizeof(word)); - if (error < 0) - goto cleanup; - - if (parentcount < 2) { - word = htonl(GIT_COMMIT_GRAPH_MISSING_PARENT); - } else if (parentcount == 2) { - packed_index = git_array_get(packed_commit->parent_indices, 1); - word = htonl((uint32_t)*packed_index); - } else { - word = htonl(0x80000000u | extra_edge_list_count); - } - error = git_str_put(&commit_data, (const char *)&word, sizeof(word)); - if (error < 0) - goto cleanup; - - if (parentcount > 2) { - unsigned int parent_i; - for (parent_i = 1; parent_i < parentcount; ++parent_i) { - packed_index = git_array_get( - packed_commit->parent_indices, parent_i); - word = htonl((uint32_t)(*packed_index | (parent_i + 1 == parentcount ? 0x80000000u : 0))); - - error = git_str_put(&extra_edge_list, - (const char *)&word, - sizeof(word)); - if (error < 0) - goto cleanup; - } - extra_edge_list_count += parentcount - 1; - } - - generation = packed_commit->generation; - commit_time = (uint64_t)packed_commit->commit_time; - if (generation > GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX) - generation = GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX; - word = ntohl((uint32_t)((generation << 2) | (((uint32_t)(commit_time >> 32)) & 0x3) )); - error = git_str_put(&commit_data, (const char *)&word, sizeof(word)); - if (error < 0) - goto cleanup; - word = ntohl((uint32_t)(commit_time & 0xfffffffful)); - error = git_str_put(&commit_data, (const char *)&word, sizeof(word)); - if (error < 0) - goto cleanup; - } - - /* Write the header. */ - hdr.chunks = 3; - if (git_str_len(&extra_edge_list) > 0) - hdr.chunks++; - error = write_cb((const char *)&hdr, sizeof(hdr), cb_data); - if (error < 0) - goto cleanup; - - /* Write the chunk headers. */ - offset = sizeof(hdr) + (hdr.chunks + 1) * 12; - error = write_chunk_header(COMMIT_GRAPH_OID_FANOUT_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += sizeof(oid_fanout); - error = write_chunk_header(COMMIT_GRAPH_OID_LOOKUP_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += git_str_len(&oid_lookup); - error = write_chunk_header(COMMIT_GRAPH_COMMIT_DATA_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += git_str_len(&commit_data); - if (git_str_len(&extra_edge_list) > 0) { - error = write_chunk_header( - COMMIT_GRAPH_EXTRA_EDGE_LIST_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += git_str_len(&extra_edge_list); - } - error = write_chunk_header(0, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - - /* Write all the chunks. */ - error = write_cb((const char *)oid_fanout, sizeof(oid_fanout), cb_data); - if (error < 0) - goto cleanup; - error = write_cb(git_str_cstr(&oid_lookup), git_str_len(&oid_lookup), cb_data); - if (error < 0) - goto cleanup; - error = write_cb(git_str_cstr(&commit_data), git_str_len(&commit_data), cb_data); - if (error < 0) - goto cleanup; - error = write_cb(git_str_cstr(&extra_edge_list), git_str_len(&extra_edge_list), cb_data); - if (error < 0) - goto cleanup; - - /* Finalize the checksum and write the trailer. */ - error = git_hash_final(checksum, &ctx); - if (error < 0) - goto cleanup; - - hash_cb_data.ctx = NULL; - - error = write_cb((char *)checksum, checksum_size, cb_data); - if (error < 0) - goto cleanup; - -cleanup: - git_str_dispose(&oid_lookup); - git_str_dispose(&commit_data); - git_str_dispose(&extra_edge_list); - git_hash_ctx_cleanup(&ctx); - return error; -} - -static int commit_graph_write_filebuf(const char *buf, size_t size, void *data) -{ - git_filebuf *f = (git_filebuf *)data; - return git_filebuf_write(f, buf, size); -} - -int git_commit_graph_writer_commit(git_commit_graph_writer *w) -{ - int error; - int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER; - git_str commit_graph_path = GIT_STR_INIT; - git_filebuf output = GIT_FILEBUF_INIT; - - error = git_str_joinpath( - &commit_graph_path, git_str_cstr(&w->objects_info_dir), "commit-graph"); - if (error < 0) - return error; - - if (git_repository__fsync_gitdir) - filebuf_flags |= GIT_FILEBUF_FSYNC; - error = git_filebuf_open(&output, git_str_cstr(&commit_graph_path), filebuf_flags, 0644); - git_str_dispose(&commit_graph_path); - if (error < 0) - return error; - - error = commit_graph_write(w, commit_graph_write_filebuf, &output); - if (error < 0) { - git_filebuf_cleanup(&output); - return error; - } - - return git_filebuf_commit(&output); -} - -int git_commit_graph_writer_dump( - git_buf *cgraph, - git_commit_graph_writer *w) -{ - GIT_BUF_WRAP_PRIVATE(cgraph, git_commit_graph__writer_dump, w); -} - -int git_commit_graph__writer_dump( - git_str *cgraph, - git_commit_graph_writer *w) -{ - return commit_graph_write(w, commit_graph_write_buf, cgraph); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/commit_graph.h b/vendor/libgit2-sys/libgit2/src/libgit2/commit_graph.h deleted file mode 100644 index a06f3f8..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/commit_graph.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_commit_graph_h__ -#define INCLUDE_commit_graph_h__ - -#include "common.h" - -#include "git2/types.h" -#include "git2/sys/commit_graph.h" - -#include "map.h" -#include "vector.h" -#include "oid.h" -#include "hash.h" - -/** - * A commit-graph file. - * - * This file contains metadata about commits, particularly the generation - * number for each one. This can help speed up graph operations without - * requiring a full graph traversal. - * - * Support for this feature was added in git 2.19. - */ -typedef struct git_commit_graph_file { - git_map graph_map; - - /* The type of object IDs in the commit graph file. */ - git_oid_t oid_type; - - /* The OID Fanout table. */ - const uint32_t *oid_fanout; - /* The total number of commits in the graph. */ - uint32_t num_commits; - - /* The OID Lookup table. */ - unsigned char *oid_lookup; - - /* - * The Commit Data table. Each entry contains the OID of the commit followed - * by two 8-byte fields in network byte order: - * - The indices of the first two parents (32 bits each). - * - The generation number (first 30 bits) and commit time in seconds since - * UNIX epoch (34 bits). - */ - const unsigned char *commit_data; - - /* - * The Extra Edge List table. Each 4-byte entry is a network byte order index - * of one of the i-th (i > 0) parents of commits in the `commit_data` table, - * when the commit has more than 2 parents. - */ - const unsigned char *extra_edge_list; - /* The number of entries in the Extra Edge List table. Each entry is 4 bytes wide. */ - size_t num_extra_edge_list; - - /* The trailer of the file. Contains the SHA1-checksum of the whole file. */ - unsigned char checksum[GIT_HASH_SHA1_SIZE]; -} git_commit_graph_file; - -/** - * An entry in the commit-graph file. Provides a subset of the information that - * can be obtained from the commit header. - */ -typedef struct git_commit_graph_entry { - /* The generation number of the commit within the graph */ - size_t generation; - - /* Time in seconds from UNIX epoch. */ - git_time_t commit_time; - - /* The number of parents of the commit. */ - size_t parent_count; - - /* - * The indices of the parent commits within the Commit Data table. The value - * of `GIT_COMMIT_GRAPH_MISSING_PARENT` indicates that no parent is in that - * position. - */ - size_t parent_indices[2]; - - /* The index within the Extra Edge List of any parent after the first two. */ - size_t extra_parents_index; - - /* The object ID of the root tree of the commit. */ - git_oid tree_oid; - - /* The object ID hash of the requested commit. */ - git_oid sha1; -} git_commit_graph_entry; - -/* A wrapper for git_commit_graph_file to enable lazy loading in the ODB. */ -struct git_commit_graph { - /* The path to the commit-graph file. Something like ".git/objects/info/commit-graph". */ - git_str filename; - - /* The underlying commit-graph file. */ - git_commit_graph_file *file; - - /* The object ID types in the commit graph. */ - git_oid_t oid_type; - - /* Whether the commit-graph file was already checked for validity. */ - bool checked; -}; - -/** Create a new commit-graph, optionally opening the underlying file. */ -int git_commit_graph_new( - git_commit_graph **cgraph_out, - const char *objects_dir, - bool open_file, - git_oid_t oid_type); - -/** Validate the checksum of a commit graph */ -int git_commit_graph_validate(git_commit_graph *cgraph); - -/** Open and validate a commit-graph file. */ -int git_commit_graph_file_open( - git_commit_graph_file **file_out, - const char *path, - git_oid_t oid_type); - -/* - * Attempt to get the git_commit_graph's commit-graph file. This object is - * still owned by the git_commit_graph. If the repository does not contain a commit graph, - * it will return GIT_ENOTFOUND. - * - * This function is not thread-safe. - */ -int git_commit_graph_get_file(git_commit_graph_file **file_out, git_commit_graph *cgraph); - -/* Marks the commit-graph file as needing a refresh. */ -void git_commit_graph_refresh(git_commit_graph *cgraph); - -/* - * A writer for `commit-graph` files. - */ -struct git_commit_graph_writer { - /* - * The path of the `objects/info` directory where the `commit-graph` will be - * stored. - */ - git_str objects_info_dir; - - /* The object ID type of the commit graph. */ - git_oid_t oid_type; - - /* The list of packed commits. */ - git_vector commits; -}; - -int git_commit_graph__writer_dump( - git_str *cgraph, - git_commit_graph_writer *w); - -/* - * Returns whether the git_commit_graph_file needs to be reloaded since the - * contents of the commit-graph file have changed on disk. - */ -bool git_commit_graph_file_needs_refresh( - const git_commit_graph_file *file, const char *path); - -int git_commit_graph_entry_find( - git_commit_graph_entry *e, - const git_commit_graph_file *file, - const git_oid *short_oid, - size_t len); -int git_commit_graph_entry_parent( - git_commit_graph_entry *parent, - const git_commit_graph_file *file, - const git_commit_graph_entry *entry, - size_t n); -int git_commit_graph_file_close(git_commit_graph_file *cgraph); -void git_commit_graph_file_free(git_commit_graph_file *cgraph); - -/* This is exposed for use in the fuzzers. */ -int git_commit_graph_file_parse( - git_commit_graph_file *file, - const unsigned char *data, - size_t size); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/commit_list.c b/vendor/libgit2-sys/libgit2/src/libgit2/commit_list.c deleted file mode 100644 index 7f00c48..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/commit_list.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "commit_list.h" - -#include "revwalk.h" -#include "pool.h" -#include "odb.h" -#include "commit.h" - -int git_commit_list_generation_cmp(const void *a, const void *b) -{ - uint32_t generation_a = ((git_commit_list_node *) a)->generation; - uint32_t generation_b = ((git_commit_list_node *) b)->generation; - - if (!generation_a || !generation_b) { - /* Fall back to comparing by timestamps if at least one commit lacks a generation. */ - return git_commit_list_time_cmp(a, b); - } - - if (generation_a < generation_b) - return 1; - if (generation_a > generation_b) - return -1; - - return 0; -} - -int git_commit_list_time_cmp(const void *a, const void *b) -{ - int64_t time_a = ((git_commit_list_node *) a)->time; - int64_t time_b = ((git_commit_list_node *) b)->time; - - if (time_a < time_b) - return 1; - if (time_a > time_b) - return -1; - - return 0; -} - -git_commit_list *git_commit_list_create(git_commit_list_node *item, git_commit_list *next) { - git_commit_list *new_list = git__malloc(sizeof(git_commit_list)); - if (new_list != NULL) { - new_list->item = item; - new_list->next = next; - } - return new_list; -} - -git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p) -{ - git_commit_list *new_list = git_commit_list_create(item, *list_p); - *list_p = new_list; - return new_list; -} - -git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p) -{ - git_commit_list **pp = list_p; - git_commit_list *p; - - while ((p = *pp) != NULL) { - if (git_commit_list_time_cmp(p->item, item) > 0) - break; - - pp = &p->next; - } - - return git_commit_list_insert(item, pp); -} - -git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk) -{ - return (git_commit_list_node *)git_pool_mallocz(&walk->commit_pool, 1); -} - -static git_commit_list_node **alloc_parents( - git_revwalk *walk, git_commit_list_node *commit, size_t n_parents) -{ - size_t bytes; - - if (n_parents <= PARENTS_PER_COMMIT) - return (git_commit_list_node **)((char *)commit + sizeof(git_commit_list_node)); - - if (git__multiply_sizet_overflow(&bytes, n_parents, sizeof(git_commit_list_node *))) - return NULL; - - return (git_commit_list_node **)git_pool_malloc(&walk->commit_pool, bytes); -} - - -void git_commit_list_free(git_commit_list **list_p) -{ - git_commit_list *list = *list_p; - - if (list == NULL) - return; - - while (list) { - git_commit_list *temp = list; - list = temp->next; - git__free(temp); - } - - *list_p = NULL; -} - -git_commit_list_node *git_commit_list_pop(git_commit_list **stack) -{ - git_commit_list *top = *stack; - git_commit_list_node *item = top ? top->item : NULL; - - if (top) { - *stack = top->next; - git__free(top); - } - return item; -} - -static int commit_quick_parse( - git_revwalk *walk, - git_commit_list_node *node, - git_odb_object *obj) -{ - git_oid *parent_oid; - git_commit *commit; - git_commit__parse_options parse_opts = { - walk->repo->oid_type, - GIT_COMMIT_PARSE_QUICK - }; - size_t i; - - commit = git__calloc(1, sizeof(*commit)); - GIT_ERROR_CHECK_ALLOC(commit); - commit->object.repo = walk->repo; - - if (git_commit__parse_ext(commit, obj, &parse_opts) < 0) { - git__free(commit); - return -1; - } - - if (!git__is_uint16(git_array_size(commit->parent_ids))) { - git__free(commit); - git_error_set(GIT_ERROR_INVALID, "commit has more than 2^16 parents"); - return -1; - } - - node->generation = 0; - node->time = commit->committer->when.time; - node->out_degree = (uint16_t) git_array_size(commit->parent_ids); - node->parents = alloc_parents(walk, node, node->out_degree); - GIT_ERROR_CHECK_ALLOC(node->parents); - - git_array_foreach(commit->parent_ids, i, parent_oid) { - node->parents[i] = git_revwalk__commit_lookup(walk, parent_oid); - } - - git_commit__free(commit); - - node->parsed = 1; - - return 0; -} - -int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit) -{ - git_odb_object *obj; - git_commit_graph_file *cgraph_file = NULL; - int error; - - if (commit->parsed) - return 0; - - /* Let's try to use the commit graph first. */ - git_odb__get_commit_graph_file(&cgraph_file, walk->odb); - if (cgraph_file) { - git_commit_graph_entry e; - - error = git_commit_graph_entry_find(&e, cgraph_file, - &commit->oid, git_oid_size(walk->repo->oid_type)); - - if (error == 0 && git__is_uint16(e.parent_count)) { - size_t i; - commit->generation = (uint32_t)e.generation; - commit->time = e.commit_time; - commit->out_degree = (uint16_t)e.parent_count; - commit->parents = alloc_parents(walk, commit, commit->out_degree); - GIT_ERROR_CHECK_ALLOC(commit->parents); - - for (i = 0; i < commit->out_degree; ++i) { - git_commit_graph_entry parent; - error = git_commit_graph_entry_parent(&parent, cgraph_file, &e, i); - if (error < 0) - return error; - commit->parents[i] = git_revwalk__commit_lookup(walk, &parent.sha1); - } - commit->parsed = 1; - return 0; - } - } - - if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0) - return error; - - if (obj->cached.type != GIT_OBJECT_COMMIT) { - git_error_set(GIT_ERROR_INVALID, "object is no commit object"); - error = -1; - } else - error = commit_quick_parse(walk, commit, obj); - - git_odb_object_free(obj); - return error; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/commit_list.h b/vendor/libgit2-sys/libgit2/src/libgit2/commit_list.h deleted file mode 100644 index e2dbd2a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/commit_list.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_commit_list_h__ -#define INCLUDE_commit_list_h__ - -#include "common.h" - -#include "git2/oid.h" - -#define PARENT1 (1 << 0) -#define PARENT2 (1 << 1) -#define RESULT (1 << 2) -#define STALE (1 << 3) -#define ALL_FLAGS (PARENT1 | PARENT2 | STALE | RESULT) - -#define PARENTS_PER_COMMIT 2 -#define COMMIT_ALLOC \ - (sizeof(git_commit_list_node) + PARENTS_PER_COMMIT * sizeof(git_commit_list_node *)) - -#define FLAG_BITS 4 - -typedef struct git_commit_list_node { - git_oid oid; - int64_t time; - uint32_t generation; - unsigned int seen:1, - uninteresting:1, - topo_delay:1, - parsed:1, - added:1, - flags : FLAG_BITS; - - uint16_t in_degree; - uint16_t out_degree; - - struct git_commit_list_node **parents; -} git_commit_list_node; - -typedef struct git_commit_list { - git_commit_list_node *item; - struct git_commit_list *next; -} git_commit_list; - -git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk); -int git_commit_list_generation_cmp(const void *a, const void *b); -int git_commit_list_time_cmp(const void *a, const void *b); -void git_commit_list_free(git_commit_list **list_p); -git_commit_list *git_commit_list_create(git_commit_list_node *item, git_commit_list *next); -git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p); -git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p); -int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit); -git_commit_list_node *git_commit_list_pop(git_commit_list **stack); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/common.h b/vendor/libgit2-sys/libgit2/src/libgit2/common.h deleted file mode 100644 index bb9ec5a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/common.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_common_h__ -#define INCLUDE_common_h__ - -#include "git2_util.h" -#include "errors.h" - -/* -* Include the declarations for deprecated functions; this ensures -* that they're decorated with the proper extern/visibility attributes. -*/ -#include "git2/deprecated.h" - -#include "posix.h" - -/** - * Initialize a structure with a version. - */ -GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version) -{ - memset(structure, 0, len); - *((int*)structure) = version; -} -#define GIT_INIT_STRUCTURE(S,V) git__init_structure(S, sizeof(*S), V) - -#define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \ - TYPE _tmpl = TPL; \ - GIT_ERROR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \ - memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0) - -/** - * Check a versioned structure for validity - */ -GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int expected_max, const char *name) -{ - unsigned int actual; - - if (!structure) - return 0; - - actual = *(const unsigned int*)structure; - if (actual > 0 && actual <= expected_max) - return 0; - - git_error_set(GIT_ERROR_INVALID, "invalid version %d on %s", actual, name); - return -1; -} -#define GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) return -1 - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config.c b/vendor/libgit2-sys/libgit2/src/libgit2/config.c deleted file mode 100644 index 653142c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config.c +++ /dev/null @@ -1,1667 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "config.h" - -#include "git2/config.h" -#include "git2/sys/config.h" - -#include "buf.h" -#include "config_backend.h" -#include "regexp.h" -#include "sysdir.h" -#include "transaction.h" -#include "vector.h" -#if GIT_WIN32 -# include -#endif - -#include - -/* - * A refcounted instance of a config_backend that can be shared across - * a configuration instance, any snapshots, and individual configuration - * levels (from `git_config_open_level`). - */ -typedef struct { - git_refcount rc; - git_config_backend *backend; -} backend_instance; - -/* - * An entry in the readers or writers vector in the configuration. - * This is kept separate from the refcounted instance so that different - * views of the configuration can have different notions of levels or - * write orders. - * - * (eg, a standard configuration has a priority ordering of writers, a - * snapshot has *no* writers, and an individual level has a single - * writer.) - */ -typedef struct { - backend_instance *instance; - git_config_level_t level; - int write_order; -} backend_entry; - -void git_config_entry_free(git_config_entry *entry) -{ - git_config_backend_entry *be; - - if (!entry) - return; - - be = (git_config_backend_entry *)entry; - be->free(be); -} - -static void backend_instance_free(backend_instance *instance) -{ - git_config_backend *backend; - - backend = instance->backend; - backend->free(backend); - git__free(instance); -} - -static void config_free(git_config *config) -{ - size_t i; - backend_entry *entry; - - git_vector_foreach(&config->readers, i, entry) { - GIT_REFCOUNT_DEC(entry->instance, backend_instance_free); - git__free(entry); - } - - git_vector_dispose(&config->readers); - git_vector_dispose(&config->writers); - git__free(config); -} - -void git_config_free(git_config *config) -{ - if (config == NULL) - return; - - GIT_REFCOUNT_DEC(config, config_free); -} - -static int reader_cmp(const void *_a, const void *_b) -{ - const backend_entry *a = _a; - const backend_entry *b = _b; - - return b->level - a->level; -} - -static int writer_cmp(const void *_a, const void *_b) -{ - const backend_entry *a = _a; - const backend_entry *b = _b; - - return b->write_order - a->write_order; -} - -int git_config_new(git_config **out) -{ - git_config *config; - - config = git__calloc(1, sizeof(git_config)); - GIT_ERROR_CHECK_ALLOC(config); - - if (git_vector_init(&config->readers, 8, reader_cmp) < 0 || - git_vector_init(&config->writers, 8, writer_cmp) < 0) { - config_free(config); - return -1; - } - - GIT_REFCOUNT_INC(config); - - *out = config; - return 0; -} - -int git_config_add_file_ondisk( - git_config *config, - const char *path, - git_config_level_t level, - const git_repository *repo, - int force) -{ - git_config_backend *file = NULL; - struct stat st; - int res; - - GIT_ASSERT_ARG(config); - GIT_ASSERT_ARG(path); - - res = p_stat(path, &st); - if (res < 0 && errno != ENOENT && errno != ENOTDIR) { - git_error_set(GIT_ERROR_CONFIG, "failed to stat '%s'", path); - return -1; - } - - if (git_config_backend_from_file(&file, path) < 0) - return -1; - - if ((res = git_config_add_backend(config, file, level, repo, force)) < 0) { - /* - * free manually; the file is not owned by the config - * instance yet and will not be freed on cleanup - */ - file->free(file); - return res; - } - - return 0; -} - -int git_config_open_ondisk(git_config **out, const char *path) -{ - int error; - git_config *config; - - *out = NULL; - - if (git_config_new(&config) < 0) - return -1; - - if ((error = git_config_add_file_ondisk(config, path, GIT_CONFIG_LEVEL_LOCAL, NULL, 0)) < 0) - git_config_free(config); - else - *out = config; - - return error; -} - -int git_config_snapshot(git_config **out, git_config *in) -{ - int error = 0; - size_t i; - backend_entry *entry; - git_config *config; - - *out = NULL; - - if (git_config_new(&config) < 0) - return -1; - - git_vector_foreach(&in->readers, i, entry) { - git_config_backend *b; - - if ((error = entry->instance->backend->snapshot(&b, entry->instance->backend)) < 0) - break; - - if ((error = git_config_add_backend(config, b, entry->level, NULL, 0)) < 0) { - b->free(b); - break; - } - } - - git_config_set_writeorder(config, NULL, 0); - - if (error < 0) - git_config_free(config); - else - *out = config; - - return error; -} - -static int find_backend_by_level( - backend_instance **out, - const git_config *config, - git_config_level_t level) -{ - backend_entry *entry, *found = NULL; - size_t i; - - /* - * when passing GIT_CONFIG_HIGHEST_LEVEL, the idea is to get the - * config backend which has the highest level. As config backends - * are stored in a vector sorted by decreasing order of level, - * getting the backend at position 0 will do the job. - */ - if (level == GIT_CONFIG_HIGHEST_LEVEL) { - found = git_vector_get(&config->readers, 0); - } else { - git_vector_foreach(&config->readers, i, entry) { - if (entry->level == level) { - found = entry; - break; - } - } - } - - if (!found) { - git_error_set(GIT_ERROR_CONFIG, - "no configuration exists for the given level '%d'", level); - return GIT_ENOTFOUND; - } - - *out = found->instance; - return 0; -} - -static int duplicate_level(void **_old, void *_new) -{ - backend_entry **old = (backend_entry **)_old; - - GIT_UNUSED(_new); - - git_error_set(GIT_ERROR_CONFIG, "configuration at level %d already exists", (*old)->level); - return GIT_EEXISTS; -} - -static void try_remove_existing_backend( - git_config *config, - git_config_level_t level) -{ - backend_entry *entry, *found = NULL; - size_t i; - - git_vector_foreach(&config->readers, i, entry) { - if (entry->level == level) { - git_vector_remove(&config->readers, i); - found = entry; - break; - } - } - - if (!found) - return; - - git_vector_foreach(&config->writers, i, entry) { - if (entry->level == level) { - git_vector_remove(&config->writers, i); - break; - } - } - - GIT_REFCOUNT_DEC(found->instance, backend_instance_free); - git__free(found); -} - -static int git_config__add_instance( - git_config *config, - backend_instance *instance, - git_config_level_t level, - int force) -{ - backend_entry *entry; - int result; - - /* delete existing config backend for level if it exists */ - if (force) - try_remove_existing_backend(config, level); - - entry = git__malloc(sizeof(backend_entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->instance = instance; - entry->level = level; - entry->write_order = level; - - if ((result = git_vector_insert_sorted(&config->readers, - entry, &duplicate_level)) < 0 || - (result = git_vector_insert_sorted(&config->writers, - entry, NULL)) < 0) { - git__free(entry); - return result; - } - - GIT_REFCOUNT_INC(entry->instance); - - return 0; -} - -int git_config_open_global(git_config **out, git_config *config) -{ - int error; - - error = git_config_open_level(out, config, GIT_CONFIG_LEVEL_XDG); - - if (error == 0) - return 0; - else if (error != GIT_ENOTFOUND) - return error; - - return git_config_open_level(out, config, GIT_CONFIG_LEVEL_GLOBAL); -} - -int git_config_open_level( - git_config **out, - const git_config *parent, - git_config_level_t level) -{ - git_config *config; - backend_instance *instance; - int res; - - if ((res = find_backend_by_level(&instance, parent, level)) < 0) - return res; - - if ((res = git_config_new(&config)) < 0) - return res; - - if ((res = git_config__add_instance(config, instance, level, true)) < 0) { - git_config_free(config); - return res; - } - - *out = config; - - return 0; -} - -int git_config_add_backend( - git_config *config, - git_config_backend *backend, - git_config_level_t level, - const git_repository *repo, - int force) -{ - backend_instance *instance; - int result; - - GIT_ASSERT_ARG(config); - GIT_ASSERT_ARG(backend); - - GIT_ERROR_CHECK_VERSION(backend, GIT_CONFIG_BACKEND_VERSION, "git_config_backend"); - - if ((result = backend->open(backend, level, repo)) < 0) - return result; - - instance = git__calloc(1, sizeof(backend_instance)); - GIT_ERROR_CHECK_ALLOC(instance); - - instance->backend = backend; - instance->backend->cfg = config; - - if ((result = git_config__add_instance(config, instance, level, force)) < 0) { - git__free(instance); - return result; - } - - return 0; -} - -int git_config_set_writeorder( - git_config *config, - git_config_level_t *levels, - size_t len) -{ - backend_entry *entry; - size_t i, j; - - GIT_ASSERT(len < INT_MAX); - - git_vector_foreach(&config->readers, i, entry) { - bool found = false; - - for (j = 0; j < len; j++) { - if (levels[j] == entry->level) { - entry->write_order = (int)j; - found = true; - break; - } - } - - if (!found) - entry->write_order = -1; - } - - git_vector_sort(&config->writers); - - return 0; -} - -/* - * Loop over all the variables - */ - -typedef struct { - git_config_iterator parent; - git_config_iterator *current; - const git_config *config; - git_regexp regex; - size_t i; -} all_iter; - -static int all_iter_next( - git_config_backend_entry **out, - git_config_iterator *_iter) -{ - all_iter *iter = (all_iter *) _iter; - backend_entry *entry; - git_config_backend *backend; - git_config_backend_entry *be; - int error = 0; - - if (iter->current != NULL && - (error = iter->current->next(&be, iter->current)) == 0) { - *out = be; - return 0; - } - - if (error < 0 && error != GIT_ITEROVER) - return error; - - do { - if (iter->i == 0) - return GIT_ITEROVER; - - entry = git_vector_get(&iter->config->readers, iter->i - 1); - GIT_ASSERT(entry && entry->instance && entry->instance->backend); - - backend = entry->instance->backend; - iter->i--; - - if (iter->current) - iter->current->free(iter->current); - - iter->current = NULL; - error = backend->iterator(&iter->current, backend); - - if (error == GIT_ENOTFOUND) - continue; - - if (error < 0) - return error; - - if ((error = iter->current->next(&be, iter->current)) == 0) { - *out = be; - return 0; - } - - /* If this backend is empty, then keep going */ - if (error == GIT_ITEROVER) - continue; - - return error; - - } while(1); - - return GIT_ITEROVER; -} - -static int all_iter_glob_next( - git_config_backend_entry **entry, - git_config_iterator *_iter) -{ - int error; - all_iter *iter = (all_iter *) _iter; - - /* - * We use the "normal" function to grab the next one across - * readers and then apply the regex - */ - while ((error = all_iter_next(entry, _iter)) == 0) { - /* skip non-matching keys if regexp was provided */ - if (git_regexp_match(&iter->regex, (*entry)->entry.name) != 0) - continue; - - /* and simply return if we like the entry's name */ - return 0; - } - - return error; -} - -static void all_iter_free(git_config_iterator *_iter) -{ - all_iter *iter = (all_iter *) _iter; - - if (iter->current) - iter->current->free(iter->current); - - git__free(iter); -} - -static void all_iter_glob_free(git_config_iterator *_iter) -{ - all_iter *iter = (all_iter *) _iter; - - git_regexp_dispose(&iter->regex); - all_iter_free(_iter); -} - -int git_config_iterator_new(git_config_iterator **out, const git_config *config) -{ - all_iter *iter; - - iter = git__calloc(1, sizeof(all_iter)); - GIT_ERROR_CHECK_ALLOC(iter); - - iter->parent.free = all_iter_free; - iter->parent.next = all_iter_next; - - iter->i = config->readers.length; - iter->config = config; - - *out = (git_config_iterator *) iter; - - return 0; -} - -int git_config_iterator_glob_new(git_config_iterator **out, const git_config *config, const char *regexp) -{ - all_iter *iter; - int result; - - if (regexp == NULL) - return git_config_iterator_new(out, config); - - iter = git__calloc(1, sizeof(all_iter)); - GIT_ERROR_CHECK_ALLOC(iter); - - if ((result = git_regexp_compile(&iter->regex, regexp, 0)) < 0) { - git__free(iter); - return -1; - } - - iter->parent.next = all_iter_glob_next; - iter->parent.free = all_iter_glob_free; - iter->i = config->readers.length; - iter->config = config; - - *out = (git_config_iterator *) iter; - - return 0; -} - -int git_config_foreach( - const git_config *config, git_config_foreach_cb cb, void *payload) -{ - return git_config_foreach_match(config, NULL, cb, payload); -} - -int git_config_backend_foreach_match( - git_config_backend *backend, - const char *regexp, - git_config_foreach_cb cb, - void *payload) -{ - git_config_backend_entry *entry; - git_config_iterator *iter; - git_regexp regex; - int error = 0; - - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(cb); - - if (regexp && git_regexp_compile(®ex, regexp, 0) < 0) - return -1; - - if ((error = backend->iterator(&iter, backend)) < 0) { - iter = NULL; - return -1; - } - - while (!(iter->next(&entry, iter) < 0)) { - /* skip non-matching keys if regexp was provided */ - if (regexp && git_regexp_match(®ex, entry->entry.name) != 0) - continue; - - /* abort iterator on non-zero return value */ - if ((error = cb(&entry->entry, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - if (regexp != NULL) - git_regexp_dispose(®ex); - - iter->free(iter); - - return error; -} - -int git_config_foreach_match( - const git_config *config, - const char *regexp, - git_config_foreach_cb cb, - void *payload) -{ - int error; - git_config_iterator *iter; - git_config_entry *entry; - - if ((error = git_config_iterator_glob_new(&iter, config, regexp)) < 0) - return error; - - while (!(error = git_config_next(&entry, iter))) { - if ((error = cb(entry, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - git_config_iterator_free(iter); - - if (error == GIT_ITEROVER) - error = 0; - - return error; -} - -/************** - * Setters - **************/ - - static backend_instance *get_writer_instance(git_config *config) - { - backend_entry *entry; - size_t i; - - git_vector_foreach(&config->writers, i, entry) { - if (entry->instance->backend->readonly) - continue; - - if (entry->write_order < 0) - continue; - - return entry->instance; - } - - return NULL; - } - -static git_config_backend *get_writer(git_config *config) -{ - backend_instance *instance = get_writer_instance(config); - - return instance ? instance->backend : NULL; -} - -int git_config_delete_entry(git_config *config, const char *name) -{ - git_config_backend *backend; - - if ((backend = get_writer(config)) == NULL) - return GIT_EREADONLY; - - return backend->del(backend, name); -} - -int git_config_set_int64(git_config *config, const char *name, int64_t value) -{ - char str_value[32]; /* All numbers should fit in here */ - p_snprintf(str_value, sizeof(str_value), "%" PRId64, value); - return git_config_set_string(config, name, str_value); -} - -int git_config_set_int32(git_config *config, const char *name, int32_t value) -{ - return git_config_set_int64(config, name, (int64_t)value); -} - -int git_config_set_bool(git_config *config, const char *name, int value) -{ - return git_config_set_string(config, name, value ? "true" : "false"); -} - -int git_config_set_string(git_config *config, const char *name, const char *value) -{ - int error; - git_config_backend *backend; - - if (!value) { - git_error_set(GIT_ERROR_CONFIG, "the value to set cannot be NULL"); - return -1; - } - - if ((backend = get_writer(config)) == NULL) { - git_error_set(GIT_ERROR_CONFIG, "cannot set '%s': the configuration is read-only", name); - return GIT_EREADONLY; - } - - error = backend->set(backend, name, value); - - if (!error && GIT_REFCOUNT_OWNER(config) != NULL) - git_repository__configmap_lookup_cache_clear(GIT_REFCOUNT_OWNER(config)); - - return error; -} - -int git_config__update_entry( - git_config *config, - const char *key, - const char *value, - bool overwrite_existing, - bool only_if_existing) -{ - int error = 0; - git_config_entry *ce = NULL; - - if ((error = git_config__lookup_entry(&ce, config, key, false)) < 0) - return error; - - if (!ce && only_if_existing) /* entry doesn't exist */ - return 0; - if (ce && !overwrite_existing) /* entry would be overwritten */ - return 0; - if (value && ce && ce->value && !strcmp(ce->value, value)) /* no change */ - return 0; - if (!value && (!ce || !ce->value)) /* asked to delete absent entry */ - return 0; - - if (!value) - error = git_config_delete_entry(config, key); - else - error = git_config_set_string(config, key, value); - - git_config_entry_free(ce); - return error; -} - -/*********** - * Getters - ***********/ - -static int config_error_notfound(const char *name) -{ - git_error_set(GIT_ERROR_CONFIG, "config value '%s' was not found", name); - return GIT_ENOTFOUND; -} - -enum { - GET_ALL_ERRORS = 0, - GET_NO_MISSING = 1, - GET_NO_ERRORS = 2 -}; - -static int get_entry( - git_config_entry **out, - const git_config *config, - const char *name, - bool normalize_name, - int want_errors) -{ - backend_entry *entry; - git_config_backend *backend; - git_config_backend_entry *be; - int res = GIT_ENOTFOUND; - const char *key = name; - char *normalized = NULL; - size_t i; - - *out = NULL; - - if (normalize_name) { - if ((res = git_config__normalize_name(name, &normalized)) < 0) - goto cleanup; - key = normalized; - } - - res = GIT_ENOTFOUND; - git_vector_foreach(&config->readers, i, entry) { - GIT_ASSERT(entry->instance && entry->instance->backend); - - backend = entry->instance->backend; - res = backend->get(backend, key, &be); - - if (res != GIT_ENOTFOUND) { - *out = &be->entry; - break; - } - } - - git__free(normalized); - -cleanup: - if (res == GIT_ENOTFOUND) { - res = (want_errors > GET_ALL_ERRORS) ? 0 : config_error_notfound(name); - } else if (res && (want_errors == GET_NO_ERRORS)) { - git_error_clear(); - res = 0; - } - - return res; -} - -int git_config_get_entry( - git_config_entry **out, const git_config *config, const char *name) -{ - return get_entry(out, config, name, true, GET_ALL_ERRORS); -} - -int git_config__lookup_entry( - git_config_entry **out, - const git_config *config, - const char *key, - bool no_errors) -{ - return get_entry( - out, config, key, false, no_errors ? GET_NO_ERRORS : GET_NO_MISSING); -} - -int git_config_get_mapped( - int *out, - const git_config *config, - const char *name, - const git_configmap *maps, - size_t map_n) -{ - git_config_entry *entry; - int ret; - - if ((ret = get_entry(&entry, config, name, true, GET_ALL_ERRORS)) < 0) - return ret; - - ret = git_config_lookup_map_value(out, maps, map_n, entry->value); - git_config_entry_free(entry); - - return ret; -} - -int git_config_get_int64(int64_t *out, const git_config *config, const char *name) -{ - git_config_entry *entry; - int ret; - - if ((ret = get_entry(&entry, config, name, true, GET_ALL_ERRORS)) < 0) - return ret; - - ret = git_config_parse_int64(out, entry->value); - git_config_entry_free(entry); - - return ret; -} - -int git_config_get_int32(int32_t *out, const git_config *config, const char *name) -{ - git_config_entry *entry; - int ret; - - if ((ret = get_entry(&entry, config, name, true, GET_ALL_ERRORS)) < 0) - return ret; - - ret = git_config_parse_int32(out, entry->value); - git_config_entry_free(entry); - - return ret; -} - -int git_config_get_bool(int *out, const git_config *config, const char *name) -{ - git_config_entry *entry; - int ret; - - if ((ret = get_entry(&entry, config, name, true, GET_ALL_ERRORS)) < 0) - return ret; - - ret = git_config_parse_bool(out, entry->value); - git_config_entry_free(entry); - - return ret; -} - -static int is_readonly(const git_config *config) -{ - backend_entry *entry; - size_t i; - - git_vector_foreach(&config->writers, i, entry) { - GIT_ASSERT(entry->instance && entry->instance->backend); - - if (!entry->instance->backend->readonly) - return 0; - } - - return 1; -} - -static int git_config__parse_path(git_str *out, const char *value) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(value); - - if (value[0] == '~') { - if (value[1] != '\0' && value[1] != '/') { - git_error_set(GIT_ERROR_CONFIG, "retrieving a homedir by name is not supported"); - return -1; - } - - return git_sysdir_expand_homedir_file(out, value[1] ? &value[2] : NULL); - } - - return git_str_sets(out, value); -} - -int git_config_parse_path(git_buf *out, const char *value) -{ - GIT_BUF_WRAP_PRIVATE(out, git_config__parse_path, value); -} - -int git_config_get_path( - git_buf *out, - const git_config *config, - const char *name) -{ - GIT_BUF_WRAP_PRIVATE(out, git_config__get_path, config, name); -} - -int git_config__get_path( - git_str *out, - const git_config *config, - const char *name) -{ - git_config_entry *entry; - int error; - - if ((error = get_entry(&entry, config, name, true, GET_ALL_ERRORS)) < 0) - return error; - - error = git_config__parse_path(out, entry->value); - git_config_entry_free(entry); - - return error; -} - -int git_config_get_string( - const char **out, const git_config *config, const char *name) -{ - git_config_entry *entry; - int ret; - - if (!is_readonly(config)) { - git_error_set(GIT_ERROR_CONFIG, "get_string called on a live config object"); - return -1; - } - - ret = get_entry(&entry, config, name, true, GET_ALL_ERRORS); - *out = !ret ? (entry->value ? entry->value : "") : NULL; - - git_config_entry_free(entry); - - return ret; -} - -int git_config_get_string_buf( - git_buf *out, const git_config *config, const char *name) -{ - GIT_BUF_WRAP_PRIVATE(out, git_config__get_string_buf, config, name); -} - -int git_config__get_string_buf( - git_str *out, const git_config *config, const char *name) -{ - git_config_entry *entry; - int ret; - const char *str; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(config); - - ret = get_entry(&entry, config, name, true, GET_ALL_ERRORS); - str = !ret ? (entry->value ? entry->value : "") : NULL; - - if (str) - ret = git_str_puts(out, str); - - git_config_entry_free(entry); - - return ret; -} - -char *git_config__get_string_force( - const git_config *config, const char *key, const char *fallback_value) -{ - git_config_entry *entry; - char *ret; - - get_entry(&entry, config, key, false, GET_NO_ERRORS); - ret = (entry && entry->value) ? git__strdup(entry->value) : fallback_value ? git__strdup(fallback_value) : NULL; - git_config_entry_free(entry); - - return ret; -} - -int git_config__get_bool_force( - const git_config *config, const char *key, int fallback_value) -{ - int val = fallback_value; - git_config_entry *entry; - - get_entry(&entry, config, key, false, GET_NO_ERRORS); - - if (entry && git_config_parse_bool(&val, entry->value) < 0) - git_error_clear(); - - git_config_entry_free(entry); - return val; -} - -int git_config__get_int_force( - const git_config *config, const char *key, int fallback_value) -{ - int32_t val = (int32_t)fallback_value; - git_config_entry *entry; - - get_entry(&entry, config, key, false, GET_NO_ERRORS); - - if (entry && git_config_parse_int32(&val, entry->value) < 0) - git_error_clear(); - - git_config_entry_free(entry); - return (int)val; -} - -int git_config_get_multivar_foreach( - const git_config *config, const char *name, const char *regexp, - git_config_foreach_cb cb, void *payload) -{ - int err, found; - git_config_iterator *iter; - git_config_backend_entry *be; - - if ((err = git_config_multivar_iterator_new(&iter, config, name, regexp)) < 0) - return err; - - found = 0; - while ((err = iter->next(&be, iter)) == 0) { - found = 1; - - if ((err = cb(&be->entry, payload)) != 0) { - git_error_set_after_callback(err); - break; - } - } - - iter->free(iter); - if (err == GIT_ITEROVER) - err = 0; - - if (found == 0 && err == 0) - err = config_error_notfound(name); - - return err; -} - -typedef struct { - git_config_iterator parent; - git_config_iterator *iter; - char *name; - git_regexp regex; - int have_regex; -} multivar_iter; - -static int multivar_iter_next( - git_config_backend_entry **entry, - git_config_iterator *_iter) -{ - multivar_iter *iter = (multivar_iter *) _iter; - int error = 0; - - while ((error = iter->iter->next(entry, iter->iter)) == 0) { - if (git__strcmp(iter->name, (*entry)->entry.name)) - continue; - - if (!iter->have_regex) - return 0; - - if (git_regexp_match(&iter->regex, (*entry)->entry.value) == 0) - return 0; - } - - return error; -} - -static void multivar_iter_free(git_config_iterator *_iter) -{ - multivar_iter *iter = (multivar_iter *) _iter; - - iter->iter->free(iter->iter); - - git__free(iter->name); - if (iter->have_regex) - git_regexp_dispose(&iter->regex); - git__free(iter); -} - -int git_config_multivar_iterator_new(git_config_iterator **out, const git_config *config, const char *name, const char *regexp) -{ - multivar_iter *iter = NULL; - git_config_iterator *inner = NULL; - int error; - - if ((error = git_config_iterator_new(&inner, config)) < 0) - return error; - - iter = git__calloc(1, sizeof(multivar_iter)); - GIT_ERROR_CHECK_ALLOC(iter); - - if ((error = git_config__normalize_name(name, &iter->name)) < 0) - goto on_error; - - if (regexp != NULL) { - if ((error = git_regexp_compile(&iter->regex, regexp, 0)) < 0) - goto on_error; - - iter->have_regex = 1; - } - - iter->iter = inner; - iter->parent.free = multivar_iter_free; - iter->parent.next = multivar_iter_next; - - *out = (git_config_iterator *) iter; - - return 0; - -on_error: - - inner->free(inner); - git__free(iter); - return error; -} - -int git_config_set_multivar(git_config *config, const char *name, const char *regexp, const char *value) -{ - git_config_backend *backend; - - if ((backend = get_writer(config)) == NULL) { - git_error_set(GIT_ERROR_CONFIG, "cannot set '%s': the configuration is read-only", name); - return GIT_EREADONLY; - } - - return backend->set_multivar(backend, name, regexp, value); -} - -int git_config_delete_multivar(git_config *config, const char *name, const char *regexp) -{ - git_config_backend *backend; - - if ((backend = get_writer(config)) == NULL) - return GIT_EREADONLY; - - return backend->del_multivar(backend, name, regexp); -} - -int git_config_next(git_config_entry **entry, git_config_iterator *iter) -{ - git_config_backend_entry *be; - int error; - - if ((error = iter->next(&be, iter)) != 0) - return error; - - *entry = &be->entry; - return 0; -} - -void git_config_iterator_free(git_config_iterator *iter) -{ - if (iter == NULL) - return; - - iter->free(iter); -} - -int git_config_find_global(git_buf *path) -{ - GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_global_file, GIT_CONFIG_FILENAME_GLOBAL); -} - -int git_config__find_global(git_str *path) -{ - return git_sysdir_find_global_file(path, GIT_CONFIG_FILENAME_GLOBAL); -} - -int git_config_find_xdg(git_buf *path) -{ - GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_xdg_file, GIT_CONFIG_FILENAME_XDG); -} - -int git_config__find_xdg(git_str *path) -{ - return git_sysdir_find_xdg_file(path, GIT_CONFIG_FILENAME_XDG); -} - -int git_config_find_system(git_buf *path) -{ - GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_system_file, GIT_CONFIG_FILENAME_SYSTEM); -} - -int git_config__find_system(git_str *path) -{ - return git_sysdir_find_system_file(path, GIT_CONFIG_FILENAME_SYSTEM); -} - -int git_config_find_programdata(git_buf *path) -{ - git_str str = GIT_STR_INIT; - int error; - - if ((error = git_buf_tostr(&str, path)) == 0 && - (error = git_config__find_programdata(&str)) == 0) - error = git_buf_fromstr(path, &str); - - git_str_dispose(&str); - return error; -} - -int git_config__find_programdata(git_str *path) -{ - git_fs_path_owner_t owner_level = - GIT_FS_PATH_OWNER_CURRENT_USER | - GIT_FS_PATH_OWNER_ADMINISTRATOR; - bool is_safe; - int error; - - if ((error = git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA)) < 0) - return error; - - if (git_fs_path_owner_is(&is_safe, path->ptr, owner_level) < 0) - return -1; - - if (!is_safe) { - git_error_set(GIT_ERROR_CONFIG, "programdata path has invalid ownership"); - return -1; - } - - return 0; -} - -int git_config__global_location(git_str *buf) -{ - const git_str *paths; - const char *sep, *start; - - if (git_sysdir_get(&paths, GIT_SYSDIR_GLOBAL) < 0) - return -1; - - /* no paths, so give up */ - if (!paths || !git_str_len(paths)) - return -1; - - /* find unescaped separator or end of string */ - for (sep = start = git_str_cstr(paths); *sep; ++sep) { - if (*sep == GIT_PATH_LIST_SEPARATOR && - (sep <= start || sep[-1] != '\\')) - break; - } - - if (git_str_set(buf, start, (size_t)(sep - start)) < 0) - return -1; - - return git_str_joinpath(buf, buf->ptr, GIT_CONFIG_FILENAME_GLOBAL); -} - -int git_config_open_default(git_config **out) -{ - int error; - git_config *config = NULL; - git_str buf = GIT_STR_INIT; - - if ((error = git_config_new(&config)) < 0) - return error; - - if (!git_config__find_global(&buf) || - !git_config__global_location(&buf)) { - error = git_config_add_file_ondisk(config, buf.ptr, - GIT_CONFIG_LEVEL_GLOBAL, NULL, 0); - } - - if (!error && !git_config__find_xdg(&buf)) - error = git_config_add_file_ondisk(config, buf.ptr, - GIT_CONFIG_LEVEL_XDG, NULL, 0); - - if (!error && !git_config__find_system(&buf)) - error = git_config_add_file_ondisk(config, buf.ptr, - GIT_CONFIG_LEVEL_SYSTEM, NULL, 0); - - if (!error && !git_config__find_programdata(&buf)) - error = git_config_add_file_ondisk(config, buf.ptr, - GIT_CONFIG_LEVEL_PROGRAMDATA, NULL, 0); - - git_str_dispose(&buf); - - if (error) { - git_config_free(config); - config = NULL; - } - - *out = config; - - return error; -} - -int git_config_lock(git_transaction **out, git_config *config) -{ - backend_instance *instance; - int error; - - GIT_ASSERT_ARG(config); - - if ((instance = get_writer_instance(config)) == NULL) { - git_error_set(GIT_ERROR_CONFIG, "cannot lock: the configuration is read-only"); - return GIT_EREADONLY; - } - - if ((error = instance->backend->lock(instance->backend)) < 0 || - (error = git_transaction_config_new(out, config, instance)) < 0) - return error; - - GIT_REFCOUNT_INC(instance); - return 0; -} - -int git_config_unlock( - git_config *config, - void *data, - int commit) -{ - backend_instance *instance = data; - int error; - - GIT_ASSERT_ARG(config && data); - GIT_UNUSED(config); - - error = instance->backend->unlock(instance->backend, commit); - GIT_REFCOUNT_DEC(instance, backend_instance_free); - - return error; -} - -/*********** - * Parsers - ***********/ - -int git_config_lookup_map_value( - int *out, - const git_configmap *maps, - size_t map_n, - const char *value) -{ - size_t i; - - for (i = 0; i < map_n; ++i) { - const git_configmap *m = maps + i; - - switch (m->type) { - case GIT_CONFIGMAP_FALSE: - case GIT_CONFIGMAP_TRUE: { - int bool_val; - - if (git_config_parse_bool(&bool_val, value) == 0 && - bool_val == (int)m->type) { - *out = m->map_value; - return 0; - } - break; - } - - case GIT_CONFIGMAP_INT32: - if (git_config_parse_int32(out, value) == 0) - return 0; - break; - - case GIT_CONFIGMAP_STRING: - if (value && strcasecmp(value, m->str_match) == 0) { - *out = m->map_value; - return 0; - } - break; - } - } - - git_error_set(GIT_ERROR_CONFIG, "failed to map '%s'", value); - return -1; -} - -int git_config_lookup_map_enum(git_configmap_t *type_out, const char **str_out, - const git_configmap *maps, size_t map_n, int enum_val) -{ - size_t i; - - for (i = 0; i < map_n; i++) { - const git_configmap *m = &maps[i]; - - if (m->map_value != enum_val) - continue; - - *type_out = m->type; - *str_out = m->str_match; - return 0; - } - - git_error_set(GIT_ERROR_CONFIG, "invalid enum value"); - return GIT_ENOTFOUND; -} - -int git_config_parse_bool(int *out, const char *value) -{ - if (git__parse_bool(out, value) == 0) - return 0; - - if (git_config_parse_int32(out, value) == 0) { - *out = !!(*out); - return 0; - } - - git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as a boolean", value ? value : "(null)"); - return -1; -} - -int git_config_parse_int64(int64_t *out, const char *value) -{ - const char *num_end; - int64_t num; - - if (!value || git__strntol64(&num, value, strlen(value), &num_end, 0) < 0) - goto fail_parse; - - switch (*num_end) { - case 'g': - case 'G': - num *= 1024; - /* fallthrough */ - - case 'm': - case 'M': - num *= 1024; - /* fallthrough */ - - case 'k': - case 'K': - num *= 1024; - - /* check that that there are no more characters after the - * given modifier suffix */ - if (num_end[1] != '\0') - return -1; - - /* fallthrough */ - - case '\0': - *out = num; - return 0; - - default: - goto fail_parse; - } - -fail_parse: - git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as an integer", value ? value : "(null)"); - return -1; -} - -int git_config_parse_int32(int32_t *out, const char *value) -{ - int64_t tmp; - int32_t truncate; - - if (git_config_parse_int64(&tmp, value) < 0) - goto fail_parse; - - truncate = tmp & 0xFFFFFFFF; - if (truncate != tmp) - goto fail_parse; - - *out = truncate; - return 0; - -fail_parse: - git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as a 32-bit integer", value ? value : "(null)"); - return -1; -} - -static int normalize_section(char *start, char *end) -{ - char *scan; - - if (start == end) - return GIT_EINVALIDSPEC; - - /* Validate and downcase range */ - for (scan = start; *scan; ++scan) { - if (end && scan >= end) - break; - if (git__isalnum(*scan)) - *scan = (char)git__tolower(*scan); - else if (*scan != '-' || scan == start) - return GIT_EINVALIDSPEC; - } - - if (scan == start) - return GIT_EINVALIDSPEC; - - return 0; -} - - -/* Take something the user gave us and make it nice for our hash function */ -int git_config__normalize_name(const char *in, char **out) -{ - char *name, *fdot, *ldot; - - GIT_ASSERT_ARG(in); - GIT_ASSERT_ARG(out); - - name = git__strdup(in); - GIT_ERROR_CHECK_ALLOC(name); - - fdot = strchr(name, '.'); - ldot = strrchr(name, '.'); - - if (fdot == NULL || fdot == name || ldot == NULL || !ldot[1]) - goto invalid; - - /* Validate and downcase up to first dot and after last dot */ - if (normalize_section(name, fdot) < 0 || - normalize_section(ldot + 1, NULL) < 0) - goto invalid; - - /* If there is a middle range, make sure it doesn't have newlines */ - while (fdot < ldot) - if (*fdot++ == '\n') - goto invalid; - - *out = name; - return 0; - -invalid: - git__free(name); - git_error_set(GIT_ERROR_CONFIG, "invalid config item name '%s'", in); - return GIT_EINVALIDSPEC; -} - -struct rename_data { - git_config *config; - git_str *name; - size_t old_len; -}; - -static int rename_config_entries_cb( - const git_config_entry *entry, - void *payload) -{ - int error = 0; - struct rename_data *data = (struct rename_data *)payload; - size_t base_len = git_str_len(data->name); - git_str value = GIT_STR_INIT; - - if (base_len > 0) { - if ((error = git_str_puts(data->name, - entry->name + data->old_len)) < 0 || - (error = git_config_set_multivar( - data->config, git_str_cstr(data->name), "^$", - entry->value)) < 0) - goto cleanup; - } - - git_str_putc(&value, '^'); - git_str_puts_escape_regex(&value, entry->value); - git_str_putc(&value, '$'); - - if (git_str_oom(&value)) { - error = -1; - goto cleanup; - } - - error = git_config_delete_multivar( - data->config, entry->name, git_str_cstr(&value)); - - cleanup: - git_str_truncate(data->name, base_len); - git_str_dispose(&value); - return error; -} - -int git_config_rename_section( - git_repository *repo, - const char *old_section_name, - const char *new_section_name) -{ - git_config *config; - git_str pattern = GIT_STR_INIT, replace = GIT_STR_INIT; - int error = 0; - struct rename_data data; - - git_str_puts_escape_regex(&pattern, old_section_name); - - if ((error = git_str_puts(&pattern, "\\..+")) < 0) - goto cleanup; - - if ((error = git_repository_config__weakptr(&config, repo)) < 0) - goto cleanup; - - data.config = config; - data.name = &replace; - data.old_len = strlen(old_section_name) + 1; - - if ((error = git_str_join(&replace, '.', new_section_name, "")) < 0) - goto cleanup; - - if (new_section_name != NULL && - (error = normalize_section(replace.ptr, strchr(replace.ptr, '.'))) < 0) - { - git_error_set( - GIT_ERROR_CONFIG, "invalid config section '%s'", new_section_name); - goto cleanup; - } - - error = git_config_foreach_match( - config, git_str_cstr(&pattern), rename_config_entries_cb, &data); - -cleanup: - git_str_dispose(&pattern); - git_str_dispose(&replace); - - return error; -} - -int git_config_init_backend(git_config_backend *backend, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - backend, version, git_config_backend, GIT_CONFIG_BACKEND_INIT); - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config.cmake.in b/vendor/libgit2-sys/libgit2/src/libgit2/config.cmake.in deleted file mode 100644 index 6d15e05..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config.cmake.in +++ /dev/null @@ -1,3 +0,0 @@ -include(CMakeFindDependencyMacro) - -include("${CMAKE_CURRENT_LIST_DIR}/@LIBGIT2_TARGETS_EXPORT_NAME@.cmake") \ No newline at end of file diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config.h b/vendor/libgit2-sys/libgit2/src/libgit2/config.h deleted file mode 100644 index 5003cbf..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_config_h__ -#define INCLUDE_config_h__ - -#include "common.h" - -#include "git2.h" -#include "git2/config.h" -#include "vector.h" -#include "repository.h" - -#define GIT_CONFIG_FILENAME_PROGRAMDATA "config" -#define GIT_CONFIG_FILENAME_SYSTEM "gitconfig" -#define GIT_CONFIG_FILENAME_GLOBAL ".gitconfig" -#define GIT_CONFIG_FILENAME_XDG "config" - -#define GIT_CONFIG_FILENAME_INREPO "config" -#define GIT_CONFIG_FILE_MODE 0666 - -struct git_config { - git_refcount rc; - git_vector readers; - git_vector writers; -}; - -extern int git_config__global_location(git_str *buf); - -extern int git_config__find_global(git_str *path); -extern int git_config__find_xdg(git_str *path); -extern int git_config__find_system(git_str *path); -extern int git_config__find_programdata(git_str *path); - -extern int git_config_rename_section( - git_repository *repo, - const char *old_section_name, /* eg "branch.dummy" */ - const char *new_section_name); /* NULL to drop the old section */ - -extern int git_config__normalize_name(const char *in, char **out); - -/* internal only: does not normalize key and sets out to NULL if not found */ -extern int git_config__lookup_entry( - git_config_entry **out, - const git_config *cfg, - const char *key, - bool no_errors); - -/* internal only: update and/or delete entry string with constraints */ -extern int git_config__update_entry( - git_config *cfg, - const char *key, - const char *value, - bool overwrite_existing, - bool only_if_existing); - -int git_config__get_path( - git_str *out, - const git_config *cfg, - const char *name); - -int git_config__get_string_buf( - git_str *out, const git_config *cfg, const char *name); - -/* - * Lookup functions that cannot fail. These functions look up a config - * value and return a fallback value if the value is missing or if any - * failures occur while trying to access the value. - */ - -extern char *git_config__get_string_force( - const git_config *cfg, const char *key, const char *fallback_value); - -extern int git_config__get_bool_force( - const git_config *cfg, const char *key, int fallback_value); - -extern int git_config__get_int_force( - const git_config *cfg, const char *key, int fallback_value); - -/* API for repository configmap-style lookups from config - not cached, but - * uses configmap value maps and fallbacks - */ -extern int git_config__configmap_lookup( - int *out, git_config *config, git_configmap_item item); - -/** - * The opposite of git_config_lookup_map_value, we take an enum value - * and map it to the string or bool value on the config. - */ -int git_config_lookup_map_enum(git_configmap_t *type_out, - const char **str_out, const git_configmap *maps, - size_t map_n, int enum_val); - -/** - * Unlock the given backend that was previously locked. - * - * Unlocking will allow other writers to update the configuration - * file. Optionally, any changes performed since the lock will be - * applied to the configuration. - * - * @param config the config instance - * @param data the config data passed to git_transaction_new - * @param commit boolean which indicates whether to commit any changes - * done since locking - * @return 0 or an error code - */ -GIT_EXTERN(int) git_config_unlock( - git_config *config, - void *data, - int commit); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_backend.h b/vendor/libgit2-sys/libgit2/src/libgit2/config_backend.h deleted file mode 100644 index 786c5de..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_backend.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_config_file_h__ -#define INCLUDE_config_file_h__ - -#include "common.h" - -#include "git2/sys/config.h" -#include "git2/config.h" - -/** - * Create a configuration file backend for ondisk files - * - * These are the normal `.gitconfig` files that Core Git - * processes. Note that you first have to add this file to a - * configuration object before you can query it for configuration - * variables. - * - * @param out the new backend - * @param path where the config file is located - */ -extern int git_config_backend_from_file(git_config_backend **out, const char *path); - -/** - * Create a readonly configuration file backend from another backend - * - * This copies the complete contents of the source backend to the - * new backend. The new backend will be completely read-only and - * cannot be modified. - * - * @param out the new snapshotted backend - * @param source the backend to copy - */ -extern int git_config_backend_snapshot(git_config_backend **out, git_config_backend *source); - -GIT_INLINE(int) git_config_backend_open(git_config_backend *cfg, unsigned int level, const git_repository *repo) -{ - return cfg->open(cfg, level, repo); -} - -GIT_INLINE(void) git_config_backend_free(git_config_backend *cfg) -{ - if (cfg) - cfg->free(cfg); -} - -GIT_INLINE(int) git_config_backend_get_string( - git_config_entry **out, git_config_backend *cfg, const char *name) -{ - git_config_backend_entry *be; - int error; - - if ((error = cfg->get(cfg, name, &be)) < 0) - return error; - - *out = &be->entry; - return 0; -} - -GIT_INLINE(int) git_config_backend_set_string( - git_config_backend *cfg, const char *name, const char *value) -{ - return cfg->set(cfg, name, value); -} - -GIT_INLINE(int) git_config_backend_delete( - git_config_backend *cfg, const char *name) -{ - return cfg->del(cfg, name); -} - -GIT_INLINE(int) git_config_backend_foreach( - git_config_backend *cfg, - int (*fn)(const git_config_entry *entry, void *data), - void *data) -{ - return git_config_backend_foreach_match(cfg, NULL, fn, data); -} - -GIT_INLINE(int) git_config_backend_lock(git_config_backend *cfg) -{ - return cfg->lock(cfg); -} - -GIT_INLINE(int) git_config_backend_unlock(git_config_backend *cfg, int success) -{ - return cfg->unlock(cfg, success); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_cache.c b/vendor/libgit2-sys/libgit2/src/libgit2/config_cache.c deleted file mode 100644 index 05d9d58..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_cache.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "futils.h" -#include "repository.h" -#include "config.h" -#include "git2/config.h" -#include "vector.h" -#include "filter.h" - -struct map_data { - const char *name; - git_configmap *maps; - size_t map_count; - int default_value; -}; - -/* - * core.eol - * Sets the line ending type to use in the working directory for - * files that have the text property set. Alternatives are lf, crlf - * and native, which uses the platform's native line ending. The default - * value is native. See gitattributes(5) for more information on - * end-of-line conversion. - */ -static git_configmap _configmap_eol[] = { - {GIT_CONFIGMAP_FALSE, NULL, GIT_EOL_UNSET}, - {GIT_CONFIGMAP_STRING, "lf", GIT_EOL_LF}, - {GIT_CONFIGMAP_STRING, "crlf", GIT_EOL_CRLF}, - {GIT_CONFIGMAP_STRING, "native", GIT_EOL_NATIVE} -}; - -/* - * core.autocrlf - * Setting this variable to "true" is almost the same as setting - * the text attribute to "auto" on all files except that text files are - * not guaranteed to be normalized: files that contain CRLF in the - * repository will not be touched. Use this setting if you want to have - * CRLF line endings in your working directory even though the repository - * does not have normalized line endings. This variable can be set to input, - * in which case no output conversion is performed. - */ -static git_configmap _configmap_autocrlf[] = { - {GIT_CONFIGMAP_FALSE, NULL, GIT_AUTO_CRLF_FALSE}, - {GIT_CONFIGMAP_TRUE, NULL, GIT_AUTO_CRLF_TRUE}, - {GIT_CONFIGMAP_STRING, "input", GIT_AUTO_CRLF_INPUT} -}; - -static git_configmap _configmap_safecrlf[] = { - {GIT_CONFIGMAP_FALSE, NULL, GIT_SAFE_CRLF_FALSE}, - {GIT_CONFIGMAP_TRUE, NULL, GIT_SAFE_CRLF_FAIL}, - {GIT_CONFIGMAP_STRING, "warn", GIT_SAFE_CRLF_WARN} -}; - -static git_configmap _configmap_logallrefupdates[] = { - {GIT_CONFIGMAP_FALSE, NULL, GIT_LOGALLREFUPDATES_FALSE}, - {GIT_CONFIGMAP_TRUE, NULL, GIT_LOGALLREFUPDATES_TRUE}, - {GIT_CONFIGMAP_STRING, "always", GIT_LOGALLREFUPDATES_ALWAYS}, -}; - -static git_configmap _configmap_abbrev[] = { - {GIT_CONFIGMAP_INT32, NULL, 0}, - {GIT_CONFIGMAP_FALSE, NULL, GIT_ABBREV_FALSE}, - {GIT_CONFIGMAP_STRING, "auto", GIT_ABBREV_DEFAULT} -}; - -static struct map_data _configmaps[] = { - {"core.autocrlf", _configmap_autocrlf, ARRAY_SIZE(_configmap_autocrlf), GIT_AUTO_CRLF_DEFAULT}, - {"core.eol", _configmap_eol, ARRAY_SIZE(_configmap_eol), GIT_EOL_DEFAULT}, - {"core.symlinks", NULL, 0, GIT_SYMLINKS_DEFAULT }, - {"core.ignorecase", NULL, 0, GIT_IGNORECASE_DEFAULT }, - {"core.filemode", NULL, 0, GIT_FILEMODE_DEFAULT }, - {"core.ignorestat", NULL, 0, GIT_IGNORESTAT_DEFAULT }, - {"core.trustctime", NULL, 0, GIT_TRUSTCTIME_DEFAULT }, - {"core.abbrev", _configmap_abbrev, ARRAY_SIZE(_configmap_abbrev), GIT_ABBREV_DEFAULT }, - {"core.precomposeunicode", NULL, 0, GIT_PRECOMPOSE_DEFAULT }, - {"core.safecrlf", _configmap_safecrlf, ARRAY_SIZE(_configmap_safecrlf), GIT_SAFE_CRLF_DEFAULT}, - {"core.logallrefupdates", _configmap_logallrefupdates, ARRAY_SIZE(_configmap_logallrefupdates), GIT_LOGALLREFUPDATES_DEFAULT}, - {"core.protecthfs", NULL, 0, GIT_PROTECTHFS_DEFAULT }, - {"core.protectntfs", NULL, 0, GIT_PROTECTNTFS_DEFAULT }, - {"core.fsyncobjectfiles", NULL, 0, GIT_FSYNCOBJECTFILES_DEFAULT }, - {"core.longpaths", NULL, 0, GIT_LONGPATHS_DEFAULT }, -}; - -int git_config__configmap_lookup(int *out, git_config *config, git_configmap_item item) -{ - int error = 0; - struct map_data *data = &_configmaps[(int)item]; - git_config_entry *entry; - - if ((error = git_config__lookup_entry(&entry, config, data->name, false)) < 0) - return error; - - if (!entry) - *out = data->default_value; - else if (data->maps) - error = git_config_lookup_map_value( - out, data->maps, data->map_count, entry->value); - else - error = git_config_parse_bool(out, entry->value); - - git_config_entry_free(entry); - return error; -} - -int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item) -{ - intptr_t value = (intptr_t)git_atomic_load(repo->configmap_cache[(int)item]); - - *out = (int)value; - - if (value == GIT_CONFIGMAP_NOT_CACHED) { - git_config *config; - intptr_t oldval = value; - int error; - - if ((error = git_repository_config__weakptr(&config, repo)) < 0 || - (error = git_config__configmap_lookup(out, config, item)) < 0) - return error; - - value = *out; - git_atomic_compare_and_swap(&repo->configmap_cache[(int)item], (void *)oldval, (void *)value); - } - - return 0; -} - -void git_repository__configmap_lookup_cache_clear(git_repository *repo) -{ - int i; - - for (i = 0; i < GIT_CONFIGMAP_CACHE_MAX; ++i) - repo->configmap_cache[i] = GIT_CONFIGMAP_NOT_CACHED; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_file.c b/vendor/libgit2-sys/libgit2/src/libgit2/config_file.c deleted file mode 100644 index 870b137..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_file.c +++ /dev/null @@ -1,1212 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "config.h" - -#include "git2/config.h" -#include "git2/sys/config.h" - -#include "array.h" -#include "str.h" -#include "config_backend.h" -#include "config_list.h" -#include "config_parse.h" -#include "filebuf.h" -#include "regexp.h" -#include "sysdir.h" -#include "wildmatch.h" -#include "hash.h" - -/* Max depth for [include] directives */ -#define MAX_INCLUDE_DEPTH 10 - -#define CONFIG_FILE_TYPE "file" - -typedef struct config_file { - git_futils_filestamp stamp; - unsigned char checksum[GIT_HASH_SHA256_SIZE]; - char *path; - git_array_t(struct config_file) includes; -} config_file; - -typedef struct { - git_config_backend parent; - git_mutex values_mutex; - git_config_list *config_list; - const git_repository *repo; - git_config_level_t level; - - git_array_t(git_config_parser) readers; - - bool locked; - git_filebuf locked_buf; - git_str locked_content; - - config_file file; -} config_file_backend; - -typedef struct { - const git_repository *repo; - config_file *file; - git_config_list *config_list; - git_config_level_t level; - unsigned int depth; -} config_file_parse_data; - -static int config_file_read(git_config_list *config_list, const git_repository *repo, config_file *file, git_config_level_t level, int depth); -static int config_file_read_buffer(git_config_list *config_list, const git_repository *repo, config_file *file, git_config_level_t level, int depth, const char *buf, size_t buflen); -static int config_file_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char *value); -static char *escape_value(const char *ptr); - -/** - * Take the current values map from the backend and increase its - * refcount. This is its own function to make sure we use the mutex to - * avoid the map pointer from changing under us. - */ -static int config_file_take_list(git_config_list **out, config_file_backend *b) -{ - int error; - - if ((error = git_mutex_lock(&b->values_mutex)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock config backend"); - return error; - } - - git_config_list_incref(b->config_list); - *out = b->config_list; - - git_mutex_unlock(&b->values_mutex); - - return 0; -} - -static void config_file_clear(config_file *file) -{ - config_file *include; - uint32_t i; - - if (file == NULL) - return; - - git_array_foreach(file->includes, i, include) { - config_file_clear(include); - } - git_array_clear(file->includes); - - git__free(file->path); -} - -static int config_file_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo) -{ - config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - int res; - - b->level = level; - b->repo = repo; - - if ((res = git_config_list_new(&b->config_list)) < 0) - return res; - - if (!git_fs_path_exists(b->file.path)) - return 0; - - /* - * git silently ignores configuration files that are not - * readable. We emulate that behavior. This is particularly - * important for sandboxed applications on macOS where the - * git configuration files may not be readable. - */ - if (p_access(b->file.path, R_OK) < 0) - return GIT_ENOTFOUND; - - if (res < 0 || (res = config_file_read(b->config_list, repo, &b->file, level, 0)) < 0) { - git_config_list_free(b->config_list); - b->config_list = NULL; - } - - return res; -} - -static int config_file_is_modified(int *modified, config_file *file) -{ - config_file *include; - git_str buf = GIT_STR_INIT; - unsigned char checksum[GIT_HASH_SHA256_SIZE]; - uint32_t i; - int error = 0; - - *modified = 0; - - if (!git_futils_filestamp_check(&file->stamp, file->path)) - goto check_includes; - - if ((error = git_futils_readbuffer(&buf, file->path)) < 0) - goto out; - - if ((error = git_hash_buf(checksum, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA256)) < 0) - goto out; - - if (memcmp(checksum, file->checksum, GIT_HASH_SHA256_SIZE) != 0) { - *modified = 1; - goto out; - } - -check_includes: - git_array_foreach(file->includes, i, include) { - if ((error = config_file_is_modified(modified, include)) < 0 || *modified) - goto out; - } - -out: - git_str_dispose(&buf); - - return error; -} - -static void config_file_clear_includes(config_file_backend *cfg) -{ - config_file *include; - uint32_t i; - - git_array_foreach(cfg->file.includes, i, include) - config_file_clear(include); - git_array_clear(cfg->file.includes); -} - -static int config_file_set_entries(git_config_backend *cfg, git_config_list *config_list) -{ - config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - git_config_list *old = NULL; - int error; - - if (b->parent.readonly) { - git_error_set(GIT_ERROR_CONFIG, "this backend is read-only"); - return -1; - } - - if ((error = git_mutex_lock(&b->values_mutex)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock config backend"); - goto out; - } - - old = b->config_list; - b->config_list = config_list; - - git_mutex_unlock(&b->values_mutex); - -out: - git_config_list_free(old); - return error; -} - -static int config_file_refresh_from_buffer(git_config_backend *cfg, const char *buf, size_t buflen) -{ - config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - git_config_list *config_list = NULL; - int error; - - config_file_clear_includes(b); - - if ((error = git_config_list_new(&config_list)) < 0 || - (error = config_file_read_buffer(config_list, b->repo, &b->file, - b->level, 0, buf, buflen)) < 0 || - (error = config_file_set_entries(cfg, config_list)) < 0) - goto out; - - config_list = NULL; -out: - git_config_list_free(config_list); - return error; -} - -static int config_file_refresh(git_config_backend *cfg) -{ - config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - git_config_list *config_list = NULL; - int error, modified; - - if (cfg->readonly) - return 0; - - if ((error = config_file_is_modified(&modified, &b->file)) < 0 && error != GIT_ENOTFOUND) - goto out; - - if (!modified) - return 0; - - config_file_clear_includes(b); - - if ((error = git_config_list_new(&config_list)) < 0 || - (error = config_file_read(config_list, b->repo, &b->file, b->level, 0)) < 0 || - (error = config_file_set_entries(cfg, config_list)) < 0) - goto out; - - config_list = NULL; -out: - git_config_list_free(config_list); - - return (error == GIT_ENOTFOUND) ? 0 : error; -} - -static void config_file_free(git_config_backend *_backend) -{ - config_file_backend *backend = GIT_CONTAINER_OF(_backend, config_file_backend, parent); - - if (backend == NULL) - return; - - config_file_clear(&backend->file); - git_config_list_free(backend->config_list); - git_mutex_free(&backend->values_mutex); - git__free(backend); -} - -static int config_file_iterator( - git_config_iterator **iter, - struct git_config_backend *backend) -{ - config_file_backend *b = GIT_CONTAINER_OF(backend, config_file_backend, parent); - git_config_list *dupped = NULL, *config_list = NULL; - int error; - - if ((error = config_file_refresh(backend)) < 0 || - (error = config_file_take_list(&config_list, b)) < 0 || - (error = git_config_list_dup(&dupped, config_list)) < 0 || - (error = git_config_list_iterator_new(iter, dupped)) < 0) - goto out; - -out: - /* Let iterator delete duplicated config_list when it's done */ - git_config_list_free(config_list); - git_config_list_free(dupped); - return error; -} - -static int config_file_snapshot(git_config_backend **out, git_config_backend *backend) -{ - return git_config_backend_snapshot(out, backend); -} - -static int config_file_set(git_config_backend *cfg, const char *name, const char *value) -{ - config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - git_config_list *config_list; - git_config_list_entry *existing; - char *key, *esc_value = NULL; - int error; - - if ((error = git_config__normalize_name(name, &key)) < 0) - return error; - - if ((error = config_file_take_list(&config_list, b)) < 0) - return error; - - /* Check whether we'd be modifying an included or multivar key */ - if ((error = git_config_list_get_unique(&existing, config_list, key)) < 0) { - if (error != GIT_ENOTFOUND) - goto out; - error = 0; - } else if ((!existing->base.entry.value && !value) || - (existing->base.entry.value && value && !strcmp(existing->base.entry.value, value))) { - /* don't update if old and new values already match */ - error = 0; - goto out; - } - - /* No early returns due to sanity checks, let's write it out and refresh */ - if (value) { - esc_value = escape_value(value); - GIT_ERROR_CHECK_ALLOC(esc_value); - } - - if ((error = config_file_write(b, name, key, NULL, esc_value)) < 0) - goto out; - -out: - git_config_list_free(config_list); - git__free(esc_value); - git__free(key); - return error; -} - -/* - * Internal function that actually gets the value in string form - */ -static int config_file_get( - git_config_backend *cfg, - const char *key, - git_config_backend_entry **out) -{ - config_file_backend *h = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - git_config_list *config_list = NULL; - git_config_list_entry *entry; - int error = 0; - - if (!h->parent.readonly && ((error = config_file_refresh(cfg)) < 0)) - return error; - - if ((error = config_file_take_list(&config_list, h)) < 0) - return error; - - if ((error = (git_config_list_get(&entry, config_list, key))) < 0) { - git_config_list_free(config_list); - return error; - } - - *out = &entry->base; - - return 0; -} - -static int config_file_set_multivar( - git_config_backend *cfg, const char *name, const char *regexp, const char *value) -{ - config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - git_regexp preg; - int result; - char *key; - - GIT_ASSERT_ARG(regexp); - - if ((result = git_config__normalize_name(name, &key)) < 0) - return result; - - if ((result = git_regexp_compile(&preg, regexp, 0)) < 0) - goto out; - - /* If we do have it, set call config_file_write() and reload */ - if ((result = config_file_write(b, name, key, &preg, value)) < 0) - goto out; - -out: - git__free(key); - git_regexp_dispose(&preg); - - return result; -} - -static int config_file_delete(git_config_backend *cfg, const char *name) -{ - config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - git_config_list *config_list = NULL; - git_config_list_entry *entry; - char *key = NULL; - int error; - - if ((error = git_config__normalize_name(name, &key)) < 0) - goto out; - - if ((error = config_file_take_list(&config_list, b)) < 0) - goto out; - - /* Check whether we'd be modifying an included or multivar key */ - if ((error = git_config_list_get_unique(&entry, config_list, key)) < 0) { - if (error == GIT_ENOTFOUND) - git_error_set(GIT_ERROR_CONFIG, "could not find key '%s' to delete", name); - goto out; - } - - if ((error = config_file_write(b, name, entry->base.entry.name, NULL, NULL)) < 0) - goto out; - -out: - git_config_list_free(config_list); - git__free(key); - return error; -} - -static int config_file_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp) -{ - config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent); - git_config_list *config_list = NULL; - git_config_list_entry *entry = NULL; - git_regexp preg = GIT_REGEX_INIT; - char *key = NULL; - int result; - - if ((result = git_config__normalize_name(name, &key)) < 0) - goto out; - - if ((result = config_file_take_list(&config_list, b)) < 0) - goto out; - - if ((result = git_config_list_get(&entry, config_list, key)) < 0) { - if (result == GIT_ENOTFOUND) - git_error_set(GIT_ERROR_CONFIG, "could not find key '%s' to delete", name); - goto out; - } - - if ((result = git_regexp_compile(&preg, regexp, 0)) < 0) - goto out; - - if ((result = config_file_write(b, name, key, &preg, NULL)) < 0) - goto out; - -out: - git_config_list_free(config_list); - git__free(key); - git_regexp_dispose(&preg); - return result; -} - -static int config_file_lock(git_config_backend *_cfg) -{ - config_file_backend *cfg = GIT_CONTAINER_OF(_cfg, config_file_backend, parent); - int error; - - if ((error = git_filebuf_open(&cfg->locked_buf, cfg->file.path, 0, GIT_CONFIG_FILE_MODE)) < 0) - return error; - - error = git_futils_readbuffer(&cfg->locked_content, cfg->file.path); - if (error < 0 && error != GIT_ENOTFOUND) { - git_filebuf_cleanup(&cfg->locked_buf); - return error; - } - - cfg->locked = true; - return 0; - -} - -static int config_file_unlock(git_config_backend *_cfg, int success) -{ - config_file_backend *cfg = GIT_CONTAINER_OF(_cfg, config_file_backend, parent); - int error = 0; - - if (success) { - git_filebuf_write(&cfg->locked_buf, cfg->locked_content.ptr, cfg->locked_content.size); - error = git_filebuf_commit(&cfg->locked_buf); - } - - git_filebuf_cleanup(&cfg->locked_buf); - git_str_dispose(&cfg->locked_content); - cfg->locked = false; - - return error; -} - -int git_config_backend_from_file(git_config_backend **out, const char *path) -{ - config_file_backend *backend; - - backend = git__calloc(1, sizeof(config_file_backend)); - GIT_ERROR_CHECK_ALLOC(backend); - - backend->parent.version = GIT_CONFIG_BACKEND_VERSION; - git_mutex_init(&backend->values_mutex); - - backend->file.path = git__strdup(path); - GIT_ERROR_CHECK_ALLOC(backend->file.path); - git_array_init(backend->file.includes); - - backend->parent.open = config_file_open; - backend->parent.get = config_file_get; - backend->parent.set = config_file_set; - backend->parent.set_multivar = config_file_set_multivar; - backend->parent.del = config_file_delete; - backend->parent.del_multivar = config_file_delete_multivar; - backend->parent.iterator = config_file_iterator; - backend->parent.snapshot = config_file_snapshot; - backend->parent.lock = config_file_lock; - backend->parent.unlock = config_file_unlock; - backend->parent.free = config_file_free; - - *out = (git_config_backend *)backend; - - return 0; -} - -static int included_path(git_str *out, const char *dir, const char *path) -{ - /* From the user's home */ - if (path[0] == '~' && path[1] == '/') - return git_sysdir_expand_homedir_file(out, &path[1]); - - return git_fs_path_join_unrooted(out, path, dir, NULL); -} - -/* Escape the values to write them to the file */ -static char *escape_value(const char *ptr) -{ - git_str buf; - size_t len; - const char *esc; - - GIT_ASSERT_ARG_WITH_RETVAL(ptr, NULL); - - len = strlen(ptr); - if (!len) - return git__calloc(1, sizeof(char)); - - if (git_str_init(&buf, len) < 0) - return NULL; - - while (*ptr != '\0') { - if ((esc = strchr(git_config_escaped, *ptr)) != NULL) { - git_str_putc(&buf, '\\'); - git_str_putc(&buf, git_config_escapes[esc - git_config_escaped]); - } else { - git_str_putc(&buf, *ptr); - } - ptr++; - } - - if (git_str_oom(&buf)) - return NULL; - - return git_str_detach(&buf); -} - -static int parse_include(config_file_parse_data *parse_data, const char *file) -{ - config_file *include; - git_str path = GIT_STR_INIT; - char *dir; - int result; - - if (!file) - return 0; - - if ((result = git_fs_path_dirname_r(&path, parse_data->file->path)) < 0) - return result; - - dir = git_str_detach(&path); - result = included_path(&path, dir, file); - git__free(dir); - - if (result < 0) - return result; - - include = git_array_alloc(parse_data->file->includes); - GIT_ERROR_CHECK_ALLOC(include); - memset(include, 0, sizeof(*include)); - git_array_init(include->includes); - include->path = git_str_detach(&path); - - result = config_file_read(parse_data->config_list, parse_data->repo, include, - parse_data->level, parse_data->depth+1); - - if (result == GIT_ENOTFOUND) { - git_error_clear(); - result = 0; - } - - return result; -} - -static int do_match_gitdir( - int *matches, - const git_repository *repo, - const char *cfg_file, - const char *condition, - bool case_insensitive) -{ - git_str pattern = GIT_STR_INIT, gitdir = GIT_STR_INIT; - int error; - - if (condition[0] == '.' && git_fs_path_is_dirsep(condition[1])) { - git_fs_path_dirname_r(&pattern, cfg_file); - git_str_joinpath(&pattern, pattern.ptr, condition + 2); - } else if (condition[0] == '~' && git_fs_path_is_dirsep(condition[1])) - git_sysdir_expand_homedir_file(&pattern, condition + 1); - else if (!git_fs_path_is_absolute(condition)) - git_str_joinpath(&pattern, "**", condition); - else - git_str_sets(&pattern, condition); - - if (git_fs_path_is_dirsep(condition[strlen(condition) - 1])) - git_str_puts(&pattern, "**"); - - if (git_str_oom(&pattern)) { - error = -1; - goto out; - } - - if ((error = git_repository__item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0) - goto out; - - if (git_fs_path_is_dirsep(gitdir.ptr[gitdir.size - 1])) - git_str_truncate(&gitdir, gitdir.size - 1); - - *matches = wildmatch(pattern.ptr, gitdir.ptr, - WM_PATHNAME | (case_insensitive ? WM_CASEFOLD : 0)) == WM_MATCH; -out: - git_str_dispose(&pattern); - git_str_dispose(&gitdir); - return error; -} - -static int conditional_match_gitdir( - int *matches, - const git_repository *repo, - const char *cfg_file, - const char *value) -{ - return do_match_gitdir(matches, repo, cfg_file, value, false); -} - -static int conditional_match_gitdir_i( - int *matches, - const git_repository *repo, - const char *cfg_file, - const char *value) -{ - return do_match_gitdir(matches, repo, cfg_file, value, true); -} - -static int conditional_match_onbranch( - int *matches, - const git_repository *repo, - const char *cfg_file, - const char *condition) -{ - git_str reference = GIT_STR_INIT, buf = GIT_STR_INIT; - int error; - - GIT_UNUSED(cfg_file); - - /* - * NOTE: you cannot use `git_repository_head` here. Looking up the - * HEAD reference will create the ODB, which causes us to read the - * repo's config for keys like core.precomposeUnicode. As we're - * just parsing the config right now, though, this would result in - * an endless recursion. - */ - - if ((error = git_str_joinpath(&buf, git_repository_path(repo), GIT_HEAD_FILE)) < 0 || - (error = git_futils_readbuffer(&reference, buf.ptr)) < 0) - goto out; - git_str_rtrim(&reference); - - if (git__strncmp(reference.ptr, GIT_SYMREF, strlen(GIT_SYMREF))) - goto out; - git_str_consume(&reference, reference.ptr + strlen(GIT_SYMREF)); - - if (git__strncmp(reference.ptr, GIT_REFS_HEADS_DIR, strlen(GIT_REFS_HEADS_DIR))) - goto out; - git_str_consume(&reference, reference.ptr + strlen(GIT_REFS_HEADS_DIR)); - - /* - * If the condition ends with a '/', then we should treat it as if - * it had '**' appended. - */ - if ((error = git_str_sets(&buf, condition)) < 0) - goto out; - if (git_fs_path_is_dirsep(condition[strlen(condition) - 1]) && - (error = git_str_puts(&buf, "**")) < 0) - goto out; - - *matches = wildmatch(buf.ptr, reference.ptr, WM_PATHNAME) == WM_MATCH; -out: - git_str_dispose(&reference); - git_str_dispose(&buf); - - return error; - -} - -static const struct { - const char *prefix; - int (*matches)(int *matches, const git_repository *repo, const char *cfg, const char *value); -} conditions[] = { - { "gitdir:", conditional_match_gitdir }, - { "gitdir/i:", conditional_match_gitdir_i }, - { "onbranch:", conditional_match_onbranch } -}; - -static int parse_conditional_include(config_file_parse_data *parse_data, const char *section, const char *file) -{ - char *condition; - size_t section_len, i; - int error = 0, matches; - - if (!parse_data->repo || !file) - return 0; - - section_len = strlen(section); - - /* - * We checked that the string starts with `includeIf.` and ends - * in `.path` to get here. Make sure it consists of more. - */ - if (section_len < CONST_STRLEN("includeIf.") + CONST_STRLEN(".path")) - return 0; - - condition = git__substrdup(section + CONST_STRLEN("includeIf."), - section_len - CONST_STRLEN("includeIf.") - CONST_STRLEN(".path")); - - GIT_ERROR_CHECK_ALLOC(condition); - - for (i = 0; i < ARRAY_SIZE(conditions); i++) { - if (git__prefixcmp(condition, conditions[i].prefix)) - continue; - - if ((error = conditions[i].matches(&matches, - parse_data->repo, - parse_data->file->path, - condition + strlen(conditions[i].prefix))) < 0) - break; - - if (matches) - error = parse_include(parse_data, file); - - break; - } - - git__free(condition); - return error; -} - -static int read_on_variable( - git_config_parser *reader, - const char *current_section, - const char *var_name, - const char *var_value, - const char *line, - size_t line_len, - void *data) -{ - config_file_parse_data *parse_data = (config_file_parse_data *)data; - git_str buf = GIT_STR_INIT; - git_config_list_entry *entry; - const char *c; - int result = 0; - - GIT_UNUSED(reader); - GIT_UNUSED(line); - GIT_UNUSED(line_len); - - if (current_section) { - /* TODO: Once warnings lang, we should likely warn - * here. Git appears to warn in most cases if it sees - * un-namespaced config options. - */ - git_str_puts(&buf, current_section); - git_str_putc(&buf, '.'); - } - - for (c = var_name; *c; c++) - git_str_putc(&buf, git__tolower(*c)); - - if (git_str_oom(&buf)) - return -1; - - entry = git__calloc(1, sizeof(git_config_list_entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->base.entry.name = git_str_detach(&buf); - GIT_ERROR_CHECK_ALLOC(entry->base.entry.name); - - if (var_value) { - entry->base.entry.value = git__strdup(var_value); - GIT_ERROR_CHECK_ALLOC(entry->base.entry.value); - } - - entry->base.entry.backend_type = git_config_list_add_string(parse_data->config_list, CONFIG_FILE_TYPE); - GIT_ERROR_CHECK_ALLOC(entry->base.entry.backend_type); - - entry->base.entry.origin_path = git_config_list_add_string(parse_data->config_list, parse_data->file->path); - GIT_ERROR_CHECK_ALLOC(entry->base.entry.origin_path); - - entry->base.entry.level = parse_data->level; - entry->base.entry.include_depth = parse_data->depth; - entry->base.free = git_config_list_entry_free; - entry->config_list = parse_data->config_list; - - if ((result = git_config_list_append(parse_data->config_list, entry)) < 0) - return result; - - result = 0; - - /* Add or append the new config option */ - if (!git__strcmp(entry->base.entry.name, "include.path")) - result = parse_include(parse_data, entry->base.entry.value); - else if (!git__prefixcmp(entry->base.entry.name, "includeif.") && - !git__suffixcmp(entry->base.entry.name, ".path")) - result = parse_conditional_include(parse_data, entry->base.entry.name, entry->base.entry.value); - - return result; -} - -static int config_file_read_buffer( - git_config_list *config_list, - const git_repository *repo, - config_file *file, - git_config_level_t level, - int depth, - const char *buf, - size_t buflen) -{ - config_file_parse_data parse_data; - git_config_parser reader; - int error; - - if (depth >= MAX_INCLUDE_DEPTH) { - git_error_set(GIT_ERROR_CONFIG, "maximum config include depth reached"); - return -1; - } - - /* Initialize the reading position */ - reader.path = file->path; - git_parse_ctx_init(&reader.ctx, buf, buflen); - - /* If the file is empty, there's nothing for us to do */ - if (!reader.ctx.content || *reader.ctx.content == '\0') { - error = 0; - goto out; - } - - parse_data.repo = repo; - parse_data.file = file; - parse_data.config_list = config_list; - parse_data.level = level; - parse_data.depth = depth; - - error = git_config_parse(&reader, NULL, read_on_variable, NULL, NULL, &parse_data); - -out: - return error; -} - -static int config_file_read( - git_config_list *config_list, - const git_repository *repo, - config_file *file, - git_config_level_t level, - int depth) -{ - git_str contents = GIT_STR_INIT; - struct stat st; - int error; - - if (p_stat(file->path, &st) < 0) { - error = git_fs_path_set_error(errno, file->path, "stat"); - goto out; - } - - if ((error = git_futils_readbuffer(&contents, file->path)) < 0) - goto out; - - git_futils_filestamp_set_from_stat(&file->stamp, &st); - if ((error = git_hash_buf(file->checksum, contents.ptr, contents.size, GIT_HASH_ALGORITHM_SHA256)) < 0) - goto out; - - if ((error = config_file_read_buffer(config_list, repo, file, level, depth, - contents.ptr, contents.size)) < 0) - goto out; - -out: - git_str_dispose(&contents); - return error; -} - -static int write_section(git_str *fbuf, const char *key) -{ - int result; - const char *dot; - git_str buf = GIT_STR_INIT; - - /* All of this just for [section "subsection"] */ - dot = strchr(key, '.'); - git_str_putc(&buf, '['); - if (dot == NULL) { - git_str_puts(&buf, key); - } else { - char *escaped; - git_str_put(&buf, key, dot - key); - escaped = escape_value(dot + 1); - GIT_ERROR_CHECK_ALLOC(escaped); - git_str_printf(&buf, " \"%s\"", escaped); - git__free(escaped); - } - git_str_puts(&buf, "]\n"); - - if (git_str_oom(&buf)) - return -1; - - result = git_str_put(fbuf, git_str_cstr(&buf), buf.size); - git_str_dispose(&buf); - - return result; -} - -static const char *quotes_for_value(const char *value) -{ - const char *ptr; - - if (value[0] == ' ' || value[0] == '\0') - return "\""; - - for (ptr = value; *ptr; ++ptr) { - if (*ptr == ';' || *ptr == '#') - return "\""; - } - - if (ptr[-1] == ' ') - return "\""; - - return ""; -} - -struct write_data { - git_str *buf; - git_str buffered_comment; - unsigned int in_section : 1, - preg_replaced : 1; - const char *orig_section; - const char *section; - const char *orig_name; - const char *name; - const git_regexp *preg; - const char *value; -}; - -static int write_line_to(git_str *buf, const char *line, size_t line_len) -{ - int result = git_str_put(buf, line, line_len); - - if (!result && line_len && line[line_len-1] != '\n') - result = git_str_printf(buf, "\n"); - - return result; -} - -static int write_line(struct write_data *write_data, const char *line, size_t line_len) -{ - return write_line_to(write_data->buf, line, line_len); -} - -static int write_value(struct write_data *write_data) -{ - const char *q; - int result; - - q = quotes_for_value(write_data->value); - result = git_str_printf(write_data->buf, - "\t%s = %s%s%s\n", write_data->orig_name, q, write_data->value, q); - - /* If we are updating a single name/value, we're done. Setting `value` - * to `NULL` will prevent us from trying to write it again later (in - * `write_on_section`) if we see the same section repeated. - */ - if (!write_data->preg) - write_data->value = NULL; - - return result; -} - -static int write_on_section( - git_config_parser *reader, - const char *current_section, - const char *line, - size_t line_len, - void *data) -{ - struct write_data *write_data = (struct write_data *)data; - int result = 0; - - GIT_UNUSED(reader); - - /* If we were previously in the correct section (but aren't anymore) - * and haven't written our value (for a simple name/value set, not - * a multivar), then append it to the end of the section before writing - * the new one. - */ - if (write_data->in_section && !write_data->preg && write_data->value) - result = write_value(write_data); - - write_data->in_section = strcmp(current_section, write_data->section) == 0; - - /* - * If there were comments just before this section, dump them as well. - */ - if (!result) { - result = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size); - git_str_clear(&write_data->buffered_comment); - } - - if (!result) - result = write_line(write_data, line, line_len); - - return result; -} - -static int write_on_variable( - git_config_parser *reader, - const char *current_section, - const char *var_name, - const char *var_value, - const char *line, - size_t line_len, - void *data) -{ - struct write_data *write_data = (struct write_data *)data; - bool has_matched = false; - int error; - - GIT_UNUSED(reader); - GIT_UNUSED(current_section); - - /* - * If there were comments just before this variable, let's dump them as well. - */ - if ((error = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0) - return error; - - git_str_clear(&write_data->buffered_comment); - - /* See if we are to update this name/value pair; first examine name */ - if (write_data->in_section && - strcasecmp(write_data->name, var_name) == 0) - has_matched = true; - - /* If we have a regex to match the value, see if it matches */ - if (has_matched && write_data->preg != NULL) - has_matched = (git_regexp_match(write_data->preg, var_value) == 0); - - /* If this isn't the name/value we're looking for, simply dump the - * existing data back out and continue on. - */ - if (!has_matched) - return write_line(write_data, line, line_len); - - write_data->preg_replaced = 1; - - /* If value is NULL, we are deleting this value; write nothing. */ - if (!write_data->value) - return 0; - - return write_value(write_data); -} - -static int write_on_comment(git_config_parser *reader, const char *line, size_t line_len, void *data) -{ - struct write_data *write_data; - - GIT_UNUSED(reader); - - write_data = (struct write_data *)data; - return write_line_to(&write_data->buffered_comment, line, line_len); -} - -static int write_on_eof( - git_config_parser *reader, const char *current_section, void *data) -{ - struct write_data *write_data = (struct write_data *)data; - int result = 0; - - GIT_UNUSED(reader); - - /* - * If we've buffered comments when reaching EOF, make sure to dump them. - */ - if ((result = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0) - return result; - - /* If we are at the EOF and have not written our value (again, for a - * simple name/value set, not a multivar) then we have never seen the - * section in question and should create a new section and write the - * value. - */ - if ((!write_data->preg || !write_data->preg_replaced) && write_data->value) { - /* write the section header unless we're already in it */ - if (!current_section || strcmp(current_section, write_data->section)) - result = write_section(write_data->buf, write_data->orig_section); - - if (!result) - result = write_value(write_data); - } - - return result; -} - -/* - * This is pretty much the parsing, except we write out anything we don't have - */ -static int config_file_write( - config_file_backend *cfg, - const char *orig_key, - const char *key, - const git_regexp *preg, - const char *value) - -{ - char *orig_section = NULL, *section = NULL; - const char *orig_name, *name, *ldot; - git_str buf = GIT_STR_INIT, contents = GIT_STR_INIT; - git_config_parser parser = GIT_CONFIG_PARSER_INIT; - git_filebuf file = GIT_FILEBUF_INIT; - struct write_data write_data; - int error; - - memset(&write_data, 0, sizeof(write_data)); - - if (cfg->locked) { - error = git_str_puts(&contents, git_str_cstr(&cfg->locked_content) == NULL ? "" : git_str_cstr(&cfg->locked_content)); - } else { - if ((error = git_filebuf_open(&file, cfg->file.path, - GIT_FILEBUF_HASH_SHA256, - GIT_CONFIG_FILE_MODE)) < 0) - goto done; - - /* We need to read in our own config file */ - error = git_futils_readbuffer(&contents, cfg->file.path); - } - if (error < 0 && error != GIT_ENOTFOUND) - goto done; - - if ((git_config_parser_init(&parser, cfg->file.path, contents.ptr, contents.size)) < 0) - goto done; - - ldot = strrchr(key, '.'); - name = ldot + 1; - section = git__strndup(key, ldot - key); - GIT_ERROR_CHECK_ALLOC(section); - - ldot = strrchr(orig_key, '.'); - orig_name = ldot + 1; - orig_section = git__strndup(orig_key, ldot - orig_key); - GIT_ERROR_CHECK_ALLOC(orig_section); - - write_data.buf = &buf; - write_data.orig_section = orig_section; - write_data.section = section; - write_data.orig_name = orig_name; - write_data.name = name; - write_data.preg = preg; - write_data.value = value; - - if ((error = git_config_parse(&parser, write_on_section, write_on_variable, - write_on_comment, write_on_eof, &write_data)) < 0) - goto done; - - if (cfg->locked) { - size_t len = buf.asize; - /* Update our copy with the modified contents */ - git_str_dispose(&cfg->locked_content); - git_str_attach(&cfg->locked_content, git_str_detach(&buf), len); - } else { - git_filebuf_write(&file, git_str_cstr(&buf), git_str_len(&buf)); - - if ((error = git_filebuf_commit(&file)) < 0) - goto done; - - if ((error = config_file_refresh_from_buffer(&cfg->parent, buf.ptr, buf.size)) < 0) - goto done; - } - -done: - git__free(section); - git__free(orig_section); - git_str_dispose(&write_data.buffered_comment); - git_str_dispose(&buf); - git_str_dispose(&contents); - git_filebuf_cleanup(&file); - git_config_parser_dispose(&parser); - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_list.c b/vendor/libgit2-sys/libgit2/src/libgit2/config_list.c deleted file mode 100644 index 0e65597..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_list.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "config_list.h" -#include "hashmap_str.h" - -typedef struct config_entry_list { - struct config_entry_list *next; - struct config_entry_list *last; - git_config_list_entry *entry; -} config_entry_list; - -typedef struct { - git_config_list_entry *entry; - bool multivar; -} config_entry_map_head; - -typedef struct config_list_iterator { - git_config_iterator parent; - git_config_list *list; - config_entry_list *head; -} config_list_iterator; - -GIT_HASHMAP_STR_SETUP(git_config_list_pathmap, char *); -GIT_HASHMAP_STR_SETUP(git_config_list_headmap, config_entry_map_head *); - -struct git_config_list { - git_refcount rc; - - /* Interned strings - paths to config files or backend types */ - git_config_list_pathmap strings; - - /* Config entries */ - git_config_list_headmap map; - config_entry_list *entries; -}; - -int git_config_list_new(git_config_list **out) -{ - git_config_list *config_list; - - config_list = git__calloc(1, sizeof(git_config_list)); - GIT_ERROR_CHECK_ALLOC(config_list); - GIT_REFCOUNT_INC(config_list); - - *out = config_list; - return 0; -} - -int git_config_list_dup_entry(git_config_list *config_list, const git_config_entry *entry) -{ - git_config_list_entry *duplicated; - int error; - - duplicated = git__calloc(1, sizeof(git_config_list_entry)); - GIT_ERROR_CHECK_ALLOC(duplicated); - - duplicated->base.entry.name = git__strdup(entry->name); - GIT_ERROR_CHECK_ALLOC(duplicated->base.entry.name); - - if (entry->value) { - duplicated->base.entry.value = git__strdup(entry->value); - GIT_ERROR_CHECK_ALLOC(duplicated->base.entry.value); - } - - duplicated->base.entry.backend_type = git_config_list_add_string(config_list, entry->backend_type); - GIT_ERROR_CHECK_ALLOC(duplicated->base.entry.backend_type); - - if (entry->origin_path) { - duplicated->base.entry.origin_path = git_config_list_add_string(config_list, entry->origin_path); - GIT_ERROR_CHECK_ALLOC(duplicated->base.entry.origin_path); - } - - duplicated->base.entry.level = entry->level; - duplicated->base.entry.include_depth = entry->include_depth; - duplicated->base.free = git_config_list_entry_free; - duplicated->config_list = config_list; - - if ((error = git_config_list_append(config_list, duplicated)) < 0) - goto out; - -out: - if (error && duplicated) { - git__free((char *) duplicated->base.entry.name); - git__free((char *) duplicated->base.entry.value); - git__free(duplicated); - } - return error; -} - -int git_config_list_dup(git_config_list **out, git_config_list *config_list) -{ - git_config_list *result = NULL; - config_entry_list *head; - int error; - - if ((error = git_config_list_new(&result)) < 0) - goto out; - - for (head = config_list->entries; head; head = head->next) - if ((git_config_list_dup_entry(result, &head->entry->base.entry)) < 0) - goto out; - - *out = result; - result = NULL; - -out: - git_config_list_free(result); - return error; -} - -void git_config_list_incref(git_config_list *config_list) -{ - GIT_REFCOUNT_INC(config_list); -} - -static void config_list_free(git_config_list *config_list) -{ - config_entry_list *entry_list = NULL, *next; - config_entry_map_head *head; - char *str; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - while (git_config_list_pathmap_iterate(&iter, NULL, &str, &config_list->strings) == 0) - git__free(str); - - git_config_list_pathmap_dispose(&config_list->strings); - - iter = GIT_HASHMAP_ITER_INIT; - while (git_config_list_headmap_iterate(&iter, NULL, &head, &config_list->map) == 0) { - git__free((char *) head->entry->base.entry.name); - git__free(head); - } - git_config_list_headmap_dispose(&config_list->map); - - entry_list = config_list->entries; - while (entry_list != NULL) { - next = entry_list->next; - git__free((char *) entry_list->entry->base.entry.value); - git__free(entry_list->entry); - git__free(entry_list); - entry_list = next; - } - - git__free(config_list); -} - -void git_config_list_free(git_config_list *config_list) -{ - if (config_list) - GIT_REFCOUNT_DEC(config_list, config_list_free); -} - -int git_config_list_append(git_config_list *config_list, git_config_list_entry *entry) -{ - config_entry_list *list_head; - config_entry_map_head *map_head; - - if (git_config_list_headmap_get(&map_head, &config_list->map, entry->base.entry.name) == 0) { - map_head->multivar = true; - /* - * This is a micro-optimization for configuration files - * with a lot of same keys. As for multivars the entry's - * key will be the same for all list, we can just free - * all except the first entry's name and just re-use it. - */ - git__free((char *) entry->base.entry.name); - entry->base.entry.name = map_head->entry->base.entry.name; - } else { - map_head = git__calloc(1, sizeof(*map_head)); - if ((git_config_list_headmap_put(&config_list->map, entry->base.entry.name, map_head)) < 0) - return -1; - } - map_head->entry = entry; - - list_head = git__calloc(1, sizeof(config_entry_list)); - GIT_ERROR_CHECK_ALLOC(list_head); - list_head->entry = entry; - - if (config_list->entries) - config_list->entries->last->next = list_head; - else - config_list->entries = list_head; - config_list->entries->last = list_head; - - return 0; -} - -int git_config_list_get(git_config_list_entry **out, git_config_list *config_list, const char *key) -{ - config_entry_map_head *entry; - - if (git_config_list_headmap_get(&entry, &config_list->map, key) != 0) - return GIT_ENOTFOUND; - - *out = entry->entry; - return 0; -} - -int git_config_list_get_unique(git_config_list_entry **out, git_config_list *config_list, const char *key) -{ - config_entry_map_head *entry; - - if (git_config_list_headmap_get(&entry, &config_list->map, key) != 0) - return GIT_ENOTFOUND; - - if (entry->multivar) { - git_error_set(GIT_ERROR_CONFIG, "entry is not unique due to being a multivar"); - return -1; - } - - if (entry->entry->base.entry.include_depth) { - git_error_set(GIT_ERROR_CONFIG, "entry is not unique due to being included"); - return -1; - } - - *out = entry->entry; - return 0; -} - -static void config_iterator_free(git_config_iterator *iter) -{ - config_list_iterator *it = (config_list_iterator *) iter; - git_config_list_free(it->list); - git__free(it); -} - -static int config_iterator_next( - git_config_backend_entry **entry, - git_config_iterator *iter) -{ - config_list_iterator *it = (config_list_iterator *) iter; - - if (!it->head) - return GIT_ITEROVER; - - *entry = &it->head->entry->base; - it->head = it->head->next; - - return 0; -} - -int git_config_list_iterator_new(git_config_iterator **out, git_config_list *config_list) -{ - config_list_iterator *it; - - it = git__calloc(1, sizeof(config_list_iterator)); - GIT_ERROR_CHECK_ALLOC(it); - it->parent.next = config_iterator_next; - it->parent.free = config_iterator_free; - it->head = config_list->entries; - it->list = config_list; - - git_config_list_incref(config_list); - *out = &it->parent; - - return 0; -} - -/* release the map containing the entry as an equivalent to freeing it */ -void git_config_list_entry_free(git_config_backend_entry *e) -{ - git_config_list_entry *entry = (git_config_list_entry *)e; - git_config_list_free(entry->config_list); -} - -const char *git_config_list_add_string( - git_config_list *config_list, - const char *str) -{ - char *s; - - if (git_config_list_pathmap_get(&s, &config_list->strings, str) == 0) - return s; - - if ((s = git__strdup(str)) == NULL || - git_config_list_pathmap_put(&config_list->strings, s, s) < 0) - return NULL; - - return s; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_list.h b/vendor/libgit2-sys/libgit2/src/libgit2/config_list.h deleted file mode 100644 index 091a59b..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_list.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/sys/config.h" -#include "config.h" - -typedef struct git_config_list git_config_list; - -typedef struct { - git_config_backend_entry base; - git_config_list *config_list; -} git_config_list_entry; - -int git_config_list_new(git_config_list **out); -int git_config_list_dup(git_config_list **out, git_config_list *list); -int git_config_list_dup_entry(git_config_list *list, const git_config_entry *entry); -void git_config_list_incref(git_config_list *list); -void git_config_list_free(git_config_list *list); -/* Add or append the new config option */ -int git_config_list_append(git_config_list *list, git_config_list_entry *entry); -int git_config_list_get(git_config_list_entry **out, git_config_list *list, const char *key); -int git_config_list_get_unique(git_config_list_entry **out, git_config_list *list, const char *key); -int git_config_list_iterator_new(git_config_iterator **out, git_config_list *list); -const char *git_config_list_add_string(git_config_list *list, const char *str); - -void git_config_list_entry_free(git_config_backend_entry *entry); diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_mem.c b/vendor/libgit2-sys/libgit2/src/libgit2/config_mem.c deleted file mode 100644 index 7d8fa75..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_mem.c +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "config.h" - -#include "config_backend.h" -#include "config_parse.h" -#include "config_list.h" -#include "strlist.h" - -typedef struct { - git_config_backend parent; - - char *backend_type; - char *origin_path; - - git_config_list *config_list; - - /* Configuration data in the config file format */ - git_str cfg; - - /* Array of key=value pairs */ - char **values; - size_t values_len; -} config_memory_backend; - -typedef struct { - const char *backend_type; - const char *origin_path; - git_config_list *config_list; - git_config_level_t level; -} config_memory_parse_data; - -static int config_error_readonly(void) -{ - git_error_set(GIT_ERROR_CONFIG, "this backend is read-only"); - return -1; -} - -static int read_variable_cb( - git_config_parser *reader, - const char *current_section, - const char *var_name, - const char *var_value, - const char *line, - size_t line_len, - void *payload) -{ - config_memory_parse_data *parse_data = (config_memory_parse_data *) payload; - git_str buf = GIT_STR_INIT; - git_config_list_entry *entry; - const char *c; - int result; - - GIT_UNUSED(reader); - GIT_UNUSED(line); - GIT_UNUSED(line_len); - - if (current_section) { - /* TODO: Once warnings land, we should likely warn - * here. Git appears to warn in most cases if it sees - * un-namespaced config options. - */ - git_str_puts(&buf, current_section); - git_str_putc(&buf, '.'); - } - - for (c = var_name; *c; c++) - git_str_putc(&buf, git__tolower(*c)); - - if (git_str_oom(&buf)) - return -1; - - entry = git__calloc(1, sizeof(git_config_list_entry)); - GIT_ERROR_CHECK_ALLOC(entry); - entry->base.entry.name = git_str_detach(&buf); - entry->base.entry.value = var_value ? git__strdup(var_value) : NULL; - entry->base.entry.level = parse_data->level; - entry->base.entry.include_depth = 0; - entry->base.entry.backend_type = parse_data->backend_type; - entry->base.entry.origin_path = parse_data->origin_path; - entry->base.free = git_config_list_entry_free; - entry->config_list = parse_data->config_list; - - if ((result = git_config_list_append(parse_data->config_list, entry)) < 0) - return result; - - return result; -} - -static int parse_config( - config_memory_backend *memory_backend, - git_config_level_t level) -{ - git_config_parser parser = GIT_PARSE_CTX_INIT; - config_memory_parse_data parse_data; - int error; - - if ((error = git_config_parser_init(&parser, "in-memory", - memory_backend->cfg.ptr, memory_backend->cfg.size)) < 0) - goto out; - - parse_data.backend_type = git_config_list_add_string( - memory_backend->config_list, memory_backend->backend_type); - parse_data.origin_path = memory_backend->origin_path ? - git_config_list_add_string(memory_backend->config_list, - memory_backend->origin_path) : - NULL; - parse_data.config_list = memory_backend->config_list; - parse_data.level = level; - - if ((error = git_config_parse(&parser, NULL, read_variable_cb, - NULL, NULL, &parse_data)) < 0) - goto out; - -out: - git_config_parser_dispose(&parser); - return error; -} - -static int parse_values( - config_memory_backend *memory_backend, - git_config_level_t level) -{ - git_config_list_entry *entry; - const char *eql, *backend_type, *origin_path; - size_t name_len, i; - - backend_type = git_config_list_add_string( - memory_backend->config_list, memory_backend->backend_type); - GIT_ERROR_CHECK_ALLOC(backend_type); - - origin_path = memory_backend->origin_path ? - git_config_list_add_string(memory_backend->config_list, - memory_backend->origin_path) : - NULL; - - for (i = 0; i < memory_backend->values_len; i++) { - eql = strchr(memory_backend->values[i], '='); - name_len = eql - memory_backend->values[i]; - - if (name_len == 0) { - git_error_set(GIT_ERROR_CONFIG, "empty config key"); - return -1; - } - - entry = git__calloc(1, sizeof(git_config_list_entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->base.entry.name = git__strndup(memory_backend->values[i], name_len); - GIT_ERROR_CHECK_ALLOC(entry->base.entry.name); - - if (eql) { - entry->base.entry.value = git__strdup(eql + 1); - GIT_ERROR_CHECK_ALLOC(entry->base.entry.value); - } - - entry->base.entry.level = level; - entry->base.entry.include_depth = 0; - entry->base.entry.backend_type = backend_type; - entry->base.entry.origin_path = origin_path; - entry->base.free = git_config_list_entry_free; - entry->config_list = memory_backend->config_list; - - if (git_config_list_append(memory_backend->config_list, entry) < 0) - return -1; - } - - return 0; -} - -static int config_memory_open(git_config_backend *backend, git_config_level_t level, const git_repository *repo) -{ - config_memory_backend *memory_backend = (config_memory_backend *) backend; - - GIT_UNUSED(repo); - - if (memory_backend->cfg.size > 0 && - parse_config(memory_backend, level) < 0) - return -1; - - if (memory_backend->values_len > 0 && - parse_values(memory_backend, level) < 0) - return -1; - - return 0; -} - -static int config_memory_get(git_config_backend *backend, const char *key, git_config_backend_entry **out) -{ - config_memory_backend *memory_backend = (config_memory_backend *) backend; - git_config_list_entry *entry; - int error; - - if ((error = git_config_list_get(&entry, memory_backend->config_list, key)) != 0) - return error; - - git_config_list_incref(memory_backend->config_list); - *out = &entry->base; - return 0; -} - -static int config_memory_iterator( - git_config_iterator **iter, - git_config_backend *backend) -{ - config_memory_backend *memory_backend = (config_memory_backend *) backend; - git_config_list *config_list; - int error; - - if ((error = git_config_list_dup(&config_list, memory_backend->config_list)) < 0) - goto out; - - if ((error = git_config_list_iterator_new(iter, config_list)) < 0) - goto out; - -out: - /* Let iterator delete duplicated config_list when it's done */ - git_config_list_free(config_list); - return error; -} - -static int config_memory_set(git_config_backend *backend, const char *name, const char *value) -{ - GIT_UNUSED(backend); - GIT_UNUSED(name); - GIT_UNUSED(value); - return config_error_readonly(); -} - -static int config_memory_set_multivar( - git_config_backend *backend, const char *name, const char *regexp, const char *value) -{ - GIT_UNUSED(backend); - GIT_UNUSED(name); - GIT_UNUSED(regexp); - GIT_UNUSED(value); - return config_error_readonly(); -} - -static int config_memory_delete(git_config_backend *backend, const char *name) -{ - GIT_UNUSED(backend); - GIT_UNUSED(name); - return config_error_readonly(); -} - -static int config_memory_delete_multivar(git_config_backend *backend, const char *name, const char *regexp) -{ - GIT_UNUSED(backend); - GIT_UNUSED(name); - GIT_UNUSED(regexp); - return config_error_readonly(); -} - -static int config_memory_lock(git_config_backend *backend) -{ - GIT_UNUSED(backend); - return config_error_readonly(); -} - -static int config_memory_unlock(git_config_backend *backend, int success) -{ - GIT_UNUSED(backend); - GIT_UNUSED(success); - return config_error_readonly(); -} - -static void config_memory_free(git_config_backend *_backend) -{ - config_memory_backend *backend = (config_memory_backend *)_backend; - - if (backend == NULL) - return; - - git__free(backend->origin_path); - git__free(backend->backend_type); - git_config_list_free(backend->config_list); - git_strlist_free(backend->values, backend->values_len); - git_str_dispose(&backend->cfg); - git__free(backend); -} - -static config_memory_backend *config_backend_new( - git_config_backend_memory_options *opts) -{ - config_memory_backend *backend; - - if ((backend = git__calloc(1, sizeof(config_memory_backend))) == NULL) - return NULL; - - if (git_config_list_new(&backend->config_list) < 0) - goto on_error; - - backend->parent.version = GIT_CONFIG_BACKEND_VERSION; - backend->parent.readonly = 1; - backend->parent.open = config_memory_open; - backend->parent.get = config_memory_get; - backend->parent.set = config_memory_set; - backend->parent.set_multivar = config_memory_set_multivar; - backend->parent.del = config_memory_delete; - backend->parent.del_multivar = config_memory_delete_multivar; - backend->parent.iterator = config_memory_iterator; - backend->parent.lock = config_memory_lock; - backend->parent.unlock = config_memory_unlock; - backend->parent.snapshot = git_config_backend_snapshot; - backend->parent.free = config_memory_free; - - backend->backend_type = git__strdup(opts && opts->backend_type ? - opts->backend_type : "in-memory"); - - if (backend->backend_type == NULL) - goto on_error; - - if (opts && opts->origin_path && - (backend->origin_path = git__strdup(opts->origin_path)) == NULL) - goto on_error; - - return backend; - -on_error: - git_config_list_free(backend->config_list); - git__free(backend->origin_path); - git__free(backend->backend_type); - git__free(backend); - return NULL; -} - -int git_config_backend_from_string( - git_config_backend **out, - const char *cfg, - size_t len, - git_config_backend_memory_options *opts) -{ - config_memory_backend *backend; - - if ((backend = config_backend_new(opts)) == NULL) - return -1; - - if (git_str_set(&backend->cfg, cfg, len) < 0) { - git_config_list_free(backend->config_list); - git__free(backend); - return -1; - } - - *out = (git_config_backend *)backend; - return 0; -} - -int git_config_backend_from_values( - git_config_backend **out, - const char **values, - size_t len, - git_config_backend_memory_options *opts) -{ - config_memory_backend *backend; - - if ((backend = config_backend_new(opts)) == NULL) - return -1; - - if (git_strlist_copy(&backend->values, values, len) < 0) { - git_config_list_free(backend->config_list); - git__free(backend); - return -1; - } - - backend->values_len = len; - - *out = (git_config_backend *)backend; - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_parse.c b/vendor/libgit2-sys/libgit2/src/libgit2/config_parse.c deleted file mode 100644 index 390fea3..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_parse.c +++ /dev/null @@ -1,582 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "config_parse.h" - -#include - -const char *git_config_escapes = "ntb\"\\"; -const char *git_config_escaped = "\n\t\b\"\\"; - -static void set_parse_error(git_config_parser *reader, int col, const char *error_str) -{ - if (col) - git_error_set(GIT_ERROR_CONFIG, - "failed to parse config file: %s (in %s:%"PRIuZ", column %d)", - error_str, reader->path, reader->ctx.line_num, col); - else - git_error_set(GIT_ERROR_CONFIG, - "failed to parse config file: %s (in %s:%"PRIuZ")", - error_str, reader->path, reader->ctx.line_num); -} - - -GIT_INLINE(int) config_keychar(char c) -{ - return git__isalnum(c) || c == '-'; -} - -static int strip_comments(char *line, int in_quotes) -{ - int quote_count = in_quotes, backslash_count = 0; - char *ptr; - - for (ptr = line; *ptr; ++ptr) { - if (ptr[0] == '"' && ((ptr > line && ptr[-1] != '\\') || ptr == line)) - quote_count++; - - if ((ptr[0] == ';' || ptr[0] == '#') && - (quote_count % 2) == 0 && - (backslash_count % 2) == 0) { - ptr[0] = '\0'; - break; - } - - if (ptr[0] == '\\') - backslash_count++; - else - backslash_count = 0; - } - - /* skip any space at the end */ - while (ptr > line && git__isspace(ptr[-1])) { - ptr--; - } - ptr[0] = '\0'; - - return quote_count; -} - - -static int parse_subsection_header(git_config_parser *reader, const char *line, size_t pos, const char *base_name, char **section_name) -{ - int c, rpos; - const char *first_quote, *last_quote; - const char *line_start = line; - git_str buf = GIT_STR_INIT; - size_t quoted_len, alloc_len, base_name_len = strlen(base_name); - - /* Skip any additional whitespace before our section name */ - while (git__isspace(line[pos])) - pos++; - - /* We should be at the first quotation mark. */ - if (line[pos] != '"') { - set_parse_error(reader, 0, "missing quotation marks in section header"); - goto end_error; - } - - first_quote = &line[pos]; - last_quote = strrchr(line, '"'); - quoted_len = last_quote - first_quote; - - if ((last_quote - line) > INT_MAX) { - set_parse_error(reader, 0, "invalid section header, line too long"); - goto end_error; - } - - if (quoted_len == 0) { - set_parse_error(reader, 0, "missing closing quotation mark in section header"); - goto end_error; - } - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); - - if (git_str_grow(&buf, alloc_len) < 0 || - git_str_printf(&buf, "%s.", base_name) < 0) - goto end_error; - - rpos = 0; - - line = first_quote; - c = line[++rpos]; - - /* - * At the end of each iteration, whatever is stored in c will be - * added to the string. In case of error, jump to out - */ - do { - - switch (c) { - case 0: - set_parse_error(reader, 0, "unexpected end-of-line in section header"); - goto end_error; - - case '"': - goto end_parse; - - case '\\': - c = line[++rpos]; - - if (c == 0) { - set_parse_error(reader, rpos, "unexpected end-of-line in section header"); - goto end_error; - } - - default: - break; - } - - git_str_putc(&buf, (char)c); - c = line[++rpos]; - } while (line + rpos < last_quote); - -end_parse: - if (git_str_oom(&buf)) - goto end_error; - - if (line[rpos] != '"' || line[rpos + 1] != ']') { - set_parse_error(reader, rpos, "unexpected text after closing quotes"); - git_str_dispose(&buf); - return -1; - } - - *section_name = git_str_detach(&buf); - return (int)(&line[rpos + 2] - line_start); /* rpos is at the closing quote */ - -end_error: - git_str_dispose(&buf); - - return -1; -} - -static int parse_section_header(git_config_parser *reader, char **section_out) -{ - char *name, *name_end; - int name_length, pos; - int result; - char *line; - char c; - size_t line_len; - - git_parse_advance_ws(&reader->ctx); - line = git__strndup(reader->ctx.line, reader->ctx.line_len); - if (line == NULL) - return -1; - - /* find the end of the variable's name */ - name_end = strrchr(line, ']'); - if (name_end == NULL) { - git__free(line); - set_parse_error(reader, 0, "missing ']' in section header"); - return -1; - } - - GIT_ERROR_CHECK_ALLOC_ADD(&line_len, (size_t)(name_end - line), 1); - name = git__malloc(line_len); - GIT_ERROR_CHECK_ALLOC(name); - - name_length = 0; - pos = 0; - - /* Make sure we were given a section header */ - c = line[pos++]; - GIT_ASSERT(c == '['); - - c = line[pos++]; - - do { - if (git__isspace(c)){ - name[name_length] = '\0'; - result = parse_subsection_header(reader, line, pos, name, section_out); - git__free(line); - git__free(name); - return result; - } - - if (!config_keychar(c) && c != '.') { - set_parse_error(reader, pos, "unexpected character in header"); - goto fail_parse; - } - - name[name_length++] = (char)git__tolower(c); - - } while ((c = line[pos++]) != ']'); - - if (line[pos - 1] != ']') { - set_parse_error(reader, pos, "unexpected end of file"); - goto fail_parse; - } - - git__free(line); - - name[name_length] = 0; - *section_out = name; - - return pos; - -fail_parse: - git__free(line); - git__free(name); - return -1; -} - -static int skip_bom(git_parse_ctx *parser) -{ - git_str buf = GIT_STR_INIT_CONST(parser->content, parser->content_len); - git_str_bom_t bom; - int bom_offset = git_str_detect_bom(&bom, &buf); - - if (bom == GIT_STR_BOM_UTF8) - git_parse_advance_chars(parser, bom_offset); - - /* TODO: reference implementation is pretty stupid with BoM */ - - return 0; -} - -/* - (* basic types *) - digit = "0".."9" - integer = digit { digit } - alphabet = "a".."z" + "A" .. "Z" - - section_char = alphabet | "." | "-" - extension_char = (* any character except newline *) - any_char = (* any character *) - variable_char = "alphabet" | "-" - - - (* actual grammar *) - config = { section } - - section = header { definition } - - header = "[" section [subsection | subsection_ext] "]" - - subsection = "." section - subsection_ext = "\"" extension "\"" - - section = section_char { section_char } - extension = extension_char { extension_char } - - definition = variable_name ["=" variable_value] "\n" - - variable_name = variable_char { variable_char } - variable_value = string | boolean | integer - - string = quoted_string | plain_string - quoted_string = "\"" plain_string "\"" - plain_string = { any_char } - - boolean = boolean_true | boolean_false - boolean_true = "yes" | "1" | "true" | "on" - boolean_false = "no" | "0" | "false" | "off" -*/ - -/* '\"' -> '"' etc */ -static int unescape_line(char **out, bool *is_multi, const char *ptr, int *quote_count) -{ - char *str, *fixed; - const char *esc; - size_t ptr_len = strlen(ptr), alloc_len; - - *is_multi = false; - - if (GIT_ADD_SIZET_OVERFLOW(&alloc_len, ptr_len, 1) || - (str = git__malloc(alloc_len)) == NULL) { - return -1; - } - - fixed = str; - - while (*ptr != '\0') { - if (*ptr == '"') { - if (quote_count) - (*quote_count)++; - } else if (*ptr != '\\') { - *fixed++ = *ptr; - } else { - /* backslash, check the next char */ - ptr++; - /* if we're at the end, it's a multiline, so keep the backslash */ - if (*ptr == '\0') { - *is_multi = true; - goto done; - } - if ((esc = strchr(git_config_escapes, *ptr)) != NULL) { - *fixed++ = git_config_escaped[esc - git_config_escapes]; - } else { - git__free(str); - git_error_set(GIT_ERROR_CONFIG, "invalid escape at %s", ptr); - return -1; - } - } - ptr++; - } - -done: - *fixed = '\0'; - *out = str; - - return 0; -} - -static int parse_multiline_variable(git_config_parser *reader, git_str *value, int in_quotes, size_t *line_len) -{ - int quote_count; - bool multiline = true; - - while (multiline) { - char *line = NULL, *proc_line = NULL; - int error; - - /* Check that the next line exists */ - git_parse_advance_line(&reader->ctx); - line = git__strndup(reader->ctx.line, reader->ctx.line_len); - GIT_ERROR_CHECK_ALLOC(line); - if (GIT_ADD_SIZET_OVERFLOW(line_len, *line_len, reader->ctx.line_len)) { - error = -1; - goto out; - } - - /* - * We've reached the end of the file, there is no continuation. - * (this is not an error). - */ - if (line[0] == '\0') { - error = 0; - goto out; - } - - /* If it was just a comment, pretend it didn't exist */ - quote_count = strip_comments(line, in_quotes); - if (line[0] == '\0') - goto next; - - if ((error = unescape_line(&proc_line, &multiline, - line, &in_quotes)) < 0) - goto out; - - /* Add this line to the multiline var */ - if ((error = git_str_puts(value, proc_line)) < 0) - goto out; - -next: - git__free(line); - git__free(proc_line); - in_quotes = quote_count; - continue; - -out: - git__free(line); - git__free(proc_line); - return error; - } - - return 0; -} - -GIT_INLINE(bool) is_namechar(char c) -{ - return git__isalnum(c) || c == '-'; -} - -static int parse_name( - char **name, const char **value, git_config_parser *reader, const char *line) -{ - const char *name_end = line, *value_start; - - *name = NULL; - *value = NULL; - - while (*name_end && is_namechar(*name_end)) - name_end++; - - if (line == name_end) { - set_parse_error(reader, 0, "invalid configuration key"); - return -1; - } - - value_start = name_end; - - while (*value_start && git__isspace(*value_start)) - value_start++; - - if (*value_start == '=') { - *value = value_start + 1; - } else if (*value_start) { - set_parse_error(reader, 0, "invalid configuration key"); - return -1; - } - - if ((*name = git__strndup(line, name_end - line)) == NULL) - return -1; - - return 0; -} - -static int parse_variable(git_config_parser *reader, char **var_name, char **var_value, size_t *line_len) -{ - const char *value_start = NULL; - char *line = NULL, *name = NULL, *value = NULL; - int quote_count, error; - bool multiline; - - *var_name = NULL; - *var_value = NULL; - - git_parse_advance_ws(&reader->ctx); - line = git__strndup(reader->ctx.line, reader->ctx.line_len); - GIT_ERROR_CHECK_ALLOC(line); - - quote_count = strip_comments(line, 0); - - if ((error = parse_name(&name, &value_start, reader, line)) < 0) - goto out; - - /* - * Now, let's try to parse the value - */ - if (value_start != NULL) { - while (git__isspace(value_start[0])) - value_start++; - - if ((error = unescape_line(&value, &multiline, value_start, NULL)) < 0) - goto out; - - if (multiline) { - git_str multi_value = GIT_STR_INIT; - git_str_attach(&multi_value, value, 0); - value = NULL; - - if (parse_multiline_variable(reader, &multi_value, quote_count % 2, line_len) < 0 || - git_str_oom(&multi_value)) { - error = -1; - git_str_dispose(&multi_value); - goto out; - } - - value = git_str_detach(&multi_value); - } - } - - *var_name = name; - *var_value = value; - name = NULL; - value = NULL; - -out: - git__free(name); - git__free(value); - git__free(line); - return error; -} - -int git_config_parser_init(git_config_parser *out, const char *path, const char *data, size_t datalen) -{ - out->path = path; - return git_parse_ctx_init(&out->ctx, data, datalen); -} - -void git_config_parser_dispose(git_config_parser *parser) -{ - git_parse_ctx_clear(&parser->ctx); -} - -int git_config_parse( - git_config_parser *parser, - git_config_parser_section_cb on_section, - git_config_parser_variable_cb on_variable, - git_config_parser_comment_cb on_comment, - git_config_parser_eof_cb on_eof, - void *payload) -{ - git_parse_ctx *ctx; - char *current_section = NULL, *var_name = NULL, *var_value = NULL; - int result = 0; - - ctx = &parser->ctx; - - skip_bom(ctx); - - for (; ctx->remain_len > 0; git_parse_advance_line(ctx)) { - const char *line_start; - size_t line_len; - char c; - - restart: - line_start = ctx->line; - line_len = ctx->line_len; - - /* - * Get either first non-whitespace character or, if that does - * not exist, the first whitespace character. This is required - * to preserve whitespaces when writing back the file. - */ - if (git_parse_peek(&c, ctx, GIT_PARSE_PEEK_SKIP_WHITESPACE) < 0 && - git_parse_peek(&c, ctx, 0) < 0) - continue; - - switch (c) { - case '[': /* section header, new section begins */ - git__free(current_section); - current_section = NULL; - - result = parse_section_header(parser, ¤t_section); - if (result < 0) - break; - - git_parse_advance_chars(ctx, result); - - if (on_section) - result = on_section(parser, current_section, line_start, line_len, payload); - /* - * After we've parsed the section header we may not be - * done with the line. If there's still data in there, - * run the next loop with the rest of the current line - * instead of moving forward. - */ - - if (!git_parse_peek(&c, ctx, GIT_PARSE_PEEK_SKIP_WHITESPACE)) - goto restart; - - break; - - case '\n': /* comment or whitespace-only */ - case '\r': - case ' ': - case '\t': - case ';': - case '#': - if (on_comment) { - result = on_comment(parser, line_start, line_len, payload); - } - break; - - default: /* assume variable declaration */ - if ((result = parse_variable(parser, &var_name, &var_value, &line_len)) == 0 && on_variable) { - result = on_variable(parser, current_section, var_name, var_value, line_start, line_len, payload); - git__free(var_name); - git__free(var_value); - } - - break; - } - - if (result < 0) - goto out; - } - - if (on_eof) - result = on_eof(parser, current_section, payload); - -out: - git__free(current_section); - return result; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_parse.h b/vendor/libgit2-sys/libgit2/src/libgit2/config_parse.h deleted file mode 100644 index b791d32..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_parse.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_config_parse_h__ -#define INCLUDE_config_parse_h__ - -#include "common.h" - -#include "array.h" -#include "futils.h" -#include "oid.h" -#include "parse.h" - -extern const char *git_config_escapes; -extern const char *git_config_escaped; - -typedef struct { - const char *path; - git_parse_ctx ctx; -} git_config_parser; - -#define GIT_CONFIG_PARSER_INIT { NULL, GIT_PARSE_CTX_INIT } - -typedef int (*git_config_parser_section_cb)( - git_config_parser *parser, - const char *current_section, - const char *line, - size_t line_len, - void *payload); - -typedef int (*git_config_parser_variable_cb)( - git_config_parser *parser, - const char *current_section, - const char *var_name, - const char *var_value, - const char *line, - size_t line_len, - void *payload); - -typedef int (*git_config_parser_comment_cb)( - git_config_parser *parser, - const char *line, - size_t line_len, - void *payload); - -typedef int (*git_config_parser_eof_cb)( - git_config_parser *parser, - const char *current_section, - void *payload); - -int git_config_parser_init(git_config_parser *out, const char *path, const char *data, size_t datalen); -void git_config_parser_dispose(git_config_parser *parser); - -int git_config_parse( - git_config_parser *parser, - git_config_parser_section_cb on_section, - git_config_parser_variable_cb on_variable, - git_config_parser_comment_cb on_comment, - git_config_parser_eof_cb on_eof, - void *payload); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/config_snapshot.c b/vendor/libgit2-sys/libgit2/src/libgit2/config_snapshot.c deleted file mode 100644 index d20984f..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/config_snapshot.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "config_backend.h" - -#include "config.h" -#include "config_list.h" - -typedef struct { - git_config_backend parent; - git_mutex values_mutex; - git_config_list *config_list; - git_config_backend *source; -} config_snapshot_backend; - -static int config_error_readonly(void) -{ - git_error_set(GIT_ERROR_CONFIG, "this backend is read-only"); - return -1; -} - -static int config_snapshot_iterator( - git_config_iterator **iter, - struct git_config_backend *backend) -{ - config_snapshot_backend *b = GIT_CONTAINER_OF(backend, config_snapshot_backend, parent); - git_config_list *config_list = NULL; - int error; - - if ((error = git_config_list_dup(&config_list, b->config_list)) < 0 || - (error = git_config_list_iterator_new(iter, config_list)) < 0) - goto out; - -out: - /* Let iterator delete duplicated config_list when it's done */ - git_config_list_free(config_list); - return error; -} - -static int config_snapshot_get( - git_config_backend *cfg, - const char *key, - git_config_backend_entry **out) -{ - config_snapshot_backend *b = GIT_CONTAINER_OF(cfg, config_snapshot_backend, parent); - git_config_list *config_list = NULL; - git_config_list_entry *entry; - int error = 0; - - if (git_mutex_lock(&b->values_mutex) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock config backend"); - return -1; - } - - config_list = b->config_list; - git_config_list_incref(config_list); - git_mutex_unlock(&b->values_mutex); - - if ((error = (git_config_list_get(&entry, config_list, key))) < 0) { - git_config_list_free(config_list); - return error; - } - - *out = &entry->base; - return 0; -} - -static int config_snapshot_set(git_config_backend *cfg, const char *name, const char *value) -{ - GIT_UNUSED(cfg); - GIT_UNUSED(name); - GIT_UNUSED(value); - - return config_error_readonly(); -} - -static int config_snapshot_set_multivar( - git_config_backend *cfg, const char *name, const char *regexp, const char *value) -{ - GIT_UNUSED(cfg); - GIT_UNUSED(name); - GIT_UNUSED(regexp); - GIT_UNUSED(value); - - return config_error_readonly(); -} - -static int config_snapshot_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp) -{ - GIT_UNUSED(cfg); - GIT_UNUSED(name); - GIT_UNUSED(regexp); - - return config_error_readonly(); -} - -static int config_snapshot_delete(git_config_backend *cfg, const char *name) -{ - GIT_UNUSED(cfg); - GIT_UNUSED(name); - - return config_error_readonly(); -} - -static int config_snapshot_lock(git_config_backend *_cfg) -{ - GIT_UNUSED(_cfg); - - return config_error_readonly(); -} - -static int config_snapshot_unlock(git_config_backend *_cfg, int success) -{ - GIT_UNUSED(_cfg); - GIT_UNUSED(success); - - return config_error_readonly(); -} - -static void config_snapshot_free(git_config_backend *_backend) -{ - config_snapshot_backend *backend = GIT_CONTAINER_OF(_backend, config_snapshot_backend, parent); - - if (backend == NULL) - return; - - git_config_list_free(backend->config_list); - git_mutex_free(&backend->values_mutex); - git__free(backend); -} - -static int config_snapshot_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo) -{ - config_snapshot_backend *b = GIT_CONTAINER_OF(cfg, config_snapshot_backend, parent); - git_config_list *config_list = NULL; - git_config_iterator *it = NULL; - git_config_entry *entry; - int error; - - /* We're just copying data, don't care about the level or repo*/ - GIT_UNUSED(level); - GIT_UNUSED(repo); - - if ((error = git_config_list_new(&config_list)) < 0 || - (error = b->source->iterator(&it, b->source)) < 0) - goto out; - - while ((error = git_config_next(&entry, it)) == 0) - if ((error = git_config_list_dup_entry(config_list, entry)) < 0) - goto out; - - if (error < 0) { - if (error != GIT_ITEROVER) - goto out; - error = 0; - } - - b->config_list = config_list; - -out: - git_config_iterator_free(it); - if (error) - git_config_list_free(config_list); - return error; -} - -int git_config_backend_snapshot(git_config_backend **out, git_config_backend *source) -{ - config_snapshot_backend *backend; - - backend = git__calloc(1, sizeof(config_snapshot_backend)); - GIT_ERROR_CHECK_ALLOC(backend); - - backend->parent.version = GIT_CONFIG_BACKEND_VERSION; - git_mutex_init(&backend->values_mutex); - - backend->source = source; - - backend->parent.readonly = 1; - backend->parent.version = GIT_CONFIG_BACKEND_VERSION; - backend->parent.open = config_snapshot_open; - backend->parent.get = config_snapshot_get; - backend->parent.set = config_snapshot_set; - backend->parent.set_multivar = config_snapshot_set_multivar; - backend->parent.snapshot = git_config_backend_snapshot; - backend->parent.del = config_snapshot_delete; - backend->parent.del_multivar = config_snapshot_delete_multivar; - backend->parent.iterator = config_snapshot_iterator; - backend->parent.lock = config_snapshot_lock; - backend->parent.unlock = config_snapshot_unlock; - backend->parent.free = config_snapshot_free; - - *out = &backend->parent; - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/crlf.c b/vendor/libgit2-sys/libgit2/src/libgit2/crlf.c deleted file mode 100644 index 1e1f1e8..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/crlf.c +++ /dev/null @@ -1,426 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/attr.h" -#include "git2/blob.h" -#include "git2/index.h" -#include "git2/sys/filter.h" - -#include "buf.h" -#include "futils.h" -#include "hash.h" -#include "filter.h" -#include "repository.h" - -typedef enum { - GIT_CRLF_UNDEFINED, - GIT_CRLF_BINARY, - GIT_CRLF_TEXT, - GIT_CRLF_TEXT_INPUT, - GIT_CRLF_TEXT_CRLF, - GIT_CRLF_AUTO, - GIT_CRLF_AUTO_INPUT, - GIT_CRLF_AUTO_CRLF -} git_crlf_t; - -struct crlf_attrs { - int attr_action; /* the .gitattributes setting */ - int crlf_action; /* the core.autocrlf setting */ - - int auto_crlf; - int safe_crlf; - int core_eol; -}; - -struct crlf_filter { - git_filter f; -}; - -static git_crlf_t check_crlf(const char *value) -{ - if (GIT_ATTR_IS_TRUE(value)) - return GIT_CRLF_TEXT; - else if (GIT_ATTR_IS_FALSE(value)) - return GIT_CRLF_BINARY; - else if (GIT_ATTR_IS_UNSPECIFIED(value)) - ; - else if (strcmp(value, "input") == 0) - return GIT_CRLF_TEXT_INPUT; - else if (strcmp(value, "auto") == 0) - return GIT_CRLF_AUTO; - - return GIT_CRLF_UNDEFINED; -} - -static git_configmap_value check_eol(const char *value) -{ - if (GIT_ATTR_IS_UNSPECIFIED(value)) - ; - else if (strcmp(value, "lf") == 0) - return GIT_EOL_LF; - else if (strcmp(value, "crlf") == 0) - return GIT_EOL_CRLF; - - return GIT_EOL_UNSET; -} - -static int has_cr_in_index(const git_filter_source *src) -{ - git_repository *repo = git_filter_source_repo(src); - const char *path = git_filter_source_path(src); - git_index *index; - const git_index_entry *entry; - git_blob *blob; - const void *blobcontent; - git_object_size_t blobsize; - bool found_cr; - - if (!path) - return false; - - if (git_repository_index__weakptr(&index, repo) < 0) { - git_error_clear(); - return false; - } - - if (!(entry = git_index_get_bypath(index, path, 0)) && - !(entry = git_index_get_bypath(index, path, 1))) - return false; - - if (!S_ISREG(entry->mode)) /* don't crlf filter non-blobs */ - return true; - - if (git_blob_lookup(&blob, repo, &entry->id) < 0) - return false; - - blobcontent = git_blob_rawcontent(blob); - blobsize = git_blob_rawsize(blob); - if (!git__is_sizet(blobsize)) - blobsize = (size_t)-1; - - found_cr = (blobcontent != NULL && - blobsize > 0 && - memchr(blobcontent, '\r', (size_t)blobsize) != NULL); - - git_blob_free(blob); - return found_cr; -} - -static int text_eol_is_crlf(struct crlf_attrs *ca) -{ - if (ca->auto_crlf == GIT_AUTO_CRLF_TRUE) - return 1; - else if (ca->auto_crlf == GIT_AUTO_CRLF_INPUT) - return 0; - - if (ca->core_eol == GIT_EOL_CRLF) - return 1; - if (ca->core_eol == GIT_EOL_UNSET && GIT_EOL_NATIVE == GIT_EOL_CRLF) - return 1; - - return 0; -} - -static git_configmap_value output_eol(struct crlf_attrs *ca) -{ - switch (ca->crlf_action) { - case GIT_CRLF_BINARY: - return GIT_EOL_UNSET; - case GIT_CRLF_TEXT_CRLF: - return GIT_EOL_CRLF; - case GIT_CRLF_TEXT_INPUT: - return GIT_EOL_LF; - case GIT_CRLF_UNDEFINED: - case GIT_CRLF_AUTO_CRLF: - return GIT_EOL_CRLF; - case GIT_CRLF_AUTO_INPUT: - return GIT_EOL_LF; - case GIT_CRLF_TEXT: - case GIT_CRLF_AUTO: - return text_eol_is_crlf(ca) ? GIT_EOL_CRLF : GIT_EOL_LF; - } - - /* TODO: warn when available */ - return ca->core_eol; -} - -GIT_INLINE(int) check_safecrlf( - struct crlf_attrs *ca, - const git_filter_source *src, - git_str_text_stats *stats) -{ - const char *filename = git_filter_source_path(src); - - if (!ca->safe_crlf) - return 0; - - if (output_eol(ca) == GIT_EOL_LF) { - /* - * CRLFs would not be restored by checkout: - * check if we'd remove CRLFs - */ - if (stats->crlf) { - if (ca->safe_crlf == GIT_SAFE_CRLF_WARN) { - /* TODO: issue a warning when available */ - } else { - if (filename && *filename) - git_error_set( - GIT_ERROR_FILTER, "CRLF would be replaced by LF in '%s'", - filename); - else - git_error_set( - GIT_ERROR_FILTER, "CRLF would be replaced by LF"); - - return -1; - } - } - } else if (output_eol(ca) == GIT_EOL_CRLF) { - /* - * CRLFs would be added by checkout: - * check if we have "naked" LFs - */ - if (stats->crlf != stats->lf) { - if (ca->safe_crlf == GIT_SAFE_CRLF_WARN) { - /* TODO: issue a warning when available */ - } else { - if (filename && *filename) - git_error_set( - GIT_ERROR_FILTER, "LF would be replaced by CRLF in '%s'", - filename); - else - git_error_set( - GIT_ERROR_FILTER, "LF would be replaced by CRLF"); - - return -1; - } - } - } - - return 0; -} - -static int crlf_apply_to_odb( - struct crlf_attrs *ca, - git_str *to, - const git_str *from, - const git_filter_source *src) -{ - git_str_text_stats stats; - bool is_binary; - int error; - - /* Binary attribute? Empty file? Nothing to do */ - if (ca->crlf_action == GIT_CRLF_BINARY || from->size == 0) - return GIT_PASSTHROUGH; - - is_binary = git_str_gather_text_stats(&stats, from, false); - - /* Heuristics to see if we can skip the conversion. - * Straight from Core Git. - */ - if (ca->crlf_action == GIT_CRLF_AUTO || - ca->crlf_action == GIT_CRLF_AUTO_INPUT || - ca->crlf_action == GIT_CRLF_AUTO_CRLF) { - - if (is_binary) - return GIT_PASSTHROUGH; - - /* - * If the file in the index has any CR in it, do not convert. - * This is the new safer autocrlf handling. - */ - if (has_cr_in_index(src)) - return GIT_PASSTHROUGH; - } - - if ((error = check_safecrlf(ca, src, &stats)) < 0) - return error; - - /* If there are no CR characters to filter out, then just pass */ - if (!stats.crlf) - return GIT_PASSTHROUGH; - - /* Actually drop the carriage returns */ - return git_str_crlf_to_lf(to, from); -} - -static int crlf_apply_to_workdir( - struct crlf_attrs *ca, - git_str *to, - const git_str *from) -{ - git_str_text_stats stats; - bool is_binary; - - /* Empty file? Nothing to do. */ - if (git_str_len(from) == 0 || output_eol(ca) != GIT_EOL_CRLF) - return GIT_PASSTHROUGH; - - is_binary = git_str_gather_text_stats(&stats, from, false); - - /* If there are no LFs, or all LFs are part of a CRLF, nothing to do */ - if (stats.lf == 0 || stats.lf == stats.crlf) - return GIT_PASSTHROUGH; - - if (ca->crlf_action == GIT_CRLF_AUTO || - ca->crlf_action == GIT_CRLF_AUTO_INPUT || - ca->crlf_action == GIT_CRLF_AUTO_CRLF) { - - /* If we have any existing CR or CRLF line endings, do nothing */ - if (stats.cr > 0) - return GIT_PASSTHROUGH; - - /* Don't filter binary files */ - if (is_binary) - return GIT_PASSTHROUGH; - } - - return git_str_lf_to_crlf(to, from); -} - -static int convert_attrs( - struct crlf_attrs *ca, - const char **attr_values, - const git_filter_source *src) -{ - int error; - - memset(ca, 0, sizeof(struct crlf_attrs)); - - if ((error = git_repository__configmap_lookup(&ca->auto_crlf, - git_filter_source_repo(src), GIT_CONFIGMAP_AUTO_CRLF)) < 0 || - (error = git_repository__configmap_lookup(&ca->safe_crlf, - git_filter_source_repo(src), GIT_CONFIGMAP_SAFE_CRLF)) < 0 || - (error = git_repository__configmap_lookup(&ca->core_eol, - git_filter_source_repo(src), GIT_CONFIGMAP_EOL)) < 0) - return error; - - /* downgrade FAIL to WARN if ALLOW_UNSAFE option is used */ - if ((git_filter_source_flags(src) & GIT_FILTER_ALLOW_UNSAFE) && - ca->safe_crlf == GIT_SAFE_CRLF_FAIL) - ca->safe_crlf = GIT_SAFE_CRLF_WARN; - - if (attr_values) { - /* load the text attribute */ - ca->crlf_action = check_crlf(attr_values[2]); /* text */ - - if (ca->crlf_action == GIT_CRLF_UNDEFINED) - ca->crlf_action = check_crlf(attr_values[0]); /* crlf */ - - if (ca->crlf_action != GIT_CRLF_BINARY) { - /* load the eol attribute */ - int eol_attr = check_eol(attr_values[1]); - - if (ca->crlf_action == GIT_CRLF_AUTO && eol_attr == GIT_EOL_LF) - ca->crlf_action = GIT_CRLF_AUTO_INPUT; - else if (ca->crlf_action == GIT_CRLF_AUTO && eol_attr == GIT_EOL_CRLF) - ca->crlf_action = GIT_CRLF_AUTO_CRLF; - else if (eol_attr == GIT_EOL_LF) - ca->crlf_action = GIT_CRLF_TEXT_INPUT; - else if (eol_attr == GIT_EOL_CRLF) - ca->crlf_action = GIT_CRLF_TEXT_CRLF; - } - - ca->attr_action = ca->crlf_action; - } else { - ca->crlf_action = GIT_CRLF_UNDEFINED; - } - - if (ca->crlf_action == GIT_CRLF_TEXT) - ca->crlf_action = text_eol_is_crlf(ca) ? GIT_CRLF_TEXT_CRLF : GIT_CRLF_TEXT_INPUT; - if (ca->crlf_action == GIT_CRLF_UNDEFINED && ca->auto_crlf == GIT_AUTO_CRLF_FALSE) - ca->crlf_action = GIT_CRLF_BINARY; - if (ca->crlf_action == GIT_CRLF_UNDEFINED && ca->auto_crlf == GIT_AUTO_CRLF_TRUE) - ca->crlf_action = GIT_CRLF_AUTO_CRLF; - if (ca->crlf_action == GIT_CRLF_UNDEFINED && ca->auto_crlf == GIT_AUTO_CRLF_INPUT) - ca->crlf_action = GIT_CRLF_AUTO_INPUT; - - return 0; -} - -static int crlf_check( - git_filter *self, - void **payload, /* points to NULL ptr on entry, may be set */ - const git_filter_source *src, - const char **attr_values) -{ - struct crlf_attrs ca; - - GIT_UNUSED(self); - - convert_attrs(&ca, attr_values, src); - - if (ca.crlf_action == GIT_CRLF_BINARY) - return GIT_PASSTHROUGH; - - *payload = git__malloc(sizeof(ca)); - GIT_ERROR_CHECK_ALLOC(*payload); - memcpy(*payload, &ca, sizeof(ca)); - - return 0; -} - -static int crlf_apply( - git_filter *self, - void **payload, /* may be read and/or set */ - git_str *to, - const git_str *from, - const git_filter_source *src) -{ - int error = 0; - - /* initialize payload in case `check` was bypassed */ - if (!*payload) { - if ((error = crlf_check(self, payload, src, NULL)) < 0) - return error; - } - - if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE) - error = crlf_apply_to_workdir(*payload, to, from); - else - error = crlf_apply_to_odb(*payload, to, from, src); - - return error; -} - -static int crlf_stream( - git_writestream **out, - git_filter *self, - void **payload, - const git_filter_source *src, - git_writestream *next) -{ - return git_filter_buffered_stream_new(out, - self, crlf_apply, NULL, payload, src, next); -} - -static void crlf_cleanup( - git_filter *self, - void *payload) -{ - GIT_UNUSED(self); - git__free(payload); -} - -git_filter *git_crlf_filter_new(void) -{ - struct crlf_filter *f = git__calloc(1, sizeof(struct crlf_filter)); - if (f == NULL) - return NULL; - - f->f.version = GIT_FILTER_VERSION; - f->f.attributes = "crlf eol text"; - f->f.initialize = NULL; - f->f.shutdown = git_filter_free; - f->f.check = crlf_check; - f->f.stream = crlf_stream; - f->f.cleanup = crlf_cleanup; - - return (git_filter *)f; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/delta.c b/vendor/libgit2-sys/libgit2/src/libgit2/delta.c deleted file mode 100644 index a7bb28d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/delta.c +++ /dev/null @@ -1,640 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "delta.h" - -/* maximum hash entry list for the same hash bucket */ -#define HASH_LIMIT 64 - -#define RABIN_SHIFT 23 -#define RABIN_WINDOW 16 - -extern size_t git_indexer__max_object_size; - -static const unsigned int T[256] = { - 0x00000000, 0xab59b4d1, 0x56b369a2, 0xfdeadd73, 0x063f6795, 0xad66d344, - 0x508c0e37, 0xfbd5bae6, 0x0c7ecf2a, 0xa7277bfb, 0x5acda688, 0xf1941259, - 0x0a41a8bf, 0xa1181c6e, 0x5cf2c11d, 0xf7ab75cc, 0x18fd9e54, 0xb3a42a85, - 0x4e4ef7f6, 0xe5174327, 0x1ec2f9c1, 0xb59b4d10, 0x48719063, 0xe32824b2, - 0x1483517e, 0xbfdae5af, 0x423038dc, 0xe9698c0d, 0x12bc36eb, 0xb9e5823a, - 0x440f5f49, 0xef56eb98, 0x31fb3ca8, 0x9aa28879, 0x6748550a, 0xcc11e1db, - 0x37c45b3d, 0x9c9defec, 0x6177329f, 0xca2e864e, 0x3d85f382, 0x96dc4753, - 0x6b369a20, 0xc06f2ef1, 0x3bba9417, 0x90e320c6, 0x6d09fdb5, 0xc6504964, - 0x2906a2fc, 0x825f162d, 0x7fb5cb5e, 0xd4ec7f8f, 0x2f39c569, 0x846071b8, - 0x798aaccb, 0xd2d3181a, 0x25786dd6, 0x8e21d907, 0x73cb0474, 0xd892b0a5, - 0x23470a43, 0x881ebe92, 0x75f463e1, 0xdeadd730, 0x63f67950, 0xc8afcd81, - 0x354510f2, 0x9e1ca423, 0x65c91ec5, 0xce90aa14, 0x337a7767, 0x9823c3b6, - 0x6f88b67a, 0xc4d102ab, 0x393bdfd8, 0x92626b09, 0x69b7d1ef, 0xc2ee653e, - 0x3f04b84d, 0x945d0c9c, 0x7b0be704, 0xd05253d5, 0x2db88ea6, 0x86e13a77, - 0x7d348091, 0xd66d3440, 0x2b87e933, 0x80de5de2, 0x7775282e, 0xdc2c9cff, - 0x21c6418c, 0x8a9ff55d, 0x714a4fbb, 0xda13fb6a, 0x27f92619, 0x8ca092c8, - 0x520d45f8, 0xf954f129, 0x04be2c5a, 0xafe7988b, 0x5432226d, 0xff6b96bc, - 0x02814bcf, 0xa9d8ff1e, 0x5e738ad2, 0xf52a3e03, 0x08c0e370, 0xa39957a1, - 0x584ced47, 0xf3155996, 0x0eff84e5, 0xa5a63034, 0x4af0dbac, 0xe1a96f7d, - 0x1c43b20e, 0xb71a06df, 0x4ccfbc39, 0xe79608e8, 0x1a7cd59b, 0xb125614a, - 0x468e1486, 0xedd7a057, 0x103d7d24, 0xbb64c9f5, 0x40b17313, 0xebe8c7c2, - 0x16021ab1, 0xbd5bae60, 0x6cb54671, 0xc7ecf2a0, 0x3a062fd3, 0x915f9b02, - 0x6a8a21e4, 0xc1d39535, 0x3c394846, 0x9760fc97, 0x60cb895b, 0xcb923d8a, - 0x3678e0f9, 0x9d215428, 0x66f4eece, 0xcdad5a1f, 0x3047876c, 0x9b1e33bd, - 0x7448d825, 0xdf116cf4, 0x22fbb187, 0x89a20556, 0x7277bfb0, 0xd92e0b61, - 0x24c4d612, 0x8f9d62c3, 0x7836170f, 0xd36fa3de, 0x2e857ead, 0x85dcca7c, - 0x7e09709a, 0xd550c44b, 0x28ba1938, 0x83e3ade9, 0x5d4e7ad9, 0xf617ce08, - 0x0bfd137b, 0xa0a4a7aa, 0x5b711d4c, 0xf028a99d, 0x0dc274ee, 0xa69bc03f, - 0x5130b5f3, 0xfa690122, 0x0783dc51, 0xacda6880, 0x570fd266, 0xfc5666b7, - 0x01bcbbc4, 0xaae50f15, 0x45b3e48d, 0xeeea505c, 0x13008d2f, 0xb85939fe, - 0x438c8318, 0xe8d537c9, 0x153feaba, 0xbe665e6b, 0x49cd2ba7, 0xe2949f76, - 0x1f7e4205, 0xb427f6d4, 0x4ff24c32, 0xe4abf8e3, 0x19412590, 0xb2189141, - 0x0f433f21, 0xa41a8bf0, 0x59f05683, 0xf2a9e252, 0x097c58b4, 0xa225ec65, - 0x5fcf3116, 0xf49685c7, 0x033df00b, 0xa86444da, 0x558e99a9, 0xfed72d78, - 0x0502979e, 0xae5b234f, 0x53b1fe3c, 0xf8e84aed, 0x17bea175, 0xbce715a4, - 0x410dc8d7, 0xea547c06, 0x1181c6e0, 0xbad87231, 0x4732af42, 0xec6b1b93, - 0x1bc06e5f, 0xb099da8e, 0x4d7307fd, 0xe62ab32c, 0x1dff09ca, 0xb6a6bd1b, - 0x4b4c6068, 0xe015d4b9, 0x3eb80389, 0x95e1b758, 0x680b6a2b, 0xc352defa, - 0x3887641c, 0x93ded0cd, 0x6e340dbe, 0xc56db96f, 0x32c6cca3, 0x999f7872, - 0x6475a501, 0xcf2c11d0, 0x34f9ab36, 0x9fa01fe7, 0x624ac294, 0xc9137645, - 0x26459ddd, 0x8d1c290c, 0x70f6f47f, 0xdbaf40ae, 0x207afa48, 0x8b234e99, - 0x76c993ea, 0xdd90273b, 0x2a3b52f7, 0x8162e626, 0x7c883b55, 0xd7d18f84, - 0x2c043562, 0x875d81b3, 0x7ab75cc0, 0xd1eee811 -}; - -static const unsigned int U[256] = { - 0x00000000, 0x7eb5200d, 0x5633f4cb, 0x2886d4c6, 0x073e5d47, 0x798b7d4a, - 0x510da98c, 0x2fb88981, 0x0e7cba8e, 0x70c99a83, 0x584f4e45, 0x26fa6e48, - 0x0942e7c9, 0x77f7c7c4, 0x5f711302, 0x21c4330f, 0x1cf9751c, 0x624c5511, - 0x4aca81d7, 0x347fa1da, 0x1bc7285b, 0x65720856, 0x4df4dc90, 0x3341fc9d, - 0x1285cf92, 0x6c30ef9f, 0x44b63b59, 0x3a031b54, 0x15bb92d5, 0x6b0eb2d8, - 0x4388661e, 0x3d3d4613, 0x39f2ea38, 0x4747ca35, 0x6fc11ef3, 0x11743efe, - 0x3eccb77f, 0x40799772, 0x68ff43b4, 0x164a63b9, 0x378e50b6, 0x493b70bb, - 0x61bda47d, 0x1f088470, 0x30b00df1, 0x4e052dfc, 0x6683f93a, 0x1836d937, - 0x250b9f24, 0x5bbebf29, 0x73386bef, 0x0d8d4be2, 0x2235c263, 0x5c80e26e, - 0x740636a8, 0x0ab316a5, 0x2b7725aa, 0x55c205a7, 0x7d44d161, 0x03f1f16c, - 0x2c4978ed, 0x52fc58e0, 0x7a7a8c26, 0x04cfac2b, 0x73e5d470, 0x0d50f47d, - 0x25d620bb, 0x5b6300b6, 0x74db8937, 0x0a6ea93a, 0x22e87dfc, 0x5c5d5df1, - 0x7d996efe, 0x032c4ef3, 0x2baa9a35, 0x551fba38, 0x7aa733b9, 0x041213b4, - 0x2c94c772, 0x5221e77f, 0x6f1ca16c, 0x11a98161, 0x392f55a7, 0x479a75aa, - 0x6822fc2b, 0x1697dc26, 0x3e1108e0, 0x40a428ed, 0x61601be2, 0x1fd53bef, - 0x3753ef29, 0x49e6cf24, 0x665e46a5, 0x18eb66a8, 0x306db26e, 0x4ed89263, - 0x4a173e48, 0x34a21e45, 0x1c24ca83, 0x6291ea8e, 0x4d29630f, 0x339c4302, - 0x1b1a97c4, 0x65afb7c9, 0x446b84c6, 0x3adea4cb, 0x1258700d, 0x6ced5000, - 0x4355d981, 0x3de0f98c, 0x15662d4a, 0x6bd30d47, 0x56ee4b54, 0x285b6b59, - 0x00ddbf9f, 0x7e689f92, 0x51d01613, 0x2f65361e, 0x07e3e2d8, 0x7956c2d5, - 0x5892f1da, 0x2627d1d7, 0x0ea10511, 0x7014251c, 0x5facac9d, 0x21198c90, - 0x099f5856, 0x772a785b, 0x4c921c31, 0x32273c3c, 0x1aa1e8fa, 0x6414c8f7, - 0x4bac4176, 0x3519617b, 0x1d9fb5bd, 0x632a95b0, 0x42eea6bf, 0x3c5b86b2, - 0x14dd5274, 0x6a687279, 0x45d0fbf8, 0x3b65dbf5, 0x13e30f33, 0x6d562f3e, - 0x506b692d, 0x2ede4920, 0x06589de6, 0x78edbdeb, 0x5755346a, 0x29e01467, - 0x0166c0a1, 0x7fd3e0ac, 0x5e17d3a3, 0x20a2f3ae, 0x08242768, 0x76910765, - 0x59298ee4, 0x279caee9, 0x0f1a7a2f, 0x71af5a22, 0x7560f609, 0x0bd5d604, - 0x235302c2, 0x5de622cf, 0x725eab4e, 0x0ceb8b43, 0x246d5f85, 0x5ad87f88, - 0x7b1c4c87, 0x05a96c8a, 0x2d2fb84c, 0x539a9841, 0x7c2211c0, 0x029731cd, - 0x2a11e50b, 0x54a4c506, 0x69998315, 0x172ca318, 0x3faa77de, 0x411f57d3, - 0x6ea7de52, 0x1012fe5f, 0x38942a99, 0x46210a94, 0x67e5399b, 0x19501996, - 0x31d6cd50, 0x4f63ed5d, 0x60db64dc, 0x1e6e44d1, 0x36e89017, 0x485db01a, - 0x3f77c841, 0x41c2e84c, 0x69443c8a, 0x17f11c87, 0x38499506, 0x46fcb50b, - 0x6e7a61cd, 0x10cf41c0, 0x310b72cf, 0x4fbe52c2, 0x67388604, 0x198da609, - 0x36352f88, 0x48800f85, 0x6006db43, 0x1eb3fb4e, 0x238ebd5d, 0x5d3b9d50, - 0x75bd4996, 0x0b08699b, 0x24b0e01a, 0x5a05c017, 0x728314d1, 0x0c3634dc, - 0x2df207d3, 0x534727de, 0x7bc1f318, 0x0574d315, 0x2acc5a94, 0x54797a99, - 0x7cffae5f, 0x024a8e52, 0x06852279, 0x78300274, 0x50b6d6b2, 0x2e03f6bf, - 0x01bb7f3e, 0x7f0e5f33, 0x57888bf5, 0x293dabf8, 0x08f998f7, 0x764cb8fa, - 0x5eca6c3c, 0x207f4c31, 0x0fc7c5b0, 0x7172e5bd, 0x59f4317b, 0x27411176, - 0x1a7c5765, 0x64c97768, 0x4c4fa3ae, 0x32fa83a3, 0x1d420a22, 0x63f72a2f, - 0x4b71fee9, 0x35c4dee4, 0x1400edeb, 0x6ab5cde6, 0x42331920, 0x3c86392d, - 0x133eb0ac, 0x6d8b90a1, 0x450d4467, 0x3bb8646a -}; - -struct index_entry { - const unsigned char *ptr; - unsigned int val; - struct index_entry *next; -}; - -struct git_delta_index { - unsigned long memsize; - const void *src_buf; - size_t src_size; - unsigned int hash_mask; - struct index_entry *hash[GIT_FLEX_ARRAY]; -}; - -static int lookup_index_alloc( - void **out, unsigned long *out_len, size_t entries, size_t hash_count) -{ - size_t entries_len, hash_len, index_len; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&entries_len, entries, sizeof(struct index_entry)); - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&hash_len, hash_count, sizeof(struct index_entry *)); - - GIT_ERROR_CHECK_ALLOC_ADD(&index_len, sizeof(struct git_delta_index), entries_len); - GIT_ERROR_CHECK_ALLOC_ADD(&index_len, index_len, hash_len); - - if (!git__is_ulong(index_len)) { - git_error_set(GIT_ERROR_NOMEMORY, "overly large delta"); - return -1; - } - - *out = git__malloc(index_len); - GIT_ERROR_CHECK_ALLOC(*out); - - *out_len = (unsigned long)index_len; - return 0; -} - -int git_delta_index_init( - git_delta_index **out, const void *buf, size_t bufsize) -{ - unsigned int i, hsize, hmask, entries, prev_val, *hash_count; - const unsigned char *data, *buffer = buf; - struct git_delta_index *index; - struct index_entry *entry, **hash; - void *mem; - unsigned long memsize; - - *out = NULL; - - if (!buf || !bufsize) - return 0; - - /* Determine index hash size. Note that indexing skips the - first byte to allow for optimizing the rabin polynomial - initialization in create_delta(). */ - entries = (unsigned int)(bufsize - 1) / RABIN_WINDOW; - if (bufsize >= 0xffffffffUL) { - /* - * Current delta format can't encode offsets into - * reference buffer with more than 32 bits. - */ - entries = 0xfffffffeU / RABIN_WINDOW; - } - hsize = entries / 4; - for (i = 4; i < 31 && (1u << i) < hsize; i++); - hsize = 1 << i; - hmask = hsize - 1; - - if (lookup_index_alloc(&mem, &memsize, entries, hsize) < 0) - return -1; - - index = mem; - mem = index->hash; - hash = mem; - mem = hash + hsize; - entry = mem; - - index->memsize = memsize; - index->src_buf = buf; - index->src_size = bufsize; - index->hash_mask = hmask; - memset(hash, 0, hsize * sizeof(*hash)); - - /* allocate an array to count hash entries */ - hash_count = git__calloc(hsize, sizeof(*hash_count)); - if (!hash_count) { - git__free(index); - return -1; - } - - /* then populate the index */ - prev_val = ~0; - for (data = buffer + entries * RABIN_WINDOW - RABIN_WINDOW; - data >= buffer; - data -= RABIN_WINDOW) { - unsigned int val = 0; - for (i = 1; i <= RABIN_WINDOW; i++) - val = ((val << 8) | data[i]) ^ T[val >> RABIN_SHIFT]; - if (val == prev_val) { - /* keep the lowest of consecutive identical blocks */ - entry[-1].ptr = data + RABIN_WINDOW; - } else { - prev_val = val; - i = val & hmask; - entry->ptr = data + RABIN_WINDOW; - entry->val = val; - entry->next = hash[i]; - hash[i] = entry++; - hash_count[i]++; - } - } - - /* - * Determine a limit on the number of entries in the same hash - * bucket. This guard us against patological data sets causing - * really bad hash distribution with most entries in the same hash - * bucket that would bring us to O(m*n) computing costs (m and n - * corresponding to reference and target buffer sizes). - * - * Make sure none of the hash buckets has more entries than - * we're willing to test. Otherwise we cull the entry list - * uniformly to still preserve a good repartition across - * the reference buffer. - */ - for (i = 0; i < hsize; i++) { - if (hash_count[i] < HASH_LIMIT) - continue; - - entry = hash[i]; - do { - struct index_entry *keep = entry; - int skip = hash_count[i] / HASH_LIMIT / 2; - do { - entry = entry->next; - } while(--skip && entry); - keep->next = entry; - } while (entry); - } - git__free(hash_count); - - *out = index; - return 0; -} - -void git_delta_index_free(git_delta_index *index) -{ - git__free(index); -} - -size_t git_delta_index_size(git_delta_index *index) -{ - GIT_ASSERT_ARG(index); - - return index->memsize; -} - -/* - * The maximum size for any opcode sequence, including the initial header - * plus rabin window plus biggest copy. - */ -#define MAX_OP_SIZE (5 + 5 + 1 + RABIN_WINDOW + 7) - -int git_delta_create_from_index( - void **out, - size_t *out_len, - const struct git_delta_index *index, - const void *trg_buf, - size_t trg_size, - size_t max_size) -{ - unsigned int i, bufpos, bufsize, moff, msize, val; - int inscnt; - const unsigned char *ref_data, *ref_top, *data, *top; - unsigned char *buf; - - *out = NULL; - *out_len = 0; - - if (!trg_buf || !trg_size) - return 0; - - if (index->src_size > UINT_MAX || - trg_size > UINT_MAX || - max_size > (UINT_MAX - MAX_OP_SIZE - 1)) { - git_error_set(GIT_ERROR_INVALID, "buffer sizes too large for delta processing"); - return -1; - } - - bufpos = 0; - bufsize = 8192; - if (max_size && bufsize >= max_size) - bufsize = (unsigned int)(max_size + MAX_OP_SIZE + 1); - buf = git__malloc(bufsize); - GIT_ERROR_CHECK_ALLOC(buf); - - /* store reference buffer size */ - i = (unsigned int)index->src_size; - while (i >= 0x80) { - buf[bufpos++] = i | 0x80; - i >>= 7; - } - buf[bufpos++] = i; - - /* store target buffer size */ - i = (unsigned int)trg_size; - while (i >= 0x80) { - buf[bufpos++] = i | 0x80; - i >>= 7; - } - buf[bufpos++] = i; - - ref_data = index->src_buf; - ref_top = ref_data + index->src_size; - data = trg_buf; - top = (const unsigned char *) trg_buf + trg_size; - - bufpos++; - val = 0; - for (i = 0; i < RABIN_WINDOW && data < top; i++, data++) { - buf[bufpos++] = *data; - val = ((val << 8) | *data) ^ T[val >> RABIN_SHIFT]; - } - inscnt = i; - - moff = 0; - msize = 0; - while (data < top) { - if (msize < 4096) { - struct index_entry *entry; - val ^= U[data[-RABIN_WINDOW]]; - val = ((val << 8) | *data) ^ T[val >> RABIN_SHIFT]; - i = val & index->hash_mask; - for (entry = index->hash[i]; entry; entry = entry->next) { - const unsigned char *ref = entry->ptr; - const unsigned char *src = data; - unsigned int ref_size = (unsigned int)(ref_top - ref); - if (entry->val != val) - continue; - if (ref_size > (unsigned int)(top - src)) - ref_size = (unsigned int)(top - src); - if (ref_size <= msize) - break; - while (ref_size-- && *src++ == *ref) - ref++; - if (msize < (unsigned int)(ref - entry->ptr)) { - /* this is our best match so far */ - msize = (unsigned int)(ref - entry->ptr); - moff = (unsigned int)(entry->ptr - ref_data); - if (msize >= 4096) /* good enough */ - break; - } - } - } - - if (msize < 4) { - if (!inscnt) - bufpos++; - buf[bufpos++] = *data++; - inscnt++; - if (inscnt == 0x7f) { - buf[bufpos - inscnt - 1] = inscnt; - inscnt = 0; - } - msize = 0; - } else { - unsigned int left; - unsigned char *op; - - if (inscnt) { - while (moff && ref_data[moff-1] == data[-1]) { - /* we can match one byte back */ - msize++; - moff--; - data--; - bufpos--; - if (--inscnt) - continue; - bufpos--; /* remove count slot */ - inscnt--; /* make it -1 */ - break; - } - buf[bufpos - inscnt - 1] = inscnt; - inscnt = 0; - } - - /* A copy op is currently limited to 64KB (pack v2) */ - left = (msize < 0x10000) ? 0 : (msize - 0x10000); - msize -= left; - - op = buf + bufpos++; - i = 0x80; - - if (moff & 0x000000ff) - buf[bufpos++] = moff >> 0, i |= 0x01; - if (moff & 0x0000ff00) - buf[bufpos++] = moff >> 8, i |= 0x02; - if (moff & 0x00ff0000) - buf[bufpos++] = moff >> 16, i |= 0x04; - if (moff & 0xff000000) - buf[bufpos++] = moff >> 24, i |= 0x08; - - if (msize & 0x00ff) - buf[bufpos++] = msize >> 0, i |= 0x10; - if (msize & 0xff00) - buf[bufpos++] = msize >> 8, i |= 0x20; - - *op = i; - - data += msize; - moff += msize; - msize = left; - - if (msize < 4096) { - int j; - val = 0; - for (j = -RABIN_WINDOW; j < 0; j++) - val = ((val << 8) | data[j]) - ^ T[val >> RABIN_SHIFT]; - } - } - - if (bufpos >= bufsize - MAX_OP_SIZE) { - void *tmp = buf; - bufsize = bufsize * 3 / 2; - if (max_size && bufsize >= max_size) - bufsize = (unsigned int)(max_size + MAX_OP_SIZE + 1); - if (max_size && bufpos > max_size) - break; - buf = git__realloc(buf, bufsize); - if (!buf) { - git__free(tmp); - return -1; - } - } - } - - if (inscnt) - buf[bufpos - inscnt - 1] = inscnt; - - if (max_size && bufpos > max_size) { - git_error_set(GIT_ERROR_NOMEMORY, "delta would be larger than maximum size"); - git__free(buf); - return GIT_EBUFS; - } - - *out_len = bufpos; - *out = buf; - return 0; -} - -/* -* Delta application was heavily cribbed from BinaryDelta.java in JGit, which -* itself was heavily cribbed from patch-delta.c in the -* GIT project. The original delta patching code was written by -* Nicolas Pitre . -*/ - -static int hdr_sz( - size_t *size, - const unsigned char **delta, - const unsigned char *end) -{ - const unsigned char *d = *delta; - size_t r = 0; - unsigned int c, shift = 0; - - do { - if (d == end) { - git_error_set(GIT_ERROR_INVALID, "truncated delta"); - return -1; - } - - if (shift >= (sizeof(size_t) * 8)) { - git_error_set(GIT_ERROR_INVALID, "delta header overflow"); - return -1; - } - c = *d++; - r |= ((size_t)(c & 0x7f)) << shift; - shift += 7; - } while (c & 0x80); - *delta = d; - *size = r; - return 0; -} - -int git_delta_read_header( - size_t *base_out, - size_t *result_out, - const unsigned char *delta, - size_t delta_len) -{ - const unsigned char *delta_end = delta + delta_len; - if ((hdr_sz(base_out, &delta, delta_end) < 0) || - (hdr_sz(result_out, &delta, delta_end) < 0)) - return -1; - return 0; -} - -#define DELTA_HEADER_BUFFER_LEN 16 -int git_delta_read_header_fromstream( - size_t *base_sz, size_t *res_sz, git_packfile_stream *stream) -{ - static const size_t buffer_len = DELTA_HEADER_BUFFER_LEN; - unsigned char buffer[DELTA_HEADER_BUFFER_LEN]; - const unsigned char *delta, *delta_end; - size_t len; - ssize_t read; - - len = read = 0; - while (len < buffer_len) { - read = git_packfile_stream_read(stream, &buffer[len], buffer_len - len); - - if (read == 0) - break; - - if (read == GIT_EBUFS) - continue; - - len += read; - } - - delta = buffer; - delta_end = delta + len; - if ((hdr_sz(base_sz, &delta, delta_end) < 0) || - (hdr_sz(res_sz, &delta, delta_end) < 0)) - return -1; - - return 0; -} - -int git_delta_apply( - void **out, - size_t *out_len, - const unsigned char *base, - size_t base_len, - const unsigned char *delta, - size_t delta_len) -{ - const unsigned char *delta_end = delta + delta_len; - size_t base_sz, res_sz, alloc_sz; - unsigned char *res_dp; - - *out = NULL; - *out_len = 0; - - /* - * Check that the base size matches the data we were given; - * if not we would underflow while accessing data from the - * base object, resulting in data corruption or segfault. - */ - if ((hdr_sz(&base_sz, &delta, delta_end) < 0) || (base_sz != base_len)) { - git_error_set(GIT_ERROR_INVALID, "failed to apply delta: base size does not match given data"); - return -1; - } - - if (hdr_sz(&res_sz, &delta, delta_end) < 0) { - git_error_set(GIT_ERROR_INVALID, "failed to apply delta: base size does not match given data"); - return -1; - } - - if (res_sz > git_indexer__max_object_size) { - git_error_set(GIT_ERROR_INVALID, - "failed to apply delta: overly large object"); - return -1; - } - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_sz, res_sz, 1); - res_dp = git__malloc(alloc_sz); - GIT_ERROR_CHECK_ALLOC(res_dp); - - res_dp[res_sz] = '\0'; - *out = res_dp; - *out_len = res_sz; - - while (delta < delta_end) { - unsigned char cmd = *delta++; - if (cmd & 0x80) { - /* cmd is a copy instruction; copy from the base. */ - size_t off = 0, len = 0, end; - -#define ADD_DELTA(o, shift) { if (delta < delta_end) (o) |= ((unsigned) *delta++ << shift); else goto fail; } - if (cmd & 0x01) ADD_DELTA(off, 0UL); - if (cmd & 0x02) ADD_DELTA(off, 8UL); - if (cmd & 0x04) ADD_DELTA(off, 16UL); - if (cmd & 0x08) ADD_DELTA(off, 24UL); - - if (cmd & 0x10) ADD_DELTA(len, 0UL); - if (cmd & 0x20) ADD_DELTA(len, 8UL); - if (cmd & 0x40) ADD_DELTA(len, 16UL); - if (!len) len = 0x10000; -#undef ADD_DELTA - - if (GIT_ADD_SIZET_OVERFLOW(&end, off, len) || - base_len < end || res_sz < len) - goto fail; - - memcpy(res_dp, base + off, len); - res_dp += len; - res_sz -= len; - - } else if (cmd) { - /* - * cmd is a literal insert instruction; copy from - * the delta stream itself. - */ - if (delta_end - delta < cmd || res_sz < cmd) - goto fail; - memcpy(res_dp, delta, cmd); - delta += cmd; - res_dp += cmd; - res_sz -= cmd; - - } else { - /* cmd == 0 is reserved for future encodings. */ - goto fail; - } - } - - if (delta != delta_end || res_sz) - goto fail; - return 0; - -fail: - git__free(*out); - - *out = NULL; - *out_len = 0; - - git_error_set(GIT_ERROR_INVALID, "failed to apply delta"); - return -1; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/delta.h b/vendor/libgit2-sys/libgit2/src/libgit2/delta.h deleted file mode 100644 index f619873..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/delta.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * diff-delta code taken from git.git. See diff-delta.c for details. - * - */ -#ifndef INCLUDE_git_delta_h__ -#define INCLUDE_git_delta_h__ - -#include "common.h" - -#include "pack.h" - -typedef struct git_delta_index git_delta_index; - -/* - * git_delta_index_init: compute index data from given buffer - * - * This returns a pointer to a struct delta_index that should be passed to - * subsequent create_delta() calls, or to free_delta_index(). A NULL pointer - * is returned on failure. The given buffer must not be freed nor altered - * before free_delta_index() is called. The returned pointer must be freed - * using free_delta_index(). - */ -extern int git_delta_index_init( - git_delta_index **out, const void *buf, size_t bufsize); - -/* - * Free the index created by git_delta_index_init() - */ -extern void git_delta_index_free(git_delta_index *index); - -/* - * Returns memory usage of delta index. - */ -extern size_t git_delta_index_size(git_delta_index *index); - -/* - * create_delta: create a delta from given index for the given buffer - * - * This function may be called multiple times with different buffers using - * the same delta_index pointer. If max_delta_size is non-zero and the - * resulting delta is to be larger than max_delta_size then NULL is returned. - * On success, a non-NULL pointer to the buffer with the delta data is - * returned and *delta_size is updated with its size. The returned buffer - * must be freed by the caller. - */ -extern int git_delta_create_from_index( - void **out, - size_t *out_size, - const struct git_delta_index *index, - const void *buf, - size_t bufsize, - size_t max_delta_size); - -/* - * diff_delta: create a delta from source buffer to target buffer - * - * If max_delta_size is non-zero and the resulting delta is to be larger - * than max_delta_size then GIT_EBUFS is returned. On success, a non-NULL - * pointer to the buffer with the delta data is returned and *delta_size is - * updated with its size. The returned buffer must be freed by the caller. - */ -GIT_INLINE(int) git_delta( - void **out, size_t *out_len, - const void *src_buf, size_t src_bufsize, - const void *trg_buf, size_t trg_bufsize, - size_t max_delta_size) -{ - git_delta_index *index; - int error = 0; - - *out = NULL; - *out_len = 0; - - if ((error = git_delta_index_init(&index, src_buf, src_bufsize)) < 0) - return error; - - if (index) { - error = git_delta_create_from_index(out, out_len, - index, trg_buf, trg_bufsize, max_delta_size); - - git_delta_index_free(index); - } - - return error; -} - -/* the smallest possible delta size is 4 bytes */ -#define GIT_DELTA_SIZE_MIN 4 - -/** -* Apply a git binary delta to recover the original content. -* The caller is responsible for freeing the returned buffer. -* -* @param out the output buffer -* @param out_len the length of the output buffer -* @param base the base to copy from during copy instructions. -* @param base_len number of bytes available at base. -* @param delta the delta to execute copy/insert instructions from. -* @param delta_len total number of bytes in the delta. -* @return 0 on success or an error code -*/ -extern int git_delta_apply( - void **out, - size_t *out_len, - const unsigned char *base, - size_t base_len, - const unsigned char *delta, - size_t delta_len); - -/** -* Read the header of a git binary delta. -* -* @param base_out pointer to store the base size field. -* @param result_out pointer to store the result size field. -* @param delta the delta to execute copy/insert instructions from. -* @param delta_len total number of bytes in the delta. -* @return 0 on success or an error code -*/ -extern int git_delta_read_header( - size_t *base_out, - size_t *result_out, - const unsigned char *delta, - size_t delta_len); - -/** - * Read the header of a git binary delta - * - * This variant reads just enough from the packfile stream to read the - * delta header. - */ -extern int git_delta_read_header_fromstream( - size_t *base_out, - size_t *result_out, - git_packfile_stream *stream); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/describe.c b/vendor/libgit2-sys/libgit2/src/libgit2/describe.c deleted file mode 100644 index dfbe7b4..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/describe.c +++ /dev/null @@ -1,912 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/describe.h" -#include "git2/diff.h" -#include "git2/status.h" - -#include "buf.h" -#include "commit.h" -#include "commit_list.h" -#include "refs.h" -#include "repository.h" -#include "revwalk.h" -#include "strarray.h" -#include "tag.h" -#include "vector.h" -#include "wildmatch.h" -#include "hashmap_oid.h" - -/* Ported from https://github.com/git/git/blob/89dde7882f71f846ccd0359756d27bebc31108de/builtin/describe.c */ - -struct commit_name { - git_tag *tag; - unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */ - unsigned name_checked:1; - git_oid sha1; - char *path; - - /* The original key for the hashmap */ - git_oid peeled; -}; - -GIT_HASHMAP_OID_SETUP(git_describe_oidmap, struct commit_name *); - -static struct commit_name *find_commit_name( - git_describe_oidmap *names, - const git_oid *peeled) -{ - struct commit_name *result; - - if (git_describe_oidmap_get(&result, names, peeled) == 0) - return result; - - return NULL; -} - -static int replace_name( - git_tag **tag, - git_repository *repo, - struct commit_name *e, - unsigned int prio, - const git_oid *sha1) -{ - git_time_t e_time = 0, t_time = 0; - - if (!e || e->prio < prio) - return 1; - - if (e->prio == 2 && prio == 2) { - /* Multiple annotated tags point to the same commit. - * Select one to keep based upon their tagger date. - */ - git_tag *t = NULL; - - if (!e->tag) { - if (git_tag_lookup(&t, repo, &e->sha1) < 0) - return 1; - e->tag = t; - } - - if (git_tag_lookup(&t, repo, sha1) < 0) - return 0; - - *tag = t; - - if (e->tag->tagger) - e_time = e->tag->tagger->when.time; - - if (t->tagger) - t_time = t->tagger->when.time; - - if (e_time < t_time) - return 1; - } - - return 0; -} - -static int add_to_known_names( - git_repository *repo, - git_describe_oidmap *names, - const char *path, - const git_oid *peeled, - unsigned int prio, - const git_oid *sha1) -{ - struct commit_name *e = find_commit_name(names, peeled); - bool found = (e != NULL); - - git_tag *tag = NULL; - if (replace_name(&tag, repo, e, prio, sha1)) { - if (!found) { - e = git__malloc(sizeof(struct commit_name)); - GIT_ERROR_CHECK_ALLOC(e); - - e->path = NULL; - e->tag = NULL; - } - - if (e->tag) - git_tag_free(e->tag); - e->tag = tag; - e->prio = prio; - e->name_checked = 0; - git_oid_cpy(&e->sha1, sha1); - git__free(e->path); - e->path = git__strdup(path); - git_oid_cpy(&e->peeled, peeled); - - if (!found && git_describe_oidmap_put(names, &e->peeled, e) < 0) - return -1; - } - else - git_tag_free(tag); - - return 0; -} - -static int retrieve_peeled_tag_or_object_oid( - git_oid *peeled_out, - git_oid *ref_target_out, - git_repository *repo, - const char *refname) -{ - git_reference *ref; - git_object *peeled = NULL; - int error; - - if ((error = git_reference_lookup_resolved(&ref, repo, refname, -1)) < 0) - return error; - - if ((error = git_reference_peel(&peeled, ref, GIT_OBJECT_ANY)) < 0) - goto cleanup; - - git_oid_cpy(ref_target_out, git_reference_target(ref)); - git_oid_cpy(peeled_out, git_object_id(peeled)); - - if (git_oid_cmp(ref_target_out, peeled_out) != 0) - error = 1; /* The reference was pointing to a annotated tag */ - else - error = 0; /* Any other object */ - -cleanup: - git_reference_free(ref); - git_object_free(peeled); - return error; -} - -struct git_describe_result { - int dirty; - int exact_match; - int fallback_to_id; - git_oid commit_id; - git_repository *repo; - struct commit_name *name; - struct possible_tag *tag; -}; - -struct get_name_data -{ - git_describe_options *opts; - git_repository *repo; - git_describe_oidmap names; - git_describe_result *result; -}; - -static int commit_name_dup(struct commit_name **out, struct commit_name *in) -{ - struct commit_name *name; - - name = git__malloc(sizeof(struct commit_name)); - GIT_ERROR_CHECK_ALLOC(name); - - memcpy(name, in, sizeof(struct commit_name)); - name->tag = NULL; - name->path = NULL; - - if (in->tag && git_tag_dup(&name->tag, in->tag) < 0) - return -1; - - name->path = git__strdup(in->path); - GIT_ERROR_CHECK_ALLOC(name->path); - - *out = name; - return 0; -} - -static int get_name(const char *refname, void *payload) -{ - struct get_name_data *data; - bool is_tag, is_annotated, all; - git_oid peeled, sha1; - unsigned int prio; - int error = 0; - - data = (struct get_name_data *)payload; - is_tag = !git__prefixcmp(refname, GIT_REFS_TAGS_DIR); - all = data->opts->describe_strategy == GIT_DESCRIBE_ALL; - - /* Reject anything outside refs/tags/ unless --all */ - if (!all && !is_tag) - return 0; - - /* Accept only tags that match the pattern, if given */ - if (data->opts->pattern && (!is_tag || wildmatch(data->opts->pattern, - refname + strlen(GIT_REFS_TAGS_DIR), 0))) - return 0; - - /* Is it annotated? */ - if ((error = retrieve_peeled_tag_or_object_oid( - &peeled, &sha1, data->repo, refname)) < 0) - return error; - - is_annotated = error; - - /* - * By default, we only use annotated tags, but with --tags - * we fall back to lightweight ones (even without --tags, - * we still remember lightweight ones, only to give hints - * in an error message). --all allows any refs to be used. - */ - if (is_annotated) - prio = 2; - else if (is_tag) - prio = 1; - else - prio = 0; - - add_to_known_names(data->repo, &data->names, - all ? refname + strlen(GIT_REFS_DIR) : refname + strlen(GIT_REFS_TAGS_DIR), - &peeled, prio, &sha1); - return 0; -} - -struct possible_tag { - struct commit_name *name; - int depth; - int found_order; - unsigned flag_within; -}; - -static int possible_tag_dup(struct possible_tag **out, struct possible_tag *in) -{ - struct possible_tag *tag; - int error; - - tag = git__malloc(sizeof(struct possible_tag)); - GIT_ERROR_CHECK_ALLOC(tag); - - memcpy(tag, in, sizeof(struct possible_tag)); - tag->name = NULL; - - if ((error = commit_name_dup(&tag->name, in->name)) < 0) { - git__free(tag); - *out = NULL; - return error; - } - - *out = tag; - return 0; -} - -static int compare_pt(const void *a_, const void *b_) -{ - struct possible_tag *a = (struct possible_tag *)a_; - struct possible_tag *b = (struct possible_tag *)b_; - if (a->depth != b->depth) - return a->depth - b->depth; - if (a->found_order != b->found_order) - return a->found_order - b->found_order; - return 0; -} - -#define SEEN (1u << 0) - -static unsigned long finish_depth_computation( - git_pqueue *list, - git_revwalk *walk, - struct possible_tag *best) -{ - unsigned long seen_commits = 0; - int error, i; - - while (git_pqueue_size(list) > 0) { - git_commit_list_node *c = git_pqueue_pop(list); - seen_commits++; - if (c->flags & best->flag_within) { - size_t index = 0; - while (git_pqueue_size(list) > index) { - git_commit_list_node *i = git_pqueue_get(list, index); - if (!(i->flags & best->flag_within)) - break; - index++; - } - if (index > git_pqueue_size(list)) - break; - } else - best->depth++; - for (i = 0; i < c->out_degree; i++) { - git_commit_list_node *p = c->parents[i]; - if ((error = git_commit_list_parse(walk, p)) < 0) - return error; - if (!(p->flags & SEEN)) - if ((error = git_pqueue_insert(list, p)) < 0) - return error; - p->flags |= c->flags; - } - } - return seen_commits; -} - -static int display_name(git_str *buf, git_repository *repo, struct commit_name *n) -{ - if (n->prio == 2 && !n->tag) { - if (git_tag_lookup(&n->tag, repo, &n->sha1) < 0) { - git_error_set(GIT_ERROR_TAG, "annotated tag '%s' not available", n->path); - return -1; - } - } - - if (n->tag && !n->name_checked) { - if (!git_tag_name(n->tag)) { - git_error_set(GIT_ERROR_TAG, "annotated tag '%s' has no embedded name", n->path); - return -1; - } - - /* TODO: Cope with warnings - if (strcmp(n->tag->tag, all ? n->path + 5 : n->path)) - warning(_("tag '%s' is really '%s' here"), n->tag->tag, n->path); - */ - - n->name_checked = 1; - } - - if (n->tag) - git_str_printf(buf, "%s", git_tag_name(n->tag)); - else - git_str_printf(buf, "%s", n->path); - - return 0; -} - -static int find_unique_abbrev_size( - int *out, - git_repository *repo, - const git_oid *oid_in, - unsigned int abbreviated_size) -{ - size_t size = abbreviated_size; - git_odb *odb; - git_oid dummy; - size_t hexsize; - int error; - - if ((error = git_repository_odb__weakptr(&odb, repo)) < 0) - return error; - - hexsize = git_oid_hexsize(repo->oid_type); - - while (size < hexsize) { - if ((error = git_odb_exists_prefix(&dummy, odb, oid_in, size)) == 0) { - *out = (int) size; - return 0; - } - - /* If the error wasn't that it's not unique, then it's a proper error */ - if (error != GIT_EAMBIGUOUS) - return error; - - /* Try again with a larger size */ - size++; - } - - /* If we didn't find any shorter prefix, we have to do the whole thing */ - *out = (int)hexsize; - - return 0; -} - -static int show_suffix( - git_str *buf, - int depth, - git_repository *repo, - const git_oid *id, - unsigned int abbrev_size) -{ - int error, size = 0; - - char hex_oid[GIT_OID_MAX_HEXSIZE]; - - if ((error = find_unique_abbrev_size(&size, repo, id, abbrev_size)) < 0) - return error; - - git_oid_fmt(hex_oid, id); - - git_str_printf(buf, "-%d-g", depth); - - git_str_put(buf, hex_oid, size); - - return git_str_oom(buf) ? -1 : 0; -} - -#define MAX_CANDIDATES_TAGS FLAG_BITS - 1 - -static int describe_not_found(const git_oid *oid, const char *message_format) { - char oid_str[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_tostr(oid_str, sizeof(oid_str), oid); - - git_error_set(GIT_ERROR_DESCRIBE, message_format, oid_str); - return GIT_ENOTFOUND; -} - -static int describe( - struct get_name_data *data, - git_commit *commit) -{ - struct commit_name *n; - struct possible_tag *best; - bool all, tags; - git_revwalk *walk = NULL; - git_pqueue list; - git_commit_list_node *cmit, *gave_up_on = NULL; - git_vector all_matches = GIT_VECTOR_INIT; - unsigned int match_cnt = 0, annotated_cnt = 0, cur_match; - unsigned long seen_commits = 0; /* TODO: Check long */ - unsigned int unannotated_cnt = 0; - int error; - - if (git_vector_init(&all_matches, MAX_CANDIDATES_TAGS, compare_pt) < 0) - return -1; - - if ((error = git_pqueue_init(&list, 0, 2, git_commit_list_time_cmp)) < 0) - goto cleanup; - - all = data->opts->describe_strategy == GIT_DESCRIBE_ALL; - tags = data->opts->describe_strategy == GIT_DESCRIBE_TAGS; - - git_oid_cpy(&data->result->commit_id, git_commit_id(commit)); - - n = find_commit_name(&data->names, git_commit_id(commit)); - if (n && (tags || all || n->prio == 2)) { - /* - * Exact match to an existing ref. - */ - data->result->exact_match = 1; - if ((error = commit_name_dup(&data->result->name, n)) < 0) - goto cleanup; - - goto cleanup; - } - - if (!data->opts->max_candidates_tags) { - error = describe_not_found( - git_commit_id(commit), - "cannot describe - no tag exactly matches '%s'"); - - goto cleanup; - } - - if ((error = git_revwalk_new(&walk, git_commit_owner(commit))) < 0) - goto cleanup; - - if ((cmit = git_revwalk__commit_lookup(walk, git_commit_id(commit))) == NULL) - goto cleanup; - - if ((error = git_commit_list_parse(walk, cmit)) < 0) - goto cleanup; - - cmit->flags = SEEN; - - if ((error = git_pqueue_insert(&list, cmit)) < 0) - goto cleanup; - - while (git_pqueue_size(&list) > 0) - { - int i; - - git_commit_list_node *c = (git_commit_list_node *)git_pqueue_pop(&list); - seen_commits++; - - n = find_commit_name(&data->names, &c->oid); - - if (n) { - if (!tags && !all && n->prio < 2) { - unannotated_cnt++; - } else if (match_cnt < data->opts->max_candidates_tags) { - struct possible_tag *t = git__malloc(sizeof(struct commit_name)); - GIT_ERROR_CHECK_ALLOC(t); - if ((error = git_vector_insert(&all_matches, t)) < 0) - goto cleanup; - - match_cnt++; - - t->name = n; - t->depth = seen_commits - 1; - t->flag_within = 1u << match_cnt; - t->found_order = match_cnt; - c->flags |= t->flag_within; - if (n->prio == 2) - annotated_cnt++; - } - else { - gave_up_on = c; - break; - } - } - - for (cur_match = 0; cur_match < match_cnt; cur_match++) { - struct possible_tag *t = git_vector_get(&all_matches, cur_match); - if (!(c->flags & t->flag_within)) - t->depth++; - } - - if (annotated_cnt && (git_pqueue_size(&list) == 0)) { - /* - if (debug) { - char oid_str[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_tostr(oid_str, sizeof(oid_str), &c->oid); - - fprintf(stderr, "finished search at %s\n", oid_str); - } - */ - break; - } - for (i = 0; i < c->out_degree; i++) { - git_commit_list_node *p = c->parents[i]; - if ((error = git_commit_list_parse(walk, p)) < 0) - goto cleanup; - if (!(p->flags & SEEN)) - if ((error = git_pqueue_insert(&list, p)) < 0) - goto cleanup; - p->flags |= c->flags; - - if (data->opts->only_follow_first_parent) - break; - } - } - - if (!match_cnt) { - if (data->opts->show_commit_oid_as_fallback) { - data->result->fallback_to_id = 1; - git_oid_cpy(&data->result->commit_id, &cmit->oid); - - goto cleanup; - } - if (unannotated_cnt) { - error = describe_not_found(git_commit_id(commit), - "cannot describe - " - "no annotated tags can describe '%s'; " - "however, there were unannotated tags."); - goto cleanup; - } - else { - error = describe_not_found(git_commit_id(commit), - "cannot describe - " - "no tags can describe '%s'."); - goto cleanup; - } - } - - git_vector_sort(&all_matches); - - best = (struct possible_tag *)git_vector_get(&all_matches, 0); - - if (gave_up_on) { - if ((error = git_pqueue_insert(&list, gave_up_on)) < 0) - goto cleanup; - seen_commits--; - } - if ((error = finish_depth_computation( - &list, walk, best)) < 0) - goto cleanup; - - seen_commits += error; - if ((error = possible_tag_dup(&data->result->tag, best)) < 0) - goto cleanup; - - /* - { - static const char *prio_names[] = { - "head", "lightweight", "annotated", - }; - - char oid_str[GIT_OID_MAX_HEXSIZE + 1]; - - if (debug) { - for (cur_match = 0; cur_match < match_cnt; cur_match++) { - struct possible_tag *t = (struct possible_tag *)git_vector_get(&all_matches, cur_match); - fprintf(stderr, " %-11s %8d %s\n", - prio_names[t->name->prio], - t->depth, t->name->path); - } - fprintf(stderr, "traversed %lu commits\n", seen_commits); - if (gave_up_on) { - git_oid_tostr(oid_str, sizeof(oid_str), &gave_up_on->oid); - fprintf(stderr, - "more than %i tags found; listed %i most recent\n" - "gave up search at %s\n", - data->opts->max_candidates_tags, data->opts->max_candidates_tags, - oid_str); - } - } - } - */ - - git_oid_cpy(&data->result->commit_id, &cmit->oid); - -cleanup: - { - size_t i; - struct possible_tag *match; - git_vector_foreach(&all_matches, i, match) { - git__free(match); - } - } - git_vector_dispose(&all_matches); - git_pqueue_free(&list); - git_revwalk_free(walk); - return error; -} - -static int normalize_options( - git_describe_options *dst, - const git_describe_options *src) -{ - git_describe_options default_options = GIT_DESCRIBE_OPTIONS_INIT; - if (!src) src = &default_options; - - *dst = *src; - - if (dst->max_candidates_tags > GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS) - dst->max_candidates_tags = GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS; - - return 0; -} - -int git_describe_commit( - git_describe_result **result, - git_object *committish, - git_describe_options *opts) -{ - struct get_name_data data = {0}; - struct commit_name *name; - git_commit *commit; - git_describe_options normalized; - git_hashmap_iter_t iter = GIT_HASHMAP_INIT; - int error = -1; - - GIT_ASSERT_ARG(result); - GIT_ASSERT_ARG(committish); - - data.result = git__calloc(1, sizeof(git_describe_result)); - GIT_ERROR_CHECK_ALLOC(data.result); - data.result->repo = git_object_owner(committish); - - data.repo = git_object_owner(committish); - - if ((error = normalize_options(&normalized, opts)) < 0) - return error; - - GIT_ERROR_CHECK_VERSION( - &normalized, - GIT_DESCRIBE_OPTIONS_VERSION, - "git_describe_options"); - data.opts = &normalized; - - /** TODO: contains to be implemented */ - - if ((error = git_object_peel((git_object **)(&commit), committish, GIT_OBJECT_COMMIT)) < 0) - goto cleanup; - - if ((error = git_reference_foreach_name( - git_object_owner(committish), - get_name, &data)) < 0) - goto cleanup; - - if (git_describe_oidmap_size(&data.names) == 0 && !normalized.show_commit_oid_as_fallback) { - git_error_set(GIT_ERROR_DESCRIBE, "cannot describe - " - "no reference found, cannot describe anything."); - error = -1; - goto cleanup; - } - - if ((error = describe(&data, commit)) < 0) - goto cleanup; - -cleanup: - git_commit_free(commit); - - while (git_describe_oidmap_iterate(&iter, NULL, &name, &data.names) == 0) { - git_tag_free(name->tag); - git__free(name->path); - git__free(name); - } - - git_describe_oidmap_dispose(&data.names); - - if (error < 0) - git_describe_result_free(data.result); - else - *result = data.result; - - return error; -} - -int git_describe_workdir( - git_describe_result **out, - git_repository *repo, - git_describe_options *opts) -{ - int error; - git_oid current_id; - git_status_list *status = NULL; - git_status_options status_opts = GIT_STATUS_OPTIONS_INIT; - git_describe_result *result = NULL; - git_object *commit; - - if ((error = git_reference_name_to_id(¤t_id, repo, GIT_HEAD_FILE)) < 0) - return error; - - if ((error = git_object_lookup(&commit, repo, ¤t_id, GIT_OBJECT_COMMIT)) < 0) - return error; - - /* The first step is to perform a describe of HEAD, so we can leverage this */ - if ((error = git_describe_commit(&result, commit, opts)) < 0) - goto out; - - if ((error = git_status_list_new(&status, repo, &status_opts)) < 0) - goto out; - - - if (git_status_list_entrycount(status) > 0) - result->dirty = 1; - -out: - git_object_free(commit); - git_status_list_free(status); - - if (error < 0) - git_describe_result_free(result); - else - *out = result; - - return error; -} - -static int normalize_format_options( - git_describe_format_options *dst, - const git_describe_format_options *src) -{ - if (!src) { - git_describe_format_options_init(dst, GIT_DESCRIBE_FORMAT_OPTIONS_VERSION); - return 0; - } - - memcpy(dst, src, sizeof(git_describe_format_options)); - return 0; -} - -static int git_describe__format( - git_str *out, - const git_describe_result *result, - const git_describe_format_options *given) -{ - int error; - git_repository *repo; - struct commit_name *name; - git_describe_format_options opts; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(result); - - GIT_ERROR_CHECK_VERSION(given, GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, "git_describe_format_options"); - normalize_format_options(&opts, given); - - if (opts.always_use_long_format && opts.abbreviated_size == 0) { - git_error_set(GIT_ERROR_DESCRIBE, "cannot describe - " - "'always_use_long_format' is incompatible with a zero" - "'abbreviated_size'"); - return -1; - } - - - repo = result->repo; - - /* If we did find an exact match, then it's the easier method */ - if (result->exact_match) { - name = result->name; - if ((error = display_name(out, repo, name)) < 0) - return error; - - if (opts.always_use_long_format) { - const git_oid *id = name->tag ? git_tag_target_id(name->tag) : &result->commit_id; - if ((error = show_suffix(out, 0, repo, id, opts.abbreviated_size)) < 0) - return error; - } - - if (result->dirty && opts.dirty_suffix) - git_str_puts(out, opts.dirty_suffix); - - return git_str_oom(out) ? -1 : 0; - } - - /* If we didn't find *any* tags, we fall back to the commit's id */ - if (result->fallback_to_id) { - char hex_oid[GIT_OID_MAX_HEXSIZE + 1] = {0}; - int size = 0; - - if ((error = find_unique_abbrev_size( - &size, repo, &result->commit_id, opts.abbreviated_size)) < 0) - return -1; - - git_oid_fmt(hex_oid, &result->commit_id); - git_str_put(out, hex_oid, size); - - if (result->dirty && opts.dirty_suffix) - git_str_puts(out, opts.dirty_suffix); - - return git_str_oom(out) ? -1 : 0; - } - - /* Lastly, if we found a matching tag, we show that */ - name = result->tag->name; - - if ((error = display_name(out, repo, name)) < 0) - return error; - - if (opts.abbreviated_size) { - if ((error = show_suffix(out, result->tag->depth, repo, - &result->commit_id, opts.abbreviated_size)) < 0) - return error; - } - - if (result->dirty && opts.dirty_suffix) { - git_str_puts(out, opts.dirty_suffix); - } - - return git_str_oom(out) ? -1 : 0; -} - -int git_describe_format( - git_buf *out, - const git_describe_result *result, - const git_describe_format_options *given) -{ - GIT_BUF_WRAP_PRIVATE(out, git_describe__format, result, given); -} - -void git_describe_result_free(git_describe_result *result) -{ - if (result == NULL) - return; - - if (result->name) { - git_tag_free(result->name->tag); - git__free(result->name->path); - git__free(result->name); - } - - if (result->tag) { - git_tag_free(result->tag->name->tag); - git__free(result->tag->name->path); - git__free(result->tag->name); - git__free(result->tag); - } - - git__free(result); -} - -int git_describe_options_init(git_describe_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_describe_options, GIT_DESCRIBE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_describe_init_options(git_describe_options *opts, unsigned int version) -{ - return git_describe_options_init(opts, version); -} -#endif - -int git_describe_format_options_init(git_describe_format_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_describe_format_options, GIT_DESCRIBE_FORMAT_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_describe_init_format_options(git_describe_format_options *opts, unsigned int version) -{ - return git_describe_format_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff.c deleted file mode 100644 index 80027ba..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff.c +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "diff.h" - -#include "common.h" -#include "buf.h" -#include "patch.h" -#include "email.h" -#include "commit.h" -#include "index.h" -#include "diff_generate.h" - -#include "git2/version.h" -#include "git2/sys/email.h" - -struct patch_id_args { - git_diff *diff; - git_hash_ctx ctx; - git_oid result; - git_oid_t oid_type; - int first_file; -}; - -GIT_INLINE(const char *) diff_delta__path(const git_diff_delta *delta) -{ - const char *str = delta->old_file.path; - - if (!str || - delta->status == GIT_DELTA_ADDED || - delta->status == GIT_DELTA_RENAMED || - delta->status == GIT_DELTA_COPIED) - str = delta->new_file.path; - - return str; -} - -int git_diff_delta__cmp(const void *a, const void *b) -{ - const git_diff_delta *da = a, *db = b; - int val = strcmp(diff_delta__path(da), diff_delta__path(db)); - return val ? val : ((int)da->status - (int)db->status); -} - -int git_diff_delta__casecmp(const void *a, const void *b) -{ - const git_diff_delta *da = a, *db = b; - int val = strcasecmp(diff_delta__path(da), diff_delta__path(db)); - return val ? val : ((int)da->status - (int)db->status); -} - -int git_diff__entry_cmp(const void *a, const void *b) -{ - const git_index_entry *entry_a = a; - const git_index_entry *entry_b = b; - - return strcmp(entry_a->path, entry_b->path); -} - -int git_diff__entry_icmp(const void *a, const void *b) -{ - const git_index_entry *entry_a = a; - const git_index_entry *entry_b = b; - - return strcasecmp(entry_a->path, entry_b->path); -} - -void git_diff_free(git_diff *diff) -{ - if (!diff) - return; - - GIT_REFCOUNT_DEC(diff, diff->free_fn); -} - -void git_diff_addref(git_diff *diff) -{ - GIT_REFCOUNT_INC(diff); -} - -size_t git_diff_num_deltas(const git_diff *diff) -{ - GIT_ASSERT_ARG(diff); - return diff->deltas.length; -} - -size_t git_diff_num_deltas_of_type(const git_diff *diff, git_delta_t type) -{ - size_t i, count = 0; - const git_diff_delta *delta; - - GIT_ASSERT_ARG(diff); - - git_vector_foreach(&diff->deltas, i, delta) { - count += (delta->status == type); - } - - return count; -} - -const git_diff_delta *git_diff_get_delta(const git_diff *diff, size_t idx) -{ - GIT_ASSERT_ARG_WITH_RETVAL(diff, NULL); - return git_vector_get(&diff->deltas, idx); -} - -int git_diff_is_sorted_icase(const git_diff *diff) -{ - return (diff->opts.flags & GIT_DIFF_IGNORE_CASE) != 0; -} - -int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff) -{ - GIT_ASSERT_ARG(out); - GIT_ERROR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata"); - out->stat_calls = diff->perf.stat_calls; - out->oid_calculations = diff->perf.oid_calculations; - return 0; -} - -int git_diff_foreach( - git_diff *diff, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb data_cb, - void *payload) -{ - int error = 0; - git_diff_delta *delta; - size_t idx; - - GIT_ASSERT_ARG(diff); - - git_vector_foreach(&diff->deltas, idx, delta) { - git_patch *patch; - - /* check flags against patch status */ - if (git_diff_delta__should_skip(&diff->opts, delta)) - continue; - - if ((error = git_patch_from_diff(&patch, diff, idx)) != 0) - break; - - error = git_patch__invoke_callbacks(patch, file_cb, binary_cb, - hunk_cb, data_cb, payload); - git_patch_free(patch); - - if (error) - break; - } - - return error; -} - -#ifndef GIT_DEPRECATE_HARD - -int git_diff_format_email( - git_buf *out, - git_diff *diff, - const git_diff_format_email_options *opts) -{ - git_email_create_options email_create_opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - git_str email = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diff); - GIT_ASSERT_ARG(opts && opts->summary && opts->id && opts->author); - - GIT_ERROR_CHECK_VERSION(opts, - GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, - "git_format_email_options"); - - /* This is a `git_buf` special case; subsequent calls append. */ - email.ptr = out->ptr; - email.asize = out->reserved; - email.size = out->size; - - out->ptr = git_str__initstr; - out->reserved = 0; - out->size = 0; - - if ((opts->flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0) - email_create_opts.subject_prefix = ""; - - error = git_email__append_from_diff(&email, diff, opts->patch_no, - opts->total_patches, opts->id, opts->summary, opts->body, - opts->author, &email_create_opts); - - if (error < 0) - goto done; - - error = git_buf_fromstr(out, &email); - -done: - git_str_dispose(&email); - return error; -} - -int git_diff_commit_as_email( - git_buf *out, - git_repository *repo, - git_commit *commit, - size_t patch_no, - size_t total_patches, - uint32_t flags, - const git_diff_options *diff_opts) -{ - git_diff *diff = NULL; - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - const git_oid *commit_id; - const char *summary, *body; - const git_signature *author; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(commit); - - commit_id = git_commit_id(commit); - summary = git_commit_summary(commit); - body = git_commit_body(commit); - author = git_commit_author(commit); - - if ((flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0) - opts.subject_prefix = ""; - - if ((error = git_diff__commit(&diff, repo, commit, diff_opts)) < 0) - return error; - - error = git_email_create_from_diff(out, diff, patch_no, total_patches, commit_id, summary, body, author, &opts); - - git_diff_free(diff); - return error; -} - -int git_diff_init_options(git_diff_options *opts, unsigned int version) -{ - return git_diff_options_init(opts, version); -} - -int git_diff_find_init_options( - git_diff_find_options *opts, unsigned int version) -{ - return git_diff_find_options_init(opts, version); -} - -int git_diff_format_email_options_init( - git_diff_format_email_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_diff_format_email_options, - GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT); - return 0; -} - -int git_diff_format_email_init_options( - git_diff_format_email_options *opts, unsigned int version) -{ - return git_diff_format_email_options_init(opts, version); -} - -#endif - -int git_diff_options_init(git_diff_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_diff_options, GIT_DIFF_OPTIONS_INIT); - return 0; -} - -int git_diff_find_options_init( - git_diff_find_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_diff_find_options, GIT_DIFF_FIND_OPTIONS_INIT); - return 0; -} - -static int flush_hunk(git_oid *result, struct patch_id_args *args) -{ - git_hash_ctx *ctx = &args->ctx; - git_oid hash; - unsigned short carry = 0; - size_t i; - int error; - - if ((error = git_hash_final(hash.id, ctx)) < 0 || - (error = git_hash_init(ctx)) < 0) - return error; - - for (i = 0; i < git_oid_size(args->oid_type); i++) { - carry += result->id[i] + hash.id[i]; - result->id[i] = (unsigned char)carry; - carry >>= 8; - } - - return 0; -} - -static void strip_spaces(git_str *buf) -{ - char *src = buf->ptr, *dst = buf->ptr; - char c; - size_t len = 0; - - while ((c = *src++) != '\0') { - if (!git__isspace(c)) { - *dst++ = c; - len++; - } - } - - git_str_truncate(buf, len); -} - -static int diff_patchid_print_callback_to_buf( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - const git_diff_line *line, - void *payload) -{ - struct patch_id_args *args = (struct patch_id_args *) payload; - git_str buf = GIT_STR_INIT; - int error = 0; - - if (line->origin == GIT_DIFF_LINE_CONTEXT_EOFNL || - line->origin == GIT_DIFF_LINE_ADD_EOFNL || - line->origin == GIT_DIFF_LINE_DEL_EOFNL) - goto out; - - if ((error = git_diff_print_callback__to_buf(delta, hunk, - line, &buf)) < 0) - goto out; - - strip_spaces(&buf); - - if (line->origin == GIT_DIFF_LINE_FILE_HDR && - !args->first_file && - (error = flush_hunk(&args->result, args) < 0)) - goto out; - - if ((error = git_hash_update(&args->ctx, buf.ptr, buf.size)) < 0) - goto out; - - if (line->origin == GIT_DIFF_LINE_FILE_HDR && args->first_file) - args->first_file = 0; - -out: - git_str_dispose(&buf); - return error; -} - -int git_diff_patchid_options_init(git_diff_patchid_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_diff_patchid_options, GIT_DIFF_PATCHID_OPTIONS_INIT); - return 0; -} - -int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opts) -{ - struct patch_id_args args; - git_hash_algorithm_t algorithm; - int error; - - GIT_ERROR_CHECK_VERSION( - opts, GIT_DIFF_PATCHID_OPTIONS_VERSION, "git_diff_patchid_options"); - - algorithm = git_oid_algorithm(diff->opts.oid_type); - - memset(&args, 0, sizeof(args)); - args.diff = diff; - args.first_file = 1; - args.oid_type = diff->opts.oid_type; - if ((error = git_hash_ctx_init(&args.ctx, algorithm)) < 0) - goto out; - - if ((error = git_diff_print(diff, - GIT_DIFF_FORMAT_PATCH_ID, - diff_patchid_print_callback_to_buf, - &args)) < 0) - goto out; - - if ((error = (flush_hunk(&args.result, &args))) < 0) - goto out; - -#ifdef GIT_EXPERIMENTAL_SHA256 - args.result.type = diff->opts.oid_type; -#endif - - git_oid_cpy(out, &args.result); - -out: - git_hash_ctx_cleanup(&args.ctx); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff.h b/vendor/libgit2-sys/libgit2/src/libgit2/diff.h deleted file mode 100644 index f21b276..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_diff_h__ -#define INCLUDE_diff_h__ - -#include "common.h" - -#include "git2/diff.h" -#include "git2/patch.h" -#include "git2/sys/diff.h" -#include "git2/oid.h" - -#include "vector.h" -#include "iterator.h" -#include "repository.h" -#include "pool.h" -#include "odb.h" - -#define DIFF_OLD_PREFIX_DEFAULT "a/" -#define DIFF_NEW_PREFIX_DEFAULT "b/" - -typedef enum { - GIT_DIFF_TYPE_UNKNOWN = 0, - GIT_DIFF_TYPE_GENERATED = 1, - GIT_DIFF_TYPE_PARSED = 2 -} git_diff_origin_t; - -struct git_diff { - git_refcount rc; - git_repository *repo; - git_attr_session attrsession; - git_diff_origin_t type; - git_diff_options opts; - git_vector deltas; /* vector of git_diff_delta */ - git_pool pool; - git_iterator_t old_src; - git_iterator_t new_src; - git_diff_perfdata perf; - - int (*strcomp)(const char *, const char *); - int (*strncomp)(const char *, const char *, size_t); - int (*pfxcomp)(const char *str, const char *pfx); - int (*entrycomp)(const void *a, const void *b); - - int (*patch_fn)(git_patch **out, git_diff *diff, size_t idx); - void (*free_fn)(git_diff *diff); -}; - -extern int git_diff_delta__format_file_header( - git_str *out, - const git_diff_delta *delta, - const char *oldpfx, - const char *newpfx, - int oid_strlen, - bool print_index); - -extern int git_diff_delta__cmp(const void *a, const void *b); -extern int git_diff_delta__casecmp(const void *a, const void *b); - -extern int git_diff__entry_cmp(const void *a, const void *b); -extern int git_diff__entry_icmp(const void *a, const void *b); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_driver.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff_driver.c deleted file mode 100644 index c2c421c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_driver.c +++ /dev/null @@ -1,515 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "diff_driver.h" - -#include "git2/attr.h" - -#include "common.h" -#include "diff.h" -#include "map.h" -#include "config.h" -#include "regexp.h" -#include "repository.h" -#include "userdiff.h" - -typedef enum { - DIFF_DRIVER_AUTO = 0, - DIFF_DRIVER_BINARY = 1, - DIFF_DRIVER_TEXT = 2, - DIFF_DRIVER_PATTERNLIST = 3 -} git_diff_driver_t; - -typedef struct { - git_regexp re; - int flags; -} git_diff_driver_pattern; - -enum { - REG_NEGATE = (1 << 15) /* get out of the way of existing flags */ -}; - -/* data for finding function context for a given file type */ -struct git_diff_driver { - git_diff_driver_t type; - uint32_t binary_flags; - uint32_t other_flags; - git_array_t(git_diff_driver_pattern) fn_patterns; - git_regexp word_pattern; - char name[GIT_FLEX_ARRAY]; -}; - -GIT_HASHMAP_STR_SETUP(git_diff_driver_map, git_diff_driver *); - -struct git_diff_driver_registry { - git_diff_driver_map map; -}; - -#define FORCE_DIFFABLE (GIT_DIFF_FORCE_TEXT | GIT_DIFF_FORCE_BINARY) - -static git_diff_driver diff_driver_auto = { DIFF_DRIVER_AUTO, 0, 0 }; -static git_diff_driver diff_driver_binary = { DIFF_DRIVER_BINARY, GIT_DIFF_FORCE_BINARY, 0 }; -static git_diff_driver diff_driver_text = { DIFF_DRIVER_TEXT, GIT_DIFF_FORCE_TEXT, 0 }; - -git_diff_driver_registry *git_diff_driver_registry_new(void) -{ - return git__calloc(1, sizeof(git_diff_driver_registry)); -} - -void git_diff_driver_registry_free(git_diff_driver_registry *reg) -{ - git_diff_driver *drv; - git_hashmap_iter_t iter = 0; - - if (!reg) - return; - - while (git_diff_driver_map_iterate(&iter, NULL, &drv, ®->map) == 0) - git_diff_driver_free(drv); - - git_diff_driver_map_dispose(®->map); - git__free(reg); -} - -static int diff_driver_add_patterns( - git_diff_driver *drv, const char *regex_str, int regex_flags) -{ - int error = 0; - const char *scan, *end; - git_diff_driver_pattern *pat = NULL; - git_str buf = GIT_STR_INIT; - - for (scan = regex_str; scan; scan = end) { - /* get pattern to fill in */ - if ((pat = git_array_alloc(drv->fn_patterns)) == NULL) { - return -1; - } - - pat->flags = regex_flags; - if (*scan == '!') { - pat->flags |= REG_NEGATE; - ++scan; - } - - if ((end = strchr(scan, '\n')) != NULL) { - error = git_str_set(&buf, scan, end - scan); - end++; - } else { - error = git_str_sets(&buf, scan); - } - if (error < 0) - break; - - if ((error = git_regexp_compile(&pat->re, buf.ptr, regex_flags)) != 0) { - /* - * TODO: issue a warning - */ - } - } - - if (error && pat != NULL) - (void)git_array_pop(drv->fn_patterns); /* release last item */ - git_str_dispose(&buf); - - /* We want to ignore bad patterns, so return success regardless */ - return 0; -} - -static int diff_driver_xfuncname(const git_config_entry *entry, void *payload) -{ - return diff_driver_add_patterns(payload, entry->value, 0); -} - -static int diff_driver_funcname(const git_config_entry *entry, void *payload) -{ - return diff_driver_add_patterns(payload, entry->value, 0); -} - -static git_diff_driver_registry *git_repository_driver_registry( - git_repository *repo) -{ - git_diff_driver_registry *reg = git_atomic_load(repo->diff_drivers), *newreg; - if (reg) - return reg; - - newreg = git_diff_driver_registry_new(); - if (!newreg) { - git_error_set(GIT_ERROR_REPOSITORY, "unable to create diff driver registry"); - return newreg; - } - reg = git_atomic_compare_and_swap(&repo->diff_drivers, NULL, newreg); - if (!reg) { - reg = newreg; - } else { - /* if we race, free losing allocation */ - git_diff_driver_registry_free(newreg); - } - return reg; -} - -static int diff_driver_alloc( - git_diff_driver **out, size_t *namelen_out, const char *name) -{ - git_diff_driver *driver; - size_t driverlen = sizeof(git_diff_driver), - namelen = strlen(name), - alloclen; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, driverlen, namelen); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); - - driver = git__calloc(1, alloclen); - GIT_ERROR_CHECK_ALLOC(driver); - - memcpy(driver->name, name, namelen); - - *out = driver; - - if (namelen_out) - *namelen_out = namelen; - - return 0; -} - -static int git_diff_driver_builtin( - git_diff_driver **out, - git_diff_driver_registry *reg, - const char *driver_name) -{ - git_diff_driver_definition *ddef = NULL; - git_diff_driver *drv = NULL; - int error = 0; - size_t idx; - - for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) { - if (!strcasecmp(driver_name, builtin_defs[idx].name)) { - ddef = &builtin_defs[idx]; - break; - } - } - if (!ddef) - goto done; - - if ((error = diff_driver_alloc(&drv, NULL, ddef->name)) < 0) - goto done; - - drv->type = DIFF_DRIVER_PATTERNLIST; - - if (ddef->fns && - (error = diff_driver_add_patterns( - drv, ddef->fns, ddef->flags)) < 0) - goto done; - - if (ddef->words && - (error = git_regexp_compile(&drv->word_pattern, ddef->words, ddef->flags)) < 0) - goto done; - - if ((error = git_diff_driver_map_put(®->map, drv->name, drv)) < 0) - goto done; - -done: - if (error && drv) - git_diff_driver_free(drv); - else - *out = drv; - - return error; -} - -static int git_diff_driver_load( - git_diff_driver **out, git_repository *repo, const char *driver_name) -{ - int error = 0; - git_diff_driver_registry *reg; - git_diff_driver *drv = NULL; - size_t namelen; - git_config *cfg = NULL; - git_str name = GIT_STR_INIT; - git_config_entry *ce = NULL; - bool found_driver = false; - - if ((reg = git_repository_driver_registry(repo)) == NULL) - return -1; - - if (git_diff_driver_map_get(&drv, ®->map, driver_name) == 0) { - *out = drv; - return 0; - } - - if ((error = diff_driver_alloc(&drv, &namelen, driver_name)) < 0) - goto done; - - drv->type = DIFF_DRIVER_AUTO; - - /* if you can't read config for repo, just use default driver */ - if (git_repository_config_snapshot(&cfg, repo) < 0) { - git_error_clear(); - goto done; - } - - if ((error = git_str_printf(&name, "diff.%s.binary", driver_name)) < 0) - goto done; - - switch (git_config__get_bool_force(cfg, name.ptr, -1)) { - case true: - /* if diff..binary is true, just return the binary driver */ - *out = &diff_driver_binary; - goto done; - case false: - /* if diff..binary is false, force binary checks off */ - /* but still may have custom function context patterns, etc. */ - drv->binary_flags = GIT_DIFF_FORCE_TEXT; - found_driver = true; - break; - default: - /* diff..binary unspecified or "auto", so just continue */ - break; - } - - /* TODO: warn if diff..command or diff..textconv are set */ - - git_str_truncate(&name, namelen + strlen("diff..")); - if ((error = git_str_PUTS(&name, "xfuncname")) < 0) - goto done; - - if ((error = git_config_get_multivar_foreach( - cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) { - if (error != GIT_ENOTFOUND) - goto done; - git_error_clear(); /* no diff..xfuncname, so just continue */ - } - - git_str_truncate(&name, namelen + strlen("diff..")); - if ((error = git_str_PUTS(&name, "funcname")) < 0) - goto done; - - if ((error = git_config_get_multivar_foreach( - cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) { - if (error != GIT_ENOTFOUND) - goto done; - git_error_clear(); /* no diff..funcname, so just continue */ - } - - /* if we found any patterns, set driver type to use correct callback */ - if (git_array_size(drv->fn_patterns) > 0) { - drv->type = DIFF_DRIVER_PATTERNLIST; - found_driver = true; - } - - git_str_truncate(&name, namelen + strlen("diff..")); - if ((error = git_str_PUTS(&name, "wordregex")) < 0) - goto done; - - if ((error = git_config__lookup_entry(&ce, cfg, name.ptr, false)) < 0) - goto done; - if (!ce || !ce->value) - /* no diff..wordregex, so just continue */; - else if (!(error = git_regexp_compile(&drv->word_pattern, ce->value, 0))) - found_driver = true; - else { - /* TODO: warn about bad regex instead of failure */ - goto done; - } - - /* TODO: look up diff..algorithm to turn on minimal / patience - * diff in drv->other_flags - */ - - /* if no driver config found at all, fall back on AUTO driver */ - if (!found_driver) - goto done; - - /* store driver in registry */ - if ((error = git_diff_driver_map_put(®->map, drv->name, drv)) < 0) - goto done; - - *out = drv; - -done: - git_config_entry_free(ce); - git_str_dispose(&name); - git_config_free(cfg); - - if (!*out) { - int error2 = git_diff_driver_builtin(out, reg, driver_name); - if (!error) - error = error2; - } - - if (drv && drv != *out) - git_diff_driver_free(drv); - - return error; -} - -int git_diff_driver_lookup( - git_diff_driver **out, git_repository *repo, - git_attr_session *attrsession, const char *path) -{ - int error = 0; - const char *values[1], *attrs[] = { "diff" }; - - GIT_ASSERT_ARG(out); - *out = NULL; - - if (!repo || !path || !strlen(path)) - /* just use the auto value */; - else if ((error = git_attr_get_many_with_session(values, repo, - attrsession, 0, path, 1, attrs)) < 0) - /* return error below */; - - else if (GIT_ATTR_IS_UNSPECIFIED(values[0])) - /* just use the auto value */; - else if (GIT_ATTR_IS_FALSE(values[0])) - *out = &diff_driver_binary; - else if (GIT_ATTR_IS_TRUE(values[0])) - *out = &diff_driver_text; - - /* otherwise look for driver information in config and build driver */ - else if ((error = git_diff_driver_load(out, repo, values[0])) < 0) { - if (error == GIT_ENOTFOUND) { - error = 0; - git_error_clear(); - } - } - - if (!*out) - *out = &diff_driver_auto; - - return error; -} - -void git_diff_driver_free(git_diff_driver *driver) -{ - git_diff_driver_pattern *pat; - - if (!driver) - return; - - while ((pat = git_array_pop(driver->fn_patterns)) != NULL) - git_regexp_dispose(&pat->re); - git_array_clear(driver->fn_patterns); - - git_regexp_dispose(&driver->word_pattern); - - git__free(driver); -} - -void git_diff_driver_update_options( - uint32_t *option_flags, git_diff_driver *driver) -{ - if ((*option_flags & FORCE_DIFFABLE) == 0) - *option_flags |= driver->binary_flags; - - *option_flags |= driver->other_flags; -} - -int git_diff_driver_content_is_binary( - git_diff_driver *driver, const char *content, size_t content_len) -{ - git_str search = GIT_STR_INIT; - - GIT_UNUSED(driver); - - git_str_attach_notowned(&search, content, - min(content_len, GIT_FILTER_BYTES_TO_CHECK_NUL)); - - /* TODO: provide encoding / binary detection callbacks that can - * be UTF-8 aware, etc. For now, instead of trying to be smart, - * let's just use the simple NUL-byte detection that core git uses. - */ - - /* previously was: if (git_str_is_binary(&search)) */ - if (git_str_contains_nul(&search)) - return 1; - - return 0; -} - -static int diff_context_line__simple( - git_diff_driver *driver, git_str *line) -{ - char firstch = line->ptr[0]; - GIT_UNUSED(driver); - return (git__isalpha(firstch) || firstch == '_' || firstch == '$'); -} - -static int diff_context_line__pattern_match( - git_diff_driver *driver, git_str *line) -{ - size_t i, maxi = git_array_size(driver->fn_patterns); - git_regmatch pmatch[2]; - - for (i = 0; i < maxi; ++i) { - git_diff_driver_pattern *pat = git_array_get(driver->fn_patterns, i); - - if (!git_regexp_search(&pat->re, line->ptr, 2, pmatch)) { - if (pat->flags & REG_NEGATE) - return false; - - /* use pmatch data to trim line data */ - i = (pmatch[1].start >= 0) ? 1 : 0; - git_str_consume(line, git_str_cstr(line) + pmatch[i].start); - git_str_truncate(line, pmatch[i].end - pmatch[i].start); - git_str_rtrim(line); - - return true; - } - } - - return false; -} - -static long diff_context_find( - const char *line, - long line_len, - char *out, - long out_size, - void *payload) -{ - git_diff_find_context_payload *ctxt = payload; - - if (git_str_set(&ctxt->line, line, (size_t)line_len) < 0) - return -1; - git_str_rtrim(&ctxt->line); - - if (!ctxt->line.size) - return -1; - - if (!ctxt->match_line || !ctxt->match_line(ctxt->driver, &ctxt->line)) - return -1; - - if (out_size > (long)ctxt->line.size) - out_size = (long)ctxt->line.size; - memcpy(out, ctxt->line.ptr, (size_t)out_size); - - return out_size; -} - -void git_diff_find_context_init( - git_diff_find_context_fn *findfn_out, - git_diff_find_context_payload *payload_out, - git_diff_driver *driver) -{ - *findfn_out = driver ? diff_context_find : NULL; - - memset(payload_out, 0, sizeof(*payload_out)); - if (driver) { - payload_out->driver = driver; - payload_out->match_line = (driver->type == DIFF_DRIVER_PATTERNLIST) ? - diff_context_line__pattern_match : diff_context_line__simple; - git_str_init(&payload_out->line, 0); - } -} - -void git_diff_find_context_clear(git_diff_find_context_payload *payload) -{ - if (payload) { - git_str_dispose(&payload->line); - payload->driver = NULL; - } -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_driver.h b/vendor/libgit2-sys/libgit2/src/libgit2/diff_driver.h deleted file mode 100644 index ca0a7ae..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_driver.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_diff_driver_h__ -#define INCLUDE_diff_driver_h__ - -#include "common.h" - -#include "attr_file.h" -#include "str.h" -#include "hashmap.h" - -typedef struct git_diff_driver git_diff_driver; -typedef struct git_diff_driver_registry git_diff_driver_registry; - -git_diff_driver_registry *git_diff_driver_registry_new(void); -void git_diff_driver_registry_free(git_diff_driver_registry *); - -int git_diff_driver_lookup(git_diff_driver **, git_repository *, - git_attr_session *attrsession, const char *); -void git_diff_driver_free(git_diff_driver *); - -/* diff option flags to force off and on for this driver */ -void git_diff_driver_update_options(uint32_t *option_flags, git_diff_driver *); - -/* returns -1 meaning "unknown", 0 meaning not binary, 1 meaning binary */ -int git_diff_driver_content_is_binary( - git_diff_driver *, const char *content, size_t content_len); - -typedef long (*git_diff_find_context_fn)( - const char *, long, char *, long, void *); - -typedef int (*git_diff_find_context_line)( - git_diff_driver *, git_str *); - -typedef struct { - git_diff_driver *driver; - git_diff_find_context_line match_line; - git_str line; -} git_diff_find_context_payload; - -void git_diff_find_context_init( - git_diff_find_context_fn *findfn_out, - git_diff_find_context_payload *payload_out, - git_diff_driver *driver); - -void git_diff_find_context_clear(git_diff_find_context_payload *); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_file.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff_file.c deleted file mode 100644 index a792834..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_file.c +++ /dev/null @@ -1,490 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "diff_file.h" - -#include "git2/blob.h" -#include "git2/submodule.h" -#include "diff.h" -#include "diff_generate.h" -#include "odb.h" -#include "futils.h" -#include "filter.h" - -#define DIFF_MAX_FILESIZE 0x20000000 - -static bool diff_file_content_binary_by_size(git_diff_file_content *fc) -{ - /* if we have diff opts, check max_size vs file size */ - if ((fc->file->flags & DIFF_FLAGS_KNOWN_BINARY) == 0 && - fc->opts_max_size > 0 && - fc->file->size > fc->opts_max_size) - fc->file->flags |= GIT_DIFF_FLAG_BINARY; - - return ((fc->file->flags & GIT_DIFF_FLAG_BINARY) != 0); -} - -static void diff_file_content_binary_by_content(git_diff_file_content *fc) -{ - if ((fc->file->flags & DIFF_FLAGS_KNOWN_BINARY) != 0) - return; - - switch (git_diff_driver_content_is_binary( - fc->driver, fc->map.data, fc->map.len)) { - case 0: fc->file->flags |= GIT_DIFF_FLAG_NOT_BINARY; break; - case 1: fc->file->flags |= GIT_DIFF_FLAG_BINARY; break; - default: break; - } -} - -static int diff_file_content_init_common( - git_diff_file_content *fc, const git_diff_options *opts) -{ - fc->opts_flags = opts ? opts->flags : GIT_DIFF_NORMAL; - - if (opts && opts->max_size >= 0) - fc->opts_max_size = opts->max_size ? - opts->max_size : DIFF_MAX_FILESIZE; - - if (fc->src == GIT_ITERATOR_EMPTY) - fc->src = GIT_ITERATOR_TREE; - - if (!fc->driver && - git_diff_driver_lookup(&fc->driver, fc->repo, - NULL, fc->file->path) < 0) - return -1; - - /* give driver a chance to modify options */ - git_diff_driver_update_options(&fc->opts_flags, fc->driver); - - /* make sure file is conceivable mmap-able */ - if ((size_t)fc->file->size != fc->file->size) - fc->file->flags |= GIT_DIFF_FLAG_BINARY; - /* check if user is forcing text diff the file */ - else if (fc->opts_flags & GIT_DIFF_FORCE_TEXT) { - fc->file->flags &= ~GIT_DIFF_FLAG_BINARY; - fc->file->flags |= GIT_DIFF_FLAG_NOT_BINARY; - } - /* check if user is forcing binary diff the file */ - else if (fc->opts_flags & GIT_DIFF_FORCE_BINARY) { - fc->file->flags &= ~GIT_DIFF_FLAG_NOT_BINARY; - fc->file->flags |= GIT_DIFF_FLAG_BINARY; - } - - diff_file_content_binary_by_size(fc); - - if ((fc->flags & GIT_DIFF_FLAG__NO_DATA) != 0) { - fc->flags |= GIT_DIFF_FLAG__LOADED; - fc->map.len = 0; - fc->map.data = ""; - } - - if ((fc->flags & GIT_DIFF_FLAG__LOADED) != 0) - diff_file_content_binary_by_content(fc); - - return 0; -} - -int git_diff_file_content__init_from_diff( - git_diff_file_content *fc, - git_diff *diff, - git_diff_delta *delta, - bool use_old) -{ - bool has_data = true; - - memset(fc, 0, sizeof(*fc)); - fc->repo = diff->repo; - fc->file = use_old ? &delta->old_file : &delta->new_file; - fc->src = use_old ? diff->old_src : diff->new_src; - - if (git_diff_driver_lookup(&fc->driver, fc->repo, - &diff->attrsession, fc->file->path) < 0) - return -1; - - switch (delta->status) { - case GIT_DELTA_ADDED: - has_data = !use_old; break; - case GIT_DELTA_DELETED: - has_data = use_old; break; - case GIT_DELTA_UNTRACKED: - has_data = (use_old == (diff->opts.flags & GIT_DIFF_REVERSE)) && - (diff->opts.flags & GIT_DIFF_SHOW_UNTRACKED_CONTENT) != 0; - break; - case GIT_DELTA_UNREADABLE: - case GIT_DELTA_MODIFIED: - case GIT_DELTA_COPIED: - case GIT_DELTA_RENAMED: - break; - default: - has_data = false; - break; - } - - if (!has_data) - fc->flags |= GIT_DIFF_FLAG__NO_DATA; - - return diff_file_content_init_common(fc, &diff->opts); -} - -int git_diff_file_content__init_from_src( - git_diff_file_content *fc, - git_repository *repo, - const git_diff_options *opts, - const git_diff_file_content_src *src, - git_diff_file *as_file) -{ - memset(fc, 0, sizeof(*fc)); - fc->repo = repo; - fc->file = as_file; - - if (!src->blob && !src->buf) { - fc->flags |= GIT_DIFF_FLAG__NO_DATA; - git_oid_clear(&fc->file->id, opts->oid_type); - } else { - fc->flags |= GIT_DIFF_FLAG__LOADED; - fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; - fc->file->mode = GIT_FILEMODE_BLOB; - - if (src->blob) { - git_blob_dup((git_blob **)&fc->blob, (git_blob *) src->blob); - fc->file->size = git_blob_rawsize(src->blob); - git_oid_cpy(&fc->file->id, git_blob_id(src->blob)); - fc->file->id_abbrev = (uint16_t)git_oid_hexsize(repo->oid_type); - - fc->map.len = (size_t)fc->file->size; - fc->map.data = (char *)git_blob_rawcontent(src->blob); - - fc->flags |= GIT_DIFF_FLAG__FREE_BLOB; - } else { - int error; - if ((error = git_odb__hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB, opts->oid_type)) < 0) - return error; - fc->file->size = src->buflen; - fc->file->id_abbrev = (uint16_t)git_oid_hexsize(opts->oid_type); - - fc->map.len = src->buflen; - fc->map.data = (char *)src->buf; - } - } - - return diff_file_content_init_common(fc, opts); -} - -static int diff_file_content_commit_to_str( - git_diff_file_content *fc, bool check_status) -{ - char oid[GIT_OID_MAX_HEXSIZE+1]; - git_str content = GIT_STR_INIT; - const char *status = ""; - - if (check_status) { - int error = 0; - git_submodule *sm = NULL; - unsigned int sm_status = 0; - const git_oid *sm_head; - - if ((error = git_submodule_lookup(&sm, fc->repo, fc->file->path)) < 0) { - /* GIT_EEXISTS means a "submodule" that has not been git added */ - if (error == GIT_EEXISTS) { - git_error_clear(); - error = 0; - } - return error; - } - - if ((error = git_submodule_status(&sm_status, fc->repo, fc->file->path, GIT_SUBMODULE_IGNORE_UNSPECIFIED)) < 0) { - git_submodule_free(sm); - return error; - } - - /* update OID if we didn't have it previously */ - if ((fc->file->flags & GIT_DIFF_FLAG_VALID_ID) == 0 && - ((sm_head = git_submodule_wd_id(sm)) != NULL || - (sm_head = git_submodule_head_id(sm)) != NULL)) - { - git_oid_cpy(&fc->file->id, sm_head); - fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; - } - - if (GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status)) - status = "-dirty"; - - git_submodule_free(sm); - } - - git_oid_tostr(oid, sizeof(oid), &fc->file->id); - if (git_str_printf(&content, "Subproject commit %s%s\n", oid, status) < 0) - return -1; - - fc->map.len = git_str_len(&content); - fc->map.data = git_str_detach(&content); - fc->flags |= GIT_DIFF_FLAG__FREE_DATA; - - return 0; -} - -static int diff_file_content_load_blob( - git_diff_file_content *fc, - git_diff_options *opts) -{ - int error = 0; - git_odb_object *odb_obj = NULL; - - if (git_oid_is_zero(&fc->file->id)) - return 0; - - if (fc->file->mode == GIT_FILEMODE_COMMIT) - return diff_file_content_commit_to_str(fc, false); - - /* if we don't know size, try to peek at object header first */ - if (!fc->file->size) { - if ((error = git_diff_file__resolve_zero_size( - fc->file, &odb_obj, fc->repo)) < 0) - return error; - } - - if ((opts->flags & GIT_DIFF_SHOW_BINARY) == 0 && - diff_file_content_binary_by_size(fc)) - return 0; - - if (odb_obj != NULL) { - error = git_object__from_odb_object( - (git_object **)&fc->blob, fc->repo, odb_obj, GIT_OBJECT_BLOB); - git_odb_object_free(odb_obj); - } else { - error = git_blob_lookup( - (git_blob **)&fc->blob, fc->repo, &fc->file->id); - } - - if (!error) { - fc->flags |= GIT_DIFF_FLAG__FREE_BLOB; - fc->map.data = (void *)git_blob_rawcontent(fc->blob); - fc->map.len = (size_t)git_blob_rawsize(fc->blob); - } - - return error; -} - -static int diff_file_content_load_workdir_symlink_fake( - git_diff_file_content *fc, git_str *path) -{ - git_str target = GIT_STR_INIT; - int error; - - if ((error = git_futils_readbuffer(&target, path->ptr)) < 0) - return error; - - fc->map.len = git_str_len(&target); - fc->map.data = git_str_detach(&target); - fc->flags |= GIT_DIFF_FLAG__FREE_DATA; - - git_str_dispose(&target); - return error; -} - -static int diff_file_content_load_workdir_symlink( - git_diff_file_content *fc, git_str *path) -{ - ssize_t alloc_len, read_len; - int symlink_supported, error; - - if ((error = git_repository__configmap_lookup( - &symlink_supported, fc->repo, GIT_CONFIGMAP_SYMLINKS)) < 0) - return -1; - - if (!symlink_supported) - return diff_file_content_load_workdir_symlink_fake(fc, path); - - /* link path on disk could be UTF-16, so prepare a buffer that is - * big enough to handle some UTF-8 data expansion - */ - alloc_len = (ssize_t)(fc->file->size * 2) + 1; - - fc->map.data = git__calloc(alloc_len, sizeof(char)); - GIT_ERROR_CHECK_ALLOC(fc->map.data); - - fc->flags |= GIT_DIFF_FLAG__FREE_DATA; - - read_len = p_readlink(git_str_cstr(path), fc->map.data, alloc_len); - if (read_len < 0) { - git_error_set(GIT_ERROR_OS, "failed to read symlink '%s'", fc->file->path); - return -1; - } - - fc->map.len = read_len; - return 0; -} - -static int diff_file_content_load_workdir_file( - git_diff_file_content *fc, - git_str *path, - git_diff_options *diff_opts) -{ - int error = 0; - git_filter_list *fl = NULL; - git_file fd = git_futils_open_ro(git_str_cstr(path)); - git_str raw = GIT_STR_INIT; - git_object_size_t new_file_size = 0; - - if (fd < 0) - return fd; - - error = git_futils_filesize(&new_file_size, fd); - - if (error < 0) - goto cleanup; - - if (!(fc->file->flags & GIT_DIFF_FLAG_VALID_SIZE)) { - fc->file->size = new_file_size; - fc->file->flags |= GIT_DIFF_FLAG_VALID_SIZE; - } else if (fc->file->size != new_file_size) { - git_error_set(GIT_ERROR_FILESYSTEM, "file changed before we could read it"); - error = -1; - goto cleanup; - } - - /* if file is empty, don't attempt to mmap or readbuffer */ - if (fc->file->size == 0) { - fc->map.len = 0; - fc->map.data = git_str__initstr; - goto cleanup; - } - - if ((diff_opts->flags & GIT_DIFF_SHOW_BINARY) == 0 && - diff_file_content_binary_by_size(fc)) - goto cleanup; - - if ((error = git_filter_list_load( - &fl, fc->repo, NULL, fc->file->path, - GIT_FILTER_TO_ODB, GIT_FILTER_ALLOW_UNSAFE)) < 0) - goto cleanup; - - /* if there are no filters, try to mmap the file */ - if (fl == NULL) { - if (!(error = git_futils_mmap_ro( - &fc->map, fd, 0, (size_t)fc->file->size))) { - fc->flags |= GIT_DIFF_FLAG__UNMAP_DATA; - goto cleanup; - } - - /* if mmap failed, fall through to try readbuffer below */ - git_error_clear(); - } - - if (!(error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size))) { - git_str out = GIT_STR_INIT; - - error = git_filter_list__convert_buf(&out, fl, &raw); - - if (!error) { - fc->map.len = out.size; - fc->map.data = out.ptr; - fc->flags |= GIT_DIFF_FLAG__FREE_DATA; - } - } - -cleanup: - git_filter_list_free(fl); - p_close(fd); - - return error; -} - -static int diff_file_content_load_workdir( - git_diff_file_content *fc, - git_diff_options *diff_opts) -{ - int error = 0; - git_str path = GIT_STR_INIT; - - if (fc->file->mode == GIT_FILEMODE_COMMIT) - return diff_file_content_commit_to_str(fc, true); - - if (fc->file->mode == GIT_FILEMODE_TREE) - return 0; - - if (git_repository_workdir_path(&path, fc->repo, fc->file->path) < 0) - return -1; - - if (S_ISLNK(fc->file->mode)) - error = diff_file_content_load_workdir_symlink(fc, &path); - else - error = diff_file_content_load_workdir_file(fc, &path, diff_opts); - - /* once data is loaded, update OID if we didn't have it previously */ - if (!error && (fc->file->flags & GIT_DIFF_FLAG_VALID_ID) == 0) { - error = git_odb__hash( - &fc->file->id, fc->map.data, fc->map.len, - GIT_OBJECT_BLOB, diff_opts->oid_type); - fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; - } - - git_str_dispose(&path); - return error; -} - -int git_diff_file_content__load( - git_diff_file_content *fc, - git_diff_options *diff_opts) -{ - int error = 0; - - if ((fc->flags & GIT_DIFF_FLAG__LOADED) != 0) - return 0; - - if ((fc->file->flags & GIT_DIFF_FLAG_BINARY) != 0 && - (diff_opts->flags & GIT_DIFF_SHOW_BINARY) == 0) - return 0; - - if (fc->src == GIT_ITERATOR_WORKDIR) - error = diff_file_content_load_workdir(fc, diff_opts); - else - error = diff_file_content_load_blob(fc, diff_opts); - if (error) - return error; - - fc->flags |= GIT_DIFF_FLAG__LOADED; - - diff_file_content_binary_by_content(fc); - - return 0; -} - -void git_diff_file_content__unload(git_diff_file_content *fc) -{ - if ((fc->flags & GIT_DIFF_FLAG__LOADED) == 0) - return; - - if (fc->flags & GIT_DIFF_FLAG__FREE_DATA) { - git__free(fc->map.data); - fc->map.data = ""; - fc->map.len = 0; - fc->flags &= ~GIT_DIFF_FLAG__FREE_DATA; - } - else if (fc->flags & GIT_DIFF_FLAG__UNMAP_DATA) { - git_futils_mmap_free(&fc->map); - fc->map.data = ""; - fc->map.len = 0; - fc->flags &= ~GIT_DIFF_FLAG__UNMAP_DATA; - } - - if (fc->flags & GIT_DIFF_FLAG__FREE_BLOB) { - git_blob_free((git_blob *)fc->blob); - fc->blob = NULL; - fc->flags &= ~GIT_DIFF_FLAG__FREE_BLOB; - } - - fc->flags &= ~GIT_DIFF_FLAG__LOADED; -} - -void git_diff_file_content__clear(git_diff_file_content *fc) -{ - git_diff_file_content__unload(fc); - - /* for now, nothing else to do */ -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_file.h b/vendor/libgit2-sys/libgit2/src/libgit2/diff_file.h deleted file mode 100644 index 8d743e8..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_file.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_diff_file_h__ -#define INCLUDE_diff_file_h__ - -#include "common.h" - -#include "diff.h" -#include "diff_driver.h" -#include "map.h" - -/* expanded information for one side of a delta */ -typedef struct { - git_repository *repo; - git_diff_file *file; - git_diff_driver *driver; - uint32_t flags; - uint32_t opts_flags; - git_object_size_t opts_max_size; - git_iterator_t src; - const git_blob *blob; - git_map map; -} git_diff_file_content; - -extern int git_diff_file_content__init_from_diff( - git_diff_file_content *fc, - git_diff *diff, - git_diff_delta *delta, - bool use_old); - -typedef struct { - const git_blob *blob; - const void *buf; - size_t buflen; - const char *as_path; -} git_diff_file_content_src; - -#define GIT_DIFF_FILE_CONTENT_SRC__BLOB(BLOB,PATH) { (BLOB),NULL,0,(PATH) } -#define GIT_DIFF_FILE_CONTENT_SRC__BUF(BUF,LEN,PATH) { NULL,(BUF),(LEN),(PATH) } - -extern int git_diff_file_content__init_from_src( - git_diff_file_content *fc, - git_repository *repo, - const git_diff_options *opts, - const git_diff_file_content_src *src, - git_diff_file *as_file); - -/* this loads the blob/file-on-disk as needed */ -extern int git_diff_file_content__load( - git_diff_file_content *fc, - git_diff_options *diff_opts); - -/* this releases the blob/file-in-memory */ -extern void git_diff_file_content__unload(git_diff_file_content *fc); - -/* this unloads and also releases any other resources */ -extern void git_diff_file_content__clear(git_diff_file_content *fc); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_generate.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff_generate.c deleted file mode 100644 index 654145e..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_generate.c +++ /dev/null @@ -1,1750 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "diff_generate.h" - -#include "diff.h" -#include "patch_generate.h" -#include "futils.h" -#include "config.h" -#include "attr_file.h" -#include "filter.h" -#include "pathspec.h" -#include "index.h" -#include "odb.h" -#include "submodule.h" - -#define DIFF_FLAG_IS_SET(DIFF,FLAG) \ - (((DIFF)->base.opts.flags & (FLAG)) != 0) -#define DIFF_FLAG_ISNT_SET(DIFF,FLAG) \ - (((DIFF)->base.opts.flags & (FLAG)) == 0) -#define DIFF_FLAG_SET(DIFF,FLAG,VAL) (DIFF)->base.opts.flags = \ - (VAL) ? ((DIFF)->base.opts.flags | (FLAG)) : \ - ((DIFF)->base.opts.flags & ~(FLAG)) - -typedef struct { - struct git_diff base; - - git_vector pathspec; - - uint32_t diffcaps; - bool index_updated; -} git_diff_generated; - -static git_diff_delta *diff_delta__alloc( - git_diff_generated *diff, - git_delta_t status, - const char *path) -{ - git_diff_delta *delta = git__calloc(1, sizeof(git_diff_delta)); - if (!delta) - return NULL; - - delta->old_file.path = git_pool_strdup(&diff->base.pool, path); - if (delta->old_file.path == NULL) { - git__free(delta); - return NULL; - } - - delta->new_file.path = delta->old_file.path; - - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) { - switch (status) { - case GIT_DELTA_ADDED: status = GIT_DELTA_DELETED; break; - case GIT_DELTA_DELETED: status = GIT_DELTA_ADDED; break; - default: break; /* leave other status values alone */ - } - } - delta->status = status; - - git_oid_clear(&delta->old_file.id, diff->base.opts.oid_type); - git_oid_clear(&delta->new_file.id, diff->base.opts.oid_type); - - return delta; -} - -static int diff_insert_delta( - git_diff_generated *diff, - git_diff_delta *delta, - const char *matched_pathspec) -{ - int error = 0; - - if (diff->base.opts.notify_cb) { - error = diff->base.opts.notify_cb( - &diff->base, delta, matched_pathspec, diff->base.opts.payload); - - if (error) { - git__free(delta); - - if (error > 0) /* positive value means to skip this delta */ - return 0; - else /* negative value means to cancel diff */ - return git_error_set_after_callback_function(error, "git_diff"); - } - } - - if ((error = git_vector_insert(&diff->base.deltas, delta)) < 0) - git__free(delta); - - return error; -} - -static bool diff_pathspec_match( - const char **matched_pathspec, - git_diff_generated *diff, - const git_index_entry *entry) -{ - bool disable_pathspec_match = - DIFF_FLAG_IS_SET(diff, GIT_DIFF_DISABLE_PATHSPEC_MATCH); - - /* If we're disabling fnmatch, then the iterator has already applied - * the filters to the files for us and we don't have to do anything. - * However, this only applies to *files* - the iterator will include - * directories that we need to recurse into when not autoexpanding, - * so we still need to apply the pathspec match to directories. - */ - if ((S_ISLNK(entry->mode) || S_ISREG(entry->mode)) && - disable_pathspec_match) { - *matched_pathspec = entry->path; - return true; - } - - return git_pathspec__match( - &diff->pathspec, entry->path, disable_pathspec_match, - DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE), - matched_pathspec, NULL); -} - -static void diff_delta__flag_known_size(git_diff_file *file) -{ - /* - * If we don't know the ID, that can only come from the workdir - * iterator, which means we *do* know the file size. This is a - * leaky abstraction, but alas. Otherwise, we test against the - * empty blob id. - */ - if (file->size || - !(file->flags & GIT_DIFF_FLAG_VALID_ID) || - git_oid_equal(&file->id, &git_oid__empty_blob_sha1)) - file->flags |= GIT_DIFF_FLAG_VALID_SIZE; -} - -static void diff_delta__flag_known_sizes(git_diff_delta *delta) -{ - diff_delta__flag_known_size(&delta->old_file); - diff_delta__flag_known_size(&delta->new_file); -} - -static int diff_delta__from_one( - git_diff_generated *diff, - git_delta_t status, - const git_index_entry *oitem, - const git_index_entry *nitem) -{ - const git_index_entry *entry = nitem; - bool has_old = false; - git_diff_delta *delta; - git_oid_t oid_type; - const char *matched_pathspec; - - GIT_ASSERT_ARG((oitem != NULL) ^ (nitem != NULL)); - - oid_type = diff->base.opts.oid_type; - - if (oitem) { - entry = oitem; - has_old = true; - } - - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) - has_old = !has_old; - - if ((entry->flags & GIT_INDEX_ENTRY_VALID) != 0) - return 0; - - if (status == GIT_DELTA_IGNORED && - DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_IGNORED)) - return 0; - - if (status == GIT_DELTA_UNTRACKED && - DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNTRACKED)) - return 0; - - if (status == GIT_DELTA_UNREADABLE && - DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNREADABLE)) - return 0; - - if (!diff_pathspec_match(&matched_pathspec, diff, entry)) - return 0; - - delta = diff_delta__alloc(diff, status, entry->path); - GIT_ERROR_CHECK_ALLOC(delta); - - /* This fn is just for single-sided diffs */ - GIT_ASSERT(status != GIT_DELTA_MODIFIED); - delta->nfiles = 1; - - git_oid_clear(&delta->old_file.id, diff->base.opts.oid_type); - git_oid_clear(&delta->new_file.id, diff->base.opts.oid_type); - - if (has_old) { - delta->old_file.mode = entry->mode; - delta->old_file.size = entry->file_size; - delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS; - git_oid_cpy(&delta->old_file.id, &entry->id); - git_oid_clear(&delta->new_file.id, oid_type); - delta->old_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type); - } else /* ADDED, IGNORED, UNTRACKED */ { - delta->new_file.mode = entry->mode; - delta->new_file.size = entry->file_size; - delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS; - git_oid_clear(&delta->old_file.id, oid_type); - git_oid_cpy(&delta->new_file.id, &entry->id); - delta->new_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type); - } - - delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; - - if (has_old || !git_oid_is_zero(&delta->new_file.id)) - delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; - - diff_delta__flag_known_sizes(delta); - - return diff_insert_delta(diff, delta, matched_pathspec); -} - -static int diff_delta__from_two( - git_diff_generated *diff, - git_delta_t status, - const git_index_entry *old_entry, - uint32_t old_mode, - const git_index_entry *new_entry, - uint32_t new_mode, - const git_oid *new_id, - const char *matched_pathspec) -{ - const git_oid *old_id = &old_entry->id; - git_diff_delta *delta; - const char *canonical_path = old_entry->path; - git_oid_t oid_type; - - oid_type = diff->base.opts.oid_type; - - if (status == GIT_DELTA_UNMODIFIED && - DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNMODIFIED)) - return 0; - - if (!new_id) - new_id = &new_entry->id; - - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) { - uint32_t temp_mode = old_mode; - const git_index_entry *temp_entry = old_entry; - const git_oid *temp_id = old_id; - - old_entry = new_entry; - new_entry = temp_entry; - old_mode = new_mode; - new_mode = temp_mode; - old_id = new_id; - new_id = temp_id; - } - - delta = diff_delta__alloc(diff, status, canonical_path); - GIT_ERROR_CHECK_ALLOC(delta); - delta->nfiles = 2; - - if (!git_index_entry_is_conflict(old_entry)) { - delta->old_file.size = old_entry->file_size; - delta->old_file.mode = old_mode; - git_oid_cpy(&delta->old_file.id, old_id); - delta->old_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type); - delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID | - GIT_DIFF_FLAG_EXISTS; - } - - if (!git_index_entry_is_conflict(new_entry)) { - git_oid_cpy(&delta->new_file.id, new_id); - delta->new_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type); - delta->new_file.size = new_entry->file_size; - delta->new_file.mode = new_mode; - delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS; - delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS; - - if (!git_oid_is_zero(&new_entry->id)) - delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; - } - - diff_delta__flag_known_sizes(delta); - - return diff_insert_delta(diff, delta, matched_pathspec); -} - -static git_diff_delta *diff_delta__last_for_item( - git_diff_generated *diff, - const git_index_entry *item) -{ - git_diff_delta *delta = git_vector_last(&diff->base.deltas); - if (!delta) - return NULL; - - switch (delta->status) { - case GIT_DELTA_UNMODIFIED: - case GIT_DELTA_DELETED: - if (git_oid__cmp(&delta->old_file.id, &item->id) == 0) - return delta; - break; - case GIT_DELTA_ADDED: - if (git_oid__cmp(&delta->new_file.id, &item->id) == 0) - return delta; - break; - case GIT_DELTA_UNREADABLE: - case GIT_DELTA_UNTRACKED: - if (diff->base.strcomp(delta->new_file.path, item->path) == 0 && - git_oid__cmp(&delta->new_file.id, &item->id) == 0) - return delta; - break; - case GIT_DELTA_MODIFIED: - if (git_oid__cmp(&delta->old_file.id, &item->id) == 0 || - (delta->new_file.mode == item->mode && - git_oid__cmp(&delta->new_file.id, &item->id) == 0)) - return delta; - break; - default: - break; - } - - return NULL; -} - -static char *diff_strdup_prefix(git_pool *pool, const char *prefix) -{ - size_t len = strlen(prefix); - - /* append '/' at end if needed */ - if (len > 0 && prefix[len - 1] != '/') - return git_pool_strcat(pool, prefix, "/"); - else - return git_pool_strndup(pool, prefix, len + 1); -} - -GIT_INLINE(const char *) diff_delta__i2w_path(const git_diff_delta *delta) -{ - return delta->old_file.path ? - delta->old_file.path : delta->new_file.path; -} - -static int diff_delta_i2w_cmp(const void *a, const void *b) -{ - const git_diff_delta *da = a, *db = b; - int val = strcmp(diff_delta__i2w_path(da), diff_delta__i2w_path(db)); - return val ? val : ((int)da->status - (int)db->status); -} - -static int diff_delta_i2w_casecmp(const void *a, const void *b) -{ - const git_diff_delta *da = a, *db = b; - int val = strcasecmp(diff_delta__i2w_path(da), diff_delta__i2w_path(db)); - return val ? val : ((int)da->status - (int)db->status); -} - -bool git_diff_delta__should_skip( - const git_diff_options *opts, const git_diff_delta *delta) -{ - uint32_t flags = opts ? opts->flags : 0; - - if (delta->status == GIT_DELTA_UNMODIFIED && - (flags & GIT_DIFF_INCLUDE_UNMODIFIED) == 0) - return true; - - if (delta->status == GIT_DELTA_IGNORED && - (flags & GIT_DIFF_INCLUDE_IGNORED) == 0) - return true; - - if (delta->status == GIT_DELTA_UNTRACKED && - (flags & GIT_DIFF_INCLUDE_UNTRACKED) == 0) - return true; - - if (delta->status == GIT_DELTA_UNREADABLE && - (flags & GIT_DIFF_INCLUDE_UNREADABLE) == 0) - return true; - - return false; -} - - -static const char *diff_mnemonic_prefix( - git_iterator_t type, bool left_side) -{ - const char *pfx = ""; - - switch (type) { - case GIT_ITERATOR_EMPTY: pfx = "c"; break; - case GIT_ITERATOR_TREE: pfx = "c"; break; - case GIT_ITERATOR_INDEX: pfx = "i"; break; - case GIT_ITERATOR_WORKDIR: pfx = "w"; break; - case GIT_ITERATOR_FS: pfx = left_side ? "1" : "2"; break; - default: break; - } - - /* note: without a deeper look at pathspecs, there is no easy way - * to get the (o)bject / (w)ork tree mnemonics working... - */ - - return pfx; -} - -static void diff_set_ignore_case(git_diff *diff, bool ignore_case) -{ - if (!ignore_case) { - diff->opts.flags &= ~GIT_DIFF_IGNORE_CASE; - - diff->strcomp = git__strcmp; - diff->strncomp = git__strncmp; - diff->pfxcomp = git__prefixcmp; - diff->entrycomp = git_diff__entry_cmp; - - git_vector_set_cmp(&diff->deltas, git_diff_delta__cmp); - } else { - diff->opts.flags |= GIT_DIFF_IGNORE_CASE; - - diff->strcomp = git__strcasecmp; - diff->strncomp = git__strncasecmp; - diff->pfxcomp = git__prefixcmp_icase; - diff->entrycomp = git_diff__entry_icmp; - - git_vector_set_cmp(&diff->deltas, git_diff_delta__casecmp); - } - - git_vector_sort(&diff->deltas); -} - -static void diff_generated_free(git_diff *d) -{ - git_diff_generated *diff = (git_diff_generated *)d; - - git_attr_session__free(&diff->base.attrsession); - git_vector_dispose_deep(&diff->base.deltas); - - git_pathspec__vfree(&diff->pathspec); - git_pool_clear(&diff->base.pool); - - git__memzero(diff, sizeof(*diff)); - git__free(diff); -} - -static git_diff_generated *diff_generated_alloc( - git_repository *repo, - git_iterator *old_iter, - git_iterator *new_iter) -{ - git_diff_generated *diff; - git_diff_options dflt = GIT_DIFF_OPTIONS_INIT; - - GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(old_iter, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(new_iter, NULL); - - if ((diff = git__calloc(1, sizeof(git_diff_generated))) == NULL) - return NULL; - - GIT_REFCOUNT_INC(&diff->base); - diff->base.type = GIT_DIFF_TYPE_GENERATED; - diff->base.repo = repo; - diff->base.old_src = old_iter->type; - diff->base.new_src = new_iter->type; - diff->base.patch_fn = git_patch_generated_from_diff; - diff->base.free_fn = diff_generated_free; - git_attr_session__init(&diff->base.attrsession, repo); - memcpy(&diff->base.opts, &dflt, sizeof(git_diff_options)); - - if (git_pool_init(&diff->base.pool, 1) < 0 || - git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) { - git_diff_free(&diff->base); - return NULL; - } - - /* Use case-insensitive compare if either iterator has - * the ignore_case bit set */ - diff_set_ignore_case( - &diff->base, - git_iterator_ignore_case(old_iter) || - git_iterator_ignore_case(new_iter)); - - return diff; -} - -static int diff_generated_apply_options( - git_diff_generated *diff, - const git_diff_options *opts) -{ - git_config *cfg = NULL; - git_repository *repo = diff->base.repo; - git_pool *pool = &diff->base.pool; - int val; - - if (opts) { - /* copy user options (except case sensitivity info from iterators) */ - bool icase = DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE); - memcpy(&diff->base.opts, opts, sizeof(diff->base.opts)); - DIFF_FLAG_SET(diff, GIT_DIFF_IGNORE_CASE, icase); - - /* initialize pathspec from options */ - if (git_pathspec__vinit(&diff->pathspec, &opts->pathspec, pool) < 0) - return -1; - } - - if (!diff->base.opts.oid_type) { - diff->base.opts.oid_type = repo->oid_type; - } else if (diff->base.opts.oid_type != repo->oid_type) { - git_error_set(GIT_ERROR_INVALID, - "specified object ID type does not match repository object ID type"); - return -1; - } - - /* flag INCLUDE_TYPECHANGE_TREES implies INCLUDE_TYPECHANGE */ - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES)) - diff->base.opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE; - - /* flag INCLUDE_UNTRACKED_CONTENT implies INCLUDE_UNTRACKED */ - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_SHOW_UNTRACKED_CONTENT)) - diff->base.opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED; - - /* load config values that affect diff behavior */ - if ((val = git_repository_config_snapshot(&cfg, repo)) < 0) - return val; - - if (!git_config__configmap_lookup(&val, cfg, GIT_CONFIGMAP_SYMLINKS) && val) - diff->diffcaps |= GIT_DIFFCAPS_HAS_SYMLINKS; - - if (!git_config__configmap_lookup(&val, cfg, GIT_CONFIGMAP_IGNORESTAT) && val) - diff->diffcaps |= GIT_DIFFCAPS_IGNORE_STAT; - - if ((diff->base.opts.flags & GIT_DIFF_IGNORE_FILEMODE) == 0 && - !git_config__configmap_lookup(&val, cfg, GIT_CONFIGMAP_FILEMODE) && val) - diff->diffcaps |= GIT_DIFFCAPS_TRUST_MODE_BITS; - - if (!git_config__configmap_lookup(&val, cfg, GIT_CONFIGMAP_TRUSTCTIME) && val) - diff->diffcaps |= GIT_DIFFCAPS_TRUST_CTIME; - - /* Don't set GIT_DIFFCAPS_USE_DEV - compile time option in core git */ - - /* If not given explicit `opts`, check `diff.xyz` configs */ - if (!opts) { - int context = git_config__get_int_force(cfg, "diff.context", 3); - diff->base.opts.context_lines = context >= 0 ? (uint32_t)context : 3; - - /* add other defaults here */ - } - - /* Reverse src info if diff is reversed */ - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) { - git_iterator_t tmp_src = diff->base.old_src; - diff->base.old_src = diff->base.new_src; - diff->base.new_src = tmp_src; - } - - /* Unset UPDATE_INDEX unless diffing workdir and index */ - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_UPDATE_INDEX) && - (!(diff->base.old_src == GIT_ITERATOR_WORKDIR || - diff->base.new_src == GIT_ITERATOR_WORKDIR) || - !(diff->base.old_src == GIT_ITERATOR_INDEX || - diff->base.new_src == GIT_ITERATOR_INDEX))) - diff->base.opts.flags &= ~GIT_DIFF_UPDATE_INDEX; - - /* if ignore_submodules not explicitly set, check diff config */ - if (diff->base.opts.ignore_submodules <= 0) { - git_config_entry *entry; - git_config__lookup_entry(&entry, cfg, "diff.ignoresubmodules", true); - - if (entry && git_submodule_parse_ignore( - &diff->base.opts.ignore_submodules, entry->value) < 0) - git_error_clear(); - git_config_entry_free(entry); - } - - /* if either prefix is not set, figure out appropriate value */ - if (!diff->base.opts.old_prefix || !diff->base.opts.new_prefix) { - const char *use_old = DIFF_OLD_PREFIX_DEFAULT; - const char *use_new = DIFF_NEW_PREFIX_DEFAULT; - - if (git_config__get_bool_force(cfg, "diff.noprefix", 0)) - use_old = use_new = ""; - else if (git_config__get_bool_force(cfg, "diff.mnemonicprefix", 0)) { - use_old = diff_mnemonic_prefix(diff->base.old_src, true); - use_new = diff_mnemonic_prefix(diff->base.new_src, false); - } - - if (!diff->base.opts.old_prefix) - diff->base.opts.old_prefix = use_old; - if (!diff->base.opts.new_prefix) - diff->base.opts.new_prefix = use_new; - } - - /* strdup prefix from pool so we're not dependent on external data */ - diff->base.opts.old_prefix = diff_strdup_prefix(pool, diff->base.opts.old_prefix); - diff->base.opts.new_prefix = diff_strdup_prefix(pool, diff->base.opts.new_prefix); - - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) { - const char *tmp_prefix = diff->base.opts.old_prefix; - diff->base.opts.old_prefix = diff->base.opts.new_prefix; - diff->base.opts.new_prefix = tmp_prefix; - } - - git_config_free(cfg); - - /* check strdup results for error */ - return (!diff->base.opts.old_prefix || !diff->base.opts.new_prefix) ? -1 : 0; -} - -int git_diff__oid_for_file( - git_oid *out, - git_diff *diff, - const char *path, - uint16_t mode, - git_object_size_t size) -{ - git_index_entry entry; - - if (size > UINT32_MAX) { - git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", path); - return -1; - } - - memset(&entry, 0, sizeof(entry)); - entry.mode = mode; - entry.file_size = (uint32_t)size; - entry.path = (char *)path; - git_oid_clear(&entry.id, diff->opts.oid_type); - - return git_diff__oid_for_entry(out, diff, &entry, mode, NULL); -} - -int git_diff__oid_for_entry( - git_oid *out, - git_diff *d, - const git_index_entry *src, - uint16_t mode, - const git_oid *update_match) -{ - git_diff_generated *diff; - git_str full_path = GIT_STR_INIT; - git_index_entry entry = *src; - git_filter_list *fl = NULL; - int error = 0; - - GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED); - diff = (git_diff_generated *)d; - - git_oid_clear(out, diff->base.opts.oid_type); - - if (git_repository_workdir_path(&full_path, diff->base.repo, entry.path) < 0) - return -1; - - if (!mode) { - struct stat st; - - diff->base.perf.stat_calls++; - - if (p_stat(full_path.ptr, &st) < 0) { - error = git_fs_path_set_error(errno, entry.path, "stat"); - git_str_dispose(&full_path); - return error; - } - - git_index_entry__init_from_stat(&entry, - &st, (diff->diffcaps & GIT_DIFFCAPS_TRUST_MODE_BITS) != 0); - } - - /* calculate OID for file if possible */ - if (S_ISGITLINK(mode)) { - git_submodule *sm; - - if (!git_submodule_lookup(&sm, diff->base.repo, entry.path)) { - const git_oid *sm_oid = git_submodule_wd_id(sm); - if (sm_oid) - git_oid_cpy(out, sm_oid); - git_submodule_free(sm); - } else { - /* if submodule lookup failed probably just in an intermediate - * state where some init hasn't happened, so ignore the error - */ - git_error_clear(); - } - } else if (S_ISLNK(mode)) { - error = git_odb__hashlink(out, full_path.ptr, - diff->base.opts.oid_type); - diff->base.perf.oid_calculations++; - } else if (!git__is_sizet(entry.file_size)) { - git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", - entry.path); - error = -1; - } else if (!(error = git_filter_list_load(&fl, - diff->base.repo, NULL, entry.path, - GIT_FILTER_TO_ODB, GIT_FILTER_ALLOW_UNSAFE))) - { - int fd = git_futils_open_ro(full_path.ptr); - if (fd < 0) - error = fd; - else { - error = git_odb__hashfd_filtered( - out, fd, (size_t)entry.file_size, - GIT_OBJECT_BLOB, diff->base.opts.oid_type, - fl); - p_close(fd); - diff->base.perf.oid_calculations++; - } - - git_filter_list_free(fl); - } - - /* update index for entry if requested */ - if (!error && update_match && git_oid_equal(out, update_match)) { - git_index *idx; - git_index_entry updated_entry; - - memcpy(&updated_entry, &entry, sizeof(git_index_entry)); - updated_entry.mode = mode; - git_oid_cpy(&updated_entry.id, out); - - if (!(error = git_repository_index__weakptr(&idx, - diff->base.repo))) { - error = git_index_add(idx, &updated_entry); - diff->index_updated = true; - } - } - - git_str_dispose(&full_path); - return error; -} - -typedef struct { - git_repository *repo; - git_iterator *old_iter; - git_iterator *new_iter; - const git_index_entry *oitem; - const git_index_entry *nitem; - git_submodule_cache *submodule_cache; - bool submodule_cache_initialized; -} diff_in_progress; - -#define MODE_BITS_MASK 0000777 - -static int maybe_modified_submodule( - git_delta_t *status, - git_oid *found_oid, - git_diff_generated *diff, - diff_in_progress *info) -{ - int error = 0; - git_submodule *sub; - unsigned int sm_status = 0; - git_submodule_ignore_t ign = diff->base.opts.ignore_submodules; - git_submodule_cache *submodule_cache = NULL; - - *status = GIT_DELTA_UNMODIFIED; - - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_SUBMODULES) || - ign == GIT_SUBMODULE_IGNORE_ALL) - return 0; - - if (diff->base.repo->submodule_cache != NULL) { - submodule_cache = diff->base.repo->submodule_cache; - } else { - if (!info->submodule_cache_initialized) { - info->submodule_cache_initialized = true; - /* - * Try to cache the submodule information to avoid having to parse it for - * every submodule. It is okay if it fails, the cache will still be NULL - * and the submodules will be attempted to be looked up individually. - */ - git_submodule_cache_init(&info->submodule_cache, diff->base.repo); - } - submodule_cache = info->submodule_cache; - } - - if ((error = git_submodule__lookup_with_cache( - &sub, diff->base.repo, info->nitem->path, submodule_cache)) < 0) { - - /* GIT_EEXISTS means dir with .git in it was found - ignore it */ - if (error == GIT_EEXISTS) { - git_error_clear(); - error = 0; - } - return error; - } - - if (ign <= 0 && git_submodule_ignore(sub) == GIT_SUBMODULE_IGNORE_ALL) - /* ignore it */; - else if ((error = git_submodule__status( - &sm_status, NULL, NULL, found_oid, sub, ign)) < 0) - /* return error below */; - - /* check IS_WD_UNMODIFIED because this case is only used - * when the new side of the diff is the working directory - */ - else if (!GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(sm_status)) - *status = GIT_DELTA_MODIFIED; - - /* now that we have a HEAD OID, check if HEAD moved */ - else if ((sm_status & GIT_SUBMODULE_STATUS_IN_WD) != 0 && - !git_oid_equal(&info->oitem->id, found_oid)) - *status = GIT_DELTA_MODIFIED; - - git_submodule_free(sub); - return error; -} - -static int maybe_modified( - git_diff_generated *diff, - diff_in_progress *info) -{ - git_oid noid; - git_delta_t status = GIT_DELTA_MODIFIED; - const git_index_entry *oitem = info->oitem; - const git_index_entry *nitem = info->nitem; - unsigned int omode = oitem->mode; - unsigned int nmode = nitem->mode; - bool new_is_workdir = (info->new_iter->type == GIT_ITERATOR_WORKDIR); - bool modified_uncertain = false; - const char *matched_pathspec; - int error = 0; - - git_oid_clear(&noid, diff->base.opts.oid_type); - - if (!diff_pathspec_match(&matched_pathspec, diff, oitem)) - return 0; - - /* on platforms with no symlinks, preserve mode of existing symlinks */ - if (S_ISLNK(omode) && S_ISREG(nmode) && new_is_workdir && - !(diff->diffcaps & GIT_DIFFCAPS_HAS_SYMLINKS)) - nmode = omode; - - /* on platforms with no execmode, just preserve old mode */ - if (!(diff->diffcaps & GIT_DIFFCAPS_TRUST_MODE_BITS) && - (nmode & MODE_BITS_MASK) != (omode & MODE_BITS_MASK) && - new_is_workdir) - nmode = (nmode & ~MODE_BITS_MASK) | (omode & MODE_BITS_MASK); - - /* if one side is a conflict, mark the whole delta as conflicted */ - if (git_index_entry_is_conflict(oitem) || - git_index_entry_is_conflict(nitem)) { - status = GIT_DELTA_CONFLICTED; - - /* support "assume unchanged" (poorly, b/c we still stat everything) */ - } else if ((oitem->flags & GIT_INDEX_ENTRY_VALID) != 0) { - status = GIT_DELTA_UNMODIFIED; - - /* support "skip worktree" index bit */ - } else if ((oitem->flags_extended & GIT_INDEX_ENTRY_SKIP_WORKTREE) != 0) { - status = GIT_DELTA_UNMODIFIED; - - /* if basic type of file changed, then split into delete and add */ - } else if (GIT_MODE_TYPE(omode) != GIT_MODE_TYPE(nmode)) { - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE)) { - status = GIT_DELTA_TYPECHANGE; - } - - else if (nmode == GIT_FILEMODE_UNREADABLE) { - if (!(error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem, NULL))) - error = diff_delta__from_one(diff, GIT_DELTA_UNREADABLE, NULL, nitem); - return error; - } - - else { - if (!(error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem, NULL))) - error = diff_delta__from_one(diff, GIT_DELTA_ADDED, NULL, nitem); - return error; - } - - /* if oids and modes match (and are valid), then file is unmodified */ - } else if (git_oid_equal(&oitem->id, &nitem->id) && - omode == nmode && - !git_oid_is_zero(&oitem->id)) { - status = GIT_DELTA_UNMODIFIED; - - /* if we have an unknown OID and a workdir iterator, then check some - * circumstances that can accelerate things or need special handling - */ - } else if (git_oid_is_zero(&nitem->id) && new_is_workdir) { - bool use_ctime = - ((diff->diffcaps & GIT_DIFFCAPS_TRUST_CTIME) != 0); - git_index *index = git_iterator_index(info->new_iter); - - status = GIT_DELTA_UNMODIFIED; - - if (S_ISGITLINK(nmode)) { - if ((error = maybe_modified_submodule(&status, &noid, diff, info)) < 0) - return error; - } - - /* if the stat data looks different, then mark modified - this just - * means that the OID will be recalculated below to confirm change - */ - else if (omode != nmode || oitem->file_size != nitem->file_size) { - status = GIT_DELTA_MODIFIED; - modified_uncertain = - (oitem->file_size <= 0 && nitem->file_size > 0); - } - else if (!git_index_time_eq(&oitem->mtime, &nitem->mtime) || - (use_ctime && !git_index_time_eq(&oitem->ctime, &nitem->ctime)) || - oitem->ino != nitem->ino || - oitem->uid != nitem->uid || - oitem->gid != nitem->gid || - git_index_entry_newer_than_index(nitem, index)) - { - status = GIT_DELTA_MODIFIED; - modified_uncertain = true; - } - - /* if mode is GITLINK and submodules are ignored, then skip */ - } else if (S_ISGITLINK(nmode) && - DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_SUBMODULES)) { - status = GIT_DELTA_UNMODIFIED; - } - - /* if we got here and decided that the files are modified, but we - * haven't calculated the OID of the new item, then calculate it now - */ - if (modified_uncertain && git_oid_is_zero(&nitem->id)) { - const git_oid *update_check = - DIFF_FLAG_IS_SET(diff, GIT_DIFF_UPDATE_INDEX) && omode == nmode ? - &oitem->id : NULL; - - if ((error = git_diff__oid_for_entry( - &noid, &diff->base, nitem, nmode, update_check)) < 0) - return error; - - /* if oid matches, then mark unmodified (except submodules, where - * the filesystem content may be modified even if the oid still - * matches between the index and the workdir HEAD) - */ - if (omode == nmode && !S_ISGITLINK(omode) && - git_oid_equal(&oitem->id, &noid)) - status = GIT_DELTA_UNMODIFIED; - } - - /* If we want case changes, then break this into a delete of the old - * and an add of the new so that consumers can act accordingly (eg, - * checkout will update the case on disk.) - */ - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE) && - DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_CASECHANGE) && - strcmp(oitem->path, nitem->path) != 0) { - - if (!(error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem, NULL))) - error = diff_delta__from_one(diff, GIT_DELTA_ADDED, NULL, nitem); - - return error; - } - - return diff_delta__from_two( - diff, status, oitem, omode, nitem, nmode, - git_oid_is_zero(&noid) ? NULL : &noid, matched_pathspec); -} - -static bool entry_is_prefixed( - git_diff_generated *diff, - const git_index_entry *item, - const git_index_entry *prefix_item) -{ - size_t pathlen; - - if (!item || diff->base.pfxcomp(item->path, prefix_item->path) != 0) - return false; - - pathlen = strlen(prefix_item->path); - - return (prefix_item->path[pathlen - 1] == '/' || - item->path[pathlen] == '\0' || - item->path[pathlen] == '/'); -} - -static int iterator_current( - const git_index_entry **entry, - git_iterator *iterator) -{ - int error; - - if ((error = git_iterator_current(entry, iterator)) == GIT_ITEROVER) { - *entry = NULL; - error = 0; - } - - return error; -} - -static int iterator_advance( - const git_index_entry **entry, - git_iterator *iterator) -{ - const git_index_entry *prev_entry = *entry; - int cmp, error; - - /* if we're looking for conflicts, we only want to report - * one conflict for each file, instead of all three sides. - * so if this entry is a conflict for this file, and the - * previous one was a conflict for the same file, skip it. - */ - while ((error = git_iterator_advance(entry, iterator)) == 0) { - if (!(iterator->flags & GIT_ITERATOR_INCLUDE_CONFLICTS) || - !git_index_entry_is_conflict(prev_entry) || - !git_index_entry_is_conflict(*entry)) - break; - - cmp = (iterator->flags & GIT_ITERATOR_IGNORE_CASE) ? - strcasecmp(prev_entry->path, (*entry)->path) : - strcmp(prev_entry->path, (*entry)->path); - - if (cmp) - break; - } - - if (error == GIT_ITEROVER) { - *entry = NULL; - error = 0; - } - - return error; -} - -static int iterator_advance_into( - const git_index_entry **entry, - git_iterator *iterator) -{ - int error; - - if ((error = git_iterator_advance_into(entry, iterator)) == GIT_ITEROVER) { - *entry = NULL; - error = 0; - } - - return error; -} - -static int iterator_advance_over( - const git_index_entry **entry, - git_iterator_status_t *status, - git_iterator *iterator) -{ - int error = git_iterator_advance_over(entry, status, iterator); - - if (error == GIT_ITEROVER) { - *entry = NULL; - error = 0; - } - - return error; -} - -static int handle_unmatched_new_item( - git_diff_generated *diff, diff_in_progress *info) -{ - int error = 0; - const git_index_entry *nitem = info->nitem; - git_delta_t delta_type = GIT_DELTA_UNTRACKED; - bool contains_oitem; - - /* check if this is a prefix of the other side */ - contains_oitem = entry_is_prefixed(diff, info->oitem, nitem); - - /* update delta_type if this item is conflicted */ - if (git_index_entry_is_conflict(nitem)) - delta_type = GIT_DELTA_CONFLICTED; - - /* update delta_type if this item is ignored */ - else if (git_iterator_current_is_ignored(info->new_iter)) - delta_type = GIT_DELTA_IGNORED; - - if (nitem->mode == GIT_FILEMODE_TREE) { - bool recurse_into_dir = contains_oitem; - - /* check if user requests recursion into this type of dir */ - recurse_into_dir = contains_oitem || - (delta_type == GIT_DELTA_UNTRACKED && - DIFF_FLAG_IS_SET(diff, GIT_DIFF_RECURSE_UNTRACKED_DIRS)) || - (delta_type == GIT_DELTA_IGNORED && - DIFF_FLAG_IS_SET(diff, GIT_DIFF_RECURSE_IGNORED_DIRS)); - - /* do not advance into directories that contain a .git file */ - if (recurse_into_dir && !contains_oitem) { - git_str *full = NULL; - if (git_iterator_current_workdir_path(&full, info->new_iter) < 0) - return -1; - if (full && git_fs_path_contains(full, DOT_GIT)) { - /* TODO: warning if not a valid git repository */ - recurse_into_dir = false; - } - } - - /* still have to look into untracked directories to match core git - - * with no untracked files, directory is treated as ignored - */ - if (!recurse_into_dir && - delta_type == GIT_DELTA_UNTRACKED && - DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS)) - { - git_diff_delta *last; - git_iterator_status_t untracked_state; - - /* attempt to insert record for this directory */ - if ((error = diff_delta__from_one(diff, delta_type, NULL, nitem)) != 0) - return error; - - /* if delta wasn't created (because of rules), just skip ahead */ - last = diff_delta__last_for_item(diff, nitem); - if (!last) - return iterator_advance(&info->nitem, info->new_iter); - - /* iterate into dir looking for an actual untracked file */ - if ((error = iterator_advance_over( - &info->nitem, &untracked_state, info->new_iter)) < 0) - return error; - - /* if we found nothing that matched our pathlist filter, exclude */ - if (untracked_state == GIT_ITERATOR_STATUS_FILTERED) { - git_vector_pop(&diff->base.deltas); - git__free(last); - } - - /* if we found nothing or just ignored items, update the record */ - if (untracked_state == GIT_ITERATOR_STATUS_IGNORED || - untracked_state == GIT_ITERATOR_STATUS_EMPTY) { - last->status = GIT_DELTA_IGNORED; - - /* remove the record if we don't want ignored records */ - if (DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_IGNORED)) { - git_vector_pop(&diff->base.deltas); - git__free(last); - } - } - - return 0; - } - - /* try to advance into directory if necessary */ - if (recurse_into_dir) { - error = iterator_advance_into(&info->nitem, info->new_iter); - - /* if directory is empty, can't advance into it, so skip it */ - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = iterator_advance(&info->nitem, info->new_iter); - } - - return error; - } - } - - else if (delta_type == GIT_DELTA_IGNORED && - DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_RECURSE_IGNORED_DIRS) && - git_iterator_current_tree_is_ignored(info->new_iter)) - /* item contained in ignored directory, so skip over it */ - return iterator_advance(&info->nitem, info->new_iter); - - else if (info->new_iter->type != GIT_ITERATOR_WORKDIR) { - if (delta_type != GIT_DELTA_CONFLICTED) - delta_type = GIT_DELTA_ADDED; - } - - else if (nitem->mode == GIT_FILEMODE_COMMIT) { - /* ignore things that are not actual submodules */ - if (git_submodule_lookup(NULL, info->repo, nitem->path) != 0) { - git_error_clear(); - delta_type = GIT_DELTA_IGNORED; - - /* if this contains a tracked item, treat as normal TREE */ - if (contains_oitem) { - error = iterator_advance_into(&info->nitem, info->new_iter); - if (error != GIT_ENOTFOUND) - return error; - - git_error_clear(); - return iterator_advance(&info->nitem, info->new_iter); - } - } - } - - else if (nitem->mode == GIT_FILEMODE_UNREADABLE) { - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED)) - delta_type = GIT_DELTA_UNTRACKED; - else - delta_type = GIT_DELTA_UNREADABLE; - } - - /* Actually create the record for this item if necessary */ - if ((error = diff_delta__from_one(diff, delta_type, NULL, nitem)) != 0) - return error; - - /* If user requested TYPECHANGE records, then check for that instead of - * just generating an ADDED/UNTRACKED record - */ - if (delta_type != GIT_DELTA_IGNORED && - DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES) && - contains_oitem) - { - /* this entry was prefixed with a tree - make TYPECHANGE */ - git_diff_delta *last = diff_delta__last_for_item(diff, nitem); - if (last) { - last->status = GIT_DELTA_TYPECHANGE; - last->old_file.mode = GIT_FILEMODE_TREE; - } - } - - return iterator_advance(&info->nitem, info->new_iter); -} - -static int handle_unmatched_old_item( - git_diff_generated *diff, diff_in_progress *info) -{ - git_delta_t delta_type = GIT_DELTA_DELETED; - int error; - - /* update delta_type if this item is conflicted */ - if (git_index_entry_is_conflict(info->oitem)) - delta_type = GIT_DELTA_CONFLICTED; - - if ((error = diff_delta__from_one(diff, delta_type, info->oitem, NULL)) < 0) - return error; - - /* if we are generating TYPECHANGE records then check for that - * instead of just generating a DELETE record - */ - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES) && - entry_is_prefixed(diff, info->nitem, info->oitem)) - { - /* this entry has become a tree! convert to TYPECHANGE */ - git_diff_delta *last = diff_delta__last_for_item(diff, info->oitem); - if (last) { - last->status = GIT_DELTA_TYPECHANGE; - last->new_file.mode = GIT_FILEMODE_TREE; - } - - /* If new_iter is a workdir iterator, then this situation - * will certainly be followed by a series of untracked items. - * Unless RECURSE_UNTRACKED_DIRS is set, skip over them... - */ - if (S_ISDIR(info->nitem->mode) && - DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_RECURSE_UNTRACKED_DIRS)) - return iterator_advance(&info->nitem, info->new_iter); - } - - return iterator_advance(&info->oitem, info->old_iter); -} - -static int handle_matched_item( - git_diff_generated *diff, diff_in_progress *info) -{ - int error = 0; - - if ((error = maybe_modified(diff, info)) < 0) - return error; - - if (!(error = iterator_advance(&info->oitem, info->old_iter))) - error = iterator_advance(&info->nitem, info->new_iter); - - return error; -} - -int git_diff__from_iterators( - git_diff **out, - git_repository *repo, - git_iterator *old_iter, - git_iterator *new_iter, - const git_diff_options *opts) -{ - git_diff_generated *diff; - diff_in_progress info = {0}; - int error = 0; - - *out = NULL; - - diff = diff_generated_alloc(repo, old_iter, new_iter); - GIT_ERROR_CHECK_ALLOC(diff); - - info.repo = repo; - info.old_iter = old_iter; - info.new_iter = new_iter; - - /* make iterators have matching icase behavior */ - if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE)) { - if ((error = git_iterator_set_ignore_case(old_iter, true)) < 0 || - (error = git_iterator_set_ignore_case(new_iter, true)) < 0) - goto cleanup; - } - - /* finish initialization */ - if ((error = diff_generated_apply_options(diff, opts)) < 0) - goto cleanup; - - if ((error = iterator_current(&info.oitem, old_iter)) < 0 || - (error = iterator_current(&info.nitem, new_iter)) < 0) - goto cleanup; - - /* run iterators building diffs */ - while (!error && (info.oitem || info.nitem)) { - int cmp; - - /* report progress */ - if (opts && opts->progress_cb) { - if ((error = opts->progress_cb(&diff->base, - info.oitem ? info.oitem->path : NULL, - info.nitem ? info.nitem->path : NULL, - opts->payload))) - break; - } - - cmp = info.oitem ? - (info.nitem ? diff->base.entrycomp(info.oitem, info.nitem) : -1) : 1; - - /* create DELETED records for old items not matched in new */ - if (cmp < 0) - error = handle_unmatched_old_item(diff, &info); - - /* create ADDED, TRACKED, or IGNORED records for new items not - * matched in old (and/or descend into directories as needed) - */ - else if (cmp > 0) - error = handle_unmatched_new_item(diff, &info); - - /* otherwise item paths match, so create MODIFIED record - * (or ADDED and DELETED pair if type changed) - */ - else - error = handle_matched_item(diff, &info); - } - - diff->base.perf.stat_calls += - old_iter->stat_calls + new_iter->stat_calls; - -cleanup: - if (!error) - *out = &diff->base; - else - git_diff_free(&diff->base); - if (info.submodule_cache) - git_submodule_cache_free(info.submodule_cache); - - return error; -} - -static int diff_prepare_iterator_opts(char **prefix, git_iterator_options *a, int aflags, - git_iterator_options *b, int bflags, - const git_diff_options *opts) -{ - GIT_ERROR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); - - *prefix = NULL; - - if (opts && (opts->flags & GIT_DIFF_DISABLE_PATHSPEC_MATCH)) { - a->pathlist.strings = opts->pathspec.strings; - a->pathlist.count = opts->pathspec.count; - b->pathlist.strings = opts->pathspec.strings; - b->pathlist.count = opts->pathspec.count; - } else if (opts) { - *prefix = git_pathspec_prefix(&opts->pathspec); - GIT_ERROR_CHECK_ALLOC(prefix); - } - - a->flags = aflags; - b->flags = bflags; - a->start = b->start = *prefix; - a->end = b->end = *prefix; - - return 0; -} - -int git_diff_tree_to_tree( - git_diff **out, - git_repository *repo, - git_tree *old_tree, - git_tree *new_tree, - const git_diff_options *opts) -{ - git_iterator_flag_t iflag = GIT_ITERATOR_DONT_IGNORE_CASE; - git_iterator_options a_opts = GIT_ITERATOR_OPTIONS_INIT, - b_opts = GIT_ITERATOR_OPTIONS_INIT; - git_iterator *a = NULL, *b = NULL; - git_diff *diff = NULL; - char *prefix = NULL; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - *out = NULL; - - /* for tree to tree diff, be case sensitive even if the index is - * currently case insensitive, unless the user explicitly asked - * for case insensitivity - */ - if (opts && (opts->flags & GIT_DIFF_IGNORE_CASE) != 0) - iflag = GIT_ITERATOR_IGNORE_CASE; - - if ((error = diff_prepare_iterator_opts(&prefix, &a_opts, iflag, &b_opts, iflag, opts)) < 0 || - (error = git_iterator_for_tree(&a, old_tree, &a_opts)) < 0 || - (error = git_iterator_for_tree(&b, new_tree, &b_opts)) < 0 || - (error = git_diff__from_iterators(&diff, repo, a, b, opts)) < 0) - goto out; - - *out = diff; - diff = NULL; -out: - git_iterator_free(a); - git_iterator_free(b); - git_diff_free(diff); - git__free(prefix); - - return error; -} - -static int diff_load_index(git_index **index, git_repository *repo) -{ - int error = git_repository_index__weakptr(index, repo); - - /* reload the repository index when user did not pass one in */ - if (!error && git_index_read(*index, false) < 0) - git_error_clear(); - - return error; -} - -int git_diff_tree_to_index( - git_diff **out, - git_repository *repo, - git_tree *old_tree, - git_index *index, - const git_diff_options *opts) -{ - git_iterator_flag_t iflag = GIT_ITERATOR_DONT_IGNORE_CASE | - GIT_ITERATOR_INCLUDE_CONFLICTS; - git_iterator_options a_opts = GIT_ITERATOR_OPTIONS_INIT, - b_opts = GIT_ITERATOR_OPTIONS_INIT; - git_iterator *a = NULL, *b = NULL; - git_diff *diff = NULL; - char *prefix = NULL; - bool index_ignore_case = false; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - *out = NULL; - - if (!index && (error = diff_load_index(&index, repo)) < 0) - return error; - - index_ignore_case = index->ignore_case; - - if ((error = diff_prepare_iterator_opts(&prefix, &a_opts, iflag, &b_opts, iflag, opts)) < 0 || - (error = git_iterator_for_tree(&a, old_tree, &a_opts)) < 0 || - (error = git_iterator_for_index(&b, repo, index, &b_opts)) < 0 || - (error = git_diff__from_iterators(&diff, repo, a, b, opts)) < 0) - goto out; - - /* if index is in case-insensitive order, re-sort deltas to match */ - if (index_ignore_case) - diff_set_ignore_case(diff, true); - - *out = diff; - diff = NULL; -out: - git_iterator_free(a); - git_iterator_free(b); - git_diff_free(diff); - git__free(prefix); - - return error; -} - -int git_diff_index_to_workdir( - git_diff **out, - git_repository *repo, - git_index *index, - const git_diff_options *opts) -{ - git_iterator_options a_opts = GIT_ITERATOR_OPTIONS_INIT, - b_opts = GIT_ITERATOR_OPTIONS_INIT; - git_iterator *a = NULL, *b = NULL; - git_diff *diff = NULL; - char *prefix = NULL; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - *out = NULL; - - if (!index && (error = diff_load_index(&index, repo)) < 0) - return error; - - if ((error = diff_prepare_iterator_opts(&prefix, &a_opts, GIT_ITERATOR_INCLUDE_CONFLICTS, - &b_opts, GIT_ITERATOR_DONT_AUTOEXPAND, opts)) < 0 || - (error = git_iterator_for_index(&a, repo, index, &a_opts)) < 0 || - (error = git_iterator_for_workdir(&b, repo, index, NULL, &b_opts)) < 0 || - (error = git_diff__from_iterators(&diff, repo, a, b, opts)) < 0) - goto out; - - if ((diff->opts.flags & GIT_DIFF_UPDATE_INDEX) && ((git_diff_generated *)diff)->index_updated) - if ((error = git_index_write(index)) < 0) - goto out; - - *out = diff; - diff = NULL; -out: - git_iterator_free(a); - git_iterator_free(b); - git_diff_free(diff); - git__free(prefix); - - return error; -} - -int git_diff_tree_to_workdir( - git_diff **out, - git_repository *repo, - git_tree *old_tree, - const git_diff_options *opts) -{ - git_iterator_options a_opts = GIT_ITERATOR_OPTIONS_INIT, - b_opts = GIT_ITERATOR_OPTIONS_INIT; - git_iterator *a = NULL, *b = NULL; - git_diff *diff = NULL; - char *prefix = NULL; - git_index *index; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - *out = NULL; - - if ((error = diff_prepare_iterator_opts(&prefix, &a_opts, 0, - &b_opts, GIT_ITERATOR_DONT_AUTOEXPAND, opts) < 0) || - (error = git_repository_index__weakptr(&index, repo)) < 0 || - (error = git_iterator_for_tree(&a, old_tree, &a_opts)) < 0 || - (error = git_iterator_for_workdir(&b, repo, index, old_tree, &b_opts)) < 0 || - (error = git_diff__from_iterators(&diff, repo, a, b, opts)) < 0) - goto out; - - *out = diff; - diff = NULL; -out: - git_iterator_free(a); - git_iterator_free(b); - git_diff_free(diff); - git__free(prefix); - - return error; -} - -int git_diff_tree_to_workdir_with_index( - git_diff **out, - git_repository *repo, - git_tree *tree, - const git_diff_options *opts) -{ - git_diff *d1 = NULL, *d2 = NULL; - git_index *index = NULL; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - *out = NULL; - - if ((error = diff_load_index(&index, repo)) < 0) - return error; - - if (!(error = git_diff_tree_to_index(&d1, repo, tree, index, opts)) && - !(error = git_diff_index_to_workdir(&d2, repo, index, opts))) - error = git_diff_merge(d1, d2); - - git_diff_free(d2); - - if (error) { - git_diff_free(d1); - d1 = NULL; - } - - *out = d1; - return error; -} - -int git_diff_index_to_index( - git_diff **out, - git_repository *repo, - git_index *old_index, - git_index *new_index, - const git_diff_options *opts) -{ - git_iterator_options a_opts = GIT_ITERATOR_OPTIONS_INIT, - b_opts = GIT_ITERATOR_OPTIONS_INIT; - git_iterator *a = NULL, *b = NULL; - git_diff *diff = NULL; - char *prefix = NULL; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(old_index); - GIT_ASSERT_ARG(new_index); - - *out = NULL; - - if ((error = diff_prepare_iterator_opts(&prefix, &a_opts, GIT_ITERATOR_DONT_IGNORE_CASE, - &b_opts, GIT_ITERATOR_DONT_IGNORE_CASE, opts) < 0) || - (error = git_iterator_for_index(&a, repo, old_index, &a_opts)) < 0 || - (error = git_iterator_for_index(&b, repo, new_index, &b_opts)) < 0 || - (error = git_diff__from_iterators(&diff, repo, a, b, opts)) < 0) - goto out; - - /* if index is in case-insensitive order, re-sort deltas to match */ - if (old_index->ignore_case || new_index->ignore_case) - diff_set_ignore_case(diff, true); - - *out = diff; - diff = NULL; -out: - git_iterator_free(a); - git_iterator_free(b); - git_diff_free(diff); - git__free(prefix); - - return error; -} - -int git_diff__paired_foreach( - git_diff *head2idx, - git_diff *idx2wd, - int (*cb)(git_diff_delta *h2i, git_diff_delta *i2w, void *payload), - void *payload) -{ - int cmp, error = 0; - git_diff_delta *h2i, *i2w; - size_t i, j, i_max, j_max; - int (*strcomp)(const char *, const char *) = git__strcmp; - bool h2i_icase, i2w_icase, icase_mismatch; - - i_max = head2idx ? head2idx->deltas.length : 0; - j_max = idx2wd ? idx2wd->deltas.length : 0; - if (!i_max && !j_max) - return 0; - - /* At some point, tree-to-index diffs will probably never ignore case, - * even if that isn't true now. Index-to-workdir diffs may or may not - * ignore case, but the index filename for the idx2wd diff should - * still be using the canonical case-preserving name. - * - * Therefore the main thing we need to do here is make sure the diffs - * are traversed in a compatible order. To do this, we temporarily - * resort a mismatched diff to get the order correct. - * - * In order to traverse renames in the index->workdir, we need to - * ensure that we compare the index name on both sides, so we - * always sort by the old name in the i2w list. - */ - h2i_icase = head2idx != NULL && git_diff_is_sorted_icase(head2idx); - i2w_icase = idx2wd != NULL && git_diff_is_sorted_icase(idx2wd); - - icase_mismatch = - (head2idx != NULL && idx2wd != NULL && h2i_icase != i2w_icase); - - if (icase_mismatch && h2i_icase) { - git_vector_set_cmp(&head2idx->deltas, git_diff_delta__cmp); - git_vector_sort(&head2idx->deltas); - } - - if (i2w_icase && !icase_mismatch) { - strcomp = git__strcasecmp; - - git_vector_set_cmp(&idx2wd->deltas, diff_delta_i2w_casecmp); - git_vector_sort(&idx2wd->deltas); - } else if (idx2wd != NULL) { - git_vector_set_cmp(&idx2wd->deltas, diff_delta_i2w_cmp); - git_vector_sort(&idx2wd->deltas); - } - - for (i = 0, j = 0; i < i_max || j < j_max; ) { - h2i = head2idx ? GIT_VECTOR_GET(&head2idx->deltas, i) : NULL; - i2w = idx2wd ? GIT_VECTOR_GET(&idx2wd->deltas, j) : NULL; - - cmp = !i2w ? -1 : !h2i ? 1 : - strcomp(h2i->new_file.path, i2w->old_file.path); - - if (cmp < 0) { - i++; i2w = NULL; - } else if (cmp > 0) { - j++; h2i = NULL; - } else { - i++; j++; - } - - if ((error = cb(h2i, i2w, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - /* restore case-insensitive delta sort */ - if (icase_mismatch && h2i_icase) { - git_vector_set_cmp(&head2idx->deltas, git_diff_delta__casecmp); - git_vector_sort(&head2idx->deltas); - } - - /* restore idx2wd sort by new path */ - if (idx2wd != NULL) { - git_vector_set_cmp(&idx2wd->deltas, - i2w_icase ? git_diff_delta__casecmp : git_diff_delta__cmp); - git_vector_sort(&idx2wd->deltas); - } - - return error; -} - -int git_diff__commit( - git_diff **out, - git_repository *repo, - const git_commit *commit, - const git_diff_options *opts) -{ - git_commit *parent = NULL; - git_diff *commit_diff = NULL; - git_tree *old_tree = NULL, *new_tree = NULL; - size_t parents; - int error = 0; - - *out = NULL; - - if ((parents = git_commit_parentcount(commit)) > 1) { - char commit_oidstr[GIT_OID_MAX_HEXSIZE + 1]; - - error = -1; - git_error_set(GIT_ERROR_INVALID, "commit %s is a merge commit", - git_oid_tostr(commit_oidstr, GIT_OID_MAX_HEXSIZE + 1, git_commit_id(commit))); - goto on_error; - } - - if (parents > 0) - if ((error = git_commit_parent(&parent, commit, 0)) < 0 || - (error = git_commit_tree(&old_tree, parent)) < 0) - goto on_error; - - if ((error = git_commit_tree(&new_tree, commit)) < 0 || - (error = git_diff_tree_to_tree(&commit_diff, repo, old_tree, new_tree, opts)) < 0) - goto on_error; - - *out = commit_diff; - -on_error: - git_tree_free(new_tree); - git_tree_free(old_tree); - git_commit_free(parent); - - return error; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_generate.h b/vendor/libgit2-sys/libgit2/src/libgit2/diff_generate.h deleted file mode 100644 index b782f29..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_generate.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_diff_generate_h__ -#define INCLUDE_diff_generate_h__ - -#include "common.h" - -#include "diff.h" -#include "pool.h" -#include "index.h" - -enum { - GIT_DIFFCAPS_HAS_SYMLINKS = (1 << 0), /* symlinks on platform? */ - GIT_DIFFCAPS_IGNORE_STAT = (1 << 1), /* use stat? */ - GIT_DIFFCAPS_TRUST_MODE_BITS = (1 << 2), /* use st_mode? */ - GIT_DIFFCAPS_TRUST_CTIME = (1 << 3), /* use st_ctime? */ - GIT_DIFFCAPS_USE_DEV = (1 << 4) /* use st_dev? */ -}; - -#define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY) -#define DIFF_FLAGS_NOT_BINARY (GIT_DIFF_FLAG_NOT_BINARY|GIT_DIFF_FLAG__NO_DATA) - -enum { - GIT_DIFF_FLAG__FREE_PATH = (1 << 7), /* `path` is allocated memory */ - GIT_DIFF_FLAG__FREE_DATA = (1 << 8), /* internal file data is allocated */ - GIT_DIFF_FLAG__UNMAP_DATA = (1 << 9), /* internal file data is mmap'ed */ - GIT_DIFF_FLAG__NO_DATA = (1 << 10), /* file data should not be loaded */ - GIT_DIFF_FLAG__FREE_BLOB = (1 << 11), /* release the blob when done */ - GIT_DIFF_FLAG__LOADED = (1 << 12), /* file data has been loaded */ - - GIT_DIFF_FLAG__TO_DELETE = (1 << 16), /* delete entry during rename det. */ - GIT_DIFF_FLAG__TO_SPLIT = (1 << 17), /* split entry during rename det. */ - GIT_DIFF_FLAG__IS_RENAME_TARGET = (1 << 18), - GIT_DIFF_FLAG__IS_RENAME_SOURCE = (1 << 19), - GIT_DIFF_FLAG__HAS_SELF_SIMILARITY = (1 << 20) -}; - -#define GIT_DIFF_FLAG__CLEAR_INTERNAL(F) (F) = ((F) & 0x00FFFF) - -#define GIT_DIFF__VERBOSE (1 << 30) - -extern void git_diff_addref(git_diff *diff); - -extern bool git_diff_delta__should_skip( - const git_diff_options *opts, const git_diff_delta *delta); - -extern int git_diff__from_iterators( - git_diff **diff_ptr, - git_repository *repo, - git_iterator *old_iter, - git_iterator *new_iter, - const git_diff_options *opts); - -extern int git_diff__commit( - git_diff **diff, git_repository *repo, const git_commit *commit, const git_diff_options *opts); - -extern int git_diff__paired_foreach( - git_diff *idx2head, - git_diff *wd2idx, - int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload), - void *payload); - -/* Merge two `git_diff`s according to the callback given by `cb`. */ - -typedef git_diff_delta *(*git_diff__merge_cb)( - const git_diff_delta *left, - const git_diff_delta *right, - git_pool *pool); - -extern int git_diff__merge( - git_diff *onto, const git_diff *from, git_diff__merge_cb cb); - -extern git_diff_delta *git_diff__merge_like_cgit( - const git_diff_delta *a, - const git_diff_delta *b, - git_pool *pool); - -/* Duplicate a `git_diff_delta` out of the `git_pool` */ -extern git_diff_delta *git_diff__delta_dup( - const git_diff_delta *d, git_pool *pool); - -extern int git_diff__oid_for_file( - git_oid *out, - git_diff *diff, - const char *path, - uint16_t mode, - git_object_size_t size); - -extern int git_diff__oid_for_entry( - git_oid *out, - git_diff *diff, - const git_index_entry *src, - uint16_t mode, - const git_oid *update_match); - -/* - * Sometimes a git_diff_file will have a zero size; this attempts to - * fill in the size without loading the blob if possible. If that is - * not possible, then it will return the git_odb_object that had to be - * loaded and the caller can use it or dispose of it as needed. - */ -GIT_INLINE(int) git_diff_file__resolve_zero_size( - git_diff_file *file, git_odb_object **odb_obj, git_repository *repo) -{ - int error; - git_odb *odb; - size_t len; - git_object_t type; - - if ((error = git_repository_odb(&odb, repo)) < 0) - return error; - - error = git_odb__read_header_or_object( - odb_obj, &len, &type, odb, &file->id); - - git_odb_free(odb); - - if (!error) { - file->size = (git_object_size_t)len; - file->flags |= GIT_DIFF_FLAG_VALID_SIZE; - } - - return error; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_parse.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff_parse.c deleted file mode 100644 index 02eb21e..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_parse.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "diff_parse.h" - -#include "diff.h" -#include "patch.h" -#include "patch_parse.h" - -static void diff_parsed_free(git_diff *d) -{ - git_diff_parsed *diff = (git_diff_parsed *)d; - git_patch *patch; - size_t i; - - git_vector_foreach(&diff->patches, i, patch) - git_patch_free(patch); - - git_vector_dispose(&diff->patches); - - git_vector_dispose(&diff->base.deltas); - git_pool_clear(&diff->base.pool); - - git__memzero(diff, sizeof(*diff)); - git__free(diff); -} - -static git_diff_parsed *diff_parsed_alloc(git_oid_t oid_type) -{ - git_diff_parsed *diff; - - if ((diff = git__calloc(1, sizeof(git_diff_parsed))) == NULL) - return NULL; - - GIT_REFCOUNT_INC(&diff->base); - diff->base.type = GIT_DIFF_TYPE_PARSED; - diff->base.strcomp = git__strcmp; - diff->base.strncomp = git__strncmp; - diff->base.pfxcomp = git__prefixcmp; - diff->base.entrycomp = git_diff__entry_cmp; - diff->base.patch_fn = git_patch_parsed_from_diff; - diff->base.free_fn = diff_parsed_free; - - if (git_diff_options_init(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION) < 0) { - git__free(diff); - return NULL; - } - - diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE; - diff->base.opts.oid_type = oid_type; - - if (git_pool_init(&diff->base.pool, 1) < 0 || - git_vector_init(&diff->patches, 0, NULL) < 0 || - git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) { - git_diff_free(&diff->base); - return NULL; - } - - git_vector_set_cmp(&diff->base.deltas, git_diff_delta__cmp); - - return diff; -} - -int git_diff_from_buffer( - git_diff **out, - const char *content, - size_t content_len -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_diff_parse_options *opts -#endif - ) -{ - git_diff_parsed *diff; - git_patch *patch; - git_patch_parse_ctx *ctx = NULL; - git_patch_options patch_opts = GIT_PATCH_OPTIONS_INIT; - git_oid_t oid_type; - int error = 0; - - *out = NULL; - -#ifdef GIT_EXPERIMENTAL_SHA256 - oid_type = (opts && opts->oid_type) ? opts->oid_type : - GIT_OID_DEFAULT; -#else - oid_type = GIT_OID_DEFAULT; -#endif - - patch_opts.oid_type = oid_type; - - diff = diff_parsed_alloc(oid_type); - GIT_ERROR_CHECK_ALLOC(diff); - - ctx = git_patch_parse_ctx_init(content, content_len, &patch_opts); - GIT_ERROR_CHECK_ALLOC(ctx); - - while (ctx->parse_ctx.remain_len) { - if ((error = git_patch_parse(&patch, ctx)) < 0) - break; - - git_vector_insert(&diff->patches, patch); - git_vector_insert(&diff->base.deltas, patch->delta); - } - - if (error == GIT_ENOTFOUND && git_vector_length(&diff->patches) > 0) { - git_error_clear(); - error = 0; - } - - git_patch_parse_ctx_free(ctx); - - if (error < 0) - git_diff_free(&diff->base); - else - *out = &diff->base; - - return error; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_parse.h b/vendor/libgit2-sys/libgit2/src/libgit2/diff_parse.h deleted file mode 100644 index 8767821..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_parse.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_diff_parse_h__ -#define INCLUDE_diff_parse_h__ - -#include "common.h" - -#include "diff.h" - -typedef struct { - struct git_diff base; - - git_vector patches; -} git_diff_parsed; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_print.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff_print.c deleted file mode 100644 index 0ffba0d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_print.c +++ /dev/null @@ -1,905 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "buf.h" -#include "diff.h" -#include "diff_file.h" -#include "patch_generate.h" -#include "futils.h" -#include "zstream.h" -#include "blob.h" -#include "delta.h" -#include "repository.h" -#include "git2/sys/diff.h" - -typedef struct { - git_diff_format_t format; - git_diff_line_cb print_cb; - void *payload; - - git_str *buf; - git_diff_line line; - - const char *old_prefix; - const char *new_prefix; - uint32_t flags; - int id_strlen; - unsigned int sent_file_header; - git_oid_t oid_type; - - int (*strcomp)(const char *, const char *); -} diff_print_info; - -static int diff_print_info_init__common( - diff_print_info *pi, - git_str *out, - git_repository *repo, - git_diff_format_t format, - git_diff_line_cb cb, - void *payload) -{ - pi->format = format; - pi->print_cb = cb; - pi->payload = payload; - pi->buf = out; - - GIT_ASSERT(pi->oid_type); - - if (!pi->id_strlen) { - if (!repo) - pi->id_strlen = GIT_ABBREV_DEFAULT; - else if (git_repository__abbrev_length(&pi->id_strlen, repo) < 0) - return -1; - } - - memset(&pi->line, 0, sizeof(pi->line)); - pi->line.old_lineno = -1; - pi->line.new_lineno = -1; - pi->line.num_lines = 1; - - return 0; -} - -static int diff_print_info_init_fromdiff( - diff_print_info *pi, - git_str *out, - git_diff *diff, - git_diff_format_t format, - git_diff_line_cb cb, - void *payload) -{ - git_repository *repo = diff ? diff->repo : NULL; - - memset(pi, 0, sizeof(diff_print_info)); - - if (diff) { - pi->flags = diff->opts.flags; - pi->oid_type = diff->opts.oid_type; - pi->id_strlen = diff->opts.id_abbrev; - pi->old_prefix = diff->opts.old_prefix; - pi->new_prefix = diff->opts.new_prefix; - - pi->strcomp = diff->strcomp; - } - - return diff_print_info_init__common(pi, out, repo, format, cb, payload); -} - -static int diff_print_info_init_frompatch( - diff_print_info *pi, - git_str *out, - git_patch *patch, - git_diff_format_t format, - git_diff_line_cb cb, - void *payload) -{ - GIT_ASSERT_ARG(patch); - - memset(pi, 0, sizeof(diff_print_info)); - - pi->flags = patch->diff_opts.flags; - pi->oid_type = patch->diff_opts.oid_type; - pi->id_strlen = patch->diff_opts.id_abbrev; - pi->old_prefix = patch->diff_opts.old_prefix; - pi->new_prefix = patch->diff_opts.new_prefix; - - return diff_print_info_init__common(pi, out, patch->repo, format, cb, payload); -} - -static char diff_pick_suffix(int mode) -{ - if (S_ISDIR(mode)) - return '/'; - else if (GIT_PERMS_IS_EXEC(mode)) /* -V536 */ - /* in git, modes are very regular, so we must have 0100755 mode */ - return '*'; - else - return ' '; -} - -char git_diff_status_char(git_delta_t status) -{ - char code; - - switch (status) { - case GIT_DELTA_ADDED: code = 'A'; break; - case GIT_DELTA_DELETED: code = 'D'; break; - case GIT_DELTA_MODIFIED: code = 'M'; break; - case GIT_DELTA_RENAMED: code = 'R'; break; - case GIT_DELTA_COPIED: code = 'C'; break; - case GIT_DELTA_IGNORED: code = 'I'; break; - case GIT_DELTA_UNTRACKED: code = '?'; break; - case GIT_DELTA_TYPECHANGE: code = 'T'; break; - case GIT_DELTA_UNREADABLE: code = 'X'; break; - default: code = ' '; break; - } - - return code; -} - -static int diff_print_one_name_only( - const git_diff_delta *delta, float progress, void *data) -{ - diff_print_info *pi = data; - git_str *out = pi->buf; - - GIT_UNUSED(progress); - - if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && - delta->status == GIT_DELTA_UNMODIFIED) - return 0; - - git_str_clear(out); - git_str_puts(out, delta->new_file.path); - git_str_putc(out, '\n'); - if (git_str_oom(out)) - return -1; - - pi->line.origin = GIT_DIFF_LINE_FILE_HDR; - pi->line.content = git_str_cstr(out); - pi->line.content_len = git_str_len(out); - - return pi->print_cb(delta, NULL, &pi->line, pi->payload); -} - -static int diff_print_one_name_status( - const git_diff_delta *delta, float progress, void *data) -{ - diff_print_info *pi = data; - git_str *out = pi->buf; - char old_suffix, new_suffix, code = git_diff_status_char(delta->status); - int(*strcomp)(const char *, const char *) = pi->strcomp ? - pi->strcomp : git__strcmp; - - GIT_UNUSED(progress); - - if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && code == ' ') - return 0; - - old_suffix = diff_pick_suffix(delta->old_file.mode); - new_suffix = diff_pick_suffix(delta->new_file.mode); - - git_str_clear(out); - - if (delta->old_file.path != delta->new_file.path && - strcomp(delta->old_file.path,delta->new_file.path) != 0) - git_str_printf(out, "%c\t%s%c %s%c\n", code, - delta->old_file.path, old_suffix, delta->new_file.path, new_suffix); - else if (delta->old_file.mode != delta->new_file.mode && - delta->old_file.mode != 0 && delta->new_file.mode != 0) - git_str_printf(out, "%c\t%s%c %s%c\n", code, - delta->old_file.path, old_suffix, delta->new_file.path, new_suffix); - else if (old_suffix != ' ') - git_str_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix); - else - git_str_printf(out, "%c\t%s\n", code, delta->old_file.path); - if (git_str_oom(out)) - return -1; - - pi->line.origin = GIT_DIFF_LINE_FILE_HDR; - pi->line.content = git_str_cstr(out); - pi->line.content_len = git_str_len(out); - - return pi->print_cb(delta, NULL, &pi->line, pi->payload); -} - -static int diff_print_one_raw( - const git_diff_delta *delta, float progress, void *data) -{ - diff_print_info *pi = data; - git_str *out = pi->buf; - int id_abbrev; - char code = git_diff_status_char(delta->status); - char start_oid[GIT_OID_MAX_HEXSIZE + 1], - end_oid[GIT_OID_MAX_HEXSIZE + 1]; - size_t oid_hexsize; - bool id_is_abbrev; - - GIT_UNUSED(progress); - - if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && code == ' ') - return 0; - - git_str_clear(out); - - id_abbrev = delta->old_file.mode ? delta->old_file.id_abbrev : - delta->new_file.id_abbrev; - - if (pi->id_strlen > id_abbrev) { - git_error_set(GIT_ERROR_PATCH, - "the patch input contains %d id characters (cannot print %d)", - id_abbrev, pi->id_strlen); - return -1; - } - -#ifdef GIT_EXPERIMENTAL_SHA256 - GIT_ASSERT(delta->old_file.id.type == delta->new_file.id.type); - oid_hexsize = git_oid_hexsize(delta->old_file.id.type); -#else - oid_hexsize = GIT_OID_SHA1_HEXSIZE; -#endif - - id_is_abbrev = (pi->id_strlen > 0 && - (size_t)pi->id_strlen <= oid_hexsize); - - git_oid_tostr(start_oid, pi->id_strlen + 1, &delta->old_file.id); - git_oid_tostr(end_oid, pi->id_strlen + 1, &delta->new_file.id); - - git_str_printf(out, - id_is_abbrev ? ":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c", - delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code); - - if (delta->similarity > 0) - git_str_printf(out, "%03u", delta->similarity); - - if (delta->old_file.path != delta->new_file.path) - git_str_printf( - out, "\t%s %s\n", delta->old_file.path, delta->new_file.path); - else - git_str_printf( - out, "\t%s\n", delta->old_file.path ? - delta->old_file.path : delta->new_file.path); - - if (git_str_oom(out)) - return -1; - - pi->line.origin = GIT_DIFF_LINE_FILE_HDR; - pi->line.content = git_str_cstr(out); - pi->line.content_len = git_str_len(out); - - return pi->print_cb(delta, NULL, &pi->line, pi->payload); -} - -static int diff_print_modes( - git_str *out, const git_diff_delta *delta) -{ - git_str_printf(out, "old mode %o\n", delta->old_file.mode); - git_str_printf(out, "new mode %o\n", delta->new_file.mode); - - return git_str_oom(out) ? -1 : 0; -} - -static int diff_print_oid_range( - git_str *out, const git_diff_delta *delta, int id_strlen, - bool print_index) -{ - char start_oid[GIT_OID_MAX_HEXSIZE + 1], - end_oid[GIT_OID_MAX_HEXSIZE + 1]; - - if (delta->old_file.mode && - id_strlen > delta->old_file.id_abbrev) { - git_error_set(GIT_ERROR_PATCH, - "the patch input contains %d id characters (cannot print %d)", - delta->old_file.id_abbrev, id_strlen); - return -1; - } - - if ((delta->new_file.mode && - id_strlen > delta->new_file.id_abbrev)) { - git_error_set(GIT_ERROR_PATCH, - "the patch input contains %d id characters (cannot print %d)", - delta->new_file.id_abbrev, id_strlen); - return -1; - } - - git_oid_tostr(start_oid, id_strlen + 1, &delta->old_file.id); - git_oid_tostr(end_oid, id_strlen + 1, &delta->new_file.id); - - if (delta->old_file.mode == delta->new_file.mode) { - if (print_index) - git_str_printf(out, "index %s..%s %o\n", - start_oid, end_oid, delta->old_file.mode); - } else { - if (delta->old_file.mode == 0) - git_str_printf(out, "new file mode %o\n", delta->new_file.mode); - else if (delta->new_file.mode == 0) - git_str_printf(out, "deleted file mode %o\n", delta->old_file.mode); - else - diff_print_modes(out, delta); - - if (print_index) - git_str_printf(out, "index %s..%s\n", start_oid, end_oid); - } - - return git_str_oom(out) ? -1 : 0; -} - -static int diff_delta_format_path( - git_str *out, const char *prefix, const char *filename) -{ - if (!filename) { - /* don't prefix "/dev/null" */ - return git_str_puts(out, "/dev/null"); - } - - if (git_str_joinpath(out, prefix, filename) < 0) - return -1; - - return git_str_quote(out); -} - -static int diff_delta_format_with_paths( - git_str *out, - const git_diff_delta *delta, - const char *template, - const char *oldpath, - const char *newpath) -{ - if (git_oid_is_zero(&delta->old_file.id)) - oldpath = "/dev/null"; - - if (git_oid_is_zero(&delta->new_file.id)) - newpath = "/dev/null"; - - return git_str_printf(out, template, oldpath, newpath); -} - -static int diff_delta_format_similarity_header( - git_str *out, - const git_diff_delta *delta) -{ - git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT; - const char *type; - int error = 0; - - if (delta->similarity > 100) { - git_error_set(GIT_ERROR_PATCH, "invalid similarity %d", delta->similarity); - error = -1; - goto done; - } - - GIT_ASSERT(delta->status == GIT_DELTA_RENAMED || delta->status == GIT_DELTA_COPIED); - if (delta->status == GIT_DELTA_RENAMED) - type = "rename"; - else - type = "copy"; - - if ((error = git_str_puts(&old_path, delta->old_file.path)) < 0 || - (error = git_str_puts(&new_path, delta->new_file.path)) < 0 || - (error = git_str_quote(&old_path)) < 0 || - (error = git_str_quote(&new_path)) < 0) - goto done; - - git_str_printf(out, - "similarity index %d%%\n" - "%s from %s\n" - "%s to %s\n", - delta->similarity, - type, old_path.ptr, - type, new_path.ptr); - - if (git_str_oom(out)) - error = -1; - -done: - git_str_dispose(&old_path); - git_str_dispose(&new_path); - - return error; -} - -static bool delta_is_unchanged(const git_diff_delta *delta) -{ - if (git_oid_is_zero(&delta->old_file.id) && - git_oid_is_zero(&delta->new_file.id)) - return true; - - if (delta->old_file.mode == GIT_FILEMODE_COMMIT || - delta->new_file.mode == GIT_FILEMODE_COMMIT) - return false; - - if (git_oid_equal(&delta->old_file.id, &delta->new_file.id)) - return true; - - return false; -} - -int git_diff_delta__format_file_header( - git_str *out, - const git_diff_delta *delta, - const char *oldpfx, - const char *newpfx, - int id_strlen, - bool print_index) -{ - git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT; - bool unchanged = delta_is_unchanged(delta); - int error = 0; - - if (!oldpfx) - oldpfx = DIFF_OLD_PREFIX_DEFAULT; - if (!newpfx) - newpfx = DIFF_NEW_PREFIX_DEFAULT; - if (!id_strlen) - id_strlen = GIT_ABBREV_DEFAULT; - - if ((error = diff_delta_format_path( - &old_path, oldpfx, delta->old_file.path)) < 0 || - (error = diff_delta_format_path( - &new_path, newpfx, delta->new_file.path)) < 0) - goto done; - - git_str_clear(out); - - git_str_printf(out, "diff --git %s %s\n", - old_path.ptr, new_path.ptr); - - if (unchanged && delta->old_file.mode != delta->new_file.mode) - diff_print_modes(out, delta); - - if (delta->status == GIT_DELTA_RENAMED || - (delta->status == GIT_DELTA_COPIED && unchanged)) { - if ((error = diff_delta_format_similarity_header(out, delta)) < 0) - goto done; - } - - if (!unchanged) { - if ((error = diff_print_oid_range(out, delta, - id_strlen, print_index)) < 0) - goto done; - - if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0) - diff_delta_format_with_paths(out, delta, - "--- %s\n+++ %s\n", old_path.ptr, new_path.ptr); - } - - if (git_str_oom(out)) - error = -1; - -done: - git_str_dispose(&old_path); - git_str_dispose(&new_path); - - return error; -} - -static int format_binary( - diff_print_info *pi, - git_diff_binary_t type, - const char *data, - size_t datalen, - size_t inflatedlen) -{ - const char *typename = type == GIT_DIFF_BINARY_DELTA ? - "delta" : "literal"; - const char *scan, *end; - - git_str_printf(pi->buf, "%s %" PRIuZ "\n", typename, inflatedlen); - pi->line.num_lines++; - - for (scan = data, end = data + datalen; scan < end; ) { - size_t chunk_len = end - scan; - if (chunk_len > 52) - chunk_len = 52; - - if (chunk_len <= 26) - git_str_putc(pi->buf, (char)chunk_len + 'A' - 1); - else - git_str_putc(pi->buf, (char)chunk_len - 26 + 'a' - 1); - - git_str_encode_base85(pi->buf, scan, chunk_len); - git_str_putc(pi->buf, '\n'); - - if (git_str_oom(pi->buf)) - return -1; - - scan += chunk_len; - pi->line.num_lines++; - } - git_str_putc(pi->buf, '\n'); - - if (git_str_oom(pi->buf)) - return -1; - - return 0; -} - -static int diff_print_patch_file_binary_noshow( - diff_print_info *pi, git_diff_delta *delta, - const char *old_pfx, const char *new_pfx) -{ - git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT; - int error; - - if ((error = diff_delta_format_path(&old_path, old_pfx, delta->old_file.path)) < 0 || - (error = diff_delta_format_path(&new_path, new_pfx, delta->new_file.path)) < 0 || - (error = diff_delta_format_with_paths(pi->buf, delta, "Binary files %s and %s differ\n", - old_path.ptr, new_path.ptr)) < 0) - goto done; - - pi->line.num_lines = 1; - -done: - git_str_dispose(&old_path); - git_str_dispose(&new_path); - return error; -} - -static int diff_print_patch_file_binary( - diff_print_info *pi, git_diff_delta *delta, - const char *old_pfx, const char *new_pfx, - const git_diff_binary *binary) -{ - size_t pre_binary_size; - int error; - - if (delta->status == GIT_DELTA_UNMODIFIED) - return 0; - - if ((pi->flags & GIT_DIFF_SHOW_BINARY) == 0 || !binary->contains_data) - return diff_print_patch_file_binary_noshow( - pi, delta, old_pfx, new_pfx); - - pre_binary_size = pi->buf->size; - git_str_printf(pi->buf, "GIT binary patch\n"); - pi->line.num_lines++; - - if ((error = format_binary(pi, binary->new_file.type, binary->new_file.data, - binary->new_file.datalen, binary->new_file.inflatedlen)) < 0 || - (error = format_binary(pi, binary->old_file.type, binary->old_file.data, - binary->old_file.datalen, binary->old_file.inflatedlen)) < 0) { - if (error == GIT_EBUFS) { - git_error_clear(); - git_str_truncate(pi->buf, pre_binary_size); - - return diff_print_patch_file_binary_noshow( - pi, delta, old_pfx, new_pfx); - } - } - - pi->line.num_lines++; - return error; -} - -GIT_INLINE(int) should_force_header(const git_diff_delta *delta) -{ - if (delta->old_file.mode != delta->new_file.mode) - return 1; - - if (delta->status == GIT_DELTA_RENAMED || delta->status == GIT_DELTA_COPIED) - return 1; - - return 0; -} - -GIT_INLINE(int) flush_file_header(const git_diff_delta *delta, diff_print_info *pi) -{ - if (pi->sent_file_header) - return 0; - - pi->line.origin = GIT_DIFF_LINE_FILE_HDR; - pi->line.content = git_str_cstr(pi->buf); - pi->line.content_len = git_str_len(pi->buf); - pi->sent_file_header = 1; - - return pi->print_cb(delta, NULL, &pi->line, pi->payload); -} - -static int diff_print_patch_file( - const git_diff_delta *delta, float progress, void *data) -{ - int error; - diff_print_info *pi = data; - const char *oldpfx = - pi->old_prefix ? pi->old_prefix : DIFF_OLD_PREFIX_DEFAULT; - const char *newpfx = - pi->new_prefix ? pi->new_prefix : DIFF_NEW_PREFIX_DEFAULT; - - bool binary = (delta->flags & GIT_DIFF_FLAG_BINARY) || - (pi->flags & GIT_DIFF_FORCE_BINARY); - bool show_binary = !!(pi->flags & GIT_DIFF_SHOW_BINARY); - int id_strlen = pi->id_strlen; - bool print_index = (pi->format != GIT_DIFF_FORMAT_PATCH_ID); - - if (binary && show_binary) - id_strlen = delta->old_file.id_abbrev ? delta->old_file.id_abbrev : - delta->new_file.id_abbrev; - - GIT_UNUSED(progress); - - if (S_ISDIR(delta->new_file.mode) || - delta->status == GIT_DELTA_UNMODIFIED || - delta->status == GIT_DELTA_IGNORED || - delta->status == GIT_DELTA_UNREADABLE || - (delta->status == GIT_DELTA_UNTRACKED && - (pi->flags & GIT_DIFF_SHOW_UNTRACKED_CONTENT) == 0)) - return 0; - - pi->sent_file_header = 0; - - if ((error = git_diff_delta__format_file_header(pi->buf, delta, oldpfx, newpfx, - id_strlen, print_index)) < 0) - return error; - - /* - * pi->buf now contains the file header data. Go ahead and send it - * if there's useful data in there, like similarity. Otherwise, we - * should queue it to send when we see the first hunk. This prevents - * us from sending a header when all hunks were ignored. - */ - if (should_force_header(delta) && (error = flush_file_header(delta, pi)) < 0) - return error; - - return 0; -} - -static int diff_print_patch_binary( - const git_diff_delta *delta, - const git_diff_binary *binary, - void *data) -{ - diff_print_info *pi = data; - const char *old_pfx = - pi->old_prefix ? pi->old_prefix : DIFF_OLD_PREFIX_DEFAULT; - const char *new_pfx = - pi->new_prefix ? pi->new_prefix : DIFF_NEW_PREFIX_DEFAULT; - int error; - - if ((error = flush_file_header(delta, pi)) < 0) - return error; - - /* - * If the caller only wants the header, we just needed to make sure to - * call flush_file_header - */ - if (pi->format == GIT_DIFF_FORMAT_PATCH_HEADER) - return 0; - - git_str_clear(pi->buf); - - if ((error = diff_print_patch_file_binary( - pi, (git_diff_delta *)delta, old_pfx, new_pfx, binary)) < 0) - return error; - - pi->line.origin = GIT_DIFF_LINE_BINARY; - pi->line.content = git_str_cstr(pi->buf); - pi->line.content_len = git_str_len(pi->buf); - - return pi->print_cb(delta, NULL, &pi->line, pi->payload); -} - -static int diff_print_patch_hunk( - const git_diff_delta *d, - const git_diff_hunk *h, - void *data) -{ - diff_print_info *pi = data; - int error; - - if (S_ISDIR(d->new_file.mode)) - return 0; - - if ((error = flush_file_header(d, pi)) < 0) - return error; - - /* - * If the caller only wants the header, we just needed to make sure to - * call flush_file_header - */ - if (pi->format == GIT_DIFF_FORMAT_PATCH_HEADER) - return 0; - - pi->line.origin = GIT_DIFF_LINE_HUNK_HDR; - pi->line.content = h->header; - pi->line.content_len = h->header_len; - - return pi->print_cb(d, h, &pi->line, pi->payload); -} - -static int diff_print_patch_line( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - const git_diff_line *line, - void *data) -{ - diff_print_info *pi = data; - int error; - - if (S_ISDIR(delta->new_file.mode)) - return 0; - - if ((error = flush_file_header(delta, pi)) < 0) - return error; - - return pi->print_cb(delta, hunk, line, pi->payload); -} - -/* print a git_diff to an output callback */ -int git_diff_print( - git_diff *diff, - git_diff_format_t format, - git_diff_line_cb print_cb, - void *payload) -{ - int error; - git_str buf = GIT_STR_INIT; - diff_print_info pi; - git_diff_file_cb print_file = NULL; - git_diff_binary_cb print_binary = NULL; - git_diff_hunk_cb print_hunk = NULL; - git_diff_line_cb print_line = NULL; - - switch (format) { - case GIT_DIFF_FORMAT_PATCH: - print_file = diff_print_patch_file; - print_binary = diff_print_patch_binary; - print_hunk = diff_print_patch_hunk; - print_line = diff_print_patch_line; - break; - case GIT_DIFF_FORMAT_PATCH_ID: - print_file = diff_print_patch_file; - print_binary = diff_print_patch_binary; - print_line = diff_print_patch_line; - break; - case GIT_DIFF_FORMAT_PATCH_HEADER: - print_file = diff_print_patch_file; - print_binary = diff_print_patch_binary; - print_hunk = diff_print_patch_hunk; - break; - case GIT_DIFF_FORMAT_RAW: - print_file = diff_print_one_raw; - break; - case GIT_DIFF_FORMAT_NAME_ONLY: - print_file = diff_print_one_name_only; - break; - case GIT_DIFF_FORMAT_NAME_STATUS: - print_file = diff_print_one_name_status; - break; - default: - git_error_set(GIT_ERROR_INVALID, "unknown diff output format (%d)", format); - return -1; - } - - if ((error = diff_print_info_init_fromdiff(&pi, &buf, diff, format, print_cb, payload)) < 0) - goto out; - - if ((error = git_diff_foreach(diff, print_file, print_binary, print_hunk, print_line, &pi)) != 0) { - git_error_set_after_callback_function(error, "git_diff_print"); - goto out; - } - -out: - git_str_dispose(&buf); - return error; -} - -int git_diff_print_callback__to_buf( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - const git_diff_line *line, - void *payload) -{ - git_str *output = payload; - GIT_UNUSED(delta); GIT_UNUSED(hunk); - - if (!output) { - git_error_set(GIT_ERROR_INVALID, "buffer pointer must be provided"); - return -1; - } - - if (line->origin == GIT_DIFF_LINE_ADDITION || - line->origin == GIT_DIFF_LINE_DELETION || - line->origin == GIT_DIFF_LINE_CONTEXT) - git_str_putc(output, line->origin); - - return git_str_put(output, line->content, line->content_len); -} - -int git_diff_print_callback__to_file_handle( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - const git_diff_line *line, - void *payload) -{ - FILE *fp = payload ? payload : stdout; - int error; - - GIT_UNUSED(delta); - GIT_UNUSED(hunk); - - if (line->origin == GIT_DIFF_LINE_CONTEXT || - line->origin == GIT_DIFF_LINE_ADDITION || - line->origin == GIT_DIFF_LINE_DELETION) { - while ((error = fputc(line->origin, fp)) == EINTR) - continue; - if (error) { - git_error_set(GIT_ERROR_OS, "could not write status"); - return -1; - } - } - - if (fwrite(line->content, line->content_len, 1, fp) != 1) { - git_error_set(GIT_ERROR_OS, "could not write line"); - return -1; - } - - return 0; -} - -/* print a git_diff to a git_str */ -int git_diff_to_buf(git_buf *out, git_diff *diff, git_diff_format_t format) -{ - git_str str = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diff); - - if ((error = git_buf_tostr(&str, out)) < 0 || - (error = git_diff_print(diff, format, git_diff_print_callback__to_buf, &str)) < 0) - goto done; - - error = git_buf_fromstr(out, &str); - -done: - git_str_dispose(&str); - return error; -} - -/* print a git_patch to an output callback */ -int git_patch_print( - git_patch *patch, - git_diff_line_cb print_cb, - void *payload) -{ - git_str temp = GIT_STR_INIT; - diff_print_info pi; - int error; - - GIT_ASSERT_ARG(patch); - GIT_ASSERT_ARG(print_cb); - - if ((error = diff_print_info_init_frompatch(&pi, &temp, patch, - GIT_DIFF_FORMAT_PATCH, print_cb, payload)) < 0) - goto out; - - if ((error = git_patch__invoke_callbacks(patch, diff_print_patch_file, diff_print_patch_binary, - diff_print_patch_hunk, diff_print_patch_line, &pi)) < 0) { - git_error_set_after_callback_function(error, "git_patch_print"); - goto out; - } - -out: - git_str_dispose(&temp); - return error; -} - -/* print a git_patch to a git_str */ -int git_patch_to_buf(git_buf *out, git_patch *patch) -{ - GIT_BUF_WRAP_PRIVATE(out, git_patch__to_buf, patch); -} - -int git_patch__to_buf(git_str *out, git_patch *patch) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(patch); - - return git_patch_print(patch, git_diff_print_callback__to_buf, out); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_stats.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff_stats.c deleted file mode 100644 index b67aa48..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_stats.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "diff_stats.h" - -#include "buf.h" -#include "common.h" -#include "vector.h" -#include "diff.h" -#include "patch_generate.h" - -#define DIFF_RENAME_FILE_SEPARATOR " => " -#define STATS_FULL_MIN_SCALE 7 - -typedef struct { - size_t insertions; - size_t deletions; -} diff_file_stats; - -struct git_diff_stats { - git_diff *diff; - diff_file_stats *filestats; - - size_t files_changed; - size_t insertions; - size_t deletions; - - size_t max_name; - size_t max_filestat; - int max_digits; -}; - -static int digits_for_value(size_t val) -{ - int count = 1; - size_t placevalue = 10; - - while (val >= placevalue) { - ++count; - placevalue *= 10; - } - - return count; -} - -static int diff_file_stats_full_to_buf( - git_str *out, - const git_diff_delta *delta, - const diff_file_stats *filestat, - const git_diff_stats *stats, - size_t width) -{ - const char *old_path = NULL, *new_path = NULL, *adddel_path = NULL; - size_t padding; - git_object_size_t old_size, new_size; - - old_path = delta->old_file.path; - new_path = delta->new_file.path; - old_size = delta->old_file.size; - new_size = delta->new_file.size; - - if (old_path && new_path && strcmp(old_path, new_path) != 0) { - size_t common_dirlen; - int error; - - if ((common_dirlen = git_fs_path_common_dirlen(old_path, new_path)) && - common_dirlen <= INT_MAX) { - error = git_str_printf(out, " %.*s{%s"DIFF_RENAME_FILE_SEPARATOR"%s}", - (int) common_dirlen, old_path, - old_path + common_dirlen, - new_path + common_dirlen); - padding = stats->max_name + common_dirlen - strlen(old_path) - - strlen(new_path) - 2 - strlen(DIFF_RENAME_FILE_SEPARATOR); - } else { - error = git_str_printf(out, " %s" DIFF_RENAME_FILE_SEPARATOR "%s", - old_path, new_path); - padding = stats->max_name - strlen(old_path) - - strlen(new_path) - strlen(DIFF_RENAME_FILE_SEPARATOR); - } - - if (error < 0) - goto on_error; - } else { - adddel_path = new_path ? new_path : old_path; - if (git_str_printf(out, " %s", adddel_path) < 0) - goto on_error; - - padding = stats->max_name - strlen(adddel_path); - } - - if (git_str_putcn(out, ' ', padding) < 0 || - git_str_puts(out, " | ") < 0) - goto on_error; - - if (delta->flags & GIT_DIFF_FLAG_BINARY) { - if (git_str_printf(out, - "Bin %" PRId64 " -> %" PRId64 " bytes", old_size, new_size) < 0) - goto on_error; - } - else { - if (git_str_printf(out, - "%*" PRIuZ, stats->max_digits, - filestat->insertions + filestat->deletions) < 0) - goto on_error; - - if (filestat->insertions || filestat->deletions) { - if (git_str_putc(out, ' ') < 0) - goto on_error; - - if (!width) { - if (git_str_putcn(out, '+', filestat->insertions) < 0 || - git_str_putcn(out, '-', filestat->deletions) < 0) - goto on_error; - } else { - size_t total = filestat->insertions + filestat->deletions; - size_t full = (total * width + stats->max_filestat / 2) / - stats->max_filestat; - size_t plus = full * filestat->insertions / total; - size_t minus = full - plus; - - if (git_str_putcn(out, '+', max(plus, 1)) < 0 || - git_str_putcn(out, '-', max(minus, 1)) < 0) - goto on_error; - } - } - } - - git_str_putc(out, '\n'); - -on_error: - return (git_str_oom(out) ? -1 : 0); -} - -static int diff_file_stats_number_to_buf( - git_str *out, - const git_diff_delta *delta, - const diff_file_stats *filestats) -{ - int error; - const char *path = delta->new_file.path; - - if (delta->flags & GIT_DIFF_FLAG_BINARY) - error = git_str_printf(out, "%-8c" "%-8c" "%s\n", '-', '-', path); - else - error = git_str_printf(out, "%-8" PRIuZ "%-8" PRIuZ "%s\n", - filestats->insertions, filestats->deletions, path); - - return error; -} - -static int diff_file_stats_summary_to_buf( - git_str *out, - const git_diff_delta *delta) -{ - if (delta->old_file.mode != delta->new_file.mode) { - if (delta->old_file.mode == 0) { - git_str_printf(out, " create mode %06o %s\n", - delta->new_file.mode, delta->new_file.path); - } - else if (delta->new_file.mode == 0) { - git_str_printf(out, " delete mode %06o %s\n", - delta->old_file.mode, delta->old_file.path); - } - else { - git_str_printf(out, " mode change %06o => %06o %s\n", - delta->old_file.mode, delta->new_file.mode, delta->new_file.path); - } - } - - return 0; -} - -int git_diff_get_stats( - git_diff_stats **out, - git_diff *diff) -{ - size_t i, deltas; - size_t total_insertions = 0, total_deletions = 0; - git_diff_stats *stats = NULL; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diff); - - stats = git__calloc(1, sizeof(git_diff_stats)); - GIT_ERROR_CHECK_ALLOC(stats); - - deltas = git_diff_num_deltas(diff); - - stats->filestats = git__calloc(deltas, sizeof(diff_file_stats)); - if (!stats->filestats) { - git__free(stats); - return -1; - } - - stats->diff = diff; - GIT_REFCOUNT_INC(diff); - - for (i = 0; i < deltas && !error; ++i) { - git_patch *patch = NULL; - size_t add = 0, remove = 0, namelen; - const git_diff_delta *delta; - - if ((error = git_patch_from_diff(&patch, diff, i)) < 0) - break; - - /* Length calculation for renames mirrors the actual presentation format - * generated in diff_file_stats_full_to_buf; namelen is the full length of - * what will be printed, taking into account renames and common prefixes. - */ - delta = patch->delta; - namelen = strlen(delta->new_file.path); - if (delta->old_file.path && - strcmp(delta->old_file.path, delta->new_file.path) != 0) { - size_t common_dirlen; - if ((common_dirlen = git_fs_path_common_dirlen(delta->old_file.path, delta->new_file.path)) && - common_dirlen <= INT_MAX) { - namelen += strlen(delta->old_file.path) + 2 + - strlen(DIFF_RENAME_FILE_SEPARATOR) - common_dirlen; - } else { - namelen += strlen(delta->old_file.path) + - strlen(DIFF_RENAME_FILE_SEPARATOR); - } - } - - /* and, of course, count the line stats */ - error = git_patch_line_stats(NULL, &add, &remove, patch); - - git_patch_free(patch); - - stats->filestats[i].insertions = add; - stats->filestats[i].deletions = remove; - - total_insertions += add; - total_deletions += remove; - - if (stats->max_name < namelen) - stats->max_name = namelen; - if (stats->max_filestat < add + remove) - stats->max_filestat = add + remove; - } - - stats->files_changed = deltas; - stats->insertions = total_insertions; - stats->deletions = total_deletions; - stats->max_digits = digits_for_value(stats->max_filestat + 1); - - if (error < 0) { - git_diff_stats_free(stats); - stats = NULL; - } - - *out = stats; - return error; -} - -size_t git_diff_stats_files_changed( - const git_diff_stats *stats) -{ - GIT_ASSERT_ARG(stats); - - return stats->files_changed; -} - -size_t git_diff_stats_insertions( - const git_diff_stats *stats) -{ - GIT_ASSERT_ARG(stats); - - return stats->insertions; -} - -size_t git_diff_stats_deletions( - const git_diff_stats *stats) -{ - GIT_ASSERT_ARG(stats); - - return stats->deletions; -} - -int git_diff_stats_to_buf( - git_buf *out, - const git_diff_stats *stats, - git_diff_stats_format_t format, - size_t width) -{ - GIT_BUF_WRAP_PRIVATE(out, git_diff__stats_to_buf, stats, format, width); -} - -int git_diff__stats_to_buf( - git_str *out, - const git_diff_stats *stats, - git_diff_stats_format_t format, - size_t width) -{ - int error = 0; - size_t i; - const git_diff_delta *delta; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(stats); - - if (format & GIT_DIFF_STATS_NUMBER) { - for (i = 0; i < stats->files_changed; ++i) { - if ((delta = git_diff_get_delta(stats->diff, i)) == NULL) - continue; - - error = diff_file_stats_number_to_buf( - out, delta, &stats->filestats[i]); - if (error < 0) - return error; - } - } - - if (format & GIT_DIFF_STATS_FULL) { - if (width > 0) { - if (width > stats->max_name + stats->max_digits + 5) - width -= (stats->max_name + stats->max_digits + 5); - if (width < STATS_FULL_MIN_SCALE) - width = STATS_FULL_MIN_SCALE; - } - if (width > stats->max_filestat) - width = 0; - - for (i = 0; i < stats->files_changed; ++i) { - if ((delta = git_diff_get_delta(stats->diff, i)) == NULL) - continue; - - error = diff_file_stats_full_to_buf( - out, delta, &stats->filestats[i], stats, width); - if (error < 0) - return error; - } - } - - if (format & GIT_DIFF_STATS_FULL || format & GIT_DIFF_STATS_SHORT) { - git_str_printf( - out, " %" PRIuZ " file%s changed", - stats->files_changed, stats->files_changed != 1 ? "s" : ""); - - if (stats->insertions || stats->deletions == 0) - git_str_printf( - out, ", %" PRIuZ " insertion%s(+)", - stats->insertions, stats->insertions != 1 ? "s" : ""); - - if (stats->deletions || stats->insertions == 0) - git_str_printf( - out, ", %" PRIuZ " deletion%s(-)", - stats->deletions, stats->deletions != 1 ? "s" : ""); - - git_str_putc(out, '\n'); - - if (git_str_oom(out)) - return -1; - } - - if (format & GIT_DIFF_STATS_INCLUDE_SUMMARY) { - for (i = 0; i < stats->files_changed; ++i) { - if ((delta = git_diff_get_delta(stats->diff, i)) == NULL) - continue; - - error = diff_file_stats_summary_to_buf(out, delta); - if (error < 0) - return error; - } - } - - return error; -} - -void git_diff_stats_free(git_diff_stats *stats) -{ - if (stats == NULL) - return; - - git_diff_free(stats->diff); /* bumped refcount in constructor */ - git__free(stats->filestats); - git__free(stats); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_stats.h b/vendor/libgit2-sys/libgit2/src/libgit2/diff_stats.h deleted file mode 100644 index c71862b..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_stats.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_diff_stats_h__ -#define INCLUDE_diff_stats_h__ - -#include "common.h" - -int git_diff__stats_to_buf( - git_str *out, - const git_diff_stats *stats, - git_diff_stats_format_t format, - size_t width); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_tform.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff_tform.c deleted file mode 100644 index 33ed2d1..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_tform.c +++ /dev/null @@ -1,1153 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "diff_tform.h" - -#include "git2/config.h" -#include "git2/blob.h" -#include "git2/sys/hashsig.h" - -#include "diff.h" -#include "diff_generate.h" -#include "fs_path.h" -#include "futils.h" -#include "config.h" - -git_diff_delta *git_diff__delta_dup( - const git_diff_delta *d, git_pool *pool) -{ - git_diff_delta *delta = git__malloc(sizeof(git_diff_delta)); - if (!delta) - return NULL; - - memcpy(delta, d, sizeof(git_diff_delta)); - GIT_DIFF_FLAG__CLEAR_INTERNAL(delta->flags); - - if (d->old_file.path != NULL) { - delta->old_file.path = git_pool_strdup(pool, d->old_file.path); - if (delta->old_file.path == NULL) - goto fail; - } - - if (d->new_file.path != d->old_file.path && d->new_file.path != NULL) { - delta->new_file.path = git_pool_strdup(pool, d->new_file.path); - if (delta->new_file.path == NULL) - goto fail; - } else { - delta->new_file.path = delta->old_file.path; - } - - return delta; - -fail: - git__free(delta); - return NULL; -} - -git_diff_delta *git_diff__merge_like_cgit( - const git_diff_delta *a, - const git_diff_delta *b, - git_pool *pool) -{ - git_diff_delta *dup; - - /* Emulate C git for merging two diffs (a la 'git diff '). - * - * When C git does a diff between the work dir and a tree, it actually - * diffs with the index but uses the workdir contents. This emulates - * those choices so we can emulate the type of diff. - * - * We have three file descriptions here, let's call them: - * f1 = a->old_file - * f2 = a->new_file AND b->old_file - * f3 = b->new_file - */ - - /* If one of the diffs is a conflict, just dup it */ - if (b->status == GIT_DELTA_CONFLICTED) - return git_diff__delta_dup(b, pool); - if (a->status == GIT_DELTA_CONFLICTED) - return git_diff__delta_dup(a, pool); - - /* if f2 == f3 or f2 is deleted, then just dup the 'a' diff */ - if (b->status == GIT_DELTA_UNMODIFIED || a->status == GIT_DELTA_DELETED) - return git_diff__delta_dup(a, pool); - - /* otherwise, base this diff on the 'b' diff */ - if ((dup = git_diff__delta_dup(b, pool)) == NULL) - return NULL; - - /* If 'a' status is uninteresting, then we're done */ - if (a->status == GIT_DELTA_UNMODIFIED || - a->status == GIT_DELTA_UNTRACKED || - a->status == GIT_DELTA_UNREADABLE) - return dup; - - GIT_ASSERT_WITH_RETVAL(b->status != GIT_DELTA_UNMODIFIED, NULL); - - /* A cgit exception is that the diff of a file that is only in the - * index (i.e. not in HEAD nor workdir) is given as empty. - */ - if (dup->status == GIT_DELTA_DELETED) { - if (a->status == GIT_DELTA_ADDED) { - dup->status = GIT_DELTA_UNMODIFIED; - dup->nfiles = 2; - } - /* else don't overwrite DELETE status */ - } else { - dup->status = a->status; - dup->nfiles = a->nfiles; - } - - git_oid_cpy(&dup->old_file.id, &a->old_file.id); - dup->old_file.mode = a->old_file.mode; - dup->old_file.size = a->old_file.size; - dup->old_file.flags = a->old_file.flags; - - return dup; -} - -int git_diff__merge( - git_diff *onto, const git_diff *from, git_diff__merge_cb cb) -{ - int error = 0; - git_pool onto_pool; - git_vector onto_new; - git_diff_delta *delta; - bool ignore_case, reversed; - unsigned int i, j; - - GIT_ASSERT_ARG(onto); - GIT_ASSERT_ARG(from); - - if (!from->deltas.length) - return 0; - - ignore_case = ((onto->opts.flags & GIT_DIFF_IGNORE_CASE) != 0); - reversed = ((onto->opts.flags & GIT_DIFF_REVERSE) != 0); - - if (ignore_case != ((from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0) || - reversed != ((from->opts.flags & GIT_DIFF_REVERSE) != 0)) { - git_error_set(GIT_ERROR_INVALID, - "attempt to merge diffs created with conflicting options"); - return -1; - } - - if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0 || - git_pool_init(&onto_pool, 1) < 0) - return -1; - - for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) { - git_diff_delta *o = GIT_VECTOR_GET(&onto->deltas, i); - const git_diff_delta *f = GIT_VECTOR_GET(&from->deltas, j); - int cmp = !f ? -1 : !o ? 1 : - STRCMP_CASESELECT(ignore_case, o->old_file.path, f->old_file.path); - - if (cmp < 0) { - delta = git_diff__delta_dup(o, &onto_pool); - i++; - } else if (cmp > 0) { - delta = git_diff__delta_dup(f, &onto_pool); - j++; - } else { - const git_diff_delta *left = reversed ? f : o; - const git_diff_delta *right = reversed ? o : f; - - delta = cb(left, right, &onto_pool); - i++; - j++; - } - - /* the ignore rules for the target may not match the source - * or the result of a merged delta could be skippable... - */ - if (delta && git_diff_delta__should_skip(&onto->opts, delta)) { - git__free(delta); - continue; - } - - if ((error = !delta ? -1 : git_vector_insert(&onto_new, delta)) < 0) - break; - } - - if (!error) { - git_vector_swap(&onto->deltas, &onto_new); - git_pool_swap(&onto->pool, &onto_pool); - - if ((onto->opts.flags & GIT_DIFF_REVERSE) != 0) - onto->old_src = from->old_src; - else - onto->new_src = from->new_src; - - /* prefix strings also come from old pool, so recreate those.*/ - onto->opts.old_prefix = - git_pool_strdup_safe(&onto->pool, onto->opts.old_prefix); - onto->opts.new_prefix = - git_pool_strdup_safe(&onto->pool, onto->opts.new_prefix); - } - - git_vector_dispose_deep(&onto_new); - git_pool_clear(&onto_pool); - - return error; -} - -int git_diff_merge(git_diff *onto, const git_diff *from) -{ - return git_diff__merge(onto, from, git_diff__merge_like_cgit); -} - -int git_diff_find_similar__hashsig_for_file( - void **out, const git_diff_file *f, const char *path, void *p) -{ - git_hashsig_option_t opt = (git_hashsig_option_t)(intptr_t)p; - - GIT_UNUSED(f); - return git_hashsig_create_fromfile((git_hashsig **)out, path, opt); -} - -int git_diff_find_similar__hashsig_for_buf( - void **out, const git_diff_file *f, const char *buf, size_t len, void *p) -{ - git_hashsig_option_t opt = (git_hashsig_option_t)(intptr_t)p; - - GIT_UNUSED(f); - return git_hashsig_create((git_hashsig **)out, buf, len, opt); -} - -void git_diff_find_similar__hashsig_free(void *sig, void *payload) -{ - GIT_UNUSED(payload); - git_hashsig_free(sig); -} - -int git_diff_find_similar__calc_similarity( - int *score, void *siga, void *sigb, void *payload) -{ - int error; - - GIT_UNUSED(payload); - error = git_hashsig_compare(siga, sigb); - if (error < 0) - return error; - - *score = error; - return 0; -} - -#define DEFAULT_THRESHOLD 50 -#define DEFAULT_BREAK_REWRITE_THRESHOLD 60 -#define DEFAULT_RENAME_LIMIT 1000 - -static int normalize_find_opts( - git_diff *diff, - git_diff_find_options *opts, - const git_diff_find_options *given) -{ - git_config *cfg = NULL; - git_hashsig_option_t hashsig_opts; - - GIT_ERROR_CHECK_VERSION(given, GIT_DIFF_FIND_OPTIONS_VERSION, "git_diff_find_options"); - - if (diff->repo != NULL && - git_repository_config__weakptr(&cfg, diff->repo) < 0) - return -1; - - if (given) - memcpy(opts, given, sizeof(*opts)); - - if (!given || - (given->flags & GIT_DIFF_FIND_ALL) == GIT_DIFF_FIND_BY_CONFIG) - { - if (cfg) { - char *rule = - git_config__get_string_force(cfg, "diff.renames", "true"); - int boolval; - - if (!git__parse_bool(&boolval, rule) && !boolval) - /* don't set FIND_RENAMES if bool value is false */; - else if (!strcasecmp(rule, "copies") || !strcasecmp(rule, "copy")) - opts->flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES; - else - opts->flags |= GIT_DIFF_FIND_RENAMES; - - git__free(rule); - } else { - /* set default flag */ - opts->flags |= GIT_DIFF_FIND_RENAMES; - } - } - - /* some flags imply others */ - - if (opts->flags & GIT_DIFF_FIND_EXACT_MATCH_ONLY) { - /* if we are only looking for exact matches, then don't turn - * MODIFIED items into ADD/DELETE pairs because it's too picky - */ - opts->flags &= ~(GIT_DIFF_FIND_REWRITES | GIT_DIFF_BREAK_REWRITES); - - /* similarly, don't look for self-rewrites to split */ - opts->flags &= ~GIT_DIFF_FIND_RENAMES_FROM_REWRITES; - } - - if (opts->flags & GIT_DIFF_FIND_RENAMES_FROM_REWRITES) - opts->flags |= GIT_DIFF_FIND_RENAMES; - - if (opts->flags & GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED) - opts->flags |= GIT_DIFF_FIND_COPIES; - - if (opts->flags & GIT_DIFF_BREAK_REWRITES) - opts->flags |= GIT_DIFF_FIND_REWRITES; - -#define USE_DEFAULT(X) ((X) == 0 || (X) > 100) - - if (USE_DEFAULT(opts->rename_threshold)) - opts->rename_threshold = DEFAULT_THRESHOLD; - - if (USE_DEFAULT(opts->rename_from_rewrite_threshold)) - opts->rename_from_rewrite_threshold = DEFAULT_THRESHOLD; - - if (USE_DEFAULT(opts->copy_threshold)) - opts->copy_threshold = DEFAULT_THRESHOLD; - - if (USE_DEFAULT(opts->break_rewrite_threshold)) - opts->break_rewrite_threshold = DEFAULT_BREAK_REWRITE_THRESHOLD; - -#undef USE_DEFAULT - - if (!opts->rename_limit) { - if (cfg) { - opts->rename_limit = git_config__get_int_force( - cfg, "diff.renamelimit", DEFAULT_RENAME_LIMIT); - } - - if (opts->rename_limit <= 0) - opts->rename_limit = DEFAULT_RENAME_LIMIT; - } - - /* assign the internal metric with whitespace flag as payload */ - if (!opts->metric) { - opts->metric = git__malloc(sizeof(git_diff_similarity_metric)); - GIT_ERROR_CHECK_ALLOC(opts->metric); - - opts->metric->file_signature = git_diff_find_similar__hashsig_for_file; - opts->metric->buffer_signature = git_diff_find_similar__hashsig_for_buf; - opts->metric->free_signature = git_diff_find_similar__hashsig_free; - opts->metric->similarity = git_diff_find_similar__calc_similarity; - - if (opts->flags & GIT_DIFF_FIND_IGNORE_WHITESPACE) - hashsig_opts = GIT_HASHSIG_IGNORE_WHITESPACE; - else if (opts->flags & GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE) - hashsig_opts = GIT_HASHSIG_NORMAL; - else - hashsig_opts = GIT_HASHSIG_SMART_WHITESPACE; - hashsig_opts |= GIT_HASHSIG_ALLOW_SMALL_FILES; - opts->metric->payload = (void *)hashsig_opts; - } - - return 0; -} - -static int insert_delete_side_of_split( - git_diff *diff, git_vector *onto, const git_diff_delta *delta) -{ - /* make new record for DELETED side of split */ - git_diff_delta *deleted = git_diff__delta_dup(delta, &diff->pool); - GIT_ERROR_CHECK_ALLOC(deleted); - - deleted->status = GIT_DELTA_DELETED; - deleted->nfiles = 1; - memset(&deleted->new_file, 0, sizeof(deleted->new_file)); - deleted->new_file.path = deleted->old_file.path; - deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; - git_oid_clear(&deleted->new_file.id, diff->opts.oid_type); - - return git_vector_insert(onto, deleted); -} - -static int apply_splits_and_deletes( - git_diff *diff, size_t expected_size, bool actually_split) -{ - git_vector onto = GIT_VECTOR_INIT; - size_t i; - git_diff_delta *delta; - - if (git_vector_init(&onto, expected_size, diff->deltas._cmp) < 0) - return -1; - - /* build new delta list without TO_DELETE and splitting TO_SPLIT */ - git_vector_foreach(&diff->deltas, i, delta) { - if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0) - continue; - - if ((delta->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0 && actually_split) { - delta->similarity = 0; - - if (insert_delete_side_of_split(diff, &onto, delta) < 0) - goto on_error; - - if (diff->new_src == GIT_ITERATOR_WORKDIR) - delta->status = GIT_DELTA_UNTRACKED; - else - delta->status = GIT_DELTA_ADDED; - delta->nfiles = 1; - memset(&delta->old_file, 0, sizeof(delta->old_file)); - delta->old_file.path = delta->new_file.path; - delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; - git_oid_clear(&delta->old_file.id, diff->opts.oid_type); - } - - /* clean up delta before inserting into new list */ - GIT_DIFF_FLAG__CLEAR_INTERNAL(delta->flags); - - if (delta->status != GIT_DELTA_COPIED && - delta->status != GIT_DELTA_RENAMED && - (delta->status != GIT_DELTA_MODIFIED || actually_split)) - delta->similarity = 0; - - /* insert into new list */ - if (git_vector_insert(&onto, delta) < 0) - goto on_error; - } - - /* cannot return an error past this point */ - - /* free deltas from old list that didn't make it to the new one */ - git_vector_foreach(&diff->deltas, i, delta) { - if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0) - git__free(delta); - } - - /* swap new delta list into place */ - git_vector_swap(&diff->deltas, &onto); - git_vector_dispose(&onto); - git_vector_sort(&diff->deltas); - - return 0; - -on_error: - git_vector_dispose_deep(&onto); - - return -1; -} - -GIT_INLINE(git_diff_file *) similarity_get_file(git_diff *diff, size_t idx) -{ - git_diff_delta *delta = git_vector_get(&diff->deltas, idx / 2); - return (idx & 1) ? &delta->new_file : &delta->old_file; -} - -typedef struct { - size_t idx; - git_iterator_t src; - git_repository *repo; - git_diff_file *file; - git_str data; - git_odb_object *odb_obj; - git_blob *blob; -} similarity_info; - -static int similarity_init( - similarity_info *info, git_diff *diff, size_t file_idx) -{ - info->idx = file_idx; - info->src = (file_idx & 1) ? diff->new_src : diff->old_src; - info->repo = diff->repo; - info->file = similarity_get_file(diff, file_idx); - info->odb_obj = NULL; - info->blob = NULL; - git_str_init(&info->data, 0); - - if ((info->file->flags & GIT_DIFF_FLAG_VALID_SIZE) || - info->src == GIT_ITERATOR_WORKDIR) - return 0; - - return git_diff_file__resolve_zero_size( - info->file, &info->odb_obj, info->repo); -} - -static int similarity_sig( - similarity_info *info, - const git_diff_find_options *opts, - void **cache) -{ - int error = 0; - git_diff_file *file = info->file; - - if (info->src == GIT_ITERATOR_WORKDIR) { - if ((error = git_repository_workdir_path( - &info->data, info->repo, file->path)) < 0) - return error; - - /* if path is not a regular file, just skip this item */ - if (!git_fs_path_isfile(info->data.ptr)) - return 0; - - /* TODO: apply wd-to-odb filters to file data if necessary */ - - error = opts->metric->file_signature( - &cache[info->idx], info->file, - info->data.ptr, opts->metric->payload); - } else { - /* if we didn't initially know the size, we might have an odb_obj - * around from earlier, so convert that, otherwise load the blob now - */ - if (info->odb_obj != NULL) - error = git_object__from_odb_object( - (git_object **)&info->blob, info->repo, - info->odb_obj, GIT_OBJECT_BLOB); - else - error = git_blob_lookup(&info->blob, info->repo, &file->id); - - if (error < 0) { - /* if lookup fails, just skip this item in similarity calc */ - git_error_clear(); - } else { - size_t sz; - - /* index size may not be actual blob size if filtered */ - if (file->size != git_blob_rawsize(info->blob)) - file->size = git_blob_rawsize(info->blob); - - sz = git__is_sizet(file->size) ? (size_t)file->size : (size_t)-1; - - error = opts->metric->buffer_signature( - &cache[info->idx], info->file, - git_blob_rawcontent(info->blob), sz, opts->metric->payload); - } - } - - return error; -} - -static void similarity_unload(similarity_info *info) -{ - if (info->odb_obj) - git_odb_object_free(info->odb_obj); - - if (info->blob) - git_blob_free(info->blob); - else - git_str_dispose(&info->data); -} - -#define FLAG_SET(opts,flag_name) (((opts)->flags & flag_name) != 0) - -/* - score < 0 means files cannot be compared - * - score >= 100 means files are exact match - * - score == 0 means files are completely different - */ -static int similarity_measure( - int *score, - git_diff *diff, - const git_diff_find_options *opts, - void **cache, - size_t a_idx, - size_t b_idx) -{ - git_diff_file *a_file = similarity_get_file(diff, a_idx); - git_diff_file *b_file = similarity_get_file(diff, b_idx); - bool exact_match = FLAG_SET(opts, GIT_DIFF_FIND_EXACT_MATCH_ONLY); - int error = 0; - similarity_info a_info, b_info; - - *score = -1; - - /* don't try to compare things that aren't files */ - if (!GIT_MODE_ISBLOB(a_file->mode) || !GIT_MODE_ISBLOB(b_file->mode)) - return 0; - - /* if exact match is requested, force calculation of missing OIDs now */ - if (exact_match) { - if (git_oid_is_zero(&a_file->id) && - diff->old_src == GIT_ITERATOR_WORKDIR && - !git_diff__oid_for_file(&a_file->id, - diff, a_file->path, a_file->mode, a_file->size)) - a_file->flags |= GIT_DIFF_FLAG_VALID_ID; - - if (git_oid_is_zero(&b_file->id) && - diff->new_src == GIT_ITERATOR_WORKDIR && - !git_diff__oid_for_file(&b_file->id, - diff, b_file->path, b_file->mode, b_file->size)) - b_file->flags |= GIT_DIFF_FLAG_VALID_ID; - } - - /* check OID match as a quick test */ - if (git_oid__cmp(&a_file->id, &b_file->id) == 0) { - *score = 100; - return 0; - } - - /* don't calculate signatures if we are doing exact match */ - if (exact_match) { - *score = 0; - return 0; - } - - memset(&a_info, 0, sizeof(a_info)); - memset(&b_info, 0, sizeof(b_info)); - - /* set up similarity data (will try to update missing file sizes) */ - if (!cache[a_idx] && (error = similarity_init(&a_info, diff, a_idx)) < 0) - return error; - if (!cache[b_idx] && (error = similarity_init(&b_info, diff, b_idx)) < 0) - goto cleanup; - - /* check if file sizes are nowhere near each other */ - if (a_file->size > 127 && - b_file->size > 127 && - (a_file->size > (b_file->size << 3) || - b_file->size > (a_file->size << 3))) - goto cleanup; - - /* update signature cache if needed */ - if (!cache[a_idx]) { - if ((error = similarity_sig(&a_info, opts, cache)) < 0) - goto cleanup; - } - if (!cache[b_idx]) { - if ((error = similarity_sig(&b_info, opts, cache)) < 0) - goto cleanup; - } - - /* calculate similarity provided that the metric choose to process - * both the a and b files (some may not if file is too big, etc). - */ - if (cache[a_idx] && cache[b_idx]) - error = opts->metric->similarity( - score, cache[a_idx], cache[b_idx], opts->metric->payload); - -cleanup: - similarity_unload(&a_info); - similarity_unload(&b_info); - - return error; -} - -static int calc_self_similarity( - git_diff *diff, - const git_diff_find_options *opts, - size_t delta_idx, - void **cache) -{ - int error, similarity = -1; - git_diff_delta *delta = GIT_VECTOR_GET(&diff->deltas, delta_idx); - - if ((delta->flags & GIT_DIFF_FLAG__HAS_SELF_SIMILARITY) != 0) - return 0; - - error = similarity_measure( - &similarity, diff, opts, cache, 2 * delta_idx, 2 * delta_idx + 1); - if (error < 0) - return error; - - if (similarity >= 0) { - delta->similarity = (uint16_t)similarity; - delta->flags |= GIT_DIFF_FLAG__HAS_SELF_SIMILARITY; - } - - return 0; -} - -static void handle_non_blob( - git_diff *diff, - const git_diff_find_options *opts, - size_t delta_idx) -{ - git_diff_delta *delta = GIT_VECTOR_GET(&diff->deltas, delta_idx); - - /* skip things that are blobs */ - if (GIT_MODE_ISBLOB(delta->old_file.mode)) - return; - - /* honor "remove unmodified" flag for non-blobs (eg submodules) */ - if (delta->status == GIT_DELTA_UNMODIFIED && - FLAG_SET(opts, GIT_DIFF_FIND_REMOVE_UNMODIFIED)) - delta->flags |= GIT_DIFF_FLAG__TO_DELETE; -} - -static bool is_rename_target( - git_diff *diff, - const git_diff_find_options *opts, - size_t delta_idx, - void **cache) -{ - git_diff_delta *delta = GIT_VECTOR_GET(&diff->deltas, delta_idx); - - /* skip things that aren't plain blobs */ - if (!GIT_MODE_ISBLOB(delta->new_file.mode)) - return false; - - /* only consider ADDED, RENAMED, COPIED, and split MODIFIED as - * targets; maybe include UNTRACKED if requested. - */ - switch (delta->status) { - case GIT_DELTA_UNMODIFIED: - case GIT_DELTA_DELETED: - case GIT_DELTA_IGNORED: - case GIT_DELTA_CONFLICTED: - return false; - - case GIT_DELTA_MODIFIED: - if (!FLAG_SET(opts, GIT_DIFF_FIND_REWRITES) && - !FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES)) - return false; - - if (calc_self_similarity(diff, opts, delta_idx, cache) < 0) - return false; - - if (FLAG_SET(opts, GIT_DIFF_BREAK_REWRITES) && - delta->similarity < opts->break_rewrite_threshold) { - delta->flags |= GIT_DIFF_FLAG__TO_SPLIT; - break; - } - if (FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES) && - delta->similarity < opts->rename_from_rewrite_threshold) { - delta->flags |= GIT_DIFF_FLAG__TO_SPLIT; - break; - } - - return false; - - case GIT_DELTA_UNTRACKED: - if (!FLAG_SET(opts, GIT_DIFF_FIND_FOR_UNTRACKED)) - return false; - break; - - default: /* all other status values should be checked */ - break; - } - - delta->flags |= GIT_DIFF_FLAG__IS_RENAME_TARGET; - return true; -} - -static bool is_rename_source( - git_diff *diff, - const git_diff_find_options *opts, - size_t delta_idx, - void **cache) -{ - git_diff_delta *delta = GIT_VECTOR_GET(&diff->deltas, delta_idx); - - /* skip things that aren't blobs */ - if (!GIT_MODE_ISBLOB(delta->old_file.mode)) - return false; - - switch (delta->status) { - case GIT_DELTA_ADDED: - case GIT_DELTA_UNTRACKED: - case GIT_DELTA_UNREADABLE: - case GIT_DELTA_IGNORED: - case GIT_DELTA_CONFLICTED: - return false; - - case GIT_DELTA_DELETED: - case GIT_DELTA_TYPECHANGE: - break; - - case GIT_DELTA_UNMODIFIED: - if (!FLAG_SET(opts, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED)) - return false; - if (FLAG_SET(opts, GIT_DIFF_FIND_REMOVE_UNMODIFIED)) - delta->flags |= GIT_DIFF_FLAG__TO_DELETE; - break; - - default: /* MODIFIED, RENAMED, COPIED */ - /* if we're finding copies, this could be a source */ - if (FLAG_SET(opts, GIT_DIFF_FIND_COPIES)) - break; - - /* otherwise, this is only a source if we can split it */ - if (!FLAG_SET(opts, GIT_DIFF_FIND_REWRITES) && - !FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES)) - return false; - - if (calc_self_similarity(diff, opts, delta_idx, cache) < 0) - return false; - - if (FLAG_SET(opts, GIT_DIFF_BREAK_REWRITES) && - delta->similarity < opts->break_rewrite_threshold) { - delta->flags |= GIT_DIFF_FLAG__TO_SPLIT; - break; - } - - if (FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES) && - delta->similarity < opts->rename_from_rewrite_threshold) - break; - - return false; - } - - delta->flags |= GIT_DIFF_FLAG__IS_RENAME_SOURCE; - return true; -} - -GIT_INLINE(bool) delta_is_split(git_diff_delta *delta) -{ - return (delta->status == GIT_DELTA_TYPECHANGE || - (delta->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0); -} - -GIT_INLINE(bool) delta_is_new_only(git_diff_delta *delta) -{ - return (delta->status == GIT_DELTA_ADDED || - delta->status == GIT_DELTA_UNTRACKED || - delta->status == GIT_DELTA_UNREADABLE || - delta->status == GIT_DELTA_IGNORED); -} - -GIT_INLINE(void) delta_make_rename( - git_diff_delta *to, const git_diff_delta *from, uint16_t similarity) -{ - to->status = GIT_DELTA_RENAMED; - to->similarity = similarity; - to->nfiles = 2; - memcpy(&to->old_file, &from->old_file, sizeof(to->old_file)); - to->flags &= ~GIT_DIFF_FLAG__TO_SPLIT; -} - -typedef struct { - size_t idx; - uint16_t similarity; -} diff_find_match; - -int git_diff_find_similar( - git_diff *diff, - const git_diff_find_options *given_opts) -{ - size_t s, t; - int error = 0, result; - uint16_t similarity; - git_diff_delta *src, *tgt; - git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT; - size_t num_deltas, num_srcs = 0, num_tgts = 0; - size_t tried_srcs = 0, tried_tgts = 0; - size_t num_rewrites = 0, num_updates = 0, num_bumped = 0, - num_to_delete = 0; - size_t sigcache_size; - void **sigcache = NULL; /* cache of similarity metric file signatures */ - diff_find_match *tgt2src = NULL; - diff_find_match *src2tgt = NULL; - diff_find_match *tgt2src_copy = NULL; - diff_find_match *best_match; - git_diff_file swap; - - GIT_ASSERT_ARG(diff); - - if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0) - return error; - - num_deltas = diff->deltas.length; - - /* TODO: maybe abort if deltas.length > rename_limit ??? */ - if (!num_deltas || !git__is_uint32(num_deltas)) - goto cleanup; - - /* No flags set; nothing to do */ - if ((opts.flags & GIT_DIFF_FIND_ALL) == 0) - goto cleanup; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&sigcache_size, num_deltas, 2); - sigcache = git__calloc(sigcache_size, sizeof(void *)); - GIT_ERROR_CHECK_ALLOC(sigcache); - - /* Label rename sources and targets - * - * This will also set self-similarity scores for MODIFIED files and - * mark them for splitting if break-rewrites is enabled - */ - git_vector_foreach(&diff->deltas, t, tgt) { - handle_non_blob(diff, &opts, t); - - if (is_rename_source(diff, &opts, t, sigcache)) - ++num_srcs; - - if (is_rename_target(diff, &opts, t, sigcache)) - ++num_tgts; - - if ((tgt->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0) - num_rewrites++; - - if ((tgt->flags & GIT_DIFF_FLAG__TO_DELETE) != 0) - num_to_delete++; - } - - /* If there are no candidate srcs or tgts, no need to find matches */ - if (!num_srcs || !num_tgts) - goto split_and_delete; - - src2tgt = git__calloc(num_deltas, sizeof(diff_find_match)); - GIT_ERROR_CHECK_ALLOC(src2tgt); - tgt2src = git__calloc(num_deltas, sizeof(diff_find_match)); - GIT_ERROR_CHECK_ALLOC(tgt2src); - - if (FLAG_SET(&opts, GIT_DIFF_FIND_COPIES)) { - tgt2src_copy = git__calloc(num_deltas, sizeof(diff_find_match)); - GIT_ERROR_CHECK_ALLOC(tgt2src_copy); - } - - /* - * Find best-fit matches for rename / copy candidates - */ - -find_best_matches: - tried_tgts = num_bumped = 0; - - git_vector_foreach(&diff->deltas, t, tgt) { - /* skip things that are not rename targets */ - if ((tgt->flags & GIT_DIFF_FLAG__IS_RENAME_TARGET) == 0) - continue; - - tried_srcs = 0; - - git_vector_foreach(&diff->deltas, s, src) { - /* skip things that are not rename sources */ - if ((src->flags & GIT_DIFF_FLAG__IS_RENAME_SOURCE) == 0) - continue; - - /* calculate similarity for this pair and find best match */ - if (s == t) - result = -1; /* don't measure self-similarity here */ - else if ((error = similarity_measure( - &result, diff, &opts, sigcache, 2 * s, 2 * t + 1)) < 0) - goto cleanup; - - if (result < 0) - continue; - similarity = (uint16_t)result; - - /* is this a better rename? */ - if (tgt2src[t].similarity < similarity && - src2tgt[s].similarity < similarity) - { - /* eject old mapping */ - if (src2tgt[s].similarity > 0) { - tgt2src[src2tgt[s].idx].similarity = 0; - num_bumped++; - } - if (tgt2src[t].similarity > 0) { - src2tgt[tgt2src[t].idx].similarity = 0; - num_bumped++; - } - - /* write new mapping */ - tgt2src[t].idx = s; - tgt2src[t].similarity = similarity; - src2tgt[s].idx = t; - src2tgt[s].similarity = similarity; - } - - /* keep best absolute match for copies */ - if (tgt2src_copy != NULL && - tgt2src_copy[t].similarity < similarity) - { - tgt2src_copy[t].idx = s; - tgt2src_copy[t].similarity = similarity; - } - - if (++tried_srcs >= num_srcs) - break; - - /* cap on maximum targets we'll examine (per "tgt" file) */ - if (tried_srcs > opts.rename_limit) - break; - } - - if (++tried_tgts >= num_tgts) - break; - } - - if (num_bumped > 0) /* try again if we bumped some items */ - goto find_best_matches; - - /* - * Rewrite the diffs with renames / copies - */ - - git_vector_foreach(&diff->deltas, t, tgt) { - /* skip things that are not rename targets */ - if ((tgt->flags & GIT_DIFF_FLAG__IS_RENAME_TARGET) == 0) - continue; - - /* check if this delta was the target of a similarity */ - if (tgt2src[t].similarity) - best_match = &tgt2src[t]; - else if (tgt2src_copy && tgt2src_copy[t].similarity) - best_match = &tgt2src_copy[t]; - else - continue; - - s = best_match->idx; - src = GIT_VECTOR_GET(&diff->deltas, s); - - /* possible scenarios: - * 1. from DELETE to ADD/UNTRACK/IGNORE = RENAME - * 2. from DELETE to SPLIT/TYPECHANGE = RENAME + DELETE - * 3. from SPLIT/TYPECHANGE to ADD/UNTRACK/IGNORE = ADD + RENAME - * 4. from SPLIT/TYPECHANGE to SPLIT/TYPECHANGE = RENAME + SPLIT - * 5. from OTHER to ADD/UNTRACK/IGNORE = OTHER + COPY - */ - - if (src->status == GIT_DELTA_DELETED) { - - if (delta_is_new_only(tgt)) { - - if (best_match->similarity < opts.rename_threshold) - continue; - - delta_make_rename(tgt, src, best_match->similarity); - - src->flags |= GIT_DIFF_FLAG__TO_DELETE; - num_rewrites++; - } else { - GIT_ASSERT(delta_is_split(tgt)); - - if (best_match->similarity < opts.rename_from_rewrite_threshold) - continue; - - memcpy(&swap, &tgt->old_file, sizeof(swap)); - - delta_make_rename(tgt, src, best_match->similarity); - num_rewrites--; - - GIT_ASSERT(src->status == GIT_DELTA_DELETED); - memcpy(&src->old_file, &swap, sizeof(src->old_file)); - memset(&src->new_file, 0, sizeof(src->new_file)); - src->new_file.path = src->old_file.path; - src->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; - git_oid_clear(&src->new_file.id, diff->opts.oid_type); - - num_updates++; - - if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) { - /* what used to be at src t is now at src s */ - tgt2src[src2tgt[t].idx].idx = s; - } - } - } - - else if (delta_is_split(src)) { - - if (delta_is_new_only(tgt)) { - - if (best_match->similarity < opts.rename_threshold) - continue; - - delta_make_rename(tgt, src, best_match->similarity); - - src->status = (diff->new_src == GIT_ITERATOR_WORKDIR) ? - GIT_DELTA_UNTRACKED : GIT_DELTA_ADDED; - src->nfiles = 1; - memset(&src->old_file, 0, sizeof(src->old_file)); - src->old_file.path = src->new_file.path; - src->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; - git_oid_clear(&src->old_file.id, diff->opts.oid_type); - - src->flags &= ~GIT_DIFF_FLAG__TO_SPLIT; - num_rewrites--; - - num_updates++; - } else { - GIT_ASSERT(delta_is_split(src)); - - if (best_match->similarity < opts.rename_from_rewrite_threshold) - continue; - - memcpy(&swap, &tgt->old_file, sizeof(swap)); - - delta_make_rename(tgt, src, best_match->similarity); - num_rewrites--; - num_updates++; - - memcpy(&src->old_file, &swap, sizeof(src->old_file)); - - /* if we've just swapped the new element into the correct - * place, clear the SPLIT and RENAME_TARGET flags - */ - if (tgt2src[s].idx == t && - tgt2src[s].similarity > - opts.rename_from_rewrite_threshold) { - src->status = GIT_DELTA_RENAMED; - src->similarity = tgt2src[s].similarity; - tgt2src[s].similarity = 0; - src->flags &= ~(GIT_DIFF_FLAG__TO_SPLIT | GIT_DIFF_FLAG__IS_RENAME_TARGET); - num_rewrites--; - } - /* otherwise, if we just overwrote a source, update mapping */ - else if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) { - /* what used to be at src t is now at src s */ - tgt2src[src2tgt[t].idx].idx = s; - } - - num_updates++; - } - } - - else if (FLAG_SET(&opts, GIT_DIFF_FIND_COPIES)) { - if (tgt2src_copy[t].similarity < opts.copy_threshold) - continue; - - /* always use best possible source for copy */ - best_match = &tgt2src_copy[t]; - src = GIT_VECTOR_GET(&diff->deltas, best_match->idx); - - if (delta_is_split(tgt)) { - error = insert_delete_side_of_split(diff, &diff->deltas, tgt); - if (error < 0) - goto cleanup; - num_rewrites--; - } - - if (!delta_is_split(tgt) && !delta_is_new_only(tgt)) - continue; - - tgt->status = GIT_DELTA_COPIED; - tgt->similarity = best_match->similarity; - tgt->nfiles = 2; - memcpy(&tgt->old_file, &src->old_file, sizeof(tgt->old_file)); - tgt->flags &= ~GIT_DIFF_FLAG__TO_SPLIT; - - num_updates++; - } - } - -split_and_delete: - /* - * Actually split and delete entries as needed - */ - - if (num_rewrites > 0 || num_updates > 0 || num_to_delete > 0) { - size_t apply_len = diff->deltas.length - - num_rewrites - num_to_delete; - - error = apply_splits_and_deletes( - diff, apply_len, - FLAG_SET(&opts, GIT_DIFF_BREAK_REWRITES) && - !FLAG_SET(&opts, GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY)); - } - -cleanup: - git__free(tgt2src); - git__free(src2tgt); - git__free(tgt2src_copy); - - if (sigcache) { - for (t = 0; t < num_deltas * 2; ++t) { - if (sigcache[t] != NULL) - opts.metric->free_signature(sigcache[t], opts.metric->payload); - } - git__free(sigcache); - } - - if (!given_opts || !given_opts->metric) - git__free(opts.metric); - - return error; -} - -#undef FLAG_SET diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_tform.h b/vendor/libgit2-sys/libgit2/src/libgit2/diff_tform.h deleted file mode 100644 index 7abb8b3..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_tform.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_diff_tform_h__ -#define INCLUDE_diff_tform_h__ - -#include "common.h" - -#include "diff_file.h" - -extern int git_diff_find_similar__hashsig_for_file( - void **out, const git_diff_file *f, const char *path, void *p); - -extern int git_diff_find_similar__hashsig_for_buf( - void **out, const git_diff_file *f, const char *buf, size_t len, void *p); - -extern void git_diff_find_similar__hashsig_free(void *sig, void *payload); - -extern int git_diff_find_similar__calc_similarity( - int *score, void *siga, void *sigb, void *payload); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_xdiff.c b/vendor/libgit2-sys/libgit2/src/libgit2/diff_xdiff.c deleted file mode 100644 index 5f56c52..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_xdiff.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "diff_xdiff.h" - -#include "git2/errors.h" -#include "diff.h" -#include "diff_driver.h" -#include "patch_generate.h" -#include "utf8.h" - -static int git_xdiff_scan_int(const char **str, int *value) -{ - const char *scan = *str; - int v = 0, digits = 0; - /* find next digit */ - for (scan = *str; *scan && !git__isdigit(*scan); scan++); - /* parse next number */ - for (; git__isdigit(*scan); scan++, digits++) - v = (v * 10) + (*scan - '0'); - *str = scan; - *value = v; - return (digits > 0) ? 0 : -1; -} - -static int git_xdiff_parse_hunk(git_diff_hunk *hunk, const char *header) -{ - /* expect something of the form "@@ -%d[,%d] +%d[,%d] @@" */ - if (*header != '@') - goto fail; - if (git_xdiff_scan_int(&header, &hunk->old_start) < 0) - goto fail; - if (*header == ',') { - if (git_xdiff_scan_int(&header, &hunk->old_lines) < 0) - goto fail; - } else - hunk->old_lines = 1; - if (git_xdiff_scan_int(&header, &hunk->new_start) < 0) - goto fail; - if (*header == ',') { - if (git_xdiff_scan_int(&header, &hunk->new_lines) < 0) - goto fail; - } else - hunk->new_lines = 1; - if (hunk->old_start < 0 || hunk->new_start < 0) - goto fail; - - return 0; - -fail: - git_error_set(GIT_ERROR_INVALID, "malformed hunk header from xdiff"); - return -1; -} - -typedef struct { - git_xdiff_output *xo; - git_patch_generated *patch; - git_diff_hunk hunk; - int old_lineno, new_lineno; - mmfile_t xd_old_data, xd_new_data; -} git_xdiff_info; - -static int diff_update_lines( - git_xdiff_info *info, - git_diff_line *line, - const char *content, - size_t content_len) -{ - const char *scan = content, *scan_end = content + content_len; - - for (line->num_lines = 0; scan < scan_end; ++scan) - if (*scan == '\n') - ++line->num_lines; - - line->content = content; - line->content_len = content_len; - - /* expect " "/"-"/"+", then data */ - switch (line->origin) { - case GIT_DIFF_LINE_ADDITION: - case GIT_DIFF_LINE_DEL_EOFNL: - line->old_lineno = -1; - line->new_lineno = info->new_lineno; - info->new_lineno += (int)line->num_lines; - break; - case GIT_DIFF_LINE_DELETION: - case GIT_DIFF_LINE_ADD_EOFNL: - line->old_lineno = info->old_lineno; - line->new_lineno = -1; - info->old_lineno += (int)line->num_lines; - break; - case GIT_DIFF_LINE_CONTEXT: - case GIT_DIFF_LINE_CONTEXT_EOFNL: - line->old_lineno = info->old_lineno; - line->new_lineno = info->new_lineno; - info->old_lineno += (int)line->num_lines; - info->new_lineno += (int)line->num_lines; - break; - default: - git_error_set(GIT_ERROR_INVALID, "unknown diff line origin %02x", - (unsigned int)line->origin); - return -1; - } - - return 0; -} - -static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len) -{ - git_xdiff_info *info = priv; - git_patch_generated *patch = info->patch; - const git_diff_delta *delta = patch->base.delta; - git_patch_generated_output *output = &info->xo->output; - git_diff_line line; - size_t buffer_len; - - if (len == 1) { - output->error = git_xdiff_parse_hunk(&info->hunk, bufs[0].ptr); - if (output->error < 0) - return output->error; - - info->hunk.header_len = bufs[0].size; - if (info->hunk.header_len >= sizeof(info->hunk.header)) - info->hunk.header_len = sizeof(info->hunk.header) - 1; - - /* Sanitize the hunk header in case there is invalid Unicode */ - buffer_len = git_utf8_valid_buf_length(bufs[0].ptr, info->hunk.header_len); - /* Sanitizing the hunk header may delete the newline, so add it back again if there is room */ - if (buffer_len < info->hunk.header_len) { - bufs[0].ptr[buffer_len] = '\n'; - buffer_len += 1; - info->hunk.header_len = buffer_len; - } - - memcpy(info->hunk.header, bufs[0].ptr, info->hunk.header_len); - info->hunk.header[info->hunk.header_len] = '\0'; - - if (output->hunk_cb != NULL && - (output->error = output->hunk_cb( - delta, &info->hunk, output->payload))) - return output->error; - - info->old_lineno = info->hunk.old_start; - info->new_lineno = info->hunk.new_start; - } - - if (len == 2 || len == 3) { - /* expect " "/"-"/"+", then data */ - line.origin = - (*bufs[0].ptr == '+') ? GIT_DIFF_LINE_ADDITION : - (*bufs[0].ptr == '-') ? GIT_DIFF_LINE_DELETION : - GIT_DIFF_LINE_CONTEXT; - - if (line.origin == GIT_DIFF_LINE_ADDITION) - line.content_offset = bufs[1].ptr - info->xd_new_data.ptr; - else if (line.origin == GIT_DIFF_LINE_DELETION) - line.content_offset = bufs[1].ptr - info->xd_old_data.ptr; - else - line.content_offset = -1; - - output->error = diff_update_lines( - info, &line, bufs[1].ptr, bufs[1].size); - - if (!output->error && output->data_cb != NULL) - output->error = output->data_cb( - delta, &info->hunk, &line, output->payload); - } - - if (len == 3 && !output->error) { - /* If we have a '+' and a third buf, then we have added a line - * without a newline and the old code had one, so DEL_EOFNL. - * If we have a '-' and a third buf, then we have removed a line - * with out a newline but added a blank line, so ADD_EOFNL. - */ - line.origin = - (*bufs[0].ptr == '+') ? GIT_DIFF_LINE_DEL_EOFNL : - (*bufs[0].ptr == '-') ? GIT_DIFF_LINE_ADD_EOFNL : - GIT_DIFF_LINE_CONTEXT_EOFNL; - - line.content_offset = -1; - - output->error = diff_update_lines( - info, &line, bufs[2].ptr, bufs[2].size); - - if (!output->error && output->data_cb != NULL) - output->error = output->data_cb( - delta, &info->hunk, &line, output->payload); - } - - return output->error; -} - -static int git_xdiff(git_patch_generated_output *output, git_patch_generated *patch) -{ - git_xdiff_output *xo = (git_xdiff_output *)output; - git_xdiff_info info; - git_diff_find_context_payload findctxt; - - memset(&info, 0, sizeof(info)); - info.patch = patch; - info.xo = xo; - - xo->callback.priv = &info; - - git_diff_find_context_init( - &xo->config.find_func, &findctxt, git_patch_generated_driver(patch)); - xo->config.find_func_priv = &findctxt; - - if (xo->config.find_func != NULL) - xo->config.flags |= XDL_EMIT_FUNCNAMES; - else - xo->config.flags &= ~XDL_EMIT_FUNCNAMES; - - /* TODO: check ofile.opts_flags to see if driver-specific per-file - * updates are needed to xo->params.flags - */ - - if (git_patch_generated_old_data(&info.xd_old_data.ptr, &info.xd_old_data.size, patch) < 0 || - git_patch_generated_new_data(&info.xd_new_data.ptr, &info.xd_new_data.size, patch) < 0) - return -1; - - xdl_diff(&info.xd_old_data, &info.xd_new_data, - &xo->params, &xo->config, &xo->callback); - - git_diff_find_context_clear(&findctxt); - - return xo->output.error; -} - -void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts) -{ - uint32_t flags = opts ? opts->flags : 0; - - xo->output.diff_cb = git_xdiff; - - xo->config.ctxlen = opts ? opts->context_lines : 3; - xo->config.interhunkctxlen = opts ? opts->interhunk_lines : 0; - - if (flags & GIT_DIFF_IGNORE_WHITESPACE) - xo->params.flags |= XDF_WHITESPACE_FLAGS; - if (flags & GIT_DIFF_IGNORE_WHITESPACE_CHANGE) - xo->params.flags |= XDF_IGNORE_WHITESPACE_CHANGE; - if (flags & GIT_DIFF_IGNORE_WHITESPACE_EOL) - xo->params.flags |= XDF_IGNORE_WHITESPACE_AT_EOL; - if (flags & GIT_DIFF_INDENT_HEURISTIC) - xo->params.flags |= XDF_INDENT_HEURISTIC; - - if (flags & GIT_DIFF_PATIENCE) - xo->params.flags |= XDF_PATIENCE_DIFF; - if (flags & GIT_DIFF_MINIMAL) - xo->params.flags |= XDF_NEED_MINIMAL; - - if (flags & GIT_DIFF_IGNORE_BLANK_LINES) - xo->params.flags |= XDF_IGNORE_BLANK_LINES; - - xo->callback.out_line = git_xdiff_cb; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/diff_xdiff.h b/vendor/libgit2-sys/libgit2/src/libgit2/diff_xdiff.h deleted file mode 100644 index 327dc7c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/diff_xdiff.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_diff_xdiff_h__ -#define INCLUDE_diff_xdiff_h__ - -#include "common.h" - -#include "diff.h" -#include "xdiff.h" -#include "patch_generate.h" - -/* xdiff cannot cope with large files. these files should not be passed to - * xdiff. callers should treat these large files as binary. - */ -#define GIT_XDIFF_MAX_SIZE (INT64_C(1024) * 1024 * 1023) - -/* A git_xdiff_output is a git_patch_generate_output with extra fields - * necessary to use libxdiff. Calling git_xdiff_init() will set the diff_cb - * field of the output to use xdiff to generate the diffs. - */ -typedef struct { - git_patch_generated_output output; - - xdemitconf_t config; - xpparam_t params; - xdemitcb_t callback; -} git_xdiff_output; - -void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/email.c b/vendor/libgit2-sys/libgit2/src/libgit2/email.c deleted file mode 100644 index c1470c1..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/email.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "email.h" - -#include "common.h" -#include "buf.h" -#include "diff_generate.h" -#include "diff_stats.h" -#include "patch.h" -#include "date.h" - -#include "git2/email.h" -#include "git2/patch.h" -#include "git2/sys/email.h" -#include "git2/version.h" - -/* - * Git uses a "magic" timestamp to indicate that an email message - * is from `git format-patch` (or our equivalent). - */ -#define EMAIL_TIMESTAMP "Mon Sep 17 00:00:00 2001" - -GIT_INLINE(int) include_prefix( - size_t patch_count, - git_email_create_options *opts) -{ - return ((!opts->subject_prefix || *opts->subject_prefix) || - (opts->flags & GIT_EMAIL_CREATE_ALWAYS_NUMBER) != 0 || - opts->reroll_number || - (patch_count > 1 && !(opts->flags & GIT_EMAIL_CREATE_OMIT_NUMBERS))); -} - -static int append_prefix( - git_str *out, - size_t patch_idx, - size_t patch_count, - git_email_create_options *opts) -{ - const char *subject_prefix = opts->subject_prefix ? - opts->subject_prefix : "PATCH"; - - git_str_putc(out, '['); - - if (*subject_prefix) - git_str_puts(out, subject_prefix); - - if (opts->reroll_number) { - if (*subject_prefix) - git_str_putc(out, ' '); - - git_str_printf(out, "v%" PRIuZ, opts->reroll_number); - } - - if ((opts->flags & GIT_EMAIL_CREATE_ALWAYS_NUMBER) != 0 || - (patch_count > 1 && !(opts->flags & GIT_EMAIL_CREATE_OMIT_NUMBERS))) { - size_t start_number = opts->start_number ? - opts->start_number : 1; - - if (*subject_prefix || opts->reroll_number) - git_str_putc(out, ' '); - - git_str_printf(out, "%" PRIuZ "/%" PRIuZ, - patch_idx + (start_number - 1), - patch_count + (start_number - 1)); - } - - git_str_puts(out, "]"); - - return git_str_oom(out) ? -1 : 0; -} - -static int append_date( - git_str *out, - const git_time *date) -{ - int error; - - if ((error = git_str_printf(out, "Date: ")) == 0 && - (error = git_date_rfc2822_fmt(out, date->time, date->offset)) == 0) - error = git_str_putc(out, '\n'); - - return error; -} - -static int append_subject( - git_str *out, - size_t patch_idx, - size_t patch_count, - const char *summary, - git_email_create_options *opts) -{ - bool prefix = include_prefix(patch_count, opts); - size_t summary_len = summary ? strlen(summary) : 0; - int error; - - if (summary_len) { - const char *nl = strchr(summary, '\n'); - - if (nl) - summary_len = (nl - summary); - } - - if ((error = git_str_puts(out, "Subject: ")) < 0) - return error; - - if (prefix && - (error = append_prefix(out, patch_idx, patch_count, opts)) < 0) - return error; - - if (prefix && summary_len && (error = git_str_putc(out, ' ')) < 0) - return error; - - if (summary_len && - (error = git_str_put(out, summary, summary_len)) < 0) - return error; - - return git_str_putc(out, '\n'); -} - -static int append_header( - git_str *out, - size_t patch_idx, - size_t patch_count, - const git_oid *commit_id, - const char *summary, - const git_signature *author, - git_email_create_options *opts) -{ - char id[GIT_OID_MAX_HEXSIZE + 1]; - int error; - - git_oid_tostr(id, GIT_OID_MAX_HEXSIZE + 1, commit_id); - - if ((error = git_str_printf(out, "From %s %s\n", id, EMAIL_TIMESTAMP)) < 0 || - (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 || - (error = append_date(out, &author->when)) < 0 || - (error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0) - return error; - - if ((error = git_str_putc(out, '\n')) < 0) - return error; - - return 0; -} - -static int append_body(git_str *out, const char *body) -{ - size_t body_len; - int error; - - if (!body) - return 0; - - body_len = strlen(body); - - if ((error = git_str_puts(out, body)) < 0) - return error; - - if (body_len && body[body_len - 1] != '\n') - error = git_str_putc(out, '\n'); - - return error; -} - -static int append_diffstat(git_str *out, git_diff *diff) -{ - git_diff_stats *stats = NULL; - unsigned int format_flags; - int error; - - format_flags = GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY; - - if ((error = git_diff_get_stats(&stats, diff)) == 0 && - (error = git_diff__stats_to_buf(out, stats, format_flags, 0)) == 0) - error = git_str_putc(out, '\n'); - - git_diff_stats_free(stats); - return error; -} - -static int append_patches(git_str *out, git_diff *diff) -{ - size_t i, deltas; - int error = 0; - - deltas = git_diff_num_deltas(diff); - - for (i = 0; i < deltas; ++i) { - git_patch *patch = NULL; - - if ((error = git_patch_from_diff(&patch, diff, i)) >= 0) - error = git_patch__to_buf(out, patch); - - git_patch_free(patch); - - if (error < 0) - break; - } - - return error; -} - -int git_email__append_from_diff( - git_str *out, - git_diff *diff, - size_t patch_idx, - size_t patch_count, - const git_oid *commit_id, - const char *summary, - const char *body, - const git_signature *author, - const git_email_create_options *given_opts) -{ - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diff); - GIT_ASSERT_ARG(!patch_idx || patch_idx <= patch_count); - GIT_ASSERT_ARG(commit_id); - GIT_ASSERT_ARG(author); - - GIT_ERROR_CHECK_VERSION(given_opts, - GIT_EMAIL_CREATE_OPTIONS_VERSION, - "git_email_create_options"); - - if (given_opts) - memcpy(&opts, given_opts, sizeof(git_email_create_options)); - - if ((error = append_header(out, patch_idx, patch_count, commit_id, summary, author, &opts)) == 0 && - (error = append_body(out, body)) == 0 && - (error = git_str_puts(out, "---\n")) == 0 && - (error = append_diffstat(out, diff)) == 0 && - (error = append_patches(out, diff)) == 0) - error = git_str_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n"); - - return error; -} - -int git_email_create_from_diff( - git_buf *out, - git_diff *diff, - size_t patch_idx, - size_t patch_count, - const git_oid *commit_id, - const char *summary, - const char *body, - const git_signature *author, - const git_email_create_options *given_opts) -{ - git_str email = GIT_STR_INIT; - int error; - - git_buf_tostr(&email, out); - - error = git_email__append_from_diff(&email, diff, patch_idx, - patch_count, commit_id, summary, body, author, - given_opts); - - if (error == 0) - error = git_buf_fromstr(out, &email); - - git_str_dispose(&email); - return error; -} - -int git_email_create_from_commit( - git_buf *out, - git_commit *commit, - const git_email_create_options *given_opts) -{ - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - git_diff *diff = NULL; - git_repository *repo; - git_diff_options *diff_opts; - git_diff_find_options *find_opts; - const git_signature *author; - const char *summary, *body; - const git_oid *commit_id; - int error = -1; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(commit); - - GIT_ERROR_CHECK_VERSION(given_opts, - GIT_EMAIL_CREATE_OPTIONS_VERSION, - "git_email_create_options"); - - if (given_opts) - memcpy(&opts, given_opts, sizeof(git_email_create_options)); - - repo = git_commit_owner(commit); - author = git_commit_author(commit); - summary = git_commit_summary(commit); - body = git_commit_body(commit); - commit_id = git_commit_id(commit); - diff_opts = &opts.diff_opts; - find_opts = &opts.diff_find_opts; - - if ((error = git_diff__commit(&diff, repo, commit, diff_opts)) < 0) - goto done; - - if ((opts.flags & GIT_EMAIL_CREATE_NO_RENAMES) == 0 && - (error = git_diff_find_similar(diff, find_opts)) < 0) - goto done; - - error = git_email_create_from_diff(out, diff, 1, 1, commit_id, summary, body, author, &opts); - -done: - git_diff_free(diff); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/email.h b/vendor/libgit2-sys/libgit2/src/libgit2/email.h deleted file mode 100644 index 083e56d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/email.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_email_h__ -#define INCLUDE_email_h__ - -#include "common.h" - -#include "git2/email.h" - -extern int git_email__append_from_diff( - git_str *out, - git_diff *diff, - size_t patch_idx, - size_t patch_count, - const git_oid *commit_id, - const char *summary, - const char *body, - const git_signature *author, - const git_email_create_options *given_opts); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/experimental.h.in b/vendor/libgit2-sys/libgit2/src/libgit2/experimental.h.in deleted file mode 100644 index 25fb14b..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/experimental.h.in +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_experimental_h__ -#define INCLUDE_experimental_h__ - -#cmakedefine GIT_EXPERIMENTAL_SHA256 1 - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/fetch.c b/vendor/libgit2-sys/libgit2/src/libgit2/fetch.c deleted file mode 100644 index 8e2660f..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/fetch.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "fetch.h" - -#include "git2/oid.h" -#include "git2/refs.h" -#include "git2/revwalk.h" -#include "git2/transport.h" -#include "git2/sys/remote.h" - -#include "oid.h" -#include "remote.h" -#include "refspec.h" -#include "pack.h" -#include "repository.h" -#include "refs.h" -#include "transports/smart.h" - -static int maybe_want(git_remote *remote, git_remote_head *head, git_refspec *tagspec, git_remote_autotag_option_t tagopt) -{ - int match = 0, valid; - - if (git_reference_name_is_valid(&valid, head->name) < 0) - return -1; - - if (!valid) - return 0; - - if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_ALL) { - /* - * If tagopt is --tags, always request tags - * in addition to the remote's refspecs - */ - if (git_refspec_src_matches(tagspec, head->name)) - match = 1; - } - - if (!match && git_remote__matching_refspec(remote, head->name)) - match = 1; - - if (!match) - return 0; - - return git_vector_insert(&remote->refs, head); -} - -static int mark_local(git_remote *remote) -{ - git_remote_head *head; - git_odb *odb; - size_t i; - - if (git_repository_odb__weakptr(&odb, remote->repo) < 0) - return -1; - - git_vector_foreach(&remote->refs, i, head) { - /* If we have the object, mark it so we don't ask for it. - However if we are unshallowing or changing history - depth, we need to ask for it even though the head - exists locally. */ - if (remote->nego.depth == GIT_FETCH_DEPTH_FULL && - git_odb_exists(odb, &head->oid)) - head->local = 1; - else - remote->need_pack = 1; - } - - return 0; -} - -static int maybe_want_oid(git_remote *remote, git_refspec *spec) -{ - git_remote_head *oid_head; - - oid_head = git__calloc(1, sizeof(git_remote_head)); - GIT_ERROR_CHECK_ALLOC(oid_head); - - git_oid__fromstr(&oid_head->oid, spec->src, remote->repo->oid_type); - - if (spec->dst) { - oid_head->name = git__strdup(spec->dst); - GIT_ERROR_CHECK_ALLOC(oid_head->name); - } - - if (git_vector_insert(&remote->local_heads, oid_head) < 0 || - git_vector_insert(&remote->refs, oid_head) < 0) - return -1; - - return 0; -} - -static int filter_wants(git_remote *remote, const git_fetch_options *opts) -{ - git_remote_head **heads; - git_refspec tagspec, head, *spec; - int error = 0; - size_t i, heads_len; - unsigned int remote_caps; - unsigned int oid_mask = GIT_REMOTE_CAPABILITY_TIP_OID | - GIT_REMOTE_CAPABILITY_REACHABLE_OID; - git_remote_autotag_option_t tagopt = remote->download_tags; - - if (opts && opts->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED) - tagopt = opts->download_tags; - - git_vector_clear(&remote->refs); - if ((error = git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true)) < 0) - return error; - - /* - * The fetch refspec can be NULL, and what this means is that the - * user didn't specify one. This is fine, as it means that we're - * not interested in any particular branch but just the remote's - * HEAD, which will be stored in FETCH_HEAD after the fetch. - */ - if (remote->active_refspecs.length == 0) { - if ((error = git_refspec__parse(&head, "HEAD", true)) < 0) - goto cleanup; - - error = git_refspec__dwim_one(&remote->active_refspecs, &head, &remote->refs); - git_refspec__dispose(&head); - - if (error < 0) - goto cleanup; - } - - if ((error = git_remote_ls((const git_remote_head ***)&heads, &heads_len, remote)) < 0 || - (error = git_remote_capabilities(&remote_caps, remote)) < 0) - goto cleanup; - - /* Handle remote heads */ - for (i = 0; i < heads_len; i++) { - if ((error = maybe_want(remote, heads[i], &tagspec, tagopt)) < 0) - goto cleanup; - } - - /* Handle explicitly specified OID specs */ - git_vector_foreach(&remote->active_refspecs, i, spec) { - if (!git_oid__is_hexstr(spec->src, remote->repo->oid_type)) - continue; - - if (!(remote_caps & oid_mask)) { - git_error_set(GIT_ERROR_INVALID, "cannot fetch a specific object from the remote repository"); - error = -1; - goto cleanup; - } - - if ((error = maybe_want_oid(remote, spec)) < 0) - goto cleanup; - } - - error = mark_local(remote); - -cleanup: - git_refspec__dispose(&tagspec); - - return error; -} - -/* - * In this first version, we push all our refs in and start sending - * them out. When we get an ACK we hide that commit and continue - * traversing until we're done - */ -int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts) -{ - git_transport *t = remote->transport; - int error; - - remote->need_pack = 0; - - if (opts) { - GIT_ASSERT_ARG(opts->depth >= 0); - remote->nego.depth = opts->depth; - } - - if (filter_wants(remote, opts) < 0) - return -1; - - /* Don't try to negotiate when we don't want anything */ - if (!remote->need_pack) - return 0; - - /* - * Now we have everything set up so we can start tell the - * server what we want and what we have. - */ - remote->nego.refs = (const git_remote_head * const *)remote->refs.contents; - remote->nego.refs_len = remote->refs.length; - - if (git_repository__shallow_roots(&remote->nego.shallow_roots, - &remote->nego.shallow_roots_len, - remote->repo) < 0) - return -1; - - error = t->negotiate_fetch(t, - remote->repo, - &remote->nego); - - git__free(remote->nego.shallow_roots); - - return error; -} - -int git_fetch_download_pack(git_remote *remote) -{ - git_oidarray shallow_roots = { NULL }; - git_transport *t = remote->transport; - int error; - - if (!remote->need_pack) - return 0; - - if ((error = t->download_pack(t, remote->repo, &remote->stats)) != 0 || - (error = t->shallow_roots(&shallow_roots, t)) != 0) - return error; - - error = git_repository__shallow_roots_write(remote->repo, &shallow_roots); - - git_oidarray_dispose(&shallow_roots); - return error; -} - -int git_fetch_options_init(git_fetch_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_fetch_options, GIT_FETCH_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_fetch_init_options(git_fetch_options *opts, unsigned int version) -{ - return git_fetch_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/fetch.h b/vendor/libgit2-sys/libgit2/src/libgit2/fetch.h deleted file mode 100644 index 493366d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/fetch.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_fetch_h__ -#define INCLUDE_fetch_h__ - -#include "common.h" - -#include "git2/remote.h" - -int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts); - -int git_fetch_download_pack(git_remote *remote); - -int git_fetch_setup_walk(git_revwalk **out, git_repository *repo); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/fetchhead.c b/vendor/libgit2-sys/libgit2/src/libgit2/fetchhead.c deleted file mode 100644 index 45ac053..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/fetchhead.c +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "fetchhead.h" - -#include "git2/types.h" -#include "git2/oid.h" - -#include "str.h" -#include "futils.h" -#include "filebuf.h" -#include "refs.h" -#include "net.h" -#include "repository.h" - -int git_fetchhead_ref_cmp(const void *a, const void *b) -{ - const git_fetchhead_ref *one = (const git_fetchhead_ref *)a; - const git_fetchhead_ref *two = (const git_fetchhead_ref *)b; - - if (one->is_merge && !two->is_merge) - return -1; - if (two->is_merge && !one->is_merge) - return 1; - - if (one->ref_name && two->ref_name) - return strcmp(one->ref_name, two->ref_name); - else if (one->ref_name) - return -1; - else if (two->ref_name) - return 1; - - return 0; -} - -static char *sanitized_remote_url(const char *remote_url) -{ - git_net_url url = GIT_NET_URL_INIT; - char *sanitized = NULL; - int error; - - if (git_net_url_parse(&url, remote_url) == 0) { - git_str buf = GIT_STR_INIT; - - git__free(url.username); - git__free(url.password); - url.username = url.password = NULL; - - if ((error = git_net_url_fmt(&buf, &url)) < 0) - goto fallback; - - sanitized = git_str_detach(&buf); - } - -fallback: - if (!sanitized) - sanitized = git__strdup(remote_url); - - git_net_url_dispose(&url); - return sanitized; -} - -int git_fetchhead_ref_create( - git_fetchhead_ref **out, - git_oid *oid, - unsigned int is_merge, - const char *ref_name, - const char *remote_url) -{ - git_fetchhead_ref *fetchhead_ref; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(oid); - - *out = NULL; - - fetchhead_ref = git__malloc(sizeof(git_fetchhead_ref)); - GIT_ERROR_CHECK_ALLOC(fetchhead_ref); - - memset(fetchhead_ref, 0x0, sizeof(git_fetchhead_ref)); - - git_oid_cpy(&fetchhead_ref->oid, oid); - fetchhead_ref->is_merge = is_merge; - - if (ref_name) { - fetchhead_ref->ref_name = git__strdup(ref_name); - GIT_ERROR_CHECK_ALLOC(fetchhead_ref->ref_name); - } - - if (remote_url) { - fetchhead_ref->remote_url = sanitized_remote_url(remote_url); - GIT_ERROR_CHECK_ALLOC(fetchhead_ref->remote_url); - } - - *out = fetchhead_ref; - - return 0; -} - -static int fetchhead_ref_write( - git_filebuf *file, - git_fetchhead_ref *fetchhead_ref) -{ - char oid[GIT_OID_MAX_HEXSIZE + 1]; - const char *type = NULL, *name = NULL; - int head = 0; - - GIT_ASSERT_ARG(file); - GIT_ASSERT_ARG(fetchhead_ref); - - git_oid_tostr(oid, GIT_OID_MAX_HEXSIZE + 1, &fetchhead_ref->oid); - - if (git__prefixcmp(fetchhead_ref->ref_name, GIT_REFS_HEADS_DIR) == 0) { - type = "branch "; - name = fetchhead_ref->ref_name + strlen(GIT_REFS_HEADS_DIR); - } else if(git__prefixcmp(fetchhead_ref->ref_name, - GIT_REFS_TAGS_DIR) == 0) { - type = "tag "; - name = fetchhead_ref->ref_name + strlen(GIT_REFS_TAGS_DIR); - } else if (!git__strcmp(fetchhead_ref->ref_name, GIT_HEAD_FILE)) { - head = 1; - } else { - type = ""; - name = fetchhead_ref->ref_name; - } - - if (head) - return git_filebuf_printf(file, "%s\t\t%s\n", oid, fetchhead_ref->remote_url); - - return git_filebuf_printf(file, "%s\t%s\t%s'%s' of %s\n", - oid, - (fetchhead_ref->is_merge) ? "" : "not-for-merge", - type, - name, - fetchhead_ref->remote_url); -} - -int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str path = GIT_STR_INIT; - unsigned int i; - git_fetchhead_ref *fetchhead_ref; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(fetchhead_refs); - - if (git_str_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0) - return -1; - - if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_APPEND, GIT_REFS_FILE_MODE) < 0) { - git_str_dispose(&path); - return -1; - } - - git_str_dispose(&path); - - git_vector_sort(fetchhead_refs); - - git_vector_foreach(fetchhead_refs, i, fetchhead_ref) - fetchhead_ref_write(&file, fetchhead_ref); - - return git_filebuf_commit(&file); -} - -static int fetchhead_ref_parse( - git_oid *oid, - unsigned int *is_merge, - git_str *ref_name, - const char **remote_url, - char *line, - size_t line_num, - git_oid_t oid_type) -{ - char *oid_str, *is_merge_str, *desc, *name = NULL; - const char *type = NULL; - int error = 0; - - *remote_url = NULL; - - if (!*line) { - git_error_set(GIT_ERROR_FETCHHEAD, - "empty line in FETCH_HEAD line %"PRIuZ, line_num); - return -1; - } - - /* Compat with old git clients that wrote FETCH_HEAD like a loose ref. */ - if ((oid_str = git__strsep(&line, "\t")) == NULL) { - oid_str = line; - line += strlen(line); - - *is_merge = 1; - } - - if (strlen(oid_str) != git_oid_hexsize(oid_type)) { - git_error_set(GIT_ERROR_FETCHHEAD, - "invalid object ID in FETCH_HEAD line %"PRIuZ, line_num); - return -1; - } - - if (git_oid__fromstr(oid, oid_str, oid_type) < 0) { - const git_error *oid_err = git_error_last(); - const char *err_msg = oid_err ? oid_err->message : "invalid object ID"; - - git_error_set(GIT_ERROR_FETCHHEAD, "%s in FETCH_HEAD line %"PRIuZ, - err_msg, line_num); - return -1; - } - - /* Parse new data from newer git clients */ - if (*line) { - if ((is_merge_str = git__strsep(&line, "\t")) == NULL) { - git_error_set(GIT_ERROR_FETCHHEAD, - "invalid description data in FETCH_HEAD line %"PRIuZ, line_num); - return -1; - } - - if (*is_merge_str == '\0') - *is_merge = 1; - else if (strcmp(is_merge_str, "not-for-merge") == 0) - *is_merge = 0; - else { - git_error_set(GIT_ERROR_FETCHHEAD, - "invalid for-merge entry in FETCH_HEAD line %"PRIuZ, line_num); - return -1; - } - - if ((desc = line) == NULL) { - git_error_set(GIT_ERROR_FETCHHEAD, - "invalid description in FETCH_HEAD line %"PRIuZ, line_num); - return -1; - } - - if (git__prefixcmp(desc, "branch '") == 0) { - type = GIT_REFS_HEADS_DIR; - name = desc + 8; - } else if (git__prefixcmp(desc, "tag '") == 0) { - type = GIT_REFS_TAGS_DIR; - name = desc + 5; - } else if (git__prefixcmp(desc, "'") == 0) - name = desc + 1; - - if (name) { - if ((desc = strstr(name, "' ")) == NULL || - git__prefixcmp(desc, "' of ") != 0) { - git_error_set(GIT_ERROR_FETCHHEAD, - "invalid description in FETCH_HEAD line %"PRIuZ, line_num); - return -1; - } - - *desc = '\0'; - desc += 5; - } - - *remote_url = desc; - } - - git_str_clear(ref_name); - - if (type) - git_str_join(ref_name, '/', type, name); - else if(name) - git_str_puts(ref_name, name); - - return error; -} - -int git_repository_fetchhead_foreach( - git_repository *repo, - git_repository_fetchhead_foreach_cb cb, - void *payload) -{ - git_str path = GIT_STR_INIT, file = GIT_STR_INIT, name = GIT_STR_INIT; - const char *ref_name; - git_oid oid; - const char *remote_url; - unsigned int is_merge = 0; - char *buffer, *line; - size_t line_num = 0; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(cb); - - if (git_str_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0) - return -1; - - if ((error = git_futils_readbuffer(&file, git_str_cstr(&path))) < 0) - goto done; - - buffer = file.ptr; - - while ((line = git__strsep(&buffer, "\n")) != NULL) { - ++line_num; - - if ((error = fetchhead_ref_parse(&oid, &is_merge, &name, - &remote_url, line, line_num, - repo->oid_type)) < 0) - goto done; - - if (git_str_len(&name) > 0) - ref_name = git_str_cstr(&name); - else - ref_name = NULL; - - error = cb(ref_name, remote_url, &oid, is_merge, payload); - if (error) { - git_error_set_after_callback(error); - goto done; - } - } - - if (*buffer) { - git_error_set(GIT_ERROR_FETCHHEAD, "no EOL at line %"PRIuZ, line_num+1); - error = -1; - goto done; - } - -done: - git_str_dispose(&file); - git_str_dispose(&path); - git_str_dispose(&name); - - return error; -} - -void git_fetchhead_ref_free(git_fetchhead_ref *fetchhead_ref) -{ - if (fetchhead_ref == NULL) - return; - - git__free(fetchhead_ref->remote_url); - git__free(fetchhead_ref->ref_name); - git__free(fetchhead_ref); -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/fetchhead.h b/vendor/libgit2-sys/libgit2/src/libgit2/fetchhead.h deleted file mode 100644 index 9e51710..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/fetchhead.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_fetchhead_h__ -#define INCLUDE_fetchhead_h__ - -#include "common.h" - -#include "oid.h" -#include "vector.h" - -typedef struct git_fetchhead_ref { - git_oid oid; - unsigned int is_merge; - char *ref_name; - char *remote_url; -} git_fetchhead_ref; - -int git_fetchhead_ref_create( - git_fetchhead_ref **fetchhead_ref_out, - git_oid *oid, - unsigned int is_merge, - const char *ref_name, - const char *remote_url); - -int git_fetchhead_ref_cmp(const void *a, const void *b); - -int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs); - -void git_fetchhead_ref_free(git_fetchhead_ref *fetchhead_ref); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/filter.c b/vendor/libgit2-sys/libgit2/src/libgit2/filter.c deleted file mode 100644 index 9e0910c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/filter.c +++ /dev/null @@ -1,1221 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "filter.h" - -#include "buf.h" -#include "common.h" -#include "futils.h" -#include "hash.h" -#include "repository.h" -#include "runtime.h" -#include "git2/sys/filter.h" -#include "git2/config.h" -#include "blob.h" -#include "attr_file.h" -#include "array.h" -#include "path.h" - -struct git_filter_source { - git_repository *repo; - const char *path; - git_oid oid; /* zero if unknown (which is likely) */ - uint16_t filemode; /* zero if unknown */ - git_filter_mode_t mode; - git_filter_options options; -}; - -typedef struct { - const char *filter_name; - git_filter *filter; - void *payload; -} git_filter_entry; - -struct git_filter_list { - git_array_t(git_filter_entry) filters; - git_filter_source source; - git_str *temp_buf; - char path[GIT_FLEX_ARRAY]; -}; - -typedef struct { - char *filter_name; - git_filter *filter; - int priority; - int initialized; - size_t nattrs, nmatches; - char *attrdata; - const char *attrs[GIT_FLEX_ARRAY]; -} git_filter_def; - -static int filter_def_priority_cmp(const void *a, const void *b) -{ - int pa = ((const git_filter_def *)a)->priority; - int pb = ((const git_filter_def *)b)->priority; - return (pa < pb) ? -1 : (pa > pb) ? 1 : 0; -} - -struct git_filter_registry { - git_rwlock lock; - git_vector filters; -}; - -static struct git_filter_registry filter_registry; - -static void git_filter_global_shutdown(void); - - -static int filter_def_scan_attrs( - git_str *attrs, size_t *nattr, size_t *nmatch, const char *attr_str) -{ - const char *start, *scan = attr_str; - int has_eq; - - *nattr = *nmatch = 0; - - if (!scan) - return 0; - - while (*scan) { - while (git__isspace(*scan)) scan++; - - for (start = scan, has_eq = 0; *scan && !git__isspace(*scan); ++scan) { - if (*scan == '=') - has_eq = 1; - } - - if (scan > start) { - (*nattr)++; - if (has_eq || *start == '-' || *start == '+' || *start == '!') - (*nmatch)++; - - if (has_eq) - git_str_putc(attrs, '='); - git_str_put(attrs, start, scan - start); - git_str_putc(attrs, '\0'); - } - } - - return 0; -} - -static void filter_def_set_attrs(git_filter_def *fdef) -{ - char *scan = fdef->attrdata; - size_t i; - - for (i = 0; i < fdef->nattrs; ++i) { - const char *name, *value; - - switch (*scan) { - case '=': - name = scan + 1; - for (scan++; *scan != '='; scan++) /* find '=' */; - *scan++ = '\0'; - value = scan; - break; - case '-': - name = scan + 1; value = git_attr__false; break; - case '+': - name = scan + 1; value = git_attr__true; break; - case '!': - name = scan + 1; value = git_attr__unset; break; - default: - name = scan; value = NULL; break; - } - - fdef->attrs[i] = name; - fdef->attrs[i + fdef->nattrs] = value; - - scan += strlen(scan) + 1; - } -} - -static int filter_def_name_key_check(const void *key, const void *fdef) -{ - const char *name = - fdef ? ((const git_filter_def *)fdef)->filter_name : NULL; - return name ? git__strcmp(key, name) : -1; -} - -static int filter_def_filter_key_check(const void *key, const void *fdef) -{ - const void *filter = fdef ? ((const git_filter_def *)fdef)->filter : NULL; - return (key == filter) ? 0 : -1; -} - -/* Note: callers must lock the registry before calling this function */ -static int filter_registry_insert( - const char *name, git_filter *filter, int priority) -{ - git_filter_def *fdef; - size_t nattr = 0, nmatch = 0, alloc_len; - git_str attrs = GIT_STR_INIT; - - if (filter_def_scan_attrs(&attrs, &nattr, &nmatch, filter->attributes) < 0) - return -1; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloc_len, nattr, 2); - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloc_len, alloc_len, sizeof(char *)); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, sizeof(git_filter_def)); - - fdef = git__calloc(1, alloc_len); - GIT_ERROR_CHECK_ALLOC(fdef); - - fdef->filter_name = git__strdup(name); - GIT_ERROR_CHECK_ALLOC(fdef->filter_name); - - fdef->filter = filter; - fdef->priority = priority; - fdef->nattrs = nattr; - fdef->nmatches = nmatch; - fdef->attrdata = git_str_detach(&attrs); - - filter_def_set_attrs(fdef); - - if (git_vector_insert(&filter_registry.filters, fdef) < 0) { - git__free(fdef->filter_name); - git__free(fdef->attrdata); - git__free(fdef); - return -1; - } - - git_vector_sort(&filter_registry.filters); - return 0; -} - -int git_filter_global_init(void) -{ - git_filter *crlf = NULL, *ident = NULL; - int error = 0; - - if (git_rwlock_init(&filter_registry.lock) < 0) - return -1; - - if ((error = git_vector_init(&filter_registry.filters, 2, - filter_def_priority_cmp)) < 0) - goto done; - - if ((crlf = git_crlf_filter_new()) == NULL || - filter_registry_insert( - GIT_FILTER_CRLF, crlf, GIT_FILTER_CRLF_PRIORITY) < 0 || - (ident = git_ident_filter_new()) == NULL || - filter_registry_insert( - GIT_FILTER_IDENT, ident, GIT_FILTER_IDENT_PRIORITY) < 0) - error = -1; - - if (!error) - error = git_runtime_shutdown_register(git_filter_global_shutdown); - -done: - if (error) { - git_filter_free(crlf); - git_filter_free(ident); - } - - return error; -} - -static void git_filter_global_shutdown(void) -{ - size_t pos; - git_filter_def *fdef; - - if (git_rwlock_wrlock(&filter_registry.lock) < 0) - return; - - git_vector_foreach(&filter_registry.filters, pos, fdef) { - if (fdef->filter && fdef->filter->shutdown) { - fdef->filter->shutdown(fdef->filter); - fdef->initialized = false; - } - - git__free(fdef->filter_name); - git__free(fdef->attrdata); - git__free(fdef); - } - - git_vector_dispose(&filter_registry.filters); - - git_rwlock_wrunlock(&filter_registry.lock); - git_rwlock_free(&filter_registry.lock); -} - -/* Note: callers must lock the registry before calling this function */ -static int filter_registry_find(size_t *pos, const char *name) -{ - return git_vector_search2( - pos, &filter_registry.filters, filter_def_name_key_check, name); -} - -/* Note: callers must lock the registry before calling this function */ -static git_filter_def *filter_registry_lookup(size_t *pos, const char *name) -{ - git_filter_def *fdef = NULL; - - if (!filter_registry_find(pos, name)) - fdef = git_vector_get(&filter_registry.filters, *pos); - - return fdef; -} - - -int git_filter_register( - const char *name, git_filter *filter, int priority) -{ - int error; - - GIT_ASSERT_ARG(name); - GIT_ASSERT_ARG(filter); - - if (git_rwlock_wrlock(&filter_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock filter registry"); - return -1; - } - - if (!filter_registry_find(NULL, name)) { - git_error_set( - GIT_ERROR_FILTER, "attempt to reregister existing filter '%s'", name); - error = GIT_EEXISTS; - goto done; - } - - error = filter_registry_insert(name, filter, priority); - -done: - git_rwlock_wrunlock(&filter_registry.lock); - return error; -} - -int git_filter_unregister(const char *name) -{ - size_t pos; - git_filter_def *fdef; - int error = 0; - - GIT_ASSERT_ARG(name); - - /* cannot unregister default filters */ - if (!strcmp(GIT_FILTER_CRLF, name) || !strcmp(GIT_FILTER_IDENT, name)) { - git_error_set(GIT_ERROR_FILTER, "cannot unregister filter '%s'", name); - return -1; - } - - if (git_rwlock_wrlock(&filter_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock filter registry"); - return -1; - } - - if ((fdef = filter_registry_lookup(&pos, name)) == NULL) { - git_error_set(GIT_ERROR_FILTER, "cannot find filter '%s' to unregister", name); - error = GIT_ENOTFOUND; - goto done; - } - - git_vector_remove(&filter_registry.filters, pos); - - if (fdef->initialized && fdef->filter && fdef->filter->shutdown) { - fdef->filter->shutdown(fdef->filter); - fdef->initialized = false; - } - - git__free(fdef->filter_name); - git__free(fdef->attrdata); - git__free(fdef); - -done: - git_rwlock_wrunlock(&filter_registry.lock); - return error; -} - -static int filter_initialize(git_filter_def *fdef) -{ - int error = 0; - - if (!fdef->initialized && fdef->filter && fdef->filter->initialize) { - if ((error = fdef->filter->initialize(fdef->filter)) < 0) - return error; - } - - fdef->initialized = true; - return 0; -} - -git_filter *git_filter_lookup(const char *name) -{ - size_t pos; - git_filter_def *fdef; - git_filter *filter = NULL; - - if (git_rwlock_rdlock(&filter_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock filter registry"); - return NULL; - } - - if ((fdef = filter_registry_lookup(&pos, name)) == NULL || - (!fdef->initialized && filter_initialize(fdef) < 0)) - goto done; - - filter = fdef->filter; - -done: - git_rwlock_rdunlock(&filter_registry.lock); - return filter; -} - -void git_filter_free(git_filter *filter) -{ - git__free(filter); -} - -git_repository *git_filter_source_repo(const git_filter_source *src) -{ - return src->repo; -} - -const char *git_filter_source_path(const git_filter_source *src) -{ - return src->path; -} - -uint16_t git_filter_source_filemode(const git_filter_source *src) -{ - return src->filemode; -} - -const git_oid *git_filter_source_id(const git_filter_source *src) -{ - return git_oid_is_zero(&src->oid) ? NULL : &src->oid; -} - -git_filter_mode_t git_filter_source_mode(const git_filter_source *src) -{ - return src->mode; -} - -uint32_t git_filter_source_flags(const git_filter_source *src) -{ - return src->options.flags; -} - -static int filter_list_new( - git_filter_list **out, const git_filter_source *src) -{ - git_filter_list *fl = NULL; - size_t pathlen = src->path ? strlen(src->path) : 0, alloclen; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_filter_list), pathlen); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); - - fl = git__calloc(1, alloclen); - GIT_ERROR_CHECK_ALLOC(fl); - - if (src->path) - memcpy(fl->path, src->path, pathlen); - fl->source.repo = src->repo; - fl->source.path = fl->path; - fl->source.mode = src->mode; - - memcpy(&fl->source.options, &src->options, sizeof(git_filter_options)); - - *out = fl; - return 0; -} - -static int filter_list_check_attributes( - const char ***out, - git_repository *repo, - git_filter_session *filter_session, - git_filter_def *fdef, - const git_filter_source *src) -{ - const char **strs = git__calloc(fdef->nattrs, sizeof(const char *)); - git_attr_options attr_opts = GIT_ATTR_OPTIONS_INIT; - size_t i; - int error; - - GIT_ERROR_CHECK_ALLOC(strs); - - if ((src->options.flags & GIT_FILTER_NO_SYSTEM_ATTRIBUTES) != 0) - attr_opts.flags |= GIT_ATTR_CHECK_NO_SYSTEM; - - if ((src->options.flags & GIT_FILTER_ATTRIBUTES_FROM_HEAD) != 0) - attr_opts.flags |= GIT_ATTR_CHECK_INCLUDE_HEAD; - - if ((src->options.flags & GIT_FILTER_ATTRIBUTES_FROM_COMMIT) != 0) { - attr_opts.flags |= GIT_ATTR_CHECK_INCLUDE_COMMIT; - -#ifndef GIT_DEPRECATE_HARD - if (src->options.commit_id) - git_oid_cpy(&attr_opts.attr_commit_id, src->options.commit_id); - else -#endif - git_oid_cpy(&attr_opts.attr_commit_id, &src->options.attr_commit_id); - } - - error = git_attr_get_many_with_session( - strs, repo, filter_session->attr_session, &attr_opts, src->path, fdef->nattrs, fdef->attrs); - - /* if no values were found but no matches are needed, it's okay! */ - if (error == GIT_ENOTFOUND && !fdef->nmatches) { - git_error_clear(); - git__free((void *)strs); - return 0; - } - - for (i = 0; !error && i < fdef->nattrs; ++i) { - const char *want = fdef->attrs[fdef->nattrs + i]; - git_attr_value_t want_type, found_type; - - if (!want) - continue; - - want_type = git_attr_value(want); - found_type = git_attr_value(strs[i]); - - if (want_type != found_type) - error = GIT_ENOTFOUND; - else if (want_type == GIT_ATTR_VALUE_STRING && - strcmp(want, strs[i]) && - strcmp(want, "*")) - error = GIT_ENOTFOUND; - } - - if (error) - git__free((void *)strs); - else - *out = strs; - - return error; -} - -int git_filter_list_new( - git_filter_list **out, - git_repository *repo, - git_filter_mode_t mode, - uint32_t flags) -{ - git_filter_source src = { 0 }; - src.repo = repo; - src.path = NULL; - src.mode = mode; - src.options.flags = flags; - return filter_list_new(out, &src); -} - -int git_filter_list__load( - git_filter_list **filters, - git_repository *repo, - git_blob *blob, /* can be NULL */ - const char *path, - git_filter_mode_t mode, - git_filter_session *filter_session) -{ - int error = 0; - git_filter_list *fl = NULL; - git_filter_source src = { 0 }; - git_filter_entry *fe; - size_t idx; - git_filter_def *fdef; - - if (git_rwlock_rdlock(&filter_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock filter registry"); - return -1; - } - - src.repo = repo; - src.path = path; - src.mode = mode; - - memcpy(&src.options, &filter_session->options, sizeof(git_filter_options)); - - if (blob) - git_oid_cpy(&src.oid, git_blob_id(blob)); - - git_vector_foreach(&filter_registry.filters, idx, fdef) { - const char **values = NULL; - void *payload = NULL; - - if (!fdef || !fdef->filter) - continue; - - if (fdef->nattrs > 0) { - error = filter_list_check_attributes( - &values, repo, - filter_session, fdef, &src); - - if (error == GIT_ENOTFOUND) { - error = 0; - continue; - } else if (error < 0) - break; - } - - if (!fdef->initialized && (error = filter_initialize(fdef)) < 0) - break; - - if (fdef->filter->check) - error = fdef->filter->check( - fdef->filter, &payload, &src, values); - - git__free((void *)values); - - if (error == GIT_PASSTHROUGH) - error = 0; - else if (error < 0) - break; - else { - if (!fl) { - if ((error = filter_list_new(&fl, &src)) < 0) - break; - - fl->temp_buf = filter_session->temp_buf; - } - - fe = git_array_alloc(fl->filters); - GIT_ERROR_CHECK_ALLOC(fe); - - fe->filter = fdef->filter; - fe->filter_name = fdef->filter_name; - fe->payload = payload; - } - } - - git_rwlock_rdunlock(&filter_registry.lock); - - if (error && fl != NULL) { - git_array_clear(fl->filters); - git__free(fl); - fl = NULL; - } - - *filters = fl; - return error; -} - -int git_filter_list_load_ext( - git_filter_list **filters, - git_repository *repo, - git_blob *blob, /* can be NULL */ - const char *path, - git_filter_mode_t mode, - git_filter_options *opts) -{ - git_filter_session filter_session = GIT_FILTER_SESSION_INIT; - - if (opts) - memcpy(&filter_session.options, opts, sizeof(git_filter_options)); - - return git_filter_list__load( - filters, repo, blob, path, mode, &filter_session); -} - -int git_filter_list_load( - git_filter_list **filters, - git_repository *repo, - git_blob *blob, /* can be NULL */ - const char *path, - git_filter_mode_t mode, - uint32_t flags) -{ - git_filter_session filter_session = GIT_FILTER_SESSION_INIT; - - filter_session.options.flags = flags; - - return git_filter_list__load( - filters, repo, blob, path, mode, &filter_session); -} - -void git_filter_list_free(git_filter_list *fl) -{ - uint32_t i; - - if (!fl) - return; - - for (i = 0; i < git_array_size(fl->filters); ++i) { - git_filter_entry *fe = git_array_get(fl->filters, i); - if (fe->filter->cleanup) - fe->filter->cleanup(fe->filter, fe->payload); - } - - git_array_clear(fl->filters); - git__free(fl); -} - -int git_filter_list_contains( - git_filter_list *fl, - const char *name) -{ - size_t i; - - GIT_ASSERT_ARG(name); - - if (!fl) - return 0; - - for (i = 0; i < fl->filters.size; i++) { - if (strcmp(fl->filters.ptr[i].filter_name, name) == 0) - return 1; - } - - return 0; -} - -int git_filter_list_push( - git_filter_list *fl, git_filter *filter, void *payload) -{ - int error = 0; - size_t pos; - git_filter_def *fdef = NULL; - git_filter_entry *fe; - - GIT_ASSERT_ARG(fl); - GIT_ASSERT_ARG(filter); - - if (git_rwlock_rdlock(&filter_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock filter registry"); - return -1; - } - - if (git_vector_search2( - &pos, &filter_registry.filters, - filter_def_filter_key_check, filter) == 0) - fdef = git_vector_get(&filter_registry.filters, pos); - - git_rwlock_rdunlock(&filter_registry.lock); - - if (fdef == NULL) { - git_error_set(GIT_ERROR_FILTER, "cannot use an unregistered filter"); - return -1; - } - - if (!fdef->initialized && (error = filter_initialize(fdef)) < 0) - return error; - - fe = git_array_alloc(fl->filters); - GIT_ERROR_CHECK_ALLOC(fe); - fe->filter = filter; - fe->payload = payload; - - return 0; -} - -size_t git_filter_list_length(const git_filter_list *fl) -{ - return fl ? git_array_size(fl->filters) : 0; -} - -struct buf_stream { - git_writestream parent; - git_str *target; - bool complete; -}; - -static int buf_stream_write( - git_writestream *s, const char *buffer, size_t len) -{ - struct buf_stream *buf_stream = (struct buf_stream *)s; - GIT_ASSERT_ARG(buf_stream); - GIT_ASSERT(buf_stream->complete == 0); - - return git_str_put(buf_stream->target, buffer, len); -} - -static int buf_stream_close(git_writestream *s) -{ - struct buf_stream *buf_stream = (struct buf_stream *)s; - GIT_ASSERT_ARG(buf_stream); - - GIT_ASSERT(buf_stream->complete == 0); - buf_stream->complete = 1; - - return 0; -} - -static void buf_stream_free(git_writestream *s) -{ - GIT_UNUSED(s); -} - -static void buf_stream_init(struct buf_stream *writer, git_str *target) -{ - memset(writer, 0, sizeof(struct buf_stream)); - - writer->parent.write = buf_stream_write; - writer->parent.close = buf_stream_close; - writer->parent.free = buf_stream_free; - writer->target = target; - - git_str_clear(target); -} - -int git_filter_list_apply_to_buffer( - git_buf *out, - git_filter_list *filters, - const char *in, - size_t in_len) -{ - GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_buffer, filters, in, in_len); -} - -int git_filter_list__apply_to_buffer( - git_str *out, - git_filter_list *filters, - const char *in, - size_t in_len) -{ - struct buf_stream writer; - int error; - - buf_stream_init(&writer, out); - - if ((error = git_filter_list_stream_buffer(filters, - in, in_len, &writer.parent)) < 0) - return error; - - GIT_ASSERT(writer.complete); - return error; -} - -int git_filter_list__convert_buf( - git_str *out, - git_filter_list *filters, - git_str *in) -{ - int error; - - if (!filters || git_filter_list_length(filters) == 0) { - git_str_swap(out, in); - git_str_dispose(in); - return 0; - } - - error = git_filter_list__apply_to_buffer(out, filters, - in->ptr, in->size); - - if (!error) - git_str_dispose(in); - - return error; -} - -int git_filter_list_apply_to_file( - git_buf *out, - git_filter_list *filters, - git_repository *repo, - const char *path) -{ - GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_file, filters, repo, path); -} - -int git_filter_list__apply_to_file( - git_str *out, - git_filter_list *filters, - git_repository *repo, - const char *path) -{ - struct buf_stream writer; - int error; - - buf_stream_init(&writer, out); - - if ((error = git_filter_list_stream_file( - filters, repo, path, &writer.parent)) < 0) - return error; - - GIT_ASSERT(writer.complete); - return error; -} - -static int buf_from_blob(git_str *out, git_blob *blob) -{ - git_object_size_t rawsize = git_blob_rawsize(blob); - - if (!git__is_sizet(rawsize)) { - git_error_set(GIT_ERROR_OS, "blob is too large to filter"); - return -1; - } - - git_str_attach_notowned(out, git_blob_rawcontent(blob), (size_t)rawsize); - return 0; -} - -int git_filter_list_apply_to_blob( - git_buf *out, - git_filter_list *filters, - git_blob *blob) -{ - GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_blob, filters, blob); -} - -int git_filter_list__apply_to_blob( - git_str *out, - git_filter_list *filters, - git_blob *blob) -{ - struct buf_stream writer; - int error; - - buf_stream_init(&writer, out); - - if ((error = git_filter_list_stream_blob( - filters, blob, &writer.parent)) < 0) - return error; - - GIT_ASSERT(writer.complete); - return error; -} - -struct buffered_stream { - git_writestream parent; - git_filter *filter; - int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *); - int (*legacy_write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *); - const git_filter_source *source; - void **payload; - git_str input; - git_str temp_buf; - git_str *output; - git_writestream *target; -}; - -static int buffered_stream_write( - git_writestream *s, const char *buffer, size_t len) -{ - struct buffered_stream *buffered_stream = (struct buffered_stream *)s; - GIT_ASSERT_ARG(buffered_stream); - - return git_str_put(&buffered_stream->input, buffer, len); -} - -#ifndef GIT_DEPRECATE_HARD -# define BUF_TO_STRUCT(b, s) \ - (b)->ptr = (s)->ptr; \ - (b)->size = (s)->size; \ - (b)->reserved = (s)->asize; -# define STRUCT_TO_BUF(s, b) \ - (s)->ptr = (b)->ptr; \ - (s)->size = (b)->size; \ - (s)->asize = (b)->reserved; -#endif - -static int buffered_stream_close(git_writestream *s) -{ - struct buffered_stream *buffered_stream = (struct buffered_stream *)s; - git_str *writebuf; - git_error *last_error; - int error; - - GIT_ASSERT_ARG(buffered_stream); - -#ifndef GIT_DEPRECATE_HARD - if (buffered_stream->write_fn == NULL) { - git_buf legacy_output = GIT_BUF_INIT, - legacy_input = GIT_BUF_INIT; - - BUF_TO_STRUCT(&legacy_output, buffered_stream->output); - BUF_TO_STRUCT(&legacy_input, &buffered_stream->input); - - error = buffered_stream->legacy_write_fn( - buffered_stream->filter, - buffered_stream->payload, - &legacy_output, - &legacy_input, - buffered_stream->source); - - STRUCT_TO_BUF(buffered_stream->output, &legacy_output); - STRUCT_TO_BUF(&buffered_stream->input, &legacy_input); - } else -#endif - error = buffered_stream->write_fn( - buffered_stream->filter, - buffered_stream->payload, - buffered_stream->output, - &buffered_stream->input, - buffered_stream->source); - - if (error == GIT_PASSTHROUGH) { - writebuf = &buffered_stream->input; - } else if (error == 0) { - writebuf = buffered_stream->output; - } else { - /* close stream before erroring out taking care - * to preserve the original error */ - git_error_save(&last_error); - buffered_stream->target->close(buffered_stream->target); - git_error_restore(last_error); - return error; - } - - if ((error = buffered_stream->target->write( - buffered_stream->target, writebuf->ptr, writebuf->size)) == 0) - error = buffered_stream->target->close(buffered_stream->target); - - return error; -} - -static void buffered_stream_free(git_writestream *s) -{ - struct buffered_stream *buffered_stream = (struct buffered_stream *)s; - - if (buffered_stream) { - git_str_dispose(&buffered_stream->input); - git_str_dispose(&buffered_stream->temp_buf); - git__free(buffered_stream); - } -} - -int git_filter_buffered_stream_new( - git_writestream **out, - git_filter *filter, - int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *), - git_str *temp_buf, - void **payload, - const git_filter_source *source, - git_writestream *target) -{ - struct buffered_stream *buffered_stream = git__calloc(1, sizeof(struct buffered_stream)); - GIT_ERROR_CHECK_ALLOC(buffered_stream); - - buffered_stream->parent.write = buffered_stream_write; - buffered_stream->parent.close = buffered_stream_close; - buffered_stream->parent.free = buffered_stream_free; - buffered_stream->filter = filter; - buffered_stream->write_fn = write_fn; - buffered_stream->output = temp_buf ? temp_buf : &buffered_stream->temp_buf; - buffered_stream->payload = payload; - buffered_stream->source = source; - buffered_stream->target = target; - - if (temp_buf) - git_str_clear(temp_buf); - - *out = (git_writestream *)buffered_stream; - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -static int buffered_legacy_stream_new( - git_writestream **out, - git_filter *filter, - int (*legacy_write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *), - git_str *temp_buf, - void **payload, - const git_filter_source *source, - git_writestream *target) -{ - struct buffered_stream *buffered_stream = git__calloc(1, sizeof(struct buffered_stream)); - GIT_ERROR_CHECK_ALLOC(buffered_stream); - - buffered_stream->parent.write = buffered_stream_write; - buffered_stream->parent.close = buffered_stream_close; - buffered_stream->parent.free = buffered_stream_free; - buffered_stream->filter = filter; - buffered_stream->legacy_write_fn = legacy_write_fn; - buffered_stream->output = temp_buf ? temp_buf : &buffered_stream->temp_buf; - buffered_stream->payload = payload; - buffered_stream->source = source; - buffered_stream->target = target; - - if (temp_buf) - git_str_clear(temp_buf); - - *out = (git_writestream *)buffered_stream; - return 0; -} -#endif - -static int setup_stream( - git_writestream **out, - git_filter_entry *fe, - git_filter_list *filters, - git_writestream *last_stream) -{ -#ifndef GIT_DEPRECATE_HARD - GIT_ASSERT(fe->filter->stream || fe->filter->apply); - - /* - * If necessary, create a stream that proxies the traditional - * application. - */ - if (!fe->filter->stream) { - /* Create a stream that proxies the one-shot apply */ - return buffered_legacy_stream_new(out, - fe->filter, fe->filter->apply, filters->temp_buf, - &fe->payload, &filters->source, last_stream); - } -#endif - - GIT_ASSERT(fe->filter->stream); - return fe->filter->stream(out, fe->filter, - &fe->payload, &filters->source, last_stream); -} - -static int stream_list_init( - git_writestream **out, - git_vector *streams, - git_filter_list *filters, - git_writestream *target) -{ - git_writestream *last_stream = target; - size_t i; - int error = 0; - - *out = NULL; - - if (!filters) { - *out = target; - return 0; - } - - /* Create filters last to first to get the chaining direction */ - for (i = 0; i < git_array_size(filters->filters); ++i) { - size_t filter_idx = (filters->source.mode == GIT_FILTER_TO_WORKTREE) ? - git_array_size(filters->filters) - 1 - i : i; - - git_filter_entry *fe = git_array_get(filters->filters, filter_idx); - git_writestream *filter_stream; - - error = setup_stream(&filter_stream, fe, filters, last_stream); - - if (error < 0) - goto out; - - git_vector_insert(streams, filter_stream); - last_stream = filter_stream; - } - -out: - if (error) - last_stream->close(last_stream); - else - *out = last_stream; - - return error; -} - -static void filter_streams_free(git_vector *streams) -{ - git_writestream *stream; - size_t i; - - git_vector_foreach(streams, i, stream) - stream->free(stream); - git_vector_dispose(streams); -} - -int git_filter_list_stream_file( - git_filter_list *filters, - git_repository *repo, - const char *path, - git_writestream *target) -{ - char buf[GIT_BUFSIZE_FILTERIO]; - git_str abspath = GIT_STR_INIT; - const char *base = repo ? git_repository_workdir(repo) : NULL; - git_vector filter_streams = GIT_VECTOR_INIT; - git_writestream *stream_start; - ssize_t readlen; - int fd = -1, error, initialized = 0; - - if ((error = stream_list_init( - &stream_start, &filter_streams, filters, target)) < 0 || - (error = git_fs_path_join_unrooted(&abspath, path, base, NULL)) < 0 || - (error = git_path_validate_str_length(repo, &abspath)) < 0) - goto done; - - initialized = 1; - - if ((fd = git_futils_open_ro(abspath.ptr)) < 0) { - error = fd; - goto done; - } - - while ((readlen = p_read(fd, buf, sizeof(buf))) > 0) { - if ((error = stream_start->write(stream_start, buf, readlen)) < 0) - goto done; - } - - if (readlen < 0) - error = -1; - -done: - if (initialized) - error |= stream_start->close(stream_start); - - if (fd >= 0) - p_close(fd); - filter_streams_free(&filter_streams); - git_str_dispose(&abspath); - return error; -} - -int git_filter_list_stream_buffer( - git_filter_list *filters, - const char *buffer, - size_t len, - git_writestream *target) -{ - git_vector filter_streams = GIT_VECTOR_INIT; - git_writestream *stream_start; - int error, initialized = 0; - - if ((error = stream_list_init(&stream_start, &filter_streams, filters, target)) < 0) - goto out; - initialized = 1; - - if ((error = stream_start->write(stream_start, buffer, len)) < 0) - goto out; - -out: - if (initialized) - error |= stream_start->close(stream_start); - - filter_streams_free(&filter_streams); - return error; -} - -int git_filter_list_stream_blob( - git_filter_list *filters, - git_blob *blob, - git_writestream *target) -{ - git_str in = GIT_STR_INIT; - - if (buf_from_blob(&in, blob) < 0) - return -1; - - if (filters) - git_oid_cpy(&filters->source.oid, git_blob_id(blob)); - - return git_filter_list_stream_buffer(filters, in.ptr, in.size, target); -} - -int git_filter_init(git_filter *filter, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE(filter, version, git_filter, GIT_FILTER_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD - -int git_filter_list_stream_data( - git_filter_list *filters, - git_buf *data, - git_writestream *target) -{ - return git_filter_list_stream_buffer(filters, data->ptr, data->size, target); -} - -int git_filter_list_apply_to_data( - git_buf *tgt, git_filter_list *filters, git_buf *src) -{ - return git_filter_list_apply_to_buffer(tgt, filters, src->ptr, src->size); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/filter.h b/vendor/libgit2-sys/libgit2/src/libgit2/filter.h deleted file mode 100644 index 58cb4b4..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/filter.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_filter_h__ -#define INCLUDE_filter_h__ - -#include "common.h" - -#include "attr_file.h" -#include "git2/filter.h" -#include "git2/sys/filter.h" - -/* Amount of file to examine for NUL byte when checking binary-ness */ -#define GIT_FILTER_BYTES_TO_CHECK_NUL 8000 - -typedef struct { - git_filter_options options; - git_attr_session *attr_session; - git_str *temp_buf; -} git_filter_session; - -#define GIT_FILTER_SESSION_INIT {GIT_FILTER_OPTIONS_INIT, 0} - -extern int git_filter_global_init(void); - -extern void git_filter_free(git_filter *filter); - -extern int git_filter_list__load( - git_filter_list **filters, - git_repository *repo, - git_blob *blob, /* can be NULL */ - const char *path, - git_filter_mode_t mode, - git_filter_session *filter_session); - -int git_filter_list__apply_to_buffer( - git_str *out, - git_filter_list *filters, - const char *in, - size_t in_len); -int git_filter_list__apply_to_file( - git_str *out, - git_filter_list *filters, - git_repository *repo, - const char *path); -int git_filter_list__apply_to_blob( - git_str *out, - git_filter_list *filters, - git_blob *blob); - -/* - * The given input buffer will be converted to the given output buffer. - * The input buffer will be freed (_if_ it was allocated). - */ -extern int git_filter_list__convert_buf( - git_str *out, - git_filter_list *filters, - git_str *in); - -extern int git_filter_list__apply_to_file( - git_str *out, - git_filter_list *filters, - git_repository *repo, - const char *path); - -/* - * Available filters - */ - -extern git_filter *git_crlf_filter_new(void); -extern git_filter *git_ident_filter_new(void); - -extern int git_filter_buffered_stream_new( - git_writestream **out, - git_filter *filter, - int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *), - git_str *temp_buf, - void **payload, - const git_filter_source *source, - git_writestream *target); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/git2.rc b/vendor/libgit2-sys/libgit2/src/libgit2/git2.rc deleted file mode 100644 index 07592d1..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/git2.rc +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include "../../include/git2/version.h" - -#ifndef LIBGIT2_FILENAME -# ifdef __GNUC__ -# define LIBGIT2_FILENAME git2 -# else -# define LIBGIT2_FILENAME "git2" -# endif -#endif - -#ifndef LIBGIT2_COMMENTS -# define LIBGIT2_COMMENTS "For more information visit https://libgit2.org/" -#endif - -#ifdef __GNUC__ -# define _STR(x) #x -# define STR(x) _STR(x) -#else -# define STR(x) x -#endif - -#ifdef __GNUC__ -VS_VERSION_INFO VERSIONINFO -#else -VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE -#endif - FILEVERSION LIBGIT2_VERSION_MAJOR,LIBGIT2_VERSION_MINOR,LIBGIT2_VERSION_REVISION,LIBGIT2_VERSION_PATCH - PRODUCTVERSION LIBGIT2_VERSION_MAJOR,LIBGIT2_VERSION_MINOR,LIBGIT2_VERSION_REVISION,LIBGIT2_VERSION_PATCH - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -#ifdef _DEBUG - FILEFLAGS VS_FF_DEBUG -#else - FILEFLAGS 0 -#endif - FILEOS VOS_NT_WINDOWS32 - FILETYPE VFT_DLL - FILESUBTYPE VFT2_UNKNOWN -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" - //language ID = U.S. English, char set = Windows, Multilingual - BEGIN - VALUE "FileDescription", "libgit2 - the Git linkable library\0" - VALUE "FileVersion", LIBGIT2_VERSION "\0" - VALUE "InternalName", STR(LIBGIT2_FILENAME) ".dll\0" - VALUE "LegalCopyright", "Copyright (C) the libgit2 contributors. All rights reserved.\0" - VALUE "OriginalFilename", STR(LIBGIT2_FILENAME) ".dll\0" - VALUE "ProductName", "libgit2\0" - VALUE "ProductVersion", LIBGIT2_VERSION "\0" - VALUE "Comments", LIBGIT2_COMMENTS "\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0409, 1252 - END -END diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/grafts.c b/vendor/libgit2-sys/libgit2/src/libgit2/grafts.c deleted file mode 100644 index d31b4ef..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/grafts.c +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "grafts.h" - -#include "futils.h" -#include "oid.h" -#include "oidarray.h" -#include "parse.h" -#include "hashmap_oid.h" - -GIT_HASHMAP_OID_SETUP(git_grafts_oidmap, git_commit_graft *); - -struct git_grafts { - /* Map of `git_commit_graft`s */ - git_grafts_oidmap commits; - - /* Type of object IDs */ - git_oid_t oid_type; - - /* File backing the graft. NULL if it's an in-memory graft */ - char *path; - unsigned char path_checksum[GIT_HASH_SHA256_SIZE]; -}; - -int git_grafts_new(git_grafts **out, git_oid_t oid_type) -{ - git_grafts *grafts; - - GIT_ASSERT_ARG(out && oid_type); - - grafts = git__calloc(1, sizeof(*grafts)); - GIT_ERROR_CHECK_ALLOC(grafts); - - grafts->oid_type = oid_type; - - *out = grafts; - return 0; -} - -int git_grafts_open( - git_grafts **out, - const char *path, - git_oid_t oid_type) -{ - git_grafts *grafts = NULL; - int error; - - GIT_ASSERT_ARG(out && path && oid_type); - - if ((error = git_grafts_new(&grafts, oid_type)) < 0) - goto error; - - grafts->path = git__strdup(path); - GIT_ERROR_CHECK_ALLOC(grafts->path); - - if ((error = git_grafts_refresh(grafts)) < 0) - goto error; - - *out = grafts; - -error: - if (error < 0) - git_grafts_free(grafts); - - return error; -} - -int git_grafts_open_or_refresh( - git_grafts **out, - const char *path, - git_oid_t oid_type) -{ - GIT_ASSERT_ARG(out && path && oid_type); - - return *out ? git_grafts_refresh(*out) : git_grafts_open(out, path, oid_type); -} - -void git_grafts_free(git_grafts *grafts) -{ - if (!grafts) - return; - git__free(grafts->path); - git_grafts_clear(grafts); - git_grafts_oidmap_dispose(&grafts->commits); - git__free(grafts); -} - -void git_grafts_clear(git_grafts *grafts) -{ - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - git_commit_graft *graft; - - if (!grafts) - return; - - while (git_grafts_oidmap_iterate(&iter, NULL, &graft, &grafts->commits) == 0) { - git__free(graft->parents.ptr); - git__free(graft); - } - - git_grafts_oidmap_clear(&grafts->commits); -} - -int git_grafts_refresh(git_grafts *grafts) -{ - git_str contents = GIT_STR_INIT; - int error, updated = 0; - - GIT_ASSERT_ARG(grafts); - - if (!grafts->path) - return 0; - - if ((error = git_futils_readbuffer_updated(&contents, grafts->path, - grafts->path_checksum, &updated)) < 0) { - - if (error == GIT_ENOTFOUND) { - git_grafts_clear(grafts); - error = 0; - } - - goto cleanup; - } - - if (!updated) { - goto cleanup; - } - - if ((error = git_grafts_parse(grafts, contents.ptr, contents.size)) < 0) - goto cleanup; - -cleanup: - git_str_dispose(&contents); - return error; -} - -int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len) -{ - git_array_oid_t parents = GIT_ARRAY_INIT; - git_parse_ctx parser; - int error; - - git_grafts_clear(grafts); - - if ((error = git_parse_ctx_init(&parser, buf, len)) < 0) - goto error; - - for (; parser.remain_len; git_parse_advance_line(&parser)) { - git_oid graft_oid; - - if ((error = git_parse_advance_oid(&graft_oid, &parser, grafts->oid_type)) < 0) { - git_error_set(GIT_ERROR_GRAFTS, "invalid graft OID at line %" PRIuZ, parser.line_num); - goto error; - } - - while (parser.line_len && git_parse_advance_expected(&parser, "\n", 1) != 0) { - git_oid *id = git_array_alloc(parents); - GIT_ERROR_CHECK_ALLOC(id); - - if ((error = git_parse_advance_expected(&parser, " ", 1)) < 0 || - (error = git_parse_advance_oid(id, &parser, grafts->oid_type)) < 0) { - git_error_set(GIT_ERROR_GRAFTS, "invalid parent OID at line %" PRIuZ, parser.line_num); - goto error; - } - } - - if ((error = git_grafts_add(grafts, &graft_oid, parents)) < 0) - goto error; - - git_array_clear(parents); - } - -error: - git_array_clear(parents); - return error; -} - -int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents) -{ - git_commit_graft *graft; - git_oid *parent_oid; - int error; - size_t i; - - GIT_ASSERT_ARG(grafts && oid); - - graft = git__calloc(1, sizeof(*graft)); - GIT_ERROR_CHECK_ALLOC(graft); - - git_array_init_to_size(graft->parents, git_array_size(parents)); - git_array_foreach(parents, i, parent_oid) { - git_oid *id = git_array_alloc(graft->parents); - GIT_ERROR_CHECK_ALLOC(id); - - git_oid_cpy(id, parent_oid); - } - git_oid_cpy(&graft->oid, oid); - - if ((error = git_grafts_remove(grafts, &graft->oid)) < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - if ((error = git_grafts_oidmap_put(&grafts->commits, &graft->oid, graft)) < 0) - goto cleanup; - - return 0; - -cleanup: - git_array_clear(graft->parents); - git__free(graft); - return error; -} - -int git_grafts_remove(git_grafts *grafts, const git_oid *oid) -{ - git_commit_graft *graft; - int error; - - GIT_ASSERT_ARG(grafts && oid); - - if (git_grafts_oidmap_get(&graft, &grafts->commits, oid) != 0) - return GIT_ENOTFOUND; - - if ((error = git_grafts_oidmap_remove(&grafts->commits, oid)) < 0) - return error; - - git__free(graft->parents.ptr); - git__free(graft); - - return 0; -} - -int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid) -{ - GIT_ASSERT_ARG(out && grafts && oid); - return git_grafts_oidmap_get(out, &grafts->commits, oid); -} - -int git_grafts_oids(git_oid **out, size_t *out_len, git_grafts *grafts) -{ - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - git_array_oid_t array = GIT_ARRAY_INIT; - const git_oid *oid; - size_t existing; - - GIT_ASSERT_ARG(out && grafts); - - if ((existing = git_grafts_oidmap_size(&grafts->commits)) > 0) - git_array_init_to_size(array, existing); - - while (git_grafts_oidmap_iterate(&iter, &oid, NULL, &grafts->commits) == 0) { - git_oid *cpy = git_array_alloc(array); - GIT_ERROR_CHECK_ALLOC(cpy); - git_oid_cpy(cpy, oid); - } - - *out = array.ptr; - *out_len = array.size; - - return 0; -} - -size_t git_grafts_size(git_grafts *grafts) -{ - return git_grafts_oidmap_size(&grafts->commits); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/grafts.h b/vendor/libgit2-sys/libgit2/src/libgit2/grafts.h deleted file mode 100644 index ab59f56..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/grafts.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_graft_h__ -#define INCLUDE_graft_h__ - -#include "common.h" -#include "oidarray.h" - -/** graft commit */ -typedef struct { - git_oid oid; - git_array_oid_t parents; -} git_commit_graft; - -typedef struct git_grafts git_grafts; - -int git_grafts_new(git_grafts **out, git_oid_t oid_type); -int git_grafts_open(git_grafts **out, const char *path, git_oid_t oid_type); -int git_grafts_open_or_refresh(git_grafts **out, const char *path, git_oid_t oid_type); -void git_grafts_free(git_grafts *grafts); -void git_grafts_clear(git_grafts *grafts); - -int git_grafts_refresh(git_grafts *grafts); -int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len); -int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents); -int git_grafts_remove(git_grafts *grafts, const git_oid *oid); -int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid); -int git_grafts_oids(git_oid **out, size_t *out_len, git_grafts *grafts); -size_t git_grafts_size(git_grafts *grafts); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/graph.c b/vendor/libgit2-sys/libgit2/src/libgit2/graph.c deleted file mode 100644 index 3cce7fd..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/graph.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "revwalk.h" -#include "merge.h" -#include "git2/graph.h" - -static int interesting(git_pqueue *list, git_commit_list *roots) -{ - unsigned int i; - - for (i = 0; i < git_pqueue_size(list); i++) { - git_commit_list_node *commit = git_pqueue_get(list, i); - if ((commit->flags & STALE) == 0) - return 1; - } - - while(roots) { - if ((roots->item->flags & STALE) == 0) - return 1; - roots = roots->next; - } - - return 0; -} - -static int mark_parents(git_revwalk *walk, git_commit_list_node *one, - git_commit_list_node *two) -{ - unsigned int i; - git_commit_list *roots = NULL; - git_pqueue list; - - /* if the commit is repeated, we have a our merge base already */ - if (one == two) { - one->flags |= PARENT1 | PARENT2 | RESULT; - return 0; - } - - if (git_pqueue_init(&list, 0, 2, git_commit_list_generation_cmp) < 0) - return -1; - - if (git_commit_list_parse(walk, one) < 0) - goto on_error; - one->flags |= PARENT1; - if (git_pqueue_insert(&list, one) < 0) - goto on_error; - - if (git_commit_list_parse(walk, two) < 0) - goto on_error; - two->flags |= PARENT2; - if (git_pqueue_insert(&list, two) < 0) - goto on_error; - - /* as long as there are non-STALE commits */ - while (interesting(&list, roots)) { - git_commit_list_node *commit = git_pqueue_pop(&list); - unsigned int flags; - - if (commit == NULL) - break; - - flags = commit->flags & (PARENT1 | PARENT2 | STALE); - if (flags == (PARENT1 | PARENT2)) { - if (!(commit->flags & RESULT)) - commit->flags |= RESULT; - /* we mark the parents of a merge stale */ - flags |= STALE; - } - - for (i = 0; i < commit->out_degree; i++) { - git_commit_list_node *p = commit->parents[i]; - if ((p->flags & flags) == flags) - continue; - - if (git_commit_list_parse(walk, p) < 0) - goto on_error; - - p->flags |= flags; - if (git_pqueue_insert(&list, p) < 0) - goto on_error; - } - - /* Keep track of root commits, to make sure the path gets marked */ - if (commit->out_degree == 0) { - if (git_commit_list_insert(commit, &roots) == NULL) - goto on_error; - } - } - - git_commit_list_free(&roots); - git_pqueue_free(&list); - return 0; - -on_error: - git_commit_list_free(&roots); - git_pqueue_free(&list); - return -1; -} - - -static int ahead_behind(git_commit_list_node *one, git_commit_list_node *two, - size_t *ahead, size_t *behind) -{ - git_commit_list_node *commit; - git_pqueue pq; - int error = 0, i; - *ahead = 0; - *behind = 0; - - if (git_pqueue_init(&pq, 0, 2, git_commit_list_time_cmp) < 0) - return -1; - - if ((error = git_pqueue_insert(&pq, one)) < 0 || - (error = git_pqueue_insert(&pq, two)) < 0) - goto done; - - while ((commit = git_pqueue_pop(&pq)) != NULL) { - if (commit->flags & RESULT || - (commit->flags & (PARENT1 | PARENT2)) == (PARENT1 | PARENT2)) - continue; - else if (commit->flags & PARENT1) - (*ahead)++; - else if (commit->flags & PARENT2) - (*behind)++; - - for (i = 0; i < commit->out_degree; i++) { - git_commit_list_node *p = commit->parents[i]; - if ((error = git_pqueue_insert(&pq, p)) < 0) - goto done; - } - commit->flags |= RESULT; - } - -done: - git_pqueue_free(&pq); - return error; -} - -int git_graph_ahead_behind(size_t *ahead, size_t *behind, git_repository *repo, - const git_oid *local, const git_oid *upstream) -{ - git_revwalk *walk; - git_commit_list_node *commit_u, *commit_l; - - if (git_revwalk_new(&walk, repo) < 0) - return -1; - - commit_u = git_revwalk__commit_lookup(walk, upstream); - if (commit_u == NULL) - goto on_error; - - commit_l = git_revwalk__commit_lookup(walk, local); - if (commit_l == NULL) - goto on_error; - - if (mark_parents(walk, commit_l, commit_u) < 0) - goto on_error; - if (ahead_behind(commit_l, commit_u, ahead, behind) < 0) - goto on_error; - - git_revwalk_free(walk); - - return 0; - -on_error: - git_revwalk_free(walk); - return -1; -} - -int git_graph_descendant_of(git_repository *repo, const git_oid *commit, const git_oid *ancestor) -{ - if (git_oid_equal(commit, ancestor)) - return 0; - - return git_graph_reachable_from_any(repo, ancestor, commit, 1); -} - -int git_graph_reachable_from_any( - git_repository *repo, - const git_oid *commit_id, - const git_oid descendant_array[], - size_t length) -{ - git_revwalk *walk = NULL; - git_vector list; - git_commit_list *result = NULL; - git_commit_list_node *commit; - size_t i; - uint32_t minimum_generation = 0xffffffff; - int error = 0; - - if (!length) - return 0; - - for (i = 0; i < length; ++i) { - if (git_oid_equal(commit_id, &descendant_array[i])) - return 1; - } - - if ((error = git_vector_init(&list, length + 1, NULL)) < 0) - return error; - - if ((error = git_revwalk_new(&walk, repo)) < 0) - goto done; - - for (i = 0; i < length; i++) { - commit = git_revwalk__commit_lookup(walk, &descendant_array[i]); - if (commit == NULL) { - error = -1; - goto done; - } - - git_vector_insert(&list, commit); - if (minimum_generation > commit->generation) - minimum_generation = commit->generation; - } - - commit = git_revwalk__commit_lookup(walk, commit_id); - if (commit == NULL) { - error = -1; - goto done; - } - - if (minimum_generation > commit->generation) - minimum_generation = commit->generation; - - if ((error = git_merge__bases_many(&result, walk, commit, &list, minimum_generation)) < 0) - goto done; - - if (result) { - error = git_oid_equal(commit_id, &result->item->oid); - } else { - /* No merge-base found, it's not a descendant */ - error = 0; - } - -done: - git_commit_list_free(&result); - git_vector_dispose(&list); - git_revwalk_free(walk); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/hashmap_oid.h b/vendor/libgit2-sys/libgit2/src/libgit2/hashmap_oid.h deleted file mode 100644 index cb1143c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/hashmap_oid.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_hashmap_oid_h__ -#define INCLUDE_hashmap_oid_h__ - -#include "hashmap.h" - -GIT_INLINE(uint32_t) git_hashmap_oid_hashcode(const git_oid *oid) -{ - uint32_t hash; - memcpy(&hash, oid->id, sizeof(uint32_t)); - return hash; -} - -#define GIT_HASHMAP_OID_STRUCT(name, val_t) \ - GIT_HASHMAP_STRUCT(name, const git_oid *, val_t) -#define GIT_HASHMAP_OID_PROTOTYPES(name, val_t) \ - GIT_HASHMAP_PROTOTYPES(name, const git_oid *, val_t) -#define GIT_HASHMAP_OID_FUNCTIONS(name, scope, val_t) \ - GIT_HASHMAP_FUNCTIONS(name, scope, const git_oid *, val_t, git_hashmap_oid_hashcode, git_oid_equal) - -#define GIT_HASHMAP_OID_SETUP(name, val_t) \ - GIT_HASHMAP_OID_STRUCT(name, val_t) \ - GIT_HASHMAP_OID_FUNCTIONS(name, GIT_HASHMAP_INLINE, val_t) - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/hashsig.c b/vendor/libgit2-sys/libgit2/src/libgit2/hashsig.c deleted file mode 100644 index 6b4fb83..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/hashsig.c +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/sys/hashsig.h" -#include "futils.h" -#include "util.h" - -typedef uint32_t hashsig_t; -typedef uint64_t hashsig_state; - -#define HASHSIG_SCALE 100 - -#define HASHSIG_MAX_RUN 80 -#define HASHSIG_HASH_START INT64_C(0x012345678ABCDEF0) -#define HASHSIG_HASH_SHIFT 5 - -#define HASHSIG_HASH_MIX(S,CH) \ - (S) = ((S) << HASHSIG_HASH_SHIFT) - (S) + (hashsig_state)(CH) - -#define HASHSIG_HEAP_SIZE ((1 << 7) - 1) -#define HASHSIG_HEAP_MIN_SIZE 4 - -typedef int (*hashsig_cmp)(const void *a, const void *b, void *); - -typedef struct { - int size, asize; - hashsig_cmp cmp; - hashsig_t values[HASHSIG_HEAP_SIZE]; -} hashsig_heap; - -struct git_hashsig { - hashsig_heap mins; - hashsig_heap maxs; - size_t lines; - git_hashsig_option_t opt; -}; - -#define HEAP_LCHILD_OF(I) (((I)<<1)+1) -#define HEAP_RCHILD_OF(I) (((I)<<1)+2) -#define HEAP_PARENT_OF(I) (((I)-1)>>1) - -static void hashsig_heap_init(hashsig_heap *h, hashsig_cmp cmp) -{ - h->size = 0; - h->asize = HASHSIG_HEAP_SIZE; - h->cmp = cmp; -} - -static int hashsig_cmp_max(const void *a, const void *b, void *payload) -{ - hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b; - GIT_UNUSED(payload); - return (av < bv) ? -1 : (av > bv) ? 1 : 0; -} - -static int hashsig_cmp_min(const void *a, const void *b, void *payload) -{ - hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b; - GIT_UNUSED(payload); - return (av > bv) ? -1 : (av < bv) ? 1 : 0; -} - -static void hashsig_heap_up(hashsig_heap *h, int el) -{ - int parent_el = HEAP_PARENT_OF(el); - - while (el > 0 && h->cmp(&h->values[parent_el], &h->values[el], NULL) > 0) { - hashsig_t t = h->values[el]; - h->values[el] = h->values[parent_el]; - h->values[parent_el] = t; - - el = parent_el; - parent_el = HEAP_PARENT_OF(el); - } -} - -static void hashsig_heap_down(hashsig_heap *h, int el) -{ - hashsig_t v, lv, rv; - - /* 'el < h->size / 2' tests if el is bottom row of heap */ - - while (el < h->size / 2) { - int lel = HEAP_LCHILD_OF(el), rel = HEAP_RCHILD_OF(el), swapel; - - v = h->values[el]; - lv = h->values[lel]; - rv = h->values[rel]; - - if (h->cmp(&v, &lv, NULL) < 0 && h->cmp(&v, &rv, NULL) < 0) - break; - - swapel = (h->cmp(&lv, &rv, NULL) < 0) ? lel : rel; - - h->values[el] = h->values[swapel]; - h->values[swapel] = v; - - el = swapel; - } -} - -static void hashsig_heap_sort(hashsig_heap *h) -{ - /* only need to do this at the end for signature comparison */ - git__qsort_r(h->values, h->size, sizeof(hashsig_t), h->cmp, NULL); -} - -static void hashsig_heap_insert(hashsig_heap *h, hashsig_t val) -{ - /* if heap is not full, insert new element */ - if (h->size < h->asize) { - h->values[h->size++] = val; - hashsig_heap_up(h, h->size - 1); - } - - /* if heap is full, pop top if new element should replace it */ - else if (h->cmp(&val, &h->values[0], NULL) > 0) { - h->size--; - h->values[0] = h->values[h->size]; - hashsig_heap_down(h, 0); - } - -} - -typedef struct { - int use_ignores; - uint8_t ignore_ch[256]; -} hashsig_in_progress; - -static int hashsig_in_progress_init( - hashsig_in_progress *prog, git_hashsig *sig) -{ - int i; - - /* no more than one can be set */ - GIT_ASSERT(!(sig->opt & GIT_HASHSIG_IGNORE_WHITESPACE) || - !(sig->opt & GIT_HASHSIG_SMART_WHITESPACE)); - - if (sig->opt & GIT_HASHSIG_IGNORE_WHITESPACE) { - for (i = 0; i < 256; ++i) - prog->ignore_ch[i] = git__isspace_nonlf(i); - prog->use_ignores = 1; - } else if (sig->opt & GIT_HASHSIG_SMART_WHITESPACE) { - for (i = 0; i < 256; ++i) - prog->ignore_ch[i] = git__isspace(i); - prog->use_ignores = 1; - } else { - memset(prog, 0, sizeof(*prog)); - } - - return 0; -} - -static int hashsig_add_hashes( - git_hashsig *sig, - const uint8_t *data, - size_t size, - hashsig_in_progress *prog) -{ - const uint8_t *scan = data, *end = data + size; - hashsig_state state = HASHSIG_HASH_START; - int use_ignores = prog->use_ignores, len; - uint8_t ch; - - while (scan < end) { - state = HASHSIG_HASH_START; - - for (len = 0; scan < end && len < HASHSIG_MAX_RUN; ) { - ch = *scan; - - if (use_ignores) - for (; scan < end && git__isspace_nonlf(ch); ch = *scan) - ++scan; - else if (sig->opt & - (GIT_HASHSIG_IGNORE_WHITESPACE | GIT_HASHSIG_SMART_WHITESPACE)) - for (; scan < end && ch == '\r'; ch = *scan) - ++scan; - - /* peek at next character to decide what to do next */ - if (sig->opt & GIT_HASHSIG_SMART_WHITESPACE) - use_ignores = (ch == '\n'); - - if (scan >= end) - break; - ++scan; - - /* check run terminator */ - if (ch == '\n' || ch == '\0') { - sig->lines++; - break; - } - - ++len; - HASHSIG_HASH_MIX(state, ch); - } - - if (len > 0) { - hashsig_heap_insert(&sig->mins, (hashsig_t)state); - hashsig_heap_insert(&sig->maxs, (hashsig_t)state); - - while (scan < end && (*scan == '\n' || !*scan)) - ++scan; - } - } - - prog->use_ignores = use_ignores; - - return 0; -} - -static int hashsig_finalize_hashes(git_hashsig *sig) -{ - if (sig->mins.size < HASHSIG_HEAP_MIN_SIZE && - !(sig->opt & GIT_HASHSIG_ALLOW_SMALL_FILES)) { - git_error_set(GIT_ERROR_INVALID, - "file too small for similarity signature calculation"); - return GIT_EBUFS; - } - - hashsig_heap_sort(&sig->mins); - hashsig_heap_sort(&sig->maxs); - - return 0; -} - -static git_hashsig *hashsig_alloc(git_hashsig_option_t opts) -{ - git_hashsig *sig = git__calloc(1, sizeof(git_hashsig)); - if (!sig) - return NULL; - - hashsig_heap_init(&sig->mins, hashsig_cmp_min); - hashsig_heap_init(&sig->maxs, hashsig_cmp_max); - sig->opt = opts; - - return sig; -} - -int git_hashsig_create( - git_hashsig **out, - const char *buf, - size_t buflen, - git_hashsig_option_t opts) -{ - int error; - hashsig_in_progress prog; - git_hashsig *sig = hashsig_alloc(opts); - GIT_ERROR_CHECK_ALLOC(sig); - - if ((error = hashsig_in_progress_init(&prog, sig)) < 0) - return error; - - error = hashsig_add_hashes(sig, (const uint8_t *)buf, buflen, &prog); - - if (!error) - error = hashsig_finalize_hashes(sig); - - if (!error) - *out = sig; - else - git_hashsig_free(sig); - - return error; -} - -int git_hashsig_create_fromfile( - git_hashsig **out, - const char *path, - git_hashsig_option_t opts) -{ - uint8_t buf[0x1000]; - ssize_t buflen = 0; - int error = 0, fd; - hashsig_in_progress prog; - git_hashsig *sig = hashsig_alloc(opts); - GIT_ERROR_CHECK_ALLOC(sig); - - if ((fd = git_futils_open_ro(path)) < 0) { - git__free(sig); - return fd; - } - - if ((error = hashsig_in_progress_init(&prog, sig)) < 0) { - p_close(fd); - return error; - } - - while (!error) { - if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) { - if ((error = (int)buflen) < 0) - git_error_set(GIT_ERROR_OS, - "read error on '%s' calculating similarity hashes", path); - break; - } - - error = hashsig_add_hashes(sig, buf, buflen, &prog); - } - - p_close(fd); - - if (!error) - error = hashsig_finalize_hashes(sig); - - if (!error) - *out = sig; - else - git_hashsig_free(sig); - - return error; -} - -void git_hashsig_free(git_hashsig *sig) -{ - git__free(sig); -} - -static int hashsig_heap_compare(const hashsig_heap *a, const hashsig_heap *b) -{ - int matches = 0, i, j, cmp; - - GIT_ASSERT_WITH_RETVAL(a->cmp == b->cmp, 0); - - /* hash heaps are sorted - just look for overlap vs total */ - - for (i = 0, j = 0; i < a->size && j < b->size; ) { - cmp = a->cmp(&a->values[i], &b->values[j], NULL); - - if (cmp < 0) - ++i; - else if (cmp > 0) - ++j; - else { - ++i; ++j; ++matches; - } - } - - return HASHSIG_SCALE * (matches * 2) / (a->size + b->size); -} - -int git_hashsig_compare(const git_hashsig *a, const git_hashsig *b) -{ - /* if we have no elements in either file then each file is either - * empty or blank. if we're ignoring whitespace then the files are - * similar, otherwise they're dissimilar. - */ - if (a->mins.size == 0 && b->mins.size == 0) { - if ((!a->lines && !b->lines) || - (a->opt & GIT_HASHSIG_IGNORE_WHITESPACE)) - return HASHSIG_SCALE; - else - return 0; - } - - /* if we have fewer than the maximum number of elements, then just use - * one array since the two arrays will be the same - */ - if (a->mins.size < HASHSIG_HEAP_SIZE) { - return hashsig_heap_compare(&a->mins, &b->mins); - } else { - int mins, maxs; - - if ((mins = hashsig_heap_compare(&a->mins, &b->mins)) < 0) - return mins; - if ((maxs = hashsig_heap_compare(&a->maxs, &b->maxs)) < 0) - return maxs; - - return (mins + maxs) / 2; - } -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/ident.c b/vendor/libgit2-sys/libgit2/src/libgit2/ident.c deleted file mode 100644 index 97110c6..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/ident.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/sys/filter.h" -#include "filter.h" -#include "str.h" - -static int ident_find_id( - const char **id_start, const char **id_end, const char *start, size_t len) -{ - const char *end = start + len, *found = NULL; - - while (len > 3 && (found = memchr(start, '$', len)) != NULL) { - size_t remaining = (size_t)(end - found) - 1; - if (remaining < 3) - return GIT_ENOTFOUND; - - start = found + 1; - len = remaining; - - if (start[0] == 'I' && start[1] == 'd') - break; - } - - if (len < 3 || !found) - return GIT_ENOTFOUND; - *id_start = found; - - if ((found = memchr(start + 2, '$', len - 2)) == NULL) - return GIT_ENOTFOUND; - - *id_end = found + 1; - return 0; -} - -static int ident_insert_id( - git_str *to, const git_str *from, const git_filter_source *src) -{ - char oid[GIT_OID_MAX_HEXSIZE + 1]; - const char *id_start, *id_end, *from_end = from->ptr + from->size; - size_t need_size; - - /* replace $Id$ with blob id */ - - if (!git_filter_source_id(src)) - return GIT_PASSTHROUGH; - - git_oid_tostr(oid, sizeof(oid), git_filter_source_id(src)); - - if (ident_find_id(&id_start, &id_end, from->ptr, from->size) < 0) - return GIT_PASSTHROUGH; - - need_size = (size_t)(id_start - from->ptr) + - 5 /* "$Id: " */ + GIT_OID_MAX_HEXSIZE + 2 /* " $" */ + - (size_t)(from_end - id_end); - - if (git_str_grow(to, need_size) < 0) - return -1; - - git_str_set(to, from->ptr, (size_t)(id_start - from->ptr)); - git_str_put(to, "$Id: ", 5); - git_str_puts(to, oid); - git_str_put(to, " $", 2); - git_str_put(to, id_end, (size_t)(from_end - id_end)); - - return git_str_oom(to) ? -1 : 0; -} - -static int ident_remove_id( - git_str *to, const git_str *from) -{ - const char *id_start, *id_end, *from_end = from->ptr + from->size; - size_t need_size; - - if (ident_find_id(&id_start, &id_end, from->ptr, from->size) < 0) - return GIT_PASSTHROUGH; - - need_size = (size_t)(id_start - from->ptr) + - 4 /* "$Id$" */ + (size_t)(from_end - id_end); - - if (git_str_grow(to, need_size) < 0) - return -1; - - git_str_set(to, from->ptr, (size_t)(id_start - from->ptr)); - git_str_put(to, "$Id$", 4); - git_str_put(to, id_end, (size_t)(from_end - id_end)); - - return git_str_oom(to) ? -1 : 0; -} - -static int ident_apply( - git_filter *self, - void **payload, - git_str *to, - const git_str *from, - const git_filter_source *src) -{ - GIT_UNUSED(self); GIT_UNUSED(payload); - - /* Don't filter binary files */ - if (git_str_is_binary(from)) - return GIT_PASSTHROUGH; - - if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE) - return ident_insert_id(to, from, src); - else - return ident_remove_id(to, from); -} - -static int ident_stream( - git_writestream **out, - git_filter *self, - void **payload, - const git_filter_source *src, - git_writestream *next) -{ - return git_filter_buffered_stream_new(out, - self, ident_apply, NULL, payload, src, next); -} - -git_filter *git_ident_filter_new(void) -{ - git_filter *f = git__calloc(1, sizeof(git_filter)); - if (f == NULL) - return NULL; - - f->version = GIT_FILTER_VERSION; - f->attributes = "+ident"; /* apply to files with ident attribute set */ - f->shutdown = git_filter_free; - f->stream = ident_stream; - - return f; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/ignore.c b/vendor/libgit2-sys/libgit2/src/libgit2/ignore.c deleted file mode 100644 index 13a6734..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/ignore.c +++ /dev/null @@ -1,656 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "ignore.h" - -#include "git2/ignore.h" -#include "common.h" -#include "attrcache.h" -#include "fs_path.h" -#include "config.h" -#include "wildmatch.h" -#include "path.h" - -#define GIT_IGNORE_INTERNAL "[internal]exclude" - -#define GIT_IGNORE_DEFAULT_RULES ".\n..\n.git\n" - -/** - * A negative ignore pattern can negate a positive one without - * wildcards if it is a basename only and equals the basename of - * the positive pattern. Thus - * - * foo/bar - * !bar - * - * would result in foo/bar being unignored again while - * - * moo/foo/bar - * !foo/bar - * - * would do nothing. The reverse also holds true: a positive - * basename pattern can be negated by unignoring the basename in - * subdirectories. Thus - * - * bar - * !foo/bar - * - * would result in foo/bar being unignored again. As with the - * first case, - * - * foo/bar - * !moo/foo/bar - * - * would do nothing, again. - */ -static int does_negate_pattern(git_attr_fnmatch *rule, git_attr_fnmatch *neg) -{ - int (*cmp)(const char *, const char *, size_t); - git_attr_fnmatch *longer, *shorter; - char *p; - - if ((rule->flags & GIT_ATTR_FNMATCH_NEGATIVE) != 0 - || (neg->flags & GIT_ATTR_FNMATCH_NEGATIVE) == 0) - return false; - - if (neg->flags & GIT_ATTR_FNMATCH_ICASE) - cmp = git__strncasecmp; - else - cmp = git__strncmp; - - /* If lengths match we need to have an exact match */ - if (rule->length == neg->length) { - return cmp(rule->pattern, neg->pattern, rule->length) == 0; - } else if (rule->length < neg->length) { - shorter = rule; - longer = neg; - } else { - shorter = neg; - longer = rule; - } - - /* Otherwise, we need to check if the shorter - * rule is a basename only (that is, it contains - * no path separator) and, if so, if it - * matches the tail of the longer rule */ - p = longer->pattern + longer->length - shorter->length; - - if (p[-1] != '/') - return false; - if (memchr(shorter->pattern, '/', shorter->length) != NULL) - return false; - - return cmp(p, shorter->pattern, shorter->length) == 0; -} - -/** - * A negative ignore can only unignore a file which is given explicitly before, thus - * - * foo - * !foo/bar - * - * does not unignore 'foo/bar' as it's not in the list. However - * - * foo/ - * !foo/bar - * - * does unignore 'foo/bar', as it is contained within the 'foo/' rule. - */ -static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match) -{ - int error = 0, wildmatch_flags, effective_flags; - size_t i; - git_attr_fnmatch *rule; - char *path; - git_str buf = GIT_STR_INIT; - - *out = 0; - - wildmatch_flags = WM_PATHNAME; - if (match->flags & GIT_ATTR_FNMATCH_ICASE) - wildmatch_flags |= WM_CASEFOLD; - - /* path of the file relative to the workdir, so we match the rules in subdirs */ - if (match->containing_dir) { - git_str_puts(&buf, match->containing_dir); - } - if (git_str_puts(&buf, match->pattern) < 0) - return -1; - - path = git_str_detach(&buf); - - git_vector_foreach(rules, i, rule) { - if (!(rule->flags & GIT_ATTR_FNMATCH_HASWILD)) { - if (does_negate_pattern(rule, match)) { - error = 0; - *out = 1; - goto out; - } - else - continue; - } - - git_str_clear(&buf); - if (rule->containing_dir) - git_str_puts(&buf, rule->containing_dir); - git_str_puts(&buf, rule->pattern); - - if (git_str_oom(&buf)) - goto out; - - /* - * if rule isn't for full path we match without PATHNAME flag - * as lines like *.txt should match something like dir/test.txt - * requiring * to also match / - */ - effective_flags = wildmatch_flags; - if (!(rule->flags & GIT_ATTR_FNMATCH_FULLPATH)) - effective_flags &= ~WM_PATHNAME; - - /* if we found a match, we want to keep this rule */ - if ((wildmatch(git_str_cstr(&buf), path, effective_flags)) == WM_MATCH) { - *out = 1; - error = 0; - goto out; - } - } - - error = 0; - -out: - git__free(path); - git_str_dispose(&buf); - return error; -} - -static int parse_ignore_file( - git_repository *repo, git_attr_file *attrs, const char *data, bool allow_macros) -{ - int error = 0; - int ignore_case = false; - const char *scan = data, *context = NULL; - git_attr_fnmatch *match = NULL; - - GIT_UNUSED(allow_macros); - - if (git_repository__configmap_lookup(&ignore_case, repo, GIT_CONFIGMAP_IGNORECASE) < 0) - git_error_clear(); - - /* if subdir file path, convert context for file paths */ - if (attrs->entry && - git_fs_path_root(attrs->entry->path) < 0 && - !git__suffixcmp(attrs->entry->path, "/" GIT_IGNORE_FILE)) - context = attrs->entry->path; - - if (git_mutex_lock(&attrs->lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock ignore file"); - return -1; - } - - while (!error && *scan) { - int valid_rule = 1; - - if (!match && !(match = git__calloc(1, sizeof(*match)))) { - error = -1; - break; - } - - match->flags = - GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG; - - if (!(error = git_attr_fnmatch__parse( - match, &attrs->pool, context, &scan))) - { - match->flags |= GIT_ATTR_FNMATCH_IGNORE; - - if (ignore_case) - match->flags |= GIT_ATTR_FNMATCH_ICASE; - - scan = git__next_line(scan); - - /* - * If a negative match doesn't actually do anything, - * throw it away. As we cannot always verify whether a - * rule containing wildcards negates another rule, we - * do not optimize away these rules, though. - * */ - if (match->flags & GIT_ATTR_FNMATCH_NEGATIVE - && !(match->flags & GIT_ATTR_FNMATCH_HASWILD)) - error = does_negate_rule(&valid_rule, &attrs->rules, match); - - if (!error && valid_rule) - error = git_vector_insert(&attrs->rules, match); - } - - if (error != 0 || !valid_rule) { - match->pattern = NULL; - - if (error == GIT_ENOTFOUND) - error = 0; - } else { - match = NULL; /* vector now "owns" the match */ - } - } - - git_mutex_unlock(&attrs->lock); - git__free(match); - - return error; -} - -static int push_ignore_file( - git_ignores *ignores, - git_vector *which_list, - const char *base, - const char *filename) -{ - git_attr_file_source source = { GIT_ATTR_FILE_SOURCE_FILE, base, filename }; - git_attr_file *file = NULL; - int error = 0; - - error = git_attr_cache__get(&file, ignores->repo, NULL, &source, parse_ignore_file, false); - - if (error < 0) - return error; - - if (file != NULL) { - if ((error = git_vector_insert(which_list, file)) < 0) - git_attr_file__free(file); - } - - return error; -} - -static int push_one_ignore(void *payload, const char *path) -{ - git_ignores *ign = payload; - ign->depth++; - return push_ignore_file(ign, &ign->ign_path, path, GIT_IGNORE_FILE); -} - -static int get_internal_ignores(git_attr_file **out, git_repository *repo) -{ - git_attr_file_source source = { GIT_ATTR_FILE_SOURCE_MEMORY, NULL, GIT_IGNORE_INTERNAL }; - int error; - - if ((error = git_attr_cache__init(repo)) < 0) - return error; - - error = git_attr_cache__get(out, repo, NULL, &source, NULL, false); - - /* if internal rules list is empty, insert default rules */ - if (!error && !(*out)->rules.length) - error = parse_ignore_file(repo, *out, GIT_IGNORE_DEFAULT_RULES, false); - - return error; -} - -int git_ignore__for_path( - git_repository *repo, - const char *path, - git_ignores *ignores) -{ - int error = 0; - const char *workdir = git_repository_workdir(repo); - git_attr_cache *attrcache; - const char *excludes_file = NULL; - git_str infopath = GIT_STR_INIT; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(ignores); - GIT_ASSERT_ARG(path); - - memset(ignores, 0, sizeof(*ignores)); - ignores->repo = repo; - - /* Read the ignore_case flag */ - if ((error = git_repository__configmap_lookup( - &ignores->ignore_case, repo, GIT_CONFIGMAP_IGNORECASE)) < 0) - goto cleanup; - - if ((error = git_attr_cache__init(repo)) < 0) - goto cleanup; - - /* given a unrooted path in a non-bare repo, resolve it */ - if (workdir && git_fs_path_root(path) < 0) { - git_str local = GIT_STR_INIT; - - if ((error = git_fs_path_dirname_r(&local, path)) < 0 || - (error = git_fs_path_resolve_relative(&local, 0)) < 0 || - (error = git_fs_path_to_dir(&local)) < 0 || - (error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 || - (error = git_path_validate_str_length(repo, &ignores->dir)) < 0) { - /* Nothing, we just want to stop on the first error */ - } - - git_str_dispose(&local); - } else { - if (!(error = git_str_joinpath(&ignores->dir, path, ""))) - error = git_path_validate_str_length(NULL, &ignores->dir); - } - - if (error < 0) - goto cleanup; - - if (workdir && !git__prefixcmp(ignores->dir.ptr, workdir)) - ignores->dir_root = strlen(workdir); - - /* set up internals */ - if ((error = get_internal_ignores(&ignores->ign_internal, repo)) < 0) - goto cleanup; - - /* load .gitignore up the path */ - if (workdir != NULL) { - error = git_fs_path_walk_up( - &ignores->dir, workdir, push_one_ignore, ignores); - if (error < 0) - goto cleanup; - } - - /* load .git/info/exclude if possible */ - if ((error = git_repository__item_path(&infopath, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || - (error = push_ignore_file(ignores, &ignores->ign_global, infopath.ptr, GIT_IGNORE_FILE_INREPO)) < 0) { - if (error != GIT_ENOTFOUND) - goto cleanup; - error = 0; - } - - /* load core.excludesfile */ - attrcache = git_repository_attr_cache(repo); - excludes_file = git_attr_cache_excludesfile(attrcache); - - if (excludes_file != NULL) - error = push_ignore_file( - ignores, &ignores->ign_global, NULL, excludes_file); - -cleanup: - git_str_dispose(&infopath); - if (error < 0) - git_ignore__free(ignores); - - return error; -} - -int git_ignore__push_dir(git_ignores *ign, const char *dir) -{ - if (git_str_joinpath(&ign->dir, ign->dir.ptr, dir) < 0) - return -1; - - ign->depth++; - - return push_ignore_file( - ign, &ign->ign_path, ign->dir.ptr, GIT_IGNORE_FILE); -} - -int git_ignore__pop_dir(git_ignores *ign) -{ - if (ign->ign_path.length > 0) { - git_attr_file *file = git_vector_last(&ign->ign_path); - const char *start = file->entry->path, *end; - - /* - ign->dir looks something like "/home/user/a/b/" (or "a/b/c/d/") - * - file->path looks something like "a/b/.gitignore - * - * We are popping the last directory off ign->dir. We also want - * to remove the file from the vector if the popped directory - * matches the ignore path. We need to test if the "a/b" part of - * the file key matches the path we are about to pop. - */ - - if ((end = strrchr(start, '/')) != NULL) { - size_t dirlen = (end - start) + 1; - const char *relpath = ign->dir.ptr + ign->dir_root; - size_t pathlen = ign->dir.size - ign->dir_root; - - if (pathlen == dirlen && !memcmp(relpath, start, dirlen)) { - git_vector_pop(&ign->ign_path); - git_attr_file__free(file); - } - } - } - - if (--ign->depth > 0) { - git_str_rtruncate_at_char(&ign->dir, '/'); - git_fs_path_to_dir(&ign->dir); - } - - return 0; -} - -void git_ignore__free(git_ignores *ignores) -{ - unsigned int i; - git_attr_file *file; - - git_attr_file__free(ignores->ign_internal); - - git_vector_foreach(&ignores->ign_path, i, file) { - git_attr_file__free(file); - ignores->ign_path.contents[i] = NULL; - } - git_vector_dispose(&ignores->ign_path); - - git_vector_foreach(&ignores->ign_global, i, file) { - git_attr_file__free(file); - ignores->ign_global.contents[i] = NULL; - } - git_vector_dispose(&ignores->ign_global); - - git_str_dispose(&ignores->dir); -} - -static bool ignore_lookup_in_rules( - int *ignored, git_attr_file *file, git_attr_path *path) -{ - size_t j; - git_attr_fnmatch *match; - - git_vector_rforeach(&file->rules, j, match) { - if (match->flags & GIT_ATTR_FNMATCH_DIRECTORY && - path->is_dir == GIT_DIR_FLAG_FALSE) - continue; - if (git_attr_fnmatch__match(match, path)) { - *ignored = ((match->flags & GIT_ATTR_FNMATCH_NEGATIVE) == 0) ? - GIT_IGNORE_TRUE : GIT_IGNORE_FALSE; - return true; - } - } - - return false; -} - -int git_ignore__lookup( - int *out, git_ignores *ignores, const char *pathname, git_dir_flag dir_flag) -{ - size_t i; - git_attr_file *file; - git_attr_path path; - - *out = GIT_IGNORE_NOTFOUND; - - if (git_attr_path__init( - &path, pathname, git_repository_workdir(ignores->repo), dir_flag) < 0) - return -1; - - /* first process builtins - success means path was found */ - if (ignore_lookup_in_rules(out, ignores->ign_internal, &path)) - goto cleanup; - - /* next process files in the path. - * this process has to process ignores in reverse order - * to ensure correct prioritization of rules - */ - git_vector_rforeach(&ignores->ign_path, i, file) { - if (ignore_lookup_in_rules(out, file, &path)) - goto cleanup; - } - - /* last process global ignores */ - git_vector_foreach(&ignores->ign_global, i, file) { - if (ignore_lookup_in_rules(out, file, &path)) - goto cleanup; - } - -cleanup: - git_attr_path__free(&path); - return 0; -} - -int git_ignore_add_rule(git_repository *repo, const char *rules) -{ - int error; - git_attr_file *ign_internal = NULL; - - if ((error = get_internal_ignores(&ign_internal, repo)) < 0) - return error; - - error = parse_ignore_file(repo, ign_internal, rules, false); - git_attr_file__free(ign_internal); - - return error; -} - -int git_ignore_clear_internal_rules(git_repository *repo) -{ - int error; - git_attr_file *ign_internal; - - if ((error = get_internal_ignores(&ign_internal, repo)) < 0) - return error; - - if (!(error = git_attr_file__clear_rules(ign_internal, true))) - error = parse_ignore_file( - repo, ign_internal, GIT_IGNORE_DEFAULT_RULES, false); - - git_attr_file__free(ign_internal); - return error; -} - -int git_ignore_path_is_ignored( - int *ignored, - git_repository *repo, - const char *pathname) -{ - int error; - const char *workdir; - git_attr_path path; - git_ignores ignores; - unsigned int i; - git_attr_file *file; - git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(ignored); - GIT_ASSERT_ARG(pathname); - - workdir = git_repository_workdir(repo); - - memset(&path, 0, sizeof(path)); - memset(&ignores, 0, sizeof(ignores)); - - if (!git__suffixcmp(pathname, "/")) - dir_flag = GIT_DIR_FLAG_TRUE; - else if (git_repository_is_bare(repo)) - dir_flag = GIT_DIR_FLAG_FALSE; - - if ((error = git_attr_path__init(&path, pathname, workdir, dir_flag)) < 0 || - (error = git_ignore__for_path(repo, path.path, &ignores)) < 0) - goto cleanup; - - while (1) { - /* first process builtins - success means path was found */ - if (ignore_lookup_in_rules(ignored, ignores.ign_internal, &path)) - goto cleanup; - - /* next process files in the path */ - git_vector_foreach(&ignores.ign_path, i, file) { - if (ignore_lookup_in_rules(ignored, file, &path)) - goto cleanup; - } - - /* last process global ignores */ - git_vector_foreach(&ignores.ign_global, i, file) { - if (ignore_lookup_in_rules(ignored, file, &path)) - goto cleanup; - } - - /* move up one directory */ - if (path.basename == path.path) - break; - path.basename[-1] = '\0'; - while (path.basename > path.path && *path.basename != '/') - path.basename--; - if (path.basename > path.path) - path.basename++; - path.is_dir = 1; - - if ((error = git_ignore__pop_dir(&ignores)) < 0) - break; - } - - *ignored = 0; - -cleanup: - git_attr_path__free(&path); - git_ignore__free(&ignores); - return error; -} - -int git_ignore__check_pathspec_for_exact_ignores( - git_repository *repo, - git_vector *vspec, - bool no_fnmatch) -{ - int error = 0; - size_t i; - git_attr_fnmatch *match; - int ignored; - git_str path = GIT_STR_INIT; - const char *filename; - git_index *idx; - - if ((error = git_repository__ensure_not_bare( - repo, "validate pathspec")) < 0 || - (error = git_repository_index(&idx, repo)) < 0) - return error; - - git_vector_foreach(vspec, i, match) { - /* skip wildcard matches (if they are being used) */ - if ((match->flags & GIT_ATTR_FNMATCH_HASWILD) != 0 && - !no_fnmatch) - continue; - - filename = match->pattern; - - /* if file is already in the index, it's fine */ - if (git_index_get_bypath(idx, filename, 0) != NULL) - continue; - - if ((error = git_repository_workdir_path(&path, repo, filename)) < 0) - break; - - /* is there a file on disk that matches this exactly? */ - if (!git_fs_path_isfile(path.ptr)) - continue; - - /* is that file ignored? */ - if ((error = git_ignore_path_is_ignored(&ignored, repo, filename)) < 0) - break; - - if (ignored) { - git_error_set(GIT_ERROR_INVALID, "pathspec contains ignored file '%s'", - filename); - error = GIT_EINVALIDSPEC; - break; - } - } - - git_index_free(idx); - git_str_dispose(&path); - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/ignore.h b/vendor/libgit2-sys/libgit2/src/libgit2/ignore.h deleted file mode 100644 index aa5ca62..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/ignore.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_ignore_h__ -#define INCLUDE_ignore_h__ - -#include "common.h" - -#include "repository.h" -#include "vector.h" -#include "attr_file.h" - -#define GIT_IGNORE_FILE ".gitignore" -#define GIT_IGNORE_FILE_INREPO "exclude" -#define GIT_IGNORE_FILE_XDG "ignore" - -/* The git_ignores structure maintains three sets of ignores: - * - internal ignores - * - per directory ignores - * - global ignores (at lower priority than the others) - * As you traverse from one directory to another, you can push and pop - * directories onto git_ignores list efficiently. - */ -typedef struct { - git_repository *repo; - git_str dir; /* current directory reflected in ign_path */ - git_attr_file *ign_internal; - git_vector ign_path; - git_vector ign_global; - size_t dir_root; /* offset in dir to repo root */ - int ignore_case; - int depth; -} git_ignores; - -extern int git_ignore__for_path( - git_repository *repo, const char *path, git_ignores *ign); - -extern int git_ignore__push_dir(git_ignores *ign, const char *dir); - -extern int git_ignore__pop_dir(git_ignores *ign); - -extern void git_ignore__free(git_ignores *ign); - -enum { - GIT_IGNORE_UNCHECKED = -2, - GIT_IGNORE_NOTFOUND = -1, - GIT_IGNORE_FALSE = 0, - GIT_IGNORE_TRUE = 1 -}; - -extern int git_ignore__lookup(int *out, git_ignores *ign, const char *path, git_dir_flag dir_flag); - -/* command line Git sometimes generates an error message if given a - * pathspec that contains an exact match to an ignored file (provided - * --force isn't also given). This makes it easy to check it that has - * happened. Returns GIT_EINVALIDSPEC if the pathspec contains ignored - * exact matches (that are not already present in the index). - */ -extern int git_ignore__check_pathspec_for_exact_ignores( - git_repository *repo, git_vector *pathspec, bool no_fnmatch); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/index.c b/vendor/libgit2-sys/libgit2/src/libgit2/index.c deleted file mode 100644 index 9b0c746..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/index.c +++ /dev/null @@ -1,3950 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "index.h" - -#include - -#include "repository.h" -#include "tree.h" -#include "tree-cache.h" -#include "hash.h" -#include "iterator.h" -#include "pathspec.h" -#include "ignore.h" -#include "blob.h" -#include "diff.h" -#include "varint.h" -#include "path.h" -#include "index_map.h" - -#include "git2/odb.h" -#include "git2/oid.h" -#include "git2/blob.h" -#include "git2/config.h" -#include "git2/sys/index.h" - -static int index_apply_to_wd_diff(git_index *index, int action, const git_strarray *paths, - unsigned int flags, - git_index_matched_path_cb cb, void *payload); - -static const size_t INDEX_HEADER_SIZE = 12; - -static const unsigned int INDEX_VERSION_NUMBER_DEFAULT = 2; -static const unsigned int INDEX_VERSION_NUMBER_LB = 2; -static const unsigned int INDEX_VERSION_NUMBER_EXT = 3; -static const unsigned int INDEX_VERSION_NUMBER_COMP = 4; -static const unsigned int INDEX_VERSION_NUMBER_UB = 4; - -static const unsigned int INDEX_HEADER_SIG = 0x44495243; -static const char INDEX_EXT_TREECACHE_SIG[] = {'T', 'R', 'E', 'E'}; -static const char INDEX_EXT_UNMERGED_SIG[] = {'R', 'E', 'U', 'C'}; -static const char INDEX_EXT_CONFLICT_NAME_SIG[] = {'N', 'A', 'M', 'E'}; - -#define INDEX_OWNER(idx) ((git_repository *)(GIT_REFCOUNT_OWNER(idx))) - -struct index_header { - uint32_t signature; - uint32_t version; - uint32_t entry_count; -}; - -struct index_extension { - char signature[4]; - uint32_t extension_size; -}; - -struct entry_time { - uint32_t seconds; - uint32_t nanoseconds; -}; - -struct entry_common { - struct entry_time ctime; - struct entry_time mtime; - uint32_t dev; - uint32_t ino; - uint32_t mode; - uint32_t uid; - uint32_t gid; - uint32_t file_size; -}; - -#define entry_short(oid_size) \ - struct { \ - struct entry_common common; \ - unsigned char oid[oid_size]; \ - uint16_t flags; \ - char path[1]; /* arbitrary length */ \ - } - -#define entry_long(oid_size) \ - struct { \ - struct entry_common common; \ - unsigned char oid[oid_size]; \ - uint16_t flags; \ - uint16_t flags_extended; \ - char path[1]; /* arbitrary length */ \ - } - -typedef entry_short(GIT_OID_SHA1_SIZE) index_entry_short_sha1; -typedef entry_long(GIT_OID_SHA1_SIZE) index_entry_long_sha1; - -#ifdef GIT_EXPERIMENTAL_SHA256 -typedef entry_short(GIT_OID_SHA256_SIZE) index_entry_short_sha256; -typedef entry_long(GIT_OID_SHA256_SIZE) index_entry_long_sha256; -#endif - -#undef entry_short -#undef entry_long - -struct entry_srch_key { - const char *path; - size_t pathlen; - int stage; -}; - -struct entry_internal { - git_index_entry entry; - size_t pathlen; - char path[GIT_FLEX_ARRAY]; -}; - -struct reuc_entry_internal { - git_index_reuc_entry entry; - size_t pathlen; - char path[GIT_FLEX_ARRAY]; -}; - -bool git_index__enforce_unsaved_safety = false; - -/* local declarations */ -static int read_extension(size_t *read_len, git_index *index, size_t checksum_size, const char *buffer, size_t buffer_size); -static int read_header(struct index_header *dest, const void *buffer); - -static int parse_index(git_index *index, const char *buffer, size_t buffer_size); -static bool is_index_extended(git_index *index); -static int write_index(unsigned char checksum[GIT_HASH_MAX_SIZE], size_t *checksum_size, git_index *index, git_filebuf *file); - -static void index_entry_free(git_index_entry *entry); -static void index_entry_reuc_free(git_index_reuc_entry *reuc); - -int git_index_entry_srch(const void *key, const void *array_member) -{ - const struct entry_srch_key *srch_key = key; - const struct entry_internal *entry = array_member; - int cmp; - size_t len1, len2, len; - - len1 = srch_key->pathlen; - len2 = entry->pathlen; - len = len1 < len2 ? len1 : len2; - - cmp = memcmp(srch_key->path, entry->path, len); - if (cmp) - return cmp; - if (len1 < len2) - return -1; - if (len1 > len2) - return 1; - - if (srch_key->stage != GIT_INDEX_STAGE_ANY) - return srch_key->stage - GIT_INDEX_ENTRY_STAGE(&entry->entry); - - return 0; -} - -int git_index_entry_isrch(const void *key, const void *array_member) -{ - const struct entry_srch_key *srch_key = key; - const struct entry_internal *entry = array_member; - int cmp; - size_t len1, len2, len; - - len1 = srch_key->pathlen; - len2 = entry->pathlen; - len = len1 < len2 ? len1 : len2; - - cmp = strncasecmp(srch_key->path, entry->path, len); - - if (cmp) - return cmp; - if (len1 < len2) - return -1; - if (len1 > len2) - return 1; - - if (srch_key->stage != GIT_INDEX_STAGE_ANY) - return srch_key->stage - GIT_INDEX_ENTRY_STAGE(&entry->entry); - - return 0; -} - -static int index_entry_srch_path(const void *path, const void *array_member) -{ - const git_index_entry *entry = array_member; - - return strcmp((const char *)path, entry->path); -} - -static int index_entry_isrch_path(const void *path, const void *array_member) -{ - const git_index_entry *entry = array_member; - - return strcasecmp((const char *)path, entry->path); -} - -int git_index_entry_cmp(const void *a, const void *b) -{ - int diff; - const git_index_entry *entry_a = a; - const git_index_entry *entry_b = b; - - diff = strcmp(entry_a->path, entry_b->path); - - if (diff == 0) - diff = (GIT_INDEX_ENTRY_STAGE(entry_a) - GIT_INDEX_ENTRY_STAGE(entry_b)); - - return diff; -} - -int git_index_entry_icmp(const void *a, const void *b) -{ - int diff; - const git_index_entry *entry_a = a; - const git_index_entry *entry_b = b; - - diff = strcasecmp(entry_a->path, entry_b->path); - - if (diff == 0) - diff = (GIT_INDEX_ENTRY_STAGE(entry_a) - GIT_INDEX_ENTRY_STAGE(entry_b)); - - return diff; -} - -static int conflict_name_cmp(const void *a, const void *b) -{ - const git_index_name_entry *name_a = a; - const git_index_name_entry *name_b = b; - - if (name_a->ancestor && !name_b->ancestor) - return 1; - - if (!name_a->ancestor && name_b->ancestor) - return -1; - - if (name_a->ancestor) - return strcmp(name_a->ancestor, name_b->ancestor); - - if (!name_a->ours || !name_b->ours) - return 0; - - return strcmp(name_a->ours, name_b->ours); -} - -/** - * TODO: enable this when resolving case insensitive conflicts - */ -#if 0 -static int conflict_name_icmp(const void *a, const void *b) -{ - const git_index_name_entry *name_a = a; - const git_index_name_entry *name_b = b; - - if (name_a->ancestor && !name_b->ancestor) - return 1; - - if (!name_a->ancestor && name_b->ancestor) - return -1; - - if (name_a->ancestor) - return strcasecmp(name_a->ancestor, name_b->ancestor); - - if (!name_a->ours || !name_b->ours) - return 0; - - return strcasecmp(name_a->ours, name_b->ours); -} -#endif - -static int reuc_srch(const void *key, const void *array_member) -{ - const git_index_reuc_entry *reuc = array_member; - - return strcmp(key, reuc->path); -} - -static int reuc_isrch(const void *key, const void *array_member) -{ - const git_index_reuc_entry *reuc = array_member; - - return strcasecmp(key, reuc->path); -} - -static int reuc_cmp(const void *a, const void *b) -{ - const git_index_reuc_entry *info_a = a; - const git_index_reuc_entry *info_b = b; - - return strcmp(info_a->path, info_b->path); -} - -static int reuc_icmp(const void *a, const void *b) -{ - const git_index_reuc_entry *info_a = a; - const git_index_reuc_entry *info_b = b; - - return strcasecmp(info_a->path, info_b->path); -} - -static void index_entry_reuc_free(git_index_reuc_entry *reuc) -{ - git__free(reuc); -} - -static void index_entry_free(git_index_entry *entry) -{ - if (!entry) - return; - - memset(&entry->id, 0, sizeof(entry->id)); - git__free(entry); -} - -unsigned int git_index__create_mode(unsigned int mode) -{ - if (S_ISLNK(mode)) - return S_IFLNK; - - if (S_ISDIR(mode) || (mode & S_IFMT) == (S_IFLNK | S_IFDIR)) - return (S_IFLNK | S_IFDIR); - - return S_IFREG | GIT_PERMS_CANONICAL(mode); -} - -static unsigned int index_merge_mode( - git_index *index, git_index_entry *existing, unsigned int mode) -{ - if (index->no_symlinks && S_ISREG(mode) && - existing && S_ISLNK(existing->mode)) - return existing->mode; - - if (index->distrust_filemode && S_ISREG(mode)) - return (existing && S_ISREG(existing->mode)) ? - existing->mode : git_index__create_mode(0666); - - return git_index__create_mode(mode); -} - -GIT_INLINE(int) index_find_in_entries( - size_t *out, git_vector *entries, git_vector_cmp entry_srch, - const char *path, size_t path_len, int stage) -{ - struct entry_srch_key srch_key; - srch_key.path = path; - srch_key.pathlen = !path_len ? strlen(path) : path_len; - srch_key.stage = stage; - return git_vector_bsearch2(out, entries, entry_srch, &srch_key); -} - -GIT_INLINE(int) index_find( - size_t *out, git_index *index, - const char *path, size_t path_len, int stage) -{ - git_vector_sort(&index->entries); - - return index_find_in_entries( - out, &index->entries, index->entries_search, path, path_len, stage); -} - -void git_index__set_ignore_case(git_index *index, bool ignore_case) -{ - index->ignore_case = ignore_case; - index->entries_map.ignore_case = ignore_case; - - if (ignore_case) { - index->entries_cmp_path = git__strcasecmp_cb; - index->entries_search = git_index_entry_isrch; - index->entries_search_path = index_entry_isrch_path; - index->reuc_search = reuc_isrch; - } else { - index->entries_cmp_path = git__strcmp_cb; - index->entries_search = git_index_entry_srch; - index->entries_search_path = index_entry_srch_path; - index->reuc_search = reuc_srch; - } - - git_vector_set_cmp(&index->entries, - ignore_case ? git_index_entry_icmp : git_index_entry_cmp); - git_vector_sort(&index->entries); - - git_vector_set_cmp(&index->reuc, ignore_case ? reuc_icmp : reuc_cmp); - git_vector_sort(&index->reuc); -} - -int git_index__open( - git_index **index_out, - const char *index_path, - git_oid_t oid_type) -{ - git_index *index; - int error = -1; - - GIT_ASSERT_ARG(index_out); - - index = git__calloc(1, sizeof(git_index)); - GIT_ERROR_CHECK_ALLOC(index); - - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); - index->oid_type = oid_type; - - if (git_pool_init(&index->tree_pool, 1) < 0) - goto fail; - - if (index_path != NULL) { - index->index_file_path = git__strdup(index_path); - if (!index->index_file_path) - goto fail; - - /* Check if index file is stored on disk already */ - if (git_fs_path_exists(index->index_file_path) == true) - index->on_disk = 1; - } - - if (git_vector_init(&index->entries, 32, git_index_entry_cmp) < 0 || - git_vector_init(&index->names, 8, conflict_name_cmp) < 0 || - git_vector_init(&index->reuc, 8, reuc_cmp) < 0 || - git_vector_init(&index->deleted, 8, git_index_entry_cmp) < 0) - goto fail; - - index->entries_cmp_path = git__strcmp_cb; - index->entries_search = git_index_entry_srch; - index->entries_search_path = index_entry_srch_path; - index->reuc_search = reuc_srch; - index->version = INDEX_VERSION_NUMBER_DEFAULT; - - if (index_path != NULL && (error = git_index_read(index, true)) < 0) - goto fail; - - *index_out = index; - GIT_REFCOUNT_INC(index); - - return 0; - -fail: - git_pool_clear(&index->tree_pool); - git_index_free(index); - return error; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_index_open( - git_index **index_out, - const char *index_path, - const git_index_options *opts) -{ - return git_index__open(index_out, index_path, - opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT); -} -#else -int git_index_open(git_index **index_out, const char *index_path) -{ - return git_index__open(index_out, index_path, GIT_OID_SHA1); -} -#endif - -int git_index__new(git_index **out, git_oid_t oid_type) -{ - return git_index__open(out, NULL, oid_type); -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_index_new(git_index **out, const git_index_options *opts) -{ - return git_index__new(out, - opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT); -} -#else -int git_index_new(git_index **out) -{ - return git_index__new(out, GIT_OID_SHA1); -} -#endif - -static void index_free(git_index *index) -{ - /* index iterators increment the refcount of the index, so if we - * get here then there should be no outstanding iterators. - */ - if (git_atomic32_get(&index->readers)) - return; - - git_index_clear(index); - git_index_entrymap_dispose(&index->entries_map); - git_vector_dispose(&index->entries); - git_vector_dispose(&index->names); - git_vector_dispose(&index->reuc); - git_vector_dispose(&index->deleted); - - git__free(index->index_file_path); - - git__memzero(index, sizeof(*index)); - git__free(index); -} - -void git_index_free(git_index *index) -{ - if (index == NULL) - return; - - GIT_REFCOUNT_DEC(index, index_free); -} - -/* call with locked index */ -static void index_free_deleted(git_index *index) -{ - int readers = (int)git_atomic32_get(&index->readers); - size_t i; - - if (readers > 0 || !index->deleted.length) - return; - - for (i = 0; i < index->deleted.length; ++i) { - git_index_entry *ie = git_atomic_swap(index->deleted.contents[i], NULL); - index_entry_free(ie); - } - - git_vector_clear(&index->deleted); -} - -/* call with locked index */ -static int index_remove_entry(git_index *index, size_t pos) -{ - int error = 0; - git_index_entry *entry = git_vector_get(&index->entries, pos); - - if (entry != NULL) { - git_tree_cache_invalidate_path(index->tree, entry->path); - git_index_entrymap_remove(&index->entries_map, entry); - } - - error = git_vector_remove(&index->entries, pos); - - if (!error) { - if (git_atomic32_get(&index->readers) > 0) { - error = git_vector_insert(&index->deleted, entry); - } else { - index_entry_free(entry); - } - - index->dirty = 1; - } - - return error; -} - -int git_index_clear(git_index *index) -{ - int error = 0; - - GIT_ASSERT_ARG(index); - - index->dirty = 1; - index->tree = NULL; - git_pool_clear(&index->tree_pool); - - git_index_entrymap_clear(&index->entries_map); - - while (!error && index->entries.length > 0) - error = index_remove_entry(index, index->entries.length - 1); - - if (error) - goto done; - - index_free_deleted(index); - - if ((error = git_index_name_clear(index)) < 0 || - (error = git_index_reuc_clear(index)) < 0) - goto done; - - git_futils_filestamp_set(&index->stamp, NULL); - -done: - return error; -} - -static int create_index_error(int error, const char *msg) -{ - git_error_set_str(GIT_ERROR_INDEX, msg); - return error; -} - -int git_index_set_caps(git_index *index, int caps) -{ - unsigned int old_ignore_case; - - GIT_ASSERT_ARG(index); - - old_ignore_case = index->ignore_case; - - if (caps == GIT_INDEX_CAPABILITY_FROM_OWNER) { - git_repository *repo = INDEX_OWNER(index); - int val; - - if (!repo) - return create_index_error( - -1, "cannot access repository to set index caps"); - - if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_IGNORECASE)) - index->ignore_case = (val != 0); - if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_FILEMODE)) - index->distrust_filemode = (val == 0); - if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_SYMLINKS)) - index->no_symlinks = (val == 0); - } - else { - index->ignore_case = ((caps & GIT_INDEX_CAPABILITY_IGNORE_CASE) != 0); - index->distrust_filemode = ((caps & GIT_INDEX_CAPABILITY_NO_FILEMODE) != 0); - index->no_symlinks = ((caps & GIT_INDEX_CAPABILITY_NO_SYMLINKS) != 0); - } - - if (old_ignore_case != index->ignore_case) { - git_index__set_ignore_case(index, (bool)index->ignore_case); - } - - return 0; -} - -int git_index_caps(const git_index *index) -{ - return ((index->ignore_case ? GIT_INDEX_CAPABILITY_IGNORE_CASE : 0) | - (index->distrust_filemode ? GIT_INDEX_CAPABILITY_NO_FILEMODE : 0) | - (index->no_symlinks ? GIT_INDEX_CAPABILITY_NO_SYMLINKS : 0)); -} - -#ifndef GIT_DEPRECATE_HARD -const git_oid *git_index_checksum(git_index *index) -{ - return (git_oid *)index->checksum; -} -#endif - -/** - * Returns 1 for changed, 0 for not changed and <0 for errors - */ -static int compare_checksum(git_index *index) -{ - int fd; - ssize_t bytes_read; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - size_t checksum_size = git_oid_size(index->oid_type); - - if ((fd = p_open(index->index_file_path, O_RDONLY)) < 0) - return fd; - - if (p_lseek(fd, (0 - (ssize_t)checksum_size), SEEK_END) < 0) { - p_close(fd); - git_error_set(GIT_ERROR_OS, "failed to seek to end of file"); - return -1; - } - - bytes_read = p_read(fd, checksum, checksum_size); - p_close(fd); - - if (bytes_read < (ssize_t)checksum_size) - return -1; - - return !!memcmp(checksum, index->checksum, checksum_size); -} - -int git_index_read(git_index *index, int force) -{ - int error = 0, updated; - git_str buffer = GIT_STR_INIT; - git_futils_filestamp stamp = index->stamp; - - if (!index->index_file_path) - return create_index_error(-1, - "failed to read index: The index is in-memory only"); - - index->on_disk = git_fs_path_exists(index->index_file_path); - - if (!index->on_disk) { - if (force && (error = git_index_clear(index)) < 0) - return error; - - index->dirty = 0; - return 0; - } - - if ((updated = git_futils_filestamp_check(&stamp, index->index_file_path) < 0) || - ((updated = compare_checksum(index)) < 0)) { - git_error_set( - GIT_ERROR_INDEX, - "failed to read index: '%s' no longer exists", - index->index_file_path); - return updated; - } - - if (!updated && !force) - return 0; - - error = git_futils_readbuffer(&buffer, index->index_file_path); - if (error < 0) - return error; - - index->tree = NULL; - git_pool_clear(&index->tree_pool); - - error = git_index_clear(index); - - if (!error) - error = parse_index(index, buffer.ptr, buffer.size); - - if (!error) { - git_futils_filestamp_set(&index->stamp, &stamp); - index->dirty = 0; - } - - git_str_dispose(&buffer); - return error; -} - -int git_index_read_safely(git_index *index) -{ - if (git_index__enforce_unsaved_safety && index->dirty) { - git_error_set(GIT_ERROR_INDEX, - "the index has unsaved changes that would be overwritten by this operation"); - return GIT_EINDEXDIRTY; - } - - return git_index_read(index, false); -} - -static bool is_racy_entry(git_index *index, const git_index_entry *entry) -{ - /* Git special-cases submodules in the check */ - if (S_ISGITLINK(entry->mode)) - return false; - - return git_index_entry_newer_than_index(entry, index); -} - -/* - * Force the next diff to take a look at those entries which have the - * same timestamp as the current index. - */ -static int truncate_racily_clean(git_index *index) -{ - size_t i; - int error; - git_index_entry *entry; - git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; - git_diff *diff = NULL; - git_vector paths = GIT_VECTOR_INIT; - git_diff_delta *delta; - - /* Nothing to do if there's no repo to talk about */ - if (!INDEX_OWNER(index)) - return 0; - - /* If there's no workdir, we can't know where to even check */ - if (!git_repository_workdir(INDEX_OWNER(index))) - return 0; - - diff_opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE | GIT_DIFF_IGNORE_SUBMODULES | GIT_DIFF_DISABLE_PATHSPEC_MATCH; - git_vector_foreach(&index->entries, i, entry) { - if ((entry->flags_extended & GIT_INDEX_ENTRY_UPTODATE) == 0 && - is_racy_entry(index, entry)) - git_vector_insert(&paths, (char *)entry->path); - } - - if (paths.length == 0) - goto done; - - diff_opts.pathspec.count = paths.length; - diff_opts.pathspec.strings = (char **)paths.contents; - - if ((error = git_diff_index_to_workdir(&diff, INDEX_OWNER(index), index, &diff_opts)) < 0) { - git_vector_dispose(&paths); - return error; - } - - git_vector_foreach(&diff->deltas, i, delta) { - entry = (git_index_entry *)git_index_get_bypath(index, delta->old_file.path, 0); - - /* Ensure that we have a stage 0 for this file (ie, it's not a - * conflict), otherwise smudging it is quite pointless. - */ - if (entry) { - entry->file_size = 0; - index->dirty = 1; - } - } - -done: - git_diff_free(diff); - git_vector_dispose(&paths); - return 0; -} - -unsigned git_index_version(git_index *index) -{ - GIT_ASSERT_ARG(index); - - return index->version; -} - -int git_index_set_version(git_index *index, unsigned int version) -{ - GIT_ASSERT_ARG(index); - - if (version < INDEX_VERSION_NUMBER_LB || - version > INDEX_VERSION_NUMBER_UB) { - git_error_set(GIT_ERROR_INDEX, "invalid version number"); - return -1; - } - - index->version = version; - - return 0; -} - -int git_index_write(git_index *index) -{ - git_indexwriter writer = GIT_INDEXWRITER_INIT; - int error; - - truncate_racily_clean(index); - - if ((error = git_indexwriter_init(&writer, index)) == 0 && - (error = git_indexwriter_commit(&writer)) == 0) - index->dirty = 0; - - git_indexwriter_cleanup(&writer); - - return error; -} - -const char *git_index_path(const git_index *index) -{ - GIT_ASSERT_ARG_WITH_RETVAL(index, NULL); - return index->index_file_path; -} - -int git_index_write_tree(git_oid *oid, git_index *index) -{ - git_repository *repo; - - GIT_ASSERT_ARG(oid); - GIT_ASSERT_ARG(index); - - repo = INDEX_OWNER(index); - - if (repo == NULL) - return create_index_error(-1, "Failed to write tree. " - "the index file is not backed up by an existing repository"); - - return git_tree__write_index(oid, index, repo); -} - -int git_index_write_tree_to( - git_oid *oid, git_index *index, git_repository *repo) -{ - GIT_ASSERT_ARG(oid); - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(repo); - - return git_tree__write_index(oid, index, repo); -} - -size_t git_index_entrycount(const git_index *index) -{ - GIT_ASSERT_ARG(index); - - return index->entries.length; -} - -const git_index_entry *git_index_get_byindex( - git_index *index, size_t n) -{ - GIT_ASSERT_ARG_WITH_RETVAL(index, NULL); - - git_vector_sort(&index->entries); - return git_vector_get(&index->entries, n); -} - -const git_index_entry *git_index_get_bypath( - git_index *index, const char *path, int stage) -{ - git_index_entry key = {{ 0 }}; - git_index_entry *value; - - GIT_ASSERT_ARG_WITH_RETVAL(index, NULL); - - key.path = path; - GIT_INDEX_ENTRY_STAGE_SET(&key, stage); - - if (git_index_entrymap_get(&value, &index->entries_map, &key) != 0) { - git_error_set(GIT_ERROR_INDEX, "index does not contain '%s'", path); - return NULL; - } - - return value; -} - -void git_index_entry__init_from_stat( - git_index_entry *entry, struct stat *st, bool trust_mode) -{ - entry->ctime.seconds = (int32_t)st->st_ctime; - entry->mtime.seconds = (int32_t)st->st_mtime; -#if defined(GIT_USE_NSEC) - entry->mtime.nanoseconds = st->st_mtime_nsec; - entry->ctime.nanoseconds = st->st_ctime_nsec; -#endif - entry->dev = st->st_rdev; - entry->ino = st->st_ino; - entry->mode = (!trust_mode && S_ISREG(st->st_mode)) ? - git_index__create_mode(0666) : git_index__create_mode(st->st_mode); - entry->uid = st->st_uid; - entry->gid = st->st_gid; - entry->file_size = (uint32_t)st->st_size; -} - -static void index_entry_adjust_namemask( - git_index_entry *entry, - size_t path_length) -{ - entry->flags &= ~GIT_INDEX_ENTRY_NAMEMASK; - - if (path_length < GIT_INDEX_ENTRY_NAMEMASK) - entry->flags |= path_length & GIT_INDEX_ENTRY_NAMEMASK; - else - entry->flags |= GIT_INDEX_ENTRY_NAMEMASK; -} - -/* When `from_workdir` is true, we will validate the paths to avoid placing - * paths that are invalid for the working directory on the current filesystem - * (eg, on Windows, we will disallow `GIT~1`, `AUX`, `COM1`, etc). This - * function will *always* prevent `.git` and directory traversal `../` from - * being added to the index. - */ -static int index_entry_create( - git_index_entry **out, - git_repository *repo, - const char *path, - struct stat *st, - bool from_workdir) -{ - size_t pathlen = strlen(path), alloclen; - struct entry_internal *entry; - unsigned int path_valid_flags = GIT_PATH_REJECT_INDEX_DEFAULTS; - uint16_t mode = 0; - - /* always reject placing `.git` in the index and directory traversal. - * when requested, disallow platform-specific filenames and upgrade to - * the platform-specific `.git` tests (eg, `git~1`, etc). - */ - if (from_workdir) - path_valid_flags |= GIT_PATH_REJECT_WORKDIR_DEFAULTS; - if (st) - mode = st->st_mode; - - if (!git_path_is_valid(repo, path, mode, path_valid_flags)) { - git_error_set(GIT_ERROR_INDEX, "invalid path: '%s'", path); - return -1; - } - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(struct entry_internal), pathlen); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); - entry = git__calloc(1, alloclen); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->pathlen = pathlen; - memcpy(entry->path, path, pathlen); - entry->entry.path = entry->path; - - *out = (git_index_entry *)entry; - return 0; -} - -static int index_entry_init( - git_index_entry **entry_out, - git_index *index, - const char *rel_path) -{ - int error = 0; - git_index_entry *entry = NULL; - git_str path = GIT_STR_INIT; - struct stat st; - git_oid oid; - git_repository *repo; - - if (INDEX_OWNER(index) == NULL) - return create_index_error(-1, - "could not initialize index entry. " - "Index is not backed up by an existing repository."); - - /* - * FIXME: this is duplicated with the work in - * git_blob__create_from_paths. It should accept an optional stat - * structure so we can pass in the one we have to do here. - */ - repo = INDEX_OWNER(index); - if (git_repository__ensure_not_bare(repo, "create blob from file") < 0) - return GIT_EBAREREPO; - - if (git_repository_workdir_path(&path, repo, rel_path) < 0) - return -1; - - error = git_fs_path_lstat(path.ptr, &st); - git_str_dispose(&path); - - if (error < 0) - return error; - - if (index_entry_create(&entry, INDEX_OWNER(index), rel_path, &st, true) < 0) - return -1; - - /* write the blob to disk and get the oid and stat info */ - error = git_blob__create_from_paths( - &oid, &st, INDEX_OWNER(index), NULL, rel_path, 0, true); - - if (error < 0) { - index_entry_free(entry); - return error; - } - - entry->id = oid; - git_index_entry__init_from_stat(entry, &st, !index->distrust_filemode); - - *entry_out = (git_index_entry *)entry; - return 0; -} - -static git_index_reuc_entry *reuc_entry_alloc(const char *path) -{ - size_t pathlen = strlen(path), - structlen = sizeof(struct reuc_entry_internal), - alloclen; - struct reuc_entry_internal *entry; - - if (GIT_ADD_SIZET_OVERFLOW(&alloclen, structlen, pathlen) || - GIT_ADD_SIZET_OVERFLOW(&alloclen, alloclen, 1)) - return NULL; - - entry = git__calloc(1, alloclen); - if (!entry) - return NULL; - - entry->pathlen = pathlen; - memcpy(entry->path, path, pathlen); - entry->entry.path = entry->path; - - return (git_index_reuc_entry *)entry; -} - -static int index_entry_reuc_init(git_index_reuc_entry **reuc_out, - const char *path, - int ancestor_mode, const git_oid *ancestor_oid, - int our_mode, const git_oid *our_oid, - int their_mode, const git_oid *their_oid) -{ - git_index_reuc_entry *reuc = NULL; - - GIT_ASSERT_ARG(reuc_out); - GIT_ASSERT_ARG(path); - - *reuc_out = reuc = reuc_entry_alloc(path); - GIT_ERROR_CHECK_ALLOC(reuc); - - if ((reuc->mode[0] = ancestor_mode) > 0) { - GIT_ASSERT(ancestor_oid); - git_oid_cpy(&reuc->oid[0], ancestor_oid); - } - - if ((reuc->mode[1] = our_mode) > 0) { - GIT_ASSERT(our_oid); - git_oid_cpy(&reuc->oid[1], our_oid); - } - - if ((reuc->mode[2] = their_mode) > 0) { - GIT_ASSERT(their_oid); - git_oid_cpy(&reuc->oid[2], their_oid); - } - - return 0; -} - -static void index_entry_cpy( - git_index_entry *tgt, - const git_index_entry *src) -{ - const char *tgt_path = tgt->path; - memcpy(tgt, src, sizeof(*tgt)); - tgt->path = tgt_path; -} - -static int index_entry_dup( - git_index_entry **out, - git_index *index, - const git_index_entry *src) -{ - if (index_entry_create(out, INDEX_OWNER(index), src->path, NULL, false) < 0) - return -1; - - index_entry_cpy(*out, src); - return 0; -} - -static void index_entry_cpy_nocache( - git_index_entry *tgt, - const git_index_entry *src) -{ - git_oid_cpy(&tgt->id, &src->id); - tgt->mode = src->mode; - tgt->flags = src->flags; - tgt->flags_extended = (src->flags_extended & GIT_INDEX_ENTRY_EXTENDED_FLAGS); -} - -static int index_entry_dup_nocache( - git_index_entry **out, - git_index *index, - const git_index_entry *src) -{ - if (index_entry_create(out, INDEX_OWNER(index), src->path, NULL, false) < 0) - return -1; - - index_entry_cpy_nocache(*out, src); - return 0; -} - -static int has_file_name(git_index *index, - const git_index_entry *entry, size_t pos, int ok_to_replace) -{ - size_t len = strlen(entry->path); - int stage = GIT_INDEX_ENTRY_STAGE(entry); - const char *name = entry->path; - - while (pos < index->entries.length) { - struct entry_internal *p = index->entries.contents[pos++]; - - if (len >= p->pathlen) - break; - if (memcmp(name, p->path, len)) - break; - if (GIT_INDEX_ENTRY_STAGE(&p->entry) != stage) - continue; - if (p->path[len] != '/') - continue; - if (!ok_to_replace) - return -1; - - if (index_remove_entry(index, --pos) < 0) - break; - } - return 0; -} - -/* - * Do we have another file with a pathname that is a proper - * subset of the name we're trying to add? - */ -static int has_dir_name(git_index *index, - const git_index_entry *entry, int ok_to_replace) -{ - int stage = GIT_INDEX_ENTRY_STAGE(entry); - const char *name = entry->path; - const char *slash = name + strlen(name); - - for (;;) { - size_t len, pos; - - for (;;) { - slash--; - - if (slash <= entry->path) - return 0; - - if (*slash == '/') - break; - } - len = slash - name; - - if (!index_find(&pos, index, name, len, stage)) { - if (!ok_to_replace) - return -1; - - if (index_remove_entry(index, pos) < 0) - break; - continue; - } - - /* - * Trivial optimization: if we find an entry that - * already matches the sub-directory, then we know - * we're ok, and we can exit. - */ - for (; pos < index->entries.length; ++pos) { - struct entry_internal *p = index->entries.contents[pos]; - - if (p->pathlen <= len || - p->path[len] != '/' || - memcmp(p->path, name, len)) - break; /* not our subdirectory */ - - if (GIT_INDEX_ENTRY_STAGE(&p->entry) == stage) - return 0; - } - } - - return 0; -} - -static int check_file_directory_collision(git_index *index, - git_index_entry *entry, size_t pos, int ok_to_replace) -{ - if (has_file_name(index, entry, pos, ok_to_replace) < 0 || - has_dir_name(index, entry, ok_to_replace) < 0) { - git_error_set(GIT_ERROR_INDEX, - "'%s' appears as both a file and a directory", entry->path); - return -1; - } - - return 0; -} - -static int canonicalize_directory_path( - git_index *index, - git_index_entry *entry, - git_index_entry *existing) -{ - const git_index_entry *match, *best = NULL; - char *search, *sep; - size_t pos, search_len, best_len = 0; - - if (!index->ignore_case) - return 0; - - /* item already exists in the index, simply re-use the existing case */ - if (existing) { - memcpy((char *)entry->path, existing->path, strlen(existing->path)); - return 0; - } - - /* nothing to do */ - if (strchr(entry->path, '/') == NULL) - return 0; - - if ((search = git__strdup(entry->path)) == NULL) - return -1; - - /* starting at the parent directory and descending to the root, find the - * common parent directory. - */ - while (!best && (sep = strrchr(search, '/'))) { - sep[1] = '\0'; - - search_len = strlen(search); - - git_vector_bsearch2( - &pos, &index->entries, index->entries_search_path, search); - - while ((match = git_vector_get(&index->entries, pos))) { - if (GIT_INDEX_ENTRY_STAGE(match) != 0) { - /* conflicts do not contribute to canonical paths */ - } else if (strncmp(search, match->path, search_len) == 0) { - /* prefer an exact match to the input filename */ - best = match; - best_len = search_len; - break; - } else if (strncasecmp(search, match->path, search_len) == 0) { - /* continue walking, there may be a path with an exact - * (case sensitive) match later in the index, but use this - * as the best match until that happens. - */ - if (!best) { - best = match; - best_len = search_len; - } - } else { - break; - } - - pos++; - } - - sep[0] = '\0'; - } - - if (best) - memcpy((char *)entry->path, best->path, best_len); - - git__free(search); - return 0; -} - -static int index_no_dups(void **old, void *new) -{ - const git_index_entry *entry = new; - GIT_UNUSED(old); - git_error_set(GIT_ERROR_INDEX, "'%s' appears multiple times at stage %d", - entry->path, GIT_INDEX_ENTRY_STAGE(entry)); - return GIT_EEXISTS; -} - -static void index_existing_and_best( - git_index_entry **existing, - size_t *existing_position, - git_index_entry **best, - git_index *index, - const git_index_entry *entry) -{ - git_index_entry *e; - size_t pos; - int error; - - error = index_find(&pos, - index, entry->path, 0, GIT_INDEX_ENTRY_STAGE(entry)); - - if (error == 0) { - *existing = index->entries.contents[pos]; - *existing_position = pos; - *best = index->entries.contents[pos]; - return; - } - - *existing = NULL; - *existing_position = 0; - *best = NULL; - - if (GIT_INDEX_ENTRY_STAGE(entry) == 0) { - for (; pos < index->entries.length; pos++) { - int (*strcomp)(const char *a, const char *b) = - index->ignore_case ? git__strcasecmp : git__strcmp; - - e = index->entries.contents[pos]; - - if (strcomp(entry->path, e->path) != 0) - break; - - if (GIT_INDEX_ENTRY_STAGE(e) == GIT_INDEX_STAGE_ANCESTOR) { - *best = e; - continue; - } else { - *best = e; - break; - } - } - } -} - -/* index_insert takes ownership of the new entry - if it can't insert - * it, then it will return an error **and also free the entry**. When - * it replaces an existing entry, it will update the entry_ptr with the - * actual entry in the index (and free the passed in one). - * - * trust_path is whether we use the given path, or whether (on case - * insensitive systems only) we try to canonicalize the given path to - * be within an existing directory. - * - * trust_mode is whether we trust the mode in entry_ptr. - * - * trust_id is whether we trust the id or it should be validated. - */ -static int index_insert( - git_index *index, - git_index_entry **entry_ptr, - int replace, - bool trust_path, - bool trust_mode, - bool trust_id) -{ - git_index_entry *existing, *best, *entry; - size_t path_length, position; - int error; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(entry_ptr); - - entry = *entry_ptr; - - /* Make sure that the path length flag is correct */ - path_length = ((struct entry_internal *)entry)->pathlen; - index_entry_adjust_namemask(entry, path_length); - - /* This entry is now up-to-date and should not be checked for raciness */ - entry->flags_extended |= GIT_INDEX_ENTRY_UPTODATE; - - git_vector_sort(&index->entries); - - /* - * Look if an entry with this path already exists, either staged, or (if - * this entry is a regular staged item) as the "ours" side of a conflict. - */ - index_existing_and_best(&existing, &position, &best, index, entry); - - /* Update the file mode */ - entry->mode = trust_mode ? - git_index__create_mode(entry->mode) : - index_merge_mode(index, best, entry->mode); - - /* Canonicalize the directory name */ - if (!trust_path && (error = canonicalize_directory_path(index, entry, best)) < 0) - goto out; - - /* Ensure that the given id exists (unless it's a submodule) */ - if (!trust_id && INDEX_OWNER(index) && - (entry->mode & GIT_FILEMODE_COMMIT) != GIT_FILEMODE_COMMIT) { - - if (!git_object__is_valid(INDEX_OWNER(index), &entry->id, - git_object__type_from_filemode(entry->mode))) { - error = -1; - goto out; - } - } - - /* Look for tree / blob name collisions, removing conflicts if requested */ - if ((error = check_file_directory_collision(index, entry, position, replace)) < 0) - goto out; - - /* - * If we are replacing an existing item, overwrite the existing entry - * and return it in place of the passed in one. - */ - if (existing) { - if (replace) { - index_entry_cpy(existing, entry); - - if (trust_path) - memcpy((char *)existing->path, entry->path, strlen(entry->path)); - } - - index_entry_free(entry); - *entry_ptr = existing; - } else { - /* - * If replace is not requested or no existing entry exists, insert - * at the sorted position. (Since we re-sort after each insert to - * check for dups, this is actually cheaper in the long run.) - */ - if ((error = git_vector_insert_sorted(&index->entries, entry, index_no_dups)) < 0 || - (error = git_index_entrymap_put(&index->entries_map, entry)) < 0) - goto out; - } - - index->dirty = 1; - -out: - if (error < 0) { - index_entry_free(*entry_ptr); - *entry_ptr = NULL; - } - - return error; -} - -int git_index__conflict_to_reuc(git_index *index, const char *path) -{ - const git_index_entry *conflict_entries[3]; - int ancestor_mode, our_mode, their_mode; - git_oid const *ancestor_oid, *our_oid, *their_oid; - int ret; - - if ((ret = git_index_conflict_get(&conflict_entries[0], - &conflict_entries[1], &conflict_entries[2], index, path)) < 0) - return ret; - - ancestor_mode = conflict_entries[0] == NULL ? 0 : conflict_entries[0]->mode; - our_mode = conflict_entries[1] == NULL ? 0 : conflict_entries[1]->mode; - their_mode = conflict_entries[2] == NULL ? 0 : conflict_entries[2]->mode; - - ancestor_oid = conflict_entries[0] == NULL ? NULL : &conflict_entries[0]->id; - our_oid = conflict_entries[1] == NULL ? NULL : &conflict_entries[1]->id; - their_oid = conflict_entries[2] == NULL ? NULL : &conflict_entries[2]->id; - - if ((ret = git_index_reuc_add(index, path, ancestor_mode, ancestor_oid, - our_mode, our_oid, their_mode, their_oid)) >= 0) - ret = git_index_conflict_remove(index, path); - - return ret; -} - -GIT_INLINE(bool) is_file_or_link(const int filemode) -{ - return (filemode == GIT_FILEMODE_BLOB || - filemode == GIT_FILEMODE_BLOB_EXECUTABLE || - filemode == GIT_FILEMODE_LINK); -} - -GIT_INLINE(bool) valid_filemode(const int filemode) -{ - return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT); -} - -int git_index_add_from_buffer( - git_index *index, const git_index_entry *source_entry, - const void *buffer, size_t len) -{ - git_index_entry *entry = NULL; - int error = 0; - git_oid id; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(source_entry && source_entry->path); - - if (INDEX_OWNER(index) == NULL) - return create_index_error(-1, - "could not initialize index entry. " - "Index is not backed up by an existing repository."); - - if (!is_file_or_link(source_entry->mode)) { - git_error_set(GIT_ERROR_INDEX, "invalid filemode"); - return -1; - } - - if (len > UINT32_MAX) { - git_error_set(GIT_ERROR_INDEX, "buffer is too large"); - return -1; - } - - if (index_entry_dup(&entry, index, source_entry) < 0) - return -1; - - error = git_blob_create_from_buffer(&id, INDEX_OWNER(index), buffer, len); - if (error < 0) { - index_entry_free(entry); - return error; - } - - git_oid_cpy(&entry->id, &id); - entry->file_size = (uint32_t)len; - - if ((error = index_insert(index, &entry, 1, true, true, true)) < 0) - return error; - - /* Adding implies conflict was resolved, move conflict entries to REUC */ - if ((error = git_index__conflict_to_reuc(index, entry->path)) < 0 && error != GIT_ENOTFOUND) - return error; - - git_tree_cache_invalidate_path(index->tree, entry->path); - return 0; -} - -static int add_repo_as_submodule(git_index_entry **out, git_index *index, const char *path) -{ - git_repository *sub; - git_str abspath = GIT_STR_INIT; - git_repository *repo = INDEX_OWNER(index); - git_reference *head; - git_index_entry *entry; - struct stat st; - int error; - - if ((error = git_repository_workdir_path(&abspath, repo, path)) < 0) - return error; - - if ((error = p_stat(abspath.ptr, &st)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to stat repository dir"); - return -1; - } - - if (index_entry_create(&entry, INDEX_OWNER(index), path, &st, true) < 0) - return -1; - - git_index_entry__init_from_stat(entry, &st, !index->distrust_filemode); - - if ((error = git_repository_open(&sub, abspath.ptr)) < 0) - return error; - - if ((error = git_repository_head(&head, sub)) < 0) - return error; - - git_oid_cpy(&entry->id, git_reference_target(head)); - entry->mode = GIT_FILEMODE_COMMIT; - - git_reference_free(head); - git_repository_free(sub); - git_str_dispose(&abspath); - - *out = entry; - return 0; -} - -int git_index_add_bypath(git_index *index, const char *path) -{ - git_index_entry *entry = NULL; - int ret; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(path); - - if ((ret = index_entry_init(&entry, index, path)) == 0) - ret = index_insert(index, &entry, 1, false, false, true); - - /* If we were given a directory, let's see if it's a submodule */ - if (ret < 0 && ret != GIT_EDIRECTORY) - return ret; - - if (ret == GIT_EDIRECTORY) { - git_submodule *sm; - git_error *last_error; - - git_error_save(&last_error); - - ret = git_submodule_lookup(&sm, INDEX_OWNER(index), path); - if (ret == GIT_ENOTFOUND) { - git_error_restore(last_error); - return GIT_EDIRECTORY; - } - - git_error_free(last_error); - - /* - * EEXISTS means that there is a repository at that path, but it's not known - * as a submodule. We add its HEAD as an entry and don't register it. - */ - if (ret == GIT_EEXISTS) { - if ((ret = add_repo_as_submodule(&entry, index, path)) < 0) - return ret; - - if ((ret = index_insert(index, &entry, 1, false, false, true)) < 0) - return ret; - } else if (ret < 0) { - return ret; - } else { - ret = git_submodule_add_to_index(sm, false); - git_submodule_free(sm); - return ret; - } - } - - /* Adding implies conflict was resolved, move conflict entries to REUC */ - if ((ret = git_index__conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND) - return ret; - - git_tree_cache_invalidate_path(index->tree, entry->path); - return 0; -} - -int git_index_remove_bypath(git_index *index, const char *path) -{ - int ret; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(path); - - if (((ret = git_index_remove(index, path, 0)) < 0 && - ret != GIT_ENOTFOUND) || - ((ret = git_index__conflict_to_reuc(index, path)) < 0 && - ret != GIT_ENOTFOUND)) - return ret; - - if (ret == GIT_ENOTFOUND) - git_error_clear(); - - return 0; -} - -int git_index__fill(git_index *index, const git_vector *source_entries) -{ - const git_index_entry *source_entry = NULL; - int error = 0; - size_t i; - - GIT_ASSERT_ARG(index); - - if (!source_entries->length) - return 0; - - if (git_vector_size_hint(&index->entries, source_entries->length) < 0 || - git_index_entrymap_resize(&index->entries_map, (size_t)(source_entries->length * 1.3)) < 0) - return -1; - - git_vector_foreach(source_entries, i, source_entry) { - git_index_entry *entry = NULL; - - if ((error = index_entry_dup(&entry, index, source_entry)) < 0) - break; - - index_entry_adjust_namemask(entry, ((struct entry_internal *)entry)->pathlen); - entry->flags_extended |= GIT_INDEX_ENTRY_UPTODATE; - entry->mode = git_index__create_mode(entry->mode); - - if ((error = git_vector_insert(&index->entries, entry)) < 0 || - (error = git_index_entrymap_put(&index->entries_map, entry)) < 0) - break; - - index->dirty = 1; - } - - if (!error) - git_vector_sort(&index->entries); - - return error; -} - - -int git_index_add(git_index *index, const git_index_entry *source_entry) -{ - git_index_entry *entry = NULL; - int ret; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(source_entry && source_entry->path); - - if (!valid_filemode(source_entry->mode)) { - git_error_set(GIT_ERROR_INDEX, "invalid entry mode"); - return -1; - } - - if ((ret = index_entry_dup(&entry, index, source_entry)) < 0 || - (ret = index_insert(index, &entry, 1, true, true, false)) < 0) - return ret; - - git_tree_cache_invalidate_path(index->tree, entry->path); - return 0; -} - -int git_index_remove(git_index *index, const char *path, int stage) -{ - int error; - size_t position; - git_index_entry remove_key = {{ 0 }}; - - remove_key.path = path; - GIT_INDEX_ENTRY_STAGE_SET(&remove_key, stage); - - git_index_entrymap_remove(&index->entries_map, &remove_key); - - if (index_find(&position, index, path, 0, stage) < 0) { - git_error_set( - GIT_ERROR_INDEX, "index does not contain %s at stage %d", path, stage); - error = GIT_ENOTFOUND; - } else { - error = index_remove_entry(index, position); - } - - return error; -} - -int git_index_remove_directory(git_index *index, const char *dir, int stage) -{ - git_str pfx = GIT_STR_INIT; - int error = 0; - size_t pos; - git_index_entry *entry; - - if (!(error = git_str_sets(&pfx, dir)) && - !(error = git_fs_path_to_dir(&pfx))) - index_find(&pos, index, pfx.ptr, pfx.size, GIT_INDEX_STAGE_ANY); - - while (!error) { - entry = git_vector_get(&index->entries, pos); - if (!entry || git__prefixcmp(entry->path, pfx.ptr) != 0) - break; - - if (GIT_INDEX_ENTRY_STAGE(entry) != stage) { - ++pos; - continue; - } - - error = index_remove_entry(index, pos); - - /* removed entry at 'pos' so we don't need to increment */ - } - - git_str_dispose(&pfx); - - return error; -} - -int git_index_find_prefix(size_t *at_pos, git_index *index, const char *prefix) -{ - int error = 0; - size_t pos; - const git_index_entry *entry; - - index_find(&pos, index, prefix, strlen(prefix), GIT_INDEX_STAGE_ANY); - entry = git_vector_get(&index->entries, pos); - if (!entry || git__prefixcmp(entry->path, prefix) != 0) - error = GIT_ENOTFOUND; - - if (!error && at_pos) - *at_pos = pos; - - return error; -} - -int git_index__find_pos( - size_t *out, git_index *index, const char *path, size_t path_len, int stage) -{ - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(path); - return index_find(out, index, path, path_len, stage); -} - -int git_index_find(size_t *at_pos, git_index *index, const char *path) -{ - size_t pos; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(path); - - if (git_vector_bsearch2( - &pos, &index->entries, index->entries_search_path, path) < 0) { - git_error_set(GIT_ERROR_INDEX, "index does not contain %s", path); - return GIT_ENOTFOUND; - } - - /* Since our binary search only looked at path, we may be in the - * middle of a list of stages. - */ - for (; pos > 0; --pos) { - const git_index_entry *prev = git_vector_get(&index->entries, pos - 1); - - if (index->entries_cmp_path(prev->path, path) != 0) - break; - } - - if (at_pos) - *at_pos = pos; - - return 0; -} - -int git_index_conflict_add(git_index *index, - const git_index_entry *ancestor_entry, - const git_index_entry *our_entry, - const git_index_entry *their_entry) -{ - git_index_entry *entries[3] = { 0 }; - unsigned short i; - int ret = 0; - - GIT_ASSERT_ARG(index); - - if ((ancestor_entry && - (ret = index_entry_dup(&entries[0], index, ancestor_entry)) < 0) || - (our_entry && - (ret = index_entry_dup(&entries[1], index, our_entry)) < 0) || - (their_entry && - (ret = index_entry_dup(&entries[2], index, their_entry)) < 0)) - goto on_error; - - /* Validate entries */ - for (i = 0; i < 3; i++) { - if (entries[i] && !valid_filemode(entries[i]->mode)) { - git_error_set(GIT_ERROR_INDEX, "invalid filemode for stage %d entry", - i + 1); - ret = -1; - goto on_error; - } - } - - /* Remove existing index entries for each path */ - for (i = 0; i < 3; i++) { - if (entries[i] == NULL) - continue; - - if ((ret = git_index_remove(index, entries[i]->path, 0)) != 0) { - if (ret != GIT_ENOTFOUND) - goto on_error; - - git_error_clear(); - ret = 0; - } - } - - /* Add the conflict entries */ - for (i = 0; i < 3; i++) { - if (entries[i] == NULL) - continue; - - /* Make sure stage is correct */ - GIT_INDEX_ENTRY_STAGE_SET(entries[i], i + 1); - - if ((ret = index_insert(index, &entries[i], 1, true, true, false)) < 0) - goto on_error; - - entries[i] = NULL; /* don't free if later entry fails */ - } - - return 0; - -on_error: - for (i = 0; i < 3; i++) { - if (entries[i] != NULL) - index_entry_free(entries[i]); - } - - return ret; -} - -static int index_conflict__get_byindex( - const git_index_entry **ancestor_out, - const git_index_entry **our_out, - const git_index_entry **their_out, - git_index *index, - size_t n) -{ - const git_index_entry *conflict_entry; - const char *path = NULL; - size_t count; - int stage, len = 0; - - GIT_ASSERT_ARG(ancestor_out); - GIT_ASSERT_ARG(our_out); - GIT_ASSERT_ARG(their_out); - GIT_ASSERT_ARG(index); - - *ancestor_out = NULL; - *our_out = NULL; - *their_out = NULL; - - for (count = git_index_entrycount(index); n < count; ++n) { - conflict_entry = git_vector_get(&index->entries, n); - - if (path && index->entries_cmp_path(conflict_entry->path, path) != 0) - break; - - stage = GIT_INDEX_ENTRY_STAGE(conflict_entry); - path = conflict_entry->path; - - switch (stage) { - case 3: - *their_out = conflict_entry; - len++; - break; - case 2: - *our_out = conflict_entry; - len++; - break; - case 1: - *ancestor_out = conflict_entry; - len++; - break; - default: - break; - }; - } - - return len; -} - -int git_index_conflict_get( - const git_index_entry **ancestor_out, - const git_index_entry **our_out, - const git_index_entry **their_out, - git_index *index, - const char *path) -{ - size_t pos; - int len = 0; - - GIT_ASSERT_ARG(ancestor_out); - GIT_ASSERT_ARG(our_out); - GIT_ASSERT_ARG(their_out); - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(path); - - *ancestor_out = NULL; - *our_out = NULL; - *their_out = NULL; - - if (git_index_find(&pos, index, path) < 0) - return GIT_ENOTFOUND; - - if ((len = index_conflict__get_byindex( - ancestor_out, our_out, their_out, index, pos)) < 0) - return len; - else if (len == 0) - return GIT_ENOTFOUND; - - return 0; -} - -static int index_conflict_remove(git_index *index, const char *path) -{ - size_t pos = 0; - git_index_entry *conflict_entry; - int error = 0; - - if (path != NULL && git_index_find(&pos, index, path) < 0) - return GIT_ENOTFOUND; - - while ((conflict_entry = git_vector_get(&index->entries, pos)) != NULL) { - - if (path != NULL && - index->entries_cmp_path(conflict_entry->path, path) != 0) - break; - - if (GIT_INDEX_ENTRY_STAGE(conflict_entry) == 0) { - pos++; - continue; - } - - if ((error = index_remove_entry(index, pos)) < 0) - break; - } - - return error; -} - -int git_index_conflict_remove(git_index *index, const char *path) -{ - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(path); - return index_conflict_remove(index, path); -} - -int git_index_conflict_cleanup(git_index *index) -{ - GIT_ASSERT_ARG(index); - return index_conflict_remove(index, NULL); -} - -int git_index_has_conflicts(const git_index *index) -{ - size_t i; - git_index_entry *entry; - - GIT_ASSERT_ARG(index); - - git_vector_foreach(&index->entries, i, entry) { - if (GIT_INDEX_ENTRY_STAGE(entry) > 0) - return 1; - } - - return 0; -} - -int git_index_iterator_new( - git_index_iterator **iterator_out, - git_index *index) -{ - git_index_iterator *it; - int error; - - GIT_ASSERT_ARG(iterator_out); - GIT_ASSERT_ARG(index); - - it = git__calloc(1, sizeof(git_index_iterator)); - GIT_ERROR_CHECK_ALLOC(it); - - if ((error = git_index_snapshot_new(&it->snap, index)) < 0) { - git__free(it); - return error; - } - - it->index = index; - - *iterator_out = it; - return 0; -} - -int git_index_iterator_next( - const git_index_entry **out, - git_index_iterator *it) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(it); - - if (it->cur >= git_vector_length(&it->snap)) - return GIT_ITEROVER; - - *out = (git_index_entry *)git_vector_get(&it->snap, it->cur++); - return 0; -} - -void git_index_iterator_free(git_index_iterator *it) -{ - if (it == NULL) - return; - - git_index_snapshot_release(&it->snap, it->index); - git__free(it); -} - -int git_index_conflict_iterator_new( - git_index_conflict_iterator **iterator_out, - git_index *index) -{ - git_index_conflict_iterator *it = NULL; - - GIT_ASSERT_ARG(iterator_out); - GIT_ASSERT_ARG(index); - - it = git__calloc(1, sizeof(git_index_conflict_iterator)); - GIT_ERROR_CHECK_ALLOC(it); - - it->index = index; - - *iterator_out = it; - return 0; -} - -int git_index_conflict_next( - const git_index_entry **ancestor_out, - const git_index_entry **our_out, - const git_index_entry **their_out, - git_index_conflict_iterator *iterator) -{ - const git_index_entry *entry; - int len; - - GIT_ASSERT_ARG(ancestor_out); - GIT_ASSERT_ARG(our_out); - GIT_ASSERT_ARG(their_out); - GIT_ASSERT_ARG(iterator); - - *ancestor_out = NULL; - *our_out = NULL; - *their_out = NULL; - - while (iterator->cur < iterator->index->entries.length) { - entry = git_index_get_byindex(iterator->index, iterator->cur); - - if (git_index_entry_is_conflict(entry)) { - if ((len = index_conflict__get_byindex( - ancestor_out, - our_out, - their_out, - iterator->index, - iterator->cur)) < 0) - return len; - - iterator->cur += len; - return 0; - } - - iterator->cur++; - } - - return GIT_ITEROVER; -} - -void git_index_conflict_iterator_free(git_index_conflict_iterator *iterator) -{ - if (iterator == NULL) - return; - - git__free(iterator); -} - -size_t git_index_name_entrycount(git_index *index) -{ - GIT_ASSERT_ARG(index); - return index->names.length; -} - -const git_index_name_entry *git_index_name_get_byindex( - git_index *index, size_t n) -{ - GIT_ASSERT_ARG_WITH_RETVAL(index, NULL); - - git_vector_sort(&index->names); - return git_vector_get(&index->names, n); -} - -static void index_name_entry_free(git_index_name_entry *ne) -{ - if (!ne) - return; - git__free(ne->ancestor); - git__free(ne->ours); - git__free(ne->theirs); - git__free(ne); -} - -int git_index_name_add(git_index *index, - const char *ancestor, const char *ours, const char *theirs) -{ - git_index_name_entry *conflict_name; - - GIT_ASSERT_ARG((ancestor && ours) || (ancestor && theirs) || (ours && theirs)); - - conflict_name = git__calloc(1, sizeof(git_index_name_entry)); - GIT_ERROR_CHECK_ALLOC(conflict_name); - - if ((ancestor && !(conflict_name->ancestor = git__strdup(ancestor))) || - (ours && !(conflict_name->ours = git__strdup(ours))) || - (theirs && !(conflict_name->theirs = git__strdup(theirs))) || - git_vector_insert(&index->names, conflict_name) < 0) - { - index_name_entry_free(conflict_name); - return -1; - } - - index->dirty = 1; - return 0; -} - -int git_index_name_clear(git_index *index) -{ - size_t i; - git_index_name_entry *conflict_name; - - GIT_ASSERT_ARG(index); - - git_vector_foreach(&index->names, i, conflict_name) - index_name_entry_free(conflict_name); - - git_vector_clear(&index->names); - - index->dirty = 1; - - return 0; -} - -size_t git_index_reuc_entrycount(git_index *index) -{ - GIT_ASSERT_ARG(index); - return index->reuc.length; -} - -static int index_reuc_on_dup(void **old, void *new) -{ - index_entry_reuc_free(*old); - *old = new; - return GIT_EEXISTS; -} - -static int index_reuc_insert( - git_index *index, - git_index_reuc_entry *reuc) -{ - int res; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(reuc && reuc->path != NULL); - GIT_ASSERT(git_vector_is_sorted(&index->reuc)); - - res = git_vector_insert_sorted(&index->reuc, reuc, &index_reuc_on_dup); - index->dirty = 1; - - return res == GIT_EEXISTS ? 0 : res; -} - -int git_index_reuc_add(git_index *index, const char *path, - int ancestor_mode, const git_oid *ancestor_oid, - int our_mode, const git_oid *our_oid, - int their_mode, const git_oid *their_oid) -{ - git_index_reuc_entry *reuc = NULL; - int error = 0; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(path); - - if ((error = index_entry_reuc_init(&reuc, path, ancestor_mode, - ancestor_oid, our_mode, our_oid, their_mode, their_oid)) < 0 || - (error = index_reuc_insert(index, reuc)) < 0) - index_entry_reuc_free(reuc); - - return error; -} - -int git_index_reuc_find(size_t *at_pos, git_index *index, const char *path) -{ - return git_vector_bsearch2(at_pos, &index->reuc, index->reuc_search, path); -} - -const git_index_reuc_entry *git_index_reuc_get_bypath( - git_index *index, const char *path) -{ - size_t pos; - - GIT_ASSERT_ARG_WITH_RETVAL(index, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(path, NULL); - - if (!index->reuc.length) - return NULL; - - GIT_ASSERT_WITH_RETVAL(git_vector_is_sorted(&index->reuc), NULL); - - if (git_index_reuc_find(&pos, index, path) < 0) - return NULL; - - return git_vector_get(&index->reuc, pos); -} - -const git_index_reuc_entry *git_index_reuc_get_byindex( - git_index *index, size_t n) -{ - GIT_ASSERT_ARG_WITH_RETVAL(index, NULL); - GIT_ASSERT_WITH_RETVAL(git_vector_is_sorted(&index->reuc), NULL); - - return git_vector_get(&index->reuc, n); -} - -int git_index_reuc_remove(git_index *index, size_t position) -{ - int error; - git_index_reuc_entry *reuc; - - GIT_ASSERT_ARG(index); - GIT_ASSERT(git_vector_is_sorted(&index->reuc)); - - reuc = git_vector_get(&index->reuc, position); - error = git_vector_remove(&index->reuc, position); - - if (!error) - index_entry_reuc_free(reuc); - - index->dirty = 1; - return error; -} - -int git_index_reuc_clear(git_index *index) -{ - size_t i; - - GIT_ASSERT_ARG(index); - - for (i = 0; i < index->reuc.length; ++i) - index_entry_reuc_free(git_atomic_swap(index->reuc.contents[i], NULL)); - - git_vector_clear(&index->reuc); - - index->dirty = 1; - - return 0; -} - -static int index_error_invalid(const char *message) -{ - git_error_set(GIT_ERROR_INDEX, "invalid data in index - %s", message); - return -1; -} - -static int read_reuc(git_index *index, const char *buffer, size_t size) -{ - const char *endptr; - size_t oid_size = git_oid_size(index->oid_type); - size_t len; - int i; - - /* If called multiple times, the vector might already be initialized */ - if (index->reuc._alloc_size == 0 && - git_vector_init(&index->reuc, 16, reuc_cmp) < 0) - return -1; - - while (size) { - git_index_reuc_entry *lost; - - len = p_strnlen(buffer, size) + 1; - if (size <= len) - return index_error_invalid("reading reuc entries"); - - lost = reuc_entry_alloc(buffer); - GIT_ERROR_CHECK_ALLOC(lost); - - size -= len; - buffer += len; - - /* read 3 ASCII octal numbers for stage entries */ - for (i = 0; i < 3; i++) { - int64_t tmp; - - if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 || - !endptr || endptr == buffer || *endptr || - tmp < 0 || tmp > UINT32_MAX) { - index_entry_reuc_free(lost); - return index_error_invalid("reading reuc entry stage"); - } - - lost->mode[i] = (uint32_t)tmp; - - len = (endptr + 1) - buffer; - if (size <= len) { - index_entry_reuc_free(lost); - return index_error_invalid("reading reuc entry stage"); - } - - size -= len; - buffer += len; - } - - /* read up to 3 OIDs for stage entries */ - for (i = 0; i < 3; i++) { - if (!lost->mode[i]) - continue; - if (size < oid_size) { - index_entry_reuc_free(lost); - return index_error_invalid("reading reuc entry oid"); - } - - if (git_oid__fromraw(&lost->oid[i], (const unsigned char *) buffer, index->oid_type) < 0) - return -1; - - size -= oid_size; - buffer += oid_size; - } - - /* entry was read successfully - insert into reuc vector */ - if (git_vector_insert(&index->reuc, lost) < 0) - return -1; - } - - /* entries are guaranteed to be sorted on-disk */ - git_vector_set_sorted(&index->reuc, true); - - return 0; -} - - -static int read_conflict_names(git_index *index, const char *buffer, size_t size) -{ - size_t len; - - /* This gets called multiple times, the vector might already be initialized */ - if (index->names._alloc_size == 0 && - git_vector_init(&index->names, 16, conflict_name_cmp) < 0) - return -1; - -#define read_conflict_name(ptr) \ - len = p_strnlen(buffer, size) + 1; \ - if (size < len) { \ - index_error_invalid("reading conflict name entries"); \ - goto out_err; \ - } \ - if (len == 1) \ - ptr = NULL; \ - else { \ - ptr = git__malloc(len); \ - GIT_ERROR_CHECK_ALLOC(ptr); \ - memcpy(ptr, buffer, len); \ - } \ - \ - buffer += len; \ - size -= len; - - while (size) { - git_index_name_entry *conflict_name = git__calloc(1, sizeof(git_index_name_entry)); - GIT_ERROR_CHECK_ALLOC(conflict_name); - - read_conflict_name(conflict_name->ancestor); - read_conflict_name(conflict_name->ours); - read_conflict_name(conflict_name->theirs); - - if (git_vector_insert(&index->names, conflict_name) < 0) - goto out_err; - - continue; - -out_err: - git__free(conflict_name->ancestor); - git__free(conflict_name->ours); - git__free(conflict_name->theirs); - git__free(conflict_name); - return -1; - } - -#undef read_conflict_name - - /* entries are guaranteed to be sorted on-disk */ - git_vector_set_sorted(&index->names, true); - - return 0; -} - -GIT_INLINE(size_t) index_entry_path_offset( - git_oid_t oid_type, - uint32_t flags) -{ - if (oid_type == GIT_OID_SHA1) - return (flags & GIT_INDEX_ENTRY_EXTENDED) ? - offsetof(index_entry_long_sha1, path) : - offsetof(index_entry_short_sha1, path); - -#ifdef GIT_EXPERIMENTAL_SHA256 - else if (oid_type == GIT_OID_SHA256) - return (flags & GIT_INDEX_ENTRY_EXTENDED) ? - offsetof(index_entry_long_sha256, path) : - offsetof(index_entry_short_sha256, path); -#endif - - git_error_set(GIT_ERROR_INTERNAL, "invalid oid type"); - return 0; -} - -GIT_INLINE(size_t) index_entry_flags_offset(git_oid_t oid_type) -{ - if (oid_type == GIT_OID_SHA1) - return offsetof(index_entry_long_sha1, flags_extended); - -#ifdef GIT_EXPERIMENTAL_SHA256 - else if (oid_type == GIT_OID_SHA256) - return offsetof(index_entry_long_sha256, flags_extended); -#endif - - git_error_set(GIT_ERROR_INTERNAL, "invalid oid type"); - return 0; -} - -static size_t index_entry_size( - size_t path_len, - size_t varint_len, - git_oid_t oid_type, - uint32_t flags) -{ - size_t offset, size; - - if (!(offset = index_entry_path_offset(oid_type, flags))) - return 0; - - if (varint_len) { - if (GIT_ADD_SIZET_OVERFLOW(&size, offset, path_len) || - GIT_ADD_SIZET_OVERFLOW(&size, size, 1) || - GIT_ADD_SIZET_OVERFLOW(&size, size, varint_len)) - return 0; - } else { - if (GIT_ADD_SIZET_OVERFLOW(&size, offset, path_len) || - GIT_ADD_SIZET_OVERFLOW(&size, size, 8)) - return 0; - - size &= ~7; - } - - return size; -} - -static int read_entry( - git_index_entry **out, - size_t *out_size, - git_index *index, - size_t checksum_size, - const void *buffer, - size_t buffer_size, - const char *last) -{ - size_t path_length, path_offset, entry_size; - const char *path_ptr; - struct entry_common *source_common = NULL; - index_entry_short_sha1 source_sha1; -#ifdef GIT_EXPERIMENTAL_SHA256 - index_entry_short_sha256 source_sha256; -#endif - git_index_entry entry = {{0}}; - bool compressed = index->version >= INDEX_VERSION_NUMBER_COMP; - char *tmp_path = NULL; - - size_t minimal_entry_size = index_entry_path_offset(index->oid_type, 0); - - if (checksum_size + minimal_entry_size > buffer_size) - return -1; - - /* buffer is not guaranteed to be aligned */ - switch (index->oid_type) { - case GIT_OID_SHA1: - source_common = &source_sha1.common; - memcpy(&source_sha1, buffer, sizeof(source_sha1)); - break; -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - source_common = &source_sha256.common; - memcpy(&source_sha256, buffer, sizeof(source_sha256)); - break; -#endif - default: - GIT_ASSERT(!"invalid oid type"); - } - - entry.ctime.seconds = (git_time_t)ntohl(source_common->ctime.seconds); - entry.ctime.nanoseconds = ntohl(source_common->ctime.nanoseconds); - entry.mtime.seconds = (git_time_t)ntohl(source_common->mtime.seconds); - entry.mtime.nanoseconds = ntohl(source_common->mtime.nanoseconds); - entry.dev = ntohl(source_common->dev); - entry.ino = ntohl(source_common->ino); - entry.mode = ntohl(source_common->mode); - entry.uid = ntohl(source_common->uid); - entry.gid = ntohl(source_common->gid); - entry.file_size = ntohl(source_common->file_size); - - switch (index->oid_type) { - case GIT_OID_SHA1: - if (git_oid__fromraw(&entry.id, source_sha1.oid, - GIT_OID_SHA1) < 0) - return -1; - entry.flags = ntohs(source_sha1.flags); - break; -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - if (git_oid__fromraw(&entry.id, source_sha256.oid, - GIT_OID_SHA256) < 0) - return -1; - entry.flags = ntohs(source_sha256.flags); - break; -#endif - default: - GIT_ASSERT(!"invalid oid type"); - } - - if (!(path_offset = index_entry_path_offset(index->oid_type, entry.flags))) - return -1; - - - if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) { - uint16_t flags_raw; - size_t flags_offset; - - if (!(flags_offset = index_entry_flags_offset(index->oid_type))) - return -1; - - memcpy(&flags_raw, (const char *)buffer + flags_offset, sizeof(flags_raw)); - flags_raw = ntohs(flags_raw); - - memcpy(&entry.flags_extended, &flags_raw, sizeof(flags_raw)); - path_ptr = (const char *)buffer + path_offset; - } else { - path_ptr = (const char *)buffer + path_offset; - } - - if (!compressed) { - path_length = entry.flags & GIT_INDEX_ENTRY_NAMEMASK; - - /* if this is a very long string, we must find its - * real length without overflowing */ - if (path_length == 0xFFF) { - const char *path_end; - - path_end = memchr(path_ptr, '\0', buffer_size); - if (path_end == NULL) - return index_error_invalid("invalid path name"); - - path_length = path_end - path_ptr; - } - - entry_size = index_entry_size(path_length, 0, index->oid_type, entry.flags); - entry.path = (char *)path_ptr; - } else { - size_t varint_len, last_len, prefix_len, suffix_len, path_len; - uintmax_t strip_len; - - strip_len = git_decode_varint((const unsigned char *)path_ptr, &varint_len); - last_len = strlen(last); - - if (varint_len == 0 || last_len < strip_len) - return index_error_invalid("incorrect prefix length"); - - prefix_len = last_len - (size_t)strip_len; - suffix_len = strlen(path_ptr + varint_len); - - GIT_ERROR_CHECK_ALLOC_ADD(&path_len, prefix_len, suffix_len); - GIT_ERROR_CHECK_ALLOC_ADD(&path_len, path_len, 1); - - if (path_len > GIT_PATH_MAX) - return index_error_invalid("unreasonable path length"); - - tmp_path = git__malloc(path_len); - GIT_ERROR_CHECK_ALLOC(tmp_path); - - memcpy(tmp_path, last, prefix_len); - memcpy(tmp_path + prefix_len, path_ptr + varint_len, suffix_len + 1); - - entry_size = index_entry_size(suffix_len, varint_len, index->oid_type, entry.flags); - entry.path = tmp_path; - } - - if (entry_size == 0) - return -1; - - if (checksum_size + entry_size > buffer_size) { - git_error_set(GIT_ERROR_INTERNAL, "invalid index checksum"); - return -1; - } - - if (index_entry_dup(out, index, &entry) < 0) { - git__free(tmp_path); - return -1; - } - - git__free(tmp_path); - *out_size = entry_size; - return 0; -} - -static int read_header(struct index_header *dest, const void *buffer) -{ - const struct index_header *source = buffer; - - dest->signature = ntohl(source->signature); - if (dest->signature != INDEX_HEADER_SIG) - return index_error_invalid("incorrect header signature"); - - dest->version = ntohl(source->version); - if (dest->version < INDEX_VERSION_NUMBER_LB || - dest->version > INDEX_VERSION_NUMBER_UB) - return index_error_invalid("incorrect header version"); - - dest->entry_count = ntohl(source->entry_count); - return 0; -} - -static int read_extension(size_t *read_len, git_index *index, size_t checksum_size, const char *buffer, size_t buffer_size) -{ - struct index_extension dest; - size_t total_size; - - /* buffer is not guaranteed to be aligned */ - memcpy(&dest, buffer, sizeof(struct index_extension)); - dest.extension_size = ntohl(dest.extension_size); - - total_size = dest.extension_size + sizeof(struct index_extension); - - if (dest.extension_size > total_size || - buffer_size < total_size || - buffer_size - total_size < checksum_size) { - index_error_invalid("extension is truncated"); - return -1; - } - - /* optional extension */ - if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') { - /* tree cache */ - if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) { - if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size, index->oid_type, &index->tree_pool) < 0) - return -1; - } else if (memcmp(dest.signature, INDEX_EXT_UNMERGED_SIG, 4) == 0) { - if (read_reuc(index, buffer + 8, dest.extension_size) < 0) - return -1; - } else if (memcmp(dest.signature, INDEX_EXT_CONFLICT_NAME_SIG, 4) == 0) { - if (read_conflict_names(index, buffer + 8, dest.extension_size) < 0) - return -1; - } - /* else, unsupported extension. We cannot parse this, but we can skip - * it by returning `total_size */ - } else { - /* we cannot handle non-ignorable extensions; - * in fact they aren't even defined in the standard */ - git_error_set(GIT_ERROR_INDEX, "unsupported mandatory extension: '%.4s'", dest.signature); - return -1; - } - - *read_len = total_size; - - return 0; -} - -static int parse_index(git_index *index, const char *buffer, size_t buffer_size) -{ - int error = 0; - unsigned int i; - struct index_header header = { 0 }; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - unsigned char zero_checksum[GIT_HASH_MAX_SIZE] = { 0 }; - size_t checksum_size = git_hash_size(git_oid_algorithm(index->oid_type)); - const char *last = NULL; - const char *empty = ""; - -#define seek_forward(_increase) { \ - if (_increase >= buffer_size) { \ - error = index_error_invalid("ran out of data while parsing"); \ - goto done; } \ - buffer += _increase; \ - buffer_size -= _increase;\ -} - - if (buffer_size < INDEX_HEADER_SIZE + checksum_size) - return index_error_invalid("insufficient buffer space"); - - /* - * Precalculate the hash of the files's contents -- we'll match - * it to the provided checksum in the footer. - */ - git_hash_buf(checksum, buffer, buffer_size - checksum_size, - git_oid_algorithm(index->oid_type)); - - /* Parse header */ - if ((error = read_header(&header, buffer)) < 0) - return error; - - index->version = header.version; - if (index->version >= INDEX_VERSION_NUMBER_COMP) - last = empty; - - seek_forward(INDEX_HEADER_SIZE); - - GIT_ASSERT(!index->entries.length); - - if ((error = git_index_entrymap_resize(&index->entries_map, header.entry_count)) < 0) - return error; - - /* Parse all the entries */ - for (i = 0; i < header.entry_count && buffer_size > checksum_size; ++i) { - git_index_entry *entry = NULL; - size_t entry_size; - - if ((error = read_entry(&entry, &entry_size, index, checksum_size, buffer, buffer_size, last)) < 0) { - error = index_error_invalid("invalid entry"); - goto done; - } - - if ((error = git_vector_insert(&index->entries, entry)) < 0) { - index_entry_free(entry); - goto done; - } - - if ((error = git_index_entrymap_put(&index->entries_map, entry)) < 0) { - index_entry_free(entry); - goto done; - } - error = 0; - - if (index->version >= INDEX_VERSION_NUMBER_COMP) - last = entry->path; - - seek_forward(entry_size); - } - - if (i != header.entry_count) { - error = index_error_invalid("header entries changed while parsing"); - goto done; - } - - /* There's still space for some extensions! */ - while (buffer_size > checksum_size) { - size_t extension_size; - - if ((error = read_extension(&extension_size, index, checksum_size, buffer, buffer_size)) < 0) { - goto done; - } - - seek_forward(extension_size); - } - - if (buffer_size != checksum_size) { - error = index_error_invalid( - "buffer size does not match index footer size"); - goto done; - } - - /* - * SHA-1 or SHA-256 (depending on the repository's object format) - * over the content of the index file before this checksum. - * Note: checksum may be 0 if the index was written by a client - * where index.skipHash was set to true. - */ - if (memcmp(zero_checksum, buffer, checksum_size) != 0 && - memcmp(checksum, buffer, checksum_size) != 0) { - error = index_error_invalid( - "calculated checksum does not match expected"); - goto done; - } - - memcpy(index->checksum, checksum, checksum_size); - -#undef seek_forward - - /* Entries are stored case-sensitively on disk, so re-sort now if - * in-memory index is supposed to be case-insensitive - */ - git_vector_set_sorted(&index->entries, !index->ignore_case); - git_vector_sort(&index->entries); - - index->dirty = 0; -done: - return error; -} - -static bool is_index_extended(git_index *index) -{ - size_t i, extended; - git_index_entry *entry; - - extended = 0; - - git_vector_foreach(&index->entries, i, entry) { - entry->flags &= ~GIT_INDEX_ENTRY_EXTENDED; - if (entry->flags_extended & GIT_INDEX_ENTRY_EXTENDED_FLAGS) { - extended++; - entry->flags |= GIT_INDEX_ENTRY_EXTENDED; - } - } - - return (extended > 0); -} - -static int write_disk_entry( - git_index *index, - git_filebuf *file, - git_index_entry *entry, - const char *last) -{ - void *mem = NULL; - struct entry_common *ondisk_common = NULL; - size_t path_len, path_offset, disk_size; - int varint_len = 0; - char *path; - const char *path_start = entry->path; - size_t same_len = 0; - - index_entry_short_sha1 ondisk_sha1; - index_entry_long_sha1 ondisk_ext_sha1; -#ifdef GIT_EXPERIMENTAL_SHA256 - index_entry_short_sha256 ondisk_sha256; - index_entry_long_sha256 ondisk_ext_sha256; -#endif - - switch (index->oid_type) { - case GIT_OID_SHA1: - ondisk_common = &ondisk_sha1.common; - break; -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - ondisk_common = &ondisk_sha256.common; - break; -#endif - default: - GIT_ASSERT(!"invalid oid type"); - } - - path_len = ((struct entry_internal *)entry)->pathlen; - - if (last) { - const char *last_c = last; - - while (*path_start == *last_c) { - if (!*path_start || !*last_c) - break; - ++path_start; - ++last_c; - ++same_len; - } - path_len -= same_len; - varint_len = git_encode_varint(NULL, 0, strlen(last) - same_len); - } - - disk_size = index_entry_size(path_len, varint_len, index->oid_type, entry->flags); - - if (!disk_size || git_filebuf_reserve(file, &mem, disk_size) < 0) - return -1; - - memset(mem, 0x0, disk_size); - - /** - * Yes, we have to truncate. - * - * The on-disk format for Index entries clearly defines - * the time and size fields to be 4 bytes each -- so even if - * we store these values with 8 bytes on-memory, they must - * be truncated to 4 bytes before writing to disk. - * - * In 2038 I will be either too dead or too rich to care about this - */ - ondisk_common->ctime.seconds = htonl((uint32_t)entry->ctime.seconds); - ondisk_common->mtime.seconds = htonl((uint32_t)entry->mtime.seconds); - ondisk_common->ctime.nanoseconds = htonl(entry->ctime.nanoseconds); - ondisk_common->mtime.nanoseconds = htonl(entry->mtime.nanoseconds); - ondisk_common->dev = htonl(entry->dev); - ondisk_common->ino = htonl(entry->ino); - ondisk_common->mode = htonl(entry->mode); - ondisk_common->uid = htonl(entry->uid); - ondisk_common->gid = htonl(entry->gid); - ondisk_common->file_size = htonl((uint32_t)entry->file_size); - - switch (index->oid_type) { - case GIT_OID_SHA1: - git_oid_raw_cpy(ondisk_sha1.oid, entry->id.id, GIT_OID_SHA1_SIZE); - ondisk_sha1.flags = htons(entry->flags); - break; -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - git_oid_raw_cpy(ondisk_sha256.oid, entry->id.id, GIT_OID_SHA256_SIZE); - ondisk_sha256.flags = htons(entry->flags); - break; -#endif - default: - GIT_ASSERT(!"invalid oid type"); - } - - path_offset = index_entry_path_offset(index->oid_type, entry->flags); - - if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) { - struct entry_common *ondisk_ext = NULL; - uint16_t flags_extended = htons(entry->flags_extended & - GIT_INDEX_ENTRY_EXTENDED_FLAGS); - - switch (index->oid_type) { - case GIT_OID_SHA1: - memcpy(&ondisk_ext_sha1, &ondisk_sha1, - sizeof(index_entry_short_sha1)); - ondisk_ext_sha1.flags_extended = flags_extended; - ondisk_ext = &ondisk_ext_sha1.common; - break; -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - memcpy(&ondisk_ext_sha256, &ondisk_sha256, - sizeof(index_entry_short_sha256)); - ondisk_ext_sha256.flags_extended = flags_extended; - ondisk_ext = &ondisk_ext_sha256.common; - break; -#endif - default: - GIT_ASSERT(!"invalid oid type"); - } - - memcpy(mem, ondisk_ext, path_offset); - } else { - switch (index->oid_type) { - case GIT_OID_SHA1: - memcpy(mem, &ondisk_sha1, path_offset); - break; -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - memcpy(mem, &ondisk_sha256, path_offset); - break; -#endif - default: - GIT_ASSERT(!"invalid oid type"); - } - } - - path = (char *)mem + path_offset; - disk_size -= path_offset; - - if (last) { - varint_len = git_encode_varint((unsigned char *) path, - disk_size, strlen(last) - same_len); - GIT_ASSERT(varint_len > 0); - - path += varint_len; - disk_size -= varint_len; - - /* - * If using path compression, we are not allowed - * to have additional trailing NULs. - */ - GIT_ASSERT(disk_size == path_len + 1); - } else { - /* - * If no path compression is used, we do have - * NULs as padding. As such, simply assert that - * we have enough space left to write the path. - */ - GIT_ASSERT(disk_size > path_len); - } - - memcpy(path, path_start, path_len + 1); - - return 0; -} - -static int write_entries(git_index *index, git_filebuf *file) -{ - int error = 0; - size_t i; - git_vector case_sorted = GIT_VECTOR_INIT, *entries = NULL; - git_index_entry *entry; - const char *last = NULL; - - /* If index->entries is sorted case-insensitively, then we need - * to re-sort it case-sensitively before writing */ - if (index->ignore_case) { - if ((error = git_vector_dup(&case_sorted, &index->entries, git_index_entry_cmp)) < 0) - goto done; - - git_vector_sort(&case_sorted); - entries = &case_sorted; - } else { - entries = &index->entries; - } - - if (index->version >= INDEX_VERSION_NUMBER_COMP) - last = ""; - - git_vector_foreach(entries, i, entry) { - if ((error = write_disk_entry(index, file, entry, last)) < 0) - break; - if (index->version >= INDEX_VERSION_NUMBER_COMP) - last = entry->path; - } - -done: - git_vector_dispose(&case_sorted); - return error; -} - -static int write_extension(git_filebuf *file, struct index_extension *header, git_str *data) -{ - struct index_extension ondisk; - - memset(&ondisk, 0x0, sizeof(struct index_extension)); - memcpy(&ondisk, header, 4); - ondisk.extension_size = htonl(header->extension_size); - - git_filebuf_write(file, &ondisk, sizeof(struct index_extension)); - return git_filebuf_write(file, data->ptr, data->size); -} - -static int create_name_extension_data(git_str *name_buf, git_index_name_entry *conflict_name) -{ - int error = 0; - - if (conflict_name->ancestor == NULL) - error = git_str_put(name_buf, "\0", 1); - else - error = git_str_put(name_buf, conflict_name->ancestor, strlen(conflict_name->ancestor) + 1); - - if (error != 0) - goto on_error; - - if (conflict_name->ours == NULL) - error = git_str_put(name_buf, "\0", 1); - else - error = git_str_put(name_buf, conflict_name->ours, strlen(conflict_name->ours) + 1); - - if (error != 0) - goto on_error; - - if (conflict_name->theirs == NULL) - error = git_str_put(name_buf, "\0", 1); - else - error = git_str_put(name_buf, conflict_name->theirs, strlen(conflict_name->theirs) + 1); - -on_error: - return error; -} - -static int write_name_extension(git_index *index, git_filebuf *file) -{ - git_str name_buf = GIT_STR_INIT; - git_vector *out = &index->names; - git_index_name_entry *conflict_name; - struct index_extension extension; - size_t i; - int error = 0; - - git_vector_foreach(out, i, conflict_name) { - if ((error = create_name_extension_data(&name_buf, conflict_name)) < 0) - goto done; - } - - memset(&extension, 0x0, sizeof(struct index_extension)); - memcpy(&extension.signature, INDEX_EXT_CONFLICT_NAME_SIG, 4); - extension.extension_size = (uint32_t)name_buf.size; - - error = write_extension(file, &extension, &name_buf); - - git_str_dispose(&name_buf); - -done: - return error; -} - -static int create_reuc_extension_data(git_str *reuc_buf, git_index *index, git_index_reuc_entry *reuc) -{ - size_t oid_size = git_oid_size(index->oid_type); - int i; - int error = 0; - - if ((error = git_str_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0) - return error; - - for (i = 0; i < 3; i++) { - if ((error = git_str_printf(reuc_buf, "%o", reuc->mode[i])) < 0 || - (error = git_str_put(reuc_buf, "\0", 1)) < 0) - return error; - } - - for (i = 0; i < 3; i++) { - if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, oid_size)) < 0) - return error; - } - - return 0; -} - -static int write_reuc_extension(git_index *index, git_filebuf *file) -{ - git_str reuc_buf = GIT_STR_INIT; - git_vector *out = &index->reuc; - git_index_reuc_entry *reuc; - struct index_extension extension; - size_t i; - int error = 0; - - git_vector_foreach(out, i, reuc) { - if ((error = create_reuc_extension_data(&reuc_buf, index, reuc)) < 0) - goto done; - } - - memset(&extension, 0x0, sizeof(struct index_extension)); - memcpy(&extension.signature, INDEX_EXT_UNMERGED_SIG, 4); - extension.extension_size = (uint32_t)reuc_buf.size; - - error = write_extension(file, &extension, &reuc_buf); - - git_str_dispose(&reuc_buf); - -done: - return error; -} - -static int write_tree_extension(git_index *index, git_filebuf *file) -{ - struct index_extension extension; - git_str buf = GIT_STR_INIT; - int error; - - if (index->tree == NULL) - return 0; - - if ((error = git_tree_cache_write(&buf, index->tree)) < 0) - return error; - - memset(&extension, 0x0, sizeof(struct index_extension)); - memcpy(&extension.signature, INDEX_EXT_TREECACHE_SIG, 4); - extension.extension_size = (uint32_t)buf.size; - - error = write_extension(file, &extension, &buf); - - git_str_dispose(&buf); - - return error; -} - -static void clear_uptodate(git_index *index) -{ - git_index_entry *entry; - size_t i; - - git_vector_foreach(&index->entries, i, entry) - entry->flags_extended &= ~GIT_INDEX_ENTRY_UPTODATE; -} - -static int write_index( - unsigned char checksum[GIT_HASH_MAX_SIZE], - size_t *checksum_size, - git_index *index, - git_filebuf *file) -{ - struct index_header header; - bool is_extended; - uint32_t index_version_number; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(file); - - GIT_ASSERT(index->oid_type); - - *checksum_size = git_hash_size(git_oid_algorithm(index->oid_type)); - - if (index->version <= INDEX_VERSION_NUMBER_EXT) { - is_extended = is_index_extended(index); - index_version_number = is_extended ? INDEX_VERSION_NUMBER_EXT : INDEX_VERSION_NUMBER_LB; - } else { - index_version_number = index->version; - } - - header.signature = htonl(INDEX_HEADER_SIG); - header.version = htonl(index_version_number); - header.entry_count = htonl((uint32_t)index->entries.length); - - if (git_filebuf_write(file, &header, sizeof(struct index_header)) < 0) - return -1; - - if (write_entries(index, file) < 0) - return -1; - - /* write the tree cache extension */ - if (index->tree != NULL && write_tree_extension(index, file) < 0) - return -1; - - /* write the rename conflict extension */ - if (index->names.length > 0 && write_name_extension(index, file) < 0) - return -1; - - /* write the reuc extension */ - if (index->reuc.length > 0 && write_reuc_extension(index, file) < 0) - return -1; - - /* get out the hash for all the contents we've appended to the file */ - git_filebuf_hash(checksum, file); - - /* write it at the end of the file */ - if (git_filebuf_write(file, checksum, *checksum_size) < 0) - return -1; - - /* file entries are no longer up to date */ - clear_uptodate(index); - - return 0; -} - -int git_index_entry_stage(const git_index_entry *entry) -{ - return GIT_INDEX_ENTRY_STAGE(entry); -} - -int git_index_entry_is_conflict(const git_index_entry *entry) -{ - return (GIT_INDEX_ENTRY_STAGE(entry) > 0); -} - -typedef struct read_tree_data { - git_index *index; - git_vector *old_entries; - git_vector *new_entries; - git_vector_cmp entry_cmp; - git_tree_cache *tree; -} read_tree_data; - -static int read_tree_cb( - const char *root, const git_tree_entry *tentry, void *payload) -{ - read_tree_data *data = payload; - git_index_entry *entry = NULL, *old_entry; - git_str path = GIT_STR_INIT; - size_t pos; - - if (git_tree_entry__is_tree(tentry)) - return 0; - - if (git_str_joinpath(&path, root, tentry->filename) < 0) - return -1; - - if (index_entry_create(&entry, INDEX_OWNER(data->index), path.ptr, NULL, false) < 0) - return -1; - - entry->mode = tentry->attr; - git_oid_cpy(&entry->id, git_tree_entry_id(tentry)); - - /* look for corresponding old entry and copy data to new entry */ - if (data->old_entries != NULL && - !index_find_in_entries( - &pos, data->old_entries, data->entry_cmp, path.ptr, 0, 0) && - (old_entry = git_vector_get(data->old_entries, pos)) != NULL && - entry->mode == old_entry->mode && - git_oid_equal(&entry->id, &old_entry->id)) - { - index_entry_cpy(entry, old_entry); - entry->flags_extended = 0; - } - - index_entry_adjust_namemask(entry, path.size); - git_str_dispose(&path); - - if (git_vector_insert(data->new_entries, entry) < 0) { - index_entry_free(entry); - return -1; - } - - return 0; -} - -int git_index_read_tree(git_index *index, const git_tree *tree) -{ - int error = 0; - git_vector entries = GIT_VECTOR_INIT; - git_index_entrymap entries_map = GIT_INDEX_ENTRYMAP_INIT; - read_tree_data data; - size_t i; - git_index_entry *e; - - git_vector_set_cmp(&entries, index->entries._cmp); /* match sort */ - - data.index = index; - data.old_entries = &index->entries; - data.new_entries = &entries; - data.entry_cmp = index->entries_search; - - index->tree = NULL; - git_pool_clear(&index->tree_pool); - - git_vector_sort(&index->entries); - - if ((error = git_tree_walk(tree, GIT_TREEWALK_POST, read_tree_cb, &data)) < 0) - goto cleanup; - - if ((error = git_index_entrymap_resize(&entries_map, entries.length)) < 0) - goto cleanup; - - git_vector_foreach(&entries, i, e) { - if ((error = git_index_entrymap_put(&entries_map, e)) < 0) { - git_error_set(GIT_ERROR_INDEX, "failed to insert entry into map"); - return error; - } - } - - error = 0; - - git_vector_sort(&entries); - - if ((error = git_index_clear(index)) < 0) - goto cleanup; - - git_vector_swap(&entries, &index->entries); - git_index_entrymap_swap(&entries_map, &index->entries_map); - - index->dirty = 1; - -cleanup: - git_vector_dispose(&entries); - git_index_entrymap_dispose(&entries_map); - - if (error < 0) - return error; - - error = git_tree_cache_read_tree(&index->tree, tree, index->oid_type, &index->tree_pool); - - return error; -} - -static int git_index_read_iterator( - git_index *index, - git_iterator *new_iterator, - size_t new_length_hint) -{ - git_vector new_entries = GIT_VECTOR_INIT, - remove_entries = GIT_VECTOR_INIT; - git_index_entrymap new_entries_map = GIT_INDEX_ENTRYMAP_INIT; - git_iterator *index_iterator = NULL; - git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT; - const git_index_entry *old_entry, *new_entry; - git_index_entry *entry; - size_t i; - int error; - - GIT_ASSERT((new_iterator->flags & GIT_ITERATOR_DONT_IGNORE_CASE)); - - if ((error = git_vector_init(&new_entries, new_length_hint, index->entries._cmp)) < 0 || - (error = git_vector_init(&remove_entries, index->entries.length, NULL)) < 0) - goto done; - - if (new_length_hint && - (error = git_index_entrymap_resize(&new_entries_map, new_length_hint)) < 0) - goto done; - - opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | - GIT_ITERATOR_INCLUDE_CONFLICTS; - - if ((error = git_iterator_for_index(&index_iterator, - git_index_owner(index), index, &opts)) < 0 || - ((error = git_iterator_current(&old_entry, index_iterator)) < 0 && - error != GIT_ITEROVER) || - ((error = git_iterator_current(&new_entry, new_iterator)) < 0 && - error != GIT_ITEROVER)) - goto done; - - while (true) { - git_index_entry - *dup_entry = NULL, - *add_entry = NULL, - *remove_entry = NULL; - int diff; - - error = 0; - - if (old_entry && new_entry) - diff = git_index_entry_cmp(old_entry, new_entry); - else if (!old_entry && new_entry) - diff = 1; - else if (old_entry && !new_entry) - diff = -1; - else - break; - - if (diff < 0) { - remove_entry = (git_index_entry *)old_entry; - } else if (diff > 0) { - dup_entry = (git_index_entry *)new_entry; - } else { - /* Path and stage are equal, if the OID is equal, keep it to - * keep the stat cache data. - */ - if (git_oid_equal(&old_entry->id, &new_entry->id) && - old_entry->mode == new_entry->mode) { - add_entry = (git_index_entry *)old_entry; - } else { - dup_entry = (git_index_entry *)new_entry; - remove_entry = (git_index_entry *)old_entry; - } - } - - if (dup_entry) { - if ((error = index_entry_dup_nocache(&add_entry, index, dup_entry)) < 0) - goto done; - - index_entry_adjust_namemask(add_entry, - ((struct entry_internal *)add_entry)->pathlen); - } - - /* invalidate this path in the tree cache if this is new (to - * invalidate the parent trees) - */ - if (dup_entry && !remove_entry && index->tree) - git_tree_cache_invalidate_path(index->tree, dup_entry->path); - - if (add_entry) { - if ((error = git_vector_insert(&new_entries, add_entry)) == 0) - error = git_index_entrymap_put(&new_entries_map, add_entry); - } - - if (remove_entry && error >= 0) - error = git_vector_insert(&remove_entries, remove_entry); - - if (error < 0) { - git_error_set(GIT_ERROR_INDEX, "failed to insert entry"); - goto done; - } - - if (diff <= 0) { - if ((error = git_iterator_advance(&old_entry, index_iterator)) < 0 && - error != GIT_ITEROVER) - goto done; - } - - if (diff >= 0) { - if ((error = git_iterator_advance(&new_entry, new_iterator)) < 0 && - error != GIT_ITEROVER) - goto done; - } - } - - if ((error = git_index_name_clear(index)) < 0 || - (error = git_index_reuc_clear(index)) < 0) - goto done; - - git_vector_swap(&new_entries, &index->entries); - git_index_entrymap_swap(&index->entries_map, &new_entries_map); - - git_vector_foreach(&remove_entries, i, entry) { - if (index->tree) - git_tree_cache_invalidate_path(index->tree, entry->path); - - index_entry_free(entry); - } - - clear_uptodate(index); - - index->dirty = 1; - error = 0; - -done: - git_index_entrymap_dispose(&new_entries_map); - git_vector_dispose(&new_entries); - git_vector_dispose(&remove_entries); - git_iterator_free(index_iterator); - return error; -} - -int git_index_read_index( - git_index *index, - const git_index *new_index) -{ - git_iterator *new_iterator = NULL; - git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT; - int error; - - opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | - GIT_ITERATOR_INCLUDE_CONFLICTS; - - if ((error = git_iterator_for_index(&new_iterator, - git_index_owner(new_index), (git_index *)new_index, &opts)) < 0 || - (error = git_index_read_iterator(index, new_iterator, - new_index->entries.length)) < 0) - goto done; - -done: - git_iterator_free(new_iterator); - return error; -} - -git_repository *git_index_owner(const git_index *index) -{ - return INDEX_OWNER(index); -} - -enum { - INDEX_ACTION_NONE = 0, - INDEX_ACTION_UPDATE = 1, - INDEX_ACTION_REMOVE = 2, - INDEX_ACTION_ADDALL = 3 -}; - -int git_index_add_all( - git_index *index, - const git_strarray *paths, - unsigned int flags, - git_index_matched_path_cb cb, - void *payload) -{ - int error; - git_repository *repo; - git_pathspec ps; - bool no_fnmatch = (flags & GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH) != 0; - - GIT_ASSERT_ARG(index); - - repo = INDEX_OWNER(index); - if ((error = git_repository__ensure_not_bare(repo, "index add all")) < 0) - return error; - - if ((error = git_pathspec__init(&ps, paths)) < 0) - return error; - - /* optionally check that pathspec doesn't mention any ignored files */ - if ((flags & GIT_INDEX_ADD_CHECK_PATHSPEC) != 0 && - (flags & GIT_INDEX_ADD_FORCE) == 0 && - (error = git_ignore__check_pathspec_for_exact_ignores( - repo, &ps.pathspec, no_fnmatch)) < 0) - goto cleanup; - - error = index_apply_to_wd_diff(index, INDEX_ACTION_ADDALL, paths, flags, cb, payload); - - if (error) - git_error_set_after_callback(error); - -cleanup: - git_pathspec__clear(&ps); - - return error; -} - -struct foreach_diff_data { - git_index *index; - const git_pathspec *pathspec; - unsigned int flags; - git_index_matched_path_cb cb; - void *payload; -}; - -static int apply_each_file(const git_diff_delta *delta, float progress, void *payload) -{ - struct foreach_diff_data *data = payload; - const char *match, *path; - int error = 0; - - GIT_UNUSED(progress); - - path = delta->old_file.path; - - /* We only want those which match the pathspecs */ - if (!git_pathspec__match( - &data->pathspec->pathspec, path, false, (bool)data->index->ignore_case, - &match, NULL)) - return 0; - - if (data->cb) - error = data->cb(path, match, data->payload); - - if (error > 0) /* skip this entry */ - return 0; - if (error < 0) /* actual error */ - return error; - - /* If the workdir item does not exist, remove it from the index. */ - if ((delta->new_file.flags & GIT_DIFF_FLAG_EXISTS) == 0) - error = git_index_remove_bypath(data->index, path); - else - error = git_index_add_bypath(data->index, delta->new_file.path); - - return error; -} - -static int index_apply_to_wd_diff(git_index *index, int action, const git_strarray *paths, - unsigned int flags, - git_index_matched_path_cb cb, void *payload) -{ - int error; - git_diff *diff; - git_pathspec ps; - git_repository *repo; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - struct foreach_diff_data data = { - index, - NULL, - flags, - cb, - payload, - }; - - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL); - - repo = INDEX_OWNER(index); - - if (!repo) { - return create_index_error(-1, - "cannot run update; the index is not backed up by a repository."); - } - - /* - * We do the matching ourselves instead of passing the list to - * diff because we want to tell the callback which one - * matched, which we do not know if we ask diff to filter for us. - */ - if ((error = git_pathspec__init(&ps, paths)) < 0) - return error; - - opts.flags = GIT_DIFF_INCLUDE_TYPECHANGE; - if (action == INDEX_ACTION_ADDALL) { - opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED | - GIT_DIFF_RECURSE_UNTRACKED_DIRS; - - if (flags == GIT_INDEX_ADD_FORCE) - opts.flags |= GIT_DIFF_INCLUDE_IGNORED | - GIT_DIFF_RECURSE_IGNORED_DIRS; - } - - if ((error = git_diff_index_to_workdir(&diff, repo, index, &opts)) < 0) - goto cleanup; - - data.pathspec = &ps; - error = git_diff_foreach(diff, apply_each_file, NULL, NULL, NULL, &data); - git_diff_free(diff); - - if (error) /* make sure error is set if callback stopped iteration */ - git_error_set_after_callback(error); - -cleanup: - git_pathspec__clear(&ps); - return error; -} - -static int index_apply_to_all( - git_index *index, - int action, - const git_strarray *paths, - git_index_matched_path_cb cb, - void *payload) -{ - int error = 0; - size_t i; - git_pathspec ps; - const char *match; - git_str path = GIT_STR_INIT; - - GIT_ASSERT_ARG(index); - - if ((error = git_pathspec__init(&ps, paths)) < 0) - return error; - - git_vector_sort(&index->entries); - - for (i = 0; !error && i < index->entries.length; ++i) { - git_index_entry *entry = git_vector_get(&index->entries, i); - - /* check if path actually matches */ - if (!git_pathspec__match( - &ps.pathspec, entry->path, false, (bool)index->ignore_case, - &match, NULL)) - continue; - - /* issue notification callback if requested */ - if (cb && (error = cb(entry->path, match, payload)) != 0) { - if (error > 0) { /* return > 0 means skip this one */ - error = 0; - continue; - } - if (error < 0) /* return < 0 means abort */ - break; - } - - /* index manipulation may alter entry, so don't depend on it */ - if ((error = git_str_sets(&path, entry->path)) < 0) - break; - - switch (action) { - case INDEX_ACTION_NONE: - break; - case INDEX_ACTION_UPDATE: - error = git_index_add_bypath(index, path.ptr); - - if (error == GIT_ENOTFOUND) { - git_error_clear(); - - error = git_index_remove_bypath(index, path.ptr); - - if (!error) /* back up foreach if we removed this */ - i--; - } - break; - case INDEX_ACTION_REMOVE: - if (!(error = git_index_remove_bypath(index, path.ptr))) - i--; /* back up foreach if we removed this */ - break; - default: - git_error_set(GIT_ERROR_INVALID, "unknown index action %d", action); - error = -1; - break; - } - } - - git_str_dispose(&path); - git_pathspec__clear(&ps); - - return error; -} - -int git_index_remove_all( - git_index *index, - const git_strarray *pathspec, - git_index_matched_path_cb cb, - void *payload) -{ - int error = index_apply_to_all( - index, INDEX_ACTION_REMOVE, pathspec, cb, payload); - - if (error) /* make sure error is set if callback stopped iteration */ - git_error_set_after_callback(error); - - return error; -} - -int git_index_update_all( - git_index *index, - const git_strarray *pathspec, - git_index_matched_path_cb cb, - void *payload) -{ - int error = index_apply_to_wd_diff(index, INDEX_ACTION_UPDATE, pathspec, 0, cb, payload); - if (error) /* make sure error is set if callback stopped iteration */ - git_error_set_after_callback(error); - - return error; -} - -int git_index_snapshot_new(git_vector *snap, git_index *index) -{ - int error; - - GIT_REFCOUNT_INC(index); - - git_atomic32_inc(&index->readers); - git_vector_sort(&index->entries); - - error = git_vector_dup(snap, &index->entries, index->entries._cmp); - - if (error < 0) - git_index_snapshot_release(snap, index); - - return error; -} - -void git_index_snapshot_release(git_vector *snap, git_index *index) -{ - git_vector_dispose(snap); - - git_atomic32_dec(&index->readers); - - git_index_free(index); -} - -int git_index_snapshot_find( - size_t *out, git_vector *entries, git_vector_cmp entry_srch, - const char *path, size_t path_len, int stage) -{ - return index_find_in_entries(out, entries, entry_srch, path, path_len, stage); -} - -int git_indexwriter_init( - git_indexwriter *writer, - git_index *index) -{ - int filebuf_hash, error; - - GIT_REFCOUNT_INC(index); - - writer->index = index; - - filebuf_hash = git_filebuf_hash_flags(git_oid_algorithm(index->oid_type)); - GIT_ASSERT(filebuf_hash); - - if (!index->index_file_path) - return create_index_error(-1, - "failed to write index: The index is in-memory only"); - - if ((error = git_filebuf_open(&writer->file, - index->index_file_path, - git_filebuf_hash_flags(filebuf_hash), - GIT_INDEX_FILE_MODE)) < 0) { - if (error == GIT_ELOCKED) - git_error_set(GIT_ERROR_INDEX, "the index is locked; this might be due to a concurrent or crashed process"); - - return error; - } - - writer->should_write = 1; - - return 0; -} - -int git_indexwriter_init_for_operation( - git_indexwriter *writer, - git_repository *repo, - unsigned int *checkout_strategy) -{ - git_index *index; - int error; - - if ((error = git_repository_index__weakptr(&index, repo)) < 0 || - (error = git_indexwriter_init(writer, index)) < 0) - return error; - - writer->should_write = (*checkout_strategy & GIT_CHECKOUT_DONT_WRITE_INDEX) == 0; - *checkout_strategy |= GIT_CHECKOUT_DONT_WRITE_INDEX; - - return 0; -} - -int git_indexwriter_commit(git_indexwriter *writer) -{ - unsigned char checksum[GIT_HASH_MAX_SIZE]; - size_t checksum_size; - int error; - - if (!writer->should_write) - return 0; - - git_vector_sort(&writer->index->entries); - git_vector_sort(&writer->index->reuc); - - if ((error = write_index(checksum, &checksum_size, writer->index, &writer->file)) < 0) { - git_indexwriter_cleanup(writer); - return error; - } - - if ((error = git_filebuf_commit(&writer->file)) < 0) - return error; - - if ((error = git_futils_filestamp_check( - &writer->index->stamp, writer->index->index_file_path)) < 0) { - git_error_set(GIT_ERROR_OS, "could not read index timestamp"); - return -1; - } - - writer->index->dirty = 0; - writer->index->on_disk = 1; - memcpy(writer->index->checksum, checksum, checksum_size); - - git_index_free(writer->index); - writer->index = NULL; - - return 0; -} - -void git_indexwriter_cleanup(git_indexwriter *writer) -{ - git_filebuf_cleanup(&writer->file); - - git_index_free(writer->index); - writer->index = NULL; -} - -/* Deprecated functions */ - -#ifndef GIT_DEPRECATE_HARD -int git_index_add_frombuffer( - git_index *index, const git_index_entry *source_entry, - const void *buffer, size_t len) -{ - return git_index_add_from_buffer(index, source_entry, buffer, len); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/index.h b/vendor/libgit2-sys/libgit2/src/libgit2/index.h deleted file mode 100644 index de8a9cf..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/index.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_index_h__ -#define INCLUDE_index_h__ - -#include "common.h" - -#include "futils.h" -#include "filebuf.h" -#include "vector.h" -#include "tree-cache.h" -#include "index_map.h" -#include "git2/odb.h" -#include "git2/index.h" - -#define GIT_INDEX_FILE "index" -#define GIT_INDEX_FILE_MODE 0666 - -extern bool git_index__enforce_unsaved_safety; - -struct git_index { - git_refcount rc; - - char *index_file_path; - git_futils_filestamp stamp; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - - git_vector entries; - git_index_entrymap entries_map; - - git_vector deleted; /* deleted entries if readers > 0 */ - git_atomic32 readers; /* number of active iterators */ - - git_oid_t oid_type; - - unsigned int on_disk:1; - unsigned int ignore_case:1; - unsigned int distrust_filemode:1; - unsigned int no_symlinks:1; - unsigned int dirty:1; /* whether we have unsaved changes */ - - git_tree_cache *tree; - git_pool tree_pool; - - git_vector names; - git_vector reuc; - - git_vector_cmp entries_cmp_path; - git_vector_cmp entries_search; - git_vector_cmp entries_search_path; - git_vector_cmp reuc_search; - - unsigned int version; -}; - -struct git_index_iterator { - git_index *index; - git_vector snap; - size_t cur; -}; - -struct git_index_conflict_iterator { - git_index *index; - size_t cur; -}; - -extern void git_index_entry__init_from_stat( - git_index_entry *entry, struct stat *st, bool trust_mode); - -/* Index entry comparison functions for array sorting */ -extern int git_index_entry_cmp(const void *a, const void *b); -extern int git_index_entry_icmp(const void *a, const void *b); - -/* Index entry search functions for search using a search spec */ -extern int git_index_entry_srch(const void *a, const void *b); -extern int git_index_entry_isrch(const void *a, const void *b); - -/* Index time handling functions */ -GIT_INLINE(bool) git_index_time_eq(const git_index_time *one, const git_index_time *two) -{ - if (one->seconds != two->seconds) - return false; - -#ifdef GIT_USE_NSEC - if (one->nanoseconds != two->nanoseconds) - return false; -#endif - - return true; -} - -/* - * Test if the given index time is newer than the given existing index entry. - * If the timestamps are exactly equivalent, then the given index time is - * considered "racily newer" than the existing index entry. - */ -GIT_INLINE(bool) git_index_entry_newer_than_index( - const git_index_entry *entry, git_index *index) -{ - /* If we never read the index, we can't have this race either */ - if (!index || index->stamp.mtime.tv_sec == 0) - return false; - - /* If the timestamp is the same or newer than the index, it's racy */ -#if defined(GIT_USE_NSEC) - if ((int32_t)index->stamp.mtime.tv_sec < entry->mtime.seconds) - return true; - else if ((int32_t)index->stamp.mtime.tv_sec > entry->mtime.seconds) - return false; - else - return (uint32_t)index->stamp.mtime.tv_nsec <= entry->mtime.nanoseconds; -#else - return ((int32_t)index->stamp.mtime.tv_sec) <= entry->mtime.seconds; -#endif -} - -/* Search index for `path`, returning GIT_ENOTFOUND if it does not exist - * (but not setting an error message). - * - * `at_pos` is set to the position where it is or would be inserted. - * Pass `path_len` as strlen of path or 0 to call strlen internally. - */ -extern int git_index__find_pos( - size_t *at_pos, git_index *index, const char *path, size_t path_len, int stage); - -extern int git_index__fill(git_index *index, const git_vector *source_entries); - -extern void git_index__set_ignore_case(git_index *index, bool ignore_case); - -extern unsigned int git_index__create_mode(unsigned int mode); - -GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index) -{ - return &index->stamp; -} - -GIT_INLINE(unsigned char *) git_index__checksum(git_index *index) -{ - return index->checksum; -} - -/* SHA256-aware internal functions */ - -extern int git_index__new( - git_index **index_out, - git_oid_t oid_type); - -extern int git_index__open( - git_index **index_out, - const char *index_path, - git_oid_t oid_type); - -/* If the path is conflicted, move it from the index to reuc. */ -int git_index__conflict_to_reuc(git_index *index, const char *path); - -/* Copy the current entries vector *and* increment the index refcount. - * Call `git_index__release_snapshot` when done. - */ -extern int git_index_snapshot_new(git_vector *snap, git_index *index); -extern void git_index_snapshot_release(git_vector *snap, git_index *index); - -/* Allow searching in a snapshot; entries must already be sorted! */ -extern int git_index_snapshot_find( - size_t *at_pos, git_vector *snap, git_vector_cmp entry_srch, - const char *path, size_t path_len, int stage); - -/* Replace an index with a new index */ -int git_index_read_index(git_index *index, const git_index *new_index); - -GIT_INLINE(int) git_index_is_dirty(git_index *index) -{ - return index->dirty; -} - -extern int git_index_read_safely(git_index *index); - -typedef struct { - git_index *index; - git_filebuf file; - unsigned int should_write:1; -} git_indexwriter; - -#define GIT_INDEXWRITER_INIT { NULL, GIT_FILEBUF_INIT } - -/* Lock the index for eventual writing. */ -extern int git_indexwriter_init(git_indexwriter *writer, git_index *index); - -/* Lock the index for eventual writing by a repository operation: a merge, - * revert, cherry-pick or a rebase. Note that the given checkout strategy - * will be updated for the operation's use so that checkout will not write - * the index. - */ -extern int git_indexwriter_init_for_operation( - git_indexwriter *writer, - git_repository *repo, - unsigned int *checkout_strategy); - -/* Write the index and unlock it. */ -extern int git_indexwriter_commit(git_indexwriter *writer); - -/* Cleanup an index writing session, unlocking the file (if it is still - * locked and freeing any data structures. - */ -extern void git_indexwriter_cleanup(git_indexwriter *writer); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/index_map.c b/vendor/libgit2-sys/libgit2/src/libgit2/index_map.c deleted file mode 100644 index 4c50ca7..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/index_map.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" -#include "hashmap.h" -#include "index_map.h" - -typedef git_index_entrymap git_index_entrymap_default; -typedef git_index_entrymap git_index_entrymap_icase; - -/* This is __ac_X31_hash_string but with tolower and it takes the entry's stage into account */ -GIT_INLINE(uint32_t) git_index_entrymap_hash(const git_index_entry *e) -{ - const char *s = e->path; - uint32_t h = (uint32_t)git__tolower(*s); - if (h) { - for (++s ; *s; ++s) - h = (h << 5) - h + (uint32_t)git__tolower(*s); - } - return h + GIT_INDEX_ENTRY_STAGE(e); -} - -#define git_index_entrymap_equal_default(a, b) (GIT_INDEX_ENTRY_STAGE(a) == GIT_INDEX_ENTRY_STAGE(b) && strcmp(a->path, b->path) == 0) -#define git_index_entrymap_equal_icase(a, b) (GIT_INDEX_ENTRY_STAGE(a) == GIT_INDEX_ENTRY_STAGE(b) && strcasecmp(a->path, b->path) == 0) - -GIT_HASHMAP_FUNCTIONS(git_index_entrymap_default, GIT_HASHMAP_INLINE, git_index_entry *, git_index_entry *, git_index_entrymap_hash, git_index_entrymap_equal_default) -GIT_HASHMAP_FUNCTIONS(git_index_entrymap_icase, GIT_HASHMAP_INLINE, git_index_entry *, git_index_entry *, git_index_entrymap_hash, git_index_entrymap_equal_icase) - -int git_index_entrymap_put(git_index_entrymap *map, git_index_entry *e) -{ - if (map->ignore_case) - return git_index_entrymap_icase_put((git_index_entrymap_icase *)map, e, e); - else - return git_index_entrymap_default_put((git_index_entrymap_default *)map, e, e); -} - -int git_index_entrymap_get(git_index_entry **out, git_index_entrymap *map, git_index_entry *e) -{ - if (map->ignore_case) - return git_index_entrymap_icase_get(out, (git_index_entrymap_icase *)map, e); - else - return git_index_entrymap_default_get(out, (git_index_entrymap_default *)map, e); -} - -int git_index_entrymap_remove(git_index_entrymap *map, git_index_entry *e) -{ - if (map->ignore_case) - return git_index_entrymap_icase_remove((git_index_entrymap_icase *)map, e); - else - return git_index_entrymap_default_remove((git_index_entrymap_default *)map, e); -} - -int git_index_entrymap_resize(git_index_entrymap *map, size_t count) -{ - if (count > UINT32_MAX) { - git_error_set(GIT_ERROR_INDEX, "index map is out of bounds"); - return -1; - } - - if (map->ignore_case) - return git_index_entrymap_icase__resize((git_index_entrymap_icase *)map, (uint32_t)count); - else - return git_index_entrymap_default__resize((git_index_entrymap_default *)map, (uint32_t)count); -} - -void git_index_entrymap_swap(git_index_entrymap *a, git_index_entrymap *b) -{ - git_index_entrymap t; - - if (a != b) { - memcpy(&t, a, sizeof(t)); - memcpy(a, b, sizeof(t)); - memcpy(b, &t, sizeof(t)); - } -} - -void git_index_entrymap_clear(git_index_entrymap *map) -{ - if (map->ignore_case) - git_index_entrymap_icase_clear((git_index_entrymap_icase *)map); - else - git_index_entrymap_default_clear((git_index_entrymap_default *)map); -} - -void git_index_entrymap_dispose(git_index_entrymap *map) -{ - if (map->ignore_case) - git_index_entrymap_icase_dispose((git_index_entrymap_icase *)map); - else - git_index_entrymap_default_dispose((git_index_entrymap_default *)map); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/index_map.h b/vendor/libgit2-sys/libgit2/src/libgit2/index_map.h deleted file mode 100644 index 177a3f1..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/index_map.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_index_map_h__ -#define INCLUDE_index_map_h__ - -#include "common.h" -#include "hashmap.h" - -typedef struct { - unsigned int ignore_case; - GIT_HASHMAP_STRUCT_MEMBERS(git_index_entry *, git_index_entry *) -} git_index_entrymap; - -#define GIT_INDEX_ENTRYMAP_INIT { 0 } - -extern int git_index_entrymap_get(git_index_entry **out, git_index_entrymap *map, git_index_entry *e); -extern int git_index_entrymap_put(git_index_entrymap *map, git_index_entry *e); -extern int git_index_entrymap_remove(git_index_entrymap *map, git_index_entry *e); -extern int git_index_entrymap_resize(git_index_entrymap *map, size_t count); -extern void git_index_entrymap_swap(git_index_entrymap *a, git_index_entrymap *b); -extern void git_index_entrymap_clear(git_index_entrymap *map); -extern void git_index_entrymap_dispose(git_index_entrymap *map); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/indexer.c b/vendor/libgit2-sys/libgit2/src/libgit2/indexer.c deleted file mode 100644 index d1a6110..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/indexer.c +++ /dev/null @@ -1,1480 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "indexer.h" - -#include "git2/indexer.h" -#include "git2/object.h" - -#include "commit.h" -#include "tree.h" -#include "tag.h" -#include "pack.h" -#include "mwindow.h" -#include "posix.h" -#include "pack.h" -#include "filebuf.h" -#include "oid.h" -#include "oidarray.h" -#include "zstream.h" -#include "object.h" -#include "hashmap_oid.h" - -#define UINT31_MAX (0x7FFFFFFF) - -size_t git_indexer__max_objects = UINT32_MAX; -size_t git_indexer__max_object_size = UINT31_MAX; - -GIT_HASHMAP_OID_SETUP(git_indexer_oidmap, git_oid *); - -struct entry { - git_oid oid; - uint32_t crc; - uint32_t offset; - uint64_t offset_long; -}; - -struct git_indexer { - unsigned int parsed_header :1, - pack_committed :1, - have_stream :1, - have_delta :1, - do_fsync :1, - do_verify :1; - git_oid_t oid_type; - struct git_pack_header hdr; - struct git_pack_file *pack; - unsigned int mode; - off64_t off; - off64_t entry_start; - git_object_t entry_type; - git_str entry_data; - git_packfile_stream stream; - size_t nr_objects; - git_vector objects; - git_vector deltas; - unsigned int fanout[256]; - git_hash_ctx hash_ctx; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - char name[(GIT_HASH_MAX_SIZE * 2) + 1]; - git_indexer_progress_cb progress_cb; - void *progress_payload; - char objbuf[8*1024]; - - /* OIDs referenced from pack objects. Used for verification. */ - git_indexer_oidmap expected_oids; - - /* Needed to look up objects which we want to inject to fix a thin pack */ - git_odb *odb; - - /* Fields for calculating the packfile trailer (hash of everything before it) */ - char inbuf[GIT_HASH_MAX_SIZE]; - size_t inbuf_len; - git_hash_ctx trailer; -}; - -struct delta_info { - off64_t delta_off; -}; - -#ifndef GIT_DEPRECATE_HARD -const git_oid *git_indexer_hash(const git_indexer *idx) -{ - return (git_oid *)idx->checksum; -} -#endif - -const char *git_indexer_name(const git_indexer *idx) -{ - return idx->name; -} - -static int parse_header(struct git_pack_header *hdr, struct git_pack_file *pack) -{ - int error; - git_map map; - - if ((error = p_mmap(&map, sizeof(*hdr), GIT_PROT_READ, GIT_MAP_SHARED, pack->mwf.fd, 0)) < 0) - return error; - - memcpy(hdr, map.data, sizeof(*hdr)); - p_munmap(&map); - - /* Verify we recognize this pack file format. */ - if (hdr->hdr_signature != ntohl(PACK_SIGNATURE)) { - git_error_set(GIT_ERROR_INDEXER, "wrong pack signature"); - return -1; - } - - if (!pack_version_ok(hdr->hdr_version)) { - git_error_set(GIT_ERROR_INDEXER, "wrong pack version"); - return -1; - } - - return 0; -} - -static int objects_cmp(const void *a, const void *b) -{ - const struct entry *entrya = a; - const struct entry *entryb = b; - - return git_oid__cmp(&entrya->oid, &entryb->oid); -} - -int git_indexer_options_init(git_indexer_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_indexer_options, GIT_INDEXER_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_indexer_init_options(git_indexer_options *opts, unsigned int version) -{ - return git_indexer_options_init(opts, version); -} -#endif - -GIT_INLINE(git_hash_algorithm_t) indexer_hash_algorithm(git_indexer *idx) -{ - switch (idx->oid_type) { - case GIT_OID_SHA1: - return GIT_HASH_ALGORITHM_SHA1; -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - return GIT_HASH_ALGORITHM_SHA256; -#endif - } - - return GIT_HASH_ALGORITHM_NONE; -} - -static int indexer_new( - git_indexer **out, - const char *prefix, - git_oid_t oid_type, - unsigned int mode, - git_odb *odb, - git_indexer_options *in_opts) -{ - git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; - git_indexer *idx; - git_str path = GIT_STR_INIT, tmp_path = GIT_STR_INIT; - static const char suff[] = "/pack"; - git_hash_algorithm_t checksum_type; - int error, fd = -1; - - if (in_opts) - memcpy(&opts, in_opts, sizeof(opts)); - - if (oid_type) - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); - - idx = git__calloc(1, sizeof(git_indexer)); - GIT_ERROR_CHECK_ALLOC(idx); - idx->oid_type = oid_type ? oid_type : GIT_OID_DEFAULT; - idx->odb = odb; - idx->progress_cb = opts.progress_cb; - idx->progress_payload = opts.progress_cb_payload; - idx->mode = mode ? mode : GIT_PACK_FILE_MODE; - git_str_init(&idx->entry_data, 0); - - checksum_type = indexer_hash_algorithm(idx); - - if ((error = git_hash_ctx_init(&idx->hash_ctx, checksum_type)) < 0 || - (error = git_hash_ctx_init(&idx->trailer, checksum_type)) < 0) - goto cleanup; - - idx->do_verify = opts.verify; - - if (git_repository__fsync_gitdir) - idx->do_fsync = 1; - - error = git_str_joinpath(&path, prefix, suff); - if (error < 0) - goto cleanup; - - fd = git_futils_mktmp(&tmp_path, git_str_cstr(&path), idx->mode); - git_str_dispose(&path); - if (fd < 0) - goto cleanup; - - error = git_packfile_alloc(&idx->pack, git_str_cstr(&tmp_path), oid_type); - git_str_dispose(&tmp_path); - - if (error < 0) - goto cleanup; - - idx->pack->mwf.fd = fd; - if ((error = git_mwindow_file_register(&idx->pack->mwf)) < 0) - goto cleanup; - - *out = idx; - return 0; - -cleanup: - if (fd != -1) - p_close(fd); - - if (git_str_len(&tmp_path) > 0) - p_unlink(git_str_cstr(&tmp_path)); - - if (idx->pack != NULL) - p_unlink(idx->pack->pack_name); - - git_str_dispose(&path); - git_str_dispose(&tmp_path); - git__free(idx); - return -1; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_indexer_new( - git_indexer **out, - const char *prefix, - git_indexer_options *opts) -{ - return indexer_new( - out, - prefix, - opts ? opts->oid_type : 0, - opts ? opts->mode : 0, - opts ? opts->odb : NULL, - opts); -} -#else -int git_indexer_new( - git_indexer **out, - const char *prefix, - unsigned int mode, - git_odb *odb, - git_indexer_options *opts) -{ - return indexer_new(out, prefix, GIT_OID_SHA1, mode, odb, opts); -} -#endif - -void git_indexer__set_fsync(git_indexer *idx, int do_fsync) -{ - idx->do_fsync = !!do_fsync; -} - -/* Try to store the delta so we can try to resolve it later */ -static int store_delta(git_indexer *idx) -{ - struct delta_info *delta; - - delta = git__calloc(1, sizeof(struct delta_info)); - GIT_ERROR_CHECK_ALLOC(delta); - delta->delta_off = idx->entry_start; - - if (git_vector_insert(&idx->deltas, delta) < 0) - return -1; - - return 0; -} - -static int hash_header(git_hash_ctx *ctx, off64_t len, git_object_t type) -{ - char buffer[64]; - size_t hdrlen; - int error; - - if ((error = git_odb__format_object_header(&hdrlen, - buffer, sizeof(buffer), (size_t)len, type)) < 0) - return error; - - return git_hash_update(ctx, buffer, hdrlen); -} - -static int hash_object_stream(git_indexer*idx, git_packfile_stream *stream) -{ - ssize_t read; - - GIT_ASSERT_ARG(idx); - GIT_ASSERT_ARG(stream); - - do { - if ((read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf))) < 0) - break; - - if (idx->do_verify) - git_str_put(&idx->entry_data, idx->objbuf, read); - - git_hash_update(&idx->hash_ctx, idx->objbuf, read); - } while (read > 0); - - if (read < 0) - return (int)read; - - return 0; -} - -/* In order to create the packfile stream, we need to skip over the delta base description */ -static int advance_delta_offset(git_indexer *idx, git_object_t type) -{ - git_mwindow *w = NULL; - - GIT_ASSERT_ARG(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA); - - if (type == GIT_OBJECT_REF_DELTA) { - idx->off += git_oid_size(idx->oid_type); - } else { - off64_t base_off; - int error = get_delta_base(&base_off, idx->pack, &w, &idx->off, type, idx->entry_start); - git_mwindow_close(&w); - if (error < 0) - return error; - } - - return 0; -} - -/* Read from the stream and discard any output */ -static int read_object_stream(git_indexer *idx, git_packfile_stream *stream) -{ - ssize_t read; - - GIT_ASSERT_ARG(stream); - - do { - read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf)); - } while (read > 0); - - if (read < 0) - return (int)read; - - return 0; -} - -static int crc_object(uint32_t *crc_out, git_mwindow_file *mwf, off64_t start, off64_t size) -{ - void *ptr; - uint32_t crc; - unsigned int left, len; - git_mwindow *w = NULL; - - crc = crc32(0L, Z_NULL, 0); - while (size) { - ptr = git_mwindow_open(mwf, &w, start, (size_t)size, &left); - if (ptr == NULL) - return -1; - - len = min(left, (unsigned int)size); - crc = crc32(crc, ptr, len); - size -= len; - start += len; - git_mwindow_close(&w); - } - - *crc_out = htonl(crc); - return 0; -} - -static int add_expected_oid(git_indexer *idx, const git_oid *oid) -{ - /* - * If we know about that object because it is stored in our ODB or - * because we have already processed it as part of our pack file, we do - * not have to expect it. - */ - if ((!idx->odb || !git_odb_exists(idx->odb, oid)) && - !git_pack_oidmap_contains(&idx->pack->idx_cache, oid) && - !git_indexer_oidmap_contains(&idx->expected_oids, oid)) { - git_oid *dup = git__malloc(sizeof(*oid)); - GIT_ERROR_CHECK_ALLOC(dup); - git_oid_cpy(dup, oid); - return git_indexer_oidmap_put(&idx->expected_oids, dup, dup); - } - - return 0; -} - -static int check_object_connectivity(git_indexer *idx, const git_rawobj *obj) -{ - git_object *object; - git_oid *expected; - int error = 0; - - if (obj->type != GIT_OBJECT_BLOB && - obj->type != GIT_OBJECT_TREE && - obj->type != GIT_OBJECT_COMMIT && - obj->type != GIT_OBJECT_TAG) - return 0; - - if (git_object__from_raw(&object, obj->data, obj->len, obj->type, idx->oid_type) < 0) { - /* - * parse_raw returns EINVALID on invalid data; downgrade - * that to a normal -1 error code. - */ - error = -1; - goto out; - } - - if (git_indexer_oidmap_get(&expected, &idx->expected_oids, &object->cached.oid) == 0) { - git_indexer_oidmap_remove(&idx->expected_oids, &object->cached.oid); - git__free(expected); - } - - /* - * Check whether this is a known object. If so, we can just continue as - * we assume that the ODB has a complete graph. - */ - if (idx->odb && git_odb_exists(idx->odb, &object->cached.oid)) - return 0; - - switch (obj->type) { - case GIT_OBJECT_TREE: - { - git_tree *tree = (git_tree *) object; - git_tree_entry *entry; - size_t i; - - git_array_foreach(tree->entries, i, entry) - if (add_expected_oid(idx, &entry->oid) < 0) - goto out; - - break; - } - case GIT_OBJECT_COMMIT: - { - git_commit *commit = (git_commit *) object; - git_oid *parent_oid; - size_t i; - - git_array_foreach(commit->parent_ids, i, parent_oid) - if (add_expected_oid(idx, parent_oid) < 0) - goto out; - - if (add_expected_oid(idx, &commit->tree_id) < 0) - goto out; - - break; - } - case GIT_OBJECT_TAG: - { - git_tag *tag = (git_tag *) object; - - if (add_expected_oid(idx, &tag->target) < 0) - goto out; - - break; - } - case GIT_OBJECT_BLOB: - default: - break; - } - -out: - git_object_free(object); - - return error; -} - -static int store_object(git_indexer *idx) -{ - int i, error; - git_oid oid; - struct entry *entry; - off64_t entry_size; - struct git_pack_entry *pentry; - off64_t entry_start = idx->entry_start; - - entry = git__calloc(1, sizeof(*entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - pentry = git__calloc(1, sizeof(struct git_pack_entry)); - GIT_ERROR_CHECK_ALLOC(pentry); - - if (git_hash_final(oid.id, &idx->hash_ctx)) { - git__free(pentry); - goto on_error; - } - -#ifdef GIT_EXPERIMENTAL_SHA256 - oid.type = idx->oid_type; -#endif - - entry_size = idx->off - entry_start; - if (entry_start > UINT31_MAX) { - entry->offset = UINT32_MAX; - entry->offset_long = entry_start; - } else { - entry->offset = (uint32_t)entry_start; - } - - if (idx->do_verify) { - git_rawobj rawobj = { - idx->entry_data.ptr, - idx->entry_data.size, - idx->entry_type - }; - - if ((error = check_object_connectivity(idx, &rawobj)) < 0) - goto on_error; - } - - git_oid_cpy(&pentry->id, &oid); - pentry->offset = entry_start; - - if (git_pack_oidmap_contains(&idx->pack->idx_cache, &pentry->id)) { - const char *idstr = git_oid_tostr_s(&pentry->id); - - if (!idstr) - git_error_set(GIT_ERROR_INDEXER, "failed to parse object id"); - else - git_error_set(GIT_ERROR_INDEXER, "duplicate object %s found in pack", idstr); - - git__free(pentry); - goto on_error; - } - - if ((error = git_pack_oidmap_put(&idx->pack->idx_cache, &pentry->id, pentry)) < 0) { - git__free(pentry); - git_error_set_oom(); - goto on_error; - } - - git_oid_cpy(&entry->oid, &oid); - - if (crc_object(&entry->crc, &idx->pack->mwf, entry_start, entry_size) < 0) - goto on_error; - - /* Add the object to the list */ - if (git_vector_insert(&idx->objects, entry) < 0) - goto on_error; - - for (i = oid.id[0]; i < 256; ++i) { - idx->fanout[i]++; - } - - return 0; - -on_error: - git__free(entry); - - return -1; -} - -GIT_INLINE(bool) has_entry(git_indexer *idx, git_oid *id) -{ - return git_pack_oidmap_contains(&idx->pack->idx_cache, id); -} - -static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, off64_t entry_start) -{ - int i; - - if (entry_start > UINT31_MAX) { - entry->offset = UINT32_MAX; - entry->offset_long = entry_start; - } else { - entry->offset = (uint32_t)entry_start; - } - - pentry->offset = entry_start; - - if (git_pack_oidmap_contains(&idx->pack->idx_cache, &pentry->id) || - git_pack_oidmap_put(&idx->pack->idx_cache, &pentry->id, pentry) < 0) { - git_error_set(GIT_ERROR_INDEXER, "cannot insert object into pack"); - return -1; - } - - /* Add the object to the list */ - if (git_vector_insert(&idx->objects, entry) < 0) - return -1; - - for (i = entry->oid.id[0]; i < 256; ++i) { - idx->fanout[i]++; - } - - return 0; -} - -static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start) -{ - git_oid oid; - size_t entry_size; - struct entry *entry; - struct git_pack_entry *pentry = NULL; - - entry = git__calloc(1, sizeof(*entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - if (git_odb__hashobj(&oid, obj, idx->oid_type) < 0) { - git_error_set(GIT_ERROR_INDEXER, "failed to hash object"); - goto on_error; - } - - pentry = git__calloc(1, sizeof(struct git_pack_entry)); - GIT_ERROR_CHECK_ALLOC(pentry); - - git_oid_cpy(&pentry->id, &oid); - git_oid_cpy(&entry->oid, &oid); - entry->crc = crc32(0L, Z_NULL, 0); - - entry_size = (size_t)(idx->off - entry_start); - if (crc_object(&entry->crc, &idx->pack->mwf, entry_start, entry_size) < 0) - goto on_error; - - return save_entry(idx, entry, pentry, entry_start); - -on_error: - git__free(pentry); - git__free(entry); - git__free(obj->data); - return -1; -} - -static int do_progress_callback(git_indexer *idx, git_indexer_progress *stats) -{ - if (idx->progress_cb) - return git_error_set_after_callback_function( - idx->progress_cb(stats, idx->progress_payload), - "indexer progress"); - return 0; -} - -/* Hash everything but the checksum trailer */ -static void hash_partially(git_indexer *idx, const uint8_t *data, size_t size) -{ - size_t to_expell, to_keep; - size_t oid_size = git_oid_size(idx->oid_type); - - if (size == 0) - return; - - /* - * Easy case, dump the buffer and the data minus the trailing - * checksum (SHA1 or SHA256). - */ - if (size >= oid_size) { - git_hash_update(&idx->trailer, idx->inbuf, idx->inbuf_len); - git_hash_update(&idx->trailer, data, size - oid_size); - - data += size - oid_size; - memcpy(idx->inbuf, data, oid_size); - idx->inbuf_len = oid_size; - return; - } - - /* We can just append */ - if (idx->inbuf_len + size <= oid_size) { - memcpy(idx->inbuf + idx->inbuf_len, data, size); - idx->inbuf_len += size; - return; - } - - /* We need to partially drain the buffer and then append */ - to_keep = oid_size - size; - to_expell = idx->inbuf_len - to_keep; - - git_hash_update(&idx->trailer, idx->inbuf, to_expell); - - memmove(idx->inbuf, idx->inbuf + to_expell, to_keep); - memcpy(idx->inbuf + to_keep, data, size); - idx->inbuf_len += size - to_expell; -} - -#if defined(NO_MMAP) || !defined(GIT_WIN32) - -static int write_at(git_indexer *idx, const void *data, off64_t offset, size_t size) -{ - size_t remaining_size = size; - const char *ptr = (const char *)data; - - /* Handle data size larger that ssize_t */ - while (remaining_size > 0) { - ssize_t nb; - HANDLE_EINTR(nb, p_pwrite(idx->pack->mwf.fd, (void *)ptr, - remaining_size, offset)); - if (nb <= 0) - return -1; - - ptr += nb; - offset += nb; - remaining_size -= nb; - } - - return 0; -} - -static int append_to_pack(git_indexer *idx, const void *data, size_t size) -{ - if (write_at(idx, data, idx->pack->mwf.size, size) < 0) { - git_error_set(GIT_ERROR_OS, "cannot extend packfile '%s'", idx->pack->pack_name); - return -1; - } - - return 0; -} - -#else - -/* - * Windows may keep different views to a networked file for the mmap- and - * open-accessed versions of a file, so any writes done through - * `write(2)`/`pwrite(2)` may not be reflected on the data that `mmap(2)` is - * able to read. - */ - -static int write_at(git_indexer *idx, const void *data, off64_t offset, size_t size) -{ - git_file fd = idx->pack->mwf.fd; - size_t mmap_alignment; - size_t page_offset; - off64_t page_start; - unsigned char *map_data; - git_map map; - int error; - - GIT_ASSERT_ARG(data); - GIT_ASSERT_ARG(size); - - if ((error = git__mmap_alignment(&mmap_alignment)) < 0) - return error; - - /* the offset needs to be at the mmap boundary for the platform */ - page_offset = offset % mmap_alignment; - page_start = offset - page_offset; - - if ((error = p_mmap(&map, page_offset + size, GIT_PROT_WRITE, GIT_MAP_SHARED, fd, page_start)) < 0) - return error; - - map_data = (unsigned char *)map.data; - memcpy(map_data + page_offset, data, size); - p_munmap(&map); - - return 0; -} - -static int append_to_pack(git_indexer *idx, const void *data, size_t size) -{ - off64_t new_size; - size_t mmap_alignment; - size_t page_offset; - off64_t page_start; - off64_t current_size = idx->pack->mwf.size; - int error; - - if (!size) - return 0; - - if ((error = git__mmap_alignment(&mmap_alignment)) < 0) - return error; - - /* Write a single byte to force the file system to allocate space now or - * report an error, since we can't report errors when writing using mmap. - * Round the size up to the nearest page so that we only need to perform file - * I/O when we add a page, instead of whenever we write even a single byte. */ - new_size = current_size + size; - page_offset = new_size % mmap_alignment; - page_start = new_size - page_offset; - - if (p_pwrite(idx->pack->mwf.fd, data, 1, page_start + mmap_alignment - 1) < 0) { - git_error_set(GIT_ERROR_OS, "cannot extend packfile '%s'", idx->pack->pack_name); - return -1; - } - - return write_at(idx, data, idx->pack->mwf.size, size); -} - -#endif - -static int read_stream_object(git_indexer *idx, git_indexer_progress *stats) -{ - git_packfile_stream *stream = &idx->stream; - off64_t entry_start = idx->off; - size_t oid_size, entry_size; - git_object_t type; - git_mwindow *w = NULL; - int error; - - oid_size = git_oid_size(idx->oid_type); - - if (idx->pack->mwf.size <= idx->off + (long long)oid_size) - return GIT_EBUFS; - - if (!idx->have_stream) { - error = git_packfile_unpack_header(&entry_size, &type, idx->pack, &w, &idx->off); - if (error == GIT_EBUFS) { - idx->off = entry_start; - return error; - } - if (error < 0) - return error; - - git_mwindow_close(&w); - idx->entry_start = entry_start; - git_hash_init(&idx->hash_ctx); - git_str_clear(&idx->entry_data); - - if (type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA) { - error = advance_delta_offset(idx, type); - if (error == GIT_EBUFS) { - idx->off = entry_start; - return error; - } - if (error < 0) - return error; - - idx->have_delta = 1; - } else { - idx->have_delta = 0; - - error = hash_header(&idx->hash_ctx, entry_size, type); - if (error < 0) - return error; - } - - idx->have_stream = 1; - idx->entry_type = type; - - error = git_packfile_stream_open(stream, idx->pack, idx->off); - if (error < 0) - return error; - } - - if (idx->have_delta) { - error = read_object_stream(idx, stream); - } else { - error = hash_object_stream(idx, stream); - } - - idx->off = stream->curpos; - if (error == GIT_EBUFS) - return error; - - /* We want to free the stream reasorces no matter what here */ - idx->have_stream = 0; - git_packfile_stream_dispose(stream); - - if (error < 0) - return error; - - if (idx->have_delta) { - error = store_delta(idx); - } else { - error = store_object(idx); - } - - if (error < 0) - return error; - - if (!idx->have_delta) { - stats->indexed_objects++; - } - stats->received_objects++; - - if ((error = do_progress_callback(idx, stats)) != 0) - return error; - - return 0; -} - -int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_indexer_progress *stats) -{ - int error = -1; - struct git_pack_header *hdr = &idx->hdr; - git_mwindow_file *mwf = &idx->pack->mwf; - - GIT_ASSERT_ARG(idx); - GIT_ASSERT_ARG(data); - GIT_ASSERT_ARG(stats); - - if ((error = append_to_pack(idx, data, size)) < 0) - return error; - - hash_partially(idx, data, (int)size); - - /* Make sure we set the new size of the pack */ - idx->pack->mwf.size += size; - - if (!idx->parsed_header) { - unsigned int total_objects; - - if ((unsigned)idx->pack->mwf.size < sizeof(struct git_pack_header)) - return 0; - - if ((error = parse_header(&idx->hdr, idx->pack)) < 0) - return error; - - idx->parsed_header = 1; - idx->nr_objects = ntohl(hdr->hdr_entries); - idx->off = sizeof(struct git_pack_header); - - if (idx->nr_objects <= git_indexer__max_objects) { - total_objects = (unsigned int)idx->nr_objects; - } else { - git_error_set(GIT_ERROR_INDEXER, "too many objects"); - return -1; - } - - idx->pack->has_cache = 1; - if (git_vector_init(&idx->objects, total_objects, objects_cmp) < 0) - return -1; - - if (git_vector_init(&idx->deltas, total_objects / 2, NULL) < 0) - return -1; - - stats->total_objects = total_objects; - stats->indexed_objects = 0; - stats->received_objects = 0; - stats->local_objects = 0; - stats->total_deltas = 0; - stats->indexed_deltas = 0; - - if ((error = do_progress_callback(idx, stats)) != 0) - return error; - } - - /* Now that we have data in the pack, let's try to parse it */ - - /* As the file grows any windows we try to use will be out of date */ - if ((error = git_mwindow_free_all(mwf)) < 0) - goto on_error; - - while (stats->indexed_objects < idx->nr_objects) { - if ((error = read_stream_object(idx, stats)) != 0) { - if (error == GIT_EBUFS) - break; - else - goto on_error; - } - } - - return 0; - -on_error: - git_mwindow_free_all(mwf); - return error; -} - -static int index_path(git_str *path, git_indexer *idx, const char *suffix) -{ - const char prefix[] = "pack-"; - size_t slash = (size_t)path->size; - - /* search backwards for '/' */ - while (slash > 0 && path->ptr[slash - 1] != '/') - slash--; - - if (git_str_grow(path, slash + 1 + strlen(prefix) + - git_oid_hexsize(idx->oid_type) + strlen(suffix) + 1) < 0) - return -1; - - git_str_truncate(path, slash); - git_str_puts(path, prefix); - git_str_puts(path, idx->name); - git_str_puts(path, suffix); - - return git_str_oom(path) ? -1 : 0; -} - -/** - * Rewind the packfile by the trailer, as we might need to fix the - * packfile by injecting objects at the tail and must overwrite it. - */ -static int seek_back_trailer(git_indexer *idx) -{ - idx->pack->mwf.size -= git_oid_size(idx->oid_type); - return git_mwindow_free_all(&idx->pack->mwf); -} - -static int inject_object(git_indexer *idx, git_oid *id) -{ - git_odb_object *obj = NULL; - struct entry *entry = NULL; - struct git_pack_entry *pentry = NULL; - unsigned char empty_checksum[GIT_HASH_MAX_SIZE] = {0}; - unsigned char hdr[64]; - git_str buf = GIT_STR_INIT; - off64_t entry_start; - const void *data; - size_t len, hdr_len; - size_t checksum_size; - int error; - - checksum_size = git_hash_size(indexer_hash_algorithm(idx)); - - if ((error = seek_back_trailer(idx)) < 0) - goto cleanup; - - entry_start = idx->pack->mwf.size; - - if ((error = git_odb_read(&obj, idx->odb, id)) < 0) { - git_error_set(GIT_ERROR_INDEXER, "missing delta bases"); - goto cleanup; - } - - data = git_odb_object_data(obj); - len = git_odb_object_size(obj); - - entry = git__calloc(1, sizeof(*entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->crc = crc32(0L, Z_NULL, 0); - - /* Write out the object header */ - if ((error = git_packfile__object_header(&hdr_len, hdr, len, git_odb_object_type(obj))) < 0 || - (error = append_to_pack(idx, hdr, hdr_len)) < 0) - goto cleanup; - - idx->pack->mwf.size += hdr_len; - entry->crc = crc32(entry->crc, hdr, (uInt)hdr_len); - - if ((error = git_zstream_deflatebuf(&buf, data, len)) < 0) - goto cleanup; - - /* And then the compressed object */ - if ((error = append_to_pack(idx, buf.ptr, buf.size)) < 0) - goto cleanup; - - idx->pack->mwf.size += buf.size; - entry->crc = htonl(crc32(entry->crc, (unsigned char *)buf.ptr, (uInt)buf.size)); - git_str_dispose(&buf); - - /* Write a fake trailer so the pack functions play ball */ - - if ((error = append_to_pack(idx, empty_checksum, checksum_size)) < 0) - goto cleanup; - - idx->pack->mwf.size += git_oid_size(idx->oid_type); - - pentry = git__calloc(1, sizeof(struct git_pack_entry)); - GIT_ERROR_CHECK_ALLOC(pentry); - - git_oid_cpy(&pentry->id, id); - git_oid_cpy(&entry->oid, id); - idx->off = entry_start + hdr_len + len; - - error = save_entry(idx, entry, pentry, entry_start); - -cleanup: - if (error) { - git__free(entry); - git__free(pentry); - } - - git_odb_object_free(obj); - return error; -} - -static int fix_thin_pack(git_indexer *idx, git_indexer_progress *stats) -{ - int error, found_ref_delta = 0; - unsigned int i; - struct delta_info *delta; - size_t size; - git_object_t type; - git_mwindow *w = NULL; - off64_t curpos = 0; - unsigned char *base_info; - unsigned int left = 0; - git_oid base; - - GIT_ASSERT(git_vector_length(&idx->deltas) > 0); - - if (idx->odb == NULL) { - git_error_set(GIT_ERROR_INDEXER, "cannot fix a thin pack without an ODB"); - return -1; - } - - /* Loop until we find the first REF delta */ - git_vector_foreach(&idx->deltas, i, delta) { - if (!delta) - continue; - - curpos = delta->delta_off; - error = git_packfile_unpack_header(&size, &type, idx->pack, &w, &curpos); - if (error < 0) - return error; - - if (type == GIT_OBJECT_REF_DELTA) { - found_ref_delta = 1; - break; - } - } - - if (!found_ref_delta) { - git_error_set(GIT_ERROR_INDEXER, "no REF_DELTA found, cannot inject object"); - return -1; - } - - /* curpos now points to the base information, which is an OID */ - base_info = git_mwindow_open(&idx->pack->mwf, &w, curpos, git_oid_size(idx->oid_type), &left); - if (base_info == NULL) { - git_error_set(GIT_ERROR_INDEXER, "failed to map delta information"); - return -1; - } - - git_oid__fromraw(&base, base_info, idx->oid_type); - git_mwindow_close(&w); - - if (has_entry(idx, &base)) - return 0; - - if (inject_object(idx, &base) < 0) - return -1; - - stats->local_objects++; - - return 0; -} - -static int resolve_deltas(git_indexer *idx, git_indexer_progress *stats) -{ - unsigned int i; - int error; - struct delta_info *delta; - int progressed = 0, non_null = 0, progress_cb_result; - - while (idx->deltas.length > 0) { - progressed = 0; - non_null = 0; - git_vector_foreach(&idx->deltas, i, delta) { - git_rawobj obj = {0}; - - if (!delta) - continue; - - non_null = 1; - idx->off = delta->delta_off; - if ((error = git_packfile_unpack(&obj, idx->pack, &idx->off)) < 0) { - if (error == GIT_PASSTHROUGH) { - /* We have not seen the base object, we'll try again later. */ - continue; - } - return -1; - } - - if (idx->do_verify && check_object_connectivity(idx, &obj) < 0) - /* TODO: error? continue? */ - continue; - - if (hash_and_save(idx, &obj, delta->delta_off) < 0) - continue; - - git__free(obj.data); - stats->indexed_objects++; - stats->indexed_deltas++; - progressed = 1; - if ((progress_cb_result = do_progress_callback(idx, stats)) < 0) - return progress_cb_result; - - /* remove from the list */ - git_vector_set(NULL, &idx->deltas, i, NULL); - git__free(delta); - } - - /* if none were actually set, we're done */ - if (!non_null) - break; - - if (!progressed && (fix_thin_pack(idx, stats) < 0)) { - return -1; - } - } - - return 0; -} - -static int update_header_and_rehash(git_indexer *idx, git_indexer_progress *stats) -{ - void *ptr; - size_t chunk = 1024*1024; - off64_t hashed = 0; - git_mwindow *w = NULL; - git_mwindow_file *mwf; - unsigned int left; - - mwf = &idx->pack->mwf; - - git_hash_init(&idx->trailer); - - - /* Update the header to include the number of local objects we injected */ - idx->hdr.hdr_entries = htonl(stats->total_objects + stats->local_objects); - if (write_at(idx, &idx->hdr, 0, sizeof(struct git_pack_header)) < 0) - return -1; - - /* - * We now use the same technique as before to determine the - * hash. We keep reading up to the end and let - * hash_partially() keep the existing trailer out of the - * calculation. - */ - if (git_mwindow_free_all(mwf) < 0) - return -1; - - idx->inbuf_len = 0; - while (hashed < mwf->size) { - ptr = git_mwindow_open(mwf, &w, hashed, chunk, &left); - if (ptr == NULL) - return -1; - - hash_partially(idx, ptr, left); - hashed += left; - - git_mwindow_close(&w); - } - - return 0; -} - -int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats) -{ - git_mwindow *w = NULL; - unsigned int i, long_offsets = 0, left; - int error; - struct git_pack_idx_header hdr; - git_str filename = GIT_STR_INIT; - struct entry *entry; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - git_filebuf index_file = {0}; - void *packfile_trailer; - size_t checksum_size; - int filebuf_hash; - bool mismatch; - - if (!idx->parsed_header) { - git_error_set(GIT_ERROR_INDEXER, "incomplete pack header"); - return -1; - } - - checksum_size = git_hash_size(indexer_hash_algorithm(idx)); - filebuf_hash = git_filebuf_hash_flags(indexer_hash_algorithm(idx)); - GIT_ASSERT(checksum_size); - - /* Test for this before resolve_deltas(), as it plays with idx->off */ - if (idx->off + (ssize_t)checksum_size < idx->pack->mwf.size) { - git_error_set(GIT_ERROR_INDEXER, "unexpected data at the end of the pack"); - return -1; - } - if (idx->off + (ssize_t)checksum_size > idx->pack->mwf.size) { - git_error_set(GIT_ERROR_INDEXER, "missing trailer at the end of the pack"); - return -1; - } - - packfile_trailer = git_mwindow_open(&idx->pack->mwf, &w, idx->pack->mwf.size - checksum_size, checksum_size, &left); - if (packfile_trailer == NULL) { - git_mwindow_close(&w); - goto on_error; - } - - /* Compare the packfile trailer as it was sent to us and what we calculated */ - git_hash_final(checksum, &idx->trailer); - mismatch = !!memcmp(checksum, packfile_trailer, checksum_size); - git_mwindow_close(&w); - - if (mismatch) { - git_error_set(GIT_ERROR_INDEXER, "packfile trailer mismatch"); - return -1; - } - - /* Freeze the number of deltas */ - stats->total_deltas = stats->total_objects - stats->indexed_objects; - - if ((error = resolve_deltas(idx, stats)) < 0) - return error; - - if (stats->indexed_objects != stats->total_objects) { - git_error_set(GIT_ERROR_INDEXER, "early EOF"); - return -1; - } - - if (stats->local_objects > 0) { - if (update_header_and_rehash(idx, stats) < 0) - return -1; - - git_hash_final(checksum, &idx->trailer); - write_at(idx, checksum, idx->pack->mwf.size - checksum_size, checksum_size); - } - - /* - * Is the resulting graph fully connected or are we still - * missing some objects? In the second case, we can - * bail out due to an incomplete and thus corrupt - * packfile. - */ - if (git_indexer_oidmap_size(&idx->expected_oids) > 0) { - git_error_set(GIT_ERROR_INDEXER, "packfile is missing %"PRIuZ" objects", - (size_t)git_indexer_oidmap_size(&idx->expected_oids)); - return -1; - } - - git_vector_sort(&idx->objects); - - /* Use the trailer hash as the pack file name to ensure - * files with different contents have different names */ - memcpy(idx->checksum, checksum, checksum_size); - if (git_hash_fmt(idx->name, checksum, checksum_size) < 0) - return -1; - - git_str_sets(&filename, idx->pack->pack_name); - git_str_shorten(&filename, strlen("pack")); - git_str_puts(&filename, "idx"); - if (git_str_oom(&filename)) - return -1; - - if (git_filebuf_open(&index_file, filename.ptr, - filebuf_hash | (idx->do_fsync ? GIT_FILEBUF_FSYNC : 0), - idx->mode) < 0) - goto on_error; - - /* Write out the header */ - hdr.idx_signature = htonl(PACK_IDX_SIGNATURE); - hdr.idx_version = htonl(2); - git_filebuf_write(&index_file, &hdr, sizeof(hdr)); - - /* Write out the fanout table */ - for (i = 0; i < 256; ++i) { - uint32_t n = htonl(idx->fanout[i]); - git_filebuf_write(&index_file, &n, sizeof(n)); - } - - /* Write out the object names (SHA-1 hashes) */ - git_vector_foreach(&idx->objects, i, entry) { - git_filebuf_write(&index_file, &entry->oid.id, git_oid_size(idx->oid_type)); - } - - /* Write out the CRC32 values */ - git_vector_foreach(&idx->objects, i, entry) { - git_filebuf_write(&index_file, &entry->crc, sizeof(uint32_t)); - } - - /* Write out the offsets */ - git_vector_foreach(&idx->objects, i, entry) { - uint32_t n; - - if (entry->offset == UINT32_MAX) - n = htonl(0x80000000 | long_offsets++); - else - n = htonl(entry->offset); - - git_filebuf_write(&index_file, &n, sizeof(uint32_t)); - } - - /* Write out the long offsets */ - git_vector_foreach(&idx->objects, i, entry) { - uint32_t split[2]; - - if (entry->offset != UINT32_MAX) - continue; - - split[0] = htonl(entry->offset_long >> 32); - split[1] = htonl(entry->offset_long & 0xffffffff); - - git_filebuf_write(&index_file, &split, sizeof(uint32_t) * 2); - } - - /* Write out the packfile trailer to the index */ - if (git_filebuf_write(&index_file, checksum, checksum_size) < 0) - goto on_error; - - /* Write out the hash of the idx */ - if (git_filebuf_hash(checksum, &index_file) < 0) - goto on_error; - - git_filebuf_write(&index_file, checksum, checksum_size); - - /* Figure out what the final name should be */ - if (index_path(&filename, idx, ".idx") < 0) - goto on_error; - - /* Commit file */ - if (git_filebuf_commit_at(&index_file, filename.ptr) < 0) - goto on_error; - - if (git_mwindow_free_all(&idx->pack->mwf) < 0) - goto on_error; - -#if !defined(NO_MMAP) && defined(GIT_WIN32) - /* - * Some non-Windows remote filesystems fail when truncating files if the - * file permissions change after opening the file (done by p_mkstemp). - * - * Truncation is only needed when mmap is used to undo rounding up to next - * page_size in append_to_pack. - */ - if (p_ftruncate(idx->pack->mwf.fd, idx->pack->mwf.size) < 0) { - git_error_set(GIT_ERROR_OS, "failed to truncate pack file '%s'", idx->pack->pack_name); - return -1; - } -#endif - - if (idx->do_fsync && p_fsync(idx->pack->mwf.fd) < 0) { - git_error_set(GIT_ERROR_OS, "failed to fsync packfile"); - goto on_error; - } - - /* We need to close the descriptor here so Windows doesn't choke on commit_at */ - if (p_close(idx->pack->mwf.fd) < 0) { - git_error_set(GIT_ERROR_OS, "failed to close packfile"); - goto on_error; - } - - idx->pack->mwf.fd = -1; - - if (index_path(&filename, idx, ".pack") < 0) - goto on_error; - - /* And don't forget to rename the packfile to its new place. */ - if (p_rename(idx->pack->pack_name, git_str_cstr(&filename)) < 0) - goto on_error; - - /* And fsync the parent directory if we're asked to. */ - if (idx->do_fsync && - git_futils_fsync_parent(git_str_cstr(&filename)) < 0) - goto on_error; - - idx->pack_committed = 1; - - git_str_dispose(&filename); - return 0; - -on_error: - git_mwindow_free_all(&idx->pack->mwf); - git_filebuf_cleanup(&index_file); - git_str_dispose(&filename); - return -1; -} - -void git_indexer_free(git_indexer *idx) -{ - struct git_pack_entry *pentry; - git_oid *id; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - if (idx == NULL) - return; - - if (idx->have_stream) - git_packfile_stream_dispose(&idx->stream); - - git_vector_dispose_deep(&idx->objects); - - while (git_pack_oidmap_iterate(&iter, NULL, &pentry, &idx->pack->idx_cache) == 0) - git__free(pentry); - - git_pack_oidmap_dispose(&idx->pack->idx_cache); - - git_vector_dispose_deep(&idx->deltas); - - git_packfile_free(idx->pack, !idx->pack_committed); - - iter = GIT_HASHMAP_ITER_INIT; - while (git_indexer_oidmap_iterate(&iter, NULL, &id, &idx->expected_oids) == 0) - git__free(id); - - git_hash_ctx_cleanup(&idx->trailer); - git_hash_ctx_cleanup(&idx->hash_ctx); - git_str_dispose(&idx->entry_data); - git_indexer_oidmap_dispose(&idx->expected_oids); - git__free(idx); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/indexer.h b/vendor/libgit2-sys/libgit2/src/libgit2/indexer.h deleted file mode 100644 index 8ee6115..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/indexer.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_indexer_h__ -#define INCLUDE_indexer_h__ - -#include "common.h" - -#include "git2/indexer.h" - -extern void git_indexer__set_fsync(git_indexer *idx, int do_fsync); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/iterator.c b/vendor/libgit2-sys/libgit2/src/libgit2/iterator.c deleted file mode 100644 index 5b3e024..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/iterator.c +++ /dev/null @@ -1,2462 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "iterator.h" - -#include "tree.h" -#include "index.h" -#include "path.h" - -#define GIT_ITERATOR_FIRST_ACCESS (1 << 15) -#define GIT_ITERATOR_HONOR_IGNORES (1 << 16) -#define GIT_ITERATOR_IGNORE_DOT_GIT (1 << 17) - -#define iterator__flag(I,F) ((((git_iterator *)(I))->flags & GIT_ITERATOR_ ## F) != 0) -#define iterator__ignore_case(I) iterator__flag(I,IGNORE_CASE) -#define iterator__include_trees(I) iterator__flag(I,INCLUDE_TREES) -#define iterator__dont_autoexpand(I) iterator__flag(I,DONT_AUTOEXPAND) -#define iterator__do_autoexpand(I) !iterator__flag(I,DONT_AUTOEXPAND) -#define iterator__include_conflicts(I) iterator__flag(I,INCLUDE_CONFLICTS) -#define iterator__has_been_accessed(I) iterator__flag(I,FIRST_ACCESS) -#define iterator__honor_ignores(I) iterator__flag(I,HONOR_IGNORES) -#define iterator__ignore_dot_git(I) iterator__flag(I,IGNORE_DOT_GIT) -#define iterator__descend_symlinks(I) iterator__flag(I,DESCEND_SYMLINKS) - -static void iterator_set_ignore_case(git_iterator *iter, bool ignore_case) -{ - int (*vector_cmp)(const void *a, const void *b); - - if (ignore_case) - iter->flags |= GIT_ITERATOR_IGNORE_CASE; - else - iter->flags &= ~GIT_ITERATOR_IGNORE_CASE; - - iter->strcomp = ignore_case ? git__strcasecmp : git__strcmp; - iter->strncomp = ignore_case ? git__strncasecmp : git__strncmp; - iter->prefixcomp = ignore_case ? git__prefixcmp_icase : git__prefixcmp; - iter->entry_srch = ignore_case ? git_index_entry_isrch : git_index_entry_srch; - - vector_cmp = ignore_case ? git__strcasecmp_cb : git__strcmp_cb; - - git_vector_set_cmp(&iter->pathlist, vector_cmp); -} - -static int iterator_range_init( - git_iterator *iter, const char *start, const char *end) -{ - if (start && *start) { - iter->start = git__strdup(start); - GIT_ERROR_CHECK_ALLOC(iter->start); - - iter->start_len = strlen(iter->start); - } - - if (end && *end) { - iter->end = git__strdup(end); - GIT_ERROR_CHECK_ALLOC(iter->end); - - iter->end_len = strlen(iter->end); - } - - iter->started = (iter->start == NULL); - iter->ended = false; - - return 0; -} - -static void iterator_range_free(git_iterator *iter) -{ - if (iter->start) { - git__free(iter->start); - iter->start = NULL; - iter->start_len = 0; - } - - if (iter->end) { - git__free(iter->end); - iter->end = NULL; - iter->end_len = 0; - } -} - -static int iterator_reset_range( - git_iterator *iter, const char *start, const char *end) -{ - iterator_range_free(iter); - return iterator_range_init(iter, start, end); -} - -static int iterator_pathlist_init(git_iterator *iter, git_strarray *pathlist) -{ - size_t i; - - if (git_vector_init(&iter->pathlist, pathlist->count, NULL) < 0) - return -1; - - for (i = 0; i < pathlist->count; i++) { - if (!pathlist->strings[i]) - continue; - - if (git_vector_insert(&iter->pathlist, pathlist->strings[i]) < 0) - return -1; - } - - return 0; -} - -static int iterator_init_common( - git_iterator *iter, - git_repository *repo, - git_index *index, - git_iterator_options *given_opts) -{ - static git_iterator_options default_opts = GIT_ITERATOR_OPTIONS_INIT; - git_iterator_options *options = given_opts ? given_opts : &default_opts; - bool ignore_case; - int precompose; - int error; - - iter->repo = repo; - iter->index = index; - iter->flags = options->flags; - - if ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0) { - ignore_case = true; - } else if ((iter->flags & GIT_ITERATOR_DONT_IGNORE_CASE) != 0) { - ignore_case = false; - } else if (repo) { - git_index *index; - - if ((error = git_repository_index__weakptr(&index, iter->repo)) < 0) - return error; - - ignore_case = !!index->ignore_case; - - if (ignore_case == 1) - iter->flags |= GIT_ITERATOR_IGNORE_CASE; - else - iter->flags |= GIT_ITERATOR_DONT_IGNORE_CASE; - } else { - ignore_case = false; - } - - /* try to look up precompose and set flag if appropriate */ - if (repo && - (iter->flags & GIT_ITERATOR_PRECOMPOSE_UNICODE) == 0 && - (iter->flags & GIT_ITERATOR_DONT_PRECOMPOSE_UNICODE) == 0) { - - if (git_repository__configmap_lookup(&precompose, repo, GIT_CONFIGMAP_PRECOMPOSE) < 0) - git_error_clear(); - else if (precompose) - iter->flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE; - } - - if ((iter->flags & GIT_ITERATOR_DONT_AUTOEXPAND)) - iter->flags |= GIT_ITERATOR_INCLUDE_TREES; - - if ((error = iterator_range_init(iter, options->start, options->end)) < 0 || - (error = iterator_pathlist_init(iter, &options->pathlist)) < 0) - return error; - - iterator_set_ignore_case(iter, ignore_case); - return 0; -} - -static void iterator_clear(git_iterator *iter) -{ - iter->started = false; - iter->ended = false; - iter->stat_calls = 0; - iter->pathlist_walk_idx = 0; - iter->flags &= ~GIT_ITERATOR_FIRST_ACCESS; -} - -GIT_INLINE(bool) iterator_has_started( - git_iterator *iter, const char *path, bool is_submodule) -{ - size_t path_len; - - if (iter->start == NULL || iter->started == true) - return true; - - /* the starting path is generally a prefix - we have started once we - * are prefixed by this path - */ - iter->started = (iter->prefixcomp(path, iter->start) >= 0); - - if (iter->started) - return true; - - path_len = strlen(path); - - /* if, however, we are a submodule, then we support `start` being - * suffixed with a `/` for crazy legacy reasons. match `submod` - * with a start path of `submod/`. - */ - if (is_submodule && iter->start_len && path_len == iter->start_len - 1 && - iter->start[iter->start_len-1] == '/') - return true; - - /* if, however, our current path is a directory, and our starting path - * is _beneath_ that directory, then recurse into the directory (even - * though we have not yet "started") - */ - if (path_len > 0 && path[path_len-1] == '/' && - iter->strncomp(path, iter->start, path_len) == 0) - return true; - - return false; -} - -GIT_INLINE(bool) iterator_has_ended(git_iterator *iter, const char *path) -{ - if (iter->end == NULL) - return false; - else if (iter->ended) - return true; - - iter->ended = (iter->prefixcomp(path, iter->end) > 0); - return iter->ended; -} - -/* walker for the index and tree iterator that allows it to walk the sorted - * pathlist entries alongside sorted iterator entries. - */ -static bool iterator_pathlist_next_is(git_iterator *iter, const char *path) -{ - char *p; - size_t path_len, p_len, cmp_len, i; - int cmp; - - if (iter->pathlist.length == 0) - return true; - - git_vector_sort(&iter->pathlist); - - path_len = strlen(path); - - /* for comparison, drop the trailing slash on the current '/' */ - if (path_len && path[path_len-1] == '/') - path_len--; - - for (i = iter->pathlist_walk_idx; i < iter->pathlist.length; i++) { - p = iter->pathlist.contents[i]; - p_len = strlen(p); - - if (p_len && p[p_len-1] == '/') - p_len--; - - cmp_len = min(path_len, p_len); - - /* see if the pathlist entry is a prefix of this path */ - cmp = iter->strncomp(p, path, cmp_len); - - /* prefix match - see if there's an exact match, or if we were - * given a path that matches the directory - */ - if (cmp == 0) { - /* if this pathlist entry is not suffixed with a '/' then - * it matches a path that is a file or a directory. - * (eg, pathlist = "foo" and path is "foo" or "foo/" or - * "foo/something") - */ - if (p[cmp_len] == '\0' && - (path[cmp_len] == '\0' || path[cmp_len] == '/')) - return true; - - /* if this pathlist entry _is_ suffixed with a '/' then - * it matches only paths that are directories. - * (eg, pathlist = "foo/" and path is "foo/" or "foo/something") - */ - if (p[cmp_len] == '/' && path[cmp_len] == '/') - return true; - } - - /* this pathlist entry sorts before the given path, try the next */ - else if (cmp < 0) { - iter->pathlist_walk_idx++; - continue; - } - - /* this pathlist sorts after the given path, no match. */ - else if (cmp > 0) { - break; - } - } - - return false; -} - -typedef enum { - ITERATOR_PATHLIST_NONE = 0, - ITERATOR_PATHLIST_IS_FILE = 1, - ITERATOR_PATHLIST_IS_DIR = 2, - ITERATOR_PATHLIST_IS_PARENT = 3, - ITERATOR_PATHLIST_FULL = 4 -} iterator_pathlist_search_t; - -static iterator_pathlist_search_t iterator_pathlist_search( - git_iterator *iter, const char *path, size_t path_len) -{ - int (*vector_cmp)(const void *a, const void *b); - const char *p; - size_t idx; - int error; - - if (iter->pathlist.length == 0) - return ITERATOR_PATHLIST_FULL; - - git_vector_sort(&iter->pathlist); - - vector_cmp = (iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0 ? - git__strcasecmp_cb : git__strcmp_cb; - - error = git_vector_bsearch2(&idx, &iter->pathlist, vector_cmp, path); - - /* the given path was found in the pathlist. since the pathlist only - * matches directories when they're suffixed with a '/', analyze the - * path string to determine whether it's a directory or not. - */ - if (error == 0) { - if (path_len && path[path_len-1] == '/') - return ITERATOR_PATHLIST_IS_DIR; - - return ITERATOR_PATHLIST_IS_FILE; - } - - /* at this point, the path we're examining may be a directory (though we - * don't know that yet, since we're avoiding a stat unless it's necessary) - * so walk the pathlist looking for the given path with a '/' after it, - */ - while ((p = git_vector_get(&iter->pathlist, idx)) != NULL) { - if (iter->prefixcomp(p, path) != 0) - break; - - /* an exact match would have been matched by the bsearch above */ - GIT_ASSERT_WITH_RETVAL(p[path_len], ITERATOR_PATHLIST_NONE); - - /* is this a literal directory entry (eg `foo/`) or a file beneath */ - if (p[path_len] == '/') { - return (p[path_len+1] == '\0') ? - ITERATOR_PATHLIST_IS_DIR : - ITERATOR_PATHLIST_IS_PARENT; - } - - if (p[path_len] > '/') - break; - - idx++; - } - - return ITERATOR_PATHLIST_NONE; -} - -/* Empty iterator */ - -static int empty_iterator_noop(const git_index_entry **e, git_iterator *i) -{ - GIT_UNUSED(i); - - if (e) - *e = NULL; - - return GIT_ITEROVER; -} - -static int empty_iterator_advance_over( - const git_index_entry **e, - git_iterator_status_t *s, - git_iterator *i) -{ - *s = GIT_ITERATOR_STATUS_EMPTY; - return empty_iterator_noop(e, i); -} - -static int empty_iterator_reset(git_iterator *i) -{ - GIT_UNUSED(i); - return 0; -} - -static void empty_iterator_free(git_iterator *i) -{ - GIT_UNUSED(i); -} - -typedef struct { - git_iterator base; - git_iterator_callbacks cb; -} empty_iterator; - -int git_iterator_for_nothing( - git_iterator **out, - git_iterator_options *options) -{ - empty_iterator *iter; - - static git_iterator_callbacks callbacks = { - empty_iterator_noop, - empty_iterator_noop, - empty_iterator_noop, - empty_iterator_advance_over, - empty_iterator_reset, - empty_iterator_free - }; - - *out = NULL; - - iter = git__calloc(1, sizeof(empty_iterator)); - GIT_ERROR_CHECK_ALLOC(iter); - - iter->base.type = GIT_ITERATOR_EMPTY; - iter->base.cb = &callbacks; - iter->base.flags = options->flags; - - *out = &iter->base; - return 0; -} - -/* Tree iterator */ - -typedef struct { - git_tree_entry *tree_entry; - const char *parent_path; -} tree_iterator_entry; - -typedef struct { - git_tree *tree; - - /* path to this particular frame (folder) */ - git_str path; - - /* a sorted list of the entries for this frame (folder), these are - * actually pointers to the iterator's entry pool. - */ - git_vector entries; - tree_iterator_entry *current; - - size_t next_idx; - - /* on case insensitive iterations, we also have an array of other - * paths that were case insensitively equal to this one, and their - * tree objects. we have coalesced the tree entries into this frame. - * a child `tree_iterator_entry` will contain a pointer to its actual - * parent path. - */ - git_vector similar_trees; - git_array_t(git_str) similar_paths; -} tree_iterator_frame; - -typedef struct { - git_iterator base; - git_tree *root; - git_array_t(tree_iterator_frame) frames; - - git_index_entry entry; - git_str entry_path; - - /* a pool of entries to reduce the number of allocations */ - git_pool entry_pool; -} tree_iterator; - -GIT_INLINE(tree_iterator_frame *) tree_iterator_parent_frame( - tree_iterator *iter) -{ - return iter->frames.size > 1 ? - &iter->frames.ptr[iter->frames.size-2] : NULL; -} - -GIT_INLINE(tree_iterator_frame *) tree_iterator_current_frame( - tree_iterator *iter) -{ - return iter->frames.size ? &iter->frames.ptr[iter->frames.size-1] : NULL; -} - -GIT_INLINE(int) tree_entry_cmp( - const git_tree_entry *a, const git_tree_entry *b, bool icase) -{ - return git_fs_path_cmp( - a->filename, a->filename_len, a->attr == GIT_FILEMODE_TREE, - b->filename, b->filename_len, b->attr == GIT_FILEMODE_TREE, - icase ? git__strncasecmp : git__strncmp); -} - -GIT_INLINE(int) tree_iterator_entry_cmp_icase( - const void *ptr_a, const void *ptr_b) -{ - const tree_iterator_entry *a = (const tree_iterator_entry *)ptr_a; - const tree_iterator_entry *b = (const tree_iterator_entry *)ptr_b; - - return tree_entry_cmp(a->tree_entry, b->tree_entry, true); -} - -static int tree_iterator_entry_sort_icase(const void *ptr_a, const void *ptr_b) -{ - const tree_iterator_entry *a = (const tree_iterator_entry *)ptr_a; - const tree_iterator_entry *b = (const tree_iterator_entry *)ptr_b; - - int c = tree_entry_cmp(a->tree_entry, b->tree_entry, true); - - /* stabilize the sort order for filenames that are (case insensitively) - * the same by examining the parent path (case sensitively) before - * falling back to a case sensitive sort of the filename. - */ - if (!c && a->parent_path != b->parent_path) - c = git__strcmp(a->parent_path, b->parent_path); - - if (!c) - c = tree_entry_cmp(a->tree_entry, b->tree_entry, false); - - return c; -} - -static int tree_iterator_compute_path( - git_str *out, - tree_iterator_entry *entry) -{ - git_str_clear(out); - - if (entry->parent_path) - git_str_joinpath(out, entry->parent_path, entry->tree_entry->filename); - else - git_str_puts(out, entry->tree_entry->filename); - - if (git_tree_entry__is_tree(entry->tree_entry)) - git_str_putc(out, '/'); - - if (git_str_oom(out)) - return -1; - - return 0; -} - -static int tree_iterator_frame_init( - tree_iterator *iter, - git_tree *tree, - tree_iterator_entry *frame_entry) -{ - tree_iterator_frame *new_frame = NULL; - tree_iterator_entry *new_entry; - git_tree *dup = NULL; - git_tree_entry *tree_entry; - git_vector_cmp cmp; - size_t i; - int error = 0; - - new_frame = git_array_alloc(iter->frames); - GIT_ERROR_CHECK_ALLOC(new_frame); - - if ((error = git_tree_dup(&dup, tree)) < 0) - goto done; - - memset(new_frame, 0x0, sizeof(tree_iterator_frame)); - new_frame->tree = dup; - - if (frame_entry && - (error = tree_iterator_compute_path(&new_frame->path, frame_entry)) < 0) - goto done; - - cmp = iterator__ignore_case(&iter->base) ? - tree_iterator_entry_sort_icase : NULL; - - if ((error = git_vector_init(&new_frame->entries, - dup->entries.size, cmp)) < 0) - goto done; - - git_array_foreach(dup->entries, i, tree_entry) { - if ((new_entry = git_pool_malloc(&iter->entry_pool, 1)) == NULL) { - git_error_set_oom(); - error = -1; - goto done; - } - - new_entry->tree_entry = tree_entry; - new_entry->parent_path = new_frame->path.ptr; - - if ((error = git_vector_insert(&new_frame->entries, new_entry)) < 0) - goto done; - } - - git_vector_set_sorted(&new_frame->entries, - !iterator__ignore_case(&iter->base)); - -done: - if (error < 0) { - git_tree_free(dup); - git_array_pop(iter->frames); - } - - return error; -} - -GIT_INLINE(tree_iterator_entry *) tree_iterator_current_entry( - tree_iterator_frame *frame) -{ - return frame->current; -} - -GIT_INLINE(int) tree_iterator_frame_push_neighbors( - tree_iterator *iter, - tree_iterator_frame *parent_frame, - tree_iterator_frame *frame, - const char *filename) -{ - tree_iterator_entry *entry, *new_entry; - git_tree *tree = NULL; - git_tree_entry *tree_entry; - git_str *path; - size_t new_size, i; - int error = 0; - - while (parent_frame->next_idx < parent_frame->entries.length) { - entry = parent_frame->entries.contents[parent_frame->next_idx]; - - if (strcasecmp(filename, entry->tree_entry->filename) != 0) - break; - - if ((error = git_tree_lookup(&tree, - iter->base.repo, &entry->tree_entry->oid)) < 0) - break; - - if (git_vector_insert(&parent_frame->similar_trees, tree) < 0) - break; - - path = git_array_alloc(parent_frame->similar_paths); - GIT_ERROR_CHECK_ALLOC(path); - - memset(path, 0, sizeof(git_str)); - - if ((error = tree_iterator_compute_path(path, entry)) < 0) - break; - - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, - frame->entries.length, tree->entries.size); - git_vector_size_hint(&frame->entries, new_size); - - git_array_foreach(tree->entries, i, tree_entry) { - new_entry = git_pool_malloc(&iter->entry_pool, 1); - GIT_ERROR_CHECK_ALLOC(new_entry); - - new_entry->tree_entry = tree_entry; - new_entry->parent_path = path->ptr; - - if ((error = git_vector_insert(&frame->entries, new_entry)) < 0) - break; - } - - if (error) - break; - - parent_frame->next_idx++; - } - - return error; -} - -GIT_INLINE(int) tree_iterator_frame_push( - tree_iterator *iter, tree_iterator_entry *entry) -{ - tree_iterator_frame *parent_frame, *frame; - git_tree *tree = NULL; - int error; - - if ((error = git_tree_lookup(&tree, - iter->base.repo, &entry->tree_entry->oid)) < 0 || - (error = tree_iterator_frame_init(iter, tree, entry)) < 0) - goto done; - - parent_frame = tree_iterator_parent_frame(iter); - frame = tree_iterator_current_frame(iter); - - /* if we're case insensitive, then we may have another directory that - * is (case insensitively) equal to this one. coalesce those children - * into this tree. - */ - if (iterator__ignore_case(&iter->base)) - error = tree_iterator_frame_push_neighbors(iter, - parent_frame, frame, entry->tree_entry->filename); - -done: - git_tree_free(tree); - return error; -} - -static int tree_iterator_frame_pop(tree_iterator *iter) -{ - tree_iterator_frame *frame; - git_str *buf = NULL; - git_tree *tree; - size_t i; - - GIT_ASSERT(iter->frames.size); - - frame = git_array_pop(iter->frames); - - git_vector_dispose(&frame->entries); - git_tree_free(frame->tree); - - do { - buf = git_array_pop(frame->similar_paths); - git_str_dispose(buf); - } while (buf != NULL); - - git_array_clear(frame->similar_paths); - - git_vector_foreach(&frame->similar_trees, i, tree) - git_tree_free(tree); - - git_vector_dispose(&frame->similar_trees); - - git_str_dispose(&frame->path); - - return 0; -} - -static int tree_iterator_current( - const git_index_entry **out, git_iterator *i) -{ - tree_iterator *iter = (tree_iterator *)i; - - if (!iterator__has_been_accessed(i)) - return iter->base.cb->advance(out, i); - - if (!iter->frames.size) { - *out = NULL; - return GIT_ITEROVER; - } - - *out = &iter->entry; - return 0; -} - -static void tree_iterator_set_current( - tree_iterator *iter, - tree_iterator_frame *frame, - tree_iterator_entry *entry) -{ - git_tree_entry *tree_entry = entry->tree_entry; - - frame->current = entry; - - memset(&iter->entry, 0x0, sizeof(git_index_entry)); - - iter->entry.mode = tree_entry->attr; - iter->entry.path = iter->entry_path.ptr; - git_oid_cpy(&iter->entry.id, &tree_entry->oid); -} - -static int tree_iterator_advance(const git_index_entry **out, git_iterator *i) -{ - tree_iterator *iter = (tree_iterator *)i; - int error = 0; - - iter->base.flags |= GIT_ITERATOR_FIRST_ACCESS; - - /* examine tree entries until we find the next one to return */ - while (true) { - tree_iterator_entry *prev_entry, *entry; - tree_iterator_frame *frame; - bool is_tree; - - if ((frame = tree_iterator_current_frame(iter)) == NULL) { - error = GIT_ITEROVER; - break; - } - - /* no more entries in this frame. pop the frame out */ - if (frame->next_idx == frame->entries.length) { - if ((error = tree_iterator_frame_pop(iter)) < 0) - break; - - continue; - } - - /* we may have coalesced the contents of case-insensitively same-named - * directories, so do the sort now. - */ - if (frame->next_idx == 0 && !git_vector_is_sorted(&frame->entries)) - git_vector_sort(&frame->entries); - - /* we have more entries in the current frame, that's our next entry */ - prev_entry = tree_iterator_current_entry(frame); - entry = frame->entries.contents[frame->next_idx]; - frame->next_idx++; - - /* we can have collisions when iterating case insensitively. (eg, - * 'A/a' and 'a/A'). squash this one if it's already been seen. - */ - if (iterator__ignore_case(&iter->base) && - prev_entry && - tree_iterator_entry_cmp_icase(prev_entry, entry) == 0) - continue; - - if ((error = tree_iterator_compute_path(&iter->entry_path, entry)) < 0) - break; - - /* if this path is before our start, advance over this entry */ - if (!iterator_has_started(&iter->base, iter->entry_path.ptr, false)) - continue; - - /* if this path is after our end, stop */ - if (iterator_has_ended(&iter->base, iter->entry_path.ptr)) { - error = GIT_ITEROVER; - break; - } - - /* if we have a list of paths we're interested in, examine it */ - if (!iterator_pathlist_next_is(&iter->base, iter->entry_path.ptr)) - continue; - - is_tree = git_tree_entry__is_tree(entry->tree_entry); - - /* if we are *not* including trees then advance over this entry */ - if (is_tree && !iterator__include_trees(iter)) { - - /* if we've found a tree (and are not returning it to the caller) - * and we are autoexpanding, then we want to return the first - * child. push the new directory and advance. - */ - if (iterator__do_autoexpand(iter)) { - if ((error = tree_iterator_frame_push(iter, entry)) < 0) - break; - } - - continue; - } - - tree_iterator_set_current(iter, frame, entry); - - /* if we are autoexpanding, then push this as a new frame, so that - * the next call to `advance` will dive into this directory. - */ - if (is_tree && iterator__do_autoexpand(iter)) - error = tree_iterator_frame_push(iter, entry); - - break; - } - - if (out) - *out = (error == 0) ? &iter->entry : NULL; - - return error; -} - -static int tree_iterator_advance_into( - const git_index_entry **out, git_iterator *i) -{ - tree_iterator *iter = (tree_iterator *)i; - tree_iterator_frame *frame; - tree_iterator_entry *prev_entry; - int error; - - if (out) - *out = NULL; - - if ((frame = tree_iterator_current_frame(iter)) == NULL) - return GIT_ITEROVER; - - /* get the last seen entry */ - prev_entry = tree_iterator_current_entry(frame); - - /* it's legal to call advance_into when auto-expand is on. in this case, - * we will have pushed a new (empty) frame on to the stack for this - * new directory. since it's empty, its current_entry should be null. - */ - GIT_ASSERT(iterator__do_autoexpand(i) ^ (prev_entry != NULL)); - - if (prev_entry) { - if (!git_tree_entry__is_tree(prev_entry->tree_entry)) - return 0; - - if ((error = tree_iterator_frame_push(iter, prev_entry)) < 0) - return error; - } - - /* we've advanced into the directory in question, let advance - * find the first entry - */ - return tree_iterator_advance(out, i); -} - -static int tree_iterator_advance_over( - const git_index_entry **out, - git_iterator_status_t *status, - git_iterator *i) -{ - *status = GIT_ITERATOR_STATUS_NORMAL; - return git_iterator_advance(out, i); -} - -static void tree_iterator_clear(tree_iterator *iter) -{ - while (iter->frames.size) - tree_iterator_frame_pop(iter); - - git_array_clear(iter->frames); - - git_pool_clear(&iter->entry_pool); - git_str_clear(&iter->entry_path); - - iterator_clear(&iter->base); -} - -static int tree_iterator_init(tree_iterator *iter) -{ - int error; - - if ((error = git_pool_init(&iter->entry_pool, sizeof(tree_iterator_entry))) < 0 || - (error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0) - return error; - - iter->base.flags &= ~GIT_ITERATOR_FIRST_ACCESS; - - return 0; -} - -static int tree_iterator_reset(git_iterator *i) -{ - tree_iterator *iter = (tree_iterator *)i; - - tree_iterator_clear(iter); - return tree_iterator_init(iter); -} - -static void tree_iterator_free(git_iterator *i) -{ - tree_iterator *iter = (tree_iterator *)i; - - tree_iterator_clear(iter); - - git_tree_free(iter->root); - git_str_dispose(&iter->entry_path); -} - -int git_iterator_for_tree( - git_iterator **out, - git_tree *tree, - git_iterator_options *options) -{ - tree_iterator *iter; - int error; - - static git_iterator_callbacks callbacks = { - tree_iterator_current, - tree_iterator_advance, - tree_iterator_advance_into, - tree_iterator_advance_over, - tree_iterator_reset, - tree_iterator_free - }; - - *out = NULL; - - if (tree == NULL) - return git_iterator_for_nothing(out, options); - - iter = git__calloc(1, sizeof(tree_iterator)); - GIT_ERROR_CHECK_ALLOC(iter); - - iter->base.type = GIT_ITERATOR_TREE; - iter->base.cb = &callbacks; - - if ((error = iterator_init_common(&iter->base, - git_tree_owner(tree), NULL, options)) < 0 || - (error = git_tree_dup(&iter->root, tree)) < 0 || - (error = tree_iterator_init(iter)) < 0) - goto on_error; - - *out = &iter->base; - return 0; - -on_error: - git_iterator_free(&iter->base); - return error; -} - -int git_iterator_current_tree_entry( - const git_tree_entry **tree_entry, git_iterator *i) -{ - tree_iterator *iter; - tree_iterator_frame *frame; - tree_iterator_entry *entry; - - GIT_ASSERT(i->type == GIT_ITERATOR_TREE); - - iter = (tree_iterator *)i; - - frame = tree_iterator_current_frame(iter); - entry = tree_iterator_current_entry(frame); - - *tree_entry = entry->tree_entry; - return 0; -} - -int git_iterator_current_parent_tree( - const git_tree **parent_tree, git_iterator *i, size_t depth) -{ - tree_iterator *iter; - tree_iterator_frame *frame; - - GIT_ASSERT(i->type == GIT_ITERATOR_TREE); - - iter = (tree_iterator *)i; - - GIT_ASSERT(depth < iter->frames.size); - frame = &iter->frames.ptr[iter->frames.size-depth-1]; - - *parent_tree = frame->tree; - return 0; -} - -/* Filesystem iterator */ - -typedef struct { - struct stat st; - size_t path_len; - iterator_pathlist_search_t match; - git_oid id; - char path[GIT_FLEX_ARRAY]; -} filesystem_iterator_entry; - -typedef struct { - git_vector entries; - git_pool entry_pool; - size_t next_idx; - - size_t path_len; - int is_ignored; -} filesystem_iterator_frame; - -typedef struct { - git_iterator base; - char *root; - size_t root_len; - - unsigned int dirload_flags; - - git_tree *tree; - git_index *index; - git_vector index_snapshot; - - git_oid_t oid_type; - - git_array_t(filesystem_iterator_frame) frames; - git_ignores ignores; - - /* info about the current entry */ - git_index_entry entry; - git_str current_path; - int current_is_ignored; - - /* temporary buffer for advance_over */ - git_str tmp_buf; -} filesystem_iterator; - - -GIT_INLINE(filesystem_iterator_frame *) filesystem_iterator_parent_frame( - filesystem_iterator *iter) -{ - return iter->frames.size > 1 ? - &iter->frames.ptr[iter->frames.size-2] : NULL; -} - -GIT_INLINE(filesystem_iterator_frame *) filesystem_iterator_current_frame( - filesystem_iterator *iter) -{ - return iter->frames.size ? &iter->frames.ptr[iter->frames.size-1] : NULL; -} - -GIT_INLINE(filesystem_iterator_entry *) filesystem_iterator_current_entry( - filesystem_iterator_frame *frame) -{ - return frame->next_idx == 0 ? - NULL : frame->entries.contents[frame->next_idx-1]; -} - -static int filesystem_iterator_entry_cmp(const void *_a, const void *_b) -{ - const filesystem_iterator_entry *a = (const filesystem_iterator_entry *)_a; - const filesystem_iterator_entry *b = (const filesystem_iterator_entry *)_b; - - return git__strcmp(a->path, b->path); -} - -static int filesystem_iterator_entry_cmp_icase(const void *_a, const void *_b) -{ - const filesystem_iterator_entry *a = (const filesystem_iterator_entry *)_a; - const filesystem_iterator_entry *b = (const filesystem_iterator_entry *)_b; - - return git__strcasecmp(a->path, b->path); -} - -#define FILESYSTEM_MAX_DEPTH 100 - -/** - * Figure out if an entry is a submodule. - * - * We consider it a submodule if the path is listed as a submodule in - * either the tree or the index. - */ -static int filesystem_iterator_is_submodule( - bool *out, filesystem_iterator *iter, const char *path, size_t path_len) -{ - bool is_submodule = false; - int error; - - *out = false; - - /* first see if this path is a submodule in HEAD */ - if (iter->tree) { - git_tree_entry *entry; - - error = git_tree_entry_bypath(&entry, iter->tree, path); - - if (error < 0 && error != GIT_ENOTFOUND) - return error; - - if (!error) { - is_submodule = (entry->attr == GIT_FILEMODE_COMMIT); - git_tree_entry_free(entry); - } - } - - if (!is_submodule && iter->base.index) { - size_t pos; - - error = git_index_snapshot_find(&pos, - &iter->index_snapshot, iter->base.entry_srch, path, path_len, 0); - - if (error < 0 && error != GIT_ENOTFOUND) - return error; - - if (!error) { - git_index_entry *e = git_vector_get(&iter->index_snapshot, pos); - is_submodule = (e->mode == GIT_FILEMODE_COMMIT); - } - } - - *out = is_submodule; - return 0; -} - -static void filesystem_iterator_frame_push_ignores( - filesystem_iterator *iter, - filesystem_iterator_entry *frame_entry, - filesystem_iterator_frame *new_frame) -{ - filesystem_iterator_frame *previous_frame; - const char *path = frame_entry ? frame_entry->path : ""; - - if (!iterator__honor_ignores(&iter->base)) - return; - - if (git_ignore__lookup(&new_frame->is_ignored, - &iter->ignores, path, GIT_DIR_FLAG_TRUE) < 0) { - git_error_clear(); - new_frame->is_ignored = GIT_IGNORE_NOTFOUND; - } - - /* if this is not the top level directory... */ - if (frame_entry) { - const char *relative_path; - - previous_frame = filesystem_iterator_parent_frame(iter); - - /* push new ignores for files in this directory */ - relative_path = frame_entry->path + previous_frame->path_len; - - /* inherit ignored from parent if no rule specified */ - if (new_frame->is_ignored <= GIT_IGNORE_NOTFOUND) - new_frame->is_ignored = previous_frame->is_ignored; - - git_ignore__push_dir(&iter->ignores, relative_path); - } -} - -static void filesystem_iterator_frame_pop_ignores( - filesystem_iterator *iter) -{ - if (iterator__honor_ignores(&iter->base)) - git_ignore__pop_dir(&iter->ignores); -} - -GIT_INLINE(bool) filesystem_iterator_examine_path( - bool *is_dir_out, - iterator_pathlist_search_t *match_out, - filesystem_iterator *iter, - filesystem_iterator_entry *frame_entry, - const char *path, - size_t path_len) -{ - bool is_dir = 0; - iterator_pathlist_search_t match = ITERATOR_PATHLIST_FULL; - - *is_dir_out = false; - *match_out = ITERATOR_PATHLIST_NONE; - - if (iter->base.start_len) { - int cmp = iter->base.strncomp(path, iter->base.start, path_len); - - /* we haven't stat'ed `path` yet, so we don't yet know if it's a - * directory or not. special case if the current path may be a - * directory that matches the start prefix. - */ - if (cmp == 0) { - if (iter->base.start[path_len] == '/') - is_dir = true; - - else if (iter->base.start[path_len] != '\0') - cmp = -1; - } - - if (cmp < 0) - return false; - } - - if (iter->base.end_len) { - int cmp = iter->base.strncomp(path, iter->base.end, iter->base.end_len); - - if (cmp > 0) - return false; - } - - /* if we have a pathlist that we're limiting to, examine this path now - * to avoid a `stat` if we're not interested in the path. - */ - if (iter->base.pathlist.length) { - /* if our parent was explicitly included, so too are we */ - if (frame_entry && frame_entry->match != ITERATOR_PATHLIST_IS_PARENT) - match = ITERATOR_PATHLIST_FULL; - else - match = iterator_pathlist_search(&iter->base, path, path_len); - - if (match == ITERATOR_PATHLIST_NONE) - return false; - - /* Ensure that the pathlist entry lines up with what we expected */ - if (match == ITERATOR_PATHLIST_IS_DIR || - match == ITERATOR_PATHLIST_IS_PARENT) - is_dir = true; - } - - *is_dir_out = is_dir; - *match_out = match; - return true; -} - -GIT_INLINE(bool) filesystem_iterator_is_dot_git( - filesystem_iterator *iter, const char *path, size_t path_len) -{ - size_t len; - - if (!iterator__ignore_dot_git(&iter->base)) - return false; - - if ((len = path_len) < 4) - return false; - - if (path[len - 1] == '/') - len--; - - if (git__tolower(path[len - 1]) != 't' || - git__tolower(path[len - 2]) != 'i' || - git__tolower(path[len - 3]) != 'g' || - git__tolower(path[len - 4]) != '.') - return false; - - return (len == 4 || path[len - 5] == '/'); -} - -static int filesystem_iterator_entry_hash( - filesystem_iterator *iter, - filesystem_iterator_entry *entry) -{ - git_str fullpath = GIT_STR_INIT; - int error; - - if (S_ISDIR(entry->st.st_mode)) { - memset(&entry->id, 0, git_oid_size(iter->oid_type)); - return 0; - } - - if (iter->base.type == GIT_ITERATOR_WORKDIR) - return git_repository_hashfile(&entry->id, - iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL); - - if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) && - !(error = git_path_validate_str_length(iter->base.repo, &fullpath))) - error = git_odb__hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB, iter->oid_type); - - git_str_dispose(&fullpath); - return error; -} - -static int filesystem_iterator_entry_init( - filesystem_iterator_entry **out, - filesystem_iterator *iter, - filesystem_iterator_frame *frame, - const char *path, - size_t path_len, - struct stat *statbuf, - iterator_pathlist_search_t pathlist_match) -{ - filesystem_iterator_entry *entry; - size_t entry_size; - int error = 0; - - *out = NULL; - - /* Make sure to append two bytes, one for the path's null - * termination, one for a possible trailing '/' for folders. - */ - GIT_ERROR_CHECK_ALLOC_ADD(&entry_size, - sizeof(filesystem_iterator_entry), path_len); - GIT_ERROR_CHECK_ALLOC_ADD(&entry_size, entry_size, 2); - - entry = git_pool_malloc(&frame->entry_pool, entry_size); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->path_len = path_len; - entry->match = pathlist_match; - memcpy(entry->path, path, path_len); - memcpy(&entry->st, statbuf, sizeof(struct stat)); - - /* Suffix directory paths with a '/' */ - if (S_ISDIR(entry->st.st_mode)) - entry->path[entry->path_len++] = '/'; - - entry->path[entry->path_len] = '\0'; - - if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH) - error = filesystem_iterator_entry_hash(iter, entry); - - if (!error) - *out = entry; - - return error; -} - -static int filesystem_iterator_frame_push( - filesystem_iterator *iter, - filesystem_iterator_entry *frame_entry) -{ - filesystem_iterator_frame *new_frame = NULL; - git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT; - git_str root = GIT_STR_INIT; - const char *path; - filesystem_iterator_entry *entry; - struct stat statbuf; - size_t path_len; - int error; - - if (iter->frames.size == FILESYSTEM_MAX_DEPTH) { - git_error_set(GIT_ERROR_REPOSITORY, - "directory nesting too deep (%"PRIuZ")", iter->frames.size); - return -1; - } - - new_frame = git_array_alloc(iter->frames); - GIT_ERROR_CHECK_ALLOC(new_frame); - - memset(new_frame, 0, sizeof(filesystem_iterator_frame)); - - if (frame_entry) - git_str_joinpath(&root, iter->root, frame_entry->path); - else - git_str_puts(&root, iter->root); - - if (git_str_oom(&root) || - git_path_validate_str_length(iter->base.repo, &root) < 0) { - error = -1; - goto done; - } - - new_frame->path_len = frame_entry ? frame_entry->path_len : 0; - - /* Any error here is equivalent to the dir not existing, skip over it */ - if ((error = git_fs_path_diriter_init( - &diriter, root.ptr, iter->dirload_flags)) < 0) { - error = GIT_ENOTFOUND; - goto done; - } - - if ((error = git_vector_init(&new_frame->entries, 64, - iterator__ignore_case(&iter->base) ? - filesystem_iterator_entry_cmp_icase : - filesystem_iterator_entry_cmp)) < 0) - goto done; - - if ((error = git_pool_init(&new_frame->entry_pool, 1)) < 0) - goto done; - - /* check if this directory is ignored */ - filesystem_iterator_frame_push_ignores(iter, frame_entry, new_frame); - - while ((error = git_fs_path_diriter_next(&diriter)) == 0) { - iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL; - git_str path_str = GIT_STR_INIT; - bool dir_expected = false; - - if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0) - goto done; - - path_str.ptr = (char *)path; - path_str.size = path_len; - - if ((error = git_path_validate_str_length(iter->base.repo, &path_str)) < 0) - goto done; - - GIT_ASSERT(path_len > iter->root_len); - - /* remove the prefix if requested */ - path += iter->root_len; - path_len -= iter->root_len; - - /* examine start / end and the pathlist to see if this path is in it. - * note that since we haven't yet stat'ed the path, we cannot know - * whether it's a directory yet or not, so this can give us an - * expected type (S_IFDIR or S_IFREG) that we should examine) - */ - if (!filesystem_iterator_examine_path(&dir_expected, &pathlist_match, - iter, frame_entry, path, path_len)) - continue; - - /* TODO: don't need to stat if assume unchanged for this path and - * we have an index, we can just copy the data out of it. - */ - - if ((error = git_fs_path_diriter_stat(&statbuf, &diriter)) < 0) { - /* file was removed between readdir and lstat */ - if (error == GIT_ENOTFOUND) - continue; - - /* treat the file as unreadable */ - memset(&statbuf, 0, sizeof(statbuf)); - statbuf.st_mode = GIT_FILEMODE_UNREADABLE; - - error = 0; - } - - iter->base.stat_calls++; - - /* Ignore wacky things in the filesystem */ - if (!S_ISDIR(statbuf.st_mode) && - !S_ISREG(statbuf.st_mode) && - !S_ISLNK(statbuf.st_mode) && - statbuf.st_mode != GIT_FILEMODE_UNREADABLE) - continue; - - if (filesystem_iterator_is_dot_git(iter, path, path_len)) - continue; - - /* convert submodules to GITLINK and remove trailing slashes */ - if (S_ISDIR(statbuf.st_mode)) { - bool submodule = false; - - if ((error = filesystem_iterator_is_submodule(&submodule, - iter, path, path_len)) < 0) - goto done; - - if (submodule) - statbuf.st_mode = GIT_FILEMODE_COMMIT; - } - - /* Ensure that the pathlist entry lines up with what we expected */ - else if (dir_expected) - continue; - - if ((error = filesystem_iterator_entry_init(&entry, - iter, new_frame, path, path_len, &statbuf, pathlist_match)) < 0) - goto done; - - git_vector_insert(&new_frame->entries, entry); - } - - if (error == GIT_ITEROVER) - error = 0; - - /* sort now that directory suffix is added */ - git_vector_sort(&new_frame->entries); - -done: - if (error < 0) - git_array_pop(iter->frames); - - git_str_dispose(&root); - git_fs_path_diriter_free(&diriter); - return error; -} - -GIT_INLINE(int) filesystem_iterator_frame_pop(filesystem_iterator *iter) -{ - filesystem_iterator_frame *frame; - - GIT_ASSERT(iter->frames.size); - - frame = git_array_pop(iter->frames); - filesystem_iterator_frame_pop_ignores(iter); - - git_pool_clear(&frame->entry_pool); - git_vector_dispose(&frame->entries); - - return 0; -} - -static void filesystem_iterator_set_current( - filesystem_iterator *iter, - filesystem_iterator_entry *entry) -{ - /* - * Index entries are limited to 32 bit timestamps. We can safely - * cast this since workdir times are only used in the cache; any - * mismatch will cause a hash recomputation which is unfortunate - * but affects only people who set their filetimes to 2038. - * (Same with the file size.) - */ - iter->entry.ctime.seconds = (int32_t)entry->st.st_ctime; - iter->entry.mtime.seconds = (int32_t)entry->st.st_mtime; - -#if defined(GIT_USE_NSEC) - iter->entry.ctime.nanoseconds = entry->st.st_ctime_nsec; - iter->entry.mtime.nanoseconds = entry->st.st_mtime_nsec; -#else - iter->entry.ctime.nanoseconds = 0; - iter->entry.mtime.nanoseconds = 0; -#endif - - iter->entry.dev = entry->st.st_dev; - iter->entry.ino = entry->st.st_ino; - iter->entry.mode = git_futils_canonical_mode(entry->st.st_mode); - iter->entry.uid = entry->st.st_uid; - iter->entry.gid = entry->st.st_gid; - iter->entry.file_size = (uint32_t)entry->st.st_size; - - if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH) - git_oid_cpy(&iter->entry.id, &entry->id); - else - git_oid_clear(&iter->entry.id, iter->oid_type); - - iter->entry.path = entry->path; - - iter->current_is_ignored = GIT_IGNORE_UNCHECKED; -} - -static int filesystem_iterator_current( - const git_index_entry **out, git_iterator *i) -{ - filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - - if (!iterator__has_been_accessed(i)) - return iter->base.cb->advance(out, i); - - if (!iter->frames.size) { - *out = NULL; - return GIT_ITEROVER; - } - - *out = &iter->entry; - return 0; -} - -static int filesystem_iterator_is_dir( - bool *is_dir, - const filesystem_iterator *iter, - const filesystem_iterator_entry *entry) -{ - struct stat st; - git_str fullpath = GIT_STR_INIT; - int error = 0; - - if (S_ISDIR(entry->st.st_mode)) { - *is_dir = 1; - goto done; - } - - if (!iterator__descend_symlinks(iter) || !S_ISLNK(entry->st.st_mode)) { - *is_dir = 0; - goto done; - } - - if ((error = git_str_joinpath(&fullpath, iter->root, entry->path)) < 0 || - (error = git_path_validate_str_length(iter->base.repo, &fullpath)) < 0 || - (error = p_stat(fullpath.ptr, &st)) < 0) - goto done; - - *is_dir = S_ISDIR(st.st_mode); - -done: - git_str_dispose(&fullpath); - return error; -} - -static int filesystem_iterator_advance( - const git_index_entry **out, git_iterator *i) -{ - filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - bool is_dir; - int error = 0; - - iter->base.flags |= GIT_ITERATOR_FIRST_ACCESS; - - /* examine filesystem entries until we find the next one to return */ - while (true) { - filesystem_iterator_frame *frame; - filesystem_iterator_entry *entry; - - if ((frame = filesystem_iterator_current_frame(iter)) == NULL) { - error = GIT_ITEROVER; - break; - } - - /* no more entries in this frame. pop the frame out */ - if (frame->next_idx == frame->entries.length) { - filesystem_iterator_frame_pop(iter); - continue; - } - - /* we have more entries in the current frame, that's our next entry */ - entry = frame->entries.contents[frame->next_idx]; - frame->next_idx++; - - if ((error = filesystem_iterator_is_dir(&is_dir, iter, entry)) < 0) - break; - - if (is_dir) { - if (iterator__do_autoexpand(iter)) { - error = filesystem_iterator_frame_push(iter, entry); - - /* may get GIT_ENOTFOUND due to races or permission problems - * that we want to quietly swallow - */ - if (error == GIT_ENOTFOUND) - continue; - else if (error < 0) - break; - } - - if (!iterator__include_trees(iter)) - continue; - } - - filesystem_iterator_set_current(iter, entry); - break; - } - - if (out) - *out = (error == 0) ? &iter->entry : NULL; - - return error; -} - -static int filesystem_iterator_advance_into( - const git_index_entry **out, git_iterator *i) -{ - filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - filesystem_iterator_frame *frame; - filesystem_iterator_entry *prev_entry; - int error; - - if (out) - *out = NULL; - - if ((frame = filesystem_iterator_current_frame(iter)) == NULL) - return GIT_ITEROVER; - - /* get the last seen entry */ - prev_entry = filesystem_iterator_current_entry(frame); - - /* it's legal to call advance_into when auto-expand is on. in this case, - * we will have pushed a new (empty) frame on to the stack for this - * new directory. since it's empty, its current_entry should be null. - */ - GIT_ASSERT(iterator__do_autoexpand(i) ^ (prev_entry != NULL)); - - if (prev_entry) { - if (prev_entry->st.st_mode != GIT_FILEMODE_COMMIT && - !S_ISDIR(prev_entry->st.st_mode)) - return 0; - - if ((error = filesystem_iterator_frame_push(iter, prev_entry)) < 0) - return error; - } - - /* we've advanced into the directory in question, let advance - * find the first entry - */ - return filesystem_iterator_advance(out, i); -} - -int git_iterator_current_workdir_path(git_str **out, git_iterator *i) -{ - filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - const git_index_entry *entry; - - if (i->type != GIT_ITERATOR_FS && - i->type != GIT_ITERATOR_WORKDIR) { - *out = NULL; - return 0; - } - - git_str_truncate(&iter->current_path, iter->root_len); - - if (git_iterator_current(&entry, i) < 0 || - git_str_puts(&iter->current_path, entry->path) < 0) - return -1; - - *out = &iter->current_path; - return 0; -} - -GIT_INLINE(git_dir_flag) entry_dir_flag(git_index_entry *entry) -{ -#if defined(GIT_WIN32) && !defined(__MINGW32__) - return (entry && entry->mode) ? - (S_ISDIR(entry->mode) ? GIT_DIR_FLAG_TRUE : GIT_DIR_FLAG_FALSE) : - GIT_DIR_FLAG_UNKNOWN; -#else - GIT_UNUSED(entry); - return GIT_DIR_FLAG_UNKNOWN; -#endif -} - -static void filesystem_iterator_update_ignored(filesystem_iterator *iter) -{ - filesystem_iterator_frame *frame; - git_dir_flag dir_flag = entry_dir_flag(&iter->entry); - - if (git_ignore__lookup(&iter->current_is_ignored, - &iter->ignores, iter->entry.path, dir_flag) < 0) { - git_error_clear(); - iter->current_is_ignored = GIT_IGNORE_NOTFOUND; - } - - /* use ignore from containing frame stack */ - if (iter->current_is_ignored <= GIT_IGNORE_NOTFOUND) { - frame = filesystem_iterator_current_frame(iter); - iter->current_is_ignored = frame->is_ignored; - } -} - -GIT_INLINE(bool) filesystem_iterator_current_is_ignored( - filesystem_iterator *iter) -{ - if (iter->current_is_ignored == GIT_IGNORE_UNCHECKED) - filesystem_iterator_update_ignored(iter); - - return (iter->current_is_ignored == GIT_IGNORE_TRUE); -} - -bool git_iterator_current_is_ignored(git_iterator *i) -{ - filesystem_iterator *iter = NULL; - - if (i->type != GIT_ITERATOR_WORKDIR) - return false; - - iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - - return filesystem_iterator_current_is_ignored(iter); -} - -bool git_iterator_current_tree_is_ignored(git_iterator *i) -{ - filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - filesystem_iterator_frame *frame; - - if (i->type != GIT_ITERATOR_WORKDIR) - return false; - - frame = filesystem_iterator_current_frame(iter); - return (frame->is_ignored == GIT_IGNORE_TRUE); -} - -static int filesystem_iterator_advance_over( - const git_index_entry **out, - git_iterator_status_t *status, - git_iterator *i) -{ - filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - filesystem_iterator_frame *current_frame; - filesystem_iterator_entry *current_entry; - const git_index_entry *entry = NULL; - const char *base; - int error = 0; - - *out = NULL; - *status = GIT_ITERATOR_STATUS_NORMAL; - - GIT_ASSERT(iterator__has_been_accessed(i)); - - current_frame = filesystem_iterator_current_frame(iter); - GIT_ASSERT(current_frame); - - current_entry = filesystem_iterator_current_entry(current_frame); - GIT_ASSERT(current_entry); - - if ((error = git_iterator_current(&entry, i)) < 0) - return error; - - if (!S_ISDIR(entry->mode)) { - if (filesystem_iterator_current_is_ignored(iter)) - *status = GIT_ITERATOR_STATUS_IGNORED; - - return filesystem_iterator_advance(out, i); - } - - git_str_clear(&iter->tmp_buf); - if ((error = git_str_puts(&iter->tmp_buf, entry->path)) < 0) - return error; - - base = iter->tmp_buf.ptr; - - /* scan inside the directory looking for files. if we find nothing, - * we will remain EMPTY. if we find any ignored item, upgrade EMPTY to - * IGNORED. if we find a real actual item, upgrade all the way to NORMAL - * and then stop. - * - * however, if we're here looking for a pathlist item (but are not - * actually in the pathlist ourselves) then start at FILTERED instead of - * EMPTY. callers then know that this path was not something they asked - * about. - */ - *status = current_entry->match == ITERATOR_PATHLIST_IS_PARENT ? - GIT_ITERATOR_STATUS_FILTERED : GIT_ITERATOR_STATUS_EMPTY; - - while (entry && !iter->base.prefixcomp(entry->path, base)) { - if (filesystem_iterator_current_is_ignored(iter)) { - /* if we found an explicitly ignored item, then update from - * EMPTY to IGNORED - */ - *status = GIT_ITERATOR_STATUS_IGNORED; - } else if (S_ISDIR(entry->mode)) { - error = filesystem_iterator_advance_into(&entry, i); - - if (!error) - continue; - - /* this directory disappeared, ignore it */ - else if (error == GIT_ENOTFOUND) - error = 0; - - /* a real error occurred */ - else - break; - } else { - /* we found a non-ignored item, treat parent as untracked */ - *status = GIT_ITERATOR_STATUS_NORMAL; - break; - } - - if ((error = git_iterator_advance(&entry, i)) < 0) - break; - } - - /* wrap up scan back to base directory */ - while (entry && !iter->base.prefixcomp(entry->path, base)) { - if ((error = git_iterator_advance(&entry, i)) < 0) - break; - } - - if (!error) - *out = entry; - - return error; -} - -static void filesystem_iterator_clear(filesystem_iterator *iter) -{ - while (iter->frames.size) - filesystem_iterator_frame_pop(iter); - - git_array_clear(iter->frames); - git_ignore__free(&iter->ignores); - - git_str_dispose(&iter->tmp_buf); - - iterator_clear(&iter->base); -} - -static int filesystem_iterator_init(filesystem_iterator *iter) -{ - int error; - - if (iterator__honor_ignores(&iter->base) && - (error = git_ignore__for_path(iter->base.repo, - ".gitignore", &iter->ignores)) < 0) - return error; - - if ((error = filesystem_iterator_frame_push(iter, NULL)) < 0) - return error; - - iter->base.flags &= ~GIT_ITERATOR_FIRST_ACCESS; - - return 0; -} - -static int filesystem_iterator_reset(git_iterator *i) -{ - filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - - filesystem_iterator_clear(iter); - return filesystem_iterator_init(iter); -} - -static void filesystem_iterator_free(git_iterator *i) -{ - filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base); - git__free(iter->root); - git_str_dispose(&iter->current_path); - git_tree_free(iter->tree); - if (iter->index) - git_index_snapshot_release(&iter->index_snapshot, iter->index); - filesystem_iterator_clear(iter); -} - -static int iterator_for_filesystem( - git_iterator **out, - git_repository *repo, - const char *root, - git_index *index, - git_tree *tree, - git_iterator_t type, - git_iterator_options *options) -{ - filesystem_iterator *iter; - size_t root_len; - int error; - - static git_iterator_callbacks callbacks = { - filesystem_iterator_current, - filesystem_iterator_advance, - filesystem_iterator_advance_into, - filesystem_iterator_advance_over, - filesystem_iterator_reset, - filesystem_iterator_free - }; - - *out = NULL; - - if (root == NULL) - return git_iterator_for_nothing(out, options); - - iter = git__calloc(1, sizeof(filesystem_iterator)); - GIT_ERROR_CHECK_ALLOC(iter); - - iter->base.type = type; - iter->base.cb = &callbacks; - - root_len = strlen(root); - - iter->root = git__malloc(root_len+2); - GIT_ERROR_CHECK_ALLOC(iter->root); - - memcpy(iter->root, root, root_len); - - if (root_len == 0 || root[root_len-1] != '/') { - iter->root[root_len] = '/'; - root_len++; - } - iter->root[root_len] = '\0'; - iter->root_len = root_len; - - if ((error = git_str_puts(&iter->current_path, iter->root)) < 0) - goto on_error; - - if ((error = iterator_init_common(&iter->base, repo, index, options)) < 0) - goto on_error; - - if (tree && (error = git_tree_dup(&iter->tree, tree)) < 0) - goto on_error; - - if (index && - (error = git_index_snapshot_new(&iter->index_snapshot, index)) < 0) - goto on_error; - - iter->index = index; - iter->dirload_flags = - (iterator__ignore_case(&iter->base) ? - GIT_FS_PATH_DIR_IGNORE_CASE : 0) | - (iterator__flag(&iter->base, PRECOMPOSE_UNICODE) ? - GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE : 0); - - iter->oid_type = options->oid_type; - - if ((error = filesystem_iterator_init(iter)) < 0) - goto on_error; - - *out = &iter->base; - return 0; - -on_error: - git_iterator_free(&iter->base); - return error; -} - -int git_iterator_for_filesystem( - git_iterator **out, - const char *root, - git_iterator_options *given_opts) -{ - git_iterator_options options = GIT_ITERATOR_OPTIONS_INIT; - - if (given_opts) - memcpy(&options, given_opts, sizeof(git_iterator_options)); - - return iterator_for_filesystem(out, - NULL, root, NULL, NULL, GIT_ITERATOR_FS, &options); -} - -int git_iterator_for_workdir_ext( - git_iterator **out, - git_repository *repo, - const char *repo_workdir, - git_index *index, - git_tree *tree, - git_iterator_options *given_opts) -{ - git_iterator_options options = GIT_ITERATOR_OPTIONS_INIT; - - if (!repo_workdir) { - if (git_repository__ensure_not_bare(repo, "scan working directory") < 0) - return GIT_EBAREREPO; - - repo_workdir = git_repository_workdir(repo); - } - - /* upgrade to a workdir iterator, adding necessary internal flags */ - if (given_opts) - memcpy(&options, given_opts, sizeof(git_iterator_options)); - - options.flags |= GIT_ITERATOR_HONOR_IGNORES | - GIT_ITERATOR_IGNORE_DOT_GIT; - - if (!options.oid_type) - options.oid_type = repo->oid_type; - else if (options.oid_type != repo->oid_type) - git_error_set(GIT_ERROR_INVALID, - "specified object ID type does not match repository object ID type"); - - return iterator_for_filesystem(out, - repo, repo_workdir, index, tree, GIT_ITERATOR_WORKDIR, &options); -} - - -/* Index iterator */ - - -typedef struct { - git_iterator base; - git_vector entries; - size_t next_idx; - - /* the pseudotree entry */ - git_index_entry tree_entry; - git_str tree_buf; - bool skip_tree; - - const git_index_entry *entry; -} index_iterator; - -static int index_iterator_current( - const git_index_entry **out, git_iterator *i) -{ - index_iterator *iter = (index_iterator *)i; - - if (!iterator__has_been_accessed(i)) - return iter->base.cb->advance(out, i); - - if (iter->entry == NULL) { - *out = NULL; - return GIT_ITEROVER; - } - - *out = iter->entry; - return 0; -} - -static bool index_iterator_create_pseudotree( - const git_index_entry **out, - index_iterator *iter, - const char *path) -{ - const char *prev_path, *relative_path, *dirsep; - size_t common_len; - - prev_path = iter->entry ? iter->entry->path : ""; - - /* determine if the new path is in a different directory from the old */ - common_len = git_fs_path_common_dirlen(prev_path, path); - relative_path = path + common_len; - - if ((dirsep = strchr(relative_path, '/')) == NULL) - return false; - - git_str_clear(&iter->tree_buf); - git_str_put(&iter->tree_buf, path, (dirsep - path) + 1); - - iter->tree_entry.mode = GIT_FILEMODE_TREE; - iter->tree_entry.path = iter->tree_buf.ptr; - - *out = &iter->tree_entry; - return true; -} - -static int index_iterator_skip_pseudotree(index_iterator *iter) -{ - GIT_ASSERT(iterator__has_been_accessed(&iter->base)); - GIT_ASSERT(S_ISDIR(iter->entry->mode)); - - while (true) { - const git_index_entry *next_entry = NULL; - - if (++iter->next_idx >= iter->entries.length) - return GIT_ITEROVER; - - next_entry = iter->entries.contents[iter->next_idx]; - - if (iter->base.strncomp(iter->tree_buf.ptr, next_entry->path, - iter->tree_buf.size) != 0) - break; - } - - iter->skip_tree = false; - return 0; -} - -static int index_iterator_advance( - const git_index_entry **out, git_iterator *i) -{ - index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base); - const git_index_entry *entry = NULL; - bool is_submodule; - int error = 0; - - iter->base.flags |= GIT_ITERATOR_FIRST_ACCESS; - - while (true) { - if (iter->next_idx >= iter->entries.length) { - error = GIT_ITEROVER; - break; - } - - /* we were not asked to expand this pseudotree. advance over it. */ - if (iter->skip_tree) { - index_iterator_skip_pseudotree(iter); - continue; - } - - entry = iter->entries.contents[iter->next_idx]; - is_submodule = S_ISGITLINK(entry->mode); - - if (!iterator_has_started(&iter->base, entry->path, is_submodule)) { - iter->next_idx++; - continue; - } - - if (iterator_has_ended(&iter->base, entry->path)) { - error = GIT_ITEROVER; - break; - } - - /* if we have a list of paths we're interested in, examine it */ - if (!iterator_pathlist_next_is(&iter->base, entry->path)) { - iter->next_idx++; - continue; - } - - /* if this is a conflict, skip it unless we're including conflicts */ - if (git_index_entry_is_conflict(entry) && - !iterator__include_conflicts(&iter->base)) { - iter->next_idx++; - continue; - } - - /* we've found what will be our next _file_ entry. but if we are - * returning trees entries, we may need to return a pseudotree - * entry that will contain this. don't advance over this entry, - * though, we still need to return it on the next `advance`. - */ - if (iterator__include_trees(&iter->base) && - index_iterator_create_pseudotree(&entry, iter, entry->path)) { - - /* Note whether this pseudo tree should be expanded or not */ - iter->skip_tree = iterator__dont_autoexpand(&iter->base); - break; - } - - iter->next_idx++; - break; - } - - iter->entry = (error == 0) ? entry : NULL; - - if (out) - *out = iter->entry; - - return error; -} - -static int index_iterator_advance_into( - const git_index_entry **out, git_iterator *i) -{ - index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base); - - if (! S_ISDIR(iter->tree_entry.mode)) { - if (out) - *out = NULL; - - return 0; - } - - iter->skip_tree = false; - return index_iterator_advance(out, i); -} - -static int index_iterator_advance_over( - const git_index_entry **out, - git_iterator_status_t *status, - git_iterator *i) -{ - index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base); - const git_index_entry *entry; - int error; - - if ((error = index_iterator_current(&entry, i)) < 0) - return error; - - if (S_ISDIR(entry->mode)) - index_iterator_skip_pseudotree(iter); - - *status = GIT_ITERATOR_STATUS_NORMAL; - return index_iterator_advance(out, i); -} - -static void index_iterator_clear(index_iterator *iter) -{ - iterator_clear(&iter->base); -} - -static int index_iterator_init(index_iterator *iter) -{ - iter->base.flags &= ~GIT_ITERATOR_FIRST_ACCESS; - iter->next_idx = 0; - iter->skip_tree = false; - return 0; -} - -static int index_iterator_reset(git_iterator *i) -{ - index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base); - - index_iterator_clear(iter); - return index_iterator_init(iter); -} - -static void index_iterator_free(git_iterator *i) -{ - index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base); - - git_index_snapshot_release(&iter->entries, iter->base.index); - git_str_dispose(&iter->tree_buf); -} - -int git_iterator_for_index( - git_iterator **out, - git_repository *repo, - git_index *index, - git_iterator_options *options) -{ - index_iterator *iter; - int error; - - static git_iterator_callbacks callbacks = { - index_iterator_current, - index_iterator_advance, - index_iterator_advance_into, - index_iterator_advance_over, - index_iterator_reset, - index_iterator_free - }; - - *out = NULL; - - if (index == NULL) - return git_iterator_for_nothing(out, options); - - iter = git__calloc(1, sizeof(index_iterator)); - GIT_ERROR_CHECK_ALLOC(iter); - - iter->base.type = GIT_ITERATOR_INDEX; - iter->base.cb = &callbacks; - - if ((error = iterator_init_common(&iter->base, repo, index, options)) < 0 || - (error = git_index_snapshot_new(&iter->entries, index)) < 0 || - (error = index_iterator_init(iter)) < 0) - goto on_error; - - git_vector_set_cmp(&iter->entries, iterator__ignore_case(&iter->base) ? - git_index_entry_icmp : git_index_entry_cmp); - git_vector_sort(&iter->entries); - - *out = &iter->base; - return 0; - -on_error: - git_iterator_free(&iter->base); - return error; -} - - -/* Iterator API */ - -int git_iterator_reset_range( - git_iterator *i, const char *start, const char *end) -{ - if (iterator_reset_range(i, start, end) < 0) - return -1; - - return i->cb->reset(i); -} - -int git_iterator_set_ignore_case(git_iterator *i, bool ignore_case) -{ - GIT_ASSERT(!iterator__has_been_accessed(i)); - iterator_set_ignore_case(i, ignore_case); - return 0; -} - -void git_iterator_free(git_iterator *iter) -{ - if (iter == NULL) - return; - - iter->cb->free(iter); - - git_vector_dispose(&iter->pathlist); - git__free(iter->start); - git__free(iter->end); - - memset(iter, 0, sizeof(*iter)); - - git__free(iter); -} - -int git_iterator_foreach( - git_iterator *iterator, - git_iterator_foreach_cb cb, - void *data) -{ - const git_index_entry *iterator_item; - int error = 0; - - if ((error = git_iterator_current(&iterator_item, iterator)) < 0) - goto done; - - if ((error = cb(iterator_item, data)) != 0) - goto done; - - while (true) { - if ((error = git_iterator_advance(&iterator_item, iterator)) < 0) - goto done; - - if ((error = cb(iterator_item, data)) != 0) - goto done; - } - -done: - if (error == GIT_ITEROVER) - error = 0; - - return error; -} - -int git_iterator_walk( - git_iterator **iterators, - size_t cnt, - git_iterator_walk_cb cb, - void *data) -{ - const git_index_entry **iterator_item; /* next in each iterator */ - const git_index_entry **cur_items; /* current path in each iter */ - const git_index_entry *first_match; - size_t i, j; - int error = 0; - - iterator_item = git__calloc(cnt, sizeof(git_index_entry *)); - cur_items = git__calloc(cnt, sizeof(git_index_entry *)); - - GIT_ERROR_CHECK_ALLOC(iterator_item); - GIT_ERROR_CHECK_ALLOC(cur_items); - - /* Set up the iterators */ - for (i = 0; i < cnt; i++) { - error = git_iterator_current(&iterator_item[i], iterators[i]); - - if (error < 0 && error != GIT_ITEROVER) - goto done; - } - - while (true) { - for (i = 0; i < cnt; i++) - cur_items[i] = NULL; - - first_match = NULL; - - /* Find the next path(s) to consume from each iterator */ - for (i = 0; i < cnt; i++) { - if (iterator_item[i] == NULL) - continue; - - if (first_match == NULL) { - first_match = iterator_item[i]; - cur_items[i] = iterator_item[i]; - } else { - int path_diff = git_index_entry_cmp(iterator_item[i], first_match); - - if (path_diff < 0) { - /* Found an index entry that sorts before the one we're - * looking at. Forget that we've seen the other and - * look at the other iterators for this path. - */ - for (j = 0; j < i; j++) - cur_items[j] = NULL; - - first_match = iterator_item[i]; - cur_items[i] = iterator_item[i]; - } else if (path_diff == 0) { - cur_items[i] = iterator_item[i]; - } - } - } - - if (first_match == NULL) - break; - - if ((error = cb(cur_items, data)) != 0) - goto done; - - /* Advance each iterator that participated */ - for (i = 0; i < cnt; i++) { - if (cur_items[i] == NULL) - continue; - - error = git_iterator_advance(&iterator_item[i], iterators[i]); - - if (error < 0 && error != GIT_ITEROVER) - goto done; - } - } - -done: - git__free((git_index_entry **)iterator_item); - git__free((git_index_entry **)cur_items); - - if (error == GIT_ITEROVER) - error = 0; - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/iterator.h b/vendor/libgit2-sys/libgit2/src/libgit2/iterator.h deleted file mode 100644 index 7963ce7..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/iterator.h +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_iterator_h__ -#define INCLUDE_iterator_h__ - -#include "common.h" - -#include "git2/index.h" -#include "vector.h" -#include "str.h" -#include "ignore.h" - -typedef struct git_iterator git_iterator; - -typedef enum { - GIT_ITERATOR_EMPTY = 0, - GIT_ITERATOR_TREE = 1, - GIT_ITERATOR_INDEX = 2, - GIT_ITERATOR_WORKDIR = 3, - GIT_ITERATOR_FS = 4 -} git_iterator_t; - -typedef enum { - /** ignore case for entry sort order */ - GIT_ITERATOR_IGNORE_CASE = (1u << 0), - /** force case sensitivity for entry sort order */ - GIT_ITERATOR_DONT_IGNORE_CASE = (1u << 1), - /** return tree items in addition to blob items */ - GIT_ITERATOR_INCLUDE_TREES = (1u << 2), - /** don't flatten trees, requiring advance_into (implies INCLUDE_TREES) */ - GIT_ITERATOR_DONT_AUTOEXPAND = (1u << 3), - /** convert precomposed unicode to decomposed unicode */ - GIT_ITERATOR_PRECOMPOSE_UNICODE = (1u << 4), - /** never convert precomposed unicode to decomposed unicode */ - GIT_ITERATOR_DONT_PRECOMPOSE_UNICODE = (1u << 5), - /** include conflicts */ - GIT_ITERATOR_INCLUDE_CONFLICTS = (1u << 6), - /** descend into symlinked directories */ - GIT_ITERATOR_DESCEND_SYMLINKS = (1u << 7), - /** hash files in workdir or filesystem iterators */ - GIT_ITERATOR_INCLUDE_HASH = (1u << 8) -} git_iterator_flag_t; - -typedef enum { - GIT_ITERATOR_STATUS_NORMAL = 0, - GIT_ITERATOR_STATUS_IGNORED = 1, - GIT_ITERATOR_STATUS_EMPTY = 2, - GIT_ITERATOR_STATUS_FILTERED = 3 -} git_iterator_status_t; - -typedef struct { - const char *start; - const char *end; - - /* paths to include in the iterator (literal). if set, any paths not - * listed here will be excluded from iteration. - */ - git_strarray pathlist; - - /* flags, from above */ - unsigned int flags; - - /* oid type - necessary for non-workdir filesystem iterators */ - git_oid_t oid_type; -} git_iterator_options; - -#define GIT_ITERATOR_OPTIONS_INIT {0} - -typedef struct { - int (*current)(const git_index_entry **, git_iterator *); - int (*advance)(const git_index_entry **, git_iterator *); - int (*advance_into)(const git_index_entry **, git_iterator *); - int (*advance_over)( - const git_index_entry **, git_iterator_status_t *, git_iterator *); - int (*reset)(git_iterator *); - void (*free)(git_iterator *); -} git_iterator_callbacks; - -struct git_iterator { - git_iterator_t type; - git_iterator_callbacks *cb; - - git_repository *repo; - git_index *index; - - char *start; - size_t start_len; - - char *end; - size_t end_len; - - bool started; - bool ended; - git_vector pathlist; - size_t pathlist_walk_idx; - int (*strcomp)(const char *a, const char *b); - int (*strncomp)(const char *a, const char *b, size_t n); - int (*prefixcomp)(const char *str, const char *prefix); - int (*entry_srch)(const void *key, const void *array_member); - size_t stat_calls; - unsigned int flags; -}; - -extern int git_iterator_for_nothing( - git_iterator **out, - git_iterator_options *options); - -/* tree iterators will match the ignore_case value from the index of the - * repository, unless you override with a non-zero flag value - */ -extern int git_iterator_for_tree( - git_iterator **out, - git_tree *tree, - git_iterator_options *options); - -/* index iterators will take the ignore_case value from the index; the - * ignore_case flags are not used - */ -extern int git_iterator_for_index( - git_iterator **out, - git_repository *repo, - git_index *index, - git_iterator_options *options); - -extern int git_iterator_for_workdir_ext( - git_iterator **out, - git_repository *repo, - const char *repo_workdir, - git_index *index, - git_tree *tree, - git_iterator_options *options); - -/* workdir iterators will match the ignore_case value from the index of the - * repository, unless you override with a non-zero flag value - */ -GIT_INLINE(int) git_iterator_for_workdir( - git_iterator **out, - git_repository *repo, - git_index *index, - git_tree *tree, - git_iterator_options *options) -{ - return git_iterator_for_workdir_ext(out, repo, NULL, index, tree, options); -} - -/* for filesystem iterators, you have to explicitly pass in the ignore_case - * behavior that you desire - */ -extern int git_iterator_for_filesystem( - git_iterator **out, - const char *root, - git_iterator_options *options); - -extern void git_iterator_free(git_iterator *iter); - -/* Return a git_index_entry structure for the current value the iterator - * is looking at or NULL if the iterator is at the end. - * - * The entry may noy be fully populated. Tree iterators will only have a - * value mode, OID, and path. Workdir iterators will not have an OID (but - * you can use `git_iterator_current_oid()` to calculate it on demand). - * - * You do not need to free the entry. It is still "owned" by the iterator. - * Once you call `git_iterator_advance()` then the old entry is no longer - * guaranteed to be valid - it may be freed or just overwritten in place. - */ -GIT_INLINE(int) git_iterator_current( - const git_index_entry **entry, git_iterator *iter) -{ - return iter->cb->current(entry, iter); -} - -/** - * Advance to the next item for the iterator. - * - * If GIT_ITERATOR_INCLUDE_TREES is set, this may be a tree item. If - * GIT_ITERATOR_DONT_AUTOEXPAND is set, calling this again when on a tree - * item will skip over all the items under that tree. - */ -GIT_INLINE(int) git_iterator_advance( - const git_index_entry **entry, git_iterator *iter) -{ - return iter->cb->advance(entry, iter); -} - -/** - * Iterate into a tree item (when GIT_ITERATOR_DONT_AUTOEXPAND is set). - * - * git_iterator_advance() steps through all items being iterated over - * (either with or without trees, depending on GIT_ITERATOR_INCLUDE_TREES), - * but if GIT_ITERATOR_DONT_AUTOEXPAND is set, it will skip to the next - * sibling of a tree instead of going to the first child of the tree. In - * that case, use this function to advance to the first child of the tree. - * - * If the current item is not a tree, this is a no-op. - * - * For filesystem and working directory iterators, a tree (i.e. directory) - * can be empty. In that case, this function returns GIT_ENOTFOUND and - * does not advance. That can't happen for tree and index iterators. - */ -GIT_INLINE(int) git_iterator_advance_into( - const git_index_entry **entry, git_iterator *iter) -{ - return iter->cb->advance_into(entry, iter); -} - -/* Advance over a directory and check if it contains no files or just - * ignored files. - * - * In a tree or the index, all directories will contain files, but in the - * working directory it is possible to have an empty directory tree or a - * tree that only contains ignored files. Many Git operations treat these - * cases specially. This advances over a directory (presumably an - * untracked directory) but checks during the scan if there are any files - * and any non-ignored files. - */ -GIT_INLINE(int) git_iterator_advance_over( - const git_index_entry **entry, - git_iterator_status_t *status, - git_iterator *iter) -{ - return iter->cb->advance_over(entry, status, iter); -} - -/** - * Go back to the start of the iteration. - */ -GIT_INLINE(int) git_iterator_reset(git_iterator *iter) -{ - return iter->cb->reset(iter); -} - -/** - * Go back to the start of the iteration after updating the `start` and - * `end` pathname boundaries of the iteration. - */ -extern int git_iterator_reset_range( - git_iterator *iter, const char *start, const char *end); - -GIT_INLINE(git_iterator_t) git_iterator_type(git_iterator *iter) -{ - return iter->type; -} - -GIT_INLINE(git_repository *) git_iterator_owner(git_iterator *iter) -{ - return iter->repo; -} - -GIT_INLINE(git_index *) git_iterator_index(git_iterator *iter) -{ - return iter->index; -} - -GIT_INLINE(git_iterator_flag_t) git_iterator_flags(git_iterator *iter) -{ - return iter->flags; -} - -GIT_INLINE(bool) git_iterator_ignore_case(git_iterator *iter) -{ - return ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0); -} - -extern int git_iterator_set_ignore_case( - git_iterator *iter, bool ignore_case); - -extern int git_iterator_current_tree_entry( - const git_tree_entry **entry_out, git_iterator *iter); - -extern int git_iterator_current_parent_tree( - const git_tree **tree_out, git_iterator *iter, size_t depth); - -extern bool git_iterator_current_is_ignored(git_iterator *iter); - -extern bool git_iterator_current_tree_is_ignored(git_iterator *iter); - -/** - * Get full path of the current item from a workdir iterator. This will - * return NULL for a non-workdir iterator. The git_str is still owned by - * the iterator; this is exposed just for efficiency. - */ -extern int git_iterator_current_workdir_path( - git_str **path, git_iterator *iter); - -/** - * Retrieve the index stored in the iterator. - * - * Only implemented for the workdir and index iterators. - */ -extern git_index *git_iterator_index(git_iterator *iter); - -typedef int (*git_iterator_foreach_cb)( - const git_index_entry *entry, - void *data); - -/** - * Walk the given iterator and invoke the callback for each path - * contained in the iterator. - */ -extern int git_iterator_foreach( - git_iterator *iterator, - git_iterator_foreach_cb cb, - void *data); - -typedef int (*git_iterator_walk_cb)( - const git_index_entry **entries, - void *data); - -/** - * Walk the given iterators in lock-step. The given callback will be - * called for each unique path, with the index entry in each iterator - * (or NULL if the given iterator does not contain that path). - */ -extern int git_iterator_walk( - git_iterator **iterators, - size_t cnt, - git_iterator_walk_cb cb, - void *data); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/libgit2.c b/vendor/libgit2-sys/libgit2/src/libgit2/libgit2.c deleted file mode 100644 index de72cfe..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/libgit2.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include "alloc.h" -#include "buf.h" -#include "common.h" -#include "filter.h" -#include "hash.h" -#include "merge_driver.h" -#include "pool.h" -#include "mwindow.h" -#include "oid.h" -#include "rand.h" -#include "runtime.h" -#include "settings.h" -#include "sysdir.h" -#include "thread.h" -#include "git2/global.h" -#include "streams/registry.h" -#include "streams/mbedtls.h" -#include "streams/openssl.h" -#include "streams/socket.h" -#include "transports/ssh_libssh2.h" - -#ifdef GIT_WIN32 -# include "win32/w32_leakcheck.h" -#endif - -int git_libgit2_init(void) -{ - static git_runtime_init_fn init_fns[] = { -#ifdef GIT_WIN32 - git_win32_leakcheck_global_init, -#endif - git_allocator_global_init, - git_error_global_init, - git_threads_global_init, - git_oid_global_init, - git_rand_global_init, - git_hash_global_init, - git_sysdir_global_init, - git_filter_global_init, - git_merge_driver_global_init, - git_transport_ssh_libssh2_global_init, - git_stream_registry_global_init, - git_socket_stream_global_init, - git_openssl_stream_global_init, - git_mbedtls_stream_global_init, - git_mwindow_global_init, - git_pool_global_init, - git_settings_global_init - }; - - return git_runtime_init(init_fns, ARRAY_SIZE(init_fns)); -} - -int git_libgit2_shutdown(void) -{ - return git_runtime_shutdown(); -} - -int git_libgit2_version(int *major, int *minor, int *rev) -{ - *major = LIBGIT2_VERSION_MAJOR; - *minor = LIBGIT2_VERSION_MINOR; - *rev = LIBGIT2_VERSION_REVISION; - - return 0; -} - -const char *git_libgit2_prerelease(void) -{ - return LIBGIT2_VERSION_PRERELEASE; -} - -int git_libgit2_features(void) -{ - return 0 -#ifdef GIT_THREADS - | GIT_FEATURE_THREADS -#endif -#ifdef GIT_HTTPS - | GIT_FEATURE_HTTPS -#endif -#ifdef GIT_SSH - | GIT_FEATURE_SSH -#endif -#ifdef GIT_USE_NSEC - | GIT_FEATURE_NSEC -#endif - | GIT_FEATURE_HTTP_PARSER - | GIT_FEATURE_REGEX -#ifdef GIT_USE_ICONV - | GIT_FEATURE_I18N -#endif -#if defined(GIT_NTLM) || defined(GIT_WIN32) - | GIT_FEATURE_AUTH_NTLM -#endif -#if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK) || defined(GIT_WIN32) - | GIT_FEATURE_AUTH_NEGOTIATE -#endif - | GIT_FEATURE_COMPRESSION - | GIT_FEATURE_SHA1 -#ifdef GIT_EXPERIMENTAL_SHA256 - | GIT_FEATURE_SHA256 -#endif - ; -} - -const char *git_libgit2_feature_backend(git_feature_t feature) -{ - switch (feature) { - case GIT_FEATURE_THREADS: -#if defined(GIT_THREADS) && defined(GIT_WIN32) - return "win32"; -#elif defined(GIT_THREADS) - return "pthread"; -#endif - break; - - case GIT_FEATURE_HTTPS: -#if defined(GIT_HTTPS) && defined(GIT_OPENSSL) - return "openssl"; -#elif defined(GIT_HTTPS) && defined(GIT_OPENSSL_DYNAMIC) - return "openssl-dynamic"; -#elif defined(GIT_HTTPS) && defined(GIT_MBEDTLS) - return "mbedtls"; -#elif defined(GIT_HTTPS) && defined(GIT_SECURE_TRANSPORT) - return "securetransport"; -#elif defined(GIT_HTTPS) && defined(GIT_SCHANNEL) - return "schannel"; -#elif defined(GIT_HTTPS) && defined(GIT_WINHTTP) - return "winhttp"; -#elif defined(GIT_HTTPS) - GIT_ASSERT_WITH_RETVAL(!"Unknown HTTPS backend", NULL); -#endif - break; - - case GIT_FEATURE_SSH: -#if defined(GIT_SSH_EXEC) - return "exec"; -#elif defined(GIT_SSH_LIBSSH2) - return "libssh2"; -#elif defined(GIT_SSH) - GIT_ASSERT_WITH_RETVAL(!"Unknown SSH backend", NULL); -#endif - break; - - case GIT_FEATURE_NSEC: -#if defined(GIT_USE_NSEC) && defined(GIT_USE_STAT_MTIMESPEC) - return "mtimespec"; -#elif defined(GIT_USE_NSEC) && defined(GIT_USE_STAT_MTIM) - return "mtim"; -#elif defined(GIT_USE_NSEC) && defined(GIT_USE_STAT_MTIME_NSEC) - return "mtime"; -#elif defined(GIT_USE_NSEC) && defined(GIT_WIN32) - return "win32"; -#elif defined(GIT_USE_NSEC) - GIT_ASSERT_WITH_RETVAL(!"Unknown high-resolution time backend", NULL); -#endif - break; - - case GIT_FEATURE_HTTP_PARSER: -#if defined(GIT_HTTPPARSER_HTTPPARSER) - return "httpparser"; -#elif defined(GIT_HTTPPARSER_LLHTTP) - return "llhttp"; -#elif defined(GIT_HTTPPARSER_BUILTIN) - return "builtin"; -#endif - GIT_ASSERT_WITH_RETVAL(!"Unknown HTTP parser backend", NULL); - break; - - case GIT_FEATURE_REGEX: -#if defined(GIT_REGEX_REGCOMP_L) - return "regcomp_l"; -#elif defined(GIT_REGEX_REGCOMP) - return "regcomp"; -#elif defined(GIT_REGEX_PCRE) - return "pcre"; -#elif defined(GIT_REGEX_PCRE2) - return "pcre2"; -#elif defined(GIT_REGEX_BUILTIN) - return "builtin"; -#endif - GIT_ASSERT_WITH_RETVAL(!"Unknown regular expression backend", NULL); - break; - - case GIT_FEATURE_I18N: -#if defined(GIT_USE_ICONV) - return "iconv"; -#endif - break; - - case GIT_FEATURE_AUTH_NTLM: -#if defined(GIT_NTLM) - return "ntlmclient"; -#elif defined(GIT_WIN32) - return "sspi"; -#endif - break; - - case GIT_FEATURE_AUTH_NEGOTIATE: -#if defined(GIT_GSSAPI) - return "gssapi"; -#elif defined(GIT_WIN32) - return "sspi"; -#endif - break; - - case GIT_FEATURE_COMPRESSION: -#if defined(GIT_COMPRESSION_ZLIB) - return "zlib"; -#elif defined(GIT_COMPRESSION_BUILTIN) - return "builtin"; -#else - GIT_ASSERT_WITH_RETVAL(!"Unknown compression backend", NULL); -#endif - break; - - case GIT_FEATURE_SHA1: -#if defined(GIT_SHA1_COLLISIONDETECT) - return "builtin"; -#elif defined(GIT_SHA1_OPENSSL) - return "openssl"; -#elif defined(GIT_SHA1_OPENSSL_FIPS) - return "openssl-fips"; -#elif defined(GIT_SHA1_OPENSSL_DYNAMIC) - return "openssl-dynamic"; -#elif defined(GIT_SHA1_MBEDTLS) - return "mbedtls"; -#elif defined(GIT_SHA1_COMMON_CRYPTO) - return "commoncrypto"; -#elif defined(GIT_SHA1_WIN32) - return "win32"; -#else - GIT_ASSERT_WITH_RETVAL(!"Unknown SHA1 backend", NULL); -#endif - break; - - case GIT_FEATURE_SHA256: -#if defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_BUILTIN) - return "builtin"; -#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_OPENSSL) - return "openssl"; -#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_OPENSSL_FIPS) - return "openssl-fips"; -#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_OPENSSL_DYNAMIC) - return "openssl-dynamic"; -#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_MBEDTLS) - return "mbedtls"; -#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_COMMON_CRYPTO) - return "commoncrypto"; -#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_WIN32) - return "win32"; -#elif defined(GIT_EXPERIMENTAL_SHA256) - GIT_ASSERT_WITH_RETVAL(!"Unknown SHA256 backend", NULL); -#endif - break; - } - - return NULL; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/mailmap.c b/vendor/libgit2-sys/libgit2/src/libgit2/mailmap.c deleted file mode 100644 index 05c88ff..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/mailmap.c +++ /dev/null @@ -1,500 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "mailmap.h" - -#include "common.h" -#include "config.h" -#include "fs_path.h" -#include "repository.h" -#include "signature.h" -#include "git2/config.h" -#include "git2/revparse.h" -#include "blob.h" -#include "parse.h" -#include "path.h" - -#define MM_FILE ".mailmap" -#define MM_FILE_CONFIG "mailmap.file" -#define MM_BLOB_CONFIG "mailmap.blob" -#define MM_BLOB_DEFAULT "HEAD:" MM_FILE - -static void mailmap_entry_free(git_mailmap_entry *entry) -{ - if (!entry) - return; - - git__free(entry->real_name); - git__free(entry->real_email); - git__free(entry->replace_name); - git__free(entry->replace_email); - git__free(entry); -} - -/* - * First we sort by replace_email, then replace_name (if present). - * Entries with names are greater than entries without. - */ -static int mailmap_entry_cmp(const void *a_raw, const void *b_raw) -{ - const git_mailmap_entry *a = (const git_mailmap_entry *)a_raw; - const git_mailmap_entry *b = (const git_mailmap_entry *)b_raw; - int cmp; - - GIT_ASSERT_ARG(a && a->replace_email); - GIT_ASSERT_ARG(b && b->replace_email); - - cmp = git__strcmp(a->replace_email, b->replace_email); - if (cmp) - return cmp; - - /* NULL replace_names are less than not-NULL ones */ - if (a->replace_name == NULL || b->replace_name == NULL) - return (int)(a->replace_name != NULL) - (int)(b->replace_name != NULL); - - return git__strcmp(a->replace_name, b->replace_name); -} - -/* Replace the old entry with the new on duplicate. */ -static int mailmap_entry_replace(void **old_raw, void *new_raw) -{ - mailmap_entry_free((git_mailmap_entry *)*old_raw); - *old_raw = new_raw; - return GIT_EEXISTS; -} - -/* Check if we're at the end of line, w/ comments */ -static bool is_eol(git_parse_ctx *ctx) -{ - char c; - return git_parse_peek(&c, ctx, GIT_PARSE_PEEK_SKIP_WHITESPACE) < 0 || c == '#'; -} - -static int advance_until( - const char **start, size_t *len, git_parse_ctx *ctx, char needle) -{ - *start = ctx->line; - while (ctx->line_len > 0 && *ctx->line != '#' && *ctx->line != needle) - git_parse_advance_chars(ctx, 1); - - if (ctx->line_len == 0 || *ctx->line == '#') - return -1; /* end of line */ - - *len = ctx->line - *start; - git_parse_advance_chars(ctx, 1); /* advance past needle */ - return 0; -} - -/* - * Parse a single entry from a mailmap file. - * - * The output git_strs will be non-owning, and should be copied before being - * persisted. - */ -static int parse_mailmap_entry( - git_str *real_name, git_str *real_email, - git_str *replace_name, git_str *replace_email, - git_parse_ctx *ctx) -{ - const char *start; - size_t len; - - git_str_clear(real_name); - git_str_clear(real_email); - git_str_clear(replace_name); - git_str_clear(replace_email); - - git_parse_advance_ws(ctx); - if (is_eol(ctx)) - return -1; /* blank line */ - - /* Parse the real name */ - if (advance_until(&start, &len, ctx, '<') < 0) - return -1; - - git_str_attach_notowned(real_name, start, len); - git_str_rtrim(real_name); - - /* - * If this is the last email in the line, this is the email to replace, - * otherwise, it's the real email. - */ - if (advance_until(&start, &len, ctx, '>') < 0) - return -1; - - /* If we aren't at the end of the line, parse a second name and email */ - if (!is_eol(ctx)) { - git_str_attach_notowned(real_email, start, len); - - git_parse_advance_ws(ctx); - if (advance_until(&start, &len, ctx, '<') < 0) - return -1; - git_str_attach_notowned(replace_name, start, len); - git_str_rtrim(replace_name); - - if (advance_until(&start, &len, ctx, '>') < 0) - return -1; - } - - git_str_attach_notowned(replace_email, start, len); - - if (!is_eol(ctx)) - return -1; - - return 0; -} - -int git_mailmap_new(git_mailmap **out) -{ - int error; - git_mailmap *mm = git__calloc(1, sizeof(git_mailmap)); - GIT_ERROR_CHECK_ALLOC(mm); - - error = git_vector_init(&mm->entries, 0, mailmap_entry_cmp); - if (error < 0) { - git__free(mm); - return error; - } - *out = mm; - return 0; -} - -void git_mailmap_free(git_mailmap *mm) -{ - size_t idx; - git_mailmap_entry *entry; - if (!mm) - return; - - git_vector_foreach(&mm->entries, idx, entry) - mailmap_entry_free(entry); - - git_vector_dispose(&mm->entries); - git__free(mm); -} - -static int mailmap_add_entry_unterminated( - git_mailmap *mm, - const char *real_name, size_t real_name_size, - const char *real_email, size_t real_email_size, - const char *replace_name, size_t replace_name_size, - const char *replace_email, size_t replace_email_size) -{ - int error; - git_mailmap_entry *entry = git__calloc(1, sizeof(git_mailmap_entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - GIT_ASSERT_ARG(mm); - GIT_ASSERT_ARG(replace_email && *replace_email); - - if (real_name_size > 0) { - entry->real_name = git__substrdup(real_name, real_name_size); - GIT_ERROR_CHECK_ALLOC(entry->real_name); - } - if (real_email_size > 0) { - entry->real_email = git__substrdup(real_email, real_email_size); - GIT_ERROR_CHECK_ALLOC(entry->real_email); - } - if (replace_name_size > 0) { - entry->replace_name = git__substrdup(replace_name, replace_name_size); - GIT_ERROR_CHECK_ALLOC(entry->replace_name); - } - entry->replace_email = git__substrdup(replace_email, replace_email_size); - GIT_ERROR_CHECK_ALLOC(entry->replace_email); - - error = git_vector_insert_sorted(&mm->entries, entry, mailmap_entry_replace); - if (error == GIT_EEXISTS) - error = GIT_OK; - else if (error < 0) - mailmap_entry_free(entry); - - return error; -} - -int git_mailmap_add_entry( - git_mailmap *mm, const char *real_name, const char *real_email, - const char *replace_name, const char *replace_email) -{ - return mailmap_add_entry_unterminated( - mm, - real_name, real_name ? strlen(real_name) : 0, - real_email, real_email ? strlen(real_email) : 0, - replace_name, replace_name ? strlen(replace_name) : 0, - replace_email, strlen(replace_email)); -} - -static int mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len) -{ - int error = 0; - git_parse_ctx ctx; - - /* Scratch buffers containing the real parsed names & emails */ - git_str real_name = GIT_STR_INIT; - git_str real_email = GIT_STR_INIT; - git_str replace_name = GIT_STR_INIT; - git_str replace_email = GIT_STR_INIT; - - /* Buffers may not contain '\0's. */ - if (memchr(buf, '\0', len) != NULL) - return -1; - - git_parse_ctx_init(&ctx, buf, len); - - /* Run the parser */ - while (ctx.remain_len > 0) { - error = parse_mailmap_entry( - &real_name, &real_email, &replace_name, &replace_email, &ctx); - if (error < 0) { - error = 0; /* Skip lines which don't contain a valid entry */ - git_parse_advance_line(&ctx); - continue; /* TODO: warn */ - } - - /* NOTE: Can't use add_entry(...) as our buffers aren't terminated */ - error = mailmap_add_entry_unterminated( - mm, real_name.ptr, real_name.size, real_email.ptr, real_email.size, - replace_name.ptr, replace_name.size, replace_email.ptr, replace_email.size); - if (error < 0) - goto cleanup; - - error = 0; - } - -cleanup: - git_str_dispose(&real_name); - git_str_dispose(&real_email); - git_str_dispose(&replace_name); - git_str_dispose(&replace_email); - return error; -} - -int git_mailmap_from_buffer(git_mailmap **out, const char *data, size_t len) -{ - int error = git_mailmap_new(out); - if (error < 0) - return error; - - error = mailmap_add_buffer(*out, data, len); - if (error < 0) { - git_mailmap_free(*out); - *out = NULL; - } - return error; -} - -static int mailmap_add_blob( - git_mailmap *mm, git_repository *repo, const char *rev) -{ - git_object *object = NULL; - git_blob *blob = NULL; - git_str content = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(mm); - GIT_ASSERT_ARG(repo); - - error = git_revparse_single(&object, repo, rev); - if (error < 0) - goto cleanup; - - error = git_object_peel((git_object **)&blob, object, GIT_OBJECT_BLOB); - if (error < 0) - goto cleanup; - - error = git_blob__getbuf(&content, blob); - if (error < 0) - goto cleanup; - - error = mailmap_add_buffer(mm, content.ptr, content.size); - if (error < 0) - goto cleanup; - -cleanup: - git_str_dispose(&content); - git_blob_free(blob); - git_object_free(object); - return error; -} - -static int mailmap_add_file_ondisk( - git_mailmap *mm, const char *path, git_repository *repo) -{ - const char *base = repo ? git_repository_workdir(repo) : NULL; - git_str fullpath = GIT_STR_INIT; - git_str content = GIT_STR_INIT; - int error; - - error = git_fs_path_join_unrooted(&fullpath, path, base, NULL); - if (error < 0) - goto cleanup; - - error = git_path_validate_str_length(repo, &fullpath); - if (error < 0) - goto cleanup; - - error = git_futils_readbuffer(&content, fullpath.ptr); - if (error < 0) - goto cleanup; - - error = mailmap_add_buffer(mm, content.ptr, content.size); - if (error < 0) - goto cleanup; - -cleanup: - git_str_dispose(&fullpath); - git_str_dispose(&content); - return error; -} - -/* NOTE: Only expose with an error return, currently never errors */ -static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo) -{ - git_config *config = NULL; - git_str rev_buf = GIT_STR_INIT; - git_str path_buf = GIT_STR_INIT; - const char *rev = NULL; - const char *path = NULL; - - /* If we're in a bare repo, default blob to 'HEAD:.mailmap' */ - if (repo->is_bare) - rev = MM_BLOB_DEFAULT; - - /* Try to load 'mailmap.file' and 'mailmap.blob' cfgs from the repo */ - if (git_repository_config(&config, repo) == 0) { - if (git_config__get_string_buf(&rev_buf, config, MM_BLOB_CONFIG) == 0) - rev = rev_buf.ptr; - if (git_config__get_path(&path_buf, config, MM_FILE_CONFIG) == 0) - path = path_buf.ptr; - } - - /* - * Load mailmap files in order, overriding previous entries with new ones. - * 1. The '.mailmap' file in the repository's workdir root, - * 2. The blob described by the 'mailmap.blob' config (default HEAD:.mailmap), - * 3. The file described by the 'mailmap.file' config. - * - * We ignore errors from these loads, as these files may not exist, or may - * contain invalid information, and we don't want to report that error. - * - * XXX: Warn? - */ - if (!repo->is_bare) - mailmap_add_file_ondisk(mm, MM_FILE, repo); - if (rev != NULL) - mailmap_add_blob(mm, repo, rev); - if (path != NULL) - mailmap_add_file_ondisk(mm, path, repo); - - git_str_dispose(&rev_buf); - git_str_dispose(&path_buf); - git_config_free(config); -} - -int git_mailmap_from_repository(git_mailmap **out, git_repository *repo) -{ - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - if ((error = git_mailmap_new(out)) < 0) - return error; - - mailmap_add_from_repository(*out, repo); - return 0; -} - -const git_mailmap_entry *git_mailmap_entry_lookup( - const git_mailmap *mm, const char *name, const char *email) -{ - int error; - ssize_t fallback = -1; - size_t idx; - git_mailmap_entry *entry; - - /* The lookup needle we want to use only sets the replace_email. */ - git_mailmap_entry needle = { NULL }; - needle.replace_email = (char *)email; - - GIT_ASSERT_ARG_WITH_RETVAL(email, NULL); - - if (!mm) - return NULL; - - /* - * We want to find the place to start looking. so we do a binary search for - * the "fallback" nameless entry. If we find it, we advance past it and record - * the index. - */ - error = git_vector_bsearch(&idx, (git_vector *)&mm->entries, &needle); - if (error >= 0) - fallback = idx++; - else if (error != GIT_ENOTFOUND) - return NULL; - - /* do a linear search for an exact match */ - for (; idx < git_vector_length(&mm->entries); ++idx) { - entry = git_vector_get(&mm->entries, idx); - - if (git__strcmp(entry->replace_email, email)) - break; /* it's a different email, so we're done looking */ - - /* should be specific */ - GIT_ASSERT_WITH_RETVAL(entry->replace_name, NULL); - if (!name || !git__strcmp(entry->replace_name, name)) - return entry; - } - - if (fallback < 0) - return NULL; /* no fallback */ - return git_vector_get(&mm->entries, fallback); -} - -int git_mailmap_resolve( - const char **real_name, const char **real_email, - const git_mailmap *mailmap, - const char *name, const char *email) -{ - const git_mailmap_entry *entry = NULL; - - GIT_ASSERT(name); - GIT_ASSERT(email); - - *real_name = name; - *real_email = email; - - if ((entry = git_mailmap_entry_lookup(mailmap, name, email))) { - if (entry->real_name) - *real_name = entry->real_name; - if (entry->real_email) - *real_email = entry->real_email; - } - return 0; -} - -int git_mailmap_resolve_signature( - git_signature **out, const git_mailmap *mailmap, const git_signature *sig) -{ - const char *name = NULL; - const char *email = NULL; - int error; - - if (!sig) - return 0; - - error = git_mailmap_resolve(&name, &email, mailmap, sig->name, sig->email); - if (error < 0) - return error; - - error = git_signature_new(out, name, email, sig->when.time, sig->when.offset); - if (error < 0) - return error; - - /* Copy over the sign, as git_signature_new doesn't let you pass it. */ - (*out)->when.sign = sig->when.sign; - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/mailmap.h b/vendor/libgit2-sys/libgit2/src/libgit2/mailmap.h deleted file mode 100644 index 2c9736a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/mailmap.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_mailmap_h__ -#define INCLUDE_mailmap_h__ - -#include "git2/mailmap.h" -#include "vector.h" - -/* - * A mailmap is stored as a sorted vector of 'git_mailmap_entry's. These entries - * are sorted first by 'replace_email', and then by 'replace_name'. NULL - * replace_names are ordered first. - * - * Looking up a name and email in the mailmap is done with a binary search. - */ -struct git_mailmap { - git_vector entries; -}; - -/* Single entry parsed from a mailmap */ -typedef struct git_mailmap_entry { - char *real_name; /**< the real name (may be NULL) */ - char *real_email; /**< the real email (may be NULL) */ - char *replace_name; /**< the name to replace (may be NULL) */ - char *replace_email; /**< the email to replace */ -} git_mailmap_entry; - -const git_mailmap_entry *git_mailmap_entry_lookup( - const git_mailmap *mm, const char *name, const char *email); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/merge.c b/vendor/libgit2-sys/libgit2/src/libgit2/merge.c deleted file mode 100644 index 62e6d08..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/merge.c +++ /dev/null @@ -1,3445 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "merge.h" - -#include "posix.h" -#include "str.h" -#include "repository.h" -#include "revwalk.h" -#include "commit_list.h" -#include "fs_path.h" -#include "refs.h" -#include "object.h" -#include "iterator.h" -#include "refs.h" -#include "diff.h" -#include "diff_generate.h" -#include "diff_tform.h" -#include "checkout.h" -#include "tree.h" -#include "blob.h" -#include "oid.h" -#include "index.h" -#include "filebuf.h" -#include "config.h" -#include "oidarray.h" -#include "annotated_commit.h" -#include "commit.h" -#include "oidarray.h" -#include "merge_driver.h" -#include "array.h" - -#include "git2/types.h" -#include "git2/repository.h" -#include "git2/object.h" -#include "git2/commit.h" -#include "git2/merge.h" -#include "git2/refs.h" -#include "git2/reset.h" -#include "git2/checkout.h" -#include "git2/signature.h" -#include "git2/config.h" -#include "git2/tree.h" -#include "git2/oidarray.h" -#include "git2/annotated_commit.h" -#include "git2/sys/index.h" -#include "git2/sys/hashsig.h" - -#define GIT_MERGE_INDEX_ENTRY_EXISTS(X) ((X).mode != 0) -#define GIT_MERGE_INDEX_ENTRY_ISFILE(X) S_ISREG((X).mode) - - -typedef enum { - TREE_IDX_ANCESTOR = 0, - TREE_IDX_OURS = 1, - TREE_IDX_THEIRS = 2 -} merge_tree_index_t; - -/* Tracks D/F conflicts */ -struct merge_diff_df_data { - const char *df_path; - const char *prev_path; - git_merge_diff *prev_conflict; -}; - -/* - * This acts as a negative cache entry marker. In case we've tried to calculate - * similarity metrics for a given blob already but `git_hashsig` determined - * that it's too small in order to have a meaningful hash signature, we will - * insert the address of this marker instead of `NULL`. Like this, we can - * easily check whether we have checked a gien entry already and skip doing the - * calculation again and again. - */ -static int cache_invalid_marker; - -/* Merge base computation */ - -static int merge_bases_many(git_commit_list **out, git_revwalk **walk_out, git_repository *repo, size_t length, const git_oid input_array[]) -{ - git_revwalk *walk = NULL; - git_vector list; - git_commit_list *result = NULL; - git_commit_list_node *commit; - int error = -1; - unsigned int i; - - if (length < 2) { - git_error_set(GIT_ERROR_INVALID, "at least two commits are required to find an ancestor"); - return -1; - } - - if (git_vector_init(&list, length - 1, NULL) < 0) - return -1; - - if (git_revwalk_new(&walk, repo) < 0) - goto on_error; - - for (i = 1; i < length; i++) { - commit = git_revwalk__commit_lookup(walk, &input_array[i]); - if (commit == NULL) - goto on_error; - - git_vector_insert(&list, commit); - } - - commit = git_revwalk__commit_lookup(walk, &input_array[0]); - if (commit == NULL) - goto on_error; - - if (git_merge__bases_many(&result, walk, commit, &list, 0) < 0) - goto on_error; - - if (!result) { - git_error_set(GIT_ERROR_MERGE, "no merge base found"); - error = GIT_ENOTFOUND; - goto on_error; - } - - *out = result; - *walk_out = walk; - - git_vector_dispose(&list); - return 0; - -on_error: - git_vector_dispose(&list); - git_revwalk_free(walk); - return error; -} - -int git_merge_base_many(git_oid *out, git_repository *repo, size_t length, const git_oid input_array[]) -{ - git_revwalk *walk; - git_commit_list *result = NULL; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(input_array); - - if ((error = merge_bases_many(&result, &walk, repo, length, input_array)) < 0) - return error; - - git_oid_cpy(out, &result->item->oid); - - git_commit_list_free(&result); - git_revwalk_free(walk); - - return 0; -} - -int git_merge_bases_many(git_oidarray *out, git_repository *repo, size_t length, const git_oid input_array[]) -{ - git_revwalk *walk; - git_commit_list *list, *result = NULL; - int error = 0; - git_array_oid_t array; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(input_array); - - if ((error = merge_bases_many(&result, &walk, repo, length, input_array)) < 0) - return error; - - git_array_init(array); - - list = result; - while (list) { - git_oid *id = git_array_alloc(array); - if (id == NULL) { - error = -1; - goto cleanup; - } - - git_oid_cpy(id, &list->item->oid); - list = list->next; - } - - git_oidarray__from_array(out, &array); - -cleanup: - git_commit_list_free(&result); - git_revwalk_free(walk); - - return error; -} - -int git_merge_base_octopus(git_oid *out, git_repository *repo, size_t length, const git_oid input_array[]) -{ - git_oid result; - unsigned int i; - int error = -1; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(input_array); - - if (length < 2) { - git_error_set(GIT_ERROR_INVALID, "at least two commits are required to find an ancestor"); - return -1; - } - - result = input_array[0]; - for (i = 1; i < length; i++) { - error = git_merge_base(&result, repo, &result, &input_array[i]); - if (error < 0) - return error; - } - - *out = result; - - return 0; -} - -static int merge_bases(git_commit_list **out, git_revwalk **walk_out, git_repository *repo, const git_oid *one, const git_oid *two) -{ - git_revwalk *walk; - git_vector list; - git_commit_list *result = NULL; - git_commit_list_node *commit; - void *contents[1]; - - if (git_revwalk_new(&walk, repo) < 0) - return -1; - - commit = git_revwalk__commit_lookup(walk, two); - if (commit == NULL) - goto on_error; - - /* This is just one value, so we can do it on the stack */ - memset(&list, 0x0, sizeof(git_vector)); - contents[0] = commit; - list.length = 1; - list.contents = contents; - - commit = git_revwalk__commit_lookup(walk, one); - if (commit == NULL) - goto on_error; - - if (git_merge__bases_many(&result, walk, commit, &list, 0) < 0) - goto on_error; - - if (!result) { - git_revwalk_free(walk); - git_error_set(GIT_ERROR_MERGE, "no merge base found"); - return GIT_ENOTFOUND; - } - - *out = result; - *walk_out = walk; - - return 0; - -on_error: - git_revwalk_free(walk); - return -1; - -} - -int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const git_oid *two) -{ - int error; - git_revwalk *walk; - git_commit_list *result; - - if ((error = merge_bases(&result, &walk, repo, one, two)) < 0) - return error; - - git_oid_cpy(out, &result->item->oid); - git_commit_list_free(&result); - git_revwalk_free(walk); - - return 0; -} - -int git_merge_bases(git_oidarray *out, git_repository *repo, const git_oid *one, const git_oid *two) -{ - int error; - git_revwalk *walk; - git_commit_list *result, *list; - git_array_oid_t array; - - git_array_init(array); - - if ((error = merge_bases(&result, &walk, repo, one, two)) < 0) - return error; - - list = result; - while (list) { - git_oid *id = git_array_alloc(array); - if (id == NULL) - goto on_error; - - git_oid_cpy(id, &list->item->oid); - list = list->next; - } - - git_oidarray__from_array(out, &array); - git_commit_list_free(&result); - git_revwalk_free(walk); - - return 0; - -on_error: - git_commit_list_free(&result); - git_revwalk_free(walk); - return -1; -} - -static int interesting(git_pqueue *list) -{ - size_t i; - - for (i = 0; i < git_pqueue_size(list); i++) { - git_commit_list_node *commit = git_pqueue_get(list, i); - if ((commit->flags & STALE) == 0) - return 1; - } - - return 0; -} - -static int clear_commit_marks_1(git_commit_list **plist, - git_commit_list_node *commit, unsigned int mark) -{ - while (commit) { - unsigned int i; - - if (!(mark & commit->flags)) - return 0; - - commit->flags &= ~mark; - - for (i = 1; i < commit->out_degree; i++) { - git_commit_list_node *p = commit->parents[i]; - if (git_commit_list_insert(p, plist) == NULL) - return -1; - } - - commit = commit->out_degree ? commit->parents[0] : NULL; - } - - return 0; -} - -static int clear_commit_marks_many(git_vector *commits, unsigned int mark) -{ - git_commit_list *list = NULL; - git_commit_list_node *c; - unsigned int i; - - git_vector_foreach(commits, i, c) { - if (git_commit_list_insert(c, &list) == NULL) - return -1; - } - - while (list) - if (clear_commit_marks_1(&list, git_commit_list_pop(&list), mark) < 0) - return -1; - return 0; -} - -static int clear_commit_marks(git_commit_list_node *commit, unsigned int mark) -{ - git_commit_list *list = NULL; - if (git_commit_list_insert(commit, &list) == NULL) - return -1; - while (list) - if (clear_commit_marks_1(&list, git_commit_list_pop(&list), mark) < 0) - return -1; - return 0; -} - -static int paint_down_to_common( - git_commit_list **out, - git_revwalk *walk, - git_commit_list_node *one, - git_vector *twos, - uint32_t minimum_generation) -{ - git_pqueue list; - git_commit_list *result = NULL; - git_commit_list_node *two; - - int error; - unsigned int i; - - if (git_pqueue_init(&list, 0, twos->length * 2, git_commit_list_generation_cmp) < 0) - return -1; - - one->flags |= PARENT1; - if (git_pqueue_insert(&list, one) < 0) - return -1; - - git_vector_foreach(twos, i, two) { - if (git_commit_list_parse(walk, two) < 0) - return -1; - - two->flags |= PARENT2; - if (git_pqueue_insert(&list, two) < 0) - return -1; - } - - /* as long as there are non-STALE commits */ - while (interesting(&list)) { - git_commit_list_node *commit = git_pqueue_pop(&list); - int flags; - - if (commit == NULL) - break; - - flags = commit->flags & (PARENT1 | PARENT2 | STALE); - if (flags == (PARENT1 | PARENT2)) { - if (!(commit->flags & RESULT)) { - commit->flags |= RESULT; - if (git_commit_list_insert(commit, &result) == NULL) - return -1; - } - /* we mark the parents of a merge stale */ - flags |= STALE; - } - - for (i = 0; i < commit->out_degree; i++) { - git_commit_list_node *p = commit->parents[i]; - if ((p->flags & flags) == flags) - continue; - if (p->generation < minimum_generation) - continue; - - if ((error = git_commit_list_parse(walk, p)) < 0) - return error; - - p->flags |= flags; - if (git_pqueue_insert(&list, p) < 0) - return -1; - } - } - - git_pqueue_free(&list); - *out = result; - return 0; -} - -static int remove_redundant(git_revwalk *walk, git_vector *commits, uint32_t minimum_generation) -{ - git_vector work = GIT_VECTOR_INIT; - unsigned char *redundant; - unsigned int *filled_index; - unsigned int i, j; - int error = 0; - - redundant = git__calloc(commits->length, 1); - GIT_ERROR_CHECK_ALLOC(redundant); - filled_index = git__calloc((commits->length - 1), sizeof(unsigned int)); - GIT_ERROR_CHECK_ALLOC(filled_index); - - for (i = 0; i < commits->length; ++i) { - if ((error = git_commit_list_parse(walk, commits->contents[i])) < 0) - goto done; - } - - for (i = 0; i < commits->length; ++i) { - git_commit_list *common = NULL; - git_commit_list_node *commit = commits->contents[i]; - - if (redundant[i]) - continue; - - git_vector_clear(&work); - - for (j = 0; j < commits->length; j++) { - if (i == j || redundant[j]) - continue; - - filled_index[work.length] = j; - if ((error = git_vector_insert(&work, commits->contents[j])) < 0) - goto done; - } - - error = paint_down_to_common(&common, walk, commit, &work, minimum_generation); - if (error < 0) - goto done; - - if (commit->flags & PARENT2) - redundant[i] = 1; - - for (j = 0; j < work.length; j++) { - git_commit_list_node *w = work.contents[j]; - if (w->flags & PARENT1) - redundant[filled_index[j]] = 1; - } - - git_commit_list_free(&common); - - if ((error = clear_commit_marks(commit, ALL_FLAGS)) < 0 || - (error = clear_commit_marks_many(&work, ALL_FLAGS)) < 0) - goto done; - } - - for (i = 0; i < commits->length; ++i) { - if (redundant[i]) - commits->contents[i] = NULL; - } - -done: - git__free(redundant); - git__free(filled_index); - git_vector_dispose(&work); - return error; -} - -int git_merge__bases_many( - git_commit_list **out, - git_revwalk *walk, - git_commit_list_node *one, - git_vector *twos, - uint32_t minimum_generation) -{ - int error; - unsigned int i; - git_commit_list_node *two; - git_commit_list *result = NULL, *tmp = NULL; - - /* If there's only the one commit, there can be no merge bases */ - if (twos->length == 0) { - *out = NULL; - return 0; - } - - /* if the commit is repeated, we have a our merge base already */ - git_vector_foreach(twos, i, two) { - if (one == two) - return git_commit_list_insert(one, out) ? 0 : -1; - } - - if (git_commit_list_parse(walk, one) < 0) - return -1; - - error = paint_down_to_common(&result, walk, one, twos, minimum_generation); - if (error < 0) - return error; - - /* filter out any stale commits in the results */ - tmp = result; - result = NULL; - - while (tmp) { - git_commit_list_node *c = git_commit_list_pop(&tmp); - if (!(c->flags & STALE)) - if (git_commit_list_insert_by_date(c, &result) == NULL) - return -1; - } - - /* - * more than one merge base -- see if there are redundant merge - * bases and remove them - */ - if (result && result->next) { - git_vector redundant = GIT_VECTOR_INIT; - - while (result) - git_vector_insert(&redundant, git_commit_list_pop(&result)); - - if ((error = clear_commit_marks(one, ALL_FLAGS)) < 0 || - (error = clear_commit_marks_many(twos, ALL_FLAGS)) < 0 || - (error = remove_redundant(walk, &redundant, minimum_generation)) < 0) { - git_vector_dispose(&redundant); - return error; - } - - git_vector_foreach(&redundant, i, two) { - if (two != NULL) - git_commit_list_insert_by_date(two, &result); - } - - git_vector_dispose(&redundant); - } - - *out = result; - return 0; -} - -int git_repository_mergehead_foreach( - git_repository *repo, - git_repository_mergehead_foreach_cb cb, - void *payload) -{ - git_str merge_head_path = GIT_STR_INIT, merge_head_file = GIT_STR_INIT; - char *buffer, *line; - size_t line_num = 1; - git_oid oid; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(cb); - - if ((error = git_str_joinpath(&merge_head_path, repo->gitdir, - GIT_MERGE_HEAD_FILE)) < 0) - return error; - - if ((error = git_futils_readbuffer(&merge_head_file, - git_str_cstr(&merge_head_path))) < 0) - goto cleanup; - - buffer = merge_head_file.ptr; - - while ((line = git__strsep(&buffer, "\n")) != NULL) { - if (strlen(line) != git_oid_hexsize(repo->oid_type)) { - git_error_set(GIT_ERROR_INVALID, "unable to parse OID - invalid length"); - error = -1; - goto cleanup; - } - - if ((error = git_oid__fromstr(&oid, line, repo->oid_type)) < 0) - goto cleanup; - - if ((error = cb(&oid, payload)) != 0) { - git_error_set_after_callback(error); - goto cleanup; - } - - ++line_num; - } - - if (*buffer) { - git_error_set(GIT_ERROR_MERGE, "no EOL at line %"PRIuZ, line_num); - error = -1; - goto cleanup; - } - -cleanup: - git_str_dispose(&merge_head_path); - git_str_dispose(&merge_head_file); - - return error; -} - -GIT_INLINE(int) index_entry_cmp(const git_index_entry *a, const git_index_entry *b) -{ - int value = 0; - - if (a->path == NULL) - return (b->path == NULL) ? 0 : 1; - - if ((value = a->mode - b->mode) == 0 && - (value = git_oid__cmp(&a->id, &b->id)) == 0) - value = strcmp(a->path, b->path); - - return value; -} - -/* Conflict resolution */ - -static int merge_conflict_resolve_trivial( - int *resolved, - git_merge_diff_list *diff_list, - const git_merge_diff *conflict) -{ - int ours_empty, theirs_empty; - int ours_changed, theirs_changed, ours_theirs_differ; - git_index_entry const *result = NULL; - int error = 0; - - GIT_ASSERT_ARG(resolved); - GIT_ASSERT_ARG(diff_list); - GIT_ASSERT_ARG(conflict); - - *resolved = 0; - - if (conflict->type == GIT_MERGE_DIFF_DIRECTORY_FILE || - conflict->type == GIT_MERGE_DIFF_RENAMED_ADDED) - return 0; - - if (conflict->our_status == GIT_DELTA_RENAMED || - conflict->their_status == GIT_DELTA_RENAMED) - return 0; - - ours_empty = !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry); - theirs_empty = !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry); - - ours_changed = (conflict->our_status != GIT_DELTA_UNMODIFIED); - theirs_changed = (conflict->their_status != GIT_DELTA_UNMODIFIED); - ours_theirs_differ = ours_changed && theirs_changed && - index_entry_cmp(&conflict->our_entry, &conflict->their_entry); - - /* - * Note: with only one ancestor, some cases are not distinct: - * - * 16: ancest:anc1/anc2, head:anc1, remote:anc2 = result:no merge - * 3: ancest:(empty)^, head:head, remote:(empty) = result:no merge - * 2: ancest:(empty)^, head:(empty), remote:remote = result:no merge - * - * Note that the two cases that take D/F conflicts into account - * specifically do not need to be explicitly tested, as D/F conflicts - * would fail the *empty* test: - * - * 3ALT: ancest:(empty)+, head:head, remote:*empty* = result:head - * 2ALT: ancest:(empty)+, head:*empty*, remote:remote = result:remote - * - * Note that many of these cases need not be explicitly tested, as - * they simply degrade to "all different" cases (eg, 11): - * - * 4: ancest:(empty)^, head:head, remote:remote = result:no merge - * 7: ancest:ancest+, head:(empty), remote:remote = result:no merge - * 9: ancest:ancest+, head:head, remote:(empty) = result:no merge - * 11: ancest:ancest+, head:head, remote:remote = result:no merge - */ - - /* 5ALT: ancest:*, head:head, remote:head = result:head */ - if (ours_changed && !ours_empty && !ours_theirs_differ) - result = &conflict->our_entry; - /* 6: ancest:ancest+, head:(empty), remote:(empty) = result:no merge */ - else if (ours_changed && ours_empty && theirs_empty) - *resolved = 0; - /* 8: ancest:ancest^, head:(empty), remote:ancest = result:no merge */ - else if (ours_empty && !theirs_changed) - *resolved = 0; - /* 10: ancest:ancest^, head:ancest, remote:(empty) = result:no merge */ - else if (!ours_changed && theirs_empty) - *resolved = 0; - /* 13: ancest:ancest+, head:head, remote:ancest = result:head */ - else if (ours_changed && !theirs_changed) - result = &conflict->our_entry; - /* 14: ancest:ancest+, head:ancest, remote:remote = result:remote */ - else if (!ours_changed && theirs_changed) - result = &conflict->their_entry; - else - *resolved = 0; - - if (result != NULL && - GIT_MERGE_INDEX_ENTRY_EXISTS(*result) && - (error = git_vector_insert(&diff_list->staged, (void *)result)) >= 0) - *resolved = 1; - - /* Note: trivial resolution does not update the REUC. */ - - return error; -} - -static int merge_conflict_resolve_one_removed( - int *resolved, - git_merge_diff_list *diff_list, - const git_merge_diff *conflict) -{ - int ours_empty, theirs_empty; - int ours_changed, theirs_changed; - int error = 0; - - GIT_ASSERT_ARG(resolved); - GIT_ASSERT_ARG(diff_list); - GIT_ASSERT_ARG(conflict); - - *resolved = 0; - - if (conflict->type == GIT_MERGE_DIFF_DIRECTORY_FILE || - conflict->type == GIT_MERGE_DIFF_RENAMED_ADDED) - return 0; - - ours_empty = !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry); - theirs_empty = !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry); - - ours_changed = (conflict->our_status != GIT_DELTA_UNMODIFIED); - theirs_changed = (conflict->their_status != GIT_DELTA_UNMODIFIED); - - /* Removed in both */ - if (ours_changed && ours_empty && theirs_empty) - *resolved = 1; - /* Removed in ours */ - else if (ours_empty && !theirs_changed) - *resolved = 1; - /* Removed in theirs */ - else if (!ours_changed && theirs_empty) - *resolved = 1; - - if (*resolved) - git_vector_insert(&diff_list->resolved, (git_merge_diff *)conflict); - - return error; -} - -static int merge_conflict_resolve_one_renamed( - int *resolved, - git_merge_diff_list *diff_list, - const git_merge_diff *conflict) -{ - int ours_renamed, theirs_renamed; - int ours_changed, theirs_changed; - git_index_entry *merged; - int error = 0; - - GIT_ASSERT_ARG(resolved); - GIT_ASSERT_ARG(diff_list); - GIT_ASSERT_ARG(conflict); - - *resolved = 0; - - if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) || - !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry)) - return 0; - - ours_renamed = (conflict->our_status == GIT_DELTA_RENAMED); - theirs_renamed = (conflict->their_status == GIT_DELTA_RENAMED); - - if (!ours_renamed && !theirs_renamed) - return 0; - - /* Reject one file in a 2->1 conflict */ - if (conflict->type == GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1 || - conflict->type == GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2 || - conflict->type == GIT_MERGE_DIFF_RENAMED_ADDED) - return 0; - - ours_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->our_entry.id) != 0) || - (conflict->ancestor_entry.mode != conflict->our_entry.mode); - - theirs_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->their_entry.id) != 0) || - (conflict->ancestor_entry.mode != conflict->their_entry.mode); - - /* if both are modified (and not to a common target) require a merge */ - if (ours_changed && theirs_changed && - git_oid__cmp(&conflict->our_entry.id, &conflict->their_entry.id) != 0) - return 0; - - if ((merged = git_pool_malloc(&diff_list->pool, sizeof(git_index_entry))) == NULL) - return -1; - - if (ours_changed) - memcpy(merged, &conflict->our_entry, sizeof(git_index_entry)); - else - memcpy(merged, &conflict->their_entry, sizeof(git_index_entry)); - - if (ours_renamed) - merged->path = conflict->our_entry.path; - else - merged->path = conflict->their_entry.path; - - *resolved = 1; - - git_vector_insert(&diff_list->staged, merged); - git_vector_insert(&diff_list->resolved, (git_merge_diff *)conflict); - - return error; -} - -static bool merge_conflict_can_resolve_contents( - const git_merge_diff *conflict) -{ - if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) || - !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry)) - return false; - - /* Reject D/F conflicts */ - if (conflict->type == GIT_MERGE_DIFF_DIRECTORY_FILE) - return false; - - /* Reject submodules. */ - if (S_ISGITLINK(conflict->ancestor_entry.mode) || - S_ISGITLINK(conflict->our_entry.mode) || - S_ISGITLINK(conflict->their_entry.mode)) - return false; - - /* Reject link/file conflicts. */ - if ((S_ISLNK(conflict->ancestor_entry.mode) ^ - S_ISLNK(conflict->our_entry.mode)) || - (S_ISLNK(conflict->ancestor_entry.mode) ^ - S_ISLNK(conflict->their_entry.mode))) - return false; - - /* Reject name conflicts */ - if (conflict->type == GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1 || - conflict->type == GIT_MERGE_DIFF_RENAMED_ADDED) - return false; - - if ((conflict->our_status & GIT_DELTA_RENAMED) == GIT_DELTA_RENAMED && - (conflict->their_status & GIT_DELTA_RENAMED) == GIT_DELTA_RENAMED && - strcmp(conflict->ancestor_entry.path, conflict->their_entry.path) != 0) - return false; - - return true; -} - -static int merge_conflict_invoke_driver( - git_index_entry **out, - const char *name, - git_merge_driver *driver, - git_merge_diff_list *diff_list, - git_merge_driver_source *src) -{ - git_index_entry *result; - git_buf buf = {0}; - const char *path; - uint32_t mode; - git_odb *odb = NULL; - git_oid oid; - int error; - - *out = NULL; - - if ((error = driver->apply(driver, &path, &mode, &buf, name, src)) < 0 || - (error = git_repository_odb(&odb, src->repo)) < 0 || - (error = git_odb_write(&oid, odb, buf.ptr, buf.size, GIT_OBJECT_BLOB)) < 0) - goto done; - - result = git_pool_mallocz(&diff_list->pool, sizeof(git_index_entry)); - GIT_ERROR_CHECK_ALLOC(result); - - git_oid_cpy(&result->id, &oid); - result->mode = mode; - result->file_size = (uint32_t)buf.size; - - result->path = git_pool_strdup(&diff_list->pool, path); - GIT_ERROR_CHECK_ALLOC(result->path); - - *out = result; - -done: - git_buf_dispose(&buf); - git_odb_free(odb); - - return error; -} - -static int merge_conflict_resolve_contents( - int *resolved, - git_merge_diff_list *diff_list, - const git_merge_diff *conflict, - const git_merge_options *merge_opts, - const git_merge_file_options *file_opts) -{ - git_merge_driver_source source = {0}; - git_merge_file_result result = {0}; - git_merge_driver *driver; - git_merge_driver__builtin builtin = {{0}}; - git_index_entry *merge_result = NULL; - git_odb *odb = NULL; - const char *name; - bool fallback = false; - int error; - - GIT_ASSERT_ARG(resolved); - GIT_ASSERT_ARG(diff_list); - GIT_ASSERT_ARG(conflict); - - *resolved = 0; - - if (!merge_conflict_can_resolve_contents(conflict)) - return 0; - - source.repo = diff_list->repo; - source.default_driver = merge_opts->default_driver; - source.file_opts = file_opts; - source.ancestor = GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) ? - &conflict->ancestor_entry : NULL; - source.ours = GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) ? - &conflict->our_entry : NULL; - source.theirs = GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry) ? - &conflict->their_entry : NULL; - - if (file_opts->favor != GIT_MERGE_FILE_FAVOR_NORMAL) { - /* if the user requested a particular type of resolution (via the - * favor flag) then let that override the gitattributes and use - * the builtin driver. - */ - name = "text"; - builtin.base.apply = git_merge_driver__builtin_apply; - builtin.favor = file_opts->favor; - - driver = &builtin.base; - } else { - /* find the merge driver for this file */ - if ((error = git_merge_driver_for_source(&name, &driver, &source)) < 0) - goto done; - - if (driver == NULL) - fallback = true; - } - - if (driver) { - error = merge_conflict_invoke_driver(&merge_result, name, driver, - diff_list, &source); - - if (error == GIT_PASSTHROUGH) - fallback = true; - } - - if (fallback) { - error = merge_conflict_invoke_driver(&merge_result, "text", - &git_merge_driver__text.base, diff_list, &source); - } - - if (error < 0) { - if (error == GIT_EMERGECONFLICT) - error = 0; - - goto done; - } - - git_vector_insert(&diff_list->staged, merge_result); - git_vector_insert(&diff_list->resolved, (git_merge_diff *)conflict); - - *resolved = 1; - -done: - git_merge_file_result_free(&result); - git_odb_free(odb); - - return error; -} - -static int merge_conflict_resolve( - int *out, - git_merge_diff_list *diff_list, - const git_merge_diff *conflict, - const git_merge_options *merge_opts, - const git_merge_file_options *file_opts) -{ - int resolved = 0; - int error = 0; - - *out = 0; - - if ((error = merge_conflict_resolve_trivial( - &resolved, diff_list, conflict)) < 0) - goto done; - - if (!resolved && (error = merge_conflict_resolve_one_removed( - &resolved, diff_list, conflict)) < 0) - goto done; - - if (!resolved && (error = merge_conflict_resolve_one_renamed( - &resolved, diff_list, conflict)) < 0) - goto done; - - if (!resolved && (error = merge_conflict_resolve_contents( - &resolved, diff_list, conflict, merge_opts, file_opts)) < 0) - goto done; - - *out = resolved; - -done: - return error; -} - -/* Rename detection and coalescing */ - -struct merge_diff_similarity { - unsigned char similarity; - size_t other_idx; -}; - -static int index_entry_similarity_calc( - void **out, - git_repository *repo, - git_index_entry *entry, - const git_merge_options *opts) -{ - git_blob *blob; - git_diff_file diff_file; - git_object_size_t blobsize; - int error; - - if (*out || *out == &cache_invalid_marker) - return 0; - - *out = NULL; - - git_oid_clear(&diff_file.id, repo->oid_type); - - if ((error = git_blob_lookup(&blob, repo, &entry->id)) < 0) - return error; - - git_oid_cpy(&diff_file.id, &entry->id); - diff_file.path = entry->path; - diff_file.size = entry->file_size; - diff_file.mode = entry->mode; - diff_file.flags = 0; - - blobsize = git_blob_rawsize(blob); - - /* file too big for rename processing */ - if (!git__is_sizet(blobsize)) - return 0; - - error = opts->metric->buffer_signature(out, &diff_file, - git_blob_rawcontent(blob), (size_t)blobsize, - opts->metric->payload); - if (error == GIT_EBUFS) - *out = &cache_invalid_marker; - - git_blob_free(blob); - - return error; -} - -static int index_entry_similarity_inexact( - git_repository *repo, - git_index_entry *a, - size_t a_idx, - git_index_entry *b, - size_t b_idx, - void **cache, - const git_merge_options *opts) -{ - int score = 0; - int error = 0; - - if (!GIT_MODE_ISBLOB(a->mode) || !GIT_MODE_ISBLOB(b->mode)) - return 0; - - /* update signature cache if needed */ - if ((error = index_entry_similarity_calc(&cache[a_idx], repo, a, opts)) < 0 || - (error = index_entry_similarity_calc(&cache[b_idx], repo, b, opts)) < 0) - return error; - - /* some metrics may not wish to process this file (too big / too small) */ - if (cache[a_idx] == &cache_invalid_marker || cache[b_idx] == &cache_invalid_marker) - return 0; - - /* compare signatures */ - if (opts->metric->similarity(&score, cache[a_idx], cache[b_idx], opts->metric->payload) < 0) - return -1; - - /* clip score */ - if (score < 0) - score = 0; - else if (score > 100) - score = 100; - - return score; -} - -/* Tracks deletes by oid for merge_diff_mark_similarity_exact(). This is a -* non-shrinking queue where next_pos is the next position to dequeue. -*/ -typedef struct { - git_array_t(size_t) arr; - size_t next_pos; - size_t first_entry; -} deletes_by_oid_queue; - -GIT_HASHMAP_OID_SETUP(git_merge_deletes_oidmap, deletes_by_oid_queue *); - -static void deletes_by_oid_dispose(git_merge_deletes_oidmap *map) -{ - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - deletes_by_oid_queue *queue; - - if (!map) - return; - - while (git_merge_deletes_oidmap_iterate(&iter, NULL, &queue, map) == 0) - git_array_clear(queue->arr); - - git_merge_deletes_oidmap_dispose(map); -} - -static int deletes_by_oid_enqueue(git_merge_deletes_oidmap *map, git_pool *pool, const git_oid *id, size_t idx) -{ - deletes_by_oid_queue *queue; - size_t *array_entry; - - if (git_merge_deletes_oidmap_get(&queue, map, id) != 0) { - queue = git_pool_malloc(pool, sizeof(deletes_by_oid_queue)); - GIT_ERROR_CHECK_ALLOC(queue); - - git_array_init(queue->arr); - queue->next_pos = 0; - queue->first_entry = idx; - - if (git_merge_deletes_oidmap_put(map, id, queue) < 0) - return -1; - } else { - array_entry = git_array_alloc(queue->arr); - GIT_ERROR_CHECK_ALLOC(array_entry); - *array_entry = idx; - } - - return 0; -} - -static int deletes_by_oid_dequeue(size_t *idx, git_merge_deletes_oidmap *map, const git_oid *id) -{ - deletes_by_oid_queue *queue; - size_t *array_entry; - int error; - - if ((error = git_merge_deletes_oidmap_get(&queue, map, id)) != 0) - return error; - - if (queue->next_pos == 0) { - *idx = queue->first_entry; - } else { - array_entry = git_array_get(queue->arr, queue->next_pos - 1); - if (array_entry == NULL) - return GIT_ENOTFOUND; - - *idx = *array_entry; - } - - queue->next_pos++; - return 0; -} - -static int merge_diff_mark_similarity_exact( - git_merge_diff_list *diff_list, - struct merge_diff_similarity *similarity_ours, - struct merge_diff_similarity *similarity_theirs) -{ - size_t i, j; - git_merge_diff *conflict_src, *conflict_tgt; - git_merge_deletes_oidmap ours_deletes_by_oid = GIT_HASHMAP_INIT, - theirs_deletes_by_oid = GIT_HASHMAP_INIT; - int error = 0; - - /* Build a map of object ids to conflicts */ - git_vector_foreach(&diff_list->conflicts, i, conflict_src) { - /* Items can be the source of a rename iff they have an item in the - * ancestor slot and lack an item in the ours or theirs slot. */ - if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->ancestor_entry)) - continue; - - /* - * Ignore empty files because it has always the same blob sha1 - * and will lead to incorrect matches between all entries. - */ - if (git_oid_equal(&conflict_src->ancestor_entry.id, &git_oid__empty_blob_sha1)) - continue; - - if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->our_entry)) { - error = deletes_by_oid_enqueue(&ours_deletes_by_oid, &diff_list->pool, &conflict_src->ancestor_entry.id, i); - if (error < 0) - goto done; - } - - if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->their_entry)) { - error = deletes_by_oid_enqueue(&theirs_deletes_by_oid, &diff_list->pool, &conflict_src->ancestor_entry.id, i); - if (error < 0) - goto done; - } - } - - git_vector_foreach(&diff_list->conflicts, j, conflict_tgt) { - if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_tgt->ancestor_entry)) - continue; - - if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_tgt->our_entry)) { - if (deletes_by_oid_dequeue(&i, &ours_deletes_by_oid, &conflict_tgt->our_entry.id) == 0) { - similarity_ours[i].similarity = 100; - similarity_ours[i].other_idx = j; - - similarity_ours[j].similarity = 100; - similarity_ours[j].other_idx = i; - } - } - - if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_tgt->their_entry)) { - if (deletes_by_oid_dequeue(&i, &theirs_deletes_by_oid, &conflict_tgt->their_entry.id) == 0) { - similarity_theirs[i].similarity = 100; - similarity_theirs[i].other_idx = j; - - similarity_theirs[j].similarity = 100; - similarity_theirs[j].other_idx = i; - } - } - } - -done: - deletes_by_oid_dispose(&ours_deletes_by_oid); - deletes_by_oid_dispose(&theirs_deletes_by_oid); - - return error; -} - -static int merge_diff_mark_similarity_inexact( - git_repository *repo, - git_merge_diff_list *diff_list, - struct merge_diff_similarity *similarity_ours, - struct merge_diff_similarity *similarity_theirs, - void **cache, - const git_merge_options *opts) -{ - size_t i, j; - git_merge_diff *conflict_src, *conflict_tgt; - int similarity; - - git_vector_foreach(&diff_list->conflicts, i, conflict_src) { - /* Items can be the source of a rename iff they have an item in the - * ancestor slot and lack an item in the ours or theirs slot. */ - if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->ancestor_entry) || - (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->our_entry) && - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->their_entry))) - continue; - - git_vector_foreach(&diff_list->conflicts, j, conflict_tgt) { - size_t our_idx = diff_list->conflicts.length + j; - size_t their_idx = (diff_list->conflicts.length * 2) + j; - - if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_tgt->ancestor_entry)) - continue; - - if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_tgt->our_entry) && - !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->our_entry)) { - similarity = index_entry_similarity_inexact(repo, &conflict_src->ancestor_entry, i, &conflict_tgt->our_entry, our_idx, cache, opts); - - if (similarity == GIT_EBUFS) - continue; - else if (similarity < 0) - return similarity; - - if (similarity > similarity_ours[i].similarity && - similarity > similarity_ours[j].similarity) { - /* Clear previous best similarity */ - if (similarity_ours[i].similarity > 0) - similarity_ours[similarity_ours[i].other_idx].similarity = 0; - - if (similarity_ours[j].similarity > 0) - similarity_ours[similarity_ours[j].other_idx].similarity = 0; - - similarity_ours[i].similarity = similarity; - similarity_ours[i].other_idx = j; - - similarity_ours[j].similarity = similarity; - similarity_ours[j].other_idx = i; - } - } - - if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_tgt->their_entry) && - !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->their_entry)) { - similarity = index_entry_similarity_inexact(repo, &conflict_src->ancestor_entry, i, &conflict_tgt->their_entry, their_idx, cache, opts); - - if (similarity > similarity_theirs[i].similarity && - similarity > similarity_theirs[j].similarity) { - /* Clear previous best similarity */ - if (similarity_theirs[i].similarity > 0) - similarity_theirs[similarity_theirs[i].other_idx].similarity = 0; - - if (similarity_theirs[j].similarity > 0) - similarity_theirs[similarity_theirs[j].other_idx].similarity = 0; - - similarity_theirs[i].similarity = similarity; - similarity_theirs[i].other_idx = j; - - similarity_theirs[j].similarity = similarity; - similarity_theirs[j].other_idx = i; - } - } - } - } - - return 0; -} - -/* - * Rename conflicts: - * - * Ancestor Ours Theirs - * - * 0a A A A No rename - * b A A* A No rename (ours was rewritten) - * c A A A* No rename (theirs rewritten) - * 1a A A B[A] Rename or rename/edit - * b A B[A] A (automergeable) - * 2 A B[A] B[A] Both renamed (automergeable) - * 3a A B[A] Rename/delete - * b A B[A] (same) - * 4a A B[A] B Rename/add [B~ours B~theirs] - * b A B B[A] (same) - * 5 A B[A] C[A] Both renamed ("1 -> 2") - * 6 A C[A] Both renamed ("2 -> 1") - * B C[B] [C~ours C~theirs] (automergeable) - */ -static void merge_diff_mark_rename_conflict( - git_merge_diff_list *diff_list, - struct merge_diff_similarity *similarity_ours, - bool ours_renamed, - size_t ours_source_idx, - struct merge_diff_similarity *similarity_theirs, - bool theirs_renamed, - size_t theirs_source_idx, - git_merge_diff *target, - const git_merge_options *opts) -{ - git_merge_diff *ours_source = NULL, *theirs_source = NULL; - - if (ours_renamed) - ours_source = diff_list->conflicts.contents[ours_source_idx]; - - if (theirs_renamed) - theirs_source = diff_list->conflicts.contents[theirs_source_idx]; - - /* Detect 2->1 conflicts */ - if (ours_renamed && theirs_renamed) { - /* Both renamed to the same target name. */ - if (ours_source_idx == theirs_source_idx) - ours_source->type = GIT_MERGE_DIFF_BOTH_RENAMED; - else { - ours_source->type = GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1; - theirs_source->type = GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1; - } - } else if (ours_renamed) { - /* If our source was also renamed in theirs, this is a 1->2 */ - if (similarity_theirs[ours_source_idx].similarity >= opts->rename_threshold) - ours_source->type = GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2; - - else if (GIT_MERGE_INDEX_ENTRY_EXISTS(target->their_entry)) { - ours_source->type = GIT_MERGE_DIFF_RENAMED_ADDED; - target->type = GIT_MERGE_DIFF_RENAMED_ADDED; - } - - else if (!GIT_MERGE_INDEX_ENTRY_EXISTS(ours_source->their_entry)) - ours_source->type = GIT_MERGE_DIFF_RENAMED_DELETED; - - else if (ours_source->type == GIT_MERGE_DIFF_MODIFIED_DELETED) - ours_source->type = GIT_MERGE_DIFF_RENAMED_MODIFIED; - } else if (theirs_renamed) { - /* If their source was also renamed in ours, this is a 1->2 */ - if (similarity_ours[theirs_source_idx].similarity >= opts->rename_threshold) - theirs_source->type = GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2; - - else if (GIT_MERGE_INDEX_ENTRY_EXISTS(target->our_entry)) { - theirs_source->type = GIT_MERGE_DIFF_RENAMED_ADDED; - target->type = GIT_MERGE_DIFF_RENAMED_ADDED; - } - - else if (!GIT_MERGE_INDEX_ENTRY_EXISTS(theirs_source->our_entry)) - theirs_source->type = GIT_MERGE_DIFF_RENAMED_DELETED; - - else if (theirs_source->type == GIT_MERGE_DIFF_MODIFIED_DELETED) - theirs_source->type = GIT_MERGE_DIFF_RENAMED_MODIFIED; - } -} - -GIT_INLINE(void) merge_diff_coalesce_rename( - git_index_entry *source_entry, - git_delta_t *source_status, - git_index_entry *target_entry, - git_delta_t *target_status) -{ - /* Coalesce the rename target into the rename source. */ - memcpy(source_entry, target_entry, sizeof(git_index_entry)); - *source_status = GIT_DELTA_RENAMED; - - memset(target_entry, 0x0, sizeof(git_index_entry)); - *target_status = GIT_DELTA_UNMODIFIED; -} - -static void merge_diff_list_coalesce_renames( - git_merge_diff_list *diff_list, - struct merge_diff_similarity *similarity_ours, - struct merge_diff_similarity *similarity_theirs, - const git_merge_options *opts) -{ - size_t i; - bool ours_renamed = 0, theirs_renamed = 0; - size_t ours_source_idx = 0, theirs_source_idx = 0; - git_merge_diff *ours_source, *theirs_source, *target; - - for (i = 0; i < diff_list->conflicts.length; i++) { - target = diff_list->conflicts.contents[i]; - - ours_renamed = 0; - theirs_renamed = 0; - - if (GIT_MERGE_INDEX_ENTRY_EXISTS(target->our_entry) && - similarity_ours[i].similarity >= opts->rename_threshold) { - ours_source_idx = similarity_ours[i].other_idx; - - ours_source = diff_list->conflicts.contents[ours_source_idx]; - - merge_diff_coalesce_rename( - &ours_source->our_entry, - &ours_source->our_status, - &target->our_entry, - &target->our_status); - - similarity_ours[ours_source_idx].similarity = 0; - similarity_ours[i].similarity = 0; - - ours_renamed = 1; - } - - /* insufficient to determine direction */ - if (GIT_MERGE_INDEX_ENTRY_EXISTS(target->their_entry) && - similarity_theirs[i].similarity >= opts->rename_threshold) { - theirs_source_idx = similarity_theirs[i].other_idx; - - theirs_source = diff_list->conflicts.contents[theirs_source_idx]; - - merge_diff_coalesce_rename( - &theirs_source->their_entry, - &theirs_source->their_status, - &target->their_entry, - &target->their_status); - - similarity_theirs[theirs_source_idx].similarity = 0; - similarity_theirs[i].similarity = 0; - - theirs_renamed = 1; - } - - merge_diff_mark_rename_conflict(diff_list, - similarity_ours, ours_renamed, ours_source_idx, - similarity_theirs, theirs_renamed, theirs_source_idx, - target, opts); - } -} - -static int merge_diff_empty(const git_vector *conflicts, size_t idx, void *p) -{ - git_merge_diff *conflict = conflicts->contents[idx]; - - GIT_UNUSED(p); - - return (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) && - !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) && - !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry)); -} - -static void merge_diff_list_count_candidates( - git_merge_diff_list *diff_list, - size_t *src_count, - size_t *tgt_count) -{ - git_merge_diff *entry; - size_t i; - - *src_count = 0; - *tgt_count = 0; - - git_vector_foreach(&diff_list->conflicts, i, entry) { - if (GIT_MERGE_INDEX_ENTRY_EXISTS(entry->ancestor_entry) && - (!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->our_entry) || - !GIT_MERGE_INDEX_ENTRY_EXISTS(entry->their_entry))) - (*src_count)++; - else if (!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->ancestor_entry)) - (*tgt_count)++; - } -} - -int git_merge_diff_list__find_renames( - git_repository *repo, - git_merge_diff_list *diff_list, - const git_merge_options *opts) -{ - struct merge_diff_similarity *similarity_ours, *similarity_theirs; - void **cache = NULL; - size_t cache_size = 0; - size_t src_count, tgt_count, i; - int error = 0; - - GIT_ASSERT_ARG(diff_list); - GIT_ASSERT_ARG(opts); - - if ((opts->flags & GIT_MERGE_FIND_RENAMES) == 0 || - !diff_list->conflicts.length) - return 0; - - similarity_ours = git__calloc(diff_list->conflicts.length, - sizeof(struct merge_diff_similarity)); - GIT_ERROR_CHECK_ALLOC(similarity_ours); - - similarity_theirs = git__calloc(diff_list->conflicts.length, - sizeof(struct merge_diff_similarity)); - GIT_ERROR_CHECK_ALLOC(similarity_theirs); - - /* Calculate similarity between items that were deleted from the ancestor - * and added in the other branch. - */ - if ((error = merge_diff_mark_similarity_exact(diff_list, similarity_ours, similarity_theirs)) < 0) - goto done; - - if (opts->rename_threshold < 100 && diff_list->conflicts.length <= opts->target_limit) { - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&cache_size, diff_list->conflicts.length, 3); - cache = git__calloc(cache_size, sizeof(void *)); - GIT_ERROR_CHECK_ALLOC(cache); - - merge_diff_list_count_candidates(diff_list, &src_count, &tgt_count); - - if (src_count > opts->target_limit || tgt_count > opts->target_limit) { - /* TODO: report! */ - } else { - if ((error = merge_diff_mark_similarity_inexact( - repo, diff_list, similarity_ours, similarity_theirs, cache, opts)) < 0) - goto done; - } - } - - /* For entries that are appropriately similar, merge the new name's entry - * into the old name. - */ - merge_diff_list_coalesce_renames(diff_list, similarity_ours, similarity_theirs, opts); - - /* And remove any entries that were merged and are now empty. */ - git_vector_remove_matching(&diff_list->conflicts, merge_diff_empty, NULL); - -done: - if (cache != NULL) { - for (i = 0; i < cache_size; ++i) { - if (cache[i] != NULL && cache[i] != &cache_invalid_marker) - opts->metric->free_signature(cache[i], opts->metric->payload); - } - - git__free(cache); - } - - git__free(similarity_ours); - git__free(similarity_theirs); - - return error; -} - -/* Directory/file conflict handling */ - -GIT_INLINE(const char *) merge_diff_path( - const git_merge_diff *conflict) -{ - if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry)) - return conflict->ancestor_entry.path; - else if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry)) - return conflict->our_entry.path; - else if (GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry)) - return conflict->their_entry.path; - - return NULL; -} - -GIT_INLINE(bool) merge_diff_any_side_added_or_modified( - const git_merge_diff *conflict) -{ - if (conflict->our_status == GIT_DELTA_ADDED || - conflict->our_status == GIT_DELTA_MODIFIED || - conflict->their_status == GIT_DELTA_ADDED || - conflict->their_status == GIT_DELTA_MODIFIED) - return true; - - return false; -} - -GIT_INLINE(bool) path_is_prefixed(const char *parent, const char *child) -{ - size_t child_len = strlen(child); - size_t parent_len = strlen(parent); - - if (child_len < parent_len || - strncmp(parent, child, parent_len) != 0) - return 0; - - return (child[parent_len] == '/'); -} - -GIT_INLINE(int) merge_diff_detect_df_conflict( - struct merge_diff_df_data *df_data, - git_merge_diff *conflict) -{ - const char *cur_path = merge_diff_path(conflict); - - /* Determine if this is a D/F conflict or the child of one */ - if (df_data->df_path && - path_is_prefixed(df_data->df_path, cur_path)) - conflict->type = GIT_MERGE_DIFF_DF_CHILD; - else if(df_data->df_path) - df_data->df_path = NULL; - else if (df_data->prev_path && - merge_diff_any_side_added_or_modified(df_data->prev_conflict) && - merge_diff_any_side_added_or_modified(conflict) && - path_is_prefixed(df_data->prev_path, cur_path)) { - conflict->type = GIT_MERGE_DIFF_DF_CHILD; - - df_data->prev_conflict->type = GIT_MERGE_DIFF_DIRECTORY_FILE; - df_data->df_path = df_data->prev_path; - } - - df_data->prev_path = cur_path; - df_data->prev_conflict = conflict; - - return 0; -} - -/* Conflict handling */ - -GIT_INLINE(int) merge_diff_detect_type( - git_merge_diff *conflict) -{ - if (conflict->our_status == GIT_DELTA_ADDED && - conflict->their_status == GIT_DELTA_ADDED) - conflict->type = GIT_MERGE_DIFF_BOTH_ADDED; - else if (conflict->our_status == GIT_DELTA_MODIFIED && - conflict->their_status == GIT_DELTA_MODIFIED) - conflict->type = GIT_MERGE_DIFF_BOTH_MODIFIED; - else if (conflict->our_status == GIT_DELTA_DELETED && - conflict->their_status == GIT_DELTA_DELETED) - conflict->type = GIT_MERGE_DIFF_BOTH_DELETED; - else if (conflict->our_status == GIT_DELTA_MODIFIED && - conflict->their_status == GIT_DELTA_DELETED) - conflict->type = GIT_MERGE_DIFF_MODIFIED_DELETED; - else if (conflict->our_status == GIT_DELTA_DELETED && - conflict->their_status == GIT_DELTA_MODIFIED) - conflict->type = GIT_MERGE_DIFF_MODIFIED_DELETED; - else - conflict->type = GIT_MERGE_DIFF_NONE; - - return 0; -} - -GIT_INLINE(int) index_entry_dup_pool( - git_index_entry *out, - git_pool *pool, - const git_index_entry *src) -{ - if (src != NULL) { - memcpy(out, src, sizeof(git_index_entry)); - if ((out->path = git_pool_strdup(pool, src->path)) == NULL) - return -1; - } - - return 0; -} - -GIT_INLINE(int) merge_delta_type_from_index_entries( - const git_index_entry *ancestor, - const git_index_entry *other) -{ - if (ancestor == NULL && other == NULL) - return GIT_DELTA_UNMODIFIED; - else if (ancestor == NULL && other != NULL) - return GIT_DELTA_ADDED; - else if (ancestor != NULL && other == NULL) - return GIT_DELTA_DELETED; - else if (S_ISDIR(ancestor->mode) ^ S_ISDIR(other->mode)) - return GIT_DELTA_TYPECHANGE; - else if(S_ISLNK(ancestor->mode) ^ S_ISLNK(other->mode)) - return GIT_DELTA_TYPECHANGE; - else if (git_oid__cmp(&ancestor->id, &other->id) || - ancestor->mode != other->mode) - return GIT_DELTA_MODIFIED; - - return GIT_DELTA_UNMODIFIED; -} - -static git_merge_diff *merge_diff_from_index_entries( - git_merge_diff_list *diff_list, - const git_index_entry **entries) -{ - git_merge_diff *conflict; - git_pool *pool = &diff_list->pool; - - if ((conflict = git_pool_mallocz(pool, sizeof(git_merge_diff))) == NULL) - return NULL; - - if (index_entry_dup_pool(&conflict->ancestor_entry, pool, entries[TREE_IDX_ANCESTOR]) < 0 || - index_entry_dup_pool(&conflict->our_entry, pool, entries[TREE_IDX_OURS]) < 0 || - index_entry_dup_pool(&conflict->their_entry, pool, entries[TREE_IDX_THEIRS]) < 0) - return NULL; - - conflict->our_status = merge_delta_type_from_index_entries( - entries[TREE_IDX_ANCESTOR], entries[TREE_IDX_OURS]); - conflict->their_status = merge_delta_type_from_index_entries( - entries[TREE_IDX_ANCESTOR], entries[TREE_IDX_THEIRS]); - - return conflict; -} - -/* Merge trees */ - -static int merge_diff_list_insert_conflict( - git_merge_diff_list *diff_list, - struct merge_diff_df_data *merge_df_data, - const git_index_entry *tree_items[3]) -{ - git_merge_diff *conflict; - - if ((conflict = merge_diff_from_index_entries(diff_list, tree_items)) == NULL || - merge_diff_detect_type(conflict) < 0 || - merge_diff_detect_df_conflict(merge_df_data, conflict) < 0 || - git_vector_insert(&diff_list->conflicts, conflict) < 0) - return -1; - - return 0; -} - -static int merge_diff_list_insert_unmodified( - git_merge_diff_list *diff_list, - const git_index_entry *tree_items[3]) -{ - int error = 0; - git_index_entry *entry; - - entry = git_pool_malloc(&diff_list->pool, sizeof(git_index_entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - if ((error = index_entry_dup_pool(entry, &diff_list->pool, tree_items[0])) >= 0) - error = git_vector_insert(&diff_list->staged, entry); - - return error; -} - -struct merge_diff_find_data { - git_merge_diff_list *diff_list; - struct merge_diff_df_data df_data; -}; - -static int queue_difference(const git_index_entry **entries, void *data) -{ - struct merge_diff_find_data *find_data = data; - bool item_modified = false; - size_t i; - - if (!entries[0] || !entries[1] || !entries[2]) { - item_modified = true; - } else { - for (i = 1; i < 3; i++) { - if (index_entry_cmp(entries[0], entries[i]) != 0) { - item_modified = true; - break; - } - } - } - - return item_modified ? - merge_diff_list_insert_conflict( - find_data->diff_list, &find_data->df_data, entries) : - merge_diff_list_insert_unmodified(find_data->diff_list, entries); -} - -int git_merge_diff_list__find_differences( - git_merge_diff_list *diff_list, - git_iterator *ancestor_iter, - git_iterator *our_iter, - git_iterator *their_iter) -{ - git_iterator *iterators[3] = { ancestor_iter, our_iter, their_iter }; - struct merge_diff_find_data find_data = { diff_list }; - - return git_iterator_walk(iterators, 3, queue_difference, &find_data); -} - -git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo) -{ - git_merge_diff_list *diff_list = git__calloc(1, sizeof(git_merge_diff_list)); - - if (diff_list == NULL) - return NULL; - - diff_list->repo = repo; - - - if (git_pool_init(&diff_list->pool, 1) < 0 || - git_vector_init(&diff_list->staged, 0, NULL) < 0 || - git_vector_init(&diff_list->conflicts, 0, NULL) < 0 || - git_vector_init(&diff_list->resolved, 0, NULL) < 0) { - git_merge_diff_list__free(diff_list); - return NULL; - } - - return diff_list; -} - -void git_merge_diff_list__free(git_merge_diff_list *diff_list) -{ - if (!diff_list) - return; - - git_vector_dispose(&diff_list->staged); - git_vector_dispose(&diff_list->conflicts); - git_vector_dispose(&diff_list->resolved); - git_pool_clear(&diff_list->pool); - git__free(diff_list); -} - -static int merge_normalize_opts( - git_repository *repo, - git_merge_options *opts, - const git_merge_options *given) -{ - git_config *cfg = NULL; - git_config_entry *entry = NULL; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(opts); - - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0) - return error; - - if (given != NULL) { - memcpy(opts, given, sizeof(git_merge_options)); - } else { - git_merge_options init = GIT_MERGE_OPTIONS_INIT; - memcpy(opts, &init, sizeof(init)); - } - - if ((opts->flags & GIT_MERGE_FIND_RENAMES) && !opts->rename_threshold) - opts->rename_threshold = GIT_MERGE_DEFAULT_RENAME_THRESHOLD; - - if (given && given->default_driver) { - opts->default_driver = git__strdup(given->default_driver); - GIT_ERROR_CHECK_ALLOC(opts->default_driver); - } else { - error = git_config_get_entry(&entry, cfg, "merge.default"); - - if (error == 0) { - opts->default_driver = git__strdup(entry->value); - GIT_ERROR_CHECK_ALLOC(opts->default_driver); - } else if (error == GIT_ENOTFOUND) { - error = 0; - } else { - goto done; - } - } - - if (!opts->target_limit) { - int limit = git_config__get_int_force(cfg, "merge.renamelimit", 0); - - if (!limit) - limit = git_config__get_int_force(cfg, "diff.renamelimit", 0); - - opts->target_limit = (limit <= 0) ? - GIT_MERGE_DEFAULT_TARGET_LIMIT : (unsigned int)limit; - } - - /* assign the internal metric with whitespace flag as payload */ - if (!opts->metric) { - opts->metric = git__malloc(sizeof(git_diff_similarity_metric)); - GIT_ERROR_CHECK_ALLOC(opts->metric); - - opts->metric->file_signature = git_diff_find_similar__hashsig_for_file; - opts->metric->buffer_signature = git_diff_find_similar__hashsig_for_buf; - opts->metric->free_signature = git_diff_find_similar__hashsig_free; - opts->metric->similarity = git_diff_find_similar__calc_similarity; - opts->metric->payload = (void *)GIT_HASHSIG_SMART_WHITESPACE; - } - -done: - git_config_entry_free(entry); - return error; -} - - -static int merge_index_insert_reuc( - git_index *index, - size_t idx, - const git_index_entry *entry) -{ - const git_index_reuc_entry *reuc; - int mode[3] = { 0, 0, 0 }; - git_oid const *oid[3] = { NULL, NULL, NULL }; - size_t i; - - if (!GIT_MERGE_INDEX_ENTRY_EXISTS(*entry)) - return 0; - - if ((reuc = git_index_reuc_get_bypath(index, entry->path)) != NULL) { - for (i = 0; i < 3; i++) { - mode[i] = reuc->mode[i]; - oid[i] = &reuc->oid[i]; - } - } - - mode[idx] = entry->mode; - oid[idx] = &entry->id; - - return git_index_reuc_add(index, entry->path, - mode[0], oid[0], mode[1], oid[1], mode[2], oid[2]); -} - -static int index_update_reuc(git_index *index, git_merge_diff_list *diff_list) -{ - int error; - size_t i; - git_merge_diff *conflict; - - /* Add each entry in the resolved conflict to the REUC independently, since - * the paths may differ due to renames. */ - git_vector_foreach(&diff_list->resolved, i, conflict) { - const git_index_entry *ancestor = - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) ? - &conflict->ancestor_entry : NULL; - - const git_index_entry *ours = - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) ? - &conflict->our_entry : NULL; - - const git_index_entry *theirs = - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry) ? - &conflict->their_entry : NULL; - - if (ancestor != NULL && - (error = merge_index_insert_reuc(index, TREE_IDX_ANCESTOR, ancestor)) < 0) - return error; - - if (ours != NULL && - (error = merge_index_insert_reuc(index, TREE_IDX_OURS, ours)) < 0) - return error; - - if (theirs != NULL && - (error = merge_index_insert_reuc(index, TREE_IDX_THEIRS, theirs)) < 0) - return error; - } - - return 0; -} - -static int index_from_diff_list( - git_index **out, - git_merge_diff_list *diff_list, - git_oid_t oid_type, - bool skip_reuc) -{ - git_index *index; - size_t i; - git_merge_diff *conflict; - int error = 0; - - *out = NULL; - - if ((error = git_index__new(&index, oid_type)) < 0) - return error; - - if ((error = git_index__fill(index, &diff_list->staged)) < 0) - goto on_error; - - git_vector_foreach(&diff_list->conflicts, i, conflict) { - const git_index_entry *ancestor = - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) ? - &conflict->ancestor_entry : NULL; - - const git_index_entry *ours = - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) ? - &conflict->our_entry : NULL; - - const git_index_entry *theirs = - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry) ? - &conflict->their_entry : NULL; - - if ((error = git_index_conflict_add(index, ancestor, ours, theirs)) < 0) - goto on_error; - } - - /* Add each rename entry to the rename portion of the index. */ - git_vector_foreach(&diff_list->conflicts, i, conflict) { - const char *ancestor_path, *our_path, *their_path; - - if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry)) - continue; - - ancestor_path = conflict->ancestor_entry.path; - - our_path = - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) ? - conflict->our_entry.path : NULL; - - their_path = - GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry) ? - conflict->their_entry.path : NULL; - - if ((our_path && strcmp(ancestor_path, our_path) != 0) || - (their_path && strcmp(ancestor_path, their_path) != 0)) { - if ((error = git_index_name_add(index, ancestor_path, our_path, their_path)) < 0) - goto on_error; - } - } - - if (!skip_reuc) { - if ((error = index_update_reuc(index, diff_list)) < 0) - goto on_error; - } - - *out = index; - return 0; - -on_error: - git_index_free(index); - return error; -} - -static git_iterator *iterator_given_or_empty(git_iterator **empty, git_iterator *given) -{ - git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT; - - if (given) - return given; - - opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; - - if (git_iterator_for_nothing(empty, &opts) < 0) - return NULL; - - return *empty; -} - -int git_merge__iterators( - git_index **out, - git_repository *repo, - git_iterator *ancestor_iter, - git_iterator *our_iter, - git_iterator *theirs_iter, - const git_merge_options *given_opts) -{ - git_iterator *empty_ancestor = NULL, - *empty_ours = NULL, - *empty_theirs = NULL; - git_merge_diff_list *diff_list; - git_merge_options opts; - git_merge_file_options file_opts = GIT_MERGE_FILE_OPTIONS_INIT; - git_merge_diff *conflict; - git_vector changes; - size_t i; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - *out = NULL; - - GIT_ERROR_CHECK_VERSION( - given_opts, GIT_MERGE_OPTIONS_VERSION, "git_merge_options"); - - if ((error = merge_normalize_opts(repo, &opts, given_opts)) < 0) - return error; - - file_opts.favor = opts.file_favor; - file_opts.flags = opts.file_flags; - - /* use the git-inspired labels when virtual base building */ - if (opts.flags & GIT_MERGE_VIRTUAL_BASE) { - file_opts.ancestor_label = "merged common ancestors"; - file_opts.our_label = "Temporary merge branch 1"; - file_opts.their_label = "Temporary merge branch 2"; - file_opts.flags |= GIT_MERGE_FILE_ACCEPT_CONFLICTS; - file_opts.marker_size = GIT_MERGE_CONFLICT_MARKER_SIZE + 2; - } - - diff_list = git_merge_diff_list__alloc(repo); - GIT_ERROR_CHECK_ALLOC(diff_list); - - ancestor_iter = iterator_given_or_empty(&empty_ancestor, ancestor_iter); - our_iter = iterator_given_or_empty(&empty_ours, our_iter); - theirs_iter = iterator_given_or_empty(&empty_theirs, theirs_iter); - - if ((error = git_merge_diff_list__find_differences( - diff_list, ancestor_iter, our_iter, theirs_iter)) < 0 || - (error = git_merge_diff_list__find_renames(repo, diff_list, &opts)) < 0) - goto done; - - memcpy(&changes, &diff_list->conflicts, sizeof(git_vector)); - git_vector_clear(&diff_list->conflicts); - - git_vector_foreach(&changes, i, conflict) { - int resolved = 0; - - if ((error = merge_conflict_resolve( - &resolved, diff_list, conflict, &opts, &file_opts)) < 0) - goto done; - - if (!resolved) { - if ((opts.flags & GIT_MERGE_FAIL_ON_CONFLICT)) { - git_error_set(GIT_ERROR_MERGE, "merge conflicts exist"); - error = GIT_EMERGECONFLICT; - goto done; - } - - git_vector_insert(&diff_list->conflicts, conflict); - } - } - - error = index_from_diff_list(out, diff_list, repo->oid_type, - (opts.flags & GIT_MERGE_SKIP_REUC)); - -done: - if (!given_opts || !given_opts->metric) - git__free(opts.metric); - - git__free((char *)opts.default_driver); - - git_merge_diff_list__free(diff_list); - git_iterator_free(empty_ancestor); - git_iterator_free(empty_ours); - git_iterator_free(empty_theirs); - - return error; -} - -int git_merge_trees( - git_index **out, - git_repository *repo, - const git_tree *ancestor_tree, - const git_tree *our_tree, - const git_tree *their_tree, - const git_merge_options *merge_opts) -{ - git_iterator *ancestor_iter = NULL, *our_iter = NULL, *their_iter = NULL; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - /* if one side is treesame to the ancestor, take the other side */ - if (ancestor_tree && merge_opts && (merge_opts->flags & GIT_MERGE_SKIP_REUC)) { - const git_tree *result = NULL; - const git_oid *ancestor_tree_id = git_tree_id(ancestor_tree); - - if (our_tree && !git_oid_cmp(ancestor_tree_id, git_tree_id(our_tree))) - result = their_tree; - else if (their_tree && !git_oid_cmp(ancestor_tree_id, git_tree_id(their_tree))) - result = our_tree; - - if (result) { - if ((error = git_index__new(out, repo->oid_type)) == 0) - error = git_index_read_tree(*out, result); - - return error; - } - } - - iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; - - if ((error = git_iterator_for_tree( - &ancestor_iter, (git_tree *)ancestor_tree, &iter_opts)) < 0 || - (error = git_iterator_for_tree( - &our_iter, (git_tree *)our_tree, &iter_opts)) < 0 || - (error = git_iterator_for_tree( - &their_iter, (git_tree *)their_tree, &iter_opts)) < 0) - goto done; - - error = git_merge__iterators( - out, repo, ancestor_iter, our_iter, their_iter, merge_opts); - -done: - git_iterator_free(ancestor_iter); - git_iterator_free(our_iter); - git_iterator_free(their_iter); - - return error; -} - -static int merge_annotated_commits( - git_index **index_out, - git_annotated_commit **base_out, - git_repository *repo, - git_annotated_commit *our_commit, - git_annotated_commit *their_commit, - size_t recursion_level, - const git_merge_options *opts); - -GIT_INLINE(int) insert_head_ids( - git_array_oid_t *ids, - const git_annotated_commit *annotated_commit) -{ - git_oid *id; - size_t i; - - if (annotated_commit->type == GIT_ANNOTATED_COMMIT_REAL) { - id = git_array_alloc(*ids); - GIT_ERROR_CHECK_ALLOC(id); - - git_oid_cpy(id, git_commit_id(annotated_commit->commit)); - } else { - for (i = 0; i < annotated_commit->parents.size; i++) { - id = git_array_alloc(*ids); - GIT_ERROR_CHECK_ALLOC(id); - - git_oid_cpy(id, &annotated_commit->parents.ptr[i]); - } - } - - return 0; -} - -static int create_virtual_base( - git_annotated_commit **out, - git_repository *repo, - git_annotated_commit *one, - git_annotated_commit *two, - const git_merge_options *opts, - size_t recursion_level) -{ - git_annotated_commit *result = NULL; - git_index *index = NULL; - git_merge_options virtual_opts = GIT_MERGE_OPTIONS_INIT; - - /* Conflicts in the merge base creation do not propagate to conflicts - * in the result; the conflicted base will act as the common ancestor. - */ - if (opts) - memcpy(&virtual_opts, opts, sizeof(git_merge_options)); - - virtual_opts.flags &= ~GIT_MERGE_FAIL_ON_CONFLICT; - virtual_opts.flags |= GIT_MERGE_VIRTUAL_BASE; - - if ((merge_annotated_commits(&index, NULL, repo, one, two, - recursion_level + 1, &virtual_opts)) < 0) - return -1; - - result = git__calloc(1, sizeof(git_annotated_commit)); - GIT_ERROR_CHECK_ALLOC(result); - result->type = GIT_ANNOTATED_COMMIT_VIRTUAL; - result->index = index; - - if (insert_head_ids(&result->parents, one) < 0 || - insert_head_ids(&result->parents, two) < 0) { - git_annotated_commit_free(result); - return -1; - } - - *out = result; - return 0; -} - -static int compute_base( - git_annotated_commit **out, - git_repository *repo, - const git_annotated_commit *one, - const git_annotated_commit *two, - const git_merge_options *given_opts, - size_t recursion_level) -{ - git_array_oid_t head_ids = GIT_ARRAY_INIT; - git_oidarray bases = {0}; - git_annotated_commit *base = NULL, *other = NULL, *new_base = NULL; - git_merge_options opts = GIT_MERGE_OPTIONS_INIT; - size_t i, base_count; - int error; - - *out = NULL; - - if (given_opts) - memcpy(&opts, given_opts, sizeof(git_merge_options)); - - /* With more than two commits, merge_bases_many finds the base of - * the first commit and a hypothetical merge of the others. Since - * "one" may itself be a virtual commit, which insert_head_ids - * substitutes multiple ancestors for, it needs to be added - * after "two" which is always a single real commit. - */ - if ((error = insert_head_ids(&head_ids, two)) < 0 || - (error = insert_head_ids(&head_ids, one)) < 0 || - (error = git_merge_bases_many(&bases, repo, - head_ids.size, head_ids.ptr)) < 0) - goto done; - - base_count = (opts.flags & GIT_MERGE_NO_RECURSIVE) ? 0 : bases.count; - - if (base_count) - git_oidarray__reverse(&bases); - - if ((error = git_annotated_commit_lookup(&base, repo, &bases.ids[0])) < 0) - goto done; - - for (i = 1; i < base_count; i++) { - recursion_level++; - - if (opts.recursion_limit && recursion_level > opts.recursion_limit) - break; - - if ((error = git_annotated_commit_lookup(&other, repo, - &bases.ids[i])) < 0 || - (error = create_virtual_base(&new_base, repo, base, other, &opts, - recursion_level)) < 0) - goto done; - - git_annotated_commit_free(base); - git_annotated_commit_free(other); - - base = new_base; - new_base = NULL; - other = NULL; - } - -done: - if (error == 0) - *out = base; - else - git_annotated_commit_free(base); - - git_annotated_commit_free(other); - git_annotated_commit_free(new_base); - git_oidarray_dispose(&bases); - git_array_clear(head_ids); - return error; -} - -static int iterator_for_annotated_commit( - git_iterator **out, - git_annotated_commit *commit) -{ - git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT; - int error; - - opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; - - if (commit == NULL) { - error = git_iterator_for_nothing(out, &opts); - } else if (commit->type == GIT_ANNOTATED_COMMIT_VIRTUAL) { - error = git_iterator_for_index(out, git_index_owner(commit->index), commit->index, &opts); - } else { - if (!commit->tree && - (error = git_commit_tree(&commit->tree, commit->commit)) < 0) - goto done; - - error = git_iterator_for_tree(out, commit->tree, &opts); - } - -done: - return error; -} - -static int merge_annotated_commits( - git_index **index_out, - git_annotated_commit **base_out, - git_repository *repo, - git_annotated_commit *ours, - git_annotated_commit *theirs, - size_t recursion_level, - const git_merge_options *opts) -{ - git_annotated_commit *base = NULL; - git_iterator *base_iter = NULL, *our_iter = NULL, *their_iter = NULL; - int error; - - if ((error = compute_base(&base, repo, ours, theirs, opts, - recursion_level)) < 0) { - - if (error != GIT_ENOTFOUND) - goto done; - - git_error_clear(); - } - - if ((error = iterator_for_annotated_commit(&base_iter, base)) < 0 || - (error = iterator_for_annotated_commit(&our_iter, ours)) < 0 || - (error = iterator_for_annotated_commit(&their_iter, theirs)) < 0 || - (error = git_merge__iterators(index_out, repo, base_iter, our_iter, - their_iter, opts)) < 0) - goto done; - - if (base_out) { - *base_out = base; - base = NULL; - } - -done: - git_annotated_commit_free(base); - git_iterator_free(base_iter); - git_iterator_free(our_iter); - git_iterator_free(their_iter); - return error; -} - - -int git_merge_commits( - git_index **out, - git_repository *repo, - const git_commit *our_commit, - const git_commit *their_commit, - const git_merge_options *opts) -{ - git_annotated_commit *ours = NULL, *theirs = NULL, *base = NULL; - int error = 0; - - if ((error = git_annotated_commit_from_commit(&ours, (git_commit *)our_commit)) < 0 || - (error = git_annotated_commit_from_commit(&theirs, (git_commit *)their_commit)) < 0) - goto done; - - error = merge_annotated_commits(out, &base, repo, ours, theirs, 0, opts); - -done: - git_annotated_commit_free(ours); - git_annotated_commit_free(theirs); - git_annotated_commit_free(base); - return error; -} - -/* Merge setup / cleanup */ - -static int write_merge_head( - git_repository *repo, - const git_annotated_commit *heads[], - size_t heads_len) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - size_t i; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(heads); - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_HEAD_FILE)) < 0 || - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0) - goto cleanup; - - for (i = 0; i < heads_len; i++) { - if ((error = git_filebuf_printf(&file, "%s\n", heads[i]->id_str)) < 0) - goto cleanup; - } - - error = git_filebuf_commit(&file); - -cleanup: - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - return error; -} - -static int write_merge_mode(git_repository *repo) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - int error = 0; - - GIT_ASSERT_ARG(repo); - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MODE_FILE)) < 0 || - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0) - goto cleanup; - - if ((error = git_filebuf_write(&file, "no-ff", 5)) < 0) - goto cleanup; - - error = git_filebuf_commit(&file); - -cleanup: - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - return error; -} - -struct merge_msg_entry { - const git_annotated_commit *merge_head; - bool written; -}; - -static int msg_entry_is_branch( - const struct merge_msg_entry *entry, - git_vector *entries) -{ - GIT_UNUSED(entries); - - return (entry->written == 0 && - entry->merge_head->remote_url == NULL && - entry->merge_head->ref_name != NULL && - git__strncmp(GIT_REFS_HEADS_DIR, entry->merge_head->ref_name, strlen(GIT_REFS_HEADS_DIR)) == 0); -} - -static int msg_entry_is_tracking( - const struct merge_msg_entry *entry, - git_vector *entries) -{ - GIT_UNUSED(entries); - - return (entry->written == 0 && - entry->merge_head->remote_url == NULL && - entry->merge_head->ref_name != NULL && - git__strncmp(GIT_REFS_REMOTES_DIR, entry->merge_head->ref_name, strlen(GIT_REFS_REMOTES_DIR)) == 0); -} - -static int msg_entry_is_tag( - const struct merge_msg_entry *entry, - git_vector *entries) -{ - GIT_UNUSED(entries); - - return (entry->written == 0 && - entry->merge_head->remote_url == NULL && - entry->merge_head->ref_name != NULL && - git__strncmp(GIT_REFS_TAGS_DIR, entry->merge_head->ref_name, strlen(GIT_REFS_TAGS_DIR)) == 0); -} - -static int msg_entry_is_remote( - const struct merge_msg_entry *entry, - git_vector *entries) -{ - if (entry->written == 0 && - entry->merge_head->remote_url != NULL && - entry->merge_head->ref_name != NULL && - git__strncmp(GIT_REFS_HEADS_DIR, entry->merge_head->ref_name, strlen(GIT_REFS_HEADS_DIR)) == 0) - { - struct merge_msg_entry *existing; - - /* Match only branches from the same remote */ - if (entries->length == 0) - return 1; - - existing = git_vector_get(entries, 0); - - return (git__strcmp(existing->merge_head->remote_url, - entry->merge_head->remote_url) == 0); - } - - return 0; -} - -static int msg_entry_is_oid( - const struct merge_msg_entry *merge_msg_entry) -{ - return (merge_msg_entry->written == 0 && - merge_msg_entry->merge_head->ref_name == NULL && - merge_msg_entry->merge_head->remote_url == NULL); -} - -static int merge_msg_entry_written( - const struct merge_msg_entry *merge_msg_entry) -{ - return (merge_msg_entry->written == 1); -} - -static int merge_msg_entries( - git_vector *v, - const struct merge_msg_entry *entries, - size_t len, - int (*match)(const struct merge_msg_entry *entry, git_vector *entries)) -{ - size_t i; - int matches, total = 0; - - git_vector_clear(v); - - for (i = 0; i < len; i++) { - if ((matches = match(&entries[i], v)) < 0) - return matches; - else if (!matches) - continue; - - git_vector_insert(v, (struct merge_msg_entry *)&entries[i]); - total++; - } - - return total; -} - -static int merge_msg_write_entries( - git_filebuf *file, - git_vector *entries, - const char *item_name, - const char *item_plural_name, - size_t ref_name_skip, - const char *source, - char sep) -{ - struct merge_msg_entry *entry; - size_t i; - int error = 0; - - if (entries->length == 0) - return 0; - - if (sep && (error = git_filebuf_printf(file, "%c ", sep)) < 0) - goto done; - - if ((error = git_filebuf_printf(file, "%s ", - (entries->length == 1) ? item_name : item_plural_name)) < 0) - goto done; - - git_vector_foreach(entries, i, entry) { - if (i > 0 && - (error = git_filebuf_printf(file, "%s", (i == entries->length - 1) ? " and " : ", ")) < 0) - goto done; - - if ((error = git_filebuf_printf(file, "'%s'", entry->merge_head->ref_name + ref_name_skip)) < 0) - goto done; - - entry->written = 1; - } - - if (source) - error = git_filebuf_printf(file, " of %s", source); - -done: - return error; -} - -static int merge_msg_write_branches( - git_filebuf *file, - git_vector *entries, - char sep) -{ - return merge_msg_write_entries(file, entries, - "branch", "branches", strlen(GIT_REFS_HEADS_DIR), NULL, sep); -} - -static int merge_msg_write_tracking( - git_filebuf *file, - git_vector *entries, - char sep) -{ - return merge_msg_write_entries(file, entries, - "remote-tracking branch", "remote-tracking branches", 0, NULL, sep); -} - -static int merge_msg_write_tags( - git_filebuf *file, - git_vector *entries, - char sep) -{ - return merge_msg_write_entries(file, entries, - "tag", "tags", strlen(GIT_REFS_TAGS_DIR), NULL, sep); -} - -static int merge_msg_write_remotes( - git_filebuf *file, - git_vector *entries, - char sep) -{ - const char *source; - - if (entries->length == 0) - return 0; - - source = ((struct merge_msg_entry *)entries->contents[0])->merge_head->remote_url; - - return merge_msg_write_entries(file, entries, - "branch", "branches", strlen(GIT_REFS_HEADS_DIR), source, sep); -} - -static int write_merge_msg( - git_repository *repo, - const git_annotated_commit *heads[], - size_t heads_len) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - struct merge_msg_entry *entries; - git_vector matching = GIT_VECTOR_INIT; - size_t i; - char sep = 0; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(heads); - - entries = git__calloc(heads_len, sizeof(struct merge_msg_entry)); - GIT_ERROR_CHECK_ALLOC(entries); - - if (git_vector_init(&matching, heads_len, NULL) < 0) { - git__free(entries); - return -1; - } - - for (i = 0; i < heads_len; i++) - entries[i].merge_head = heads[i]; - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 || - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0 || - (error = git_filebuf_write(&file, "Merge ", 6)) < 0) - goto cleanup; - - /* - * This is to emulate the format of MERGE_MSG by core git. - * - * Core git will write all the commits specified by OID, in the order - * provided, until the first named branch or tag is reached, at which - * point all branches will be written in the order provided, then all - * tags, then all remote tracking branches and finally all commits that - * were specified by OID that were not already written. - * - * Yes. Really. - */ - for (i = 0; i < heads_len; i++) { - if (!msg_entry_is_oid(&entries[i])) - break; - - if ((error = git_filebuf_printf(&file, - "%scommit '%s'", (i > 0) ? "; " : "", - entries[i].merge_head->id_str)) < 0) - goto cleanup; - - entries[i].written = 1; - } - - if (i) - sep = ';'; - - if ((error = merge_msg_entries(&matching, entries, heads_len, msg_entry_is_branch)) < 0 || - (error = merge_msg_write_branches(&file, &matching, sep)) < 0) - goto cleanup; - - if (matching.length) - sep =','; - - if ((error = merge_msg_entries(&matching, entries, heads_len, msg_entry_is_tracking)) < 0 || - (error = merge_msg_write_tracking(&file, &matching, sep)) < 0) - goto cleanup; - - if (matching.length) - sep =','; - - if ((error = merge_msg_entries(&matching, entries, heads_len, msg_entry_is_tag)) < 0 || - (error = merge_msg_write_tags(&file, &matching, sep)) < 0) - goto cleanup; - - if (matching.length) - sep =','; - - /* We should never be called with multiple remote branches, but handle - * it in case we are... */ - while ((error = merge_msg_entries(&matching, entries, heads_len, msg_entry_is_remote)) > 0) { - if ((error = merge_msg_write_remotes(&file, &matching, sep)) < 0) - goto cleanup; - - if (matching.length) - sep =','; - } - - if (error < 0) - goto cleanup; - - for (i = 0; i < heads_len; i++) { - if (merge_msg_entry_written(&entries[i])) - continue; - - if ((error = git_filebuf_printf(&file, "; commit '%s'", - entries[i].merge_head->id_str)) < 0) - goto cleanup; - } - - if ((error = git_filebuf_printf(&file, "\n")) < 0 || - (error = git_filebuf_commit(&file)) < 0) - goto cleanup; - -cleanup: - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - git_vector_dispose(&matching); - git__free(entries); - - return error; -} - -int git_merge__setup( - git_repository *repo, - const git_annotated_commit *our_head, - const git_annotated_commit *heads[], - size_t heads_len) -{ - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(our_head); - GIT_ASSERT_ARG(heads); - - if ((error = git_repository__set_orig_head(repo, git_annotated_commit_id(our_head))) == 0 && - (error = write_merge_head(repo, heads, heads_len)) == 0 && - (error = write_merge_mode(repo)) == 0) { - error = write_merge_msg(repo, heads, heads_len); - } - - return error; -} - -/* Merge branches */ - -static int merge_ancestor_head( - git_annotated_commit **ancestor_head, - git_repository *repo, - const git_annotated_commit *our_head, - const git_annotated_commit **their_heads, - size_t their_heads_len) -{ - git_oid *oids, ancestor_oid; - size_t i, alloc_len; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(our_head); - GIT_ASSERT_ARG(their_heads); - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, their_heads_len, 1); - oids = git__calloc(alloc_len, sizeof(git_oid)); - GIT_ERROR_CHECK_ALLOC(oids); - - git_oid_cpy(&oids[0], git_commit_id(our_head->commit)); - - for (i = 0; i < their_heads_len; i++) - git_oid_cpy(&oids[i + 1], git_annotated_commit_id(their_heads[i])); - - if ((error = git_merge_base_many(&ancestor_oid, repo, their_heads_len + 1, oids)) < 0) - goto on_error; - - error = git_annotated_commit_lookup(ancestor_head, repo, &ancestor_oid); - -on_error: - git__free(oids); - return error; -} - -static const char *merge_their_label(const char *branchname) -{ - const char *slash; - - if ((slash = strrchr(branchname, '/')) == NULL) - return branchname; - - if (*(slash+1) == '\0') - return "theirs"; - - return slash+1; -} - -static int merge_normalize_checkout_opts( - git_checkout_options *out, - git_repository *repo, - const git_checkout_options *given_checkout_opts, - unsigned int checkout_strategy, - git_annotated_commit *ancestor, - const git_annotated_commit *our_head, - const git_annotated_commit **their_heads, - size_t their_heads_len) -{ - git_checkout_options default_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; - int error = 0; - - GIT_UNUSED(repo); - - if (given_checkout_opts != NULL) - memcpy(out, given_checkout_opts, sizeof(git_checkout_options)); - else - memcpy(out, &default_checkout_opts, sizeof(git_checkout_options)); - - out->checkout_strategy = checkout_strategy; - - if (!out->ancestor_label) { - if (ancestor && ancestor->type == GIT_ANNOTATED_COMMIT_REAL) - out->ancestor_label = git_commit_summary(ancestor->commit); - else if (ancestor) - out->ancestor_label = "merged common ancestors"; - else - out->ancestor_label = "empty base"; - } - - if (!out->our_label) { - if (our_head && our_head->ref_name) - out->our_label = our_head->ref_name; - else - out->our_label = "ours"; - } - - if (!out->their_label) { - if (their_heads_len == 1 && their_heads[0]->ref_name) - out->their_label = merge_their_label(their_heads[0]->ref_name); - else if (their_heads_len == 1) - out->their_label = their_heads[0]->id_str; - else - out->their_label = "theirs"; - } - - return error; -} - -static int merge_check_index(size_t *conflicts, git_repository *repo, git_index *index_new, git_vector *merged_paths) -{ - git_tree *head_tree = NULL; - git_index *index_repo = NULL; - git_iterator *iter_repo = NULL, *iter_new = NULL; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - git_diff *staged_diff_list = NULL, *index_diff_list = NULL; - git_diff_delta *delta; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_vector staged_paths = GIT_VECTOR_INIT; - size_t i; - int error = 0; - - GIT_UNUSED(merged_paths); - - *conflicts = 0; - - /* No staged changes may exist unless the change staged is identical to - * the result of the merge. This allows one to apply to merge manually, - * then run merge. Any other staged change would be overwritten by - * a reset merge. - */ - if ((error = git_repository_head_tree(&head_tree, repo)) < 0 || - (error = git_repository_index(&index_repo, repo)) < 0 || - (error = git_diff_tree_to_index(&staged_diff_list, repo, head_tree, index_repo, &opts)) < 0) - goto done; - - if (staged_diff_list->deltas.length == 0) - goto done; - - git_vector_foreach(&staged_diff_list->deltas, i, delta) { - if ((error = git_vector_insert(&staged_paths, (char *)delta->new_file.path)) < 0) - goto done; - } - - iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; - iter_opts.pathlist.strings = (char **)staged_paths.contents; - iter_opts.pathlist.count = staged_paths.length; - - if ((error = git_iterator_for_index(&iter_repo, repo, index_repo, &iter_opts)) < 0 || - (error = git_iterator_for_index(&iter_new, repo, index_new, &iter_opts)) < 0 || - (error = git_diff__from_iterators(&index_diff_list, repo, iter_repo, iter_new, &opts)) < 0) - goto done; - - *conflicts = index_diff_list->deltas.length; - -done: - git_tree_free(head_tree); - git_index_free(index_repo); - git_iterator_free(iter_repo); - git_iterator_free(iter_new); - git_diff_free(staged_diff_list); - git_diff_free(index_diff_list); - git_vector_dispose(&staged_paths); - - return error; -} - -static int merge_check_workdir(size_t *conflicts, git_repository *repo, git_index *index_new, git_vector *merged_paths) -{ - git_diff *wd_diff_list = NULL; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - int error = 0; - - GIT_UNUSED(index_new); - - *conflicts = 0; - - /* We need to have merged at least 1 file for the possibility to exist to - * have conflicts with the workdir. Passing 0 as the pathspec count parameter - * will consider all files in the working directory, that is, we may detect - * a conflict if there were untracked files in the workdir prior to starting - * the merge. This typically happens when cherry-picking a commit whose - * changes have already been applied. - */ - if (merged_paths->length == 0) - return 0; - - opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED; - - /* Workdir changes may exist iff they do not conflict with changes that - * will be applied by the merge (including conflicts). Ensure that there - * are no changes in the workdir to these paths. - */ - opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH; - opts.pathspec.count = merged_paths->length; - opts.pathspec.strings = (char **)merged_paths->contents; - opts.ignore_submodules = GIT_SUBMODULE_IGNORE_ALL; - - if ((error = git_diff_index_to_workdir(&wd_diff_list, repo, NULL, &opts)) < 0) - goto done; - - *conflicts = wd_diff_list->deltas.length; - -done: - git_diff_free(wd_diff_list); - - return error; -} - -int git_merge__check_result(git_repository *repo, git_index *index_new) -{ - git_tree *head_tree = NULL; - git_iterator *iter_head = NULL, *iter_new = NULL; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - git_diff *merged_list = NULL; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_delta *delta; - git_vector paths = GIT_VECTOR_INIT; - size_t i, index_conflicts = 0, wd_conflicts = 0, conflicts; - const git_index_entry *e; - int error = 0; - - iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; - - if ((error = git_repository_head_tree(&head_tree, repo)) < 0 || - (error = git_iterator_for_tree(&iter_head, head_tree, &iter_opts)) < 0 || - (error = git_iterator_for_index(&iter_new, repo, index_new, &iter_opts)) < 0 || - (error = git_diff__from_iterators(&merged_list, repo, iter_head, iter_new, &opts)) < 0) - goto done; - - git_vector_foreach(&merged_list->deltas, i, delta) { - if ((error = git_vector_insert(&paths, (char *)delta->new_file.path)) < 0) - goto done; - } - - for (i = 0; i < git_index_entrycount(index_new); i++) { - e = git_index_get_byindex(index_new, i); - - if (git_index_entry_is_conflict(e) && - (git_vector_last(&paths) == NULL || - strcmp(git_vector_last(&paths), e->path) != 0)) { - - if ((error = git_vector_insert(&paths, (char *)e->path)) < 0) - goto done; - } - } - - /* Make sure the index and workdir state do not prevent merging */ - if ((error = merge_check_index(&index_conflicts, repo, index_new, &paths)) < 0 || - (error = merge_check_workdir(&wd_conflicts, repo, index_new, &paths)) < 0) - goto done; - - if ((conflicts = index_conflicts + wd_conflicts) > 0) { - git_error_set(GIT_ERROR_MERGE, "%" PRIuZ " uncommitted change%s would be overwritten by merge", - conflicts, (conflicts != 1) ? "s" : ""); - error = GIT_ECONFLICT; - } - -done: - git_vector_dispose(&paths); - git_tree_free(head_tree); - git_iterator_free(iter_head); - git_iterator_free(iter_new); - git_diff_free(merged_list); - - return error; -} - -int git_merge__append_conflicts_to_merge_msg( - git_repository *repo, - git_index *index) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - const char *last = NULL; - size_t i; - int error; - - if (!git_index_has_conflicts(index)) - return 0; - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 || - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_APPEND, GIT_MERGE_FILE_MODE)) < 0) - goto cleanup; - - git_filebuf_printf(&file, "\n#Conflicts:\n"); - - for (i = 0; i < git_index_entrycount(index); i++) { - const git_index_entry *e = git_index_get_byindex(index, i); - - if (!git_index_entry_is_conflict(e)) - continue; - - if (last == NULL || strcmp(e->path, last) != 0) - git_filebuf_printf(&file, "#\t%s\n", e->path); - - last = e->path; - } - - error = git_filebuf_commit(&file); - -cleanup: - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - return error; -} - -static int merge_state_cleanup(git_repository *repo) -{ - const char *state_files[] = { - GIT_MERGE_HEAD_FILE, - GIT_MERGE_MODE_FILE, - GIT_MERGE_MSG_FILE, - }; - - return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files)); -} - -static int merge_heads( - git_annotated_commit **ancestor_head_out, - git_annotated_commit **our_head_out, - git_repository *repo, - git_reference *our_ref, - const git_annotated_commit **their_heads, - size_t their_heads_len) -{ - git_annotated_commit *ancestor_head = NULL, *our_head = NULL; - int error = 0; - - *ancestor_head_out = NULL; - *our_head_out = NULL; - - if ((error = git_annotated_commit_from_ref(&our_head, repo, our_ref)) < 0) - goto done; - - if ((error = merge_ancestor_head(&ancestor_head, repo, our_head, their_heads, their_heads_len)) < 0) { - if (error != GIT_ENOTFOUND) - goto done; - - git_error_clear(); - error = 0; - } - - *ancestor_head_out = ancestor_head; - *our_head_out = our_head; - -done: - if (error < 0) { - git_annotated_commit_free(ancestor_head); - git_annotated_commit_free(our_head); - } - - return error; -} - -static int merge_preference(git_merge_preference_t *out, git_repository *repo) -{ - git_config *config; - const char *value; - int bool_value, error = 0; - - *out = GIT_MERGE_PREFERENCE_NONE; - - if ((error = git_repository_config_snapshot(&config, repo)) < 0) - goto done; - - if ((error = git_config_get_string(&value, config, "merge.ff")) < 0) { - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - - goto done; - } - - if (git_config_parse_bool(&bool_value, value) == 0) { - if (!bool_value) - *out |= GIT_MERGE_PREFERENCE_NO_FASTFORWARD; - } else { - if (strcasecmp(value, "only") == 0) - *out |= GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY; - } - -done: - git_config_free(config); - return error; -} - -int git_merge_analysis_for_ref( - git_merge_analysis_t *analysis_out, - git_merge_preference_t *preference_out, - git_repository *repo, - git_reference *our_ref, - const git_annotated_commit **their_heads, - size_t their_heads_len) -{ - git_annotated_commit *ancestor_head = NULL, *our_head = NULL; - int error = 0; - bool unborn; - - GIT_ASSERT_ARG(analysis_out); - GIT_ASSERT_ARG(preference_out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(their_heads && their_heads_len > 0); - - if (their_heads_len != 1) { - git_error_set(GIT_ERROR_MERGE, "can only merge a single branch"); - error = -1; - goto done; - } - - *analysis_out = GIT_MERGE_ANALYSIS_NONE; - - if ((error = merge_preference(preference_out, repo)) < 0) - goto done; - - if ((error = git_reference__is_unborn_head(&unborn, our_ref, repo)) < 0) - goto done; - - if (unborn) { - *analysis_out |= GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_UNBORN; - error = 0; - goto done; - } - - if ((error = merge_heads(&ancestor_head, &our_head, repo, our_ref, their_heads, their_heads_len)) < 0) - goto done; - - /* We're up-to-date if we're trying to merge our own common ancestor. */ - if (ancestor_head && git_oid_equal( - git_annotated_commit_id(ancestor_head), git_annotated_commit_id(their_heads[0]))) - *analysis_out |= GIT_MERGE_ANALYSIS_UP_TO_DATE; - - /* We're fastforwardable if we're our own common ancestor. */ - else if (ancestor_head && git_oid_equal( - git_annotated_commit_id(ancestor_head), git_annotated_commit_id(our_head))) - *analysis_out |= GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_NORMAL; - - /* Otherwise, just a normal merge is possible. */ - else - *analysis_out |= GIT_MERGE_ANALYSIS_NORMAL; - -done: - git_annotated_commit_free(ancestor_head); - git_annotated_commit_free(our_head); - return error; -} - -int git_merge_analysis( - git_merge_analysis_t *analysis_out, - git_merge_preference_t *preference_out, - git_repository *repo, - const git_annotated_commit **their_heads, - size_t their_heads_len) -{ - git_reference *head_ref = NULL; - int error = 0; - - if ((error = git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE)) < 0) { - git_error_set(GIT_ERROR_MERGE, "failed to lookup HEAD reference"); - return error; - } - - error = git_merge_analysis_for_ref(analysis_out, preference_out, repo, head_ref, their_heads, their_heads_len); - - git_reference_free(head_ref); - - return error; -} - -int git_merge( - git_repository *repo, - const git_annotated_commit **their_heads, - size_t their_heads_len, - const git_merge_options *merge_opts, - const git_checkout_options *given_checkout_opts) -{ - git_reference *our_ref = NULL; - git_checkout_options checkout_opts; - git_annotated_commit *our_head = NULL, *base = NULL; - git_index *repo_index = NULL, *index = NULL; - git_indexwriter indexwriter = GIT_INDEXWRITER_INIT; - unsigned int checkout_strategy; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(their_heads && their_heads_len > 0); - - if (their_heads_len != 1) { - git_error_set(GIT_ERROR_MERGE, "can only merge a single branch"); - return -1; - } - - if ((error = git_repository__ensure_not_bare(repo, "merge")) < 0) - goto done; - - checkout_strategy = given_checkout_opts ? - given_checkout_opts->checkout_strategy : 0; - - if ((error = git_indexwriter_init_for_operation(&indexwriter, repo, - &checkout_strategy)) < 0) - goto done; - - if ((error = git_repository_index(&repo_index, repo) < 0) || - (error = git_index_read(repo_index, 0) < 0)) - goto done; - - /* Write the merge setup files to the repository. */ - if ((error = git_annotated_commit_from_head(&our_head, repo)) < 0 || - (error = git_merge__setup(repo, our_head, their_heads, - their_heads_len)) < 0) - goto done; - - /* TODO: octopus */ - - if ((error = merge_annotated_commits(&index, &base, repo, our_head, - (git_annotated_commit *)their_heads[0], 0, merge_opts)) < 0 || - (error = git_merge__check_result(repo, index)) < 0 || - (error = git_merge__append_conflicts_to_merge_msg(repo, index)) < 0) - goto done; - - /* check out the merge results */ - - if ((error = merge_normalize_checkout_opts(&checkout_opts, repo, - given_checkout_opts, checkout_strategy, - base, our_head, their_heads, their_heads_len)) < 0 || - (error = git_checkout_index(repo, index, &checkout_opts)) < 0) - goto done; - - error = git_indexwriter_commit(&indexwriter); - -done: - if (error < 0) - merge_state_cleanup(repo); - - git_indexwriter_cleanup(&indexwriter); - git_index_free(index); - git_annotated_commit_free(our_head); - git_annotated_commit_free(base); - git_reference_free(our_ref); - git_index_free(repo_index); - - return error; -} - -int git_merge_options_init(git_merge_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_merge_options, GIT_MERGE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_merge_init_options(git_merge_options *opts, unsigned int version) -{ - return git_merge_options_init(opts, version); -} -#endif - -int git_merge_file_input_init(git_merge_file_input *input, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - input, version, git_merge_file_input, GIT_MERGE_FILE_INPUT_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_merge_file_init_input(git_merge_file_input *input, unsigned int version) -{ - return git_merge_file_input_init(input, version); -} -#endif - -int git_merge_file_options_init( - git_merge_file_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_merge_file_options, GIT_MERGE_FILE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_merge_file_init_options( - git_merge_file_options *opts, unsigned int version) -{ - return git_merge_file_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/merge.h b/vendor/libgit2-sys/libgit2/src/libgit2/merge.h deleted file mode 100644 index fca9c20..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/merge.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_merge_h__ -#define INCLUDE_merge_h__ - -#include "common.h" - -#include "vector.h" -#include "commit_list.h" -#include "pool.h" -#include "iterator.h" - -#include "git2/types.h" -#include "git2/merge.h" -#include "git2/sys/merge.h" - -#define GIT_MERGE_MSG_FILE "MERGE_MSG" -#define GIT_MERGE_MODE_FILE "MERGE_MODE" -#define GIT_MERGE_FILE_MODE 0666 - -#define GIT_MERGE_DEFAULT_RENAME_THRESHOLD 50 -#define GIT_MERGE_DEFAULT_TARGET_LIMIT 1000 - -/** Types of changes when files are merged from branch to branch. */ -typedef enum { - /* No conflict - a change only occurs in one branch. */ - GIT_MERGE_DIFF_NONE = 0, - - /* Occurs when a file is modified in both branches. */ - GIT_MERGE_DIFF_BOTH_MODIFIED = (1 << 0), - - /* Occurs when a file is added in both branches. */ - GIT_MERGE_DIFF_BOTH_ADDED = (1 << 1), - - /* Occurs when a file is deleted in both branches. */ - GIT_MERGE_DIFF_BOTH_DELETED = (1 << 2), - - /* Occurs when a file is modified in one branch and deleted in the other. */ - GIT_MERGE_DIFF_MODIFIED_DELETED = (1 << 3), - - /* Occurs when a file is renamed in one branch and modified in the other. */ - GIT_MERGE_DIFF_RENAMED_MODIFIED = (1 << 4), - - /* Occurs when a file is renamed in one branch and deleted in the other. */ - GIT_MERGE_DIFF_RENAMED_DELETED = (1 << 5), - - /* Occurs when a file is renamed in one branch and a file with the same - * name is added in the other. Eg, A->B and new file B. Core git calls - * this a "rename/delete". */ - GIT_MERGE_DIFF_RENAMED_ADDED = (1 << 6), - - /* Occurs when both a file is renamed to the same name in the ours and - * theirs branches. Eg, A->B and A->B in both. Automergeable. */ - GIT_MERGE_DIFF_BOTH_RENAMED = (1 << 7), - - /* Occurs when a file is renamed to different names in the ours and theirs - * branches. Eg, A->B and A->C. */ - GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2 = (1 << 8), - - /* Occurs when two files are renamed to the same name in the ours and - * theirs branches. Eg, A->C and B->C. */ - GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1 = (1 << 9), - - /* Occurs when an item at a path in one branch is a directory, and an - * item at the same path in a different branch is a file. */ - GIT_MERGE_DIFF_DIRECTORY_FILE = (1 << 10), - - /* The child of a folder that is in a directory/file conflict. */ - GIT_MERGE_DIFF_DF_CHILD = (1 << 11) -} git_merge_diff_t; - -typedef struct { - git_repository *repo; - git_pool pool; - - /* Vector of git_index_entry that represent the merged items that - * have been staged, either because only one side changed, or because - * the two changes were non-conflicting and mergeable. These items - * will be written as staged entries in the main index. - */ - git_vector staged; - - /* Vector of git_merge_diff entries that represent the conflicts that - * have not been automerged. These items will be written to high-stage - * entries in the main index. - */ - git_vector conflicts; - - /* Vector of git_merge_diff that have been automerged. These items - * will be written to the REUC when the index is produced. - */ - git_vector resolved; -} git_merge_diff_list; - -/** - * Description of changes to one file across three trees. - */ -typedef struct { - git_merge_diff_t type; - - git_index_entry ancestor_entry; - - git_index_entry our_entry; - git_delta_t our_status; - - git_index_entry their_entry; - git_delta_t their_status; - -} git_merge_diff; - -int git_merge__bases_many( - git_commit_list **out, - git_revwalk *walk, - git_commit_list_node *one, - git_vector *twos, - uint32_t minimum_generation); - -/* - * Three-way tree differencing - */ - -git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo); - -int git_merge_diff_list__find_differences( - git_merge_diff_list *merge_diff_list, - git_iterator *ancestor_iterator, - git_iterator *ours_iter, - git_iterator *theirs_iter); - -int git_merge_diff_list__find_renames(git_repository *repo, git_merge_diff_list *merge_diff_list, const git_merge_options *opts); - -void git_merge_diff_list__free(git_merge_diff_list *diff_list); - -/* Merge metadata setup */ - -int git_merge__setup( - git_repository *repo, - const git_annotated_commit *our_head, - const git_annotated_commit *heads[], - size_t heads_len); - -int git_merge__iterators( - git_index **out, - git_repository *repo, - git_iterator *ancestor_iter, - git_iterator *our_iter, - git_iterator *their_iter, - const git_merge_options *given_opts); - -int git_merge__check_result(git_repository *repo, git_index *index_new); - -int git_merge__append_conflicts_to_merge_msg(git_repository *repo, git_index *index); - -/* Merge files */ - -GIT_INLINE(const char *) git_merge_file__best_path( - const char *ancestor, - const char *ours, - const char *theirs) -{ - if (!ancestor) { - if (ours && theirs && strcmp(ours, theirs) == 0) - return ours; - if (ours && !theirs) - return ours; - if (theirs && !ours) - return theirs; - - return NULL; - } - - if (ours && strcmp(ancestor, ours) == 0) - return theirs; - else if(theirs && strcmp(ancestor, theirs) == 0) - return ours; - - return NULL; -} - -GIT_INLINE(uint32_t) git_merge_file__best_mode( - uint32_t ancestor, uint32_t ours, uint32_t theirs) -{ - /* - * If ancestor didn't exist and either ours or theirs is executable, - * assume executable. Otherwise, if any mode changed from the ancestor, - * use that one. - */ - if (!ancestor) { - if (ours == GIT_FILEMODE_BLOB_EXECUTABLE || - theirs == GIT_FILEMODE_BLOB_EXECUTABLE) - return GIT_FILEMODE_BLOB_EXECUTABLE; - - return GIT_FILEMODE_BLOB; - } else if (ours && theirs) { - if (ancestor == ours) - return theirs; - - return ours; - } - - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/merge_driver.c b/vendor/libgit2-sys/libgit2/src/libgit2/merge_driver.c deleted file mode 100644 index 300964a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/merge_driver.c +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "merge_driver.h" - -#include "vector.h" -#include "runtime.h" -#include "merge.h" -#include "git2/merge.h" -#include "git2/sys/merge.h" - -static const char *merge_driver_name__text = "text"; -static const char *merge_driver_name__union = "union"; -static const char *merge_driver_name__binary = "binary"; - -struct merge_driver_registry { - git_rwlock lock; - git_vector drivers; -}; - -typedef struct { - git_merge_driver *driver; - int initialized; - char name[GIT_FLEX_ARRAY]; -} git_merge_driver_entry; - -static struct merge_driver_registry merge_driver_registry; - -static void git_merge_driver_global_shutdown(void); - -git_repository *git_merge_driver_source_repo( - const git_merge_driver_source *src) -{ - GIT_ASSERT_ARG_WITH_RETVAL(src, NULL); - return src->repo; -} - -const git_index_entry *git_merge_driver_source_ancestor( - const git_merge_driver_source *src) -{ - GIT_ASSERT_ARG_WITH_RETVAL(src, NULL); - return src->ancestor; -} - -const git_index_entry *git_merge_driver_source_ours( - const git_merge_driver_source *src) -{ - GIT_ASSERT_ARG_WITH_RETVAL(src, NULL); - return src->ours; -} - -const git_index_entry *git_merge_driver_source_theirs( - const git_merge_driver_source *src) -{ - GIT_ASSERT_ARG_WITH_RETVAL(src, NULL); - return src->theirs; -} - -const git_merge_file_options *git_merge_driver_source_file_options( - const git_merge_driver_source *src) -{ - GIT_ASSERT_ARG_WITH_RETVAL(src, NULL); - return src->file_opts; -} - -int git_merge_driver__builtin_apply( - git_merge_driver *self, - const char **path_out, - uint32_t *mode_out, - git_buf *merged_out, - const char *filter_name, - const git_merge_driver_source *src) -{ - git_merge_driver__builtin *driver = (git_merge_driver__builtin *)self; - git_merge_file_options file_opts = GIT_MERGE_FILE_OPTIONS_INIT; - git_merge_file_result result = {0}; - int error; - - GIT_UNUSED(filter_name); - - if (src->file_opts) - memcpy(&file_opts, src->file_opts, sizeof(git_merge_file_options)); - - if (driver->favor) - file_opts.favor = driver->favor; - - if ((error = git_merge_file_from_index(&result, src->repo, - src->ancestor, src->ours, src->theirs, &file_opts)) < 0) - goto done; - - if (!result.automergeable && - !(file_opts.flags & GIT_MERGE_FILE_ACCEPT_CONFLICTS)) { - error = GIT_EMERGECONFLICT; - goto done; - } - - *path_out = git_merge_file__best_path( - src->ancestor ? src->ancestor->path : NULL, - src->ours ? src->ours->path : NULL, - src->theirs ? src->theirs->path : NULL); - - *mode_out = git_merge_file__best_mode( - src->ancestor ? src->ancestor->mode : 0, - src->ours ? src->ours->mode : 0, - src->theirs ? src->theirs->mode : 0); - - merged_out->ptr = (char *)result.ptr; - merged_out->size = result.len; - merged_out->reserved = 0; - result.ptr = NULL; - -done: - git_merge_file_result_free(&result); - return error; -} - -static int merge_driver_binary_apply( - git_merge_driver *self, - const char **path_out, - uint32_t *mode_out, - git_buf *merged_out, - const char *filter_name, - const git_merge_driver_source *src) -{ - GIT_UNUSED(self); - GIT_UNUSED(path_out); - GIT_UNUSED(mode_out); - GIT_UNUSED(merged_out); - GIT_UNUSED(filter_name); - GIT_UNUSED(src); - - return GIT_EMERGECONFLICT; -} - -static int merge_driver_entry_cmp(const void *a, const void *b) -{ - const git_merge_driver_entry *entry_a = a; - const git_merge_driver_entry *entry_b = b; - - return strcmp(entry_a->name, entry_b->name); -} - -static int merge_driver_entry_search(const void *a, const void *b) -{ - const char *name_a = a; - const git_merge_driver_entry *entry_b = b; - - return strcmp(name_a, entry_b->name); -} - -git_merge_driver__builtin git_merge_driver__text = { - { - GIT_MERGE_DRIVER_VERSION, - NULL, - NULL, - git_merge_driver__builtin_apply, - }, - GIT_MERGE_FILE_FAVOR_NORMAL -}; - -git_merge_driver__builtin git_merge_driver__union = { - { - GIT_MERGE_DRIVER_VERSION, - NULL, - NULL, - git_merge_driver__builtin_apply, - }, - GIT_MERGE_FILE_FAVOR_UNION -}; - -git_merge_driver git_merge_driver__binary = { - GIT_MERGE_DRIVER_VERSION, - NULL, - NULL, - merge_driver_binary_apply -}; - -/* Note: callers must lock the registry before calling this function */ -static int merge_driver_registry_insert( - const char *name, git_merge_driver *driver) -{ - git_merge_driver_entry *entry; - - entry = git__calloc(1, sizeof(git_merge_driver_entry) + strlen(name) + 1); - GIT_ERROR_CHECK_ALLOC(entry); - - strcpy(entry->name, name); - entry->driver = driver; - - return git_vector_insert_sorted( - &merge_driver_registry.drivers, entry, NULL); -} - -int git_merge_driver_global_init(void) -{ - int error; - - if (git_rwlock_init(&merge_driver_registry.lock) < 0) - return -1; - - if ((error = git_vector_init(&merge_driver_registry.drivers, 3, - merge_driver_entry_cmp)) < 0) - goto done; - - if ((error = merge_driver_registry_insert( - merge_driver_name__text, &git_merge_driver__text.base)) < 0 || - (error = merge_driver_registry_insert( - merge_driver_name__union, &git_merge_driver__union.base)) < 0 || - (error = merge_driver_registry_insert( - merge_driver_name__binary, &git_merge_driver__binary)) < 0) - goto done; - - error = git_runtime_shutdown_register(git_merge_driver_global_shutdown); - -done: - if (error < 0) - git_vector_dispose_deep(&merge_driver_registry.drivers); - - return error; -} - -static void git_merge_driver_global_shutdown(void) -{ - git_merge_driver_entry *entry; - size_t i; - - if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0) - return; - - git_vector_foreach(&merge_driver_registry.drivers, i, entry) { - if (entry->driver->shutdown) - entry->driver->shutdown(entry->driver); - - git__free(entry); - } - - git_vector_dispose(&merge_driver_registry.drivers); - - git_rwlock_wrunlock(&merge_driver_registry.lock); - git_rwlock_free(&merge_driver_registry.lock); -} - -/* Note: callers must lock the registry before calling this function */ -static int merge_driver_registry_find(size_t *pos, const char *name) -{ - return git_vector_search2(pos, &merge_driver_registry.drivers, - merge_driver_entry_search, name); -} - -/* Note: callers must lock the registry before calling this function */ -static git_merge_driver_entry *merge_driver_registry_lookup( - size_t *pos, const char *name) -{ - git_merge_driver_entry *entry = NULL; - - if (!merge_driver_registry_find(pos, name)) - entry = git_vector_get(&merge_driver_registry.drivers, *pos); - - return entry; -} - -int git_merge_driver_register(const char *name, git_merge_driver *driver) -{ - int error; - - GIT_ASSERT_ARG(name); - GIT_ASSERT_ARG(driver); - - if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock merge driver registry"); - return -1; - } - - if (!merge_driver_registry_find(NULL, name)) { - git_error_set(GIT_ERROR_MERGE, "attempt to reregister existing driver '%s'", - name); - error = GIT_EEXISTS; - goto done; - } - - error = merge_driver_registry_insert(name, driver); - -done: - git_rwlock_wrunlock(&merge_driver_registry.lock); - return error; -} - -int git_merge_driver_unregister(const char *name) -{ - git_merge_driver_entry *entry; - size_t pos; - int error = 0; - - if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock merge driver registry"); - return -1; - } - - if ((entry = merge_driver_registry_lookup(&pos, name)) == NULL) { - git_error_set(GIT_ERROR_MERGE, "cannot find merge driver '%s' to unregister", - name); - error = GIT_ENOTFOUND; - goto done; - } - - git_vector_remove(&merge_driver_registry.drivers, pos); - - if (entry->initialized && entry->driver->shutdown) { - entry->driver->shutdown(entry->driver); - entry->initialized = false; - } - - git__free(entry); - -done: - git_rwlock_wrunlock(&merge_driver_registry.lock); - return error; -} - -git_merge_driver *git_merge_driver_lookup(const char *name) -{ - git_merge_driver_entry *entry; - size_t pos; - int error; - - /* If we've decided the merge driver to use internally - and not - * based on user configuration (in merge_driver_name_for_path) - * then we can use a hardcoded name to compare instead of bothering - * to take a lock and look it up in the vector. - */ - if (name == merge_driver_name__text) - return &git_merge_driver__text.base; - else if (name == merge_driver_name__binary) - return &git_merge_driver__binary; - - if (git_rwlock_rdlock(&merge_driver_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock merge driver registry"); - return NULL; - } - - entry = merge_driver_registry_lookup(&pos, name); - - git_rwlock_rdunlock(&merge_driver_registry.lock); - - if (entry == NULL) { - git_error_set(GIT_ERROR_MERGE, "cannot use an unregistered filter"); - return NULL; - } - - if (!entry->initialized) { - if (entry->driver->initialize && - (error = entry->driver->initialize(entry->driver)) < 0) - return NULL; - - entry->initialized = 1; - } - - return entry->driver; -} - -static int merge_driver_name_for_path( - const char **out, - git_repository *repo, - const char *path, - const char *default_driver) -{ - const char *value; - int error; - - *out = NULL; - - if ((error = git_attr_get(&value, repo, 0, path, "merge")) < 0) - return error; - - /* set: use the built-in 3-way merge driver ("text") */ - if (GIT_ATTR_IS_TRUE(value)) - *out = merge_driver_name__text; - - /* unset: do not merge ("binary") */ - else if (GIT_ATTR_IS_FALSE(value)) - *out = merge_driver_name__binary; - - else if (GIT_ATTR_IS_UNSPECIFIED(value) && default_driver) - *out = default_driver; - - else if (GIT_ATTR_IS_UNSPECIFIED(value)) - *out = merge_driver_name__text; - - else - *out = value; - - return 0; -} - - -GIT_INLINE(git_merge_driver *) merge_driver_lookup_with_wildcard( - const char *name) -{ - git_merge_driver *driver = git_merge_driver_lookup(name); - - if (driver == NULL) - driver = git_merge_driver_lookup("*"); - - return driver; -} - -int git_merge_driver_for_source( - const char **name_out, - git_merge_driver **driver_out, - const git_merge_driver_source *src) -{ - const char *path, *driver_name; - int error = 0; - - path = git_merge_file__best_path( - src->ancestor ? src->ancestor->path : NULL, - src->ours ? src->ours->path : NULL, - src->theirs ? src->theirs->path : NULL); - - if ((error = merge_driver_name_for_path( - &driver_name, src->repo, path, src->default_driver)) < 0) - return error; - - *name_out = driver_name; - *driver_out = merge_driver_lookup_with_wildcard(driver_name); - return error; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/merge_driver.h b/vendor/libgit2-sys/libgit2/src/libgit2/merge_driver.h deleted file mode 100644 index 6b7da52..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/merge_driver.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_merge_driver_h__ -#define INCLUDE_merge_driver_h__ - -#include "common.h" - -#include "git2/merge.h" -#include "git2/index.h" -#include "git2/sys/merge.h" - -struct git_merge_driver_source { - git_repository *repo; - const char *default_driver; - const git_merge_file_options *file_opts; - - const git_index_entry *ancestor; - const git_index_entry *ours; - const git_index_entry *theirs; -}; - -typedef struct git_merge_driver__builtin { - git_merge_driver base; - git_merge_file_favor_t favor; -} git_merge_driver__builtin; - -extern int git_merge_driver_global_init(void); - -extern int git_merge_driver_for_path( - char **name_out, - git_merge_driver **driver_out, - git_repository *repo, - const char *path); - -/* Merge driver configuration */ -extern int git_merge_driver_for_source( - const char **name_out, - git_merge_driver **driver_out, - const git_merge_driver_source *src); - -extern int git_merge_driver__builtin_apply( - git_merge_driver *self, - const char **path_out, - uint32_t *mode_out, - git_buf *merged_out, - const char *filter_name, - const git_merge_driver_source *src); - -/* Merge driver for text files, performs a standard three-way merge */ -extern git_merge_driver__builtin git_merge_driver__text; - -/* Merge driver for union-style merging */ -extern git_merge_driver__builtin git_merge_driver__union; - -/* Merge driver for unmergeable (binary) files: always produces conflicts */ -extern git_merge_driver git_merge_driver__binary; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/merge_file.c b/vendor/libgit2-sys/libgit2/src/libgit2/merge_file.c deleted file mode 100644 index f6c2193..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/merge_file.c +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "repository.h" -#include "posix.h" -#include "futils.h" -#include "index.h" -#include "diff_xdiff.h" -#include "merge.h" - -#include "git2/repository.h" -#include "git2/object.h" -#include "git2/index.h" -#include "git2/merge.h" - -/* only examine the first 8000 bytes for binaryness. - * https://github.com/git/git/blob/77bd3ea9f54f1584147b594abc04c26ca516d987/xdiff-interface.c#L197 - */ -#define GIT_MERGE_FILE_BINARY_SIZE 8000 - -#define GIT_MERGE_FILE_SIDE_EXISTS(X) ((X)->mode != 0) - -static int merge_file_input_from_index( - git_merge_file_input *input_out, - git_odb_object **odb_object_out, - git_odb *odb, - const git_index_entry *entry) -{ - int error = 0; - - GIT_ASSERT_ARG(input_out); - GIT_ASSERT_ARG(odb_object_out); - GIT_ASSERT_ARG(odb); - GIT_ASSERT_ARG(entry); - - if ((error = git_odb_read(odb_object_out, odb, &entry->id)) < 0) - goto done; - - input_out->path = entry->path; - input_out->mode = entry->mode; - input_out->ptr = (char *)git_odb_object_data(*odb_object_out); - input_out->size = git_odb_object_size(*odb_object_out); - -done: - return error; -} - -static void merge_file_normalize_opts( - git_merge_file_options *out, - const git_merge_file_options *given_opts) -{ - if (given_opts) - memcpy(out, given_opts, sizeof(git_merge_file_options)); - else { - git_merge_file_options default_opts = GIT_MERGE_FILE_OPTIONS_INIT; - memcpy(out, &default_opts, sizeof(git_merge_file_options)); - } -} - -static int merge_file__xdiff( - git_merge_file_result *out, - const git_merge_file_input *ancestor, - const git_merge_file_input *ours, - const git_merge_file_input *theirs, - const git_merge_file_options *given_opts) -{ - xmparam_t xmparam; - mmfile_t ancestor_mmfile = {0}, our_mmfile = {0}, their_mmfile = {0}; - mmbuffer_t mmbuffer; - git_merge_file_options options = GIT_MERGE_FILE_OPTIONS_INIT; - const char *path; - int xdl_result; - int error = 0; - - memset(out, 0x0, sizeof(git_merge_file_result)); - - merge_file_normalize_opts(&options, given_opts); - - memset(&xmparam, 0x0, sizeof(xmparam_t)); - - if ((ours && ours->size > LONG_MAX) || - (theirs && theirs->size > LONG_MAX) || - (ancestor && ancestor->size > LONG_MAX)) { - git_error_set(GIT_ERROR_MERGE, "failed to merge files"); - error = -1; - goto done; - } - - if (ancestor && ancestor->size) { - xmparam.ancestor = (options.ancestor_label) ? - options.ancestor_label : ancestor->path; - ancestor_mmfile.ptr = (char *)ancestor->ptr; - ancestor_mmfile.size = (long)ancestor->size; - } - - if (ours && ours->size) { - xmparam.file1 = (options.our_label) ? - options.our_label : ours->path; - our_mmfile.ptr = (char *)ours->ptr; - our_mmfile.size = (long)ours->size; - } - - if (theirs && theirs->size) { - xmparam.file2 = (options.their_label) ? - options.their_label : theirs->path; - their_mmfile.ptr = (char *)theirs->ptr; - their_mmfile.size = (long)theirs->size; - } - - if (options.favor == GIT_MERGE_FILE_FAVOR_OURS) - xmparam.favor = XDL_MERGE_FAVOR_OURS; - else if (options.favor == GIT_MERGE_FILE_FAVOR_THEIRS) - xmparam.favor = XDL_MERGE_FAVOR_THEIRS; - else if (options.favor == GIT_MERGE_FILE_FAVOR_UNION) - xmparam.favor = XDL_MERGE_FAVOR_UNION; - - xmparam.level = (options.flags & GIT_MERGE_FILE_SIMPLIFY_ALNUM) ? - XDL_MERGE_ZEALOUS_ALNUM : XDL_MERGE_ZEALOUS; - - if (options.flags & GIT_MERGE_FILE_STYLE_DIFF3) - xmparam.style = XDL_MERGE_DIFF3; - if (options.flags & GIT_MERGE_FILE_STYLE_ZDIFF3) - xmparam.style = XDL_MERGE_ZEALOUS_DIFF3; - - if (options.flags & GIT_MERGE_FILE_IGNORE_WHITESPACE) - xmparam.xpp.flags |= XDF_IGNORE_WHITESPACE; - if (options.flags & GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE) - xmparam.xpp.flags |= XDF_IGNORE_WHITESPACE_CHANGE; - if (options.flags & GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL) - xmparam.xpp.flags |= XDF_IGNORE_WHITESPACE_AT_EOL; - - if (options.flags & GIT_MERGE_FILE_DIFF_PATIENCE) - xmparam.xpp.flags |= XDF_PATIENCE_DIFF; - - if (options.flags & GIT_MERGE_FILE_DIFF_MINIMAL) - xmparam.xpp.flags |= XDF_NEED_MINIMAL; - - xmparam.marker_size = options.marker_size; - - if ((xdl_result = xdl_merge(&ancestor_mmfile, &our_mmfile, - &their_mmfile, &xmparam, &mmbuffer)) < 0) { - git_error_set(GIT_ERROR_MERGE, "failed to merge files"); - error = -1; - goto done; - } - - path = git_merge_file__best_path( - ancestor ? ancestor->path : NULL, - ours ? ours->path : NULL, - theirs ? theirs->path : NULL); - - if (path != NULL && (out->path = git__strdup(path)) == NULL) { - error = -1; - goto done; - } - - out->automergeable = (xdl_result == 0); - out->ptr = (const char *)mmbuffer.ptr; - out->len = mmbuffer.size; - out->mode = git_merge_file__best_mode( - ancestor ? ancestor->mode : 0, - ours ? ours->mode : 0, - theirs ? theirs->mode : 0); - -done: - if (error < 0) - git_merge_file_result_free(out); - - return error; -} - -static bool merge_file__is_binary(const git_merge_file_input *file) -{ - size_t len = file ? file->size : 0; - - if (len > GIT_XDIFF_MAX_SIZE) - return true; - if (len > GIT_MERGE_FILE_BINARY_SIZE) - len = GIT_MERGE_FILE_BINARY_SIZE; - - return len ? (memchr(file->ptr, 0, len) != NULL) : false; -} - -static int merge_file__binary( - git_merge_file_result *out, - const git_merge_file_input *ours, - const git_merge_file_input *theirs, - const git_merge_file_options *given_opts) -{ - const git_merge_file_input *favored = NULL; - - memset(out, 0x0, sizeof(git_merge_file_result)); - - if (given_opts && given_opts->favor == GIT_MERGE_FILE_FAVOR_OURS) - favored = ours; - else if (given_opts && given_opts->favor == GIT_MERGE_FILE_FAVOR_THEIRS) - favored = theirs; - else - goto done; - - if ((out->path = git__strdup(favored->path)) == NULL || - (out->ptr = git__malloc(favored->size)) == NULL) - goto done; - - memcpy((char *)out->ptr, favored->ptr, favored->size); - out->len = favored->size; - out->mode = favored->mode; - out->automergeable = 1; - -done: - return 0; -} - -static int merge_file__from_inputs( - git_merge_file_result *out, - const git_merge_file_input *ancestor, - const git_merge_file_input *ours, - const git_merge_file_input *theirs, - const git_merge_file_options *given_opts) -{ - if (merge_file__is_binary(ancestor) || - merge_file__is_binary(ours) || - merge_file__is_binary(theirs)) - return merge_file__binary(out, ours, theirs, given_opts); - - return merge_file__xdiff(out, ancestor, ours, theirs, given_opts); -} - -static git_merge_file_input *git_merge_file__normalize_inputs( - git_merge_file_input *out, - const git_merge_file_input *given) -{ - memcpy(out, given, sizeof(git_merge_file_input)); - - if (!out->path) - out->path = "file.txt"; - - if (!out->mode) - out->mode = 0100644; - - return out; -} - -int git_merge_file( - git_merge_file_result *out, - const git_merge_file_input *ancestor, - const git_merge_file_input *ours, - const git_merge_file_input *theirs, - const git_merge_file_options *options) -{ - git_merge_file_input inputs[3] = { {0} }; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(ours); - GIT_ASSERT_ARG(theirs); - - memset(out, 0x0, sizeof(git_merge_file_result)); - - if (ancestor) - ancestor = git_merge_file__normalize_inputs(&inputs[0], ancestor); - - if (ours) - ours = git_merge_file__normalize_inputs(&inputs[1], ours); - - if (theirs) - theirs = git_merge_file__normalize_inputs(&inputs[2], theirs); - - return merge_file__from_inputs(out, ancestor, ours, theirs, options); -} - -int git_merge_file_from_index( - git_merge_file_result *out, - git_repository *repo, - const git_index_entry *ancestor, - const git_index_entry *ours, - const git_index_entry *theirs, - const git_merge_file_options *options) -{ - git_merge_file_input ancestor_input = {0}; - git_merge_file_input our_input = {0}; - git_merge_file_input their_input = {0}; - git_odb *odb; - git_odb_object *odb_object[3] = { 0 }; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(ancestor || ours || theirs); - - memset(out, 0x0, sizeof(git_merge_file_result)); - - if ((error = git_repository_odb(&odb, repo)) < 0) - goto done; - - if (ancestor) { - if ((error = merge_file_input_from_index( - &ancestor_input, &odb_object[0], odb, ancestor)) < 0) - goto done; - } - - if (ours) { - if ((error = merge_file_input_from_index( - &our_input, &odb_object[1], odb, ours)) < 0) - goto done; - } - - if (theirs) { - if ((error = merge_file_input_from_index( - &their_input, &odb_object[2], odb, theirs)) < 0) - goto done; - } - - error = merge_file__from_inputs(out, - &ancestor_input, &our_input, &their_input, options); - -done: - git_odb_object_free(odb_object[0]); - git_odb_object_free(odb_object[1]); - git_odb_object_free(odb_object[2]); - git_odb_free(odb); - - return error; -} - -void git_merge_file_result_free(git_merge_file_result *result) -{ - if (result == NULL) - return; - - git__free((char *)result->path); - git__free((char *)result->ptr); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/message.c b/vendor/libgit2-sys/libgit2/src/libgit2/message.c deleted file mode 100644 index fe0000a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/message.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "buf.h" - -#include "git2/message.h" - -static size_t line_length_without_trailing_spaces(const char *line, size_t len) -{ - while (len) { - unsigned char c = line[len - 1]; - if (!git__isspace(c)) - break; - len--; - } - - return len; -} - -/* Greatly inspired from git.git "stripspace" */ -/* see https://github.com/git/git/blob/497215d8811ac7b8955693ceaad0899ecd894ed2/builtin/stripspace.c#L4-67 */ -static int git_message__prettify( - git_str *message_out, - const char *message, - int strip_comments, - char comment_char) -{ - const size_t message_len = strlen(message); - - int consecutive_empty_lines = 0; - size_t i, line_length, rtrimmed_line_length; - const char *next_newline; - - for (i = 0; i < strlen(message); i += line_length) { - next_newline = memchr(message + i, '\n', message_len - i); - - if (next_newline != NULL) { - line_length = next_newline - (message + i) + 1; - } else { - line_length = message_len - i; - } - - if (strip_comments && line_length && message[i] == comment_char) - continue; - - rtrimmed_line_length = line_length_without_trailing_spaces(message + i, line_length); - - if (!rtrimmed_line_length) { - consecutive_empty_lines++; - continue; - } - - if (consecutive_empty_lines > 0 && message_out->size > 0) - git_str_putc(message_out, '\n'); - - consecutive_empty_lines = 0; - git_str_put(message_out, message + i, rtrimmed_line_length); - git_str_putc(message_out, '\n'); - } - - return git_str_oom(message_out) ? -1 : 0; -} - -int git_message_prettify( - git_buf *message_out, - const char *message, - int strip_comments, - char comment_char) -{ - GIT_BUF_WRAP_PRIVATE(message_out, git_message__prettify, message, strip_comments, comment_char); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/midx.c b/vendor/libgit2-sys/libgit2/src/libgit2/midx.c deleted file mode 100644 index 6d90e4a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/midx.c +++ /dev/null @@ -1,940 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "midx.h" - -#include "array.h" -#include "buf.h" -#include "filebuf.h" -#include "futils.h" -#include "hash.h" -#include "odb.h" -#include "pack.h" -#include "fs_path.h" -#include "repository.h" -#include "str.h" - -#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */ -#define MIDX_VERSION 1 -#define MIDX_OBJECT_ID_VERSION 1 -struct git_midx_header { - uint32_t signature; - uint8_t version; - uint8_t object_id_version; - uint8_t chunks; - uint8_t base_midx_files; - uint32_t packfiles; -}; - -#define MIDX_PACKFILE_NAMES_ID 0x504e414d /* "PNAM" */ -#define MIDX_OID_FANOUT_ID 0x4f494446 /* "OIDF" */ -#define MIDX_OID_LOOKUP_ID 0x4f49444c /* "OIDL" */ -#define MIDX_OBJECT_OFFSETS_ID 0x4f4f4646 /* "OOFF" */ -#define MIDX_OBJECT_LARGE_OFFSETS_ID 0x4c4f4646 /* "LOFF" */ - -struct git_midx_chunk { - off64_t offset; - size_t length; -}; - -typedef int (*midx_write_cb)(const char *buf, size_t size, void *cb_data); - -static int midx_error(const char *message) -{ - git_error_set(GIT_ERROR_ODB, "invalid multi-pack-index file - %s", message); - return -1; -} - -static int midx_parse_packfile_names( - git_midx_file *idx, - const unsigned char *data, - uint32_t packfiles, - struct git_midx_chunk *chunk) -{ - int error; - uint32_t i; - char *packfile_name = (char *)(data + chunk->offset); - size_t chunk_size = chunk->length, len; - if (chunk->offset == 0) - return midx_error("missing Packfile Names chunk"); - if (chunk->length == 0) - return midx_error("empty Packfile Names chunk"); - if ((error = git_vector_init(&idx->packfile_names, packfiles, git__strcmp_cb)) < 0) - return error; - for (i = 0; i < packfiles; ++i) { - len = p_strnlen(packfile_name, chunk_size); - if (len == 0) - return midx_error("empty packfile name"); - if (len + 1 > chunk_size) - return midx_error("unterminated packfile name"); - git_vector_insert(&idx->packfile_names, packfile_name); - if (i && strcmp(git_vector_get(&idx->packfile_names, i - 1), packfile_name) >= 0) - return midx_error("packfile names are not sorted"); - if (strlen(packfile_name) <= strlen(".idx") || git__suffixcmp(packfile_name, ".idx") != 0) - return midx_error("non-.idx packfile name"); - if (strchr(packfile_name, '/') != NULL || strchr(packfile_name, '\\') != NULL) - return midx_error("non-local packfile"); - packfile_name += len + 1; - chunk_size -= len + 1; - } - return 0; -} - -static int midx_parse_oid_fanout( - git_midx_file *idx, - const unsigned char *data, - struct git_midx_chunk *chunk_oid_fanout) -{ - uint32_t i, nr; - if (chunk_oid_fanout->offset == 0) - return midx_error("missing OID Fanout chunk"); - if (chunk_oid_fanout->length == 0) - return midx_error("empty OID Fanout chunk"); - if (chunk_oid_fanout->length != 256 * 4) - return midx_error("OID Fanout chunk has wrong length"); - - idx->oid_fanout = (const uint32_t *)(data + chunk_oid_fanout->offset); - nr = 0; - for (i = 0; i < 256; ++i) { - uint32_t n = ntohl(idx->oid_fanout[i]); - if (n < nr) - return midx_error("index is non-monotonic"); - nr = n; - } - idx->num_objects = nr; - return 0; -} - -static int midx_parse_oid_lookup( - git_midx_file *idx, - const unsigned char *data, - struct git_midx_chunk *chunk_oid_lookup) -{ - size_t oid_size = git_oid_size(idx->oid_type); - - if (chunk_oid_lookup->offset == 0) - return midx_error("missing OID Lookup chunk"); - if (chunk_oid_lookup->length == 0) - return midx_error("empty OID Lookup chunk"); - if (chunk_oid_lookup->length != idx->num_objects * oid_size) - return midx_error("OID Lookup chunk has wrong length"); - - idx->oid_lookup = (unsigned char *)(data + chunk_oid_lookup->offset); - - return 0; -} - -static int midx_parse_object_offsets( - git_midx_file *idx, - const unsigned char *data, - struct git_midx_chunk *chunk_object_offsets) -{ - if (chunk_object_offsets->offset == 0) - return midx_error("missing Object Offsets chunk"); - if (chunk_object_offsets->length == 0) - return midx_error("empty Object Offsets chunk"); - if (chunk_object_offsets->length != idx->num_objects * 8) - return midx_error("Object Offsets chunk has wrong length"); - - idx->object_offsets = data + chunk_object_offsets->offset; - - return 0; -} - -static int midx_parse_object_large_offsets( - git_midx_file *idx, - const unsigned char *data, - struct git_midx_chunk *chunk_object_large_offsets) -{ - if (chunk_object_large_offsets->length == 0) - return 0; - if (chunk_object_large_offsets->length % 8 != 0) - return midx_error("malformed Object Large Offsets chunk"); - - idx->object_large_offsets = data + chunk_object_large_offsets->offset; - idx->num_object_large_offsets = chunk_object_large_offsets->length / 8; - - return 0; -} - -int git_midx_parse( - git_midx_file *idx, - const unsigned char *data, - size_t size) -{ - struct git_midx_header *hdr; - const unsigned char *chunk_hdr; - struct git_midx_chunk *last_chunk; - uint32_t i; - off64_t last_chunk_offset, chunk_offset, trailer_offset; - size_t checksum_size, oid_size; - int error; - struct git_midx_chunk chunk_packfile_names = {0}, - chunk_oid_fanout = {0}, - chunk_oid_lookup = {0}, - chunk_object_offsets = {0}, - chunk_object_large_offsets = {0}, - chunk_unknown = {0}; - - GIT_ASSERT_ARG(idx); - - oid_size = git_oid_size(idx->oid_type); - - if (size < sizeof(struct git_midx_header) + oid_size) - return midx_error("multi-pack index is too short"); - - hdr = ((struct git_midx_header *)data); - - if (hdr->signature != htonl(MIDX_SIGNATURE) || - hdr->version != MIDX_VERSION || - hdr->object_id_version != MIDX_OBJECT_ID_VERSION) { - return midx_error("unsupported multi-pack index version"); - } - if (hdr->chunks == 0) - return midx_error("no chunks in multi-pack index"); - - /* - * The very first chunk's offset should be after the header, all the chunk - * headers, and a special zero chunk. - */ - last_chunk_offset = - sizeof(struct git_midx_header) + - (1 + hdr->chunks) * 12; - - checksum_size = oid_size; - trailer_offset = size - checksum_size; - - if (trailer_offset < last_chunk_offset) - return midx_error("wrong index size"); - memcpy(idx->checksum, data + trailer_offset, checksum_size); - - chunk_hdr = data + sizeof(struct git_midx_header); - last_chunk = NULL; - for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) { - uint32_t chunk_id = ntohl(*((uint32_t *)(chunk_hdr + 0))); - uint64_t high_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) & 0xffffffffu; - uint64_t low_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 8)))) & 0xffffffffu; - - if (high_offset >= INT32_MAX) - return midx_error("chunk offset out of range"); - chunk_offset = (off64_t)(high_offset << 32 | low_offset); - if (chunk_offset < last_chunk_offset) - return midx_error("chunks are non-monotonic"); - if (chunk_offset >= trailer_offset) - return midx_error("chunks extend beyond the trailer"); - if (last_chunk != NULL) - last_chunk->length = (size_t)(chunk_offset - last_chunk_offset); - last_chunk_offset = chunk_offset; - - switch (chunk_id) { - case MIDX_PACKFILE_NAMES_ID: - chunk_packfile_names.offset = last_chunk_offset; - last_chunk = &chunk_packfile_names; - break; - - case MIDX_OID_FANOUT_ID: - chunk_oid_fanout.offset = last_chunk_offset; - last_chunk = &chunk_oid_fanout; - break; - - case MIDX_OID_LOOKUP_ID: - chunk_oid_lookup.offset = last_chunk_offset; - last_chunk = &chunk_oid_lookup; - break; - - case MIDX_OBJECT_OFFSETS_ID: - chunk_object_offsets.offset = last_chunk_offset; - last_chunk = &chunk_object_offsets; - break; - - case MIDX_OBJECT_LARGE_OFFSETS_ID: - chunk_object_large_offsets.offset = last_chunk_offset; - last_chunk = &chunk_object_large_offsets; - break; - - default: - chunk_unknown.offset = last_chunk_offset; - last_chunk = &chunk_unknown; - break; - } - } - last_chunk->length = (size_t)(trailer_offset - last_chunk_offset); - - error = midx_parse_packfile_names( - idx, data, ntohl(hdr->packfiles), &chunk_packfile_names); - if (error < 0) - return error; - error = midx_parse_oid_fanout(idx, data, &chunk_oid_fanout); - if (error < 0) - return error; - error = midx_parse_oid_lookup(idx, data, &chunk_oid_lookup); - if (error < 0) - return error; - error = midx_parse_object_offsets(idx, data, &chunk_object_offsets); - if (error < 0) - return error; - error = midx_parse_object_large_offsets(idx, data, &chunk_object_large_offsets); - if (error < 0) - return error; - - return 0; -} - -int git_midx_open( - git_midx_file **idx_out, - const char *path, - git_oid_t oid_type) -{ - git_midx_file *idx; - git_file fd = -1; - size_t idx_size; - struct stat st; - int error; - - GIT_ASSERT_ARG(idx_out && path && oid_type); - - /* TODO: properly open the file without access time using O_NOATIME */ - fd = git_futils_open_ro(path); - if (fd < 0) - return fd; - - if (p_fstat(fd, &st) < 0) { - p_close(fd); - git_error_set(GIT_ERROR_ODB, "multi-pack-index file not found - '%s'", path); - return -1; - } - - if (!S_ISREG(st.st_mode) || !git__is_sizet(st.st_size)) { - p_close(fd); - git_error_set(GIT_ERROR_ODB, "invalid pack index '%s'", path); - return -1; - } - idx_size = (size_t)st.st_size; - - idx = git__calloc(1, sizeof(git_midx_file)); - GIT_ERROR_CHECK_ALLOC(idx); - - idx->oid_type = oid_type; - - error = git_str_sets(&idx->filename, path); - if (error < 0) - return error; - - error = git_futils_mmap_ro(&idx->index_map, fd, 0, idx_size); - p_close(fd); - if (error < 0) { - git_midx_free(idx); - return error; - } - - if ((error = git_midx_parse(idx, idx->index_map.data, idx_size)) < 0) { - git_midx_free(idx); - return error; - } - - *idx_out = idx; - return 0; -} - -bool git_midx_needs_refresh( - const git_midx_file *idx, - const char *path) -{ - git_file fd = -1; - struct stat st; - ssize_t bytes_read; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - size_t checksum_size; - - /* TODO: properly open the file without access time using O_NOATIME */ - fd = git_futils_open_ro(path); - if (fd < 0) - return true; - - if (p_fstat(fd, &st) < 0) { - p_close(fd); - return true; - } - - if (!S_ISREG(st.st_mode) || - !git__is_sizet(st.st_size) || - (size_t)st.st_size != idx->index_map.len) { - p_close(fd); - return true; - } - - checksum_size = git_oid_size(idx->oid_type); - bytes_read = p_pread(fd, checksum, checksum_size, st.st_size - checksum_size); - p_close(fd); - - if (bytes_read != (ssize_t)checksum_size) - return true; - - return (memcmp(checksum, idx->checksum, checksum_size) != 0); -} - -int git_midx_entry_find( - git_midx_entry *e, - git_midx_file *idx, - const git_oid *short_oid, - size_t len) -{ - int pos, found = 0; - size_t pack_index, oid_size, oid_hexsize; - uint32_t hi, lo; - unsigned char *current = NULL; - const unsigned char *object_offset; - off64_t offset; - - GIT_ASSERT_ARG(idx); - - oid_size = git_oid_size(idx->oid_type); - oid_hexsize = git_oid_hexsize(idx->oid_type); - - hi = ntohl(idx->oid_fanout[(int)short_oid->id[0]]); - lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(idx->oid_fanout[(int)short_oid->id[0] - 1])); - - pos = git_pack__lookup_id(idx->oid_lookup, oid_size, lo, hi, short_oid->id, idx->oid_type); - - if (pos >= 0) { - /* An object matching exactly the oid was found */ - found = 1; - current = idx->oid_lookup + (pos * oid_size); - } else { - /* No object was found */ - /* pos refers to the object with the "closest" oid to short_oid */ - pos = -1 - pos; - if (pos < (int)idx->num_objects) { - current = idx->oid_lookup + (pos * oid_size); - - if (!git_oid_raw_ncmp(short_oid->id, current, len)) - found = 1; - } - } - - if (found && len != oid_hexsize && pos + 1 < (int)idx->num_objects) { - /* Check for ambiguousity */ - const unsigned char *next = current + oid_size; - - if (!git_oid_raw_ncmp(short_oid->id, next, len)) - found = 2; - } - - if (!found) - return git_odb__error_notfound("failed to find offset for multi-pack index entry", short_oid, len); - if (found > 1) - return git_odb__error_ambiguous("found multiple offsets for multi-pack index entry"); - - object_offset = idx->object_offsets + pos * 8; - offset = ntohl(*((uint32_t *)(object_offset + 4))); - if (idx->object_large_offsets && offset & 0x80000000) { - uint32_t object_large_offsets_pos = (uint32_t) (offset ^ 0x80000000); - const unsigned char *object_large_offsets_index = idx->object_large_offsets; - - /* Make sure we're not being sent out of bounds */ - if (object_large_offsets_pos >= idx->num_object_large_offsets) - return git_odb__error_notfound("invalid index into the object large offsets table", short_oid, len); - - object_large_offsets_index += 8 * object_large_offsets_pos; - - offset = (((uint64_t)ntohl(*((uint32_t *)(object_large_offsets_index + 0)))) << 32) | - ntohl(*((uint32_t *)(object_large_offsets_index + 4))); - } - pack_index = ntohl(*((uint32_t *)(object_offset + 0))); - if (pack_index >= git_vector_length(&idx->packfile_names)) - return midx_error("invalid index into the packfile names table"); - e->pack_index = pack_index; - e->offset = offset; - git_oid__fromraw(&e->sha1, current, idx->oid_type); - return 0; -} - -int git_midx_foreach_entry( - git_midx_file *idx, - git_odb_foreach_cb cb, - void *data) -{ - git_oid oid; - size_t oid_size, i; - int error = 0; - - GIT_ASSERT_ARG(idx); - - oid_size = git_oid_size(idx->oid_type); - - for (i = 0; i < idx->num_objects; ++i) { - if ((error = git_oid__fromraw(&oid, &idx->oid_lookup[i * oid_size], idx->oid_type)) < 0) - return error; - - if ((error = cb(&oid, data)) != 0) - return git_error_set_after_callback(error); - } - - return error; -} - -int git_midx_close(git_midx_file *idx) -{ - GIT_ASSERT_ARG(idx); - - if (idx->index_map.data) - git_futils_mmap_free(&idx->index_map); - - git_vector_dispose(&idx->packfile_names); - - return 0; -} - -void git_midx_free(git_midx_file *idx) -{ - if (!idx) - return; - - git_str_dispose(&idx->filename); - git_midx_close(idx); - git__free(idx); -} - -static int packfile__cmp(const void *a_, const void *b_) -{ - const struct git_pack_file *a = a_; - const struct git_pack_file *b = b_; - - return strcmp(a->pack_name, b->pack_name); -} - -int git_midx_writer_new( - git_midx_writer **out, - const char *pack_dir -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_midx_writer_options *opts -#endif - ) -{ - git_midx_writer *w; - git_oid_t oid_type; - - GIT_ASSERT_ARG(out && pack_dir); - -#ifdef GIT_EXPERIMENTAL_SHA256 - GIT_ERROR_CHECK_VERSION(opts, - GIT_MIDX_WRITER_OPTIONS_VERSION, - "git_midx_writer_options"); - - oid_type = opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT; - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); -#else - oid_type = GIT_OID_SHA1; -#endif - - w = git__calloc(1, sizeof(git_midx_writer)); - GIT_ERROR_CHECK_ALLOC(w); - - if (git_str_sets(&w->pack_dir, pack_dir) < 0) { - git__free(w); - return -1; - } - git_fs_path_squash_slashes(&w->pack_dir); - - if (git_vector_init(&w->packs, 0, packfile__cmp) < 0) { - git_str_dispose(&w->pack_dir); - git__free(w); - return -1; - } - - w->oid_type = oid_type; - - *out = w; - return 0; -} - -void git_midx_writer_free(git_midx_writer *w) -{ - struct git_pack_file *p; - size_t i; - - if (!w) - return; - - git_vector_foreach (&w->packs, i, p) - git_mwindow_put_pack(p); - git_vector_dispose(&w->packs); - git_str_dispose(&w->pack_dir); - git__free(w); -} - -int git_midx_writer_add( - git_midx_writer *w, - const char *idx_path) -{ - git_str idx_path_buf = GIT_STR_INIT; - int error; - struct git_pack_file *p; - - error = git_fs_path_prettify(&idx_path_buf, idx_path, git_str_cstr(&w->pack_dir)); - if (error < 0) - return error; - - error = git_mwindow_get_pack(&p, git_str_cstr(&idx_path_buf), w->oid_type); - git_str_dispose(&idx_path_buf); - if (error < 0) - return error; - - error = git_vector_insert(&w->packs, p); - if (error < 0) { - git_mwindow_put_pack(p); - return error; - } - - return 0; -} - -typedef git_array_t(git_midx_entry) object_entry_array_t; - -struct object_entry_cb_state { - uint32_t pack_index; - object_entry_array_t *object_entries_array; -}; - -static int object_entry__cb(const git_oid *oid, off64_t offset, void *data) -{ - struct object_entry_cb_state *state = (struct object_entry_cb_state *)data; - - git_midx_entry *entry = git_array_alloc(*state->object_entries_array); - GIT_ERROR_CHECK_ALLOC(entry); - - git_oid_cpy(&entry->sha1, oid); - entry->offset = offset; - entry->pack_index = state->pack_index; - - return 0; -} - -static int object_entry__cmp(const void *a_, const void *b_) -{ - const git_midx_entry *a = (const git_midx_entry *)a_; - const git_midx_entry *b = (const git_midx_entry *)b_; - - return git_oid_cmp(&a->sha1, &b->sha1); -} - -static int write_offset(off64_t offset, midx_write_cb write_cb, void *cb_data) -{ - int error; - uint32_t word; - - word = htonl((uint32_t)((offset >> 32) & 0xffffffffu)); - error = write_cb((const char *)&word, sizeof(word), cb_data); - if (error < 0) - return error; - word = htonl((uint32_t)((offset >> 0) & 0xffffffffu)); - error = write_cb((const char *)&word, sizeof(word), cb_data); - if (error < 0) - return error; - - return 0; -} - -static int write_chunk_header(int chunk_id, off64_t offset, midx_write_cb write_cb, void *cb_data) -{ - uint32_t word = htonl(chunk_id); - int error = write_cb((const char *)&word, sizeof(word), cb_data); - if (error < 0) - return error; - return write_offset(offset, write_cb, cb_data); - - return 0; -} - -static int midx_write_buf(const char *buf, size_t size, void *data) -{ - git_str *b = (git_str *)data; - return git_str_put(b, buf, size); -} - -struct midx_write_hash_context { - midx_write_cb write_cb; - void *cb_data; - git_hash_ctx *ctx; -}; - -static int midx_write_hash(const char *buf, size_t size, void *data) -{ - struct midx_write_hash_context *ctx = (struct midx_write_hash_context *)data; - int error; - - if (ctx->ctx) { - error = git_hash_update(ctx->ctx, buf, size); - if (error < 0) - return error; - } - - return ctx->write_cb(buf, size, ctx->cb_data); -} - -static int midx_write( - git_midx_writer *w, - midx_write_cb write_cb, - void *cb_data) -{ - int error = 0; - size_t i; - struct git_pack_file *p; - struct git_midx_header hdr = {0}; - uint32_t oid_fanout_count; - uint32_t object_large_offsets_count; - uint32_t oid_fanout[256]; - off64_t offset; - git_str packfile_names = GIT_STR_INIT, - oid_lookup = GIT_STR_INIT, - object_offsets = GIT_STR_INIT, - object_large_offsets = GIT_STR_INIT; - unsigned char checksum[GIT_HASH_MAX_SIZE]; - size_t checksum_size, oid_size; - git_midx_entry *entry; - object_entry_array_t object_entries_array = GIT_ARRAY_INIT; - git_vector object_entries = GIT_VECTOR_INIT; - git_hash_ctx ctx; - git_hash_algorithm_t checksum_type; - struct midx_write_hash_context hash_cb_data = {0}; - - hdr.signature = htonl(MIDX_SIGNATURE); - hdr.version = MIDX_VERSION; - hdr.object_id_version = MIDX_OBJECT_ID_VERSION; - hdr.base_midx_files = 0; - - hash_cb_data.write_cb = write_cb; - hash_cb_data.cb_data = cb_data; - hash_cb_data.ctx = &ctx; - - oid_size = git_oid_size(w->oid_type); - checksum_type = git_oid_algorithm(w->oid_type); - checksum_size = git_hash_size(checksum_type); - GIT_ASSERT(oid_size && checksum_type && checksum_size); - - if ((error = git_hash_ctx_init(&ctx, checksum_type)) < 0) - return error; - - cb_data = &hash_cb_data; - write_cb = midx_write_hash; - - git_vector_sort(&w->packs); - git_vector_foreach (&w->packs, i, p) { - git_str relative_index = GIT_STR_INIT; - struct object_entry_cb_state state = {0}; - size_t path_len; - - state.pack_index = (uint32_t)i; - state.object_entries_array = &object_entries_array; - - error = git_str_sets(&relative_index, p->pack_name); - if (error < 0) - goto cleanup; - error = git_fs_path_make_relative(&relative_index, git_str_cstr(&w->pack_dir)); - if (error < 0) { - git_str_dispose(&relative_index); - goto cleanup; - } - path_len = git_str_len(&relative_index); - if (path_len <= strlen(".pack") || git__suffixcmp(git_str_cstr(&relative_index), ".pack") != 0) { - git_str_dispose(&relative_index); - git_error_set(GIT_ERROR_INVALID, "invalid packfile name: '%s'", p->pack_name); - error = -1; - goto cleanup; - } - path_len -= strlen(".pack"); - - git_str_put(&packfile_names, git_str_cstr(&relative_index), path_len); - git_str_puts(&packfile_names, ".idx"); - git_str_putc(&packfile_names, '\0'); - git_str_dispose(&relative_index); - - error = git_pack_foreach_entry_offset(p, object_entry__cb, &state); - if (error < 0) - goto cleanup; - } - - /* Sort the object entries. */ - error = git_vector_init(&object_entries, git_array_size(object_entries_array), object_entry__cmp); - if (error < 0) - goto cleanup; - git_array_foreach (object_entries_array, i, entry) { - if ((error = git_vector_set(NULL, &object_entries, i, entry)) < 0) - goto cleanup; - } - git_vector_set_sorted(&object_entries, 0); - git_vector_sort(&object_entries); - git_vector_uniq(&object_entries, NULL); - - /* Pad the packfile names so it is a multiple of four. */ - while (git_str_len(&packfile_names) & 3) - git_str_putc(&packfile_names, '\0'); - - /* Fill the OID Fanout table. */ - oid_fanout_count = 0; - for (i = 0; i < 256; i++) { - while (oid_fanout_count < git_vector_length(&object_entries) && - ((const git_midx_entry *)git_vector_get(&object_entries, oid_fanout_count))->sha1.id[0] <= i) - ++oid_fanout_count; - oid_fanout[i] = htonl(oid_fanout_count); - } - - /* Fill the OID Lookup table. */ - git_vector_foreach (&object_entries, i, entry) { - error = git_str_put(&oid_lookup, - (char *)&entry->sha1.id, oid_size); - - if (error < 0) - goto cleanup; - } - - /* Fill the Object Offsets and Object Large Offsets tables. */ - object_large_offsets_count = 0; - git_vector_foreach (&object_entries, i, entry) { - uint32_t word; - - word = htonl((uint32_t)entry->pack_index); - error = git_str_put(&object_offsets, (const char *)&word, sizeof(word)); - if (error < 0) - goto cleanup; - if (entry->offset >= 0x80000000l) { - word = htonl(0x80000000u | object_large_offsets_count++); - if ((error = write_offset(entry->offset, midx_write_buf, &object_large_offsets)) < 0) - goto cleanup; - } else { - word = htonl((uint32_t)entry->offset & 0x7fffffffu); - } - - error = git_str_put(&object_offsets, (const char *)&word, sizeof(word)); - if (error < 0) - goto cleanup; - } - - /* Write the header. */ - hdr.packfiles = htonl((uint32_t)git_vector_length(&w->packs)); - hdr.chunks = 4; - if (git_str_len(&object_large_offsets) > 0) - hdr.chunks++; - error = write_cb((const char *)&hdr, sizeof(hdr), cb_data); - if (error < 0) - goto cleanup; - - /* Write the chunk headers. */ - offset = sizeof(hdr) + (hdr.chunks + 1) * 12; - error = write_chunk_header(MIDX_PACKFILE_NAMES_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += git_str_len(&packfile_names); - error = write_chunk_header(MIDX_OID_FANOUT_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += sizeof(oid_fanout); - error = write_chunk_header(MIDX_OID_LOOKUP_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += git_str_len(&oid_lookup); - error = write_chunk_header(MIDX_OBJECT_OFFSETS_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += git_str_len(&object_offsets); - if (git_str_len(&object_large_offsets) > 0) { - error = write_chunk_header(MIDX_OBJECT_LARGE_OFFSETS_ID, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - offset += git_str_len(&object_large_offsets); - } - error = write_chunk_header(0, offset, write_cb, cb_data); - if (error < 0) - goto cleanup; - - /* Write all the chunks. */ - error = write_cb(git_str_cstr(&packfile_names), git_str_len(&packfile_names), cb_data); - if (error < 0) - goto cleanup; - error = write_cb((const char *)oid_fanout, sizeof(oid_fanout), cb_data); - if (error < 0) - goto cleanup; - error = write_cb(git_str_cstr(&oid_lookup), git_str_len(&oid_lookup), cb_data); - if (error < 0) - goto cleanup; - error = write_cb(git_str_cstr(&object_offsets), git_str_len(&object_offsets), cb_data); - if (error < 0) - goto cleanup; - error = write_cb(git_str_cstr(&object_large_offsets), git_str_len(&object_large_offsets), cb_data); - if (error < 0) - goto cleanup; - - /* Finalize the checksum and write the trailer. */ - error = git_hash_final(checksum, &ctx); - if (error < 0) - goto cleanup; - - hash_cb_data.ctx = NULL; - - error = write_cb((char *)checksum, checksum_size, cb_data); - if (error < 0) - goto cleanup; - -cleanup: - git_array_clear(object_entries_array); - git_vector_dispose(&object_entries); - git_str_dispose(&packfile_names); - git_str_dispose(&oid_lookup); - git_str_dispose(&object_offsets); - git_str_dispose(&object_large_offsets); - git_hash_ctx_cleanup(&ctx); - return error; -} - -static int midx_write_filebuf(const char *buf, size_t size, void *data) -{ - git_filebuf *f = (git_filebuf *)data; - return git_filebuf_write(f, buf, size); -} - -int git_midx_writer_commit( - git_midx_writer *w) -{ - int error; - int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER; - git_str midx_path = GIT_STR_INIT; - git_filebuf output = GIT_FILEBUF_INIT; - - error = git_str_joinpath(&midx_path, git_str_cstr(&w->pack_dir), "multi-pack-index"); - if (error < 0) - return error; - - if (git_repository__fsync_gitdir) - filebuf_flags |= GIT_FILEBUF_FSYNC; - error = git_filebuf_open(&output, git_str_cstr(&midx_path), filebuf_flags, 0644); - git_str_dispose(&midx_path); - if (error < 0) - return error; - - error = midx_write(w, midx_write_filebuf, &output); - if (error < 0) { - git_filebuf_cleanup(&output); - return error; - } - - return git_filebuf_commit(&output); -} - -int git_midx_writer_dump( - git_buf *midx, - git_midx_writer *w) -{ - git_str str = GIT_STR_INIT; - int error; - - if ((error = git_buf_tostr(&str, midx)) < 0 || - (error = midx_write(w, midx_write_buf, &str)) == 0) - error = git_buf_fromstr(midx, &str); - - git_str_dispose(&str); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/midx.h b/vendor/libgit2-sys/libgit2/src/libgit2/midx.h deleted file mode 100644 index 5107f69..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/midx.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_midx_h__ -#define INCLUDE_midx_h__ - -#include "common.h" - -#include - -#include "git2/sys/midx.h" - -#include "map.h" -#include "mwindow.h" -#include "odb.h" -#include "oid.h" - -/* - * A multi-pack-index file. - * - * This file contains a merged index for multiple independent .pack files. This - * can help speed up locating objects without requiring a garbage collection - * cycle to create a single .pack file. - * - * Support for this feature was added in git 2.21, and requires the - * `core.multiPackIndex` config option to be set. - */ -typedef struct git_midx_file { - git_map index_map; - - /* The table of Packfile Names. */ - git_vector packfile_names; - - /* The OID Fanout table. */ - const uint32_t *oid_fanout; - /* The total number of objects in the index. */ - uint32_t num_objects; - - /* The OID Lookup table. */ - unsigned char *oid_lookup; - - /* The Object Offsets table. Each entry has two 4-byte fields with the pack index and the offset. */ - const unsigned char *object_offsets; - - /* The Object Large Offsets table. */ - const unsigned char *object_large_offsets; - /* The number of entries in the Object Large Offsets table. Each entry has an 8-byte with an offset */ - size_t num_object_large_offsets; - - /* - * The trailer of the file. Contains the checksum of the whole - * file, in the repository's object format hash. - */ - unsigned char checksum[GIT_HASH_MAX_SIZE]; - - /* The type of object IDs in the midx. */ - git_oid_t oid_type; - - /* something like ".git/objects/pack/multi-pack-index". */ - git_str filename; -} git_midx_file; - -/* - * An entry in the multi-pack-index file. Similar in purpose to git_pack_entry. - */ -typedef struct git_midx_entry { - /* The index within idx->packfile_names where the packfile name can be found. */ - size_t pack_index; - /* The offset within the .pack file where the requested object is found. */ - off64_t offset; - /* The SHA-1 hash of the requested object. */ - git_oid sha1; -} git_midx_entry; - -/* - * A writer for `multi-pack-index` files. - */ -struct git_midx_writer { - /* - * The path of the directory where the .pack/.idx files are stored. The - * `multi-pack-index` file will be written to the same directory. - */ - git_str pack_dir; - - /* The list of `git_pack_file`s. */ - git_vector packs; - - /* The object ID type of the writer. */ - git_oid_t oid_type; -}; - -int git_midx_open( - git_midx_file **idx_out, - const char *path, - git_oid_t oid_type); -bool git_midx_needs_refresh( - const git_midx_file *idx, - const char *path); -int git_midx_entry_find( - git_midx_entry *e, - git_midx_file *idx, - const git_oid *short_oid, - size_t len); -int git_midx_foreach_entry( - git_midx_file *idx, - git_odb_foreach_cb cb, - void *data); -int git_midx_close(git_midx_file *idx); -void git_midx_free(git_midx_file *idx); - -/* This is exposed for use in the fuzzers. */ -int git_midx_parse( - git_midx_file *idx, - const unsigned char *data, - size_t size); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/mwindow.c b/vendor/libgit2-sys/libgit2/src/libgit2/mwindow.c deleted file mode 100644 index 7e4054d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/mwindow.c +++ /dev/null @@ -1,537 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "mwindow.h" - -#include "vector.h" -#include "futils.h" -#include "map.h" -#include "runtime.h" -#include "pack.h" - -#define DEFAULT_WINDOW_SIZE \ - (sizeof(void*) >= 8 \ - ? 1 * 1024 * 1024 * 1024 \ - : 32 * 1024 * 1024) - -#define DEFAULT_MAPPED_LIMIT \ - ((1024 * 1024) * (sizeof(void*) >= 8 ? UINT64_C(8192) : UINT64_C(256))) - -/* default is unlimited */ -#define DEFAULT_FILE_LIMIT 0 - -size_t git_mwindow__window_size = DEFAULT_WINDOW_SIZE; -size_t git_mwindow__mapped_limit = DEFAULT_MAPPED_LIMIT; -size_t git_mwindow__file_limit = DEFAULT_FILE_LIMIT; - -/* Mutex to control access to `git_mwindow__mem_ctl` and `git_mwindow__pack_cache`. */ -git_mutex git_mwindow__mutex; - -/* Whenever you want to read or modify this, grab `git_mwindow__mutex` */ -git_mwindow_ctl git_mwindow__mem_ctl; - -/* Global list of mwindow files, to open packs once across repos */ -GIT_HASHMAP_STR_FUNCTIONS(git_mwindow_packmap, , struct git_pack_file *); -git_mwindow_packmap git_mwindow__pack_cache; - -static void git_mwindow_global_shutdown(void) -{ - git_mutex_free(&git_mwindow__mutex); - git_mwindow_packmap_dispose(&git_mwindow__pack_cache); -} - -int git_mwindow_global_init(void) -{ - int error; - - if ((error = git_mutex_init(&git_mwindow__mutex)) < 0) - return error; - - return git_runtime_shutdown_register(git_mwindow_global_shutdown); -} - -int git_mwindow_get_pack( - struct git_pack_file **out, - const char *path, - git_oid_t oid_type) -{ - struct git_pack_file *pack; - char *packname; - int error; - - if ((error = git_packfile__name(&packname, path)) < 0) - return error; - - if (git_mutex_lock(&git_mwindow__mutex) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock mwindow mutex"); - return -1; - } - - error = git_mwindow_packmap_get(&pack, &git_mwindow__pack_cache, packname); - git__free(packname); - - if (error == 0) { - git_atomic32_inc(&pack->refcount); - git_mutex_unlock(&git_mwindow__mutex); - *out = pack; - return 0; - } else if (error != GIT_ENOTFOUND) { - return error; - } - - /* If we didn't find it, we need to create it */ - if ((error = git_packfile_alloc(&pack, path, oid_type)) < 0) { - git_mutex_unlock(&git_mwindow__mutex); - return error; - } - - git_atomic32_inc(&pack->refcount); - - error = git_mwindow_packmap_put(&git_mwindow__pack_cache, pack->pack_name, pack); - git_mutex_unlock(&git_mwindow__mutex); - - if (error < 0) { - git_packfile_free(pack, false); - return error; - } - - *out = pack; - return 0; -} - -int git_mwindow_put_pack(struct git_pack_file *pack) -{ - int count, error; - struct git_pack_file *pack_to_delete = NULL; - - if ((error = git_mutex_lock(&git_mwindow__mutex)) < 0) - return error; - - /* if we cannot find it, the state is corrupted */ - GIT_ASSERT(git_mwindow_packmap_contains(&git_mwindow__pack_cache, pack->pack_name)); - - count = git_atomic32_dec(&pack->refcount); - if (count == 0) { - git_mwindow_packmap_remove(&git_mwindow__pack_cache, pack->pack_name); - pack_to_delete = pack; - } - git_mutex_unlock(&git_mwindow__mutex); - git_packfile_free(pack_to_delete, false); - - return 0; -} - -/* - * Free all the windows in a sequence, typically because we're done - * with the file. Needs to hold the git_mwindow__mutex. - */ -static int git_mwindow_free_all_locked(git_mwindow_file *mwf) -{ - git_mwindow_ctl *ctl = &git_mwindow__mem_ctl; - size_t i; - - /* - * Remove these windows from the global list - */ - for (i = 0; i < ctl->windowfiles.length; ++i){ - if (git_vector_get(&ctl->windowfiles, i) == mwf) { - git_vector_remove(&ctl->windowfiles, i); - break; - } - } - - if (ctl->windowfiles.length == 0) { - git_vector_dispose(&ctl->windowfiles); - ctl->windowfiles.contents = NULL; - } - - while (mwf->windows) { - git_mwindow *w = mwf->windows; - GIT_ASSERT(w->inuse_cnt == 0); - - ctl->mapped -= w->window_map.len; - ctl->open_windows--; - - git_futils_mmap_free(&w->window_map); - - mwf->windows = w->next; - git__free(w); - } - - return 0; -} - -int git_mwindow_free_all(git_mwindow_file *mwf) -{ - int error; - - if (git_mutex_lock(&git_mwindow__mutex)) { - git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex"); - return -1; - } - - error = git_mwindow_free_all_locked(mwf); - - git_mutex_unlock(&git_mwindow__mutex); - - return error; -} - -/* - * Check if a window 'win' contains both the address 'offset' and 'extra'. - * - * 'extra' is the size of the hash we're using as we always want to make sure - * that it's contained. - */ -int git_mwindow_contains(git_mwindow *win, off64_t offset, off64_t extra) -{ - off64_t win_off = win->offset; - return win_off <= offset - && (offset + extra) <= (off64_t)(win_off + win->window_map.len); -} - -#define GIT_MWINDOW__LRU -1 -#define GIT_MWINDOW__MRU 1 - -/* - * Find the least- or most-recently-used window in a file that is not currently - * being used. The 'only_unused' flag controls whether the caller requires the - * file to only have unused windows. If '*out_window' is non-null, it is used as - * a starting point for the comparison. - * - * Returns whether such a window was found in the file. - */ -static bool git_mwindow_scan_recently_used( - git_mwindow_file *mwf, - git_mwindow **out_window, - git_mwindow **out_last, - bool only_unused, - int comparison_sign) -{ - git_mwindow *w, *w_last; - git_mwindow *lru_window = NULL, *lru_last = NULL; - bool found = false; - - GIT_ASSERT_ARG(mwf); - GIT_ASSERT_ARG(out_window); - - lru_window = *out_window; - if (out_last) - lru_last = *out_last; - - for (w_last = NULL, w = mwf->windows; w; w_last = w, w = w->next) { - if (w->inuse_cnt) { - if (only_unused) - return false; - /* This window is currently being used. Skip it. */ - continue; - } - - /* - * If the current one is more (or less) recent than the last one, - * store it in the output parameter. If lru_window is NULL, - * it's the first loop, so store it as well. - */ - if (!lru_window || (comparison_sign * w->last_used) > lru_window->last_used) { - lru_window = w; - lru_last = w_last; - found = true; - } - } - - if (!found) - return false; - - *out_window = lru_window; - if (out_last) - *out_last = lru_last; - return true; -} - -/* - * Close the least recently used window (that is currently not being used) out - * of all the files. Called under lock from new_window_locked. - */ -static int git_mwindow_close_lru_window_locked(void) -{ - git_mwindow_ctl *ctl = &git_mwindow__mem_ctl; - git_mwindow_file *cur; - size_t i; - git_mwindow *lru_window = NULL, *lru_last = NULL, **list = NULL; - - git_vector_foreach(&ctl->windowfiles, i, cur) { - if (git_mwindow_scan_recently_used( - cur, &lru_window, &lru_last, false, GIT_MWINDOW__LRU)) { - list = &cur->windows; - } - } - - if (!lru_window) { - git_error_set(GIT_ERROR_OS, "failed to close memory window; couldn't find LRU"); - return -1; - } - - ctl->mapped -= lru_window->window_map.len; - git_futils_mmap_free(&lru_window->window_map); - - if (lru_last) - lru_last->next = lru_window->next; - else - *list = lru_window->next; - - git__free(lru_window); - ctl->open_windows--; - - return 0; -} - -/* - * Finds the file that does not have any open windows AND whose - * most-recently-used window is the least-recently used one across all - * currently open files. - * - * Called under lock from new_window_locked. - */ -static int git_mwindow_find_lru_file_locked(git_mwindow_file **out) -{ - git_mwindow_ctl *ctl = &git_mwindow__mem_ctl; - git_mwindow_file *lru_file = NULL, *current_file = NULL; - git_mwindow *lru_window = NULL; - size_t i; - - git_vector_foreach(&ctl->windowfiles, i, current_file) { - git_mwindow *mru_window = NULL; - if (!git_mwindow_scan_recently_used( - current_file, &mru_window, NULL, true, GIT_MWINDOW__MRU)) { - continue; - } - if (!lru_window || lru_window->last_used > mru_window->last_used) { - lru_window = mru_window; - lru_file = current_file; - } - } - - if (!lru_file) { - git_error_set(GIT_ERROR_OS, "failed to close memory window file; couldn't find LRU"); - return -1; - } - - *out = lru_file; - return 0; -} - -/* This gets called under lock from git_mwindow_open */ -static git_mwindow *new_window_locked( - git_file fd, - off64_t size, - off64_t offset) -{ - git_mwindow_ctl *ctl = &git_mwindow__mem_ctl; - size_t walign = git_mwindow__window_size / 2; - off64_t len; - git_mwindow *w; - - w = git__calloc(1, sizeof(*w)); - - if (w == NULL) - return NULL; - - w->offset = (offset / walign) * walign; - - len = size - w->offset; - if (len > (off64_t)git_mwindow__window_size) - len = (off64_t)git_mwindow__window_size; - - ctl->mapped += (size_t)len; - - while (git_mwindow__mapped_limit < ctl->mapped && - git_mwindow_close_lru_window_locked() == 0) /* nop */; - - /* - * We treat `mapped_limit` as a soft limit. If we can't find a - * window to close and are above the limit, we still mmap the new - * window. - */ - - if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) { - /* - * The first error might be down to memory fragmentation even if - * we're below our soft limits, so free up what we can and try again. - */ - - while (git_mwindow_close_lru_window_locked() == 0) - /* nop */; - - if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) { - git__free(w); - return NULL; - } - } - - ctl->mmap_calls++; - ctl->open_windows++; - - if (ctl->mapped > ctl->peak_mapped) - ctl->peak_mapped = ctl->mapped; - - if (ctl->open_windows > ctl->peak_open_windows) - ctl->peak_open_windows = ctl->open_windows; - - return w; -} - -/* - * Open a new window, closing the least recenty used until we have - * enough space. Don't forget to add it to your list - */ -unsigned char *git_mwindow_open( - git_mwindow_file *mwf, - git_mwindow **cursor, - off64_t offset, - size_t extra, - unsigned int *left) -{ - git_mwindow_ctl *ctl = &git_mwindow__mem_ctl; - git_mwindow *w = *cursor; - - if (git_mutex_lock(&git_mwindow__mutex)) { - git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex"); - return NULL; - } - - if (!w || !(git_mwindow_contains(w, offset, extra))) { - if (w) { - w->inuse_cnt--; - } - - for (w = mwf->windows; w; w = w->next) { - if (git_mwindow_contains(w, offset, extra)) - break; - } - - /* - * If there isn't a suitable window, we need to create a new - * one. - */ - if (!w) { - w = new_window_locked(mwf->fd, mwf->size, offset); - if (w == NULL) { - git_mutex_unlock(&git_mwindow__mutex); - return NULL; - } - w->next = mwf->windows; - mwf->windows = w; - } - } - - /* If we changed w, store it in the cursor */ - if (w != *cursor) { - w->last_used = ctl->used_ctr++; - w->inuse_cnt++; - *cursor = w; - } - - offset -= w->offset; - - if (left) - *left = (unsigned int)(w->window_map.len - offset); - - git_mutex_unlock(&git_mwindow__mutex); - return (unsigned char *) w->window_map.data + offset; -} - -int git_mwindow_file_register(git_mwindow_file *mwf) -{ - git_vector closed_files = GIT_VECTOR_INIT; - git_mwindow_ctl *ctl = &git_mwindow__mem_ctl; - int error; - size_t i; - git_mwindow_file *closed_file = NULL; - - if (git_mutex_lock(&git_mwindow__mutex)) { - git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex"); - return -1; - } - - if (ctl->windowfiles.length == 0 && - (error = git_vector_init(&ctl->windowfiles, 8, NULL)) < 0) { - git_mutex_unlock(&git_mwindow__mutex); - goto cleanup; - } - - if (git_mwindow__file_limit) { - git_mwindow_file *lru_file; - while (git_mwindow__file_limit <= ctl->windowfiles.length && - git_mwindow_find_lru_file_locked(&lru_file) == 0) { - if ((error = git_vector_insert(&closed_files, lru_file)) < 0) { - /* - * Exceeding the file limit seems preferable to being open to - * data races that can end up corrupting the heap. - */ - break; - } - git_mwindow_free_all_locked(lru_file); - } - } - - error = git_vector_insert(&ctl->windowfiles, mwf); - git_mutex_unlock(&git_mwindow__mutex); - if (error < 0) - goto cleanup; - - /* - * Once we have released the global windowfiles lock, we can close each - * individual file. Before doing so, acquire that file's lock to avoid - * closing a file that is currently being used. - */ - git_vector_foreach(&closed_files, i, closed_file) { - error = git_mutex_lock(&closed_file->lock); - if (error < 0) - continue; - p_close(closed_file->fd); - closed_file->fd = -1; - git_mutex_unlock(&closed_file->lock); - } - -cleanup: - git_vector_dispose(&closed_files); - return error; -} - -void git_mwindow_file_deregister(git_mwindow_file *mwf) -{ - git_mwindow_ctl *ctl = &git_mwindow__mem_ctl; - git_mwindow_file *cur; - size_t i; - - if (git_mutex_lock(&git_mwindow__mutex)) - return; - - git_vector_foreach(&ctl->windowfiles, i, cur) { - if (cur == mwf) { - git_vector_remove(&ctl->windowfiles, i); - git_mutex_unlock(&git_mwindow__mutex); - return; - } - } - git_mutex_unlock(&git_mwindow__mutex); -} - -void git_mwindow_close(git_mwindow **window) -{ - git_mwindow *w = *window; - if (w) { - if (git_mutex_lock(&git_mwindow__mutex)) { - git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex"); - return; - } - - w->inuse_cnt--; - git_mutex_unlock(&git_mwindow__mutex); - *window = NULL; - } -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/mwindow.h b/vendor/libgit2-sys/libgit2/src/libgit2/mwindow.h deleted file mode 100644 index 43352c4..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/mwindow.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_mwindow__ -#define INCLUDE_mwindow__ - -#include "common.h" - -#include "map.h" -#include "vector.h" -#include "hashmap_str.h" - -GIT_HASHMAP_STR_STRUCT(git_mwindow_packmap, struct git_pack_file *); -GIT_HASHMAP_STR_PROTOTYPES(git_mwindow_packmap, struct git_pack_file *); - -typedef struct git_mwindow { - struct git_mwindow *next; - git_map window_map; - off64_t offset; - size_t last_used; - size_t inuse_cnt; -} git_mwindow; - -typedef struct git_mwindow_file { - git_mutex lock; /* protects updates to fd */ - git_mwindow *windows; - int fd; - off64_t size; -} git_mwindow_file; - -typedef struct git_mwindow_ctl { - size_t mapped; - unsigned int open_windows; - unsigned int mmap_calls; - unsigned int peak_open_windows; - size_t peak_mapped; - size_t used_ctr; - git_vector windowfiles; -} git_mwindow_ctl; - -int git_mwindow_contains(git_mwindow *win, off64_t offset, off64_t extra); -int git_mwindow_free_all(git_mwindow_file *mwf); /* locks */ -unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, off64_t offset, size_t extra, unsigned int *left); -int git_mwindow_file_register(git_mwindow_file *mwf); -void git_mwindow_file_deregister(git_mwindow_file *mwf); -void git_mwindow_close(git_mwindow **w_cursor); - -extern int git_mwindow_global_init(void); - -struct git_pack_file; /* just declaration to avoid cyclical includes */ -int git_mwindow_get_pack( - struct git_pack_file **out, - const char *path, - git_oid_t oid_type); -int git_mwindow_put_pack(struct git_pack_file *pack); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/notes.c b/vendor/libgit2-sys/libgit2/src/libgit2/notes.c deleted file mode 100644 index 13ca382..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/notes.c +++ /dev/null @@ -1,810 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "notes.h" - -#include "buf.h" -#include "refs.h" -#include "config.h" -#include "iterator.h" -#include "signature.h" -#include "blob.h" - -static int note_error_notfound(void) -{ - git_error_set(GIT_ERROR_INVALID, "note could not be found"); - return GIT_ENOTFOUND; -} - -static int find_subtree_in_current_level( - git_tree **out, - git_repository *repo, - git_tree *parent, - const char *annotated_object_sha, - int fanout) -{ - size_t i; - const git_tree_entry *entry; - - *out = NULL; - - if (parent == NULL) - return note_error_notfound(); - - for (i = 0; i < git_tree_entrycount(parent); i++) { - entry = git_tree_entry_byindex(parent, i); - - if (!git__ishex(git_tree_entry_name(entry))) - continue; - - if (S_ISDIR(git_tree_entry_filemode(entry)) - && strlen(git_tree_entry_name(entry)) == 2 - && !strncmp(git_tree_entry_name(entry), annotated_object_sha + fanout, 2)) - return git_tree_lookup(out, repo, git_tree_entry_id(entry)); - - /* Not a DIR, so do we have an already existing blob? */ - if (!strcmp(git_tree_entry_name(entry), annotated_object_sha + fanout)) - return GIT_EEXISTS; - } - - return note_error_notfound(); -} - -static int find_subtree_r(git_tree **out, git_tree *root, - git_repository *repo, const char *target, int *fanout) -{ - int error; - git_tree *subtree = NULL; - - *out = NULL; - - error = find_subtree_in_current_level(&subtree, repo, root, target, *fanout); - if (error == GIT_EEXISTS) - return git_tree_lookup(out, repo, git_tree_id(root)); - - if (error < 0) - return error; - - *fanout += 2; - error = find_subtree_r(out, subtree, repo, target, fanout); - git_tree_free(subtree); - - return error; -} - -static int find_blob(git_oid *blob, git_tree *tree, const char *target) -{ - size_t i; - const git_tree_entry *entry; - - for (i=0; iid, note_oid); - - if (git_signature_dup(¬e->author, git_commit_author(commit)) < 0 || - git_signature_dup(¬e->committer, git_commit_committer(commit)) < 0) - return -1; - - blobsize = git_blob_rawsize(blob); - GIT_ERROR_CHECK_BLOBSIZE(blobsize); - - note->message = git__strndup(git_blob_rawcontent(blob), (size_t)blobsize); - GIT_ERROR_CHECK_ALLOC(note->message); - - *out = note; - return 0; -} - -static int note_lookup( - git_note **out, - git_repository *repo, - git_commit *commit, - git_tree *tree, - const char *target) -{ - int error, fanout = 0; - git_oid oid; - git_blob *blob = NULL; - git_note *note = NULL; - git_tree *subtree = NULL; - - if ((error = find_subtree_r(&subtree, tree, repo, target, &fanout)) < 0) - goto cleanup; - - if ((error = find_blob(&oid, subtree, target + fanout)) < 0) - goto cleanup; - - if ((error = git_blob_lookup(&blob, repo, &oid)) < 0) - goto cleanup; - - if ((error = note_new(¬e, &oid, commit, blob)) < 0) - goto cleanup; - - *out = note; - -cleanup: - git_tree_free(subtree); - git_blob_free(blob); - return error; -} - -static int note_remove( - git_oid *notes_commit_out, - git_repository *repo, - const git_signature *author, const git_signature *committer, - const char *notes_ref, git_tree *tree, - const char *target, git_commit **parents) -{ - int error; - git_tree *tree_after_removal = NULL; - git_oid oid; - - if ((error = manipulate_note_in_tree_r( - &tree_after_removal, repo, tree, NULL, target, 0, - remove_note_in_tree_eexists_cb, remove_note_in_tree_enotfound_cb)) < 0) - goto cleanup; - - error = git_commit_create(&oid, repo, notes_ref, author, committer, - NULL, GIT_NOTES_DEFAULT_MSG_RM, - tree_after_removal, - *parents == NULL ? 0 : 1, - (const git_commit **) parents); - - if (error < 0) - goto cleanup; - - if (notes_commit_out) - git_oid_cpy(notes_commit_out, &oid); - -cleanup: - git_tree_free(tree_after_removal); - return error; -} - -static int note_get_default_ref(git_str *out, git_repository *repo) -{ - git_config *cfg; - int error; - - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0) - return error; - - error = git_config__get_string_buf(out, cfg, "core.notesref"); - - if (error == GIT_ENOTFOUND) - error = git_str_puts(out, GIT_NOTES_DEFAULT_REF); - - return error; -} - -static int normalize_namespace(git_str *out, git_repository *repo, const char *notes_ref) -{ - if (notes_ref) - return git_str_puts(out, notes_ref); - - return note_get_default_ref(out, repo); -} - -static int retrieve_note_commit( - git_commit **commit_out, - git_str *notes_ref_out, - git_repository *repo, - const char *notes_ref) -{ - int error; - git_oid oid; - - if ((error = normalize_namespace(notes_ref_out, repo, notes_ref)) < 0) - return error; - - if ((error = git_reference_name_to_id(&oid, repo, notes_ref_out->ptr)) < 0) - return error; - - if (git_commit_lookup(commit_out, repo, &oid) < 0) - return error; - - return 0; -} - -int git_note_commit_read( - git_note **out, - git_repository *repo, - git_commit *notes_commit, - const git_oid *oid) -{ - int error; - git_tree *tree = NULL; - char target[GIT_OID_MAX_HEXSIZE + 1]; - - git_oid_tostr(target, sizeof(target), oid); - - if ((error = git_commit_tree(&tree, notes_commit)) < 0) - goto cleanup; - - error = note_lookup(out, repo, notes_commit, tree, target); - -cleanup: - git_tree_free(tree); - return error; -} - -int git_note_read(git_note **out, git_repository *repo, - const char *notes_ref_in, const git_oid *oid) -{ - int error; - git_str notes_ref = GIT_STR_INIT; - git_commit *commit = NULL; - - error = retrieve_note_commit(&commit, ¬es_ref, repo, notes_ref_in); - - if (error < 0) - goto cleanup; - - error = git_note_commit_read(out, repo, commit, oid); - -cleanup: - git_str_dispose(¬es_ref); - git_commit_free(commit); - return error; -} - -int git_note_commit_create( - git_oid *notes_commit_out, - git_oid *notes_blob_out, - git_repository *repo, - git_commit *parent, - const git_signature *author, - const git_signature *committer, - const git_oid *oid, - const char *note, - int allow_note_overwrite) -{ - int error; - git_tree *tree = NULL; - char target[GIT_OID_MAX_HEXSIZE + 1]; - - git_oid_tostr(target, sizeof(target), oid); - - if (parent != NULL && (error = git_commit_tree(&tree, parent)) < 0) - goto cleanup; - - error = note_write(notes_commit_out, notes_blob_out, repo, author, - committer, NULL, note, tree, target, &parent, allow_note_overwrite); - - if (error < 0) - goto cleanup; - -cleanup: - git_tree_free(tree); - return error; -} - -int git_note_create( - git_oid *out, - git_repository *repo, - const char *notes_ref_in, - const git_signature *author, - const git_signature *committer, - const git_oid *oid, - const char *note, - int allow_note_overwrite) -{ - int error; - git_str notes_ref = GIT_STR_INIT; - git_commit *existing_notes_commit = NULL; - git_reference *ref = NULL; - git_oid notes_blob_oid, notes_commit_oid; - - error = retrieve_note_commit(&existing_notes_commit, ¬es_ref, - repo, notes_ref_in); - - if (error < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - error = git_note_commit_create(¬es_commit_oid, - ¬es_blob_oid, - repo, existing_notes_commit, author, - committer, oid, note, - allow_note_overwrite); - if (error < 0) - goto cleanup; - - error = git_reference_create(&ref, repo, notes_ref.ptr, - ¬es_commit_oid, 1, NULL); - - if (out != NULL) - git_oid_cpy(out, ¬es_blob_oid); - -cleanup: - git_str_dispose(¬es_ref); - git_commit_free(existing_notes_commit); - git_reference_free(ref); - return error; -} - -int git_note_commit_remove( - git_oid *notes_commit_out, - git_repository *repo, - git_commit *notes_commit, - const git_signature *author, - const git_signature *committer, - const git_oid *oid) -{ - int error; - git_tree *tree = NULL; - char target[GIT_OID_MAX_HEXSIZE + 1]; - - git_oid_tostr(target, sizeof(target), oid); - - if ((error = git_commit_tree(&tree, notes_commit)) < 0) - goto cleanup; - - error = note_remove(notes_commit_out, - repo, author, committer, NULL, tree, target, ¬es_commit); - -cleanup: - git_tree_free(tree); - return error; -} - -int git_note_remove(git_repository *repo, const char *notes_ref_in, - const git_signature *author, const git_signature *committer, - const git_oid *oid) -{ - int error; - git_str notes_ref_target = GIT_STR_INIT; - git_commit *existing_notes_commit = NULL; - git_oid new_notes_commit; - git_reference *notes_ref = NULL; - - error = retrieve_note_commit(&existing_notes_commit, ¬es_ref_target, - repo, notes_ref_in); - - if (error < 0) - goto cleanup; - - error = git_note_commit_remove(&new_notes_commit, repo, - existing_notes_commit, author, committer, oid); - if (error < 0) - goto cleanup; - - error = git_reference_create(¬es_ref, repo, notes_ref_target.ptr, - &new_notes_commit, 1, NULL); - -cleanup: - git_str_dispose(¬es_ref_target); - git_reference_free(notes_ref); - git_commit_free(existing_notes_commit); - return error; -} - -int git_note_default_ref(git_buf *out, git_repository *repo) -{ - GIT_BUF_WRAP_PRIVATE(out, note_get_default_ref, repo); -} - -const git_signature *git_note_committer(const git_note *note) -{ - GIT_ASSERT_ARG_WITH_RETVAL(note, NULL); - return note->committer; -} - -const git_signature *git_note_author(const git_note *note) -{ - GIT_ASSERT_ARG_WITH_RETVAL(note, NULL); - return note->author; -} - -const char *git_note_message(const git_note *note) -{ - GIT_ASSERT_ARG_WITH_RETVAL(note, NULL); - return note->message; -} - -const git_oid *git_note_id(const git_note *note) -{ - GIT_ASSERT_ARG_WITH_RETVAL(note, NULL); - return ¬e->id; -} - -void git_note_free(git_note *note) -{ - if (note == NULL) - return; - - git_signature_free(note->committer); - git_signature_free(note->author); - git__free(note->message); - git__free(note); -} - -static int process_entry_path( - git_oid *annotated_object_id, - git_note_iterator *it, - const char *entry_path) -{ - int error = 0; - size_t i = 0, j = 0, len; - git_str buf = GIT_STR_INIT; - - if ((error = git_str_puts(&buf, entry_path)) < 0) - goto cleanup; - - len = git_str_len(&buf); - - while (i < len) { - if (buf.ptr[i] == '/') { - i++; - continue; - } - - if (git__fromhex(buf.ptr[i]) < 0) { - /* This is not a note entry */ - goto cleanup; - } - - if (i != j) - buf.ptr[j] = buf.ptr[i]; - - i++; - j++; - } - - buf.ptr[j] = '\0'; - buf.size = j; - - if (j != git_oid_hexsize(it->repo->oid_type)) { - /* This is not a note entry */ - goto cleanup; - } - - error = git_oid__fromstr(annotated_object_id, buf.ptr, it->repo->oid_type); - -cleanup: - git_str_dispose(&buf); - return error; -} - -int git_note_foreach( - git_repository *repo, - const char *notes_ref, - git_note_foreach_cb note_cb, - void *payload) -{ - int error; - git_note_iterator *iter = NULL; - git_oid note_id, annotated_id; - - if ((error = git_note_iterator_new(&iter, repo, notes_ref)) < 0) - return error; - - while (!(error = git_note_next(¬e_id, &annotated_id, iter))) { - if ((error = note_cb(¬e_id, &annotated_id, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - if (error == GIT_ITEROVER) - error = 0; - - git_note_iterator_free(iter); - return error; -} - -void git_note_iterator_free(git_note_iterator *it) -{ - if (it == NULL) - return; - - git_iterator_free(it); -} - -int git_note_commit_iterator_new( - git_note_iterator **it, - git_commit *notes_commit) -{ - int error; - git_tree *tree; - - if ((error = git_commit_tree(&tree, notes_commit)) < 0) - goto cleanup; - - if ((error = git_iterator_for_tree(it, tree, NULL)) < 0) - git_iterator_free(*it); - -cleanup: - git_tree_free(tree); - - return error; -} - -int git_note_iterator_new( - git_note_iterator **it, - git_repository *repo, - const char *notes_ref_in) -{ - int error; - git_commit *commit = NULL; - git_str notes_ref = GIT_STR_INIT; - - error = retrieve_note_commit(&commit, ¬es_ref, repo, notes_ref_in); - if (error < 0) - goto cleanup; - - error = git_note_commit_iterator_new(it, commit); - -cleanup: - git_str_dispose(¬es_ref); - git_commit_free(commit); - - return error; -} - -int git_note_next( - git_oid *note_id, - git_oid *annotated_id, - git_note_iterator *it) -{ - int error; - const git_index_entry *item; - - if ((error = git_iterator_current(&item, it)) < 0) - return error; - - git_oid_cpy(note_id, &item->id); - - if ((error = process_entry_path(annotated_id, it, item->path)) < 0) - return error; - - if ((error = git_iterator_advance(NULL, it)) < 0 && error != GIT_ITEROVER) - return error; - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/notes.h b/vendor/libgit2-sys/libgit2/src/libgit2/notes.h deleted file mode 100644 index 2168e45..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/notes.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_note_h__ -#define INCLUDE_note_h__ - -#include "common.h" - -#include "git2/oid.h" -#include "git2/types.h" - -#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" - -#define GIT_NOTES_DEFAULT_MSG_ADD \ - "Notes added by 'git_note_create' from libgit2" - -#define GIT_NOTES_DEFAULT_MSG_RM \ - "Notes removed by 'git_note_remove' from libgit2" - -struct git_note { - git_oid id; - - git_signature *author; - git_signature *committer; - - char *message; -}; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/object.c b/vendor/libgit2-sys/libgit2/src/libgit2/object.c deleted file mode 100644 index 36665c6..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/object.c +++ /dev/null @@ -1,692 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "object.h" - -#include "git2/object.h" - -#include "repository.h" - -#include "buf.h" -#include "commit.h" -#include "hash.h" -#include "tree.h" -#include "blob.h" -#include "oid.h" -#include "tag.h" - -bool git_object__strict_input_validation = true; - -size_t git_object__size(git_object_t type); - -typedef struct { - const char *str; /* type name string */ - size_t size; /* size in bytes of the object structure */ - - int (*parse)(void *self, git_odb_object *obj, git_oid_t oid_type); - int (*parse_raw)(void *self, const char *data, size_t size, git_oid_t oid_type); - void (*free)(void *self); -} git_object_def; - -static git_object_def git_objects_table[] = { - /* 0 = GIT_OBJECT__EXT1 */ - { "", 0, NULL, NULL, NULL }, - - /* 1 = GIT_OBJECT_COMMIT */ - { "commit", sizeof(git_commit), git_commit__parse, git_commit__parse_raw, git_commit__free }, - - /* 2 = GIT_OBJECT_TREE */ - { "tree", sizeof(git_tree), git_tree__parse, git_tree__parse_raw, git_tree__free }, - - /* 3 = GIT_OBJECT_BLOB */ - { "blob", sizeof(git_blob), git_blob__parse, git_blob__parse_raw, git_blob__free }, - - /* 4 = GIT_OBJECT_TAG */ - { "tag", sizeof(git_tag), git_tag__parse, git_tag__parse_raw, git_tag__free }, - - /* 5 = GIT_OBJECT__EXT2 */ - { "", 0, NULL, NULL, NULL }, - /* 6 = GIT_OBJECT_OFS_DELTA */ - { "OFS_DELTA", 0, NULL, NULL, NULL }, - /* 7 = GIT_OBJECT_REF_DELTA */ - { "REF_DELTA", 0, NULL, NULL, NULL }, -}; - -int git_object__from_raw( - git_object **object_out, - const char *data, - size_t size, - git_object_t object_type, - git_oid_t oid_type) -{ - git_object_def *def; - git_object *object; - size_t object_size; - int error; - - GIT_ASSERT_ARG(object_out); - *object_out = NULL; - - /* Validate type match */ - if (object_type != GIT_OBJECT_BLOB && - object_type != GIT_OBJECT_TREE && - object_type != GIT_OBJECT_COMMIT && - object_type != GIT_OBJECT_TAG) { - git_error_set(GIT_ERROR_INVALID, "the requested type is invalid"); - return GIT_ENOTFOUND; - } - - if ((object_size = git_object__size(object_type)) == 0) { - git_error_set(GIT_ERROR_INVALID, "the requested type is invalid"); - return GIT_ENOTFOUND; - } - - /* Allocate and initialize base object */ - object = git__calloc(1, object_size); - GIT_ERROR_CHECK_ALLOC(object); - object->cached.flags = GIT_CACHE_STORE_PARSED; - object->cached.type = object_type; - if ((error = git_odb__hash(&object->cached.oid, data, size, object_type, oid_type)) < 0) - return error; - - /* Parse raw object data */ - def = &git_objects_table[object_type]; - GIT_ASSERT(def->free && def->parse_raw); - - if ((error = def->parse_raw(object, data, size, oid_type)) < 0) { - def->free(object); - return error; - } - - git_cached_obj_incref(object); - *object_out = object; - - return 0; -} - -int git_object__init_from_odb_object( - git_object **object_out, - git_repository *repo, - git_odb_object *odb_obj, - git_object_t type) -{ - size_t object_size; - git_object *object = NULL; - - GIT_ASSERT_ARG(object_out); - *object_out = NULL; - - /* Validate type match */ - if (type != GIT_OBJECT_ANY && type != odb_obj->cached.type) { - git_error_set(GIT_ERROR_INVALID, - "the requested type does not match the type in the ODB"); - return GIT_ENOTFOUND; - } - - if ((object_size = git_object__size(odb_obj->cached.type)) == 0) { - git_error_set(GIT_ERROR_INVALID, "the requested type is invalid"); - return GIT_ENOTFOUND; - } - - /* Allocate and initialize base object */ - object = git__calloc(1, object_size); - GIT_ERROR_CHECK_ALLOC(object); - - git_oid_cpy(&object->cached.oid, &odb_obj->cached.oid); - object->cached.type = odb_obj->cached.type; - object->cached.size = odb_obj->cached.size; - object->repo = repo; - - *object_out = object; - return 0; -} - -int git_object__from_odb_object( - git_object **object_out, - git_repository *repo, - git_odb_object *odb_obj, - git_object_t type) -{ - int error; - git_object_def *def; - git_object *object = NULL; - - if ((error = git_object__init_from_odb_object(&object, repo, odb_obj, type)) < 0) - return error; - - /* Parse raw object data */ - def = &git_objects_table[odb_obj->cached.type]; - GIT_ASSERT(def->free && def->parse); - - if ((error = def->parse(object, odb_obj, repo->oid_type)) < 0) { - /* - * parse returns EINVALID on invalid data; downgrade - * that to a normal -1 error code. - */ - def->free(object); - return -1; - } - - *object_out = git_cache_store_parsed(&repo->objects, object); - return 0; -} - -void git_object__free(void *obj) -{ - git_object_t type = ((git_object *)obj)->cached.type; - - if (type < 0 || ((size_t)type) >= ARRAY_SIZE(git_objects_table) || - !git_objects_table[type].free) - git__free(obj); - else - git_objects_table[type].free(obj); -} - -int git_object_lookup_prefix( - git_object **object_out, - git_repository *repo, - const git_oid *id, - size_t len, - git_object_t type) -{ - git_object *object = NULL; - git_odb *odb = NULL; - git_odb_object *odb_obj = NULL; - size_t oid_hexsize; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(object_out); - GIT_ASSERT_ARG(id); - - if (len < GIT_OID_MINPREFIXLEN) { - git_error_set(GIT_ERROR_OBJECT, "ambiguous lookup - OID prefix is too short"); - return GIT_EAMBIGUOUS; - } - - error = git_repository_odb__weakptr(&odb, repo); - if (error < 0) - return error; - - oid_hexsize = git_oid_hexsize(repo->oid_type); - - if (len > oid_hexsize) - len = oid_hexsize; - - if (len == oid_hexsize) { - git_cached_obj *cached = NULL; - - /* We want to match the full id : we can first look up in the cache, - * since there is no need to check for non ambiguousity - */ - cached = git_cache_get_any(&repo->objects, id); - if (cached != NULL) { - if (cached->flags == GIT_CACHE_STORE_PARSED) { - object = (git_object *)cached; - - if (type != GIT_OBJECT_ANY && type != object->cached.type) { - git_object_free(object); - git_error_set(GIT_ERROR_INVALID, - "the requested type does not match the type in the ODB"); - return GIT_ENOTFOUND; - } - - *object_out = object; - return 0; - } else if (cached->flags == GIT_CACHE_STORE_RAW) { - odb_obj = (git_odb_object *)cached; - } else { - GIT_ASSERT(!"Wrong caching type in the global object cache"); - } - } else { - /* Object was not found in the cache, let's explore the backends. - * We could just use git_odb_read_unique_short_oid, - * it is the same cost for packed and loose object backends, - * but it may be much more costly for sqlite and hiredis. - */ - error = git_odb_read(&odb_obj, odb, id); - } - } else { - git_oid short_oid; - - git_oid_clear(&short_oid, repo->oid_type); - git_oid__cpy_prefix(&short_oid, id, len); - - /* If len < GIT_OID_SHA1_HEXSIZE (a strict short oid was given), we have - * 2 options : - * - We always search in the cache first. If we find that short oid is - * ambiguous, we can stop. But in all the other cases, we must then - * explore all the backends (to find an object if there was match, - * or to check that oid is not ambiguous if we have found 1 match in - * the cache) - * - We never explore the cache, go right to exploring the backends - * We chose the latter : we explore directly the backends. - */ - error = git_odb_read_prefix(&odb_obj, odb, &short_oid, len); - } - - if (error < 0) - return error; - - GIT_ASSERT(odb_obj); - error = git_object__from_odb_object(object_out, repo, odb_obj, type); - - git_odb_object_free(odb_obj); - - return error; -} - -int git_object_lookup(git_object **object_out, git_repository *repo, const git_oid *id, git_object_t type) { - return git_object_lookup_prefix(object_out, - repo, id, git_oid_hexsize(repo->oid_type), type); -} - -void git_object_free(git_object *object) -{ - if (object == NULL) - return; - - git_cached_obj_decref(object); -} - -const git_oid *git_object_id(const git_object *obj) -{ - GIT_ASSERT_ARG_WITH_RETVAL(obj, NULL); - return &obj->cached.oid; -} - -git_object_t git_object_type(const git_object *obj) -{ - GIT_ASSERT_ARG_WITH_RETVAL(obj, GIT_OBJECT_INVALID); - return obj->cached.type; -} - -git_repository *git_object_owner(const git_object *obj) -{ - GIT_ASSERT_ARG_WITH_RETVAL(obj, NULL); - return obj->repo; -} - -const char *git_object_type2string(git_object_t type) -{ - if (type < 0 || ((size_t) type) >= ARRAY_SIZE(git_objects_table)) - return ""; - - return git_objects_table[type].str; -} - -git_object_t git_object_string2type(const char *str) -{ - if (!str) - return GIT_OBJECT_INVALID; - - return git_object_stringn2type(str, strlen(str)); -} - -git_object_t git_object_stringn2type(const char *str, size_t len) -{ - size_t i; - - if (!str || !len || !*str) - return GIT_OBJECT_INVALID; - - for (i = 0; i < ARRAY_SIZE(git_objects_table); i++) - if (*git_objects_table[i].str && - !git__prefixncmp(str, len, git_objects_table[i].str)) - return (git_object_t)i; - - return GIT_OBJECT_INVALID; -} - -int git_object_typeisloose(git_object_t type) -{ - if (type < 0 || ((size_t) type) >= ARRAY_SIZE(git_objects_table)) - return 0; - - return (git_objects_table[type].size > 0) ? 1 : 0; -} - -size_t git_object__size(git_object_t type) -{ - if (type < 0 || ((size_t) type) >= ARRAY_SIZE(git_objects_table)) - return 0; - - return git_objects_table[type].size; -} - -static int dereference_object(git_object **dereferenced, git_object *obj) -{ - git_object_t type = git_object_type(obj); - - switch (type) { - case GIT_OBJECT_COMMIT: - return git_commit_tree((git_tree **)dereferenced, (git_commit*)obj); - - case GIT_OBJECT_TAG: - return git_tag_target(dereferenced, (git_tag*)obj); - - case GIT_OBJECT_BLOB: - case GIT_OBJECT_TREE: - return GIT_EPEEL; - - default: - return GIT_EINVALIDSPEC; - } -} - -static int peel_error(int error, const git_oid *oid, git_object_t type) -{ - const char *type_name; - char hex_oid[GIT_OID_MAX_HEXSIZE + 1]; - - type_name = git_object_type2string(type); - - git_oid_nfmt(hex_oid, GIT_OID_MAX_HEXSIZE + 1, oid); - - git_error_set(GIT_ERROR_OBJECT, "the git_object of id '%s' can not be " - "successfully peeled into a %s (git_object_t=%i).", hex_oid, type_name, type); - - return error; -} - -static int check_type_combination(git_object_t type, git_object_t target) -{ - if (type == target) - return 0; - - switch (type) { - case GIT_OBJECT_BLOB: - case GIT_OBJECT_TREE: - /* a blob or tree can never be peeled to anything but themselves */ - return GIT_EINVALIDSPEC; - break; - case GIT_OBJECT_COMMIT: - /* a commit can only be peeled to a tree */ - if (target != GIT_OBJECT_TREE && target != GIT_OBJECT_ANY) - return GIT_EINVALIDSPEC; - break; - case GIT_OBJECT_TAG: - /* a tag may point to anything, so we let anything through */ - break; - default: - return GIT_EINVALIDSPEC; - } - - return 0; -} - -int git_object_peel( - git_object **peeled, - const git_object *object, - git_object_t target_type) -{ - git_object *source, *deref = NULL; - int error; - - GIT_ASSERT_ARG(object); - GIT_ASSERT_ARG(peeled); - - GIT_ASSERT_ARG(target_type == GIT_OBJECT_TAG || - target_type == GIT_OBJECT_COMMIT || - target_type == GIT_OBJECT_TREE || - target_type == GIT_OBJECT_BLOB || - target_type == GIT_OBJECT_ANY); - - if ((error = check_type_combination(git_object_type(object), target_type)) < 0) - return peel_error(error, git_object_id(object), target_type); - - if (git_object_type(object) == target_type) - return git_object_dup(peeled, (git_object *)object); - - source = (git_object *)object; - - while (!(error = dereference_object(&deref, source))) { - - if (source != object) - git_object_free(source); - - if (git_object_type(deref) == target_type) { - *peeled = deref; - return 0; - } - - if (target_type == GIT_OBJECT_ANY && - git_object_type(deref) != git_object_type(object)) - { - *peeled = deref; - return 0; - } - - source = deref; - deref = NULL; - } - - if (source != object) - git_object_free(source); - - git_object_free(deref); - - if (error) - error = peel_error(error, git_object_id(object), target_type); - - return error; -} - -int git_object_dup(git_object **dest, git_object *source) -{ - git_cached_obj_incref(source); - *dest = source; - return 0; -} - -int git_object_lookup_bypath( - git_object **out, - const git_object *treeish, - const char *path, - git_object_t type) -{ - int error = -1; - git_tree *tree = NULL; - git_tree_entry *entry = NULL; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(treeish); - GIT_ASSERT_ARG(path); - - if ((error = git_object_peel((git_object**)&tree, treeish, GIT_OBJECT_TREE)) < 0 || - (error = git_tree_entry_bypath(&entry, tree, path)) < 0) - { - goto cleanup; - } - - if (type != GIT_OBJECT_ANY && git_tree_entry_type(entry) != type) - { - git_error_set(GIT_ERROR_OBJECT, - "object at path '%s' is not of the asked-for type %d", - path, type); - error = GIT_EINVALIDSPEC; - goto cleanup; - } - - error = git_tree_entry_to_object(out, git_object_owner(treeish), entry); - -cleanup: - git_tree_entry_free(entry); - git_tree_free(tree); - return error; -} - -static int git_object__short_id(git_str *out, const git_object *obj) -{ - git_repository *repo; - git_oid id; - git_odb *odb; - size_t oid_hexsize; - int len, error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(obj); - - repo = git_object_owner(obj); - - git_oid_clear(&id, repo->oid_type); - oid_hexsize = git_oid_hexsize(repo->oid_type); - - if ((error = git_repository__abbrev_length(&len, repo)) < 0) - return error; - - if ((size_t)len == oid_hexsize) { - if ((error = git_oid_cpy(&id, &obj->cached.oid)) < 0) { - return error; - } - } - - if ((error = git_repository_odb(&odb, repo)) < 0) - return error; - - while ((size_t)len < oid_hexsize) { - /* set up short oid */ - memcpy(&id.id, &obj->cached.oid.id, (len + 1) / 2); - if (len & 1) - id.id[len / 2] &= 0xf0; - - error = git_odb_exists_prefix(NULL, odb, &id, len); - if (error != GIT_EAMBIGUOUS) - break; - - git_error_clear(); - len++; - } - - if (!error && !(error = git_str_grow(out, len + 1))) { - git_oid_tostr(out->ptr, len + 1, &id); - out->size = len; - } - - git_odb_free(odb); - - return error; -} - -int git_object_short_id(git_buf *out, const git_object *obj) -{ - GIT_BUF_WRAP_PRIVATE(out, git_object__short_id, obj); -} - -bool git_object__is_valid( - git_repository *repo, const git_oid *id, git_object_t expected_type) -{ - git_odb *odb; - git_object_t actual_type; - size_t len; - int error; - - if (!git_object__strict_input_validation) - return true; - - if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 || - (error = git_odb_read_header(&len, &actual_type, odb, id)) < 0) - return false; - - if (expected_type != GIT_OBJECT_ANY && expected_type != actual_type) { - git_error_set(GIT_ERROR_INVALID, - "the requested type does not match the type in the ODB"); - return false; - } - - return true; -} - -int git_object_rawcontent_is_valid( - int *valid, - const char *buf, - size_t len, - git_object_t object_type -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_oid_t oid_type -#endif - ) -{ - git_object *obj = NULL; - int error; - -#ifndef GIT_EXPERIMENTAL_SHA256 - git_oid_t oid_type = GIT_OID_SHA1; -#endif - - GIT_ASSERT_ARG(valid); - GIT_ASSERT_ARG(buf); - - /* Blobs are always valid; don't bother parsing. */ - if (object_type == GIT_OBJECT_BLOB) { - *valid = 1; - return 0; - } - - error = git_object__from_raw(&obj, buf, len, object_type, oid_type); - git_object_free(obj); - - if (error == 0) { - *valid = 1; - return 0; - } else if (error == GIT_EINVALID) { - *valid = 0; - return 0; - } - - return error; -} - -int git_object__parse_oid_header( - git_oid *oid, - const char **buffer_out, - const char *buffer_end, - const char *header, - git_oid_t oid_type) -{ - const size_t sha_len = git_oid_hexsize(oid_type); - const size_t header_len = strlen(header); - - const char *buffer = *buffer_out; - - if (buffer + (header_len + sha_len + 1) > buffer_end) - return -1; - - if (memcmp(buffer, header, header_len) != 0) - return -1; - - if (buffer[header_len + sha_len] != '\n') - return -1; - - if (git_oid__fromstr(oid, buffer + header_len, oid_type) < 0) - return -1; - - *buffer_out = buffer + (header_len + sha_len + 1); - - return 0; -} - -int git_object__write_oid_header( - git_str *buf, - const char *header, - const git_oid *oid) -{ - size_t hex_size = git_oid_hexsize(git_oid_type(oid)); - char hex_oid[GIT_OID_MAX_HEXSIZE]; - - if (!hex_size) { - git_error_set(GIT_ERROR_INVALID, "unknown type"); - return -1; - } - - git_oid_fmt(hex_oid, oid); - git_str_puts(buf, header); - git_str_put(buf, hex_oid, hex_size); - git_str_putc(buf, '\n'); - - return git_str_oom(buf) ? -1 : 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/object.h b/vendor/libgit2-sys/libgit2/src/libgit2/object.h deleted file mode 100644 index b6c604c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/object.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_object_h__ -#define INCLUDE_object_h__ - -#include "common.h" - -#include "repository.h" - -#define GIT_OBJECT_SIZE_MAX UINT64_MAX - -extern bool git_object__strict_input_validation; - -/** Base git object for inheritance */ -struct git_object { - git_cached_obj cached; - git_repository *repo; -}; - -/* fully free the object; internal method, DO NOT EXPORT */ -void git_object__free(void *object); - -/* - * Parse object from raw data. Note that the resulting object is - * tied to the lifetime of the data, as some objects simply point - * into it. - */ -int git_object__from_raw( - git_object **object_out, - const char *data, - size_t size, - git_object_t object_type, - git_oid_t oid_type); - -int git_object__init_from_odb_object( - git_object **object_out, - git_repository *repo, - git_odb_object *odb_obj, - git_object_t type); - -int git_object__from_odb_object( - git_object **object_out, - git_repository *repo, - git_odb_object *odb_obj, - git_object_t type); - -int git_object__resolve_to_type(git_object **obj, git_object_t type); - -git_object_t git_object_stringn2type(const char *str, size_t len); - -int git_object__parse_oid_header( - git_oid *oid, - const char **buffer_out, - const char *buffer_end, - const char *header, - git_oid_t oid_type); - -int git_object__write_oid_header( - git_str *buf, - const char *header, - const git_oid *oid); - -bool git_object__is_valid( - git_repository *repo, const git_oid *id, git_object_t expected_type); - -GIT_INLINE(git_object_t) git_object__type_from_filemode(git_filemode_t mode) -{ - switch (mode) { - case GIT_FILEMODE_TREE: - return GIT_OBJECT_TREE; - case GIT_FILEMODE_COMMIT: - return GIT_OBJECT_COMMIT; - case GIT_FILEMODE_BLOB: - case GIT_FILEMODE_BLOB_EXECUTABLE: - case GIT_FILEMODE_LINK: - return GIT_OBJECT_BLOB; - default: - return GIT_OBJECT_INVALID; - } -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/object_api.c b/vendor/libgit2-sys/libgit2/src/libgit2/object_api.c deleted file mode 100644 index d45abd5..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/object_api.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/object.h" - -#include "repository.h" -#include "commit.h" -#include "tree.h" -#include "blob.h" -#include "tag.h" - -/** - * Commit - */ -int git_commit_lookup(git_commit **out, git_repository *repo, const git_oid *id) -{ - return git_object_lookup((git_object **)out, repo, id, GIT_OBJECT_COMMIT); -} - -int git_commit_lookup_prefix(git_commit **out, git_repository *repo, const git_oid *id, size_t len) -{ - return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJECT_COMMIT); -} - -void git_commit_free(git_commit *obj) -{ - git_object_free((git_object *)obj); -} - -const git_oid *git_commit_id(const git_commit *obj) -{ - return git_object_id((const git_object *)obj); -} - -git_repository *git_commit_owner(const git_commit *obj) -{ - return git_object_owner((const git_object *)obj); -} - -int git_commit_dup(git_commit **out, git_commit *obj) -{ - return git_object_dup((git_object **)out, (git_object *)obj); -} - -/** - * Tree - */ -int git_tree_lookup(git_tree **out, git_repository *repo, const git_oid *id) -{ - return git_object_lookup((git_object **)out, repo, id, GIT_OBJECT_TREE); -} - -int git_tree_lookup_prefix(git_tree **out, git_repository *repo, const git_oid *id, size_t len) -{ - return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJECT_TREE); -} - -void git_tree_free(git_tree *obj) -{ - git_object_free((git_object *)obj); -} - -const git_oid *git_tree_id(const git_tree *obj) -{ - return git_object_id((const git_object *)obj); -} - -git_repository *git_tree_owner(const git_tree *obj) -{ - return git_object_owner((const git_object *)obj); -} - -int git_tree_dup(git_tree **out, git_tree *obj) -{ - return git_object_dup((git_object **)out, (git_object *)obj); -} - -/** - * Tag - */ -int git_tag_lookup(git_tag **out, git_repository *repo, const git_oid *id) -{ - return git_object_lookup((git_object **)out, repo, id, GIT_OBJECT_TAG); -} - -int git_tag_lookup_prefix(git_tag **out, git_repository *repo, const git_oid *id, size_t len) -{ - return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJECT_TAG); -} - -void git_tag_free(git_tag *obj) -{ - git_object_free((git_object *)obj); -} - -const git_oid *git_tag_id(const git_tag *obj) -{ - return git_object_id((const git_object *)obj); -} - -git_repository *git_tag_owner(const git_tag *obj) -{ - return git_object_owner((const git_object *)obj); -} - -int git_tag_dup(git_tag **out, git_tag *obj) -{ - return git_object_dup((git_object **)out, (git_object *)obj); -} - -/** - * Blob - */ -int git_blob_lookup(git_blob **out, git_repository *repo, const git_oid *id) -{ - return git_object_lookup((git_object **)out, repo, id, GIT_OBJECT_BLOB); -} - -int git_blob_lookup_prefix(git_blob **out, git_repository *repo, const git_oid *id, size_t len) -{ - return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJECT_BLOB); -} - -void git_blob_free(git_blob *obj) -{ - git_object_free((git_object *)obj); -} - -const git_oid *git_blob_id(const git_blob *obj) -{ - return git_object_id((const git_object *)obj); -} - -git_repository *git_blob_owner(const git_blob *obj) -{ - return git_object_owner((const git_object *)obj); -} - -int git_blob_dup(git_blob **out, git_blob *obj) -{ - return git_object_dup((git_object **)out, (git_object *)obj); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/odb.c b/vendor/libgit2-sys/libgit2/src/libgit2/odb.c deleted file mode 100644 index 653c7c0..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/odb.c +++ /dev/null @@ -1,1997 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "odb.h" - -#include -#include "git2/object.h" -#include "git2/sys/odb_backend.h" -#include "futils.h" -#include "hash.h" -#include "delta.h" -#include "filter.h" -#include "repository.h" -#include "blob.h" -#include "oid.h" - -#include "git2/odb_backend.h" -#include "git2/oid.h" -#include "git2/oidarray.h" - -#define GIT_ALTERNATES_FILE "info/alternates" - -#define GIT_ALTERNATES_MAX_DEPTH 5 - -/* - * We work under the assumption that most objects for long-running - * operations will be packed - */ -int git_odb__loose_priority = GIT_ODB_DEFAULT_LOOSE_PRIORITY; -int git_odb__packed_priority = GIT_ODB_DEFAULT_PACKED_PRIORITY; - -bool git_odb__strict_hash_verification = true; - -typedef struct -{ - git_odb_backend *backend; - int priority; - bool is_alternate; - ino_t disk_inode; -} backend_internal; - -static git_cache *odb_cache(git_odb *odb) -{ - git_repository *owner = GIT_REFCOUNT_OWNER(odb); - if (owner != NULL) { - return &owner->objects; - } - - return &odb->own_cache; -} - -static int odb_otype_fast(git_object_t *type_p, git_odb *db, const git_oid *id); -static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_depth); -static int error_null_oid(int error, const char *message); - -static git_object_t odb_hardcoded_type(const git_oid *id) -{ - if (!git_oid_cmp(id, &git_oid__empty_tree_sha1)) - return GIT_OBJECT_TREE; - - return GIT_OBJECT_INVALID; -} - -static int odb_read_hardcoded(bool *found, git_rawobj *raw, const git_oid *id) -{ - git_object_t type; - - *found = false; - - if ((type = odb_hardcoded_type(id)) == GIT_OBJECT_INVALID) - return 0; - - raw->type = type; - raw->len = 0; - raw->data = git__calloc(1, sizeof(uint8_t)); - GIT_ERROR_CHECK_ALLOC(raw->data); - - *found = true; - return 0; -} - -int git_odb__format_object_header( - size_t *written, - char *hdr, - size_t hdr_size, - git_object_size_t obj_len, - git_object_t obj_type) -{ - const char *type_str = git_object_type2string(obj_type); - int hdr_max = (hdr_size > INT_MAX-2) ? (INT_MAX-2) : (int)hdr_size; - int len; - - len = p_snprintf(hdr, hdr_max, "%s %"PRId64, type_str, (int64_t)obj_len); - - if (len < 0 || len >= hdr_max) { - git_error_set(GIT_ERROR_OS, "object header creation failed"); - return -1; - } - - *written = (size_t)(len + 1); - return 0; -} - -int git_odb__hashobj(git_oid *id, git_rawobj *obj, git_oid_t oid_type) -{ - git_str_vec vec[2]; - char header[64]; - size_t hdrlen; - git_hash_algorithm_t algorithm; - int error; - - GIT_ASSERT_ARG(id); - GIT_ASSERT_ARG(obj); - - if (!git_object_typeisloose(obj->type)) { - git_error_set(GIT_ERROR_INVALID, "invalid object type"); - return -1; - } - - if (!(algorithm = git_oid_algorithm(oid_type))) { - git_error_set(GIT_ERROR_INVALID, "unknown oid type"); - return -1; - } - - if (!obj->data && obj->len != 0) { - git_error_set(GIT_ERROR_INVALID, "invalid object"); - return -1; - } - - if ((error = git_odb__format_object_header(&hdrlen, - header, sizeof(header), obj->len, obj->type)) < 0) - return error; - - vec[0].data = header; - vec[0].len = hdrlen; - vec[1].data = obj->data; - vec[1].len = obj->len; - -#ifdef GIT_EXPERIMENTAL_SHA256 - id->type = oid_type; -#endif - - return git_hash_vec(id->id, vec, 2, algorithm); -} - - -static git_odb_object *odb_object__alloc(const git_oid *oid, git_rawobj *source) -{ - git_odb_object *object = git__calloc(1, sizeof(git_odb_object)); - - if (object != NULL) { - git_oid_cpy(&object->cached.oid, oid); - object->cached.type = source->type; - object->cached.size = source->len; - object->buffer = source->data; - } - - return object; -} - -void git_odb_object__free(void *object) -{ - if (object != NULL) { - git__free(((git_odb_object *)object)->buffer); - git__free(object); - } -} - -const git_oid *git_odb_object_id(git_odb_object *object) -{ - return &object->cached.oid; -} - -const void *git_odb_object_data(git_odb_object *object) -{ - return object->buffer; -} - -size_t git_odb_object_size(git_odb_object *object) -{ - return object->cached.size; -} - -git_object_t git_odb_object_type(git_odb_object *object) -{ - return object->cached.type; -} - -int git_odb_object_dup(git_odb_object **dest, git_odb_object *source) -{ - git_cached_obj_incref(source); - *dest = source; - return 0; -} - -void git_odb_object_free(git_odb_object *object) -{ - if (object == NULL) - return; - - git_cached_obj_decref(object); -} - -int git_odb__hashfd( - git_oid *out, - git_file fd, - size_t size, - git_object_t object_type, - git_oid_t oid_type) -{ - size_t hdr_len; - char hdr[64], buffer[GIT_BUFSIZE_FILEIO]; - git_hash_ctx ctx; - git_hash_algorithm_t algorithm; - ssize_t read_len = 0; - int error = 0; - - if (!git_object_typeisloose(object_type)) { - git_error_set(GIT_ERROR_INVALID, "invalid object type for hash"); - return -1; - } - - if (!(algorithm = git_oid_algorithm(oid_type))) { - git_error_set(GIT_ERROR_INVALID, "unknown oid type"); - return -1; - } - - if ((error = git_hash_ctx_init(&ctx, algorithm)) < 0) - return error; - - if ((error = git_odb__format_object_header(&hdr_len, hdr, - sizeof(hdr), size, object_type)) < 0) - goto done; - - if ((error = git_hash_update(&ctx, hdr, hdr_len)) < 0) - goto done; - - while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) { - if ((error = git_hash_update(&ctx, buffer, read_len)) < 0) - goto done; - - size -= read_len; - } - - /* If p_read returned an error code, the read obviously failed. - * If size is not zero, the file was truncated after we originally - * stat'd it, so we consider this a read failure too */ - if (read_len < 0 || size > 0) { - git_error_set(GIT_ERROR_OS, "error reading file for hashing"); - error = -1; - - goto done; - } - - error = git_hash_final(out->id, &ctx); - -#ifdef GIT_EXPERIMENTAL_SHA256 - out->type = oid_type; -#endif - -done: - git_hash_ctx_cleanup(&ctx); - return error; -} - -int git_odb__hashfd_filtered( - git_oid *out, - git_file fd, - size_t size, - git_object_t object_type, - git_oid_t oid_type, - git_filter_list *fl) -{ - int error; - git_str raw = GIT_STR_INIT; - - if (!fl) - return git_odb__hashfd(out, fd, size, object_type, oid_type); - - /* size of data is used in header, so we have to read the whole file - * into memory to apply filters before beginning to calculate the hash - */ - - if (!(error = git_futils_readbuffer_fd(&raw, fd, size))) { - git_str post = GIT_STR_INIT; - - error = git_filter_list__convert_buf(&post, fl, &raw); - - if (!error) - error = git_odb__hash(out, post.ptr, post.size, object_type, oid_type); - - git_str_dispose(&post); - } - - return error; -} - -int git_odb__hashlink(git_oid *out, const char *path, git_oid_t oid_type) -{ - struct stat st; - int size; - int result; - - if (git_fs_path_lstat(path, &st) < 0) - return -1; - - if (!git__is_int(st.st_size) || (int)st.st_size < 0) { - git_error_set(GIT_ERROR_FILESYSTEM, "file size overflow for 32-bit systems"); - return -1; - } - - size = (int)st.st_size; - - if (S_ISLNK(st.st_mode)) { - char *link_data; - int read_len; - size_t alloc_size; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, size, 1); - link_data = git__malloc(alloc_size); - GIT_ERROR_CHECK_ALLOC(link_data); - - read_len = p_readlink(path, link_data, size); - if (read_len == -1) { - git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", path); - git__free(link_data); - return -1; - } - GIT_ASSERT(read_len <= size); - link_data[read_len] = '\0'; - - result = git_odb__hash(out, link_data, read_len, GIT_OBJECT_BLOB, oid_type); - git__free(link_data); - } else { - int fd = git_futils_open_ro(path); - if (fd < 0) - return -1; - result = git_odb__hashfd(out, fd, size, GIT_OBJECT_BLOB, oid_type); - p_close(fd); - } - - return result; -} - -int git_odb__hashfile( - git_oid *out, - const char *path, - git_object_t object_type, - git_oid_t oid_type) -{ - uint64_t size; - int fd, error = 0; - - if ((fd = git_futils_open_ro(path)) < 0) - return fd; - - if ((error = git_futils_filesize(&size, fd)) < 0) - goto done; - - if (!git__is_sizet(size)) { - git_error_set(GIT_ERROR_OS, "file size overflow for 32-bit systems"); - error = -1; - goto done; - } - - error = git_odb__hashfd(out, fd, (size_t)size, object_type, oid_type); - -done: - p_close(fd); - return error; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_odb_hashfile( - git_oid *out, - const char *path, - git_object_t object_type, - git_oid_t oid_type) -{ - return git_odb__hashfile(out, path, object_type, oid_type); -} -#else -int git_odb_hashfile( - git_oid *out, - const char *path, - git_object_t object_type) -{ - return git_odb__hashfile(out, path, object_type, GIT_OID_SHA1); -} -#endif - -int git_odb__hash( - git_oid *id, - const void *data, - size_t len, - git_object_t object_type, - git_oid_t oid_type) -{ - git_rawobj raw; - - GIT_ASSERT_ARG(id); - - raw.data = (void *)data; - raw.len = len; - raw.type = object_type; - - return git_odb__hashobj(id, &raw, oid_type); -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_odb_hash( - git_oid *out, - const void *data, - size_t len, - git_object_t object_type, - git_oid_t oid_type) -{ - return git_odb__hash(out, data, len, object_type, oid_type); -} -#else -int git_odb_hash( - git_oid *out, - const void *data, - size_t len, - git_object_t type) -{ - return git_odb__hash(out, data, len, type, GIT_OID_SHA1); -} -#endif - -/** - * FAKE WSTREAM - */ - -typedef struct { - git_odb_stream stream; - char *buffer; - size_t size, written; - git_object_t type; -} fake_wstream; - -static int fake_wstream__fwrite(git_odb_stream *_stream, const git_oid *oid) -{ - fake_wstream *stream = (fake_wstream *)_stream; - return _stream->backend->write(_stream->backend, oid, stream->buffer, stream->size, stream->type); -} - -static int fake_wstream__write(git_odb_stream *_stream, const char *data, size_t len) -{ - fake_wstream *stream = (fake_wstream *)_stream; - - GIT_ASSERT(stream->written + len <= stream->size); - - memcpy(stream->buffer + stream->written, data, len); - stream->written += len; - return 0; -} - -static void fake_wstream__free(git_odb_stream *_stream) -{ - fake_wstream *stream = (fake_wstream *)_stream; - - git__free(stream->buffer); - git__free(stream); -} - -static int init_fake_wstream(git_odb_stream **stream_p, git_odb_backend *backend, git_object_size_t size, git_object_t type) -{ - fake_wstream *stream; - size_t blobsize; - - GIT_ERROR_CHECK_BLOBSIZE(size); - blobsize = (size_t)size; - - stream = git__calloc(1, sizeof(fake_wstream)); - GIT_ERROR_CHECK_ALLOC(stream); - - stream->size = blobsize; - stream->type = type; - stream->buffer = git__malloc(blobsize); - if (stream->buffer == NULL) { - git__free(stream); - return -1; - } - - stream->stream.backend = backend; - stream->stream.read = NULL; /* read only */ - stream->stream.write = &fake_wstream__write; - stream->stream.finalize_write = &fake_wstream__fwrite; - stream->stream.free = &fake_wstream__free; - stream->stream.mode = GIT_STREAM_WRONLY; - - *stream_p = (git_odb_stream *)stream; - return 0; -} - -/*********************************************************** - * - * OBJECT DATABASE PUBLIC API - * - * Public calls for the ODB functionality - * - ***********************************************************/ - -static int backend_sort_cmp(const void *a, const void *b) -{ - const backend_internal *backend_a = (const backend_internal *)(a); - const backend_internal *backend_b = (const backend_internal *)(b); - - if (backend_b->priority == backend_a->priority) { - if (backend_a->is_alternate) - return -1; - if (backend_b->is_alternate) - return 1; - return 0; - } - return (backend_b->priority - backend_a->priority); -} - -static void normalize_options( - git_odb_options *opts, - const git_odb_options *given_opts) -{ - git_odb_options init = GIT_ODB_OPTIONS_INIT; - - if (given_opts) - memcpy(opts, given_opts, sizeof(git_odb_options)); - else - memcpy(opts, &init, sizeof(git_odb_options)); - - if (!opts->oid_type) - opts->oid_type = GIT_OID_DEFAULT; -} - -int git_odb__new(git_odb **out, const git_odb_options *opts) -{ - git_odb *db = git__calloc(1, sizeof(*db)); - GIT_ERROR_CHECK_ALLOC(db); - - normalize_options(&db->options, opts); - - if (git_mutex_init(&db->lock) < 0) { - git__free(db); - return -1; - } - if (git_cache_init(&db->own_cache) < 0) { - git_mutex_free(&db->lock); - git__free(db); - return -1; - } - if (git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) { - git_cache_dispose(&db->own_cache); - git_mutex_free(&db->lock); - git__free(db); - return -1; - } - - *out = db; - GIT_REFCOUNT_INC(db); - return 0; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_odb_new(git_odb **out, const git_odb_options *opts) -{ - return git_odb__new(out, opts); -} -#else -int git_odb_new(git_odb **out) -{ - return git_odb__new(out, NULL); -} -#endif - -static int add_backend_internal( - git_odb *odb, git_odb_backend *backend, - int priority, bool is_alternate, ino_t disk_inode) -{ - backend_internal *internal; - - GIT_ASSERT_ARG(odb); - GIT_ASSERT_ARG(backend); - - GIT_ERROR_CHECK_VERSION(backend, GIT_ODB_BACKEND_VERSION, "git_odb_backend"); - - /* Check if the backend is already owned by another ODB */ - GIT_ASSERT(!backend->odb || backend->odb == odb); - - internal = git__malloc(sizeof(backend_internal)); - GIT_ERROR_CHECK_ALLOC(internal); - - internal->backend = backend; - internal->priority = priority; - internal->is_alternate = is_alternate; - internal->disk_inode = disk_inode; - - if (git_mutex_lock(&odb->lock) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return -1; - } - if (git_vector_insert(&odb->backends, internal) < 0) { - git_mutex_unlock(&odb->lock); - git__free(internal); - return -1; - } - git_vector_sort(&odb->backends); - internal->backend->odb = odb; - git_mutex_unlock(&odb->lock); - return 0; -} - -int git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority) -{ - return add_backend_internal(odb, backend, priority, false, 0); -} - -int git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority) -{ - return add_backend_internal(odb, backend, priority, true, 0); -} - -size_t git_odb_num_backends(git_odb *odb) -{ - size_t length; - bool locked = true; - - GIT_ASSERT_ARG(odb); - - if (git_mutex_lock(&odb->lock) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - locked = false; - } - length = odb->backends.length; - if (locked) - git_mutex_unlock(&odb->lock); - return length; -} - -static int git_odb__error_unsupported_in_backend(const char *action) -{ - git_error_set(GIT_ERROR_ODB, - "cannot %s - unsupported in the loaded odb backends", action); - return -1; -} - - -int git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos) -{ - backend_internal *internal; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(odb); - - - if ((error = git_mutex_lock(&odb->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - internal = git_vector_get(&odb->backends, pos); - - if (!internal || !internal->backend) { - git_mutex_unlock(&odb->lock); - - git_error_set(GIT_ERROR_ODB, "no ODB backend loaded at index %" PRIuZ, pos); - return GIT_ENOTFOUND; - } - *out = internal->backend; - git_mutex_unlock(&odb->lock); - - return 0; -} - -int git_odb__add_default_backends( - git_odb *db, const char *objects_dir, - bool as_alternates, int alternate_depth) -{ - size_t i = 0; - struct stat st; - ino_t inode; - git_odb_backend *loose, *packed; - git_odb_backend_loose_options loose_opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; - git_odb_backend_pack_options pack_opts = GIT_ODB_BACKEND_PACK_OPTIONS_INIT; - - /* TODO: inodes are not really relevant on Win32, so we need to find - * a cross-platform workaround for this */ -#ifdef GIT_WIN32 - GIT_UNUSED(i); - GIT_UNUSED(&st); - - inode = 0; -#else - if (p_stat(objects_dir, &st) < 0) { - if (as_alternates) - /* this should warn */ - return 0; - - git_error_set(GIT_ERROR_ODB, "failed to load object database in '%s'", objects_dir); - return -1; - } - - inode = st.st_ino; - - if (git_mutex_lock(&db->lock) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return -1; - } - for (i = 0; i < db->backends.length; ++i) { - backend_internal *backend = git_vector_get(&db->backends, i); - if (backend->disk_inode == inode) { - git_mutex_unlock(&db->lock); - return 0; - } - } - git_mutex_unlock(&db->lock); -#endif - - if (db->do_fsync) - loose_opts.flags |= GIT_ODB_BACKEND_LOOSE_FSYNC; - - loose_opts.oid_type = db->options.oid_type; - pack_opts.oid_type = db->options.oid_type; - - /* add the loose object backend */ - if (git_odb__backend_loose(&loose, objects_dir, &loose_opts) < 0 || - add_backend_internal(db, loose, git_odb__loose_priority, as_alternates, inode) < 0) - return -1; - - /* add the packed file backend */ -#ifdef GIT_EXPERIMENTAL_SHA256 - if (git_odb_backend_pack(&packed, objects_dir, &pack_opts) < 0) - return -1; -#else - GIT_UNUSED(pack_opts); - - if (git_odb_backend_pack(&packed, objects_dir) < 0) - return -1; -#endif - - if (add_backend_internal(db, packed, git_odb__packed_priority, as_alternates, inode) < 0) - return -1; - - if (git_mutex_lock(&db->lock) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return -1; - } - if (!db->cgraph && - git_commit_graph_new(&db->cgraph, objects_dir, false, db->options.oid_type) < 0) { - git_mutex_unlock(&db->lock); - return -1; - } - git_mutex_unlock(&db->lock); - - return load_alternates(db, objects_dir, alternate_depth); -} - -static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_depth) -{ - git_str alternates_path = GIT_STR_INIT; - git_str alternates_buf = GIT_STR_INIT; - char *buffer; - const char *alternate; - int result = 0; - - /* Git reports an error, we just ignore anything deeper */ - if (alternate_depth > GIT_ALTERNATES_MAX_DEPTH) - return 0; - - if (git_str_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0) - return -1; - - if (git_fs_path_exists(alternates_path.ptr) == false) { - git_str_dispose(&alternates_path); - return 0; - } - - if (git_futils_readbuffer(&alternates_buf, alternates_path.ptr) < 0) { - git_str_dispose(&alternates_path); - return -1; - } - - buffer = (char *)alternates_buf.ptr; - - /* add each alternate as a new backend; one alternate per line */ - while ((alternate = git__strtok(&buffer, "\r\n")) != NULL) { - if (*alternate == '\0' || *alternate == '#') - continue; - - /* Relative path: build based on the current `objects` folder. */ - if (*alternate == '.') { - if ((result = git_str_joinpath(&alternates_path, objects_dir, alternate)) < 0) - break; - alternate = git_str_cstr(&alternates_path); - } - - if ((result = git_odb__add_default_backends(odb, alternate, true, alternate_depth + 1)) < 0) - break; - } - - git_str_dispose(&alternates_path); - git_str_dispose(&alternates_buf); - - return result; -} - -int git_odb_add_disk_alternate(git_odb *odb, const char *path) -{ - return git_odb__add_default_backends(odb, path, true, 0); -} - -int git_odb_set_commit_graph(git_odb *odb, git_commit_graph *cgraph) -{ - int error = 0; - - GIT_ASSERT_ARG(odb); - - if ((error = git_mutex_lock(&odb->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the db lock"); - return error; - } - git_commit_graph_free(odb->cgraph); - odb->cgraph = cgraph; - git_mutex_unlock(&odb->lock); - - return error; -} - -int git_odb__open( - git_odb **out, - const char *objects_dir, - const git_odb_options *opts) -{ - git_odb *db; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(objects_dir); - - *out = NULL; - - if (git_odb__new(&db, opts) < 0) - return -1; - - if (git_odb__add_default_backends(db, objects_dir, 0, 0) < 0) { - git_odb_free(db); - return -1; - } - - *out = db; - return 0; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 - -int git_odb_open( - git_odb **out, - const char *objects_dir, - const git_odb_options *opts) -{ - return git_odb__open(out, objects_dir, opts); -} - -#else - -int git_odb_open(git_odb **out, const char *objects_dir) -{ - return git_odb__open(out, objects_dir, NULL); -} - -#endif - -int git_odb__set_caps(git_odb *odb, int caps) -{ - if (caps == GIT_ODB_CAP_FROM_OWNER) { - git_repository *repo = GIT_REFCOUNT_OWNER(odb); - int val; - - if (!repo) { - git_error_set(GIT_ERROR_ODB, "cannot access repository to set odb caps"); - return -1; - } - - if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_FSYNCOBJECTFILES)) - odb->do_fsync = !!val; - } - - return 0; -} - -static void odb_free(git_odb *db) -{ - size_t i; - bool locked = true; - - if (git_mutex_lock(&db->lock) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - locked = false; - } - for (i = 0; i < db->backends.length; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *backend = internal->backend; - - backend->free(backend); - - git__free(internal); - } - if (locked) - git_mutex_unlock(&db->lock); - - git_commit_graph_free(db->cgraph); - git_vector_dispose(&db->backends); - git_cache_dispose(&db->own_cache); - git_mutex_free(&db->lock); - - git__memzero(db, sizeof(*db)); - git__free(db); -} - -void git_odb_free(git_odb *db) -{ - if (db == NULL) - return; - - GIT_REFCOUNT_DEC(db, odb_free); -} - -static int odb_exists_1( - git_odb *db, - const git_oid *id, - bool only_refreshed) -{ - size_t i; - bool found = false; - int error; - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - for (i = 0; i < db->backends.length && !found; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (only_refreshed && !b->refresh) - continue; - - if (b->exists != NULL) - found = (bool)b->exists(b, id); - } - git_mutex_unlock(&db->lock); - - return (int)found; -} - -int git_odb__get_commit_graph_file(git_commit_graph_file **out, git_odb *db) -{ - int error = 0; - git_commit_graph_file *result = NULL; - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the db lock"); - return error; - } - if (!db->cgraph) { - error = GIT_ENOTFOUND; - goto done; - } - error = git_commit_graph_get_file(&result, db->cgraph); - if (error) - goto done; - *out = result; - -done: - git_mutex_unlock(&db->lock); - return error; -} - -static int odb_freshen_1( - git_odb *db, - const git_oid *id, - bool only_refreshed) -{ - size_t i; - bool found = false; - int error; - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - for (i = 0; i < db->backends.length && !found; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (only_refreshed && !b->refresh) - continue; - - if (b->freshen != NULL) - found = !b->freshen(b, id); - else if (b->exists != NULL) - found = b->exists(b, id); - } - git_mutex_unlock(&db->lock); - - return (int)found; -} - -int git_odb__freshen(git_odb *db, const git_oid *id) -{ - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(id); - - if (odb_freshen_1(db, id, false)) - return 1; - - if (!git_odb_refresh(db)) - return odb_freshen_1(db, id, true); - - /* Failed to refresh, hence not found */ - return 0; -} - -int git_odb_exists(git_odb *db, const git_oid *id) -{ - return git_odb_exists_ext(db, id, 0); -} - -int git_odb_exists_ext(git_odb *db, const git_oid *id, unsigned int flags) -{ - git_odb_object *object; - - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(id); - - if (git_oid_is_zero(id)) - return 0; - - if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) { - git_odb_object_free(object); - return 1; - } - - if (odb_exists_1(db, id, false)) - return 1; - - if (!(flags & GIT_ODB_LOOKUP_NO_REFRESH) && !git_odb_refresh(db)) - return odb_exists_1(db, id, true); - - /* Failed to refresh, hence not found */ - return 0; -} - -static int odb_exists_prefix_1(git_oid *out, git_odb *db, - const git_oid *key, size_t len, bool only_refreshed) -{ - size_t i; - int error = GIT_ENOTFOUND, num_found = 0; - git_oid last_found = GIT_OID_NONE, found; - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - error = GIT_ENOTFOUND; - for (i = 0; i < db->backends.length; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (only_refreshed && !b->refresh) - continue; - - if (!b->exists_prefix) - continue; - - error = b->exists_prefix(&found, b, key, len); - if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH) - continue; - if (error) { - git_mutex_unlock(&db->lock); - return error; - } - - /* make sure found item doesn't introduce ambiguity */ - if (num_found) { - if (git_oid__cmp(&last_found, &found)) { - git_mutex_unlock(&db->lock); - return git_odb__error_ambiguous("multiple matches for prefix"); - } - } else { - git_oid_cpy(&last_found, &found); - num_found++; - } - } - git_mutex_unlock(&db->lock); - - if (!num_found) - return GIT_ENOTFOUND; - - if (out) - git_oid_cpy(out, &last_found); - - return 0; -} - -int git_odb_exists_prefix( - git_oid *out, git_odb *db, const git_oid *short_id, size_t len) -{ - int error; - git_oid key = GIT_OID_NONE; - - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(short_id); - - if (len < GIT_OID_MINPREFIXLEN) - return git_odb__error_ambiguous("prefix length too short"); - - if (len >= git_oid_hexsize(db->options.oid_type)) { - if (git_odb_exists(db, short_id)) { - if (out) - git_oid_cpy(out, short_id); - return 0; - } else { - return git_odb__error_notfound( - "no match for id prefix", short_id, len); - } - } - - git_oid__cpy_prefix(&key, short_id, len); - - error = odb_exists_prefix_1(out, db, &key, len, false); - - if (error == GIT_ENOTFOUND && !git_odb_refresh(db)) - error = odb_exists_prefix_1(out, db, &key, len, true); - - if (error == GIT_ENOTFOUND) - return git_odb__error_notfound("no match for id prefix", &key, len); - - return error; -} - -int git_odb_expand_ids( - git_odb *db, - git_odb_expand_id *ids, - size_t count) -{ - size_t hex_size, i; - - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(ids); - - hex_size = git_oid_hexsize(db->options.oid_type); - - for (i = 0; i < count; i++) { - git_odb_expand_id *query = &ids[i]; - int error = GIT_EAMBIGUOUS; - - if (!query->type) - query->type = GIT_OBJECT_ANY; - - /* if we have a short OID, expand it first */ - if (query->length >= GIT_OID_MINPREFIXLEN && query->length < hex_size) { - git_oid actual_id; - - error = odb_exists_prefix_1(&actual_id, db, &query->id, query->length, false); - if (!error) { - git_oid_cpy(&query->id, &actual_id); - query->length = (unsigned short)hex_size; - } - } - - /* - * now we ought to have a 40-char OID, either because we've expanded it - * or because the user passed a full OID. Ensure its type is right. - */ - if (query->length >= hex_size) { - git_object_t actual_type; - - error = odb_otype_fast(&actual_type, db, &query->id); - if (!error) { - if (query->type != GIT_OBJECT_ANY && query->type != actual_type) - error = GIT_ENOTFOUND; - else - query->type = actual_type; - } - } - - switch (error) { - /* no errors, so we've successfully expanded the OID */ - case 0: - continue; - - /* the object is missing or ambiguous */ - case GIT_ENOTFOUND: - case GIT_EAMBIGUOUS: - git_oid_clear(&query->id, db->options.oid_type); - query->length = 0; - query->type = 0; - break; - - /* something went very wrong with the ODB; bail hard */ - default: - return error; - } - } - - git_error_clear(); - return 0; -} - -int git_odb_read_header(size_t *len_p, git_object_t *type_p, git_odb *db, const git_oid *id) -{ - int error; - git_odb_object *object = NULL; - - error = git_odb__read_header_or_object(&object, len_p, type_p, db, id); - - if (object) - git_odb_object_free(object); - - return error; -} - -static int odb_read_header_1( - size_t *len_p, git_object_t *type_p, git_odb *db, - const git_oid *id, bool only_refreshed) -{ - size_t i; - git_object_t ht; - bool passthrough = false; - int error; - - if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJECT_INVALID) { - *type_p = ht; - *len_p = 0; - return 0; - } - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - for (i = 0; i < db->backends.length; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (only_refreshed && !b->refresh) - continue; - - if (!b->read_header) { - passthrough = true; - continue; - } - - error = b->read_header(len_p, type_p, b, id); - - switch (error) { - case GIT_PASSTHROUGH: - passthrough = true; - break; - case GIT_ENOTFOUND: - break; - default: - git_mutex_unlock(&db->lock); - return error; - } - } - git_mutex_unlock(&db->lock); - - return passthrough ? GIT_PASSTHROUGH : GIT_ENOTFOUND; -} - -int git_odb__read_header_or_object( - git_odb_object **out, size_t *len_p, git_object_t *type_p, - git_odb *db, const git_oid *id) -{ - int error = GIT_ENOTFOUND; - git_odb_object *object; - - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(id); - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(len_p); - GIT_ASSERT_ARG(type_p); - - *out = NULL; - - if (git_oid_is_zero(id)) - return error_null_oid(GIT_ENOTFOUND, "cannot read object"); - - if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) { - *len_p = object->cached.size; - *type_p = object->cached.type; - *out = object; - return 0; - } - - error = odb_read_header_1(len_p, type_p, db, id, false); - - if (error == GIT_ENOTFOUND && !git_odb_refresh(db)) - error = odb_read_header_1(len_p, type_p, db, id, true); - - if (error == GIT_ENOTFOUND) - return git_odb__error_notfound("cannot read header for", id, git_oid_hexsize(db->options.oid_type)); - - /* we found the header; return early */ - if (!error) - return 0; - - if (error == GIT_PASSTHROUGH) { - /* - * no backend has header-reading functionality - * so try using `git_odb_read` instead - */ - error = git_odb_read(&object, db, id); - if (!error) { - *len_p = object->cached.size; - *type_p = object->cached.type; - *out = object; - } - } - - return error; -} - -static int odb_read_1( - git_odb_object **out, - git_odb *db, - const git_oid *id, - bool only_refreshed) -{ - size_t i; - git_rawobj raw; - git_odb_object *object; - git_oid hashed; - bool found = false; - int error = 0; - - if (!only_refreshed) { - if ((error = odb_read_hardcoded(&found, &raw, id)) < 0) - return error; - } - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - for (i = 0; i < db->backends.length && !found; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (only_refreshed && !b->refresh) - continue; - - if (b->read != NULL) { - error = b->read(&raw.data, &raw.len, &raw.type, b, id); - if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND) - continue; - - if (error < 0) { - git_mutex_unlock(&db->lock); - return error; - } - - found = true; - } - } - git_mutex_unlock(&db->lock); - - if (!found) - return GIT_ENOTFOUND; - - if (git_odb__strict_hash_verification) { - if ((error = git_odb__hash(&hashed, raw.data, raw.len, raw.type, db->options.oid_type)) < 0) - goto out; - - if (!git_oid_equal(id, &hashed)) { - error = git_odb__error_mismatch(id, &hashed); - goto out; - } - } - - git_error_clear(); - if ((object = odb_object__alloc(id, &raw)) == NULL) { - error = -1; - goto out; - } - - *out = git_cache_store_raw(odb_cache(db), object); - -out: - if (error) - git__free(raw.data); - return error; -} - -int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id) -{ - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(id); - - if (git_oid_is_zero(id)) - return error_null_oid(GIT_ENOTFOUND, "cannot read object"); - - *out = git_cache_get_raw(odb_cache(db), id); - if (*out != NULL) - return 0; - - error = odb_read_1(out, db, id, false); - - if (error == GIT_ENOTFOUND && !git_odb_refresh(db)) - error = odb_read_1(out, db, id, true); - - if (error == GIT_ENOTFOUND) - return git_odb__error_notfound("no match for id", id, git_oid_hexsize(git_oid_type(id))); - - return error; -} - -static int odb_otype_fast(git_object_t *type_p, git_odb *db, const git_oid *id) -{ - git_odb_object *object; - size_t _unused; - int error; - - if (git_oid_is_zero(id)) - return error_null_oid(GIT_ENOTFOUND, "cannot get object type"); - - if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) { - *type_p = object->cached.type; - git_odb_object_free(object); - return 0; - } - - error = odb_read_header_1(&_unused, type_p, db, id, false); - - if (error == GIT_PASSTHROUGH) { - error = odb_read_1(&object, db, id, false); - if (!error) - *type_p = object->cached.type; - git_odb_object_free(object); - } - - return error; -} - -static int read_prefix_1(git_odb_object **out, git_odb *db, - const git_oid *key, size_t len, bool only_refreshed) -{ - size_t i; - int error = 0; - git_oid found_full_oid = GIT_OID_NONE; - git_rawobj raw = {0}; - void *data = NULL; - bool found = false; - git_odb_object *object; - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - for (i = 0; i < db->backends.length; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (only_refreshed && !b->refresh) - continue; - - if (b->read_prefix != NULL) { - git_oid full_oid; - error = b->read_prefix(&full_oid, &raw.data, &raw.len, &raw.type, b, key, len); - - if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH) { - error = 0; - continue; - } - - if (error) { - git_mutex_unlock(&db->lock); - goto out; - } - - git__free(data); - data = raw.data; - - if (found && git_oid__cmp(&full_oid, &found_full_oid)) { - git_str buf = GIT_STR_INIT; - const char *idstr; - - if ((idstr = git_oid_tostr_s(&full_oid)) == NULL) { - git_str_puts(&buf, "failed to parse object id"); - } else { - git_str_printf(&buf, "multiple matches for prefix: %s", idstr); - - if ((idstr = git_oid_tostr_s(&found_full_oid)) != NULL) - git_str_printf(&buf, " %s", idstr); - } - - error = git_odb__error_ambiguous(buf.ptr); - git_str_dispose(&buf); - git_mutex_unlock(&db->lock); - goto out; - } - - found_full_oid = full_oid; - found = true; - } - } - git_mutex_unlock(&db->lock); - - if (!found) - return GIT_ENOTFOUND; - - if (git_odb__strict_hash_verification) { - git_oid hash; - - if ((error = git_odb__hash(&hash, raw.data, raw.len, raw.type, db->options.oid_type)) < 0) - goto out; - - if (!git_oid_equal(&found_full_oid, &hash)) { - error = git_odb__error_mismatch(&found_full_oid, &hash); - goto out; - } - } - - if ((object = odb_object__alloc(&found_full_oid, &raw)) == NULL) { - error = -1; - goto out; - } - - *out = git_cache_store_raw(odb_cache(db), object); - -out: - if (error) - git__free(raw.data); - - return error; -} - -int git_odb_read_prefix( - git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len) -{ - git_oid key = GIT_OID_NONE; - size_t hex_size; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(db); - - hex_size = git_oid_hexsize(db->options.oid_type); - - if (len < GIT_OID_MINPREFIXLEN) - return git_odb__error_ambiguous("prefix length too short"); - - if (len > hex_size) - len = hex_size; - - if (len == hex_size) { - *out = git_cache_get_raw(odb_cache(db), short_id); - if (*out != NULL) - return 0; - } - - git_oid__cpy_prefix(&key, short_id, len); - - error = read_prefix_1(out, db, &key, len, false); - - if (error == GIT_ENOTFOUND && !git_odb_refresh(db)) - error = read_prefix_1(out, db, &key, len, true); - - if (error == GIT_ENOTFOUND) - return git_odb__error_notfound("no match for prefix", &key, len); - - return error; -} - -int git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload) -{ - unsigned int i; - git_vector backends = GIT_VECTOR_INIT; - backend_internal *internal; - int error = 0; - - /* Make a copy of the backends vector to invoke the callback without holding the lock. */ - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - goto cleanup; - } - error = git_vector_dup(&backends, &db->backends, NULL); - git_mutex_unlock(&db->lock); - - if (error < 0) - goto cleanup; - - git_vector_foreach(&backends, i, internal) { - git_odb_backend *b = internal->backend; - error = b->foreach(b, cb, payload); - if (error != 0) - goto cleanup; - } - -cleanup: - git_vector_dispose(&backends); - - return error; -} - -int git_odb_write( - git_oid *oid, git_odb *db, const void *data, size_t len, git_object_t type) -{ - size_t i; - int error; - git_odb_stream *stream; - - GIT_ASSERT_ARG(oid); - GIT_ASSERT_ARG(db); - - if ((error = git_odb__hash(oid, data, len, type, db->options.oid_type)) < 0) - return error; - - if (git_oid_is_zero(oid)) - return error_null_oid(GIT_EINVALID, "cannot write object"); - - if (git_odb__freshen(db, oid)) - return 0; - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - for (i = 0, error = GIT_ERROR; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - /* we don't write in alternates! */ - if (internal->is_alternate) - continue; - - if (b->write != NULL) - error = b->write(b, oid, data, len, type); - } - git_mutex_unlock(&db->lock); - - if (!error || error == GIT_PASSTHROUGH) - return 0; - - /* if no backends were able to write the object directly, we try a - * streaming write to the backends; just write the whole object into the - * stream in one push - */ - if ((error = git_odb_open_wstream(&stream, db, len, type)) != 0) - return error; - - if ((error = stream->write(stream, data, len)) == 0) - error = stream->finalize_write(stream, oid); - - git_odb_stream_free(stream); - return error; -} - -static int hash_header(git_hash_ctx *ctx, git_object_size_t size, git_object_t type) -{ - char header[64]; - size_t hdrlen; - int error; - - if ((error = git_odb__format_object_header(&hdrlen, - header, sizeof(header), size, type)) < 0) - return error; - - return git_hash_update(ctx, header, hdrlen); -} - -int git_odb_open_wstream( - git_odb_stream **stream, git_odb *db, git_object_size_t size, git_object_t type) -{ - size_t i, writes = 0; - int error = GIT_ERROR; - git_hash_ctx *ctx = NULL; - - GIT_ASSERT_ARG(stream); - GIT_ASSERT_ARG(db); - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - error = GIT_ERROR; - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - /* we don't write in alternates! */ - if (internal->is_alternate) - continue; - - if (b->writestream != NULL) { - ++writes; - error = b->writestream(stream, b, size, type); - } else if (b->write != NULL) { - ++writes; - error = init_fake_wstream(stream, b, size, type); - } - } - git_mutex_unlock(&db->lock); - - if (error < 0) { - if (error == GIT_PASSTHROUGH) - error = 0; - else if (!writes) - error = git_odb__error_unsupported_in_backend("write object"); - - goto done; - } - - ctx = git__malloc(sizeof(git_hash_ctx)); - GIT_ERROR_CHECK_ALLOC(ctx); - - if ((error = git_hash_ctx_init(ctx, git_oid_algorithm(db->options.oid_type))) < 0 || - (error = hash_header(ctx, size, type)) < 0) - goto done; - -#ifdef GIT_EXPERIMENTAL_SHA256 - (*stream)->oid_type = db->options.oid_type; -#endif - (*stream)->hash_ctx = ctx; - (*stream)->declared_size = size; - (*stream)->received_bytes = 0; - -done: - if (error) - git__free(ctx); - return error; -} - -static int git_odb_stream__invalid_length( - const git_odb_stream *stream, - const char *action) -{ - git_error_set(GIT_ERROR_ODB, - "cannot %s - " - "Invalid length. %"PRId64" was expected. The " - "total size of the received chunks amounts to %"PRId64".", - action, stream->declared_size, stream->received_bytes); - - return -1; -} - -int git_odb_stream_write(git_odb_stream *stream, const char *buffer, size_t len) -{ - git_hash_update(stream->hash_ctx, buffer, len); - - stream->received_bytes += len; - - if (stream->received_bytes > stream->declared_size) - return git_odb_stream__invalid_length(stream, - "stream_write()"); - - return stream->write(stream, buffer, len); -} - -int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream) -{ - if (stream->received_bytes != stream->declared_size) - return git_odb_stream__invalid_length(stream, - "stream_finalize_write()"); - - git_hash_final(out->id, stream->hash_ctx); - -#ifdef GIT_EXPERIMENTAL_SHA256 - out->type = stream->oid_type; -#endif - - if (git_odb__freshen(stream->backend->odb, out)) - return 0; - - return stream->finalize_write(stream, out); -} - -int git_odb_stream_read(git_odb_stream *stream, char *buffer, size_t len) -{ - return stream->read(stream, buffer, len); -} - -void git_odb_stream_free(git_odb_stream *stream) -{ - if (stream == NULL) - return; - - if (stream->hash_ctx) - git_hash_ctx_cleanup(stream->hash_ctx); - git__free(stream->hash_ctx); - stream->free(stream); -} - -int git_odb_open_rstream( - git_odb_stream **stream, - size_t *len, - git_object_t *type, - git_odb *db, - const git_oid *oid) -{ - size_t i, reads = 0; - int error = GIT_ERROR; - - GIT_ASSERT_ARG(stream); - GIT_ASSERT_ARG(db); - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - error = GIT_ERROR; - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (b->readstream != NULL) { - ++reads; - error = b->readstream(stream, len, type, b, oid); - } - } - git_mutex_unlock(&db->lock); - - if (error == GIT_PASSTHROUGH) - error = 0; - if (error < 0 && !reads) - error = git_odb__error_unsupported_in_backend("read object streamed"); - - return error; -} - -int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_indexer_progress_cb progress_cb, void *progress_payload) -{ - size_t i, writes = 0; - int error = GIT_ERROR; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(db); - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - error = GIT_ERROR; - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - /* we don't write in alternates! */ - if (internal->is_alternate) - continue; - - if (b->writepack != NULL) { - ++writes; - error = b->writepack(out, b, db, progress_cb, progress_payload); - } - } - git_mutex_unlock(&db->lock); - - if (error == GIT_PASSTHROUGH) - error = 0; - if (error < 0 && !writes) - error = git_odb__error_unsupported_in_backend("write pack"); - - return error; -} - -int git_odb_write_multi_pack_index(git_odb *db) -{ - size_t i, writes = 0; - int error = GIT_ERROR; - - GIT_ASSERT_ARG(db); - - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - /* we don't write in alternates! */ - if (internal->is_alternate) - continue; - - if (b->writemidx != NULL) { - ++writes; - error = b->writemidx(b); - } - } - - if (error == GIT_PASSTHROUGH) - error = 0; - if (error < 0 && !writes) - error = git_odb__error_unsupported_in_backend("write multi-pack-index"); - - return error; -} - -void *git_odb_backend_data_alloc(git_odb_backend *backend, size_t len) -{ - GIT_UNUSED(backend); - return git__malloc(len); -} - -#ifndef GIT_DEPRECATE_HARD -void *git_odb_backend_malloc(git_odb_backend *backend, size_t len) -{ - return git_odb_backend_data_alloc(backend, len); -} -#endif - -void git_odb_backend_data_free(git_odb_backend *backend, void *data) -{ - GIT_UNUSED(backend); - git__free(data); -} - -int git_odb_refresh(git_odb *db) -{ - size_t i; - int error; - - GIT_ASSERT_ARG(db); - - if ((error = git_mutex_lock(&db->lock)) < 0) { - git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); - return error; - } - for (i = 0; i < db->backends.length; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (b->refresh != NULL) { - int error = b->refresh(b); - if (error < 0) { - git_mutex_unlock(&db->lock); - return error; - } - } - } - if (db->cgraph) - git_commit_graph_refresh(db->cgraph); - git_mutex_unlock(&db->lock); - - return 0; -} - -int git_odb__error_mismatch(const git_oid *expected, const git_oid *actual) -{ - char expected_oid[GIT_OID_MAX_HEXSIZE + 1], - actual_oid[GIT_OID_MAX_HEXSIZE + 1]; - - git_oid_tostr(expected_oid, git_oid_hexsize(git_oid_type(expected)) + 1, expected); - git_oid_tostr(actual_oid, git_oid_hexsize(git_oid_type(actual)) + 1, actual); - - git_error_set(GIT_ERROR_ODB, "object hash mismatch - expected %s but got %s", - expected_oid, actual_oid); - - return GIT_EMISMATCH; -} - -int git_odb__error_notfound( - const char *message, const git_oid *oid, size_t oid_len) -{ - if (oid != NULL) { - char oid_str[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_tostr(oid_str, oid_len+1, oid); - git_error_set(GIT_ERROR_ODB, "object not found - %s (%.*s)", - message, (int) oid_len, oid_str); - } else - git_error_set(GIT_ERROR_ODB, "object not found - %s", message); - - return GIT_ENOTFOUND; -} - -static int error_null_oid(int error, const char *message) -{ - git_error_set(GIT_ERROR_ODB, "odb: %s: null OID cannot exist", message); - return error; -} - -int git_odb__error_ambiguous(const char *message) -{ - git_error_set(GIT_ERROR_ODB, "ambiguous OID prefix - %s", message); - return GIT_EAMBIGUOUS; -} - -int git_odb_init_backend(git_odb_backend *backend, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - backend, version, git_odb_backend, GIT_ODB_BACKEND_INIT); - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/odb.h b/vendor/libgit2-sys/libgit2/src/libgit2/odb.h deleted file mode 100644 index 7a712e2..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/odb.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_odb_h__ -#define INCLUDE_odb_h__ - -#include "common.h" - -#include "git2/odb.h" -#include "git2/odb_backend.h" -#include "git2/oid.h" -#include "git2/types.h" -#include "git2/sys/commit_graph.h" - -#include "cache.h" -#include "commit_graph.h" -#include "filter.h" -#include "posix.h" -#include "vector.h" - -#define GIT_OBJECTS_DIR "objects/" -#define GIT_OBJECT_DIR_MODE 0777 -#define GIT_OBJECT_FILE_MODE 0444 - -#define GIT_ODB_DEFAULT_LOOSE_PRIORITY 1 -#define GIT_ODB_DEFAULT_PACKED_PRIORITY 2 - -extern bool git_odb__strict_hash_verification; - -/* DO NOT EXPORT */ -typedef struct { - void *data; /**< Raw, decompressed object data. */ - size_t len; /**< Total number of bytes in data. */ - git_object_t type; /**< Type of this object. */ -} git_rawobj; - -/* EXPORT */ -struct git_odb_object { - git_cached_obj cached; - void *buffer; -}; - -/* EXPORT */ -struct git_odb { - git_refcount rc; - git_mutex lock; /* protects backends */ - git_odb_options options; - git_vector backends; - git_cache own_cache; - git_commit_graph *cgraph; - unsigned int do_fsync :1; -}; - -typedef enum { - GIT_ODB_CAP_FROM_OWNER = -1 -} git_odb_cap_t; - -/* - * Set the capabilities for the object database. - */ -int git_odb__set_caps(git_odb *odb, int caps); - -/* - * Add the default loose and packed backends for a database. - */ -int git_odb__add_default_backends( - git_odb *db, const char *objects_dir, - bool as_alternates, int alternate_depth); - -/* - * Hash a git_rawobj internally. - * The `git_rawobj` is supposed to be previously initialized - */ -int git_odb__hashobj(git_oid *id, git_rawobj *obj, git_oid_t oid_type); - -/* - * Format the object header such as it would appear in the on-disk object - */ -int git_odb__format_object_header(size_t *out_len, char *hdr, size_t hdr_size, git_object_size_t obj_len, git_object_t obj_type); - -/* - * Hash an open file descriptor. - * This is a performance call when the contents of a fd need to be hashed, - * but the fd is already open and we have the size of the contents. - * - * Saves us some `stat` calls. - * - * The fd is never closed, not even on error. It must be opened and closed - * by the caller - */ -int git_odb__hashfd( - git_oid *out, - git_file fd, - size_t size, - git_object_t object_type, - git_oid_t oid_type); - -/* - * Hash an open file descriptor applying an array of filters - * Acts just like git_odb__hashfd with the addition of filters... - */ -int git_odb__hashfd_filtered( - git_oid *out, - git_file fd, - size_t len, - git_object_t object_type, - git_oid_t oid_type, - git_filter_list *fl); - -/* - * Hash a `path`, assuming it could be a POSIX symlink: if the path is a - * symlink, then the raw contents of the symlink will be hashed. Otherwise, - * this will fallback to `git_odb__hashfd`. - * - * The hash type for this call is always `GIT_OBJECT_BLOB` because - * symlinks may only point to blobs. - */ -int git_odb__hashlink(git_oid *out, const char *path, git_oid_t oid_type); - -/** - * Generate a GIT_EMISMATCH error for the ODB. - */ -int git_odb__error_mismatch( - const git_oid *expected, const git_oid *actual); - -/* - * Generate a GIT_ENOTFOUND error for the ODB. - */ -int git_odb__error_notfound( - const char *message, const git_oid *oid, size_t oid_len); - -/* - * Generate a GIT_EAMBIGUOUS error for the ODB. - */ -int git_odb__error_ambiguous(const char *message); - -/* - * Attempt to read object header or just return whole object if it could - * not be read. - */ -int git_odb__read_header_or_object( - git_odb_object **out, size_t *len_p, git_object_t *type_p, - git_odb *db, const git_oid *id); - -/* - * Attempt to get the ODB's commit-graph file. This object is still owned by - * the ODB. If the repository does not contain a commit-graph, it will return - * GIT_ENOTFOUND. - */ -int git_odb__get_commit_graph_file(git_commit_graph_file **out, git_odb *odb); - -/* freshen an entry in the object database */ -int git_odb__freshen(git_odb *db, const git_oid *id); - -/* fully free the object; internal method, DO NOT EXPORT */ -void git_odb_object__free(void *object); - -/* SHA256 support */ - -int git_odb__new(git_odb **out, const git_odb_options *opts); - -int git_odb__open( - git_odb **out, - const char *objects_dir, - const git_odb_options *opts); - -int git_odb__hash( - git_oid *out, - const void *data, - size_t len, - git_object_t object_type, - git_oid_t oid_type); - -int git_odb__hashfile( - git_oid *out, - const char *path, - git_object_t object_type, - git_oid_t oid_type); - -GIT_EXTERN(int) git_odb__backend_loose( - git_odb_backend **out, - const char *objects_dir, - git_odb_backend_loose_options *opts); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/odb_loose.c b/vendor/libgit2-sys/libgit2/src/libgit2/odb_loose.c deleted file mode 100644 index d2e3cb2..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/odb_loose.c +++ /dev/null @@ -1,1250 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include -#include "git2/object.h" -#include "git2/sys/odb_backend.h" -#include "futils.h" -#include "hash.h" -#include "odb.h" -#include "delta.h" -#include "filebuf.h" -#include "object.h" -#include "zstream.h" - -#include "git2/odb_backend.h" -#include "git2/types.h" - -/* maximum possible header length */ -#define MAX_HEADER_LEN 64 - -typedef struct { /* object header data */ - git_object_t type; /* object type */ - size_t size; /* object size */ -} obj_hdr; - -typedef struct { - git_odb_stream stream; - git_filebuf fbuf; -} loose_writestream; - -typedef struct { - git_odb_stream stream; - git_map map; - char start[MAX_HEADER_LEN]; - size_t start_len; - size_t start_read; - git_zstream zstream; -} loose_readstream; - -typedef struct loose_backend { - git_odb_backend parent; - - git_odb_backend_loose_options options; - size_t oid_hexsize; - - size_t objects_dirlen; - char objects_dir[GIT_FLEX_ARRAY]; -} loose_backend; - -/* State structure for exploring directories, - * in order to locate objects matching a short oid. - */ -typedef struct { - loose_backend *backend; - - size_t dir_len; - - /* Hex formatted oid to match (and its length) */ - unsigned char short_oid[GIT_OID_MAX_HEXSIZE]; - size_t short_oid_len; - - /* Number of matching objects found so far */ - int found; - - /* Hex formatted oid of the object found */ - unsigned char res_oid[GIT_OID_MAX_HEXSIZE]; -} loose_locate_object_state; - - -/*********************************************************** - * - * MISCELLANEOUS HELPER FUNCTIONS - * - ***********************************************************/ - -static int object_file_name( - git_str *name, const loose_backend *be, const git_oid *id) -{ - /* append loose object filename: aa/aaa... (41 bytes plus NUL) */ - size_t path_size = be->oid_hexsize + 1; - - git_str_set(name, be->objects_dir, be->objects_dirlen); - git_fs_path_to_dir(name); - - if (git_str_grow_by(name, path_size + 1) < 0) - return -1; - - git_oid_pathfmt(name->ptr + name->size, id); - name->size += path_size; - name->ptr[name->size] = '\0'; - - return 0; -} - -static int object_mkdir(const git_str *name, const loose_backend *be) -{ - return git_futils_mkdir_relative( - name->ptr + be->objects_dirlen, - be->objects_dir, - be->options.dir_mode, - GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR, NULL); -} - -static int parse_header_packlike( - obj_hdr *out, size_t *out_len, const unsigned char *data, size_t len) -{ - unsigned long c; - size_t shift, size, used = 0; - - if (len == 0) - goto on_error; - - c = data[used++]; - out->type = (c >> 4) & 7; - - size = c & 15; - shift = 4; - while (c & 0x80) { - if (len <= used) - goto on_error; - - if (sizeof(size_t) * 8 <= shift) - goto on_error; - - c = data[used++]; - size += (c & 0x7f) << shift; - shift += 7; - } - - out->size = size; - - if (out_len) - *out_len = used; - - return 0; - -on_error: - git_error_set(GIT_ERROR_OBJECT, "failed to parse loose object: invalid header"); - return -1; -} - -static int parse_header( - obj_hdr *out, - size_t *out_len, - const unsigned char *_data, - size_t data_len) -{ - const char *data = (char *)_data; - size_t i, typename_len, size_idx, size_len; - int64_t size; - - *out_len = 0; - - /* find the object type name */ - for (i = 0, typename_len = 0; i < data_len; i++, typename_len++) { - if (data[i] == ' ') - break; - } - - if (typename_len == data_len) - goto on_error; - - out->type = git_object_stringn2type(data, typename_len); - - size_idx = typename_len + 1; - for (i = size_idx, size_len = 0; i < data_len; i++, size_len++) { - if (data[i] == '\0') - break; - } - - if (i == data_len) - goto on_error; - - if (git__strntol64(&size, &data[size_idx], size_len, NULL, 10) < 0 || - size < 0) - goto on_error; - - if ((uint64_t)size > SIZE_MAX) { - git_error_set(GIT_ERROR_OBJECT, "object is larger than available memory"); - return -1; - } - - out->size = (size_t)size; - - if (GIT_ADD_SIZET_OVERFLOW(out_len, i, 1)) - goto on_error; - - return 0; - -on_error: - git_error_set(GIT_ERROR_OBJECT, "failed to parse loose object: invalid header"); - return -1; -} - -static int is_zlib_compressed_data(unsigned char *data, size_t data_len) -{ - unsigned int w; - - if (data_len < 2) - return 0; - - w = ((unsigned int)(data[0]) << 8) + data[1]; - return (data[0] & 0x8F) == 0x08 && !(w % 31); -} - -/*********************************************************** - * - * ODB OBJECT READING & WRITING - * - * Backend for the public API; read headers and full objects - * from the ODB. Write raw data to the ODB. - * - ***********************************************************/ - - -/* - * At one point, there was a loose object format that was intended to - * mimic the format used in pack-files. This was to allow easy copying - * of loose object data into packs. This format is no longer used, but - * we must still read it. - */ -static int read_loose_packlike(git_rawobj *out, git_str *obj) -{ - git_str body = GIT_STR_INIT; - const unsigned char *obj_data; - obj_hdr hdr; - size_t obj_len, head_len, alloc_size; - int error; - - obj_data = (unsigned char *)obj->ptr; - obj_len = obj->size; - - /* - * read the object header, which is an (uncompressed) - * binary encoding of the object type and size. - */ - if ((error = parse_header_packlike(&hdr, &head_len, obj_data, obj_len)) < 0) - goto done; - - if (!git_object_typeisloose(hdr.type) || head_len > obj_len) { - git_error_set(GIT_ERROR_ODB, "failed to inflate loose object"); - error = -1; - goto done; - } - - obj_data += head_len; - obj_len -= head_len; - - /* - * allocate a buffer and inflate the data into it - */ - if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, hdr.size, 1) || - git_str_init(&body, alloc_size) < 0) { - error = -1; - goto done; - } - - if ((error = git_zstream_inflatebuf(&body, obj_data, obj_len)) < 0) - goto done; - - out->len = hdr.size; - out->type = hdr.type; - out->data = git_str_detach(&body); - -done: - git_str_dispose(&body); - return error; -} - -static int read_loose_standard(git_rawobj *out, git_str *obj) -{ - git_zstream zstream = GIT_ZSTREAM_INIT; - unsigned char head[MAX_HEADER_LEN], *body = NULL, *body_out; - size_t decompressed, head_len, body_remain, alloc_size; - obj_hdr hdr; - int error; - - if ((error = git_zstream_init(&zstream, GIT_ZSTREAM_INFLATE)) < 0 || - (error = git_zstream_set_input(&zstream, git_str_cstr(obj), git_str_len(obj))) < 0) - goto done; - - /* - * inflate the initial part of the compressed buffer in order to - * parse the header and read the largest header possible. later, we'll - * push the remainder into the body buffer. - */ - decompressed = sizeof(head); - if ((error = git_zstream_get_output(head, &decompressed, &zstream)) < 0 || - (error = parse_header(&hdr, &head_len, head, decompressed)) < 0) - goto done; - GIT_ASSERT(head_len <= decompressed); - - if (!git_object_typeisloose(hdr.type)) { - git_error_set(GIT_ERROR_ODB, "failed to inflate disk object"); - error = -1; - goto done; - } - - /* - * allocate a buffer and inflate the object data into it - * (including the initial sequence in the head buffer). - */ - if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, hdr.size, 1) || - (body = git__calloc(1, alloc_size)) == NULL) { - error = -1; - goto done; - } - body_out = body; - body_remain = hdr.size; - - decompressed -= head_len; - if (decompressed > body_remain) { - git_error_set(GIT_ERROR_ODB, "malformed object: body was longer than specified in header"); - error = -1; - goto done; - } - if (decompressed) - memcpy(body_out, head + head_len, decompressed); - body_out += decompressed; - body_remain -= decompressed; - - decompressed = body_remain; - if ((error = git_zstream_get_output(body_out, &decompressed, &zstream)) < 0) - goto done; - body_out += decompressed; - - if (!git_zstream_done(&zstream)) { - git_error_set(GIT_ERROR_ZLIB, "failed to finish zlib inflation: stream aborted prematurely"); - error = -1; - goto done; - } - - /* object bodies that are too short are silently zero-padded */ - GIT_ASSERT(body_out <= body + hdr.size); - *body_out = '\0'; - - out->data = body; - out->len = hdr.size; - out->type = hdr.type; - -done: - if (error < 0) - git__free(body); - - git_zstream_free(&zstream); - return error; -} - -static int read_loose(git_rawobj *out, git_str *loc) -{ - int error; - git_str obj = GIT_STR_INIT; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(loc); - - if (git_str_oom(loc)) - return -1; - - out->data = NULL; - out->len = 0; - out->type = GIT_OBJECT_INVALID; - - if ((error = git_futils_readbuffer(&obj, loc->ptr)) < 0) - goto done; - - if (!is_zlib_compressed_data((unsigned char *)obj.ptr, obj.size)) - error = read_loose_packlike(out, &obj); - else - error = read_loose_standard(out, &obj); - -done: - git_str_dispose(&obj); - return error; -} - -static int read_header_loose_packlike( - git_rawobj *out, const unsigned char *data, size_t len) -{ - obj_hdr hdr; - size_t header_len; - int error; - - if ((error = parse_header_packlike(&hdr, &header_len, data, len)) < 0) - return error; - - out->len = hdr.size; - out->type = hdr.type; - - return error; -} - -static int read_header_loose_standard( - git_rawobj *out, const unsigned char *data, size_t len) -{ - git_zstream zs = GIT_ZSTREAM_INIT; - obj_hdr hdr = {0}; - unsigned char inflated[MAX_HEADER_LEN] = {0}; - size_t header_len, inflated_len = sizeof(inflated); - int error; - - if ((error = git_zstream_init(&zs, GIT_ZSTREAM_INFLATE)) < 0 || - (error = git_zstream_set_input(&zs, data, len)) < 0 || - (error = git_zstream_get_output_chunk(inflated, &inflated_len, &zs)) < 0 || - (error = parse_header(&hdr, &header_len, inflated, inflated_len)) < 0) - goto done; - - out->len = hdr.size; - out->type = hdr.type; - -done: - git_zstream_free(&zs); - return error; -} - -static int read_header_loose(git_rawobj *out, git_str *loc) -{ - unsigned char obj[1024]; - ssize_t obj_len; - int fd, error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(loc); - - if (git_str_oom(loc)) - return -1; - - out->data = NULL; - - if ((error = fd = git_futils_open_ro(loc->ptr)) < 0) - goto done; - - if ((obj_len = p_read(fd, obj, sizeof(obj))) < 0) { - error = (int)obj_len; - goto done; - } - - if (!is_zlib_compressed_data(obj, (size_t)obj_len)) - error = read_header_loose_packlike(out, obj, (size_t)obj_len); - else - error = read_header_loose_standard(out, obj, (size_t)obj_len); - - if (!error && !git_object_typeisloose(out->type)) { - git_error_set(GIT_ERROR_ZLIB, "failed to read loose object header"); - error = -1; - goto done; - } - -done: - if (fd >= 0) - p_close(fd); - return error; -} - -static int locate_object( - git_str *object_location, - loose_backend *backend, - const git_oid *oid) -{ - int error = object_file_name(object_location, backend, oid); - - if (!error && !git_fs_path_exists(object_location->ptr)) - return GIT_ENOTFOUND; - - return error; -} - -/* Explore an entry of a directory and see if it matches a short oid */ -static int fn_locate_object_short_oid(void *state, git_str *pathbuf) { - loose_locate_object_state *sstate = (loose_locate_object_state *)state; - size_t hex_size = sstate->backend->oid_hexsize; - - if (git_str_len(pathbuf) - sstate->dir_len != hex_size - 2) { - /* Entry cannot be an object. Continue to next entry */ - return 0; - } - - if (git_fs_path_isdir(pathbuf->ptr) == false) { - /* We are already in the directory matching the 2 first hex characters, - * compare the first ncmp characters of the oids */ - if (!memcmp(sstate->short_oid + 2, - (unsigned char *)pathbuf->ptr + sstate->dir_len, - sstate->short_oid_len - 2)) { - - if (!sstate->found) { - sstate->res_oid[0] = sstate->short_oid[0]; - sstate->res_oid[1] = sstate->short_oid[1]; - memcpy(sstate->res_oid + 2, - pathbuf->ptr+sstate->dir_len, - hex_size - 2); - } - sstate->found++; - } - } - - if (sstate->found > 1) - return GIT_EAMBIGUOUS; - - return 0; -} - -/* Locate an object matching a given short oid */ -static int locate_object_short_oid( - git_str *object_location, - git_oid *res_oid, - loose_backend *backend, - const git_oid *short_oid, - size_t len) -{ - char *objects_dir = backend->objects_dir; - size_t dir_len = strlen(objects_dir), alloc_len; - loose_locate_object_state state; - int error; - - /* prealloc memory for OBJ_DIR/xx/xx..38x..xx */ - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, backend->oid_hexsize); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 3); - if (git_str_grow(object_location, alloc_len) < 0) - return -1; - - git_str_set(object_location, objects_dir, dir_len); - git_fs_path_to_dir(object_location); - - /* save adjusted position at end of dir so it can be restored later */ - dir_len = git_str_len(object_location); - - /* Convert raw oid to hex formatted oid */ - git_oid_fmt((char *)state.short_oid, short_oid); - - /* Explore OBJ_DIR/xx/ where xx is the beginning of hex formatted short oid */ - if (git_str_put(object_location, (char *)state.short_oid, 3) < 0) - return -1; - object_location->ptr[object_location->size - 1] = '/'; - - /* Check that directory exists */ - if (git_fs_path_isdir(object_location->ptr) == false) - return git_odb__error_notfound("no matching loose object for prefix", - short_oid, len); - - state.backend = backend; - state.dir_len = git_str_len(object_location); - state.short_oid_len = len; - state.found = 0; - - /* Explore directory to find a unique object matching short_oid */ - error = git_fs_path_direach( - object_location, 0, fn_locate_object_short_oid, &state); - if (error < 0 && error != GIT_EAMBIGUOUS) - return error; - - if (!state.found) - return git_odb__error_notfound("no matching loose object for prefix", - short_oid, len); - - if (state.found > 1) - return git_odb__error_ambiguous("multiple matches in loose objects"); - - /* Convert obtained hex formatted oid to raw */ - error = git_oid__fromstr(res_oid, (char *)state.res_oid, backend->options.oid_type); - if (error) - return error; - - /* Update the location according to the oid obtained */ - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, backend->oid_hexsize); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); - - git_str_truncate(object_location, dir_len); - if (git_str_grow(object_location, alloc_len) < 0) - return -1; - - git_oid_pathfmt(object_location->ptr + dir_len, res_oid); - - object_location->size += backend->oid_hexsize + 1; - object_location->ptr[object_location->size] = '\0'; - - return 0; -} - -/*********************************************************** - * - * LOOSE BACKEND PUBLIC API - * - * Implement the git_odb_backend API calls - * - ***********************************************************/ - -static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid) -{ - git_str object_path = GIT_STR_INIT; - git_rawobj raw; - int error; - - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(oid); - - raw.len = 0; - raw.type = GIT_OBJECT_INVALID; - - if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) { - error = git_odb__error_notfound("no matching loose object", - oid, ((struct loose_backend *)backend)->oid_hexsize); - } else if ((error = read_header_loose(&raw, &object_path)) == 0) { - *len_p = raw.len; - *type_p = raw.type; - } - - git_str_dispose(&object_path); - - return error; -} - -static int loose_backend__read(void **buffer_p, size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid) -{ - git_str object_path = GIT_STR_INIT; - git_rawobj raw; - int error = 0; - - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(oid); - - if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) { - error = git_odb__error_notfound("no matching loose object", - oid, ((struct loose_backend *)backend)->oid_hexsize); - } else if ((error = read_loose(&raw, &object_path)) == 0) { - *buffer_p = raw.data; - *len_p = raw.len; - *type_p = raw.type; - } - - git_str_dispose(&object_path); - - return error; -} - -static int loose_backend__read_prefix( - git_oid *out_oid, - void **buffer_p, - size_t *len_p, - git_object_t *type_p, - git_odb_backend *_backend, - const git_oid *short_oid, - size_t len) -{ - struct loose_backend *backend = (struct loose_backend *)_backend; - int error = 0; - - GIT_ASSERT_ARG(len >= GIT_OID_MINPREFIXLEN && - len <= backend->oid_hexsize); - - if (len == backend->oid_hexsize) { - /* We can fall back to regular read method */ - error = loose_backend__read(buffer_p, len_p, type_p, _backend, short_oid); - if (!error) - git_oid_cpy(out_oid, short_oid); - } else { - git_str object_path = GIT_STR_INIT; - git_rawobj raw; - - GIT_ASSERT_ARG(backend && short_oid); - - if ((error = locate_object_short_oid(&object_path, out_oid, - (loose_backend *)backend, short_oid, len)) == 0 && - (error = read_loose(&raw, &object_path)) == 0) - { - *buffer_p = raw.data; - *len_p = raw.len; - *type_p = raw.type; - } - - git_str_dispose(&object_path); - } - - return error; -} - -static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid) -{ - git_str object_path = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(oid); - - error = locate_object(&object_path, (loose_backend *)backend, oid); - - git_str_dispose(&object_path); - - return !error; -} - -static int loose_backend__exists_prefix( - git_oid *out, git_odb_backend *backend, const git_oid *short_id, size_t len) -{ - git_str object_path = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(short_id); - GIT_ASSERT_ARG(len >= GIT_OID_MINPREFIXLEN); - - error = locate_object_short_oid( - &object_path, out, (loose_backend *)backend, short_id, len); - - git_str_dispose(&object_path); - - return error; -} - -struct foreach_state { - struct loose_backend *backend; - size_t dir_len; - git_odb_foreach_cb cb; - void *data; -}; - -GIT_INLINE(int) filename_to_oid(struct loose_backend *backend, git_oid *oid, const char *ptr) -{ - int v; - size_t i = 0; - - if (strlen(ptr) != backend->oid_hexsize + 1) - return -1; - - if (ptr[2] != '/') { - return -1; - } - - v = (git__fromhex(ptr[i]) << 4) | git__fromhex(ptr[i+1]); - if (v < 0) - return -1; - - oid->id[0] = (unsigned char) v; - - ptr += 3; - for (i = 0; i < backend->oid_hexsize - 2; i += 2) { - v = (git__fromhex(ptr[i]) << 4) | git__fromhex(ptr[i + 1]); - if (v < 0) - return -1; - - oid->id[1 + i/2] = (unsigned char) v; - } - -#ifdef GIT_EXPERIMENTAL_SHA256 - oid->type = backend->options.oid_type; -#endif - - return 0; -} - -static int foreach_object_dir_cb(void *_state, git_str *path) -{ - git_oid oid; - struct foreach_state *state = (struct foreach_state *) _state; - - if (filename_to_oid(state->backend, &oid, path->ptr + state->dir_len) < 0) - return 0; - - return git_error_set_after_callback_function( - state->cb(&oid, state->data), "git_odb_foreach"); -} - -static int foreach_cb(void *_state, git_str *path) -{ - struct foreach_state *state = (struct foreach_state *) _state; - - /* non-dir is some stray file, ignore it */ - if (!git_fs_path_isdir(git_str_cstr(path))) - return 0; - - return git_fs_path_direach(path, 0, foreach_object_dir_cb, state); -} - -static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data) -{ - char *objects_dir; - int error; - git_str buf = GIT_STR_INIT; - struct foreach_state state; - loose_backend *backend = (loose_backend *) _backend; - - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(cb); - - objects_dir = backend->objects_dir; - - git_str_sets(&buf, objects_dir); - git_fs_path_to_dir(&buf); - if (git_str_oom(&buf)) - return -1; - - memset(&state, 0, sizeof(state)); - state.backend = backend; - state.cb = cb; - state.data = data; - state.dir_len = git_str_len(&buf); - - error = git_fs_path_direach(&buf, 0, foreach_cb, &state); - - git_str_dispose(&buf); - - return error; -} - -static int loose_backend__writestream_finalize(git_odb_stream *_stream, const git_oid *oid) -{ - loose_writestream *stream = (loose_writestream *)_stream; - loose_backend *backend = (loose_backend *)_stream->backend; - git_str final_path = GIT_STR_INIT; - int error = 0; - - if (object_file_name(&final_path, backend, oid) < 0 || - object_mkdir(&final_path, backend) < 0) - error = -1; - else - error = git_filebuf_commit_at( - &stream->fbuf, final_path.ptr); - - git_str_dispose(&final_path); - - return error; -} - -static int loose_backend__writestream_write(git_odb_stream *_stream, const char *data, size_t len) -{ - loose_writestream *stream = (loose_writestream *)_stream; - return git_filebuf_write(&stream->fbuf, data, len); -} - -static void loose_backend__writestream_free(git_odb_stream *_stream) -{ - loose_writestream *stream = (loose_writestream *)_stream; - - git_filebuf_cleanup(&stream->fbuf); - git__free(stream); -} - -static int filebuf_flags(loose_backend *backend) -{ - int flags = GIT_FILEBUF_TEMPORARY | - (backend->options.compression_level << GIT_FILEBUF_DEFLATE_SHIFT); - - if ((backend->options.flags & GIT_ODB_BACKEND_LOOSE_FSYNC) || - git_repository__fsync_gitdir) - flags |= GIT_FILEBUF_FSYNC; - - return flags; -} - -static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backend *_backend, git_object_size_t length, git_object_t type) -{ - loose_backend *backend; - loose_writestream *stream = NULL; - char hdr[MAX_HEADER_LEN]; - git_str tmp_path = GIT_STR_INIT; - size_t hdrlen; - int error; - - GIT_ASSERT_ARG(_backend); - - backend = (loose_backend *)_backend; - *stream_out = NULL; - - if ((error = git_odb__format_object_header(&hdrlen, - hdr, sizeof(hdr), length, type)) < 0) - return error; - - stream = git__calloc(1, sizeof(loose_writestream)); - GIT_ERROR_CHECK_ALLOC(stream); - - stream->stream.backend = _backend; - stream->stream.read = NULL; /* read only */ - stream->stream.write = &loose_backend__writestream_write; - stream->stream.finalize_write = &loose_backend__writestream_finalize; - stream->stream.free = &loose_backend__writestream_free; - stream->stream.mode = GIT_STREAM_WRONLY; - - if (git_str_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 || - git_filebuf_open(&stream->fbuf, tmp_path.ptr, filebuf_flags(backend), - backend->options.file_mode) < 0 || - stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0) - { - git_filebuf_cleanup(&stream->fbuf); - git__free(stream); - stream = NULL; - } - git_str_dispose(&tmp_path); - *stream_out = (git_odb_stream *)stream; - - return !stream ? -1 : 0; -} - -static int loose_backend__readstream_read( - git_odb_stream *_stream, - char *buffer, - size_t buffer_len) -{ - loose_readstream *stream = (loose_readstream *)_stream; - size_t start_remain = stream->start_len - stream->start_read; - int total = 0, error; - - buffer_len = min(buffer_len, INT_MAX); - - /* - * if we read more than just the header in the initial read, play - * that back for the caller. - */ - if (start_remain && buffer_len) { - size_t chunk = min(start_remain, buffer_len); - memcpy(buffer, stream->start + stream->start_read, chunk); - - buffer += chunk; - stream->start_read += chunk; - - total += (int)chunk; - buffer_len -= chunk; - } - - if (buffer_len) { - size_t chunk = buffer_len; - - if ((error = git_zstream_get_output(buffer, &chunk, &stream->zstream)) < 0) - return error; - - total += (int)chunk; - } - - return (int)total; -} - -static void loose_backend__readstream_free(git_odb_stream *_stream) -{ - loose_readstream *stream = (loose_readstream *)_stream; - - git_futils_mmap_free(&stream->map); - git_zstream_free(&stream->zstream); - git__free(stream); -} - -static int loose_backend__readstream_packlike( - obj_hdr *hdr, - loose_readstream *stream) -{ - const unsigned char *data; - size_t data_len, head_len; - int error; - - data = stream->map.data; - data_len = stream->map.len; - - /* - * read the object header, which is an (uncompressed) - * binary encoding of the object type and size. - */ - if ((error = parse_header_packlike(hdr, &head_len, data, data_len)) < 0) - return error; - - if (!git_object_typeisloose(hdr->type)) { - git_error_set(GIT_ERROR_ODB, "failed to inflate loose object"); - return -1; - } - - return git_zstream_set_input(&stream->zstream, - data + head_len, data_len - head_len); -} - -static int loose_backend__readstream_standard( - obj_hdr *hdr, - loose_readstream *stream) -{ - unsigned char head[MAX_HEADER_LEN]; - size_t init, head_len; - int error; - - if ((error = git_zstream_set_input(&stream->zstream, - stream->map.data, stream->map.len)) < 0) - return error; - - init = sizeof(head); - - /* - * inflate the initial part of the compressed buffer in order to - * parse the header; read the largest header possible, then store - * it in the `start` field of the stream object. - */ - if ((error = git_zstream_get_output(head, &init, &stream->zstream)) < 0 || - (error = parse_header(hdr, &head_len, head, init)) < 0) - return error; - - if (!git_object_typeisloose(hdr->type)) { - git_error_set(GIT_ERROR_ODB, "failed to inflate disk object"); - return -1; - } - - if (init > head_len) { - stream->start_len = init - head_len; - memcpy(stream->start, head + head_len, init - head_len); - } - - return 0; -} - -static int loose_backend__readstream( - git_odb_stream **stream_out, - size_t *len_out, - git_object_t *type_out, - git_odb_backend *_backend, - const git_oid *oid) -{ - loose_backend *backend; - loose_readstream *stream = NULL; - git_hash_ctx *hash_ctx = NULL; - git_str object_path = GIT_STR_INIT; - git_hash_algorithm_t algorithm; - obj_hdr hdr; - int error = 0; - - GIT_ASSERT_ARG(stream_out); - GIT_ASSERT_ARG(len_out); - GIT_ASSERT_ARG(type_out); - GIT_ASSERT_ARG(_backend); - GIT_ASSERT_ARG(oid); - - backend = (loose_backend *)_backend; - *stream_out = NULL; - *len_out = 0; - *type_out = GIT_OBJECT_INVALID; - - if (locate_object(&object_path, backend, oid) < 0) { - error = git_odb__error_notfound("no matching loose object", - oid, backend->oid_hexsize); - goto done; - } - - stream = git__calloc(1, sizeof(loose_readstream)); - GIT_ERROR_CHECK_ALLOC(stream); - - hash_ctx = git__malloc(sizeof(git_hash_ctx)); - GIT_ERROR_CHECK_ALLOC(hash_ctx); - - algorithm = git_oid_algorithm(backend->options.oid_type); - - if ((error = git_hash_ctx_init(hash_ctx, algorithm)) < 0 || - (error = git_futils_mmap_ro_file(&stream->map, object_path.ptr)) < 0 || - (error = git_zstream_init(&stream->zstream, GIT_ZSTREAM_INFLATE)) < 0) - goto done; - - /* check for a packlike loose object */ - if (!is_zlib_compressed_data(stream->map.data, stream->map.len)) - error = loose_backend__readstream_packlike(&hdr, stream); - else - error = loose_backend__readstream_standard(&hdr, stream); - - if (error < 0) - goto done; - - stream->stream.backend = _backend; - stream->stream.hash_ctx = hash_ctx; - stream->stream.read = &loose_backend__readstream_read; - stream->stream.free = &loose_backend__readstream_free; - - *stream_out = (git_odb_stream *)stream; - *len_out = hdr.size; - *type_out = hdr.type; - -done: - if (error < 0) { - if (stream) { - git_futils_mmap_free(&stream->map); - git_zstream_free(&stream->zstream); - git__free(stream); - } - if (hash_ctx) { - git_hash_ctx_cleanup(hash_ctx); - git__free(hash_ctx); - } - } - - git_str_dispose(&object_path); - return error; -} - -static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, const void *data, size_t len, git_object_t type) -{ - int error = 0; - git_str final_path = GIT_STR_INIT; - char header[MAX_HEADER_LEN]; - size_t header_len; - git_filebuf fbuf = GIT_FILEBUF_INIT; - loose_backend *backend; - - backend = (loose_backend *)_backend; - - /* prepare the header for the file */ - if ((error = git_odb__format_object_header(&header_len, - header, sizeof(header), len, type)) < 0) - goto cleanup; - - if (git_str_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 || - git_filebuf_open(&fbuf, final_path.ptr, filebuf_flags(backend), - backend->options.file_mode) < 0) - { - error = -1; - goto cleanup; - } - - git_filebuf_write(&fbuf, header, header_len); - git_filebuf_write(&fbuf, data, len); - - if (object_file_name(&final_path, backend, oid) < 0 || - object_mkdir(&final_path, backend) < 0 || - git_filebuf_commit_at(&fbuf, final_path.ptr) < 0) - error = -1; - -cleanup: - if (error < 0) - git_filebuf_cleanup(&fbuf); - git_str_dispose(&final_path); - return error; -} - -static int loose_backend__freshen( - git_odb_backend *_backend, - const git_oid *oid) -{ - loose_backend *backend = (loose_backend *)_backend; - git_str path = GIT_STR_INIT; - int error; - - if (object_file_name(&path, backend, oid) < 0) - return -1; - - error = git_futils_touch(path.ptr, NULL); - git_str_dispose(&path); - - return error; -} - -static void loose_backend__free(git_odb_backend *_backend) -{ - git__free(_backend); -} - -static void normalize_options( - git_odb_backend_loose_options *opts, - const git_odb_backend_loose_options *given_opts) -{ - git_odb_backend_loose_options init = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; - - if (given_opts) - memcpy(opts, given_opts, sizeof(git_odb_backend_loose_options)); - else - memcpy(opts, &init, sizeof(git_odb_backend_loose_options)); - - if (opts->compression_level < 0) - opts->compression_level = Z_BEST_SPEED; - - if (opts->dir_mode == 0) - opts->dir_mode = GIT_OBJECT_DIR_MODE; - - if (opts->file_mode == 0) - opts->file_mode = GIT_OBJECT_FILE_MODE; - - if (opts->oid_type == 0) - opts->oid_type = GIT_OID_DEFAULT; -} - -int git_odb__backend_loose( - git_odb_backend **backend_out, - const char *objects_dir, - git_odb_backend_loose_options *opts) -{ - loose_backend *backend; - size_t objects_dirlen, alloclen; - - GIT_ASSERT_ARG(backend_out); - GIT_ASSERT_ARG(objects_dir); - - objects_dirlen = strlen(objects_dir); - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(loose_backend), objects_dirlen); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 2); - backend = git__calloc(1, alloclen); - GIT_ERROR_CHECK_ALLOC(backend); - - backend->parent.version = GIT_ODB_BACKEND_VERSION; - backend->objects_dirlen = objects_dirlen; - memcpy(backend->objects_dir, objects_dir, objects_dirlen); - - if (backend->objects_dir[backend->objects_dirlen - 1] != '/') - backend->objects_dir[backend->objects_dirlen++] = '/'; - - normalize_options(&backend->options, opts); - backend->oid_hexsize = git_oid_hexsize(backend->options.oid_type); - - backend->parent.read = &loose_backend__read; - backend->parent.write = &loose_backend__write; - backend->parent.read_prefix = &loose_backend__read_prefix; - backend->parent.read_header = &loose_backend__read_header; - backend->parent.writestream = &loose_backend__writestream; - backend->parent.readstream = &loose_backend__readstream; - backend->parent.exists = &loose_backend__exists; - backend->parent.exists_prefix = &loose_backend__exists_prefix; - backend->parent.foreach = &loose_backend__foreach; - backend->parent.freshen = &loose_backend__freshen; - backend->parent.free = &loose_backend__free; - - *backend_out = (git_odb_backend *)backend; - return 0; -} - - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_odb_backend_loose( - git_odb_backend **backend_out, - const char *objects_dir, - git_odb_backend_loose_options *opts) -{ - return git_odb__backend_loose(backend_out, objects_dir, opts); -} -#else -int git_odb_backend_loose( - git_odb_backend **backend_out, - const char *objects_dir, - int compression_level, - int do_fsync, - unsigned int dir_mode, - unsigned int file_mode) -{ - git_odb_backend_loose_flag_t flags = 0; - git_odb_backend_loose_options opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; - - if (do_fsync) - flags |= GIT_ODB_BACKEND_LOOSE_FSYNC; - - opts.flags = flags; - opts.compression_level = compression_level; - opts.dir_mode = dir_mode; - opts.file_mode = file_mode; - opts.oid_type = GIT_OID_DEFAULT; - - return git_odb__backend_loose(backend_out, objects_dir, &opts); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/odb_mempack.c b/vendor/libgit2-sys/libgit2/src/libgit2/odb_mempack.c deleted file mode 100644 index 2f3fba9..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/odb_mempack.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "buf.h" -#include "futils.h" -#include "hash.h" -#include "odb.h" -#include "array.h" -#include "pack-objects.h" - -#include "git2/odb_backend.h" -#include "git2/object.h" -#include "git2/types.h" -#include "git2/pack.h" -#include "git2/sys/odb_backend.h" -#include "git2/sys/mempack.h" - -struct memobject { - git_oid oid; - size_t len; - git_object_t type; - char data[GIT_FLEX_ARRAY]; -}; - -GIT_HASHMAP_OID_SETUP(git_odb_mempack_oidmap, struct memobject *); - -struct memory_packer_db { - git_odb_backend parent; - git_odb_mempack_oidmap objects; - git_array_t(struct memobject *) commits; -}; - -static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void *data, size_t len, git_object_t type) -{ - struct memory_packer_db *db = (struct memory_packer_db *)_backend; - struct memobject *obj = NULL; - size_t alloc_len; - - if (git_odb_mempack_oidmap_contains(&db->objects, oid)) - return 0; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(struct memobject), len); - obj = git__malloc(alloc_len); - GIT_ERROR_CHECK_ALLOC(obj); - - memcpy(obj->data, data, len); - git_oid_cpy(&obj->oid, oid); - obj->len = len; - obj->type = type; - - if (git_odb_mempack_oidmap_put(&db->objects, &obj->oid, obj) < 0) - return -1; - - if (type == GIT_OBJECT_COMMIT) { - struct memobject **store = git_array_alloc(db->commits); - GIT_ERROR_CHECK_ALLOC(store); - *store = obj; - } - - return 0; -} - -static int impl__exists(git_odb_backend *backend, const git_oid *oid) -{ - struct memory_packer_db *db = (struct memory_packer_db *)backend; - - return git_odb_mempack_oidmap_contains(&db->objects, oid); -} - -static int impl__read(void **buffer_p, size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid) -{ - struct memory_packer_db *db = (struct memory_packer_db *)backend; - struct memobject *obj; - int error; - - if ((error = git_odb_mempack_oidmap_get(&obj, &db->objects, oid)) != 0) - return error; - - *len_p = obj->len; - *type_p = obj->type; - *buffer_p = git__malloc(obj->len); - GIT_ERROR_CHECK_ALLOC(*buffer_p); - - memcpy(*buffer_p, obj->data, obj->len); - return 0; -} - -static int impl__read_header(size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid) -{ - struct memory_packer_db *db = (struct memory_packer_db *)backend; - struct memobject *obj; - int error; - - if ((error = git_odb_mempack_oidmap_get(&obj, &db->objects, oid)) != 0) - return error; - - *len_p = obj->len; - *type_p = obj->type; - return 0; -} - -static int git_mempack__dump( - git_str *pack, - git_repository *repo, - git_odb_backend *_backend) -{ - struct memory_packer_db *db = (struct memory_packer_db *)_backend; - git_packbuilder *packbuilder; - uint32_t i; - int err = -1; - - if (git_packbuilder_new(&packbuilder, repo) < 0) - return -1; - - git_packbuilder_set_threads(packbuilder, 0); - - for (i = 0; i < db->commits.size; ++i) { - struct memobject *commit = db->commits.ptr[i]; - - err = git_packbuilder_insert_commit(packbuilder, &commit->oid); - if (err < 0) - goto cleanup; - } - - err = git_packbuilder__write_buf(pack, packbuilder); - -cleanup: - git_packbuilder_free(packbuilder); - return err; -} - -int git_mempack_write_thin_pack(git_odb_backend *backend, git_packbuilder *pb) -{ - struct memory_packer_db *db = (struct memory_packer_db *)backend; - const git_oid *oid; - git_hashmap_iter_t iter = GIT_HASHMAP_INIT; - int err; - - while (true) { - err = git_odb_mempack_oidmap_iterate(&iter, &oid, NULL, &db->objects); - - if (err == GIT_ITEROVER) - break; - else if (err != 0) - return err; - - err = git_packbuilder_insert(pb, oid, NULL); - if (err != 0) - return err; - } - - return 0; -} - -int git_mempack_dump( - git_buf *pack, - git_repository *repo, - git_odb_backend *_backend) -{ - GIT_BUF_WRAP_PRIVATE(pack, git_mempack__dump, repo, _backend); -} - -int git_mempack_reset(git_odb_backend *_backend) -{ - struct memory_packer_db *db = (struct memory_packer_db *)_backend; - struct memobject *object = NULL; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - while (git_odb_mempack_oidmap_iterate(&iter, NULL, &object, &db->objects) == 0) - git__free(object); - - git_array_clear(db->commits); - git_odb_mempack_oidmap_clear(&db->objects); - - return 0; -} - -static void impl__free(git_odb_backend *_backend) -{ - struct memory_packer_db *db = (struct memory_packer_db *)_backend; - - git_mempack_reset(_backend); - git_odb_mempack_oidmap_dispose(&db->objects); - git__free(db); -} - -int git_mempack_new(git_odb_backend **out) -{ - struct memory_packer_db *db; - - GIT_ASSERT_ARG(out); - - db = git__calloc(1, sizeof(struct memory_packer_db)); - GIT_ERROR_CHECK_ALLOC(db); - - db->parent.version = GIT_ODB_BACKEND_VERSION; - db->parent.read = &impl__read; - db->parent.write = &impl__write; - db->parent.read_header = &impl__read_header; - db->parent.exists = &impl__exists; - db->parent.free = &impl__free; - - *out = (git_odb_backend *)db; - return 0; -} - -int git_mempack_object_count(size_t *out, git_odb_backend *_backend) -{ - struct memory_packer_db *db = (struct memory_packer_db *)_backend; - - GIT_ASSERT_ARG(_backend); - - *out = (size_t)git_odb_mempack_oidmap_size(&db->objects); - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/odb_pack.c b/vendor/libgit2-sys/libgit2/src/libgit2/odb_pack.c deleted file mode 100644 index ef8d353..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/odb_pack.c +++ /dev/null @@ -1,994 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include -#include "git2/repository.h" -#include "git2/indexer.h" -#include "git2/sys/odb_backend.h" -#include "delta.h" -#include "futils.h" -#include "hash.h" -#include "midx.h" -#include "mwindow.h" -#include "odb.h" -#include "pack.h" - -#include "git2/odb_backend.h" - -/* re-freshen pack files no more than every 2 seconds */ -#define FRESHEN_FREQUENCY 2 - -struct pack_backend { - git_odb_backend parent; - git_odb_backend_pack_options opts; - git_midx_file *midx; - git_vector midx_packs; - git_vector packs; - struct git_pack_file *last_found; - char *pack_folder; -}; - -struct pack_writepack { - struct git_odb_writepack parent; - git_indexer *indexer; -}; - -/** - * The wonderful tale of a Packed Object lookup query - * =================================================== - * A riveting and epic story of epicness and ASCII - * art, presented by yours truly, - * Sir Vicent of Marti - * - * - * Chapter 1: Once upon a time... - * Initialization of the Pack Backend - * -------------------------------------------------- - * - * # git_odb_backend_pack - * | Creates the pack backend structure, initializes the - * | callback pointers to our default read() and exist() methods, - * | and tries to find the `pack` folder, if it exists. ODBs without a `pack` - * | folder are ignored altogether. If there is a `pack` folder, it tries to - * | preload all the known packfiles in the ODB. - * | - * |-# pack_backend__refresh - * | The `multi-pack-index` is loaded if it exists and is valid. - * | Then we run a `dirent` callback through every file in the pack folder, - * | even those present in `multi-pack-index`. The unindexed packfiles are - * | then sorted according to a sorting callback. - * | - * |-# refresh_multi_pack_index - * | Detect the presence of the `multi-pack-index` file. If it needs to be - * | refreshed, frees the old copy and tries to load the new one, together - * | with all the packfiles it indexes. If the process fails, fall back to - * | the old behavior, as if the `multi-pack-index` file was not there. - * | - * |-# packfile_load__cb - * | | This callback is called from `dirent` with every single file - * | | inside the pack folder. We find the packs by actually locating - * | | their index (ends in ".idx"). From that index, we verify that - * | | the corresponding packfile exists and is valid, and if so, we - * | | add it to the pack list. - * | | - * | # git_mwindow_get_pack - * | Make sure that there's a packfile to back this index, and store - * | some very basic information regarding the packfile itself, - * | such as the full path, the size, and the modification time. - * | We don't actually open the packfile to check for internal consistency. - * | - * |-# packfile_sort__cb - * Sort all the preloaded packs according to some specific criteria: - * we prioritize the "newer" packs because it's more likely they - * contain the objects we are looking for, and we prioritize local - * packs over remote ones. - * - * - * - * Chapter 2: To be, or not to be... - * A standard packed `exist` query for an OID - * -------------------------------------------------- - * - * # pack_backend__exists / pack_backend__exists_prefix - * | Check if the given oid (or an oid prefix) exists in any of the - * | packs that have been loaded for our ODB. - * | - * |-# pack_entry_find / pack_entry_find_prefix - * | If there is a multi-pack-index present, search the oid in that - * | index first. If it is not found there, iterate through all the unindexed - * | packs that have been preloaded (starting by the pack where the latest - * | object was found) to try to find the OID in one of them. - * | - * |-# git_midx_entry_find - * | Search for the oid in the multi-pack-index. See - * | - * | for specifics on the multi-pack-index format and how do we find - * | entries in it. - * | - * |-# git_pack_entry_find - * | Check the index of an individual unindexed pack to see if the - * | OID can be found. If we can find the offset to that inside of the - * | index, that means the object is contained inside of the packfile and - * | we can stop searching. Before returning, we verify that the - * | packfile behind the index we are searching still exists on disk. - * | - * |-# pack_entry_find_offset - * | Mmap the actual index file to disk if it hasn't been opened - * | yet, and run a binary search through it to find the OID. - * | See - * | for specifics on the Packfile Index format and how do we find - * | entries in it. - * | - * |-# pack_index_open - * | Guess the name of the index based on the full path to the - * | packfile, open it and verify its contents. Only if the index - * | has not been opened already. - * | - * |-# pack_index_check - * Mmap the index file and do a quick run through the header - * to guess the index version (right now we support v1 and v2), - * and to verify that the size of the index makes sense. - * - * - * - * Chapter 3: The neverending story... - * A standard packed `lookup` query for an OID - * -------------------------------------------------- - * - * # pack_backend__read / pack_backend__read_prefix - * | Check if the given oid (or an oid prefix) exists in any of the - * | packs that have been loaded for our ODB. If it does, open the packfile and - * | read from it. - * | - * |-# git_packfile_unpack - * Armed with a packfile and the offset within it, we can finally unpack - * the object pointed at by the oid. This involves mmapping part of - * the `.pack` file, and uncompressing the object within it (if it is - * stored in the undelfitied representation), or finding a base object and - * applying some deltas to its uncompressed representation (if it is stored - * in the deltified representation). See - * - * for specifics on the Packfile format and how do we read from it. - * - */ - - -/*********************************************************** - * - * FORWARD DECLARATIONS - * - ***********************************************************/ - -static int packfile_sort__cb(const void *a_, const void *b_); - -static int packfile_load__cb(void *_data, git_str *path); - -static int packfile_byname_search_cmp(const void *path, const void *pack_entry); - -static int pack_entry_find(struct git_pack_entry *e, - struct pack_backend *backend, const git_oid *oid); - -/* Can find the offset of an object given - * a prefix of an identifier. - * Sets GIT_EAMBIGUOUS if short oid is ambiguous. - * This method assumes that len is between - * GIT_OID_MINPREFIXLEN and the hexsize for the hash type. - */ -static int pack_entry_find_prefix( - struct git_pack_entry *e, - struct pack_backend *backend, - const git_oid *short_oid, - size_t len); - - - -/*********************************************************** - * - * PACK WINDOW MANAGEMENT - * - ***********************************************************/ - -static int packfile_byname_search_cmp(const void *path_, const void *p_) -{ - const git_str *path = (const git_str *)path_; - const struct git_pack_file *p = (const struct git_pack_file *)p_; - - return strncmp(p->pack_name, git_str_cstr(path), git_str_len(path)); -} - -static int packfile_sort__cb(const void *a_, const void *b_) -{ - const struct git_pack_file *a = a_; - const struct git_pack_file *b = b_; - int st; - - /* - * Local packs tend to contain objects specific to our - * variant of the project than remote ones. In addition, - * remote ones could be on a network mounted filesystem. - * Favor local ones for these reasons. - */ - st = a->pack_local - b->pack_local; - if (st) - return -st; - - /* - * Younger packs tend to contain more recent objects, - * and more recent objects tend to get accessed more - * often. - */ - if (a->mtime < b->mtime) - return 1; - else if (a->mtime == b->mtime) - return 0; - - return -1; -} - - -static int packfile_load__cb(void *data, git_str *path) -{ - struct pack_backend *backend = data; - struct git_pack_file *pack; - const char *path_str = git_str_cstr(path); - git_str index_prefix = GIT_STR_INIT; - size_t cmp_len = git_str_len(path); - int error; - - if (cmp_len <= strlen(".idx") || git__suffixcmp(path_str, ".idx") != 0) - return 0; /* not an index */ - - cmp_len -= strlen(".idx"); - git_str_attach_notowned(&index_prefix, path_str, cmp_len); - - if (git_vector_search2(NULL, &backend->midx_packs, packfile_byname_search_cmp, &index_prefix) == 0) - return 0; - if (git_vector_search2(NULL, &backend->packs, packfile_byname_search_cmp, &index_prefix) == 0) - return 0; - - error = git_mwindow_get_pack(&pack, path->ptr, backend->opts.oid_type); - - /* ignore missing .pack file as git does */ - if (error == GIT_ENOTFOUND) { - git_error_clear(); - return 0; - } - - if (!error) - error = git_vector_insert(&backend->packs, pack); - - return error; - -} - -static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid) -{ - struct git_pack_file *last_found = backend->last_found, *p; - git_midx_entry midx_entry; - size_t oid_hexsize = git_oid_hexsize(backend->opts.oid_type); - size_t i; - - if (backend->midx && - git_midx_entry_find(&midx_entry, backend->midx, oid, oid_hexsize) == 0 && - midx_entry.pack_index < git_vector_length(&backend->midx_packs)) { - e->offset = midx_entry.offset; - git_oid_cpy(&e->id, &midx_entry.sha1); - e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index); - return 0; - } - - if (last_found && - git_pack_entry_find(e, last_found, oid, oid_hexsize) == 0) - return 0; - - git_vector_foreach(&backend->packs, i, p) { - if (p == last_found) - continue; - - if (git_pack_entry_find(e, p, oid, oid_hexsize) == 0) { - backend->last_found = p; - return 0; - } - } - - return git_odb__error_notfound( - "failed to find pack entry", oid, oid_hexsize); -} - -static int pack_entry_find_prefix( - struct git_pack_entry *e, - struct pack_backend *backend, - const git_oid *short_oid, - size_t len) -{ - int error; - size_t i; - git_oid found_full_oid; - bool found = false; - struct git_pack_file *last_found = backend->last_found, *p; - git_midx_entry midx_entry; - -#ifdef GIT_EXPERIMENTAL_SHA256 - git_oid_clear(&found_full_oid, short_oid->type); -#else - git_oid_clear(&found_full_oid, GIT_OID_SHA1); -#endif - - if (backend->midx) { - error = git_midx_entry_find(&midx_entry, backend->midx, short_oid, len); - if (error == GIT_EAMBIGUOUS) - return error; - if (!error && midx_entry.pack_index < git_vector_length(&backend->midx_packs)) { - e->offset = midx_entry.offset; - git_oid_cpy(&e->id, &midx_entry.sha1); - e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index); - git_oid_cpy(&found_full_oid, &e->id); - found = true; - } - } - - if (last_found) { - error = git_pack_entry_find(e, last_found, short_oid, len); - if (error == GIT_EAMBIGUOUS) - return error; - if (!error) { - if (found && git_oid_cmp(&e->id, &found_full_oid)) - return git_odb__error_ambiguous("found multiple pack entries"); - git_oid_cpy(&found_full_oid, &e->id); - found = true; - } - } - - git_vector_foreach(&backend->packs, i, p) { - if (p == last_found) - continue; - - error = git_pack_entry_find(e, p, short_oid, len); - if (error == GIT_EAMBIGUOUS) - return error; - if (!error) { - if (found && git_oid_cmp(&e->id, &found_full_oid)) - return git_odb__error_ambiguous("found multiple pack entries"); - git_oid_cpy(&found_full_oid, &e->id); - found = true; - backend->last_found = p; - } - } - - if (!found) - return git_odb__error_notfound("no matching pack entry for prefix", - short_oid, len); - else - return 0; -} - -/*********************************************************** - * - * MULTI-PACK-INDEX SUPPORT - * - * Functions needed to support the multi-pack-index. - * - ***********************************************************/ - -/* - * Remove the multi-pack-index, and move all midx_packs to packs. - */ -static int remove_multi_pack_index(struct pack_backend *backend) -{ - size_t i, j = git_vector_length(&backend->packs); - struct pack_backend *p; - int error = git_vector_size_hint( - &backend->packs, - j + git_vector_length(&backend->midx_packs)); - if (error < 0) - return error; - - git_vector_foreach(&backend->midx_packs, i, p) - git_vector_set(NULL, &backend->packs, j++, p); - git_vector_clear(&backend->midx_packs); - - git_midx_free(backend->midx); - backend->midx = NULL; - - return 0; -} - -/* - * Loads a single .pack file referred to by the multi-pack-index. These must - * match the order in which they are declared in the multi-pack-index file, - * since these files are referred to by their index. - */ -static int process_multi_pack_index_pack( - struct pack_backend *backend, - size_t i, - const char *packfile_name) -{ - int error; - struct git_pack_file *pack; - size_t found_position; - git_str pack_path = GIT_STR_INIT, index_prefix = GIT_STR_INIT; - - error = git_str_joinpath(&pack_path, backend->pack_folder, packfile_name); - if (error < 0) - return error; - - /* This is ensured by midx_parse_packfile_name() */ - if (git_str_len(&pack_path) <= strlen(".idx") || git__suffixcmp(git_str_cstr(&pack_path), ".idx") != 0) - return git_odb__error_notfound("midx file contained a non-index", NULL, 0); - - git_str_attach_notowned(&index_prefix, git_str_cstr(&pack_path), git_str_len(&pack_path) - strlen(".idx")); - - if (git_vector_search2(&found_position, &backend->packs, packfile_byname_search_cmp, &index_prefix) == 0) { - /* Pack was found in the packs list. Moving it to the midx_packs list. */ - git_str_dispose(&pack_path); - git_vector_set(NULL, &backend->midx_packs, i, git_vector_get(&backend->packs, found_position)); - git_vector_remove(&backend->packs, found_position); - return 0; - } - - /* Pack was not found. Allocate a new one. */ - error = git_mwindow_get_pack( - &pack, - git_str_cstr(&pack_path), - backend->opts.oid_type); - git_str_dispose(&pack_path); - if (error < 0) - return error; - - git_vector_set(NULL, &backend->midx_packs, i, pack); - return 0; -} - -/* - * Reads the multi-pack-index. If this fails for whatever reason, the - * multi-pack-index object is freed, and all the packfiles that are related to - * it are moved to the unindexed packfiles vector. - */ -static int refresh_multi_pack_index(struct pack_backend *backend) -{ - int error; - git_str midx_path = GIT_STR_INIT; - const char *packfile_name; - size_t i; - - error = git_str_joinpath(&midx_path, backend->pack_folder, "multi-pack-index"); - if (error < 0) - return error; - - /* - * Check whether the multi-pack-index has changed. If it has, close any - * old multi-pack-index and move all the packfiles to the unindexed - * packs. This is done to prevent losing any open packfiles in case - * refreshing the new multi-pack-index fails, or the file is deleted. - */ - if (backend->midx) { - if (!git_midx_needs_refresh(backend->midx, git_str_cstr(&midx_path))) { - git_str_dispose(&midx_path); - return 0; - } - error = remove_multi_pack_index(backend); - if (error < 0) { - git_str_dispose(&midx_path); - return error; - } - } - - error = git_midx_open(&backend->midx, git_str_cstr(&midx_path), - backend->opts.oid_type); - - git_str_dispose(&midx_path); - if (error < 0) - return error; - - git_vector_resize_to(&backend->midx_packs, git_vector_length(&backend->midx->packfile_names)); - - git_vector_foreach(&backend->midx->packfile_names, i, packfile_name) { - error = process_multi_pack_index_pack(backend, i, packfile_name); - if (error < 0) { - /* - * Something failed during reading multi-pack-index. - * Restore the state of backend as if the - * multi-pack-index was never there, and move all - * packfiles that have been processed so far to the - * unindexed packs. - */ - git_vector_resize_to(&backend->midx_packs, i); - remove_multi_pack_index(backend); - return error; - } - } - - return 0; -} - -/*********************************************************** - * - * PACKED BACKEND PUBLIC API - * - * Implement the git_odb_backend API calls - * - ***********************************************************/ -static int pack_backend__refresh(git_odb_backend *backend_) -{ - int error; - struct stat st; - git_str path = GIT_STR_INIT; - struct pack_backend *backend = (struct pack_backend *)backend_; - - if (backend->pack_folder == NULL) - return 0; - - if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode)) - return git_odb__error_notfound("failed to refresh packfiles", NULL, 0); - - if (refresh_multi_pack_index(backend) < 0) { - /* - * It is okay if this fails. We will just not use the - * multi-pack-index in this case. - */ - git_error_clear(); - } - - /* reload all packs */ - git_str_sets(&path, backend->pack_folder); - error = git_fs_path_direach(&path, 0, packfile_load__cb, backend); - - git_str_dispose(&path); - git_vector_sort(&backend->packs); - - return error; -} - -static int pack_backend__read_header( - size_t *len_p, git_object_t *type_p, - struct git_odb_backend *backend, const git_oid *oid) -{ - struct git_pack_entry e; - int error; - - GIT_ASSERT_ARG(len_p); - GIT_ASSERT_ARG(type_p); - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(oid); - - if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0) - return error; - - return git_packfile_resolve_header(len_p, type_p, e.p, e.offset); -} - -static int pack_backend__freshen( - git_odb_backend *backend, const git_oid *oid) -{ - struct git_pack_entry e; - time_t now; - int error; - - if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0) - return error; - - now = time(NULL); - - if (e.p->last_freshen > now - FRESHEN_FREQUENCY) - return 0; - - if ((error = git_futils_touch(e.p->pack_name, &now)) < 0) - return error; - - e.p->last_freshen = now; - return 0; -} - -static int pack_backend__read( - void **buffer_p, size_t *len_p, git_object_t *type_p, - git_odb_backend *backend, const git_oid *oid) -{ - struct git_pack_entry e; - git_rawobj raw = {NULL}; - int error; - - if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0 || - (error = git_packfile_unpack(&raw, e.p, &e.offset)) < 0) - return error; - - *buffer_p = raw.data; - *len_p = raw.len; - *type_p = raw.type; - - return 0; -} - -static int pack_backend__read_prefix( - git_oid *out_oid, - void **buffer_p, - size_t *len_p, - git_object_t *type_p, - git_odb_backend *_backend, - const git_oid *short_oid, - size_t len) -{ - struct pack_backend *backend = (struct pack_backend *)_backend; - int error = 0; - - if (len < GIT_OID_MINPREFIXLEN) - error = git_odb__error_ambiguous("prefix length too short"); - - else if (len >= git_oid_hexsize(backend->opts.oid_type)) { - /* We can fall back to regular read method */ - error = pack_backend__read(buffer_p, len_p, type_p, _backend, short_oid); - if (!error) - git_oid_cpy(out_oid, short_oid); - } else { - struct git_pack_entry e; - git_rawobj raw = {NULL}; - - if ((error = pack_entry_find_prefix(&e, - backend, short_oid, len)) == 0 && - (error = git_packfile_unpack(&raw, e.p, &e.offset)) == 0) - { - *buffer_p = raw.data; - *len_p = raw.len; - *type_p = raw.type; - git_oid_cpy(out_oid, &e.id); - } - } - - return error; -} - -static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid) -{ - struct git_pack_entry e; - return pack_entry_find(&e, (struct pack_backend *)backend, oid) == 0; -} - -static int pack_backend__exists_prefix( - git_oid *out, git_odb_backend *backend, const git_oid *short_id, size_t len) -{ - int error; - struct pack_backend *pb = (struct pack_backend *)backend; - struct git_pack_entry e = {0}; - - error = pack_entry_find_prefix(&e, pb, short_id, len); - git_oid_cpy(out, &e.id); - return error; -} - -static int pack_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data) -{ - int error; - struct git_pack_file *p; - struct pack_backend *backend; - unsigned int i; - - GIT_ASSERT_ARG(_backend); - GIT_ASSERT_ARG(cb); - - backend = (struct pack_backend *)_backend; - - /* Make sure we know about the packfiles */ - if ((error = pack_backend__refresh(_backend)) != 0) - return error; - - if (backend->midx && (error = git_midx_foreach_entry(backend->midx, cb, data)) != 0) - return error; - git_vector_foreach(&backend->packs, i, p) { - if ((error = git_pack_foreach_entry(p, cb, data)) != 0) - return error; - } - - return 0; -} - -static int pack_backend__writepack_append(struct git_odb_writepack *_writepack, const void *data, size_t size, git_indexer_progress *stats) -{ - struct pack_writepack *writepack = (struct pack_writepack *)_writepack; - - GIT_ASSERT_ARG(writepack); - - return git_indexer_append(writepack->indexer, data, size, stats); -} - -static int pack_backend__writepack_commit(struct git_odb_writepack *_writepack, git_indexer_progress *stats) -{ - struct pack_writepack *writepack = (struct pack_writepack *)_writepack; - - GIT_ASSERT_ARG(writepack); - - return git_indexer_commit(writepack->indexer, stats); -} - -static void pack_backend__writepack_free(struct git_odb_writepack *_writepack) -{ - struct pack_writepack *writepack; - - if (!_writepack) - return; - - writepack = (struct pack_writepack *)_writepack; - - git_indexer_free(writepack->indexer); - git__free(writepack); -} - -static int pack_backend__writepack(struct git_odb_writepack **out, - git_odb_backend *_backend, - git_odb *odb, - git_indexer_progress_cb progress_cb, - void *progress_payload) -{ - git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; - struct pack_backend *backend; - struct pack_writepack *writepack; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(_backend); - - *out = NULL; - - opts.progress_cb = progress_cb; - opts.progress_cb_payload = progress_payload; - - backend = (struct pack_backend *)_backend; - - writepack = git__calloc(1, sizeof(struct pack_writepack)); - GIT_ERROR_CHECK_ALLOC(writepack); - -#ifdef GIT_EXPERIMENTAL_SHA256 - opts.odb = odb; - opts.oid_type = backend->opts.oid_type; - - error = git_indexer_new(&writepack->indexer, - backend->pack_folder, - &opts); -#else - error = git_indexer_new(&writepack->indexer, - backend->pack_folder, 0, odb, &opts); -#endif - - if (error < 0) - return -1; - - writepack->parent.backend = _backend; - writepack->parent.append = pack_backend__writepack_append; - writepack->parent.commit = pack_backend__writepack_commit; - writepack->parent.free = pack_backend__writepack_free; - - *out = (git_odb_writepack *)writepack; - - return 0; -} - -static int get_idx_path( - git_str *idx_path, - struct pack_backend *backend, - struct git_pack_file *p) -{ - size_t path_len; - int error; - - error = git_fs_path_prettify(idx_path, p->pack_name, backend->pack_folder); - if (error < 0) - return error; - path_len = git_str_len(idx_path); - if (path_len <= strlen(".pack") || git__suffixcmp(git_str_cstr(idx_path), ".pack") != 0) - return git_odb__error_notfound("packfile does not end in .pack", NULL, 0); - path_len -= strlen(".pack"); - error = git_str_splice(idx_path, path_len, strlen(".pack"), ".idx", strlen(".idx")); - if (error < 0) - return error; - - return 0; -} - -static int pack_backend__writemidx(git_odb_backend *_backend) -{ - struct pack_backend *backend; - git_midx_writer *w = NULL; - struct git_pack_file *p; - size_t i; - int error = 0; - -#ifdef GIT_EXPERIMENTAL_SHA256 - git_midx_writer_options midx_opts = GIT_MIDX_WRITER_OPTIONS_INIT; -#endif - - GIT_ASSERT_ARG(_backend); - - backend = (struct pack_backend *)_backend; - -#ifdef GIT_EXPERIMENTAL_SHA256 - midx_opts.oid_type = backend->opts.oid_type; -#endif - - error = git_midx_writer_new(&w, backend->pack_folder -#ifdef GIT_EXPERIMENTAL_SHA256 - , &midx_opts -#endif - ); - - if (error < 0) - return error; - - git_vector_foreach(&backend->midx_packs, i, p) { - git_str idx_path = GIT_STR_INIT; - error = get_idx_path(&idx_path, backend, p); - if (error < 0) - goto cleanup; - error = git_midx_writer_add(w, git_str_cstr(&idx_path)); - git_str_dispose(&idx_path); - if (error < 0) - goto cleanup; - } - git_vector_foreach(&backend->packs, i, p) { - git_str idx_path = GIT_STR_INIT; - error = get_idx_path(&idx_path, backend, p); - if (error < 0) - goto cleanup; - error = git_midx_writer_add(w, git_str_cstr(&idx_path)); - git_str_dispose(&idx_path); - if (error < 0) - goto cleanup; - } - - /* - * Invalidate the previous midx before writing the new one. - */ - error = remove_multi_pack_index(backend); - if (error < 0) - goto cleanup; - error = git_midx_writer_commit(w); - if (error < 0) - goto cleanup; - error = refresh_multi_pack_index(backend); - -cleanup: - git_midx_writer_free(w); - return error; -} - -static void pack_backend__free(git_odb_backend *_backend) -{ - struct pack_backend *backend; - struct git_pack_file *p; - size_t i; - - if (!_backend) - return; - - backend = (struct pack_backend *)_backend; - - git_vector_foreach(&backend->midx_packs, i, p) - git_mwindow_put_pack(p); - git_vector_foreach(&backend->packs, i, p) - git_mwindow_put_pack(p); - - git_midx_free(backend->midx); - git_vector_dispose(&backend->midx_packs); - git_vector_dispose(&backend->packs); - git__free(backend->pack_folder); - git__free(backend); -} - -static int pack_backend__alloc( - struct pack_backend **out, - size_t initial_size, - const git_odb_backend_pack_options *opts) -{ - struct pack_backend *backend = git__calloc(1, sizeof(struct pack_backend)); - GIT_ERROR_CHECK_ALLOC(backend); - - if (git_vector_init(&backend->midx_packs, 0, NULL) < 0) { - git__free(backend); - return -1; - } - - if (git_vector_init(&backend->packs, initial_size, packfile_sort__cb) < 0) { - git_vector_dispose(&backend->midx_packs); - git__free(backend); - return -1; - } - - if (opts) - memcpy(&backend->opts, opts, sizeof(git_odb_backend_pack_options)); - - if (!backend->opts.oid_type) - backend->opts.oid_type = GIT_OID_DEFAULT; - - backend->parent.version = GIT_ODB_BACKEND_VERSION; - - backend->parent.read = &pack_backend__read; - backend->parent.read_prefix = &pack_backend__read_prefix; - backend->parent.read_header = &pack_backend__read_header; - backend->parent.exists = &pack_backend__exists; - backend->parent.exists_prefix = &pack_backend__exists_prefix; - backend->parent.refresh = &pack_backend__refresh; - backend->parent.foreach = &pack_backend__foreach; - backend->parent.writepack = &pack_backend__writepack; - backend->parent.writemidx = &pack_backend__writemidx; - backend->parent.freshen = &pack_backend__freshen; - backend->parent.free = &pack_backend__free; - - *out = backend; - return 0; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_odb_backend_one_pack( - git_odb_backend **backend_out, - const char *idx, - const git_odb_backend_pack_options *opts) -#else -int git_odb_backend_one_pack( - git_odb_backend **backend_out, - const char *idx) -#endif -{ - struct pack_backend *backend = NULL; - struct git_pack_file *packfile = NULL; - -#ifndef GIT_EXPERIMENTAL_SHA256 - git_odb_backend_pack_options *opts = NULL; -#endif - - git_oid_t oid_type = opts ? opts->oid_type : 0; - - if (pack_backend__alloc(&backend, 1, opts) < 0) - return -1; - - if (git_mwindow_get_pack(&packfile, idx, oid_type) < 0 || - git_vector_insert(&backend->packs, packfile) < 0) { - pack_backend__free((git_odb_backend *)backend); - return -1; - } - - *backend_out = (git_odb_backend *)backend; - return 0; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_odb_backend_pack( - git_odb_backend **backend_out, - const char *objects_dir, - const git_odb_backend_pack_options *opts) -#else -int git_odb_backend_pack( - git_odb_backend **backend_out, - const char *objects_dir) -#endif -{ - int error = 0; - struct pack_backend *backend = NULL; - git_str path = GIT_STR_INIT; - -#ifndef GIT_EXPERIMENTAL_SHA256 - git_odb_backend_pack_options *opts = NULL; -#endif - - if (pack_backend__alloc(&backend, 8, opts) < 0) - return -1; - - if (!(error = git_str_joinpath(&path, objects_dir, "pack")) && - git_fs_path_isdir(git_str_cstr(&path))) { - backend->pack_folder = git_str_detach(&path); - error = pack_backend__refresh((git_odb_backend *)backend); - } - - if (error < 0) { - pack_backend__free((git_odb_backend *)backend); - backend = NULL; - } - - *backend_out = (git_odb_backend *)backend; - - git_str_dispose(&path); - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/oid.c b/vendor/libgit2-sys/libgit2/src/libgit2/oid.c deleted file mode 100644 index 36b4ef5..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/oid.c +++ /dev/null @@ -1,534 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "oid.h" - -#include "git2/oid.h" -#include "repository.h" -#include "runtime.h" -#include -#include - -const git_oid git_oid__empty_blob_sha1 = - GIT_OID_INIT(GIT_OID_SHA1, - { 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b, - 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 }); -const git_oid git_oid__empty_tree_sha1 = - GIT_OID_INIT(GIT_OID_SHA1, - { 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, - 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }); - -static const unsigned char git_oid_zero[GIT_OID_MAX_SIZE] = {0}; - -static int oid_error_invalid(const char *msg) -{ - git_error_set(GIT_ERROR_INVALID, "unable to parse OID - %s", msg); - return -1; -} - -int git_oid__fromstrn( - git_oid *out, - const char *str, - size_t length, - git_oid_t type) -{ - size_t size, p; - int v; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(str); - - if (!(size = git_oid_size(type))) - return oid_error_invalid("unknown type"); - - if (!length) - return oid_error_invalid("too short"); - - if (length > git_oid_hexsize(type)) - return oid_error_invalid("too long"); - -#ifdef GIT_EXPERIMENTAL_SHA256 - out->type = type; -#endif - memset(out->id, 0, size); - - for (p = 0; p < length; p++) { - v = git__fromhex(str[p]); - if (v < 0) - return oid_error_invalid("contains invalid characters"); - - out->id[p / 2] |= (unsigned char)(v << (p % 2 ? 0 : 4)); - } - - return 0; -} - -int git_oid__fromstrp(git_oid *out, const char *str, git_oid_t type) -{ - return git_oid__fromstrn(out, str, strlen(str), type); -} - -int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type) -{ - return git_oid__fromstrn(out, str, git_oid_hexsize(type), type); -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_oid_fromstrn( - git_oid *out, - const char *str, - size_t length, - git_oid_t type) -{ - return git_oid__fromstrn(out, str, length, type); -} - -int git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type) -{ - return git_oid_fromstrn(out, str, strlen(str), type); -} - -int git_oid_fromstr(git_oid *out, const char *str, git_oid_t type) -{ - return git_oid_fromstrn(out, str, git_oid_hexsize(type), type); -} -#else -int git_oid_fromstrn( - git_oid *out, - const char *str, - size_t length) -{ - return git_oid__fromstrn(out, str, length, GIT_OID_SHA1); -} - -int git_oid_fromstrp(git_oid *out, const char *str) -{ - return git_oid__fromstrn(out, str, strlen(str), GIT_OID_SHA1); -} - -int git_oid_fromstr(git_oid *out, const char *str) -{ - return git_oid__fromstrn(out, str, GIT_OID_SHA1_HEXSIZE, GIT_OID_SHA1); -} -#endif - -int git_oid_nfmt(char *str, size_t n, const git_oid *oid) -{ - size_t hex_size; - - if (!oid) { - memset(str, 0, n); - return 0; - } - - if (!(hex_size = git_oid_hexsize(git_oid_type(oid)))) - return oid_error_invalid("unknown type"); - - if (n > hex_size) { - memset(&str[hex_size], 0, n - hex_size); - n = hex_size; - } - - git_oid_fmt_substr(str, oid, 0, n); - return 0; -} - -int git_oid_fmt(char *str, const git_oid *oid) -{ - return git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)), oid); -} - -int git_oid_pathfmt(char *str, const git_oid *oid) -{ - size_t hex_size; - - if (!(hex_size = git_oid_hexsize(git_oid_type(oid)))) - return oid_error_invalid("unknown type"); - - git_oid_fmt_substr(str, oid, 0, 2); - str[2] = '/'; - git_oid_fmt_substr(&str[3], oid, 2, (hex_size - 2)); - return 0; -} - -static git_tlsdata_key thread_str_key; - -static void GIT_SYSTEM_CALL thread_str_free(void *s) -{ - char *str = (char *)s; - git__free(str); -} - -static void thread_str_global_shutdown(void) -{ - char *str = git_tlsdata_get(thread_str_key); - git_tlsdata_set(thread_str_key, NULL); - - git__free(str); - git_tlsdata_dispose(thread_str_key); -} - -int git_oid_global_init(void) -{ - if (git_tlsdata_init(&thread_str_key, thread_str_free) != 0) - return -1; - - return git_runtime_shutdown_register(thread_str_global_shutdown); -} - -char *git_oid_tostr_s(const git_oid *oid) -{ - char *str; - - if ((str = git_tlsdata_get(thread_str_key)) == NULL) { - if ((str = git__malloc(GIT_OID_MAX_HEXSIZE + 1)) == NULL) - return NULL; - - git_tlsdata_set(thread_str_key, str); - } - - git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)) + 1, oid); - return str; -} - -char *git_oid_allocfmt(const git_oid *oid) -{ - size_t hex_size = git_oid_hexsize(git_oid_type(oid)); - char *str = git__malloc(hex_size + 1); - - if (!hex_size || !str) - return NULL; - - if (git_oid_nfmt(str, hex_size + 1, oid) < 0) { - git__free(str); - return NULL; - } - - return str; -} - -char *git_oid_tostr(char *out, size_t n, const git_oid *oid) -{ - size_t hex_size; - - if (!out || n == 0) - return ""; - - hex_size = oid ? git_oid_hexsize(git_oid_type(oid)) : 0; - - if (n > hex_size + 1) - n = hex_size + 1; - - git_oid_nfmt(out, n - 1, oid); /* allow room for terminating NUL */ - out[n - 1] = '\0'; - - return out; -} - -int git_oid__fromraw(git_oid *out, const unsigned char *raw, git_oid_t type) -{ - size_t size; - - if (!(size = git_oid_size(type))) - return oid_error_invalid("unknown type"); - -#ifdef GIT_EXPERIMENTAL_SHA256 - out->type = type; -#endif - memcpy(out->id, raw, size); - return 0; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type) -{ - return git_oid__fromraw(out, raw, type); -} -#else -int git_oid_fromraw(git_oid *out, const unsigned char *raw) -{ - return git_oid__fromraw(out, raw, GIT_OID_SHA1); -} -#endif - -int git_oid_cpy(git_oid *out, const git_oid *src) -{ - size_t size; - - if (!(size = git_oid_size(git_oid_type(src)))) - return oid_error_invalid("unknown type"); - -#ifdef GIT_EXPERIMENTAL_SHA256 - out->type = src->type; -#endif - - return git_oid_raw_cpy(out->id, src->id, size); -} - -int git_oid_cmp(const git_oid *a, const git_oid *b) -{ - return git_oid__cmp(a, b); -} - -int git_oid_equal(const git_oid *a, const git_oid *b) -{ - return (git_oid__cmp(a, b) == 0); -} - -int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len) -{ -#ifdef GIT_EXPERIMENTAL_SHA256 - if (oid_a->type != oid_b->type) - return oid_a->type - oid_b->type; -#endif - - return git_oid_raw_ncmp(oid_a->id, oid_b->id, len); -} - -int git_oid_strcmp(const git_oid *oid_a, const char *str) -{ - const unsigned char *a; - unsigned char strval; - long size = (long)git_oid_size(git_oid_type(oid_a)); - int hexval; - - for (a = oid_a->id; *str && (a - oid_a->id) < size; ++a) { - if ((hexval = git__fromhex(*str++)) < 0) - return -1; - strval = (unsigned char)(hexval << 4); - if (*str) { - if ((hexval = git__fromhex(*str++)) < 0) - return -1; - strval |= hexval; - } - if (*a != strval) - return (*a - strval); - } - - return 0; -} - -int git_oid_streq(const git_oid *oid_a, const char *str) -{ - return git_oid_strcmp(oid_a, str) == 0 ? 0 : -1; -} - -int git_oid_is_zero(const git_oid *oid_a) -{ - const unsigned char *a = oid_a->id; - size_t size = git_oid_size(git_oid_type(oid_a)); - -#ifdef GIT_EXPERIMENTAL_SHA256 - if (!oid_a->type) - return 1; - else if (!size) - return 0; -#endif - - return git_oid_raw_cmp(a, git_oid_zero, size) == 0 ? 1 : 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_oid_iszero(const git_oid *oid_a) -{ - return git_oid_is_zero(oid_a); -} -#endif - -typedef short node_index; - -typedef union { - const char *tail; - node_index children[16]; -} trie_node; - -struct git_oid_shorten { - trie_node *nodes; - size_t node_count, size; - int min_length, full; -}; - -static int resize_trie(git_oid_shorten *self, size_t new_size) -{ - self->nodes = git__reallocarray(self->nodes, new_size, sizeof(trie_node)); - GIT_ERROR_CHECK_ALLOC(self->nodes); - - if (new_size > self->size) { - memset(&self->nodes[self->size], 0x0, (new_size - self->size) * sizeof(trie_node)); - } - - self->size = new_size; - return 0; -} - -static trie_node *push_leaf(git_oid_shorten *os, node_index idx, int push_at, const char *oid) -{ - trie_node *node, *leaf; - node_index idx_leaf; - - if (os->node_count >= os->size) { - if (resize_trie(os, os->size * 2) < 0) - return NULL; - } - - idx_leaf = (node_index)os->node_count++; - - if (os->node_count == SHRT_MAX) { - os->full = 1; - return NULL; - } - - node = &os->nodes[idx]; - node->children[push_at] = -idx_leaf; - - leaf = &os->nodes[idx_leaf]; - leaf->tail = oid; - - return node; -} - -git_oid_shorten *git_oid_shorten_new(size_t min_length) -{ - git_oid_shorten *os; - - GIT_ASSERT_ARG_WITH_RETVAL((size_t)((int)min_length) == min_length, NULL); - - os = git__calloc(1, sizeof(git_oid_shorten)); - if (os == NULL) - return NULL; - - if (resize_trie(os, 16) < 0) { - git__free(os); - return NULL; - } - - os->node_count = 1; - os->min_length = (int)min_length; - - return os; -} - -void git_oid_shorten_free(git_oid_shorten *os) -{ - if (os == NULL) - return; - - git__free(os->nodes); - git__free(os); -} - - -/* - * What wizardry is this? - * - * This is just a memory-optimized trie: basically a very fancy - * 16-ary tree, which is used to store the prefixes of the OID - * strings. - * - * Read more: http://en.wikipedia.org/wiki/Trie - * - * Magic that happens in this method: - * - * - Each node in the trie is an union, so it can work both as - * a normal node, or as a leaf. - * - * - Each normal node points to 16 children (one for each possible - * character in the oid). This is *not* stored in an array of - * pointers, because in a 64-bit arch this would be sucking - * 16*sizeof(void*) = 128 bytes of memory per node, which is - * insane. What we do is store Node Indexes, and use these indexes - * to look up each node in the om->index array. These indexes are - * signed shorts, so this limits the amount of unique OIDs that - * fit in the structure to about 20000 (assuming a more or less uniform - * distribution). - * - * - All the nodes in om->index array are stored contiguously in - * memory, and each of them is 32 bytes, so we fit 2x nodes per - * cache line. Convenient for speed. - * - * - To differentiate the leafs from the normal nodes, we store all - * the indexes towards a leaf as a negative index (indexes to normal - * nodes are positives). When we find that one of the children for - * a node has a negative value, that means it's going to be a leaf. - * This reduces the amount of indexes we have by two, but also reduces - * the size of each node by 1-4 bytes (the amount we would need to - * add a `is_leaf` field): this is good because it allows the nodes - * to fit cleanly in cache lines. - * - * - Once we reach an empty children, instead of continuing to insert - * new nodes for each remaining character of the OID, we store a pointer - * to the tail in the leaf; if the leaf is reached again, we turn it - * into a normal node and use the tail to create a new leaf. - * - * This is a pretty good balance between performance and memory usage. - */ -int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) -{ - int i; - bool is_leaf; - node_index idx; - - if (os->full) { - git_error_set(GIT_ERROR_INVALID, "unable to shorten OID - OID set full"); - return -1; - } - - if (text_oid == NULL) - return os->min_length; - - idx = 0; - is_leaf = false; - - for (i = 0; i < GIT_OID_SHA1_HEXSIZE; ++i) { - int c = git__fromhex(text_oid[i]); - trie_node *node; - - if (c == -1) { - git_error_set(GIT_ERROR_INVALID, "unable to shorten OID - invalid hex value"); - return -1; - } - - node = &os->nodes[idx]; - - if (is_leaf) { - const char *tail; - - tail = node->tail; - node->tail = NULL; - - node = push_leaf(os, idx, git__fromhex(tail[0]), &tail[1]); - if (node == NULL) { - if (os->full) - git_error_set(GIT_ERROR_INVALID, "unable to shorten OID - OID set full"); - return -1; - } - } - - if (node->children[c] == 0) { - if (push_leaf(os, idx, c, &text_oid[i + 1]) == NULL) { - if (os->full) - git_error_set(GIT_ERROR_INVALID, "unable to shorten OID - OID set full"); - return -1; - } - break; - } - - idx = node->children[c]; - is_leaf = false; - - if (idx < 0) { - node->children[c] = idx = -idx; - is_leaf = true; - } - } - - if (++i > os->min_length) - os->min_length = i; - - return os->min_length; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/oid.h b/vendor/libgit2-sys/libgit2/src/libgit2/oid.h deleted file mode 100644 index 9415915..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/oid.h +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_oid_h__ -#define INCLUDE_oid_h__ - -#include "common.h" - -#include "git2/experimental.h" -#include "git2/oid.h" -#include "hash.h" - -#ifdef GIT_EXPERIMENTAL_SHA256 -# define GIT_OID_NONE { 0, { 0 } } -# define GIT_OID_INIT(type, ...) { type, __VA_ARGS__ } -#else -# define GIT_OID_NONE { { 0 } } -# define GIT_OID_INIT(type, ...) { __VA_ARGS__ } -#endif - -extern const git_oid git_oid__empty_blob_sha1; -extern const git_oid git_oid__empty_tree_sha1; - -GIT_INLINE(git_oid_t) git_oid_type(const git_oid *oid) -{ -#ifdef GIT_EXPERIMENTAL_SHA256 - return oid->type; -#else - GIT_UNUSED(oid); - return GIT_OID_SHA1; -#endif -} - -GIT_INLINE(size_t) git_oid_size(git_oid_t type) -{ - switch (type) { - case GIT_OID_SHA1: - return GIT_OID_SHA1_SIZE; - -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - return GIT_OID_SHA256_SIZE; -#endif - - } - - return 0; -} - -GIT_INLINE(size_t) git_oid_hexsize(git_oid_t type) -{ - switch (type) { - case GIT_OID_SHA1: - return GIT_OID_SHA1_HEXSIZE; - -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - return GIT_OID_SHA256_HEXSIZE; -#endif - - } - - return 0; -} - -GIT_INLINE(bool) git_oid_type_is_valid(git_oid_t type) -{ - return (type == GIT_OID_SHA1 -#ifdef GIT_EXPERIMENTAL_SHA256 - || type == GIT_OID_SHA256 -#endif - ); -} - -GIT_INLINE(const char *) git_oid_type_name(git_oid_t type) -{ - switch (type) { - case GIT_OID_SHA1: - return "sha1"; - -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - return "sha256"; -#endif - } - - return "unknown"; -} - -GIT_INLINE(git_oid_t) git_oid_type_fromstr(const char *name) -{ - if (strcmp(name, "sha1") == 0) - return GIT_OID_SHA1; - -#ifdef GIT_EXPERIMENTAL_SHA256 - if (strcmp(name, "sha256") == 0) - return GIT_OID_SHA256; -#endif - - return 0; -} - -GIT_INLINE(git_oid_t) git_oid_type_fromstrn(const char *name, size_t len) -{ - if (len == CONST_STRLEN("sha1") && strncmp(name, "sha1", len) == 0) - return GIT_OID_SHA1; - -#ifdef GIT_EXPERIMENTAL_SHA256 - if (len == CONST_STRLEN("sha256") && strncmp(name, "sha256", len) == 0) - return GIT_OID_SHA256; -#endif - - return 0; -} - -GIT_INLINE(git_hash_algorithm_t) git_oid_algorithm(git_oid_t type) -{ - switch (type) { - case GIT_OID_SHA1: - return GIT_HASH_ALGORITHM_SHA1; - -#ifdef GIT_EXPERIMENTAL_SHA256 - case GIT_OID_SHA256: - return GIT_HASH_ALGORITHM_SHA256; -#endif - - } - - return 0; -} - -/** - * Format a git_oid into a newly allocated c-string. - * - * The c-string is owned by the caller and needs to be manually freed. - * - * @param id the oid structure to format - * @return the c-string; NULL if memory is exhausted. Caller must - * deallocate the string with git__free(). - */ -char *git_oid_allocfmt(const git_oid *id); - -/** - * Format the requested nibbles of an object id. - * - * @param str the string to write into - * @param oid the oid structure to format - * @param start the starting number of nibbles - * @param count the number of nibbles to format - */ -GIT_INLINE(void) git_oid_fmt_substr( - char *str, - const git_oid *oid, - size_t start, - size_t count) -{ - static char hex[] = "0123456789abcdef"; - size_t i, end = start + count, min = start / 2, max = end / 2; - - if (start & 1) - *str++ = hex[oid->id[min++] & 0x0f]; - - for (i = min; i < max; i++) { - *str++ = hex[oid->id[i] >> 4]; - *str++ = hex[oid->id[i] & 0x0f]; - } - - if (end & 1) - *str++ = hex[oid->id[i] >> 4]; -} - -GIT_INLINE(int) git_oid_raw_ncmp( - const unsigned char *sha1, - const unsigned char *sha2, - size_t len) -{ - if (len > GIT_OID_MAX_HEXSIZE) - len = GIT_OID_MAX_HEXSIZE; - - while (len > 1) { - if (*sha1 != *sha2) - return 1; - sha1++; - sha2++; - len -= 2; - }; - - if (len) - if ((*sha1 ^ *sha2) & 0xf0) - return 1; - - return 0; -} - -GIT_INLINE(int) git_oid_raw_cmp( - const unsigned char *sha1, - const unsigned char *sha2, - size_t size) -{ - return memcmp(sha1, sha2, size); -} - -GIT_INLINE(int) git_oid_raw_cpy( - unsigned char *dst, - const unsigned char *src, - size_t size) -{ - memcpy(dst, src, size); - return 0; -} - -/* - * Compare two oid structures. - * - * @param a first oid structure. - * @param b second oid structure. - * @return <0, 0, >0 if a < b, a == b, a > b. - */ -GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b) -{ -#ifdef GIT_EXPERIMENTAL_SHA256 - if (a->type != b->type) - return a->type - b->type; - - return git_oid_raw_cmp(a->id, b->id, git_oid_size(a->type)); -#else - return git_oid_raw_cmp(a->id, b->id, git_oid_size(GIT_OID_SHA1)); -#endif -} - -GIT_INLINE(void) git_oid__cpy_prefix( - git_oid *out, const git_oid *id, size_t len) -{ -#ifdef GIT_EXPERIMENTAL_SHA256 - out->type = id->type; -#endif - - memcpy(&out->id, id->id, (len + 1) / 2); - - if (len & 1) - out->id[len / 2] &= 0xF0; -} - -GIT_INLINE(bool) git_oid__is_hexstr(const char *str, git_oid_t type) -{ - size_t i; - - for (i = 0; str[i] != '\0'; i++) { - if (git__fromhex(str[i]) < 0) - return false; - } - - return (i == git_oid_hexsize(type)); -} - -GIT_INLINE(void) git_oid_clear(git_oid *out, git_oid_t type) -{ - memset(out->id, 0, git_oid_size(type)); - -#ifdef GIT_EXPERIMENTAL_SHA256 - out->type = type; -#endif -} - -/* SHA256 support */ - -int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type); - -int git_oid__fromstrp(git_oid *out, const char *str, git_oid_t type); - -int git_oid__fromstrn( - git_oid *out, - const char *str, - size_t length, - git_oid_t type); - -int git_oid__fromraw(git_oid *out, const unsigned char *raw, git_oid_t type); - -int git_oid_global_init(void); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/oidarray.c b/vendor/libgit2-sys/libgit2/src/libgit2/oidarray.c deleted file mode 100644 index 37f6775..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/oidarray.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "oidarray.h" - -#include "git2/oidarray.h" -#include "array.h" - -void git_oidarray_dispose(git_oidarray *arr) -{ - git__free(arr->ids); -} - -void git_oidarray__from_array(git_oidarray *out, const git_array_oid_t *array) -{ - out->count = array->size; - out->ids = array->ptr; -} - -void git_oidarray__to_array(git_array_oid_t *out, const git_oidarray *array) -{ - out->ptr = array->ids; - out->size = array->count; - out->asize = array->count; -} - -void git_oidarray__reverse(git_oidarray *arr) -{ - size_t i; - git_oid tmp; - - for (i = 0; i < arr->count / 2; i++) { - git_oid_cpy(&tmp, &arr->ids[i]); - git_oid_cpy(&arr->ids[i], &arr->ids[(arr->count-1)-i]); - git_oid_cpy(&arr->ids[(arr->count-1)-i], &tmp); - } -} - -int git_oidarray__add(git_array_oid_t *arr, git_oid *id) -{ - git_oid *add, *iter; - size_t i; - - git_array_foreach(*arr, i, iter) { - if (git_oid_cmp(iter, id) == 0) - return 0; - } - - if ((add = git_array_alloc(*arr)) == NULL) - return -1; - - git_oid_cpy(add, id); - return 0; -} - -bool git_oidarray__remove(git_array_oid_t *arr, git_oid *id) -{ - bool found = false; - size_t remain, i; - git_oid *iter; - - git_array_foreach(*arr, i, iter) { - if (git_oid_cmp(iter, id) == 0) { - arr->size--; - remain = arr->size - i; - - if (remain > 0) - memmove(&arr->ptr[i], &arr->ptr[i+1], remain * sizeof(git_oid)); - - found = true; - break; - } - } - - return found; -} - -#ifndef GIT_DEPRECATE_HARD - -void git_oidarray_free(git_oidarray *arr) -{ - git_oidarray_dispose(arr); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/oidarray.h b/vendor/libgit2-sys/libgit2/src/libgit2/oidarray.h deleted file mode 100644 index 8f1543a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/oidarray.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_oidarray_h__ -#define INCLUDE_oidarray_h__ - -#include "common.h" - -#include "git2/oidarray.h" -#include "array.h" - -typedef git_array_t(git_oid) git_array_oid_t; - -extern void git_oidarray__reverse(git_oidarray *arr); -extern void git_oidarray__from_array(git_oidarray *out, const git_array_oid_t *array); -extern void git_oidarray__to_array(git_array_oid_t *out, const git_oidarray *array); - -int git_oidarray__add(git_array_oid_t *arr, git_oid *id); -bool git_oidarray__remove(git_array_oid_t *arr, git_oid *id); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/pack-objects.c b/vendor/libgit2-sys/libgit2/src/libgit2/pack-objects.c deleted file mode 100644 index 489af13..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/pack-objects.c +++ /dev/null @@ -1,1864 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "pack-objects.h" - -#include "buf.h" -#include "zstream.h" -#include "delta.h" -#include "iterator.h" -#include "pack.h" -#include "thread.h" -#include "tree.h" -#include "util.h" -#include "revwalk.h" -#include "commit_list.h" - -#include "git2/pack.h" -#include "git2/commit.h" -#include "git2/tag.h" -#include "git2/indexer.h" -#include "git2/config.h" - -struct unpacked { - git_pobject *object; - void *data; - struct git_delta_index *index; - size_t depth; -}; - -struct tree_walk_context { - git_packbuilder *pb; - git_str buf; -}; - -struct pack_write_context { - git_indexer *indexer; - git_indexer_progress *stats; -}; - -struct walk_object { - git_oid id; - unsigned int uninteresting:1, - seen:1; -}; - -#ifdef GIT_THREADS -# define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) git_mutex_##op(&(pb)->mtx) -#else -# define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) git__noop() -#endif - -#define git_packbuilder__cache_lock(pb) GIT_PACKBUILDER__MUTEX_OP(pb, cache_mutex, lock) -#define git_packbuilder__cache_unlock(pb) GIT_PACKBUILDER__MUTEX_OP(pb, cache_mutex, unlock) -#define git_packbuilder__progress_lock(pb) GIT_PACKBUILDER__MUTEX_OP(pb, progress_mutex, lock) -#define git_packbuilder__progress_unlock(pb) GIT_PACKBUILDER__MUTEX_OP(pb, progress_mutex, unlock) - -/* The minimal interval between progress updates (in seconds). */ -#define MIN_PROGRESS_UPDATE_INTERVAL 0.5 - -/* Size of the buffer to feed to zlib */ -#define COMPRESS_BUFLEN (1024 * 1024) - -GIT_HASHMAP_OID_FUNCTIONS(git_packbuilder_pobjectmap, GIT_HASHMAP_INLINE, git_pobject *); -GIT_HASHMAP_OID_FUNCTIONS(git_packbuilder_walk_objectmap, GIT_HASHMAP_INLINE, struct walk_object *); - -static unsigned name_hash(const char *name) -{ - unsigned c, hash = 0; - - if (!name) - return 0; - - /* - * This effectively just creates a sortable number from the - * last sixteen non-whitespace characters. Last characters - * count "most", so things that end in ".c" sort together. - */ - while ((c = *name++) != 0) { - if (git__isspace(c)) - continue; - hash = (hash >> 2) + (c << 24); - } - return hash; -} - -static int packbuilder_config(git_packbuilder *pb) -{ - git_config *config; - int ret = 0; - int64_t val; - - if ((ret = git_repository_config_snapshot(&config, pb->repo)) < 0) - return ret; - -#define config_get(KEY,DST,DFLT) do { \ - ret = git_config_get_int64(&val, config, KEY); \ - if (!ret) { \ - if (!git__is_sizet(val)) { \ - git_error_set(GIT_ERROR_CONFIG, \ - "configuration value '%s' is too large", KEY); \ - ret = -1; \ - goto out; \ - } \ - (DST) = (size_t)val; \ - } else if (ret == GIT_ENOTFOUND) { \ - (DST) = (DFLT); \ - ret = 0; \ - } else if (ret < 0) goto out; } while (0) - - config_get("pack.deltaCacheSize", pb->max_delta_cache_size, - GIT_PACK_DELTA_CACHE_SIZE); - config_get("pack.deltaCacheLimit", pb->cache_max_small_delta_size, - GIT_PACK_DELTA_CACHE_LIMIT); - config_get("pack.deltaCacheSize", pb->big_file_threshold, - GIT_PACK_BIG_FILE_THRESHOLD); - config_get("pack.windowMemory", pb->window_memory_limit, 0); - -#undef config_get - -out: - git_config_free(config); - - return ret; -} - -int git_packbuilder_new(git_packbuilder **out, git_repository *repo) -{ - git_hash_algorithm_t hash_algorithm; - git_packbuilder *pb; - - *out = NULL; - - pb = git__calloc(1, sizeof(*pb)); - GIT_ERROR_CHECK_ALLOC(pb); - - pb->oid_type = repo->oid_type; - - hash_algorithm = git_oid_algorithm(pb->oid_type); - GIT_ASSERT(hash_algorithm); - - if (git_pool_init(&pb->object_pool, sizeof(struct walk_object)) < 0) - goto on_error; - - pb->repo = repo; - pb->nr_threads = 1; /* do not spawn any thread by default */ - - if (git_hash_ctx_init(&pb->ctx, hash_algorithm) < 0 || - git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 || - git_repository_odb(&pb->odb, repo) < 0 || - packbuilder_config(pb) < 0) - goto on_error; - -#ifdef GIT_THREADS - - if (git_mutex_init(&pb->cache_mutex) || - git_mutex_init(&pb->progress_mutex) || - git_cond_init(&pb->progress_cond)) - { - git_error_set(GIT_ERROR_OS, "failed to initialize packbuilder mutex"); - goto on_error; - } - -#endif - - *out = pb; - return 0; - -on_error: - git_packbuilder_free(pb); - return -1; -} - -unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n) -{ - GIT_ASSERT_ARG(pb); - -#ifdef GIT_THREADS - pb->nr_threads = n; -#else - GIT_UNUSED(n); - GIT_ASSERT(pb->nr_threads == 1); -#endif - - return pb->nr_threads; -} - -static int rehash(git_packbuilder *pb) -{ - git_pobject *po; - size_t i; - - git_packbuilder_pobjectmap_clear(&pb->object_ix); - - for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) { - if (git_packbuilder_pobjectmap_put(&pb->object_ix, &po->id, po) < 0) - return -1; - } - - return 0; -} - -int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, - const char *name) -{ - git_pobject *po; - size_t newsize; - int ret; - - GIT_ASSERT_ARG(pb); - GIT_ASSERT_ARG(oid); - - /* If the object already exists in the hash table, then we don't - * have any work to do */ - if (git_packbuilder_pobjectmap_contains(&pb->object_ix, oid)) - return 0; - - if (pb->nr_objects >= pb->nr_alloc) { - GIT_ERROR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024); - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize / 2, 3); - - if (!git__is_uint32(newsize)) { - git_error_set(GIT_ERROR_NOMEMORY, "packfile too large to fit in memory."); - return -1; - } - - pb->nr_alloc = newsize; - - pb->object_list = git__reallocarray(pb->object_list, - pb->nr_alloc, sizeof(*po)); - GIT_ERROR_CHECK_ALLOC(pb->object_list); - - if (rehash(pb) < 0) - return -1; - } - - po = pb->object_list + pb->nr_objects; - memset(po, 0x0, sizeof(*po)); - - if ((ret = git_odb_read_header(&po->size, &po->type, pb->odb, oid)) < 0) - return ret; - - pb->nr_objects++; - git_oid_cpy(&po->id, oid); - po->hash = name_hash(name); - - if (git_packbuilder_pobjectmap_put(&pb->object_ix, &po->id, po) < 0) { - git_error_set_oom(); - return -1; - } - - pb->done = false; - - if (pb->progress_cb) { - uint64_t current_time = git_time_monotonic(); - uint64_t elapsed = current_time - pb->last_progress_report_time; - - if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) { - pb->last_progress_report_time = current_time; - - ret = pb->progress_cb( - GIT_PACKBUILDER_ADDING_OBJECTS, - pb->nr_objects, 0, pb->progress_cb_payload); - - if (ret) - return git_error_set_after_callback(ret); - } - } - - return 0; -} - -static int get_delta(void **out, git_odb *odb, git_pobject *po) -{ - git_odb_object *src = NULL, *trg = NULL; - size_t delta_size; - void *delta_buf; - int error; - - *out = NULL; - - if (git_odb_read(&src, odb, &po->delta->id) < 0 || - git_odb_read(&trg, odb, &po->id) < 0) - goto on_error; - - error = git_delta(&delta_buf, &delta_size, - git_odb_object_data(src), git_odb_object_size(src), - git_odb_object_data(trg), git_odb_object_size(trg), - 0); - - if (error < 0 && error != GIT_EBUFS) - goto on_error; - - if (error == GIT_EBUFS || delta_size != po->delta_size) { - git_error_set(GIT_ERROR_INVALID, "delta size changed"); - goto on_error; - } - - *out = delta_buf; - - git_odb_object_free(src); - git_odb_object_free(trg); - return 0; - -on_error: - git_odb_object_free(src); - git_odb_object_free(trg); - return -1; -} - -static int write_object( - git_packbuilder *pb, - git_pobject *po, - int (*write_cb)(void *buf, size_t size, void *cb_data), - void *cb_data) -{ - git_odb_object *obj = NULL; - git_object_t type; - unsigned char hdr[10], *zbuf = NULL; - void *data = NULL; - size_t hdr_len, zbuf_len = COMPRESS_BUFLEN, data_len, oid_size; - int error; - - oid_size = git_oid_size(pb->oid_type); - - /* - * If we have a delta base, let's use the delta to save space. - * Otherwise load the whole object. 'data' ends up pointing to - * whatever data we want to put into the packfile. - */ - if (po->delta) { - if (po->delta_data) - data = po->delta_data; - else if ((error = get_delta(&data, pb->odb, po)) < 0) - goto done; - - data_len = po->delta_size; - type = GIT_OBJECT_REF_DELTA; - } else { - if ((error = git_odb_read(&obj, pb->odb, &po->id)) < 0) - goto done; - - data = (void *)git_odb_object_data(obj); - data_len = git_odb_object_size(obj); - type = git_odb_object_type(obj); - } - - /* Write header */ - if ((error = git_packfile__object_header(&hdr_len, hdr, data_len, type)) < 0 || - (error = write_cb(hdr, hdr_len, cb_data)) < 0 || - (error = git_hash_update(&pb->ctx, hdr, hdr_len)) < 0) - goto done; - - if (type == GIT_OBJECT_REF_DELTA) { - if ((error = write_cb(po->delta->id.id, oid_size, cb_data)) < 0 || - (error = git_hash_update(&pb->ctx, po->delta->id.id, oid_size)) < 0) - goto done; - } - - /* Write data */ - if (po->z_delta_size) { - data_len = po->z_delta_size; - - if ((error = write_cb(data, data_len, cb_data)) < 0 || - (error = git_hash_update(&pb->ctx, data, data_len)) < 0) - goto done; - } else { - zbuf = git__malloc(zbuf_len); - GIT_ERROR_CHECK_ALLOC(zbuf); - - git_zstream_reset(&pb->zstream); - - if ((error = git_zstream_set_input(&pb->zstream, data, data_len)) < 0) - goto done; - - while (!git_zstream_done(&pb->zstream)) { - if ((error = git_zstream_get_output(zbuf, &zbuf_len, &pb->zstream)) < 0 || - (error = write_cb(zbuf, zbuf_len, cb_data)) < 0 || - (error = git_hash_update(&pb->ctx, zbuf, zbuf_len)) < 0) - goto done; - - zbuf_len = COMPRESS_BUFLEN; /* reuse buffer */ - } - } - - /* - * If po->delta is true, data is a delta and it is our - * responsibility to free it (otherwise it's a git_object's - * data). We set po->delta_data to NULL in case we got the - * data from there instead of get_delta(). If we didn't, - * there's no harm. - */ - if (po->delta) { - git__free(data); - po->delta_data = NULL; - } - - pb->nr_written++; - -done: - git__free(zbuf); - git_odb_object_free(obj); - return error; -} - -enum write_one_status { - WRITE_ONE_SKIP = -1, /* already written */ - WRITE_ONE_BREAK = 0, /* writing this will bust the limit; not written */ - WRITE_ONE_WRITTEN = 1, /* normal */ - WRITE_ONE_RECURSIVE = 2 /* already scheduled to be written */ -}; - -static int write_one( - enum write_one_status *status, - git_packbuilder *pb, - git_pobject *po, - int (*write_cb)(void *buf, size_t size, void *cb_data), - void *cb_data) -{ - int error; - - if (po->recursing) { - *status = WRITE_ONE_RECURSIVE; - return 0; - } else if (po->written) { - *status = WRITE_ONE_SKIP; - return 0; - } - - if (po->delta) { - po->recursing = 1; - - if ((error = write_one(status, pb, po->delta, write_cb, cb_data)) < 0) - return error; - - /* we cannot depend on this one */ - if (*status == WRITE_ONE_RECURSIVE) - po->delta = NULL; - } - - *status = WRITE_ONE_WRITTEN; - po->written = 1; - po->recursing = 0; - - return write_object(pb, po, write_cb, cb_data); -} - -GIT_INLINE(void) add_to_write_order(git_pobject **wo, size_t *endp, - git_pobject *po) -{ - if (po->filled) - return; - wo[(*endp)++] = po; - po->filled = 1; -} - -static void add_descendants_to_write_order(git_pobject **wo, size_t *endp, - git_pobject *po) -{ - int add_to_order = 1; - while (po) { - if (add_to_order) { - git_pobject *s; - /* add this node... */ - add_to_write_order(wo, endp, po); - /* all its siblings... */ - for (s = po->delta_sibling; s; s = s->delta_sibling) { - add_to_write_order(wo, endp, s); - } - } - /* drop down a level to add left subtree nodes if possible */ - if (po->delta_child) { - add_to_order = 1; - po = po->delta_child; - } else { - add_to_order = 0; - /* our sibling might have some children, it is next */ - if (po->delta_sibling) { - po = po->delta_sibling; - continue; - } - /* go back to our parent node */ - po = po->delta; - while (po && !po->delta_sibling) { - /* we're on the right side of a subtree, keep - * going up until we can go right again */ - po = po->delta; - } - if (!po) { - /* done- we hit our original root node */ - return; - } - /* pass it off to sibling at this level */ - po = po->delta_sibling; - } - }; -} - -static void add_family_to_write_order(git_pobject **wo, size_t *endp, - git_pobject *po) -{ - git_pobject *root; - - for (root = po; root->delta; root = root->delta) - ; /* nothing */ - add_descendants_to_write_order(wo, endp, root); -} - -static int cb_tag_foreach(const char *name, git_oid *oid, void *data) -{ - git_packbuilder *pb = data; - git_pobject *po; - - GIT_UNUSED(name); - - if (git_packbuilder_pobjectmap_get(&po, &pb->object_ix, oid) != 0) - return 0; - - po->tagged = 1; - - /* TODO: peel objects */ - - return 0; -} - -static int compute_write_order(git_pobject ***out, git_packbuilder *pb) -{ - size_t i, wo_end, last_untagged; - git_pobject **wo; - - *out = NULL; - - if (!pb->nr_objects) - return 0; - - if ((wo = git__mallocarray(pb->nr_objects, sizeof(*wo))) == NULL) - return -1; - - for (i = 0; i < pb->nr_objects; i++) { - git_pobject *po = pb->object_list + i; - po->tagged = 0; - po->filled = 0; - po->delta_child = NULL; - po->delta_sibling = NULL; - } - - /* - * Fully connect delta_child/delta_sibling network. - * Make sure delta_sibling is sorted in the original - * recency order. - */ - for (i = pb->nr_objects; i > 0;) { - git_pobject *po = &pb->object_list[--i]; - if (!po->delta) - continue; - /* Mark me as the first child */ - po->delta_sibling = po->delta->delta_child; - po->delta->delta_child = po; - } - - /* - * Mark objects that are at the tip of tags. - */ - if (git_tag_foreach(pb->repo, &cb_tag_foreach, pb) < 0) { - git__free(wo); - return -1; - } - - /* - * Give the objects in the original recency order until - * we see a tagged tip. - */ - for (i = wo_end = 0; i < pb->nr_objects; i++) { - git_pobject *po = pb->object_list + i; - if (po->tagged) - break; - add_to_write_order(wo, &wo_end, po); - } - last_untagged = i; - - /* - * Then fill all the tagged tips. - */ - for (; i < pb->nr_objects; i++) { - git_pobject *po = pb->object_list + i; - if (po->tagged) - add_to_write_order(wo, &wo_end, po); - } - - /* - * And then all remaining commits and tags. - */ - for (i = last_untagged; i < pb->nr_objects; i++) { - git_pobject *po = pb->object_list + i; - if (po->type != GIT_OBJECT_COMMIT && - po->type != GIT_OBJECT_TAG) - continue; - add_to_write_order(wo, &wo_end, po); - } - - /* - * And then all the trees. - */ - for (i = last_untagged; i < pb->nr_objects; i++) { - git_pobject *po = pb->object_list + i; - if (po->type != GIT_OBJECT_TREE) - continue; - add_to_write_order(wo, &wo_end, po); - } - - /* - * Finally all the rest in really tight order - */ - for (i = last_untagged; i < pb->nr_objects; i++) { - git_pobject *po = pb->object_list + i; - if (!po->filled) - add_family_to_write_order(wo, &wo_end, po); - } - - if (wo_end != pb->nr_objects) { - git__free(wo); - git_error_set(GIT_ERROR_INVALID, "invalid write order"); - return -1; - } - - *out = wo; - return 0; -} - -static int write_pack(git_packbuilder *pb, - int (*write_cb)(void *buf, size_t size, void *cb_data), - void *cb_data) -{ - git_pobject **write_order; - git_pobject *po; - enum write_one_status status; - struct git_pack_header ph; - git_oid entry_oid; - size_t i = 0; - int error; - - if ((error = compute_write_order(&write_order, pb)) < 0) - return error; - - if (!git__is_uint32(pb->nr_objects)) { - git_error_set(GIT_ERROR_INVALID, "too many objects"); - error = -1; - goto done; - } - - /* Write pack header */ - ph.hdr_signature = htonl(PACK_SIGNATURE); - ph.hdr_version = htonl(PACK_VERSION); - ph.hdr_entries = htonl(pb->nr_objects); - - if ((error = write_cb(&ph, sizeof(ph), cb_data)) < 0 || - (error = git_hash_update(&pb->ctx, &ph, sizeof(ph))) < 0) - goto done; - - pb->nr_remaining = pb->nr_objects; - do { - pb->nr_written = 0; - for ( ; i < pb->nr_objects; ++i) { - po = write_order[i]; - - if ((error = write_one(&status, pb, po, write_cb, cb_data)) < 0) - goto done; - } - - pb->nr_remaining -= pb->nr_written; - } while (pb->nr_remaining && i < pb->nr_objects); - - if ((error = git_hash_final(entry_oid.id, &pb->ctx)) < 0) - goto done; - - error = write_cb(entry_oid.id, git_oid_size(pb->oid_type), cb_data); - -done: - /* if callback cancelled writing, we must still free delta_data */ - for ( ; i < pb->nr_objects; ++i) { - po = write_order[i]; - if (po->delta_data) { - git__free(po->delta_data); - po->delta_data = NULL; - } - } - - git__free(write_order); - return error; -} - -static int write_pack_buf(void *buf, size_t size, void *data) -{ - git_str *b = (git_str *)data; - return git_str_put(b, buf, size); -} - -static int type_size_sort(const void *_a, const void *_b) -{ - const git_pobject *a = (git_pobject *)_a; - const git_pobject *b = (git_pobject *)_b; - - if (a->type > b->type) - return -1; - if (a->type < b->type) - return 1; - if (a->hash > b->hash) - return -1; - if (a->hash < b->hash) - return 1; - /* - * TODO - * - if (a->preferred_base > b->preferred_base) - return -1; - if (a->preferred_base < b->preferred_base) - return 1; - */ - if (a->size > b->size) - return -1; - if (a->size < b->size) - return 1; - return a < b ? -1 : (a > b); /* newest first */ -} - -static int delta_cacheable( - git_packbuilder *pb, - size_t src_size, - size_t trg_size, - size_t delta_size) -{ - size_t new_size; - - if (git__add_sizet_overflow(&new_size, pb->delta_cache_size, delta_size)) - return 0; - - if (pb->max_delta_cache_size && new_size > pb->max_delta_cache_size) - return 0; - - if (delta_size < pb->cache_max_small_delta_size) - return 1; - - /* cache delta, if objects are large enough compared to delta size */ - if ((src_size >> 20) + (trg_size >> 21) > (delta_size >> 10)) - return 1; - - return 0; -} - -static int try_delta(git_packbuilder *pb, struct unpacked *trg, - struct unpacked *src, size_t max_depth, - size_t *mem_usage, int *ret) -{ - git_pobject *trg_object = trg->object; - git_pobject *src_object = src->object; - git_odb_object *obj; - size_t trg_size, src_size, delta_size, sizediff, max_size, sz; - size_t ref_depth; - void *delta_buf; - - /* Don't bother doing diffs between different types */ - if (trg_object->type != src_object->type) { - *ret = -1; - return 0; - } - - *ret = 0; - - /* TODO: support reuse-delta */ - - /* Let's not bust the allowed depth. */ - if (src->depth >= max_depth) - return 0; - - /* Now some size filtering heuristics. */ - trg_size = trg_object->size; - if (!trg_object->delta) { - max_size = trg_size/2 - 20; - ref_depth = 1; - } else { - max_size = trg_object->delta_size; - ref_depth = trg->depth; - } - - max_size = (uint64_t)max_size * (max_depth - src->depth) / - (max_depth - ref_depth + 1); - if (max_size == 0) - return 0; - - src_size = src_object->size; - sizediff = src_size < trg_size ? trg_size - src_size : 0; - if (sizediff >= max_size) - return 0; - if (trg_size < src_size / 32) - return 0; - - /* Load data if not already done */ - if (!trg->data) { - if (git_odb_read(&obj, pb->odb, &trg_object->id) < 0) - return -1; - - sz = git_odb_object_size(obj); - trg->data = git__malloc(sz); - GIT_ERROR_CHECK_ALLOC(trg->data); - memcpy(trg->data, git_odb_object_data(obj), sz); - - git_odb_object_free(obj); - - if (sz != trg_size) { - git_error_set(GIT_ERROR_INVALID, - "inconsistent target object length"); - return -1; - } - - *mem_usage += sz; - } - if (!src->data) { - size_t obj_sz; - - if (git_odb_read(&obj, pb->odb, &src_object->id) < 0 || - !git__is_ulong(obj_sz = git_odb_object_size(obj))) - return -1; - - sz = obj_sz; - src->data = git__malloc(sz); - GIT_ERROR_CHECK_ALLOC(src->data); - memcpy(src->data, git_odb_object_data(obj), sz); - - git_odb_object_free(obj); - - if (sz != src_size) { - git_error_set(GIT_ERROR_INVALID, - "inconsistent source object length"); - return -1; - } - - *mem_usage += sz; - } - if (!src->index) { - if (git_delta_index_init(&src->index, src->data, src_size) < 0) - return 0; /* suboptimal pack - out of memory */ - - *mem_usage += git_delta_index_size(src->index); - } - - if (git_delta_create_from_index(&delta_buf, &delta_size, src->index, trg->data, trg_size, - max_size) < 0) - return 0; - - if (trg_object->delta) { - /* Prefer only shallower same-sized deltas. */ - if (delta_size == trg_object->delta_size && - src->depth + 1 >= trg->depth) { - git__free(delta_buf); - return 0; - } - } - - GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0); - - if (trg_object->delta_data) { - git__free(trg_object->delta_data); - GIT_ASSERT(pb->delta_cache_size >= trg_object->delta_size); - pb->delta_cache_size -= trg_object->delta_size; - trg_object->delta_data = NULL; - } - if (delta_cacheable(pb, src_size, trg_size, delta_size)) { - bool overflow = git__add_sizet_overflow( - &pb->delta_cache_size, pb->delta_cache_size, delta_size); - - GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0); - - if (overflow) { - git__free(delta_buf); - return -1; - } - - trg_object->delta_data = git__realloc(delta_buf, delta_size); - GIT_ERROR_CHECK_ALLOC(trg_object->delta_data); - } else { - /* create delta when writing the pack */ - GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0); - git__free(delta_buf); - } - - trg_object->delta = src_object; - trg_object->delta_size = delta_size; - trg->depth = src->depth + 1; - - *ret = 1; - return 0; -} - -static size_t check_delta_limit(git_pobject *me, size_t n) -{ - git_pobject *child = me->delta_child; - size_t m = n; - - while (child) { - size_t c = check_delta_limit(child, n + 1); - if (m < c) - m = c; - child = child->delta_sibling; - } - return m; -} - -static size_t free_unpacked(struct unpacked *n) -{ - size_t freed_mem = 0; - - if (n->index) { - freed_mem += git_delta_index_size(n->index); - git_delta_index_free(n->index); - } - n->index = NULL; - - if (n->data) { - freed_mem += n->object->size; - git__free(n->data); - n->data = NULL; - } - n->object = NULL; - n->depth = 0; - return freed_mem; -} - -static int report_delta_progress( - git_packbuilder *pb, uint32_t count, bool force) -{ - int ret; - - if (pb->failure) - return pb->failure; - - if (pb->progress_cb) { - uint64_t current_time = git_time_monotonic(); - uint64_t elapsed = current_time - pb->last_progress_report_time; - - if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) { - pb->last_progress_report_time = current_time; - - ret = pb->progress_cb( - GIT_PACKBUILDER_DELTAFICATION, - count, pb->nr_objects, pb->progress_cb_payload); - - if (ret) { - pb->failure = ret; - return git_error_set_after_callback(ret); - } - } - } - - return 0; -} - -static int find_deltas(git_packbuilder *pb, git_pobject **list, - size_t *list_size, size_t window, size_t depth) -{ - git_pobject *po; - git_str zbuf = GIT_STR_INIT; - struct unpacked *array; - size_t idx = 0, count = 0; - size_t mem_usage = 0; - size_t i; - int error = -1; - - array = git__calloc(window, sizeof(struct unpacked)); - GIT_ERROR_CHECK_ALLOC(array); - - for (;;) { - struct unpacked *n = array + idx; - size_t max_depth, j, best_base = SIZE_MAX; - - GIT_ASSERT(git_packbuilder__progress_lock(pb) == 0); - if (!*list_size) { - GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0); - break; - } - - pb->nr_deltified += 1; - if ((error = report_delta_progress(pb, pb->nr_deltified, false)) < 0) { - GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0); - goto on_error; - } - - po = *list++; - (*list_size)--; - GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0); - - mem_usage -= free_unpacked(n); - n->object = po; - - while (pb->window_memory_limit && - mem_usage > pb->window_memory_limit && - count > 1) { - size_t tail = (idx + window - count) % window; - mem_usage -= free_unpacked(array + tail); - count--; - } - - /* - * If the current object is at pack edge, take the depth the - * objects that depend on the current object into account - * otherwise they would become too deep. - */ - max_depth = depth; - if (po->delta_child) { - size_t delta_limit = check_delta_limit(po, 0); - - if (delta_limit > max_depth) - goto next; - - max_depth -= delta_limit; - } - - j = window; - while (--j > 0) { - int ret; - size_t other_idx = idx + j; - struct unpacked *m; - - if (other_idx >= window) - other_idx -= window; - - m = array + other_idx; - if (!m->object) - break; - - if (try_delta(pb, n, m, max_depth, &mem_usage, &ret) < 0) - goto on_error; - if (ret < 0) - break; - else if (ret > 0) - best_base = other_idx; - } - - /* - * If we decided to cache the delta data, then it is best - * to compress it right away. First because we have to do - * it anyway, and doing it here while we're threaded will - * save a lot of time in the non threaded write phase, - * as well as allow for caching more deltas within - * the same cache size limit. - * ... - * But only if not writing to stdout, since in that case - * the network is most likely throttling writes anyway, - * and therefore it is best to go to the write phase ASAP - * instead, as we can afford spending more time compressing - * between writes at that moment. - */ - if (po->delta_data) { - if (git_zstream_deflatebuf(&zbuf, po->delta_data, po->delta_size) < 0) - goto on_error; - - git__free(po->delta_data); - po->delta_data = git__malloc(zbuf.size); - GIT_ERROR_CHECK_ALLOC(po->delta_data); - - memcpy(po->delta_data, zbuf.ptr, zbuf.size); - po->z_delta_size = zbuf.size; - git_str_clear(&zbuf); - - GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0); - pb->delta_cache_size -= po->delta_size; - pb->delta_cache_size += po->z_delta_size; - GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0); - } - - /* - * If we made n a delta, and if n is already at max - * depth, leaving it in the window is pointless. we - * should evict it first. - */ - if (po->delta && max_depth <= n->depth) - continue; - - /* - * Move the best delta base up in the window, after the - * currently deltified object, to keep it longer. It will - * be the first base object to be attempted next. - */ - if (po->delta) { - struct unpacked swap = array[best_base]; - size_t dist = (window + idx - best_base) % window; - size_t dst = best_base; - while (dist--) { - size_t src = (dst + 1) % window; - array[dst] = array[src]; - dst = src; - } - array[dst] = swap; - } - - next: - idx++; - if (count + 1 < window) - count++; - if (idx >= window) - idx = 0; - } - error = 0; - -on_error: - for (i = 0; i < window; ++i) { - git__free(array[i].index); - git__free(array[i].data); - } - git__free(array); - git_str_dispose(&zbuf); - - return error; -} - -#ifdef GIT_THREADS - -struct thread_params { - git_thread thread; - git_packbuilder *pb; - - git_pobject **list; - - git_cond cond; - git_mutex mutex; - - size_t list_size; - size_t remaining; - - size_t window; - size_t depth; - size_t working; - size_t data_ready; - - /* A pb->progress_cb can stop the packing process by returning an error. - When that happens, all threads observe the error and stop voluntarily. */ - bool stopped; -}; - -static void *threaded_find_deltas(void *arg) -{ - struct thread_params *me = arg; - - while (me->remaining) { - if (find_deltas(me->pb, me->list, &me->remaining, - me->window, me->depth) < 0) { - me->stopped = true; - GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_lock(me->pb) == 0, NULL); - me->working = false; - git_cond_signal(&me->pb->progress_cond); - GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_unlock(me->pb) == 0, NULL); - return NULL; - } - - GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_lock(me->pb) == 0, NULL); - me->working = 0; - git_cond_signal(&me->pb->progress_cond); - GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_unlock(me->pb) == 0, NULL); - - if (git_mutex_lock(&me->mutex)) { - git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex"); - return NULL; - } - - while (!me->data_ready) - git_cond_wait(&me->cond, &me->mutex); - - /* - * We must not set ->data_ready before we wait on the - * condition because the main thread may have set it to 1 - * before we get here. In order to be sure that new - * work is available if we see 1 in ->data_ready, it - * was initialized to 0 before this thread was spawned - * and we reset it to 0 right away. - */ - me->data_ready = 0; - git_mutex_unlock(&me->mutex); - } - /* leave ->working 1 so that this doesn't get more work assigned */ - return NULL; -} - -static int ll_find_deltas(git_packbuilder *pb, git_pobject **list, - size_t list_size, size_t window, size_t depth) -{ - struct thread_params *p; - size_t i; - int ret, active_threads = 0; - - if (!pb->nr_threads) - pb->nr_threads = git__online_cpus(); - - if (pb->nr_threads <= 1) { - return find_deltas(pb, list, &list_size, window, depth); - } - - p = git__mallocarray(pb->nr_threads, sizeof(*p)); - GIT_ERROR_CHECK_ALLOC(p); - - /* Partition the work among the threads */ - for (i = 0; i < pb->nr_threads; ++i) { - size_t sub_size = list_size / (pb->nr_threads - i); - - /* don't use too small segments or no deltas will be found */ - if (sub_size < 2*window && i+1 < pb->nr_threads) - sub_size = 0; - - p[i].pb = pb; - p[i].window = window; - p[i].depth = depth; - p[i].working = 1; - p[i].data_ready = 0; - p[i].stopped = 0; - - /* try to split chunks on "path" boundaries */ - while (sub_size && sub_size < list_size && - list[sub_size]->hash && - list[sub_size]->hash == list[sub_size-1]->hash) - sub_size++; - - p[i].list = list; - p[i].list_size = sub_size; - p[i].remaining = sub_size; - - list += sub_size; - list_size -= sub_size; - } - - /* Start work threads */ - for (i = 0; i < pb->nr_threads; ++i) { - if (!p[i].list_size) - continue; - - git_mutex_init(&p[i].mutex); - git_cond_init(&p[i].cond); - - ret = git_thread_create(&p[i].thread, - threaded_find_deltas, &p[i]); - if (ret) { - git_error_set(GIT_ERROR_THREAD, "unable to create thread"); - return -1; - } - active_threads++; - } - - /* - * Now let's wait for work completion. Each time a thread is done - * with its work, we steal half of the remaining work from the - * thread with the largest number of unprocessed objects and give - * it to that newly idle thread. This ensure good load balancing - * until the remaining object list segments are simply too short - * to be worth splitting anymore. - */ - while (active_threads) { - struct thread_params *target = NULL; - struct thread_params *victim = NULL; - size_t sub_size = 0; - - /* Start by locating a thread that has transitioned its - * 'working' flag from 1 -> 0. This indicates that it is - * ready to receive more work using our work-stealing - * algorithm. */ - GIT_ASSERT(git_packbuilder__progress_lock(pb) == 0); - for (;;) { - for (i = 0; !target && i < pb->nr_threads; i++) - if (!p[i].working) - target = &p[i]; - if (target) - break; - git_cond_wait(&pb->progress_cond, &pb->progress_mutex); - } - - /* At this point we hold the progress lock and have located - * a thread to receive more work. We still need to locate a - * thread from which to steal work (the victim). */ - for (i = 0; i < pb->nr_threads; i++) - if (p[i].remaining > 2*window && - (!victim || victim->remaining < p[i].remaining)) - victim = &p[i]; - - if (victim && !target->stopped) { - sub_size = victim->remaining / 2; - list = victim->list + victim->list_size - sub_size; - while (sub_size && list[0]->hash && - list[0]->hash == list[-1]->hash) { - list++; - sub_size--; - } - if (!sub_size) { - /* - * It is possible for some "paths" to have - * so many objects that no hash boundary - * might be found. Let's just steal the - * exact half in that case. - */ - sub_size = victim->remaining / 2; - list -= sub_size; - } - target->list = list; - victim->list_size -= sub_size; - victim->remaining -= sub_size; - } - target->list_size = sub_size; - target->remaining = sub_size; - target->working = 1; /* even when target->stopped, so that we don't process this thread again */ - GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0); - - if (git_mutex_lock(&target->mutex)) { - git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex"); - git__free(p); - return -1; - } - - target->data_ready = 1; - git_cond_signal(&target->cond); - git_mutex_unlock(&target->mutex); - - if (target->stopped || !sub_size) { - git_thread_join(&target->thread, NULL); - git_cond_free(&target->cond); - git_mutex_free(&target->mutex); - active_threads--; - } - } - - git__free(p); - return pb->failure; -} - -#else -#define ll_find_deltas(pb, l, ls, w, d) find_deltas(pb, l, &ls, w, d) -#endif - -int git_packbuilder__prepare(git_packbuilder *pb) -{ - git_pobject **delta_list; - size_t i, n = 0; - int error; - - if (pb->nr_objects == 0 || pb->done) - return 0; /* nothing to do */ - - /* - * Although we do not report progress during deltafication, we - * at least report that we are in the deltafication stage - */ - if (pb->progress_cb) { - if ((error = pb->progress_cb(GIT_PACKBUILDER_DELTAFICATION, 0, pb->nr_objects, pb->progress_cb_payload)) < 0) - return git_error_set_after_callback(error); - } - - delta_list = git__mallocarray(pb->nr_objects, sizeof(*delta_list)); - GIT_ERROR_CHECK_ALLOC(delta_list); - - for (i = 0; i < pb->nr_objects; ++i) { - git_pobject *po = pb->object_list + i; - - /* Make sure the item is within our size limits */ - if (po->size < 50 || po->size > pb->big_file_threshold) - continue; - - delta_list[n++] = po; - } - - if (n > 1) { - git__tsort((void **)delta_list, n, type_size_sort); - if ((error = ll_find_deltas(pb, delta_list, n, - GIT_PACK_WINDOW + 1, - GIT_PACK_DEPTH)) < 0) { - git__free(delta_list); - return error; - } - } - - error = report_delta_progress(pb, pb->nr_objects, true); - - pb->done = true; - git__free(delta_list); - return error; -} - -#define PREPARE_PACK error = git_packbuilder__prepare(pb); if (error < 0) { return error; } - -int git_packbuilder_foreach(git_packbuilder *pb, int (*cb)(void *buf, size_t size, void *payload), void *payload) -{ - int error; - PREPARE_PACK; - return write_pack(pb, cb, payload); -} - -int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb) -{ - int error; - PREPARE_PACK; - - return write_pack(pb, &write_pack_buf, buf); -} - -int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb) -{ - GIT_BUF_WRAP_PRIVATE(buf, git_packbuilder__write_buf, pb); -} - -static int write_cb(void *buf, size_t len, void *payload) -{ - struct pack_write_context *ctx = payload; - return git_indexer_append(ctx->indexer, buf, len, ctx->stats); -} - -int git_packbuilder_write( - git_packbuilder *pb, - const char *path, - unsigned int mode, - git_indexer_progress_cb progress_cb, - void *progress_cb_payload) -{ - int error = -1; - git_str object_path = GIT_STR_INIT; - git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; - git_indexer *indexer = NULL; - git_indexer_progress stats = { 0 }; - struct pack_write_context ctx; - int t; - - PREPARE_PACK; - - if (path == NULL) { - if ((error = git_repository__item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0) - goto cleanup; - if ((error = git_str_joinpath(&object_path, git_str_cstr(&object_path), "pack")) < 0) - goto cleanup; - path = git_str_cstr(&object_path); - } - - opts.progress_cb = progress_cb; - opts.progress_cb_payload = progress_cb_payload; - -#ifdef GIT_EXPERIMENTAL_SHA256 - opts.mode = mode; - opts.odb = pb->odb; - opts.oid_type = pb->oid_type; - - error = git_indexer_new(&indexer, path, &opts); -#else - error = git_indexer_new(&indexer, path, mode, pb->odb, &opts); -#endif - - if (error < 0) - goto cleanup; - - if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) - git_indexer__set_fsync(indexer, 1); - - ctx.indexer = indexer; - ctx.stats = &stats; - - if ((error = git_packbuilder_foreach(pb, write_cb, &ctx)) < 0) - goto cleanup; - - if ((error = git_indexer_commit(indexer, &stats)) < 0) - goto cleanup; - -#ifndef GIT_DEPRECATE_HARD - git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer)); -#endif - - pb->pack_name = git__strdup(git_indexer_name(indexer)); - GIT_ERROR_CHECK_ALLOC(pb->pack_name); - -cleanup: - git_indexer_free(indexer); - git_str_dispose(&object_path); - return error; -} - -#undef PREPARE_PACK - -#ifndef GIT_DEPRECATE_HARD -const git_oid *git_packbuilder_hash(git_packbuilder *pb) -{ - return &pb->pack_oid; -} -#endif - -const char *git_packbuilder_name(git_packbuilder *pb) -{ - return pb->pack_name; -} - - -static int cb_tree_walk( - const char *root, const git_tree_entry *entry, void *payload) -{ - int error; - struct tree_walk_context *ctx = payload; - - /* A commit inside a tree represents a submodule commit and should be skipped. */ - if (git_tree_entry_type(entry) == GIT_OBJECT_COMMIT) - return 0; - - if (!(error = git_str_sets(&ctx->buf, root)) && - !(error = git_str_puts(&ctx->buf, git_tree_entry_name(entry)))) - error = git_packbuilder_insert( - ctx->pb, git_tree_entry_id(entry), git_str_cstr(&ctx->buf)); - - return error; -} - -int git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *oid) -{ - git_commit *commit; - - if (git_commit_lookup(&commit, pb->repo, oid) < 0 || - git_packbuilder_insert(pb, oid, NULL) < 0) - return -1; - - if (git_packbuilder_insert_tree(pb, git_commit_tree_id(commit)) < 0) - return -1; - - git_commit_free(commit); - return 0; -} - -int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid) -{ - int error; - git_tree *tree = NULL; - struct tree_walk_context context = { pb, GIT_STR_INIT }; - - if (!(error = git_tree_lookup(&tree, pb->repo, oid)) && - !(error = git_packbuilder_insert(pb, oid, NULL))) - error = git_tree_walk(tree, GIT_TREEWALK_PRE, cb_tree_walk, &context); - - git_tree_free(tree); - git_str_dispose(&context.buf); - return error; -} - -int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name) -{ - git_object *obj; - int error; - - GIT_ASSERT_ARG(pb); - GIT_ASSERT_ARG(id); - - if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJECT_ANY)) < 0) - return error; - - switch (git_object_type(obj)) { - case GIT_OBJECT_BLOB: - error = git_packbuilder_insert(pb, id, name); - break; - case GIT_OBJECT_TREE: - error = git_packbuilder_insert_tree(pb, id); - break; - case GIT_OBJECT_COMMIT: - error = git_packbuilder_insert_commit(pb, id); - break; - case GIT_OBJECT_TAG: - if ((error = git_packbuilder_insert(pb, id, name)) < 0) - goto cleanup; - error = git_packbuilder_insert_recur(pb, git_tag_target_id((git_tag *) obj), NULL); - break; - - default: - git_error_set(GIT_ERROR_INVALID, "unknown object type"); - error = -1; - } - -cleanup: - git_object_free(obj); - return error; -} - -size_t git_packbuilder_object_count(git_packbuilder *pb) -{ - return pb->nr_objects; -} - -size_t git_packbuilder_written(git_packbuilder *pb) -{ - return pb->nr_written; -} - -static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id) -{ - struct walk_object *obj; - - obj = git_pool_mallocz(&pb->object_pool, 1); - if (!obj) { - git_error_set_oom(); - return -1; - } - - git_oid_cpy(&obj->id, id); - - *out = obj; - return 0; -} - -static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id) -{ - struct walk_object *obj; - int error; - - error = git_packbuilder_walk_objectmap_get(&obj, &pb->walk_objects, id); - - if (error == GIT_ENOTFOUND) { - if ((error = lookup_walk_object(&obj, pb, id)) < 0) - return error; - - if ((error = git_packbuilder_walk_objectmap_put(&pb->walk_objects, &obj->id, obj)) < 0) - return error; - } else if (error != 0) { - return error; - } - - *out = obj; - return 0; -} - -static int mark_blob_uninteresting(git_packbuilder *pb, const git_oid *id) -{ - int error; - struct walk_object *obj; - - if ((error = retrieve_object(&obj, pb, id)) < 0) - return error; - - obj->uninteresting = 1; - - return 0; -} - -static int mark_tree_uninteresting(git_packbuilder *pb, const git_oid *id) -{ - struct walk_object *obj; - git_tree *tree; - int error; - size_t i; - - if ((error = retrieve_object(&obj, pb, id)) < 0) - return error; - - if (obj->uninteresting) - return 0; - - obj->uninteresting = 1; - - if ((error = git_tree_lookup(&tree, pb->repo, id)) < 0) - return error; - - for (i = 0; i < git_tree_entrycount(tree); i++) { - const git_tree_entry *entry = git_tree_entry_byindex(tree, i); - const git_oid *entry_id = git_tree_entry_id(entry); - switch (git_tree_entry_type(entry)) { - case GIT_OBJECT_TREE: - if ((error = mark_tree_uninteresting(pb, entry_id)) < 0) - goto cleanup; - break; - case GIT_OBJECT_BLOB: - if ((error = mark_blob_uninteresting(pb, entry_id)) < 0) - goto cleanup; - break; - default: - /* it's a submodule or something unknown, we don't want it */ - ; - } - } - -cleanup: - git_tree_free(tree); - return error; -} - -/* - * Mark the edges of the graph uninteresting. Since we start from a - * git_revwalk, the commits are already uninteresting, but we need to - * mark the trees and blobs. - */ -static int mark_edges_uninteresting(git_packbuilder *pb, git_commit_list *commits) -{ - int error; - git_commit_list *list; - git_commit *commit; - - for (list = commits; list; list = list->next) { - if (!list->item->uninteresting) - continue; - - if ((error = git_commit_lookup(&commit, pb->repo, &list->item->oid)) < 0) - return error; - - error = mark_tree_uninteresting(pb, git_commit_tree_id(commit)); - git_commit_free(commit); - - if (error < 0) - return error; - } - - return 0; -} - -static int pack_objects_insert_tree(git_packbuilder *pb, git_tree *tree) -{ - size_t i; - int error; - git_tree *subtree; - struct walk_object *obj; - const char *name; - - if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0) - return error; - - if (obj->seen || obj->uninteresting) - return 0; - - obj->seen = 1; - - if ((error = git_packbuilder_insert(pb, &obj->id, NULL))) - return error; - - for (i = 0; i < git_tree_entrycount(tree); i++) { - const git_tree_entry *entry = git_tree_entry_byindex(tree, i); - const git_oid *entry_id = git_tree_entry_id(entry); - switch (git_tree_entry_type(entry)) { - case GIT_OBJECT_TREE: - if ((error = git_tree_lookup(&subtree, pb->repo, entry_id)) < 0) - return error; - - error = pack_objects_insert_tree(pb, subtree); - git_tree_free(subtree); - - if (error < 0) - return error; - - break; - case GIT_OBJECT_BLOB: - if ((error = retrieve_object(&obj, pb, entry_id)) < 0) - return error; - if (obj->uninteresting) - continue; - name = git_tree_entry_name(entry); - if ((error = git_packbuilder_insert(pb, entry_id, name)) < 0) - return error; - break; - default: - /* it's a submodule or something unknown, we don't want it */ - ; - } - } - - - return error; -} - -static int pack_objects_insert_commit(git_packbuilder *pb, struct walk_object *obj) -{ - int error; - git_commit *commit = NULL; - git_tree *tree = NULL; - - obj->seen = 1; - - if ((error = git_packbuilder_insert(pb, &obj->id, NULL)) < 0) - return error; - - if ((error = git_commit_lookup(&commit, pb->repo, &obj->id)) < 0) - return error; - - if ((error = git_tree_lookup(&tree, pb->repo, git_commit_tree_id(commit))) < 0) - goto cleanup; - - if ((error = pack_objects_insert_tree(pb, tree)) < 0) - goto cleanup; - -cleanup: - git_commit_free(commit); - git_tree_free(tree); - return error; -} - -int git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk) -{ - int error; - git_oid id; - struct walk_object *obj; - - GIT_ASSERT_ARG(pb); - GIT_ASSERT_ARG(walk); - - if ((error = mark_edges_uninteresting(pb, walk->user_input)) < 0) - return error; - - /* - * TODO: git marks the parents of the edges - * uninteresting. This may provide a speed advantage, but does - * seem to assume the remote does not have a single-commit - * history on the other end. - */ - - /* walk down each tree up to the blobs and insert them, stopping when uninteresting */ - while ((error = git_revwalk_next(&id, walk)) == 0) { - if ((error = retrieve_object(&obj, pb, &id)) < 0) - return error; - - if (obj->seen || obj->uninteresting) - continue; - - if ((error = pack_objects_insert_commit(pb, obj)) < 0) - return error; - } - - if (error == GIT_ITEROVER) - error = 0; - - return error; -} - -int git_packbuilder_set_callbacks(git_packbuilder *pb, git_packbuilder_progress progress_cb, void *progress_cb_payload) -{ - if (!pb) - return -1; - - pb->progress_cb = progress_cb; - pb->progress_cb_payload = progress_cb_payload; - - return 0; -} - -void git_packbuilder_free(git_packbuilder *pb) -{ - if (pb == NULL) - return; - -#ifdef GIT_THREADS - - git_mutex_free(&pb->cache_mutex); - git_mutex_free(&pb->progress_mutex); - git_cond_free(&pb->progress_cond); - -#endif - - if (pb->odb) - git_odb_free(pb->odb); - - git_packbuilder_pobjectmap_dispose(&pb->object_ix); - - if (pb->object_list) - git__free(pb->object_list); - - git_packbuilder_walk_objectmap_dispose(&pb->walk_objects); - git_pool_clear(&pb->object_pool); - - git_hash_ctx_cleanup(&pb->ctx); - git_zstream_free(&pb->zstream); - - git__free(pb->pack_name); - - git__free(pb); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/pack-objects.h b/vendor/libgit2-sys/libgit2/src/libgit2/pack-objects.h deleted file mode 100644 index ad04fb0..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/pack-objects.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_pack_objects_h__ -#define INCLUDE_pack_objects_h__ - -#include "common.h" - -#include "str.h" -#include "hash.h" -#include "zstream.h" -#include "pool.h" -#include "indexer.h" -#include "hashmap_oid.h" - -#include "git2/oid.h" -#include "git2/pack.h" - -#define GIT_PACK_WINDOW 10 /* number of objects to possibly delta against */ -#define GIT_PACK_DEPTH 50 /* max delta depth */ -#define GIT_PACK_DELTA_CACHE_SIZE (256 * 1024 * 1024) -#define GIT_PACK_DELTA_CACHE_LIMIT 1000 -#define GIT_PACK_BIG_FILE_THRESHOLD (512 * 1024 * 1024) - -typedef struct git_pobject { - git_oid id; - git_object_t type; - off64_t offset; - - size_t size; - - unsigned int hash; /* name hint hash */ - - struct git_pobject *delta; /* delta base object */ - struct git_pobject *delta_child; /* deltified objects who bases me */ - struct git_pobject *delta_sibling; /* other deltified objects - * who uses the same base as - * me */ - - void *delta_data; - size_t delta_size; - size_t z_delta_size; - - unsigned int written:1, - recursing:1, - tagged:1, - filled:1; -} git_pobject; - -typedef struct walk_object walk_object; - -GIT_HASHMAP_OID_STRUCT(git_packbuilder_pobjectmap, git_pobject *); -GIT_HASHMAP_OID_STRUCT(git_packbuilder_walk_objectmap, walk_object *); - -struct git_packbuilder { - git_repository *repo; /* associated repository */ - git_odb *odb; /* associated object database */ - - git_oid_t oid_type; - - git_hash_ctx ctx; - git_zstream zstream; - - uint32_t nr_objects, - nr_deltified, - nr_written, - nr_remaining; - - size_t nr_alloc; - - git_pobject *object_list; - - git_packbuilder_pobjectmap object_ix; - git_packbuilder_walk_objectmap walk_objects; - git_pool object_pool; - -#ifndef GIT_DEPRECATE_HARD - git_oid pack_oid; /* hash of written pack */ -#endif - char *pack_name; /* name of written pack */ - - /* synchronization objects */ - git_mutex cache_mutex; - git_mutex progress_mutex; - git_cond progress_cond; - - /* configs */ - size_t delta_cache_size; - size_t max_delta_cache_size; - size_t cache_max_small_delta_size; - size_t big_file_threshold; - size_t window_memory_limit; - - unsigned int nr_threads; /* nr of threads to use */ - - git_packbuilder_progress progress_cb; - void *progress_cb_payload; - - /* the time progress was last reported, in millisecond ticks */ - uint64_t last_progress_report_time; - - bool done; - - /* A non-zero error code in failure causes all threads to shut themselves - down. Some functions will return this error code. */ - volatile int failure; -}; - -int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb); -int git_packbuilder__prepare(git_packbuilder *pb); - - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/pack.c b/vendor/libgit2-sys/libgit2/src/libgit2/pack.c deleted file mode 100644 index 7eef1e6..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/pack.c +++ /dev/null @@ -1,1667 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "pack.h" - -#include "delta.h" -#include "futils.h" -#include "mwindow.h" -#include "odb.h" -#include "oid.h" -#include "oidarray.h" -#include "hashmap_oid.h" - -/* Option to bypass checking existence of '.keep' files */ -bool git_disable_pack_keep_file_checks = false; - -static int packfile_open_locked(struct git_pack_file *p); -static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t n); -static int packfile_unpack_compressed( - git_rawobj *obj, - struct git_pack_file *p, - git_mwindow **w_curs, - off64_t *curpos, - size_t size, - git_object_t type); - -/* Can find the offset of an object given - * a prefix of an identifier. - * Throws GIT_EAMBIGUOUSOIDPREFIX if short oid - * is ambiguous within the pack. - * This method assumes that len is between - * GIT_OID_MINPREFIXLEN and the oid type's hexsize. - */ -static int pack_entry_find_offset( - off64_t *offset_out, - git_oid *found_oid, - struct git_pack_file *p, - const git_oid *short_oid, - size_t len); - -#define off64_hash(key) (uint32_t)((key)>>33^(key)^(key)<<11) -#define off64_equal(a, b) ((a) == (b)) - -GIT_HASHMAP_FUNCTIONS(git_pack_offsetmap, GIT_HASHMAP_INLINE, off64_t, git_pack_cache_entry *, off64_hash, off64_equal); -GIT_HASHMAP_OID_FUNCTIONS(git_pack_oidmap, , struct git_pack_entry *); - -static int packfile_error(const char *message) -{ - git_error_set(GIT_ERROR_ODB, "invalid pack file - %s", message); - return -1; -} - -/******************** - * Delta base cache - ********************/ - -static git_pack_cache_entry *new_cache_object(git_rawobj *source) -{ - git_pack_cache_entry *e = git__calloc(1, sizeof(git_pack_cache_entry)); - if (!e) - return NULL; - - git_atomic32_inc(&e->refcount); - memcpy(&e->raw, source, sizeof(git_rawobj)); - - return e; -} - -static void free_cache_object(void *o) -{ - git_pack_cache_entry *e = (git_pack_cache_entry *)o; - - if (e != NULL) { - git__free(e->raw.data); - git__free(e); - } -} - -static void cache_free(git_pack_cache *cache) -{ - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - git_pack_cache_entry *entry; - - while (git_pack_offsetmap_iterate(&iter, NULL, &entry, &cache->entries) == 0) - free_cache_object(entry); - - git_pack_offsetmap_dispose(&cache->entries); -} - -static int cache_init(git_pack_cache *cache) -{ - cache->memory_limit = GIT_PACK_CACHE_MEMORY_LIMIT; - - if (git_mutex_init(&cache->lock)) { - git_error_set(GIT_ERROR_OS, "failed to initialize pack cache mutex"); - return -1; - } - - return 0; -} - -static git_pack_cache_entry *cache_get(git_pack_cache *cache, off64_t offset) -{ - git_pack_cache_entry *entry = NULL; - - if (git_mutex_lock(&cache->lock) < 0) - return NULL; - - if (git_pack_offsetmap_get(&entry, &cache->entries, offset) == 0) { - git_atomic32_inc(&entry->refcount); - entry->last_usage = cache->use_ctr++; - } - - git_mutex_unlock(&cache->lock); - - return entry; -} - -/* Run with the cache lock held */ -static void free_lowest_entry(git_pack_cache *cache) -{ - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - git_pack_cache_entry *entry; - off64_t offset; - - while (git_pack_offsetmap_iterate(&iter, &offset, &entry, &cache->entries) == 0) { - if (entry && git_atomic32_get(&entry->refcount) == 0) { - cache->memory_used -= entry->raw.len; - git_pack_offsetmap_remove(&cache->entries, offset); - free_cache_object(entry); - } - } -} - -static int cache_add( - git_pack_cache_entry **cached_out, - git_pack_cache *cache, - git_rawobj *base, - off64_t offset) -{ - git_pack_cache_entry *entry; - int exists; - - if (base->len > GIT_PACK_CACHE_SIZE_LIMIT) - return -1; - - entry = new_cache_object(base); - if (entry) { - if (git_mutex_lock(&cache->lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock cache"); - git__free(entry); - return -1; - } - /* Add it to the cache if nobody else has */ - exists = git_pack_offsetmap_contains(&cache->entries, offset); - if (!exists) { - while (cache->memory_used + base->len > cache->memory_limit) - free_lowest_entry(cache); - - git_pack_offsetmap_put(&cache->entries, offset, entry); - cache->memory_used += entry->raw.len; - - *cached_out = entry; - } - git_mutex_unlock(&cache->lock); - /* Somebody beat us to adding it into the cache */ - if (exists) { - git__free(entry); - return -1; - } - } - - return 0; -} - -/*********************************************************** - * - * PACK INDEX METHODS - * - ***********************************************************/ - -static void pack_index_free(struct git_pack_file *p) -{ - if (p->ids) { - git__free(p->ids); - p->ids = NULL; - } - if (p->index_map.data) { - git_futils_mmap_free(&p->index_map); - p->index_map.data = NULL; - } -} - -/* Run with the packfile lock held */ -static int pack_index_check_locked(const char *path, struct git_pack_file *p) -{ - struct git_pack_idx_header *hdr; - uint32_t version, nr = 0, i, *index; - void *idx_map; - size_t idx_size; - struct stat st; - int error; - - /* TODO: properly open the file without access time using O_NOATIME */ - git_file fd = git_futils_open_ro(path); - if (fd < 0) - return fd; - - if (p_fstat(fd, &st) < 0) { - p_close(fd); - git_error_set(GIT_ERROR_OS, "unable to stat pack index '%s'", path); - return -1; - } - - if (!S_ISREG(st.st_mode) || - !git__is_sizet(st.st_size) || - (idx_size = (size_t)st.st_size) < (size_t)((4 * 256) + (p->oid_size * 2))) { - p_close(fd); - git_error_set(GIT_ERROR_ODB, "invalid pack index '%s'", path); - return -1; - } - - error = git_futils_mmap_ro(&p->index_map, fd, 0, idx_size); - - p_close(fd); - - if (error < 0) - return error; - - hdr = idx_map = p->index_map.data; - - if (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) { - version = ntohl(hdr->idx_version); - - if (version < 2 || version > 2) { - git_futils_mmap_free(&p->index_map); - return packfile_error("unsupported index version"); - } - - } else { - version = 1; - } - - index = idx_map; - - if (version > 1) - index += 2; /* skip index header */ - - for (i = 0; i < 256; i++) { - uint32_t n = ntohl(index[i]); - if (n < nr) { - git_futils_mmap_free(&p->index_map); - return packfile_error("index is non-monotonic"); - } - nr = n; - } - - if (version == 1) { - /* - * Total size: - * - 256 index entries 4 bytes each - * - 24/36-byte entries * nr (20/32 byte SHA + 4-byte offset) - * - 20/32-byte SHA of the packfile - * - 20/32-byte SHA file checksum - */ - if (idx_size != (4 * 256 + ((uint64_t) nr * (p->oid_size + 4)) + (p->oid_size * 2))) { - git_futils_mmap_free(&p->index_map); - return packfile_error("index is corrupted"); - } - } else if (version == 2) { - /* - * Minimum size: - * - 8 bytes of header - * - 256 index entries 4 bytes each - * - 20/32-byte SHA entry * nr - * - 4-byte crc entry * nr - * - 4-byte offset entry * nr - * - 20/32-byte SHA of the packfile - * - 20/32-byte SHA file checksum - * And after the 4-byte offset table might be a - * variable sized table containing 8-byte entries - * for offsets larger than 2^31. - */ - uint64_t min_size = 8 + (4 * 256) + ((uint64_t)nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2); - uint64_t max_size = min_size; - - if (nr) - max_size += (nr - 1)*8; - - if (idx_size < min_size || idx_size > max_size) { - git_futils_mmap_free(&p->index_map); - return packfile_error("wrong index size"); - } - } - - p->num_objects = nr; - p->index_version = version; - return 0; -} - -/* Run with the packfile lock held */ -static int pack_index_open_locked(struct git_pack_file *p) -{ - int error = 0; - size_t name_len; - git_str idx_name = GIT_STR_INIT; - - if (p->index_version > -1) - goto cleanup; - - /* checked by git_pack_file alloc */ - name_len = strlen(p->pack_name); - GIT_ASSERT(name_len > strlen(".pack")); - - if ((error = git_str_init(&idx_name, name_len)) < 0) - goto cleanup; - - git_str_put(&idx_name, p->pack_name, name_len - strlen(".pack")); - git_str_puts(&idx_name, ".idx"); - if (git_str_oom(&idx_name)) { - error = -1; - goto cleanup; - } - - if (p->index_version == -1) - error = pack_index_check_locked(idx_name.ptr, p); - -cleanup: - git_str_dispose(&idx_name); - - return error; -} - -static unsigned char *pack_window_open( - struct git_pack_file *p, - git_mwindow **w_cursor, - off64_t offset, - unsigned int *left) -{ - unsigned char *pack_data = NULL; - - if (git_mutex_lock(&p->lock) < 0) { - git_error_set(GIT_ERROR_THREAD, "unable to lock packfile"); - return NULL; - } - if (git_mutex_lock(&p->mwf.lock) < 0) { - git_mutex_unlock(&p->lock); - git_error_set(GIT_ERROR_THREAD, "unable to lock packfile"); - return NULL; - } - - if (p->mwf.fd == -1 && packfile_open_locked(p) < 0) - goto cleanup; - - /* Since packfiles end in a hash of their content and it's - * pointless to ask for an offset into the middle of that - * hash, and the pack_window_contains function above wouldn't match - * don't allow an offset too close to the end of the file. - * - * Don't allow a negative offset, as that means we've wrapped - * around. - */ - if (offset > (p->mwf.size - p->oid_size)) - goto cleanup; - if (offset < 0) - goto cleanup; - - pack_data = git_mwindow_open(&p->mwf, w_cursor, offset, p->oid_size, left); - -cleanup: - git_mutex_unlock(&p->mwf.lock); - git_mutex_unlock(&p->lock); - return pack_data; - } - -/* - * The per-object header is a pretty dense thing, which is - * - first byte: low four bits are "size", - * then three bits of "type", - * with the high bit being "size continues". - * - each byte afterwards: low seven bits are size continuation, - * with the high bit being "size continues" - */ -int git_packfile__object_header(size_t *out, unsigned char *hdr, size_t size, git_object_t type) -{ - unsigned char *hdr_base; - unsigned char c; - - GIT_ASSERT_ARG(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA); - - /* TODO: add support for chunked objects; see git.git 6c0d19b1 */ - - c = (unsigned char)((type << 4) | (size & 15)); - size >>= 4; - hdr_base = hdr; - - while (size) { - *hdr++ = c | 0x80; - c = size & 0x7f; - size >>= 7; - } - *hdr++ = c; - - *out = (hdr - hdr_base); - return 0; -} - - -static int packfile_unpack_header1( - unsigned long *usedp, - size_t *sizep, - git_object_t *type, - const unsigned char *buf, - unsigned long len) -{ - unsigned shift; - unsigned long size, c; - unsigned long used = 0; - - c = buf[used++]; - *type = (c >> 4) & 7; - size = c & 15; - shift = 4; - while (c & 0x80) { - if (len <= used) { - git_error_set(GIT_ERROR_ODB, "buffer too small"); - return GIT_EBUFS; - } - - if (bitsizeof(long) <= shift) { - *usedp = 0; - git_error_set(GIT_ERROR_ODB, "packfile corrupted"); - return -1; - } - - c = buf[used++]; - size += (c & 0x7f) << shift; - shift += 7; - } - - *sizep = (size_t)size; - *usedp = used; - return 0; -} - -int git_packfile_unpack_header( - size_t *size_p, - git_object_t *type_p, - struct git_pack_file *p, - git_mwindow **w_curs, - off64_t *curpos) -{ - unsigned char *base; - unsigned int left; - unsigned long used; - int error; - - if ((error = git_mutex_lock(&p->lock)) < 0) - return error; - if ((error = git_mutex_lock(&p->mwf.lock)) < 0) { - git_mutex_unlock(&p->lock); - return error; - } - - if (p->mwf.fd == -1 && (error = packfile_open_locked(p)) < 0) { - git_mutex_unlock(&p->lock); - git_mutex_unlock(&p->mwf.lock); - return error; - } - - /* pack_window_open() assures us we have [base, base + oid_size) - * available as a range that we can look at at. (It's actually - * the hash size that is assured.) With our object header - * encoding the maximum deflated object size is 2^137, which is - * just insane, so we know won't exceed what we have been given. - */ - base = git_mwindow_open(&p->mwf, w_curs, *curpos, p->oid_size, &left); - git_mutex_unlock(&p->lock); - git_mutex_unlock(&p->mwf.lock); - if (base == NULL) - return GIT_EBUFS; - - error = packfile_unpack_header1(&used, size_p, type_p, base, left); - git_mwindow_close(w_curs); - if (error == GIT_EBUFS) - return error; - else if (error < 0) - return packfile_error("header length is zero"); - - *curpos += used; - return 0; -} - -int git_packfile_resolve_header( - size_t *size_p, - git_object_t *type_p, - struct git_pack_file *p, - off64_t offset) -{ - git_mwindow *w_curs = NULL; - off64_t curpos = offset; - size_t size; - git_object_t type; - off64_t base_offset; - int error; - - error = git_mutex_lock(&p->lock); - if (error < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock packfile reader"); - return error; - } - error = git_mutex_lock(&p->mwf.lock); - if (error < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock packfile reader"); - git_mutex_unlock(&p->lock); - return error; - } - - if (p->mwf.fd == -1 && (error = packfile_open_locked(p)) < 0) { - git_mutex_unlock(&p->mwf.lock); - git_mutex_unlock(&p->lock); - return error; - } - git_mutex_unlock(&p->mwf.lock); - git_mutex_unlock(&p->lock); - - error = git_packfile_unpack_header(&size, &type, p, &w_curs, &curpos); - if (error < 0) - return error; - - if (type == GIT_OBJECT_OFS_DELTA || type == GIT_OBJECT_REF_DELTA) { - size_t base_size; - git_packfile_stream stream; - - error = get_delta_base(&base_offset, p, &w_curs, &curpos, type, offset); - git_mwindow_close(&w_curs); - - if (error < 0) - return error; - - if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0) - return error; - error = git_delta_read_header_fromstream(&base_size, size_p, &stream); - git_packfile_stream_dispose(&stream); - if (error < 0) - return error; - } else { - *size_p = size; - base_offset = 0; - } - - while (type == GIT_OBJECT_OFS_DELTA || type == GIT_OBJECT_REF_DELTA) { - curpos = base_offset; - error = git_packfile_unpack_header(&size, &type, p, &w_curs, &curpos); - if (error < 0) - return error; - if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA) - break; - - error = get_delta_base(&base_offset, p, &w_curs, &curpos, type, base_offset); - git_mwindow_close(&w_curs); - - if (error < 0) - return error; - } - *type_p = type; - - return error; -} - -#define SMALL_STACK_SIZE 64 - -/** - * Generate the chain of dependencies which we need to get to the - * object at `off`. `chain` is used a stack, popping gives the right - * order to apply deltas on. If an object is found in the pack's base - * cache, we stop calculating there. - */ -static int pack_dependency_chain(git_dependency_chain *chain_out, - git_pack_cache_entry **cached_out, off64_t *cached_off, - struct pack_chain_elem *small_stack, size_t *stack_sz, - struct git_pack_file *p, off64_t obj_offset) -{ - git_dependency_chain chain = GIT_ARRAY_INIT; - git_mwindow *w_curs = NULL; - off64_t curpos = obj_offset, base_offset; - int error = 0, use_heap = 0; - size_t size, elem_pos; - git_object_t type; - - elem_pos = 0; - while (true) { - struct pack_chain_elem *elem; - git_pack_cache_entry *cached = NULL; - - /* if we have a base cached, we can stop here instead */ - if ((cached = cache_get(&p->bases, obj_offset)) != NULL) { - *cached_out = cached; - *cached_off = obj_offset; - break; - } - - /* if we run out of space on the small stack, use the array */ - if (elem_pos == SMALL_STACK_SIZE) { - git_array_init_to_size(chain, elem_pos); - GIT_ERROR_CHECK_ARRAY(chain); - memcpy(chain.ptr, small_stack, elem_pos * sizeof(struct pack_chain_elem)); - chain.size = elem_pos; - use_heap = 1; - } - - curpos = obj_offset; - if (!use_heap) { - elem = &small_stack[elem_pos]; - } else { - elem = git_array_alloc(chain); - if (!elem) { - error = -1; - goto on_error; - } - } - - elem->base_key = obj_offset; - - error = git_packfile_unpack_header(&size, &type, p, &w_curs, &curpos); - if (error < 0) - goto on_error; - - elem->offset = curpos; - elem->size = size; - elem->type = type; - elem->base_key = obj_offset; - - if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA) - break; - - error = get_delta_base(&base_offset, p, &w_curs, &curpos, type, obj_offset); - git_mwindow_close(&w_curs); - - if (error < 0) - goto on_error; - - /* we need to pass the pos *after* the delta-base bit */ - elem->offset = curpos; - - /* go through the loop again, but with the new object */ - obj_offset = base_offset; - elem_pos++; - } - - - *stack_sz = elem_pos + 1; - *chain_out = chain; - return error; - -on_error: - git_array_clear(chain); - return error; -} - -int git_packfile_unpack( - git_rawobj *obj, - struct git_pack_file *p, - off64_t *obj_offset) -{ - git_mwindow *w_curs = NULL; - off64_t curpos = *obj_offset; - int error, free_base = 0; - git_dependency_chain chain = GIT_ARRAY_INIT; - struct pack_chain_elem *elem = NULL, *stack; - git_pack_cache_entry *cached = NULL; - struct pack_chain_elem small_stack[SMALL_STACK_SIZE]; - size_t stack_size = 0, elem_pos, alloclen; - git_object_t base_type; - - error = git_mutex_lock(&p->lock); - if (error < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock packfile reader"); - return error; - } - error = git_mutex_lock(&p->mwf.lock); - if (error < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock packfile reader"); - git_mutex_unlock(&p->lock); - return error; - } - - if (p->mwf.fd == -1) - error = packfile_open_locked(p); - git_mutex_unlock(&p->mwf.lock); - git_mutex_unlock(&p->lock); - if (error < 0) - return error; - - /* - * TODO: optionally check the CRC on the packfile - */ - - error = pack_dependency_chain(&chain, &cached, obj_offset, small_stack, &stack_size, p, *obj_offset); - if (error < 0) - return error; - - obj->data = NULL; - obj->len = 0; - obj->type = GIT_OBJECT_INVALID; - - /* let's point to the right stack */ - stack = chain.ptr ? chain.ptr : small_stack; - - elem_pos = stack_size; - if (cached) { - memcpy(obj, &cached->raw, sizeof(git_rawobj)); - base_type = obj->type; - elem_pos--; /* stack_size includes the base, which isn't actually there */ - } else { - elem = &stack[--elem_pos]; - base_type = elem->type; - } - - switch (base_type) { - case GIT_OBJECT_COMMIT: - case GIT_OBJECT_TREE: - case GIT_OBJECT_BLOB: - case GIT_OBJECT_TAG: - if (!cached) { - curpos = elem->offset; - error = packfile_unpack_compressed(obj, p, &w_curs, &curpos, elem->size, elem->type); - git_mwindow_close(&w_curs); - base_type = elem->type; - } - if (error < 0) - goto cleanup; - break; - case GIT_OBJECT_OFS_DELTA: - case GIT_OBJECT_REF_DELTA: - error = packfile_error("dependency chain ends in a delta"); - goto cleanup; - default: - error = packfile_error("invalid packfile type in header"); - goto cleanup; - } - - /* - * Finding the object we want a cached base element is - * problematic, as we need to make sure we don't accidentally - * give the caller the cached object, which it would then feel - * free to free, so we need to copy the data. - */ - if (cached && stack_size == 1) { - void *data = obj->data; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, obj->len, 1); - obj->data = git__malloc(alloclen); - GIT_ERROR_CHECK_ALLOC(obj->data); - - memcpy(obj->data, data, obj->len + 1); - git_atomic32_dec(&cached->refcount); - goto cleanup; - } - - /* we now apply each consecutive delta until we run out */ - while (elem_pos > 0 && !error) { - git_rawobj base, delta; - - /* - * We can now try to add the base to the cache, as - * long as it's not already the cached one. - */ - if (!cached) - free_base = !!cache_add(&cached, &p->bases, obj, elem->base_key); - - elem = &stack[elem_pos - 1]; - curpos = elem->offset; - error = packfile_unpack_compressed(&delta, p, &w_curs, &curpos, elem->size, elem->type); - git_mwindow_close(&w_curs); - - if (error < 0) { - /* We have transferred ownership of the data to the cache. */ - obj->data = NULL; - break; - } - - /* the current object becomes the new base, on which we apply the delta */ - base = *obj; - obj->data = NULL; - obj->len = 0; - obj->type = GIT_OBJECT_INVALID; - - error = git_delta_apply(&obj->data, &obj->len, base.data, base.len, delta.data, delta.len); - obj->type = base_type; - - /* - * We usually don't want to free the base at this - * point, as we put it into the cache in the previous - * iteration. free_base lets us know that we got the - * base object directly from the packfile, so we can free it. - */ - git__free(delta.data); - if (free_base) { - free_base = 0; - git__free(base.data); - } - - if (cached) { - git_atomic32_dec(&cached->refcount); - cached = NULL; - } - - if (error < 0) - break; - - elem_pos--; - } - -cleanup: - if (error < 0) { - git__free(obj->data); - if (cached) - git_atomic32_dec(&cached->refcount); - } - - if (elem) - *obj_offset = curpos; - - git_array_clear(chain); - return error; -} - -int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, off64_t curpos) -{ - memset(obj, 0, sizeof(git_packfile_stream)); - obj->curpos = curpos; - obj->p = p; - - if (git_zstream_init(&obj->zstream, GIT_ZSTREAM_INFLATE) < 0) { - git_error_set(GIT_ERROR_ZLIB, "failed to init packfile stream"); - return -1; - } - - return 0; -} - -ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len) -{ - unsigned int window_len; - unsigned char *in; - int error; - - if (obj->done) - return 0; - - if ((in = pack_window_open(obj->p, &obj->mw, obj->curpos, &window_len)) == NULL) - return GIT_EBUFS; - - if ((error = git_zstream_set_input(&obj->zstream, in, window_len)) < 0 || - (error = git_zstream_get_output_chunk(buffer, &len, &obj->zstream)) < 0) { - git_mwindow_close(&obj->mw); - git_error_set(GIT_ERROR_ZLIB, "error reading from the zlib stream"); - return -1; - } - - git_mwindow_close(&obj->mw); - - obj->curpos += window_len - obj->zstream.in_len; - - if (git_zstream_eos(&obj->zstream)) - obj->done = 1; - - /* If we didn't write anything out but we're not done, we need more data */ - if (!len && !git_zstream_eos(&obj->zstream)) - return GIT_EBUFS; - - return len; - -} - -void git_packfile_stream_dispose(git_packfile_stream *obj) -{ - git_zstream_free(&obj->zstream); -} - -static int packfile_unpack_compressed( - git_rawobj *obj, - struct git_pack_file *p, - git_mwindow **mwindow, - off64_t *position, - size_t size, - git_object_t type) -{ - git_zstream zstream = GIT_ZSTREAM_INIT; - size_t buffer_len, total = 0; - char *data = NULL; - int error; - - GIT_ERROR_CHECK_ALLOC_ADD(&buffer_len, size, 1); - data = git__calloc(1, buffer_len); - GIT_ERROR_CHECK_ALLOC(data); - - if ((error = git_zstream_init(&zstream, GIT_ZSTREAM_INFLATE)) < 0) { - git_error_set(GIT_ERROR_ZLIB, "failed to init zlib stream on unpack"); - goto out; - } - - do { - size_t bytes = buffer_len - total; - unsigned int window_len, consumed; - unsigned char *in; - - if ((in = pack_window_open(p, mwindow, *position, &window_len)) == NULL) { - error = -1; - goto out; - } - - if ((error = git_zstream_set_input(&zstream, in, window_len)) < 0 || - (error = git_zstream_get_output_chunk(data + total, &bytes, &zstream)) < 0) { - git_mwindow_close(mwindow); - goto out; - } - - git_mwindow_close(mwindow); - - consumed = window_len - (unsigned int)zstream.in_len; - - if (!bytes && !consumed) { - git_error_set(GIT_ERROR_ZLIB, "error inflating zlib stream"); - error = -1; - goto out; - } - - *position += consumed; - total += bytes; - } while (!git_zstream_eos(&zstream)); - - if (total != size || !git_zstream_eos(&zstream)) { - git_error_set(GIT_ERROR_ZLIB, "error inflating zlib stream"); - error = -1; - goto out; - } - - /* zlib may have garbled the trailing buffer */ - data[size] = '\0'; - - obj->type = type; - obj->len = size; - obj->data = data; - -out: - git_zstream_free(&zstream); - if (error) - git__free(data); - - return error; -} - -/* - * curpos is where the data starts, delta_obj_offset is the where the - * header starts - */ -int get_delta_base( - off64_t *delta_base_out, - struct git_pack_file *p, - git_mwindow **w_curs, - off64_t *curpos, - git_object_t type, - off64_t delta_obj_offset) -{ - unsigned int left = 0; - unsigned char *base_info; - off64_t base_offset; - git_oid unused; - - GIT_ASSERT_ARG(delta_base_out); - - base_info = pack_window_open(p, w_curs, *curpos, &left); - /* Assumption: the only reason this would fail is because the file is too small */ - if (base_info == NULL) - return GIT_EBUFS; - /* pack_window_open() assured us we have - * [base_info, base_info + oid_size) as a range that we can look - * at without walking off the end of the mapped window. Its - * actually the hash size that is assured. An OFS_DELTA longer - * than the hash size is stupid, as then a REF_DELTA would be - * smaller to store. - */ - if (type == GIT_OBJECT_OFS_DELTA) { - unsigned used = 0; - unsigned char c = base_info[used++]; - size_t unsigned_base_offset = c & 127; - while (c & 128) { - if (left <= used) - return GIT_EBUFS; - unsigned_base_offset += 1; - if (!unsigned_base_offset || MSB(unsigned_base_offset, 7)) - return packfile_error("overflow"); - c = base_info[used++]; - unsigned_base_offset = (unsigned_base_offset << 7) + (c & 127); - } - if (unsigned_base_offset == 0 || (size_t)delta_obj_offset <= unsigned_base_offset) - return packfile_error("out of bounds"); - base_offset = delta_obj_offset - unsigned_base_offset; - *curpos += used; - } else if (type == GIT_OBJECT_REF_DELTA) { - git_oid base_oid; - git_oid__fromraw(&base_oid, base_info, p->oid_type); - - /* If we have the cooperative cache, search in it first */ - if (p->has_cache) { - struct git_pack_entry *entry; - - if (git_pack_oidmap_get(&entry, &p->idx_cache, &base_oid) == 0) { - if (entry->offset == 0) - return packfile_error("delta offset is zero"); - - *curpos += p->oid_size; - *delta_base_out = entry->offset; - return 0; - } else { - /* If we're building an index, don't try to find the pack - * entry; we just haven't seen it yet. We'll make - * progress again in the next loop. - */ - return GIT_PASSTHROUGH; - } - } - - /* The base entry _must_ be in the same pack */ - if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, p->oid_hexsize) < 0) - return packfile_error("base entry delta is not in the same pack"); - *curpos += p->oid_size; - } else - return packfile_error("unknown object type"); - - if (base_offset == 0) - return packfile_error("delta offset is zero"); - - *delta_base_out = base_offset; - return 0; -} - -/*********************************************************** - * - * PACKFILE METHODS - * - ***********************************************************/ - -void git_packfile_free(struct git_pack_file *p, bool unlink_packfile) -{ - bool locked = true; - - if (!p) - return; - - cache_free(&p->bases); - - if (git_mutex_lock(&p->lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock packfile"); - locked = false; - } - if (p->mwf.fd >= 0) { - git_mwindow_free_all(&p->mwf); - p_close(p->mwf.fd); - p->mwf.fd = -1; - } - if (locked) - git_mutex_unlock(&p->lock); - - if (unlink_packfile) - p_unlink(p->pack_name); - - pack_index_free(p); - - git__free(p->bad_object_ids); - - git_mutex_free(&p->bases.lock); - git_mutex_free(&p->mwf.lock); - git_mutex_free(&p->lock); - git__free(p); -} - -/* Run with the packfile and mwf locks held */ -static int packfile_open_locked(struct git_pack_file *p) -{ - struct stat st; - struct git_pack_header hdr; - unsigned char checksum[GIT_OID_MAX_SIZE]; - unsigned char *idx_checksum; - - if (pack_index_open_locked(p) < 0) - return git_odb__error_notfound("failed to open packfile", NULL, 0); - - if (p->mwf.fd >= 0) - return 0; - - /* TODO: open with noatime */ - p->mwf.fd = git_futils_open_ro(p->pack_name); - if (p->mwf.fd < 0) - goto cleanup; - - if (p_fstat(p->mwf.fd, &st) < 0) { - git_error_set(GIT_ERROR_OS, "could not stat packfile"); - goto cleanup; - } - - /* If we created the struct before we had the pack we lack size. */ - if (!p->mwf.size) { - if (!S_ISREG(st.st_mode)) - goto cleanup; - p->mwf.size = (off64_t)st.st_size; - } else if (p->mwf.size != st.st_size) - goto cleanup; - -#if 0 - /* We leave these file descriptors open with sliding mmap; - * there is no point keeping them open across exec(), though. - */ - fd_flag = fcntl(p->mwf.fd, F_GETFD, 0); - if (fd_flag < 0) - goto cleanup; - - fd_flag |= FD_CLOEXEC; - if (fcntl(p->pack_fd, F_SETFD, fd_flag) == -1) - goto cleanup; -#endif - - /* Verify we recognize this pack file format. */ - if (p_read(p->mwf.fd, &hdr, sizeof(hdr)) < 0 || - hdr.hdr_signature != htonl(PACK_SIGNATURE) || - !pack_version_ok(hdr.hdr_version)) - goto cleanup; - - /* Verify the pack matches its index. */ - if (p->num_objects != ntohl(hdr.hdr_entries) || - p_pread(p->mwf.fd, checksum, p->oid_size, p->mwf.size - p->oid_size) < 0) - goto cleanup; - - idx_checksum = ((unsigned char *)p->index_map.data) + - p->index_map.len - (p->oid_size * 2); - - if (git_oid_raw_cmp(checksum, idx_checksum, p->oid_size) != 0) - goto cleanup; - - if (git_mwindow_file_register(&p->mwf) < 0) - goto cleanup; - - return 0; - -cleanup: - git_error_set(GIT_ERROR_OS, "invalid packfile '%s'", p->pack_name); - - if (p->mwf.fd >= 0) - p_close(p->mwf.fd); - p->mwf.fd = -1; - - return -1; -} - -int git_packfile__name(char **out, const char *path) -{ - size_t path_len; - git_str buf = GIT_STR_INIT; - - path_len = strlen(path); - - if (path_len < strlen(".idx")) - return git_odb__error_notfound("invalid packfile path", NULL, 0); - - if (git_str_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0) - return -1; - - *out = git_str_detach(&buf); - return 0; -} - -int git_packfile_alloc( - struct git_pack_file **pack_out, - const char *path, - git_oid_t oid_type) -{ - struct stat st; - struct git_pack_file *p; - size_t path_len = path ? strlen(path) : 0, alloc_len; - - *pack_out = NULL; - - if (path_len < strlen(".idx")) - return git_odb__error_notfound("invalid packfile path", NULL, 0); - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*p), path_len); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); - - p = git__calloc(1, alloc_len); - GIT_ERROR_CHECK_ALLOC(p); - - memcpy(p->pack_name, path, path_len + 1); - - /* - * Make sure a corresponding .pack file exists and that - * the index looks sane. - */ - if (git__suffixcmp(path, ".idx") == 0) { - size_t root_len = path_len - strlen(".idx"); - - if (!git_disable_pack_keep_file_checks) { - memcpy(p->pack_name + root_len, ".keep", sizeof(".keep")); - if (git_fs_path_exists(p->pack_name) == true) - p->pack_keep = 1; - } - - memcpy(p->pack_name + root_len, ".pack", sizeof(".pack")); - } - - if (p_stat(p->pack_name, &st) < 0 || !S_ISREG(st.st_mode)) { - git__free(p); - return git_odb__error_notfound("packfile not found", NULL, 0); - } - - /* ok, it looks sane as far as we can check without - * actually mapping the pack file. - */ - p->mwf.fd = -1; - p->mwf.size = st.st_size; - p->pack_local = 1; - p->mtime = (git_time_t)st.st_mtime; - p->index_version = -1; - p->oid_type = oid_type ? oid_type : GIT_OID_DEFAULT; - p->oid_size = (unsigned int)git_oid_size(p->oid_type); - p->oid_hexsize = (unsigned int)git_oid_hexsize(p->oid_type); - - if (git_mutex_init(&p->lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to initialize packfile mutex"); - git__free(p); - return -1; - } - - if (git_mutex_init(&p->mwf.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to initialize packfile window mutex"); - git_mutex_free(&p->lock); - git__free(p); - return -1; - } - - if (cache_init(&p->bases) < 0) { - git_mutex_free(&p->mwf.lock); - git_mutex_free(&p->lock); - git__free(p); - return -1; - } - - *pack_out = p; - - return 0; -} - -/*********************************************************** - * - * PACKFILE ENTRY SEARCH INTERNALS - * - ***********************************************************/ - -static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t n) -{ - const unsigned char *index, *end; - uint32_t off32; - - index = p->index_map.data; - end = index + p->index_map.len; - index += 4 * 256; - if (p->index_version == 1) - return ntohl(*((uint32_t *)(index + (p->oid_size + 4) * (size_t) n))); - - index += 8 + (size_t) p->num_objects * (p->oid_size + 4); - off32 = ntohl(*((uint32_t *)(index + 4 * n))); - if (!(off32 & 0x80000000)) - return off32; - index += (size_t) p->num_objects * 4 + (off32 & 0x7fffffff) * 8; - - /* Make sure we're not being sent out of bounds */ - if (index >= end - 8) - return -1; - - return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) | - ntohl(*((uint32_t *)(index + 4))); -} - -static int git__memcmp4(const void *a, const void *b) { - return memcmp(a, b, 4); -} - -int git_pack_foreach_entry( - struct git_pack_file *p, - git_odb_foreach_cb cb, - void *data) -{ - const unsigned char *index, *current; - uint32_t i; - int error = 0; - git_array_oid_t oids = GIT_ARRAY_INIT; - git_oid *oid; - - if (git_mutex_lock(&p->lock) < 0) - return packfile_error("failed to get lock for git_pack_foreach_entry"); - - if ((error = pack_index_open_locked(p)) < 0) { - git_mutex_unlock(&p->lock); - return error; - } - - if (!p->index_map.data) { - git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL"); - git_mutex_unlock(&p->lock); - return -1; - } - - index = p->index_map.data; - - if (p->index_version > 1) - index += 8; - - index += 4 * 256; - - if (p->ids == NULL) { - git_vector offsets, oids; - - if ((error = git_vector_init(&oids, p->num_objects, NULL))) { - git_mutex_unlock(&p->lock); - return error; - } - - if ((error = git_vector_init(&offsets, p->num_objects, git__memcmp4))) { - git_mutex_unlock(&p->lock); - return error; - } - - if (p->index_version > 1) { - const unsigned char *off = index + - (p->oid_size + 4) * p->num_objects; - - for (i = 0; i < p->num_objects; i++) - git_vector_insert(&offsets, (void*)&off[4 * i]); - - git_vector_sort(&offsets); - git_vector_foreach(&offsets, i, current) - git_vector_insert(&oids, (void*)&index[5 * (current - off)]); - } else { - for (i = 0; i < p->num_objects; i++) - git_vector_insert(&offsets, (void*)&index[(p->oid_size + 4) * i]); - git_vector_sort(&offsets); - git_vector_foreach(&offsets, i, current) - git_vector_insert(&oids, (void*)¤t[4]); - } - - git_vector_dispose(&offsets); - p->ids = (unsigned char **)git_vector_detach(NULL, NULL, &oids); - } - - /* - * We need to copy the OIDs to another array before we - * relinquish the lock to avoid races. We can also take - * this opportunity to put them into normal form. - */ - git_array_init_to_size(oids, p->num_objects); - if (!oids.ptr) { - git_mutex_unlock(&p->lock); - git_array_clear(oids); - GIT_ERROR_CHECK_ARRAY(oids); - } - for (i = 0; i < p->num_objects; i++) { - oid = git_array_alloc(oids); - if (!oid) { - git_mutex_unlock(&p->lock); - git_array_clear(oids); - GIT_ERROR_CHECK_ALLOC(oid); - } - git_oid__fromraw(oid, p->ids[i], p->oid_type); - } - - git_mutex_unlock(&p->lock); - - git_array_foreach(oids, i, oid) { - if ((error = cb(oid, data)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - git_array_clear(oids); - return error; -} - -int git_pack_foreach_entry_offset( - struct git_pack_file *p, - git_pack_foreach_entry_offset_cb cb, - void *data) -{ - const unsigned char *index; - off64_t current_offset; - git_oid current_oid; - uint32_t i; - int error = 0; - - if (git_mutex_lock(&p->lock) < 0) - return packfile_error("failed to get lock for git_pack_foreach_entry_offset"); - - index = p->index_map.data; - if (index == NULL) { - if ((error = pack_index_open_locked(p)) < 0) - goto cleanup; - - if (!p->index_map.data) { - git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL"); - goto cleanup; - } - - index = p->index_map.data; - } - - if (p->index_version > 1) - index += 8; - - index += 4 * 256; - - /* all offsets should have been validated by pack_index_check_locked */ - if (p->index_version > 1) { - const unsigned char *offsets = index + - (p->oid_size + 4) * p->num_objects; - const unsigned char *large_offset_ptr; - const unsigned char *large_offsets = index + - (p->oid_size + 8) * p->num_objects; - const unsigned char *large_offsets_end = ((const unsigned char *)p->index_map.data) + p->index_map.len - p->oid_size; - - for (i = 0; i < p->num_objects; i++) { - current_offset = ntohl(*(const uint32_t *)(offsets + 4 * i)); - if (current_offset & 0x80000000) { - large_offset_ptr = large_offsets + (current_offset & 0x7fffffff) * 8; - if (large_offset_ptr >= large_offsets_end) { - error = packfile_error("invalid large offset"); - goto cleanup; - } - current_offset = (((off64_t)ntohl(*((uint32_t *)(large_offset_ptr + 0)))) << 32) | - ntohl(*((uint32_t *)(large_offset_ptr + 4))); - } - - git_oid__fromraw(¤t_oid, (index + p->oid_size * i), p->oid_type); - if ((error = cb(¤t_oid, current_offset, data)) != 0) { - error = git_error_set_after_callback(error); - goto cleanup; - } - } - } else { - for (i = 0; i < p->num_objects; i++) { - current_offset = ntohl(*(const uint32_t *)(index + (p->oid_size + 4) * i)); - git_oid__fromraw(¤t_oid, (index + (p->oid_size + 4) * i + 4), p->oid_type); - if ((error = cb(¤t_oid, current_offset, data)) != 0) { - error = git_error_set_after_callback(error); - goto cleanup; - } - } - } - -cleanup: - git_mutex_unlock(&p->lock); - return error; -} - -int git_pack__lookup_id( - const void *oid_lookup_table, - size_t stride, - unsigned lo, - unsigned hi, - const unsigned char *oid_prefix, - const git_oid_t oid_type) -{ - const unsigned char *base = oid_lookup_table; - size_t oid_size = git_oid_size(oid_type); - - while (lo < hi) { - unsigned mi = (lo + hi) / 2; - int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix, oid_size); - - if (!cmp) - return mi; - - if (cmp > 0) - hi = mi; - else - lo = mi+1; - } - - return -((int)lo)-1; -} - -static int pack_entry_find_offset( - off64_t *offset_out, - git_oid *found_oid, - struct git_pack_file *p, - const git_oid *short_oid, - size_t len) -{ - const uint32_t *level1_ofs; - size_t ofs_delta = 0; - const unsigned char *index; - unsigned hi, lo, stride; - int pos, found = 0; - off64_t offset; - const unsigned char *current = 0; - int error = 0; - - *offset_out = 0; - - if (git_mutex_lock(&p->lock) < 0) - return packfile_error("failed to get lock for pack_entry_find_offset"); - - if ((error = pack_index_open_locked(p)) < 0) - goto cleanup; - - if (!p->index_map.data) { - git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL"); - goto cleanup; - } - - index = p->index_map.data; - level1_ofs = p->index_map.data; - - if (p->index_version > 1) { - level1_ofs += 2; - ofs_delta = 2; - index += 8; - } - - if ((size_t)short_oid->id[0] + ofs_delta >= p->index_map.len) { - git_error_set(GIT_ERROR_INTERNAL, "internal error: p->short_oid->[0] out of bounds"); - goto cleanup; - } - - index += 4 * 256; - hi = ntohl(level1_ofs[(int)short_oid->id[0]]); - lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(level1_ofs[(int)short_oid->id[0] - 1])); - - if (p->index_version > 1) { - stride = p->oid_size; - } else { - stride = p->oid_size + 4; - index += 4; - } - -#ifdef INDEX_DEBUG_LOOKUP - printf("%02x%02x%02x... lo %u hi %u nr %d\n", - short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects); -#endif - - pos = git_pack__lookup_id(index, stride, lo, hi, - short_oid->id, p->oid_type); - - if (pos >= 0) { - /* An object matching exactly the oid was found */ - found = 1; - current = index + pos * stride; - } else { - /* No object was found */ - /* pos refers to the object with the "closest" oid to short_oid */ - pos = - 1 - pos; - if (pos < (int)p->num_objects) { - current = index + pos * stride; - - if (!git_oid_raw_ncmp(short_oid->id, current, len)) - found = 1; - } - } - - if (found && - len != p->oid_hexsize && - pos + 1 < (int)p->num_objects) { - /* Check for ambiguousity */ - const unsigned char *next = current + stride; - - if (!git_oid_raw_ncmp(short_oid->id, next, len)) { - found = 2; - } - } - - if (!found) { - error = git_odb__error_notfound("failed to find offset for pack entry", short_oid, len); - goto cleanup; - } - if (found > 1) { - error = git_odb__error_ambiguous("found multiple offsets for pack entry"); - goto cleanup; - } - - if ((offset = nth_packed_object_offset_locked(p, pos)) < 0) { - git_error_set(GIT_ERROR_ODB, "packfile index is corrupt"); - error = -1; - goto cleanup; - } - - *offset_out = offset; - git_oid__fromraw(found_oid, current, p->oid_type); - -#ifdef INDEX_DEBUG_LOOKUP - { - char hex_sha1[p->oid_hexsize + 1]; - git_oid_fmt(hex_sha1, found_oid); - hex_sha1[p->oid_hexsize] = '\0'; - printf("found lo=%d %s\n", lo, hex_sha1); - } -#endif - -cleanup: - git_mutex_unlock(&p->lock); - return error; -} - -int git_pack_entry_find( - struct git_pack_entry *e, - struct git_pack_file *p, - const git_oid *short_oid, - size_t len) -{ - off64_t offset; - git_oid found_oid; - int error; - - GIT_ASSERT_ARG(p); - - if (len == p->oid_hexsize && p->num_bad_objects) { - unsigned i; - for (i = 0; i < p->num_bad_objects; i++) - if (git_oid__cmp(short_oid, &p->bad_object_ids[i]) == 0) - return packfile_error("bad object found in packfile"); - } - - error = pack_entry_find_offset(&offset, &found_oid, p, short_oid, len); - if (error < 0) - return error; - - error = git_mutex_lock(&p->lock); - if (error < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock packfile reader"); - return error; - } - error = git_mutex_lock(&p->mwf.lock); - if (error < 0) { - git_mutex_unlock(&p->lock); - git_error_set(GIT_ERROR_OS, "failed to lock packfile reader"); - return error; - } - - /* we found a unique entry in the index; - * make sure the packfile backing the index - * still exists on disk */ - if (p->mwf.fd == -1) - error = packfile_open_locked(p); - git_mutex_unlock(&p->mwf.lock); - git_mutex_unlock(&p->lock); - if (error < 0) - return error; - - e->offset = offset; - e->p = p; - - git_oid_cpy(&e->id, &found_oid); - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/pack.h b/vendor/libgit2-sys/libgit2/src/libgit2/pack.h deleted file mode 100644 index 4fd0921..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/pack.h +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_pack_h__ -#define INCLUDE_pack_h__ - -#include "common.h" - -#include "git2/oid.h" - -#include "array.h" -#include "map.h" -#include "mwindow.h" -#include "odb.h" -#include "zstream.h" -#include "oid.h" -#include "hashmap_oid.h" - -/** - * Function type for callbacks from git_pack_foreach_entry_offset. - */ -typedef int git_pack_foreach_entry_offset_cb( - const git_oid *id, - off64_t offset, - void *payload); - -#define GIT_PACK_FILE_MODE 0444 - -#define PACK_SIGNATURE 0x5041434b /* "PACK" */ -#define PACK_VERSION 2 -#define pack_version_ok(v) ((v) == htonl(2)) -struct git_pack_header { - uint32_t hdr_signature; - uint32_t hdr_version; - uint32_t hdr_entries; -}; - -/* - * The first four bytes of index formats later than version 1 should - * start with this signature, as all older git binaries would find this - * value illegal and abort reading the file. - * - * This is the case because the number of objects in a packfile - * cannot exceed 1,431,660,000 as every object would need at least - * 3 bytes of data and the overall packfile cannot exceed 4 GiB with - * version 1 of the index file due to the offsets limited to 32 bits. - * Clearly the signature exceeds this maximum. - * - * Very old git binaries will also compare the first 4 bytes to the - * next 4 bytes in the index and abort with a "non-monotonic index" - * error if the second 4 byte word is smaller than the first 4 - * byte word. This would be true in the proposed future index - * format as idx_signature would be greater than idx_version. - */ - -#define PACK_IDX_SIGNATURE 0xff744f63 /* "\377tOc" */ - -struct git_pack_idx_header { - uint32_t idx_signature; - uint32_t idx_version; -}; - -typedef struct git_pack_cache_entry { - size_t last_usage; /* enough? */ - git_atomic32 refcount; - git_rawobj raw; -} git_pack_cache_entry; - -struct pack_chain_elem { - off64_t base_key; - off64_t offset; - size_t size; - git_object_t type; -}; - -typedef git_array_t(struct pack_chain_elem) git_dependency_chain; - -#define GIT_PACK_CACHE_MEMORY_LIMIT 16 * 1024 * 1024 -#define GIT_PACK_CACHE_SIZE_LIMIT 1024 * 1024 /* don't bother caching anything over 1MB */ - -struct git_pack_entry { - off64_t offset; - git_oid id; - struct git_pack_file *p; -}; - -GIT_HASHMAP_STRUCT(git_pack_offsetmap, off64_t, git_pack_cache_entry *); - -GIT_HASHMAP_OID_STRUCT(git_pack_oidmap, struct git_pack_entry *); -GIT_HASHMAP_OID_PROTOTYPES(git_pack_oidmap, struct git_pack_entry *); - -typedef struct { - size_t memory_used; - size_t memory_limit; - size_t use_ctr; - git_mutex lock; - git_pack_offsetmap entries; -} git_pack_cache; - -struct git_pack_file { - git_mwindow_file mwf; - git_map index_map; - git_mutex lock; /* protect updates to index_map */ - git_atomic32 refcount; - - uint32_t num_objects; - uint32_t num_bad_objects; - git_oid *bad_object_ids; /* array of git_oid */ - - git_oid_t oid_type; - unsigned oid_hexsize:7, - oid_size:6, - pack_local:1, - pack_keep:1, - has_cache:1; - - int index_version; - git_time_t mtime; - - git_pack_oidmap idx_cache; - unsigned char **ids; - - git_pack_cache bases; /* delta base cache */ - - time_t last_freshen; /* last time the packfile was freshened */ - - /* something like ".git/objects/pack/xxxxx.pack" */ - char pack_name[GIT_FLEX_ARRAY]; /* more */ -}; - -/** - * Return the position where an OID (or a prefix) would be inserted within - * the OID Lookup Table of an .idx file. This performs binary search - * between the lo and hi indices. - * - * The stride parameter is provided because .idx files version 1 store the - * OIDs interleaved with the 4-byte file offsets of the objects within the - * .pack file (stride = oid_size + 4), whereas files with version 2 store - * them in a contiguous flat array (stride = oid_size). - */ -int git_pack__lookup_id( - const void *id_lookup_table, - size_t stride, - unsigned lo, - unsigned hi, - const unsigned char *id_prefix, - const git_oid_t oid_type); - -typedef struct git_packfile_stream { - off64_t curpos; - int done; - git_zstream zstream; - struct git_pack_file *p; - git_mwindow *mw; -} git_packfile_stream; - -int git_packfile__object_header(size_t *out, unsigned char *hdr, size_t size, git_object_t type); - -int git_packfile__name(char **out, const char *path); - -int git_packfile_unpack_header( - size_t *size_p, - git_object_t *type_p, - struct git_pack_file *p, - git_mwindow **w_curs, - off64_t *curpos); - -int git_packfile_resolve_header( - size_t *size_p, - git_object_t *type_p, - struct git_pack_file *p, - off64_t offset); - -int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, off64_t *obj_offset); - -int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, off64_t curpos); -ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len); -void git_packfile_stream_dispose(git_packfile_stream *obj); - -int get_delta_base( - off64_t *delta_base_out, - struct git_pack_file *p, - git_mwindow **w_curs, - off64_t *curpos, - git_object_t type, - off64_t delta_obj_offset); - -void git_packfile_free(struct git_pack_file *p, bool unlink_packfile); -int git_packfile_alloc( - struct git_pack_file **pack_out, - const char *path, - git_oid_t oid_type); - -int git_pack_entry_find( - struct git_pack_entry *e, - struct git_pack_file *p, - const git_oid *short_id, - size_t len); -int git_pack_foreach_entry( - struct git_pack_file *p, - git_odb_foreach_cb cb, - void *data); -/** - * Similar to git_pack_foreach_entry, but: - * - It also provides the offset of the object within the - * packfile. - * - It does not sort the objects in any order. - * - It retains the lock while invoking the callback. - */ -int git_pack_foreach_entry_offset( - struct git_pack_file *p, - git_pack_foreach_entry_offset_cb cb, - void *data); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/parse.c b/vendor/libgit2-sys/libgit2/src/libgit2/parse.c deleted file mode 100644 index 9eb86a3..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/parse.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#include "parse.h" -#include "oid.h" - -int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len) -{ - if (content && content_len) { - ctx->content = content; - ctx->content_len = content_len; - } else { - ctx->content = ""; - ctx->content_len = 0; - } - - ctx->remain = ctx->content; - ctx->remain_len = ctx->content_len; - ctx->line = ctx->remain; - ctx->line_len = git__linenlen(ctx->line, ctx->remain_len); - ctx->line_num = 1; - - return 0; -} - -void git_parse_ctx_clear(git_parse_ctx *ctx) -{ - memset(ctx, 0, sizeof(*ctx)); - ctx->content = ""; -} - -void git_parse_advance_line(git_parse_ctx *ctx) -{ - ctx->line += ctx->line_len; - ctx->remain_len -= ctx->line_len; - ctx->line_len = git__linenlen(ctx->line, ctx->remain_len); - ctx->line_num++; -} - -void git_parse_advance_chars(git_parse_ctx *ctx, size_t char_cnt) -{ - ctx->line += char_cnt; - ctx->remain_len -= char_cnt; - ctx->line_len -= char_cnt; -} - -int git_parse_advance_expected( - git_parse_ctx *ctx, - const char *expected, - size_t expected_len) -{ - if (ctx->line_len < expected_len) - return -1; - - if (memcmp(ctx->line, expected, expected_len) != 0) - return -1; - - git_parse_advance_chars(ctx, expected_len); - return 0; -} - -int git_parse_advance_ws(git_parse_ctx *ctx) -{ - int ret = -1; - - while (ctx->line_len > 0 && - ctx->line[0] != '\n' && - git__isspace(ctx->line[0])) { - ctx->line++; - ctx->line_len--; - ctx->remain_len--; - ret = 0; - } - - return ret; -} - -int git_parse_advance_nl(git_parse_ctx *ctx) -{ - if (ctx->line_len != 1 || ctx->line[0] != '\n') - return -1; - - git_parse_advance_line(ctx); - return 0; -} - -int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base) -{ - const char *end; - int ret; - - if (ctx->line_len < 1 || !git__isdigit(ctx->line[0])) - return -1; - - if ((ret = git__strntol64(out, ctx->line, ctx->line_len, &end, base)) < 0) - return -1; - - git_parse_advance_chars(ctx, (end - ctx->line)); - return 0; -} - -int git_parse_advance_oid(git_oid *out, git_parse_ctx *ctx, git_oid_t oid_type) -{ - size_t oid_hexsize = git_oid_hexsize(oid_type); - GIT_ASSERT(oid_hexsize); - - if (ctx->line_len < oid_hexsize) - return -1; - if ((git_oid__fromstrn(out, ctx->line, oid_hexsize, oid_type)) < 0) - return -1; - git_parse_advance_chars(ctx, oid_hexsize); - return 0; -} - -int git_parse_peek(char *out, git_parse_ctx *ctx, int flags) -{ - size_t remain = ctx->line_len; - const char *ptr = ctx->line; - - while (remain) { - char c = *ptr; - - if ((flags & GIT_PARSE_PEEK_SKIP_WHITESPACE) && - git__isspace(c)) { - remain--; - ptr++; - continue; - } - - *out = c; - return 0; - } - - return -1; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/parse.h b/vendor/libgit2-sys/libgit2/src/libgit2/parse.h deleted file mode 100644 index beef1de..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/parse.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_parse_h__ -#define INCLUDE_parse_h__ - -#include "common.h" - -typedef struct { - /* Original content buffer */ - const char *content; - size_t content_len; - - /* The remaining (unparsed) buffer */ - const char *remain; - size_t remain_len; - - const char *line; - size_t line_len; - size_t line_num; -} git_parse_ctx; - -#define GIT_PARSE_CTX_INIT { 0 } - -int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len); -void git_parse_ctx_clear(git_parse_ctx *ctx); - -#define git_parse_ctx_contains_s(ctx, str) \ - git_parse_ctx_contains(ctx, str, sizeof(str) - 1) - -GIT_INLINE(bool) git_parse_ctx_contains( - git_parse_ctx *ctx, const char *str, size_t len) -{ - return (ctx->line_len >= len && memcmp(ctx->line, str, len) == 0); -} - -void git_parse_advance_line(git_parse_ctx *ctx); -void git_parse_advance_chars(git_parse_ctx *ctx, size_t char_cnt); -int git_parse_advance_expected( - git_parse_ctx *ctx, - const char *expected, - size_t expected_len); - -#define git_parse_advance_expected_str(ctx, str) \ - git_parse_advance_expected(ctx, str, strlen(str)) - -int git_parse_advance_ws(git_parse_ctx *ctx); -int git_parse_advance_nl(git_parse_ctx *ctx); -int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base); -int git_parse_advance_oid(git_oid *out, git_parse_ctx *ctx, git_oid_t oid_type); - -enum GIT_PARSE_PEEK_FLAGS { - GIT_PARSE_PEEK_SKIP_WHITESPACE = (1 << 0) -}; - -int git_parse_peek(char *out, git_parse_ctx *ctx, int flags); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/patch.c b/vendor/libgit2-sys/libgit2/src/libgit2/patch.c deleted file mode 100644 index a30546f..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/patch.c +++ /dev/null @@ -1,230 +0,0 @@ -/* -* Copyright (C) the libgit2 contributors. All rights reserved. -* -* This file is part of libgit2, distributed under the GNU GPL v2 with -* a Linking Exception. For full terms see the included COPYING file. -*/ - -#include "patch.h" - -#include "git2/patch.h" -#include "diff.h" - -int git_patch__invoke_callbacks( - git_patch *patch, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb line_cb, - void *payload) -{ - int error = 0; - uint32_t i, j; - - if (file_cb) - error = file_cb(patch->delta, 0, payload); - - if (error) - return error; - - if ((patch->delta->flags & GIT_DIFF_FLAG_BINARY) != 0) { - if (binary_cb) - error = binary_cb(patch->delta, &patch->binary, payload); - - return error; - } - - if (!hunk_cb && !line_cb) - return error; - - for (i = 0; !error && i < git_array_size(patch->hunks); ++i) { - git_patch_hunk *h = git_array_get(patch->hunks, i); - - if (hunk_cb) - error = hunk_cb(patch->delta, &h->hunk, payload); - - if (!line_cb) - continue; - - for (j = 0; !error && j < h->line_count; ++j) { - git_diff_line *l = - git_array_get(patch->lines, h->line_start + j); - - error = line_cb(patch->delta, &h->hunk, l, payload); - } - } - - return error; -} - -size_t git_patch_size( - git_patch *patch, - int include_context, - int include_hunk_headers, - int include_file_headers) -{ - size_t out; - - GIT_ASSERT_ARG(patch); - - out = patch->content_size; - - if (!include_context) - out -= patch->context_size; - - if (include_hunk_headers) - out += patch->header_size; - - if (include_file_headers) { - git_str file_header = GIT_STR_INIT; - - if (git_diff_delta__format_file_header( - &file_header, patch->delta, NULL, NULL, 0, true) < 0) - git_error_clear(); - else - out += git_str_len(&file_header); - - git_str_dispose(&file_header); - } - - return out; -} - -int git_patch_line_stats( - size_t *total_ctxt, - size_t *total_adds, - size_t *total_dels, - const git_patch *patch) -{ - size_t totals[3], idx; - - memset(totals, 0, sizeof(totals)); - - for (idx = 0; idx < git_array_size(patch->lines); ++idx) { - git_diff_line *line = git_array_get(patch->lines, idx); - if (!line) - continue; - - switch (line->origin) { - case GIT_DIFF_LINE_CONTEXT: totals[0]++; break; - case GIT_DIFF_LINE_ADDITION: totals[1]++; break; - case GIT_DIFF_LINE_DELETION: totals[2]++; break; - default: - /* diff --stat and --numstat don't count EOFNL marks because - * they will always be paired with a ADDITION or DELETION line. - */ - break; - } - } - - if (total_ctxt) - *total_ctxt = totals[0]; - if (total_adds) - *total_adds = totals[1]; - if (total_dels) - *total_dels = totals[2]; - - return 0; -} - -const git_diff_delta *git_patch_get_delta(const git_patch *patch) -{ - GIT_ASSERT_ARG_WITH_RETVAL(patch, NULL); - return patch->delta; -} - -size_t git_patch_num_hunks(const git_patch *patch) -{ - GIT_ASSERT_ARG(patch); - return git_array_size(patch->hunks); -} - -static int patch_error_outofrange(const char *thing) -{ - git_error_set(GIT_ERROR_INVALID, "patch %s index out of range", thing); - return GIT_ENOTFOUND; -} - -int git_patch_get_hunk( - const git_diff_hunk **out, - size_t *lines_in_hunk, - git_patch *patch, - size_t hunk_idx) -{ - git_patch_hunk *hunk; - GIT_ASSERT_ARG(patch); - - hunk = git_array_get(patch->hunks, hunk_idx); - - if (!hunk) { - if (out) *out = NULL; - if (lines_in_hunk) *lines_in_hunk = 0; - return patch_error_outofrange("hunk"); - } - - if (out) *out = &hunk->hunk; - if (lines_in_hunk) *lines_in_hunk = hunk->line_count; - return 0; -} - -int git_patch_num_lines_in_hunk(const git_patch *patch, size_t hunk_idx) -{ - git_patch_hunk *hunk; - GIT_ASSERT_ARG(patch); - - if (!(hunk = git_array_get(patch->hunks, hunk_idx))) - return patch_error_outofrange("hunk"); - return (int)hunk->line_count; -} - -int git_patch_get_line_in_hunk( - const git_diff_line **out, - git_patch *patch, - size_t hunk_idx, - size_t line_of_hunk) -{ - git_patch_hunk *hunk; - git_diff_line *line; - - GIT_ASSERT_ARG(patch); - - if (!(hunk = git_array_get(patch->hunks, hunk_idx))) { - if (out) *out = NULL; - return patch_error_outofrange("hunk"); - } - - if (line_of_hunk >= hunk->line_count || - !(line = git_array_get( - patch->lines, hunk->line_start + line_of_hunk))) { - if (out) *out = NULL; - return patch_error_outofrange("line"); - } - - if (out) *out = line; - return 0; -} - -git_repository *git_patch_owner(const git_patch *patch) -{ - return patch->repo; -} - -int git_patch_from_diff(git_patch **out, git_diff *diff, size_t idx) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diff); - GIT_ASSERT_ARG(diff->patch_fn); - return diff->patch_fn(out, diff, idx); -} - -static void git_patch__free(git_patch *patch) -{ - if (patch->free_fn) - patch->free_fn(patch); -} - -void git_patch_free(git_patch *patch) -{ - if (patch) - GIT_REFCOUNT_DEC(patch, git_patch__free); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/patch.h b/vendor/libgit2-sys/libgit2/src/libgit2/patch.h deleted file mode 100644 index 86328e8..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/patch.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* Copyright (C) the libgit2 contributors. All rights reserved. -* -* This file is part of libgit2, distributed under the GNU GPL v2 with -* a Linking Exception. For full terms see the included COPYING file. -*/ -#ifndef INCLUDE_patch_h__ -#define INCLUDE_patch_h__ - -#include "common.h" - -#include "git2/patch.h" -#include "array.h" - -/* cached information about a hunk in a patch */ -typedef struct git_patch_hunk { - git_diff_hunk hunk; - size_t line_start; - size_t line_count; -} git_patch_hunk; - -struct git_patch { - git_refcount rc; - - git_repository *repo; /* may be null */ - - git_diff_options diff_opts; - - git_diff_delta *delta; - git_diff_binary binary; - git_array_t(git_patch_hunk) hunks; - git_array_t(git_diff_line) lines; - - size_t header_size; - size_t content_size; - size_t context_size; - - void (*free_fn)(git_patch *patch); -}; - -extern int git_patch__invoke_callbacks( - git_patch *patch, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb line_cb, - void *payload); - -extern int git_patch_line_stats( - size_t *total_ctxt, - size_t *total_adds, - size_t *total_dels, - const git_patch *patch); - -/** Options for parsing patch files. */ -typedef struct { - /** - * The length of the prefix (in path segments) for the filenames. - * This prefix will be removed when looking for files. The default is 1. - */ - uint32_t prefix_len; - - /** - * The type of object IDs in the patch file. The default is - * `GIT_OID_DEFAULT`. - */ - git_oid_t oid_type; -} git_patch_options; - -#define GIT_PATCH_OPTIONS_INIT { 1, GIT_OID_DEFAULT } - -extern int git_patch__to_buf(git_str *out, git_patch *patch); -extern void git_patch_free(git_patch *patch); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/patch_generate.c b/vendor/libgit2-sys/libgit2/src/libgit2/patch_generate.c deleted file mode 100644 index 079bc53..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/patch_generate.c +++ /dev/null @@ -1,934 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "patch_generate.h" - -#include "git2/blob.h" -#include "diff.h" -#include "diff_generate.h" -#include "diff_file.h" -#include "diff_driver.h" -#include "diff_xdiff.h" -#include "delta.h" -#include "zstream.h" -#include "futils.h" - -static void diff_output_init( - git_patch_generated_output *, const git_diff_options *, git_diff_file_cb, - git_diff_binary_cb, git_diff_hunk_cb, git_diff_line_cb, void*); - -static void diff_output_to_patch( - git_patch_generated_output *, git_patch_generated *); - -static void patch_generated_free(git_patch *p) -{ - git_patch_generated *patch = (git_patch_generated *)p; - - git_array_clear(patch->base.lines); - git_array_clear(patch->base.hunks); - - git__free((char *)patch->base.binary.old_file.data); - git__free((char *)patch->base.binary.new_file.data); - - git_diff_file_content__clear(&patch->ofile); - git_diff_file_content__clear(&patch->nfile); - - git_diff_free(patch->diff); /* decrements refcount */ - patch->diff = NULL; - - git_pool_clear(&patch->flattened); - - git__free((char *)patch->base.diff_opts.old_prefix); - git__free((char *)patch->base.diff_opts.new_prefix); - - if (patch->flags & GIT_PATCH_GENERATED_ALLOCATED) - git__free(patch); -} - -static void patch_generated_update_binary(git_patch_generated *patch) -{ - if ((patch->base.delta->flags & DIFF_FLAGS_KNOWN_BINARY) != 0) - return; - - if ((patch->ofile.file->flags & GIT_DIFF_FLAG_BINARY) != 0 || - (patch->nfile.file->flags & GIT_DIFF_FLAG_BINARY) != 0) - patch->base.delta->flags |= GIT_DIFF_FLAG_BINARY; - - else if (patch->ofile.file->size > GIT_XDIFF_MAX_SIZE || - patch->nfile.file->size > GIT_XDIFF_MAX_SIZE) - patch->base.delta->flags |= GIT_DIFF_FLAG_BINARY; - - else if ((patch->ofile.file->flags & DIFF_FLAGS_NOT_BINARY) != 0 && - (patch->nfile.file->flags & DIFF_FLAGS_NOT_BINARY) != 0) - patch->base.delta->flags |= GIT_DIFF_FLAG_NOT_BINARY; -} - -static void patch_generated_init_common(git_patch_generated *patch) -{ - patch->base.free_fn = patch_generated_free; - - patch_generated_update_binary(patch); - - patch->flags |= GIT_PATCH_GENERATED_INITIALIZED; - - if (patch->diff) - git_diff_addref(patch->diff); -} - -static int patch_generated_normalize_options( - git_diff_options *out, - const git_diff_options *opts, - git_repository *repo) -{ - if (opts) { - GIT_ERROR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); - memcpy(out, opts, sizeof(git_diff_options)); - } else { - git_diff_options default_opts = GIT_DIFF_OPTIONS_INIT; - memcpy(out, &default_opts, sizeof(git_diff_options)); - } - - if (repo && opts && opts->oid_type && repo->oid_type != opts->oid_type) { - /* - * This limitation feels unnecessary - we should consider - * allowing users to generate diffs with a different object - * ID format than the repository. - */ - git_error_set(GIT_ERROR_INVALID, - "specified object ID type does not match repository object ID type"); - return -1; - } else if (repo) { - out->oid_type = repo->oid_type; - } else if (opts && opts->oid_type) { - out->oid_type = opts->oid_type; - } else { - out->oid_type = GIT_OID_DEFAULT; - } - - out->old_prefix = opts && opts->old_prefix ? - git__strdup(opts->old_prefix) : - git__strdup(DIFF_OLD_PREFIX_DEFAULT); - - out->new_prefix = opts && opts->new_prefix ? - git__strdup(opts->new_prefix) : - git__strdup(DIFF_NEW_PREFIX_DEFAULT); - - GIT_ERROR_CHECK_ALLOC(out->old_prefix); - GIT_ERROR_CHECK_ALLOC(out->new_prefix); - - return 0; -} - -static int patch_generated_init( - git_patch_generated *patch, git_diff *diff, size_t delta_index) -{ - int error = 0; - - memset(patch, 0, sizeof(*patch)); - - patch->diff = diff; - patch->base.repo = diff->repo; - patch->base.delta = git_vector_get(&diff->deltas, delta_index); - patch->delta_index = delta_index; - - if ((error = patch_generated_normalize_options( - &patch->base.diff_opts, &diff->opts, diff->repo)) < 0 || - (error = git_diff_file_content__init_from_diff( - &patch->ofile, diff, patch->base.delta, true)) < 0 || - (error = git_diff_file_content__init_from_diff( - &patch->nfile, diff, patch->base.delta, false)) < 0) - return error; - - patch_generated_init_common(patch); - - return 0; -} - -static int patch_generated_alloc_from_diff( - git_patch_generated **out, git_diff *diff, size_t delta_index) -{ - int error; - git_patch_generated *patch = git__calloc(1, sizeof(git_patch_generated)); - GIT_ERROR_CHECK_ALLOC(patch); - - if (!(error = patch_generated_init(patch, diff, delta_index))) { - patch->flags |= GIT_PATCH_GENERATED_ALLOCATED; - GIT_REFCOUNT_INC(&patch->base); - } else { - git__free(patch); - patch = NULL; - } - - *out = patch; - return error; -} - -GIT_INLINE(bool) should_skip_binary(git_patch_generated *patch, git_diff_file *file) -{ - if ((patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) != 0) - return false; - - return (file->flags & GIT_DIFF_FLAG_BINARY) != 0; -} - -static bool patch_generated_diffable(git_patch_generated *patch) -{ - size_t olen, nlen; - - if (patch->base.delta->status == GIT_DELTA_UNMODIFIED) - return false; - - /* if we've determined this to be binary (and we are not showing binary - * data) then we have skipped loading the map data. instead, query the - * file data itself. - */ - if ((patch->base.delta->flags & GIT_DIFF_FLAG_BINARY) != 0 && - (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) == 0) { - olen = (size_t)patch->ofile.file->size; - nlen = (size_t)patch->nfile.file->size; - } else { - olen = patch->ofile.map.len; - nlen = patch->nfile.map.len; - } - - /* if both sides are empty, files are identical */ - if (!olen && !nlen) - return false; - - /* otherwise, check the file sizes and the oid */ - return (olen != nlen || - !git_oid_equal(&patch->ofile.file->id, &patch->nfile.file->id)); -} - -static int patch_generated_load(git_patch_generated *patch, git_patch_generated_output *output) -{ - int error = 0; - bool incomplete_data; - - if ((patch->flags & GIT_PATCH_GENERATED_LOADED) != 0) - return 0; - - /* if no hunk and data callbacks and user doesn't care if data looks - * binary, then there is no need to actually load the data - */ - if ((patch->ofile.opts_flags & GIT_DIFF_SKIP_BINARY_CHECK) != 0 && - output && !output->binary_cb && !output->hunk_cb && !output->data_cb) - return 0; - - incomplete_data = - (((patch->ofile.flags & GIT_DIFF_FLAG__NO_DATA) != 0 || - (patch->ofile.file->flags & GIT_DIFF_FLAG_VALID_ID) != 0) && - ((patch->nfile.flags & GIT_DIFF_FLAG__NO_DATA) != 0 || - (patch->nfile.file->flags & GIT_DIFF_FLAG_VALID_ID) != 0)); - - if ((error = git_diff_file_content__load( - &patch->ofile, &patch->base.diff_opts)) < 0 || - (error = git_diff_file_content__load( - &patch->nfile, &patch->base.diff_opts)) < 0 || - should_skip_binary(patch, patch->nfile.file)) - goto cleanup; - - /* if previously missing an oid, and now that we have it the two sides - * are the same (and not submodules), update MODIFIED -> UNMODIFIED - */ - if (incomplete_data && - patch->ofile.file->mode == patch->nfile.file->mode && - patch->ofile.file->mode != GIT_FILEMODE_COMMIT && - git_oid_equal(&patch->ofile.file->id, &patch->nfile.file->id) && - patch->base.delta->status == GIT_DELTA_MODIFIED) /* not RENAMED/COPIED! */ - patch->base.delta->status = GIT_DELTA_UNMODIFIED; - -cleanup: - patch_generated_update_binary(patch); - - if (!error) { - if (patch_generated_diffable(patch)) - patch->flags |= GIT_PATCH_GENERATED_DIFFABLE; - - patch->flags |= GIT_PATCH_GENERATED_LOADED; - } - - return error; -} - -static int patch_generated_invoke_file_callback( - git_patch_generated *patch, git_patch_generated_output *output) -{ - float progress = patch->diff ? - ((float)patch->delta_index / patch->diff->deltas.length) : 1.0f; - - if (!output->file_cb) - return 0; - - return git_error_set_after_callback_function( - output->file_cb(patch->base.delta, progress, output->payload), - "git_patch"); -} - -static int create_binary( - git_diff_binary_t *out_type, - char **out_data, - size_t *out_datalen, - size_t *out_inflatedlen, - const char *a_data, - size_t a_datalen, - const char *b_data, - size_t b_datalen) -{ - git_str deflate = GIT_STR_INIT, delta = GIT_STR_INIT; - size_t delta_data_len = 0; - int error; - - /* The git_delta function accepts unsigned long only */ - if (!git__is_ulong(a_datalen) || !git__is_ulong(b_datalen)) - return GIT_EBUFS; - - if ((error = git_zstream_deflatebuf(&deflate, b_data, b_datalen)) < 0) - goto done; - - /* The git_delta function accepts unsigned long only */ - if (!git__is_ulong(deflate.size)) { - error = GIT_EBUFS; - goto done; - } - - if (a_datalen && b_datalen) { - void *delta_data; - - error = git_delta(&delta_data, &delta_data_len, - a_data, a_datalen, - b_data, b_datalen, - deflate.size); - - if (error == 0) { - error = git_zstream_deflatebuf( - &delta, delta_data, delta_data_len); - - git__free(delta_data); - } else if (error == GIT_EBUFS) { - error = 0; - } - - if (error < 0) - goto done; - } - - if (delta.size && delta.size < deflate.size) { - *out_type = GIT_DIFF_BINARY_DELTA; - *out_datalen = delta.size; - *out_data = git_str_detach(&delta); - *out_inflatedlen = delta_data_len; - } else { - *out_type = GIT_DIFF_BINARY_LITERAL; - *out_datalen = deflate.size; - *out_data = git_str_detach(&deflate); - *out_inflatedlen = b_datalen; - } - -done: - git_str_dispose(&deflate); - git_str_dispose(&delta); - - return error; -} - -static int diff_binary(git_patch_generated_output *output, git_patch_generated *patch) -{ - git_diff_binary binary = {0}; - const char *old_data = patch->ofile.map.data; - const char *new_data = patch->nfile.map.data; - size_t old_len = patch->ofile.map.len, - new_len = patch->nfile.map.len; - int error; - - /* Only load contents if the user actually wants to diff - * binary files. */ - if (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) { - binary.contains_data = 1; - - /* Create the old->new delta (as the "new" side of the patch), - * and the new->old delta (as the "old" side) - */ - if ((error = create_binary(&binary.old_file.type, - (char **)&binary.old_file.data, - &binary.old_file.datalen, - &binary.old_file.inflatedlen, - new_data, new_len, old_data, old_len)) < 0 || - (error = create_binary(&binary.new_file.type, - (char **)&binary.new_file.data, - &binary.new_file.datalen, - &binary.new_file.inflatedlen, - old_data, old_len, new_data, new_len)) < 0) - return error; - } - - error = git_error_set_after_callback_function( - output->binary_cb(patch->base.delta, &binary, output->payload), - "git_patch"); - - git__free((char *) binary.old_file.data); - git__free((char *) binary.new_file.data); - - return error; -} - -static int patch_generated_create( - git_patch_generated *patch, - git_patch_generated_output *output) -{ - int error = 0; - - if ((patch->flags & GIT_PATCH_GENERATED_DIFFED) != 0) - return 0; - - /* if we are not looking at the binary or text data, don't do the diff */ - if (!output->binary_cb && !output->hunk_cb && !output->data_cb) - return 0; - - if ((patch->flags & GIT_PATCH_GENERATED_LOADED) == 0 && - (error = patch_generated_load(patch, output)) < 0) - return error; - - if ((patch->flags & GIT_PATCH_GENERATED_DIFFABLE) == 0) - return 0; - - if ((patch->base.delta->flags & GIT_DIFF_FLAG_BINARY) != 0) { - if (output->binary_cb) - error = diff_binary(output, patch); - } - else { - if (output->diff_cb) - error = output->diff_cb(output, patch); - } - - patch->flags |= GIT_PATCH_GENERATED_DIFFED; - return error; -} - -static int diff_required(git_diff *diff, const char *action) -{ - if (diff) - return 0; - git_error_set(GIT_ERROR_INVALID, "must provide valid diff to %s", action); - return -1; -} - -typedef struct { - git_patch_generated patch; - git_diff_delta delta; - char paths[GIT_FLEX_ARRAY]; -} patch_generated_with_delta; - -static int diff_single_generate(patch_generated_with_delta *pd, git_xdiff_output *xo) -{ - int error = 0; - git_patch_generated *patch = &pd->patch; - bool has_old = ((patch->ofile.flags & GIT_DIFF_FLAG__NO_DATA) == 0); - bool has_new = ((patch->nfile.flags & GIT_DIFF_FLAG__NO_DATA) == 0); - - pd->delta.status = has_new ? - (has_old ? GIT_DELTA_MODIFIED : GIT_DELTA_ADDED) : - (has_old ? GIT_DELTA_DELETED : GIT_DELTA_UNTRACKED); - - if (git_oid_equal(&patch->nfile.file->id, &patch->ofile.file->id)) - pd->delta.status = GIT_DELTA_UNMODIFIED; - - patch->base.delta = &pd->delta; - - patch_generated_init_common(patch); - - if (pd->delta.status == GIT_DELTA_UNMODIFIED && - !(patch->ofile.opts_flags & GIT_DIFF_INCLUDE_UNMODIFIED)) { - - /* Even empty patches are flagged as binary, and even though - * there's no difference, we flag this as "containing data" - * (the data is known to be empty, as opposed to wholly unknown). - */ - if (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) - patch->base.binary.contains_data = 1; - - return error; - } - - error = patch_generated_invoke_file_callback(patch, (git_patch_generated_output *)xo); - - if (!error) - error = patch_generated_create(patch, (git_patch_generated_output *)xo); - - return error; -} - -static int patch_generated_from_sources( - patch_generated_with_delta *pd, - git_xdiff_output *xo, - git_diff_file_content_src *oldsrc, - git_diff_file_content_src *newsrc, - const git_diff_options *given_opts) -{ - int error = 0; - git_repository *repo = - oldsrc->blob ? git_blob_owner(oldsrc->blob) : - newsrc->blob ? git_blob_owner(newsrc->blob) : NULL; - git_diff_file *lfile = &pd->delta.old_file, *rfile = &pd->delta.new_file; - git_diff_file_content *ldata = &pd->patch.ofile, *rdata = &pd->patch.nfile; - git_diff_options *opts = &pd->patch.base.diff_opts; - - if ((error = patch_generated_normalize_options(opts, given_opts, repo)) < 0) - return error; - - if ((opts->flags & GIT_DIFF_REVERSE) != 0) { - void *tmp = lfile; lfile = rfile; rfile = tmp; - tmp = ldata; ldata = rdata; rdata = tmp; - } - - pd->patch.base.delta = &pd->delta; - - if (!oldsrc->as_path) { - if (newsrc->as_path) - oldsrc->as_path = newsrc->as_path; - else - oldsrc->as_path = newsrc->as_path = "file"; - } - else if (!newsrc->as_path) - newsrc->as_path = oldsrc->as_path; - - lfile->path = oldsrc->as_path; - rfile->path = newsrc->as_path; - - if ((error = git_diff_file_content__init_from_src( - ldata, repo, opts, oldsrc, lfile)) < 0 || - (error = git_diff_file_content__init_from_src( - rdata, repo, opts, newsrc, rfile)) < 0) - return error; - - return diff_single_generate(pd, xo); -} - -static int patch_generated_with_delta_alloc( - patch_generated_with_delta **out, - const char **old_path, - const char **new_path) -{ - patch_generated_with_delta *pd; - size_t old_len = *old_path ? strlen(*old_path) : 0; - size_t new_len = *new_path ? strlen(*new_path) : 0; - size_t alloc_len; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*pd), old_len); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, new_len); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); - - *out = pd = git__calloc(1, alloc_len); - GIT_ERROR_CHECK_ALLOC(pd); - - pd->patch.flags = GIT_PATCH_GENERATED_ALLOCATED; - - if (*old_path) { - memcpy(&pd->paths[0], *old_path, old_len); - *old_path = &pd->paths[0]; - } else if (*new_path) - *old_path = &pd->paths[old_len + 1]; - - if (*new_path) { - memcpy(&pd->paths[old_len + 1], *new_path, new_len); - *new_path = &pd->paths[old_len + 1]; - } else if (*old_path) - *new_path = &pd->paths[0]; - - return 0; -} - -static int diff_from_sources( - git_diff_file_content_src *oldsrc, - git_diff_file_content_src *newsrc, - const git_diff_options *opts, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb data_cb, - void *payload) -{ - int error = 0; - patch_generated_with_delta pd; - git_xdiff_output xo; - - memset(&xo, 0, sizeof(xo)); - diff_output_init( - &xo.output, opts, file_cb, binary_cb, hunk_cb, data_cb, payload); - git_xdiff_init(&xo, opts); - - memset(&pd, 0, sizeof(pd)); - - error = patch_generated_from_sources(&pd, &xo, oldsrc, newsrc, opts); - - git_patch_free(&pd.patch.base); - - return error; -} - -static int patch_from_sources( - git_patch **out, - git_diff_file_content_src *oldsrc, - git_diff_file_content_src *newsrc, - const git_diff_options *opts) -{ - int error = 0; - patch_generated_with_delta *pd; - git_xdiff_output xo; - - GIT_ASSERT_ARG(out); - *out = NULL; - - if ((error = patch_generated_with_delta_alloc( - &pd, &oldsrc->as_path, &newsrc->as_path)) < 0) - return error; - - memset(&xo, 0, sizeof(xo)); - diff_output_to_patch(&xo.output, &pd->patch); - git_xdiff_init(&xo, opts); - - if (!(error = patch_generated_from_sources(pd, &xo, oldsrc, newsrc, opts))) - *out = (git_patch *)pd; - else - git_patch_free((git_patch *)pd); - - return error; -} - -int git_diff_blobs( - const git_blob *old_blob, - const char *old_path, - const git_blob *new_blob, - const char *new_path, - const git_diff_options *opts, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb data_cb, - void *payload) -{ - git_diff_file_content_src osrc = - GIT_DIFF_FILE_CONTENT_SRC__BLOB(old_blob, old_path); - git_diff_file_content_src nsrc = - GIT_DIFF_FILE_CONTENT_SRC__BLOB(new_blob, new_path); - return diff_from_sources( - &osrc, &nsrc, opts, file_cb, binary_cb, hunk_cb, data_cb, payload); -} - -int git_patch_from_blobs( - git_patch **out, - const git_blob *old_blob, - const char *old_path, - const git_blob *new_blob, - const char *new_path, - const git_diff_options *opts) -{ - git_diff_file_content_src osrc = - GIT_DIFF_FILE_CONTENT_SRC__BLOB(old_blob, old_path); - git_diff_file_content_src nsrc = - GIT_DIFF_FILE_CONTENT_SRC__BLOB(new_blob, new_path); - return patch_from_sources(out, &osrc, &nsrc, opts); -} - -int git_diff_blob_to_buffer( - const git_blob *old_blob, - const char *old_path, - const char *buf, - size_t buflen, - const char *buf_path, - const git_diff_options *opts, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb data_cb, - void *payload) -{ - git_diff_file_content_src osrc = - GIT_DIFF_FILE_CONTENT_SRC__BLOB(old_blob, old_path); - git_diff_file_content_src nsrc = - GIT_DIFF_FILE_CONTENT_SRC__BUF(buf, buflen, buf_path); - return diff_from_sources( - &osrc, &nsrc, opts, file_cb, binary_cb, hunk_cb, data_cb, payload); -} - -int git_patch_from_blob_and_buffer( - git_patch **out, - const git_blob *old_blob, - const char *old_path, - const void *buf, - size_t buflen, - const char *buf_path, - const git_diff_options *opts) -{ - git_diff_file_content_src osrc = - GIT_DIFF_FILE_CONTENT_SRC__BLOB(old_blob, old_path); - git_diff_file_content_src nsrc = - GIT_DIFF_FILE_CONTENT_SRC__BUF(buf, buflen, buf_path); - return patch_from_sources(out, &osrc, &nsrc, opts); -} - -int git_diff_buffers( - const void *old_buf, - size_t old_len, - const char *old_path, - const void *new_buf, - size_t new_len, - const char *new_path, - const git_diff_options *opts, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb data_cb, - void *payload) -{ - git_diff_file_content_src osrc = - GIT_DIFF_FILE_CONTENT_SRC__BUF(old_buf, old_len, old_path); - git_diff_file_content_src nsrc = - GIT_DIFF_FILE_CONTENT_SRC__BUF(new_buf, new_len, new_path); - return diff_from_sources( - &osrc, &nsrc, opts, file_cb, binary_cb, hunk_cb, data_cb, payload); -} - -int git_patch_from_buffers( - git_patch **out, - const void *old_buf, - size_t old_len, - const char *old_path, - const void *new_buf, - size_t new_len, - const char *new_path, - const git_diff_options *opts) -{ - git_diff_file_content_src osrc = - GIT_DIFF_FILE_CONTENT_SRC__BUF(old_buf, old_len, old_path); - git_diff_file_content_src nsrc = - GIT_DIFF_FILE_CONTENT_SRC__BUF(new_buf, new_len, new_path); - return patch_from_sources(out, &osrc, &nsrc, opts); -} - -int git_patch_generated_from_diff( - git_patch **patch_ptr, git_diff *diff, size_t idx) -{ - int error = 0; - git_xdiff_output xo; - git_diff_delta *delta = NULL; - git_patch_generated *patch = NULL; - - if (patch_ptr) *patch_ptr = NULL; - - if (diff_required(diff, "git_patch_from_diff") < 0) - return -1; - - delta = git_vector_get(&diff->deltas, idx); - if (!delta) { - git_error_set(GIT_ERROR_INVALID, "index out of range for delta in diff"); - return GIT_ENOTFOUND; - } - - if (git_diff_delta__should_skip(&diff->opts, delta)) - return 0; - - /* don't load the patch data unless we need it for binary check */ - if (!patch_ptr && - ((delta->flags & DIFF_FLAGS_KNOWN_BINARY) != 0 || - (diff->opts.flags & GIT_DIFF_SKIP_BINARY_CHECK) != 0)) - return 0; - - if ((error = patch_generated_alloc_from_diff(&patch, diff, idx)) < 0) - return error; - - memset(&xo, 0, sizeof(xo)); - diff_output_to_patch(&xo.output, patch); - git_xdiff_init(&xo, &diff->opts); - - error = patch_generated_invoke_file_callback(patch, &xo.output); - - if (!error) - error = patch_generated_create(patch, &xo.output); - - if (!error) { - /* TODO: if cumulative diff size is < 0.5 total size, flatten patch */ - /* TODO: and unload the file content */ - } - - if (error || !patch_ptr) - git_patch_free(&patch->base); - else - *patch_ptr = &patch->base; - - return error; -} - -git_diff_driver *git_patch_generated_driver(git_patch_generated *patch) -{ - /* ofile driver is representative for whole patch */ - return patch->ofile.driver; -} - -int git_patch_generated_old_data( - char **ptr, long *len, git_patch_generated *patch) -{ - if (patch->ofile.map.len > LONG_MAX || - patch->ofile.map.len > GIT_XDIFF_MAX_SIZE) { - git_error_set(GIT_ERROR_INVALID, "files too large for diff"); - return -1; - } - - *ptr = patch->ofile.map.data; - *len = (long)patch->ofile.map.len; - - return 0; -} - -int git_patch_generated_new_data( - char **ptr, long *len, git_patch_generated *patch) -{ - if (patch->ofile.map.len > LONG_MAX || - patch->ofile.map.len > GIT_XDIFF_MAX_SIZE) { - git_error_set(GIT_ERROR_INVALID, "files too large for diff"); - return -1; - } - - *ptr = patch->nfile.map.data; - *len = (long)patch->nfile.map.len; - - return 0; -} - -static int patch_generated_file_cb( - const git_diff_delta *delta, - float progress, - void *payload) -{ - GIT_UNUSED(delta); GIT_UNUSED(progress); GIT_UNUSED(payload); - return 0; -} - -static int patch_generated_binary_cb( - const git_diff_delta *delta, - const git_diff_binary *binary, - void *payload) -{ - git_patch *patch = payload; - - GIT_UNUSED(delta); - - memcpy(&patch->binary, binary, sizeof(git_diff_binary)); - - if (binary->old_file.data) { - patch->binary.old_file.data = git__malloc(binary->old_file.datalen); - GIT_ERROR_CHECK_ALLOC(patch->binary.old_file.data); - - memcpy((char *)patch->binary.old_file.data, - binary->old_file.data, binary->old_file.datalen); - } - - if (binary->new_file.data) { - patch->binary.new_file.data = git__malloc(binary->new_file.datalen); - GIT_ERROR_CHECK_ALLOC(patch->binary.new_file.data); - - memcpy((char *)patch->binary.new_file.data, - binary->new_file.data, binary->new_file.datalen); - } - - return 0; -} - -static int git_patch_hunk_cb( - const git_diff_delta *delta, - const git_diff_hunk *hunk_, - void *payload) -{ - git_patch_generated *patch = payload; - git_patch_hunk *hunk; - - GIT_UNUSED(delta); - - hunk = git_array_alloc(patch->base.hunks); - GIT_ERROR_CHECK_ALLOC(hunk); - - memcpy(&hunk->hunk, hunk_, sizeof(hunk->hunk)); - - patch->base.header_size += hunk_->header_len; - - hunk->line_start = git_array_size(patch->base.lines); - hunk->line_count = 0; - - return 0; -} - -static int patch_generated_line_cb( - const git_diff_delta *delta, - const git_diff_hunk *hunk_, - const git_diff_line *line_, - void *payload) -{ - git_patch_generated *patch = payload; - git_patch_hunk *hunk; - git_diff_line *line; - - GIT_UNUSED(delta); - GIT_UNUSED(hunk_); - - hunk = git_array_last(patch->base.hunks); - GIT_ASSERT(hunk); /* programmer error if no hunk is available */ - - line = git_array_alloc(patch->base.lines); - GIT_ERROR_CHECK_ALLOC(line); - - memcpy(line, line_, sizeof(*line)); - - /* do some bookkeeping so we can provide old/new line numbers */ - - patch->base.content_size += line->content_len; - - if (line->origin == GIT_DIFF_LINE_ADDITION || - line->origin == GIT_DIFF_LINE_DELETION) - patch->base.content_size += 1; - else if (line->origin == GIT_DIFF_LINE_CONTEXT) { - patch->base.content_size += 1; - patch->base.context_size += line->content_len + 1; - } else if (line->origin == GIT_DIFF_LINE_CONTEXT_EOFNL) - patch->base.context_size += line->content_len; - - hunk->line_count++; - - return 0; -} - -static void diff_output_init( - git_patch_generated_output *out, - const git_diff_options *opts, - git_diff_file_cb file_cb, - git_diff_binary_cb binary_cb, - git_diff_hunk_cb hunk_cb, - git_diff_line_cb data_cb, - void *payload) -{ - GIT_UNUSED(opts); - - memset(out, 0, sizeof(*out)); - - out->file_cb = file_cb; - out->binary_cb = binary_cb; - out->hunk_cb = hunk_cb; - out->data_cb = data_cb; - out->payload = payload; -} - -static void diff_output_to_patch( - git_patch_generated_output *out, git_patch_generated *patch) -{ - diff_output_init( - out, - NULL, - patch_generated_file_cb, - patch_generated_binary_cb, - git_patch_hunk_cb, - patch_generated_line_cb, - patch); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/patch_generate.h b/vendor/libgit2-sys/libgit2/src/libgit2/patch_generate.h deleted file mode 100644 index 56e3e9d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/patch_generate.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_patch_generate_h__ -#define INCLUDE_patch_generate_h__ - -#include "common.h" - -#include "diff.h" -#include "diff_file.h" -#include "patch.h" - -enum { - GIT_PATCH_GENERATED_ALLOCATED = (1 << 0), - GIT_PATCH_GENERATED_INITIALIZED = (1 << 1), - GIT_PATCH_GENERATED_LOADED = (1 << 2), - /* the two sides are different */ - GIT_PATCH_GENERATED_DIFFABLE = (1 << 3), - /* the difference between the two sides has been computed */ - GIT_PATCH_GENERATED_DIFFED = (1 << 4), - GIT_PATCH_GENERATED_FLATTENED = (1 << 5) -}; - -struct git_patch_generated { - struct git_patch base; - - git_diff *diff; /* for refcount purposes, maybe NULL for blob diffs */ - size_t delta_index; - git_diff_file_content ofile; - git_diff_file_content nfile; - uint32_t flags; - git_pool flattened; -}; - -typedef struct git_patch_generated git_patch_generated; - -extern git_diff_driver *git_patch_generated_driver(git_patch_generated *); - -extern int git_patch_generated_old_data( - char **, long *, git_patch_generated *); -extern int git_patch_generated_new_data( - char **, long *, git_patch_generated *); -extern int git_patch_generated_from_diff( - git_patch **, git_diff *, size_t); - -typedef struct git_patch_generated_output git_patch_generated_output; - -struct git_patch_generated_output { - /* these callbacks are issued with the diff data */ - git_diff_file_cb file_cb; - git_diff_binary_cb binary_cb; - git_diff_hunk_cb hunk_cb; - git_diff_line_cb data_cb; - void *payload; - - /* this records the actual error in cases where it may be obscured */ - int error; - - /* this callback is used to do the diff and drive the other callbacks. - * see diff_xdiff.h for how to use this in practice for now. - */ - int (*diff_cb)(git_patch_generated_output *output, - git_patch_generated *patch); -}; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/patch_parse.c b/vendor/libgit2-sys/libgit2/src/libgit2/patch_parse.c deleted file mode 100644 index 70c9673..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/patch_parse.c +++ /dev/null @@ -1,1250 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - * Modified for native-diff, 2026-09-14: preserve rename/copy path whitespace. - */ - -#include "patch_parse.h" - -#include "git2/patch.h" -#include "patch.h" -#include "diff_parse.h" -#include "fs_path.h" - -typedef struct { - git_patch base; - - git_patch_parse_ctx *ctx; - - /* the paths from the `diff --git` header, these will be used if this is not - * a rename (and rename paths are specified) or if no `+++`/`---` line specify - * the paths. - */ - char *header_old_path, *header_new_path; - - /* renamed paths are precise and are not prefixed */ - char *rename_old_path, *rename_new_path; - - /* the paths given in `---` and `+++` lines */ - char *old_path, *new_path; - - /* the prefixes from the old/new paths */ - char *old_prefix, *new_prefix; -} git_patch_parsed; - -static int git_parse_err(const char *fmt, ...) GIT_FORMAT_PRINTF(1, 2); -static int git_parse_err(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - git_error_vset(GIT_ERROR_PATCH, fmt, ap); - va_end(ap); - - return -1; -} - -static size_t header_path_len(git_patch_parse_ctx *ctx) -{ - bool inquote = 0; - bool quoted = git_parse_ctx_contains_s(&ctx->parse_ctx, "\""); - size_t len; - - for (len = quoted; len < ctx->parse_ctx.line_len; len++) { - if (!quoted && git__isspace(ctx->parse_ctx.line[len])) - break; - else if (quoted && !inquote && ctx->parse_ctx.line[len] == '"') { - len++; - break; - } - - inquote = (!inquote && ctx->parse_ctx.line[len] == '\\'); - } - - return len; -} - -static int parse_header_path_buf(git_str *path, git_patch_parse_ctx *ctx, size_t path_len, bool trim) -{ - int error; - - if ((error = git_str_put(path, ctx->parse_ctx.line, path_len)) < 0) - return error; - - git_parse_advance_chars(&ctx->parse_ctx, path_len); - - if (trim) - git_str_rtrim(path); - - if (path->size > 0 && path->ptr[0] == '"' && - (error = git_str_unquote(path)) < 0) - return error; - - git_fs_path_squash_slashes(path); - - if (!path->size) - return git_parse_err("patch contains empty path at line %"PRIuZ, - ctx->parse_ctx.line_num); - - return 0; -} - -static int parse_header_path(char **out, git_patch_parse_ctx *ctx) -{ - git_str path = GIT_STR_INIT; - int error; - - if ((error = parse_header_path_buf(&path, ctx, header_path_len(ctx), true)) < 0) - goto out; - *out = git_str_detach(&path); - -out: - git_str_dispose(&path); - return error; -} - -static int parse_header_git_oldpath( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - git_str old_path = GIT_STR_INIT; - int error; - - if (patch->old_path) { - error = git_parse_err("patch contains duplicate old path at line %"PRIuZ, - ctx->parse_ctx.line_num); - goto out; - } - - if ((error = parse_header_path_buf(&old_path, ctx, ctx->parse_ctx.line_len - 1, true)) < 0) - goto out; - - patch->old_path = git_str_detach(&old_path); - -out: - git_str_dispose(&old_path); - return error; -} - -static int parse_header_git_newpath( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - git_str new_path = GIT_STR_INIT; - int error; - - if (patch->new_path) { - error = git_parse_err("patch contains duplicate new path at line %"PRIuZ, - ctx->parse_ctx.line_num); - goto out; - } - - if ((error = parse_header_path_buf(&new_path, ctx, ctx->parse_ctx.line_len - 1, true)) < 0) - goto out; - patch->new_path = git_str_detach(&new_path); - -out: - git_str_dispose(&new_path); - return error; -} - -static int parse_header_mode(uint16_t *mode, git_patch_parse_ctx *ctx) -{ - int64_t m; - - if ((git_parse_advance_digit(&m, &ctx->parse_ctx, 8)) < 0) - return git_parse_err("invalid file mode at line %"PRIuZ, ctx->parse_ctx.line_num); - - if (m > UINT16_MAX) - return -1; - - *mode = (uint16_t)m; - - return 0; -} - -static int parse_header_oid( - git_oid *oid, - uint16_t *oid_len, - git_patch_parse_ctx *ctx) -{ - size_t hexsize, len; - - hexsize = git_oid_hexsize(ctx->opts.oid_type); - - for (len = 0; - len < ctx->parse_ctx.line_len && len < hexsize; - len++) { - if (!git__isxdigit(ctx->parse_ctx.line[len])) - break; - } - - if (len < GIT_OID_MINPREFIXLEN || len > hexsize || - git_oid__fromstrn(oid, ctx->parse_ctx.line, len, ctx->opts.oid_type) < 0) - return git_parse_err("invalid hex formatted object id at line %"PRIuZ, - ctx->parse_ctx.line_num); - - git_parse_advance_chars(&ctx->parse_ctx, len); - - *oid_len = (uint16_t)len; - - return 0; -} - -static int parse_header_git_index( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - char c; - - if (parse_header_oid(&patch->base.delta->old_file.id, - &patch->base.delta->old_file.id_abbrev, ctx) < 0 || - git_parse_advance_expected_str(&ctx->parse_ctx, "..") < 0 || - parse_header_oid(&patch->base.delta->new_file.id, - &patch->base.delta->new_file.id_abbrev, ctx) < 0) - return -1; - - if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ' ') { - uint16_t mode = 0; - - git_parse_advance_chars(&ctx->parse_ctx, 1); - - if (parse_header_mode(&mode, ctx) < 0) - return -1; - - if (!patch->base.delta->new_file.mode) - patch->base.delta->new_file.mode = mode; - - if (!patch->base.delta->old_file.mode) - patch->base.delta->old_file.mode = mode; - } - - return 0; -} - -static int parse_header_git_oldmode( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - return parse_header_mode(&patch->base.delta->old_file.mode, ctx); -} - -static int parse_header_git_newmode( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - return parse_header_mode(&patch->base.delta->new_file.mode, ctx); -} - -static int parse_header_git_deletedfilemode( - git_patch_parsed *patch, - git_patch_parse_ctx *ctx) -{ - git__free((char *)patch->base.delta->new_file.path); - - patch->base.delta->new_file.path = NULL; - patch->base.delta->status = GIT_DELTA_DELETED; - patch->base.delta->nfiles = 1; - - return parse_header_mode(&patch->base.delta->old_file.mode, ctx); -} - -static int parse_header_git_newfilemode( - git_patch_parsed *patch, - git_patch_parse_ctx *ctx) -{ - git__free((char *)patch->base.delta->old_file.path); - - patch->base.delta->old_file.path = NULL; - patch->base.delta->status = GIT_DELTA_ADDED; - patch->base.delta->nfiles = 1; - - return parse_header_mode(&patch->base.delta->new_file.mode, ctx); -} - -static int parse_header_rename( - char **out, - git_patch_parse_ctx *ctx) -{ - git_str path = GIT_STR_INIT; - size_t len = ctx->parse_ctx.line_len - 1; - int error; - - if (git_parse_ctx_contains_s(&ctx->parse_ctx, "\"")) - len = header_path_len(ctx); - else if (len && ctx->parse_ctx.line[len - 1] == '\r') - len--; - - if ((error = parse_header_path_buf(&path, ctx, len, false)) < 0) - goto out; - - /* Note: the `rename from` and `rename to` lines include the literal - * filename. They do *not* include the prefix. (Who needs consistency?) - */ - *out = git_str_detach(&path); - -out: - git_str_dispose(&path); - return error; -} - -static int parse_header_renamefrom( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - patch->base.delta->status = GIT_DELTA_RENAMED; - return parse_header_rename(&patch->rename_old_path, ctx); -} - -static int parse_header_renameto( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - patch->base.delta->status = GIT_DELTA_RENAMED; - return parse_header_rename(&patch->rename_new_path, ctx); -} - -static int parse_header_copyfrom( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - patch->base.delta->status = GIT_DELTA_COPIED; - return parse_header_rename(&patch->rename_old_path, ctx); -} - -static int parse_header_copyto( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - patch->base.delta->status = GIT_DELTA_COPIED; - return parse_header_rename(&patch->rename_new_path, ctx); -} - -static int parse_header_percent(uint16_t *out, git_patch_parse_ctx *ctx) -{ - int64_t val; - - if (git_parse_advance_digit(&val, &ctx->parse_ctx, 10) < 0) - return -1; - - if (git_parse_advance_expected_str(&ctx->parse_ctx, "%") < 0) - return -1; - - if (val < 0 || val > 100) - return -1; - - *out = (uint16_t)val; - return 0; -} - -static int parse_header_similarity( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - if (parse_header_percent(&patch->base.delta->similarity, ctx) < 0) - return git_parse_err("invalid similarity percentage at line %"PRIuZ, - ctx->parse_ctx.line_num); - - return 0; -} - -static int parse_header_dissimilarity( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - uint16_t dissimilarity; - - if (parse_header_percent(&dissimilarity, ctx) < 0) - return git_parse_err("invalid similarity percentage at line %"PRIuZ, - ctx->parse_ctx.line_num); - - patch->base.delta->similarity = 100 - dissimilarity; - - return 0; -} - -static int parse_header_start(git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - if (parse_header_path(&patch->header_old_path, ctx) < 0) - return git_parse_err("corrupt old path in git diff header at line %"PRIuZ, - ctx->parse_ctx.line_num); - - if (git_parse_advance_ws(&ctx->parse_ctx) < 0 || - parse_header_path(&patch->header_new_path, ctx) < 0) - return git_parse_err("corrupt new path in git diff header at line %"PRIuZ, - ctx->parse_ctx.line_num); - - /* - * We cannot expect to be able to always parse paths correctly at this - * point. Due to the possibility of unquoted names, whitespaces in - * filenames and custom prefixes we have to allow that, though, and just - * proceed here. We then hope for the "---" and "+++" lines to fix that - * for us. - */ - if (!git_parse_ctx_contains(&ctx->parse_ctx, "\n", 1) && - !git_parse_ctx_contains(&ctx->parse_ctx, "\r\n", 2)) { - git_parse_advance_chars(&ctx->parse_ctx, ctx->parse_ctx.line_len - 1); - - git__free(patch->header_old_path); - patch->header_old_path = NULL; - git__free(patch->header_new_path); - patch->header_new_path = NULL; - } - - return 0; -} - -typedef enum { - STATE_START, - - STATE_DIFF, - STATE_FILEMODE, - STATE_MODE, - STATE_INDEX, - STATE_PATH, - - STATE_SIMILARITY, - STATE_RENAME, - STATE_COPY, - - STATE_END -} parse_header_state; - -typedef struct { - const char *str; - parse_header_state expected_state; - parse_header_state next_state; - int(*fn)(git_patch_parsed *, git_patch_parse_ctx *); -} parse_header_transition; - -static const parse_header_transition transitions[] = { - /* Start */ - { "diff --git " , STATE_START, STATE_DIFF, parse_header_start }, - - { "deleted file mode " , STATE_DIFF, STATE_FILEMODE, parse_header_git_deletedfilemode }, - { "new file mode " , STATE_DIFF, STATE_FILEMODE, parse_header_git_newfilemode }, - { "old mode " , STATE_DIFF, STATE_MODE, parse_header_git_oldmode }, - { "new mode " , STATE_MODE, STATE_END, parse_header_git_newmode }, - - { "index " , STATE_FILEMODE, STATE_INDEX, parse_header_git_index }, - { "index " , STATE_DIFF, STATE_INDEX, parse_header_git_index }, - { "index " , STATE_END, STATE_INDEX, parse_header_git_index }, - - { "--- " , STATE_DIFF, STATE_PATH, parse_header_git_oldpath }, - { "--- " , STATE_INDEX, STATE_PATH, parse_header_git_oldpath }, - { "--- " , STATE_FILEMODE, STATE_PATH, parse_header_git_oldpath }, - { "+++ " , STATE_PATH, STATE_END, parse_header_git_newpath }, - { "GIT binary patch" , STATE_INDEX, STATE_END, NULL }, - { "Binary files " , STATE_INDEX, STATE_END, NULL }, - - { "similarity index " , STATE_END, STATE_SIMILARITY, parse_header_similarity }, - { "similarity index " , STATE_DIFF, STATE_SIMILARITY, parse_header_similarity }, - { "dissimilarity index ", STATE_DIFF, STATE_SIMILARITY, parse_header_dissimilarity }, - { "rename from " , STATE_SIMILARITY, STATE_RENAME, parse_header_renamefrom }, - { "rename old " , STATE_SIMILARITY, STATE_RENAME, parse_header_renamefrom }, - { "copy from " , STATE_SIMILARITY, STATE_COPY, parse_header_copyfrom }, - { "rename to " , STATE_RENAME, STATE_END, parse_header_renameto }, - { "rename new " , STATE_RENAME, STATE_END, parse_header_renameto }, - { "copy to " , STATE_COPY, STATE_END, parse_header_copyto }, - - /* Next patch */ - { "diff --git " , STATE_END, 0, NULL }, - { "@@ -" , STATE_END, 0, NULL }, - { "-- " , STATE_INDEX, 0, NULL }, - { "-- " , STATE_END, 0, NULL }, -}; - -static int parse_header_git( - git_patch_parsed *patch, - git_patch_parse_ctx *ctx) -{ - size_t i; - int error = 0; - parse_header_state state = STATE_START; - - /* Parse remaining header lines */ - for (; ctx->parse_ctx.remain_len > 0; git_parse_advance_line(&ctx->parse_ctx)) { - bool found = false; - - if (ctx->parse_ctx.line_len == 0 || ctx->parse_ctx.line[ctx->parse_ctx.line_len - 1] != '\n') - break; - - for (i = 0; i < ARRAY_SIZE(transitions); i++) { - const parse_header_transition *transition = &transitions[i]; - size_t op_len = strlen(transition->str); - - if (transition->expected_state != state || - git__prefixcmp(ctx->parse_ctx.line, transition->str) != 0) - continue; - - state = transition->next_state; - - /* Do not advance if this is the patch separator */ - if (transition->fn == NULL) - goto done; - - git_parse_advance_chars(&ctx->parse_ctx, op_len); - - if ((error = transition->fn(patch, ctx)) < 0) - goto done; - - git_parse_advance_ws(&ctx->parse_ctx); - - if (git_parse_advance_expected_str(&ctx->parse_ctx, "\n") < 0 || - ctx->parse_ctx.line_len > 0) { - error = git_parse_err("trailing data at line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - - found = true; - break; - } - - if (!found) { - error = git_parse_err("invalid patch header at line %"PRIuZ, - ctx->parse_ctx.line_num); - goto done; - } - } - - if (state != STATE_END) { - error = git_parse_err("unexpected header line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - -done: - return error; -} - -static int parse_int(int *out, git_patch_parse_ctx *ctx) -{ - int64_t num; - - if (git_parse_advance_digit(&num, &ctx->parse_ctx, 10) < 0 || !git__is_int(num)) - return -1; - - *out = (int)num; - return 0; -} - -static int parse_hunk_header( - git_patch_hunk *hunk, - git_patch_parse_ctx *ctx) -{ - const char *header_start = ctx->parse_ctx.line; - char c; - - hunk->hunk.old_lines = 1; - hunk->hunk.new_lines = 1; - - if (git_parse_advance_expected_str(&ctx->parse_ctx, "@@ -") < 0 || - parse_int(&hunk->hunk.old_start, ctx) < 0) - goto fail; - - if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ',') { - if (git_parse_advance_expected_str(&ctx->parse_ctx, ",") < 0 || - parse_int(&hunk->hunk.old_lines, ctx) < 0) - goto fail; - } - - if (git_parse_advance_expected_str(&ctx->parse_ctx, " +") < 0 || - parse_int(&hunk->hunk.new_start, ctx) < 0) - goto fail; - - if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ',') { - if (git_parse_advance_expected_str(&ctx->parse_ctx, ",") < 0 || - parse_int(&hunk->hunk.new_lines, ctx) < 0) - goto fail; - } - - if (git_parse_advance_expected_str(&ctx->parse_ctx, " @@") < 0) - goto fail; - - git_parse_advance_line(&ctx->parse_ctx); - - if (!hunk->hunk.old_lines && !hunk->hunk.new_lines) - goto fail; - - hunk->hunk.header_len = ctx->parse_ctx.line - header_start; - if (hunk->hunk.header_len > (GIT_DIFF_HUNK_HEADER_SIZE - 1)) - return git_parse_err("oversized patch hunk header at line %"PRIuZ, - ctx->parse_ctx.line_num); - - memcpy(hunk->hunk.header, header_start, hunk->hunk.header_len); - hunk->hunk.header[hunk->hunk.header_len] = '\0'; - - return 0; - -fail: - git_error_set(GIT_ERROR_PATCH, "invalid patch hunk header at line %"PRIuZ, - ctx->parse_ctx.line_num); - return -1; -} - -static int eof_for_origin(int origin) { - if (origin == GIT_DIFF_LINE_ADDITION) - return GIT_DIFF_LINE_DEL_EOFNL; - if (origin == GIT_DIFF_LINE_DELETION) - return GIT_DIFF_LINE_ADD_EOFNL; - return GIT_DIFF_LINE_CONTEXT_EOFNL; -} - -static int parse_hunk_body( - git_patch_parsed *patch, - git_patch_hunk *hunk, - git_patch_parse_ctx *ctx) -{ - git_diff_line *line; - int error = 0; - - int oldlines = hunk->hunk.old_lines; - int newlines = hunk->hunk.new_lines; - int last_origin = 0; - - for (; - ctx->parse_ctx.remain_len > 1 && - (oldlines || newlines) && - !git_parse_ctx_contains_s(&ctx->parse_ctx, "@@ -"); - git_parse_advance_line(&ctx->parse_ctx)) { - - int old_lineno, new_lineno, origin, prefix = 1; - char c; - - if (git__add_int_overflow(&old_lineno, hunk->hunk.old_start, hunk->hunk.old_lines) || - git__sub_int_overflow(&old_lineno, old_lineno, oldlines) || - git__add_int_overflow(&new_lineno, hunk->hunk.new_start, hunk->hunk.new_lines) || - git__sub_int_overflow(&new_lineno, new_lineno, newlines)) { - error = git_parse_err("unrepresentable line count at line %"PRIuZ, - ctx->parse_ctx.line_num); - goto done; - } - - if (ctx->parse_ctx.line_len == 0 || ctx->parse_ctx.line[ctx->parse_ctx.line_len - 1] != '\n') { - error = git_parse_err("invalid patch instruction at line %"PRIuZ, - ctx->parse_ctx.line_num); - goto done; - } - - git_parse_peek(&c, &ctx->parse_ctx, 0); - - switch (c) { - case '\n': - prefix = 0; - /* fall through */ - - case ' ': - origin = GIT_DIFF_LINE_CONTEXT; - oldlines--; - newlines--; - break; - - case '-': - origin = GIT_DIFF_LINE_DELETION; - oldlines--; - new_lineno = -1; - break; - - case '+': - origin = GIT_DIFF_LINE_ADDITION; - newlines--; - old_lineno = -1; - break; - - case '\\': - /* - * If there are no oldlines left, then this is probably - * the "\ No newline at end of file" marker. Do not - * verify its format, as it may be localized. - */ - if (!oldlines) { - prefix = 0; - origin = eof_for_origin(last_origin); - old_lineno = -1; - new_lineno = -1; - break; - } - /* fall through */ - - default: - error = git_parse_err("invalid patch hunk at line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - - line = git_array_alloc(patch->base.lines); - GIT_ERROR_CHECK_ALLOC(line); - - memset(line, 0x0, sizeof(git_diff_line)); - - line->content_len = ctx->parse_ctx.line_len - prefix; - line->content = git__strndup(ctx->parse_ctx.line + prefix, line->content_len); - GIT_ERROR_CHECK_ALLOC(line->content); - line->content_offset = ctx->parse_ctx.content_len - ctx->parse_ctx.remain_len; - line->origin = origin; - line->num_lines = 1; - line->old_lineno = old_lineno; - line->new_lineno = new_lineno; - - hunk->line_count++; - - last_origin = origin; - } - - if (oldlines || newlines) { - error = git_parse_err( - "invalid patch hunk, expected %d old lines and %d new lines", - hunk->hunk.old_lines, hunk->hunk.new_lines); - goto done; - } - - /* - * Handle "\ No newline at end of file". Only expect the leading - * backslash, though, because the rest of the string could be - * localized. Because `diff` optimizes for the case where you - * want to apply the patch by hand. - */ - if (git_parse_ctx_contains_s(&ctx->parse_ctx, "\\ ") && - git_array_size(patch->base.lines) > 0) { - - line = git_array_get(patch->base.lines, git_array_size(patch->base.lines) - 1); - - if (line->content_len < 1) { - error = git_parse_err("last line has no trailing newline"); - goto done; - } - - line = git_array_alloc(patch->base.lines); - GIT_ERROR_CHECK_ALLOC(line); - - memset(line, 0x0, sizeof(git_diff_line)); - - line->content_len = ctx->parse_ctx.line_len; - line->content = git__strndup(ctx->parse_ctx.line, line->content_len); - GIT_ERROR_CHECK_ALLOC(line->content); - line->content_offset = ctx->parse_ctx.content_len - ctx->parse_ctx.remain_len; - line->origin = eof_for_origin(last_origin); - line->num_lines = 1; - line->old_lineno = -1; - line->new_lineno = -1; - - hunk->line_count++; - - git_parse_advance_line(&ctx->parse_ctx); - } - -done: - return error; -} - -static int parse_patch_header( - git_patch_parsed *patch, - git_patch_parse_ctx *ctx) -{ - int error = 0; - - for (; ctx->parse_ctx.remain_len > 0; git_parse_advance_line(&ctx->parse_ctx)) { - /* This line is too short to be a patch header. */ - if (ctx->parse_ctx.line_len < 6) - continue; - - /* This might be a hunk header without a patch header, provide a - * sensible error message. */ - if (git_parse_ctx_contains_s(&ctx->parse_ctx, "@@ -")) { - size_t line_num = ctx->parse_ctx.line_num; - git_patch_hunk hunk; - - /* If this cannot be parsed as a hunk header, it's just leading - * noise, continue. - */ - if (parse_hunk_header(&hunk, ctx) < 0) { - git_error_clear(); - continue; - } - - error = git_parse_err("invalid hunk header outside patch at line %"PRIuZ, - line_num); - goto done; - } - - /* This buffer is too short to contain a patch. */ - if (ctx->parse_ctx.remain_len < ctx->parse_ctx.line_len + 6) - break; - - /* A proper git patch */ - if (git_parse_ctx_contains_s(&ctx->parse_ctx, "diff --git ")) { - error = parse_header_git(patch, ctx); - goto done; - } - - error = 0; - continue; - } - - git_error_set(GIT_ERROR_PATCH, "no patch found"); - error = GIT_ENOTFOUND; - -done: - return error; -} - -static int parse_patch_binary_side( - git_diff_binary_file *binary, - git_patch_parse_ctx *ctx) -{ - git_diff_binary_t type = GIT_DIFF_BINARY_NONE; - git_str base85 = GIT_STR_INIT, decoded = GIT_STR_INIT; - int64_t len; - int error = 0; - - if (git_parse_ctx_contains_s(&ctx->parse_ctx, "literal ")) { - type = GIT_DIFF_BINARY_LITERAL; - git_parse_advance_chars(&ctx->parse_ctx, 8); - } else if (git_parse_ctx_contains_s(&ctx->parse_ctx, "delta ")) { - type = GIT_DIFF_BINARY_DELTA; - git_parse_advance_chars(&ctx->parse_ctx, 6); - } else { - error = git_parse_err( - "unknown binary delta type at line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - - if (git_parse_advance_digit(&len, &ctx->parse_ctx, 10) < 0 || - git_parse_advance_nl(&ctx->parse_ctx) < 0 || len < 0) { - error = git_parse_err("invalid binary size at line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - - while (ctx->parse_ctx.line_len) { - char c; - size_t encoded_len, decoded_len = 0, decoded_orig = decoded.size; - - git_parse_peek(&c, &ctx->parse_ctx, 0); - - if (c == '\n') - break; - else if (c >= 'A' && c <= 'Z') - decoded_len = c - 'A' + 1; - else if (c >= 'a' && c <= 'z') - decoded_len = c - 'a' + (('z' - 'a') + 1) + 1; - - if (!decoded_len) { - error = git_parse_err("invalid binary length at line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - - git_parse_advance_chars(&ctx->parse_ctx, 1); - - encoded_len = ((decoded_len / 4) + !!(decoded_len % 4)) * 5; - - if (!encoded_len || !ctx->parse_ctx.line_len || encoded_len > ctx->parse_ctx.line_len - 1) { - error = git_parse_err("truncated binary data at line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - - if ((error = git_str_decode_base85( - &decoded, ctx->parse_ctx.line, encoded_len, decoded_len)) < 0) - goto done; - - if (decoded.size - decoded_orig != decoded_len) { - error = git_parse_err("truncated binary data at line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - - git_parse_advance_chars(&ctx->parse_ctx, encoded_len); - - if (git_parse_advance_nl(&ctx->parse_ctx) < 0) { - error = git_parse_err("trailing data at line %"PRIuZ, ctx->parse_ctx.line_num); - goto done; - } - } - - binary->type = type; - binary->inflatedlen = (size_t)len; - binary->datalen = decoded.size; - binary->data = git_str_detach(&decoded); - -done: - git_str_dispose(&base85); - git_str_dispose(&decoded); - return error; -} - -static int parse_patch_binary( - git_patch_parsed *patch, - git_patch_parse_ctx *ctx) -{ - int error; - - if (git_parse_advance_expected_str(&ctx->parse_ctx, "GIT binary patch") < 0 || - git_parse_advance_nl(&ctx->parse_ctx) < 0) - return git_parse_err("corrupt git binary header at line %"PRIuZ, ctx->parse_ctx.line_num); - - /* parse old->new binary diff */ - if ((error = parse_patch_binary_side( - &patch->base.binary.new_file, ctx)) < 0) - return error; - - if (git_parse_advance_nl(&ctx->parse_ctx) < 0) - return git_parse_err("corrupt git binary separator at line %"PRIuZ, - ctx->parse_ctx.line_num); - - /* parse new->old binary diff */ - if ((error = parse_patch_binary_side( - &patch->base.binary.old_file, ctx)) < 0) - return error; - - if (git_parse_advance_nl(&ctx->parse_ctx) < 0) - return git_parse_err("corrupt git binary patch separator at line %"PRIuZ, - ctx->parse_ctx.line_num); - - patch->base.binary.contains_data = 1; - patch->base.delta->flags |= GIT_DIFF_FLAG_BINARY; - return 0; -} - -static int parse_patch_binary_nodata( - git_patch_parsed *patch, - git_patch_parse_ctx *ctx) -{ - const char *old = patch->old_path ? patch->old_path : patch->header_old_path; - const char *new = patch->new_path ? patch->new_path : patch->header_new_path; - - if (!old || !new) - return git_parse_err("corrupt binary data without paths at line %"PRIuZ, ctx->parse_ctx.line_num); - - if (patch->base.delta->status == GIT_DELTA_ADDED) - old = "/dev/null"; - else if (patch->base.delta->status == GIT_DELTA_DELETED) - new = "/dev/null"; - - if (git_parse_advance_expected_str(&ctx->parse_ctx, "Binary files ") < 0 || - git_parse_advance_expected_str(&ctx->parse_ctx, old) < 0 || - git_parse_advance_expected_str(&ctx->parse_ctx, " and ") < 0 || - git_parse_advance_expected_str(&ctx->parse_ctx, new) < 0 || - git_parse_advance_expected_str(&ctx->parse_ctx, " differ") < 0 || - git_parse_advance_nl(&ctx->parse_ctx) < 0) - return git_parse_err("corrupt git binary header at line %"PRIuZ, ctx->parse_ctx.line_num); - - patch->base.binary.contains_data = 0; - patch->base.delta->flags |= GIT_DIFF_FLAG_BINARY; - return 0; -} - -static int parse_patch_hunks( - git_patch_parsed *patch, - git_patch_parse_ctx *ctx) -{ - git_patch_hunk *hunk; - int error = 0; - - while (git_parse_ctx_contains_s(&ctx->parse_ctx, "@@ -")) { - hunk = git_array_alloc(patch->base.hunks); - GIT_ERROR_CHECK_ALLOC(hunk); - - memset(hunk, 0, sizeof(git_patch_hunk)); - - hunk->line_start = git_array_size(patch->base.lines); - hunk->line_count = 0; - - if ((error = parse_hunk_header(hunk, ctx)) < 0 || - (error = parse_hunk_body(patch, hunk, ctx)) < 0) - goto done; - } - - patch->base.delta->flags |= GIT_DIFF_FLAG_NOT_BINARY; - -done: - return error; -} - -static int parse_patch_body( - git_patch_parsed *patch, git_patch_parse_ctx *ctx) -{ - if (git_parse_ctx_contains_s(&ctx->parse_ctx, "GIT binary patch")) - return parse_patch_binary(patch, ctx); - else if (git_parse_ctx_contains_s(&ctx->parse_ctx, "Binary files ")) - return parse_patch_binary_nodata(patch, ctx); - else - return parse_patch_hunks(patch, ctx); -} - -static int check_header_names( - const char *one, - const char *two, - const char *old_or_new, - bool two_null) -{ - if (!one || !two) - return 0; - - if (two_null && strcmp(two, "/dev/null") != 0) - return git_parse_err("expected %s path of '/dev/null'", old_or_new); - - else if (!two_null && strcmp(one, two) != 0) - return git_parse_err("mismatched %s path names", old_or_new); - - return 0; -} - -static int check_prefix( - char **out, - size_t *out_len, - git_patch_parsed *patch, - const char *path_start) -{ - const char *path = path_start; - size_t prefix_len = patch->ctx->opts.prefix_len; - size_t remain_len = prefix_len; - - *out = NULL; - *out_len = 0; - - if (prefix_len == 0) - goto done; - - /* leading slashes do not count as part of the prefix in git apply */ - while (*path == '/') - path++; - - while (*path && remain_len) { - if (*path == '/') - remain_len--; - - path++; - } - - if (remain_len || !*path) - return git_parse_err( - "header filename does not contain %"PRIuZ" path components", - prefix_len); - -done: - *out_len = (path - path_start); - *out = git__strndup(path_start, *out_len); - - return (*out == NULL) ? -1 : 0; -} - -static int check_filenames(git_patch_parsed *patch) -{ - const char *prefixed_new, *prefixed_old; - size_t old_prefixlen = 0, new_prefixlen = 0; - bool added = (patch->base.delta->status == GIT_DELTA_ADDED); - bool deleted = (patch->base.delta->status == GIT_DELTA_DELETED); - - if (patch->old_path && !patch->new_path) - return git_parse_err("missing new path"); - - if (!patch->old_path && patch->new_path) - return git_parse_err("missing old path"); - - /* Ensure (non-renamed) paths match */ - if (check_header_names(patch->header_old_path, patch->old_path, "old", added) < 0 || - check_header_names(patch->header_new_path, patch->new_path, "new", deleted) < 0) - return -1; - - prefixed_old = (!added && patch->old_path) ? patch->old_path : patch->header_old_path; - prefixed_new = (!deleted && patch->new_path) ? patch->new_path : patch->header_new_path; - - if ((prefixed_old && check_prefix(&patch->old_prefix, &old_prefixlen, patch, prefixed_old) < 0) || - (prefixed_new && check_prefix(&patch->new_prefix, &new_prefixlen, patch, prefixed_new) < 0)) - return -1; - - /* Prefer the rename filenames as they are unambiguous and unprefixed */ - if (patch->rename_old_path) - patch->base.delta->old_file.path = patch->rename_old_path; - else if (prefixed_old) - patch->base.delta->old_file.path = prefixed_old + old_prefixlen; - else - patch->base.delta->old_file.path = NULL; - - if (patch->rename_new_path) - patch->base.delta->new_file.path = patch->rename_new_path; - else if (prefixed_new) - patch->base.delta->new_file.path = prefixed_new + new_prefixlen; - else - patch->base.delta->new_file.path = NULL; - - if (!patch->base.delta->old_file.path && - !patch->base.delta->new_file.path) - return git_parse_err("git diff header lacks old / new paths"); - - return 0; -} - -static int check_patch(git_patch_parsed *patch) -{ - git_diff_delta *delta = patch->base.delta; - - if (check_filenames(patch) < 0) - return -1; - - if (delta->old_file.path && - delta->status != GIT_DELTA_DELETED && - !delta->new_file.mode) - delta->new_file.mode = delta->old_file.mode; - - if (delta->status == GIT_DELTA_MODIFIED && - !(delta->flags & GIT_DIFF_FLAG_BINARY) && - delta->new_file.mode == delta->old_file.mode && - git_array_size(patch->base.hunks) == 0) - return git_parse_err("patch with no hunks"); - - if (delta->status == GIT_DELTA_ADDED) { - git_oid_clear(&delta->old_file.id, - patch->base.diff_opts.oid_type); - delta->old_file.id_abbrev = 0; - } - - if (delta->status == GIT_DELTA_DELETED) { - git_oid_clear(&delta->new_file.id, - patch->base.diff_opts.oid_type); - delta->new_file.id_abbrev = 0; - } - - return 0; -} - -git_patch_parse_ctx *git_patch_parse_ctx_init( - const char *content, - size_t content_len, - const git_patch_options *opts) -{ - git_patch_parse_ctx *ctx; - git_patch_options default_opts = GIT_PATCH_OPTIONS_INIT; - - if ((ctx = git__calloc(1, sizeof(git_patch_parse_ctx))) == NULL) - return NULL; - - if ((git_parse_ctx_init(&ctx->parse_ctx, content, content_len)) < 0) { - git__free(ctx); - return NULL; - } - - if (opts) - memcpy(&ctx->opts, opts, sizeof(git_patch_options)); - else - memcpy(&ctx->opts, &default_opts, sizeof(git_patch_options)); - - GIT_REFCOUNT_INC(ctx); - return ctx; -} - -static void patch_parse_ctx_free(git_patch_parse_ctx *ctx) -{ - if (!ctx) - return; - - git_parse_ctx_clear(&ctx->parse_ctx); - git__free(ctx); -} - -void git_patch_parse_ctx_free(git_patch_parse_ctx *ctx) -{ - GIT_REFCOUNT_DEC(ctx, patch_parse_ctx_free); -} - -int git_patch_parsed_from_diff(git_patch **out, git_diff *d, size_t idx) -{ - git_diff_parsed *diff = (git_diff_parsed *)d; - git_patch *p; - - if ((p = git_vector_get(&diff->patches, idx)) == NULL) - return -1; - - GIT_REFCOUNT_INC(p); - *out = p; - - return 0; -} - -static void patch_parsed__free(git_patch *p) -{ - git_patch_parsed *patch = (git_patch_parsed *)p; - git_diff_line *line; - size_t i; - - if (!patch) - return; - - git_patch_parse_ctx_free(patch->ctx); - - git__free((char *)patch->base.binary.old_file.data); - git__free((char *)patch->base.binary.new_file.data); - git_array_clear(patch->base.hunks); - git_array_foreach(patch->base.lines, i, line) - git__free((char *) line->content); - git_array_clear(patch->base.lines); - git__free(patch->base.delta); - - git__free(patch->old_prefix); - git__free(patch->new_prefix); - git__free(patch->header_old_path); - git__free(patch->header_new_path); - git__free(patch->rename_old_path); - git__free(patch->rename_new_path); - git__free(patch->old_path); - git__free(patch->new_path); - git__free(patch); -} - -int git_patch_parse( - git_patch **out, - git_patch_parse_ctx *ctx) -{ - git_patch_parsed *patch; - size_t start, used; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(ctx); - - *out = NULL; - - patch = git__calloc(1, sizeof(git_patch_parsed)); - GIT_ERROR_CHECK_ALLOC(patch); - - patch->ctx = ctx; - GIT_REFCOUNT_INC(patch->ctx); - - patch->base.free_fn = patch_parsed__free; - - patch->base.delta = git__calloc(1, sizeof(git_diff_delta)); - GIT_ERROR_CHECK_ALLOC(patch->base.delta); - - patch->base.delta->status = GIT_DELTA_MODIFIED; - patch->base.delta->nfiles = 2; - - patch->base.diff_opts.oid_type = ctx->opts.oid_type; - - start = ctx->parse_ctx.remain_len; - - if ((error = parse_patch_header(patch, ctx)) < 0 || - (error = parse_patch_body(patch, ctx)) < 0 || - (error = check_patch(patch)) < 0) - goto done; - - used = start - ctx->parse_ctx.remain_len; - ctx->parse_ctx.remain += used; - - patch->base.diff_opts.old_prefix = patch->old_prefix; - patch->base.diff_opts.new_prefix = patch->new_prefix; - patch->base.diff_opts.flags |= GIT_DIFF_SHOW_BINARY; - - GIT_REFCOUNT_INC(&patch->base); - *out = &patch->base; - -done: - if (error < 0) - patch_parsed__free(&patch->base); - - return error; -} - -int git_patch_from_buffer( - git_patch **out, - const char *content, - size_t content_len, - const git_patch_options *opts) -{ - git_patch_parse_ctx *ctx; - int error; - - ctx = git_patch_parse_ctx_init(content, content_len, opts); - GIT_ERROR_CHECK_ALLOC(ctx); - - error = git_patch_parse(out, ctx); - - git_patch_parse_ctx_free(ctx); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/patch_parse.h b/vendor/libgit2-sys/libgit2/src/libgit2/patch_parse.h deleted file mode 100644 index 140629d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/patch_parse.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_patch_parse_h__ -#define INCLUDE_patch_parse_h__ - -#include "common.h" - -#include "parse.h" -#include "patch.h" - -typedef struct { - git_refcount rc; - - git_patch_options opts; - - git_parse_ctx parse_ctx; -} git_patch_parse_ctx; - -extern git_patch_parse_ctx *git_patch_parse_ctx_init( - const char *content, - size_t content_len, - const git_patch_options *opts); - -extern void git_patch_parse_ctx_free(git_patch_parse_ctx *ctx); - -/** - * Create a patch for a single file from the contents of a patch buffer. - * - * @param out The patch to be created - * @param contents The contents of a patch file - * @param contents_len The length of the patch file - * @param opts The git_patch_options - * @return 0 on success, <0 on failure. - */ -extern int git_patch_from_buffer( - git_patch **out, - const char *contents, - size_t contents_len, - const git_patch_options *opts); - -extern int git_patch_parse( - git_patch **out, - git_patch_parse_ctx *ctx); - -extern int git_patch_parsed_from_diff(git_patch **, git_diff *, size_t); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/path.c b/vendor/libgit2-sys/libgit2/src/libgit2/path.c deleted file mode 100644 index 4b584fb..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/path.c +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "path.h" - -#include "repository.h" -#include "fs_path.h" -#include "utf8.h" - -typedef struct { - git_repository *repo; - uint16_t file_mode; - unsigned int flags; -} repository_path_validate_data; - -static int32_t next_hfs_char(const char **in, size_t *len) -{ - while (*len) { - uint32_t codepoint; - int cp_len = git_utf8_iterate(&codepoint, *in, *len); - if (cp_len < 0) - return -1; - - (*in) += cp_len; - (*len) -= cp_len; - - /* these code points are ignored completely */ - switch (codepoint) { - case 0x200c: /* ZERO WIDTH NON-JOINER */ - case 0x200d: /* ZERO WIDTH JOINER */ - case 0x200e: /* LEFT-TO-RIGHT MARK */ - case 0x200f: /* RIGHT-TO-LEFT MARK */ - case 0x202a: /* LEFT-TO-RIGHT EMBEDDING */ - case 0x202b: /* RIGHT-TO-LEFT EMBEDDING */ - case 0x202c: /* POP DIRECTIONAL FORMATTING */ - case 0x202d: /* LEFT-TO-RIGHT OVERRIDE */ - case 0x202e: /* RIGHT-TO-LEFT OVERRIDE */ - case 0x206a: /* INHIBIT SYMMETRIC SWAPPING */ - case 0x206b: /* ACTIVATE SYMMETRIC SWAPPING */ - case 0x206c: /* INHIBIT ARABIC FORM SHAPING */ - case 0x206d: /* ACTIVATE ARABIC FORM SHAPING */ - case 0x206e: /* NATIONAL DIGIT SHAPES */ - case 0x206f: /* NOMINAL DIGIT SHAPES */ - case 0xfeff: /* ZERO WIDTH NO-BREAK SPACE */ - continue; - } - - /* fold into lowercase -- this will only fold characters in - * the ASCII range, which is perfectly fine, because the - * git folder name can only be composed of ascii characters - */ - return git__tolower((int)codepoint); - } - return 0; /* NULL byte -- end of string */ -} - -static bool validate_dotgit_hfs_generic( - const char *path, - size_t len, - const char *needle, - size_t needle_len) -{ - size_t i; - char c; - - if (next_hfs_char(&path, &len) != '.') - return true; - - for (i = 0; i < needle_len; i++) { - c = next_hfs_char(&path, &len); - if (c != needle[i]) - return true; - } - - if (next_hfs_char(&path, &len) != '\0') - return true; - - return false; -} - -static bool validate_dotgit_hfs(const char *path, size_t len) -{ - return validate_dotgit_hfs_generic(path, len, "git", CONST_STRLEN("git")); -} - -GIT_INLINE(bool) validate_dotgit_ntfs( - git_repository *repo, - const char *path, - size_t len) -{ - git_str *reserved = git_repository__reserved_names_win32; - size_t reserved_len = git_repository__reserved_names_win32_len; - size_t start = 0, i; - - if (repo) - git_repository__reserved_names(&reserved, &reserved_len, repo, true); - - for (i = 0; i < reserved_len; i++) { - git_str *r = &reserved[i]; - - if (len >= r->size && - strncasecmp(path, r->ptr, r->size) == 0) { - start = r->size; - break; - } - } - - if (!start) - return true; - - /* - * Reject paths that start with Windows-style directory separators - * (".git\") or NTFS alternate streams (".git:") and could be used - * to write to the ".git" directory on Windows platforms. - */ - if (path[start] == '\\' || path[start] == ':') - return false; - - /* Reject paths like '.git ' or '.git.' */ - for (i = start; i < len; i++) { - if (path[i] != ' ' && path[i] != '.') - return true; - } - - return false; -} - -/* - * Windows paths that end with spaces and/or dots are elided to the - * path without them for backward compatibility. That is to say - * that opening file "foo ", "foo." or even "foo . . ." will all - * map to a filename of "foo". This function identifies spaces and - * dots at the end of a filename, whether the proper end of the - * filename (end of string) or a colon (which would indicate a - * Windows alternate data stream.) - */ -GIT_INLINE(bool) ntfs_end_of_filename(const char *path) -{ - const char *c = path; - - for (;; c++) { - if (*c == '\0' || *c == ':') - return true; - if (*c != ' ' && *c != '.') - return false; - } - - return true; -} - -GIT_INLINE(bool) validate_dotgit_ntfs_generic( - const char *name, - size_t len, - const char *dotgit_name, - size_t dotgit_len, - const char *shortname_pfix) -{ - int i, saw_tilde; - - if (name[0] == '.' && len >= dotgit_len && - !strncasecmp(name + 1, dotgit_name, dotgit_len)) { - return !ntfs_end_of_filename(name + dotgit_len + 1); - } - - /* Detect the basic NTFS shortname with the first six chars */ - if (!strncasecmp(name, dotgit_name, 6) && name[6] == '~' && - name[7] >= '1' && name[7] <= '4') - return !ntfs_end_of_filename(name + 8); - - /* Catch fallback names */ - for (i = 0, saw_tilde = 0; i < 8; i++) { - if (name[i] == '\0') { - return true; - } else if (saw_tilde) { - if (name[i] < '0' || name[i] > '9') - return true; - } else if (name[i] == '~') { - if (name[i+1] < '1' || name[i+1] > '9') - return true; - saw_tilde = 1; - } else if (i >= 6) { - return true; - } else if ((unsigned char)name[i] > 127) { - return true; - } else if (git__tolower(name[i]) != shortname_pfix[i]) { - return true; - } - } - - return !ntfs_end_of_filename(name + i); -} - -/* - * Return the length of the common prefix between str and prefix, comparing them - * case-insensitively (must be ASCII to match). - */ -GIT_INLINE(size_t) common_prefix_icase(const char *str, size_t len, const char *prefix) -{ - size_t count = 0; - - while (len > 0 && git__tolower(*str) == git__tolower(*prefix)) { - count++; - str++; - prefix++; - len--; - } - - return count; -} - -static bool validate_repo_component( - const char *component, - size_t len, - void *payload) -{ - repository_path_validate_data *data = (repository_path_validate_data *)payload; - - if (data->flags & GIT_PATH_REJECT_DOT_GIT_HFS) { - if (!validate_dotgit_hfs(component, len)) - return false; - - if (S_ISLNK(data->file_mode) && - git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS)) - return false; - } - - if (data->flags & GIT_PATH_REJECT_DOT_GIT_NTFS) { - if (!validate_dotgit_ntfs(data->repo, component, len)) - return false; - - if (S_ISLNK(data->file_mode) && - git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS)) - return false; - } - - /* don't bother rerunning the `.git` test if we ran the HFS or NTFS - * specific tests, they would have already rejected `.git`. - */ - if ((data->flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 && - (data->flags & GIT_PATH_REJECT_DOT_GIT_NTFS) == 0 && - (data->flags & GIT_PATH_REJECT_DOT_GIT_LITERAL)) { - if (len >= 4 && - component[0] == '.' && - (component[1] == 'g' || component[1] == 'G') && - (component[2] == 'i' || component[2] == 'I') && - (component[3] == 't' || component[3] == 'T')) { - if (len == 4) - return false; - - if (S_ISLNK(data->file_mode) && - common_prefix_icase(component, len, ".gitmodules") == len) - return false; - } - } - - return true; -} - -GIT_INLINE(unsigned int) dotgit_flags( - git_repository *repo, - unsigned int flags) -{ - int protectHFS = 0, protectNTFS = 1; - int error = 0; - - flags |= GIT_PATH_REJECT_DOT_GIT_LITERAL; - -#ifdef __APPLE__ - protectHFS = 1; -#endif - - if (repo && !protectHFS) - error = git_repository__configmap_lookup(&protectHFS, repo, GIT_CONFIGMAP_PROTECTHFS); - if (!error && protectHFS) - flags |= GIT_PATH_REJECT_DOT_GIT_HFS; - - if (repo) - error = git_repository__configmap_lookup(&protectNTFS, repo, GIT_CONFIGMAP_PROTECTNTFS); - if (!error && protectNTFS) - flags |= GIT_PATH_REJECT_DOT_GIT_NTFS; - - return flags; -} - -GIT_INLINE(unsigned int) length_flags( - git_repository *repo, - unsigned int flags) -{ -#ifdef GIT_WIN32 - int allow = 0; - - if (repo && - git_repository__configmap_lookup(&allow, repo, GIT_CONFIGMAP_LONGPATHS) < 0) - allow = 0; - - if (allow) - flags &= ~GIT_FS_PATH_REJECT_LONG_PATHS; - -#else - GIT_UNUSED(repo); - flags &= ~GIT_FS_PATH_REJECT_LONG_PATHS; -#endif - - return flags; -} - -bool git_path_str_is_valid( - git_repository *repo, - const git_str *path, - uint16_t file_mode, - unsigned int flags) -{ - repository_path_validate_data data = {0}; - - /* Upgrade the ".git" checks based on platform */ - if ((flags & GIT_PATH_REJECT_DOT_GIT)) - flags = dotgit_flags(repo, flags); - - /* Update the length checks based on platform */ - if ((flags & GIT_FS_PATH_REJECT_LONG_PATHS)) - flags = length_flags(repo, flags); - - data.repo = repo; - data.file_mode = file_mode; - data.flags = flags; - - return git_fs_path_str_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data); -} - -static const struct { - const char *file; - const char *hash; - size_t filelen; -} gitfiles[] = { - { "gitignore", "gi250a", CONST_STRLEN("gitignore") }, - { "gitmodules", "gi7eba", CONST_STRLEN("gitmodules") }, - { "gitattributes", "gi7d29", CONST_STRLEN("gitattributes") } -}; - -extern int git_path_is_gitfile( - const char *path, - size_t pathlen, - git_path_gitfile gitfile, - git_path_fs fs) -{ - const char *file, *hash; - size_t filelen; - - if (!(gitfile >= GIT_PATH_GITFILE_GITIGNORE && gitfile < ARRAY_SIZE(gitfiles))) { - git_error_set(GIT_ERROR_OS, "invalid gitfile for path validation"); - return -1; - } - - file = gitfiles[gitfile].file; - filelen = gitfiles[gitfile].filelen; - hash = gitfiles[gitfile].hash; - - switch (fs) { - case GIT_PATH_FS_GENERIC: - return !validate_dotgit_ntfs_generic(path, pathlen, file, filelen, hash) || - !validate_dotgit_hfs_generic(path, pathlen, file, filelen); - case GIT_PATH_FS_NTFS: - return !validate_dotgit_ntfs_generic(path, pathlen, file, filelen, hash); - case GIT_PATH_FS_HFS: - return !validate_dotgit_hfs_generic(path, pathlen, file, filelen); - default: - git_error_set(GIT_ERROR_OS, "invalid filesystem for path validation"); - return -1; - } -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/path.h b/vendor/libgit2-sys/libgit2/src/libgit2/path.h deleted file mode 100644 index c4a2c42..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/path.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_path_h__ -#define INCLUDE_path_h__ - -#include "common.h" - -#include "fs_path.h" -#include - -#define GIT_PATH_REJECT_DOT_GIT (GIT_FS_PATH_REJECT_MAX << 1) -#define GIT_PATH_REJECT_DOT_GIT_LITERAL (GIT_FS_PATH_REJECT_MAX << 2) -#define GIT_PATH_REJECT_DOT_GIT_HFS (GIT_FS_PATH_REJECT_MAX << 3) -#define GIT_PATH_REJECT_DOT_GIT_NTFS (GIT_FS_PATH_REJECT_MAX << 4) - -/* Paths that should never be written into the working directory. */ -#define GIT_PATH_REJECT_WORKDIR_DEFAULTS \ - GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS | GIT_PATH_REJECT_DOT_GIT - -/* Paths that should never be written to the index. */ -#define GIT_PATH_REJECT_INDEX_DEFAULTS \ - GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT - -extern bool git_path_str_is_valid( - git_repository *repo, - const git_str *path, - uint16_t file_mode, - unsigned int flags); - -GIT_INLINE(bool) git_path_is_valid( - git_repository *repo, - const char *path, - uint16_t file_mode, - unsigned int flags) -{ - git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); - return git_path_str_is_valid(repo, &str, file_mode, flags); -} - -GIT_INLINE(int) git_path_validate_str_length( - git_repository *repo, - const git_str *path) -{ - if (!git_path_str_is_valid(repo, path, 0, GIT_FS_PATH_REJECT_LONG_PATHS)) { - if (path->size == SIZE_MAX) - git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path->ptr); - else - git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'", (int)path->size, path->ptr); - - return -1; - } - - return 0; -} - -GIT_INLINE(int) git_path_validate_length( - git_repository *repo, - const char *path) -{ - git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); - return git_path_validate_str_length(repo, &str); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/pathspec.c b/vendor/libgit2-sys/libgit2/src/libgit2/pathspec.c deleted file mode 100644 index 26684c0..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/pathspec.c +++ /dev/null @@ -1,722 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "pathspec.h" - -#include "git2/pathspec.h" -#include "git2/diff.h" -#include "attr_file.h" -#include "iterator.h" -#include "repository.h" -#include "index.h" -#include "bitvec.h" -#include "diff.h" -#include "wildmatch.h" - -/* what is the common non-wildcard prefix for all items in the pathspec */ -char *git_pathspec_prefix(const git_strarray *pathspec) -{ - git_str prefix = GIT_STR_INIT; - const char *scan; - - if (!pathspec || !pathspec->count || - git_str_common_prefix(&prefix, pathspec->strings, pathspec->count) < 0) - return NULL; - - /* diff prefix will only be leading non-wildcards */ - for (scan = prefix.ptr; *scan; ++scan) { - if (git__iswildcard(*scan) && - (scan == prefix.ptr || (*(scan - 1) != '\\'))) - break; - } - git_str_truncate(&prefix, scan - prefix.ptr); - - if (prefix.size <= 0) { - git_str_dispose(&prefix); - return NULL; - } - - git_str_unescape(&prefix); - - return git_str_detach(&prefix); -} - -/* is there anything in the spec that needs to be filtered on */ -bool git_pathspec_is_empty(const git_strarray *pathspec) -{ - size_t i; - - if (pathspec == NULL) - return true; - - for (i = 0; i < pathspec->count; ++i) { - const char *str = pathspec->strings[i]; - - if (str && str[0]) - return false; - } - - return true; -} - -/* build a vector of fnmatch patterns to evaluate efficiently */ -int git_pathspec__vinit( - git_vector *vspec, const git_strarray *strspec, git_pool *strpool) -{ - size_t i; - - memset(vspec, 0, sizeof(*vspec)); - - if (git_pathspec_is_empty(strspec)) - return 0; - - if (git_vector_init(vspec, strspec->count, NULL) < 0) - return -1; - - for (i = 0; i < strspec->count; ++i) { - int ret; - const char *pattern = strspec->strings[i]; - git_attr_fnmatch *match = git__calloc(1, sizeof(git_attr_fnmatch)); - if (!match) - return -1; - - match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG; - - ret = git_attr_fnmatch__parse(match, strpool, NULL, &pattern); - if (ret == GIT_ENOTFOUND) { - git__free(match); - continue; - } else if (ret < 0) { - git__free(match); - return ret; - } - - if (git_vector_insert(vspec, match) < 0) - return -1; - } - - return 0; -} - -/* free data from the pathspec vector */ -void git_pathspec__vfree(git_vector *vspec) -{ - git_vector_dispose_deep(vspec); -} - -struct pathspec_match_context { - int wildmatch_flags; - int (*strcomp)(const char *, const char *); - int (*strncomp)(const char *, const char *, size_t); -}; - -static void pathspec_match_context_init( - struct pathspec_match_context *ctxt, - bool disable_fnmatch, - bool casefold) -{ - if (disable_fnmatch) - ctxt->wildmatch_flags = -1; - else if (casefold) - ctxt->wildmatch_flags = WM_CASEFOLD; - else - ctxt->wildmatch_flags = 0; - - if (casefold) { - ctxt->strcomp = git__strcasecmp; - ctxt->strncomp = git__strncasecmp; - } else { - ctxt->strcomp = git__strcmp; - ctxt->strncomp = git__strncmp; - } -} - -static int pathspec_match_one( - const git_attr_fnmatch *match, - struct pathspec_match_context *ctxt, - const char *path) -{ - int result = (match->flags & GIT_ATTR_FNMATCH_MATCH_ALL) ? 0 : WM_NOMATCH; - - if (result == WM_NOMATCH) - result = ctxt->strcomp(match->pattern, path) ? WM_NOMATCH : 0; - - if (ctxt->wildmatch_flags >= 0 && result == WM_NOMATCH) - result = wildmatch(match->pattern, path, ctxt->wildmatch_flags); - - /* if we didn't match, look for exact dirname prefix match */ - if (result == WM_NOMATCH && - (match->flags & GIT_ATTR_FNMATCH_HASWILD) == 0 && - ctxt->strncomp(path, match->pattern, match->length) == 0 && - path[match->length] == '/') - result = 0; - - /* if we didn't match and this is a negative match, check for exact - * match of filename with leading '!' - */ - if (result == WM_NOMATCH && - (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) != 0 && - *path == '!' && - ctxt->strncomp(path + 1, match->pattern, match->length) == 0 && - (!path[match->length + 1] || path[match->length + 1] == '/')) - return 1; - - if (result == 0) - return (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) ? 0 : 1; - return -1; -} - -static int git_pathspec__match_at( - size_t *matched_at, - const git_vector *vspec, - struct pathspec_match_context *ctxt, - const char *path0, - const char *path1) -{ - int result = GIT_ENOTFOUND; - size_t i = 0; - const git_attr_fnmatch *match; - - git_vector_foreach(vspec, i, match) { - if (path0 && (result = pathspec_match_one(match, ctxt, path0)) >= 0) - break; - if (path1 && (result = pathspec_match_one(match, ctxt, path1)) >= 0) - break; - } - - *matched_at = i; - return result; -} - -/* match a path against the vectorized pathspec */ -bool git_pathspec__match( - const git_vector *vspec, - const char *path, - bool disable_fnmatch, - bool casefold, - const char **matched_pathspec, - size_t *matched_at) -{ - int result; - size_t pos; - struct pathspec_match_context ctxt; - - if (matched_pathspec) - *matched_pathspec = NULL; - if (matched_at) - *matched_at = GIT_PATHSPEC_NOMATCH; - - if (!vspec || !vspec->length) - return true; - - pathspec_match_context_init(&ctxt, disable_fnmatch, casefold); - - result = git_pathspec__match_at(&pos, vspec, &ctxt, path, NULL); - if (result >= 0) { - if (matched_pathspec) { - const git_attr_fnmatch *match = git_vector_get(vspec, pos); - *matched_pathspec = match->pattern; - } - - if (matched_at) - *matched_at = pos; - } - - return (result > 0); -} - - -int git_pathspec__init(git_pathspec *ps, const git_strarray *paths) -{ - int error = 0; - - memset(ps, 0, sizeof(*ps)); - - ps->prefix = git_pathspec_prefix(paths); - - if ((error = git_pool_init(&ps->pool, 1)) < 0 || - (error = git_pathspec__vinit(&ps->pathspec, paths, &ps->pool)) < 0) - git_pathspec__clear(ps); - - return error; -} - -void git_pathspec__clear(git_pathspec *ps) -{ - git__free(ps->prefix); - git_pathspec__vfree(&ps->pathspec); - git_pool_clear(&ps->pool); - memset(ps, 0, sizeof(*ps)); -} - -int git_pathspec_new(git_pathspec **out, const git_strarray *pathspec) -{ - int error = 0; - git_pathspec *ps = git__malloc(sizeof(git_pathspec)); - GIT_ERROR_CHECK_ALLOC(ps); - - if ((error = git_pathspec__init(ps, pathspec)) < 0) { - git__free(ps); - return error; - } - - GIT_REFCOUNT_INC(ps); - *out = ps; - return 0; -} - -static void pathspec_free(git_pathspec *ps) -{ - git_pathspec__clear(ps); - git__free(ps); -} - -void git_pathspec_free(git_pathspec *ps) -{ - if (!ps) - return; - GIT_REFCOUNT_DEC(ps, pathspec_free); -} - -int git_pathspec_matches_path( - const git_pathspec *ps, uint32_t flags, const char *path) -{ - bool no_fnmatch = (flags & GIT_PATHSPEC_NO_GLOB) != 0; - bool casefold = (flags & GIT_PATHSPEC_IGNORE_CASE) != 0; - - GIT_ASSERT_ARG(ps); - GIT_ASSERT_ARG(path); - - return (0 != git_pathspec__match( - &ps->pathspec, path, no_fnmatch, casefold, NULL, NULL)); -} - -static void pathspec_match_free(git_pathspec_match_list *m) -{ - if (!m) - return; - - git_pathspec_free(m->pathspec); - m->pathspec = NULL; - - git_array_clear(m->matches); - git_array_clear(m->failures); - git_pool_clear(&m->pool); - git__free(m); -} - -static git_pathspec_match_list *pathspec_match_alloc( - git_pathspec *ps, int datatype) -{ - git_pathspec_match_list *m = git__calloc(1, sizeof(git_pathspec_match_list)); - if (!m) - return NULL; - - if (git_pool_init(&m->pool, 1) < 0) - return NULL; - - /* need to keep reference to pathspec and increment refcount because - * failures array stores pointers to the pattern strings of the - * pathspec that had no matches - */ - GIT_REFCOUNT_INC(ps); - m->pathspec = ps; - m->datatype = datatype; - - return m; -} - -GIT_INLINE(size_t) pathspec_mark_pattern(git_bitvec *used, size_t pos) -{ - if (!git_bitvec_get(used, pos)) { - git_bitvec_set(used, pos, true); - return 1; - } - - return 0; -} - -static size_t pathspec_mark_remaining( - git_bitvec *used, - git_vector *patterns, - struct pathspec_match_context *ctxt, - size_t start, - const char *path0, - const char *path1) -{ - size_t count = 0; - - if (path1 == path0) - path1 = NULL; - - for (; start < patterns->length; ++start) { - const git_attr_fnmatch *pat = git_vector_get(patterns, start); - - if (git_bitvec_get(used, start)) - continue; - - if (path0 && pathspec_match_one(pat, ctxt, path0) > 0) - count += pathspec_mark_pattern(used, start); - else if (path1 && pathspec_match_one(pat, ctxt, path1) > 0) - count += pathspec_mark_pattern(used, start); - } - - return count; -} - -static int pathspec_build_failure_array( - git_pathspec_string_array_t *failures, - git_vector *patterns, - git_bitvec *used, - git_pool *pool) -{ - size_t pos; - char **failed; - const git_attr_fnmatch *pat; - - for (pos = 0; pos < patterns->length; ++pos) { - if (git_bitvec_get(used, pos)) - continue; - - if ((failed = git_array_alloc(*failures)) == NULL) - return -1; - - pat = git_vector_get(patterns, pos); - - if ((*failed = git_pool_strdup(pool, pat->pattern)) == NULL) - return -1; - } - - return 0; -} - -static int pathspec_match_from_iterator( - git_pathspec_match_list **out, - git_iterator *iter, - uint32_t flags, - git_pathspec *ps) -{ - int error = 0; - git_pathspec_match_list *m = NULL; - const git_index_entry *entry = NULL; - struct pathspec_match_context ctxt; - git_vector *patterns = &ps->pathspec; - bool find_failures = out && (flags & GIT_PATHSPEC_FIND_FAILURES) != 0; - bool failures_only = !out || (flags & GIT_PATHSPEC_FAILURES_ONLY) != 0; - size_t pos, used_ct = 0, found_files = 0; - git_index *index = NULL; - git_bitvec used_patterns; - char **file; - - if (git_bitvec_init(&used_patterns, patterns->length) < 0) - return -1; - - if (out) { - *out = m = pathspec_match_alloc(ps, PATHSPEC_DATATYPE_STRINGS); - GIT_ERROR_CHECK_ALLOC(m); - } - - if ((error = git_iterator_reset_range(iter, ps->prefix, ps->prefix)) < 0) - goto done; - - if (git_iterator_type(iter) == GIT_ITERATOR_WORKDIR && - (error = git_repository_index__weakptr( - &index, git_iterator_owner(iter))) < 0) - goto done; - - pathspec_match_context_init( - &ctxt, (flags & GIT_PATHSPEC_NO_GLOB) != 0, - git_iterator_ignore_case(iter)); - - while (!(error = git_iterator_advance(&entry, iter))) { - /* search for match with entry->path */ - int result = git_pathspec__match_at( - &pos, patterns, &ctxt, entry->path, NULL); - - /* no matches for this path */ - if (result < 0) - continue; - - /* if result was a negative pattern match, then don't list file */ - if (!result) { - used_ct += pathspec_mark_pattern(&used_patterns, pos); - continue; - } - - /* check if path is ignored and untracked */ - if (index != NULL && - git_iterator_current_is_ignored(iter) && - git_index__find_pos(NULL, index, entry->path, 0, GIT_INDEX_STAGE_ANY) < 0) - continue; - - /* mark the matched pattern as used */ - used_ct += pathspec_mark_pattern(&used_patterns, pos); - ++found_files; - - /* if find_failures is on, check if any later patterns also match */ - if (find_failures && used_ct < patterns->length) - used_ct += pathspec_mark_remaining( - &used_patterns, patterns, &ctxt, pos + 1, entry->path, NULL); - - /* if only looking at failures, exit early or just continue */ - if (failures_only || !out) { - if (used_ct == patterns->length) - break; - continue; - } - - /* insert matched path into matches array */ - if ((file = (char **)git_array_alloc(m->matches)) == NULL || - (*file = git_pool_strdup(&m->pool, entry->path)) == NULL) { - error = -1; - goto done; - } - } - - if (error < 0 && error != GIT_ITEROVER) - goto done; - error = 0; - - /* insert patterns that had no matches into failures array */ - if (find_failures && used_ct < patterns->length && - (error = pathspec_build_failure_array( - &m->failures, patterns, &used_patterns, &m->pool)) < 0) - goto done; - - /* if every pattern failed to match, then we have failed */ - if ((flags & GIT_PATHSPEC_NO_MATCH_ERROR) != 0 && !found_files) { - git_error_set(GIT_ERROR_INVALID, "no matching files were found"); - error = GIT_ENOTFOUND; - } - -done: - git_bitvec_free(&used_patterns); - - if (error < 0) { - pathspec_match_free(m); - if (out) *out = NULL; - } - - return error; -} - -static git_iterator_flag_t pathspec_match_iter_flags(uint32_t flags) -{ - git_iterator_flag_t f = 0; - - if ((flags & GIT_PATHSPEC_IGNORE_CASE) != 0) - f |= GIT_ITERATOR_IGNORE_CASE; - else if ((flags & GIT_PATHSPEC_USE_CASE) != 0) - f |= GIT_ITERATOR_DONT_IGNORE_CASE; - - return f; -} - -int git_pathspec_match_workdir( - git_pathspec_match_list **out, - git_repository *repo, - uint32_t flags, - git_pathspec *ps) -{ - git_iterator *iter; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - int error = 0; - - GIT_ASSERT_ARG(repo); - - iter_opts.flags = pathspec_match_iter_flags(flags); - - if (!(error = git_iterator_for_workdir(&iter, repo, NULL, NULL, &iter_opts))) { - error = pathspec_match_from_iterator(out, iter, flags, ps); - git_iterator_free(iter); - } - - return error; -} - -int git_pathspec_match_index( - git_pathspec_match_list **out, - git_index *index, - uint32_t flags, - git_pathspec *ps) -{ - git_iterator *iter; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - int error = 0; - - GIT_ASSERT_ARG(index); - - iter_opts.flags = pathspec_match_iter_flags(flags); - - if (!(error = git_iterator_for_index(&iter, git_index_owner(index), index, &iter_opts))) { - error = pathspec_match_from_iterator(out, iter, flags, ps); - git_iterator_free(iter); - } - - return error; -} - -int git_pathspec_match_tree( - git_pathspec_match_list **out, - git_tree *tree, - uint32_t flags, - git_pathspec *ps) -{ - git_iterator *iter; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - int error = 0; - - GIT_ASSERT_ARG(tree); - - iter_opts.flags = pathspec_match_iter_flags(flags); - - if (!(error = git_iterator_for_tree(&iter, tree, &iter_opts))) { - error = pathspec_match_from_iterator(out, iter, flags, ps); - git_iterator_free(iter); - } - - return error; -} - -int git_pathspec_match_diff( - git_pathspec_match_list **out, - git_diff *diff, - uint32_t flags, - git_pathspec *ps) -{ - int error = 0; - git_pathspec_match_list *m = NULL; - struct pathspec_match_context ctxt; - git_vector *patterns = &ps->pathspec; - bool find_failures = out && (flags & GIT_PATHSPEC_FIND_FAILURES) != 0; - bool failures_only = !out || (flags & GIT_PATHSPEC_FAILURES_ONLY) != 0; - size_t i, pos, used_ct = 0, found_deltas = 0; - const git_diff_delta *delta, **match; - git_bitvec used_patterns; - - GIT_ASSERT_ARG(diff); - - if (git_bitvec_init(&used_patterns, patterns->length) < 0) - return -1; - - if (out) { - *out = m = pathspec_match_alloc(ps, PATHSPEC_DATATYPE_DIFF); - GIT_ERROR_CHECK_ALLOC(m); - } - - pathspec_match_context_init( - &ctxt, (flags & GIT_PATHSPEC_NO_GLOB) != 0, - git_diff_is_sorted_icase(diff)); - - git_vector_foreach(&diff->deltas, i, delta) { - /* search for match with delta */ - int result = git_pathspec__match_at( - &pos, patterns, &ctxt, delta->old_file.path, delta->new_file.path); - - /* no matches for this path */ - if (result < 0) - continue; - - /* mark the matched pattern as used */ - used_ct += pathspec_mark_pattern(&used_patterns, pos); - - /* if result was a negative pattern match, then don't list file */ - if (!result) - continue; - - ++found_deltas; - - /* if find_failures is on, check if any later patterns also match */ - if (find_failures && used_ct < patterns->length) - used_ct += pathspec_mark_remaining( - &used_patterns, patterns, &ctxt, pos + 1, - delta->old_file.path, delta->new_file.path); - - /* if only looking at failures, exit early or just continue */ - if (failures_only || !out) { - if (used_ct == patterns->length) - break; - continue; - } - - /* insert matched delta into matches array */ - if (!(match = (const git_diff_delta **)git_array_alloc(m->matches))) { - error = -1; - goto done; - } else { - *match = delta; - } - } - - /* insert patterns that had no matches into failures array */ - if (find_failures && used_ct < patterns->length && - (error = pathspec_build_failure_array( - &m->failures, patterns, &used_patterns, &m->pool)) < 0) - goto done; - - /* if every pattern failed to match, then we have failed */ - if ((flags & GIT_PATHSPEC_NO_MATCH_ERROR) != 0 && !found_deltas) { - git_error_set(GIT_ERROR_INVALID, "no matching deltas were found"); - error = GIT_ENOTFOUND; - } - -done: - git_bitvec_free(&used_patterns); - - if (error < 0) { - pathspec_match_free(m); - if (out) *out = NULL; - } - - return error; -} - -void git_pathspec_match_list_free(git_pathspec_match_list *m) -{ - if (m) - pathspec_match_free(m); -} - -size_t git_pathspec_match_list_entrycount( - const git_pathspec_match_list *m) -{ - return m ? git_array_size(m->matches) : 0; -} - -const char *git_pathspec_match_list_entry( - const git_pathspec_match_list *m, size_t pos) -{ - if (!m || m->datatype != PATHSPEC_DATATYPE_STRINGS || - !git_array_valid_index(m->matches, pos)) - return NULL; - - return *((const char **)git_array_get(m->matches, pos)); -} - -const git_diff_delta *git_pathspec_match_list_diff_entry( - const git_pathspec_match_list *m, size_t pos) -{ - if (!m || m->datatype != PATHSPEC_DATATYPE_DIFF || - !git_array_valid_index(m->matches, pos)) - return NULL; - - return *((const git_diff_delta **)git_array_get(m->matches, pos)); -} - -size_t git_pathspec_match_list_failed_entrycount( - const git_pathspec_match_list *m) -{ - return m ? git_array_size(m->failures) : 0; -} - -const char * git_pathspec_match_list_failed_entry( - const git_pathspec_match_list *m, size_t pos) -{ - char **entry = m ? git_array_get(m->failures, pos) : NULL; - - return entry ? *entry : NULL; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/pathspec.h b/vendor/libgit2-sys/libgit2/src/libgit2/pathspec.h deleted file mode 100644 index 0256cb9..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/pathspec.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_pathspec_h__ -#define INCLUDE_pathspec_h__ - -#include "common.h" - -#include "git2/pathspec.h" -#include "str.h" -#include "vector.h" -#include "pool.h" -#include "array.h" - -/* public compiled pathspec */ -struct git_pathspec { - git_refcount rc; - char *prefix; - git_vector pathspec; - git_pool pool; -}; - -enum { - PATHSPEC_DATATYPE_STRINGS = 0, - PATHSPEC_DATATYPE_DIFF = 1 -}; - -typedef git_array_t(char *) git_pathspec_string_array_t; - -/* public interface to pathspec matching */ -struct git_pathspec_match_list { - git_pathspec *pathspec; - git_array_t(void *) matches; - git_pathspec_string_array_t failures; - git_pool pool; - int datatype; -}; - -/* what is the common non-wildcard prefix for all items in the pathspec */ -extern char *git_pathspec_prefix(const git_strarray *pathspec); - -/* is there anything in the spec that needs to be filtered on */ -extern bool git_pathspec_is_empty(const git_strarray *pathspec); - -/* build a vector of fnmatch patterns to evaluate efficiently */ -extern int git_pathspec__vinit( - git_vector *vspec, const git_strarray *strspec, git_pool *strpool); - -/* free data from the pathspec vector */ -extern void git_pathspec__vfree(git_vector *vspec); - -#define GIT_PATHSPEC_NOMATCH ((size_t)-1) - -/* - * Match a path against the vectorized pathspec. - * The matched pathspec is passed back into the `matched_pathspec` parameter, - * unless it is passed as NULL by the caller. - */ -extern bool git_pathspec__match( - const git_vector *vspec, - const char *path, - bool disable_fnmatch, - bool casefold, - const char **matched_pathspec, - size_t *matched_at); - -/* easy pathspec setup */ - -extern int git_pathspec__init(git_pathspec *ps, const git_strarray *paths); - -extern void git_pathspec__clear(git_pathspec *ps); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/proxy.c b/vendor/libgit2-sys/libgit2/src/libgit2/proxy.c deleted file mode 100644 index ef91ad6..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/proxy.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "proxy.h" - -#include "git2/proxy.h" - -int git_proxy_options_init(git_proxy_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_proxy_options, GIT_PROXY_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_proxy_init_options(git_proxy_options *opts, unsigned int version) -{ - return git_proxy_options_init(opts, version); -} -#endif - -int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src) -{ - if (!src) { - git_proxy_options_init(tgt, GIT_PROXY_OPTIONS_VERSION); - return 0; - } - - memcpy(tgt, src, sizeof(git_proxy_options)); - if (src->url) { - tgt->url = git__strdup(src->url); - GIT_ERROR_CHECK_ALLOC(tgt->url); - } - - return 0; -} - -void git_proxy_options_dispose(git_proxy_options *opts) -{ - if (!opts) - return; - - git__free((char *) opts->url); - opts->url = NULL; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/proxy.h b/vendor/libgit2-sys/libgit2/src/libgit2/proxy.h deleted file mode 100644 index 7c0ab59..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/proxy.h +++ /dev/null @@ -1,17 +0,0 @@ -/* -* Copyright (C) the libgit2 contributors. All rights reserved. -* -* This file is part of libgit2, distributed under the GNU GPL v2 with -* a Linking Exception. For full terms see the included COPYING file. -*/ -#ifndef INCLUDE_proxy_h__ -#define INCLUDE_proxy_h__ - -#include "common.h" - -#include "git2/proxy.h" - -extern int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src); -extern void git_proxy_options_dispose(git_proxy_options *opts); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/push.c b/vendor/libgit2-sys/libgit2/src/libgit2/push.c deleted file mode 100644 index b0e8417..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/push.c +++ /dev/null @@ -1,619 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "push.h" - -#include "git2.h" - -#include "pack.h" -#include "pack-objects.h" -#include "remote.h" -#include "vector.h" -#include "tree.h" - -static int push_spec_rref_cmp(const void *a, const void *b) -{ - const push_spec *push_spec_a = a, *push_spec_b = b; - - return strcmp(push_spec_a->refspec.dst, push_spec_b->refspec.dst); -} - -static int push_status_ref_cmp(const void *a, const void *b) -{ - const push_status *push_status_a = a, *push_status_b = b; - - return strcmp(push_status_a->ref, push_status_b->ref); -} - -int git_push_new(git_push **out, git_remote *remote, const git_push_options *opts) -{ - git_push *p; - - *out = NULL; - - GIT_ERROR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options"); - - p = git__calloc(1, sizeof(*p)); - GIT_ERROR_CHECK_ALLOC(p); - - p->repo = remote->repo; - p->remote = remote; - p->report_status = 1; - p->pb_parallelism = opts ? opts->pb_parallelism : 1; - - if (opts) { - GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); - memcpy(&p->callbacks, &opts->callbacks, sizeof(git_remote_callbacks)); - } - - if (git_vector_init(&p->specs, 0, push_spec_rref_cmp) < 0) { - git__free(p); - return -1; - } - - if (git_vector_init(&p->status, 0, push_status_ref_cmp) < 0) { - git_vector_dispose(&p->specs); - git__free(p); - return -1; - } - - if (git_vector_init(&p->updates, 0, NULL) < 0) { - git_vector_dispose(&p->status); - git_vector_dispose(&p->specs); - git__free(p); - return -1; - } - - if (git_vector_init(&p->remote_push_options, 0, git__strcmp_cb) < 0) { - git_vector_dispose(&p->status); - git_vector_dispose(&p->specs); - git_vector_dispose(&p->updates); - git__free(p); - return -1; - } - - *out = p; - return 0; -} - -static void free_refspec(push_spec *spec) -{ - if (spec == NULL) - return; - - git_refspec__dispose(&spec->refspec); - git__free(spec); -} - -static int check_rref(char *ref) -{ - if (git__prefixcmp(ref, "refs/")) { - git_error_set(GIT_ERROR_INVALID, "not a valid reference '%s'", ref); - return -1; - } - - return 0; -} - -static int check_lref(git_push *push, char *ref) -{ - /* lref must be resolvable to an existing object */ - git_object *obj; - int error = git_revparse_single(&obj, push->repo, ref); - git_object_free(obj); - - if (!error) - return 0; - - if (error == GIT_ENOTFOUND) - git_error_set(GIT_ERROR_REFERENCE, - "src refspec '%s' does not match any existing object", ref); - else - git_error_set(GIT_ERROR_INVALID, "not a valid reference '%s'", ref); - return -1; -} - -static int parse_refspec(git_push *push, push_spec **spec, const char *str) -{ - push_spec *s; - - *spec = NULL; - - s = git__calloc(1, sizeof(*s)); - GIT_ERROR_CHECK_ALLOC(s); - - git_oid_clear(&s->loid, push->repo->oid_type); - git_oid_clear(&s->roid, push->repo->oid_type); - - if (git_refspec__parse(&s->refspec, str, false) < 0) { - git_error_set(GIT_ERROR_INVALID, "invalid refspec %s", str); - goto on_error; - } - - if (s->refspec.src && s->refspec.src[0] != '\0' && - check_lref(push, s->refspec.src) < 0) { - goto on_error; - } - - if (check_rref(s->refspec.dst) < 0) - goto on_error; - - *spec = s; - return 0; - -on_error: - free_refspec(s); - return -1; -} - -int git_push_add_refspec(git_push *push, const char *refspec) -{ - push_spec *spec; - - if (parse_refspec(push, &spec, refspec) < 0 || - git_vector_insert(&push->specs, spec) < 0) - return -1; - - return 0; -} - -int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks) -{ - git_str remote_ref_name = GIT_STR_INIT; - size_t i, j; - git_refspec *fetch_spec; - push_spec *push_spec = NULL; - git_reference *remote_ref; - push_status *status; - int error = 0; - - git_vector_foreach(&push->status, i, status) { - int fire_callback = 1; - - /* Skip unsuccessful updates which have non-empty messages */ - if (status->msg) - continue; - - /* Find the corresponding remote ref */ - fetch_spec = git_remote__matching_refspec(push->remote, status->ref); - if (!fetch_spec) - continue; - - /* Clear the buffer which can be dirty from previous iteration */ - git_str_clear(&remote_ref_name); - - if ((error = git_refspec__transform(&remote_ref_name, fetch_spec, status->ref)) < 0) - goto on_error; - - /* Find matching push ref spec */ - git_vector_foreach(&push->specs, j, push_spec) { - if (!strcmp(push_spec->refspec.dst, status->ref)) - break; - } - - /* Could not find the corresponding push ref spec for this push update */ - if (j == push->specs.length) - continue; - - /* Update the remote ref */ - if (git_oid_is_zero(&push_spec->loid)) { - error = git_reference_lookup(&remote_ref, push->remote->repo, git_str_cstr(&remote_ref_name)); - - if (error >= 0) { - error = git_reference_delete(remote_ref); - git_reference_free(remote_ref); - } - } else { - error = git_reference_create(NULL, push->remote->repo, - git_str_cstr(&remote_ref_name), &push_spec->loid, 1, - "update by push"); - } - - if (error < 0) { - if (error != GIT_ENOTFOUND) - goto on_error; - - git_error_clear(); - fire_callback = 0; - } - - if (!fire_callback || !callbacks) - continue; - - if (callbacks->update_refs) - error = callbacks->update_refs( - git_str_cstr(&remote_ref_name), - &push_spec->roid, &push_spec->loid, - &push_spec->refspec, callbacks->payload); -#ifndef GIT_DEPRECATE_HARD - else if (callbacks->update_tips) - error = callbacks->update_tips( - git_str_cstr(&remote_ref_name), - &push_spec->roid, &push_spec->loid, - callbacks->payload); -#endif - - if (error < 0) { - git_error_set_after_callback_function(error, "git_remote_push"); - goto on_error; - } - } - - error = 0; - -on_error: - git_str_dispose(&remote_ref_name); - return error; -} - -/** - * Insert all tags until we find a non-tag object, which is returned - * in `out`. - */ -static int enqueue_tag(git_object **out, git_push *push, git_oid *id) -{ - git_object *obj = NULL, *target = NULL; - int error; - - if ((error = git_object_lookup(&obj, push->repo, id, GIT_OBJECT_TAG)) < 0) - return error; - - while (git_object_type(obj) == GIT_OBJECT_TAG) { - if ((error = git_packbuilder_insert(push->pb, git_object_id(obj), NULL)) < 0) - break; - - if ((error = git_tag_target(&target, (git_tag *) obj)) < 0) - break; - - git_object_free(obj); - obj = target; - } - - if (error < 0) - git_object_free(obj); - else - *out = obj; - - return error; -} - -static int queue_objects(git_push *push) -{ - git_remote_head *head; - push_spec *spec; - git_revwalk *rw; - unsigned int i; - int error = -1; - - if (git_revwalk_new(&rw, push->repo) < 0) - return -1; - - git_revwalk_sorting(rw, GIT_SORT_TIME); - - git_vector_foreach(&push->specs, i, spec) { - git_object_t type; - git_oid id; - size_t size; - - if (git_oid_is_zero(&spec->loid)) - /* - * Delete reference on remote side; - * nothing to do here. - */ - continue; - - if (git_oid_equal(&spec->loid, &spec->roid)) - continue; /* up-to-date */ - - if ((error = git_odb_read_header(&size, &type, push->repo->_odb, &spec->loid)) < 0) - goto on_error; - - if (type == GIT_OBJECT_TAG) { - git_object *target; - - if ((error = enqueue_tag(&target, push, &spec->loid)) < 0) - goto on_error; - - type = git_object_type(target); - git_oid_cpy(&id, git_object_id(target)); - - git_object_free(target); - } else { - git_oid_cpy(&id, &spec->loid); - } - - if (type == GIT_OBJECT_COMMIT) - error = git_revwalk_push(rw, &id); - else - error = git_packbuilder_insert(push->pb, &id, NULL); - - if (error < 0) - goto on_error; - - if (!spec->refspec.force) { - git_oid base; - - if (git_oid_is_zero(&spec->roid)) - continue; - - if (!git_odb_exists(push->repo->_odb, &spec->roid)) { - git_error_set(GIT_ERROR_REFERENCE, - "cannot push because a reference that you are trying to update on the remote contains commits that are not present locally."); - error = GIT_ENONFASTFORWARD; - goto on_error; - } - - error = git_merge_base(&base, push->repo, - &spec->loid, &spec->roid); - - if (error == GIT_ENOTFOUND || - (!error && !git_oid_equal(&base, &spec->roid))) { - git_error_set(GIT_ERROR_REFERENCE, - "cannot push non-fastforwardable reference"); - error = GIT_ENONFASTFORWARD; - goto on_error; - } - - if (error < 0) - goto on_error; - } - } - - git_vector_foreach(&push->remote->refs, i, head) { - if (git_oid_is_zero(&head->oid)) - continue; - - if ((error = git_revwalk_hide(rw, &head->oid)) < 0 && - error != GIT_ENOTFOUND && error != GIT_EINVALIDSPEC && error != GIT_EPEEL) - goto on_error; - } - - error = git_packbuilder_insert_walk(push->pb, rw); - -on_error: - git_revwalk_free(rw); - return error; -} - -static int add_update(git_push *push, push_spec *spec) -{ - git_push_update *u = git__calloc(1, sizeof(git_push_update)); - GIT_ERROR_CHECK_ALLOC(u); - - u->src_refname = git__strdup(spec->refspec.src); - GIT_ERROR_CHECK_ALLOC(u->src_refname); - - u->dst_refname = git__strdup(spec->refspec.dst); - GIT_ERROR_CHECK_ALLOC(u->dst_refname); - - git_oid_cpy(&u->src, &spec->roid); - git_oid_cpy(&u->dst, &spec->loid); - - return git_vector_insert(&push->updates, u); -} - -static int calculate_work(git_push *push) -{ - git_remote_head *head; - push_spec *spec; - unsigned int i, j; - - /* Update local and remote oids*/ - - git_vector_foreach(&push->specs, i, spec) { - if (spec->refspec.src && spec->refspec.src[0]!= '\0') { - /* This is a create or update. Local ref must exist. */ - - git_object *obj; - int error = git_revparse_single(&obj, push->repo, spec->refspec.src); - - if (error < 0) { - git_object_free(obj); - git_error_set(GIT_ERROR_REFERENCE, "src refspec %s does not match any", spec->refspec.src); - return -1; - } - - git_oid_cpy(&spec->loid, git_object_id(obj)); - git_object_free(obj); - } - - /* Remote ref may or may not (e.g. during create) already exist. */ - git_vector_foreach(&push->remote->refs, j, head) { - if (!strcmp(spec->refspec.dst, head->name)) { - git_oid_cpy(&spec->roid, &head->oid); - break; - } - } - - if (add_update(push, spec) < 0) - return -1; - } - - return 0; -} - -static int do_push(git_push *push) -{ - int error = 0; - git_transport *transport = push->remote->transport; - git_remote_callbacks *callbacks = &push->callbacks; - - if (!transport->push) { - git_error_set(GIT_ERROR_NET, "remote transport doesn't support push"); - error = -1; - goto on_error; - } - - /* - * A pack-file MUST be sent if either create or update command - * is used, even if the server already has all the necessary - * objects. In this case the client MUST send an empty pack-file. - */ - - if ((error = git_packbuilder_new(&push->pb, push->repo)) < 0) - goto on_error; - - git_packbuilder_set_threads(push->pb, push->pb_parallelism); - - if (callbacks && callbacks->pack_progress) - if ((error = git_packbuilder_set_callbacks(push->pb, callbacks->pack_progress, callbacks->payload)) < 0) - goto on_error; - - if ((error = calculate_work(push)) < 0) - goto on_error; - - if (callbacks && callbacks->push_negotiation) { - git_error_clear(); - - error = callbacks->push_negotiation( - (const git_push_update **) push->updates.contents, - push->updates.length, callbacks->payload); - - if (error < 0) { - git_error_set_after_callback_function(error, - "push_negotiation"); - goto on_error; - } - - error = 0; - } - - if ((error = queue_objects(push)) < 0 || - (error = transport->push(transport, push)) < 0) - goto on_error; - -on_error: - git_packbuilder_free(push->pb); - return error; -} - -static int filter_refs(git_remote *remote) -{ - const git_remote_head **heads; - size_t heads_len, i; - - git_vector_clear(&remote->refs); - - if (git_remote_ls(&heads, &heads_len, remote) < 0) - return -1; - - for (i = 0; i < heads_len; i++) { - if (git_vector_insert(&remote->refs, (void *)heads[i]) < 0) - return -1; - } - - return 0; -} - -int git_push_finish(git_push *push) -{ - int error; - unsigned int remote_caps; - - if (!git_remote_connected(push->remote)) { - git_error_set(GIT_ERROR_NET, "remote is disconnected"); - return -1; - } - - if ((error = git_remote_capabilities(&remote_caps, push->remote)) < 0) { - git_error_set(GIT_ERROR_INVALID, "remote capabilities not available"); - return -1; - } - - if (git_vector_length(&push->remote_push_options) > 0 && - !(remote_caps & GIT_REMOTE_CAPABILITY_PUSH_OPTIONS)) { - git_error_set(GIT_ERROR_INVALID, "push-options not supported by remote"); - return -1; - } - - if ((error = filter_refs(push->remote)) < 0 || - (error = do_push(push)) < 0) - return error; - - if (!push->unpack_ok) { - error = -1; - git_error_set(GIT_ERROR_NET, "unpacking the sent packfile failed on the remote"); - } - - return error; -} - -int git_push_status_foreach(git_push *push, - int (*cb)(const char *ref, const char *msg, void *data), - void *data) -{ - push_status *status; - unsigned int i; - - git_vector_foreach(&push->status, i, status) { - int error = cb(status->ref, status->msg, data); - if (error) - return git_error_set_after_callback(error); - } - - return 0; -} - -void git_push_status_free(push_status *status) -{ - if (status == NULL) - return; - - git__free(status->msg); - git__free(status->ref); - git__free(status); -} - -void git_push_free(git_push *push) -{ - push_spec *spec; - push_status *status; - git_push_update *update; - char *option; - unsigned int i; - - if (push == NULL) - return; - - git_vector_foreach(&push->specs, i, spec) { - free_refspec(spec); - } - git_vector_dispose(&push->specs); - - git_vector_foreach(&push->status, i, status) { - git_push_status_free(status); - } - git_vector_dispose(&push->status); - - git_vector_foreach(&push->updates, i, update) { - git__free(update->src_refname); - git__free(update->dst_refname); - git__free(update); - } - git_vector_dispose(&push->updates); - - git_vector_foreach(&push->remote_push_options, i, option) { - git__free(option); - } - git_vector_dispose(&push->remote_push_options); - - git__free(push); -} - -int git_push_options_init(git_push_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_push_options, GIT_PUSH_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_push_init_options(git_push_options *opts, unsigned int version) -{ - return git_push_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/push.h b/vendor/libgit2-sys/libgit2/src/libgit2/push.h deleted file mode 100644 index 40a1823..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/push.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_push_h__ -#define INCLUDE_push_h__ - -#include "common.h" - -#include "git2.h" -#include "refspec.h" -#include "remote.h" - -typedef struct push_spec { - struct git_refspec refspec; - - git_oid loid; - git_oid roid; -} push_spec; - -typedef struct push_status { - bool ok; - - char *ref; - char *msg; -} push_status; - -struct git_push { - git_repository *repo; - git_packbuilder *pb; - git_remote *remote; - git_vector specs; - git_vector updates; - bool report_status; - git_vector remote_push_options; - - /* report-status */ - bool unpack_ok; - git_vector status; - - /* options */ - unsigned pb_parallelism; - git_remote_callbacks callbacks; -}; - -/** - * Free the given push status object - * - * @param status The push status object - */ -void git_push_status_free(push_status *status); - -/** - * Create a new push object - * - * @param out New push object - * @param remote Remote instance - * @param opts Push options or NULL - * - * @return 0 or an error code - */ -int git_push_new(git_push **out, git_remote *remote, const git_push_options *opts); - -/** - * Add a refspec to be pushed - * - * @param push The push object - * @param refspec Refspec string - * - * @return 0 or an error code - */ -int git_push_add_refspec(git_push *push, const char *refspec); - -/** - * Update remote tips after a push - * - * @param push The push object - * @param callbacks the callbacks to use for this connection - * - * @return 0 or an error code - */ -int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks); - -/** - * Perform the push - * - * This function will return an error in case of a protocol error or - * the server being unable to unpack the data we sent. - * - * The return value does not reflect whether the server accepted or - * refused any reference updates. Use `git_push_status_foreach()` in - * order to find out which updates were accepted or rejected. - * - * @param push The push object - * - * @return 0 or an error code - */ -int git_push_finish(git_push *push); - -/** - * Invoke callback `cb' on each status entry - * - * For each of the updated references, we receive a status report in the - * form of `ok refs/heads/master` or `ng refs/heads/master `. - * `msg != NULL` means the reference has not been updated for the given - * reason. - * - * Return a non-zero value from the callback to stop the loop. - * - * @param push The push object - * @param cb The callback to call on each object - * @param data The payload passed to the callback - * - * @return 0 on success, non-zero callback return value, or error code - */ -int git_push_status_foreach(git_push *push, - int (*cb)(const char *ref, const char *msg, void *data), - void *data); - -/** - * Free the given push object - * - * @param push The push object - */ -void git_push_free(git_push *push); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/reader.c b/vendor/libgit2-sys/libgit2/src/libgit2/reader.c deleted file mode 100644 index df2b280..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/reader.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "reader.h" - -#include "futils.h" -#include "blob.h" - -#include "git2/tree.h" -#include "git2/blob.h" -#include "git2/index.h" -#include "git2/repository.h" - -/* tree reader */ - -typedef struct { - git_reader reader; - git_tree *tree; -} tree_reader; - -static int tree_reader_read( - git_str *out, - git_oid *out_id, - git_filemode_t *out_filemode, - git_reader *_reader, - const char *filename) -{ - tree_reader *reader = (tree_reader *)_reader; - git_tree_entry *tree_entry = NULL; - git_blob *blob = NULL; - git_object_size_t blobsize; - int error; - - if ((error = git_tree_entry_bypath(&tree_entry, reader->tree, filename)) < 0 || - (error = git_blob_lookup(&blob, git_tree_owner(reader->tree), git_tree_entry_id(tree_entry))) < 0) - goto done; - - blobsize = git_blob_rawsize(blob); - GIT_ERROR_CHECK_BLOBSIZE(blobsize); - - if ((error = git_str_set(out, git_blob_rawcontent(blob), (size_t)blobsize)) < 0) - goto done; - - if (out_id) - git_oid_cpy(out_id, git_tree_entry_id(tree_entry)); - - if (out_filemode) - *out_filemode = git_tree_entry_filemode(tree_entry); - -done: - git_blob_free(blob); - git_tree_entry_free(tree_entry); - return error; -} - -int git_reader_for_tree(git_reader **out, git_tree *tree) -{ - tree_reader *reader; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(tree); - - reader = git__calloc(1, sizeof(tree_reader)); - GIT_ERROR_CHECK_ALLOC(reader); - - reader->reader.read = tree_reader_read; - reader->tree = tree; - - *out = (git_reader *)reader; - return 0; -} - -/* workdir reader */ - -typedef struct { - git_reader reader; - git_repository *repo; - git_index *index; -} workdir_reader; - -static int workdir_reader_read( - git_str *out, - git_oid *out_id, - git_filemode_t *out_filemode, - git_reader *_reader, - const char *filename) -{ - workdir_reader *reader = (workdir_reader *)_reader; - git_str path = GIT_STR_INIT; - struct stat st; - git_filemode_t filemode; - git_filter_list *filters = NULL; - const git_index_entry *idx_entry; - git_oid id; - int error; - - if ((error = git_repository_workdir_path(&path, reader->repo, filename)) < 0) - goto done; - - if ((error = p_lstat(path.ptr, &st)) < 0) { - if (error == -1 && errno == ENOENT) - error = GIT_ENOTFOUND; - - git_error_set(GIT_ERROR_OS, "could not stat '%s'", path.ptr); - goto done; - } - - filemode = git_futils_canonical_mode(st.st_mode); - - /* - * Patch application - for example - uses the filtered version of - * the working directory data to match git. So we will run the - * workdir -> ODB filter on the contents in this workdir reader. - */ - if ((error = git_filter_list_load(&filters, reader->repo, NULL, filename, - GIT_FILTER_TO_ODB, GIT_FILTER_DEFAULT)) < 0) - goto done; - - if ((error = git_filter_list__apply_to_file(out, - filters, reader->repo, path.ptr)) < 0) - goto done; - - if (out_id || reader->index) { - if ((error = git_odb__hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB, reader->repo->oid_type)) < 0) - goto done; - } - - if (reader->index) { - if (!(idx_entry = git_index_get_bypath(reader->index, filename, 0)) || - filemode != idx_entry->mode || - !git_oid_equal(&id, &idx_entry->id)) { - error = GIT_READER_MISMATCH; - goto done; - } - } - - if (out_id) - git_oid_cpy(out_id, &id); - - if (out_filemode) - *out_filemode = filemode; - -done: - git_filter_list_free(filters); - git_str_dispose(&path); - return error; -} - -int git_reader_for_workdir( - git_reader **out, - git_repository *repo, - bool validate_index) -{ - workdir_reader *reader; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - reader = git__calloc(1, sizeof(workdir_reader)); - GIT_ERROR_CHECK_ALLOC(reader); - - reader->reader.read = workdir_reader_read; - reader->repo = repo; - - if (validate_index && - (error = git_repository_index__weakptr(&reader->index, repo)) < 0) { - git__free(reader); - return error; - } - - *out = (git_reader *)reader; - return 0; -} - -/* index reader */ - -typedef struct { - git_reader reader; - git_repository *repo; - git_index *index; -} index_reader; - -static int index_reader_read( - git_str *out, - git_oid *out_id, - git_filemode_t *out_filemode, - git_reader *_reader, - const char *filename) -{ - index_reader *reader = (index_reader *)_reader; - const git_index_entry *entry; - git_blob *blob; - int error; - - if ((entry = git_index_get_bypath(reader->index, filename, 0)) == NULL) - return GIT_ENOTFOUND; - - if ((error = git_blob_lookup(&blob, reader->repo, &entry->id)) < 0) - goto done; - - if (out_id) - git_oid_cpy(out_id, &entry->id); - - if (out_filemode) - *out_filemode = entry->mode; - - error = git_blob__getbuf(out, blob); - -done: - git_blob_free(blob); - return error; -} - -int git_reader_for_index( - git_reader **out, - git_repository *repo, - git_index *index) -{ - index_reader *reader; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - reader = git__calloc(1, sizeof(index_reader)); - GIT_ERROR_CHECK_ALLOC(reader); - - reader->reader.read = index_reader_read; - reader->repo = repo; - - if (index) { - reader->index = index; - } else if ((error = git_repository_index__weakptr(&reader->index, repo)) < 0) { - git__free(reader); - return error; - } - - *out = (git_reader *)reader; - return 0; -} - -/* generic */ - -int git_reader_read( - git_str *out, - git_oid *out_id, - git_filemode_t *out_filemode, - git_reader *reader, - const char *filename) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(reader); - GIT_ASSERT_ARG(filename); - - return reader->read(out, out_id, out_filemode, reader, filename); -} - -void git_reader_free(git_reader *reader) -{ - if (!reader) - return; - - git__free(reader); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/reader.h b/vendor/libgit2-sys/libgit2/src/libgit2/reader.h deleted file mode 100644 index b58dc93..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/reader.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_reader_h__ -#define INCLUDE_reader_h__ - -#include "common.h" - -/* Returned when the workdir does not match the index */ -#define GIT_READER_MISMATCH 1 - -typedef struct git_reader git_reader; - -/* - * The `git_reader` structure is a generic interface for reading the - * contents of a file by its name, and implementations are provided - * for reading out of a tree, the index, and the working directory. - * - * Note that the reader implementation is meant to have a short - * lifecycle and does not increase the refcount of the object that - * it's reading. Callers should ensure that they do not use a - * reader after disposing the underlying object that it reads. - */ -struct git_reader { - int (*read)(git_str *out, git_oid *out_oid, git_filemode_t *mode, git_reader *reader, const char *filename); -}; - -/** - * Create a `git_reader` that will allow random access to the given - * tree. Paths requested via `git_reader_read` will be rooted at this - * tree, callers are not expected to recurse through tree lookups. Thus, - * you can request to read `/src/foo.c` and the tree provided to this - * function will be searched to find another tree named `src`, which - * will then be opened to find `foo.c`. - * - * @param out The reader for the given tree - * @param tree The tree object to read - * @return 0 on success, or an error code < 0 - */ -extern int git_reader_for_tree( - git_reader **out, - git_tree *tree); - -/** - * Create a `git_reader` that will allow random access to the given - * index, or the repository's index. - * - * @param out The reader for the given index - * @param repo The repository containing the index - * @param index The index to read, or NULL to use the repository's index - * @return 0 on success, or an error code < 0 - */ -extern int git_reader_for_index( - git_reader **out, - git_repository *repo, - git_index *index); - -/** - * Create a `git_reader` that will allow random access to the given - * repository's working directory. Note that the contents are read - * in repository format, meaning any workdir -> odb filters are - * applied. - * - * If `validate_index` is set to true, reads of files will hash the - * on-disk contents and ensure that the resulting object ID matches - * the repository's index. This ensures that the working directory - * is unmodified from the index contents. - * - * @param out The reader for the given working directory - * @param repo The repository containing the working directory - * @param validate_index If true, the working directory contents will - * be compared to the index contents during read to ensure that - * the working directory is unmodified. - * @return 0 on success, or an error code < 0 - */ -extern int git_reader_for_workdir( - git_reader **out, - git_repository *repo, - bool validate_index); - -/** - * Read the given filename from the reader and populate the given buffer - * with the contents and the given oid with the object ID. - * - * @param out The buffer to populate with the file contents - * @param out_id The oid to populate with the object ID - * @param reader The reader to read - * @param filename The filename to read from the reader - */ -extern int git_reader_read( - git_str *out, - git_oid *out_id, - git_filemode_t *out_filemode, - git_reader *reader, - const char *filename); - -/** - * Free the given reader and any associated objects. - * - * @param reader The reader to free - */ -extern void git_reader_free(git_reader *reader); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/rebase.c b/vendor/libgit2-sys/libgit2/src/libgit2/rebase.c deleted file mode 100644 index 77e442e..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/rebase.c +++ /dev/null @@ -1,1469 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "str.h" -#include "repository.h" -#include "posix.h" -#include "filebuf.h" -#include "commit.h" -#include "merge.h" -#include "array.h" -#include "config.h" -#include "annotated_commit.h" -#include "index.h" - -#include -#include -#include -#include -#include -#include -#include - -#define REBASE_APPLY_DIR "rebase-apply" -#define REBASE_MERGE_DIR "rebase-merge" - -#define HEAD_NAME_FILE "head-name" -#define ORIG_HEAD_FILE "orig-head" -#define HEAD_FILE "head" -#define ONTO_FILE "onto" -#define ONTO_NAME_FILE "onto_name" -#define QUIET_FILE "quiet" -#define INTERACTIVE_FILE "interactive" - -#define MSGNUM_FILE "msgnum" -#define END_FILE "end" -#define CMT_FILE_FMT "cmt.%" PRIuZ -#define CURRENT_FILE "current" -#define REWRITTEN_FILE "rewritten" - -#define ORIG_DETACHED_HEAD "detached HEAD" - -#define NOTES_DEFAULT_REF NULL - -#define REBASE_DIR_MODE 0777 -#define REBASE_FILE_MODE 0666 - -typedef enum { - GIT_REBASE_NONE = 0, - GIT_REBASE_APPLY = 1, - GIT_REBASE_MERGE = 2, - GIT_REBASE_INTERACTIVE = 3 -} git_rebase_t; - -struct git_rebase { - git_repository *repo; - - git_rebase_options options; - - git_rebase_t type; - char *state_path; - - /* Temporary buffer for paths within the state path. */ - git_str state_filename; - - unsigned int head_detached:1, - inmemory:1, - quiet:1, - started:1; - - git_array_t(git_rebase_operation) operations; - size_t current; - - /* Used by in-memory rebase */ - git_index *index; - git_commit *last_commit; - - /* Used by regular (not in-memory) merge-style rebase */ - git_oid orig_head_id; - char *orig_head_name; - - git_oid onto_id; - char *onto_name; -}; - -#define GIT_REBASE_STATE_INIT {0} - -static int rebase_state_type( - git_rebase_t *type_out, - char **path_out, - git_repository *repo) -{ - git_str path = GIT_STR_INIT; - git_str interactive_path = GIT_STR_INIT; - git_rebase_t type = GIT_REBASE_NONE; - - if (git_str_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0) - return -1; - - if (git_fs_path_isdir(git_str_cstr(&path))) { - type = GIT_REBASE_APPLY; - goto done; - } - - git_str_clear(&path); - if (git_str_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0) - return -1; - - if (git_fs_path_isdir(git_str_cstr(&path))) { - if (git_str_joinpath(&interactive_path, path.ptr, INTERACTIVE_FILE) < 0) - return -1; - - if (git_fs_path_isfile(interactive_path.ptr)) - type = GIT_REBASE_INTERACTIVE; - else - type = GIT_REBASE_MERGE; - - goto done; - } - -done: - *type_out = type; - - if (type != GIT_REBASE_NONE && path_out) - *path_out = git_str_detach(&path); - - git_str_dispose(&path); - git_str_dispose(&interactive_path); - - return 0; -} - -GIT_INLINE(int) rebase_readfile( - git_str *out, - git_rebase *rebase, - const char *filename) -{ - /* - * `rebase->state_filename` is a temporary buffer to avoid - * unnecessary allocations and copies of `rebase->state_path`. - * At the start and end of this function it always contains the - * contents of `rebase->state_path` itself. - */ - size_t state_path_len = rebase->state_filename.size; - int error; - - git_str_clear(out); - - if ((error = git_str_joinpath(&rebase->state_filename, rebase->state_filename.ptr, filename)) < 0 || - (error = git_futils_readbuffer(out, rebase->state_filename.ptr)) < 0) - goto done; - - git_str_rtrim(out); - -done: - git_str_truncate(&rebase->state_filename, state_path_len); - return error; -} - -GIT_INLINE(int) rebase_readint( - size_t *out, - git_str *asc_out, - git_rebase *rebase, - const char *filename) -{ - int32_t num; - const char *eol; - int error = 0; - - if ((error = rebase_readfile(asc_out, rebase, filename)) < 0) - return error; - - if (git__strntol32(&num, asc_out->ptr, asc_out->size, &eol, 10) < 0 || num < 0 || *eol) { - git_error_set(GIT_ERROR_REBASE, "the file '%s' contains an invalid numeric value", filename); - return -1; - } - - *out = (size_t) num; - - return 0; -} - -GIT_INLINE(int) rebase_readoid( - git_oid *out, - git_str *str_out, - git_rebase *rebase, - const char *filename) -{ - int error; - - if ((error = rebase_readfile(str_out, rebase, filename)) < 0) - return error; - - if (str_out->size != git_oid_hexsize(rebase->repo->oid_type) || - git_oid__fromstr(out, str_out->ptr, rebase->repo->oid_type) < 0) { - git_error_set(GIT_ERROR_REBASE, "the file '%s' contains an invalid object ID", filename); - return -1; - } - - return 0; -} - -static git_rebase_operation *rebase_operation_alloc( - git_rebase *rebase, - git_rebase_operation_t type, - git_oid *id, - const char *exec) -{ - git_rebase_operation *operation; - - GIT_ASSERT_WITH_RETVAL((type == GIT_REBASE_OPERATION_EXEC) == !id, NULL); - GIT_ASSERT_WITH_RETVAL((type == GIT_REBASE_OPERATION_EXEC) == !!exec, NULL); - - if ((operation = git_array_alloc(rebase->operations)) == NULL) - return NULL; - - operation->type = type; - git_oid_cpy((git_oid *)&operation->id, id); - operation->exec = exec; - - return operation; -} - -static int rebase_open_merge(git_rebase *rebase) -{ - git_str buf = GIT_STR_INIT, cmt = GIT_STR_INIT; - git_oid id; - git_rebase_operation *operation; - size_t i, msgnum = 0, end; - int error; - - /* Read 'msgnum' if it exists (otherwise, let msgnum = 0) */ - if ((error = rebase_readint(&msgnum, &buf, rebase, MSGNUM_FILE)) < 0 && - error != GIT_ENOTFOUND) - goto done; - - if (msgnum) { - rebase->started = 1; - rebase->current = msgnum - 1; - } - - /* Read 'end' */ - if ((error = rebase_readint(&end, &buf, rebase, END_FILE)) < 0) - goto done; - - /* Read 'current' if it exists */ - if ((error = rebase_readoid(&id, &buf, rebase, CURRENT_FILE)) < 0 && - error != GIT_ENOTFOUND) - goto done; - - /* Read cmt.* */ - git_array_init_to_size(rebase->operations, end); - GIT_ERROR_CHECK_ARRAY(rebase->operations); - - for (i = 0; i < end; i++) { - git_str_clear(&cmt); - - if ((error = git_str_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 || - (error = rebase_readoid(&id, &buf, rebase, cmt.ptr)) < 0) - goto done; - - operation = rebase_operation_alloc(rebase, GIT_REBASE_OPERATION_PICK, &id, NULL); - GIT_ERROR_CHECK_ALLOC(operation); - } - - /* Read 'onto_name' */ - if ((error = rebase_readfile(&buf, rebase, ONTO_NAME_FILE)) < 0) - goto done; - - rebase->onto_name = git_str_detach(&buf); - -done: - git_str_dispose(&cmt); - git_str_dispose(&buf); - - return error; -} - -static int rebase_alloc(git_rebase **out, const git_rebase_options *rebase_opts) -{ - git_rebase *rebase = git__calloc(1, sizeof(git_rebase)); - GIT_ERROR_CHECK_ALLOC(rebase); - - *out = NULL; - - if (rebase_opts) - memcpy(&rebase->options, rebase_opts, sizeof(git_rebase_options)); - else - git_rebase_options_init(&rebase->options, GIT_REBASE_OPTIONS_VERSION); - - if (rebase_opts && rebase_opts->rewrite_notes_ref) { - rebase->options.rewrite_notes_ref = git__strdup(rebase_opts->rewrite_notes_ref); - GIT_ERROR_CHECK_ALLOC(rebase->options.rewrite_notes_ref); - } - - *out = rebase; - - return 0; -} - -static int rebase_check_versions(const git_rebase_options *given_opts) -{ - GIT_ERROR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options"); - - if (given_opts) - GIT_ERROR_CHECK_VERSION(&given_opts->checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options"); - - return 0; -} - -int git_rebase_open( - git_rebase **out, - git_repository *repo, - const git_rebase_options *given_opts) -{ - git_rebase *rebase; - git_str orig_head_name = GIT_STR_INIT, - orig_head_id = GIT_STR_INIT, - onto_id = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(repo); - - if ((error = rebase_check_versions(given_opts)) < 0) - return error; - - if (rebase_alloc(&rebase, given_opts) < 0) - return -1; - - rebase->repo = repo; - - if ((error = rebase_state_type(&rebase->type, &rebase->state_path, repo)) < 0) - goto done; - - if (rebase->type == GIT_REBASE_NONE) { - git_error_set(GIT_ERROR_REBASE, "there is no rebase in progress"); - error = GIT_ENOTFOUND; - goto done; - } - - if ((error = git_str_puts(&rebase->state_filename, rebase->state_path)) < 0) - goto done; - - if ((error = rebase_readfile(&orig_head_name, rebase, HEAD_NAME_FILE)) < 0) - goto done; - - git_str_rtrim(&orig_head_name); - - if (strcmp(ORIG_DETACHED_HEAD, orig_head_name.ptr) == 0) - rebase->head_detached = 1; - - if ((error = rebase_readoid(&rebase->orig_head_id, &orig_head_id, rebase, ORIG_HEAD_FILE)) < 0) { - /* Previous versions of git.git used 'head' here; support that. */ - if (error == GIT_ENOTFOUND) - error = rebase_readoid(&rebase->orig_head_id, &orig_head_id, rebase, HEAD_FILE); - - if (error < 0) - goto done; - } - - if ((error = rebase_readoid(&rebase->onto_id, &onto_id, rebase, ONTO_FILE)) < 0) - goto done; - - if (!rebase->head_detached) - rebase->orig_head_name = git_str_detach(&orig_head_name); - - switch (rebase->type) { - case GIT_REBASE_INTERACTIVE: - git_error_set(GIT_ERROR_REBASE, "interactive rebase is not supported"); - error = -1; - break; - case GIT_REBASE_MERGE: - error = rebase_open_merge(rebase); - break; - case GIT_REBASE_APPLY: - git_error_set(GIT_ERROR_REBASE, "patch application rebase is not supported"); - error = -1; - break; - default: - abort(); - } - -done: - if (error == 0) - *out = rebase; - else - git_rebase_free(rebase); - - git_str_dispose(&orig_head_name); - git_str_dispose(&orig_head_id); - git_str_dispose(&onto_id); - return error; -} - -static int rebase_cleanup(git_rebase *rebase) -{ - if (!rebase || rebase->inmemory) - return 0; - - return git_fs_path_isdir(rebase->state_path) ? - git_futils_rmdir_r(rebase->state_path, NULL, GIT_RMDIR_REMOVE_FILES) : - 0; -} - -static int rebase_setupfile(git_rebase *rebase, const char *filename, int flags, const char *fmt, ...) -{ - git_str path = GIT_STR_INIT, - contents = GIT_STR_INIT; - va_list ap; - int error; - - va_start(ap, fmt); - git_str_vprintf(&contents, fmt, ap); - va_end(ap); - - if ((error = git_str_joinpath(&path, rebase->state_path, filename)) == 0) - error = git_futils_writebuffer(&contents, path.ptr, flags, REBASE_FILE_MODE); - - git_str_dispose(&path); - git_str_dispose(&contents); - - return error; -} - -static const char *rebase_onto_name(const git_annotated_commit *onto) -{ - if (onto->ref_name && git__strncmp(onto->ref_name, "refs/heads/", 11) == 0) - return onto->ref_name + 11; - else if (onto->ref_name) - return onto->ref_name; - else - return onto->id_str; -} - -static int rebase_setupfiles_merge(git_rebase *rebase) -{ - git_str commit_filename = GIT_STR_INIT; - char id_str[GIT_OID_MAX_HEXSIZE + 1]; - git_rebase_operation *operation; - size_t i; - int error = 0; - - if ((error = rebase_setupfile(rebase, END_FILE, 0, "%" PRIuZ "\n", git_array_size(rebase->operations))) < 0 || - (error = rebase_setupfile(rebase, ONTO_NAME_FILE, 0, "%s\n", rebase->onto_name)) < 0) - goto done; - - for (i = 0; i < git_array_size(rebase->operations); i++) { - operation = git_array_get(rebase->operations, i); - - git_str_clear(&commit_filename); - git_str_printf(&commit_filename, CMT_FILE_FMT, i+1); - - git_oid_tostr(id_str, GIT_OID_MAX_HEXSIZE + 1, &operation->id); - - if ((error = rebase_setupfile(rebase, commit_filename.ptr, 0, "%s\n", id_str)) < 0) - goto done; - } - -done: - git_str_dispose(&commit_filename); - return error; -} - -static int rebase_setupfiles(git_rebase *rebase) -{ - char onto[GIT_OID_MAX_HEXSIZE + 1], orig_head[GIT_OID_MAX_HEXSIZE + 1]; - const char *orig_head_name; - - git_oid_tostr(onto, GIT_OID_MAX_HEXSIZE + 1, &rebase->onto_id); - git_oid_tostr(orig_head, GIT_OID_MAX_HEXSIZE + 1, &rebase->orig_head_id); - - if (p_mkdir(rebase->state_path, REBASE_DIR_MODE) < 0) { - git_error_set(GIT_ERROR_OS, "failed to create rebase directory '%s'", rebase->state_path); - return -1; - } - - orig_head_name = rebase->head_detached ? ORIG_DETACHED_HEAD : - rebase->orig_head_name; - - if (git_repository__set_orig_head(rebase->repo, &rebase->orig_head_id) < 0 || - rebase_setupfile(rebase, HEAD_NAME_FILE, 0, "%s\n", orig_head_name) < 0 || - rebase_setupfile(rebase, ONTO_FILE, 0, "%s\n", onto) < 0 || - rebase_setupfile(rebase, ORIG_HEAD_FILE, 0, "%s\n", orig_head) < 0 || - rebase_setupfile(rebase, QUIET_FILE, 0, rebase->quiet ? "t\n" : "\n") < 0) - return -1; - - return rebase_setupfiles_merge(rebase); -} - -int git_rebase_options_init(git_rebase_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_rebase_options, GIT_REBASE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_rebase_init_options(git_rebase_options *opts, unsigned int version) -{ - return git_rebase_options_init(opts, version); -} -#endif - -static int rebase_ensure_not_in_progress(git_repository *repo) -{ - int error; - git_rebase_t type; - - if ((error = rebase_state_type(&type, NULL, repo)) < 0) - return error; - - if (type != GIT_REBASE_NONE) { - git_error_set(GIT_ERROR_REBASE, "there is an existing rebase in progress"); - return -1; - } - - return 0; -} - -static int rebase_ensure_not_dirty( - git_repository *repo, - bool check_index, - bool check_workdir, - int fail_with) -{ - git_tree *head = NULL; - git_index *index = NULL; - git_diff *diff = NULL; - int error = 0; - - if (check_index) { - if ((error = git_repository_head_tree(&head, repo)) < 0 || - (error = git_repository_index(&index, repo)) < 0 || - (error = git_diff_tree_to_index(&diff, repo, head, index, NULL)) < 0) - goto done; - - if (git_diff_num_deltas(diff) > 0) { - git_error_set(GIT_ERROR_REBASE, "uncommitted changes exist in index"); - error = fail_with; - goto done; - } - - git_diff_free(diff); - diff = NULL; - } - - if (check_workdir) { - git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; - diff_opts.ignore_submodules = GIT_SUBMODULE_IGNORE_UNTRACKED; - if ((error = git_diff_index_to_workdir(&diff, repo, index, &diff_opts)) < 0) - goto done; - - if (git_diff_num_deltas(diff) > 0) { - git_error_set(GIT_ERROR_REBASE, "unstaged changes exist in workdir"); - error = fail_with; - goto done; - } - } - -done: - git_diff_free(diff); - git_index_free(index); - git_tree_free(head); - - return error; -} - -static int rebase_init_operations( - git_rebase *rebase, - git_repository *repo, - const git_annotated_commit *branch, - const git_annotated_commit *upstream, - const git_annotated_commit *onto) -{ - git_revwalk *revwalk = NULL; - git_commit *commit; - git_oid id; - bool merge; - git_rebase_operation *operation; - int error; - - if (!upstream) - upstream = onto; - - if ((error = git_revwalk_new(&revwalk, rebase->repo)) < 0 || - (error = git_revwalk_push(revwalk, git_annotated_commit_id(branch))) < 0 || - (error = git_revwalk_hide(revwalk, git_annotated_commit_id(upstream))) < 0) - goto done; - - git_revwalk_sorting(revwalk, GIT_SORT_REVERSE); - - while ((error = git_revwalk_next(&id, revwalk)) == 0) { - if ((error = git_commit_lookup(&commit, repo, &id)) < 0) - goto done; - - merge = (git_commit_parentcount(commit) > 1); - git_commit_free(commit); - - if (merge) - continue; - - operation = rebase_operation_alloc(rebase, GIT_REBASE_OPERATION_PICK, &id, NULL); - GIT_ERROR_CHECK_ALLOC(operation); - } - - error = 0; - -done: - git_revwalk_free(revwalk); - return error; -} - -static int rebase_init_merge( - git_rebase *rebase, - git_repository *repo, - const git_annotated_commit *branch, - const git_annotated_commit *upstream, - const git_annotated_commit *onto) -{ - git_reference *head_ref = NULL; - git_commit *onto_commit = NULL; - git_str reflog = GIT_STR_INIT; - git_str state_path = GIT_STR_INIT; - int error; - - GIT_UNUSED(upstream); - - if ((error = git_str_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0 || - (error = git_str_put(&rebase->state_filename, state_path.ptr, state_path.size)) < 0) - goto done; - - rebase->state_path = git_str_detach(&state_path); - GIT_ERROR_CHECK_ALLOC(rebase->state_path); - - if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) { - rebase->orig_head_name = git__strdup(branch->ref_name); - GIT_ERROR_CHECK_ALLOC(rebase->orig_head_name); - } else { - rebase->head_detached = 1; - } - - rebase->onto_name = git__strdup(rebase_onto_name(onto)); - GIT_ERROR_CHECK_ALLOC(rebase->onto_name); - - rebase->quiet = rebase->options.quiet; - - git_oid_cpy(&rebase->orig_head_id, git_annotated_commit_id(branch)); - git_oid_cpy(&rebase->onto_id, git_annotated_commit_id(onto)); - - if ((error = rebase_setupfiles(rebase)) < 0 || - (error = git_str_printf(&reflog, - "rebase: checkout %s", rebase_onto_name(onto))) < 0 || - (error = git_commit_lookup( - &onto_commit, repo, git_annotated_commit_id(onto))) < 0 || - (error = git_checkout_tree(repo, - (git_object *)onto_commit, &rebase->options.checkout_options)) < 0 || - (error = git_reference_create(&head_ref, repo, GIT_HEAD_FILE, - git_annotated_commit_id(onto), 1, reflog.ptr)) < 0) - goto done; - -done: - git_reference_free(head_ref); - git_commit_free(onto_commit); - git_str_dispose(&reflog); - git_str_dispose(&state_path); - - return error; -} - -static int rebase_init_inmemory( - git_rebase *rebase, - git_repository *repo, - const git_annotated_commit *branch, - const git_annotated_commit *upstream, - const git_annotated_commit *onto) -{ - GIT_UNUSED(branch); - GIT_UNUSED(upstream); - - return git_commit_lookup( - &rebase->last_commit, repo, git_annotated_commit_id(onto)); -} - -int git_rebase_init( - git_rebase **out, - git_repository *repo, - const git_annotated_commit *branch, - const git_annotated_commit *upstream, - const git_annotated_commit *onto, - const git_rebase_options *given_opts) -{ - git_rebase *rebase = NULL; - git_annotated_commit *head_branch = NULL; - git_reference *head_ref = NULL; - bool inmemory = (given_opts && given_opts->inmemory); - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(upstream || onto); - - *out = NULL; - - if (!onto) - onto = upstream; - - if ((error = rebase_check_versions(given_opts)) < 0) - goto done; - - if (!inmemory) { - if ((error = git_repository__ensure_not_bare(repo, "rebase")) < 0 || - (error = rebase_ensure_not_in_progress(repo)) < 0 || - (error = rebase_ensure_not_dirty(repo, true, true, GIT_ERROR)) < 0) - goto done; - } - - if (!branch) { - if ((error = git_repository_head(&head_ref, repo)) < 0 || - (error = git_annotated_commit_from_ref(&head_branch, repo, head_ref)) < 0) - goto done; - - branch = head_branch; - } - - if (rebase_alloc(&rebase, given_opts) < 0) - return -1; - - rebase->repo = repo; - rebase->inmemory = inmemory; - rebase->type = GIT_REBASE_MERGE; - - if ((error = rebase_init_operations(rebase, repo, branch, upstream, onto)) < 0) - goto done; - - if (inmemory) - error = rebase_init_inmemory(rebase, repo, branch, upstream, onto); - else - error = rebase_init_merge(rebase, repo, branch ,upstream, onto); - - if (error == 0) - *out = rebase; - -done: - git_reference_free(head_ref); - git_annotated_commit_free(head_branch); - - if (error < 0) { - rebase_cleanup(rebase); - git_rebase_free(rebase); - } - - return error; -} - -static void normalize_checkout_options_for_apply( - git_checkout_options *checkout_opts, - git_rebase *rebase, - git_commit *current_commit) -{ - memcpy(checkout_opts, &rebase->options.checkout_options, sizeof(git_checkout_options)); - - if (!checkout_opts->ancestor_label) - checkout_opts->ancestor_label = "ancestor"; - - if (rebase->type == GIT_REBASE_MERGE) { - if (!checkout_opts->our_label) - checkout_opts->our_label = rebase->onto_name; - - if (!checkout_opts->their_label) - checkout_opts->their_label = git_commit_summary(current_commit); - } else { - abort(); - } -} - -GIT_INLINE(int) rebase_movenext(git_rebase *rebase) -{ - size_t next = rebase->started ? rebase->current + 1 : 0; - - if (next == git_array_size(rebase->operations)) - return GIT_ITEROVER; - - rebase->started = 1; - rebase->current = next; - - return 0; -} - -static int rebase_next_merge( - git_rebase_operation **out, - git_rebase *rebase) -{ - git_str path = GIT_STR_INIT; - git_commit *current_commit = NULL, *parent_commit = NULL; - git_tree *current_tree = NULL, *head_tree = NULL, *parent_tree = NULL; - git_index *index = NULL; - git_indexwriter indexwriter = GIT_INDEXWRITER_INIT; - git_rebase_operation *operation; - git_checkout_options checkout_opts; - char current_idstr[GIT_OID_MAX_HEXSIZE + 1]; - unsigned int parent_count; - int error; - - *out = NULL; - - operation = git_array_get(rebase->operations, rebase->current); - - if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 || - (error = git_commit_tree(¤t_tree, current_commit)) < 0 || - (error = git_repository_head_tree(&head_tree, rebase->repo)) < 0) - goto done; - - if ((parent_count = git_commit_parentcount(current_commit)) > 1) { - git_error_set(GIT_ERROR_REBASE, "cannot rebase a merge commit"); - error = -1; - goto done; - } else if (parent_count) { - if ((error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 || - (error = git_commit_tree(&parent_tree, parent_commit)) < 0) - goto done; - } - - git_oid_tostr(current_idstr, GIT_OID_MAX_HEXSIZE + 1, &operation->id); - - normalize_checkout_options_for_apply(&checkout_opts, rebase, current_commit); - - if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 || - (error = rebase_setupfile(rebase, MSGNUM_FILE, 0, "%" PRIuZ "\n", rebase->current+1)) < 0 || - (error = rebase_setupfile(rebase, CURRENT_FILE, 0, "%s\n", current_idstr)) < 0 || - (error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0 || - (error = git_merge__check_result(rebase->repo, index)) < 0 || - (error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0 || - (error = git_indexwriter_commit(&indexwriter)) < 0) - goto done; - - *out = operation; - -done: - git_indexwriter_cleanup(&indexwriter); - git_index_free(index); - git_tree_free(current_tree); - git_tree_free(head_tree); - git_tree_free(parent_tree); - git_commit_free(parent_commit); - git_commit_free(current_commit); - git_str_dispose(&path); - - return error; -} - -static int rebase_next_inmemory( - git_rebase_operation **out, - git_rebase *rebase) -{ - git_commit *current_commit = NULL, *parent_commit = NULL; - git_tree *current_tree = NULL, *head_tree = NULL, *parent_tree = NULL; - git_rebase_operation *operation; - git_index *index = NULL; - unsigned int parent_count; - int error; - - *out = NULL; - - operation = git_array_get(rebase->operations, rebase->current); - - if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 || - (error = git_commit_tree(¤t_tree, current_commit)) < 0) - goto done; - - if ((parent_count = git_commit_parentcount(current_commit)) > 1) { - git_error_set(GIT_ERROR_REBASE, "cannot rebase a merge commit"); - error = -1; - goto done; - } else if (parent_count) { - if ((error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 || - (error = git_commit_tree(&parent_tree, parent_commit)) < 0) - goto done; - } - - if ((error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 || - (error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0) - goto done; - - if (!rebase->index) { - rebase->index = index; - index = NULL; - } else { - if ((error = git_index_read_index(rebase->index, index)) < 0) - goto done; - } - - *out = operation; - -done: - git_commit_free(current_commit); - git_commit_free(parent_commit); - git_tree_free(current_tree); - git_tree_free(head_tree); - git_tree_free(parent_tree); - git_index_free(index); - - return error; -} - -int git_rebase_next( - git_rebase_operation **out, - git_rebase *rebase) -{ - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(rebase); - - if ((error = rebase_movenext(rebase)) < 0) - return error; - - if (rebase->inmemory) - error = rebase_next_inmemory(out, rebase); - else if (rebase->type == GIT_REBASE_MERGE) - error = rebase_next_merge(out, rebase); - else - abort(); - - return error; -} - -int git_rebase_inmemory_index( - git_index **out, - git_rebase *rebase) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(rebase); - GIT_ASSERT_ARG(rebase->index); - - GIT_REFCOUNT_INC(rebase->index); - *out = rebase->index; - - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -static int create_signed( - git_oid *out, - git_rebase *rebase, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - git_tree *tree, - size_t parent_count, - const git_commit **parents) -{ - git_str commit_content = GIT_STR_INIT; - git_buf commit_signature = { NULL, 0, 0 }, - signature_field = { NULL, 0, 0 }; - int error; - - git_error_clear(); - - if ((error = git_commit__create_buffer(&commit_content, - rebase->repo, author, committer, message_encoding, - message, tree, parent_count, parents)) < 0) - goto done; - - error = rebase->options.signing_cb(&commit_signature, - &signature_field, commit_content.ptr, - rebase->options.payload); - - if (error) { - if (error != GIT_PASSTHROUGH) - git_error_set_after_callback_function(error, "signing_cb"); - - goto done; - } - - error = git_commit_create_with_signature(out, rebase->repo, - commit_content.ptr, - commit_signature.size > 0 ? commit_signature.ptr : NULL, - signature_field.size > 0 ? signature_field.ptr : NULL); - -done: - git_buf_dispose(&commit_signature); - git_buf_dispose(&signature_field); - git_str_dispose(&commit_content); - return error; -} -#endif - -static int rebase_commit__create( - git_commit **out, - git_rebase *rebase, - git_index *index, - git_commit *parent_commit, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message) -{ - git_rebase_operation *operation; - git_commit *current_commit = NULL, *commit = NULL; - git_tree *parent_tree = NULL, *tree = NULL; - git_oid tree_id, commit_id; - int error; - - operation = git_array_get(rebase->operations, rebase->current); - - if (git_index_has_conflicts(index)) { - git_error_set(GIT_ERROR_REBASE, "conflicts have not been resolved"); - error = GIT_EUNMERGED; - goto done; - } - - if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 || - (error = git_commit_tree(&parent_tree, parent_commit)) < 0 || - (error = git_index_write_tree_to(&tree_id, index, rebase->repo)) < 0 || - (error = git_tree_lookup(&tree, rebase->repo, &tree_id)) < 0) - goto done; - - if (git_oid_equal(&tree_id, git_tree_id(parent_tree))) { - git_error_set(GIT_ERROR_REBASE, "this patch has already been applied"); - error = GIT_EAPPLIED; - goto done; - } - - if (!author) - author = git_commit_author(current_commit); - - if (!message) { - message_encoding = git_commit_message_encoding(current_commit); - message = git_commit_message(current_commit); - } - - git_error_clear(); - error = GIT_PASSTHROUGH; - - if (rebase->options.commit_create_cb) { - error = rebase->options.commit_create_cb(&commit_id, - author, committer, message_encoding, message, - tree, 1, (const git_commit **)&parent_commit, - rebase->options.payload); - - git_error_set_after_callback_function(error, - "commit_create_cb"); - } -#ifndef GIT_DEPRECATE_HARD - else if (rebase->options.signing_cb) { - error = create_signed(&commit_id, rebase, author, - committer, message_encoding, message, tree, - 1, (const git_commit **)&parent_commit); - } -#endif - - if (error == GIT_PASSTHROUGH) - error = git_commit_create(&commit_id, rebase->repo, NULL, - author, committer, message_encoding, message, - tree, 1, (const git_commit **)&parent_commit); - - if (error) - goto done; - - if ((error = git_commit_lookup(&commit, rebase->repo, &commit_id)) < 0) - goto done; - - *out = commit; - -done: - if (error < 0) - git_commit_free(commit); - - git_commit_free(current_commit); - git_tree_free(parent_tree); - git_tree_free(tree); - - return error; -} - -static int rebase_commit_merge( - git_oid *commit_id, - git_rebase *rebase, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message) -{ - git_rebase_operation *operation; - git_reference *head = NULL; - git_commit *head_commit = NULL, *commit = NULL; - git_index *index = NULL; - char old_idstr[GIT_OID_MAX_HEXSIZE + 1], new_idstr[GIT_OID_MAX_HEXSIZE + 1]; - int error; - - operation = git_array_get(rebase->operations, rebase->current); - GIT_ASSERT(operation); - - if ((error = rebase_ensure_not_dirty(rebase->repo, false, true, GIT_EUNMERGED)) < 0 || - (error = git_repository_head(&head, rebase->repo)) < 0 || - (error = git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)) < 0 || - (error = git_repository_index(&index, rebase->repo)) < 0 || - (error = rebase_commit__create(&commit, rebase, index, head_commit, - author, committer, message_encoding, message)) < 0 || - (error = git_reference__update_for_commit( - rebase->repo, NULL, "HEAD", git_commit_id(commit), "rebase")) < 0) - goto done; - - git_oid_tostr(old_idstr, GIT_OID_MAX_HEXSIZE + 1, &operation->id); - git_oid_tostr(new_idstr, GIT_OID_MAX_HEXSIZE + 1, git_commit_id(commit)); - - if ((error = rebase_setupfile(rebase, REWRITTEN_FILE, O_CREAT|O_WRONLY|O_APPEND, - "%s %s\n", old_idstr, new_idstr)) < 0) - goto done; - - git_oid_cpy(commit_id, git_commit_id(commit)); - -done: - git_index_free(index); - git_reference_free(head); - git_commit_free(head_commit); - git_commit_free(commit); - return error; -} - -static int rebase_commit_inmemory( - git_oid *commit_id, - git_rebase *rebase, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message) -{ - git_commit *commit = NULL; - int error = 0; - - GIT_ASSERT_ARG(rebase->index); - GIT_ASSERT_ARG(rebase->last_commit); - GIT_ASSERT_ARG(rebase->current < rebase->operations.size); - - if ((error = rebase_commit__create(&commit, rebase, rebase->index, - rebase->last_commit, author, committer, message_encoding, message)) < 0) - goto done; - - git_commit_free(rebase->last_commit); - rebase->last_commit = commit; - - git_oid_cpy(commit_id, git_commit_id(commit)); - -done: - if (error < 0) - git_commit_free(commit); - - return error; -} - -int git_rebase_commit( - git_oid *id, - git_rebase *rebase, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message) -{ - int error; - - GIT_ASSERT_ARG(rebase); - GIT_ASSERT_ARG(committer); - - if (rebase->inmemory) - error = rebase_commit_inmemory( - id, rebase, author, committer, message_encoding, message); - else if (rebase->type == GIT_REBASE_MERGE) - error = rebase_commit_merge( - id, rebase, author, committer, message_encoding, message); - else - abort(); - - return error; -} - -int git_rebase_abort(git_rebase *rebase) -{ - git_reference *orig_head_ref = NULL; - git_commit *orig_head_commit = NULL; - int error; - - GIT_ASSERT_ARG(rebase); - - if (rebase->inmemory) - return 0; - - error = rebase->head_detached ? - git_reference_create(&orig_head_ref, rebase->repo, GIT_HEAD_FILE, - &rebase->orig_head_id, 1, "rebase: aborting") : - git_reference_symbolic_create( - &orig_head_ref, rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1, - "rebase: aborting"); - - if (error < 0) - goto done; - - if ((error = git_commit_lookup( - &orig_head_commit, rebase->repo, &rebase->orig_head_id)) < 0 || - (error = git_reset(rebase->repo, (git_object *)orig_head_commit, - GIT_RESET_HARD, &rebase->options.checkout_options)) < 0) - goto done; - - error = rebase_cleanup(rebase); - -done: - git_commit_free(orig_head_commit); - git_reference_free(orig_head_ref); - - return error; -} - -static int notes_ref_lookup(git_str *out, git_rebase *rebase) -{ - git_config *config = NULL; - int do_rewrite, error; - - if (rebase->options.rewrite_notes_ref) { - git_str_attach_notowned(out, - rebase->options.rewrite_notes_ref, - strlen(rebase->options.rewrite_notes_ref)); - return 0; - } - - if ((error = git_repository_config(&config, rebase->repo)) < 0 || - (error = git_config_get_bool(&do_rewrite, config, "notes.rewrite.rebase")) < 0) { - - if (error != GIT_ENOTFOUND) - goto done; - - git_error_clear(); - do_rewrite = 1; - } - - error = do_rewrite ? - git_config__get_string_buf(out, config, "notes.rewriteref") : - GIT_ENOTFOUND; - -done: - git_config_free(config); - return error; -} - -static int rebase_copy_note( - git_rebase *rebase, - const char *notes_ref, - git_oid *from, - git_oid *to, - const git_signature *committer) -{ - git_note *note = NULL; - git_oid note_id; - git_signature *who = NULL; - int error; - - if ((error = git_note_read(¬e, rebase->repo, notes_ref, from)) < 0) { - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - - goto done; - } - - if (!committer) { - if((error = git_signature_default(&who, rebase->repo)) < 0) { - if (error != GIT_ENOTFOUND || - (error = git_signature_now(&who, "unknown", "unknown")) < 0) - goto done; - - git_error_clear(); - } - - committer = who; - } - - error = git_note_create(¬e_id, rebase->repo, notes_ref, - git_note_author(note), committer, to, git_note_message(note), 0); - -done: - git_note_free(note); - git_signature_free(who); - - return error; -} - -static int rebase_copy_notes( - git_rebase *rebase, - const git_signature *committer) -{ - git_str path = GIT_STR_INIT, - rewritten = GIT_STR_INIT, - notes_ref = GIT_STR_INIT; - char *pair_list, *fromstr, *tostr, *end; - git_oid from, to; - unsigned int linenum = 1; - int error = 0; - - if ((error = notes_ref_lookup(¬es_ref, rebase)) < 0) { - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - - goto done; - } - - if ((error = git_str_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 || - (error = git_futils_readbuffer(&rewritten, path.ptr)) < 0) - goto done; - - pair_list = rewritten.ptr; - - while (*pair_list) { - fromstr = pair_list; - - if ((end = strchr(fromstr, '\n')) == NULL) - goto on_error; - - pair_list = end+1; - *end = '\0'; - - if ((end = strchr(fromstr, ' ')) == NULL) - goto on_error; - - tostr = end+1; - *end = '\0'; - - if (strlen(fromstr) != git_oid_hexsize(rebase->repo->oid_type) || - strlen(tostr) != git_oid_hexsize(rebase->repo->oid_type) || - git_oid__fromstr(&from, fromstr, rebase->repo->oid_type) < 0 || - git_oid__fromstr(&to, tostr, rebase->repo->oid_type) < 0) - goto on_error; - - if ((error = rebase_copy_note(rebase, notes_ref.ptr, &from, &to, committer)) < 0) - goto done; - - linenum++; - } - - goto done; - -on_error: - git_error_set(GIT_ERROR_REBASE, "invalid rewritten file at line %d", linenum); - error = -1; - -done: - git_str_dispose(&rewritten); - git_str_dispose(&path); - git_str_dispose(¬es_ref); - - return error; -} - -static int return_to_orig_head(git_rebase *rebase) -{ - git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL; - git_commit *terminal_commit = NULL; - git_str branch_msg = GIT_STR_INIT, head_msg = GIT_STR_INIT; - char onto[GIT_OID_MAX_HEXSIZE + 1]; - int error = 0; - - git_oid_tostr(onto, GIT_OID_MAX_HEXSIZE + 1, &rebase->onto_id); - - if ((error = git_str_printf(&branch_msg, - "rebase finished: %s onto %s", rebase->orig_head_name, onto)) == 0 && - (error = git_str_printf(&head_msg, - "rebase finished: returning to %s", rebase->orig_head_name)) == 0 && - (error = git_repository_head(&terminal_ref, rebase->repo)) == 0 && - (error = git_reference_peel((git_object **)&terminal_commit, - terminal_ref, GIT_OBJECT_COMMIT)) == 0 && - (error = git_reference_create_matching(&branch_ref, - rebase->repo, rebase->orig_head_name, - git_commit_id(terminal_commit), 1, - &rebase->orig_head_id, branch_msg.ptr)) == 0) - error = git_reference_symbolic_create(&head_ref, - rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1, - head_msg.ptr); - - git_str_dispose(&head_msg); - git_str_dispose(&branch_msg); - git_commit_free(terminal_commit); - git_reference_free(head_ref); - git_reference_free(branch_ref); - git_reference_free(terminal_ref); - - return error; -} - -int git_rebase_finish( - git_rebase *rebase, - const git_signature *signature) -{ - int error = 0; - - GIT_ASSERT_ARG(rebase); - - if (rebase->inmemory) - return 0; - - if (!rebase->head_detached) - error = return_to_orig_head(rebase); - - if (error == 0 && (error = rebase_copy_notes(rebase, signature)) == 0) - error = rebase_cleanup(rebase); - - return error; -} - -const char *git_rebase_orig_head_name(git_rebase *rebase) { - GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL); - return rebase->orig_head_name; -} - -const git_oid *git_rebase_orig_head_id(git_rebase *rebase) { - GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL); - return &rebase->orig_head_id; -} - -const char *git_rebase_onto_name(git_rebase *rebase) { - GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL); - return rebase->onto_name; -} - -const git_oid *git_rebase_onto_id(git_rebase *rebase) { - return &rebase->onto_id; -} - -size_t git_rebase_operation_entrycount(git_rebase *rebase) -{ - GIT_ASSERT_ARG_WITH_RETVAL(rebase, 0); - - return git_array_size(rebase->operations); -} - -size_t git_rebase_operation_current(git_rebase *rebase) -{ - GIT_ASSERT_ARG_WITH_RETVAL(rebase, 0); - - return rebase->started ? rebase->current : GIT_REBASE_NO_OPERATION; -} - -git_rebase_operation *git_rebase_operation_byindex(git_rebase *rebase, size_t idx) -{ - GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL); - - return git_array_get(rebase->operations, idx); -} - -void git_rebase_free(git_rebase *rebase) -{ - if (rebase == NULL) - return; - - git_index_free(rebase->index); - git_commit_free(rebase->last_commit); - git__free(rebase->onto_name); - git__free(rebase->orig_head_name); - git__free(rebase->state_path); - git_str_dispose(&rebase->state_filename); - git_array_clear(rebase->operations); - git__free((char *)rebase->options.rewrite_notes_ref); - git__free(rebase); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/refdb.c b/vendor/libgit2-sys/libgit2/src/libgit2/refdb.c deleted file mode 100644 index ed33de9..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/refdb.c +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "refdb.h" - -#include "git2/object.h" -#include "git2/refs.h" -#include "git2/refdb.h" -#include "git2/sys/refdb_backend.h" - -#include "hash.h" -#include "refs.h" -#include "reflog.h" -#include "posix.h" - -#define DEFAULT_NESTING_LEVEL 5 -#define MAX_NESTING_LEVEL 10 - -int git_refdb_new(git_refdb **out, git_repository *repo) -{ - git_refdb *db; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - db = git__calloc(1, sizeof(*db)); - GIT_ERROR_CHECK_ALLOC(db); - - db->repo = repo; - - *out = db; - GIT_REFCOUNT_INC(db); - return 0; -} - -int git_refdb_open(git_refdb **out, git_repository *repo) -{ - git_refdb *db; - git_refdb_backend *dir; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - *out = NULL; - - if (git_refdb_new(&db, repo) < 0) - return -1; - - /* Add the default (filesystem) backend */ - if (git_refdb_backend_fs(&dir, repo) < 0) { - git_refdb_free(db); - return -1; - } - - db->repo = repo; - db->backend = dir; - - *out = db; - return 0; -} - -static void refdb_free_backend(git_refdb *db) -{ - if (db->backend) - db->backend->free(db->backend); -} - -int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend) -{ - GIT_ERROR_CHECK_VERSION(backend, GIT_REFDB_BACKEND_VERSION, "git_refdb_backend"); - - if (!backend->exists || !backend->lookup || !backend->iterator || - !backend->write || !backend->rename || !backend->del || - !backend->has_log || !backend->ensure_log || !backend->free || - !backend->reflog_read || !backend->reflog_write || - !backend->reflog_rename || !backend->reflog_delete || - (backend->lock && !backend->unlock)) { - git_error_set(GIT_ERROR_REFERENCE, "incomplete refdb backend implementation"); - return GIT_EINVALID; - } - - refdb_free_backend(db); - db->backend = backend; - - return 0; -} - -int git_refdb_compress(git_refdb *db) -{ - GIT_ASSERT_ARG(db); - - if (db->backend->compress) - return db->backend->compress(db->backend); - - return 0; -} - -void git_refdb__free(git_refdb *db) -{ - refdb_free_backend(db); - git__memzero(db, sizeof(*db)); - git__free(db); -} - -void git_refdb_free(git_refdb *db) -{ - if (db == NULL) - return; - - GIT_REFCOUNT_DEC(db, git_refdb__free); -} - -int git_refdb_exists(int *exists, git_refdb *refdb, const char *ref_name) -{ - GIT_ASSERT_ARG(exists); - GIT_ASSERT_ARG(refdb); - GIT_ASSERT_ARG(refdb->backend); - - return refdb->backend->exists(exists, refdb->backend, ref_name); -} - -int git_refdb_lookup(git_reference **out, git_refdb *db, const char *ref_name) -{ - git_reference *ref; - int error; - - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(db->backend); - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(ref_name); - - error = db->backend->lookup(&ref, db->backend, ref_name); - if (error < 0) - return error; - - GIT_REFCOUNT_INC(db); - ref->db = db; - - *out = ref; - return 0; -} - -int git_refdb_resolve( - git_reference **out, - git_refdb *db, - const char *ref_name, - int max_nesting) -{ - git_reference *ref = NULL; - int error = 0, nesting; - - *out = NULL; - - if (max_nesting > MAX_NESTING_LEVEL) - max_nesting = MAX_NESTING_LEVEL; - else if (max_nesting < 0) - max_nesting = DEFAULT_NESTING_LEVEL; - - if ((error = git_refdb_lookup(&ref, db, ref_name)) < 0) - goto out; - - for (nesting = 0; nesting < max_nesting; nesting++) { - git_reference *resolved; - - if (ref->type == GIT_REFERENCE_DIRECT) - break; - - if ((error = git_refdb_lookup(&resolved, db, git_reference_symbolic_target(ref))) < 0) { - /* If we found a symbolic reference with a nonexistent target, return it. */ - if (error == GIT_ENOTFOUND) { - error = 0; - *out = ref; - ref = NULL; - } - goto out; - } - - git_reference_free(ref); - ref = resolved; - } - - if (ref->type != GIT_REFERENCE_DIRECT && max_nesting != 0) { - git_error_set(GIT_ERROR_REFERENCE, - "cannot resolve reference (>%u levels deep)", max_nesting); - error = -1; - goto out; - } - - *out = ref; - ref = NULL; -out: - git_reference_free(ref); - return error; -} - -int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char *glob) -{ - int error; - - if (!db->backend || !db->backend->iterator) { - git_error_set(GIT_ERROR_REFERENCE, "this backend doesn't support iterators"); - return -1; - } - - if ((error = db->backend->iterator(out, db->backend, glob)) < 0) - return error; - - GIT_REFCOUNT_INC(db); - (*out)->db = db; - - return 0; -} - -int git_refdb_iterator_next(git_reference **out, git_reference_iterator *iter) -{ - int error; - - if ((error = iter->next(out, iter)) < 0) - return error; - - GIT_REFCOUNT_INC(iter->db); - (*out)->db = iter->db; - - return 0; -} - -int git_refdb_iterator_next_name(const char **out, git_reference_iterator *iter) -{ - return iter->next_name(out, iter); -} - -void git_refdb_iterator_free(git_reference_iterator *iter) -{ - GIT_REFCOUNT_DEC(iter->db, git_refdb__free); - iter->free(iter); -} - -int git_refdb_write(git_refdb *db, git_reference *ref, int force, const git_signature *who, const char *message, const git_oid *old_id, const char *old_target) -{ - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(db->backend); - - GIT_REFCOUNT_INC(db); - ref->db = db; - - return db->backend->write(db->backend, ref, force, who, message, old_id, old_target); -} - -int git_refdb_rename( - git_reference **out, - git_refdb *db, - const char *old_name, - const char *new_name, - int force, - const git_signature *who, - const char *message) -{ - int error; - - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(db->backend); - - error = db->backend->rename(out, db->backend, old_name, new_name, force, who, message); - if (error < 0) - return error; - - if (out) { - GIT_REFCOUNT_INC(db); - (*out)->db = db; - } - - return 0; -} - -int git_refdb_delete(struct git_refdb *db, const char *ref_name, const git_oid *old_id, const char *old_target) -{ - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(db->backend); - - return db->backend->del(db->backend, ref_name, old_id, old_target); -} - -int git_refdb_reflog_read(git_reflog **out, git_refdb *db, const char *name) -{ - int error; - - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(db->backend); - - if ((error = db->backend->reflog_read(out, db->backend, name)) < 0) - return error; - - GIT_REFCOUNT_INC(db); - (*out)->db = db; - - return 0; -} - -int git_refdb_should_write_reflog(int *out, git_refdb *db, const git_reference *ref) -{ - int error, logall; - - error = git_repository__configmap_lookup(&logall, db->repo, GIT_CONFIGMAP_LOGALLREFUPDATES); - if (error < 0) - return error; - - /* Defaults to the opposite of the repo being bare */ - if (logall == GIT_LOGALLREFUPDATES_UNSET) - logall = !git_repository_is_bare(db->repo); - - *out = 0; - switch (logall) { - case GIT_LOGALLREFUPDATES_FALSE: - *out = 0; - break; - - case GIT_LOGALLREFUPDATES_TRUE: - /* Only write if it already has a log, - * or if it's under heads/, remotes/ or notes/ - */ - *out = git_refdb_has_log(db, ref->name) || - !git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR) || - !git__strcmp(ref->name, GIT_HEAD_FILE) || - !git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR) || - !git__prefixcmp(ref->name, GIT_REFS_NOTES_DIR); - break; - - case GIT_LOGALLREFUPDATES_ALWAYS: - *out = 1; - break; - } - - return 0; -} - -int git_refdb_should_write_head_reflog(int *out, git_refdb *db, const git_reference *ref) -{ - git_reference *head = NULL, *resolved = NULL; - const char *name; - int error; - - *out = 0; - - if (ref->type == GIT_REFERENCE_SYMBOLIC) { - error = 0; - goto out; - } - - if ((error = git_refdb_lookup(&head, db, GIT_HEAD_FILE)) < 0) - goto out; - - if (git_reference_type(head) == GIT_REFERENCE_DIRECT) - goto out; - - /* Go down the symref chain until we find the branch */ - if ((error = git_refdb_resolve(&resolved, db, git_reference_symbolic_target(head), -1)) < 0) { - if (error != GIT_ENOTFOUND) - goto out; - error = 0; - name = git_reference_symbolic_target(head); - } else if (git_reference_type(resolved) == GIT_REFERENCE_SYMBOLIC) { - name = git_reference_symbolic_target(resolved); - } else { - name = git_reference_name(resolved); - } - - if (strcmp(name, ref->name)) - goto out; - - *out = 1; - -out: - git_reference_free(resolved); - git_reference_free(head); - return error; -} - -int git_refdb_has_log(git_refdb *db, const char *refname) -{ - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(refname); - - return db->backend->has_log(db->backend, refname); -} - -int git_refdb_ensure_log(git_refdb *db, const char *refname) -{ - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(refname); - - return db->backend->ensure_log(db->backend, refname); -} - -int git_refdb_init_backend(git_refdb_backend *backend, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - backend, version, git_refdb_backend, GIT_REFDB_BACKEND_INIT); - return 0; -} - -int git_refdb_lock(void **payload, git_refdb *db, const char *refname) -{ - GIT_ASSERT_ARG(payload); - GIT_ASSERT_ARG(db); - GIT_ASSERT_ARG(refname); - - if (!db->backend->lock) { - git_error_set(GIT_ERROR_REFERENCE, "backend does not support locking"); - return -1; - } - - return db->backend->lock(payload, db->backend, refname); -} - -int git_refdb_unlock(git_refdb *db, void *payload, int success, int update_reflog, const git_reference *ref, const git_signature *sig, const char *message) -{ - GIT_ASSERT_ARG(db); - - return db->backend->unlock(db->backend, payload, success, update_reflog, ref, sig, message); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/refdb.h b/vendor/libgit2-sys/libgit2/src/libgit2/refdb.h deleted file mode 100644 index 84e19b1..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/refdb.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_refdb_h__ -#define INCLUDE_refdb_h__ - -#include "common.h" - -#include "git2/refdb.h" -#include "repository.h" - -struct git_refdb { - git_refcount rc; - git_repository *repo; - git_refdb_backend *backend; -}; - -void git_refdb__free(git_refdb *db); - -int git_refdb_exists( - int *exists, - git_refdb *refdb, - const char *ref_name); - -int git_refdb_lookup( - git_reference **out, - git_refdb *refdb, - const char *ref_name); - -/** - * Resolve the reference by following symbolic references. - * - * Given a reference name, this function will follow any symbolic references up - * to `max_nesting` deep and return the resolved direct reference. If any of - * the intermediate symbolic references points to a non-existing reference, - * then that symbolic reference is returned instead with an error code of `0`. - * If the given reference is a direct reference already, it is returned - * directly. - * - * If `max_nesting` is `0`, the reference will not be resolved. If it's - * negative, it will be set to the default resolve depth which is `5`. - * - * @param out Pointer to store the result in. - * @param db The refdb to use for resolving the reference. - * @param ref_name The reference name to lookup and resolve. - * @param max_nesting The maximum nesting depth. - * @return `0` on success, a negative error code otherwise. - */ -int git_refdb_resolve( - git_reference **out, - git_refdb *db, - const char *ref_name, - int max_nesting); - -int git_refdb_rename( - git_reference **out, - git_refdb *db, - const char *old_name, - const char *new_name, - int force, - const git_signature *who, - const char *message); - -int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char *glob); -int git_refdb_iterator_next(git_reference **out, git_reference_iterator *iter); -int git_refdb_iterator_next_name(const char **out, git_reference_iterator *iter); -void git_refdb_iterator_free(git_reference_iterator *iter); - -int git_refdb_write(git_refdb *refdb, git_reference *ref, int force, const git_signature *who, const char *message, const git_oid *old_id, const char *old_target); -int git_refdb_delete(git_refdb *refdb, const char *ref_name, const git_oid *old_id, const char *old_target); - -int git_refdb_reflog_read(git_reflog **out, git_refdb *db, const char *name); -int git_refdb_reflog_write(git_reflog *reflog); - -/** - * Determine whether a reflog entry should be created for the given reference. - * - * Whether or not writing to a reference should create a reflog entry is - * dependent on a number of things. Most importantly, there's the - * "core.logAllRefUpdates" setting that controls in which situations a - * reference should get a corresponding reflog entry. The following values for - * it are understood: - * - * - "false": Do not log reference updates. - * - * - "true": Log normal reference updates. This will write entries for - * references in "refs/heads", "refs/remotes", "refs/notes" and - * "HEAD" or if the reference already has a log entry. - * - * - "always": Always create a reflog entry. - * - * If unset, the value will default to "true" for non-bare repositories and - * "false" for bare ones. - * - * @param out pointer to which the result will be written, `1` means a reflog - * entry should be written, `0` means none should be written. - * @param db The refdb to decide this for. - * @param ref The reference one wants to check. - * @return `0` on success, a negative error code otherwise. - */ -int git_refdb_should_write_reflog(int *out, git_refdb *db, const git_reference *ref); - -/** - * Determine whether a reflog entry should be created for HEAD if creating one - * for the given reference - * - * In case the given reference is being pointed to by HEAD, then creating a - * reflog entry for this reference also requires us to create a corresponding - * reflog entry for HEAD. This function can be used to determine that scenario. - * - * @param out pointer to which the result will be written, `1` means a reflog - * entry should be written, `0` means none should be written. - * @param db The refdb to decide this for. - * @param ref The reference one wants to check. - * @return `0` on success, a negative error code otherwise. - */ -int git_refdb_should_write_head_reflog(int *out, git_refdb *db, const git_reference *ref); - -int git_refdb_has_log(git_refdb *db, const char *refname); -int git_refdb_ensure_log(git_refdb *refdb, const char *refname); - -int git_refdb_lock(void **payload, git_refdb *db, const char *refname); -int git_refdb_unlock(git_refdb *db, void *payload, int success, int update_reflog, const git_reference *ref, const git_signature *sig, const char *message); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/refdb_fs.c b/vendor/libgit2-sys/libgit2/src/libgit2/refdb_fs.c deleted file mode 100644 index aa42782..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/refdb_fs.c +++ /dev/null @@ -1,2575 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "refs.h" -#include "hash.h" -#include "repository.h" -#include "futils.h" -#include "filebuf.h" -#include "pack.h" -#include "parse.h" -#include "reflog.h" -#include "refdb.h" -#include "iterator.h" -#include "sortedcache.h" -#include "signature.h" -#include "wildmatch.h" -#include "path.h" - -#include -#include -#include -#include -#include -#include - -#define DEFAULT_NESTING_LEVEL 5 -#define MAX_NESTING_LEVEL 10 - -enum { - PACKREF_HAS_PEEL = 1, - PACKREF_WAS_LOOSE = 2, - PACKREF_CANNOT_PEEL = 4, - PACKREF_SHADOWED = 8 -}; - -enum { - PEELING_NONE = 0, - PEELING_STANDARD, - PEELING_FULL -}; - -struct packref { - git_oid oid; - git_oid peel; - char flags; - char name[GIT_FLEX_ARRAY]; -}; - -typedef struct refdb_fs_backend { - git_refdb_backend parent; - - git_repository *repo; - /* path to git directory */ - char *gitpath; - /* path to common objects' directory */ - char *commonpath; - - git_oid_t oid_type; - - unsigned int fsync : 1, - sorted : 1; - int peeling_mode; - git_iterator_flag_t iterator_flags; - uint32_t direach_flags; - git_sortedcache *refcache; - git_map packed_refs_map; - git_mutex prlock; /* protect packed_refs_map */ - git_futils_filestamp packed_refs_stamp; -} refdb_fs_backend; - -static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name); -static char *packed_set_peeling_mode(char *data, size_t data_sz, refdb_fs_backend *backend); - -GIT_INLINE(int) loose_path( - git_str *out, - const char *base, - const char *refname) -{ - if (git_str_joinpath(out, base, refname) < 0) - return -1; - - return git_fs_path_validate_str_length_with_suffix(out, - CONST_STRLEN(".lock")); -} - -GIT_INLINE(int) reflog_path( - git_str *out, - git_repository *repo, - const char *refname) -{ - const char *base; - int error; - - base = (strcmp(refname, GIT_HEAD_FILE) == 0) ? repo->gitdir : - repo->commondir; - - if ((error = git_str_joinpath(out, base, GIT_REFLOG_DIR)) < 0) - return error; - - return loose_path(out, out->ptr, refname); -} - -static int packref_cmp(const void *a_, const void *b_) -{ - const struct packref *a = a_, *b = b_; - return strcmp(a->name, b->name); -} - -static int packed_reload(refdb_fs_backend *backend) -{ - int error; - git_str packedrefs = GIT_STR_INIT; - size_t oid_hexsize = git_oid_hexsize(backend->oid_type); - char *scan, *eof, *eol; - - if (!backend->gitpath) - return 0; - - error = git_sortedcache_lockandload(backend->refcache, &packedrefs); - - /* - * If we can't find the packed-refs, clear table and return. - * Any other error just gets passed through. - * If no error, and file wasn't changed, just return. - * Anything else means we need to refresh the packed refs. - */ - if (error <= 0) { - if (error == GIT_ENOTFOUND) { - GIT_UNUSED(git_sortedcache_clear(backend->refcache, true)); - git_error_clear(); - error = 0; - } - return error; - } - - /* At this point, refresh the packed refs from the loaded buffer. */ - - GIT_UNUSED(git_sortedcache_clear(backend->refcache, false)); - - scan = packedrefs.ptr; - eof = scan + packedrefs.size; - - scan = packed_set_peeling_mode(scan, packedrefs.size, backend); - if (!scan) - goto parse_failed; - - while (scan < eof && *scan == '#') { - if (!(eol = strchr(scan, '\n'))) - goto parse_failed; - scan = eol + 1; - } - - while (scan < eof) { - struct packref *ref; - git_oid oid; - - /* parse " \n" */ - - if (git_oid__fromstr(&oid, scan, backend->oid_type) < 0) - goto parse_failed; - scan += oid_hexsize; - - if (*scan++ != ' ') - goto parse_failed; - if (!(eol = strchr(scan, '\n'))) - goto parse_failed; - *eol = '\0'; - if (eol[-1] == '\r') - eol[-1] = '\0'; - - if (git_sortedcache_upsert((void **)&ref, backend->refcache, scan) < 0) - goto parse_failed; - scan = eol + 1; - - git_oid_cpy(&ref->oid, &oid); - - /* look for optional "^\n" */ - - if (*scan == '^') { - if (git_oid__fromstr(&oid, scan + 1, backend->oid_type) < 0) - goto parse_failed; - scan += oid_hexsize + 1; - - if (scan < eof) { - if (!(eol = strchr(scan, '\n'))) - goto parse_failed; - scan = eol + 1; - } - - git_oid_cpy(&ref->peel, &oid); - ref->flags |= PACKREF_HAS_PEEL; - } - else if (backend->peeling_mode == PEELING_FULL || - (backend->peeling_mode == PEELING_STANDARD && - git__prefixcmp(ref->name, GIT_REFS_TAGS_DIR) == 0)) - ref->flags |= PACKREF_CANNOT_PEEL; - } - - git_sortedcache_wunlock(backend->refcache); - git_str_dispose(&packedrefs); - - return 0; - -parse_failed: - git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file"); - - GIT_UNUSED(git_sortedcache_clear(backend->refcache, false)); - git_sortedcache_wunlock(backend->refcache); - git_str_dispose(&packedrefs); - - return -1; -} - -static int loose_parse_oid( - git_oid *oid, - const char *filename, - git_str *file_content, - git_oid_t oid_type) -{ - const char *str = git_str_cstr(file_content); - size_t oid_hexsize = git_oid_hexsize(oid_type); - - if (git_str_len(file_content) < oid_hexsize) - goto corrupted; - - /* we need to get 40 OID characters from the file */ - if (git_oid__fromstr(oid, str, oid_type) < 0) - goto corrupted; - - /* If the file is longer than 40 chars, the 41st must be a space */ - str += oid_hexsize; - if (*str == '\0' || git__isspace(*str)) - return 0; - -corrupted: - git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file: %s", filename); - return -1; -} - -static int loose_readbuffer(git_str *buf, const char *base, const char *path) -{ - int error; - - if ((error = loose_path(buf, base, path)) < 0 || - (error = git_futils_readbuffer(buf, buf->ptr)) < 0) - git_str_dispose(buf); - - return error; -} - -static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name) -{ - int error = 0; - git_str ref_file = GIT_STR_INIT; - struct packref *ref = NULL; - git_oid oid; - - /* if we fail to load the loose reference, assume someone changed - * the filesystem under us and skip it... - */ - if (loose_readbuffer(&ref_file, backend->gitpath, name) < 0) { - git_error_clear(); - goto done; - } - - /* skip symbolic refs */ - if (!git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF)) - goto done; - - /* parse OID from file */ - if ((error = loose_parse_oid(&oid, name, &ref_file, backend->oid_type)) < 0) - goto done; - - if ((error = git_sortedcache_wlock(backend->refcache)) < 0) - goto done; - - if (!(error = git_sortedcache_upsert( - (void **)&ref, backend->refcache, name))) { - - git_oid_cpy(&ref->oid, &oid); - ref->flags = PACKREF_WAS_LOOSE; - } - - git_sortedcache_wunlock(backend->refcache); - -done: - git_str_dispose(&ref_file); - return error; -} - -static int _dirent_loose_load(void *payload, git_str *full_path) -{ - refdb_fs_backend *backend = payload; - const char *file_path; - - if (git__suffixcmp(full_path->ptr, ".lock") == 0) - return 0; - - if (git_fs_path_isdir(full_path->ptr)) { - int error = git_fs_path_direach( - full_path, backend->direach_flags, _dirent_loose_load, backend); - /* Race with the filesystem, ignore it */ - if (error == GIT_ENOTFOUND) { - git_error_clear(); - return 0; - } - - return error; - } - - file_path = full_path->ptr + strlen(backend->gitpath); - - return loose_lookup_to_packfile(backend, file_path); -} - -/* - * Load all the loose references from the repository - * into the in-memory Packfile, and build a vector with - * all the references so it can be written back to - * disk. - */ -static int packed_loadloose(refdb_fs_backend *backend) -{ - int error; - git_str refs_path = GIT_STR_INIT; - - if (git_str_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0) - return -1; - - /* - * Load all the loose files from disk into the Packfile table. - * This will overwrite any old packed entries with their - * updated loose versions - */ - error = git_fs_path_direach( - &refs_path, backend->direach_flags, _dirent_loose_load, backend); - - git_str_dispose(&refs_path); - - return error; -} - -static int refdb_fs_backend__exists( - int *exists, - git_refdb_backend *_backend, - const char *ref_name) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - git_str ref_path = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(backend); - - *exists = 0; - - if ((error = loose_path(&ref_path, backend->gitpath, ref_name)) < 0) - goto out; - - if (git_fs_path_isfile(ref_path.ptr)) { - *exists = 1; - goto out; - } - - if ((error = packed_reload(backend)) < 0) - goto out; - - if (git_sortedcache_lookup(backend->refcache, ref_name) != NULL) { - *exists = 1; - goto out; - } - -out: - git_str_dispose(&ref_path); - return error; -} - -static const char *loose_parse_symbolic(git_str *file_content) -{ - const unsigned int header_len = (unsigned int)strlen(GIT_SYMREF); - const char *refname_start; - - refname_start = (const char *)file_content->ptr; - - if (git_str_len(file_content) < header_len + 1) { - git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file"); - return NULL; - } - - /* - * Assume we have already checked for the header - * before calling this function - */ - refname_start += header_len; - - return refname_start; -} - -/* - * Returns whether a reference is stored per worktree or not. - * Per-worktree references are: - * - * - all pseudorefs, e.g. HEAD and MERGE_HEAD - * - all references stored inside of "refs/bisect/" - */ -static bool is_per_worktree_ref(const char *ref_name) -{ - return git__prefixcmp(ref_name, "refs/") != 0 || - git__prefixcmp(ref_name, "refs/bisect/") == 0 || - git__prefixcmp(ref_name, "refs/worktree/") == 0 || - git__prefixcmp(ref_name, "refs/rewritten/") == 0; -} - -static int loose_lookup( - git_reference **out, - refdb_fs_backend *backend, - const char *ref_name) -{ - git_str ref_file = GIT_STR_INIT; - int error = 0; - const char *ref_dir; - - if (out) - *out = NULL; - - if (is_per_worktree_ref(ref_name)) - ref_dir = backend->gitpath; - else - ref_dir = backend->commonpath; - - if ((error = loose_readbuffer(&ref_file, ref_dir, ref_name)) < 0) - /* cannot read loose ref file - gah */; - else if (git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF) == 0) { - const char *target; - - git_str_rtrim(&ref_file); - - if (!(target = loose_parse_symbolic(&ref_file))) - error = -1; - else if (out != NULL) - *out = git_reference__alloc_symbolic(ref_name, target); - } else { - git_oid oid; - - if (!(error = loose_parse_oid(&oid, ref_name, &ref_file, backend->oid_type)) && - out != NULL) - *out = git_reference__alloc(ref_name, &oid, NULL); - } - - git_str_dispose(&ref_file); - return error; -} - -static int ref_error_notfound(const char *name) -{ - git_error_set(GIT_ERROR_REFERENCE, "reference '%s' not found", name); - return GIT_ENOTFOUND; -} - -static char *packed_set_peeling_mode( - char *data, - size_t data_sz, - refdb_fs_backend *backend) -{ - static const char *traits_header = "# pack-refs with:"; - char *eol; - backend->peeling_mode = PEELING_NONE; - - if (git__prefixncmp(data, data_sz, traits_header) == 0) { - size_t hdr_sz = strlen(traits_header); - const char *sorted = " sorted "; - const char *peeled = " peeled "; - const char *fully_peeled = " fully-peeled "; - data += hdr_sz; - data_sz -= hdr_sz; - - eol = memchr(data, '\n', data_sz); - - if (!eol) - return NULL; - - if (git__memmem(data, eol - data, fully_peeled, strlen(fully_peeled))) - backend->peeling_mode = PEELING_FULL; - else if (git__memmem(data, eol - data, peeled, strlen(peeled))) - backend->peeling_mode = PEELING_STANDARD; - - backend->sorted = NULL != git__memmem(data, eol - data, sorted, strlen(sorted)); - - return eol + 1; - } - return data; -} - -static void packed_map_free(refdb_fs_backend *backend) -{ - if (backend->packed_refs_map.data) { -#ifdef GIT_WIN32 - git__free(backend->packed_refs_map.data); -#else - git_futils_mmap_free(&backend->packed_refs_map); -#endif - backend->packed_refs_map.data = NULL; - backend->packed_refs_map.len = 0; - git_futils_filestamp_set(&backend->packed_refs_stamp, NULL); - } -} - -static int packed_map_check(refdb_fs_backend *backend) -{ - int error = 0; - git_file fd = -1; - struct stat st; - - if ((error = git_mutex_lock(&backend->prlock)) < 0) - return error; - - if (backend->packed_refs_map.data && - !git_futils_filestamp_check( - &backend->packed_refs_stamp, backend->refcache->path)) { - git_mutex_unlock(&backend->prlock); - return error; - } - packed_map_free(backend); - - fd = git_futils_open_ro(backend->refcache->path); - if (fd < 0) { - git_mutex_unlock(&backend->prlock); - if (fd == GIT_ENOTFOUND) { - git_error_clear(); - return 0; - } - return fd; - } - - if (p_fstat(fd, &st) < 0) { - p_close(fd); - git_mutex_unlock(&backend->prlock); - git_error_set(GIT_ERROR_OS, "unable to stat packed-refs '%s'", backend->refcache->path); - return -1; - } - - if (st.st_size == 0) { - p_close(fd); - git_mutex_unlock(&backend->prlock); - return 0; - } - - git_futils_filestamp_set_from_stat(&backend->packed_refs_stamp, &st); - -#ifdef GIT_WIN32 - /* on windows, we copy the entire file into memory rather than using - * mmap() because using mmap() on windows also locks the file and this - * map is long-lived. */ - backend->packed_refs_map.len = (size_t)st.st_size; - backend->packed_refs_map.data = - git__malloc(backend->packed_refs_map.len); - GIT_ERROR_CHECK_ALLOC(backend->packed_refs_map.data); - { - ssize_t bytesread = - p_read(fd, backend->packed_refs_map.data, - backend->packed_refs_map.len); - error = (bytesread == (ssize_t)backend->packed_refs_map.len) ? 0 : -1; - } -#else - error = git_futils_mmap_ro(&backend->packed_refs_map, fd, 0, (size_t)st.st_size); -#endif - p_close(fd); - if (error < 0) { - git_mutex_unlock(&backend->prlock); - return error; - } - - packed_set_peeling_mode( - backend->packed_refs_map.data, backend->packed_refs_map.len, - backend); - - git_mutex_unlock(&backend->prlock); - return error; -} - -/* - * Find beginning of packed-ref record pointed to by p. - * buf - a lower-bound pointer to some memory buffer - * p - an upper-bound pointer to the same memory buffer - */ -static const char *start_of_record(const char *buf, const char *p) -{ - const char *nl = p; - while (true) { - nl = git__memrchr(buf, '\n', nl - buf); - if (!nl) - return buf; - - if (nl[1] == '^' && nl > buf) - --nl; - else - break; - }; - return nl + 1; -} - -/* - * Find end of packed-ref record pointed to by p. - * end - an upper-bound pointer to some memory buffer - * p - a lower-bound pointer to the same memory buffer - */ -static const char *end_of_record(const char *p, const char *end) -{ - while (1) { - size_t sz = end - p; - p = memchr(p, '\n', sz); - if (!p) - return end; - ++p; - if (p < end && p[0] == '^') - ++p; - else - break; - } - return p; -} - -static int cmp_record_to_refname( - const char *rec, - size_t data_end, - const char *ref_name, - git_oid_t oid_type) -{ - const size_t ref_len = strlen(ref_name); - int cmp_val; - const char *end; - size_t oid_hexsize = git_oid_hexsize(oid_type); - - rec += oid_hexsize + 1; /* + space */ - - /* an incomplete (corrupt) record is treated as less than ref_name */ - if (data_end < oid_hexsize + 3) - return -1; - - data_end -= oid_hexsize + 1; - - end = memchr(rec, '\n', data_end); - if (end) - data_end = end - rec; - - cmp_val = memcmp(rec, ref_name, min(ref_len, data_end)); - - if (cmp_val == 0 && data_end != ref_len) - return (data_end > ref_len) ? 1 : -1; - return cmp_val; -} - -static int packed_unsorted_lookup( - git_reference **out, - refdb_fs_backend *backend, - const char *ref_name) -{ - int error = 0; - struct packref *entry; - - if ((error = packed_reload(backend)) < 0) - return error; - - if (git_sortedcache_rlock(backend->refcache) < 0) - return -1; - - entry = git_sortedcache_lookup(backend->refcache, ref_name); - if (!entry) { - error = ref_error_notfound(ref_name); - } else { - *out = git_reference__alloc(ref_name, &entry->oid, &entry->peel); - if (!*out) - error = -1; - } - - git_sortedcache_runlock(backend->refcache); - - return error; -} - -static int packed_lookup( - git_reference **out, - refdb_fs_backend *backend, - const char *ref_name) -{ - int error = 0; - const char *left, *right, *data_end; - size_t oid_hexsize = git_oid_hexsize(backend->oid_type); - - if ((error = packed_map_check(backend)) < 0) - return error; - - if (!backend->sorted) - return packed_unsorted_lookup(out, backend, ref_name); - - left = backend->packed_refs_map.data; - right = data_end = (const char *) backend->packed_refs_map.data + - backend->packed_refs_map.len; - - while (left < right && *left == '#') { - if (!(left = memchr(left, '\n', data_end - left))) - goto parse_failed; - left++; - } - - while (left < right) { - const char *mid, *rec; - int compare; - - mid = left + (right - left) / 2; - rec = start_of_record(left, mid); - compare = cmp_record_to_refname(rec, data_end - rec, ref_name, backend->oid_type); - - if (compare < 0) { - left = end_of_record(mid, right); - } else if (compare > 0) { - right = rec; - } else { - const char *eol; - git_oid oid, peel, *peel_ptr = NULL; - - if (data_end - rec < (long)oid_hexsize || - git_oid__fromstr(&oid, rec, backend->oid_type) < 0) { - goto parse_failed; - } - rec += oid_hexsize + 1; - if (!(eol = memchr(rec, '\n', data_end - rec))) { - goto parse_failed; - } - - /* look for optional "^\n" */ - - if (eol + 1 < data_end) { - rec = eol + 1; - - if (*rec == '^') { - rec++; - if (data_end - rec < (long)oid_hexsize || - git_oid__fromstr(&peel, rec, backend->oid_type) < 0) { - goto parse_failed; - } - peel_ptr = &peel; - } - } - - *out = git_reference__alloc(ref_name, &oid, peel_ptr); - if (!*out) { - return -1; - } - - return 0; - } - } - return ref_error_notfound(ref_name); - -parse_failed: - git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file"); - return -1; -} - -static int refdb_fs_backend__lookup( - git_reference **out, - git_refdb_backend *_backend, - const char *ref_name) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - int error; - - GIT_ASSERT_ARG(backend); - - if (!(error = loose_lookup(out, backend, ref_name))) - return 0; - - /* only try to lookup this reference on the packfile if it - * wasn't found on the loose refs; not if there was a critical error */ - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = packed_lookup(out, backend, ref_name); - } - return error; -} - -typedef struct { - git_reference_iterator parent; - - char *glob; - - git_pool pool; - git_vector loose; - - git_sortedcache *cache; - size_t loose_pos; - size_t packed_pos; -} refdb_fs_iter; - -static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter) -{ - refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent); - - git_vector_dispose(&iter->loose); - git_pool_clear(&iter->pool); - git_sortedcache_free(iter->cache); - git__free(iter); -} - -struct iter_load_context { - refdb_fs_backend *backend; - refdb_fs_iter *iter; - - /* - * If we have a glob with a prefix (eg `refs/heads/ *`) then we can - * optimize our prefix to avoid walking refs that we know won't - * match. This is that prefix. - */ - const char *ref_prefix; - size_t ref_prefix_len; - - /* Temporary variables to avoid unnecessary allocations */ - git_str ref_name; - git_str path; -}; - -static void iter_load_optimize_prefix(struct iter_load_context *ctx) -{ - const char *pos, *last_sep = NULL; - - if (!ctx->iter->glob) - return; - - for (pos = ctx->iter->glob; *pos; pos++) { - switch (*pos) { - case '?': - case '*': - case '[': - case '\\': - break; - case '/': - last_sep = pos; - /* FALLTHROUGH */ - default: - continue; - } - break; - } - - if (last_sep) { - ctx->ref_prefix = ctx->iter->glob; - ctx->ref_prefix_len = (last_sep - ctx->ref_prefix) + 1; - } -} - -static int iter_load_paths( - struct iter_load_context *ctx, - const char *root_path, - bool worktree) -{ - git_iterator *fsit = NULL; - git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT; - const git_index_entry *entry; - int error = 0; - - fsit_opts.flags = ctx->backend->iterator_flags; - - git_str_clear(&ctx->path); - git_str_puts(&ctx->path, root_path); - git_str_put(&ctx->path, ctx->ref_prefix, ctx->ref_prefix_len); - - fsit_opts.flags = ctx->backend->iterator_flags; - fsit_opts.oid_type = ctx->backend->oid_type; - - if ((error = git_iterator_for_filesystem(&fsit, ctx->path.ptr, &fsit_opts)) < 0) { - /* - * Subdirectories - either glob provided or per-worktree refs - need - * not exist. - */ - if ((worktree || ctx->iter->glob) && error == GIT_ENOTFOUND) - error = 0; - - goto done; - } - - git_str_clear(&ctx->ref_name); - git_str_put(&ctx->ref_name, ctx->ref_prefix, ctx->ref_prefix_len); - - while (git_iterator_advance(&entry, fsit) == 0) { - char *ref_dup; - - git_str_truncate(&ctx->ref_name, ctx->ref_prefix_len); - git_str_puts(&ctx->ref_name, entry->path); - - if (worktree) { - if (!is_per_worktree_ref(ctx->ref_name.ptr)) - continue; - } else { - if (git_repository_is_worktree(ctx->backend->repo) && - is_per_worktree_ref(ctx->ref_name.ptr)) - continue; - } - - if (git__suffixcmp(ctx->ref_name.ptr, ".lock") == 0) - continue; - - if (ctx->iter->glob && wildmatch(ctx->iter->glob, ctx->ref_name.ptr, 0)) - continue; - - ref_dup = git_pool_strdup(&ctx->iter->pool, ctx->ref_name.ptr); - GIT_ERROR_CHECK_ALLOC(ref_dup); - - if ((error = git_vector_insert(&ctx->iter->loose, ref_dup)) < 0) - goto done; - } - -done: - git_iterator_free(fsit); - return error; -} - -#define iter_load_context_init(b, i) { b, i, GIT_REFS_DIR, CONST_STRLEN(GIT_REFS_DIR) } -#define iter_load_context_dispose(ctx) do { \ - git_str_dispose(&((ctx)->path)); \ - git_str_dispose(&((ctx)->ref_name)); \ -} while(0) - -static int iter_load_loose_paths( - refdb_fs_backend *backend, - refdb_fs_iter *iter) -{ - struct iter_load_context ctx = iter_load_context_init(backend, iter); - - int error = 0; - - if (!backend->commonpath) - return 0; - - iter_load_optimize_prefix(&ctx); - - if ((error = iter_load_paths(&ctx, - backend->commonpath, false)) < 0) - goto done; - - if (git_repository_is_worktree(backend->repo)) { - if ((error = iter_load_paths(&ctx, - backend->gitpath, true)) < 0) - goto done; - } - -done: - iter_load_context_dispose(&ctx); - return error; -} - -static int refdb_fs_backend__iterator_next( - git_reference **out, git_reference_iterator *_iter) -{ - int error = GIT_ITEROVER; - refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent); - refdb_fs_backend *backend = GIT_CONTAINER_OF(iter->parent.db->backend, refdb_fs_backend, parent); - struct packref *ref; - - while (iter->loose_pos < iter->loose.length) { - const char *path = git_vector_get(&iter->loose, iter->loose_pos++); - - if (loose_lookup(out, backend, path) == 0) { - ref = git_sortedcache_lookup(iter->cache, path); - if (ref) - ref->flags |= PACKREF_SHADOWED; - - return 0; - } - - git_error_clear(); - } - - error = GIT_ITEROVER; - while (iter->packed_pos < git_sortedcache_entrycount(iter->cache)) { - ref = git_sortedcache_entry(iter->cache, iter->packed_pos++); - if (!ref) /* stop now if another thread deleted refs and we past end */ - break; - - if (ref->flags & PACKREF_SHADOWED) - continue; - if (iter->glob && wildmatch(iter->glob, ref->name, 0) != 0) - continue; - - *out = git_reference__alloc(ref->name, &ref->oid, &ref->peel); - error = (*out != NULL) ? 0 : -1; - break; - } - - return error; -} - -static int refdb_fs_backend__iterator_next_name( - const char **out, git_reference_iterator *_iter) -{ - int error = GIT_ITEROVER; - refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent); - refdb_fs_backend *backend = GIT_CONTAINER_OF(iter->parent.db->backend, refdb_fs_backend, parent); - struct packref *ref; - - while (iter->loose_pos < iter->loose.length) { - const char *path = git_vector_get(&iter->loose, iter->loose_pos++); - struct packref *ref; - - if (loose_lookup(NULL, backend, path) == 0) { - ref = git_sortedcache_lookup(iter->cache, path); - if (ref) - ref->flags |= PACKREF_SHADOWED; - - *out = path; - return 0; - } - - git_error_clear(); - } - - error = GIT_ITEROVER; - while (iter->packed_pos < git_sortedcache_entrycount(iter->cache)) { - ref = git_sortedcache_entry(iter->cache, iter->packed_pos++); - if (!ref) /* stop now if another thread deleted refs and we past end */ - break; - - if (ref->flags & PACKREF_SHADOWED) - continue; - if (iter->glob && wildmatch(iter->glob, ref->name, 0) != 0) - continue; - - *out = ref->name; - error = 0; - break; - } - - return error; -} - -static int refdb_fs_backend__iterator( - git_reference_iterator **out, git_refdb_backend *_backend, const char *glob) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - refdb_fs_iter *iter = NULL; - int error; - - GIT_ASSERT_ARG(backend); - - iter = git__calloc(1, sizeof(refdb_fs_iter)); - GIT_ERROR_CHECK_ALLOC(iter); - - if ((error = git_pool_init(&iter->pool, 1)) < 0) - goto out; - - if ((error = git_vector_init(&iter->loose, 8, NULL)) < 0) - goto out; - - if (glob != NULL && - (iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL) { - error = GIT_ERROR_NOMEMORY; - goto out; - } - - if ((error = iter_load_loose_paths(backend, iter)) < 0) - goto out; - - if ((error = packed_reload(backend)) < 0) - goto out; - - if ((error = git_sortedcache_copy(&iter->cache, backend->refcache, 1, NULL, NULL)) < 0) - goto out; - - iter->parent.next = refdb_fs_backend__iterator_next; - iter->parent.next_name = refdb_fs_backend__iterator_next_name; - iter->parent.free = refdb_fs_backend__iterator_free; - - *out = (git_reference_iterator *)iter; -out: - if (error) - refdb_fs_backend__iterator_free((git_reference_iterator *)iter); - return error; -} - -static bool ref_is_available( - const char *old_ref, const char *new_ref, const char *this_ref) -{ - if (old_ref == NULL || strcmp(old_ref, this_ref)) { - size_t reflen = strlen(this_ref); - size_t newlen = strlen(new_ref); - size_t cmplen = reflen < newlen ? reflen : newlen; - const char *lead = reflen < newlen ? new_ref : this_ref; - - if (!strncmp(new_ref, this_ref, cmplen) && lead[cmplen] == '/') { - return false; - } - } - - return true; -} - -static int reference_path_available( - refdb_fs_backend *backend, - const char *new_ref, - const char *old_ref, - int force) -{ - size_t i; - int error; - - if ((error = packed_reload(backend)) < 0) - return error; - - if (!force) { - int exists; - - if ((error = refdb_fs_backend__exists( - &exists, (git_refdb_backend *)backend, new_ref)) < 0) { - return error; - } - - if (exists) { - git_error_set(GIT_ERROR_REFERENCE, - "failed to write reference '%s': a reference with " - "that name already exists.", new_ref); - return GIT_EEXISTS; - } - } - - if ((error = git_sortedcache_rlock(backend->refcache)) < 0) - return error; - - for (i = 0; i < git_sortedcache_entrycount(backend->refcache); ++i) { - struct packref *ref = git_sortedcache_entry(backend->refcache, i); - - if (ref && !ref_is_available(old_ref, new_ref, ref->name)) { - git_sortedcache_runlock(backend->refcache); - git_error_set(GIT_ERROR_REFERENCE, - "path to reference '%s' collides with existing one", new_ref); - return -1; - } - } - - git_sortedcache_runlock(backend->refcache); - return 0; -} - -static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *name) -{ - int error, filebuf_flags; - git_str ref_path = GIT_STR_INIT; - const char *basedir; - - GIT_ASSERT_ARG(file); - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(name); - - if (!git_path_is_valid(backend->repo, name, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) { - git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name); - return GIT_EINVALIDSPEC; - } - - if (is_per_worktree_ref(name)) - basedir = backend->gitpath; - else - basedir = backend->commonpath; - - /* Remove a possibly existing empty directory hierarchy - * which name would collide with the reference name - */ - if ((error = git_futils_rmdir_r(name, basedir, GIT_RMDIR_SKIP_NONEMPTY)) < 0) - return error; - - if ((error = loose_path(&ref_path, basedir, name)) < 0) - return error; - - filebuf_flags = GIT_FILEBUF_CREATE_LEADING_DIRS; - if (backend->fsync) - filebuf_flags |= GIT_FILEBUF_FSYNC; - - error = git_filebuf_open(file, ref_path.ptr, filebuf_flags, GIT_REFS_FILE_MODE); - - if (error == GIT_EDIRECTORY) - git_error_set(GIT_ERROR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name); - - git_str_dispose(&ref_path); - return error; -} - -static int loose_commit(git_filebuf *file, const git_reference *ref) -{ - GIT_ASSERT_ARG(file); - GIT_ASSERT_ARG(ref); - - if (ref->type == GIT_REFERENCE_DIRECT) { - char oid[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_nfmt(oid, sizeof(oid), &ref->target.oid); - - git_filebuf_printf(file, "%s\n", oid); - } else if (ref->type == GIT_REFERENCE_SYMBOLIC) { - git_filebuf_printf(file, GIT_SYMREF "%s\n", ref->target.symbolic); - } else { - GIT_ASSERT(0); - } - - return git_filebuf_commit(file); -} - -static int refdb_fs_backend__lock(void **out, git_refdb_backend *_backend, const char *refname) -{ - int error; - git_filebuf *lock; - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - - lock = git__calloc(1, sizeof(git_filebuf)); - GIT_ERROR_CHECK_ALLOC(lock); - - if ((error = loose_lock(lock, backend, refname)) < 0) { - git__free(lock); - return error; - } - - *out = lock; - return 0; -} - -static int refdb_fs_backend__write_tail( - git_refdb_backend *_backend, - const git_reference *ref, - git_filebuf *file, - int update_reflog, - const git_oid *old_id, - const char *old_target, - const git_signature *who, - const char *message); - -static int refdb_fs_backend__delete_tail( - git_refdb_backend *_backend, - git_filebuf *file, - const char *ref_name, - const git_oid *old_id, - const char *old_target); - -static int refdb_fs_backend__unlock(git_refdb_backend *backend, void *payload, int success, int update_reflog, - const git_reference *ref, const git_signature *sig, const char *message) -{ - git_filebuf *lock = (git_filebuf *) payload; - int error = 0; - - if (success == 2) - error = refdb_fs_backend__delete_tail(backend, lock, ref->name, NULL, NULL); - else if (success) - error = refdb_fs_backend__write_tail(backend, ref, lock, update_reflog, NULL, NULL, sig, message); - else - git_filebuf_cleanup(lock); - - git__free(lock); - return error; -} - -/* - * Find out what object this reference resolves to. - * - * For references that point to a 'big' tag (e.g. an - * actual tag object on the repository), we need to - * cache on the packfile the OID of the object to - * which that 'big tag' is pointing to. - */ -static int packed_find_peel(refdb_fs_backend *backend, struct packref *ref) -{ - git_object *object; - - if (ref->flags & PACKREF_HAS_PEEL || ref->flags & PACKREF_CANNOT_PEEL) - return 0; - - /* - * Find the tagged object in the repository - */ - if (git_object_lookup(&object, backend->repo, &ref->oid, GIT_OBJECT_ANY) < 0) - return -1; - - /* - * If the tagged object is a Tag object, we need to resolve it; - * if the ref is actually a 'weak' ref, we don't need to resolve - * anything. - */ - if (git_object_type(object) == GIT_OBJECT_TAG) { - git_tag *tag = (git_tag *)object; - - /* - * Find the object pointed at by this tag - */ - git_oid_cpy(&ref->peel, git_tag_target_id(tag)); - ref->flags |= PACKREF_HAS_PEEL; - - /* - * The reference has now cached the resolved OID, and is - * marked at such. When written to the packfile, it'll be - * accompanied by this resolved oid - */ - } - - git_object_free(object); - return 0; -} - -/* - * Write a single reference into a packfile - */ -static int packed_write_ref(struct packref *ref, git_filebuf *file) -{ - char oid[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_nfmt(oid, sizeof(oid), &ref->oid); - - /* - * For references that peel to an object in the repo, we must - * write the resulting peel on a separate line, e.g. - * - * 6fa8a902cc1d18527e1355773c86721945475d37 refs/tags/libgit2-0.4 - * ^2ec0cb7959b0bf965d54f95453f5b4b34e8d3100 - * - * This obviously only applies to tags. - * The required peels have already been loaded into `ref->peel_target`. - */ - if (ref->flags & PACKREF_HAS_PEEL) { - char peel[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_nfmt(peel, sizeof(peel), &ref->peel); - - if (git_filebuf_printf(file, "%s %s\n^%s\n", oid, ref->name, peel) < 0) - return -1; - } else { - if (git_filebuf_printf(file, "%s %s\n", oid, ref->name) < 0) - return -1; - } - - return 0; -} - -/* - * Remove all loose references - * - * Once we have successfully written a packfile, - * all the loose references that were packed must be - * removed from disk. - * - * This is a dangerous method; make sure the packfile - * is well-written, because we are destructing references - * here otherwise. - */ -static int packed_remove_loose(refdb_fs_backend *backend) -{ - size_t i; - git_filebuf lock = GIT_FILEBUF_INIT; - git_str ref_content = GIT_STR_INIT; - int error = 0; - - /* backend->refcache is already locked when this is called */ - - for (i = 0; i < git_sortedcache_entrycount(backend->refcache); ++i) { - struct packref *ref = git_sortedcache_entry(backend->refcache, i); - git_oid current_id; - - if (!ref || !(ref->flags & PACKREF_WAS_LOOSE)) - continue; - - git_filebuf_cleanup(&lock); - - /* We need to stop anybody from updating the ref while we try to do a safe delete */ - error = loose_lock(&lock, backend, ref->name); - /* If someone else is updating it, let them do it */ - if (error == GIT_EEXISTS || error == GIT_ENOTFOUND) - continue; - - if (error < 0) { - git_str_dispose(&ref_content); - git_error_set(GIT_ERROR_REFERENCE, "failed to lock loose reference '%s'", ref->name); - return error; - } - - error = git_futils_readbuffer(&ref_content, lock.path_original); - /* Someone else beat us to cleaning up the ref, let's simply continue */ - if (error == GIT_ENOTFOUND) - continue; - - /* This became a symref between us packing and trying to delete it, so ignore it */ - if (!git__prefixcmp(ref_content.ptr, GIT_SYMREF)) - continue; - - /* Figure out the current id; if we find a bad ref file, skip it so we can do the rest */ - if (loose_parse_oid(¤t_id, lock.path_original, &ref_content, backend->oid_type) < 0) - continue; - - /* If the ref moved since we packed it, we must not delete it */ - if (!git_oid_equal(¤t_id, &ref->oid)) - continue; - - /* - * if we fail to remove a single file, this is *not* good, - * but we should keep going and remove as many as possible. - * If we fail to remove, the ref is still in the old state, so - * we haven't lost information. - */ - p_unlink(lock.path_original); - } - - git_str_dispose(&ref_content); - git_filebuf_cleanup(&lock); - return 0; -} - -/* - * Write all the contents in the in-memory packfile to disk. - */ -static int packed_write(refdb_fs_backend *backend) -{ - git_sortedcache *refcache = backend->refcache; - git_filebuf pack_file = GIT_FILEBUF_INIT; - int error, open_flags = 0; - size_t i; - - /* take lock and close up packed-refs mmap if open */ - if ((error = git_mutex_lock(&backend->prlock)) < 0) { - return error; - } - - packed_map_free(backend); - - git_mutex_unlock(&backend->prlock); - - /* lock the cache to updates while we do this */ - if ((error = git_sortedcache_wlock(refcache)) < 0) - return error; - - if (backend->fsync) - open_flags = GIT_FILEBUF_FSYNC; - - /* Open the file! */ - if ((error = git_filebuf_open(&pack_file, git_sortedcache_path(refcache), open_flags, GIT_PACKEDREFS_FILE_MODE)) < 0) - goto fail; - - /* Packfiles have a header... apparently - * This is in fact not required, but we might as well print it - * just for kicks */ - if ((error = git_filebuf_printf(&pack_file, "%s\n", GIT_PACKEDREFS_HEADER)) < 0) - goto fail; - - for (i = 0; i < git_sortedcache_entrycount(refcache); ++i) { - struct packref *ref = git_sortedcache_entry(refcache, i); - - GIT_ASSERT_WITH_CLEANUP(ref, { - error = -1; - goto fail; - }); - - if ((error = packed_find_peel(backend, ref)) < 0) - goto fail; - - if ((error = packed_write_ref(ref, &pack_file)) < 0) - goto fail; - } - - /* if we've written all the references properly, we can commit - * the packfile to make the changes effective */ - if ((error = git_filebuf_commit(&pack_file)) < 0) - goto fail; - - /* when and only when the packfile has been properly written, - * we can go ahead and remove the loose refs */ - if ((error = packed_remove_loose(backend)) < 0) - goto fail; - - git_sortedcache_updated(refcache); - git_sortedcache_wunlock(refcache); - - /* we're good now */ - return 0; - -fail: - git_filebuf_cleanup(&pack_file); - git_sortedcache_wunlock(refcache); - - return error; -} - -static int packed_delete(refdb_fs_backend *backend, const char *ref_name) -{ - size_t pack_pos; - int error, found = 0; - - if ((error = packed_reload(backend)) < 0) - goto cleanup; - - if ((error = git_sortedcache_wlock(backend->refcache)) < 0) - goto cleanup; - - /* If a packed reference exists, remove it from the packfile and repack if necessary */ - error = git_sortedcache_lookup_index(&pack_pos, backend->refcache, ref_name); - if (error == 0) { - error = git_sortedcache_remove(backend->refcache, pack_pos); - found = 1; - } - if (error == GIT_ENOTFOUND) - error = 0; - - git_sortedcache_wunlock(backend->refcache); - - if (found) - error = packed_write(backend); - -cleanup: - return error; -} - -static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *author, const char *message); - -static int cmp_old_ref(int *cmp, git_refdb_backend *backend, const char *name, - const git_oid *old_id, const char *old_target) -{ - int error = 0; - git_reference *old_ref = NULL; - - *cmp = 0; - /* It "matches" if there is no old value to compare against */ - if (!old_id && !old_target) - return 0; - - if ((error = refdb_fs_backend__lookup(&old_ref, backend, name)) < 0) { - if (error == GIT_ENOTFOUND && old_id && git_oid_is_zero(old_id)) - return 0; - goto out; - } - - /* If the types don't match, there's no way the values do */ - if (old_id && old_ref->type != GIT_REFERENCE_DIRECT) { - *cmp = -1; - goto out; - } - if (old_target && old_ref->type != GIT_REFERENCE_SYMBOLIC) { - *cmp = 1; - goto out; - } - - if (old_id && old_ref->type == GIT_REFERENCE_DIRECT) - *cmp = git_oid_cmp(old_id, &old_ref->target.oid); - - if (old_target && old_ref->type == GIT_REFERENCE_SYMBOLIC) - *cmp = git__strcmp(old_target, old_ref->target.symbolic); - -out: - git_reference_free(old_ref); - - return error; -} - -/* - * The git.git comment regarding this, for your viewing pleasure: - * - * Special hack: If a branch is updated directly and HEAD - * points to it (may happen on the remote side of a push - * for example) then logically the HEAD reflog should be - * updated too. - * A generic solution implies reverse symref information, - * but finding all symrefs pointing to the given branch - * would be rather costly for this rare event (the direct - * update of a branch) to be worth it. So let's cheat and - * check with HEAD only which should cover 99% of all usage - * scenarios (even 100% of the default ones). - */ -static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref, const git_signature *who, const char *message) -{ - git_reference *head = NULL; - git_refdb *refdb = NULL; - int error, write_reflog; - git_oid old_id; - - if ((error = git_repository_refdb(&refdb, backend->repo)) < 0 || - (error = git_refdb_should_write_head_reflog(&write_reflog, refdb, ref)) < 0) - goto out; - if (!write_reflog) - goto out; - - /* if we can't resolve, we use {0}*40 as old id */ - if (git_reference_name_to_id(&old_id, backend->repo, ref->name) < 0) - memset(&old_id, 0, sizeof(old_id)); - - if ((error = git_reference_lookup(&head, backend->repo, GIT_HEAD_FILE)) < 0 || - (error = reflog_append(backend, head, &old_id, git_reference_target(ref), who, message)) < 0) - goto out; - -out: - git_reference_free(head); - git_refdb_free(refdb); - return error; -} - -static int refdb_fs_backend__write( - git_refdb_backend *_backend, - const git_reference *ref, - int force, - const git_signature *who, - const char *message, - const git_oid *old_id, - const char *old_target) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - git_filebuf file = GIT_FILEBUF_INIT; - int error = 0; - - GIT_ASSERT_ARG(backend); - - if ((error = reference_path_available(backend, ref->name, NULL, force)) < 0) - return error; - - /* We need to perform the reflog append and old value check under the ref's lock */ - if ((error = loose_lock(&file, backend, ref->name)) < 0) - return error; - - return refdb_fs_backend__write_tail(_backend, ref, &file, true, old_id, old_target, who, message); -} - -static int refdb_fs_backend__write_tail( - git_refdb_backend *_backend, - const git_reference *ref, - git_filebuf *file, - int update_reflog, - const git_oid *old_id, - const char *old_target, - const git_signature *who, - const char *message) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - int error = 0, cmp = 0, should_write; - const char *new_target = NULL; - const git_oid *new_id = NULL; - - if ((error = cmp_old_ref(&cmp, _backend, ref->name, old_id, old_target)) < 0) - goto on_error; - - if (cmp) { - git_error_set(GIT_ERROR_REFERENCE, "old reference value does not match"); - error = GIT_EMODIFIED; - goto on_error; - } - - if (ref->type == GIT_REFERENCE_SYMBOLIC) - new_target = ref->target.symbolic; - else - new_id = &ref->target.oid; - - error = cmp_old_ref(&cmp, _backend, ref->name, new_id, new_target); - if (error < 0 && error != GIT_ENOTFOUND) - goto on_error; - - /* Don't update if we have the same value */ - if (!error && !cmp) { - error = 0; - goto on_error; /* not really error */ - } - - if (update_reflog) { - git_refdb *refdb; - - if ((error = git_repository_refdb__weakptr(&refdb, backend->repo)) < 0 || - (error = git_refdb_should_write_reflog(&should_write, refdb, ref)) < 0) - goto on_error; - - if (should_write) { - if ((error = reflog_append(backend, ref, NULL, NULL, who, message)) < 0) - goto on_error; - if ((error = maybe_append_head(backend, ref, who, message)) < 0) - goto on_error; - } - } - - return loose_commit(file, ref); - -on_error: - git_filebuf_cleanup(file); - return error; -} - -static int refdb_fs_backend__prune_refs( - refdb_fs_backend *backend, - const char *ref_name, - const char *prefix) -{ - git_str relative_path = GIT_STR_INIT; - git_str base_path = GIT_STR_INIT; - size_t commonlen; - int error; - - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(ref_name); - - if ((error = git_str_sets(&relative_path, ref_name)) < 0) - goto cleanup; - - git_fs_path_squash_slashes(&relative_path); - if ((commonlen = git_fs_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") || - (commonlen = git_fs_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") || - (commonlen = git_fs_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) { - - git_str_truncate(&relative_path, commonlen); - - if (prefix) - error = git_str_join3(&base_path, '/', - backend->commonpath, prefix, - git_str_cstr(&relative_path)); - else - error = git_str_joinpath(&base_path, - backend->commonpath, - git_str_cstr(&relative_path)); - - if (!error) - error = git_path_validate_str_length(NULL, &base_path); - - if (error < 0) - goto cleanup; - - error = git_futils_rmdir_r(ref_name + commonlen, - git_str_cstr(&base_path), - GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT); - - if (error == GIT_ENOTFOUND) - error = 0; - } - -cleanup: - git_str_dispose(&relative_path); - git_str_dispose(&base_path); - return error; -} - -static int refdb_fs_backend__delete( - git_refdb_backend *_backend, - const char *ref_name, - const git_oid *old_id, const char *old_target) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - git_filebuf file = GIT_FILEBUF_INIT; - int error = 0; - - GIT_ASSERT_ARG(backend); - GIT_ASSERT_ARG(ref_name); - - if ((error = loose_lock(&file, backend, ref_name)) < 0) - return error; - - if ((error = refdb_reflog_fs__delete(_backend, ref_name)) < 0) { - git_filebuf_cleanup(&file); - return error; - } - - return refdb_fs_backend__delete_tail(_backend, &file, ref_name, old_id, old_target); -} - -static int loose_delete(refdb_fs_backend *backend, const char *ref_name) -{ - git_str path = GIT_STR_INIT; - int error = 0; - - if ((error = loose_path(&path, backend->commonpath, ref_name)) < 0) - return error; - - error = p_unlink(path.ptr); - if (error < 0 && errno == ENOENT) - error = GIT_ENOTFOUND; - else if (error != 0) - error = -1; - - git_str_dispose(&path); - - return error; -} - -static int refdb_fs_backend__delete_tail( - git_refdb_backend *_backend, - git_filebuf *file, - const char *ref_name, - const git_oid *old_id, const char *old_target) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - int error = 0, cmp = 0; - bool packed_deleted = 0; - - error = cmp_old_ref(&cmp, _backend, ref_name, old_id, old_target); - if (error < 0) - goto cleanup; - - if (cmp) { - git_error_set(GIT_ERROR_REFERENCE, "old reference value does not match"); - error = GIT_EMODIFIED; - goto cleanup; - } - - /* - * To ensure that an external observer will see either the current ref value - * (because the loose ref still exists), or a missing ref (after the packed-file is - * unlocked, there will be nothing left), we must ensure things happen in the - * following order: - * - * - the packed-ref file is locked and loaded, as well as a loose one, if it exists - * - we optimistically delete a packed ref, keeping track of whether it existed - * - we delete the loose ref, note that we have its .lock - * - the loose ref is "unlocked", then the packed-ref file is rewritten and unlocked - * - we should prune the path components if a loose ref was deleted - * - * Note that, because our packed backend doesn't expose its filesystem lock, - * we might not be able to guarantee that this is what actually happens (ie. - * as our current code never write packed-refs.lock, nothing stops observers - * from grabbing a "stale" value from there). - */ - if ((error = packed_delete(backend, ref_name)) < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - if (error == 0) - packed_deleted = 1; - - if ((error = loose_delete(backend, ref_name)) < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - if (error == GIT_ENOTFOUND) { - error = packed_deleted ? 0 : ref_error_notfound(ref_name); - goto cleanup; - } - -cleanup: - git_filebuf_cleanup(file); - if (error == 0) - error = refdb_fs_backend__prune_refs(backend, ref_name, ""); - return error; -} - -static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name); - -static int refdb_fs_backend__rename( - git_reference **out, - git_refdb_backend *_backend, - const char *old_name, - const char *new_name, - int force, - const git_signature *who, - const char *message) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - git_reference *old, *new = NULL; - git_filebuf file = GIT_FILEBUF_INIT; - int error; - - GIT_ASSERT_ARG(backend); - - if ((error = reference_path_available( - backend, new_name, old_name, force)) < 0 || - (error = refdb_fs_backend__lookup(&old, _backend, old_name)) < 0) - return error; - - if ((error = loose_lock(&file, backend, old->name)) < 0) { - git_reference_free(old); - return error; - } - - new = git_reference__realloc(&old, new_name); - if (!new) { - git_reference_free(old); - git_filebuf_cleanup(&file); - return -1; - } - - if ((error = refdb_fs_backend__delete_tail(_backend, &file, old_name, NULL, NULL)) < 0) { - git_reference_free(new); - git_filebuf_cleanup(&file); - return error; - } - - if ((error = loose_lock(&file, backend, new_name)) < 0) { - git_reference_free(new); - return error; - } - - /* Try to rename the refog; it's ok if the old doesn't exist */ - error = refdb_reflog_fs__rename(_backend, old_name, new_name); - if (((error == 0) || (error == GIT_ENOTFOUND)) && - ((error = reflog_append(backend, new, git_reference_target(new), NULL, who, message)) < 0)) { - git_reference_free(new); - git_filebuf_cleanup(&file); - return error; - } - - if ((error = loose_commit(&file, new)) < 0 || out == NULL) { - git_reference_free(new); - git_filebuf_cleanup(&file); - return error; - } - - *out = new; - return 0; -} - -static int refdb_fs_backend__compress(git_refdb_backend *_backend) -{ - int error; - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - - GIT_ASSERT_ARG(backend); - - if ((error = packed_reload(backend)) < 0 || /* load the existing packfile */ - (error = packed_loadloose(backend)) < 0 || /* add all the loose refs */ - (error = packed_write(backend)) < 0) /* write back to disk */ - return error; - - return 0; -} - -static void refdb_fs_backend__free(git_refdb_backend *_backend) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - - if (!backend) - return; - - git_sortedcache_free(backend->refcache); - - git_mutex_lock(&backend->prlock); - packed_map_free(backend); - git_mutex_unlock(&backend->prlock); - git_mutex_free(&backend->prlock); - - git__free(backend->gitpath); - git__free(backend->commonpath); - git__free(backend); -} - -static char *setup_namespace(git_repository *repo, const char *in) -{ - git_str path = GIT_STR_INIT; - char *parts, *start, *end, *out = NULL; - - if (!in) - goto done; - - git_str_puts(&path, in); - - /* if the repo is not namespaced, nothing else to do */ - if (repo->namespace == NULL) { - out = git_str_detach(&path); - goto done; - } - - parts = end = git__strdup(repo->namespace); - if (parts == NULL) - goto done; - - /* - * From `man gitnamespaces`: - * namespaces which include a / will expand to a hierarchy - * of namespaces; for example, GIT_NAMESPACE=foo/bar will store - * refs under refs/namespaces/foo/refs/namespaces/bar/ - */ - while ((start = git__strsep(&end, "/")) != NULL) - git_str_printf(&path, "refs/namespaces/%s/", start); - - git_str_printf(&path, "refs/namespaces/%s/refs", end); - git__free(parts); - - /* Make sure that the folder with the namespace exists */ - if (git_futils_mkdir_relative(git_str_cstr(&path), in, 0777, - GIT_MKDIR_PATH, NULL) < 0) - goto done; - - /* Return root of the namespaced gitpath, i.e. without the trailing 'refs' */ - git_str_rtruncate_at_char(&path, '/'); - git_str_putc(&path, '/'); - out = git_str_detach(&path); - -done: - git_str_dispose(&path); - return out; -} - -static int reflog_alloc( - git_reflog **reflog, - const char *name, - git_oid_t oid_type) -{ - git_reflog *log; - - *reflog = NULL; - - log = git__calloc(1, sizeof(git_reflog)); - GIT_ERROR_CHECK_ALLOC(log); - - log->ref_name = git__strdup(name); - GIT_ERROR_CHECK_ALLOC(log->ref_name); - - log->oid_type = oid_type; - - if (git_vector_init(&log->entries, 0, NULL) < 0) { - git__free(log->ref_name); - git__free(log); - return -1; - } - - *reflog = log; - - return 0; -} - -static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size) -{ - git_parse_ctx parser = GIT_PARSE_CTX_INIT; - - if ((git_parse_ctx_init(&parser, buf, buf_size)) < 0) - return -1; - - for (; parser.remain_len; git_parse_advance_line(&parser)) { - git_reflog_entry *entry; - const char *sig; - char c; - - entry = git__calloc(1, sizeof(*entry)); - GIT_ERROR_CHECK_ALLOC(entry); - entry->committer = git__calloc(1, sizeof(*entry->committer)); - GIT_ERROR_CHECK_ALLOC(entry->committer); - - if (git_parse_advance_oid(&entry->oid_old, &parser, log->oid_type) < 0 || - git_parse_advance_expected(&parser, " ", 1) < 0 || - git_parse_advance_oid(&entry->oid_cur, &parser, log->oid_type) < 0) - goto next; - - sig = parser.line; - while (git_parse_peek(&c, &parser, 0) == 0 && c != '\t' && c != '\n') - git_parse_advance_chars(&parser, 1); - - if (git_signature__parse(entry->committer, &sig, parser.line, NULL, 0) < 0) - goto next; - - if (c == '\t') { - size_t len; - git_parse_advance_chars(&parser, 1); - - len = parser.line_len; - if (parser.line[len - 1] == '\n') - len--; - - entry->msg = git__strndup(parser.line, len); - GIT_ERROR_CHECK_ALLOC(entry->msg); - } - - if ((git_vector_insert(&log->entries, entry)) < 0) { - git_reflog_entry__free(entry); - return -1; - } - - continue; - -next: - git_reflog_entry__free(entry); - } - - return 0; -} - -static int create_new_reflog_file(const char *filepath) -{ - int fd, error; - - if ((error = git_futils_mkpath2file(filepath, GIT_REFLOG_DIR_MODE)) < 0) - return error; - - if ((fd = p_open(filepath, - O_WRONLY | O_CREAT, - GIT_REFLOG_FILE_MODE)) < 0) - return -1; - - return p_close(fd); -} - -static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *name) -{ - refdb_fs_backend *backend; - git_repository *repo; - git_str path = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(_backend && name); - - backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - repo = backend->repo; - - if ((error = reflog_path(&path, repo, name)) < 0) - return error; - - error = create_new_reflog_file(git_str_cstr(&path)); - git_str_dispose(&path); - - return error; -} - -static int has_reflog(git_repository *repo, const char *name) -{ - int ret = 0; - git_str path = GIT_STR_INIT; - - if (reflog_path(&path, repo, name) < 0) - goto cleanup; - - ret = git_fs_path_isfile(git_str_cstr(&path)); - -cleanup: - git_str_dispose(&path); - return ret; -} - -static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *name) -{ - refdb_fs_backend *backend; - - GIT_ASSERT_ARG(_backend); - GIT_ASSERT_ARG(name); - - backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - - return has_reflog(backend->repo, name); -} - -static int refdb_reflog_fs__read( - git_reflog **out, - git_refdb_backend *_backend, - const char *name) -{ - int error = -1; - git_str log_path = GIT_STR_INIT; - git_str log_file = GIT_STR_INIT; - git_reflog *log = NULL; - git_repository *repo; - refdb_fs_backend *backend; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(_backend); - GIT_ASSERT_ARG(name); - - backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - repo = backend->repo; - - if (reflog_alloc(&log, name, backend->oid_type) < 0) - return -1; - - if (reflog_path(&log_path, repo, name) < 0) - goto cleanup; - - error = git_futils_readbuffer(&log_file, git_str_cstr(&log_path)); - if (error < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - if ((error == GIT_ENOTFOUND) && - ((error = create_new_reflog_file(git_str_cstr(&log_path))) < 0)) - goto cleanup; - - if ((error = reflog_parse(log, - git_str_cstr(&log_file), git_str_len(&log_file))) < 0) - goto cleanup; - - *out = log; - goto success; - -cleanup: - git_reflog_free(log); - -success: - git_str_dispose(&log_file); - git_str_dispose(&log_path); - - return error; -} - -static int serialize_reflog_entry( - git_str *buf, - const git_oid *oid_old, - const git_oid *oid_new, - const git_signature *committer, - const char *msg) -{ - char raw_old[GIT_OID_MAX_HEXSIZE + 1]; - char raw_new[GIT_OID_MAX_HEXSIZE + 1]; - - git_oid_tostr(raw_old, GIT_OID_MAX_HEXSIZE + 1, oid_old); - git_oid_tostr(raw_new, GIT_OID_MAX_HEXSIZE + 1, oid_new); - - git_str_clear(buf); - - git_str_puts(buf, raw_old); - git_str_putc(buf, ' '); - git_str_puts(buf, raw_new); - - git_signature__writebuf(buf, " ", committer); - - /* drop trailing LF */ - git_str_rtrim(buf); - - if (msg) { - size_t i; - - git_str_putc(buf, '\t'); - git_str_puts(buf, msg); - - for (i = 0; i < buf->size - 2; i++) - if (buf->ptr[i] == '\n') - buf->ptr[i] = ' '; - git_str_rtrim(buf); - } - - git_str_putc(buf, '\n'); - - return git_str_oom(buf); -} - -static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char *refname) -{ - git_repository *repo; - git_str log_path = GIT_STR_INIT; - int error; - - repo = backend->repo; - - if (!git_path_is_valid(backend->repo, refname, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) { - git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname); - return GIT_EINVALIDSPEC; - } - - if (reflog_path(&log_path, repo, refname) < 0) - return -1; - - if (!git_fs_path_isfile(git_str_cstr(&log_path))) { - git_error_set(GIT_ERROR_INVALID, - "log file for reference '%s' doesn't exist", refname); - error = -1; - goto cleanup; - } - - error = git_filebuf_open(file, git_str_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE); - -cleanup: - git_str_dispose(&log_path); - - return error; -} - -static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflog) -{ - int error = -1; - unsigned int i; - git_reflog_entry *entry; - refdb_fs_backend *backend; - git_str log = GIT_STR_INIT; - git_filebuf fbuf = GIT_FILEBUF_INIT; - - GIT_ASSERT_ARG(_backend); - GIT_ASSERT_ARG(reflog); - - backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - - if ((error = lock_reflog(&fbuf, backend, reflog->ref_name)) < 0) - return -1; - - git_vector_foreach(&reflog->entries, i, entry) { - if (serialize_reflog_entry(&log, &(entry->oid_old), &(entry->oid_cur), entry->committer, entry->msg) < 0) - goto cleanup; - - if ((error = git_filebuf_write(&fbuf, log.ptr, log.size)) < 0) - goto cleanup; - } - - error = git_filebuf_commit(&fbuf); - goto success; - -cleanup: - git_filebuf_cleanup(&fbuf); - -success: - git_str_dispose(&log); - - return error; -} - -/* Append to the reflog, must be called under reference lock */ -static int reflog_append( - refdb_fs_backend *backend, - const git_reference *ref, - const git_oid *old, - const git_oid *new, - const git_signature *who, - const char *message) -{ - int error, is_symbolic, open_flags; - git_oid old_id, new_id; - git_str buf = GIT_STR_INIT, path = GIT_STR_INIT; - git_repository *repo = backend->repo; - - is_symbolic = ref->type == GIT_REFERENCE_SYMBOLIC; - - /* "normal" symbolic updates do not write */ - if (is_symbolic && - strcmp(ref->name, GIT_HEAD_FILE) && - !(old && new)) - return 0; - - /* From here on is_symbolic also means that it's HEAD */ - - git_oid_clear(&old_id, backend->oid_type); - git_oid_clear(&new_id, backend->oid_type); - - if (old) { - git_oid_cpy(&old_id, old); - } else { - error = git_reference_name_to_id(&old_id, repo, ref->name); - if (error < 0 && error != GIT_ENOTFOUND) - return error; - } - - if (new) { - git_oid_cpy(&new_id, new); - } else { - if (!is_symbolic) { - git_oid_cpy(&new_id, git_reference_target(ref)); - } else { - error = git_reference_name_to_id(&new_id, repo, git_reference_symbolic_target(ref)); - if (error < 0 && error != GIT_ENOTFOUND) - return error; - /* detaching HEAD does not create an entry */ - if (error == GIT_ENOTFOUND) - return 0; - - git_error_clear(); - } - } - - if ((error = serialize_reflog_entry(&buf, &old_id, &new_id, who, message)) < 0) - goto cleanup; - - if ((error = reflog_path(&path, repo, ref->name)) < 0) - goto cleanup; - - if (((error = git_futils_mkpath2file(git_str_cstr(&path), 0777)) < 0) && - (error != GIT_EEXISTS)) { - goto cleanup; - } - - /* If the new branch matches part of the namespace of a previously deleted branch, - * there maybe an obsolete/unused directory (or directory hierarchy) in the way. - */ - if (git_fs_path_isdir(git_str_cstr(&path))) { - if ((error = git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) { - if (error == GIT_ENOTFOUND) - error = 0; - } else if (git_fs_path_isdir(git_str_cstr(&path))) { - git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder", - ref->name); - error = GIT_EDIRECTORY; - } - - if (error != 0) - goto cleanup; - } - - open_flags = O_WRONLY | O_CREAT | O_APPEND; - - if (backend->fsync) - open_flags |= O_FSYNC; - - error = git_futils_writebuffer(&buf, git_str_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE); - -cleanup: - git_str_dispose(&buf); - git_str_dispose(&path); - - return error; -} - -static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name) -{ - int error = 0, fd; - git_str old_path = GIT_STR_INIT; - git_str new_path = GIT_STR_INIT; - git_str temp_path = GIT_STR_INIT; - git_str normalized = GIT_STR_INIT; - git_repository *repo; - refdb_fs_backend *backend; - - GIT_ASSERT_ARG(_backend); - GIT_ASSERT_ARG(old_name); - GIT_ASSERT_ARG(new_name); - - backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - repo = backend->repo; - - if ((error = git_reference__normalize_name( - &normalized, new_name, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) < 0) - return error; - - if (git_str_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0) - return -1; - - if ((error = loose_path(&old_path, git_str_cstr(&temp_path), old_name)) < 0) - return error; - - if ((error = loose_path(&new_path, git_str_cstr(&temp_path), git_str_cstr(&normalized))) < 0) - return error; - - if (!git_fs_path_exists(git_str_cstr(&old_path))) { - error = GIT_ENOTFOUND; - goto cleanup; - } - - /* - * Move the reflog to a temporary place. This two-phase renaming is required - * in order to cope with funny renaming use cases when one tries to move a reference - * to a partially colliding namespace: - * - a/b -> a/b/c - * - a/b/c/d -> a/b/c - */ - if ((error = loose_path(&temp_path, git_str_cstr(&temp_path), "temp_reflog")) < 0) - return error; - - if ((fd = git_futils_mktmp(&temp_path, git_str_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) { - error = -1; - goto cleanup; - } - - p_close(fd); - - if (p_rename(git_str_cstr(&old_path), git_str_cstr(&temp_path)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name); - error = -1; - goto cleanup; - } - - if (git_fs_path_isdir(git_str_cstr(&new_path)) && - (git_futils_rmdir_r(git_str_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) { - error = -1; - goto cleanup; - } - - if (git_futils_mkpath2file(git_str_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) { - error = -1; - goto cleanup; - } - - if (p_rename(git_str_cstr(&temp_path), git_str_cstr(&new_path)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name); - error = -1; - } - -cleanup: - git_str_dispose(&temp_path); - git_str_dispose(&old_path); - git_str_dispose(&new_path); - git_str_dispose(&normalized); - - return error; -} - -static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name) -{ - refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); - git_str path = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(_backend); - GIT_ASSERT_ARG(name); - - if ((error = reflog_path(&path, backend->repo, name)) < 0) - goto out; - - /* - * If a reference was moved downwards, eg refs/heads/br2 -> refs/heads/br2/new-name, - * refs/heads/br2 does exist but it's a directory. That's a valid situation. - * Proceed only if it's a file. - */ - if (!git_fs_path_isfile(path.ptr)) - goto out; - - if ((error = p_unlink(path.ptr)) < 0) - goto out; - - error = refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR); - -out: - git_str_dispose(&path); - - return error; -} - -int git_refdb_backend_fs( - git_refdb_backend **backend_out, - git_repository *repository) -{ - int t = 0; - git_str gitpath = GIT_STR_INIT; - refdb_fs_backend *backend; - - backend = git__calloc(1, sizeof(refdb_fs_backend)); - GIT_ERROR_CHECK_ALLOC(backend); - if (git_mutex_init(&backend->prlock) < 0) { - git__free(backend); - return -1; - } - - - if (git_refdb_init_backend(&backend->parent, GIT_REFDB_BACKEND_VERSION) < 0) - goto fail; - - backend->repo = repository; - backend->oid_type = repository->oid_type; - - if (repository->gitdir) { - backend->gitpath = setup_namespace(repository, repository->gitdir); - - if (backend->gitpath == NULL) - goto fail; - } - - if (repository->commondir) { - backend->commonpath = setup_namespace(repository, repository->commondir); - - if (backend->commonpath == NULL) - goto fail; - } - - if (git_str_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 || - git_sortedcache_new( - &backend->refcache, offsetof(struct packref, name), - NULL, NULL, packref_cmp, git_str_cstr(&gitpath)) < 0) - goto fail; - - git_str_dispose(&gitpath); - - if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) { - backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE; - backend->direach_flags |= GIT_FS_PATH_DIR_IGNORE_CASE; - } - if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_PRECOMPOSE) && t) { - backend->iterator_flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE; - backend->direach_flags |= GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE; - } - if ((!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) || - git_repository__fsync_gitdir) - backend->fsync = 1; - backend->iterator_flags |= GIT_ITERATOR_DESCEND_SYMLINKS; - - backend->parent.exists = &refdb_fs_backend__exists; - backend->parent.lookup = &refdb_fs_backend__lookup; - backend->parent.iterator = &refdb_fs_backend__iterator; - backend->parent.write = &refdb_fs_backend__write; - backend->parent.del = &refdb_fs_backend__delete; - backend->parent.rename = &refdb_fs_backend__rename; - backend->parent.compress = &refdb_fs_backend__compress; - backend->parent.lock = &refdb_fs_backend__lock; - backend->parent.unlock = &refdb_fs_backend__unlock; - backend->parent.has_log = &refdb_reflog_fs__has_log; - backend->parent.ensure_log = &refdb_reflog_fs__ensure_log; - backend->parent.free = &refdb_fs_backend__free; - backend->parent.reflog_read = &refdb_reflog_fs__read; - backend->parent.reflog_write = &refdb_reflog_fs__write; - backend->parent.reflog_rename = &refdb_reflog_fs__rename; - backend->parent.reflog_delete = &refdb_reflog_fs__delete; - - *backend_out = (git_refdb_backend *)backend; - return 0; - -fail: - git_mutex_free(&backend->prlock); - git_str_dispose(&gitpath); - git__free(backend->gitpath); - git__free(backend->commonpath); - git__free(backend); - return -1; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/reflog.c b/vendor/libgit2-sys/libgit2/src/libgit2/reflog.c deleted file mode 100644 index b998172..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/reflog.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "reflog.h" - -#include "repository.h" -#include "filebuf.h" -#include "signature.h" -#include "refdb.h" - -#include "git2/sys/refdb_backend.h" - -void git_reflog_entry__free(git_reflog_entry *entry) -{ - git_signature_free(entry->committer); - - git__free(entry->msg); - git__free(entry); -} - -void git_reflog_free(git_reflog *reflog) -{ - size_t i; - git_reflog_entry *entry; - - if (reflog == NULL) - return; - - if (reflog->db) - GIT_REFCOUNT_DEC(reflog->db, git_refdb__free); - - for (i=0; i < reflog->entries.length; i++) { - entry = git_vector_get(&reflog->entries, i); - - git_reflog_entry__free(entry); - } - - git_vector_dispose(&reflog->entries); - git__free(reflog->ref_name); - git__free(reflog); -} - -int git_reflog_read(git_reflog **reflog, git_repository *repo, const char *name) -{ - git_refdb *refdb; - int error; - - GIT_ASSERT_ARG(reflog); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) - return error; - - return git_refdb_reflog_read(reflog, refdb, name); -} - -int git_reflog_write(git_reflog *reflog) -{ - git_refdb *db; - - GIT_ASSERT_ARG(reflog); - GIT_ASSERT_ARG(reflog->db); - - db = reflog->db; - return db->backend->reflog_write(db->backend, reflog); -} - -int git_reflog_append( - git_reflog *reflog, - const git_oid *new_oid, - const git_signature *committer, - const char *msg) -{ - const git_reflog_entry *previous; - git_reflog_entry *entry; - - GIT_ASSERT_ARG(reflog); - GIT_ASSERT_ARG(new_oid); - GIT_ASSERT_ARG(committer); - - entry = git__calloc(1, sizeof(git_reflog_entry)); - GIT_ERROR_CHECK_ALLOC(entry); - - if ((git_signature_dup(&entry->committer, committer)) < 0) - goto cleanup; - - if (msg != NULL) { - size_t i, msglen = strlen(msg); - - if ((entry->msg = git__strndup(msg, msglen)) == NULL) - goto cleanup; - - /* - * Replace all newlines with spaces, except for - * the final trailing newline. - */ - for (i = 0; i < msglen; i++) - if (entry->msg[i] == '\n') - entry->msg[i] = ' '; - } - - previous = git_reflog_entry_byindex(reflog, 0); - - if (previous == NULL) - git_oid_clear(&entry->oid_old, reflog->oid_type); - else - git_oid_cpy(&entry->oid_old, &previous->oid_cur); - - git_oid_cpy(&entry->oid_cur, new_oid); - - if (git_vector_insert(&reflog->entries, entry) < 0) - goto cleanup; - - return 0; - -cleanup: - git_reflog_entry__free(entry); - return -1; -} - -int git_reflog_rename(git_repository *repo, const char *old_name, const char *new_name) -{ - git_refdb *refdb; - int error; - - if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) - return -1; - - return refdb->backend->reflog_rename(refdb->backend, old_name, new_name); -} - -int git_reflog_delete(git_repository *repo, const char *name) -{ - git_refdb *refdb; - int error; - - if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) - return -1; - - return refdb->backend->reflog_delete(refdb->backend, name); -} - -size_t git_reflog_entrycount(git_reflog *reflog) -{ - GIT_ASSERT_ARG_WITH_RETVAL(reflog, 0); - return reflog->entries.length; -} - -const git_reflog_entry *git_reflog_entry_byindex(const git_reflog *reflog, size_t idx) -{ - GIT_ASSERT_ARG_WITH_RETVAL(reflog, NULL); - - if (idx >= reflog->entries.length) - return NULL; - - return git_vector_get( - &reflog->entries, reflog_inverse_index(idx, reflog->entries.length)); -} - -const git_oid *git_reflog_entry_id_old(const git_reflog_entry *entry) -{ - GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL); - return &entry->oid_old; -} - -const git_oid *git_reflog_entry_id_new(const git_reflog_entry *entry) -{ - GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL); - return &entry->oid_cur; -} - -const git_signature *git_reflog_entry_committer(const git_reflog_entry *entry) -{ - GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL); - return entry->committer; -} - -const char *git_reflog_entry_message(const git_reflog_entry *entry) -{ - GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL); - return entry->msg; -} - -int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry) -{ - size_t entrycount; - git_reflog_entry *entry, *previous; - - entrycount = git_reflog_entrycount(reflog); - - entry = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx); - - if (entry == NULL) { - git_error_set(GIT_ERROR_REFERENCE, "no reflog entry at index %"PRIuZ, idx); - return GIT_ENOTFOUND; - } - - git_reflog_entry__free(entry); - - if (git_vector_remove( - &reflog->entries, reflog_inverse_index(idx, entrycount)) < 0) - return -1; - - if (!rewrite_previous_entry) - return 0; - - /* No need to rewrite anything when removing the most recent entry */ - if (idx == 0) - return 0; - - /* Have the latest entry just been dropped? */ - if (entrycount == 1) - return 0; - - entry = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx - 1); - - /* If the oldest entry has just been removed... */ - if (idx == entrycount - 1) { - /* ...clear the oid_old member of the "new" oldest entry */ - git_oid_clear(&entry->oid_old, reflog->oid_type); - return 0; - } - - previous = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx); - git_oid_cpy(&entry->oid_old, &previous->oid_cur); - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/reflog.h b/vendor/libgit2-sys/libgit2/src/libgit2/reflog.h deleted file mode 100644 index ab3afdf..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/reflog.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_reflog_h__ -#define INCLUDE_reflog_h__ - -#include "common.h" - -#include "git2/reflog.h" -#include "vector.h" - -#define GIT_REFLOG_DIR "logs/" -#define GIT_REFLOG_DIR_MODE 0777 -#define GIT_REFLOG_FILE_MODE 0666 - -struct git_reflog_entry { - git_oid oid_old; - git_oid oid_cur; - - git_signature *committer; - - char *msg; -}; - -struct git_reflog { - git_refdb *db; - char *ref_name; - git_oid_t oid_type; - git_vector entries; -}; - -GIT_INLINE(size_t) reflog_inverse_index(size_t idx, size_t total) -{ - return (total - 1) - idx; -} - -void git_reflog_entry__free(git_reflog_entry *entry); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/refs.c b/vendor/libgit2-sys/libgit2/src/libgit2/refs.c deleted file mode 100644 index 89421e5..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/refs.c +++ /dev/null @@ -1,1432 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "refs.h" - -#include "hash.h" -#include "repository.h" -#include "futils.h" -#include "filebuf.h" -#include "pack.h" -#include "reflog.h" -#include "refdb.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -bool git_reference__enable_symbolic_ref_target_validation = true; - -enum { - GIT_PACKREF_HAS_PEEL = 1, - GIT_PACKREF_WAS_LOOSE = 2 -}; - -static git_reference *alloc_ref(const char *name) -{ - git_reference *ref = NULL; - size_t namelen = strlen(name), reflen; - - if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) && - !GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) && - (ref = git__calloc(1, reflen)) != NULL) - memcpy(ref->name, name, namelen + 1); - - return ref; -} - -git_reference *git_reference__alloc_symbolic( - const char *name, const char *target) -{ - git_reference *ref; - - GIT_ASSERT_ARG_WITH_RETVAL(name, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(target, NULL); - - ref = alloc_ref(name); - if (!ref) - return NULL; - - ref->type = GIT_REFERENCE_SYMBOLIC; - - if ((ref->target.symbolic = git__strdup(target)) == NULL) { - git__free(ref); - return NULL; - } - - return ref; -} - -git_reference *git_reference__alloc( - const char *name, - const git_oid *oid, - const git_oid *peel) -{ - git_oid_t oid_type; - git_reference *ref; - - GIT_ASSERT_ARG_WITH_RETVAL(name, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(oid, NULL); - - ref = alloc_ref(name); - if (!ref) - return NULL; - - ref->type = GIT_REFERENCE_DIRECT; - git_oid_cpy(&ref->target.oid, oid); - -#ifdef GIT_EXPERIMENTAL_SHA256 - oid_type = oid->type; -#else - oid_type = GIT_OID_SHA1; -#endif - - if (peel != NULL) - git_oid_cpy(&ref->peel, peel); - else - git_oid_clear(&ref->peel, oid_type); - - return ref; -} - -git_reference *git_reference__realloc( - git_reference **ptr_to_ref, const char *name) -{ - size_t namelen, reflen; - git_reference *rewrite = NULL; - - GIT_ASSERT_ARG_WITH_RETVAL(ptr_to_ref, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(name, NULL); - - namelen = strlen(name); - - if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) && - !GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) && - (rewrite = git__realloc(*ptr_to_ref, reflen)) != NULL) - memcpy(rewrite->name, name, namelen + 1); - - *ptr_to_ref = NULL; - - return rewrite; -} - -int git_reference_dup(git_reference **dest, git_reference *source) -{ - if (source->type == GIT_REFERENCE_SYMBOLIC) - *dest = git_reference__alloc_symbolic(source->name, source->target.symbolic); - else - *dest = git_reference__alloc(source->name, &source->target.oid, &source->peel); - - GIT_ERROR_CHECK_ALLOC(*dest); - - (*dest)->db = source->db; - GIT_REFCOUNT_INC((*dest)->db); - - return 0; -} - -void git_reference_free(git_reference *reference) -{ - if (reference == NULL) - return; - - if (reference->type == GIT_REFERENCE_SYMBOLIC) - git__free(reference->target.symbolic); - - if (reference->db) - GIT_REFCOUNT_DEC(reference->db, git_refdb__free); - - git__free(reference); -} - -int git_reference_delete(git_reference *ref) -{ - const git_oid *old_id = NULL; - const char *old_target = NULL; - - if (!strcmp(ref->name, "HEAD")) { - git_error_set(GIT_ERROR_REFERENCE, "cannot delete HEAD"); - return GIT_ERROR; - } - - if (ref->type == GIT_REFERENCE_DIRECT) - old_id = &ref->target.oid; - else - old_target = ref->target.symbolic; - - return git_refdb_delete(ref->db, ref->name, old_id, old_target); -} - -int git_reference_remove(git_repository *repo, const char *name) -{ - git_refdb *db; - int error; - - if ((error = git_repository_refdb__weakptr(&db, repo)) < 0) - return error; - - return git_refdb_delete(db, name, NULL, NULL); -} - -int git_reference_lookup(git_reference **ref_out, - git_repository *repo, const char *name) -{ - return git_reference_lookup_resolved(ref_out, repo, name, 0); -} - -int git_reference_name_to_id( - git_oid *out, git_repository *repo, const char *name) -{ - int error; - git_reference *ref; - - if ((error = git_reference_lookup_resolved(&ref, repo, name, -1)) < 0) - return error; - - git_oid_cpy(out, git_reference_target(ref)); - git_reference_free(ref); - return 0; -} - -static int reference_normalize_for_repo( - git_refname_t out, - git_repository *repo, - const char *name, - bool validate) -{ - int precompose; - unsigned int flags = GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL; - - if (!git_repository__configmap_lookup(&precompose, repo, GIT_CONFIGMAP_PRECOMPOSE) && - precompose) - flags |= GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE; - - if (!validate) - flags |= GIT_REFERENCE_FORMAT__VALIDATION_DISABLE; - - return git_reference_normalize_name(out, GIT_REFNAME_MAX, name, flags); -} - -int git_reference_lookup_resolved( - git_reference **ref_out, - git_repository *repo, - const char *name, - int max_nesting) -{ - git_refname_t normalized; - git_refdb *refdb; - int error = 0; - - GIT_ASSERT_ARG(ref_out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - if ((error = reference_normalize_for_repo(normalized, repo, name, true)) < 0 || - (error = git_repository_refdb__weakptr(&refdb, repo)) < 0 || - (error = git_refdb_resolve(ref_out, refdb, normalized, max_nesting)) < 0) - return error; - - /* - * The resolved reference may be a symbolic reference in case its - * target doesn't exist. If the user asked us to resolve (e.g. - * `max_nesting != 0`), then we need to return an error in case we got - * a symbolic reference back. - */ - if (max_nesting && git_reference_type(*ref_out) == GIT_REFERENCE_SYMBOLIC) { - git_reference_free(*ref_out); - *ref_out = NULL; - return GIT_ENOTFOUND; - } - - return 0; -} - -int git_reference_dwim(git_reference **out, git_repository *repo, const char *refname) -{ - int error = 0, i, valid; - bool fallbackmode = true, foundvalid = false; - git_reference *ref; - git_str refnamebuf = GIT_STR_INIT, name = GIT_STR_INIT; - - static const char *formatters[] = { - "%s", - GIT_REFS_DIR "%s", - GIT_REFS_TAGS_DIR "%s", - GIT_REFS_HEADS_DIR "%s", - GIT_REFS_REMOTES_DIR "%s", - GIT_REFS_REMOTES_DIR "%s/" GIT_HEAD_FILE, - NULL - }; - - if (*refname) - git_str_puts(&name, refname); - else { - git_str_puts(&name, GIT_HEAD_FILE); - fallbackmode = false; - } - - for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) { - - git_str_clear(&refnamebuf); - - if ((error = git_str_printf(&refnamebuf, formatters[i], git_str_cstr(&name))) < 0 || - (error = git_reference_name_is_valid(&valid, git_str_cstr(&refnamebuf))) < 0) - goto cleanup; - - if (!valid) { - error = GIT_EINVALIDSPEC; - continue; - } - foundvalid = true; - - error = git_reference_lookup_resolved(&ref, repo, git_str_cstr(&refnamebuf), -1); - - if (!error) { - *out = ref; - error = 0; - goto cleanup; - } - - if (error != GIT_ENOTFOUND) - goto cleanup; - } - -cleanup: - if (error && !foundvalid) { - /* never found a valid reference name */ - git_error_set(GIT_ERROR_REFERENCE, - "could not use '%s' as valid reference name", git_str_cstr(&name)); - } - - if (error == GIT_ENOTFOUND) - git_error_set(GIT_ERROR_REFERENCE, "no reference found for shorthand '%s'", refname); - - git_str_dispose(&name); - git_str_dispose(&refnamebuf); - return error; -} - -/** - * Getters - */ -git_reference_t git_reference_type(const git_reference *ref) -{ - GIT_ASSERT_ARG(ref); - return ref->type; -} - -const char *git_reference_name(const git_reference *ref) -{ - GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); - return ref->name; -} - -git_repository *git_reference_owner(const git_reference *ref) -{ - GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); - return ref->db->repo; -} - -const git_oid *git_reference_target(const git_reference *ref) -{ - GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); - - if (ref->type != GIT_REFERENCE_DIRECT) - return NULL; - - return &ref->target.oid; -} - -const git_oid *git_reference_target_peel(const git_reference *ref) -{ - GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); - - if (ref->type != GIT_REFERENCE_DIRECT || git_oid_is_zero(&ref->peel)) - return NULL; - - return &ref->peel; -} - -const char *git_reference_symbolic_target(const git_reference *ref) -{ - GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); - - if (ref->type != GIT_REFERENCE_SYMBOLIC) - return NULL; - - return ref->target.symbolic; -} - -static int reference__create( - git_reference **ref_out, - git_repository *repo, - const char *name, - const git_oid *oid, - const char *symbolic, - int force, - const git_signature *signature, - const char *log_message, - const git_oid *old_id, - const char *old_target) -{ - git_refname_t normalized; - git_refdb *refdb; - git_reference *ref = NULL; - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - GIT_ASSERT_ARG(symbolic || signature); - - if (ref_out) - *ref_out = NULL; - - error = reference_normalize_for_repo(normalized, repo, name, true); - if (error < 0) - return error; - - error = git_repository_refdb__weakptr(&refdb, repo); - if (error < 0) - return error; - - if (oid != NULL) { - GIT_ASSERT(symbolic == NULL); - - if (!git_object__is_valid(repo, oid, GIT_OBJECT_ANY)) { - git_error_set(GIT_ERROR_REFERENCE, - "target OID for the reference doesn't exist on the repository"); - return -1; - } - - ref = git_reference__alloc(normalized, oid, NULL); - } else { - git_refname_t normalized_target; - - error = reference_normalize_for_repo(normalized_target, repo, - symbolic, git_reference__enable_symbolic_ref_target_validation); - - if (error < 0) - return error; - - ref = git_reference__alloc_symbolic(normalized, normalized_target); - } - - GIT_ERROR_CHECK_ALLOC(ref); - - if ((error = git_refdb_write(refdb, ref, force, signature, log_message, old_id, old_target)) < 0) { - git_reference_free(ref); - return error; - } - - if (ref_out == NULL) - git_reference_free(ref); - else - *ref_out = ref; - - return 0; -} - -static int refs_configured_ident(git_signature **out, const git_repository *repo) -{ - if (repo->ident_name && repo->ident_email) - return git_signature_now(out, repo->ident_name, repo->ident_email); - - /* if not configured let us fall-through to the next method */ - return -1; -} - -int git_reference__log_signature(git_signature **out, git_repository *repo) -{ - int error; - git_signature *who; - - if(((error = refs_configured_ident(&who, repo)) < 0) && - ((error = git_signature_default(&who, repo)) < 0) && - ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) - return error; - - *out = who; - return 0; -} - -int git_reference_create_matching( - git_reference **ref_out, - git_repository *repo, - const char *name, - const git_oid *id, - int force, - const git_oid *old_id, - const char *log_message) - -{ - int error; - git_signature *who = NULL; - - GIT_ASSERT_ARG(id); - - if ((error = git_reference__log_signature(&who, repo)) < 0) - return error; - - error = reference__create( - ref_out, repo, name, id, NULL, force, who, log_message, old_id, NULL); - - git_signature_free(who); - return error; -} - -int git_reference_create( - git_reference **ref_out, - git_repository *repo, - const char *name, - const git_oid *id, - int force, - const char *log_message) -{ - return git_reference_create_matching(ref_out, repo, name, id, force, NULL, log_message); -} - -int git_reference_symbolic_create_matching( - git_reference **ref_out, - git_repository *repo, - const char *name, - const char *target, - int force, - const char *old_target, - const char *log_message) -{ - int error; - git_signature *who = NULL; - - GIT_ASSERT_ARG(target); - - if ((error = git_reference__log_signature(&who, repo)) < 0) - return error; - - error = reference__create( - ref_out, repo, name, NULL, target, force, who, log_message, NULL, old_target); - - git_signature_free(who); - return error; -} - -int git_reference_symbolic_create( - git_reference **ref_out, - git_repository *repo, - const char *name, - const char *target, - int force, - const char *log_message) -{ - return git_reference_symbolic_create_matching(ref_out, repo, name, target, force, NULL, log_message); -} - -static int ensure_is_an_updatable_direct_reference(git_reference *ref) -{ - if (ref->type == GIT_REFERENCE_DIRECT) - return 0; - - git_error_set(GIT_ERROR_REFERENCE, "cannot set OID on symbolic reference"); - return -1; -} - -int git_reference_set_target( - git_reference **out, - git_reference *ref, - const git_oid *id, - const char *log_message) -{ - int error; - git_repository *repo; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(ref); - GIT_ASSERT_ARG(id); - - repo = ref->db->repo; - - if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0) - return error; - - return git_reference_create_matching(out, repo, ref->name, id, 1, &ref->target.oid, log_message); -} - -static int ensure_is_an_updatable_symbolic_reference(git_reference *ref) -{ - if (ref->type == GIT_REFERENCE_SYMBOLIC) - return 0; - - git_error_set(GIT_ERROR_REFERENCE, "cannot set symbolic target on a direct reference"); - return -1; -} - -int git_reference_symbolic_set_target( - git_reference **out, - git_reference *ref, - const char *target, - const char *log_message) -{ - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(ref); - GIT_ASSERT_ARG(target); - - if ((error = ensure_is_an_updatable_symbolic_reference(ref)) < 0) - return error; - - return git_reference_symbolic_create_matching( - out, ref->db->repo, ref->name, target, 1, ref->target.symbolic, log_message); -} - -typedef struct { - const char *old_name; - git_refname_t new_name; -} refs_update_head_payload; - -static int refs_update_head(git_repository *worktree, void *_payload) -{ - refs_update_head_payload *payload = (refs_update_head_payload *)_payload; - git_reference *head = NULL, *updated = NULL; - int error; - - if ((error = git_reference_lookup(&head, worktree, GIT_HEAD_FILE)) < 0) - goto out; - - if (git_reference_type(head) != GIT_REFERENCE_SYMBOLIC || - git__strcmp(git_reference_symbolic_target(head), payload->old_name) != 0) - goto out; - - /* Update HEAD if it was pointing to the reference being renamed */ - if ((error = git_reference_symbolic_set_target(&updated, head, payload->new_name, NULL)) < 0) { - git_error_set(GIT_ERROR_REFERENCE, "failed to update HEAD after renaming reference"); - goto out; - } - -out: - git_reference_free(updated); - git_reference_free(head); - return error; -} - -int git_reference_rename( - git_reference **out, - git_reference *ref, - const char *new_name, - int force, - const char *log_message) -{ - refs_update_head_payload payload; - git_signature *signature = NULL; - git_repository *repo; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(ref); - - repo = git_reference_owner(ref); - - if ((error = git_reference__log_signature(&signature, repo)) < 0 || - (error = reference_normalize_for_repo(payload.new_name, repo, new_name, true)) < 0 || - (error = git_refdb_rename(out, ref->db, ref->name, payload.new_name, force, signature, log_message)) < 0) - goto out; - - payload.old_name = ref->name; - - /* We may have to update any HEAD that was pointing to the renamed reference. */ - if ((error = git_repository_foreach_worktree(repo, refs_update_head, &payload)) < 0) - goto out; - -out: - git_signature_free(signature); - return error; -} - -int git_reference_resolve(git_reference **ref_out, const git_reference *ref) -{ - switch (git_reference_type(ref)) { - case GIT_REFERENCE_DIRECT: - return git_reference_lookup(ref_out, ref->db->repo, ref->name); - - case GIT_REFERENCE_SYMBOLIC: - return git_reference_lookup_resolved(ref_out, ref->db->repo, ref->target.symbolic, -1); - - default: - git_error_set(GIT_ERROR_REFERENCE, "invalid reference"); - return -1; - } -} - -int git_reference_foreach( - git_repository *repo, - git_reference_foreach_cb callback, - void *payload) -{ - git_reference_iterator *iter; - git_reference *ref; - int error; - - if ((error = git_reference_iterator_new(&iter, repo)) < 0) - return error; - - while (!(error = git_reference_next(&ref, iter))) { - if ((error = callback(ref, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - if (error == GIT_ITEROVER) - error = 0; - - git_reference_iterator_free(iter); - return error; -} - -int git_reference_foreach_name( - git_repository *repo, - git_reference_foreach_name_cb callback, - void *payload) -{ - git_reference_iterator *iter; - const char *refname; - int error; - - if ((error = git_reference_iterator_new(&iter, repo)) < 0) - return error; - - while (!(error = git_reference_next_name(&refname, iter))) { - if ((error = callback(refname, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - if (error == GIT_ITEROVER) - error = 0; - - git_reference_iterator_free(iter); - return error; -} - -int git_reference_foreach_glob( - git_repository *repo, - const char *glob, - git_reference_foreach_name_cb callback, - void *payload) -{ - git_reference_iterator *iter; - const char *refname; - int error; - - if ((error = git_reference_iterator_glob_new(&iter, repo, glob)) < 0) - return error; - - while (!(error = git_reference_next_name(&refname, iter))) { - if ((error = callback(refname, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - if (error == GIT_ITEROVER) - error = 0; - - git_reference_iterator_free(iter); - return error; -} - -int git_reference_iterator_new(git_reference_iterator **out, git_repository *repo) -{ - git_refdb *refdb; - - if (git_repository_refdb__weakptr(&refdb, repo) < 0) - return -1; - - return git_refdb_iterator(out, refdb, NULL); -} - -int git_reference_iterator_glob_new( - git_reference_iterator **out, git_repository *repo, const char *glob) -{ - git_refdb *refdb; - - if (git_repository_refdb__weakptr(&refdb, repo) < 0) - return -1; - - return git_refdb_iterator(out, refdb, glob); -} - -int git_reference_next(git_reference **out, git_reference_iterator *iter) -{ - return git_refdb_iterator_next(out, iter); -} - -int git_reference_next_name(const char **out, git_reference_iterator *iter) -{ - return git_refdb_iterator_next_name(out, iter); -} - -void git_reference_iterator_free(git_reference_iterator *iter) -{ - if (iter == NULL) - return; - - git_refdb_iterator_free(iter); -} - -static int cb__reflist_add(const char *ref, void *data) -{ - char *name = git__strdup(ref); - GIT_ERROR_CHECK_ALLOC(name); - return git_vector_insert((git_vector *)data, name); -} - -int git_reference_list( - git_strarray *array, - git_repository *repo) -{ - git_vector ref_list; - - GIT_ASSERT_ARG(array); - GIT_ASSERT_ARG(repo); - - array->strings = NULL; - array->count = 0; - - if (git_vector_init(&ref_list, 8, NULL) < 0) - return -1; - - if (git_reference_foreach_name( - repo, &cb__reflist_add, (void *)&ref_list) < 0) { - git_vector_dispose(&ref_list); - return -1; - } - - array->strings = (char **)git_vector_detach(&array->count, NULL, &ref_list); - - return 0; -} - -static int is_valid_ref_char(char ch) -{ - if ((unsigned) ch <= ' ' || ch == '\177') /* ASCII control characters */ - return 0; - - switch (ch) { - case '~': - case '^': - case ':': - case '\\': - case '?': - case '[': - return 0; - default: - return 1; - } -} - -static int ensure_segment_validity(const char *name, char may_contain_glob, bool allow_caret_prefix) -{ - const char *current = name; - const char *start = current; - char prev = '\0'; - const int lock_len = (int)strlen(GIT_FILELOCK_EXTENSION); - int segment_len; - - if (*current == '.') - return -1; /* Refname starts with "." */ - if (allow_caret_prefix && *current == '^') - start++; - - for (current = start; ; current++) { - if (*current == '\0' || *current == '/') - break; - - if (!is_valid_ref_char(*current)) - return -1; /* Illegal character in refname */ - - if (prev == '.' && *current == '.') - return -1; /* Refname contains ".." */ - - if (prev == '@' && *current == '{') - return -1; /* Refname contains "@{" */ - - if (*current == '*') { - if (!may_contain_glob) - return -1; - may_contain_glob = 0; - } - - prev = *current; - } - - segment_len = (int)(current - name); - - /* A refname component can not end with ".lock" */ - if (segment_len >= lock_len && - !memcmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len)) - return -1; - - return segment_len; -} - -static bool is_valid_normalized_name(const char *name, size_t len) -{ - size_t i; - char c; - - GIT_ASSERT_ARG(name); - GIT_ASSERT_ARG(len > 0); - - for (i = 0; i < len; i++) - { - c = name[i]; - if (i == 0 && c == '^') - continue; /* The first character is allowed to be "^" for negative refspecs */ - - if (len == 1 && c == '@') - return true; /* Abbreviation for HEAD */ - - if ((c < 'A' || c > 'Z') && c != '_') - return false; - } - - if (*name == '_' || name[len - 1] == '_') - return false; - - return true; -} - -/* Inspired from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/refs.c#L36-100 */ -int git_reference__normalize_name( - git_str *buf, - const char *name, - unsigned int flags) -{ - const char *current; - int segment_len, segments_count = 0, error = GIT_EINVALIDSPEC; - unsigned int process_flags; - bool normalize = (buf != NULL); - bool allow_caret_prefix = true; - bool validate = (flags & GIT_REFERENCE_FORMAT__VALIDATION_DISABLE) == 0; - -#ifdef GIT_USE_ICONV - git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT; -#endif - - GIT_ASSERT_ARG(name); - - process_flags = flags; - current = (char *)name; - - if (validate && *current == '/') - goto cleanup; - - if (normalize) - git_str_clear(buf); - -#ifdef GIT_USE_ICONV - if ((flags & GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE) != 0) { - size_t namelen = strlen(current); - if ((error = git_fs_path_iconv_init_precompose(&ic)) < 0 || - (error = git_fs_path_iconv(&ic, ¤t, &namelen)) < 0) - goto cleanup; - error = GIT_EINVALIDSPEC; - } -#endif - - if (!validate) { - git_str_sets(buf, current); - - error = git_str_oom(buf) ? -1 : 0; - goto cleanup; - } - - while (true) { - char may_contain_glob = process_flags & GIT_REFERENCE_FORMAT_REFSPEC_PATTERN; - - segment_len = ensure_segment_validity(current, may_contain_glob, allow_caret_prefix); - if (segment_len < 0) - goto cleanup; - - if (segment_len > 0) { - /* - * There may only be one glob in a pattern, thus we reset - * the pattern-flag in case the current segment has one. - */ - if (memchr(current, '*', segment_len)) - process_flags &= ~GIT_REFERENCE_FORMAT_REFSPEC_PATTERN; - - if (normalize) { - /* `@` (i.e. just `@`) is an alias for `HEAD` */ - if (segments_count == 0 && segment_len == 1 && current[0] == '@') { - git_str_sets(buf, GIT_HEAD_FILE); - } else { - size_t cur_len = git_str_len(buf); - - git_str_joinpath(buf, git_str_cstr(buf), current); - git_str_truncate(buf, - cur_len + segment_len + (segments_count ? 1 : 0)); - } - - if (git_str_oom(buf)) { - error = -1; - goto cleanup; - } - } - - segments_count++; - } - - /* No empty segment is allowed when not normalizing */ - if (segment_len == 0 && !normalize) - goto cleanup; - - if (current[segment_len] == '\0') - break; - - current += segment_len + 1; - - /* - * A caret prefix is only allowed in the first segment to signify a - * negative refspec. - */ - allow_caret_prefix = false; - } - - /* A refname can not be empty */ - if (segment_len == 0 && segments_count == 0) - goto cleanup; - - /* A refname can not end with "." */ - if (current[segment_len - 1] == '.') - goto cleanup; - - /* A refname can not end with "/" */ - if (current[segment_len - 1] == '/') - goto cleanup; - - if ((segments_count == 1 ) && !(flags & GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) - goto cleanup; - - if ((segments_count == 1 ) && - !(flags & GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND) && - !(is_valid_normalized_name(name, (size_t)segment_len) || - ((flags & GIT_REFERENCE_FORMAT_REFSPEC_PATTERN) && !strcmp("*", name)))) - goto cleanup; - - if ((segments_count > 1) - && !(flags & GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND) - && (is_valid_normalized_name(name, strchr(name, '/') - name))) - goto cleanup; - - error = 0; - -cleanup: - if (error == GIT_EINVALIDSPEC) - git_error_set( - GIT_ERROR_REFERENCE, - "the given reference name '%s' is not valid", name); - - if (error && normalize) - git_str_dispose(buf); - -#ifdef GIT_USE_ICONV - git_fs_path_iconv_clear(&ic); -#endif - - return error; -} - -int git_reference_normalize_name( - char *buffer_out, - size_t buffer_size, - const char *name, - unsigned int flags) -{ - git_str buf = GIT_STR_INIT; - int error; - - if ((error = git_reference__normalize_name(&buf, name, flags)) < 0) - goto cleanup; - - if (git_str_len(&buf) > buffer_size - 1) { - git_error_set( - GIT_ERROR_REFERENCE, - "the provided buffer is too short to hold the normalization of '%s'", name); - error = GIT_EBUFS; - goto cleanup; - } - - if ((error = git_str_copy_cstr(buffer_out, buffer_size, &buf)) < 0) - goto cleanup; - - error = 0; - -cleanup: - git_str_dispose(&buf); - return error; -} - -#define GIT_REFERENCE_TYPEMASK (GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC) - -int git_reference_cmp( - const git_reference *ref1, - const git_reference *ref2) -{ - git_reference_t type1, type2; - - GIT_ASSERT_ARG(ref1); - GIT_ASSERT_ARG(ref2); - - type1 = git_reference_type(ref1); - type2 = git_reference_type(ref2); - - /* let's put symbolic refs before OIDs */ - if (type1 != type2) - return (type1 == GIT_REFERENCE_SYMBOLIC) ? -1 : 1; - - if (type1 == GIT_REFERENCE_SYMBOLIC) - return strcmp(ref1->target.symbolic, ref2->target.symbolic); - - return git_oid__cmp(&ref1->target.oid, &ref2->target.oid); -} - -int git_reference__cmp_cb(const void *a, const void *b) -{ - return git_reference_cmp( - (const git_reference *)a, (const git_reference *)b); -} - -/* - * Starting with the reference given by `ref_name`, follows symbolic - * references until a direct reference is found and updated the OID - * on that direct reference to `oid`. - */ -int git_reference__update_terminal( - git_repository *repo, - const char *ref_name, - const git_oid *oid, - const git_signature *sig, - const char *log_message) -{ - git_reference *ref = NULL, *ref2 = NULL; - git_signature *who = NULL; - git_refdb *refdb = NULL; - const git_signature *to_use; - int error = 0; - - if (!sig && (error = git_reference__log_signature(&who, repo)) < 0) - goto out; - - to_use = sig ? sig : who; - - if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) - goto out; - - if ((error = git_refdb_resolve(&ref, refdb, ref_name, -1)) < 0) { - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = reference__create(&ref2, repo, ref_name, oid, NULL, 0, to_use, - log_message, NULL, NULL); - } - goto out; - } - - /* In case the resolved reference is symbolic, then it's a dangling symref. */ - if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) { - error = reference__create(&ref2, repo, ref->target.symbolic, oid, NULL, 0, to_use, - log_message, NULL, NULL); - } else { - error = reference__create(&ref2, repo, ref->name, oid, NULL, 1, to_use, - log_message, &ref->target.oid, NULL); - } - -out: - git_reference_free(ref2); - git_reference_free(ref); - git_signature_free(who); - return error; -} - -static const char *commit_type(const git_commit *commit) -{ - unsigned int count = git_commit_parentcount(commit); - - if (count >= 2) - return " (merge)"; - else if (count == 0) - return " (initial)"; - else - return ""; -} - -int git_reference__update_for_commit( - git_repository *repo, - git_reference *ref, - const char *ref_name, - const git_oid *id, - const char *operation) -{ - git_reference *ref_new = NULL; - git_commit *commit = NULL; - git_str reflog_msg = GIT_STR_INIT; - const git_signature *who; - int error; - - if ((error = git_commit_lookup(&commit, repo, id)) < 0 || - (error = git_str_printf(&reflog_msg, "%s%s: %s", - operation ? operation : "commit", - commit_type(commit), - git_commit_summary(commit))) < 0) - goto done; - - who = git_commit_committer(commit); - - if (ref) { - if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0) - return error; - - error = reference__create(&ref_new, repo, ref->name, id, NULL, 1, who, - git_str_cstr(&reflog_msg), &ref->target.oid, NULL); - } - else - error = git_reference__update_terminal( - repo, ref_name, id, who, git_str_cstr(&reflog_msg)); - -done: - git_reference_free(ref_new); - git_str_dispose(&reflog_msg); - git_commit_free(commit); - return error; -} - -int git_reference_has_log(git_repository *repo, const char *refname) -{ - int error; - git_refdb *refdb; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(refname); - - if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) - return error; - - return git_refdb_has_log(refdb, refname); -} - -int git_reference_ensure_log(git_repository *repo, const char *refname) -{ - int error; - git_refdb *refdb; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(refname); - - if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) - return error; - - return git_refdb_ensure_log(refdb, refname); -} - -int git_reference__is_branch(const char *ref_name) -{ - return git__prefixcmp(ref_name, GIT_REFS_HEADS_DIR) == 0; -} - -int git_reference_is_branch(const git_reference *ref) -{ - GIT_ASSERT_ARG(ref); - return git_reference__is_branch(ref->name); -} - -int git_reference__is_remote(const char *ref_name) -{ - return git__prefixcmp(ref_name, GIT_REFS_REMOTES_DIR) == 0; -} - -int git_reference_is_remote(const git_reference *ref) -{ - GIT_ASSERT_ARG(ref); - return git_reference__is_remote(ref->name); -} - -int git_reference__is_tag(const char *ref_name) -{ - return git__prefixcmp(ref_name, GIT_REFS_TAGS_DIR) == 0; -} - -int git_reference_is_tag(const git_reference *ref) -{ - GIT_ASSERT_ARG(ref); - return git_reference__is_tag(ref->name); -} - -int git_reference__is_note(const char *ref_name) -{ - return git__prefixcmp(ref_name, GIT_REFS_NOTES_DIR) == 0; -} - -int git_reference_is_note(const git_reference *ref) -{ - GIT_ASSERT_ARG(ref); - return git_reference__is_note(ref->name); -} - -static int peel_error(int error, const git_reference *ref, const char *msg) -{ - git_error_set( - GIT_ERROR_INVALID, - "the reference '%s' cannot be peeled - %s", git_reference_name(ref), msg); - return error; -} - -int git_reference_peel( - git_object **peeled, - const git_reference *ref, - git_object_t target_type) -{ - const git_reference *resolved = NULL; - git_reference *allocated = NULL; - git_object *target = NULL; - int error; - - GIT_ASSERT_ARG(ref); - - if (ref->type == GIT_REFERENCE_DIRECT) { - resolved = ref; - } else { - if ((error = git_reference_resolve(&allocated, ref)) < 0) - return peel_error(error, ref, "Cannot resolve reference"); - - resolved = allocated; - } - - /* - * If we try to peel an object to a tag, we cannot use - * the fully peeled object, as that will always resolve - * to a commit. So we only want to use the peeled value - * if it is not zero and the target is not a tag. - */ - if (target_type != GIT_OBJECT_TAG && !git_oid_is_zero(&resolved->peel)) { - error = git_object_lookup(&target, - git_reference_owner(ref), &resolved->peel, GIT_OBJECT_ANY); - } else { - error = git_object_lookup(&target, - git_reference_owner(ref), &resolved->target.oid, GIT_OBJECT_ANY); - } - - if (error < 0) { - peel_error(error, ref, "Cannot retrieve reference target"); - goto cleanup; - } - - if (target_type == GIT_OBJECT_ANY && git_object_type(target) != GIT_OBJECT_TAG) - error = git_object_dup(peeled, target); - else - error = git_object_peel(peeled, target, target_type); - -cleanup: - git_object_free(target); - git_reference_free(allocated); - - return error; -} - -int git_reference__name_is_valid( - int *valid, - const char *refname, - unsigned int flags) -{ - int error; - - GIT_ASSERT(valid && refname); - - *valid = 0; - - error = git_reference__normalize_name(NULL, refname, flags); - - if (!error) - *valid = 1; - else if (error == GIT_EINVALIDSPEC) - error = 0; - - return error; -} - -int git_reference_name_is_valid(int *valid, const char *refname) -{ - return git_reference__name_is_valid(valid, refname, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL); -} - -const char *git_reference__shorthand(const char *name) -{ - if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR)) - return name + strlen(GIT_REFS_HEADS_DIR); - else if (!git__prefixcmp(name, GIT_REFS_TAGS_DIR)) - return name + strlen(GIT_REFS_TAGS_DIR); - else if (!git__prefixcmp(name, GIT_REFS_REMOTES_DIR)) - return name + strlen(GIT_REFS_REMOTES_DIR); - else if (!git__prefixcmp(name, GIT_REFS_DIR)) - return name + strlen(GIT_REFS_DIR); - - /* No shorthands are available, so just return the name. */ - return name; -} - -const char *git_reference_shorthand(const git_reference *ref) -{ - return git_reference__shorthand(ref->name); -} - -int git_reference__is_unborn_head(bool *unborn, const git_reference *ref, git_repository *repo) -{ - int error; - git_reference *tmp_ref; - - GIT_ASSERT_ARG(unborn); - GIT_ASSERT_ARG(ref); - GIT_ASSERT_ARG(repo); - - if (ref->type == GIT_REFERENCE_DIRECT) { - *unborn = 0; - return 0; - } - - error = git_reference_lookup_resolved(&tmp_ref, repo, ref->name, -1); - git_reference_free(tmp_ref); - - if (error != 0 && error != GIT_ENOTFOUND) - return error; - else if (error == GIT_ENOTFOUND && git__strcmp(ref->name, GIT_HEAD_FILE) == 0) - *unborn = true; - else - *unborn = false; - - return 0; -} - -/* Deprecated functions */ - -#ifndef GIT_DEPRECATE_HARD - -int git_reference_is_valid_name(const char *refname) -{ - int valid = 0; - - git_reference__name_is_valid(&valid, refname, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL); - - return valid; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/refs.h b/vendor/libgit2-sys/libgit2/src/libgit2/refs.h deleted file mode 100644 index a06965b..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/refs.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_refs_h__ -#define INCLUDE_refs_h__ - -#include "common.h" - -#include "git2/oid.h" -#include "git2/refs.h" -#include "git2/refdb.h" -#include "str.h" -#include "oid.h" - -extern bool git_reference__enable_symbolic_ref_target_validation; - -#define GIT_REFS_DIR "refs/" -#define GIT_REFS_HEADS_DIR GIT_REFS_DIR "heads/" -#define GIT_REFS_TAGS_DIR GIT_REFS_DIR "tags/" -#define GIT_REFS_REMOTES_DIR GIT_REFS_DIR "remotes/" -#define GIT_REFS_NOTES_DIR GIT_REFS_DIR "notes/" -#define GIT_REFS_DIR_MODE 0777 -#define GIT_REFS_FILE_MODE 0666 - -#define GIT_RENAMED_REF_FILE GIT_REFS_DIR "RENAMED-REF" - -#define GIT_SYMREF "ref: " -#define GIT_PACKEDREFS_FILE "packed-refs" -#define GIT_PACKEDREFS_HEADER "# pack-refs with: peeled fully-peeled sorted " -#define GIT_PACKEDREFS_FILE_MODE 0666 - -#define GIT_HEAD_FILE "HEAD" -#define GIT_ORIG_HEAD_FILE "ORIG_HEAD" -#define GIT_FETCH_HEAD_FILE "FETCH_HEAD" -#define GIT_MERGE_HEAD_FILE "MERGE_HEAD" -#define GIT_REVERT_HEAD_FILE "REVERT_HEAD" -#define GIT_CHERRYPICK_HEAD_FILE "CHERRY_PICK_HEAD" -#define GIT_BISECT_LOG_FILE "BISECT_LOG" -#define GIT_REBASE_MERGE_DIR "rebase-merge/" -#define GIT_REBASE_MERGE_INTERACTIVE_FILE GIT_REBASE_MERGE_DIR "interactive" -#define GIT_REBASE_APPLY_DIR "rebase-apply/" -#define GIT_REBASE_APPLY_REBASING_FILE GIT_REBASE_APPLY_DIR "rebasing" -#define GIT_REBASE_APPLY_APPLYING_FILE GIT_REBASE_APPLY_DIR "applying" - -#define GIT_SEQUENCER_DIR "sequencer/" -#define GIT_SEQUENCER_HEAD_FILE GIT_SEQUENCER_DIR "head" -#define GIT_SEQUENCER_OPTIONS_FILE GIT_SEQUENCER_DIR "options" -#define GIT_SEQUENCER_TODO_FILE GIT_SEQUENCER_DIR "todo" - -#define GIT_STASH_FILE "stash" -#define GIT_REFS_STASH_FILE GIT_REFS_DIR GIT_STASH_FILE - -#define GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE (1u << 16) -#define GIT_REFERENCE_FORMAT__VALIDATION_DISABLE (1u << 15) - -#define GIT_REFNAME_MAX 1024 - -typedef char git_refname_t[GIT_REFNAME_MAX]; - -struct git_reference { - git_refdb *db; - git_reference_t type; - - union { - git_oid oid; - char *symbolic; - } target; - - git_oid peel; - char name[GIT_FLEX_ARRAY]; -}; - -/** - * Reallocate the reference with a new name - * - * Note that this is a dangerous operation, as on success, all existing - * pointers to the old reference will now be dangling. Only call this on objects - * you control, possibly using `git_reference_dup`. - */ -git_reference *git_reference__realloc(git_reference **ptr_to_ref, const char *name); - -int git_reference__normalize_name(git_str *buf, const char *name, unsigned int flags); -int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *sig, const char *log_message); -int git_reference__name_is_valid(int *valid, const char *name, unsigned int flags); -int git_reference__is_branch(const char *ref_name); -int git_reference__is_remote(const char *ref_name); -int git_reference__is_tag(const char *ref_name); -int git_reference__is_note(const char *ref_name); -const char *git_reference__shorthand(const char *name); - -/* - * A `git_reference_cmp` wrapper suitable for passing to generic - * comparators, like `vector_cmp` / `tsort` / etc. - */ -int git_reference__cmp_cb(const void *a, const void *b); - -/** - * Lookup a reference by name and try to resolve to an OID. - * - * You can control how many dereferences this will attempt to resolve the - * reference with the `max_deref` parameter, or pass -1 to use a sane - * default. If you pass 0 for `max_deref`, this will not attempt to resolve - * the reference. For any value of `max_deref` other than 0, not - * successfully resolving the reference will be reported as an error. - - * The generated reference must be freed by the user. - * - * @param reference_out Pointer to the looked-up reference - * @param repo The repository to look up the reference - * @param name The long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...) - * @param max_deref Maximum number of dereferences to make of symbolic refs, 0 means simple lookup, < 0 means use default reasonable value - * @return 0 on success or < 0 on error; not being able to resolve the reference is an error unless 0 was passed for max_deref - */ -int git_reference_lookup_resolved( - git_reference **reference_out, - git_repository *repo, - const char *name, - int max_deref); - -int git_reference__log_signature(git_signature **out, git_repository *repo); - -/** Update a reference after a commit. */ -int git_reference__update_for_commit( - git_repository *repo, - git_reference *ref, - const char *ref_name, - const git_oid *id, - const char *operation); - -int git_reference__is_unborn_head(bool *unborn, const git_reference *ref, git_repository *repo); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/refspec.c b/vendor/libgit2-sys/libgit2/src/libgit2/refspec.c deleted file mode 100644 index 7ce8ef4..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/refspec.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "refspec.h" - -#include "buf.h" -#include "refs.h" -#include "util.h" -#include "vector.h" -#include "wildmatch.h" - -int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch) -{ - /* Ported from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/remote.c#L518-636 */ - - size_t llen; - int is_glob = 0; - const char *lhs, *rhs; - int valid = 0; - unsigned int flags; - bool is_neg_refspec = false; - - GIT_ASSERT_ARG(refspec); - GIT_ASSERT_ARG(input); - - memset(refspec, 0x0, sizeof(git_refspec)); - refspec->push = !is_fetch; - - lhs = input; - if (*lhs == '+') { - refspec->force = 1; - lhs++; - } - if (*lhs == '^') { - is_neg_refspec = true; - } - - rhs = strrchr(lhs, ':'); - - /* - * Before going on, special case ":" (or "+:") as a refspec - * for matching refs. - */ - if (!is_fetch && rhs == lhs && rhs[1] == '\0') { - refspec->matching = 1; - refspec->string = git__strdup(input); - GIT_ERROR_CHECK_ALLOC(refspec->string); - refspec->src = git__strdup(""); - GIT_ERROR_CHECK_ALLOC(refspec->src); - refspec->dst = git__strdup(""); - GIT_ERROR_CHECK_ALLOC(refspec->dst); - return 0; - } - - if (rhs) { - size_t rlen = strlen(++rhs); - if (rlen || !is_fetch) { - is_glob = (1 <= rlen && strchr(rhs, '*')); - refspec->dst = git__strndup(rhs, rlen); - } - } - - llen = (rhs ? (size_t)(rhs - lhs - 1) : strlen(lhs)); - if (1 <= llen && memchr(lhs, '*', llen)) { - /* - * If the lefthand side contains a glob, then one of the following must be - * true, otherwise the spec is invalid - * 1) the rhs exists and also contains a glob - * 2) it is a negative refspec (i.e. no rhs) - * 3) the rhs doesn't exist and we're fetching - */ - if ((rhs && !is_glob) || (rhs && is_neg_refspec) || (!rhs && is_fetch && !is_neg_refspec)) - goto invalid; - is_glob = 1; - } else if (rhs && is_glob) - goto invalid; - - refspec->pattern = is_glob; - refspec->src = git__strndup(lhs, llen); - flags = GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL | - GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND | - (is_glob ? GIT_REFERENCE_FORMAT_REFSPEC_PATTERN : 0); - - if (is_fetch) { - /* - * LHS - * - empty is allowed; it means HEAD. - * - otherwise it must be a valid looking ref. - */ - if (!*refspec->src) - ; /* empty is ok */ - else if (git_reference__name_is_valid(&valid, refspec->src, flags) < 0) - goto on_error; - else if (!valid) - goto invalid; - - /* - * RHS - * - missing is ok, and is same as empty. - * - empty is ok; it means not to store. - * - otherwise it must be a valid looking ref. - */ - if (!refspec->dst) - ; /* ok */ - else if (!*refspec->dst) - ; /* ok */ - else if (git_reference__name_is_valid(&valid, refspec->dst, flags) < 0) - goto on_error; - else if (!valid) - goto invalid; - } else { - /* - * LHS - * - empty is allowed; it means delete. - * - when wildcarded, it must be a valid looking ref. - * - otherwise, it must be an extended SHA-1, but - * there is no existing way to validate this. - */ - if (!*refspec->src) - ; /* empty is ok */ - else if (is_glob) { - if (git_reference__name_is_valid(&valid, refspec->src, flags) < 0) - goto on_error; - else if (!valid) - goto invalid; - } - else { - ; /* anything goes, for now */ - } - - /* - * RHS - * - missing is allowed, but LHS then must be a - * valid looking ref. - * - empty is not allowed. - * - otherwise it must be a valid looking ref. - */ - if (!refspec->dst) { - if (git_reference__name_is_valid(&valid, refspec->src, flags) < 0) - goto on_error; - else if (!valid) - goto invalid; - } else if (!*refspec->dst) { - goto invalid; - } else { - if (git_reference__name_is_valid(&valid, refspec->dst, flags) < 0) - goto on_error; - else if (!valid) - goto invalid; - } - - /* if the RHS is empty, then it's a copy of the LHS */ - if (!refspec->dst) { - refspec->dst = git__strdup(refspec->src); - GIT_ERROR_CHECK_ALLOC(refspec->dst); - } - } - - refspec->string = git__strdup(input); - GIT_ERROR_CHECK_ALLOC(refspec->string); - - return 0; - -invalid: - git_error_set(GIT_ERROR_INVALID, - "'%s' is not a valid refspec.", input); - git_refspec__dispose(refspec); - return GIT_EINVALIDSPEC; - -on_error: - git_refspec__dispose(refspec); - return -1; -} - -void git_refspec__dispose(git_refspec *refspec) -{ - if (refspec == NULL) - return; - - git__free(refspec->src); - git__free(refspec->dst); - git__free(refspec->string); - - memset(refspec, 0x0, sizeof(git_refspec)); -} - -int git_refspec_parse(git_refspec **out_refspec, const char *input, int is_fetch) -{ - git_refspec *refspec; - GIT_ASSERT_ARG(out_refspec); - GIT_ASSERT_ARG(input); - - *out_refspec = NULL; - - refspec = git__malloc(sizeof(git_refspec)); - GIT_ERROR_CHECK_ALLOC(refspec); - - if (git_refspec__parse(refspec, input, !!is_fetch) != 0) { - git__free(refspec); - return -1; - } - - *out_refspec = refspec; - return 0; -} - -void git_refspec_free(git_refspec *refspec) -{ - git_refspec__dispose(refspec); - git__free(refspec); -} - -const char *git_refspec_src(const git_refspec *refspec) -{ - return refspec == NULL ? NULL : refspec->src; -} - -const char *git_refspec_dst(const git_refspec *refspec) -{ - return refspec == NULL ? NULL : refspec->dst; -} - -const char *git_refspec_string(const git_refspec *refspec) -{ - return refspec == NULL ? NULL : refspec->string; -} - -int git_refspec_force(const git_refspec *refspec) -{ - GIT_ASSERT_ARG(refspec); - - return refspec->force; -} - -int git_refspec_src_matches_negative(const git_refspec *refspec, const char *refname) -{ - if (refspec == NULL || refspec->src == NULL || !git_refspec_is_negative(refspec)) - return false; - - return (wildmatch(refspec->src + 1, refname, 0) == 0); -} - -int git_refspec_src_matches(const git_refspec *refspec, const char *refname) -{ - if (refspec == NULL || refspec->src == NULL) - return false; - - return (wildmatch(refspec->src, refname, 0) == 0); -} - -int git_refspec_dst_matches(const git_refspec *refspec, const char *refname) -{ - if (refspec == NULL || refspec->dst == NULL) - return false; - - return (wildmatch(refspec->dst, refname, 0) == 0); -} - -static int refspec_transform( - git_str *out, const char *from, const char *to, const char *name) -{ - const char *from_star, *to_star; - size_t replacement_len, star_offset; - - git_str_clear(out); - - /* - * There are two parts to each side of a refspec, the bit - * before the star and the bit after it. The star can be in - * the middle of the pattern, so we need to look at each bit - * individually. - */ - from_star = strchr(from, '*'); - to_star = strchr(to, '*'); - - GIT_ASSERT(from_star && to_star); - - /* star offset, both in 'from' and in 'name' */ - star_offset = from_star - from; - - /* the first half is copied over */ - git_str_put(out, to, to_star - to); - - /* - * Copy over the name, but exclude the trailing part in "from" starting - * after the glob - */ - replacement_len = strlen(name + star_offset) - strlen(from_star + 1); - git_str_put(out, name + star_offset, replacement_len); - - return git_str_puts(out, to_star + 1); -} - -int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name) -{ - GIT_BUF_WRAP_PRIVATE(out, git_refspec__transform, spec, name); -} - -int git_refspec__transform(git_str *out, const git_refspec *spec, const char *name) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(spec); - GIT_ASSERT_ARG(name); - - if (!git_refspec_src_matches(spec, name)) { - git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the source", name); - return -1; - } - - if (!spec->pattern) - return git_str_puts(out, spec->dst ? spec->dst : ""); - - return refspec_transform(out, spec->src, spec->dst, name); -} - -int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name) -{ - GIT_BUF_WRAP_PRIVATE(out, git_refspec__rtransform, spec, name); -} - -int git_refspec__rtransform(git_str *out, const git_refspec *spec, const char *name) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(spec); - GIT_ASSERT_ARG(name); - - if (!git_refspec_dst_matches(spec, name)) { - git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the destination", name); - return -1; - } - - if (!spec->pattern) - return git_str_puts(out, spec->src); - - return refspec_transform(out, spec->dst, spec->src, name); -} - -int git_refspec__serialize(git_str *out, const git_refspec *refspec) -{ - if (refspec->force) - git_str_putc(out, '+'); - - git_str_printf(out, "%s:%s", - refspec->src != NULL ? refspec->src : "", - refspec->dst != NULL ? refspec->dst : ""); - - return git_str_oom(out) == false; -} - -int git_refspec_is_wildcard(const git_refspec *spec) -{ - GIT_ASSERT_ARG(spec); - GIT_ASSERT_ARG(spec->src); - - return (spec->src[strlen(spec->src) - 1] == '*'); -} - -int git_refspec_is_negative(const git_refspec *spec) -{ - GIT_ASSERT_ARG(spec); - GIT_ASSERT_ARG(spec->src); - - return (spec->src[0] == '^' && spec->dst == NULL); -} - -git_direction git_refspec_direction(const git_refspec *spec) -{ - GIT_ASSERT_ARG(spec); - - return spec->push; -} - -int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs) -{ - git_str buf = GIT_STR_INIT; - size_t j, pos; - git_remote_head key; - git_refspec *cur; - - const char *formatters[] = { - GIT_REFS_DIR "%s", - GIT_REFS_TAGS_DIR "%s", - GIT_REFS_HEADS_DIR "%s", - NULL - }; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(spec); - GIT_ASSERT_ARG(refs); - - cur = git__calloc(1, sizeof(git_refspec)); - GIT_ERROR_CHECK_ALLOC(cur); - - cur->force = spec->force; - cur->push = spec->push; - cur->pattern = spec->pattern; - cur->matching = spec->matching; - cur->string = git__strdup(spec->string); - - /* shorthand on the lhs */ - if (git__prefixcmp(spec->src, GIT_REFS_DIR)) { - for (j = 0; formatters[j]; j++) { - git_str_clear(&buf); - git_str_printf(&buf, formatters[j], spec->src); - GIT_ERROR_CHECK_ALLOC_STR(&buf); - - key.name = (char *) git_str_cstr(&buf); - if (!git_vector_search(&pos, refs, &key)) { - /* we found something to match the shorthand, set src to that */ - cur->src = git_str_detach(&buf); - } - } - } - - /* No shorthands found, copy over the name */ - if (cur->src == NULL && spec->src != NULL) { - cur->src = git__strdup(spec->src); - GIT_ERROR_CHECK_ALLOC(cur->src); - } - - if (spec->dst && git__prefixcmp(spec->dst, GIT_REFS_DIR)) { - /* if it starts with "remotes" then we just prepend "refs/" */ - if (!git__prefixcmp(spec->dst, "remotes/")) { - git_str_puts(&buf, GIT_REFS_DIR); - } else { - git_str_puts(&buf, GIT_REFS_HEADS_DIR); - } - - git_str_puts(&buf, spec->dst); - GIT_ERROR_CHECK_ALLOC_STR(&buf); - - cur->dst = git_str_detach(&buf); - } - - git_str_dispose(&buf); - - if (cur->dst == NULL && spec->dst != NULL) { - cur->dst = git__strdup(spec->dst); - GIT_ERROR_CHECK_ALLOC(cur->dst); - } - - return git_vector_insert(out, cur); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/refspec.h b/vendor/libgit2-sys/libgit2/src/libgit2/refspec.h deleted file mode 100644 index 3761221..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/refspec.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_refspec_h__ -#define INCLUDE_refspec_h__ - -#include "common.h" - -#include "git2/refspec.h" -#include "str.h" -#include "vector.h" - -struct git_refspec { - char *string; - char *src; - char *dst; - unsigned int force :1, - push : 1, - pattern :1, - matching :1; -}; - -#define GIT_REFSPEC_TAGS "refs/tags/*:refs/tags/*" - -int git_refspec__transform(git_str *out, const git_refspec *spec, const char *name); -int git_refspec__rtransform(git_str *out, const git_refspec *spec, const char *name); - -int git_refspec__parse( - struct git_refspec *refspec, - const char *str, - bool is_fetch); - -void git_refspec__dispose(git_refspec *refspec); - -int git_refspec__serialize(git_str *out, const git_refspec *refspec); - -/** - * Determines if a refspec is a wildcard refspec. - * - * @param spec the refspec - * @return 1 if the refspec is a wildcard, 0 otherwise - */ -int git_refspec_is_wildcard(const git_refspec *spec); - -/** - * Determines if a refspec is a negative refspec. - * - * @param spec the refspec - * @return 1 if the refspec is a negative, 0 otherwise - */ -int git_refspec_is_negative(const git_refspec *spec); - -/** - * DWIM `spec` with `refs` existing on the remote, append the dwim'ed - * result in `out`. - */ -int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/remote.c b/vendor/libgit2-sys/libgit2/src/libgit2/remote.c deleted file mode 100644 index 5b41d2d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/remote.c +++ /dev/null @@ -1,3160 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "remote.h" - -#include "buf.h" -#include "branch.h" -#include "config.h" -#include "repository.h" -#include "fetch.h" -#include "refs.h" -#include "refspec.h" -#include "fetchhead.h" -#include "push.h" -#include "proxy.h" -#include "strarray.h" - -#include "git2/config.h" -#include "git2/types.h" -#include "git2/oid.h" -#include "git2/net.h" -#include "transports/smart.h" - -#define CONFIG_URL_FMT "remote.%s.url" -#define CONFIG_PUSHURL_FMT "remote.%s.pushurl" -#define CONFIG_FETCH_FMT "remote.%s.fetch" -#define CONFIG_PUSH_FMT "remote.%s.push" -#define CONFIG_TAGOPT_FMT "remote.%s.tagopt" - -static int dwim_refspecs(git_vector *out, git_vector *refspecs, git_vector *refs); -static int lookup_remote_prune_config(git_remote *remote, git_config *config, const char *name); -static int apply_insteadof(char **out, git_config *config, const char *url, int direction, bool use_default_if_empty); - -static int add_refspec_to(git_vector *vector, const char *string, bool is_fetch) -{ - git_refspec *spec; - - spec = git__calloc(1, sizeof(git_refspec)); - GIT_ERROR_CHECK_ALLOC(spec); - - if (git_refspec__parse(spec, string, is_fetch) < 0) { - git__free(spec); - return -1; - } - - spec->push = !is_fetch; - if (git_vector_insert(vector, spec) < 0) { - git_refspec__dispose(spec); - git__free(spec); - return -1; - } - - return 0; -} - -static int add_refspec(git_remote *remote, const char *string, bool is_fetch) -{ - return add_refspec_to(&remote->refspecs, string, is_fetch); -} - -static int download_tags_value(git_remote *remote, git_config *cfg) -{ - git_config_entry *ce; - git_str buf = GIT_STR_INIT; - int error; - - if (git_str_printf(&buf, "remote.%s.tagopt", remote->name) < 0) - return -1; - - error = git_config__lookup_entry(&ce, cfg, git_str_cstr(&buf), false); - git_str_dispose(&buf); - - if (!error && ce && ce->value) { - if (!strcmp(ce->value, "--no-tags")) - remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_NONE; - else if (!strcmp(ce->value, "--tags")) - remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL; - } - - git_config_entry_free(ce); - return error; -} - -static int ensure_remote_name_is_valid(const char *name) -{ - int valid, error; - - error = git_remote_name_is_valid(&valid, name); - - if (!error && !valid) { - git_error_set( - GIT_ERROR_CONFIG, - "'%s' is not a valid remote name.", name ? name : "(null)"); - error = GIT_EINVALIDSPEC; - } - - return error; -} - -static int write_add_refspec(git_repository *repo, const char *name, const char *refspec, bool fetch) -{ - git_config *cfg; - git_str var = GIT_STR_INIT; - git_refspec spec; - const char *fmt; - int error; - - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0) - return error; - - fmt = fetch ? CONFIG_FETCH_FMT : CONFIG_PUSH_FMT; - - if ((error = ensure_remote_name_is_valid(name)) < 0) - return error; - - if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0) - return error; - - git_refspec__dispose(&spec); - - if ((error = git_str_printf(&var, fmt, name)) < 0) - return error; - - /* - * "$^" is an unmatchable regexp: it will not match anything at all, so - * all values will be considered new and we will not replace any - * present value. - */ - if ((error = git_config_set_multivar(cfg, var.ptr, "$^", refspec)) < 0) { - goto cleanup; - } - -cleanup: - git_str_dispose(&var); - return 0; -} - -static int canonicalize_url(git_str *out, const char *in) -{ - if (in == NULL || strlen(in) == 0) { - git_error_set(GIT_ERROR_INVALID, "cannot set empty URL"); - return GIT_EINVALIDSPEC; - } - -#ifdef GIT_WIN32 - /* Given a UNC path like \\server\path, we need to convert this - * to //server/path for compatibility with core git. - */ - if (in[0] == '\\' && in[1] == '\\' && - (git__isalpha(in[2]) || git__isdigit(in[2]))) { - const char *c; - for (c = in; *c; c++) - git_str_putc(out, *c == '\\' ? '/' : *c); - - return git_str_oom(out) ? -1 : 0; - } -#endif - - return git_str_puts(out, in); -} - -static int default_fetchspec_for_name(git_str *buf, const char *name) -{ - if (git_str_printf(buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0) - return -1; - - return 0; -} - -static int ensure_remote_doesnot_exist(git_repository *repo, const char *name) -{ - int error; - git_remote *remote; - - error = git_remote_lookup(&remote, repo, name); - - if (error == GIT_ENOTFOUND) - return 0; - - if (error < 0) - return error; - - git_remote_free(remote); - - git_error_set(GIT_ERROR_CONFIG, "remote '%s' already exists", name); - - return GIT_EEXISTS; -} - -int git_remote_create_options_init(git_remote_create_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_remote_create_options, GIT_REMOTE_CREATE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_remote_create_init_options(git_remote_create_options *opts, unsigned int version) -{ - return git_remote_create_options_init(opts, version); -} -#endif - -int git_remote_create_with_opts(git_remote **out, const char *url, const git_remote_create_options *opts) -{ - git_remote *remote = NULL; - git_config *config_ro = NULL, *config_rw; - git_str canonical_url = GIT_STR_INIT; - git_str var = GIT_STR_INIT; - git_str specbuf = GIT_STR_INIT; - const git_remote_create_options dummy_opts = GIT_REMOTE_CREATE_OPTIONS_INIT; - int error = -1; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(url); - - if (!opts) { - opts = &dummy_opts; - } - - GIT_ERROR_CHECK_VERSION(opts, GIT_REMOTE_CREATE_OPTIONS_VERSION, "git_remote_create_options"); - - if (opts->name != NULL) { - if ((error = ensure_remote_name_is_valid(opts->name)) < 0) - return error; - - if (opts->repository && - (error = ensure_remote_doesnot_exist(opts->repository, opts->name)) < 0) - return error; - } - - if (opts->repository) { - if ((error = git_repository_config_snapshot(&config_ro, opts->repository)) < 0) - goto on_error; - } else if (!(opts->flags & GIT_REMOTE_CREATE_SKIP_INSTEADOF)) { - if ((error = git_config_open_default(&config_ro)) < 0) - goto on_error; - } - - remote = git__calloc(1, sizeof(git_remote)); - GIT_ERROR_CHECK_ALLOC(remote); - - remote->repo = opts->repository; - - if ((error = git_vector_init(&remote->refs, 8, NULL)) < 0 || - (error = canonicalize_url(&canonical_url, url)) < 0) - goto on_error; - - if (config_ro && !(opts->flags & GIT_REMOTE_CREATE_SKIP_INSTEADOF)) { - if ((error = apply_insteadof(&remote->url, config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH, true)) < 0 || - (error = apply_insteadof(&remote->pushurl, config_ro, canonical_url.ptr, GIT_DIRECTION_PUSH, false)) < 0) - goto on_error; - } else { - remote->url = git__strdup(canonical_url.ptr); - GIT_ERROR_CHECK_ALLOC(remote->url); - } - - if (opts->name != NULL) { - remote->name = git__strdup(opts->name); - GIT_ERROR_CHECK_ALLOC(remote->name); - - if (opts->repository && - ((error = git_str_printf(&var, CONFIG_URL_FMT, opts->name)) < 0 || - (error = git_repository_config__weakptr(&config_rw, opts->repository)) < 0 || - (error = git_config_set_string(config_rw, var.ptr, canonical_url.ptr)) < 0)) - goto on_error; - } - - if (opts->fetchspec != NULL || - (opts->name && !(opts->flags & GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC))) { - const char *fetch = NULL; - if (opts->fetchspec) { - fetch = opts->fetchspec; - } else { - if ((error = default_fetchspec_for_name(&specbuf, opts->name)) < 0) - goto on_error; - - fetch = git_str_cstr(&specbuf); - } - - if ((error = add_refspec(remote, fetch, true)) < 0) - goto on_error; - - /* only write for named remotes with a repository */ - if (opts->repository && opts->name && - ((error = write_add_refspec(opts->repository, opts->name, fetch, true)) < 0 || - (error = lookup_remote_prune_config(remote, config_ro, opts->name)) < 0)) - goto on_error; - - /* Move the data over to where the matching functions can find them */ - if ((error = dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs)) < 0) - goto on_error; - } - - /* A remote without a name doesn't download tags */ - if (!opts->name) - remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_NONE; - else - remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO; - - - git_str_dispose(&var); - - *out = remote; - error = 0; - -on_error: - if (error) - git_remote_free(remote); - - git_config_free(config_ro); - git_str_dispose(&specbuf); - git_str_dispose(&canonical_url); - git_str_dispose(&var); - return error; -} - -int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url) -{ - git_str buf = GIT_STR_INIT; - int error; - git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; - - /* Those 2 tests are duplicated here because of backward-compatibility */ - if ((error = ensure_remote_name_is_valid(name)) < 0) - return error; - - if (canonicalize_url(&buf, url) < 0) - return GIT_ERROR; - - git_str_clear(&buf); - - opts.repository = repo; - opts.name = name; - - error = git_remote_create_with_opts(out, url, &opts); - - git_str_dispose(&buf); - - return error; -} - -int git_remote_create_with_fetchspec(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch) -{ - int error; - git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; - - if ((error = ensure_remote_name_is_valid(name)) < 0) - return error; - - opts.repository = repo; - opts.name = name; - opts.fetchspec = fetch; - opts.flags = GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC; - - return git_remote_create_with_opts(out, url, &opts); -} - -int git_remote_create_anonymous(git_remote **out, git_repository *repo, const char *url) -{ - git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; - - opts.repository = repo; - - return git_remote_create_with_opts(out, url, &opts); -} - -int git_remote_create_detached(git_remote **out, const char *url) -{ - return git_remote_create_with_opts(out, url, NULL); -} - -int git_remote_dup(git_remote **dest, git_remote *source) -{ - size_t i; - int error = 0; - git_refspec *spec; - git_remote *remote = git__calloc(1, sizeof(git_remote)); - GIT_ERROR_CHECK_ALLOC(remote); - - if (source->name != NULL) { - remote->name = git__strdup(source->name); - GIT_ERROR_CHECK_ALLOC(remote->name); - } - - if (source->url != NULL) { - remote->url = git__strdup(source->url); - GIT_ERROR_CHECK_ALLOC(remote->url); - } - - if (source->pushurl != NULL) { - remote->pushurl = git__strdup(source->pushurl); - GIT_ERROR_CHECK_ALLOC(remote->pushurl); - } - - remote->repo = source->repo; - remote->download_tags = source->download_tags; - remote->prune_refs = source->prune_refs; - - if (git_vector_init(&remote->refs, 32, NULL) < 0 || - git_vector_init(&remote->refspecs, 2, NULL) < 0 || - git_vector_init(&remote->active_refspecs, 2, NULL) < 0) { - error = -1; - goto cleanup; - } - - git_vector_foreach(&source->refspecs, i, spec) { - if ((error = add_refspec(remote, spec->string, !spec->push)) < 0) - goto cleanup; - } - - *dest = remote; - -cleanup: - - if (error < 0) - git__free(remote); - - return error; -} - -struct refspec_cb_data { - git_remote *remote; - int fetch; -}; - -static int refspec_cb(const git_config_entry *entry, void *payload) -{ - struct refspec_cb_data *data = (struct refspec_cb_data *)payload; - return add_refspec(data->remote, entry->value, data->fetch); -} - -static int get_optional_config( - bool *found, git_config *config, git_str *buf, - git_config_foreach_cb cb, void *payload) -{ - int error = 0; - const char *key = git_str_cstr(buf); - - if (git_str_oom(buf)) - return -1; - - if (cb != NULL) - error = git_config_get_multivar_foreach(config, key, NULL, cb, payload); - else - error = git_config_get_string(payload, config, key); - - if (found) - *found = !error; - - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - - return error; -} - -int git_remote_lookup(git_remote **out, git_repository *repo, const char *name) -{ - git_remote *remote = NULL; - git_str buf = GIT_STR_INIT; - const char *val; - int error = 0; - git_config *config; - struct refspec_cb_data data = { NULL }; - bool optional_setting_found = false, found; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - if ((error = ensure_remote_name_is_valid(name)) < 0) - return error; - - if ((error = git_repository_config_snapshot(&config, repo)) < 0) - return error; - - remote = git__calloc(1, sizeof(git_remote)); - GIT_ERROR_CHECK_ALLOC(remote); - - remote->name = git__strdup(name); - GIT_ERROR_CHECK_ALLOC(remote->name); - - if (git_vector_init(&remote->refs, 32, NULL) < 0 || - git_vector_init(&remote->refspecs, 2, NULL) < 0 || - git_vector_init(&remote->passive_refspecs, 2, NULL) < 0 || - git_vector_init(&remote->active_refspecs, 2, NULL) < 0) { - error = -1; - goto cleanup; - } - - if ((error = git_str_printf(&buf, "remote.%s.url", name)) < 0) - goto cleanup; - - if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0) - goto cleanup; - - optional_setting_found |= found; - - remote->repo = repo; - remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO; - - if (found && strlen(val) > 0) { - if ((error = apply_insteadof(&remote->url, config, val, GIT_DIRECTION_FETCH, true)) < 0 || - (error = apply_insteadof(&remote->pushurl, config, val, GIT_DIRECTION_PUSH, false)) < 0) - goto cleanup; - } - - val = NULL; - git_str_clear(&buf); - git_str_printf(&buf, "remote.%s.pushurl", name); - - if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0) - goto cleanup; - - optional_setting_found |= found; - - if (!optional_setting_found) { - error = GIT_ENOTFOUND; - git_error_set(GIT_ERROR_CONFIG, "remote '%s' does not exist", name); - goto cleanup; - } - - if (found && strlen(val) > 0) { - if (remote->pushurl) - git__free(remote->pushurl); - - if ((error = apply_insteadof(&remote->pushurl, config, val, GIT_DIRECTION_FETCH, true)) < 0) - goto cleanup; - } - - data.remote = remote; - data.fetch = true; - - git_str_clear(&buf); - git_str_printf(&buf, "remote.%s.fetch", name); - - if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0) - goto cleanup; - - data.fetch = false; - git_str_clear(&buf); - git_str_printf(&buf, "remote.%s.push", name); - - if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0) - goto cleanup; - - if ((error = download_tags_value(remote, config)) < 0) - goto cleanup; - - if ((error = lookup_remote_prune_config(remote, config, name)) < 0) - goto cleanup; - - /* Move the data over to where the matching functions can find them */ - if ((error = dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs)) < 0) - goto cleanup; - - *out = remote; - -cleanup: - git_config_free(config); - git_str_dispose(&buf); - - if (error < 0) - git_remote_free(remote); - - return error; -} - -static int lookup_remote_prune_config(git_remote *remote, git_config *config, const char *name) -{ - git_str buf = GIT_STR_INIT; - int error = 0; - - git_str_printf(&buf, "remote.%s.prune", name); - - if ((error = git_config_get_bool(&remote->prune_refs, config, git_str_cstr(&buf))) < 0) { - if (error == GIT_ENOTFOUND) { - git_error_clear(); - - if ((error = git_config_get_bool(&remote->prune_refs, config, "fetch.prune")) < 0) { - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - } - } - } - - git_str_dispose(&buf); - return error; -} - -const char *git_remote_name(const git_remote *remote) -{ - GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL); - return remote->name; -} - -git_repository *git_remote_owner(const git_remote *remote) -{ - GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL); - return remote->repo; -} - -const char *git_remote_url(const git_remote *remote) -{ - GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL); - return remote->url; -} - -int git_remote_set_instance_url(git_remote *remote, const char *url) -{ - char *tmp; - - GIT_ASSERT_ARG(remote); - GIT_ASSERT_ARG(url); - - if ((tmp = git__strdup(url)) == NULL) - return -1; - - git__free(remote->url); - remote->url = tmp; - - return 0; -} - -static int set_url(git_repository *repo, const char *remote, const char *pattern, const char *url) -{ - git_config *cfg; - git_str buf = GIT_STR_INIT, canonical_url = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(remote); - - if ((error = ensure_remote_name_is_valid(remote)) < 0) - return error; - - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0) - return error; - - if ((error = git_str_printf(&buf, pattern, remote)) < 0) - return error; - - if (url) { - if ((error = canonicalize_url(&canonical_url, url)) < 0) - goto cleanup; - - error = git_config_set_string(cfg, buf.ptr, url); - } else { - error = git_config_delete_entry(cfg, buf.ptr); - } - -cleanup: - git_str_dispose(&canonical_url); - git_str_dispose(&buf); - - return error; -} - -int git_remote_set_url(git_repository *repo, const char *remote, const char *url) -{ - return set_url(repo, remote, CONFIG_URL_FMT, url); -} - -const char *git_remote_pushurl(const git_remote *remote) -{ - GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL); - return remote->pushurl; -} - -int git_remote_set_instance_pushurl(git_remote *remote, const char *url) -{ - char *tmp; - - GIT_ASSERT_ARG(remote); - GIT_ASSERT_ARG(url); - - if ((tmp = git__strdup(url)) == NULL) - return -1; - - git__free(remote->pushurl); - remote->pushurl = tmp; - - return 0; -} - -int git_remote_set_pushurl(git_repository *repo, const char *remote, const char *url) -{ - return set_url(repo, remote, CONFIG_PUSHURL_FMT, url); -} - -static int resolve_url( - git_str *resolved_url, - const char *url, - int direction, - const git_remote_callbacks *callbacks) -{ -#ifdef GIT_DEPRECATE_HARD - GIT_UNUSED(direction); - GIT_UNUSED(callbacks); -#else - git_buf buf = GIT_BUF_INIT; - int error; - - if (callbacks && callbacks->resolve_url) { - error = callbacks->resolve_url(&buf, url, direction, callbacks->payload); - - if (error != GIT_PASSTHROUGH) { - git_error_set_after_callback_function(error, "git_resolve_url_cb"); - - git_str_set(resolved_url, buf.ptr, buf.size); - git_buf_dispose(&buf); - - return error; - } - } -#endif - - return git_str_sets(resolved_url, url); -} - -int git_remote__urlfordirection( - git_str *url_out, - struct git_remote *remote, - int direction, - const git_remote_callbacks *callbacks) -{ - const char *url = NULL; - - GIT_ASSERT_ARG(remote); - GIT_ASSERT_ARG(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH); - - if (callbacks && callbacks->remote_ready) { - int status = callbacks->remote_ready(remote, direction, callbacks->payload); - - if (status != 0 && status != GIT_PASSTHROUGH) { - git_error_set_after_callback_function(status, "git_remote_ready_cb"); - return status; - } - } - - if (direction == GIT_DIRECTION_FETCH) - url = remote->url; - else if (direction == GIT_DIRECTION_PUSH) - url = remote->pushurl ? remote->pushurl : remote->url; - - if (!url) { - git_error_set(GIT_ERROR_INVALID, - "malformed remote '%s' - missing %s URL", - remote->name ? remote->name : "(anonymous)", - direction == GIT_DIRECTION_FETCH ? "fetch" : "push"); - return GIT_EINVALID; - } - - return resolve_url(url_out, url, direction, callbacks); -} - -int git_remote_connect_options_init( - git_remote_connect_options *opts, - unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_remote_connect_options, GIT_REMOTE_CONNECT_OPTIONS_INIT); - return 0; -} - -int git_remote_connect_options_dup( - git_remote_connect_options *dst, - const git_remote_connect_options *src) -{ - memcpy(dst, src, sizeof(git_remote_connect_options)); - - if (git_proxy_options_dup(&dst->proxy_opts, &src->proxy_opts) < 0 || - git_strarray_copy(&dst->custom_headers, &src->custom_headers) < 0) - return -1; - - return 0; -} - -void git_remote_connect_options_dispose(git_remote_connect_options *opts) -{ - if (!opts) - return; - - git_strarray_dispose(&opts->custom_headers); - git_proxy_options_dispose(&opts->proxy_opts); -} - -static size_t http_header_name_length(const char *http_header) -{ - const char *colon = strchr(http_header, ':'); - if (!colon) - return 0; - return colon - http_header; -} - -static bool is_malformed_http_header(const char *http_header) -{ - const char *c; - size_t name_len; - - /* Disallow \r and \n */ - if ((c = strchr(http_header, '\r')) != NULL) - return true; - if ((c = strchr(http_header, '\n')) != NULL) - return true; - - /* Require a header name followed by : */ - if ((name_len = http_header_name_length(http_header)) < 1) - return true; - - return false; -} - -static char *forbidden_custom_headers[] = { - "User-Agent", - "Host", - "Accept", - "Content-Type", - "Transfer-Encoding", - "Content-Length", -}; - -static bool is_forbidden_custom_header(const char *custom_header) -{ - unsigned long i; - size_t name_len = http_header_name_length(custom_header); - - /* Disallow headers that we set */ - for (i = 0; i < ARRAY_SIZE(forbidden_custom_headers); i++) - if (strncmp(forbidden_custom_headers[i], custom_header, name_len) == 0) - return true; - - return false; -} - -static int validate_custom_headers(const git_strarray *custom_headers) -{ - size_t i; - - if (!custom_headers) - return 0; - - for (i = 0; i < custom_headers->count; i++) { - if (is_malformed_http_header(custom_headers->strings[i])) { - git_error_set(GIT_ERROR_INVALID, "custom HTTP header '%s' is malformed", custom_headers->strings[i]); - return -1; - } - - if (is_forbidden_custom_header(custom_headers->strings[i])) { - git_error_set(GIT_ERROR_INVALID, "custom HTTP header '%s' is already set by libgit2", custom_headers->strings[i]); - return -1; - } - } - - return 0; -} - -static int lookup_redirect_config( - git_remote_redirect_t *out, - git_repository *repo) -{ - git_config *config; - const char *value; - int bool_value, error = 0; - - if (!repo) { - *out = GIT_REMOTE_REDIRECT_INITIAL; - return 0; - } - - if ((error = git_repository_config_snapshot(&config, repo)) < 0) - goto done; - - if ((error = git_config_get_string(&value, config, "http.followRedirects")) < 0) { - if (error == GIT_ENOTFOUND) { - *out = GIT_REMOTE_REDIRECT_INITIAL; - error = 0; - } - - goto done; - } - - if (git_config_parse_bool(&bool_value, value) == 0) { - *out = bool_value ? GIT_REMOTE_REDIRECT_ALL : - GIT_REMOTE_REDIRECT_NONE; - } else if (strcasecmp(value, "initial") == 0) { - *out = GIT_REMOTE_REDIRECT_INITIAL; - } else { - git_error_set(GIT_ERROR_CONFIG, "invalid configuration setting '%s' for 'http.followRedirects'", value); - error = -1; - } - -done: - git_config_free(config); - return error; -} - -int git_remote_connect_options_normalize( - git_remote_connect_options *dst, - git_repository *repo, - const git_remote_connect_options *src) -{ - git_remote_connect_options_dispose(dst); - git_remote_connect_options_init(dst, GIT_REMOTE_CONNECT_OPTIONS_VERSION); - - if (src) { - GIT_ERROR_CHECK_VERSION(src, GIT_REMOTE_CONNECT_OPTIONS_VERSION, "git_remote_connect_options"); - GIT_ERROR_CHECK_VERSION(&src->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); - GIT_ERROR_CHECK_VERSION(&src->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); - - if (validate_custom_headers(&src->custom_headers) < 0 || - git_remote_connect_options_dup(dst, src) < 0) - return -1; - } - - if (dst->follow_redirects == 0) { - if (lookup_redirect_config(&dst->follow_redirects, repo) < 0) - return -1; - } - - return 0; -} - -int git_remote_connect_ext( - git_remote *remote, - git_direction direction, - const git_remote_connect_options *given_opts) -{ - git_remote_connect_options opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; - git_str url = GIT_STR_INIT; - git_transport *t; - int error; - - GIT_ASSERT_ARG(remote); - - if (given_opts) - memcpy(&opts, given_opts, sizeof(git_remote_connect_options)); - - GIT_ERROR_CHECK_VERSION(&opts.callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); - GIT_ERROR_CHECK_VERSION(&opts.proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options"); - - t = remote->transport; - - if ((error = git_remote__urlfordirection(&url, remote, direction, &opts.callbacks)) < 0) - goto on_error; - - /* If we don't have a transport object yet, and the caller specified a - * custom transport factory, use that */ - if (!t && opts.callbacks.transport && - (error = opts.callbacks.transport(&t, remote, opts.callbacks.payload)) < 0) - goto on_error; - - /* If we still don't have a transport, then use the global - * transport registrations which map URI schemes to transport factories */ - if (!t && (error = git_transport_new(&t, remote, url.ptr)) < 0) - goto on_error; - - if ((error = t->connect(t, url.ptr, direction, &opts)) != 0) - goto on_error; - - remote->transport = t; - - git_str_dispose(&url); - - return 0; - -on_error: - if (t) - t->free(t); - - git_str_dispose(&url); - - if (t == remote->transport) - remote->transport = NULL; - - return error; -} - -int git_remote_connect( - git_remote *remote, - git_direction direction, - const git_remote_callbacks *callbacks, - const git_proxy_options *proxy, - const git_strarray *custom_headers) -{ - git_remote_connect_options opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; - - if (callbacks) - memcpy(&opts.callbacks, callbacks, sizeof(git_remote_callbacks)); - - if (proxy) - memcpy(&opts.proxy_opts, proxy, sizeof(git_proxy_options)); - - if (custom_headers) - memcpy(&opts.custom_headers, custom_headers, sizeof(git_strarray)); - - return git_remote_connect_ext(remote, direction, &opts); -} - -int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote) -{ - GIT_ASSERT_ARG(remote); - - if (!remote->transport) { - git_error_set(GIT_ERROR_NET, "this remote has never connected"); - return -1; - } - - return remote->transport->ls(out, size, remote->transport); -} - -int git_remote_capabilities(unsigned int *out, git_remote *remote) -{ - GIT_ASSERT_ARG(remote); - - *out = 0; - - if (!remote->transport) { - git_error_set(GIT_ERROR_NET, "this remote has never connected"); - return -1; - } - - return remote->transport->capabilities(out, remote->transport); -} - -int git_remote_oid_type(git_oid_t *out, git_remote *remote) -{ - GIT_ASSERT_ARG(remote); - - if (!remote->transport) { - git_error_set(GIT_ERROR_NET, "this remote has never connected"); - *out = 0; - return -1; - } - -#ifdef GIT_EXPERIMENTAL_SHA256 - return remote->transport->oid_type(out, remote->transport); -#else - *out = GIT_OID_SHA1; - return 0; -#endif -} - -static int lookup_config(char **out, git_config *cfg, const char *name) -{ - git_config_entry *ce = NULL; - int error; - - if ((error = git_config__lookup_entry(&ce, cfg, name, false)) < 0) - return error; - - if (ce && ce->value) { - *out = git__strdup(ce->value); - GIT_ERROR_CHECK_ALLOC(*out); - } else { - error = GIT_ENOTFOUND; - } - - git_config_entry_free(ce); - return error; -} - -static void url_config_trim(git_net_url *url) -{ - size_t len = strlen(url->path); - - if (url->path[len - 1] == '/') { - len--; - } else { - while (len && url->path[len - 1] != '/') - len--; - } - - url->path[len] = '\0'; -} - -static int http_proxy_config(char **out, git_remote *remote, git_net_url *url) -{ - git_config *cfg = NULL; - git_str buf = GIT_STR_INIT; - git_net_url lookup_url = GIT_NET_URL_INIT; - int error; - - if ((error = git_net_url_dup(&lookup_url, url)) < 0) - goto done; - - if (remote->repo) { - if ((error = git_repository_config(&cfg, remote->repo)) < 0) - goto done; - } else { - if ((error = git_config_open_default(&cfg)) < 0) - goto done; - } - - /* remote..proxy config setting */ - if (remote->name && remote->name[0]) { - git_str_clear(&buf); - - if ((error = git_str_printf(&buf, "remote.%s.proxy", remote->name)) < 0 || - (error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND) - goto done; - } - - while (true) { - git_str_clear(&buf); - - if ((error = git_str_puts(&buf, "http.")) < 0 || - (error = git_net_url_fmt(&buf, &lookup_url)) < 0 || - (error = git_str_puts(&buf, ".proxy")) < 0 || - (error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND) - goto done; - - if (! lookup_url.path[0]) - break; - - url_config_trim(&lookup_url); - } - - git_str_clear(&buf); - - error = lookup_config(out, cfg, "http.proxy"); - -done: - git_config_free(cfg); - git_str_dispose(&buf); - git_net_url_dispose(&lookup_url); - return error; -} - -static int http_proxy_env(char **out, git_remote *remote, git_net_url *url) -{ - git_str proxy_env = GIT_STR_INIT, no_proxy_env = GIT_STR_INIT; - bool use_ssl = (strcmp(url->scheme, "https") == 0); - int error; - - GIT_UNUSED(remote); - - /* http_proxy / https_proxy environment variables */ - error = git__getenv(&proxy_env, use_ssl ? "https_proxy" : "http_proxy"); - - /* try uppercase environment variables */ - if (error == GIT_ENOTFOUND) - error = git__getenv(&proxy_env, use_ssl ? "HTTPS_PROXY" : "HTTP_PROXY"); - - if (error) - goto done; - - /* no_proxy/NO_PROXY environment variables */ - error = git__getenv(&no_proxy_env, "no_proxy"); - - if (error == GIT_ENOTFOUND) - error = git__getenv(&no_proxy_env, "NO_PROXY"); - - if (error && error != GIT_ENOTFOUND) - goto done; - - if (!git_net_url_matches_pattern_list(url, no_proxy_env.ptr)) - *out = git_str_detach(&proxy_env); - else - error = GIT_ENOTFOUND; - -done: - git_str_dispose(&proxy_env); - git_str_dispose(&no_proxy_env); - return error; -} - -int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url) -{ - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(remote); - - *out = NULL; - - /* - * Go through the possible sources for proxy configuration, - * Examine the various git config options first, then - * consult environment variables. - */ - if ((error = http_proxy_config(out, remote, url)) != GIT_ENOTFOUND || - (error = http_proxy_env(out, remote, url)) != GIT_ENOTFOUND) - return error; - - return 0; -} - -/* DWIM `refspecs` based on `refs` and append the output to `out` */ -static int dwim_refspecs(git_vector *out, git_vector *refspecs, git_vector *refs) -{ - size_t i; - git_refspec *spec; - - git_vector_foreach(refspecs, i, spec) { - if (git_refspec__dwim_one(out, spec, refs) < 0) - return -1; - } - - return 0; -} - -static void free_refspecs(git_vector *vec) -{ - size_t i; - git_refspec *spec; - - git_vector_foreach(vec, i, spec) { - git_refspec__dispose(spec); - git__free(spec); - } - - git_vector_clear(vec); -} - -static int remote_head_cmp(const void *_a, const void *_b) -{ - const git_remote_head *a = (git_remote_head *) _a; - const git_remote_head *b = (git_remote_head *) _b; - - return git__strcmp_cb(a->name, b->name); -} - -static int ls_to_vector(git_vector *out, git_remote *remote) -{ - git_remote_head **heads; - size_t heads_len, i; - - if (git_remote_ls((const git_remote_head ***)&heads, &heads_len, remote) < 0) - return -1; - - if (git_vector_init(out, heads_len, remote_head_cmp) < 0) - return -1; - - for (i = 0; i < heads_len; i++) { - if (git_vector_insert(out, heads[i]) < 0) - return -1; - } - - return 0; -} - -static int connect_or_reset_options( - git_remote *remote, - int direction, - git_remote_connect_options *opts) -{ - if (!git_remote_connected(remote)) { - return git_remote_connect_ext(remote, direction, opts); - } else { - return remote->transport->set_connect_opts(remote->transport, opts); - } -} - -/* Download from an already connected remote. */ -static int git_remote__download( - git_remote *remote, - const git_strarray *refspecs, - const git_fetch_options *opts) -{ - git_vector *to_active, specs = GIT_VECTOR_INIT, refs = GIT_VECTOR_INIT; - size_t i; - int error; - - if (ls_to_vector(&refs, remote) < 0) - return -1; - - if ((error = git_vector_init(&specs, 0, NULL)) < 0) - goto on_error; - - remote->passed_refspecs = 0; - if (!refspecs || !refspecs->count) { - to_active = &remote->refspecs; - } else { - for (i = 0; i < refspecs->count; i++) { - if ((error = add_refspec_to(&specs, refspecs->strings[i], true)) < 0) - goto on_error; - } - - to_active = &specs; - remote->passed_refspecs = 1; - } - - free_refspecs(&remote->passive_refspecs); - if ((error = dwim_refspecs(&remote->passive_refspecs, &remote->refspecs, &refs)) < 0) - goto on_error; - - free_refspecs(&remote->active_refspecs); - error = dwim_refspecs(&remote->active_refspecs, to_active, &refs); - - git_vector_dispose(&refs); - free_refspecs(&specs); - git_vector_dispose(&specs); - - if (error < 0) - goto on_error; - - if (remote->push) { - git_push_free(remote->push); - remote->push = NULL; - } - - if ((error = git_fetch_negotiate(remote, opts)) < 0) - goto on_error; - - error = git_fetch_download_pack(remote); - -on_error: - git_vector_dispose(&refs); - free_refspecs(&specs); - git_vector_dispose(&specs); - return error; -} - -int git_remote_download( - git_remote *remote, - const git_strarray *refspecs, - const git_fetch_options *opts) -{ - git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; - int error; - - GIT_ASSERT_ARG(remote); - - if (!remote->repo) { - git_error_set(GIT_ERROR_INVALID, "cannot download detached remote"); - return -1; - } - - if (git_remote_connect_options__from_fetch_opts(&connect_opts, - remote, opts) < 0) - return -1; - - if ((error = connect_or_reset_options(remote, GIT_DIRECTION_FETCH, &connect_opts)) < 0) - return error; - - error = git_remote__download(remote, refspecs, opts); - - git_remote_connect_options_dispose(&connect_opts); - - return error; -} - -int git_remote_fetch( - git_remote *remote, - const git_strarray *refspecs, - const git_fetch_options *opts, - const char *reflog_message) -{ - git_remote_autotag_option_t tagopt = remote->download_tags; - bool prune = false; - git_str reflog_msg_buf = GIT_STR_INIT; - git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; - unsigned int capabilities; - git_oid_t oid_type; - unsigned int update_flags = GIT_REMOTE_UPDATE_FETCHHEAD; - int error; - - GIT_ASSERT_ARG(remote); - - if (!remote->repo) { - git_error_set(GIT_ERROR_INVALID, "cannot download detached remote"); - return -1; - } - - if (git_remote_connect_options__from_fetch_opts(&connect_opts, - remote, opts) < 0) - return -1; - - if ((error = connect_or_reset_options(remote, GIT_DIRECTION_FETCH, &connect_opts)) < 0) - return error; - - if (opts) { - update_flags = opts->update_fetchhead; - tagopt = opts->download_tags; - } - - if ((error = git_remote_capabilities(&capabilities, remote)) < 0 || - (error = git_remote_oid_type(&oid_type, remote)) < 0) - return error; - - /* Connect and download everything */ - error = git_remote__download(remote, refspecs, opts); - - /* We don't need to be connected anymore */ - git_remote_disconnect(remote); - - /* If the download failed, return the error */ - if (error != 0) - goto done; - - /* Default reflog message */ - if (reflog_message) - git_str_sets(&reflog_msg_buf, reflog_message); - else { - git_str_printf(&reflog_msg_buf, "fetch %s", - remote->name ? remote->name : remote->url); - } - - /* Create "remote/foo" branches for all remote branches */ - error = git_remote_update_tips(remote, - &connect_opts.callbacks, - update_flags, - tagopt, - git_str_cstr(&reflog_msg_buf)); - - git_str_dispose(&reflog_msg_buf); - - if (error < 0) - goto done; - - if (opts && opts->prune == GIT_FETCH_PRUNE) - prune = true; - else if (opts && opts->prune == GIT_FETCH_PRUNE_UNSPECIFIED && remote->prune_refs) - prune = true; - else if (opts && opts->prune == GIT_FETCH_NO_PRUNE) - prune = false; - else - prune = remote->prune_refs; - - if (prune) - error = git_remote_prune(remote, &connect_opts.callbacks); - -done: - git_remote_connect_options_dispose(&connect_opts); - return error; -} - -static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src) -{ - unsigned int i; - git_remote_head *remote_ref; - - GIT_ASSERT_ARG(update_heads); - GIT_ASSERT_ARG(fetchspec_src); - - *out = NULL; - - git_vector_foreach(update_heads, i, remote_ref) { - if (strcmp(remote_ref->name, fetchspec_src) == 0) { - *out = remote_ref; - break; - } - } - - return 0; -} - -static int ref_to_update(int *update, git_str *remote_name, git_remote *remote, git_refspec *spec, const char *ref_name) -{ - int error = 0; - git_repository *repo; - git_str upstream_remote = GIT_STR_INIT; - git_str upstream_name = GIT_STR_INIT; - - repo = git_remote_owner(remote); - - if ((!git_reference__is_branch(ref_name)) || - !git_remote_name(remote) || - (error = git_branch__upstream_remote(&upstream_remote, repo, ref_name) < 0) || - git__strcmp(git_remote_name(remote), git_str_cstr(&upstream_remote)) || - (error = git_branch__upstream_name(&upstream_name, repo, ref_name)) < 0 || - !git_refspec_dst_matches(spec, git_str_cstr(&upstream_name)) || - (error = git_refspec__rtransform(remote_name, spec, upstream_name.ptr)) < 0) { - /* Not an error if there is no upstream */ - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - - *update = 0; - } else { - *update = 1; - } - - git_str_dispose(&upstream_remote); - git_str_dispose(&upstream_name); - return error; -} - -static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_refspec *spec, git_vector *update_heads, git_reference *ref) -{ - git_reference *resolved_ref = NULL; - git_str remote_name = GIT_STR_INIT; - git_config *config = NULL; - const char *ref_name; - int error = 0, update; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(spec); - GIT_ASSERT_ARG(ref); - - *out = NULL; - - error = git_reference_resolve(&resolved_ref, ref); - - /* If we're in an unborn branch, let's pretend nothing happened */ - if (error == GIT_ENOTFOUND && git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) { - ref_name = git_reference_symbolic_target(ref); - error = 0; - } else { - ref_name = git_reference_name(resolved_ref); - } - - /* - * The ref name may be unresolvable - perhaps it's pointing to - * something invalid. In this case, there is no remote head for - * this ref. - */ - if (!ref_name) { - error = 0; - goto cleanup; - } - - if ((error = ref_to_update(&update, &remote_name, remote, spec, ref_name)) < 0) - goto cleanup; - - if (update) - error = remote_head_for_fetchspec_src(out, update_heads, git_str_cstr(&remote_name)); - -cleanup: - git_str_dispose(&remote_name); - git_reference_free(resolved_ref); - git_config_free(config); - return error; -} - -static int git_remote_write_fetchhead(git_remote *remote, git_refspec *spec, git_vector *update_heads) -{ - git_reference *head_ref = NULL; - git_fetchhead_ref *fetchhead_ref; - git_remote_head *remote_ref, *merge_remote_ref; - git_vector fetchhead_refs; - bool include_all_fetchheads; - unsigned int i = 0; - int error = 0; - - GIT_ASSERT_ARG(remote); - - /* no heads, nothing to do */ - if (update_heads->length == 0) - return 0; - - if (git_vector_init(&fetchhead_refs, update_heads->length, git_fetchhead_ref_cmp) < 0) - return -1; - - /* Iff refspec is * (but not subdir slash star), include tags */ - include_all_fetchheads = (strcmp(GIT_REFS_HEADS_DIR "*", git_refspec_src(spec)) == 0); - - /* Determine what to merge: if refspec was a wildcard, just use HEAD */ - if (git_refspec_is_wildcard(spec)) { - if ((error = git_reference_lookup(&head_ref, remote->repo, GIT_HEAD_FILE)) < 0 || - (error = remote_head_for_ref(&merge_remote_ref, remote, spec, update_heads, head_ref)) < 0) - goto cleanup; - } else { - /* If we're fetching a single refspec, that's the only thing that should be in FETCH_HEAD. */ - if ((error = remote_head_for_fetchspec_src(&merge_remote_ref, update_heads, git_refspec_src(spec))) < 0) - goto cleanup; - } - - /* Create the FETCH_HEAD file */ - git_vector_foreach(update_heads, i, remote_ref) { - int merge_this_fetchhead = (merge_remote_ref == remote_ref); - - if (!include_all_fetchheads && - !git_refspec_src_matches(spec, remote_ref->name) && - !merge_this_fetchhead) - continue; - - if (git_fetchhead_ref_create(&fetchhead_ref, - &remote_ref->oid, - merge_this_fetchhead, - remote_ref->name, - git_remote_url(remote)) < 0) - goto cleanup; - - if (git_vector_insert(&fetchhead_refs, fetchhead_ref) < 0) - goto cleanup; - } - - git_fetchhead_write(remote->repo, &fetchhead_refs); - -cleanup: - for (i = 0; i < fetchhead_refs.length; ++i) - git_fetchhead_ref_free(fetchhead_refs.contents[i]); - - git_vector_dispose(&fetchhead_refs); - git_reference_free(head_ref); - - return error; -} - -/** - * Generate a list of candidates for pruning by getting a list of - * references which match the rhs of an active refspec. - */ -static int prune_candidates(git_vector *candidates, git_remote *remote) -{ - git_strarray arr = { 0 }; - size_t i; - int error; - - if ((error = git_reference_list(&arr, remote->repo)) < 0) - return error; - - for (i = 0; i < arr.count; i++) { - const char *refname = arr.strings[i]; - char *refname_dup; - - if (!git_remote__matching_dst_refspec(remote, refname)) - continue; - - refname_dup = git__strdup(refname); - GIT_ERROR_CHECK_ALLOC(refname_dup); - - if ((error = git_vector_insert(candidates, refname_dup)) < 0) - goto out; - } - -out: - git_strarray_dispose(&arr); - return error; -} - -static int find_head(const void *_a, const void *_b) -{ - git_remote_head *a = (git_remote_head *) _a; - git_remote_head *b = (git_remote_head *) _b; - - return strcmp(a->name, b->name); -} - -int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks) -{ - size_t i, j; - git_vector remote_refs = GIT_VECTOR_INIT; - git_vector candidates = GIT_VECTOR_INIT; - const git_refspec *spec; - const char *refname; - int error; - git_oid zero_id; - - GIT_ASSERT(remote && remote->repo); - git_oid_clear(&zero_id, remote->repo->oid_type); - - if (callbacks) - GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); - - if ((error = ls_to_vector(&remote_refs, remote)) < 0) - goto cleanup; - - git_vector_set_cmp(&remote_refs, find_head); - - if ((error = prune_candidates(&candidates, remote)) < 0) - goto cleanup; - - /* - * Remove those entries from the candidate list for which we - * can find a remote reference in at least one refspec. - */ - git_vector_foreach(&candidates, i, refname) { - git_vector_foreach(&remote->active_refspecs, j, spec) { - git_str buf = GIT_STR_INIT; - size_t pos; - char *src_name; - git_remote_head key = {0}; - - if (!git_refspec_dst_matches(spec, refname)) - continue; - - if ((error = git_refspec__rtransform(&buf, spec, refname)) < 0) - goto cleanup; - - key.name = (char *) git_str_cstr(&buf); - error = git_vector_bsearch(&pos, &remote_refs, &key); - git_str_dispose(&buf); - - if (error < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - if (error == GIT_ENOTFOUND) - continue; - - /* If we did find a source, remove it from the candidates. */ - if ((error = git_vector_set((void **) &src_name, &candidates, i, NULL)) < 0) - goto cleanup; - - git__free(src_name); - break; - } - } - - /* - * For those candidates still left in the list, we need to - * remove them. We do not remove symrefs, as those are for - * stuff like origin/HEAD which will never match, but we do - * not want to remove them. - */ - git_vector_foreach(&candidates, i, refname) { - git_reference *ref; - git_oid id; - - if (refname == NULL) - continue; - - error = git_reference_lookup(&ref, remote->repo, refname); - /* as we want it gone, let's not consider this an error */ - if (error == GIT_ENOTFOUND) - continue; - - if (error < 0) - goto cleanup; - - if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) { - git_reference_free(ref); - continue; - } - - git_oid_cpy(&id, git_reference_target(ref)); - error = git_reference_delete(ref); - git_reference_free(ref); - - if (error < 0) - goto cleanup; - - if (callbacks && callbacks->update_refs) - error = callbacks->update_refs(refname, &id, - &zero_id, NULL, callbacks->payload); -#ifndef GIT_DEPRECATE_HARD - else if (callbacks && callbacks->update_tips) - error = callbacks->update_tips(refname, &id, - &zero_id, callbacks->payload); -#endif - - if (error < 0) { - git_error_set_after_callback_function(error, "git_remote_fetch"); - goto cleanup; - } - } - -cleanup: - git_vector_dispose(&remote_refs); - git_vector_dispose_deep(&candidates); - return error; -} - -static int update_ref( - const git_remote *remote, - const char *ref_name, - git_oid *id, - git_refspec *spec, - const char *msg, - const git_remote_callbacks *callbacks) -{ - git_reference *ref; - git_oid old_id; - int error; - - GIT_ASSERT(remote && remote->repo); - git_oid_clear(&old_id, remote->repo->oid_type); - - error = git_reference_name_to_id(&old_id, remote->repo, ref_name); - - if (error < 0 && error != GIT_ENOTFOUND) - return error; - else if (error == 0 && git_oid_equal(&old_id, id)) - return 0; - - /* If we did find a current reference, make sure we haven't lost a race */ - if (error) - error = git_reference_create(&ref, remote->repo, ref_name, id, true, msg); - else - error = git_reference_create_matching(&ref, remote->repo, ref_name, id, true, &old_id, msg); - - git_reference_free(ref); - - if (error < 0) - return error; - - if (callbacks && callbacks->update_refs) - error = callbacks->update_refs(ref_name, &old_id, - id, spec, callbacks->payload); -#ifndef GIT_DEPRECATE_HARD - else if (callbacks && callbacks->update_tips) - error = callbacks->update_tips(ref_name, &old_id, - id, callbacks->payload); -#endif - - if (error < 0) { - git_error_set_after_callback_function(error, "git_remote_fetch"); - return error; - } - - return 0; -} - -static int update_one_tip( - git_vector *update_heads, - git_remote *remote, - git_refspec *spec, - git_remote_head *head, - git_refspec *tagspec, - unsigned int update_flags, - git_remote_autotag_option_t tagopt, - const char *log_message, - const git_remote_callbacks *callbacks) -{ - git_odb *odb; - git_str refname = GIT_STR_INIT; - git_reference *ref = NULL; - bool autotag = false, updated = false; - git_oid old; - int valid; - int error; - - GIT_ASSERT(remote && remote->repo); - - if ((error = git_repository_odb__weakptr(&odb, remote->repo)) < 0) - goto done; - - /* Ignore malformed ref names (which also saves us from tag^{} */ - if ((error = git_reference_name_is_valid(&valid, head->name)) < 0) - goto done; - - if (!valid) - goto done; - - /* If we have a tag, see if the auto-follow rules say to update it */ - if (git_refspec_src_matches(tagspec, head->name)) { - if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_AUTO) - autotag = true; - - if (tagopt != GIT_REMOTE_DOWNLOAD_TAGS_NONE) { - if (git_str_puts(&refname, head->name) < 0) - goto done; - } - } - - /* If we didn't want to auto-follow the tag, check if the refspec matches */ - if (!autotag && git_refspec_src_matches(spec, head->name)) { - if (spec->dst) { - if ((error = git_refspec__transform(&refname, spec, head->name)) < 0) - goto done; - } else { - /* - * no rhs means store it in FETCH_HEAD, even if we don't - * update anything else. - */ - error = git_vector_insert(update_heads, head); - goto done; - } - } - - /* If we still don't have a refname, we don't want it */ - if (git_str_len(&refname) == 0) - goto done; - - /* In autotag mode, only create tags for objects already in db */ - if (autotag && !git_odb_exists(odb, &head->oid)) - goto done; - - if (!autotag && (error = git_vector_insert(update_heads, head)) < 0) - goto done; - - error = git_reference_name_to_id(&old, remote->repo, refname.ptr); - - if (error < 0 && error != GIT_ENOTFOUND) - goto done; - - if (!(error || error == GIT_ENOTFOUND) && - !spec->force && - !git_graph_descendant_of(remote->repo, &head->oid, &old)) { - error = 0; - goto done; - } - - if (error == GIT_ENOTFOUND) { - git_oid_clear(&old, remote->repo->oid_type); - error = 0; - - if (autotag && (error = git_vector_insert(update_heads, head)) < 0) - goto done; - } - - if ((updated = !git_oid_equal(&old, &head->oid))) { - /* In autotag mode, don't overwrite any locally-existing tags */ - error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag, - log_message); - - if (error < 0) { - if (error == GIT_EEXISTS) - error = 0; - - goto done; - } - } - - if (!callbacks || - (!updated && (update_flags & GIT_REMOTE_UPDATE_REPORT_UNCHANGED) == 0)) - goto done; - - if (callbacks && callbacks->update_refs) - error = callbacks->update_refs(refname.ptr, &old, - &head->oid, spec, callbacks->payload); -#ifndef GIT_DEPRECATE_HARD - else if (callbacks && callbacks->update_tips) - error = callbacks->update_tips(refname.ptr, &old, - &head->oid, callbacks->payload); -#endif - - if (error < 0) - git_error_set_after_callback_function(error, "git_remote_fetch"); - -done: - git_reference_free(ref); - git_str_dispose(&refname); - return error; -} - -static int update_tips_for_spec( - git_remote *remote, - const git_remote_callbacks *callbacks, - unsigned int update_flags, - git_remote_autotag_option_t tagopt, - git_refspec *spec, - git_vector *refs, - const char *log_message) -{ - git_refspec tagspec; - git_remote_head *head, oid_head; - git_vector update_heads; - int error = 0; - size_t i; - - GIT_ASSERT_ARG(remote && remote->repo); - - if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0) - return -1; - - /* Make a copy of the transport's refs */ - if (git_vector_init(&update_heads, 16, NULL) < 0) - return -1; - - /* Update tips based on the remote heads */ - git_vector_foreach(refs, i, head) { - if (update_one_tip(&update_heads, - remote, spec, head, &tagspec, - update_flags, tagopt, log_message, - callbacks) < 0) - goto on_error; - } - - /* Handle specified oid sources */ - if (git_oid__is_hexstr(spec->src, remote->repo->oid_type)) { - git_oid id; - - if ((error = git_oid__fromstr(&id, spec->src, remote->repo->oid_type)) < 0) - goto on_error; - - if (spec->dst && - (error = update_ref(remote, spec->dst, &id, spec, log_message, callbacks)) < 0) - goto on_error; - - git_oid_cpy(&oid_head.oid, &id); - oid_head.name = spec->src; - - if ((error = git_vector_insert(&update_heads, &oid_head)) < 0) - goto on_error; - } - - if ((update_flags & GIT_REMOTE_UPDATE_FETCHHEAD) && - (error = git_remote_write_fetchhead(remote, spec, &update_heads)) < 0) - goto on_error; - - git_refspec__dispose(&tagspec); - git_vector_dispose(&update_heads); - return 0; - -on_error: - git_refspec__dispose(&tagspec); - git_vector_dispose(&update_heads); - return -1; - -} - -/** - * Iteration over the three vectors, with a pause whenever we find a match - * - * On each stop, we store the iteration stat in the inout i,j,k - * parameters, and return the currently matching passive refspec as - * well as the head which we matched. - */ -static int next_head(const git_remote *remote, git_vector *refs, - git_refspec **out_spec, git_remote_head **out_head, - size_t *out_i, size_t *out_j, size_t *out_k) -{ - const git_vector *active, *passive; - git_remote_head *head; - git_refspec *spec, *passive_spec; - size_t i, j, k; - int valid; - - active = &remote->active_refspecs; - passive = &remote->passive_refspecs; - - i = *out_i; - j = *out_j; - k = *out_k; - - for (; i < refs->length; i++) { - head = git_vector_get(refs, i); - - if (git_reference_name_is_valid(&valid, head->name) < 0) - return -1; - - if (!valid) - continue; - - for (; j < active->length; j++) { - spec = git_vector_get(active, j); - - if (!git_refspec_src_matches(spec, head->name)) - continue; - - for (; k < passive->length; k++) { - passive_spec = git_vector_get(passive, k); - - if (!git_refspec_src_matches(passive_spec, head->name)) - continue; - - *out_spec = passive_spec; - *out_head = head; - *out_i = i; - *out_j = j; - *out_k = k + 1; - return 0; - - } - k = 0; - } - j = 0; - } - - return GIT_ITEROVER; -} - -static int opportunistic_updates( - const git_remote *remote, - const git_remote_callbacks *callbacks, - git_vector *refs, - const char *msg) -{ - size_t i, j, k; - git_refspec *spec; - git_remote_head *head; - git_str refname = GIT_STR_INIT; - int error = 0; - - i = j = k = 0; - - /* Handle refspecs matching remote heads */ - while ((error = next_head(remote, refs, &spec, &head, &i, &j, &k)) == 0) { - /* - * If we got here, there is a refspec which was used - * for fetching which matches the source of one of the - * passive refspecs, so we should update that - * remote-tracking branch, but not add it to - * FETCH_HEAD - */ - - git_str_clear(&refname); - if ((error = git_refspec__transform(&refname, spec, head->name)) < 0 || - (error = update_ref(remote, refname.ptr, &head->oid, spec, msg, callbacks)) < 0) - goto cleanup; - } - - if (error != GIT_ITEROVER) - goto cleanup; - - error = 0; - -cleanup: - git_str_dispose(&refname); - return error; -} - -static int truncate_fetch_head(const char *gitdir) -{ - git_str path = GIT_STR_INIT; - int error; - - if ((error = git_str_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0) - return error; - - error = git_futils_truncate(path.ptr, GIT_REFS_FILE_MODE); - git_str_dispose(&path); - - return error; -} - -int git_remote_update_tips( - git_remote *remote, - const git_remote_callbacks *callbacks, - unsigned int update_flags, - git_remote_autotag_option_t download_tags, - const char *reflog_message) -{ - git_refspec *spec, tagspec; - git_vector refs = GIT_VECTOR_INIT; - git_remote_autotag_option_t tagopt; - int error; - size_t i; - - /* push has its own logic hidden away in the push object */ - if (remote->push) { - return git_push_update_tips(remote->push, callbacks); - } - - if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0) - return -1; - - - if ((error = ls_to_vector(&refs, remote)) < 0) - goto out; - - if (download_tags == GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED) - tagopt = remote->download_tags; - else - tagopt = download_tags; - - if ((error = truncate_fetch_head(git_repository_path(remote->repo))) < 0) - goto out; - - if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_ALL) { - if ((error = update_tips_for_spec(remote, callbacks, update_flags, tagopt, &tagspec, &refs, reflog_message)) < 0) - goto out; - } - - git_vector_foreach(&remote->active_refspecs, i, spec) { - if (spec->push) - continue; - - if ((error = update_tips_for_spec(remote, callbacks, update_flags, tagopt, spec, &refs, reflog_message)) < 0) - goto out; - } - - /* Only try to do opportunistic updates if the refspec lists differ. */ - if (remote->passed_refspecs) - error = opportunistic_updates(remote, callbacks, &refs, reflog_message); - -out: - git_vector_dispose(&refs); - git_refspec__dispose(&tagspec); - return error; -} - -int git_remote_connected(const git_remote *remote) -{ - GIT_ASSERT_ARG(remote); - - if (!remote->transport || !remote->transport->is_connected) - return 0; - - /* Ask the transport if it's connected. */ - return remote->transport->is_connected(remote->transport); -} - -int git_remote_stop(git_remote *remote) -{ - GIT_ASSERT_ARG(remote); - - if (remote->transport && remote->transport->cancel) - remote->transport->cancel(remote->transport); - - return 0; -} - -int git_remote_disconnect(git_remote *remote) -{ - GIT_ASSERT_ARG(remote); - - if (git_remote_connected(remote)) - remote->transport->close(remote->transport); - - return 0; -} - -static void free_heads(git_vector *heads) -{ - git_remote_head *head; - size_t i; - - git_vector_foreach(heads, i, head) { - git__free(head->name); - git__free(head); - } -} - -void git_remote_free(git_remote *remote) -{ - if (remote == NULL) - return; - - if (remote->transport != NULL) { - git_remote_disconnect(remote); - - remote->transport->free(remote->transport); - remote->transport = NULL; - } - - git_vector_dispose(&remote->refs); - - free_refspecs(&remote->refspecs); - git_vector_dispose(&remote->refspecs); - - free_refspecs(&remote->active_refspecs); - git_vector_dispose(&remote->active_refspecs); - - free_refspecs(&remote->passive_refspecs); - git_vector_dispose(&remote->passive_refspecs); - - free_heads(&remote->local_heads); - git_vector_dispose(&remote->local_heads); - - git_push_free(remote->push); - git__free(remote->url); - git__free(remote->pushurl); - git__free(remote->name); - git__free(remote); -} - -static int remote_list_cb(const git_config_entry *entry, void *payload) -{ - git_vector *list = payload; - const char *name = entry->name + strlen("remote."); - size_t namelen = strlen(name); - char *remote_name; - - /* we know name matches "remote..(push)?url" */ - - if (!strcmp(&name[namelen - 4], ".url")) - remote_name = git__strndup(name, namelen - 4); /* strip ".url" */ - else - remote_name = git__strndup(name, namelen - 8); /* strip ".pushurl" */ - GIT_ERROR_CHECK_ALLOC(remote_name); - - return git_vector_insert(list, remote_name); -} - -int git_remote_list(git_strarray *remotes_list, git_repository *repo) -{ - int error; - git_config *cfg; - git_vector list = GIT_VECTOR_INIT; - - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0) - return error; - - if ((error = git_vector_init(&list, 4, git__strcmp_cb)) < 0) - return error; - - error = git_config_foreach_match( - cfg, "^remote\\..*\\.(push)?url$", remote_list_cb, &list); - - if (error < 0) { - git_vector_dispose_deep(&list); - return error; - } - - git_vector_uniq(&list, git__free); - - remotes_list->strings = - (char **)git_vector_detach(&remotes_list->count, NULL, &list); - - return 0; -} - -const git_indexer_progress *git_remote_stats(git_remote *remote) -{ - GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL); - return &remote->stats; -} - -git_remote_autotag_option_t git_remote_autotag(const git_remote *remote) -{ - return remote->download_tags; -} - -int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_autotag_option_t value) -{ - git_str var = GIT_STR_INIT; - git_config *config; - int error; - - GIT_ASSERT_ARG(repo && remote); - - if ((error = ensure_remote_name_is_valid(remote)) < 0) - return error; - - if ((error = git_repository_config__weakptr(&config, repo)) < 0) - return error; - - if ((error = git_str_printf(&var, CONFIG_TAGOPT_FMT, remote))) - return error; - - switch (value) { - case GIT_REMOTE_DOWNLOAD_TAGS_NONE: - error = git_config_set_string(config, var.ptr, "--no-tags"); - break; - case GIT_REMOTE_DOWNLOAD_TAGS_ALL: - error = git_config_set_string(config, var.ptr, "--tags"); - break; - case GIT_REMOTE_DOWNLOAD_TAGS_AUTO: - error = git_config_delete_entry(config, var.ptr); - if (error == GIT_ENOTFOUND) - error = 0; - break; - default: - git_error_set(GIT_ERROR_INVALID, "invalid value for the tagopt setting"); - error = -1; - } - - git_str_dispose(&var); - return error; -} - -int git_remote_prune_refs(const git_remote *remote) -{ - return remote->prune_refs; -} - -static int rename_remote_config_section( - git_repository *repo, - const char *old_name, - const char *new_name) -{ - git_str old_section_name = GIT_STR_INIT, - new_section_name = GIT_STR_INIT; - int error = -1; - - if (git_str_printf(&old_section_name, "remote.%s", old_name) < 0) - goto cleanup; - - if (new_name && - (git_str_printf(&new_section_name, "remote.%s", new_name) < 0)) - goto cleanup; - - error = git_config_rename_section( - repo, - git_str_cstr(&old_section_name), - new_name ? git_str_cstr(&new_section_name) : NULL); - -cleanup: - git_str_dispose(&old_section_name); - git_str_dispose(&new_section_name); - - return error; -} - -struct update_data { - git_config *config; - const char *old_remote_name; - const char *new_remote_name; -}; - -static int update_config_entries_cb( - const git_config_entry *entry, - void *payload) -{ - struct update_data *data = (struct update_data *)payload; - - if (strcmp(entry->value, data->old_remote_name)) - return 0; - - return git_config_set_string( - data->config, entry->name, data->new_remote_name); -} - -static int update_branch_remote_config_entry( - git_repository *repo, - const char *old_name, - const char *new_name) -{ - int error; - struct update_data data = { NULL }; - - if ((error = git_repository_config__weakptr(&data.config, repo)) < 0) - return error; - - data.old_remote_name = old_name; - data.new_remote_name = new_name; - - return git_config_foreach_match( - data.config, "branch\\..+\\.remote", update_config_entries_cb, &data); -} - -static int rename_one_remote_reference( - git_reference *reference_in, - const char *old_remote_name, - const char *new_remote_name) -{ - int error; - git_reference *ref = NULL, *dummy = NULL; - git_str namespace = GIT_STR_INIT, old_namespace = GIT_STR_INIT; - git_str new_name = GIT_STR_INIT; - git_str log_message = GIT_STR_INIT; - size_t pfx_len; - const char *target; - - if ((error = git_str_printf(&namespace, GIT_REFS_REMOTES_DIR "%s/", new_remote_name)) < 0) - return error; - - pfx_len = strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name) + 1; - git_str_puts(&new_name, namespace.ptr); - if ((error = git_str_puts(&new_name, git_reference_name(reference_in) + pfx_len)) < 0) - goto cleanup; - - if ((error = git_str_printf(&log_message, - "renamed remote %s to %s", - old_remote_name, new_remote_name)) < 0) - goto cleanup; - - if ((error = git_reference_rename(&ref, reference_in, git_str_cstr(&new_name), 1, - git_str_cstr(&log_message))) < 0) - goto cleanup; - - if (git_reference_type(ref) != GIT_REFERENCE_SYMBOLIC) - goto cleanup; - - /* Handle refs like origin/HEAD -> origin/master */ - target = git_reference_symbolic_target(ref); - if ((error = git_str_printf(&old_namespace, GIT_REFS_REMOTES_DIR "%s/", old_remote_name)) < 0) - goto cleanup; - - if (git__prefixcmp(target, old_namespace.ptr)) - goto cleanup; - - git_str_clear(&new_name); - git_str_puts(&new_name, namespace.ptr); - if ((error = git_str_puts(&new_name, target + pfx_len)) < 0) - goto cleanup; - - error = git_reference_symbolic_set_target(&dummy, ref, git_str_cstr(&new_name), - git_str_cstr(&log_message)); - - git_reference_free(dummy); - -cleanup: - git_reference_free(reference_in); - git_reference_free(ref); - git_str_dispose(&namespace); - git_str_dispose(&old_namespace); - git_str_dispose(&new_name); - git_str_dispose(&log_message); - return error; -} - -static int rename_remote_references( - git_repository *repo, - const char *old_name, - const char *new_name) -{ - int error; - git_str buf = GIT_STR_INIT; - git_reference *ref; - git_reference_iterator *iter; - - if ((error = git_str_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0) - return error; - - error = git_reference_iterator_glob_new(&iter, repo, git_str_cstr(&buf)); - git_str_dispose(&buf); - - if (error < 0) - return error; - - while ((error = git_reference_next(&ref, iter)) == 0) { - if ((error = rename_one_remote_reference(ref, old_name, new_name)) < 0) - break; - } - - git_reference_iterator_free(iter); - - return (error == GIT_ITEROVER) ? 0 : error; -} - -static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const char *new_name) -{ - git_config *config; - git_str base = GIT_STR_INIT, var = GIT_STR_INIT, val = GIT_STR_INIT; - const git_refspec *spec; - size_t i; - int error = 0; - - if ((error = git_repository_config__weakptr(&config, remote->repo)) < 0) - return error; - - if ((error = git_vector_init(problems, 1, NULL)) < 0) - return error; - - if ((error = default_fetchspec_for_name(&base, remote->name)) < 0) - return error; - - git_vector_foreach(&remote->refspecs, i, spec) { - if (spec->push) - continue; - - /* Does the dst part of the refspec follow the expected format? */ - if (strcmp(git_str_cstr(&base), spec->string)) { - char *dup; - - dup = git__strdup(spec->string); - GIT_ERROR_CHECK_ALLOC(dup); - - if ((error = git_vector_insert(problems, dup)) < 0) - break; - - continue; - } - - /* If we do want to move it to the new section */ - - git_str_clear(&val); - git_str_clear(&var); - - if (default_fetchspec_for_name(&val, new_name) < 0 || - git_str_printf(&var, "remote.%s.fetch", new_name) < 0) - { - error = -1; - break; - } - - if ((error = git_config_set_string( - config, git_str_cstr(&var), git_str_cstr(&val))) < 0) - break; - } - - git_str_dispose(&base); - git_str_dispose(&var); - git_str_dispose(&val); - - if (error < 0) { - char *str; - git_vector_foreach(problems, i, str) - git__free(str); - - git_vector_dispose(problems); - } - - return error; -} - -int git_remote_rename(git_strarray *out, git_repository *repo, const char *name, const char *new_name) -{ - int error; - git_vector problem_refspecs = GIT_VECTOR_INIT; - git_remote *remote = NULL; - - GIT_ASSERT_ARG(out && repo && name && new_name); - - if ((error = git_remote_lookup(&remote, repo, name)) < 0) - return error; - - if ((error = ensure_remote_name_is_valid(new_name)) < 0) - goto cleanup; - - if ((error = ensure_remote_doesnot_exist(repo, new_name)) < 0) - goto cleanup; - - if ((error = rename_remote_config_section(repo, name, new_name)) < 0) - goto cleanup; - - if ((error = update_branch_remote_config_entry(repo, name, new_name)) < 0) - goto cleanup; - - if ((error = rename_remote_references(repo, name, new_name)) < 0) - goto cleanup; - - if ((error = rename_fetch_refspecs(&problem_refspecs, remote, new_name)) < 0) - goto cleanup; - - out->count = problem_refspecs.length; - out->strings = (char **) problem_refspecs.contents; - -cleanup: - if (error < 0) - git_vector_dispose(&problem_refspecs); - - git_remote_free(remote); - return error; -} - -int git_remote_name_is_valid(int *valid, const char *remote_name) -{ - git_str buf = GIT_STR_INIT; - git_refspec refspec = {0}; - int error; - - GIT_ASSERT(valid); - - *valid = 0; - - if (!remote_name || *remote_name == '\0') - return 0; - - if ((error = git_str_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name)) < 0) - goto done; - - error = git_refspec__parse(&refspec, git_str_cstr(&buf), true); - - if (!error) - *valid = 1; - else if (error == GIT_EINVALIDSPEC) - error = 0; - -done: - git_str_dispose(&buf); - git_refspec__dispose(&refspec); - - return error; -} - -git_refspec *git_remote__matching_refspec(git_remote *remote, const char *refname) -{ - git_refspec *spec; - git_refspec *match = NULL; - size_t i; - - git_vector_foreach(&remote->active_refspecs, i, spec) { - if (spec->push) - continue; - - if (git_refspec_src_matches_negative(spec, refname)) - return NULL; - - if (git_refspec_src_matches(spec, refname) && match == NULL) - match = spec; - } - - return match; -} - -git_refspec *git_remote__matching_dst_refspec(git_remote *remote, const char *refname) -{ - git_refspec *spec; - size_t i; - - git_vector_foreach(&remote->active_refspecs, i, spec) { - if (spec->push) - continue; - - if (git_refspec_dst_matches(spec, refname)) - return spec; - } - - return NULL; -} - -int git_remote_add_fetch(git_repository *repo, const char *remote, const char *refspec) -{ - return write_add_refspec(repo, remote, refspec, true); -} - -int git_remote_add_push(git_repository *repo, const char *remote, const char *refspec) -{ - return write_add_refspec(repo, remote, refspec, false); -} - -static int copy_refspecs(git_strarray *array, const git_remote *remote, unsigned int push) -{ - size_t i; - git_vector refspecs; - git_refspec *spec; - char *dup; - - if (git_vector_init(&refspecs, remote->refspecs.length, NULL) < 0) - return -1; - - git_vector_foreach(&remote->refspecs, i, spec) { - if (spec->push != push) - continue; - - if ((dup = git__strdup(spec->string)) == NULL) - goto on_error; - - if (git_vector_insert(&refspecs, dup) < 0) { - git__free(dup); - goto on_error; - } - } - - array->strings = (char **)refspecs.contents; - array->count = refspecs.length; - - return 0; - -on_error: - git_vector_dispose_deep(&refspecs); - - return -1; -} - -int git_remote_get_fetch_refspecs(git_strarray *array, const git_remote *remote) -{ - return copy_refspecs(array, remote, false); -} - -int git_remote_get_push_refspecs(git_strarray *array, const git_remote *remote) -{ - return copy_refspecs(array, remote, true); -} - -size_t git_remote_refspec_count(const git_remote *remote) -{ - return remote->refspecs.length; -} - -const git_refspec *git_remote_get_refspec(const git_remote *remote, size_t n) -{ - return git_vector_get(&remote->refspecs, n); -} - -int git_remote_init_callbacks(git_remote_callbacks *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_remote_callbacks, GIT_REMOTE_CALLBACKS_INIT); - return 0; -} - -/* asserts a branch..remote format */ -static const char *name_offset(size_t *len_out, const char *name) -{ - size_t prefix_len; - const char *dot; - - prefix_len = strlen("remote."); - dot = strchr(name + prefix_len, '.'); - - GIT_ASSERT_ARG_WITH_RETVAL(dot, NULL); - - *len_out = dot - name - prefix_len; - return name + prefix_len; -} - -static int remove_branch_config_related_entries( - git_repository *repo, - const char *remote_name) -{ - int error; - git_config *config; - git_config_entry *entry; - git_config_iterator *iter; - git_str buf = GIT_STR_INIT; - - if ((error = git_repository_config__weakptr(&config, repo)) < 0) - return error; - - if ((error = git_config_iterator_glob_new(&iter, config, "branch\\..+\\.remote")) < 0) - return error; - - /* find any branches with us as upstream and remove that config */ - while ((error = git_config_next(&entry, iter)) == 0) { - const char *branch; - size_t branch_len; - - if (strcmp(remote_name, entry->value)) - continue; - - if ((branch = name_offset(&branch_len, entry->name)) == NULL) { - error = -1; - break; - } - - git_str_clear(&buf); - if ((error = git_str_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch)) < 0) - break; - - if ((error = git_config_delete_entry(config, git_str_cstr(&buf))) < 0) { - if (error != GIT_ENOTFOUND) - break; - git_error_clear(); - } - - git_str_clear(&buf); - if ((error = git_str_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch)) < 0) - break; - - if ((error = git_config_delete_entry(config, git_str_cstr(&buf))) < 0) { - if (error != GIT_ENOTFOUND) - break; - git_error_clear(); - } - } - - if (error == GIT_ITEROVER) - error = 0; - - git_str_dispose(&buf); - git_config_iterator_free(iter); - return error; -} - -static int remove_refs(git_repository *repo, const git_refspec *spec) -{ - git_reference_iterator *iter = NULL; - git_vector refs; - const char *name; - char *dup; - int error; - size_t i; - - if ((error = git_vector_init(&refs, 8, NULL)) < 0) - return error; - - if ((error = git_reference_iterator_new(&iter, repo)) < 0) - goto cleanup; - - while ((error = git_reference_next_name(&name, iter)) == 0) { - if (!git_refspec_dst_matches(spec, name)) - continue; - - dup = git__strdup(name); - if (!dup) { - error = -1; - goto cleanup; - } - - if ((error = git_vector_insert(&refs, dup)) < 0) - goto cleanup; - } - if (error == GIT_ITEROVER) - error = 0; - if (error < 0) - goto cleanup; - - git_vector_foreach(&refs, i, name) { - if ((error = git_reference_remove(repo, name)) < 0) - break; - } - -cleanup: - git_reference_iterator_free(iter); - git_vector_foreach(&refs, i, dup) { - git__free(dup); - } - git_vector_dispose(&refs); - return error; -} - -static int remove_remote_tracking(git_repository *repo, const char *remote_name) -{ - git_remote *remote; - int error; - size_t i, count; - - /* we want to use what's on the config, regardless of changes to the instance in memory */ - if ((error = git_remote_lookup(&remote, repo, remote_name)) < 0) - return error; - - count = git_remote_refspec_count(remote); - for (i = 0; i < count; i++) { - const git_refspec *refspec = git_remote_get_refspec(remote, i); - - /* shouldn't ever actually happen */ - if (refspec == NULL) - continue; - - if ((error = remove_refs(repo, refspec)) < 0) - break; - } - - git_remote_free(remote); - return error; -} - -int git_remote_delete(git_repository *repo, const char *name) -{ - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - if ((error = remove_branch_config_related_entries(repo, name)) < 0 || - (error = remove_remote_tracking(repo, name)) < 0 || - (error = rename_remote_config_section(repo, name, NULL)) < 0) - return error; - - return 0; -} - -int git_remote_default_branch(git_buf *out, git_remote *remote) -{ - GIT_BUF_WRAP_PRIVATE(out, git_remote__default_branch, remote); -} - -int git_remote__default_branch(git_str *out, git_remote *remote) -{ - const git_remote_head **heads; - const git_remote_head *guess = NULL; - const git_oid *head_id; - size_t heads_len, i; - git_str local_default = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(out); - - if ((error = git_remote_ls(&heads, &heads_len, remote)) < 0) - goto done; - - if (heads_len == 0 || strcmp(heads[0]->name, GIT_HEAD_FILE)) { - error = GIT_ENOTFOUND; - goto done; - } - - /* the first one must be HEAD so if that has the symref info, we're done */ - if (heads[0]->symref_target) { - error = git_str_puts(out, heads[0]->symref_target); - goto done; - } - - /* - * If there's no symref information, we have to look over them - * and guess. We return the first match unless the default - * branch is a candidate. Then we return the default branch. - */ - - if ((error = git_repository_initialbranch(&local_default, remote->repo)) < 0) - goto done; - - head_id = &heads[0]->oid; - - for (i = 1; i < heads_len; i++) { - if (git_oid_cmp(head_id, &heads[i]->oid)) - continue; - - if (git__prefixcmp(heads[i]->name, GIT_REFS_HEADS_DIR)) - continue; - - if (!guess) { - guess = heads[i]; - continue; - } - - if (!git__strcmp(local_default.ptr, heads[i]->name)) { - guess = heads[i]; - break; - } - } - - if (!guess) { - error = GIT_ENOTFOUND; - goto done; - } - - error = git_str_puts(out, guess->name); - -done: - git_str_dispose(&local_default); - return error; -} - -int git_remote_upload( - git_remote *remote, - const git_strarray *refspecs, - const git_push_options *opts) -{ - git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; - git_push *push; - git_refspec *spec; - size_t i; - int error; - - GIT_ASSERT_ARG(remote); - - if (!remote->repo) { - git_error_set(GIT_ERROR_INVALID, "cannot download detached remote"); - return -1; - } - - if ((error = git_remote_connect_options__from_push_opts( - &connect_opts, remote, opts)) < 0) - goto cleanup; - - if ((error = connect_or_reset_options(remote, GIT_DIRECTION_PUSH, &connect_opts)) < 0) - goto cleanup; - - free_refspecs(&remote->active_refspecs); - if ((error = dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs)) < 0) - goto cleanup; - - if (remote->push) { - git_push_free(remote->push); - remote->push = NULL; - } - - if ((error = git_push_new(&remote->push, remote, opts)) < 0) - goto cleanup; - - push = remote->push; - - if (refspecs && refspecs->count > 0) { - for (i = 0; i < refspecs->count; i++) { - if ((error = git_push_add_refspec(push, refspecs->strings[i])) < 0) - goto cleanup; - } - } else { - git_vector_foreach(&remote->refspecs, i, spec) { - if (!spec->push) - continue; - if ((error = git_push_add_refspec(push, spec->string)) < 0) - goto cleanup; - } - } - - if (opts && opts->remote_push_options.count > 0) - for (i = 0; i < opts->remote_push_options.count; ++i) { - char *optstr = git__strdup(opts->remote_push_options.strings[i]); - GIT_ERROR_CHECK_ALLOC(optstr); - - if ((error = git_vector_insert(&push->remote_push_options, optstr)) < 0) - goto cleanup; - } - - error = git_push_finish(push); - - if (connect_opts.callbacks.push_update_reference) { - const int cb_error = git_push_status_foreach(push, connect_opts.callbacks.push_update_reference, connect_opts.callbacks.payload); - if (!error) - error = cb_error; - } - -cleanup: - git_remote_connect_options_dispose(&connect_opts); - return error; -} - -int git_remote_push( - git_remote *remote, - const git_strarray *refspecs, - const git_push_options *opts) -{ - git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; - int error; - - GIT_ASSERT_ARG(remote); - - if (!remote->repo) { - git_error_set(GIT_ERROR_INVALID, "cannot download detached remote"); - return -1; - } - - if (git_remote_connect_options__from_push_opts(&connect_opts, - remote, opts) < 0) - return -1; - - if ((error = git_remote_upload(remote, refspecs, opts)) < 0) - goto done; - - error = git_remote_update_tips(remote, &connect_opts.callbacks, 0, 0, NULL); - -done: - git_remote_disconnect(remote); - git_remote_connect_options_dispose(&connect_opts); - return error; -} - -#define PREFIX "url" -#define SUFFIX_FETCH "insteadof" -#define SUFFIX_PUSH "pushinsteadof" - -static int apply_insteadof(char **out, git_config *config, const char *url, int direction, bool use_default_if_empty) -{ - size_t match_length, prefix_length, suffix_length; - char *replacement = NULL; - const char *regexp; - - git_str result = GIT_STR_INIT; - git_config_entry *entry; - git_config_iterator *iter; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(config); - GIT_ASSERT_ARG(url); - GIT_ASSERT_ARG(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH); - - /* Add 1 to prefix/suffix length due to the additional escaped dot */ - prefix_length = strlen(PREFIX) + 1; - if (direction == GIT_DIRECTION_FETCH) { - regexp = PREFIX "\\..*\\." SUFFIX_FETCH; - suffix_length = strlen(SUFFIX_FETCH) + 1; - } else { - regexp = PREFIX "\\..*\\." SUFFIX_PUSH; - suffix_length = strlen(SUFFIX_PUSH) + 1; - } - - if (git_config_iterator_glob_new(&iter, config, regexp) < 0) - return -1; - - match_length = 0; - while (git_config_next(&entry, iter) == 0) { - size_t n, replacement_length; - - /* Check if entry value is a prefix of URL */ - if (git__prefixcmp(url, entry->value)) - continue; - - /* Check if entry value is longer than previous - * prefixes */ - if ((n = strlen(entry->value)) <= match_length) - continue; - - git__free(replacement); - match_length = n; - - /* Cut off prefix and suffix of the value */ - replacement_length = - strlen(entry->name) - (prefix_length + suffix_length); - replacement = git__strndup(entry->name + prefix_length, - replacement_length); - } - - git_config_iterator_free(iter); - - if (match_length == 0 && use_default_if_empty) { - *out = git__strdup(url); - return *out ? 0 : -1; - } else if (match_length == 0) { - *out = NULL; - return 0; - } - - git_str_printf(&result, "%s%s", replacement, url + match_length); - - git__free(replacement); - - *out = git_str_detach(&result); - return 0; -} - -/* Deprecated functions */ - -#ifndef GIT_DEPRECATE_HARD - -int git_remote_is_valid_name(const char *remote_name) -{ - int valid = 0; - - git_remote_name_is_valid(&valid, remote_name); - return valid; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/remote.h b/vendor/libgit2-sys/libgit2/src/libgit2/remote.h deleted file mode 100644 index cc560f1..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/remote.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_remote_h__ -#define INCLUDE_remote_h__ - -#include "common.h" - -#include "git2/remote.h" -#include "git2/transport.h" -#include "git2/sys/remote.h" -#include "git2/sys/transport.h" - -#include "refspec.h" -#include "vector.h" -#include "net.h" -#include "proxy.h" - -#define GIT_REMOTE_ORIGIN "origin" - -struct git_remote { - char *name; - char *url; - char *pushurl; - git_vector refs; - git_vector refspecs; - git_vector active_refspecs; - git_vector passive_refspecs; - git_vector local_heads; - git_transport *transport; - git_repository *repo; - git_push *push; - git_indexer_progress stats; - unsigned int need_pack; - git_remote_autotag_option_t download_tags; - int prune_refs; - int passed_refspecs; - git_fetch_negotiation nego; -}; - -int git_remote__urlfordirection(git_str *url_out, struct git_remote *remote, int direction, const git_remote_callbacks *callbacks); -int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url); - -git_refspec *git_remote__matching_refspec(git_remote *remote, const char *refname); -git_refspec *git_remote__matching_dst_refspec(git_remote *remote, const char *refname); - -int git_remote__default_branch(git_str *out, git_remote *remote); - -int git_remote_connect_options_dup( - git_remote_connect_options *dst, - const git_remote_connect_options *src); -int git_remote_connect_options_normalize( - git_remote_connect_options *dst, - git_repository *repo, - const git_remote_connect_options *src); - -int git_remote_capabilities(unsigned int *out, git_remote *remote); - - -#define git_remote_connect_options__copy_opts(out, in) \ - if (in) { \ - (out)->callbacks = (in)->callbacks; \ - (out)->proxy_opts = (in)->proxy_opts; \ - (out)->custom_headers = (in)->custom_headers; \ - (out)->follow_redirects = (in)->follow_redirects; \ - } - -GIT_INLINE(int) git_remote_connect_options__from_fetch_opts( - git_remote_connect_options *out, - git_remote *remote, - const git_fetch_options *fetch_opts) -{ - git_remote_connect_options tmp = GIT_REMOTE_CONNECT_OPTIONS_INIT; - git_remote_connect_options__copy_opts(&tmp, fetch_opts); - return git_remote_connect_options_normalize(out, remote->repo, &tmp); -} - -GIT_INLINE(int) git_remote_connect_options__from_push_opts( - git_remote_connect_options *out, - git_remote *remote, - const git_push_options *push_opts) -{ - git_remote_connect_options tmp = GIT_REMOTE_CONNECT_OPTIONS_INIT; - git_remote_connect_options__copy_opts(&tmp, push_opts); - return git_remote_connect_options_normalize(out, remote->repo, &tmp); -} - -#undef git_remote_connect_options__copy_opts - -GIT_INLINE(void) git_remote_connect_options__dispose( - git_remote_connect_options *opts) -{ - git_proxy_options_dispose(&opts->proxy_opts); - git_strarray_dispose(&opts->custom_headers); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/repo_template.h b/vendor/libgit2-sys/libgit2/src/libgit2/repo_template.h deleted file mode 100644 index 099279a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/repo_template.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_repo_template_h__ -#define INCLUDE_repo_template_h__ - -#define GIT_OBJECTS_INFO_DIR GIT_OBJECTS_DIR "info/" -#define GIT_OBJECTS_PACK_DIR GIT_OBJECTS_DIR "pack/" - -#define GIT_HOOKS_DIR "hooks/" -#define GIT_HOOKS_DIR_MODE 0777 - -#define GIT_HOOKS_README_FILE GIT_HOOKS_DIR "README.sample" -#define GIT_HOOKS_README_MODE 0777 -#define GIT_HOOKS_README_CONTENT \ -"#!/bin/sh\n"\ -"#\n"\ -"# Place appropriately named executable hook scripts into this directory\n"\ -"# to intercept various actions that git takes. See `git help hooks` for\n"\ -"# more information.\n" - -#define GIT_INFO_DIR "info/" -#define GIT_INFO_DIR_MODE 0777 - -#define GIT_INFO_EXCLUDE_FILE GIT_INFO_DIR "exclude" -#define GIT_INFO_EXCLUDE_MODE 0666 -#define GIT_INFO_EXCLUDE_CONTENT \ -"# File patterns to ignore; see `git help ignore` for more information.\n"\ -"# Lines that start with '#' are comments.\n" - -#define GIT_DESC_FILE "description" -#define GIT_DESC_MODE 0666 -#define GIT_DESC_CONTENT \ -"Unnamed repository; edit this file 'description' to name the repository.\n" - -typedef struct { - const char *path; - mode_t mode; - const char *content; -} repo_template_item; - -static repo_template_item repo_template[] = { - { GIT_OBJECTS_INFO_DIR, GIT_OBJECT_DIR_MODE, NULL }, /* '/objects/info/' */ - { GIT_OBJECTS_PACK_DIR, GIT_OBJECT_DIR_MODE, NULL }, /* '/objects/pack/' */ - { GIT_REFS_HEADS_DIR, GIT_REFS_DIR_MODE, NULL }, /* '/refs/heads/' */ - { GIT_REFS_TAGS_DIR, GIT_REFS_DIR_MODE, NULL }, /* '/refs/tags/' */ - { GIT_HOOKS_DIR, GIT_HOOKS_DIR_MODE, NULL }, /* '/hooks/' */ - { GIT_INFO_DIR, GIT_INFO_DIR_MODE, NULL }, /* '/info/' */ - { GIT_DESC_FILE, GIT_DESC_MODE, GIT_DESC_CONTENT }, - { GIT_HOOKS_README_FILE, GIT_HOOKS_README_MODE, GIT_HOOKS_README_CONTENT }, - { GIT_INFO_EXCLUDE_FILE, GIT_INFO_EXCLUDE_MODE, GIT_INFO_EXCLUDE_CONTENT }, - { NULL, 0, NULL } -}; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/repository.c b/vendor/libgit2-sys/libgit2/src/libgit2/repository.c deleted file mode 100644 index 9fed12c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/repository.c +++ /dev/null @@ -1,4022 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "repository.h" - -#include - -#include "git2/object.h" -#include "git2/sys/repository.h" - -#include "buf.h" -#include "common.h" -#include "commit.h" -#include "grafts.h" -#include "tag.h" -#include "blob.h" -#include "futils.h" -#include "sysdir.h" -#include "filebuf.h" -#include "index.h" -#include "config.h" -#include "refs.h" -#include "filter.h" -#include "odb.h" -#include "refdb.h" -#include "remote.h" -#include "merge.h" -#include "diff_driver.h" -#include "annotated_commit.h" -#include "submodule.h" -#include "worktree.h" -#include "path.h" - -#ifdef GIT_WIN32 -# include "win32/w32_util.h" -#endif - -bool git_repository__validate_ownership = true; -bool git_repository__fsync_gitdir = false; - -static const struct { - git_repository_item_t parent; - git_repository_item_t fallback; - const char *name; - bool directory; -} items[] = { - { GIT_REPOSITORY_ITEM_GITDIR, GIT_REPOSITORY_ITEM__LAST, NULL, true }, - { GIT_REPOSITORY_ITEM_WORKDIR, GIT_REPOSITORY_ITEM__LAST, NULL, true }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM__LAST, NULL, true }, - { GIT_REPOSITORY_ITEM_GITDIR, GIT_REPOSITORY_ITEM__LAST, "index", false }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "objects", true }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "refs", true }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "packed-refs", false }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "remotes", true }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "config", false }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "info", true }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "hooks", true }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "logs", true }, - { GIT_REPOSITORY_ITEM_GITDIR, GIT_REPOSITORY_ITEM__LAST, "modules", true }, - { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "worktrees", true }, - { GIT_REPOSITORY_ITEM_GITDIR, GIT_REPOSITORY_ITEM_GITDIR, "config.worktree", false } -}; - -static int check_repositoryformatversion(int *version, git_config *config); -static int check_extensions(git_config *config, int version); -static int load_global_config(git_config **config, bool use_env); -static int load_objectformat(git_repository *repo, git_config *config); - -#define GIT_COMMONDIR_FILE "commondir" -#define GIT_GITDIR_FILE "gitdir" - -#define GIT_FILE_CONTENT_PREFIX "gitdir:" - -#define GIT_BRANCH_DEFAULT "master" - -#define GIT_REPO_VERSION_DEFAULT 0 -#define GIT_REPO_VERSION_MAX 1 - -git_str git_repository__reserved_names_win32[] = { - { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) }, - { GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) } -}; -size_t git_repository__reserved_names_win32_len = 2; - -git_str git_repository__reserved_names_posix[] = { - { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) }, -}; -size_t git_repository__reserved_names_posix_len = 1; - -static void set_odb(git_repository *repo, git_odb *odb) -{ - if (odb) { - GIT_REFCOUNT_OWN(odb, repo); - GIT_REFCOUNT_INC(odb); - } - - if ((odb = git_atomic_swap(repo->_odb, odb)) != NULL) { - GIT_REFCOUNT_OWN(odb, NULL); - git_odb_free(odb); - } -} - -static void set_refdb(git_repository *repo, git_refdb *refdb) -{ - if (refdb) { - GIT_REFCOUNT_OWN(refdb, repo); - GIT_REFCOUNT_INC(refdb); - } - - if ((refdb = git_atomic_swap(repo->_refdb, refdb)) != NULL) { - GIT_REFCOUNT_OWN(refdb, NULL); - git_refdb_free(refdb); - } -} - -static void set_config(git_repository *repo, git_config *config) -{ - if (config) { - GIT_REFCOUNT_OWN(config, repo); - GIT_REFCOUNT_INC(config); - } - - if ((config = git_atomic_swap(repo->_config, config)) != NULL) { - GIT_REFCOUNT_OWN(config, NULL); - git_config_free(config); - } - - git_repository__configmap_lookup_cache_clear(repo); -} - -static void set_index(git_repository *repo, git_index *index) -{ - if (index) { - GIT_REFCOUNT_OWN(index, repo); - GIT_REFCOUNT_INC(index); - } - - if ((index = git_atomic_swap(repo->_index, index)) != NULL) { - GIT_REFCOUNT_OWN(index, NULL); - git_index_free(index); - } -} - -int git_repository__cleanup(git_repository *repo) -{ - GIT_ASSERT_ARG(repo); - - git_repository_submodule_cache_clear(repo); - git_cache_clear(&repo->objects); - git_attr_cache_flush(repo); - git_grafts_free(repo->grafts); - repo->grafts = NULL; - git_grafts_free(repo->shallow_grafts); - repo->shallow_grafts = NULL; - - set_config(repo, NULL); - set_index(repo, NULL); - set_odb(repo, NULL); - set_refdb(repo, NULL); - - return 0; -} - -void git_repository_free(git_repository *repo) -{ - size_t i; - - if (repo == NULL) - return; - - git_repository__cleanup(repo); - - git_cache_dispose(&repo->objects); - - git_diff_driver_registry_free(repo->diff_drivers); - repo->diff_drivers = NULL; - - for (i = 0; i < repo->reserved_names.size; i++) - git_str_dispose(git_array_get(repo->reserved_names, i)); - git_array_clear(repo->reserved_names); - - git__free(repo->gitlink); - git__free(repo->gitdir); - git__free(repo->commondir); - git__free(repo->workdir); - git__free(repo->namespace); - git__free(repo->ident_name); - git__free(repo->ident_email); - - git__memzero(repo, sizeof(*repo)); - git__free(repo); -} - -/* Check if we have a separate commondir (e.g. we have a worktree) */ -static int lookup_commondir( - bool *separate, - git_str *commondir, - git_str *repository_path, - uint32_t flags) -{ - git_str common_link = GIT_STR_INIT; - int error; - - /* Environment variable overrides configuration */ - if ((flags & GIT_REPOSITORY_OPEN_FROM_ENV)) { - error = git__getenv(commondir, "GIT_COMMON_DIR"); - - if (!error || error != GIT_ENOTFOUND) - goto done; - } - - /* - * If there's no commondir file, the repository path is the - * common path, but it needs a trailing slash. - */ - if (!git_fs_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) { - if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0) - error = git_fs_path_to_dir(commondir); - - *separate = false; - goto done; - } - - *separate = true; - - if ((error = git_str_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 || - (error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0) - goto done; - - git_str_rtrim(&common_link); - if (git_fs_path_is_relative(common_link.ptr)) { - if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0) - goto done; - } else { - git_str_swap(commondir, &common_link); - } - - /* Make sure the commondir path always has a trailing slash */ - error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL); - -done: - git_str_dispose(&common_link); - return error; -} - -GIT_INLINE(int) validate_repo_path(git_str *path) -{ - /* - * The longest static path in a repository (or commondir) is the - * packed refs file. (Loose refs may be longer since they - * include the reference name, but will be validated when the - * path is constructed.) - */ - static size_t suffix_len = - CONST_STRLEN("objects/pack/pack-.pack.lock") + - GIT_OID_MAX_HEXSIZE; - - return git_fs_path_validate_str_length_with_suffix( - path, suffix_len); -} - -/* - * Git repository open methods - * - * Open a repository object from its path - */ -static int is_valid_repository_path( - bool *out, - git_str *repository_path, - git_str *common_path, - uint32_t flags) -{ - bool separate_commondir = false; - int error; - - *out = false; - - if ((error = lookup_commondir(&separate_commondir, - common_path, repository_path, flags)) < 0) - return error; - - /* Ensure HEAD file exists */ - if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false) - return 0; - - /* Check files in common dir */ - if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false) - return 0; - if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false) - return 0; - - /* Ensure the repo (and commondir) are valid paths */ - if ((error = validate_repo_path(common_path)) < 0 || - (separate_commondir && - (error = validate_repo_path(repository_path)) < 0)) - return error; - - *out = true; - return 0; -} - -static git_repository *repository_alloc(void) -{ - git_repository *repo = git__calloc(1, sizeof(git_repository)); - - if (repo == NULL || - git_cache_init(&repo->objects) < 0) - goto on_error; - - git_array_init_to_size(repo->reserved_names, 4); - if (!repo->reserved_names.ptr) - goto on_error; - - /* set all the entries in the configmap cache to `unset` */ - git_repository__configmap_lookup_cache_clear(repo); - - return repo; - -on_error: - if (repo) - git_cache_dispose(&repo->objects); - - git__free(repo); - return NULL; -} - -int git_repository__new(git_repository **out, git_oid_t oid_type) -{ - git_repository *repo; - - *out = repo = repository_alloc(); - GIT_ERROR_CHECK_ALLOC(repo); - - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); - - repo->is_bare = 1; - repo->is_worktree = 0; - repo->oid_type = oid_type; - - return 0; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_repository_new(git_repository **out, git_repository_new_options *opts) -{ - return git_repository__new(out, opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT); -} -#else -int git_repository_new(git_repository** out) -{ - return git_repository__new(out, GIT_OID_SHA1); -} -#endif - -static int load_config_data(git_repository *repo, const git_config *config) -{ - int is_bare; - - int err = git_config_get_bool(&is_bare, config, "core.bare"); - if (err < 0 && err != GIT_ENOTFOUND) - return err; - - /* Try to figure out if it's bare, default to non-bare if it's not set */ - if (err != GIT_ENOTFOUND) - repo->is_bare = is_bare && !repo->is_worktree; - else - repo->is_bare = 0; - - return 0; -} - -static int load_workdir( - git_repository *repo, - git_config *config, - git_str *parent_path) -{ - git_config_entry *ce = NULL; - git_str worktree = GIT_STR_INIT; - git_str path = GIT_STR_INIT; - git_str workdir_env = GIT_STR_INIT; - const char *value = NULL; - int error; - - if (repo->is_bare) - return 0; - - /* Environment variables are preferred */ - if (repo->use_env) { - error = git__getenv(&workdir_env, "GIT_WORK_TREE"); - - if (error == 0) - value = workdir_env.ptr; - else if (error == GIT_ENOTFOUND) - error = 0; - else - goto cleanup; - } - - /* Examine configuration values if necessary */ - if (!value) { - if ((error = git_config__lookup_entry(&ce, config, - "core.worktree", false)) < 0) - return error; - - if (ce && ce->value) - value = ce->value; - } - - if (repo->is_worktree) { - char *gitlink = git_worktree__read_link(repo->gitdir, GIT_GITDIR_FILE); - if (!gitlink) { - error = -1; - goto cleanup; - } - - git_str_attach(&worktree, gitlink, 0); - - if ((git_fs_path_dirname_r(&worktree, worktree.ptr)) < 0 || - git_fs_path_to_dir(&worktree) < 0) { - error = -1; - goto cleanup; - } - - repo->workdir = git_str_detach(&worktree); - } else if (value) { - if (!*value) { - git_error_set(GIT_ERROR_NET, "working directory cannot be set to empty path"); - error = -1; - goto cleanup; - } - - if ((error = git_fs_path_prettify_dir(&worktree, - value, repo->gitdir)) < 0) - goto cleanup; - - repo->workdir = git_str_detach(&worktree); - } else if (parent_path && git_fs_path_isdir(parent_path->ptr)) { - repo->workdir = git_str_detach(parent_path); - } else { - if (git_fs_path_dirname_r(&worktree, repo->gitdir) < 0 || - git_fs_path_to_dir(&worktree) < 0) { - error = -1; - goto cleanup; - } - - repo->workdir = git_str_detach(&worktree); - } - - GIT_ERROR_CHECK_ALLOC(repo->workdir); - -cleanup: - git_str_dispose(&path); - git_str_dispose(&workdir_env); - git_config_entry_free(ce); - return error; -} - -/* - * This function returns furthest offset into path where a ceiling dir - * is found, so we can stop processing the path at that point. - * - * Note: converting this to use git_strs instead of GIT_PATH_MAX buffers on - * the stack could remove directories name limits, but at the cost of doing - * repeated malloc/frees inside the loop below, so let's not do it now. - */ -static size_t find_ceiling_dir_offset( - const char *path, - const char *ceiling_directories) -{ - char buf[GIT_PATH_MAX + 1]; - char buf2[GIT_PATH_MAX + 1]; - const char *ceil, *sep; - size_t len, max_len = 0, min_len; - - GIT_ASSERT_ARG(path); - - min_len = (size_t)(git_fs_path_root(path) + 1); - - if (ceiling_directories == NULL || min_len == 0) - return min_len; - - for (sep = ceil = ceiling_directories; *sep; ceil = sep + 1) { - for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++); - len = sep - ceil; - - if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1) - continue; - - strncpy(buf, ceil, len); - buf[len] = '\0'; - - if (p_realpath(buf, buf2) == NULL) - continue; - - len = strlen(buf2); - if (len > 0 && buf2[len-1] == '/') - buf[--len] = '\0'; - - if (!strncmp(path, buf2, len) && - (path[len] == '/' || !path[len]) && - len > max_len) - { - max_len = len; - } - } - - return (max_len <= min_len ? min_len : max_len); -} - -/* - * Read the contents of `file_path` and set `path_out` to the repo dir that - * it points to. Before calling, set `path_out` to the base directory that - * should be used if the contents of `file_path` are a relative path. - */ -static int read_gitfile(git_str *path_out, const char *file_path) -{ - int error = 0; - git_str file = GIT_STR_INIT; - size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX); - - GIT_ASSERT_ARG(path_out); - GIT_ASSERT_ARG(file_path); - - if (git_futils_readbuffer(&file, file_path) < 0) - return -1; - - git_str_rtrim(&file); - /* apparently on Windows, some people use backslashes in paths */ - git_fs_path_mkposix(file.ptr); - - if (git_str_len(&file) <= prefix_len || - memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0) - { - git_error_set(GIT_ERROR_REPOSITORY, - "the `.git` file at '%s' is malformed", file_path); - error = -1; - } - else if ((error = git_fs_path_dirname_r(path_out, file_path)) >= 0) { - const char *gitlink = git_str_cstr(&file) + prefix_len; - while (*gitlink && git__isspace(*gitlink)) gitlink++; - - error = git_fs_path_prettify_dir( - path_out, gitlink, git_str_cstr(path_out)); - } - - git_str_dispose(&file); - return error; -} - -typedef struct { - const char *repo_path; - git_str tmp; - bool *is_safe; -} validate_ownership_data; - -static int validate_ownership_cb(const git_config_entry *entry, void *payload) -{ - validate_ownership_data *data = payload; - const char *test_path; - - if (!entry->value || strcmp(entry->value, "") == 0) { - *data->is_safe = false; - } else if (strcmp(entry->value, "*") == 0) { - *data->is_safe = true; - } else { - if (git_str_sets(&data->tmp, entry->value) < 0) - return -1; - - if (!git_fs_path_is_root(data->tmp.ptr)) { - /* Input must not have trailing backslash. */ - if (!data->tmp.size || - data->tmp.ptr[data->tmp.size - 1] == '/') - return 0; - - if (git_fs_path_to_dir(&data->tmp) < 0) - return -1; - } - - test_path = data->tmp.ptr; - - /* - * Git - and especially, Git for Windows - does some - * truly bizarre things with paths that start with a - * forward slash; and expects you to escape that with - * `%(prefix)`. This syntax generally means to add the - * prefix that Git was installed to (eg `/usr/local`) - * unless it's an absolute path, in which case the - * leading `%(prefix)/` is just removed. And Git for - * Windows expects you to use this syntax for absolute - * Unix-style paths (in "Git Bash" or Windows Subsystem - * for Linux). - * - * Worse, the behavior used to be that a leading `/` was - * not absolute. It would indicate that Git for Windows - * should add the prefix. So `//` is required for absolute - * Unix-style paths. Yes, this is truly horrifying. - * - * Emulate that behavior, I guess, but only for absolute - * paths. We won't deal with the Git install prefix. Also, - * give WSL users an escape hatch where they don't have to - * think about this and can use the literal path that the - * filesystem APIs provide (`//wsl.localhost/...`). - */ - if (strncmp(test_path, "%(prefix)//", strlen("%(prefix)//")) == 0) - test_path += strlen("%(prefix)/"); - - if (strcmp(test_path, data->repo_path) == 0) - *data->is_safe = true; - } - - return 0; -} - -static int validate_ownership_config( - bool *is_safe, - const char *path, - bool use_env) -{ - validate_ownership_data ownership_data = { - path, GIT_STR_INIT, is_safe - }; - git_config *config; - int error; - - if (load_global_config(&config, use_env) != 0) - return 0; - - error = git_config_get_multivar_foreach(config, - "safe.directory", NULL, - validate_ownership_cb, - &ownership_data); - - if (error == GIT_ENOTFOUND) - error = 0; - - git_config_free(config); - git_str_dispose(&ownership_data.tmp); - - return error; -} - -static int validate_ownership_path(bool *is_safe, const char *path) -{ - git_fs_path_owner_t owner_level = - GIT_FS_PATH_OWNER_CURRENT_USER | - GIT_FS_PATH_USER_IS_ADMINISTRATOR | - GIT_FS_PATH_OWNER_RUNNING_SUDO; - int error = 0; - - if (path) - error = git_fs_path_owner_is(is_safe, path, owner_level); - - if (error == GIT_ENOTFOUND) { - *is_safe = true; - error = 0; - } else if (error == GIT_EINVALID) { - *is_safe = false; - error = 0; - } - - return error; -} - -static int validate_ownership(git_repository *repo) -{ - const char *validation_paths[3] = { NULL }, *path = NULL; - size_t validation_len = 0, i; - bool is_safe = false; - int error = 0; - - /* - * If there's a worktree, validate the permissions to it *and* - * the git directory, and use the worktree as the configuration - * key for allowlisting the directory. In a bare setup, only - * look at the gitdir and use that as the allowlist. So we - * examine all `validation_paths` but use only the first as - * the configuration lookup. - */ - - if (repo->workdir) - validation_paths[validation_len++] = repo->workdir; - - if (repo->gitlink) - validation_paths[validation_len++] = repo->gitlink; - - validation_paths[validation_len++] = repo->gitdir; - - for (i = 0; i < validation_len; i++) { - path = validation_paths[i]; - - if ((error = validate_ownership_path(&is_safe, path)) < 0) - goto done; - - if (!is_safe) - break; - } - - if (is_safe || - (error = validate_ownership_config( - &is_safe, validation_paths[0], repo->use_env)) < 0) - goto done; - - if (!is_safe) { - size_t path_len = git_fs_path_is_root(path) ? - strlen(path) : git_fs_path_dirlen(path); - - git_error_set(GIT_ERROR_CONFIG, - "repository path '%.*s' is not owned by current user", - (int)min(path_len, INT_MAX), path); - error = GIT_EOWNER; - } - -done: - return error; -} - -struct repo_paths { - git_str gitdir; - git_str workdir; - git_str gitlink; - git_str commondir; -}; - -#define REPO_PATHS_INIT { GIT_STR_INIT } - -GIT_INLINE(void) repo_paths_dispose(struct repo_paths *paths) -{ - git_str_dispose(&paths->gitdir); - git_str_dispose(&paths->workdir); - git_str_dispose(&paths->gitlink); - git_str_dispose(&paths->commondir); -} - -static int find_repo_traverse( - struct repo_paths *out, - const char *start_path, - const char *ceiling_dirs, - uint32_t flags) -{ - git_str path = GIT_STR_INIT; - git_str repo_link = GIT_STR_INIT; - git_str common_link = GIT_STR_INIT; - struct stat st; - dev_t initial_device = 0; - int min_iterations; - bool in_dot_git, is_valid; - size_t ceiling_offset = 0; - int error; - - git_str_clear(&out->gitdir); - - if ((error = git_fs_path_prettify(&path, start_path, NULL)) < 0) - return error; - - /* - * In each loop we look first for a `.git` dir within the - * directory, then to see if the directory itself is a repo. - * - * In other words: if we start in /a/b/c, then we look at: - * /a/b/c/.git, /a/b/c, /a/b/.git, /a/b, /a/.git, /a - * - * With GIT_REPOSITORY_OPEN_BARE or GIT_REPOSITORY_OPEN_NO_DOTGIT, - * we assume we started with /a/b/c.git and don't append .git the - * first time through. min_iterations indicates the number of - * iterations left before going further counts as a search. - */ - if (flags & (GIT_REPOSITORY_OPEN_BARE | GIT_REPOSITORY_OPEN_NO_DOTGIT)) { - in_dot_git = true; - min_iterations = 1; - } else { - in_dot_git = false; - min_iterations = 2; - } - - for (;;) { - if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) { - if (!in_dot_git) { - if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0) - goto out; - } - in_dot_git = !in_dot_git; - } - - if (p_stat(path.ptr, &st) == 0) { - /* check that we have not crossed device boundaries */ - if (initial_device == 0) - initial_device = st.st_dev; - else if (st.st_dev != initial_device && - !(flags & GIT_REPOSITORY_OPEN_CROSS_FS)) - break; - - if (S_ISDIR(st.st_mode)) { - if ((error = is_valid_repository_path(&is_valid, &path, &common_link, flags)) < 0) - goto out; - - if (is_valid) { - if ((error = git_fs_path_to_dir(&path)) < 0 || - (error = git_str_set(&out->gitdir, path.ptr, path.size)) < 0) - goto out; - - if ((error = git_str_attach(&out->gitlink, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0) - goto out; - - git_str_swap(&common_link, &out->commondir); - - break; - } - } else if (S_ISREG(st.st_mode) && git__suffixcmp(path.ptr, "/" DOT_GIT) == 0) { - if ((error = read_gitfile(&repo_link, path.ptr)) < 0 || - (error = is_valid_repository_path(&is_valid, &repo_link, &common_link, flags)) < 0) - goto out; - - if (is_valid) { - git_str_swap(&out->gitdir, &repo_link); - - if ((error = git_str_put(&out->gitlink, path.ptr, path.size)) < 0) - goto out; - - git_str_swap(&common_link, &out->commondir); - } - break; - } - } - - /* - * Move up one directory. If we're in_dot_git, we'll - * search the parent itself next. If we're !in_dot_git, - * we'll search .git in the parent directory next (added - * at the top of the loop). - */ - if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0) - goto out; - - /* - * Once we've checked the directory (and .git if - * applicable), find the ceiling for a search. - */ - if (min_iterations && (--min_iterations == 0)) - ceiling_offset = find_ceiling_dir_offset(path.ptr, ceiling_dirs); - - /* Check if we should stop searching here. */ - if (min_iterations == 0 && - (path.ptr[ceiling_offset] == 0 || (flags & GIT_REPOSITORY_OPEN_NO_SEARCH))) - break; - } - - if (!(flags & GIT_REPOSITORY_OPEN_BARE)) { - if (!git_str_len(&out->gitdir)) - git_str_clear(&out->workdir); - else if ((error = git_fs_path_dirname_r(&out->workdir, path.ptr)) < 0 || - (error = git_fs_path_to_dir(&out->workdir)) < 0) - goto out; - } - - /* If we didn't find the repository, and we don't have any other - * error to report, report that. */ - if (!git_str_len(&out->gitdir)) { - git_error_set(GIT_ERROR_REPOSITORY, "could not find repository at '%s'", start_path); - error = GIT_ENOTFOUND; - goto out; - } - -out: - if (error) - repo_paths_dispose(out); - - git_str_dispose(&path); - git_str_dispose(&repo_link); - git_str_dispose(&common_link); - return error; -} - -static int load_grafts(git_repository *repo) -{ - git_str path = GIT_STR_INIT; - int error; - - /* refresh if they've both been opened previously */ - if (repo->grafts && repo->shallow_grafts) { - if ((error = git_grafts_refresh(repo->grafts)) < 0 || - (error = git_grafts_refresh(repo->shallow_grafts)) < 0) - return error; - } - - /* resolve info path, which may not be found for inmemory repository */ - if ((error = git_repository__item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0) { - if (error != GIT_ENOTFOUND) - return error; - - /* create empty/inmemory grafts for inmemory repository */ - if (!repo->grafts && (error = git_grafts_new(&repo->grafts, repo->oid_type)) < 0) - return error; - - if (!repo->shallow_grafts && (error = git_grafts_new(&repo->shallow_grafts, repo->oid_type)) < 0) - return error; - - return 0; - } - - /* load grafts from disk */ - if ((error = git_str_joinpath(&path, path.ptr, "grafts")) < 0 || - (error = git_grafts_open_or_refresh(&repo->grafts, path.ptr, repo->oid_type)) < 0) - goto error; - - git_str_clear(&path); - - if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0 || - (error = git_grafts_open_or_refresh(&repo->shallow_grafts, path.ptr, repo->oid_type)) < 0) - goto error; - -error: - git_str_dispose(&path); - return error; -} - -static int find_repo( - struct repo_paths *out, - const char *start_path, - const char *ceiling_dirs, - uint32_t flags) -{ - bool use_env = !!(flags & GIT_REPOSITORY_OPEN_FROM_ENV); - git_str gitdir_buf = GIT_STR_INIT, - ceiling_dirs_buf = GIT_STR_INIT, - across_fs_buf = GIT_STR_INIT; - int error; - - if (use_env && !start_path) { - error = git__getenv(&gitdir_buf, "GIT_DIR"); - - if (!error) { - start_path = gitdir_buf.ptr; - flags |= GIT_REPOSITORY_OPEN_NO_SEARCH; - flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT; - } else if (error == GIT_ENOTFOUND) { - start_path = "."; - } else { - goto done; - } - } - - if (use_env && !ceiling_dirs) { - error = git__getenv(&ceiling_dirs_buf, - "GIT_CEILING_DIRECTORIES"); - - if (!error) - ceiling_dirs = ceiling_dirs_buf.ptr; - else if (error != GIT_ENOTFOUND) - goto done; - } - - if (use_env) { - error = git__getenv(&across_fs_buf, - "GIT_DISCOVERY_ACROSS_FILESYSTEM"); - - if (!error) { - int across_fs = 0; - - if ((error = git_config_parse_bool(&across_fs, - git_str_cstr(&across_fs_buf))) < 0) - goto done; - - if (across_fs) - flags |= GIT_REPOSITORY_OPEN_CROSS_FS; - } else if (error != GIT_ENOTFOUND) { - goto done; - } - } - - error = find_repo_traverse(out, start_path, ceiling_dirs, flags); - -done: - git_str_dispose(&gitdir_buf); - git_str_dispose(&ceiling_dirs_buf); - git_str_dispose(&across_fs_buf); - - return error; -} - -static int obtain_config_and_set_oid_type( - git_config **config_ptr, - git_repository *repo) -{ - int error; - git_config *config = NULL; - int version = 0; - - /* - * We'd like to have the config, but git doesn't particularly - * care if it's not there, so we need to deal with that. - */ - - error = git_repository_config_snapshot(&config, repo); - if (error < 0 && error != GIT_ENOTFOUND) - goto out; - - if (config && - (error = check_repositoryformatversion(&version, config)) < 0) - goto out; - - if ((error = check_extensions(config, version)) < 0) - goto out; - - if (version > 0) { - if ((error = load_objectformat(repo, config)) < 0) - goto out; - } else { - repo->oid_type = GIT_OID_DEFAULT; - } - -out: - *config_ptr = config; - - return error; -} - -int git_repository_open_bare( - git_repository **repo_ptr, - const char *bare_path) -{ - git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT; - git_repository *repo = NULL; - bool is_valid; - int error; - git_config *config; - - if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 || - (error = is_valid_repository_path(&is_valid, &path, &common_path, 0)) < 0) - return error; - - if (!is_valid) { - git_str_dispose(&path); - git_str_dispose(&common_path); - git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path); - return GIT_ENOTFOUND; - } - - repo = repository_alloc(); - GIT_ERROR_CHECK_ALLOC(repo); - - repo->gitdir = git_str_detach(&path); - GIT_ERROR_CHECK_ALLOC(repo->gitdir); - repo->commondir = git_str_detach(&common_path); - GIT_ERROR_CHECK_ALLOC(repo->commondir); - - /* of course we're bare! */ - repo->is_bare = 1; - repo->is_worktree = 0; - repo->workdir = NULL; - - if ((error = obtain_config_and_set_oid_type(&config, repo)) < 0) - goto cleanup; - - *repo_ptr = repo; - -cleanup: - git_config_free(config); - - return error; -} - -static int repo_load_namespace(git_repository *repo) -{ - git_str namespace_buf = GIT_STR_INIT; - int error; - - if (!repo->use_env) - return 0; - - error = git__getenv(&namespace_buf, "GIT_NAMESPACE"); - - if (error == 0) - repo->namespace = git_str_detach(&namespace_buf); - else if (error != GIT_ENOTFOUND) - return error; - - return 0; -} - -static int repo_is_worktree(unsigned *out, const git_repository *repo) -{ - git_str gitdir_link = GIT_STR_INIT; - int error; - - /* Worktrees cannot have the same commondir and gitdir */ - if (repo->commondir && repo->gitdir - && !strcmp(repo->commondir, repo->gitdir)) { - *out = 0; - return 0; - } - - if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0) - return -1; - - /* A 'gitdir' file inside a git directory is currently - * only used when the repository is a working tree. */ - *out = !!git_fs_path_exists(gitdir_link.ptr); - - git_str_dispose(&gitdir_link); - return error; -} - -int git_repository_open_ext( - git_repository **repo_ptr, - const char *start_path, - unsigned int flags, - const char *ceiling_dirs) -{ - struct repo_paths paths = { GIT_STR_INIT }; - git_repository *repo = NULL; - git_config *config = NULL; - unsigned is_worktree; - int error; - - if (repo_ptr) - *repo_ptr = NULL; - - error = find_repo(&paths, start_path, ceiling_dirs, flags); - - if (error < 0 || !repo_ptr) - goto cleanup; - - repo = repository_alloc(); - GIT_ERROR_CHECK_ALLOC(repo); - - repo->use_env = !!(flags & GIT_REPOSITORY_OPEN_FROM_ENV); - - repo->gitdir = git_str_detach(&paths.gitdir); - GIT_ERROR_CHECK_ALLOC(repo->gitdir); - - if (paths.gitlink.size) { - repo->gitlink = git_str_detach(&paths.gitlink); - GIT_ERROR_CHECK_ALLOC(repo->gitlink); - } - if (paths.commondir.size) { - repo->commondir = git_str_detach(&paths.commondir); - GIT_ERROR_CHECK_ALLOC(repo->commondir); - } - - if ((error = repo_is_worktree(&is_worktree, repo)) < 0) - goto cleanup; - - repo->is_worktree = is_worktree; - - error = obtain_config_and_set_oid_type(&config, repo); - if (error < 0) - goto cleanup; - - if ((error = load_grafts(repo)) < 0) - goto cleanup; - - if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) { - repo->is_bare = 1; - } else { - if (config && - ((error = load_config_data(repo, config)) < 0 || - (error = load_workdir(repo, config, &paths.workdir)) < 0)) - goto cleanup; - } - - if ((error = repo_load_namespace(repo)) < 0) - goto cleanup; - - /* - * Ensure that the git directory and worktree are - * owned by the current user. - */ - if (git_repository__validate_ownership && - (error = validate_ownership(repo)) < 0) - goto cleanup; - -cleanup: - repo_paths_dispose(&paths); - git_config_free(config); - - if (error < 0) - git_repository_free(repo); - else if (repo_ptr) - *repo_ptr = repo; - - return error; -} - -int git_repository_open(git_repository **repo_out, const char *path) -{ - return git_repository_open_ext( - repo_out, path, GIT_REPOSITORY_OPEN_NO_SEARCH, NULL); -} - -int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt) -{ - git_str path = GIT_STR_INIT; - git_repository *repo = NULL; - size_t len; - int err; - - GIT_ASSERT_ARG(repo_out); - GIT_ASSERT_ARG(wt); - - *repo_out = NULL; - len = strlen(wt->gitlink_path); - - if (len <= 4 || strcasecmp(wt->gitlink_path + len - 4, ".git")) { - err = -1; - goto out; - } - - if ((err = git_str_set(&path, wt->gitlink_path, len - 4)) < 0) - goto out; - - if ((err = git_repository_open(&repo, path.ptr)) < 0) - goto out; - - *repo_out = repo; - -out: - git_str_dispose(&path); - - return err; -} - -int git_repository_wrap_odb(git_repository **out, git_odb *odb) -{ - git_repository *repo; - - repo = repository_alloc(); - GIT_ERROR_CHECK_ALLOC(repo); - - GIT_ASSERT(git_oid_type_is_valid(odb->options.oid_type)); - repo->oid_type = odb->options.oid_type; - - git_repository_set_odb(repo, odb); - *out = repo; - - return 0; -} - -int git_repository_discover( - git_buf *out, - const char *start_path, - int across_fs, - const char *ceiling_dirs) -{ - struct repo_paths paths = { GIT_STR_INIT }; - uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0; - int error; - - GIT_ASSERT_ARG(start_path); - - if ((error = find_repo(&paths, start_path, ceiling_dirs, flags)) == 0) - error = git_buf_fromstr(out, &paths.gitdir); - - repo_paths_dispose(&paths); - return error; -} - -static int has_config_worktree(bool *out, git_config *cfg) -{ - int worktreeconfig = 0, error; - - *out = false; - - error = git_config_get_bool(&worktreeconfig, cfg, "extensions.worktreeconfig"); - - if (error == 0) - *out = worktreeconfig; - else if (error == GIT_ENOTFOUND) - *out = false; - else - return error; - - return 0; -} - -static int load_config( - git_config **out, - git_repository *repo, - const char *global_config_path, - const char *xdg_config_path, - const char *system_config_path, - const char *programdata_path) -{ - git_str config_path = GIT_STR_INIT; - git_config *cfg = NULL; - git_config_level_t write_order; - bool has_worktree; - int error; - - GIT_ASSERT_ARG(out); - - if ((error = git_config_new(&cfg)) < 0) - return error; - - if (repo) { - if ((error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0) - error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0); - - if (error && error != GIT_ENOTFOUND) - goto on_error; - - if ((error = has_config_worktree(&has_worktree, cfg)) == 0 && - has_worktree && - (error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_WORKTREE_CONFIG)) == 0) - error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_WORKTREE, repo, 0); - - if (error && error != GIT_ENOTFOUND) - goto on_error; - - git_str_dispose(&config_path); - } - - if (global_config_path != NULL && - (error = git_config_add_file_ondisk( - cfg, global_config_path, GIT_CONFIG_LEVEL_GLOBAL, repo, 0)) < 0 && - error != GIT_ENOTFOUND) - goto on_error; - - if (xdg_config_path != NULL && - (error = git_config_add_file_ondisk( - cfg, xdg_config_path, GIT_CONFIG_LEVEL_XDG, repo, 0)) < 0 && - error != GIT_ENOTFOUND) - goto on_error; - - if (system_config_path != NULL && - (error = git_config_add_file_ondisk( - cfg, system_config_path, GIT_CONFIG_LEVEL_SYSTEM, repo, 0)) < 0 && - error != GIT_ENOTFOUND) - goto on_error; - - if (programdata_path != NULL && - (error = git_config_add_file_ondisk( - cfg, programdata_path, GIT_CONFIG_LEVEL_PROGRAMDATA, repo, 0)) < 0 && - error != GIT_ENOTFOUND) - goto on_error; - - git_error_clear(); /* clear any lingering ENOTFOUND errors */ - - write_order = GIT_CONFIG_LEVEL_LOCAL; - - if ((error = git_config_set_writeorder(cfg, &write_order, 1)) < 0) - goto on_error; - - *out = cfg; - return 0; - -on_error: - git_str_dispose(&config_path); - git_config_free(cfg); - *out = NULL; - return error; -} - -static const char *path_unless_empty(git_str *buf) -{ - return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL; -} - -GIT_INLINE(int) config_path_system(git_str *out, bool use_env) -{ - if (use_env) { - git_str no_system_buf = GIT_STR_INIT; - int no_system = 0; - int error; - - error = git__getenv(&no_system_buf, "GIT_CONFIG_NOSYSTEM"); - - if (error && error != GIT_ENOTFOUND) - return error; - - error = git_config_parse_bool(&no_system, no_system_buf.ptr); - git_str_dispose(&no_system_buf); - - if (no_system) - return 0; - - error = git__getenv(out, "GIT_CONFIG_SYSTEM"); - - if (error == 0 || error != GIT_ENOTFOUND) - return 0; - } - - git_config__find_system(out); - return 0; -} - -GIT_INLINE(int) config_path_global(git_str *out, bool use_env) -{ - if (use_env) { - int error = git__getenv(out, "GIT_CONFIG_GLOBAL"); - - if (error == 0 || error != GIT_ENOTFOUND) - return 0; - } - - git_config__find_global(out); - return 0; -} - -int git_repository_config__weakptr(git_config **out, git_repository *repo) -{ - int error = 0; - - if (repo->_config == NULL) { - git_str system_buf = GIT_STR_INIT; - git_str global_buf = GIT_STR_INIT; - git_str xdg_buf = GIT_STR_INIT; - git_str programdata_buf = GIT_STR_INIT; - bool use_env = repo->use_env; - git_config *config = NULL; - - if (!(error = config_path_system(&system_buf, use_env)) && - !(error = config_path_global(&global_buf, use_env))) { - git_config__find_xdg(&xdg_buf); - git_config__find_programdata(&programdata_buf); - } - - if (!error) { - /* - * If there is no global file, open a backend - * for it anyway. - */ - if (git_str_len(&global_buf) == 0) - git_config__global_location(&global_buf); - - error = load_config( - &config, repo, - path_unless_empty(&global_buf), - path_unless_empty(&xdg_buf), - path_unless_empty(&system_buf), - path_unless_empty(&programdata_buf)); - } - - if (!error) { - GIT_REFCOUNT_OWN(config, repo); - - if (git_atomic_compare_and_swap(&repo->_config, NULL, config) != NULL) { - GIT_REFCOUNT_OWN(config, NULL); - git_config_free(config); - } - } - - git_str_dispose(&global_buf); - git_str_dispose(&xdg_buf); - git_str_dispose(&system_buf); - git_str_dispose(&programdata_buf); - } - - *out = repo->_config; - return error; -} - -int git_repository_config(git_config **out, git_repository *repo) -{ - if (git_repository_config__weakptr(out, repo) < 0) - return -1; - - GIT_REFCOUNT_INC(*out); - return 0; -} - -int git_repository_config_snapshot(git_config **out, git_repository *repo) -{ - int error; - git_config *weak; - - if ((error = git_repository_config__weakptr(&weak, repo)) < 0) - return error; - - return git_config_snapshot(out, weak); -} - -int git_repository_set_config(git_repository *repo, git_config *config) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(config); - - set_config(repo, config); - return 0; -} - -static int repository_odb_path(git_str *out, git_repository *repo) -{ - int error = GIT_ENOTFOUND; - - if (repo->use_env) - error = git__getenv(out, "GIT_OBJECT_DIRECTORY"); - - if (error == GIT_ENOTFOUND) - error = git_repository__item_path(out, repo, - GIT_REPOSITORY_ITEM_OBJECTS); - - return error; -} - -static int repository_odb_alternates( - git_odb *odb, - git_repository *repo) -{ - git_str alternates = GIT_STR_INIT; - char *sep, *alt; - int error; - - if (!repo->use_env) - return 0; - - error = git__getenv(&alternates, "GIT_ALTERNATE_OBJECT_DIRECTORIES"); - - if (error != 0) - return (error == GIT_ENOTFOUND) ? 0 : error; - - alt = alternates.ptr; - - while (*alt) { - sep = strchr(alt, GIT_PATH_LIST_SEPARATOR); - - if (sep) - *sep = '\0'; - - error = git_odb_add_disk_alternate(odb, alt); - - if (sep) - alt = sep + 1; - else - break; - } - - git_str_dispose(&alternates); - return 0; -} - -int git_repository_odb__weakptr(git_odb **out, git_repository *repo) -{ - int error = 0; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(out); - - *out = git_atomic_load(repo->_odb); - if (*out == NULL) { - git_str odb_path = GIT_STR_INIT; - git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; - git_odb *odb; - - odb_opts.oid_type = repo->oid_type; - - if ((error = repository_odb_path(&odb_path, repo)) < 0 || - (error = git_odb__new(&odb, &odb_opts)) < 0 || - (error = repository_odb_alternates(odb, repo)) < 0) - return error; - - GIT_REFCOUNT_OWN(odb, repo); - - if ((error = git_odb__set_caps(odb, GIT_ODB_CAP_FROM_OWNER)) < 0 || - (error = git_odb__add_default_backends(odb, odb_path.ptr, 0, 0)) < 0) { - git_odb_free(odb); - return error; - } - - if (git_atomic_compare_and_swap(&repo->_odb, NULL, odb) != NULL) { - GIT_REFCOUNT_OWN(odb, NULL); - git_odb_free(odb); - } - - git_str_dispose(&odb_path); - *out = git_atomic_load(repo->_odb); - } - - return error; -} - -int git_repository_odb(git_odb **out, git_repository *repo) -{ - if (git_repository_odb__weakptr(out, repo) < 0) - return -1; - - GIT_REFCOUNT_INC(*out); - return 0; -} - -int git_repository_set_odb(git_repository *repo, git_odb *odb) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(odb); - - set_odb(repo, odb); - return 0; -} - -int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo) -{ - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - if (repo->_refdb == NULL) { - git_refdb *refdb; - - error = git_refdb_open(&refdb, repo); - if (!error) { - GIT_REFCOUNT_OWN(refdb, repo); - - if (git_atomic_compare_and_swap(&repo->_refdb, NULL, refdb) != NULL) { - GIT_REFCOUNT_OWN(refdb, NULL); - git_refdb_free(refdb); - } - } - } - - *out = repo->_refdb; - return error; -} - -int git_repository_refdb(git_refdb **out, git_repository *repo) -{ - if (git_repository_refdb__weakptr(out, repo) < 0) - return -1; - - GIT_REFCOUNT_INC(*out); - return 0; -} - -int git_repository_set_refdb(git_repository *repo, git_refdb *refdb) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(refdb); - - set_refdb(repo, refdb); - return 0; -} - -static int repository_index_path(git_str *out, git_repository *repo) -{ - int error = GIT_ENOTFOUND; - - if (repo->use_env) - error = git__getenv(out, "GIT_INDEX_FILE"); - - if (error == GIT_ENOTFOUND) - error = git_repository__item_path(out, repo, - GIT_REPOSITORY_ITEM_INDEX); - - return error; -} - -int git_repository_index__weakptr(git_index **out, git_repository *repo) -{ - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - if (repo->_index == NULL) { - git_str index_path = GIT_STR_INIT; - git_index *index; - - if ((error = repository_index_path(&index_path, repo)) < 0) - return error; - - error = git_index__open(&index, index_path.ptr, repo->oid_type); - - if (!error) { - GIT_REFCOUNT_OWN(index, repo); - - if (git_atomic_compare_and_swap(&repo->_index, NULL, index) != NULL) { - GIT_REFCOUNT_OWN(index, NULL); - git_index_free(index); - } - - error = git_index_set_caps(repo->_index, - GIT_INDEX_CAPABILITY_FROM_OWNER); - } - - git_str_dispose(&index_path); - } - - *out = repo->_index; - return error; -} - -int git_repository_index(git_index **out, git_repository *repo) -{ - if (git_repository_index__weakptr(out, repo) < 0) - return -1; - - GIT_REFCOUNT_INC(*out); - return 0; -} - -int git_repository_set_index(git_repository *repo, git_index *index) -{ - GIT_ASSERT_ARG(repo); - set_index(repo, index); - return 0; -} - -int git_repository_grafts__weakptr(git_grafts **out, git_repository *repo) -{ - GIT_ASSERT_ARG(out && repo); - GIT_ASSERT(repo->grafts); - *out = repo->grafts; - return 0; -} - -int git_repository_shallow_grafts__weakptr(git_grafts **out, git_repository *repo) -{ - GIT_ASSERT_ARG(out && repo); - GIT_ASSERT(repo->shallow_grafts); - *out = repo->shallow_grafts; - return 0; -} - -int git_repository_set_namespace(git_repository *repo, const char *namespace) -{ - git__free(repo->namespace); - - if (namespace == NULL) { - repo->namespace = NULL; - return 0; - } - - return (repo->namespace = git__strdup(namespace)) ? 0 : -1; -} - -const char *git_repository_get_namespace(git_repository *repo) -{ - return repo->namespace; -} - -#ifdef GIT_WIN32 -static int reserved_names_add8dot3(git_repository *repo, const char *path) -{ - char *name = git_win32_path_8dot3_name(path); - const char *def = GIT_DIR_SHORTNAME; - const char *def_dot_git = DOT_GIT; - size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME); - size_t def_dot_git_len = CONST_STRLEN(DOT_GIT); - git_str *buf; - - if (!name) - return 0; - - name_len = strlen(name); - - if ((name_len == def_len && memcmp(name, def, def_len) == 0) || - (name_len == def_dot_git_len && memcmp(name, def_dot_git, def_dot_git_len) == 0)) { - git__free(name); - return 0; - } - - if ((buf = git_array_alloc(repo->reserved_names)) == NULL) - return -1; - - git_str_attach(buf, name, name_len); - return true; -} - -bool git_repository__reserved_names( - git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs) -{ - GIT_UNUSED(include_ntfs); - - if (repo->reserved_names.size == 0) { - git_str *buf; - size_t i; - - /* Add the static defaults */ - for (i = 0; i < git_repository__reserved_names_win32_len; i++) { - if ((buf = git_array_alloc(repo->reserved_names)) == NULL) - goto on_error; - - buf->ptr = git_repository__reserved_names_win32[i].ptr; - buf->size = git_repository__reserved_names_win32[i].size; - } - - /* Try to add any repo-specific reserved names - the gitlink file - * within a submodule or the repository (if the repository directory - * is beneath the workdir). These are typically `.git`, but should - * be protected in case they are not. Note, repo and workdir paths - * are always prettified to end in `/`, so a prefixcmp is safe. - */ - if (!repo->is_bare) { - int (*prefixcmp)(const char *, const char *); - int error, ignorecase; - - error = git_repository__configmap_lookup( - &ignorecase, repo, GIT_CONFIGMAP_IGNORECASE); - prefixcmp = (error || ignorecase) ? git__prefixcmp_icase : - git__prefixcmp; - - if (repo->gitlink && - reserved_names_add8dot3(repo, repo->gitlink) < 0) - goto on_error; - - if (repo->gitdir && - prefixcmp(repo->gitdir, repo->workdir) == 0 && - reserved_names_add8dot3(repo, repo->gitdir) < 0) - goto on_error; - } - } - - *out = repo->reserved_names.ptr; - *outlen = repo->reserved_names.size; - - return true; - - /* Always give good defaults, even on OOM */ -on_error: - *out = git_repository__reserved_names_win32; - *outlen = git_repository__reserved_names_win32_len; - - return false; -} -#else -bool git_repository__reserved_names( - git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs) -{ - GIT_UNUSED(repo); - - if (include_ntfs) { - *out = git_repository__reserved_names_win32; - *outlen = git_repository__reserved_names_win32_len; - } else { - *out = git_repository__reserved_names_posix; - *outlen = git_repository__reserved_names_posix_len; - } - - return true; -} -#endif - -static int check_repositoryformatversion(int *version, git_config *config) -{ - int error; - - error = git_config_get_int32(version, config, "core.repositoryformatversion"); - - /* git ignores this if the config variable isn't there */ - if (error == GIT_ENOTFOUND) - return 0; - - if (error < 0) - return -1; - - if (*version < 0) { - git_error_set(GIT_ERROR_REPOSITORY, - "invalid repository version %d", *version); - } - - if (GIT_REPO_VERSION_MAX < *version) { - git_error_set(GIT_ERROR_REPOSITORY, - "unsupported repository version %d; only versions up to %d are supported", - *version, GIT_REPO_VERSION_MAX); - return -1; - } - - return 0; -} - -static const char *builtin_extensions[] = { - "noop", - "objectformat", - "worktreeconfig", - "preciousobjects", - "relativeworktrees" -}; - -static git_vector user_extensions = { 0, git__strcmp_cb }; - -static int check_valid_extension(const git_config_entry *entry, void *payload) -{ - git_str cfg = GIT_STR_INIT; - bool reject; - const char *extension; - size_t i; - int error = 0; - - GIT_UNUSED(payload); - - git_vector_foreach (&user_extensions, i, extension) { - git_str_clear(&cfg); - - /* - * Users can specify that they don't want to support an - * extension with a '!' prefix. - */ - if ((reject = (extension[0] == '!')) == true) - extension = &extension[1]; - - if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0) - goto done; - - if (strcmp(entry->name, cfg.ptr) == 0) { - if (reject) - goto fail; - - goto done; - } - } - - for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) { - git_str_clear(&cfg); - extension = builtin_extensions[i]; - - if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0) - goto done; - - if (strcmp(entry->name, cfg.ptr) == 0) - goto done; - } - -fail: - git_error_set(GIT_ERROR_REPOSITORY, "unsupported extension name %s", entry->name); - error = -1; - -done: - git_str_dispose(&cfg); - return error; -} - -static int check_extensions(git_config *config, int version) -{ - if (version < 1) - return 0; - - return git_config_foreach_match(config, "^extensions\\.", check_valid_extension, NULL); -} - -static int load_objectformat(git_repository *repo, git_config *config) -{ - git_config_entry *entry = NULL; - int error; - - if ((error = git_config_get_entry(&entry, config, "extensions.objectformat")) < 0) { - if (error == GIT_ENOTFOUND) { - repo->oid_type = GIT_OID_DEFAULT; - git_error_clear(); - error = 0; - } - - goto done; - } - - if ((repo->oid_type = git_oid_type_fromstr(entry->value)) == 0) { - git_error_set(GIT_ERROR_REPOSITORY, - "unknown object format '%s'", entry->value); - error = GIT_EINVALID; - } - -done: - git_config_entry_free(entry); - return error; -} - -int git_repository__set_objectformat( - git_repository *repo, - git_oid_t oid_type) -{ - git_config *cfg; - - /* - * Older clients do not necessarily understand the - * `objectformat` extension, even when it's set to an - * object format that they understand (SHA1). Do not set - * the objectformat extension unless we're not using the - * default object format. - */ - if (oid_type == GIT_OID_DEFAULT) - return 0; - - if (!git_repository_is_empty(repo) && repo->oid_type != oid_type) { - git_error_set(GIT_ERROR_REPOSITORY, - "cannot change object id type of existing repository"); - return -1; - } - - if (git_repository_config__weakptr(&cfg, repo) < 0) - return -1; - - if (git_config_set_int32(cfg, - "core.repositoryformatversion", 1) < 0 || - git_config_set_string(cfg, "extensions.objectformat", - git_oid_type_name(oid_type)) < 0) - return -1; - - /* - * During repo init, we may create some backends with the - * default oid type. Clear them so that we create them with - * the proper oid type. - */ - if (repo->oid_type != oid_type) { - set_index(repo, NULL); - set_odb(repo, NULL); - set_refdb(repo, NULL); - - repo->oid_type = oid_type; - } - - return 0; -} - -int git_repository__extensions(char ***out, size_t *out_len) -{ - git_vector extensions; - const char *builtin, *user; - char *extension; - size_t i, j; - - if (git_vector_init(&extensions, 8, git__strcmp_cb) < 0) - return -1; - - for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) { - bool match = false; - - builtin = builtin_extensions[i]; - - git_vector_foreach (&user_extensions, j, user) { - if (user[0] == '!' && strcmp(builtin, &user[1]) == 0) { - match = true; - break; - } - } - - if (match) - continue; - - if ((extension = git__strdup(builtin)) == NULL || - git_vector_insert(&extensions, extension) < 0) - return -1; - } - - git_vector_foreach (&user_extensions, i, user) { - if (user[0] == '!') - continue; - - if ((extension = git__strdup(user)) == NULL || - git_vector_insert(&extensions, extension) < 0) - return -1; - } - - git_vector_sort(&extensions); - - *out = (char **)git_vector_detach(out_len, NULL, &extensions); - return 0; -} - -static int dup_ext_err(void **old, void *extension) -{ - GIT_UNUSED(old); - GIT_UNUSED(extension); - return GIT_EEXISTS; -} - -int git_repository__set_extensions(const char **extensions, size_t len) -{ - char *extension; - size_t i, j; - int error; - - git_repository__free_extensions(); - - for (i = 0; i < len; i++) { - bool is_builtin = false; - - for (j = 0; j < ARRAY_SIZE(builtin_extensions); j++) { - if (strcmp(builtin_extensions[j], extensions[i]) == 0) { - is_builtin = true; - break; - } - } - - if (is_builtin) - continue; - - if ((extension = git__strdup(extensions[i])) == NULL) - return -1; - - if ((error = git_vector_insert_sorted(&user_extensions, extension, dup_ext_err)) < 0) { - git__free(extension); - - if (error != GIT_EEXISTS) - return -1; - } - } - - return 0; -} - -void git_repository__free_extensions(void) -{ - git_vector_dispose_deep(&user_extensions); -} - -int git_repository_create_head(const char *git_dir, const char *ref_name) -{ - git_str ref_path = GIT_STR_INIT; - git_filebuf ref = GIT_FILEBUF_INIT; - const char *fmt; - int error; - - if ((error = git_str_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 || - (error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0) - goto out; - - if (git__prefixcmp(ref_name, GIT_REFS_DIR) == 0) - fmt = "ref: %s\n"; - else - fmt = "ref: " GIT_REFS_HEADS_DIR "%s\n"; - - if ((error = git_filebuf_printf(&ref, fmt, ref_name)) < 0 || - (error = git_filebuf_commit(&ref)) < 0) - goto out; - -out: - git_str_dispose(&ref_path); - git_filebuf_cleanup(&ref); - return error; -} - -static bool is_chmod_supported(const char *file_path) -{ - struct stat st1, st2; - - if (p_stat(file_path, &st1) < 0) - return false; - - if (p_chmod(file_path, st1.st_mode ^ S_IXUSR) < 0) - return false; - - if (p_stat(file_path, &st2) < 0) - return false; - - return (st1.st_mode != st2.st_mode); -} - -static bool is_filesystem_case_insensitive(const char *gitdir_path) -{ - git_str path = GIT_STR_INIT; - int is_insensitive = -1; - - if (!git_str_joinpath(&path, gitdir_path, "CoNfIg")) - is_insensitive = git_fs_path_exists(git_str_cstr(&path)); - - git_str_dispose(&path); - return is_insensitive; -} - -/* - * Return a configuration object with only the global and system - * configurations; no repository-level configuration. - */ -static int load_global_config(git_config **config, bool use_env) -{ - git_str global_buf = GIT_STR_INIT; - git_str xdg_buf = GIT_STR_INIT; - git_str system_buf = GIT_STR_INIT; - git_str programdata_buf = GIT_STR_INIT; - int error; - - if (!(error = config_path_system(&system_buf, use_env)) && - !(error = config_path_global(&global_buf, use_env))) { - git_config__find_xdg(&xdg_buf); - git_config__find_programdata(&programdata_buf); - - error = load_config(config, NULL, - path_unless_empty(&global_buf), - path_unless_empty(&xdg_buf), - path_unless_empty(&system_buf), - path_unless_empty(&programdata_buf)); - } - - git_str_dispose(&global_buf); - git_str_dispose(&xdg_buf); - git_str_dispose(&system_buf); - git_str_dispose(&programdata_buf); - - return error; -} - -static bool are_symlinks_supported(const char *wd_path, bool use_env) -{ - git_config *config = NULL; - int symlinks = 0; - - /* - * To emulate Git for Windows, symlinks on Windows must be explicitly - * opted-in. We examine the system configuration for a core.symlinks - * set to true. If found, we then examine the filesystem to see if - * symlinks are _actually_ supported by the current user. If that is - * _not_ set, then we do not test or enable symlink support. - */ -#ifdef GIT_WIN32 - if (load_global_config(&config, use_env) < 0 || - git_config_get_bool(&symlinks, config, "core.symlinks") < 0 || - !symlinks) - goto done; -#else - GIT_UNUSED(use_env); -#endif - - if (!(symlinks = git_fs_path_supports_symlinks(wd_path))) - goto done; - -done: - git_config_free(config); - return symlinks != 0; -} - -static int create_empty_file(const char *path, mode_t mode) -{ - int fd; - - if ((fd = p_creat(path, mode)) < 0) { - git_error_set(GIT_ERROR_OS, "error while creating '%s'", path); - return -1; - } - - if (p_close(fd) < 0) { - git_error_set(GIT_ERROR_OS, "error while closing '%s'", path); - return -1; - } - - return 0; -} - -static int repo_local_config( - git_config **out, - git_str *config_dir, - git_repository *repo, - const char *repo_dir) -{ - int error = 0; - git_config *parent; - const char *cfg_path; - - if (git_str_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0) - return -1; - cfg_path = git_str_cstr(config_dir); - - /* make LOCAL config if missing */ - if (!git_fs_path_isfile(cfg_path) && - (error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0) - return error; - - /* if no repo, just open that file directly */ - if (!repo) - return git_config_open_ondisk(out, cfg_path); - - /* otherwise, open parent config and get that level */ - if ((error = git_repository_config__weakptr(&parent, repo)) < 0) - return error; - - if (git_config_open_level(out, parent, GIT_CONFIG_LEVEL_LOCAL) < 0) { - git_error_clear(); - - if (!(error = git_config_add_file_ondisk( - parent, cfg_path, GIT_CONFIG_LEVEL_LOCAL, repo, false))) - error = git_config_open_level(out, parent, GIT_CONFIG_LEVEL_LOCAL); - } - - git_config_free(parent); - - return error; -} - -static int repo_init_fs_configs( - git_config *cfg, - const char *cfg_path, - const char *repo_dir, - const char *work_dir, - bool update_ignorecase, - bool use_env) -{ - int error = 0; - - if (!work_dir) - work_dir = repo_dir; - - if ((error = git_config_set_bool( - cfg, "core.filemode", is_chmod_supported(cfg_path))) < 0) - return error; - - if (!are_symlinks_supported(work_dir, use_env)) { - if ((error = git_config_set_bool(cfg, "core.symlinks", false)) < 0) - return error; - } else if (git_config_delete_entry(cfg, "core.symlinks") < 0) - git_error_clear(); - - if (update_ignorecase) { - if (is_filesystem_case_insensitive(repo_dir)) { - if ((error = git_config_set_bool(cfg, "core.ignorecase", true)) < 0) - return error; - } else if (git_config_delete_entry(cfg, "core.ignorecase") < 0) - git_error_clear(); - } - -#ifdef GIT_USE_ICONV - if ((error = git_config_set_bool( - cfg, "core.precomposeunicode", - git_fs_path_does_decompose_unicode(work_dir))) < 0) - return error; - /* on non-iconv platforms, don't even set core.precomposeunicode */ -#endif - - return 0; -} - -static int repo_init_config( - const char *repo_dir, - const char *work_dir, - uint32_t flags, - uint32_t mode, - git_oid_t oid_type) -{ - int error = 0; - git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT; - git_config *config = NULL; - bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0); - bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0); - bool use_env = ((flags & GIT_REPOSITORY_OPEN_FROM_ENV) != 0); - int version = GIT_REPO_VERSION_DEFAULT; - - if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0) - goto cleanup; - - if (is_reinit && - (error = check_repositoryformatversion(&version, config)) < 0) - goto cleanup; - - if ((error = check_extensions(config, version)) < 0) - goto cleanup; - -#define SET_REPO_CONFIG(TYPE, NAME, VAL) do { \ - if ((error = git_config_set_##TYPE(config, NAME, VAL)) < 0) \ - goto cleanup; } while (0) - - SET_REPO_CONFIG(bool, "core.bare", is_bare); - SET_REPO_CONFIG(int32, "core.repositoryformatversion", version); - - if ((error = repo_init_fs_configs( - config, cfg_path.ptr, repo_dir, work_dir, - !is_reinit, use_env)) < 0) - goto cleanup; - - if (!is_bare) { - SET_REPO_CONFIG(bool, "core.logallrefupdates", true); - - if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) { - if ((error = git_str_sets(&worktree_path, work_dir)) < 0) - goto cleanup; - - if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK)) - if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0) - goto cleanup; - - SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr); - } else if (is_reinit) { - if (git_config_delete_entry(config, "core.worktree") < 0) - git_error_clear(); - } - } - - if (mode == GIT_REPOSITORY_INIT_SHARED_GROUP) { - SET_REPO_CONFIG(int32, "core.sharedrepository", 1); - SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true); - } - else if (mode == GIT_REPOSITORY_INIT_SHARED_ALL) { - SET_REPO_CONFIG(int32, "core.sharedrepository", 2); - SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true); - } - - if (oid_type != GIT_OID_DEFAULT) { - SET_REPO_CONFIG(int32, "core.repositoryformatversion", 1); - SET_REPO_CONFIG(string, "extensions.objectformat", git_oid_type_name(oid_type)); - } - -cleanup: - git_str_dispose(&cfg_path); - git_str_dispose(&worktree_path); - git_config_free(config); - - return error; -} - -static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p) -{ - git_repository *smrepo = NULL; - GIT_UNUSED(n); GIT_UNUSED(p); - - if (git_submodule_open(&smrepo, sm) < 0 || - git_repository_reinit_filesystem(smrepo, true) < 0) - git_error_clear(); - git_repository_free(smrepo); - - return 0; -} - -int git_repository_reinit_filesystem(git_repository *repo, int recurse) -{ - int error = 0; - git_str path = GIT_STR_INIT; - git_config *config = NULL; - const char *repo_dir = git_repository_path(repo); - - if (!(error = repo_local_config(&config, &path, repo, repo_dir))) - error = repo_init_fs_configs(config, path.ptr, repo_dir, - git_repository_workdir(repo), true, repo->use_env); - - git_config_free(config); - git_str_dispose(&path); - - git_repository__configmap_lookup_cache_clear(repo); - - if (!repo->is_bare && recurse) - (void)git_submodule_foreach(repo, repo_reinit_submodule_fs, NULL); - - return error; -} - -static int repo_write_template( - const char *git_dir, - bool allow_overwrite, - const char *file, - mode_t mode, - bool hidden, - const char *content) -{ - git_str path = GIT_STR_INIT; - int fd, error = 0, flags; - - if (git_str_joinpath(&path, git_dir, file) < 0) - return -1; - - if (allow_overwrite) - flags = O_WRONLY | O_CREAT | O_TRUNC; - else - flags = O_WRONLY | O_CREAT | O_EXCL; - - fd = p_open(git_str_cstr(&path), flags, mode); - - if (fd >= 0) { - error = p_write(fd, content, strlen(content)); - - p_close(fd); - } - else if (errno != EEXIST) - error = fd; - -#ifdef GIT_WIN32 - if (!error && hidden) { - if (git_win32__set_hidden(path.ptr, true) < 0) - error = -1; - } -#else - GIT_UNUSED(hidden); -#endif - - git_str_dispose(&path); - - if (error) - git_error_set(GIT_ERROR_OS, - "failed to initialize repository with template '%s'", file); - - return error; -} - -static int repo_write_gitlink( - const char *in_dir, const char *to_repo, bool use_relative_path) -{ - int error; - git_str buf = GIT_STR_INIT; - git_str path_to_repo = GIT_STR_INIT; - struct stat st; - - git_fs_path_dirname_r(&buf, to_repo); - git_fs_path_to_dir(&buf); - if (git_str_oom(&buf)) - return -1; - - /* don't write gitlink to natural workdir */ - if (git__suffixcmp(to_repo, "/" DOT_GIT "/") == 0 && - strcmp(in_dir, buf.ptr) == 0) - { - error = GIT_PASSTHROUGH; - goto cleanup; - } - - if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0) - goto cleanup; - - if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) { - git_error_set(GIT_ERROR_REPOSITORY, - "cannot overwrite gitlink file into path '%s'", in_dir); - error = GIT_EEXISTS; - goto cleanup; - } - - git_str_clear(&buf); - - error = git_str_sets(&path_to_repo, to_repo); - - if (!error && use_relative_path) - error = git_fs_path_make_relative(&path_to_repo, in_dir); - - if (!error) - error = git_str_printf(&buf, "%s %s\n", GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr); - - if (!error) - error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr); - -cleanup: - git_str_dispose(&buf); - git_str_dispose(&path_to_repo); - return error; -} - -static mode_t pick_dir_mode(git_repository_init_options *opts) -{ - if (opts->mode == GIT_REPOSITORY_INIT_SHARED_UMASK) - return 0777; - if (opts->mode == GIT_REPOSITORY_INIT_SHARED_GROUP) - return (0775 | S_ISGID); - if (opts->mode == GIT_REPOSITORY_INIT_SHARED_ALL) - return (0777 | S_ISGID); - return opts->mode; -} - -#include "repo_template.h" - -static int repo_init_structure( - const char *repo_dir, - const char *work_dir, - git_repository_init_options *opts) -{ - int error = 0; - repo_template_item *tpl; - bool external_tpl = - opts->template_path != NULL || - (opts->flags & GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE) != 0; - mode_t dmode = pick_dir_mode(opts); - bool chmod = opts->mode != GIT_REPOSITORY_INIT_SHARED_UMASK; - - /* Hide the ".git" directory */ -#ifdef GIT_WIN32 - if ((opts->flags & GIT_REPOSITORY_INIT__HAS_DOTGIT) != 0) { - if (git_win32__set_hidden(repo_dir, true) < 0) { - git_error_set(GIT_ERROR_OS, - "failed to mark Git repository folder as hidden"); - return -1; - } - } -#endif - - /* Create the .git gitlink if appropriate */ - if ((opts->flags & GIT_REPOSITORY_INIT_BARE) == 0 && - (opts->flags & GIT_REPOSITORY_INIT__NATURAL_WD) == 0) - { - if (repo_write_gitlink(work_dir, repo_dir, opts->flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK) < 0) - return -1; - } - - /* Copy external template if requested */ - if (external_tpl) { - git_config *cfg = NULL; - const char *tdir = NULL; - bool default_template = false; - git_str template_buf = GIT_STR_INIT; - - if (opts->template_path) - tdir = opts->template_path; - else if ((error = git_config_open_default(&cfg)) >= 0) { - if (!git_config__get_path(&template_buf, cfg, "init.templatedir")) - tdir = template_buf.ptr; - git_error_clear(); - } - - if (!tdir) { - if (!(error = git_sysdir_find_template_dir(&template_buf))) - tdir = template_buf.ptr; - default_template = true; - } - - /* - * If tdir was the empty string, treat it like tdir was a path to an - * empty directory (so, don't do any copying). This is the behavior - * that git(1) exhibits, although it doesn't seem to be officially - * documented. - */ - if (tdir && git__strcmp(tdir, "") != 0) { - uint32_t cpflags = GIT_CPDIR_COPY_SYMLINKS | - GIT_CPDIR_SIMPLE_TO_MODE | - GIT_CPDIR_COPY_DOTFILES; - if (opts->mode != GIT_REPOSITORY_INIT_SHARED_UMASK) - cpflags |= GIT_CPDIR_CHMOD_DIRS; - error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode); - } - - git_str_dispose(&template_buf); - git_config_free(cfg); - - /* If tdir does not exist, then do not error out. This matches the - * behaviour of git(1), which just prints a warning and continues. - * TODO: issue warning when warning API is available. - * `git` prints to stderr: 'warning: templates not found in /path/to/tdir' - */ - if (error < 0) { - if (!default_template && error != GIT_ENOTFOUND) - return error; - - /* if template was default, ignore error and use internal */ - git_error_clear(); - external_tpl = false; - error = 0; - } - } - - /* Copy internal template - * - always ensure existence of dirs - * - only create files if no external template was specified - */ - for (tpl = repo_template; !error && tpl->path; ++tpl) { - if (!tpl->content) { - uint32_t mkdir_flags = GIT_MKDIR_PATH; - if (chmod) - mkdir_flags |= GIT_MKDIR_CHMOD; - - error = git_futils_mkdir_relative( - tpl->path, repo_dir, dmode, mkdir_flags, NULL); - } - else if (!external_tpl) { - const char *content = tpl->content; - - if (opts->description && strcmp(tpl->path, GIT_DESC_FILE) == 0) - content = opts->description; - - error = repo_write_template( - repo_dir, false, tpl->path, tpl->mode, false, content); - } - } - - return error; -} - -static int mkdir_parent(git_str *buf, uint32_t mode, bool skip2) -{ - /* When making parent directories during repository initialization - * don't try to set gid or grant world write access - */ - return git_futils_mkdir( - buf->ptr, mode & ~(S_ISGID | 0002), - GIT_MKDIR_PATH | GIT_MKDIR_VERIFY_DIR | - (skip2 ? GIT_MKDIR_SKIP_LAST2 : GIT_MKDIR_SKIP_LAST)); -} - -static int repo_init_directories( - git_str *repo_path, - git_str *wd_path, - const char *given_repo, - git_repository_init_options *opts) -{ - int error = 0; - bool is_bare, add_dotgit, has_dotgit, natural_wd; - mode_t dirmode; - - /* There are three possible rules for what we are allowed to create: - * - MKPATH means anything we need - * - MKDIR means just the .git directory and its parent and the workdir - * - Neither means only the .git directory can be created - * - * There are 5 "segments" of path that we might need to deal with: - * 1. The .git directory - * 2. The parent of the .git directory - * 3. Everything above the parent of the .git directory - * 4. The working directory (often the same as #2) - * 5. Everything above the working directory (often the same as #3) - * - * For all directories created, we start with the init_mode value for - * permissions and then strip off bits in some cases: - * - * For MKPATH, we create #3 (and #5) paths without S_ISGID or S_IWOTH - * For MKPATH and MKDIR, we create #2 (and #4) without S_ISGID - * For all rules, we create #1 using the untouched init_mode - */ - - /* set up repo path */ - - is_bare = ((opts->flags & GIT_REPOSITORY_INIT_BARE) != 0); - - add_dotgit = - (opts->flags & GIT_REPOSITORY_INIT_NO_DOTGIT_DIR) == 0 && - !is_bare && - git__suffixcmp(given_repo, "/" DOT_GIT) != 0 && - git__suffixcmp(given_repo, "/" GIT_DIR) != 0; - - if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0) - return -1; - - git_fs_path_mkposix(repo_path->ptr); - - has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0); - if (has_dotgit) - opts->flags |= GIT_REPOSITORY_INIT__HAS_DOTGIT; - - /* set up workdir path */ - - if (!is_bare) { - if (opts->workdir_path) { - if (git_fs_path_join_unrooted( - wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0) - return -1; - } else if (has_dotgit) { - if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0) - return -1; - } else { - git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory" - " for non-bare repository that isn't a '.git' directory"); - return -1; - } - - if (git_fs_path_to_dir(wd_path) < 0) - return -1; - } else { - git_str_clear(wd_path); - } - - natural_wd = - has_dotgit && - wd_path->size > 0 && - wd_path->size + strlen(GIT_DIR) == repo_path->size && - memcmp(repo_path->ptr, wd_path->ptr, wd_path->size) == 0; - if (natural_wd) - opts->flags |= GIT_REPOSITORY_INIT__NATURAL_WD; - - /* create directories as needed / requested */ - - dirmode = pick_dir_mode(opts); - - if ((opts->flags & GIT_REPOSITORY_INIT_MKPATH) != 0) { - /* create path #5 */ - if (wd_path->size > 0 && - (error = mkdir_parent(wd_path, dirmode, false)) < 0) - return error; - - /* create path #3 (if not the same as #5) */ - if (!natural_wd && - (error = mkdir_parent(repo_path, dirmode, has_dotgit)) < 0) - return error; - } - - if ((opts->flags & GIT_REPOSITORY_INIT_MKDIR) != 0 || - (opts->flags & GIT_REPOSITORY_INIT_MKPATH) != 0) - { - /* create path #4 */ - if (wd_path->size > 0 && - (error = git_futils_mkdir( - wd_path->ptr, dirmode & ~S_ISGID, - GIT_MKDIR_VERIFY_DIR)) < 0) - return error; - - /* create path #2 (if not the same as #4) */ - if (!natural_wd && - (error = git_futils_mkdir( - repo_path->ptr, dirmode & ~S_ISGID, - GIT_MKDIR_VERIFY_DIR | GIT_MKDIR_SKIP_LAST)) < 0) - return error; - } - - if ((opts->flags & GIT_REPOSITORY_INIT_MKDIR) != 0 || - (opts->flags & GIT_REPOSITORY_INIT_MKPATH) != 0 || - has_dotgit) - { - /* create path #1 */ - error = git_futils_mkdir(repo_path->ptr, dirmode, - GIT_MKDIR_VERIFY_DIR | ((dirmode & S_ISGID) ? GIT_MKDIR_CHMOD : 0)); - } - - /* prettify both directories now that they are created */ - - if (!error) { - error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL); - - if (!error && wd_path->size > 0) - error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL); - } - - return error; -} - -static int repo_init_head(const char *repo_dir, const char *given) -{ - git_config *cfg = NULL; - git_str head_path = GIT_STR_INIT, cfg_branch = GIT_STR_INIT; - const char *initial_head = NULL; - int error; - - if ((error = git_str_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0) - goto out; - - /* - * A template may have set a HEAD; use that unless it's been - * overridden by the caller's given initial head setting. - */ - if (git_fs_path_exists(head_path.ptr) && !given) - goto out; - - if (given) { - initial_head = given; - } else if ((error = git_config_open_default(&cfg)) >= 0 && - (error = git_config__get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 && - *cfg_branch.ptr) { - initial_head = cfg_branch.ptr; - } - - if (!initial_head) - initial_head = GIT_BRANCH_DEFAULT; - - error = git_repository_create_head(repo_dir, initial_head); - -out: - git_config_free(cfg); - git_str_dispose(&head_path); - git_str_dispose(&cfg_branch); - - return error; -} - -static int repo_init_create_origin(git_repository *repo, const char *url) -{ - int error; - git_remote *remote; - - if (!(error = git_remote_create(&remote, repo, GIT_REMOTE_ORIGIN, url))) { - git_remote_free(remote); - } - - return error; -} - -int git_repository_init( - git_repository **repo_out, const char *path, unsigned is_bare) -{ - git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; - - opts.flags = GIT_REPOSITORY_INIT_MKPATH; /* don't love this default */ - if (is_bare) - opts.flags |= GIT_REPOSITORY_INIT_BARE; - - return git_repository_init_ext(repo_out, path, &opts); -} - -int git_repository_init_ext( - git_repository **out, - const char *given_repo, - git_repository_init_options *opts) -{ - git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT, - common_path = GIT_STR_INIT; - const char *wd; - bool is_valid; - git_oid_t oid_type = GIT_OID_DEFAULT; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(given_repo); - GIT_ASSERT_ARG(opts); - - GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options"); - -#ifdef GIT_EXPERIMENTAL_SHA256 - if (opts->oid_type) - oid_type = opts->oid_type; -#endif - - if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0) - goto out; - - wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_str_cstr(&wd_path); - - if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path, opts->flags)) < 0) - goto out; - - if (is_valid) { - if ((opts->flags & GIT_REPOSITORY_INIT_NO_REINIT) != 0) { - git_error_set(GIT_ERROR_REPOSITORY, - "attempt to reinitialize '%s'", given_repo); - error = GIT_EEXISTS; - goto out; - } - - opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT; - - if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0) - goto out; - - /* TODO: reinitialize the templates */ - } else { - if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 || - (error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0 || - (error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0) - goto out; - } - - if ((error = git_repository_open(out, repo_path.ptr)) < 0) - goto out; - - if (opts->origin_url && - (error = repo_init_create_origin(*out, opts->origin_url)) < 0) - goto out; - -out: - git_str_dispose(&common_path); - git_str_dispose(&repo_path); - git_str_dispose(&wd_path); - - return error; -} - -int git_repository_head_detached(git_repository *repo) -{ - git_reference *ref; - git_odb *odb = NULL; - int exists; - - if (git_repository_odb__weakptr(&odb, repo) < 0) - return -1; - - if (git_reference_lookup(&ref, repo, GIT_HEAD_FILE) < 0) - return -1; - - if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) { - git_reference_free(ref); - return 0; - } - - exists = git_odb_exists(odb, git_reference_target(ref)); - - git_reference_free(ref); - return exists; -} - -int git_repository_head_detached_for_worktree(git_repository *repo, const char *name) -{ - git_reference *ref = NULL; - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - if ((error = git_repository_head_for_worktree(&ref, repo, name)) < 0) - goto out; - - error = (git_reference_type(ref) != GIT_REFERENCE_SYMBOLIC); -out: - git_reference_free(ref); - - return error; -} - -int git_repository_head(git_reference **head_out, git_repository *repo) -{ - git_reference *head; - int error; - - GIT_ASSERT_ARG(head_out); - - if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0) - return error; - - if (git_reference_type(head) == GIT_REFERENCE_DIRECT) { - *head_out = head; - return 0; - } - - error = git_reference_lookup_resolved(head_out, repo, git_reference_symbolic_target(head), -1); - git_reference_free(head); - - return error == GIT_ENOTFOUND ? GIT_EUNBORNBRANCH : error; -} - -int git_repository_head_for_worktree(git_reference **out, git_repository *repo, const char *name) -{ - git_repository *worktree_repo = NULL; - git_worktree *worktree = NULL; - git_reference *head = NULL; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - *out = NULL; - - if ((error = git_worktree_lookup(&worktree, repo, name)) < 0 || - (error = git_repository_open_from_worktree(&worktree_repo, worktree)) < 0 || - (error = git_reference_lookup(&head, worktree_repo, GIT_HEAD_FILE)) < 0) - goto out; - - if (git_reference_type(head) != GIT_REFERENCE_DIRECT) { - if ((error = git_reference_lookup_resolved(out, worktree_repo, git_reference_symbolic_target(head), -1)) < 0) - goto out; - } else { - *out = head; - head = NULL; - } - -out: - git_reference_free(head); - git_worktree_free(worktree); - git_repository_free(worktree_repo); - return error; -} - -int git_repository_foreach_worktree(git_repository *repo, - git_repository_foreach_worktree_cb cb, - void *payload) -{ - git_strarray worktrees = {0}; - git_repository *worktree_repo = NULL; - git_worktree *worktree = NULL; - int error; - size_t i; - - /* apply operation to repository supplied when commondir is empty, implying there's - * no linked worktrees to iterate, which can occur when using custom odb/refdb - */ - if (!repo->commondir) - return cb(repo, payload); - - if ((error = git_repository_open(&worktree_repo, repo->commondir)) < 0 || - (error = cb(worktree_repo, payload) != 0)) - goto out; - - git_repository_free(worktree_repo); - worktree_repo = NULL; - - if ((error = git_worktree_list(&worktrees, repo)) < 0) - goto out; - - for (i = 0; i < worktrees.count; i++) { - git_repository_free(worktree_repo); - worktree_repo = NULL; - git_worktree_free(worktree); - worktree = NULL; - - if ((error = git_worktree_lookup(&worktree, repo, worktrees.strings[i]) < 0) || - (error = git_repository_open_from_worktree(&worktree_repo, worktree)) < 0) { - if (error != GIT_ENOTFOUND) - goto out; - error = 0; - continue; - } - - if ((error = cb(worktree_repo, payload)) != 0) - goto out; - } - -out: - git_strarray_dispose(&worktrees); - git_repository_free(worktree_repo); - git_worktree_free(worktree); - return error; -} - -int git_repository_head_unborn(git_repository *repo) -{ - git_reference *ref = NULL; - int error; - - error = git_repository_head(&ref, repo); - git_reference_free(ref); - - if (error == GIT_EUNBORNBRANCH) { - git_error_clear(); - return 1; - } - - if (error < 0) - return -1; - - return 0; -} - -static int repo_contains_no_reference(git_repository *repo) -{ - git_reference_iterator *iter; - const char *refname; - int error; - - if ((error = git_reference_iterator_new(&iter, repo)) < 0) - return error; - - error = git_reference_next_name(&refname, iter); - git_reference_iterator_free(iter); - - if (error == GIT_ITEROVER) - return 1; - - return error; -} - -int git_repository_initialbranch(git_str *out, git_repository *repo) -{ - git_config *config; - git_config_entry *entry = NULL; - const char *branch; - int valid, error; - - if ((error = git_repository_config__weakptr(&config, repo)) < 0) - return error; - - if ((error = git_config_get_entry(&entry, config, "init.defaultbranch")) == 0 && - *entry->value) { - branch = entry->value; - } - else if (!error || error == GIT_ENOTFOUND) { - branch = GIT_BRANCH_DEFAULT; - } - else { - goto done; - } - - if ((error = git_str_puts(out, GIT_REFS_HEADS_DIR)) < 0 || - (error = git_str_puts(out, branch)) < 0 || - (error = git_reference_name_is_valid(&valid, out->ptr)) < 0) - goto done; - - if (!valid) { - git_error_set(GIT_ERROR_INVALID, "the value of init.defaultBranch is not a valid branch name"); - error = -1; - } - -done: - git_config_entry_free(entry); - return error; -} - -int git_repository_is_empty(git_repository *repo) -{ - git_reference *head = NULL; - git_str initialbranch = GIT_STR_INIT; - int result = 0; - - if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 || - (result = git_repository_initialbranch(&initialbranch, repo)) < 0) - goto done; - - result = (git_reference_type(head) == GIT_REFERENCE_SYMBOLIC && - strcmp(git_reference_symbolic_target(head), initialbranch.ptr) == 0 && - repo_contains_no_reference(repo)); - -done: - git_reference_free(head); - git_str_dispose(&initialbranch); - - return result; -} - -static const char *resolved_parent_path(const git_repository *repo, git_repository_item_t item, git_repository_item_t fallback) -{ - const char *parent; - - switch (item) { - case GIT_REPOSITORY_ITEM_GITDIR: - parent = git_repository_path(repo); - break; - case GIT_REPOSITORY_ITEM_WORKDIR: - parent = git_repository_workdir(repo); - break; - case GIT_REPOSITORY_ITEM_COMMONDIR: - parent = git_repository_commondir(repo); - break; - default: - git_error_set(GIT_ERROR_INVALID, "invalid item directory"); - return NULL; - } - if (!parent && fallback != GIT_REPOSITORY_ITEM__LAST) - return resolved_parent_path(repo, fallback, GIT_REPOSITORY_ITEM__LAST); - - return parent; -} - -int git_repository_item_path( - git_buf *out, - const git_repository *repo, - git_repository_item_t item) -{ - GIT_BUF_WRAP_PRIVATE(out, git_repository__item_path, repo, item); -} - -int git_repository__item_path( - git_str *out, - const git_repository *repo, - git_repository_item_t item) -{ - const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback); - if (parent == NULL) { - git_error_set(GIT_ERROR_INVALID, "path cannot exist in repository"); - return GIT_ENOTFOUND; - } - - if (git_str_sets(out, parent) < 0) - return -1; - - if (items[item].name) { - if (git_str_joinpath(out, parent, items[item].name) < 0) - return -1; - } - - if (items[item].directory) { - if (git_fs_path_to_dir(out) < 0) - return -1; - } - - return 0; -} - -const char *git_repository_path(const git_repository *repo) -{ - GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL); - return repo->gitdir; -} - -const char *git_repository_workdir(const git_repository *repo) -{ - GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL); - - if (repo->is_bare) - return NULL; - - return repo->workdir; -} - -int git_repository_workdir_path( - git_str *out, git_repository *repo, const char *path) -{ - int error; - - if (!repo->workdir) { - git_error_set(GIT_ERROR_REPOSITORY, "repository has no working directory"); - return GIT_EBAREREPO; - } - - if (!(error = git_str_joinpath(out, repo->workdir, path))) - error = git_path_validate_str_length(repo, out); - - return error; -} - -const char *git_repository_commondir(const git_repository *repo) -{ - GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL); - return repo->commondir; -} - -int git_repository_set_workdir( - git_repository *repo, const char *workdir, int update_gitlink) -{ - int error = 0; - git_str path = GIT_STR_INIT; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(workdir); - - if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0) - return -1; - - if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0) { - git_str_dispose(&path); - return 0; - } - - if (update_gitlink) { - git_config *config; - - if (git_repository_config__weakptr(&config, repo) < 0) { - git_str_dispose(&path); - return -1; - } - - error = repo_write_gitlink(path.ptr, git_repository_path(repo), false); - - /* passthrough error means gitlink is unnecessary */ - if (error == GIT_PASSTHROUGH) - error = git_config_delete_entry(config, "core.worktree"); - else if (!error) - error = git_config_set_string(config, "core.worktree", path.ptr); - - if (!error) - error = git_config_set_bool(config, "core.bare", false); - } - - if (!error) { - char *old_workdir = repo->workdir; - - repo->workdir = git_str_detach(&path); - repo->is_bare = 0; - - git__free(old_workdir); - } - git_str_dispose(&path); - - return error; -} - -int git_repository_is_bare(const git_repository *repo) -{ - GIT_ASSERT_ARG(repo); - return repo->is_bare; -} - -int git_repository_is_worktree(const git_repository *repo) -{ - GIT_ASSERT_ARG(repo); - return repo->is_worktree; -} - -int git_repository_set_bare(git_repository *repo) -{ - int error; - git_config *config; - - GIT_ASSERT_ARG(repo); - - if (repo->is_bare) - return 0; - - if ((error = git_repository_config__weakptr(&config, repo)) < 0) - return error; - - if ((error = git_config_set_bool(config, "core.bare", true)) < 0) - return error; - - if ((error = git_config__update_entry(config, "core.worktree", NULL, true, true)) < 0) - return error; - - git__free(repo->workdir); - repo->workdir = NULL; - repo->is_bare = 1; - - return 0; -} - -int git_repository_head_commit(git_commit **commit, git_repository *repo) -{ - git_reference *head; - git_object *obj; - int error; - - if ((error = git_repository_head(&head, repo)) < 0) - return error; - - if ((error = git_reference_peel(&obj, head, GIT_OBJECT_COMMIT)) < 0) - goto cleanup; - - *commit = (git_commit *)obj; - -cleanup: - git_reference_free(head); - return error; -} - -int git_repository_head_tree(git_tree **tree, git_repository *repo) -{ - git_reference *head; - git_object *obj; - int error; - - if ((error = git_repository_head(&head, repo)) < 0) - return error; - - if ((error = git_reference_peel(&obj, head, GIT_OBJECT_TREE)) < 0) - goto cleanup; - - *tree = (git_tree *)obj; - -cleanup: - git_reference_free(head); - return error; -} - -int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - char orig_head_str[GIT_OID_MAX_HEXSIZE]; - int error = 0; - - git_oid_fmt(orig_head_str, orig_head); - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 && - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 && - (error = git_filebuf_printf(&file, "%.*s\n", (int)git_oid_hexsize(repo->oid_type), orig_head_str)) == 0) - error = git_filebuf_commit(&file); - - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - return error; -} - -static int git_repository__message(git_str *out, git_repository *repo) -{ - git_str path = GIT_STR_INIT; - struct stat st; - int error; - - if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0) - return -1; - - if ((error = p_stat(git_str_cstr(&path), &st)) < 0) { - if (errno == ENOENT) - error = GIT_ENOTFOUND; - git_error_set(GIT_ERROR_OS, "could not access message file"); - } else { - error = git_futils_readbuffer(out, git_str_cstr(&path)); - } - - git_str_dispose(&path); - - return error; -} - -int git_repository_message(git_buf *out, git_repository *repo) -{ - GIT_BUF_WRAP_PRIVATE(out, git_repository__message, repo); -} - -int git_repository_message_remove(git_repository *repo) -{ - git_str path = GIT_STR_INIT; - int error; - - if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0) - return -1; - - error = p_unlink(git_str_cstr(&path)); - git_str_dispose(&path); - - return error; -} - -int git_repository_hashfile( - git_oid *out, - git_repository *repo, - const char *path, - git_object_t type, - const char *as_path) -{ - int error; - git_filter_list *fl = NULL; - git_file fd = -1; - uint64_t len; - git_str full_path = GIT_STR_INIT; - const char *workdir = git_repository_workdir(repo); - - /* as_path can be NULL */ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(path); - GIT_ASSERT_ARG(repo); - - if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 || - (error = git_path_validate_str_length(repo, &full_path)) < 0) - return error; - - /* - * NULL as_path means that we should derive it from the - * given path. - */ - if (!as_path) { - if (workdir && !git__prefixcmp(full_path.ptr, workdir)) - as_path = full_path.ptr + strlen(workdir); - else - as_path = ""; - } - - /* passing empty string for "as_path" indicated --no-filters */ - if (strlen(as_path) > 0) { - error = git_filter_list_load( - &fl, repo, NULL, as_path, - GIT_FILTER_TO_ODB, GIT_FILTER_DEFAULT); - - if (error < 0) - return error; - } - - /* at this point, error is a count of the number of loaded filters */ - - fd = git_futils_open_ro(full_path.ptr); - if (fd < 0) { - error = fd; - goto cleanup; - } - - if ((error = git_futils_filesize(&len, fd)) < 0) - goto cleanup; - - if (!git__is_sizet(len)) { - git_error_set(GIT_ERROR_OS, "file size overflow for 32-bit systems"); - error = -1; - goto cleanup; - } - - error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, repo->oid_type, fl); - -cleanup: - if (fd >= 0) - p_close(fd); - git_filter_list_free(fl); - git_str_dispose(&full_path); - - return error; -} - -static int checkout_message(git_str *out, git_reference *old, const char *new) -{ - const char *idstr; - - git_str_puts(out, "checkout: moving from "); - - if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC) { - git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old))); - } else { - if ((idstr = git_oid_tostr_s(git_reference_target(old))) == NULL) - return -1; - - git_str_puts(out, idstr); - } - - git_str_puts(out, " to "); - - if (git_reference__is_branch(new) || - git_reference__is_tag(new) || - git_reference__is_remote(new)) - git_str_puts(out, git_reference__shorthand(new)); - else - git_str_puts(out, new); - - if (git_str_oom(out)) - return -1; - - return 0; -} - -static int detach(git_repository *repo, const git_oid *id, const char *new) -{ - int error; - git_str log_message = GIT_STR_INIT; - git_object *object = NULL, *peeled = NULL; - git_reference *new_head = NULL, *current = NULL; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(id); - - if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0) - return error; - - if ((error = git_object_lookup(&object, repo, id, GIT_OBJECT_ANY)) < 0) - goto cleanup; - - if ((error = git_object_peel(&peeled, object, GIT_OBJECT_COMMIT)) < 0) - goto cleanup; - - if (new == NULL && - (new = git_oid_tostr_s(git_object_id(peeled))) == NULL) { - error = -1; - goto cleanup; - } - - if ((error = checkout_message(&log_message, current, new)) < 0) - goto cleanup; - - error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_str_cstr(&log_message)); - -cleanup: - git_str_dispose(&log_message); - git_object_free(object); - git_object_free(peeled); - git_reference_free(current); - git_reference_free(new_head); - return error; -} - -int git_repository_set_head( - git_repository *repo, - const char *refname) -{ - git_reference *ref = NULL, *current = NULL, *new_head = NULL; - git_str log_message = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(refname); - - if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0) - return error; - - if ((error = checkout_message(&log_message, current, refname)) < 0) - goto cleanup; - - error = git_reference_lookup(&ref, repo, refname); - if (error < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - if (ref && current->type == GIT_REFERENCE_SYMBOLIC && git__strcmp(current->target.symbolic, ref->name) && - git_reference_is_branch(ref) && git_branch_is_checked_out(ref)) { - git_error_set(GIT_ERROR_REPOSITORY, "cannot set HEAD to reference '%s' as it is the current HEAD " - "of a linked repository.", git_reference_name(ref)); - error = -1; - goto cleanup; - } - - if (!error) { - if (git_reference_is_branch(ref)) { - error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, - git_reference_name(ref), true, git_str_cstr(&log_message)); - } else { - error = detach(repo, git_reference_target(ref), - git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL); - } - } else if (git_reference__is_branch(refname)) { - error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname, - true, git_str_cstr(&log_message)); - } - -cleanup: - git_str_dispose(&log_message); - git_reference_free(current); - git_reference_free(ref); - git_reference_free(new_head); - return error; -} - -int git_repository_set_head_detached( - git_repository *repo, - const git_oid *committish) -{ - return detach(repo, committish, NULL); -} - -int git_repository_set_head_detached_from_annotated( - git_repository *repo, - const git_annotated_commit *committish) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(committish); - - return detach(repo, git_annotated_commit_id(committish), committish->description); -} - -int git_repository_detach_head(git_repository *repo) -{ - git_reference *old_head = NULL, *new_head = NULL, *current = NULL; - git_object *object = NULL; - git_str log_message = GIT_STR_INIT; - const char *idstr; - int error; - - GIT_ASSERT_ARG(repo); - - if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0) - return error; - - if ((error = git_repository_head(&old_head, repo)) < 0) - goto cleanup; - - if ((error = git_object_lookup(&object, repo, git_reference_target(old_head), GIT_OBJECT_COMMIT)) < 0) - goto cleanup; - - if ((idstr = git_oid_tostr_s(git_object_id(object))) == NULL) { - error = -1; - goto cleanup; - } - - if ((error = checkout_message(&log_message, current, idstr)) < 0) - goto cleanup; - - error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head), - 1, git_str_cstr(&log_message)); - -cleanup: - git_str_dispose(&log_message); - git_object_free(object); - git_reference_free(old_head); - git_reference_free(new_head); - git_reference_free(current); - return error; -} - -/** - * Loosely ported from git.git - * https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh#L198-289 - */ -int git_repository_state(git_repository *repo) -{ - git_str repo_path = GIT_STR_INIT; - int state = GIT_REPOSITORY_STATE_NONE; - - GIT_ASSERT_ARG(repo); - - if (git_str_puts(&repo_path, repo->gitdir) < 0) - return -1; - - if (git_fs_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE)) - state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE; - else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR)) - state = GIT_REPOSITORY_STATE_REBASE_MERGE; - else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE)) - state = GIT_REPOSITORY_STATE_REBASE; - else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE)) - state = GIT_REPOSITORY_STATE_APPLY_MAILBOX; - else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR)) - state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE; - else if (git_fs_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE)) - state = GIT_REPOSITORY_STATE_MERGE; - else if (git_fs_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) { - state = GIT_REPOSITORY_STATE_REVERT; - if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) { - state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE; - } - } else if (git_fs_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) { - state = GIT_REPOSITORY_STATE_CHERRYPICK; - if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) { - state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE; - } - } else if (git_fs_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE)) - state = GIT_REPOSITORY_STATE_BISECT; - - git_str_dispose(&repo_path); - return state; -} - -int git_repository__cleanup_files( - git_repository *repo, const char *files[], size_t files_len) -{ - git_str buf = GIT_STR_INIT; - size_t i; - int error; - - for (error = 0, i = 0; !error && i < files_len; ++i) { - const char *path; - - if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0) - return -1; - - path = git_str_cstr(&buf); - - if (git_fs_path_isfile(path)) { - error = p_unlink(path); - } else if (git_fs_path_isdir(path)) { - error = git_futils_rmdir_r(path, NULL, - GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS); - } - - git_str_clear(&buf); - } - - git_str_dispose(&buf); - return error; -} - -static const char *state_files[] = { - GIT_MERGE_HEAD_FILE, - GIT_MERGE_MODE_FILE, - GIT_MERGE_MSG_FILE, - GIT_REVERT_HEAD_FILE, - GIT_CHERRYPICK_HEAD_FILE, - GIT_BISECT_LOG_FILE, - GIT_REBASE_MERGE_DIR, - GIT_REBASE_APPLY_DIR, - GIT_SEQUENCER_DIR, -}; - -int git_repository_state_cleanup(git_repository *repo) -{ - GIT_ASSERT_ARG(repo); - - return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files)); -} - -int git_repository__shallow_roots( - git_oid **out, - size_t *out_len, - git_repository *repo) -{ - int error = 0; - - if (!repo->shallow_grafts && (error = load_grafts(repo)) < 0) - return error; - - if ((error = git_grafts_refresh(repo->shallow_grafts)) < 0) - return error; - - if ((error = git_grafts_oids(out, out_len, repo->shallow_grafts)) < 0) - return error; - - return 0; -} - -int git_repository__shallow_roots_write(git_repository *repo, git_oidarray *roots) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str path = GIT_STR_INIT; - char oid_str[GIT_OID_MAX_HEXSIZE + 1]; - size_t i; - int filebuf_hash, error = 0; - - GIT_ASSERT_ARG(repo); - - filebuf_hash = git_filebuf_hash_flags(git_oid_algorithm(repo->oid_type)); - GIT_ASSERT(filebuf_hash); - - if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0) - goto on_error; - - if ((error = git_filebuf_open(&file, git_str_cstr(&path), filebuf_hash, 0666)) < 0) - goto on_error; - - for (i = 0; i < roots->count; i++) { - git_oid_tostr(oid_str, sizeof(oid_str), &roots->ids[i]); - git_filebuf_write(&file, oid_str, git_oid_hexsize(repo->oid_type)); - git_filebuf_write(&file, "\n", 1); - } - - git_filebuf_commit(&file); - - if ((error = load_grafts(repo)) < 0) { - error = -1; - goto on_error; - } - - if (!roots->count) - remove(path.ptr); - -on_error: - git_str_dispose(&path); - - return error; -} - -int git_repository_is_shallow(git_repository *repo) -{ - git_str path = GIT_STR_INIT; - struct stat st; - int error; - - if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0) - return error; - - error = git_fs_path_lstat(path.ptr, &st); - git_str_dispose(&path); - - if (error == GIT_ENOTFOUND) { - git_error_clear(); - return 0; - } - - if (error < 0) - return error; - - return st.st_size == 0 ? 0 : 1; -} - -int git_repository_init_options_init( - git_repository_init_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_repository_init_options, - GIT_REPOSITORY_INIT_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_repository_init_init_options( - git_repository_init_options *opts, unsigned int version) -{ - return git_repository_init_options_init(opts, version); -} -#endif - -int git_repository_ident(const char **name, const char **email, const git_repository *repo) -{ - *name = repo->ident_name; - *email = repo->ident_email; - - return 0; -} - -int git_repository_set_ident(git_repository *repo, const char *name, const char *email) -{ - char *tmp_name = NULL, *tmp_email = NULL; - - if (name) { - tmp_name = git__strdup(name); - GIT_ERROR_CHECK_ALLOC(tmp_name); - } - - if (email) { - tmp_email = git__strdup(email); - GIT_ERROR_CHECK_ALLOC(tmp_email); - } - - tmp_name = git_atomic_swap(repo->ident_name, tmp_name); - tmp_email = git_atomic_swap(repo->ident_email, tmp_email); - - git__free(tmp_name); - git__free(tmp_email); - - return 0; -} - -int git_repository_submodule_cache_all(git_repository *repo) -{ - GIT_ASSERT_ARG(repo); - return git_submodule_cache_init(&repo->submodule_cache, repo); -} - -int git_repository_submodule_cache_clear(git_repository *repo) -{ - int error = 0; - GIT_ASSERT_ARG(repo); - - error = git_submodule_cache_free(repo->submodule_cache); - repo->submodule_cache = NULL; - return error; -} - -git_oid_t git_repository_oid_type(git_repository *repo) -{ - return repo ? repo->oid_type : 0; -} - -struct mergehead_data { - git_repository *repo; - git_vector *parents; -}; - -static int insert_mergehead(const git_oid *oid, void *payload) -{ - git_commit *commit; - struct mergehead_data *data = (struct mergehead_data *)payload; - - if (git_commit_lookup(&commit, data->repo, oid) < 0) - return -1; - - return git_vector_insert(data->parents, commit); -} - -int git_repository_commit_parents(git_commitarray *out, git_repository *repo) -{ - git_commit *first_parent = NULL, *commit; - git_reference *head_ref = NULL; - git_vector parents = GIT_VECTOR_INIT; - struct mergehead_data data; - size_t i; - int error; - - GIT_ASSERT_ARG(out && repo); - - out->count = 0; - out->commits = NULL; - - error = git_revparse_ext((git_object **)&first_parent, &head_ref, repo, "HEAD"); - - if (error != 0) { - if (error == GIT_ENOTFOUND) - error = 0; - - goto done; - } - - if ((error = git_vector_insert(&parents, first_parent)) < 0) - goto done; - - data.repo = repo; - data.parents = &parents; - - error = git_repository_mergehead_foreach(repo, insert_mergehead, &data); - - if (error == GIT_ENOTFOUND) - error = 0; - else if (error != 0) - goto done; - - out->commits = (git_commit **)git_vector_detach(&out->count, NULL, &parents); - -done: - git_vector_foreach(&parents, i, commit) - git__free(commit); - - git_reference_free(head_ref); - return error; -} - -int git_repository__abbrev_length(int *out, git_repository *repo) -{ - size_t oid_hexsize; - int len; - int error; - - oid_hexsize = git_oid_hexsize(repo->oid_type); - - if ((error = git_repository__configmap_lookup(&len, repo, GIT_CONFIGMAP_ABBREV)) < 0) - return error; - - if (len < GIT_ABBREV_MINIMUM) { - git_error_set(GIT_ERROR_CONFIG, "invalid oid abbreviation setting: '%d'", len); - return -1; - } - - if (len == GIT_ABBREV_FALSE || (size_t)len > oid_hexsize) - len = (int)oid_hexsize; - - *out = len; - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/repository.h b/vendor/libgit2-sys/libgit2/src/libgit2/repository.h deleted file mode 100644 index fbf1438..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/repository.h +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_repository_h__ -#define INCLUDE_repository_h__ - -#include "common.h" - -#include "git2/common.h" -#include "git2/oid.h" -#include "git2/odb.h" -#include "git2/repository.h" -#include "git2/object.h" -#include "git2/config.h" - -#include "array.h" -#include "cache.h" -#include "refs.h" -#include "str.h" -#include "object.h" -#include "attrcache.h" -#include "submodule.h" -#include "diff_driver.h" -#include "grafts.h" - -#define DOT_GIT ".git" -#define GIT_DIR DOT_GIT "/" -#define GIT_DIR_MODE 0755 -#define GIT_BARE_DIR_MODE 0777 - -/* Default DOS-compatible 8.3 "short name" for a git repository, "GIT~1" */ -#define GIT_DIR_SHORTNAME "GIT~1" - -extern bool git_repository__fsync_gitdir; -extern bool git_repository__validate_ownership; - -/** Cvar cache identifiers */ -typedef enum { - GIT_CONFIGMAP_AUTO_CRLF = 0, /* core.autocrlf */ - GIT_CONFIGMAP_EOL, /* core.eol */ - GIT_CONFIGMAP_SYMLINKS, /* core.symlinks */ - GIT_CONFIGMAP_IGNORECASE, /* core.ignorecase */ - GIT_CONFIGMAP_FILEMODE, /* core.filemode */ - GIT_CONFIGMAP_IGNORESTAT, /* core.ignorestat */ - GIT_CONFIGMAP_TRUSTCTIME, /* core.trustctime */ - GIT_CONFIGMAP_ABBREV, /* core.abbrev */ - GIT_CONFIGMAP_PRECOMPOSE, /* core.precomposeunicode */ - GIT_CONFIGMAP_SAFE_CRLF, /* core.safecrlf */ - GIT_CONFIGMAP_LOGALLREFUPDATES, /* core.logallrefupdates */ - GIT_CONFIGMAP_PROTECTHFS, /* core.protectHFS */ - GIT_CONFIGMAP_PROTECTNTFS, /* core.protectNTFS */ - GIT_CONFIGMAP_FSYNCOBJECTFILES, /* core.fsyncObjectFiles */ - GIT_CONFIGMAP_LONGPATHS, /* core.longpaths */ - GIT_CONFIGMAP_CACHE_MAX -} git_configmap_item; - -/** - * Configuration map value enumerations - * - * These are the values that are actually stored in the configmap cache, - * instead of their string equivalents. These values are internal and - * symbolic; make sure that none of them is set to `-1`, since that is - * the unique identifier for "not cached" - */ -typedef enum { - /* The value hasn't been loaded from the cache yet */ - GIT_CONFIGMAP_NOT_CACHED = -1, - - /* core.safecrlf: false, 'fail', 'warn' */ - GIT_SAFE_CRLF_FALSE = 0, - GIT_SAFE_CRLF_FAIL = 1, - GIT_SAFE_CRLF_WARN = 2, - - /* core.autocrlf: false, true, 'input; */ - GIT_AUTO_CRLF_FALSE = 0, - GIT_AUTO_CRLF_TRUE = 1, - GIT_AUTO_CRLF_INPUT = 2, - GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE, - - /* core.eol: unset, 'crlf', 'lf', 'native' */ - GIT_EOL_UNSET = 0, - GIT_EOL_CRLF = 1, - GIT_EOL_LF = 2, -#ifdef GIT_WIN32 - GIT_EOL_NATIVE = GIT_EOL_CRLF, -#else - GIT_EOL_NATIVE = GIT_EOL_LF, -#endif - GIT_EOL_DEFAULT = GIT_EOL_NATIVE, - - /* core.symlinks: bool */ - GIT_SYMLINKS_DEFAULT = GIT_CONFIGMAP_TRUE, - /* core.ignorecase */ - GIT_IGNORECASE_DEFAULT = GIT_CONFIGMAP_FALSE, - /* core.filemode */ - GIT_FILEMODE_DEFAULT = GIT_CONFIGMAP_TRUE, - /* core.ignorestat */ - GIT_IGNORESTAT_DEFAULT = GIT_CONFIGMAP_FALSE, - /* core.trustctime */ - GIT_TRUSTCTIME_DEFAULT = GIT_CONFIGMAP_TRUE, - /* core.abbrev */ - GIT_ABBREV_FALSE = GIT_OID_MAX_HEXSIZE, - GIT_ABBREV_MINIMUM = 4, - GIT_ABBREV_DEFAULT = 7, - /* core.precomposeunicode */ - GIT_PRECOMPOSE_DEFAULT = GIT_CONFIGMAP_FALSE, - /* core.safecrlf */ - GIT_SAFE_CRLF_DEFAULT = GIT_CONFIGMAP_FALSE, - /* core.logallrefupdates */ - GIT_LOGALLREFUPDATES_FALSE = GIT_CONFIGMAP_FALSE, - GIT_LOGALLREFUPDATES_TRUE = GIT_CONFIGMAP_TRUE, - GIT_LOGALLREFUPDATES_UNSET = 2, - GIT_LOGALLREFUPDATES_ALWAYS = 3, - GIT_LOGALLREFUPDATES_DEFAULT = GIT_LOGALLREFUPDATES_UNSET, - /* core.protectHFS */ - GIT_PROTECTHFS_DEFAULT = GIT_CONFIGMAP_FALSE, - /* core.protectNTFS */ - GIT_PROTECTNTFS_DEFAULT = GIT_CONFIGMAP_TRUE, - /* core.fsyncObjectFiles */ - GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CONFIGMAP_FALSE, - /* core.longpaths */ - GIT_LONGPATHS_DEFAULT = GIT_CONFIGMAP_FALSE -} git_configmap_value; - -/* internal repository init flags */ -enum { - GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16), - GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17), - GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18) -}; - -/** Internal structure for repository object */ -struct git_repository { - git_odb *_odb; - git_refdb *_refdb; - git_config *_config; - git_index *_index; - - git_cache objects; - git_attr_cache *attrcache; - git_diff_driver_registry *diff_drivers; - - char *gitlink; - char *gitdir; - char *commondir; - char *workdir; - char *namespace; - - char *ident_name; - char *ident_email; - - git_array_t(git_str) reserved_names; - - unsigned use_env:1, - is_bare:1, - is_worktree:1; - git_oid_t oid_type; - - unsigned int lru_counter; - - git_grafts *grafts; - git_grafts *shallow_grafts; - - git_atomic32 attr_session_key; - - intptr_t configmap_cache[GIT_CONFIGMAP_CACHE_MAX]; - git_submodule_cache *submodule_cache; -}; - -GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo) -{ - return repo->attrcache; -} - -int git_repository_head_commit(git_commit **commit, git_repository *repo); -int git_repository_head_tree(git_tree **tree, git_repository *repo); -int git_repository_create_head(const char *git_dir, const char *ref_name); - -typedef int (*git_repository_foreach_worktree_cb)(git_repository *, void *); - -int git_repository_foreach_worktree(git_repository *repo, - git_repository_foreach_worktree_cb cb, - void *payload); - -/* - * Weak pointers to repository internals. - * - * The returned pointers do not need to be freed. Do not keep - * permanent references to these (i.e. between API calls), since they may - * become invalidated if the user replaces a repository internal. - */ -int git_repository_config__weakptr(git_config **out, git_repository *repo); -int git_repository_odb__weakptr(git_odb **out, git_repository *repo); -int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo); -int git_repository_index__weakptr(git_index **out, git_repository *repo); -int git_repository_grafts__weakptr(git_grafts **out, git_repository *repo); -int git_repository_shallow_grafts__weakptr(git_grafts **out, git_repository *repo); - -/* - * Configuration map cache - * - * Efficient access to the most used config variables of a repository. - * The cache is cleared every time the config backend is replaced. - */ -int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item); -void git_repository__configmap_lookup_cache_clear(git_repository *repo); - -/** Return the length that object names will be abbreviated to. */ -int git_repository__abbrev_length(int *out, git_repository *repo); - -int git_repository__item_path(git_str *out, const git_repository *repo, git_repository_item_t item); - -GIT_INLINE(int) git_repository__ensure_not_bare( - git_repository *repo, - const char *operation_name) -{ - if (!git_repository_is_bare(repo)) - return 0; - - git_error_set( - GIT_ERROR_REPOSITORY, - "cannot %s. This operation is not allowed against bare repositories.", - operation_name); - - return GIT_EBAREREPO; -} - -int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head); - -int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len); - -/* The default "reserved names" for a repository */ -extern git_str git_repository__reserved_names_win32[]; -extern size_t git_repository__reserved_names_win32_len; - -extern git_str git_repository__reserved_names_posix[]; -extern size_t git_repository__reserved_names_posix_len; - -/* - * Gets any "reserved names" in the repository. This will return paths - * that should not be allowed in the repository (like ".git") to avoid - * conflicting with the repository path, or with alternate mechanisms to - * the repository path (eg, "GIT~1"). Every attempt will be made to look - * up all possible reserved names - if there was a conflict for the shortname - * GIT~1, for example, this function will try to look up the alternate - * shortname. If that fails, this function returns false, but out and outlen - * will still be populated with good defaults. - */ -bool git_repository__reserved_names( - git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs); - -int git_repository__shallow_roots(git_oid **out, size_t *out_len, git_repository *repo); -int git_repository__shallow_roots_write(git_repository *repo, git_oidarray *roots); - -/* - * The default branch for the repository; the `init.defaultBranch` - * configuration option, if set, or `master` if it is not. - */ -int git_repository_initialbranch(git_str *out, git_repository *repo); - -/* - * Given a relative `path`, this makes it absolute based on the - * repository's working directory. This will perform validation - * to ensure that the path is not longer than MAX_PATH on Windows - * (unless `core.longpaths` is set in the repo config). - */ -int git_repository_workdir_path(git_str *out, git_repository *repo, const char *path); - -int git_repository__extensions(char ***out, size_t *out_len); -int git_repository__set_extensions(const char **extensions, size_t len); -void git_repository__free_extensions(void); - -/* - * Set the object format (OID type) for a repository; this will set - * both the configuration and the internal value for the oid type. - */ -int git_repository__set_objectformat( - git_repository *repo, - git_oid_t oid_type); - -/* SHA256-aware internal functions */ -int git_repository__new(git_repository **out, git_oid_t oid_type); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/reset.c b/vendor/libgit2-sys/libgit2/src/libgit2/reset.c deleted file mode 100644 index 605c4af..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/reset.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "commit.h" -#include "tag.h" -#include "merge.h" -#include "diff.h" -#include "annotated_commit.h" -#include "git2/reset.h" -#include "git2/checkout.h" -#include "git2/merge.h" -#include "git2/refs.h" - -#define ERROR_MSG "Cannot perform reset" - -int git_reset_default( - git_repository *repo, - const git_object *target, - const git_strarray *pathspecs) -{ - git_object *commit = NULL; - git_tree *tree = NULL; - git_diff *diff = NULL; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - size_t i, max_i; - git_index_entry entry; - int error; - git_index *index = NULL; - - GIT_ASSERT_ARG(pathspecs && pathspecs->count > 0); - - memset(&entry, 0, sizeof(git_index_entry)); - - if ((error = git_repository_index(&index, repo)) < 0) - goto cleanup; - - if (target) { - if (git_object_owner(target) != repo) { - git_error_set(GIT_ERROR_OBJECT, - "%s_default - The given target does not belong to this repository.", ERROR_MSG); - return -1; - } - - if ((error = git_object_peel(&commit, target, GIT_OBJECT_COMMIT)) < 0 || - (error = git_commit_tree(&tree, (git_commit *)commit)) < 0) - goto cleanup; - } - - opts.pathspec = *pathspecs; - opts.flags = GIT_DIFF_REVERSE; - - if ((error = git_diff_tree_to_index( - &diff, repo, tree, index, &opts)) < 0) - goto cleanup; - - for (i = 0, max_i = git_diff_num_deltas(diff); i < max_i; ++i) { - const git_diff_delta *delta = git_diff_get_delta(diff, i); - - GIT_ASSERT(delta->status == GIT_DELTA_ADDED || - delta->status == GIT_DELTA_MODIFIED || - delta->status == GIT_DELTA_CONFLICTED || - delta->status == GIT_DELTA_DELETED); - - error = git_index_conflict_remove(index, delta->old_file.path); - if (error < 0) { - if (delta->status == GIT_DELTA_ADDED && error == GIT_ENOTFOUND) - git_error_clear(); - else - goto cleanup; - } - - if (delta->status == GIT_DELTA_DELETED) { - if ((error = git_index_remove(index, delta->old_file.path, 0)) < 0) - goto cleanup; - } else { - entry.mode = delta->new_file.mode; - git_oid_cpy(&entry.id, &delta->new_file.id); - entry.path = (char *)delta->new_file.path; - - if ((error = git_index_add(index, &entry)) < 0) - goto cleanup; - } - } - - error = git_index_write(index); - -cleanup: - git_object_free(commit); - git_tree_free(tree); - git_index_free(index); - git_diff_free(diff); - - return error; -} - -static int reset( - git_repository *repo, - const git_object *target, - const char *to, - git_reset_t reset_type, - const git_checkout_options *checkout_opts) -{ - git_object *commit = NULL; - git_index *index = NULL; - git_tree *tree = NULL; - int error = 0; - git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; - git_str log_message = GIT_STR_INIT; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(target); - - if (checkout_opts) - opts = *checkout_opts; - - if (git_object_owner(target) != repo) { - git_error_set(GIT_ERROR_OBJECT, - "%s - The given target does not belong to this repository.", ERROR_MSG); - return -1; - } - - if (reset_type != GIT_RESET_SOFT && - (error = git_repository__ensure_not_bare(repo, - reset_type == GIT_RESET_MIXED ? "reset mixed" : "reset hard")) < 0) - return error; - - if ((error = git_object_peel(&commit, target, GIT_OBJECT_COMMIT)) < 0 || - (error = git_repository_index(&index, repo)) < 0 || - (error = git_commit_tree(&tree, (git_commit *)commit)) < 0) - goto cleanup; - - if (reset_type == GIT_RESET_SOFT && - (git_repository_state(repo) == GIT_REPOSITORY_STATE_MERGE || - git_index_has_conflicts(index))) - { - git_error_set(GIT_ERROR_OBJECT, "%s (soft) in the middle of a merge", ERROR_MSG); - error = GIT_EUNMERGED; - goto cleanup; - } - - if ((error = git_str_printf(&log_message, "reset: moving to %s", to)) < 0) - return error; - - if (reset_type == GIT_RESET_HARD) { - /* overwrite working directory with the new tree */ - opts.checkout_strategy = GIT_CHECKOUT_FORCE; - - if ((error = git_checkout_tree(repo, (git_object *)tree, &opts)) < 0) - goto cleanup; - } - - /* move HEAD to the new target */ - if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE, - git_object_id(commit), NULL, git_str_cstr(&log_message))) < 0) - goto cleanup; - - if (reset_type > GIT_RESET_SOFT) { - /* reset index to the target content */ - - if ((error = git_index_read_tree(index, tree)) < 0 || - (error = git_index_write(index)) < 0) - goto cleanup; - - if ((error = git_repository_state_cleanup(repo)) < 0) { - git_error_set(GIT_ERROR_INDEX, "%s - failed to clean up merge data", ERROR_MSG); - goto cleanup; - } - } - -cleanup: - git_object_free(commit); - git_index_free(index); - git_tree_free(tree); - git_str_dispose(&log_message); - - return error; -} - -int git_reset( - git_repository *repo, - const git_object *target, - git_reset_t reset_type, - const git_checkout_options *checkout_opts) -{ - char to[GIT_OID_MAX_HEXSIZE + 1]; - - git_oid_tostr(to, GIT_OID_MAX_HEXSIZE + 1, git_object_id(target)); - return reset(repo, target, to, reset_type, checkout_opts); -} - -int git_reset_from_annotated( - git_repository *repo, - const git_annotated_commit *commit, - git_reset_t reset_type, - const git_checkout_options *checkout_opts) -{ - return reset(repo, (git_object *) commit->commit, commit->description, reset_type, checkout_opts); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/revert.c b/vendor/libgit2-sys/libgit2/src/libgit2/revert.c deleted file mode 100644 index 2fb53f8..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/revert.c +++ /dev/null @@ -1,239 +0,0 @@ -/* -* Copyright (C) the libgit2 contributors. All rights reserved. -* -* This file is part of libgit2, distributed under the GNU GPL v2 with -* a Linking Exception. For full terms see the included COPYING file. -*/ - -#include "common.h" - -#include "repository.h" -#include "filebuf.h" -#include "merge.h" -#include "index.h" - -#include "git2/types.h" -#include "git2/merge.h" -#include "git2/revert.h" -#include "git2/commit.h" -#include "git2/sys/commit.h" - -#define GIT_REVERT_FILE_MODE 0666 - -static int write_revert_head( - git_repository *repo, - const char *commit_oidstr) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - int error = 0; - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_REVERT_HEAD_FILE)) >= 0 && - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_REVERT_FILE_MODE)) >= 0 && - (error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0) - error = git_filebuf_commit(&file); - - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - return error; -} - -static int write_merge_msg( - git_repository *repo, - const char *commit_oidstr, - const char *commit_msgline) -{ - git_filebuf file = GIT_FILEBUF_INIT; - git_str file_path = GIT_STR_INIT; - int error = 0; - - if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 || - (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_REVERT_FILE_MODE)) < 0 || - (error = git_filebuf_printf(&file, "Revert \"%s\"\n\nThis reverts commit %s.\n", - commit_msgline, commit_oidstr)) < 0) - goto cleanup; - - error = git_filebuf_commit(&file); - -cleanup: - if (error < 0) - git_filebuf_cleanup(&file); - - git_str_dispose(&file_path); - - return error; -} - -static int revert_normalize_opts( - git_repository *repo, - git_revert_options *opts, - const git_revert_options *given, - const char *their_label) -{ - int error = 0; - unsigned int default_checkout_strategy = GIT_CHECKOUT_ALLOW_CONFLICTS; - - GIT_UNUSED(repo); - - if (given != NULL) - memcpy(opts, given, sizeof(git_revert_options)); - else { - git_revert_options default_opts = GIT_REVERT_OPTIONS_INIT; - memcpy(opts, &default_opts, sizeof(git_revert_options)); - } - - if (!opts->checkout_opts.checkout_strategy) - opts->checkout_opts.checkout_strategy = default_checkout_strategy; - - if (!opts->checkout_opts.our_label) - opts->checkout_opts.our_label = "HEAD"; - - if (!opts->checkout_opts.their_label) - opts->checkout_opts.their_label = their_label; - - return error; -} - -static int revert_state_cleanup(git_repository *repo) -{ - const char *state_files[] = { GIT_REVERT_HEAD_FILE, GIT_MERGE_MSG_FILE }; - - return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files)); -} - -static int revert_seterr(git_commit *commit, const char *fmt) -{ - char commit_id[GIT_OID_MAX_HEXSIZE + 1]; - - git_oid_tostr(commit_id, GIT_OID_MAX_HEXSIZE + 1, git_commit_id(commit)); - git_error_set(GIT_ERROR_REVERT, fmt, commit_id); - - return -1; -} - -int git_revert_commit( - git_index **out, - git_repository *repo, - git_commit *revert_commit, - git_commit *our_commit, - unsigned int mainline, - const git_merge_options *merge_opts) -{ - git_commit *parent_commit = NULL; - git_tree *parent_tree = NULL, *our_tree = NULL, *revert_tree = NULL; - int parent = 0, error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(revert_commit); - GIT_ASSERT_ARG(our_commit); - - if (git_commit_parentcount(revert_commit) > 1) { - if (!mainline) - return revert_seterr(revert_commit, - "mainline branch is not specified but %s is a merge commit"); - - parent = mainline; - } else { - if (mainline) - return revert_seterr(revert_commit, - "mainline branch specified but %s is not a merge commit"); - - parent = git_commit_parentcount(revert_commit); - } - - if (parent && - ((error = git_commit_parent(&parent_commit, revert_commit, (parent - 1))) < 0 || - (error = git_commit_tree(&parent_tree, parent_commit)) < 0)) - goto done; - - if ((error = git_commit_tree(&revert_tree, revert_commit)) < 0 || - (error = git_commit_tree(&our_tree, our_commit)) < 0) - goto done; - - error = git_merge_trees(out, repo, revert_tree, our_tree, parent_tree, merge_opts); - -done: - git_tree_free(parent_tree); - git_tree_free(our_tree); - git_tree_free(revert_tree); - git_commit_free(parent_commit); - - return error; -} - -int git_revert( - git_repository *repo, - git_commit *commit, - const git_revert_options *given_opts) -{ - git_revert_options opts; - git_reference *our_ref = NULL; - git_commit *our_commit = NULL; - char commit_id[GIT_OID_MAX_HEXSIZE + 1]; - const char *commit_msg; - git_str their_label = GIT_STR_INIT; - git_index *index = NULL; - git_indexwriter indexwriter = GIT_INDEXWRITER_INIT; - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(commit); - - GIT_ERROR_CHECK_VERSION(given_opts, GIT_REVERT_OPTIONS_VERSION, "git_revert_options"); - - if ((error = git_repository__ensure_not_bare(repo, "revert")) < 0) - return error; - - git_oid_tostr(commit_id, GIT_OID_MAX_HEXSIZE + 1, git_commit_id(commit)); - - if ((commit_msg = git_commit_summary(commit)) == NULL) { - error = -1; - goto on_error; - } - - if ((error = git_str_printf(&their_label, "parent of %.7s... %s", commit_id, commit_msg)) < 0 || - (error = revert_normalize_opts(repo, &opts, given_opts, git_str_cstr(&their_label))) < 0 || - (error = git_indexwriter_init_for_operation(&indexwriter, repo, &opts.checkout_opts.checkout_strategy)) < 0 || - (error = write_revert_head(repo, commit_id)) < 0 || - (error = write_merge_msg(repo, commit_id, commit_msg)) < 0 || - (error = git_repository_head(&our_ref, repo)) < 0 || - (error = git_reference_peel((git_object **)&our_commit, our_ref, GIT_OBJECT_COMMIT)) < 0 || - (error = git_revert_commit(&index, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 || - (error = git_merge__check_result(repo, index)) < 0 || - (error = git_merge__append_conflicts_to_merge_msg(repo, index)) < 0 || - (error = git_checkout_index(repo, index, &opts.checkout_opts)) < 0 || - (error = git_indexwriter_commit(&indexwriter)) < 0) - goto on_error; - - goto done; - -on_error: - revert_state_cleanup(repo); - -done: - git_indexwriter_cleanup(&indexwriter); - git_index_free(index); - git_commit_free(our_commit); - git_reference_free(our_ref); - git_str_dispose(&their_label); - - return error; -} - -int git_revert_options_init(git_revert_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_revert_options, GIT_REVERT_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_revert_init_options(git_revert_options *opts, unsigned int version) -{ - return git_revert_options_init(opts, version); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/revparse.c b/vendor/libgit2-sys/libgit2/src/libgit2/revparse.c deleted file mode 100644 index 9083e7a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/revparse.c +++ /dev/null @@ -1,968 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "str.h" -#include "tree.h" -#include "refdb.h" -#include "regexp.h" -#include "date.h" - -#include "git2.h" - -static int maybe_sha_or_abbrev( - git_object **out, - git_repository *repo, - const char *spec, - size_t speclen) -{ - git_oid oid; - - if (git_oid__fromstrn(&oid, spec, speclen, repo->oid_type) < 0) - return GIT_ENOTFOUND; - - return git_object_lookup_prefix(out, repo, &oid, speclen, GIT_OBJECT_ANY); -} - -static int maybe_sha( - git_object **out, - git_repository *repo, - const char *spec) -{ - size_t speclen = strlen(spec); - - if (speclen != git_oid_hexsize(repo->oid_type)) - return GIT_ENOTFOUND; - - return maybe_sha_or_abbrev(out, repo, spec, speclen); -} - -static int maybe_abbrev(git_object **out, git_repository *repo, const char *spec) -{ - size_t speclen = strlen(spec); - - return maybe_sha_or_abbrev(out, repo, spec, speclen); -} - -static int build_regex(git_regexp *regex, const char *pattern) -{ - int error; - - if (*pattern == '\0') { - git_error_set(GIT_ERROR_REGEX, "empty pattern"); - return GIT_EINVALIDSPEC; - } - - error = git_regexp_compile(regex, pattern, 0); - if (!error) - return 0; - - git_regexp_dispose(regex); - - return error; -} - -static int maybe_describe(git_object**out, git_repository *repo, const char *spec) -{ - const char *substr; - int error; - git_regexp regex; - - substr = strstr(spec, "-g"); - - if (substr == NULL) - return GIT_ENOTFOUND; - - if (build_regex(®ex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0) - return -1; - - error = git_regexp_match(®ex, spec); - git_regexp_dispose(®ex); - - if (error) - return GIT_ENOTFOUND; - - return maybe_abbrev(out, repo, substr+2); -} - -static int revparse_lookup_object( - git_object **object_out, - git_reference **reference_out, - git_repository *repo, - const char *spec) -{ - int error; - git_reference *ref; - - if ((error = maybe_sha(object_out, repo, spec)) != GIT_ENOTFOUND) - return error; - - error = git_reference_dwim(&ref, repo, spec); - if (!error) { - - error = git_object_lookup( - object_out, repo, git_reference_target(ref), GIT_OBJECT_ANY); - - if (!error) - *reference_out = ref; - - return error; - } - - if (error != GIT_ENOTFOUND) - return error; - - if ((strlen(spec) < git_oid_hexsize(repo->oid_type)) && - ((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND)) - return error; - - if ((error = maybe_describe(object_out, repo, spec)) != GIT_ENOTFOUND) - return error; - - git_error_set(GIT_ERROR_REFERENCE, "revspec '%s' not found", spec); - return GIT_ENOTFOUND; -} - -static int try_parse_numeric(int *n, const char *curly_braces_content) -{ - int32_t content; - const char *end_ptr; - - if (git__strntol32(&content, curly_braces_content, strlen(curly_braces_content), - &end_ptr, 10) < 0) - return -1; - - if (*end_ptr != '\0') - return -1; - - *n = (int)content; - return 0; -} - -static int retrieve_previously_checked_out_branch_or_revision(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, size_t position) -{ - git_reference *ref = NULL; - git_reflog *reflog = NULL; - git_regexp preg; - int error = -1; - size_t i, numentries, cur; - const git_reflog_entry *entry; - const char *msg; - git_str buf = GIT_STR_INIT; - - cur = position; - - if (*identifier != '\0' || *base_ref != NULL) - return GIT_EINVALIDSPEC; - - if (build_regex(&preg, "checkout: moving from (.*) to .*") < 0) - return -1; - - if (git_reference_lookup(&ref, repo, GIT_HEAD_FILE) < 0) - goto cleanup; - - if (git_reflog_read(&reflog, repo, GIT_HEAD_FILE) < 0) - goto cleanup; - - numentries = git_reflog_entrycount(reflog); - - for (i = 0; i < numentries; i++) { - git_regmatch regexmatches[2]; - - entry = git_reflog_entry_byindex(reflog, i); - msg = git_reflog_entry_message(entry); - if (!msg) - continue; - - if (git_regexp_search(&preg, msg, 2, regexmatches) < 0) - continue; - - cur--; - - if (cur > 0) - continue; - - if ((git_str_put(&buf, msg+regexmatches[1].start, regexmatches[1].end - regexmatches[1].start)) < 0) - goto cleanup; - - if ((error = git_reference_dwim(base_ref, repo, git_str_cstr(&buf))) == 0) - goto cleanup; - - if (error < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - error = maybe_abbrev(out, repo, git_str_cstr(&buf)); - - goto cleanup; - } - - error = GIT_ENOTFOUND; - -cleanup: - git_reference_free(ref); - git_str_dispose(&buf); - git_regexp_dispose(&preg); - git_reflog_free(reflog); - return error; -} - -static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t identifier) -{ - git_reflog *reflog; - size_t numentries; - const git_reflog_entry *entry = NULL; - bool search_by_pos = (identifier <= 100000000); - - if (git_reflog_read(&reflog, git_reference_owner(ref), git_reference_name(ref)) < 0) - return -1; - - numentries = git_reflog_entrycount(reflog); - - if (search_by_pos) { - if (numentries < identifier + 1) - goto notfound; - - entry = git_reflog_entry_byindex(reflog, identifier); - git_oid_cpy(oid, git_reflog_entry_id_new(entry)); - } else { - size_t i; - git_time commit_time; - - for (i = 0; i < numentries; i++) { - entry = git_reflog_entry_byindex(reflog, i); - commit_time = git_reflog_entry_committer(entry)->when; - - if (commit_time.time > (git_time_t)identifier) - continue; - - git_oid_cpy(oid, git_reflog_entry_id_new(entry)); - break; - } - - if (i == numentries) { - if (entry == NULL) - goto notfound; - - /* - * TODO: emit a warning (log for 'branch' only goes back to ...) - */ - git_oid_cpy(oid, git_reflog_entry_id_new(entry)); - } - } - - git_reflog_free(reflog); - return 0; - -notfound: - git_error_set( - GIT_ERROR_REFERENCE, - "reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ, - git_reference_name(ref), numentries, identifier); - - git_reflog_free(reflog); - return GIT_ENOTFOUND; -} - -static int retrieve_revobject_from_reflog(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, size_t position) -{ - git_reference *ref; - git_oid oid; - int error = -1; - - if (*base_ref == NULL) { - /* - * When HEAD@{n} is specified, do not use dwim, which would resolve the - * reference (to the current branch that HEAD is pointing to). - */ - if (position > 0 && strcmp(identifier, GIT_HEAD_FILE) == 0) - error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE); - else - error = git_reference_dwim(&ref, repo, identifier); - - if (error < 0) - return error; - } else { - ref = *base_ref; - *base_ref = NULL; - } - - if (position == 0) { - error = git_object_lookup(out, repo, git_reference_target(ref), GIT_OBJECT_ANY); - goto cleanup; - } - - if ((error = retrieve_oid_from_reflog(&oid, ref, position)) < 0) - goto cleanup; - - error = git_object_lookup(out, repo, &oid, GIT_OBJECT_ANY); - -cleanup: - git_reference_free(ref); - return error; -} - -static int retrieve_remote_tracking_reference(git_reference **base_ref, const char *identifier, git_repository *repo) -{ - git_reference *tracking, *ref; - int error = -1; - - if (*base_ref == NULL) { - if ((error = git_reference_dwim(&ref, repo, identifier)) < 0) - return error; - } else { - ref = *base_ref; - *base_ref = NULL; - } - - if (!git_reference_is_branch(ref)) { - error = GIT_EINVALIDSPEC; - goto cleanup; - } - - if ((error = git_branch_upstream(&tracking, ref)) < 0) - goto cleanup; - - *base_ref = tracking; - -cleanup: - git_reference_free(ref); - return error; -} - -static int handle_at_syntax(git_object **out, git_reference **ref, const char *spec, size_t identifier_len, git_repository *repo, const char *curly_braces_content) -{ - bool is_numeric; - int parsed = 0, error = -1; - git_str identifier = GIT_STR_INIT; - git_time_t timestamp; - - GIT_ASSERT(*out == NULL); - - if (git_str_put(&identifier, spec, identifier_len) < 0) - return -1; - - is_numeric = !try_parse_numeric(&parsed, curly_braces_content); - - if (*curly_braces_content == '-' && (!is_numeric || parsed == 0)) { - error = GIT_EINVALIDSPEC; - goto cleanup; - } - - if (is_numeric) { - if (parsed < 0) - error = retrieve_previously_checked_out_branch_or_revision(out, ref, repo, git_str_cstr(&identifier), -parsed); - else - error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), parsed); - - goto cleanup; - } - - if (!strcmp(curly_braces_content, "u") || !strcmp(curly_braces_content, "upstream")) { - error = retrieve_remote_tracking_reference(ref, git_str_cstr(&identifier), repo); - - goto cleanup; - } - - if (git_date_parse(×tamp, curly_braces_content) < 0) { - error = GIT_EINVALIDSPEC; - goto cleanup; - } - - error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp); - -cleanup: - git_str_dispose(&identifier); - return error; -} - -static git_object_t parse_obj_type(const char *str) -{ - if (!strcmp(str, "commit")) - return GIT_OBJECT_COMMIT; - - if (!strcmp(str, "tree")) - return GIT_OBJECT_TREE; - - if (!strcmp(str, "blob")) - return GIT_OBJECT_BLOB; - - if (!strcmp(str, "tag")) - return GIT_OBJECT_TAG; - - return GIT_OBJECT_INVALID; -} - -static int dereference_to_non_tag(git_object **out, git_object *obj) -{ - if (git_object_type(obj) == GIT_OBJECT_TAG) - return git_tag_peel(out, (git_tag *)obj); - - return git_object_dup(out, obj); -} - -static int handle_caret_parent_syntax(git_object **out, git_object *obj, int n) -{ - git_object *temp_commit = NULL; - int error; - - if ((error = git_object_peel(&temp_commit, obj, GIT_OBJECT_COMMIT)) < 0) - return (error == GIT_EAMBIGUOUS || error == GIT_ENOTFOUND) ? - GIT_EINVALIDSPEC : error; - - if (n == 0) { - *out = temp_commit; - return 0; - } - - error = git_commit_parent((git_commit **)out, (git_commit*)temp_commit, n - 1); - - git_object_free(temp_commit); - return error; -} - -static int handle_linear_syntax(git_object **out, git_object *obj, int n) -{ - git_object *temp_commit = NULL; - int error; - - if ((error = git_object_peel(&temp_commit, obj, GIT_OBJECT_COMMIT)) < 0) - return (error == GIT_EAMBIGUOUS || error == GIT_ENOTFOUND) ? - GIT_EINVALIDSPEC : error; - - error = git_commit_nth_gen_ancestor((git_commit **)out, (git_commit*)temp_commit, n); - - git_object_free(temp_commit); - return error; -} - -static int handle_colon_syntax( - git_object **out, - git_object *obj, - const char *path) -{ - git_object *tree; - int error = -1; - git_tree_entry *entry = NULL; - - if ((error = git_object_peel(&tree, obj, GIT_OBJECT_TREE)) < 0) - return error == GIT_ENOTFOUND ? GIT_EINVALIDSPEC : error; - - if (*path == '\0') { - *out = tree; - return 0; - } - - /* - * TODO: Handle the relative path syntax - * (:./relative/path and :../relative/path) - */ - if ((error = git_tree_entry_bypath(&entry, (git_tree *)tree, path)) < 0) - goto cleanup; - - error = git_tree_entry_to_object(out, git_object_owner(tree), entry); - -cleanup: - git_tree_entry_free(entry); - git_object_free(tree); - - return error; -} - -static int walk_and_search(git_object **out, git_revwalk *walk, git_regexp *regex) -{ - int error; - git_oid oid; - git_object *obj; - - while (!(error = git_revwalk_next(&oid, walk))) { - - error = git_object_lookup(&obj, git_revwalk_repository(walk), &oid, GIT_OBJECT_COMMIT); - if ((error < 0) && (error != GIT_ENOTFOUND)) - return -1; - - if (!git_regexp_match(regex, git_commit_message((git_commit*)obj))) { - *out = obj; - return 0; - } - - git_object_free(obj); - } - - if (error < 0 && error == GIT_ITEROVER) - error = GIT_ENOTFOUND; - - return error; -} - -static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern) -{ - git_regexp preg; - git_revwalk *walk = NULL; - int error; - - if ((error = build_regex(&preg, pattern)) < 0) - return error; - - if ((error = git_revwalk_new(&walk, repo)) < 0) - goto cleanup; - - git_revwalk_sorting(walk, GIT_SORT_TIME); - - if (spec_oid == NULL) { - if ((error = git_revwalk_push_glob(walk, "refs/*")) < 0) - goto cleanup; - } else if ((error = git_revwalk_push(walk, spec_oid)) < 0) - goto cleanup; - - error = walk_and_search(out, walk, &preg); - -cleanup: - git_regexp_dispose(&preg); - git_revwalk_free(walk); - - return error; -} - -static int handle_caret_curly_syntax(git_object **out, git_object *obj, const char *curly_braces_content) -{ - git_object_t expected_type; - - if (*curly_braces_content == '\0') - return dereference_to_non_tag(out, obj); - - if (*curly_braces_content == '/') - return handle_grep_syntax(out, git_object_owner(obj), git_object_id(obj), curly_braces_content + 1); - - expected_type = parse_obj_type(curly_braces_content); - - if (expected_type == GIT_OBJECT_INVALID) - return GIT_EINVALIDSPEC; - - return git_object_peel(out, obj, expected_type); -} - -static int extract_curly_braces_content(git_str *buf, const char *spec, size_t *pos) -{ - git_str_clear(buf); - - GIT_ASSERT_ARG(spec[*pos] == '^' || spec[*pos] == '@'); - - (*pos)++; - - if (spec[*pos] == '\0' || spec[*pos] != '{') - return GIT_EINVALIDSPEC; - - (*pos)++; - - while (spec[*pos] != '}') { - if (spec[*pos] == '\0') - return GIT_EINVALIDSPEC; - - if (git_str_putc(buf, spec[(*pos)++]) < 0) - return -1; - } - - (*pos)++; - - return 0; -} - -static int extract_path(git_str *buf, const char *spec, size_t *pos) -{ - git_str_clear(buf); - - GIT_ASSERT_ARG(spec[*pos] == ':'); - - (*pos)++; - - if (git_str_puts(buf, spec + *pos) < 0) - return -1; - - *pos += git_str_len(buf); - - return 0; -} - -static int extract_how_many(int *n, const char *spec, size_t *pos) -{ - const char *end_ptr; - int parsed, accumulated; - char kind = spec[*pos]; - - GIT_ASSERT_ARG(spec[*pos] == '^' || spec[*pos] == '~'); - - accumulated = 0; - - do { - do { - (*pos)++; - accumulated++; - } while (spec[(*pos)] == kind && kind == '~'); - - if (git__isdigit(spec[*pos])) { - if (git__strntol32(&parsed, spec + *pos, strlen(spec + *pos), &end_ptr, 10) < 0) - return GIT_EINVALIDSPEC; - - accumulated += (parsed - 1); - *pos = end_ptr - spec; - } - - } while (spec[(*pos)] == kind && kind == '~'); - - *n = accumulated; - - return 0; -} - -static int object_from_reference(git_object **object, git_reference *reference) -{ - git_reference *resolved = NULL; - int error; - - if (git_reference_resolve(&resolved, reference) < 0) - return -1; - - error = git_object_lookup(object, reference->db->repo, git_reference_target(resolved), GIT_OBJECT_ANY); - git_reference_free(resolved); - - return error; -} - -static int ensure_base_rev_loaded(git_object **object, git_reference **reference, const char *spec, size_t identifier_len, git_repository *repo, bool allow_empty_identifier) -{ - int error; - git_str identifier = GIT_STR_INIT; - - if (*object != NULL) - return 0; - - if (*reference != NULL) - return object_from_reference(object, *reference); - - if (!allow_empty_identifier && identifier_len == 0) - return GIT_EINVALIDSPEC; - - if (git_str_put(&identifier, spec, identifier_len) < 0) - return -1; - - error = revparse_lookup_object(object, reference, repo, git_str_cstr(&identifier)); - git_str_dispose(&identifier); - - return error; -} - -static int ensure_base_rev_is_not_known_yet(git_object *object) -{ - if (object == NULL) - return 0; - - return GIT_EINVALIDSPEC; -} - -static bool any_left_hand_identifier(git_object *object, git_reference *reference, size_t identifier_len) -{ - if (object != NULL) - return true; - - if (reference != NULL) - return true; - - if (identifier_len > 0) - return true; - - return false; -} - -static int ensure_left_hand_identifier_is_not_known_yet(git_object *object, git_reference *reference) -{ - if (!ensure_base_rev_is_not_known_yet(object) && reference == NULL) - return 0; - - return GIT_EINVALIDSPEC; -} - -static int revparse( - git_object **object_out, - git_reference **reference_out, - size_t *identifier_len_out, - git_repository *repo, - const char *spec) -{ - size_t pos = 0, identifier_len = 0; - int error = -1, n; - git_str buf = GIT_STR_INIT; - - git_reference *reference = NULL; - git_object *base_rev = NULL; - - bool should_return_reference = true; - bool parsed = false; - - GIT_ASSERT_ARG(object_out); - GIT_ASSERT_ARG(reference_out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(spec); - - *object_out = NULL; - *reference_out = NULL; - - while (!parsed && spec[pos]) { - switch (spec[pos]) { - case '^': - should_return_reference = false; - - if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0) - goto cleanup; - - if (spec[pos+1] == '{') { - git_object *temp_object = NULL; - - if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0) - goto cleanup; - - if ((error = handle_caret_curly_syntax(&temp_object, base_rev, git_str_cstr(&buf))) < 0) - goto cleanup; - - git_object_free(base_rev); - base_rev = temp_object; - } else { - git_object *temp_object = NULL; - - if ((error = extract_how_many(&n, spec, &pos)) < 0) - goto cleanup; - - if ((error = handle_caret_parent_syntax(&temp_object, base_rev, n)) < 0) - goto cleanup; - - git_object_free(base_rev); - base_rev = temp_object; - } - break; - - case '~': - { - git_object *temp_object = NULL; - - should_return_reference = false; - - if ((error = extract_how_many(&n, spec, &pos)) < 0) - goto cleanup; - - if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0) - goto cleanup; - - if ((error = handle_linear_syntax(&temp_object, base_rev, n)) < 0) - goto cleanup; - - git_object_free(base_rev); - base_rev = temp_object; - break; - } - - case ':': - { - git_object *temp_object = NULL; - - should_return_reference = false; - - if ((error = extract_path(&buf, spec, &pos)) < 0) - goto cleanup; - - if (any_left_hand_identifier(base_rev, reference, identifier_len)) { - if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, true)) < 0) - goto cleanup; - - if ((error = handle_colon_syntax(&temp_object, base_rev, git_str_cstr(&buf))) < 0) - goto cleanup; - } else { - if (*git_str_cstr(&buf) == '/') { - if ((error = handle_grep_syntax(&temp_object, repo, NULL, git_str_cstr(&buf) + 1)) < 0) - goto cleanup; - } else { - - /* - * TODO: support merge-stage path lookup (":2:Makefile") - * and plain index blob lookup (:i-am/a/blob) - */ - git_error_set(GIT_ERROR_INVALID, "unimplemented"); - error = GIT_ERROR; - goto cleanup; - } - } - - git_object_free(base_rev); - base_rev = temp_object; - break; - } - - case '@': - if (spec[pos+1] == '{') { - git_object *temp_object = NULL; - - if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0) - goto cleanup; - - if ((error = ensure_base_rev_is_not_known_yet(base_rev)) < 0) - goto cleanup; - - if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_str_cstr(&buf))) < 0) - goto cleanup; - - if (temp_object != NULL) - base_rev = temp_object; - break; - } else if (spec[pos + 1] == '\0' && !pos) { - spec = "HEAD"; - identifier_len = 4; - parsed = true; - break; - } - /* fall through */ - - default: - if ((error = ensure_left_hand_identifier_is_not_known_yet(base_rev, reference)) < 0) - goto cleanup; - - pos++; - identifier_len++; - } - } - - if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0) - goto cleanup; - - if (!should_return_reference) { - git_reference_free(reference); - reference = NULL; - } - - *object_out = base_rev; - *reference_out = reference; - *identifier_len_out = identifier_len; - error = 0; - -cleanup: - if (error) { - if (error == GIT_EINVALIDSPEC) - git_error_set(GIT_ERROR_INVALID, - "failed to parse revision specifier - Invalid pattern '%s'", spec); - - git_object_free(base_rev); - git_reference_free(reference); - } - - git_str_dispose(&buf); - return error; -} - -int git_revparse_ext( - git_object **object_out, - git_reference **reference_out, - git_repository *repo, - const char *spec) -{ - int error; - size_t identifier_len; - git_object *obj = NULL; - git_reference *ref = NULL; - - if ((error = revparse(&obj, &ref, &identifier_len, repo, spec)) < 0) - goto cleanup; - - *object_out = obj; - *reference_out = ref; - GIT_UNUSED(identifier_len); - - return 0; - -cleanup: - git_object_free(obj); - git_reference_free(ref); - return error; -} - -int git_revparse_single(git_object **out, git_repository *repo, const char *spec) -{ - int error; - git_object *obj = NULL; - git_reference *ref = NULL; - - *out = NULL; - - if ((error = git_revparse_ext(&obj, &ref, repo, spec)) < 0) - goto cleanup; - - git_reference_free(ref); - - *out = obj; - - return 0; - -cleanup: - git_object_free(obj); - git_reference_free(ref); - return error; -} - -int git_revparse( - git_revspec *revspec, - git_repository *repo, - const char *spec) -{ - const char *dotdot; - int error = 0; - - GIT_ASSERT_ARG(revspec); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(spec); - - memset(revspec, 0x0, sizeof(*revspec)); - - if ((dotdot = strstr(spec, "..")) != NULL) { - char *lstr; - const char *rstr; - revspec->flags = GIT_REVSPEC_RANGE; - - /* - * Following git.git, don't allow '..' because it makes command line - * arguments which can be either paths or revisions ambiguous when the - * path is almost certainly intended. The empty range '...' is still - * allowed. - */ - if (!git__strcmp(spec, "..")) { - git_error_set(GIT_ERROR_INVALID, "invalid pattern '..'"); - return GIT_EINVALIDSPEC; - } - - lstr = git__substrdup(spec, dotdot - spec); - rstr = dotdot + 2; - if (dotdot[2] == '.') { - revspec->flags |= GIT_REVSPEC_MERGE_BASE; - rstr++; - } - - error = git_revparse_single( - &revspec->from, - repo, - *lstr == '\0' ? "HEAD" : lstr); - - if (!error) { - error = git_revparse_single( - &revspec->to, - repo, - *rstr == '\0' ? "HEAD" : rstr); - } - - git__free((void*)lstr); - } else { - revspec->flags = GIT_REVSPEC_SINGLE; - error = git_revparse_single(&revspec->from, repo, spec); - } - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/revwalk.c b/vendor/libgit2-sys/libgit2/src/libgit2/revwalk.c deleted file mode 100644 index a793a8e..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/revwalk.c +++ /dev/null @@ -1,849 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "revwalk.h" - -#include "commit.h" -#include "odb.h" -#include "pool.h" - -#include "git2/revparse.h" -#include "merge.h" -#include "vector.h" -#include "hashmap_oid.h" - -GIT_HASHMAP_OID_FUNCTIONS(git_revwalk_oidmap, GIT_HASHMAP_INLINE, git_commit_list_node *); - -static int get_revision(git_commit_list_node **out, git_revwalk *walk, git_commit_list **list); - -git_commit_list_node *git_revwalk__commit_lookup( - git_revwalk *walk, const git_oid *oid) -{ - git_commit_list_node *commit; - - /* lookup and reserve space if not already present */ - if (git_revwalk_oidmap_get(&commit, &walk->commits, oid) == 0) - return commit; - - commit = git_commit_list_alloc_node(walk); - if (commit == NULL) - return NULL; - - git_oid_cpy(&commit->oid, oid); - - if (git_revwalk_oidmap_put(&walk->commits, &commit->oid, commit) < 0) - return NULL; - - return commit; -} - -int git_revwalk__push_commit(git_revwalk *walk, const git_oid *oid, const git_revwalk__push_options *opts) -{ - git_oid commit_id; - int error; - git_object *obj, *oobj; - git_commit_list_node *commit; - git_commit_list *list; - - if ((error = git_object_lookup(&oobj, walk->repo, oid, GIT_OBJECT_ANY)) < 0) - return error; - - error = git_object_peel(&obj, oobj, GIT_OBJECT_COMMIT); - git_object_free(oobj); - - if (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL) { - /* If this comes from e.g. push_glob("tags"), ignore this */ - if (opts->from_glob) - return 0; - - git_error_set(GIT_ERROR_INVALID, "object is not a committish"); - return error; - } - if (error < 0) - return error; - - git_oid_cpy(&commit_id, git_object_id(obj)); - git_object_free(obj); - - commit = git_revwalk__commit_lookup(walk, &commit_id); - if (commit == NULL) - return -1; /* error already reported by failed lookup */ - - /* A previous hide already told us we don't want this commit */ - if (commit->uninteresting) - return 0; - - if (opts->uninteresting) { - walk->limited = 1; - walk->did_hide = 1; - } else { - walk->did_push = 1; - } - - commit->uninteresting = opts->uninteresting; - list = walk->user_input; - - /* To insert by date, we need to parse so we know the date. */ - if (opts->insert_by_date && ((error = git_commit_list_parse(walk, commit)) < 0)) - return error; - - if ((opts->insert_by_date == 0 || - git_commit_list_insert_by_date(commit, &list) == NULL) && - git_commit_list_insert(commit, &list) == NULL) { - git_error_set_oom(); - return -1; - } - - walk->user_input = list; - - return 0; -} - -int git_revwalk_push(git_revwalk *walk, const git_oid *oid) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - - GIT_ASSERT_ARG(walk); - GIT_ASSERT_ARG(oid); - - return git_revwalk__push_commit(walk, oid, &opts); -} - - -int git_revwalk_hide(git_revwalk *walk, const git_oid *oid) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - - GIT_ASSERT_ARG(walk); - GIT_ASSERT_ARG(oid); - - opts.uninteresting = 1; - return git_revwalk__push_commit(walk, oid, &opts); -} - -int git_revwalk__push_ref(git_revwalk *walk, const char *refname, const git_revwalk__push_options *opts) -{ - git_oid oid; - - int error = git_reference_name_to_id(&oid, walk->repo, refname); - if (opts->from_glob && (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL)) { - return 0; - } else if (error < 0) { - return -1; - } - - return git_revwalk__push_commit(walk, &oid, opts); -} - -int git_revwalk__push_glob(git_revwalk *walk, const char *glob, const git_revwalk__push_options *given_opts) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - int error = 0; - git_str buf = GIT_STR_INIT; - git_reference *ref; - git_reference_iterator *iter; - size_t wildcard; - - GIT_ASSERT_ARG(walk); - GIT_ASSERT_ARG(glob); - - if (given_opts) - memcpy(&opts, given_opts, sizeof(opts)); - - /* refs/ is implied if not given in the glob */ - if (git__prefixcmp(glob, GIT_REFS_DIR) != 0) - git_str_joinpath(&buf, GIT_REFS_DIR, glob); - else - git_str_puts(&buf, glob); - GIT_ERROR_CHECK_ALLOC_STR(&buf); - - /* If no '?', '*' or '[' exist, we append '/ *' to the glob */ - wildcard = strcspn(glob, "?*["); - if (!glob[wildcard]) - git_str_put(&buf, "/*", 2); - - if ((error = git_reference_iterator_glob_new(&iter, walk->repo, buf.ptr)) < 0) - goto out; - - opts.from_glob = true; - while ((error = git_reference_next(&ref, iter)) == 0) { - error = git_revwalk__push_ref(walk, git_reference_name(ref), &opts); - git_reference_free(ref); - if (error < 0) - break; - } - git_reference_iterator_free(iter); - - if (error == GIT_ITEROVER) - error = 0; -out: - git_str_dispose(&buf); - return error; -} - -int git_revwalk_push_glob(git_revwalk *walk, const char *glob) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - - GIT_ASSERT_ARG(walk); - GIT_ASSERT_ARG(glob); - - return git_revwalk__push_glob(walk, glob, &opts); -} - -int git_revwalk_hide_glob(git_revwalk *walk, const char *glob) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - - GIT_ASSERT_ARG(walk); - GIT_ASSERT_ARG(glob); - - opts.uninteresting = 1; - return git_revwalk__push_glob(walk, glob, &opts); -} - -int git_revwalk_push_head(git_revwalk *walk) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - - GIT_ASSERT_ARG(walk); - - return git_revwalk__push_ref(walk, GIT_HEAD_FILE, &opts); -} - -int git_revwalk_hide_head(git_revwalk *walk) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - - GIT_ASSERT_ARG(walk); - - opts.uninteresting = 1; - return git_revwalk__push_ref(walk, GIT_HEAD_FILE, &opts); -} - -int git_revwalk_push_ref(git_revwalk *walk, const char *refname) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - - GIT_ASSERT_ARG(walk); - GIT_ASSERT_ARG(refname); - - return git_revwalk__push_ref(walk, refname, &opts); -} - -int git_revwalk_push_range(git_revwalk *walk, const char *range) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - git_revspec revspec; - int error = 0; - - if ((error = git_revparse(&revspec, walk->repo, range))) - return error; - - if (!revspec.to) { - git_error_set(GIT_ERROR_INVALID, "invalid revspec: range not provided"); - error = GIT_EINVALIDSPEC; - goto out; - } - - if (revspec.flags & GIT_REVSPEC_MERGE_BASE) { - /* TODO: support "..." */ - git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk"); - error = GIT_EINVALIDSPEC; - goto out; - } - - opts.uninteresting = 1; - if ((error = git_revwalk__push_commit(walk, git_object_id(revspec.from), &opts))) - goto out; - - opts.uninteresting = 0; - error = git_revwalk__push_commit(walk, git_object_id(revspec.to), &opts); - -out: - git_object_free(revspec.from); - git_object_free(revspec.to); - return error; -} - -int git_revwalk_hide_ref(git_revwalk *walk, const char *refname) -{ - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - - GIT_ASSERT_ARG(walk); - GIT_ASSERT_ARG(refname); - - opts.uninteresting = 1; - return git_revwalk__push_ref(walk, refname, &opts); -} - -static int revwalk_enqueue_timesort(git_revwalk *walk, git_commit_list_node *commit) -{ - return git_pqueue_insert(&walk->iterator_time, commit); -} - -static int revwalk_enqueue_unsorted(git_revwalk *walk, git_commit_list_node *commit) -{ - return git_commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1; -} - -static int revwalk_next_timesort(git_commit_list_node **object_out, git_revwalk *walk) -{ - git_commit_list_node *next; - - while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) { - /* Some commits might become uninteresting after being added to the list */ - if (!next->uninteresting) { - *object_out = next; - return 0; - } - } - - git_error_clear(); - return GIT_ITEROVER; -} - -static int revwalk_next_unsorted(git_commit_list_node **object_out, git_revwalk *walk) -{ - int error; - git_commit_list_node *next; - - while (!(error = get_revision(&next, walk, &walk->iterator_rand))) { - /* Some commits might become uninteresting after being added to the list */ - if (!next->uninteresting) { - *object_out = next; - return 0; - } - } - - return error; -} - -static int revwalk_next_toposort(git_commit_list_node **object_out, git_revwalk *walk) -{ - int error; - git_commit_list_node *next; - - while (!(error = get_revision(&next, walk, &walk->iterator_topo))) { - /* Some commits might become uninteresting after being added to the list */ - if (!next->uninteresting) { - *object_out = next; - return 0; - } - } - - return error; -} - -static int revwalk_next_reverse(git_commit_list_node **object_out, git_revwalk *walk) -{ - *object_out = git_commit_list_pop(&walk->iterator_reverse); - return *object_out ? 0 : GIT_ITEROVER; -} - -static void mark_parents_uninteresting(git_commit_list_node *commit) -{ - unsigned short i; - git_commit_list *parents = NULL; - - for (i = 0; i < commit->out_degree; i++) - git_commit_list_insert(commit->parents[i], &parents); - - - while (parents) { - commit = git_commit_list_pop(&parents); - - while (commit) { - if (commit->uninteresting) - break; - - commit->uninteresting = 1; - /* - * If we've reached this commit some other way - * already, we need to mark its parents uninteresting - * as well. - */ - if (!commit->parents) - break; - - for (i = 0; i < commit->out_degree; i++) - git_commit_list_insert(commit->parents[i], &parents); - commit = commit->parents[0]; - } - } -} - -static int add_parents_to_list(git_revwalk *walk, git_commit_list_node *commit, git_commit_list **list) -{ - unsigned short i; - int error; - - if (commit->added) - return 0; - - commit->added = 1; - - /* - * Go full on in the uninteresting case as we want to include - * as many of these as we can. - * - * Usually we haven't parsed the parent of a parent, but if we - * have it we reached it via other means so we want to mark - * its parents recursively too. - */ - if (commit->uninteresting) { - for (i = 0; i < commit->out_degree; i++) { - git_commit_list_node *p = commit->parents[i]; - p->uninteresting = 1; - - /* git does it gently here, but we don't like missing objects */ - if ((error = git_commit_list_parse(walk, p)) < 0) - return error; - - if (p->parents) - mark_parents_uninteresting(p); - - p->seen = 1; - git_commit_list_insert_by_date(p, list); - } - - return 0; - } - - /* - * Now on to what we do if the commit is indeed - * interesting. Here we do want things like first-parent take - * effect as this is what we'll be showing. - */ - for (i = 0; i < commit->out_degree; i++) { - git_commit_list_node *p = commit->parents[i]; - - if ((error = git_commit_list_parse(walk, p)) < 0) - return error; - - if (walk->hide_cb && walk->hide_cb(&p->oid, walk->hide_cb_payload)) - continue; - - if (!p->seen) { - p->seen = 1; - git_commit_list_insert_by_date(p, list); - } - - if (walk->first_parent) - break; - } - return 0; -} - -/* How many uninteresting commits we want to look at after we run out of interesting ones */ -#define SLOP 5 - -static int still_interesting(git_commit_list *list, int64_t time, int slop) -{ - /* The empty list is pretty boring */ - if (!list) - return 0; - - /* - * If the destination list has commits with an earlier date than our - * source, we want to reset the slop counter as we're not done. - */ - if (time <= list->item->time) - return SLOP; - - for (; list; list = list->next) { - /* - * If the destination list still contains interesting commits we - * want to continue looking. - */ - if (!list->item->uninteresting || list->item->time > time) - return SLOP; - } - - /* Everything's uninteresting, reduce the count */ - return slop - 1; -} - -static int limit_list(git_commit_list **out, git_revwalk *walk, git_commit_list *commits) -{ - int error, slop = SLOP; - int64_t time = INT64_MAX; - git_commit_list *list = commits; - git_commit_list *newlist = NULL; - git_commit_list **p = &newlist; - - while (list) { - git_commit_list_node *commit = git_commit_list_pop(&list); - - if ((error = add_parents_to_list(walk, commit, &list)) < 0) - return error; - - if (commit->uninteresting) { - mark_parents_uninteresting(commit); - - slop = still_interesting(list, time, slop); - if (slop) - continue; - - break; - } - - if (walk->hide_cb && walk->hide_cb(&commit->oid, walk->hide_cb_payload)) - continue; - - time = commit->time; - p = &git_commit_list_insert(commit, p)->next; - } - - git_commit_list_free(&list); - *out = newlist; - return 0; -} - -static int get_revision(git_commit_list_node **out, git_revwalk *walk, git_commit_list **list) -{ - int error; - git_commit_list_node *commit; - - commit = git_commit_list_pop(list); - if (!commit) { - git_error_clear(); - return GIT_ITEROVER; - } - - /* - * If we did not run limit_list and we must add parents to the - * list ourselves. - */ - if (!walk->limited) { - if ((error = add_parents_to_list(walk, commit, list)) < 0) - return error; - } - - *out = commit; - return 0; -} - -static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk, git_commit_list *list) -{ - git_commit_list *ll = NULL, *newlist, **pptr; - git_commit_list_node *next; - git_pqueue queue; - git_vector_cmp queue_cmp = NULL; - unsigned short i; - int error; - - if (walk->sorting & GIT_SORT_TIME) - queue_cmp = git_commit_list_time_cmp; - - if ((error = git_pqueue_init(&queue, 0, 8, queue_cmp))) - return error; - - /* - * Start by resetting the in-degree to 1 for the commits in - * our list. We want to go through this list again, so we - * store it in the commit list as we extract it from the lower - * machinery. - */ - for (ll = list; ll; ll = ll->next) { - ll->item->in_degree = 1; - } - - /* - * Count up how many children each commit has. We limit - * ourselves to those commits in the original list (in-degree - * of 1) avoiding setting it for any parent that was hidden. - */ - for(ll = list; ll; ll = ll->next) { - for (i = 0; i < ll->item->out_degree; ++i) { - git_commit_list_node *parent = ll->item->parents[i]; - if (parent->in_degree) - parent->in_degree++; - } - } - - /* - * Now we find the tips i.e. those not reachable from any other node - * i.e. those which still have an in-degree of 1. - */ - for(ll = list; ll; ll = ll->next) { - if (ll->item->in_degree == 1) { - if ((error = git_pqueue_insert(&queue, ll->item))) - goto cleanup; - } - } - - /* - * We need to output the tips in the order that they came out of the - * traversal, so if we're not doing time-sorting, we need to reverse the - * pqueue in order to get them to come out as we inserted them. - */ - if ((walk->sorting & GIT_SORT_TIME) == 0) - git_pqueue_reverse(&queue); - - - pptr = &newlist; - newlist = NULL; - while ((next = git_pqueue_pop(&queue)) != NULL) { - for (i = 0; i < next->out_degree; ++i) { - git_commit_list_node *parent = next->parents[i]; - if (parent->in_degree == 0) - continue; - - if (--parent->in_degree == 1) { - if ((error = git_pqueue_insert(&queue, parent))) - goto cleanup; - } - } - - /* All the children of 'item' have been emitted (since we got to it via the priority queue) */ - next->in_degree = 0; - - pptr = &git_commit_list_insert(next, pptr)->next; - } - - *out = newlist; - error = 0; - -cleanup: - git_pqueue_free(&queue); - return error; -} - -static int prepare_walk(git_revwalk *walk) -{ - int error = 0; - git_commit_list *list, *commits = NULL, *commits_last = NULL; - git_commit_list_node *next; - - /* If there were no pushes, we know that the walk is already over */ - if (!walk->did_push) { - git_error_clear(); - return GIT_ITEROVER; - } - - /* - * This is a bit convoluted, but necessary to maintain the order of - * the commits. This is especially important in situations where - * git_revwalk__push_glob is called with a git_revwalk__push_options - * setting insert_by_date = 1, which is critical for fetch negotiation. - */ - for (list = walk->user_input; list; list = list->next) { - git_commit_list_node *commit = list->item; - if ((error = git_commit_list_parse(walk, commit)) < 0) - return error; - - if (commit->uninteresting) - mark_parents_uninteresting(commit); - - if (!commit->seen) { - git_commit_list *new_list = NULL; - if ((new_list = git_commit_list_create(commit, NULL)) == NULL) { - git_error_set_oom(); - return -1; - } - - commit->seen = 1; - if (commits_last == NULL) - commits = new_list; - else - commits_last->next = new_list; - - commits_last = new_list; - } - } - - if (walk->limited && (error = limit_list(&commits, walk, commits)) < 0) - return error; - - if (walk->sorting & GIT_SORT_TOPOLOGICAL) { - error = sort_in_topological_order(&walk->iterator_topo, walk, commits); - git_commit_list_free(&commits); - - if (error < 0) - return error; - - walk->get_next = &revwalk_next_toposort; - } else if (walk->sorting & GIT_SORT_TIME) { - for (list = commits; list && !error; list = list->next) - error = walk->enqueue(walk, list->item); - - git_commit_list_free(&commits); - - if (error < 0) - return error; - } else { - walk->iterator_rand = commits; - walk->get_next = revwalk_next_unsorted; - } - - if (walk->sorting & GIT_SORT_REVERSE) { - - while ((error = walk->get_next(&next, walk)) == 0) - if (git_commit_list_insert(next, &walk->iterator_reverse) == NULL) - return -1; - - if (error != GIT_ITEROVER) - return error; - - walk->get_next = &revwalk_next_reverse; - } - - walk->walking = 1; - return 0; -} - - -int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo) -{ - git_revwalk *walk = git__calloc(1, sizeof(git_revwalk)); - GIT_ERROR_CHECK_ALLOC(walk); - - if (git_pqueue_init(&walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0 || - git_pool_init(&walk->commit_pool, COMMIT_ALLOC) < 0) - return -1; - - walk->get_next = &revwalk_next_unsorted; - walk->enqueue = &revwalk_enqueue_unsorted; - - walk->repo = repo; - - if (git_repository_odb(&walk->odb, repo) < 0) { - git_revwalk_free(walk); - return -1; - } - - *revwalk_out = walk; - return 0; -} - -void git_revwalk_free(git_revwalk *walk) -{ - if (walk == NULL) - return; - - git_revwalk_reset(walk); - git_odb_free(walk->odb); - - git_revwalk_oidmap_dispose(&walk->commits); - git_pool_clear(&walk->commit_pool); - git_pqueue_free(&walk->iterator_time); - git__free(walk); -} - -git_repository *git_revwalk_repository(git_revwalk *walk) -{ - GIT_ASSERT_ARG_WITH_RETVAL(walk, NULL); - - return walk->repo; -} - -int git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode) -{ - GIT_ASSERT_ARG(walk); - - if (walk->walking) - git_revwalk_reset(walk); - - walk->sorting = sort_mode; - - if (walk->sorting & GIT_SORT_TIME) { - walk->get_next = &revwalk_next_timesort; - walk->enqueue = &revwalk_enqueue_timesort; - } else { - walk->get_next = &revwalk_next_unsorted; - walk->enqueue = &revwalk_enqueue_unsorted; - } - - if (walk->sorting != GIT_SORT_NONE) - walk->limited = 1; - - return 0; -} - -int git_revwalk_simplify_first_parent(git_revwalk *walk) -{ - walk->first_parent = 1; - return 0; -} - -int git_revwalk_next(git_oid *oid, git_revwalk *walk) -{ - int error; - git_commit_list_node *next; - - GIT_ASSERT_ARG(walk); - GIT_ASSERT_ARG(oid); - - if (!walk->walking) { - if ((error = prepare_walk(walk)) < 0) - return error; - } - - error = walk->get_next(&next, walk); - - if (error == GIT_ITEROVER) { - git_revwalk_reset(walk); - git_error_clear(); - return GIT_ITEROVER; - } - - if (!error) - git_oid_cpy(oid, &next->oid); - - return error; -} - -int git_revwalk_reset(git_revwalk *walk) -{ - git_commit_list_node *commit; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - GIT_ASSERT_ARG(walk); - - while (git_revwalk_oidmap_iterate(&iter, NULL, &commit, &walk->commits) == 0) { - commit->seen = 0; - commit->in_degree = 0; - commit->topo_delay = 0; - commit->uninteresting = 0; - commit->added = 0; - commit->flags = 0; - } - - git_pqueue_clear(&walk->iterator_time); - git_commit_list_free(&walk->iterator_topo); - git_commit_list_free(&walk->iterator_rand); - git_commit_list_free(&walk->iterator_reverse); - git_commit_list_free(&walk->user_input); - walk->first_parent = 0; - walk->walking = 0; - walk->limited = 0; - walk->did_push = walk->did_hide = 0; - walk->sorting = GIT_SORT_NONE; - - return 0; -} - -int git_revwalk_add_hide_cb( - git_revwalk *walk, - git_revwalk_hide_cb hide_cb, - void *payload) -{ - GIT_ASSERT_ARG(walk); - - if (walk->walking) - git_revwalk_reset(walk); - - walk->hide_cb = hide_cb; - walk->hide_cb_payload = payload; - - if (hide_cb) - walk->limited = 1; - - return 0; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/revwalk.h b/vendor/libgit2-sys/libgit2/src/libgit2/revwalk.h deleted file mode 100644 index 632b280..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/revwalk.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_revwalk_h__ -#define INCLUDE_revwalk_h__ - -#include "common.h" - -#include "git2/revwalk.h" -#include "commit_list.h" -#include "pqueue.h" -#include "pool.h" -#include "vector.h" -#include "hashmap_oid.h" - -GIT_HASHMAP_OID_STRUCT(git_revwalk_oidmap, git_commit_list_node *); - -struct git_revwalk { - git_repository *repo; - git_odb *odb; - - git_revwalk_oidmap commits; - git_pool commit_pool; - - git_commit_list *iterator_topo; - git_commit_list *iterator_rand; - git_commit_list *iterator_reverse; - git_pqueue iterator_time; - - int (*get_next)(git_commit_list_node **, git_revwalk *); - int (*enqueue)(git_revwalk *, git_commit_list_node *); - - unsigned walking:1, - first_parent: 1, - did_hide: 1, - did_push: 1, - limited: 1; - unsigned int sorting; - - /* the pushes and hides */ - git_commit_list *user_input; - - /* hide callback */ - git_revwalk_hide_cb hide_cb; - void *hide_cb_payload; -}; - -git_commit_list_node *git_revwalk__commit_lookup(git_revwalk *walk, const git_oid *oid); - -typedef struct { - int uninteresting; - int from_glob; - int insert_by_date; -} git_revwalk__push_options; - -#define GIT_REVWALK__PUSH_OPTIONS_INIT { 0 } - -int git_revwalk__push_commit(git_revwalk *walk, - const git_oid *oid, - const git_revwalk__push_options *opts); - -int git_revwalk__push_ref(git_revwalk *walk, - const char *refname, - const git_revwalk__push_options *opts); - -int git_revwalk__push_glob(git_revwalk *walk, - const char *glob, - const git_revwalk__push_options *given_opts); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/settings.c b/vendor/libgit2-sys/libgit2/src/libgit2/settings.c deleted file mode 100644 index 7e7ff61..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/settings.c +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "settings.h" - -#include -#include "alloc.h" -#include "buf.h" -#include "cache.h" -#include "common.h" -#include "filter.h" -#include "grafts.h" -#include "hash.h" -#include "index.h" -#include "merge_driver.h" -#include "pool.h" -#include "mwindow.h" -#include "object.h" -#include "odb.h" -#include "rand.h" -#include "refs.h" -#include "runtime.h" -#include "sysdir.h" -#include "thread.h" -#include "git2/global.h" -#include "streams/registry.h" -#include "streams/mbedtls.h" -#include "streams/openssl.h" -#include "streams/socket.h" -#include "transports/smart.h" -#include "transports/http.h" -#include "transports/ssh_libssh2.h" - -#ifdef GIT_WIN32 -# include "win32/w32_leakcheck.h" -#endif - -/* Declarations for tuneable settings */ -extern size_t git_mwindow__window_size; -extern size_t git_mwindow__mapped_limit; -extern size_t git_mwindow__file_limit; -extern size_t git_indexer__max_objects; -extern size_t git_indexer__max_object_size; -extern bool git_disable_pack_keep_file_checks; -extern int git_odb__packed_priority; -extern int git_odb__loose_priority; -extern int git_socket_stream__connect_timeout; -extern int git_socket_stream__timeout; - -char *git__user_agent; -char *git__user_agent_product; -char *git__ssl_ciphers; - -static void settings_global_shutdown(void) -{ - git__free(git__user_agent); - git__free(git__user_agent_product); - - git__free(git__ssl_ciphers); - git_repository__free_extensions(); -} - -int git_settings_global_init(void) -{ - return git_runtime_shutdown_register(settings_global_shutdown); -} - -static int config_level_to_sysdir(int *out, int config_level) -{ - switch (config_level) { - case GIT_CONFIG_LEVEL_SYSTEM: - *out = GIT_SYSDIR_SYSTEM; - return 0; - case GIT_CONFIG_LEVEL_XDG: - *out = GIT_SYSDIR_XDG; - return 0; - case GIT_CONFIG_LEVEL_GLOBAL: - *out = GIT_SYSDIR_GLOBAL; - return 0; - case GIT_CONFIG_LEVEL_PROGRAMDATA: - *out = GIT_SYSDIR_PROGRAMDATA; - return 0; - default: - break; - } - - git_error_set( - GIT_ERROR_INVALID, "invalid config path selector %d", config_level); - return -1; -} - -const char *git_settings__user_agent_product(void) -{ - return git__user_agent_product ? git__user_agent_product : - "git/2.0"; -} - -const char *git_settings__user_agent(void) -{ - return git__user_agent ? git__user_agent : - "libgit2 " LIBGIT2_VERSION; -} - -int git_libgit2_opts(int key, ...) -{ - int error = 0; - va_list ap; - - va_start(ap, key); - - switch (key) { - case GIT_OPT_SET_MWINDOW_SIZE: - git_mwindow__window_size = va_arg(ap, size_t); - break; - - case GIT_OPT_GET_MWINDOW_SIZE: - *(va_arg(ap, size_t *)) = git_mwindow__window_size; - break; - - case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT: - git_mwindow__mapped_limit = va_arg(ap, size_t); - break; - - case GIT_OPT_GET_MWINDOW_MAPPED_LIMIT: - *(va_arg(ap, size_t *)) = git_mwindow__mapped_limit; - break; - - case GIT_OPT_SET_MWINDOW_FILE_LIMIT: - git_mwindow__file_limit = va_arg(ap, size_t); - break; - - case GIT_OPT_GET_MWINDOW_FILE_LIMIT: - *(va_arg(ap, size_t *)) = git_mwindow__file_limit; - break; - - case GIT_OPT_GET_SEARCH_PATH: - { - int sysdir = va_arg(ap, int); - git_buf *out = va_arg(ap, git_buf *); - git_str str = GIT_STR_INIT; - const git_str *tmp; - int level; - - if ((error = git_buf_tostr(&str, out)) < 0 || - (error = config_level_to_sysdir(&level, sysdir)) < 0 || - (error = git_sysdir_get(&tmp, level)) < 0 || - (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0) - break; - - error = git_buf_fromstr(out, &str); - } - break; - - case GIT_OPT_SET_SEARCH_PATH: - { - int level; - - if ((error = config_level_to_sysdir(&level, va_arg(ap, int))) >= 0) - error = git_sysdir_set(level, va_arg(ap, const char *)); - } - break; - - case GIT_OPT_SET_CACHE_OBJECT_LIMIT: - { - git_object_t type = (git_object_t)va_arg(ap, int); - size_t size = va_arg(ap, size_t); - error = git_cache_set_max_object_size(type, size); - break; - } - - case GIT_OPT_SET_CACHE_MAX_SIZE: - git_cache__max_storage = va_arg(ap, ssize_t); - break; - - case GIT_OPT_ENABLE_CACHING: - git_cache__enabled = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_GET_CACHED_MEMORY: - *(va_arg(ap, ssize_t *)) = git_cache__current_storage.val; - *(va_arg(ap, ssize_t *)) = git_cache__max_storage; - break; - - case GIT_OPT_GET_TEMPLATE_PATH: - { - git_buf *out = va_arg(ap, git_buf *); - git_str str = GIT_STR_INIT; - const git_str *tmp; - - if ((error = git_buf_tostr(&str, out)) < 0 || - (error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0 || - (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0) - break; - - error = git_buf_fromstr(out, &str); - } - break; - - case GIT_OPT_SET_TEMPLATE_PATH: - error = git_sysdir_set(GIT_SYSDIR_TEMPLATE, va_arg(ap, const char *)); - break; - - case GIT_OPT_SET_SSL_CERT_LOCATIONS: -#ifdef GIT_OPENSSL - { - const char *file = va_arg(ap, const char *); - const char *path = va_arg(ap, const char *); - error = git_openssl__set_cert_location(file, path); - } -#elif defined(GIT_MBEDTLS) - { - const char *file = va_arg(ap, const char *); - const char *path = va_arg(ap, const char *); - error = git_mbedtls__set_cert_location(file, path); - } -#else - git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support certificate locations"); - error = -1; -#endif - break; - - case GIT_OPT_ADD_SSL_X509_CERT: -#ifdef GIT_OPENSSL - { - X509 *cert = va_arg(ap, X509 *); - error = git_openssl__add_x509_cert(cert); - } -#else - git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support adding of the raw certs"); - error = -1; -#endif - break; - - case GIT_OPT_SET_USER_AGENT: - { - const char *new_agent = va_arg(ap, const char *); - - git__free(git__user_agent); - - if (new_agent) { - git__user_agent= git__strdup(new_agent); - - if (!git__user_agent) - error = -1; - } else { - git__user_agent = NULL; - } - } - break; - - case GIT_OPT_GET_USER_AGENT: - { - git_buf *out = va_arg(ap, git_buf *); - git_str str = GIT_STR_INIT; - - if ((error = git_buf_tostr(&str, out)) < 0 || - (error = git_str_puts(&str, git_settings__user_agent())) < 0) - break; - - error = git_buf_fromstr(out, &str); - } - break; - - case GIT_OPT_SET_USER_AGENT_PRODUCT: - { - const char *new_agent = va_arg(ap, const char *); - - git__free(git__user_agent_product); - - if (new_agent) { - git__user_agent_product = git__strdup(new_agent); - - if (!git__user_agent_product) - error = -1; - } else { - git__user_agent_product = NULL; - } - } - break; - - case GIT_OPT_GET_USER_AGENT_PRODUCT: - { - git_buf *out = va_arg(ap, git_buf *); - git_str str = GIT_STR_INIT; - - if ((error = git_buf_tostr(&str, out)) < 0 || - (error = git_str_puts(&str, git_settings__user_agent_product())) < 0) - break; - - error = git_buf_fromstr(out, &str); - } - break; - - case GIT_OPT_ENABLE_STRICT_OBJECT_CREATION: - git_object__strict_input_validation = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION: - git_reference__enable_symbolic_ref_target_validation = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_SET_SSL_CIPHERS: -#if (GIT_OPENSSL || GIT_MBEDTLS) - { - git__free(git__ssl_ciphers); - git__ssl_ciphers = git__strdup(va_arg(ap, const char *)); - if (!git__ssl_ciphers) { - git_error_set_oom(); - error = -1; - } - } -#else - git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support custom ciphers"); - error = -1; -#endif - break; - - case GIT_OPT_ENABLE_OFS_DELTA: - git_smart__ofs_delta_enabled = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_ENABLE_FSYNC_GITDIR: - git_repository__fsync_gitdir = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_GET_WINDOWS_SHAREMODE: -#ifdef GIT_WIN32 - *(va_arg(ap, unsigned long *)) = git_win32__createfile_sharemode; -#endif - break; - - case GIT_OPT_SET_WINDOWS_SHAREMODE: -#ifdef GIT_WIN32 - git_win32__createfile_sharemode = va_arg(ap, unsigned long); -#endif - break; - - case GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION: - git_odb__strict_hash_verification = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_SET_ALLOCATOR: - error = git_allocator_setup(va_arg(ap, git_allocator *)); - break; - - case GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY: - git_index__enforce_unsaved_safety = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_SET_PACK_MAX_OBJECTS: - git_indexer__max_objects = va_arg(ap, size_t); - break; - - case GIT_OPT_GET_PACK_MAX_OBJECTS: - *(va_arg(ap, size_t *)) = git_indexer__max_objects; - break; - - case GIT_OPT_SET_PACK_MAX_OBJECT_SIZE: - git_indexer__max_object_size = va_arg(ap, size_t); - break; - - case GIT_OPT_GET_PACK_MAX_OBJECT_SIZE: - *(va_arg(ap, size_t *)) = git_indexer__max_object_size; - break; - - case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS: - git_disable_pack_keep_file_checks = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE: - git_http__expect_continue = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_SET_ODB_PACKED_PRIORITY: - git_odb__packed_priority = va_arg(ap, int); - break; - - case GIT_OPT_SET_ODB_LOOSE_PRIORITY: - git_odb__loose_priority = va_arg(ap, int); - break; - - case GIT_OPT_SET_EXTENSIONS: - { - const char **extensions = va_arg(ap, const char **); - size_t len = va_arg(ap, size_t); - error = git_repository__set_extensions(extensions, len); - } - break; - - case GIT_OPT_GET_EXTENSIONS: - { - git_strarray *out = va_arg(ap, git_strarray *); - char **extensions; - size_t len; - - if ((error = git_repository__extensions(&extensions, &len)) < 0) - break; - - out->strings = extensions; - out->count = len; - } - break; - - case GIT_OPT_GET_OWNER_VALIDATION: - *(va_arg(ap, int *)) = git_repository__validate_ownership; - break; - - case GIT_OPT_SET_OWNER_VALIDATION: - git_repository__validate_ownership = (va_arg(ap, int) != 0); - break; - - case GIT_OPT_GET_HOMEDIR: - { - git_buf *out = va_arg(ap, git_buf *); - git_str str = GIT_STR_INIT; - const git_str *tmp; - - if ((error = git_buf_tostr(&str, out)) < 0 || - (error = git_sysdir_get(&tmp, GIT_SYSDIR_HOME)) < 0 || - (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0) - break; - - error = git_buf_fromstr(out, &str); - } - break; - - case GIT_OPT_SET_HOMEDIR: - error = git_sysdir_set(GIT_SYSDIR_HOME, va_arg(ap, const char *)); - break; - - case GIT_OPT_GET_SERVER_CONNECT_TIMEOUT: - *(va_arg(ap, int *)) = git_socket_stream__connect_timeout; - break; - - case GIT_OPT_SET_SERVER_CONNECT_TIMEOUT: - { - int timeout = va_arg(ap, int); - - if (timeout < 0) { - git_error_set(GIT_ERROR_INVALID, "invalid connect timeout"); - error = -1; - } else { - git_socket_stream__connect_timeout = timeout; - } - } - break; - - case GIT_OPT_GET_SERVER_TIMEOUT: - *(va_arg(ap, int *)) = git_socket_stream__timeout; - break; - - case GIT_OPT_SET_SERVER_TIMEOUT: - { - int timeout = va_arg(ap, int); - - if (timeout < 0) { - git_error_set(GIT_ERROR_INVALID, "invalid timeout"); - error = -1; - } else { - git_socket_stream__timeout = timeout; - } - } - break; - - default: - git_error_set(GIT_ERROR_INVALID, "invalid option key"); - error = -1; - } - - va_end(ap); - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/settings.h b/vendor/libgit2-sys/libgit2/src/libgit2/settings.h deleted file mode 100644 index 2929366..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/settings.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_settings_h__ -#define INCLUDE_settings_h__ - -extern int git_settings_global_init(void); - -extern const char *git_settings__user_agent(void); -extern const char *git_settings__user_agent_product(void); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/signature.c b/vendor/libgit2-sys/libgit2/src/libgit2/signature.c deleted file mode 100644 index 71da416..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/signature.c +++ /dev/null @@ -1,456 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "signature.h" - -#include "repository.h" -#include "git2/common.h" -#include "posix.h" -#include "date.h" - -void git_signature_free(git_signature *sig) -{ - if (sig == NULL) - return; - - git__free(sig->name); - sig->name = NULL; - git__free(sig->email); - sig->email = NULL; - git__free(sig); -} - -static int signature_parse_error(const char *msg) -{ - git_error_set(GIT_ERROR_INVALID, "failed to parse signature - %s", msg); - return GIT_EINVALID; -} - -static int signature_error(const char *msg) -{ - git_error_set(GIT_ERROR_INVALID, "failed to parse signature - %s", msg); - return -1; -} - -static bool contains_angle_brackets(const char *input) -{ - return strchr(input, '<') != NULL || strchr(input, '>') != NULL; -} - -static bool is_crud(unsigned char c) -{ - return c <= 32 || - c == ',' || - c == ':' || - c == ';' || - c == '<' || - c == '>' || - c == '"' || - c == '\\' || - c == '\''; -} - -static char *extract_trimmed(const char *ptr, size_t len) -{ - while (len && is_crud((unsigned char)ptr[0])) { - ptr++; len--; - } - - while (len && is_crud((unsigned char)ptr[len - 1])) { - len--; - } - - return git__substrdup(ptr, len); -} - -int git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset) -{ - git_signature *p = NULL; - - GIT_ASSERT_ARG(name); - GIT_ASSERT_ARG(email); - - *sig_out = NULL; - - if (contains_angle_brackets(name) || - contains_angle_brackets(email)) { - return signature_error( - "Neither `name` nor `email` should contain angle brackets chars."); - } - - p = git__calloc(1, sizeof(git_signature)); - GIT_ERROR_CHECK_ALLOC(p); - - p->name = extract_trimmed(name, strlen(name)); - GIT_ERROR_CHECK_ALLOC(p->name); - p->email = extract_trimmed(email, strlen(email)); - GIT_ERROR_CHECK_ALLOC(p->email); - - if (p->name[0] == '\0' || p->email[0] == '\0') { - git_signature_free(p); - return signature_error("Signature cannot have an empty name or email"); - } - - p->when.time = time; - p->when.offset = offset; - p->when.sign = (offset < 0) ? '-' : '+'; - - *sig_out = p; - return 0; -} - -int git_signature_dup(git_signature **dest, const git_signature *source) -{ - git_signature *signature; - - if (source == NULL) - return 0; - - signature = git__calloc(1, sizeof(git_signature)); - GIT_ERROR_CHECK_ALLOC(signature); - - signature->name = git__strdup(source->name); - GIT_ERROR_CHECK_ALLOC(signature->name); - - signature->email = git__strdup(source->email); - GIT_ERROR_CHECK_ALLOC(signature->email); - - signature->when.time = source->when.time; - signature->when.offset = source->when.offset; - signature->when.sign = source->when.sign; - - *dest = signature; - - return 0; -} - -int git_signature__pdup(git_signature **dest, const git_signature *source, git_pool *pool) -{ - git_signature *signature; - - if (source == NULL) - return 0; - - signature = git_pool_mallocz(pool, sizeof(git_signature)); - GIT_ERROR_CHECK_ALLOC(signature); - - signature->name = git_pool_strdup(pool, source->name); - GIT_ERROR_CHECK_ALLOC(signature->name); - - signature->email = git_pool_strdup(pool, source->email); - GIT_ERROR_CHECK_ALLOC(signature->email); - - signature->when.time = source->when.time; - signature->when.offset = source->when.offset; - signature->when.sign = source->when.sign; - - *dest = signature; - - return 0; -} - -static void current_time(time_t *now_out, int *offset_out) -{ - time_t offset; - struct tm _utc, *utc_tm; - - /* - * Get the current time as seconds since the epoch and - * transform that into a tm struct containing the time at - * UTC. Give that to mktime which considers it a local time - * (tm_isdst = -1 asks it to take DST into account) and gives - * us that time as seconds since the epoch. The difference - * between its return value and 'now' is our offset to UTC. - */ - time(now_out); - utc_tm = p_gmtime_r(now_out, &_utc); - utc_tm->tm_isdst = -1; - offset = (time_t)difftime(*now_out, mktime(utc_tm)); - offset /= 60; - - *offset_out = (int)offset; -} - -int git_signature_now( - git_signature **sig_out, - const char *name, - const char *email) -{ - time_t now; - int offset; - - current_time(&now, &offset); - - return git_signature_new(sig_out, name, email, now, offset); -} - -int git_signature_default(git_signature **out, git_repository *repo) -{ - int error; - git_config *cfg; - const char *user_name, *user_email; - - if ((error = git_repository_config_snapshot(&cfg, repo)) < 0) - return error; - - if (!(error = git_config_get_string(&user_name, cfg, "user.name")) && - !(error = git_config_get_string(&user_email, cfg, "user.email"))) - error = git_signature_now(out, user_name, user_email); - - git_config_free(cfg); - return error; -} - -static int user_from_env( - git_signature **out, - git_repository *repo, - const char *name_env_var, - const char *email_env_var, - const char *date_env_var, - time_t default_time, - int default_offset) -{ - int error; - git_config *cfg; - const char *name, *email, *date; - git_time_t timestamp; - int offset; - git_str name_env = GIT_STR_INIT; - git_str email_env = GIT_STR_INIT; - git_str date_env = GIT_STR_INIT; - - if ((error = git_repository_config_snapshot(&cfg, repo)) < 0) - return error; - - /* Check if the environment variable for the name is set */ - if (!(git__getenv(&name_env, name_env_var))) { - name = git_str_cstr(&name_env); - } else { - /* or else read the configuration value. */ - if ((error = git_config_get_string(&name, cfg, "user.name")) < 0) - goto done; - } - - /* Check if the environment variable for the email is set. */ - if (!(git__getenv(&email_env, email_env_var))) { - email = git_str_cstr(&email_env); - } else { - if ((error = git_config_get_string(&email, cfg, "user.email")) == GIT_ENOTFOUND) { - git_error *last_error; - - git_error_save(&last_error); - - if ((error = git__getenv(&email_env, "EMAIL")) < 0) { - git_error_restore(last_error); - error = GIT_ENOTFOUND; - goto done; - } - - email = git_str_cstr(&email_env); - git_error_free(last_error); - } else if (error < 0) { - goto done; - } - } - - /* Check if the environment variable for the timestamp is set */ - if (!(git__getenv(&date_env, date_env_var))) { - date = git_str_cstr(&date_env); - - if ((error = git_date_offset_parse(×tamp, &offset, date)) < 0) - goto done; - } else { - timestamp = default_time; - offset = default_offset; - } - - error = git_signature_new(out, name, email, timestamp, offset); - -done: - git_config_free(cfg); - git_str_dispose(&name_env); - git_str_dispose(&email_env); - git_str_dispose(&date_env); - return error; -} - -int git_signature_default_from_env( - git_signature **author_out, - git_signature **committer_out, - git_repository *repo) -{ - git_signature *author = NULL, *committer = NULL; - time_t now; - int offset; - int error; - - GIT_ASSERT_ARG(author_out || committer_out); - GIT_ASSERT_ARG(repo); - - current_time(&now, &offset); - - if (author_out && - (error = user_from_env(&author, repo, "GIT_AUTHOR_NAME", - "GIT_AUTHOR_EMAIL", "GIT_AUTHOR_DATE", - now, offset)) < 0) - goto on_error; - - if (committer_out && - (error = user_from_env(&committer, repo, "GIT_COMMITTER_NAME", - "GIT_COMMITTER_EMAIL", "GIT_COMMITTER_DATE", - now, offset)) < 0) - goto on_error; - - if (author_out) - *author_out = author; - - if (committer_out) - *committer_out = committer; - - return 0; - -on_error: - git__free(author); - git__free(committer); - return error; -} - -int git_signature__parse(git_signature *sig, const char **buffer_out, - const char *buffer_end, const char *header, char ender) -{ - const char *buffer = *buffer_out; - const char *email_start, *email_end; - - memset(sig, 0, sizeof(git_signature)); - - if (ender && - (buffer_end = memchr(buffer, ender, buffer_end - buffer)) == NULL) - return signature_parse_error("no newline given"); - - if (header) { - const size_t header_len = strlen(header); - - if (buffer + header_len >= buffer_end || memcmp(buffer, header, header_len) != 0) - return signature_parse_error("expected prefix doesn't match actual"); - - buffer += header_len; - } - - email_start = git__memrchr(buffer, '<', buffer_end - buffer); - email_end = git__memrchr(buffer, '>', buffer_end - buffer); - - if (!email_start || !email_end || email_end <= email_start) - return signature_parse_error("malformed e-mail"); - - email_start += 1; - sig->name = extract_trimmed(buffer, email_start - buffer - 1); - sig->email = extract_trimmed(email_start, email_end - email_start); - - /* Do we even have a time at the end of the signature? */ - if (email_end + 2 < buffer_end) { - const char *time_start = email_end + 2; - const char *time_end; - - if (git__strntol64(&sig->when.time, time_start, - buffer_end - time_start, &time_end, 10) < 0) { - git__free(sig->name); - git__free(sig->email); - sig->name = sig->email = NULL; - return signature_parse_error("invalid Unix timestamp"); - } - - /* do we have a timezone? */ - if (time_end + 1 < buffer_end) { - int offset, hours, mins; - const char *tz_start, *tz_end; - - tz_start = time_end + 1; - - if ((tz_start[0] != '-' && tz_start[0] != '+') || - git__strntol32(&offset, tz_start + 1, - buffer_end - tz_start - 1, &tz_end, 10) < 0) { - /* malformed timezone, just assume it's zero */ - offset = 0; - } - - hours = offset / 100; - mins = offset % 100; - - /* - * only store timezone if it's not overflowing; - * see http://www.worldtimezone.com/faq.html - */ - if (hours <= 14 && mins <= 59) { - sig->when.offset = (hours * 60) + mins; - sig->when.sign = tz_start[0]; - if (tz_start[0] == '-') - sig->when.offset = -sig->when.offset; - } - } - } - - *buffer_out = buffer_end + 1; - return 0; -} - -int git_signature_from_buffer(git_signature **out, const char *buf) -{ - git_signature *sig; - const char *buf_end; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(buf); - - *out = NULL; - - sig = git__calloc(1, sizeof(git_signature)); - GIT_ERROR_CHECK_ALLOC(sig); - - buf_end = buf + strlen(buf); - error = git_signature__parse(sig, &buf, buf_end, NULL, '\0'); - - if (error) - git__free(sig); - else - *out = sig; - - return error; -} - -void git_signature__writebuf(git_str *buf, const char *header, const git_signature *sig) -{ - int offset, hours, mins; - char sign; - - offset = sig->when.offset; - sign = (sig->when.offset < 0 || sig->when.sign == '-') ? '-' : '+'; - - if (offset < 0) - offset = -offset; - - hours = offset / 60; - mins = offset % 60; - - git_str_printf(buf, "%s%s <%s> %u %c%02d%02d\n", - header ? header : "", sig->name, sig->email, - (unsigned)sig->when.time, sign, hours, mins); -} - -bool git_signature__equal(const git_signature *one, const git_signature *two) -{ - GIT_ASSERT_ARG(one); - GIT_ASSERT_ARG(two); - - return - git__strcmp(one->name, two->name) == 0 && - git__strcmp(one->email, two->email) == 0 && - one->when.time == two->when.time && - one->when.offset == two->when.offset && - one->when.sign == two->when.sign; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/signature.h b/vendor/libgit2-sys/libgit2/src/libgit2/signature.h deleted file mode 100644 index a5645e9..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/signature.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_signature_h__ -#define INCLUDE_signature_h__ - -#include "common.h" - -#include "git2/common.h" -#include "git2/signature.h" -#include "repository.h" -#include - -int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header, char ender); -void git_signature__writebuf(git_str *buf, const char *header, const git_signature *sig); -bool git_signature__equal(const git_signature *one, const git_signature *two); -int git_signature__pdup(git_signature **dest, const git_signature *source, git_pool *pool); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/stash.c b/vendor/libgit2-sys/libgit2/src/libgit2/stash.c deleted file mode 100644 index b49e95c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/stash.c +++ /dev/null @@ -1,1286 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "repository.h" -#include "commit.h" -#include "tree.h" -#include "reflog.h" -#include "blob.h" -#include "git2/diff.h" -#include "git2/stash.h" -#include "git2/status.h" -#include "git2/checkout.h" -#include "git2/index.h" -#include "git2/transaction.h" -#include "git2/merge.h" -#include "index.h" -#include "signature.h" -#include "iterator.h" -#include "merge.h" -#include "diff.h" -#include "diff_generate.h" -#include "strarray.h" - -static int create_error(int error, const char *msg) -{ - git_error_set(GIT_ERROR_STASH, "cannot stash changes - %s", msg); - return error; -} - -static int retrieve_head(git_reference **out, git_repository *repo) -{ - int error = git_repository_head(out, repo); - - if (error == GIT_EUNBORNBRANCH) - return create_error(error, "you do not have the initial commit yet."); - - return error; -} - -static int append_abbreviated_oid(git_str *out, const git_oid *b_commit) -{ - char *formatted_oid; - - formatted_oid = git_oid_allocfmt(b_commit); - GIT_ERROR_CHECK_ALLOC(formatted_oid); - - git_str_put(out, formatted_oid, 7); - git__free(formatted_oid); - - return git_str_oom(out) ? -1 : 0; -} - -static int append_commit_description(git_str *out, git_commit *commit) -{ - const char *summary = git_commit_summary(commit); - GIT_ERROR_CHECK_ALLOC(summary); - - if (append_abbreviated_oid(out, git_commit_id(commit)) < 0) - return -1; - - git_str_putc(out, ' '); - git_str_puts(out, summary); - git_str_putc(out, '\n'); - - return git_str_oom(out) ? -1 : 0; -} - -static int retrieve_base_commit_and_message( - git_commit **b_commit, - git_str *stash_message, - git_repository *repo) -{ - git_reference *head = NULL; - int error; - - if ((error = retrieve_head(&head, repo)) < 0) - return error; - - if (strcmp("HEAD", git_reference_name(head)) == 0) - error = git_str_puts(stash_message, "(no branch): "); - else - error = git_str_printf( - stash_message, - "%s: ", - git_reference_name(head) + strlen(GIT_REFS_HEADS_DIR)); - if (error < 0) - goto cleanup; - - if ((error = git_commit_lookup( - b_commit, repo, git_reference_target(head))) < 0) - goto cleanup; - - if ((error = append_commit_description(stash_message, *b_commit)) < 0) - goto cleanup; - -cleanup: - git_reference_free(head); - return error; -} - -static int build_tree_from_index( - git_tree **out, - git_repository *repo, - git_index *index) -{ - int error; - git_oid i_tree_oid; - - if ((error = git_index_write_tree_to(&i_tree_oid, index, repo)) < 0) - return error; - - return git_tree_lookup(out, repo, &i_tree_oid); -} - -static int commit_index( - git_commit **i_commit, - git_repository *repo, - git_index *index, - const git_signature *stasher, - const char *message, - const git_commit *parent) -{ - git_tree *i_tree = NULL; - git_oid i_commit_oid; - git_str msg = GIT_STR_INIT; - int error; - - if ((error = build_tree_from_index(&i_tree, repo, index)) < 0) - goto cleanup; - - if ((error = git_str_printf(&msg, "index on %s\n", message)) < 0) - goto cleanup; - - if ((error = git_commit_create( - &i_commit_oid, - git_index_owner(index), - NULL, - stasher, - stasher, - NULL, - git_str_cstr(&msg), - i_tree, - 1, - &parent)) < 0) - goto cleanup; - - error = git_commit_lookup(i_commit, git_index_owner(index), &i_commit_oid); - -cleanup: - git_tree_free(i_tree); - git_str_dispose(&msg); - return error; -} - -struct stash_update_rules { - bool include_changed; - bool include_untracked; - bool include_ignored; -}; - -/* - * Similar to git_index_add_bypath but able to operate on any - * index without making assumptions about the repository's index - */ -static int stash_to_index( - git_repository *repo, - git_index *index, - const char *path) -{ - git_index *repo_index = NULL; - git_index_entry entry = {{0}}; - struct stat st; - int error; - - if (!git_repository_is_bare(repo) && - (error = git_repository_index__weakptr(&repo_index, repo)) < 0) - return error; - - if ((error = git_blob__create_from_paths( - &entry.id, &st, repo, NULL, path, 0, true)) < 0) - return error; - - git_index_entry__init_from_stat(&entry, &st, - (repo_index == NULL || !repo_index->distrust_filemode)); - - entry.path = path; - - return git_index_add(index, &entry); -} - -static int stash_update_index_from_paths( - git_repository *repo, - git_index *index, - const git_strarray *paths) -{ - unsigned int status_flags; - size_t i; - int error = 0; - - for (i = 0; i < paths->count; i++) { - git_status_file(&status_flags, repo, paths->strings[i]); - - if (status_flags & (GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_DELETED)) { - if ((error = git_index_remove(index, paths->strings[i], 0)) < 0) - return error; - } else { - if ((error = stash_to_index(repo, index, paths->strings[i])) < 0) - return error; - } - } - - return error; -} - -static int stash_update_index_from_diff( - git_repository *repo, - git_index *index, - const git_diff *diff, - struct stash_update_rules *data) -{ - int error = 0; - size_t d, max_d = git_diff_num_deltas(diff); - - for (d = 0; !error && d < max_d; ++d) { - const char *add_path = NULL; - const git_diff_delta *delta = git_diff_get_delta(diff, d); - - switch (delta->status) { - case GIT_DELTA_IGNORED: - if (data->include_ignored) - add_path = delta->new_file.path; - break; - - case GIT_DELTA_UNTRACKED: - if (data->include_untracked && - delta->new_file.mode != GIT_FILEMODE_TREE) - add_path = delta->new_file.path; - break; - - case GIT_DELTA_ADDED: - case GIT_DELTA_MODIFIED: - if (data->include_changed) - add_path = delta->new_file.path; - break; - - case GIT_DELTA_DELETED: - if (data->include_changed && - !git_index_find(NULL, index, delta->old_file.path)) - error = git_index_remove(index, delta->old_file.path, 0); - break; - - default: - /* Unimplemented */ - git_error_set( - GIT_ERROR_INVALID, - "cannot update index. Unimplemented status (%d)", - delta->status); - return -1; - } - - if (add_path != NULL) - error = stash_to_index(repo, index, add_path); - } - - return error; -} - -static int build_untracked_tree( - git_tree **tree_out, - git_repository *repo, - git_commit *i_commit, - uint32_t flags) -{ - git_index *i_index = NULL; - git_tree *i_tree = NULL; - git_diff *diff = NULL; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - struct stash_update_rules data = {0}; - int error; - - if ((error = git_index__new(&i_index, repo->oid_type)) < 0) - goto cleanup; - - if (flags & GIT_STASH_INCLUDE_UNTRACKED) { - opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED | - GIT_DIFF_RECURSE_UNTRACKED_DIRS; - data.include_untracked = true; - } - - if (flags & GIT_STASH_INCLUDE_IGNORED) { - opts.flags |= GIT_DIFF_INCLUDE_IGNORED | - GIT_DIFF_RECURSE_IGNORED_DIRS; - data.include_ignored = true; - } - - if ((error = git_commit_tree(&i_tree, i_commit)) < 0) - goto cleanup; - - if ((error = git_diff_tree_to_workdir(&diff, repo, i_tree, &opts)) < 0) - goto cleanup; - - if ((error = stash_update_index_from_diff(repo, i_index, diff, &data)) < 0) - goto cleanup; - - error = build_tree_from_index(tree_out, repo, i_index); - -cleanup: - git_diff_free(diff); - git_tree_free(i_tree); - git_index_free(i_index); - return error; -} - -static int commit_untracked( - git_commit **u_commit, - git_repository *repo, - const git_signature *stasher, - const char *message, - git_commit *i_commit, - uint32_t flags) -{ - git_tree *u_tree = NULL; - git_oid u_commit_oid; - git_str msg = GIT_STR_INIT; - int error; - - if ((error = build_untracked_tree(&u_tree, repo, i_commit, flags)) < 0) - goto cleanup; - - if ((error = git_str_printf(&msg, "untracked files on %s\n", message)) < 0) - goto cleanup; - - if ((error = git_commit_create( - &u_commit_oid, - repo, - NULL, - stasher, - stasher, - NULL, - git_str_cstr(&msg), - u_tree, - 0, - NULL)) < 0) - goto cleanup; - - error = git_commit_lookup(u_commit, repo, &u_commit_oid); - -cleanup: - git_tree_free(u_tree); - git_str_dispose(&msg); - return error; -} - -static git_diff_delta *stash_delta_merge( - const git_diff_delta *a, - const git_diff_delta *b, - git_pool *pool) -{ - /* Special case for stash: if a file is deleted in the index, but exists - * in the working tree, we need to stash the workdir copy for the workdir. - */ - if (a->status == GIT_DELTA_DELETED && b->status == GIT_DELTA_UNTRACKED) { - git_diff_delta *dup = git_diff__delta_dup(b, pool); - - if (dup) - dup->status = GIT_DELTA_MODIFIED; - return dup; - } - - return git_diff__merge_like_cgit(a, b, pool); -} - -static int build_workdir_tree( - git_tree **tree_out, - git_repository *repo, - git_index *i_index, - git_commit *b_commit) -{ - git_tree *b_tree = NULL; - git_diff *diff = NULL, *idx_to_wd = NULL; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - struct stash_update_rules data = {0}; - int error; - - opts.flags = GIT_DIFF_IGNORE_SUBMODULES | GIT_DIFF_INCLUDE_UNTRACKED; - - if ((error = git_commit_tree(&b_tree, b_commit)) < 0) - goto cleanup; - - if ((error = git_diff_tree_to_index(&diff, repo, b_tree, i_index, &opts)) < 0 || - (error = git_diff_index_to_workdir(&idx_to_wd, repo, i_index, &opts)) < 0 || - (error = git_diff__merge(diff, idx_to_wd, stash_delta_merge)) < 0) - goto cleanup; - - data.include_changed = true; - - if ((error = stash_update_index_from_diff(repo, i_index, diff, &data)) < 0) - goto cleanup; - - error = build_tree_from_index(tree_out, repo, i_index); - -cleanup: - git_diff_free(idx_to_wd); - git_diff_free(diff); - git_tree_free(b_tree); - - return error; -} - -static int build_stash_commit_from_tree( - git_oid *w_commit_oid, - git_repository *repo, - const git_signature *stasher, - const char *message, - git_commit *i_commit, - git_commit *b_commit, - git_commit *u_commit, - const git_tree *tree) -{ - const git_commit *parents[] = { NULL, NULL, NULL }; - - parents[0] = b_commit; - parents[1] = i_commit; - parents[2] = u_commit; - - return git_commit_create( - w_commit_oid, - repo, - NULL, - stasher, - stasher, - NULL, - message, - tree, - u_commit ? 3 : 2, - parents); -} - -static int build_stash_commit_from_index( - git_oid *w_commit_oid, - git_repository *repo, - const git_signature *stasher, - const char *message, - git_commit *i_commit, - git_commit *b_commit, - git_commit *u_commit, - git_index *index) -{ - git_tree *tree; - int error; - - if ((error = build_tree_from_index(&tree, repo, index)) < 0) - goto cleanup; - - error = build_stash_commit_from_tree( - w_commit_oid, - repo, - stasher, - message, - i_commit, - b_commit, - u_commit, - tree); - -cleanup: - git_tree_free(tree); - return error; -} - -static int commit_worktree( - git_oid *w_commit_oid, - git_repository *repo, - const git_signature *stasher, - const char *message, - git_commit *i_commit, - git_commit *b_commit, - git_commit *u_commit) -{ - git_index *i_index = NULL, *r_index = NULL; - git_tree *w_tree = NULL; - int error = 0, ignorecase; - - if ((error = git_repository_index(&r_index, repo) < 0) || - (error = git_index__new(&i_index, repo->oid_type)) < 0 || - (error = git_index__fill(i_index, &r_index->entries) < 0) || - (error = git_repository__configmap_lookup(&ignorecase, repo, GIT_CONFIGMAP_IGNORECASE)) < 0) - goto cleanup; - - git_index__set_ignore_case(i_index, ignorecase); - - if ((error = build_workdir_tree(&w_tree, repo, i_index, b_commit)) < 0) - goto cleanup; - - error = build_stash_commit_from_tree( - w_commit_oid, - repo, - stasher, - message, - i_commit, - b_commit, - u_commit, - w_tree - ); - -cleanup: - git_tree_free(w_tree); - git_index_free(i_index); - git_index_free(r_index); - return error; -} - -static int prepare_worktree_commit_message(git_str *out, const char *user_message) -{ - git_str buf = GIT_STR_INIT; - int error = 0; - - if (!user_message) { - git_str_printf(&buf, "WIP on %s", git_str_cstr(out)); - } else { - const char *colon; - - if ((colon = strchr(git_str_cstr(out), ':')) == NULL) - goto cleanup; - - git_str_puts(&buf, "On "); - git_str_put(&buf, git_str_cstr(out), colon - out->ptr); - git_str_printf(&buf, ": %s\n", user_message); - } - - if (git_str_oom(&buf)) { - error = -1; - goto cleanup; - } - - git_str_swap(out, &buf); - -cleanup: - git_str_dispose(&buf); - return error; -} - -static int update_reflog( - git_oid *w_commit_oid, - git_repository *repo, - const char *message) -{ - git_reference *stash; - int error; - - if ((error = git_reference_ensure_log(repo, GIT_REFS_STASH_FILE)) < 0) - return error; - - error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, message); - - git_reference_free(stash); - - return error; -} - -static int is_dirty_cb(const char *path, unsigned int status, void *payload) -{ - GIT_UNUSED(path); - GIT_UNUSED(status); - GIT_UNUSED(payload); - - return GIT_PASSTHROUGH; -} - -static int ensure_there_are_changes_to_stash(git_repository *repo, uint32_t flags) -{ - int error; - git_status_options opts = GIT_STATUS_OPTIONS_INIT; - - opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; - opts.flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES; - - if (flags & GIT_STASH_INCLUDE_UNTRACKED) - opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED | - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; - - if (flags & GIT_STASH_INCLUDE_IGNORED) - opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED | - GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; - - error = git_status_foreach_ext(repo, &opts, is_dirty_cb, NULL); - - if (error == GIT_PASSTHROUGH) - return 0; - - if (!error) - return create_error(GIT_ENOTFOUND, "there is nothing to stash."); - - return error; -} - -static int has_changes_cb( - const char *path, - unsigned int status, - void *payload) -{ - GIT_UNUSED(path); - GIT_UNUSED(status); - GIT_UNUSED(payload); - - if (status == GIT_STATUS_CURRENT) - return GIT_ENOTFOUND; - - return 0; -} - -static int ensure_there_are_changes_to_stash_paths( - git_repository *repo, - uint32_t flags, - const git_strarray *paths) -{ - int error; - git_status_options opts = GIT_STATUS_OPTIONS_INIT; - - opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; - opts.flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES | - GIT_STATUS_OPT_INCLUDE_UNMODIFIED | - GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH; - - if (flags & GIT_STASH_INCLUDE_UNTRACKED) - opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED | - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; - - if (flags & GIT_STASH_INCLUDE_IGNORED) - opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED | - GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; - - git_strarray_copy(&opts.pathspec, paths); - - error = git_status_foreach_ext(repo, &opts, has_changes_cb, NULL); - - git_strarray_dispose(&opts.pathspec); - - if (error == GIT_ENOTFOUND) - return create_error(GIT_ENOTFOUND, "one of the files does not have any changes to stash."); - - return error; -} - -static int reset_index_and_workdir(git_repository *repo, git_commit *commit, uint32_t flags) -{ - git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; - - opts.checkout_strategy = GIT_CHECKOUT_FORCE; - if (flags & GIT_STASH_INCLUDE_UNTRACKED) - opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_UNTRACKED; - if (flags & GIT_STASH_INCLUDE_IGNORED) - opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_IGNORED; - - return git_checkout_tree(repo, (git_object *)commit, &opts); -} - -int git_stash_save( - git_oid *out, - git_repository *repo, - const git_signature *stasher, - const char *message, - uint32_t flags) -{ - git_stash_save_options opts = GIT_STASH_SAVE_OPTIONS_INIT; - - GIT_ASSERT_ARG(stasher); - - opts.stasher = stasher; - opts.message = message; - opts.flags = flags; - - return git_stash_save_with_opts(out, repo, &opts); -} - -int git_stash_save_with_opts( - git_oid *out, - git_repository *repo, - const git_stash_save_options *opts) -{ - git_index *index = NULL, *paths_index = NULL; - git_commit *b_commit = NULL, *i_commit = NULL, *u_commit = NULL; - git_str msg = GIT_STR_INIT; - git_tree *tree = NULL; - git_reference *head = NULL; - bool has_paths = false; - - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(opts && opts->stasher); - - has_paths = opts->paths.count > 0; - - if ((error = git_repository__ensure_not_bare(repo, "stash save")) < 0) - return error; - - if ((error = retrieve_base_commit_and_message(&b_commit, &msg, repo)) < 0) - goto cleanup; - - if (!has_paths && - (error = ensure_there_are_changes_to_stash(repo, opts->flags)) < 0) - goto cleanup; - else if (has_paths && - (error = ensure_there_are_changes_to_stash_paths( - repo, opts->flags, &opts->paths)) < 0) - goto cleanup; - - if ((error = git_repository_index(&index, repo)) < 0) - goto cleanup; - - if ((error = commit_index(&i_commit, repo, index, opts->stasher, - git_str_cstr(&msg), b_commit)) < 0) - goto cleanup; - - if ((opts->flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) && - (error = commit_untracked(&u_commit, repo, opts->stasher, - git_str_cstr(&msg), i_commit, opts->flags)) < 0) - goto cleanup; - - if ((error = prepare_worktree_commit_message(&msg, opts->message)) < 0) - goto cleanup; - - if (!has_paths) { - if ((error = commit_worktree(out, repo, opts->stasher, git_str_cstr(&msg), - i_commit, b_commit, u_commit)) < 0) - goto cleanup; - } else { - if ((error = git_index__new(&paths_index, repo->oid_type)) < 0 || - (error = retrieve_head(&head, repo)) < 0 || - (error = git_reference_peel((git_object**)&tree, head, GIT_OBJECT_TREE)) < 0 || - (error = git_index_read_tree(paths_index, tree)) < 0 || - (error = stash_update_index_from_paths(repo, paths_index, &opts->paths)) < 0 || - (error = build_stash_commit_from_index(out, repo, opts->stasher, git_str_cstr(&msg), - i_commit, b_commit, u_commit, paths_index)) < 0) - goto cleanup; - } - - git_str_rtrim(&msg); - - if ((error = update_reflog(out, repo, git_str_cstr(&msg))) < 0) - goto cleanup; - - if (!(opts->flags & GIT_STASH_KEEP_ALL) && - (error = reset_index_and_workdir(repo, - (opts->flags & GIT_STASH_KEEP_INDEX) ? i_commit : b_commit,opts->flags)) < 0) - goto cleanup; - -cleanup: - git_str_dispose(&msg); - git_commit_free(i_commit); - git_commit_free(b_commit); - git_commit_free(u_commit); - git_tree_free(tree); - git_reference_free(head); - git_index_free(index); - git_index_free(paths_index); - - return error; -} - -static int retrieve_stash_commit( - git_commit **commit, - git_repository *repo, - size_t index) -{ - git_reference *stash = NULL; - git_reflog *reflog = NULL; - int error; - size_t max; - const git_reflog_entry *entry; - - if ((error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)) < 0) - goto cleanup; - - if ((error = git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE)) < 0) - goto cleanup; - - max = git_reflog_entrycount(reflog); - if (!max || index > max - 1) { - error = GIT_ENOTFOUND; - git_error_set(GIT_ERROR_STASH, "no stashed state at position %" PRIuZ, index); - goto cleanup; - } - - entry = git_reflog_entry_byindex(reflog, index); - if ((error = git_commit_lookup(commit, repo, git_reflog_entry_id_new(entry))) < 0) - goto cleanup; - -cleanup: - git_reference_free(stash); - git_reflog_free(reflog); - return error; -} - -static int retrieve_stash_trees( - git_tree **out_stash_tree, - git_tree **out_base_tree, - git_tree **out_index_tree, - git_tree **out_index_parent_tree, - git_tree **out_untracked_tree, - git_commit *stash_commit) -{ - git_tree *stash_tree = NULL; - git_commit *base_commit = NULL; - git_tree *base_tree = NULL; - git_commit *index_commit = NULL; - git_tree *index_tree = NULL; - git_commit *index_parent_commit = NULL; - git_tree *index_parent_tree = NULL; - git_commit *untracked_commit = NULL; - git_tree *untracked_tree = NULL; - int error; - - if ((error = git_commit_tree(&stash_tree, stash_commit)) < 0) - goto cleanup; - - if ((error = git_commit_parent(&base_commit, stash_commit, 0)) < 0) - goto cleanup; - if ((error = git_commit_tree(&base_tree, base_commit)) < 0) - goto cleanup; - - if ((error = git_commit_parent(&index_commit, stash_commit, 1)) < 0) - goto cleanup; - if ((error = git_commit_tree(&index_tree, index_commit)) < 0) - goto cleanup; - - if ((error = git_commit_parent(&index_parent_commit, index_commit, 0)) < 0) - goto cleanup; - if ((error = git_commit_tree(&index_parent_tree, index_parent_commit)) < 0) - goto cleanup; - - if (git_commit_parentcount(stash_commit) == 3) { - if ((error = git_commit_parent(&untracked_commit, stash_commit, 2)) < 0) - goto cleanup; - if ((error = git_commit_tree(&untracked_tree, untracked_commit)) < 0) - goto cleanup; - } - - *out_stash_tree = stash_tree; - *out_base_tree = base_tree; - *out_index_tree = index_tree; - *out_index_parent_tree = index_parent_tree; - *out_untracked_tree = untracked_tree; - -cleanup: - git_commit_free(untracked_commit); - git_commit_free(index_parent_commit); - git_commit_free(index_commit); - git_commit_free(base_commit); - if (error < 0) { - git_tree_free(stash_tree); - git_tree_free(base_tree); - git_tree_free(index_tree); - git_tree_free(index_parent_tree); - git_tree_free(untracked_tree); - } - return error; -} - -static int merge_indexes( - git_index **out, - git_repository *repo, - git_tree *ancestor_tree, - git_index *ours_index, - git_index *theirs_index) -{ - git_iterator *ancestor = NULL, *ours = NULL, *theirs = NULL; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - int error; - - iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; - - if ((error = git_iterator_for_tree(&ancestor, ancestor_tree, &iter_opts)) < 0 || - (error = git_iterator_for_index(&ours, repo, ours_index, &iter_opts)) < 0 || - (error = git_iterator_for_index(&theirs, repo, theirs_index, &iter_opts)) < 0) - goto done; - - error = git_merge__iterators(out, repo, ancestor, ours, theirs, NULL); - -done: - git_iterator_free(ancestor); - git_iterator_free(ours); - git_iterator_free(theirs); - return error; -} - -static int merge_index_and_tree( - git_index **out, - git_repository *repo, - git_tree *ancestor_tree, - git_index *ours_index, - git_tree *theirs_tree) -{ - git_iterator *ancestor = NULL, *ours = NULL, *theirs = NULL; - git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - int error; - - iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; - - if ((error = git_iterator_for_tree(&ancestor, ancestor_tree, &iter_opts)) < 0 || - (error = git_iterator_for_index(&ours, repo, ours_index, &iter_opts)) < 0 || - (error = git_iterator_for_tree(&theirs, theirs_tree, &iter_opts)) < 0) - goto done; - - error = git_merge__iterators(out, repo, ancestor, ours, theirs, NULL); - -done: - git_iterator_free(ancestor); - git_iterator_free(ours); - git_iterator_free(theirs); - return error; -} - -static void normalize_apply_options( - git_stash_apply_options *opts, - const git_stash_apply_options *given_apply_opts) -{ - if (given_apply_opts != NULL) { - memcpy(opts, given_apply_opts, sizeof(git_stash_apply_options)); - } else { - git_stash_apply_options default_apply_opts = GIT_STASH_APPLY_OPTIONS_INIT; - memcpy(opts, &default_apply_opts, sizeof(git_stash_apply_options)); - } - - opts->checkout_options.checkout_strategy |= GIT_CHECKOUT_NO_REFRESH; - - if (!opts->checkout_options.our_label) - opts->checkout_options.our_label = "Updated upstream"; - - if (!opts->checkout_options.their_label) - opts->checkout_options.their_label = "Stashed changes"; -} - -int git_stash_apply_options_init(git_stash_apply_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_stash_apply_options, GIT_STASH_APPLY_OPTIONS_INIT); - return 0; -} - -int git_stash_save_options_init(git_stash_save_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_stash_save_options, GIT_STASH_SAVE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_stash_apply_init_options(git_stash_apply_options *opts, unsigned int version) -{ - return git_stash_apply_options_init(opts, version); -} -#endif - -#define NOTIFY_PROGRESS(opts, progress_type) \ - do { \ - if ((opts).progress_cb && \ - (error = (opts).progress_cb((progress_type), (opts).progress_payload))) { \ - error = (error < 0) ? error : -1; \ - goto cleanup; \ - } \ - } while(false); - -static int ensure_clean_index(git_repository *repo, git_index *index) -{ - git_tree *head_tree = NULL; - git_diff *index_diff = NULL; - int error = 0; - - if ((error = git_repository_head_tree(&head_tree, repo)) < 0 || - (error = git_diff_tree_to_index( - &index_diff, repo, head_tree, index, NULL)) < 0) - goto done; - - if (git_diff_num_deltas(index_diff) > 0) { - git_error_set(GIT_ERROR_STASH, "%" PRIuZ " uncommitted changes exist in the index", - git_diff_num_deltas(index_diff)); - error = GIT_EUNCOMMITTED; - } - -done: - git_diff_free(index_diff); - git_tree_free(head_tree); - return error; -} - -static int stage_new_file(const git_index_entry **entries, void *data) -{ - git_index *index = data; - - if(entries[0] == NULL) - return git_index_add(index, entries[1]); - else - return git_index_add(index, entries[0]); -} - -static int stage_new_files( - git_index **out, - git_repository *repo, - git_tree *parent_tree, - git_tree *tree) -{ - git_iterator *iterators[2] = { NULL, NULL }; - git_iterator_options iterator_options = GIT_ITERATOR_OPTIONS_INIT; - git_index *index = NULL; - int error; - - if ((error = git_index__new(&index, repo->oid_type)) < 0 || - (error = git_iterator_for_tree( - &iterators[0], parent_tree, &iterator_options)) < 0 || - (error = git_iterator_for_tree( - &iterators[1], tree, &iterator_options)) < 0) - goto done; - - error = git_iterator_walk(iterators, 2, stage_new_file, index); - -done: - if (error < 0) - git_index_free(index); - else - *out = index; - - git_iterator_free(iterators[0]); - git_iterator_free(iterators[1]); - - return error; -} - -int git_stash_apply( - git_repository *repo, - size_t index, - const git_stash_apply_options *given_opts) -{ - git_stash_apply_options opts; - unsigned int checkout_strategy; - git_commit *stash_commit = NULL; - git_tree *stash_tree = NULL; - git_tree *stash_parent_tree = NULL; - git_tree *index_tree = NULL; - git_tree *index_parent_tree = NULL; - git_tree *untracked_tree = NULL; - git_index *stash_adds = NULL; - git_index *repo_index = NULL; - git_index *unstashed_index = NULL; - git_index *modified_index = NULL; - git_index *untracked_index = NULL; - int error; - - GIT_ERROR_CHECK_VERSION(given_opts, GIT_STASH_APPLY_OPTIONS_VERSION, "git_stash_apply_options"); - - normalize_apply_options(&opts, given_opts); - checkout_strategy = opts.checkout_options.checkout_strategy; - - NOTIFY_PROGRESS(opts, GIT_STASH_APPLY_PROGRESS_LOADING_STASH); - - /* Retrieve commit corresponding to the given stash */ - if ((error = retrieve_stash_commit(&stash_commit, repo, index)) < 0) - goto cleanup; - - /* Retrieve all trees in the stash */ - if ((error = retrieve_stash_trees( - &stash_tree, &stash_parent_tree, &index_tree, - &index_parent_tree, &untracked_tree, stash_commit)) < 0) - goto cleanup; - - /* Load repo index */ - if ((error = git_repository_index(&repo_index, repo)) < 0) - goto cleanup; - - NOTIFY_PROGRESS(opts, GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX); - - if ((error = ensure_clean_index(repo, repo_index)) < 0) - goto cleanup; - - /* Restore index if required */ - if ((opts.flags & GIT_STASH_APPLY_REINSTATE_INDEX) && - git_oid_cmp(git_tree_id(stash_parent_tree), git_tree_id(index_tree))) { - - if ((error = merge_index_and_tree( - &unstashed_index, repo, index_parent_tree, repo_index, index_tree)) < 0) - goto cleanup; - - if (git_index_has_conflicts(unstashed_index)) { - error = GIT_ECONFLICT; - goto cleanup; - } - - /* Otherwise, stage any new files in the stash tree. (Note: their - * previously unstaged contents are staged, not the previously staged.) - */ - } else if ((opts.flags & GIT_STASH_APPLY_REINSTATE_INDEX) == 0) { - if ((error = stage_new_files(&stash_adds, repo, - stash_parent_tree, stash_tree)) < 0 || - (error = merge_indexes(&unstashed_index, repo, - stash_parent_tree, repo_index, stash_adds)) < 0) - goto cleanup; - } - - NOTIFY_PROGRESS(opts, GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED); - - /* Restore modified files in workdir */ - if ((error = merge_index_and_tree( - &modified_index, repo, stash_parent_tree, repo_index, stash_tree)) < 0) - goto cleanup; - - /* If applicable, restore untracked / ignored files in workdir */ - if (untracked_tree) { - NOTIFY_PROGRESS(opts, GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED); - - if ((error = merge_index_and_tree(&untracked_index, repo, NULL, repo_index, untracked_tree)) < 0) - goto cleanup; - } - - if (untracked_index) { - opts.checkout_options.checkout_strategy |= GIT_CHECKOUT_DONT_UPDATE_INDEX; - - NOTIFY_PROGRESS(opts, GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED); - - if ((error = git_checkout_index(repo, untracked_index, &opts.checkout_options)) < 0) - goto cleanup; - - opts.checkout_options.checkout_strategy = checkout_strategy; - } - - - /* If there are conflicts in the modified index, then we need to actually - * check that out as the repo's index. Otherwise, we don't update the - * index. - */ - - if (!git_index_has_conflicts(modified_index)) - opts.checkout_options.checkout_strategy |= GIT_CHECKOUT_DONT_UPDATE_INDEX; - - /* Check out the modified index using the existing repo index as baseline, - * so that existing modifications in the index can be rewritten even when - * checking out safely. - */ - opts.checkout_options.baseline_index = repo_index; - - NOTIFY_PROGRESS(opts, GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED); - - if ((error = git_checkout_index(repo, modified_index, &opts.checkout_options)) < 0) - goto cleanup; - - if (unstashed_index && !git_index_has_conflicts(modified_index)) { - if ((error = git_index_read_index(repo_index, unstashed_index)) < 0) - goto cleanup; - } - - NOTIFY_PROGRESS(opts, GIT_STASH_APPLY_PROGRESS_DONE); - - error = git_index_write(repo_index); - -cleanup: - git_index_free(untracked_index); - git_index_free(modified_index); - git_index_free(unstashed_index); - git_index_free(stash_adds); - git_index_free(repo_index); - git_tree_free(untracked_tree); - git_tree_free(index_parent_tree); - git_tree_free(index_tree); - git_tree_free(stash_parent_tree); - git_tree_free(stash_tree); - git_commit_free(stash_commit); - return error; -} - -int git_stash_foreach( - git_repository *repo, - git_stash_cb callback, - void *payload) -{ - git_reference *stash; - git_reflog *reflog = NULL; - int error; - size_t i, max; - const git_reflog_entry *entry; - - error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE); - if (error == GIT_ENOTFOUND) { - git_error_clear(); - return 0; - } - if (error < 0) - goto cleanup; - - if ((error = git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE)) < 0) - goto cleanup; - - max = git_reflog_entrycount(reflog); - for (i = 0; i < max; i++) { - entry = git_reflog_entry_byindex(reflog, i); - - error = callback(i, - git_reflog_entry_message(entry), - git_reflog_entry_id_new(entry), - payload); - - if (error) { - git_error_set_after_callback(error); - break; - } - } - -cleanup: - git_reference_free(stash); - git_reflog_free(reflog); - return error; -} - -int git_stash_drop( - git_repository *repo, - size_t index) -{ - git_transaction *tx; - git_reference *stash = NULL; - git_reflog *reflog = NULL; - size_t max; - int error; - - if ((error = git_transaction_new(&tx, repo)) < 0) - return error; - - if ((error = git_transaction_lock_ref(tx, GIT_REFS_STASH_FILE)) < 0) - goto cleanup; - - if ((error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)) < 0) - goto cleanup; - - if ((error = git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE)) < 0) - goto cleanup; - - max = git_reflog_entrycount(reflog); - - if (!max || index > max - 1) { - error = GIT_ENOTFOUND; - git_error_set(GIT_ERROR_STASH, "no stashed state at position %" PRIuZ, index); - goto cleanup; - } - - if ((error = git_reflog_drop(reflog, index, true)) < 0) - goto cleanup; - - if ((error = git_transaction_set_reflog(tx, GIT_REFS_STASH_FILE, reflog)) < 0) - goto cleanup; - - if (max == 1) { - if ((error = git_transaction_remove(tx, GIT_REFS_STASH_FILE)) < 0) - goto cleanup; - } else if (index == 0) { - const git_reflog_entry *entry; - - entry = git_reflog_entry_byindex(reflog, 0); - if ((error = git_transaction_set_target(tx, GIT_REFS_STASH_FILE, &entry->oid_cur, NULL, NULL)) < 0) - goto cleanup; - } - - error = git_transaction_commit(tx); - -cleanup: - git_reference_free(stash); - git_transaction_free(tx); - git_reflog_free(reflog); - return error; -} - -int git_stash_pop( - git_repository *repo, - size_t index, - const git_stash_apply_options *options) -{ - int error; - - if ((error = git_stash_apply(repo, index, options)) < 0) - return error; - - return git_stash_drop(repo, index); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/status.c b/vendor/libgit2-sys/libgit2/src/libgit2/status.c deleted file mode 100644 index 06356ad..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/status.c +++ /dev/null @@ -1,584 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "status.h" - -#include "git2.h" -#include "futils.h" -#include "hash.h" -#include "vector.h" -#include "tree.h" -#include "git2/status.h" -#include "repository.h" -#include "ignore.h" -#include "index.h" -#include "wildmatch.h" - -#include "git2/diff.h" -#include "diff.h" -#include "diff_generate.h" - -static unsigned int index_delta2status(const git_diff_delta *head2idx) -{ - git_status_t st = GIT_STATUS_CURRENT; - - switch (head2idx->status) { - case GIT_DELTA_ADDED: - case GIT_DELTA_COPIED: - st = GIT_STATUS_INDEX_NEW; - break; - case GIT_DELTA_DELETED: - st = GIT_STATUS_INDEX_DELETED; - break; - case GIT_DELTA_MODIFIED: - st = GIT_STATUS_INDEX_MODIFIED; - break; - case GIT_DELTA_RENAMED: - st = GIT_STATUS_INDEX_RENAMED; - - if (!git_oid_equal(&head2idx->old_file.id, &head2idx->new_file.id)) - st |= GIT_STATUS_INDEX_MODIFIED; - break; - case GIT_DELTA_TYPECHANGE: - st = GIT_STATUS_INDEX_TYPECHANGE; - break; - case GIT_DELTA_CONFLICTED: - st = GIT_STATUS_CONFLICTED; - break; - default: - break; - } - - return st; -} - -static unsigned int workdir_delta2status( - git_diff *diff, git_diff_delta *idx2wd) -{ - git_status_t st = GIT_STATUS_CURRENT; - - switch (idx2wd->status) { - case GIT_DELTA_ADDED: - case GIT_DELTA_COPIED: - case GIT_DELTA_UNTRACKED: - st = GIT_STATUS_WT_NEW; - break; - case GIT_DELTA_UNREADABLE: - st = GIT_STATUS_WT_UNREADABLE; - break; - case GIT_DELTA_DELETED: - st = GIT_STATUS_WT_DELETED; - break; - case GIT_DELTA_MODIFIED: - st = GIT_STATUS_WT_MODIFIED; - break; - case GIT_DELTA_IGNORED: - st = GIT_STATUS_IGNORED; - break; - case GIT_DELTA_RENAMED: - st = GIT_STATUS_WT_RENAMED; - - if (!git_oid_equal(&idx2wd->old_file.id, &idx2wd->new_file.id)) { - /* if OIDs don't match, we might need to calculate them now to - * discern between RENAMED vs RENAMED+MODIFIED - */ - if (git_oid_is_zero(&idx2wd->old_file.id) && - diff->old_src == GIT_ITERATOR_WORKDIR && - !git_diff__oid_for_file( - &idx2wd->old_file.id, diff, idx2wd->old_file.path, - idx2wd->old_file.mode, idx2wd->old_file.size)) - idx2wd->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; - - if (git_oid_is_zero(&idx2wd->new_file.id) && - diff->new_src == GIT_ITERATOR_WORKDIR && - !git_diff__oid_for_file( - &idx2wd->new_file.id, diff, idx2wd->new_file.path, - idx2wd->new_file.mode, idx2wd->new_file.size)) - idx2wd->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; - - if (!git_oid_equal(&idx2wd->old_file.id, &idx2wd->new_file.id)) - st |= GIT_STATUS_WT_MODIFIED; - } - break; - case GIT_DELTA_TYPECHANGE: - st = GIT_STATUS_WT_TYPECHANGE; - break; - case GIT_DELTA_CONFLICTED: - st = GIT_STATUS_CONFLICTED; - break; - default: - break; - } - - return st; -} - -static bool status_is_included( - git_status_list *status, - git_diff_delta *head2idx, - git_diff_delta *idx2wd) -{ - if (!(status->opts.flags & GIT_STATUS_OPT_EXCLUDE_SUBMODULES)) - return 1; - - /* if excluding submodules and this is a submodule everywhere */ - if (head2idx) { - if (head2idx->status != GIT_DELTA_ADDED && - head2idx->old_file.mode != GIT_FILEMODE_COMMIT) - return 1; - if (head2idx->status != GIT_DELTA_DELETED && - head2idx->new_file.mode != GIT_FILEMODE_COMMIT) - return 1; - } - if (idx2wd) { - if (idx2wd->status != GIT_DELTA_ADDED && - idx2wd->old_file.mode != GIT_FILEMODE_COMMIT) - return 1; - if (idx2wd->status != GIT_DELTA_DELETED && - idx2wd->new_file.mode != GIT_FILEMODE_COMMIT) - return 1; - } - - /* only get here if every valid mode is GIT_FILEMODE_COMMIT */ - return 0; -} - -static git_status_t status_compute( - git_status_list *status, - git_diff_delta *head2idx, - git_diff_delta *idx2wd) -{ - git_status_t st = GIT_STATUS_CURRENT; - - if (head2idx) - st |= index_delta2status(head2idx); - - if (idx2wd) - st |= workdir_delta2status(status->idx2wd, idx2wd); - - return st; -} - -static int status_collect( - git_diff_delta *head2idx, - git_diff_delta *idx2wd, - void *payload) -{ - git_status_list *status = payload; - git_status_entry *status_entry; - - if (!status_is_included(status, head2idx, idx2wd)) - return 0; - - status_entry = git__malloc(sizeof(git_status_entry)); - GIT_ERROR_CHECK_ALLOC(status_entry); - - status_entry->status = status_compute(status, head2idx, idx2wd); - status_entry->head_to_index = head2idx; - status_entry->index_to_workdir = idx2wd; - - return git_vector_insert(&status->paired, status_entry); -} - -GIT_INLINE(int) status_entry_cmp_base( - const void *a, - const void *b, - int (*strcomp)(const char *a, const char *b)) -{ - const git_status_entry *entry_a = a; - const git_status_entry *entry_b = b; - const git_diff_delta *delta_a, *delta_b; - - delta_a = entry_a->index_to_workdir ? entry_a->index_to_workdir : - entry_a->head_to_index; - delta_b = entry_b->index_to_workdir ? entry_b->index_to_workdir : - entry_b->head_to_index; - - if (!delta_a && delta_b) - return -1; - if (delta_a && !delta_b) - return 1; - if (!delta_a && !delta_b) - return 0; - - return strcomp(delta_a->new_file.path, delta_b->new_file.path); -} - -static int status_entry_icmp(const void *a, const void *b) -{ - return status_entry_cmp_base(a, b, git__strcasecmp); -} - -static int status_entry_cmp(const void *a, const void *b) -{ - return status_entry_cmp_base(a, b, git__strcmp); -} - -static git_status_list *git_status_list_alloc(git_index *index) -{ - git_status_list *status = NULL; - int (*entrycmp)(const void *a, const void *b); - - if (!(status = git__calloc(1, sizeof(git_status_list)))) - return NULL; - - entrycmp = index->ignore_case ? status_entry_icmp : status_entry_cmp; - - if (git_vector_init(&status->paired, 0, entrycmp) < 0) { - git__free(status); - return NULL; - } - - return status; -} - -static int status_validate_options(const git_status_options *opts) -{ - if (!opts) - return 0; - - GIT_ERROR_CHECK_VERSION(opts, GIT_STATUS_OPTIONS_VERSION, "git_status_options"); - - if (opts->show > GIT_STATUS_SHOW_WORKDIR_ONLY) { - git_error_set(GIT_ERROR_INVALID, "unknown status 'show' option"); - return -1; - } - - if ((opts->flags & GIT_STATUS_OPT_NO_REFRESH) != 0 && - (opts->flags & GIT_STATUS_OPT_UPDATE_INDEX) != 0) { - git_error_set(GIT_ERROR_INVALID, "updating index from status " - "is not allowed when index refresh is disabled"); - return -1; - } - - return 0; -} - -int git_status_list_new( - git_status_list **out, - git_repository *repo, - const git_status_options *opts) -{ - git_index *index = NULL; - git_status_list *status = NULL; - git_diff_options diffopt = GIT_DIFF_OPTIONS_INIT; - git_diff_find_options findopt = GIT_DIFF_FIND_OPTIONS_INIT; - git_tree *head = NULL; - git_status_show_t show = - opts ? opts->show : GIT_STATUS_SHOW_INDEX_AND_WORKDIR; - int error = 0; - unsigned int flags = opts ? opts->flags : GIT_STATUS_OPT_DEFAULTS; - - *out = NULL; - - if (status_validate_options(opts) < 0) - return -1; - - if ((error = git_repository__ensure_not_bare(repo, "status")) < 0 || - (error = git_repository_index(&index, repo)) < 0) - return error; - - if (opts != NULL && opts->baseline != NULL) { - head = opts->baseline; - } else { - /* if there is no HEAD, that's okay - we'll make an empty iterator */ - if ((error = git_repository_head_tree(&head, repo)) < 0) { - if (error != GIT_ENOTFOUND && error != GIT_EUNBORNBRANCH) - goto done; - git_error_clear(); - } - } - - /* refresh index from disk unless prevented */ - if ((flags & GIT_STATUS_OPT_NO_REFRESH) == 0 && - git_index_read_safely(index) < 0) - git_error_clear(); - - status = git_status_list_alloc(index); - GIT_ERROR_CHECK_ALLOC(status); - - if (opts) { - memcpy(&status->opts, opts, sizeof(git_status_options)); - memcpy(&diffopt.pathspec, &opts->pathspec, sizeof(diffopt.pathspec)); - } - - diffopt.flags = GIT_DIFF_INCLUDE_TYPECHANGE; - findopt.flags = GIT_DIFF_FIND_FOR_UNTRACKED; - - if ((flags & GIT_STATUS_OPT_INCLUDE_UNTRACKED) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNTRACKED; - if ((flags & GIT_STATUS_OPT_INCLUDE_IGNORED) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_IGNORED; - if ((flags & GIT_STATUS_OPT_INCLUDE_UNMODIFIED) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNMODIFIED; - if ((flags & GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_RECURSE_UNTRACKED_DIRS; - if ((flags & GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_DISABLE_PATHSPEC_MATCH; - if ((flags & GIT_STATUS_OPT_RECURSE_IGNORED_DIRS) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_RECURSE_IGNORED_DIRS; - if ((flags & GIT_STATUS_OPT_EXCLUDE_SUBMODULES) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_IGNORE_SUBMODULES; - if ((flags & GIT_STATUS_OPT_UPDATE_INDEX) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_UPDATE_INDEX; - if ((flags & GIT_STATUS_OPT_INCLUDE_UNREADABLE) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNREADABLE; - if ((flags & GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED) != 0) - diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED; - - if ((flags & GIT_STATUS_OPT_RENAMES_FROM_REWRITES) != 0) - findopt.flags = findopt.flags | - GIT_DIFF_FIND_AND_BREAK_REWRITES | - GIT_DIFF_FIND_RENAMES_FROM_REWRITES | - GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY; - - if (opts != NULL && opts->rename_threshold != 0) - findopt.rename_threshold = opts->rename_threshold; - - if (show != GIT_STATUS_SHOW_WORKDIR_ONLY) { - if ((error = git_diff_tree_to_index( - &status->head2idx, repo, head, index, &diffopt)) < 0) - goto done; - - if ((flags & GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX) != 0 && - (error = git_diff_find_similar(status->head2idx, &findopt)) < 0) - goto done; - } - - if (show != GIT_STATUS_SHOW_INDEX_ONLY) { - if ((error = git_diff_index_to_workdir( - &status->idx2wd, repo, index, &diffopt)) < 0) { - goto done; - } - - if ((flags & GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR) != 0 && - (error = git_diff_find_similar(status->idx2wd, &findopt)) < 0) - goto done; - } - - error = git_diff__paired_foreach( - status->head2idx, status->idx2wd, status_collect, status); - if (error < 0) - goto done; - - if (flags & GIT_STATUS_OPT_SORT_CASE_SENSITIVELY) - git_vector_set_cmp(&status->paired, status_entry_cmp); - if (flags & GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY) - git_vector_set_cmp(&status->paired, status_entry_icmp); - - if ((flags & - (GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX | - GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR | - GIT_STATUS_OPT_SORT_CASE_SENSITIVELY | - GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY)) != 0) - git_vector_sort(&status->paired); - -done: - if (error < 0) { - git_status_list_free(status); - status = NULL; - } - - *out = status; - - if (opts == NULL || opts->baseline != head) - git_tree_free(head); - git_index_free(index); - - return error; -} - -size_t git_status_list_entrycount(git_status_list *status) -{ - GIT_ASSERT_ARG_WITH_RETVAL(status, 0); - - return status->paired.length; -} - -const git_status_entry *git_status_byindex(git_status_list *status, size_t i) -{ - GIT_ASSERT_ARG_WITH_RETVAL(status, NULL); - - return git_vector_get(&status->paired, i); -} - -void git_status_list_free(git_status_list *status) -{ - if (status == NULL) - return; - - git_diff_free(status->head2idx); - git_diff_free(status->idx2wd); - - git_vector_dispose_deep(&status->paired); - - git__memzero(status, sizeof(*status)); - git__free(status); -} - -int git_status_foreach_ext( - git_repository *repo, - const git_status_options *opts, - git_status_cb cb, - void *payload) -{ - git_status_list *status; - const git_status_entry *status_entry; - size_t i; - int error = 0; - - if ((error = git_status_list_new(&status, repo, opts)) < 0) { - return error; - } - - git_vector_foreach(&status->paired, i, status_entry) { - const char *path = status_entry->head_to_index ? - status_entry->head_to_index->old_file.path : - status_entry->index_to_workdir->old_file.path; - - if ((error = cb(path, status_entry->status, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - - git_status_list_free(status); - - return error; -} - -int git_status_foreach(git_repository *repo, git_status_cb cb, void *payload) -{ - return git_status_foreach_ext(repo, NULL, cb, payload); -} - -struct status_file_info { - char *expected; - unsigned int count; - unsigned int status; - int wildmatch_flags; - int ambiguous; -}; - -static int get_one_status(const char *path, unsigned int status, void *data) -{ - struct status_file_info *sfi = data; - int (*strcomp)(const char *a, const char *b); - - sfi->count++; - sfi->status = status; - - strcomp = (sfi->wildmatch_flags & WM_CASEFOLD) ? git__strcasecmp : git__strcmp; - - if (sfi->count > 1 || - (strcomp(sfi->expected, path) != 0 && - wildmatch(sfi->expected, path, sfi->wildmatch_flags) != 0)) - { - sfi->ambiguous = true; - return GIT_EAMBIGUOUS; /* git_error_set will be done by caller */ - } - - return 0; -} - -int git_status_file( - unsigned int *status_flags, - git_repository *repo, - const char *path) -{ - int error; - git_status_options opts = GIT_STATUS_OPTIONS_INIT; - struct status_file_info sfi = {0}; - git_index *index; - - GIT_ASSERT_ARG(status_flags); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(path); - - if ((error = git_repository_index__weakptr(&index, repo)) < 0) - return error; - - if ((sfi.expected = git__strdup(path)) == NULL) - return -1; - if (index->ignore_case) - sfi.wildmatch_flags = WM_CASEFOLD; - - opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; - opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED | - GIT_STATUS_OPT_RECURSE_IGNORED_DIRS | - GIT_STATUS_OPT_INCLUDE_UNTRACKED | - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS | - GIT_STATUS_OPT_INCLUDE_UNMODIFIED | - GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH; - opts.pathspec.count = 1; - opts.pathspec.strings = &sfi.expected; - - error = git_status_foreach_ext(repo, &opts, get_one_status, &sfi); - - if (error < 0 && sfi.ambiguous) { - git_error_set(GIT_ERROR_INVALID, - "ambiguous path '%s' given to git_status_file", sfi.expected); - error = GIT_EAMBIGUOUS; - } - - if (!error && !sfi.count) { - git_error_set(GIT_ERROR_INVALID, - "attempt to get status of nonexistent file '%s'", path); - error = GIT_ENOTFOUND; - } - - *status_flags = sfi.status; - - git__free(sfi.expected); - - return error; -} - -int git_status_should_ignore( - int *ignored, - git_repository *repo, - const char *path) -{ - return git_ignore_path_is_ignored(ignored, repo, path); -} - -int git_status_options_init(git_status_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_status_options, GIT_STATUS_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_status_init_options(git_status_options *opts, unsigned int version) -{ - return git_status_options_init(opts, version); -} -#endif - -int git_status_list_get_perfdata( - git_diff_perfdata *out, const git_status_list *status) -{ - GIT_ASSERT_ARG(out); - - GIT_ERROR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata"); - - out->stat_calls = 0; - out->oid_calculations = 0; - - if (status->head2idx) { - out->stat_calls += status->head2idx->perf.stat_calls; - out->oid_calculations += status->head2idx->perf.oid_calculations; - } - if (status->idx2wd) { - out->stat_calls += status->idx2wd->perf.stat_calls; - out->oid_calculations += status->idx2wd->perf.oid_calculations; - } - - return 0; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/status.h b/vendor/libgit2-sys/libgit2/src/libgit2/status.h deleted file mode 100644 index 907479a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/status.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_status_h__ -#define INCLUDE_status_h__ - -#include "common.h" - -#include "diff.h" -#include "git2/status.h" -#include "git2/diff.h" - -struct git_status_list { - git_status_options opts; - - git_diff *head2idx; - git_diff *idx2wd; - - git_vector paired; -}; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/strarray.c b/vendor/libgit2-sys/libgit2/src/libgit2/strarray.c deleted file mode 100644 index 25e75f0..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/strarray.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "util.h" - -#include "common.h" -#include "strarray.h" - -int git_strarray_copy(git_strarray *tgt, const git_strarray *src) -{ - size_t i; - - GIT_ASSERT_ARG(tgt); - GIT_ASSERT_ARG(src); - - memset(tgt, 0, sizeof(*tgt)); - - if (!src->count) - return 0; - - tgt->strings = git__calloc(src->count, sizeof(char *)); - GIT_ERROR_CHECK_ALLOC(tgt->strings); - - for (i = 0; i < src->count; ++i) { - if (!src->strings[i]) - continue; - - tgt->strings[tgt->count] = git__strdup(src->strings[i]); - if (!tgt->strings[tgt->count]) { - git_strarray_dispose(tgt); - memset(tgt, 0, sizeof(*tgt)); - return -1; - } - - tgt->count++; - } - - return 0; -} - -void git_strarray_dispose(git_strarray *array) -{ - size_t i; - - if (array == NULL) - return; - - for (i = 0; i < array->count; ++i) - git__free(array->strings[i]); - - git__free(array->strings); - - memset(array, 0, sizeof(*array)); -} - -#ifndef GIT_DEPRECATE_HARD -void git_strarray_free(git_strarray *array) -{ - git_strarray_dispose(array); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/strarray.h b/vendor/libgit2-sys/libgit2/src/libgit2/strarray.h deleted file mode 100644 index 1984805..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/strarray.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_strarray_h__ -#define INCLUDE_strarray_h__ - -#include "common.h" -#include "git2/strarray.h" - -/** - * Copy a string array object from source to target. - * - * Note: target is overwritten and hence should be empty, otherwise its - * contents are leaked. Call git_strarray_free() if necessary. - * - * @param tgt target - * @param src source - * @return 0 on success, < 0 on allocation failure - */ -extern int git_strarray_copy(git_strarray *tgt, const git_strarray *src); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/stream.h b/vendor/libgit2-sys/libgit2/src/libgit2/stream.h deleted file mode 100644 index f16b026..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/stream.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_stream_h__ -#define INCLUDE_stream_h__ - -#include "common.h" -#include "git2/sys/stream.h" - -GIT_INLINE(int) git_stream_connect(git_stream *st) -{ - return st->connect(st); -} - -GIT_INLINE(int) git_stream_is_encrypted(git_stream *st) -{ - return st->encrypted; -} - -GIT_INLINE(int) git_stream_certificate(git_cert **out, git_stream *st) -{ - if (!st->encrypted) { - git_error_set(GIT_ERROR_INVALID, "an unencrypted stream does not have a certificate"); - return -1; - } - - return st->certificate(out, st); -} - -GIT_INLINE(int) git_stream_supports_proxy(git_stream *st) -{ - return st->proxy_support; -} - -GIT_INLINE(int) git_stream_set_proxy(git_stream *st, const git_proxy_options *proxy_opts) -{ - if (!st->proxy_support) { - git_error_set(GIT_ERROR_INVALID, "proxy not supported on this stream"); - return -1; - } - - return st->set_proxy(st, proxy_opts); -} - -GIT_INLINE(ssize_t) git_stream_read(git_stream *st, void *data, size_t len) -{ - return st->read(st, data, len); -} - -GIT_INLINE(ssize_t) git_stream_write(git_stream *st, const char *data, size_t len, int flags) -{ - return st->write(st, data, len, flags); -} - -GIT_INLINE(int) git_stream__write_full(git_stream *st, const char *data, size_t len, int flags) -{ - size_t total_written = 0; - - while (total_written < len) { - ssize_t written = git_stream_write(st, data + total_written, len - total_written, flags); - if (written <= 0) - return -1; - - total_written += written; - } - - return 0; -} - -GIT_INLINE(int) git_stream_close(git_stream *st) -{ - return st->close(st); -} - -GIT_INLINE(void) git_stream_free(git_stream *st) -{ - if (!st) - return; - - st->free(st); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/mbedtls.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/mbedtls.c deleted file mode 100644 index 37abcda..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/mbedtls.c +++ /dev/null @@ -1,475 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "streams/mbedtls.h" - -#ifdef GIT_MBEDTLS - -#include - -#include "runtime.h" -#include "stream.h" -#include "streams/socket.h" -#include "git2/transport.h" -#include "util.h" - -#ifndef GIT_DEFAULT_CERT_LOCATION -#define GIT_DEFAULT_CERT_LOCATION NULL -#endif - -/* Work around C90-conformance issues */ -#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) -# if defined(_MSC_VER) -# define inline __inline -# elif defined(__GNUC__) -# define inline __inline__ -# else -# define inline -# endif -#endif - -#include -#include -#include -#include - -#undef inline - -#define GIT_SSL_DEFAULT_CIPHERS "TLS1-3-AES-128-GCM-SHA256:TLS1-3-AES-256-GCM-SHA384:TLS1-3-CHACHA20-POLY1305-SHA256:TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384:TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384:TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256:TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-CHACHA20-POLY1305-SHA256:TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256:TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256:TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA:TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384:TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-RSA-WITH-AES-128-CBC-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-RSA-WITH-AES-128-GCM-SHA256:TLS-RSA-WITH-AES-256-GCM-SHA384:TLS-RSA-WITH-AES-128-CBC-SHA256:TLS-RSA-WITH-AES-256-CBC-SHA256:TLS-RSA-WITH-AES-128-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA" -#define GIT_SSL_DEFAULT_CIPHERS_COUNT 28 - -static int ciphers_list[GIT_SSL_DEFAULT_CIPHERS_COUNT]; - -static bool initialized = false; -static mbedtls_ssl_config mbedtls_config; -static mbedtls_ctr_drbg_context mbedtls_rng; -static mbedtls_entropy_context mbedtls_entropy; - -static bool has_ca_chain = false; -static mbedtls_x509_crt mbedtls_ca_chain; - -/** - * This function aims to clean-up the SSL context which - * we allocated. - */ -static void shutdown_ssl(void) -{ - if (has_ca_chain) { - mbedtls_x509_crt_free(&mbedtls_ca_chain); - has_ca_chain = false; - } - - if (initialized) { - mbedtls_ctr_drbg_free(&mbedtls_rng); - mbedtls_ssl_config_free(&mbedtls_config); - mbedtls_entropy_free(&mbedtls_entropy); - initialized = false; - } -} - -int git_mbedtls_stream_global_init(void) -{ - int loaded = 0; - char *crtpath = GIT_DEFAULT_CERT_LOCATION; - struct stat statbuf; - - size_t ciphers_known = 0; - char *cipher_name = NULL; - char *cipher_string = NULL; - char *cipher_string_tmp = NULL; - - mbedtls_ssl_config_init(&mbedtls_config); - mbedtls_entropy_init(&mbedtls_entropy); - mbedtls_ctr_drbg_init(&mbedtls_rng); - - if (mbedtls_ssl_config_defaults(&mbedtls_config, - MBEDTLS_SSL_IS_CLIENT, - MBEDTLS_SSL_TRANSPORT_STREAM, - MBEDTLS_SSL_PRESET_DEFAULT) != 0) { - git_error_set(GIT_ERROR_SSL, "failed to initialize mbedTLS"); - goto cleanup; - } - - /* configure TLSv1.1 or better */ -#ifdef MBEDTLS_SSL_MINOR_VERSION_2 - mbedtls_ssl_conf_min_version(&mbedtls_config, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_2); -#endif - - /* verify_server_cert is responsible for making the check. - * OPTIONAL because REQUIRED drops the certificate as soon as the check - * is made, so we can never see the certificate and override it. */ - mbedtls_ssl_conf_authmode(&mbedtls_config, MBEDTLS_SSL_VERIFY_OPTIONAL); - - /* set the list of allowed ciphersuites */ - ciphers_known = 0; - cipher_string = cipher_string_tmp = git__strdup(GIT_SSL_DEFAULT_CIPHERS); - GIT_ERROR_CHECK_ALLOC(cipher_string); - - while ((cipher_name = git__strtok(&cipher_string_tmp, ":")) != NULL) { - int cipherid = mbedtls_ssl_get_ciphersuite_id(cipher_name); - if (cipherid == 0) continue; - - if (ciphers_known >= ARRAY_SIZE(ciphers_list)) { - git_error_set(GIT_ERROR_SSL, "out of cipher list space"); - goto cleanup; - } - - ciphers_list[ciphers_known++] = cipherid; - } - git__free(cipher_string); - - if (!ciphers_known) { - git_error_set(GIT_ERROR_SSL, "no cipher could be enabled"); - goto cleanup; - } - mbedtls_ssl_conf_ciphersuites(&mbedtls_config, ciphers_list); - - /* Seeding the random number generator */ - - if (mbedtls_ctr_drbg_seed(&mbedtls_rng, mbedtls_entropy_func, - &mbedtls_entropy, NULL, 0) != 0) { - git_error_set(GIT_ERROR_SSL, "failed to initialize mbedTLS entropy pool"); - goto cleanup; - } - - mbedtls_ssl_conf_rng(&mbedtls_config, mbedtls_ctr_drbg_random, &mbedtls_rng); - - /* load default certificates */ - if (crtpath != NULL && stat(crtpath, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) - loaded = (git_mbedtls__set_cert_location(crtpath, NULL) == 0); - - if (!loaded && crtpath != NULL && stat(crtpath, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) - loaded = (git_mbedtls__set_cert_location(NULL, crtpath) == 0); - - initialized = true; - - return git_runtime_shutdown_register(shutdown_ssl); - -cleanup: - mbedtls_ctr_drbg_free(&mbedtls_rng); - mbedtls_ssl_config_free(&mbedtls_config); - mbedtls_entropy_free(&mbedtls_entropy); - - return -1; -} - -static int bio_read(void *b, unsigned char *buf, size_t len) -{ - git_stream *io = (git_stream *) b; - return (int) git_stream_read(io, buf, min(len, INT_MAX)); -} - -static int bio_write(void *b, const unsigned char *buf, size_t len) -{ - git_stream *io = (git_stream *) b; - return (int) git_stream_write(io, (const char *)buf, min(len, INT_MAX), 0); -} - -static int ssl_set_error(mbedtls_ssl_context *ssl, int error) -{ - char errbuf[512]; - int ret = -1; - - GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_READ); - GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_WRITE); - - if (error != 0) - mbedtls_strerror( error, errbuf, 512 ); - - switch(error) { - case 0: - git_error_set(GIT_ERROR_SSL, "SSL error: unknown error"); - break; - - case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED: - git_error_set(GIT_ERROR_SSL, "SSL error: %#04x [%x] - %s", error, mbedtls_ssl_get_verify_result(ssl), errbuf); - ret = GIT_ECERTIFICATE; - break; - - default: - git_error_set(GIT_ERROR_SSL, "SSL error: %#04x - %s", error, errbuf); - } - - return ret; -} - -static int ssl_teardown(mbedtls_ssl_context *ssl) -{ - int ret = 0; - - ret = mbedtls_ssl_close_notify(ssl); - if (ret < 0) - ret = ssl_set_error(ssl, ret); - - mbedtls_ssl_free(ssl); - return ret; -} - -static int verify_server_cert(mbedtls_ssl_context *ssl) -{ - int ret = -1; - - if ((ret = mbedtls_ssl_get_verify_result(ssl)) != 0) { - char vrfy_buf[512]; - int len = mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), "", ret); - if (len >= 1) vrfy_buf[len - 1] = '\0'; /* Remove trailing \n */ - git_error_set(GIT_ERROR_SSL, "the SSL certificate is invalid: %#04x - %s", ret, vrfy_buf); - return GIT_ECERTIFICATE; - } - - return 0; -} - -typedef struct { - git_stream parent; - git_stream *io; - int owned; - bool connected; - char *host; - mbedtls_ssl_context *ssl; - git_cert_x509 cert_info; -} mbedtls_stream; - - -static int mbedtls_connect(git_stream *stream) -{ - int ret; - mbedtls_stream *st = (mbedtls_stream *) stream; - - if (st->owned && (ret = git_stream_connect(st->io)) < 0) - return ret; - - st->connected = true; - - mbedtls_ssl_set_hostname(st->ssl, st->host); - - mbedtls_ssl_set_bio(st->ssl, st->io, bio_write, bio_read, NULL); - - if ((ret = mbedtls_ssl_handshake(st->ssl)) != 0) - return ssl_set_error(st->ssl, ret); - - return verify_server_cert(st->ssl); -} - -static int mbedtls_certificate(git_cert **out, git_stream *stream) -{ - unsigned char *encoded_cert; - mbedtls_stream *st = (mbedtls_stream *) stream; - - const mbedtls_x509_crt *cert = mbedtls_ssl_get_peer_cert(st->ssl); - if (!cert) { - git_error_set(GIT_ERROR_SSL, "the server did not provide a certificate"); - return -1; - } - - /* Retrieve the length of the certificate first */ - if (cert->raw.len == 0) { - git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information"); - return -1; - } - - encoded_cert = git__malloc(cert->raw.len); - GIT_ERROR_CHECK_ALLOC(encoded_cert); - memcpy(encoded_cert, cert->raw.p, cert->raw.len); - - st->cert_info.parent.cert_type = GIT_CERT_X509; - st->cert_info.data = encoded_cert; - st->cert_info.len = cert->raw.len; - - *out = &st->cert_info.parent; - - return 0; -} - -static int mbedtls_set_proxy(git_stream *stream, const git_proxy_options *proxy_options) -{ - mbedtls_stream *st = (mbedtls_stream *) stream; - - return git_stream_set_proxy(st->io, proxy_options); -} - -static ssize_t mbedtls_stream_write(git_stream *stream, const char *data, size_t len, int flags) -{ - mbedtls_stream *st = (mbedtls_stream *) stream; - int written; - - GIT_UNUSED(flags); - - /* - * `mbedtls_ssl_write` can only represent INT_MAX bytes - * written via its return value. We thus need to clamp - * the maximum number of bytes written. - */ - len = min(len, INT_MAX); - - if ((written = mbedtls_ssl_write(st->ssl, (const unsigned char *)data, len)) <= 0) - return ssl_set_error(st->ssl, written); - - return written; -} - -static ssize_t mbedtls_stream_read(git_stream *stream, void *data, size_t len) -{ - mbedtls_stream *st = (mbedtls_stream *) stream; - int ret; - - if ((ret = mbedtls_ssl_read(st->ssl, (unsigned char *)data, len)) <= 0) - ssl_set_error(st->ssl, ret); - - return ret; -} - -static int mbedtls_stream_close(git_stream *stream) -{ - mbedtls_stream *st = (mbedtls_stream *) stream; - int ret = 0; - - if (st->connected && (ret = ssl_teardown(st->ssl)) != 0) - return -1; - - st->connected = false; - - return st->owned ? git_stream_close(st->io) : 0; -} - -static void mbedtls_stream_free(git_stream *stream) -{ - mbedtls_stream *st = (mbedtls_stream *) stream; - - if (st->owned) - git_stream_free(st->io); - - git__free(st->host); - git__free(st->cert_info.data); - mbedtls_ssl_free(st->ssl); - git__free(st->ssl); - git__free(st); -} - -static int mbedtls_stream_wrap( - git_stream **out, - git_stream *in, - const char *host, - int owned) -{ - mbedtls_stream *st; - int error; - - st = git__calloc(1, sizeof(mbedtls_stream)); - GIT_ERROR_CHECK_ALLOC(st); - - st->io = in; - st->owned = owned; - - st->ssl = git__malloc(sizeof(mbedtls_ssl_context)); - GIT_ERROR_CHECK_ALLOC(st->ssl); - mbedtls_ssl_init(st->ssl); - if (mbedtls_ssl_setup(st->ssl, &mbedtls_config)) { - git_error_set(GIT_ERROR_SSL, "failed to create ssl object"); - error = -1; - goto out_err; - } - - st->host = git__strdup(host); - GIT_ERROR_CHECK_ALLOC(st->host); - - st->parent.version = GIT_STREAM_VERSION; - st->parent.encrypted = 1; - st->parent.proxy_support = git_stream_supports_proxy(st->io); - st->parent.connect = mbedtls_connect; - st->parent.certificate = mbedtls_certificate; - st->parent.set_proxy = mbedtls_set_proxy; - st->parent.read = mbedtls_stream_read; - st->parent.write = mbedtls_stream_write; - st->parent.close = mbedtls_stream_close; - st->parent.free = mbedtls_stream_free; - - *out = (git_stream *) st; - return 0; - -out_err: - mbedtls_ssl_free(st->ssl); - git_stream_close(st->io); - git_stream_free(st->io); - git__free(st); - - return error; -} - -int git_mbedtls_stream_wrap( - git_stream **out, - git_stream *in, - const char *host) -{ - return mbedtls_stream_wrap(out, in, host, 0); -} - -int git_mbedtls_stream_new( - git_stream **out, - const char *host, - const char *port) -{ - git_stream *stream; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(host); - GIT_ASSERT_ARG(port); - - if ((error = git_socket_stream_new(&stream, host, port)) < 0) - return error; - - if ((error = mbedtls_stream_wrap(out, stream, host, 1)) < 0) { - git_stream_close(stream); - git_stream_free(stream); - } - - return error; -} - -int git_mbedtls__set_cert_location(const char *file, const char *path) -{ - int ret = 0; - char errbuf[512]; - - GIT_ASSERT_ARG(file || path); - - if (has_ca_chain) - mbedtls_x509_crt_free(&mbedtls_ca_chain); - - mbedtls_x509_crt_init(&mbedtls_ca_chain); - - if (file) - ret = mbedtls_x509_crt_parse_file(&mbedtls_ca_chain, file); - - if (ret >= 0 && path) - ret = mbedtls_x509_crt_parse_path(&mbedtls_ca_chain, path); - - /* mbedtls_x509_crt_parse_path returns the number of invalid certs on success */ - if (ret < 0) { - mbedtls_x509_crt_free(&mbedtls_ca_chain); - mbedtls_strerror( ret, errbuf, 512 ); - git_error_set(GIT_ERROR_SSL, "failed to load CA certificates: %#04x - %s", ret, errbuf); - return -1; - } - - mbedtls_ssl_conf_ca_chain(&mbedtls_config, &mbedtls_ca_chain, NULL); - has_ca_chain = true; - - return 0; -} - -#else - -#include "stream.h" - -int git_mbedtls_stream_global_init(void) -{ - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/mbedtls.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/mbedtls.h deleted file mode 100644 index bcca6dd..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/mbedtls.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_steams_mbedtls_h__ -#define INCLUDE_steams_mbedtls_h__ - -#include "common.h" - -#include "git2/sys/stream.h" - -extern int git_mbedtls_stream_global_init(void); - -#ifdef GIT_MBEDTLS -extern int git_mbedtls__set_cert_location(const char *file, const char *path); - -extern int git_mbedtls_stream_new(git_stream **out, const char *host, const char *port); -extern int git_mbedtls_stream_wrap(git_stream **out, git_stream *in, const char *host); -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl.c deleted file mode 100644 index ca77ad0..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl.c +++ /dev/null @@ -1,767 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "streams/openssl.h" -#include "streams/openssl_legacy.h" -#include "streams/openssl_dynamic.h" - -#ifdef GIT_OPENSSL - -#include - -#include "common.h" -#include "runtime.h" -#include "settings.h" -#include "posix.h" -#include "stream.h" -#include "net.h" -#include "streams/socket.h" -#include "git2/transport.h" -#include "git2/sys/openssl.h" - -#ifndef GIT_WIN32 -# include -# include -# include -#endif - -#ifndef GIT_OPENSSL_DYNAMIC -# include -# include -# include -# include -#endif - -extern char *git__ssl_ciphers; - -SSL_CTX *git__ssl_ctx; - -#define GIT_SSL_DEFAULT_CIPHERS "TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA" - -static BIO_METHOD *git_stream_bio_method; -static int init_bio_method(void); - -/** - * This function aims to clean-up the SSL context which - * we allocated. - */ -static void shutdown_ssl(void) -{ - if (git_stream_bio_method) { - BIO_meth_free(git_stream_bio_method); - git_stream_bio_method = NULL; - } - - if (git__ssl_ctx) { - SSL_CTX_free(git__ssl_ctx); - git__ssl_ctx = NULL; - } -} - -#ifdef VALGRIND -# if !defined(GIT_OPENSSL_LEGACY) && !defined(GIT_OPENSSL_DYNAMIC) - -static void *git_openssl_malloc(size_t bytes, const char *file, int line) -{ - GIT_UNUSED(file); - GIT_UNUSED(line); - return git__calloc(1, bytes); -} - -static void *git_openssl_realloc(void *mem, size_t size, const char *file, int line) -{ - GIT_UNUSED(file); - GIT_UNUSED(line); - return git__realloc(mem, size); -} - -static void git_openssl_free(void *mem, const char *file, int line) -{ - GIT_UNUSED(file); - GIT_UNUSED(line); - git__free(mem); -} -# else /* !GIT_OPENSSL_LEGACY && !GIT_OPENSSL_DYNAMIC */ -static void *git_openssl_malloc(size_t bytes) -{ - return git__calloc(1, bytes); -} - -static void *git_openssl_realloc(void *mem, size_t size) -{ - return git__realloc(mem, size); -} - -static void git_openssl_free(void *mem) -{ - git__free(mem); -} -# endif /* !GIT_OPENSSL_LEGACY && !GIT_OPENSSL_DYNAMIC */ -#endif /* VALGRIND */ - -static int openssl_init(void) -{ - long ssl_opts = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3; - const char *ciphers = git__ssl_ciphers; -#ifdef VALGRIND - static bool allocators_initialized = false; -#endif - - /* Older OpenSSL and MacOS OpenSSL doesn't have this */ -#ifdef SSL_OP_NO_COMPRESSION - ssl_opts |= SSL_OP_NO_COMPRESSION; -#endif - -#ifdef VALGRIND - /* - * Swap in our own allocator functions that initialize - * allocated memory to avoid spurious valgrind warnings. - * Don't error on failure; many builds of OpenSSL do not - * allow you to set these functions. - */ - if (!allocators_initialized) { - CRYPTO_set_mem_functions(git_openssl_malloc, - git_openssl_realloc, - git_openssl_free); - allocators_initialized = true; - } -#endif - - OPENSSL_init_ssl(0, NULL); - - /* - * Despite the name SSLv23_method, this is actually a version- - * flexible context, which honors the protocol versions - * specified in `ssl_opts`. So we only support TLSv1.0 and - * higher. - */ - if (!(git__ssl_ctx = SSL_CTX_new(SSLv23_method()))) - goto error; - - SSL_CTX_set_options(git__ssl_ctx, ssl_opts); - SSL_CTX_set_mode(git__ssl_ctx, SSL_MODE_AUTO_RETRY); - SSL_CTX_set_verify(git__ssl_ctx, SSL_VERIFY_NONE, NULL); - if (!SSL_CTX_set_default_verify_paths(git__ssl_ctx)) - goto error; - - if (!ciphers) - ciphers = GIT_SSL_DEFAULT_CIPHERS; - - if(!SSL_CTX_set_cipher_list(git__ssl_ctx, ciphers)) - goto error; - - if (init_bio_method() < 0) - goto error; - - return git_runtime_shutdown_register(shutdown_ssl); - -error: - git_error_set(GIT_ERROR_NET, "could not initialize openssl: %s", - ERR_error_string(ERR_get_error(), NULL)); - SSL_CTX_free(git__ssl_ctx); - git__ssl_ctx = NULL; - return -1; -} - -/* - * When we use dynamic loading, we defer OpenSSL initialization until - * it's first used. `openssl_ensure_initialized` will do the work - * under a mutex. - */ -git_mutex openssl_mutex; -bool openssl_initialized; - -int git_openssl_stream_global_init(void) -{ -#ifndef GIT_OPENSSL_DYNAMIC - return openssl_init(); -#else - if (git_mutex_init(&openssl_mutex) != 0) - return -1; - - return 0; -#endif -} - -static int openssl_ensure_initialized(void) -{ -#ifdef GIT_OPENSSL_DYNAMIC - int error = 0; - - if (git_mutex_lock(&openssl_mutex) != 0) - return -1; - - if (!openssl_initialized) { - if ((error = git_openssl_stream_dynamic_init()) == 0) - error = openssl_init(); - - openssl_initialized = !error; - } - - error |= git_mutex_unlock(&openssl_mutex); - return error; - -#else - return 0; -#endif -} - -#if !defined(GIT_OPENSSL_LEGACY) && !defined(GIT_OPENSSL_DYNAMIC) -int git_openssl_set_locking(void) -{ -# ifdef GIT_THREADS - return 0; -# else - git_error_set(GIT_ERROR_THREAD, "libgit2 was not built with threads"); - return -1; -# endif -} -#endif - - -static int bio_create(BIO *b) -{ - BIO_set_init(b, 1); - BIO_set_data(b, NULL); - - return 1; -} - -static int bio_destroy(BIO *b) -{ - if (!b) - return 0; - - BIO_set_data(b, NULL); - - return 1; -} - -static int bio_read(BIO *b, char *buf, int len) -{ - git_stream *io = (git_stream *) BIO_get_data(b); - - return (int) git_stream_read(io, buf, len); -} - -static int bio_write(BIO *b, const char *buf, int len) -{ - git_stream *io = (git_stream *) BIO_get_data(b); - return (int) git_stream_write(io, buf, len, 0); -} - -static long bio_ctrl(BIO *b, int cmd, long num, void *ptr) -{ - GIT_UNUSED(b); - GIT_UNUSED(num); - GIT_UNUSED(ptr); - - if (cmd == BIO_CTRL_FLUSH) - return 1; - - return 0; -} - -static int bio_gets(BIO *b, char *buf, int len) -{ - GIT_UNUSED(b); - GIT_UNUSED(buf); - GIT_UNUSED(len); - return -1; -} - -static int bio_puts(BIO *b, const char *str) -{ - return bio_write(b, str, strlen(str)); -} - -static int init_bio_method(void) -{ - /* Set up the BIO_METHOD we use for wrapping our own stream implementations */ - git_stream_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK | BIO_get_new_index(), "git_stream"); - GIT_ERROR_CHECK_ALLOC(git_stream_bio_method); - - BIO_meth_set_write(git_stream_bio_method, bio_write); - BIO_meth_set_read(git_stream_bio_method, bio_read); - BIO_meth_set_puts(git_stream_bio_method, bio_puts); - BIO_meth_set_gets(git_stream_bio_method, bio_gets); - BIO_meth_set_ctrl(git_stream_bio_method, bio_ctrl); - BIO_meth_set_create(git_stream_bio_method, bio_create); - BIO_meth_set_destroy(git_stream_bio_method, bio_destroy); - - return 0; -} - -static int ssl_set_error(SSL *ssl, int error) -{ - int err; - unsigned long e; - - err = SSL_get_error(ssl, error); - - GIT_ASSERT(err != SSL_ERROR_WANT_READ); - GIT_ASSERT(err != SSL_ERROR_WANT_WRITE); - - switch (err) { - case SSL_ERROR_WANT_CONNECT: - case SSL_ERROR_WANT_ACCEPT: - git_error_set(GIT_ERROR_SSL, "SSL error: connection failure"); - break; - case SSL_ERROR_WANT_X509_LOOKUP: - git_error_set(GIT_ERROR_SSL, "SSL error: x509 error"); - break; - case SSL_ERROR_SYSCALL: - e = ERR_get_error(); - if (e > 0) { - char errmsg[256]; - ERR_error_string_n(e, errmsg, sizeof(errmsg)); - git_error_set(GIT_ERROR_NET, "SSL error: %s", errmsg); - break; - } else if (error < 0) { - git_error_set(GIT_ERROR_OS, "SSL error: syscall failure"); - break; - } - git_error_set(GIT_ERROR_SSL, "SSL error: received early EOF"); - return GIT_EEOF; - break; - case SSL_ERROR_SSL: - { - char errmsg[256]; - e = ERR_get_error(); - ERR_error_string_n(e, errmsg, sizeof(errmsg)); - git_error_set(GIT_ERROR_SSL, "SSL error: %s", errmsg); - break; - } - case SSL_ERROR_NONE: - case SSL_ERROR_ZERO_RETURN: - default: - git_error_set(GIT_ERROR_SSL, "SSL error: unknown error"); - break; - } - return -1; -} - -static int ssl_teardown(SSL *ssl) -{ - int ret; - - ret = SSL_shutdown(ssl); - if (ret < 0) - ret = ssl_set_error(ssl, ret); - else - ret = 0; - - return ret; -} - -static bool check_host_name(const char *host, const char *name) -{ - return !strcasecmp(host, name) || - git_net_hostname_matches_cert(host, name); -} - -static int verify_server_cert(SSL *ssl, const char *host) -{ - X509 *cert = NULL; - X509_NAME *peer_name; - ASN1_STRING *str; - unsigned char *peer_cn = NULL; - int matched = -1, type = GEN_DNS; - GENERAL_NAMES *alts; - struct in6_addr addr6; - struct in_addr addr4; - void *addr = NULL; - size_t addrlen = 0; - int i = -1, j, error = 0; - - if (SSL_get_verify_result(ssl) != X509_V_OK) { - git_error_set(GIT_ERROR_SSL, "the SSL certificate is invalid"); - return GIT_ECERTIFICATE; - } - - /* Try to parse the host as an IP address to see if it is */ - if (p_inet_pton(AF_INET, host, &addr4)) { - type = GEN_IPADD; - addr = &addr4; - addrlen = sizeof(addr4); - } else { - if (p_inet_pton(AF_INET6, host, &addr6)) { - type = GEN_IPADD; - addr = &addr6; - addrlen = sizeof(addr6); - } - } - - - cert = SSL_get_peer_certificate(ssl); - if (!cert) { - error = -1; - git_error_set(GIT_ERROR_SSL, "the server did not provide a certificate"); - goto cleanup; - } - - /* Check the alternative names */ - alts = X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL); - if (alts) { - int num; - - num = sk_GENERAL_NAME_num(alts); - for (i = 0; i < num && matched != 1; i++) { - const GENERAL_NAME *gn = sk_GENERAL_NAME_value(alts, i); - const char *name = (char *) ASN1_STRING_get0_data(gn->d.ia5); - size_t namelen = (size_t) ASN1_STRING_length(gn->d.ia5); - - /* Skip any names of a type we're not looking for */ - if (gn->type != type) - continue; - - if (type == GEN_DNS) { - /* If it contains embedded NULs, don't even try */ - if (memchr(name, '\0', namelen)) - continue; - - matched = !!check_host_name(host, name); - } else if (type == GEN_IPADD) { - /* Here name isn't so much a name but a binary representation of the IP */ - matched = (addr && namelen == addrlen && memcmp(name, addr, namelen) == 0); - } - } - } - GENERAL_NAMES_free(alts); - - if (matched == 0) - goto cert_fail_name; - - if (matched == 1) { - goto cleanup; - } - - /* If no alternative names are available, check the common name */ - peer_name = X509_get_subject_name(cert); - if (peer_name == NULL) - goto on_error; - - if (peer_name) { - /* Get the index of the last CN entry */ - while ((j = X509_NAME_get_index_by_NID(peer_name, NID_commonName, i)) >= 0) - i = j; - } - - if (i < 0) - goto on_error; - - str = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(peer_name, i)); - if (str == NULL) - goto on_error; - - /* Work around a bug in OpenSSL whereby ASN1_STRING_to_UTF8 fails if it's already in utf-8 */ - if (ASN1_STRING_type(str) == V_ASN1_UTF8STRING) { - int size = ASN1_STRING_length(str); - - if (size > 0) { - peer_cn = OPENSSL_malloc(size + 1); - GIT_ERROR_CHECK_ALLOC(peer_cn); - memcpy(peer_cn, ASN1_STRING_get0_data(str), size); - peer_cn[size] = '\0'; - } else { - goto cert_fail_name; - } - } else { - int size = ASN1_STRING_to_UTF8(&peer_cn, str); - GIT_ERROR_CHECK_ALLOC(peer_cn); - if (memchr(peer_cn, '\0', size)) - goto cert_fail_name; - } - - if (!check_host_name(host, (char *)peer_cn)) - goto cert_fail_name; - - goto cleanup; - -cert_fail_name: - error = GIT_ECERTIFICATE; - git_error_set(GIT_ERROR_SSL, "hostname does not match certificate"); - goto cleanup; - -on_error: - error = ssl_set_error(ssl, 0); - goto cleanup; - -cleanup: - X509_free(cert); - OPENSSL_free(peer_cn); - return error; -} - -typedef struct { - git_stream parent; - git_stream *io; - int owned; - bool connected; - char *host; - SSL *ssl; - git_cert_x509 cert_info; -} openssl_stream; - -static int openssl_connect(git_stream *stream) -{ - int ret; - BIO *bio; - openssl_stream *st = (openssl_stream *) stream; - - if (st->owned && (ret = git_stream_connect(st->io)) < 0) - return ret; - - bio = BIO_new(git_stream_bio_method); - GIT_ERROR_CHECK_ALLOC(bio); - - BIO_set_data(bio, st->io); - SSL_set_bio(st->ssl, bio, bio); - - /* specify the host in case SNI is needed */ -#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME - SSL_set_tlsext_host_name(st->ssl, st->host); -#endif - - if ((ret = SSL_connect(st->ssl)) <= 0) - return ssl_set_error(st->ssl, ret); - - st->connected = true; - - return verify_server_cert(st->ssl, st->host); -} - -static int openssl_certificate(git_cert **out, git_stream *stream) -{ - openssl_stream *st = (openssl_stream *) stream; - X509 *cert = SSL_get_peer_certificate(st->ssl); - unsigned char *guard, *encoded_cert = NULL; - int error, len; - - /* Retrieve the length of the certificate first */ - len = i2d_X509(cert, NULL); - if (len < 0) { - git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information"); - error = -1; - goto out; - } - - encoded_cert = git__malloc(len); - GIT_ERROR_CHECK_ALLOC(encoded_cert); - /* i2d_X509 makes 'guard' point to just after the data */ - guard = encoded_cert; - - len = i2d_X509(cert, &guard); - if (len < 0) { - git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information"); - error = -1; - goto out; - } - - st->cert_info.parent.cert_type = GIT_CERT_X509; - st->cert_info.data = encoded_cert; - st->cert_info.len = len; - encoded_cert = NULL; - - *out = &st->cert_info.parent; - error = 0; - -out: - git__free(encoded_cert); - X509_free(cert); - return error; -} - -static int openssl_set_proxy(git_stream *stream, const git_proxy_options *proxy_opts) -{ - openssl_stream *st = (openssl_stream *) stream; - - return git_stream_set_proxy(st->io, proxy_opts); -} - -static ssize_t openssl_write(git_stream *stream, const char *data, size_t data_len, int flags) -{ - openssl_stream *st = (openssl_stream *) stream; - int ret, len = min(data_len, INT_MAX); - - GIT_UNUSED(flags); - - if ((ret = SSL_write(st->ssl, data, len)) <= 0) - return ssl_set_error(st->ssl, ret); - - return ret; -} - -static ssize_t openssl_read(git_stream *stream, void *data, size_t len) -{ - openssl_stream *st = (openssl_stream *) stream; - int ret; - - if ((ret = SSL_read(st->ssl, data, len)) <= 0) - return ssl_set_error(st->ssl, ret); - - return ret; -} - -static int openssl_close(git_stream *stream) -{ - openssl_stream *st = (openssl_stream *) stream; - int ret; - - if (st->connected && (ret = ssl_teardown(st->ssl)) < 0) - return -1; - - st->connected = false; - - return st->owned ? git_stream_close(st->io) : 0; -} - -static void openssl_free(git_stream *stream) -{ - openssl_stream *st = (openssl_stream *) stream; - - if (st->owned) - git_stream_free(st->io); - - SSL_free(st->ssl); - git__free(st->host); - git__free(st->cert_info.data); - git__free(st); -} - -static int openssl_stream_wrap( - git_stream **out, - git_stream *in, - const char *host, - int owned) -{ - openssl_stream *st; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(in); - GIT_ASSERT_ARG(host); - - st = git__calloc(1, sizeof(openssl_stream)); - GIT_ERROR_CHECK_ALLOC(st); - - st->io = in; - st->owned = owned; - - st->ssl = SSL_new(git__ssl_ctx); - if (st->ssl == NULL) { - git_error_set(GIT_ERROR_SSL, "failed to create ssl object"); - git__free(st); - return -1; - } - - st->host = git__strdup(host); - GIT_ERROR_CHECK_ALLOC(st->host); - - st->parent.version = GIT_STREAM_VERSION; - st->parent.encrypted = 1; - st->parent.proxy_support = git_stream_supports_proxy(st->io); - st->parent.connect = openssl_connect; - st->parent.certificate = openssl_certificate; - st->parent.set_proxy = openssl_set_proxy; - st->parent.read = openssl_read; - st->parent.write = openssl_write; - st->parent.close = openssl_close; - st->parent.free = openssl_free; - - *out = (git_stream *) st; - return 0; -} - -int git_openssl_stream_wrap(git_stream **out, git_stream *in, const char *host) -{ - if (openssl_ensure_initialized() < 0) - return -1; - - return openssl_stream_wrap(out, in, host, 0); -} - -int git_openssl_stream_new(git_stream **out, const char *host, const char *port) -{ - git_stream *stream = NULL; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(host); - GIT_ASSERT_ARG(port); - - if (openssl_ensure_initialized() < 0) - return -1; - - if ((error = git_socket_stream_new(&stream, host, port)) < 0) - return error; - - if ((error = openssl_stream_wrap(out, stream, host, 1)) < 0) { - git_stream_close(stream); - git_stream_free(stream); - } - - return error; -} - -int git_openssl__set_cert_location(const char *file, const char *path) -{ - if (openssl_ensure_initialized() < 0) - return -1; - - if (SSL_CTX_load_verify_locations(git__ssl_ctx, file, path) == 0) { - char errmsg[256]; - - ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg)); - git_error_set(GIT_ERROR_SSL, "OpenSSL error: failed to load certificates: %s", - errmsg); - - return -1; - } - return 0; -} - -int git_openssl__add_x509_cert(X509 *cert) -{ - X509_STORE *cert_store; - - if (openssl_ensure_initialized() < 0) - return -1; - - if (!(cert_store = SSL_CTX_get_cert_store(git__ssl_ctx))) - return -1; - - if (cert && X509_STORE_add_cert(cert_store, cert) == 0) { - git_error_set(GIT_ERROR_SSL, "OpenSSL error: failed to add raw X509 certificate"); - return -1; - } - - return 0; -} - -int git_openssl__reset_context(void) -{ - shutdown_ssl(); - return openssl_init(); -} - -#else - -#include "stream.h" -#include "git2/sys/openssl.h" - -int git_openssl_stream_global_init(void) -{ - return 0; -} - -int git_openssl_set_locking(void) -{ - git_error_set(GIT_ERROR_SSL, "libgit2 was not built with OpenSSL support"); - return -1; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl.h deleted file mode 100644 index a3ef1a9..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_streams_openssl_h__ -#define INCLUDE_streams_openssl_h__ - -#include "common.h" -#include "streams/openssl_legacy.h" -#include "streams/openssl_dynamic.h" - -#include "git2/sys/stream.h" - -extern int git_openssl_stream_global_init(void); - -#if defined(GIT_OPENSSL) && !defined(GIT_OPENSSL_DYNAMIC) -# include -# include -# include -# include -# endif - -#ifdef GIT_OPENSSL -extern int git_openssl__set_cert_location(const char *file, const char *path); -extern int git_openssl__add_x509_cert(X509 *cert); -extern int git_openssl__reset_context(void); -extern int git_openssl_stream_new(git_stream **out, const char *host, const char *port); -extern int git_openssl_stream_wrap(git_stream **out, git_stream *in, const char *host); -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_dynamic.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_dynamic.c deleted file mode 100644 index fe67952..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_dynamic.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "streams/openssl.h" -#include "streams/openssl_dynamic.h" - -#if defined(GIT_OPENSSL) && defined(GIT_OPENSSL_DYNAMIC) - -#include "runtime.h" - -#include - -unsigned char *(*ASN1_STRING_data)(ASN1_STRING *x); -const unsigned char *(*ASN1_STRING_get0_data)(const ASN1_STRING *x); -int (*ASN1_STRING_length)(const ASN1_STRING *x); -int (*ASN1_STRING_to_UTF8)(unsigned char **out, const ASN1_STRING *in); -int (*ASN1_STRING_type)(const ASN1_STRING *x); - -void *(*BIO_get_data)(BIO *a); -int (*BIO_get_new_index)(void); -int (*OPENSSL_init_ssl)(uint64_t opts, const void *settings); -void (*BIO_meth_free)(BIO_METHOD *biom); -int (*BIO_meth_set_create)(BIO_METHOD *biom, int (*create) (BIO *)); -int (*BIO_meth_set_ctrl)(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *)); -int (*BIO_meth_set_destroy)(BIO_METHOD *biom, int (*destroy) (BIO *)); -int (*BIO_meth_set_gets)(BIO_METHOD *biom, int (*gets) (BIO *, char *, int)); -int (*BIO_meth_set_puts)(BIO_METHOD *biom, int (*puts) (BIO *, const char *)); -int (*BIO_meth_set_read)(BIO_METHOD *biom, int (*read) (BIO *, char *, int)); -int (*BIO_meth_set_write)(BIO_METHOD *biom, int (*write) (BIO *, const char *, int)); -BIO_METHOD *(*BIO_meth_new)(int type, const char *name); -BIO *(*BIO_new)(const BIO_METHOD *type); -void (*BIO_set_data)(BIO *a, void *ptr); -void (*BIO_set_init)(BIO *a, int init); - -void (*CRYPTO_free)(void *ptr, const char *file, int line); -void *(*CRYPTO_malloc)(size_t num, const char *file, int line); -int (*CRYPTO_num_locks)(void); -void (*CRYPTO_set_locking_callback)(void (*func)(int mode, int type, const char *file, int line)); -int (*CRYPTO_set_mem_functions)(void *(*m)(size_t bytes), void *(*r)(void *mem, size_t size), void (*f)(void *mem)); -int (*CRYPTO_THREADID_set_callback)(void (*func)(CRYPTO_THREADID *id)); -void (*CRYPTO_THREADID_set_numeric)(CRYPTO_THREADID *id, unsigned long val); - -char *(*ERR_error_string)(unsigned long e, char *buf); -void (*ERR_error_string_n)(unsigned long e, char *buf, size_t len); -unsigned long (*ERR_get_error)(void); - -int (*SSL_connect)(SSL *ssl); -long (*SSL_ctrl)(SSL *ssl, int cmd, long arg, void *parg); -void (*SSL_free)(SSL *ssl); -int (*SSL_get_error)(SSL *ssl, int ret); -X509 *(*SSL_get_peer_certificate)(const SSL *ssl); -long (*SSL_get_verify_result)(const SSL *ssl); -int (*SSL_library_init)(void); -void (*SSL_load_error_strings)(void); -SSL *(*SSL_new)(SSL_CTX *ctx); -int (*SSL_read)(SSL *ssl, const void *buf, int num); -void (*SSL_set_bio)(SSL *ssl, BIO *rbio, BIO *wbio); -int (*SSL_shutdown)(SSL *ssl); -int (*SSL_write)(SSL *ssl, const void *buf, int num); - -long (*SSL_CTX_ctrl)(SSL_CTX *ctx, int cmd, long larg, void *parg); -void (*SSL_CTX_free)(SSL_CTX *ctx); -SSL_CTX *(*SSL_CTX_new)(const SSL_METHOD *method); -X509_STORE *(*SSL_CTX_get_cert_store)(const SSL_CTX *); -int (*SSL_CTX_set_cipher_list)(SSL_CTX *ctx, const char *str); -int (*SSL_CTX_set_default_verify_paths)(SSL_CTX *ctx); -long (*SSL_CTX_set_options)(SSL_CTX *ctx, long options); -void (*SSL_CTX_set_verify)(SSL_CTX *ctx, int mode, int (*verify_callback)(int, X509_STORE_CTX *)); -int (*SSL_CTX_load_verify_locations)(SSL_CTX *ctx, const char *CAfile, const char *CApath); - -const SSL_METHOD *(*SSLv23_method)(void); -const SSL_METHOD *(*TLS_method)(void); - -ASN1_STRING *(*X509_NAME_ENTRY_get_data)(const X509_NAME_ENTRY *ne); -X509_NAME_ENTRY *(*X509_NAME_get_entry)(X509_NAME *name, int loc); -int (*X509_NAME_get_index_by_NID)(X509_NAME *name, int nid, int lastpos); -void (*X509_free)(X509 *a); -void *(*X509_get_ext_d2i)(const X509 *x, int nid, int *crit, int *idx); -X509_NAME *(*X509_get_subject_name)(const X509 *x); -int (*X509_STORE_add_cert)(X509_STORE *ctx, X509 *x); - -int (*i2d_X509)(X509 *a, unsigned char **ppout); - -int (*OPENSSL_sk_num)(const void *sk); -void *(*OPENSSL_sk_value)(const void *sk, int i); -void (*OPENSSL_sk_free)(void *sk); - -int (*sk_num)(const void *sk); -void *(*sk_value)(const void *sk, int i); -void (*sk_free)(void *sk); - -static void *openssl_handle; - -GIT_INLINE(void *) openssl_sym(int *err, const char *name, bool required) -{ - void *symbol; - - /* if we've seen an err, noop to retain it */ - if (*err) - return NULL; - - - if ((symbol = dlsym(openssl_handle, name)) == NULL && required) { - const char *msg = dlerror(); - git_error_set(GIT_ERROR_SSL, "could not load ssl function '%s': %s", name, msg ? msg : "unknown error"); - *err = -1; - } - - return symbol; -} - -static void dynamic_shutdown(void) -{ - dlclose(openssl_handle); - openssl_handle = NULL; -} - -int git_openssl_stream_dynamic_init(void) -{ - int err = 0; - - if ((openssl_handle = dlopen("libssl.so.1.1", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.1.1.dylib", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.so.1.0.0", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.1.0.0.dylib", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.so.3", RTLD_NOW)) == NULL) { - git_error_set(GIT_ERROR_SSL, "could not load ssl libraries"); - return -1; - } - - ASN1_STRING_data = (unsigned char *(*)(ASN1_STRING *x))openssl_sym(&err, "ASN1_STRING_data", false); - ASN1_STRING_get0_data = (const unsigned char *(*)(const ASN1_STRING *x))openssl_sym(&err, "ASN1_STRING_get0_data", false); - ASN1_STRING_length = (int (*)(const ASN1_STRING *))openssl_sym(&err, "ASN1_STRING_length", true); - ASN1_STRING_to_UTF8 = (int (*)(unsigned char **, const ASN1_STRING *))openssl_sym(&err, "ASN1_STRING_to_UTF8", true); - ASN1_STRING_type = (int (*)(const ASN1_STRING *))openssl_sym(&err, "ASN1_STRING_type", true); - - BIO_get_data = (void *(*)(BIO *))openssl_sym(&err, "BIO_get_data", false); - BIO_get_new_index = (int (*)(void))openssl_sym(&err, "BIO_get_new_index", false); - BIO_meth_free = (void (*)(BIO_METHOD *))openssl_sym(&err, "BIO_meth_free", false); - BIO_meth_new = (BIO_METHOD *(*)(int, const char *))openssl_sym(&err, "BIO_meth_new", false); - BIO_meth_set_create = (int (*)(BIO_METHOD *, int (*)(BIO *)))openssl_sym(&err, "BIO_meth_set_create", false); - BIO_meth_set_ctrl = (int (*)(BIO_METHOD *, long (*)(BIO *, int, long, void *)))openssl_sym(&err, "BIO_meth_set_ctrl", false); - BIO_meth_set_destroy = (int (*)(BIO_METHOD *, int (*)(BIO *)))openssl_sym(&err, "BIO_meth_set_destroy", false); - BIO_meth_set_gets = (int (*)(BIO_METHOD *, int (*)(BIO *, char *, int)))openssl_sym(&err, "BIO_meth_set_gets", false); - BIO_meth_set_puts = (int (*)(BIO_METHOD *, int (*)(BIO *, const char *)))openssl_sym(&err, "BIO_meth_set_puts", false); - BIO_meth_set_read = (int (*)(BIO_METHOD *, int (*)(BIO *, char *, int)))openssl_sym(&err, "BIO_meth_set_read", false); - BIO_meth_set_write = (int (*)(BIO_METHOD *, int (*)(BIO *, const char *, int)))openssl_sym(&err, "BIO_meth_set_write", false); - BIO_new = (BIO *(*)(const BIO_METHOD *))openssl_sym(&err, "BIO_new", true); - BIO_set_data = (void (*)(BIO *a, void *))openssl_sym(&err, "BIO_set_data", false); - BIO_set_init = (void (*)(BIO *a, int))openssl_sym(&err, "BIO_set_init", false); - - CRYPTO_free = (void (*)(void *, const char *, int))openssl_sym(&err, "CRYPTO_free", true); - CRYPTO_malloc = (void *(*)(size_t, const char *, int))openssl_sym(&err, "CRYPTO_malloc", true); - CRYPTO_num_locks = (int (*)(void))openssl_sym(&err, "CRYPTO_num_locks", false); - CRYPTO_set_locking_callback = (void (*)(void (*)(int, int, const char *, int)))openssl_sym(&err, "CRYPTO_set_locking_callback", false); - CRYPTO_set_mem_functions = (int (*)(void *(*)(size_t), void *(*)(void *, size_t), void (*f)(void *)))openssl_sym(&err, "CRYPTO_set_mem_functions", true); - - CRYPTO_THREADID_set_callback = (int (*)(void (*)(CRYPTO_THREADID *)))openssl_sym(&err, "CRYPTO_THREADID_set_callback", false); - CRYPTO_THREADID_set_numeric = (void (*)(CRYPTO_THREADID *, unsigned long))openssl_sym(&err, "CRYPTO_THREADID_set_numeric", false); - - ERR_error_string = (char *(*)(unsigned long, char *))openssl_sym(&err, "ERR_error_string", true); - ERR_error_string_n = (void (*)(unsigned long, char *, size_t))openssl_sym(&err, "ERR_error_string_n", true); - ERR_get_error = (unsigned long (*)(void))openssl_sym(&err, "ERR_get_error", true); - - OPENSSL_init_ssl = (int (*)(uint64_t opts, const void *settings))openssl_sym(&err, "OPENSSL_init_ssl", false); - OPENSSL_sk_num = (int (*)(const void *))openssl_sym(&err, "OPENSSL_sk_num", false); - OPENSSL_sk_value = (void *(*)(const void *sk, int i))openssl_sym(&err, "OPENSSL_sk_value", false); - OPENSSL_sk_free = (void (*)(void *))openssl_sym(&err, "OPENSSL_sk_free", false); - - sk_num = (int (*)(const void *))openssl_sym(&err, "sk_num", false); - sk_value = (void *(*)(const void *sk, int i))openssl_sym(&err, "sk_value", false); - sk_free = (void (*)(void *))openssl_sym(&err, "sk_free", false); - - SSL_connect = (int (*)(SSL *))openssl_sym(&err, "SSL_connect", true); - SSL_ctrl = (long (*)(SSL *, int, long, void *))openssl_sym(&err, "SSL_ctrl", true); - SSL_library_init = (int (*)(void))openssl_sym(&err, "SSL_library_init", false); - SSL_free = (void (*)(SSL *))openssl_sym(&err, "SSL_free", true); - SSL_get_error = (int (*)(SSL *, int))openssl_sym(&err, "SSL_get_error", true); - SSL_get_verify_result = (long (*)(const SSL *ssl))openssl_sym(&err, "SSL_get_verify_result", true); - SSL_load_error_strings = (void (*)(void))openssl_sym(&err, "SSL_load_error_strings", false); - SSL_new = (SSL *(*)(SSL_CTX *))openssl_sym(&err, "SSL_new", true); - SSL_read = (int (*)(SSL *, const void *, int))openssl_sym(&err, "SSL_read", true); - SSL_set_bio = (void (*)(SSL *, BIO *, BIO *))openssl_sym(&err, "SSL_set_bio", true); - SSL_shutdown = (int (*)(SSL *ssl))openssl_sym(&err, "SSL_shutdown", true); - SSL_write = (int (*)(SSL *, const void *, int))openssl_sym(&err, "SSL_write", true); - - if (!(SSL_get_peer_certificate = (X509 *(*)(const SSL *))openssl_sym(&err, "SSL_get_peer_certificate", false))) { - SSL_get_peer_certificate = (X509 *(*)(const SSL *))openssl_sym(&err, "SSL_get1_peer_certificate", true); - } - - SSL_CTX_ctrl = (long (*)(SSL_CTX *, int, long, void *))openssl_sym(&err, "SSL_CTX_ctrl", true); - SSL_CTX_free = (void (*)(SSL_CTX *))openssl_sym(&err, "SSL_CTX_free", true); - SSL_CTX_new = (SSL_CTX *(*)(const SSL_METHOD *))openssl_sym(&err, "SSL_CTX_new", true); - SSL_CTX_get_cert_store = (X509_STORE *(*)(const SSL_CTX *))openssl_sym(&err, "SSL_CTX_get_cert_store", true); - SSL_CTX_set_cipher_list = (int (*)(SSL_CTX *, const char *))openssl_sym(&err, "SSL_CTX_set_cipher_list", true); - SSL_CTX_set_default_verify_paths = (int (*)(SSL_CTX *ctx))openssl_sym(&err, "SSL_CTX_set_default_verify_paths", true); - SSL_CTX_set_options = (long (*)(SSL_CTX *, long))openssl_sym(&err, "SSL_CTX_set_options", false); - SSL_CTX_set_verify = (void (*)(SSL_CTX *, int, int (*)(int, X509_STORE_CTX *)))openssl_sym(&err, "SSL_CTX_set_verify", true); - SSL_CTX_load_verify_locations = (int (*)(SSL_CTX *, const char *, const char *))openssl_sym(&err, "SSL_CTX_load_verify_locations", true); - - SSLv23_method = (const SSL_METHOD *(*)(void))openssl_sym(&err, "SSLv23_method", false); - TLS_method = (const SSL_METHOD *(*)(void))openssl_sym(&err, "TLS_method", false); - - X509_NAME_ENTRY_get_data = (ASN1_STRING *(*)(const X509_NAME_ENTRY *))openssl_sym(&err, "X509_NAME_ENTRY_get_data", true); - X509_NAME_get_entry = (X509_NAME_ENTRY *(*)(X509_NAME *, int))openssl_sym(&err, "X509_NAME_get_entry", true); - X509_NAME_get_index_by_NID = (int (*)(X509_NAME *, int, int))openssl_sym(&err, "X509_NAME_get_index_by_NID", true); - X509_free = (void (*)(X509 *))openssl_sym(&err, "X509_free", true); - X509_get_ext_d2i = (void *(*)(const X509 *x, int nid, int *crit, int *idx))openssl_sym(&err, "X509_get_ext_d2i", true); - X509_get_subject_name = (X509_NAME *(*)(const X509 *))openssl_sym(&err, "X509_get_subject_name", true); - X509_STORE_add_cert = (int (*)(X509_STORE *ctx, X509 *x))openssl_sym(&err, "X509_STORE_add_cert", true); - - i2d_X509 = (int (*)(X509 *a, unsigned char **ppout))openssl_sym(&err, "i2d_X509", true); - - if (err) - goto on_error; - - /* Add legacy functionality */ - if (!OPENSSL_init_ssl) { - OPENSSL_init_ssl = OPENSSL_init_ssl__legacy; - - if (!SSL_library_init || - !SSL_load_error_strings || - !CRYPTO_num_locks || - !CRYPTO_set_locking_callback || - !CRYPTO_THREADID_set_callback || - !CRYPTO_THREADID_set_numeric) { - git_error_set(GIT_ERROR_SSL, "could not load legacy openssl initialization functions"); - goto on_error; - } - } - - if (!SSL_CTX_set_options) - SSL_CTX_set_options = SSL_CTX_set_options__legacy; - - if (TLS_method) - SSLv23_method = TLS_method; - - if (!BIO_meth_new) { - BIO_meth_new = BIO_meth_new__legacy; - BIO_meth_new = BIO_meth_new__legacy; - BIO_meth_free = BIO_meth_free__legacy; - BIO_meth_set_write = BIO_meth_set_write__legacy; - BIO_meth_set_read = BIO_meth_set_read__legacy; - BIO_meth_set_puts = BIO_meth_set_puts__legacy; - BIO_meth_set_gets = BIO_meth_set_gets__legacy; - BIO_meth_set_ctrl = BIO_meth_set_ctrl__legacy; - BIO_meth_set_create = BIO_meth_set_create__legacy; - BIO_meth_set_destroy = BIO_meth_set_destroy__legacy; - BIO_get_new_index = BIO_get_new_index__legacy; - BIO_set_data = BIO_set_data__legacy; - BIO_set_init = BIO_set_init__legacy; - BIO_get_data = BIO_get_data__legacy; - } - - if (!ASN1_STRING_get0_data) { - if (!ASN1_STRING_data) { - git_error_set(GIT_ERROR_SSL, "could not load legacy openssl string function"); - goto on_error; - } - - ASN1_STRING_get0_data = ASN1_STRING_get0_data__legacy; - } - - if ((!OPENSSL_sk_num && !sk_num) || - (!OPENSSL_sk_value && !sk_value) || - (!OPENSSL_sk_free && !sk_free)) { - git_error_set(GIT_ERROR_SSL, "could not load legacy openssl stack functions"); - goto on_error; - } - - if (git_runtime_shutdown_register(dynamic_shutdown) != 0) - goto on_error; - - return 0; - -on_error: - dlclose(openssl_handle); - return -1; -} - - -int sk_GENERAL_NAME_num(const GENERAL_NAME *sk) -{ - if (OPENSSL_sk_num) - return OPENSSL_sk_num(sk); - else if (sk_num) - return sk_num(sk); - - GIT_ASSERT_WITH_RETVAL(false, 0); - return 0; -} - -GENERAL_NAME *sk_GENERAL_NAME_value(const GENERAL_NAME *sk, int i) -{ - if (OPENSSL_sk_value) - return OPENSSL_sk_value(sk, i); - else if (sk_value) - return sk_value(sk, i); - - GIT_ASSERT_WITH_RETVAL(false, NULL); - return NULL; -} - -void GENERAL_NAMES_free(GENERAL_NAME *sk) -{ - if (OPENSSL_sk_free) - OPENSSL_sk_free(sk); - else if (sk_free) - sk_free(sk); -} - -#endif /* GIT_OPENSSL && GIT_OPENSSL_DYNAMIC */ diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_dynamic.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_dynamic.h deleted file mode 100644 index e59f1f9..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_dynamic.h +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are adhered to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the routines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publicly available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ -/* ==================================================================== - * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * - */ -/* ==================================================================== - * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. - * ECC cipher suite support in OpenSSL originally developed by - * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. - */ -/* ==================================================================== - * Copyright 2005 Nokia. All rights reserved. - * - * The portions of the attached software ("Contribution") is developed by - * Nokia Corporation and is licensed pursuant to the OpenSSL open source - * license. - * - * The Contribution, originally written by Mika Kousa and Pasi Eronen of - * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites - * support (see RFC 4279) to OpenSSL. - * - * No patent licenses or other rights except those expressly stated in - * the OpenSSL open source license shall be deemed granted or received - * expressly, by implication, estoppel, or otherwise. - * - * No assurances are provided by Nokia that the Contribution does not - * infringe the patent or other intellectual property rights of any third - * party or that the license provides you with all the necessary rights - * to make use of the Contribution. - * - * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN - * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA - * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY - * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR - * OTHERWISE. - */ - -#ifndef INCLUDE_streams_openssl_dynamic_h__ -#define INCLUDE_streams_openssl_dynamic_h__ - -#ifdef GIT_OPENSSL_DYNAMIC - -# define BIO_CTRL_FLUSH 11 - -# define BIO_TYPE_SOURCE_SINK 0x0400 - -# define CRYPTO_LOCK 1 - -# define GEN_DNS 2 -# define GEN_IPADD 7 - -# define NID_commonName 13 -# define NID_subject_alt_name 85 - -# define SSL_VERIFY_NONE 0x00 - -# define SSL_CTRL_OPTIONS 32 -# define SSL_CTRL_MODE 33 -# define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 - -# define SSL_ERROR_NONE 0 -# define SSL_ERROR_SSL 1 -# define SSL_ERROR_WANT_READ 2 -# define SSL_ERROR_WANT_WRITE 3 -# define SSL_ERROR_WANT_X509_LOOKUP 4 -# define SSL_ERROR_SYSCALL 5 -# define SSL_ERROR_ZERO_RETURN 6 -# define SSL_ERROR_WANT_CONNECT 7 -# define SSL_ERROR_WANT_ACCEPT 8 - -# define SSL_OP_NO_COMPRESSION 0x00020000L -# define SSL_OP_NO_SSLv2 0x01000000L -# define SSL_OP_NO_SSLv3 0x02000000L - -# define SSL_MODE_AUTO_RETRY 0x00000004L - -# define TLSEXT_NAMETYPE_host_name 0 - -# define V_ASN1_UTF8STRING 12 - -# define X509_V_OK 0 - -/* Most of the OpenSSL types are mercifully opaque, so we can treat them like `void *` */ -typedef struct bio_st BIO; -typedef struct bio_method_st BIO_METHOD; -typedef void bio_info_cb; -typedef void * CRYPTO_EX_DATA; -typedef void CRYPTO_THREADID; -typedef void GENERAL_NAMES; -typedef void SSL; -typedef void SSL_CTX; -typedef void SSL_METHOD; -typedef void X509; -typedef void X509_NAME; -typedef void X509_NAME_ENTRY; -typedef void X509_STORE; -typedef void X509_STORE_CTX; - -typedef struct { - int length; - int type; - unsigned char *data; - long flags; -} ASN1_STRING; - -typedef struct { - int type; - union { - char *ptr; - ASN1_STRING *ia5; - } d; -} GENERAL_NAME; - -struct bio_st { - BIO_METHOD *method; - /* bio, mode, argp, argi, argl, ret */ - long (*callback) (struct bio_st *, int, const char *, int, long, long); - char *cb_arg; /* first argument for the callback */ - int init; - int shutdown; - int flags; /* extra storage */ - int retry_reason; - int num; - void *ptr; - struct bio_st *next_bio; /* used by filter BIOs */ - struct bio_st *prev_bio; /* used by filter BIOs */ - int references; - unsigned long num_read; - unsigned long num_write; - CRYPTO_EX_DATA ex_data; -}; - -struct bio_method_st { - int type; - const char *name; - int (*bwrite) (BIO *, const char *, int); - int (*bread) (BIO *, char *, int); - int (*bputs) (BIO *, const char *); - int (*bgets) (BIO *, char *, int); - long (*ctrl) (BIO *, int, long, void *); - int (*create) (BIO *); - int (*destroy) (BIO *); - long (*callback_ctrl) (BIO *, int, bio_info_cb *); -}; - -extern unsigned char *(*ASN1_STRING_data)(ASN1_STRING *x); -extern const unsigned char *(*ASN1_STRING_get0_data)(const ASN1_STRING *x); -extern int (*ASN1_STRING_length)(const ASN1_STRING *x); -extern int (*ASN1_STRING_to_UTF8)(unsigned char **out, const ASN1_STRING *in); -extern int (*ASN1_STRING_type)(const ASN1_STRING *x); - -extern void *(*BIO_get_data)(BIO *a); -extern int (*BIO_get_new_index)(void); -extern int (*OPENSSL_init_ssl)(uint64_t opts, const void *settings); -extern void (*BIO_meth_free)(BIO_METHOD *biom); -extern int (*BIO_meth_set_create)(BIO_METHOD *biom, int (*create) (BIO *)); -extern int (*BIO_meth_set_ctrl)(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *)); -extern int (*BIO_meth_set_destroy)(BIO_METHOD *biom, int (*destroy) (BIO *)); -extern int (*BIO_meth_set_gets)(BIO_METHOD *biom, int (*gets) (BIO *, char *, int)); -extern int (*BIO_meth_set_puts)(BIO_METHOD *biom, int (*puts) (BIO *, const char *)); -extern int (*BIO_meth_set_read)(BIO_METHOD *biom, int (*read) (BIO *, char *, int)); -extern int (*BIO_meth_set_write)(BIO_METHOD *biom, int (*write) (BIO *, const char *, int)); -extern BIO_METHOD *(*BIO_meth_new)(int type, const char *name); -extern BIO *(*BIO_new)(const BIO_METHOD *type); -extern void (*BIO_set_data)(BIO *a, void *ptr); -extern void (*BIO_set_init)(BIO *a, int init); - -extern void (*CRYPTO_free)(void *ptr, const char *file, int line); -extern void *(*CRYPTO_malloc)(size_t num, const char *file, int line); -extern int (*CRYPTO_num_locks)(void); -extern void (*CRYPTO_set_locking_callback)(void (*func)(int mode, int type, const char *file, int line)); -extern int (*CRYPTO_set_mem_functions)(void *(*m)(size_t bytes), void *(*r)(void *mem, size_t size), void (*f)(void *mem)); -extern int (*CRYPTO_THREADID_set_callback)(void (*func)(CRYPTO_THREADID *id)); -extern void (*CRYPTO_THREADID_set_numeric)(CRYPTO_THREADID *id, unsigned long val); - -extern char *(*ERR_error_string)(unsigned long e, char *buf); -extern void (*ERR_error_string_n)(unsigned long e, char *buf, size_t len); -extern unsigned long (*ERR_get_error)(void); - -# define OPENSSL_malloc(num) CRYPTO_malloc(num, __FILE__, __LINE__) -# define OPENSSL_free(addr) CRYPTO_free(addr, __FILE__, __LINE__) - -extern int (*SSL_connect)(SSL *ssl); -extern long (*SSL_ctrl)(SSL *ssl, int cmd, long arg, void *parg); -extern void (*SSL_free)(SSL *ssl); -extern int (*SSL_get_error)(SSL *ssl, int ret); -extern X509 *(*SSL_get_peer_certificate)(const SSL *ssl); -extern long (*SSL_get_verify_result)(const SSL *ssl); -extern int (*SSL_library_init)(void); -extern void (*SSL_load_error_strings)(void); -extern SSL *(*SSL_new)(SSL_CTX *ctx); -extern int (*SSL_read)(SSL *ssl, const void *buf, int num); -extern void (*SSL_set_bio)(SSL *ssl, BIO *rbio, BIO *wbio); -extern int (*SSL_shutdown)(SSL *ssl); -extern int (*SSL_write)(SSL *ssl, const void *buf, int num); - -# define SSL_set_tlsext_host_name(s, name) SSL_ctrl((s), SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, (char *)(name)); - -extern long (*SSL_CTX_ctrl)(SSL_CTX *ctx, int cmd, long larg, void *parg); -extern void (*SSL_CTX_free)(SSL_CTX *ctx); -extern SSL_CTX *(*SSL_CTX_new)(const SSL_METHOD *method); -extern X509_STORE *(*SSL_CTX_get_cert_store)(const SSL_CTX *ctx); -extern int (*SSL_CTX_set_cipher_list)(SSL_CTX *ctx, const char *str); -extern int (*SSL_CTX_set_default_verify_paths)(SSL_CTX *ctx); -extern long (*SSL_CTX_set_options)(SSL_CTX *ctx, long options); -extern void (*SSL_CTX_set_verify)(SSL_CTX *ctx, int mode, int (*verify_callback)(int, X509_STORE_CTX *)); -extern int (*SSL_CTX_load_verify_locations)(SSL_CTX *ctx, const char *CAfile, const char *CApath); - -# define SSL_CTX_set_mode(ctx, mode) SSL_CTX_ctrl((ctx), SSL_CTRL_MODE, (mode), NULL); - -extern const SSL_METHOD *(*SSLv23_method)(void); -extern const SSL_METHOD *(*TLS_method)(void); - -extern ASN1_STRING *(*X509_NAME_ENTRY_get_data)(const X509_NAME_ENTRY *ne); -extern X509_NAME_ENTRY *(*X509_NAME_get_entry)(X509_NAME *name, int loc); -extern int (*X509_NAME_get_index_by_NID)(X509_NAME *name, int nid, int lastpos); -extern void (*X509_free)(X509 *a); -extern void *(*X509_get_ext_d2i)(const X509 *x, int nid, int *crit, int *idx); -extern X509_NAME *(*X509_get_subject_name)(const X509 *x); -extern int (*X509_STORE_add_cert)(X509_STORE *ctx, X509 *x); - -extern int (*i2d_X509)(X509 *a, unsigned char **ppout); - -extern int (*OPENSSL_sk_num)(const void *sk); -extern void *(*OPENSSL_sk_value)(const void *sk, int i); -extern void (*OPENSSL_sk_free)(void *sk); - -extern int (*sk_num)(const void *sk); -extern void *(*sk_value)(const void *sk, int i); -extern void (*sk_free)(void *sk); - -extern int sk_GENERAL_NAME_num(const GENERAL_NAME *sk); -extern GENERAL_NAME *sk_GENERAL_NAME_value(const GENERAL_NAME *sk, int i); -extern void GENERAL_NAMES_free(GENERAL_NAME *sk); - -extern int git_openssl_stream_dynamic_init(void); - -#endif /* GIT_OPENSSL_DYNAMIC */ - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_legacy.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_legacy.c deleted file mode 100644 index e61e6ef..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_legacy.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "streams/openssl.h" -#include "streams/openssl_legacy.h" - -#include "runtime.h" -#include "git2/sys/openssl.h" - -#if defined(GIT_OPENSSL) && !defined(GIT_OPENSSL_DYNAMIC) -# include -# include -# include -# include -#endif - -#if defined(GIT_OPENSSL_LEGACY) || defined(GIT_OPENSSL_DYNAMIC) - -/* - * OpenSSL 1.1 made BIO opaque so we have to use functions to interact with it - * which do not exist in previous versions. We define these inline functions so - * we can program against the interface instead of littering the implementation - * with ifdefs. We do the same for OPENSSL_init_ssl. - */ - -int OPENSSL_init_ssl__legacy(uint64_t opts, const void *settings) -{ - GIT_UNUSED(opts); - GIT_UNUSED(settings); - SSL_load_error_strings(); - SSL_library_init(); - return 0; -} - -BIO_METHOD *BIO_meth_new__legacy(int type, const char *name) -{ - BIO_METHOD *meth = git__calloc(1, sizeof(BIO_METHOD)); - if (!meth) { - return NULL; - } - - meth->type = type; - meth->name = name; - - return meth; -} - -void BIO_meth_free__legacy(BIO_METHOD *biom) -{ - git__free(biom); -} - -int BIO_meth_set_write__legacy(BIO_METHOD *biom, int (*write) (BIO *, const char *, int)) -{ - biom->bwrite = write; - return 1; -} - -int BIO_meth_set_read__legacy(BIO_METHOD *biom, int (*read) (BIO *, char *, int)) -{ - biom->bread = read; - return 1; -} - -int BIO_meth_set_puts__legacy(BIO_METHOD *biom, int (*puts) (BIO *, const char *)) -{ - biom->bputs = puts; - return 1; -} - -int BIO_meth_set_gets__legacy(BIO_METHOD *biom, int (*gets) (BIO *, char *, int)) - -{ - biom->bgets = gets; - return 1; -} - -int BIO_meth_set_ctrl__legacy(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *)) -{ - biom->ctrl = ctrl; - return 1; -} - -int BIO_meth_set_create__legacy(BIO_METHOD *biom, int (*create) (BIO *)) -{ - biom->create = create; - return 1; -} - -int BIO_meth_set_destroy__legacy(BIO_METHOD *biom, int (*destroy) (BIO *)) -{ - biom->destroy = destroy; - return 1; -} - -int BIO_get_new_index__legacy(void) -{ - /* This exists as of 1.1 so before we'd just have 0 */ - return 0; -} - -void BIO_set_init__legacy(BIO *b, int init) -{ - b->init = init; -} - -void BIO_set_data__legacy(BIO *a, void *ptr) -{ - a->ptr = ptr; -} - -void *BIO_get_data__legacy(BIO *a) -{ - return a->ptr; -} - -const unsigned char *ASN1_STRING_get0_data__legacy(const ASN1_STRING *x) -{ - return ASN1_STRING_data((ASN1_STRING *)x); -} - -long SSL_CTX_set_options__legacy(SSL_CTX *ctx, long op) -{ - return SSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, op, NULL); -} - -# if defined(GIT_THREADS) -static git_mutex *openssl_locks; - -static void openssl_locking_function(int mode, int n, const char *file, int line) -{ - int lock; - - GIT_UNUSED(file); - GIT_UNUSED(line); - - lock = mode & CRYPTO_LOCK; - - if (lock) - (void)git_mutex_lock(&openssl_locks[n]); - else - git_mutex_unlock(&openssl_locks[n]); -} - -static void shutdown_ssl_locking(void) -{ - int num_locks, i; - - num_locks = CRYPTO_num_locks(); - CRYPTO_set_locking_callback(NULL); - - for (i = 0; i < num_locks; ++i) - git_mutex_free(&openssl_locks[i]); - git__free(openssl_locks); -} - -static void threadid_cb(CRYPTO_THREADID *threadid) -{ - GIT_UNUSED(threadid); - CRYPTO_THREADID_set_numeric(threadid, git_thread_currentid()); -} - -int git_openssl_set_locking(void) -{ - int num_locks, i; - -#ifndef GIT_THREADS - git_error_set(GIT_ERROR_THREAD, "libgit2 was not built with threads"); - return -1; -#endif - -#ifdef GIT_OPENSSL_DYNAMIC - /* - * This function is required on legacy versions of OpenSSL; when building - * with dynamically-loaded OpenSSL, we detect whether we loaded it or not. - */ - if (!CRYPTO_set_locking_callback) - return 0; -#endif - - CRYPTO_THREADID_set_callback(threadid_cb); - - num_locks = CRYPTO_num_locks(); - openssl_locks = git__calloc(num_locks, sizeof(git_mutex)); - GIT_ERROR_CHECK_ALLOC(openssl_locks); - - for (i = 0; i < num_locks; i++) { - if (git_mutex_init(&openssl_locks[i]) != 0) { - git_error_set(GIT_ERROR_SSL, "failed to initialize openssl locks"); - return -1; - } - } - - CRYPTO_set_locking_callback(openssl_locking_function); - return git_runtime_shutdown_register(shutdown_ssl_locking); -} -#endif /* GIT_THREADS */ - -#endif /* GIT_OPENSSL_LEGACY || GIT_OPENSSL_DYNAMIC */ diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_legacy.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_legacy.h deleted file mode 100644 index e6dae95..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/openssl_legacy.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_streams_openssl_legacy_h__ -#define INCLUDE_streams_openssl_legacy_h__ - -#include "streams/openssl_dynamic.h" - -#if defined(GIT_OPENSSL) && !defined(GIT_OPENSSL_DYNAMIC) -# include -# include -# include -# include - -# if (defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L) || \ - (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) -# define GIT_OPENSSL_LEGACY -# endif -#endif - -#if defined(GIT_OPENSSL_LEGACY) && !defined(GIT_OPENSSL_DYNAMIC) -# define OPENSSL_init_ssl OPENSSL_init_ssl__legacy -# define BIO_meth_new BIO_meth_new__legacy -# define BIO_meth_free BIO_meth_free__legacy -# define BIO_meth_set_write BIO_meth_set_write__legacy -# define BIO_meth_set_read BIO_meth_set_read__legacy -# define BIO_meth_set_puts BIO_meth_set_puts__legacy -# define BIO_meth_set_gets BIO_meth_set_gets__legacy -# define BIO_meth_set_ctrl BIO_meth_set_ctrl__legacy -# define BIO_meth_set_create BIO_meth_set_create__legacy -# define BIO_meth_set_destroy BIO_meth_set_destroy__legacy -# define BIO_get_new_index BIO_get_new_index__legacy -# define BIO_set_data BIO_set_data__legacy -# define BIO_set_init BIO_set_init__legacy -# define BIO_get_data BIO_get_data__legacy -# define ASN1_STRING_get0_data ASN1_STRING_get0_data__legacy -#endif - -#if defined(GIT_OPENSSL_LEGACY) || defined(GIT_OPENSSL_DYNAMIC) - -extern int OPENSSL_init_ssl__legacy(uint64_t opts, const void *settings); -extern BIO_METHOD *BIO_meth_new__legacy(int type, const char *name); -extern void BIO_meth_free__legacy(BIO_METHOD *biom); -extern int BIO_meth_set_write__legacy(BIO_METHOD *biom, int (*write) (BIO *, const char *, int)); -extern int BIO_meth_set_read__legacy(BIO_METHOD *biom, int (*read) (BIO *, char *, int)); -extern int BIO_meth_set_puts__legacy(BIO_METHOD *biom, int (*puts) (BIO *, const char *)); -extern int BIO_meth_set_gets__legacy(BIO_METHOD *biom, int (*gets) (BIO *, char *, int)); -extern int BIO_meth_set_ctrl__legacy(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *)); -extern int BIO_meth_set_create__legacy(BIO_METHOD *biom, int (*create) (BIO *)); -extern int BIO_meth_set_destroy__legacy(BIO_METHOD *biom, int (*destroy) (BIO *)); -extern int BIO_get_new_index__legacy(void); -extern void BIO_set_data__legacy(BIO *a, void *ptr); -extern void BIO_set_init__legacy(BIO *b, int init); -extern void *BIO_get_data__legacy(BIO *a); -extern const unsigned char *ASN1_STRING_get0_data__legacy(const ASN1_STRING *x); -extern long SSL_CTX_set_options__legacy(SSL_CTX *ctx, long op); - -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/registry.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/registry.c deleted file mode 100644 index e60e1cd..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/registry.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "streams/registry.h" - -#include "runtime.h" -#include "streams/tls.h" -#include "streams/mbedtls.h" -#include "streams/openssl.h" -#include "streams/stransport.h" - -struct stream_registry { - git_rwlock lock; - git_stream_registration callbacks; - git_stream_registration tls_callbacks; -}; - -static struct stream_registry stream_registry; - -static void shutdown_stream_registry(void) -{ - git_rwlock_free(&stream_registry.lock); -} - -int git_stream_registry_global_init(void) -{ - if (git_rwlock_init(&stream_registry.lock) < 0) - return -1; - - return git_runtime_shutdown_register(shutdown_stream_registry); -} - -GIT_INLINE(void) stream_registration_cpy( - git_stream_registration *target, - git_stream_registration *src) -{ - if (src) - memcpy(target, src, sizeof(git_stream_registration)); - else - memset(target, 0, sizeof(git_stream_registration)); -} - -int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type) -{ - git_stream_registration *target; - int error = GIT_ENOTFOUND; - - GIT_ASSERT_ARG(out); - - switch(type) { - case GIT_STREAM_STANDARD: - target = &stream_registry.callbacks; - break; - case GIT_STREAM_TLS: - target = &stream_registry.tls_callbacks; - break; - default: - git_error_set(GIT_ERROR_INVALID, "invalid stream type"); - return -1; - } - - if (git_rwlock_rdlock(&stream_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock stream registry"); - return -1; - } - - if (target->init) { - stream_registration_cpy(out, target); - error = 0; - } - - git_rwlock_rdunlock(&stream_registry.lock); - return error; -} - -int git_stream_register(git_stream_t type, git_stream_registration *registration) -{ - GIT_ASSERT(!registration || registration->init); - - GIT_ERROR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration"); - - if (git_rwlock_wrlock(&stream_registry.lock) < 0) { - git_error_set(GIT_ERROR_OS, "failed to lock stream registry"); - return -1; - } - - if ((type & GIT_STREAM_STANDARD) == GIT_STREAM_STANDARD) - stream_registration_cpy(&stream_registry.callbacks, registration); - - if ((type & GIT_STREAM_TLS) == GIT_STREAM_TLS) - stream_registration_cpy(&stream_registry.tls_callbacks, registration); - - git_rwlock_wrunlock(&stream_registry.lock); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_stream_register_tls( - int GIT_CALLBACK(ctor)(git_stream **out, const char *host, const char *port)) -{ - git_stream_registration registration = {0}; - - if (ctor) { - registration.version = GIT_STREAM_VERSION; - registration.init = ctor; - registration.wrap = NULL; - - return git_stream_register(GIT_STREAM_TLS, ®istration); - } else { - return git_stream_register(GIT_STREAM_TLS, NULL); - } -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/registry.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/registry.h deleted file mode 100644 index adc2b8b..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/registry.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_streams_registry_h__ -#define INCLUDE_streams_registry_h__ - -#include "common.h" -#include "git2/sys/stream.h" - -/** Configure stream registry. */ -int git_stream_registry_global_init(void); - -/** Lookup a stream registration. */ -extern int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/schannel.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/schannel.c deleted file mode 100644 index f096158..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/schannel.c +++ /dev/null @@ -1,715 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "streams/schannel.h" - -#ifdef GIT_SCHANNEL - -#define SECURITY_WIN32 - -#include -#include -#include - -#include "stream.h" -#include "streams/socket.h" - -#ifndef SP_PROT_TLS1_2_CLIENT -# define SP_PROT_TLS1_2_CLIENT 2048 -#endif - -#ifndef SP_PROT_TLS1_3_CLIENT -# define SP_PROT_TLS1_3_CLIENT 8192 -#endif - -#ifndef SECBUFFER_ALERT -# define SECBUFFER_ALERT 17 -#endif - -#define READ_BLOCKSIZE (16 * 1024) - -typedef enum { - STATE_NONE = 0, - STATE_CRED = 1, - STATE_CONTEXT = 2, - STATE_CERTIFICATE = 3 -} schannel_state; - -typedef struct { - git_stream parent; - git_stream *io; - int owned; - bool connected; - wchar_t *host_w; - - schannel_state state; - - CredHandle cred; - CtxtHandle context; - SecPkgContext_StreamSizes stream_sizes; - - CERT_CONTEXT *certificate; - const CERT_CHAIN_CONTEXT *cert_chain; - git_cert_x509 x509; - - git_str plaintext_in; - git_str ciphertext_in; -} schannel_stream; - -static int connect_context(schannel_stream *st) -{ - SCHANNEL_CRED cred = { 0 }; - SECURITY_STATUS status = SEC_E_INTERNAL_ERROR; - DWORD context_flags; - static size_t MAX_RETRIES = 1024; - size_t retries; - ssize_t read_len; - int error = 0; - - if (st->owned && (error = git_stream_connect(st->io)) < 0) - return error; - - cred.dwVersion = SCHANNEL_CRED_VERSION; - cred.dwFlags = SCH_CRED_IGNORE_NO_REVOCATION_CHECK | - SCH_CRED_IGNORE_REVOCATION_OFFLINE | - SCH_CRED_MANUAL_CRED_VALIDATION | - SCH_CRED_NO_DEFAULT_CREDS | - SCH_CRED_NO_SERVERNAME_CHECK; - cred.grbitEnabledProtocols = SP_PROT_TLS1_2_CLIENT | - SP_PROT_TLS1_3_CLIENT; - - if (AcquireCredentialsHandleW(NULL, SCHANNEL_NAME_W, - SECPKG_CRED_OUTBOUND, NULL, &cred, NULL, - NULL, &st->cred, NULL) != SEC_E_OK) { - git_error_set(GIT_ERROR_OS, "could not acquire credentials handle"); - return -1; - } - - st->state = STATE_CRED; - - context_flags = ISC_REQ_ALLOCATE_MEMORY | - ISC_REQ_CONFIDENTIALITY | - ISC_REQ_REPLAY_DETECT | - ISC_REQ_SEQUENCE_DETECT | - ISC_REQ_STREAM; - - for (retries = 0; retries < MAX_RETRIES; retries++) { - SecBuffer input_buf[] = { - { (unsigned long)st->ciphertext_in.size, - SECBUFFER_TOKEN, - st->ciphertext_in.size ? st->ciphertext_in.ptr : NULL }, - { 0, SECBUFFER_EMPTY, NULL } - }; - SecBuffer output_buf[] = { { 0, SECBUFFER_TOKEN, NULL }, - { 0, SECBUFFER_ALERT, NULL } }; - - SecBufferDesc input_buf_desc = { SECBUFFER_VERSION, 2, input_buf }; - SecBufferDesc output_buf_desc = { SECBUFFER_VERSION, 2, output_buf }; - - status = InitializeSecurityContextW(&st->cred, - retries ? &st->context : NULL, st->host_w, - context_flags, 0, 0, retries ? &input_buf_desc : NULL, 0, - retries ? NULL : &st->context, &output_buf_desc, - &context_flags, NULL); - - if (status == SEC_E_OK || status == SEC_I_CONTINUE_NEEDED) { - st->state = STATE_CONTEXT; - - if (output_buf[0].cbBuffer > 0) { - error = git_stream__write_full(st->io, - output_buf[0].pvBuffer, - output_buf[0].cbBuffer, 0); - - FreeContextBuffer(output_buf[0].pvBuffer); - } - - /* handle any leftover, unprocessed data */ - if (input_buf[1].BufferType == SECBUFFER_EXTRA) { - GIT_ASSERT(st->ciphertext_in.size > input_buf[1].cbBuffer); - - git_str_consume_bytes(&st->ciphertext_in, - st->ciphertext_in.size - input_buf[1].cbBuffer); - } else { - git_str_clear(&st->ciphertext_in); - } - - if (error < 0 || status == SEC_E_OK) - break; - } else if (status == SEC_E_INCOMPLETE_MESSAGE) { - /* we need additional data from the client; */ - if (git_str_grow_by(&st->ciphertext_in, READ_BLOCKSIZE) < 0) { - error = -1; - break; - } - - if ((read_len = git_stream_read(st->io, - st->ciphertext_in.ptr + st->ciphertext_in.size, - (st->ciphertext_in.asize - st->ciphertext_in.size))) < 0) { - error = -1; - break; - } - - GIT_ASSERT((size_t)read_len <= - st->ciphertext_in.asize - st->ciphertext_in.size); - st->ciphertext_in.size += read_len; - } else { - git_error_set(GIT_ERROR_OS, - "could not initialize security context"); - error = -1; - break; - } - - GIT_ASSERT(st->ciphertext_in.size < ULONG_MAX); - } - - if (retries == MAX_RETRIES) { - git_error_set(GIT_ERROR_SSL, - "could not initialize security context: too many retries"); - error = -1; - } - - if (!error) { - if (QueryContextAttributesW(&st->context, - SECPKG_ATTR_STREAM_SIZES, - &st->stream_sizes) != SEC_E_OK) { - git_error_set(GIT_ERROR_SSL, - "could not query stream sizes"); - error = -1; - } - } - - return error; -} - -static int set_certificate_lookup_error(DWORD status) -{ - switch (status) { - case CERT_TRUST_IS_NOT_TIME_VALID: - git_error_set(GIT_ERROR_SSL, - "certificate is expired or not yet valid"); - break; - case CERT_TRUST_IS_REVOKED: - git_error_set(GIT_ERROR_SSL, "certificate is revoked"); - break; - case CERT_TRUST_IS_NOT_SIGNATURE_VALID: - case CERT_TRUST_IS_NOT_VALID_FOR_USAGE: - case CERT_TRUST_INVALID_EXTENSION: - case CERT_TRUST_INVALID_POLICY_CONSTRAINTS: - case CERT_TRUST_INVALID_BASIC_CONSTRAINTS: - case CERT_TRUST_INVALID_NAME_CONSTRAINTS: - case CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT: - case CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT: - case CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT: - case CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT: - case CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY: - case CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT: - git_error_set(GIT_ERROR_SSL, "certificate is not valid"); - break; - case CERT_TRUST_IS_UNTRUSTED_ROOT: - case CERT_TRUST_IS_CYCLIC: - case CERT_TRUST_IS_EXPLICIT_DISTRUST: - git_error_set(GIT_ERROR_SSL, "certificate is not trusted"); - break; - case CERT_TRUST_REVOCATION_STATUS_UNKNOWN: - git_error_set(GIT_ERROR_SSL, - "certificate revocation status could not be verified"); - break; - case CERT_TRUST_IS_OFFLINE_REVOCATION: - git_error_set(GIT_ERROR_SSL, - "certificate revocation is offline or stale"); - break; - case CERT_TRUST_HAS_WEAK_SIGNATURE: - git_error_set(GIT_ERROR_SSL, "certificate has a weak signature"); - break; - default: - git_error_set(GIT_ERROR_SSL, - "unknown certificate lookup failure: %d", status); - return -1; - } - - return GIT_ECERTIFICATE; -} - -static int set_certificate_validation_error(DWORD status) -{ - switch (status) { - case TRUST_E_CERT_SIGNATURE: - git_error_set(GIT_ERROR_SSL, - "the certificate cannot be verified"); - break; - case CRYPT_E_REVOKED: - git_error_set(GIT_ERROR_SSL, - "the certificate or signature has been revoked"); - break; - case CERT_E_UNTRUSTEDROOT: - git_error_set(GIT_ERROR_SSL, - "the certificate root is not trusted"); - break; - case CERT_E_UNTRUSTEDTESTROOT: - git_error_set(GIT_ERROR_SSL, - "the certificate root is a test certificate"); - break; - case CERT_E_CHAINING: - git_error_set(GIT_ERROR_SSL, - "the certificate chain is invalid"); - break; - case CERT_E_WRONG_USAGE: - case CERT_E_PURPOSE: - git_error_set(GIT_ERROR_SSL, - "the certificate is not valid for this usage"); - break; - case CERT_E_EXPIRED: - git_error_set(GIT_ERROR_SSL, - "certificate is expired or not yet valid"); - break; - case CERT_E_INVALID_NAME: - case CERT_E_CN_NO_MATCH: - git_error_set(GIT_ERROR_SSL, - "certificate is not valid for this hostname"); - break; - case CERT_E_INVALID_POLICY: - case TRUST_E_BASIC_CONSTRAINTS: - case CERT_E_CRITICAL: - case CERT_E_VALIDITYPERIODNESTING: - git_error_set(GIT_ERROR_SSL, "certificate is not valid"); - break; - case CRYPT_E_NO_REVOCATION_CHECK: - git_error_set(GIT_ERROR_SSL, - "certificate revocation status could not be verified"); - break; - case CRYPT_E_REVOCATION_OFFLINE: - git_error_set(GIT_ERROR_SSL, - "certificate revocation is offline or stale"); - break; - case CERT_E_ROLE: - git_error_set(GIT_ERROR_SSL, "certificate authority is not valid"); - break; - default: - git_error_set(GIT_ERROR_SSL, - "unknown certificate policy checking failure: %d", - status); - return -1; - } - - return GIT_ECERTIFICATE; -} - -static int check_certificate(schannel_stream* st) -{ - CERT_CHAIN_PARA cert_chain_parameters; - SSL_EXTRA_CERT_CHAIN_POLICY_PARA ssl_policy_parameters; - CERT_CHAIN_POLICY_PARA cert_policy_parameters = - { sizeof(CERT_CHAIN_POLICY_PARA), 0, &ssl_policy_parameters }; - CERT_CHAIN_POLICY_STATUS cert_policy_status; - - memset(&cert_chain_parameters, 0, sizeof(CERT_CHAIN_PARA)); - cert_chain_parameters.cbSize = sizeof(CERT_CHAIN_PARA); - - if (QueryContextAttributesW(&st->context, - SECPKG_ATTR_REMOTE_CERT_CONTEXT, - &st->certificate) != SEC_E_OK) { - git_error_set(GIT_ERROR_OS, - "could not query remote certificate context"); - return -1; - } - - /* TODO: do we really want to do revokcation checking ? */ - if (!CertGetCertificateChain(NULL, st->certificate, NULL, - st->certificate->hCertStore, &cert_chain_parameters, - CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT, - NULL, &st->cert_chain)) { - git_error_set(GIT_ERROR_OS, "could not query remote certificate chain"); - CertFreeCertificateContext(st->certificate); - return -1; - } - - st->state = STATE_CERTIFICATE; - - /* Set up the x509 certificate data for future callbacks */ - - st->x509.parent.cert_type = GIT_CERT_X509; - st->x509.data = st->certificate->pbCertEncoded; - st->x509.len = st->certificate->cbCertEncoded; - - /* Handle initial certificate validation */ - - if (st->cert_chain->TrustStatus.dwErrorStatus != CERT_TRUST_NO_ERROR) - return set_certificate_lookup_error(st->cert_chain->TrustStatus.dwErrorStatus); - - ssl_policy_parameters.cbSize = sizeof(SSL_EXTRA_CERT_CHAIN_POLICY_PARA); - ssl_policy_parameters.dwAuthType = AUTHTYPE_SERVER; - ssl_policy_parameters.pwszServerName = st->host_w; - - if (!CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_SSL, - st->cert_chain, &cert_policy_parameters, - &cert_policy_status)) { - git_error_set(GIT_ERROR_OS, "could not verify certificate chain policy"); - return -1; - } - - if (cert_policy_status.dwError != SEC_E_OK) - return set_certificate_validation_error(cert_policy_status.dwError); - - return 0; -} - -static int schannel_connect(git_stream *stream) -{ - schannel_stream *st = (schannel_stream *)stream; - int error; - - GIT_ASSERT(st->state == STATE_NONE); - - if ((error = connect_context(st)) < 0 || - (error = check_certificate(st)) < 0) - return error; - - st->connected = 1; - return 0; -} - -static int schannel_certificate(git_cert **out, git_stream *stream) -{ - schannel_stream *st = (schannel_stream *)stream; - - *out = &st->x509.parent; - return 0; -} - -static int schannel_set_proxy( - git_stream *stream, - const git_proxy_options *proxy_options) -{ - schannel_stream *st = (schannel_stream *)stream; - return git_stream_set_proxy(st->io, proxy_options); -} - -static ssize_t schannel_write( - git_stream *stream, - const char *data, - size_t data_len, - int flags) -{ - schannel_stream *st = (schannel_stream *)stream; - SecBuffer encrypt_buf[3]; - SecBufferDesc encrypt_buf_desc = { SECBUFFER_VERSION, 3, encrypt_buf }; - git_str ciphertext_out = GIT_STR_INIT; - ssize_t total_len = 0; - - GIT_UNUSED(flags); - - if (data_len > SSIZE_MAX) - data_len = SSIZE_MAX; - - git_str_init(&ciphertext_out, - st->stream_sizes.cbHeader + - st->stream_sizes.cbMaximumMessage + - st->stream_sizes.cbTrailer); - - while (data_len > 0) { - size_t message_len = min(data_len, st->stream_sizes.cbMaximumMessage); - size_t ciphertext_len, ciphertext_written = 0; - - encrypt_buf[0].BufferType = SECBUFFER_STREAM_HEADER; - encrypt_buf[0].cbBuffer = st->stream_sizes.cbHeader; - encrypt_buf[0].pvBuffer = ciphertext_out.ptr; - - encrypt_buf[1].BufferType = SECBUFFER_DATA; - encrypt_buf[1].cbBuffer = (unsigned long)message_len; - encrypt_buf[1].pvBuffer = - ciphertext_out.ptr + st->stream_sizes.cbHeader; - - encrypt_buf[2].BufferType = SECBUFFER_STREAM_TRAILER; - encrypt_buf[2].cbBuffer = st->stream_sizes.cbTrailer; - encrypt_buf[2].pvBuffer = - ciphertext_out.ptr + st->stream_sizes.cbHeader + - message_len; - - memcpy(ciphertext_out.ptr + st->stream_sizes.cbHeader, data, message_len); - - if (EncryptMessage(&st->context, 0, &encrypt_buf_desc, 0) != SEC_E_OK) { - git_error_set(GIT_ERROR_OS, "could not encrypt tls message"); - total_len = -1; - goto done; - } - - ciphertext_len = encrypt_buf[0].cbBuffer + - encrypt_buf[1].cbBuffer + - encrypt_buf[2].cbBuffer; - - while (ciphertext_written < ciphertext_len) { - ssize_t chunk_len = git_stream_write(st->io, - ciphertext_out.ptr + ciphertext_written, - ciphertext_len - ciphertext_written, 0); - - if (chunk_len < 0) { - total_len = -1; - goto done; - } - - ciphertext_len -= chunk_len; - ciphertext_written += chunk_len; - } - - total_len += message_len; - - data += message_len; - data_len -= message_len; - } - -done: - git_str_dispose(&ciphertext_out); - return total_len; -} - -static ssize_t schannel_read(git_stream *stream, void *_data, size_t data_len) -{ - schannel_stream *st = (schannel_stream *)stream; - char *data = (char *)_data; - SecBuffer decrypt_buf[4]; - SecBufferDesc decrypt_buf_desc = { SECBUFFER_VERSION, 4, decrypt_buf }; - SECURITY_STATUS status; - ssize_t chunk_len, total_len = 0; - - if (data_len > SSIZE_MAX) - data_len = SSIZE_MAX; - - /* - * Loop until we have some bytes to return - we may have decrypted - * bytes queued or ciphertext from the wire that we can decrypt and - * return. Return any queued bytes if they're available to avoid a - * network read, which may block. We may return less than the - * caller requested, and they can retry for an actual network - */ - while ((size_t)total_len < data_len) { - if (st->plaintext_in.size > 0) { - size_t copy_len = min(st->plaintext_in.size, data_len); - - memcpy(data, st->plaintext_in.ptr, copy_len); - git_str_consume_bytes(&st->plaintext_in, copy_len); - - data += copy_len; - data_len -= copy_len; - - total_len += copy_len; - - continue; - } - - if (st->ciphertext_in.size > 0) { - decrypt_buf[0].BufferType = SECBUFFER_DATA; - decrypt_buf[0].cbBuffer = (unsigned long)min(st->ciphertext_in.size, ULONG_MAX); - decrypt_buf[0].pvBuffer = st->ciphertext_in.ptr; - - decrypt_buf[1].BufferType = SECBUFFER_EMPTY; - decrypt_buf[1].cbBuffer = 0; - decrypt_buf[1].pvBuffer = NULL; - - decrypt_buf[2].BufferType = SECBUFFER_EMPTY; - decrypt_buf[2].cbBuffer = 0; - decrypt_buf[2].pvBuffer = NULL; - - decrypt_buf[3].BufferType = SECBUFFER_EMPTY; - decrypt_buf[3].cbBuffer = 0; - decrypt_buf[3].pvBuffer = NULL; - - status = DecryptMessage(&st->context, &decrypt_buf_desc, 0, NULL); - - if (status == SEC_E_OK) { - GIT_ASSERT(decrypt_buf[0].BufferType == SECBUFFER_STREAM_HEADER); - GIT_ASSERT(decrypt_buf[1].BufferType == SECBUFFER_DATA); - GIT_ASSERT(decrypt_buf[2].BufferType == SECBUFFER_STREAM_TRAILER); - - if (git_str_put(&st->plaintext_in, decrypt_buf[1].pvBuffer, decrypt_buf[1].cbBuffer) < 0) { - total_len = -1; - goto done; - } - - if (decrypt_buf[3].BufferType == SECBUFFER_EXTRA) { - git_str_consume_bytes(&st->ciphertext_in, (st->ciphertext_in.size - decrypt_buf[3].cbBuffer)); - } else { - git_str_clear(&st->ciphertext_in); - } - - continue; - } else if (status == SEC_E_CONTEXT_EXPIRED) { - break; - } else if (status != SEC_E_INCOMPLETE_MESSAGE) { - git_error_set(GIT_ERROR_SSL, "could not decrypt tls message"); - total_len = -1; - goto done; - } - } - - if (total_len != 0) - break; - - if (git_str_grow_by(&st->ciphertext_in, READ_BLOCKSIZE) < 0) { - total_len = -1; - goto done; - } - - if ((chunk_len = git_stream_read(st->io, st->ciphertext_in.ptr + st->ciphertext_in.size, st->ciphertext_in.asize - st->ciphertext_in.size)) < 0) { - total_len = -1; - goto done; - } - - st->ciphertext_in.size += chunk_len; - } - -done: - return total_len; -} - -static int schannel_close(git_stream *stream) -{ - schannel_stream *st = (schannel_stream *)stream; - int error = 0; - - if (st->connected) { - SecBuffer shutdown_buf; - SecBufferDesc shutdown_buf_desc = - { SECBUFFER_VERSION, 1, &shutdown_buf }; - DWORD shutdown_message = SCHANNEL_SHUTDOWN, shutdown_flags; - - shutdown_buf.BufferType = SECBUFFER_TOKEN; - shutdown_buf.cbBuffer = sizeof(DWORD); - shutdown_buf.pvBuffer = &shutdown_message; - - if (ApplyControlToken(&st->context, &shutdown_buf_desc) != SEC_E_OK) { - git_error_set(GIT_ERROR_SSL, "could not shutdown stream"); - error = -1; - } - - shutdown_buf.BufferType = SECBUFFER_TOKEN; - shutdown_buf.cbBuffer = 0; - shutdown_buf.pvBuffer = NULL; - - shutdown_flags = ISC_REQ_ALLOCATE_MEMORY | - ISC_REQ_CONFIDENTIALITY | - ISC_REQ_REPLAY_DETECT | - ISC_REQ_SEQUENCE_DETECT | - ISC_REQ_STREAM; - - if (InitializeSecurityContext(&st->cred, &st->context, - NULL, shutdown_flags, 0, 0, - &shutdown_buf_desc, 0, NULL, - &shutdown_buf_desc, &shutdown_flags, - NULL) == SEC_E_OK) { - if (shutdown_buf.cbBuffer > 0) { - if (git_stream__write_full(st->io, - shutdown_buf.pvBuffer, - shutdown_buf.cbBuffer, 0) < 0) - error = -1; - - FreeContextBuffer(shutdown_buf.pvBuffer); - } - } - } - - st->connected = false; - - if (st->owned && git_stream_close(st->io) < 0) - error = -1; - - return error; -} - -static void schannel_free(git_stream *stream) -{ - schannel_stream *st = (schannel_stream *)stream; - - if (st->state >= STATE_CERTIFICATE) { - CertFreeCertificateContext(st->certificate); - CertFreeCertificateChain(st->cert_chain); - } - - if (st->state >= STATE_CONTEXT) - DeleteSecurityContext(&st->context); - - if (st->state >= STATE_CRED) - FreeCredentialsHandle(&st->cred); - - st->state = STATE_NONE; - - git_str_dispose(&st->ciphertext_in); - git_str_dispose(&st->plaintext_in); - - git__free(st->host_w); - - if (st->owned) - git_stream_free(st->io); - - git__free(st); -} - -static int schannel_stream_wrap( - git_stream **out, - git_stream *in, - const char *host, - int owned) -{ - schannel_stream *st; - - st = git__calloc(1, sizeof(schannel_stream)); - GIT_ERROR_CHECK_ALLOC(st); - - st->io = in; - st->owned = owned; - - if (git_utf8_to_16_alloc(&st->host_w, host) < 0) { - git__free(st); - return -1; - } - - st->parent.version = GIT_STREAM_VERSION; - st->parent.encrypted = 1; - st->parent.proxy_support = git_stream_supports_proxy(st->io); - st->parent.connect = schannel_connect; - st->parent.certificate = schannel_certificate; - st->parent.set_proxy = schannel_set_proxy; - st->parent.read = schannel_read; - st->parent.write = schannel_write; - st->parent.close = schannel_close; - st->parent.free = schannel_free; - - *out = (git_stream *)st; - return 0; -} - -extern int git_schannel_stream_new( - git_stream **out, - const char *host, - const char *port) -{ - git_stream *stream; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(host); - GIT_ASSERT_ARG(port); - - if ((error = git_socket_stream_new(&stream, host, port)) < 0) - return error; - - if ((error = schannel_stream_wrap(out, stream, host, 1)) < 0) { - git_stream_close(stream); - git_stream_free(stream); - } - - return error; -} - -extern int git_schannel_stream_wrap( - git_stream **out, - git_stream *in, - const char *host) -{ - return schannel_stream_wrap(out, in, host, 0); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/schannel.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/schannel.h deleted file mode 100644 index 3584970..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/schannel.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_steams_schannel_h__ -#define INCLUDE_steams_schannel_h__ - -#include "common.h" - -#include "git2/sys/stream.h" - -#ifdef GIT_SCHANNEL - -extern int git_schannel_stream_new( - git_stream **out, - const char *host, - const char *port); - -extern int git_schannel_stream_wrap( - git_stream **out, - git_stream *in, - const char *host); - -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/socket.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/socket.c deleted file mode 100644 index d064f86..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/socket.c +++ /dev/null @@ -1,458 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "streams/socket.h" - -#include "posix.h" -#include "registry.h" -#include "runtime.h" -#include "stream.h" - -#ifndef _WIN32 -# include -# include -# include -# include -# include -# include -# include -# include -# ifdef __APPLE__ -# include -# endif -#else -# include -# include -# ifdef _MSC_VER -# pragma comment(lib, "ws2_32") -# endif -#endif - -int git_socket_stream__connect_timeout = 0; -int git_socket_stream__timeout = 0; - -#ifdef GIT_WIN32 -static void net_set_error(const char *str) -{ - int error = WSAGetLastError(); - char * win32_error = git_win32_get_error_message(error); - - if (win32_error) { - git_error_set(GIT_ERROR_NET, "%s: %s", str, win32_error); - git__free(win32_error); - } else { - git_error_set(GIT_ERROR_NET, "%s", str); - } -} -#else -static void net_set_error(const char *str) -{ - git_error_set(GIT_ERROR_NET, "%s: %s", str, strerror(errno)); -} -#endif - -static int close_socket(GIT_SOCKET s) -{ - if (s == INVALID_SOCKET) - return 0; - -#ifdef GIT_WIN32 - if (closesocket(s) != 0) { - net_set_error("could not close socket"); - return -1; - } - - return 0; -#else - return close(s); -#endif - -} - -static int set_nonblocking(GIT_SOCKET s) -{ -#ifdef GIT_WIN32 - unsigned long nonblocking = 1; - - if (ioctlsocket(s, FIONBIO, &nonblocking) != 0) { - net_set_error("could not set socket non-blocking"); - return -1; - } -#else - int flags; - - if ((flags = fcntl(s, F_GETFL, 0)) == -1) { - net_set_error("could not query socket flags"); - return -1; - } - - flags |= O_NONBLOCK; - - if (fcntl(s, F_SETFL, flags) != 0) { - net_set_error("could not set socket non-blocking"); - return -1; - } -#endif - - return 0; -} - -/* Promote a sockerr to an errno for our error handling routines */ -static int handle_sockerr(GIT_SOCKET socket) -{ - int sockerr; - socklen_t errlen = sizeof(sockerr); - - if (getsockopt(socket, SOL_SOCKET, SO_ERROR, - (void *)&sockerr, &errlen) < 0) - return -1; - - if (sockerr == ETIMEDOUT) - return GIT_TIMEOUT; - - errno = sockerr; - return -1; -} - -GIT_INLINE(bool) connect_would_block(int error) -{ -#ifdef GIT_WIN32 - if (error == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) - return true; -#endif - - if (error == -1 && errno == EINPROGRESS) - return true; - - return false; -} - -static int connect_with_timeout( - GIT_SOCKET socket, - const struct sockaddr *address, - socklen_t address_len, - int timeout) -{ - struct pollfd fd; - int error; - - if (timeout && (error = set_nonblocking(socket)) < 0) - return error; - - error = connect(socket, address, address_len); - - if (error == 0 || !connect_would_block(error)) - return error; - - fd.fd = socket; - fd.events = POLLOUT; - fd.revents = 0; - - error = p_poll(&fd, 1, timeout); - - if (error == 0) { - return GIT_TIMEOUT; - } else if (error != 1) { - return -1; - } else if ((fd.revents & (POLLPRI | POLLHUP | POLLERR))) { - return handle_sockerr(socket); - } else if ((fd.revents & POLLOUT) != POLLOUT) { - git_error_set(GIT_ERROR_NET, - "unknown error while polling for connect: %d", - fd.revents); - return -1; - } - - return 0; -} - -static int socket_connect(git_stream *stream) -{ - git_socket_stream *st = (git_socket_stream *) stream; - GIT_SOCKET s = INVALID_SOCKET; - struct addrinfo *info = NULL, *p; - struct addrinfo hints; - int error; - - memset(&hints, 0x0, sizeof(struct addrinfo)); - hints.ai_socktype = SOCK_STREAM; - hints.ai_family = AF_UNSPEC; - - if ((error = p_getaddrinfo(st->host, st->port, &hints, &info)) != 0) { - git_error_set(GIT_ERROR_NET, - "failed to resolve address for %s: %s", - st->host, p_gai_strerror(error)); - return -1; - } - - for (p = info; p != NULL; p = p->ai_next) { - s = socket(p->ai_family, p->ai_socktype | SOCK_CLOEXEC, p->ai_protocol); - - /* Enable TCP keepalive to detect dead connections */ - if (s != INVALID_SOCKET && p->ai_family == AF_INET) { - int keepalive = 1; - if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, - (const char *)&keepalive, sizeof(keepalive)) == 0) { -#ifdef __APPLE__ - /* macOS: Set idle time to 60 seconds */ - int keepidle = 60; - setsockopt(s, IPPROTO_TCP, TCP_KEEPALIVE, - &keepidle, sizeof(keepidle)); - /* Note: TCP_CONNECTIONTIMEOUT (0x20) could also be set */ -#elif defined(__linux__) - /* Linux: Set idle, interval, and count */ - int keepidle = 60; /* Start probes after 60 seconds */ - int keepintvl = 10; /* 10 seconds between probes */ - int keepcnt = 3; /* 3 probes before giving up */ - setsockopt(s, IPPROTO_TCP, TCP_KEEPIDLE, - &keepidle, sizeof(keepidle)); - setsockopt(s, IPPROTO_TCP, TCP_KEEPINTVL, - &keepintvl, sizeof(keepintvl)); - setsockopt(s, IPPROTO_TCP, TCP_KEEPCNT, - &keepcnt, sizeof(keepcnt)); -#endif - } - } - - if (s == INVALID_SOCKET) - continue; - - error = connect_with_timeout(s, p->ai_addr, - (socklen_t)p->ai_addrlen, - st->parent.connect_timeout); - - if (error == 0) - break; - - /* If we can't connect, try the next one */ - close_socket(s); - s = INVALID_SOCKET; - - if (error == GIT_TIMEOUT) - break; - } - - /* Oops, we couldn't connect to any address */ - if (s == INVALID_SOCKET) { - if (error == GIT_TIMEOUT) - git_error_set(GIT_ERROR_NET, "failed to connect to %s: Operation timed out", st->host); - else - git_error_set(GIT_ERROR_OS, "failed to connect to %s", st->host); - error = -1; - goto done; - } - - if (st->parent.timeout && !st->parent.connect_timeout && - (error = set_nonblocking(s)) < 0) - return error; - - st->s = s; - error = 0; - -done: - p_freeaddrinfo(info); - return error; -} - -static ssize_t socket_write( - git_stream *stream, - const char *data, - size_t len, - int flags) -{ - git_socket_stream *st = (git_socket_stream *) stream; - struct pollfd fd; - ssize_t ret; - - GIT_ASSERT(flags == 0); - GIT_UNUSED(flags); - - ret = p_send(st->s, data, len, 0); - - if (st->parent.timeout && ret < 0 && - (errno == EAGAIN || errno != EWOULDBLOCK)) { - fd.fd = st->s; - fd.events = POLLOUT; - fd.revents = 0; - - ret = p_poll(&fd, 1, st->parent.timeout); - - if (ret == 1) { - ret = p_send(st->s, data, len, 0); - } else if (ret == 0) { - git_error_set(GIT_ERROR_NET, - "could not write to socket: timed out"); - return GIT_TIMEOUT; - } - } - - if (ret < 0) { - net_set_error("error receiving data from socket"); - return -1; - } - - return ret; -} - -static ssize_t socket_read( - git_stream *stream, - void *data, - size_t len) -{ - git_socket_stream *st = (git_socket_stream *) stream; - struct pollfd fd; - ssize_t ret; - - ret = p_recv(st->s, data, len, 0); - - if (st->parent.timeout && ret < 0 && - (errno == EAGAIN || errno != EWOULDBLOCK)) { - fd.fd = st->s; - fd.events = POLLIN; - fd.revents = 0; - - ret = p_poll(&fd, 1, st->parent.timeout); - - if (ret == 1) { - ret = p_recv(st->s, data, len, 0); - } else if (ret == 0) { - git_error_set(GIT_ERROR_NET, - "could not read from socket: timed out"); - return GIT_TIMEOUT; - } - } - - if (ret < 0) { - net_set_error("error receiving data from socket"); - return -1; - } - - return ret; -} - -static int socket_close(git_stream *stream) -{ - git_socket_stream *st = (git_socket_stream *) stream; - int error; - - error = close_socket(st->s); - st->s = INVALID_SOCKET; - - return error; -} - -static void socket_free(git_stream *stream) -{ - git_socket_stream *st = (git_socket_stream *) stream; - - git__free(st->host); - git__free(st->port); - git__free(st); -} - -static int default_socket_stream_new( - git_stream **out, - const char *host, - const char *port) -{ - git_socket_stream *st; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(host); - GIT_ASSERT_ARG(port); - - st = git__calloc(1, sizeof(git_socket_stream)); - GIT_ERROR_CHECK_ALLOC(st); - - st->host = git__strdup(host); - GIT_ERROR_CHECK_ALLOC(st->host); - - if (port) { - st->port = git__strdup(port); - GIT_ERROR_CHECK_ALLOC(st->port); - } - - st->parent.version = GIT_STREAM_VERSION; - st->parent.timeout = git_socket_stream__timeout; - st->parent.connect_timeout = git_socket_stream__connect_timeout; - st->parent.connect = socket_connect; - st->parent.write = socket_write; - st->parent.read = socket_read; - st->parent.close = socket_close; - st->parent.free = socket_free; - st->s = INVALID_SOCKET; - - *out = (git_stream *) st; - return 0; -} - -int git_socket_stream_new( - git_stream **out, - const char *host, - const char *port) -{ - int (*init)(git_stream **, const char *, const char *) = NULL; - git_stream_registration custom = {0}; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(host); - GIT_ASSERT_ARG(port); - - if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_STANDARD)) == 0) - init = custom.init; - else if (error == GIT_ENOTFOUND) - init = default_socket_stream_new; - else - return error; - - if (!init) { - git_error_set(GIT_ERROR_NET, "there is no socket stream available"); - return -1; - } - - return init(out, host, port); -} - -#ifdef GIT_WIN32 - -static void socket_stream_global_shutdown(void) -{ - WSACleanup(); -} - -int git_socket_stream_global_init(void) -{ - WORD winsock_version; - WSADATA wsa_data; - - winsock_version = MAKEWORD(2, 2); - - if (WSAStartup(winsock_version, &wsa_data) != 0) { - git_error_set(GIT_ERROR_OS, "could not initialize Windows Socket Library"); - return -1; - } - - if (LOBYTE(wsa_data.wVersion) != 2 || - HIBYTE(wsa_data.wVersion) != 2) { - git_error_set(GIT_ERROR_SSL, "Windows Socket Library does not support Winsock 2.2"); - return -1; - } - - return git_runtime_shutdown_register(socket_stream_global_shutdown); -} - -#else - -#include "stream.h" - -int git_socket_stream_global_init(void) -{ - return 0; -} - - #endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/socket.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/socket.h deleted file mode 100644 index 73e8de0..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/socket.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_streams_socket_h__ -#define INCLUDE_streams_socket_h__ - -#include "common.h" - -#include "stream.h" - -typedef struct { - git_stream parent; - char *host; - char *port; - GIT_SOCKET s; -} git_socket_stream; - -extern int git_socket_stream_new(git_stream **out, const char *host, const char *port); - -extern int git_socket_stream_global_init(void); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/stransport.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/stransport.c deleted file mode 100644 index 863616d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/stransport.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "streams/stransport.h" - -#ifdef GIT_SECURE_TRANSPORT - -#include -#include -#include - -#include "common.h" -#include "trace.h" -#include "git2/transport.h" -#include "streams/socket.h" - -static int stransport_error(OSStatus ret) -{ - CFStringRef message_ref = NULL; - const char *message_cstr = NULL; - char *message_ptr = NULL; - - if (ret == noErr || ret == errSSLClosedGraceful) { - git_error_clear(); - return 0; - } - -#if !TARGET_OS_IPHONE - message_ref = SecCopyErrorMessageString(ret, NULL); - GIT_ERROR_CHECK_ALLOC(message_ref); - - /* - * Attempt the cheap CFString conversion; this can return NULL - * when that would be expensive. In that case, call the more - * expensive function. - */ - message_cstr = CFStringGetCStringPtr(message_ref, kCFStringEncodingUTF8); - - if (!message_cstr) { - /* Provide buffer to convert from UTF16 to UTF8 */ - size_t message_size = CFStringGetLength(message_ref) * 2 + 1; - - message_cstr = message_ptr = git__malloc(message_size); - GIT_ERROR_CHECK_ALLOC(message_ptr); - - if (!CFStringGetCString(message_ref, message_ptr, message_size, kCFStringEncodingUTF8)) { - git_error_set(GIT_ERROR_NET, "SecureTransport error: %d", (unsigned int)ret); - goto done; - } - } - - git_error_set(GIT_ERROR_NET, "SecureTransport error: %s", message_cstr); - -done: - git__free(message_ptr); - CFRelease(message_ref); -#else - git_error_set(GIT_ERROR_NET, "SecureTransport error: OSStatus %d", (unsigned int)ret); - GIT_UNUSED(message_ref); - GIT_UNUSED(message_cstr); - GIT_UNUSED(message_ptr); -#endif - - return -1; -} - -typedef struct { - git_stream parent; - git_stream *io; - int owned; - int error; - SSLContextRef ctx; - CFDataRef der_data; - git_cert_x509 cert_info; -} stransport_stream; - -static int stransport_connect(git_stream *stream) -{ - stransport_stream *st = (stransport_stream *) stream; - int error; - SecTrustRef trust = NULL; - SecTrustResultType sec_res; - OSStatus ret; - - if (st->owned && (error = git_stream_connect(st->io)) < 0) - return error; - - ret = SSLHandshake(st->ctx); - - if (ret != errSSLServerAuthCompleted && st->error != 0) - return -1; - else if (ret != errSSLServerAuthCompleted) { - git_error_set(GIT_ERROR_SSL, "unexpected return value from ssl handshake %d", (int)ret); - return -1; - } - - if ((ret = SSLCopyPeerTrust(st->ctx, &trust)) != noErr) - goto on_error; - - if (!trust) - return GIT_ECERTIFICATE; - - if ((ret = SecTrustEvaluate(trust, &sec_res)) != noErr) - goto on_error; - - CFRelease(trust); - - if (sec_res == kSecTrustResultInvalid || sec_res == kSecTrustResultOtherError) { - git_error_set(GIT_ERROR_SSL, "internal security trust error"); - return -1; - } - - if (sec_res == kSecTrustResultDeny || sec_res == kSecTrustResultRecoverableTrustFailure || - sec_res == kSecTrustResultFatalTrustFailure) { - git_error_set(GIT_ERROR_SSL, "untrusted connection error"); - return GIT_ECERTIFICATE; - } - - return 0; - -on_error: - if (trust) - CFRelease(trust); - - return stransport_error(ret); -} - -static int stransport_certificate(git_cert **out, git_stream *stream) -{ - stransport_stream *st = (stransport_stream *) stream; - SecTrustRef trust = NULL; - SecCertificateRef sec_cert; - OSStatus ret; - - if ((ret = SSLCopyPeerTrust(st->ctx, &trust)) != noErr) - return stransport_error(ret); - - sec_cert = SecTrustGetCertificateAtIndex(trust, 0); - st->der_data = SecCertificateCopyData(sec_cert); - CFRelease(trust); - - if (st->der_data == NULL) { - git_error_set(GIT_ERROR_SSL, "retrieved invalid certificate data"); - return -1; - } - - st->cert_info.parent.cert_type = GIT_CERT_X509; - st->cert_info.data = (void *) CFDataGetBytePtr(st->der_data); - st->cert_info.len = CFDataGetLength(st->der_data); - - *out = (git_cert *)&st->cert_info; - return 0; -} - -static int stransport_set_proxy( - git_stream *stream, - const git_proxy_options *proxy_opts) -{ - stransport_stream *st = (stransport_stream *) stream; - - return git_stream_set_proxy(st->io, proxy_opts); -} - -/* - * Contrary to typical network IO callbacks, Secure Transport write callback is - * expected to write *all* passed data, not just as much as it can, and any - * other case would be considered a failure. - * - * This behavior is actually not specified in the Apple documentation, but is - * required for things to work correctly (and incidentally, that's also how - * Apple implements it in its projects at opensource.apple.com). - * - * Libgit2 streams happen to already have this very behavior so this is just - * passthrough. - */ -static OSStatus write_cb(SSLConnectionRef conn, const void *data, size_t *len) -{ - stransport_stream *st = (stransport_stream *)conn; - git_stream *io = st->io; - OSStatus ret; - - st->error = 0; - - ret = git_stream__write_full(io, data, *len, 0); - - if (ret < 0) { - st->error = ret; - return (ret == GIT_TIMEOUT) ? - -9853 /* errSSLNetworkTimeout */: - -36 /* ioErr */; - } - - return noErr; -} - -static ssize_t stransport_write(git_stream *stream, const char *data, size_t len, int flags) -{ - stransport_stream *st = (stransport_stream *) stream; - size_t data_len, processed; - OSStatus ret; - - GIT_UNUSED(flags); - - data_len = min(len, SSIZE_MAX); - if ((ret = SSLWrite(st->ctx, data, data_len, &processed)) != noErr) { - if (st->error == GIT_TIMEOUT) - return GIT_TIMEOUT; - - return stransport_error(ret); - } - - GIT_ASSERT(processed < SSIZE_MAX); - return (ssize_t)processed; -} - -/* - * Contrary to typical network IO callbacks, Secure Transport read callback is - * expected to read *exactly* the requested number of bytes, not just as much - * as it can, and any other case would be considered a failure. - * - * This behavior is actually not specified in the Apple documentation, but is - * required for things to work correctly (and incidentally, that's also how - * Apple implements it in its projects at opensource.apple.com). - */ -static OSStatus read_cb(SSLConnectionRef conn, void *data, size_t *len) -{ - stransport_stream *st = (stransport_stream *)conn; - git_stream *io = st->io; - OSStatus error = noErr; - size_t off = 0; - ssize_t ret; - - st->error = 0; - - do { - ret = git_stream_read(io, data + off, *len - off); - - if (ret < 0) { - st->error = ret; - error = (ret == GIT_TIMEOUT) ? - -9853 /* errSSLNetworkTimeout */: - -36 /* ioErr */; - break; - } else if (ret == 0) { - error = errSSLClosedGraceful; - break; - } - - off += ret; - } while (off < *len); - - *len = off; - return error; -} - -static ssize_t stransport_read(git_stream *stream, void *data, size_t len) -{ - stransport_stream *st = (stransport_stream *)stream; - size_t processed; - OSStatus ret; - - if ((ret = SSLRead(st->ctx, data, len, &processed)) != noErr) { - /* This specific SecureTransport error is not well described */ - if (ret == -9806) - git_trace(GIT_TRACE_INFO, "SecureTraceport error during SSLRead: returned -9806 (connection closed via error)"); - - if (st->error == GIT_TIMEOUT) - return GIT_TIMEOUT; - - return stransport_error(ret); - } - - return processed; -} - -static int stransport_close(git_stream *stream) -{ - stransport_stream *st = (stransport_stream *) stream; - OSStatus ret; - - ret = SSLClose(st->ctx); - if (ret != noErr && ret != errSSLClosedGraceful) - return stransport_error(ret); - - return st->owned ? git_stream_close(st->io) : 0; -} - -static void stransport_free(git_stream *stream) -{ - stransport_stream *st = (stransport_stream *) stream; - - if (st->owned) - git_stream_free(st->io); - - CFRelease(st->ctx); - if (st->der_data) - CFRelease(st->der_data); - git__free(st); -} - -static int stransport_wrap( - git_stream **out, - git_stream *in, - const char *host, - int owned) -{ - stransport_stream *st; - OSStatus ret; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(in); - GIT_ASSERT_ARG(host); - - st = git__calloc(1, sizeof(stransport_stream)); - GIT_ERROR_CHECK_ALLOC(st); - - st->io = in; - st->owned = owned; - - st->ctx = SSLCreateContext(NULL, kSSLClientSide, kSSLStreamType); - if (!st->ctx) { - git_error_set(GIT_ERROR_NET, "failed to create SSL context"); - git__free(st); - return -1; - } - - if ((ret = SSLSetIOFuncs(st->ctx, read_cb, write_cb)) != noErr || - (ret = SSLSetConnection(st->ctx, st)) != noErr || - (ret = SSLSetSessionOption(st->ctx, kSSLSessionOptionBreakOnServerAuth, true)) != noErr || - (ret = SSLSetProtocolVersionMin(st->ctx, kTLSProtocol1)) != noErr || - (ret = SSLSetProtocolVersionMax(st->ctx, kTLSProtocol12)) != noErr || - (ret = SSLSetPeerDomainName(st->ctx, host, strlen(host))) != noErr) { - CFRelease(st->ctx); - git__free(st); - return stransport_error(ret); - } - - st->parent.version = GIT_STREAM_VERSION; - st->parent.encrypted = 1; - st->parent.proxy_support = git_stream_supports_proxy(st->io); - st->parent.connect = stransport_connect; - st->parent.certificate = stransport_certificate; - st->parent.set_proxy = stransport_set_proxy; - st->parent.read = stransport_read; - st->parent.write = stransport_write; - st->parent.close = stransport_close; - st->parent.free = stransport_free; - - *out = (git_stream *) st; - return 0; -} - -int git_stransport_stream_wrap( - git_stream **out, - git_stream *in, - const char *host) -{ - return stransport_wrap(out, in, host, 0); -} - -int git_stransport_stream_new(git_stream **out, const char *host, const char *port) -{ - git_stream *stream = NULL; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(host); - - error = git_socket_stream_new(&stream, host, port); - - if (!error) - error = stransport_wrap(out, stream, host, 1); - - if (error < 0 && stream) { - git_stream_close(stream); - git_stream_free(stream); - } - - return error; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/stransport.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/stransport.h deleted file mode 100644 index 1026e20..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/stransport.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_streams_stransport_h__ -#define INCLUDE_streams_stransport_h__ - -#include "common.h" - -#include "git2/sys/stream.h" - -#ifdef GIT_SECURE_TRANSPORT - -extern int git_stransport_stream_new(git_stream **out, const char *host, const char *port); -extern int git_stransport_stream_wrap(git_stream **out, git_stream *in, const char *host); - -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/tls.c b/vendor/libgit2-sys/libgit2/src/libgit2/streams/tls.c deleted file mode 100644 index 246ac9c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/tls.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2/errors.h" - -#include "common.h" -#include "streams/registry.h" -#include "streams/tls.h" -#include "streams/mbedtls.h" -#include "streams/openssl.h" -#include "streams/stransport.h" -#include "streams/schannel.h" - -int git_tls_stream_new(git_stream **out, const char *host, const char *port) -{ - int (*init)(git_stream **, const char *, const char *) = NULL; - git_stream_registration custom = {0}; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(host); - GIT_ASSERT_ARG(port); - - if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_TLS)) == 0) { - init = custom.init; - } else if (error == GIT_ENOTFOUND) { -#ifdef GIT_SECURE_TRANSPORT - init = git_stransport_stream_new; -#elif defined(GIT_OPENSSL) - init = git_openssl_stream_new; -#elif defined(GIT_MBEDTLS) - init = git_mbedtls_stream_new; -#elif defined(GIT_SCHANNEL) - init = git_schannel_stream_new; -#endif - } else { - return error; - } - - if (!init) { - git_error_set(GIT_ERROR_SSL, "there is no TLS stream available"); - return -1; - } - - return init(out, host, port); -} - -int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host) -{ - int (*wrap)(git_stream **, git_stream *, const char *) = NULL; - git_stream_registration custom = {0}; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(in); - - if (git_stream_registry_lookup(&custom, GIT_STREAM_TLS) == 0) { - wrap = custom.wrap; - } else { -#ifdef GIT_SECURE_TRANSPORT - wrap = git_stransport_stream_wrap; -#elif defined(GIT_OPENSSL) - wrap = git_openssl_stream_wrap; -#elif defined(GIT_MBEDTLS) - wrap = git_mbedtls_stream_wrap; -#elif defined(GIT_SCHANNEL) - wrap = git_schannel_stream_wrap; -#endif - } - - if (!wrap) { - git_error_set(GIT_ERROR_SSL, "there is no TLS stream available"); - return -1; - } - - return wrap(out, in, host); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/streams/tls.h b/vendor/libgit2-sys/libgit2/src/libgit2/streams/tls.h deleted file mode 100644 index 465a6ea..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/streams/tls.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_streams_tls_h__ -#define INCLUDE_streams_tls_h__ - -#include "common.h" - -#include "git2/sys/stream.h" - -/** - * Create a TLS stream with the most appropriate backend available for - * the current platform, whether that's SecureTransport on macOS, - * OpenSSL or mbedTLS on other Unixes, or something else entirely. - */ -extern int git_tls_stream_new(git_stream **out, const char *host, const char *port); - -/** - * Create a TLS stream on top of an existing insecure stream, using - * the most appropriate backend available for the current platform. - * - * This allows us to create a CONNECT stream on top of a proxy; - * using SecureTransport on macOS, OpenSSL or mbedTLS on other - * Unixes, or something else entirely. - */ -extern int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/submodule.c b/vendor/libgit2-sys/libgit2/src/libgit2/submodule.c deleted file mode 100644 index c64521c..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/submodule.c +++ /dev/null @@ -1,2499 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "submodule.h" - -#include "buf.h" -#include "branch.h" -#include "vector.h" -#include "posix.h" -#include "config_backend.h" -#include "config.h" -#include "repository.h" -#include "tree.h" -#include "iterator.h" -#include "fs_path.h" -#include "str.h" -#include "index.h" -#include "worktree.h" -#include "clone.h" -#include "path.h" - -#include "git2/config.h" -#include "git2/sys/config.h" -#include "git2/types.h" -#include "git2/index.h" - -#define GIT_MODULES_FILE ".gitmodules" - -static git_configmap _sm_update_map[] = { - {GIT_CONFIGMAP_STRING, "checkout", GIT_SUBMODULE_UPDATE_CHECKOUT}, - {GIT_CONFIGMAP_STRING, "rebase", GIT_SUBMODULE_UPDATE_REBASE}, - {GIT_CONFIGMAP_STRING, "merge", GIT_SUBMODULE_UPDATE_MERGE}, - {GIT_CONFIGMAP_STRING, "none", GIT_SUBMODULE_UPDATE_NONE}, - {GIT_CONFIGMAP_FALSE, NULL, GIT_SUBMODULE_UPDATE_NONE}, - {GIT_CONFIGMAP_TRUE, NULL, GIT_SUBMODULE_UPDATE_CHECKOUT}, -}; - -static git_configmap _sm_ignore_map[] = { - {GIT_CONFIGMAP_STRING, "none", GIT_SUBMODULE_IGNORE_NONE}, - {GIT_CONFIGMAP_STRING, "untracked", GIT_SUBMODULE_IGNORE_UNTRACKED}, - {GIT_CONFIGMAP_STRING, "dirty", GIT_SUBMODULE_IGNORE_DIRTY}, - {GIT_CONFIGMAP_STRING, "all", GIT_SUBMODULE_IGNORE_ALL}, - {GIT_CONFIGMAP_FALSE, NULL, GIT_SUBMODULE_IGNORE_NONE}, - {GIT_CONFIGMAP_TRUE, NULL, GIT_SUBMODULE_IGNORE_ALL}, -}; - -static git_configmap _sm_recurse_map[] = { - {GIT_CONFIGMAP_STRING, "on-demand", GIT_SUBMODULE_RECURSE_ONDEMAND}, - {GIT_CONFIGMAP_FALSE, NULL, GIT_SUBMODULE_RECURSE_NO}, - {GIT_CONFIGMAP_TRUE, NULL, GIT_SUBMODULE_RECURSE_YES}, -}; - -enum { - CACHE_OK = 0, - CACHE_REFRESH = 1, - CACHE_FLUSH = 2 -}; -enum { - GITMODULES_EXISTING = 0, - GITMODULES_CREATE = 1 -}; - -static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name); -static git_config_backend *open_gitmodules(git_repository *repo, int gitmod); -static int gitmodules_snapshot(git_config **snap, git_repository *repo); -static int get_url_base(git_str *url, git_repository *repo); -static int lookup_head_remote_key(git_str *remote_key, git_repository *repo); -static int lookup_default_remote(git_remote **remote, git_repository *repo); -static int submodule_load_each(const git_config_entry *entry, void *payload); -static int submodule_read_config(git_submodule *sm, git_config *cfg); -static int submodule_load_from_wd_lite(git_submodule *); -static void submodule_get_index_status(unsigned int *, git_submodule *); -static void submodule_get_wd_status(unsigned int *, git_submodule *, git_repository *, git_submodule_ignore_t); -static void submodule_update_from_index_entry(git_submodule *sm, const git_index_entry *ie); -static void submodule_update_from_head_data(git_submodule *sm, mode_t mode, const git_oid *id); -static int path_is_valid(git_repository *repo, const char *path); - -static int submodule_cmp(const void *a, const void *b) -{ - return strcmp(((git_submodule *)a)->name, ((git_submodule *)b)->name); -} - -static int submodule_config_key_trunc_puts(git_str *key, const char *suffix) -{ - ssize_t idx = git_str_rfind(key, '.'); - git_str_truncate(key, (size_t)(idx + 1)); - return git_str_puts(key, suffix); -} - -/* - * PUBLIC APIS - */ - -static void submodule_set_lookup_error(int error, const char *name) -{ - if (!error) - return; - - git_error_set(GIT_ERROR_SUBMODULE, (error == GIT_ENOTFOUND) ? - "no submodule named '%s'" : - "submodule '%s' has not been added yet", name); -} - -typedef struct { - const char *path; - char *name; -} fbp_data; - -static int find_by_path(const git_config_entry *entry, void *payload) -{ - fbp_data *data = payload; - - if (!strcmp(entry->value, data->path)) { - const char *fdot, *ldot; - fdot = strchr(entry->name, '.'); - ldot = strrchr(entry->name, '.'); - data->name = git__strndup(fdot + 1, ldot - fdot - 1); - GIT_ERROR_CHECK_ALLOC(data->name); - } - - return 0; -} - -/* - * Checks to see if the submodule shares its name with a file or directory that - * already exists on the index. If so, the submodule cannot be added. - */ -static int is_path_occupied(bool *occupied, git_repository *repo, const char *path) -{ - int error = 0; - git_index *index; - git_str dir = GIT_STR_INIT; - *occupied = false; - - if ((error = git_repository_index__weakptr(&index, repo)) < 0) - goto out; - - if ((error = git_index_find(NULL, index, path)) != GIT_ENOTFOUND) { - if (!error) { - git_error_set(GIT_ERROR_SUBMODULE, - "File '%s' already exists in the index", path); - *occupied = true; - } - goto out; - } - - if ((error = git_str_sets(&dir, path)) < 0) - goto out; - - if ((error = git_fs_path_to_dir(&dir)) < 0) - goto out; - - if ((error = git_index_find_prefix(NULL, index, dir.ptr)) != GIT_ENOTFOUND) { - if (!error) { - git_error_set(GIT_ERROR_SUBMODULE, - "Directory '%s' already exists in the index", path); - *occupied = true; - } - goto out; - } - - error = 0; - -out: - git_str_dispose(&dir); - return error; -} - -GIT_HASHMAP_STR_SETUP(git_submodule_namemap, char *); - -/** - * Release the name map returned by 'load_submodule_names'. - */ -static void free_submodule_names(git_submodule_namemap *names) -{ - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - const char *key; - char *value; - - if (names == NULL) - return; - - while (git_submodule_namemap_iterate(&iter, &key, &value, names) == 0) { - git__free((char *)key); - git__free(value); - } - - git_submodule_namemap_dispose(names); - git__free(names); - - return; -} - -/** - * Map submodule paths to names. - * TODO: for some use-cases, this might need case-folding on a - * case-insensitive filesystem - */ -static int load_submodule_names(git_submodule_namemap **out, git_repository *repo, git_config *cfg) -{ - const char *key = "^submodule\\..*\\.path$"; - char *value; - git_config_iterator *iter = NULL; - git_config_entry *entry; - git_str buf = GIT_STR_INIT; - git_submodule_namemap *names; - int isvalid, error; - - *out = NULL; - - if ((names = git__calloc(1, sizeof(git_submodule_namemap))) == NULL) { - error = -1; - goto out; - } - - if ((error = git_config_iterator_glob_new(&iter, cfg, key)) < 0) - goto out; - - while ((error = git_config_next(&entry, iter)) == 0) { - const char *fdot, *ldot; - - fdot = strchr(entry->name, '.'); - ldot = strrchr(entry->name, '.'); - - if (git_submodule_namemap_contains(names, entry->value)) { - git_error_set(GIT_ERROR_SUBMODULE, - "duplicated submodule path '%s'", entry->value); - error = -1; - goto out; - } - - git_str_clear(&buf); - git_str_put(&buf, fdot + 1, ldot - fdot - 1); - - isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0); - if (isvalid < 0) { - error = isvalid; - goto out; - } - if (!isvalid) - continue; - - isvalid = path_is_valid(repo, entry->value); - if (isvalid < 0) { - error = isvalid; - goto out; - } - if (!isvalid) - continue; - - if ((value = git__strdup(entry->value)) == NULL) { - error = -1; - goto out; - } - - if ((error = git_submodule_namemap_put(names, value, git_str_detach(&buf))) < 0) { - git_error_set(GIT_ERROR_NOMEMORY, "error inserting submodule into hash table"); - error = -1; - goto out; - } - } - if (error == GIT_ITEROVER) - error = 0; - - *out = names; - names = NULL; - -out: - free_submodule_names(names); - git_str_dispose(&buf); - git_config_iterator_free(iter); - return error; -} - -GIT_HASHMAP_STR_FUNCTIONS(git_submodule_cache, GIT_HASHMAP_INLINE, git_submodule *); - -int git_submodule__map(git_submodule_cache *cache, git_repository *repo); - -int git_submodule_cache_init(git_submodule_cache **out, git_repository *repo) -{ - git_submodule_cache *cache = NULL; - int error = 0; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - if ((cache = git__calloc(1, sizeof(git_submodule_cache))) == NULL) - return -1; - - if ((error = git_submodule__map(cache, repo)) < 0) { - git_submodule_cache_free(cache); - return error; - } - - *out = cache; - return error; -} - -int git_submodule_cache_free(git_submodule_cache *cache) -{ - git_submodule *sm = NULL; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - if (cache == NULL) - return 0; - - while (git_submodule_cache_iterate(&iter, NULL, &sm, cache) == 0) - git_submodule_free(sm); - - git_submodule_cache_dispose(cache); - git__free(cache); - return 0; -} - -int git_submodule_lookup( - git_submodule **out, /* NULL if user only wants to test existence */ - git_repository *repo, - const char *name) /* trailing slash is allowed */ -{ - return git_submodule__lookup_with_cache(out, repo, name, repo->submodule_cache); -} - -int git_submodule__lookup_with_cache( - git_submodule **out, /* NULL if user only wants to test existence */ - git_repository *repo, - const char *name, /* trailing slash is allowed */ - git_submodule_cache *cache) -{ - git_submodule *sm; - unsigned int location; - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - if (repo->is_bare) { - git_error_set(GIT_ERROR_SUBMODULE, "cannot get submodules without a working tree"); - return -1; - } - - if (cache != NULL) { - if (git_submodule_cache_get(&sm, cache, name) == 0) { - if (out) { - *out = sm; - GIT_REFCOUNT_INC(*out); - } - return 0; - } - } - - if ((error = submodule_alloc(&sm, repo, name)) < 0) - return error; - - /* - * Only try to reload if they gave us a valid _name_; if this is a - * path, we'll do some lookups then try to reload to populate. - */ - if (git_submodule_name_is_valid(sm->repo, name, 0) <= 0) { - error = GIT_ENOTFOUND; - } else { - error = git_submodule_reload(sm, false); - } - - if (error < 0 && error != GIT_ENOTFOUND) { - git_submodule_free(sm); - return error; - } - - if ((error = git_submodule_location(&location, sm)) < 0) { - git_submodule_free(sm); - return error; - } - - /* If it's not configured or we're looking by path */ - if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) { - git_config_backend *mods; - const char *pattern = "^submodule\\..*\\.path$"; - git_str path = GIT_STR_INIT; - fbp_data data = { NULL, NULL }; - - git_str_puts(&path, name); - while (path.ptr[path.size-1] == '/') { - path.ptr[--path.size] = '\0'; - } - data.path = path.ptr; - - mods = open_gitmodules(repo, GITMODULES_EXISTING); - - if (mods) - error = git_config_backend_foreach_match(mods, pattern, find_by_path, &data); - - git_config_backend_free(mods); - - if (error < 0) { - git_submodule_free(sm); - git_str_dispose(&path); - return error; - } - - if (data.name) { - git__free(sm->name); - sm->name = data.name; - sm->path = git_str_detach(&path); - - /* Try to load again with the right name */ - if ((error = git_submodule_reload(sm, false)) < 0) { - git_submodule_free(sm); - return error; - } - } - - git_str_dispose(&path); - } - - if ((error = git_submodule_location(&location, sm)) < 0) { - git_submodule_free(sm); - return error; - } - - /* If we still haven't found it, do the WD check */ - if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) { - git_submodule_free(sm); - git_error_set(GIT_ERROR_SUBMODULE, "invalid submodule name: '%s'", name); - error = GIT_ENOTFOUND; - - /* If it's not configured, we still check if there's a repo at the path */ - if (git_repository_workdir(repo)) { - git_str path = GIT_STR_INIT; - if (git_str_join3(&path, '/', - git_repository_workdir(repo), - name, DOT_GIT) < 0 || - git_path_validate_str_length(NULL, &path) < 0) - return -1; - - if (git_fs_path_exists(path.ptr)) - error = GIT_EEXISTS; - - git_str_dispose(&path); - } - - submodule_set_lookup_error(error, name); - return error; - } - - if (out) - *out = sm; - else - git_submodule_free(sm); - - return 0; -} - -int git_submodule_name_is_valid(git_repository *repo, const char *name, int flags) -{ - git_str buf = GIT_STR_INIT; - int error, isvalid; - - if (flags == 0) - flags = GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS; - - /* Avoid allocating a new string if we can avoid it */ - if (strchr(name, '\\') != NULL) { - if ((error = git_fs_path_normalize_slashes(&buf, name)) < 0) - return error; - } else { - git_str_attach_notowned(&buf, name, strlen(name)); - } - - isvalid = git_path_is_valid(repo, buf.ptr, 0, flags); - git_str_dispose(&buf); - - return isvalid; -} - -static int path_is_valid(git_repository *repo, const char *path) -{ - git_str buf = GIT_STR_INIT; - int flags = GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS & - ~GIT_FS_PATH_REJECT_EMPTY_COMPONENT; - int error, isvalid; - - /* Avoid allocating a new string if we can avoid it */ - if (strchr(path, '\\') != NULL) { - if ((error = git_fs_path_normalize_slashes(&buf, path)) < 0) - return error; - } else { - git_str_attach_notowned(&buf, path, strlen(path)); - } - - isvalid = git_path_is_valid(repo, buf.ptr, 0, flags); - git_str_dispose(&buf); - - return isvalid; -} - -static void submodule_free_dup(void *sm) -{ - git_submodule_free(sm); -} - -static int submodule_get_or_create( - git_submodule **out, - git_repository *repo, - git_submodule_cache *cache, - const char *name) -{ - git_submodule *sm = NULL; - int error; - - if (git_submodule_cache_get(&sm, cache, name) == 0) - goto done; - - /* if the submodule doesn't exist yet in the map, create it */ - if ((error = submodule_alloc(&sm, repo, name)) < 0) - return error; - - if ((error = git_submodule_cache_put(cache, sm->name, sm)) < 0) { - git_submodule_free(sm); - return error; - } - -done: - GIT_REFCOUNT_INC(sm); - *out = sm; - return 0; -} - -static int submodules_from_index( - git_submodule_cache *cache, - git_index *idx, - git_config *cfg) -{ - int error; - git_iterator *i = NULL; - const git_index_entry *entry; - git_submodule_namemap *names; - - if ((error = load_submodule_names(&names, git_index_owner(idx), cfg))) - goto done; - - if ((error = git_iterator_for_index(&i, git_index_owner(idx), idx, NULL)) < 0) - goto done; - - while (!(error = git_iterator_advance(&entry, i))) { - git_submodule *sm; - - if (git_submodule_cache_get(&sm, cache, entry->path) == 0) { - if (S_ISGITLINK(entry->mode)) - submodule_update_from_index_entry(sm, entry); - else - sm->flags |= GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE; - } else if (S_ISGITLINK(entry->mode)) { - const char *name; - - if (git_submodule_namemap_get((char **)&name, names, entry->path) != 0) - name = entry->path; - - if (!submodule_get_or_create(&sm, git_index_owner(idx), cache, name)) { - submodule_update_from_index_entry(sm, entry); - git_submodule_free(sm); - } - } - } - - if (error == GIT_ITEROVER) - error = 0; - -done: - git_iterator_free(i); - free_submodule_names(names); - - return error; -} - -static int submodules_from_head( - git_submodule_cache *cache, - git_tree *head, - git_config *cfg) -{ - int error; - git_iterator *i = NULL; - const git_index_entry *entry; - git_submodule_namemap *names; - - if ((error = load_submodule_names(&names, git_tree_owner(head), cfg))) - goto done; - - if ((error = git_iterator_for_tree(&i, head, NULL)) < 0) - goto done; - - while (!(error = git_iterator_advance(&entry, i))) { - git_submodule *sm; - - if (git_submodule_cache_get(&sm, cache, entry->path) == 0) { - if (S_ISGITLINK(entry->mode)) - submodule_update_from_head_data(sm, entry->mode, &entry->id); - else - sm->flags |= GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE; - } else if (S_ISGITLINK(entry->mode)) { - const char *name; - - if (git_submodule_namemap_get((char **)&name, names, entry->path) != 0) - name = entry->path; - - if (!submodule_get_or_create(&sm, git_tree_owner(head), cache, name)) { - submodule_update_from_head_data( - sm, entry->mode, &entry->id); - git_submodule_free(sm); - } - } - } - - if (error == GIT_ITEROVER) - error = 0; - -done: - git_iterator_free(i); - free_submodule_names(names); - - return error; -} - -/* If have_sm is true, sm is populated, otherwise map an repo are. */ -typedef struct { - git_config *mods; - git_submodule_cache *cache; - git_repository *repo; -} lfc_data; - -int git_submodule__map(git_submodule_cache *cache, git_repository *repo) -{ - int error = 0; - git_index *idx = NULL; - git_tree *head = NULL; - git_str path = GIT_STR_INIT; - git_submodule *sm; - git_config *mods = NULL; - bool has_workdir; - - GIT_ASSERT_ARG(cache); - GIT_ASSERT_ARG(repo); - - /* get sources that we will need to check */ - if (git_repository_index(&idx, repo) < 0) - git_error_clear(); - if (git_repository_head_tree(&head, repo) < 0) - git_error_clear(); - - has_workdir = git_repository_workdir(repo) != NULL; - - if (has_workdir && - (error = git_repository_workdir_path(&path, repo, GIT_MODULES_FILE)) < 0) - goto cleanup; - - /* add submodule information from .gitmodules */ - if (has_workdir) { - lfc_data data = { 0 }; - data.cache = cache; - data.repo = repo; - - if ((error = gitmodules_snapshot(&mods, repo)) < 0) { - if (error == GIT_ENOTFOUND) - error = 0; - goto cleanup; - } - - data.mods = mods; - if ((error = git_config_foreach( - mods, submodule_load_each, &data)) < 0) - goto cleanup; - } - /* add back submodule information from index */ - if (mods && idx) { - if ((error = submodules_from_index(cache, idx, mods)) < 0) - goto cleanup; - } - /* add submodule information from HEAD */ - if (mods && head) { - if ((error = submodules_from_head(cache, head, mods)) < 0) - goto cleanup; - } - /* shallow scan submodules in work tree as needed */ - if (has_workdir) { - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - while (git_submodule_cache_iterate(&iter, NULL, &sm, cache) == 0) { - if ((error = submodule_load_from_wd_lite(sm)) < 0) - goto cleanup; - } - } - -cleanup: - git_config_free(mods); - /* TODO: if we got an error, mark submodule config as invalid? */ - git_index_free(idx); - git_tree_free(head); - git_str_dispose(&path); - return error; -} - -int git_submodule_foreach( - git_repository *repo, - git_submodule_cb callback, - void *payload) -{ - git_vector snapshot = GIT_VECTOR_INIT; - git_submodule_cache *submodules; - git_submodule *sm; - git_hashmap_iter_t iter; - int error; - size_t i; - - if (repo->is_bare) { - git_error_set(GIT_ERROR_SUBMODULE, "cannot get submodules without a working tree"); - return -1; - } - - if ((submodules = git__calloc(1, sizeof(git_submodule_cache))) == NULL) - return -1; - - if ((error = git_submodule__map(submodules, repo)) < 0) - goto done; - - if (!(error = git_vector_init(&snapshot, - git_submodule_cache_size(submodules), - submodule_cmp))) { - for (iter = GIT_HASHMAP_ITER_INIT; - git_submodule_cache_iterate(&iter, NULL, &sm, submodules) == 0; ) { - if ((error = git_vector_insert(&snapshot, sm)) < 0) - break; - - GIT_REFCOUNT_INC(sm); - } - } - - if (error < 0) - goto done; - - git_vector_uniq(&snapshot, submodule_free_dup); - - git_vector_foreach(&snapshot, i, sm) { - if ((error = callback(sm, sm->name, payload)) != 0) { - git_error_set_after_callback(error); - break; - } - } - -done: - git_vector_foreach(&snapshot, i, sm) - git_submodule_free(sm); - git_vector_dispose(&snapshot); - - for (iter = GIT_HASHMAP_ITER_INIT; - git_submodule_cache_iterate(&iter, NULL, &sm, submodules) == 0; ) - git_submodule_free(sm); - - git_submodule_cache_dispose(submodules); - git__free(submodules); - - return error; -} - -static int submodule_repo_init( - git_repository **out, - git_repository *parent_repo, - const char *path, - const char *url, - bool use_gitlink) -{ - int error = 0; - git_str workdir = GIT_STR_INIT, repodir = GIT_STR_INIT; - git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT; - git_repository *subrepo = NULL; - - error = git_repository_workdir_path(&workdir, parent_repo, path); - if (error < 0) - goto cleanup; - - initopt.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_NO_REINIT; - initopt.origin_url = url; - - /* init submodule repository and add origin remote as needed */ - - /* New style: sub-repo goes in /modules// with a - * gitlink in the sub-repo workdir directory to that repository - * - * Old style: sub-repo goes directly into repo//.git/ - */ - if (use_gitlink) { - error = git_repository__item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES); - if (error < 0) - goto cleanup; - error = git_str_joinpath(&repodir, repodir.ptr, path); - if (error < 0) - goto cleanup; - - initopt.workdir_path = workdir.ptr; - initopt.flags |= - GIT_REPOSITORY_INIT_NO_DOTGIT_DIR | - GIT_REPOSITORY_INIT_RELATIVE_GITLINK; - - error = git_repository_init_ext(&subrepo, repodir.ptr, &initopt); - } else - error = git_repository_init_ext(&subrepo, workdir.ptr, &initopt); - -cleanup: - git_str_dispose(&workdir); - git_str_dispose(&repodir); - - *out = subrepo; - - return error; -} - -static int git_submodule__resolve_url( - git_str *out, - git_repository *repo, - const char *url) -{ - int error = 0; - git_str normalized = GIT_STR_INIT; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(url); - - /* We do this in all platforms in case someone on Windows created the .gitmodules */ - if (strchr(url, '\\')) { - if ((error = git_fs_path_normalize_slashes(&normalized, url)) < 0) - return error; - - url = normalized.ptr; - } - - - if (git_fs_path_is_relative(url)) { - if (!(error = get_url_base(out, repo))) - error = git_fs_path_apply_relative(out, url); - } else if (strchr(url, ':') != NULL || url[0] == '/') { - error = git_str_sets(out, url); - } else { - git_error_set(GIT_ERROR_SUBMODULE, "invalid format for submodule URL"); - error = -1; - } - - git_str_dispose(&normalized); - return error; -} - -int git_submodule_resolve_url( - git_buf *out, - git_repository *repo, - const char *url) -{ - GIT_BUF_WRAP_PRIVATE(out, git_submodule__resolve_url, repo, url); -} - -int git_submodule_add_setup( - git_submodule **out, - git_repository *repo, - const char *url, - const char *path, - int use_gitlink) -{ - int error = 0; - git_config_backend *mods = NULL; - git_submodule *sm = NULL; - git_str name = GIT_STR_INIT, real_url = GIT_STR_INIT; - git_repository *subrepo = NULL; - bool path_occupied; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(url); - GIT_ASSERT_ARG(path); - - /* see if there is already an entry for this submodule */ - - if (git_submodule_lookup(NULL, repo, path) < 0) - git_error_clear(); - else { - git_error_set(GIT_ERROR_SUBMODULE, - "attempt to add submodule '%s' that already exists", path); - return GIT_EEXISTS; - } - - /* validate and normalize path */ - - if (git__prefixcmp(path, git_repository_workdir(repo)) == 0) - path += strlen(git_repository_workdir(repo)); - - if (git_fs_path_root(path) >= 0) { - git_error_set(GIT_ERROR_SUBMODULE, "submodule path must be a relative path"); - error = -1; - goto cleanup; - } - - if ((error = is_path_occupied(&path_occupied, repo, path)) < 0) - goto cleanup; - - if (path_occupied) { - error = GIT_EEXISTS; - goto cleanup; - } - - /* update .gitmodules */ - - if (!(mods = open_gitmodules(repo, GITMODULES_CREATE))) { - git_error_set(GIT_ERROR_SUBMODULE, - "adding submodules to a bare repository is not supported"); - return -1; - } - - if ((error = git_str_printf(&name, "submodule.%s.path", path)) < 0 || - (error = git_config_backend_set_string(mods, name.ptr, path)) < 0) - goto cleanup; - - if ((error = submodule_config_key_trunc_puts(&name, "url")) < 0 || - (error = git_config_backend_set_string(mods, name.ptr, url)) < 0) - goto cleanup; - - git_str_clear(&name); - - /* init submodule repository and add origin remote as needed */ - - error = git_repository_workdir_path(&name, repo, path); - if (error < 0) - goto cleanup; - - /* if the repo does not already exist, then init a new repo and add it. - * Otherwise, just add the existing repo. - */ - if (!(git_fs_path_exists(name.ptr) && - git_fs_path_contains(&name, DOT_GIT))) { - - /* resolve the actual URL to use */ - if ((error = git_submodule__resolve_url(&real_url, repo, url)) < 0) - goto cleanup; - - if ((error = submodule_repo_init(&subrepo, repo, path, real_url.ptr, use_gitlink)) < 0) - goto cleanup; - } - - if ((error = git_submodule_lookup(&sm, repo, path)) < 0) - goto cleanup; - - error = git_submodule_init(sm, false); - -cleanup: - if (error && sm) { - git_submodule_free(sm); - sm = NULL; - } - if (out != NULL) - *out = sm; - - git_config_backend_free(mods); - git_repository_free(subrepo); - git_str_dispose(&real_url); - git_str_dispose(&name); - - return error; -} - -int git_submodule_repo_init( - git_repository **out, - const git_submodule *sm, - int use_gitlink) -{ - int error; - git_repository *sub_repo = NULL; - const char *configured_url; - git_config *cfg = NULL; - git_str buf = GIT_STR_INIT; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(sm); - - /* get the configured remote url of the submodule */ - if ((error = git_str_printf(&buf, "submodule.%s.url", sm->name)) < 0 || - (error = git_repository_config_snapshot(&cfg, sm->repo)) < 0 || - (error = git_config_get_string(&configured_url, cfg, buf.ptr)) < 0 || - (error = submodule_repo_init(&sub_repo, sm->repo, sm->path, configured_url, use_gitlink)) < 0) - goto done; - - *out = sub_repo; - -done: - git_config_free(cfg); - git_str_dispose(&buf); - return error; -} - -static int clone_return_origin(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) -{ - GIT_UNUSED(url); - GIT_UNUSED(payload); - return git_remote_lookup(out, repo, name); -} - -static int clone_return_repo(git_repository **out, const char *path, int bare, void *payload) -{ - git_submodule *sm = payload; - - GIT_UNUSED(path); - GIT_UNUSED(bare); - return git_submodule_open(out, sm); -} - -int git_submodule_clone(git_repository **out, git_submodule *submodule, const git_submodule_update_options *given_opts) -{ - int error; - git_repository *clone; - git_str rel_path = GIT_STR_INIT; - git_submodule_update_options sub_opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; - git_clone_options opts = GIT_CLONE_OPTIONS_INIT; - - GIT_ASSERT_ARG(submodule); - - if (given_opts) - memcpy(&sub_opts, given_opts, sizeof(sub_opts)); - - GIT_ERROR_CHECK_VERSION(&sub_opts, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, "git_submodule_update_options"); - - memcpy(&opts.checkout_opts, &sub_opts.checkout_opts, sizeof(sub_opts.checkout_opts)); - memcpy(&opts.fetch_opts, &sub_opts.fetch_opts, sizeof(sub_opts.fetch_opts)); - opts.repository_cb = clone_return_repo; - opts.repository_cb_payload = submodule; - opts.remote_cb = clone_return_origin; - opts.remote_cb_payload = submodule; - - error = git_repository_workdir_path(&rel_path, git_submodule_owner(submodule), git_submodule_path(submodule)); - if (error < 0) - goto cleanup; - - error = git_clone__submodule(&clone, git_submodule_url(submodule), git_str_cstr(&rel_path), &opts); - if (error < 0) - goto cleanup; - - if (!out) - git_repository_free(clone); - else - *out = clone; - -cleanup: - git_str_dispose(&rel_path); - - return error; -} - -int git_submodule_add_finalize(git_submodule *sm) -{ - int error; - git_index *index; - - GIT_ASSERT_ARG(sm); - - if ((error = git_repository_index__weakptr(&index, sm->repo)) < 0 || - (error = git_index_add_bypath(index, GIT_MODULES_FILE)) < 0) - return error; - - return git_submodule_add_to_index(sm, true); -} - -int git_submodule_add_to_index(git_submodule *sm, int write_index) -{ - int error; - git_repository *sm_repo = NULL; - git_index *index; - git_str path = GIT_STR_INIT; - git_commit *head; - git_index_entry entry; - struct stat st; - - GIT_ASSERT_ARG(sm); - - /* force reload of wd OID by git_submodule_open */ - sm->flags = sm->flags & ~GIT_SUBMODULE_STATUS__WD_OID_VALID; - - if ((error = git_repository_index__weakptr(&index, sm->repo)) < 0 || - (error = git_repository_workdir_path(&path, sm->repo, sm->path)) < 0 || - (error = git_submodule_open(&sm_repo, sm)) < 0) - goto cleanup; - - /* read stat information for submodule working directory */ - if (p_stat(path.ptr, &st) < 0) { - git_error_set(GIT_ERROR_SUBMODULE, - "cannot add submodule without working directory"); - error = -1; - goto cleanup; - } - - memset(&entry, 0, sizeof(entry)); - entry.path = sm->path; - git_index_entry__init_from_stat( - &entry, &st, !(git_index_caps(index) & GIT_INDEX_CAPABILITY_NO_FILEMODE)); - - /* calling git_submodule_open will have set sm->wd_oid if possible */ - if ((sm->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID) == 0) { - git_error_set(GIT_ERROR_SUBMODULE, - "cannot add submodule without HEAD to index"); - error = -1; - goto cleanup; - } - git_oid_cpy(&entry.id, &sm->wd_oid); - - if ((error = git_commit_lookup(&head, sm_repo, &sm->wd_oid)) < 0) - goto cleanup; - - entry.ctime.seconds = (int32_t)git_commit_time(head); - entry.ctime.nanoseconds = 0; - entry.mtime.seconds = (int32_t)git_commit_time(head); - entry.mtime.nanoseconds = 0; - - git_commit_free(head); - - /* add it */ - if ((error = git_index_add(index, &entry)) < 0) - goto cleanup; - - /* Adding implies conflict was resolved, move conflict entries to REUC */ - if ((error = git_index__conflict_to_reuc(index, entry.path)) < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - /* write it, if requested */ - if (write_index) { - if ((error = git_index_write(index)) < 0) - goto cleanup; - - git_oid_cpy(&sm->index_oid, &sm->wd_oid); - } - - error = 0; - -cleanup: - git_repository_free(sm_repo); - git_str_dispose(&path); - return error; -} - -static const char *submodule_update_to_str(git_submodule_update_t update) -{ - int i; - for (i = 0; i < (int)ARRAY_SIZE(_sm_update_map); ++i) - if (_sm_update_map[i].map_value == (int)update) - return _sm_update_map[i].str_match; - return NULL; -} - -git_repository *git_submodule_owner(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL); - return submodule->repo; -} - -const char *git_submodule_name(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL); - return submodule->name; -} - -const char *git_submodule_path(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL); - return submodule->path; -} - -const char *git_submodule_url(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL); - return submodule->url; -} - -static int write_var(git_repository *repo, const char *name, const char *var, const char *val) -{ - git_str key = GIT_STR_INIT; - git_config_backend *mods; - int error; - - mods = open_gitmodules(repo, GITMODULES_CREATE); - if (!mods) - return -1; - - if ((error = git_str_printf(&key, "submodule.%s.%s", name, var)) < 0) - goto cleanup; - - if (val) - error = git_config_backend_set_string(mods, key.ptr, val); - else - error = git_config_backend_delete(mods, key.ptr); - - git_str_dispose(&key); - -cleanup: - git_config_backend_free(mods); - return error; -} - -static int write_mapped_var(git_repository *repo, const char *name, git_configmap *maps, size_t nmaps, const char *var, int ival) -{ - git_configmap_t type; - const char *val; - - if (git_config_lookup_map_enum(&type, &val, maps, nmaps, ival) < 0) { - git_error_set(GIT_ERROR_SUBMODULE, "invalid value for %s", var); - return -1; - } - - if (type == GIT_CONFIGMAP_TRUE) - val = "true"; - - return write_var(repo, name, var, val); -} - -const char *git_submodule_branch(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL); - return submodule->branch; -} - -int git_submodule_set_branch(git_repository *repo, const char *name, const char *branch) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - return write_var(repo, name, "branch", branch); -} - -int git_submodule_set_url(git_repository *repo, const char *name, const char *url) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - GIT_ASSERT_ARG(url); - - return write_var(repo, name, "url", url); -} - -const git_oid *git_submodule_index_id(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL); - - if (submodule->flags & GIT_SUBMODULE_STATUS__INDEX_OID_VALID) - return &submodule->index_oid; - else - return NULL; -} - -const git_oid *git_submodule_head_id(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL); - - if (submodule->flags & GIT_SUBMODULE_STATUS__HEAD_OID_VALID) - return &submodule->head_oid; - else - return NULL; -} - -const git_oid *git_submodule_wd_id(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL); - - /* load unless we think we have a valid oid */ - if (!(submodule->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID)) { - git_repository *subrepo; - - /* calling submodule open grabs the HEAD OID if possible */ - if (!git_submodule_open_bare(&subrepo, submodule)) - git_repository_free(subrepo); - else - git_error_clear(); - } - - if (submodule->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID) - return &submodule->wd_oid; - else - return NULL; -} - -git_submodule_ignore_t git_submodule_ignore(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, GIT_SUBMODULE_IGNORE_UNSPECIFIED); - - return (submodule->ignore < GIT_SUBMODULE_IGNORE_NONE) ? - GIT_SUBMODULE_IGNORE_NONE : submodule->ignore; -} - -int git_submodule_set_ignore(git_repository *repo, const char *name, git_submodule_ignore_t ignore) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - return write_mapped_var(repo, name, _sm_ignore_map, ARRAY_SIZE(_sm_ignore_map), "ignore", ignore); -} - -git_submodule_update_t git_submodule_update_strategy(git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, GIT_SUBMODULE_UPDATE_NONE); - - return (submodule->update < GIT_SUBMODULE_UPDATE_CHECKOUT) ? - GIT_SUBMODULE_UPDATE_CHECKOUT : submodule->update; -} - -int git_submodule_set_update(git_repository *repo, const char *name, git_submodule_update_t update) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - return write_mapped_var(repo, name, _sm_update_map, ARRAY_SIZE(_sm_update_map), "update", update); -} - -git_submodule_recurse_t git_submodule_fetch_recurse_submodules( - git_submodule *submodule) -{ - GIT_ASSERT_ARG_WITH_RETVAL(submodule, GIT_SUBMODULE_RECURSE_NO); - return submodule->fetch_recurse; -} - -int git_submodule_set_fetch_recurse_submodules(git_repository *repo, const char *name, git_submodule_recurse_t recurse) -{ - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - return write_mapped_var(repo, name, _sm_recurse_map, ARRAY_SIZE(_sm_recurse_map), "fetchRecurseSubmodules", recurse); -} - -static int submodule_repo_create( - git_repository **out, - git_repository *parent_repo, - const char *path) -{ - int error = 0; - git_str workdir = GIT_STR_INIT, repodir = GIT_STR_INIT; - git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT; - git_repository *subrepo = NULL; - - initopt.flags = - GIT_REPOSITORY_INIT_MKPATH | - GIT_REPOSITORY_INIT_NO_REINIT | - GIT_REPOSITORY_INIT_NO_DOTGIT_DIR | - GIT_REPOSITORY_INIT_RELATIVE_GITLINK; - - /* Workdir: path to sub-repo working directory */ - error = git_repository_workdir_path(&workdir, parent_repo, path); - if (error < 0) - goto cleanup; - - initopt.workdir_path = workdir.ptr; - - /** - * Repodir: path to the sub-repo. sub-repo goes in: - * /modules// with a gitlink in the - * sub-repo workdir directory to that repository. - */ - error = git_repository__item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES); - if (error < 0) - goto cleanup; - error = git_str_joinpath(&repodir, repodir.ptr, path); - if (error < 0) - goto cleanup; - - error = git_repository_init_ext(&subrepo, repodir.ptr, &initopt); - -cleanup: - git_str_dispose(&workdir); - git_str_dispose(&repodir); - - *out = subrepo; - - return error; -} - -/** - * Callback to override sub-repository creation when - * cloning a sub-repository. - */ -static int git_submodule_update_repo_init_cb( - git_repository **out, - const char *path, - int bare, - void *payload) -{ - git_submodule *sm; - - GIT_UNUSED(bare); - - sm = payload; - - return submodule_repo_create(out, sm->repo, path); -} - -int git_submodule_update_options_init(git_submodule_update_options *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_submodule_update_options, GIT_SUBMODULE_UPDATE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_submodule_update_init_options(git_submodule_update_options *opts, unsigned int version) -{ - return git_submodule_update_options_init(opts, version); -} -#endif - -int git_submodule_update(git_submodule *sm, int init, git_submodule_update_options *_update_options) -{ - int error; - unsigned int submodule_status; - git_config *config = NULL; - const char *submodule_url; - git_repository *sub_repo = NULL; - git_remote *remote = NULL; - git_object *target_commit = NULL; - git_str buf = GIT_STR_INIT; - git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; - git_clone_options clone_options = GIT_CLONE_OPTIONS_INIT; - - GIT_ASSERT_ARG(sm); - - if (_update_options) - memcpy(&update_options, _update_options, sizeof(git_submodule_update_options)); - - GIT_ERROR_CHECK_VERSION(&update_options, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, "git_submodule_update_options"); - - /* Copy over the remote callbacks */ - memcpy(&clone_options.fetch_opts, &update_options.fetch_opts, sizeof(git_fetch_options)); - - /* Get the status of the submodule to determine if it is already initialized */ - if ((error = git_submodule_status(&submodule_status, sm->repo, sm->name, GIT_SUBMODULE_IGNORE_UNSPECIFIED)) < 0) - goto done; - - /* If the submodule is configured but hasn't been added, skip it */ - if (submodule_status == GIT_SUBMODULE_STATUS_IN_CONFIG) - goto done; - - /* - * If submodule work dir is not already initialized, check to see - * what we need to do (initialize, clone, return error...) - */ - if (submodule_status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) { - /* - * Work dir is not initialized, check to see if the submodule - * info has been copied into .git/config - */ - if ((error = git_repository_config_snapshot(&config, sm->repo)) < 0 || - (error = git_str_printf(&buf, "submodule.%s.url", git_submodule_name(sm))) < 0) - goto done; - - if ((error = git_config_get_string(&submodule_url, config, git_str_cstr(&buf))) < 0) { - /* - * If the error is not "not found" or if it is "not found" and we are not - * initializing the submodule, then return error. - */ - if (error != GIT_ENOTFOUND) - goto done; - - if (!init) { - git_error_set(GIT_ERROR_SUBMODULE, "submodule is not initialized"); - error = GIT_ERROR; - goto done; - } - - /* The submodule has not been initialized yet - initialize it now.*/ - if ((error = git_submodule_init(sm, 0)) < 0) - goto done; - - git_config_free(config); - config = NULL; - - if ((error = git_repository_config_snapshot(&config, sm->repo)) < 0 || - (error = git_config_get_string(&submodule_url, config, git_str_cstr(&buf))) < 0) - goto done; - } - - /** submodule is initialized - now clone it **/ - /* override repo creation */ - clone_options.repository_cb = git_submodule_update_repo_init_cb; - clone_options.repository_cb_payload = sm; - - /* - * Do not perform checkout as part of clone, instead we - * will checkout the specific commit manually. - */ - clone_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_NONE; - - if ((error = git_clone__submodule(&sub_repo, submodule_url, sm->path, &clone_options)) < 0 || - (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm))) < 0 || - (error = git_checkout_head(sub_repo, &update_options.checkout_opts)) != 0) - goto done; - } else { - const git_oid *oid; - - /** - * Work dir is initialized - look up the commit in the parent repository's index, - * update the workdir contents of the subrepository, and set the subrepository's - * head to the new commit. - */ - if ((error = git_submodule_open(&sub_repo, sm)) < 0) - goto done; - - if ((oid = git_submodule_index_id(sm)) == NULL) { - git_error_set(GIT_ERROR_SUBMODULE, "could not get ID of submodule in index"); - error = -1; - goto done; - } - - /* Look up the target commit in the submodule. */ - if ((error = git_object_lookup(&target_commit, sub_repo, oid, GIT_OBJECT_COMMIT)) < 0) { - /* If it isn't found then fetch and try again. */ - if (error != GIT_ENOTFOUND || !update_options.allow_fetch || - (error = lookup_default_remote(&remote, sub_repo)) < 0 || - (error = git_remote_fetch(remote, NULL, &update_options.fetch_opts, NULL)) < 0 || - (error = git_object_lookup(&target_commit, sub_repo, git_submodule_index_id(sm), GIT_OBJECT_COMMIT)) < 0) - goto done; - } - - if ((error = git_checkout_tree(sub_repo, target_commit, &update_options.checkout_opts)) != 0 || - (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm))) < 0) - goto done; - - /* Invalidate the wd flags as the workdir has been updated. */ - sm->flags = sm->flags & - ~(GIT_SUBMODULE_STATUS_IN_WD | - GIT_SUBMODULE_STATUS__WD_OID_VALID | - GIT_SUBMODULE_STATUS__WD_SCANNED); - } - -done: - git_str_dispose(&buf); - git_config_free(config); - git_object_free(target_commit); - git_remote_free(remote); - git_repository_free(sub_repo); - - return error; -} - -int git_submodule_init(git_submodule *sm, int overwrite) -{ - int error; - const char *val; - git_str key = GIT_STR_INIT, effective_submodule_url = GIT_STR_INIT; - git_config *cfg = NULL; - - if (!sm->url) { - git_error_set(GIT_ERROR_SUBMODULE, - "no URL configured for submodule '%s'", sm->name); - return -1; - } - - if ((error = git_repository_config(&cfg, sm->repo)) < 0) - return error; - - /* write "submodule.NAME.url" */ - - if ((error = git_submodule__resolve_url(&effective_submodule_url, sm->repo, sm->url)) < 0 || - (error = git_str_printf(&key, "submodule.%s.url", sm->name)) < 0 || - (error = git_config__update_entry( - cfg, key.ptr, effective_submodule_url.ptr, overwrite != 0, false)) < 0) - goto cleanup; - - /* write "submodule.NAME.update" if not default */ - - val = (sm->update == GIT_SUBMODULE_UPDATE_CHECKOUT) ? - NULL : submodule_update_to_str(sm->update); - - if ((error = git_str_printf(&key, "submodule.%s.update", sm->name)) < 0 || - (error = git_config__update_entry( - cfg, key.ptr, val, overwrite != 0, false)) < 0) - goto cleanup; - - /* success */ - -cleanup: - git_config_free(cfg); - git_str_dispose(&key); - git_str_dispose(&effective_submodule_url); - - return error; -} - -int git_submodule_sync(git_submodule *sm) -{ - git_str key = GIT_STR_INIT, url = GIT_STR_INIT, remote_name = GIT_STR_INIT; - git_repository *smrepo = NULL; - git_config *cfg = NULL; - int error = 0; - - if (!sm->url) { - git_error_set(GIT_ERROR_SUBMODULE, "no URL configured for submodule '%s'", sm->name); - return -1; - } - - /* copy URL over to config only if it already exists */ - if ((error = git_repository_config__weakptr(&cfg, sm->repo)) < 0 || - (error = git_str_printf(&key, "submodule.%s.url", sm->name)) < 0 || - (error = git_submodule__resolve_url(&url, sm->repo, sm->url)) < 0 || - (error = git_config__update_entry(cfg, key.ptr, url.ptr, true, true)) < 0) - goto out; - - if (!(sm->flags & GIT_SUBMODULE_STATUS_IN_WD)) - goto out; - - /* if submodule exists in the working directory, update remote url */ - if ((error = git_submodule_open(&smrepo, sm)) < 0 || - (error = git_repository_config__weakptr(&cfg, smrepo)) < 0) - goto out; - - if (lookup_head_remote_key(&remote_name, smrepo) == 0) { - if ((error = git_str_join3(&key, '.', "remote", remote_name.ptr, "url")) < 0) - goto out; - } else if ((error = git_str_sets(&key, "remote.origin.url")) < 0) { - goto out; - } - - if ((error = git_config__update_entry(cfg, key.ptr, url.ptr, true, false)) < 0) - goto out; - -out: - git_repository_free(smrepo); - git_str_dispose(&remote_name); - git_str_dispose(&key); - git_str_dispose(&url); - return error; -} - -static int git_submodule__open( - git_repository **subrepo, git_submodule *sm, bool bare) -{ - int error; - git_str path = GIT_STR_INIT; - unsigned int flags = GIT_REPOSITORY_OPEN_NO_SEARCH; - const char *wd; - - GIT_ASSERT_ARG(sm); - GIT_ASSERT_ARG(subrepo); - - if (git_repository__ensure_not_bare( - sm->repo, "open submodule repository") < 0) - return GIT_EBAREREPO; - - wd = git_repository_workdir(sm->repo); - - if (git_str_join3(&path, '/', wd, sm->path, DOT_GIT) < 0) - return -1; - - sm->flags = sm->flags & - ~(GIT_SUBMODULE_STATUS_IN_WD | - GIT_SUBMODULE_STATUS__WD_OID_VALID | - GIT_SUBMODULE_STATUS__WD_SCANNED); - - if (bare) - flags |= GIT_REPOSITORY_OPEN_BARE; - - error = git_repository_open_ext(subrepo, path.ptr, flags, wd); - - /* if we opened the submodule successfully, grab HEAD OID, etc. */ - if (!error) { - sm->flags |= GIT_SUBMODULE_STATUS_IN_WD | - GIT_SUBMODULE_STATUS__WD_SCANNED; - - if (!git_reference_name_to_id(&sm->wd_oid, *subrepo, GIT_HEAD_FILE)) - sm->flags |= GIT_SUBMODULE_STATUS__WD_OID_VALID; - else - git_error_clear(); - } else if (git_fs_path_exists(path.ptr)) { - sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED | - GIT_SUBMODULE_STATUS_IN_WD; - } else { - git_str_rtruncate_at_char(&path, '/'); /* remove "/.git" */ - - if (git_fs_path_isdir(path.ptr)) - sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED; - } - - git_str_dispose(&path); - - return error; -} - -int git_submodule_open_bare(git_repository **subrepo, git_submodule *sm) -{ - return git_submodule__open(subrepo, sm, true); -} - -int git_submodule_open(git_repository **subrepo, git_submodule *sm) -{ - return git_submodule__open(subrepo, sm, false); -} - -static void submodule_update_from_index_entry( - git_submodule *sm, const git_index_entry *ie) -{ - bool already_found = (sm->flags & GIT_SUBMODULE_STATUS_IN_INDEX) != 0; - - if (!S_ISGITLINK(ie->mode)) { - if (!already_found) - sm->flags |= GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE; - } else { - if (already_found) - sm->flags |= GIT_SUBMODULE_STATUS__INDEX_MULTIPLE_ENTRIES; - else - git_oid_cpy(&sm->index_oid, &ie->id); - - sm->flags |= GIT_SUBMODULE_STATUS_IN_INDEX | - GIT_SUBMODULE_STATUS__INDEX_OID_VALID; - } -} - -static int submodule_update_index(git_submodule *sm) -{ - git_index *index; - const git_index_entry *ie; - - if (git_repository_index__weakptr(&index, sm->repo) < 0) - return -1; - - sm->flags = sm->flags & - ~(GIT_SUBMODULE_STATUS_IN_INDEX | - GIT_SUBMODULE_STATUS__INDEX_OID_VALID); - - if (!(ie = git_index_get_bypath(index, sm->path, 0))) - return 0; - - submodule_update_from_index_entry(sm, ie); - - return 0; -} - -static void submodule_update_from_head_data( - git_submodule *sm, mode_t mode, const git_oid *id) -{ - if (!S_ISGITLINK(mode)) - sm->flags |= GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE; - else { - git_oid_cpy(&sm->head_oid, id); - - sm->flags |= GIT_SUBMODULE_STATUS_IN_HEAD | - GIT_SUBMODULE_STATUS__HEAD_OID_VALID; - } -} - -static int submodule_update_head(git_submodule *submodule) -{ - git_tree *head = NULL; - git_tree_entry *te = NULL; - - submodule->flags = submodule->flags & - ~(GIT_SUBMODULE_STATUS_IN_HEAD | - GIT_SUBMODULE_STATUS__HEAD_OID_VALID); - - /* if we can't look up file in current head, then done */ - if (git_repository_head_tree(&head, submodule->repo) < 0 || - git_tree_entry_bypath(&te, head, submodule->path) < 0) - git_error_clear(); - else - submodule_update_from_head_data(submodule, te->attr, git_tree_entry_id(te)); - - git_tree_entry_free(te); - git_tree_free(head); - return 0; -} - -static int submodule_name_error(const char *name) -{ - git_error_set(GIT_ERROR_SUBMODULE, - "invalid value for submodule name: '%s'", name); - return GIT_EINVALID; -} - -static int submodule_config_error(const char *property, const char *value) -{ - git_error_set(GIT_ERROR_SUBMODULE, - "invalid value for submodule '%s' property: '%s'", property, value); - return GIT_EINVALID; -} - -int git_submodule_reload(git_submodule *sm, int force) -{ - git_config *mods = NULL; - int valid, error = 0; - - GIT_UNUSED(force); - - GIT_ASSERT_ARG(sm); - - if ((valid = git_submodule_name_is_valid(sm->repo, sm->name, 0)) <= 0) { - /* This should come with a warning, but we've no API for that */ - error = valid ? valid : submodule_name_error(sm->name); - goto out; - } - - if (git_repository_is_bare(sm->repo)) - goto out; - - /* refresh config data */ - if ((error = gitmodules_snapshot(&mods, sm->repo)) < 0 && error != GIT_ENOTFOUND) - goto out; - - if (mods != NULL && (error = submodule_read_config(sm, mods)) < 0) - goto out; - - /* refresh wd data */ - sm->flags &= - ~(GIT_SUBMODULE_STATUS_IN_WD | - GIT_SUBMODULE_STATUS__WD_OID_VALID | - GIT_SUBMODULE_STATUS__WD_FLAGS); - - if ((error = submodule_load_from_wd_lite(sm)) < 0 || - (error = submodule_update_index(sm)) < 0 || - (error = submodule_update_head(sm)) < 0) - goto out; - - if ((valid = path_is_valid(sm->repo, sm->path)) <= 0) { - /* This should come with a warning, but we've no API for that */ - error = valid ? valid : submodule_config_error("path", sm->path); - goto out; - } - -out: - git_config_free(mods); - return error; -} - -static void submodule_copy_oid_maybe( - git_oid *tgt, const git_oid *src, bool valid) -{ - if (tgt) { - if (valid) - memcpy(tgt, src, sizeof(*tgt)); - else - memset(tgt, 0, sizeof(*tgt)); - } -} - -int git_submodule__status( - unsigned int *out_status, - git_oid *out_head_id, - git_oid *out_index_id, - git_oid *out_wd_id, - git_submodule *sm, - git_submodule_ignore_t ign) -{ - unsigned int status; - git_repository *smrepo = NULL; - - if (ign == GIT_SUBMODULE_IGNORE_UNSPECIFIED) - ign = sm->ignore; - - /* only return location info if ignore == all */ - if (ign == GIT_SUBMODULE_IGNORE_ALL) { - *out_status = (sm->flags & GIT_SUBMODULE_STATUS__IN_FLAGS); - return 0; - } - - /* If the user has requested caching submodule state, performing these - * expensive operations (especially `submodule_update_head`, which is - * bottlenecked on `git_repository_head_tree`) eliminates much of the - * advantage. We will, therefore, interpret the request for caching to - * apply here to and skip them. - */ - - if (sm->repo->submodule_cache == NULL) { - /* refresh the index OID */ - if (submodule_update_index(sm) < 0) - return -1; - - /* refresh the HEAD OID */ - if (submodule_update_head(sm) < 0) - return -1; - } - - /* for ignore == dirty, don't scan the working directory */ - if (ign == GIT_SUBMODULE_IGNORE_DIRTY) { - /* git_submodule_open_bare will load WD OID data */ - if (git_submodule_open_bare(&smrepo, sm) < 0) - git_error_clear(); - else - git_repository_free(smrepo); - smrepo = NULL; - } else if (git_submodule_open(&smrepo, sm) < 0) { - git_error_clear(); - smrepo = NULL; - } - - status = GIT_SUBMODULE_STATUS__CLEAR_INTERNAL(sm->flags); - - submodule_get_index_status(&status, sm); - submodule_get_wd_status(&status, sm, smrepo, ign); - - git_repository_free(smrepo); - - *out_status = status; - - submodule_copy_oid_maybe(out_head_id, &sm->head_oid, - (sm->flags & GIT_SUBMODULE_STATUS__HEAD_OID_VALID) != 0); - submodule_copy_oid_maybe(out_index_id, &sm->index_oid, - (sm->flags & GIT_SUBMODULE_STATUS__INDEX_OID_VALID) != 0); - submodule_copy_oid_maybe(out_wd_id, &sm->wd_oid, - (sm->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID) != 0); - - return 0; -} - -int git_submodule_status(unsigned int *status, git_repository *repo, const char *name, git_submodule_ignore_t ignore) -{ - git_submodule *sm; - int error; - - GIT_ASSERT_ARG(status); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - if ((error = git_submodule_lookup(&sm, repo, name)) < 0) - return error; - - error = git_submodule__status(status, NULL, NULL, NULL, sm, ignore); - git_submodule_free(sm); - - return error; -} - -int git_submodule_location(unsigned int *location, git_submodule *sm) -{ - GIT_ASSERT_ARG(location); - GIT_ASSERT_ARG(sm); - - return git_submodule__status( - location, NULL, NULL, NULL, sm, GIT_SUBMODULE_IGNORE_ALL); -} - -/* - * INTERNAL FUNCTIONS - */ - -static int submodule_alloc( - git_submodule **out, git_repository *repo, const char *name) -{ - size_t namelen; - git_submodule *sm; - - if (!name || !(namelen = strlen(name))) { - git_error_set(GIT_ERROR_SUBMODULE, "invalid submodule name"); - return -1; - } - - sm = git__calloc(1, sizeof(git_submodule)); - GIT_ERROR_CHECK_ALLOC(sm); - - sm->name = sm->path = git__strdup(name); - if (!sm->name) { - git__free(sm); - return -1; - } - - GIT_REFCOUNT_INC(sm); - sm->ignore = sm->ignore_default = GIT_SUBMODULE_IGNORE_NONE; - sm->update = sm->update_default = GIT_SUBMODULE_UPDATE_CHECKOUT; - sm->fetch_recurse = sm->fetch_recurse_default = GIT_SUBMODULE_RECURSE_NO; - sm->repo = repo; - sm->branch = NULL; - - *out = sm; - return 0; -} - -static void submodule_release(git_submodule *sm) -{ - if (!sm) - return; - - if (sm->repo) { - sm->repo = NULL; - } - - if (sm->path != sm->name) - git__free(sm->path); - git__free(sm->name); - git__free(sm->url); - git__free(sm->branch); - git__memzero(sm, sizeof(*sm)); - git__free(sm); -} - -int git_submodule_dup(git_submodule **out, git_submodule *source) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(source); - - GIT_REFCOUNT_INC(source); - - *out = source; - return 0; -} - -void git_submodule_free(git_submodule *sm) -{ - if (!sm) - return; - GIT_REFCOUNT_DEC(sm, submodule_release); -} - -int git_submodule_parse_ignore(git_submodule_ignore_t *out, const char *value) -{ - int val; - - if (git_config_lookup_map_value( - &val, _sm_ignore_map, ARRAY_SIZE(_sm_ignore_map), value) < 0) { - *out = GIT_SUBMODULE_IGNORE_NONE; - return submodule_config_error("ignore", value); - } - - *out = (git_submodule_ignore_t)val; - return 0; -} - -int git_submodule_parse_update(git_submodule_update_t *out, const char *value) -{ - int val; - - if (git_config_lookup_map_value( - &val, _sm_update_map, ARRAY_SIZE(_sm_update_map), value) < 0) { - *out = GIT_SUBMODULE_UPDATE_CHECKOUT; - return submodule_config_error("update", value); - } - - *out = (git_submodule_update_t)val; - return 0; -} - -static int submodule_parse_recurse(git_submodule_recurse_t *out, const char *value) -{ - int val; - - if (git_config_lookup_map_value( - &val, _sm_recurse_map, ARRAY_SIZE(_sm_recurse_map), value) < 0) { - *out = GIT_SUBMODULE_RECURSE_YES; - return submodule_config_error("recurse", value); - } - - *out = (git_submodule_recurse_t)val; - return 0; -} - -static int get_value(const char **out, git_config *cfg, git_str *buf, const char *name, const char *field) -{ - int error; - - git_str_clear(buf); - - if ((error = git_str_printf(buf, "submodule.%s.%s", name, field)) < 0 || - (error = git_config_get_string(out, cfg, buf->ptr)) < 0) - return error; - - return error; -} - -static bool looks_like_command_line_option(const char *s) -{ - if (s && s[0] == '-') - return true; - - return false; -} - -static int submodule_read_config(git_submodule *sm, git_config *cfg) -{ - git_str key = GIT_STR_INIT; - const char *value; - int error, in_config = 0; - - /* - * TODO: Look up path in index and if it is present but not a GITLINK - * then this should be deleted (at least to match git's behavior) - */ - - if ((error = get_value(&value, cfg, &key, sm->name, "path")) == 0) { - in_config = 1; - /* We would warn here if we had that API */ - if (!looks_like_command_line_option(value)) { - /* - * TODO: if case insensitive filesystem, then the following strcmp - * should be strcasecmp - */ - if (strcmp(sm->name, value) != 0) { - if (sm->path != sm->name) - git__free(sm->path); - sm->path = git__strdup(value); - GIT_ERROR_CHECK_ALLOC(sm->path); - } - - } - } else if (error != GIT_ENOTFOUND) { - goto cleanup; - } - - if ((error = get_value(&value, cfg, &key, sm->name, "url")) == 0) { - /* We would warn here if we had that API */ - if (!looks_like_command_line_option(value)) { - in_config = 1; - sm->url = git__strdup(value); - GIT_ERROR_CHECK_ALLOC(sm->url); - } - } else if (error != GIT_ENOTFOUND) { - goto cleanup; - } - - if ((error = get_value(&value, cfg, &key, sm->name, "branch")) == 0) { - in_config = 1; - sm->branch = git__strdup(value); - GIT_ERROR_CHECK_ALLOC(sm->branch); - } else if (error != GIT_ENOTFOUND) { - goto cleanup; - } - - if ((error = get_value(&value, cfg, &key, sm->name, "update")) == 0) { - in_config = 1; - if ((error = git_submodule_parse_update(&sm->update, value)) < 0) - goto cleanup; - sm->update_default = sm->update; - } else if (error != GIT_ENOTFOUND) { - goto cleanup; - } - - if ((error = get_value(&value, cfg, &key, sm->name, "fetchRecurseSubmodules")) == 0) { - in_config = 1; - if ((error = submodule_parse_recurse(&sm->fetch_recurse, value)) < 0) - goto cleanup; - sm->fetch_recurse_default = sm->fetch_recurse; - } else if (error != GIT_ENOTFOUND) { - goto cleanup; - } - - if ((error = get_value(&value, cfg, &key, sm->name, "ignore")) == 0) { - in_config = 1; - if ((error = git_submodule_parse_ignore(&sm->ignore, value)) < 0) - goto cleanup; - sm->ignore_default = sm->ignore; - } else if (error != GIT_ENOTFOUND) { - goto cleanup; - } - - if (in_config) - sm->flags |= GIT_SUBMODULE_STATUS_IN_CONFIG; - - error = 0; - -cleanup: - git_str_dispose(&key); - return error; -} - -static int submodule_load_each(const git_config_entry *entry, void *payload) -{ - lfc_data *data = payload; - const char *namestart, *property; - git_submodule_cache *cache = data->cache; - git_str name = GIT_STR_INIT; - git_submodule *sm; - int error, isvalid; - - if (git__prefixcmp(entry->name, "submodule.") != 0) - return 0; - - namestart = entry->name + strlen("submodule."); - property = strrchr(namestart, '.'); - - if (!property || (property == namestart)) - return 0; - - property++; - - if ((error = git_str_set(&name, namestart, property - namestart -1)) < 0) - return error; - - isvalid = git_submodule_name_is_valid(data->repo, name.ptr, 0); - if (isvalid <= 0) { - error = isvalid; - goto done; - } - - /* - * Now that we have the submodule's name, we can use that to - * figure out whether it's in the map. If it's not, we create - * a new submodule, load the config and insert it. If it's - * already inserted, we've already loaded it, so we skip. - */ - if (git_submodule_cache_contains(cache, name.ptr)) { - error = 0; - goto done; - } - - if ((error = submodule_alloc(&sm, data->repo, name.ptr)) < 0) - goto done; - - if ((error = submodule_read_config(sm, data->mods)) < 0) { - git_submodule_free(sm); - goto done; - } - - isvalid = path_is_valid(data->repo, sm->path); - if (isvalid <= 0) { - git_submodule_free(sm); - error = isvalid; - goto done; - } - - if ((error = git_submodule_cache_put(cache, sm->name, sm)) < 0) - goto done; - - error = 0; - -done: - git_str_dispose(&name); - return error; -} - -static int submodule_load_from_wd_lite(git_submodule *sm) -{ - git_str path = GIT_STR_INIT; - - if (git_repository_workdir_path(&path, sm->repo, sm->path) < 0) - return -1; - - if (git_fs_path_isdir(path.ptr)) - sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED; - - if (git_fs_path_contains(&path, DOT_GIT)) - sm->flags |= GIT_SUBMODULE_STATUS_IN_WD; - - git_str_dispose(&path); - return 0; -} - -/** - * Requests a snapshot of $WORK_TREE/.gitmodules. - * - * Returns GIT_ENOTFOUND in case no .gitmodules file exist - */ -static int gitmodules_snapshot(git_config **snap, git_repository *repo) -{ - git_config *mods = NULL; - git_str path = GIT_STR_INIT; - int error; - - if (git_repository_workdir(repo) == NULL) - return GIT_ENOTFOUND; - - if ((error = git_repository_workdir_path(&path, repo, GIT_MODULES_FILE)) < 0) - return error; - - if ((error = git_config_open_ondisk(&mods, path.ptr)) < 0) - goto cleanup; - git_str_dispose(&path); - - if ((error = git_config_snapshot(snap, mods)) < 0) - goto cleanup; - - error = 0; - -cleanup: - if (mods) - git_config_free(mods); - git_str_dispose(&path); - - return error; -} - -static git_config_backend *open_gitmodules( - git_repository *repo, - int okay_to_create) -{ - git_str path = GIT_STR_INIT; - git_config_backend *mods = NULL; - - if (git_repository_workdir(repo) != NULL) { - if (git_repository_workdir_path(&path, repo, GIT_MODULES_FILE) != 0) - return NULL; - - if (okay_to_create || git_fs_path_isfile(path.ptr)) { - /* git_config_backend_from_file should only fail if OOM */ - if (git_config_backend_from_file(&mods, path.ptr) < 0) - mods = NULL; - /* open should only fail here if the file is malformed */ - else if (git_config_backend_open(mods, GIT_CONFIG_LEVEL_LOCAL, repo) < 0) { - git_config_backend_free(mods); - mods = NULL; - } - } - } - - git_str_dispose(&path); - - return mods; -} - -/* Lookup name of remote of the local tracking branch HEAD points to */ -static int lookup_head_remote_key(git_str *remote_name, git_repository *repo) -{ - int error; - git_reference *head = NULL; - git_str upstream_name = GIT_STR_INIT; - - /* lookup and dereference HEAD */ - if ((error = git_repository_head(&head, repo)) < 0) - return error; - - /** - * If head does not refer to a branch, then return - * GIT_ENOTFOUND to indicate that we could not find - * a remote key for the local tracking branch HEAD points to. - **/ - if (!git_reference_is_branch(head)) { - git_error_set(GIT_ERROR_INVALID, - "HEAD does not refer to a branch."); - error = GIT_ENOTFOUND; - goto done; - } - - /* lookup remote tracking branch of HEAD */ - if ((error = git_branch__upstream_name( - &upstream_name, - repo, - git_reference_name(head))) < 0) - goto done; - - /* lookup remote of remote tracking branch */ - if ((error = git_branch__remote_name(remote_name, repo, upstream_name.ptr)) < 0) - goto done; - -done: - git_str_dispose(&upstream_name); - git_reference_free(head); - - return error; -} - -/* Lookup the remote of the local tracking branch HEAD points to */ -static int lookup_head_remote(git_remote **remote, git_repository *repo) -{ - int error; - git_str remote_name = GIT_STR_INIT; - - /* lookup remote of remote tracking branch name */ - if (!(error = lookup_head_remote_key(&remote_name, repo))) - error = git_remote_lookup(remote, repo, remote_name.ptr); - - git_str_dispose(&remote_name); - - return error; -} - -/* Lookup remote, either from HEAD or fall back on origin */ -static int lookup_default_remote(git_remote **remote, git_repository *repo) -{ - int error = lookup_head_remote(remote, repo); - - /* if that failed, use 'origin' instead */ - if (error == GIT_ENOTFOUND || error == GIT_EUNBORNBRANCH) - error = git_remote_lookup(remote, repo, "origin"); - - if (error == GIT_ENOTFOUND) - git_error_set( - GIT_ERROR_SUBMODULE, - "cannot get default remote for submodule - no local tracking " - "branch for HEAD and origin does not exist"); - - return error; -} - -static int get_url_base(git_str *url, git_repository *repo) -{ - int error; - git_worktree *wt = NULL; - git_remote *remote = NULL; - - if ((error = lookup_default_remote(&remote, repo)) == 0) { - error = git_str_sets(url, git_remote_url(remote)); - goto out; - } else if (error != GIT_ENOTFOUND) - goto out; - else - git_error_clear(); - - /* if repository does not have a default remote, use workdir instead */ - if (git_repository_is_worktree(repo)) { - if ((error = git_worktree_open_from_repository(&wt, repo)) < 0) - goto out; - error = git_str_sets(url, wt->parent_path); - } else { - error = git_str_sets(url, git_repository_workdir(repo)); - } - -out: - git_remote_free(remote); - git_worktree_free(wt); - - return error; -} - -static void submodule_get_index_status(unsigned int *status, git_submodule *sm) -{ - const git_oid *head_oid = git_submodule_head_id(sm); - const git_oid *index_oid = git_submodule_index_id(sm); - - *status = *status & ~GIT_SUBMODULE_STATUS__INDEX_FLAGS; - - if (!head_oid) { - if (index_oid) - *status |= GIT_SUBMODULE_STATUS_INDEX_ADDED; - } - else if (!index_oid) - *status |= GIT_SUBMODULE_STATUS_INDEX_DELETED; - else if (!git_oid_equal(head_oid, index_oid)) - *status |= GIT_SUBMODULE_STATUS_INDEX_MODIFIED; -} - - -static void submodule_get_wd_status( - unsigned int *status, - git_submodule *sm, - git_repository *sm_repo, - git_submodule_ignore_t ign) -{ - const git_oid *index_oid = git_submodule_index_id(sm); - const git_oid *wd_oid = - (sm->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID) ? &sm->wd_oid : NULL; - git_tree *sm_head = NULL; - git_index *index = NULL; - git_diff_options opt = GIT_DIFF_OPTIONS_INIT; - git_diff *diff; - - *status = *status & ~GIT_SUBMODULE_STATUS__WD_FLAGS; - - if (!index_oid) { - if (wd_oid) - *status |= GIT_SUBMODULE_STATUS_WD_ADDED; - } - else if (!wd_oid) { - if ((sm->flags & GIT_SUBMODULE_STATUS__WD_SCANNED) != 0 && - (sm->flags & GIT_SUBMODULE_STATUS_IN_WD) == 0) - *status |= GIT_SUBMODULE_STATUS_WD_UNINITIALIZED; - else - *status |= GIT_SUBMODULE_STATUS_WD_DELETED; - } - else if (!git_oid_equal(index_oid, wd_oid)) - *status |= GIT_SUBMODULE_STATUS_WD_MODIFIED; - - /* if we have no repo, then we're done */ - if (!sm_repo) - return; - - /* the diffs below could be optimized with an early termination - * option to the git_diff functions, but for now this is sufficient - * (and certainly no worse that what core git does). - */ - - if (ign == GIT_SUBMODULE_IGNORE_NONE) - opt.flags |= GIT_DIFF_INCLUDE_UNTRACKED; - - (void)git_repository_index__weakptr(&index, sm_repo); - - /* if we don't have an unborn head, check diff with index */ - if (git_repository_head_tree(&sm_head, sm_repo) < 0) - git_error_clear(); - else { - /* perform head to index diff on submodule */ - if (git_diff_tree_to_index(&diff, sm_repo, sm_head, index, &opt) < 0) - git_error_clear(); - else { - if (git_diff_num_deltas(diff) > 0) - *status |= GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED; - git_diff_free(diff); - diff = NULL; - } - - git_tree_free(sm_head); - } - - /* perform index-to-workdir diff on submodule */ - if (git_diff_index_to_workdir(&diff, sm_repo, index, &opt) < 0) - git_error_clear(); - else { - size_t untracked = - git_diff_num_deltas_of_type(diff, GIT_DELTA_UNTRACKED); - - if (untracked > 0) - *status |= GIT_SUBMODULE_STATUS_WD_UNTRACKED; - - if (git_diff_num_deltas(diff) != untracked) - *status |= GIT_SUBMODULE_STATUS_WD_WD_MODIFIED; - - git_diff_free(diff); - diff = NULL; - } -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/submodule.h b/vendor/libgit2-sys/libgit2/src/libgit2/submodule.h deleted file mode 100644 index 2690d8d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/submodule.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_submodule_h__ -#define INCLUDE_submodule_h__ - -#include "common.h" - -#include "git2/submodule.h" -#include "git2/repository.h" -#include "futils.h" -#include "hashmap.h" - -/* Notes: - * - * Submodule information can be in four places: the index, the config files - * (both .git/config and .gitmodules), the HEAD tree, and the working - * directory. - * - * In the index: - * - submodule is found by path - * - may be missing, present, or of the wrong type - * - will have an oid if present - * - * In the HEAD tree: - * - submodule is found by path - * - may be missing, present, or of the wrong type - * - will have an oid if present - * - * In the config files: - * - submodule is found by submodule "name" which is usually the path - * - may be missing or present - * - will have a name, path, url, and other properties - * - * In the working directory: - * - submodule is found by path - * - may be missing, an empty directory, a checked out directory, - * or of the wrong type - * - if checked out, will have a HEAD oid - * - if checked out, will have git history that can be used to compare oids - * - if checked out, may have modified files and/or untracked files - */ - -/** - * Description of submodule - * - * This record describes a submodule found in a repository. There should be - * an entry for every submodule found in the HEAD and index, and for every - * submodule described in .gitmodules. The fields are as follows: - * - * - `rc` tracks the refcount of how many hash table entries in the - * git_submodule_cache there are for this submodule. It only comes into - * play if the name and path of the submodule differ. - * - * - `name` is the name of the submodule from .gitmodules. - * - `path` is the path to the submodule from the repo root. It is almost - * always the same as `name`. - * - `url` is the url for the submodule. - * - `update` is a git_submodule_update_t value - see gitmodules(5) update. - * - `update_default` is the update value from the config - * - `ignore` is a git_submodule_ignore_t value - see gitmodules(5) ignore. - * - `ignore_default` is the ignore value from the config - * - `fetch_recurse` is a git_submodule_recurse_t value - see gitmodules(5) - * fetchRecurseSubmodules. - * - `fetch_recurse_default` is the recurse value from the config - * - * - `repo` is the parent repository that contains this submodule. - * - `flags` after for internal use, tracking where this submodule has been - * found (head, index, config, workdir) and known status info, etc. - * - `head_oid` is the oid for the submodule path in the repo HEAD. - * - `index_oid` is the oid for the submodule recorded in the index. - * - `wd_oid` is the oid for the HEAD of the checked out submodule. - * - * If the submodule has been added to .gitmodules but not yet git added, - * then the `index_oid` will be zero but still marked valid. If the - * submodule has been deleted, but the delete has not been committed yet, - * then the `index_oid` will be set, but the `url` will be NULL. - */ -struct git_submodule { - git_refcount rc; - - /* information from config */ - char *name; - char *path; /* important: may just point to "name" string */ - char *url; - char *branch; - git_submodule_update_t update; - git_submodule_update_t update_default; - git_submodule_ignore_t ignore; - git_submodule_ignore_t ignore_default; - git_submodule_recurse_t fetch_recurse; - git_submodule_recurse_t fetch_recurse_default; - - /* internal information */ - git_repository *repo; - uint32_t flags; - git_oid head_oid; - git_oid index_oid; - git_oid wd_oid; -}; - -/* Additional flags on top of public GIT_SUBMODULE_STATUS values */ -enum { - GIT_SUBMODULE_STATUS__WD_SCANNED = (1u << 20), - GIT_SUBMODULE_STATUS__HEAD_OID_VALID = (1u << 21), - GIT_SUBMODULE_STATUS__INDEX_OID_VALID = (1u << 22), - GIT_SUBMODULE_STATUS__WD_OID_VALID = (1u << 23), - GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE = (1u << 24), - GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE = (1u << 25), - GIT_SUBMODULE_STATUS__WD_NOT_SUBMODULE = (1u << 26), - GIT_SUBMODULE_STATUS__INDEX_MULTIPLE_ENTRIES = (1u << 27) -}; - -#define GIT_SUBMODULE_STATUS__CLEAR_INTERNAL(S) \ - ((S) & ~(0xFFFFFFFFu << 20)) - -GIT_HASHMAP_STR_STRUCT(git_submodule_cache, git_submodule *); - -/* Initialize an external submodule cache for the provided repo. */ -extern int git_submodule_cache_init(git_submodule_cache **out, git_repository *repo); - -/* Release the resources of the submodule cache. */ -extern int git_submodule_cache_free(git_submodule_cache *cache); - -/* Submodule lookup with an explicit cache */ -extern int git_submodule__lookup_with_cache( - git_submodule **out, git_repository *repo, const char *path, git_submodule_cache *cache); - -/* Internal status fn returns status and optionally the various OIDs */ -extern int git_submodule__status( - unsigned int *out_status, - git_oid *out_head_id, - git_oid *out_index_id, - git_oid *out_wd_id, - git_submodule *sm, - git_submodule_ignore_t ign); - -/* Open submodule repository as bare repo for quick HEAD check, etc. */ -extern int git_submodule_open_bare( - git_repository **repo, - git_submodule *submodule); - -extern int git_submodule_parse_ignore( - git_submodule_ignore_t *out, const char *value); -extern int git_submodule_parse_update( - git_submodule_update_t *out, const char *value); - -/** - * Check whether a submodule's name is valid. - * - * Check the path against the path validity rules, either the filesystem - * defaults (like checkout does) or whichever you want to compare against. - * - * @param repo the repository which contains the submodule - * @param name the name to check - * @param flags the `GIT_PATH` flags to use for the check (0 to use filesystem defaults) - */ -extern int git_submodule_name_is_valid(git_repository *repo, const char *name, int flags); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/sysdir.c b/vendor/libgit2-sys/libgit2/src/libgit2/sysdir.c deleted file mode 100644 index 7838a67..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/sysdir.c +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "sysdir.h" - -#include "runtime.h" -#include "str.h" -#include "fs_path.h" -#include -#if GIT_WIN32 -# include "fs_path.h" -# include "win32/path_w32.h" -# include "win32/utf-conv.h" -#else -# include -# include -#endif - -#ifdef GIT_WIN32 -# define REG_GITFORWINDOWS_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" -# define REG_GITFORWINDOWS_KEY_WOW64 L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" - -static int expand_win32_path(git_win32_path dest, const wchar_t *src) -{ - DWORD len = ExpandEnvironmentStringsW(src, dest, GIT_WIN_PATH_UTF16); - - if (!len || len > GIT_WIN_PATH_UTF16) - return -1; - - return 0; -} - -static int win32_path_to_utf8(git_str *dest, const wchar_t *src) -{ - git_win32_utf8_path utf8_path; - - if (git_win32_path_to_utf8(utf8_path, src) < 0) { - git_error_set(GIT_ERROR_OS, "unable to convert path to UTF-8"); - return -1; - } - - /* Convert backslashes to forward slashes */ - git_fs_path_mkposix(utf8_path); - - return git_str_sets(dest, utf8_path); -} - -static git_win32_path mock_registry; -static bool mock_registry_set; - -extern int git_win32__set_registry_system_dir(const wchar_t *mock_sysdir) -{ - if (!mock_sysdir) { - mock_registry[0] = L'\0'; - mock_registry_set = false; - } else { - size_t len = wcslen(mock_sysdir); - - if (len > GIT_WIN_PATH_MAX) { - git_error_set(GIT_ERROR_INVALID, "mock path too long"); - return -1; - } - - wcscpy(mock_registry, mock_sysdir); - mock_registry_set = true; - } - - return 0; -} - -static int lookup_registry_key( - git_win32_path out, - const HKEY hive, - const wchar_t* key, - const wchar_t *value) -{ - HKEY hkey; - DWORD type, size; - int error = GIT_ENOTFOUND; - - /* - * Registry data may not be NUL terminated, provide room to do - * it ourselves. - */ - size = (DWORD)((sizeof(git_win32_path) - 1) * sizeof(wchar_t)); - - if (RegOpenKeyExW(hive, key, 0, KEY_READ, &hkey) != 0) - return GIT_ENOTFOUND; - - if (RegQueryValueExW(hkey, value, NULL, &type, (LPBYTE)out, &size) == 0 && - type == REG_SZ && - size > 0 && - size < sizeof(git_win32_path)) { - size_t wsize = size / sizeof(wchar_t); - size_t len = wsize - 1; - - if (out[wsize - 1] != L'\0') { - len = wsize; - out[wsize] = L'\0'; - } - - if (out[len - 1] == L'\\') - out[len - 1] = L'\0'; - - if (_waccess(out, F_OK) == 0) - error = 0; - } - - RegCloseKey(hkey); - return error; -} - -static int find_sysdir_in_registry(git_win32_path out) -{ - if (mock_registry_set) { - if (mock_registry[0] == L'\0') - return GIT_ENOTFOUND; - - wcscpy(out, mock_registry); - return 0; - } - - if (lookup_registry_key(out, HKEY_CURRENT_USER, REG_GITFORWINDOWS_KEY, L"InstallLocation") == 0 || - lookup_registry_key(out, HKEY_CURRENT_USER, REG_GITFORWINDOWS_KEY_WOW64, L"InstallLocation") == 0 || - lookup_registry_key(out, HKEY_LOCAL_MACHINE, REG_GITFORWINDOWS_KEY, L"InstallLocation") == 0 || - lookup_registry_key(out, HKEY_LOCAL_MACHINE, REG_GITFORWINDOWS_KEY_WOW64, L"InstallLocation") == 0) - return 0; - - return GIT_ENOTFOUND; -} - -static int find_sysdir_in_path(git_win32_path out) -{ - size_t out_len; - - if (git_win32_path_find_executable(out, L"git.exe") < 0 && - git_win32_path_find_executable(out, L"git.cmd") < 0) - return GIT_ENOTFOUND; - - out_len = wcslen(out); - - /* Trim the file name */ - if (out_len <= CONST_STRLEN(L"git.exe")) - return GIT_ENOTFOUND; - - out_len -= CONST_STRLEN(L"git.exe"); - - if (out_len && out[out_len - 1] == L'\\') - out_len--; - - /* - * Git for Windows usually places the command in a 'bin' or - * 'cmd' directory, trim that. - */ - if (out_len >= CONST_STRLEN(L"\\bin") && - wcsncmp(&out[out_len - CONST_STRLEN(L"\\bin")], L"\\bin", CONST_STRLEN(L"\\bin")) == 0) - out_len -= CONST_STRLEN(L"\\bin"); - else if (out_len >= CONST_STRLEN(L"\\cmd") && - wcsncmp(&out[out_len - CONST_STRLEN(L"\\cmd")], L"\\cmd", CONST_STRLEN(L"\\cmd")) == 0) - out_len -= CONST_STRLEN(L"\\cmd"); - - if (!out_len) - return GIT_ENOTFOUND; - - out[out_len] = L'\0'; - return 0; -} - -static int find_win32_dirs( - git_str *out, - const wchar_t* tmpl[]) -{ - git_win32_path path16; - git_str buf = GIT_STR_INIT; - - git_str_clear(out); - - for (; *tmpl != NULL; tmpl++) { - if (!expand_win32_path(path16, *tmpl) && - path16[0] != L'%' && - !_waccess(path16, F_OK)) { - win32_path_to_utf8(&buf, path16); - - if (buf.size) - git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr); - } - } - - git_str_dispose(&buf); - - return (git_str_oom(out) ? -1 : 0); -} - -static int append_subdir(git_str *out, git_str *path, const char *subdir) -{ - static const char* architecture_roots[] = { - "", - "mingw64", - "mingw32", - NULL - }; - const char **root; - size_t orig_path_len = path->size; - - for (root = architecture_roots; *root; root++) { - if ((*root[0] && git_str_joinpath(path, path->ptr, *root) < 0) || - git_str_joinpath(path, path->ptr, subdir) < 0) - return -1; - - if (git_fs_path_exists(path->ptr) && - git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, path->ptr) < 0) - return -1; - - git_str_truncate(path, orig_path_len); - } - - return 0; -} - -int git_win32__find_system_dirs(git_str *out, const char *subdir) -{ - git_win32_path pathdir, regdir; - git_str path8 = GIT_STR_INIT; - bool has_pathdir, has_regdir; - int error; - - has_pathdir = (find_sysdir_in_path(pathdir) == 0); - has_regdir = (find_sysdir_in_registry(regdir) == 0); - - if (!has_pathdir && !has_regdir) - return 0; - - /* - * Usually the git in the path is the same git in the registry, - * in this case there's no need to duplicate the paths. - */ - if (has_pathdir && has_regdir && wcscmp(pathdir, regdir) == 0) - has_regdir = false; - - if (has_pathdir) { - if ((error = win32_path_to_utf8(&path8, pathdir)) < 0 || - (error = append_subdir(out, &path8, subdir)) < 0) - goto done; - } - - if (has_regdir) { - if ((error = win32_path_to_utf8(&path8, regdir)) < 0 || - (error = append_subdir(out, &path8, subdir)) < 0) - goto done; - } - -done: - git_str_dispose(&path8); - return error; -} -#endif /* WIN32 */ - -static int git_sysdir_guess_programdata_dirs(git_str *out) -{ -#ifdef GIT_WIN32 - static const wchar_t *programdata_tmpls[2] = { - L"%PROGRAMDATA%\\Git", - NULL, - }; - - return find_win32_dirs(out, programdata_tmpls); -#else - git_str_clear(out); - return 0; -#endif -} - -static int git_sysdir_guess_system_dirs(git_str *out) -{ -#ifdef GIT_WIN32 - return git_win32__find_system_dirs(out, "etc"); -#else - return git_str_sets(out, "/etc"); -#endif -} - -#ifndef GIT_WIN32 -static int get_passwd_home(git_str *out, uid_t uid) -{ - struct passwd pwd, *pwdptr; - char *buf = NULL; - long buflen; - int error; - - GIT_ASSERT_ARG(out); - - if ((buflen = sysconf(_SC_GETPW_R_SIZE_MAX)) == -1) - buflen = 1024; - - do { - buf = git__realloc(buf, buflen); - error = getpwuid_r(uid, &pwd, buf, buflen, &pwdptr); - buflen *= 2; - } while (error == ERANGE && buflen <= 8192); - - if (error) { - git_error_set(GIT_ERROR_OS, "failed to get passwd entry"); - goto out; - } - - if (!pwdptr) { - git_error_set(GIT_ERROR_OS, "no passwd entry found for user"); - goto out; - } - - if ((error = git_str_puts(out, pwdptr->pw_dir)) < 0) - goto out; - -out: - git__free(buf); - return error; -} -#endif - -static int git_sysdir_guess_home_dirs(git_str *out) -{ -#ifdef GIT_WIN32 - static const wchar_t *global_tmpls[4] = { - L"%HOME%\\", - L"%HOMEDRIVE%%HOMEPATH%\\", - L"%USERPROFILE%\\", - NULL, - }; - - return find_win32_dirs(out, global_tmpls); -#else - int error; - uid_t uid, euid; - const char *sandbox_id; - - uid = getuid(); - euid = geteuid(); - - /** - * If APP_SANDBOX_CONTAINER_ID is set, we are running in a - * sandboxed environment on macOS. - */ - sandbox_id = getenv("APP_SANDBOX_CONTAINER_ID"); - - /* - * In case we are running setuid, use the configuration - * of the effective user. - * - * If we are running in a sandboxed environment on macOS, - * we have to get the HOME dir from the password entry file. - */ - if (!sandbox_id && uid == euid) - error = git__getenv(out, "HOME"); - else - error = get_passwd_home(out, euid); - - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - - return error; -#endif -} - -static int git_sysdir_guess_global_dirs(git_str *out) -{ - return git_sysdir_guess_home_dirs(out); -} - -static int git_sysdir_guess_xdg_dirs(git_str *out) -{ -#ifdef GIT_WIN32 - static const wchar_t *global_tmpls[7] = { - L"%XDG_CONFIG_HOME%\\git", - L"%APPDATA%\\git", - L"%LOCALAPPDATA%\\git", - L"%HOME%\\.config\\git", - L"%HOMEDRIVE%%HOMEPATH%\\.config\\git", - L"%USERPROFILE%\\.config\\git", - NULL, - }; - - return find_win32_dirs(out, global_tmpls); -#else - git_str env = GIT_STR_INIT; - int error; - uid_t uid, euid; - - uid = getuid(); - euid = geteuid(); - - /* - * In case we are running setuid, only look up passwd - * directory of the effective user. - */ - if (uid == euid) { - if ((error = git__getenv(&env, "XDG_CONFIG_HOME")) == 0) - error = git_str_joinpath(out, env.ptr, "git"); - - if (error == GIT_ENOTFOUND && (error = git__getenv(&env, "HOME")) == 0) - error = git_str_joinpath(out, env.ptr, ".config/git"); - } else { - if ((error = get_passwd_home(&env, euid)) == 0) - error = git_str_joinpath(out, env.ptr, ".config/git"); - } - - if (error == GIT_ENOTFOUND) { - git_error_clear(); - error = 0; - } - - git_str_dispose(&env); - return error; -#endif -} - -static int git_sysdir_guess_template_dirs(git_str *out) -{ -#ifdef GIT_WIN32 - return git_win32__find_system_dirs(out, "share/git-core/templates"); -#else - return git_str_sets(out, "/usr/share/git-core/templates"); -#endif -} - -struct git_sysdir__dir { - git_str buf; - int (*guess)(git_str *out); -}; - -static struct git_sysdir__dir git_sysdir__dirs[] = { - { GIT_STR_INIT, git_sysdir_guess_system_dirs }, - { GIT_STR_INIT, git_sysdir_guess_global_dirs }, - { GIT_STR_INIT, git_sysdir_guess_xdg_dirs }, - { GIT_STR_INIT, git_sysdir_guess_programdata_dirs }, - { GIT_STR_INIT, git_sysdir_guess_template_dirs }, - { GIT_STR_INIT, git_sysdir_guess_home_dirs } -}; - -static void git_sysdir_global_shutdown(void) -{ - size_t i; - - for (i = 0; i < ARRAY_SIZE(git_sysdir__dirs); ++i) - git_str_dispose(&git_sysdir__dirs[i].buf); -} - -int git_sysdir_global_init(void) -{ - size_t i; - int error = 0; - - for (i = 0; !error && i < ARRAY_SIZE(git_sysdir__dirs); i++) - error = git_sysdir__dirs[i].guess(&git_sysdir__dirs[i].buf); - - if (error) - return error; - - return git_runtime_shutdown_register(git_sysdir_global_shutdown); -} - -int git_sysdir_reset(void) -{ - size_t i; - int error = 0; - - for (i = 0; !error && i < ARRAY_SIZE(git_sysdir__dirs); ++i) { - git_str_dispose(&git_sysdir__dirs[i].buf); - error = git_sysdir__dirs[i].guess(&git_sysdir__dirs[i].buf); - } - - return error; -} - -static int git_sysdir_check_selector(git_sysdir_t which) -{ - if (which < ARRAY_SIZE(git_sysdir__dirs)) - return 0; - - git_error_set(GIT_ERROR_INVALID, "config directory selector out of range"); - return -1; -} - - -int git_sysdir_get(const git_str **out, git_sysdir_t which) -{ - GIT_ASSERT_ARG(out); - - *out = NULL; - - GIT_ERROR_CHECK_ERROR(git_sysdir_check_selector(which)); - - *out = &git_sysdir__dirs[which].buf; - return 0; -} - -#define PATH_MAGIC "$PATH" - -int git_sysdir_set(git_sysdir_t which, const char *search_path) -{ - const char *expand_path = NULL; - git_str merge = GIT_STR_INIT; - - GIT_ERROR_CHECK_ERROR(git_sysdir_check_selector(which)); - - if (search_path != NULL) - expand_path = strstr(search_path, PATH_MAGIC); - - /* reset the default if this path has been cleared */ - if (!search_path) - git_sysdir__dirs[which].guess(&git_sysdir__dirs[which].buf); - - /* if $PATH is not referenced, then just set the path */ - if (!expand_path) { - if (search_path) - git_str_sets(&git_sysdir__dirs[which].buf, search_path); - - goto done; - } - - /* otherwise set to join(before $PATH, old value, after $PATH) */ - if (expand_path > search_path) - git_str_set(&merge, search_path, expand_path - search_path); - - if (git_str_len(&git_sysdir__dirs[which].buf)) - git_str_join(&merge, GIT_PATH_LIST_SEPARATOR, - merge.ptr, git_sysdir__dirs[which].buf.ptr); - - expand_path += strlen(PATH_MAGIC); - if (*expand_path) - git_str_join(&merge, GIT_PATH_LIST_SEPARATOR, merge.ptr, expand_path); - - git_str_swap(&git_sysdir__dirs[which].buf, &merge); - git_str_dispose(&merge); - -done: - if (git_str_oom(&git_sysdir__dirs[which].buf)) - return -1; - - return 0; -} - -static int git_sysdir_find_in_dirlist( - git_str *path, - const char *name, - git_sysdir_t which, - const char *label) -{ - size_t len; - const char *scan, *next = NULL; - const git_str *syspath; - - GIT_ERROR_CHECK_ERROR(git_sysdir_get(&syspath, which)); - if (!syspath || !git_str_len(syspath)) - goto done; - - for (scan = git_str_cstr(syspath); scan; scan = next) { - /* find unescaped separator or end of string */ - for (next = scan; *next; ++next) { - if (*next == GIT_PATH_LIST_SEPARATOR && - (next <= scan || next[-1] != '\\')) - break; - } - - len = (size_t)(next - scan); - next = (*next ? next + 1 : NULL); - if (!len) - continue; - - GIT_ERROR_CHECK_ERROR(git_str_set(path, scan, len)); - if (name) - GIT_ERROR_CHECK_ERROR(git_str_joinpath(path, path->ptr, name)); - - if (git_fs_path_exists(path->ptr)) - return 0; - } - -done: - if (name) - git_error_set(GIT_ERROR_OS, "the %s file '%s' doesn't exist", label, name); - else - git_error_set(GIT_ERROR_OS, "the %s directory doesn't exist", label); - git_str_dispose(path); - return GIT_ENOTFOUND; -} - -int git_sysdir_find_system_file(git_str *path, const char *filename) -{ - return git_sysdir_find_in_dirlist( - path, filename, GIT_SYSDIR_SYSTEM, "system"); -} - -int git_sysdir_find_global_file(git_str *path, const char *filename) -{ - return git_sysdir_find_in_dirlist( - path, filename, GIT_SYSDIR_GLOBAL, "global"); -} - -int git_sysdir_find_xdg_file(git_str *path, const char *filename) -{ - return git_sysdir_find_in_dirlist( - path, filename, GIT_SYSDIR_XDG, "global/xdg"); -} - -int git_sysdir_find_programdata_file(git_str *path, const char *filename) -{ - return git_sysdir_find_in_dirlist( - path, filename, GIT_SYSDIR_PROGRAMDATA, "ProgramData"); -} - -int git_sysdir_find_template_dir(git_str *path) -{ - return git_sysdir_find_in_dirlist( - path, NULL, GIT_SYSDIR_TEMPLATE, "template"); -} - -int git_sysdir_find_homedir(git_str *path) -{ - return git_sysdir_find_in_dirlist( - path, NULL, GIT_SYSDIR_HOME, "home directory"); -} - -int git_sysdir_expand_global_file(git_str *path, const char *filename) -{ - int error; - - if ((error = git_sysdir_find_global_file(path, NULL)) == 0) { - if (filename) - error = git_str_joinpath(path, path->ptr, filename); - } - - return error; -} - -int git_sysdir_expand_homedir_file(git_str *path, const char *filename) -{ - int error; - - if ((error = git_sysdir_find_homedir(path)) == 0) { - if (filename) - error = git_str_joinpath(path, path->ptr, filename); - } - - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/sysdir.h b/vendor/libgit2-sys/libgit2/src/libgit2/sysdir.h deleted file mode 100644 index 03f59e1..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/sysdir.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sysdir_h__ -#define INCLUDE_sysdir_h__ - -#include "common.h" - -#include "posix.h" -#include "str.h" - -/** - * Find a "global" file (i.e. one in a user's home directory). - * - * @param path buffer to write the full path into - * @param filename name of file to find in the home directory - * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error - */ -extern int git_sysdir_find_global_file(git_str *path, const char *filename); - -/** - * Find an "XDG" file (i.e. one in user's XDG config path). - * - * @param path buffer to write the full path into - * @param filename name of file to find in the home directory - * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error - */ -extern int git_sysdir_find_xdg_file(git_str *path, const char *filename); - -/** - * Find a "system" file (i.e. one shared for all users of the system). - * - * @param path buffer to write the full path into - * @param filename name of file to find in the home directory - * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error - */ -extern int git_sysdir_find_system_file(git_str *path, const char *filename); - -/** - * Find a "ProgramData" file (i.e. one in %PROGRAMDATA%) - * - * @param path buffer to write the full path into - * @param filename name of file to find in the ProgramData directory - * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error - */ -extern int git_sysdir_find_programdata_file(git_str *path, const char *filename); - -/** - * Find template directory. - * - * @param path buffer to write the full path into - * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error - */ -extern int git_sysdir_find_template_dir(git_str *path); - -/** - * Find the home directory. On Windows, this will look at the `HOME`, - * `HOMEPATH`, and `USERPROFILE` environment variables (in that order) - * and return the first path that is set and exists. On other systems, - * this will simply return the contents of the `HOME` environment variable. - * - * @param path buffer to write the full path into - * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error - */ -extern int git_sysdir_find_homedir(git_str *path); - -/** - * Expand the name of a "global" file -- by default inside the user's - * home directory, but can be overridden by the user configuration. - * Unlike `find_global_file` (above), this makes no attempt to check - * for the existence of the file, and is useful if you want the full - * path regardless of existence. - * - * @param path buffer to write the full path into - * @param filename name of file in the home directory - * @return 0 on success or -1 on error - */ -extern int git_sysdir_expand_global_file(git_str *path, const char *filename); - -/** - * Expand the name of a file in the user's home directory. This - * function makes no attempt to check for the existence of the file, - * and is useful if you want the full path regardless of existence. - * - * @param path buffer to write the full path into - * @param filename name of file in the home directory - * @return 0 on success or -1 on error - */ -extern int git_sysdir_expand_homedir_file(git_str *path, const char *filename); - -typedef enum { - GIT_SYSDIR_SYSTEM = 0, - GIT_SYSDIR_GLOBAL = 1, - GIT_SYSDIR_XDG = 2, - GIT_SYSDIR_PROGRAMDATA = 3, - GIT_SYSDIR_TEMPLATE = 4, - GIT_SYSDIR_HOME = 5, - GIT_SYSDIR__MAX = 6 -} git_sysdir_t; - -/** - * Configures global data for configuration file search paths. - * - * @return 0 on success, <0 on failure - */ -extern int git_sysdir_global_init(void); - -/** - * Get the search path for global/system/xdg files - * - * @param out pointer to git_str containing search path - * @param which which list of paths to return - * @return 0 on success, <0 on failure - */ -extern int git_sysdir_get(const git_str **out, git_sysdir_t which); - -/** - * Set search paths for global/system/xdg files - * - * The first occurrence of the magic string "$PATH" in the new value will - * be replaced with the old value of the search path. - * - * @param which Which search path to modify - * @param paths New search path (separated by GIT_PATH_LIST_SEPARATOR) - * @return 0 on success, <0 on failure (allocation error) - */ -extern int git_sysdir_set(git_sysdir_t which, const char *paths); - -/** - * Reset search paths for global/system/xdg files. - */ -extern int git_sysdir_reset(void); - -#ifdef GIT_WIN32 -/** Sets the registry system dir to a mock; for testing. */ -extern int git_win32__set_registry_system_dir(const wchar_t *mock_sysdir); - -/** Find the given system dir; for testing. */ -extern int git_win32__find_system_dirs(git_str *out, const char *subdir); -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/tag.c b/vendor/libgit2-sys/libgit2/src/libgit2/tag.c deleted file mode 100644 index d12efdb..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/tag.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "tag.h" - -#include "commit.h" -#include "signature.h" -#include "wildmatch.h" -#include "git2/object.h" -#include "git2/repository.h" -#include "git2/signature.h" -#include "git2/odb_backend.h" - -void git_tag__free(void *_tag) -{ - git_tag *tag = _tag; - git_signature_free(tag->tagger); - git__free(tag->message); - git__free(tag->tag_name); - git__free(tag); -} - -int git_tag_target(git_object **target, const git_tag *t) -{ - GIT_ASSERT_ARG(t); - return git_object_lookup(target, t->object.repo, &t->target, t->type); -} - -const git_oid *git_tag_target_id(const git_tag *t) -{ - GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); - return &t->target; -} - -git_object_t git_tag_target_type(const git_tag *t) -{ - GIT_ASSERT_ARG_WITH_RETVAL(t, GIT_OBJECT_INVALID); - return t->type; -} - -const char *git_tag_name(const git_tag *t) -{ - GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); - return t->tag_name; -} - -const git_signature *git_tag_tagger(const git_tag *t) -{ - return t->tagger; -} - -const char *git_tag_message(const git_tag *t) -{ - GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); - return t->message; -} - -static int tag_error(const char *str) -{ - git_error_set(GIT_ERROR_TAG, "failed to parse tag: %s", str); - return GIT_EINVALID; -} - -static int tag_parse( - git_tag *tag, - const char *buffer, - const char *buffer_end, - git_oid_t oid_type) -{ - static const char *tag_types[] = { - NULL, "commit\n", "tree\n", "blob\n", "tag\n" - }; - size_t text_len, alloc_len; - const char *search; - unsigned int i; - int error; - - if (git_object__parse_oid_header(&tag->target, - &buffer, buffer_end, "object ", oid_type) < 0) - return tag_error("object field invalid"); - - if (buffer + 5 >= buffer_end) - return tag_error("object too short"); - - if (memcmp(buffer, "type ", 5) != 0) - return tag_error("type field not found"); - buffer += 5; - - tag->type = GIT_OBJECT_INVALID; - - for (i = 1; i < ARRAY_SIZE(tag_types); ++i) { - size_t type_length = strlen(tag_types[i]); - - if (buffer + type_length >= buffer_end) - return tag_error("object too short"); - - if (memcmp(buffer, tag_types[i], type_length) == 0) { - tag->type = i; - buffer += type_length; - break; - } - } - - if (tag->type == GIT_OBJECT_INVALID) - return tag_error("invalid object type"); - - if (buffer + 4 >= buffer_end) - return tag_error("object too short"); - - if (memcmp(buffer, "tag ", 4) != 0) - return tag_error("tag field not found"); - - buffer += 4; - - search = memchr(buffer, '\n', buffer_end - buffer); - if (search == NULL) - return tag_error("object too short"); - - text_len = search - buffer; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); - tag->tag_name = git__malloc(alloc_len); - GIT_ERROR_CHECK_ALLOC(tag->tag_name); - - memcpy(tag->tag_name, buffer, text_len); - tag->tag_name[text_len] = '\0'; - - buffer = search + 1; - - tag->tagger = NULL; - if (buffer < buffer_end && *buffer != '\n') { - tag->tagger = git__malloc(sizeof(git_signature)); - GIT_ERROR_CHECK_ALLOC(tag->tagger); - - if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ", '\n')) < 0) - return error; - } - - tag->message = NULL; - if (buffer < buffer_end) { - /* If we're not at the end of the header, search for it */ - if(*buffer != '\n') { - search = git__memmem(buffer, buffer_end - buffer, - "\n\n", 2); - if (search) - buffer = search + 1; - else - return tag_error("tag contains no message"); - } - - text_len = buffer_end - ++buffer; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); - tag->message = git__malloc(alloc_len); - GIT_ERROR_CHECK_ALLOC(tag->message); - - memcpy(tag->message, buffer, text_len); - tag->message[text_len] = '\0'; - } - - return 0; -} - -int git_tag__parse_raw( - void *_tag, - const char *data, - size_t size, - git_oid_t oid_type) -{ - return tag_parse(_tag, data, data + size, oid_type); -} - -int git_tag__parse( - void *_tag, - git_odb_object *odb_obj, - git_oid_t oid_type) -{ - git_tag *tag = _tag; - const char *buffer = git_odb_object_data(odb_obj); - const char *buffer_end = buffer + git_odb_object_size(odb_obj); - - return tag_parse(tag, buffer, buffer_end, oid_type); -} - -static int retrieve_tag_reference( - git_reference **tag_reference_out, - git_str *ref_name_out, - git_repository *repo, - const char *tag_name) -{ - git_reference *tag_ref; - int error; - - *tag_reference_out = NULL; - - if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0) - return -1; - - error = git_reference_lookup(&tag_ref, repo, ref_name_out->ptr); - if (error < 0) - return error; /* Be it not foundo or corrupted */ - - *tag_reference_out = tag_ref; - - return 0; -} - -static int retrieve_tag_reference_oid( - git_oid *oid, - git_str *ref_name_out, - git_repository *repo, - const char *tag_name) -{ - if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0) - return -1; - - return git_reference_name_to_id(oid, repo, ref_name_out->ptr); -} - -static int write_tag_annotation( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message) -{ - git_str tag = GIT_STR_INIT; - git_odb *odb; - - if (git_object__write_oid_header(&tag, "object ", git_object_id(target)) < 0) - goto on_error; - - git_str_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target))); - git_str_printf(&tag, "tag %s\n", tag_name); - git_signature__writebuf(&tag, "tagger ", tagger); - git_str_putc(&tag, '\n'); - - if (git_str_puts(&tag, message) < 0) - goto on_error; - - if (git_repository_odb__weakptr(&odb, repo) < 0) - goto on_error; - - if (git_odb_write(oid, odb, tag.ptr, tag.size, GIT_OBJECT_TAG) < 0) - goto on_error; - - git_str_dispose(&tag); - return 0; - -on_error: - git_str_dispose(&tag); - git_error_set(GIT_ERROR_OBJECT, "failed to create tag annotation"); - return -1; -} - -static bool tag_name_is_valid(const char *tag_name) -{ - /* - * Discourage tag name starting with dash, - * https://github.com/git/git/commit/4f0accd638b8d2 - * and refuse to use HEAD as a tagname, - * https://github.com/git/git/commit/bbd445d5efd415 - */ - return tag_name[0] != '-' && git__strcmp(tag_name, "HEAD"); -} - -static int git_tag_create__internal( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message, - int allow_ref_overwrite, - int create_tag_annotation) -{ - git_reference *new_ref = NULL; - git_str ref_name = GIT_STR_INIT; - - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(tag_name); - GIT_ASSERT_ARG(target); - GIT_ASSERT_ARG(!create_tag_annotation || (tagger && message)); - - if (git_object_owner(target) != repo) { - git_error_set(GIT_ERROR_INVALID, "the given target does not belong to this repository"); - return -1; - } - - if (!tag_name_is_valid(tag_name)) { - git_error_set(GIT_ERROR_TAG, "'%s' is not a valid tag name", tag_name); - return -1; - } - - error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag_name); - if (error < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - /** Ensure the tag name doesn't conflict with an already existing - * reference unless overwriting has explicitly been requested **/ - if (error == 0 && !allow_ref_overwrite) { - git_str_dispose(&ref_name); - git_error_set(GIT_ERROR_TAG, "tag already exists"); - return GIT_EEXISTS; - } - - if (create_tag_annotation) { - if (write_tag_annotation(oid, repo, tag_name, target, tagger, message) < 0) { - git_str_dispose(&ref_name); - return -1; - } - } else - git_oid_cpy(oid, git_object_id(target)); - - error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL); - -cleanup: - git_reference_free(new_ref); - git_str_dispose(&ref_name); - return error; -} - -int git_tag_create( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message, - int allow_ref_overwrite) -{ - return git_tag_create__internal(oid, repo, tag_name, target, tagger, message, allow_ref_overwrite, 1); -} - -int git_tag_annotation_create( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message) -{ - GIT_ASSERT_ARG(oid); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(tag_name); - GIT_ASSERT_ARG(target); - GIT_ASSERT_ARG(tagger); - GIT_ASSERT_ARG(message); - - return write_tag_annotation(oid, repo, tag_name, target, tagger, message); -} - -int git_tag_create_lightweight( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - int allow_ref_overwrite) -{ - return git_tag_create__internal(oid, repo, tag_name, target, NULL, NULL, allow_ref_overwrite, 0); -} - -int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *buffer, int allow_ref_overwrite) -{ - git_tag tag; - int error; - git_odb *odb; - git_odb_stream *stream; - git_odb_object *target_obj; - - git_reference *new_ref = NULL; - git_str ref_name = GIT_STR_INIT; - - GIT_ASSERT_ARG(oid); - GIT_ASSERT_ARG(buffer); - - memset(&tag, 0, sizeof(tag)); - - if (git_repository_odb__weakptr(&odb, repo) < 0) - return -1; - - /* validate the buffer */ - if (tag_parse(&tag, buffer, buffer + strlen(buffer), repo->oid_type) < 0) - return -1; - - /* validate the target */ - if (git_odb_read(&target_obj, odb, &tag.target) < 0) - goto on_error; - - if (tag.type != target_obj->cached.type) { - git_error_set(GIT_ERROR_TAG, "the type for the given target is invalid"); - goto on_error; - } - - error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag.tag_name); - if (error < 0 && error != GIT_ENOTFOUND) - goto on_error; - - /* We don't need these objects after this */ - git_signature_free(tag.tagger); - git__free(tag.tag_name); - git__free(tag.message); - git_odb_object_free(target_obj); - - /** Ensure the tag name doesn't conflict with an already existing - * reference unless overwriting has explicitly been requested **/ - if (error == 0 && !allow_ref_overwrite) { - git_str_dispose(&ref_name); - git_error_set(GIT_ERROR_TAG, "tag already exists"); - return GIT_EEXISTS; - } - - /* write the buffer */ - if ((error = git_odb_open_wstream( - &stream, odb, strlen(buffer), GIT_OBJECT_TAG)) < 0) { - git_str_dispose(&ref_name); - return error; - } - - if (!(error = git_odb_stream_write(stream, buffer, strlen(buffer)))) - error = git_odb_stream_finalize_write(oid, stream); - - git_odb_stream_free(stream); - - if (error < 0) { - git_str_dispose(&ref_name); - return error; - } - - error = git_reference_create( - &new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL); - - git_reference_free(new_ref); - git_str_dispose(&ref_name); - - return error; - -on_error: - git_signature_free(tag.tagger); - git__free(tag.tag_name); - git__free(tag.message); - git_odb_object_free(target_obj); - return -1; -} - -int git_tag_delete(git_repository *repo, const char *tag_name) -{ - git_reference *tag_ref; - git_str ref_name = GIT_STR_INIT; - int error; - - error = retrieve_tag_reference(&tag_ref, &ref_name, repo, tag_name); - - git_str_dispose(&ref_name); - - if (error < 0) - return error; - - error = git_reference_delete(tag_ref); - - git_reference_free(tag_ref); - - return error; -} - -typedef struct { - git_repository *repo; - git_tag_foreach_cb cb; - void *cb_data; -} tag_cb_data; - -static int tags_cb(const char *ref, void *data) -{ - int error; - git_oid oid; - tag_cb_data *d = (tag_cb_data *)data; - - if (git__prefixcmp(ref, GIT_REFS_TAGS_DIR) != 0) - return 0; /* no tag */ - - if (!(error = git_reference_name_to_id(&oid, d->repo, ref))) { - if ((error = d->cb(ref, &oid, d->cb_data)) != 0) - git_error_set_after_callback_function(error, "git_tag_foreach"); - } - - return error; -} - -int git_tag_foreach(git_repository *repo, git_tag_foreach_cb cb, void *cb_data) -{ - tag_cb_data data; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(cb); - - data.cb = cb; - data.cb_data = cb_data; - data.repo = repo; - - return git_reference_foreach_name(repo, &tags_cb, &data); -} - -typedef struct { - git_vector *taglist; - const char *pattern; -} tag_filter_data; - -#define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR) - -static int tag_list_cb(const char *tag_name, git_oid *oid, void *data) -{ - tag_filter_data *filter = (tag_filter_data *)data; - GIT_UNUSED(oid); - - if (!*filter->pattern || - wildmatch(filter->pattern, tag_name + GIT_REFS_TAGS_DIR_LEN, 0) == 0) - { - char *matched = git__strdup(tag_name + GIT_REFS_TAGS_DIR_LEN); - GIT_ERROR_CHECK_ALLOC(matched); - - return git_vector_insert(filter->taglist, matched); - } - - return 0; -} - -int git_tag_list_match(git_strarray *tag_names, const char *pattern, git_repository *repo) -{ - int error; - tag_filter_data filter; - git_vector taglist; - - GIT_ASSERT_ARG(tag_names); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(pattern); - - if ((error = git_vector_init(&taglist, 8, NULL)) < 0) - return error; - - filter.taglist = &taglist; - filter.pattern = pattern; - - error = git_tag_foreach(repo, &tag_list_cb, (void *)&filter); - - if (error < 0) - git_vector_dispose(&taglist); - - tag_names->strings = - (char **)git_vector_detach(&tag_names->count, NULL, &taglist); - - return 0; -} - -int git_tag_list(git_strarray *tag_names, git_repository *repo) -{ - return git_tag_list_match(tag_names, "", repo); -} - -int git_tag_peel(git_object **tag_target, const git_tag *tag) -{ - return git_object_peel(tag_target, (const git_object *)tag, GIT_OBJECT_ANY); -} - -int git_tag_name_is_valid(int *valid, const char *name) -{ - git_str ref_name = GIT_STR_INIT; - int error = 0; - - GIT_ASSERT(valid); - - *valid = 0; - - if (!name || !tag_name_is_valid(name)) - goto done; - - if ((error = git_str_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 || - (error = git_str_puts(&ref_name, name)) < 0) - goto done; - - error = git_reference_name_is_valid(valid, ref_name.ptr); - -done: - git_str_dispose(&ref_name); - return error; -} - -/* Deprecated Functions */ - -#ifndef GIT_DEPRECATE_HARD -int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *buffer, int allow_ref_overwrite) -{ - return git_tag_create_from_buffer(oid, repo, buffer, allow_ref_overwrite); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/tag.h b/vendor/libgit2-sys/libgit2/src/libgit2/tag.h deleted file mode 100644 index fdaaa46..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/tag.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_tag_h__ -#define INCLUDE_tag_h__ - -#include "common.h" - -#include "git2/tag.h" -#include "repository.h" -#include "odb.h" - -struct git_tag { - git_object object; - - git_oid target; - git_object_t type; - - char *tag_name; - git_signature *tagger; - char *message; -}; - -void git_tag__free(void *tag); -int git_tag__parse(void *tag, git_odb_object *obj, git_oid_t oid_type); -int git_tag__parse_raw(void *tag, const char *data, size_t size, git_oid_t oid_type); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/trace.c b/vendor/libgit2-sys/libgit2/src/libgit2/trace.c deleted file mode 100644 index b0c56c4..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/trace.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "trace.h" - -#include "str.h" -#include "runtime.h" -#include "git2/trace.h" - -struct git_trace_data git_trace__data = {0}; - -int git_trace_set(git_trace_level_t level, git_trace_cb callback) -{ - GIT_ASSERT_ARG(level == 0 || callback != NULL); - - git_trace__data.level = level; - git_trace__data.callback = callback; - GIT_MEMORY_BARRIER; - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/trace.h b/vendor/libgit2-sys/libgit2/src/libgit2/trace.h deleted file mode 100644 index 239928d..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/trace.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_trace_h__ -#define INCLUDE_trace_h__ - -#include "common.h" - -#include -#include "str.h" - -struct git_trace_data { - git_trace_level_t level; - git_trace_cb callback; -}; - -extern struct git_trace_data git_trace__data; - -GIT_INLINE(void) git_trace__write_fmt( - git_trace_level_t level, - const char *fmt, - va_list ap) -{ - git_trace_cb callback = git_trace__data.callback; - git_str message = GIT_STR_INIT; - - git_str_vprintf(&message, fmt, ap); - - callback(level, git_str_cstr(&message)); - - git_str_dispose(&message); -} - -#define git_trace_level() (git_trace__data.level) - -GIT_INLINE(void) git_trace(git_trace_level_t level, const char *fmt, ...) -{ - if (git_trace__data.level >= level && - git_trace__data.callback != NULL) { - va_list ap; - - va_start(ap, fmt); - git_trace__write_fmt(level, fmt, ap); - va_end(ap); - } -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/trailer.c b/vendor/libgit2-sys/libgit2/src/libgit2/trailer.c deleted file mode 100644 index c7579fb..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/trailer.c +++ /dev/null @@ -1,430 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#include "array.h" -#include "common.h" -#include "git2/message.h" - -#include -#include -#include - -#define COMMENT_LINE_CHAR '#' -#define TRAILER_SEPARATORS ":" - -static const char *const git_generated_prefixes[] = { - "Signed-off-by: ", - "(cherry picked from commit ", - NULL -}; - -static int is_blank_line(const char *str) -{ - const char *s = str; - while (*s && *s != '\n' && git__isspace(*s)) - s++; - return !*s || *s == '\n'; -} - -static const char *next_line(const char *str) -{ - const char *nl = strchr(str, '\n'); - - if (nl) { - return nl + 1; - } else { - /* return pointer to the NUL terminator: */ - return str + strlen(str); - } -} - -/* - * Return the position of the start of the last line. If len is 0, return 0. - */ -static bool last_line(size_t *out, const char *buf, size_t len) -{ - size_t i; - - *out = 0; - - if (len == 0) - return false; - if (len == 1) - return true; - - /* - * Skip the last character (in addition to the null terminator), - * because if the last character is a newline, it is considered as part - * of the last line anyway. - */ - i = len - 2; - - for (; i > 0; i--) { - if (buf[i] == '\n') { - *out = i + 1; - return true; - } - } - return true; -} - -/* - * If the given line is of the form - * "..." or "...", sets out - * to the location of the separator and returns true. Otherwise, returns - * false. The optional whitespace is allowed there primarily to allow things - * like "Bug #43" where is "Bug" and is "#". - * - * The separator-starts-line case (in which this function returns true and - * sets out to 0) is distinguished from the non-well-formed-line case (in - * which this function returns false) because some callers of this function - * need such a distinction. - */ -static bool find_separator(size_t *out, const char *line, const char *separators) -{ - int whitespace_found = 0; - const char *c; - for (c = line; *c; c++) { - if (strchr(separators, *c)) { - *out = c - line; - return true; - } - - if (!whitespace_found && (git__isalnum(*c) || *c == '-')) - continue; - if (c != line && (*c == ' ' || *c == '\t')) { - whitespace_found = 1; - continue; - } - break; - } - return false; -} - -/* - * Inspect the given string and determine the true "end" of the log message, in - * order to find where to put a new Signed-off-by: line. Ignored are - * trailing comment lines and blank lines. To support "git commit -s - * --amend" on an existing commit, we also ignore "Conflicts:". To - * support "git commit -v", we truncate at cut lines. - * - * Returns the number of bytes from the tail to ignore, to be fed as - * the second parameter to append_signoff(). - */ -static size_t ignore_non_trailer(const char *buf, size_t len) -{ - size_t boc = 0, bol = 0; - int in_old_conflicts_block = 0; - size_t cutoff = len; - - while (bol < cutoff) { - const char *next_line = memchr(buf + bol, '\n', len - bol); - - if (!next_line) - next_line = buf + len; - else - next_line++; - - if (buf[bol] == COMMENT_LINE_CHAR || buf[bol] == '\n') { - /* is this the first of the run of comments? */ - if (!boc) - boc = bol; - /* otherwise, it is just continuing */ - } else if (git__prefixcmp(buf + bol, "Conflicts:\n") == 0) { - in_old_conflicts_block = 1; - if (!boc) - boc = bol; - } else if (in_old_conflicts_block && buf[bol] == '\t') { - ; /* a pathname in the conflicts block */ - } else if (boc) { - /* the previous was not trailing comment */ - boc = 0; - in_old_conflicts_block = 0; - } - bol = next_line - buf; - } - return boc ? len - boc : len - cutoff; -} - -/* - * Return the position of the start of the patch or the length of str if there - * is no patch in the message. - */ -static size_t find_patch_start(const char *str) -{ - const char *s; - - for (s = str; *s; s = next_line(s)) { - if (git__prefixcmp(s, "---") == 0 && git__isspace(s[3])) - return s - str; - } - - return s - str; -} - -/* - * Return the position of the first trailer line or len if there are no - * trailers. - */ -static size_t find_trailer_start(const char *buf, size_t len) -{ - const char *s; - size_t end_of_title, l; - int only_spaces = 1; - int recognized_prefix = 0, trailer_lines = 0, non_trailer_lines = 0; - /* - * Number of possible continuation lines encountered. This will be - * reset to 0 if we encounter a trailer (since those lines are to be - * considered continuations of that trailer), and added to - * non_trailer_lines if we encounter a non-trailer (since those lines - * are to be considered non-trailers). - */ - int possible_continuation_lines = 0; - - /* The first paragraph is the title and cannot be trailers */ - for (s = buf; s < buf + len; s = next_line(s)) { - if (s[0] == COMMENT_LINE_CHAR) - continue; - if (is_blank_line(s)) - break; - } - end_of_title = s - buf; - - /* - * Get the start of the trailers by looking starting from the end for a - * blank line before a set of non-blank lines that (i) are all - * trailers, or (ii) contains at least one Git-generated trailer and - * consists of at least 25% trailers. - */ - l = len; - while (last_line(&l, buf, l) && l >= end_of_title) { - const char *bol = buf + l; - const char *const *p; - size_t separator_pos = 0; - - if (bol[0] == COMMENT_LINE_CHAR) { - non_trailer_lines += possible_continuation_lines; - possible_continuation_lines = 0; - continue; - } - if (is_blank_line(bol)) { - if (only_spaces) - continue; - non_trailer_lines += possible_continuation_lines; - if (recognized_prefix && - trailer_lines * 3 >= non_trailer_lines) - return next_line(bol) - buf; - else if (trailer_lines && !non_trailer_lines) - return next_line(bol) - buf; - return len; - } - only_spaces = 0; - - for (p = git_generated_prefixes; *p; p++) { - if (git__prefixcmp(bol, *p) == 0) { - trailer_lines++; - possible_continuation_lines = 0; - recognized_prefix = 1; - goto continue_outer_loop; - } - } - - find_separator(&separator_pos, bol, TRAILER_SEPARATORS); - if (separator_pos >= 1 && !git__isspace(bol[0])) { - trailer_lines++; - possible_continuation_lines = 0; - if (recognized_prefix) - continue; - } else if (git__isspace(bol[0])) - possible_continuation_lines++; - else { - non_trailer_lines++; - non_trailer_lines += possible_continuation_lines; - possible_continuation_lines = 0; - } -continue_outer_loop: - ; - } - - return len; -} - -/* Return the position of the end of the trailers. */ -static size_t find_trailer_end(const char *buf, size_t len) -{ - return len - ignore_non_trailer(buf, len); -} - -static char *extract_trailer_block(const char *message, size_t *len) -{ - size_t patch_start = find_patch_start(message); - size_t trailer_end = find_trailer_end(message, patch_start); - size_t trailer_start = find_trailer_start(message, trailer_end); - - size_t trailer_len = trailer_end - trailer_start; - - char *buffer = git__malloc(trailer_len + 1); - if (buffer == NULL) - return NULL; - - memcpy(buffer, message + trailer_start, trailer_len); - buffer[trailer_len] = 0; - - *len = trailer_len; - - return buffer; -} - -enum trailer_state { - S_START = 0, - S_KEY = 1, - S_KEY_WS = 2, - S_SEP_WS = 3, - S_VALUE = 4, - S_VALUE_NL = 5, - S_VALUE_END = 6, - S_IGNORE = 7 -}; - -#define NEXT(st) { state = (st); ptr++; continue; } -#define GOTO(st) { state = (st); continue; } - -typedef git_array_t(git_message_trailer) git_array_trailer_t; - -int git_message_trailers(git_message_trailer_array *trailer_arr, const char *message) -{ - enum trailer_state state = S_START; - int rc = 0; - char *ptr; - char *key = NULL; - char *value = NULL; - git_array_trailer_t arr = GIT_ARRAY_INIT; - - size_t trailer_len; - char *trailer = extract_trailer_block(message, &trailer_len); - if (trailer == NULL) - return -1; - - for (ptr = trailer;;) { - switch (state) { - case S_START: { - if (*ptr == 0) { - goto ret; - } - - key = ptr; - GOTO(S_KEY); - } - case S_KEY: { - if (*ptr == 0) { - goto ret; - } - - if (git__isalnum(*ptr) || *ptr == '-') { - /* legal key character */ - NEXT(S_KEY); - } - - if (*ptr == ' ' || *ptr == '\t') { - /* optional whitespace before separator */ - *ptr = 0; - NEXT(S_KEY_WS); - } - - if (strchr(TRAILER_SEPARATORS, *ptr)) { - *ptr = 0; - NEXT(S_SEP_WS); - } - - /* illegal character */ - GOTO(S_IGNORE); - } - case S_KEY_WS: { - if (*ptr == 0) { - goto ret; - } - - if (*ptr == ' ' || *ptr == '\t') { - NEXT(S_KEY_WS); - } - - if (strchr(TRAILER_SEPARATORS, *ptr)) { - NEXT(S_SEP_WS); - } - - /* illegal character */ - GOTO(S_IGNORE); - } - case S_SEP_WS: { - if (*ptr == 0) { - goto ret; - } - - if (*ptr == ' ' || *ptr == '\t') { - NEXT(S_SEP_WS); - } - - value = ptr; - NEXT(S_VALUE); - } - case S_VALUE: { - if (*ptr == 0) { - GOTO(S_VALUE_END); - } - - if (*ptr == '\n') { - NEXT(S_VALUE_NL); - } - - NEXT(S_VALUE); - } - case S_VALUE_NL: { - if (*ptr == ' ') { - /* continuation; */ - NEXT(S_VALUE); - } - - ptr[-1] = 0; - GOTO(S_VALUE_END); - } - case S_VALUE_END: { - git_message_trailer *t = git_array_alloc(arr); - - t->key = key; - t->value = value; - - key = NULL; - value = NULL; - - GOTO(S_START); - } - case S_IGNORE: { - if (*ptr == 0) { - goto ret; - } - - if (*ptr == '\n') { - NEXT(S_START); - } - - NEXT(S_IGNORE); - } - } - } - -ret: - trailer_arr->_trailer_block = trailer; - trailer_arr->trailers = arr.ptr; - trailer_arr->count = arr.size; - - return rc; -} - -void git_message_trailer_array_free(git_message_trailer_array *arr) -{ - git__free(arr->_trailer_block); - git__free(arr->trailers); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transaction.c b/vendor/libgit2-sys/libgit2/src/libgit2/transaction.c deleted file mode 100644 index 1965498..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transaction.c +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "transaction.h" - -#include "repository.h" -#include "refdb.h" -#include "pool.h" -#include "reflog.h" -#include "signature.h" -#include "config.h" - -#include "git2/transaction.h" -#include "git2/signature.h" -#include "git2/sys/refs.h" -#include "git2/sys/refdb_backend.h" - -typedef enum { - TRANSACTION_NONE, - TRANSACTION_REFS, - TRANSACTION_CONFIG -} transaction_t; - -typedef struct { - const char *name; - void *payload; - - git_reference_t ref_type; - union { - git_oid id; - char *symbolic; - } target; - git_reflog *reflog; - - const char *message; - git_signature *sig; - - unsigned int committed :1, - remove :1; -} transaction_node; - -GIT_HASHMAP_STR_SETUP(git_transaction_nodemap, transaction_node *); - -struct git_transaction { - transaction_t type; - git_repository *repo; - git_refdb *db; - git_config *cfg; - void *cfg_data; - - git_transaction_nodemap locks; - git_pool pool; -}; - -int git_transaction_config_new( - git_transaction **out, - git_config *cfg, - void *data) -{ - git_transaction *tx; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(cfg); - - tx = git__calloc(1, sizeof(git_transaction)); - GIT_ERROR_CHECK_ALLOC(tx); - - tx->type = TRANSACTION_CONFIG; - tx->cfg = cfg; - tx->cfg_data = data; - - *out = tx; - return 0; -} - -int git_transaction_new(git_transaction **out, git_repository *repo) -{ - int error; - git_pool pool; - git_transaction *tx = NULL; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - - if ((error = git_pool_init(&pool, 1)) < 0) - goto on_error; - - tx = git_pool_mallocz(&pool, sizeof(git_transaction)); - if (!tx) { - error = -1; - goto on_error; - } - - if ((error = git_repository_refdb(&tx->db, repo)) < 0) - goto on_error; - - tx->type = TRANSACTION_REFS; - memcpy(&tx->pool, &pool, sizeof(git_pool)); - tx->repo = repo; - *out = tx; - return 0; - -on_error: - git_pool_clear(&pool); - return error; -} - -int git_transaction_lock_ref(git_transaction *tx, const char *refname) -{ - int error; - transaction_node *node; - - GIT_ASSERT_ARG(tx); - GIT_ASSERT_ARG(refname); - - node = git_pool_mallocz(&tx->pool, sizeof(transaction_node)); - GIT_ERROR_CHECK_ALLOC(node); - - node->name = git_pool_strdup(&tx->pool, refname); - GIT_ERROR_CHECK_ALLOC(node->name); - - if ((error = git_refdb_lock(&node->payload, tx->db, refname)) < 0) - return error; - - if ((error = git_transaction_nodemap_put(&tx->locks, node->name, node)) < 0) - goto cleanup; - - return 0; - -cleanup: - git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL); - - return error; -} - -static int find_locked(transaction_node **out, git_transaction *tx, const char *refname) -{ - transaction_node *node; - int error; - - error = git_transaction_nodemap_get(&node, &tx->locks, refname); - - if (error != 0) { - git_error_set(GIT_ERROR_REFERENCE, "the specified reference is not locked"); - return GIT_ENOTFOUND; - } - - *out = node; - return 0; -} - -static int copy_common(transaction_node *node, git_transaction *tx, const git_signature *sig, const char *msg) -{ - if (sig && git_signature__pdup(&node->sig, sig, &tx->pool) < 0) - return -1; - - if (!node->sig) { - git_signature *tmp; - int error; - - if (git_reference__log_signature(&tmp, tx->repo) < 0) - return -1; - - /* make sure the sig we use is in our pool */ - error = git_signature__pdup(&node->sig, tmp, &tx->pool); - git_signature_free(tmp); - if (error < 0) - return error; - } - - if (msg) { - node->message = git_pool_strdup(&tx->pool, msg); - GIT_ERROR_CHECK_ALLOC(node->message); - } - - return 0; -} - -int git_transaction_set_target(git_transaction *tx, const char *refname, const git_oid *target, const git_signature *sig, const char *msg) -{ - int error; - transaction_node *node; - - GIT_ASSERT_ARG(tx); - GIT_ASSERT_ARG(refname); - GIT_ASSERT_ARG(target); - - if ((error = find_locked(&node, tx, refname)) < 0) - return error; - - if ((error = copy_common(node, tx, sig, msg)) < 0) - return error; - - git_oid_cpy(&node->target.id, target); - node->ref_type = GIT_REFERENCE_DIRECT; - - return 0; -} - -int git_transaction_set_symbolic_target(git_transaction *tx, const char *refname, const char *target, const git_signature *sig, const char *msg) -{ - int error; - transaction_node *node; - - GIT_ASSERT_ARG(tx); - GIT_ASSERT_ARG(refname); - GIT_ASSERT_ARG(target); - - if ((error = find_locked(&node, tx, refname)) < 0) - return error; - - if ((error = copy_common(node, tx, sig, msg)) < 0) - return error; - - node->target.symbolic = git_pool_strdup(&tx->pool, target); - GIT_ERROR_CHECK_ALLOC(node->target.symbolic); - node->ref_type = GIT_REFERENCE_SYMBOLIC; - - return 0; -} - -int git_transaction_remove(git_transaction *tx, const char *refname) -{ - int error; - transaction_node *node; - - if ((error = find_locked(&node, tx, refname)) < 0) - return error; - - node->remove = true; - node->ref_type = GIT_REFERENCE_DIRECT; /* the id will be ignored */ - - return 0; -} - -static int dup_reflog(git_reflog **out, const git_reflog *in, git_pool *pool) -{ - git_reflog *reflog; - git_reflog_entry *entries; - size_t len, i; - - reflog = git_pool_mallocz(pool, sizeof(git_reflog)); - GIT_ERROR_CHECK_ALLOC(reflog); - - reflog->ref_name = git_pool_strdup(pool, in->ref_name); - GIT_ERROR_CHECK_ALLOC(reflog->ref_name); - - len = in->entries.length; - reflog->entries.length = len; - reflog->entries.contents = git_pool_mallocz(pool, len * sizeof(void *)); - GIT_ERROR_CHECK_ALLOC(reflog->entries.contents); - - entries = git_pool_mallocz(pool, len * sizeof(git_reflog_entry)); - GIT_ERROR_CHECK_ALLOC(entries); - - for (i = 0; i < len; i++) { - const git_reflog_entry *src; - git_reflog_entry *tgt; - - tgt = &entries[i]; - reflog->entries.contents[i] = tgt; - - src = git_vector_get(&in->entries, i); - git_oid_cpy(&tgt->oid_old, &src->oid_old); - git_oid_cpy(&tgt->oid_cur, &src->oid_cur); - - tgt->msg = git_pool_strdup(pool, src->msg); - GIT_ERROR_CHECK_ALLOC(tgt->msg); - - if (git_signature__pdup(&tgt->committer, src->committer, pool) < 0) - return -1; - } - - - *out = reflog; - return 0; -} - -int git_transaction_set_reflog(git_transaction *tx, const char *refname, const git_reflog *reflog) -{ - int error; - transaction_node *node; - - GIT_ASSERT_ARG(tx); - GIT_ASSERT_ARG(refname); - GIT_ASSERT_ARG(reflog); - - if ((error = find_locked(&node, tx, refname)) < 0) - return error; - - if ((error = dup_reflog(&node->reflog, reflog, &tx->pool)) < 0) - return error; - - return 0; -} - -static int update_target(git_refdb *db, transaction_node *node) -{ - git_reference *ref; - int error, update_reflog; - - if (node->ref_type == GIT_REFERENCE_DIRECT) { - ref = git_reference__alloc(node->name, &node->target.id, NULL); - } else if (node->ref_type == GIT_REFERENCE_SYMBOLIC) { - ref = git_reference__alloc_symbolic(node->name, node->target.symbolic); - } else { - abort(); - } - - GIT_ERROR_CHECK_ALLOC(ref); - update_reflog = node->reflog == NULL; - - if (node->remove) { - error = git_refdb_unlock(db, node->payload, 2, false, ref, NULL, NULL); - } else if (node->ref_type == GIT_REFERENCE_DIRECT) { - error = git_refdb_unlock(db, node->payload, true, update_reflog, ref, node->sig, node->message); - } else if (node->ref_type == GIT_REFERENCE_SYMBOLIC) { - error = git_refdb_unlock(db, node->payload, true, update_reflog, ref, node->sig, node->message); - } else { - abort(); - } - - git_reference_free(ref); - node->committed = true; - - return error; -} - -int git_transaction_commit(git_transaction *tx) -{ - transaction_node *node; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - int error = 0; - - GIT_ASSERT_ARG(tx); - - if (tx->type == TRANSACTION_CONFIG) { - error = git_config_unlock(tx->cfg, tx->cfg_data, true); - tx->cfg = NULL; - tx->cfg_data = NULL; - - return error; - } - - while (git_transaction_nodemap_iterate(&iter, NULL, &node, &tx->locks) == 0) { - if (node->reflog) { - if ((error = tx->db->backend->reflog_write(tx->db->backend, node->reflog)) < 0) - return error; - } - - if (node->ref_type == GIT_REFERENCE_INVALID) { - /* ref was locked but not modified */ - if ((error = git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL)) < 0) { - return error; - } - node->committed = true; - } else { - if ((error = update_target(tx->db, node)) < 0) - return error; - } - } - - return 0; -} - -void git_transaction_free(git_transaction *tx) -{ - transaction_node *node; - git_pool pool; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - if (!tx) - return; - - if (tx->type == TRANSACTION_CONFIG) { - if (tx->cfg) - git_config_unlock(tx->cfg, tx->cfg_data, false); - - git__free(tx); - return; - } - - /* start by unlocking the ones we've left hanging, if any */ - while (git_transaction_nodemap_iterate(&iter, NULL, &node, &tx->locks) == 0) { - if (node->committed) - continue; - - git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL); - } - - git_refdb_free(tx->db); - git_transaction_nodemap_dispose(&tx->locks); - - /* tx is inside the pool, so we need to extract the data */ - memcpy(&pool, &tx->pool, sizeof(git_pool)); - git_pool_clear(&pool); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transaction.h b/vendor/libgit2-sys/libgit2/src/libgit2/transaction.h deleted file mode 100644 index cb26017..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transaction.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_transaction_h__ -#define INCLUDE_transaction_h__ - -#include "common.h" - -int git_transaction_config_new( - git_transaction **out, - git_config *cfg, - void *data); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transport.c b/vendor/libgit2-sys/libgit2/src/libgit2/transport.c deleted file mode 100644 index c31fca3..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transport.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/types.h" -#include "git2/remote.h" -#include "git2/net.h" -#include "git2/transport.h" -#include "git2/sys/transport.h" -#include "fs_path.h" - -typedef struct transport_definition { - char *prefix; - git_transport_cb fn; - void *param; -} transport_definition; - -static git_smart_subtransport_definition http_subtransport_definition = { git_smart_subtransport_http, 1, NULL }; -static git_smart_subtransport_definition git_subtransport_definition = { git_smart_subtransport_git, 0, NULL }; - -#ifdef GIT_SSH -static git_smart_subtransport_definition ssh_subtransport_definition = { git_smart_subtransport_ssh, 0, NULL }; -#endif - -static transport_definition local_transport_definition = { "file://", git_transport_local, NULL }; - -static transport_definition transports[] = { - { "git://", git_transport_smart, &git_subtransport_definition }, - { "http://", git_transport_smart, &http_subtransport_definition }, - { "https://", git_transport_smart, &http_subtransport_definition }, - { "file://", git_transport_local, NULL }, - -#ifdef GIT_SSH - { "ssh://", git_transport_smart, &ssh_subtransport_definition }, - { "ssh+git://", git_transport_smart, &ssh_subtransport_definition }, - { "git+ssh://", git_transport_smart, &ssh_subtransport_definition }, -#endif - - { NULL, 0, 0 } -}; - -static git_vector custom_transports = GIT_VECTOR_INIT; - -#define GIT_TRANSPORT_COUNT (sizeof(transports)/sizeof(transports[0])) - 1 - -static transport_definition * transport_find_by_url(const char *url) -{ - size_t i = 0; - transport_definition *d; - - /* Find a user transport who wants to deal with this URI */ - git_vector_foreach(&custom_transports, i, d) { - if (strncasecmp(url, d->prefix, strlen(d->prefix)) == 0) { - return d; - } - } - - /* Find a system transport for this URI */ - for (i = 0; i < GIT_TRANSPORT_COUNT; ++i) { - d = &transports[i]; - - if (strncasecmp(url, d->prefix, strlen(d->prefix)) == 0) { - return d; - } - } - - return NULL; -} - -static int transport_find_fn( - git_transport_cb *out, - const char *url, - void **param) -{ - transport_definition *definition = transport_find_by_url(url); - -#ifdef GIT_WIN32 - /* On Windows, it might not be possible to discern between absolute local - * and ssh paths - first check if this is a valid local path that points - * to a directory and if so assume local path, else assume SSH */ - - /* Check to see if the path points to a file on the local file system */ - if (!definition && git_fs_path_exists(url) && git_fs_path_isdir(url)) - definition = &local_transport_definition; -#endif - - /* For other systems, perform the SSH check first, to avoid going to the - * filesystem if it is not necessary */ - - /* It could be a SSH remote path. Check to see if there's a : */ - if (!definition && strrchr(url, ':')) { - /* re-search transports again with ssh:// as url - * so that we can find a third party ssh transport */ - definition = transport_find_by_url("ssh://"); - } - -#ifndef GIT_WIN32 - /* Check to see if the path points to a file on the local file system */ - if (!definition && git_fs_path_exists(url) && git_fs_path_isdir(url)) - definition = &local_transport_definition; -#endif - - if (!definition) - return GIT_ENOTFOUND; - - *out = definition->fn; - *param = definition->param; - - return 0; -} - -/************** - * Public API * - **************/ - -int git_transport_new(git_transport **out, git_remote *owner, const char *url) -{ - git_transport_cb fn; - git_transport *transport; - void *param; - int error; - - if ((error = transport_find_fn(&fn, url, ¶m)) == GIT_ENOTFOUND) { - git_error_set(GIT_ERROR_NET, "unsupported URL protocol"); - return -1; - } else if (error < 0) - return error; - - if ((error = fn(&transport, owner, param)) < 0) - return error; - - GIT_ERROR_CHECK_VERSION(transport, GIT_TRANSPORT_VERSION, "git_transport"); - - *out = transport; - - return 0; -} - -int git_transport_register( - const char *scheme, - git_transport_cb cb, - void *param) -{ - git_str prefix = GIT_STR_INIT; - transport_definition *d, *definition = NULL; - size_t i; - int error = 0; - - GIT_ASSERT_ARG(scheme); - GIT_ASSERT_ARG(cb); - - if ((error = git_str_printf(&prefix, "%s://", scheme)) < 0) - goto on_error; - - git_vector_foreach(&custom_transports, i, d) { - if (strcasecmp(d->prefix, prefix.ptr) == 0) { - error = GIT_EEXISTS; - goto on_error; - } - } - - definition = git__calloc(1, sizeof(transport_definition)); - GIT_ERROR_CHECK_ALLOC(definition); - - definition->prefix = git_str_detach(&prefix); - definition->fn = cb; - definition->param = param; - - if (git_vector_insert(&custom_transports, definition) < 0) - goto on_error; - - return 0; - -on_error: - git_str_dispose(&prefix); - git__free(definition); - return error; -} - -int git_transport_unregister(const char *scheme) -{ - git_str prefix = GIT_STR_INIT; - transport_definition *d; - size_t i; - int error = 0; - - GIT_ASSERT_ARG(scheme); - - if ((error = git_str_printf(&prefix, "%s://", scheme)) < 0) - goto done; - - git_vector_foreach(&custom_transports, i, d) { - if (strcasecmp(d->prefix, prefix.ptr) == 0) { - if ((error = git_vector_remove(&custom_transports, i)) < 0) - goto done; - - git__free(d->prefix); - git__free(d); - - if (!custom_transports.length) - git_vector_dispose(&custom_transports); - - error = 0; - goto done; - } - } - - error = GIT_ENOTFOUND; - -done: - git_str_dispose(&prefix); - return error; -} - -int git_transport_init(git_transport *opts, unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, version, git_transport, GIT_TRANSPORT_INIT); - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth.c deleted file mode 100644 index 90b6b12..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "auth.h" - -#include "git2/sys/credential.h" - -static int basic_next_token( - git_str *out, - git_http_auth_context *ctx, - git_credential *c) -{ - git_credential_userpass_plaintext *cred; - git_str raw = GIT_STR_INIT; - int error = GIT_EAUTH; - - GIT_UNUSED(ctx); - - if (c->credtype != GIT_CREDENTIAL_USERPASS_PLAINTEXT) { - git_error_set(GIT_ERROR_INVALID, "invalid credential type for basic auth"); - goto on_error; - } - - cred = (git_credential_userpass_plaintext *)c; - - git_str_printf(&raw, "%s:%s", cred->username, cred->password); - - if (git_str_oom(&raw) || - git_str_puts(out, "Basic ") < 0 || - git_str_encode_base64(out, git_str_cstr(&raw), raw.size) < 0) - goto on_error; - - error = 0; - -on_error: - if (raw.size) - git__memzero(raw.ptr, raw.size); - - git_str_dispose(&raw); - return error; -} - -static git_http_auth_context basic_context = { - GIT_HTTP_AUTH_BASIC, - GIT_CREDENTIAL_USERPASS_PLAINTEXT, - 0, - NULL, - basic_next_token, - NULL, - NULL -}; - -int git_http_auth_basic( - git_http_auth_context **out, const git_net_url *url) -{ - GIT_UNUSED(url); - - *out = &basic_context; - return 0; -} - -int git_http_auth_dummy( - git_http_auth_context **out, const git_net_url *url) -{ - GIT_UNUSED(url); - - *out = NULL; - return GIT_PASSTHROUGH; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth.h deleted file mode 100644 index 9f6f8fd..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_transports_auth_h__ -#define INCLUDE_transports_auth_h__ - -#include "common.h" -#include "net.h" - -typedef enum { - GIT_HTTP_AUTH_BASIC = 1, - GIT_HTTP_AUTH_NEGOTIATE = 2, - GIT_HTTP_AUTH_NTLM = 4 -} git_http_auth_t; - -typedef struct git_http_auth_context git_http_auth_context; - -struct git_http_auth_context { - /** Type of scheme */ - git_http_auth_t type; - - /** Supported credentials */ - git_credential_t credtypes; - - /** Connection affinity or request affinity */ - unsigned connection_affinity : 1; - - /** Sets the challenge on the authentication context */ - int (*set_challenge)(git_http_auth_context *ctx, const char *challenge); - - /** Gets the next authentication token from the context */ - int (*next_token)(git_str *out, git_http_auth_context *ctx, git_credential *cred); - - /** Examines if all tokens have been presented. */ - int (*is_complete)(git_http_auth_context *ctx); - - /** Frees the authentication context */ - void (*free)(git_http_auth_context *ctx); -}; - -typedef struct { - /** Type of scheme */ - git_http_auth_t type; - - /** Name of the scheme (as used in the Authorization header) */ - const char *name; - - /** Credential types this scheme supports */ - git_credential_t credtypes; - - /** Function to initialize an authentication context */ - int (*init_context)( - git_http_auth_context **out, - const git_net_url *url); -} git_http_auth_scheme; - -int git_http_auth_dummy( - git_http_auth_context **out, - const git_net_url *url); - -int git_http_auth_basic( - git_http_auth_context **out, - const git_net_url *url); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_gssapi.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_gssapi.c deleted file mode 100644 index 5005538..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_gssapi.c +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "auth_negotiate.h" - -#if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK) - -#include "git2.h" -#include "auth.h" -#include "git2/sys/credential.h" - -#ifdef GIT_GSSFRAMEWORK -#import -#elif defined(GIT_GSSAPI) -#include -#include -#endif - -static gss_OID_desc gssapi_oid_spnego = - { 6, (void *) "\x2b\x06\x01\x05\x05\x02" }; -static gss_OID_desc gssapi_oid_krb5 = - { 9, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" }; - -static gss_OID gssapi_oids[] = - { &gssapi_oid_spnego, &gssapi_oid_krb5, NULL }; - -typedef struct { - git_http_auth_context parent; - unsigned configured : 1, - complete : 1; - git_str target; - char *challenge; - gss_ctx_id_t gss_context; - gss_OID oid; -} http_auth_gssapi_context; - -static void gssapi_err_set( - OM_uint32 status_major, - OM_uint32 status_minor, - const char *message) -{ - gss_buffer_desc buffer = GSS_C_EMPTY_BUFFER; - OM_uint32 status_display, context = 0; - - if (gss_display_status(&status_display, status_major, GSS_C_GSS_CODE, - GSS_C_NO_OID, &context, &buffer) == GSS_S_COMPLETE) { - git_error_set(GIT_ERROR_NET, "%s: %.*s (%d.%d)", - message, (int)buffer.length, (const char *)buffer.value, - status_major, status_minor); - gss_release_buffer(&status_minor, &buffer); - } else { - git_error_set(GIT_ERROR_NET, "%s: unknown negotiate error (%d.%d)", - message, status_major, status_minor); - } -} - -static int gssapi_set_challenge( - git_http_auth_context *c, - const char *challenge) -{ - http_auth_gssapi_context *ctx = (http_auth_gssapi_context *)c; - - GIT_ASSERT_ARG(ctx); - GIT_ASSERT_ARG(challenge); - GIT_ASSERT(ctx->configured); - - git__free(ctx->challenge); - - ctx->challenge = git__strdup(challenge); - GIT_ERROR_CHECK_ALLOC(ctx->challenge); - - return 0; -} - -static void gssapi_context_dispose(http_auth_gssapi_context *ctx) -{ - OM_uint32 status_minor; - - if (ctx->gss_context != GSS_C_NO_CONTEXT) { - gss_delete_sec_context( - &status_minor, &ctx->gss_context, GSS_C_NO_BUFFER); - ctx->gss_context = GSS_C_NO_CONTEXT; - } - - git_str_dispose(&ctx->target); - - git__free(ctx->challenge); - ctx->challenge = NULL; -} - -static int gssapi_next_token( - git_str *buf, - git_http_auth_context *c, - git_credential *cred) -{ - http_auth_gssapi_context *ctx = (http_auth_gssapi_context *)c; - OM_uint32 status_major, status_minor; - gss_buffer_desc target_buffer = GSS_C_EMPTY_BUFFER, - input_token = GSS_C_EMPTY_BUFFER, - output_token = GSS_C_EMPTY_BUFFER; - gss_buffer_t input_token_ptr = GSS_C_NO_BUFFER; - git_str input_buf = GIT_STR_INIT; - gss_name_t server = NULL; - gss_OID mech; - size_t challenge_len; - int error = 0; - - GIT_ASSERT_ARG(buf); - GIT_ASSERT_ARG(ctx); - GIT_ASSERT_ARG(cred); - - GIT_ASSERT(ctx->configured); - GIT_ASSERT(cred->credtype == GIT_CREDENTIAL_DEFAULT); - - if (ctx->complete) - return 0; - - target_buffer.value = (void *)ctx->target.ptr; - target_buffer.length = ctx->target.size; - - status_major = gss_import_name(&status_minor, &target_buffer, - GSS_C_NT_HOSTBASED_SERVICE, &server); - - if (GSS_ERROR(status_major)) { - gssapi_err_set(status_major, status_minor, - "could not parse principal"); - error = -1; - goto done; - } - - challenge_len = ctx->challenge ? strlen(ctx->challenge) : 0; - - if (challenge_len < 9 || memcmp(ctx->challenge, "Negotiate", 9) != 0) { - git_error_set(GIT_ERROR_NET, "server did not request negotiate"); - error = -1; - goto done; - } - - if (challenge_len > 9) { - if (git_str_decode_base64(&input_buf, - ctx->challenge + 10, challenge_len - 10) < 0) { - git_error_set(GIT_ERROR_NET, "invalid negotiate challenge from server"); - error = -1; - goto done; - } - - input_token.value = input_buf.ptr; - input_token.length = input_buf.size; - input_token_ptr = &input_token; - } else if (ctx->gss_context != GSS_C_NO_CONTEXT) { - gssapi_context_dispose(ctx); - } - - mech = &gssapi_oid_spnego; - - status_major = gss_init_sec_context( - &status_minor, - GSS_C_NO_CREDENTIAL, - &ctx->gss_context, - server, - mech, - GSS_C_DELEG_FLAG | GSS_C_MUTUAL_FLAG, - GSS_C_INDEFINITE, - GSS_C_NO_CHANNEL_BINDINGS, - input_token_ptr, - NULL, - &output_token, - NULL, - NULL); - - if (GSS_ERROR(status_major)) { - gssapi_err_set(status_major, status_minor, "negotiate failure"); - error = -1; - goto done; - } - - /* This message merely told us auth was complete; we do not respond. */ - if (status_major == GSS_S_COMPLETE) { - gssapi_context_dispose(ctx); - ctx->complete = 1; - goto done; - } - - if (output_token.length == 0) { - git_error_set(GIT_ERROR_NET, "GSSAPI did not return token"); - error = -1; - goto done; - } - - git_str_puts(buf, "Negotiate "); - git_str_encode_base64(buf, output_token.value, output_token.length); - - if (git_str_oom(buf)) - error = -1; - -done: - gss_release_name(&status_minor, &server); - gss_release_buffer(&status_minor, (gss_buffer_t) &output_token); - git_str_dispose(&input_buf); - return error; -} - -static int gssapi_is_complete(git_http_auth_context *c) -{ - http_auth_gssapi_context *ctx = (http_auth_gssapi_context *)c; - - GIT_ASSERT_ARG(ctx); - - return (ctx->complete == 1); -} - -static void gssapi_context_free(git_http_auth_context *c) -{ - http_auth_gssapi_context *ctx = (http_auth_gssapi_context *)c; - - gssapi_context_dispose(ctx); - - ctx->configured = 0; - ctx->complete = 0; - ctx->oid = NULL; - - git__free(ctx); -} - -static int gssapi_init_context( - http_auth_gssapi_context *ctx, - const git_net_url *url) -{ - OM_uint32 status_major, status_minor; - gss_OID item, *oid; - gss_OID_set mechanism_list; - size_t i; - - /* Query supported mechanisms looking for SPNEGO) */ - status_major = gss_indicate_mechs(&status_minor, &mechanism_list); - - if (GSS_ERROR(status_major)) { - gssapi_err_set(status_major, status_minor, - "could not query mechanisms"); - return -1; - } - - if (mechanism_list) { - for (oid = gssapi_oids; *oid; oid++) { - for (i = 0; i < mechanism_list->count; i++) { - item = &mechanism_list->elements[i]; - - if (item->length == (*oid)->length && - memcmp(item->elements, (*oid)->elements, item->length) == 0) { - ctx->oid = *oid; - break; - } - - } - - if (ctx->oid) - break; - } - } - - gss_release_oid_set(&status_minor, &mechanism_list); - - if (!ctx->oid) { - git_error_set(GIT_ERROR_NET, "negotiate authentication is not supported"); - return GIT_EAUTH; - } - - git_str_puts(&ctx->target, "HTTP@"); - git_str_puts(&ctx->target, url->host); - - if (git_str_oom(&ctx->target)) - return -1; - - ctx->gss_context = GSS_C_NO_CONTEXT; - ctx->configured = 1; - - return 0; -} - -int git_http_auth_negotiate( - git_http_auth_context **out, - const git_net_url *url) -{ - http_auth_gssapi_context *ctx; - - *out = NULL; - - ctx = git__calloc(1, sizeof(http_auth_gssapi_context)); - GIT_ERROR_CHECK_ALLOC(ctx); - - if (gssapi_init_context(ctx, url) < 0) { - git__free(ctx); - return -1; - } - - ctx->parent.type = GIT_HTTP_AUTH_NEGOTIATE; - ctx->parent.credtypes = GIT_CREDENTIAL_DEFAULT; - ctx->parent.connection_affinity = 1; - ctx->parent.set_challenge = gssapi_set_challenge; - ctx->parent.next_token = gssapi_next_token; - ctx->parent.is_complete = gssapi_is_complete; - ctx->parent.free = gssapi_context_free; - - *out = (git_http_auth_context *)ctx; - - return 0; -} - -#endif /* GIT_GSSAPI */ - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_negotiate.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_negotiate.h deleted file mode 100644 index 4360785..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_negotiate.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_transports_auth_negotiate_h__ -#define INCLUDE_transports_auth_negotiate_h__ - -#include "common.h" -#include "git2.h" -#include "auth.h" - -#if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK) || defined(GIT_WIN32) - -extern int git_http_auth_negotiate( - git_http_auth_context **out, - const git_net_url *url); - -#else - -#define git_http_auth_negotiate git_http_auth_dummy - -#endif /* GIT_GSSAPI */ - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_ntlm.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_ntlm.h deleted file mode 100644 index 33406ae..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_ntlm.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_transports_auth_ntlm_h__ -#define INCLUDE_transports_auth_ntlm_h__ - -#include "auth.h" - -/* NTLM requires a full request/challenge/response */ -#define GIT_AUTH_STEPS_NTLM 2 - -#if defined(GIT_NTLM) || defined(GIT_WIN32) - -#if defined(GIT_OPENSSL) -# define CRYPT_OPENSSL -#elif defined(GIT_MBEDTLS) -# define CRYPT_MBEDTLS -#elif defined(GIT_SECURE_TRANSPORT) -# define CRYPT_COMMONCRYPTO -#endif - -extern int git_http_auth_ntlm( - git_http_auth_context **out, - const git_net_url *url); - -#else - -#define git_http_auth_ntlm git_http_auth_dummy - -#endif /* GIT_NTLM */ - -#endif - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_ntlmclient.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_ntlmclient.c deleted file mode 100644 index 6f26a61..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_ntlmclient.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "auth_ntlm.h" - -#include "common.h" -#include "str.h" -#include "auth.h" -#include "git2/sys/credential.h" - -#ifdef GIT_NTLM - -#include "ntlmclient.h" - -typedef struct { - git_http_auth_context parent; - ntlm_client *ntlm; - char *challenge; - bool complete; -} http_auth_ntlm_context; - -static int ntlmclient_set_challenge( - git_http_auth_context *c, - const char *challenge) -{ - http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c; - - GIT_ASSERT_ARG(ctx); - GIT_ASSERT_ARG(challenge); - - git__free(ctx->challenge); - - ctx->challenge = git__strdup(challenge); - GIT_ERROR_CHECK_ALLOC(ctx->challenge); - - return 0; -} - -static int ntlmclient_set_credentials(http_auth_ntlm_context *ctx, git_credential *_cred) -{ - git_credential_userpass_plaintext *cred; - const char *sep, *username; - char *domain = NULL, *domainuser = NULL; - int error = 0; - - GIT_ASSERT(_cred->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT); - cred = (git_credential_userpass_plaintext *)_cred; - - if ((sep = strchr(cred->username, '\\')) != NULL) { - domain = git__strndup(cred->username, (sep - cred->username)); - GIT_ERROR_CHECK_ALLOC(domain); - - domainuser = git__strdup(sep + 1); - GIT_ERROR_CHECK_ALLOC(domainuser); - - username = domainuser; - } else { - username = cred->username; - } - - if (ntlm_client_set_credentials(ctx->ntlm, - username, domain, cred->password) < 0) { - git_error_set(GIT_ERROR_NET, "could not set credentials: %s", - ntlm_client_errmsg(ctx->ntlm)); - error = -1; - goto done; - } - -done: - git__free(domain); - git__free(domainuser); - return error; -} - -static int ntlmclient_next_token( - git_str *buf, - git_http_auth_context *c, - git_credential *cred) -{ - http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c; - git_str input_buf = GIT_STR_INIT; - const unsigned char *msg; - size_t challenge_len, msg_len; - int error = GIT_EAUTH; - - GIT_ASSERT_ARG(buf); - GIT_ASSERT_ARG(ctx); - - GIT_ASSERT(ctx->ntlm); - - challenge_len = ctx->challenge ? strlen(ctx->challenge) : 0; - - if (ctx->complete) - ntlm_client_reset(ctx->ntlm); - - /* - * Set us complete now since it's the default case; the one - * incomplete case (successfully created a client request) - * will explicitly set that it requires a second step. - */ - ctx->complete = true; - - if (cred && ntlmclient_set_credentials(ctx, cred) != 0) - goto done; - - if (challenge_len < 4) { - git_error_set(GIT_ERROR_NET, "no ntlm challenge sent from server"); - goto done; - } else if (challenge_len == 4) { - if (memcmp(ctx->challenge, "NTLM", 4) != 0) { - git_error_set(GIT_ERROR_NET, "server did not request NTLM"); - goto done; - } - - if (ntlm_client_negotiate(&msg, &msg_len, ctx->ntlm) != 0) { - git_error_set(GIT_ERROR_NET, "ntlm authentication failed: %s", - ntlm_client_errmsg(ctx->ntlm)); - goto done; - } - - ctx->complete = false; - } else { - if (memcmp(ctx->challenge, "NTLM ", 5) != 0) { - git_error_set(GIT_ERROR_NET, "challenge from server was not NTLM"); - goto done; - } - - if (git_str_decode_base64(&input_buf, - ctx->challenge + 5, challenge_len - 5) < 0) { - git_error_set(GIT_ERROR_NET, "invalid NTLM challenge from server"); - goto done; - } - - if (ntlm_client_set_challenge(ctx->ntlm, - (const unsigned char *)input_buf.ptr, input_buf.size) != 0) { - git_error_set(GIT_ERROR_NET, "ntlm challenge failed: %s", - ntlm_client_errmsg(ctx->ntlm)); - goto done; - } - - if (ntlm_client_response(&msg, &msg_len, ctx->ntlm) != 0) { - git_error_set(GIT_ERROR_NET, "ntlm authentication failed: %s", - ntlm_client_errmsg(ctx->ntlm)); - goto done; - } - } - - git_str_puts(buf, "NTLM "); - git_str_encode_base64(buf, (const char *)msg, msg_len); - - if (git_str_oom(buf)) - goto done; - - error = 0; - -done: - git_str_dispose(&input_buf); - return error; -} - -static int ntlmclient_is_complete(git_http_auth_context *c) -{ - http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c; - - GIT_ASSERT_ARG(ctx); - return (ctx->complete == true); -} - -static void ntlmclient_context_free(git_http_auth_context *c) -{ - http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c; - - ntlm_client_free(ctx->ntlm); - git__free(ctx->challenge); - git__free(ctx); -} - -static int ntlmclient_init_context( - http_auth_ntlm_context *ctx, - const git_net_url *url) -{ - GIT_UNUSED(url); - - if ((ctx->ntlm = ntlm_client_init(NTLM_CLIENT_DEFAULTS)) == NULL) { - git_error_set_oom(); - return -1; - } - - return 0; -} - -int git_http_auth_ntlm( - git_http_auth_context **out, - const git_net_url *url) -{ - http_auth_ntlm_context *ctx; - - GIT_UNUSED(url); - - *out = NULL; - - ctx = git__calloc(1, sizeof(http_auth_ntlm_context)); - GIT_ERROR_CHECK_ALLOC(ctx); - - if (ntlmclient_init_context(ctx, url) < 0) { - git__free(ctx); - return -1; - } - - ctx->parent.type = GIT_HTTP_AUTH_NTLM; - ctx->parent.credtypes = GIT_CREDENTIAL_USERPASS_PLAINTEXT; - ctx->parent.connection_affinity = 1; - ctx->parent.set_challenge = ntlmclient_set_challenge; - ctx->parent.next_token = ntlmclient_next_token; - ctx->parent.is_complete = ntlmclient_is_complete; - ctx->parent.free = ntlmclient_context_free; - - *out = (git_http_auth_context *)ctx; - - return 0; -} - -#endif /* GIT_NTLM */ diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_sspi.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_sspi.c deleted file mode 100644 index 1b8fb64..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/auth_sspi.c +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "auth_ntlm.h" -#include "auth_negotiate.h" - -#ifdef GIT_WIN32 - -#define SECURITY_WIN32 - -#include "git2.h" -#include "auth.h" -#include "git2/sys/credential.h" - -#include -#include - -typedef struct { - git_http_auth_context parent; - wchar_t *target; - - const char *package_name; - size_t package_name_len; - wchar_t *package_name_w; - SecPkgInfoW *package_info; - SEC_WINNT_AUTH_IDENTITY_W identity; - CredHandle cred; - CtxtHandle context; - - int has_identity : 1, - has_credentials : 1, - has_context : 1, - complete : 1; - git_str challenge; -} http_auth_sspi_context; - -static void sspi_reset_context(http_auth_sspi_context *ctx) -{ - if (ctx->has_identity) { - git__free(ctx->identity.User); - git__free(ctx->identity.Domain); - git__free(ctx->identity.Password); - - memset(&ctx->identity, 0, sizeof(SEC_WINNT_AUTH_IDENTITY_W)); - - ctx->has_identity = 0; - } - - if (ctx->has_credentials) { - FreeCredentialsHandle(&ctx->cred); - memset(&ctx->cred, 0, sizeof(CredHandle)); - - ctx->has_credentials = 0; - } - - if (ctx->has_context) { - DeleteSecurityContext(&ctx->context); - memset(&ctx->context, 0, sizeof(CtxtHandle)); - - ctx->has_context = 0; - } - - ctx->complete = 0; - - git_str_dispose(&ctx->challenge); -} - -static int sspi_set_challenge( - git_http_auth_context *c, - const char *challenge) -{ - http_auth_sspi_context *ctx = (http_auth_sspi_context *)c; - size_t challenge_len = strlen(challenge); - - git_str_clear(&ctx->challenge); - - if (strncmp(challenge, ctx->package_name, ctx->package_name_len) != 0) { - git_error_set(GIT_ERROR_NET, "invalid %s challenge from server", ctx->package_name); - return -1; - } - - /* - * A package type indicator without a base64 payload indicates the - * mechanism; it's not an actual challenge. Ignore it. - */ - if (challenge[ctx->package_name_len] == 0) { - return 0; - } else if (challenge[ctx->package_name_len] != ' ') { - git_error_set(GIT_ERROR_NET, "invalid %s challenge from server", ctx->package_name); - return -1; - } - - if (git_str_decode_base64(&ctx->challenge, - challenge + (ctx->package_name_len + 1), - challenge_len - (ctx->package_name_len + 1)) < 0) { - git_error_set(GIT_ERROR_NET, "invalid %s challenge from server", ctx->package_name); - return -1; - } - - GIT_ASSERT(ctx->challenge.size <= ULONG_MAX); - return 0; -} - -static int create_identity( - SEC_WINNT_AUTH_IDENTITY_W **out, - http_auth_sspi_context *ctx, - git_credential *cred) -{ - git_credential_userpass_plaintext *userpass; - wchar_t *username = NULL, *domain = NULL, *password = NULL; - int username_len = 0, domain_len = 0, password_len = 0; - const char *sep; - - if (cred->credtype == GIT_CREDENTIAL_DEFAULT) { - *out = NULL; - return 0; - } - - if (cred->credtype != GIT_CREDENTIAL_USERPASS_PLAINTEXT) { - git_error_set(GIT_ERROR_NET, "unknown credential type: %d", cred->credtype); - return -1; - } - - userpass = (git_credential_userpass_plaintext *)cred; - - if ((sep = strchr(userpass->username, '\\')) != NULL) { - GIT_ASSERT(sep - userpass->username < INT_MAX); - - username_len = git_utf8_to_16_alloc(&username, sep + 1); - domain_len = git_utf8_to_16_alloc_with_len(&domain, - userpass->username, (int)(sep - userpass->username)); - } else { - username_len = git_utf8_to_16_alloc(&username, - userpass->username); - } - - password_len = git_utf8_to_16_alloc(&password, userpass->password); - - if (username_len < 0 || domain_len < 0 || password_len < 0) { - git__free(username); - git__free(domain); - git__free(password); - return -1; - } - - ctx->identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; - ctx->identity.User = username; - ctx->identity.UserLength = (unsigned long)username_len; - ctx->identity.Password = password; - ctx->identity.PasswordLength = (unsigned long)password_len; - ctx->identity.Domain = domain; - ctx->identity.DomainLength = (unsigned long)domain_len; - - ctx->has_identity = 1; - - *out = &ctx->identity; - - return 0; -} - -static int sspi_next_token( - git_str *buf, - git_http_auth_context *c, - git_credential *cred) -{ - http_auth_sspi_context *ctx = (http_auth_sspi_context *)c; - SEC_WINNT_AUTH_IDENTITY_W *identity = NULL; - TimeStamp timestamp; - DWORD context_flags; - SecBuffer input_buf = { 0, SECBUFFER_TOKEN, NULL }; - SecBuffer output_buf = { 0, SECBUFFER_TOKEN, NULL }; - SecBufferDesc input_buf_desc = { SECBUFFER_VERSION, 1, &input_buf }; - SecBufferDesc output_buf_desc = { SECBUFFER_VERSION, 1, &output_buf }; - SECURITY_STATUS status; - - if (ctx->complete) - sspi_reset_context(ctx); - - if (!ctx->has_context) { - if (create_identity(&identity, ctx, cred) < 0) - return -1; - - status = AcquireCredentialsHandleW(NULL, ctx->package_name_w, - SECPKG_CRED_BOTH, NULL, identity, NULL, - NULL, &ctx->cred, ×tamp); - - if (status != SEC_E_OK) { - git_error_set(GIT_ERROR_OS, "could not acquire credentials"); - return -1; - } - - ctx->has_credentials = 1; - } - - context_flags = ISC_REQ_ALLOCATE_MEMORY | - ISC_REQ_CONFIDENTIALITY | - ISC_REQ_MUTUAL_AUTH; - - if (ctx->challenge.size > 0) { - input_buf.BufferType = SECBUFFER_TOKEN; - input_buf.cbBuffer = (unsigned long)ctx->challenge.size; - input_buf.pvBuffer = ctx->challenge.ptr; - } - - status = InitializeSecurityContextW(&ctx->cred, - ctx->has_context ? &ctx->context : NULL, - ctx->target, - context_flags, - 0, - SECURITY_NETWORK_DREP, - ctx->has_context ? &input_buf_desc : NULL, - 0, - ctx->has_context ? NULL : &ctx->context, - &output_buf_desc, - &context_flags, - NULL); - - if (status == SEC_I_COMPLETE_AND_CONTINUE || - status == SEC_I_COMPLETE_NEEDED) - status = CompleteAuthToken(&ctx->context, &output_buf_desc); - - if (status == SEC_E_OK) { - ctx->complete = 1; - } else if (status != SEC_I_CONTINUE_NEEDED) { - git_error_set(GIT_ERROR_OS, "could not initialize security context"); - return -1; - } - - ctx->has_context = 1; - git_str_clear(&ctx->challenge); - - if (output_buf.cbBuffer > 0) { - git_str_put(buf, ctx->package_name, ctx->package_name_len); - git_str_putc(buf, ' '); - git_str_encode_base64(buf, output_buf.pvBuffer, output_buf.cbBuffer); - - FreeContextBuffer(output_buf.pvBuffer); - - if (git_str_oom(buf)) - return -1; - } - - return 0; -} - -static int sspi_is_complete(git_http_auth_context *c) -{ - http_auth_sspi_context *ctx = (http_auth_sspi_context *)c; - - return ctx->complete; -} - -static void sspi_context_free(git_http_auth_context *c) -{ - http_auth_sspi_context *ctx = (http_auth_sspi_context *)c; - - sspi_reset_context(ctx); - - FreeContextBuffer(ctx->package_info); - git__free(ctx->target); - git__free(ctx); -} - -static int sspi_init_context( - git_http_auth_context **out, - git_http_auth_t type, - const git_net_url *url) -{ - http_auth_sspi_context *ctx; - git_str target = GIT_STR_INIT; - - *out = NULL; - - ctx = git__calloc(1, sizeof(http_auth_sspi_context)); - GIT_ERROR_CHECK_ALLOC(ctx); - - switch (type) { - case GIT_HTTP_AUTH_NTLM: - ctx->package_name = "NTLM"; - ctx->package_name_len = CONST_STRLEN("NTLM"); - ctx->package_name_w = L"NTLM"; - ctx->parent.credtypes = GIT_CREDENTIAL_USERPASS_PLAINTEXT | - GIT_CREDENTIAL_DEFAULT; - break; - case GIT_HTTP_AUTH_NEGOTIATE: - ctx->package_name = "Negotiate"; - ctx->package_name_len = CONST_STRLEN("Negotiate"); - ctx->package_name_w = L"Negotiate"; - ctx->parent.credtypes = GIT_CREDENTIAL_DEFAULT; - break; - default: - git_error_set(GIT_ERROR_NET, "unknown SSPI auth type: %d", ctx->parent.type); - git__free(ctx); - return -1; - } - - if (QuerySecurityPackageInfoW(ctx->package_name_w, &ctx->package_info) != SEC_E_OK) { - git_error_set(GIT_ERROR_OS, "could not query security package"); - git__free(ctx); - return -1; - } - - if (git_str_printf(&target, "http/%s", url->host) < 0 || - git_utf8_to_16_alloc(&ctx->target, target.ptr) < 0) { - FreeContextBuffer(ctx->package_info); - git__free(ctx); - return -1; - } - - ctx->parent.type = type; - ctx->parent.connection_affinity = 1; - ctx->parent.set_challenge = sspi_set_challenge; - ctx->parent.next_token = sspi_next_token; - ctx->parent.is_complete = sspi_is_complete; - ctx->parent.free = sspi_context_free; - - *out = (git_http_auth_context *)ctx; - - git_str_dispose(&target); - return 0; -} - -#if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK) || defined(GIT_WIN32) -int git_http_auth_negotiate( - git_http_auth_context **out, - const git_net_url *url) -{ - return sspi_init_context(out, GIT_HTTP_AUTH_NEGOTIATE, url); -} -#endif - -int git_http_auth_ntlm( - git_http_auth_context **out, - const git_net_url *url) -{ - return sspi_init_context(out, GIT_HTTP_AUTH_NTLM, url); -} - -#endif /* GIT_WIN32 */ diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/credential.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/credential.c deleted file mode 100644 index 7d0eace..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/credential.c +++ /dev/null @@ -1,486 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/credential.h" -#include "git2/sys/credential.h" -#include "git2/credential_helpers.h" - -static int git_credential_ssh_key_type_new( - git_credential **cred, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase, - git_credential_t credtype); - -int git_credential_has_username(git_credential *cred) -{ - if (cred->credtype == GIT_CREDENTIAL_DEFAULT) - return 0; - - return 1; -} - -const char *git_credential_get_username(git_credential *cred) -{ - switch (cred->credtype) { - case GIT_CREDENTIAL_USERNAME: - { - git_credential_username *c = (git_credential_username *) cred; - return c->username; - } - case GIT_CREDENTIAL_USERPASS_PLAINTEXT: - { - git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *) cred; - return c->username; - } - case GIT_CREDENTIAL_SSH_KEY: - case GIT_CREDENTIAL_SSH_MEMORY: - { - git_credential_ssh_key *c = (git_credential_ssh_key *) cred; - return c->username; - } - case GIT_CREDENTIAL_SSH_CUSTOM: - { - git_credential_ssh_custom *c = (git_credential_ssh_custom *) cred; - return c->username; - } - case GIT_CREDENTIAL_SSH_INTERACTIVE: - { - git_credential_ssh_interactive *c = (git_credential_ssh_interactive *) cred; - return c->username; - } - - default: - return NULL; - } -} - -static void plaintext_free(struct git_credential *cred) -{ - git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred; - - git__free(c->username); - - /* Zero the memory which previously held the password */ - if (c->password) { - size_t pass_len = strlen(c->password); - git__memzero(c->password, pass_len); - git__free(c->password); - } - - git__free(c); -} - -int git_credential_userpass_plaintext_new( - git_credential **cred, - const char *username, - const char *password) -{ - git_credential_userpass_plaintext *c; - - GIT_ASSERT_ARG(cred); - GIT_ASSERT_ARG(username); - GIT_ASSERT_ARG(password); - - c = git__malloc(sizeof(git_credential_userpass_plaintext)); - GIT_ERROR_CHECK_ALLOC(c); - - c->parent.credtype = GIT_CREDENTIAL_USERPASS_PLAINTEXT; - c->parent.free = plaintext_free; - c->username = git__strdup(username); - - if (!c->username) { - git__free(c); - return -1; - } - - c->password = git__strdup(password); - - if (!c->password) { - git__free(c->username); - git__free(c); - return -1; - } - - *cred = &c->parent; - return 0; -} - -static void ssh_key_free(struct git_credential *cred) -{ - git_credential_ssh_key *c = - (git_credential_ssh_key *)cred; - - git__free(c->username); - - if (c->privatekey) { - /* Zero the memory which previously held the private key */ - size_t key_len = strlen(c->privatekey); - git__memzero(c->privatekey, key_len); - git__free(c->privatekey); - } - - if (c->passphrase) { - /* Zero the memory which previously held the passphrase */ - size_t pass_len = strlen(c->passphrase); - git__memzero(c->passphrase, pass_len); - git__free(c->passphrase); - } - - if (c->publickey) { - /* Zero the memory which previously held the public key */ - size_t key_len = strlen(c->publickey); - git__memzero(c->publickey, key_len); - git__free(c->publickey); - } - - git__free(c); -} - -static void ssh_interactive_free(struct git_credential *cred) -{ - git_credential_ssh_interactive *c = (git_credential_ssh_interactive *)cred; - - git__free(c->username); - - git__free(c); -} - -static void ssh_custom_free(struct git_credential *cred) -{ - git_credential_ssh_custom *c = (git_credential_ssh_custom *)cred; - - git__free(c->username); - - if (c->publickey) { - /* Zero the memory which previously held the publickey */ - size_t key_len = c->publickey_len; - git__memzero(c->publickey, key_len); - git__free(c->publickey); - } - - git__free(c); -} - -static void default_free(struct git_credential *cred) -{ - git_credential_default *c = (git_credential_default *)cred; - - git__free(c); -} - -static void username_free(struct git_credential *cred) -{ - git__free(cred); -} - -int git_credential_ssh_key_new( - git_credential **cred, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase) -{ - return git_credential_ssh_key_type_new( - cred, - username, - publickey, - privatekey, - passphrase, - GIT_CREDENTIAL_SSH_KEY); -} - -int git_credential_ssh_key_memory_new( - git_credential **cred, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase) -{ -#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS - return git_credential_ssh_key_type_new( - cred, - username, - publickey, - privatekey, - passphrase, - GIT_CREDENTIAL_SSH_MEMORY); -#else - GIT_UNUSED(cred); - GIT_UNUSED(username); - GIT_UNUSED(publickey); - GIT_UNUSED(privatekey); - GIT_UNUSED(passphrase); - - git_error_set(GIT_ERROR_INVALID, - "this version of libgit2 was not built with ssh memory credentials."); - return -1; -#endif -} - -static int git_credential_ssh_key_type_new( - git_credential **cred, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase, - git_credential_t credtype) -{ - git_credential_ssh_key *c; - - GIT_ASSERT_ARG(username); - GIT_ASSERT_ARG(cred); - GIT_ASSERT_ARG(privatekey); - - c = git__calloc(1, sizeof(git_credential_ssh_key)); - GIT_ERROR_CHECK_ALLOC(c); - - c->parent.credtype = credtype; - c->parent.free = ssh_key_free; - - c->username = git__strdup(username); - GIT_ERROR_CHECK_ALLOC(c->username); - - c->privatekey = git__strdup(privatekey); - GIT_ERROR_CHECK_ALLOC(c->privatekey); - - if (publickey) { - c->publickey = git__strdup(publickey); - GIT_ERROR_CHECK_ALLOC(c->publickey); - } - - if (passphrase) { - c->passphrase = git__strdup(passphrase); - GIT_ERROR_CHECK_ALLOC(c->passphrase); - } - - *cred = &c->parent; - return 0; -} - -int git_credential_ssh_interactive_new( - git_credential **out, - const char *username, - git_credential_ssh_interactive_cb prompt_callback, - void *payload) -{ - git_credential_ssh_interactive *c; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(username); - GIT_ASSERT_ARG(prompt_callback); - - c = git__calloc(1, sizeof(git_credential_ssh_interactive)); - GIT_ERROR_CHECK_ALLOC(c); - - c->parent.credtype = GIT_CREDENTIAL_SSH_INTERACTIVE; - c->parent.free = ssh_interactive_free; - - c->username = git__strdup(username); - GIT_ERROR_CHECK_ALLOC(c->username); - - c->prompt_callback = prompt_callback; - c->payload = payload; - - *out = &c->parent; - return 0; -} - -int git_credential_ssh_key_from_agent(git_credential **cred, const char *username) { - git_credential_ssh_key *c; - - GIT_ASSERT_ARG(username); - GIT_ASSERT_ARG(cred); - - c = git__calloc(1, sizeof(git_credential_ssh_key)); - GIT_ERROR_CHECK_ALLOC(c); - - c->parent.credtype = GIT_CREDENTIAL_SSH_KEY; - c->parent.free = ssh_key_free; - - c->username = git__strdup(username); - GIT_ERROR_CHECK_ALLOC(c->username); - - c->privatekey = NULL; - - *cred = &c->parent; - return 0; -} - -int git_credential_ssh_custom_new( - git_credential **cred, - const char *username, - const char *publickey, - size_t publickey_len, - git_credential_sign_cb sign_callback, - void *payload) -{ - git_credential_ssh_custom *c; - - GIT_ASSERT_ARG(username); - GIT_ASSERT_ARG(cred); - - c = git__calloc(1, sizeof(git_credential_ssh_custom)); - GIT_ERROR_CHECK_ALLOC(c); - - c->parent.credtype = GIT_CREDENTIAL_SSH_CUSTOM; - c->parent.free = ssh_custom_free; - - c->username = git__strdup(username); - GIT_ERROR_CHECK_ALLOC(c->username); - - if (publickey_len > 0) { - c->publickey = git__malloc(publickey_len); - GIT_ERROR_CHECK_ALLOC(c->publickey); - - memcpy(c->publickey, publickey, publickey_len); - } - - c->publickey_len = publickey_len; - c->sign_callback = sign_callback; - c->payload = payload; - - *cred = &c->parent; - return 0; -} - -int git_credential_default_new(git_credential **cred) -{ - git_credential_default *c; - - GIT_ASSERT_ARG(cred); - - c = git__calloc(1, sizeof(git_credential_default)); - GIT_ERROR_CHECK_ALLOC(c); - - c->credtype = GIT_CREDENTIAL_DEFAULT; - c->free = default_free; - - *cred = c; - return 0; -} - -int git_credential_username_new(git_credential **cred, const char *username) -{ - git_credential_username *c; - size_t len, allocsize; - - GIT_ASSERT_ARG(cred); - - len = strlen(username); - - GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, sizeof(git_credential_username), len); - GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, allocsize, 1); - c = git__malloc(allocsize); - GIT_ERROR_CHECK_ALLOC(c); - - c->parent.credtype = GIT_CREDENTIAL_USERNAME; - c->parent.free = username_free; - memcpy(c->username, username, len + 1); - - *cred = (git_credential *) c; - return 0; -} - -void git_credential_free(git_credential *cred) -{ - if (!cred) - return; - - cred->free(cred); -} - -/* Deprecated credential functions */ - -#ifndef GIT_DEPRECATE_HARD -int git_cred_has_username(git_credential *cred) -{ - return git_credential_has_username(cred); -} - -const char *git_cred_get_username(git_credential *cred) -{ - return git_credential_get_username(cred); -} - -int git_cred_userpass_plaintext_new( - git_credential **out, - const char *username, - const char *password) -{ - return git_credential_userpass_plaintext_new(out,username, password); -} - -int git_cred_default_new(git_credential **out) -{ - return git_credential_default_new(out); -} - -int git_cred_username_new(git_credential **out, const char *username) -{ - return git_credential_username_new(out, username); -} - -int git_cred_ssh_key_new( - git_credential **out, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase) -{ - return git_credential_ssh_key_new(out, username, - publickey, privatekey, passphrase); -} - -int git_cred_ssh_key_memory_new( - git_credential **out, - const char *username, - const char *publickey, - const char *privatekey, - const char *passphrase) -{ - return git_credential_ssh_key_memory_new(out, username, - publickey, privatekey, passphrase); -} - -int git_cred_ssh_interactive_new( - git_credential **out, - const char *username, - git_credential_ssh_interactive_cb prompt_callback, - void *payload) -{ - return git_credential_ssh_interactive_new(out, username, - prompt_callback, payload); -} - -int git_cred_ssh_key_from_agent( - git_credential **out, - const char *username) -{ - return git_credential_ssh_key_from_agent(out, username); -} - -int git_cred_ssh_custom_new( - git_credential **out, - const char *username, - const char *publickey, - size_t publickey_len, - git_credential_sign_cb sign_callback, - void *payload) -{ - return git_credential_ssh_custom_new(out, username, - publickey, publickey_len, sign_callback, payload); -} - -void git_cred_free(git_credential *cred) -{ - git_credential_free(cred); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/credential_helpers.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/credential_helpers.c deleted file mode 100644 index 6d34a4e..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/credential_helpers.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2/credential_helpers.h" - -int git_credential_userpass( - git_credential **cred, - const char *url, - const char *user_from_url, - unsigned int allowed_types, - void *payload) -{ - git_credential_userpass_payload *userpass = (git_credential_userpass_payload*)payload; - const char *effective_username = NULL; - - GIT_UNUSED(url); - - if (!userpass || !userpass->password) return -1; - - /* Username resolution: a username can be passed with the URL, the - * credentials payload, or both. Here's what we do. Note that if we get - * this far, we know that any password the url may contain has already - * failed at least once, so we ignore it. - * - * | Payload | URL | Used | - * +-------------+----------+-----------+ - * | yes | no | payload | - * | yes | yes | payload | - * | no | yes | url | - * | no | no | FAIL | - */ - if (userpass->username) - effective_username = userpass->username; - else if (user_from_url) - effective_username = user_from_url; - else - return -1; - - if (GIT_CREDENTIAL_USERNAME & allowed_types) - return git_credential_username_new(cred, effective_username); - - if ((GIT_CREDENTIAL_USERPASS_PLAINTEXT & allowed_types) == 0 || - git_credential_userpass_plaintext_new(cred, effective_username, userpass->password) < 0) - return -1; - - return 0; -} - -/* Deprecated credential functions */ - -#ifndef GIT_DEPRECATE_HARD -int git_cred_userpass( - git_credential **out, - const char *url, - const char *user_from_url, - unsigned int allowed_types, - void *payload) -{ - return git_credential_userpass(out, url, user_from_url, - allowed_types, payload); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/git.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/git.c deleted file mode 100644 index 904de25..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/git.c +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "net.h" -#include "stream.h" -#include "streams/socket.h" -#include "git2/sys/transport.h" - -#define OWNING_SUBTRANSPORT(s) ((git_subtransport *)(s)->parent.subtransport) - -static const char prefix_git[] = "git://"; -static const char cmd_uploadpack[] = "git-upload-pack"; -static const char cmd_receivepack[] = "git-receive-pack"; - -typedef struct { - git_smart_subtransport_stream parent; - git_stream *io; - const char *cmd; - char *url; - unsigned sent_command : 1; -} git_proto_stream; - -typedef struct { - git_smart_subtransport parent; - git_transport *owner; - git_proto_stream *current_stream; -} git_subtransport; - -/* - * Create a git protocol request. - * - * For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0 - */ -static int gen_proto(git_str *request, const char *cmd, const char *url) -{ - const char *delim, *repo; - char host[] = "host="; - size_t len; - - delim = strchr(url, '/'); - if (delim == NULL) { - git_error_set(GIT_ERROR_NET, "malformed URL"); - return -1; - } - - repo = delim; - if (repo[1] == '~') - ++repo; - - delim = strchr(url, ':'); - if (delim == NULL) - delim = strchr(url, '/'); - - len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1; - - git_str_grow(request, len); - git_str_printf(request, "%04x%s %s%c%s", - (unsigned int)(len & 0x0FFFF), cmd, repo, 0, host); - git_str_put(request, url, delim - url); - git_str_putc(request, '\0'); - - if (git_str_oom(request)) - return -1; - - return 0; -} - -static int send_command(git_proto_stream *s) -{ - git_str request = GIT_STR_INIT; - int error; - - if ((error = gen_proto(&request, s->cmd, s->url)) < 0) - goto cleanup; - - if ((error = git_stream__write_full(s->io, request.ptr, request.size, 0)) < 0) - goto cleanup; - - s->sent_command = 1; - -cleanup: - git_str_dispose(&request); - return error; -} - -static int git_proto_stream_read( - git_smart_subtransport_stream *stream, - char *buffer, - size_t buf_size, - size_t *bytes_read) -{ - git_proto_stream *s = (git_proto_stream *)stream; - ssize_t ret; - int error; - - *bytes_read = 0; - - if (!s->sent_command && (error = send_command(s)) < 0) - return error; - - ret = git_stream_read(s->io, buffer, min(buf_size, INT_MAX)); - - if (ret < 0) - return -1; - - *bytes_read = (size_t)ret; - return 0; -} - -static int git_proto_stream_write( - git_smart_subtransport_stream *stream, - const char *buffer, - size_t len) -{ - git_proto_stream *s = (git_proto_stream *)stream; - int error; - - if (!s->sent_command && (error = send_command(s)) < 0) - return error; - - return git_stream__write_full(s->io, buffer, len, 0); -} - -static void git_proto_stream_free(git_smart_subtransport_stream *stream) -{ - git_proto_stream *s; - git_subtransport *t; - - if (!stream) - return; - - s = (git_proto_stream *)stream; - t = OWNING_SUBTRANSPORT(s); - - t->current_stream = NULL; - - git_stream_close(s->io); - git_stream_free(s->io); - git__free(s->url); - git__free(s); -} - -static int git_proto_stream_alloc( - git_subtransport *t, - const char *url, - const char *cmd, - const char *host, - const char *port, - git_smart_subtransport_stream **stream) -{ - git_proto_stream *s; - - if (!stream) - return -1; - - s = git__calloc(1, sizeof(git_proto_stream)); - GIT_ERROR_CHECK_ALLOC(s); - - s->parent.subtransport = &t->parent; - s->parent.read = git_proto_stream_read; - s->parent.write = git_proto_stream_write; - s->parent.free = git_proto_stream_free; - - s->cmd = cmd; - s->url = git__strdup(url); - - if (!s->url) { - git__free(s); - return -1; - } - - if ((git_socket_stream_new(&s->io, host, port)) < 0) - return -1; - - GIT_ERROR_CHECK_VERSION(s->io, GIT_STREAM_VERSION, "git_stream"); - - *stream = &s->parent; - return 0; -} - -static int _git_uploadpack_ls( - git_subtransport *t, - const char *url, - git_smart_subtransport_stream **stream) -{ - git_net_url urldata = GIT_NET_URL_INIT; - const char *stream_url = url; - const char *host, *port; - git_proto_stream *s; - int error; - - *stream = NULL; - - if (!git__prefixcmp(url, prefix_git)) - stream_url += strlen(prefix_git); - - if ((error = git_net_url_parse(&urldata, url)) < 0) - return error; - - host = urldata.host; - port = urldata.port ? urldata.port : GIT_DEFAULT_PORT; - - error = git_proto_stream_alloc(t, stream_url, cmd_uploadpack, host, port, stream); - - git_net_url_dispose(&urldata); - - if (error < 0) { - git_proto_stream_free(*stream); - return error; - } - - s = (git_proto_stream *) *stream; - if ((error = git_stream_connect(s->io)) < 0) { - git_proto_stream_free(*stream); - return error; - } - - t->current_stream = s; - - return 0; -} - -static int _git_uploadpack( - git_subtransport *t, - const char *url, - git_smart_subtransport_stream **stream) -{ - GIT_UNUSED(url); - - if (t->current_stream) { - *stream = &t->current_stream->parent; - return 0; - } - - git_error_set(GIT_ERROR_NET, "must call UPLOADPACK_LS before UPLOADPACK"); - return -1; -} - -static int _git_receivepack_ls( - git_subtransport *t, - const char *url, - git_smart_subtransport_stream **stream) -{ - git_net_url urldata = GIT_NET_URL_INIT; - const char *stream_url = url; - git_proto_stream *s; - int error; - - *stream = NULL; - if (!git__prefixcmp(url, prefix_git)) - stream_url += strlen(prefix_git); - - if ((error = git_net_url_parse(&urldata, url)) < 0) - return error; - - error = git_proto_stream_alloc(t, stream_url, cmd_receivepack, urldata.host, urldata.port, stream); - - git_net_url_dispose(&urldata); - - if (error < 0) { - git_proto_stream_free(*stream); - return error; - } - - s = (git_proto_stream *) *stream; - - if ((error = git_stream_connect(s->io)) < 0) - return error; - - t->current_stream = s; - - return 0; -} - -static int _git_receivepack( - git_subtransport *t, - const char *url, - git_smart_subtransport_stream **stream) -{ - GIT_UNUSED(url); - - if (t->current_stream) { - *stream = &t->current_stream->parent; - return 0; - } - - git_error_set(GIT_ERROR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK"); - return -1; -} - -static int _git_action( - git_smart_subtransport_stream **stream, - git_smart_subtransport *subtransport, - const char *url, - git_smart_service_t action) -{ - git_subtransport *t = (git_subtransport *) subtransport; - - switch (action) { - case GIT_SERVICE_UPLOADPACK_LS: - return _git_uploadpack_ls(t, url, stream); - - case GIT_SERVICE_UPLOADPACK: - return _git_uploadpack(t, url, stream); - - case GIT_SERVICE_RECEIVEPACK_LS: - return _git_receivepack_ls(t, url, stream); - - case GIT_SERVICE_RECEIVEPACK: - return _git_receivepack(t, url, stream); - } - - *stream = NULL; - return -1; -} - -static int _git_close(git_smart_subtransport *subtransport) -{ - git_subtransport *t = (git_subtransport *) subtransport; - - GIT_ASSERT(!t->current_stream); - - GIT_UNUSED(t); - - return 0; -} - -static void _git_free(git_smart_subtransport *subtransport) -{ - git_subtransport *t = (git_subtransport *) subtransport; - - git__free(t); -} - -int git_smart_subtransport_git(git_smart_subtransport **out, git_transport *owner, void *param) -{ - git_subtransport *t; - - GIT_UNUSED(param); - - if (!out) - return -1; - - t = git__calloc(1, sizeof(git_subtransport)); - GIT_ERROR_CHECK_ALLOC(t); - - t->owner = owner; - t->parent.action = _git_action; - t->parent.close = _git_close; - t->parent.free = _git_free; - - *out = (git_smart_subtransport *) t; - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/http.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/http.c deleted file mode 100644 index f344888..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/http.c +++ /dev/null @@ -1,765 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#ifndef GIT_WINHTTP - -#include "net.h" -#include "remote.h" -#include "smart.h" -#include "auth.h" -#include "http.h" -#include "auth_negotiate.h" -#include "auth_ntlm.h" -#include "trace.h" -#include "streams/tls.h" -#include "streams/socket.h" -#include "httpclient.h" -#include "git2/sys/credential.h" - -bool git_http__expect_continue = false; - -typedef enum { - HTTP_STATE_NONE = 0, - HTTP_STATE_SENDING_REQUEST, - HTTP_STATE_RECEIVING_RESPONSE, - HTTP_STATE_DONE -} http_state; - -typedef struct { - git_http_method method; - const char *url; - const char *request_type; - const char *response_type; - unsigned int initial : 1, - chunked : 1; -} http_service; - -typedef struct { - git_smart_subtransport_stream parent; - const http_service *service; - http_state state; - unsigned replay_count; -} http_stream; - -typedef struct { - git_net_url url; - - git_credential *cred; - unsigned auth_schemetypes; - unsigned url_cred_presented : 1; -} http_server; - -typedef struct { - git_smart_subtransport parent; - transport_smart *owner; - - http_server server; - http_server proxy; - - git_http_client *http_client; -} http_subtransport; - -static const http_service upload_pack_ls_service = { - GIT_HTTP_METHOD_GET, "/info/refs?service=git-upload-pack", - NULL, - "application/x-git-upload-pack-advertisement", - 1, - 0 -}; -static const http_service upload_pack_service = { - GIT_HTTP_METHOD_POST, "/git-upload-pack", - "application/x-git-upload-pack-request", - "application/x-git-upload-pack-result", - 0, - 0 -}; -static const http_service receive_pack_ls_service = { - GIT_HTTP_METHOD_GET, "/info/refs?service=git-receive-pack", - NULL, - "application/x-git-receive-pack-advertisement", - 1, - 0 -}; -static const http_service receive_pack_service = { - GIT_HTTP_METHOD_POST, "/git-receive-pack", - "application/x-git-receive-pack-request", - "application/x-git-receive-pack-result", - 0, - 1 -}; - -#define SERVER_TYPE_REMOTE "remote" -#define SERVER_TYPE_PROXY "proxy" - -#define OWNING_SUBTRANSPORT(s) ((http_subtransport *)(s)->parent.subtransport) - -static int apply_url_credentials( - git_credential **cred, - unsigned int allowed_types, - const char *username, - const char *password) -{ - GIT_ASSERT_ARG(username); - - if (!password) - password = ""; - - if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT) - return git_credential_userpass_plaintext_new(cred, username, password); - - if ((allowed_types & GIT_CREDENTIAL_DEFAULT) && *username == '\0' && *password == '\0') - return git_credential_default_new(cred); - - return GIT_PASSTHROUGH; -} - -GIT_INLINE(void) free_cred(git_credential **cred) -{ - if (*cred) { - git_credential_free(*cred); - (*cred) = NULL; - } -} - -static int handle_auth( - http_server *server, - const char *server_type, - unsigned int allowed_schemetypes, - unsigned int allowed_credtypes, - git_credential_acquire_cb callback, - void *callback_payload) -{ - git_str server_url = GIT_STR_INIT; - int error = 1; - - if (server->cred) - free_cred(&server->cred); - - /* Start with URL-specified credentials, if there were any. */ - if ((allowed_credtypes & GIT_CREDENTIAL_USERPASS_PLAINTEXT) && - !server->url_cred_presented && - server->url.username) { - error = apply_url_credentials(&server->cred, allowed_credtypes, server->url.username, server->url.password); - server->url_cred_presented = 1; - - /* treat GIT_PASSTHROUGH as if callback isn't set */ - if (error == GIT_PASSTHROUGH) - error = 1; - } - - if (error > 0 && callback) { - if ((error = git_net_url_fmt(&server_url, &server->url)) == 0) - error = callback(&server->cred, server_url.ptr, server->url.username, allowed_credtypes, callback_payload); - - /* treat GIT_PASSTHROUGH as if callback isn't set */ - if (error == GIT_PASSTHROUGH) - error = 1; - } - - if (error > 0) { - git_error_set(GIT_ERROR_HTTP, "%s authentication required but no callback set", server_type); - error = GIT_EAUTH; - } - - if (!error) - server->auth_schemetypes = allowed_schemetypes; - - git_str_dispose(&server_url); - return error; -} - -GIT_INLINE(int) handle_remote_auth( - http_stream *stream, - git_http_response *response) -{ - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - git_remote_connect_options *connect_opts = &transport->owner->connect_opts; - - if (response->server_auth_credtypes == 0) { - git_error_set(GIT_ERROR_HTTP, "server requires authentication that we do not support"); - return GIT_EAUTH; - } - - /* Otherwise, prompt for credentials. */ - return handle_auth( - &transport->server, - SERVER_TYPE_REMOTE, - response->server_auth_schemetypes, - response->server_auth_credtypes, - connect_opts->callbacks.credentials, - connect_opts->callbacks.payload); -} - -GIT_INLINE(int) handle_proxy_auth( - http_stream *stream, - git_http_response *response) -{ - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - git_remote_connect_options *connect_opts = &transport->owner->connect_opts; - - if (response->proxy_auth_credtypes == 0) { - git_error_set(GIT_ERROR_HTTP, "proxy requires authentication that we do not support"); - return GIT_EAUTH; - } - - /* Otherwise, prompt for credentials. */ - return handle_auth( - &transport->proxy, - SERVER_TYPE_PROXY, - response->server_auth_schemetypes, - response->proxy_auth_credtypes, - connect_opts->proxy_opts.credentials, - connect_opts->proxy_opts.payload); -} - -static bool allow_redirect(http_stream *stream) -{ - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - - switch (transport->owner->connect_opts.follow_redirects) { - case GIT_REMOTE_REDIRECT_INITIAL: - return (stream->service->initial == 1); - case GIT_REMOTE_REDIRECT_ALL: - return true; - default: - return false; - } -} - -static int handle_response( - bool *complete, - http_stream *stream, - git_http_response *response, - bool allow_replay) -{ - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - int error; - - *complete = false; - - if (allow_replay && git_http_response_is_redirect(response)) { - if (!response->location) { - git_error_set(GIT_ERROR_HTTP, "redirect without location"); - return -1; - } - - if (git_net_url_apply_redirect(&transport->server.url, response->location, allow_redirect(stream), stream->service->url) < 0) { - return -1; - } - - return 0; - } else if (git_http_response_is_redirect(response)) { - git_error_set(GIT_ERROR_HTTP, "unexpected redirect"); - return -1; - } - - /* If we're in the middle of challenge/response auth, continue. */ - if (allow_replay && response->resend_credentials) { - return 0; - } else if (allow_replay && response->status == GIT_HTTP_STATUS_UNAUTHORIZED) { - if ((error = handle_remote_auth(stream, response)) < 0) - return error; - - return git_http_client_skip_body(transport->http_client); - } else if (allow_replay && response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) { - if ((error = handle_proxy_auth(stream, response)) < 0) - return error; - - return git_http_client_skip_body(transport->http_client); - } else if (response->status == GIT_HTTP_STATUS_UNAUTHORIZED || - response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) { - git_error_set(GIT_ERROR_HTTP, "unexpected authentication failure"); - return GIT_EAUTH; - } - - if (response->status != GIT_HTTP_STATUS_OK) { - git_error_set(GIT_ERROR_HTTP, "unexpected http status code: %d", response->status); - return -1; - } - - /* The response must contain a Content-Type header. */ - if (!response->content_type) { - git_error_set(GIT_ERROR_HTTP, "no content-type header in response"); - return -1; - } - - /* The Content-Type header must match our expectation. */ - if (strcmp(response->content_type, stream->service->response_type) != 0) { - git_error_set(GIT_ERROR_HTTP, "invalid content-type: '%s'", response->content_type); - return -1; - } - - *complete = true; - stream->state = HTTP_STATE_RECEIVING_RESPONSE; - return 0; -} - -static int lookup_proxy( - bool *out_use, - http_subtransport *transport) -{ - git_remote_connect_options *connect_opts = &transport->owner->connect_opts; - const char *proxy; - git_remote *remote; - char *config = NULL; - int error = 0; - - *out_use = false; - git_net_url_dispose(&transport->proxy.url); - - switch (connect_opts->proxy_opts.type) { - case GIT_PROXY_SPECIFIED: - proxy = connect_opts->proxy_opts.url; - break; - - case GIT_PROXY_AUTO: - remote = transport->owner->owner; - - error = git_remote__http_proxy(&config, remote, &transport->server.url); - - if (error || !config) - goto done; - - proxy = config; - break; - - default: - return 0; - } - - if (!proxy || !*proxy || - (error = git_net_url_parse_http(&transport->proxy.url, proxy)) < 0) - goto done; - - if (!git_net_url_valid(&transport->proxy.url)) { - git_error_set(GIT_ERROR_HTTP, "invalid URL: '%s'", proxy); - error = -1; - goto done; - } - - *out_use = true; - -done: - git__free(config); - return error; -} - -static int generate_request( - git_net_url *url, - git_http_request *request, - http_stream *stream, - size_t len) -{ - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - bool use_proxy = false; - int error; - - if ((error = git_net_url_joinpath(url, - &transport->server.url, stream->service->url)) < 0 || - (error = lookup_proxy(&use_proxy, transport)) < 0) - return error; - - request->method = stream->service->method; - request->url = url; - request->credentials = transport->server.cred; - request->proxy = use_proxy ? &transport->proxy.url : NULL; - request->proxy_credentials = transport->proxy.cred; - request->custom_headers = &transport->owner->connect_opts.custom_headers; - - if (stream->service->method == GIT_HTTP_METHOD_POST) { - request->chunked = stream->service->chunked; - request->content_length = stream->service->chunked ? 0 : len; - request->content_type = stream->service->request_type; - request->accept = stream->service->response_type; - request->expect_continue = git_http__expect_continue; - } - - return 0; -} - -/* - * Read from an HTTP transport - for the first invocation of this function - * (ie, when stream->state == HTTP_STATE_NONE), we'll send a GET request - * to the remote host. We will stream that data back on all subsequent - * calls. - */ -static int http_stream_read( - git_smart_subtransport_stream *s, - char *buffer, - size_t buffer_size, - size_t *out_len) -{ - http_stream *stream = (http_stream *)s; - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - git_net_url url = GIT_NET_URL_INIT; - git_net_url proxy_url = GIT_NET_URL_INIT; - git_http_request request = {0}; - git_http_response response = {0}; - bool complete; - int error; - - *out_len = 0; - - if (stream->state == HTTP_STATE_NONE) { - stream->state = HTTP_STATE_SENDING_REQUEST; - stream->replay_count = 0; - } - - /* - * Formulate the URL, send the request and read the response - * headers. Some of the request body may also be read. - */ - while (stream->state == HTTP_STATE_SENDING_REQUEST && - stream->replay_count < GIT_HTTP_REPLAY_MAX) { - git_net_url_dispose(&url); - git_net_url_dispose(&proxy_url); - git_http_response_dispose(&response); - - if ((error = generate_request(&url, &request, stream, 0)) < 0 || - (error = git_http_client_send_request( - transport->http_client, &request)) < 0 || - (error = git_http_client_read_response( - &response, transport->http_client)) < 0 || - (error = handle_response(&complete, stream, &response, true)) < 0) - goto done; - - if (complete) - break; - - stream->replay_count++; - } - - if (stream->state == HTTP_STATE_SENDING_REQUEST) { - git_error_set(GIT_ERROR_HTTP, "too many redirects or authentication replays"); - error = GIT_ERROR; /* not GIT_EAUTH, because the exact cause is unclear */ - goto done; - } - - GIT_ASSERT(stream->state == HTTP_STATE_RECEIVING_RESPONSE); - - error = git_http_client_read_body(transport->http_client, buffer, buffer_size); - - if (error > 0) { - *out_len = error; - error = 0; - } - -done: - git_net_url_dispose(&url); - git_net_url_dispose(&proxy_url); - git_http_response_dispose(&response); - - return error; -} - -static bool needs_probe(http_stream *stream) -{ - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - - return (transport->server.auth_schemetypes == GIT_HTTP_AUTH_NTLM || - transport->server.auth_schemetypes == GIT_HTTP_AUTH_NEGOTIATE); -} - -static int send_probe(http_stream *stream) -{ - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - git_http_client *client = transport->http_client; - const char *probe = "0000"; - size_t len = 4; - git_net_url url = GIT_NET_URL_INIT; - git_http_request request = {0}; - git_http_response response = {0}; - bool complete = false; - size_t step, steps = 1; - int error; - - /* NTLM requires a full challenge/response */ - if (transport->server.auth_schemetypes == GIT_HTTP_AUTH_NTLM) - steps = GIT_AUTH_STEPS_NTLM; - - /* - * Send at most two requests: one without any authentication to see - * if we get prompted to authenticate. If we do, send a second one - * with the first authentication message. The final authentication - * message with the response will occur with the *actual* POST data. - */ - for (step = 0; step < steps && !complete; step++) { - git_net_url_dispose(&url); - git_http_response_dispose(&response); - - if ((error = generate_request(&url, &request, stream, len)) < 0 || - (error = git_http_client_send_request(client, &request)) < 0 || - (error = git_http_client_send_body(client, probe, len)) < 0 || - (error = git_http_client_read_response(&response, client)) < 0 || - (error = git_http_client_skip_body(client)) < 0 || - (error = handle_response(&complete, stream, &response, true)) < 0) - goto done; - } - -done: - git_http_response_dispose(&response); - git_net_url_dispose(&url); - return error; -} - -/* -* Write to an HTTP transport - for the first invocation of this function -* (ie, when stream->state == HTTP_STATE_NONE), we'll send a POST request -* to the remote host. If we're sending chunked data, then subsequent calls -* will write the additional data given in the buffer. If we're not chunking, -* then the caller should have given us all the data in the original call. -* The caller should call http_stream_read_response to get the result. -*/ -static int http_stream_write( - git_smart_subtransport_stream *s, - const char *buffer, - size_t len) -{ - http_stream *stream = GIT_CONTAINER_OF(s, http_stream, parent); - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - git_net_url url = GIT_NET_URL_INIT; - git_http_request request = {0}; - git_http_response response = {0}; - int error; - - while (stream->state == HTTP_STATE_NONE && - stream->replay_count < GIT_HTTP_REPLAY_MAX) { - - git_net_url_dispose(&url); - git_http_response_dispose(&response); - - /* - * If we're authenticating with a connection-based mechanism - * (NTLM, Kerberos), send a "probe" packet. Servers SHOULD - * authenticate an entire keep-alive connection, so ideally - * we should not need to authenticate but some servers do - * not support this. By sending a probe packet, we'll be - * able to follow up with a second POST using the actual - * data (and, in the degenerate case, the authentication - * header as well). - */ - if (needs_probe(stream) && (error = send_probe(stream)) < 0) - goto done; - - /* Send the regular POST request. */ - if ((error = generate_request(&url, &request, stream, len)) < 0 || - (error = git_http_client_send_request( - transport->http_client, &request)) < 0) - goto done; - - if (request.expect_continue && - git_http_client_has_response(transport->http_client)) { - bool complete; - - /* - * If we got a response to an expect/continue, then - * it's something other than a 100 and we should - * deal with the response somehow. - */ - if ((error = git_http_client_read_response(&response, transport->http_client)) < 0 || - (error = handle_response(&complete, stream, &response, true)) < 0) - goto done; - } else { - stream->state = HTTP_STATE_SENDING_REQUEST; - } - - stream->replay_count++; - } - - if (stream->state == HTTP_STATE_NONE) { - git_error_set(GIT_ERROR_HTTP, - "too many redirects or authentication replays"); - error = GIT_ERROR; /* not GIT_EAUTH because the exact cause is unclear */ - goto done; - } - - GIT_ASSERT(stream->state == HTTP_STATE_SENDING_REQUEST); - - error = git_http_client_send_body(transport->http_client, buffer, len); - -done: - git_http_response_dispose(&response); - git_net_url_dispose(&url); - return error; -} - -/* -* Read from an HTTP transport after it has been written to. This is the -* response from a POST request made by http_stream_write. -*/ -static int http_stream_read_response( - git_smart_subtransport_stream *s, - char *buffer, - size_t buffer_size, - size_t *out_len) -{ - http_stream *stream = (http_stream *)s; - http_subtransport *transport = OWNING_SUBTRANSPORT(stream); - git_http_client *client = transport->http_client; - git_http_response response = {0}; - bool complete; - int error; - - *out_len = 0; - - if (stream->state == HTTP_STATE_SENDING_REQUEST) { - if ((error = git_http_client_read_response(&response, client)) < 0 || - (error = handle_response(&complete, stream, &response, false)) < 0) - goto done; - - GIT_ASSERT(complete); - stream->state = HTTP_STATE_RECEIVING_RESPONSE; - } - - error = git_http_client_read_body(client, buffer, buffer_size); - - if (error > 0) { - *out_len = error; - error = 0; - } - -done: - git_http_response_dispose(&response); - return error; -} - -static void http_stream_free(git_smart_subtransport_stream *stream) -{ - http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent); - git__free(s); -} - -static const http_service *select_service(git_smart_service_t action) -{ - switch (action) { - case GIT_SERVICE_UPLOADPACK_LS: - return &upload_pack_ls_service; - case GIT_SERVICE_UPLOADPACK: - return &upload_pack_service; - case GIT_SERVICE_RECEIVEPACK_LS: - return &receive_pack_ls_service; - case GIT_SERVICE_RECEIVEPACK: - return &receive_pack_service; - } - - return NULL; -} - -static int http_action( - git_smart_subtransport_stream **out, - git_smart_subtransport *t, - const char *url, - git_smart_service_t action) -{ - http_subtransport *transport = GIT_CONTAINER_OF(t, http_subtransport, parent); - git_remote_connect_options *connect_opts = &transport->owner->connect_opts; - git_http_client_options opts = {0}; - http_stream *stream; - const http_service *service; - int error; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(t); - - *out = NULL; - - /* - * If we've seen a redirect then preserve the location that we've - * been given. This is important to continue authorization against - * the redirect target, not the user-given source; the endpoint may - * have redirected us from HTTP->HTTPS and is using an auth mechanism - * that would be insecure in plaintext (eg, HTTP Basic). - */ - if (!git_net_url_valid(&transport->server.url) && - (error = git_net_url_parse(&transport->server.url, url)) < 0) - return error; - - if ((service = select_service(action)) == NULL) { - git_error_set(GIT_ERROR_HTTP, "invalid action"); - return -1; - } - - stream = git__calloc(sizeof(http_stream), 1); - GIT_ERROR_CHECK_ALLOC(stream); - - opts.server_certificate_check_cb = connect_opts->callbacks.certificate_check; - opts.server_certificate_check_payload = connect_opts->callbacks.payload; - opts.proxy_certificate_check_cb = connect_opts->proxy_opts.certificate_check; - opts.proxy_certificate_check_payload = connect_opts->proxy_opts.payload; - - if (transport->http_client) { - git_http_client_set_options(transport->http_client, &opts); - } else { - if (git_http_client_new(&transport->http_client, &opts) < 0) - return -1; - } - - stream->service = service; - stream->parent.subtransport = &transport->parent; - - if (service->method == GIT_HTTP_METHOD_GET) { - stream->parent.read = http_stream_read; - } else { - stream->parent.write = http_stream_write; - stream->parent.read = http_stream_read_response; - } - - stream->parent.free = http_stream_free; - - *out = (git_smart_subtransport_stream *)stream; - return 0; -} - -static int http_close(git_smart_subtransport *t) -{ - http_subtransport *transport = GIT_CONTAINER_OF(t, http_subtransport, parent); - - free_cred(&transport->server.cred); - free_cred(&transport->proxy.cred); - - transport->server.url_cred_presented = false; - transport->proxy.url_cred_presented = false; - - git_net_url_dispose(&transport->server.url); - git_net_url_dispose(&transport->proxy.url); - - return 0; -} - -static void http_free(git_smart_subtransport *t) -{ - http_subtransport *transport = GIT_CONTAINER_OF(t, http_subtransport, parent); - - git_http_client_free(transport->http_client); - - http_close(t); - git__free(transport); -} - -int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *owner, void *param) -{ - http_subtransport *transport; - - GIT_UNUSED(param); - - GIT_ASSERT_ARG(out); - - transport = git__calloc(sizeof(http_subtransport), 1); - GIT_ERROR_CHECK_ALLOC(transport); - - transport->owner = (transport_smart *)owner; - transport->parent.action = http_action; - transport->parent.close = http_close; - transport->parent.free = http_free; - - *out = (git_smart_subtransport *) transport; - return 0; -} - -#endif /* !GIT_WINHTTP */ diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/http.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/http.h deleted file mode 100644 index 7410202..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/http.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_transports_http_h__ -#define INCLUDE_transports_http_h__ - -#include "settings.h" -#include "httpclient.h" - -#define GIT_HTTP_REPLAY_MAX 15 - -extern bool git_http__expect_continue; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpclient.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpclient.c deleted file mode 100644 index 86bae39..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpclient.c +++ /dev/null @@ -1,1636 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" -#include "git2.h" - -#include "vector.h" -#include "trace.h" -#include "httpclient.h" -#include "http.h" -#include "auth.h" -#include "auth_negotiate.h" -#include "auth_ntlm.h" -#include "git2/sys/credential.h" -#include "net.h" -#include "stream.h" -#include "streams/socket.h" -#include "streams/tls.h" -#include "auth.h" -#include "httpparser.h" - -static git_http_auth_scheme auth_schemes[] = { - { GIT_HTTP_AUTH_NEGOTIATE, "Negotiate", GIT_CREDENTIAL_DEFAULT, git_http_auth_negotiate }, - { GIT_HTTP_AUTH_NTLM, "NTLM", GIT_CREDENTIAL_USERPASS_PLAINTEXT, git_http_auth_ntlm }, - { GIT_HTTP_AUTH_BASIC, "Basic", GIT_CREDENTIAL_USERPASS_PLAINTEXT, git_http_auth_basic }, -}; - -/* - * Use a 16kb read buffer to match the maximum size of a TLS packet. This - * is critical for compatibility with SecureTransport, which will always do - * a network read on every call, even if it has data buffered to return to - * you. That buffered data may be the _end_ of a keep-alive response, so - * if SecureTransport performs another network read, it will wait until the - * server ultimately times out before it returns that buffered data to you. - * Since SecureTransport only reads a single TLS packet at a time, by - * calling it with a read buffer that is the maximum size of a TLS packet, - * we ensure that it will never buffer. - */ -#define GIT_READ_BUFFER_SIZE (16 * 1024) - -typedef struct { - git_net_url url; - git_stream *stream; - - git_vector auth_challenges; - git_http_auth_context *auth_context; -} git_http_server; - -typedef enum { - PROXY = 1, - SERVER -} git_http_server_t; - -typedef enum { - NONE = 0, - SENDING_REQUEST, - SENDING_BODY, - SENT_REQUEST, - HAS_EARLY_RESPONSE, - READING_RESPONSE, - READING_BODY, - DONE -} http_client_state; - -/* Parser state */ -typedef enum { - PARSE_HEADER_NONE = 0, - PARSE_HEADER_NAME, - PARSE_HEADER_VALUE, - PARSE_HEADER_COMPLETE -} parse_header_state; - -typedef enum { - PARSE_STATUS_OK, - PARSE_STATUS_NO_OUTPUT, - PARSE_STATUS_ERROR -} parse_status; - -typedef struct { - git_http_client *client; - git_http_response *response; - - /* Temporary buffers to avoid extra mallocs */ - git_str parse_header_name; - git_str parse_header_value; - - /* Parser state */ - int error; - parse_status parse_status; - - /* Headers parsing */ - parse_header_state parse_header_state; - - /* Body parsing */ - char *output_buf; /* Caller's output buffer */ - size_t output_size; /* Size of caller's output buffer */ - size_t output_written; /* Bytes we've written to output buffer */ -} http_parser_context; - -/* HTTP client connection */ -struct git_http_client { - git_http_client_options opts; - - /* Are we writing to the proxy or server, and state of the client. */ - git_http_server_t current_server; - http_client_state state; - - git_http_parser parser; - - git_http_server server; - git_http_server proxy; - - unsigned request_count; - unsigned connected : 1, - proxy_connected : 1, - keepalive : 1, - request_chunked : 1; - - /* Temporary buffers to avoid extra mallocs */ - git_str request_msg; - git_str read_buf; - - /* A subset of information from the request */ - size_t request_body_len, - request_body_remain; - - /* - * When state == HAS_EARLY_RESPONSE, the response of our proxy - * that we have buffered and will deliver during read_response. - */ - git_http_response early_response; -}; - -bool git_http_response_is_redirect(git_http_response *response) -{ - return (response->status == GIT_HTTP_MOVED_PERMANENTLY || - response->status == GIT_HTTP_FOUND || - response->status == GIT_HTTP_SEE_OTHER || - response->status == GIT_HTTP_TEMPORARY_REDIRECT || - response->status == GIT_HTTP_PERMANENT_REDIRECT); -} - -void git_http_response_dispose(git_http_response *response) -{ - if (!response) - return; - - git__free(response->content_type); - git__free(response->location); - - memset(response, 0, sizeof(git_http_response)); -} - -static int on_header_complete(git_http_parser *parser) -{ - http_parser_context *ctx = (http_parser_context *) parser->data; - git_http_client *client = ctx->client; - git_http_response *response = ctx->response; - - git_str *name = &ctx->parse_header_name; - git_str *value = &ctx->parse_header_value; - - if (!strcasecmp("Content-Type", name->ptr)) { - if (response->content_type) { - git_error_set(GIT_ERROR_HTTP, - "multiple content-type headers"); - return -1; - } - - response->content_type = - git__strndup(value->ptr, value->size); - GIT_ERROR_CHECK_ALLOC(ctx->response->content_type); - } else if (!strcasecmp("Content-Length", name->ptr)) { - int64_t len; - - if (response->content_length) { - git_error_set(GIT_ERROR_HTTP, - "multiple content-length headers"); - return -1; - } - - if (git__strntol64(&len, value->ptr, value->size, - NULL, 10) < 0 || len < 0) { - git_error_set(GIT_ERROR_HTTP, - "invalid content-length"); - return -1; - } - - response->content_length = (size_t)len; - } else if (!strcasecmp("Transfer-Encoding", name->ptr) && - !strcasecmp("chunked", value->ptr)) { - ctx->response->chunked = 1; - } else if (!strcasecmp("Proxy-Authenticate", git_str_cstr(name))) { - char *dup = git__strndup(value->ptr, value->size); - GIT_ERROR_CHECK_ALLOC(dup); - - if (git_vector_insert(&client->proxy.auth_challenges, dup) < 0) - return -1; - } else if (!strcasecmp("WWW-Authenticate", name->ptr)) { - char *dup = git__strndup(value->ptr, value->size); - GIT_ERROR_CHECK_ALLOC(dup); - - if (git_vector_insert(&client->server.auth_challenges, dup) < 0) - return -1; - } else if (!strcasecmp("Location", name->ptr)) { - if (response->location) { - git_error_set(GIT_ERROR_HTTP, - "multiple location headers"); - return -1; - } - - response->location = git__strndup(value->ptr, value->size); - GIT_ERROR_CHECK_ALLOC(response->location); - } - - return 0; -} - -static int on_header_field(git_http_parser *parser, const char *str, size_t len) -{ - http_parser_context *ctx = (http_parser_context *) parser->data; - - switch (ctx->parse_header_state) { - /* - * We last saw a header value, process the name/value pair and - * get ready to handle this new name. - */ - case PARSE_HEADER_VALUE: - if (on_header_complete(parser) < 0) - return ctx->parse_status = PARSE_STATUS_ERROR; - - git_str_clear(&ctx->parse_header_name); - git_str_clear(&ctx->parse_header_value); - /* Fall through */ - - case PARSE_HEADER_NONE: - case PARSE_HEADER_NAME: - ctx->parse_header_state = PARSE_HEADER_NAME; - - if (git_str_put(&ctx->parse_header_name, str, len) < 0) - return ctx->parse_status = PARSE_STATUS_ERROR; - - break; - - default: - git_error_set(GIT_ERROR_HTTP, - "header name seen at unexpected time"); - return ctx->parse_status = PARSE_STATUS_ERROR; - } - - return 0; -} - -static int on_header_value(git_http_parser *parser, const char *str, size_t len) -{ - http_parser_context *ctx = (http_parser_context *) parser->data; - - switch (ctx->parse_header_state) { - case PARSE_HEADER_NAME: - case PARSE_HEADER_VALUE: - ctx->parse_header_state = PARSE_HEADER_VALUE; - - if (git_str_put(&ctx->parse_header_value, str, len) < 0) - return ctx->parse_status = PARSE_STATUS_ERROR; - - break; - - default: - git_error_set(GIT_ERROR_HTTP, - "header value seen at unexpected time"); - return ctx->parse_status = PARSE_STATUS_ERROR; - } - - return 0; -} - -GIT_INLINE(bool) challenge_matches_scheme( - const char *challenge, - git_http_auth_scheme *scheme) -{ - const char *scheme_name = scheme->name; - size_t scheme_len = strlen(scheme_name); - - if (!strncasecmp(challenge, scheme_name, scheme_len) && - (challenge[scheme_len] == '\0' || challenge[scheme_len] == ' ')) - return true; - - return false; -} - -static git_http_auth_scheme *scheme_for_challenge(const char *challenge) -{ - size_t i; - - for (i = 0; i < ARRAY_SIZE(auth_schemes); i++) { - if (challenge_matches_scheme(challenge, &auth_schemes[i])) - return &auth_schemes[i]; - } - - return NULL; -} - -GIT_INLINE(void) collect_authinfo( - unsigned int *schemetypes, - unsigned int *credtypes, - git_vector *challenges) -{ - git_http_auth_scheme *scheme; - const char *challenge; - size_t i; - - *schemetypes = 0; - *credtypes = 0; - - git_vector_foreach(challenges, i, challenge) { - if ((scheme = scheme_for_challenge(challenge)) != NULL) { - *schemetypes |= scheme->type; - *credtypes |= scheme->credtypes; - } - } -} - -static int resend_needed(git_http_client *client, git_http_response *response) -{ - git_http_auth_context *auth_context; - - if (response->status == GIT_HTTP_STATUS_UNAUTHORIZED && - (auth_context = client->server.auth_context) && - auth_context->is_complete && - !auth_context->is_complete(auth_context)) - return 1; - - if (response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED && - (auth_context = client->proxy.auth_context) && - auth_context->is_complete && - !auth_context->is_complete(auth_context)) - return 1; - - return 0; -} - -static int on_headers_complete(git_http_parser *parser) -{ - http_parser_context *ctx = (http_parser_context *) parser->data; - - /* Finalize the last seen header */ - switch (ctx->parse_header_state) { - case PARSE_HEADER_VALUE: - if (on_header_complete(parser) < 0) - return ctx->parse_status = PARSE_STATUS_ERROR; - - /* Fall through */ - - case PARSE_HEADER_NONE: - ctx->parse_header_state = PARSE_HEADER_COMPLETE; - break; - - default: - git_error_set(GIT_ERROR_HTTP, - "header completion at unexpected time"); - return ctx->parse_status = PARSE_STATUS_ERROR; - } - - ctx->response->status = git_http_parser_status_code(parser); - ctx->client->keepalive = git_http_parser_keep_alive(parser); - - /* Prepare for authentication */ - collect_authinfo(&ctx->response->server_auth_schemetypes, - &ctx->response->server_auth_credtypes, - &ctx->client->server.auth_challenges); - collect_authinfo(&ctx->response->proxy_auth_schemetypes, - &ctx->response->proxy_auth_credtypes, - &ctx->client->proxy.auth_challenges); - - ctx->response->resend_credentials = resend_needed(ctx->client, - ctx->response); - - if (ctx->response->content_length || ctx->response->chunked) - ctx->client->state = READING_BODY; - else - ctx->client->state = DONE; - - return git_http_parser_pause(parser); -} - -static int on_body(git_http_parser *parser, const char *buf, size_t len) -{ - http_parser_context *ctx = (http_parser_context *) parser->data; - size_t max_len; - - /* Saw data when we expected not to (eg, in consume_response_body) */ - if (ctx->output_buf == NULL || ctx->output_size == 0) { - ctx->parse_status = PARSE_STATUS_NO_OUTPUT; - return 0; - } - - GIT_ASSERT(ctx->output_size >= ctx->output_written); - - max_len = min(ctx->output_size - ctx->output_written, len); - max_len = min(max_len, INT_MAX); - - memcpy(ctx->output_buf + ctx->output_written, buf, max_len); - ctx->output_written += max_len; - - return 0; -} - -static int on_message_complete(git_http_parser *parser) -{ - http_parser_context *ctx = (http_parser_context *) parser->data; - - ctx->client->state = DONE; - return 0; -} - -GIT_INLINE(int) stream_write( - git_http_server *server, - const char *data, - size_t len) -{ - git_trace(GIT_TRACE_TRACE, - "Sending request:\n%.*s", (int)len, data); - - return git_stream__write_full(server->stream, data, len, 0); -} - -GIT_INLINE(int) client_write_request(git_http_client *client) -{ - git_stream *stream = client->current_server == PROXY ? - client->proxy.stream : client->server.stream; - - git_trace(GIT_TRACE_TRACE, - "Sending request:\n%.*s", - (int)client->request_msg.size, client->request_msg.ptr); - - return git_stream__write_full(stream, - client->request_msg.ptr, - client->request_msg.size, - 0); -} - -static const char *name_for_method(git_http_method method) -{ - switch (method) { - case GIT_HTTP_METHOD_GET: - return "GET"; - case GIT_HTTP_METHOD_POST: - return "POST"; - case GIT_HTTP_METHOD_CONNECT: - return "CONNECT"; - } - - return NULL; -} - -/* - * Find the scheme that is suitable for the given credentials, based on the - * server's auth challenges. - */ -static bool best_scheme_and_challenge( - git_http_auth_scheme **scheme_out, - const char **challenge_out, - git_vector *challenges, - git_credential *credentials) -{ - const char *challenge; - size_t i, j; - - for (i = 0; i < ARRAY_SIZE(auth_schemes); i++) { - git_vector_foreach(challenges, j, challenge) { - git_http_auth_scheme *scheme = &auth_schemes[i]; - - if (challenge_matches_scheme(challenge, scheme) && - (scheme->credtypes & credentials->credtype)) { - *scheme_out = scheme; - *challenge_out = challenge; - return true; - } - } - } - - return false; -} - -/* - * Find the challenge from the server for our current auth context. - */ -static const char *challenge_for_context( - git_vector *challenges, - git_http_auth_context *auth_ctx) -{ - const char *challenge; - size_t i, j; - - for (i = 0; i < ARRAY_SIZE(auth_schemes); i++) { - if (auth_schemes[i].type == auth_ctx->type) { - git_http_auth_scheme *scheme = &auth_schemes[i]; - - git_vector_foreach(challenges, j, challenge) { - if (challenge_matches_scheme(challenge, scheme)) - return challenge; - } - } - } - - return NULL; -} - -static const char *init_auth_context( - git_http_server *server, - git_vector *challenges, - git_credential *credentials) -{ - git_http_auth_scheme *scheme; - const char *challenge; - int error; - - if (!best_scheme_and_challenge(&scheme, &challenge, challenges, credentials)) { - git_error_set(GIT_ERROR_HTTP, "could not find appropriate mechanism for credentials"); - return NULL; - } - - error = scheme->init_context(&server->auth_context, &server->url); - - if (error == GIT_PASSTHROUGH) { - git_error_set(GIT_ERROR_HTTP, "'%s' authentication is not supported", scheme->name); - return NULL; - } - - return challenge; -} - -static void free_auth_context(git_http_server *server) -{ - if (!server->auth_context) - return; - - if (server->auth_context->free) - server->auth_context->free(server->auth_context); - - server->auth_context = NULL; -} - -static int apply_credentials( - git_str *buf, - git_http_server *server, - const char *header_name, - git_credential *credentials) -{ - git_http_auth_context *auth = server->auth_context; - git_vector *challenges = &server->auth_challenges; - const char *challenge = NULL; - git_str token = GIT_STR_INIT; - int error = 0; - - /* We've started a new request without creds; free the context. */ - if (auth && !credentials) { - free_auth_context(server); - return 0; - } - - /* We haven't authenticated, nor were we asked to. Nothing to do. */ - if (!auth && !git_vector_length(challenges)) - return 0; - - if (!auth) { - challenge = init_auth_context(server, challenges, credentials); - auth = server->auth_context; - - if (!challenge || !auth) { - error = -1; - goto done; - } - } else if (auth->set_challenge) { - challenge = challenge_for_context(challenges, auth); - } - - if (auth->set_challenge && challenge && - (error = auth->set_challenge(auth, challenge)) < 0) - goto done; - - if ((error = auth->next_token(&token, auth, credentials)) < 0) - goto done; - - if (auth->is_complete && auth->is_complete(auth)) { - /* - * If we're done with an auth mechanism with connection affinity, - * we don't need to send any more headers and can dispose the context. - */ - if (auth->connection_affinity) - free_auth_context(server); - } else if (!token.size) { - git_error_set(GIT_ERROR_HTTP, "failed to respond to authentication challenge"); - error = GIT_EAUTH; - goto done; - } - - if (token.size > 0) - error = git_str_printf(buf, "%s: %s\r\n", header_name, token.ptr); - -done: - git_str_dispose(&token); - return error; -} - -GIT_INLINE(int) apply_server_credentials( - git_str *buf, - git_http_client *client, - git_http_request *request) -{ - return apply_credentials(buf, - &client->server, - "Authorization", - request->credentials); -} - -GIT_INLINE(int) apply_proxy_credentials( - git_str *buf, - git_http_client *client, - git_http_request *request) -{ - return apply_credentials(buf, - &client->proxy, - "Proxy-Authorization", - request->proxy_credentials); -} - -static int puts_host_and_port(git_str *buf, git_net_url *url, bool force_port) -{ - bool ipv6 = git_net_url_is_ipv6(url); - - if (ipv6) - git_str_putc(buf, '['); - - git_str_puts(buf, url->host); - - if (ipv6) - git_str_putc(buf, ']'); - - if (force_port || !git_net_url_is_default_port(url)) { - git_str_putc(buf, ':'); - git_str_puts(buf, url->port); - } - - return git_str_oom(buf) ? -1 : 0; -} - -static int append_user_agent(git_str *buf) -{ - const char *product = git_settings__user_agent_product(); - const char *comment = git_settings__user_agent(); - - GIT_ASSERT(product && comment); - - if (!*product) - return 0; - - git_str_puts(buf, "User-Agent: "); - git_str_puts(buf, product); - - if (*comment) { - git_str_puts(buf, " ("); - git_str_puts(buf, comment); - git_str_puts(buf, ")"); - } - - git_str_puts(buf, "\r\n"); - - return git_str_oom(buf) ? -1 : 0; -} - -static int generate_connect_request( - git_http_client *client, - git_http_request *request) -{ - git_str *buf; - int error; - - git_str_clear(&client->request_msg); - buf = &client->request_msg; - - git_str_puts(buf, "CONNECT "); - puts_host_and_port(buf, &client->server.url, true); - git_str_puts(buf, " HTTP/1.1\r\n"); - - append_user_agent(buf); - - git_str_puts(buf, "Host: "); - puts_host_and_port(buf, &client->server.url, true); - git_str_puts(buf, "\r\n"); - - if ((error = apply_proxy_credentials(buf, client, request) < 0)) - return -1; - - git_str_puts(buf, "\r\n"); - - return git_str_oom(buf) ? -1 : 0; -} - -static bool use_connect_proxy(git_http_client *client) -{ - return client->proxy.url.host && !strcmp(client->server.url.scheme, "https"); -} - -static int generate_request( - git_http_client *client, - git_http_request *request) -{ - git_str *buf; - size_t i; - int error; - - GIT_ASSERT_ARG(client); - GIT_ASSERT_ARG(request); - - git_str_clear(&client->request_msg); - buf = &client->request_msg; - - /* GET|POST path HTTP/1.1 */ - git_str_puts(buf, name_for_method(request->method)); - git_str_putc(buf, ' '); - - if (request->proxy && strcmp(request->url->scheme, "https")) - git_net_url_fmt(buf, request->url); - else - git_net_url_fmt_path(buf, request->url); - - git_str_puts(buf, " HTTP/1.1\r\n"); - - append_user_agent(buf); - - git_str_puts(buf, "Host: "); - puts_host_and_port(buf, request->url, false); - git_str_puts(buf, "\r\n"); - - if (request->accept) - git_str_printf(buf, "Accept: %s\r\n", request->accept); - else - git_str_puts(buf, "Accept: */*\r\n"); - - if (request->content_type) - git_str_printf(buf, "Content-Type: %s\r\n", - request->content_type); - - if (request->chunked) - git_str_puts(buf, "Transfer-Encoding: chunked\r\n"); - - if (request->content_length > 0) - git_str_printf(buf, "Content-Length: %"PRIuZ "\r\n", - request->content_length); - - if (request->expect_continue) - git_str_printf(buf, "Expect: 100-continue\r\n"); - - if ((error = apply_server_credentials(buf, client, request)) < 0 || - (!use_connect_proxy(client) && - (error = apply_proxy_credentials(buf, client, request)) < 0)) - return error; - - if (request->custom_headers) { - for (i = 0; i < request->custom_headers->count; i++) { - const char *hdr = request->custom_headers->strings[i]; - - if (hdr) - git_str_printf(buf, "%s\r\n", hdr); - } - } - - git_str_puts(buf, "\r\n"); - - if (git_str_oom(buf)) - return -1; - - return 0; -} - -static int check_certificate( - git_stream *stream, - git_net_url *url, - int is_valid, - git_transport_certificate_check_cb cert_cb, - void *cert_cb_payload) -{ - git_cert *cert; - git_error *last_error; - int error; - - if ((error = git_stream_certificate(&cert, stream)) < 0) - return error; - - /* - * Allow callers to set an error - but save ours and clear - * it, so that we can detect if they set one and restore it - * if we need to. - */ - git_error_save(&last_error); - git_error_clear(); - - error = cert_cb(cert, is_valid, url->host, cert_cb_payload); - - if (error == GIT_PASSTHROUGH) { - error = is_valid ? 0 : -1; - - if (error) { - git_error_restore(last_error); - last_error = NULL; - } - } else if (error) { - if (!git_error_exists()) - git_error_set(GIT_ERROR_HTTP, - "user rejected certificate for %s", - url->host); - } - - git_error_free(last_error); - return error; -} - -static int server_connect_stream( - git_http_server *server, - git_transport_certificate_check_cb cert_cb, - void *cb_payload) -{ - int error; - - GIT_ERROR_CHECK_VERSION(server->stream, GIT_STREAM_VERSION, "git_stream"); - - error = git_stream_connect(server->stream); - - if (error && error != GIT_ECERTIFICATE) - return error; - - if (git_stream_is_encrypted(server->stream) && cert_cb != NULL) - error = check_certificate(server->stream, &server->url, !error, - cert_cb, cb_payload); - - return error; -} - -static void reset_auth_connection(git_http_server *server) -{ - /* - * If we've authenticated and we're doing "normal" - * authentication with a request affinity (Basic, Digest) - * then we want to _keep_ our context, since authentication - * survives even through non-keep-alive connections. If - * we've authenticated and we're doing connection-based - * authentication (NTLM, Negotiate) - indicated by the presence - * of an `is_complete` callback - then we need to restart - * authentication on a new connection. - */ - - if (server->auth_context && - server->auth_context->connection_affinity) - free_auth_context(server); -} - -/* - * Updates the server data structure with the new URL; returns 1 if the server - * has changed and we need to reconnect, returns 0 otherwise. - */ -GIT_INLINE(int) server_setup_from_url( - git_http_server *server, - git_net_url *url) -{ - GIT_ASSERT_ARG(url); - GIT_ASSERT_ARG(url->scheme); - GIT_ASSERT_ARG(url->host); - GIT_ASSERT_ARG(url->port); - - if (!server->url.scheme || strcmp(server->url.scheme, url->scheme) || - !server->url.host || strcmp(server->url.host, url->host) || - !server->url.port || strcmp(server->url.port, url->port)) { - git__free(server->url.scheme); - git__free(server->url.host); - git__free(server->url.port); - - server->url.scheme = git__strdup(url->scheme); - GIT_ERROR_CHECK_ALLOC(server->url.scheme); - - server->url.host = git__strdup(url->host); - GIT_ERROR_CHECK_ALLOC(server->url.host); - - server->url.port = git__strdup(url->port); - GIT_ERROR_CHECK_ALLOC(server->url.port); - - return 1; - } - - return 0; -} - -static bool parser_settings_initialized; -static git_http_parser_settings parser_settings; - -GIT_INLINE(git_http_parser_settings *) http_client_parser_settings(void) -{ - if (!parser_settings_initialized) { - parser_settings.on_header_field = on_header_field; - parser_settings.on_header_value = on_header_value; - parser_settings.on_headers_complete = on_headers_complete; - parser_settings.on_body = on_body; - parser_settings.on_message_complete = on_message_complete; - - parser_settings_initialized = true; - } - - return &parser_settings; -} - -static void reset_parser(git_http_client *client) -{ - git_http_parser_init(&client->parser, - GIT_HTTP_PARSER_RESPONSE, - http_client_parser_settings()); -} - -static int setup_hosts( - git_http_client *client, - git_http_request *request) -{ - int ret, diff = 0; - - GIT_ASSERT_ARG(client); - GIT_ASSERT_ARG(request); - - GIT_ASSERT(request->url); - - if ((ret = server_setup_from_url(&client->server, request->url)) < 0) - return ret; - - diff |= ret; - - if (request->proxy && - (ret = server_setup_from_url(&client->proxy, request->proxy)) < 0) - return ret; - - diff |= ret; - - if (diff) { - free_auth_context(&client->server); - free_auth_context(&client->proxy); - - client->connected = 0; - } - - return 0; -} - -GIT_INLINE(int) server_create_stream(git_http_server *server) -{ - git_net_url *url = &server->url; - - if (strcasecmp(url->scheme, "https") == 0) - return git_tls_stream_new(&server->stream, url->host, url->port); - else if (strcasecmp(url->scheme, "http") == 0) - return git_socket_stream_new(&server->stream, url->host, url->port); - - git_error_set(GIT_ERROR_HTTP, "unknown http scheme '%s'", url->scheme); - return -1; -} - -GIT_INLINE(void) save_early_response( - git_http_client *client, - git_http_response *response) -{ - /* Buffer the response so we can return it in read_response */ - client->state = HAS_EARLY_RESPONSE; - - memcpy(&client->early_response, response, sizeof(git_http_response)); - memset(response, 0, sizeof(git_http_response)); -} - -static int proxy_connect( - git_http_client *client, - git_http_request *request) -{ - git_http_response response = {0}; - int error; - - if (!client->proxy_connected || !client->keepalive) { - git_trace(GIT_TRACE_DEBUG, "Connecting to proxy %s port %s", - client->proxy.url.host, client->proxy.url.port); - - if ((error = server_create_stream(&client->proxy)) < 0 || - (error = server_connect_stream(&client->proxy, - client->opts.proxy_certificate_check_cb, - client->opts.proxy_certificate_check_payload)) < 0) - goto done; - - client->proxy_connected = 1; - } - - client->current_server = PROXY; - client->state = SENDING_REQUEST; - - if ((error = generate_connect_request(client, request)) < 0 || - (error = client_write_request(client)) < 0) - goto done; - - client->state = SENT_REQUEST; - - if ((error = git_http_client_read_response(&response, client)) < 0 || - (error = git_http_client_skip_body(client)) < 0) - goto done; - - GIT_ASSERT(client->state == DONE); - - if (response.status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) { - save_early_response(client, &response); - - error = GIT_RETRY; - goto done; - } else if (response.status != GIT_HTTP_STATUS_OK) { - git_error_set(GIT_ERROR_HTTP, "proxy returned unexpected status: %d", response.status); - error = -1; - goto done; - } - - reset_parser(client); - client->state = NONE; - -done: - git_http_response_dispose(&response); - return error; -} - -static int server_connect(git_http_client *client) -{ - git_net_url *url = &client->server.url; - git_transport_certificate_check_cb cert_cb; - void *cert_payload; - int error; - - client->current_server = SERVER; - - if (client->proxy.stream) - error = git_tls_stream_wrap(&client->server.stream, client->proxy.stream, url->host); - else - error = server_create_stream(&client->server); - - if (error < 0) - goto done; - - cert_cb = client->opts.server_certificate_check_cb; - cert_payload = client->opts.server_certificate_check_payload; - - error = server_connect_stream(&client->server, cert_cb, cert_payload); - -done: - return error; -} - -GIT_INLINE(void) close_stream(git_http_server *server) -{ - if (server->stream) { - git_stream_close(server->stream); - git_stream_free(server->stream); - server->stream = NULL; - } -} - -static int http_client_connect( - git_http_client *client, - git_http_request *request) -{ - bool use_proxy = false; - int error; - - if ((error = setup_hosts(client, request)) < 0) - goto on_error; - - /* We're connected to our destination server; no need to reconnect */ - if (client->connected && client->keepalive && - (client->state == NONE || client->state == DONE)) - return 0; - - client->connected = 0; - client->request_count = 0; - - close_stream(&client->server); - reset_auth_connection(&client->server); - - reset_parser(client); - - /* Reconnect to the proxy if necessary. */ - use_proxy = use_connect_proxy(client); - - if (use_proxy) { - if (!client->proxy_connected || !client->keepalive || - (client->state != NONE && client->state != DONE)) { - close_stream(&client->proxy); - reset_auth_connection(&client->proxy); - - client->proxy_connected = 0; - } - - if ((error = proxy_connect(client, request)) < 0) - goto on_error; - } - - git_trace(GIT_TRACE_DEBUG, "Connecting to remote %s port %s", - client->server.url.host, client->server.url.port); - - if ((error = server_connect(client)) < 0) - goto on_error; - - client->connected = 1; - return error; - -on_error: - if (error != GIT_RETRY) - close_stream(&client->proxy); - - close_stream(&client->server); - return error; -} - -GIT_INLINE(int) client_read(git_http_client *client) -{ - http_parser_context *parser_context = client->parser.data; - git_stream *stream; - char *buf = client->read_buf.ptr + client->read_buf.size; - size_t max_len; - ssize_t read_len; - - stream = client->current_server == PROXY ? - client->proxy.stream : client->server.stream; - - /* - * We use a git_str for convenience, but statically allocate it and - * don't resize. Limit our consumption to INT_MAX since calling - * functions use an int return type to return number of bytes read. - */ - max_len = client->read_buf.asize - client->read_buf.size; - max_len = min(max_len, INT_MAX); - - if (parser_context->output_size) - max_len = min(max_len, parser_context->output_size); - - if (max_len == 0) { - git_error_set(GIT_ERROR_HTTP, "no room in output buffer"); - return -1; - } - - read_len = git_stream_read(stream, buf, max_len); - - if (read_len >= 0) { - client->read_buf.size += read_len; - - git_trace(GIT_TRACE_TRACE, "Received:\n%.*s", - (int)read_len, buf); - } - - return (int)read_len; -} - -GIT_INLINE(int) client_read_and_parse(git_http_client *client) -{ - git_http_parser *parser = &client->parser; - http_parser_context *ctx = (http_parser_context *) parser->data; - unsigned char http_errno; - int read_len; - size_t parsed_len; - - /* - * If we have data in our read buffer, that means we stopped early - * when parsing headers. Use the data in the read buffer instead of - * reading more from the socket. - */ - if (!client->read_buf.size && (read_len = client_read(client)) < 0) - return read_len; - - parsed_len = git_http_parser_execute(parser, - client->read_buf.ptr, - client->read_buf.size); - http_errno = git_http_parser_errno(parser); - - if (parsed_len > INT_MAX) { - git_error_set(GIT_ERROR_HTTP, "unexpectedly large parse"); - return -1; - } - - if (ctx->parse_status == PARSE_STATUS_ERROR) { - client->connected = 0; - return ctx->error ? ctx->error : -1; - } - - /* - * If we finished reading the headers or body, we paused parsing. - * Otherwise the parser will start filling the body, or even parse - * a new response if the server pipelined us multiple responses. - * (This can happen in response to an expect/continue request, - * where the server gives you a 100 and 200 simultaneously.) - */ - if (http_errno == GIT_HTTP_PARSER_PAUSED) { - size_t additional_size; - - git_http_parser_resume(parser); - - /* - * http-parser has a "feature" where it will not deliver - * the final byte when paused in a callback. Consume - * that byte. - */ - if ((additional_size = git_http_parser_remain_after_pause(parser)) > 0) { - GIT_ASSERT((client->read_buf.size - parsed_len) >= additional_size); - - parsed_len += git_http_parser_execute(parser, - client->read_buf.ptr + parsed_len, - additional_size); - } - } - - /* Most failures will be reported in http_errno */ - else if (git_http_parser_errno(parser) != GIT_HTTP_PARSER_OK) { - git_error_set(GIT_ERROR_HTTP, "http parser error: %s", - git_http_parser_errmsg(parser, http_errno)); - return -1; - } - - /* Otherwise we should have consumed the entire buffer. */ - else if (parsed_len != client->read_buf.size) { - git_error_set(GIT_ERROR_HTTP, - "http parser did not consume entire buffer: %s", - git_http_parser_errmsg(parser, http_errno)); - return -1; - } - - /* recv returned 0, the server hung up on us */ - else if (!parsed_len) { - git_error_set(GIT_ERROR_HTTP, "unexpected EOF"); - return -1; - } - - git_str_consume_bytes(&client->read_buf, parsed_len); - - return (int)parsed_len; -} - -/* - * Try to consume any remaining response body. The client may have - * decided that it did not need to consume the entire response body. - * For example, the client saw a redirect in the header and ignored - * the body. Or the client saw a particular sequence (like a final - * flush in a git response) and stopped reading (but there were - * additional response bytes, perhaps because the response was chunked). - * Do one more read to try to clear this out; this takes care of small - * remainders, like a chunk response or a small redirect message. If - * there is too much data, we'll just leave it and close the - * connection. - */ -static void complete_response_body(git_http_client *client) -{ - http_parser_context parser_context = {0}; - - /* If we're not keeping alive, don't bother. */ - if (!client->keepalive) { - client->connected = 0; - goto done; - } - - parser_context.client = client; - client->parser.data = &parser_context; - - /* If there was an error, just close the connection. */ - if (client_read_and_parse(client) < 0 || - parser_context.error != GIT_HTTP_PARSER_OK || - (parser_context.parse_status != PARSE_STATUS_OK && - parser_context.parse_status != PARSE_STATUS_NO_OUTPUT)) { - git_error_clear(); - client->connected = 0; - } - -done: - client->parser.data = NULL; - git_str_clear(&client->read_buf); -} - -int git_http_client_send_request( - git_http_client *client, - git_http_request *request) -{ - git_http_response response = {0}; - int error = -1; - - GIT_ASSERT_ARG(client); - GIT_ASSERT_ARG(request); - - /* If the client did not finish reading, clean up the stream. */ - if (client->state == READING_BODY) - complete_response_body(client); - - /* If we're waiting for proxy auth, don't sending more requests. */ - if (client->state == HAS_EARLY_RESPONSE) - return 0; - - if (git_trace_level() >= GIT_TRACE_DEBUG) { - git_str url = GIT_STR_INIT; - git_net_url_fmt(&url, request->url); - git_trace(GIT_TRACE_DEBUG, "Sending %s request to %s", - name_for_method(request->method), - url.ptr ? url.ptr : ""); - git_str_dispose(&url); - } - - if ((error = http_client_connect(client, request)) < 0 || - (error = generate_request(client, request)) < 0 || - (error = client_write_request(client)) < 0) - goto done; - - client->state = SENT_REQUEST; - - if (request->expect_continue) { - if ((error = git_http_client_read_response(&response, client)) < 0 || - (error = git_http_client_skip_body(client)) < 0) - goto done; - - error = 0; - - if (response.status != GIT_HTTP_STATUS_CONTINUE) { - save_early_response(client, &response); - goto done; - } - } - - if (request->content_length || request->chunked) { - client->state = SENDING_BODY; - client->request_body_len = request->content_length; - client->request_body_remain = request->content_length; - client->request_chunked = request->chunked; - } - - reset_parser(client); - -done: - if (error == GIT_RETRY) - error = 0; - - git_http_response_dispose(&response); - return error; -} - -bool git_http_client_has_response(git_http_client *client) -{ - return (client->state == HAS_EARLY_RESPONSE || - client->state > SENT_REQUEST); -} - -int git_http_client_send_body( - git_http_client *client, - const char *buffer, - size_t buffer_len) -{ - git_http_server *server; - git_str hdr = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(client); - - /* If we're waiting for proxy auth, don't sending more requests. */ - if (client->state == HAS_EARLY_RESPONSE) - return 0; - - if (client->state != SENDING_BODY) { - git_error_set(GIT_ERROR_HTTP, "client is in invalid state"); - return -1; - } - - if (!buffer_len) - return 0; - - server = &client->server; - - if (client->request_body_len) { - GIT_ASSERT(buffer_len <= client->request_body_remain); - - if ((error = stream_write(server, buffer, buffer_len)) < 0) - goto done; - - client->request_body_remain -= buffer_len; - } else { - if ((error = git_str_printf(&hdr, "%" PRIxZ "\r\n", buffer_len)) < 0 || - (error = stream_write(server, hdr.ptr, hdr.size)) < 0 || - (error = stream_write(server, buffer, buffer_len)) < 0 || - (error = stream_write(server, "\r\n", 2)) < 0) - goto done; - } - -done: - git_str_dispose(&hdr); - return error; -} - -static int complete_request(git_http_client *client) -{ - int error = 0; - - GIT_ASSERT_ARG(client); - GIT_ASSERT(client->state == SENDING_BODY); - - if (client->request_body_len && client->request_body_remain) { - git_error_set(GIT_ERROR_HTTP, "truncated write"); - error = -1; - } else if (client->request_chunked) { - error = stream_write(&client->server, "0\r\n\r\n", 5); - } - - client->state = SENT_REQUEST; - return error; -} - -int git_http_client_read_response( - git_http_response *response, - git_http_client *client) -{ - http_parser_context parser_context = {0}; - int error; - - GIT_ASSERT_ARG(response); - GIT_ASSERT_ARG(client); - - if (client->state == SENDING_BODY) { - if ((error = complete_request(client)) < 0) - goto done; - } - - if (client->state == HAS_EARLY_RESPONSE) { - memcpy(response, &client->early_response, sizeof(git_http_response)); - memset(&client->early_response, 0, sizeof(git_http_response)); - client->state = DONE; - return 0; - } - - if (client->state != SENT_REQUEST) { - git_error_set(GIT_ERROR_HTTP, "client is in invalid state"); - error = -1; - goto done; - } - - git_http_response_dispose(response); - - if (client->current_server == PROXY) { - git_vector_dispose_deep(&client->proxy.auth_challenges); - } else if(client->current_server == SERVER) { - git_vector_dispose_deep(&client->server.auth_challenges); - } - - client->state = READING_RESPONSE; - client->keepalive = 0; - client->parser.data = &parser_context; - - parser_context.client = client; - parser_context.response = response; - - while (client->state == READING_RESPONSE) { - if ((error = client_read_and_parse(client)) < 0) - goto done; - } - - GIT_ASSERT(client->state == READING_BODY || client->state == DONE); - -done: - git_str_dispose(&parser_context.parse_header_name); - git_str_dispose(&parser_context.parse_header_value); - client->parser.data = NULL; - - return error; -} - -int git_http_client_read_body( - git_http_client *client, - char *buffer, - size_t buffer_size) -{ - http_parser_context parser_context = {0}; - int error = 0; - - if (client->state == DONE) - return 0; - - if (client->state != READING_BODY) { - git_error_set(GIT_ERROR_HTTP, "client is in invalid state"); - return -1; - } - - /* - * Now we'll read from the socket and http_parser will pipeline the - * data directly to the client. - */ - - parser_context.client = client; - parser_context.output_buf = buffer; - parser_context.output_size = buffer_size; - - client->parser.data = &parser_context; - - /* - * Clients expect to get a non-zero amount of data from us, - * so we either block until we have data to return, until we - * hit EOF or there's an error. Do this in a loop, since we - * may end up reading only some stream metadata (like chunk - * information). - */ - while (!parser_context.output_written) { - error = client_read_and_parse(client); - - if (error <= 0) - goto done; - - if (client->state == DONE) - break; - } - - GIT_ASSERT(parser_context.output_written <= INT_MAX); - error = (int)parser_context.output_written; - -done: - if (error < 0) - client->connected = 0; - - client->parser.data = NULL; - - return error; -} - -int git_http_client_skip_body(git_http_client *client) -{ - http_parser_context parser_context = {0}; - int error; - - if (client->state == DONE) - return 0; - - if (client->state != READING_BODY) { - git_error_set(GIT_ERROR_HTTP, "client is in invalid state"); - return -1; - } - - parser_context.client = client; - client->parser.data = &parser_context; - - do { - error = client_read_and_parse(client); - - if (parser_context.error != GIT_HTTP_PARSER_OK || - (parser_context.parse_status != PARSE_STATUS_OK && - parser_context.parse_status != PARSE_STATUS_NO_OUTPUT)) { - git_error_set(GIT_ERROR_HTTP, - "unexpected data handled in callback"); - error = -1; - } - } while (error >= 0 && client->state != DONE); - - if (error < 0) - client->connected = 0; - - client->parser.data = NULL; - - return error; -} - -/* - * Create an http_client capable of communicating with the given remote - * host. - */ -int git_http_client_new( - git_http_client **out, - git_http_client_options *opts) -{ - git_http_client *client; - - GIT_ASSERT_ARG(out); - - client = git__calloc(1, sizeof(git_http_client)); - GIT_ERROR_CHECK_ALLOC(client); - - git_str_init(&client->read_buf, GIT_READ_BUFFER_SIZE); - GIT_ERROR_CHECK_ALLOC(client->read_buf.ptr); - - if (opts) - memcpy(&client->opts, opts, sizeof(git_http_client_options)); - - *out = client; - return 0; -} - -/* Update the options of an existing httpclient instance. */ -void git_http_client_set_options( - git_http_client *client, - git_http_client_options *opts) -{ - if (opts) - memcpy(&client->opts, opts, sizeof(git_http_client_options)); -} - -GIT_INLINE(void) http_server_close(git_http_server *server) -{ - if (server->stream) { - git_stream_close(server->stream); - git_stream_free(server->stream); - server->stream = NULL; - } - - git_net_url_dispose(&server->url); - - git_vector_dispose_deep(&server->auth_challenges); - free_auth_context(server); -} - -static void http_client_close(git_http_client *client) -{ - http_server_close(&client->server); - http_server_close(&client->proxy); - - git_str_dispose(&client->request_msg); - - client->state = 0; - client->request_count = 0; - client->connected = 0; - client->keepalive = 0; -} - -void git_http_client_free(git_http_client *client) -{ - if (!client) - return; - - http_client_close(client); - git_str_dispose(&client->read_buf); - git__free(client); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpclient.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpclient.h deleted file mode 100644 index 22c4dd0..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpclient.h +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_transports_httpclient_h__ -#define INCLUDE_transports_httpclient_h__ - -#include "common.h" -#include "net.h" - -#define GIT_HTTP_STATUS_CONTINUE 100 -#define GIT_HTTP_STATUS_OK 200 -#define GIT_HTTP_MOVED_PERMANENTLY 301 -#define GIT_HTTP_FOUND 302 -#define GIT_HTTP_SEE_OTHER 303 -#define GIT_HTTP_TEMPORARY_REDIRECT 307 -#define GIT_HTTP_PERMANENT_REDIRECT 308 -#define GIT_HTTP_STATUS_UNAUTHORIZED 401 -#define GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED 407 - -typedef struct git_http_client git_http_client; - -/** Method for the HTTP request */ -typedef enum { - GIT_HTTP_METHOD_GET, - GIT_HTTP_METHOD_POST, - GIT_HTTP_METHOD_CONNECT -} git_http_method; - -/** An HTTP request */ -typedef struct { - git_http_method method; /**< Method for the request */ - git_net_url *url; /**< Full request URL */ - git_net_url *proxy; /**< Proxy to use */ - - /* Headers */ - const char *accept; /**< Contents of the Accept header */ - const char *content_type; /**< Content-Type header (for POST) */ - git_credential *credentials; /**< Credentials to authenticate with */ - git_credential *proxy_credentials; /**< Credentials for proxy */ - git_strarray *custom_headers; /**< Additional headers to deliver */ - - /* To POST a payload, either set content_length OR set chunked. */ - size_t content_length; /**< Length of the POST body */ - unsigned chunked : 1, /**< Post with chunking */ - expect_continue : 1; /**< Use expect/continue negotiation */ -} git_http_request; - -typedef struct { - int status; - - /* Headers */ - char *content_type; - size_t content_length; - char *location; - - /* Authentication headers */ - unsigned server_auth_schemetypes; /**< Schemes requested by remote */ - unsigned server_auth_credtypes; /**< Supported cred types for remote */ - - unsigned proxy_auth_schemetypes; /**< Schemes requested by proxy */ - unsigned proxy_auth_credtypes; /**< Supported cred types for proxy */ - - unsigned chunked : 1, /**< Response body is chunked */ - resend_credentials : 1; /**< Resend with authentication */ -} git_http_response; - -typedef struct { - /** Certificate check callback for the remote */ - git_transport_certificate_check_cb server_certificate_check_cb; - void *server_certificate_check_payload; - - /** Certificate check callback for the proxy */ - git_transport_certificate_check_cb proxy_certificate_check_cb; - void *proxy_certificate_check_payload; -} git_http_client_options; - -/** - * Create a new httpclient instance with the given options. - * - * @param out pointer to receive the new instance - * @param opts options to create the client with or NULL for defaults - */ -extern int git_http_client_new( - git_http_client **out, - git_http_client_options *opts); - -/** - * Update the options of an existing httpclient instance. - * - * @param client the httpclient instance to modify - * @param opts new options or NULL to keep existing options - */ -extern void git_http_client_set_options( - git_http_client *client, - git_http_client_options *opts); - -/* - * Sends a request to the host specified by the request URL. If the - * method is POST, either the content_length or the chunked flag must - * be specified. The body should be provided in subsequent calls to - * git_http_client_send_body. - * - * @param client the client to write the request to - * @param request the request to send - */ -extern int git_http_client_send_request( - git_http_client *client, - git_http_request *request); - -/* - * After sending a request, there may already be a response to read -- - * either because there was a non-continue response to an expect: continue - * request, or because the server pipelined a response to us before we even - * sent the request. Examine the state. - * - * @param client the client to examine - * @return true if there's already a response to read, false otherwise - */ -extern bool git_http_client_has_response(git_http_client *client); - -/** - * Sends the given buffer to the remote as part of the request body. The - * request must have specified either a content_length or the chunked flag. - * - * @param client the client to write the request body to - * @param buffer the request body - * @param buffer_len number of bytes of the buffer to send - */ -extern int git_http_client_send_body( - git_http_client *client, - const char *buffer, - size_t buffer_len); - -/** - * Reads the headers of a response to a request. This will consume the - * entirety of the headers of a response from the server. The body (if any) - * can be read by calling git_http_client_read_body. Callers must free - * the response with git_http_response_dispose. - * - * @param response pointer to the response object to fill - * @param client the client to read the response from - */ -extern int git_http_client_read_response( - git_http_response *response, - git_http_client *client); - -/** - * Reads some or all of the body of a response. At most buffer_size (or - * INT_MAX) bytes will be read and placed into the buffer provided. The - * number of bytes read will be returned, or 0 to indicate that the end of - * the body has been read. - * - * @param client the client to read the response from - * @param buffer pointer to the buffer to fill - * @param buffer_size the maximum number of bytes to read - * @return the number of bytes read, 0 on end of body, or error code - */ -extern int git_http_client_read_body( - git_http_client *client, - char *buffer, - size_t buffer_size); - -/** - * Reads all of the (remainder of the) body of the response and ignores it. - * None of the data from the body will be returned to the caller. - * - * @param client the client to read the response from - * @return 0 or an error code - */ -extern int git_http_client_skip_body(git_http_client *client); - -/** - * Examines the status code of the response to determine if it is a - * redirect of any type (eg, 301, 302, etc). - * - * @param response the response to inspect - * @return true if the response is a redirect, false otherwise - */ -extern bool git_http_response_is_redirect(git_http_response *response); - -/** - * Frees any memory associated with the response. - * - * @param response the response to free - */ -extern void git_http_response_dispose(git_http_response *response); - -/** - * Frees any memory associated with the client. If any sockets are open, - * they will be closed. - * - * @param client the client to free - */ -extern void git_http_client_free(git_http_client *client); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpparser.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpparser.c deleted file mode 100644 index 84833e6..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpparser.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "httpparser.h" - -#include - -#if defined(GIT_HTTPPARSER_HTTPPARSER) - -#include "http_parser.h" - -static int on_message_begin(http_parser *p) -{ - git_http_parser *parser = (git_http_parser *)p; - return parser->settings.on_message_begin(parser); -} - -static int on_url(http_parser *p, const char *str, size_t len) -{ - git_http_parser *parser = (git_http_parser *)p; - return parser->settings.on_url(parser, str, len); -} - -static int on_header_field(http_parser *p, const char *str, size_t len) -{ - git_http_parser *parser = (git_http_parser *)p; - return parser->settings.on_header_field(parser, str, len); -} - -static int on_header_value(http_parser *p, const char *str, size_t len) -{ - git_http_parser *parser = (git_http_parser *)p; - return parser->settings.on_header_value(parser, str, len); -} - -static int on_headers_complete(http_parser *p) -{ - git_http_parser *parser = (git_http_parser *)p; - return parser->settings.on_headers_complete(parser); -} - -static int on_body(http_parser *p, const char *buf, size_t len) -{ - git_http_parser *parser = (git_http_parser *)p; - return parser->settings.on_body(parser, buf, len); -} - -static int on_message_complete(http_parser *p) -{ - git_http_parser *parser = (git_http_parser *)p; - return parser->settings.on_message_complete(parser); -} - -void git_http_parser_init( - git_http_parser *parser, - git_http_parser_t type, - git_http_parser_settings *settings) -{ - http_parser_init(&parser->parser, (enum http_parser_type)type); - memcpy(&parser->settings, settings, sizeof(git_http_parser_settings)); -} - -size_t git_http_parser_execute( - git_http_parser *parser, - const char *data, - size_t len) -{ - struct http_parser_settings settings_proxy; - - memset(&settings_proxy, 0, sizeof(struct http_parser_settings)); - - settings_proxy.on_message_begin = parser->settings.on_message_begin ? on_message_begin : NULL; - settings_proxy.on_url = parser->settings.on_url ? on_url : NULL; - settings_proxy.on_header_field = parser->settings.on_header_field ? on_header_field : NULL; - settings_proxy.on_header_value = parser->settings.on_header_value ? on_header_value : NULL; - settings_proxy.on_headers_complete = parser->settings.on_headers_complete ? on_headers_complete : NULL; - settings_proxy.on_body = parser->settings.on_body ? on_body : NULL; - settings_proxy.on_message_complete = parser->settings.on_message_complete ? on_message_complete : NULL; - - return http_parser_execute(&parser->parser, &settings_proxy, data, len); -} - -#elif defined(GIT_HTTPPARSER_LLHTTP) || defined(GIT_HTTPPARSER_BUILTIN) - -# include - -size_t git_http_parser_execute( - git_http_parser *parser, - const char* data, - size_t len) -{ - llhttp_errno_t error; - size_t parsed_len; - - /* - * Unlike http_parser, which returns the number of parsed - * bytes in the _execute() call, llhttp returns an error - * code. - */ - - if (data == NULL || len == 0) - error = llhttp_finish(parser); - else - error = llhttp_execute(parser, data, len); - - parsed_len = len; - - /* - * Adjust number of parsed bytes in case of error. - */ - if (error != HPE_OK) { - parsed_len = llhttp_get_error_pos(parser) - data; - - /* This isn't a real pause, just a way to stop parsing early. */ - if (error == HPE_PAUSED_UPGRADE) - llhttp_resume_after_upgrade(parser); - } - - return parsed_len; -} - -#else -# error unknown http-parser -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpparser.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpparser.h deleted file mode 100644 index 1fe0dcf..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/httpparser.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_transports_httpparser_h__ -#define INCLUDE_transports_httpparser_h__ - -#include "git2_util.h" - -#if defined(GIT_HTTPPARSER_HTTPPARSER) - -# include - -typedef enum { - GIT_HTTP_PARSER_OK = HPE_OK, - GIT_HTTP_PARSER_PAUSED = HPE_PAUSED, -} git_http_parser_error_t; - -typedef enum { - GIT_HTTP_PARSER_REQUEST = HTTP_REQUEST, - GIT_HTTP_PARSER_RESPONSE = HTTP_RESPONSE, -} git_http_parser_t; - -typedef struct git_http_parser git_http_parser; - -typedef struct { - int (*on_message_begin)(git_http_parser *); - int (*on_url)(git_http_parser *, const char *, size_t); - int (*on_header_field)(git_http_parser *, const char *, size_t); - int (*on_header_value)(git_http_parser *, const char *, size_t); - int (*on_headers_complete)(git_http_parser *); - int (*on_body)(git_http_parser *, const char *, size_t); - int (*on_message_complete)(git_http_parser *); -} git_http_parser_settings; - -struct git_http_parser { - http_parser parser; - git_http_parser_settings settings; - void *data; -}; - -void git_http_parser_init( - git_http_parser *parser, - git_http_parser_t type, - git_http_parser_settings *settings); - -size_t git_http_parser_execute( - git_http_parser *parser, - const char *data, - size_t len); - -# define git_http_parser_status_code(parser) parser->parser.status_code -# define git_http_parser_keep_alive(parser) http_should_keep_alive(&parser->parser) -# define git_http_parser_pause(parser) (http_parser_pause(&parser->parser, 1), 0) -# define git_http_parser_resume(parser) http_parser_pause(&parser->parser, 0) -# define git_http_parser_remain_after_pause(parser) 1 -# define git_http_parser_errno(parser) parser->parser.http_errno -# define git_http_parser_errmsg(parser, errno) http_errno_description(errno) - -#elif defined(GIT_HTTPPARSER_LLHTTP) || defined(GIT_HTTPPARSER_BUILTIN) - -# include - -typedef enum { - GIT_HTTP_PARSER_OK = HPE_OK, - GIT_HTTP_PARSER_PAUSED = HPE_PAUSED, -} git_http_parser_error_t; - -typedef enum { - GIT_HTTP_PARSER_REQUEST = HTTP_REQUEST, - GIT_HTTP_PARSER_RESPONSE = HTTP_RESPONSE, -} git_http_parser_t; - -typedef llhttp_t git_http_parser; -typedef llhttp_settings_t git_http_parser_settings; - -# define git_http_parser_init(parser, direction, settings) llhttp_init(parser, (llhttp_type_t)direction, settings) - -size_t git_http_parser_execute( - git_http_parser *parser, - const char *data, - size_t len); - -# define git_http_parser_status_code(parser) parser->status_code -# define git_http_parser_keep_alive(parser) llhttp_should_keep_alive(parser) -# define git_http_parser_pause(parser) (llhttp_pause(parser), GIT_HTTP_PARSER_PAUSED) -# define git_http_parser_resume(parser) llhttp_resume(parser) -# define git_http_parser_remain_after_pause(parser) 0 -# define git_http_parser_errno(parser) parser->error -# define git_http_parser_errmsg(parser, errno) llhttp_get_error_reason(parser) - -#else -# error unknown http-parser -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/local.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/local.c deleted file mode 100644 index 1220b4f..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/local.c +++ /dev/null @@ -1,785 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "pack-objects.h" -#include "refs.h" -#include "posix.h" -#include "fs_path.h" -#include "repository.h" -#include "odb.h" -#include "push.h" -#include "remote.h" -#include "proxy.h" - -#include "git2/types.h" -#include "git2/net.h" -#include "git2/repository.h" -#include "git2/object.h" -#include "git2/tag.h" -#include "git2/transport.h" -#include "git2/revwalk.h" -#include "git2/odb_backend.h" -#include "git2/pack.h" -#include "git2/commit.h" -#include "git2/revparse.h" -#include "git2/sys/remote.h" - -typedef struct { - git_transport parent; - git_remote *owner; - char *url; - int direction; - git_atomic32 cancelled; - git_repository *repo; - git_remote_connect_options connect_opts; - git_vector refs; - unsigned connected : 1, - have_refs : 1; -#ifdef GIT_EXPERIMENTAL_SHA256 - git_oid_t oid_type; -#endif -} transport_local; - -static void free_head(git_remote_head *head) -{ - git__free(head->name); - git__free(head->symref_target); - git__free(head); -} - -static void free_heads(git_vector *heads) -{ - git_remote_head *head; - size_t i; - - git_vector_foreach(heads, i, head) - free_head(head); - - git_vector_dispose(heads); -} - -static int add_ref(transport_local *t, const char *name) -{ - const char peeled[] = "^{}"; - git_reference *ref, *resolved; - git_remote_head *head; - git_oid obj_id; - git_object *obj = NULL, *target = NULL; - git_str buf = GIT_STR_INIT; - int error; - - if ((error = git_reference_lookup(&ref, t->repo, name)) < 0) - return error; - - error = git_reference_resolve(&resolved, ref); - if (error < 0) { - git_reference_free(ref); - if (!strcmp(name, GIT_HEAD_FILE) && error == GIT_ENOTFOUND) { - /* This is actually okay. Empty repos often have a HEAD that - * points to a nonexistent "refs/heads/master". */ - git_error_clear(); - return 0; - } - return error; - } - - git_oid_cpy(&obj_id, git_reference_target(resolved)); - git_reference_free(resolved); - - head = git__calloc(1, sizeof(git_remote_head)); - GIT_ERROR_CHECK_ALLOC(head); - - head->name = git__strdup(name); - GIT_ERROR_CHECK_ALLOC(head->name); - - git_oid_cpy(&head->oid, &obj_id); - - if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) { - head->symref_target = git__strdup(git_reference_symbolic_target(ref)); - GIT_ERROR_CHECK_ALLOC(head->symref_target); - } - git_reference_free(ref); - - if ((error = git_vector_insert(&t->refs, head)) < 0) { - free_head(head); - return error; - } - - if ((error = git_object_lookup(&obj, t->repo, &head->oid, GIT_OBJECT_ANY)) < 0) - return error; - - head = NULL; - - /* If it's not an annotated tag, or if we're mocking - * git-receive-pack, just get out */ - if (git_object_type(obj) != GIT_OBJECT_TAG || - t->direction != GIT_DIRECTION_FETCH) { - git_object_free(obj); - return 0; - } - - /* And if it's a tag, peel it, and add it to the list */ - head = git__calloc(1, sizeof(git_remote_head)); - GIT_ERROR_CHECK_ALLOC(head); - - if (git_str_join(&buf, 0, name, peeled) < 0) { - free_head(head); - return -1; - } - head->name = git_str_detach(&buf); - - if (!(error = git_tag_peel(&target, (git_tag *)obj))) { - git_oid_cpy(&head->oid, git_object_id(target)); - - if ((error = git_vector_insert(&t->refs, head)) < 0) { - free_head(head); - } - } - - git_object_free(obj); - git_object_free(target); - - return error; -} - -static int store_refs(transport_local *t) -{ - size_t i; - git_remote_head *head; - git_strarray ref_names = {0}; - - GIT_ASSERT_ARG(t); - - if (git_reference_list(&ref_names, t->repo) < 0) - goto on_error; - - /* Clear all heads we might have fetched in a previous connect */ - git_vector_foreach(&t->refs, i, head) { - git__free(head->name); - git__free(head); - } - - /* Clear the vector so we can reuse it */ - git_vector_clear(&t->refs); - - /* Sort the references first */ - git__tsort((void **)ref_names.strings, ref_names.count, &git__strcmp_cb); - - /* Add HEAD iff direction is fetch */ - if (t->direction == GIT_DIRECTION_FETCH && add_ref(t, GIT_HEAD_FILE) < 0) - goto on_error; - - for (i = 0; i < ref_names.count; ++i) { - if (add_ref(t, ref_names.strings[i]) < 0) - goto on_error; - } - - t->have_refs = 1; - git_strarray_dispose(&ref_names); - return 0; - -on_error: - git_vector_dispose(&t->refs); - git_strarray_dispose(&ref_names); - return -1; -} - -/* - * Try to open the url as a git directory. The direction doesn't - * matter in this case because we're calculating the heads ourselves. - */ -static int local_connect( - git_transport *transport, - const char *url, - int direction, - const git_remote_connect_options *connect_opts) -{ - git_repository *repo; - int error; - transport_local *t = (transport_local *)transport; - const char *path; - git_str buf = GIT_STR_INIT; - - if (t->connected) - return 0; - - if (git_remote_connect_options_normalize(&t->connect_opts, t->owner->repo, connect_opts) < 0) - return -1; - - free_heads(&t->refs); - - t->url = git__strdup(url); - GIT_ERROR_CHECK_ALLOC(t->url); - t->direction = direction; - - /* 'url' may be a url or path; convert to a path */ - if ((error = git_fs_path_from_url_or_path(&buf, url)) < 0) { - git_str_dispose(&buf); - return error; - } - path = git_str_cstr(&buf); - - error = git_repository_open(&repo, path); - - git_str_dispose(&buf); - - if (error < 0) - return -1; - - t->repo = repo; - -#ifdef GIT_EXPERIMENTAL_SHA256 - t->oid_type = repo->oid_type; -#endif - - if (store_refs(t) < 0) - return -1; - - t->connected = 1; - - return 0; -} - -static int local_set_connect_opts( - git_transport *transport, - const git_remote_connect_options *connect_opts) -{ - transport_local *t = (transport_local *)transport; - - if (!t->connected) { - git_error_set(GIT_ERROR_NET, "cannot reconfigure a transport that is not connected"); - return -1; - } - - return git_remote_connect_options_normalize(&t->connect_opts, t->owner->repo, connect_opts); -} - -static int local_capabilities(unsigned int *capabilities, git_transport *transport) -{ - GIT_UNUSED(transport); - - *capabilities = GIT_REMOTE_CAPABILITY_TIP_OID | - GIT_REMOTE_CAPABILITY_REACHABLE_OID; - return 0; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -static int local_oid_type(git_oid_t *out, git_transport *transport) -{ - transport_local *t = (transport_local *)transport; - - *out = t->oid_type; - - return 0; -} -#endif - -static int local_ls(const git_remote_head ***out, size_t *size, git_transport *transport) -{ - transport_local *t = (transport_local *)transport; - - if (!t->have_refs) { - git_error_set(GIT_ERROR_NET, "the transport has not yet loaded the refs"); - return -1; - } - - *out = (const git_remote_head **)t->refs.contents; - *size = t->refs.length; - - return 0; -} - -static int local_negotiate_fetch( - git_transport *transport, - git_repository *repo, - const git_fetch_negotiation *wants) -{ - transport_local *t = (transport_local*)transport; - git_remote_head *rhead; - unsigned int i; - - GIT_UNUSED(wants); - - if (wants->depth) { - git_error_set(GIT_ERROR_NET, "shallow fetch is not supported by the local transport"); - return GIT_ENOTSUPPORTED; - } - - /* Fill in the loids */ - git_vector_foreach(&t->refs, i, rhead) { - git_object *obj; - - int error = git_revparse_single(&obj, repo, rhead->name); - if (!error) - git_oid_cpy(&rhead->loid, git_object_id(obj)); - else if (error != GIT_ENOTFOUND) - return error; - else - git_error_clear(); - git_object_free(obj); - } - - return 0; -} - -static int local_shallow_roots( - git_oidarray *out, - git_transport *transport) -{ - GIT_UNUSED(out); - GIT_UNUSED(transport); - - return 0; -} - -static int local_push_update_remote_ref( - git_repository *remote_repo, - const char *lref, - const char *rref, - git_oid *loid, - git_oid *roid) -{ - int error; - git_reference *remote_ref = NULL; - - /* check for lhs, if it's empty it means to delete */ - if (lref[0] != '\0') { - /* Create or update a ref */ - error = git_reference_create(NULL, remote_repo, rref, loid, - !git_oid_is_zero(roid), NULL); - } else { - /* Delete a ref */ - if ((error = git_reference_lookup(&remote_ref, remote_repo, rref)) < 0) { - if (error == GIT_ENOTFOUND) - error = 0; - return error; - } - - error = git_reference_delete(remote_ref); - git_reference_free(remote_ref); - } - - return error; -} - -static int transfer_to_push_transfer(const git_indexer_progress *stats, void *payload) -{ - const git_remote_callbacks *cbs = payload; - - if (!cbs || !cbs->push_transfer_progress) - return 0; - - return cbs->push_transfer_progress(stats->received_objects, stats->total_objects, stats->received_bytes, - cbs->payload); -} - -static int local_push( - git_transport *transport, - git_push *push) -{ - transport_local *t = (transport_local *)transport; - git_remote_callbacks *cbs = &t->connect_opts.callbacks; - git_repository *remote_repo = NULL; - push_spec *spec; - char *url = NULL; - const char *path; - git_str buf = GIT_STR_INIT, odb_path = GIT_STR_INIT; - int error; - size_t j; - - /* 'push->remote->url' may be a url or path; convert to a path */ - if ((error = git_fs_path_from_url_or_path(&buf, push->remote->url)) < 0) { - git_str_dispose(&buf); - return error; - } - path = git_str_cstr(&buf); - - error = git_repository_open(&remote_repo, path); - - git_str_dispose(&buf); - - if (error < 0) - return error; - - /* We don't currently support pushing locally to non-bare repos. Proper - non-bare repo push support would require checking configs to see if - we should override the default 'don't let this happen' behavior. - - Note that this is only an issue when pushing to the current branch, - but we forbid all pushes just in case */ - if (!remote_repo->is_bare) { - error = GIT_EBAREREPO; - git_error_set(GIT_ERROR_INVALID, "local push doesn't (yet) support pushing to non-bare repos."); - goto on_error; - } - - if ((error = git_repository__item_path(&odb_path, remote_repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0 - || (error = git_str_joinpath(&odb_path, odb_path.ptr, "pack")) < 0) - goto on_error; - - error = git_packbuilder_write(push->pb, odb_path.ptr, 0, transfer_to_push_transfer, (void *) cbs); - git_str_dispose(&odb_path); - - if (error < 0) - goto on_error; - - push->unpack_ok = 1; - - git_vector_foreach(&push->specs, j, spec) { - push_status *status; - const git_error *last; - char *ref = spec->refspec.dst; - - status = git__calloc(1, sizeof(push_status)); - if (!status) - goto on_error; - - status->ref = git__strdup(ref); - if (!status->ref) { - git_push_status_free(status); - goto on_error; - } - - error = local_push_update_remote_ref(remote_repo, spec->refspec.src, spec->refspec.dst, - &spec->loid, &spec->roid); - - switch (error) { - case GIT_OK: - break; - case GIT_EINVALIDSPEC: - status->msg = git__strdup("funny refname"); - break; - case GIT_ENOTFOUND: - status->msg = git__strdup("Remote branch not found to delete"); - break; - default: - last = git_error_last(); - - if (last->klass != GIT_ERROR_NONE) - status->msg = git__strdup(last->message); - else - status->msg = git__strdup("Unspecified error encountered"); - break; - } - - /* failed to allocate memory for a status message */ - if (error < 0 && !status->msg) { - git_push_status_free(status); - goto on_error; - } - - /* failed to insert the ref update status */ - if ((error = git_vector_insert(&push->status, status)) < 0) { - git_push_status_free(status); - goto on_error; - } - } - - if (push->specs.length) { - url = git__strdup(t->url); - - if (!url || t->parent.close(&t->parent) < 0 || - t->parent.connect(&t->parent, url, - GIT_DIRECTION_PUSH, NULL)) - goto on_error; - } - - error = 0; - -on_error: - git_repository_free(remote_repo); - git__free(url); - - return error; -} - -typedef struct foreach_data { - git_indexer_progress *stats; - git_indexer_progress_cb progress_cb; - void *progress_payload; - git_odb_writepack *writepack; -} foreach_data; - -static int foreach_cb(void *buf, size_t len, void *payload) -{ - foreach_data *data = (foreach_data*)payload; - - data->stats->received_bytes += len; - return data->writepack->append(data->writepack, buf, len, data->stats); -} - -static const char *counting_objects_fmt = "Counting objects %d\r"; -static const char *compressing_objects_fmt = "Compressing objects: %.0f%% (%d/%d)"; - -static int local_counting(int stage, unsigned int current, unsigned int total, void *payload) -{ - git_str progress_info = GIT_STR_INIT; - transport_local *t = payload; - int error; - - if (!t->connect_opts.callbacks.sideband_progress) - return 0; - - if (stage == GIT_PACKBUILDER_ADDING_OBJECTS) { - git_str_printf(&progress_info, counting_objects_fmt, current); - } else if (stage == GIT_PACKBUILDER_DELTAFICATION) { - float perc = (((float) current) / total) * 100; - git_str_printf(&progress_info, compressing_objects_fmt, perc, current, total); - if (current == total) - git_str_printf(&progress_info, ", done\n"); - else - git_str_putc(&progress_info, '\r'); - - } - - if (git_str_oom(&progress_info)) - return -1; - - if (progress_info.size > INT_MAX) { - git_error_set(GIT_ERROR_NET, "remote sent overly large progress data"); - git_str_dispose(&progress_info); - return -1; - } - - - error = t->connect_opts.callbacks.sideband_progress( - progress_info.ptr, - (int)progress_info.size, - t->connect_opts.callbacks.payload); - - git_str_dispose(&progress_info); - return error; -} - -static int foreach_reference_cb(git_reference *reference, void *payload) -{ - git_revwalk *walk = (git_revwalk *)payload; - int error; - - if (git_reference_type(reference) != GIT_REFERENCE_DIRECT) { - git_reference_free(reference); - return 0; - } - - error = git_revwalk_hide(walk, git_reference_target(reference)); - /* The reference is in the local repository, so the target may not - * exist on the remote. It also may not be a commit. */ - if (error == GIT_ENOTFOUND || error == GIT_ERROR_INVALID) { - git_error_clear(); - error = 0; - } - - git_reference_free(reference); - - return error; -} - -static int local_download_pack( - git_transport *transport, - git_repository *repo, - git_indexer_progress *stats) -{ - transport_local *t = (transport_local*)transport; - git_revwalk *walk = NULL; - git_remote_head *rhead; - unsigned int i; - int error = -1; - git_packbuilder *pack = NULL; - git_odb_writepack *writepack = NULL; - git_odb *odb = NULL; - git_str progress_info = GIT_STR_INIT; - foreach_data data = {0}; - - if ((error = git_revwalk_new(&walk, t->repo)) < 0) - goto cleanup; - - git_revwalk_sorting(walk, GIT_SORT_TIME); - - if ((error = git_packbuilder_new(&pack, t->repo)) < 0) - goto cleanup; - - git_packbuilder_set_callbacks(pack, local_counting, t); - - stats->total_objects = 0; - stats->indexed_objects = 0; - stats->received_objects = 0; - stats->received_bytes = 0; - - git_vector_foreach(&t->refs, i, rhead) { - git_object *obj; - if ((error = git_object_lookup(&obj, t->repo, &rhead->oid, GIT_OBJECT_ANY)) < 0) - goto cleanup; - - if (git_object_type(obj) == GIT_OBJECT_COMMIT) { - /* Revwalker includes only wanted commits */ - error = git_revwalk_push(walk, &rhead->oid); - } else { - /* Tag or some other wanted object. Add it on its own */ - error = git_packbuilder_insert_recur(pack, &rhead->oid, rhead->name); - } - git_object_free(obj); - if (error < 0) - goto cleanup; - } - - if ((error = git_reference_foreach(repo, foreach_reference_cb, walk))) - goto cleanup; - - if ((error = git_packbuilder_insert_walk(pack, walk))) - goto cleanup; - - if (t->connect_opts.callbacks.sideband_progress) { - if ((error = git_str_printf( - &progress_info, - counting_objects_fmt, - git_packbuilder_object_count(pack))) < 0 || - (error = t->connect_opts.callbacks.sideband_progress( - progress_info.ptr, - (int)progress_info.size, - t->connect_opts.callbacks.payload)) < 0) - goto cleanup; - } - - /* Walk the objects, building a packfile */ - if ((error = git_repository_odb__weakptr(&odb, repo)) < 0) - goto cleanup; - - /* One last one with the newline */ - if (t->connect_opts.callbacks.sideband_progress) { - git_str_clear(&progress_info); - - if ((error = git_str_printf( - &progress_info, - counting_objects_fmt, - git_packbuilder_object_count(pack))) < 0 || - (error = git_str_putc(&progress_info, '\n')) < 0 || - (error = t->connect_opts.callbacks.sideband_progress( - progress_info.ptr, - (int)progress_info.size, - t->connect_opts.callbacks.payload)) < 0) - goto cleanup; - } - - if ((error = git_odb_write_pack( - &writepack, - odb, - t->connect_opts.callbacks.transfer_progress, - t->connect_opts.callbacks.payload)) < 0) - goto cleanup; - - /* Write the data to the ODB */ - data.stats = stats; - data.progress_cb = t->connect_opts.callbacks.transfer_progress; - data.progress_payload = t->connect_opts.callbacks.payload; - data.writepack = writepack; - - /* autodetect */ - git_packbuilder_set_threads(pack, 0); - - if ((error = git_packbuilder_foreach(pack, foreach_cb, &data)) != 0) - goto cleanup; - - error = writepack->commit(writepack, stats); - -cleanup: - if (writepack) writepack->free(writepack); - git_str_dispose(&progress_info); - git_packbuilder_free(pack); - git_revwalk_free(walk); - return error; -} - -static int local_is_connected(git_transport *transport) -{ - transport_local *t = (transport_local *)transport; - - return t->connected; -} - -static void local_cancel(git_transport *transport) -{ - transport_local *t = (transport_local *)transport; - - git_atomic32_set(&t->cancelled, 1); -} - -static int local_close(git_transport *transport) -{ - transport_local *t = (transport_local *)transport; - - t->connected = 0; - - if (t->repo) { - git_repository_free(t->repo); - t->repo = NULL; - } - - if (t->url) { - git__free(t->url); - t->url = NULL; - } - - return 0; -} - -static void local_free(git_transport *transport) -{ - transport_local *t = (transport_local *)transport; - - free_heads(&t->refs); - - /* Close the transport, if it's still open. */ - local_close(transport); - - /* Free the transport */ - git__free(t); -} - -/************** - * Public API * - **************/ - -int git_transport_local(git_transport **out, git_remote *owner, void *param) -{ - int error; - transport_local *t; - - GIT_UNUSED(param); - - t = git__calloc(1, sizeof(transport_local)); - GIT_ERROR_CHECK_ALLOC(t); - - t->parent.version = GIT_TRANSPORT_VERSION; - t->parent.connect = local_connect; - t->parent.set_connect_opts = local_set_connect_opts; - t->parent.capabilities = local_capabilities; -#ifdef GIT_EXPERIMENTAL_SHA256 - t->parent.oid_type = local_oid_type; -#endif - t->parent.negotiate_fetch = local_negotiate_fetch; - t->parent.shallow_roots = local_shallow_roots; - t->parent.download_pack = local_download_pack; - t->parent.push = local_push; - t->parent.close = local_close; - t->parent.free = local_free; - t->parent.ls = local_ls; - t->parent.is_connected = local_is_connected; - t->parent.cancel = local_cancel; - - if ((error = git_vector_init(&t->refs, 0, NULL)) < 0) { - git__free(t); - return error; - } - - t->owner = owner; - - *out = (git_transport *) t; - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart.c deleted file mode 100644 index ebd5a5b..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart.c +++ /dev/null @@ -1,537 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "smart.h" - -#include "git2.h" -#include "git2/sys/remote.h" -#include "refs.h" -#include "refspec.h" -#include "proxy.h" - -int git_smart__recv(transport_smart *t) -{ - size_t bytes_read; - int ret; - - GIT_ASSERT_ARG(t); - GIT_ASSERT(t->current_stream); - - if (git_staticstr_remain(&t->buffer) == 0) { - git_error_set(GIT_ERROR_NET, "out of buffer space"); - return -1; - } - - ret = t->current_stream->read(t->current_stream, - git_staticstr_offset(&t->buffer), - git_staticstr_remain(&t->buffer), - &bytes_read); - - if (ret < 0) - return ret; - - GIT_ASSERT(bytes_read <= INT_MAX); - GIT_ASSERT(bytes_read <= git_staticstr_remain(&t->buffer)); - - git_staticstr_increase(&t->buffer, bytes_read); - - if (t->packetsize_cb && !t->cancelled.val) { - ret = t->packetsize_cb(bytes_read, t->packetsize_payload); - - if (ret) { - git_atomic32_set(&t->cancelled, 1); - return GIT_EUSER; - } - } - - return (int)bytes_read; -} - -GIT_INLINE(int) git_smart__reset_stream(transport_smart *t, bool close_subtransport) -{ - if (t->current_stream) { - t->current_stream->free(t->current_stream); - t->current_stream = NULL; - } - - if (close_subtransport) { - git__free(t->url); - t->url = NULL; - - if (t->wrapped->close(t->wrapped) < 0) - return -1; - - git__free(t->caps.object_format); - t->caps.object_format = NULL; - - git__free(t->caps.agent); - t->caps.agent = NULL; - } - - return 0; -} - -int git_smart__update_heads(transport_smart *t, git_vector *symrefs) -{ - size_t i; - git_pkt *pkt; - - git_vector_clear(&t->heads); - git_vector_foreach(&t->refs, i, pkt) { - git_pkt_ref *ref = (git_pkt_ref *) pkt; - if (pkt->type != GIT_PKT_REF) - continue; - - if (symrefs) { - git_refspec *spec; - git_str buf = GIT_STR_INIT; - size_t j; - int error = 0; - - git_vector_foreach(symrefs, j, spec) { - git_str_clear(&buf); - if (git_refspec_src_matches(spec, ref->head.name) && - !(error = git_refspec__transform(&buf, spec, ref->head.name))) { - git__free(ref->head.symref_target); - ref->head.symref_target = git_str_detach(&buf); - } - } - - git_str_dispose(&buf); - - if (error < 0) - return error; - } - - if (git_vector_insert(&t->heads, &ref->head) < 0) - return -1; - } - - return 0; -} - -static void free_symrefs(git_vector *symrefs) -{ - git_refspec *spec; - size_t i; - - git_vector_foreach(symrefs, i, spec) { - git_refspec__dispose(spec); - git__free(spec); - } - - git_vector_dispose(symrefs); -} - -static int git_smart__connect( - git_transport *transport, - const char *url, - int direction, - const git_remote_connect_options *connect_opts) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - git_smart_subtransport_stream *stream; - int error; - git_pkt *pkt; - git_pkt_ref *first; - git_vector symrefs; - git_smart_service_t service; - - if (git_smart__reset_stream(t, true) < 0) - return -1; - - if (git_remote_connect_options_normalize(&t->connect_opts, t->owner->repo, connect_opts) < 0) - return -1; - - t->url = git__strdup(url); - GIT_ERROR_CHECK_ALLOC(t->url); - - t->direction = direction; - - if (GIT_DIRECTION_FETCH == t->direction) { - service = GIT_SERVICE_UPLOADPACK_LS; - } else if (GIT_DIRECTION_PUSH == t->direction) { - service = GIT_SERVICE_RECEIVEPACK_LS; - } else { - git_error_set(GIT_ERROR_NET, "invalid direction"); - return -1; - } - - if ((error = t->wrapped->action(&stream, t->wrapped, t->url, service)) < 0) - return error; - - /* Save off the current stream (i.e. socket) that we are working with */ - t->current_stream = stream; - - /* 2 flushes for RPC; 1 for stateful */ - if ((error = git_smart__store_refs(t, t->rpc ? 2 : 1)) < 0) - return error; - - /* Strip the comment packet for RPC */ - if (t->rpc) { - pkt = (git_pkt *)git_vector_get(&t->refs, 0); - - if (!pkt || GIT_PKT_COMMENT != pkt->type) { - git_error_set(GIT_ERROR_NET, "invalid response"); - return -1; - } else { - /* Remove the comment pkt from the list */ - git_vector_remove(&t->refs, 0); - git__free(pkt); - } - } - - /* We now have loaded the refs. */ - t->have_refs = 1; - - pkt = (git_pkt *)git_vector_get(&t->refs, 0); - if (pkt && GIT_PKT_REF != pkt->type) { - git_error_set(GIT_ERROR_NET, "invalid response"); - return -1; - } - first = (git_pkt_ref *)pkt; - - if ((error = git_vector_init(&symrefs, 1, NULL)) < 0) - return error; - - /* Detect capabilities */ - if ((error = git_smart__detect_caps(first, &t->caps, &symrefs)) == 0) { - /* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */ - if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") && - git_oid_is_zero(&first->head.oid)) { - git_vector_clear(&t->refs); - git_pkt_free((git_pkt *)first); - } - - /* Keep a list of heads for _ls */ - git_smart__update_heads(t, &symrefs); - } else if (error == GIT_ENOTFOUND) { - /* There was no ref packet received, or the cap list was empty */ - error = 0; - } else { - git_error_set(GIT_ERROR_NET, "invalid response"); - goto cleanup; - } - - if (t->rpc && (error = git_smart__reset_stream(t, false)) < 0) - goto cleanup; - - /* We're now logically connected. */ - t->connected = 1; - -cleanup: - free_symrefs(&symrefs); - - return error; -} - -static int git_smart__set_connect_opts( - git_transport *transport, - const git_remote_connect_options *opts) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - - if (!t->connected) { - git_error_set(GIT_ERROR_NET, "cannot reconfigure a transport that is not connected"); - return -1; - } - - return git_remote_connect_options_normalize(&t->connect_opts, t->owner->repo, opts); -} - -static int git_smart__capabilities(unsigned int *capabilities, git_transport *transport) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - - *capabilities = 0; - - if (t->caps.push_options) - *capabilities |= GIT_REMOTE_CAPABILITY_PUSH_OPTIONS; - - if (t->caps.want_tip_sha1) - *capabilities |= GIT_REMOTE_CAPABILITY_TIP_OID; - - if (t->caps.want_reachable_sha1) - *capabilities |= GIT_REMOTE_CAPABILITY_REACHABLE_OID; - - return 0; -} - -#ifdef GIT_EXPERIMENTAL_SHA256 -static int git_smart__oid_type(git_oid_t *out, git_transport *transport) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - - *out = 0; - - if (t->caps.object_format == NULL) { - *out = GIT_OID_DEFAULT; - } else { - *out = git_oid_type_fromstr(t->caps.object_format); - - if (!*out) { - git_error_set(GIT_ERROR_INVALID, - "unknown object format '%s'", - t->caps.object_format); - return -1; - } - } - - return 0; -} -#endif - -static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - - if (!t->have_refs) { - git_error_set(GIT_ERROR_NET, "the transport has not yet loaded the refs"); - return -1; - } - - *out = (const git_remote_head **) t->heads.contents; - *size = t->heads.length; - - return 0; -} - -int git_smart__negotiation_step(git_transport *transport, void *data, size_t len) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - git_smart_subtransport_stream *stream; - int error; - - if (t->rpc && git_smart__reset_stream(t, false) < 0) - return -1; - - if (GIT_DIRECTION_FETCH != t->direction) { - git_error_set(GIT_ERROR_NET, "this operation is only valid for fetch"); - return -1; - } - - if ((error = t->wrapped->action(&stream, t->wrapped, t->url, GIT_SERVICE_UPLOADPACK)) < 0) - return error; - - /* If this is a stateful implementation, the stream we get back should be the same */ - GIT_ASSERT(t->rpc || t->current_stream == stream); - - /* Save off the current stream (i.e. socket) that we are working with */ - t->current_stream = stream; - - if ((error = stream->write(stream, (const char *)data, len)) < 0) - return error; - - return 0; -} - -int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream **stream) -{ - int error; - - if (t->rpc && git_smart__reset_stream(t, false) < 0) - return -1; - - if (GIT_DIRECTION_PUSH != t->direction) { - git_error_set(GIT_ERROR_NET, "this operation is only valid for push"); - return -1; - } - - if ((error = t->wrapped->action(stream, t->wrapped, t->url, GIT_SERVICE_RECEIVEPACK)) < 0) - return error; - - /* If this is a stateful implementation, the stream we get back should be the same */ - GIT_ASSERT(t->rpc || t->current_stream == *stream); - - /* Save off the current stream (i.e. socket) that we are working with */ - t->current_stream = *stream; - - return 0; -} - -static void git_smart__cancel(git_transport *transport) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - - git_atomic32_set(&t->cancelled, 1); -} - -static int git_smart__is_connected(git_transport *transport) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - - return t->connected; -} - -static int git_smart__close(git_transport *transport) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - git_vector *common = &t->common; - unsigned int i; - git_pkt *p; - git_smart_service_t service; - int ret; - git_smart_subtransport_stream *stream; - const char flush[] = "0000"; - - if (t->direction == GIT_DIRECTION_FETCH) { - service = GIT_SERVICE_UPLOADPACK; - } else if (t->direction == GIT_DIRECTION_PUSH) { - service = GIT_SERVICE_RECEIVEPACK; - } else { - git_error_set(GIT_ERROR_NET, "invalid direction"); - return -1; - } - - /* - * If we're still connected at this point and not using RPC, - * we should say goodbye by sending a flush, or git-daemon - * will complain that we disconnected unexpectedly. - */ - if (t->connected && !t->rpc && - !t->wrapped->action(&stream, t->wrapped, t->url, service)) { - t->current_stream->write(t->current_stream, flush, 4); - } - - ret = git_smart__reset_stream(t, true); - - git_vector_foreach(common, i, p) - git_pkt_free(p); - - git_vector_dispose(common); - - if (t->url) { - git__free(t->url); - t->url = NULL; - } - - t->connected = 0; - - return ret; -} - -static void git_smart__free(git_transport *transport) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - git_vector *refs = &t->refs; - unsigned int i; - git_pkt *p; - - /* Make sure that the current stream is closed, if we have one. */ - git_smart__close(transport); - - /* Free the subtransport */ - t->wrapped->free(t->wrapped); - - git_vector_dispose(&t->heads); - git_vector_foreach(refs, i, p) - git_pkt_free(p); - - git_vector_dispose(refs); - - git_remote_connect_options_dispose(&t->connect_opts); - - git_array_dispose(t->shallow_roots); - - git__free(t->caps.object_format); - git__free(t->caps.agent); - git__free(t); -} - -static int ref_name_cmp(const void *a, const void *b) -{ - const git_pkt_ref *ref_a = a, *ref_b = b; - - return strcmp(ref_a->head.name, ref_b->head.name); -} - -int git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - git_remote_connect_options *connect_opts = &t->connect_opts; - - GIT_ASSERT_ARG(transport); - GIT_ASSERT_ARG(cert); - GIT_ASSERT_ARG(hostname); - - if (!connect_opts->callbacks.certificate_check) - return GIT_PASSTHROUGH; - - return connect_opts->callbacks.certificate_check(cert, valid, hostname, connect_opts->callbacks.payload); -} - -int git_transport_smart_credentials(git_credential **out, git_transport *transport, const char *user, int methods) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - git_remote_connect_options *connect_opts = &t->connect_opts; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(transport); - - if (!connect_opts->callbacks.credentials) - return GIT_PASSTHROUGH; - - return connect_opts->callbacks.credentials(out, t->url, user, methods, connect_opts->callbacks.payload); -} - -int git_transport_remote_connect_options( - git_remote_connect_options *out, - git_transport *transport) -{ - transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(transport); - - return git_remote_connect_options_dup(out, &t->connect_opts); -} - -int git_transport_smart(git_transport **out, git_remote *owner, void *param) -{ - transport_smart *t; - git_smart_subtransport_definition *definition = (git_smart_subtransport_definition *)param; - - if (!param) - return -1; - - t = git__calloc(1, sizeof(transport_smart)); - GIT_ERROR_CHECK_ALLOC(t); - - t->parent.version = GIT_TRANSPORT_VERSION; - t->parent.connect = git_smart__connect; - t->parent.set_connect_opts = git_smart__set_connect_opts; - t->parent.capabilities = git_smart__capabilities; -#ifdef GIT_EXPERIMENTAL_SHA256 - t->parent.oid_type = git_smart__oid_type; -#endif - t->parent.close = git_smart__close; - t->parent.free = git_smart__free; - t->parent.negotiate_fetch = git_smart__negotiate_fetch; - t->parent.shallow_roots = git_smart__shallow_roots; - t->parent.download_pack = git_smart__download_pack; - t->parent.push = git_smart__push; - t->parent.ls = git_smart__ls; - t->parent.is_connected = git_smart__is_connected; - t->parent.cancel = git_smart__cancel; - - t->owner = owner; - t->rpc = definition->rpc; - - if (git_vector_init(&t->refs, 16, ref_name_cmp) < 0 || - git_vector_init(&t->heads, 16, ref_name_cmp) < 0 || - definition->callback(&t->wrapped, &t->parent, definition->param) < 0) { - git_vector_dispose(&t->refs); - git_vector_dispose(&t->heads); - git__free(t); - return -1; - } - - git_staticstr_init(&t->buffer, GIT_SMART_BUFFER_SIZE); - - *out = (git_transport *) t; - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart.h deleted file mode 100644 index c987d93..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart.h +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_transports_smart_h__ -#define INCLUDE_transports_smart_h__ - -#include "common.h" - -#include "git2.h" -#include "vector.h" -#include "push.h" -#include "str.h" -#include "oidarray.h" -#include "staticstr.h" -#include "git2/sys/transport.h" - -#define GIT_SMART_BUFFER_SIZE 65536 - -#define GIT_SIDE_BAND_DATA 1 -#define GIT_SIDE_BAND_PROGRESS 2 -#define GIT_SIDE_BAND_ERROR 3 - -#define GIT_CAP_OFS_DELTA "ofs-delta" -#define GIT_CAP_MULTI_ACK "multi_ack" -#define GIT_CAP_MULTI_ACK_DETAILED "multi_ack_detailed" -#define GIT_CAP_SIDE_BAND "side-band" -#define GIT_CAP_SIDE_BAND_64K "side-band-64k" -#define GIT_CAP_INCLUDE_TAG "include-tag" -#define GIT_CAP_DELETE_REFS "delete-refs" -#define GIT_CAP_REPORT_STATUS "report-status" -#define GIT_CAP_THIN_PACK "thin-pack" -#define GIT_CAP_SYMREF "symref" -#define GIT_CAP_WANT_TIP_SHA1 "allow-tip-sha1-in-want" -#define GIT_CAP_WANT_REACHABLE_SHA1 "allow-reachable-sha1-in-want" -#define GIT_CAP_SHALLOW "shallow" -#define GIT_CAP_OBJECT_FORMAT "object-format=" -#define GIT_CAP_AGENT "agent=" -#define GIT_CAP_PUSH_OPTIONS "push-options" - -extern bool git_smart__ofs_delta_enabled; - -typedef enum { - GIT_PKT_CMD, - GIT_PKT_FLUSH, - GIT_PKT_REF, - GIT_PKT_HAVE, - GIT_PKT_ACK, - GIT_PKT_NAK, - GIT_PKT_COMMENT, - GIT_PKT_ERR, - GIT_PKT_DATA, - GIT_PKT_PROGRESS, - GIT_PKT_OK, - GIT_PKT_NG, - GIT_PKT_UNPACK, - GIT_PKT_SHALLOW, - GIT_PKT_UNSHALLOW -} git_pkt_type; - -/* Used for multi_ack and multi_ack_detailed */ -enum git_ack_status { - GIT_ACK_NONE, - GIT_ACK_CONTINUE, - GIT_ACK_COMMON, - GIT_ACK_READY -}; - -/* This would be a flush pkt */ -typedef struct { - git_pkt_type type; -} git_pkt; - -struct git_pkt_cmd { - git_pkt_type type; - char *cmd; - char *path; - char *host; -}; - -/* This is a pkt-line with some info in it */ -typedef struct { - git_pkt_type type; - git_remote_head head; - char *capabilities; -} git_pkt_ref; - -/* Useful later */ -typedef struct { - git_pkt_type type; - git_oid oid; - enum git_ack_status status; -} git_pkt_ack; - -typedef struct { - git_pkt_type type; - char comment[GIT_FLEX_ARRAY]; -} git_pkt_comment; - -typedef struct { - git_pkt_type type; - size_t len; - char data[GIT_FLEX_ARRAY]; -} git_pkt_data; - -typedef git_pkt_data git_pkt_progress; - -typedef struct { - git_pkt_type type; - size_t len; - char error[GIT_FLEX_ARRAY]; -} git_pkt_err; - -typedef struct { - git_pkt_type type; - char *ref; -} git_pkt_ok; - -typedef struct { - git_pkt_type type; - char *ref; - char *msg; -} git_pkt_ng; - -typedef struct { - git_pkt_type type; - int unpack_ok; -} git_pkt_unpack; - -typedef struct { - git_pkt_type type; - git_oid oid; -} git_pkt_shallow; - -typedef struct transport_smart_caps { - unsigned int common:1, - ofs_delta:1, - multi_ack:1, - multi_ack_detailed:1, - side_band:1, - side_band_64k:1, - include_tag:1, - delete_refs:1, - report_status:1, - thin_pack:1, - want_tip_sha1:1, - want_reachable_sha1:1, - shallow:1, - push_options:1; - char *object_format; - char *agent; -} transport_smart_caps; - -typedef int (*packetsize_cb)(size_t received, void *payload); - -typedef struct { - git_transport parent; - git_remote *owner; - char *url; - git_remote_connect_options connect_opts; - int direction; - git_smart_subtransport *wrapped; - git_smart_subtransport_stream *current_stream; - transport_smart_caps caps; - git_vector refs; - git_vector heads; - git_vector common; - git_array_oid_t shallow_roots; - git_atomic32 cancelled; - packetsize_cb packetsize_cb; - void *packetsize_payload; - unsigned rpc : 1, - have_refs : 1, - connected : 1; - git_staticstr_with_size(GIT_SMART_BUFFER_SIZE) buffer; -} transport_smart; - -/* smart_protocol.c */ -int git_smart__store_refs(transport_smart *t, int flushes); -int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vector *symrefs); -int git_smart__push(git_transport *transport, git_push *push); - -int git_smart__negotiate_fetch( - git_transport *transport, - git_repository *repo, - const git_fetch_negotiation *wants); - -int git_smart__shallow_roots(git_oidarray *out, git_transport *transport); - -int git_smart__download_pack( - git_transport *transport, - git_repository *repo, - git_indexer_progress *stats); - -/* smart.c */ -int git_smart__recv(transport_smart *t); - -int git_smart__negotiation_step(git_transport *transport, void *data, size_t len); -int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream **out); - -int git_smart__update_heads(transport_smart *t, git_vector *symrefs); - -/* smart_pkt.c */ -typedef struct { - git_oid_t oid_type; - unsigned int seen_capabilities: 1; -} git_pkt_parse_data; - -int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen, git_pkt_parse_data *data); -int git_pkt_buffer_flush(git_str *buf); -int git_pkt_send_flush(GIT_SOCKET s); -int git_pkt_buffer_done(git_str *buf); -int git_pkt_buffer_wants(const git_fetch_negotiation *wants, transport_smart_caps *caps, git_str *buf); -int git_pkt_buffer_have(git_oid *oid, git_str *buf); -void git_pkt_free(git_pkt *pkt); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart_pkt.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart_pkt.c deleted file mode 100644 index af2e73f..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart_pkt.c +++ /dev/null @@ -1,871 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "smart.h" -#include "util.h" -#include "posix.h" -#include "str.h" -#include "oid.h" - -#include "git2/types.h" -#include "git2/errors.h" -#include "git2/refs.h" -#include "git2/revwalk.h" - -#include - -#define PKT_DONE_STR "0009done\n" -#define PKT_FLUSH_STR "0000" -#define PKT_HAVE_PREFIX "have " -#define PKT_WANT_PREFIX "want " - -#define PKT_LEN_SIZE 4 -#define PKT_MAX_SIZE 0xffff -#define PKT_MAX_WANTLEN (PKT_LEN_SIZE + CONST_STRLEN(PKT_WANT_PREFIX) + GIT_OID_MAX_HEXSIZE + 1) - -static int flush_pkt(git_pkt **out) -{ - git_pkt *pkt; - - pkt = git__malloc(sizeof(git_pkt)); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->type = GIT_PKT_FLUSH; - *out = pkt; - - return 0; -} - -/* the rest of the line will be useful for multi_ack and multi_ack_detailed */ -static int ack_pkt( - git_pkt **out, - const char *line, - size_t len, - git_pkt_parse_data *data) -{ - git_pkt_ack *pkt; - size_t oid_hexsize = git_oid_hexsize(data->oid_type); - - GIT_ASSERT(data && data->oid_type); - - pkt = git__calloc(1, sizeof(git_pkt_ack)); - GIT_ERROR_CHECK_ALLOC(pkt); - pkt->type = GIT_PKT_ACK; - - if (git__prefixncmp(line, len, "ACK ")) - goto out_err; - line += 4; - len -= 4; - - if (len < oid_hexsize || - git_oid__fromstr(&pkt->oid, line, data->oid_type) < 0) - goto out_err; - line += oid_hexsize; - len -= oid_hexsize; - - if (len && line[0] == ' ') { - line++; - len--; - - if (!git__prefixncmp(line, len, "continue")) - pkt->status = GIT_ACK_CONTINUE; - else if (!git__prefixncmp(line, len, "common")) - pkt->status = GIT_ACK_COMMON; - else if (!git__prefixncmp(line, len, "ready")) - pkt->status = GIT_ACK_READY; - else - goto out_err; - } - - *out = (git_pkt *) pkt; - - return 0; - -out_err: - git_error_set(GIT_ERROR_NET, "error parsing ACK pkt-line"); - git__free(pkt); - return -1; -} - -static int nak_pkt(git_pkt **out) -{ - git_pkt *pkt; - - pkt = git__malloc(sizeof(git_pkt)); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->type = GIT_PKT_NAK; - *out = pkt; - - return 0; -} - -static int comment_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_comment *pkt; - size_t alloclen; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_comment), len); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); - pkt = git__malloc(alloclen); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->type = GIT_PKT_COMMENT; - memcpy(pkt->comment, line, len); - pkt->comment[len] = '\0'; - - *out = (git_pkt *) pkt; - - return 0; -} - -static int err_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_err *pkt = NULL; - size_t alloclen; - - /* Remove "ERR " from the line */ - if (git__prefixncmp(line, len, "ERR ")) - goto out_err; - line += 4; - len -= 4; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); - pkt = git__malloc(alloclen); - GIT_ERROR_CHECK_ALLOC(pkt); - pkt->type = GIT_PKT_ERR; - pkt->len = len; - - memcpy(pkt->error, line, len); - pkt->error[len] = '\0'; - - *out = (git_pkt *) pkt; - - return 0; - -out_err: - git_error_set(GIT_ERROR_NET, "error parsing ERR pkt-line"); - git__free(pkt); - return -1; -} - -static int data_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_data *pkt; - size_t alloclen; - - line++; - len--; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); - pkt = git__malloc(alloclen); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->type = GIT_PKT_DATA; - pkt->len = len; - memcpy(pkt->data, line, len); - - *out = (git_pkt *) pkt; - - return 0; -} - -static int sideband_progress_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_progress *pkt; - size_t alloclen; - - line++; - len--; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_pkt_progress), len); - pkt = git__malloc(alloclen); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->type = GIT_PKT_PROGRESS; - pkt->len = len; - memcpy(pkt->data, line, len); - - *out = (git_pkt *) pkt; - - return 0; -} - -static int sideband_error_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_err *pkt; - size_t alloc_len; - - line++; - len--; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(git_pkt_err), len); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); - pkt = git__malloc(alloc_len); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->type = GIT_PKT_ERR; - pkt->len = (int)len; - memcpy(pkt->error, line, len); - pkt->error[len] = '\0'; - - *out = (git_pkt *)pkt; - - return 0; -} - -static int set_data( - git_pkt_parse_data *data, - const char *line, - size_t len) -{ - const char *caps, *format_str = NULL, *eos; - size_t format_len; - git_oid_t remote_oid_type; - - GIT_ASSERT_ARG(data); - - if ((caps = memchr(line, '\0', len)) != NULL && - len > (size_t)((caps - line) + 1)) { - caps++; - - if (len - (caps - line) >= CONST_STRLEN("object-format=") && - strncmp(caps, "object-format=", CONST_STRLEN("object-format=")) == 0) - format_str = caps + CONST_STRLEN("object-format="); - else if ((format_str = git__memmem(caps, len - (caps - line), " object-format=", CONST_STRLEN(" object-format="))) != NULL) - format_str += CONST_STRLEN(" object-format="); - } - - if (format_str) { - if ((eos = memchr(format_str, ' ', len - (format_str - line))) == NULL) - eos = memchr(format_str, '\0', len - (format_str - line)); - - GIT_ASSERT(eos); - - format_len = eos - format_str; - - if ((remote_oid_type = git_oid_type_fromstrn(format_str, format_len)) == 0) { - git_error_set(GIT_ERROR_INVALID, "unknown remote object format '%.*s'", (int)format_len, format_str); - return -1; - } - } else { - remote_oid_type = GIT_OID_SHA1; - } - - if (!data->oid_type) { - data->oid_type = remote_oid_type; - } else if (data->oid_type != remote_oid_type) { - git_error_set(GIT_ERROR_INVALID, - "the local object format '%s' does not match the remote object format '%s'", - git_oid_type_name(data->oid_type), - git_oid_type_name(remote_oid_type)); - return -1; - } - - return 0; -} - -/* - * Parse an other-ref line. - */ -static int ref_pkt( - git_pkt **out, - const char *line, - size_t len, - git_pkt_parse_data *data) -{ - git_pkt_ref *pkt; - size_t alloclen, oid_hexsize; - - pkt = git__calloc(1, sizeof(git_pkt_ref)); - GIT_ERROR_CHECK_ALLOC(pkt); - pkt->type = GIT_PKT_REF; - - /* Determine OID type from capabilities */ - if (!data->seen_capabilities && set_data(data, line, len) < 0) - return -1; - - GIT_ASSERT(data->oid_type); - oid_hexsize = git_oid_hexsize(data->oid_type); - - if (len < oid_hexsize || - git_oid__fromstr(&pkt->head.oid, line, data->oid_type) < 0) - goto out_err; - line += oid_hexsize; - len -= oid_hexsize; - - if (git__prefixncmp(line, len, " ")) - goto out_err; - - line++; - len--; - - if (!len) - goto out_err; - - if (line[len - 1] == '\n') - --len; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1); - pkt->head.name = git__malloc(alloclen); - GIT_ERROR_CHECK_ALLOC(pkt->head.name); - - memcpy(pkt->head.name, line, len); - pkt->head.name[len] = '\0'; - - if (strlen(pkt->head.name) < len) { - if (!data->seen_capabilities) - pkt->capabilities = strchr(pkt->head.name, '\0') + 1; - else - goto out_err; - } - - data->seen_capabilities = 1; - - *out = (git_pkt *)pkt; - return 0; - -out_err: - git_error_set(GIT_ERROR_NET, "error parsing REF pkt-line"); - if (pkt) - git__free(pkt->head.name); - git__free(pkt); - return -1; -} - -static int ok_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_ok *pkt; - size_t alloc_len; - - pkt = git__malloc(sizeof(*pkt)); - GIT_ERROR_CHECK_ALLOC(pkt); - pkt->type = GIT_PKT_OK; - - if (git__prefixncmp(line, len, "ok ")) - goto out_err; - line += 3; - len -= 3; - - if (len && line[len - 1] == '\n') - --len; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1); - pkt->ref = git__malloc(alloc_len); - GIT_ERROR_CHECK_ALLOC(pkt->ref); - - memcpy(pkt->ref, line, len); - pkt->ref[len] = '\0'; - - *out = (git_pkt *)pkt; - return 0; - -out_err: - git_error_set(GIT_ERROR_NET, "error parsing OK pkt-line"); - git__free(pkt); - return -1; -} - -static int ng_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_ng *pkt; - const char *ptr, *eol; - size_t alloclen; - - pkt = git__malloc(sizeof(*pkt)); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->ref = NULL; - pkt->type = GIT_PKT_NG; - - eol = line + len; - - if (git__prefixncmp(line, len, "ng ")) - goto out_err; - line += 3; - - if (!(ptr = memchr(line, ' ', eol - line))) - goto out_err; - len = ptr - line; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1); - pkt->ref = git__malloc(alloclen); - GIT_ERROR_CHECK_ALLOC(pkt->ref); - - memcpy(pkt->ref, line, len); - pkt->ref[len] = '\0'; - - line = ptr + 1; - if (line >= eol) - goto out_err; - - if (!(ptr = memchr(line, '\n', eol - line))) - goto out_err; - len = ptr - line; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1); - pkt->msg = git__malloc(alloclen); - GIT_ERROR_CHECK_ALLOC(pkt->msg); - - memcpy(pkt->msg, line, len); - pkt->msg[len] = '\0'; - - *out = (git_pkt *)pkt; - return 0; - -out_err: - git_error_set(GIT_ERROR_NET, "invalid packet line"); - git__free(pkt->ref); - git__free(pkt); - return -1; -} - -static int unpack_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_unpack *pkt; - - pkt = git__malloc(sizeof(*pkt)); - GIT_ERROR_CHECK_ALLOC(pkt); - pkt->type = GIT_PKT_UNPACK; - - if (!git__prefixncmp(line, len, "unpack ok")) - pkt->unpack_ok = 1; - else - pkt->unpack_ok = 0; - - *out = (git_pkt *)pkt; - return 0; -} - -static int shallow_pkt( - git_pkt **out, - const char *line, - size_t len, - git_pkt_parse_data *data) -{ - git_pkt_shallow *pkt; - size_t oid_hexsize = git_oid_hexsize(data->oid_type); - - GIT_ASSERT(data && data->oid_type); - - pkt = git__calloc(1, sizeof(git_pkt_shallow)); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->type = GIT_PKT_SHALLOW; - - if (git__prefixncmp(line, len, "shallow ")) - goto out_err; - - line += 8; - len -= 8; - - if (len != oid_hexsize) - goto out_err; - - git_oid__fromstr(&pkt->oid, line, data->oid_type); - line += oid_hexsize + 1; - len -= oid_hexsize + 1; - - *out = (git_pkt *)pkt; - - return 0; - -out_err: - git_error_set(GIT_ERROR_NET, "invalid packet line"); - git__free(pkt); - return -1; -} - -static int unshallow_pkt( - git_pkt **out, - const char *line, - size_t len, - git_pkt_parse_data *data) -{ - git_pkt_shallow *pkt; - size_t oid_hexsize = git_oid_hexsize(data->oid_type); - - GIT_ASSERT(data && data->oid_type); - - pkt = git__calloc(1, sizeof(git_pkt_shallow)); - GIT_ERROR_CHECK_ALLOC(pkt); - - pkt->type = GIT_PKT_UNSHALLOW; - - if (git__prefixncmp(line, len, "unshallow ")) - goto out_err; - - line += 10; - len -= 10; - - if (len != oid_hexsize) - goto out_err; - - git_oid__fromstr(&pkt->oid, line, data->oid_type); - line += oid_hexsize + 1; - len -= oid_hexsize + 1; - - *out = (git_pkt *) pkt; - - return 0; - -out_err: - git_error_set(GIT_ERROR_NET, "invalid packet line"); - git__free(pkt); - return -1; -} - -static int parse_len(size_t *out, const char *line, size_t linelen) -{ - char num[PKT_LEN_SIZE + 1]; - int i, k, error; - int32_t len; - const char *num_end; - - /* Not even enough for the length */ - if (linelen < PKT_LEN_SIZE) - return GIT_EBUFS; - - memcpy(num, line, PKT_LEN_SIZE); - num[PKT_LEN_SIZE] = '\0'; - - for (i = 0; i < PKT_LEN_SIZE; ++i) { - if (!git__isxdigit(num[i])) { - /* Make sure there are no special characters before passing to error message */ - for (k = 0; k < PKT_LEN_SIZE; ++k) { - if(!git__isprint(num[k])) { - num[k] = '.'; - } - } - - git_error_set(GIT_ERROR_NET, "invalid hex digit in length: '%s'", num); - return -1; - } - } - - if ((error = git__strntol32(&len, num, PKT_LEN_SIZE, &num_end, 16)) < 0) - return error; - - if (len < 0) - return -1; - - *out = (size_t) len; - return 0; -} - -/* - * As per the documentation, the syntax is: - * - * pkt-line = data-pkt / flush-pkt - * data-pkt = pkt-len pkt-payload - * pkt-len = 4*(HEXDIG) - * pkt-payload = (pkt-len -4)*(OCTET) - * flush-pkt = "0000" - * - * Which means that the first four bytes are the length of the line, - * in ASCII hexadecimal (including itself) - */ - -int git_pkt_parse_line( - git_pkt **pkt, - const char **endptr, - const char *line, - size_t linelen, - git_pkt_parse_data *data) -{ - int error; - size_t len; - - if ((error = parse_len(&len, line, linelen)) < 0) { - /* - * If we fail to parse the length, it might be - * because the server is trying to send us the - * packfile already or because we do not yet have - * enough data. - */ - if (error == GIT_EBUFS) - ; - else if (!git__prefixncmp(line, linelen, "PACK")) - git_error_set(GIT_ERROR_NET, "unexpected pack file"); - else - git_error_set(GIT_ERROR_NET, "bad packet length"); - return error; - } - - /* - * Make sure there is enough in the buffer to satisfy - * this line. - */ - if (linelen < len) - return GIT_EBUFS; - - /* - * The length has to be exactly 0 in case of a flush - * packet or greater than PKT_LEN_SIZE, as the decoded - * length includes its own encoded length of four bytes. - */ - if (len != 0 && len < PKT_LEN_SIZE) - return GIT_ERROR; - - line += PKT_LEN_SIZE; - /* - * The Git protocol does not specify empty lines as part - * of the protocol. Not knowing what to do with an empty - * line, we should return an error upon hitting one. - */ - if (len == PKT_LEN_SIZE) { - git_error_set_str(GIT_ERROR_NET, "Invalid empty packet"); - return GIT_ERROR; - } - - if (len == 0) { /* Flush pkt */ - *endptr = line; - return flush_pkt(pkt); - } - - len -= PKT_LEN_SIZE; /* the encoded length includes its own size */ - - if (*line == GIT_SIDE_BAND_DATA) - error = data_pkt(pkt, line, len); - else if (*line == GIT_SIDE_BAND_PROGRESS) - error = sideband_progress_pkt(pkt, line, len); - else if (*line == GIT_SIDE_BAND_ERROR) - error = sideband_error_pkt(pkt, line, len); - else if (!git__prefixncmp(line, len, "ACK")) - error = ack_pkt(pkt, line, len, data); - else if (!git__prefixncmp(line, len, "NAK")) - error = nak_pkt(pkt); - else if (!git__prefixncmp(line, len, "ERR")) - error = err_pkt(pkt, line, len); - else if (*line == '#') - error = comment_pkt(pkt, line, len); - else if (!git__prefixncmp(line, len, "ok")) - error = ok_pkt(pkt, line, len); - else if (!git__prefixncmp(line, len, "ng")) - error = ng_pkt(pkt, line, len); - else if (!git__prefixncmp(line, len, "unpack")) - error = unpack_pkt(pkt, line, len); - else if (!git__prefixcmp(line, "shallow")) - error = shallow_pkt(pkt, line, len, data); - else if (!git__prefixcmp(line, "unshallow")) - error = unshallow_pkt(pkt, line, len, data); - else - error = ref_pkt(pkt, line, len, data); - - *endptr = line + len; - - return error; -} - -void git_pkt_free(git_pkt *pkt) -{ - if (pkt == NULL) { - return; - } - if (pkt->type == GIT_PKT_REF) { - git_pkt_ref *p = (git_pkt_ref *) pkt; - git__free(p->head.name); - git__free(p->head.symref_target); - } - - if (pkt->type == GIT_PKT_OK) { - git_pkt_ok *p = (git_pkt_ok *) pkt; - git__free(p->ref); - } - - if (pkt->type == GIT_PKT_NG) { - git_pkt_ng *p = (git_pkt_ng *) pkt; - git__free(p->ref); - git__free(p->msg); - } - - git__free(pkt); -} - -int git_pkt_buffer_flush(git_str *buf) -{ - return git_str_put(buf, PKT_FLUSH_STR, CONST_STRLEN(PKT_FLUSH_STR)); -} - -static int buffer_want_with_caps( - const git_remote_head *head, - transport_smart_caps *caps, - git_oid_t oid_type, - git_str *buf) -{ - git_str str = GIT_STR_INIT; - char oid[GIT_OID_MAX_HEXSIZE]; - size_t oid_hexsize, len; - - oid_hexsize = git_oid_hexsize(oid_type); - git_oid_fmt(oid, &head->oid); - - /* Prefer multi_ack_detailed */ - if (caps->multi_ack_detailed) - git_str_puts(&str, GIT_CAP_MULTI_ACK_DETAILED " "); - else if (caps->multi_ack) - git_str_puts(&str, GIT_CAP_MULTI_ACK " "); - - /* Prefer side-band-64k if the server supports both */ - if (caps->side_band_64k) - git_str_printf(&str, "%s ", GIT_CAP_SIDE_BAND_64K); - else if (caps->side_band) - git_str_printf(&str, "%s ", GIT_CAP_SIDE_BAND); - - if (caps->include_tag) - git_str_puts(&str, GIT_CAP_INCLUDE_TAG " "); - - if (caps->thin_pack) - git_str_puts(&str, GIT_CAP_THIN_PACK " "); - - if (caps->ofs_delta) - git_str_puts(&str, GIT_CAP_OFS_DELTA " "); - - if (caps->shallow) - git_str_puts(&str, GIT_CAP_SHALLOW " "); - - if (git_str_oom(&str)) - return -1; - - if (str.size > (PKT_MAX_SIZE - (PKT_MAX_WANTLEN + 1))) { - git_error_set(GIT_ERROR_NET, - "tried to produce packet with invalid caps length %" PRIuZ, str.size); - return -1; - } - - len = PKT_LEN_SIZE + CONST_STRLEN(PKT_WANT_PREFIX) + - oid_hexsize + 1 /* NUL */ + - git_str_len(&str) + 1 /* LF */; - - git_str_grow_by(buf, len); - git_str_printf(buf, - "%04x%s%.*s %s\n", (unsigned int)len, PKT_WANT_PREFIX, - (int)oid_hexsize, oid, git_str_cstr(&str)); - git_str_dispose(&str); - - GIT_ERROR_CHECK_ALLOC_STR(buf); - - return 0; -} - -/* - * All "want" packets have the same length and format, so what we do - * is overwrite the OID each time. - */ - -int git_pkt_buffer_wants( - const git_fetch_negotiation *wants, - transport_smart_caps *caps, - git_str *buf) -{ - const git_remote_head *head; - char oid[GIT_OID_MAX_HEXSIZE]; - git_oid_t oid_type; - size_t oid_hexsize, want_len, i = 0; - -#ifdef GIT_EXPERIMENTAL_SHA256 - oid_type = wants->refs_len > 0 ? wants->refs[0]->oid.type : GIT_OID_SHA1; -#else - oid_type = GIT_OID_SHA1; -#endif - - oid_hexsize = git_oid_hexsize(oid_type); - - want_len = PKT_LEN_SIZE + CONST_STRLEN(PKT_WANT_PREFIX) + - oid_hexsize + 1 /* LF */; - - if (caps->common) { - for (; i < wants->refs_len; ++i) { - head = wants->refs[i]; - if (!head->local) - break; - } - - if (buffer_want_with_caps(wants->refs[i], caps, oid_type, buf) < 0) - return -1; - - i++; - } - - for (; i < wants->refs_len; ++i) { - head = wants->refs[i]; - - if (head->local) - continue; - - git_oid_fmt(oid, &head->oid); - - git_str_printf(buf, "%04x%s%.*s\n", - (unsigned int)want_len, PKT_WANT_PREFIX, - (int)oid_hexsize, oid); - - if (git_str_oom(buf)) - return -1; - } - - /* Tell the server about our shallow objects */ - for (i = 0; i < wants->shallow_roots_len; i++) { - char oid[GIT_OID_MAX_HEXSIZE + 1]; - git_str shallow_buf = GIT_STR_INIT; - - git_oid_tostr(oid, GIT_OID_MAX_HEXSIZE + 1, &wants->shallow_roots[i]); - git_str_puts(&shallow_buf, "shallow "); - git_str_puts(&shallow_buf, oid); - git_str_putc(&shallow_buf, '\n'); - - git_str_printf(buf, "%04x%s", (unsigned int)git_str_len(&shallow_buf) + 4, git_str_cstr(&shallow_buf)); - - git_str_dispose(&shallow_buf); - - if (git_str_oom(buf)) - return -1; - } - - if (wants->depth > 0) { - git_str deepen_buf = GIT_STR_INIT; - - git_str_printf(&deepen_buf, "deepen %d\n", wants->depth); - git_str_printf(buf,"%04x%s", (unsigned int)git_str_len(&deepen_buf) + 4, git_str_cstr(&deepen_buf)); - - git_str_dispose(&deepen_buf); - - if (git_str_oom(buf)) - return -1; - } - - return git_pkt_buffer_flush(buf); -} - -int git_pkt_buffer_have(git_oid *oid, git_str *buf) -{ - char oid_str[GIT_OID_MAX_HEXSIZE]; - git_oid_t oid_type; - size_t oid_hexsize, have_len; - -#ifdef GIT_EXPERIMENTAL_SHA256 - oid_type = oid->type; -#else - oid_type = GIT_OID_SHA1; -#endif - - oid_hexsize = git_oid_hexsize(oid_type); - have_len = PKT_LEN_SIZE + CONST_STRLEN(PKT_HAVE_PREFIX) + - oid_hexsize + 1 /* LF */; - - git_oid_fmt(oid_str, oid); - return git_str_printf(buf, "%04x%s%.*s\n", - (unsigned int)have_len, PKT_HAVE_PREFIX, - (int)oid_hexsize, oid_str); -} - -int git_pkt_buffer_done(git_str *buf) -{ - return git_str_put(buf, PKT_DONE_STR, CONST_STRLEN(PKT_DONE_STR)); -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart_protocol.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart_protocol.c deleted file mode 100644 index 87c1904..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/smart_protocol.c +++ /dev/null @@ -1,1276 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#include "git2.h" -#include "git2/odb_backend.h" - -#include "smart.h" -#include "refs.h" -#include "repository.h" -#include "push.h" -#include "pack-objects.h" -#include "remote.h" -#include "util.h" -#include "revwalk.h" - -#define NETWORK_XFER_THRESHOLD (100*1024) -/* The minimal interval between progress updates (in seconds). */ -#define MIN_PROGRESS_UPDATE_INTERVAL 0.5 - -bool git_smart__ofs_delta_enabled = true; - -int git_smart__store_refs(transport_smart *t, int flushes) -{ - git_vector *refs = &t->refs; - int error, flush = 0, recvd; - const char *line_end = NULL; - git_pkt *pkt = NULL; - git_pkt_parse_data pkt_parse_data = { 0 }; - size_t i; - - /* Clear existing refs in case git_remote_connect() is called again - * after git_remote_disconnect(). - */ - git_vector_foreach(refs, i, pkt) { - git_pkt_free(pkt); - } - git_vector_clear(refs); - pkt = NULL; - - do { - if (t->buffer.len > 0) - error = git_pkt_parse_line(&pkt, &line_end, - t->buffer.data, t->buffer.len, - &pkt_parse_data); - else - error = GIT_EBUFS; - - if (error < 0 && error != GIT_EBUFS) - return error; - - if (error == GIT_EBUFS) { - if ((recvd = git_smart__recv(t)) < 0) - return recvd; - - if (recvd == 0) { - git_error_set(GIT_ERROR_NET, "could not read refs from remote repository"); - return GIT_EEOF; - } - - continue; - } - - git_staticstr_consume(&t->buffer, line_end); - - if (pkt->type == GIT_PKT_ERR) { - git_error_set(GIT_ERROR_NET, "remote error: %s", ((git_pkt_err *)pkt)->error); - git__free(pkt); - return -1; - } - - if (pkt->type != GIT_PKT_FLUSH && git_vector_insert(refs, pkt) < 0) - return -1; - - if (pkt->type == GIT_PKT_FLUSH) { - flush++; - git_pkt_free(pkt); - } - } while (flush < flushes); - - return flush; -} - -static int append_symref(const char **out, git_vector *symrefs, const char *ptr) -{ - int error; - const char *end; - git_str buf = GIT_STR_INIT; - git_refspec *mapping = NULL; - - ptr += strlen(GIT_CAP_SYMREF); - if (*ptr != '=') - goto on_invalid; - - ptr++; - if (!(end = strchr(ptr, ' ')) && - !(end = strchr(ptr, '\0'))) - goto on_invalid; - - if ((error = git_str_put(&buf, ptr, end - ptr)) < 0) - return error; - - /* symref mapping has refspec format */ - mapping = git__calloc(1, sizeof(git_refspec)); - GIT_ERROR_CHECK_ALLOC(mapping); - - error = git_refspec__parse(mapping, git_str_cstr(&buf), true); - git_str_dispose(&buf); - - /* if the error isn't OOM, then it's a parse error; let's use a nicer message */ - if (error < 0) { - if (git_error_last()->klass != GIT_ERROR_NOMEMORY) - goto on_invalid; - - git__free(mapping); - return error; - } - - if ((error = git_vector_insert(symrefs, mapping)) < 0) - return error; - - *out = end; - return 0; - -on_invalid: - git_error_set(GIT_ERROR_NET, "remote sent invalid symref"); - git_refspec__dispose(mapping); - git__free(mapping); - return -1; -} - -int git_smart__detect_caps( - git_pkt_ref *pkt, - transport_smart_caps *caps, - git_vector *symrefs) -{ - const char *ptr, *start; - - /* No refs or capabilities, odd but not a problem */ - if (pkt == NULL || pkt->capabilities == NULL) - return GIT_ENOTFOUND; - - ptr = pkt->capabilities; - while (ptr != NULL && *ptr != '\0') { - if (*ptr == ' ') - ptr++; - - if (git_smart__ofs_delta_enabled && !git__prefixcmp(ptr, GIT_CAP_OFS_DELTA)) { - caps->common = caps->ofs_delta = 1; - ptr += strlen(GIT_CAP_OFS_DELTA); - continue; - } - - /* Keep multi_ack_detailed before multi_ack */ - if (!git__prefixcmp(ptr, GIT_CAP_MULTI_ACK_DETAILED)) { - caps->common = caps->multi_ack_detailed = 1; - ptr += strlen(GIT_CAP_MULTI_ACK_DETAILED); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_MULTI_ACK)) { - caps->common = caps->multi_ack = 1; - ptr += strlen(GIT_CAP_MULTI_ACK); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_INCLUDE_TAG)) { - caps->common = caps->include_tag = 1; - ptr += strlen(GIT_CAP_INCLUDE_TAG); - continue; - } - - /* Keep side-band check after side-band-64k */ - if (!git__prefixcmp(ptr, GIT_CAP_SIDE_BAND_64K)) { - caps->common = caps->side_band_64k = 1; - ptr += strlen(GIT_CAP_SIDE_BAND_64K); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_SIDE_BAND)) { - caps->common = caps->side_band = 1; - ptr += strlen(GIT_CAP_SIDE_BAND); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_DELETE_REFS)) { - caps->common = caps->delete_refs = 1; - ptr += strlen(GIT_CAP_DELETE_REFS); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_PUSH_OPTIONS)) { - caps->common = caps->push_options = 1; - ptr += strlen(GIT_CAP_PUSH_OPTIONS); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_THIN_PACK)) { - caps->common = caps->thin_pack = 1; - ptr += strlen(GIT_CAP_THIN_PACK); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_SYMREF)) { - int error; - - if ((error = append_symref(&ptr, symrefs, ptr)) < 0) - return error; - - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_WANT_TIP_SHA1)) { - caps->common = caps->want_tip_sha1 = 1; - ptr += strlen(GIT_CAP_WANT_TIP_SHA1); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_WANT_REACHABLE_SHA1)) { - caps->common = caps->want_reachable_sha1 = 1; - ptr += strlen(GIT_CAP_WANT_REACHABLE_SHA1); - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_OBJECT_FORMAT)) { - ptr += strlen(GIT_CAP_OBJECT_FORMAT); - - start = ptr; - ptr = strchr(ptr, ' '); - - if ((caps->object_format = git__strndup(start, (ptr - start))) == NULL) - return -1; - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_AGENT)) { - ptr += strlen(GIT_CAP_AGENT); - - start = ptr; - ptr = strchr(ptr, ' '); - - if ((caps->agent = git__strndup(start, (ptr - start))) == NULL) - return -1; - continue; - } - - if (!git__prefixcmp(ptr, GIT_CAP_SHALLOW)) { - caps->common = caps->shallow = 1; - ptr += strlen(GIT_CAP_SHALLOW); - continue; - } - - /* We don't know this capability, so skip it */ - ptr = strchr(ptr, ' '); - } - - return 0; -} - -static int recv_pkt( - git_pkt **out_pkt, - git_pkt_type *out_type, - transport_smart *t) -{ - const char *ptr = t->buffer.data, *line_end = ptr; - git_pkt *pkt = NULL; - git_pkt_parse_data pkt_parse_data = { 0 }; - int error = 0, ret; - - pkt_parse_data.oid_type = t->owner->repo->oid_type; - pkt_parse_data.seen_capabilities = 1; - - do { - if (t->buffer.len > 0) - error = git_pkt_parse_line(&pkt, &line_end, ptr, - t->buffer.len, &pkt_parse_data); - else - error = GIT_EBUFS; - - if (error == 0) - break; /* return the pkt */ - - if (error < 0 && error != GIT_EBUFS) - return error; - - if ((ret = git_smart__recv(t)) < 0) { - return ret; - } else if (ret == 0) { - git_error_set(GIT_ERROR_NET, "could not read from remote repository"); - return GIT_EEOF; - } - } while (error); - - git_staticstr_consume(&t->buffer, line_end); - - if (out_type != NULL) - *out_type = pkt->type; - if (out_pkt != NULL) - *out_pkt = pkt; - else - git__free(pkt); - - return error; -} - -static int store_common(transport_smart *t) -{ - git_pkt *pkt = NULL; - int error; - - do { - if ((error = recv_pkt(&pkt, NULL, t)) < 0) - return error; - - if (t->rpc && (pkt->type == GIT_PKT_SHALLOW || - pkt->type == GIT_PKT_UNSHALLOW || - pkt->type == GIT_PKT_FLUSH)) { - git__free(pkt); - continue; - } - - if (pkt->type != GIT_PKT_ACK) { - git__free(pkt); - return 0; - } - - if (git_vector_insert(&t->common, pkt) < 0) { - git__free(pkt); - return -1; - } - } while (1); - - return 0; -} - -static int wait_while_ack(transport_smart *t) -{ - int error; - git_pkt *pkt = NULL; - git_pkt_ack *ack = NULL; - - while (1) { - git_pkt_free(pkt); - - if ((error = recv_pkt(&pkt, NULL, t)) < 0) - return error; - - if (pkt->type == GIT_PKT_NAK) - break; - if (pkt->type != GIT_PKT_ACK) - continue; - - ack = (git_pkt_ack*)pkt; - - if (ack->status != GIT_ACK_CONTINUE && - ack->status != GIT_ACK_COMMON && - ack->status != GIT_ACK_READY) { - break; - } - } - - git_pkt_free(pkt); - return 0; -} - -static int cap_not_sup_err(const char *cap_name) -{ - git_error_set(GIT_ERROR_NET, "server doesn't support %s", cap_name); - return GIT_EINVALID; -} - -/* Disables server capabilities we're not interested in */ -static int setup_caps( - transport_smart_caps *caps, - const git_fetch_negotiation *wants) -{ - if (wants->depth > 0) { - if (!caps->shallow) - return cap_not_sup_err(GIT_CAP_SHALLOW); - } else { - caps->shallow = 0; - } - - return 0; -} - -static int setup_shallow_roots( - git_array_oid_t *out, - const git_fetch_negotiation *wants) -{ - git_array_clear(*out); - - if (wants->shallow_roots_len > 0) { - git_array_init_to_size(*out, wants->shallow_roots_len); - GIT_ERROR_CHECK_ALLOC(out->ptr); - - memcpy(out->ptr, wants->shallow_roots, - sizeof(git_oid) * wants->shallow_roots_len); - out->size = wants->shallow_roots_len; - } - - return 0; -} - -int git_smart__negotiate_fetch( - git_transport *transport, - git_repository *repo, - const git_fetch_negotiation *wants) -{ - transport_smart *t = (transport_smart *)transport; - git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT; - git_str data = GIT_STR_INIT; - git_revwalk *walk = NULL; - int error = -1; - git_pkt_type pkt_type; - unsigned int i; - git_oid oid; - - if ((error = setup_caps(&t->caps, wants)) < 0 || - (error = setup_shallow_roots(&t->shallow_roots, wants)) < 0) - return error; - - if ((error = git_pkt_buffer_wants(wants, &t->caps, &data)) < 0) - return error; - - if ((error = git_revwalk_new(&walk, repo)) < 0) - goto on_error; - - opts.insert_by_date = 1; - if ((error = git_revwalk__push_glob(walk, "refs/*", &opts)) < 0) - goto on_error; - - if (wants->depth > 0) { - git_pkt_shallow *pkt; - - if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0) - goto on_error; - - if (!t->rpc) - git_str_clear(&data); - - while ((error = recv_pkt((git_pkt **)&pkt, NULL, t)) == 0) { - bool complete = false; - - if (pkt->type == GIT_PKT_SHALLOW) { - error = git_oidarray__add(&t->shallow_roots, &pkt->oid); - } else if (pkt->type == GIT_PKT_UNSHALLOW) { - git_oidarray__remove(&t->shallow_roots, &pkt->oid); - } else if (pkt->type == GIT_PKT_FLUSH) { - /* Server is done, stop processing shallow oids */ - complete = true; - } else { - git_error_set(GIT_ERROR_NET, "unexpected packet type"); - error = -1; - } - - git_pkt_free((git_pkt *) pkt); - - if (complete || error < 0) - break; - } - - if (error < 0) - goto on_error; - } - - /* - * Our support for ACK extensions is simply to parse them. On - * the first ACK we will accept that as enough common - * objects. We give up if we haven't found an answer in the - * first 256 we send. - */ - i = 0; - while (i < 256) { - error = git_revwalk_next(&oid, walk); - - if (error < 0) { - if (GIT_ITEROVER == error) - break; - - goto on_error; - } - - git_pkt_buffer_have(&oid, &data); - i++; - if (i % 20 == 0) { - if (t->cancelled.val) { - git_error_set(GIT_ERROR_NET, "The fetch was cancelled by the user"); - error = GIT_EUSER; - goto on_error; - } - - git_pkt_buffer_flush(&data); - if (git_str_oom(&data)) { - error = -1; - goto on_error; - } - - if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0) - goto on_error; - - git_str_clear(&data); - if (t->caps.multi_ack || t->caps.multi_ack_detailed) { - if ((error = store_common(t)) < 0) - goto on_error; - } else { - if ((error = recv_pkt(NULL, &pkt_type, t)) < 0) - goto on_error; - - if (pkt_type == GIT_PKT_ACK) { - break; - } else if (pkt_type == GIT_PKT_NAK) { - continue; - } else { - git_error_set(GIT_ERROR_NET, "unexpected pkt type"); - error = -1; - goto on_error; - } - } - } - - if (t->common.length > 0) - break; - - if (i % 20 == 0 && t->rpc) { - git_pkt_ack *pkt; - unsigned int j; - - if ((error = git_pkt_buffer_wants(wants, &t->caps, &data)) < 0) - goto on_error; - - git_vector_foreach(&t->common, j, pkt) { - if ((error = git_pkt_buffer_have(&pkt->oid, &data)) < 0) - goto on_error; - } - - if (git_str_oom(&data)) { - error = -1; - goto on_error; - } - } - } - - /* Tell the other end that we're done negotiating */ - if (t->rpc && t->common.length > 0) { - git_pkt_ack *pkt; - unsigned int j; - - if ((error = git_pkt_buffer_wants(wants, &t->caps, &data)) < 0) - goto on_error; - - git_vector_foreach(&t->common, j, pkt) { - if ((error = git_pkt_buffer_have(&pkt->oid, &data)) < 0) - goto on_error; - } - - if (git_str_oom(&data)) { - error = -1; - goto on_error; - } - } - - if ((error = git_pkt_buffer_done(&data)) < 0) - goto on_error; - - if (t->cancelled.val) { - git_error_set(GIT_ERROR_NET, "the fetch was cancelled"); - error = GIT_EUSER; - goto on_error; - } - - if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0) - goto on_error; - - git_str_dispose(&data); - git_revwalk_free(walk); - - /* Now let's eat up whatever the server gives us */ - if (!t->caps.multi_ack && !t->caps.multi_ack_detailed) { - if ((error = recv_pkt(NULL, &pkt_type, t)) < 0) - return error; - - if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) { - git_error_set(GIT_ERROR_NET, "unexpected pkt type"); - return -1; - } - } else { - error = wait_while_ack(t); - } - - return error; - -on_error: - git_revwalk_free(walk); - git_str_dispose(&data); - return error; -} - -int git_smart__shallow_roots(git_oidarray *out, git_transport *transport) -{ - transport_smart *t = (transport_smart *)transport; - size_t len; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&len, t->shallow_roots.size, sizeof(git_oid)); - - out->count = t->shallow_roots.size; - - if (len) { - out->ids = git__malloc(len); - memcpy(out->ids, t->shallow_roots.ptr, len); - } else { - out->ids = NULL; - } - - return 0; -} - -static int no_sideband( - transport_smart *t, - struct git_odb_writepack *writepack, - git_indexer_progress *stats) -{ - int recvd; - - do { - if (t->cancelled.val) { - git_error_set(GIT_ERROR_NET, "the fetch was cancelled by the user"); - return GIT_EUSER; - } - - if (writepack->append(writepack, t->buffer.data, t->buffer.len, stats) < 0) - return -1; - - git_staticstr_clear(&t->buffer); - - if ((recvd = git_smart__recv(t)) < 0) - return recvd; - } while(recvd > 0); - - if (writepack->commit(writepack, stats) < 0) - return -1; - - return 0; -} - -struct network_packetsize_payload -{ - git_indexer_progress_cb callback; - void *payload; - git_indexer_progress *stats; - size_t last_fired_bytes; -}; - -static int network_packetsize(size_t received, void *payload) -{ - struct network_packetsize_payload *npp = (struct network_packetsize_payload*)payload; - - /* Accumulate bytes */ - npp->stats->received_bytes += received; - - /* Fire notification if the threshold is reached */ - if ((npp->stats->received_bytes - npp->last_fired_bytes) > NETWORK_XFER_THRESHOLD) { - npp->last_fired_bytes = npp->stats->received_bytes; - - if (npp->callback(npp->stats, npp->payload)) - return GIT_EUSER; - } - - return 0; -} - -int git_smart__download_pack( - git_transport *transport, - git_repository *repo, - git_indexer_progress *stats) -{ - transport_smart *t = (transport_smart *)transport; - git_odb *odb; - struct git_odb_writepack *writepack = NULL; - int error = 0; - struct network_packetsize_payload npp = {0}; - - git_indexer_progress_cb progress_cb = t->connect_opts.callbacks.transfer_progress; - void *progress_payload = t->connect_opts.callbacks.payload; - - memset(stats, 0, sizeof(git_indexer_progress)); - - if (progress_cb) { - npp.callback = progress_cb; - npp.payload = progress_payload; - npp.stats = stats; - t->packetsize_cb = &network_packetsize; - t->packetsize_payload = &npp; - - /* We might have something in the buffer already from negotiate_fetch */ - if (t->buffer.len > 0 && !t->cancelled.val) { - if (t->packetsize_cb(t->buffer.len, t->packetsize_payload)) - git_atomic32_set(&t->cancelled, 1); - } - } - - if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 || - ((error = git_odb_write_pack(&writepack, odb, progress_cb, progress_payload)) != 0)) - goto done; - - /* - * If the remote doesn't support the side-band, we can feed - * the data directly to the pack writer. Otherwise, we need to - * check which one belongs there. - */ - if (!t->caps.side_band && !t->caps.side_band_64k) { - error = no_sideband(t, writepack, stats); - goto done; - } - - do { - git_pkt *pkt = NULL; - - /* Check cancellation before network call */ - if (t->cancelled.val) { - git_error_clear(); - error = GIT_EUSER; - goto done; - } - - if ((error = recv_pkt(&pkt, NULL, t)) >= 0) { - /* Check cancellation after network call */ - if (t->cancelled.val) { - git_error_clear(); - error = GIT_EUSER; - } else if (pkt->type == GIT_PKT_PROGRESS) { - if (t->connect_opts.callbacks.sideband_progress) { - git_pkt_progress *p = (git_pkt_progress *) pkt; - - if (p->len > INT_MAX) { - git_error_set(GIT_ERROR_NET, "oversized progress message"); - error = GIT_ERROR; - goto done; - } - - error = t->connect_opts.callbacks.sideband_progress(p->data, (int)p->len, t->connect_opts.callbacks.payload); - } - } else if (pkt->type == GIT_PKT_DATA) { - git_pkt_data *p = (git_pkt_data *) pkt; - - if (p->len) - error = writepack->append(writepack, p->data, p->len, stats); - } else if (pkt->type == GIT_PKT_FLUSH) { - /* A flush indicates the end of the packfile */ - git__free(pkt); - break; - } - } - - git_pkt_free(pkt); - - if (error < 0) - goto done; - - } while (1); - - /* - * Trailing execution of progress_cb, if necessary... - * Only the callback through the npp datastructure currently - * updates the last_fired_bytes value. It is possible that - * progress has already been reported with the correct - * "received_bytes" value, but until (if?) this is unified - * then we will report progress again to be sure that the - * correct last received_bytes value is reported. - */ - if (npp.callback && npp.stats->received_bytes > npp.last_fired_bytes) { - error = npp.callback(npp.stats, npp.payload); - if (error != 0) - goto done; - } - - error = writepack->commit(writepack, stats); - -done: - if (writepack) - writepack->free(writepack); - if (progress_cb) { - t->packetsize_cb = NULL; - t->packetsize_payload = NULL; - } - - return error; -} - -static int gen_pktline(git_str *buf, git_push *push) -{ - push_spec *spec; - char *option; - size_t i, len; - char old_id[GIT_OID_MAX_HEXSIZE + 1], new_id[GIT_OID_MAX_HEXSIZE + 1]; - size_t old_id_len, new_id_len; - - git_vector_foreach(&push->specs, i, spec) { - len = strlen(spec->refspec.dst) + 7; - - if (i == 0) { - /* Need a leading \0 */ - ++len; - - if (push->report_status) - len += strlen(GIT_CAP_REPORT_STATUS) + 1; - - if (git_vector_length(&push->remote_push_options) > 0) - len += strlen(GIT_CAP_PUSH_OPTIONS) + 1; - - len += strlen(GIT_CAP_SIDE_BAND_64K) + 1; - } - - old_id_len = git_oid_hexsize(git_oid_type(&spec->roid)); - new_id_len = git_oid_hexsize(git_oid_type(&spec->loid)); - - len += (old_id_len + new_id_len); - - git_oid_fmt(old_id, &spec->roid); - old_id[old_id_len] = '\0'; - - git_oid_fmt(new_id, &spec->loid); - new_id[new_id_len] = '\0'; - - git_str_printf(buf, "%04"PRIxZ"%.*s %.*s %s", len, - (int)old_id_len, old_id, (int)new_id_len, new_id, - spec->refspec.dst); - - if (i == 0) { - git_str_putc(buf, '\0'); - - /* Core git always starts their capabilities string with a space */ - if (push->report_status) { - git_str_putc(buf, ' '); - git_str_printf(buf, GIT_CAP_REPORT_STATUS); - } - if (git_vector_length(&push->remote_push_options) > 0) { - git_str_putc(buf, ' '); - git_str_printf(buf, GIT_CAP_PUSH_OPTIONS); - } - git_str_putc(buf, ' '); - git_str_printf(buf, GIT_CAP_SIDE_BAND_64K); - } - - git_str_putc(buf, '\n'); - } - - if (git_vector_length(&push->remote_push_options) > 0) { - git_str_printf(buf, "0000"); - git_vector_foreach(&push->remote_push_options, i, option) { - git_str_printf(buf, "%04"PRIxZ"%s", strlen(option) + 4 , option); - } - } - - git_str_puts(buf, "0000"); - return git_str_oom(buf) ? -1 : 0; -} - -static int add_push_report_pkt(git_push *push, git_pkt *pkt) -{ - push_status *status; - - switch (pkt->type) { - case GIT_PKT_OK: - status = git__calloc(1, sizeof(push_status)); - GIT_ERROR_CHECK_ALLOC(status); - status->msg = NULL; - status->ref = git__strdup(((git_pkt_ok *)pkt)->ref); - if (!status->ref || - git_vector_insert(&push->status, status) < 0) { - git_push_status_free(status); - return -1; - } - break; - case GIT_PKT_NG: - status = git__calloc(1, sizeof(push_status)); - GIT_ERROR_CHECK_ALLOC(status); - status->ref = git__strdup(((git_pkt_ng *)pkt)->ref); - status->msg = git__strdup(((git_pkt_ng *)pkt)->msg); - if (!status->ref || !status->msg || - git_vector_insert(&push->status, status) < 0) { - git_push_status_free(status); - return -1; - } - break; - case GIT_PKT_UNPACK: - push->unpack_ok = ((git_pkt_unpack *)pkt)->unpack_ok; - break; - case GIT_PKT_FLUSH: - return GIT_ITEROVER; - default: - git_error_set(GIT_ERROR_NET, "report-status: protocol error"); - return -1; - } - - return 0; -} - -static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt, git_str *data_pkt_buf) -{ - git_pkt *pkt; - git_pkt_parse_data pkt_parse_data = { 0 }; - const char *line, *line_end = NULL; - size_t line_len; - int error; - int reading_from_buf = data_pkt_buf->size > 0; - - if (reading_from_buf) { - /* We had an existing partial packet, so add the new - * packet to the buffer and parse the whole thing */ - git_str_put(data_pkt_buf, data_pkt->data, data_pkt->len); - line = data_pkt_buf->ptr; - line_len = data_pkt_buf->size; - } - else { - line = data_pkt->data; - line_len = data_pkt->len; - } - - while (line_len > 0) { - error = git_pkt_parse_line(&pkt, &line_end, line, line_len, &pkt_parse_data); - - if (error == GIT_EBUFS) { - /* Buffer the data when the inner packet is split - * across multiple sideband packets */ - if (!reading_from_buf) - git_str_put(data_pkt_buf, line, line_len); - error = 0; - goto done; - } - else if (error < 0) - goto done; - - /* Advance in the buffer */ - line_len -= (line_end - line); - line = line_end; - - error = add_push_report_pkt(push, pkt); - - git_pkt_free(pkt); - - if (error < 0 && error != GIT_ITEROVER) - goto done; - } - - error = 0; - -done: - if (reading_from_buf) - git_str_consume(data_pkt_buf, line_end); - return error; -} - -static int parse_report(transport_smart *transport, git_push *push) -{ - git_pkt *pkt = NULL; - git_pkt_parse_data pkt_parse_data = { 0 }; - const char *line_end = NULL; - int error, recvd; - git_str data_pkt_buf = GIT_STR_INIT; - - for (;;) { - if (transport->buffer.len > 0) - error = git_pkt_parse_line(&pkt, &line_end, - transport->buffer.data, - transport->buffer.len, - &pkt_parse_data); - else - error = GIT_EBUFS; - - if (error < 0 && error != GIT_EBUFS) { - error = -1; - goto done; - } - - if (error == GIT_EBUFS) { - if ((recvd = git_smart__recv(transport)) < 0) { - error = recvd; - goto done; - } - - if (recvd == 0) { - git_error_set(GIT_ERROR_NET, "could not read report from remote repository"); - error = GIT_EEOF; - goto done; - } - continue; - } - - git_staticstr_consume(&transport->buffer, line_end); - error = 0; - - switch (pkt->type) { - case GIT_PKT_DATA: - /* This is a sideband packet which contains other packets */ - error = add_push_report_sideband_pkt(push, (git_pkt_data *)pkt, &data_pkt_buf); - break; - case GIT_PKT_ERR: - git_error_set(GIT_ERROR_NET, "report-status: Error reported: %s", - ((git_pkt_err *)pkt)->error); - error = -1; - break; - case GIT_PKT_PROGRESS: - if (transport->connect_opts.callbacks.sideband_progress) { - git_pkt_progress *p = (git_pkt_progress *) pkt; - - if (p->len > INT_MAX) { - git_error_set(GIT_ERROR_NET, "oversized progress message"); - error = GIT_ERROR; - goto done; - } - - error = transport->connect_opts.callbacks.sideband_progress(p->data, (int)p->len, transport->connect_opts.callbacks.payload); - } - break; - default: - error = add_push_report_pkt(push, pkt); - break; - } - - git_pkt_free(pkt); - - /* add_push_report_pkt returns GIT_ITEROVER when it receives a flush */ - if (error == GIT_ITEROVER) { - error = 0; - if (data_pkt_buf.size > 0) { - /* If there was data remaining in the pack data buffer, - * then the server sent a partial pkt-line */ - git_error_set(GIT_ERROR_NET, "incomplete pack data pkt-line"); - error = GIT_ERROR; - } - goto done; - } - - if (error < 0) { - goto done; - } - } -done: - git_str_dispose(&data_pkt_buf); - return error; -} - -static int add_ref_from_push_spec(git_vector *refs, push_spec *push_spec) -{ - git_pkt_ref *added = git__calloc(1, sizeof(git_pkt_ref)); - GIT_ERROR_CHECK_ALLOC(added); - - added->type = GIT_PKT_REF; - git_oid_cpy(&added->head.oid, &push_spec->loid); - added->head.name = git__strdup(push_spec->refspec.dst); - - if (!added->head.name || - git_vector_insert(refs, added) < 0) { - git_pkt_free((git_pkt *)added); - return -1; - } - - return 0; -} - -static int update_refs_from_report( - git_vector *refs, - git_vector *push_specs, - git_vector *push_report) -{ - git_pkt_ref *ref; - push_spec *push_spec; - push_status *push_status; - size_t i, j, refs_len; - int cmp; - - /* For each push spec we sent to the server, we should have - * gotten back a status packet in the push report */ - if (push_specs->length != push_report->length) { - git_error_set(GIT_ERROR_NET, "report-status: protocol error"); - return -1; - } - - /* We require that push_specs be sorted with push_spec_rref_cmp, - * and that push_report be sorted with push_status_ref_cmp */ - git_vector_sort(push_specs); - git_vector_sort(push_report); - - git_vector_foreach(push_specs, i, push_spec) { - push_status = git_vector_get(push_report, i); - - /* For each push spec we sent to the server, we should have - * gotten back a status packet in the push report which matches */ - if (strcmp(push_spec->refspec.dst, push_status->ref)) { - git_error_set(GIT_ERROR_NET, "report-status: protocol error"); - return -1; - } - } - - /* We require that refs be sorted with ref_name_cmp */ - git_vector_sort(refs); - i = j = 0; - refs_len = refs->length; - - /* Merge join push_specs with refs */ - while (i < push_specs->length && j < refs_len) { - push_spec = git_vector_get(push_specs, i); - push_status = git_vector_get(push_report, i); - ref = git_vector_get(refs, j); - - cmp = strcmp(push_spec->refspec.dst, ref->head.name); - - /* Iterate appropriately */ - if (cmp <= 0) i++; - if (cmp >= 0) j++; - - /* Add case */ - if (cmp < 0 && - !push_status->msg && - add_ref_from_push_spec(refs, push_spec) < 0) - return -1; - - /* Update case, delete case */ - if (cmp == 0 && - !push_status->msg) - git_oid_cpy(&ref->head.oid, &push_spec->loid); - } - - for (; i < push_specs->length; i++) { - push_spec = git_vector_get(push_specs, i); - push_status = git_vector_get(push_report, i); - - /* Add case */ - if (!push_status->msg && - add_ref_from_push_spec(refs, push_spec) < 0) - return -1; - } - - /* Remove any refs which we updated to have a zero OID. */ - git_vector_rforeach(refs, i, ref) { - if (git_oid_is_zero(&ref->head.oid)) { - git_vector_remove(refs, i); - git_pkt_free((git_pkt *)ref); - } - } - - git_vector_sort(refs); - - return 0; -} - -struct push_packbuilder_payload -{ - git_smart_subtransport_stream *stream; - git_packbuilder *pb; - git_push_transfer_progress_cb cb; - void *cb_payload; - size_t last_bytes; - uint64_t last_progress_report_time; -}; - -static int stream_thunk(void *buf, size_t size, void *data) -{ - int error = 0; - struct push_packbuilder_payload *payload = data; - - if ((error = payload->stream->write(payload->stream, (const char *)buf, size)) < 0) - return error; - - if (payload->cb) { - uint64_t current_time = git_time_monotonic(); - uint64_t elapsed = current_time - payload->last_progress_report_time; - payload->last_bytes += size; - - if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) { - payload->last_progress_report_time = current_time; - error = payload->cb(payload->pb->nr_written, payload->pb->nr_objects, payload->last_bytes, payload->cb_payload); - } - } - - return error; -} - -int git_smart__push(git_transport *transport, git_push *push) -{ - transport_smart *t = (transport_smart *)transport; - git_remote_callbacks *cbs = &t->connect_opts.callbacks; - struct push_packbuilder_payload packbuilder_payload = {0}; - git_str pktline = GIT_STR_INIT; - int error = 0, need_pack = 0; - push_spec *spec; - unsigned int i; - - packbuilder_payload.pb = push->pb; - - if (cbs && cbs->push_transfer_progress) { - packbuilder_payload.cb = cbs->push_transfer_progress; - packbuilder_payload.cb_payload = cbs->payload; - } - -#ifdef PUSH_DEBUG -{ - git_remote_head *head; - char hex[GIT_OID_MAX_HEXSIZE+1], hex[GIT_OID_MAX_HEXSIZE] = '\0'; - - git_vector_foreach(&push->remote->refs, i, head) { - git_oid_fmt(hex, &head->oid); - fprintf(stderr, "%s (%s)\n", hex, head->name); - } - - git_vector_foreach(&push->specs, i, spec) { - git_oid_fmt(hex, &spec->roid); - fprintf(stderr, "%s (%s) -> ", hex, spec->lref); - git_oid_fmt(hex, &spec->loid); - fprintf(stderr, "%s (%s)\n", hex, spec->rref ? - spec->rref : spec->lref); - } -} -#endif - - /* - * Figure out if we need to send a packfile; which is in all - * cases except when we only send delete commands - */ - git_vector_foreach(&push->specs, i, spec) { - if (spec->refspec.src && spec->refspec.src[0] != '\0') { - need_pack = 1; - break; - } - } - - /* prepare pack before sending pack header to avoid timeouts */ - if (need_pack && ((error = git_packbuilder__prepare(push->pb))) < 0) - goto done; - - if ((error = git_smart__get_push_stream(t, &packbuilder_payload.stream)) < 0 || - (error = gen_pktline(&pktline, push)) < 0 || - (error = packbuilder_payload.stream->write(packbuilder_payload.stream, git_str_cstr(&pktline), git_str_len(&pktline))) < 0) - goto done; - - if (need_pack && - (error = git_packbuilder_foreach(push->pb, &stream_thunk, &packbuilder_payload)) < 0) - goto done; - - /* If we sent nothing or the server doesn't support report-status, then - * we consider the pack to have been unpacked successfully */ - if (!push->specs.length || !push->report_status) - push->unpack_ok = 1; - else if ((error = parse_report(t, push)) < 0) - goto done; - - /* If progress is being reported write the final report */ - if (cbs && cbs->push_transfer_progress) { - error = cbs->push_transfer_progress( - push->pb->nr_written, - push->pb->nr_objects, - packbuilder_payload.last_bytes, - cbs->payload); - - if (error < 0) - goto done; - } - - if (push->status.length) { - error = update_refs_from_report(&t->refs, &push->specs, &push->status); - if (error < 0) - goto done; - - error = git_smart__update_heads(t, NULL); - } - -done: - git_str_dispose(&pktline); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh.c deleted file mode 100644 index 3f3a127..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "ssh_exec.h" -#include "ssh_libssh2.h" - -#include "transports/smart.h" - -int git_smart_subtransport_ssh( - git_smart_subtransport **out, - git_transport *owner, - void *param) -{ -#ifdef GIT_SSH_LIBSSH2 - return git_smart_subtransport_ssh_libssh2(out, owner, param); -#elif GIT_SSH_EXEC - return git_smart_subtransport_ssh_exec(out, owner, param); -#else - GIT_UNUSED(out); - GIT_UNUSED(owner); - GIT_UNUSED(param); - - git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport; library was built without SSH support"); - return -1; -#endif -} - -static int transport_set_paths(git_transport *t, git_strarray *paths) -{ - transport_smart *smart = (transport_smart *)t; - -#ifdef GIT_SSH_LIBSSH2 - return git_smart_subtransport_ssh_libssh2_set_paths( - (git_smart_subtransport *)smart->wrapped, - paths->strings[0], - paths->strings[1]); -#elif GIT_SSH_EXEC - return git_smart_subtransport_ssh_exec_set_paths( - (git_smart_subtransport *)smart->wrapped, - paths->strings[0], - paths->strings[1]); -#else - GIT_UNUSED(t); - GIT_UNUSED(smart); - GIT_UNUSED(paths); - - GIT_ASSERT(!"cannot create SSH library; library was built without SSH support"); - return -1; -#endif -} - -int git_transport_ssh_with_paths( - git_transport **out, - git_remote *owner, - void *payload) -{ - git_strarray *paths = (git_strarray *) payload; - git_transport *transport; - int error; - - git_smart_subtransport_definition ssh_definition = { - git_smart_subtransport_ssh, - 0, /* no RPC */ - NULL - }; - - if (paths->count != 2) { - git_error_set(GIT_ERROR_SSH, "invalid ssh paths, must be two strings"); - return GIT_EINVALIDSPEC; - } - - if ((error = git_transport_smart(&transport, owner, &ssh_definition)) < 0) - return error; - - if ((error = transport_set_paths(transport, paths)) < 0) - return error; - - *out = transport; - return 0; -} - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_exec.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_exec.c deleted file mode 100644 index 91d46a3..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_exec.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "ssh_exec.h" - -#ifdef GIT_SSH_EXEC - -#include "common.h" - -#include "config.h" -#include "net.h" -#include "path.h" -#include "futils.h" -#include "process.h" -#include "transports/smart.h" - -typedef struct { - git_smart_subtransport_stream parent; -} ssh_exec_subtransport_stream; - -typedef struct { - git_smart_subtransport parent; - git_transport *owner; - - ssh_exec_subtransport_stream *current_stream; - - char *cmd_uploadpack; - char *cmd_receivepack; - - git_smart_service_t action; - git_process *process; -} ssh_exec_subtransport; - -static int ssh_exec_subtransport_stream_read( - git_smart_subtransport_stream *s, - char *buffer, - size_t buf_size, - size_t *bytes_read) -{ - ssh_exec_subtransport *transport; - ssh_exec_subtransport_stream *stream = (ssh_exec_subtransport_stream *)s; - ssize_t ret; - - GIT_ASSERT_ARG(stream); - GIT_ASSERT(stream->parent.subtransport); - - transport = (ssh_exec_subtransport *)stream->parent.subtransport; - - if ((ret = git_process_read(transport->process, buffer, buf_size)) < 0) { - return (int)ret; - } - - *bytes_read = (size_t)ret; - return 0; -} - -static int ssh_exec_subtransport_stream_write( - git_smart_subtransport_stream *s, - const char *buffer, - size_t len) -{ - ssh_exec_subtransport *transport; - ssh_exec_subtransport_stream *stream = (ssh_exec_subtransport_stream *)s; - ssize_t ret; - - GIT_ASSERT(stream && stream->parent.subtransport); - - transport = (ssh_exec_subtransport *)stream->parent.subtransport; - - while (len > 0) { - if ((ret = git_process_write(transport->process, buffer, len)) < 0) - return (int)ret; - - len -= ret; - } - - return 0; -} - -static void ssh_exec_subtransport_stream_free(git_smart_subtransport_stream *s) -{ - ssh_exec_subtransport_stream *stream = (ssh_exec_subtransport_stream *)s; - - git__free(stream); -} - -static int ssh_exec_subtransport_stream_init( - ssh_exec_subtransport_stream **out, - ssh_exec_subtransport *transport) -{ - GIT_ASSERT_ARG(out); - - *out = git__calloc(sizeof(ssh_exec_subtransport_stream), 1); - GIT_ERROR_CHECK_ALLOC(*out); - - (*out)->parent.subtransport = &transport->parent; - (*out)->parent.read = ssh_exec_subtransport_stream_read; - (*out)->parent.write = ssh_exec_subtransport_stream_write; - (*out)->parent.free = ssh_exec_subtransport_stream_free; - - return 0; -} - -GIT_INLINE(int) ensure_transport_state( - ssh_exec_subtransport *transport, - git_smart_service_t expected, - git_smart_service_t next) -{ - if (transport->action != expected && transport->action != next) { - git_error_set(GIT_ERROR_NET, "invalid transport state"); - - return -1; - } - - return 0; -} - -static int get_ssh_cmdline( - git_vector *args, - bool *use_shell, - ssh_exec_subtransport *transport, - git_net_url *url, - const char *command) -{ - git_remote *remote = ((transport_smart *)transport->owner)->owner; - git_repository *repo = remote->repo; - git_config *cfg; - git_str ssh_cmd = GIT_STR_INIT, url_and_host = GIT_STR_INIT, - remote_cmd = GIT_STR_INIT; - const char *default_ssh_cmd = "ssh"; - int error; - - /* - * Safety check: like git, we forbid paths that look like an - * option as that could lead to injection to ssh that can make - * us do unexpected things - */ - if (git_process__is_cmdline_option(url->username)) { - git_error_set(GIT_ERROR_NET, "cannot ssh: username '%s' is ambiguous with command-line option", url->username); - return -1; - } else if (git_process__is_cmdline_option(url->host)) { - git_error_set(GIT_ERROR_NET, "cannot ssh: host '%s' is ambiguous with command-line option", url->host); - return -1; - } else if (git_process__is_cmdline_option(url->path)) { - git_error_set(GIT_ERROR_NET, "cannot ssh: path '%s' is ambiguous with command-line option", url->path); - return -1; - } - - if ((error = git_repository_config_snapshot(&cfg, repo)) < 0) - return error; - - if ((error = git__getenv(&ssh_cmd, "GIT_SSH_COMMAND")) == 0) - *use_shell = true; - else if (error != GIT_ENOTFOUND) - goto done; - else if ((error = git__getenv(&ssh_cmd, "GIT_SSH")) == 0) - *use_shell = false; - else if (error != GIT_ENOTFOUND) - goto done; - else if ((error = git_config__get_string_buf(&ssh_cmd, cfg, "core.sshcommand")) < 0 && error != GIT_ENOTFOUND) - goto done; - - git_error_clear(); - - if (!ssh_cmd.size && - git_str_puts(&ssh_cmd, default_ssh_cmd) < 0) - goto done; - - if ((error = git_vector_insert(args, git_str_detach(&ssh_cmd))) < 0) - goto done; - - if (url->port_specified) { - char *p = git__strdup("-p"); - char *port = git__strdup(url->port); - - if (!p || !port || - (error = git_vector_insert(args, p)) < 0 || - (error = git_vector_insert(args, port)) < 0) - goto done; - } - - if (url->username) { - if ((error = git_str_puts(&url_and_host, url->username)) < 0 || - (error = git_str_putc(&url_and_host, '@')) < 0) - goto done; - } - - if ((error = git_str_puts(&url_and_host, url->host)) < 0 || - (error = git_vector_insert(args, git_str_detach(&url_and_host))) < 0) - goto done; - - if ((error = git_str_puts(&remote_cmd, command)) < 0 || - (error = git_str_puts(&remote_cmd, " '")) < 0 || - (error = git_str_puts_escaped(&remote_cmd, url->path, "'!", "'\\", "'")) < 0 || - (error = git_str_puts(&remote_cmd, "'")) < 0 || - (error = git_vector_insert(args, git_str_detach(&remote_cmd))) < 0) - goto done; - -done: - git_str_dispose(&ssh_cmd); - git_str_dispose(&url_and_host); - git_str_dispose(&remote_cmd); - git_config_free(cfg); - return error; -} - -static int start_ssh( - ssh_exec_subtransport *transport, - git_smart_service_t action, - const char *sshpath) -{ - const char *env[] = { "GIT_DIR=" }; - - git_process_options process_opts = GIT_PROCESS_OPTIONS_INIT; - git_net_url url = GIT_NET_URL_INIT; - git_vector args = GIT_VECTOR_INIT; - bool use_shell = false; - const char *command; - int error; - - process_opts.capture_in = 1; - process_opts.capture_out = 1; - process_opts.capture_err = 0; - - switch (action) { - case GIT_SERVICE_UPLOADPACK_LS: - command = transport->cmd_uploadpack ? - transport->cmd_uploadpack : "git-upload-pack"; - break; - case GIT_SERVICE_RECEIVEPACK_LS: - command = transport->cmd_receivepack ? - transport->cmd_receivepack : "git-receive-pack"; - break; - default: - git_error_set(GIT_ERROR_NET, "invalid action"); - error = -1; - goto done; - } - - if (git_net_str_is_url(sshpath)) - error = git_net_url_parse(&url, sshpath); - else - error = git_net_url_parse_scp(&url, sshpath); - - if (error < 0) - goto done; - - if ((error = get_ssh_cmdline(&args, &use_shell, - transport, &url, command)) < 0) - goto done; - - process_opts.use_shell = use_shell; - - if ((error = git_process_new(&transport->process, - (const char **)args.contents, args.length, - env, ARRAY_SIZE(env), &process_opts)) < 0 || - (error = git_process_start(transport->process)) < 0) { - git_process_free(transport->process); - transport->process = NULL; - goto done; - } - -done: - git_vector_dispose_deep(&args); - git_net_url_dispose(&url); - return error; -} - -static int ssh_exec_subtransport_action( - git_smart_subtransport_stream **out, - git_smart_subtransport *t, - const char *sshpath, - git_smart_service_t action) -{ - ssh_exec_subtransport *transport = (ssh_exec_subtransport *)t; - ssh_exec_subtransport_stream *stream = NULL; - git_smart_service_t expected; - int error; - - switch (action) { - case GIT_SERVICE_UPLOADPACK_LS: - case GIT_SERVICE_RECEIVEPACK_LS: - if ((error = ensure_transport_state(transport, 0, 0)) < 0 || - (error = ssh_exec_subtransport_stream_init(&stream, transport)) < 0 || - (error = start_ssh(transport, action, sshpath)) < 0) - goto on_error; - - transport->current_stream = stream; - break; - - case GIT_SERVICE_UPLOADPACK: - case GIT_SERVICE_RECEIVEPACK: - expected = (action == GIT_SERVICE_UPLOADPACK) ? - GIT_SERVICE_UPLOADPACK_LS : GIT_SERVICE_RECEIVEPACK_LS; - - if ((error = ensure_transport_state(transport, expected, action)) < 0) - goto on_error; - - break; - - default: - git_error_set(GIT_ERROR_INVALID, "invalid service request"); - goto on_error; - } - - transport->action = action; - *out = &transport->current_stream->parent; - - return 0; - -on_error: - if (stream != NULL) - ssh_exec_subtransport_stream_free(&stream->parent); - - return -1; -} - -static int ssh_exec_subtransport_close(git_smart_subtransport *t) -{ - ssh_exec_subtransport *transport = (ssh_exec_subtransport *)t; - - if (transport->process) { - git_process_close(transport->process); - git_process_free(transport->process); - transport->process = NULL; - } - - transport->action = 0; - - return 0; -} - -static void ssh_exec_subtransport_free(git_smart_subtransport *t) -{ - ssh_exec_subtransport *transport = (ssh_exec_subtransport *)t; - - git__free(transport->cmd_uploadpack); - git__free(transport->cmd_receivepack); - git__free(transport); -} - -int git_smart_subtransport_ssh_exec( - git_smart_subtransport **out, - git_transport *owner, - void *payload) -{ - ssh_exec_subtransport *transport; - - GIT_UNUSED(payload); - - transport = git__calloc(sizeof(ssh_exec_subtransport), 1); - GIT_ERROR_CHECK_ALLOC(transport); - - transport->owner = owner; - transport->parent.action = ssh_exec_subtransport_action; - transport->parent.close = ssh_exec_subtransport_close; - transport->parent.free = ssh_exec_subtransport_free; - - *out = (git_smart_subtransport *) transport; - return 0; -} - -int git_smart_subtransport_ssh_exec_set_paths( - git_smart_subtransport *subtransport, - const char *cmd_uploadpack, - const char *cmd_receivepack) -{ - ssh_exec_subtransport *t = (ssh_exec_subtransport *)subtransport; - - git__free(t->cmd_uploadpack); - git__free(t->cmd_receivepack); - - t->cmd_uploadpack = git__strdup(cmd_uploadpack); - GIT_ERROR_CHECK_ALLOC(t->cmd_uploadpack); - - t->cmd_receivepack = git__strdup(cmd_receivepack); - GIT_ERROR_CHECK_ALLOC(t->cmd_receivepack); - - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_exec.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_exec.h deleted file mode 100644 index 4bcba06..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_exec.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_transports_ssh_exec_h__ -#define INCLUDE_transports_ssh_exec_h__ - -#include "common.h" - -#include "git2.h" -#include "git2/transport.h" -#include "git2/sys/transport.h" - -int git_smart_subtransport_ssh_exec( - git_smart_subtransport **out, - git_transport *owner, - void *param); - -int git_smart_subtransport_ssh_exec_set_paths( - git_smart_subtransport *subtransport, - const char *cmd_uploadpack, - const char *cmd_receivepack); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_libssh2.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_libssh2.c deleted file mode 100644 index f83eb1e..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_libssh2.c +++ /dev/null @@ -1,1132 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "ssh_libssh2.h" - -#ifdef GIT_SSH_LIBSSH2 - -#include - -#include "runtime.h" -#include "net.h" -#include "smart.h" -#include "process.h" -#include "streams/socket.h" -#include "sysdir.h" - -#include "git2/credential.h" -#include "git2/sys/credential.h" - -#define OWNING_SUBTRANSPORT(s) ((ssh_subtransport *)(s)->parent.subtransport) - -extern int git_socket_stream__timeout; - -static const char cmd_uploadpack[] = "git-upload-pack"; -static const char cmd_receivepack[] = "git-receive-pack"; - -typedef struct { - git_smart_subtransport_stream parent; - git_stream *io; - LIBSSH2_SESSION *session; - LIBSSH2_CHANNEL *channel; - const char *cmd; - git_net_url url; - unsigned sent_command : 1; -} ssh_stream; - -typedef struct { - git_smart_subtransport parent; - transport_smart *owner; - ssh_stream *current_stream; - git_credential *cred; - char *cmd_uploadpack; - char *cmd_receivepack; -} ssh_subtransport; - -static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *username); - -static void ssh_error(LIBSSH2_SESSION *session, const char *errmsg) -{ - char *ssherr; - libssh2_session_last_error(session, &ssherr, NULL, 0); - - git_error_set(GIT_ERROR_SSH, "%s: %s", errmsg, ssherr); -} - -/* - * Create a git protocol request. - * - * For example: git-upload-pack '/libgit2/libgit2' - */ -static int gen_proto(git_str *request, const char *cmd, git_net_url *url) -{ - const char *repo; - - repo = url->path; - - if (repo && repo[0] == '/' && repo[1] == '~') - repo++; - - if (!repo || !repo[0]) { - git_error_set(GIT_ERROR_NET, "malformed git protocol URL"); - return -1; - } - - git_str_puts(request, cmd); - git_str_puts(request, " '"); - git_str_puts_escaped(request, repo, "'!", "'\\", "'"); - git_str_puts(request, "'"); - - if (git_str_oom(request)) - return -1; - - return 0; -} - -static int send_command(ssh_stream *s) -{ - int error; - git_str request = GIT_STR_INIT; - - error = gen_proto(&request, s->cmd, &s->url); - if (error < 0) - goto cleanup; - - error = libssh2_channel_exec(s->channel, request.ptr); - if (error < LIBSSH2_ERROR_NONE) { - ssh_error(s->session, "SSH could not execute request"); - goto cleanup; - } - - s->sent_command = 1; - -cleanup: - git_str_dispose(&request); - return error; -} - -static int ssh_stream_read( - git_smart_subtransport_stream *stream, - char *buffer, - size_t buf_size, - size_t *bytes_read) -{ - ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent); - ssize_t rc; - - *bytes_read = 0; - - if (!s->sent_command && send_command(s) < 0) - return -1; - - if ((rc = libssh2_channel_read(s->channel, buffer, buf_size)) < LIBSSH2_ERROR_NONE) { - ssh_error(s->session, "SSH could not read data"); - return -1; - } - - /* - * If we can't get anything out of stdout, it's typically a - * not-found error, so read from stderr and signal EOF on - * stderr. - */ - if (rc == 0) { - if ((rc = libssh2_channel_read_stderr(s->channel, buffer, buf_size)) > 0) { - git_error_set(GIT_ERROR_SSH, "%*s", (int)rc, buffer); - return GIT_EEOF; - } else if (rc < LIBSSH2_ERROR_NONE) { - ssh_error(s->session, "SSH could not read stderr"); - return -1; - } - } - - *bytes_read = rc; - - return 0; -} - -static int ssh_stream_write( - git_smart_subtransport_stream *stream, - const char *buffer, - size_t len) -{ - ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent); - size_t off = 0; - ssize_t ret = 0; - - if (!s->sent_command && send_command(s) < 0) - return -1; - - do { - ret = libssh2_channel_write(s->channel, buffer + off, len - off); - if (ret < 0) - break; - - off += ret; - - } while (off < len); - - if (ret < 0) { - ssh_error(s->session, "SSH could not write data"); - return -1; - } - - return 0; -} - -static void ssh_stream_free(git_smart_subtransport_stream *stream) -{ - ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent); - ssh_subtransport *t; - - if (!stream) - return; - - t = OWNING_SUBTRANSPORT(s); - t->current_stream = NULL; - - if (s->channel) { - libssh2_channel_close(s->channel); - libssh2_channel_free(s->channel); - s->channel = NULL; - } - - if (s->session) { - libssh2_session_disconnect(s->session, "closing transport"); - libssh2_session_free(s->session); - s->session = NULL; - } - - if (s->io) { - git_stream_close(s->io); - git_stream_free(s->io); - s->io = NULL; - } - - git_net_url_dispose(&s->url); - git__free(s); -} - -static int ssh_stream_alloc( - ssh_subtransport *t, - const char *cmd, - git_smart_subtransport_stream **stream) -{ - ssh_stream *s; - - GIT_ASSERT_ARG(stream); - - s = git__calloc(sizeof(ssh_stream), 1); - GIT_ERROR_CHECK_ALLOC(s); - - s->parent.subtransport = &t->parent; - s->parent.read = ssh_stream_read; - s->parent.write = ssh_stream_write; - s->parent.free = ssh_stream_free; - - s->cmd = cmd; - - *stream = &s->parent; - return 0; -} - -static int ssh_agent_auth(LIBSSH2_SESSION *session, git_credential_ssh_key *c) { - int rc = LIBSSH2_ERROR_NONE; - - struct libssh2_agent_publickey *curr, *prev = NULL; - - LIBSSH2_AGENT *agent = libssh2_agent_init(session); - - if (agent == NULL) - return -1; - - rc = libssh2_agent_connect(agent); - - if (rc != LIBSSH2_ERROR_NONE) { - rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED; - goto shutdown; - } - - rc = libssh2_agent_list_identities(agent); - - if (rc != LIBSSH2_ERROR_NONE) - goto shutdown; - - while (1) { - rc = libssh2_agent_get_identity(agent, &curr, prev); - - if (rc < 0) - goto shutdown; - - /* rc is set to 1 whenever the ssh agent ran out of keys to check. - * Set the error code to authentication failure rather than erroring - * out with an untranslatable error code. - */ - if (rc == 1) { - rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED; - goto shutdown; - } - - rc = libssh2_agent_userauth(agent, c->username, curr); - - if (rc == 0) - break; - - prev = curr; - } - -shutdown: - - if (rc != LIBSSH2_ERROR_NONE) - ssh_error(session, "error authenticating"); - - libssh2_agent_disconnect(agent); - libssh2_agent_free(agent); - - return rc; -} - -static int _git_ssh_authenticate_session( - LIBSSH2_SESSION *session, - git_credential *cred) -{ - int rc; - - do { - git_error_clear(); - switch (cred->credtype) { - case GIT_CREDENTIAL_USERPASS_PLAINTEXT: { - git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred; - rc = libssh2_userauth_password(session, c->username, c->password); - break; - } - case GIT_CREDENTIAL_SSH_KEY: { - git_credential_ssh_key *c = (git_credential_ssh_key *)cred; - - if (c->privatekey) - rc = libssh2_userauth_publickey_fromfile( - session, c->username, c->publickey, - c->privatekey, c->passphrase); - else - rc = ssh_agent_auth(session, c); - - break; - } - case GIT_CREDENTIAL_SSH_CUSTOM: { - git_credential_ssh_custom *c = (git_credential_ssh_custom *)cred; - - rc = libssh2_userauth_publickey( - session, c->username, (const unsigned char *)c->publickey, - c->publickey_len, c->sign_callback, &c->payload); - break; - } - case GIT_CREDENTIAL_SSH_INTERACTIVE: { - void **abstract = libssh2_session_abstract(session); - git_credential_ssh_interactive *c = (git_credential_ssh_interactive *)cred; - - /* ideally, we should be able to set this by calling - * libssh2_session_init_ex() instead of libssh2_session_init(). - * libssh2's API is inconsistent here i.e. libssh2_userauth_publickey() - * allows you to pass the `abstract` as part of the call, whereas - * libssh2_userauth_keyboard_interactive() does not! - * - * The only way to set the `abstract` pointer is by calling - * libssh2_session_abstract(), which will replace the existing - * pointer as is done below. This is safe for now (at time of writing), - * but may not be valid in future. - */ - *abstract = c->payload; - - rc = libssh2_userauth_keyboard_interactive( - session, c->username, c->prompt_callback); - break; - } -#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS - case GIT_CREDENTIAL_SSH_MEMORY: { - git_credential_ssh_key *c = (git_credential_ssh_key *)cred; - - GIT_ASSERT(c->username); - GIT_ASSERT(c->privatekey); - - rc = libssh2_userauth_publickey_frommemory( - session, - c->username, - strlen(c->username), - c->publickey, - c->publickey ? strlen(c->publickey) : 0, - c->privatekey, - strlen(c->privatekey), - c->passphrase); - break; - } -#endif - default: - rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED; - } - } while (LIBSSH2_ERROR_EAGAIN == rc); - - if (rc == LIBSSH2_ERROR_PASSWORD_EXPIRED || - rc == LIBSSH2_ERROR_AUTHENTICATION_FAILED || - rc == LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED) - return GIT_EAUTH; - - if (rc != LIBSSH2_ERROR_NONE) { - if (git_error_last()->klass == GIT_ERROR_NONE) - ssh_error(session, "failed to authenticate SSH session"); - return -1; - } - - return 0; -} - -static int request_creds(git_credential **out, ssh_subtransport *t, const char *user, int auth_methods) -{ - int error, no_callback = 0; - git_credential *cred = NULL; - - if (!t->owner->connect_opts.callbacks.credentials) { - no_callback = 1; - } else { - error = t->owner->connect_opts.callbacks.credentials( - &cred, - t->owner->url, - user, - auth_methods, - t->owner->connect_opts.callbacks.payload); - - if (error == GIT_PASSTHROUGH) { - no_callback = 1; - } else if (error < 0) { - return error; - } else if (!cred) { - git_error_set(GIT_ERROR_SSH, "callback failed to initialize SSH credentials"); - return -1; - } - } - - if (no_callback) { - git_error_set(GIT_ERROR_SSH, "authentication required but no callback set"); - return GIT_EAUTH; - } - - if (!(cred->credtype & auth_methods)) { - cred->free(cred); - git_error_set(GIT_ERROR_SSH, "authentication callback returned unsupported credentials type"); - return GIT_EAUTH; - } - - *out = cred; - - return 0; -} - -#define SSH_DIR ".ssh" -#define KNOWN_HOSTS_FILE "known_hosts" - -/* - * Load the known_hosts file. - * - * Returns success but leaves the output NULL if we couldn't find the file. - */ -static int load_known_hosts(LIBSSH2_KNOWNHOSTS **hosts, LIBSSH2_SESSION *session) -{ - git_str path = GIT_STR_INIT, sshdir = GIT_STR_INIT; - LIBSSH2_KNOWNHOSTS *known_hosts = NULL; - int error; - - GIT_ASSERT_ARG(hosts); - - if ((known_hosts = libssh2_knownhost_init(session)) == NULL) { - ssh_error(session, "error initializing known hosts"); - error = -1; - goto out; - } - - if ((error = git_sysdir_expand_homedir_file(&sshdir, SSH_DIR)) < 0) { - if (error == GIT_ENOTFOUND) - error = 0; - - goto out; - } - - if ((error = git_str_joinpath(&path, git_str_cstr(&sshdir), KNOWN_HOSTS_FILE)) < 0) - goto out; - - /* - * Try to read the file and consider not finding it as not trusting the - * host rather than an error. - */ - error = libssh2_knownhost_readfile(known_hosts, git_str_cstr(&path), LIBSSH2_KNOWNHOST_FILE_OPENSSH); - if (error == LIBSSH2_ERROR_FILE) - error = 0; - if (error < 0) - ssh_error(session, "error reading known_hosts"); - -out: - *hosts = known_hosts; - - git_str_dispose(&sshdir); - git_str_dispose(&path); - - return error; -} - -static void add_hostkey_pref_if_avail( - LIBSSH2_KNOWNHOSTS *known_hosts, - const char *hostname, - int port, - git_str *prefs, - int type, - const char *type_name) -{ - struct libssh2_knownhost *host = NULL; - const char key = '\0'; - int mask = LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW | type; - int error; - - error = libssh2_knownhost_checkp(known_hosts, hostname, port, &key, 1, mask, &host); - if (error == LIBSSH2_KNOWNHOST_CHECK_MISMATCH) { - if (git_str_len(prefs) > 0) { - git_str_putc(prefs, ','); - } - git_str_puts(prefs, type_name); - } -} - -/* - * We figure out what kind of key we want to ask the remote for by trying to - * look it up with a nonsense key and using that mismatch to figure out what key - * we do have stored for the host. - * - * Populates prefs with the string to pass to libssh2_session_method_pref. - */ -static void find_hostkey_preference( - LIBSSH2_KNOWNHOSTS *known_hosts, - const char *hostname, - int port, - git_str *prefs) -{ - /* - * The order here is important as it indicates the priority of what will - * be preferred. - */ -#ifdef LIBSSH2_KNOWNHOST_KEY_ED25519 - add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ED25519, "ssh-ed25519"); -#endif -#ifdef LIBSSH2_KNOWNHOST_KEY_ECDSA_256 - add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_256, "ecdsa-sha2-nistp256"); - add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_384, "ecdsa-sha2-nistp384"); - add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_521, "ecdsa-sha2-nistp521"); -#endif - add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_SSHRSA, "rsa-sha2-512"); - add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_SSHRSA, "rsa-sha2-256"); - add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_SSHRSA, "ssh-rsa"); -} - -static int _git_ssh_session_create( - LIBSSH2_SESSION **session, - LIBSSH2_KNOWNHOSTS **hosts, - const char *hostname, - int port, - git_stream *io) -{ - git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent); - LIBSSH2_SESSION *s; - LIBSSH2_KNOWNHOSTS *known_hosts; - git_str prefs = GIT_STR_INIT; - int rc = 0; - - GIT_ASSERT_ARG(session); - GIT_ASSERT_ARG(hosts); - - s = libssh2_session_init(); - if (!s) { - git_error_set(GIT_ERROR_NET, "failed to initialize SSH session"); - return -1; - } - - if (git_socket_stream__timeout > 0) { - libssh2_session_set_timeout(s, git_socket_stream__timeout); - } - - if ((rc = load_known_hosts(&known_hosts, s)) < 0) { - ssh_error(s, "error loading known_hosts"); - libssh2_session_free(s); - return -1; - } - - find_hostkey_preference(known_hosts, hostname, port, &prefs); - if (git_str_len(&prefs) > 0) { - do { - rc = libssh2_session_method_pref(s, LIBSSH2_METHOD_HOSTKEY, git_str_cstr(&prefs)); - } while (LIBSSH2_ERROR_EAGAIN == rc); - if (rc != LIBSSH2_ERROR_NONE) { - ssh_error(s, "failed to set hostkey preference"); - goto on_error; - } - } - git_str_dispose(&prefs); - - do { - rc = libssh2_session_handshake(s, socket->s); - } while (LIBSSH2_ERROR_EAGAIN == rc); - - if (rc != LIBSSH2_ERROR_NONE) { - ssh_error(s, "failed to start SSH session"); - goto on_error; - } - - libssh2_session_set_blocking(s, 1); - - *session = s; - *hosts = known_hosts; - - return 0; - -on_error: - libssh2_knownhost_free(known_hosts); - libssh2_session_free(s); - return -1; -} - - -/* - * Returns the typemask argument to pass to libssh2_knownhost_check{,p} based on - * the type of key that libssh2_session_hostkey returns. - */ -static int fingerprint_type_mask(int keytype) -{ - int mask = LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW; - return mask; - - switch (keytype) { - case LIBSSH2_HOSTKEY_TYPE_RSA: - mask |= LIBSSH2_KNOWNHOST_KEY_SSHRSA; - break; - case LIBSSH2_HOSTKEY_TYPE_DSS: - mask |= LIBSSH2_KNOWNHOST_KEY_SSHDSS; - break; -#ifdef LIBSSH2_HOSTKEY_TYPE_ECDSA_256 - case LIBSSH2_HOSTKEY_TYPE_ECDSA_256: - mask |= LIBSSH2_KNOWNHOST_KEY_ECDSA_256; - break; - case LIBSSH2_HOSTKEY_TYPE_ECDSA_384: - mask |= LIBSSH2_KNOWNHOST_KEY_ECDSA_384; - break; - case LIBSSH2_HOSTKEY_TYPE_ECDSA_521: - mask |= LIBSSH2_KNOWNHOST_KEY_ECDSA_521; - break; -#endif -#ifdef LIBSSH2_HOSTKEY_TYPE_ED25519 - case LIBSSH2_HOSTKEY_TYPE_ED25519: - mask |= LIBSSH2_KNOWNHOST_KEY_ED25519; - break; -#endif - } - - return mask; -} - -/* - * Check the host against the user's known_hosts file. - * - * Returns 1/0 for valid/''not-valid or <0 for an error - */ -static int check_against_known_hosts( - LIBSSH2_SESSION *session, - LIBSSH2_KNOWNHOSTS *known_hosts, - const char *hostname, - int port, - const char *key, - size_t key_len, - int key_type) -{ - int check, typemask, ret = 0; - struct libssh2_knownhost *host = NULL; - - if (known_hosts == NULL) - return 0; - - typemask = fingerprint_type_mask(key_type); - check = libssh2_knownhost_checkp(known_hosts, hostname, port, key, key_len, typemask, &host); - if (check == LIBSSH2_KNOWNHOST_CHECK_FAILURE) { - ssh_error(session, "error checking for known host"); - return -1; - } - - ret = check == LIBSSH2_KNOWNHOST_CHECK_MATCH ? 1 : 0; - - return ret; -} - -/* - * Perform the check for the session's certificate against known hosts if - * possible and then ask the user if they have a callback. - * - * Returns 1/0 for valid/not-valid or <0 for an error - */ -static int check_certificate( - LIBSSH2_SESSION *session, - LIBSSH2_KNOWNHOSTS *known_hosts, - git_transport_certificate_check_cb check_cb, - void *check_cb_payload, - const char *host, - int port) -{ - git_cert_hostkey cert = {{ 0 }}; - const char *key; - size_t cert_len; - int cert_type, cert_valid = 0, error = GIT_ECERTIFICATE; - - if ((key = libssh2_session_hostkey(session, &cert_len, &cert_type)) == NULL) { - ssh_error(session, "failed to retrieve hostkey"); - return -1; - } - - if ((cert_valid = check_against_known_hosts(session, known_hosts, host, port, key, cert_len, cert_type)) < 0) - return -1; - - cert.parent.cert_type = GIT_CERT_HOSTKEY_LIBSSH2; - if (key != NULL) { - cert.type |= GIT_CERT_SSH_RAW; - cert.hostkey = key; - cert.hostkey_len = cert_len; - switch (cert_type) { - case LIBSSH2_HOSTKEY_TYPE_RSA: - cert.raw_type = GIT_CERT_SSH_RAW_TYPE_RSA; - break; - case LIBSSH2_HOSTKEY_TYPE_DSS: - cert.raw_type = GIT_CERT_SSH_RAW_TYPE_DSS; - break; - -#ifdef LIBSSH2_HOSTKEY_TYPE_ECDSA_256 - case LIBSSH2_HOSTKEY_TYPE_ECDSA_256: - cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_256; - break; - case LIBSSH2_HOSTKEY_TYPE_ECDSA_384: - cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_384; - break; - case LIBSSH2_KNOWNHOST_KEY_ECDSA_521: - cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_521; - break; -#endif - -#ifdef LIBSSH2_HOSTKEY_TYPE_ED25519 - case LIBSSH2_HOSTKEY_TYPE_ED25519: - cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ED25519; - break; -#endif - default: - cert.raw_type = GIT_CERT_SSH_RAW_TYPE_UNKNOWN; - } - } - -#ifdef LIBSSH2_HOSTKEY_HASH_SHA256 - key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256); - if (key != NULL) { - cert.type |= GIT_CERT_SSH_SHA256; - memcpy(&cert.hash_sha256, key, 32); - } -#endif - - key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); - if (key != NULL) { - cert.type |= GIT_CERT_SSH_SHA1; - memcpy(&cert.hash_sha1, key, 20); - } - - key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_MD5); - if (key != NULL) { - cert.type |= GIT_CERT_SSH_MD5; - memcpy(&cert.hash_md5, key, 16); - } - - if (cert.type == 0) { - git_error_set(GIT_ERROR_SSH, "unable to get the host key"); - return -1; - } - - if (check_cb != NULL) { - git_cert_hostkey *cert_ptr = &cert; - - error = check_cb((git_cert *)cert_ptr, cert_valid, host, - check_cb_payload); - - if (error == 0) - cert_valid = 1; - else if (error != GIT_PASSTHROUGH) - cert_valid = 0; - } - - if (!cert_valid) { - git_error_set(GIT_ERROR_SSH, "invalid or unknown remote ssh hostkey"); - return (error == GIT_PASSTHROUGH) ? GIT_ECERTIFICATE : error; - } - - return 0; -} - -#define SSH_DEFAULT_PORT "22" - -static int _git_ssh_setup_conn( - ssh_subtransport *t, - const char *url, - const char *cmd, - git_smart_subtransport_stream **stream) -{ - int auth_methods, error = 0, port; - ssh_stream *s; - git_credential *cred = NULL; - LIBSSH2_SESSION *session=NULL; - LIBSSH2_CHANNEL *channel=NULL; - LIBSSH2_KNOWNHOSTS *known_hosts = NULL; - - t->current_stream = NULL; - - *stream = NULL; - if (ssh_stream_alloc(t, cmd, stream) < 0) - return -1; - - s = (ssh_stream *)*stream; - s->session = NULL; - s->channel = NULL; - - if (git_net_str_is_url(url)) - error = git_net_url_parse(&s->url, url); - else - error = git_net_url_parse_scp(&s->url, url); - - if (error < 0) - goto done; - - /* Safety check: like git, we forbid paths that look like an option as - * that could lead to injection on the remote side */ - if (git_process__is_cmdline_option(s->url.path)) { - git_error_set(GIT_ERROR_NET, "cannot ssh: path '%s' is ambiguous with command-line option", s->url.path); - error = -1; - goto done; - } - - - if ((error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 || - (error = git_stream_connect(s->io)) < 0) - goto done; - - /* - * Try to parse the port as a number, if we can't then fall back to - * default. It would be nice if we could get the port that was resolved - * as part of the stream connection, but that's not something that's - * exposed. - */ - if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0) - port = -1; - - if ((error = _git_ssh_session_create(&session, &known_hosts, s->url.host, port, s->io)) < 0) - goto done; - - if ((error = check_certificate(session, known_hosts, t->owner->connect_opts.callbacks.certificate_check, t->owner->connect_opts.callbacks.payload, s->url.host, port)) < 0) - goto done; - - /* we need the username to ask for auth methods */ - if (!s->url.username) { - if ((error = request_creds(&cred, t, NULL, GIT_CREDENTIAL_USERNAME)) < 0) - goto done; - - s->url.username = git__strdup(((git_credential_username *) cred)->username); - cred->free(cred); - cred = NULL; - if (!s->url.username) - goto done; - } else if (s->url.username && s->url.password) { - if ((error = git_credential_userpass_plaintext_new(&cred, s->url.username, s->url.password)) < 0) - goto done; - } - - if ((error = list_auth_methods(&auth_methods, session, s->url.username)) < 0) - goto done; - - error = GIT_EAUTH; - /* if we already have something to try */ - if (cred && auth_methods & cred->credtype) - error = _git_ssh_authenticate_session(session, cred); - - while (error == GIT_EAUTH) { - if (cred) { - cred->free(cred); - cred = NULL; - } - - if ((error = request_creds(&cred, t, s->url.username, auth_methods)) < 0) - goto done; - - if (strcmp(s->url.username, git_credential_get_username(cred))) { - git_error_set(GIT_ERROR_SSH, "username does not match previous request"); - error = -1; - goto done; - } - - error = _git_ssh_authenticate_session(session, cred); - - if (error == GIT_EAUTH) { - /* refresh auth methods */ - if ((error = list_auth_methods(&auth_methods, session, s->url.username)) < 0) - goto done; - else - error = GIT_EAUTH; - } - } - - if (error < 0) - goto done; - - channel = libssh2_channel_open_session(session); - if (!channel) { - error = -1; - ssh_error(session, "Failed to open SSH channel"); - goto done; - } - - libssh2_channel_set_blocking(channel, 1); - - s->session = session; - s->channel = channel; - - t->current_stream = s; - -done: - if (known_hosts) - libssh2_knownhost_free(known_hosts); - - if (error < 0) { - ssh_stream_free(*stream); - - if (session) - libssh2_session_free(session); - } - - if (cred) - cred->free(cred); - - return error; -} - -static int ssh_uploadpack_ls( - ssh_subtransport *t, - const char *url, - git_smart_subtransport_stream **stream) -{ - const char *cmd = t->cmd_uploadpack ? t->cmd_uploadpack : cmd_uploadpack; - - return _git_ssh_setup_conn(t, url, cmd, stream); -} - -static int ssh_uploadpack( - ssh_subtransport *t, - const char *url, - git_smart_subtransport_stream **stream) -{ - GIT_UNUSED(url); - - if (t->current_stream) { - *stream = &t->current_stream->parent; - return 0; - } - - git_error_set(GIT_ERROR_NET, "must call UPLOADPACK_LS before UPLOADPACK"); - return -1; -} - -static int ssh_receivepack_ls( - ssh_subtransport *t, - const char *url, - git_smart_subtransport_stream **stream) -{ - const char *cmd = t->cmd_receivepack ? t->cmd_receivepack : cmd_receivepack; - - - return _git_ssh_setup_conn(t, url, cmd, stream); -} - -static int ssh_receivepack( - ssh_subtransport *t, - const char *url, - git_smart_subtransport_stream **stream) -{ - GIT_UNUSED(url); - - if (t->current_stream) { - *stream = &t->current_stream->parent; - return 0; - } - - git_error_set(GIT_ERROR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK"); - return -1; -} - -static int _ssh_action( - git_smart_subtransport_stream **stream, - git_smart_subtransport *subtransport, - const char *url, - git_smart_service_t action) -{ - ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent); - - switch (action) { - case GIT_SERVICE_UPLOADPACK_LS: - return ssh_uploadpack_ls(t, url, stream); - - case GIT_SERVICE_UPLOADPACK: - return ssh_uploadpack(t, url, stream); - - case GIT_SERVICE_RECEIVEPACK_LS: - return ssh_receivepack_ls(t, url, stream); - - case GIT_SERVICE_RECEIVEPACK: - return ssh_receivepack(t, url, stream); - } - - *stream = NULL; - return -1; -} - -static int _ssh_close(git_smart_subtransport *subtransport) -{ - ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent); - - GIT_ASSERT(!t->current_stream); - - GIT_UNUSED(t); - - return 0; -} - -static void _ssh_free(git_smart_subtransport *subtransport) -{ - ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent); - - git__free(t->cmd_uploadpack); - git__free(t->cmd_receivepack); - git__free(t); -} - -#define SSH_AUTH_PUBLICKEY "publickey" -#define SSH_AUTH_PASSWORD "password" -#define SSH_AUTH_KEYBOARD_INTERACTIVE "keyboard-interactive" - -static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *username) -{ - const char *list, *ptr; - - *out = 0; - - list = libssh2_userauth_list(session, username, - (unsigned int)strlen(username)); - - /* either error, or the remote accepts NONE auth, which is bizarre, let's punt */ - if (list == NULL && !libssh2_userauth_authenticated(session)) { - ssh_error(session, "remote rejected authentication"); - return GIT_EAUTH; - } - - ptr = list; - while (ptr) { - if (*ptr == ',') - ptr++; - - if (!git__prefixcmp(ptr, SSH_AUTH_PUBLICKEY)) { - *out |= GIT_CREDENTIAL_SSH_KEY; - *out |= GIT_CREDENTIAL_SSH_CUSTOM; -#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS - *out |= GIT_CREDENTIAL_SSH_MEMORY; -#endif - ptr += strlen(SSH_AUTH_PUBLICKEY); - continue; - } - - if (!git__prefixcmp(ptr, SSH_AUTH_PASSWORD)) { - *out |= GIT_CREDENTIAL_USERPASS_PLAINTEXT; - ptr += strlen(SSH_AUTH_PASSWORD); - continue; - } - - if (!git__prefixcmp(ptr, SSH_AUTH_KEYBOARD_INTERACTIVE)) { - *out |= GIT_CREDENTIAL_SSH_INTERACTIVE; - ptr += strlen(SSH_AUTH_KEYBOARD_INTERACTIVE); - continue; - } - - /* Skip it if we don't know it */ - ptr = strchr(ptr, ','); - } - - return 0; -} - -int git_smart_subtransport_ssh_libssh2( - git_smart_subtransport **out, - git_transport *owner, - void *param) -{ - ssh_subtransport *t; - - GIT_ASSERT_ARG(out); - - GIT_UNUSED(param); - - t = git__calloc(sizeof(ssh_subtransport), 1); - GIT_ERROR_CHECK_ALLOC(t); - - t->owner = (transport_smart *)owner; - t->parent.action = _ssh_action; - t->parent.close = _ssh_close; - t->parent.free = _ssh_free; - - *out = (git_smart_subtransport *) t; - return 0; -} - -int git_smart_subtransport_ssh_libssh2_set_paths( - git_smart_subtransport *subtransport, - const char *cmd_uploadpack, - const char *cmd_receivepack) -{ - ssh_subtransport *t = (ssh_subtransport *)subtransport; - - git__free(t->cmd_uploadpack); - git__free(t->cmd_receivepack); - - t->cmd_uploadpack = git__strdup(cmd_uploadpack); - GIT_ERROR_CHECK_ALLOC(t->cmd_uploadpack); - - t->cmd_receivepack = git__strdup(cmd_receivepack); - GIT_ERROR_CHECK_ALLOC(t->cmd_receivepack); - - return 0; -} - -static void shutdown_libssh2(void) -{ - libssh2_exit(); -} - -int git_transport_ssh_libssh2_global_init(void) -{ - if (libssh2_init(0) < 0) { - git_error_set(GIT_ERROR_SSH, "unable to initialize libssh2"); - return -1; - } - - return git_runtime_shutdown_register(shutdown_libssh2); -} - -#else /* GIT_SSH */ - -int git_transport_ssh_libssh2_global_init(void) -{ - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_libssh2.h b/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_libssh2.h deleted file mode 100644 index 3f8cc2a..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/ssh_libssh2.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_transports_libssh2_h__ -#define INCLUDE_transports_libssh2_h__ - -#include "common.h" - -#include "git2.h" -#include "git2/transport.h" -#include "git2/sys/transport.h" - -int git_transport_ssh_libssh2_global_init(void); - -int git_smart_subtransport_ssh_libssh2( - git_smart_subtransport **out, - git_transport *owner, - void *param); - -int git_smart_subtransport_ssh_libssh2_set_paths( - git_smart_subtransport *subtransport, - const char *cmd_uploadpack, - const char *cmd_receivepack); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/transports/winhttp.c b/vendor/libgit2-sys/libgit2/src/libgit2/transports/winhttp.c deleted file mode 100644 index b83ef99..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/transports/winhttp.c +++ /dev/null @@ -1,1718 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common.h" - -#ifdef GIT_WINHTTP - -#include "git2.h" -#include "git2/transport.h" -#include "posix.h" -#include "str.h" -#include "smart.h" -#include "remote.h" -#include "repository.h" -#include "http.h" -#include "git2/sys/credential.h" - -#include -#include - -/* For IInternetSecurityManager zone check */ -#include -#include - -#define WIDEN2(s) L ## s -#define WIDEN(s) WIDEN2(s) - -#define MAX_CONTENT_TYPE_LEN 100 -#define WINHTTP_OPTION_PEERDIST_EXTENSION_STATE 109 -#define CACHED_POST_BODY_BUF_SIZE 4096 -#define UUID_LENGTH_CCH 32 -#define TIMEOUT_INFINITE -1 -#define DEFAULT_CONNECT_TIMEOUT 60000 -#ifndef WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH -#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0 -#endif - -#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 -# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 0x00000200 -#endif - -#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 -# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800 -#endif - -#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3 -# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3 0x00002000 -#endif - -#ifndef WINHTTP_NO_CLIENT_CERT_CONTEXT -# define WINHTTP_NO_CLIENT_CERT_CONTEXT NULL -#endif - -#ifndef HTTP_STATUS_PERMANENT_REDIRECT -# define HTTP_STATUS_PERMANENT_REDIRECT 308 -#endif - -#ifndef DWORD_MAX -# define DWORD_MAX 0xffffffff -#endif - -bool git_http__expect_continue = false; - -static const char *prefix_https = "https://"; -static const char *upload_pack_service = "upload-pack"; -static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack"; -static const char *upload_pack_service_url = "/git-upload-pack"; -static const char *receive_pack_service = "receive-pack"; -static const char *receive_pack_ls_service_url = "/info/refs?service=git-receive-pack"; -static const char *receive_pack_service_url = "/git-receive-pack"; -static const wchar_t *get_verb = L"GET"; -static const wchar_t *post_verb = L"POST"; -static const wchar_t *pragma_nocache = L"Pragma: no-cache"; -static const wchar_t *transfer_encoding = L"Transfer-Encoding: chunked"; -static const int no_check_cert_flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID | - SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | - SECURITY_FLAG_IGNORE_UNKNOWN_CA; - -#if defined(__MINGW32__) -static const CLSID CLSID_InternetSecurityManager_mingw = - { 0x7B8A2D94, 0x0AC9, 0x11D1, - { 0x89, 0x6C, 0x00, 0xC0, 0x4F, 0xB6, 0xBF, 0xC4 } }; -static const IID IID_IInternetSecurityManager_mingw = - { 0x79EAC9EE, 0xBAF9, 0x11CE, - { 0x8C, 0x82, 0x00, 0xAA, 0x00, 0x4B, 0xA9, 0x0B } }; - -# define CLSID_InternetSecurityManager CLSID_InternetSecurityManager_mingw -# define IID_IInternetSecurityManager IID_IInternetSecurityManager_mingw -#endif - -#define OWNING_SUBTRANSPORT(s) ((winhttp_subtransport *)(s)->parent.subtransport) - -typedef enum { - GIT_WINHTTP_AUTH_BASIC = 1, - GIT_WINHTTP_AUTH_NTLM = 2, - GIT_WINHTTP_AUTH_NEGOTIATE = 4, - GIT_WINHTTP_AUTH_DIGEST = 8 -} winhttp_authmechanism_t; - -typedef struct { - git_smart_subtransport_stream parent; - const char *service; - const char *service_url; - const wchar_t *verb; - HINTERNET request; - wchar_t *request_uri; - char *chunk_buffer; - unsigned chunk_buffer_len; - HANDLE post_body; - DWORD post_body_len; - unsigned sent_request : 1, - received_response : 1, - chunked : 1, - status_sending_request_reached: 1; -} winhttp_stream; - -typedef struct { - git_net_url url; - git_credential *cred; - int auth_mechanisms; - bool url_cred_presented; -} winhttp_server; - -typedef struct { - git_smart_subtransport parent; - transport_smart *owner; - - winhttp_server server; - winhttp_server proxy; - - HINTERNET session; - HINTERNET connection; -} winhttp_subtransport; - -static int apply_userpass_credentials(HINTERNET request, DWORD target, int mechanisms, git_credential *cred) -{ - git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred; - wchar_t *user = NULL, *pass = NULL; - int user_len = 0, pass_len = 0, error = 0; - DWORD native_scheme; - - if (mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) { - native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE; - } else if (mechanisms & GIT_WINHTTP_AUTH_NTLM) { - native_scheme = WINHTTP_AUTH_SCHEME_NTLM; - } else if (mechanisms & GIT_WINHTTP_AUTH_DIGEST) { - native_scheme = WINHTTP_AUTH_SCHEME_DIGEST; - } else if (mechanisms & GIT_WINHTTP_AUTH_BASIC) { - native_scheme = WINHTTP_AUTH_SCHEME_BASIC; - } else { - git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme"); - error = GIT_EAUTH; - goto done; - } - - if ((error = user_len = git_utf8_to_16_alloc(&user, c->username)) < 0) - goto done; - - if ((error = pass_len = git_utf8_to_16_alloc(&pass, c->password)) < 0) - goto done; - - if (!WinHttpSetCredentials(request, target, native_scheme, user, pass, NULL)) { - git_error_set(GIT_ERROR_OS, "failed to set credentials"); - error = -1; - } - -done: - if (user_len > 0) - git__memzero(user, user_len * sizeof(wchar_t)); - - if (pass_len > 0) - git__memzero(pass, pass_len * sizeof(wchar_t)); - - git__free(user); - git__free(pass); - - return error; -} - -static int apply_default_credentials(HINTERNET request, DWORD target, int mechanisms) -{ - DWORD autologon_level = WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW; - DWORD native_scheme = 0; - - if ((mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) != 0) { - native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE; - } else if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) != 0) { - native_scheme = WINHTTP_AUTH_SCHEME_NTLM; - } else { - git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme"); - return GIT_EAUTH; - } - - /* - * Autologon policy must be "low" to use default creds. - * This is safe as the user has explicitly requested it. - */ - if (!WinHttpSetOption(request, WINHTTP_OPTION_AUTOLOGON_POLICY, &autologon_level, sizeof(DWORD))) { - git_error_set(GIT_ERROR_OS, "could not configure logon policy"); - return -1; - } - - if (!WinHttpSetCredentials(request, target, native_scheme, NULL, NULL, NULL)) { - git_error_set(GIT_ERROR_OS, "could not configure credentials"); - return -1; - } - - return 0; -} - -static int acquire_url_cred( - git_credential **cred, - unsigned int allowed_types, - const char *username, - const char *password) -{ - if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT) - return git_credential_userpass_plaintext_new(cred, username, password); - - if ((allowed_types & GIT_CREDENTIAL_DEFAULT) && *username == '\0' && *password == '\0') - return git_credential_default_new(cred); - - return 1; -} - -static int acquire_fallback_cred( - git_credential **cred, - const char *url, - unsigned int allowed_types) -{ - int error = 1; - - /* If the target URI supports integrated Windows authentication - * as an authentication mechanism */ - if (GIT_CREDENTIAL_DEFAULT & allowed_types) { - wchar_t *wide_url; - HRESULT hCoInitResult; - - /* Convert URL to wide characters */ - if (git_utf8_to_16_alloc(&wide_url, url) < 0) { - git_error_set(GIT_ERROR_OS, "failed to convert string to wide form"); - return -1; - } - - hCoInitResult = CoInitializeEx(NULL, COINIT_MULTITHREADED); - - if (SUCCEEDED(hCoInitResult) || hCoInitResult == RPC_E_CHANGED_MODE) { - IInternetSecurityManager *pISM; - - /* And if the target URI is in the My Computer, Intranet, or Trusted zones */ - if (SUCCEEDED(CoCreateInstance(&CLSID_InternetSecurityManager, NULL, - CLSCTX_ALL, &IID_IInternetSecurityManager, (void **)&pISM))) { - DWORD dwZone; - - if (SUCCEEDED(pISM->lpVtbl->MapUrlToZone(pISM, wide_url, &dwZone, 0)) && - (URLZONE_LOCAL_MACHINE == dwZone || - URLZONE_INTRANET == dwZone || - URLZONE_TRUSTED == dwZone)) { - git_credential *existing = *cred; - - if (existing) - existing->free(existing); - - /* Then use default Windows credentials to authenticate this request */ - error = git_credential_default_new(cred); - } - - pISM->lpVtbl->Release(pISM); - } - - /* Only uninitialize if the call to CoInitializeEx was successful. */ - if (SUCCEEDED(hCoInitResult)) - CoUninitialize(); - } - - git__free(wide_url); - } - - return error; -} - -static int certificate_check(winhttp_stream *s, int valid) -{ - int error; - winhttp_subtransport *t = OWNING_SUBTRANSPORT(s); - PCERT_CONTEXT cert_ctx; - DWORD cert_ctx_size = sizeof(cert_ctx); - git_cert_x509 cert; - - /* If there is no override, we should fail if WinHTTP doesn't think it's fine */ - if (t->owner->connect_opts.callbacks.certificate_check == NULL && !valid) { - if (git_error_last()->klass == GIT_ERROR_NONE) - git_error_set(GIT_ERROR_HTTP, "unknown certificate check failure"); - - return GIT_ECERTIFICATE; - } - - if (t->owner->connect_opts.callbacks.certificate_check == NULL || git__strcmp(t->server.url.scheme, "https") != 0) - return 0; - - if (!WinHttpQueryOption(s->request, WINHTTP_OPTION_SERVER_CERT_CONTEXT, &cert_ctx, &cert_ctx_size)) { - git_error_set(GIT_ERROR_OS, "failed to get server certificate"); - return -1; - } - - git_error_clear(); - cert.parent.cert_type = GIT_CERT_X509; - cert.data = cert_ctx->pbCertEncoded; - cert.len = cert_ctx->cbCertEncoded; - error = t->owner->connect_opts.callbacks.certificate_check((git_cert *) &cert, valid, t->server.url.host, t->owner->connect_opts.callbacks.payload); - CertFreeCertificateContext(cert_ctx); - - if (error == GIT_PASSTHROUGH) - error = valid ? 0 : GIT_ECERTIFICATE; - - if (error < 0 && git_error_last()->klass == GIT_ERROR_NONE) - git_error_set(GIT_ERROR_HTTP, "user cancelled certificate check"); - - return error; -} - -static void winhttp_stream_close(winhttp_stream *s) -{ - if (s->chunk_buffer) { - git__free(s->chunk_buffer); - s->chunk_buffer = NULL; - } - - if (s->post_body) { - CloseHandle(s->post_body); - s->post_body = NULL; - } - - if (s->request_uri) { - git__free(s->request_uri); - s->request_uri = NULL; - } - - if (s->request) { - WinHttpCloseHandle(s->request); - s->request = NULL; - } - - s->sent_request = 0; -} - -static int apply_credentials( - HINTERNET request, - git_net_url *url, - int target, - git_credential *creds, - int mechanisms) -{ - int error = 0; - - GIT_UNUSED(url); - - /* If we have creds, just apply them */ - if (creds && creds->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT) - error = apply_userpass_credentials(request, target, mechanisms, creds); - else if (creds && creds->credtype == GIT_CREDENTIAL_DEFAULT) - error = apply_default_credentials(request, target, mechanisms); - - return error; -} - -static int winhttp_stream_connect(winhttp_stream *s) -{ - winhttp_subtransport *t = OWNING_SUBTRANSPORT(s); - git_str buf = GIT_STR_INIT; - char *proxy_url = NULL; - wchar_t ct[MAX_CONTENT_TYPE_LEN]; - LPCWSTR types[] = { L"*/*", NULL }; - BOOL peerdist = FALSE; - int error = -1; - unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS; - int default_timeout = TIMEOUT_INFINITE; - int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT; - DWORD autologon_policy = WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH; - - const char *service_url = s->service_url; - size_t i; - const git_proxy_options *proxy_opts; - - /* If path already ends in /, remove the leading slash from service_url */ - if ((git__suffixcmp(t->server.url.path, "/") == 0) && (git__prefixcmp(service_url, "/") == 0)) - service_url++; - /* Prepare URL */ - git_str_printf(&buf, "%s%s", t->server.url.path, service_url); - - if (git_str_oom(&buf)) - return -1; - - /* Convert URL to wide characters */ - if (git_utf8_to_16_alloc(&s->request_uri, git_str_cstr(&buf)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to convert string to wide form"); - goto on_error; - } - - /* Establish request */ - s->request = WinHttpOpenRequest( - t->connection, - s->verb, - s->request_uri, - NULL, - WINHTTP_NO_REFERER, - types, - git__strcmp(t->server.url.scheme, "https") == 0 ? WINHTTP_FLAG_SECURE : 0); - - if (!s->request) { - git_error_set(GIT_ERROR_OS, "failed to open request"); - goto on_error; - } - - /* Never attempt default credentials; we'll provide them explicitly. */ - if (!WinHttpSetOption(s->request, WINHTTP_OPTION_AUTOLOGON_POLICY, &autologon_policy, sizeof(DWORD))) - return -1; - - if (!WinHttpSetTimeouts(s->request, default_timeout, default_connect_timeout, default_timeout, default_timeout)) { - git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP"); - goto on_error; - } - - proxy_opts = &t->owner->connect_opts.proxy_opts; - if (proxy_opts->type == GIT_PROXY_AUTO) { - /* Set proxy if necessary */ - if (git_remote__http_proxy(&proxy_url, t->owner->owner, &t->server.url) < 0) - goto on_error; - } - else if (proxy_opts->type == GIT_PROXY_SPECIFIED) { - proxy_url = git__strdup(proxy_opts->url); - GIT_ERROR_CHECK_ALLOC(proxy_url); - } - - if (proxy_url && *proxy_url) { - git_str processed_url = GIT_STR_INIT; - WINHTTP_PROXY_INFO proxy_info; - wchar_t *proxy_wide; - - git_net_url_dispose(&t->proxy.url); - - if ((error = git_net_url_parse_http(&t->proxy.url, proxy_url)) < 0) - goto on_error; - - if (!git_net_url_valid(&t->proxy.url)) { - git_error_set(GIT_ERROR_HTTP, "invalid URL: '%s'", proxy_url); - error = -1; - goto on_error; - } - - git_str_puts(&processed_url, t->proxy.url.scheme); - git_str_PUTS(&processed_url, "://"); - - if (git_net_url_is_ipv6(&t->proxy.url)) - git_str_putc(&processed_url, '['); - - git_str_puts(&processed_url, t->proxy.url.host); - - if (git_net_url_is_ipv6(&t->proxy.url)) - git_str_putc(&processed_url, ']'); - - if (!git_net_url_is_default_port(&t->proxy.url)) - git_str_printf(&processed_url, ":%s", t->proxy.url.port); - - if (git_str_oom(&processed_url)) { - error = -1; - goto on_error; - } - - /* Convert URL to wide characters */ - error = git_utf8_to_16_alloc(&proxy_wide, processed_url.ptr); - git_str_dispose(&processed_url); - if (error < 0) - goto on_error; - - proxy_info.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY; - proxy_info.lpszProxy = proxy_wide; - proxy_info.lpszProxyBypass = NULL; - - if (!WinHttpSetOption(s->request, - WINHTTP_OPTION_PROXY, - &proxy_info, - sizeof(WINHTTP_PROXY_INFO))) { - git_error_set(GIT_ERROR_OS, "failed to set proxy"); - git__free(proxy_wide); - goto on_error; - } - - git__free(proxy_wide); - - if ((error = apply_credentials(s->request, &t->proxy.url, WINHTTP_AUTH_TARGET_PROXY, t->proxy.cred, t->proxy.auth_mechanisms)) < 0) - goto on_error; - } - - /* Disable WinHTTP redirects so we can handle them manually. Why, you ask? - * http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/b2ff8879-ab9f-4218-8f09-16d25dff87ae - */ - if (!WinHttpSetOption(s->request, - WINHTTP_OPTION_DISABLE_FEATURE, - &disable_redirects, - sizeof(disable_redirects))) { - git_error_set(GIT_ERROR_OS, "failed to disable redirects"); - error = -1; - goto on_error; - } - - /* Strip unwanted headers (X-P2P-PeerDist, X-P2P-PeerDistEx) that WinHTTP - * adds itself. This option may not be supported by the underlying - * platform, so we do not error-check it */ - WinHttpSetOption(s->request, - WINHTTP_OPTION_PEERDIST_EXTENSION_STATE, - &peerdist, - sizeof(peerdist)); - - /* Send Pragma: no-cache header */ - if (!WinHttpAddRequestHeaders(s->request, pragma_nocache, (ULONG) -1L, WINHTTP_ADDREQ_FLAG_ADD)) { - git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); - goto on_error; - } - - if (post_verb == s->verb) { - /* Send Content-Type and Accept headers -- only necessary on a POST */ - git_str_clear(&buf); - if (git_str_printf(&buf, - "Content-Type: application/x-git-%s-request", - s->service) < 0) - goto on_error; - - if (git_utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to convert content-type to wide characters"); - goto on_error; - } - - if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L, - WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { - git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); - goto on_error; - } - - git_str_clear(&buf); - if (git_str_printf(&buf, - "Accept: application/x-git-%s-result", - s->service) < 0) - goto on_error; - - if (git_utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to convert accept header to wide characters"); - goto on_error; - } - - if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L, - WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { - git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); - goto on_error; - } - } - - for (i = 0; i < t->owner->connect_opts.custom_headers.count; i++) { - if (t->owner->connect_opts.custom_headers.strings[i]) { - wchar_t *custom_header_wide = NULL; - - git_str_clear(&buf); - git_str_puts(&buf, t->owner->connect_opts.custom_headers.strings[i]); - - /* Convert header to wide characters */ - if ((error = git_utf8_to_16_alloc(&custom_header_wide, git_str_cstr(&buf))) < 0) - goto on_error; - - if (!WinHttpAddRequestHeaders(s->request, custom_header_wide, (ULONG)-1L, - WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { - git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); - git__free(custom_header_wide); - goto on_error; - } - - git__free(custom_header_wide); - } - } - - if ((error = apply_credentials(s->request, &t->server.url, WINHTTP_AUTH_TARGET_SERVER, t->server.cred, t->server.auth_mechanisms)) < 0) - goto on_error; - - /* We've done everything up to calling WinHttpSendRequest. */ - - error = 0; - -on_error: - if (error < 0) - winhttp_stream_close(s); - - git__free(proxy_url); - git_str_dispose(&buf); - return error; -} - -static int parse_unauthorized_response( - int *allowed_types, - int *allowed_mechanisms, - HINTERNET request) -{ - DWORD supported, first, target; - - *allowed_types = 0; - *allowed_mechanisms = 0; - - /* WinHttpQueryHeaders() must be called before WinHttpQueryAuthSchemes(). - * We can assume this was already done, since we know we are unauthorized. - */ - if (!WinHttpQueryAuthSchemes(request, &supported, &first, &target)) { - git_error_set(GIT_ERROR_OS, "failed to parse supported auth schemes"); - return GIT_EAUTH; - } - - if (WINHTTP_AUTH_SCHEME_NTLM & supported) { - *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT; - *allowed_types |= GIT_CREDENTIAL_DEFAULT; - *allowed_mechanisms |= GIT_WINHTTP_AUTH_NTLM; - } - - if (WINHTTP_AUTH_SCHEME_NEGOTIATE & supported) { - *allowed_types |= GIT_CREDENTIAL_DEFAULT; - *allowed_mechanisms |= GIT_WINHTTP_AUTH_NEGOTIATE; - } - - if (WINHTTP_AUTH_SCHEME_BASIC & supported) { - *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT; - *allowed_mechanisms |= GIT_WINHTTP_AUTH_BASIC; - } - - if (WINHTTP_AUTH_SCHEME_DIGEST & supported) { - *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT; - *allowed_mechanisms |= GIT_WINHTTP_AUTH_DIGEST; - } - - return 0; -} - -static int write_chunk(HINTERNET request, const char *buffer, size_t len) -{ - DWORD bytes_written; - git_str buf = GIT_STR_INIT; - - /* Chunk header */ - git_str_printf(&buf, "%"PRIXZ"\r\n", len); - - if (git_str_oom(&buf)) - return -1; - - if (!WinHttpWriteData(request, - git_str_cstr(&buf), (DWORD)git_str_len(&buf), - &bytes_written)) { - git_str_dispose(&buf); - git_error_set(GIT_ERROR_OS, "failed to write chunk header"); - return -1; - } - - git_str_dispose(&buf); - - /* Chunk body */ - if (!WinHttpWriteData(request, - buffer, (DWORD)len, - &bytes_written)) { - git_error_set(GIT_ERROR_OS, "failed to write chunk"); - return -1; - } - - /* Chunk footer */ - if (!WinHttpWriteData(request, - "\r\n", 2, - &bytes_written)) { - git_error_set(GIT_ERROR_OS, "failed to write chunk footer"); - return -1; - } - - return 0; -} - -static int winhttp_close_connection(winhttp_subtransport *t) -{ - int ret = 0; - - if (t->connection) { - if (!WinHttpCloseHandle(t->connection)) { - git_error_set(GIT_ERROR_OS, "unable to close connection"); - ret = -1; - } - - t->connection = NULL; - } - - if (t->session) { - if (!WinHttpCloseHandle(t->session)) { - git_error_set(GIT_ERROR_OS, "unable to close session"); - ret = -1; - } - - t->session = NULL; - } - - return ret; -} - -static void CALLBACK winhttp_status( - HINTERNET connection, - DWORD_PTR ctx, - DWORD code, - LPVOID info, - DWORD info_len) -{ - DWORD status; - - GIT_UNUSED(connection); - GIT_UNUSED(info_len); - - switch (code) { - case WINHTTP_CALLBACK_STATUS_SECURE_FAILURE: - status = *((DWORD *)info); - - if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID)) - git_error_set(GIT_ERROR_HTTP, "SSL certificate issued for different common name"); - else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID)) - git_error_set(GIT_ERROR_HTTP, "SSL certificate has expired"); - else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA)) - git_error_set(GIT_ERROR_HTTP, "SSL certificate signed by unknown CA"); - else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT)) - git_error_set(GIT_ERROR_HTTP, "SSL certificate is invalid"); - else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED)) - git_error_set(GIT_ERROR_HTTP, "certificate revocation check failed"); - else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED)) - git_error_set(GIT_ERROR_HTTP, "SSL certificate was revoked"); - else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR)) - git_error_set(GIT_ERROR_HTTP, "security libraries could not be loaded"); - else - git_error_set(GIT_ERROR_HTTP, "unknown security error %lu", status); - - break; - - case WINHTTP_CALLBACK_STATUS_SENDING_REQUEST: - ((winhttp_stream *) ctx)->status_sending_request_reached = 1; - - break; - } -} - -static int user_agent(bool *exists, git_str *out) -{ - const char *product = git_settings__user_agent_product(); - const char *comment = git_settings__user_agent(); - - GIT_ASSERT(product && comment); - - if (!*product) { - *exists = false; - return 0; - } - - git_str_puts(out, product); - - if (*comment) { - git_str_puts(out, " ("); - git_str_puts(out, comment); - git_str_puts(out, ")"); - } - - if (git_str_oom(out)) - return -1; - - *exists = true; - return 0; -} - -static int winhttp_connect( - winhttp_subtransport *t) -{ - wchar_t *wide_host = NULL; - int32_t port; - wchar_t *wide_ua = NULL; - git_str ipv6 = GIT_STR_INIT, ua = GIT_STR_INIT; - const char *host; - int error = -1; - int default_timeout = TIMEOUT_INFINITE; - int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT; - bool has_ua = true; - DWORD protocols = - WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | - WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 | - WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 | - WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3; - - t->session = NULL; - t->connection = NULL; - - /* Prepare port */ - if (git__strntol32(&port, t->server.url.port, - strlen(t->server.url.port), NULL, 10) < 0) - goto on_error; - - /* IPv6? Add braces around the host. */ - if (git_net_url_is_ipv6(&t->server.url)) { - if (git_str_printf(&ipv6, "[%s]", t->server.url.host) < 0) - goto on_error; - - host = ipv6.ptr; - } else { - host = t->server.url.host; - } - - /* Prepare host */ - if (git_utf8_to_16_alloc(&wide_host, host) < 0) { - git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters"); - goto on_error; - } - - if (user_agent(&has_ua, &ua) < 0) - goto on_error; - - if (has_ua && - git_utf8_to_16_alloc(&wide_ua, git_str_cstr(&ua)) < 0) { - git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters"); - goto on_error; - } - - /* Establish session */ - t->session = WinHttpOpen( - wide_ua, - WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, - WINHTTP_NO_PROXY_NAME, - WINHTTP_NO_PROXY_BYPASS, - 0); - - if (!t->session) { - git_error_set(GIT_ERROR_OS, "failed to init WinHTTP"); - goto on_error; - } - - /* - * Do a best-effort attempt to enable TLS 1.3 and 1.2 but allow this to - * fail; if TLS 1.2 or 1.3 support is not available for some reason, - * ignore the failure (it will keep the default protocols). - */ - if (WinHttpSetOption(t->session, - WINHTTP_OPTION_SECURE_PROTOCOLS, - &protocols, - sizeof(protocols)) == FALSE) { - protocols &= ~WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3; - WinHttpSetOption(t->session, - WINHTTP_OPTION_SECURE_PROTOCOLS, - &protocols, - sizeof(protocols)); - } - - if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) { - git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP"); - goto on_error; - } - - - /* Establish connection */ - t->connection = WinHttpConnect( - t->session, - wide_host, - (INTERNET_PORT) port, - 0); - - if (!t->connection) { - git_error_set(GIT_ERROR_OS, "failed to connect to host"); - goto on_error; - } - - if (WinHttpSetStatusCallback( - t->connection, - winhttp_status, - WINHTTP_CALLBACK_FLAG_SECURE_FAILURE | WINHTTP_CALLBACK_FLAG_SEND_REQUEST, - 0 - ) == WINHTTP_INVALID_STATUS_CALLBACK) { - git_error_set(GIT_ERROR_OS, "failed to set status callback"); - goto on_error; - } - - error = 0; - -on_error: - if (error < 0) - winhttp_close_connection(t); - - git_str_dispose(&ua); - git_str_dispose(&ipv6); - git__free(wide_host); - git__free(wide_ua); - - return error; -} - -static int do_send_request(winhttp_stream *s, size_t len, bool chunked) -{ - int attempts; - bool success; - - if (len > DWORD_MAX) { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return -1; - } - - for (attempts = 0; attempts < 5; attempts++) { - if (chunked) { - success = WinHttpSendRequest(s->request, - WINHTTP_NO_ADDITIONAL_HEADERS, 0, - WINHTTP_NO_REQUEST_DATA, 0, - WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH, (DWORD_PTR)s); - } else { - success = WinHttpSendRequest(s->request, - WINHTTP_NO_ADDITIONAL_HEADERS, 0, - WINHTTP_NO_REQUEST_DATA, 0, - (DWORD)len, (DWORD_PTR)s); - } - - if (success || GetLastError() != (DWORD)SEC_E_BUFFER_TOO_SMALL) - break; - } - - return success ? 0 : -1; -} - -static int send_request(winhttp_stream *s, size_t len, bool chunked) -{ - int request_failed = 1, error, attempts = 0; - DWORD ignore_flags, send_request_error; - - git_error_clear(); - - while (request_failed && attempts++ < 3) { - int cert_valid = 1; - int client_cert_requested = 0; - request_failed = 0; - if ((error = do_send_request(s, len, chunked)) < 0) { - send_request_error = GetLastError(); - request_failed = 1; - switch (send_request_error) { - case ERROR_WINHTTP_SECURE_FAILURE: - cert_valid = 0; - break; - case ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED: - client_cert_requested = 1; - break; - default: - git_error_set(GIT_ERROR_OS, "failed to send request"); - return -1; - } - } - - /* - * Only check the certificate if we were able to reach the sending request phase, or - * received a secure failure error. Otherwise, the server certificate won't be available - * since the request wasn't able to complete (e.g. proxy auth required) - */ - if (!cert_valid || - (!request_failed && s->status_sending_request_reached)) { - git_error_clear(); - if ((error = certificate_check(s, cert_valid)) < 0) { - if (git_error_last()->klass == GIT_ERROR_NONE) - git_error_set(GIT_ERROR_OS, "user cancelled certificate check"); - - return error; - } - } - - /* if neither the request nor the certificate check returned errors, we're done */ - if (!request_failed) - return 0; - - if (!cert_valid) { - ignore_flags = no_check_cert_flags; - if (!WinHttpSetOption(s->request, WINHTTP_OPTION_SECURITY_FLAGS, &ignore_flags, sizeof(ignore_flags))) { - git_error_set(GIT_ERROR_OS, "failed to set security options"); - return -1; - } - } - - if (client_cert_requested) { - /* - * Client certificates are not supported, explicitly tell the server that - * (it's possible a client certificate was requested but is not required) - */ - if (!WinHttpSetOption(s->request, WINHTTP_OPTION_CLIENT_CERT_CONTEXT, WINHTTP_NO_CLIENT_CERT_CONTEXT, 0)) { - git_error_set(GIT_ERROR_OS, "failed to set client cert context"); - return -1; - } - } - } - - return error; -} - -static int acquire_credentials( - HINTERNET request, - winhttp_server *server, - const char *url_str, - git_credential_acquire_cb cred_cb, - void *cred_cb_payload) -{ - int allowed_types; - int error = 1; - - if (parse_unauthorized_response(&allowed_types, &server->auth_mechanisms, request) < 0) - return -1; - - if (allowed_types) { - git_credential_free(server->cred); - server->cred = NULL; - - /* Start with URL-specified credentials, if there were any. */ - if (!server->url_cred_presented && server->url.username && server->url.password) { - error = acquire_url_cred(&server->cred, allowed_types, server->url.username, server->url.password); - server->url_cred_presented = 1; - - if (error < 0) - return error; - } - - /* Next use the user-defined callback, if there is one. */ - if (error > 0 && cred_cb) { - error = cred_cb(&server->cred, url_str, server->url.username, allowed_types, cred_cb_payload); - - /* Treat GIT_PASSTHROUGH as though git_credential_acquire_cb isn't set */ - if (error == GIT_PASSTHROUGH) - error = 1; - else if (error < 0) - return error; - } - - /* Finally, invoke the fallback default credential lookup. */ - if (error > 0) { - error = acquire_fallback_cred(&server->cred, url_str, allowed_types); - - if (error < 0) - return error; - } - } - - /* - * No error occurred but we could not find appropriate credentials. - * This behaves like a pass-through. - */ - return error; -} - -static int winhttp_stream_read( - git_smart_subtransport_stream *stream, - char *buffer, - size_t buf_size, - size_t *bytes_read) -{ - winhttp_stream *s = (winhttp_stream *)stream; - winhttp_subtransport *t = OWNING_SUBTRANSPORT(s); - DWORD dw_bytes_read; - char replay_count = 0; - int error; - -replay: - /* Enforce a reasonable cap on the number of replays */ - if (replay_count++ >= GIT_HTTP_REPLAY_MAX) { - git_error_set(GIT_ERROR_HTTP, "too many redirects or authentication replays"); - return GIT_ERROR; /* not GIT_EAUTH because the exact cause is not clear */ - } - - /* Connect if necessary */ - if (!s->request && winhttp_stream_connect(s) < 0) - return -1; - - if (!s->received_response) { - DWORD status_code, status_code_length, content_type_length, bytes_written; - char expected_content_type_8[MAX_CONTENT_TYPE_LEN]; - wchar_t expected_content_type[MAX_CONTENT_TYPE_LEN], content_type[MAX_CONTENT_TYPE_LEN]; - - if (!s->sent_request) { - - if ((error = send_request(s, s->post_body_len, false)) < 0) - return error; - - s->sent_request = 1; - } - - if (s->chunked) { - GIT_ASSERT(s->verb == post_verb); - - /* Flush, if necessary */ - if (s->chunk_buffer_len > 0 && - write_chunk(s->request, s->chunk_buffer, s->chunk_buffer_len) < 0) - return -1; - - s->chunk_buffer_len = 0; - - /* Write the final chunk. */ - if (!WinHttpWriteData(s->request, - "0\r\n\r\n", 5, - &bytes_written)) { - git_error_set(GIT_ERROR_OS, "failed to write final chunk"); - return -1; - } - } - else if (s->post_body) { - char *buffer; - DWORD len = s->post_body_len, bytes_read; - - if (INVALID_SET_FILE_POINTER == SetFilePointer(s->post_body, - 0, 0, FILE_BEGIN) && - NO_ERROR != GetLastError()) { - git_error_set(GIT_ERROR_OS, "failed to reset file pointer"); - return -1; - } - - buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE); - GIT_ERROR_CHECK_ALLOC(buffer); - - while (len > 0) { - DWORD bytes_written; - - if (!ReadFile(s->post_body, buffer, - min(CACHED_POST_BODY_BUF_SIZE, len), - &bytes_read, NULL) || - !bytes_read) { - git__free(buffer); - git_error_set(GIT_ERROR_OS, "failed to read from temp file"); - return -1; - } - - if (!WinHttpWriteData(s->request, buffer, - bytes_read, &bytes_written)) { - git__free(buffer); - git_error_set(GIT_ERROR_OS, "failed to write data"); - return -1; - } - - len -= bytes_read; - GIT_ASSERT(bytes_read == bytes_written); - } - - git__free(buffer); - - /* Eagerly close the temp file */ - CloseHandle(s->post_body); - s->post_body = NULL; - } - - if (!WinHttpReceiveResponse(s->request, 0)) { - git_error_set(GIT_ERROR_OS, "failed to receive response"); - return -1; - } - - /* Verify that we got a 200 back */ - status_code_length = sizeof(status_code); - - if (!WinHttpQueryHeaders(s->request, - WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, - WINHTTP_HEADER_NAME_BY_INDEX, - &status_code, &status_code_length, - WINHTTP_NO_HEADER_INDEX)) { - git_error_set(GIT_ERROR_OS, "failed to retrieve status code"); - return -1; - } - - /* The implementation of WinHTTP prior to Windows 7 will not - * redirect to an identical URI. Some Git hosters use self-redirects - * as part of their DoS mitigation strategy. Check first to see if we - * have a redirect status code, and that we haven't already streamed - * a post body. (We can't replay a streamed POST.) */ - if (!s->chunked && - (HTTP_STATUS_MOVED == status_code || - HTTP_STATUS_REDIRECT == status_code || - (HTTP_STATUS_REDIRECT_METHOD == status_code && - get_verb == s->verb) || - HTTP_STATUS_REDIRECT_KEEP_VERB == status_code || - HTTP_STATUS_PERMANENT_REDIRECT == status_code)) { - - /* Check for Windows 7. This workaround is only necessary on - * Windows Vista and earlier. Windows 7 is version 6.1. */ - wchar_t *location; - DWORD location_length; - char *location8; - - /* OK, fetch the Location header from the redirect. */ - if (WinHttpQueryHeaders(s->request, - WINHTTP_QUERY_LOCATION, - WINHTTP_HEADER_NAME_BY_INDEX, - WINHTTP_NO_OUTPUT_BUFFER, - &location_length, - WINHTTP_NO_HEADER_INDEX) || - GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - git_error_set(GIT_ERROR_OS, "failed to read Location header"); - return -1; - } - - location = git__malloc(location_length); - GIT_ERROR_CHECK_ALLOC(location); - - if (!WinHttpQueryHeaders(s->request, - WINHTTP_QUERY_LOCATION, - WINHTTP_HEADER_NAME_BY_INDEX, - location, - &location_length, - WINHTTP_NO_HEADER_INDEX)) { - git_error_set(GIT_ERROR_OS, "failed to read Location header"); - git__free(location); - return -1; - } - - /* Convert the Location header to UTF-8 */ - if (git_utf8_from_16_alloc(&location8, location) < 0) { - git_error_set(GIT_ERROR_OS, "failed to convert Location header to UTF-8"); - git__free(location); - return -1; - } - - git__free(location); - - /* Replay the request */ - winhttp_stream_close(s); - - if (!git__prefixcmp_icase(location8, prefix_https)) { - bool follow = (t->owner->connect_opts.follow_redirects != GIT_REMOTE_REDIRECT_NONE); - - /* Upgrade to secure connection; disconnect and start over */ - if (git_net_url_apply_redirect(&t->server.url, location8, follow, s->service_url) < 0) { - git__free(location8); - return -1; - } - - winhttp_close_connection(t); - - if (winhttp_connect(t) < 0) - return -1; - } - - git__free(location8); - goto replay; - } - - /* Handle authentication failures */ - if (status_code == HTTP_STATUS_DENIED) { - int error = acquire_credentials(s->request, - &t->server, - t->owner->url, - t->owner->connect_opts.callbacks.credentials, - t->owner->connect_opts.callbacks.payload); - - if (error < 0) { - return error; - } else if (!error) { - GIT_ASSERT(t->server.cred); - winhttp_stream_close(s); - goto replay; - } - } else if (status_code == HTTP_STATUS_PROXY_AUTH_REQ) { - int error = acquire_credentials(s->request, - &t->proxy, - t->owner->connect_opts.proxy_opts.url, - t->owner->connect_opts.proxy_opts.credentials, - t->owner->connect_opts.proxy_opts.payload); - - if (error < 0) { - return error; - } else if (!error) { - GIT_ASSERT(t->proxy.cred); - winhttp_stream_close(s); - goto replay; - } - } - - if (HTTP_STATUS_OK != status_code) { - git_error_set(GIT_ERROR_HTTP, "request failed with status code: %lu", status_code); - return -1; - } - - /* Verify that we got the correct content-type back */ - if (post_verb == s->verb) - p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-result", s->service); - else - p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-advertisement", s->service); - - if (git_utf8_to_16(expected_content_type, MAX_CONTENT_TYPE_LEN, expected_content_type_8) < 0) { - git_error_set(GIT_ERROR_OS, "failed to convert expected content-type to wide characters"); - return -1; - } - - content_type_length = sizeof(content_type); - - if (!WinHttpQueryHeaders(s->request, - WINHTTP_QUERY_CONTENT_TYPE, - WINHTTP_HEADER_NAME_BY_INDEX, - &content_type, &content_type_length, - WINHTTP_NO_HEADER_INDEX)) { - git_error_set(GIT_ERROR_OS, "failed to retrieve response content-type"); - return -1; - } - - if (wcscmp(expected_content_type, content_type)) { - git_error_set(GIT_ERROR_HTTP, "received unexpected content-type"); - return -1; - } - - s->received_response = 1; - } - - if (!WinHttpReadData(s->request, - (LPVOID)buffer, - (DWORD)buf_size, - &dw_bytes_read)) - { - git_error_set(GIT_ERROR_OS, "failed to read data"); - return -1; - } - - *bytes_read = dw_bytes_read; - - return 0; -} - -static int winhttp_stream_write_single( - git_smart_subtransport_stream *stream, - const char *buffer, - size_t len) -{ - winhttp_stream *s = (winhttp_stream *)stream; - DWORD bytes_written; - int error; - - if (!s->request && winhttp_stream_connect(s) < 0) - return -1; - - /* This implementation of write permits only a single call. */ - if (s->sent_request) { - git_error_set(GIT_ERROR_HTTP, "subtransport configured for only one write"); - return -1; - } - - if ((error = send_request(s, len, false)) < 0) - return error; - - s->sent_request = 1; - - if (!WinHttpWriteData(s->request, - (LPCVOID)buffer, - (DWORD)len, - &bytes_written)) { - git_error_set(GIT_ERROR_OS, "failed to write data"); - return -1; - } - - GIT_ASSERT((DWORD)len == bytes_written); - - return 0; -} - -static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch) -{ - UUID uuid; - RPC_STATUS status = UuidCreate(&uuid); - int result; - - if (RPC_S_OK != status && - RPC_S_UUID_LOCAL_ONLY != status && - RPC_S_UUID_NO_ADDRESS != status) { - git_error_set(GIT_ERROR_HTTP, "unable to generate name for temp file"); - return -1; - } - - if (buffer_len_cch < UUID_LENGTH_CCH + 1) { - git_error_set(GIT_ERROR_HTTP, "buffer too small for name of temp file"); - return -1; - } - -#if !defined(__MINGW32__) || defined(MINGW_HAS_SECURE_API) - result = swprintf_s(buffer, buffer_len_cch, -#else - result = wsprintfW(buffer, -#endif - L"%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x", - uuid.Data1, uuid.Data2, uuid.Data3, - uuid.Data4[0], uuid.Data4[1], uuid.Data4[2], uuid.Data4[3], - uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]); - - if (result < UUID_LENGTH_CCH) { - git_error_set(GIT_ERROR_OS, "unable to generate name for temp file"); - return -1; - } - - return 0; -} - -static int get_temp_file(LPWSTR buffer, DWORD buffer_len_cch) -{ - size_t len; - - if (!GetTempPathW(buffer_len_cch, buffer)) { - git_error_set(GIT_ERROR_OS, "failed to get temp path"); - return -1; - } - - len = wcslen(buffer); - - if (buffer[len - 1] != '\\' && len < buffer_len_cch) - buffer[len++] = '\\'; - - if (put_uuid_string(&buffer[len], (size_t)buffer_len_cch - len) < 0) - return -1; - - return 0; -} - -static int winhttp_stream_write_buffered( - git_smart_subtransport_stream *stream, - const char *buffer, - size_t len) -{ - winhttp_stream *s = (winhttp_stream *)stream; - DWORD bytes_written; - - if (!s->request && winhttp_stream_connect(s) < 0) - return -1; - - /* Buffer the payload, using a temporary file so we delegate - * memory management of the data to the operating system. */ - if (!s->post_body) { - wchar_t temp_path[MAX_PATH + 1]; - - if (get_temp_file(temp_path, MAX_PATH + 1) < 0) - return -1; - - s->post_body = CreateFileW(temp_path, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_DELETE, NULL, - CREATE_NEW, - FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_SEQUENTIAL_SCAN, - NULL); - - if (INVALID_HANDLE_VALUE == s->post_body) { - s->post_body = NULL; - git_error_set(GIT_ERROR_OS, "failed to create temporary file"); - return -1; - } - } - - if (!WriteFile(s->post_body, buffer, (DWORD)len, &bytes_written, NULL)) { - git_error_set(GIT_ERROR_OS, "failed to write to temporary file"); - return -1; - } - - GIT_ASSERT((DWORD)len == bytes_written); - - s->post_body_len += bytes_written; - - return 0; -} - -static int winhttp_stream_write_chunked( - git_smart_subtransport_stream *stream, - const char *buffer, - size_t len) -{ - winhttp_stream *s = (winhttp_stream *)stream; - int error; - - if (!s->request && winhttp_stream_connect(s) < 0) - return -1; - - if (!s->sent_request) { - /* Send Transfer-Encoding: chunked header */ - if (!WinHttpAddRequestHeaders(s->request, - transfer_encoding, (ULONG) -1L, - WINHTTP_ADDREQ_FLAG_ADD)) { - git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); - return -1; - } - - if ((error = send_request(s, 0, true)) < 0) - return error; - - s->sent_request = 1; - } - - if (len > CACHED_POST_BODY_BUF_SIZE) { - /* Flush, if necessary */ - if (s->chunk_buffer_len > 0) { - if (write_chunk(s->request, s->chunk_buffer, s->chunk_buffer_len) < 0) - return -1; - - s->chunk_buffer_len = 0; - } - - /* Write chunk directly */ - if (write_chunk(s->request, buffer, len) < 0) - return -1; - } - else { - /* Append as much to the buffer as we can */ - int count = (int)min(CACHED_POST_BODY_BUF_SIZE - s->chunk_buffer_len, len); - - if (!s->chunk_buffer) { - s->chunk_buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE); - GIT_ERROR_CHECK_ALLOC(s->chunk_buffer); - } - - memcpy(s->chunk_buffer + s->chunk_buffer_len, buffer, count); - s->chunk_buffer_len += count; - buffer += count; - len -= count; - - /* Is the buffer full? If so, then flush */ - if (CACHED_POST_BODY_BUF_SIZE == s->chunk_buffer_len) { - if (write_chunk(s->request, s->chunk_buffer, s->chunk_buffer_len) < 0) - return -1; - - s->chunk_buffer_len = 0; - - /* Is there any remaining data from the source? */ - if (len > 0) { - memcpy(s->chunk_buffer, buffer, len); - s->chunk_buffer_len = (unsigned int)len; - } - } - } - - return 0; -} - -static void winhttp_stream_free(git_smart_subtransport_stream *stream) -{ - winhttp_stream *s = (winhttp_stream *)stream; - - winhttp_stream_close(s); - git__free(s); -} - -static int winhttp_stream_alloc(winhttp_subtransport *t, winhttp_stream **stream) -{ - winhttp_stream *s; - - if (!stream) - return -1; - - s = git__calloc(1, sizeof(winhttp_stream)); - GIT_ERROR_CHECK_ALLOC(s); - - s->parent.subtransport = &t->parent; - s->parent.read = winhttp_stream_read; - s->parent.write = winhttp_stream_write_single; - s->parent.free = winhttp_stream_free; - - *stream = s; - - return 0; -} - -static int winhttp_uploadpack_ls( - winhttp_subtransport *t, - winhttp_stream *s) -{ - GIT_UNUSED(t); - - s->service = upload_pack_service; - s->service_url = upload_pack_ls_service_url; - s->verb = get_verb; - - return 0; -} - -static int winhttp_uploadpack( - winhttp_subtransport *t, - winhttp_stream *s) -{ - GIT_UNUSED(t); - - s->service = upload_pack_service; - s->service_url = upload_pack_service_url; - s->verb = post_verb; - - return 0; -} - -static int winhttp_receivepack_ls( - winhttp_subtransport *t, - winhttp_stream *s) -{ - GIT_UNUSED(t); - - s->service = receive_pack_service; - s->service_url = receive_pack_ls_service_url; - s->verb = get_verb; - - return 0; -} - -static int winhttp_receivepack( - winhttp_subtransport *t, - winhttp_stream *s) -{ - GIT_UNUSED(t); - - /* WinHTTP only supports Transfer-Encoding: chunked - * on Windows Vista (NT 6.0) and higher. */ - s->chunked = git_has_win32_version(6, 0, 0); - - if (s->chunked) - s->parent.write = winhttp_stream_write_chunked; - else - s->parent.write = winhttp_stream_write_buffered; - - s->service = receive_pack_service; - s->service_url = receive_pack_service_url; - s->verb = post_verb; - - return 0; -} - -static int winhttp_action( - git_smart_subtransport_stream **stream, - git_smart_subtransport *subtransport, - const char *url, - git_smart_service_t action) -{ - winhttp_subtransport *t = (winhttp_subtransport *)subtransport; - winhttp_stream *s; - int ret = -1; - - if (!t->connection) - if ((ret = git_net_url_parse(&t->server.url, url)) < 0 || - (ret = winhttp_connect(t)) < 0) - return ret; - - if (winhttp_stream_alloc(t, &s) < 0) - return -1; - - if (!stream) - return -1; - - switch (action) - { - case GIT_SERVICE_UPLOADPACK_LS: - ret = winhttp_uploadpack_ls(t, s); - break; - - case GIT_SERVICE_UPLOADPACK: - ret = winhttp_uploadpack(t, s); - break; - - case GIT_SERVICE_RECEIVEPACK_LS: - ret = winhttp_receivepack_ls(t, s); - break; - - case GIT_SERVICE_RECEIVEPACK: - ret = winhttp_receivepack(t, s); - break; - - default: - GIT_ASSERT(0); - } - - if (!ret) - *stream = &s->parent; - - return ret; -} - -static int winhttp_close(git_smart_subtransport *subtransport) -{ - winhttp_subtransport *t = (winhttp_subtransport *)subtransport; - - git_net_url_dispose(&t->server.url); - git_net_url_dispose(&t->proxy.url); - - if (t->server.cred) { - t->server.cred->free(t->server.cred); - t->server.cred = NULL; - } - - if (t->proxy.cred) { - t->proxy.cred->free(t->proxy.cred); - t->proxy.cred = NULL; - } - - return winhttp_close_connection(t); -} - -static void winhttp_free(git_smart_subtransport *subtransport) -{ - winhttp_subtransport *t = (winhttp_subtransport *)subtransport; - - winhttp_close(subtransport); - - git__free(t); -} - -int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *owner, void *param) -{ - winhttp_subtransport *t; - - GIT_UNUSED(param); - - if (!out) - return -1; - - t = git__calloc(1, sizeof(winhttp_subtransport)); - GIT_ERROR_CHECK_ALLOC(t); - - t->owner = (transport_smart *)owner; - t->parent.action = winhttp_action; - t->parent.close = winhttp_close; - t->parent.free = winhttp_free; - - *out = (git_smart_subtransport *) t; - return 0; -} - -#endif /* GIT_WINHTTP */ diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/tree-cache.c b/vendor/libgit2-sys/libgit2/src/libgit2/tree-cache.c deleted file mode 100644 index 95d8798..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/tree-cache.c +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "tree-cache.h" - -#include "pool.h" -#include "tree.h" - -static git_tree_cache *find_child( - const git_tree_cache *tree, const char *path, const char *end) -{ - size_t i, dirlen = end ? (size_t)(end - path) : strlen(path); - - for (i = 0; i < tree->children_count; ++i) { - git_tree_cache *child = tree->children[i]; - - if (child->namelen == dirlen && !memcmp(path, child->name, dirlen)) - return child; - } - - return NULL; -} - -void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path) -{ - const char *ptr = path, *end; - - if (tree == NULL) - return; - - tree->entry_count = -1; - - while (ptr != NULL) { - end = strchr(ptr, '/'); - - if (end == NULL) /* End of path */ - break; - - tree = find_child(tree, ptr, end); - if (tree == NULL) /* We don't have that tree */ - return; - - tree->entry_count = -1; - ptr = end + 1; - } -} - -const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char *path) -{ - const char *ptr = path, *end; - - if (tree == NULL) { - return NULL; - } - - while (1) { - end = strchr(ptr, '/'); - - tree = find_child(tree, ptr, end); - if (tree == NULL) /* Can't find it */ - return NULL; - - if (end == NULL || *end + 1 == '\0') - return tree; - - ptr = end + 1; - } -} - -static int read_tree_internal( - git_tree_cache **out, - const char **buffer_in, - const char *buffer_end, - git_oid_t oid_type, - git_pool *pool) -{ - git_tree_cache *tree = NULL; - const char *name_start, *buffer; - size_t oid_size = git_oid_size(oid_type); - int count; - - buffer = name_start = *buffer_in; - - if ((buffer = memchr(buffer, '\0', buffer_end - buffer)) == NULL) - goto corrupted; - - if (++buffer >= buffer_end) - goto corrupted; - - if (git_tree_cache_new(&tree, name_start, oid_type, pool) < 0) - return -1; - - /* Blank-terminated ASCII decimal number of entries in this tree */ - if (git__strntol32(&count, buffer, buffer_end - buffer, &buffer, 10) < 0) - goto corrupted; - - tree->entry_count = count; - - if (*buffer != ' ' || ++buffer >= buffer_end) - goto corrupted; - - /* Number of children of the tree, newline-terminated */ - if (git__strntol32(&count, buffer, buffer_end - buffer, &buffer, 10) < 0 || count < 0) - goto corrupted; - - tree->children_count = count; - - if (*buffer != '\n' || ++buffer > buffer_end) - goto corrupted; - - /* The OID is only there if it's not invalidated */ - if (tree->entry_count >= 0) { - /* 160-bit SHA-1 for this tree and it's children */ - if (buffer + oid_size > buffer_end) - goto corrupted; - - git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, oid_type); - buffer += oid_size; - } - - /* Parse children: */ - if (tree->children_count > 0) { - size_t i, bufsize; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&bufsize, tree->children_count, sizeof(git_tree_cache*)); - - tree->children = git_pool_malloc(pool, bufsize); - GIT_ERROR_CHECK_ALLOC(tree->children); - - memset(tree->children, 0x0, bufsize); - - for (i = 0; i < tree->children_count; ++i) { - if (read_tree_internal(&tree->children[i], &buffer, buffer_end, oid_type, pool) < 0) - goto corrupted; - } - } - - *buffer_in = buffer; - *out = tree; - return 0; - - corrupted: - git_error_set(GIT_ERROR_INDEX, "corrupted TREE extension in index"); - return -1; -} - -int git_tree_cache_read( - git_tree_cache **tree, - const char *buffer, - size_t buffer_size, - git_oid_t oid_type, - git_pool *pool) -{ - const char *buffer_end = buffer + buffer_size; - - if (read_tree_internal(tree, &buffer, buffer_end, oid_type, pool) < 0) - return -1; - - if (buffer < buffer_end) { - git_error_set(GIT_ERROR_INDEX, "corrupted TREE extension in index (unexpected trailing data)"); - return -1; - } - - return 0; -} - -static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_pool *pool) -{ - git_repository *repo; - size_t i, j, nentries, ntrees, alloc_size; - int error; - - repo = git_tree_owner(tree); - - git_oid_cpy(&cache->oid, git_tree_id(tree)); - nentries = git_tree_entrycount(tree); - - /* - * We make sure we know how many trees we need to allocate for - * so we don't have to realloc and change the pointers for the - * parents. - */ - ntrees = 0; - for (i = 0; i < nentries; i++) { - const git_tree_entry *entry; - - entry = git_tree_entry_byindex(tree, i); - if (git_tree_entry_filemode(entry) == GIT_FILEMODE_TREE) - ntrees++; - } - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloc_size, ntrees, sizeof(git_tree_cache *)); - - cache->children_count = ntrees; - cache->children = git_pool_mallocz(pool, alloc_size); - GIT_ERROR_CHECK_ALLOC(cache->children); - - j = 0; - for (i = 0; i < nentries; i++) { - const git_tree_entry *entry; - git_tree *subtree; - - entry = git_tree_entry_byindex(tree, i); - if (git_tree_entry_filemode(entry) != GIT_FILEMODE_TREE) { - cache->entry_count++; - continue; - } - - if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), cache->oid_type, pool)) < 0) - return error; - - if ((error = git_tree_lookup(&subtree, repo, git_tree_entry_id(entry))) < 0) - return error; - - error = read_tree_recursive(cache->children[j], subtree, pool); - git_tree_free(subtree); - cache->entry_count += cache->children[j]->entry_count; - j++; - - if (error < 0) - return error; - } - - return 0; -} - -int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool) -{ - int error; - git_tree_cache *cache; - - if ((error = git_tree_cache_new(&cache, "", oid_type, pool)) < 0) - return error; - - if ((error = read_tree_recursive(cache, tree, pool)) < 0) - return error; - - *out = cache; - return 0; -} - -int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool) -{ - size_t name_len, alloc_size; - git_tree_cache *tree; - - name_len = strlen(name); - - GIT_ERROR_CHECK_ALLOC_ADD3(&alloc_size, sizeof(git_tree_cache), name_len, 1); - - tree = git_pool_malloc(pool, alloc_size); - GIT_ERROR_CHECK_ALLOC(tree); - - memset(tree, 0x0, sizeof(git_tree_cache)); - /* NUL-terminated tree name */ - tree->oid_type = oid_type; - tree->namelen = name_len; - memcpy(tree->name, name, name_len); - tree->name[name_len] = '\0'; - - *out = tree; - return 0; -} - -static void write_tree(git_str *out, git_tree_cache *tree) -{ - size_t i; - - git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count); - - if (tree->entry_count != -1) - git_str_put(out, (char *)&tree->oid.id, git_oid_size(tree->oid_type)); - - for (i = 0; i < tree->children_count; i++) - write_tree(out, tree->children[i]); -} - -int git_tree_cache_write(git_str *out, git_tree_cache *tree) -{ - write_tree(out, tree); - - return git_str_oom(out) ? -1 : 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/tree-cache.h b/vendor/libgit2-sys/libgit2/src/libgit2/tree-cache.h deleted file mode 100644 index e4a73f2..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/tree-cache.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_tree_cache_h__ -#define INCLUDE_tree_cache_h__ - -#include "common.h" - -#include "pool.h" -#include "str.h" -#include "git2/oid.h" - -typedef struct git_tree_cache { - struct git_tree_cache **children; - size_t children_count; - - git_oid_t oid_type; - - ssize_t entry_count; - git_oid oid; - size_t namelen; - char name[GIT_FLEX_ARRAY]; -} git_tree_cache; - -int git_tree_cache_write(git_str *out, git_tree_cache *tree); -int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_oid_t oid_type, git_pool *pool); -void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path); -const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char *path); -int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool); -/** - * Read a tree as the root of the tree cache (like for `git read-tree`) - */ -int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool); -void git_tree_cache_free(git_tree_cache *tree); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/tree.c b/vendor/libgit2-sys/libgit2/src/libgit2/tree.c deleted file mode 100644 index ad9d8af..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/tree.c +++ /dev/null @@ -1,1338 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "tree.h" - -#include "commit.h" -#include "git2/repository.h" -#include "git2/object.h" -#include "futils.h" -#include "tree-cache.h" -#include "index.h" -#include "path.h" - -#define DEFAULT_TREE_SIZE 16 -#define MAX_FILEMODE_BYTES 6 - -#define TREE_ENTRY_CHECK_NAMELEN(n) \ - if (n > UINT16_MAX) { git_error_set(GIT_ERROR_INVALID, "tree entry path too long"); } - -GIT_HASHMAP_STR_FUNCTIONS(git_treebuilder_entrymap, GIT_HASHMAP_INLINE, git_tree_entry *); - -static bool valid_filemode(const int filemode) -{ - return (filemode == GIT_FILEMODE_TREE - || filemode == GIT_FILEMODE_BLOB - || filemode == GIT_FILEMODE_BLOB_EXECUTABLE - || filemode == GIT_FILEMODE_LINK - || filemode == GIT_FILEMODE_COMMIT); -} - -GIT_INLINE(git_filemode_t) normalize_filemode(git_filemode_t filemode) -{ - /* Tree bits set, but it's not a commit */ - if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_TREE) - return GIT_FILEMODE_TREE; - - /* If any of the x bits are set */ - if (GIT_PERMS_IS_EXEC(filemode)) - return GIT_FILEMODE_BLOB_EXECUTABLE; - - /* 16XXXX means commit */ - if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_COMMIT) - return GIT_FILEMODE_COMMIT; - - /* 12XXXX means symlink */ - if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_LINK) - return GIT_FILEMODE_LINK; - - /* Otherwise, return a blob */ - return GIT_FILEMODE_BLOB; -} - -static int valid_entry_name(git_repository *repo, const char *filename) -{ - return *filename != '\0' && - git_path_is_valid(repo, filename, 0, - GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT | GIT_FS_PATH_REJECT_SLASH); -} - -static int entry_sort_cmp(const void *a, const void *b) -{ - const git_tree_entry *e1 = (const git_tree_entry *)a; - const git_tree_entry *e2 = (const git_tree_entry *)b; - - return git_fs_path_cmp( - e1->filename, e1->filename_len, git_tree_entry__is_tree(e1), - e2->filename, e2->filename_len, git_tree_entry__is_tree(e2), - git__strncmp); -} - -int git_tree_entry_cmp(const git_tree_entry *e1, const git_tree_entry *e2) -{ - return entry_sort_cmp(e1, e2); -} - -/** - * Allocate a new self-contained entry, with enough space after it to - * store the filename and the id. - */ -static git_tree_entry *alloc_entry(const char *filename, size_t filename_len, const git_oid *id) -{ - git_tree_entry *entry = NULL; - char *filename_ptr; - size_t tree_len; - -#ifdef GIT_EXPERIMENTAL_SHA256 - size_t oid_size = git_oid_size(id->type); -#else - size_t oid_size = GIT_OID_SHA1_SIZE; -#endif - - TREE_ENTRY_CHECK_NAMELEN(filename_len); - - if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) || - GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, 1) || - GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, oid_size)) - return NULL; - - entry = git__calloc(1, tree_len); - if (!entry) - return NULL; - - filename_ptr = ((char *) entry) + sizeof(git_tree_entry); - memcpy(filename_ptr, filename, filename_len); - entry->filename = filename_ptr; - entry->filename_len = (uint16_t)filename_len; - - git_oid_cpy(&entry->oid, id); - - return entry; -} - -struct tree_key_search { - const char *filename; - uint16_t filename_len; -}; - -static int homing_search_cmp(const void *key, const void *array_member) -{ - const struct tree_key_search *ksearch = key; - const git_tree_entry *entry = array_member; - - const uint16_t len1 = ksearch->filename_len; - const uint16_t len2 = entry->filename_len; - - return memcmp( - ksearch->filename, - entry->filename, - len1 < len2 ? len1 : len2 - ); -} - -/* - * Search for an entry in a given tree. - * - * Note that this search is performed in two steps because - * of the way tree entries are sorted internally in git: - * - * Entries in a tree are not sorted alphabetically; two entries - * with the same root prefix will have different positions - * depending on whether they are folders (subtrees) or normal files. - * - * Consequently, it is not possible to find an entry on the tree - * with a binary search if you don't know whether the filename - * you're looking for is a folder or a normal file. - * - * To work around this, we first perform a homing binary search - * on the tree, using the minimal length root prefix of our filename. - * Once the comparisons for this homing search start becoming - * ambiguous because of folder vs file sorting, we look linearly - * around the area for our target file. - */ -static int tree_key_search( - size_t *at_pos, - const git_tree *tree, - const char *filename, - size_t filename_len) -{ - struct tree_key_search ksearch; - const git_tree_entry *entry; - size_t homing, i; - - TREE_ENTRY_CHECK_NAMELEN(filename_len); - - ksearch.filename = filename; - ksearch.filename_len = (uint16_t)filename_len; - - /* Initial homing search; find an entry on the tree with - * the same prefix as the filename we're looking for */ - - if (git_array_search(&homing, - tree->entries, &homing_search_cmp, &ksearch) < 0) - return GIT_ENOTFOUND; /* just a signal error; not passed back to user */ - - /* We found a common prefix. Look forward as long as - * there are entries that share the common prefix */ - for (i = homing; i < tree->entries.size; ++i) { - entry = git_array_get(tree->entries, i); - - if (homing_search_cmp(&ksearch, entry) < 0) - break; - - if (entry->filename_len == filename_len && - memcmp(filename, entry->filename, filename_len) == 0) { - if (at_pos) - *at_pos = i; - - return 0; - } - } - - /* If we haven't found our filename yet, look backwards - * too as long as we have entries with the same prefix */ - if (homing > 0) { - i = homing - 1; - - do { - entry = git_array_get(tree->entries, i); - - if (homing_search_cmp(&ksearch, entry) > 0) - break; - - if (entry->filename_len == filename_len && - memcmp(filename, entry->filename, filename_len) == 0) { - if (at_pos) - *at_pos = i; - - return 0; - } - } while (i-- > 0); - } - - /* The filename doesn't exist at all */ - return GIT_ENOTFOUND; -} - -void git_tree_entry_free(git_tree_entry *entry) -{ - if (entry == NULL) - return; - - git__free(entry); -} - -int git_tree_entry_dup(git_tree_entry **dest, const git_tree_entry *source) -{ - git_tree_entry *cpy; - - GIT_ASSERT_ARG(source); - - cpy = alloc_entry(source->filename, source->filename_len, &source->oid); - if (cpy == NULL) - return -1; - - cpy->attr = source->attr; - - *dest = cpy; - return 0; -} - -void git_tree__free(void *_tree) -{ - git_tree *tree = _tree; - - git_odb_object_free(tree->odb_obj); - git_array_clear(tree->entries); - git__free(tree); -} - -git_filemode_t git_tree_entry_filemode(const git_tree_entry *entry) -{ - return normalize_filemode(entry->attr); -} - -git_filemode_t git_tree_entry_filemode_raw(const git_tree_entry *entry) -{ - return entry->attr; -} - -const char *git_tree_entry_name(const git_tree_entry *entry) -{ - GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL); - return entry->filename; -} - -const git_oid *git_tree_entry_id(const git_tree_entry *entry) -{ - GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL); - return &entry->oid; -} - -git_object_t git_tree_entry_type(const git_tree_entry *entry) -{ - GIT_ASSERT_ARG_WITH_RETVAL(entry, GIT_OBJECT_INVALID); - - if (S_ISGITLINK(entry->attr)) - return GIT_OBJECT_COMMIT; - else if (S_ISDIR(entry->attr)) - return GIT_OBJECT_TREE; - else - return GIT_OBJECT_BLOB; -} - -int git_tree_entry_to_object( - git_object **object_out, - git_repository *repo, - const git_tree_entry *entry) -{ - GIT_ASSERT_ARG(entry); - GIT_ASSERT_ARG(object_out); - - return git_object_lookup(object_out, repo, &entry->oid, GIT_OBJECT_ANY); -} - -static const git_tree_entry *entry_fromname( - const git_tree *tree, const char *name, size_t name_len) -{ - size_t idx; - - if (tree_key_search(&idx, tree, name, name_len) < 0) - return NULL; - - return git_array_get(tree->entries, idx); -} - -const git_tree_entry *git_tree_entry_byname( - const git_tree *tree, const char *filename) -{ - GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(filename, NULL); - - return entry_fromname(tree, filename, strlen(filename)); -} - -const git_tree_entry *git_tree_entry_byindex( - const git_tree *tree, size_t idx) -{ - GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL); - return git_array_get(tree->entries, idx); -} - -const git_tree_entry *git_tree_entry_byid( - const git_tree *tree, const git_oid *id) -{ - size_t i; - const git_tree_entry *e; - - GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL); - - git_array_foreach(tree->entries, i, e) { - if (git_oid_equal(&e->oid, id)) - return e; - } - - return NULL; -} - -size_t git_tree_entrycount(const git_tree *tree) -{ - GIT_ASSERT_ARG_WITH_RETVAL(tree, 0); - return tree->entries.size; -} - -size_t git_treebuilder_entrycount(git_treebuilder *bld) -{ - GIT_ASSERT_ARG_WITH_RETVAL(bld, 0); - - return git_treebuilder_entrymap_size(&bld->map); -} - -GIT_INLINE(void) set_error(const char *str, const char *path) -{ - if (path) - git_error_set(GIT_ERROR_TREE, "%s - %s", str, path); - else - git_error_set(GIT_ERROR_TREE, "%s", str); -} - -static int tree_error(const char *str, const char *path) -{ - set_error(str, path); - return -1; -} - -static int tree_parse_error(const char *str, const char *path) -{ - set_error(str, path); - return GIT_EINVALID; -} - -static int parse_mode(uint16_t *mode_out, const char *buffer, size_t buffer_len, const char **buffer_out) -{ - int32_t mode; - int error; - - if (!buffer_len || git__isspace(*buffer)) - return -1; - - if ((error = git__strntol32(&mode, buffer, buffer_len, buffer_out, 8)) < 0) - return error; - - if (mode < 0 || (uint32_t)mode > UINT16_MAX) - return -1; - - *mode_out = mode; - - return 0; -} - -int git_tree__parse_raw(void *_tree, const char *data, size_t size, git_oid_t oid_type) -{ - git_tree *tree = _tree; - const char *buffer; - const char *buffer_end; - const long oid_size = (long)git_oid_size(oid_type); - - buffer = data; - buffer_end = buffer + size; - - tree->odb_obj = NULL; - git_array_init_to_size(tree->entries, DEFAULT_TREE_SIZE); - GIT_ERROR_CHECK_ARRAY(tree->entries); - - while (buffer < buffer_end) { - git_tree_entry *entry; - size_t filename_len; - const char *nul; - uint16_t attr; - - if (parse_mode(&attr, buffer, buffer_end - buffer, &buffer) < 0 || !buffer) - return tree_parse_error("failed to parse tree: can't parse filemode", NULL); - - if (buffer >= buffer_end || (*buffer++) != ' ') - return tree_parse_error("failed to parse tree: missing space after filemode", NULL); - - if ((nul = memchr(buffer, 0, buffer_end - buffer)) == NULL) - return tree_parse_error("failed to parse tree: object is corrupted", NULL); - - if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX) - return tree_parse_error("failed to parse tree: can't parse filename", NULL); - - if ((buffer_end - (nul + 1)) < (long)oid_size) - return tree_parse_error("failed to parse tree: can't parse OID", NULL); - - /* Allocate the entry */ - entry = git_array_alloc(tree->entries); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->attr = attr; - entry->filename_len = (uint16_t)filename_len; - entry->filename = buffer; - buffer += filename_len + 1; - - git_oid__fromraw(&entry->oid, (unsigned char *)buffer, oid_type); - buffer += oid_size; - } - - return 0; -} - -int git_tree__parse(void *_tree, git_odb_object *odb_obj, git_oid_t oid_type) -{ - git_tree *tree = _tree; - const char *data = git_odb_object_data(odb_obj); - size_t size = git_odb_object_size(odb_obj); - int error; - - if ((error = git_tree__parse_raw(tree, data, size, oid_type)) < 0 || - (error = git_odb_object_dup(&tree->odb_obj, odb_obj)) < 0) - return error; - - return error; -} - -static size_t find_next_dir(const char *dirname, git_index *index, size_t start) -{ - size_t dirlen, i, entries = git_index_entrycount(index); - - dirlen = strlen(dirname); - for (i = start; i < entries; ++i) { - const git_index_entry *entry = git_index_get_byindex(index, i); - if (strlen(entry->path) < dirlen || - memcmp(entry->path, dirname, dirlen) || - (dirlen > 0 && entry->path[dirlen] != '/')) { - break; - } - } - - return i; -} - -static git_object_t otype_from_mode(git_filemode_t filemode) -{ - switch (filemode) { - case GIT_FILEMODE_TREE: - return GIT_OBJECT_TREE; - case GIT_FILEMODE_COMMIT: - return GIT_OBJECT_COMMIT; - default: - return GIT_OBJECT_BLOB; - } -} - -static int check_entry(git_repository *repo, const char *filename, const git_oid *id, git_filemode_t filemode) -{ - if (!valid_filemode(filemode)) - return tree_error("failed to insert entry: invalid filemode for file", filename); - - if (!valid_entry_name(repo, filename)) - return tree_error("failed to insert entry: invalid name for a tree entry", filename); - - if (git_oid_is_zero(id)) - return tree_error("failed to insert entry: invalid null OID", filename); - - if (filemode != GIT_FILEMODE_COMMIT && - !git_object__is_valid(repo, id, otype_from_mode(filemode))) - return tree_error("failed to insert entry: invalid object specified", filename); - - return 0; -} - -static int git_treebuilder__write_with_buffer( - git_oid *oid, - git_treebuilder *bld, - git_str *buf) -{ - int error = 0; - size_t i, entrycount; - git_odb *odb; - git_tree_entry *entry; - git_vector entries = GIT_VECTOR_INIT; - size_t oid_size = git_oid_size(bld->repo->oid_type); - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - git_str_clear(buf); - - entrycount = git_treebuilder_entrymap_size(&bld->map); - - if ((error = git_vector_init(&entries, entrycount, entry_sort_cmp)) < 0) - goto out; - - if (buf->asize == 0 && - (error = git_str_grow(buf, entrycount * 72)) < 0) - goto out; - - while (git_treebuilder_entrymap_iterate(&iter, NULL, &entry, &bld->map) == 0) { - if ((error = git_vector_insert(&entries, entry)) < 0) - goto out; - } - - git_vector_sort(&entries); - - for (i = 0; i < entries.length && !error; ++i) { - entry = git_vector_get(&entries, i); - - git_str_printf(buf, "%o ", entry->attr); - git_str_put(buf, entry->filename, entry->filename_len + 1); - git_str_put(buf, (char *)entry->oid.id, oid_size); - - if (git_str_oom(buf)) { - error = -1; - goto out; - } - } - - if ((error = git_repository_odb__weakptr(&odb, bld->repo)) == 0) - error = git_odb_write(oid, odb, buf->ptr, buf->size, GIT_OBJECT_TREE); - -out: - git_vector_dispose(&entries); - - return error; -} - -static int append_entry( - git_treebuilder *bld, - const char *filename, - const git_oid *id, - git_filemode_t filemode, - bool validate) -{ - git_tree_entry *entry; - int error = 0; - - if (validate && ((error = check_entry(bld->repo, filename, id, filemode)) < 0)) - return error; - - entry = alloc_entry(filename, strlen(filename), id); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->attr = (uint16_t)filemode; - - if ((error = git_treebuilder_entrymap_put(&bld->map, entry->filename, entry)) < 0) { - git_tree_entry_free(entry); - git_error_set(GIT_ERROR_TREE, "failed to append entry %s to the tree builder", filename); - return -1; - } - - return 0; -} - -static int write_tree( - git_oid *oid, - git_repository *repo, - git_index *index, - const char *dirname, - size_t start, - git_str *shared_buf) -{ - git_treebuilder *bld = NULL; - size_t i, entries = git_index_entrycount(index); - int error; - size_t dirname_len = strlen(dirname); - const git_tree_cache *cache; - - cache = git_tree_cache_get(index->tree, dirname); - if (cache != NULL && cache->entry_count >= 0){ - git_oid_cpy(oid, &cache->oid); - return (int)find_next_dir(dirname, index, start); - } - - if ((error = git_treebuilder_new(&bld, repo, NULL)) < 0 || bld == NULL) - return -1; - - /* - * This loop is unfortunate, but necessary. The index doesn't have - * any directories, so we need to handle that manually, and we - * need to keep track of the current position. - */ - for (i = start; i < entries; ++i) { - const git_index_entry *entry = git_index_get_byindex(index, i); - const char *filename, *next_slash; - - /* - * If we've left our (sub)tree, exit the loop and return. The - * first check is an early out (and security for the - * third). The second check is a simple prefix comparison. The - * third check catches situations where there is a directory - * win32/sys and a file win32mmap.c. Without it, the following - * code believes there is a file win32/mmap.c - */ - if (strlen(entry->path) < dirname_len || - memcmp(entry->path, dirname, dirname_len) || - (dirname_len > 0 && entry->path[dirname_len] != '/')) { - break; - } - - filename = entry->path + dirname_len; - if (*filename == '/') - filename++; - next_slash = strchr(filename, '/'); - if (next_slash) { - git_oid sub_oid; - int written; - char *subdir, *last_comp; - - subdir = git__strndup(entry->path, next_slash - entry->path); - GIT_ERROR_CHECK_ALLOC(subdir); - - /* Write out the subtree */ - written = write_tree(&sub_oid, repo, index, subdir, i, shared_buf); - if (written < 0) { - git__free(subdir); - goto on_error; - } else { - i = written - 1; /* -1 because of the loop increment */ - } - - /* - * We need to figure out what we want toinsert - * into this tree. If we're traversing - * deps/zlib/, then we only want to write - * 'zlib' into the tree. - */ - last_comp = strrchr(subdir, '/'); - if (last_comp) { - last_comp++; /* Get rid of the '/' */ - } else { - last_comp = subdir; - } - - error = append_entry(bld, last_comp, &sub_oid, S_IFDIR, true); - git__free(subdir); - if (error < 0) - goto on_error; - } else { - error = append_entry(bld, filename, &entry->id, entry->mode, true); - if (error < 0) - goto on_error; - } - } - - if (git_treebuilder__write_with_buffer(oid, bld, shared_buf) < 0) - goto on_error; - - git_treebuilder_free(bld); - return (int)i; - -on_error: - git_treebuilder_free(bld); - return -1; -} - -int git_tree__write_index( - git_oid *oid, git_index *index, git_repository *repo) -{ - int ret; - git_tree *tree; - git_str shared_buf = GIT_STR_INIT; - bool old_ignore_case = false; - - GIT_ASSERT_ARG(oid); - GIT_ASSERT_ARG(index); - GIT_ASSERT_ARG(repo); - - if (git_index_has_conflicts(index)) { - git_error_set(GIT_ERROR_INDEX, - "cannot create a tree from a not fully merged index."); - return GIT_EUNMERGED; - } - - if (index->tree != NULL && index->tree->entry_count >= 0) { - git_oid_cpy(oid, &index->tree->oid); - return 0; - } - - /* The tree cache didn't help us; we'll have to write - * out a tree. If the index is ignore_case, we must - * make it case-sensitive for the duration of the tree-write - * operation. */ - - if (index->ignore_case) { - old_ignore_case = true; - git_index__set_ignore_case(index, false); - } - - ret = write_tree(oid, repo, index, "", 0, &shared_buf); - git_str_dispose(&shared_buf); - - if (old_ignore_case) - git_index__set_ignore_case(index, true); - - index->tree = NULL; - - if (ret < 0) - return ret; - - git_pool_clear(&index->tree_pool); - - if ((ret = git_tree_lookup(&tree, repo, oid)) < 0) - return ret; - - /* Read the tree cache into the index */ - ret = git_tree_cache_read_tree(&index->tree, tree, index->oid_type, &index->tree_pool); - git_tree_free(tree); - - return ret; -} - -int git_treebuilder_new( - git_treebuilder **builder_p, - git_repository *repo, - const git_tree *source) -{ - git_treebuilder *bld; - size_t i; - - GIT_ASSERT_ARG(builder_p); - GIT_ASSERT_ARG(repo); - - bld = git__calloc(1, sizeof(git_treebuilder)); - GIT_ERROR_CHECK_ALLOC(bld); - - bld->repo = repo; - - if (source != NULL) { - git_tree_entry *entry_src; - - git_array_foreach(source->entries, i, entry_src) { - if (append_entry( - bld, entry_src->filename, - &entry_src->oid, - entry_src->attr, - false) < 0) - goto on_error; - } - } - - *builder_p = bld; - return 0; - -on_error: - git_treebuilder_free(bld); - return -1; -} - -int git_treebuilder_insert( - const git_tree_entry **entry_out, - git_treebuilder *bld, - const char *filename, - const git_oid *id, - git_filemode_t filemode) -{ - git_tree_entry *entry; - int error; - - GIT_ASSERT_ARG(bld); - GIT_ASSERT_ARG(id); - GIT_ASSERT_ARG(filename); - - if ((error = check_entry(bld->repo, filename, id, filemode)) < 0) - return error; - - if (git_treebuilder_entrymap_get(&entry, &bld->map, filename) == 0) { - git_oid_cpy(&entry->oid, id); - } else { - entry = alloc_entry(filename, strlen(filename), id); - GIT_ERROR_CHECK_ALLOC(entry); - - if (git_treebuilder_entrymap_put(&bld->map, entry->filename, entry) < 0) { - git_tree_entry_free(entry); - git_error_set(GIT_ERROR_TREE, "failed to insert %s", filename); - return -1; - } - } - - entry->attr = filemode; - - if (entry_out) - *entry_out = entry; - - return 0; -} - -static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename) -{ - git_tree_entry *entry; - - GIT_ASSERT_ARG_WITH_RETVAL(bld, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(filename, NULL); - - if (git_treebuilder_entrymap_get(&entry, &bld->map, filename) != 0) - return NULL; - - return entry; -} - -const git_tree_entry *git_treebuilder_get(git_treebuilder *bld, const char *filename) -{ - return treebuilder_get(bld, filename); -} - -int git_treebuilder_remove(git_treebuilder *bld, const char *filename) -{ - git_tree_entry *entry = treebuilder_get(bld, filename); - - if (entry == NULL) - return tree_error("failed to remove entry: file isn't in the tree", filename); - - git_treebuilder_entrymap_remove(&bld->map, filename); - git_tree_entry_free(entry); - - return 0; -} - -int git_treebuilder_write(git_oid *oid, git_treebuilder *bld) -{ - GIT_ASSERT_ARG(oid); - GIT_ASSERT_ARG(bld); - - return git_treebuilder__write_with_buffer(oid, bld, &bld->write_cache); -} - -int git_treebuilder_filter( - git_treebuilder *bld, - git_treebuilder_filter_cb filter, - void *payload) -{ - const char *filename; - git_tree_entry *entry; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - GIT_ASSERT_ARG(bld); - GIT_ASSERT_ARG(filter); - - while (git_treebuilder_entrymap_iterate(&iter, &filename, &entry, &bld->map) == 0) { - if (filter(entry, payload)) { - git_treebuilder_entrymap_remove(&bld->map, filename); - git_tree_entry_free(entry); - } - } - - return 0; -} - -int git_treebuilder_clear(git_treebuilder *bld) -{ - git_tree_entry *e; - git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT; - - GIT_ASSERT_ARG(bld); - - while (git_treebuilder_entrymap_iterate(&iter, NULL, &e, &bld->map) == 0) - git_tree_entry_free(e); - - git_treebuilder_entrymap_clear(&bld->map); - - return 0; -} - -void git_treebuilder_free(git_treebuilder *bld) -{ - if (bld == NULL) - return; - - git_str_dispose(&bld->write_cache); - git_treebuilder_clear(bld); - git_treebuilder_entrymap_dispose(&bld->map); - git__free(bld); -} - -static size_t subpath_len(const char *path) -{ - const char *slash_pos = strchr(path, '/'); - if (slash_pos == NULL) - return strlen(path); - - return slash_pos - path; -} - -int git_tree_entry_bypath( - git_tree_entry **entry_out, - const git_tree *root, - const char *path) -{ - int error = 0; - git_tree *subtree; - const git_tree_entry *entry; - size_t filename_len; - - /* Find how long is the current path component (i.e. - * the filename between two slashes */ - filename_len = subpath_len(path); - - if (filename_len == 0) { - git_error_set(GIT_ERROR_TREE, "invalid tree path given"); - return GIT_ENOTFOUND; - } - - entry = entry_fromname(root, path, filename_len); - - if (entry == NULL) { - git_error_set(GIT_ERROR_TREE, - "the path '%.*s' does not exist in the given tree", (int) filename_len, path); - return GIT_ENOTFOUND; - } - - switch (path[filename_len]) { - case '/': - /* If there are more components in the path... - * then this entry *must* be a tree */ - if (!git_tree_entry__is_tree(entry)) { - git_error_set(GIT_ERROR_TREE, - "the path '%.*s' exists but is not a tree", (int) filename_len, path); - return GIT_ENOTFOUND; - } - - /* If there's only a slash left in the path, we - * return the current entry; otherwise, we keep - * walking down the path */ - if (path[filename_len + 1] != '\0') - break; - /* fall through */ - case '\0': - /* If there are no more components in the path, return - * this entry */ - return git_tree_entry_dup(entry_out, entry); - } - - if (git_tree_lookup(&subtree, root->object.repo, &entry->oid) < 0) - return -1; - - error = git_tree_entry_bypath( - entry_out, - subtree, - path + filename_len + 1 - ); - - git_tree_free(subtree); - return error; -} - -static int tree_walk( - const git_tree *tree, - git_treewalk_cb callback, - git_str *path, - void *payload, - bool preorder) -{ - int error = 0; - size_t i; - const git_tree_entry *entry; - - git_array_foreach(tree->entries, i, entry) { - if (preorder) { - error = callback(path->ptr, entry, payload); - if (error < 0) { /* negative value stops iteration */ - git_error_set_after_callback_function(error, "git_tree_walk"); - break; - } - if (error > 0) { /* positive value skips this entry */ - error = 0; - continue; - } - } - - if (git_tree_entry__is_tree(entry)) { - git_tree *subtree; - size_t path_len = git_str_len(path); - - error = git_tree_lookup(&subtree, tree->object.repo, &entry->oid); - if (error < 0) - break; - - /* append the next entry to the path */ - git_str_puts(path, entry->filename); - git_str_putc(path, '/'); - - if (git_str_oom(path)) - error = -1; - else - error = tree_walk(subtree, callback, path, payload, preorder); - - git_tree_free(subtree); - if (error != 0) - break; - - git_str_truncate(path, path_len); - } - - if (!preorder) { - error = callback(path->ptr, entry, payload); - if (error < 0) { /* negative value stops iteration */ - git_error_set_after_callback_function(error, "git_tree_walk"); - break; - } - error = 0; - } - } - - return error; -} - -int git_tree_walk( - const git_tree *tree, - git_treewalk_mode mode, - git_treewalk_cb callback, - void *payload) -{ - int error = 0; - git_str root_path = GIT_STR_INIT; - - if (mode != GIT_TREEWALK_POST && mode != GIT_TREEWALK_PRE) { - git_error_set(GIT_ERROR_INVALID, "invalid walking mode for tree walk"); - return -1; - } - - error = tree_walk( - tree, callback, &root_path, payload, (mode == GIT_TREEWALK_PRE)); - - git_str_dispose(&root_path); - - return error; -} - -static int compare_entries(const void *_a, const void *_b) -{ - const git_tree_update *a = (git_tree_update *) _a; - const git_tree_update *b = (git_tree_update *) _b; - - return strcmp(a->path, b->path); -} - -static int on_dup_entry(void **old, void *new) -{ - GIT_UNUSED(old); GIT_UNUSED(new); - - git_error_set(GIT_ERROR_TREE, "duplicate entries given for update"); - return -1; -} - -/* - * We keep the previous tree and the new one at each level of the - * stack. When we leave a level we're done with that tree and we can - * write it out to the odb. - */ -typedef struct { - git_treebuilder *bld; - git_tree *tree; - char *name; -} tree_stack_entry; - -/** Count how many slashes (i.e. path components) there are in this string */ -GIT_INLINE(size_t) count_slashes(const char *path) -{ - size_t count = 0; - const char *slash; - - while ((slash = strchr(path, '/')) != NULL) { - count++; - path = slash + 1; - } - - return count; -} - -static bool next_component(git_str *out, const char *in) -{ - const char *slash = strchr(in, '/'); - - git_str_clear(out); - - if (slash) - git_str_put(out, in, slash - in); - - return !!slash; -} - -static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *popped, git_str *component) -{ - int error; - git_oid new_tree; - - git_tree_free(popped->tree); - - /* If the tree would be empty, remove it from the one higher up */ - if (git_treebuilder_entrycount(popped->bld) == 0) { - git_treebuilder_free(popped->bld); - error = git_treebuilder_remove(current->bld, popped->name); - git__free(popped->name); - return error; - } - - error = git_treebuilder_write(&new_tree, popped->bld); - git_treebuilder_free(popped->bld); - - if (error < 0) { - git__free(popped->name); - return error; - } - - /* We've written out the tree, now we have to put the new value into its parent */ - git_str_clear(component); - git_str_puts(component, popped->name); - git__free(popped->name); - - GIT_ERROR_CHECK_ALLOC(component->ptr); - - /* Error out if this would create a D/F conflict in this update */ - if (current->tree) { - const git_tree_entry *to_replace; - to_replace = git_tree_entry_byname(current->tree, component->ptr); - if (to_replace && git_tree_entry_type(to_replace) != GIT_OBJECT_TREE) { - git_error_set(GIT_ERROR_TREE, "D/F conflict when updating tree"); - return -1; - } - } - - return git_treebuilder_insert(NULL, current->bld, component->ptr, &new_tree, GIT_FILEMODE_TREE); -} - -int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseline, size_t nupdates, const git_tree_update *updates) -{ - git_array_t(tree_stack_entry) stack = GIT_ARRAY_INIT; - tree_stack_entry *root_elem; - git_vector entries; - int error; - size_t i; - git_str component = GIT_STR_INIT; - - if ((error = git_vector_init(&entries, nupdates, compare_entries)) < 0) - return error; - - /* Sort the entries for treversal */ - for (i = 0 ; i < nupdates; i++) { - if ((error = git_vector_insert_sorted(&entries, (void *) &updates[i], on_dup_entry)) < 0) - goto cleanup; - } - - root_elem = git_array_alloc(stack); - GIT_ERROR_CHECK_ALLOC(root_elem); - memset(root_elem, 0, sizeof(*root_elem)); - - if (baseline && (error = git_tree_dup(&root_elem->tree, baseline)) < 0) - goto cleanup; - - if ((error = git_treebuilder_new(&root_elem->bld, repo, root_elem->tree)) < 0) - goto cleanup; - - for (i = 0; i < nupdates; i++) { - const git_tree_update *last_update = i == 0 ? NULL : git_vector_get(&entries, i-1); - const git_tree_update *update = git_vector_get(&entries, i); - size_t common_prefix = 0, steps_up, j; - const char *path; - - /* Figure out how much we need to change from the previous tree */ - if (last_update) - common_prefix = git_fs_path_common_dirlen(last_update->path, update->path); - - /* - * The entries are sorted, so when we find we're no - * longer in the same directory, we need to abandon - * the old tree (steps up) and dive down to the next - * one. - */ - steps_up = last_update == NULL ? 0 : count_slashes(&last_update->path[common_prefix]); - - for (j = 0; j < steps_up; j++) { - tree_stack_entry *current, *popped = git_array_pop(stack); - GIT_ASSERT(popped); - - current = git_array_last(stack); - GIT_ASSERT(current); - - if ((error = create_popped_tree(current, popped, &component)) < 0) - goto cleanup; - } - - /* Now that we've created the trees we popped from the stack, let's go back down */ - path = &update->path[common_prefix]; - while (next_component(&component, path)) { - tree_stack_entry *last, *new_entry; - const git_tree_entry *entry; - - last = git_array_last(stack); - entry = last->tree ? git_tree_entry_byname(last->tree, component.ptr) : NULL; - if (!entry) - entry = treebuilder_get(last->bld, component.ptr); - - if (entry && git_tree_entry_type(entry) != GIT_OBJECT_TREE) { - git_error_set(GIT_ERROR_TREE, "D/F conflict when updating tree"); - error = -1; - goto cleanup; - } - - new_entry = git_array_alloc(stack); - GIT_ERROR_CHECK_ALLOC(new_entry); - memset(new_entry, 0, sizeof(*new_entry)); - - new_entry->tree = NULL; - if (entry && (error = git_tree_lookup(&new_entry->tree, repo, git_tree_entry_id(entry))) < 0) - goto cleanup; - - if ((error = git_treebuilder_new(&new_entry->bld, repo, new_entry->tree)) < 0) - goto cleanup; - - new_entry->name = git__strdup(component.ptr); - GIT_ERROR_CHECK_ALLOC(new_entry->name); - - /* Get to the start of the next component */ - path += component.size + 1; - } - - /* After all that, we're finally at the place where we want to perform the update */ - switch (update->action) { - case GIT_TREE_UPDATE_UPSERT: - { - /* Make sure we're replacing something of the same type */ - tree_stack_entry *last = git_array_last(stack); - char *basename = git_fs_path_basename(update->path); - const git_tree_entry *e = git_treebuilder_get(last->bld, basename); - if (e && git_tree_entry_type(e) != git_object__type_from_filemode(update->filemode)) { - git__free(basename); - git_error_set(GIT_ERROR_TREE, "cannot replace '%s' with '%s' at '%s'", - git_object_type2string(git_tree_entry_type(e)), - git_object_type2string(git_object__type_from_filemode(update->filemode)), - update->path); - error = -1; - goto cleanup; - } - - error = git_treebuilder_insert(NULL, last->bld, basename, &update->id, update->filemode); - git__free(basename); - break; - } - case GIT_TREE_UPDATE_REMOVE: - { - tree_stack_entry *last = git_array_last(stack); - char *basename = git_fs_path_basename(update->path); - error = git_treebuilder_remove(last->bld, basename); - git__free(basename); - break; - } - default: - git_error_set(GIT_ERROR_TREE, "unknown action for update"); - error = -1; - goto cleanup; - } - - if (error < 0) - goto cleanup; - } - - /* We're done, go up the stack again and write out the tree */ - { - tree_stack_entry *current = NULL, *popped = NULL; - while ((popped = git_array_pop(stack)) != NULL) { - current = git_array_last(stack); - /* We've reached the top, current is the root tree */ - if (!current) - break; - - if ((error = create_popped_tree(current, popped, &component)) < 0) - goto cleanup; - } - - /* Write out the root tree */ - git__free(popped->name); - git_tree_free(popped->tree); - - error = git_treebuilder_write(out, popped->bld); - git_treebuilder_free(popped->bld); - if (error < 0) - goto cleanup; - } - -cleanup: - { - tree_stack_entry *e; - while ((e = git_array_pop(stack)) != NULL) { - git_treebuilder_free(e->bld); - git_tree_free(e->tree); - git__free(e->name); - } - } - - git_str_dispose(&component); - git_array_clear(stack); - git_vector_dispose(&entries); - return error; -} - -/* Deprecated Functions */ - -#ifndef GIT_DEPRECATE_HARD - -int git_treebuilder_write_with_buffer(git_oid *oid, git_treebuilder *bld, git_buf *buf) -{ - GIT_UNUSED(buf); - - return git_treebuilder_write(oid, bld); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/tree.h b/vendor/libgit2-sys/libgit2/src/libgit2/tree.h deleted file mode 100644 index 8deec60..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/tree.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_tree_h__ -#define INCLUDE_tree_h__ - -#include "common.h" - -#include "git2/tree.h" -#include "repository.h" -#include "odb.h" -#include "vector.h" -#include "pool.h" - -struct git_tree_entry { - uint16_t attr; - uint16_t filename_len; - git_oid oid; - const char *filename; -}; - -struct git_tree { - git_object object; - git_odb_object *odb_obj; - git_array_t(git_tree_entry) entries; -}; - -GIT_HASHMAP_STR_STRUCT(git_treebuilder_entrymap, git_tree_entry *); - -struct git_treebuilder { - git_repository *repo; - git_treebuilder_entrymap map; - git_str write_cache; -}; - -GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e) -{ - return (S_ISDIR(e->attr) && !S_ISGITLINK(e->attr)); -} - -void git_tree__free(void *tree); -int git_tree__parse(void *tree, git_odb_object *obj, git_oid_t oid_type); -int git_tree__parse_raw(void *_tree, const char *data, size_t size, git_oid_t oid_type); - -/** - * Write a tree to the given repository - */ -int git_tree__write_index( - git_oid *oid, git_index *index, git_repository *repo); - -/** - * Obsolete mode kept for compatibility reasons - */ -#define GIT_FILEMODE_BLOB_GROUP_WRITABLE 0100664 - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/userdiff.h b/vendor/libgit2-sys/libgit2/src/libgit2/userdiff.h deleted file mode 100644 index c9a80d7..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/userdiff.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_userdiff_h__ -#define INCLUDE_userdiff_h__ - -#include "regexp.h" - -/* - * This file isolates the built in diff driver function name patterns. - * Most of these patterns are taken from Git (with permission from the - * original authors for relicensing to libgit2). - */ - -typedef struct { - const char *name; - const char *fns; - const char *words; - int flags; -} git_diff_driver_definition; - -#define WORD_DEFAULT "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" - -/* - * These builtin driver definition macros have same signature as in core - * git userdiff.c so that the data can be extracted verbatim - */ -#define PATTERNS(NAME, FN_PATS, WORD_PAT) \ - { NAME, FN_PATS, WORD_PAT WORD_DEFAULT, 0 } -#define IPATTERN(NAME, FN_PATS, WORD_PAT) \ - { NAME, FN_PATS, WORD_PAT WORD_DEFAULT, GIT_REGEXP_ICASE } - -/* - * The table of diff driver patterns - * - * Function name patterns are a list of newline separated patterns that - * match a function declaration (i.e. the line you want in the hunk header), - * or a negative pattern prefixed with a '!' to reject a pattern (such as - * rejecting goto labels in C code). - * - * Word boundary patterns are just a simple pattern that will be OR'ed with - * the default value above (i.e. whitespace or non-ASCII characters). - */ -static git_diff_driver_definition builtin_defs[] = { - -IPATTERN("ada", - "!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n" - "!^[ \t]*with[ \t].*$\n" - "^[ \t]*((procedure|function)[ \t]+.*)$\n" - "^[ \t]*((package|protected|task)[ \t]+.*)$", - /* -- */ - "[a-zA-Z][a-zA-Z0-9_]*" - "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?" - "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"), - -IPATTERN("fortran", - "!^([C*]|[ \t]*!)\n" - "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n" - "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA" - "|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$", - /* -- */ - "[a-zA-Z][a-zA-Z0-9_]*" - "|\\.([Ee][Qq]|[Nn][Ee]|[Gg][TtEe]|[Ll][TtEe]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Aa][Nn][Dd]|[Oo][Rr]|[Nn]?[Ee][Qq][Vv]|[Nn][Oo][Tt])\\." - /* numbers and format statements like 2E14.4, or ES12.6, 9X. - * Don't worry about format statements without leading digits since - * they would have been matched above as a variable anyway. */ - "|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?" - "|//|\\*\\*|::|[/<>=]="), - -PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$", - "[^<>= \t]+"), - -PATTERNS("java", - "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n" - "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$", - /* -- */ - "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" - "|[-+*/<>%&^|=!]=" - "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), - -PATTERNS("matlab", - "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$", - "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"), - -PATTERNS("objc", - /* Negate C statements that can look like functions */ - "!^[ \t]*(do|for|if|else|return|switch|while)\n" - /* Objective-C methods */ - "^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_].*)$\n" - /* C functions */ - "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$\n" - /* Objective-C class/protocol definitions */ - "^(@(implementation|interface|protocol)[ \t].*)$", - /* -- */ - "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" - "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), - -PATTERNS("pascal", - "^(((class[ \t]+)?(procedure|function)|constructor|destructor|interface|" - "implementation|initialization|finalization)[ \t]*.*)$" - "\n" - "^(.*=[ \t]*(class|record).*)$", - /* -- */ - "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+" - "|<>|<=|>=|:=|\\.\\."), - -PATTERNS("perl", - "^package .*\n" - "^sub [[:alnum:]_':]+[ \t]*" - "(\\([^)]*\\)[ \t]*)?" /* prototype */ - /* - * Attributes. A regex can't count nested parentheses, - * so just slurp up whatever we see, taking care not - * to accept lines like "sub foo; # defined elsewhere". - * - * An attribute could contain a semicolon, but at that - * point it seems reasonable enough to give up. - */ - "(:[^;#]*)?" - "(\\{[ \t]*)?" /* brace can come here or on the next line */ - "(#.*)?$\n" /* comment */ - "^(BEGIN|END|INIT|CHECK|UNITCHECK|AUTOLOAD|DESTROY)[ \t]*" - "(\\{[ \t]*)?" /* brace can come here or on the next line */ - "(#.*)?$\n" - "^=head[0-9] .*", /* POD */ - /* -- */ - "[[:alpha:]_'][[:alnum:]_']*" - "|0[xb]?[0-9a-fA-F_]*" - /* taking care not to interpret 3..5 as (3.)(.5) */ - "|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?" - "|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::" - "|&&=|\\|\\|=|//=|\\*\\*=" - "|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?" - "|[-+*/%.^&<>=!|]=" - "|=~|!~" - "|<<|<>|<=>|>>"), - -PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$", - /* -- */ - "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?" - "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"), - -PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$", - /* -- */ - "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?." - "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"), - -PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$", - "[={}\"]|[^={}\" \t]+"), - -PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$", - "\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+"), - -PATTERNS("cpp", - /* Jump targets or access declarations */ - "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])\n" - /* functions/methods, variables, and compounds at top level */ - "^((::[[:space:]]*)?[A-Za-z_].*)$", - /* -- */ - "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lLuU]*" - "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->\\*?|\\.\\*"), - -PATTERNS("csharp", - /* Keywords */ - "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n" - /* Methods and constructors */ - "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n" - /* Properties */ - "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n" - /* Type definitions */ - "^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct)[ \t]+.*)$\n" - /* Namespace */ - "^[ \t]*(namespace[ \t]+.*)$", - /* -- */ - "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" - "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), - -PATTERNS("php", - "^[ \t]*(((public|private|protected|static|final)[ \t]+)*((class|function)[ \t].*))$", - /* -- */ - "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?" - "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), - -PATTERNS("javascript", - "([a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z0-9_$]+)*[ \t]*=[ \t]*function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)\n" - "([a-zA-Z_$][a-zA-Z0-9_$]*[ \t]*:[ \t]*function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)\n" - "[^a-zA-Z0-9_\\$](function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)", - /* -- */ - "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?" - "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), -}; - -#undef IPATTERN -#undef PATTERNS -#undef WORD_DEFAULT - -#endif - diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/worktree.c b/vendor/libgit2-sys/libgit2/src/libgit2/worktree.c deleted file mode 100644 index 00ff9e7..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/worktree.c +++ /dev/null @@ -1,669 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "worktree.h" - -#include "buf.h" -#include "repository.h" -#include "path.h" - -#include "git2/branch.h" -#include "git2/commit.h" -#include "git2/worktree.h" - -static bool is_worktree_dir(const char *dir) -{ - git_str buf = GIT_STR_INIT; - int error; - - if (git_str_sets(&buf, dir) < 0) - return -1; - - error = git_fs_path_contains_file(&buf, "commondir") - && git_fs_path_contains_file(&buf, "gitdir") - && git_fs_path_contains_file(&buf, "HEAD"); - - git_str_dispose(&buf); - return error; -} - -int git_worktree_list(git_strarray *wts, git_repository *repo) -{ - git_vector worktrees = GIT_VECTOR_INIT; - git_str path = GIT_STR_INIT; - char *worktree; - size_t i, len; - int error; - - GIT_ASSERT_ARG(wts); - GIT_ASSERT_ARG(repo); - - wts->count = 0; - wts->strings = NULL; - - if ((error = git_str_joinpath(&path, repo->commondir, "worktrees/")) < 0) - goto exit; - if (!git_fs_path_exists(path.ptr) || git_fs_path_is_empty_dir(path.ptr)) - goto exit; - if ((error = git_fs_path_dirload(&worktrees, path.ptr, path.size, 0x0)) < 0) - goto exit; - - len = path.size; - - git_vector_foreach(&worktrees, i, worktree) { - git_str_truncate(&path, len); - git_str_puts(&path, worktree); - - if (!is_worktree_dir(path.ptr)) { - git_vector_remove(&worktrees, i); - git__free(worktree); - } - } - - wts->strings = (char **)git_vector_detach(&wts->count, NULL, &worktrees); - -exit: - git_str_dispose(&path); - - return error; -} - -char *git_worktree__read_link(const char *base, const char *file) -{ - git_str path = GIT_STR_INIT, buf = GIT_STR_INIT; - - GIT_ASSERT_ARG_WITH_RETVAL(base, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(file, NULL); - - if (git_str_joinpath(&path, base, file) < 0) - goto err; - if (git_futils_readbuffer(&buf, path.ptr) < 0) - goto err; - git_str_dispose(&path); - - git_str_rtrim(&buf); - - if (!git_fs_path_is_relative(buf.ptr)) - return git_str_detach(&buf); - - if (git_str_sets(&path, base) < 0) - goto err; - if (git_fs_path_apply_relative(&path, buf.ptr) < 0) - goto err; - git_str_dispose(&buf); - - return git_str_detach(&path); - -err: - git_str_dispose(&buf); - git_str_dispose(&path); - - return NULL; -} - -static int write_wtfile(const char *base, const char *file, const git_str *buf) -{ - git_str path = GIT_STR_INIT; - int err; - - GIT_ASSERT_ARG(base); - GIT_ASSERT_ARG(file); - GIT_ASSERT_ARG(buf); - - if ((err = git_str_joinpath(&path, base, file)) < 0) - goto out; - - if ((err = git_futils_writebuffer(buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0) - goto out; - -out: - git_str_dispose(&path); - - return err; -} - -static int open_worktree_dir(git_worktree **out, const char *parent, const char *dir, const char *name) -{ - git_str gitdir = GIT_STR_INIT; - git_worktree *wt = NULL; - int error = 0; - - if (!is_worktree_dir(dir)) { - error = -1; - goto out; - } - - if ((error = git_path_validate_length(NULL, dir)) < 0) - goto out; - - if ((wt = git__calloc(1, sizeof(*wt))) == NULL) { - error = -1; - goto out; - } - - if ((wt->name = git__strdup(name)) == NULL || - (wt->commondir_path = git_worktree__read_link(dir, "commondir")) == NULL || - (wt->gitlink_path = git_worktree__read_link(dir, "gitdir")) == NULL || - (parent && (wt->parent_path = git__strdup(parent)) == NULL) || - (wt->worktree_path = git_fs_path_dirname(wt->gitlink_path)) == NULL) { - error = -1; - goto out; - } - - if ((error = git_fs_path_prettify_dir(&gitdir, dir, NULL)) < 0) - goto out; - wt->gitdir_path = git_str_detach(&gitdir); - - if ((error = git_worktree_is_locked(NULL, wt)) < 0) - goto out; - wt->locked = !!error; - error = 0; - - *out = wt; - -out: - if (error) - git_worktree_free(wt); - git_str_dispose(&gitdir); - - return error; -} - -int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *name) -{ - git_str path = GIT_STR_INIT; - git_worktree *wt = NULL; - int error; - - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - - *out = NULL; - - if ((error = git_str_join3(&path, '/', repo->commondir, "worktrees", name)) < 0) - goto out; - - if (!git_fs_path_isdir(path.ptr)) { - error = GIT_ENOTFOUND; - goto out; - } - - if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0) - goto out; - -out: - git_str_dispose(&path); - - if (error) - git_worktree_free(wt); - - return error; -} - -int git_worktree_open_from_repository(git_worktree **out, git_repository *repo) -{ - git_str parent = GIT_STR_INIT; - const char *gitdir, *commondir; - char *name = NULL; - int error = 0; - - if (!git_repository_is_worktree(repo)) { - git_error_set(GIT_ERROR_WORKTREE, "cannot open worktree of a non-worktree repo"); - error = -1; - goto out; - } - - gitdir = git_repository_path(repo); - commondir = git_repository_commondir(repo); - - if ((error = git_fs_path_prettify_dir(&parent, "..", commondir)) < 0) - goto out; - - /* The name is defined by the last component in '.git/worktree/%s' */ - name = git_fs_path_basename(gitdir); - - if ((error = open_worktree_dir(out, parent.ptr, gitdir, name)) < 0) - goto out; - -out: - git__free(name); - git_str_dispose(&parent); - - return error; -} - -void git_worktree_free(git_worktree *wt) -{ - if (!wt) - return; - - git__free(wt->commondir_path); - git__free(wt->worktree_path); - git__free(wt->gitlink_path); - git__free(wt->gitdir_path); - git__free(wt->parent_path); - git__free(wt->name); - git__free(wt); -} - -int git_worktree_validate(const git_worktree *wt) -{ - GIT_ASSERT_ARG(wt); - - if (!is_worktree_dir(wt->gitdir_path)) { - git_error_set(GIT_ERROR_WORKTREE, - "worktree gitdir ('%s') is not valid", - wt->gitlink_path); - return GIT_ERROR; - } - - if (wt->parent_path && !git_fs_path_exists(wt->parent_path)) { - git_error_set(GIT_ERROR_WORKTREE, - "worktree parent directory ('%s') does not exist ", - wt->parent_path); - return GIT_ERROR; - } - - if (!git_fs_path_exists(wt->commondir_path)) { - git_error_set(GIT_ERROR_WORKTREE, - "worktree common directory ('%s') does not exist ", - wt->commondir_path); - return GIT_ERROR; - } - - if (!git_fs_path_exists(wt->worktree_path)) { - git_error_set(GIT_ERROR_WORKTREE, - "worktree directory '%s' does not exist", - wt->worktree_path); - return GIT_ERROR; - } - - return 0; -} - -int git_worktree_add_options_init(git_worktree_add_options *opts, - unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version, - git_worktree_add_options, GIT_WORKTREE_ADD_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_worktree_add_init_options(git_worktree_add_options *opts, - unsigned int version) -{ - return git_worktree_add_options_init(opts, version); -} -#endif - -int git_worktree_add(git_worktree **out, git_repository *repo, - const char *name, const char *worktree, - const git_worktree_add_options *opts) -{ - git_str gitdir = GIT_STR_INIT, wddir = GIT_STR_INIT, buf = GIT_STR_INIT; - git_reference *ref = NULL, *head = NULL; - git_commit *commit = NULL; - git_repository *wt = NULL; - git_checkout_options coopts; - git_worktree_add_options wtopts = GIT_WORKTREE_ADD_OPTIONS_INIT; - int err; - - GIT_ERROR_CHECK_VERSION( - opts, GIT_WORKTREE_ADD_OPTIONS_VERSION, "git_worktree_add_options"); - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(name); - GIT_ASSERT_ARG(worktree); - - *out = NULL; - - if (opts) - memcpy(&wtopts, opts, sizeof(wtopts)); - - memcpy(&coopts, &wtopts.checkout_options, sizeof(coopts)); - - if (wtopts.ref) { - if (!git_reference_is_branch(wtopts.ref)) { - git_error_set(GIT_ERROR_WORKTREE, "reference is not a branch"); - err = -1; - goto out; - } - - if ((err = git_reference_dup(&ref, wtopts.ref)) < 0) - goto out; - } else if (wtopts.checkout_existing && git_branch_lookup(&ref, repo, name, GIT_BRANCH_LOCAL) == 0) { - /* Do nothing */ - } else if ((err = git_repository_head(&head, repo)) < 0 || - (err = git_commit_lookup(&commit, repo, &head->target.oid)) < 0 || - (err = git_branch_create(&ref, repo, name, commit, false)) < 0) { - goto out; - } - - if (git_branch_is_checked_out(ref)) { - git_error_set(GIT_ERROR_WORKTREE, "reference %s is already checked out", - git_reference_name(ref)); - err = -1; - goto out; - } - - /* Create gitdir directory ".git/worktrees/" */ - if ((err = git_str_joinpath(&gitdir, repo->commondir, "worktrees")) < 0) - goto out; - if (!git_fs_path_exists(gitdir.ptr)) - if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0) - goto out; - if ((err = git_str_joinpath(&gitdir, gitdir.ptr, name)) < 0) - goto out; - if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0) - goto out; - if ((err = git_fs_path_prettify_dir(&gitdir, gitdir.ptr, NULL)) < 0) - goto out; - - /* Create worktree work dir */ - if ((err = git_futils_mkdir(worktree, 0755, GIT_MKDIR_EXCL)) < 0) - goto out; - if ((err = git_fs_path_prettify_dir(&wddir, worktree, NULL)) < 0) - goto out; - - if (wtopts.lock) { - int fd; - - if ((err = git_str_joinpath(&buf, gitdir.ptr, "locked")) < 0) - goto out; - - if ((fd = p_creat(buf.ptr, 0644)) < 0) { - err = fd; - goto out; - } - - p_close(fd); - git_str_clear(&buf); - } - - /* Create worktree .git file */ - if ((err = git_str_printf(&buf, "gitdir: %s\n", gitdir.ptr)) < 0) - goto out; - if ((err = write_wtfile(wddir.ptr, ".git", &buf)) < 0) - goto out; - - /* Create gitdir files */ - if ((err = git_fs_path_prettify_dir(&buf, repo->commondir, NULL) < 0) - || (err = git_str_putc(&buf, '\n')) < 0 - || (err = write_wtfile(gitdir.ptr, "commondir", &buf)) < 0) - goto out; - if ((err = git_str_joinpath(&buf, wddir.ptr, ".git")) < 0 - || (err = git_str_putc(&buf, '\n')) < 0 - || (err = write_wtfile(gitdir.ptr, "gitdir", &buf)) < 0) - goto out; - - /* Set worktree's HEAD */ - if ((err = git_repository_create_head(gitdir.ptr, git_reference_name(ref))) < 0) - goto out; - if ((err = git_repository_open(&wt, wddir.ptr)) < 0) - goto out; - - /* Checkout worktree's HEAD */ - if ((err = git_checkout_head(wt, &coopts)) < 0) - goto out; - - /* Load result */ - if ((err = git_worktree_lookup(out, repo, name)) < 0) - goto out; - -out: - git_str_dispose(&gitdir); - git_str_dispose(&wddir); - git_str_dispose(&buf); - git_reference_free(ref); - git_reference_free(head); - git_commit_free(commit); - git_repository_free(wt); - - return err; -} - -int git_worktree_lock(git_worktree *wt, const char *reason) -{ - git_str buf = GIT_STR_INIT, path = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(wt); - - if ((error = git_worktree_is_locked(NULL, wt)) < 0) - goto out; - if (error) { - error = GIT_ELOCKED; - goto out; - } - - if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0) - goto out; - - if (reason) - git_str_attach_notowned(&buf, reason, strlen(reason)); - - if ((error = git_futils_writebuffer(&buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0) - goto out; - - wt->locked = 1; - -out: - git_str_dispose(&path); - - return error; -} - -int git_worktree_unlock(git_worktree *wt) -{ - git_str path = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(wt); - - if ((error = git_worktree_is_locked(NULL, wt)) < 0) - return error; - if (!error) - return 1; - - if (git_str_joinpath(&path, wt->gitdir_path, "locked") < 0) - return -1; - - if (p_unlink(path.ptr) != 0) { - git_str_dispose(&path); - return -1; - } - - wt->locked = 0; - - git_str_dispose(&path); - - return 0; -} - -static int git_worktree__is_locked(git_str *reason, const git_worktree *wt) -{ - git_str path = GIT_STR_INIT; - int error, locked; - - GIT_ASSERT_ARG(wt); - - if (reason) - git_str_clear(reason); - - if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0) - goto out; - locked = git_fs_path_exists(path.ptr); - if (locked && reason && - (error = git_futils_readbuffer(reason, path.ptr)) < 0) - goto out; - - error = locked; -out: - git_str_dispose(&path); - - return error; -} - -int git_worktree_is_locked(git_buf *reason, const git_worktree *wt) -{ - git_str str = GIT_STR_INIT; - int error = 0; - - if (reason && (error = git_buf_tostr(&str, reason)) < 0) - return error; - - error = git_worktree__is_locked(reason ? &str : NULL, wt); - - if (error >= 0 && reason) { - if (git_buf_fromstr(reason, &str) < 0) - error = -1; - } - - git_str_dispose(&str); - return error; -} - -const char *git_worktree_name(const git_worktree *wt) -{ - GIT_ASSERT_ARG_WITH_RETVAL(wt, NULL); - return wt->name; -} - -const char *git_worktree_path(const git_worktree *wt) -{ - GIT_ASSERT_ARG_WITH_RETVAL(wt, NULL); - return wt->worktree_path; -} - -int git_worktree_prune_options_init( - git_worktree_prune_options *opts, - unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version, - git_worktree_prune_options, GIT_WORKTREE_PRUNE_OPTIONS_INIT); - return 0; -} - -#ifndef GIT_DEPRECATE_HARD -int git_worktree_prune_init_options(git_worktree_prune_options *opts, - unsigned int version) -{ - return git_worktree_prune_options_init(opts, version); -} -#endif - -int git_worktree_is_prunable(git_worktree *wt, - git_worktree_prune_options *opts) -{ - git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; - git_str path = GIT_STR_INIT; - int ret = 0; - - GIT_ERROR_CHECK_VERSION( - opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION, - "git_worktree_prune_options"); - - if (opts) - memcpy(&popts, opts, sizeof(popts)); - - if ((popts.flags & GIT_WORKTREE_PRUNE_LOCKED) == 0) { - git_str reason = GIT_STR_INIT; - - if ((ret = git_worktree__is_locked(&reason, wt)) < 0) - goto out; - - if (ret) { - git_error_set(GIT_ERROR_WORKTREE, - "not pruning locked working tree: '%s'", - reason.size ? reason.ptr : "is locked"); - - git_str_dispose(&reason); - ret = 0; - goto out; - } - } - - if ((popts.flags & GIT_WORKTREE_PRUNE_VALID) == 0 && - git_worktree_validate(wt) == 0) { - git_error_set(GIT_ERROR_WORKTREE, "not pruning valid working tree"); - goto out; - } - - if ((ret = git_str_printf(&path, "%s/worktrees/%s", wt->commondir_path, wt->name) < 0)) - goto out; - - if (!git_fs_path_exists(path.ptr)) { - git_error_set(GIT_ERROR_WORKTREE, "worktree gitdir ('%s') does not exist", path.ptr); - goto out; - } - - ret = 1; - -out: - git_str_dispose(&path); - return ret; -} - -int git_worktree_prune(git_worktree *wt, - git_worktree_prune_options *opts) -{ - git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; - git_str path = GIT_STR_INIT; - char *wtpath; - int err; - - GIT_ERROR_CHECK_VERSION( - opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION, - "git_worktree_prune_options"); - - if (opts) - memcpy(&popts, opts, sizeof(popts)); - - if (!git_worktree_is_prunable(wt, &popts)) { - err = -1; - goto out; - } - - /* Delete gitdir in parent repository */ - if ((err = git_str_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0) - goto out; - if (!git_fs_path_exists(path.ptr)) - { - git_error_set(GIT_ERROR_WORKTREE, "worktree gitdir '%s' does not exist", path.ptr); - err = -1; - goto out; - } - if ((err = git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES)) < 0) - goto out; - - /* Skip deletion of the actual working tree if it does - * not exist or deletion was not requested */ - if ((popts.flags & GIT_WORKTREE_PRUNE_WORKING_TREE) == 0 || - !git_fs_path_exists(wt->gitlink_path)) - { - goto out; - } - - if ((wtpath = git_fs_path_dirname(wt->gitlink_path)) == NULL) - goto out; - git_str_attach(&path, wtpath, 0); - if (!git_fs_path_exists(path.ptr)) - { - git_error_set(GIT_ERROR_WORKTREE, "working tree '%s' does not exist", path.ptr); - err = -1; - goto out; - } - if ((err = git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES)) < 0) - goto out; - -out: - git_str_dispose(&path); - - return err; -} diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/worktree.h b/vendor/libgit2-sys/libgit2/src/libgit2/worktree.h deleted file mode 100644 index 587189f..0000000 --- a/vendor/libgit2-sys/libgit2/src/libgit2/worktree.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_worktree_h__ -#define INCLUDE_worktree_h__ - -#include "common.h" - -#include "git2/common.h" -#include "git2/worktree.h" - -struct git_worktree { - /* Name of the working tree. This is the name of the - * containing directory in the `$PARENT/.git/worktrees/` - * directory. */ - char *name; - - /* Path to the where the worktree lives in the filesystem */ - char *worktree_path; - /* Path to the .git file in the working tree's repository */ - char *gitlink_path; - /* Path to the .git directory inside the parent's - * worktrees directory */ - char *gitdir_path; - /* Path to the common directory contained in the parent - * repository */ - char *commondir_path; - /* Path to the parent's working directory */ - char *parent_path; - - unsigned int locked:1; -}; - -char *git_worktree__read_link(const char *base, const char *file); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/CMakeLists.txt b/vendor/libgit2-sys/libgit2/src/util/CMakeLists.txt deleted file mode 100644 index 062e0c6..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/CMakeLists.txt +++ /dev/null @@ -1,76 +0,0 @@ -# util: a shared library for common utility functions for libgit2 projects - -add_library(util OBJECT) - -configure_file(git2_features.h.in "${PROJECT_BINARY_DIR}/gen_headers/git2_features.h") - -set(UTIL_INCLUDES - "${PROJECT_SOURCE_DIR}/src/util" - "${PROJECT_SOURCE_DIR}/include" - "${PROJECT_BINARY_DIR}/gen_headers") - -file(GLOB UTIL_SRC *.c *.h allocators/*.c allocators/*.h hash.h) -list(SORT UTIL_SRC) - -# -# Platform specific sources -# - -if(WIN32 AND NOT CYGWIN) - file(GLOB UTIL_SRC_OS win32/*.c win32/*.h) - list(SORT UTIL_SRC_OS) -elseif(NOT AMIGA) - file(GLOB UTIL_SRC_OS unix/*.c unix/*.h) - list(SORT UTIL_SRC_OS) -endif() - -# -# Hash backend selection -# - -if(USE_SHA1 STREQUAL "CollisionDetection") - file(GLOB UTIL_SRC_SHA1 hash/collisiondetect.* hash/sha1dc/*) - target_compile_definitions(util PRIVATE SHA1DC_NO_STANDARD_INCLUDES=1) - target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_SHA1_C=\"git2_util.h\") - target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"git2_util.h\") -elseif(USE_SHA1 STREQUAL "OpenSSL" OR USE_SHA1 STREQUAL "OpenSSL-Dynamic" OR USE_SHA1 STREQUAL "OpenSSL-FIPS") - add_definitions(-DOPENSSL_API_COMPAT=0x10100000L) - file(GLOB UTIL_SRC_SHA1 hash/openssl.*) -elseif(USE_SHA1 STREQUAL "CommonCrypto") - file(GLOB UTIL_SRC_SHA1 hash/common_crypto.*) -elseif(USE_SHA1 STREQUAL "mbedTLS") - file(GLOB UTIL_SRC_SHA1 hash/mbedtls.*) -elseif(USE_SHA1 STREQUAL "Win32") - file(GLOB UTIL_SRC_SHA1 hash/win32.*) -else() - message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}") -endif() - -list(SORT UTIL_SRC_SHA1) - -if(USE_SHA256 STREQUAL "builtin") - file(GLOB UTIL_SRC_SHA256 hash/builtin.* hash/rfc6234/*) -elseif(USE_SHA256 STREQUAL "OpenSSL" OR USE_SHA256 STREQUAL "OpenSSL-Dynamic" OR USE_SHA256 STREQUAL "OpenSSL-FIPS") - add_definitions(-DOPENSSL_API_COMPAT=0x10100000L) - file(GLOB UTIL_SRC_SHA256 hash/openssl.*) -elseif(USE_SHA256 STREQUAL "CommonCrypto") - file(GLOB UTIL_SRC_SHA256 hash/common_crypto.*) -elseif(USE_SHA256 STREQUAL "mbedTLS") - file(GLOB UTIL_SRC_SHA256 hash/mbedtls.*) -elseif(USE_SHA256 STREQUAL "Win32") - file(GLOB UTIL_SRC_SHA256 hash/win32.*) -else() - message(FATAL_ERROR "asked for unknown SHA256 backend: ${USE_SHA256}") -endif() - -list(SORT UTIL_SRC_SHA256) - -# -# Build the library -# - -target_sources(util PRIVATE ${UTIL_SRC} ${UTIL_SRC_OS} ${UTIL_SRC_SHA1} ${UTIL_SRC_SHA256}) -ide_split_sources(util) - -target_include_directories(util PRIVATE ${UTIL_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include) -target_include_directories(util SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) diff --git a/vendor/libgit2-sys/libgit2/src/util/alloc.c b/vendor/libgit2-sys/libgit2/src/util/alloc.c deleted file mode 100644 index 998b0ae..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/alloc.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "alloc.h" -#include "runtime.h" - -#include "allocators/stdalloc.h" -#include "allocators/debugalloc.h" -#include "allocators/failalloc.h" -#include "allocators/win32_leakcheck.h" - -/* Fail any allocation until git_libgit2_init is called. */ -git_allocator git__allocator = { - git_failalloc_malloc, - git_failalloc_realloc, - git_failalloc_free -}; - -void *git__calloc(size_t nelem, size_t elsize) -{ - size_t newsize; - void *ptr; - - if (GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize)) - return NULL; - - if ((ptr = git__malloc(newsize))) - memset(ptr, 0, newsize); - - return ptr; -} - -void *git__reallocarray(void *ptr, size_t nelem, size_t elsize) -{ - size_t newsize; - - if (GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize)) - return NULL; - - return git__realloc(ptr, newsize); -} - -void *git__mallocarray(size_t nelem, size_t elsize) -{ - return git__reallocarray(NULL, nelem, elsize); -} - -char *git__strdup(const char *str) -{ - size_t len = strlen(str) + 1; - void *ptr = git__malloc(len); - - if (ptr) - memcpy(ptr, str, len); - - return ptr; -} - -char *git__strndup(const char *str, size_t n) -{ - size_t len = p_strnlen(str, n); - char *ptr = git__malloc(len + 1); - - if (ptr) { - memcpy(ptr, str, len); - ptr[len] = '\0'; - } - - return ptr; -} - -char *git__substrdup(const char *str, size_t n) -{ - char *ptr = git__malloc(n + 1); - - if (ptr) { - memcpy(ptr, str, n); - ptr[n] = '\0'; - } - - return ptr; -} - -static int setup_default_allocator(void) -{ -#if defined(GIT_WIN32_LEAKCHECK) - return git_win32_leakcheck_init_allocator(&git__allocator); -#elif defined(GIT_DEBUG_STRICT_ALLOC) - return git_debugalloc_init_allocator(&git__allocator); -#else - return git_stdalloc_init_allocator(&git__allocator); -#endif -} - -int git_allocator_global_init(void) -{ - /* - * We don't want to overwrite any allocator which has been set - * before the init function is called. - */ - if (git__allocator.gmalloc != git_failalloc_malloc) - return 0; - - return setup_default_allocator(); -} - -int git_allocator_setup(git_allocator *allocator) -{ - if (!allocator) - return setup_default_allocator(); - - memcpy(&git__allocator, allocator, sizeof(*allocator)); - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/alloc.h b/vendor/libgit2-sys/libgit2/src/util/alloc.h deleted file mode 100644 index 32b614b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/alloc.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_alloc_h__ -#define INCLUDE_alloc_h__ - -#include "git2/sys/alloc.h" - -#include "git2_util.h" - -extern git_allocator git__allocator; - -GIT_INLINE(void *) git__malloc(size_t len) -{ - void *p = git__allocator.gmalloc(len, __FILE__, __LINE__); - - if (!p) - git_error_set_oom(); - - return p; -} - -GIT_INLINE(void *) git__realloc(void *ptr, size_t size) -{ - void *p = git__allocator.grealloc(ptr, size, __FILE__, __LINE__); - - if (!p) - git_error_set_oom(); - - return p; -} - -GIT_INLINE(void) git__free(void *ptr) -{ - git__allocator.gfree(ptr); -} - -extern void *git__calloc(size_t nelem, size_t elsize); -extern void *git__mallocarray(size_t nelem, size_t elsize); -extern void *git__reallocarray(void *ptr, size_t nelem, size_t elsize); - -extern char *git__strdup(const char *str); -extern char *git__strndup(const char *str, size_t n); -extern char *git__substrdup(const char *str, size_t n); - -/** - * This function is being called by our global setup routines to - * initialize the standard allocator. - */ -int git_allocator_global_init(void); - -/** - * Switch out libgit2's global memory allocator - * - * @param allocator The new allocator that should be used. All function pointers - * of it need to be set correctly. - * @return An error code or 0. - */ -int git_allocator_setup(git_allocator *allocator); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/allocators/debugalloc.c b/vendor/libgit2-sys/libgit2/src/util/allocators/debugalloc.c deleted file mode 100644 index 44022cd..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/allocators/debugalloc.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "debugalloc.h" - -static void *debugalloc__malloc(size_t len, const char *file, int line) -{ - unsigned char *ptr; - size_t total = len + sizeof(size_t); - - GIT_UNUSED(file); - GIT_UNUSED(line); - - if (!len || (ptr = malloc(total)) == NULL) - return NULL; - - memcpy(ptr, &len, sizeof(size_t)); - return ptr + sizeof(size_t); -} - -static void *debugalloc__realloc(void *_ptr, size_t len, const char *file, int line) -{ - unsigned char *ptr = _ptr, *newptr; - size_t original_len; - size_t total = len + sizeof(size_t); - - GIT_UNUSED(file); - GIT_UNUSED(line); - - if (!len && !ptr) - return NULL; - - if (!len) { - free(ptr - sizeof(size_t)); - return NULL; - } - - if ((newptr = malloc(total)) == NULL) - return NULL; - - if (ptr) { - memcpy(&original_len, ptr - sizeof(size_t), sizeof(size_t)); - memcpy(newptr + sizeof(size_t), ptr, min(len, original_len)); - - memset(ptr - sizeof(size_t), 0xfd, original_len + sizeof(size_t)); - free(ptr - sizeof(size_t)); - } - - memcpy(newptr, &len, sizeof(size_t)); - return newptr + sizeof(size_t); -} - -static void debugalloc__free(void *_ptr) -{ - unsigned char *ptr = _ptr; - - if (!ptr) - return; - - free(ptr - sizeof(size_t)); -} - -int git_debugalloc_init_allocator(git_allocator *allocator) -{ - allocator->gmalloc = debugalloc__malloc; - allocator->grealloc = debugalloc__realloc; - allocator->gfree = debugalloc__free; - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/allocators/debugalloc.h b/vendor/libgit2-sys/libgit2/src/util/allocators/debugalloc.h deleted file mode 100644 index dea0ca3..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/allocators/debugalloc.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_allocators_debugalloc_h__ -#define INCLUDE_allocators_debugalloc_h__ - -#include "git2_util.h" - -#include "alloc.h" - -int git_debugalloc_init_allocator(git_allocator *allocator); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/allocators/failalloc.c b/vendor/libgit2-sys/libgit2/src/util/allocators/failalloc.c deleted file mode 100644 index c1025e3..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/allocators/failalloc.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "failalloc.h" - -void *git_failalloc_malloc(size_t len, const char *file, int line) -{ - GIT_UNUSED(len); - GIT_UNUSED(file); - GIT_UNUSED(line); - - return NULL; -} - -void *git_failalloc_realloc(void *ptr, size_t size, const char *file, int line) -{ - GIT_UNUSED(ptr); - GIT_UNUSED(size); - GIT_UNUSED(file); - GIT_UNUSED(line); - - return NULL; -} - -void git_failalloc_free(void *ptr) -{ - GIT_UNUSED(ptr); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/allocators/failalloc.h b/vendor/libgit2-sys/libgit2/src/util/allocators/failalloc.h deleted file mode 100644 index a3788e6..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/allocators/failalloc.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_allocators_failalloc_h__ -#define INCLUDE_allocators_failalloc_h__ - -#include "git2_util.h" - -extern void *git_failalloc_malloc(size_t len, const char *file, int line); -extern void *git_failalloc_realloc(void *ptr, size_t size, const char *file, int line); -extern void git_failalloc_free(void *ptr); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/allocators/stdalloc.c b/vendor/libgit2-sys/libgit2/src/util/allocators/stdalloc.c deleted file mode 100644 index 65ec40f..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/allocators/stdalloc.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "stdalloc.h" - -static void *stdalloc__malloc(size_t len, const char *file, int line) -{ - GIT_UNUSED(file); - GIT_UNUSED(line); - - return malloc(len); -} - -static void *stdalloc__realloc(void *ptr, size_t size, const char *file, int line) -{ - GIT_UNUSED(file); - GIT_UNUSED(line); - - return realloc(ptr, size); -} - -static void stdalloc__free(void *ptr) -{ - free(ptr); -} - -int git_stdalloc_init_allocator(git_allocator *allocator) -{ - allocator->gmalloc = stdalloc__malloc; - allocator->grealloc = stdalloc__realloc; - allocator->gfree = stdalloc__free; - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/allocators/stdalloc.h b/vendor/libgit2-sys/libgit2/src/util/allocators/stdalloc.h deleted file mode 100644 index 955038c..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/allocators/stdalloc.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_allocators_stdalloc_h__ -#define INCLUDE_allocators_stdalloc_h__ - -#include "git2_util.h" - -#include "alloc.h" - -int git_stdalloc_init_allocator(git_allocator *allocator); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/allocators/win32_leakcheck.c b/vendor/libgit2-sys/libgit2/src/util/allocators/win32_leakcheck.c deleted file mode 100644 index cdf16d3..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/allocators/win32_leakcheck.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "win32_leakcheck.h" - -#if defined(GIT_WIN32_LEAKCHECK) - -#include "win32/w32_leakcheck.h" - -static void *leakcheck_malloc(size_t len, const char *file, int line) -{ - void *ptr = _malloc_dbg(len, _NORMAL_BLOCK, git_win32_leakcheck_stacktrace(1,file), line); - if (!ptr) git_error_set_oom(); - return ptr; -} - -static void *leakcheck_realloc(void *ptr, size_t size, const char *file, int line) -{ - void *new_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, git_win32_leakcheck_stacktrace(1,file), line); - if (!new_ptr) git_error_set_oom(); - return new_ptr; -} - -static void leakcheck_free(void *ptr) -{ - free(ptr); -} - -int git_win32_leakcheck_init_allocator(git_allocator *allocator) -{ - allocator->gmalloc = leakcheck_malloc; - allocator->grealloc = leakcheck_realloc; - allocator->gfree = leakcheck_free; - return 0; -} - -#else - -int git_win32_leakcheck_init_allocator(git_allocator *allocator) -{ - GIT_UNUSED(allocator); - git_error_set(GIT_EINVALID, "leakcheck memory allocator not available"); - return -1; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/allocators/win32_leakcheck.h b/vendor/libgit2-sys/libgit2/src/util/allocators/win32_leakcheck.h deleted file mode 100644 index edcd930..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/allocators/win32_leakcheck.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_allocators_win32_leakcheck_h -#define INCLUDE_allocators_win32_leakcheck_h - -#include "git2_util.h" - -#include "alloc.h" - -int git_win32_leakcheck_init_allocator(git_allocator *allocator); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/array.h b/vendor/libgit2-sys/libgit2/src/util/array.h deleted file mode 100644 index 515e6e3..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/array.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_array_h__ -#define INCLUDE_array_h__ - -#include "git2_util.h" - -/* - * Use this to declare a typesafe resizable array of items, a la: - * - * git_array_t(int) my_ints = GIT_ARRAY_INIT; - * ... - * int *i = git_array_alloc(my_ints); - * GIT_ERROR_CHECK_ALLOC(i); - * ... - * git_array_clear(my_ints); - * - * You may also want to do things like: - * - * typedef git_array_t(my_struct) my_struct_array_t; - */ -#define git_array_t(type) struct { type *ptr; size_t size, asize; } - -#define GIT_ARRAY_INIT { NULL, 0, 0 } - -#define git_array_init(a) \ - do { (a).size = (a).asize = 0; (a).ptr = NULL; } while (0) - -#define git_array_init_to_size(a, desired) \ - do { (a).size = 0; (a).asize = desired; (a).ptr = git__calloc(desired, sizeof(*(a).ptr)); } while (0) - -#define git_array_dispose(a) \ - do { git__free((a).ptr); } while (0) - -#define git_array_clear(a) \ - do { git__free((a).ptr); git_array_init(a); } while (0) - -#define GIT_ERROR_CHECK_ARRAY(a) GIT_ERROR_CHECK_ALLOC((a).ptr) - -GIT_INLINE(void *) git_array__alloc(void *arr, size_t *size, size_t *asize, size_t item_size) -{ - size_t new_size; - void *new_array; - - if (*size < *asize) - return arr; - - if (*size < 8) { - new_size = 8; - } else { - if (GIT_MULTIPLY_SIZET_OVERFLOW(&new_size, *asize, 3)) - goto on_oom; - - new_size /= 2; - } - - if ((new_array = git__reallocarray(arr, new_size, item_size)) == NULL) - goto on_oom; - - *asize = new_size; - - return new_array; - -on_oom: - git__free(arr); - *size = 0; - *asize = 0; - return NULL; -} - -#define git_array_alloc(a) \ - (((a).size < (a).asize || \ - ((a).ptr = git_array__alloc((a).ptr, &(a).size, &(a).asize, sizeof(*(a).ptr))) != NULL) ? &(a).ptr[(a).size++] : (void *)NULL) - -#define git_array_last(a) ((a).size ? &(a).ptr[(a).size - 1] : (void *)NULL) - -#define git_array_pop(a) ((a).size ? &(a).ptr[--(a).size] : (void *)NULL) - -#define git_array_get(a, i) (((i) < (a).size) ? &(a).ptr[(i)] : (void *)NULL) - -#define git_array_size(a) (a).size - -#define git_array_valid_index(a, i) ((i) < (a).size) - -#define git_array_foreach(a, i, element) \ - for ((i) = 0; (i) < (a).size && ((element) = &(a).ptr[(i)]); (i)++) - -typedef int (*git_array_compare_cb)(const void *, const void *); - -GIT_INLINE(int) git_array__search( - size_t *out, - void *array_ptr, - size_t item_size, - size_t array_len, - git_array_compare_cb compare, - const void *key) -{ - size_t lim; - unsigned char *part, *array = array_ptr, *base = array_ptr; - int cmp = -1; - - for (lim = array_len; lim != 0; lim >>= 1) { - part = base + (lim >> 1) * item_size; - cmp = (*compare)(key, part); - - if (cmp == 0) { - base = part; - break; - } - if (cmp > 0) { /* key > p; take right partition */ - base = part + 1 * item_size; - lim--; - } /* else take left partition */ - } - - if (out) - *out = (base - array) / item_size; - - return (cmp == 0) ? 0 : GIT_ENOTFOUND; -} - -#define git_array_search(out, a, cmp, key) \ - git_array__search(out, (a).ptr, sizeof(*(a).ptr), (a).size, \ - (cmp), (key)) - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/assert_safe.h b/vendor/libgit2-sys/libgit2/src/util/assert_safe.h deleted file mode 100644 index cc0bac5..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/assert_safe.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_assert_safe_h__ -#define INCLUDE_assert_safe_h__ - -/* - * In a debug build, we'll assert(3) for aide in debugging. In release - * builds, we will provide macros that will set an error message that - * indicate a failure and return. Note that memory leaks can occur in - * a release-mode assertion failure -- it is impractical to provide - * safe clean up routines in these very extreme failures, but care - * should be taken to not leak very large objects. - */ - -#if (defined(_DEBUG) || defined(GIT_ASSERT_HARD)) && GIT_ASSERT_HARD != 0 -# include - -# define GIT_ASSERT(expr) assert(expr) -# define GIT_ASSERT_ARG(expr) assert(expr) - -# define GIT_ASSERT_WITH_RETVAL(expr, fail) assert(expr) -# define GIT_ASSERT_ARG_WITH_RETVAL(expr, fail) assert(expr) - -# define GIT_ASSERT_WITH_CLEANUP(expr, cleanup) assert(expr) -#else - -/** Internal consistency check to stop the function. */ -# define GIT_ASSERT(expr) GIT_ASSERT_WITH_RETVAL(expr, -1) - -/** - * Assert that a consumer-provided argument is valid, setting an - * actionable error message and returning -1 if it is not. - */ -# define GIT_ASSERT_ARG(expr) GIT_ASSERT_ARG_WITH_RETVAL(expr, -1) - -/** Internal consistency check to return the `fail` param on failure. */ -# define GIT_ASSERT_WITH_RETVAL(expr, fail) \ - GIT_ASSERT__WITH_RETVAL(expr, GIT_ERROR_INTERNAL, "unrecoverable internal error", fail) - -/** - * Assert that a consumer-provided argument is valid, setting an - * actionable error message and returning the `fail` param if not. - */ -# define GIT_ASSERT_ARG_WITH_RETVAL(expr, fail) \ - GIT_ASSERT__WITH_RETVAL(expr, GIT_ERROR_INVALID, "invalid argument", fail) - -# define GIT_ASSERT__WITH_RETVAL(expr, code, msg, fail) do { \ - if (!(expr)) { \ - git_error_set(code, "%s: '%s'", msg, #expr); \ - return fail; \ - } \ - } while(0) - -/** - * Go to to the given label on assertion failures; useful when you have - * taken a lock or otherwise need to release a resource. - */ -# define GIT_ASSERT_WITH_CLEANUP(expr, cleanup) \ - GIT_ASSERT__WITH_CLEANUP(expr, GIT_ERROR_INTERNAL, "unrecoverable internal error", cleanup) - -# define GIT_ASSERT__WITH_CLEANUP(expr, code, msg, cleanup) do { \ - if (!(expr)) { \ - git_error_set(code, "%s: '%s'", msg, #expr); \ - cleanup; \ - } \ - } while(0) - -#endif /* GIT_ASSERT_HARD */ - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/bitvec.h b/vendor/libgit2-sys/libgit2/src/util/bitvec.h deleted file mode 100644 index 544832d..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/bitvec.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_bitvec_h__ -#define INCLUDE_bitvec_h__ - -#include "common.h" - -/* - * This is a silly little fixed length bit vector type that will store - * vectors of 64 bits or less directly in the structure and allocate - * memory for vectors longer than 64 bits. You can use the two versions - * transparently through the API and avoid heap allocation completely when - * using a short bit vector as a result. - */ -typedef struct { - size_t length; - union { - uint64_t *words; - uint64_t bits; - } u; -} git_bitvec; - -GIT_INLINE(int) git_bitvec_init(git_bitvec *bv, size_t capacity) -{ - memset(bv, 0x0, sizeof(*bv)); - - if (capacity >= 64) { - bv->length = (capacity / 64) + 1; - bv->u.words = git__calloc(bv->length, sizeof(uint64_t)); - if (!bv->u.words) - return -1; - } - - return 0; -} - -#define GIT_BITVEC_MASK(BIT) ((uint64_t)1 << (BIT % 64)) -#define GIT_BITVEC_WORD(BV, BIT) (BV->length ? &BV->u.words[BIT / 64] : &BV->u.bits) - -GIT_INLINE(void) git_bitvec_set(git_bitvec *bv, size_t bit, bool on) -{ - uint64_t *word = GIT_BITVEC_WORD(bv, bit); - uint64_t mask = GIT_BITVEC_MASK(bit); - - if (on) - *word |= mask; - else - *word &= ~mask; -} - -GIT_INLINE(bool) git_bitvec_get(git_bitvec *bv, size_t bit) -{ - uint64_t *word = GIT_BITVEC_WORD(bv, bit); - return (*word & GIT_BITVEC_MASK(bit)) != 0; -} - -GIT_INLINE(void) git_bitvec_clear(git_bitvec *bv) -{ - if (!bv->length) - bv->u.bits = 0; - else - memset(bv->u.words, 0x0, bv->length * sizeof(uint64_t)); -} - -GIT_INLINE(void) git_bitvec_free(git_bitvec *bv) -{ - if (bv->length) - git__free(bv->u.words); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/cc-compat.h b/vendor/libgit2-sys/libgit2/src/util/cc-compat.h deleted file mode 100644 index ae81970..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/cc-compat.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_cc_compat_h__ -#define INCLUDE_cc_compat_h__ - -#include - -/* - * See if our compiler is known to support flexible array members. - */ -#ifndef GIT_FLEX_ARRAY -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define GIT_FLEX_ARRAY /* empty */ -# elif defined(__GNUC__) -# if (__GNUC__ >= 3) -# define GIT_FLEX_ARRAY /* empty */ -# else -# define GIT_FLEX_ARRAY 0 /* older GNU extension */ -# endif -# endif - -/* Default to safer but a bit wasteful traditional style */ -# ifndef GIT_FLEX_ARRAY -# define GIT_FLEX_ARRAY 1 -# endif -#endif - -#if defined(__GNUC__) -# define GIT_ALIGN(x,size) x __attribute__ ((aligned(size))) -#elif defined(_MSC_VER) -# define GIT_ALIGN(x,size) __declspec(align(size)) x -#else -# define GIT_ALIGN(x,size) x -#endif - -#if defined(__GNUC__) -# define GIT_UNUSED(x) \ - do { \ - __typeof__(x) _unused __attribute__((unused)); \ - _unused = (x); \ - } while (0) -# define GIT_UNUSED_ARG __attribute__((unused)) -# define GIT_UNUSED_FUNCTION __attribute__((unused)) -#else -# define GIT_UNUSED(x) ((void)(x)) -# define GIT_UNUSED_ARG -# define GIT_UNUSED_FUNCTION -#endif - -/* Define the printf format specifier to use for size_t output */ -#if defined(_MSC_VER) || defined(__MINGW32__) - -/* Visual Studio 2012 and prior lack PRId64 entirely */ -# ifndef PRId64 -# define PRId64 "I64d" -# endif - -/* The first block is needed to avoid warnings on MingW amd64 */ -# if (SIZE_MAX == ULLONG_MAX) -# define PRIuZ "I64u" -# define PRIxZ "I64x" -# define PRIXZ "I64X" -# define PRIdZ "I64d" -# else -# define PRIuZ "Iu" -# define PRIxZ "Ix" -# define PRIXZ "IX" -# define PRIdZ "Id" -# endif - -#else -# define PRIuZ "zu" -# define PRIxZ "zx" -# define PRIXZ "zX" -# define PRIdZ "zd" -#endif - -/* Microsoft Visual C/C++ */ -#if defined(_MSC_VER) -/* disable "deprecated function" warnings */ -# pragma warning ( disable : 4996 ) -/* disable "conditional expression is constant" level 4 warnings */ -# pragma warning ( disable : 4127 ) -#endif - -#if defined (_MSC_VER) - typedef unsigned char bool; -# ifndef true -# define true 1 -# endif -# ifndef false -# define false 0 -# endif -#else -# include -#endif - -#ifndef va_copy -# ifdef __va_copy -# define va_copy(dst, src) __va_copy(dst, src) -# else -# define va_copy(dst, src) ((dst) = (src)) -# endif -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/ctype_compat.h b/vendor/libgit2-sys/libgit2/src/util/ctype_compat.h deleted file mode 100644 index 462c8a1..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/ctype_compat.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_ctype_compat_h__ -#define INCLUDE_ctype_compat_h__ - -/* - * The Microsoft C runtime (MSVCRT) may take a heavy lock on the - * locale in order to figure out how the `ctype` functions work. - * This is deeply slow. Provide our own to avoid that. - */ - -#ifdef GIT_WIN32 - -GIT_INLINE(int) git__tolower(int c) -{ - return (c >= 'A' && c <= 'Z') ? (c + 32) : c; -} - -GIT_INLINE(int) git__toupper(int c) -{ - return (c >= 'a' && c <= 'z') ? (c - 32) : c; -} - -GIT_INLINE(bool) git__isalpha(int c) -{ - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); -} - -GIT_INLINE(bool) git__isdigit(int c) -{ - return (c >= '0' && c <= '9'); -} - -GIT_INLINE(bool) git__isalnum(int c) -{ - return git__isalpha(c) || git__isdigit(c); -} - -GIT_INLINE(bool) git__isspace(int c) -{ - return (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r' || c == '\v'); -} - -GIT_INLINE(bool) git__isxdigit(int c) -{ - return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); -} - -GIT_INLINE(bool) git__isprint(int c) -{ - return (c >= ' ' && c <= '~'); -} - -#else -# define git__tolower(a) tolower((unsigned char)(a)) -# define git__toupper(a) toupper((unsigned char)(a)) - -# define git__isalpha(a) (!!isalpha((unsigned char)(a))) -# define git__isdigit(a) (!!isdigit((unsigned char)(a))) -# define git__isalnum(a) (!!isalnum((unsigned char)(a))) -# define git__isspace(a) (!!isspace((unsigned char)(a))) -# define git__isxdigit(a) (!!isxdigit((unsigned char)(a))) -# define git__isprint(a) (!!isprint((unsigned char)(a))) -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/date.c b/vendor/libgit2-sys/libgit2/src/util/date.c deleted file mode 100644 index 0ff5287..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/date.c +++ /dev/null @@ -1,907 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" - -#ifndef GIT_WIN32 -#include -#endif - -#include "util.h" -#include "posix.h" -#include "date.h" - -#include -#include - -typedef enum { - DATE_NORMAL = 0, - DATE_RELATIVE, - DATE_SHORT, - DATE_LOCAL, - DATE_ISO8601, - DATE_RFC2822, - DATE_RAW -} date_mode; - -/* - * This is like mktime, but without normalization of tm_wday and tm_yday. - */ -static git_time_t tm_to_time_t(const struct tm *tm) -{ - static const int mdays[] = { - 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 - }; - int year = tm->tm_year - 70; - int month = tm->tm_mon; - int day = tm->tm_mday; - - if (year < 0 || year > 129) /* algo only works for 1970-2099 */ - return -1; - if (month < 0 || month > 11) /* array bounds */ - return -1; - if (month < 2 || (year + 2) % 4) - day--; - if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_sec < 0) - return -1; - return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + - tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; -} - -static const char *month_names[] = { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" -}; - -static const char *weekday_names[] = { - "Sundays", "Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fridays", "Saturdays" -}; - - - -/* - * Check these. And note how it doesn't do the summer-time conversion. - * - * In my world, it's always summer, and things are probably a bit off - * in other ways too. - */ -static const struct { - const char *name; - int offset; - int dst; -} timezone_names[] = { - { "IDLW", -12, 0, }, /* International Date Line West */ - { "NT", -11, 0, }, /* Nome */ - { "CAT", -10, 0, }, /* Central Alaska */ - { "HST", -10, 0, }, /* Hawaii Standard */ - { "HDT", -10, 1, }, /* Hawaii Daylight */ - { "YST", -9, 0, }, /* Yukon Standard */ - { "YDT", -9, 1, }, /* Yukon Daylight */ - { "PST", -8, 0, }, /* Pacific Standard */ - { "PDT", -8, 1, }, /* Pacific Daylight */ - { "MST", -7, 0, }, /* Mountain Standard */ - { "MDT", -7, 1, }, /* Mountain Daylight */ - { "CST", -6, 0, }, /* Central Standard */ - { "CDT", -6, 1, }, /* Central Daylight */ - { "EST", -5, 0, }, /* Eastern Standard */ - { "EDT", -5, 1, }, /* Eastern Daylight */ - { "AST", -3, 0, }, /* Atlantic Standard */ - { "ADT", -3, 1, }, /* Atlantic Daylight */ - { "WAT", -1, 0, }, /* West Africa */ - - { "GMT", 0, 0, }, /* Greenwich Mean */ - { "UTC", 0, 0, }, /* Universal (Coordinated) */ - { "Z", 0, 0, }, /* Zulu, alias for UTC */ - - { "WET", 0, 0, }, /* Western European */ - { "BST", 0, 1, }, /* British Summer */ - { "CET", +1, 0, }, /* Central European */ - { "MET", +1, 0, }, /* Middle European */ - { "MEWT", +1, 0, }, /* Middle European Winter */ - { "MEST", +1, 1, }, /* Middle European Summer */ - { "CEST", +1, 1, }, /* Central European Summer */ - { "MESZ", +1, 1, }, /* Middle European Summer */ - { "FWT", +1, 0, }, /* French Winter */ - { "FST", +1, 1, }, /* French Summer */ - { "EET", +2, 0, }, /* Eastern Europe */ - { "EEST", +2, 1, }, /* Eastern European Daylight */ - { "WAST", +7, 0, }, /* West Australian Standard */ - { "WADT", +7, 1, }, /* West Australian Daylight */ - { "CCT", +8, 0, }, /* China Coast */ - { "JST", +9, 0, }, /* Japan Standard */ - { "EAST", +10, 0, }, /* Eastern Australian Standard */ - { "EADT", +10, 1, }, /* Eastern Australian Daylight */ - { "GST", +10, 0, }, /* Guam Standard */ - { "NZT", +12, 0, }, /* New Zealand */ - { "NZST", +12, 0, }, /* New Zealand Standard */ - { "NZDT", +12, 1, }, /* New Zealand Daylight */ - { "IDLE", +12, 0, }, /* International Date Line East */ -}; - -static size_t match_string(const char *date, const char *str) -{ - size_t i = 0; - - for (i = 0; *date; date++, str++, i++) { - if (*date == *str) - continue; - if (git__toupper(*date) == git__toupper(*str)) - continue; - if (!git__isalnum(*date)) - break; - return 0; - } - return i; -} - -static int skip_alpha(const char *date) -{ - int i = 0; - do { - i++; - } while (git__isalpha(date[i])); - return i; -} - -/* -* Parse month, weekday, or timezone name -*/ -static size_t match_alpha(const char *date, struct tm *tm, int *offset) -{ - unsigned int i; - - for (i = 0; i < 12; i++) { - size_t match = match_string(date, month_names[i]); - if (match >= 3) { - tm->tm_mon = i; - return match; - } - } - - for (i = 0; i < 7; i++) { - size_t match = match_string(date, weekday_names[i]); - if (match >= 3) { - tm->tm_wday = i; - return match; - } - } - - for (i = 0; i < ARRAY_SIZE(timezone_names); i++) { - size_t match = match_string(date, timezone_names[i].name); - if (match >= 3 || match == strlen(timezone_names[i].name)) { - int off = timezone_names[i].offset; - - /* This is bogus, but we like summer */ - off += timezone_names[i].dst; - - /* Only use the tz name offset if we don't have anything better */ - if (*offset == -1) - *offset = 60*off; - - return match; - } - } - - if (match_string(date, "PM") == 2) { - tm->tm_hour = (tm->tm_hour % 12) + 12; - return 2; - } - - if (match_string(date, "AM") == 2) { - tm->tm_hour = (tm->tm_hour % 12) + 0; - return 2; - } - - /* BAD */ - return skip_alpha(date); -} - -static int is_date(int year, int month, int day, struct tm *now_tm, time_t now, struct tm *tm) -{ - if (month > 0 && month < 13 && day > 0 && day < 32) { - struct tm check = *tm; - struct tm *r = (now_tm ? &check : tm); - git_time_t specified; - - r->tm_mon = month - 1; - r->tm_mday = day; - if (year == -1) { - if (!now_tm) - return 1; - r->tm_year = now_tm->tm_year; - } - else if (year >= 1970 && year < 2100) - r->tm_year = year - 1900; - else if (year > 70 && year < 100) - r->tm_year = year; - else if (year < 38) - r->tm_year = year + 100; - else - return 0; - if (!now_tm) - return 1; - - specified = tm_to_time_t(r); - - /* Be it commit time or author time, it does not make - * sense to specify timestamp way into the future. Make - * sure it is not later than ten days from now... - */ - if (now + 10*24*3600 < specified) - return 0; - tm->tm_mon = r->tm_mon; - tm->tm_mday = r->tm_mday; - if (year != -1) - tm->tm_year = r->tm_year; - return 1; - } - return 0; -} - -static size_t match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm) -{ - time_t now; - struct tm now_tm; - struct tm *refuse_future; - long num2, num3; - - num2 = strtol(end+1, &end, 10); - num3 = -1; - if (*end == c && git__isdigit(end[1])) - num3 = strtol(end+1, &end, 10); - - /* Time? Date? */ - switch (c) { - case ':': - if (num3 < 0) - num3 = 0; - if (num < 25 && num2 >= 0 && num2 < 60 && num3 >= 0 && num3 <= 60) { - tm->tm_hour = num; - tm->tm_min = num2; - tm->tm_sec = num3; - break; - } - return 0; - - case '-': - case '/': - case '.': - now = time(NULL); - refuse_future = NULL; - if (p_gmtime_r(&now, &now_tm)) - refuse_future = &now_tm; - - if (num > 70) { - /* yyyy-mm-dd? */ - if (is_date(num, num2, num3, refuse_future, now, tm)) - break; - /* yyyy-dd-mm? */ - if (is_date(num, num3, num2, refuse_future, now, tm)) - break; - } - /* Our eastern European friends say dd.mm.yy[yy] - * is the norm there, so giving precedence to - * mm/dd/yy[yy] form only when separator is not '.' - */ - if (c != '.' && - is_date(num3, num, num2, refuse_future, now, tm)) - break; - /* European dd.mm.yy[yy] or funny US dd/mm/yy[yy] */ - if (is_date(num3, num2, num, refuse_future, now, tm)) - break; - /* Funny European mm.dd.yy */ - if (c == '.' && - is_date(num3, num, num2, refuse_future, now, tm)) - break; - return 0; - } - return end - date; -} - -/* - * Have we filled in any part of the time/date yet? - * We just do a binary 'and' to see if the sign bit - * is set in all the values. - */ -static int nodate(struct tm *tm) -{ - return (tm->tm_year & - tm->tm_mon & - tm->tm_mday & - tm->tm_hour & - tm->tm_min & - tm->tm_sec) < 0; -} - -/* - * We've seen a digit. Time? Year? Date? - */ -static size_t match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt) -{ - size_t n; - char *end; - unsigned long num; - - num = strtoul(date, &end, 10); - - /* - * Seconds since 1970? We trigger on that for any numbers with - * more than 8 digits. This is because we don't want to rule out - * numbers like 20070606 as a YYYYMMDD date. - */ - if (num >= 100000000 && nodate(tm)) { - time_t time = num; - if (p_gmtime_r(&time, tm)) { - *tm_gmt = 1; - return end - date; - } - } - - /* - * Check for special formats: num[-.:/]num[same]num - */ - switch (*end) { - case ':': - case '.': - case '/': - case '-': - if (git__isdigit(end[1])) { - size_t match = match_multi_number(num, *end, date, end, tm); - if (match) - return match; - } - } - - /* - * None of the special formats? Try to guess what - * the number meant. We use the number of digits - * to make a more educated guess.. - */ - n = 0; - do { - n++; - } while (git__isdigit(date[n])); - - /* Four-digit year or a timezone? */ - if (n == 4) { - if (num <= 1400 && *offset == -1) { - unsigned int minutes = num % 100; - unsigned int hours = num / 100; - *offset = hours*60 + minutes; - } else if (num > 1900 && num < 2100) - tm->tm_year = num - 1900; - return n; - } - - /* - * Ignore lots of numerals. We took care of 4-digit years above. - * Days or months must be one or two digits. - */ - if (n > 2) - return n; - - /* - * NOTE! We will give precedence to day-of-month over month or - * year numbers in the 1-12 range. So 05 is always "mday 5", - * unless we already have a mday.. - * - * IOW, 01 Apr 05 parses as "April 1st, 2005". - */ - if (num > 0 && num < 32 && tm->tm_mday < 0) { - tm->tm_mday = num; - return n; - } - - /* Two-digit year? */ - if (n == 2 && tm->tm_year < 0) { - if (num < 10 && tm->tm_mday >= 0) { - tm->tm_year = num + 100; - return n; - } - if (num >= 70) { - tm->tm_year = num; - return n; - } - } - - if (num > 0 && num < 13 && tm->tm_mon < 0) - tm->tm_mon = num-1; - - return n; -} - -static size_t match_tz(const char *date, int *offp) -{ - char *end; - int hour = strtoul(date + 1, &end, 10); - size_t n = end - (date + 1); - int min = 0; - - if (n == 4) { - /* hhmm */ - min = hour % 100; - hour = hour / 100; - } else if (n != 2) { - min = 99; /* random stuff */ - } else if (*end == ':') { - /* hh:mm? */ - min = strtoul(end + 1, &end, 10); - if (end - (date + 1) != 5) - min = 99; /* random stuff */ - } /* otherwise we parsed "hh" */ - - /* - * Don't accept any random stuff. Even though some places have - * offset larger than 12 hours (e.g. Pacific/Kiritimati is at - * UTC+14), there is something wrong if hour part is much - * larger than that. We might also want to check that the - * minutes are divisible by 15 or something too. (Offset of - * Kathmandu, Nepal is UTC+5:45) - */ - if (min < 60 && hour < 24) { - int offset = hour * 60 + min; - if (*date == '-') - offset = -offset; - *offp = offset; - } - return end - date; -} - -/* - * Parse a string like "0 +0000" as ancient timestamp near epoch, but - * only when it appears not as part of any other string. - */ -static int match_object_header_date(const char *date, git_time_t *timestamp, int *offset) -{ - char *end; - unsigned long stamp; - int ofs; - - if (*date < '0' || '9' <= *date) - return -1; - stamp = strtoul(date, &end, 10); - if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-')) - return -1; - date = end + 2; - ofs = strtol(date, &end, 10); - if ((*end != '\0' && (*end != '\n')) || end != date + 4) - return -1; - ofs = (ofs / 100) * 60 + (ofs % 100); - if (date[-1] == '-') - ofs = -ofs; - *timestamp = stamp; - *offset = ofs; - return 0; -} - -/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822 - (i.e. English) day/month names, and it doesn't work correctly with %z. */ -static int parse_date_basic(const char *date, git_time_t *timestamp, int *offset) -{ - struct tm tm; - int tm_gmt; - git_time_t dummy_timestamp; - int dummy_offset; - - if (!timestamp) - timestamp = &dummy_timestamp; - if (!offset) - offset = &dummy_offset; - - memset(&tm, 0, sizeof(tm)); - tm.tm_year = -1; - tm.tm_mon = -1; - tm.tm_mday = -1; - tm.tm_isdst = -1; - tm.tm_hour = -1; - tm.tm_min = -1; - tm.tm_sec = -1; - *offset = -1; - tm_gmt = 0; - - if (*date == '@' && - !match_object_header_date(date + 1, timestamp, offset)) - return 0; /* success */ - for (;;) { - size_t match = 0; - unsigned char c = *date; - - /* Stop at end of string or newline */ - if (!c || c == '\n') - break; - - if (git__isalpha(c)) - match = match_alpha(date, &tm, offset); - else if (git__isdigit(c)) - match = match_digit(date, &tm, offset, &tm_gmt); - else if ((c == '-' || c == '+') && git__isdigit(date[1])) - match = match_tz(date, offset); - - if (!match) { - /* BAD */ - match = 1; - } - - date += match; - } - - /* mktime uses local timezone */ - *timestamp = tm_to_time_t(&tm); - if (*offset == -1) - *offset = (int)((time_t)*timestamp - mktime(&tm)) / 60; - - if (*timestamp == (git_time_t)-1) - return -1; - - if (!tm_gmt) - *timestamp -= *offset * 60; - return 0; /* success */ -} - - -/* - * Relative time update (eg "2 days ago"). If we haven't set the time - * yet, we need to set it from current time. - */ -static git_time_t update_tm(struct tm *tm, struct tm *now, unsigned long sec) -{ - time_t n; - - if (tm->tm_mday < 0) - tm->tm_mday = now->tm_mday; - if (tm->tm_mon < 0) - tm->tm_mon = now->tm_mon; - if (tm->tm_year < 0) { - tm->tm_year = now->tm_year; - if (tm->tm_mon > now->tm_mon) - tm->tm_year--; - } - - n = mktime(tm) - sec; - p_localtime_r(&n, tm); - return n; -} - -static void date_now(struct tm *tm, struct tm *now, int *num) -{ - GIT_UNUSED(num); - update_tm(tm, now, 0); -} - -static void date_yesterday(struct tm *tm, struct tm *now, int *num) -{ - GIT_UNUSED(num); - update_tm(tm, now, 24*60*60); -} - -static void date_time(struct tm *tm, struct tm *now, int hour) -{ - if (tm->tm_hour < hour) - date_yesterday(tm, now, NULL); - tm->tm_hour = hour; - tm->tm_min = 0; - tm->tm_sec = 0; -} - -static void date_midnight(struct tm *tm, struct tm *now, int *num) -{ - GIT_UNUSED(num); - date_time(tm, now, 0); -} - -static void date_noon(struct tm *tm, struct tm *now, int *num) -{ - GIT_UNUSED(num); - date_time(tm, now, 12); -} - -static void date_tea(struct tm *tm, struct tm *now, int *num) -{ - GIT_UNUSED(num); - date_time(tm, now, 17); -} - -static void date_pm(struct tm *tm, struct tm *now, int *num) -{ - int hour, n = *num; - *num = 0; - GIT_UNUSED(now); - - hour = tm->tm_hour; - if (n) { - hour = n; - tm->tm_min = 0; - tm->tm_sec = 0; - } - tm->tm_hour = (hour % 12) + 12; -} - -static void date_am(struct tm *tm, struct tm *now, int *num) -{ - int hour, n = *num; - *num = 0; - GIT_UNUSED(now); - - hour = tm->tm_hour; - if (n) { - hour = n; - tm->tm_min = 0; - tm->tm_sec = 0; - } - tm->tm_hour = (hour % 12); -} - -static void date_never(struct tm *tm, struct tm *now, int *num) -{ - time_t n = 0; - GIT_UNUSED(now); - GIT_UNUSED(num); - p_localtime_r(&n, tm); -} - -static const struct special { - const char *name; - void (*fn)(struct tm *, struct tm *, int *); -} special[] = { - { "yesterday", date_yesterday }, - { "noon", date_noon }, - { "midnight", date_midnight }, - { "tea", date_tea }, - { "PM", date_pm }, - { "AM", date_am }, - { "never", date_never }, - { "now", date_now }, - { NULL } -}; - -static const char *number_name[] = { - "zero", "one", "two", "three", "four", - "five", "six", "seven", "eight", "nine", "ten", -}; - -static const struct typelen { - const char *type; - int length; -} typelen[] = { - { "seconds", 1 }, - { "minutes", 60 }, - { "hours", 60*60 }, - { "days", 24*60*60 }, - { "weeks", 7*24*60*60 }, - { NULL } -}; - -static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm *now, int *num, int *touched) -{ - const struct typelen *tl; - const struct special *s; - const char *end = date; - int i; - - while (git__isalpha(*++end)) - /* scan to non-alpha */; - - for (i = 0; i < 12; i++) { - size_t match = match_string(date, month_names[i]); - if (match >= 3) { - tm->tm_mon = i; - *touched = 1; - return end; - } - } - - for (s = special; s->name; s++) { - size_t len = strlen(s->name); - if (match_string(date, s->name) == len) { - s->fn(tm, now, num); - *touched = 1; - return end; - } - } - - if (!*num) { - for (i = 1; i < 11; i++) { - size_t len = strlen(number_name[i]); - if (match_string(date, number_name[i]) == len) { - *num = i; - *touched = 1; - return end; - } - } - if (match_string(date, "last") == 4) { - *num = 1; - *touched = 1; - } - return end; - } - - tl = typelen; - while (tl->type) { - size_t len = strlen(tl->type); - if (match_string(date, tl->type) >= len-1) { - update_tm(tm, now, tl->length * (unsigned long)*num); - *num = 0; - *touched = 1; - return end; - } - tl++; - } - - for (i = 0; i < 7; i++) { - size_t match = match_string(date, weekday_names[i]); - if (match >= 3) { - int diff, n = *num -1; - *num = 0; - - diff = tm->tm_wday - i; - if (diff <= 0) - n++; - diff += 7*n; - - update_tm(tm, now, diff * 24 * 60 * 60); - *touched = 1; - return end; - } - } - - if (match_string(date, "months") >= 5) { - int n; - update_tm(tm, now, 0); /* fill in date fields if needed */ - n = tm->tm_mon - *num; - *num = 0; - while (n < 0) { - n += 12; - tm->tm_year--; - } - tm->tm_mon = n; - *touched = 1; - return end; - } - - if (match_string(date, "years") >= 4) { - update_tm(tm, now, 0); /* fill in date fields if needed */ - tm->tm_year -= *num; - *num = 0; - *touched = 1; - return end; - } - - return end; -} - -static const char *approxidate_digit(const char *date, struct tm *tm, int *num) -{ - char *end; - unsigned long number = strtoul(date, &end, 10); - - switch (*end) { - case ':': - case '.': - case '/': - case '-': - if (git__isdigit(end[1])) { - size_t match = match_multi_number(number, *end, date, end, tm); - if (match) - return date + match; - } - } - - /* Accept zero-padding only for small numbers ("Dec 02", never "Dec 0002") */ - if (date[0] != '0' || end - date <= 2) - *num = number; - return end; -} - -/* - * Do we have a pending number at the end, or when - * we see a new one? Let's assume it's a month day, - * as in "Dec 6, 1992" - */ -static void pending_number(struct tm *tm, int *num) -{ - int number = *num; - - if (number) { - *num = 0; - if (tm->tm_mday < 0 && number < 32) - tm->tm_mday = number; - else if (tm->tm_mon < 0 && number < 13) - tm->tm_mon = number-1; - else if (tm->tm_year < 0) { - if (number > 1969 && number < 2100) - tm->tm_year = number - 1900; - else if (number > 69 && number < 100) - tm->tm_year = number; - else if (number < 38) - tm->tm_year = 100 + number; - /* We mess up for number = 00 ? */ - } - } -} - -static git_time_t approxidate_str(const char *date, - time_t time_sec, - int *error_ret) -{ - int number = 0; - int touched = 0; - struct tm tm = {0}, now; - - p_localtime_r(&time_sec, &tm); - now = tm; - - tm.tm_year = -1; - tm.tm_mon = -1; - tm.tm_mday = -1; - - for (;;) { - unsigned char c = *date; - if (!c) - break; - date++; - if (git__isdigit(c)) { - pending_number(&tm, &number); - date = approxidate_digit(date-1, &tm, &number); - touched = 1; - continue; - } - if (git__isalpha(c)) - date = approxidate_alpha(date-1, &tm, &now, &number, &touched); - } - pending_number(&tm, &number); - if (!touched) - *error_ret = -1; - return update_tm(&tm, &now, 0); -} - -int git_date_offset_parse(git_time_t *out, int *out_offset, const char *date) -{ - time_t time_sec; - git_time_t timestamp; - int offset, error_ret=0; - - if (!parse_date_basic(date, ×tamp, &offset)) { - *out = timestamp; - *out_offset = offset; - return 0; - } - - if (time(&time_sec) == -1) - return -1; - - *out = approxidate_str(date, time_sec, &error_ret); - return error_ret; -} - -int git_date_parse(git_time_t *out, const char *date) -{ - int offset; - - return git_date_offset_parse(out, &offset, date); -} - -int git_date_rfc2822_fmt(git_str *out, git_time_t time, int offset) -{ - time_t t; - struct tm gmt; - - GIT_ASSERT_ARG(out); - - t = (time_t) (time + offset * 60); - - if (p_gmtime_r(&t, &gmt) == NULL) - return -1; - - return git_str_printf(out, "%.3s, %u %.3s %.4u %02u:%02u:%02u %+03d%02d", - weekday_names[gmt.tm_wday], - gmt.tm_mday, - month_names[gmt.tm_mon], - gmt.tm_year + 1900, - gmt.tm_hour, gmt.tm_min, gmt.tm_sec, - offset / 60, offset % 60); -} - diff --git a/vendor/libgit2-sys/libgit2/src/util/date.h b/vendor/libgit2-sys/libgit2/src/util/date.h deleted file mode 100644 index 785fc06..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/date.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_date_h__ -#define INCLUDE_date_h__ - -#include "util.h" -#include "str.h" - -/* - * Parse a string into a value as a git_time_t with a timezone offset. - * - * Sample valid input: - * - "yesterday" - * - "July 17, 2003" - * - "2003-7-17 08:23i+03" - */ -extern int git_date_offset_parse(git_time_t *out, int *out_offset, const char *date); - -/* - * Parse a string into a value as a git_time_t. - * - * Timezone offset is ignored. - * - * Sample valid input: - * - "yesterday" - * - "July 17, 2003" - * - "2003-7-17 08:23" - */ -extern int git_date_parse(git_time_t *out, const char *date); - -/* - * Format a git_time as a RFC2822 string - * - * @param out buffer to store formatted date - * @param time the time to be formatted - * @param offset the timezone offset - * @return 0 if successful; -1 on error - */ -extern int git_date_rfc2822_fmt(git_str *out, git_time_t time, int offset); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/errors.c b/vendor/libgit2-sys/libgit2/src/util/errors.c deleted file mode 100644 index feed6a8..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/errors.c +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" - -#include "errors.h" -#include "posix.h" -#include "str.h" -#include "runtime.h" - -/* - * Some static error data that is used when we're out of memory, TLS - * has not been setup, or TLS has failed. - */ - -static git_error oom_error = { - "Out of memory", - GIT_ERROR_NOMEMORY -}; - -static git_error uninitialized_error = { - "library has not been initialized", - GIT_ERROR_INVALID -}; - -static git_error tlsdata_error = { - "thread-local data initialization failure", - GIT_ERROR_THREAD -}; - -static git_error no_error = { - "no error", - GIT_ERROR_NONE -}; - -#define IS_STATIC_ERROR(err) \ - ((err) == &oom_error || (err) == &uninitialized_error || \ - (err) == &tlsdata_error || (err) == &no_error) - -/* Per-thread error state (TLS) */ - -static git_tlsdata_key tls_key; - -struct error_threadstate { - /* The error message buffer. */ - git_str message; - - /* Error information, set by `git_error_set` and friends. */ - git_error error; - - /* - * The last error to occur; points to the error member of this - * struct _or_ a static error. - */ - git_error *last; -}; - -static void threadstate_dispose(struct error_threadstate *threadstate) -{ - if (!threadstate) - return; - - git_str_dispose(&threadstate->message); -} - -static struct error_threadstate *threadstate_get(void) -{ - struct error_threadstate *threadstate; - - if ((threadstate = git_tlsdata_get(tls_key)) != NULL) - return threadstate; - - /* - * Avoid git__malloc here, since if it fails, it sets an error - * message, which requires thread state, which would allocate - * here, which would fail, which would set an error message... - */ - - if ((threadstate = git__allocator.gmalloc( - sizeof(struct error_threadstate), - __FILE__, __LINE__)) == NULL) - return NULL; - - memset(threadstate, 0, sizeof(struct error_threadstate)); - - if (git_str_init(&threadstate->message, 0) < 0) { - git__allocator.gfree(threadstate); - return NULL; - } - - git_tlsdata_set(tls_key, threadstate); - return threadstate; -} - -static void GIT_SYSTEM_CALL threadstate_free(void *threadstate) -{ - threadstate_dispose(threadstate); - git__free(threadstate); -} - -static void git_error_global_shutdown(void) -{ - struct error_threadstate *threadstate; - - threadstate = git_tlsdata_get(tls_key); - git_tlsdata_set(tls_key, NULL); - - threadstate_dispose(threadstate); - git__free(threadstate); - - git_tlsdata_dispose(tls_key); -} - -int git_error_global_init(void) -{ - if (git_tlsdata_init(&tls_key, &threadstate_free) != 0) - return -1; - - return git_runtime_shutdown_register(git_error_global_shutdown); -} - -static void set_error_from_buffer(int error_class) -{ - struct error_threadstate *threadstate = threadstate_get(); - git_error *error; - git_str *buf; - - if (!threadstate) - return; - - error = &threadstate->error; - buf = &threadstate->message; - - error->message = buf->ptr; - error->klass = error_class; - - threadstate->last = error; -} - -static void set_error(int error_class, char *string) -{ - struct error_threadstate *threadstate = threadstate_get(); - git_str *buf; - - if (!threadstate) - return; - - buf = &threadstate->message; - - git_str_clear(buf); - - if (string) - git_str_puts(buf, string); - - if (!git_str_oom(buf)) - set_error_from_buffer(error_class); -} - -void git_error_set_oom(void) -{ - struct error_threadstate *threadstate = threadstate_get(); - - if (!threadstate) - return; - - threadstate->last = &oom_error; -} - -void git_error_set(int error_class, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - git_error_vset(error_class, fmt, ap); - va_end(ap); -} - -void git_error_vset(int error_class, const char *fmt, va_list ap) -{ -#ifdef GIT_WIN32 - DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0; -#endif - - struct error_threadstate *threadstate = threadstate_get(); - int error_code = (error_class == GIT_ERROR_OS) ? errno : 0; - git_str *buf; - - if (!threadstate) - return; - - buf = &threadstate->message; - - git_str_clear(buf); - - if (fmt) { - git_str_vprintf(buf, fmt, ap); - if (error_class == GIT_ERROR_OS) - git_str_PUTS(buf, ": "); - } - - if (error_class == GIT_ERROR_OS) { -#ifdef GIT_WIN32 - char *win32_error = git_win32_get_error_message(win32_error_code); - if (win32_error) { - git_str_puts(buf, win32_error); - git__free(win32_error); - - SetLastError(0); - } - else -#endif - if (error_code) - git_str_puts(buf, strerror(error_code)); - - if (error_code) - errno = 0; - } - - if (!git_str_oom(buf)) - set_error_from_buffer(error_class); -} - -int git_error_set_str(int error_class, const char *string) -{ - struct error_threadstate *threadstate = threadstate_get(); - git_str *buf; - - GIT_ASSERT_ARG(string); - - if (!threadstate) - return -1; - - buf = &threadstate->message; - - git_str_clear(buf); - git_str_puts(buf, string); - - if (git_str_oom(buf)) - return -1; - - set_error_from_buffer(error_class); - return 0; -} - -void git_error_clear(void) -{ - struct error_threadstate *threadstate = threadstate_get(); - - if (!threadstate) - return; - - if (threadstate->last != NULL) { - set_error(0, NULL); - threadstate->last = NULL; - } - - errno = 0; -#ifdef GIT_WIN32 - SetLastError(0); -#endif -} - -bool git_error_exists(void) -{ - struct error_threadstate *threadstate; - - if ((threadstate = threadstate_get()) == NULL) - return true; - - return threadstate->last != NULL; -} - -const git_error *git_error_last(void) -{ - struct error_threadstate *threadstate; - - /* If the library is not initialized, return a static error. */ - if (!git_runtime_init_count()) - return &uninitialized_error; - - if ((threadstate = threadstate_get()) == NULL) - return &tlsdata_error; - - if (!threadstate->last) - return &no_error; - - return threadstate->last; -} - -int git_error_save(git_error **out) -{ - struct error_threadstate *threadstate = threadstate_get(); - git_error *error, *dup; - - if (!threadstate) { - *out = &tlsdata_error; - return -1; - } - - error = threadstate->last; - - if (!error || error == &no_error) { - *out = &no_error; - return 0; - } else if (IS_STATIC_ERROR(error)) { - *out = error; - return 0; - } - - if ((dup = git__malloc(sizeof(git_error))) == NULL) { - *out = &oom_error; - return -1; - } - - dup->klass = error->klass; - dup->message = git__strdup(error->message); - - if (!dup->message) { - *out = &oom_error; - return -1; - } - - *out = dup; - return 0; -} - -int git_error_restore(git_error *error) -{ - struct error_threadstate *threadstate = threadstate_get(); - - GIT_ASSERT_ARG(error); - - if (IS_STATIC_ERROR(error) && threadstate) - threadstate->last = error; - else - set_error(error->klass, error->message); - - git_error_free(error); - return 0; -} - -void git_error_free(git_error *error) -{ - if (!error) - return; - - if (IS_STATIC_ERROR(error)) - return; - - git__free(error->message); - git__free(error); -} - -int git_error_system_last(void) -{ -#ifdef GIT_WIN32 - return GetLastError(); -#else - return errno; -#endif -} - -void git_error_system_set(int code) -{ -#ifdef GIT_WIN32 - SetLastError(code); -#else - errno = code; -#endif -} - -/* Deprecated error values and functions */ - -#ifndef GIT_DEPRECATE_HARD - -#include "git2/deprecated.h" - -const git_error *giterr_last(void) -{ - return git_error_last(); -} - -void giterr_clear(void) -{ - git_error_clear(); -} - -void giterr_set_str(int error_class, const char *string) -{ - git_error_set_str(error_class, string); -} - -void giterr_set_oom(void) -{ - git_error_set_oom(); -} -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/errors.h b/vendor/libgit2-sys/libgit2/src/util/errors.h deleted file mode 100644 index 8d58775..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/errors.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_errors_h__ -#define INCLUDE_errors_h__ - -#include "git2_util.h" -#include "git2/sys/errors.h" - -/* Initialize the error thread-state. */ -int git_error_global_init(void); - -/* - * `vprintf`-style formatting for the error message for this thread. - */ -void git_error_vset(int error_class, const char *fmt, va_list ap); - -/** - * Determines whether an error exists. - */ -bool git_error_exists(void); - -/** - * Set error message for user callback if needed. - * - * If the error code in non-zero and no error message is set, this - * sets a generic error message. - * - * @return This always returns the `error_code` parameter. - */ -GIT_INLINE(int) git_error_set_after_callback_function( - int error_code, const char *action) -{ - if (error_code) { - if (!git_error_exists()) - git_error_set(GIT_ERROR_CALLBACK, - "%s callback returned %d", action, error_code); - } - return error_code; -} - -#ifdef GIT_WIN32 -#define git_error_set_after_callback(code) \ - git_error_set_after_callback_function((code), __FUNCTION__) -#else -#define git_error_set_after_callback(code) \ - git_error_set_after_callback_function((code), __func__) -#endif - -/** - * Gets the system error code for this thread. - */ -int git_error_system_last(void); - -/** - * Sets the system error code for this thread. - */ -void git_error_system_set(int code); - -/** - * Capture current error state to restore later, returning error code. - * If `error_code` is zero, this does not clear the current error state. - * You must either restore this error state, or free it. - * - * This function returns 0 on success, or -1 on failure. If the function - * fails, the `out` structure is set to the failure error message and - * the normal system error message is not updated. - */ -extern int git_error_save(git_error **out); - -/** - * Restore thread error state to the given value. The given value is - * freed and `git_error_free` need not be called on it. - */ -extern int git_error_restore(git_error *error); - -/** Free an error state. */ -extern void git_error_free(git_error *error); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/filebuf.c b/vendor/libgit2-sys/libgit2/src/util/filebuf.c deleted file mode 100644 index 7afb76b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/filebuf.c +++ /dev/null @@ -1,600 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "filebuf.h" - -#include "futils.h" - -static const size_t WRITE_BUFFER_SIZE = (4096 * 2); - -enum buferr_t { - BUFERR_OK = 0, - BUFERR_WRITE, - BUFERR_ZLIB, - BUFERR_MEM -}; - -#define ENSURE_BUF_OK(buf) if ((buf)->last_error != BUFERR_OK) { return -1; } - -static int verify_last_error(git_filebuf *file) -{ - switch (file->last_error) { - case BUFERR_WRITE: - git_error_set(GIT_ERROR_OS, "failed to write out file"); - return -1; - - case BUFERR_MEM: - git_error_set_oom(); - return -1; - - case BUFERR_ZLIB: - git_error_set(GIT_ERROR_ZLIB, - "Buffer error when writing out ZLib data"); - return -1; - - default: - return 0; - } -} - -static int lock_file(git_filebuf *file, int flags, mode_t mode) -{ - if (git_fs_path_exists(file->path_lock) == true) { - git_error_clear(); /* actual OS error code just confuses */ - git_error_set(GIT_ERROR_OS, - "failed to lock file '%s' for writing", file->path_lock); - return GIT_ELOCKED; - } - - /* create path to the file buffer is required */ - if (flags & GIT_FILEBUF_CREATE_LEADING_DIRS) { - /* XXX: Should dirmode here be configurable? Or is 0777 always fine? */ - file->fd = git_futils_creat_locked_withpath(file->path_lock, 0777, mode); - } else { - file->fd = git_futils_creat_locked(file->path_lock, mode); - } - - if (file->fd < 0) - return file->fd; - - file->fd_is_open = true; - - if ((flags & GIT_FILEBUF_APPEND) && git_fs_path_exists(file->path_original) == true) { - git_file source; - char buffer[GIT_BUFSIZE_FILEIO]; - ssize_t read_bytes; - int error = 0; - - source = p_open(file->path_original, O_RDONLY); - if (source < 0) { - git_error_set(GIT_ERROR_OS, - "failed to open file '%s' for reading", - file->path_original); - return -1; - } - - while ((read_bytes = p_read(source, buffer, sizeof(buffer))) > 0) { - if ((error = p_write(file->fd, buffer, read_bytes)) < 0) - break; - if (file->compute_digest) - git_hash_update(&file->digest, buffer, read_bytes); - } - - p_close(source); - - if (read_bytes < 0) { - git_error_set(GIT_ERROR_OS, "failed to read file '%s'", file->path_original); - return -1; - } else if (error < 0) { - git_error_set(GIT_ERROR_OS, "failed to write file '%s'", file->path_lock); - return -1; - } - } - - return 0; -} - -void git_filebuf_cleanup(git_filebuf *file) -{ - if (file->fd_is_open && file->fd >= 0) - p_close(file->fd); - - if (file->created_lock && !file->did_rename && file->path_lock && git_fs_path_exists(file->path_lock)) - p_unlink(file->path_lock); - - if (file->compute_digest) { - git_hash_ctx_cleanup(&file->digest); - file->compute_digest = 0; - } - - if (file->buffer) - git__free(file->buffer); - - /* use the presence of z_buf to decide if we need to deflateEnd */ - if (file->z_buf) { - git__free(file->z_buf); - deflateEnd(&file->zs); - } - - if (file->path_original) - git__free(file->path_original); - if (file->path_lock) - git__free(file->path_lock); - - memset(file, 0x0, sizeof(git_filebuf)); - file->fd = -1; -} - -GIT_INLINE(int) flush_buffer(git_filebuf *file) -{ - int result = file->write(file, file->buffer, file->buf_pos); - file->buf_pos = 0; - return result; -} - -int git_filebuf_flush(git_filebuf *file) -{ - return flush_buffer(file); -} - -static int write_normal(git_filebuf *file, void *source, size_t len) -{ - if (len > 0) { - if (p_write(file->fd, (void *)source, len) < 0) { - file->last_error = BUFERR_WRITE; - return -1; - } - - if (file->compute_digest) - git_hash_update(&file->digest, source, len); - } - - return 0; -} - -static int write_deflate(git_filebuf *file, void *source, size_t len) -{ - z_stream *zs = &file->zs; - - if (len > 0 || file->flush_mode == Z_FINISH) { - zs->next_in = source; - zs->avail_in = (uInt)len; - - do { - size_t have; - - zs->next_out = file->z_buf; - zs->avail_out = (uInt)file->buf_size; - - if (deflate(zs, file->flush_mode) == Z_STREAM_ERROR) { - file->last_error = BUFERR_ZLIB; - return -1; - } - - have = file->buf_size - (size_t)zs->avail_out; - - if (p_write(file->fd, file->z_buf, have) < 0) { - file->last_error = BUFERR_WRITE; - return -1; - } - - } while (zs->avail_out == 0); - - GIT_ASSERT(zs->avail_in == 0); - - if (file->compute_digest) - git_hash_update(&file->digest, source, len); - } - - return 0; -} - -#define MAX_SYMLINK_DEPTH 5 - -static int resolve_symlink(git_str *out, const char *path) -{ - int i, error, root; - ssize_t ret; - struct stat st; - git_str curpath = GIT_STR_INIT, target = GIT_STR_INIT; - - if ((error = git_str_grow(&target, GIT_PATH_MAX + 1)) < 0 || - (error = git_str_puts(&curpath, path)) < 0) - return error; - - for (i = 0; i < MAX_SYMLINK_DEPTH; i++) { - error = p_lstat(curpath.ptr, &st); - if (error < 0 && errno == ENOENT) { - error = git_str_puts(out, curpath.ptr); - goto cleanup; - } - - if (error < 0) { - git_error_set(GIT_ERROR_OS, "failed to stat '%s'", curpath.ptr); - error = -1; - goto cleanup; - } - - if (!S_ISLNK(st.st_mode)) { - error = git_str_puts(out, curpath.ptr); - goto cleanup; - } - - ret = p_readlink(curpath.ptr, target.ptr, GIT_PATH_MAX); - if (ret < 0) { - git_error_set(GIT_ERROR_OS, "failed to read symlink '%s'", curpath.ptr); - error = -1; - goto cleanup; - } - - if (ret == GIT_PATH_MAX) { - git_error_set(GIT_ERROR_INVALID, "symlink target too long"); - error = -1; - goto cleanup; - } - - /* readlink(2) won't NUL-terminate for us */ - target.ptr[ret] = '\0'; - target.size = ret; - - root = git_fs_path_root(target.ptr); - if (root >= 0) { - if ((error = git_str_sets(&curpath, target.ptr)) < 0) - goto cleanup; - } else { - git_str dir = GIT_STR_INIT; - - if ((error = git_fs_path_dirname_r(&dir, curpath.ptr)) < 0) - goto cleanup; - - git_str_swap(&curpath, &dir); - git_str_dispose(&dir); - - if ((error = git_fs_path_apply_relative(&curpath, target.ptr)) < 0) - goto cleanup; - } - } - - git_error_set(GIT_ERROR_INVALID, "maximum symlink depth reached"); - error = -1; - -cleanup: - git_str_dispose(&curpath); - git_str_dispose(&target); - return error; -} - -int git_filebuf_open(git_filebuf *file, const char *path, int flags, mode_t mode) -{ - return git_filebuf_open_withsize(file, path, flags, mode, WRITE_BUFFER_SIZE); -} - -int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mode_t mode, size_t size) -{ - int compression, error = -1; - size_t path_len, alloc_len; - - GIT_ASSERT_ARG(file); - GIT_ASSERT_ARG(path); - GIT_ASSERT(file->buffer == NULL); - - memset(file, 0x0, sizeof(git_filebuf)); - - if (flags & GIT_FILEBUF_DO_NOT_BUFFER) - file->do_not_buffer = true; - - if (flags & GIT_FILEBUF_FSYNC) - file->do_fsync = true; - - file->buf_size = size; - file->buf_pos = 0; - file->fd = -1; - file->last_error = BUFERR_OK; - - /* Allocate the main cache buffer */ - if (!file->do_not_buffer) { - file->buffer = git__malloc(file->buf_size); - GIT_ERROR_CHECK_ALLOC(file->buffer); - } - - /* If we are hashing on-write, allocate a new hash context */ - if (flags & GIT_FILEBUF_HASH_SHA1) { - file->compute_digest = 1; - - if (git_hash_ctx_init(&file->digest, GIT_HASH_ALGORITHM_SHA1) < 0) - goto cleanup; - } else if (flags & GIT_FILEBUF_HASH_SHA256) { - file->compute_digest = 1; - - if (git_hash_ctx_init(&file->digest, GIT_HASH_ALGORITHM_SHA256) < 0) - goto cleanup; - } - - compression = flags >> GIT_FILEBUF_DEFLATE_SHIFT; - - /* If we are deflating on-write, */ - if (compression != 0) { - /* Initialize the ZLib stream */ - if (deflateInit(&file->zs, compression) != Z_OK) { - git_error_set(GIT_ERROR_ZLIB, "failed to initialize zlib"); - goto cleanup; - } - - /* Allocate the Zlib cache buffer */ - file->z_buf = git__malloc(file->buf_size); - GIT_ERROR_CHECK_ALLOC(file->z_buf); - - /* Never flush */ - file->flush_mode = Z_NO_FLUSH; - file->write = &write_deflate; - } else { - file->write = &write_normal; - } - - /* If we are writing to a temp file */ - if (flags & GIT_FILEBUF_TEMPORARY) { - git_str tmp_path = GIT_STR_INIT; - - /* Open the file as temporary for locking */ - file->fd = git_futils_mktmp(&tmp_path, path, mode); - - if (file->fd < 0) { - git_str_dispose(&tmp_path); - goto cleanup; - } - file->fd_is_open = true; - file->created_lock = true; - - /* No original path */ - file->path_original = NULL; - file->path_lock = git_str_detach(&tmp_path); - GIT_ERROR_CHECK_ALLOC(file->path_lock); - } else { - git_str resolved_path = GIT_STR_INIT; - - if ((error = resolve_symlink(&resolved_path, path)) < 0) - goto cleanup; - - /* Save the original path of the file */ - path_len = resolved_path.size; - file->path_original = git_str_detach(&resolved_path); - - /* create the locking path by appending ".lock" to the original */ - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, path_len, GIT_FILELOCK_EXTLENGTH); - file->path_lock = git__malloc(alloc_len); - GIT_ERROR_CHECK_ALLOC(file->path_lock); - - memcpy(file->path_lock, file->path_original, path_len); - memcpy(file->path_lock + path_len, GIT_FILELOCK_EXTENSION, GIT_FILELOCK_EXTLENGTH); - - if (git_fs_path_isdir(file->path_original)) { - git_error_set(GIT_ERROR_FILESYSTEM, "path '%s' is a directory", file->path_original); - error = GIT_EDIRECTORY; - goto cleanup; - } - - /* open the file for locking */ - if ((error = lock_file(file, flags, mode)) < 0) - goto cleanup; - - file->created_lock = true; - } - - return 0; - -cleanup: - git_filebuf_cleanup(file); - return error; -} - -int git_filebuf_hash(unsigned char *out, git_filebuf *file) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(file); - GIT_ASSERT_ARG(file->compute_digest); - - flush_buffer(file); - - if (verify_last_error(file) < 0) - return -1; - - git_hash_final(out, &file->digest); - git_hash_ctx_cleanup(&file->digest); - file->compute_digest = 0; - - return 0; -} - -int git_filebuf_commit_at(git_filebuf *file, const char *path) -{ - git__free(file->path_original); - file->path_original = git__strdup(path); - GIT_ERROR_CHECK_ALLOC(file->path_original); - - return git_filebuf_commit(file); -} - -int git_filebuf_commit(git_filebuf *file) -{ - /* temporary files cannot be committed */ - GIT_ASSERT_ARG(file); - GIT_ASSERT(file->path_original); - - file->flush_mode = Z_FINISH; - flush_buffer(file); - - if (verify_last_error(file) < 0) - goto on_error; - - file->fd_is_open = false; - - if (file->do_fsync && p_fsync(file->fd) < 0) { - git_error_set(GIT_ERROR_OS, "failed to fsync '%s'", file->path_lock); - goto on_error; - } - - if (p_close(file->fd) < 0) { - git_error_set(GIT_ERROR_OS, "failed to close file at '%s'", file->path_lock); - goto on_error; - } - - file->fd = -1; - - if (p_rename(file->path_lock, file->path_original) < 0) { - git_error_set(GIT_ERROR_OS, "failed to rename lockfile to '%s'", file->path_original); - goto on_error; - } - - if (file->do_fsync && git_futils_fsync_parent(file->path_original) < 0) - goto on_error; - - file->did_rename = true; - - git_filebuf_cleanup(file); - return 0; - -on_error: - git_filebuf_cleanup(file); - return -1; -} - -GIT_INLINE(void) add_to_cache(git_filebuf *file, const void *buf, size_t len) -{ - memcpy(file->buffer + file->buf_pos, buf, len); - file->buf_pos += len; -} - -int git_filebuf_write(git_filebuf *file, const void *buff, size_t len) -{ - const unsigned char *buf = buff; - - ENSURE_BUF_OK(file); - - if (file->do_not_buffer) - return file->write(file, (void *)buff, len); - - for (;;) { - size_t space_left = file->buf_size - file->buf_pos; - - /* cache if it's small */ - if (space_left > len) { - add_to_cache(file, buf, len); - return 0; - } - - add_to_cache(file, buf, space_left); - if (flush_buffer(file) < 0) - return -1; - - len -= space_left; - buf += space_left; - } -} - -int git_filebuf_reserve(git_filebuf *file, void **buffer, size_t len) -{ - size_t space_left = file->buf_size - file->buf_pos; - - *buffer = NULL; - - ENSURE_BUF_OK(file); - - if (len > file->buf_size) { - file->last_error = BUFERR_MEM; - return -1; - } - - if (space_left <= len) { - if (flush_buffer(file) < 0) - return -1; - } - - *buffer = (file->buffer + file->buf_pos); - file->buf_pos += len; - - return 0; -} - -int git_filebuf_printf(git_filebuf *file, const char *format, ...) -{ - va_list arglist; - size_t space_left, len, alloclen; - int written, res; - char *tmp_buffer; - - ENSURE_BUF_OK(file); - - space_left = file->buf_size - file->buf_pos; - - do { - va_start(arglist, format); - written = p_vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist); - va_end(arglist); - - if (written < 0) { - file->last_error = BUFERR_MEM; - return -1; - } - - len = written; - if (len + 1 <= space_left) { - file->buf_pos += len; - return 0; - } - - if (flush_buffer(file) < 0) - return -1; - - space_left = file->buf_size - file->buf_pos; - - } while (len + 1 <= space_left); - - if (GIT_ADD_SIZET_OVERFLOW(&alloclen, len, 1) || - !(tmp_buffer = git__malloc(alloclen))) { - file->last_error = BUFERR_MEM; - return -1; - } - - va_start(arglist, format); - written = p_vsnprintf(tmp_buffer, len + 1, format, arglist); - va_end(arglist); - - if (written < 0) { - git__free(tmp_buffer); - file->last_error = BUFERR_MEM; - return -1; - } - - res = git_filebuf_write(file, tmp_buffer, len); - git__free(tmp_buffer); - - return res; -} - -int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file) -{ - int res; - struct stat st; - - if (file->fd_is_open) - res = p_fstat(file->fd, &st); - else - res = p_stat(file->path_original, &st); - - if (res < 0) { - git_error_set(GIT_ERROR_OS, "could not get stat info for '%s'", - file->path_original); - return res; - } - - if (mtime) - *mtime = st.st_mtime; - if (size) - *size = (size_t)st.st_size; - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/filebuf.h b/vendor/libgit2-sys/libgit2/src/util/filebuf.h deleted file mode 100644 index e23b9ed..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/filebuf.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_filebuf_h__ -#define INCLUDE_filebuf_h__ - -#include "git2_util.h" - -#include "futils.h" -#include "hash.h" -#include - -#ifdef GIT_THREADS -# define GIT_FILEBUF_THREADS -#endif - -#define GIT_FILEBUF_HASH_SHA1 (1 << 0) -#define GIT_FILEBUF_HASH_SHA256 (1 << 1) -#define GIT_FILEBUF_APPEND (1 << 2) -#define GIT_FILEBUF_CREATE_LEADING_DIRS (1 << 3) -#define GIT_FILEBUF_TEMPORARY (1 << 4) -#define GIT_FILEBUF_DO_NOT_BUFFER (1 << 5) -#define GIT_FILEBUF_FSYNC (1 << 6) -#define GIT_FILEBUF_DEFLATE_SHIFT (7) - -#define GIT_FILELOCK_EXTENSION ".lock\0" -#define GIT_FILELOCK_EXTLENGTH 6 - -typedef struct git_filebuf git_filebuf; -struct git_filebuf { - char *path_original; - char *path_lock; - - int (*write)(git_filebuf *file, void *source, size_t len); - - bool compute_digest; - git_hash_ctx digest; - - unsigned char *buffer; - unsigned char *z_buf; - - z_stream zs; - int flush_mode; - - size_t buf_size, buf_pos; - git_file fd; - bool fd_is_open; - bool created_lock; - bool did_rename; - bool do_not_buffer; - bool do_fsync; - int last_error; -}; - -#define GIT_FILEBUF_INIT {0} - -/* - * The git_filebuf object lifecycle is: - * - Allocate git_filebuf, preferably using GIT_FILEBUF_INIT. - * - * - Call git_filebuf_open() to initialize the filebuf for use. - * - * - Make as many calls to git_filebuf_write(), git_filebuf_printf(), - * git_filebuf_reserve() as you like. The error codes for these - * functions don't need to be checked. They are stored internally - * by the file buffer. - * - * - While you are writing, you may call git_filebuf_hash() to get - * the hash of all you have written so far. This function will - * fail if any of the previous writes to the buffer failed. - * - * - To close the git_filebuf, you may call git_filebuf_commit() or - * git_filebuf_commit_at() to save the file, or - * git_filebuf_cleanup() to abandon the file. All of these will - * free the git_filebuf object. Likewise, all of these will fail - * if any of the previous writes to the buffer failed, and set - * an error code accordingly. - */ -int git_filebuf_write(git_filebuf *lock, const void *buff, size_t len); -int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len); -int git_filebuf_printf(git_filebuf *file, const char *format, ...) GIT_FORMAT_PRINTF(2, 3); - -int git_filebuf_open(git_filebuf *lock, const char *path, int flags, mode_t mode); -int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mode_t mode, size_t size); -int git_filebuf_commit(git_filebuf *lock); -int git_filebuf_commit_at(git_filebuf *lock, const char *path); -void git_filebuf_cleanup(git_filebuf *lock); -int git_filebuf_hash(unsigned char *out, git_filebuf *file); -int git_filebuf_flush(git_filebuf *file); -int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file); - -GIT_INLINE(int) git_filebuf_hash_flags(git_hash_algorithm_t algorithm) -{ - switch (algorithm) { - case GIT_HASH_ALGORITHM_SHA1: - return GIT_FILEBUF_HASH_SHA1; - case GIT_HASH_ALGORITHM_SHA256: - return GIT_FILEBUF_HASH_SHA256; - default: - return 0; - } -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/fs_path.c b/vendor/libgit2-sys/libgit2/src/util/fs_path.c deleted file mode 100644 index 5b00b1b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/fs_path.c +++ /dev/null @@ -1,2137 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "fs_path.h" - -#include "git2_util.h" -#include "futils.h" -#include "posix.h" -#ifdef GIT_WIN32 -#include "win32/posix.h" -#include "win32/w32_buffer.h" -#include "win32/w32_util.h" -#include "win32/version.h" -#include -#else -#include -#endif -#include -#include - -#define ensure_error_set(code) do { \ - const git_error *e = git_error_last(); \ - if (!e || !e->message) \ - git_error_set(e ? e->klass : GIT_ERROR_CALLBACK, \ - "filesystem callback returned %d", code); \ - } while(0) - -static int dos_drive_prefix_length(const char *path) -{ - int i; - - /* - * Does it start with an ASCII letter (i.e. highest bit not set), - * followed by a colon? - */ - if (!(0x80 & (unsigned char)*path)) - return *path && path[1] == ':' ? 2 : 0; - - /* - * While drive letters must be letters of the English alphabet, it is - * possible to assign virtually _any_ Unicode character via `subst` as - * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff - * like this: - * - * subst ֍: %USERPROFILE%\Desktop - */ - for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++) - ; /* skip first UTF-8 character */ - return path[i] == ':' ? i + 1 : 0; -} - -#ifdef GIT_WIN32 -static bool looks_like_network_computer_name(const char *path, int pos) -{ - if (pos < 3) - return false; - - if (path[0] != '/' || path[1] != '/') - return false; - - while (pos-- > 2) { - if (path[pos] == '/') - return false; - } - - return true; -} -#endif - -/* - * Based on the Android implementation, BSD licensed. - * http://android.git.kernel.org/ - * - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -int git_fs_path_basename_r(git_str *buffer, const char *path) -{ - const char *endp, *startp; - int len, result; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - startp = "."; - len = 1; - goto Exit; - } - - /* Strip trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* All slashes becomes "/" */ - if (endp == path && *endp == '/') { - startp = "/"; - len = 1; - goto Exit; - } - - /* Find the start of the base */ - startp = endp; - while (startp > path && *(startp - 1) != '/') - startp--; - - /* Cast is safe because max path < max int */ - len = (int)(endp - startp + 1); - -Exit: - result = len; - - if (buffer != NULL && git_str_set(buffer, startp, len) < 0) - return -1; - - return result; -} - -/* - * Determine if the path is a Windows prefix and, if so, returns - * its actual length. If it is not a prefix, returns -1. - */ -static int win32_prefix_length(const char *path, int len) -{ -#ifndef GIT_WIN32 - GIT_UNUSED(path); - GIT_UNUSED(len); -#else - /* - * Mimic unix behavior where '/.git' returns '/': 'C:/.git' - * will return 'C:/' here - */ - if (dos_drive_prefix_length(path) == len) - return len; - - /* - * Similarly checks if we're dealing with a network computer name - * '//computername/.git' will return '//computername/' - */ - if (looks_like_network_computer_name(path, len)) - return len; -#endif - - return -1; -} - -/* - * Based on the Android implementation, BSD licensed. - * Check http://android.git.kernel.org/ - */ -int git_fs_path_dirname_r(git_str *buffer, const char *path) -{ - const char *endp; - int is_prefix = 0, len; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - path = "."; - len = 1; - goto Exit; - } - - /* Strip trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - if (endp - path + 1 > INT_MAX) { - git_error_set(GIT_ERROR_INVALID, "path too long"); - return -1; - } - - if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) { - is_prefix = 1; - goto Exit; - } - - /* Find the start of the dir */ - while (endp > path && *endp != '/') - endp--; - - /* Either the dir is "/" or there are no slashes */ - if (endp == path) { - path = (*endp == '/') ? "/" : "."; - len = 1; - goto Exit; - } - - do { - endp--; - } while (endp > path && *endp == '/'); - - if (endp - path + 1 > INT_MAX) { - git_error_set(GIT_ERROR_INVALID, "path too long"); - return -1; - } - - if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) { - is_prefix = 1; - goto Exit; - } - - /* Cast is safe because max path < max int */ - len = (int)(endp - path + 1); - -Exit: - if (buffer) { - if (git_str_set(buffer, path, len) < 0) - return -1; - if (is_prefix && git_str_putc(buffer, '/') < 0) - return -1; - } - - return len; -} - - -char *git_fs_path_dirname(const char *path) -{ - git_str buf = GIT_STR_INIT; - char *dirname; - - git_fs_path_dirname_r(&buf, path); - dirname = git_str_detach(&buf); - git_str_dispose(&buf); /* avoid memleak if error occurs */ - - return dirname; -} - -char *git_fs_path_basename(const char *path) -{ - git_str buf = GIT_STR_INIT; - char *basename; - - git_fs_path_basename_r(&buf, path); - basename = git_str_detach(&buf); - git_str_dispose(&buf); /* avoid memleak if error occurs */ - - return basename; -} - -size_t git_fs_path_basename_offset(git_str *buffer) -{ - ssize_t slash; - - if (!buffer || buffer->size <= 0) - return 0; - - slash = git_str_rfind_next(buffer, '/'); - - if (slash >= 0 && buffer->ptr[slash] == '/') - return (size_t)(slash + 1); - - return 0; -} - -int git_fs_path_root(const char *path) -{ - int offset = 0, prefix_len; - - /* Does the root of the path look like a windows drive ? */ - if ((prefix_len = dos_drive_prefix_length(path))) - offset += prefix_len; - -#ifdef GIT_WIN32 - /* Are we dealing with a windows network path? */ - else if ((path[0] == '/' && path[1] == '/' && path[2] != '/') || - (path[0] == '\\' && path[1] == '\\' && path[2] != '\\')) - { - offset += 2; - - /* Skip the computer name segment */ - while (path[offset] && path[offset] != '/' && path[offset] != '\\') - offset++; - } - - if (path[offset] == '\\') - return offset; -#endif - - if (path[offset] == '/') - return offset; - - return -1; /* Not a real error - signals that path is not rooted */ -} - -static void path_trim_slashes(git_str *path) -{ - int ceiling = git_fs_path_root(path->ptr) + 1; - - if (ceiling < 0) - return; - - while (path->size > (size_t)ceiling) { - if (path->ptr[path->size-1] != '/') - break; - - path->ptr[path->size-1] = '\0'; - path->size--; - } -} - -int git_fs_path_join_unrooted( - git_str *path_out, const char *path, const char *base, ssize_t *root_at) -{ - ssize_t root; - - GIT_ASSERT_ARG(path_out); - GIT_ASSERT_ARG(path); - - root = (ssize_t)git_fs_path_root(path); - - if (base != NULL && root < 0) { - if (git_str_joinpath(path_out, base, path) < 0) - return -1; - - root = (ssize_t)strlen(base); - } else { - if (git_str_sets(path_out, path) < 0) - return -1; - - if (root < 0) - root = 0; - else if (base) - git_fs_path_equal_or_prefixed(base, path, &root); - } - - if (root_at) - *root_at = root; - - return 0; -} - -void git_fs_path_squash_slashes(git_str *path) -{ - char *p, *q; - - if (path->size == 0) - return; - - for (p = path->ptr, q = path->ptr; *q; p++, q++) { - *p = *q; - - while (*q == '/' && *(q+1) == '/') { - path->size--; - q++; - } - } - - *p = '\0'; -} - -int git_fs_path_prettify(git_str *path_out, const char *path, const char *base) -{ - char buf[GIT_PATH_MAX]; - - GIT_ASSERT_ARG(path_out); - GIT_ASSERT_ARG(path); - - /* construct path if needed */ - if (base != NULL && git_fs_path_root(path) < 0) { - if (git_str_joinpath(path_out, base, path) < 0) - return -1; - path = path_out->ptr; - } - - if (p_realpath(path, buf) == NULL) { - /* git_error_set resets the errno when dealing with a GIT_ERROR_OS kind of error */ - int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1; - git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path); - - git_str_clear(path_out); - - return error; - } - - return git_str_sets(path_out, buf); -} - -int git_fs_path_prettify_dir(git_str *path_out, const char *path, const char *base) -{ - int error = git_fs_path_prettify(path_out, path, base); - return (error < 0) ? error : git_fs_path_to_dir(path_out); -} - -int git_fs_path_to_dir(git_str *path) -{ - if (path->asize > 0 && - git_str_len(path) > 0 && - path->ptr[git_str_len(path) - 1] != '/') - git_str_putc(path, '/'); - - return git_str_oom(path) ? -1 : 0; -} - -size_t git_fs_path_dirlen(const char *path) -{ - size_t len = strlen(path); - - while (len > 1 && path[len - 1] == '/') - len--; - - return len; -} - -void git_fs_path_string_to_dir(char *path, size_t size) -{ - size_t end = strlen(path); - - if (end && path[end - 1] != '/' && end < size) { - path[end] = '/'; - path[end + 1] = '\0'; - } -} - -int git__percent_decode(git_str *decoded_out, const char *input) -{ - int len, hi, lo, i; - - GIT_ASSERT_ARG(decoded_out); - GIT_ASSERT_ARG(input); - - len = (int)strlen(input); - git_str_clear(decoded_out); - - for(i = 0; i < len; i++) - { - char c = input[i]; - - if (c != '%') - goto append; - - if (i >= len - 2) - goto append; - - hi = git__fromhex(input[i + 1]); - lo = git__fromhex(input[i + 2]); - - if (hi < 0 || lo < 0) - goto append; - - c = (char)(hi << 4 | lo); - i += 2; - -append: - if (git_str_putc(decoded_out, c) < 0) - return -1; - } - - return 0; -} - -static int error_invalid_local_file_uri(const char *uri) -{ - git_error_set(GIT_ERROR_CONFIG, "'%s' is not a valid local file URI", uri); - return -1; -} - -static int local_file_url_prefixlen(const char *file_url) -{ - int len = -1; - - if (git__prefixcmp(file_url, "file://") == 0) { - if (file_url[7] == '/') - len = 8; - else if (git__prefixcmp(file_url + 7, "localhost/") == 0) - len = 17; - } - - return len; -} - -bool git_fs_path_is_local_file_url(const char *file_url) -{ - return (local_file_url_prefixlen(file_url) > 0); -} - -int git_fs_path_fromurl(git_str *local_path_out, const char *file_url) -{ - int offset; - - GIT_ASSERT_ARG(local_path_out); - GIT_ASSERT_ARG(file_url); - - if ((offset = local_file_url_prefixlen(file_url)) < 0 || - file_url[offset] == '\0' || file_url[offset] == '/') - return error_invalid_local_file_uri(file_url); - -#ifndef GIT_WIN32 - offset--; /* A *nix absolute path starts with a forward slash */ -#endif - - git_str_clear(local_path_out); - return git__percent_decode(local_path_out, file_url + offset); -} - -int git_fs_path_walk_up( - git_str *path, - const char *ceiling, - int (*cb)(void *data, const char *), - void *data) -{ - int error = 0; - git_str iter; - ssize_t stop = 0, scan; - char oldc = '\0'; - - GIT_ASSERT_ARG(path); - GIT_ASSERT_ARG(cb); - - if (ceiling != NULL) { - if (git__prefixcmp(path->ptr, ceiling) == 0) - stop = (ssize_t)strlen(ceiling); - else - stop = git_str_len(path); - } - scan = git_str_len(path); - - /* empty path: yield only once */ - if (!scan) { - error = cb(data, ""); - if (error) - ensure_error_set(error); - return error; - } - - iter.ptr = path->ptr; - iter.size = git_str_len(path); - iter.asize = path->asize; - - while (scan >= stop) { - error = cb(data, iter.ptr); - iter.ptr[scan] = oldc; - - if (error) { - ensure_error_set(error); - break; - } - - scan = git_str_rfind_next(&iter, '/'); - if (scan >= 0) { - scan++; - oldc = iter.ptr[scan]; - iter.size = scan; - iter.ptr[scan] = '\0'; - } - } - - if (scan >= 0) - iter.ptr[scan] = oldc; - - /* relative path: yield for the last component */ - if (!error && stop == 0 && iter.ptr[0] != '/') { - error = cb(data, ""); - if (error) - ensure_error_set(error); - } - - return error; -} - -bool git_fs_path_exists(const char *path) -{ - GIT_ASSERT_ARG_WITH_RETVAL(path, false); - return p_access(path, F_OK) == 0; -} - -bool git_fs_path_isdir(const char *path) -{ - struct stat st; - if (p_stat(path, &st) < 0) - return false; - - return S_ISDIR(st.st_mode) != 0; -} - -bool git_fs_path_isfile(const char *path) -{ - struct stat st; - - GIT_ASSERT_ARG_WITH_RETVAL(path, false); - if (p_stat(path, &st) < 0) - return false; - - return S_ISREG(st.st_mode) != 0; -} - -#ifdef GIT_WIN32 - -bool git_fs_path_isexecutable(const char *path) -{ - struct stat st; - - GIT_ASSERT_ARG_WITH_RETVAL(path, false); - - if (git__suffixcmp_icase(path, ".exe") != 0 && - git__suffixcmp_icase(path, ".cmd") != 0) - return false; - - return (p_stat(path, &st) == 0); -} - -#else - -bool git_fs_path_isexecutable(const char *path) -{ - struct stat st; - - GIT_ASSERT_ARG_WITH_RETVAL(path, false); - if (p_stat(path, &st) < 0) - return false; - - return S_ISREG(st.st_mode) != 0 && - ((st.st_mode & S_IXUSR) != 0); -} - -#endif - -bool git_fs_path_islink(const char *path) -{ - struct stat st; - - GIT_ASSERT_ARG_WITH_RETVAL(path, false); - if (p_lstat(path, &st) < 0) - return false; - - return S_ISLNK(st.st_mode) != 0; -} - -#ifdef GIT_WIN32 - -bool git_fs_path_is_empty_dir(const char *path) -{ - git_win32_path filter_w; - bool empty = false; - - if (git_win32__findfirstfile_filter(filter_w, path)) { - WIN32_FIND_DATAW findData; - HANDLE hFind = FindFirstFileW(filter_w, &findData); - - /* FindFirstFile will fail if there are no children to the given - * path, which can happen if the given path is a file (and obviously - * has no children) or if the given path is an empty mount point. - * (Most directories have at least directory entries '.' and '..', - * but ridiculously another volume mounted in another drive letter's - * path space do not, and thus have nothing to enumerate.) If - * FindFirstFile fails, check if this is a directory-like thing - * (a mount point). - */ - if (hFind == INVALID_HANDLE_VALUE) - return git_fs_path_isdir(path); - - /* If the find handle was created successfully, then it's a directory */ - empty = true; - - do { - /* Allow the enumeration to return . and .. and still be considered - * empty. In the special case of drive roots (i.e. C:\) where . and - * .. do not occur, we can still consider the path to be an empty - * directory if there's nothing there. */ - if (!git_fs_path_is_dot_or_dotdotW(findData.cFileName)) { - empty = false; - break; - } - } while (FindNextFileW(hFind, &findData)); - - FindClose(hFind); - } - - return empty; -} - -#else - -static int path_found_entry(void *payload, git_str *path) -{ - GIT_UNUSED(payload); - return !git_fs_path_is_dot_or_dotdot(path->ptr); -} - -bool git_fs_path_is_empty_dir(const char *path) -{ - int error; - git_str dir = GIT_STR_INIT; - - if (!git_fs_path_isdir(path)) - return false; - - if ((error = git_str_sets(&dir, path)) != 0) - git_error_clear(); - else - error = git_fs_path_direach(&dir, 0, path_found_entry, NULL); - - git_str_dispose(&dir); - - return !error; -} - -#endif - -int git_fs_path_set_error(int errno_value, const char *path, const char *action) -{ - switch (errno_value) { - case ENOENT: - case ENOTDIR: - git_error_set(GIT_ERROR_OS, "could not find '%s' to %s", path, action); - return GIT_ENOTFOUND; - - case EINVAL: - case ENAMETOOLONG: - git_error_set(GIT_ERROR_OS, "invalid path for filesystem '%s'", path); - return GIT_EINVALIDSPEC; - - case EEXIST: - git_error_set(GIT_ERROR_OS, "failed %s - '%s' already exists", action, path); - return GIT_EEXISTS; - - case EACCES: - git_error_set(GIT_ERROR_OS, "failed %s - '%s' is locked", action, path); - return GIT_ELOCKED; - - default: - git_error_set(GIT_ERROR_OS, "could not %s '%s'", action, path); - return -1; - } -} - -int git_fs_path_lstat(const char *path, struct stat *st) -{ - if (p_lstat(path, st) == 0) - return 0; - - return git_fs_path_set_error(errno, path, "stat"); -} - -static bool _check_dir_contents( - git_str *dir, - const char *sub, - bool (*predicate)(const char *)) -{ - bool result; - size_t dir_size = git_str_len(dir); - size_t sub_size = strlen(sub); - size_t alloc_size; - - /* leave base valid even if we could not make space for subdir */ - if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) || - GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) || - git_str_try_grow(dir, alloc_size, false) < 0) - return false; - - /* save excursion */ - if (git_str_joinpath(dir, dir->ptr, sub) < 0) - return false; - - result = predicate(dir->ptr); - - /* restore path */ - git_str_truncate(dir, dir_size); - return result; -} - -bool git_fs_path_contains(git_str *dir, const char *item) -{ - return _check_dir_contents(dir, item, &git_fs_path_exists); -} - -bool git_fs_path_contains_dir(git_str *base, const char *subdir) -{ - return _check_dir_contents(base, subdir, &git_fs_path_isdir); -} - -bool git_fs_path_contains_file(git_str *base, const char *file) -{ - return _check_dir_contents(base, file, &git_fs_path_isfile); -} - -int git_fs_path_find_dir(git_str *dir) -{ - int error = 0; - char buf[GIT_PATH_MAX]; - - if (p_realpath(dir->ptr, buf) != NULL) - error = git_str_sets(dir, buf); - - /* call dirname if this is not a directory */ - if (!error) /* && git_fs_path_isdir(dir->ptr) == false) */ - error = (git_fs_path_dirname_r(dir, dir->ptr) < 0) ? -1 : 0; - - if (!error) - error = git_fs_path_to_dir(dir); - - return error; -} - -int git_fs_path_resolve_relative(git_str *path, size_t ceiling) -{ - char *base, *to, *from, *next; - size_t len; - - GIT_ERROR_CHECK_ALLOC_STR(path); - - if (ceiling > path->size) - ceiling = path->size; - - /* recognize drive prefixes, etc. that should not be backed over */ - if (ceiling == 0) - ceiling = git_fs_path_root(path->ptr) + 1; - - /* recognize URL prefixes that should not be backed over */ - if (ceiling == 0) { - for (next = path->ptr; *next && git__isalpha(*next); ++next); - if (next[0] == ':' && next[1] == '/' && next[2] == '/') - ceiling = (next + 3) - path->ptr; - } - - base = to = from = path->ptr + ceiling; - - while (*from) { - for (next = from; *next && *next != '/'; ++next); - - len = next - from; - - if (len == 1 && from[0] == '.') - /* do nothing with singleton dot */; - - else if (len == 2 && from[0] == '.' && from[1] == '.') { - /* error out if trying to up one from a hard base */ - if (to == base && ceiling != 0) { - git_error_set(GIT_ERROR_INVALID, - "cannot strip root component off url"); - return -1; - } - - /* no more path segments to strip, - * use '../' as a new base path */ - if (to == base) { - if (*next == '/') - len++; - - if (to != from) - memmove(to, from, len); - - to += len; - /* this is now the base, can't back up from a - * relative prefix */ - base = to; - } else { - /* back up a path segment */ - while (to > base && to[-1] == '/') to--; - while (to > base && to[-1] != '/') to--; - } - } else { - if (*next == '/' && *from != '/') - len++; - - if (to != from) - memmove(to, from, len); - - to += len; - } - - from += len; - - while (*from == '/') from++; - } - - *to = '\0'; - - path->size = to - path->ptr; - - return 0; -} - -int git_fs_path_apply_relative(git_str *target, const char *relpath) -{ - return git_str_joinpath(target, git_str_cstr(target), relpath) || - git_fs_path_resolve_relative(target, 0); -} - -int git_fs_path_cmp( - const char *name1, size_t len1, int isdir1, - const char *name2, size_t len2, int isdir2, - int (*compare)(const char *, const char *, size_t)) -{ - unsigned char c1, c2; - size_t len = len1 < len2 ? len1 : len2; - int cmp; - - cmp = compare(name1, name2, len); - if (cmp) - return cmp; - - c1 = name1[len]; - c2 = name2[len]; - - if (c1 == '\0' && isdir1) - c1 = '/'; - - if (c2 == '\0' && isdir2) - c2 = '/'; - - return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; -} - -size_t git_fs_path_common_dirlen(const char *one, const char *two) -{ - const char *p, *q, *dirsep = NULL; - - for (p = one, q = two; *p && *q; p++, q++) { - if (*p == '/' && *q == '/') - dirsep = p; - else if (*p != *q) - break; - } - - return dirsep ? (dirsep - one) + 1 : 0; -} - -int git_fs_path_make_relative(git_str *path, const char *parent) -{ - const char *p, *q, *p_dirsep, *q_dirsep; - size_t plen = path->size, newlen, alloclen, depth = 1, i, offset; - - for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) { - if (*p == '/' && *q == '/') { - p_dirsep = p; - q_dirsep = q; - } - else if (*p != *q) - break; - } - - /* need at least 1 common path segment */ - if ((p_dirsep == path->ptr || q_dirsep == parent) && - (*p_dirsep != '/' || *q_dirsep != '/')) { - git_error_set(GIT_ERROR_INVALID, - "%s is not a parent of %s", parent, path->ptr); - return GIT_ENOTFOUND; - } - - if (*p == '/' && !*q) - p++; - else if (!*p && *q == '/') - q++; - else if (!*p && !*q) - return git_str_clear(path), 0; - else { - p = p_dirsep + 1; - q = q_dirsep + 1; - } - - plen -= (p - path->ptr); - - if (!*q) - return git_str_set(path, p, plen); - - for (; (q = strchr(q, '/')) && *(q + 1); q++) - depth++; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3); - GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen); - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1); - - /* save the offset as we might realllocate the pointer */ - offset = p - path->ptr; - if (git_str_try_grow(path, alloclen, 1) < 0) - return -1; - p = path->ptr + offset; - - memmove(path->ptr + (depth * 3), p, plen + 1); - - for (i = 0; i < depth; i++) - memcpy(path->ptr + (i * 3), "../", 3); - - path->size = newlen; - return 0; -} - -bool git_fs_path_has_non_ascii(const char *path, size_t pathlen) -{ - const uint8_t *scan = (const uint8_t *)path, *end; - - for (end = scan + pathlen; scan < end; ++scan) - if (*scan & 0x80) - return true; - - return false; -} - -#ifdef GIT_USE_ICONV - -int git_fs_path_iconv_init_precompose(git_fs_path_iconv_t *ic) -{ - git_str_init(&ic->buf, 0); - ic->map = iconv_open(GIT_PATH_REPO_ENCODING, GIT_PATH_NATIVE_ENCODING); - return 0; -} - -void git_fs_path_iconv_clear(git_fs_path_iconv_t *ic) -{ - if (ic) { - if (ic->map != (iconv_t)-1) - iconv_close(ic->map); - git_str_dispose(&ic->buf); - } -} - -int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen) -{ - char *nfd = (char*)*in, *nfc; - size_t nfdlen = *inlen, nfclen, wantlen = nfdlen, alloclen, rv; - int retry = 1; - - if (!ic || ic->map == (iconv_t)-1 || - !git_fs_path_has_non_ascii(*in, *inlen)) - return 0; - - git_str_clear(&ic->buf); - - while (1) { - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1); - if (git_str_grow(&ic->buf, alloclen) < 0) - return -1; - - nfc = ic->buf.ptr + ic->buf.size; - nfclen = ic->buf.asize - ic->buf.size; - - rv = iconv(ic->map, &nfd, &nfdlen, &nfc, &nfclen); - - ic->buf.size = (nfc - ic->buf.ptr); - - if (rv != (size_t)-1) - break; - - /* if we cannot convert the data (probably because iconv thinks - * it is not valid UTF-8 source data), then use original data - */ - if (errno != E2BIG) - return 0; - - /* make space for 2x the remaining data to be converted - * (with per retry overhead to avoid infinite loops) - */ - wantlen = ic->buf.size + max(nfclen, nfdlen) * 2 + (size_t)(retry * 4); - - if (retry++ > 4) - goto fail; - } - - ic->buf.ptr[ic->buf.size] = '\0'; - - *in = ic->buf.ptr; - *inlen = ic->buf.size; - - return 0; - -fail: - git_error_set(GIT_ERROR_OS, "unable to convert unicode path data"); - return -1; -} - -static const char *nfc_file = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D"; -static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D"; - -/* Check if the platform is decomposing unicode data for us. We will - * emulate core Git and prefer to use precomposed unicode data internally - * on these platforms, composing the decomposed unicode on the fly. - * - * This mainly happens on the Mac where HDFS stores filenames as - * decomposed unicode. Even on VFAT and SAMBA file systems, the Mac will - * return decomposed unicode from readdir() even when the actual - * filesystem is storing precomposed unicode. - */ -bool git_fs_path_does_decompose_unicode(const char *root) -{ - git_str nfc_path = GIT_STR_INIT; - git_str nfd_path = GIT_STR_INIT; - int fd; - bool found_decomposed = false; - size_t orig_len; - const char *trailer; - - /* Create a file using a precomposed path and then try to find it - * using the decomposed name. If the lookup fails, then we will mark - * that we should precompose unicode for this repository. - */ - if (git_str_joinpath(&nfc_path, root, nfc_file) < 0) - goto done; - - /* record original path length before trailer */ - orig_len = nfc_path.size; - - if ((fd = git_futils_mktmp(&nfc_path, nfc_path.ptr, 0666)) < 0) - goto done; - p_close(fd); - - trailer = nfc_path.ptr + orig_len; - - /* try to look up as NFD path */ - if (git_str_joinpath(&nfd_path, root, nfd_file) < 0 || - git_str_puts(&nfd_path, trailer) < 0) - goto done; - - found_decomposed = git_fs_path_exists(nfd_path.ptr); - - /* remove temporary file (using original precomposed path) */ - (void)p_unlink(nfc_path.ptr); - -done: - git_str_dispose(&nfc_path); - git_str_dispose(&nfd_path); - return found_decomposed; -} - -#else - -bool git_fs_path_does_decompose_unicode(const char *root) -{ - GIT_UNUSED(root); - return false; -} - -#endif - -#if defined(__sun) || defined(__GNU__) -typedef char path_dirent_data[sizeof(struct dirent) + FILENAME_MAX + 1]; -#else -typedef struct dirent path_dirent_data; -#endif - -int git_fs_path_direach( - git_str *path, - uint32_t flags, - int (*fn)(void *, git_str *), - void *arg) -{ - int error = 0; - ssize_t wd_len; - DIR *dir; - struct dirent *de; - -#ifdef GIT_USE_ICONV - git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT; -#endif - - GIT_UNUSED(flags); - - if (git_fs_path_to_dir(path) < 0) - return -1; - - wd_len = git_str_len(path); - - if ((dir = opendir(path->ptr)) == NULL) { - git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr); - if (errno == ENOENT) - return GIT_ENOTFOUND; - - return -1; - } - -#ifdef GIT_USE_ICONV - if ((flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0) - (void)git_fs_path_iconv_init_precompose(&ic); -#endif - - while ((de = readdir(dir)) != NULL) { - const char *de_path = de->d_name; - size_t de_len = strlen(de_path); - - if (git_fs_path_is_dot_or_dotdot(de_path)) - continue; - -#ifdef GIT_USE_ICONV - if ((error = git_fs_path_iconv(&ic, &de_path, &de_len)) < 0) - break; -#endif - - if ((error = git_str_put(path, de_path, de_len)) < 0) - break; - - git_error_clear(); - error = fn(arg, path); - - git_str_truncate(path, wd_len); /* restore path */ - - /* Only set our own error if the callback did not set one already */ - if (error != 0) { - if (!git_error_last()) - ensure_error_set(error); - - break; - } - } - - closedir(dir); - -#ifdef GIT_USE_ICONV - git_fs_path_iconv_clear(&ic); -#endif - - return error; -} - -#if defined(GIT_WIN32) && !defined(__MINGW32__) - -/* Using _FIND_FIRST_EX_LARGE_FETCH may increase performance in Windows 7 - * and better. - */ -#ifndef FIND_FIRST_EX_LARGE_FETCH -# define FIND_FIRST_EX_LARGE_FETCH 2 -#endif - -int git_fs_path_diriter_init( - git_fs_path_diriter *diriter, - const char *path, - unsigned int flags) -{ - git_win32_path path_filter; - - static int is_win7_or_later = -1; - if (is_win7_or_later < 0) - is_win7_or_later = git_has_win32_version(6, 1, 0); - - GIT_ASSERT_ARG(diriter); - GIT_ASSERT_ARG(path); - - memset(diriter, 0, sizeof(git_fs_path_diriter)); - diriter->handle = INVALID_HANDLE_VALUE; - - if (git_str_puts(&diriter->path_utf8, path) < 0) - return -1; - - path_trim_slashes(&diriter->path_utf8); - - if (diriter->path_utf8.size == 0) { - git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path); - return -1; - } - - if ((diriter->parent_len = git_win32_path_from_utf8(diriter->path, diriter->path_utf8.ptr)) < 0 || - !git_win32__findfirstfile_filter(path_filter, diriter->path_utf8.ptr)) { - git_error_set(GIT_ERROR_OS, "could not parse the directory path '%s'", path); - return -1; - } - - diriter->handle = FindFirstFileExW( - path_filter, - is_win7_or_later ? FindExInfoBasic : FindExInfoStandard, - &diriter->current, - FindExSearchNameMatch, - NULL, - is_win7_or_later ? FIND_FIRST_EX_LARGE_FETCH : 0); - - if (diriter->handle == INVALID_HANDLE_VALUE) { - git_error_set(GIT_ERROR_OS, "could not open directory '%s'", path); - return -1; - } - - diriter->parent_utf8_len = diriter->path_utf8.size; - diriter->flags = flags; - return 0; -} - -static int diriter_update_paths(git_fs_path_diriter *diriter) -{ - size_t filename_len, path_len; - - filename_len = wcslen(diriter->current.cFileName); - - if (GIT_ADD_SIZET_OVERFLOW(&path_len, diriter->parent_len, filename_len) || - GIT_ADD_SIZET_OVERFLOW(&path_len, path_len, 2)) - return -1; - - if (path_len > GIT_WIN_PATH_UTF16) { - git_error_set(GIT_ERROR_FILESYSTEM, - "invalid path '%.*ls\\%ls' (path too long)", - diriter->parent_len, diriter->path, diriter->current.cFileName); - return -1; - } - - diriter->path[diriter->parent_len] = L'\\'; - memcpy(&diriter->path[diriter->parent_len+1], - diriter->current.cFileName, filename_len * sizeof(wchar_t)); - diriter->path[path_len-1] = L'\0'; - - git_str_truncate(&diriter->path_utf8, diriter->parent_utf8_len); - - if (diriter->parent_utf8_len > 0 && - diriter->path_utf8.ptr[diriter->parent_utf8_len-1] != '/') - git_str_putc(&diriter->path_utf8, '/'); - - git_str_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len); - - if (git_str_oom(&diriter->path_utf8)) - return -1; - - return 0; -} - -int git_fs_path_diriter_next(git_fs_path_diriter *diriter) -{ - bool skip_dot = !(diriter->flags & GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT); - - do { - /* Our first time through, we already have the data from - * FindFirstFileW. Use it, otherwise get the next file. - */ - if (!diriter->needs_next) - diriter->needs_next = 1; - else if (!FindNextFileW(diriter->handle, &diriter->current)) - return GIT_ITEROVER; - } while (skip_dot && git_fs_path_is_dot_or_dotdotW(diriter->current.cFileName)); - - if (diriter_update_paths(diriter) < 0) - return -1; - - return 0; -} - -int git_fs_path_diriter_filename( - const char **out, - size_t *out_len, - git_fs_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(out_len); - GIT_ASSERT_ARG(diriter); - GIT_ASSERT(diriter->path_utf8.size > diriter->parent_utf8_len); - - *out = &diriter->path_utf8.ptr[diriter->parent_utf8_len+1]; - *out_len = diriter->path_utf8.size - diriter->parent_utf8_len - 1; - return 0; -} - -int git_fs_path_diriter_fullpath( - const char **out, - size_t *out_len, - git_fs_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(out_len); - GIT_ASSERT_ARG(diriter); - - *out = diriter->path_utf8.ptr; - *out_len = diriter->path_utf8.size; - return 0; -} - -int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diriter); - - return git_win32__file_attribute_to_stat(out, - (WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current, - diriter->path); -} - -void git_fs_path_diriter_free(git_fs_path_diriter *diriter) -{ - if (diriter == NULL) - return; - - git_str_dispose(&diriter->path_utf8); - - if (diriter->handle != INVALID_HANDLE_VALUE) { - FindClose(diriter->handle); - diriter->handle = INVALID_HANDLE_VALUE; - } -} - -#else - -int git_fs_path_diriter_init( - git_fs_path_diriter *diriter, - const char *path, - unsigned int flags) -{ - GIT_ASSERT_ARG(diriter); - GIT_ASSERT_ARG(path); - - memset(diriter, 0, sizeof(git_fs_path_diriter)); - - if (git_str_puts(&diriter->path, path) < 0) - return -1; - - path_trim_slashes(&diriter->path); - - if (diriter->path.size == 0) { - git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path); - return -1; - } - - if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) { - git_str_dispose(&diriter->path); - - git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path); - return -1; - } - -#ifdef GIT_USE_ICONV - if ((flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0) - (void)git_fs_path_iconv_init_precompose(&diriter->ic); -#endif - - diriter->parent_len = diriter->path.size; - diriter->flags = flags; - - return 0; -} - -int git_fs_path_diriter_next(git_fs_path_diriter *diriter) -{ - struct dirent *de; - const char *filename; - size_t filename_len; - bool skip_dot = !(diriter->flags & GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT); - int error = 0; - - GIT_ASSERT_ARG(diriter); - - errno = 0; - - do { - if ((de = readdir(diriter->dir)) == NULL) { - if (!errno) - return GIT_ITEROVER; - - git_error_set(GIT_ERROR_OS, - "could not read directory '%s'", diriter->path.ptr); - return -1; - } - } while (skip_dot && git_fs_path_is_dot_or_dotdot(de->d_name)); - - filename = de->d_name; - filename_len = strlen(filename); - -#ifdef GIT_USE_ICONV - if ((diriter->flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0 && - (error = git_fs_path_iconv(&diriter->ic, &filename, &filename_len)) < 0) - return error; -#endif - - git_str_truncate(&diriter->path, diriter->parent_len); - - if (diriter->parent_len > 0 && - diriter->path.ptr[diriter->parent_len-1] != '/') - git_str_putc(&diriter->path, '/'); - - git_str_put(&diriter->path, filename, filename_len); - - if (git_str_oom(&diriter->path)) - return -1; - - return error; -} - -int git_fs_path_diriter_filename( - const char **out, - size_t *out_len, - git_fs_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(out_len); - GIT_ASSERT_ARG(diriter); - GIT_ASSERT(diriter->path.size > diriter->parent_len); - - *out = &diriter->path.ptr[diriter->parent_len+1]; - *out_len = diriter->path.size - diriter->parent_len - 1; - return 0; -} - -int git_fs_path_diriter_fullpath( - const char **out, - size_t *out_len, - git_fs_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(out_len); - GIT_ASSERT_ARG(diriter); - - *out = diriter->path.ptr; - *out_len = diriter->path.size; - return 0; -} - -int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diriter); - - return git_fs_path_lstat(diriter->path.ptr, out); -} - -void git_fs_path_diriter_free(git_fs_path_diriter *diriter) -{ - if (diriter == NULL) - return; - - if (diriter->dir) { - closedir(diriter->dir); - diriter->dir = NULL; - } - -#ifdef GIT_USE_ICONV - git_fs_path_iconv_clear(&diriter->ic); -#endif - - git_str_dispose(&diriter->path); -} - -#endif - -int git_fs_path_dirload( - git_vector *contents, - const char *path, - size_t prefix_len, - uint32_t flags) -{ - git_fs_path_diriter iter = GIT_FS_PATH_DIRITER_INIT; - const char *name; - size_t name_len; - char *dup; - int error; - - GIT_ASSERT_ARG(contents); - GIT_ASSERT_ARG(path); - - if ((error = git_fs_path_diriter_init(&iter, path, flags)) < 0) - return error; - - while ((error = git_fs_path_diriter_next(&iter)) == 0) { - if ((error = git_fs_path_diriter_fullpath(&name, &name_len, &iter)) < 0) - break; - - GIT_ASSERT(name_len > prefix_len); - - dup = git__strndup(name + prefix_len, name_len - prefix_len); - GIT_ERROR_CHECK_ALLOC(dup); - - if ((error = git_vector_insert(contents, dup)) < 0) - break; - } - - if (error == GIT_ITEROVER) - error = 0; - - git_fs_path_diriter_free(&iter); - return error; -} - -int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url_or_path) -{ - if (git_fs_path_is_local_file_url(url_or_path)) - return git_fs_path_fromurl(local_path_out, url_or_path); - else - return git_str_sets(local_path_out, url_or_path); -} - -/* Reject paths like AUX or COM1, or those versions that end in a dot or - * colon. ("AUX." or "AUX:") - */ -GIT_INLINE(bool) validate_dospath( - const char *component, - size_t len, - const char dospath[3], - bool trailing_num) -{ - size_t last = trailing_num ? 4 : 3; - - if (len < last || git__strncasecmp(component, dospath, 3) != 0) - return true; - - if (trailing_num && (component[3] < '1' || component[3] > '9')) - return true; - - return (len > last && - component[last] != '.' && - component[last] != ':'); -} - -GIT_INLINE(bool) validate_char(unsigned char c, unsigned int flags) -{ - if ((flags & GIT_FS_PATH_REJECT_BACKSLASH) && c == '\\') - return false; - - if ((flags & GIT_FS_PATH_REJECT_SLASH) && c == '/') - return false; - - if (flags & GIT_FS_PATH_REJECT_NT_CHARS) { - if (c < 32) - return false; - - switch (c) { - case '<': - case '>': - case ':': - case '"': - case '|': - case '?': - case '*': - return false; - } - } - - return true; -} - -/* - * We fundamentally don't like some paths when dealing with user-inputted - * strings (to avoid escaping a sandbox): we don't want dot or dot-dot - * anywhere, we want to avoid writing weird paths on Windows that can't - * be handled by tools that use the non-\\?\ APIs, we don't want slashes - * or double slashes at the end of paths that can make them ambiguous. - * - * For checkout, we don't want to recurse into ".git" either. - */ -static bool validate_component( - const char *component, - size_t len, - unsigned int flags) -{ - if (len == 0) - return !(flags & GIT_FS_PATH_REJECT_EMPTY_COMPONENT); - - if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) && - len == 1 && component[0] == '.') - return false; - - if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) && - len == 2 && component[0] == '.' && component[1] == '.') - return false; - - if ((flags & GIT_FS_PATH_REJECT_TRAILING_DOT) && - component[len - 1] == '.') - return false; - - if ((flags & GIT_FS_PATH_REJECT_TRAILING_SPACE) && - component[len - 1] == ' ') - return false; - - if ((flags & GIT_FS_PATH_REJECT_TRAILING_COLON) && - component[len - 1] == ':') - return false; - - if (flags & GIT_FS_PATH_REJECT_DOS_PATHS) { - if (!validate_dospath(component, len, "CON", false) || - !validate_dospath(component, len, "PRN", false) || - !validate_dospath(component, len, "AUX", false) || - !validate_dospath(component, len, "NUL", false) || - !validate_dospath(component, len, "COM", true) || - !validate_dospath(component, len, "LPT", true)) - return false; - } - - return true; -} - -#ifdef GIT_WIN32 -GIT_INLINE(bool) validate_length( - const char *path, - size_t len, - size_t utf8_char_len) -{ - GIT_UNUSED(path); - GIT_UNUSED(len); - - return (utf8_char_len <= MAX_PATH); -} -#endif - -bool git_fs_path_str_is_valid_ext( - const git_str *path, - unsigned int flags, - bool (*validate_char_cb)(char ch, void *payload), - bool (*validate_component_cb)(const char *component, size_t len, void *payload), - bool (*validate_length_cb)(const char *path, size_t len, size_t utf8_char_len), - void *payload) -{ - const char *start, *c; - size_t len = 0; - - if (!flags) - return true; - - for (start = c = path->ptr; *c && len < path->size; c++, len++) { - if (!validate_char(*c, flags)) - return false; - - if (validate_char_cb && !validate_char_cb(*c, payload)) - return false; - - if (*c != '/') - continue; - - if (!validate_component(start, (c - start), flags)) - return false; - - if (validate_component_cb && - !validate_component_cb(start, (c - start), payload)) - return false; - - start = c + 1; - } - - /* - * We want to support paths specified as either `const char *` - * or `git_str *`; we pass size as `SIZE_MAX` when we use a - * `const char *` to avoid a `strlen`. Ensure that we didn't - * have a NUL in the buffer if there was a non-SIZE_MAX length. - */ - if (path->size != SIZE_MAX && len != path->size) - return false; - - if (!validate_component(start, (c - start), flags)) - return false; - - if (validate_component_cb && - !validate_component_cb(start, (c - start), payload)) - return false; - -#ifdef GIT_WIN32 - if ((flags & GIT_FS_PATH_REJECT_LONG_PATHS) != 0) { - size_t utf8_len = git_utf8_char_length(path->ptr, len); - - if (!validate_length(path->ptr, len, utf8_len)) - return false; - - if (validate_length_cb && - !validate_length_cb(path->ptr, len, utf8_len)) - return false; - } -#else - GIT_UNUSED(validate_length_cb); -#endif - - return true; -} - -int git_fs_path_validate_str_length_with_suffix( - git_str *path, - size_t suffix_len) -{ -#ifdef GIT_WIN32 - size_t utf8_len = git_utf8_char_length(path->ptr, path->size); - size_t total_len; - - if (GIT_ADD_SIZET_OVERFLOW(&total_len, utf8_len, suffix_len) || - total_len > MAX_PATH) { - - git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'", - (int)path->size, path->ptr); - return -1; - } -#else - GIT_UNUSED(path); - GIT_UNUSED(suffix_len); -#endif - - return 0; -} - -int git_fs_path_normalize_slashes(git_str *out, const char *path) -{ - int error; - char *p; - - if ((error = git_str_puts(out, path)) < 0) - return error; - - for (p = out->ptr; *p; p++) { - if (*p == '\\') - *p = '/'; - } - - return 0; -} - -bool git_fs_path_supports_symlinks(const char *dir) -{ - git_str path = GIT_STR_INIT; - bool supported = false; - struct stat st; - int fd; - - if ((fd = git_futils_mktmp(&path, dir, 0666)) < 0 || - p_close(fd) < 0 || - p_unlink(path.ptr) < 0 || - p_symlink("testing", path.ptr) < 0 || - p_lstat(path.ptr, &st) < 0) - goto done; - - supported = (S_ISLNK(st.st_mode) != 0); -done: - if (path.size) - (void)p_unlink(path.ptr); - git_str_dispose(&path); - return supported; -} - -static git_fs_path_owner_t mock_owner = GIT_FS_PATH_OWNER_NONE; - -void git_fs_path__set_owner(git_fs_path_owner_t owner) -{ - mock_owner = owner; -} - -#ifdef GIT_WIN32 -static PSID *sid_dup(PSID sid) -{ - DWORD len; - PSID dup; - - len = GetLengthSid(sid); - - if ((dup = git__malloc(len)) == NULL) - return NULL; - - if (!CopySid(len, dup, sid)) { - git_error_set(GIT_ERROR_OS, "could not duplicate sid"); - git__free(dup); - return NULL; - } - - return dup; -} - -static int current_user_sid(PSID *out) -{ - TOKEN_USER *info = NULL; - HANDLE token = NULL; - DWORD len = 0; - int error = -1; - - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) { - git_error_set(GIT_ERROR_OS, "could not lookup process information"); - goto done; - } - - if (GetTokenInformation(token, TokenUser, NULL, 0, &len) || - GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - git_error_set(GIT_ERROR_OS, "could not lookup token metadata"); - goto done; - } - - info = git__malloc(len); - GIT_ERROR_CHECK_ALLOC(info); - - if (!GetTokenInformation(token, TokenUser, info, len, &len)) { - git_error_set(GIT_ERROR_OS, "could not lookup current user"); - goto done; - } - - if ((*out = sid_dup(info->User.Sid))) - error = 0; - -done: - if (token) - CloseHandle(token); - - git__free(info); - return error; -} - -static int file_owner_sid(PSID *out, const char *path) -{ - git_win32_path path_w32; - PSECURITY_DESCRIPTOR descriptor = NULL; - PSID owner_sid; - DWORD ret; - int error = GIT_EINVALID; - - if (git_win32_path_from_utf8(path_w32, path) < 0) - return -1; - - ret = GetNamedSecurityInfoW(path_w32, SE_FILE_OBJECT, - OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, - &owner_sid, NULL, NULL, NULL, &descriptor); - - if (ret == ERROR_FILE_NOT_FOUND || ret == ERROR_PATH_NOT_FOUND) - error = GIT_ENOTFOUND; - else if (ret != ERROR_SUCCESS) - git_error_set(GIT_ERROR_OS, "failed to get security information"); - else if (!IsValidSid(owner_sid)) - git_error_set(GIT_ERROR_OS, "file owner is not valid"); - else if ((*out = sid_dup(owner_sid))) - error = 0; - - if (descriptor) - LocalFree(descriptor); - - return error; -} - -int git_fs_path_owner_is( - bool *out, - const char *path, - git_fs_path_owner_t owner_type) -{ - PSID owner_sid = NULL, user_sid = NULL; - BOOL is_admin, admin_owned; - int error; - - if (mock_owner) { - *out = ((mock_owner & owner_type) != 0); - return 0; - } - - if ((error = file_owner_sid(&owner_sid, path)) < 0) - goto done; - - if ((owner_type & GIT_FS_PATH_OWNER_CURRENT_USER) != 0) { - if ((error = current_user_sid(&user_sid)) < 0) - goto done; - - if (EqualSid(owner_sid, user_sid)) { - *out = true; - goto done; - } - } - - admin_owned = - IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) || - IsWellKnownSid(owner_sid, WinLocalSystemSid); - - if (admin_owned && - (owner_type & GIT_FS_PATH_OWNER_ADMINISTRATOR) != 0) { - *out = true; - goto done; - } - - if (admin_owned && - (owner_type & GIT_FS_PATH_USER_IS_ADMINISTRATOR) != 0 && - CheckTokenMembership(NULL, owner_sid, &is_admin) && - is_admin) { - *out = true; - goto done; - } - - *out = false; - -done: - git__free(owner_sid); - git__free(user_sid); - return error; -} - -#else - -static int sudo_uid_lookup(uid_t *out) -{ - git_str uid_str = GIT_STR_INIT; - int64_t uid; - int error = -1; - - if (git__getenv(&uid_str, "SUDO_UID") == 0 && - git__strntol64(&uid, uid_str.ptr, uid_str.size, NULL, 10) == 0 && - uid == (int64_t)((uid_t)uid)) { - *out = (uid_t)uid; - error = 0; - } - - git_str_dispose(&uid_str); - return error; -} - -int git_fs_path_owner_is( - bool *out, - const char *path, - git_fs_path_owner_t owner_type) -{ - struct stat st; - uid_t euid, sudo_uid; - - if (mock_owner) { - *out = ((mock_owner & owner_type) != 0); - return 0; - } - - euid = geteuid(); - - if (p_lstat(path, &st) != 0) { - if (errno == ENOENT) - return GIT_ENOTFOUND; - - git_error_set(GIT_ERROR_OS, "could not stat '%s'", path); - return -1; - } - - if ((owner_type & GIT_FS_PATH_OWNER_CURRENT_USER) != 0 && - st.st_uid == euid) { - *out = true; - return 0; - } - - if ((owner_type & GIT_FS_PATH_OWNER_ADMINISTRATOR) != 0 && - st.st_uid == 0) { - *out = true; - return 0; - } - - if ((owner_type & GIT_FS_PATH_OWNER_RUNNING_SUDO) != 0 && - euid == 0 && - sudo_uid_lookup(&sudo_uid) == 0 && - st.st_uid == sudo_uid) { - *out = true; - return 0; - } - - *out = false; - return 0; -} - -#endif - -int git_fs_path_owner_is_current_user(bool *out, const char *path) -{ - return git_fs_path_owner_is(out, path, GIT_FS_PATH_OWNER_CURRENT_USER); -} - -int git_fs_path_owner_is_system(bool *out, const char *path) -{ - return git_fs_path_owner_is(out, path, GIT_FS_PATH_OWNER_ADMINISTRATOR); -} - -#ifdef GIT_WIN32 - -static int find_executable(git_str *fullpath, const char *executable) -{ - git_win32_path fullpath_w, executable_w; - int error; - - if (git_utf8_to_16(executable_w, GIT_WIN_PATH_MAX, executable) < 0) - return -1; - - error = git_win32_path_find_executable(fullpath_w, executable_w); - - if (error == 0) - error = git_str_put_w(fullpath, fullpath_w, wcslen(fullpath_w)); - - return error; -} - -#else - -static int find_executable(git_str *fullpath, const char *executable) -{ - git_str path = GIT_STR_INIT; - const char *current_dir, *term; - size_t current_dirlen; - bool found = false; - - if (git__getenv(&path, "PATH") < 0) - return -1; - - current_dir = path.ptr; - - while (*current_dir) { - if (! (term = strchr(current_dir, GIT_PATH_LIST_SEPARATOR))) - term = strchr(current_dir, '\0'); - - current_dirlen = term - current_dir; - git_str_clear(fullpath); - - /* An empty path segment is treated as '.' */ - if (current_dirlen == 0 && git_str_putc(fullpath, '.')) - return -1; - else if (current_dirlen != 0 && - git_str_put(fullpath, current_dir, current_dirlen) < 0) - return -1; - - if (git_str_putc(fullpath, '/') < 0 || - git_str_puts(fullpath, executable) < 0) - return -1; - - if (git_fs_path_isexecutable(fullpath->ptr)) { - found = true; - break; - } - - current_dir = term; - - if (*current_dir == GIT_PATH_LIST_SEPARATOR) - current_dir++; - } - - git_str_dispose(&path); - - if (found) - return 0; - - git_str_clear(fullpath); - return GIT_ENOTFOUND; -} - -#endif - -int git_fs_path_find_executable(git_str *fullpath, const char *executable) -{ - /* For qualified paths we do not look in PATH */ - if (strchr(executable, '/') != NULL) { - if (!git_fs_path_isexecutable(executable)) - return GIT_ENOTFOUND; - - return git_str_puts(fullpath, executable); - } - - return find_executable(fullpath, executable); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/fs_path.h b/vendor/libgit2-sys/libgit2/src/util/fs_path.h deleted file mode 100644 index cafee64..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/fs_path.h +++ /dev/null @@ -1,819 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_fs_path_h__ -#define INCLUDE_fs_path_h__ - -#include "git2_util.h" - -#include "posix.h" -#include "str.h" -#include "vector.h" -#include "utf8.h" - -/** - * Path manipulation utils - * - * These are path utilities that munge paths without actually - * looking at the real filesystem. - */ - -/* - * The dirname() function shall take a pointer to a character string - * that contains a pathname, and return a pointer to a string that is a - * pathname of the parent directory of that file. Trailing '/' characters - * in the path are not counted as part of the path. - * - * If path does not contain a '/', then dirname() shall return a pointer to - * the string ".". If path is a null pointer or points to an empty string, - * dirname() shall return a pointer to the string "." . - * - * The `git_fs_path_dirname` implementation is thread safe. The returned - * string must be manually free'd. - * - * The `git_fs_path_dirname_r` implementation writes the dirname to a `git_str` - * if the buffer pointer is not NULL. - * It returns an error code < 0 if there is an allocation error, otherwise - * the length of the dirname (which will be > 0). - */ -extern char *git_fs_path_dirname(const char *path); -extern int git_fs_path_dirname_r(git_str *buffer, const char *path); - -/* - * This function returns the basename of the file, which is the last - * part of its full name given by fname, with the drive letter and - * leading directories stripped off. For example, the basename of - * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo. - * - * Trailing slashes and backslashes are significant: the basename of - * c:/foo/bar/ is an empty string after the rightmost slash. - * - * The `git_fs_path_basename` implementation is thread safe. The returned - * string must be manually free'd. - * - * The `git_fs_path_basename_r` implementation writes the basename to a `git_str`. - * It returns an error code < 0 if there is an allocation error, otherwise - * the length of the basename (which will be >= 0). - */ -extern char *git_fs_path_basename(const char *path); -extern int git_fs_path_basename_r(git_str *buffer, const char *path); - -/* Return the offset of the start of the basename. Unlike the other - * basename functions, this returns 0 if the path is empty. - */ -extern size_t git_fs_path_basename_offset(git_str *buffer); - -/** - * Find offset to root of path if path has one. - * - * This will return a number >= 0 which is the offset to the start of the - * path, if the path is rooted (i.e. "/rooted/path" returns 0 and - * "c:/windows/rooted/path" returns 2). If the path is not rooted, this - * returns -1. - */ -extern int git_fs_path_root(const char *path); - -/** - * Ensure path has a trailing '/'. - */ -extern int git_fs_path_to_dir(git_str *path); - -/** - * Ensure string has a trailing '/' if there is space for it. - */ -extern void git_fs_path_string_to_dir(char *path, size_t size); - -/** - * Provides the length of the given path string with no trailing - * slashes. - */ -size_t git_fs_path_dirlen(const char *path); - -/** - * Returns nonzero if the given path is a filesystem root; on Windows, this - * means a drive letter (eg `A:/`, `C:\`). On POSIX this is `/`. - */ -GIT_INLINE(int) git_fs_path_is_root(const char *name) -{ -#ifdef GIT_WIN32 - if (((name[0] >= 'A' && name[0] <= 'Z') || (name[0] >= 'a' && name[0] <= 'z')) && - name[1] == ':' && - (name[2] == '/' || name[2] == '\\') && - name[3] == '\0') - return 1; -#endif - - return (name[0] == '/' && name[1] == '\0'); -} - -/** - * Taken from git.git; returns nonzero if the given path is "." or "..". - */ -GIT_INLINE(int) git_fs_path_is_dot_or_dotdot(const char *name) -{ - return (name[0] == '.' && - (name[1] == '\0' || - (name[1] == '.' && name[2] == '\0'))); -} - -#ifdef GIT_WIN32 -GIT_INLINE(int) git_fs_path_is_dot_or_dotdotW(const wchar_t *name) -{ - return (name[0] == L'.' && - (name[1] == L'\0' || - (name[1] == L'.' && name[2] == L'\0'))); -} - -#define git_fs_path_is_absolute(p) \ - (git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/')) - -#define git_fs_path_is_dirsep(p) \ - ((p) == '/' || (p) == '\\') - -/** - * Convert backslashes in path to forward slashes. - */ -GIT_INLINE(void) git_fs_path_mkposix(char *path) -{ - while (*path) { - if (*path == '\\') - *path = '/'; - - path++; - } -} -#else -# define git_fs_path_mkposix(p) /* blank */ - -#define git_fs_path_is_absolute(p) \ - ((p)[0] == '/') - -#define git_fs_path_is_dirsep(p) \ - ((p) == '/') - -#endif - -/** - * Check if string is a relative path (i.e. starts with "./" or "../") - */ -GIT_INLINE(int) git_fs_path_is_relative(const char *p) -{ - return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/'))); -} - -/** - * Check if string is at end of path segment (i.e. looking at '/' or '\0') - */ -GIT_INLINE(int) git_fs_path_at_end_of_segment(const char *p) -{ - return !*p || *p == '/'; -} - -extern int git__percent_decode(git_str *decoded_out, const char *input); - -/** - * Extract path from file:// URL. - */ -extern int git_fs_path_fromurl(git_str *local_path_out, const char *file_url); - - -/** - * Path filesystem utils - * - * These are path utilities that actually access the filesystem. - */ - -/** - * Check if a file exists and can be accessed. - * @return true or false - */ -extern bool git_fs_path_exists(const char *path); - -/** - * Check if the given path points to a directory. - * @return true or false - */ -extern bool git_fs_path_isdir(const char *path); - -/** - * Check if the given path points to a regular file. - * @return true or false - */ -extern bool git_fs_path_isfile(const char *path); - -/** - * Check if the given path points to an executable. - * @return true or false - */ -extern bool git_fs_path_isexecutable(const char *path); - -/** - * Check if the given path points to a symbolic link. - * @return true or false - */ -extern bool git_fs_path_islink(const char *path); - -/** - * Check if the given path is a directory, and is empty. - */ -extern bool git_fs_path_is_empty_dir(const char *path); - -/** - * Stat a file and/or link and set error if needed. - */ -extern int git_fs_path_lstat(const char *path, struct stat *st); - -/** - * Check if the parent directory contains the item. - * - * @param dir Directory to check. - * @param item Item that might be in the directory. - * @return 0 if item exists in directory, <0 otherwise. - */ -extern bool git_fs_path_contains(git_str *dir, const char *item); - -/** - * Check if the given path contains the given subdirectory. - * - * @param parent Directory path that might contain subdir - * @param subdir Subdirectory name to look for in parent - * @return true if subdirectory exists, false otherwise. - */ -extern bool git_fs_path_contains_dir(git_str *parent, const char *subdir); - -/** - * Determine the common directory length between two paths, including - * the final path separator. For example, given paths 'a/b/c/1.txt - * and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this - * will return the length of the string 'a/b/c/', which is 6. - * - * @param one The first path - * @param two The second path - * @return The length of the common directory - */ -extern size_t git_fs_path_common_dirlen(const char *one, const char *two); - -/** - * Make the path relative to the given parent path. - * - * @param path The path to make relative - * @param parent The parent path to make path relative to - * @return 0 if path was made relative, GIT_ENOTFOUND - * if there was not common root between the paths, - * or <0. - */ -extern int git_fs_path_make_relative(git_str *path, const char *parent); - -/** - * Check if the given path contains the given file. - * - * @param dir Directory path that might contain file - * @param file File name to look for in parent - * @return true if file exists, false otherwise. - */ -extern bool git_fs_path_contains_file(git_str *dir, const char *file); - -/** - * Prepend base to unrooted path or just copy path over. - * - * This will optionally return the index into the path where the "root" - * is, either the end of the base directory prefix or the path root. - */ -extern int git_fs_path_join_unrooted( - git_str *path_out, const char *path, const char *base, ssize_t *root_at); - -/** - * Removes multiple occurrences of '/' in a row, squashing them into a - * single '/'. - */ -extern void git_fs_path_squash_slashes(git_str *path); - -/** - * Clean up path, prepending base if it is not already rooted. - */ -extern int git_fs_path_prettify(git_str *path_out, const char *path, const char *base); - -/** - * Clean up path, prepending base if it is not already rooted and - * appending a slash. - */ -extern int git_fs_path_prettify_dir(git_str *path_out, const char *path, const char *base); - -/** - * Get a directory from a path. - * - * If path is a directory, this acts like `git_fs_path_prettify_dir` - * (cleaning up path and appending a '/'). If path is a normal file, - * this prettifies it, then removed the filename a la dirname and - * appends the trailing '/'. If the path does not exist, it is - * treated like a regular filename. - */ -extern int git_fs_path_find_dir(git_str *dir); - -/** - * Resolve relative references within a path. - * - * This eliminates "./" and "../" relative references inside a path, - * as well as condensing multiple slashes into single ones. It will - * not touch the path before the "ceiling" length. - * - * Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL - * prefix and not touch that part of the path. - */ -extern int git_fs_path_resolve_relative(git_str *path, size_t ceiling); - -/** - * Apply a relative path to base path. - * - * Note that the base path could be a filename or a URL and this - * should still work. The relative path is walked segment by segment - * with three rules: series of slashes will be condensed to a single - * slash, "." will be eaten with no change, and ".." will remove a - * segment from the base path. - */ -extern int git_fs_path_apply_relative(git_str *target, const char *relpath); - -enum { - GIT_FS_PATH_DIR_IGNORE_CASE = (1u << 0), - GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE = (1u << 1), - GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT = (1u << 2), -}; - -/** - * Walk each directory entry, except '.' and '..', calling fn(state). - * - * @param pathbuf Buffer the function reads the initial directory - * path from, and updates with each successive entry's name. - * @param flags Combination of GIT_FS_PATH_DIR flags. - * @param callback Callback for each entry. Passed the `payload` and each - * successive path inside the directory as a full path. This may - * safely append text to the pathbuf if needed. Return non-zero to - * cancel iteration (and return value will be propagated back). - * @param payload Passed to callback as first argument. - * @return 0 on success or error code from OS error or from callback - */ -extern int git_fs_path_direach( - git_str *pathbuf, - uint32_t flags, - int (*callback)(void *payload, git_str *path), - void *payload); - -/** - * Sort function to order two paths - */ -extern int git_fs_path_cmp( - const char *name1, size_t len1, int isdir1, - const char *name2, size_t len2, int isdir2, - int (*compare)(const char *, const char *, size_t)); - -/** - * Invoke callback up path directory by directory until the ceiling is - * reached (inclusive of a final call at the root_path). - * - * Returning anything other than 0 from the callback function - * will stop the iteration and propagate the error to the caller. - * - * @param pathbuf Buffer the function reads the directory from and - * and updates with each successive name. - * @param ceiling Prefix of path at which to stop walking up. If NULL, - * this will walk all the way up to the root. If not a prefix of - * pathbuf, the callback will be invoked a single time on the - * original input path. - * @param callback Function to invoke on each path. Passed the `payload` - * and the buffer containing the current path. The path should not - * be modified in any way. Return non-zero to stop iteration. - * @param payload Passed to fn as the first ath. - */ -extern int git_fs_path_walk_up( - git_str *pathbuf, - const char *ceiling, - int (*callback)(void *payload, const char *path), - void *payload); - - -enum { - GIT_FS_PATH_NOTEQUAL = 0, - GIT_FS_PATH_EQUAL = 1, - GIT_FS_PATH_PREFIX = 2 -}; - -/* - * Determines if a path is equal to or potentially a child of another. - * @param parent The possible parent - * @param child The possible child - */ -GIT_INLINE(int) git_fs_path_equal_or_prefixed( - const char *parent, - const char *child, - ssize_t *prefixlen) -{ - const char *p = parent, *c = child; - int lastslash = 0; - - while (*p && *c) { - lastslash = (*p == '/'); - - if (*p++ != *c++) - return GIT_FS_PATH_NOTEQUAL; - } - - if (*p != '\0') - return GIT_FS_PATH_NOTEQUAL; - - if (*c == '\0') { - if (prefixlen) - *prefixlen = p - parent; - - return GIT_FS_PATH_EQUAL; - } - - if (*c == '/' || lastslash) { - if (prefixlen) - *prefixlen = (p - parent) - lastslash; - - return GIT_FS_PATH_PREFIX; - } - - return GIT_FS_PATH_NOTEQUAL; -} - -/* translate errno to libgit2 error code and set error message */ -extern int git_fs_path_set_error( - int errno_value, const char *path, const char *action); - -/* check if non-ascii characters are present in filename */ -extern bool git_fs_path_has_non_ascii(const char *path, size_t pathlen); - -#define GIT_PATH_REPO_ENCODING "UTF-8" - -#ifdef __APPLE__ -#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC" -#else -#define GIT_PATH_NATIVE_ENCODING "UTF-8" -#endif - -#ifdef GIT_USE_ICONV - -#include - -typedef struct { - iconv_t map; - git_str buf; -} git_fs_path_iconv_t; - -#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_STR_INIT } - -/* Init iconv data for converting decomposed UTF-8 to precomposed */ -extern int git_fs_path_iconv_init_precompose(git_fs_path_iconv_t *ic); - -/* Clear allocated iconv data */ -extern void git_fs_path_iconv_clear(git_fs_path_iconv_t *ic); - -/* - * Rewrite `in` buffer using iconv map if necessary, replacing `in` - * pointer internal iconv buffer if rewrite happened. The `in` pointer - * will be left unchanged if no rewrite was needed. - */ -extern int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen); - -#endif /* GIT_USE_ICONV */ - -extern bool git_fs_path_does_decompose_unicode(const char *root); - - -typedef struct git_fs_path_diriter git_fs_path_diriter; - -#if defined(GIT_WIN32) && !defined(__MINGW32__) - -struct git_fs_path_diriter -{ - git_win32_path path; - size_t parent_len; - - git_str path_utf8; - size_t parent_utf8_len; - - HANDLE handle; - - unsigned int flags; - - WIN32_FIND_DATAW current; - unsigned int needs_next; -}; - -#define GIT_FS_PATH_DIRITER_INIT { {0}, 0, GIT_STR_INIT, 0, INVALID_HANDLE_VALUE } - -#else - -struct git_fs_path_diriter -{ - git_str path; - size_t parent_len; - - unsigned int flags; - - DIR *dir; - -#ifdef GIT_USE_ICONV - git_fs_path_iconv_t ic; -#endif -}; - -#define GIT_FS_PATH_DIRITER_INIT { GIT_STR_INIT } - -#endif - -/** - * Initialize a directory iterator. - * - * @param diriter Pointer to a diriter structure that will be setup. - * @param path The path that will be iterated over - * @param flags Directory reader flags - * @return 0 or an error code - */ -extern int git_fs_path_diriter_init( - git_fs_path_diriter *diriter, - const char *path, - unsigned int flags); - -/** - * Advance the directory iterator. Will return GIT_ITEROVER when - * the iteration has completed successfully. - * - * @param diriter The directory iterator - * @return 0, GIT_ITEROVER, or an error code - */ -extern int git_fs_path_diriter_next(git_fs_path_diriter *diriter); - -/** - * Returns the file name of the current item in the iterator. - * - * @param out Pointer to store the path in - * @param out_len Pointer to store the length of the path in - * @param diriter The directory iterator - * @return 0 or an error code - */ -extern int git_fs_path_diriter_filename( - const char **out, - size_t *out_len, - git_fs_path_diriter *diriter); - -/** - * Returns the full path of the current item in the iterator; that - * is the current filename plus the path of the directory that the - * iterator was constructed with. - * - * @param out Pointer to store the path in - * @param out_len Pointer to store the length of the path in - * @param diriter The directory iterator - * @return 0 or an error code - */ -extern int git_fs_path_diriter_fullpath( - const char **out, - size_t *out_len, - git_fs_path_diriter *diriter); - -/** - * Performs an `lstat` on the current item in the iterator. - * - * @param out Pointer to store the stat data in - * @param diriter The directory iterator - * @return 0 or an error code - */ -extern int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter); - -/** - * Closes the directory iterator. - * - * @param diriter The directory iterator - */ -extern void git_fs_path_diriter_free(git_fs_path_diriter *diriter); - -/** - * Load all directory entries (except '.' and '..') into a vector. - * - * For cases where `git_fs_path_direach()` is not appropriate, this - * allows you to load the filenames in a directory into a vector - * of strings. That vector can then be sorted, iterated, or whatever. - * Remember to free alloc of the allocated strings when you are done. - * - * @param contents Vector to fill with directory entry names. - * @param path The directory to read from. - * @param prefix_len When inserting entries, the trailing part of path - * will be prefixed after this length. I.e. given path "/a/b" and - * prefix_len 3, the entries will look like "b/e1", "b/e2", etc. - * @param flags Combination of GIT_FS_PATH_DIR flags. - */ -extern int git_fs_path_dirload( - git_vector *contents, - const char *path, - size_t prefix_len, - uint32_t flags); - - -/* Used for paths to repositories on the filesystem */ -extern bool git_fs_path_is_local_file_url(const char *file_url); -extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url_or_path); - -/* Flags to determine path validity in `git_fs_path_isvalid` */ -#define GIT_FS_PATH_REJECT_EMPTY_COMPONENT (1 << 0) -#define GIT_FS_PATH_REJECT_TRAVERSAL (1 << 1) -#define GIT_FS_PATH_REJECT_SLASH (1 << 2) -#define GIT_FS_PATH_REJECT_BACKSLASH (1 << 3) -#define GIT_FS_PATH_REJECT_TRAILING_DOT (1 << 4) -#define GIT_FS_PATH_REJECT_TRAILING_SPACE (1 << 5) -#define GIT_FS_PATH_REJECT_TRAILING_COLON (1 << 6) -#define GIT_FS_PATH_REJECT_DOS_PATHS (1 << 7) -#define GIT_FS_PATH_REJECT_NT_CHARS (1 << 8) -#define GIT_FS_PATH_REJECT_LONG_PATHS (1 << 9) - -#define GIT_FS_PATH_REJECT_MAX (1 << 9) - -/* Default path safety for writing files to disk: since we use the - * Win32 "File Namespace" APIs ("\\?\") we need to protect from - * paths that the normal Win32 APIs would not write. - */ -#ifdef GIT_WIN32 -# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \ - (GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \ - GIT_FS_PATH_REJECT_TRAVERSAL | \ - GIT_FS_PATH_REJECT_BACKSLASH | \ - GIT_FS_PATH_REJECT_TRAILING_DOT | \ - GIT_FS_PATH_REJECT_TRAILING_SPACE | \ - GIT_FS_PATH_REJECT_TRAILING_COLON | \ - GIT_FS_PATH_REJECT_DOS_PATHS | \ - GIT_FS_PATH_REJECT_NT_CHARS) -#else -# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \ - (GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \ - GIT_FS_PATH_REJECT_TRAVERSAL) -#endif - -/** - * Validate a filesystem path; with custom callbacks per-character and - * per-path component. - */ -extern bool git_fs_path_str_is_valid_ext( - const git_str *path, - unsigned int flags, - bool (*validate_char_cb)(char ch, void *payload), - bool (*validate_component_cb)(const char *component, size_t len, void *payload), - bool (*validate_length_cb)(const char *component, size_t len, size_t utf8_char_len), - void *payload); - -GIT_INLINE(bool) git_fs_path_is_valid_ext( - const char *path, - unsigned int flags, - bool (*validate_char_cb)(char ch, void *payload), - bool (*validate_component_cb)(const char *component, size_t len, void *payload), - bool (*validate_length_cb)(const char *component, size_t len, size_t utf8_char_len), - void *payload) -{ - const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); - return git_fs_path_str_is_valid_ext( - &str, - flags, - validate_char_cb, - validate_component_cb, - validate_length_cb, - payload); -} - -/** - * Validate a filesystem path. This ensures that the given path is legal - * and does not contain any "unsafe" components like path traversal ('.' - * or '..'), characters that are inappropriate for lesser filesystems - * (trailing ' ' or ':' characters), or filenames ("component names") - * that are not supported ('AUX', 'COM1"). - */ -GIT_INLINE(bool) git_fs_path_is_valid( - const char *path, - unsigned int flags) -{ - const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); - return git_fs_path_str_is_valid_ext(&str, flags, NULL, NULL, NULL, NULL); -} - -/** Validate a filesystem path in a `git_str`. */ -GIT_INLINE(bool) git_fs_path_str_is_valid( - const git_str *path, - unsigned int flags) -{ - return git_fs_path_str_is_valid_ext(path, flags, NULL, NULL, NULL, NULL); -} - -extern int git_fs_path_validate_str_length_with_suffix( - git_str *path, - size_t suffix_len); - -/** - * Validate an on-disk path, taking into account that it will have a - * suffix appended (eg, `.lock`). - */ -GIT_INLINE(int) git_fs_path_validate_filesystem_with_suffix( - const char *path, - size_t path_len, - size_t suffix_len) -{ -#ifdef GIT_WIN32 - size_t path_chars, total_chars; - - path_chars = git_utf8_char_length(path, path_len); - - if (GIT_ADD_SIZET_OVERFLOW(&total_chars, path_chars, suffix_len) || - total_chars > MAX_PATH) { - git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path); - return -1; - } - return 0; -#else - GIT_UNUSED(path); - GIT_UNUSED(path_len); - GIT_UNUSED(suffix_len); - return 0; -#endif -} - -/** - * Validate an path on the filesystem. This ensures that the given - * path is valid for the operating system/platform; for example, this - * will ensure that the given absolute path is smaller than MAX_PATH on - * Windows. - * - * For paths within the working directory, you should use ensure that - * `core.longpaths` is obeyed. Use `git_fs_path_validate_workdir`. - */ -GIT_INLINE(int) git_fs_path_validate_filesystem( - const char *path, - size_t path_len) -{ - return git_fs_path_validate_filesystem_with_suffix(path, path_len, 0); -} - -/** - * Convert any backslashes into slashes - */ -int git_fs_path_normalize_slashes(git_str *out, const char *path); - -bool git_fs_path_supports_symlinks(const char *dir); - -typedef enum { - GIT_FS_PATH_OWNER_NONE = 0, - - /** The file must be owned by the current user. */ - GIT_FS_PATH_OWNER_CURRENT_USER = (1 << 0), - - /** The file must be owned by the system account. */ - GIT_FS_PATH_OWNER_ADMINISTRATOR = (1 << 1), - - /** - * The file may be owned by a system account if the current - * user is in an administrator group. Windows only; this is - * a noop on non-Windows systems. - */ - GIT_FS_PATH_USER_IS_ADMINISTRATOR = (1 << 2), - - /** - * The file is owned by the current user, who is running `sudo`. - */ - GIT_FS_PATH_OWNER_RUNNING_SUDO = (1 << 3), - - /** The file may be owned by another user. */ - GIT_FS_PATH_OWNER_OTHER = (1 << 4) -} git_fs_path_owner_t; - -/** - * Sets the mock ownership for files; subsequent calls to - * `git_fs_path_owner_is_*` functions will return this data until - * cleared with `GIT_FS_PATH_OWNER_NONE`. - */ -void git_fs_path__set_owner(git_fs_path_owner_t owner); - -/** Verify that the file in question is owned by the given owner. */ -int git_fs_path_owner_is( - bool *out, - const char *path, - git_fs_path_owner_t owner_type); - -/** - * Verify that the file in question is owned by an administrator or system - * account. - */ -int git_fs_path_owner_is_system(bool *out, const char *path); - -/** - * Verify that the file in question is owned by the current user; - */ - -int git_fs_path_owner_is_current_user(bool *out, const char *path); - -/** - * Search the current PATH for the given executable, returning the full - * path if it is found. - */ -int git_fs_path_find_executable(git_str *fullpath, const char *executable); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/futils.c b/vendor/libgit2-sys/libgit2/src/util/futils.c deleted file mode 100644 index eb32cbb..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/futils.c +++ /dev/null @@ -1,1237 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "futils.h" - -#include "runtime.h" -#include "hash.h" -#include "rand.h" -#include "hashmap_str.h" - -#include - -#define GIT_FILEMODE_DEFAULT 0100666 - -int git_futils_mkpath2file(const char *file_path, const mode_t mode) -{ - return git_futils_mkdir( - file_path, mode, - GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR); -} - -int git_futils_mktmp(git_str *path_out, const char *filename, mode_t mode) -{ - const int open_flags = O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC; - unsigned int tries = 32; - int fd; - - while (tries--) { - uint64_t rand = git_rand_next(); - - git_str_sets(path_out, filename); - git_str_puts(path_out, "_git2_"); - git_str_encode_hexstr(path_out, (void *)&rand, sizeof(uint64_t)); - - if (git_str_oom(path_out)) - return -1; - - /* Note that we open with O_CREAT | O_EXCL */ - if ((fd = p_open(path_out->ptr, open_flags, mode)) >= 0) - return fd; - } - - git_error_set(GIT_ERROR_OS, - "failed to create temporary file '%s'", path_out->ptr); - git_str_dispose(path_out); - return -1; -} - -int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode) -{ - int fd; - - if (git_futils_mkpath2file(path, dirmode) < 0) - return -1; - - fd = p_creat(path, mode); - if (fd < 0) { - git_error_set(GIT_ERROR_OS, "failed to create file '%s'", path); - return -1; - } - - return fd; -} - -int git_futils_creat_locked(const char *path, const mode_t mode) -{ - int fd = p_open(path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC, - mode); - - if (fd < 0) { - int error = errno; - git_error_set(GIT_ERROR_OS, "failed to create locked file '%s'", path); - switch (error) { - case EEXIST: - return GIT_ELOCKED; - case ENOENT: - return GIT_ENOTFOUND; - default: - return -1; - } - } - - return fd; -} - -int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode) -{ - if (git_futils_mkpath2file(path, dirmode) < 0) - return -1; - - return git_futils_creat_locked(path, mode); -} - -int git_futils_open_ro(const char *path) -{ - int fd = p_open(path, O_RDONLY); - if (fd < 0) - return git_fs_path_set_error(errno, path, "open"); - return fd; -} - -int git_futils_truncate(const char *path, int mode) -{ - int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode); - if (fd < 0) - return git_fs_path_set_error(errno, path, "open"); - - close(fd); - return 0; -} - -int git_futils_filesize(uint64_t *out, git_file fd) -{ - struct stat sb; - - if (p_fstat(fd, &sb)) { - git_error_set(GIT_ERROR_OS, "failed to stat file descriptor"); - return -1; - } - - if (sb.st_size < 0) { - git_error_set(GIT_ERROR_INVALID, "invalid file size"); - return -1; - } - - *out = sb.st_size; - return 0; -} - -mode_t git_futils_canonical_mode(mode_t raw_mode) -{ - if (S_ISREG(raw_mode)) - return S_IFREG | GIT_PERMS_CANONICAL(raw_mode); - else if (S_ISLNK(raw_mode)) - return S_IFLNK; - else if (S_ISGITLINK(raw_mode)) - return S_IFGITLINK; - else if (S_ISDIR(raw_mode)) - return S_IFDIR; - else - return 0; -} - -int git_futils_readbuffer_fd(git_str *buf, git_file fd, size_t len) -{ - ssize_t read_size = 0; - size_t alloc_len; - - git_str_clear(buf); - - if (!git__is_ssizet(len)) { - git_error_set(GIT_ERROR_INVALID, "read too large"); - return -1; - } - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1); - if (git_str_grow(buf, alloc_len) < 0) - return -1; - - /* p_read loops internally to read len bytes */ - read_size = p_read(fd, buf->ptr, len); - - if (read_size < 0) { - git_error_set(GIT_ERROR_OS, "failed to read descriptor"); - git_str_dispose(buf); - return -1; - } - - if ((size_t)read_size != len) { - git_error_set(GIT_ERROR_FILESYSTEM, "could not read (expected %" PRIuZ " bytes, read %" PRIuZ ")", len, (size_t)read_size); - git_str_dispose(buf); - return -1; - } - - buf->ptr[read_size] = '\0'; - buf->size = read_size; - - return 0; -} - -int git_futils_readbuffer_fd_full(git_str *buf, git_file fd) -{ - static size_t blocksize = 10240; - size_t alloc_len = 0, total_size = 0; - ssize_t read_size = 0; - - git_str_clear(buf); - - while (true) { - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, blocksize); - - if (git_str_grow(buf, alloc_len) < 0) - return -1; - - /* p_read loops internally to read blocksize bytes */ - read_size = p_read(fd, buf->ptr, blocksize); - - if (read_size < 0) { - git_error_set(GIT_ERROR_OS, "failed to read descriptor"); - git_str_dispose(buf); - return -1; - } - - total_size += read_size; - - if ((size_t)read_size < blocksize) { - break; - } - } - - buf->ptr[total_size] = '\0'; - buf->size = total_size; - - return 0; -} - -int git_futils_readbuffer_updated( - git_str *out, - const char *path, - unsigned char checksum[GIT_HASH_SHA256_SIZE], - int *updated) -{ - int error; - git_file fd; - struct stat st; - git_str buf = GIT_STR_INIT; - unsigned char checksum_new[GIT_HASH_SHA256_SIZE]; - - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(path && *path); - - if (updated != NULL) - *updated = 0; - - if (p_stat(path, &st) < 0) - return git_fs_path_set_error(errno, path, "stat"); - - - if (S_ISDIR(st.st_mode)) { - git_error_set(GIT_ERROR_INVALID, "requested file is a directory"); - return GIT_ENOTFOUND; - } - - if (!git__is_sizet(st.st_size+1)) { - git_error_set(GIT_ERROR_OS, "invalid regular file stat for '%s'", path); - return -1; - } - - if ((fd = git_futils_open_ro(path)) < 0) - return fd; - - if (git_futils_readbuffer_fd(&buf, fd, (size_t)st.st_size) < 0) { - p_close(fd); - return -1; - } - - p_close(fd); - - if (checksum) { - error = git_hash_buf(checksum_new, buf.ptr, - buf.size, GIT_HASH_ALGORITHM_SHA256); - - if (error < 0) { - git_str_dispose(&buf); - return error; - } - - /* - * If we were given a checksum, we only want to use it if it's different - */ - if (!memcmp(checksum, checksum_new, GIT_HASH_SHA256_SIZE)) { - git_str_dispose(&buf); - if (updated) - *updated = 0; - - return 0; - } - - memcpy(checksum, checksum_new, GIT_HASH_SHA256_SIZE); - } - - /* - * If we're here, the file did change, or the user didn't have an old version - */ - if (updated != NULL) - *updated = 1; - - git_str_swap(out, &buf); - git_str_dispose(&buf); - - return 0; -} - -int git_futils_readbuffer(git_str *buf, const char *path) -{ - return git_futils_readbuffer_updated(buf, path, NULL, NULL); -} - -int git_futils_writebuffer( - const git_str *buf, const char *path, int flags, mode_t mode) -{ - int fd, do_fsync = 0, error = 0; - - if (!flags) - flags = O_CREAT | O_TRUNC | O_WRONLY; - - if ((flags & O_FSYNC) != 0) - do_fsync = 1; - - flags &= ~O_FSYNC; - - if (!mode) - mode = GIT_FILEMODE_DEFAULT; - - if ((fd = p_open(path, flags, mode)) < 0) { - git_error_set(GIT_ERROR_OS, "could not open '%s' for writing", path); - return fd; - } - - if ((error = p_write(fd, git_str_cstr(buf), git_str_len(buf))) < 0) { - git_error_set(GIT_ERROR_OS, "could not write to '%s'", path); - (void)p_close(fd); - return error; - } - - if (do_fsync && (error = p_fsync(fd)) < 0) { - git_error_set(GIT_ERROR_OS, "could not fsync '%s'", path); - p_close(fd); - return error; - } - - if ((error = p_close(fd)) < 0) { - git_error_set(GIT_ERROR_OS, "error while closing '%s'", path); - return error; - } - - if (do_fsync && (flags & O_CREAT)) - error = git_futils_fsync_parent(path); - - return error; -} - -int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode) -{ - if (git_futils_mkpath2file(to, dirmode) < 0) - return -1; - - if (p_rename(from, to) < 0) { - git_error_set(GIT_ERROR_OS, "failed to rename '%s' to '%s'", from, to); - return -1; - } - - return 0; -} - -int git_futils_mmap_ro(git_map *out, git_file fd, off64_t begin, size_t len) -{ - return p_mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin); -} - -int git_futils_mmap_ro_file(git_map *out, const char *path) -{ - git_file fd = git_futils_open_ro(path); - uint64_t len; - int result; - - if (fd < 0) - return fd; - - if ((result = git_futils_filesize(&len, fd)) < 0) - goto out; - - if (!git__is_sizet(len)) { - git_error_set(GIT_ERROR_OS, "file `%s` too large to mmap", path); - result = -1; - goto out; - } - - result = git_futils_mmap_ro(out, fd, 0, (size_t)len); -out: - p_close(fd); - return result; -} - -void git_futils_mmap_free(git_map *out) -{ - p_munmap(out); -} - -GIT_INLINE(int) mkdir_validate_dir( - const char *path, - struct stat *st, - mode_t mode, - uint32_t flags, - struct git_futils_mkdir_options *opts) -{ - /* with exclusive create, existing dir is an error */ - if ((flags & GIT_MKDIR_EXCL) != 0) { - git_error_set(GIT_ERROR_FILESYSTEM, - "failed to make directory '%s': directory exists", path); - return GIT_EEXISTS; - } - - if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) || - (S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) { - if (p_unlink(path) < 0) { - git_error_set(GIT_ERROR_OS, "failed to remove %s '%s'", - S_ISLNK(st->st_mode) ? "symlink" : "file", path); - return GIT_EEXISTS; - } - - opts->perfdata.mkdir_calls++; - - if (p_mkdir(path, mode) < 0) { - git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path); - return GIT_EEXISTS; - } - } - - else if (S_ISLNK(st->st_mode)) { - /* Re-stat the target, make sure it's a directory */ - opts->perfdata.stat_calls++; - - if (p_stat(path, st) < 0) { - git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path); - return GIT_EEXISTS; - } - } - - else if (!S_ISDIR(st->st_mode)) { - git_error_set(GIT_ERROR_FILESYSTEM, - "failed to make directory '%s': directory exists", path); - return GIT_EEXISTS; - } - - return 0; -} - -GIT_INLINE(int) mkdir_validate_mode( - const char *path, - struct stat *st, - bool terminal_path, - mode_t mode, - uint32_t flags, - struct git_futils_mkdir_options *opts) -{ - if (((terminal_path && (flags & GIT_MKDIR_CHMOD) != 0) || - (flags & GIT_MKDIR_CHMOD_PATH) != 0) && st->st_mode != mode) { - - opts->perfdata.chmod_calls++; - - if (p_chmod(path, mode) < 0) { - git_error_set(GIT_ERROR_OS, "failed to set permissions on '%s'", path); - return -1; - } - } - - return 0; -} - -GIT_INLINE(int) mkdir_canonicalize( - git_str *path, - uint32_t flags) -{ - ssize_t root_len; - - if (path->size == 0) { - git_error_set(GIT_ERROR_OS, "attempt to create empty path"); - return -1; - } - - /* Trim trailing slashes (except the root) */ - if ((root_len = git_fs_path_root(path->ptr)) < 0) - root_len = 0; - else - root_len++; - - while (path->size > (size_t)root_len && path->ptr[path->size - 1] == '/') - path->ptr[--path->size] = '\0'; - - /* if we are not supposed to made the last element, truncate it */ - if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) { - git_fs_path_dirname_r(path, path->ptr); - flags |= GIT_MKDIR_SKIP_LAST; - } - if ((flags & GIT_MKDIR_SKIP_LAST) != 0) { - git_fs_path_dirname_r(path, path->ptr); - } - - /* We were either given the root path (or trimmed it to - * the root), we don't have anything to do. - */ - if (path->size <= (size_t)root_len) - git_str_clear(path); - - return 0; -} - -int git_futils_mkdir( - const char *path, - mode_t mode, - uint32_t flags) -{ - git_str make_path = GIT_STR_INIT, parent_path = GIT_STR_INIT; - const char *relative; - struct git_futils_mkdir_options opts = { 0 }; - struct stat st; - size_t depth = 0; - int len = 0, root_len, error; - - if ((error = git_str_puts(&make_path, path)) < 0 || - (error = mkdir_canonicalize(&make_path, flags)) < 0 || - (error = git_str_puts(&parent_path, make_path.ptr)) < 0 || - make_path.size == 0) - goto done; - - root_len = git_fs_path_root(make_path.ptr); - - /* find the first parent directory that exists. this will be used - * as the base to dirname_relative. - */ - for (relative = make_path.ptr; parent_path.size; ) { - error = p_lstat(parent_path.ptr, &st); - - if (error == 0) { - break; - } else if (errno != ENOENT) { - git_error_set(GIT_ERROR_OS, "failed to stat '%s'", parent_path.ptr); - error = -1; - goto done; - } - - depth++; - - /* examine the parent of the current path */ - if ((len = git_fs_path_dirname_r(&parent_path, parent_path.ptr)) < 0) { - error = len; - goto done; - } - - GIT_ASSERT(len); - - /* - * We've walked all the given path's parents and it's either relative - * (the parent is simply '.') or rooted (the length is less than or - * equal to length of the root path). The path may be less than the - * root path length on Windows, where `C:` == `C:/`. - */ - if ((len == 1 && parent_path.ptr[0] == '.') || - (len == 1 && parent_path.ptr[0] == '/') || - len <= root_len) { - relative = make_path.ptr; - break; - } - - relative = make_path.ptr + len + 1; - - /* not recursive? just make this directory relative to its parent. */ - if ((flags & GIT_MKDIR_PATH) == 0) - break; - } - - /* we found an item at the location we're trying to create, - * validate it. - */ - if (depth == 0) { - error = mkdir_validate_dir(make_path.ptr, &st, mode, flags, &opts); - - if (!error) - error = mkdir_validate_mode( - make_path.ptr, &st, true, mode, flags, &opts); - - goto done; - } - - /* we already took `SKIP_LAST` and `SKIP_LAST2` into account when - * canonicalizing `make_path`. - */ - flags &= ~(GIT_MKDIR_SKIP_LAST2 | GIT_MKDIR_SKIP_LAST); - - error = git_futils_mkdir_relative(relative, - parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts); - -done: - git_str_dispose(&make_path); - git_str_dispose(&parent_path); - return error; -} - -int git_futils_mkdir_r(const char *path, const mode_t mode) -{ - return git_futils_mkdir(path, mode, GIT_MKDIR_PATH); -} - -int git_futils_mkdir_relative( - const char *relative_path, - const char *base, - mode_t mode, - uint32_t flags, - struct git_futils_mkdir_options *opts) -{ - git_str make_path = GIT_STR_INIT; - ssize_t root = 0, min_root_len; - char lastch = '/', *tail; - struct stat st; - struct git_futils_mkdir_options empty_opts = {0}; - int error; - - if (!opts) - opts = &empty_opts; - - /* build path and find "root" where we should start calling mkdir */ - if (git_fs_path_join_unrooted(&make_path, relative_path, base, &root) < 0) - return -1; - - if ((error = mkdir_canonicalize(&make_path, flags)) < 0 || - make_path.size == 0) - goto done; - - /* if we are not supposed to make the whole path, reset root */ - if ((flags & GIT_MKDIR_PATH) == 0) - root = git_str_rfind(&make_path, '/'); - - /* advance root past drive name or network mount prefix */ - min_root_len = git_fs_path_root(make_path.ptr); - if (root < min_root_len) - root = min_root_len; - while (root >= 0 && make_path.ptr[root] == '/') - ++root; - - /* clip root to make_path length */ - if (root > (ssize_t)make_path.size) - root = (ssize_t)make_path.size; /* i.e. NUL byte of string */ - if (root < 0) - root = 0; - - /* walk down tail of path making each directory */ - for (tail = &make_path.ptr[root]; *tail; *tail = lastch) { - bool mkdir_attempted = false; - - /* advance tail to include next path component */ - while (*tail == '/') - tail++; - while (*tail && *tail != '/') - tail++; - - /* truncate path at next component */ - lastch = *tail; - *tail = '\0'; - st.st_mode = 0; - - if (opts->cache_pathset && - git_hashset_str_contains(opts->cache_pathset, make_path.ptr)) - continue; - - /* See what's going on with this path component */ - opts->perfdata.stat_calls++; - -retry_lstat: - if (p_lstat(make_path.ptr, &st) < 0) { - if (mkdir_attempted || errno != ENOENT) { - git_error_set(GIT_ERROR_OS, "cannot access component in path '%s'", make_path.ptr); - error = -1; - goto done; - } - - git_error_clear(); - opts->perfdata.mkdir_calls++; - mkdir_attempted = true; - if (p_mkdir(make_path.ptr, mode) < 0) { - if (errno == EEXIST) - goto retry_lstat; - git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", make_path.ptr); - error = -1; - goto done; - } - } else { - if ((error = mkdir_validate_dir( - make_path.ptr, &st, mode, flags, opts)) < 0) - goto done; - } - - /* chmod if requested and necessary */ - if ((error = mkdir_validate_mode( - make_path.ptr, &st, (lastch == '\0'), mode, flags, opts)) < 0) - goto done; - - if (opts->cache_pathset && opts->cache_pool) { - char *cache_path; - size_t alloc_size; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, make_path.size, 1); - cache_path = git_pool_malloc(opts->cache_pool, alloc_size); - GIT_ERROR_CHECK_ALLOC(cache_path); - - memcpy(cache_path, make_path.ptr, make_path.size + 1); - - if ((error = git_hashset_str_add(opts->cache_pathset, cache_path)) < 0) - goto done; - } - } - - error = 0; - - /* check that full path really is a directory if requested & needed */ - if ((flags & GIT_MKDIR_VERIFY_DIR) != 0 && - lastch != '\0') { - opts->perfdata.stat_calls++; - - if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) { - git_error_set(GIT_ERROR_OS, "path is not a directory '%s'", - make_path.ptr); - error = GIT_ENOTFOUND; - } - } - -done: - git_str_dispose(&make_path); - return error; -} - -typedef struct { - const char *base; - size_t baselen; - uint32_t flags; - int depth; -} futils__rmdir_data; - -#define FUTILS_MAX_DEPTH 100 - -static int futils__error_cannot_rmdir(const char *path, const char *filemsg) -{ - if (filemsg) - git_error_set(GIT_ERROR_OS, "could not remove directory '%s': %s", - path, filemsg); - else - git_error_set(GIT_ERROR_OS, "could not remove directory '%s'", path); - - return -1; -} - -static int futils__rm_first_parent(git_str *path, const char *ceiling) -{ - int error = GIT_ENOTFOUND; - struct stat st; - - while (error == GIT_ENOTFOUND) { - git_str_rtruncate_at_char(path, '/'); - - if (!path->size || git__prefixcmp(path->ptr, ceiling) != 0) - error = 0; - else if (p_lstat_posixly(path->ptr, &st) == 0) { - if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) - error = p_unlink(path->ptr); - else if (!S_ISDIR(st.st_mode)) - error = -1; /* fail to remove non-regular file */ - } else if (errno != ENOTDIR) - error = -1; - } - - if (error) - futils__error_cannot_rmdir(path->ptr, "cannot remove parent"); - - return error; -} - -static int futils__rmdir_recurs_foreach(void *opaque, git_str *path) -{ - int error = 0; - futils__rmdir_data *data = opaque; - struct stat st; - - if (data->depth > FUTILS_MAX_DEPTH) - error = futils__error_cannot_rmdir( - path->ptr, "directory nesting too deep"); - - else if ((error = p_lstat_posixly(path->ptr, &st)) < 0) { - if (errno == ENOENT) - error = 0; - else if (errno == ENOTDIR) { - /* asked to remove a/b/c/d/e and a/b is a normal file */ - if ((data->flags & GIT_RMDIR_REMOVE_BLOCKERS) != 0) - error = futils__rm_first_parent(path, data->base); - else - futils__error_cannot_rmdir( - path->ptr, "parent is not directory"); - } - else - error = git_fs_path_set_error(errno, path->ptr, "rmdir"); - } - - else if (S_ISDIR(st.st_mode)) { - data->depth++; - - error = git_fs_path_direach(path, 0, futils__rmdir_recurs_foreach, data); - - data->depth--; - - if (error < 0) - return error; - - if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0) - return error; - - if ((error = p_rmdir(path->ptr)) < 0) { - if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) != 0 && - (errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY)) - error = 0; - else - error = git_fs_path_set_error(errno, path->ptr, "rmdir"); - } - } - - else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) { - if (p_unlink(path->ptr) < 0) - error = git_fs_path_set_error(errno, path->ptr, "remove"); - } - - else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0) - error = futils__error_cannot_rmdir(path->ptr, "still present"); - - return error; -} - -static int futils__rmdir_empty_parent(void *opaque, const char *path) -{ - futils__rmdir_data *data = opaque; - int error = 0; - - if (strlen(path) <= data->baselen) - error = GIT_ITEROVER; - - else if (p_rmdir(path) < 0) { - int en = errno; - - if (en == ENOENT || en == ENOTDIR) { - /* do nothing */ - } else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 && - en == EBUSY) { - error = git_fs_path_set_error(errno, path, "rmdir"); - } else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) { - error = GIT_ITEROVER; - } else { - error = git_fs_path_set_error(errno, path, "rmdir"); - } - } - - return error; -} - -int git_futils_rmdir_r( - const char *path, const char *base, uint32_t flags) -{ - int error; - git_str fullpath = GIT_STR_INIT; - futils__rmdir_data data; - - /* build path and find "root" where we should start calling mkdir */ - if (git_fs_path_join_unrooted(&fullpath, path, base, NULL) < 0) - return -1; - - memset(&data, 0, sizeof(data)); - data.base = base ? base : ""; - data.baselen = base ? strlen(base) : 0; - data.flags = flags; - - error = futils__rmdir_recurs_foreach(&data, &fullpath); - - /* remove now-empty parents if requested */ - if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0) - error = git_fs_path_walk_up( - &fullpath, base, futils__rmdir_empty_parent, &data); - - if (error == GIT_ITEROVER) { - git_error_clear(); - error = 0; - } - - git_str_dispose(&fullpath); - - return error; -} - -int git_futils_fake_symlink(const char *target, const char *path) -{ - int retcode = GIT_ERROR; - int fd = git_futils_creat_withpath(path, 0755, 0644); - if (fd >= 0) { - retcode = p_write(fd, target, strlen(target)); - p_close(fd); - } - return retcode; -} - -static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done) -{ - int error = 0; - char buffer[GIT_BUFSIZE_FILEIO]; - ssize_t len = 0; - - while (!error && (len = p_read(ifd, buffer, sizeof(buffer))) > 0) - /* p_write() does not have the same semantics as write(). It loops - * internally and will return 0 when it has completed writing. - */ - error = p_write(ofd, buffer, len); - - if (len < 0) { - git_error_set(GIT_ERROR_OS, "read error while copying file"); - error = (int)len; - } - - if (error < 0) - git_error_set(GIT_ERROR_OS, "write error while copying file"); - - if (close_fd_when_done) { - p_close(ifd); - p_close(ofd); - } - - return error; -} - -int git_futils_cp(const char *from, const char *to, mode_t filemode) -{ - int ifd, ofd; - - if ((ifd = git_futils_open_ro(from)) < 0) - return ifd; - - if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) { - p_close(ifd); - return git_fs_path_set_error(errno, to, "open for writing"); - } - - return cp_by_fd(ifd, ofd, true); -} - -int git_futils_touch(const char *path, time_t *when) -{ - struct p_timeval times[2]; - int ret; - - times[0].tv_sec = times[1].tv_sec = when ? *when : time(NULL); - times[0].tv_usec = times[1].tv_usec = 0; - - ret = p_utimes(path, times); - - return (ret < 0) ? git_fs_path_set_error(errno, path, "touch") : 0; -} - -static int cp_link(const char *from, const char *to, size_t link_size) -{ - int error = 0; - ssize_t read_len; - char *link_data; - size_t alloc_size; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, link_size, 1); - link_data = git__malloc(alloc_size); - GIT_ERROR_CHECK_ALLOC(link_data); - - read_len = p_readlink(from, link_data, link_size); - if (read_len != (ssize_t)link_size) { - git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", from); - error = -1; - } - else { - link_data[read_len] = '\0'; - - if (p_symlink(link_data, to) < 0) { - git_error_set(GIT_ERROR_OS, "could not symlink '%s' as '%s'", - link_data, to); - error = -1; - } - } - - git__free(link_data); - return error; -} - -typedef struct { - const char *to_root; - git_str to; - ssize_t from_prefix; - uint32_t flags; - uint32_t mkdir_flags; - mode_t dirmode; -} cp_r_info; - -#define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10) - -static int _cp_r_mkdir(cp_r_info *info, git_str *from) -{ - int error = 0; - - /* create root directory the first time we need to create a directory */ - if ((info->flags & GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT) == 0) { - error = git_futils_mkdir( - info->to_root, info->dirmode, - (info->flags & GIT_CPDIR_CHMOD_DIRS) ? GIT_MKDIR_CHMOD : 0); - - info->flags |= GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT; - } - - /* create directory with root as base to prevent excess chmods */ - if (!error) - error = git_futils_mkdir_relative( - from->ptr + info->from_prefix, info->to_root, - info->dirmode, info->mkdir_flags, NULL); - - return error; -} - -static int _cp_r_callback(void *ref, git_str *from) -{ - int error = 0; - cp_r_info *info = ref; - struct stat from_st, to_st; - bool exists = false; - - if ((info->flags & GIT_CPDIR_COPY_DOTFILES) == 0 && - from->ptr[git_fs_path_basename_offset(from)] == '.') - return 0; - - if ((error = git_str_joinpath( - &info->to, info->to_root, from->ptr + info->from_prefix)) < 0) - return error; - - if (!(error = git_fs_path_lstat(info->to.ptr, &to_st))) - exists = true; - else if (error != GIT_ENOTFOUND) - return error; - else { - git_error_clear(); - error = 0; - } - - if ((error = git_fs_path_lstat(from->ptr, &from_st)) < 0) - return error; - - if (S_ISDIR(from_st.st_mode)) { - mode_t oldmode = info->dirmode; - - /* if we are not chmod'ing, then overwrite dirmode */ - if ((info->flags & GIT_CPDIR_CHMOD_DIRS) == 0) - info->dirmode = from_st.st_mode; - - /* make directory now if CREATE_EMPTY_DIRS is requested and needed */ - if (!exists && (info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) != 0) - error = _cp_r_mkdir(info, from); - - /* recurse onto target directory */ - if (!error && (!exists || S_ISDIR(to_st.st_mode))) - error = git_fs_path_direach(from, 0, _cp_r_callback, info); - - if (oldmode != 0) - info->dirmode = oldmode; - - return error; - } - - if (exists) { - if ((info->flags & GIT_CPDIR_OVERWRITE) == 0) - return 0; - - if (p_unlink(info->to.ptr) < 0) { - git_error_set(GIT_ERROR_OS, "cannot overwrite existing file '%s'", - info->to.ptr); - return GIT_EEXISTS; - } - } - - /* Done if this isn't a regular file or a symlink */ - if (!S_ISREG(from_st.st_mode) && - (!S_ISLNK(from_st.st_mode) || - (info->flags & GIT_CPDIR_COPY_SYMLINKS) == 0)) - return 0; - - /* Make container directory on demand if needed */ - if ((info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0 && - (error = _cp_r_mkdir(info, from)) < 0) - return error; - - /* make symlink or regular file */ - if (info->flags & GIT_CPDIR_LINK_FILES) { - if ((error = p_link(from->ptr, info->to.ptr)) < 0) - git_error_set(GIT_ERROR_OS, "failed to link '%s'", from->ptr); - } else if (S_ISLNK(from_st.st_mode)) { - error = cp_link(from->ptr, info->to.ptr, (size_t)from_st.st_size); - } else { - mode_t usemode = from_st.st_mode; - - if ((info->flags & GIT_CPDIR_SIMPLE_TO_MODE) != 0) - usemode = GIT_PERMS_FOR_WRITE(usemode); - - error = git_futils_cp(from->ptr, info->to.ptr, usemode); - } - - return error; -} - -int git_futils_cp_r( - const char *from, - const char *to, - uint32_t flags, - mode_t dirmode) -{ - int error; - git_str path = GIT_STR_INIT; - cp_r_info info; - - if (git_str_joinpath(&path, from, "") < 0) /* ensure trailing slash */ - return -1; - - memset(&info, 0, sizeof(info)); - info.to_root = to; - info.flags = flags; - info.dirmode = dirmode; - info.from_prefix = path.size; - git_str_init(&info.to, 0); - - /* precalculate mkdir flags */ - if ((flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0) { - /* if not creating empty dirs, then use mkdir to create the path on - * demand right before files are copied. - */ - info.mkdir_flags = GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST; - if ((flags & GIT_CPDIR_CHMOD_DIRS) != 0) - info.mkdir_flags |= GIT_MKDIR_CHMOD_PATH; - } else { - /* otherwise, we will do simple mkdir as directories are encountered */ - info.mkdir_flags = - ((flags & GIT_CPDIR_CHMOD_DIRS) != 0) ? GIT_MKDIR_CHMOD : 0; - } - - error = _cp_r_callback(&info, &path); - - git_str_dispose(&path); - git_str_dispose(&info.to); - - return error; -} - -int git_futils_filestamp_check( - git_futils_filestamp *stamp, const char *path) -{ - struct stat st; - - /* if the stamp is NULL, then always reload */ - if (stamp == NULL) - return 1; - - if (p_stat(path, &st) < 0) - return GIT_ENOTFOUND; - - if (stamp->mtime.tv_sec == st.st_mtime && -#if defined(GIT_USE_NSEC) - stamp->mtime.tv_nsec == st.st_mtime_nsec && -#endif - stamp->size == (uint64_t)st.st_size && - stamp->ino == (unsigned int)st.st_ino) - return 0; - - stamp->mtime.tv_sec = st.st_mtime; -#if defined(GIT_USE_NSEC) - stamp->mtime.tv_nsec = st.st_mtime_nsec; -#endif - stamp->size = (uint64_t)st.st_size; - stamp->ino = (unsigned int)st.st_ino; - - return 1; -} - -void git_futils_filestamp_set( - git_futils_filestamp *target, const git_futils_filestamp *source) -{ - if (source) - memcpy(target, source, sizeof(*target)); - else - memset(target, 0, sizeof(*target)); -} - - -void git_futils_filestamp_set_from_stat( - git_futils_filestamp *stamp, struct stat *st) -{ - if (st) { - stamp->mtime.tv_sec = st->st_mtime; -#if defined(GIT_USE_NSEC) - stamp->mtime.tv_nsec = st->st_mtime_nsec; -#else - stamp->mtime.tv_nsec = 0; -#endif - stamp->size = (uint64_t)st->st_size; - stamp->ino = (unsigned int)st->st_ino; - } else { - memset(stamp, 0, sizeof(*stamp)); - } -} - -int git_futils_fsync_dir(const char *path) -{ -#ifdef GIT_WIN32 - GIT_UNUSED(path); - return 0; -#else - int fd, error = -1; - - if ((fd = p_open(path, O_RDONLY)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to open directory '%s' for fsync", path); - return -1; - } - - if ((error = p_fsync(fd)) < 0) - git_error_set(GIT_ERROR_OS, "failed to fsync directory '%s'", path); - - p_close(fd); - return error; -#endif -} - -int git_futils_fsync_parent(const char *path) -{ - char *parent; - int error; - - if ((parent = git_fs_path_dirname(path)) == NULL) - return -1; - - error = git_futils_fsync_dir(parent); - git__free(parent); - return error; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/futils.h b/vendor/libgit2-sys/libgit2/src/util/futils.h deleted file mode 100644 index 38894da..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/futils.h +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_futils_h__ -#define INCLUDE_futils_h__ - -#include "git2_util.h" - -#include "map.h" -#include "posix.h" -#include "fs_path.h" -#include "pool.h" -#include "hash.h" -#include "hashmap_str.h" - -/** - * Filebuffer methods - * - * Read whole files into an in-memory buffer for processing - */ -extern int git_futils_readbuffer(git_str *obj, const char *path); -extern int git_futils_readbuffer_updated( - git_str *obj, - const char *path, - unsigned char checksum[GIT_HASH_SHA256_SIZE], - int *updated); -extern int git_futils_readbuffer_fd_full(git_str *obj, git_file fd); -extern int git_futils_readbuffer_fd(git_str *obj, git_file fd, size_t len); - -/* Additional constants for `git_futils_writebuffer`'s `open_flags`. We - * support these internally and they will be removed before the `open` call. - * - * Not all platforms define O_FSYNC. Fall back to O_SYNC (the POSIX - * standard name; O_FSYNC is a non-standard alias) when available, - * otherwise use a sentinel value that won't collide with real open - * flags. Avoid (1 << 31) since left-shifting into the sign bit of - * a signed int is undefined behavior. - */ -#if !defined(O_FSYNC) && defined(O_SYNC) -# define O_FSYNC O_SYNC -#elif !defined(O_FSYNC) -# define O_FSYNC (1 << 30) -#endif - -extern int git_futils_writebuffer( - const git_str *buf, const char *path, int open_flags, mode_t mode); - -/** - * File utils - * - * These are custom filesystem-related helper methods. They are - * rather high level, and wrap the underlying POSIX methods - * - * All these methods return 0 on success, - * or an error code on failure and an error message is set. - */ - -/** - * Create and open a file, while also - * creating all the folders in its path - */ -extern int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode); - -/** - * Create and open a process-locked file - */ -extern int git_futils_creat_locked(const char *path, const mode_t mode); - -/** - * Create and open a process-locked file, while - * also creating all the folders in its path - */ -extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode); - -/** - * Create a path recursively. - */ -extern int git_futils_mkdir_r(const char *path, const mode_t mode); - -/** - * Flags to pass to `git_futils_mkdir`. - * - * * GIT_MKDIR_EXCL is "exclusive" - i.e. generate an error if dir exists. - * * GIT_MKDIR_PATH says to make all components in the path. - * * GIT_MKDIR_CHMOD says to chmod the final directory entry after creation - * * GIT_MKDIR_CHMOD_PATH says to chmod each directory component in the path - * * GIT_MKDIR_SKIP_LAST says to leave off the last element of the path - * * GIT_MKDIR_SKIP_LAST2 says to leave off the last 2 elements of the path - * * GIT_MKDIR_VERIFY_DIR says confirm final item is a dir, not just EEXIST - * * GIT_MKDIR_REMOVE_FILES says to remove files and recreate dirs - * * GIT_MKDIR_REMOVE_SYMLINKS says to remove symlinks and recreate dirs - * - * Note that the chmod options will be executed even if the directory already - * exists, unless GIT_MKDIR_EXCL is given. - */ -typedef enum { - GIT_MKDIR_EXCL = 1, - GIT_MKDIR_PATH = 2, - GIT_MKDIR_CHMOD = 4, - GIT_MKDIR_CHMOD_PATH = 8, - GIT_MKDIR_SKIP_LAST = 16, - GIT_MKDIR_SKIP_LAST2 = 32, - GIT_MKDIR_VERIFY_DIR = 64, - GIT_MKDIR_REMOVE_FILES = 128, - GIT_MKDIR_REMOVE_SYMLINKS = 256 -} git_futils_mkdir_flags; - -struct git_futils_mkdir_perfdata -{ - size_t stat_calls; - size_t mkdir_calls; - size_t chmod_calls; -}; - -struct git_futils_mkdir_options -{ - /* - * Callers can optionally pass an allocation pool and a - * hashset of strings; mkdir will populate these with the - * path(s) it creates; this can be useful for repeated calls - * to mkdir. This will reduce I/O by avoiding testing for the - * existence of intermediate directories that it knows already - * exist (because it created them). - */ - git_pool *cache_pool; - git_hashset_str *cache_pathset; - - struct git_futils_mkdir_perfdata perfdata; -}; - -/** - * Create a directory or entire path. - * - * This makes a directory (and the entire path leading up to it if requested), - * and optionally chmods the directory immediately after (or each part of the - * path if requested). - * - * @param path The path to create, relative to base. - * @param base Root for relative path. These directories will never be made. - * @param mode The mode to use for created directories. - * @param flags Combination of the mkdir flags above. - * @param opts Extended options, or null. - * @return 0 on success, else error code - */ -extern int git_futils_mkdir_relative(const char *path, const char *base, mode_t mode, uint32_t flags, struct git_futils_mkdir_options *opts); - -/** - * Create a directory or entire path. Similar to `git_futils_mkdir_relative` - * without performance data. - */ -extern int git_futils_mkdir(const char *path, mode_t mode, uint32_t flags); - -/** - * Create all the folders required to contain - * the full path of a file - */ -extern int git_futils_mkpath2file(const char *path, const mode_t mode); - -/** - * Flags to pass to `git_futils_rmdir_r`. - * - * * GIT_RMDIR_EMPTY_HIERARCHY - the default; remove hierarchy of empty - * dirs and generate error if any files are found. - * * GIT_RMDIR_REMOVE_FILES - attempt to remove files in the hierarchy. - * * GIT_RMDIR_SKIP_NONEMPTY - skip non-empty directories with no error. - * * GIT_RMDIR_EMPTY_PARENTS - remove containing directories up to base - * if removing this item leaves them empty - * * GIT_RMDIR_REMOVE_BLOCKERS - remove blocking file that causes ENOTDIR - * * GIT_RMDIR_SKIP_ROOT - don't remove root directory itself - */ -typedef enum { - GIT_RMDIR_EMPTY_HIERARCHY = 0, - GIT_RMDIR_REMOVE_FILES = (1 << 0), - GIT_RMDIR_SKIP_NONEMPTY = (1 << 1), - GIT_RMDIR_EMPTY_PARENTS = (1 << 2), - GIT_RMDIR_REMOVE_BLOCKERS = (1 << 3), - GIT_RMDIR_SKIP_ROOT = (1 << 4) -} git_futils_rmdir_flags; - -/** - * Remove path and any files and directories beneath it. - * - * @param path Path to the top level directory to process. - * @param base Root for relative path. - * @param flags Combination of git_futils_rmdir_flags values - * @return 0 on success; -1 on error. - */ -extern int git_futils_rmdir_r(const char *path, const char *base, uint32_t flags); - -/** - * Create and open a temporary file with a `_git2_` suffix in a - * protected directory; the file created will created will honor - * the current `umask`. Writes the filename into path_out. - * - * This function uses a high-quality PRNG seeded by the system's - * entropy pool _where available_ and falls back to a simple seed - * (time plus system information) when not. This is suitable for - * writing within a protected directory, but the system's safe - * temporary file creation functions should be preferred where - * available when writing into world-writable (temp) directories. - * - * @return On success, an open file descriptor, else an error code < 0. - */ -extern int git_futils_mktmp(git_str *path_out, const char *filename, mode_t mode); - -/** - * Move a file on the filesystem, create the - * destination path if it doesn't exist - */ -extern int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode); - -/** - * Copy a file - * - * The filemode will be used for the newly created file. - */ -extern int git_futils_cp( - const char *from, - const char *to, - mode_t filemode); - -/** - * Set the files atime and mtime to the given time, or the current time - * if `ts` is NULL. - */ -extern int git_futils_touch(const char *path, time_t *when); - -/** - * Flags that can be passed to `git_futils_cp_r`. - * - * - GIT_CPDIR_CREATE_EMPTY_DIRS: create directories even if there are no - * files under them (otherwise directories will only be created lazily - * when a file inside them is copied). - * - GIT_CPDIR_COPY_SYMLINKS: copy symlinks, otherwise they are ignored. - * - GIT_CPDIR_COPY_DOTFILES: copy files with leading '.', otherwise ignored. - * - GIT_CPDIR_OVERWRITE: overwrite pre-existing files with source content, - * otherwise they are silently skipped. - * - GIT_CPDIR_CHMOD_DIRS: explicitly chmod directories to `dirmode` - * - GIT_CPDIR_SIMPLE_TO_MODE: default tries to replicate the mode of the - * source file to the target; with this flag, always use 0666 (or 0777 if - * source has exec bits set) for target. - * - GIT_CPDIR_LINK_FILES will try to use hardlinks for the files - */ -typedef enum { - GIT_CPDIR_CREATE_EMPTY_DIRS = (1u << 0), - GIT_CPDIR_COPY_SYMLINKS = (1u << 1), - GIT_CPDIR_COPY_DOTFILES = (1u << 2), - GIT_CPDIR_OVERWRITE = (1u << 3), - GIT_CPDIR_CHMOD_DIRS = (1u << 4), - GIT_CPDIR_SIMPLE_TO_MODE = (1u << 5), - GIT_CPDIR_LINK_FILES = (1u << 6) -} git_futils_cpdir_flags; - -/** - * Copy a directory tree. - * - * This copies directories and files from one root to another. You can - * pass a combination of GIT_CPDIR flags as defined above. - * - * If you pass the CHMOD flag, then the dirmode will be applied to all - * directories that are created during the copy, overriding the natural - * permissions. If you do not pass the CHMOD flag, then the dirmode - * will actually be copied from the source files and the `dirmode` arg - * will be ignored. - */ -extern int git_futils_cp_r( - const char *from, - const char *to, - uint32_t flags, - mode_t dirmode); - -/** - * Open a file readonly and set error if needed. - */ -extern int git_futils_open_ro(const char *path); - -/** - * Truncate a file, creating it if it doesn't exist. - */ -extern int git_futils_truncate(const char *path, int mode); - -/** - * Get the filesize in bytes of a file - */ -extern int git_futils_filesize(uint64_t *out, git_file fd); - -#define GIT_PERMS_IS_EXEC(MODE) (((MODE) & 0100) != 0) -#define GIT_PERMS_CANONICAL(MODE) (GIT_PERMS_IS_EXEC(MODE) ? 0755 : 0644) -#define GIT_PERMS_FOR_WRITE(MODE) (GIT_PERMS_IS_EXEC(MODE) ? 0777 : 0666) - -#define GIT_MODE_PERMS_MASK 0777 -#define GIT_MODE_TYPE_MASK 0170000 -#define GIT_MODE_TYPE(MODE) ((MODE) & GIT_MODE_TYPE_MASK) -#define GIT_MODE_ISBLOB(MODE) (GIT_MODE_TYPE(MODE) == GIT_MODE_TYPE(GIT_FILEMODE_BLOB)) - -/** - * Convert a mode_t from the OS to a legal git mode_t value. - */ -extern mode_t git_futils_canonical_mode(mode_t raw_mode); - - -/** - * Read-only map all or part of a file into memory. - * When possible this function should favor a virtual memory - * style mapping over some form of malloc()+read(), as the - * data access will be random and is not likely to touch the - * majority of the region requested. - * - * @param out buffer to populate with the mapping information. - * @param fd open descriptor to configure the mapping from. - * @param begin first byte to map, this should be page aligned. - * @param len number of bytes to map. - * @return - * - 0 on success; - * - -1 on error. - */ -extern int git_futils_mmap_ro( - git_map *out, - git_file fd, - off64_t begin, - size_t len); - -/** - * Read-only map an entire file. - * - * @param out buffer to populate with the mapping information. - * @param path path to file to be opened. - * @return - * - 0 on success; - * - GIT_ENOTFOUND if not found; - * - -1 on an unspecified OS related error. - */ -extern int git_futils_mmap_ro_file( - git_map *out, - const char *path); - -/** - * Release the memory associated with a previous memory mapping. - * @param map the mapping description previously configured. - */ -extern void git_futils_mmap_free(git_map *map); - -/** - * Create a "fake" symlink (text file containing the target path). - * - * @param target original symlink target - * @param path symlink file to be created - * @return 0 on success, -1 on error - */ -extern int git_futils_fake_symlink(const char *target, const char *path); - -/** - * A file stamp represents a snapshot of information about a file that can - * be used to test if the file changes. This portable implementation is - * based on stat data about that file, but it is possible that OS specific - * versions could be implemented in the future. - */ -typedef struct { - struct timespec mtime; - uint64_t size; - unsigned int ino; -} git_futils_filestamp; - -/** - * Compare stat information for file with reference info. - * - * This function updates the file stamp to current data for the given path - * and returns 0 if the file is up-to-date relative to the prior setting, - * 1 if the file has been changed, or GIT_ENOTFOUND if the file doesn't - * exist. This will not call git_error_set, so you must set the error if you - * plan to return an error. - * - * @param stamp File stamp to be checked - * @param path Path to stat and check if changed - * @return 0 if up-to-date, 1 if out-of-date, GIT_ENOTFOUND if cannot stat - */ -extern int git_futils_filestamp_check( - git_futils_filestamp *stamp, const char *path); - -/** - * Set or reset file stamp data - * - * This writes the target file stamp. If the source is NULL, this will set - * the target stamp to values that will definitely be out of date. If the - * source is not NULL, this copies the source values to the target. - * - * @param tgt File stamp to write to - * @param src File stamp to copy from or NULL to clear the target - */ -extern void git_futils_filestamp_set( - git_futils_filestamp *tgt, const git_futils_filestamp *src); - -/** - * Set file stamp data from stat structure - */ -extern void git_futils_filestamp_set_from_stat( - git_futils_filestamp *stamp, struct stat *st); - -/** - * `fsync` the parent directory of the given path, if `fsync` is - * supported for directories on this platform. - * - * @param path Path of the directory to sync. - * @return 0 on success, -1 on error - */ -extern int git_futils_fsync_dir(const char *path); - -/** - * `fsync` the parent directory of the given path, if `fsync` is - * supported for directories on this platform. - * - * @param path Path of the file whose parent directory should be synced. - * @return 0 on success, -1 on error - */ -extern int git_futils_fsync_parent(const char *path); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/git2_features.h.in b/vendor/libgit2-sys/libgit2/src/util/git2_features.h.in deleted file mode 100644 index cd14cc2..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/git2_features.h.in +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef INCLUDE_features_h__ -#define INCLUDE_features_h__ - -#cmakedefine GIT_DEBUG_POOL 1 -#cmakedefine GIT_DEBUG_STRICT_ALLOC 1 -#cmakedefine GIT_DEBUG_STRICT_OPEN 1 - -#cmakedefine GIT_THREADS 1 -#cmakedefine GIT_WIN32_LEAKCHECK 1 - -#cmakedefine GIT_ARCH_64 1 -#cmakedefine GIT_ARCH_32 1 - -#cmakedefine GIT_USE_ICONV 1 -#cmakedefine GIT_USE_NSEC 1 -#cmakedefine GIT_USE_STAT_MTIM 1 -#cmakedefine GIT_USE_STAT_MTIMESPEC 1 -#cmakedefine GIT_USE_STAT_MTIME_NSEC 1 -#cmakedefine GIT_USE_FUTIMENS 1 - -#cmakedefine GIT_REGEX_REGCOMP_L -#cmakedefine GIT_REGEX_REGCOMP -#cmakedefine GIT_REGEX_PCRE -#cmakedefine GIT_REGEX_PCRE2 -#cmakedefine GIT_REGEX_BUILTIN 1 - -#cmakedefine GIT_QSORT_BSD -#cmakedefine GIT_QSORT_GNU -#cmakedefine GIT_QSORT_C11 -#cmakedefine GIT_QSORT_MSC - -#cmakedefine GIT_SSH 1 -#cmakedefine GIT_SSH_EXEC 1 -#cmakedefine GIT_SSH_LIBSSH2 1 -#cmakedefine GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1 - -#cmakedefine GIT_NTLM 1 -#cmakedefine GIT_GSSAPI 1 -#cmakedefine GIT_GSSFRAMEWORK 1 - -#cmakedefine GIT_WINHTTP 1 -#cmakedefine GIT_HTTPS 1 -#cmakedefine GIT_OPENSSL 1 -#cmakedefine GIT_OPENSSL_DYNAMIC 1 -#cmakedefine GIT_SECURE_TRANSPORT 1 -#cmakedefine GIT_MBEDTLS 1 -#cmakedefine GIT_SCHANNEL 1 - -#cmakedefine GIT_HTTPPARSER_HTTPPARSER 1 -#cmakedefine GIT_HTTPPARSER_LLHTTP 1 -#cmakedefine GIT_HTTPPARSER_BUILTIN 1 - -#cmakedefine GIT_SHA1_COLLISIONDETECT 1 -#cmakedefine GIT_SHA1_WIN32 1 -#cmakedefine GIT_SHA1_COMMON_CRYPTO 1 -#cmakedefine GIT_SHA1_OPENSSL 1 -#cmakedefine GIT_SHA1_OPENSSL_FIPS 1 -#cmakedefine GIT_SHA1_OPENSSL_DYNAMIC 1 -#cmakedefine GIT_SHA1_MBEDTLS 1 - -#cmakedefine GIT_SHA256_BUILTIN 1 -#cmakedefine GIT_SHA256_WIN32 1 -#cmakedefine GIT_SHA256_COMMON_CRYPTO 1 -#cmakedefine GIT_SHA256_OPENSSL 1 -#cmakedefine GIT_SHA256_OPENSSL_FIPS 1 -#cmakedefine GIT_SHA256_OPENSSL_DYNAMIC 1 -#cmakedefine GIT_SHA256_MBEDTLS 1 - -#cmakedefine GIT_COMPRESSION_BUILTIN 1 -#cmakedefine GIT_COMPRESSION_ZLIB 1 - -#cmakedefine GIT_RAND_GETENTROPY 1 -#cmakedefine GIT_RAND_GETLOADAVG 1 - -#cmakedefine GIT_IO_POLL 1 -#cmakedefine GIT_IO_WSAPOLL 1 -#cmakedefine GIT_IO_SELECT 1 - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/git2_util.h b/vendor/libgit2-sys/libgit2/src/util/git2_util.h deleted file mode 100644 index d47ce5f..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/git2_util.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_git2_util_h__ -#define INCLUDE_git2_util_h__ - -#if !defined(LIBGIT2_NO_FEATURES_H) -# include "git2_features.h" -#endif - -#include "git2/common.h" -#include "git2/sys/errors.h" -#include "cc-compat.h" - -typedef struct git_str git_str; - -/** Declare a function as always inlined. */ -#if defined(_MSC_VER) -# define GIT_INLINE(type) static __inline type -#elif defined(__GNUC__) -# define GIT_INLINE(type) static __inline__ type -#else -# define GIT_INLINE(type) static type -#endif - -/** Support for gcc/clang __has_builtin intrinsic */ -#ifndef __has_builtin -# define __has_builtin(x) 0 -#endif - -/** - * Declare that a function's return value must be used. - * - * Used mostly to guard against potential silent bugs at runtime. This is - * recommended to be added to functions that: - * - * - Allocate / reallocate memory. This prevents memory leaks or errors where - * buffers are expected to have grown to a certain size, but could not be - * resized. - * - Acquire locks. When a lock cannot be acquired, that will almost certainly - * cause a data race / undefined behavior. - */ -#if defined(__GNUC__) -# define GIT_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#else -# define GIT_WARN_UNUSED_RESULT -#endif - -#if (defined(_WIN32)) && !defined(__CYGWIN__) -# define GIT_WIN32 1 -#endif - -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef GIT_WIN32 - -# include -# include -# include -# include -# include -# include "win32/msvc-compat.h" -# include "win32/mingw-compat.h" -# include "win32/win32-compat.h" -# include "win32/w32_common.h" -# include "win32/version.h" -# include "win32/error.h" -# ifdef GIT_THREADS -# include "win32/thread.h" -# endif - -#else - -# include -# include -# ifdef GIT_THREADS -# include -# include -# endif - -#define GIT_LIBGIT2_CALL -#define GIT_SYSTEM_CALL - -#ifdef GIT_USE_STAT_ATIMESPEC -# define st_atim st_atimespec -# define st_ctim st_ctimespec -# define st_mtim st_mtimespec -#endif - -# include - -#endif - -#include "git2/types.h" -#include "git2/errors.h" -#include "thread.h" -#include "integer.h" -#include "assert_safe.h" - -#include "posix.h" - -#define GIT_BUFSIZE_DEFAULT 65536 -#define GIT_BUFSIZE_FILEIO GIT_BUFSIZE_DEFAULT -#define GIT_BUFSIZE_FILTERIO GIT_BUFSIZE_DEFAULT -#define GIT_BUFSIZE_NETIO GIT_BUFSIZE_DEFAULT - - -/** - * Check a pointer allocation result, returning -1 if it failed. - */ -#define GIT_ERROR_CHECK_ALLOC(ptr) do { \ - if ((ptr) == NULL) { return -1; } \ - } while(0) - -/** - * Check a buffer allocation result, returning -1 if it failed. - */ -#define GIT_ERROR_CHECK_ALLOC_STR(buf) do { \ - if ((void *)(buf) == NULL || git_str_oom(buf)) { return -1; } \ - } while(0) - -/** - * Check a return value and propagate result if non-zero. - */ -#define GIT_ERROR_CHECK_ERROR(code) \ - do { int _err = (code); if (_err) return _err; } while (0) - - -/** Check for additive overflow, setting an error if would occur. */ -#define GIT_ADD_SIZET_OVERFLOW(out, one, two) \ - (git__add_sizet_overflow(out, one, two) ? (git_error_set_oom(), 1) : 0) - -/** Check for additive overflow, setting an error if would occur. */ -#define GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize) \ - (git__multiply_sizet_overflow(out, nelem, elsize) ? (git_error_set_oom(), 1) : 0) - -/** Check for additive overflow, failing if it would occur. */ -#define GIT_ERROR_CHECK_ALLOC_ADD(out, one, two) \ - if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { return -1; } - -#define GIT_ERROR_CHECK_ALLOC_ADD3(out, one, two, three) \ - if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { return -1; } - -#define GIT_ERROR_CHECK_ALLOC_ADD4(out, one, two, three, four) \ - if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { return -1; } - -#define GIT_ERROR_CHECK_ALLOC_ADD5(out, one, two, three, four, five) \ - if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), four) || \ - GIT_ADD_SIZET_OVERFLOW(out, *(out), five)) { return -1; } - -/** Check for multiplicative overflow, failing if it would occur. */ -#define GIT_ERROR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \ - if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { return -1; } - -#include "util.h" -#include "ctype_compat.h" - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash.c b/vendor/libgit2-sys/libgit2/src/util/hash.c deleted file mode 100644 index ff900ce..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "hash.h" - -int git_hash_global_init(void) -{ - if (git_hash_sha1_global_init() < 0 || - git_hash_sha256_global_init() < 0) - return -1; - - return 0; -} - -int git_hash_ctx_init(git_hash_ctx *ctx, git_hash_algorithm_t algorithm) -{ - int error; - - switch (algorithm) { - case GIT_HASH_ALGORITHM_SHA1: - error = git_hash_sha1_ctx_init(&ctx->ctx.sha1); - break; - case GIT_HASH_ALGORITHM_SHA256: - error = git_hash_sha256_ctx_init(&ctx->ctx.sha256); - break; - default: - git_error_set(GIT_ERROR_INTERNAL, "unknown hash algorithm"); - error = -1; - } - - ctx->algorithm = algorithm; - return error; -} - -void git_hash_ctx_cleanup(git_hash_ctx *ctx) -{ - switch (ctx->algorithm) { - case GIT_HASH_ALGORITHM_SHA1: - git_hash_sha1_ctx_cleanup(&ctx->ctx.sha1); - return; - case GIT_HASH_ALGORITHM_SHA256: - git_hash_sha256_ctx_cleanup(&ctx->ctx.sha256); - return; - default: - /* unreachable */ ; - } -} - -int git_hash_init(git_hash_ctx *ctx) -{ - switch (ctx->algorithm) { - case GIT_HASH_ALGORITHM_SHA1: - return git_hash_sha1_init(&ctx->ctx.sha1); - case GIT_HASH_ALGORITHM_SHA256: - return git_hash_sha256_init(&ctx->ctx.sha256); - default: - /* unreachable */ ; - } - - git_error_set(GIT_ERROR_INTERNAL, "unknown hash algorithm"); - return -1; -} - -int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) -{ - switch (ctx->algorithm) { - case GIT_HASH_ALGORITHM_SHA1: - return git_hash_sha1_update(&ctx->ctx.sha1, data, len); - case GIT_HASH_ALGORITHM_SHA256: - return git_hash_sha256_update(&ctx->ctx.sha256, data, len); - default: - /* unreachable */ ; - } - - git_error_set(GIT_ERROR_INTERNAL, "unknown hash algorithm"); - return -1; -} - -int git_hash_final(unsigned char *out, git_hash_ctx *ctx) -{ - switch (ctx->algorithm) { - case GIT_HASH_ALGORITHM_SHA1: - return git_hash_sha1_final(out, &ctx->ctx.sha1); - case GIT_HASH_ALGORITHM_SHA256: - return git_hash_sha256_final(out, &ctx->ctx.sha256); - default: - /* unreachable */ ; - } - - git_error_set(GIT_ERROR_INTERNAL, "unknown hash algorithm"); - return -1; -} - -int git_hash_buf( - unsigned char *out, - const void *data, - size_t len, - git_hash_algorithm_t algorithm) -{ - git_hash_ctx ctx; - int error = 0; - - if (git_hash_ctx_init(&ctx, algorithm) < 0) - return -1; - - if ((error = git_hash_update(&ctx, data, len)) >= 0) - error = git_hash_final(out, &ctx); - - git_hash_ctx_cleanup(&ctx); - - return error; -} - -int git_hash_vec( - unsigned char *out, - git_str_vec *vec, - size_t n, - git_hash_algorithm_t algorithm) -{ - git_hash_ctx ctx; - size_t i; - int error = 0; - - if (git_hash_ctx_init(&ctx, algorithm) < 0) - return -1; - - for (i = 0; i < n; i++) { - if ((error = git_hash_update(&ctx, vec[i].data, vec[i].len)) < 0) - goto done; - } - - error = git_hash_final(out, &ctx); - -done: - git_hash_ctx_cleanup(&ctx); - - return error; -} - -int git_hash_fmt(char *out, unsigned char *hash, size_t hash_len) -{ - static char hex[] = "0123456789abcdef"; - char *str = out; - size_t i; - - for (i = 0; i < hash_len; i++) { - *str++ = hex[hash[i] >> 4]; - *str++ = hex[hash[i] & 0x0f]; - } - - *str++ = '\0'; - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/hash.h b/vendor/libgit2-sys/libgit2/src/util/hash.h deleted file mode 100644 index 21fcaf0..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_hash_h__ -#define INCLUDE_hash_h__ - -#include "git2_util.h" - -#include "hash/sha.h" - -typedef struct { - void *data; - size_t len; -} git_str_vec; - -typedef enum { - GIT_HASH_ALGORITHM_NONE = 0, - GIT_HASH_ALGORITHM_SHA1, - GIT_HASH_ALGORITHM_SHA256 -} git_hash_algorithm_t; - -#define GIT_HASH_MAX_SIZE GIT_HASH_SHA256_SIZE - -typedef struct git_hash_ctx { - union { - git_hash_sha1_ctx sha1; - git_hash_sha256_ctx sha256; - } ctx; - git_hash_algorithm_t algorithm; -} git_hash_ctx; - -int git_hash_global_init(void); - -int git_hash_ctx_init(git_hash_ctx *ctx, git_hash_algorithm_t algorithm); -void git_hash_ctx_cleanup(git_hash_ctx *ctx); - -int git_hash_init(git_hash_ctx *c); -int git_hash_update(git_hash_ctx *c, const void *data, size_t len); -int git_hash_final(unsigned char *out, git_hash_ctx *c); - -int git_hash_buf(unsigned char *out, const void *data, size_t len, git_hash_algorithm_t algorithm); -int git_hash_vec(unsigned char *out, git_str_vec *vec, size_t n, git_hash_algorithm_t algorithm); - -int git_hash_fmt(char *out, unsigned char *hash, size_t hash_len); - -GIT_INLINE(size_t) git_hash_size(git_hash_algorithm_t algorithm) { - switch (algorithm) { - case GIT_HASH_ALGORITHM_SHA1: - return GIT_HASH_SHA1_SIZE; - case GIT_HASH_ALGORITHM_SHA256: - return GIT_HASH_SHA256_SIZE; - default: - return 0; - } -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/builtin.c b/vendor/libgit2-sys/libgit2/src/util/hash/builtin.c deleted file mode 100644 index b4736ef..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/builtin.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "builtin.h" - -int git_hash_sha256_global_init(void) -{ - return 0; -} - -int git_hash_sha256_ctx_init(git_hash_sha256_ctx *ctx) -{ - return git_hash_sha256_init(ctx); -} - -void git_hash_sha256_ctx_cleanup(git_hash_sha256_ctx *ctx) -{ - GIT_UNUSED(ctx); -} - -int git_hash_sha256_init(git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - if (SHA256Reset(&ctx->c)) { - git_error_set(GIT_ERROR_SHA, "SHA256 error"); - return -1; - } - return 0; -} - -int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *_data, size_t len) -{ - const unsigned char *data = _data; - GIT_ASSERT_ARG(ctx); - - while (len > 0) { - unsigned int chunk = (len > UINT_MAX) ? UINT_MAX : (unsigned int)len; - - if (SHA256Input(&ctx->c, data, chunk)) { - git_error_set(GIT_ERROR_SHA, "SHA256 error"); - return -1; - } - - data += chunk; - len -= chunk; - } - - return 0; -} - -int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - if (SHA256Result(&ctx->c, out)) { - git_error_set(GIT_ERROR_SHA, "SHA256 error"); - return -1; - } - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/builtin.h b/vendor/libgit2-sys/libgit2/src/util/hash/builtin.h deleted file mode 100644 index 769df1a..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/builtin.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_hash_builtin_h__ -#define INCLUDE_hash_builtin_h__ - -#include "hash/sha.h" - -#include "rfc6234/sha.h" - -struct git_hash_sha256_ctx { - SHA256Context c; -}; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/collisiondetect.c b/vendor/libgit2-sys/libgit2/src/util/hash/collisiondetect.c deleted file mode 100644 index c51a402..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/collisiondetect.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "collisiondetect.h" - -int git_hash_sha1_global_init(void) -{ - return 0; -} - -int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) -{ - return git_hash_sha1_init(ctx); -} - -void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) -{ - GIT_UNUSED(ctx); -} - -int git_hash_sha1_init(git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - SHA1DCInit(&ctx->c); - return 0; -} - -int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx); - SHA1DCUpdate(&ctx->c, data, len); - return 0; -} - -int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - if (SHA1DCFinal(out, &ctx->c)) { - git_error_set(GIT_ERROR_SHA, "SHA1 collision attack detected"); - return -1; - } - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/collisiondetect.h b/vendor/libgit2-sys/libgit2/src/util/hash/collisiondetect.h deleted file mode 100644 index 8de5502..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/collisiondetect.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_hash_collisiondetect_h__ -#define INCLUDE_hash_collisiondetect_h__ - -#include "hash/sha.h" - -#include "sha1dc/sha1.h" - -struct git_hash_sha1_ctx { - SHA1_CTX c; -}; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/common_crypto.c b/vendor/libgit2-sys/libgit2/src/util/hash/common_crypto.c deleted file mode 100644 index b327ba9..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/common_crypto.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "common_crypto.h" - -#define CC_LONG_MAX ((CC_LONG)-1) - -#ifdef GIT_SHA1_COMMON_CRYPTO - -int git_hash_sha1_global_init(void) -{ - return 0; -} - -int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) -{ - return git_hash_sha1_init(ctx); -} - -void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) -{ - GIT_UNUSED(ctx); -} - -int git_hash_sha1_init(git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - CC_SHA1_Init(&ctx->c); - return 0; -} - -int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len) -{ - const unsigned char *data = _data; - - GIT_ASSERT_ARG(ctx); - - while (len > 0) { - CC_LONG chunk = (len > CC_LONG_MAX) ? CC_LONG_MAX : (CC_LONG)len; - - CC_SHA1_Update(&ctx->c, data, chunk); - - data += chunk; - len -= chunk; - } - - return 0; -} - -int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - CC_SHA1_Final(out, &ctx->c); - return 0; -} - -#endif - -#ifdef GIT_SHA256_COMMON_CRYPTO - -int git_hash_sha256_global_init(void) -{ - return 0; -} - -int git_hash_sha256_ctx_init(git_hash_sha256_ctx *ctx) -{ - return git_hash_sha256_init(ctx); -} - -void git_hash_sha256_ctx_cleanup(git_hash_sha256_ctx *ctx) -{ - GIT_UNUSED(ctx); -} - -int git_hash_sha256_init(git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - CC_SHA256_Init(&ctx->c); - return 0; -} - -int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *_data, size_t len) -{ - const unsigned char *data = _data; - - GIT_ASSERT_ARG(ctx); - - while (len > 0) { - CC_LONG chunk = (len > CC_LONG_MAX) ? CC_LONG_MAX : (CC_LONG)len; - - CC_SHA256_Update(&ctx->c, data, chunk); - - data += chunk; - len -= chunk; - } - - return 0; -} - -int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - CC_SHA256_Final(out, &ctx->c); - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/common_crypto.h b/vendor/libgit2-sys/libgit2/src/util/hash/common_crypto.h deleted file mode 100644 index 157712b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/common_crypto.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_hash_common_crypto_h__ -#define INCLUDE_hash_common_crypto_h__ - -#include "hash/sha.h" - -#include - -#ifdef GIT_SHA1_COMMON_CRYPTO -struct git_hash_sha1_ctx { - CC_SHA1_CTX c; -}; -#endif - -#ifdef GIT_SHA256_COMMON_CRYPTO -struct git_hash_sha256_ctx { - CC_SHA256_CTX c; -}; -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/mbedtls.c b/vendor/libgit2-sys/libgit2/src/util/hash/mbedtls.c deleted file mode 100644 index ecdfb78..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/mbedtls.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "mbedtls.h" - -#ifdef GIT_SHA1_MBEDTLS - -int git_hash_sha1_global_init(void) -{ - return 0; -} - -int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) -{ - return git_hash_sha1_init(ctx); -} - -void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) -{ - if (ctx) - mbedtls_sha1_free(&ctx->c); -} - -int git_hash_sha1_init(git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - mbedtls_sha1_init(&ctx->c); - mbedtls_sha1_starts(&ctx->c); - return 0; -} - -int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx); - mbedtls_sha1_update(&ctx->c, data, len); - return 0; -} - -int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - mbedtls_sha1_finish(&ctx->c, out); - return 0; -} - -#endif - -#ifdef GIT_SHA256_MBEDTLS - -int git_hash_sha256_global_init(void) -{ - return 0; -} - -int git_hash_sha256_ctx_init(git_hash_sha256_ctx *ctx) -{ - return git_hash_sha256_init(ctx); -} - -void git_hash_sha256_ctx_cleanup(git_hash_sha256_ctx *ctx) -{ - if (ctx) - mbedtls_sha256_free(&ctx->c); -} - -int git_hash_sha256_init(git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - mbedtls_sha256_init(&ctx->c); - mbedtls_sha256_starts(&ctx->c, 0); - return 0; -} - -int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx); - mbedtls_sha256_update(&ctx->c, data, len); - return 0; -} - -int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - mbedtls_sha256_finish(&ctx->c, out); - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/mbedtls.h b/vendor/libgit2-sys/libgit2/src/util/hash/mbedtls.h deleted file mode 100644 index 05fb38b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/mbedtls.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_hash_mbedtls_h__ -#define INCLUDE_hash_mbedtls_h__ - -#include "hash/sha.h" - -#ifdef GIT_SHA1_MBEDTLS -# include - -struct git_hash_sha1_ctx { - mbedtls_sha1_context c; -}; -#endif - -#ifdef GIT_SHA256_MBEDTLS -# include - -struct git_hash_sha256_ctx { - mbedtls_sha256_context c; -}; -#endif - -#endif /* INCLUDE_hash_sha1_mbedtls_h__ */ diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/openssl.c b/vendor/libgit2-sys/libgit2/src/util/hash/openssl.c deleted file mode 100644 index 8911073..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/openssl.c +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "openssl.h" - -#ifdef GIT_OPENSSL_DYNAMIC -# include - -static int handle_count; -static void *openssl_handle; - -static int git_hash_openssl_global_shutdown(void) -{ - if (--handle_count == 0) { - dlclose(openssl_handle); - openssl_handle = NULL; - } - - return 0; -} - -static int git_hash_openssl_global_init(void) -{ - if (!handle_count) { - if ((openssl_handle = dlopen("libssl.so.1.1", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.1.1.dylib", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.so.1.0.0", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.1.0.0.dylib", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.so.3", RTLD_NOW)) == NULL) { - git_error_set(GIT_ERROR_SSL, "could not load ssl libraries"); - return -1; - } - } - - if (git_hash_openssl_global_shutdown() < 0) - return -1; - - handle_count++; - return 0; -} - -#endif - -#ifdef GIT_SHA1_OPENSSL - -# ifdef GIT_OPENSSL_DYNAMIC -static int (*SHA1_Init)(SHA_CTX *c); -static int (*SHA1_Update)(SHA_CTX *c, const void *data, size_t len); -static int (*SHA1_Final)(unsigned char *md, SHA_CTX *c); -# endif - -int git_hash_sha1_global_init(void) -{ -#ifdef GIT_OPENSSL_DYNAMIC - if (git_hash_openssl_global_init() < 0) - return -1; - - if ((SHA1_Init = dlsym(openssl_handle, "SHA1_Init")) == NULL || - (SHA1_Update = dlsym(openssl_handle, "SHA1_Update")) == NULL || - (SHA1_Final = dlsym(openssl_handle, "SHA1_Final")) == NULL) { - const char *msg = dlerror(); - git_error_set(GIT_ERROR_SSL, "could not load hash function: %s", msg ? msg : "unknown error"); - return -1; - } -#endif - - return 0; -} - -int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) -{ - return git_hash_sha1_init(ctx); -} - -void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) -{ - GIT_UNUSED(ctx); -} - -int git_hash_sha1_init(git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - - if (SHA1_Init(&ctx->c) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to initialize sha1 context"); - return -1; - } - - return 0; -} - -int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx); - - if (SHA1_Update(&ctx->c, data, len) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to update sha1"); - return -1; - } - - return 0; -} - -int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - - if (SHA1_Final(out, &ctx->c) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to finalize sha1"); - return -1; - } - - return 0; -} - -#endif - -#ifdef GIT_SHA1_OPENSSL_FIPS - -static const EVP_MD *SHA1_ENGINE_DIGEST_TYPE = NULL; - -int git_hash_sha1_global_init(void) -{ - SHA1_ENGINE_DIGEST_TYPE = EVP_sha1(); - return SHA1_ENGINE_DIGEST_TYPE != NULL ? 0 : -1; -} - -int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) -{ - return git_hash_sha1_init(ctx); -} - -void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) -{ -#if OPENSSL_VERSION_NUMBER < 0x10100000L - EVP_MD_CTX_destroy(ctx->c); -#else - EVP_MD_CTX_free(ctx->c); -#endif -} - -int git_hash_sha1_init(git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - GIT_ASSERT(SHA1_ENGINE_DIGEST_TYPE); - -#if OPENSSL_VERSION_NUMBER < 0x10100000L - ctx->c = EVP_MD_CTX_create(); -#else - ctx->c = EVP_MD_CTX_new(); -#endif - - GIT_ASSERT(ctx->c); - - if (EVP_DigestInit_ex(ctx->c, SHA1_ENGINE_DIGEST_TYPE, NULL) != 1) { - git_hash_sha1_ctx_cleanup(ctx); - git_error_set(GIT_ERROR_SHA, "failed to initialize sha1 context"); - return -1; - } - - return 0; -} - -int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx && ctx->c); - - if (EVP_DigestUpdate(ctx->c, data, len) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to update sha1"); - return -1; - } - - return 0; -} - -int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx) -{ - unsigned int len = 0; - - GIT_ASSERT_ARG(ctx && ctx->c); - - if (EVP_DigestFinal(ctx->c, out, &len) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to finalize sha1"); - return -1; - } - - return 0; -} - -#endif - -#ifdef GIT_SHA256_OPENSSL - -# ifdef GIT_OPENSSL_DYNAMIC -static int (*SHA256_Init)(SHA256_CTX *c); -static int (*SHA256_Update)(SHA256_CTX *c, const void *data, size_t len); -static int (*SHA256_Final)(unsigned char *md, SHA256_CTX *c); -#endif - -int git_hash_sha256_global_init(void) -{ -#ifdef GIT_OPENSSL_DYNAMIC - if (git_hash_openssl_global_init() < 0) - return -1; - - if ((SHA256_Init = dlsym(openssl_handle, "SHA256_Init")) == NULL || - (SHA256_Update = dlsym(openssl_handle, "SHA256_Update")) == NULL || - (SHA256_Final = dlsym(openssl_handle, "SHA256_Final")) == NULL) { - const char *msg = dlerror(); - git_error_set(GIT_ERROR_SSL, "could not load hash function: %s", msg ? msg : "unknown error"); - return -1; - } -#endif - - return 0; -} - -int git_hash_sha256_ctx_init(git_hash_sha256_ctx *ctx) -{ - return git_hash_sha256_init(ctx); -} - -void git_hash_sha256_ctx_cleanup(git_hash_sha256_ctx *ctx) -{ - GIT_UNUSED(ctx); -} - -int git_hash_sha256_init(git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - - if (SHA256_Init(&ctx->c) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to initialize sha256 context"); - return -1; - } - - return 0; -} - -int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx); - - if (SHA256_Update(&ctx->c, data, len) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to update sha256"); - return -1; - } - - return 0; -} - -int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - - if (SHA256_Final(out, &ctx->c) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to finalize sha256"); - return -1; - } - - return 0; -} - -#endif - -#ifdef GIT_SHA256_OPENSSL_FIPS - -static const EVP_MD *SHA256_ENGINE_DIGEST_TYPE = NULL; - -int git_hash_sha256_global_init(void) -{ - SHA256_ENGINE_DIGEST_TYPE = EVP_sha256(); - return SHA256_ENGINE_DIGEST_TYPE != NULL ? 0 : -1; -} - -int git_hash_sha256_ctx_init(git_hash_sha256_ctx *ctx) -{ - return git_hash_sha256_init(ctx); -} - -void git_hash_sha256_ctx_cleanup(git_hash_sha256_ctx *ctx) -{ -#if OPENSSL_VERSION_NUMBER < 0x10100000L - EVP_MD_CTX_destroy(ctx->c); -#else - EVP_MD_CTX_free(ctx->c); -#endif -} - -int git_hash_sha256_init(git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - GIT_ASSERT(SHA256_ENGINE_DIGEST_TYPE); - -#if OPENSSL_VERSION_NUMBER < 0x10100000L - ctx->c = EVP_MD_CTX_create(); -#else - ctx->c = EVP_MD_CTX_new(); -#endif - - GIT_ASSERT(ctx->c); - - if (EVP_DigestInit_ex(ctx->c, SHA256_ENGINE_DIGEST_TYPE, NULL) != 1) { - git_hash_sha256_ctx_cleanup(ctx); - git_error_set(GIT_ERROR_SHA, "failed to initialize sha256 context"); - return -1; - } - - return 0; -} - -int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx && ctx->c); - - if (EVP_DigestUpdate(ctx->c, data, len) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to update sha256"); - return -1; - } - - return 0; -} - -int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *ctx) -{ - unsigned int len = 0; - - GIT_ASSERT_ARG(ctx && ctx->c); - - if (EVP_DigestFinal(ctx->c, out, &len) != 1) { - git_error_set(GIT_ERROR_SHA, "failed to finalize sha256"); - return -1; - } - - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/openssl.h b/vendor/libgit2-sys/libgit2/src/util/hash/openssl.h deleted file mode 100644 index 8be37fd..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/openssl.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_hash_openssl_h__ -#define INCLUDE_hash_openssl_h__ - -#include "hash/sha.h" - -#ifndef GIT_OPENSSL_DYNAMIC -# if defined(GIT_SHA1_OPENSSL_FIPS) || defined(GIT_SHA256_OPENSSL_FIPS) -# include -# else -# include -# endif -#else - -typedef struct { - unsigned int h0, h1, h2, h3, h4; - unsigned int Nl, Nh; - unsigned int data[16]; - unsigned int num; -} SHA_CTX; - -typedef struct { - unsigned int h[8]; - unsigned int Nl, Nh; - unsigned int data[16]; - unsigned int num, md_len; -} SHA256_CTX; - -#endif - -#ifdef GIT_SHA1_OPENSSL -struct git_hash_sha1_ctx { - SHA_CTX c; -}; -#endif - -#ifdef GIT_SHA1_OPENSSL_FIPS -struct git_hash_sha1_ctx { - EVP_MD_CTX* c; -}; -#endif - -#ifdef GIT_SHA256_OPENSSL -struct git_hash_sha256_ctx { - SHA256_CTX c; -}; -#endif - -#ifdef GIT_SHA256_OPENSSL_FIPS -struct git_hash_sha256_ctx { - EVP_MD_CTX* c; -}; -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/rfc6234/sha.h b/vendor/libgit2-sys/libgit2/src/util/hash/rfc6234/sha.h deleted file mode 100644 index 0fbcc50..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/rfc6234/sha.h +++ /dev/null @@ -1,243 +0,0 @@ -/**************************** sha.h ****************************/ -/***************** See RFC 6234 for details. *******************/ -/* - Copyright (c) 2011 IETF Trust and the persons identified as - authors of the code. All rights reserved. - - Redistribution and use in source and binary forms, with or - without modification, are permitted provided that the following - conditions are met: - - - Redistributions of source code must retain the above - copyright notice, this list of conditions and - the following disclaimer. - - - Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - - Neither the name of Internet Society, IETF or IETF Trust, nor - the names of specific contributors, may be used to endorse or - promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#ifndef _SHA_H_ -#define _SHA_H_ - -/* - * Description: - * This file implements the Secure Hash Algorithms - * as defined in the U.S. National Institute of Standards - * and Technology Federal Information Processing Standards - * Publication (FIPS PUB) 180-3 published in October 2008 - * and formerly defined in its predecessors, FIPS PUB 180-1 - * and FIP PUB 180-2. - * - * A combined document showing all algorithms is available at - * http://csrc.nist.gov/publications/fips/ - * fips180-3/fips180-3_final.pdf - * - * The five hashes are defined in these sizes: - * SHA-1 20 byte / 160 bit - * SHA-224 28 byte / 224 bit - * SHA-256 32 byte / 256 bit - * SHA-384 48 byte / 384 bit - * SHA-512 64 byte / 512 bit - * - * Compilation Note: - * These files may be compiled with two options: - * USE_32BIT_ONLY - use 32-bit arithmetic only, for systems - * without 64-bit integers - * - * USE_MODIFIED_MACROS - use alternate form of the SHA_Ch() - * and SHA_Maj() macros that are equivalent - * and potentially faster on many systems - * - */ - -#include -/* - * If you do not have the ISO standard stdint.h header file, then you - * must typedef the following: - * name meaning - * uint64_t unsigned 64-bit integer - * uint32_t unsigned 32-bit integer - * uint8_t unsigned 8-bit integer (i.e., unsigned char) - * int_least16_t integer of >= 16 bits - * - * See stdint-example.h - */ - -#ifndef _SHA_enum_ -#define _SHA_enum_ -/* - * All SHA functions return one of these values. - */ -enum { - shaSuccess = 0, - shaNull, /* Null pointer parameter */ - shaInputTooLong, /* input data too long */ - shaStateError, /* called Input after FinalBits or Result */ - shaBadParam /* passed a bad parameter */ -}; -#endif /* _SHA_enum_ */ - -/* - * These constants hold size information for each of the SHA - * hashing operations - */ -enum { - SHA1_Message_Block_Size = 64, SHA224_Message_Block_Size = 64, - SHA256_Message_Block_Size = 64, SHA384_Message_Block_Size = 128, - SHA512_Message_Block_Size = 128, - USHA_Max_Message_Block_Size = SHA512_Message_Block_Size, - SHA1HashSize = 20, SHA224HashSize = 28, SHA256HashSize = 32, - SHA384HashSize = 48, SHA512HashSize = 64, - USHAMaxHashSize = SHA512HashSize, - - SHA1HashSizeBits = 160, SHA224HashSizeBits = 224, - SHA256HashSizeBits = 256, SHA384HashSizeBits = 384, - SHA512HashSizeBits = 512, USHAMaxHashSizeBits = SHA512HashSizeBits -}; - -/* - * These constants are used in the USHA (Unified SHA) functions. - */ -typedef enum SHAversion { - SHA1, SHA224, SHA256, SHA384, SHA512 -} SHAversion; - -/* - * This structure will hold context information for the SHA-1 - * hashing operation. - */ -typedef struct SHA1Context { - uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */ - - uint32_t Length_High; /* Message length in bits */ - uint32_t Length_Low; /* Message length in bits */ - - int_least16_t Message_Block_Index; /* Message_Block array index */ - /* 512-bit message blocks */ - uint8_t Message_Block[SHA1_Message_Block_Size]; - - int Computed; /* Is the hash computed? */ - int Corrupted; /* Cumulative corruption code */ -} SHA1Context; - -/* - * This structure will hold context information for the SHA-256 - * hashing operation. - */ -typedef struct SHA256Context { - uint32_t Intermediate_Hash[SHA256HashSize/4]; /* Message Digest */ - - uint32_t Length_High; /* Message length in bits */ - uint32_t Length_Low; /* Message length in bits */ - - int_least16_t Message_Block_Index; /* Message_Block array index */ - /* 512-bit message blocks */ - uint8_t Message_Block[SHA256_Message_Block_Size]; - - int Computed; /* Is the hash computed? */ - int Corrupted; /* Cumulative corruption code */ -} SHA256Context; - -/* - * This structure will hold context information for the SHA-512 - * hashing operation. - */ -typedef struct SHA512Context { -#ifdef USE_32BIT_ONLY - uint32_t Intermediate_Hash[SHA512HashSize/4]; /* Message Digest */ - uint32_t Length[4]; /* Message length in bits */ -#else /* !USE_32BIT_ONLY */ - uint64_t Intermediate_Hash[SHA512HashSize/8]; /* Message Digest */ - uint64_t Length_High, Length_Low; /* Message length in bits */ -#endif /* USE_32BIT_ONLY */ - - int_least16_t Message_Block_Index; /* Message_Block array index */ - /* 1024-bit message blocks */ - uint8_t Message_Block[SHA512_Message_Block_Size]; - - int Computed; /* Is the hash computed?*/ - int Corrupted; /* Cumulative corruption code */ -} SHA512Context; - -/* - * This structure will hold context information for the SHA-224 - * hashing operation. It uses the SHA-256 structure for computation. - */ -typedef struct SHA256Context SHA224Context; - -/* - * This structure will hold context information for the SHA-384 - * hashing operation. It uses the SHA-512 structure for computation. - */ -typedef struct SHA512Context SHA384Context; - -/* - * Function Prototypes - */ - -/* SHA-1 */ -extern int SHA1Reset(SHA1Context *); -extern int SHA1Input(SHA1Context *, const uint8_t *bytes, - unsigned int bytecount); -extern int SHA1FinalBits(SHA1Context *, uint8_t bits, - unsigned int bit_count); -extern int SHA1Result(SHA1Context *, - uint8_t Message_Digest[SHA1HashSize]); - -/* SHA-224 */ -extern int SHA224Reset(SHA224Context *); -extern int SHA224Input(SHA224Context *, const uint8_t *bytes, - unsigned int bytecount); -extern int SHA224FinalBits(SHA224Context *, uint8_t bits, - unsigned int bit_count); -extern int SHA224Result(SHA224Context *, - uint8_t Message_Digest[SHA224HashSize]); - -/* SHA-256 */ -extern int SHA256Reset(SHA256Context *); -extern int SHA256Input(SHA256Context *, const uint8_t *bytes, - unsigned int bytecount); -extern int SHA256FinalBits(SHA256Context *, uint8_t bits, - unsigned int bit_count); -extern int SHA256Result(SHA256Context *, - uint8_t Message_Digest[SHA256HashSize]); - -/* SHA-384 */ -extern int SHA384Reset(SHA384Context *); -extern int SHA384Input(SHA384Context *, const uint8_t *bytes, - unsigned int bytecount); -extern int SHA384FinalBits(SHA384Context *, uint8_t bits, - unsigned int bit_count); -extern int SHA384Result(SHA384Context *, - uint8_t Message_Digest[SHA384HashSize]); - -/* SHA-512 */ -extern int SHA512Reset(SHA512Context *); -extern int SHA512Input(SHA512Context *, const uint8_t *bytes, - unsigned int bytecount); -extern int SHA512FinalBits(SHA512Context *, uint8_t bits, - unsigned int bit_count); -extern int SHA512Result(SHA512Context *, - uint8_t Message_Digest[SHA512HashSize]); - -#endif /* _SHA_H_ */ diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/rfc6234/sha224-256.c b/vendor/libgit2-sys/libgit2/src/util/hash/rfc6234/sha224-256.c deleted file mode 100644 index ad96534..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/rfc6234/sha224-256.c +++ /dev/null @@ -1,603 +0,0 @@ -/************************* sha224-256.c ************************/ -/***************** See RFC 6234 for details. *******************/ -/* Copyright (c) 2011 IETF Trust and the persons identified as */ -/* authors of the code. All rights reserved. */ -/* See sha.h for terms of use and redistribution. */ - -/* - * Description: - * This file implements the Secure Hash Algorithms SHA-224 and - * SHA-256 as defined in the U.S. National Institute of Standards - * and Technology Federal Information Processing Standards - * Publication (FIPS PUB) 180-3 published in October 2008 - * and formerly defined in its predecessors, FIPS PUB 180-1 - * and FIP PUB 180-2. - * - * A combined document showing all algorithms is available at - * http://csrc.nist.gov/publications/fips/ - * fips180-3/fips180-3_final.pdf - * - * The SHA-224 and SHA-256 algorithms produce 224-bit and 256-bit - * message digests for a given data stream. It should take about - * 2**n steps to find a message with the same digest as a given - * message and 2**(n/2) to find any two messages with the same - * digest, when n is the digest size in bits. Therefore, this - * algorithm can serve as a means of providing a - * "fingerprint" for a message. - * - * Portability Issues: - * SHA-224 and SHA-256 are defined in terms of 32-bit "words". - * This code uses (included via "sha.h") to define 32- - * and 8-bit unsigned integer types. If your C compiler does not - * support 32-bit unsigned integers, this code is not - * appropriate. - * - * Caveats: - * SHA-224 and SHA-256 are designed to work with messages less - * than 2^64 bits long. This implementation uses SHA224/256Input() - * to hash the bits that are a multiple of the size of an 8-bit - * octet, and then optionally uses SHA224/256FinalBits() - * to hash the final few bits of the input. - */ - -#include "sha.h" - -/* - * These definitions are defined in FIPS 180-3, section 4.1. - * Ch() and Maj() are defined identically in sections 4.1.1, - * 4.1.2, and 4.1.3. - * - * The definitions used in FIPS 180-3 are as follows: - */ -#ifndef USE_MODIFIED_MACROS -#define SHA_Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) -#define SHA_Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) -#else /* USE_MODIFIED_MACROS */ -/* - * The following definitions are equivalent and potentially faster. - */ -#define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z)) -#define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) -#endif /* USE_MODIFIED_MACROS */ - -#define SHA_Parity(x, y, z) ((x) ^ (y) ^ (z)) - -/* Define the SHA shift, rotate left, and rotate right macros */ -#define SHA256_SHR(bits,word) ((word) >> (bits)) -#define SHA256_ROTL(bits,word) \ - (((word) << (bits)) | ((word) >> (32-(bits)))) -#define SHA256_ROTR(bits,word) \ - (((word) >> (bits)) | ((word) << (32-(bits)))) - -/* Define the SHA SIGMA and sigma macros */ -#define SHA256_SIGMA0(word) \ - (SHA256_ROTR( 2,word) ^ SHA256_ROTR(13,word) ^ SHA256_ROTR(22,word)) -#define SHA256_SIGMA1(word) \ - (SHA256_ROTR( 6,word) ^ SHA256_ROTR(11,word) ^ SHA256_ROTR(25,word)) -#define SHA256_sigma0(word) \ - (SHA256_ROTR( 7,word) ^ SHA256_ROTR(18,word) ^ SHA256_SHR( 3,word)) -#define SHA256_sigma1(word) \ - (SHA256_ROTR(17,word) ^ SHA256_ROTR(19,word) ^ SHA256_SHR(10,word)) - -/* - * Add "length" to the length. - * Set Corrupted when overflow has occurred. - */ -static int SHA224_256AddLength(SHA256Context *context, unsigned int length) -{ - uint32_t addTemp = context->Length_Low; - context->Length_Low += length; - if (context->Length_Low < addTemp && ++context->Length_High == 0) - context->Corrupted = shaInputTooLong; - return context->Corrupted; -} - -/* Local Function Prototypes */ -static int SHA224_256Reset(SHA256Context *context, uint32_t *H0); -static void SHA224_256ProcessMessageBlock(SHA256Context *context); -static void SHA224_256Finalize(SHA256Context *context, - uint8_t Pad_Byte); -static void SHA224_256PadMessage(SHA256Context *context, - uint8_t Pad_Byte); -static int SHA224_256ResultN(SHA256Context *context, - uint8_t Message_Digest[ ], int HashSize); - -/* Initial Hash Values: FIPS 180-3 section 5.3.2 */ -static uint32_t SHA224_H0[SHA256HashSize/4] = { - 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, - 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4 -}; - -/* Initial Hash Values: FIPS 180-3 section 5.3.3 */ -static uint32_t SHA256_H0[SHA256HashSize/4] = { - 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, - 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 -}; - -/* - * SHA224Reset - * - * Description: - * This function will initialize the SHA224Context in preparation - * for computing a new SHA224 message digest. - * - * Parameters: - * context: [in/out] - * The context to reset. - * - * Returns: - * sha Error Code. - */ -int SHA224Reset(SHA224Context *context) -{ - return SHA224_256Reset(context, SHA224_H0); -} - -/* - * SHA224Input - * - * Description: - * This function accepts an array of octets as the next portion - * of the message. - * - * Parameters: - * context: [in/out] - * The SHA context to update. - * message_array[ ]: [in] - * An array of octets representing the next portion of - * the message. - * length: [in] - * The length of the message in message_array. - * - * Returns: - * sha Error Code. - * - */ -int SHA224Input(SHA224Context *context, const uint8_t *message_array, - unsigned int length) -{ - return SHA256Input(context, message_array, length); -} - -/* - * SHA224FinalBits - * - * Description: - * This function will add in any final bits of the message. - * - * Parameters: - * context: [in/out] - * The SHA context to update. - * message_bits: [in] - * The final bits of the message, in the upper portion of the - * byte. (Use 0b###00000 instead of 0b00000### to input the - * three bits ###.) - * length: [in] - * The number of bits in message_bits, between 1 and 7. - * - * Returns: - * sha Error Code. - */ -int SHA224FinalBits(SHA224Context *context, - uint8_t message_bits, unsigned int length) -{ - return SHA256FinalBits(context, message_bits, length); -} - -/* - * SHA224Result - * - * Description: - * This function will return the 224-bit message digest - * into the Message_Digest array provided by the caller. - * NOTE: - * The first octet of hash is stored in the element with index 0, - * the last octet of hash in the element with index 27. - * - * Parameters: - * context: [in/out] - * The context to use to calculate the SHA hash. - * Message_Digest[ ]: [out] - * Where the digest is returned. - * - * Returns: - * sha Error Code. - */ -int SHA224Result(SHA224Context *context, - uint8_t Message_Digest[SHA224HashSize]) -{ - return SHA224_256ResultN(context, Message_Digest, SHA224HashSize); -} - -/* - * SHA256Reset - * - * Description: - * This function will initialize the SHA256Context in preparation - * for computing a new SHA256 message digest. - * - * Parameters: - * context: [in/out] - * The context to reset. - * - * Returns: - * sha Error Code. - */ -int SHA256Reset(SHA256Context *context) -{ - return SHA224_256Reset(context, SHA256_H0); -} - -/* - * SHA256Input - * - * Description: - * This function accepts an array of octets as the next portion - * of the message. - * - * Parameters: - * context: [in/out] - * The SHA context to update. - * message_array[ ]: [in] - * An array of octets representing the next portion of - * the message. - * length: [in] - * The length of the message in message_array. - * - * Returns: - * sha Error Code. - */ -int SHA256Input(SHA256Context *context, const uint8_t *message_array, - unsigned int length) -{ - if (!context) return shaNull; - if (!length) return shaSuccess; - if (!message_array) return shaNull; - if (context->Computed) return context->Corrupted = shaStateError; - if (context->Corrupted) return context->Corrupted; - - while (length--) { - context->Message_Block[context->Message_Block_Index++] = - *message_array; - - if ((SHA224_256AddLength(context, 8) == shaSuccess) && - (context->Message_Block_Index == SHA256_Message_Block_Size)) - SHA224_256ProcessMessageBlock(context); - - message_array++; - } - - return context->Corrupted; - -} - -/* - * SHA256FinalBits - * - * Description: - * This function will add in any final bits of the message. - * - * Parameters: - * context: [in/out] - * The SHA context to update. - * message_bits: [in] - * The final bits of the message, in the upper portion of the - * byte. (Use 0b###00000 instead of 0b00000### to input the - * three bits ###.) - * length: [in] - * The number of bits in message_bits, between 1 and 7. - * - * Returns: - * sha Error Code. - */ -int SHA256FinalBits(SHA256Context *context, - uint8_t message_bits, unsigned int length) -{ - static uint8_t masks[8] = { - /* 0 0b00000000 */ 0x00, /* 1 0b10000000 */ 0x80, - /* 2 0b11000000 */ 0xC0, /* 3 0b11100000 */ 0xE0, - /* 4 0b11110000 */ 0xF0, /* 5 0b11111000 */ 0xF8, - /* 6 0b11111100 */ 0xFC, /* 7 0b11111110 */ 0xFE - }; - static uint8_t markbit[8] = { - /* 0 0b10000000 */ 0x80, /* 1 0b01000000 */ 0x40, - /* 2 0b00100000 */ 0x20, /* 3 0b00010000 */ 0x10, - /* 4 0b00001000 */ 0x08, /* 5 0b00000100 */ 0x04, - /* 6 0b00000010 */ 0x02, /* 7 0b00000001 */ 0x01 - }; - - if (!context) return shaNull; - if (!length) return shaSuccess; - if (context->Corrupted) return context->Corrupted; - if (context->Computed) return context->Corrupted = shaStateError; - if (length >= 8) return context->Corrupted = shaBadParam; - - SHA224_256AddLength(context, length); - SHA224_256Finalize(context, (uint8_t) - ((message_bits & masks[length]) | markbit[length])); - - return context->Corrupted; -} - -/* - * SHA256Result - * - * Description: - * This function will return the 256-bit message digest - * into the Message_Digest array provided by the caller. - * NOTE: - * The first octet of hash is stored in the element with index 0, - * the last octet of hash in the element with index 31. - * - * Parameters: - * context: [in/out] - * The context to use to calculate the SHA hash. - * Message_Digest[ ]: [out] - * Where the digest is returned. - * - * Returns: - * sha Error Code. - */ -int SHA256Result(SHA256Context *context, - uint8_t Message_Digest[SHA256HashSize]) -{ - return SHA224_256ResultN(context, Message_Digest, SHA256HashSize); -} - -/* - * SHA224_256Reset - * - * Description: - * This helper function will initialize the SHA256Context in - * preparation for computing a new SHA-224 or SHA-256 message digest. - * - * Parameters: - * context: [in/out] - * The context to reset. - * H0[ ]: [in] - * The initial hash value array to use. - * - * Returns: - * sha Error Code. - */ -static int SHA224_256Reset(SHA256Context *context, uint32_t *H0) -{ - if (!context) return shaNull; - - context->Length_High = context->Length_Low = 0; - context->Message_Block_Index = 0; - - context->Intermediate_Hash[0] = H0[0]; - context->Intermediate_Hash[1] = H0[1]; - context->Intermediate_Hash[2] = H0[2]; - context->Intermediate_Hash[3] = H0[3]; - context->Intermediate_Hash[4] = H0[4]; - context->Intermediate_Hash[5] = H0[5]; - context->Intermediate_Hash[6] = H0[6]; - context->Intermediate_Hash[7] = H0[7]; - - context->Computed = 0; - context->Corrupted = shaSuccess; - - return shaSuccess; -} - -/* - * SHA224_256ProcessMessageBlock - * - * Description: - * This helper function will process the next 512 bits of the - * message stored in the Message_Block array. - * - * Parameters: - * context: [in/out] - * The SHA context to update. - * - * Returns: - * Nothing. - * - * Comments: - * Many of the variable names in this code, especially the - * single character names, were used because those were the - * names used in the Secure Hash Standard. - */ -static void SHA224_256ProcessMessageBlock(SHA256Context *context) -{ - /* Constants defined in FIPS 180-3, section 4.2.2 */ - static const uint32_t K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, - 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, - 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, - 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, - 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, - 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, - 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, - 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, - 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, - 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 - }; - int t, t4; /* Loop counter */ - uint32_t temp1, temp2; /* Temporary word value */ - uint32_t W[64]; /* Word sequence */ - uint32_t A, B, C, D, E, F, G, H; /* Word buffers */ - - /* - * Initialize the first 16 words in the array W - */ - for (t = t4 = 0; t < 16; t++, t4 += 4) - W[t] = (((uint32_t)context->Message_Block[t4]) << 24) | - (((uint32_t)context->Message_Block[t4 + 1]) << 16) | - (((uint32_t)context->Message_Block[t4 + 2]) << 8) | - (((uint32_t)context->Message_Block[t4 + 3])); - - for (t = 16; t < 64; t++) - W[t] = SHA256_sigma1(W[t-2]) + W[t-7] + - SHA256_sigma0(W[t-15]) + W[t-16]; - - A = context->Intermediate_Hash[0]; - B = context->Intermediate_Hash[1]; - C = context->Intermediate_Hash[2]; - D = context->Intermediate_Hash[3]; - E = context->Intermediate_Hash[4]; - F = context->Intermediate_Hash[5]; - G = context->Intermediate_Hash[6]; - H = context->Intermediate_Hash[7]; - - for (t = 0; t < 64; t++) { - temp1 = H + SHA256_SIGMA1(E) + SHA_Ch(E,F,G) + K[t] + W[t]; - temp2 = SHA256_SIGMA0(A) + SHA_Maj(A,B,C); - H = G; - G = F; - F = E; - E = D + temp1; - D = C; - C = B; - B = A; - A = temp1 + temp2; - } - - context->Intermediate_Hash[0] += A; - context->Intermediate_Hash[1] += B; - context->Intermediate_Hash[2] += C; - context->Intermediate_Hash[3] += D; - context->Intermediate_Hash[4] += E; - context->Intermediate_Hash[5] += F; - context->Intermediate_Hash[6] += G; - context->Intermediate_Hash[7] += H; - - context->Message_Block_Index = 0; -} - -/* - * SHA224_256Finalize - * - * Description: - * This helper function finishes off the digest calculations. - * - * Parameters: - * context: [in/out] - * The SHA context to update. - * Pad_Byte: [in] - * The last byte to add to the message block before the 0-padding - * and length. This will contain the last bits of the message - * followed by another single bit. If the message was an - * exact multiple of 8-bits long, Pad_Byte will be 0x80. - * - * Returns: - * sha Error Code. - */ -static void SHA224_256Finalize(SHA256Context *context, - uint8_t Pad_Byte) -{ - int i; - SHA224_256PadMessage(context, Pad_Byte); - /* message may be sensitive, so clear it out */ - for (i = 0; i < SHA256_Message_Block_Size; ++i) - context->Message_Block[i] = 0; - context->Length_High = 0; /* and clear length */ - context->Length_Low = 0; - context->Computed = 1; -} - -/* - * SHA224_256PadMessage - * - * Description: - * According to the standard, the message must be padded to the next - * even multiple of 512 bits. The first padding bit must be a '1'. - * The last 64 bits represent the length of the original message. - * All bits in between should be 0. This helper function will pad - * the message according to those rules by filling the - * Message_Block array accordingly. When it returns, it can be - * assumed that the message digest has been computed. - * - * Parameters: - * context: [in/out] - * The context to pad. - * Pad_Byte: [in] - * The last byte to add to the message block before the 0-padding - * and length. This will contain the last bits of the message - * followed by another single bit. If the message was an - * exact multiple of 8-bits long, Pad_Byte will be 0x80. - * - * Returns: - * Nothing. - */ -static void SHA224_256PadMessage(SHA256Context *context, - uint8_t Pad_Byte) -{ - /* - * Check to see if the current message block is too small to hold - * the initial padding bits and length. If so, we will pad the - * block, process it, and then continue padding into a second - * block. - */ - if (context->Message_Block_Index >= (SHA256_Message_Block_Size-8)) { - context->Message_Block[context->Message_Block_Index++] = Pad_Byte; - while (context->Message_Block_Index < SHA256_Message_Block_Size) - context->Message_Block[context->Message_Block_Index++] = 0; - SHA224_256ProcessMessageBlock(context); - } else - context->Message_Block[context->Message_Block_Index++] = Pad_Byte; - - while (context->Message_Block_Index < (SHA256_Message_Block_Size-8)) - context->Message_Block[context->Message_Block_Index++] = 0; - - /* - * Store the message length as the last 8 octets - */ - context->Message_Block[56] = (uint8_t)(context->Length_High >> 24); - context->Message_Block[57] = (uint8_t)(context->Length_High >> 16); - context->Message_Block[58] = (uint8_t)(context->Length_High >> 8); - context->Message_Block[59] = (uint8_t)(context->Length_High); - context->Message_Block[60] = (uint8_t)(context->Length_Low >> 24); - context->Message_Block[61] = (uint8_t)(context->Length_Low >> 16); - context->Message_Block[62] = (uint8_t)(context->Length_Low >> 8); - context->Message_Block[63] = (uint8_t)(context->Length_Low); - - SHA224_256ProcessMessageBlock(context); -} - -/* - * SHA224_256ResultN - * - * Description: - * This helper function will return the 224-bit or 256-bit message - * digest into the Message_Digest array provided by the caller. - * NOTE: - * The first octet of hash is stored in the element with index 0, - * the last octet of hash in the element with index 27/31. - * - * Parameters: - * context: [in/out] - * The context to use to calculate the SHA hash. - * Message_Digest[ ]: [out] - * Where the digest is returned. - * HashSize: [in] - * The size of the hash, either 28 or 32. - * - * Returns: - * sha Error Code. - */ -static int SHA224_256ResultN(SHA256Context *context, - uint8_t Message_Digest[ ], int HashSize) -{ - int i; - - if (!context) return shaNull; - if (!Message_Digest) return shaNull; - if (context->Corrupted) return context->Corrupted; - - if (!context->Computed) - SHA224_256Finalize(context, 0x80); - - for (i = 0; i < HashSize; ++i) - Message_Digest[i] = (uint8_t) - (context->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) )); - - return shaSuccess; -} - diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/sha.h b/vendor/libgit2-sys/libgit2/src/util/hash/sha.h deleted file mode 100644 index 8e7eeae..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/sha.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_hash_sha_h__ -#define INCLUDE_hash_sha_h__ - -#include "git2_util.h" - -typedef struct git_hash_sha1_ctx git_hash_sha1_ctx; -typedef struct git_hash_sha256_ctx git_hash_sha256_ctx; - -#if defined(GIT_SHA1_COMMON_CRYPTO) || defined(GIT_SHA256_COMMON_CRYPTO) -# include "common_crypto.h" -#endif - -#if defined(GIT_SHA1_OPENSSL) || \ - defined(GIT_SHA1_OPENSSL_FIPS) || \ - defined(GIT_SHA256_OPENSSL) || \ - defined(GIT_SHA256_OPENSSL_FIPS) -# include "openssl.h" -#endif - -#if defined(GIT_SHA1_WIN32) || defined(GIT_SHA256_WIN32) -# include "win32.h" -#endif - -#if defined(GIT_SHA1_MBEDTLS) || defined(GIT_SHA256_MBEDTLS) -# include "mbedtls.h" -#endif - -#if defined(GIT_SHA1_COLLISIONDETECT) -# include "collisiondetect.h" -#endif - -#if defined(GIT_SHA256_BUILTIN) -# include "builtin.h" -#endif - -/* - * SHA1 - */ - -#define GIT_HASH_SHA1_SIZE 20 - -int git_hash_sha1_global_init(void); - -int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx); -void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx); - -int git_hash_sha1_init(git_hash_sha1_ctx *c); -int git_hash_sha1_update(git_hash_sha1_ctx *c, const void *data, size_t len); -int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *c); - -/* - * SHA256 - */ - -#define GIT_HASH_SHA256_SIZE 32 - -int git_hash_sha256_global_init(void); - -int git_hash_sha256_ctx_init(git_hash_sha256_ctx *ctx); -void git_hash_sha256_ctx_cleanup(git_hash_sha256_ctx *ctx); - -int git_hash_sha256_init(git_hash_sha256_ctx *c); -int git_hash_sha256_update(git_hash_sha256_ctx *c, const void *data, size_t len); -int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *c); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/sha1.c b/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/sha1.c deleted file mode 100644 index 9298227..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/sha1.c +++ /dev/null @@ -1,1909 +0,0 @@ -/*** -* Copyright 2017 Marc Stevens , Dan Shumow (danshu@microsoft.com) -* Distributed under the MIT Software License. -* See accompanying file LICENSE.txt or copy at -* https://opensource.org/licenses/MIT -***/ - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#include -#include -#include -#include /* make sure macros like _BIG_ENDIAN visible */ -#endif - -#ifdef SHA1DC_CUSTOM_INCLUDE_SHA1_C -#include SHA1DC_CUSTOM_INCLUDE_SHA1_C -#endif - -#ifndef SHA1DC_INIT_SAFE_HASH_DEFAULT -#define SHA1DC_INIT_SAFE_HASH_DEFAULT 1 -#endif - -#include "sha1.h" -#include "ubc_check.h" - -#if (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \ - defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || \ - defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || \ - defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || defined(__INTEL__) || \ - defined(__386) || defined(_M_X64) || defined(_M_AMD64)) -#define SHA1DC_ON_INTEL_LIKE_PROCESSOR -#endif - -/* - Because Little-Endian architectures are most common, - we only set SHA1DC_BIGENDIAN if one of these conditions is met. - Note that all MSFT platforms are little endian, - so none of these will be defined under the MSC compiler. - If you are compiling on a big endian platform and your compiler does not define one of these, - you will have to add whatever macros your tool chain defines to indicate Big-Endianness. - */ - -#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) -/* - * Should detect Big Endian under GCC since at least 4.6.0 (gcc svn - * rev #165881). See - * https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html - * - * This also works under clang since 3.2, it copied the GCC-ism. See - * clang.git's 3b198a97d2 ("Preprocessor: add __BYTE_ORDER__ - * predefined macro", 2012-07-27) - */ -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike */ -#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) -/* - * Should detect Big Endian under glibc.git since 14245eb70e ("entered - * into RCS", 1992-11-25). Defined in which will have been - * brought in by standard headers. See glibc.git and - * https://sourceforge.net/p/predef/wiki/Endianness/ - */ -#if __BYTE_ORDER == __BIG_ENDIAN -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike or glibc */ -#elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) -/* - * *BSD and newlib (embedded linux, cygwin, etc). - * the defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) part prevents - * this condition from matching with Solaris/sparc. - * (Solaris defines only one endian macro) - */ -#if _BYTE_ORDER == _BIG_ENDIAN -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike or glibc or *BSD or newlib */ -#elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ - defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \ - defined(__sparc)) -/* - * Should define Big Endian for a whitelist of known processors. See - * https://sourceforge.net/p/predef/wiki/Endianness/ and - * http://www.oracle.com/technetwork/server-storage/solaris/portingtosolaris-138514.html - */ -#define SHA1DC_BIGENDIAN - -/* Not under GCC-alike or glibc or *BSD or newlib or */ -#elif (defined(_AIX) || defined(__hpux)) - -/* - * Defines Big Endian on a whitelist of OSs that are known to be Big - * Endian-only. See - * https://public-inbox.org/git/93056823-2740-d072-1ebd-46b440b33d7e@felt.demon.nl/ - */ -#define SHA1DC_BIGENDIAN - -/* Not under GCC-alike or glibc or *BSD or newlib or or */ -#elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) -/* - * As a last resort before we do anything else we're not 100% sure - * about below, we blacklist specific processors here. We could add - * more, see e.g. https://wiki.debian.org/ArchitectureSpecificsMemo - */ -#else /* Not under GCC-alike or glibc or *BSD or newlib or or or */ - -/* We do nothing more here for now */ -/*#error "Uncomment this to see if you fall through all the detection"*/ - -#endif /* Big Endian detection */ - -#if (defined(SHA1DC_FORCE_LITTLEENDIAN) && defined(SHA1DC_BIGENDIAN)) -#undef SHA1DC_BIGENDIAN -#endif -#if (defined(SHA1DC_FORCE_BIGENDIAN) && !defined(SHA1DC_BIGENDIAN)) -#define SHA1DC_BIGENDIAN -#endif -/*ENDIANNESS SELECTION*/ - -#ifndef SHA1DC_FORCE_ALIGNED_ACCESS -#if defined(SHA1DC_FORCE_UNALIGNED_ACCESS) || defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) -#define SHA1DC_ALLOW_UNALIGNED_ACCESS -#endif /*UNALIGNED ACCESS DETECTION*/ -#endif /*FORCE ALIGNED ACCESS*/ - -#define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n)))) -#define rotate_left(x,n) (((x)<<(n))|((x)>>(32-(n)))) - -#define sha1_bswap32(x) \ - {x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); x = (x << 16) | (x >> 16);} - -#define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1)) - -#ifdef SHA1DC_BIGENDIAN - #define sha1_load(m, t, temp) { temp = m[t]; } -#else - #define sha1_load(m, t, temp) { temp = m[t]; sha1_bswap32(temp); } -#endif - -#define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x - -#define sha1_f1(b,c,d) ((d)^((b)&((c)^(d)))) -#define sha1_f2(b,c,d) ((b)^(c)^(d)) -#define sha1_f3(b,c,d) (((b)&(c))+((d)&((b)^(c)))) -#define sha1_f4(b,c,d) ((b)^(c)^(d)) - -#define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \ - { e += rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; b = rotate_left(b, 30); } -#define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \ - { e += rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; b = rotate_left(b, 30); } -#define HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, m, t) \ - { e += rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; b = rotate_left(b, 30); } -#define HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, m, t) \ - { e += rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; b = rotate_left(b, 30); } - -#define HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, m, t) \ - { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; } -#define HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, m, t) \ - { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; } -#define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \ - { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; } -#define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \ - { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; } - -#define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) \ - {sha1_load(m, t, temp); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999; b = rotate_left(b, 30);} - -#define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) \ - {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999; b = rotate_left(b, 30); } - -#define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) \ - {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1; b = rotate_left(b, 30); } - -#define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) \ - {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC; b = rotate_left(b, 30); } - -#define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) \ - {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6; b = rotate_left(b, 30); } - - -#define SHA1_STORE_STATE(i) states[i][0] = a; states[i][1] = b; states[i][2] = c; states[i][3] = d; states[i][4] = e; - -#ifdef BUILDNOCOLLDETECTSHA1COMPRESSION -void sha1_compression(uint32_t ihv[5], const uint32_t m[16]) -{ - uint32_t W[80]; - uint32_t a,b,c,d,e; - unsigned i; - - memcpy(W, m, 16 * 4); - for (i = 16; i < 80; ++i) - W[i] = sha1_mix(W, i); - - a = ihv[0]; b = ihv[1]; c = ihv[2]; d = ihv[3]; e = ihv[4]; - - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); - - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); - - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); - - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); - - ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; -} -#endif /*BUILDNOCOLLDETECTSHA1COMPRESSION*/ - - -static void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]) -{ - uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; - - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); - - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); - - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); - - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); - - ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; -} - - - -void sha1_compression_states(uint32_t ihv[5], const uint32_t m[16], uint32_t W[80], uint32_t states[80][5]) -{ - uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; - uint32_t temp; - -#ifdef DOSTORESTATE00 - SHA1_STORE_STATE(0) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 0, temp); - -#ifdef DOSTORESTATE01 - SHA1_STORE_STATE(1) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 1, temp); - -#ifdef DOSTORESTATE02 - SHA1_STORE_STATE(2) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 2, temp); - -#ifdef DOSTORESTATE03 - SHA1_STORE_STATE(3) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 3, temp); - -#ifdef DOSTORESTATE04 - SHA1_STORE_STATE(4) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 4, temp); - -#ifdef DOSTORESTATE05 - SHA1_STORE_STATE(5) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 5, temp); - -#ifdef DOSTORESTATE06 - SHA1_STORE_STATE(6) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 6, temp); - -#ifdef DOSTORESTATE07 - SHA1_STORE_STATE(7) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 7, temp); - -#ifdef DOSTORESTATE08 - SHA1_STORE_STATE(8) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 8, temp); - -#ifdef DOSTORESTATE09 - SHA1_STORE_STATE(9) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 9, temp); - -#ifdef DOSTORESTATE10 - SHA1_STORE_STATE(10) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 10, temp); - -#ifdef DOSTORESTATE11 - SHA1_STORE_STATE(11) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 11, temp); - -#ifdef DOSTORESTATE12 - SHA1_STORE_STATE(12) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 12, temp); - -#ifdef DOSTORESTATE13 - SHA1_STORE_STATE(13) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 13, temp); - -#ifdef DOSTORESTATE14 - SHA1_STORE_STATE(14) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 14, temp); - -#ifdef DOSTORESTATE15 - SHA1_STORE_STATE(15) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 15, temp); - -#ifdef DOSTORESTATE16 - SHA1_STORE_STATE(16) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(e, a, b, c, d, W, 16, temp); - -#ifdef DOSTORESTATE17 - SHA1_STORE_STATE(17) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(d, e, a, b, c, W, 17, temp); - -#ifdef DOSTORESTATE18 - SHA1_STORE_STATE(18) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(c, d, e, a, b, W, 18, temp); - -#ifdef DOSTORESTATE19 - SHA1_STORE_STATE(19) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(b, c, d, e, a, W, 19, temp); - - - -#ifdef DOSTORESTATE20 - SHA1_STORE_STATE(20) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 20, temp); - -#ifdef DOSTORESTATE21 - SHA1_STORE_STATE(21) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 21, temp); - -#ifdef DOSTORESTATE22 - SHA1_STORE_STATE(22) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 22, temp); - -#ifdef DOSTORESTATE23 - SHA1_STORE_STATE(23) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 23, temp); - -#ifdef DOSTORESTATE24 - SHA1_STORE_STATE(24) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 24, temp); - -#ifdef DOSTORESTATE25 - SHA1_STORE_STATE(25) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 25, temp); - -#ifdef DOSTORESTATE26 - SHA1_STORE_STATE(26) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 26, temp); - -#ifdef DOSTORESTATE27 - SHA1_STORE_STATE(27) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 27, temp); - -#ifdef DOSTORESTATE28 - SHA1_STORE_STATE(28) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 28, temp); - -#ifdef DOSTORESTATE29 - SHA1_STORE_STATE(29) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 29, temp); - -#ifdef DOSTORESTATE30 - SHA1_STORE_STATE(30) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 30, temp); - -#ifdef DOSTORESTATE31 - SHA1_STORE_STATE(31) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 31, temp); - -#ifdef DOSTORESTATE32 - SHA1_STORE_STATE(32) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 32, temp); - -#ifdef DOSTORESTATE33 - SHA1_STORE_STATE(33) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 33, temp); - -#ifdef DOSTORESTATE34 - SHA1_STORE_STATE(34) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 34, temp); - -#ifdef DOSTORESTATE35 - SHA1_STORE_STATE(35) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 35, temp); - -#ifdef DOSTORESTATE36 - SHA1_STORE_STATE(36) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 36, temp); - -#ifdef DOSTORESTATE37 - SHA1_STORE_STATE(37) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 37, temp); - -#ifdef DOSTORESTATE38 - SHA1_STORE_STATE(38) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 38, temp); - -#ifdef DOSTORESTATE39 - SHA1_STORE_STATE(39) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 39, temp); - - - -#ifdef DOSTORESTATE40 - SHA1_STORE_STATE(40) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 40, temp); - -#ifdef DOSTORESTATE41 - SHA1_STORE_STATE(41) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 41, temp); - -#ifdef DOSTORESTATE42 - SHA1_STORE_STATE(42) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 42, temp); - -#ifdef DOSTORESTATE43 - SHA1_STORE_STATE(43) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 43, temp); - -#ifdef DOSTORESTATE44 - SHA1_STORE_STATE(44) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 44, temp); - -#ifdef DOSTORESTATE45 - SHA1_STORE_STATE(45) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 45, temp); - -#ifdef DOSTORESTATE46 - SHA1_STORE_STATE(46) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 46, temp); - -#ifdef DOSTORESTATE47 - SHA1_STORE_STATE(47) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 47, temp); - -#ifdef DOSTORESTATE48 - SHA1_STORE_STATE(48) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 48, temp); - -#ifdef DOSTORESTATE49 - SHA1_STORE_STATE(49) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 49, temp); - -#ifdef DOSTORESTATE50 - SHA1_STORE_STATE(50) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 50, temp); - -#ifdef DOSTORESTATE51 - SHA1_STORE_STATE(51) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 51, temp); - -#ifdef DOSTORESTATE52 - SHA1_STORE_STATE(52) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 52, temp); - -#ifdef DOSTORESTATE53 - SHA1_STORE_STATE(53) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 53, temp); - -#ifdef DOSTORESTATE54 - SHA1_STORE_STATE(54) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 54, temp); - -#ifdef DOSTORESTATE55 - SHA1_STORE_STATE(55) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 55, temp); - -#ifdef DOSTORESTATE56 - SHA1_STORE_STATE(56) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 56, temp); - -#ifdef DOSTORESTATE57 - SHA1_STORE_STATE(57) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 57, temp); - -#ifdef DOSTORESTATE58 - SHA1_STORE_STATE(58) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 58, temp); - -#ifdef DOSTORESTATE59 - SHA1_STORE_STATE(59) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 59, temp); - - - - -#ifdef DOSTORESTATE60 - SHA1_STORE_STATE(60) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 60, temp); - -#ifdef DOSTORESTATE61 - SHA1_STORE_STATE(61) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 61, temp); - -#ifdef DOSTORESTATE62 - SHA1_STORE_STATE(62) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 62, temp); - -#ifdef DOSTORESTATE63 - SHA1_STORE_STATE(63) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 63, temp); - -#ifdef DOSTORESTATE64 - SHA1_STORE_STATE(64) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 64, temp); - -#ifdef DOSTORESTATE65 - SHA1_STORE_STATE(65) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 65, temp); - -#ifdef DOSTORESTATE66 - SHA1_STORE_STATE(66) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 66, temp); - -#ifdef DOSTORESTATE67 - SHA1_STORE_STATE(67) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 67, temp); - -#ifdef DOSTORESTATE68 - SHA1_STORE_STATE(68) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 68, temp); - -#ifdef DOSTORESTATE69 - SHA1_STORE_STATE(69) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 69, temp); - -#ifdef DOSTORESTATE70 - SHA1_STORE_STATE(70) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 70, temp); - -#ifdef DOSTORESTATE71 - SHA1_STORE_STATE(71) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 71, temp); - -#ifdef DOSTORESTATE72 - SHA1_STORE_STATE(72) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 72, temp); - -#ifdef DOSTORESTATE73 - SHA1_STORE_STATE(73) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 73, temp); - -#ifdef DOSTORESTATE74 - SHA1_STORE_STATE(74) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 74, temp); - -#ifdef DOSTORESTATE75 - SHA1_STORE_STATE(75) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 75, temp); - -#ifdef DOSTORESTATE76 - SHA1_STORE_STATE(76) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 76, temp); - -#ifdef DOSTORESTATE77 - SHA1_STORE_STATE(77) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 77, temp); - -#ifdef DOSTORESTATE78 - SHA1_STORE_STATE(78) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 78, temp); - -#ifdef DOSTORESTATE79 - SHA1_STORE_STATE(79) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 79, temp); - - - - ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; -} - - - - -#define SHA1_RECOMPRESS(t) \ -static void sha1recompress_fast_ ## t (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) \ -{ \ - uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; \ - if (t > 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 79); \ - if (t > 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 78); \ - if (t > 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 77); \ - if (t > 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 76); \ - if (t > 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 75); \ - if (t > 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 74); \ - if (t > 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 73); \ - if (t > 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 72); \ - if (t > 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 71); \ - if (t > 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 70); \ - if (t > 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 69); \ - if (t > 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 68); \ - if (t > 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 67); \ - if (t > 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 66); \ - if (t > 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 65); \ - if (t > 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 64); \ - if (t > 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 63); \ - if (t > 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 62); \ - if (t > 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 61); \ - if (t > 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 60); \ - if (t > 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 59); \ - if (t > 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 58); \ - if (t > 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 57); \ - if (t > 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 56); \ - if (t > 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 55); \ - if (t > 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 54); \ - if (t > 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 53); \ - if (t > 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 52); \ - if (t > 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 51); \ - if (t > 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 50); \ - if (t > 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 49); \ - if (t > 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 48); \ - if (t > 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 47); \ - if (t > 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 46); \ - if (t > 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 45); \ - if (t > 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 44); \ - if (t > 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 43); \ - if (t > 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 42); \ - if (t > 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 41); \ - if (t > 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 40); \ - if (t > 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 39); \ - if (t > 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 38); \ - if (t > 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 37); \ - if (t > 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 36); \ - if (t > 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 35); \ - if (t > 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 34); \ - if (t > 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 33); \ - if (t > 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 32); \ - if (t > 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 31); \ - if (t > 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 30); \ - if (t > 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 29); \ - if (t > 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 28); \ - if (t > 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 27); \ - if (t > 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 26); \ - if (t > 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 25); \ - if (t > 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 24); \ - if (t > 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 23); \ - if (t > 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 22); \ - if (t > 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 21); \ - if (t > 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 20); \ - if (t > 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 19); \ - if (t > 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 18); \ - if (t > 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 17); \ - if (t > 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 16); \ - if (t > 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 15); \ - if (t > 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 14); \ - if (t > 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 13); \ - if (t > 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 12); \ - if (t > 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 11); \ - if (t > 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 10); \ - if (t > 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 9); \ - if (t > 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 8); \ - if (t > 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 7); \ - if (t > 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 6); \ - if (t > 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 5); \ - if (t > 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 4); \ - if (t > 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 3); \ - if (t > 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 2); \ - if (t > 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 1); \ - if (t > 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 0); \ - ihvin[0] = a; ihvin[1] = b; ihvin[2] = c; ihvin[3] = d; ihvin[4] = e; \ - a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; \ - if (t <= 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 0); \ - if (t <= 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 1); \ - if (t <= 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 2); \ - if (t <= 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 3); \ - if (t <= 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 4); \ - if (t <= 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 5); \ - if (t <= 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 6); \ - if (t <= 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 7); \ - if (t <= 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 8); \ - if (t <= 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 9); \ - if (t <= 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 10); \ - if (t <= 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 11); \ - if (t <= 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 12); \ - if (t <= 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 13); \ - if (t <= 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 14); \ - if (t <= 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 15); \ - if (t <= 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 16); \ - if (t <= 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 17); \ - if (t <= 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 18); \ - if (t <= 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 19); \ - if (t <= 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 20); \ - if (t <= 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 21); \ - if (t <= 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 22); \ - if (t <= 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 23); \ - if (t <= 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 24); \ - if (t <= 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 25); \ - if (t <= 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 26); \ - if (t <= 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 27); \ - if (t <= 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 28); \ - if (t <= 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 29); \ - if (t <= 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 30); \ - if (t <= 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 31); \ - if (t <= 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 32); \ - if (t <= 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 33); \ - if (t <= 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 34); \ - if (t <= 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 35); \ - if (t <= 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 36); \ - if (t <= 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 37); \ - if (t <= 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 38); \ - if (t <= 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 39); \ - if (t <= 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 40); \ - if (t <= 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 41); \ - if (t <= 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 42); \ - if (t <= 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 43); \ - if (t <= 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 44); \ - if (t <= 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 45); \ - if (t <= 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 46); \ - if (t <= 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 47); \ - if (t <= 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 48); \ - if (t <= 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 49); \ - if (t <= 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 50); \ - if (t <= 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 51); \ - if (t <= 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 52); \ - if (t <= 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 53); \ - if (t <= 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 54); \ - if (t <= 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 55); \ - if (t <= 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 56); \ - if (t <= 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 57); \ - if (t <= 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 58); \ - if (t <= 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 59); \ - if (t <= 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 60); \ - if (t <= 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 61); \ - if (t <= 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 62); \ - if (t <= 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 63); \ - if (t <= 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 64); \ - if (t <= 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 65); \ - if (t <= 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 66); \ - if (t <= 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 67); \ - if (t <= 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 68); \ - if (t <= 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 69); \ - if (t <= 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 70); \ - if (t <= 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 71); \ - if (t <= 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 72); \ - if (t <= 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 73); \ - if (t <= 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 74); \ - if (t <= 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 75); \ - if (t <= 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 76); \ - if (t <= 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 77); \ - if (t <= 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 78); \ - if (t <= 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 79); \ - ihvout[0] = ihvin[0] + a; ihvout[1] = ihvin[1] + b; ihvout[2] = ihvin[2] + c; ihvout[3] = ihvin[3] + d; ihvout[4] = ihvin[4] + e; \ -} - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4127) /* Compiler complains about the checks in the above macro being constant. */ -#endif - -#ifdef DOSTORESTATE0 -SHA1_RECOMPRESS(0) -#endif - -#ifdef DOSTORESTATE1 -SHA1_RECOMPRESS(1) -#endif - -#ifdef DOSTORESTATE2 -SHA1_RECOMPRESS(2) -#endif - -#ifdef DOSTORESTATE3 -SHA1_RECOMPRESS(3) -#endif - -#ifdef DOSTORESTATE4 -SHA1_RECOMPRESS(4) -#endif - -#ifdef DOSTORESTATE5 -SHA1_RECOMPRESS(5) -#endif - -#ifdef DOSTORESTATE6 -SHA1_RECOMPRESS(6) -#endif - -#ifdef DOSTORESTATE7 -SHA1_RECOMPRESS(7) -#endif - -#ifdef DOSTORESTATE8 -SHA1_RECOMPRESS(8) -#endif - -#ifdef DOSTORESTATE9 -SHA1_RECOMPRESS(9) -#endif - -#ifdef DOSTORESTATE10 -SHA1_RECOMPRESS(10) -#endif - -#ifdef DOSTORESTATE11 -SHA1_RECOMPRESS(11) -#endif - -#ifdef DOSTORESTATE12 -SHA1_RECOMPRESS(12) -#endif - -#ifdef DOSTORESTATE13 -SHA1_RECOMPRESS(13) -#endif - -#ifdef DOSTORESTATE14 -SHA1_RECOMPRESS(14) -#endif - -#ifdef DOSTORESTATE15 -SHA1_RECOMPRESS(15) -#endif - -#ifdef DOSTORESTATE16 -SHA1_RECOMPRESS(16) -#endif - -#ifdef DOSTORESTATE17 -SHA1_RECOMPRESS(17) -#endif - -#ifdef DOSTORESTATE18 -SHA1_RECOMPRESS(18) -#endif - -#ifdef DOSTORESTATE19 -SHA1_RECOMPRESS(19) -#endif - -#ifdef DOSTORESTATE20 -SHA1_RECOMPRESS(20) -#endif - -#ifdef DOSTORESTATE21 -SHA1_RECOMPRESS(21) -#endif - -#ifdef DOSTORESTATE22 -SHA1_RECOMPRESS(22) -#endif - -#ifdef DOSTORESTATE23 -SHA1_RECOMPRESS(23) -#endif - -#ifdef DOSTORESTATE24 -SHA1_RECOMPRESS(24) -#endif - -#ifdef DOSTORESTATE25 -SHA1_RECOMPRESS(25) -#endif - -#ifdef DOSTORESTATE26 -SHA1_RECOMPRESS(26) -#endif - -#ifdef DOSTORESTATE27 -SHA1_RECOMPRESS(27) -#endif - -#ifdef DOSTORESTATE28 -SHA1_RECOMPRESS(28) -#endif - -#ifdef DOSTORESTATE29 -SHA1_RECOMPRESS(29) -#endif - -#ifdef DOSTORESTATE30 -SHA1_RECOMPRESS(30) -#endif - -#ifdef DOSTORESTATE31 -SHA1_RECOMPRESS(31) -#endif - -#ifdef DOSTORESTATE32 -SHA1_RECOMPRESS(32) -#endif - -#ifdef DOSTORESTATE33 -SHA1_RECOMPRESS(33) -#endif - -#ifdef DOSTORESTATE34 -SHA1_RECOMPRESS(34) -#endif - -#ifdef DOSTORESTATE35 -SHA1_RECOMPRESS(35) -#endif - -#ifdef DOSTORESTATE36 -SHA1_RECOMPRESS(36) -#endif - -#ifdef DOSTORESTATE37 -SHA1_RECOMPRESS(37) -#endif - -#ifdef DOSTORESTATE38 -SHA1_RECOMPRESS(38) -#endif - -#ifdef DOSTORESTATE39 -SHA1_RECOMPRESS(39) -#endif - -#ifdef DOSTORESTATE40 -SHA1_RECOMPRESS(40) -#endif - -#ifdef DOSTORESTATE41 -SHA1_RECOMPRESS(41) -#endif - -#ifdef DOSTORESTATE42 -SHA1_RECOMPRESS(42) -#endif - -#ifdef DOSTORESTATE43 -SHA1_RECOMPRESS(43) -#endif - -#ifdef DOSTORESTATE44 -SHA1_RECOMPRESS(44) -#endif - -#ifdef DOSTORESTATE45 -SHA1_RECOMPRESS(45) -#endif - -#ifdef DOSTORESTATE46 -SHA1_RECOMPRESS(46) -#endif - -#ifdef DOSTORESTATE47 -SHA1_RECOMPRESS(47) -#endif - -#ifdef DOSTORESTATE48 -SHA1_RECOMPRESS(48) -#endif - -#ifdef DOSTORESTATE49 -SHA1_RECOMPRESS(49) -#endif - -#ifdef DOSTORESTATE50 -SHA1_RECOMPRESS(50) -#endif - -#ifdef DOSTORESTATE51 -SHA1_RECOMPRESS(51) -#endif - -#ifdef DOSTORESTATE52 -SHA1_RECOMPRESS(52) -#endif - -#ifdef DOSTORESTATE53 -SHA1_RECOMPRESS(53) -#endif - -#ifdef DOSTORESTATE54 -SHA1_RECOMPRESS(54) -#endif - -#ifdef DOSTORESTATE55 -SHA1_RECOMPRESS(55) -#endif - -#ifdef DOSTORESTATE56 -SHA1_RECOMPRESS(56) -#endif - -#ifdef DOSTORESTATE57 -SHA1_RECOMPRESS(57) -#endif - -#ifdef DOSTORESTATE58 -SHA1_RECOMPRESS(58) -#endif - -#ifdef DOSTORESTATE59 -SHA1_RECOMPRESS(59) -#endif - -#ifdef DOSTORESTATE60 -SHA1_RECOMPRESS(60) -#endif - -#ifdef DOSTORESTATE61 -SHA1_RECOMPRESS(61) -#endif - -#ifdef DOSTORESTATE62 -SHA1_RECOMPRESS(62) -#endif - -#ifdef DOSTORESTATE63 -SHA1_RECOMPRESS(63) -#endif - -#ifdef DOSTORESTATE64 -SHA1_RECOMPRESS(64) -#endif - -#ifdef DOSTORESTATE65 -SHA1_RECOMPRESS(65) -#endif - -#ifdef DOSTORESTATE66 -SHA1_RECOMPRESS(66) -#endif - -#ifdef DOSTORESTATE67 -SHA1_RECOMPRESS(67) -#endif - -#ifdef DOSTORESTATE68 -SHA1_RECOMPRESS(68) -#endif - -#ifdef DOSTORESTATE69 -SHA1_RECOMPRESS(69) -#endif - -#ifdef DOSTORESTATE70 -SHA1_RECOMPRESS(70) -#endif - -#ifdef DOSTORESTATE71 -SHA1_RECOMPRESS(71) -#endif - -#ifdef DOSTORESTATE72 -SHA1_RECOMPRESS(72) -#endif - -#ifdef DOSTORESTATE73 -SHA1_RECOMPRESS(73) -#endif - -#ifdef DOSTORESTATE74 -SHA1_RECOMPRESS(74) -#endif - -#ifdef DOSTORESTATE75 -SHA1_RECOMPRESS(75) -#endif - -#ifdef DOSTORESTATE76 -SHA1_RECOMPRESS(76) -#endif - -#ifdef DOSTORESTATE77 -SHA1_RECOMPRESS(77) -#endif - -#ifdef DOSTORESTATE78 -SHA1_RECOMPRESS(78) -#endif - -#ifdef DOSTORESTATE79 -SHA1_RECOMPRESS(79) -#endif - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -static void sha1_recompression_step(uint32_t step, uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) -{ - switch (step) - { -#ifdef DOSTORESTATE0 - case 0: - sha1recompress_fast_0(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE1 - case 1: - sha1recompress_fast_1(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE2 - case 2: - sha1recompress_fast_2(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE3 - case 3: - sha1recompress_fast_3(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE4 - case 4: - sha1recompress_fast_4(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE5 - case 5: - sha1recompress_fast_5(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE6 - case 6: - sha1recompress_fast_6(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE7 - case 7: - sha1recompress_fast_7(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE8 - case 8: - sha1recompress_fast_8(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE9 - case 9: - sha1recompress_fast_9(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE10 - case 10: - sha1recompress_fast_10(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE11 - case 11: - sha1recompress_fast_11(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE12 - case 12: - sha1recompress_fast_12(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE13 - case 13: - sha1recompress_fast_13(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE14 - case 14: - sha1recompress_fast_14(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE15 - case 15: - sha1recompress_fast_15(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE16 - case 16: - sha1recompress_fast_16(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE17 - case 17: - sha1recompress_fast_17(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE18 - case 18: - sha1recompress_fast_18(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE19 - case 19: - sha1recompress_fast_19(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE20 - case 20: - sha1recompress_fast_20(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE21 - case 21: - sha1recompress_fast_21(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE22 - case 22: - sha1recompress_fast_22(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE23 - case 23: - sha1recompress_fast_23(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE24 - case 24: - sha1recompress_fast_24(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE25 - case 25: - sha1recompress_fast_25(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE26 - case 26: - sha1recompress_fast_26(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE27 - case 27: - sha1recompress_fast_27(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE28 - case 28: - sha1recompress_fast_28(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE29 - case 29: - sha1recompress_fast_29(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE30 - case 30: - sha1recompress_fast_30(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE31 - case 31: - sha1recompress_fast_31(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE32 - case 32: - sha1recompress_fast_32(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE33 - case 33: - sha1recompress_fast_33(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE34 - case 34: - sha1recompress_fast_34(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE35 - case 35: - sha1recompress_fast_35(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE36 - case 36: - sha1recompress_fast_36(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE37 - case 37: - sha1recompress_fast_37(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE38 - case 38: - sha1recompress_fast_38(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE39 - case 39: - sha1recompress_fast_39(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE40 - case 40: - sha1recompress_fast_40(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE41 - case 41: - sha1recompress_fast_41(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE42 - case 42: - sha1recompress_fast_42(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE43 - case 43: - sha1recompress_fast_43(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE44 - case 44: - sha1recompress_fast_44(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE45 - case 45: - sha1recompress_fast_45(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE46 - case 46: - sha1recompress_fast_46(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE47 - case 47: - sha1recompress_fast_47(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE48 - case 48: - sha1recompress_fast_48(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE49 - case 49: - sha1recompress_fast_49(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE50 - case 50: - sha1recompress_fast_50(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE51 - case 51: - sha1recompress_fast_51(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE52 - case 52: - sha1recompress_fast_52(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE53 - case 53: - sha1recompress_fast_53(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE54 - case 54: - sha1recompress_fast_54(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE55 - case 55: - sha1recompress_fast_55(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE56 - case 56: - sha1recompress_fast_56(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE57 - case 57: - sha1recompress_fast_57(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE58 - case 58: - sha1recompress_fast_58(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE59 - case 59: - sha1recompress_fast_59(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE60 - case 60: - sha1recompress_fast_60(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE61 - case 61: - sha1recompress_fast_61(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE62 - case 62: - sha1recompress_fast_62(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE63 - case 63: - sha1recompress_fast_63(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE64 - case 64: - sha1recompress_fast_64(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE65 - case 65: - sha1recompress_fast_65(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE66 - case 66: - sha1recompress_fast_66(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE67 - case 67: - sha1recompress_fast_67(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE68 - case 68: - sha1recompress_fast_68(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE69 - case 69: - sha1recompress_fast_69(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE70 - case 70: - sha1recompress_fast_70(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE71 - case 71: - sha1recompress_fast_71(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE72 - case 72: - sha1recompress_fast_72(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE73 - case 73: - sha1recompress_fast_73(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE74 - case 74: - sha1recompress_fast_74(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE75 - case 75: - sha1recompress_fast_75(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE76 - case 76: - sha1recompress_fast_76(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE77 - case 77: - sha1recompress_fast_77(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE78 - case 78: - sha1recompress_fast_78(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE79 - case 79: - sha1recompress_fast_79(ihvin, ihvout, me2, state); - break; -#endif - default: - abort(); - } - -} - - - -static void sha1_process(SHA1_CTX *ctx, const uint32_t block[16]) -{ - unsigned i, j; - uint32_t ubc_dv_mask[DVMASKSIZE] = { 0xFFFFFFFF }; - uint32_t ihvtmp[5]; - - ctx->ihv1[0] = ctx->ihv[0]; - ctx->ihv1[1] = ctx->ihv[1]; - ctx->ihv1[2] = ctx->ihv[2]; - ctx->ihv1[3] = ctx->ihv[3]; - ctx->ihv1[4] = ctx->ihv[4]; - - sha1_compression_states(ctx->ihv, block, ctx->m1, ctx->states); - - if (ctx->detect_coll) - { - if (ctx->ubc_check) - { - ubc_check(ctx->m1, ubc_dv_mask); - } - - if (ubc_dv_mask[0] != 0) - { - for (i = 0; sha1_dvs[i].dvType != 0; ++i) - { - if (ubc_dv_mask[0] & ((uint32_t)(1) << sha1_dvs[i].maskb)) - { - for (j = 0; j < 80; ++j) - ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j]; - - sha1_recompression_step(sha1_dvs[i].testt, ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]); - - /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */ - if ((0 == ((ihvtmp[0] ^ ctx->ihv[0]) | (ihvtmp[1] ^ ctx->ihv[1]) | (ihvtmp[2] ^ ctx->ihv[2]) | (ihvtmp[3] ^ ctx->ihv[3]) | (ihvtmp[4] ^ ctx->ihv[4]))) - || (ctx->reduced_round_coll && 0==((ctx->ihv1[0] ^ ctx->ihv2[0]) | (ctx->ihv1[1] ^ ctx->ihv2[1]) | (ctx->ihv1[2] ^ ctx->ihv2[2]) | (ctx->ihv1[3] ^ ctx->ihv2[3]) | (ctx->ihv1[4] ^ ctx->ihv2[4])))) - { - ctx->found_collision = 1; - - if (ctx->safe_hash) - { - sha1_compression_W(ctx->ihv, ctx->m1); - sha1_compression_W(ctx->ihv, ctx->m1); - } - - break; - } - } - } - } - } -} - -void SHA1DCInit(SHA1_CTX *ctx) -{ - ctx->total = 0; - ctx->ihv[0] = 0x67452301; - ctx->ihv[1] = 0xEFCDAB89; - ctx->ihv[2] = 0x98BADCFE; - ctx->ihv[3] = 0x10325476; - ctx->ihv[4] = 0xC3D2E1F0; - ctx->found_collision = 0; - ctx->safe_hash = SHA1DC_INIT_SAFE_HASH_DEFAULT; - ctx->ubc_check = 1; - ctx->detect_coll = 1; - ctx->reduced_round_coll = 0; - ctx->callback = NULL; -} - -void SHA1DCSetSafeHash(SHA1_CTX *ctx, int safehash) -{ - if (safehash) - ctx->safe_hash = 1; - else - ctx->safe_hash = 0; -} - - -void SHA1DCSetUseUBC(SHA1_CTX *ctx, int ubc_check) -{ - if (ubc_check) - ctx->ubc_check = 1; - else - ctx->ubc_check = 0; -} - -void SHA1DCSetUseDetectColl(SHA1_CTX *ctx, int detect_coll) -{ - if (detect_coll) - ctx->detect_coll = 1; - else - ctx->detect_coll = 0; -} - -void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX *ctx, int reduced_round_coll) -{ - if (reduced_round_coll) - ctx->reduced_round_coll = 1; - else - ctx->reduced_round_coll = 0; -} - -void SHA1DCSetCallback(SHA1_CTX *ctx, collision_block_callback callback) -{ - ctx->callback = callback; -} - -void SHA1DCUpdate(SHA1_CTX *ctx, const char *buf, size_t len) -{ - unsigned left, fill; - - if (len == 0) - return; - - left = ctx->total & 63; - fill = 64 - left; - - if (left && len >= fill) - { - ctx->total += fill; - memcpy(ctx->buffer + left, buf, fill); - sha1_process(ctx, (uint32_t*)(ctx->buffer)); - buf += fill; - len -= fill; - left = 0; - } - while (len >= 64) - { - ctx->total += 64; - -#if defined(SHA1DC_ALLOW_UNALIGNED_ACCESS) - sha1_process(ctx, (uint32_t*)(buf)); -#else - memcpy(ctx->buffer, buf, 64); - sha1_process(ctx, (uint32_t*)(ctx->buffer)); -#endif /* defined(SHA1DC_ALLOW_UNALIGNED_ACCESS) */ - buf += 64; - len -= 64; - } - if (len > 0) - { - ctx->total += len; - memcpy(ctx->buffer + left, buf, len); - } -} - -static const unsigned char sha1_padding[64] = -{ - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -int SHA1DCFinal(unsigned char output[20], SHA1_CTX *ctx) -{ - uint32_t last = ctx->total & 63; - uint32_t padn = (last < 56) ? (56 - last) : (120 - last); - uint64_t total; - SHA1DCUpdate(ctx, (const char*)(sha1_padding), padn); - - total = ctx->total - padn; - total <<= 3; - ctx->buffer[56] = (unsigned char)(total >> 56); - ctx->buffer[57] = (unsigned char)(total >> 48); - ctx->buffer[58] = (unsigned char)(total >> 40); - ctx->buffer[59] = (unsigned char)(total >> 32); - ctx->buffer[60] = (unsigned char)(total >> 24); - ctx->buffer[61] = (unsigned char)(total >> 16); - ctx->buffer[62] = (unsigned char)(total >> 8); - ctx->buffer[63] = (unsigned char)(total); - sha1_process(ctx, (uint32_t*)(ctx->buffer)); - output[0] = (unsigned char)(ctx->ihv[0] >> 24); - output[1] = (unsigned char)(ctx->ihv[0] >> 16); - output[2] = (unsigned char)(ctx->ihv[0] >> 8); - output[3] = (unsigned char)(ctx->ihv[0]); - output[4] = (unsigned char)(ctx->ihv[1] >> 24); - output[5] = (unsigned char)(ctx->ihv[1] >> 16); - output[6] = (unsigned char)(ctx->ihv[1] >> 8); - output[7] = (unsigned char)(ctx->ihv[1]); - output[8] = (unsigned char)(ctx->ihv[2] >> 24); - output[9] = (unsigned char)(ctx->ihv[2] >> 16); - output[10] = (unsigned char)(ctx->ihv[2] >> 8); - output[11] = (unsigned char)(ctx->ihv[2]); - output[12] = (unsigned char)(ctx->ihv[3] >> 24); - output[13] = (unsigned char)(ctx->ihv[3] >> 16); - output[14] = (unsigned char)(ctx->ihv[3] >> 8); - output[15] = (unsigned char)(ctx->ihv[3]); - output[16] = (unsigned char)(ctx->ihv[4] >> 24); - output[17] = (unsigned char)(ctx->ihv[4] >> 16); - output[18] = (unsigned char)(ctx->ihv[4] >> 8); - output[19] = (unsigned char)(ctx->ihv[4]); - return ctx->found_collision; -} - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/sha1.h b/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/sha1.h deleted file mode 100644 index 1e4e94b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/sha1.h +++ /dev/null @@ -1,110 +0,0 @@ -/*** -* Copyright 2017 Marc Stevens , Dan Shumow -* Distributed under the MIT Software License. -* See accompanying file LICENSE.txt or copy at -* https://opensource.org/licenses/MIT -***/ - -#ifndef SHA1DC_SHA1_H -#define SHA1DC_SHA1_H - -#if defined(__cplusplus) -extern "C" { -#endif - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif - -/* sha-1 compression function that takes an already expanded message, and additionally store intermediate states */ -/* only stores states ii (the state between step ii-1 and step ii) when DOSTORESTATEii is defined in ubc_check.h */ -void sha1_compression_states(uint32_t[5], const uint32_t[16], uint32_t[80], uint32_t[80][5]); - -/* -// Function type for sha1_recompression_step_T (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]). -// Where 0 <= T < 80 -// me2 is an expanded message (the expansion of an original message block XOR'ed with a disturbance vector's message block difference.) -// state is the internal state (a,b,c,d,e) before step T of the SHA-1 compression function while processing the original message block. -// The function will return: -// ihvin: The reconstructed input chaining value. -// ihvout: The reconstructed output chaining value. -*/ -typedef void(*sha1_recompression_type)(uint32_t*, uint32_t*, const uint32_t*, const uint32_t*); - -/* A callback function type that can be set to be called when a collision block has been found: */ -/* void collision_block_callback(uint64_t byteoffset, const uint32_t ihvin1[5], const uint32_t ihvin2[5], const uint32_t m1[80], const uint32_t m2[80]) */ -typedef void(*collision_block_callback)(uint64_t, const uint32_t*, const uint32_t*, const uint32_t*, const uint32_t*); - -/* The SHA-1 context. */ -typedef struct { - uint64_t total; - uint32_t ihv[5]; - unsigned char buffer[64]; - int found_collision; - int safe_hash; - int detect_coll; - int ubc_check; - int reduced_round_coll; - collision_block_callback callback; - - uint32_t ihv1[5]; - uint32_t ihv2[5]; - uint32_t m1[80]; - uint32_t m2[80]; - uint32_t states[80][5]; -} SHA1_CTX; - -/* Initialize SHA-1 context. */ -void SHA1DCInit(SHA1_CTX*); - -/* - Function to enable safe SHA-1 hashing: - Collision attacks are thwarted by hashing a detected near-collision block 3 times. - Think of it as extending SHA-1 from 80-steps to 240-steps for such blocks: - The best collision attacks against SHA-1 have complexity about 2^60, - thus for 240-steps an immediate lower-bound for the best cryptanalytic attacks would be 2^180. - An attacker would be better off using a generic birthday search of complexity 2^80. - - Enabling safe SHA-1 hashing will result in the correct SHA-1 hash for messages where no collision attack was detected, - but it will result in a different SHA-1 hash for messages where a collision attack was detected. - This will automatically invalidate SHA-1 based digital signature forgeries. - Enabled by default. -*/ -void SHA1DCSetSafeHash(SHA1_CTX*, int); - -/* - Function to disable or enable the use of Unavoidable Bitconditions (provides a significant speed up). - Enabled by default - */ -void SHA1DCSetUseUBC(SHA1_CTX*, int); - -/* - Function to disable or enable the use of Collision Detection. - Enabled by default. - */ -void SHA1DCSetUseDetectColl(SHA1_CTX*, int); - -/* function to disable or enable the detection of reduced-round SHA-1 collisions */ -/* disabled by default */ -void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX*, int); - -/* function to set a callback function, pass NULL to disable */ -/* by default no callback set */ -void SHA1DCSetCallback(SHA1_CTX*, collision_block_callback); - -/* update SHA-1 context with buffer contents */ -void SHA1DCUpdate(SHA1_CTX*, const char*, size_t); - -/* obtain SHA-1 hash from SHA-1 context */ -/* returns: 0 = no collision detected, otherwise = collision found => warn user for active attack */ -int SHA1DCFinal(unsigned char[20], SHA1_CTX*); - -#if defined(__cplusplus) -} -#endif - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/ubc_check.c b/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/ubc_check.c deleted file mode 100644 index b3beff2..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/ubc_check.c +++ /dev/null @@ -1,372 +0,0 @@ -/*** -* Copyright 2017 Marc Stevens , Dan Shumow -* Distributed under the MIT Software License. -* See accompanying file LICENSE.txt or copy at -* https://opensource.org/licenses/MIT -***/ - -/* -// this file was generated by the 'parse_bitrel' program in the tools section -// using the data files from directory 'tools/data/3565' -// -// sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check -// dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) -// dm[80] is the expanded message block XOR-difference defined by the DV -// testt is the step to do the recompression from for collision detection -// maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check -// -// ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs -// it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met -// thus one needs to do the recompression check for each DV that has its bit set -// -// ubc_check is programmatically generated and the unavoidable bitconditions have been hardcoded -// a directly verifiable version named ubc_check_verify can be found in ubc_check_verify.c -// ubc_check has been verified against ubc_check_verify using the 'ubc_check_test' program in the tools section -*/ - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif -#ifdef SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C -#include SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C -#endif -#include "ubc_check.h" - -static const uint32_t DV_I_43_0_bit = (uint32_t)(1) << 0; -static const uint32_t DV_I_44_0_bit = (uint32_t)(1) << 1; -static const uint32_t DV_I_45_0_bit = (uint32_t)(1) << 2; -static const uint32_t DV_I_46_0_bit = (uint32_t)(1) << 3; -static const uint32_t DV_I_46_2_bit = (uint32_t)(1) << 4; -static const uint32_t DV_I_47_0_bit = (uint32_t)(1) << 5; -static const uint32_t DV_I_47_2_bit = (uint32_t)(1) << 6; -static const uint32_t DV_I_48_0_bit = (uint32_t)(1) << 7; -static const uint32_t DV_I_48_2_bit = (uint32_t)(1) << 8; -static const uint32_t DV_I_49_0_bit = (uint32_t)(1) << 9; -static const uint32_t DV_I_49_2_bit = (uint32_t)(1) << 10; -static const uint32_t DV_I_50_0_bit = (uint32_t)(1) << 11; -static const uint32_t DV_I_50_2_bit = (uint32_t)(1) << 12; -static const uint32_t DV_I_51_0_bit = (uint32_t)(1) << 13; -static const uint32_t DV_I_51_2_bit = (uint32_t)(1) << 14; -static const uint32_t DV_I_52_0_bit = (uint32_t)(1) << 15; -static const uint32_t DV_II_45_0_bit = (uint32_t)(1) << 16; -static const uint32_t DV_II_46_0_bit = (uint32_t)(1) << 17; -static const uint32_t DV_II_46_2_bit = (uint32_t)(1) << 18; -static const uint32_t DV_II_47_0_bit = (uint32_t)(1) << 19; -static const uint32_t DV_II_48_0_bit = (uint32_t)(1) << 20; -static const uint32_t DV_II_49_0_bit = (uint32_t)(1) << 21; -static const uint32_t DV_II_49_2_bit = (uint32_t)(1) << 22; -static const uint32_t DV_II_50_0_bit = (uint32_t)(1) << 23; -static const uint32_t DV_II_50_2_bit = (uint32_t)(1) << 24; -static const uint32_t DV_II_51_0_bit = (uint32_t)(1) << 25; -static const uint32_t DV_II_51_2_bit = (uint32_t)(1) << 26; -static const uint32_t DV_II_52_0_bit = (uint32_t)(1) << 27; -static const uint32_t DV_II_53_0_bit = (uint32_t)(1) << 28; -static const uint32_t DV_II_54_0_bit = (uint32_t)(1) << 29; -static const uint32_t DV_II_55_0_bit = (uint32_t)(1) << 30; -static const uint32_t DV_II_56_0_bit = (uint32_t)(1) << 31; - -dv_info_t sha1_dvs[] = -{ - {1,43,0,58,0,0, { 0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803,0x80000161,0x80000599 } } -, {1,44,0,58,0,1, { 0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803,0x80000161 } } -, {1,45,0,58,0,2, { 0xf4000014,0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803 } } -, {1,46,0,58,0,3, { 0x2c000010,0xf4000014,0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c } } -, {1,46,2,58,0,4, { 0xb0000040,0xd0000053,0xd0000022,0x20000000,0x60000032,0x60000043,0x20000040,0xe0000042,0x60000002,0x80000001,0x00000020,0x00000003,0x40000052,0x40000040,0xe0000052,0xa0000000,0x80000040,0x20000001,0x20000060,0x80000001,0x40000042,0xc0000043,0x40000022,0x00000003,0x40000042,0xc0000043,0xc0000022,0x00000001,0x40000002,0xc0000043,0x40000062,0x80000001,0x40000042,0x40000042,0x40000002,0x00000002,0x00000040,0x80000002,0x80000000,0x80000002,0x80000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000000,0x00000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000101,0x00000009,0x00000012,0x00000202,0x0000001a,0x00000124,0x0000040c,0x00000026,0x0000004a,0x0000080a,0x00000060,0x00000590,0x00001020,0x0000039a,0x00000132 } } -, {1,47,0,58,0,5, { 0xc8000010,0x2c000010,0xf4000014,0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6 } } -, {1,47,2,58,0,6, { 0x20000043,0xb0000040,0xd0000053,0xd0000022,0x20000000,0x60000032,0x60000043,0x20000040,0xe0000042,0x60000002,0x80000001,0x00000020,0x00000003,0x40000052,0x40000040,0xe0000052,0xa0000000,0x80000040,0x20000001,0x20000060,0x80000001,0x40000042,0xc0000043,0x40000022,0x00000003,0x40000042,0xc0000043,0xc0000022,0x00000001,0x40000002,0xc0000043,0x40000062,0x80000001,0x40000042,0x40000042,0x40000002,0x00000002,0x00000040,0x80000002,0x80000000,0x80000002,0x80000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000000,0x00000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000101,0x00000009,0x00000012,0x00000202,0x0000001a,0x00000124,0x0000040c,0x00000026,0x0000004a,0x0000080a,0x00000060,0x00000590,0x00001020,0x0000039a } } -, {1,48,0,58,0,7, { 0xb800000a,0xc8000010,0x2c000010,0xf4000014,0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408 } } -, {1,48,2,58,0,8, { 0xe000002a,0x20000043,0xb0000040,0xd0000053,0xd0000022,0x20000000,0x60000032,0x60000043,0x20000040,0xe0000042,0x60000002,0x80000001,0x00000020,0x00000003,0x40000052,0x40000040,0xe0000052,0xa0000000,0x80000040,0x20000001,0x20000060,0x80000001,0x40000042,0xc0000043,0x40000022,0x00000003,0x40000042,0xc0000043,0xc0000022,0x00000001,0x40000002,0xc0000043,0x40000062,0x80000001,0x40000042,0x40000042,0x40000002,0x00000002,0x00000040,0x80000002,0x80000000,0x80000002,0x80000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000000,0x00000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000101,0x00000009,0x00000012,0x00000202,0x0000001a,0x00000124,0x0000040c,0x00000026,0x0000004a,0x0000080a,0x00000060,0x00000590,0x00001020 } } -, {1,49,0,58,0,9, { 0x18000000,0xb800000a,0xc8000010,0x2c000010,0xf4000014,0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164 } } -, {1,49,2,58,0,10, { 0x60000000,0xe000002a,0x20000043,0xb0000040,0xd0000053,0xd0000022,0x20000000,0x60000032,0x60000043,0x20000040,0xe0000042,0x60000002,0x80000001,0x00000020,0x00000003,0x40000052,0x40000040,0xe0000052,0xa0000000,0x80000040,0x20000001,0x20000060,0x80000001,0x40000042,0xc0000043,0x40000022,0x00000003,0x40000042,0xc0000043,0xc0000022,0x00000001,0x40000002,0xc0000043,0x40000062,0x80000001,0x40000042,0x40000042,0x40000002,0x00000002,0x00000040,0x80000002,0x80000000,0x80000002,0x80000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000000,0x00000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000101,0x00000009,0x00000012,0x00000202,0x0000001a,0x00000124,0x0000040c,0x00000026,0x0000004a,0x0000080a,0x00000060,0x00000590 } } -, {1,50,0,65,0,11, { 0x0800000c,0x18000000,0xb800000a,0xc8000010,0x2c000010,0xf4000014,0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018 } } -, {1,50,2,65,0,12, { 0x20000030,0x60000000,0xe000002a,0x20000043,0xb0000040,0xd0000053,0xd0000022,0x20000000,0x60000032,0x60000043,0x20000040,0xe0000042,0x60000002,0x80000001,0x00000020,0x00000003,0x40000052,0x40000040,0xe0000052,0xa0000000,0x80000040,0x20000001,0x20000060,0x80000001,0x40000042,0xc0000043,0x40000022,0x00000003,0x40000042,0xc0000043,0xc0000022,0x00000001,0x40000002,0xc0000043,0x40000062,0x80000001,0x40000042,0x40000042,0x40000002,0x00000002,0x00000040,0x80000002,0x80000000,0x80000002,0x80000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000000,0x00000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000101,0x00000009,0x00000012,0x00000202,0x0000001a,0x00000124,0x0000040c,0x00000026,0x0000004a,0x0000080a,0x00000060 } } -, {1,51,0,65,0,13, { 0xe8000000,0x0800000c,0x18000000,0xb800000a,0xc8000010,0x2c000010,0xf4000014,0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202 } } -, {1,51,2,65,0,14, { 0xa0000003,0x20000030,0x60000000,0xe000002a,0x20000043,0xb0000040,0xd0000053,0xd0000022,0x20000000,0x60000032,0x60000043,0x20000040,0xe0000042,0x60000002,0x80000001,0x00000020,0x00000003,0x40000052,0x40000040,0xe0000052,0xa0000000,0x80000040,0x20000001,0x20000060,0x80000001,0x40000042,0xc0000043,0x40000022,0x00000003,0x40000042,0xc0000043,0xc0000022,0x00000001,0x40000002,0xc0000043,0x40000062,0x80000001,0x40000042,0x40000042,0x40000002,0x00000002,0x00000040,0x80000002,0x80000000,0x80000002,0x80000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000000,0x00000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000101,0x00000009,0x00000012,0x00000202,0x0000001a,0x00000124,0x0000040c,0x00000026,0x0000004a,0x0000080a } } -, {1,52,0,65,0,15, { 0x04000010,0xe8000000,0x0800000c,0x18000000,0xb800000a,0xc8000010,0x2c000010,0xf4000014,0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012 } } -, {2,45,0,58,0,16, { 0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089,0x00000014,0x8000024b,0x0000011b,0x8000016d,0x8000041a,0x000002e4,0x80000054,0x00000967 } } -, {2,46,0,58,0,17, { 0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089,0x00000014,0x8000024b,0x0000011b,0x8000016d,0x8000041a,0x000002e4,0x80000054 } } -, {2,46,2,58,0,18, { 0x90000070,0xb0000053,0x30000008,0x00000043,0xd0000072,0xb0000010,0xf0000062,0xc0000042,0x00000030,0xe0000042,0x20000060,0xe0000041,0x20000050,0xc0000041,0xe0000072,0xa0000003,0xc0000012,0x60000041,0xc0000032,0x20000001,0xc0000002,0xe0000042,0x60000042,0x80000002,0x00000000,0x00000000,0x80000000,0x00000002,0x00000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000001,0x00000060,0x80000003,0x40000002,0xc0000040,0xc0000002,0x80000000,0x80000000,0x80000002,0x00000040,0x00000002,0x80000000,0x80000000,0x80000000,0x00000002,0x00000040,0x00000000,0x80000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000105,0x00000089,0x00000016,0x0000020b,0x0000011b,0x0000012d,0x0000041e,0x00000224,0x00000050,0x0000092e,0x0000046c,0x000005b6,0x0000106a,0x00000b90,0x00000152 } } -, {2,47,0,58,0,19, { 0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089,0x00000014,0x8000024b,0x0000011b,0x8000016d,0x8000041a,0x000002e4 } } -, {2,48,0,58,0,20, { 0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089,0x00000014,0x8000024b,0x0000011b,0x8000016d,0x8000041a } } -, {2,49,0,58,0,21, { 0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089,0x00000014,0x8000024b,0x0000011b,0x8000016d } } -, {2,49,2,58,0,22, { 0xf0000010,0xf000006a,0x80000040,0x90000070,0xb0000053,0x30000008,0x00000043,0xd0000072,0xb0000010,0xf0000062,0xc0000042,0x00000030,0xe0000042,0x20000060,0xe0000041,0x20000050,0xc0000041,0xe0000072,0xa0000003,0xc0000012,0x60000041,0xc0000032,0x20000001,0xc0000002,0xe0000042,0x60000042,0x80000002,0x00000000,0x00000000,0x80000000,0x00000002,0x00000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000001,0x00000060,0x80000003,0x40000002,0xc0000040,0xc0000002,0x80000000,0x80000000,0x80000002,0x00000040,0x00000002,0x80000000,0x80000000,0x80000000,0x00000002,0x00000040,0x00000000,0x80000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000105,0x00000089,0x00000016,0x0000020b,0x0000011b,0x0000012d,0x0000041e,0x00000224,0x00000050,0x0000092e,0x0000046c,0x000005b6 } } -, {2,50,0,65,0,23, { 0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089,0x00000014,0x8000024b,0x0000011b } } -, {2,50,2,65,0,24, { 0xd0000072,0xf0000010,0xf000006a,0x80000040,0x90000070,0xb0000053,0x30000008,0x00000043,0xd0000072,0xb0000010,0xf0000062,0xc0000042,0x00000030,0xe0000042,0x20000060,0xe0000041,0x20000050,0xc0000041,0xe0000072,0xa0000003,0xc0000012,0x60000041,0xc0000032,0x20000001,0xc0000002,0xe0000042,0x60000042,0x80000002,0x00000000,0x00000000,0x80000000,0x00000002,0x00000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000001,0x00000060,0x80000003,0x40000002,0xc0000040,0xc0000002,0x80000000,0x80000000,0x80000002,0x00000040,0x00000002,0x80000000,0x80000000,0x80000000,0x00000002,0x00000040,0x00000000,0x80000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000105,0x00000089,0x00000016,0x0000020b,0x0000011b,0x0000012d,0x0000041e,0x00000224,0x00000050,0x0000092e,0x0000046c } } -, {2,51,0,65,0,25, { 0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089,0x00000014,0x8000024b } } -, {2,51,2,65,0,26, { 0x00000043,0xd0000072,0xf0000010,0xf000006a,0x80000040,0x90000070,0xb0000053,0x30000008,0x00000043,0xd0000072,0xb0000010,0xf0000062,0xc0000042,0x00000030,0xe0000042,0x20000060,0xe0000041,0x20000050,0xc0000041,0xe0000072,0xa0000003,0xc0000012,0x60000041,0xc0000032,0x20000001,0xc0000002,0xe0000042,0x60000042,0x80000002,0x00000000,0x00000000,0x80000000,0x00000002,0x00000040,0x00000000,0x80000040,0x80000000,0x00000040,0x80000001,0x00000060,0x80000003,0x40000002,0xc0000040,0xc0000002,0x80000000,0x80000000,0x80000002,0x00000040,0x00000002,0x80000000,0x80000000,0x80000000,0x00000002,0x00000040,0x00000000,0x80000040,0x80000002,0x00000000,0x80000000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000004,0x00000080,0x00000004,0x00000009,0x00000105,0x00000089,0x00000016,0x0000020b,0x0000011b,0x0000012d,0x0000041e,0x00000224,0x00000050,0x0000092e } } -, {2,52,0,65,0,27, { 0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089,0x00000014 } } -, {2,53,0,65,0,28, { 0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107,0x00000089 } } -, {2,54,0,65,0,29, { 0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107 } } -, {2,55,0,65,0,30, { 0x00000010,0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b } } -, {2,56,0,65,0,31, { 0x2600001a,0x00000010,0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046 } } -, {0,0,0,0,0,0, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} -}; -void ubc_check(const uint32_t W[80], uint32_t dvmask[1]) -{ - uint32_t mask = ~((uint32_t)(0)); - mask &= (((((W[44]^W[45])>>29)&1)-1) | ~(DV_I_48_0_bit|DV_I_51_0_bit|DV_I_52_0_bit|DV_II_45_0_bit|DV_II_46_0_bit|DV_II_50_0_bit|DV_II_51_0_bit)); - mask &= (((((W[49]^W[50])>>29)&1)-1) | ~(DV_I_46_0_bit|DV_II_45_0_bit|DV_II_50_0_bit|DV_II_51_0_bit|DV_II_55_0_bit|DV_II_56_0_bit)); - mask &= (((((W[48]^W[49])>>29)&1)-1) | ~(DV_I_45_0_bit|DV_I_52_0_bit|DV_II_49_0_bit|DV_II_50_0_bit|DV_II_54_0_bit|DV_II_55_0_bit)); - mask &= ((((W[47]^(W[50]>>25))&(1<<4))-(1<<4)) | ~(DV_I_47_0_bit|DV_I_49_0_bit|DV_I_51_0_bit|DV_II_45_0_bit|DV_II_51_0_bit|DV_II_56_0_bit)); - mask &= (((((W[47]^W[48])>>29)&1)-1) | ~(DV_I_44_0_bit|DV_I_51_0_bit|DV_II_48_0_bit|DV_II_49_0_bit|DV_II_53_0_bit|DV_II_54_0_bit)); - mask &= (((((W[46]>>4)^(W[49]>>29))&1)-1) | ~(DV_I_46_0_bit|DV_I_48_0_bit|DV_I_50_0_bit|DV_I_52_0_bit|DV_II_50_0_bit|DV_II_55_0_bit)); - mask &= (((((W[46]^W[47])>>29)&1)-1) | ~(DV_I_43_0_bit|DV_I_50_0_bit|DV_II_47_0_bit|DV_II_48_0_bit|DV_II_52_0_bit|DV_II_53_0_bit)); - mask &= (((((W[45]>>4)^(W[48]>>29))&1)-1) | ~(DV_I_45_0_bit|DV_I_47_0_bit|DV_I_49_0_bit|DV_I_51_0_bit|DV_II_49_0_bit|DV_II_54_0_bit)); - mask &= (((((W[45]^W[46])>>29)&1)-1) | ~(DV_I_49_0_bit|DV_I_52_0_bit|DV_II_46_0_bit|DV_II_47_0_bit|DV_II_51_0_bit|DV_II_52_0_bit)); - mask &= (((((W[44]>>4)^(W[47]>>29))&1)-1) | ~(DV_I_44_0_bit|DV_I_46_0_bit|DV_I_48_0_bit|DV_I_50_0_bit|DV_II_48_0_bit|DV_II_53_0_bit)); - mask &= (((((W[43]>>4)^(W[46]>>29))&1)-1) | ~(DV_I_43_0_bit|DV_I_45_0_bit|DV_I_47_0_bit|DV_I_49_0_bit|DV_II_47_0_bit|DV_II_52_0_bit)); - mask &= (((((W[43]^W[44])>>29)&1)-1) | ~(DV_I_47_0_bit|DV_I_50_0_bit|DV_I_51_0_bit|DV_II_45_0_bit|DV_II_49_0_bit|DV_II_50_0_bit)); - mask &= (((((W[42]>>4)^(W[45]>>29))&1)-1) | ~(DV_I_44_0_bit|DV_I_46_0_bit|DV_I_48_0_bit|DV_I_52_0_bit|DV_II_46_0_bit|DV_II_51_0_bit)); - mask &= (((((W[41]>>4)^(W[44]>>29))&1)-1) | ~(DV_I_43_0_bit|DV_I_45_0_bit|DV_I_47_0_bit|DV_I_51_0_bit|DV_II_45_0_bit|DV_II_50_0_bit)); - mask &= (((((W[40]^W[41])>>29)&1)-1) | ~(DV_I_44_0_bit|DV_I_47_0_bit|DV_I_48_0_bit|DV_II_46_0_bit|DV_II_47_0_bit|DV_II_56_0_bit)); - mask &= (((((W[54]^W[55])>>29)&1)-1) | ~(DV_I_51_0_bit|DV_II_47_0_bit|DV_II_50_0_bit|DV_II_55_0_bit|DV_II_56_0_bit)); - mask &= (((((W[53]^W[54])>>29)&1)-1) | ~(DV_I_50_0_bit|DV_II_46_0_bit|DV_II_49_0_bit|DV_II_54_0_bit|DV_II_55_0_bit)); - mask &= (((((W[52]^W[53])>>29)&1)-1) | ~(DV_I_49_0_bit|DV_II_45_0_bit|DV_II_48_0_bit|DV_II_53_0_bit|DV_II_54_0_bit)); - mask &= ((((W[50]^(W[53]>>25))&(1<<4))-(1<<4)) | ~(DV_I_50_0_bit|DV_I_52_0_bit|DV_II_46_0_bit|DV_II_48_0_bit|DV_II_54_0_bit)); - mask &= (((((W[50]^W[51])>>29)&1)-1) | ~(DV_I_47_0_bit|DV_II_46_0_bit|DV_II_51_0_bit|DV_II_52_0_bit|DV_II_56_0_bit)); - mask &= ((((W[49]^(W[52]>>25))&(1<<4))-(1<<4)) | ~(DV_I_49_0_bit|DV_I_51_0_bit|DV_II_45_0_bit|DV_II_47_0_bit|DV_II_53_0_bit)); - mask &= ((((W[48]^(W[51]>>25))&(1<<4))-(1<<4)) | ~(DV_I_48_0_bit|DV_I_50_0_bit|DV_I_52_0_bit|DV_II_46_0_bit|DV_II_52_0_bit)); - mask &= (((((W[42]^W[43])>>29)&1)-1) | ~(DV_I_46_0_bit|DV_I_49_0_bit|DV_I_50_0_bit|DV_II_48_0_bit|DV_II_49_0_bit)); - mask &= (((((W[41]^W[42])>>29)&1)-1) | ~(DV_I_45_0_bit|DV_I_48_0_bit|DV_I_49_0_bit|DV_II_47_0_bit|DV_II_48_0_bit)); - mask &= (((((W[40]>>4)^(W[43]>>29))&1)-1) | ~(DV_I_44_0_bit|DV_I_46_0_bit|DV_I_50_0_bit|DV_II_49_0_bit|DV_II_56_0_bit)); - mask &= (((((W[39]>>4)^(W[42]>>29))&1)-1) | ~(DV_I_43_0_bit|DV_I_45_0_bit|DV_I_49_0_bit|DV_II_48_0_bit|DV_II_55_0_bit)); - if (mask & (DV_I_44_0_bit|DV_I_48_0_bit|DV_II_47_0_bit|DV_II_54_0_bit|DV_II_56_0_bit)) - mask &= (((((W[38]>>4)^(W[41]>>29))&1)-1) | ~(DV_I_44_0_bit|DV_I_48_0_bit|DV_II_47_0_bit|DV_II_54_0_bit|DV_II_56_0_bit)); - mask &= (((((W[37]>>4)^(W[40]>>29))&1)-1) | ~(DV_I_43_0_bit|DV_I_47_0_bit|DV_II_46_0_bit|DV_II_53_0_bit|DV_II_55_0_bit)); - if (mask & (DV_I_52_0_bit|DV_II_48_0_bit|DV_II_51_0_bit|DV_II_56_0_bit)) - mask &= (((((W[55]^W[56])>>29)&1)-1) | ~(DV_I_52_0_bit|DV_II_48_0_bit|DV_II_51_0_bit|DV_II_56_0_bit)); - if (mask & (DV_I_52_0_bit|DV_II_48_0_bit|DV_II_50_0_bit|DV_II_56_0_bit)) - mask &= ((((W[52]^(W[55]>>25))&(1<<4))-(1<<4)) | ~(DV_I_52_0_bit|DV_II_48_0_bit|DV_II_50_0_bit|DV_II_56_0_bit)); - if (mask & (DV_I_51_0_bit|DV_II_47_0_bit|DV_II_49_0_bit|DV_II_55_0_bit)) - mask &= ((((W[51]^(W[54]>>25))&(1<<4))-(1<<4)) | ~(DV_I_51_0_bit|DV_II_47_0_bit|DV_II_49_0_bit|DV_II_55_0_bit)); - if (mask & (DV_I_48_0_bit|DV_II_47_0_bit|DV_II_52_0_bit|DV_II_53_0_bit)) - mask &= (((((W[51]^W[52])>>29)&1)-1) | ~(DV_I_48_0_bit|DV_II_47_0_bit|DV_II_52_0_bit|DV_II_53_0_bit)); - if (mask & (DV_I_46_0_bit|DV_I_49_0_bit|DV_II_45_0_bit|DV_II_48_0_bit)) - mask &= (((((W[36]>>4)^(W[40]>>29))&1)-1) | ~(DV_I_46_0_bit|DV_I_49_0_bit|DV_II_45_0_bit|DV_II_48_0_bit)); - if (mask & (DV_I_52_0_bit|DV_II_48_0_bit|DV_II_49_0_bit)) - mask &= ((0-(((W[53]^W[56])>>29)&1)) | ~(DV_I_52_0_bit|DV_II_48_0_bit|DV_II_49_0_bit)); - if (mask & (DV_I_50_0_bit|DV_II_46_0_bit|DV_II_47_0_bit)) - mask &= ((0-(((W[51]^W[54])>>29)&1)) | ~(DV_I_50_0_bit|DV_II_46_0_bit|DV_II_47_0_bit)); - if (mask & (DV_I_49_0_bit|DV_I_51_0_bit|DV_II_45_0_bit)) - mask &= ((0-(((W[50]^W[52])>>29)&1)) | ~(DV_I_49_0_bit|DV_I_51_0_bit|DV_II_45_0_bit)); - if (mask & (DV_I_48_0_bit|DV_I_50_0_bit|DV_I_52_0_bit)) - mask &= ((0-(((W[49]^W[51])>>29)&1)) | ~(DV_I_48_0_bit|DV_I_50_0_bit|DV_I_52_0_bit)); - if (mask & (DV_I_47_0_bit|DV_I_49_0_bit|DV_I_51_0_bit)) - mask &= ((0-(((W[48]^W[50])>>29)&1)) | ~(DV_I_47_0_bit|DV_I_49_0_bit|DV_I_51_0_bit)); - if (mask & (DV_I_46_0_bit|DV_I_48_0_bit|DV_I_50_0_bit)) - mask &= ((0-(((W[47]^W[49])>>29)&1)) | ~(DV_I_46_0_bit|DV_I_48_0_bit|DV_I_50_0_bit)); - if (mask & (DV_I_45_0_bit|DV_I_47_0_bit|DV_I_49_0_bit)) - mask &= ((0-(((W[46]^W[48])>>29)&1)) | ~(DV_I_45_0_bit|DV_I_47_0_bit|DV_I_49_0_bit)); - mask &= ((((W[45]^W[47])&(1<<6))-(1<<6)) | ~(DV_I_47_2_bit|DV_I_49_2_bit|DV_I_51_2_bit)); - if (mask & (DV_I_44_0_bit|DV_I_46_0_bit|DV_I_48_0_bit)) - mask &= ((0-(((W[45]^W[47])>>29)&1)) | ~(DV_I_44_0_bit|DV_I_46_0_bit|DV_I_48_0_bit)); - mask &= (((((W[44]^W[46])>>6)&1)-1) | ~(DV_I_46_2_bit|DV_I_48_2_bit|DV_I_50_2_bit)); - if (mask & (DV_I_43_0_bit|DV_I_45_0_bit|DV_I_47_0_bit)) - mask &= ((0-(((W[44]^W[46])>>29)&1)) | ~(DV_I_43_0_bit|DV_I_45_0_bit|DV_I_47_0_bit)); - mask &= ((0-((W[41]^(W[42]>>5))&(1<<1))) | ~(DV_I_48_2_bit|DV_II_46_2_bit|DV_II_51_2_bit)); - mask &= ((0-((W[40]^(W[41]>>5))&(1<<1))) | ~(DV_I_47_2_bit|DV_I_51_2_bit|DV_II_50_2_bit)); - if (mask & (DV_I_44_0_bit|DV_I_46_0_bit|DV_II_56_0_bit)) - mask &= ((0-(((W[40]^W[42])>>4)&1)) | ~(DV_I_44_0_bit|DV_I_46_0_bit|DV_II_56_0_bit)); - mask &= ((0-((W[39]^(W[40]>>5))&(1<<1))) | ~(DV_I_46_2_bit|DV_I_50_2_bit|DV_II_49_2_bit)); - if (mask & (DV_I_43_0_bit|DV_I_45_0_bit|DV_II_55_0_bit)) - mask &= ((0-(((W[39]^W[41])>>4)&1)) | ~(DV_I_43_0_bit|DV_I_45_0_bit|DV_II_55_0_bit)); - if (mask & (DV_I_44_0_bit|DV_II_54_0_bit|DV_II_56_0_bit)) - mask &= ((0-(((W[38]^W[40])>>4)&1)) | ~(DV_I_44_0_bit|DV_II_54_0_bit|DV_II_56_0_bit)); - if (mask & (DV_I_43_0_bit|DV_II_53_0_bit|DV_II_55_0_bit)) - mask &= ((0-(((W[37]^W[39])>>4)&1)) | ~(DV_I_43_0_bit|DV_II_53_0_bit|DV_II_55_0_bit)); - mask &= ((0-((W[36]^(W[37]>>5))&(1<<1))) | ~(DV_I_47_2_bit|DV_I_50_2_bit|DV_II_46_2_bit)); - if (mask & (DV_I_45_0_bit|DV_I_48_0_bit|DV_II_47_0_bit)) - mask &= (((((W[35]>>4)^(W[39]>>29))&1)-1) | ~(DV_I_45_0_bit|DV_I_48_0_bit|DV_II_47_0_bit)); - if (mask & (DV_I_48_0_bit|DV_II_48_0_bit)) - mask &= ((0-((W[63]^(W[64]>>5))&(1<<0))) | ~(DV_I_48_0_bit|DV_II_48_0_bit)); - if (mask & (DV_I_45_0_bit|DV_II_45_0_bit)) - mask &= ((0-((W[63]^(W[64]>>5))&(1<<1))) | ~(DV_I_45_0_bit|DV_II_45_0_bit)); - if (mask & (DV_I_47_0_bit|DV_II_47_0_bit)) - mask &= ((0-((W[62]^(W[63]>>5))&(1<<0))) | ~(DV_I_47_0_bit|DV_II_47_0_bit)); - if (mask & (DV_I_46_0_bit|DV_II_46_0_bit)) - mask &= ((0-((W[61]^(W[62]>>5))&(1<<0))) | ~(DV_I_46_0_bit|DV_II_46_0_bit)); - mask &= ((0-((W[61]^(W[62]>>5))&(1<<2))) | ~(DV_I_46_2_bit|DV_II_46_2_bit)); - if (mask & (DV_I_45_0_bit|DV_II_45_0_bit)) - mask &= ((0-((W[60]^(W[61]>>5))&(1<<0))) | ~(DV_I_45_0_bit|DV_II_45_0_bit)); - if (mask & (DV_II_51_0_bit|DV_II_54_0_bit)) - mask &= (((((W[58]^W[59])>>29)&1)-1) | ~(DV_II_51_0_bit|DV_II_54_0_bit)); - if (mask & (DV_II_50_0_bit|DV_II_53_0_bit)) - mask &= (((((W[57]^W[58])>>29)&1)-1) | ~(DV_II_50_0_bit|DV_II_53_0_bit)); - if (mask & (DV_II_52_0_bit|DV_II_54_0_bit)) - mask &= ((((W[56]^(W[59]>>25))&(1<<4))-(1<<4)) | ~(DV_II_52_0_bit|DV_II_54_0_bit)); - if (mask & (DV_II_51_0_bit|DV_II_52_0_bit)) - mask &= ((0-(((W[56]^W[59])>>29)&1)) | ~(DV_II_51_0_bit|DV_II_52_0_bit)); - if (mask & (DV_II_49_0_bit|DV_II_52_0_bit)) - mask &= (((((W[56]^W[57])>>29)&1)-1) | ~(DV_II_49_0_bit|DV_II_52_0_bit)); - if (mask & (DV_II_51_0_bit|DV_II_53_0_bit)) - mask &= ((((W[55]^(W[58]>>25))&(1<<4))-(1<<4)) | ~(DV_II_51_0_bit|DV_II_53_0_bit)); - if (mask & (DV_II_50_0_bit|DV_II_52_0_bit)) - mask &= ((((W[54]^(W[57]>>25))&(1<<4))-(1<<4)) | ~(DV_II_50_0_bit|DV_II_52_0_bit)); - if (mask & (DV_II_49_0_bit|DV_II_51_0_bit)) - mask &= ((((W[53]^(W[56]>>25))&(1<<4))-(1<<4)) | ~(DV_II_49_0_bit|DV_II_51_0_bit)); - mask &= ((((W[51]^(W[50]>>5))&(1<<1))-(1<<1)) | ~(DV_I_50_2_bit|DV_II_46_2_bit)); - mask &= ((((W[48]^W[50])&(1<<6))-(1<<6)) | ~(DV_I_50_2_bit|DV_II_46_2_bit)); - if (mask & (DV_I_51_0_bit|DV_I_52_0_bit)) - mask &= ((0-(((W[48]^W[55])>>29)&1)) | ~(DV_I_51_0_bit|DV_I_52_0_bit)); - mask &= ((((W[47]^W[49])&(1<<6))-(1<<6)) | ~(DV_I_49_2_bit|DV_I_51_2_bit)); - mask &= ((((W[48]^(W[47]>>5))&(1<<1))-(1<<1)) | ~(DV_I_47_2_bit|DV_II_51_2_bit)); - mask &= ((((W[46]^W[48])&(1<<6))-(1<<6)) | ~(DV_I_48_2_bit|DV_I_50_2_bit)); - mask &= ((((W[47]^(W[46]>>5))&(1<<1))-(1<<1)) | ~(DV_I_46_2_bit|DV_II_50_2_bit)); - mask &= ((0-((W[44]^(W[45]>>5))&(1<<1))) | ~(DV_I_51_2_bit|DV_II_49_2_bit)); - mask &= ((((W[43]^W[45])&(1<<6))-(1<<6)) | ~(DV_I_47_2_bit|DV_I_49_2_bit)); - mask &= (((((W[42]^W[44])>>6)&1)-1) | ~(DV_I_46_2_bit|DV_I_48_2_bit)); - mask &= ((((W[43]^(W[42]>>5))&(1<<1))-(1<<1)) | ~(DV_II_46_2_bit|DV_II_51_2_bit)); - mask &= ((((W[42]^(W[41]>>5))&(1<<1))-(1<<1)) | ~(DV_I_51_2_bit|DV_II_50_2_bit)); - mask &= ((((W[41]^(W[40]>>5))&(1<<1))-(1<<1)) | ~(DV_I_50_2_bit|DV_II_49_2_bit)); - if (mask & (DV_I_52_0_bit|DV_II_51_0_bit)) - mask &= ((((W[39]^(W[43]>>25))&(1<<4))-(1<<4)) | ~(DV_I_52_0_bit|DV_II_51_0_bit)); - if (mask & (DV_I_51_0_bit|DV_II_50_0_bit)) - mask &= ((((W[38]^(W[42]>>25))&(1<<4))-(1<<4)) | ~(DV_I_51_0_bit|DV_II_50_0_bit)); - if (mask & (DV_I_48_2_bit|DV_I_51_2_bit)) - mask &= ((0-((W[37]^(W[38]>>5))&(1<<1))) | ~(DV_I_48_2_bit|DV_I_51_2_bit)); - if (mask & (DV_I_50_0_bit|DV_II_49_0_bit)) - mask &= ((((W[37]^(W[41]>>25))&(1<<4))-(1<<4)) | ~(DV_I_50_0_bit|DV_II_49_0_bit)); - if (mask & (DV_II_52_0_bit|DV_II_54_0_bit)) - mask &= ((0-((W[36]^W[38])&(1<<4))) | ~(DV_II_52_0_bit|DV_II_54_0_bit)); - mask &= ((0-((W[35]^(W[36]>>5))&(1<<1))) | ~(DV_I_46_2_bit|DV_I_49_2_bit)); - if (mask & (DV_I_51_0_bit|DV_II_47_0_bit)) - mask &= ((((W[35]^(W[39]>>25))&(1<<3))-(1<<3)) | ~(DV_I_51_0_bit|DV_II_47_0_bit)); -if (mask) { - - if (mask & DV_I_43_0_bit) - if ( - !((W[61]^(W[62]>>5)) & (1<<1)) - || !(!((W[59]^(W[63]>>25)) & (1<<5))) - || !((W[58]^(W[63]>>30)) & (1<<0)) - ) mask &= ~DV_I_43_0_bit; - if (mask & DV_I_44_0_bit) - if ( - !((W[62]^(W[63]>>5)) & (1<<1)) - || !(!((W[60]^(W[64]>>25)) & (1<<5))) - || !((W[59]^(W[64]>>30)) & (1<<0)) - ) mask &= ~DV_I_44_0_bit; - if (mask & DV_I_46_2_bit) - mask &= ((~((W[40]^W[42])>>2)) | ~DV_I_46_2_bit); - if (mask & DV_I_47_2_bit) - if ( - !((W[62]^(W[63]>>5)) & (1<<2)) - || !(!((W[41]^W[43]) & (1<<6))) - ) mask &= ~DV_I_47_2_bit; - if (mask & DV_I_48_2_bit) - if ( - !((W[63]^(W[64]>>5)) & (1<<2)) - || !(!((W[48]^(W[49]<<5)) & (1<<6))) - ) mask &= ~DV_I_48_2_bit; - if (mask & DV_I_49_2_bit) - if ( - !(!((W[49]^(W[50]<<5)) & (1<<6))) - || !((W[42]^W[50]) & (1<<1)) - || !(!((W[39]^(W[40]<<5)) & (1<<6))) - || !((W[38]^W[40]) & (1<<1)) - ) mask &= ~DV_I_49_2_bit; - if (mask & DV_I_50_0_bit) - mask &= ((((W[36]^W[37])<<7)) | ~DV_I_50_0_bit); - if (mask & DV_I_50_2_bit) - mask &= ((((W[43]^W[51])<<11)) | ~DV_I_50_2_bit); - if (mask & DV_I_51_0_bit) - mask &= ((((W[37]^W[38])<<9)) | ~DV_I_51_0_bit); - if (mask & DV_I_51_2_bit) - if ( - !(!((W[51]^(W[52]<<5)) & (1<<6))) - || !(!((W[49]^W[51]) & (1<<6))) - || !(!((W[37]^(W[37]>>5)) & (1<<1))) - || !(!((W[35]^(W[39]>>25)) & (1<<5))) - ) mask &= ~DV_I_51_2_bit; - if (mask & DV_I_52_0_bit) - mask &= ((((W[38]^W[39])<<11)) | ~DV_I_52_0_bit); - if (mask & DV_II_46_2_bit) - mask &= ((((W[47]^W[51])<<17)) | ~DV_II_46_2_bit); - if (mask & DV_II_48_0_bit) - if ( - !(!((W[36]^(W[40]>>25)) & (1<<3))) - || !((W[35]^(W[40]<<2)) & (1<<30)) - ) mask &= ~DV_II_48_0_bit; - if (mask & DV_II_49_0_bit) - if ( - !(!((W[37]^(W[41]>>25)) & (1<<3))) - || !((W[36]^(W[41]<<2)) & (1<<30)) - ) mask &= ~DV_II_49_0_bit; - if (mask & DV_II_49_2_bit) - if ( - !(!((W[53]^(W[54]<<5)) & (1<<6))) - || !(!((W[51]^W[53]) & (1<<6))) - || !((W[50]^W[54]) & (1<<1)) - || !(!((W[45]^(W[46]<<5)) & (1<<6))) - || !(!((W[37]^(W[41]>>25)) & (1<<5))) - || !((W[36]^(W[41]>>30)) & (1<<0)) - ) mask &= ~DV_II_49_2_bit; - if (mask & DV_II_50_0_bit) - if ( - !((W[55]^W[58]) & (1<<29)) - || !(!((W[38]^(W[42]>>25)) & (1<<3))) - || !((W[37]^(W[42]<<2)) & (1<<30)) - ) mask &= ~DV_II_50_0_bit; - if (mask & DV_II_50_2_bit) - if ( - !(!((W[54]^(W[55]<<5)) & (1<<6))) - || !(!((W[52]^W[54]) & (1<<6))) - || !((W[51]^W[55]) & (1<<1)) - || !((W[45]^W[47]) & (1<<1)) - || !(!((W[38]^(W[42]>>25)) & (1<<5))) - || !((W[37]^(W[42]>>30)) & (1<<0)) - ) mask &= ~DV_II_50_2_bit; - if (mask & DV_II_51_0_bit) - if ( - !(!((W[39]^(W[43]>>25)) & (1<<3))) - || !((W[38]^(W[43]<<2)) & (1<<30)) - ) mask &= ~DV_II_51_0_bit; - if (mask & DV_II_51_2_bit) - if ( - !(!((W[55]^(W[56]<<5)) & (1<<6))) - || !(!((W[53]^W[55]) & (1<<6))) - || !((W[52]^W[56]) & (1<<1)) - || !((W[46]^W[48]) & (1<<1)) - || !(!((W[39]^(W[43]>>25)) & (1<<5))) - || !((W[38]^(W[43]>>30)) & (1<<0)) - ) mask &= ~DV_II_51_2_bit; - if (mask & DV_II_52_0_bit) - if ( - !(!((W[59]^W[60]) & (1<<29))) - || !(!((W[40]^(W[44]>>25)) & (1<<3))) - || !(!((W[40]^(W[44]>>25)) & (1<<4))) - || !((W[39]^(W[44]<<2)) & (1<<30)) - ) mask &= ~DV_II_52_0_bit; - if (mask & DV_II_53_0_bit) - if ( - !((W[58]^W[61]) & (1<<29)) - || !(!((W[57]^(W[61]>>25)) & (1<<4))) - || !(!((W[41]^(W[45]>>25)) & (1<<3))) - || !(!((W[41]^(W[45]>>25)) & (1<<4))) - ) mask &= ~DV_II_53_0_bit; - if (mask & DV_II_54_0_bit) - if ( - !(!((W[58]^(W[62]>>25)) & (1<<4))) - || !(!((W[42]^(W[46]>>25)) & (1<<3))) - || !(!((W[42]^(W[46]>>25)) & (1<<4))) - ) mask &= ~DV_II_54_0_bit; - if (mask & DV_II_55_0_bit) - if ( - !(!((W[59]^(W[63]>>25)) & (1<<4))) - || !(!((W[57]^(W[59]>>25)) & (1<<4))) - || !(!((W[43]^(W[47]>>25)) & (1<<3))) - || !(!((W[43]^(W[47]>>25)) & (1<<4))) - ) mask &= ~DV_II_55_0_bit; - if (mask & DV_II_56_0_bit) - if ( - !(!((W[60]^(W[64]>>25)) & (1<<4))) - || !(!((W[44]^(W[48]>>25)) & (1<<3))) - || !(!((W[44]^(W[48]>>25)) & (1<<4))) - ) mask &= ~DV_II_56_0_bit; -} - - dvmask[0]=mask; -} - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_C -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_C -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/ubc_check.h b/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/ubc_check.h deleted file mode 100644 index d7e17dc..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/sha1dc/ubc_check.h +++ /dev/null @@ -1,52 +0,0 @@ -/*** -* Copyright 2017 Marc Stevens , Dan Shumow -* Distributed under the MIT Software License. -* See accompanying file LICENSE.txt or copy at -* https://opensource.org/licenses/MIT -***/ - -/* -// this file was generated by the 'parse_bitrel' program in the tools section -// using the data files from directory 'tools/data/3565' -// -// sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check -// dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) -// dm[80] is the expanded message block XOR-difference defined by the DV -// testt is the step to do the recompression from for collision detection -// maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check -// -// ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs -// it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met -// thus one needs to do the recompression check for each DV that has its bit set -*/ - -#ifndef SHA1DC_UBC_CHECK_H -#define SHA1DC_UBC_CHECK_H - -#if defined(__cplusplus) -extern "C" { -#endif - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif - -#define DVMASKSIZE 1 -typedef struct { int dvType; int dvK; int dvB; int testt; int maski; int maskb; uint32_t dm[80]; } dv_info_t; -extern dv_info_t sha1_dvs[]; -void ubc_check(const uint32_t W[80], uint32_t dvmask[DVMASKSIZE]); - -#define DOSTORESTATE58 -#define DOSTORESTATE65 - -#define CHECK_DVMASK(_DVMASK) (0 != _DVMASK[0]) - -#if defined(__cplusplus) -} -#endif - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_H -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_H -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/win32.c b/vendor/libgit2-sys/libgit2/src/util/hash/win32.c deleted file mode 100644 index f80c0d5..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/win32.c +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "win32.h" - -#include "runtime.h" - -#include -#include - -#define GIT_HASH_CNG_DLL_NAME "bcrypt.dll" - -/* BCRYPT_SHA1_ALGORITHM */ -#define GIT_HASH_CNG_SHA1_TYPE L"SHA1" -#define GIT_HASH_CNG_SHA256_TYPE L"SHA256" - -/* BCRYPT_OBJECT_LENGTH */ -#define GIT_HASH_CNG_HASH_OBJECT_LEN L"ObjectLength" - -/* BCRYPT_HASH_REUSEABLE_FLAGS */ -#define GIT_HASH_CNG_HASH_REUSABLE 0x00000020 - -/* Definitions */ - -/* CryptoAPI is available for hashing on Windows XP and newer. */ -struct cryptoapi_provider { - HCRYPTPROV handle; -}; - -/* - * CNG (bcrypt.dll) is significantly more performant than CryptoAPI and is - * preferred, however it is only available on Windows 2008 and newer and - * must therefore be dynamically loaded, and we must inline constants that - * would not exist when building in pre-Windows 2008 environments. - */ - -/* Function declarations for CNG */ -typedef NTSTATUS (WINAPI *cng_open_algorithm_provider_fn)( - HANDLE /* BCRYPT_ALG_HANDLE */ *phAlgorithm, - LPCWSTR pszAlgId, - LPCWSTR pszImplementation, - DWORD dwFlags); - -typedef NTSTATUS (WINAPI *cng_get_property_fn)( - HANDLE /* BCRYPT_HANDLE */ hObject, - LPCWSTR pszProperty, - PUCHAR pbOutput, - ULONG cbOutput, - ULONG *pcbResult, - ULONG dwFlags); - -typedef NTSTATUS (WINAPI *cng_create_hash_fn)( - HANDLE /* BCRYPT_ALG_HANDLE */ hAlgorithm, - HANDLE /* BCRYPT_HASH_HANDLE */ *phHash, - PUCHAR pbHashObject, ULONG cbHashObject, - PUCHAR pbSecret, - ULONG cbSecret, - ULONG dwFlags); - -typedef NTSTATUS (WINAPI *cng_finish_hash_fn)( - HANDLE /* BCRYPT_HASH_HANDLE */ hHash, - PUCHAR pbOutput, - ULONG cbOutput, - ULONG dwFlags); - -typedef NTSTATUS (WINAPI *cng_hash_data_fn)( - HANDLE /* BCRYPT_HASH_HANDLE */ hHash, - PUCHAR pbInput, - ULONG cbInput, - ULONG dwFlags); - -typedef NTSTATUS (WINAPI *cng_destroy_hash_fn)( - HANDLE /* BCRYPT_HASH_HANDLE */ hHash); - -typedef NTSTATUS (WINAPI *cng_close_algorithm_provider_fn)( - HANDLE /* BCRYPT_ALG_HANDLE */ hAlgorithm, - ULONG dwFlags); - -struct cng_provider { - /* DLL for CNG */ - HINSTANCE dll; - - /* Function pointers for CNG */ - cng_open_algorithm_provider_fn open_algorithm_provider; - cng_get_property_fn get_property; - cng_create_hash_fn create_hash; - cng_finish_hash_fn finish_hash; - cng_hash_data_fn hash_data; - cng_destroy_hash_fn destroy_hash; - cng_close_algorithm_provider_fn close_algorithm_provider; - - HANDLE /* BCRYPT_ALG_HANDLE */ sha1_handle; - DWORD sha1_object_size; - - HANDLE /* BCRYPT_ALG_HANDLE */ sha256_handle; - DWORD sha256_object_size; -}; - -typedef struct { - git_hash_win32_provider_t type; - - union { - struct cryptoapi_provider cryptoapi; - struct cng_provider cng; - } provider; -} hash_win32_provider; - -/* Hash provider definition */ - -static hash_win32_provider hash_provider = {0}; - -/* Hash initialization */ - -/* Initialize CNG, if available */ -GIT_INLINE(int) cng_provider_init(void) -{ - char dll_path[MAX_PATH]; - DWORD dll_path_len, size_len; - - /* Only use CNG on Windows 2008 / Vista SP1 or better (Windows 6.0 SP1) */ - if (!git_has_win32_version(6, 0, 1)) { - git_error_set(GIT_ERROR_SHA, "CryptoNG is not supported on this platform"); - return -1; - } - - /* Load bcrypt.dll explicitly from the system directory */ - if ((dll_path_len = GetSystemDirectory(dll_path, MAX_PATH)) == 0 || - dll_path_len > MAX_PATH || - StringCchCat(dll_path, MAX_PATH, "\\") < 0 || - StringCchCat(dll_path, MAX_PATH, GIT_HASH_CNG_DLL_NAME) < 0 || - (hash_provider.provider.cng.dll = LoadLibrary(dll_path)) == NULL) { - git_error_set(GIT_ERROR_SHA, "CryptoNG library could not be loaded"); - return -1; - } - - /* Load the function addresses */ - if ((hash_provider.provider.cng.open_algorithm_provider = (cng_open_algorithm_provider_fn)((void *)GetProcAddress(hash_provider.provider.cng.dll, "BCryptOpenAlgorithmProvider"))) == NULL || - (hash_provider.provider.cng.get_property = (cng_get_property_fn)((void *)GetProcAddress(hash_provider.provider.cng.dll, "BCryptGetProperty"))) == NULL || - (hash_provider.provider.cng.create_hash = (cng_create_hash_fn)((void *)GetProcAddress(hash_provider.provider.cng.dll, "BCryptCreateHash"))) == NULL || - (hash_provider.provider.cng.finish_hash = (cng_finish_hash_fn)((void *)GetProcAddress(hash_provider.provider.cng.dll, "BCryptFinishHash"))) == NULL || - (hash_provider.provider.cng.hash_data = (cng_hash_data_fn)((void *)GetProcAddress(hash_provider.provider.cng.dll, "BCryptHashData"))) == NULL || - (hash_provider.provider.cng.destroy_hash = (cng_destroy_hash_fn)((void *)GetProcAddress(hash_provider.provider.cng.dll, "BCryptDestroyHash"))) == NULL || - (hash_provider.provider.cng.close_algorithm_provider = (cng_close_algorithm_provider_fn)((void *)GetProcAddress(hash_provider.provider.cng.dll, "BCryptCloseAlgorithmProvider"))) == NULL) { - FreeLibrary(hash_provider.provider.cng.dll); - - git_error_set(GIT_ERROR_OS, "CryptoNG functions could not be loaded"); - return -1; - } - - /* Load the SHA1 algorithm */ - if (hash_provider.provider.cng.open_algorithm_provider(&hash_provider.provider.cng.sha1_handle, GIT_HASH_CNG_SHA1_TYPE, NULL, GIT_HASH_CNG_HASH_REUSABLE) < 0 || - hash_provider.provider.cng.get_property(hash_provider.provider.cng.sha1_handle, GIT_HASH_CNG_HASH_OBJECT_LEN, (PBYTE)&hash_provider.provider.cng.sha1_object_size, sizeof(DWORD), &size_len, 0) < 0) { - git_error_set(GIT_ERROR_OS, "algorithm provider could not be initialized"); - goto on_error; - } - - /* Load the SHA256 algorithm */ - if (hash_provider.provider.cng.open_algorithm_provider(&hash_provider.provider.cng.sha256_handle, GIT_HASH_CNG_SHA256_TYPE, NULL, GIT_HASH_CNG_HASH_REUSABLE) < 0 || - hash_provider.provider.cng.get_property(hash_provider.provider.cng.sha256_handle, GIT_HASH_CNG_HASH_OBJECT_LEN, (PBYTE)&hash_provider.provider.cng.sha256_object_size, sizeof(DWORD), &size_len, 0) < 0) { - git_error_set(GIT_ERROR_OS, "algorithm provider could not be initialized"); - goto on_error; - } - - hash_provider.type = GIT_HASH_WIN32_CNG; - return 0; - -on_error: - if (hash_provider.provider.cng.sha1_handle) - hash_provider.provider.cng.close_algorithm_provider(hash_provider.provider.cng.sha1_handle, 0); - - if (hash_provider.provider.cng.sha256_handle) - hash_provider.provider.cng.close_algorithm_provider(hash_provider.provider.cng.sha256_handle, 0); - - if (hash_provider.provider.cng.dll) - FreeLibrary(hash_provider.provider.cng.dll); - - return -1; -} - -GIT_INLINE(void) cng_provider_shutdown(void) -{ - if (hash_provider.type == GIT_HASH_WIN32_INVALID) - return; - - hash_provider.provider.cng.close_algorithm_provider(hash_provider.provider.cng.sha1_handle, 0); - hash_provider.provider.cng.close_algorithm_provider(hash_provider.provider.cng.sha256_handle, 0); - FreeLibrary(hash_provider.provider.cng.dll); - - hash_provider.type = GIT_HASH_WIN32_INVALID; -} - -/* Initialize CryptoAPI */ -GIT_INLINE(int) cryptoapi_provider_init(void) -{ - if (!CryptAcquireContext(&hash_provider.provider.cryptoapi.handle, NULL, 0, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) { - git_error_set(GIT_ERROR_OS, "legacy hash context could not be started"); - return -1; - } - - hash_provider.type = GIT_HASH_WIN32_CRYPTOAPI; - return 0; -} - -GIT_INLINE(void) cryptoapi_provider_shutdown(void) -{ - if (hash_provider.type == GIT_HASH_WIN32_INVALID) - return; - - CryptReleaseContext(hash_provider.provider.cryptoapi.handle, 0); - - hash_provider.type = GIT_HASH_WIN32_INVALID; -} - -static void hash_provider_shutdown(void) -{ - if (hash_provider.type == GIT_HASH_WIN32_CNG) - cng_provider_shutdown(); - else if (hash_provider.type == GIT_HASH_WIN32_CRYPTOAPI) - cryptoapi_provider_shutdown(); -} - -static int hash_provider_init(void) -{ - int error = 0; - - if (hash_provider.type != GIT_HASH_WIN32_INVALID) - return 0; - - if ((error = cng_provider_init()) < 0) - error = cryptoapi_provider_init(); - - if (!error) - error = git_runtime_shutdown_register(hash_provider_shutdown); - - return error; -} - -git_hash_win32_provider_t git_hash_win32_provider(void) -{ - return hash_provider.type; -} - -int git_hash_win32_set_provider(git_hash_win32_provider_t provider) -{ - if (provider == hash_provider.type) - return 0; - - hash_provider_shutdown(); - - if (provider == GIT_HASH_WIN32_CNG) - return cng_provider_init(); - else if (provider == GIT_HASH_WIN32_CRYPTOAPI) - return cryptoapi_provider_init(); - - git_error_set(GIT_ERROR_SHA, "unsupported win32 provider"); - return -1; -} - -/* CryptoAPI: available in Windows XP and newer */ - -GIT_INLINE(int) hash_cryptoapi_init(git_hash_win32_ctx *ctx) -{ - if (ctx->ctx.cryptoapi.valid) - CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle); - - if (!CryptCreateHash(hash_provider.provider.cryptoapi.handle, ctx->algorithm, 0, 0, &ctx->ctx.cryptoapi.hash_handle)) { - ctx->ctx.cryptoapi.valid = 0; - git_error_set(GIT_ERROR_OS, "legacy hash implementation could not be created"); - return -1; - } - - ctx->ctx.cryptoapi.valid = 1; - return 0; -} - -GIT_INLINE(int) hash_cryptoapi_update(git_hash_win32_ctx *ctx, const void *_data, size_t len) -{ - const BYTE *data = (BYTE *)_data; - - GIT_ASSERT(ctx->ctx.cryptoapi.valid); - - while (len > 0) { - DWORD chunk = (len > MAXDWORD) ? MAXDWORD : (DWORD)len; - - if (!CryptHashData(ctx->ctx.cryptoapi.hash_handle, data, chunk, 0)) { - git_error_set(GIT_ERROR_OS, "legacy hash data could not be updated"); - return -1; - } - - data += chunk; - len -= chunk; - } - - return 0; -} - -GIT_INLINE(int) hash_cryptoapi_final(unsigned char *out, git_hash_win32_ctx *ctx) -{ - DWORD len = ctx->algorithm == CALG_SHA_256 ? GIT_HASH_SHA256_SIZE : GIT_HASH_SHA1_SIZE; - int error = 0; - - GIT_ASSERT(ctx->ctx.cryptoapi.valid); - - if (!CryptGetHashParam(ctx->ctx.cryptoapi.hash_handle, HP_HASHVAL, out, &len, 0)) { - git_error_set(GIT_ERROR_OS, "legacy hash data could not be finished"); - error = -1; - } - - CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle); - ctx->ctx.cryptoapi.valid = 0; - - return error; -} - -GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_win32_ctx *ctx) -{ - if (ctx->ctx.cryptoapi.valid) - CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle); -} - -GIT_INLINE(int) hash_sha1_cryptoapi_ctx_init_init(git_hash_win32_ctx *ctx) -{ - ctx->algorithm = CALG_SHA1; - return hash_cryptoapi_init(ctx); -} - -GIT_INLINE(int) hash_sha256_cryptoapi_ctx_init(git_hash_win32_ctx *ctx) -{ - ctx->algorithm = CALG_SHA_256; - return hash_cryptoapi_init(ctx); -} - -/* CNG: Available in Windows Server 2008 and newer */ - -GIT_INLINE(int) hash_sha1_cng_ctx_init(git_hash_win32_ctx *ctx) -{ - if ((ctx->ctx.cng.hash_object = git__malloc(hash_provider.provider.cng.sha1_object_size)) == NULL) - return -1; - - if (hash_provider.provider.cng.create_hash(hash_provider.provider.cng.sha1_handle, &ctx->ctx.cng.hash_handle, ctx->ctx.cng.hash_object, hash_provider.provider.cng.sha1_object_size, NULL, 0, 0) < 0) { - git__free(ctx->ctx.cng.hash_object); - - git_error_set(GIT_ERROR_OS, "sha1 implementation could not be created"); - return -1; - } - - ctx->algorithm = CALG_SHA1; - return 0; -} - -GIT_INLINE(int) hash_sha256_cng_ctx_init(git_hash_win32_ctx *ctx) -{ - if ((ctx->ctx.cng.hash_object = git__malloc(hash_provider.provider.cng.sha256_object_size)) == NULL) - return -1; - - if (hash_provider.provider.cng.create_hash(hash_provider.provider.cng.sha256_handle, &ctx->ctx.cng.hash_handle, ctx->ctx.cng.hash_object, hash_provider.provider.cng.sha256_object_size, NULL, 0, 0) < 0) { - git__free(ctx->ctx.cng.hash_object); - - git_error_set(GIT_ERROR_OS, "sha256 implementation could not be created"); - return -1; - } - - ctx->algorithm = CALG_SHA_256; - return 0; -} - -GIT_INLINE(int) hash_cng_init(git_hash_win32_ctx *ctx) -{ - BYTE hash[GIT_HASH_SHA256_SIZE]; - ULONG size = ctx->algorithm == CALG_SHA_256 ? GIT_HASH_SHA256_SIZE : GIT_HASH_SHA1_SIZE; - - if (!ctx->ctx.cng.updated) - return 0; - - /* CNG needs to be finished to restart */ - if (hash_provider.provider.cng.finish_hash(ctx->ctx.cng.hash_handle, hash, size, 0) < 0) { - git_error_set(GIT_ERROR_OS, "hash implementation could not be finished"); - return -1; - } - - ctx->ctx.cng.updated = 0; - - return 0; -} - -GIT_INLINE(int) hash_cng_update(git_hash_win32_ctx *ctx, const void *_data, size_t len) -{ - PBYTE data = (PBYTE)_data; - - while (len > 0) { - ULONG chunk = (len > ULONG_MAX) ? ULONG_MAX : (ULONG)len; - - if (hash_provider.provider.cng.hash_data(ctx->ctx.cng.hash_handle, data, chunk, 0) < 0) { - git_error_set(GIT_ERROR_OS, "hash could not be updated"); - return -1; - } - - data += chunk; - len -= chunk; - } - - return 0; -} - -GIT_INLINE(int) hash_cng_final(unsigned char *out, git_hash_win32_ctx *ctx) -{ - ULONG size = ctx->algorithm == CALG_SHA_256 ? GIT_HASH_SHA256_SIZE : GIT_HASH_SHA1_SIZE; - - if (hash_provider.provider.cng.finish_hash(ctx->ctx.cng.hash_handle, out, size, 0) < 0) { - git_error_set(GIT_ERROR_OS, "hash could not be finished"); - return -1; - } - - ctx->ctx.cng.updated = 0; - - return 0; -} - -GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_win32_ctx *ctx) -{ - hash_provider.provider.cng.destroy_hash(ctx->ctx.cng.hash_handle); - git__free(ctx->ctx.cng.hash_object); -} - -/* Indirection between CryptoAPI and CNG */ - -GIT_INLINE(int) hash_sha1_win32_ctx_init(git_hash_win32_ctx *ctx) -{ - GIT_ASSERT_ARG(hash_provider.type); - - memset(ctx, 0x0, sizeof(git_hash_win32_ctx)); - return (hash_provider.type == GIT_HASH_WIN32_CNG) ? hash_sha1_cng_ctx_init(ctx) : hash_sha1_cryptoapi_ctx_init_init(ctx); -} - -GIT_INLINE(int) hash_sha256_win32_ctx_init(git_hash_win32_ctx *ctx) -{ - GIT_ASSERT_ARG(hash_provider.type); - - memset(ctx, 0x0, sizeof(git_hash_win32_ctx)); - return (hash_provider.type == GIT_HASH_WIN32_CNG) ? hash_sha256_cng_ctx_init(ctx) : hash_sha256_cryptoapi_ctx_init(ctx); -} - -GIT_INLINE(int) hash_win32_init(git_hash_win32_ctx *ctx) -{ - return (hash_provider.type == GIT_HASH_WIN32_CNG) ? hash_cng_init(ctx) : hash_cryptoapi_init(ctx); -} - -GIT_INLINE(int) hash_win32_update(git_hash_win32_ctx *ctx, const void *data, size_t len) -{ - return (hash_provider.type == GIT_HASH_WIN32_CNG) ? hash_cng_update(ctx, data, len) : hash_cryptoapi_update(ctx, data, len); -} - -GIT_INLINE(int) hash_win32_final(unsigned char *out, git_hash_win32_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - return (hash_provider.type == GIT_HASH_WIN32_CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx); -} - -GIT_INLINE(void) hash_win32_cleanup(git_hash_win32_ctx *ctx) -{ - if (hash_provider.type == GIT_HASH_WIN32_CNG) - hash_ctx_cng_cleanup(ctx); - else if(hash_provider.type == GIT_HASH_WIN32_CRYPTOAPI) - hash_ctx_cryptoapi_cleanup(ctx); -} - -#ifdef GIT_SHA1_WIN32 - -int git_hash_sha1_global_init(void) -{ - return hash_provider_init(); -} - -int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - return hash_sha1_win32_ctx_init(&ctx->win32); -} - -int git_hash_sha1_init(git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - return hash_win32_init(&ctx->win32); -} - -int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx); - return hash_win32_update(&ctx->win32, data, len); -} - -int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - return hash_win32_final(out, &ctx->win32); -} - -void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) -{ - if (!ctx) - return; - hash_win32_cleanup(&ctx->win32); -} - -#endif - -#ifdef GIT_SHA256_WIN32 - -int git_hash_sha256_global_init(void) -{ - return hash_provider_init(); -} - -int git_hash_sha256_ctx_init(git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - return hash_sha256_win32_ctx_init(&ctx->win32); -} - -int git_hash_sha256_init(git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - return hash_win32_init(&ctx->win32); -} - -int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *data, size_t len) -{ - GIT_ASSERT_ARG(ctx); - return hash_win32_update(&ctx->win32, data, len); -} - -int git_hash_sha256_final(unsigned char *out, git_hash_sha256_ctx *ctx) -{ - GIT_ASSERT_ARG(ctx); - return hash_win32_final(out, &ctx->win32); -} - -void git_hash_sha256_ctx_cleanup(git_hash_sha256_ctx *ctx) -{ - if (!ctx) - return; - hash_win32_cleanup(&ctx->win32); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hash/win32.h b/vendor/libgit2-sys/libgit2/src/util/hash/win32.h deleted file mode 100644 index a9fb87a..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hash/win32.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_hash_win32_h__ -#define INCLUDE_hash_win32_h__ - -#include "hash/sha.h" - -#include - -typedef enum { - GIT_HASH_WIN32_INVALID = 0, - GIT_HASH_WIN32_CRYPTOAPI, - GIT_HASH_WIN32_CNG -} git_hash_win32_provider_t; - -struct git_hash_win32_cryptoapi_ctx { - bool valid; - HCRYPTHASH hash_handle; -}; - -struct git_hash_win32_cng_ctx { - bool updated; - HANDLE /* BCRYPT_HASH_HANDLE */ hash_handle; - PBYTE hash_object; -}; - -typedef struct { - ALG_ID algorithm; - - union { - struct git_hash_win32_cryptoapi_ctx cryptoapi; - struct git_hash_win32_cng_ctx cng; - } ctx; -} git_hash_win32_ctx; - -/* - * Gets/sets the current hash provider (cng or cryptoapi). This is only - * for testing purposes. - */ -git_hash_win32_provider_t git_hash_win32_provider(void); -int git_hash_win32_set_provider(git_hash_win32_provider_t provider); - -#ifdef GIT_SHA1_WIN32 -struct git_hash_sha1_ctx { - git_hash_win32_ctx win32; -}; -#endif - -#ifdef GIT_SHA256_WIN32 -struct git_hash_sha256_ctx { - git_hash_win32_ctx win32; -}; -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hashmap.h b/vendor/libgit2-sys/libgit2/src/util/hashmap.h deleted file mode 100644 index e340527..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hashmap.h +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_hashmap_h__ -#define INCLUDE_hashmap_h__ - -/* - * This is a variation on khash.h from khlib 2013-05-02 (0.2.8) - * - * The MIT License - * - * Copyright (c) 2008, 2009, 2011 by Attractive Chaos - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include - -#define GIT_HASHMAP_INIT {0} -#define GIT_HASHSET_INIT {0} - -#define GIT_HASHMAP_EMPTY -#define GIT_HASHMAP_INLINE GIT_INLINE(GIT_HASHMAP_EMPTY) - -#define GIT_HASHMAP_IS_EMPTY(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2) -#define GIT_HASHMAP_IS_DELETE(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1) -#define GIT_HASHMAP_IS_EITHER(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&3) -#define GIT_HASHMAP_SET_EMPTY_FALSE(flag, i) (flag[i>>4]&=~(2ul<<((i&0xfU)<<1))) -#define GIT_HASHMAP_SET_DELETE_TRUE(flag, i) (flag[i>>4]|=1ul<<((i&0xfU)<<1)) -#define GIT_HASHMAP_SET_DELETE_FALSE(flag, i) (flag[i>>4]&=~(1ul<<((i&0xfU)<<1))) -#define GIT_HASHMAP_SET_BOTH_FALSE(flag, i) (flag[i>>4]&=~(3ul<<((i&0xfU)<<1))) - -#define GIT_HASHMAP_FLAGSIZE(m) ((m) < 16? 1 : (m)>>4) -#define GIT_HASHMAP_ROUNDUP(x) (--(x), (x)|=(x)>>1, \ - (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x)) - -#define GIT_HASHSET_VAL_T void * - -typedef uint32_t git_hashmap_iter_t; -#define GIT_HASHMAP_ITER_INIT 0 - -#define GIT_HASHMAP_STRUCT_MEMBERS(key_t, val_t) \ - uint32_t n_buckets, \ - size, \ - n_occupied, \ - upper_bound; \ - uint32_t *flags; \ - key_t *keys; \ - val_t *vals; - -#define GIT_HASHMAP_STRUCT(name, key_t, val_t) \ - typedef struct { \ - GIT_HASHMAP_STRUCT_MEMBERS(key_t, val_t) \ - } name; -#define GIT_HASHSET_STRUCT(name, key_t) \ - GIT_HASHMAP_STRUCT(name, key_t, void *) - - -#define GIT_HASHMAP__COMMON_PROTOTYPES(name, key_t, val_t) \ - extern uint32_t name##_size(name *h); \ - extern bool name##_contains(name *h, key_t key); \ - extern int name##_remove(name *h, key_t key); \ - extern void name##_clear(name *h); \ - extern void name##_dispose(name *h); - -#define GIT_HASHMAP_PROTOTYPES(name, key_t, val_t) \ - GIT_HASHMAP__COMMON_PROTOTYPES(name, key_t, val_t) \ - extern int name##_get(val_t *out, name *h, key_t key); \ - extern int name##_put(name *h, key_t key, val_t val); \ - extern int name##_iterate(git_hashmap_iter_t *iter, key_t *key, val_t *val, name *h); \ - extern int name##_foreach(name *h, int (*cb)(key_t, val_t)); - -#define GIT_HASHSET_PROTOTYPES(name, key_t) \ - GIT_HASHMAP__COMMON_PROTOTYPES(name, key_t, GIT_HASHSET_VAL_T) \ - extern int name##_add(name *h, key_t key); \ - extern int name##_iterate(git_hashmap_iter_t *iter, key_t *key, name *h); \ - extern int name##_foreach(name *h, int (*cb)(key_t)); \ - - -#define GIT_HASHMAP__COMMON_FUNCTIONS(name, is_map, scope, key_t, val_t, __hash_fn, __equal_fn) \ - GIT_UNUSED_FUNCTION scope uint32_t name##_size(name *h) \ - { \ - return h->size; \ - } \ - GIT_INLINE(int) name##__idx(uint32_t *out, name *h, key_t key) \ - { \ - *out = UINT32_MAX; \ - if (h->n_buckets) { \ - uint32_t k, i, last, mask, step = 0; \ - GIT_ASSERT((h)->flags); \ - mask = h->n_buckets - 1; \ - k = __hash_fn(key); \ - i = k & mask; \ - last = i; \ - while (!GIT_HASHMAP_IS_EMPTY(h->flags, i) && \ - (GIT_HASHMAP_IS_DELETE(h->flags, i) || !__equal_fn(h->keys[i], key))) { \ - i = (i + (++step)) & mask; \ - if (i == last) \ - return GIT_ENOTFOUND; \ - } \ - if (GIT_HASHMAP_IS_EITHER(h->flags, i)) \ - return GIT_ENOTFOUND; \ - *out = i; \ - return 0; \ - } \ - return GIT_ENOTFOUND; \ - } \ - GIT_UNUSED_FUNCTION scope bool name##_contains(name *h, key_t key) \ - { \ - uint32_t idx; \ - return name##__idx(&idx, h, key) == 0; \ - } \ - GIT_INLINE(int) name##__remove_at_idx(name *h, uint32_t idx) \ - { \ - if (idx < h->n_buckets && !GIT_HASHMAP_IS_EITHER(h->flags, idx)) { \ - GIT_HASHMAP_SET_DELETE_TRUE(h->flags, idx); \ - --h->size; \ - return 0; \ - } \ - return GIT_ENOTFOUND; \ - } \ - GIT_UNUSED_FUNCTION scope int name##_remove(name *h, key_t key) \ - { \ - uint32_t idx; \ - int error; \ - if ((error = name##__idx(&idx, h, key)) == 0) \ - error = name##__remove_at_idx(h, idx); \ - return error; \ - } \ - GIT_INLINE(int) name##__resize(name *h, uint32_t new_n_buckets) \ - { \ - /* This function uses 0.25*n_buckets bytes of working \ - * space instead of [sizeof(key_t+val_t)+.25]*n_buckets. \ - */ \ - double git_hashmap__upper_bound = 0.77; \ - uint32_t *new_flags = 0; \ - uint32_t j = 1; \ - { \ - GIT_HASHMAP_ROUNDUP(new_n_buckets); \ - if (new_n_buckets < 4) \ - new_n_buckets = 4; \ - if (h->size >= (uint32_t)(new_n_buckets * git_hashmap__upper_bound + 0.5)) { \ - /* Requested size is too small */ \ - j = 0; \ - } else { \ - /* Shrink or expand; rehash */ \ - new_flags = git__reallocarray(NULL, GIT_HASHMAP_FLAGSIZE(new_n_buckets), sizeof(uint32_t)); \ - if (!new_flags) \ - return -1; \ - memset(new_flags, 0xaa, GIT_HASHMAP_FLAGSIZE(new_n_buckets) * sizeof(uint32_t)); \ - if (h->n_buckets < new_n_buckets) { \ - /* Expand */ \ - key_t *new_keys = git__reallocarray(h->keys, new_n_buckets, sizeof(key_t)); \ - if (!new_keys) { \ - git__free(new_flags); \ - return -1; \ - } \ - h->keys = new_keys; \ - if (is_map) { \ - val_t *new_vals = git__reallocarray(h->vals, new_n_buckets, sizeof(val_t)); \ - if (!new_vals) { \ - git__free(new_flags); \ - return -1; \ - } \ - h->vals = new_vals; \ - } \ - } \ - } \ - } \ - if (j) { \ - /* Rehashing is needed */ \ - for (j = 0; j != h->n_buckets; ++j) { \ - if (GIT_HASHMAP_IS_EITHER(h->flags, j) == 0) { \ - key_t key = h->keys[j]; \ - val_t val; \ - uint32_t new_mask; \ - new_mask = new_n_buckets - 1; \ - if (is_map) \ - val = h->vals[j]; \ - GIT_HASHMAP_SET_DELETE_TRUE(h->flags, j); \ - while (1) { \ - /* Kick-out process; sort of like in Cuckoo hashing */ \ - uint32_t k, i, step = 0; \ - k = __hash_fn(key); \ - i = k & new_mask; \ - while (!GIT_HASHMAP_IS_EMPTY(new_flags, i)) \ - i = (i + (++step)) & new_mask; \ - GIT_HASHMAP_SET_EMPTY_FALSE(new_flags, i); \ - if (i < h->n_buckets && GIT_HASHMAP_IS_EITHER(h->flags, i) == 0) { \ - /* Kick out the existing element */ \ - { \ - key_t tmp = h->keys[i]; \ - h->keys[i] = key; \ - key = tmp; \ - } \ - if (is_map) { \ - val_t tmp = h->vals[i]; \ - h->vals[i] = val; \ - val = tmp; \ - } \ - /* Mark it as deleted in the old hash table */ \ - GIT_HASHMAP_SET_DELETE_TRUE(h->flags, i); \ - } else { \ - /* Write the element and jump out of the loop */ \ - h->keys[i] = key; \ - if (is_map) \ - h->vals[i] = val; \ - break; \ - } \ - } \ - } \ - } \ - if (h->n_buckets > new_n_buckets) { \ - /* Shrink the hash table */ \ - h->keys = git__reallocarray(h->keys, new_n_buckets, sizeof(key_t)); \ - if (is_map) \ - h->vals = git__reallocarray(h->vals, new_n_buckets, sizeof(val_t)); \ - } \ - /* free the working space */ \ - git__free(h->flags); \ - h->flags = new_flags; \ - h->n_buckets = new_n_buckets; \ - h->n_occupied = h->size; \ - h->upper_bound = (uint32_t)(h->n_buckets * git_hashmap__upper_bound + 0.5); \ - } \ - return 0; \ - } \ - GIT_INLINE(int) name##__put_idx(uint32_t *idx, bool *key_exists, name *h, key_t key) \ - { \ - uint32_t x; \ - if (h->n_occupied >= h->upper_bound) { \ - /* Update the hash table */ \ - if (h->n_buckets > (h->size<<1)) { \ - /* Clear "deleted" elements */ \ - if (name##__resize(h, h->n_buckets - 1) < 0) \ - return -1; \ - } else if (name##__resize(h, h->n_buckets + 1) < 0) { \ - return -1; \ - } \ - } \ - GIT_ASSERT((h)->flags); \ - GIT_ASSERT((h)->keys); \ - /* TODO: to implement automatically shrinking; resize() already support shrinking */ \ - { \ - uint32_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \ - x = site = h->n_buckets; \ - k = __hash_fn(key); \ - i = k & mask; \ - if (GIT_HASHMAP_IS_EMPTY(h->flags, i)) { \ - /* for speed up */ \ - x = i; \ - } else { \ - last = i; \ - while (!GIT_HASHMAP_IS_EMPTY(h->flags, i) && (GIT_HASHMAP_IS_DELETE(h->flags, i) || !__equal_fn(h->keys[i], key))) { \ - if (GIT_HASHMAP_IS_DELETE(h->flags, i)) \ - site = i; \ - i = (i + (++step)) & mask; \ - if (i == last) { \ - x = site; \ - break; \ - } \ - } \ - if (x == h->n_buckets) { \ - if (GIT_HASHMAP_IS_EMPTY(h->flags, i) && site != h->n_buckets) \ - x = site; \ - else \ - x = i; \ - } \ - } \ - } \ - if (GIT_HASHMAP_IS_EMPTY(h->flags, x)) { \ - /* not present at all */ \ - h->keys[x] = key; \ - GIT_HASHMAP_SET_BOTH_FALSE(h->flags, x); \ - ++h->size; \ - ++h->n_occupied; \ - *key_exists = 1; \ - } else if (GIT_HASHMAP_IS_DELETE(h->flags, x)) { \ - /* deleted */ \ - h->keys[x] = key; \ - GIT_HASHMAP_SET_BOTH_FALSE(h->flags, x); \ - ++h->size; \ - *key_exists = 1; \ - } else { \ - /* Don't touch h->keys[x] if present and not deleted */ \ - *key_exists = 0; \ - } \ - *idx = x; \ - return 0; \ - } \ - GIT_UNUSED_FUNCTION scope void name##_clear(name *h) \ - { \ - if (h && h->flags) { \ - memset(h->flags, 0xaa, GIT_HASHMAP_FLAGSIZE(h->n_buckets) * sizeof(uint32_t)); \ - h->size = h->n_occupied = 0; \ - } \ - } \ - GIT_UNUSED_FUNCTION scope void name##_dispose(name *h) \ - { \ - git__free(h->flags); \ - git__free(h->keys); \ - git__free(h->vals); \ - memset(h, 0, sizeof(name)); \ - } - -#define GIT_HASHMAP_FUNCTIONS(name, scope, key_t, val_t, __hash_fn, __equal_fn) \ - GIT_HASHMAP__COMMON_FUNCTIONS(name, true, scope, key_t, val_t, __hash_fn, __equal_fn) \ - \ - GIT_UNUSED_FUNCTION scope int name##_get(val_t *out, name *h, key_t key) \ - { \ - uint32_t idx; \ - int error; \ - if ((error = name##__idx(&idx, h, key)) == 0) \ - *out = (h)->vals[idx]; \ - return error; \ - } \ - GIT_UNUSED_FUNCTION scope int name##_put(name *h, key_t key, val_t val) \ - { \ - uint32_t idx; \ - bool key_exists; \ - int error = name##__put_idx(&idx, &key_exists, h, key); \ - if (error) \ - return error; \ - GIT_ASSERT((h)->vals); \ - if (!key_exists) \ - (h)->keys[idx] = key; \ - (h)->vals[idx] = val; \ - return 0; \ - } \ - GIT_UNUSED_FUNCTION scope int name##_iterate(git_hashmap_iter_t *iter, key_t *key, val_t *val, name *h) \ - { \ - for (; *iter < h->n_buckets; (*iter)++) { \ - if (GIT_HASHMAP_IS_EITHER(h->flags, *iter)) \ - continue; \ - if (key) \ - *key = h->keys[*iter]; \ - if (val) \ - *val = h->vals[*iter]; \ - (*iter)++; \ - return 0; \ - } \ - return GIT_ITEROVER; \ - } \ - GIT_UNUSED_FUNCTION scope int name##_foreach(name *h, int (*cb)(key_t, val_t)) \ - { \ - uint32_t idx = 0; \ - key_t key; \ - val_t val; \ - int ret; \ - while ((ret = name##_iterate(&idx, &key, &val, h)) == 0) { \ - if ((ret = cb(key, val)) != 0) \ - return ret; \ - } \ - return ret == GIT_ITEROVER ? 0 : ret; \ - } - -#define GIT_HASHSET_FUNCTIONS(name, scope, key_t, __hash_fn, __equal_fn) \ - GIT_HASHMAP__COMMON_FUNCTIONS(name, false, scope, key_t, void *, __hash_fn, __equal_fn) \ - \ - GIT_UNUSED_FUNCTION scope int name##_add(name *h, key_t key) \ - { \ - uint32_t idx; \ - bool key_exists; \ - int error = name##__put_idx(&idx, &key_exists, h, key); \ - if (error) \ - return error; \ - if (!key_exists) { \ - (h)->keys[idx] = key; \ - } \ - return 0; \ - } \ - GIT_UNUSED_FUNCTION scope int name##_iterate(git_hashmap_iter_t *iter, key_t *key, name *h) \ - { \ - for (; *iter < h->n_buckets; (*iter)++) { \ - if (GIT_HASHMAP_IS_EITHER(h->flags, *iter)) \ - continue; \ - *key = h->keys[*iter]; \ - return 0; \ - } \ - return GIT_ITEROVER; \ - } \ - GIT_UNUSED_FUNCTION scope int name##_foreach(name *h, int (*cb)(key_t)) \ - { \ - git_hashmap_iter_t iter = 0; \ - key_t key; \ - int ret; \ - while ((ret = name##_iterate(&iter, &key, h)) == 0) { \ - if ((ret = cb(key)) != 0) \ - return ret; \ - } \ - return ret == GIT_ITEROVER ? 0 : ret; \ - } - - -#define GIT_HASHSET_SETUP(name, key_t, __hash_fn, __equal_fn) \ - GIT_HASHSET_STRUCT(name, key_t) \ - GIT_HASHSET_FUNCTIONS(name, GIT_HASHMAP_INLINE, key_t, __hash_fn, __equal_fn) -#define GIT_HASHMAP_SETUP(name, key_t, val_t, __hash_fn, __equal_fn) \ - GIT_HASHMAP_STRUCT(name, key_t, val_t) \ - GIT_HASHMAP_FUNCTIONS(name, GIT_HASHMAP_INLINE, key_t, val_t, __hash_fn, __equal_fn) - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/hashmap_str.h b/vendor/libgit2-sys/libgit2/src/util/hashmap_str.h deleted file mode 100644 index 099aac5..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/hashmap_str.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_hashmap_str_h__ -#define INCLUDE_hashmap_str_h__ - -#include "hashmap.h" - -GIT_INLINE(uint32_t) git_hashmap_str_hash(const char *s) -{ - uint32_t h = (uint32_t)*s; - - if (h) { - for (++s; *s; ++s) - h = (h << 5) - h + (uint32_t)*s; - } - - return h; -} - -GIT_INLINE(bool) git_hashmap_str_equal(const char *one, const char *two) -{ - return strcmp(one, two) == 0; -} - -#define GIT_HASHMAP_STR_STRUCT(name, val_t) \ - GIT_HASHMAP_STRUCT(name, const char *, val_t) -#define GIT_HASHMAP_STR_PROTOTYPES(name, val_t) \ - GIT_HASHMAP_PROTOTYPES(name, const char *, val_t) -#define GIT_HASHMAP_STR_FUNCTIONS(name, scope, val_t) \ - GIT_HASHMAP_FUNCTIONS(name, scope, const char *, val_t, git_hashmap_str_hash, git_hashmap_str_equal) - -#define GIT_HASHMAP_STR_SETUP(name, val_t) \ - GIT_HASHMAP_STR_STRUCT(name, val_t) \ - GIT_HASHMAP_STR_FUNCTIONS(name, GIT_HASHMAP_INLINE, val_t) - -GIT_HASHSET_SETUP(git_hashset_str, const char *, git_hashmap_str_hash, git_hashmap_str_equal); -GIT_HASHMAP_SETUP(git_hashmap_str, const char *, void *, git_hashmap_str_hash, git_hashmap_str_equal); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/integer.h b/vendor/libgit2-sys/libgit2/src/util/integer.h deleted file mode 100644 index a9e416c..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/integer.h +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_integer_h__ -#define INCLUDE_integer_h__ - -/** @return true if p fits into the range of a size_t */ -GIT_INLINE(int) git__is_sizet(int64_t p) -{ - size_t r = (size_t)p; - return p == (int64_t)r; -} - -/** @return true if p fits into the range of an ssize_t */ -GIT_INLINE(int) git__is_ssizet(size_t p) -{ - ssize_t r = (ssize_t)p; - return p == (size_t)r; -} - -/** @return true if p fits into the range of a uint16_t */ -GIT_INLINE(int) git__is_uint16(size_t p) -{ - uint16_t r = (uint16_t)p; - return p == (size_t)r; -} - -/** @return true if p fits into the range of a uint32_t */ -GIT_INLINE(int) git__is_uint32(size_t p) -{ - uint32_t r = (uint32_t)p; - return p == (size_t)r; -} - -/** @return true if p fits into the range of an unsigned long */ -GIT_INLINE(int) git__is_ulong(int64_t p) -{ - unsigned long r = (unsigned long)p; - return p == (int64_t)r; -} - -/** @return true if p fits into the range of an int */ -GIT_INLINE(int) git__is_int(int64_t p) -{ - int r = (int)p; - return p == (int64_t)r; -} - -/* Use clang/gcc compiler intrinsics whenever possible */ -#if (__has_builtin(__builtin_add_overflow) || \ - (defined(__GNUC__) && (__GNUC__ >= 5))) - -# if (SIZE_MAX == UINT_MAX) -# define git__add_sizet_overflow(out, one, two) \ - __builtin_uadd_overflow(one, two, out) -# define git__multiply_sizet_overflow(out, one, two) \ - __builtin_umul_overflow(one, two, out) -# elif (SIZE_MAX == ULONG_MAX) -# define git__add_sizet_overflow(out, one, two) \ - __builtin_uaddl_overflow(one, two, out) -# define git__multiply_sizet_overflow(out, one, two) \ - __builtin_umull_overflow(one, two, out) -# elif (SIZE_MAX == ULLONG_MAX) -# define git__add_sizet_overflow(out, one, two) \ - __builtin_uaddll_overflow(one, two, out) -# define git__multiply_sizet_overflow(out, one, two) \ - __builtin_umulll_overflow(one, two, out) -# else -# error compiler has add with overflow intrinsics but SIZE_MAX is unknown -# endif - -# define git__add_int_overflow(out, one, two) \ - __builtin_sadd_overflow(one, two, out) -# define git__sub_int_overflow(out, one, two) \ - __builtin_ssub_overflow(one, two, out) - -# define git__add_int64_overflow(out, one, two) \ - __builtin_add_overflow(one, two, out) - -/* clang on 32-bit systems produces an undefined reference to `__mulodi4`. */ -# if !defined(__clang__) || !defined(GIT_ARCH_32) -# define git__multiply_int64_overflow(out, one, two) \ - __builtin_mul_overflow(one, two, out) -# endif - -/* Use Microsoft's safe integer handling functions where available */ -#elif defined(_MSC_VER) - -# if !defined(ENABLE_INTSAFE_SIGNED_FUNCTIONS) -# define ENABLE_INTSAFE_SIGNED_FUNCTIONS -# endif -# include - -# define git__add_sizet_overflow(out, one, two) \ - (SizeTAdd(one, two, out) != S_OK) -# define git__multiply_sizet_overflow(out, one, two) \ - (SizeTMult(one, two, out) != S_OK) - -#define git__add_int_overflow(out, one, two) \ - (IntAdd(one, two, out) != S_OK) -#define git__sub_int_overflow(out, one, two) \ - (IntSub(one, two, out) != S_OK) - -#define git__add_int64_overflow(out, one, two) \ - (LongLongAdd(one, two, out) != S_OK) -#define git__multiply_int64_overflow(out, one, two) \ - (LongLongMult(one, two, out) != S_OK) - -#else - -/** - * Sets `one + two` into `out`, unless the arithmetic would overflow. - * @return false if the result fits in a `size_t`, true on overflow. - */ -GIT_INLINE(bool) git__add_sizet_overflow(size_t *out, size_t one, size_t two) -{ - if (SIZE_MAX - one < two) - return true; - *out = one + two; - return false; -} - -/** - * Sets `one * two` into `out`, unless the arithmetic would overflow. - * @return false if the result fits in a `size_t`, true on overflow. - */ -GIT_INLINE(bool) git__multiply_sizet_overflow(size_t *out, size_t one, size_t two) -{ - if (one && SIZE_MAX / one < two) - return true; - *out = one * two; - return false; -} - -GIT_INLINE(bool) git__add_int_overflow(int *out, int one, int two) -{ - if ((two > 0 && one > (INT_MAX - two)) || - (two < 0 && one < (INT_MIN - two))) - return true; - *out = one + two; - return false; -} - -GIT_INLINE(bool) git__sub_int_overflow(int *out, int one, int two) -{ - if ((two > 0 && one < (INT_MIN + two)) || - (two < 0 && one > (INT_MAX + two))) - return true; - *out = one - two; - return false; -} - -GIT_INLINE(bool) git__add_int64_overflow(int64_t *out, int64_t one, int64_t two) -{ - if ((two > 0 && one > (INT64_MAX - two)) || - (two < 0 && one < (INT64_MIN - two))) - return true; - *out = one + two; - return false; -} - -#endif - -/* If we could not provide an intrinsic implementation for this, provide a (slow) fallback. */ -#if !defined(git__multiply_int64_overflow) -GIT_INLINE(bool) git__multiply_int64_overflow(int64_t *out, int64_t one, int64_t two) -{ - /* - * Detects whether `INT64_MAX < (one * two) || INT64_MIN > (one * two)`, - * without incurring in undefined behavior. That is done by performing the - * comparison with a division instead of a multiplication, which translates - * to `INT64_MAX / one < two || INT64_MIN / one > two`. Some caveats: - * - * - The comparison sign is inverted when both sides of the inequality are - * multiplied/divided by a negative number, so if `one < 0` the comparison - * needs to be flipped. - * - `INT64_MAX / -1` itself overflows (or traps), so that case should be - * avoided. - * - Since the overflow flag is defined as the discrepance between the result - * of performing the multiplication in a signed integer at twice the width - * of the operands, and the truncated+sign-extended version of that same - * result, there are four cases where the result is the opposite of what - * would be expected: - * * `INT64_MIN * -1` / `-1 * INT64_MIN` - * * `INT64_MIN * 1 / `1 * INT64_MIN` - */ - if (one && two) { - if (one > 0 && two > 0) { - if (INT64_MAX / one < two) - return true; - } else if (one < 0 && two < 0) { - if ((one == -1 && two == INT64_MIN) || - (two == -1 && one == INT64_MIN)) { - *out = INT64_MIN; - return false; - } - if (INT64_MAX / one > two) - return true; - } else if (one > 0 && two < 0) { - if ((one == 1 && two == INT64_MIN) || - (INT64_MIN / one > two)) - return true; - } else if (one == -1) { - if (INT64_MIN / two > one) - return true; - } else { - if ((one == INT64_MIN && two == 1) || - (INT64_MIN / one < two)) - return true; - } - } - *out = one * two; - return false; -} -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/map.h b/vendor/libgit2-sys/libgit2/src/util/map.h deleted file mode 100644 index c101e46..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/map.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_map_h__ -#define INCLUDE_map_h__ - -#include "git2_util.h" - - -/* p_mmap() prot values */ -#define GIT_PROT_NONE 0x0 -#define GIT_PROT_READ 0x1 -#define GIT_PROT_WRITE 0x2 -#define GIT_PROT_EXEC 0x4 - -/* git__mmmap() flags values */ -#define GIT_MAP_FILE 0 -#define GIT_MAP_SHARED 1 -#define GIT_MAP_PRIVATE 2 -#define GIT_MAP_TYPE 0xf -#define GIT_MAP_FIXED 0x10 - -#ifdef __amigaos4__ -#define MAP_FAILED 0 -#endif - -typedef struct { /* memory mapped buffer */ - void *data; /* data bytes */ - size_t len; /* data length */ -#ifdef GIT_WIN32 - HANDLE fmh; /* file mapping handle */ -#endif -} git_map; - -#define GIT_MMAP_VALIDATE(out, len, prot, flags) do { \ - GIT_ASSERT(out != NULL && len > 0); \ - GIT_ASSERT((prot & GIT_PROT_WRITE) || (prot & GIT_PROT_READ)); \ - GIT_ASSERT((flags & GIT_MAP_FIXED) == 0); } while (0) - -extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset); -extern int p_munmap(git_map *map); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/net.c b/vendor/libgit2-sys/libgit2/src/util/net.c deleted file mode 100644 index b55921b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/net.c +++ /dev/null @@ -1,1160 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "net.h" - -#include - -#include "posix.h" -#include "str.h" -#include "runtime.h" - -#define DEFAULT_PORT_HTTP "80" -#define DEFAULT_PORT_HTTPS "443" -#define DEFAULT_PORT_GIT "9418" -#define DEFAULT_PORT_SSH "22" - -#define GIT_NET_URL_PARSER_INIT { 0 } - -typedef struct { - unsigned int hierarchical : 1; - - const char *scheme; - const char *user; - const char *password; - const char *host; - const char *port; - const char *path; - const char *query; - const char *fragment; - - size_t scheme_len; - size_t user_len; - size_t password_len; - size_t host_len; - size_t port_len; - size_t path_len; - size_t query_len; - size_t fragment_len; -} git_net_url_parser; - -bool git_net_hostname_matches_cert( - const char *hostname, - const char *pattern) -{ - for (;;) { - char c = git__tolower(*pattern++); - - if (c == '\0') - return *hostname ? false : true; - - if (c == '*') { - c = *pattern; - - /* '*' at the end matches everything left */ - if (c == '\0') - return true; - - /* - * We've found a pattern, so move towards the - * next matching char. The '.' is handled - * specially because wildcards aren't allowed - * to cross subdomains. - */ - while(*hostname) { - char h = git__tolower(*hostname); - - if (h == c) - return git_net_hostname_matches_cert(hostname++, pattern); - else if (h == '.') - return git_net_hostname_matches_cert(hostname, pattern); - - hostname++; - } - - return false; - } - - if (c != git__tolower(*hostname++)) - return false; - } - - return false; -} - -#define is_valid_scheme_char(c) \ - (((c) >= 'a' && (c) <= 'z') || \ - ((c) >= 'A' && (c) <= 'Z') || \ - ((c) >= '0' && (c) <= '9') || \ - (c) == '+' || (c) == '-' || (c) == '.') - -bool git_net_str_is_url(const char *str) -{ - const char *c; - - for (c = str; *c; c++) { - if (*c == ':' && *(c+1) == '/' && *(c+2) == '/') - return true; - - if (!is_valid_scheme_char(*c)) - break; - } - - return false; -} - -static const char *default_port_for_scheme(const char *scheme) -{ - if (strcmp(scheme, "http") == 0) - return DEFAULT_PORT_HTTP; - else if (strcmp(scheme, "https") == 0) - return DEFAULT_PORT_HTTPS; - else if (strcmp(scheme, "git") == 0) - return DEFAULT_PORT_GIT; - else if (strcmp(scheme, "ssh") == 0 || - strcmp(scheme, "ssh+git") == 0 || - strcmp(scheme, "git+ssh") == 0) - return DEFAULT_PORT_SSH; - - return NULL; -} - -static bool is_ssh_scheme(const char *scheme, size_t scheme_len) -{ - if (!scheme_len) - return false; - - return strncasecmp(scheme, "ssh", scheme_len) == 0 || - strncasecmp(scheme, "ssh+git", scheme_len) == 0 || - strncasecmp(scheme, "git+ssh", scheme_len) == 0; -} - -int git_net_url_dup(git_net_url *out, git_net_url *in) -{ - if (in->scheme) { - out->scheme = git__strdup(in->scheme); - GIT_ERROR_CHECK_ALLOC(out->scheme); - } - - if (in->host) { - out->host = git__strdup(in->host); - GIT_ERROR_CHECK_ALLOC(out->host); - } - - if (in->port) { - out->port = git__strdup(in->port); - GIT_ERROR_CHECK_ALLOC(out->port); - } - - if (in->path) { - out->path = git__strdup(in->path); - GIT_ERROR_CHECK_ALLOC(out->path); - } - - if (in->query) { - out->query = git__strdup(in->query); - GIT_ERROR_CHECK_ALLOC(out->query); - } - - if (in->username) { - out->username = git__strdup(in->username); - GIT_ERROR_CHECK_ALLOC(out->username); - } - - if (in->password) { - out->password = git__strdup(in->password); - GIT_ERROR_CHECK_ALLOC(out->password); - } - - return 0; -} - -static int url_invalid(const char *message) -{ - git_error_set(GIT_ERROR_NET, "invalid url: %s", message); - return GIT_EINVALIDSPEC; -} - -static int url_parse_authority( - git_net_url_parser *parser, - const char *authority, - size_t len) -{ - const char *c, *hostport_end = NULL, *host_end = NULL, - *userpass_end = NULL, *user_end = NULL; - - enum { - HOSTPORT, HOST, IPV6, HOST_END, USERPASS, USER - } state = HOSTPORT; - - if (len == 0) - return 0; - - /* - * walk the authority backwards so that we can parse google code's - * ssh urls that are not rfc compliant and allow @ in the username - */ - for (hostport_end = authority + len, c = hostport_end - 1; - c >= authority && !user_end; - c--) { - switch (state) { - case HOSTPORT: - if (*c == ':') { - parser->port = c + 1; - parser->port_len = hostport_end - parser->port; - host_end = c; - state = HOST; - break; - } - - /* - * if we've only seen digits then we don't know - * if we're parsing just a host or a host and port. - * if we see a non-digit, then we're in a host, - * otherwise, fall through to possibly match the - * "@" (user/host separator). - */ - - if (*c < '0' || *c > '9') { - host_end = hostport_end; - state = HOST; - } - - /* fall through */ - - case HOST: - if (*c == ']' && host_end == c + 1) { - host_end = c; - state = IPV6; - } - - else if (*c == '@') { - parser->host = c + 1; - parser->host_len = host_end ? - host_end - parser->host : - hostport_end - parser->host; - userpass_end = c; - state = USERPASS; - } - - else if (*c == '[' || *c == ']' || *c == ':') { - return url_invalid("malformed hostname"); - } - - break; - - case IPV6: - if (*c == '[') { - parser->host = c + 1; - parser->host_len = host_end - parser->host; - state = HOST_END; - } - - else if ((*c < '0' || *c > '9') && - (*c < 'a' || *c > 'f') && - (*c < 'A' || *c > 'F') && - (*c != ':')) { - return url_invalid("malformed hostname"); - } - - break; - - case HOST_END: - if (*c == '@') { - userpass_end = c; - state = USERPASS; - break; - } - - return url_invalid("malformed hostname"); - - case USERPASS: - if (*c == '@' && - !is_ssh_scheme(parser->scheme, parser->scheme_len)) - return url_invalid("malformed hostname"); - - if (*c == ':') { - parser->password = c + 1; - parser->password_len = userpass_end - parser->password; - user_end = c; - state = USER; - break; - } - - break; - - default: - GIT_ASSERT(!"unhandled state"); - } - } - - switch (state) { - case HOSTPORT: - parser->host = authority; - parser->host_len = (hostport_end - parser->host); - break; - case HOST: - parser->host = authority; - parser->host_len = (host_end - parser->host); - break; - case IPV6: - return url_invalid("malformed hostname"); - case HOST_END: - break; - case USERPASS: - parser->user = authority; - parser->user_len = (userpass_end - parser->user); - break; - case USER: - parser->user = authority; - parser->user_len = (user_end - parser->user); - break; - default: - GIT_ASSERT(!"unhandled state"); - } - - return 0; -} - -static int url_parse_path( - git_net_url_parser *parser, - const char *path, - size_t len) -{ - const char *c, *end; - - enum { PATH, QUERY, FRAGMENT } state = PATH; - - parser->path = path; - end = path + len; - - for (c = path; c < end; c++) { - switch (state) { - case PATH: - switch (*c) { - case '?': - parser->path_len = (c - parser->path); - parser->query = c + 1; - state = QUERY; - break; - case '#': - parser->path_len = (c - parser->path); - parser->fragment = c + 1; - state = FRAGMENT; - break; - } - break; - - case QUERY: - if (*c == '#') { - parser->query_len = (c - parser->query); - parser->fragment = c + 1; - state = FRAGMENT; - } - break; - - case FRAGMENT: - break; - - default: - GIT_ASSERT(!"unhandled state"); - } - } - - switch (state) { - case PATH: - parser->path_len = (c - parser->path); - break; - case QUERY: - parser->query_len = (c - parser->query); - break; - case FRAGMENT: - parser->fragment_len = (c - parser->fragment); - break; - } - - return 0; -} - -static int url_parse_finalize(git_net_url *url, git_net_url_parser *parser) -{ - git_str scheme = GIT_STR_INIT, user = GIT_STR_INIT, - password = GIT_STR_INIT, host = GIT_STR_INIT, - port = GIT_STR_INIT, path = GIT_STR_INIT, - query = GIT_STR_INIT, fragment = GIT_STR_INIT; - const char *default_port; - int port_specified = 0; - int error = 0; - - if (parser->scheme_len) { - if ((error = git_str_put(&scheme, parser->scheme, parser->scheme_len)) < 0) - goto done; - - git__strntolower(scheme.ptr, scheme.size); - } - - if (parser->user_len && - (error = git_str_decode_percent(&user, parser->user, parser->user_len)) < 0) - goto done; - - if (parser->password_len && - (error = git_str_decode_percent(&password, parser->password, parser->password_len)) < 0) - goto done; - - if (parser->host_len && - (error = git_str_decode_percent(&host, parser->host, parser->host_len)) < 0) - goto done; - - if (parser->port_len) { - port_specified = 1; - error = git_str_put(&port, parser->port, parser->port_len); - } else if (parser->scheme_len && - (default_port = default_port_for_scheme(scheme.ptr)) != NULL) { - error = git_str_puts(&port, default_port); - } - - if (error < 0) - goto done; - - if (parser->path_len) - error = git_str_put(&path, parser->path, parser->path_len); - else if (parser->hierarchical) - error = git_str_puts(&path, "/"); - - if (error < 0) - goto done; - - if (parser->query_len && - (error = git_str_decode_percent(&query, parser->query, parser->query_len)) < 0) - goto done; - - if (parser->fragment_len && - (error = git_str_decode_percent(&fragment, parser->fragment, parser->fragment_len)) < 0) - goto done; - - url->scheme = git_str_detach(&scheme); - url->host = git_str_detach(&host); - url->port = git_str_detach(&port); - url->path = git_str_detach(&path); - url->query = git_str_detach(&query); - url->fragment = git_str_detach(&fragment); - url->username = git_str_detach(&user); - url->password = git_str_detach(&password); - url->port_specified = port_specified; - - error = 0; - -done: - git_str_dispose(&scheme); - git_str_dispose(&user); - git_str_dispose(&password); - git_str_dispose(&host); - git_str_dispose(&port); - git_str_dispose(&path); - git_str_dispose(&query); - git_str_dispose(&fragment); - - return error; -} - -int git_net_url_parse(git_net_url *url, const char *given) -{ - git_net_url_parser parser = GIT_NET_URL_PARSER_INIT; - const char *c, *authority = NULL, *path = NULL; - size_t authority_len = 0, path_len = 0; - int error = 0; - - enum { - SCHEME_START, SCHEME, - AUTHORITY_START, AUTHORITY, - PATH_START, PATH - } state = SCHEME_START; - - memset(url, 0, sizeof(git_net_url)); - - for (c = given; *c; c++) { - switch (state) { - case SCHEME_START: - parser.scheme = c; - state = SCHEME; - - /* fall through */ - - case SCHEME: - if (*c == ':') { - parser.scheme_len = (c - parser.scheme); - - if (parser.scheme_len && - *(c+1) == '/' && *(c+2) == '/') { - c += 2; - parser.hierarchical = 1; - state = AUTHORITY_START; - } else { - state = PATH_START; - } - } else if (!is_valid_scheme_char(*c)) { - /* - * an illegal scheme character means that we - * were just given a relative path - */ - path = given; - state = PATH; - break; - } - break; - - case AUTHORITY_START: - authority = c; - state = AUTHORITY; - - /* fall through */ - case AUTHORITY: - if (*c != '/') - break; - - authority_len = (c - authority); - - /* fall through */ - case PATH_START: - path = c; - state = PATH; - break; - - case PATH: - break; - - default: - GIT_ASSERT(!"unhandled state"); - } - } - - switch (state) { - case SCHEME: - /* - * if we never saw a ':' then we were given a relative - * path, not a bare scheme - */ - path = given; - path_len = (c - path); - break; - case AUTHORITY_START: - break; - case AUTHORITY: - authority_len = (c - authority); - break; - case PATH_START: - break; - case PATH: - path_len = (c - path); - break; - default: - GIT_ASSERT(!"unhandled state"); - } - - if (authority_len && - (error = url_parse_authority(&parser, authority, authority_len)) < 0) - goto done; - - if (path_len && - (error = url_parse_path(&parser, path, path_len)) < 0) - goto done; - - error = url_parse_finalize(url, &parser); - -done: - return error; -} - -int git_net_url_parse_http( - git_net_url *url, - const char *given) -{ - git_net_url_parser parser = GIT_NET_URL_PARSER_INIT; - const char *c = NULL, *authority = NULL, *path = NULL; - size_t authority_len = 0, path_len = 0; - int error; - - /* Hopefully this is a proper URL with a scheme. */ - if (git_net_str_is_url(given)) - return git_net_url_parse(url, given); - - memset(url, 0, sizeof(git_net_url)); - - /* Without a scheme, we are in the host (authority) section. */ - for (c = authority = given; *c; c++) { - if (!path && *c == '/') { - authority_len = (c - authority); - path = c; - } - } - - if (path) - path_len = (c - path); - else - authority_len = (c - authority); - - parser.scheme = "http"; - parser.scheme_len = 4; - parser.hierarchical = 1; - - if (authority_len && - (error = url_parse_authority(&parser, authority, authority_len)) < 0) - return error; - - if (path_len && - (error = url_parse_path(&parser, path, path_len)) < 0) - return error; - - return url_parse_finalize(url, &parser); -} - -static int scp_invalid(const char *message) -{ - git_error_set(GIT_ERROR_NET, "invalid scp-style path: %s", message); - return GIT_EINVALIDSPEC; -} - -static bool is_ipv6(const char *str) -{ - const char *c; - size_t colons = 0; - - if (*str++ != '[') - return false; - - for (c = str; *c; c++) { - if (*c == ':') - colons++; - - if (*c == ']') - return (colons > 1); - - if (*c != ':' && - (*c < '0' || *c > '9') && - (*c < 'a' || *c > 'f') && - (*c < 'A' || *c > 'F')) - return false; - } - - return false; -} - -static bool has_at(const char *str) -{ - const char *c; - - for (c = str; *c; c++) { - if (*c == '@') - return true; - - if (*c == ':') - break; - } - - return false; -} - -int git_net_url_parse_scp(git_net_url *url, const char *given) -{ - const char *default_port = default_port_for_scheme("ssh"); - const char *c, *user = NULL, *host = NULL, *port = NULL, *path = NULL; - size_t user_len = 0, host_len = 0, port_len = 0; - unsigned short bracket = 0; - - enum { - NONE, - USER, - HOST_START, HOST, HOST_END, - IPV6, IPV6_END, - PORT_START, PORT, PORT_END, - PATH_START - } state = NONE; - - memset(url, 0, sizeof(git_net_url)); - - for (c = given; *c && !path; c++) { - switch (state) { - case NONE: - switch (*c) { - case '@': - return scp_invalid("unexpected '@'"); - case ':': - return scp_invalid("unexpected ':'"); - case '[': - if (is_ipv6(c)) { - state = IPV6; - host = c; - } else if (bracket++ > 1) { - return scp_invalid("unexpected '['"); - } - break; - default: - if (has_at(c)) { - state = USER; - user = c; - } else { - state = HOST; - host = c; - } - break; - } - break; - - case USER: - if (*c == '@') { - user_len = (c - user); - state = HOST_START; - } - break; - - case HOST_START: - state = (*c == '[') ? IPV6 : HOST; - host = c; - break; - - case HOST: - if (*c == ':') { - host_len = (c - host); - state = bracket ? PORT_START : PATH_START; - } else if (*c == ']') { - if (bracket-- == 0) - return scp_invalid("unexpected ']'"); - - host_len = (c - host); - state = HOST_END; - } - break; - - case HOST_END: - if (*c != ':') - return scp_invalid("unexpected character after hostname"); - state = PATH_START; - break; - - case IPV6: - if (*c == ']') - state = IPV6_END; - break; - - case IPV6_END: - if (*c != ':') - return scp_invalid("unexpected character after ipv6 address"); - - host_len = (c - host); - state = bracket ? PORT_START : PATH_START; - break; - - case PORT_START: - port = c; - state = PORT; - break; - - case PORT: - if (*c == ']') { - if (bracket-- == 0) - return scp_invalid("unexpected ']'"); - - port_len = c - port; - state = PORT_END; - } - break; - - case PORT_END: - if (*c != ':') - return scp_invalid("unexpected character after ipv6 address"); - - state = PATH_START; - break; - - case PATH_START: - path = c; - break; - - default: - GIT_ASSERT(!"unhandled state"); - } - } - - if (!path) - return scp_invalid("path is required"); - - GIT_ERROR_CHECK_ALLOC(url->scheme = git__strdup("ssh")); - - if (user_len) - GIT_ERROR_CHECK_ALLOC(url->username = git__strndup(user, user_len)); - - GIT_ASSERT(host_len); - GIT_ERROR_CHECK_ALLOC(url->host = git__strndup(host, host_len)); - - if (port_len) { - url->port_specified = 1; - GIT_ERROR_CHECK_ALLOC(url->port = git__strndup(port, port_len)); - } else { - GIT_ERROR_CHECK_ALLOC(url->port = git__strdup(default_port)); - } - - GIT_ASSERT(path); - GIT_ERROR_CHECK_ALLOC(url->path = git__strdup(path)); - - return 0; -} - -int git_net_url_parse_standard_or_scp(git_net_url *url, const char *given) -{ - return git_net_str_is_url(given) ? - git_net_url_parse(url, given) : - git_net_url_parse_scp(url, given); -} - -int git_net_url_joinpath( - git_net_url *out, - git_net_url *one, - const char *two) -{ - git_str path = GIT_STR_INIT; - const char *query; - size_t one_len, two_len; - - git_net_url_dispose(out); - - if ((query = strchr(two, '?')) != NULL) { - two_len = query - two; - - if (*(++query) != '\0') { - out->query = git__strdup(query); - GIT_ERROR_CHECK_ALLOC(out->query); - } - } else { - two_len = strlen(two); - } - - /* Strip all trailing `/`s from the first path */ - one_len = one->path ? strlen(one->path) : 0; - while (one_len && one->path[one_len - 1] == '/') - one_len--; - - /* Strip all leading `/`s from the second path */ - while (*two == '/') { - two++; - two_len--; - } - - git_str_put(&path, one->path, one_len); - git_str_putc(&path, '/'); - git_str_put(&path, two, two_len); - - if (git_str_oom(&path)) - return -1; - - out->path = git_str_detach(&path); - - if (one->scheme) { - out->scheme = git__strdup(one->scheme); - GIT_ERROR_CHECK_ALLOC(out->scheme); - } - - if (one->host) { - out->host = git__strdup(one->host); - GIT_ERROR_CHECK_ALLOC(out->host); - } - - if (one->port) { - out->port = git__strdup(one->port); - GIT_ERROR_CHECK_ALLOC(out->port); - } - - if (one->username) { - out->username = git__strdup(one->username); - GIT_ERROR_CHECK_ALLOC(out->username); - } - - if (one->password) { - out->password = git__strdup(one->password); - GIT_ERROR_CHECK_ALLOC(out->password); - } - - return 0; -} - -/* - * Some servers strip the query parameters from the Location header - * when sending a redirect. Others leave it in place. - * Check for both, starting with the stripped case first, - * since it appears to be more common. - */ -static void remove_service_suffix( - git_net_url *url, - const char *service_suffix) -{ - const char *service_query = strchr(service_suffix, '?'); - size_t full_suffix_len = strlen(service_suffix); - size_t suffix_len = service_query ? - (size_t)(service_query - service_suffix) : full_suffix_len; - size_t path_len = strlen(url->path); - ssize_t truncate = -1; - - /* - * Check for a redirect without query parameters, - * like "/newloc/info/refs"' - */ - if (suffix_len && path_len >= suffix_len) { - size_t suffix_offset = path_len - suffix_len; - - if (git__strncmp(url->path + suffix_offset, service_suffix, suffix_len) == 0 && - (!service_query || git__strcmp(url->query, service_query + 1) == 0)) { - truncate = suffix_offset; - } - } - - /* - * If we haven't already found where to truncate to remove the - * suffix, check for a redirect with query parameters, like - * "/newloc/info/refs?service=git-upload-pack" - */ - if (truncate < 0 && git__suffixcmp(url->path, service_suffix) == 0) - truncate = path_len - full_suffix_len; - - /* Ensure we leave a minimum of '/' as the path */ - if (truncate == 0) - truncate++; - - if (truncate > 0) { - url->path[truncate] = '\0'; - - git__free(url->query); - url->query = NULL; - } -} - -int git_net_url_apply_redirect( - git_net_url *url, - const char *redirect_location, - bool allow_offsite, - const char *service_suffix) -{ - git_net_url tmp = GIT_NET_URL_INIT; - int error = 0; - - GIT_ASSERT(url); - GIT_ASSERT(redirect_location); - - if (redirect_location[0] == '/') { - git__free(url->path); - - if ((url->path = git__strdup(redirect_location)) == NULL) { - error = -1; - goto done; - } - } else { - git_net_url *original = url; - - if ((error = git_net_url_parse(&tmp, redirect_location)) < 0) - goto done; - - /* Validate that this is a legal redirection */ - - if (original->scheme && - strcmp(original->scheme, tmp.scheme) != 0 && - strcmp(tmp.scheme, "https") != 0) { - git_error_set(GIT_ERROR_NET, "cannot redirect from '%s' to '%s'", - original->scheme, tmp.scheme); - - error = -1; - goto done; - } - - if (original->host && - !allow_offsite && - git__strcasecmp(original->host, tmp.host) != 0) { - git_error_set(GIT_ERROR_NET, "cannot redirect from '%s' to '%s'", - original->host, tmp.host); - - error = -1; - goto done; - } - - git_net_url_swap(url, &tmp); - } - - /* Remove the service suffix if it was given to us */ - if (service_suffix) - remove_service_suffix(url, service_suffix); - -done: - git_net_url_dispose(&tmp); - return error; -} - -bool git_net_url_valid(git_net_url *url) -{ - return (url->host && url->port && url->path); -} - -bool git_net_url_is_default_port(git_net_url *url) -{ - const char *default_port; - - if (url->scheme && (default_port = default_port_for_scheme(url->scheme)) != NULL) - return (strcmp(url->port, default_port) == 0); - else - return false; -} - -bool git_net_url_is_ipv6(git_net_url *url) -{ - return (strchr(url->host, ':') != NULL); -} - -void git_net_url_swap(git_net_url *a, git_net_url *b) -{ - git_net_url tmp = GIT_NET_URL_INIT; - - memcpy(&tmp, a, sizeof(git_net_url)); - memcpy(a, b, sizeof(git_net_url)); - memcpy(b, &tmp, sizeof(git_net_url)); -} - -int git_net_url_fmt(git_str *buf, git_net_url *url) -{ - GIT_ASSERT_ARG(url); - GIT_ASSERT_ARG(url->scheme); - GIT_ASSERT_ARG(url->host); - - git_str_puts(buf, url->scheme); - git_str_puts(buf, "://"); - - if (url->username) { - git_str_puts(buf, url->username); - - if (url->password) { - git_str_puts(buf, ":"); - git_str_puts(buf, url->password); - } - - git_str_putc(buf, '@'); - } - - git_str_puts(buf, url->host); - - if (url->port && !git_net_url_is_default_port(url)) { - git_str_putc(buf, ':'); - git_str_puts(buf, url->port); - } - - git_str_puts(buf, url->path ? url->path : "/"); - - if (url->query) { - git_str_putc(buf, '?'); - git_str_puts(buf, url->query); - } - - return git_str_oom(buf) ? -1 : 0; -} - -int git_net_url_fmt_path(git_str *buf, git_net_url *url) -{ - git_str_puts(buf, url->path ? url->path : "/"); - - if (url->query) { - git_str_putc(buf, '?'); - git_str_puts(buf, url->query); - } - - return git_str_oom(buf) ? -1 : 0; -} - -static bool matches_pattern( - git_net_url *url, - const char *pattern, - size_t pattern_len) -{ - const char *domain, *port = NULL, *colon; - size_t host_len, domain_len, port_len = 0, wildcard = 0; - - GIT_UNUSED(url); - GIT_UNUSED(pattern); - - if (!pattern_len) - return false; - else if (pattern_len == 1 && pattern[0] == '*') - return true; - else if (pattern_len > 1 && pattern[0] == '*' && pattern[1] == '.') - wildcard = 2; - else if (pattern[0] == '.') - wildcard = 1; - - domain = pattern + wildcard; - domain_len = pattern_len - wildcard; - - if ((colon = memchr(domain, ':', domain_len)) != NULL) { - domain_len = colon - domain; - port = colon + 1; - port_len = pattern_len - wildcard - domain_len - 1; - } - - /* A pattern's port *must* match if it's specified */ - if (port_len && git__strlcmp(url->port, port, port_len) != 0) - return false; - - /* No wildcard? Host must match exactly. */ - if (!wildcard) - return !git__strlcmp(url->host, domain, domain_len); - - /* Wildcard: ensure there's (at least) a suffix match */ - if ((host_len = strlen(url->host)) < domain_len || - memcmp(url->host + (host_len - domain_len), domain, domain_len)) - return false; - - /* The pattern is *.domain and the host is simply domain */ - if (host_len == domain_len) - return true; - - /* The pattern is *.domain and the host is foo.domain */ - return (url->host[host_len - domain_len - 1] == '.'); -} - -bool git_net_url_matches_pattern(git_net_url *url, const char *pattern) -{ - return matches_pattern(url, pattern, strlen(pattern)); -} - -bool git_net_url_matches_pattern_list( - git_net_url *url, - const char *pattern_list) -{ - const char *pattern, *pattern_end, *sep; - - for (pattern = pattern_list; - pattern && *pattern; - pattern = sep ? sep + 1 : NULL) { - sep = strchr(pattern, ','); - pattern_end = sep ? sep : strchr(pattern, '\0'); - - if (matches_pattern(url, pattern, (pattern_end - pattern))) - return true; - } - - return false; -} - -void git_net_url_dispose(git_net_url *url) -{ - if (url->username) - git__memzero(url->username, strlen(url->username)); - - if (url->password) - git__memzero(url->password, strlen(url->password)); - - git__free(url->scheme); url->scheme = NULL; - git__free(url->host); url->host = NULL; - git__free(url->port); url->port = NULL; - git__free(url->path); url->path = NULL; - git__free(url->query); url->query = NULL; - git__free(url->fragment); url->fragment = NULL; - git__free(url->username); url->username = NULL; - git__free(url->password); url->password = NULL; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/net.h b/vendor/libgit2-sys/libgit2/src/util/net.h deleted file mode 100644 index 360a55d..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/net.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_net_h__ -#define INCLUDE_net_h__ - -#include "git2_util.h" - -/* - * Hostname handling - */ - -/* - * See if a given hostname matches a certificate name pattern, according - * to RFC2818 rules (which specifies HTTP over TLS). Mainly, an asterisk - * matches anything, but is limited to a single url component. - */ -extern bool git_net_hostname_matches_cert( - const char *hostname, - const char *pattern); - -/* - * URL handling - */ - -typedef struct git_net_url { - char *scheme; - char *host; - char *port; - char *path; - char *query; - char *fragment; - char *username; - char *password; - - unsigned int port_specified; -} git_net_url; - -#define GIT_NET_URL_INIT { NULL } - -/** Is a given string a url? */ -extern bool git_net_str_is_url(const char *str); - -/** Duplicate a URL */ -extern int git_net_url_dup(git_net_url *out, git_net_url *in); - -/** Parses a string containing a URL into a structure. */ -extern int git_net_url_parse(git_net_url *url, const char *str); - -/** Parses a string containing an SCP style path into a URL structure. */ -extern int git_net_url_parse_scp(git_net_url *url, const char *str); - -/** - * Parses a string containing a standard URL or an SCP style path into - * a URL structure. - */ -extern int git_net_url_parse_standard_or_scp(git_net_url *url, const char *str); - -/** - * Parses a string containing an HTTP endpoint that may not be a - * well-formed URL. For example, "localhost" or "localhost:port". - */ -extern int git_net_url_parse_http( - git_net_url *url, - const char *str); - -/** Appends a path and/or query string to the given URL */ -extern int git_net_url_joinpath( - git_net_url *out, - git_net_url *in, - const char *path); - -/** Ensures that a URL is minimally valid (contains a host, port and path) */ -extern bool git_net_url_valid(git_net_url *url); - -/** Returns true if the URL is on the default port. */ -extern bool git_net_url_is_default_port(git_net_url *url); - -/** Returns true if the host portion of the URL is an ipv6 address. */ -extern bool git_net_url_is_ipv6(git_net_url *url); - -/* Applies a redirect to the URL with a git-aware service suffix. */ -extern int git_net_url_apply_redirect( - git_net_url *url, - const char *redirect_location, - bool allow_offsite, - const char *service_suffix); - -/** Swaps the contents of one URL for another. */ -extern void git_net_url_swap(git_net_url *a, git_net_url *b); - -/** Places the URL into the given buffer. */ -extern int git_net_url_fmt(git_str *out, git_net_url *url); - -/** Place the path and query string into the given buffer. */ -extern int git_net_url_fmt_path(git_str *buf, git_net_url *url); - -/** Determines if the url matches given pattern or pattern list */ -extern bool git_net_url_matches_pattern( - git_net_url *url, - const char *pattern); -extern bool git_net_url_matches_pattern_list( - git_net_url *url, - const char *pattern_list); - -/** Disposes the contents of the structure. */ -extern void git_net_url_dispose(git_net_url *url); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/pool.c b/vendor/libgit2-sys/libgit2/src/util/pool.c deleted file mode 100644 index afbae45..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/pool.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "pool.h" - -#include "posix.h" -#ifndef GIT_WIN32 -#include -#endif - -struct git_pool_page { - git_pool_page *next; - size_t size; - size_t avail; - GIT_ALIGN(char data[GIT_FLEX_ARRAY], 8); -}; - -static void *pool_alloc_page(git_pool *pool, size_t size); - -#ifndef GIT_DEBUG_POOL - -static size_t system_page_size = 0; - -int git_pool_global_init(void) -{ - if (git__page_size(&system_page_size) < 0) - system_page_size = 4096; - /* allow space for malloc overhead */ - system_page_size -= (2 * sizeof(void *)) + sizeof(git_pool_page); - return 0; -} - -int git_pool_init(git_pool *pool, size_t item_size) -{ - GIT_ASSERT_ARG(pool); - GIT_ASSERT_ARG(item_size >= 1); - - memset(pool, 0, sizeof(git_pool)); - pool->item_size = item_size; - pool->page_size = system_page_size; - - return 0; -} - -void git_pool_clear(git_pool *pool) -{ - git_pool_page *scan, *next; - - for (scan = pool->pages; scan != NULL; scan = next) { - next = scan->next; - git__free(scan); - } - - pool->pages = NULL; -} - -static void *pool_alloc_page(git_pool *pool, size_t size) -{ - git_pool_page *page; - const size_t new_page_size = (size <= pool->page_size) ? pool->page_size : size; - size_t alloc_size; - - if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, new_page_size, sizeof(git_pool_page)) || - !(page = git__malloc(alloc_size))) - return NULL; - - page->size = new_page_size; - page->avail = new_page_size - size; - page->next = pool->pages; - - pool->pages = page; - - return page->data; -} - -static void *pool_alloc(git_pool *pool, size_t size) -{ - git_pool_page *page = pool->pages; - void *ptr = NULL; - - if (!page || page->avail < size) - return pool_alloc_page(pool, size); - - ptr = &page->data[page->size - page->avail]; - page->avail -= size; - - return ptr; -} - -uint32_t git_pool__open_pages(git_pool *pool) -{ - uint32_t ct = 0; - git_pool_page *scan; - for (scan = pool->pages; scan != NULL; scan = scan->next) ct++; - return ct; -} - -bool git_pool__ptr_in_pool(git_pool *pool, void *ptr) -{ - git_pool_page *scan; - for (scan = pool->pages; scan != NULL; scan = scan->next) - if ((void *)scan->data <= ptr && - (void *)(((char *)scan->data) + scan->size) > ptr) - return true; - return false; -} - -#else - -int git_pool_global_init(void) -{ - return 0; -} - -static int git_pool__ptr_cmp(const void * a, const void * b) -{ - if(a > b) { - return 1; - } - if(a < b) { - return -1; - } - else { - return 0; - } -} - -int git_pool_init(git_pool *pool, size_t item_size) -{ - GIT_ASSERT_ARG(pool); - GIT_ASSERT_ARG(item_size >= 1); - - memset(pool, 0, sizeof(git_pool)); - pool->item_size = item_size; - pool->page_size = git_pool__system_page_size(); - git_vector_init(&pool->allocations, 100, git_pool__ptr_cmp); - - return 0; -} - -void git_pool_clear(git_pool *pool) -{ - git_vector_dispose_deep(&pool->allocations); -} - -static void *pool_alloc(git_pool *pool, size_t size) { - void *ptr = NULL; - if((ptr = git__malloc(size)) == NULL) { - return NULL; - } - git_vector_insert_sorted(&pool->allocations, ptr, NULL); - return ptr; -} - -bool git_pool__ptr_in_pool(git_pool *pool, void *ptr) -{ - size_t pos; - return git_vector_bsearch(&pos, &pool->allocations, ptr) != GIT_ENOTFOUND; -} -#endif - -void git_pool_swap(git_pool *a, git_pool *b) -{ - git_pool temp; - - if (a == b) - return; - - memcpy(&temp, a, sizeof(temp)); - memcpy(a, b, sizeof(temp)); - memcpy(b, &temp, sizeof(temp)); -} - -static size_t alloc_size(git_pool *pool, size_t count) -{ - const size_t align = sizeof(void *) - 1; - - if (pool->item_size > 1) { - const size_t item_size = (pool->item_size + align) & ~align; - return item_size * count; - } - - return (count + align) & ~align; -} - -void *git_pool_malloc(git_pool *pool, size_t items) -{ - return pool_alloc(pool, alloc_size(pool, items)); -} - -void *git_pool_mallocz(git_pool *pool, size_t items) -{ - const size_t size = alloc_size(pool, items); - void *ptr = pool_alloc(pool, size); - if (ptr) - memset(ptr, 0x0, size); - return ptr; -} - -char *git_pool_strndup(git_pool *pool, const char *str, size_t n) -{ - char *ptr = NULL; - - GIT_ASSERT_ARG_WITH_RETVAL(pool, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(str, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(pool->item_size == sizeof(char), NULL); - - if (n == SIZE_MAX) - return NULL; - - if ((ptr = git_pool_malloc(pool, (n + 1))) != NULL) { - memcpy(ptr, str, n); - ptr[n] = '\0'; - } - - return ptr; -} - -char *git_pool_strdup(git_pool *pool, const char *str) -{ - GIT_ASSERT_ARG_WITH_RETVAL(pool, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(str, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(pool->item_size == sizeof(char), NULL); - - return git_pool_strndup(pool, str, strlen(str)); -} - -char *git_pool_strdup_safe(git_pool *pool, const char *str) -{ - return str ? git_pool_strdup(pool, str) : NULL; -} - -char *git_pool_strcat(git_pool *pool, const char *a, const char *b) -{ - void *ptr; - size_t len_a, len_b, total; - - GIT_ASSERT_ARG_WITH_RETVAL(pool, NULL); - GIT_ASSERT_ARG_WITH_RETVAL(pool->item_size == sizeof(char), NULL); - - len_a = a ? strlen(a) : 0; - len_b = b ? strlen(b) : 0; - - if (GIT_ADD_SIZET_OVERFLOW(&total, len_a, len_b) || - GIT_ADD_SIZET_OVERFLOW(&total, total, 1)) - return NULL; - - if ((ptr = git_pool_malloc(pool, total)) != NULL) { - if (len_a) - memcpy(ptr, a, len_a); - if (len_b) - memcpy(((char *)ptr) + len_a, b, len_b); - *(((char *)ptr) + len_a + len_b) = '\0'; - } - return ptr; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/pool.h b/vendor/libgit2-sys/libgit2/src/util/pool.h deleted file mode 100644 index 75a28c3..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/pool.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_pool_h__ -#define INCLUDE_pool_h__ - -#include "git2_util.h" - -#include "vector.h" - -typedef struct git_pool_page git_pool_page; - -#ifndef GIT_DEBUG_POOL -/** - * Chunked allocator. - * - * A `git_pool` can be used when you want to cheaply allocate - * multiple items of the same type and are willing to free them - * all together with a single call. The two most common cases - * are a set of fixed size items (such as lots of OIDs) or a - * bunch of strings. - * - * Internally, a `git_pool` allocates pages of memory and then - * deals out blocks from the trailing unused portion of each page. - * The pages guarantee that the number of actual allocations done - * will be much smaller than the number of items needed. - * - * For examples of how to set up a `git_pool` see `git_pool_init`. - */ -typedef struct { - git_pool_page *pages; /* allocated pages */ - size_t item_size; /* size of single alloc unit in bytes */ - size_t page_size; /* size of page in bytes */ -} git_pool; - -#define GIT_POOL_INIT { NULL, 0, 0 } - -#else - -/** - * Debug chunked allocator. - * - * Acts just like `git_pool` but instead of actually pooling allocations it - * passes them through to `git__malloc`. This makes it possible to easily debug - * systems that use `git_pool` using valgrind. - * - * In order to track allocations during the lifetime of the pool we use a - * `git_vector`. When the pool is deallocated everything in the vector is - * freed. - * - * `API is exactly the same as the standard `git_pool` with one exception. - * Since we aren't allocating pages to hand out in chunks we can't easily - * implement `git_pool__open_pages`. - */ -typedef struct { - git_vector allocations; - size_t item_size; - size_t page_size; -} git_pool; - -#define GIT_POOL_INIT { GIT_VECTOR_INIT, 0, 0 } - -#endif - -/** - * Initialize a pool. - * - * To allocation strings, use like this: - * - * git_pool_init(&string_pool, 1); - * my_string = git_pool_strdup(&string_pool, your_string); - * - * To allocate items of fixed size, use like this: - * - * git_pool_init(&pool, sizeof(item)); - * my_item = git_pool_malloc(&pool, 1); - * - * Of course, you can use this in other ways, but those are the - * two most common patterns. - */ -extern int git_pool_init(git_pool *pool, size_t item_size); - -GIT_INLINE(bool) git_pool_is_initialized(git_pool *pool) -{ - return (pool->item_size > 0); -} - -/** - * Free all items in pool - */ -extern void git_pool_clear(git_pool *pool); - -/** - * Swap two pools with one another - */ -extern void git_pool_swap(git_pool *a, git_pool *b); - -/** - * Allocate space for one or more items from a pool. - */ -extern void *git_pool_malloc(git_pool *pool, size_t items); -extern void *git_pool_mallocz(git_pool *pool, size_t items); - -/** - * Allocate space and duplicate string data into it. - * - * This is allowed only for pools with item_size == sizeof(char) - */ -extern char *git_pool_strndup(git_pool *pool, const char *str, size_t n); - -/** - * Allocate space and duplicate a string into it. - * - * This is allowed only for pools with item_size == sizeof(char) - */ -extern char *git_pool_strdup(git_pool *pool, const char *str); - -/** - * Allocate space and duplicate a string into it, NULL is no error. - * - * This is allowed only for pools with item_size == sizeof(char) - */ -extern char *git_pool_strdup_safe(git_pool *pool, const char *str); - -/** - * Allocate space for the concatenation of two strings. - * - * This is allowed only for pools with item_size == sizeof(char) - */ -extern char *git_pool_strcat(git_pool *pool, const char *a, const char *b); - -/* - * Misc utilities - */ -#ifndef GIT_DEBUG_POOL -extern uint32_t git_pool__open_pages(git_pool *pool); -#endif -extern bool git_pool__ptr_in_pool(git_pool *pool, void *ptr); - -/** - * This function is being called by our global setup routines to - * initialize the system pool size. - * - * @return 0 on success, <0 on failure - */ -extern int git_pool_global_init(void); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/posix.c b/vendor/libgit2-sys/libgit2/src/util/posix.c deleted file mode 100644 index cfc0e07..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/posix.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "posix.h" - -#include "fs_path.h" -#include -#include - -size_t p_fsync__cnt = 0; - -#ifndef GIT_WIN32 - -#ifdef NO_ADDRINFO - -int p_getaddrinfo( - const char *host, - const char *port, - struct addrinfo *hints, - struct addrinfo **info) -{ - struct addrinfo *ainfo, *ai; - int p = 0; - - GIT_UNUSED(hints); - - if ((ainfo = git__malloc(sizeof(struct addrinfo))) == NULL) - return -1; - - if ((ainfo->ai_hostent = gethostbyname(host)) == NULL) { - git__free(ainfo); - return -2; - } - - ainfo->ai_servent = getservbyname(port, 0); - - if (ainfo->ai_servent) - ainfo->ai_port = ainfo->ai_servent->s_port; - else - ainfo->ai_port = htons(atol(port)); - - memcpy(&ainfo->ai_addr_in.sin_addr, - ainfo->ai_hostent->h_addr_list[0], - ainfo->ai_hostent->h_length); - - ainfo->ai_protocol = 0; - ainfo->ai_socktype = hints->ai_socktype; - ainfo->ai_family = ainfo->ai_hostent->h_addrtype; - ainfo->ai_addr_in.sin_family = ainfo->ai_family; - ainfo->ai_addr_in.sin_port = ainfo->ai_port; - ainfo->ai_addr = (struct addrinfo *)&ainfo->ai_addr_in; - ainfo->ai_addrlen = sizeof(struct sockaddr_in); - - *info = ainfo; - - if (ainfo->ai_hostent->h_addr_list[1] == NULL) { - ainfo->ai_next = NULL; - return 0; - } - - ai = ainfo; - - for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) { - if (!(ai->ai_next = git__malloc(sizeof(struct addrinfo)))) { - p_freeaddrinfo(ainfo); - return -1; - } - memcpy(ai->ai_next, ainfo, sizeof(struct addrinfo)); - memcpy(&ai->ai_next->ai_addr_in.sin_addr, - ainfo->ai_hostent->h_addr_list[p], - ainfo->ai_hostent->h_length); - ai->ai_next->ai_addr = (struct addrinfo *)&ai->ai_next->ai_addr_in; - ai = ai->ai_next; - } - - ai->ai_next = NULL; - return 0; -} - -void p_freeaddrinfo(struct addrinfo *info) -{ - struct addrinfo *p, *next; - - p = info; - - while(p != NULL) { - next = p->ai_next; - git__free(p); - p = next; - } -} - -const char *p_gai_strerror(int ret) -{ - switch(ret) { - case -1: return "Out of memory"; break; - case -2: return "Address lookup failed"; break; - default: return "Unknown error"; break; - } -} - -#endif /* NO_ADDRINFO */ - -int p_open(const char *path, volatile int flags, ...) -{ - mode_t mode = 0; - - #ifdef GIT_DEBUG_STRICT_OPEN - if (strstr(path, "//") != NULL) { - errno = EACCES; - return -1; - } - #endif - - if (flags & O_CREAT) { - va_list arg_list; - - va_start(arg_list, flags); - mode = (mode_t)va_arg(arg_list, int); - va_end(arg_list); - } - - return open(path, flags | O_BINARY | O_CLOEXEC, mode); -} - -int p_creat(const char *path, mode_t mode) -{ - return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC, mode); -} - -int p_getcwd(char *buffer_out, size_t size) -{ - char *cwd_buffer; - - GIT_ASSERT_ARG(buffer_out); - GIT_ASSERT_ARG(size > 0); - - cwd_buffer = getcwd(buffer_out, size); - - if (cwd_buffer == NULL) - return -1; - - git_fs_path_mkposix(buffer_out); - git_fs_path_string_to_dir(buffer_out, size); /* append trailing slash */ - - return 0; -} - -int p_rename(const char *from, const char *to) -{ - if (!link(from, to)) { - p_unlink(from); - return 0; - } - - if (!rename(from, to)) - return 0; - - return -1; -} - -#endif /* GIT_WIN32 */ - -ssize_t p_read(git_file fd, void *buf, size_t cnt) -{ - char *b = buf; - - if (!git__is_ssizet(cnt)) { -#ifdef GIT_WIN32 - SetLastError(ERROR_INVALID_PARAMETER); -#endif - errno = EINVAL; - return -1; - } - - while (cnt) { - ssize_t r; -#ifdef GIT_WIN32 - r = read(fd, b, cnt > INT_MAX ? INT_MAX : (unsigned int)cnt); -#else - r = read(fd, b, cnt); -#endif - if (r < 0) { - if (errno == EINTR || errno == EAGAIN) - continue; - return -1; - } - if (!r) - break; - cnt -= r; - b += r; - } - return (b - (char *)buf); -} - -int p_write(git_file fd, const void *buf, size_t cnt) -{ - const char *b = buf; - - while (cnt) { - ssize_t r; -#ifdef GIT_WIN32 - GIT_ASSERT((size_t)((unsigned int)cnt) == cnt); - r = write(fd, b, (unsigned int)cnt); -#else - r = write(fd, b, cnt); -#endif - if (r < 0) { - if (errno == EINTR || GIT_ISBLOCKED(errno)) - continue; - return -1; - } - if (!r) { - errno = EPIPE; - return -1; - } - cnt -= r; - b += r; - } - return 0; -} - -#ifdef NO_MMAP - -#include "map.h" - -int git__page_size(size_t *page_size) -{ - /* dummy; here we don't need any alignment anyway */ - *page_size = 4096; - return 0; -} - -int git__mmap_alignment(size_t *alignment) -{ - /* dummy; here we don't need any alignment anyway */ - *alignment = 4096; - return 0; -} - - -int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset) -{ - const char *ptr; - size_t remaining_len; - - GIT_MMAP_VALIDATE(out, len, prot, flags); - - /* writes cannot be emulated without handling pagefaults since write happens by - * writing to mapped memory */ - if (prot & GIT_PROT_WRITE) { - git_error_set(GIT_ERROR_OS, "trying to map %s-writeable", - ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED) ? "shared": "private"); - return -1; - } - - if (!git__is_ssizet(len)) { - errno = EINVAL; - return -1; - } - - out->len = 0; - out->data = git__malloc(len); - GIT_ERROR_CHECK_ALLOC(out->data); - - remaining_len = len; - ptr = (const char *)out->data; - while (remaining_len > 0) { - ssize_t nb; - HANDLE_EINTR(nb, p_pread(fd, (void *)ptr, remaining_len, offset)); - if (nb <= 0) { - git_error_set(GIT_ERROR_OS, "mmap emulation failed"); - git__free(out->data); - out->data = NULL; - return -1; - } - - ptr += nb; - offset += nb; - remaining_len -= nb; - } - - out->len = len; - return 0; -} - -int p_munmap(git_map *map) -{ - GIT_ASSERT_ARG(map); - git__free(map->data); - - /* Initializing will help debug use-after-free */ - map->len = 0; - map->data = NULL; - - return 0; -} - -#endif - -#if defined(GIT_IO_POLL) || defined(GIT_IO_WSAPOLL) - -/* Handled by posix.h; this test simplifies the final else */ - -#elif defined(GIT_IO_SELECT) - -int p_poll(struct pollfd *fds, unsigned int nfds, int timeout_ms) -{ - fd_set read_fds, write_fds, except_fds; - struct timeval timeout = { 0, 0 }; - unsigned int i; - int max_fd = -1, ret; - - FD_ZERO(&read_fds); - FD_ZERO(&write_fds); - FD_ZERO(&except_fds); - - for (i = 0; i < nfds; i++) { - if ((fds[i].events & POLLIN)) - FD_SET(fds[i].fd, &read_fds); - - if ((fds[i].events & POLLOUT)) - FD_SET(fds[i].fd, &write_fds); - - if ((fds[i].events & POLLPRI)) - FD_SET(fds[i].fd, &except_fds); - - max_fd = MAX(max_fd, fds[i].fd); - } - - if (timeout_ms > 0) { - timeout.tv_sec = timeout_ms / 1000; - timeout.tv_usec = (timeout_ms % 1000) * 1000; - } - - if ((ret = select(max_fd + 1, &read_fds, &write_fds, &except_fds, - timeout_ms < 0 ? NULL : &timeout)) < 0) - goto done; - - for (i = 0; i < nfds; i++) { - fds[i].revents = 0 | - FD_ISSET(fds[i].fd, &read_fds) ? POLLIN : 0 | - FD_ISSET(fds[i].fd, &write_fds) ? POLLOUT : 0 | - FD_ISSET(fds[i].fd, &except_fds) ? POLLPRI : 0; - } - -done: - return ret; -} - -#else -# error no poll compatible implementation -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/posix.h b/vendor/libgit2-sys/libgit2/src/util/posix.h deleted file mode 100644 index 7470745..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/posix.h +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_posix_h__ -#define INCLUDE_posix_h__ - -#include "git2_util.h" - -#include -#include -#include - -/* stat: file mode type testing macros */ -#ifndef S_IFGITLINK -#define S_IFGITLINK 0160000 -#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) -#endif - -#ifndef S_IFLNK -#define S_IFLNK 0120000 -#undef _S_IFLNK -#define _S_IFLNK S_IFLNK -#endif - -#ifndef S_IWUSR -#define S_IWUSR 00200 -#endif - -#ifndef S_IXUSR -#define S_IXUSR 00100 -#endif - -#ifndef S_ISLNK -#define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) -#endif - -#ifndef S_ISDIR -#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -#endif - -#ifndef S_ISREG -#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) -#endif - -#ifndef S_ISFIFO -#define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) -#endif - -/* if S_ISGID is not defined, then don't try to set it */ -#ifndef S_ISGID -#define S_ISGID 0 -#endif - -#ifndef O_BINARY -#define O_BINARY 0 -#endif -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 -#endif -#ifndef SOCK_CLOEXEC -#define SOCK_CLOEXEC 0 -#endif - -/* access() mode parameter #defines */ -#ifndef F_OK -#define F_OK 0 /* existence check */ -#endif -#ifndef W_OK -#define W_OK 2 /* write mode check */ -#endif -#ifndef R_OK -#define R_OK 4 /* read mode check */ -#endif - -/* Determine whether an errno value indicates that a read or write failed - * because the descriptor is blocked. - */ -#if defined(EWOULDBLOCK) -#define GIT_ISBLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK) -#else -#define GIT_ISBLOCKED(e) ((e) == EAGAIN) -#endif - -/* define some standard errnos that the runtime may be missing. for example, - * mingw lacks EAFNOSUPPORT. */ -#ifndef EAFNOSUPPORT -#define EAFNOSUPPORT (INT_MAX-1) -#endif - -/* Compiler independent macro to handle signal interrpted system calls */ -#define HANDLE_EINTR(result, x) do { \ - result = (x); \ - } while (result == -1 && errno == EINTR); - - -/* Provide a 64-bit size for offsets. */ - -#if defined(_MSC_VER) -typedef __int64 off64_t; -#elif defined(__HAIKU__) -typedef __haiku_std_int64 off64_t; -#elif defined(__APPLE__) -typedef __int64_t off64_t; -#elif defined(_AIX) -typedef long long off64_t; -#else -typedef int64_t off64_t; -#endif - -typedef int git_file; - -/** - * Standard POSIX Methods - * - * All the methods starting with the `p_` prefix are - * direct ports of the standard POSIX methods. - * - * Some of the methods are slightly wrapped to provide - * saner defaults. Some of these methods are emulated - * in Windows platforms. - * - * Use your manpages to check the docs on these. - */ - -extern ssize_t p_read(git_file fd, void *buf, size_t cnt); -extern int p_write(git_file fd, const void *buf, size_t cnt); - -extern ssize_t p_pread(int fd, void *data, size_t size, off64_t offset); -extern ssize_t p_pwrite(int fd, const void *data, size_t size, off64_t offset); - -#define p_close(fd) close(fd) -#define p_umask(m) umask(m) - -extern int p_open(const char *path, int flags, ...); -extern int p_creat(const char *path, mode_t mode); -extern int p_getcwd(char *buffer_out, size_t size); -extern int p_rename(const char *from, const char *to); - -extern int git__page_size(size_t *page_size); -extern int git__mmap_alignment(size_t *page_size); - -/* The number of times `p_fsync` has been called. Note that this is for - * test code only; it it not necessarily thread-safe and should not be - * relied upon in production. - */ -extern size_t p_fsync__cnt; - -/** - * Platform-dependent methods - */ -#ifdef GIT_WIN32 -# include "win32/posix.h" -#else -# include "unix/posix.h" -#endif - -#include "strnlen.h" - -#ifdef NO_READDIR_R -GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) -{ - GIT_UNUSED(entry); - *result = readdir(dirp); - return 0; -} -#else /* NO_READDIR_R */ -# define p_readdir_r(d,e,r) readdir_r(d,e,r) -#endif - -#ifdef NO_ADDRINFO -# include -struct addrinfo { - struct hostent *ai_hostent; - struct servent *ai_servent; - struct sockaddr_in ai_addr_in; - struct sockaddr *ai_addr; - size_t ai_addrlen; - int ai_family; - int ai_socktype; - int ai_protocol; - long ai_port; - struct addrinfo *ai_next; -}; - -extern int p_getaddrinfo(const char *host, const char *port, - struct addrinfo *hints, struct addrinfo **info); -extern void p_freeaddrinfo(struct addrinfo *info); -extern const char *p_gai_strerror(int ret); -#else -# define p_getaddrinfo(a, b, c, d) getaddrinfo(a, b, c, d) -# define p_freeaddrinfo(a) freeaddrinfo(a) -# define p_gai_strerror(c) gai_strerror(c) -#endif /* NO_ADDRINFO */ - -#ifdef GIT_IO_POLL -# include -# define p_poll poll -#elif GIT_IO_WSAPOLL -# include -# define p_poll WSAPoll -#else -# define POLLIN 0x01 -# define POLLPRI 0x02 -# define POLLOUT 0x04 -# define POLLERR 0x08 -# define POLLHUP 0x10 - -struct pollfd { - int fd; - short events; - short revents; -}; - -extern int p_poll(struct pollfd *fds, unsigned int nfds, int timeout); -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/pqueue.c b/vendor/libgit2-sys/libgit2/src/util/pqueue.c deleted file mode 100644 index 3820e99..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/pqueue.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "pqueue.h" - -#include "util.h" - -#define PQUEUE_LCHILD_OF(I) (((I)<<1)+1) -#define PQUEUE_RCHILD_OF(I) (((I)<<1)+2) -#define PQUEUE_PARENT_OF(I) (((I)-1)>>1) - -int git_pqueue_init( - git_pqueue *pq, - uint32_t flags, - size_t init_size, - git_vector_cmp cmp) -{ - int error = git_vector_init(pq, init_size, cmp); - - if (!error) { - /* mix in our flags */ - pq->flags |= flags; - - /* if fixed size heap, pretend vector is exactly init_size elements */ - if ((flags & GIT_PQUEUE_FIXED_SIZE) && init_size > 0) - pq->_alloc_size = init_size; - } - - return error; -} - -static void pqueue_up(git_pqueue *pq, size_t el) -{ - size_t parent_el = PQUEUE_PARENT_OF(el); - void *kid = git_vector_get(pq, el); - - while (el > 0) { - void *parent = pq->contents[parent_el]; - - if (pq->_cmp(parent, kid) <= 0) - break; - - pq->contents[el] = parent; - - el = parent_el; - parent_el = PQUEUE_PARENT_OF(el); - } - - pq->contents[el] = kid; -} - -static void pqueue_down(git_pqueue *pq, size_t el) -{ - void *parent = git_vector_get(pq, el), *kid, *rkid; - - while (1) { - size_t kid_el = PQUEUE_LCHILD_OF(el); - - if ((kid = git_vector_get(pq, kid_el)) == NULL) - break; - - if ((rkid = git_vector_get(pq, kid_el + 1)) != NULL && - pq->_cmp(kid, rkid) > 0) { - kid = rkid; - kid_el += 1; - } - - if (pq->_cmp(parent, kid) <= 0) - break; - - pq->contents[el] = kid; - el = kid_el; - } - - pq->contents[el] = parent; -} - -int git_pqueue_insert(git_pqueue *pq, void *item) -{ - int error = 0; - - /* if heap is full, pop the top element if new one should replace it */ - if ((pq->flags & GIT_PQUEUE_FIXED_SIZE) != 0 && - pq->length >= pq->_alloc_size) - { - /* skip this item if below min item in heap or if - * we do not have a comparison function */ - if (!pq->_cmp || pq->_cmp(item, git_vector_get(pq, 0)) <= 0) - return 0; - /* otherwise remove the min item before inserting new */ - (void)git_pqueue_pop(pq); - } - - if (!(error = git_vector_insert(pq, item)) && pq->_cmp) - pqueue_up(pq, pq->length - 1); - - return error; -} - -void *git_pqueue_pop(git_pqueue *pq) -{ - void *rval; - - if (!pq->_cmp) { - rval = git_vector_last(pq); - } else { - rval = git_pqueue_get(pq, 0); - } - - if (git_pqueue_size(pq) > 1 && pq->_cmp) { - /* move last item to top of heap, shrink, and push item down */ - pq->contents[0] = git_vector_last(pq); - git_vector_pop(pq); - pqueue_down(pq, 0); - } else { - /* all we need to do is shrink the heap in this case */ - git_vector_pop(pq); - } - - return rval; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/pqueue.h b/vendor/libgit2-sys/libgit2/src/util/pqueue.h deleted file mode 100644 index a8ef018..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/pqueue.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_pqueue_h__ -#define INCLUDE_pqueue_h__ - -#include "git2_util.h" - -#include "vector.h" - -typedef git_vector git_pqueue; - -enum { - /* flag meaning: don't grow heap, keep highest values only */ - GIT_PQUEUE_FIXED_SIZE = (GIT_VECTOR_FLAG_MAX << 1) -}; - -/** - * Initialize priority queue - * - * @param pq The priority queue struct to initialize - * @param flags Flags (see above) to control queue behavior - * @param init_size The initial queue size - * @param cmp The entry priority comparison function - * @return 0 on success, <0 on error - */ -extern int git_pqueue_init( - git_pqueue *pq, - uint32_t flags, - size_t init_size, - git_vector_cmp cmp); - -#define git_pqueue_free git_vector_dispose -#define git_pqueue_clear git_vector_clear -#define git_pqueue_size git_vector_length -#define git_pqueue_get git_vector_get -#define git_pqueue_reverse git_vector_reverse - -/** - * Insert a new item into the queue - * - * @param pq The priority queue - * @param item Pointer to the item data - * @return 0 on success, <0 on failure - */ -extern int git_pqueue_insert(git_pqueue *pq, void *item); - -/** - * Remove the top item in the priority queue - * - * @param pq The priority queue - * @return item from heap on success, NULL if queue is empty - */ -extern void *git_pqueue_pop(git_pqueue *pq); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/process.h b/vendor/libgit2-sys/libgit2/src/util/process.h deleted file mode 100644 index a3804ec..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/process.h +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_process_h__ -#define INCLUDE_process_h__ - -typedef struct git_process git_process; - -typedef struct { - unsigned int use_shell : 1, - capture_in : 1, - capture_out : 1, - capture_err : 1, - exclude_env : 1; - - char *cwd; -} git_process_options; - -typedef enum { - GIT_PROCESS_STATUS_NONE, - GIT_PROCESS_STATUS_NORMAL, - GIT_PROCESS_STATUS_ERROR -} git_process_result_status; - -#define GIT_PROCESS_RESULT_INIT { GIT_PROCESS_STATUS_NONE } - -typedef struct { - git_process_result_status status; - int exitcode; - int signal; -} git_process_result; - -#define GIT_PROCESS_OPTIONS_INIT { 0 } - -#ifdef GIT_WIN32 -# define p_pid_t DWORD -#else -# define p_pid_t pid_t -#endif - -/** - * Create a new process. The command to run should be specified as the - * element of the `arg` array, execv-style. This should be the full path - * to the command to run, the PATH is not obeyed. - * - * This function will add the given environment variables (in `env`) - * to the current environment. Operations on environment variables - * are not thread safe, so you may not modify the environment during - * this call. You can avoid this by setting `exclude_env` in the - * options and providing the entire environment yourself. - * - * @param out location to store the process - * @param args the command (with arguments) to run - * @param args_len the length of the args array - * @param env environment variables to add (or NULL) - * @param env_len the length of the env len - * @param opts the options for creating the process - * @return 0 or an error code - */ -extern int git_process_new( - git_process **out, - const char **args, - size_t args_len, - const char **env, - size_t env_len, - git_process_options *opts); - -/** - * Create a new process. The command to run should be specified as the - * `cmdline` option - which is the full text of the command line as it - * would be specified or run by a user. The command to run will be - * looked up in the PATH. - * - * On Unix, this will be executed by the system's shell (`/bin/sh`) - * and may contain _Bourne-style_ shell quoting rules. On Windows, - * this will be passed to `CreateProcess`, and similarly, may - * contain _Windows-style_ shell quoting rules. - * - * This function will add the given environment variables (in `env`) - * to the current environment. Operations on environment variables - * are not thread safe, so you may not modify the environment during - * this call. You can avoid this by setting `exclude_env` in the - * options and providing the entire environment yourself. - */ -extern int git_process_new_from_cmdline( - git_process **out, - const char *cmdline, - const char **env, - size_t env_len, - git_process_options *opts); - -#ifdef GIT_WIN32 - -extern int git_process__appname( - git_str *out, - const char *cmdline); - -/* Windows path parsing is tricky; this helper function is for testing. */ -extern int git_process__cmdline( - git_str *out, - const char **in, - size_t in_len); - -#endif - -/* - * Whether the given string looks like a command line option (starts - * with a dash). This is useful for examining strings that will become - * cmdline arguments to ensure that they are not erroneously treated - * as an option. For example, arguments to `ssh`. - */ -GIT_INLINE(bool) git_process__is_cmdline_option(const char *str) -{ - return (str && str[0] == '-'); -} - -/** - * Start the process. - * - * @param process the process to start - * @return 0 or an error code - */ -extern int git_process_start(git_process *process); - -/** - * Returns the process id of the process. - * - * @param out pointer to a pid_t to store the process id - * @param process the process to query - * @return 0 or an error code - */ -extern int git_process_id(p_pid_t *out, git_process *process); - -/** - * Read from the process's stdout. The process must have been created with - * `capture_out` set to true. - * - * @param process the process to read from - * @param buf the buf to read into - * @param count maximum number of bytes to read - * @return number of bytes read or an error code - */ -extern ssize_t git_process_read(git_process *process, void *buf, size_t count); - -/** - * Read from the process's stderr. The process must have been created with - * `capture_err` set to true. - * - * @param process the process to read from - * @param buf the buf to read into - * @param count maximum number of bytes to read - * @return number of bytes read or an error code - */ -extern ssize_t git_process_read_err(git_process *process, void *buf, size_t count); - -/** - * Write to the process's stdin. The process must have been created with - * `capture_in` set to true. - * - * @param process the process to write to - * @param buf the buf to write - * @param count maximum number of bytes to write - * @return number of bytes written or an error code - */ -extern ssize_t git_process_write(git_process *process, const void *buf, size_t count); - -/** - * Wait for the process to finish. - * - * @param result the result of the process or NULL - * @param process the process to wait on - */ -extern int git_process_wait(git_process_result *result, git_process *process); - -/** - * Close the input pipe from the child. - * - * @param process the process to close the pipe on - */ -extern int git_process_close_in(git_process *process); - -/** - * Close the output pipe from the child. - * - * @param process the process to close the pipe on - */ -extern int git_process_close_out(git_process *process); - -/** - * Close the error pipe from the child. - * - * @param process the process to close the pipe on - */ -extern int git_process_close_err(git_process *process); - -/** - * Close all resources that are used by the process. This does not - * wait for the process to complete. - * - * @parma process the process to close - */ -extern int git_process_close(git_process *process); - -/** - * Place a human-readable error message in the given git buffer. - * - * @param msg the buffer to store the message - * @param result the process result that produced an error - */ -extern int git_process_result_msg(git_str *msg, git_process_result *result); - -/** - * Free a process structure - * - * @param process the process to free - */ -extern void git_process_free(git_process *process); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/rand.c b/vendor/libgit2-sys/libgit2/src/util/rand.c deleted file mode 100644 index 2b137a5..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/rand.c +++ /dev/null @@ -1,230 +0,0 @@ -/* Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) - -To the extent possible under law, the author has dedicated all copyright -and related and neighboring rights to this software to the public domain -worldwide. This software is distributed without any warranty. - -See . */ - -#include "git2_util.h" -#include "rand.h" -#include "runtime.h" - -#if defined(GIT_WIN32) -# include -#endif - -static uint64_t state[4]; -static git_mutex state_lock; - -typedef union { - double f; - uint64_t d; -} bits; - -#if defined(GIT_WIN32) -GIT_INLINE(int) getseed(uint64_t *seed) -{ - HCRYPTPROV provider; - SYSTEMTIME systemtime; - FILETIME filetime, idletime, kerneltime, usertime; - - if (CryptAcquireContext(&provider, 0, 0, PROV_RSA_FULL, - CRYPT_VERIFYCONTEXT|CRYPT_SILENT)) { - BOOL success = CryptGenRandom(provider, sizeof(uint64_t), (void *)seed); - CryptReleaseContext(provider, 0); - - if (success) - return 0; - } - - GetSystemTime(&systemtime); - if (!SystemTimeToFileTime(&systemtime, &filetime)) { - git_error_set(GIT_ERROR_OS, "could not get time for random seed"); - return -1; - } - - /* Fall-through: generate a seed from the time and system state */ - *seed = 0; - *seed |= ((uint64_t)filetime.dwLowDateTime << 32); - *seed |= ((uint64_t)filetime.dwHighDateTime); - - GetSystemTimes(&idletime, &kerneltime, &usertime); - - *seed ^= ((uint64_t)idletime.dwLowDateTime << 32); - *seed ^= ((uint64_t)kerneltime.dwLowDateTime); - *seed ^= ((uint64_t)usertime.dwLowDateTime << 32); - - *seed ^= ((uint64_t)idletime.dwHighDateTime); - *seed ^= ((uint64_t)kerneltime.dwHighDateTime << 12); - *seed ^= ((uint64_t)usertime.dwHighDateTime << 24); - - *seed ^= ((uint64_t)GetCurrentProcessId() << 32); - *seed ^= ((uint64_t)GetCurrentThreadId() << 48); - - *seed ^= git_time_monotonic(); - - /* Mix in the addresses of some functions and variables */ - *seed ^= (((uint64_t)((uintptr_t)seed) << 32)); - *seed ^= (((uint64_t)((uintptr_t)&errno))); - - return 0; -} - -#else - -GIT_INLINE(int) getseed(uint64_t *seed) -{ - struct timeval tv; - int fd; - -# if defined(GIT_RAND_GETLOADAVG) - double loadavg[3]; - bits convert; -# endif - -# if defined(GIT_RAND_GETENTROPY) - GIT_UNUSED((fd = 0)); - - if (getentropy(seed, sizeof(uint64_t)) == 0) - return 0; -# else - /* - * Try to read from /dev/urandom; most modern systems will have - * this, but we may be chrooted, etc, so it's not a fatal error - */ - if ((fd = open("/dev/urandom", O_RDONLY)) >= 0) { - ssize_t ret = read(fd, seed, sizeof(uint64_t)); - close(fd); - - if (ret == (ssize_t)sizeof(uint64_t)) - return 0; - } -# endif - - /* Fall-through: generate a seed from the time and system state */ - if (gettimeofday(&tv, NULL) < 0) { - git_error_set(GIT_ERROR_OS, "could get time for random seed"); - return -1; - } - - *seed = 0; - *seed |= ((uint64_t)tv.tv_usec << 40); - *seed |= ((uint64_t)tv.tv_sec); - - *seed ^= ((uint64_t)getpid() << 48); - *seed ^= ((uint64_t)getppid() << 32); - *seed ^= ((uint64_t)getpgid(0) << 28); - *seed ^= ((uint64_t)getsid(0) << 16); - *seed ^= ((uint64_t)getuid() << 8); - *seed ^= ((uint64_t)getgid()); - -# if defined(GIT_RAND_GETLOADAVG) - getloadavg(loadavg, 3); - - convert.f = loadavg[0]; *seed ^= (convert.d >> 36); - convert.f = loadavg[1]; *seed ^= (convert.d); - convert.f = loadavg[2]; *seed ^= (convert.d >> 16); -# endif - - *seed ^= git_time_monotonic(); - - /* Mix in the addresses of some variables */ - *seed ^= ((uint64_t)((size_t)((void *)seed)) << 32); - *seed ^= ((uint64_t)((size_t)((void *)&errno))); - - return 0; -} -#endif - -static void git_rand_global_shutdown(void) -{ - git_mutex_free(&state_lock); -} - -int git_rand_global_init(void) -{ - uint64_t seed = 0; - - if (git_mutex_init(&state_lock) < 0 || getseed(&seed) < 0) - return -1; - - if (!seed) { - git_error_set(GIT_ERROR_INTERNAL, "failed to generate random seed"); - return -1; - } - - git_rand_seed(seed); - git_runtime_shutdown_register(git_rand_global_shutdown); - - return 0; -} - -/* - * This is splitmix64. xoroshiro256** uses 256 bit seed; this is used - * to generate 256 bits of seed from the given 64, per the author's - * recommendation. - */ -GIT_INLINE(uint64_t) splitmix64(uint64_t *in) -{ - uint64_t z; - - *in += 0x9e3779b97f4a7c15; - - z = *in; - z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; - z = (z ^ (z >> 27)) * 0x94d049bb133111eb; - return z ^ (z >> 31); -} - -void git_rand_seed(uint64_t seed) -{ - uint64_t mixer; - - mixer = seed; - - git_mutex_lock(&state_lock); - state[0] = splitmix64(&mixer); - state[1] = splitmix64(&mixer); - state[2] = splitmix64(&mixer); - state[3] = splitmix64(&mixer); - git_mutex_unlock(&state_lock); -} - -/* This is xoshiro256** 1.0, one of our all-purpose, rock-solid - generators. It has excellent (sub-ns) speed, a state (256 bits) that is - large enough for any parallel application, and it passes all tests we - are aware of. - - For generating just floating-point numbers, xoshiro256+ is even faster. - - The state must be seeded so that it is not everywhere zero. If you have - a 64-bit seed, we suggest to seed a splitmix64 generator and use its - output to fill s. */ - -GIT_INLINE(uint64_t) rotl(const uint64_t x, int k) { - return (x << k) | (x >> (64 - k)); -} - -uint64_t git_rand_next(void) { - uint64_t t, result; - - git_mutex_lock(&state_lock); - - result = rotl(state[1] * 5, 7) * 9; - - t = state[1] << 17; - - state[2] ^= state[0]; - state[3] ^= state[1]; - state[1] ^= state[2]; - state[0] ^= state[3]; - - state[2] ^= t; - - state[3] = rotl(state[3], 45); - - git_mutex_unlock(&state_lock); - - return result; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/rand.h b/vendor/libgit2-sys/libgit2/src/util/rand.h deleted file mode 100644 index fa0619a..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/rand.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_rand_h__ -#define INCLUDE_rand_h__ - -#include "git2_util.h" - -/** - * Initialize the random number generation subsystem. This will - * seed the random number generator with the system's entropy pool, - * if available, and will fall back to the current time and - * system information if not. - */ -int git_rand_global_init(void); - -/** - * Seed the pseudo-random number generator. This is not needed to be - * called; the PRNG is seeded by `git_rand_global_init`, but it may - * be useful for testing. When the same seed is specified, the same - * sequence of random numbers from `git_rand_next` is emitted. - * - * @param seed the seed to use - */ -void git_rand_seed(uint64_t seed); - -/** - * Get the next pseudo-random number in the sequence. - * - * @return a 64-bit pseudo-random number - */ -uint64_t git_rand_next(void); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/regexp.c b/vendor/libgit2-sys/libgit2/src/util/regexp.c deleted file mode 100644 index ca0d043..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/regexp.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "regexp.h" - -#if defined(GIT_REGEX_PCRE) - -int git_regexp_compile(git_regexp *r, const char *pattern, int flags) -{ - int erroffset, cflags = 0; - const char *error = NULL; - - if (flags & GIT_REGEXP_ICASE) - cflags |= PCRE_CASELESS; - - if ((*r = pcre_compile(pattern, cflags, &error, &erroffset, NULL)) == NULL) { - git_error_set_str(GIT_ERROR_REGEX, error); - return GIT_EINVALIDSPEC; - } - - return 0; -} - -void git_regexp_dispose(git_regexp *r) -{ - pcre_free(*r); - *r = NULL; -} - -int git_regexp_match(const git_regexp *r, const char *string) -{ - int error; - if ((error = pcre_exec(*r, NULL, string, (int) strlen(string), 0, 0, NULL, 0)) < 0) - return (error == PCRE_ERROR_NOMATCH) ? GIT_ENOTFOUND : GIT_EINVALIDSPEC; - return 0; -} - -int git_regexp_search(const git_regexp *r, const char *string, size_t nmatches, git_regmatch *matches) -{ - int static_ovec[9] = {0}, *ovec; - int error; - size_t i; - - /* The ovec array always needs to be a multiple of three */ - if (nmatches <= ARRAY_SIZE(static_ovec) / 3) - ovec = static_ovec; - else - ovec = git__calloc(nmatches * 3, sizeof(*ovec)); - GIT_ERROR_CHECK_ALLOC(ovec); - - if ((error = pcre_exec(*r, NULL, string, (int) strlen(string), 0, 0, ovec, (int) nmatches * 3)) < 0) - goto out; - - if (error == 0) - error = (int) nmatches; - - for (i = 0; i < (unsigned int) error; i++) { - matches[i].start = (ovec[i * 2] < 0) ? -1 : ovec[i * 2]; - matches[i].end = (ovec[i * 2 + 1] < 0) ? -1 : ovec[i * 2 + 1]; - } - for (i = (unsigned int) error; i < nmatches; i++) - matches[i].start = matches[i].end = -1; - -out: - if (nmatches > ARRAY_SIZE(static_ovec) / 3) - git__free(ovec); - if (error < 0) - return (error == PCRE_ERROR_NOMATCH) ? GIT_ENOTFOUND : GIT_EINVALIDSPEC; - return 0; -} - -#elif defined(GIT_REGEX_BUILTIN) || defined(GIT_REGEX_PCRE2) - -int git_regexp_compile(git_regexp *r, const char *pattern, int flags) -{ - unsigned char errmsg[1024]; - PCRE2_SIZE erroff; - int error, cflags = 0; - - if (flags & GIT_REGEXP_ICASE) - cflags |= PCRE2_CASELESS; - - if ((*r = pcre2_compile((const unsigned char *) pattern, - PCRE2_ZERO_TERMINATED, - cflags, &error, &erroff, NULL)) == NULL) { - pcre2_get_error_message(error, errmsg, sizeof(errmsg)); - git_error_set_str(GIT_ERROR_REGEX, (char *) errmsg); - return GIT_EINVALIDSPEC; - } - - return 0; -} - -void git_regexp_dispose(git_regexp *r) -{ - pcre2_code_free(*r); - *r = NULL; -} - -int git_regexp_match(const git_regexp *r, const char *string) -{ - pcre2_match_data *data; - int error; - - data = pcre2_match_data_create(1, NULL); - GIT_ERROR_CHECK_ALLOC(data); - - error = pcre2_match(*r, (const unsigned char *) string, strlen(string), 0, 0, data, NULL); - pcre2_match_data_free(data); - - if (error < 0) - return (error == PCRE2_ERROR_NOMATCH) ? GIT_ENOTFOUND : GIT_EINVALIDSPEC; - - return 0; -} - -int git_regexp_search( - const git_regexp *r, - const char *string, - size_t given_nmatches, - git_regmatch *matches) -{ - pcre2_match_data *data = NULL; - PCRE2_SIZE *ovec; - size_t i, captures; - uint32_t nmatches; - int error; - - GIT_ASSERT(given_nmatches <= UINT32_MAX); - - nmatches = (uint32_t) given_nmatches; - - if ((data = pcre2_match_data_create(nmatches, NULL)) == NULL) { - git_error_set_oom(); - return -1; - } - - if ((error = pcre2_match(*r, (const unsigned char *) string, - strlen(string), 0, 0, data, NULL)) < 0) - goto out; - - captures = (size_t) error; - - if (!captures || captures > nmatches) - captures = nmatches; - - ovec = pcre2_get_ovector_pointer(data); - - for (i = 0; i < captures; i++) { - matches[i].start = (ovec[i * 2] == PCRE2_UNSET) ? -1 : (ssize_t) ovec[i * 2]; - matches[i].end = (ovec[i * 2 + 1] == PCRE2_UNSET) ? -1 : (ssize_t) ovec[i * 2 + 1]; - } - - for (i = captures; i < nmatches; i++) - matches[i].start = matches[i].end = -1; - -out: - pcre2_match_data_free(data); - if (error < 0) - return (error == PCRE2_ERROR_NOMATCH) ? GIT_ENOTFOUND : GIT_EINVALIDSPEC; - return 0; -} - -#elif defined(GIT_REGEX_REGCOMP) || defined(GIT_REGEX_REGCOMP_L) - -#if defined(GIT_REGEX_REGCOMP_L) -# include -#endif - -int git_regexp_compile(git_regexp *r, const char *pattern, int flags) -{ - int cflags = REG_EXTENDED, error; - char errmsg[1024]; - - if (flags & GIT_REGEXP_ICASE) - cflags |= REG_ICASE; - -# if defined(GIT_REGEX_REGCOMP) - if ((error = regcomp(r, pattern, cflags)) != 0) -# else - if ((error = regcomp_l(r, pattern, cflags, (locale_t) 0)) != 0) -# endif - { - regerror(error, r, errmsg, sizeof(errmsg)); - git_error_set_str(GIT_ERROR_REGEX, errmsg); - return GIT_EINVALIDSPEC; - } - - return 0; -} - -void git_regexp_dispose(git_regexp *r) -{ - regfree(r); -} - -int git_regexp_match(const git_regexp *r, const char *string) -{ - int error; - if ((error = regexec(r, string, 0, NULL, 0)) != 0) - return (error == REG_NOMATCH) ? GIT_ENOTFOUND : GIT_EINVALIDSPEC; - return 0; -} - -int git_regexp_search(const git_regexp *r, const char *string, size_t nmatches, git_regmatch *matches) -{ - regmatch_t static_m[3], *m; - int error; - size_t i; - - if (nmatches <= ARRAY_SIZE(static_m)) - m = static_m; - else - m = git__calloc(nmatches, sizeof(*m)); - - if ((error = regexec(r, string, nmatches, m, 0)) != 0) - goto out; - - for (i = 0; i < nmatches; i++) { - matches[i].start = (m[i].rm_so < 0) ? -1 : m[i].rm_so; - matches[i].end = (m[i].rm_eo < 0) ? -1 : m[i].rm_eo; - } - -out: - if (nmatches > ARRAY_SIZE(static_m)) - git__free(m); - if (error) - return (error == REG_NOMATCH) ? GIT_ENOTFOUND : GIT_EINVALIDSPEC; - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/regexp.h b/vendor/libgit2-sys/libgit2/src/util/regexp.h deleted file mode 100644 index aa9aae2..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/regexp.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_regexp_h__ -#define INCLUDE_regexp_h__ - -#include "git2_util.h" - -#if defined(GIT_REGEX_BUILTIN) -# define PCRE2_CODE_UNIT_WIDTH 8 -# include "pcre2.h" -typedef pcre2_code *git_regexp; -# define GIT_REGEX_INIT NULL -#elif defined(GIT_REGEX_PCRE) -# include -typedef pcre *git_regexp; -# define GIT_REGEX_INIT NULL -#elif defined(GIT_REGEX_PCRE2) -# define PCRE2_CODE_UNIT_WIDTH 8 -# include -typedef pcre2_code *git_regexp; -# define GIT_REGEX_INIT NULL -#elif defined(GIT_REGEX_REGCOMP) || defined(GIT_REGEX_REGCOMP_L) -# include -typedef regex_t git_regexp; -# define GIT_REGEX_INIT { 0 } -#else -# error "No regex backend" -#endif - -/** Options supported by @git_regexp_compile. */ -typedef enum { - /** Enable case-insensitive matching */ - GIT_REGEXP_ICASE = (1 << 0) -} git_regexp_flags_t; - -/** Structure containing information about regular expression matching groups */ -typedef struct { - /** Start of the given match. -1 if the group didn't match anything */ - ssize_t start; - /** End of the given match. -1 if the group didn't match anything */ - ssize_t end; -} git_regmatch; - -/** - * Compile a regular expression. The compiled expression needs to - * be cleaned up afterwards with `git_regexp_dispose`. - * - * @param r Pointer to the storage where to initialize the regular expression. - * @param pattern The pattern that shall be compiled. - * @param flags Flags to alter how the pattern shall be handled. - * 0 for defaults, otherwise see @git_regexp_flags_t. - * @return 0 on success, otherwise a negative return value. - */ -int git_regexp_compile(git_regexp *r, const char *pattern, int flags); - -/** - * Free memory associated with the regular expression - * - * @param r The regular expression structure to dispose. - */ -void git_regexp_dispose(git_regexp *r); - -/** - * Test whether a given string matches a compiled regular - * expression. - * - * @param r Compiled regular expression. - * @param string String to match against the regular expression. - * @return 0 if the string matches, a negative error code - * otherwise. GIT_ENOTFOUND if no match was found, - * GIT_EINVALIDSPEC if the regular expression matching - * was invalid. - */ -int git_regexp_match(const git_regexp *r, const char *string); - -/** - * Search for matches inside of a given string. - * - * Given a regular expression with capturing groups, this - * function will populate provided @git_regmatch structures with - * offsets for each of the given matches. Non-matching groups - * will have start and end values of the respective @git_regmatch - * structure set to -1. - * - * @param r Compiled regular expression. - * @param string String to match against the regular expression. - * @param nmatches Number of @git_regmatch structures provided by - * the user. - * @param matches Pointer to an array of @git_regmatch structures. - * @return 0 if the string matches, a negative error code - * otherwise. GIT_ENOTFOUND if no match was found, - * GIT_EINVALIDSPEC if the regular expression matching - * was invalid. - */ -int git_regexp_search(const git_regexp *r, const char *string, size_t nmatches, git_regmatch *matches); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/runtime.c b/vendor/libgit2-sys/libgit2/src/util/runtime.c deleted file mode 100644 index ff3037b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/runtime.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" -#include "runtime.h" - -static git_runtime_shutdown_fn shutdown_callback[32]; -static git_atomic32 shutdown_callback_count; - -static git_atomic32 init_count; - -static int init_common(git_runtime_init_fn init_fns[], size_t cnt) -{ - size_t i; - int ret = 0; - - /* Initialize subsystems that have global state */ - for (i = 0; i < cnt; i++) { - if ((ret = init_fns[i]()) != 0) - break; - } - - GIT_MEMORY_BARRIER; - - return ret; -} - -static void shutdown_common(void) -{ - git_runtime_shutdown_fn cb; - int pos; - - for (pos = git_atomic32_get(&shutdown_callback_count); - pos > 0; - pos = git_atomic32_dec(&shutdown_callback_count)) { - cb = git_atomic_swap(shutdown_callback[pos - 1], NULL); - - if (cb != NULL) - cb(); - } -} - -int git_runtime_shutdown_register(git_runtime_shutdown_fn callback) -{ - int count = git_atomic32_inc(&shutdown_callback_count); - - if (count > (int)ARRAY_SIZE(shutdown_callback) || count == 0) { - git_error_set(GIT_ERROR_INVALID, - "too many shutdown callbacks registered"); - git_atomic32_dec(&shutdown_callback_count); - return -1; - } - - shutdown_callback[count - 1] = callback; - - return 0; -} - -#if defined(GIT_THREADS) && defined(GIT_WIN32) - -/* - * On Win32, we use a spinlock to provide locking semantics. This is - * lighter-weight than a proper critical section. - */ -static volatile LONG init_spinlock = 0; - -GIT_INLINE(int) init_lock(void) -{ - while (InterlockedCompareExchange(&init_spinlock, 1, 0)) { Sleep(0); } - return 0; -} - -GIT_INLINE(int) init_unlock(void) -{ - InterlockedExchange(&init_spinlock, 0); - return 0; -} - -#elif defined(GIT_THREADS) && defined(_POSIX_THREADS) - -/* - * On POSIX, we need to use a proper mutex for locking. We might prefer - * a spinlock here, too, but there's no static initializer for a - * pthread_spinlock_t. - */ -static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; - -GIT_INLINE(int) init_lock(void) -{ - return pthread_mutex_lock(&init_mutex) == 0 ? 0 : -1; -} - -GIT_INLINE(int) init_unlock(void) -{ - return pthread_mutex_unlock(&init_mutex) == 0 ? 0 : -1; -} - -#elif defined(GIT_THREADS) -# error unknown threading model -#else - -# define init_lock() git__noop() -# define init_unlock() git__noop() - -#endif - -int git_runtime_init(git_runtime_init_fn init_fns[], size_t cnt) -{ - int ret = 0; - - if (init_lock() < 0) - return -1; - - /* Only do work on a 0 -> 1 transition of the refcount */ - if ((ret = git_atomic32_inc(&init_count)) == 1) { - if (init_common(init_fns, cnt) < 0) - ret = -1; - } - - if (init_unlock() < 0) - return -1; - - return ret; -} - -int git_runtime_init_count(void) -{ - int ret; - - if (init_lock() < 0) - return -1; - - ret = git_atomic32_get(&init_count); - - if (init_unlock() < 0) - return -1; - - return ret; -} - -int git_runtime_shutdown(void) -{ - int ret; - - /* Enter the lock */ - if (init_lock() < 0) - return -1; - - /* Only do work on a 1 -> 0 transition of the refcount */ - if ((ret = git_atomic32_dec(&init_count)) == 0) - shutdown_common(); - - /* Exit the lock */ - if (init_unlock() < 0) - return -1; - - return ret; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/runtime.h b/vendor/libgit2-sys/libgit2/src/util/runtime.h deleted file mode 100644 index 6cbfd60..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/runtime.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_runtime_h__ -#define INCLUDE_runtime_h__ - -#include "git2_util.h" - -typedef int (*git_runtime_init_fn)(void); -typedef void (*git_runtime_shutdown_fn)(void); - -/** - * Start up a new runtime. If this is the first time that this - * function is called within the context of the current library - * or executable, then the given `init_fns` will be invoked. If - * it is not the first time, they will be ignored. - * - * The given initialization functions _may_ register shutdown - * handlers using `git_runtime_shutdown_register` to be notified - * when the runtime is shutdown. - * - * @param init_fns The list of initialization functions to call - * @param cnt The number of init_fns - * @return The number of initializations performed (including this one) or an error - */ -int git_runtime_init(git_runtime_init_fn init_fns[], size_t cnt); - -/* - * Returns the number of initializations active (the number of calls to - * `git_runtime_init` minus the number of calls sto `git_runtime_shutdown`). - * If 0, the runtime is not currently initialized. - * - * @return The number of initializations performed or an error - */ -int git_runtime_init_count(void); - -/** - * Shut down the runtime. If this is the last shutdown call, - * such that there are no remaining `init` calls, then any - * shutdown hooks that have been registered will be invoked. - * - * The number of outstanding initializations will be returned. - * If this number is 0, then the runtime is shutdown. - * - * @return The number of outstanding initializations (after this one) or an error - */ -int git_runtime_shutdown(void); - -/** - * Register a shutdown handler for this runtime. This should be done - * by a function invoked by `git_runtime_init` to ensure that the - * appropriate locks are taken. - * - * @param callback The shutdown handler callback - * @return 0 or an error code - */ -int git_runtime_shutdown_register(git_runtime_shutdown_fn callback); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/sortedcache.c b/vendor/libgit2-sys/libgit2/src/util/sortedcache.c deleted file mode 100644 index 05b9434..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/sortedcache.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "sortedcache.h" -#include "hashmap.h" - -int git_sortedcache_new( - git_sortedcache **out, - size_t item_path_offset, - git_sortedcache_free_item_fn free_item, - void *free_item_payload, - git_vector_cmp item_cmp, - const char *path) -{ - git_sortedcache *sc; - size_t pathlen, alloclen; - - pathlen = path ? strlen(path) : 0; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_sortedcache), pathlen); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); - sc = git__calloc(1, alloclen); - GIT_ERROR_CHECK_ALLOC(sc); - - if (git_pool_init(&sc->pool, 1) < 0 || - git_vector_init(&sc->items, 4, item_cmp) < 0) - goto fail; - - if (git_rwlock_init(&sc->lock)) { - git_error_set(GIT_ERROR_OS, "failed to initialize lock"); - goto fail; - } - - sc->item_path_offset = item_path_offset; - sc->free_item = free_item; - sc->free_item_payload = free_item_payload; - GIT_REFCOUNT_INC(sc); - if (pathlen) - memcpy(sc->path, path, pathlen); - - *out = sc; - return 0; - -fail: - git_vector_dispose(&sc->items); - git_pool_clear(&sc->pool); - git__free(sc); - return -1; -} - -void git_sortedcache_incref(git_sortedcache *sc) -{ - GIT_REFCOUNT_INC(sc); -} - -const char *git_sortedcache_path(git_sortedcache *sc) -{ - return sc->path; -} - -static void sortedcache_clear(git_sortedcache *sc) -{ - git_hashmap_str_clear(&sc->map); - - if (sc->free_item) { - size_t i; - void *item; - - git_vector_foreach(&sc->items, i, item) { - sc->free_item(sc->free_item_payload, item); - } - } - - git_vector_clear(&sc->items); - - git_pool_clear(&sc->pool); -} - -static void sortedcache_free(git_sortedcache *sc) -{ - /* acquire write lock to make sure everyone else is done */ - if (git_sortedcache_wlock(sc) < 0) - return; - - sortedcache_clear(sc); - git_vector_dispose(&sc->items); - git_hashmap_str_dispose(&sc->map); - - git_sortedcache_wunlock(sc); - - git_rwlock_free(&sc->lock); - git__free(sc); -} - -void git_sortedcache_free(git_sortedcache *sc) -{ - if (!sc) - return; - GIT_REFCOUNT_DEC(sc, sortedcache_free); -} - -static int sortedcache_copy_item(void *payload, void *tgt_item, void *src_item) -{ - git_sortedcache *sc = payload; - /* path will already have been copied by upsert */ - memcpy(tgt_item, src_item, sc->item_path_offset); - return 0; -} - -/* copy a sorted cache */ -int git_sortedcache_copy( - git_sortedcache **out, - git_sortedcache *src, - bool lock, - int (*copy_item)(void *payload, void *tgt_item, void *src_item), - void *payload) -{ - int error = 0; - git_sortedcache *tgt; - size_t i; - void *src_item, *tgt_item; - - /* just use memcpy if no special copy fn is passed in */ - if (!copy_item) { - copy_item = sortedcache_copy_item; - payload = src; - } - - if ((error = git_sortedcache_new( - &tgt, src->item_path_offset, - src->free_item, src->free_item_payload, - src->items._cmp, src->path)) < 0) - return error; - - if (lock && git_sortedcache_rlock(src) < 0) { - git_sortedcache_free(tgt); - return -1; - } - - git_vector_foreach(&src->items, i, src_item) { - char *path = ((char *)src_item) + src->item_path_offset; - - if ((error = git_sortedcache_upsert(&tgt_item, tgt, path)) < 0 || - (error = copy_item(payload, tgt_item, src_item)) < 0) - break; - } - - if (lock) - git_sortedcache_runlock(src); - if (error) - git_sortedcache_free(tgt); - - *out = !error ? tgt : NULL; - - return error; -} - -/* lock sortedcache while making modifications */ -int git_sortedcache_wlock(git_sortedcache *sc) -{ - GIT_UNUSED(sc); /* prevent warning when compiled w/o threads */ - - if (git_rwlock_wrlock(&sc->lock) < 0) { - git_error_set(GIT_ERROR_OS, "unable to acquire write lock on cache"); - return -1; - } - return 0; -} - -/* unlock sorted cache when done with modifications */ -void git_sortedcache_wunlock(git_sortedcache *sc) -{ - git_vector_sort(&sc->items); - git_rwlock_wrunlock(&sc->lock); -} - -/* lock sortedcache for read */ -int git_sortedcache_rlock(git_sortedcache *sc) -{ - GIT_UNUSED(sc); /* prevent warning when compiled w/o threads */ - - if (git_rwlock_rdlock(&sc->lock) < 0) { - git_error_set(GIT_ERROR_OS, "unable to acquire read lock on cache"); - return -1; - } - return 0; -} - -/* unlock sorted cache when done reading */ -void git_sortedcache_runlock(git_sortedcache *sc) -{ - GIT_UNUSED(sc); /* prevent warning when compiled w/o threads */ - git_rwlock_rdunlock(&sc->lock); -} - -/* if the file has changed, lock cache and load file contents into buf; - * returns <0 on error, >0 if file has not changed - */ -int git_sortedcache_lockandload(git_sortedcache *sc, git_str *buf) -{ - int error, fd; - struct stat st; - - if ((error = git_sortedcache_wlock(sc)) < 0) - return error; - - if ((error = git_futils_filestamp_check(&sc->stamp, sc->path)) <= 0) - goto unlock; - - if ((fd = git_futils_open_ro(sc->path)) < 0) { - error = fd; - goto unlock; - } - - if (p_fstat(fd, &st) < 0) { - git_error_set(GIT_ERROR_OS, "failed to stat file"); - error = -1; - (void)p_close(fd); - goto unlock; - } - - if (!git__is_sizet(st.st_size)) { - git_error_set(GIT_ERROR_INVALID, "unable to load file larger than size_t"); - error = -1; - (void)p_close(fd); - goto unlock; - } - - if (buf) - error = git_futils_readbuffer_fd(buf, fd, (size_t)st.st_size); - - (void)p_close(fd); - - if (error < 0) - goto unlock; - - return 1; /* return 1 -> file needs reload and was successfully loaded */ - -unlock: - git_sortedcache_wunlock(sc); - return error; -} - -void git_sortedcache_updated(git_sortedcache *sc) -{ - /* update filestamp to latest value */ - git_futils_filestamp_check(&sc->stamp, sc->path); -} - -/* release all items in sorted cache */ -int git_sortedcache_clear(git_sortedcache *sc, bool wlock) -{ - if (wlock && git_sortedcache_wlock(sc) < 0) - return -1; - - sortedcache_clear(sc); - - if (wlock) - git_sortedcache_wunlock(sc); - - return 0; -} - -/* find and/or insert item, returning pointer to item data */ -int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key) -{ - size_t keylen, itemlen; - int error = 0; - char *item_key; - void *item; - - if (git_hashmap_str_get(&item, &sc->map, key) == 0) - goto done; - - keylen = strlen(key); - itemlen = sc->item_path_offset + keylen + 1; - itemlen = (itemlen + 7) & ~7; - - if ((item = git_pool_mallocz(&sc->pool, itemlen)) == NULL) { - /* don't use GIT_ERROR_CHECK_ALLOC b/c of lock */ - error = -1; - goto done; - } - - /* one strange thing is that even if the vector or hash table insert - * fail, there is no way to free the pool item so we just abandon it - */ - - item_key = ((char *)item) + sc->item_path_offset; - memcpy(item_key, key, keylen); - - if ((error = git_hashmap_str_put(&sc->map, item_key, item)) < 0) - goto done; - - if ((error = git_vector_insert(&sc->items, item)) < 0) - git_hashmap_str_remove(&sc->map, item_key); - -done: - if (out) - *out = !error ? item : NULL; - return error; -} - -/* lookup item by key */ -void *git_sortedcache_lookup(git_sortedcache *sc, const char *key) -{ - void *value; - - return git_hashmap_str_get(&value, &sc->map, key) == 0 ? value : NULL; -} - -/* find out how many items are in the cache */ -size_t git_sortedcache_entrycount(const git_sortedcache *sc) -{ - return git_vector_length(&sc->items); -} - -/* lookup item by index */ -void *git_sortedcache_entry(git_sortedcache *sc, size_t pos) -{ - /* make sure the items are sorted so this gets the correct item */ - if (!git_vector_is_sorted(&sc->items)) - git_vector_sort(&sc->items); - - return git_vector_get(&sc->items, pos); -} - -/* helper struct so bsearch callback can know offset + key value for cmp */ -struct sortedcache_magic_key { - size_t offset; - const char *key; -}; - -static int sortedcache_magic_cmp(const void *key, const void *value) -{ - const struct sortedcache_magic_key *magic = key; - const char *value_key = ((const char *)value) + magic->offset; - return strcmp(magic->key, value_key); -} - -/* lookup index of item by key */ -int git_sortedcache_lookup_index( - size_t *out, git_sortedcache *sc, const char *key) -{ - struct sortedcache_magic_key magic; - - magic.offset = sc->item_path_offset; - magic.key = key; - - return git_vector_bsearch2(out, &sc->items, sortedcache_magic_cmp, &magic); -} - -/* remove entry from cache */ -int git_sortedcache_remove(git_sortedcache *sc, size_t pos) -{ - char *item; - - /* - * Because of pool allocation, this can't actually remove the item, - * but we can remove it from the items vector and the hash table. - */ - - if ((item = git_vector_get(&sc->items, pos)) == NULL) { - git_error_set(GIT_ERROR_INVALID, "removing item out of range"); - return GIT_ENOTFOUND; - } - - (void)git_vector_remove(&sc->items, pos); - - git_hashmap_str_remove(&sc->map, item + sc->item_path_offset); - - if (sc->free_item) - sc->free_item(sc->free_item_payload, item); - - return 0; -} - diff --git a/vendor/libgit2-sys/libgit2/src/util/sortedcache.h b/vendor/libgit2-sys/libgit2/src/util/sortedcache.h deleted file mode 100644 index d4383e9..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/sortedcache.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_sorted_cache_h__ -#define INCLUDE_sorted_cache_h__ - -#include "git2_util.h" - -#include "util.h" -#include "futils.h" -#include "vector.h" -#include "thread.h" -#include "pool.h" -#include "hashmap_str.h" - -#include - -/* - * The purpose of this data structure is to cache the parsed contents of a - * file (a.k.a. the backing file) where each item in the file can be - * identified by a key string and you want to both look them up by name - * and traverse them in sorted order. Each item is assumed to itself end - * in a GIT_FLEX_ARRAY. - */ - -typedef void (*git_sortedcache_free_item_fn)(void *payload, void *item); - -typedef struct { - git_refcount rc; - git_rwlock lock; - size_t item_path_offset; - git_sortedcache_free_item_fn free_item; - void *free_item_payload; - git_pool pool; - git_vector items; - git_hashmap_str map; - git_futils_filestamp stamp; - char path[GIT_FLEX_ARRAY]; -} git_sortedcache; - -/* Create a new sortedcache - * - * Even though every sortedcache stores items with a GIT_FLEX_ARRAY at - * the end containing their key string, you have to provide the item_cmp - * sorting function because the sorting function doesn't get a payload - * and therefore can't know the offset to the item key string. :-( - * - * @param out The allocated git_sortedcache - * @param item_path_offset Offset to the GIT_FLEX_ARRAY item key in the - * struct - use offsetof(struct mine, key-field) to get this - * @param free_item Optional callback to free each item - * @param free_item_payload Optional payload passed to free_item callback - * @param item_cmp Compare the keys of two items - * @param path The path to the backing store file for this cache; this - * may be NULL. The cache makes it easy to load this and check - * if it has been modified since the last load and/or write. - */ -GIT_WARN_UNUSED_RESULT int git_sortedcache_new( - git_sortedcache **out, - size_t item_path_offset, /* use offsetof(struct, path-field) macro */ - git_sortedcache_free_item_fn free_item, - void *free_item_payload, - git_vector_cmp item_cmp, - const char *path); - -/* Copy a sorted cache - * - * - `copy_item` can be NULL to just use memcpy - * - if `lock`, grabs read lock on `src` during copy and releases after - */ -GIT_WARN_UNUSED_RESULT int git_sortedcache_copy( - git_sortedcache **out, - git_sortedcache *src, - bool lock, - int (*copy_item)(void *payload, void *tgt_item, void *src_item), - void *payload); - -/* Free sorted cache (first calling `free_item` callbacks) - * - * Don't call on a locked collection - it may acquire a write lock - */ -void git_sortedcache_free(git_sortedcache *sc); - -/* Increment reference count - balance with call to free */ -void git_sortedcache_incref(git_sortedcache *sc); - -/* Get the pathname associated with this cache at creation time */ -const char *git_sortedcache_path(git_sortedcache *sc); - -/* - * CACHE WRITE FUNCTIONS - * - * The following functions require you to have a writer lock to make the - * modification. Some of the functions take a `wlock` parameter and - * will optionally lock and unlock for you if that is passed as true. - * - */ - -/* Lock sortedcache for write */ -GIT_WARN_UNUSED_RESULT int git_sortedcache_wlock(git_sortedcache *sc); - -/* Unlock sorted cache when done with write */ -void git_sortedcache_wunlock(git_sortedcache *sc); - -/* Lock cache and load backing file into a buffer. - * - * This grabs a write lock on the cache then looks at the modification - * time and size of the file on disk. - * - * If the file appears to have changed, this loads the file contents into - * the buffer and returns a positive value leaving the cache locked - the - * caller should parse the file content, update the cache as needed, then - * release the lock. NOTE: In this case, the caller MUST unlock the cache. - * - * If the file appears to be unchanged, then this automatically releases - * the lock on the cache, clears the buffer, and returns 0. - * - * @return 0 if up-to-date, 1 if out-of-date, <0 on error - */ -GIT_WARN_UNUSED_RESULT int git_sortedcache_lockandload( - git_sortedcache *sc, git_str *buf); - -/* Refresh file timestamp after write completes - * You should already be holding the write lock when you call this. - */ -void git_sortedcache_updated(git_sortedcache *sc); - -/* Release all items in sorted cache - * - * If `wlock` is true, grabs write lock and releases when done, otherwise - * you should already be holding a write lock when you call this. - */ -GIT_WARN_UNUSED_RESULT int git_sortedcache_clear( - git_sortedcache *sc, bool wlock); - -/* Find and/or insert item, returning pointer to item data. - * You should already be holding the write lock when you call this. - */ -GIT_WARN_UNUSED_RESULT int git_sortedcache_upsert( - void **out, git_sortedcache *sc, const char *key); - -/* Removes entry at pos from cache - * You should already be holding the write lock when you call this. - */ -int git_sortedcache_remove(git_sortedcache *sc, size_t pos); - -/* - * CACHE READ FUNCTIONS - * - * The following functions access items in the cache. To prevent the - * results from being invalidated before they can be used, you should be - * holding either a read lock or a write lock when using these functions. - * - */ - -/* Lock sortedcache for read */ -GIT_WARN_UNUSED_RESULT int git_sortedcache_rlock(git_sortedcache *sc); - -/* Unlock sorted cache when done with read */ -void git_sortedcache_runlock(git_sortedcache *sc); - -/* Lookup item by key - returns NULL if not found */ -void *git_sortedcache_lookup(git_sortedcache *sc, const char *key); - -/* Get how many items are in the cache - * - * You can call this function without holding a lock, but be aware - * that it may change before you use it. - */ -size_t git_sortedcache_entrycount(const git_sortedcache *sc); - -/* Lookup item by index - returns NULL if out of range */ -void *git_sortedcache_entry(git_sortedcache *sc, size_t pos); - -/* Lookup index of item by key - returns GIT_ENOTFOUND if not found */ -int git_sortedcache_lookup_index( - size_t *out, git_sortedcache *sc, const char *key); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/staticstr.h b/vendor/libgit2-sys/libgit2/src/util/staticstr.h deleted file mode 100644 index b7d0790..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/staticstr.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_stackstr_h__ -#define INCLUDE_stackstr_h__ - -#include "git2_util.h" - -typedef struct { - /* Length of / number of bytes used by `data`. */ - size_t len; - - /* Size of the allocated `data` buffer. */ - size_t size; - - /* The actual string buffer data. */ - char data[GIT_FLEX_ARRAY]; -} git_staticstr; - -#define git_staticstr_with_size(__size) \ - struct { \ - size_t len; \ - size_t size; \ - char data[__size]; \ - } - -#define git_staticstr_init(__str, __size) \ - do { \ - (__str)->len = 0; \ - (__str)->size = __size; \ - (__str)->data[0] = '\0'; \ - } while(0) - -#define git_staticstr_offset(__str) \ - ((__str)->data + (__str)->len) - -#define git_staticstr_remain(__str) \ - ((__str)->len > (__str)->size ? 0 : ((__str)->size - (__str)->len)) - -#define git_staticstr_increase(__str, __len) \ - do { ((__str)->len += __len); } while(0) - -#define git_staticstr_consume_bytes(__str, __len) \ - do { git_staticstr_consume(__str, (__str)->data + __len); } while(0) - -#define git_staticstr_consume(__str, __end) \ - do { \ - if (__end > (__str)->data && \ - __end <= (__str)->data + (__str)->len) { \ - size_t __consumed = __end - (__str)->data; \ - memmove((__str)->data, __end, (__str)->len - __consumed); \ - (__str)->len -= __consumed; \ - (__str)->data[(__str)->len] = '\0'; \ - } \ - } while(0) - -#define git_staticstr_clear(__str) \ - do { \ - (__str)->len = 0; \ - (__str)->data[0] = 0; \ - } while(0) - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/str.c b/vendor/libgit2-sys/libgit2/src/util/str.c deleted file mode 100644 index 7b8d99b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/str.c +++ /dev/null @@ -1,1384 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "str.h" -#include "posix.h" -#include - -/* Used as default value for git_str->ptr so that people can always - * assume ptr is non-NULL and zero terminated even for new git_strs. - */ -char git_str__initstr[1]; - -char git_str__oom[1]; - -#define ENSURE_SIZE(b, d) \ - if ((b)->ptr == git_str__oom || \ - ((d) > (b)->asize && git_str_grow((b), (d)) < 0))\ - return -1; - - -int git_str_init(git_str *buf, size_t initial_size) -{ - buf->asize = 0; - buf->size = 0; - buf->ptr = git_str__initstr; - - ENSURE_SIZE(buf, initial_size); - - return 0; -} - -int git_str_try_grow( - git_str *buf, size_t target_size, bool mark_oom) -{ - char *new_ptr; - size_t new_size; - - if (buf->ptr == git_str__oom) - return -1; - - if (buf->asize == 0 && buf->size != 0) { - git_error_set(GIT_ERROR_INVALID, "cannot grow a borrowed buffer"); - return GIT_EINVALID; - } - - if (!target_size) - target_size = buf->size; - - if (target_size <= buf->asize) - return 0; - - if (buf->asize == 0) { - new_size = target_size; - new_ptr = NULL; - } else { - new_size = buf->asize; - /* - * Grow the allocated buffer by 1.5 to allow - * re-use of memory holes resulting from the - * realloc. If this is still too small, then just - * use the target size. - */ - if ((new_size = (new_size << 1) - (new_size >> 1)) < target_size) - new_size = target_size; - new_ptr = buf->ptr; - } - - /* round allocation up to multiple of 8 */ - new_size = (new_size + 7) & ~7; - - if (new_size < buf->size) { - if (mark_oom) { - if (buf->ptr && buf->ptr != git_str__initstr) - git__free(buf->ptr); - buf->ptr = git_str__oom; - } - - git_error_set_oom(); - return -1; - } - - new_ptr = git__realloc(new_ptr, new_size); - - if (!new_ptr) { - if (mark_oom) { - if (buf->ptr && (buf->ptr != git_str__initstr)) - git__free(buf->ptr); - buf->ptr = git_str__oom; - } - return -1; - } - - buf->asize = new_size; - buf->ptr = new_ptr; - - /* truncate the existing buffer size if necessary */ - if (buf->size >= buf->asize) - buf->size = buf->asize - 1; - buf->ptr[buf->size] = '\0'; - - return 0; -} - -int git_str_grow(git_str *buffer, size_t target_size) -{ - return git_str_try_grow(buffer, target_size, true); -} - -int git_str_grow_by(git_str *buffer, size_t additional_size) -{ - size_t newsize; - - if (GIT_ADD_SIZET_OVERFLOW(&newsize, buffer->size, additional_size)) { - buffer->ptr = git_str__oom; - return -1; - } - - return git_str_try_grow(buffer, newsize, true); -} - -void git_str_dispose(git_str *buf) -{ - if (!buf) return; - - if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_str__oom) - git__free(buf->ptr); - - git_str_init(buf, 0); -} - -void git_str_clear(git_str *buf) -{ - buf->size = 0; - - if (!buf->ptr) { - buf->ptr = git_str__initstr; - buf->asize = 0; - } - - if (buf->asize > 0) - buf->ptr[0] = '\0'; -} - -int git_str_set(git_str *buf, const void *data, size_t len) -{ - size_t alloclen; - - if (len == 0 || data == NULL) { - git_str_clear(buf); - } else { - if (data != buf->ptr) { - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1); - ENSURE_SIZE(buf, alloclen); - memmove(buf->ptr, data, len); - } - - buf->size = len; - if (buf->asize > buf->size) - buf->ptr[buf->size] = '\0'; - - } - return 0; -} - -int git_str_sets(git_str *buf, const char *string) -{ - return git_str_set(buf, string, string ? strlen(string) : 0); -} - -int git_str_putc(git_str *buf, char c) -{ - size_t new_size; - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2); - ENSURE_SIZE(buf, new_size); - buf->ptr[buf->size++] = c; - buf->ptr[buf->size] = '\0'; - return 0; -} - -int git_str_putcn(git_str *buf, char c, size_t len) -{ - size_t new_size; - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); - ENSURE_SIZE(buf, new_size); - memset(buf->ptr + buf->size, c, len); - buf->size += len; - buf->ptr[buf->size] = '\0'; - return 0; -} - -int git_str_put(git_str *buf, const char *data, size_t len) -{ - if (len) { - size_t new_size; - - GIT_ASSERT_ARG(data); - - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); - ENSURE_SIZE(buf, new_size); - memmove(buf->ptr + buf->size, data, len); - buf->size += len; - buf->ptr[buf->size] = '\0'; - } - return 0; -} - -int git_str_puts(git_str *buf, const char *string) -{ - GIT_ASSERT_ARG(string); - - return git_str_put(buf, string, strlen(string)); -} - -static char hex_encode[] = "0123456789abcdef"; - -int git_str_encode_hexstr(git_str *str, const char *data, size_t len) -{ - size_t new_size, i; - char *s; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&new_size, len, 2); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); - - if (git_str_grow_by(str, new_size) < 0) - return -1; - - s = str->ptr + str->size; - - for (i = 0; i < len; i++) { - *s++ = hex_encode[(data[i] & 0xf0) >> 4]; - *s++ = hex_encode[(data[i] & 0x0f)]; - } - - str->size += (len * 2); - str->ptr[str->size] = '\0'; - - return 0; -} - -static const char base64_encode[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -int git_str_encode_base64(git_str *buf, const char *data, size_t len) -{ - size_t extra = len % 3; - uint8_t *write, a, b, c; - const uint8_t *read = (const uint8_t *)data; - size_t blocks = (len / 3) + !!extra, alloclen; - - GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1); - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size); - - ENSURE_SIZE(buf, alloclen); - write = (uint8_t *)&buf->ptr[buf->size]; - - /* convert each run of 3 bytes into 4 output bytes */ - for (len -= extra; len > 0; len -= 3) { - a = *read++; - b = *read++; - c = *read++; - - *write++ = base64_encode[a >> 2]; - *write++ = base64_encode[(a & 0x03) << 4 | b >> 4]; - *write++ = base64_encode[(b & 0x0f) << 2 | c >> 6]; - *write++ = base64_encode[c & 0x3f]; - } - - if (extra > 0) { - a = *read++; - b = (extra > 1) ? *read++ : 0; - - *write++ = base64_encode[a >> 2]; - *write++ = base64_encode[(a & 0x03) << 4 | b >> 4]; - *write++ = (extra > 1) ? base64_encode[(b & 0x0f) << 2] : '='; - *write++ = '='; - } - - buf->size = ((char *)write) - buf->ptr; - buf->ptr[buf->size] = '\0'; - - return 0; -} - -/* The inverse of base64_encode */ -static const int8_t base64_decode[] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 -}; - -int git_str_decode_base64(git_str *buf, const char *base64, size_t len) -{ - size_t i; - int8_t a, b, c, d; - size_t orig_size = buf->size, new_size; - - if (len % 4) { - git_error_set(GIT_ERROR_INVALID, "invalid base64 input"); - return -1; - } - - GIT_ASSERT_ARG(len % 4 == 0); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (len / 4 * 3), buf->size); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); - ENSURE_SIZE(buf, new_size); - - for (i = 0; i < len; i += 4) { - if ((a = base64_decode[(unsigned char)base64[i]]) < 0 || - (b = base64_decode[(unsigned char)base64[i+1]]) < 0 || - (c = base64_decode[(unsigned char)base64[i+2]]) < 0 || - (d = base64_decode[(unsigned char)base64[i+3]]) < 0) { - buf->size = orig_size; - buf->ptr[buf->size] = '\0'; - - git_error_set(GIT_ERROR_INVALID, "invalid base64 input"); - return -1; - } - - buf->ptr[buf->size++] = ((a << 2) | (b & 0x30) >> 4); - buf->ptr[buf->size++] = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2); - buf->ptr[buf->size++] = (c & 0x03) << 6 | (d & 0x3f); - } - - buf->ptr[buf->size] = '\0'; - return 0; -} - -static const char base85_encode[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"; - -int git_str_encode_base85(git_str *buf, const char *data, size_t len) -{ - size_t blocks = (len / 4) + !!(len % 4), alloclen; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); - - ENSURE_SIZE(buf, alloclen); - - while (len) { - uint32_t acc = 0; - char b85[5]; - int i; - - for (i = 24; i >= 0; i -= 8) { - uint8_t ch = *data++; - acc |= (uint32_t)ch << i; - - if (--len == 0) - break; - } - - for (i = 4; i >= 0; i--) { - int val = acc % 85; - acc /= 85; - - b85[i] = base85_encode[val]; - } - - for (i = 0; i < 5; i++) - buf->ptr[buf->size++] = b85[i]; - } - - buf->ptr[buf->size] = '\0'; - - return 0; -} - -/* The inverse of base85_encode */ -static const int8_t base85_decode[] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 63, -1, 64, 65, 66, 67, -1, 68, 69, 70, 71, -1, 72, -1, -1, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 73, 74, 75, 76, 77, - 78, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, -1, -1, 79, 80, - 81, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 82, 83, 84, 85, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 -}; - -int git_str_decode_base85( - git_str *buf, - const char *base85, - size_t base85_len, - size_t output_len) -{ - size_t orig_size = buf->size, new_size; - - if (base85_len % 5 || - output_len > base85_len * 4 / 5) { - git_error_set(GIT_ERROR_INVALID, "invalid base85 input"); - return -1; - } - - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, output_len, buf->size); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); - ENSURE_SIZE(buf, new_size); - - while (output_len) { - unsigned acc = 0; - int de, cnt = 4; - unsigned char ch; - do { - ch = *base85++; - de = base85_decode[ch]; - if (--de < 0) - goto on_error; - - acc = acc * 85 + de; - } while (--cnt); - ch = *base85++; - de = base85_decode[ch]; - if (--de < 0) - goto on_error; - - /* Detect overflow. */ - if (0xffffffff / 85 < acc || - 0xffffffff - de < (acc *= 85)) - goto on_error; - - acc += de; - - cnt = (output_len < 4) ? (int)output_len : 4; - output_len -= cnt; - do { - acc = (acc << 8) | (acc >> 24); - buf->ptr[buf->size++] = acc; - } while (--cnt); - } - - buf->ptr[buf->size] = 0; - - return 0; - -on_error: - buf->size = orig_size; - buf->ptr[buf->size] = '\0'; - - git_error_set(GIT_ERROR_INVALID, "invalid base85 input"); - return -1; -} - -#define HEX_DECODE(c) ((c | 32) % 39 - 9) - -int git_str_decode_percent( - git_str *buf, - const char *str, - size_t str_len) -{ - size_t str_pos, new_size; - - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, str_len); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); - ENSURE_SIZE(buf, new_size); - - for (str_pos = 0; str_pos < str_len; buf->size++, str_pos++) { - if (str[str_pos] == '%' && - str_len > str_pos + 2 && - git__isxdigit(str[str_pos + 1]) && - git__isxdigit(str[str_pos + 2])) { - buf->ptr[buf->size] = (HEX_DECODE(str[str_pos + 1]) << 4) + - HEX_DECODE(str[str_pos + 2]); - str_pos += 2; - } else { - buf->ptr[buf->size] = str[str_pos]; - } - } - - buf->ptr[buf->size] = '\0'; - return 0; -} - -int git_str_vprintf(git_str *buf, const char *format, va_list ap) -{ - size_t expected_size, new_size; - int len; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2); - GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size); - ENSURE_SIZE(buf, expected_size); - - while (1) { - va_list args; - va_copy(args, ap); - - len = p_vsnprintf( - buf->ptr + buf->size, - buf->asize - buf->size, - format, args - ); - - va_end(args); - - if (len < 0) { - git__free(buf->ptr); - buf->ptr = git_str__oom; - return -1; - } - - if ((size_t)len + 1 <= buf->asize - buf->size) { - buf->size += len; - break; - } - - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); - ENSURE_SIZE(buf, new_size); - } - - return 0; -} - -int git_str_printf(git_str *buf, const char *format, ...) -{ - int r; - va_list ap; - - va_start(ap, format); - r = git_str_vprintf(buf, format, ap); - va_end(ap); - - return r; -} - -int git_str_copy_cstr(char *data, size_t datasize, const git_str *buf) -{ - size_t copylen; - - GIT_ASSERT_ARG(data); - GIT_ASSERT_ARG(datasize); - GIT_ASSERT_ARG(buf); - - data[0] = '\0'; - - if (buf->size == 0 || buf->asize <= 0) - return 0; - - copylen = buf->size; - if (copylen > datasize - 1) - copylen = datasize - 1; - memmove(data, buf->ptr, copylen); - data[copylen] = '\0'; - - return 0; -} - -void git_str_consume_bytes(git_str *buf, size_t len) -{ - git_str_consume(buf, buf->ptr + len); -} - -void git_str_consume(git_str *buf, const char *end) -{ - if (end > buf->ptr && end <= buf->ptr + buf->size) { - size_t consumed = end - buf->ptr; - memmove(buf->ptr, end, buf->size - consumed); - buf->size -= consumed; - buf->ptr[buf->size] = '\0'; - } -} - -void git_str_truncate(git_str *buf, size_t len) -{ - if (len >= buf->size) - return; - - buf->size = len; - if (buf->size < buf->asize) - buf->ptr[buf->size] = '\0'; -} - -void git_str_shorten(git_str *buf, size_t amount) -{ - if (buf->size > amount) - git_str_truncate(buf, buf->size - amount); - else - git_str_clear(buf); -} - -void git_str_truncate_at_char(git_str *buf, char separator) -{ - ssize_t idx = git_str_find(buf, separator); - if (idx >= 0) - git_str_truncate(buf, (size_t)idx); -} - -void git_str_rtruncate_at_char(git_str *buf, char separator) -{ - ssize_t idx = git_str_rfind_next(buf, separator); - git_str_truncate(buf, idx < 0 ? 0 : (size_t)idx); -} - -void git_str_swap(git_str *str_a, git_str *str_b) -{ - git_str t = *str_a; - *str_a = *str_b; - *str_b = t; -} - -char *git_str_detach(git_str *buf) -{ - char *data = buf->ptr; - - if (buf->asize == 0 || buf->ptr == git_str__oom) - return NULL; - - git_str_init(buf, 0); - - return data; -} - -int git_str_attach(git_str *buf, char *ptr, size_t asize) -{ - git_str_dispose(buf); - - if (ptr) { - buf->ptr = ptr; - buf->size = strlen(ptr); - if (asize) - buf->asize = (asize < buf->size) ? buf->size + 1 : asize; - else /* pass 0 to fall back on strlen + 1 */ - buf->asize = buf->size + 1; - } - - ENSURE_SIZE(buf, asize); - return 0; -} - -void git_str_attach_notowned(git_str *buf, const char *ptr, size_t size) -{ - if (git_str_is_allocated(buf)) - git_str_dispose(buf); - - if (!size) { - git_str_init(buf, 0); - } else { - buf->ptr = (char *)ptr; - buf->asize = 0; - buf->size = size; - } -} - -int git_str_join_n(git_str *buf, char separator, int nbuf, ...) -{ - va_list ap; - int i; - size_t total_size = 0, original_size = buf->size; - char *out, *original = buf->ptr; - - if (buf->size > 0 && buf->ptr[buf->size - 1] != separator) - ++total_size; /* space for initial separator */ - - /* Make two passes to avoid multiple reallocation */ - - va_start(ap, nbuf); - for (i = 0; i < nbuf; ++i) { - const char *segment; - size_t segment_len; - - segment = va_arg(ap, const char *); - if (!segment) - continue; - - segment_len = strlen(segment); - - GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, segment_len); - - if (segment_len == 0 || segment[segment_len - 1] != separator) - GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1); - } - va_end(ap); - - /* expand buffer if needed */ - if (total_size == 0) - return 0; - - GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1); - if (git_str_grow_by(buf, total_size) < 0) - return -1; - - out = buf->ptr + buf->size; - - /* append separator to existing buf if needed */ - if (buf->size > 0 && out[-1] != separator) - *out++ = separator; - - va_start(ap, nbuf); - for (i = 0; i < nbuf; ++i) { - const char *segment; - size_t segment_len; - - segment = va_arg(ap, const char *); - if (!segment) - continue; - - /* deal with join that references buffer's original content */ - if (segment >= original && segment < original + original_size) { - size_t offset = (segment - original); - segment = buf->ptr + offset; - segment_len = original_size - offset; - } else { - segment_len = strlen(segment); - } - - /* skip leading separators */ - if (out > buf->ptr && out[-1] == separator) - while (segment_len > 0 && *segment == separator) { - segment++; - segment_len--; - } - - /* copy over next buffer */ - if (segment_len > 0) { - memmove(out, segment, segment_len); - out += segment_len; - } - - /* append trailing separator (except for last item) */ - if (i < nbuf - 1 && out > buf->ptr && out[-1] != separator) - *out++ = separator; - } - va_end(ap); - - /* set size based on num characters actually written */ - buf->size = out - buf->ptr; - buf->ptr[buf->size] = '\0'; - - return 0; -} - -int git_str_join( - git_str *buf, - char separator, - const char *str_a, - const char *str_b) -{ - size_t strlen_a = str_a ? strlen(str_a) : 0; - size_t strlen_b = strlen(str_b); - size_t alloc_len; - int need_sep = 0; - ssize_t offset_a = -1; - - /* not safe to have str_b point internally to the buffer */ - if (buf->size) - GIT_ASSERT_ARG(str_b < buf->ptr || str_b >= buf->ptr + buf->size); - - /* figure out if we need to insert a separator */ - if (separator && strlen_a) { - while (*str_b == separator) { str_b++; strlen_b--; } - if (str_a[strlen_a - 1] != separator) - need_sep = 1; - } - - /* str_a could be part of the buffer */ - if (buf->size && str_a >= buf->ptr && str_a < buf->ptr + buf->size) - offset_a = str_a - buf->ptr; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); - ENSURE_SIZE(buf, alloc_len); - - /* fix up internal pointers */ - if (offset_a >= 0) - str_a = buf->ptr + offset_a; - - /* do the actual copying */ - if (offset_a != 0 && str_a) - memmove(buf->ptr, str_a, strlen_a); - if (need_sep) - buf->ptr[strlen_a] = separator; - memcpy(buf->ptr + strlen_a + need_sep, str_b, strlen_b); - - buf->size = strlen_a + strlen_b + need_sep; - buf->ptr[buf->size] = '\0'; - - return 0; -} - -int git_str_join3( - git_str *buf, - char separator, - const char *str_a, - const char *str_b, - const char *str_c) -{ - size_t len_a = strlen(str_a), - len_b = strlen(str_b), - len_c = strlen(str_c), - len_total; - int sep_a = 0, sep_b = 0; - char *tgt; - - /* for this function, disallow pointers into the existing buffer */ - GIT_ASSERT(str_a < buf->ptr || str_a >= buf->ptr + buf->size); - GIT_ASSERT(str_b < buf->ptr || str_b >= buf->ptr + buf->size); - GIT_ASSERT(str_c < buf->ptr || str_c >= buf->ptr + buf->size); - - if (separator) { - if (len_a > 0) { - while (*str_b == separator) { str_b++; len_b--; } - sep_a = (str_a[len_a - 1] != separator); - } - if (len_a > 0 || len_b > 0) - while (*str_c == separator) { str_c++; len_c--; } - if (len_b > 0) - sep_b = (str_b[len_b - 1] != separator); - } - - GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_a, sep_a); - GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_b); - GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b); - GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_c); - GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1); - ENSURE_SIZE(buf, len_total); - - tgt = buf->ptr; - - if (len_a) { - memcpy(tgt, str_a, len_a); - tgt += len_a; - } - if (sep_a) - *tgt++ = separator; - if (len_b) { - memcpy(tgt, str_b, len_b); - tgt += len_b; - } - if (sep_b) - *tgt++ = separator; - if (len_c) - memcpy(tgt, str_c, len_c); - - buf->size = len_a + sep_a + len_b + sep_b + len_c; - buf->ptr[buf->size] = '\0'; - - return 0; -} - -void git_str_rtrim(git_str *buf) -{ - while (buf->size > 0) { - if (!git__isspace(buf->ptr[buf->size - 1])) - break; - - buf->size--; - } - - if (buf->asize > buf->size) - buf->ptr[buf->size] = '\0'; -} - -int git_str_cmp(const git_str *a, const git_str *b) -{ - int result = memcmp(a->ptr, b->ptr, min(a->size, b->size)); - return (result != 0) ? result : - (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0; -} - -int git_str_splice( - git_str *buf, - size_t where, - size_t nb_to_remove, - const char *data, - size_t nb_to_insert) -{ - char *splice_loc; - size_t new_size, alloc_size; - - GIT_ASSERT(buf); - GIT_ASSERT(where <= buf->size); - GIT_ASSERT(nb_to_remove <= buf->size - where); - - splice_loc = buf->ptr + where; - - /* Ported from git.git - * https://github.com/git/git/blob/16eed7c/strbuf.c#L159-176 - */ - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (buf->size - nb_to_remove), nb_to_insert); - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1); - ENSURE_SIZE(buf, alloc_size); - - memmove(splice_loc + nb_to_insert, - splice_loc + nb_to_remove, - buf->size - where - nb_to_remove); - - memcpy(splice_loc, data, nb_to_insert); - - buf->size = new_size; - buf->ptr[buf->size] = '\0'; - return 0; -} - -/* Quote per http://marc.info/?l=git&m=112927316408690&w=2 */ -int git_str_quote(git_str *buf) -{ - const char whitespace[] = { 'a', 'b', 't', 'n', 'v', 'f', 'r' }; - git_str quoted = GIT_STR_INIT; - size_t i = 0; - bool quote = false; - int error = 0; - - /* walk to the first char that needs quoting */ - if (buf->size && buf->ptr[0] == '!') - quote = true; - - for (i = 0; !quote && i < buf->size; i++) { - if (buf->ptr[i] == '"' || buf->ptr[i] == '\\' || - buf->ptr[i] < ' ' || buf->ptr[i] > '~') { - quote = true; - break; - } - } - - if (!quote) - goto done; - - git_str_putc("ed, '"'); - git_str_put("ed, buf->ptr, i); - - for (; i < buf->size; i++) { - /* whitespace - use the map above, which is ordered by ascii value */ - if (buf->ptr[i] >= '\a' && buf->ptr[i] <= '\r') { - git_str_putc("ed, '\\'); - git_str_putc("ed, whitespace[buf->ptr[i] - '\a']); - } - - /* double quote and backslash must be escaped */ - else if (buf->ptr[i] == '"' || buf->ptr[i] == '\\') { - git_str_putc("ed, '\\'); - git_str_putc("ed, buf->ptr[i]); - } - - /* escape anything unprintable as octal */ - else if (buf->ptr[i] != ' ' && - (buf->ptr[i] < '!' || buf->ptr[i] > '~')) { - git_str_printf("ed, "\\%03o", (unsigned char)buf->ptr[i]); - } - - /* yay, printable! */ - else { - git_str_putc("ed, buf->ptr[i]); - } - } - - git_str_putc("ed, '"'); - - if (git_str_oom("ed)) { - error = -1; - goto done; - } - - git_str_swap("ed, buf); - -done: - git_str_dispose("ed); - return error; -} - -/* Unquote per http://marc.info/?l=git&m=112927316408690&w=2 */ -int git_str_unquote(git_str *buf) -{ - size_t i, j; - char ch; - - git_str_rtrim(buf); - - if (buf->size < 2 || buf->ptr[0] != '"' || buf->ptr[buf->size-1] != '"') - goto invalid; - - for (i = 0, j = 1; j < buf->size-1; i++, j++) { - ch = buf->ptr[j]; - - if (ch == '\\') { - if (j == buf->size-2) - goto invalid; - - ch = buf->ptr[++j]; - - switch (ch) { - /* \" or \\ simply copy the char in */ - case '"': case '\\': - break; - - /* add the appropriate escaped char */ - case 'a': ch = '\a'; break; - case 'b': ch = '\b'; break; - case 'f': ch = '\f'; break; - case 'n': ch = '\n'; break; - case 'r': ch = '\r'; break; - case 't': ch = '\t'; break; - case 'v': ch = '\v'; break; - - /* \xyz digits convert to the char*/ - case '0': case '1': case '2': case '3': - if (j == buf->size-3) { - git_error_set(GIT_ERROR_INVALID, - "truncated quoted character \\%c", ch); - return -1; - } - - if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' || - buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') { - git_error_set(GIT_ERROR_INVALID, - "truncated quoted character \\%c%c%c", - buf->ptr[j], buf->ptr[j+1], buf->ptr[j+2]); - return -1; - } - - ch = ((buf->ptr[j] - '0') << 6) | - ((buf->ptr[j+1] - '0') << 3) | - (buf->ptr[j+2] - '0'); - j += 2; - break; - - default: - git_error_set(GIT_ERROR_INVALID, "invalid quoted character \\%c", ch); - return -1; - } - } - - buf->ptr[i] = ch; - } - - buf->ptr[i] = '\0'; - buf->size = i; - - return 0; - -invalid: - git_error_set(GIT_ERROR_INVALID, "invalid quoted line"); - return -1; -} - -int git_str_puts_escaped( - git_str *buf, - const char *string, - const char *esc_chars, - const char *esc_prefix, - const char *esc_suffix) -{ - const char *scan; - size_t total = 0, count, alloclen; - size_t esc_prefix_len = esc_prefix ? strlen(esc_prefix) : 0; - size_t esc_suffix_len = esc_suffix ? strlen(esc_suffix) : 0; - - if (!string) - return 0; - - for (scan = string; *scan; ) { - /* count run of non-escaped characters */ - count = strcspn(scan, esc_chars); - total += count; - scan += count; - /* count run of escaped characters */ - count = strspn(scan, esc_chars); - total += count * (esc_prefix_len + esc_suffix_len + 1); - scan += count; - } - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, total, 1); - if (git_str_grow_by(buf, alloclen) < 0) - return -1; - - for (scan = string; *scan; ) { - count = strcspn(scan, esc_chars); - - memmove(buf->ptr + buf->size, scan, count); - scan += count; - buf->size += count; - - for (count = strspn(scan, esc_chars); count > 0; --count) { - /* copy escape prefix sequence */ - if (esc_prefix) { - memmove(buf->ptr + buf->size, esc_prefix, esc_prefix_len); - buf->size += esc_prefix_len; - } - - /* copy character to be escaped */ - buf->ptr[buf->size] = *scan; - buf->size++; - scan++; - - /* copy escape suffix sequence */ - if (esc_suffix) { - memmove(buf->ptr + buf->size, esc_suffix, esc_suffix_len); - buf->size += esc_suffix_len; - } - } - } - - buf->ptr[buf->size] = '\0'; - - return 0; -} - -void git_str_unescape(git_str *buf) -{ - buf->size = git__unescape(buf->ptr); -} - -int git_str_crlf_to_lf(git_str *tgt, const git_str *src) -{ - const char *scan = src->ptr; - const char *scan_end = src->ptr + src->size; - const char *next = memchr(scan, '\r', src->size); - size_t new_size; - char *out; - - GIT_ASSERT(tgt != src); - - if (!next) - return git_str_set(tgt, src->ptr, src->size); - - /* reduce reallocs while in the loop */ - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, src->size, 1); - if (git_str_grow(tgt, new_size) < 0) - return -1; - - out = tgt->ptr; - tgt->size = 0; - - /* Find the next \r and copy whole chunk up to there to tgt */ - for (; next; scan = next + 1, next = memchr(scan, '\r', scan_end - scan)) { - if (next > scan) { - size_t copylen = (size_t)(next - scan); - memcpy(out, scan, copylen); - out += copylen; - } - - /* Do not drop \r unless it is followed by \n */ - if (next + 1 == scan_end || next[1] != '\n') - *out++ = '\r'; - } - - /* Copy remaining input into dest */ - if (scan < scan_end) { - size_t remaining = (size_t)(scan_end - scan); - memcpy(out, scan, remaining); - out += remaining; - } - - tgt->size = (size_t)(out - tgt->ptr); - tgt->ptr[tgt->size] = '\0'; - - return 0; -} - -int git_str_lf_to_crlf(git_str *tgt, const git_str *src) -{ - const char *start = src->ptr; - const char *end = start + src->size; - const char *scan = start; - const char *next = memchr(scan, '\n', src->size); - size_t alloclen; - - GIT_ASSERT(tgt != src); - - if (!next) - return git_str_set(tgt, src->ptr, src->size); - - /* attempt to reduce reallocs while in the loop */ - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, src->size, src->size >> 4); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); - if (git_str_grow(tgt, alloclen) < 0) - return -1; - tgt->size = 0; - - for (; next; scan = next + 1, next = memchr(scan, '\n', end - scan)) { - size_t copylen = next - scan; - - /* if we find mixed line endings, carry on */ - if (copylen && next[-1] == '\r') - copylen--; - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, copylen, 3); - if (git_str_grow_by(tgt, alloclen) < 0) - return -1; - - if (copylen) { - memcpy(tgt->ptr + tgt->size, scan, copylen); - tgt->size += copylen; - } - - tgt->ptr[tgt->size++] = '\r'; - tgt->ptr[tgt->size++] = '\n'; - } - - tgt->ptr[tgt->size] = '\0'; - return git_str_put(tgt, scan, end - scan); -} - -int git_str_common_prefix(git_str *buf, char *const *const strings, size_t count) -{ - size_t i; - const char *str, *pfx; - - git_str_clear(buf); - - if (!strings || !count) - return 0; - - /* initialize common prefix to first string */ - if (git_str_sets(buf, strings[0]) < 0) - return -1; - - /* go through the rest of the strings, truncating to shared prefix */ - for (i = 1; i < count; ++i) { - - for (str = strings[i], pfx = buf->ptr; - *str && *str == *pfx; - str++, pfx++) - /* scanning */; - - git_str_truncate(buf, pfx - buf->ptr); - - if (!buf->size) - break; - } - - return 0; -} - -int git_str_is_binary(const git_str *buf) -{ - const char *scan = buf->ptr, *end = buf->ptr + buf->size; - git_str_bom_t bom; - int printable = 0, nonprintable = 0; - - scan += git_str_detect_bom(&bom, buf); - - if (bom > GIT_STR_BOM_UTF8) - return 1; - - while (scan < end) { - unsigned char c = *scan++; - - /* Printable characters are those above SPACE (0x1F) excluding DEL, - * and including BS, ESC and FF. - */ - if ((c > 0x1F && c != 127) || c == '\b' || c == '\033' || c == '\014') - printable++; - else if (c == '\0') - return true; - else if (!git__isspace(c)) - nonprintable++; - } - - return ((printable >> 7) < nonprintable); -} - -int git_str_contains_nul(const git_str *buf) -{ - return (memchr(buf->ptr, '\0', buf->size) != NULL); -} - -int git_str_detect_bom(git_str_bom_t *bom, const git_str *buf) -{ - const char *ptr; - size_t len; - - *bom = GIT_STR_BOM_NONE; - /* need at least 2 bytes to look for any BOM */ - if (buf->size < 2) - return 0; - - ptr = buf->ptr; - len = buf->size; - - switch (*ptr++) { - case 0: - if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') { - *bom = GIT_STR_BOM_UTF32_BE; - return 4; - } - break; - case '\xEF': - if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') { - *bom = GIT_STR_BOM_UTF8; - return 3; - } - break; - case '\xFE': - if (*ptr == '\xFF') { - *bom = GIT_STR_BOM_UTF16_BE; - return 2; - } - break; - case '\xFF': - if (*ptr != '\xFE') - break; - if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) { - *bom = GIT_STR_BOM_UTF32_LE; - return 4; - } else { - *bom = GIT_STR_BOM_UTF16_LE; - return 2; - } - break; - default: - break; - } - - return 0; -} - -bool git_str_gather_text_stats( - git_str_text_stats *stats, const git_str *buf, bool skip_bom) -{ - const char *scan = buf->ptr, *end = buf->ptr + buf->size; - int skip; - - memset(stats, 0, sizeof(*stats)); - - /* BOM detection */ - skip = git_str_detect_bom(&stats->bom, buf); - if (skip_bom) - scan += skip; - - /* Ignore EOF character */ - if (buf->size > 0 && end[-1] == '\032') - end--; - - /* Counting loop */ - while (scan < end) { - unsigned char c = *scan++; - - if (c > 0x1F && c != 0x7F) - stats->printable++; - else switch (c) { - case '\0': - stats->nul++; - stats->nonprintable++; - break; - case '\n': - stats->lf++; - break; - case '\r': - stats->cr++; - if (scan < end && *scan == '\n') - stats->crlf++; - break; - case '\t': case '\f': case '\v': case '\b': case 0x1b: /*ESC*/ - stats->printable++; - break; - default: - stats->nonprintable++; - break; - } - } - - /* Treat files with a bare CR as binary */ - return (stats->cr != stats->crlf || stats->nul > 0 || - ((stats->printable >> 7) < stats->nonprintable)); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/str.h b/vendor/libgit2-sys/libgit2/src/util/str.h deleted file mode 100644 index ad9b892..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/str.h +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_str_h__ -#define INCLUDE_str_h__ - -#include "git2_util.h" - -struct git_str { - char *ptr; - size_t asize; - size_t size; -}; - -typedef enum { - GIT_STR_BOM_NONE = 0, - GIT_STR_BOM_UTF8 = 1, - GIT_STR_BOM_UTF16_LE = 2, - GIT_STR_BOM_UTF16_BE = 3, - GIT_STR_BOM_UTF32_LE = 4, - GIT_STR_BOM_UTF32_BE = 5 -} git_str_bom_t; - -typedef struct { - git_str_bom_t bom; /* BOM found at head of text */ - unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */ - unsigned int printable, nonprintable; /* These are just approximations! */ -} git_str_text_stats; - -extern char git_str__initstr[]; -extern char git_str__oom[]; - -/* Use to initialize string buffer structure when git_str is on stack */ -#define GIT_STR_INIT { git_str__initstr, 0, 0 } - -/** - * Static initializer for git_str from static string buffer - */ -#define GIT_STR_INIT_CONST(str, len) { (char *)(str), 0, (size_t)(len) } - -GIT_INLINE(bool) git_str_is_allocated(const git_str *str) -{ - return (str->ptr != NULL && str->asize > 0); -} - -/** - * Initialize a git_str structure. - * - * For the cases where GIT_STR_INIT cannot be used to do static - * initialization. - */ -extern int git_str_init(git_str *str, size_t initial_size); - -extern void git_str_dispose(git_str *str); - -/** - * Resize the string buffer allocation to make more space. - * - * This will attempt to grow the string buffer to accommodate the target - * size. The bstring buffer's `ptr` will be replaced with a newly - * allocated block of data. Be careful so that memory allocated by the - * caller is not lost. As a special variant, if you pass `target_size` as - * 0 and the memory is not allocated by libgit2, this will allocate a new - * buffer of size `size` and copy the external data into it. - * - * Currently, this will never shrink a buffer, only expand it. - * - * If the allocation fails, this will return an error and the buffer will be - * marked as invalid for future operations, invaliding the contents. - * - * @param str The buffer to be resized; may or may not be allocated yet - * @param target_size The desired available size - * @return 0 on success, -1 on allocation failure - */ -int git_str_grow(git_str *str, size_t target_size); - -/** - * Resize the buffer allocation to make more space. - * - * This will attempt to grow the string buffer to accommodate the - * additional size. It is similar to `git_str_grow`, but performs the - * new size calculation, checking for overflow. - * - * Like `git_str_grow`, if this is a user-supplied string buffer, - * this will allocate a new string uffer. - */ -extern int git_str_grow_by(git_str *str, size_t additional_size); - -/** - * Attempt to grow the buffer to hold at least `target_size` bytes. - * - * If the allocation fails, this will return an error. If `mark_oom` is - * true, this will mark the string buffer as invalid for future - * operations; if false, existing string buffer content will be preserved, - * but calling code must handle that string buffer was not expanded. If - * `preserve_external` is true, then any existing data pointed to be - * `ptr` even if `asize` is zero will be copied into the newly allocated - * string buffer. - */ -extern int git_str_try_grow( - git_str *str, size_t target_size, bool mark_oom); - -extern void git_str_swap(git_str *str_a, git_str *str_b); -extern char *git_str_detach(git_str *str); -extern int git_str_attach(git_str *str, char *ptr, size_t asize); - -/* Populates a `git_str` where the contents are not "owned" by the string - * buffer, and calls to `git_str_dispose` will not free the given str. - */ -extern void git_str_attach_notowned( - git_str *str, const char *ptr, size_t size); - -/** - * Test if there have been any reallocation failures with this git_str. - * - * Any function that writes to a git_str can fail due to memory allocation - * issues. If one fails, the git_str will be marked with an OOM error and - * further calls to modify the string buffer will fail. Check - * git_str_oom() at the end of your sequence and it will be true if you - * ran out of memory at any point with that string buffer. - * - * @return false if no error, true if allocation error - */ -GIT_INLINE(bool) git_str_oom(const git_str *str) -{ - return (str->ptr == git_str__oom); -} - -/* - * Functions below that return int value error codes will return 0 on - * success or -1 on failure (which generally means an allocation failed). - * Using a git_str where the allocation has failed with result in -1 from - * all further calls using that string buffer. As a result, you can - * ignore the return code of these functions and call them in a series - * then just call git_str_oom at the end. - */ - -int git_str_set(git_str *str, const void *data, size_t datalen); - -int git_str_sets(git_str *str, const char *string); -int git_str_putc(git_str *str, char c); -int git_str_putcn(git_str *str, char c, size_t len); -int git_str_put(git_str *str, const char *data, size_t len); -int git_str_puts(git_str *str, const char *string); -int git_str_printf(git_str *str, const char *format, ...) GIT_FORMAT_PRINTF(2, 3); -int git_str_vprintf(git_str *str, const char *format, va_list ap); -void git_str_clear(git_str *str); -void git_str_consume_bytes(git_str *str, size_t len); -void git_str_consume(git_str *str, const char *end); -void git_str_truncate(git_str *str, size_t len); -void git_str_shorten(git_str *str, size_t amount); -void git_str_truncate_at_char(git_str *path, char separator); -void git_str_rtruncate_at_char(git_str *path, char separator); - -/** General join with separator */ -int git_str_join_n(git_str *str, char separator, int len, ...); -/** Fast join of two strings - first may legally point into `str` data */ -int git_str_join(git_str *str, char separator, const char *str_a, const char *str_b); -/** Fast join of three strings - cannot reference `str` data */ -int git_str_join3(git_str *str, char separator, const char *str_a, const char *str_b, const char *str_c); - -/** - * Join two strings as paths, inserting a slash between as needed. - * @return 0 on success, -1 on failure - */ -GIT_INLINE(int) git_str_joinpath(git_str *str, const char *a, const char *b) -{ - return git_str_join(str, '/', a, b); -} - -GIT_INLINE(const char *) git_str_cstr(const git_str *str) -{ - return str->ptr; -} - -GIT_INLINE(size_t) git_str_len(const git_str *str) -{ - return str->size; -} - -int git_str_copy_cstr(char *data, size_t datasize, const git_str *str); - -#define git_str_PUTS(str, cstr) git_str_put(str, cstr, sizeof(cstr) - 1) - -GIT_INLINE(ssize_t) git_str_rfind_next(const git_str *str, char ch) -{ - ssize_t idx = (ssize_t)str->size - 1; - while (idx >= 0 && str->ptr[idx] == ch) idx--; - while (idx >= 0 && str->ptr[idx] != ch) idx--; - return idx; -} - -GIT_INLINE(ssize_t) git_str_rfind(const git_str *str, char ch) -{ - ssize_t idx = (ssize_t)str->size - 1; - while (idx >= 0 && str->ptr[idx] != ch) idx--; - return idx; -} - -GIT_INLINE(ssize_t) git_str_find(const git_str *str, char ch) -{ - void *found = memchr(str->ptr, ch, str->size); - return found ? (ssize_t)((const char *)found - str->ptr) : -1; -} - -/* Remove whitespace from the end of the string buffer */ -void git_str_rtrim(git_str *str); - -int git_str_cmp(const git_str *a, const git_str *b); - -/* Quote and unquote a string buffer as specified in - * http://marc.info/?l=git&m=112927316408690&w=2 - */ -int git_str_quote(git_str *str); -int git_str_unquote(git_str *str); - -/* Write data as a hex string */ -int git_str_encode_hexstr(git_str *str, const char *data, size_t len); - -/* Write data as base64 encoded in string buffer */ -int git_str_encode_base64(git_str *str, const char *data, size_t len); -/* Decode the given bas64 and write the result to the string buffer */ -int git_str_decode_base64(git_str *str, const char *base64, size_t len); - -/* Write data as "base85" encoded in string buffer */ -int git_str_encode_base85(git_str *str, const char *data, size_t len); -/* Decode the given "base85" and write the result to the string buffer */ -int git_str_decode_base85(git_str *str, const char *base64, size_t len, size_t output_len); - -/* - * Decode the given percent-encoded string and write the result to the - * string buffer. - */ -int git_str_decode_percent(git_str *str, const char *encoded, size_t len); - -/* - * Insert, remove or replace a portion of the string buffer. - * - * @param str The string buffer to work with - * - * @param where The location in the string buffer where the transformation - * should be applied. - * - * @param nb_to_remove The number of chars to be removed. 0 to not - * remove any character in the string buffer. - * - * @param data A pointer to the data which should be inserted. - * - * @param nb_to_insert The number of chars to be inserted. 0 to not - * insert any character from the string buffer. - * - * @return 0 or an error code. - */ -int git_str_splice( - git_str *str, - size_t where, - size_t nb_to_remove, - const char *data, - size_t nb_to_insert); - -/** - * Append string to string buffer, prefixing each character from - * `esc_chars` with `esc_with` string. - * - * @param str String buffer to append data to - * @param string String to escape and append - * @param esc_chars Characters to be escaped - * @param esc_prefix String to insert as prefix of each found character - * @param esc_suffix String to insert as suffix of each found character - * @return 0 on success, <0 on failure (probably allocation problem) - */ -extern int git_str_puts_escaped( - git_str *str, - const char *string, - const char *esc_chars, - const char *esc_prefix, - const char *esc_suffix); - -/** - * Append string escaping characters that are regex special - */ -GIT_INLINE(int) git_str_puts_escape_regex(git_str *str, const char *string) -{ - return git_str_puts_escaped(str, string, "^.[]$()|*+?{}\\", "\\", NULL); -} - -/** - * Unescape all characters in a string buffer in place - * - * I.e. remove backslashes - */ -extern void git_str_unescape(git_str *str); - -/** - * Replace all \r\n with \n. - * - * @return 0 on success, -1 on memory error - */ -extern int git_str_crlf_to_lf(git_str *tgt, const git_str *src); - -/** - * Replace all \n with \r\n. Does not modify existing \r\n. - * - * @return 0 on success, -1 on memory error - */ -extern int git_str_lf_to_crlf(git_str *tgt, const git_str *src); - -/** - * Fill string buffer with the common prefix of a array of strings - * - * String buffer will be set to empty if there is no common prefix - */ -extern int git_str_common_prefix(git_str *buf, char *const *const strings, size_t count); - -/** - * Check if a string buffer begins with a UTF BOM - * - * @param bom Set to the type of BOM detected or GIT_BOM_NONE - * @param str String buffer in which to check the first bytes for a BOM - * @return Number of bytes of BOM data (or 0 if no BOM found) - */ -extern int git_str_detect_bom(git_str_bom_t *bom, const git_str *str); - -/** - * Gather stats for a piece of text - * - * Fill the `stats` structure with counts of unreadable characters, carriage - * returns, etc, so it can be used in heuristics. This automatically skips - * a trailing EOF (\032 character). Also it will look for a BOM at the - * start of the text and can be told to skip that as well. - * - * @param stats Structure to be filled in - * @param str Text to process - * @param skip_bom Exclude leading BOM from stats if true - * @return Does the string buffer heuristically look like binary data - */ -extern bool git_str_gather_text_stats( - git_str_text_stats *stats, const git_str *str, bool skip_bom); - -/** -* Check quickly if string buffer looks like it contains binary data -* -* @param str string buffer to check -* @return 1 if string buffer looks like non-text data -*/ -int git_str_is_binary(const git_str *str); - -/** -* Check quickly if buffer contains a NUL byte -* -* @param str string buffer to check -* @return 1 if string buffer contains a NUL byte -*/ -int git_str_contains_nul(const git_str *str); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/strlist.c b/vendor/libgit2-sys/libgit2/src/util/strlist.c deleted file mode 100644 index df5640c..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/strlist.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include - -#include "git2_util.h" -#include "vector.h" -#include "strlist.h" - -int git_strlist_copy(char ***out, const char **in, size_t len) -{ - char **dup; - size_t i; - - dup = git__calloc(len, sizeof(char *)); - GIT_ERROR_CHECK_ALLOC(dup); - - for (i = 0; i < len; i++) { - dup[i] = git__strdup(in[i]); - GIT_ERROR_CHECK_ALLOC(dup[i]); - } - - *out = dup; - return 0; -} - -int git_strlist_copy_with_null(char ***out, const char **in, size_t len) -{ - char **dup; - size_t new_len, i; - - GIT_ERROR_CHECK_ALLOC_ADD(&new_len, len, 1); - - dup = git__calloc(new_len, sizeof(char *)); - GIT_ERROR_CHECK_ALLOC(dup); - - for (i = 0; i < len; i++) { - dup[i] = git__strdup(in[i]); - GIT_ERROR_CHECK_ALLOC(dup[i]); - } - - *out = dup; - return 0; -} - -bool git_strlist_contains_prefix( - const char **strings, - size_t len, - const char *str, - size_t n) -{ - size_t i; - - for (i = 0; i < len; i++) { - if (strncmp(strings[i], str, n) == 0) - return true; - } - - return false; -} - -bool git_strlist_contains_key( - const char **strings, - size_t len, - const char *key, - char delimiter) -{ - const char *c; - - for (c = key; *c; c++) { - if (*c == delimiter) - break; - } - - return *c ? - git_strlist_contains_prefix(strings, len, key, (c - key)) : - false; -} - -void git_strlist_free(char **strings, size_t len) -{ - size_t i; - - if (!strings) - return; - - for (i = 0; i < len; i++) - git__free(strings[i]); - - git__free(strings); -} - -void git_strlist_free_with_null(char **strings) -{ - char **s; - - if (!strings) - return; - - for (s = strings; *s; s++) - git__free(*s); - - git__free(strings); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/strlist.h b/vendor/libgit2-sys/libgit2/src/util/strlist.h deleted file mode 100644 index 68fbf8f..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/strlist.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_runtime_h__ -#define INCLUDE_runtime_h__ - -#include "git2_util.h" - -extern int git_strlist_copy(char ***out, const char **in, size_t len); - -extern int git_strlist_copy_with_null( - char ***out, - const char **in, - size_t len); - -extern bool git_strlist_contains_prefix( - const char **strings, - size_t len, - const char *str, - size_t n); - -extern bool git_strlist_contains_key( - const char **strings, - size_t len, - const char *key, - char delimiter); - -extern void git_strlist_free(char **strings, size_t len); - -extern void git_strlist_free_with_null(char **strings); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/strnlen.h b/vendor/libgit2-sys/libgit2/src/util/strnlen.h deleted file mode 100644 index eecfe3c..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/strnlen.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_strlen_h__ -#define INCLUDE_strlen_h__ - -#if defined(__MINGW32__) || defined(__sun) || defined(__APPLE__) || defined(__MidnightBSD__) ||\ - (defined(_MSC_VER) && _MSC_VER < 1500) -# define NO_STRNLEN -#endif - -#ifdef NO_STRNLEN -GIT_INLINE(size_t) p_strnlen(const char *s, size_t maxlen) { - const char *end = memchr(s, 0, maxlen); - return end ? (size_t)(end - s) : maxlen; -} -#else -# define p_strnlen strnlen -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/thread.c b/vendor/libgit2-sys/libgit2/src/util/thread.c deleted file mode 100644 index bc7364f..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/thread.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" - -#if !defined(GIT_THREADS) - -#define TLSDATA_MAX 16 - -typedef struct { - void *value; - void (GIT_SYSTEM_CALL *destroy_fn)(void *); -} tlsdata_value; - -static tlsdata_value tlsdata_values[TLSDATA_MAX]; -static int tlsdata_cnt = 0; - -int git_tlsdata_init(git_tlsdata_key *key, void (GIT_SYSTEM_CALL *destroy_fn)(void *)) -{ - if (tlsdata_cnt >= TLSDATA_MAX) - return -1; - - tlsdata_values[tlsdata_cnt].value = NULL; - tlsdata_values[tlsdata_cnt].destroy_fn = destroy_fn; - - *key = tlsdata_cnt; - tlsdata_cnt++; - - return 0; -} - -int git_tlsdata_set(git_tlsdata_key key, void *value) -{ - if (key < 0 || key > tlsdata_cnt) - return -1; - - tlsdata_values[key].value = value; - return 0; -} - -void *git_tlsdata_get(git_tlsdata_key key) -{ - if (key < 0 || key > tlsdata_cnt) - return NULL; - - return tlsdata_values[key].value; -} - -int git_tlsdata_dispose(git_tlsdata_key key) -{ - void *value; - void (*destroy_fn)(void *) = NULL; - - if (key < 0 || key > tlsdata_cnt) - return -1; - - value = tlsdata_values[key].value; - destroy_fn = tlsdata_values[key].destroy_fn; - - tlsdata_values[key].value = NULL; - tlsdata_values[key].destroy_fn = NULL; - - if (value && destroy_fn) - destroy_fn(value); - - return 0; -} - -#elif defined(GIT_WIN32) - -int git_tlsdata_init(git_tlsdata_key *key, void (GIT_SYSTEM_CALL *destroy_fn)(void *)) -{ - DWORD fls_index = FlsAlloc(destroy_fn); - - if (fls_index == FLS_OUT_OF_INDEXES) - return -1; - - *key = fls_index; - return 0; -} - -int git_tlsdata_set(git_tlsdata_key key, void *value) -{ - if (!FlsSetValue(key, value)) - return -1; - - return 0; -} - -void *git_tlsdata_get(git_tlsdata_key key) -{ - return FlsGetValue(key); -} - -int git_tlsdata_dispose(git_tlsdata_key key) -{ - if (!FlsFree(key)) - return -1; - - return 0; -} - -#elif defined(_POSIX_THREADS) - -int git_tlsdata_init(git_tlsdata_key *key, void (GIT_SYSTEM_CALL *destroy_fn)(void *)) -{ - if (pthread_key_create(key, destroy_fn) != 0) - return -1; - - return 0; -} - -int git_tlsdata_set(git_tlsdata_key key, void *value) -{ - if (pthread_setspecific(key, value) != 0) - return -1; - - return 0; -} - -void *git_tlsdata_get(git_tlsdata_key key) -{ - return pthread_getspecific(key); -} - -int git_tlsdata_dispose(git_tlsdata_key key) -{ - if (pthread_key_delete(key) != 0) - return -1; - - return 0; -} - -#else -# error unknown threading model -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/thread.h b/vendor/libgit2-sys/libgit2/src/util/thread.h deleted file mode 100644 index c32554b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/thread.h +++ /dev/null @@ -1,480 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_thread_h__ -#define INCLUDE_thread_h__ - -#if defined(GIT_THREADS) - -#if defined(__clang__) - -# if (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1)) -# error Atomic primitives do not exist on this version of clang; configure libgit2 with -DUSE_THREADS=OFF -# else -# define GIT_BUILTIN_ATOMIC -# endif - -#elif defined(__GNUC__) - -# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)) -# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DUSE_THREADS=OFF -# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) -# define GIT_BUILTIN_ATOMIC -# else -# define GIT_BUILTIN_SYNC -# endif - -#endif - -#endif /* GIT_THREADS */ - -/* Common operations even if threading has been disabled */ -typedef struct { -#if defined(GIT_WIN32) - volatile long val; -#else - volatile int val; -#endif -} git_atomic32; - -#ifdef GIT_ARCH_64 - -typedef struct { -#if defined(GIT_WIN32) - volatile __int64 val; -#else - volatile int64_t val; -#endif -} git_atomic64; - -typedef git_atomic64 git_atomic_ssize; - -#define git_atomic_ssize_set git_atomic64_set -#define git_atomic_ssize_add git_atomic64_add -#define git_atomic_ssize_get git_atomic64_get - -#else - -typedef git_atomic32 git_atomic_ssize; - -#define git_atomic_ssize_set git_atomic32_set -#define git_atomic_ssize_add git_atomic32_add -#define git_atomic_ssize_get git_atomic32_get - -#endif - -#ifdef GIT_THREADS - -#ifdef GIT_WIN32 -# include "win32/thread.h" -#else -# include "unix/pthread.h" -#endif - -/* - * Atomically sets the contents of *a to be val. - */ -GIT_INLINE(void) git_atomic32_set(git_atomic32 *a, int val) -{ -#if defined(GIT_WIN32) - InterlockedExchange(&a->val, (LONG)val); -#elif defined(GIT_BUILTIN_ATOMIC) - __atomic_store_n(&a->val, val, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - __sync_lock_test_and_set(&a->val, val); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -/* - * Atomically increments the contents of *a by 1, and stores the result back into *a. - * @return the result of the operation. - */ -GIT_INLINE(int) git_atomic32_inc(git_atomic32 *a) -{ -#if defined(GIT_WIN32) - return InterlockedIncrement(&a->val); -#elif defined(GIT_BUILTIN_ATOMIC) - return __atomic_add_fetch(&a->val, 1, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - return __sync_add_and_fetch(&a->val, 1); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -/* - * Atomically adds the contents of *a and addend, and stores the result back into *a. - * @return the result of the operation. - */ -GIT_INLINE(int) git_atomic32_add(git_atomic32 *a, int32_t addend) -{ -#if defined(GIT_WIN32) - return InterlockedAdd(&a->val, addend); -#elif defined(GIT_BUILTIN_ATOMIC) - return __atomic_add_fetch(&a->val, addend, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - return __sync_add_and_fetch(&a->val, addend); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -/* - * Atomically decrements the contents of *a by 1, and stores the result back into *a. - * @return the result of the operation. - */ -GIT_INLINE(int) git_atomic32_dec(git_atomic32 *a) -{ -#if defined(GIT_WIN32) - return InterlockedDecrement(&a->val); -#elif defined(GIT_BUILTIN_ATOMIC) - return __atomic_sub_fetch(&a->val, 1, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - return __sync_sub_and_fetch(&a->val, 1); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -/* - * Atomically gets the contents of *a. - * @return the contents of *a. - */ -GIT_INLINE(int) git_atomic32_get(git_atomic32 *a) -{ -#if defined(GIT_WIN32) - return (int)InterlockedCompareExchange(&a->val, 0, 0); -#elif defined(GIT_BUILTIN_ATOMIC) - return __atomic_load_n(&a->val, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - return __sync_val_compare_and_swap(&a->val, 0, 0); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -GIT_INLINE(void *) git_atomic__compare_and_swap( - void * volatile *ptr, void *oldval, void *newval) -{ -#if defined(GIT_WIN32) - return InterlockedCompareExchangePointer((volatile PVOID *)ptr, newval, oldval); -#elif defined(GIT_BUILTIN_ATOMIC) - void *foundval = oldval; - __atomic_compare_exchange(ptr, &foundval, &newval, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); - return foundval; -#elif defined(GIT_BUILTIN_SYNC) - return __sync_val_compare_and_swap(ptr, oldval, newval); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -GIT_INLINE(volatile void *) git_atomic__swap( - void * volatile *ptr, void *newval) -{ -#if defined(GIT_WIN32) - return InterlockedExchangePointer(ptr, newval); -#elif defined(GIT_BUILTIN_ATOMIC) - void * foundval = NULL; - __atomic_exchange(ptr, &newval, &foundval, __ATOMIC_SEQ_CST); - return foundval; -#elif defined(GIT_BUILTIN_SYNC) - return (volatile void *)__sync_lock_test_and_set(ptr, newval); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -GIT_INLINE(volatile void *) git_atomic__load(void * volatile *ptr) -{ -#if defined(GIT_WIN32) - void *newval = NULL, *oldval = NULL; - return (volatile void *)InterlockedCompareExchangePointer((volatile PVOID *)ptr, newval, oldval); -#elif defined(GIT_BUILTIN_ATOMIC) - return (volatile void *)__atomic_load_n(ptr, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - return (volatile void *)__sync_val_compare_and_swap(ptr, 0, 0); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -#ifdef GIT_ARCH_64 - -/* - * Atomically adds the contents of *a and addend, and stores the result back into *a. - * @return the result of the operation. - */ -GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend) -{ -#if defined(GIT_WIN32) - return InterlockedAdd64(&a->val, addend); -#elif defined(GIT_BUILTIN_ATOMIC) - return __atomic_add_fetch(&a->val, addend, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - return __sync_add_and_fetch(&a->val, addend); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -/* - * Atomically sets the contents of *a to be val. - */ -GIT_INLINE(void) git_atomic64_set(git_atomic64 *a, int64_t val) -{ -#if defined(GIT_WIN32) - InterlockedExchange64(&a->val, val); -#elif defined(GIT_BUILTIN_ATOMIC) - __atomic_store_n(&a->val, val, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - __sync_lock_test_and_set(&a->val, val); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -/* - * Atomically gets the contents of *a. - * @return the contents of *a. - */ -GIT_INLINE(int64_t) git_atomic64_get(git_atomic64 *a) -{ -#if defined(GIT_WIN32) - return (int64_t)InterlockedCompareExchange64(&a->val, 0, 0); -#elif defined(GIT_BUILTIN_ATOMIC) - return __atomic_load_n(&a->val, __ATOMIC_SEQ_CST); -#elif defined(GIT_BUILTIN_SYNC) - return __sync_val_compare_and_swap(&a->val, 0, 0); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -#endif - -#else - -#define git_threads_global_init git__noop - -#define git_thread unsigned int -#define git_thread_create(t, s, a) git__noop(t, s, a) -#define git_thread_join(i, s) git__noop_args(i, s) - -/* Pthreads Mutex */ -#define git_mutex unsigned int -#define git_mutex_init(a) git__noop_args(a) -#define git_mutex_init(a) git__noop_args(a) -#define git_mutex_lock(a) git__noop_args(a) -#define git_mutex_unlock(a) git__noop_args(a) -#define git_mutex_free(a) git__noop_args(a) - -/* Pthreads condition vars */ -#define git_cond unsigned int -#define git_cond_init(c) git__noop_args(c) -#define git_cond_free(c) git__noop_args(c) -#define git_cond_wait(c, l) git__noop_args(c, l) -#define git_cond_signal(c) git__noop_args(c) -#define git_cond_broadcast(c) git__noop_args(c) - -/* Pthreads rwlock */ -#define git_rwlock unsigned int -#define git_rwlock_init(a) git__noop_args(a) -#define git_rwlock_rdlock(a) git__noop_args(a) -#define git_rwlock_rdunlock(a) git__noop_args(a) -#define git_rwlock_wrlock(a) git__noop_args(a) -#define git_rwlock_wrunlock(a) git__noop_args(a) -#define git_rwlock_free(a) git__noop_args(a) - -#define GIT_RWLOCK_STATIC_INIT 0 - - -GIT_INLINE(void) git_atomic32_set(git_atomic32 *a, int val) -{ - a->val = val; -} - -GIT_INLINE(int) git_atomic32_inc(git_atomic32 *a) -{ - return ++a->val; -} - -GIT_INLINE(int) git_atomic32_add(git_atomic32 *a, int32_t addend) -{ - a->val += addend; - return a->val; -} - -GIT_INLINE(int) git_atomic32_dec(git_atomic32 *a) -{ - return --a->val; -} - -GIT_INLINE(int) git_atomic32_get(git_atomic32 *a) -{ - return (int)a->val; -} - -GIT_INLINE(void *) git_atomic__compare_and_swap( - void * volatile *ptr, void *oldval, void *newval) -{ - void *foundval = *ptr; - if (foundval == oldval) - *ptr = newval; - return foundval; -} - -GIT_INLINE(volatile void *) git_atomic__swap( - void * volatile *ptr, void *newval) -{ - volatile void *old = *ptr; - *ptr = newval; - return old; -} - -GIT_INLINE(volatile void *) git_atomic__load(void * volatile *ptr) -{ - return *ptr; -} - -#ifdef GIT_ARCH_64 - -GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend) -{ - a->val += addend; - return a->val; -} - -GIT_INLINE(void) git_atomic64_set(git_atomic64 *a, int64_t val) -{ - a->val = val; -} - -GIT_INLINE(int64_t) git_atomic64_get(git_atomic64 *a) -{ - return (int64_t)a->val; -} - -#endif - -#endif - -/* - * Atomically replace the contents of *ptr (if they are equal to oldval) with - * newval. ptr must point to a pointer or a value that is the same size as a - * pointer. This is semantically compatible with: - * - * #define git_atomic_compare_and_swap(ptr, oldval, newval) \ - * ({ \ - * void *foundval = *ptr; \ - * if (foundval == oldval) \ - * *ptr = newval; \ - * foundval; \ - * }) - * - * @return the original contents of *ptr. - */ -#define git_atomic_compare_and_swap(ptr, oldval, newval) \ - git_atomic__compare_and_swap((void * volatile *)ptr, oldval, newval) - -/* - * Atomically replace the contents of v with newval. v must be the same size as - * a pointer. This is semantically compatible with: - * - * #define git_atomic_swap(v, newval) \ - * ({ \ - * volatile void *old = v; \ - * v = newval; \ - * old; \ - * }) - * - * @return the original contents of v. - */ -#define git_atomic_swap(v, newval) \ - (void *)git_atomic__swap((void * volatile *)&(v), newval) - -/* - * Atomically reads the contents of v. v must be the same size as a pointer. - * This is semantically compatible with: - * - * #define git_atomic_load(v) v - * - * @return the contents of v. - */ -#define git_atomic_load(v) \ - (void *)git_atomic__load((void * volatile *)&(v)) - -#if defined(GIT_THREADS) - -# if defined(GIT_WIN32) -# define GIT_MEMORY_BARRIER MemoryBarrier() -# elif defined(GIT_BUILTIN_ATOMIC) -# define GIT_MEMORY_BARRIER __atomic_thread_fence(__ATOMIC_SEQ_CST) -# elif defined(GIT_BUILTIN_SYNC) -# define GIT_MEMORY_BARRIER __sync_synchronize() -# endif - -#else - -# define GIT_MEMORY_BARRIER /* noop */ - -#endif - -/* Thread-local data */ - -#if !defined(GIT_THREADS) -# define git_tlsdata_key int -#elif defined(GIT_WIN32) -# define git_tlsdata_key DWORD -#elif defined(_POSIX_THREADS) -# define git_tlsdata_key pthread_key_t -#else -# error unknown threading model -#endif - -/** - * Create a thread-local data key. The destroy function will be - * called upon thread exit. On some platforms, it may be called - * when all threads have deleted their keys. - * - * Note that the tlsdata functions do not set an error message on - * failure; this is because the error handling in libgit2 is itself - * handled by thread-local data storage. - * - * @param key the tlsdata key - * @param destroy_fn function pointer called upon thread exit - * @return 0 on success, non-zero on failure - */ -int git_tlsdata_init(git_tlsdata_key *key, void (GIT_SYSTEM_CALL *destroy_fn)(void *)); - -/** - * Set a the thread-local value for the given key. - * - * @param key the tlsdata key to store data on - * @param value the pointer to store - * @return 0 on success, non-zero on failure - */ -int git_tlsdata_set(git_tlsdata_key key, void *value); - -/** - * Get the thread-local value for the given key. - * - * @param key the tlsdata key to retrieve the value of - * @return the pointer stored with git_tlsdata_set - */ -void *git_tlsdata_get(git_tlsdata_key key); - -/** - * Delete the given thread-local key. - * - * @param key the tlsdata key to dispose - * @return 0 on success, non-zero on failure - */ -int git_tlsdata_dispose(git_tlsdata_key key); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/tsort.c b/vendor/libgit2-sys/libgit2/src/util/tsort.c deleted file mode 100644 index 2ef03d0..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/tsort.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" - -/** - * An array-of-pointers implementation of Python's Timsort - * Based on code by Christopher Swenson under the MIT license - * - * Copyright (c) 2010 Christopher Swenson - * Copyright (c) 2011 Vicent Marti - */ - -#ifndef MAX -# define MAX(x,y) (((x) > (y) ? (x) : (y))) -#endif - -#ifndef MIN -# define MIN(x,y) (((x) < (y) ? (x) : (y))) -#endif - -static int binsearch( - void **dst, const void *x, size_t size, git__sort_r_cmp cmp, void *payload) -{ - int l, c, r; - void *lx, *cx; - - l = 0; - r = (int)size - 1; - c = r >> 1; - lx = dst[l]; - - /* check for beginning conditions */ - if (cmp(x, lx, payload) < 0) - return 0; - - else if (cmp(x, lx, payload) == 0) { - int i = 1; - while (cmp(x, dst[i], payload) == 0) - i++; - return i; - } - - /* guaranteed not to be >= rx */ - cx = dst[c]; - while (1) { - const int val = cmp(x, cx, payload); - if (val < 0) { - if (c - l <= 1) return c; - r = c; - } else if (val > 0) { - if (r - c <= 1) return c + 1; - l = c; - lx = cx; - } else { - do { - cx = dst[++c]; - } while (cmp(x, cx, payload) == 0); - return c; - } - c = l + ((r - l) >> 1); - cx = dst[c]; - } -} - -/* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */ -static void bisort( - void **dst, size_t start, size_t size, git__sort_r_cmp cmp, void *payload) -{ - size_t i; - void *x; - int location; - - for (i = start; i < size; i++) { - int j; - /* If this entry is already correct, just move along */ - if (cmp(dst[i - 1], dst[i], payload) <= 0) - continue; - - /* Else we need to find the right place, shift everything over, and squeeze in */ - x = dst[i]; - location = binsearch(dst, x, i, cmp, payload); - for (j = (int)i - 1; j >= location; j--) { - dst[j + 1] = dst[j]; - } - dst[location] = x; - } -} - - -/* timsort implementation, based on timsort.txt */ -struct tsort_run { - ssize_t start; - ssize_t length; -}; - -struct tsort_store { - size_t alloc; - git__sort_r_cmp cmp; - void *payload; - void **storage; -}; - -static void reverse_elements(void **dst, ssize_t start, ssize_t end) -{ - while (start < end) { - void *tmp = dst[start]; - dst[start] = dst[end]; - dst[end] = tmp; - - start++; - end--; - } -} - -static ssize_t count_run( - void **dst, ssize_t start, ssize_t size, struct tsort_store *store) -{ - ssize_t curr = start + 2; - - if (size - start == 1) - return 1; - - if (start >= size - 2) { - if (store->cmp(dst[size - 2], dst[size - 1], store->payload) > 0) { - void *tmp = dst[size - 1]; - dst[size - 1] = dst[size - 2]; - dst[size - 2] = tmp; - } - - return 2; - } - - if (store->cmp(dst[start], dst[start + 1], store->payload) <= 0) { - while (curr < size - 1 && - store->cmp(dst[curr - 1], dst[curr], store->payload) <= 0) - curr++; - - return curr - start; - } else { - while (curr < size - 1 && - store->cmp(dst[curr - 1], dst[curr], store->payload) > 0) - curr++; - - /* reverse in-place */ - reverse_elements(dst, start, curr - 1); - return curr - start; - } -} - -static size_t compute_minrun(size_t n) -{ - int r = 0; - while (n >= 64) { - r |= n & 1; - n >>= 1; - } - return n + r; -} - -static int check_invariant(struct tsort_run *stack, ssize_t stack_curr) -{ - if (stack_curr < 2) - return 1; - - else if (stack_curr == 2) { - const ssize_t A = stack[stack_curr - 2].length; - const ssize_t B = stack[stack_curr - 1].length; - return (A > B); - } else { - const ssize_t A = stack[stack_curr - 3].length; - const ssize_t B = stack[stack_curr - 2].length; - const ssize_t C = stack[stack_curr - 1].length; - return !((A <= B + C) || (B <= C)); - } -} - -static int resize(struct tsort_store *store, size_t new_size) -{ - if (store->alloc < new_size) { - void **tempstore; - - tempstore = git__reallocarray(store->storage, new_size, sizeof(void *)); - - /** - * Do not propagate on OOM; this will abort the sort and - * leave the array unsorted, but no error code will be - * raised - */ - if (tempstore == NULL) - return -1; - - store->storage = tempstore; - store->alloc = new_size; - } - - return 0; -} - -static void merge(void **dst, const struct tsort_run *stack, ssize_t stack_curr, struct tsort_store *store) -{ - const ssize_t A = stack[stack_curr - 2].length; - const ssize_t B = stack[stack_curr - 1].length; - const ssize_t curr = stack[stack_curr - 2].start; - - void **storage; - ssize_t i, j, k; - - if (resize(store, MIN(A, B)) < 0) - return; - - storage = store->storage; - - /* left merge */ - if (A < B) { - memcpy(storage, &dst[curr], A * sizeof(void *)); - i = 0; - j = curr + A; - - for (k = curr; k < curr + A + B; k++) { - if ((i < A) && (j < curr + A + B)) { - if (store->cmp(storage[i], dst[j], store->payload) <= 0) - dst[k] = storage[i++]; - else - dst[k] = dst[j++]; - } else if (i < A) { - dst[k] = storage[i++]; - } else - dst[k] = dst[j++]; - } - } else { - memcpy(storage, &dst[curr + A], B * sizeof(void *)); - i = B - 1; - j = curr + A - 1; - - for (k = curr + A + B - 1; k >= curr; k--) { - if ((i >= 0) && (j >= curr)) { - if (store->cmp(dst[j], storage[i], store->payload) > 0) - dst[k] = dst[j--]; - else - dst[k] = storage[i--]; - } else if (i >= 0) - dst[k] = storage[i--]; - else - dst[k] = dst[j--]; - } - } -} - -static ssize_t collapse(void **dst, struct tsort_run *stack, ssize_t stack_curr, struct tsort_store *store, ssize_t size) -{ - ssize_t A, B, C; - - while (1) { - /* if the stack only has one thing on it, we are done with the collapse */ - if (stack_curr <= 1) - break; - - /* if this is the last merge, just do it */ - if ((stack_curr == 2) && (stack[0].length + stack[1].length == size)) { - merge(dst, stack, stack_curr, store); - stack[0].length += stack[1].length; - stack_curr--; - break; - } - - /* check if the invariant is off for a stack of 2 elements */ - else if ((stack_curr == 2) && (stack[0].length <= stack[1].length)) { - merge(dst, stack, stack_curr, store); - stack[0].length += stack[1].length; - stack_curr--; - break; - } - else if (stack_curr == 2) - break; - - A = stack[stack_curr - 3].length; - B = stack[stack_curr - 2].length; - C = stack[stack_curr - 1].length; - - /* check first invariant */ - if (A <= B + C) { - if (A < C) { - merge(dst, stack, stack_curr - 1, store); - stack[stack_curr - 3].length += stack[stack_curr - 2].length; - stack[stack_curr - 2] = stack[stack_curr - 1]; - stack_curr--; - } else { - merge(dst, stack, stack_curr, store); - stack[stack_curr - 2].length += stack[stack_curr - 1].length; - stack_curr--; - } - } else if (B <= C) { - merge(dst, stack, stack_curr, store); - stack[stack_curr - 2].length += stack[stack_curr - 1].length; - stack_curr--; - } else - break; - } - - return stack_curr; -} - -#define PUSH_NEXT() do {\ - len = count_run(dst, curr, size, store);\ - run = minrun;\ - if (run > (ssize_t)size - curr) run = size - curr;\ - if (run > len) {\ - bisort(&dst[curr], len, run, cmp, payload);\ - len = run;\ - }\ - run_stack[stack_curr].start = curr;\ - run_stack[stack_curr++].length = len;\ - curr += len;\ - if (curr == (ssize_t)size) {\ - /* finish up */ \ - while (stack_curr > 1) { \ - merge(dst, run_stack, stack_curr, store); \ - run_stack[stack_curr - 2].length += run_stack[stack_curr - 1].length; \ - stack_curr--; \ - } \ - if (store->storage != NULL) {\ - git__free(store->storage);\ - store->storage = NULL;\ - }\ - return;\ - }\ -}\ -while (0) - -void git__tsort_r( - void **dst, size_t size, git__sort_r_cmp cmp, void *payload) -{ - struct tsort_store _store, *store = &_store; - struct tsort_run run_stack[128]; - - ssize_t stack_curr = 0; - ssize_t len, run; - ssize_t curr = 0; - ssize_t minrun; - - if (size < 64) { - bisort(dst, 1, size, cmp, payload); - return; - } - - /* compute the minimum run length */ - minrun = (ssize_t)compute_minrun(size); - - /* temporary storage for merges */ - store->alloc = 0; - store->storage = NULL; - store->cmp = cmp; - store->payload = payload; - - PUSH_NEXT(); - PUSH_NEXT(); - PUSH_NEXT(); - - while (1) { - if (!check_invariant(run_stack, stack_curr)) { - stack_curr = collapse(dst, run_stack, stack_curr, store, size); - continue; - } - - PUSH_NEXT(); - } -} - -static int tsort_r_cmp(const void *a, const void *b, void *payload) -{ - return ((git__tsort_cmp)payload)(a, b); -} - -void git__tsort(void **dst, size_t size, git__tsort_cmp cmp) -{ - git__tsort_r(dst, size, tsort_r_cmp, cmp); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/unix/map.c b/vendor/libgit2-sys/libgit2/src/util/unix/map.c deleted file mode 100644 index 9330776..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/unix/map.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" - -#if !defined(GIT_WIN32) && !defined(NO_MMAP) - -#include "map.h" -#include -#include -#include - -int git__page_size(size_t *page_size) -{ - long sc_page_size = sysconf(_SC_PAGE_SIZE); - if (sc_page_size < 0) { - git_error_set(GIT_ERROR_OS, "can't determine system page size"); - return -1; - } - *page_size = (size_t) sc_page_size; - return 0; -} - -int git__mmap_alignment(size_t *alignment) -{ - return git__page_size(alignment); -} - -int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset) -{ - int mprot = PROT_READ; - int mflag = 0; - - GIT_MMAP_VALIDATE(out, len, prot, flags); - - out->data = NULL; - out->len = 0; - - if (prot & GIT_PROT_WRITE) - mprot |= PROT_WRITE; - - if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED) - mflag = MAP_SHARED; - else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE) - mflag = MAP_PRIVATE; - else - mflag = MAP_SHARED; - - out->data = mmap(NULL, len, mprot, mflag, fd, offset); - - if (!out->data || out->data == MAP_FAILED) { - git_error_set(GIT_ERROR_OS, "failed to mmap. Could not write data"); - return -1; - } - - out->len = len; - - return 0; -} - -int p_munmap(git_map *map) -{ - GIT_ASSERT_ARG(map); - munmap(map->data, map->len); - map->data = NULL; - map->len = 0; - - return 0; -} - -#endif - diff --git a/vendor/libgit2-sys/libgit2/src/util/unix/posix.h b/vendor/libgit2-sys/libgit2/src/util/unix/posix.h deleted file mode 100644 index 60f27d3..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/unix/posix.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_unix_posix_h__ -#define INCLUDE_unix_posix_h__ - -#include "git2_util.h" - -#include -#include -#include -#include -#include - -typedef int GIT_SOCKET; -#define INVALID_SOCKET -1 - -#define p_lseek(f,n,w) lseek(f, n, w) -#define p_fstat(f,b) fstat(f, b) -#define p_lstat(p,b) lstat(p,b) -#define p_stat(p,b) stat(p, b) - -#if defined(GIT_USE_STAT_MTIMESPEC) -# define st_atime_nsec st_atimespec.tv_nsec -# define st_mtime_nsec st_mtimespec.tv_nsec -# define st_ctime_nsec st_ctimespec.tv_nsec -#elif defined(GIT_USE_STAT_MTIM) -# define st_atime_nsec st_atim.tv_nsec -# define st_mtime_nsec st_mtim.tv_nsec -# define st_ctime_nsec st_ctim.tv_nsec -#elif !defined(GIT_USE_STAT_MTIME_NSEC) && defined(GIT_USE_NSEC) -# error GIT_USE_NSEC defined but unknown struct stat nanosecond type -#endif - -#define p_utimes(f, t) utimes(f, t) - -#define p_readlink(a, b, c) readlink(a, b, c) -#define p_symlink(o,n) symlink(o, n) -#define p_link(o,n) link(o, n) -#define p_unlink(p) unlink(p) -#define p_mkdir(p,m) mkdir(p, m) -extern char *p_realpath(const char *, char *); - -GIT_INLINE(int) p_fsync(int fd) -{ - p_fsync__cnt++; - return fsync(fd); -} - -#define p_recv(s,b,l,f) recv(s,b,l,f) -#define p_send(s,b,l,f) send(s,b,l,f) -#define p_inet_pton(a, b, c) inet_pton(a, b, c) - -#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a) -#define p_snprintf snprintf -#define p_chdir(p) chdir(p) -#define p_rmdir(p) rmdir(p) -#define p_access(p,m) access(p,m) -#define p_ftruncate(fd, sz) ftruncate(fd, sz) - -/* - * Pre-Android 5 did not implement a virtual filesystem atop FAT - * partitions for Unix permissions, which causes chmod to fail. However, - * Unix permissions have no effect on Android anyway as file permissions - * are not actually managed this way, so treating it as a no-op across - * all Android is safe. - */ -#ifdef __ANDROID__ -# define p_chmod(p,m) 0 -#else -# define p_chmod(p,m) chmod(p, m) -#endif - -/* see win32/posix.h for explanation about why this exists */ -#define p_lstat_posixly(p,b) lstat(p,b) - -#define p_localtime_r(c, r) localtime_r(c, r) -#define p_gmtime_r(c, r) gmtime_r(c, r) - -#define p_timeval timeval - -#ifdef GIT_USE_FUTIMENS -GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2]) -{ - struct timespec s[2]; - s[0].tv_sec = t[0].tv_sec; - s[0].tv_nsec = t[0].tv_usec * 1000; - s[1].tv_sec = t[1].tv_sec; - s[1].tv_nsec = t[1].tv_usec * 1000; - return futimens(f, s); -} -#else -# define p_futimes futimes -#endif - -#define p_pread(f, d, s, o) pread(f, d, s, o) -#define p_pwrite(f, d, s, o) pwrite(f, d, s, o) - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/unix/process.c b/vendor/libgit2-sys/libgit2/src/util/unix/process.c deleted file mode 100644 index 72308b1..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/unix/process.c +++ /dev/null @@ -1,706 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include -#include -#include - -#include "git2_util.h" -#include "vector.h" -#include "futils.h" -#include "process.h" -#include "strlist.h" - -#ifdef __APPLE__ - #include - #define environ (*_NSGetEnviron()) -#else - extern char **environ; -#endif - -struct git_process { - char **args; - char **env; - - char *cwd; - - unsigned int use_shell : 1, - capture_in : 1, - capture_out : 1, - capture_err : 1; - - pid_t pid; - - int child_in; - int child_out; - int child_err; - git_process_result_status status; -}; - -GIT_INLINE(bool) is_delete_env(const char *env) -{ - const char *c = strchr(env, '='); - - if (c == NULL) - return false; - - return *(c+1) == '\0'; -} - -GIT_INLINE(int) insert_dup(git_vector *v, const char *s) -{ - char *dup = git__strdup(s); - - GIT_ERROR_CHECK_ALLOC(dup); - - return git_vector_insert(v, dup); -} - -static int setup_args( - char ***out, - const char **args, - size_t args_len, - bool use_shell) -{ - git_vector prefixed = GIT_VECTOR_INIT; - git_str first = GIT_STR_INIT; - size_t cnt; - - GIT_ASSERT(args && args_len); - - if (use_shell) { - if (git_str_puts(&first, args[0]) < 0 || - git_str_puts(&first, " \"$@\"") < 0 || - insert_dup(&prefixed, "/bin/sh") < 0 || - insert_dup(&prefixed, "-c") < 0 || - git_vector_insert(&prefixed, git_str_detach(&first)) < 0) - goto on_error; - } - - for (cnt = 0; args && cnt < args_len; cnt++) { - if (insert_dup(&prefixed, args[cnt]) < 0) - goto on_error; - } - - git_vector_insert(&prefixed, NULL); - - *out = (char **)prefixed.contents; - - return 0; - -on_error: - git_str_dispose(&first); - git_vector_dispose_deep(&prefixed); - return -1; -} - -static int merge_env( - char ***out, - const char **env, - size_t env_len, - bool exclude_env) -{ - git_vector merged = GIT_VECTOR_INIT; - char **kv; - size_t max, cnt; - int error = 0; - - for (max = env_len, kv = environ; !exclude_env && *kv; kv++) - max++; - - if ((error = git_vector_init(&merged, max, NULL)) < 0) - goto on_error; - - for (cnt = 0; env && cnt < env_len; cnt++) { - if (is_delete_env(env[cnt])) - continue; - - if (insert_dup(&merged, env[cnt]) < 0) - goto on_error; - } - - if (!exclude_env) { - for (kv = environ; *kv; kv++) { - if (env && git_strlist_contains_key(env, env_len, *kv, '=')) - continue; - - if (insert_dup(&merged, *kv) < 0) - goto on_error; - } - } - - if (merged.length == 0) { - *out = NULL; - error = 0; - goto on_error; - } - - git_vector_insert(&merged, NULL); - - *out = (char **)merged.contents; - - return 0; - -on_error: - git_vector_dispose_deep(&merged); - return error; -} - -int git_process_new( - git_process **out, - const char **args, - size_t args_len, - const char **env, - size_t env_len, - git_process_options *opts) -{ - git_process *process; - - GIT_ASSERT_ARG(out && args && args_len > 0); - - *out = NULL; - - process = git__calloc(sizeof(git_process), 1); - GIT_ERROR_CHECK_ALLOC(process); - - if (setup_args(&process->args, args, args_len, opts ? opts->use_shell : false) < 0 || - merge_env(&process->env, env, env_len, opts ? opts->exclude_env : false) < 0) { - git_process_free(process); - return -1; - } - - if (opts) { - process->use_shell = opts->use_shell; - process->capture_in = opts->capture_in; - process->capture_out = opts->capture_out; - process->capture_err = opts->capture_err; - - if (opts->cwd) { - process->cwd = git__strdup(opts->cwd); - GIT_ERROR_CHECK_ALLOC(process->cwd); - } - } - - process->child_in = -1; - process->child_out = -1; - process->child_err = -1; - process->status = -1; - - *out = process; - return 0; -} - -extern int git_process_new_from_cmdline( - git_process **out, - const char *cmdline, - const char **env, - size_t env_len, - git_process_options *opts) -{ - git_process_options merged_opts = {0}; - - memcpy(&merged_opts, opts, sizeof(git_process_options)); - merged_opts.use_shell = 1; - - return git_process_new(out, &cmdline, 1, env, env_len, &merged_opts); -} - -#define CLOSE_FD(fd) \ - if (fd >= 0) { \ - close(fd); \ - fd = -1; \ - } - -static int try_read_status(size_t *out, int fd, void *buf, size_t len) -{ - size_t read_len = 0; - int ret = -1; - - while (ret && read_len < len) { - ret = read(fd, buf + read_len, len - read_len); - - if (ret < 0 && errno != EAGAIN && errno != EINTR) { - git_error_set(GIT_ERROR_OS, "could not read child status"); - return -1; - } - - read_len += ret; - } - - *out = read_len; - return 0; -} - - -static int read_status(int fd) -{ - size_t status_len = sizeof(int) * 3, read_len = 0; - char buffer[status_len], fn[128]; - int error, fn_error, os_error, fn_len = 0; - - if ((error = try_read_status(&read_len, fd, buffer, status_len)) < 0) - return error; - - /* Immediate EOF indicates the exec succeeded. */ - if (read_len == 0) - return 0; - - if (read_len < status_len) { - git_error_set(GIT_ERROR_INVALID, "child status truncated"); - return -1; - } - - memcpy(&fn_error, &buffer[0], sizeof(int)); - memcpy(&os_error, &buffer[sizeof(int)], sizeof(int)); - memcpy(&fn_len, &buffer[sizeof(int) * 2], sizeof(int)); - - if (fn_len > 0) { - fn_len = min(fn_len, (int)(ARRAY_SIZE(fn) - 1)); - - if ((error = try_read_status(&read_len, fd, fn, fn_len)) < 0) - return error; - - fn[fn_len] = '\0'; - } else { - fn[0] = '\0'; - } - - if (fn_error) { - errno = os_error; - git_error_set(GIT_ERROR_OS, "could not %s", fn[0] ? fn : "(unknown)"); - } - - return fn_error; -} - -static bool try_write_status(int fd, const void *buf, size_t len) -{ - size_t write_len; - int ret; - - for (write_len = 0; write_len < len; ) { - ret = write(fd, buf + write_len, len - write_len); - - if (ret <= 0) - break; - - write_len += ret; - } - - return (len == write_len); -} - -static void write_status(int fd, const char *fn, int error, int os_error) -{ - size_t status_len = sizeof(int) * 3, fn_len; - char buffer[status_len]; - - fn_len = strlen(fn); - - if (fn_len > INT_MAX) - fn_len = INT_MAX; - - memcpy(&buffer[0], &error, sizeof(int)); - memcpy(&buffer[sizeof(int)], &os_error, sizeof(int)); - memcpy(&buffer[sizeof(int) * 2], &fn_len, sizeof(int)); - - /* Do our best effort to write all the status. */ - if (!try_write_status(fd, buffer, status_len)) - return; - - if (fn_len) - try_write_status(fd, fn, fn_len); -} - -static int resolve_path(git_process *process) -{ - git_str full_path = GIT_STR_INIT; - int error = 0; - - /* The shell will resolve the path for us */ - if (process->use_shell) - goto done; - - error = git_fs_path_find_executable(&full_path, process->args[0]); - - if (error == GIT_ENOTFOUND) { - git_error_set(GIT_ERROR_SSH, "cannot run %s: No such file or directory", process->args[0]); - error = -1; - } - - if (error) - goto done; - - git__free(process->args[0]); - process->args[0] = git_str_detach(&full_path); - -done: - git_str_dispose(&full_path); - return error; -} - -int git_process_start(git_process *process) -{ - int in[2] = { -1, -1 }, out[2] = { -1, -1 }, - err[2] = { -1, -1 }, status[2] = { -1, -1 }; - int fdflags, state, error; - pid_t pid; - - /* Locate the path (unless we're letting the shell do it for us) */ - if ((error = resolve_path(process)) < 0) - goto on_error; - - /* Set up the pipes to read from/write to the process */ - if ((process->capture_in && pipe(in) < 0) || - (process->capture_out && pipe(out) < 0) || - (process->capture_err && pipe(err) < 0)) { - git_error_set(GIT_ERROR_OS, "could not create pipe"); - goto on_error; - } - - /* Set up a self-pipe for status from the forked process. */ - if (pipe(status) < 0 || - (fdflags = fcntl(status[1], F_GETFD)) < 0 || - fcntl(status[1], F_SETFD, fdflags | FD_CLOEXEC) < 0) { - git_error_set(GIT_ERROR_OS, "could not create pipe"); - goto on_error; - } - - switch (pid = fork()) { - case -1: - git_error_set(GIT_ERROR_OS, "could not fork"); - goto on_error; - - /* Child: start the process. */ - case 0: - /* Close the opposing side of the pipes */ - CLOSE_FD(status[0]); - - if (process->capture_in) { - CLOSE_FD(in[1]); - dup2(in[0], STDIN_FILENO); - } - - if (process->capture_out) { - CLOSE_FD(out[0]); - dup2(out[1], STDOUT_FILENO); - } - - if (process->capture_err) { - CLOSE_FD(err[0]); - dup2(err[1], STDERR_FILENO); - } - - if (process->cwd && (error = chdir(process->cwd)) < 0) { - write_status(status[1], "chdir", error, errno); - exit(0); - } - - /* - * Exec the process and write the results back if the - * call fails. If it succeeds, we'll close the status - * pipe (via CLOEXEC) and the parent will know. - */ - error = execve(process->args[0], - process->args, - process->env); - - write_status(status[1], "execve", error, errno); - exit(0); - - /* Parent: make sure the child process exec'd correctly. */ - default: - /* Close the opposing side of the pipes */ - CLOSE_FD(status[1]); - - if (process->capture_in) { - CLOSE_FD(in[0]); - process->child_in = in[1]; - } - - if (process->capture_out) { - CLOSE_FD(out[1]); - process->child_out = out[0]; - } - - if (process->capture_err) { - CLOSE_FD(err[1]); - process->child_err = err[0]; - } - - /* Try to read the status */ - process->status = status[0]; - if ((error = read_status(status[0])) < 0) { - waitpid(process->pid, &state, 0); - goto on_error; - } - - process->pid = pid; - return 0; - } - -on_error: - CLOSE_FD(in[0]); CLOSE_FD(in[1]); - CLOSE_FD(out[0]); CLOSE_FD(out[1]); - CLOSE_FD(err[0]); CLOSE_FD(err[1]); - CLOSE_FD(status[0]); CLOSE_FD(status[1]); - return -1; -} - -int git_process_id(p_pid_t *out, git_process *process) -{ - GIT_ASSERT(out && process); - - if (!process->pid) { - git_error_set(GIT_ERROR_INVALID, "process not running"); - return -1; - } - - *out = process->pid; - return 0; -} - -static ssize_t process_read(int fd, void *buf, size_t count) -{ - ssize_t ret; - - if (count > SSIZE_MAX) - count = SSIZE_MAX; - - if ((ret = read(fd, buf, count)) < 0) { - git_error_set(GIT_ERROR_OS, "could not read from child process"); - return -1; - } - - return ret; -} - -ssize_t git_process_read(git_process *process, void *buf, size_t count) -{ - GIT_ASSERT_ARG(process); - GIT_ASSERT(process->capture_out); - - return process_read(process->child_out, buf, count); -} - -ssize_t git_process_read_err(git_process *process, void *buf, size_t count) -{ - GIT_ASSERT_ARG(process); - GIT_ASSERT(process->capture_err); - - return process_read(process->child_err, buf, count); -} - -#ifdef GIT_THREADS - -# define signal_state sigset_t - -/* - * Since signal-handling is process-wide, we cannot simply use - * SIG_IGN to avoid SIGPIPE. Instead: http://www.microhowto.info:80/howto/ignore_sigpipe_without_affecting_other_threads_in_a_process.html - */ - -GIT_INLINE(int) disable_signals(sigset_t *saved_mask) -{ - sigset_t sigpipe_mask; - - sigemptyset(&sigpipe_mask); - sigaddset(&sigpipe_mask, SIGPIPE); - - if (pthread_sigmask(SIG_BLOCK, &sigpipe_mask, saved_mask) < 0) { - git_error_set(GIT_ERROR_OS, "could not configure signal mask"); - return -1; - } - - return 0; -} - -GIT_INLINE(int) restore_signals(sigset_t *saved_mask) -{ - sigset_t sigpipe_mask, pending; - int signal; - - sigemptyset(&sigpipe_mask); - sigaddset(&sigpipe_mask, SIGPIPE); - - if (sigpending(&pending) < 0) { - git_error_set(GIT_ERROR_OS, "could not examine pending signals"); - return -1; - } - - if (sigismember(&pending, SIGPIPE) == 1 && - sigwait(&sigpipe_mask, &signal) < 0) { - git_error_set(GIT_ERROR_OS, "could not wait for (blocking) signal delivery"); - return -1; - } - - if (pthread_sigmask(SIG_SETMASK, saved_mask, 0) < 0) { - git_error_set(GIT_ERROR_OS, "could not configure signal mask"); - return -1; - } - - return 0; -} - -#else - -# define signal_state struct sigaction - -GIT_INLINE(int) disable_signals(struct sigaction *saved_handler) -{ - struct sigaction ign_handler = { 0 }; - - ign_handler.sa_handler = SIG_IGN; - - if (sigaction(SIGPIPE, &ign_handler, saved_handler) < 0) { - git_error_set(GIT_ERROR_OS, "could not configure signal handler"); - return -1; - } - - return 0; -} - -GIT_INLINE(int) restore_signals(struct sigaction *saved_handler) -{ - if (sigaction(SIGPIPE, saved_handler, NULL) < 0) { - git_error_set(GIT_ERROR_OS, "could not configure signal handler"); - return -1; - } - - return 0; -} - -#endif - -ssize_t git_process_write(git_process *process, const void *buf, size_t count) -{ - signal_state saved_signal; - ssize_t ret; - - GIT_ASSERT_ARG(process); - GIT_ASSERT(process->capture_in); - - if (count > SSIZE_MAX) - count = SSIZE_MAX; - - if (disable_signals(&saved_signal) < 0) - return -1; - - if ((ret = write(process->child_in, buf, count)) < 0) - git_error_set(GIT_ERROR_OS, "could not write to child process"); - - if (restore_signals(&saved_signal) < 0) - return -1; - - return (ret < 0) ? -1 : ret; -} - -int git_process_close_in(git_process *process) -{ - if (!process->capture_in) { - git_error_set(GIT_ERROR_INVALID, "input is not open"); - return -1; - } - - CLOSE_FD(process->child_in); - return 0; -} - -int git_process_close_out(git_process *process) -{ - if (!process->capture_out) { - git_error_set(GIT_ERROR_INVALID, "output is not open"); - return -1; - } - - CLOSE_FD(process->child_out); - return 0; -} - -int git_process_close_err(git_process *process) -{ - if (!process->capture_err) { - git_error_set(GIT_ERROR_INVALID, "error is not open"); - return -1; - } - - CLOSE_FD(process->child_err); - return 0; -} - -int git_process_close(git_process *process) -{ - CLOSE_FD(process->child_in); - CLOSE_FD(process->child_out); - CLOSE_FD(process->child_err); - - return 0; -} - -int git_process_wait(git_process_result *result, git_process *process) -{ - int state; - - if (result) - memset(result, 0, sizeof(git_process_result)); - - if (!process->pid) { - git_error_set(GIT_ERROR_INVALID, "process is stopped"); - return -1; - } - - if (waitpid(process->pid, &state, 0) < 0) { - git_error_set(GIT_ERROR_OS, "could not wait for child"); - return -1; - } - - process->pid = 0; - - if (result) { - if (WIFEXITED(state)) { - result->status = GIT_PROCESS_STATUS_NORMAL; - result->exitcode = WEXITSTATUS(state); - } else if (WIFSIGNALED(state)) { - result->status = GIT_PROCESS_STATUS_ERROR; - result->signal = WTERMSIG(state); - } else { - result->status = GIT_PROCESS_STATUS_ERROR; - } - } - - return 0; -} - -int git_process_result_msg(git_str *out, git_process_result *result) -{ - if (result->status == GIT_PROCESS_STATUS_NONE) { - return git_str_puts(out, "process not started"); - } else if (result->status == GIT_PROCESS_STATUS_NORMAL) { - return git_str_printf(out, "process exited with code %d", - result->exitcode); - } else if (result->signal) { - return git_str_printf(out, "process exited on signal %d", - result->signal); - } - - return git_str_puts(out, "unknown error"); -} - -void git_process_free(git_process *process) -{ - if (!process) - return; - - if (process->pid) - git_process_close(process); - - git__free(process->cwd); - git_strlist_free_with_null(process->args); - git_strlist_free_with_null(process->env); - git__free(process); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/unix/pthread.h b/vendor/libgit2-sys/libgit2/src/util/unix/pthread.h deleted file mode 100644 index 55f4ae2..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/unix/pthread.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_unix_pthread_h__ -#define INCLUDE_unix_pthread_h__ - -typedef struct { - pthread_t thread; -} git_thread; - -GIT_INLINE(int) git_threads_global_init(void) { return 0; } - -#define git_thread_create(git_thread_ptr, start_routine, arg) \ - pthread_create(&(git_thread_ptr)->thread, NULL, start_routine, arg) -#define git_thread_join(git_thread_ptr, status) \ - pthread_join((git_thread_ptr)->thread, status) -#define git_thread_currentid() ((size_t)(pthread_self())) -#define git_thread_exit(retval) pthread_exit(retval) - -/* Git Mutex */ -#define git_mutex pthread_mutex_t -#define git_mutex_init(a) pthread_mutex_init(a, NULL) -#define git_mutex_lock(a) pthread_mutex_lock(a) -#define git_mutex_unlock(a) pthread_mutex_unlock(a) -#define git_mutex_free(a) pthread_mutex_destroy(a) - -/* Git condition vars */ -#define git_cond pthread_cond_t -#define git_cond_init(c) pthread_cond_init(c, NULL) -#define git_cond_free(c) pthread_cond_destroy(c) -#define git_cond_wait(c, l) pthread_cond_wait(c, l) -#define git_cond_signal(c) pthread_cond_signal(c) -#define git_cond_broadcast(c) pthread_cond_broadcast(c) - -/* Pthread (-ish) rwlock - * - * This differs from normal pthreads rwlocks in two ways: - * 1. Separate APIs for releasing read locks and write locks (as - * opposed to the pure POSIX API which only has one unlock fn) - * 2. You should not use recursive read locks (i.e. grabbing a read - * lock in a thread that already holds a read lock) because the - * Windows implementation doesn't support it - */ -#define git_rwlock pthread_rwlock_t -#define git_rwlock_init(a) pthread_rwlock_init(a, NULL) -#define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a) -#define git_rwlock_rdunlock(a) pthread_rwlock_unlock(a) -#define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a) -#define git_rwlock_wrunlock(a) pthread_rwlock_unlock(a) -#define git_rwlock_free(a) pthread_rwlock_destroy(a) -#define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/unix/realpath.c b/vendor/libgit2-sys/libgit2/src/util/unix/realpath.c deleted file mode 100644 index 2565e2e..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/unix/realpath.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" - -#ifndef GIT_WIN32 - -#include -#include -#include -#include - -char *p_realpath(const char *pathname, char *resolved) -{ - char *result; - - if ((result = realpath(pathname, resolved)) == NULL) - return NULL; - -#ifdef __OpenBSD__ - /* The OpenBSD realpath function behaves differently, - * figure out if the file exists */ - if (access(result, F_OK) < 0) { - if (!resolved) - free(result); - - return NULL; - } -#endif - - /* - * If resolved == NULL, the system has allocated the result - * string. We need to strdup this into _our_ allocator pool - * so that callers can free it with git__free. - */ - if (!resolved) { - char *dup = git__strdup(result); - free(result); - - result = dup; - } - - return result; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/utf8.c b/vendor/libgit2-sys/libgit2/src/util/utf8.c deleted file mode 100644 index c566fdf..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/utf8.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "utf8.h" - -#include "git2_util.h" - -/* - * git_utf8_iterate is taken from the utf8proc project, - * http://www.public-software-group.org/utf8proc - * - * Copyright (c) 2009 Public Software Group e. V., Berlin, Germany - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the ""Software""), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -static const uint8_t utf8proc_utf8class[256] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -static int utf8_charlen(const uint8_t *str, size_t str_len) -{ - uint8_t length; - size_t i; - - length = utf8proc_utf8class[str[0]]; - if (!length) - return -1; - - if (str_len > 0 && length > str_len) - return -1; - - for (i = 1; i < length; i++) { - if ((str[i] & 0xC0) != 0x80) - return -1; - } - - return (int)length; -} - -int git_utf8_iterate(uint32_t *out, const char *_str, size_t str_len) -{ - const uint8_t *str = (const uint8_t *)_str; - uint32_t uc = 0; - int length; - - *out = 0; - - if ((length = utf8_charlen(str, str_len)) < 0) - return -1; - - switch (length) { - case 1: - uc = str[0]; - break; - case 2: - uc = ((str[0] & 0x1F) << 6) + (str[1] & 0x3F); - if (uc < 0x80) uc = -1; - break; - case 3: - uc = ((str[0] & 0x0F) << 12) + ((str[1] & 0x3F) << 6) - + (str[2] & 0x3F); - if (uc < 0x800 || (uc >= 0xD800 && uc < 0xE000) || - (uc >= 0xFDD0 && uc < 0xFDF0)) uc = -1; - break; - case 4: - uc = ((str[0] & 0x07) << 18) + ((str[1] & 0x3F) << 12) - + ((str[2] & 0x3F) << 6) + (str[3] & 0x3F); - if (uc < 0x10000 || uc >= 0x110000) uc = -1; - break; - default: - return -1; - } - - if ((uc & 0xFFFF) >= 0xFFFE) - return -1; - - *out = uc; - return length; -} - -size_t git_utf8_char_length(const char *_str, size_t str_len) -{ - const uint8_t *str = (const uint8_t *)_str; - size_t offset = 0, count = 0; - - while (offset < str_len) { - int length = utf8_charlen(str + offset, str_len - offset); - - if (length < 0) - length = 1; - - offset += length; - count++; - } - - return count; -} - -size_t git_utf8_valid_buf_length(const char *_str, size_t str_len) -{ - const uint8_t *str = (const uint8_t *)_str; - size_t offset = 0; - - while (offset < str_len) { - int length = utf8_charlen(str + offset, str_len - offset); - - if (length < 0) - break; - - offset += length; - } - - return offset; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/utf8.h b/vendor/libgit2-sys/libgit2/src/util/utf8.h deleted file mode 100644 index 753ab07..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/utf8.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_utf8_h__ -#define INCLUDE_utf8_h__ - -#include "git2_util.h" - -/* - * Iterate through an UTF-8 string, yielding one codepoint at a time. - * - * @param out pointer where to store the current codepoint - * @param str current position in the string - * @param str_len size left in the string - * @return length in bytes of the read codepoint; -1 if the codepoint was invalid - */ -extern int git_utf8_iterate(uint32_t *out, const char *str, size_t str_len); - -/** - * Returns the number of characters in the given string. - * - * This function will count invalid codepoints; if any given byte is - * not part of a valid UTF-8 codepoint, then it will be counted toward - * the length in characters. - * - * In other words: - * 0x24 (U+0024 "$") has length 1 - * 0xc2 0xa2 (U+00A2 "¢") has length 1 - * 0x24 0xc2 0xa2 (U+0024 U+00A2 "$¢") has length 2 - * 0xf0 0x90 0x8d 0x88 (U+10348 "𐍈") has length 1 - * 0x24 0xc0 0xc1 0x34 (U+0024 "4) has length 4 - * - * @param str string to scan - * @param str_len size of the string - * @return length in characters of the string - */ -extern size_t git_utf8_char_length(const char *str, size_t str_len); - -/** - * Iterate through an UTF-8 string and stops after finding any invalid UTF-8 - * codepoints. - * - * @param str string to scan - * @param str_len size of the string - * @return length in bytes of the string that contains valid data - */ -extern size_t git_utf8_valid_buf_length(const char *str, size_t str_len); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/util.c b/vendor/libgit2-sys/libgit2/src/util/util.c deleted file mode 100644 index f22a75b..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/util.c +++ /dev/null @@ -1,837 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "util.h" - -#include "git2_util.h" - -#ifdef GIT_WIN32 -# include "win32/utf-conv.h" -# include "win32/w32_buffer.h" - -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -# include - -# ifdef GIT_QSORT_MSC -# include -# endif -#endif - -#ifdef _MSC_VER -# include -#endif - -#if defined(hpux) || defined(__hpux) || defined(_hpux) -# include -#endif - -int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const char **endptr, int base) -{ - const char *p; - int64_t n, nn, v; - int c, ovfl, neg, ndig; - - p = nptr; - neg = 0; - n = 0; - ndig = 0; - ovfl = 0; - - /* - * White space - */ - while (nptr_len && git__isspace(*p)) - p++, nptr_len--; - - if (!nptr_len) - goto Return; - - /* - * Sign - */ - if (*p == '-' || *p == '+') { - if (*p == '-') - neg = 1; - p++; - nptr_len--; - } - - if (!nptr_len) - goto Return; - - /* - * Automatically detect the base if none was given to us. - * Right now, we assume that a number starting with '0x' - * is hexadecimal and a number starting with '0' is - * octal. - */ - if (base == 0) { - if (*p != '0') - base = 10; - else if (nptr_len > 2 && (p[1] == 'x' || p[1] == 'X')) - base = 16; - else - base = 8; - } - - if (base < 0 || 36 < base) - goto Return; - - /* - * Skip prefix of '0x'-prefixed hexadecimal numbers. There is no - * need to do the same for '0'-prefixed octal numbers as a - * leading '0' does not have any impact. Also, if we skip a - * leading '0' in such a string, then we may end up with no - * digits left and produce an error later on which isn't one. - */ - if (base == 16 && nptr_len > 2 && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { - p += 2; - nptr_len -= 2; - } - - /* - * Non-empty sequence of digits - */ - for (; nptr_len > 0; p++,ndig++,nptr_len--) { - c = *p; - v = base; - if ('0'<=c && c<='9') - v = c - '0'; - else if ('a'<=c && c<='z') - v = c - 'a' + 10; - else if ('A'<=c && c<='Z') - v = c - 'A' + 10; - if (v >= base) - break; - v = neg ? -v : v; - if (git__multiply_int64_overflow(&nn, n, base) || git__add_int64_overflow(&n, nn, v)) { - ovfl = 1; - /* Keep on iterating until the end of this number */ - continue; - } - } - -Return: - if (ndig == 0) { - git_error_set(GIT_ERROR_INVALID, "failed to convert string to long: not a number"); - return -1; - } - - if (endptr) - *endptr = p; - - if (ovfl) { - git_error_set(GIT_ERROR_INVALID, "failed to convert string to long: overflow error"); - return -1; - } - - *result = n; - return 0; -} - -int git__strntol32(int32_t *result, const char *nptr, size_t nptr_len, const char **endptr, int base) -{ - const char *tmp_endptr; - int32_t tmp_int; - int64_t tmp_long; - int error; - - if ((error = git__strntol64(&tmp_long, nptr, nptr_len, &tmp_endptr, base)) < 0) - return error; - - tmp_int = tmp_long & 0xFFFFFFFF; - if (tmp_int != tmp_long) { - int len = (int)(tmp_endptr - nptr); - git_error_set(GIT_ERROR_INVALID, "failed to convert: '%.*s' is too large", len, nptr); - return -1; - } - - *result = tmp_int; - if (endptr) - *endptr = tmp_endptr; - - return error; -} - -int git__strcasecmp(const char *a, const char *b) -{ - while (*a && *b && git__tolower(*a) == git__tolower(*b)) - ++a, ++b; - return ((unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b)); -} - -int git__strcasesort_cmp(const char *a, const char *b) -{ - int cmp = 0; - - while (*a && *b) { - if (*a != *b) { - if (git__tolower(*a) != git__tolower(*b)) - break; - /* use case in sort order even if not in equivalence */ - if (!cmp) - cmp = (int)(*(const uint8_t *)a) - (int)(*(const uint8_t *)b); - } - - ++a, ++b; - } - - if (*a || *b) - return (unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b); - - return cmp; -} - -int git__strncasecmp(const char *a, const char *b, size_t sz) -{ - int al, bl; - - do { - al = (unsigned char)git__tolower(*a); - bl = (unsigned char)git__tolower(*b); - ++a, ++b; - } while (--sz && al && al == bl); - - return al - bl; -} - -void git__strntolower(char *str, size_t len) -{ - size_t i; - - for (i = 0; i < len; ++i) { - str[i] = (char)git__tolower(str[i]); - } -} - -void git__strtolower(char *str) -{ - git__strntolower(str, strlen(str)); -} - -GIT_INLINE(int) prefixcmp(const char *str, size_t str_n, const char *prefix, bool icase) -{ - int s, p; - - while (str_n--) { - s = (unsigned char)*str++; - p = (unsigned char)*prefix++; - - if (icase) { - s = git__tolower(s); - p = git__tolower(p); - } - - if (!p) - return 0; - - if (s != p) - return s - p; - } - - return (0 - *prefix); -} - -int git__prefixcmp(const char *str, const char *prefix) -{ - unsigned char s, p; - - while (1) { - p = *prefix++; - s = *str++; - - if (!p) - return 0; - - if (s != p) - return s - p; - } -} - -int git__prefixncmp(const char *str, size_t str_n, const char *prefix) -{ - return prefixcmp(str, str_n, prefix, false); -} - -int git__prefixcmp_icase(const char *str, const char *prefix) -{ - return prefixcmp(str, SIZE_MAX, prefix, true); -} - -int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix) -{ - return prefixcmp(str, str_n, prefix, true); -} - -static int suffixcmp(const char *str, const char *suffix, bool icase) -{ - size_t a = strlen(str); - size_t b = strlen(suffix); - - if (a < b) - return -1; - - return icase ? strcasecmp(str + (a - b), suffix) : - strcmp(str + (a - b), suffix); -} - -int git__suffixcmp(const char *str, const char *suffix) -{ - return suffixcmp(str, suffix, false); -} - -int git__suffixcmp_icase(const char *str, const char *suffix) -{ - return suffixcmp(str, suffix, true); -} - -char *git__strtok(char **end, const char *sep) -{ - char *ptr = *end; - - while (*ptr && strchr(sep, *ptr)) - ++ptr; - - if (*ptr) { - char *start = ptr; - *end = start + 1; - - while (**end && !strchr(sep, **end)) - ++*end; - - if (**end) { - **end = '\0'; - ++*end; - } - - return start; - } - - return NULL; -} - -/* Similar to strtok, but does not collapse repeated tokens. */ -char *git__strsep(char **end, const char *sep) -{ - char *start = *end, *ptr = *end; - - while (*ptr && !strchr(sep, *ptr)) - ++ptr; - - if (*ptr) { - *end = ptr + 1; - *ptr = '\0'; - - return start; - } - - return NULL; -} - -size_t git__linenlen(const char *buffer, size_t buffer_len) -{ - const char *nl = memchr(buffer, '\n', buffer_len); - return nl ? (size_t)(nl - buffer) + 1 : buffer_len; -} - -/* - * Adapted Not So Naive algorithm from http://www-igm.univ-mlv.fr/~lecroq/string/ - */ -const void * git__memmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen) -{ - const char *h, *n; - size_t j, k, l; - - if (needlelen > haystacklen || !haystacklen || !needlelen) - return NULL; - - h = (const char *) haystack, - n = (const char *) needle; - - if (needlelen == 1) - return memchr(haystack, *n, haystacklen); - - if (n[0] == n[1]) { - k = 2; - l = 1; - } else { - k = 1; - l = 2; - } - - j = 0; - while (j <= haystacklen - needlelen) { - if (n[1] != h[j + 1]) { - j += k; - } else { - if (memcmp(n + 2, h + j + 2, needlelen - 2) == 0 && - n[0] == h[j]) - return h + j; - j += l; - } - } - - return NULL; -} - -void git__hexdump(const char *buffer, size_t len) -{ - static const size_t LINE_WIDTH = 16; - - size_t line_count, last_line, i, j; - const char *line; - - line_count = (len / LINE_WIDTH); - last_line = (len % LINE_WIDTH); - - for (i = 0; i < line_count; ++i) { - printf("%08" PRIxZ " ", (i * LINE_WIDTH)); - - line = buffer + (i * LINE_WIDTH); - for (j = 0; j < LINE_WIDTH; ++j, ++line) { - printf("%02x ", (unsigned char)*line & 0xFF); - - if (j == (LINE_WIDTH / 2)) - printf(" "); - } - - printf(" |"); - - line = buffer + (i * LINE_WIDTH); - for (j = 0; j < LINE_WIDTH; ++j, ++line) - printf("%c", (*line >= 32 && *line <= 126) ? *line : '.'); - - printf("|\n"); - } - - if (last_line > 0) { - printf("%08" PRIxZ " ", (line_count * LINE_WIDTH)); - - line = buffer + (line_count * LINE_WIDTH); - for (j = 0; j < last_line; ++j, ++line) { - printf("%02x ", (unsigned char)*line & 0xFF); - - if (j == (LINE_WIDTH / 2)) - printf(" "); - } - - if (j < (LINE_WIDTH / 2)) - printf(" "); - for (j = 0; j < (LINE_WIDTH - last_line); ++j) - printf(" "); - - printf(" |"); - - line = buffer + (line_count * LINE_WIDTH); - for (j = 0; j < last_line; ++j, ++line) - printf("%c", (*line >= 32 && *line <= 126) ? *line : '.'); - - printf("|\n"); - } - - printf("\n"); -} - -#ifdef GIT_LEGACY_HASH -uint32_t git__hash(const void *key, int len, unsigned int seed) -{ - const uint32_t m = 0x5bd1e995; - const int r = 24; - uint32_t h = seed ^ len; - - const unsigned char *data = (const unsigned char *)key; - - while(len >= 4) { - uint32_t k = *(uint32_t *)data; - - k *= m; - k ^= k >> r; - k *= m; - - h *= m; - h ^= k; - - data += 4; - len -= 4; - } - - switch(len) { - case 3: h ^= data[2] << 16; - case 2: h ^= data[1] << 8; - case 1: h ^= data[0]; - h *= m; - }; - - h ^= h >> 13; - h *= m; - h ^= h >> 15; - - return h; -} -#else -/* - Cross-platform version of Murmurhash3 - http://code.google.com/p/smhasher/wiki/MurmurHash3 - by Austin Appleby (aappleby@gmail.com) - - This code is on the public domain. -*/ -uint32_t git__hash(const void *key, int len, uint32_t seed) -{ - -#define MURMUR_BLOCK() {\ - k1 *= c1; \ - k1 = git__rotl(k1,11);\ - k1 *= c2;\ - h1 ^= k1;\ - h1 = h1*3 + 0x52dce729;\ - c1 = c1*5 + 0x7b7d159c;\ - c2 = c2*5 + 0x6bce6396;\ -} - - const uint8_t *data = (const uint8_t*)key; - const int nblocks = len / 4; - - const uint32_t *blocks = (const uint32_t *)(data + nblocks * 4); - const uint8_t *tail = (const uint8_t *)(data + nblocks * 4); - - uint32_t h1 = 0x971e137b ^ seed; - uint32_t k1; - - uint32_t c1 = 0x95543787; - uint32_t c2 = 0x2ad7eb25; - - int i; - - for (i = -nblocks; i; i++) { - k1 = blocks[i]; - MURMUR_BLOCK(); - } - - k1 = 0; - - switch(len & 3) { - case 3: k1 ^= tail[2] << 16; - /* fall through */ - case 2: k1 ^= tail[1] << 8; - /* fall through */ - case 1: k1 ^= tail[0]; - MURMUR_BLOCK(); - } - - h1 ^= len; - h1 ^= h1 >> 16; - h1 *= 0x85ebca6b; - h1 ^= h1 >> 13; - h1 *= 0xc2b2ae35; - h1 ^= h1 >> 16; - - return h1; -} -#endif - -/** - * A modified `bsearch` from the BSD glibc. - * - * Copyright (c) 1990 Regents of the University of California. - * All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. [rescinded 22 July 1999] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -int git__bsearch( - void **array, - size_t array_len, - const void *key, - int (*compare)(const void *, const void *), - size_t *position) -{ - size_t lim; - int cmp = -1; - void **part, **base = array; - - for (lim = array_len; lim != 0; lim >>= 1) { - part = base + (lim >> 1); - cmp = (*compare)(key, *part); - if (cmp == 0) { - base = part; - break; - } - if (cmp > 0) { /* key > p; take right partition */ - base = part + 1; - lim--; - } /* else take left partition */ - } - - if (position) - *position = (base - array); - - return (cmp == 0) ? 0 : GIT_ENOTFOUND; -} - -int git__bsearch_r( - void **array, - size_t array_len, - const void *key, - int (*compare_r)(const void *, const void *, void *), - void *payload, - size_t *position) -{ - size_t lim; - int cmp = -1; - void **part, **base = array; - - for (lim = array_len; lim != 0; lim >>= 1) { - part = base + (lim >> 1); - cmp = (*compare_r)(key, *part, payload); - if (cmp == 0) { - base = part; - break; - } - if (cmp > 0) { /* key > p; take right partition */ - base = part + 1; - lim--; - } /* else take left partition */ - } - - if (position) - *position = (base - array); - - return (cmp == 0) ? 0 : GIT_ENOTFOUND; -} - -/** - * A strcmp wrapper - * - * We don't want direct pointers to the CRT on Windows, we may - * get stdcall conflicts. - */ -int git__strcmp_cb(const void *a, const void *b) -{ - return git__strcmp((const char *)a, (const char *)b); -} - -int git__strcasecmp_cb(const void *a, const void *b) -{ - return git__strcasecmp((const char *)a, (const char *)b); -} - -int git__parse_bool(int *out, const char *value) -{ - /* A missing value means true */ - if (value == NULL || - !strcasecmp(value, "true") || - !strcasecmp(value, "yes") || - !strcasecmp(value, "on")) { - *out = 1; - return 0; - } - if (!strcasecmp(value, "false") || - !strcasecmp(value, "no") || - !strcasecmp(value, "off") || - value[0] == '\0') { - *out = 0; - return 0; - } - - return -1; -} - -size_t git__unescape(char *str) -{ - char *scan, *pos = str; - - if (!str) - return 0; - - for (scan = str; *scan; pos++, scan++) { - if (*scan == '\\' && *(scan + 1) != '\0') - scan++; /* skip '\' but include next char */ - if (pos != scan) - *pos = *scan; - } - - if (pos != scan) { - *pos = '\0'; - } - - return (pos - str); -} - -#if defined(GIT_QSORT_MSC) || defined(GIT_QSORT_BSD) -typedef struct { - git__sort_r_cmp cmp; - void *payload; -} git__qsort_r_glue; - -static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp( - void *payload, const void *a, const void *b) -{ - git__qsort_r_glue *glue = payload; - return glue->cmp(a, b, glue->payload); -} -#endif - - -#if !defined(GIT_QSORT_BSD) && \ - !defined(GIT_QSORT_GNU) && \ - !defined(GIT_QSORT_C11) && \ - !defined(GIT_QSORT_MSC) - -static void swap(uint8_t *a, uint8_t *b, size_t elsize) -{ - char tmp[256]; - - while (elsize) { - size_t n = elsize < sizeof(tmp) ? elsize : sizeof(tmp); - memcpy(tmp, a + elsize - n, n); - memcpy(a + elsize - n, b + elsize - n, n); - memcpy(b + elsize - n, tmp, n); - elsize -= n; - } -} - -static void insertsort( - void *els, size_t nel, size_t elsize, - git__sort_r_cmp cmp, void *payload) -{ - uint8_t *base = els; - uint8_t *end = base + nel * elsize; - uint8_t *i, *j; - - for (i = base + elsize; i < end; i += elsize) - for (j = i; j > base && cmp(j, j - elsize, payload) < 0; j -= elsize) - swap(j, j - elsize, elsize); -} - -#endif - -void git__qsort_r( - void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload) -{ -#if defined(GIT_QSORT_GNU) - qsort_r(els, nel, elsize, cmp, payload); -#elif defined(GIT_QSORT_C11) - qsort_s(els, nel, elsize, cmp, payload); -#elif defined(GIT_QSORT_BSD) - git__qsort_r_glue glue = { cmp, payload }; - qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp); -#elif defined(GIT_QSORT_MSC) - git__qsort_r_glue glue = { cmp, payload }; - qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue); -#else - insertsort(els, nel, elsize, cmp, payload); -#endif -} - -#ifdef GIT_WIN32 -int git__getenv(git_str *out, const char *name) -{ - wchar_t *wide_name = NULL, *wide_value = NULL; - DWORD value_len; - int error = -1; - - git_str_clear(out); - - if (git_utf8_to_16_alloc(&wide_name, name) < 0) - return -1; - - if ((value_len = GetEnvironmentVariableW(wide_name, NULL, 0)) > 0) { - wide_value = git__malloc(value_len * sizeof(wchar_t)); - GIT_ERROR_CHECK_ALLOC(wide_value); - - value_len = GetEnvironmentVariableW(wide_name, wide_value, value_len); - } - - if (value_len) - error = git_str_put_w(out, wide_value, value_len); - else if (GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_ENVVAR_NOT_FOUND) - error = GIT_ENOTFOUND; - else - git_error_set(GIT_ERROR_OS, "could not read environment variable '%s'", name); - - git__free(wide_name); - git__free(wide_value); - return error; -} -#else -int git__getenv(git_str *out, const char *name) -{ - const char *val = getenv(name); - - git_str_clear(out); - - if (!val) - return GIT_ENOTFOUND; - - return git_str_puts(out, val); -} -#endif - -/* - * By doing this in two steps we can at least get - * the function to be somewhat coherent, even - * with this disgusting nest of #ifdefs. - */ -#ifndef _SC_NPROCESSORS_ONLN -# ifdef _SC_NPROC_ONLN -# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN -# elif defined _SC_CRAY_NCPU -# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU -# endif -#endif - -int git__online_cpus(void) -{ -#ifdef _SC_NPROCESSORS_ONLN - long ncpus; -#endif - -#ifdef _WIN32 - SYSTEM_INFO info; - GetSystemInfo(&info); - - if ((int)info.dwNumberOfProcessors > 0) - return (int)info.dwNumberOfProcessors; -#elif defined(hpux) || defined(__hpux) || defined(_hpux) - struct pst_dynamic psd; - - if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0)) - return (int)psd.psd_proc_cnt; -#endif - -#ifdef _SC_NPROCESSORS_ONLN - if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0) - return (int)ncpus; -#endif - - return 1; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/util.h b/vendor/libgit2-sys/libgit2/src/util/util.h deleted file mode 100644 index d3cbbf4..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/util.h +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_util_h__ -#define INCLUDE_util_h__ - -#include "str.h" -#include "git2_util.h" -#include "strnlen.h" -#include "thread.h" - -#ifndef GIT_WIN32 -# include -#endif - -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) -#define bitsizeof(x) (CHAR_BIT * sizeof(x)) -#define MSB(x, bits) ((x) & (~UINT64_C(0) << (bitsizeof(x) - (bits)))) -#ifndef min -# define min(a,b) ((a) < (b) ? (a) : (b)) -#endif -#ifndef max -# define max(a,b) ((a) > (b) ? (a) : (b)) -#endif - -#if defined(__GNUC__) -# define GIT_CONTAINER_OF(ptr, type, member) \ - __builtin_choose_expr( \ - __builtin_offsetof(type, member) == 0 && \ - __builtin_types_compatible_p(__typeof__(&((type *) 0)->member), __typeof__(ptr)), \ - ((type *) (ptr)), \ - (void)0) -#else -# define GIT_CONTAINER_OF(ptr, type, member) (type *)(ptr) -#endif - -/** - * Return the length of a constant string. - * We are aware that `strlen` performs the same task and is usually - * optimized away by the compiler, whilst being safer because it returns - * valid values when passed a pointer instead of a constant string; however - * this macro will transparently work with wide-char and single-char strings. - */ -#define CONST_STRLEN(x) ((sizeof(x)/sizeof(x[0])) - 1) - -#define STRCMP_CASESELECT(IGNORE_CASE, STR1, STR2) \ - ((IGNORE_CASE) ? strcasecmp((STR1), (STR2)) : strcmp((STR1), (STR2))) - -#define CASESELECT(IGNORE_CASE, ICASE, CASE) \ - ((IGNORE_CASE) ? (ICASE) : (CASE)) - -extern int git__prefixcmp(const char *str, const char *prefix); -extern int git__prefixcmp_icase(const char *str, const char *prefix); -extern int git__prefixncmp(const char *str, size_t str_n, const char *prefix); -extern int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix); -extern int git__suffixcmp(const char *str, const char *suffix); -extern int git__suffixcmp_icase(const char *str, const char *suffix); - -GIT_INLINE(int) git__signum(int val) -{ - return ((val > 0) - (val < 0)); -} - -extern int git__strntol32(int32_t *n, const char *buff, size_t buff_len, const char **end_buf, int base); -extern int git__strntol64(int64_t *n, const char *buff, size_t buff_len, const char **end_buf, int base); - - -extern void git__hexdump(const char *buffer, size_t n); -extern uint32_t git__hash(const void *key, int len, uint32_t seed); - -/* 32-bit cross-platform rotl */ -#ifdef _MSC_VER /* use built-in method in MSVC */ -# define git__rotl(v, s) (uint32_t)_rotl(v, s) -#else /* use bitops in GCC; with o2 this gets optimized to a rotl instruction */ -# define git__rotl(v, s) (uint32_t)(((uint32_t)(v) << (s)) | ((uint32_t)(v) >> (32 - (s)))) -#endif - -extern char *git__strtok(char **end, const char *sep); -extern char *git__strsep(char **end, const char *sep); - -extern void git__strntolower(char *str, size_t len); -extern void git__strtolower(char *str); - -extern size_t git__linenlen(const char *buffer, size_t buffer_len); - -GIT_INLINE(const char *) git__next_line(const char *s) -{ - while (*s && *s != '\n') s++; - while (*s == '\n' || *s == '\r') s++; - return s; -} - -GIT_INLINE(const void *) git__memrchr(const void *s, int c, size_t n) -{ - const unsigned char *cp; - - if (n != 0) { - cp = (unsigned char *)s + n; - do { - if (*(--cp) == (unsigned char)c) - return cp; - } while (--n != 0); - } - - return NULL; -} - -extern const void * git__memmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen); - -typedef int (*git__tsort_cmp)(const void *a, const void *b); - -extern void git__tsort(void **dst, size_t size, git__tsort_cmp cmp); - -typedef int (*git__sort_r_cmp)(const void *a, const void *b, void *payload); - -extern void git__tsort_r( - void **dst, size_t size, git__sort_r_cmp cmp, void *payload); - -extern void git__qsort_r( - void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload); - -/** - * @param position If non-NULL, this will be set to the position where the - * element is or would be inserted if not found. - * @return 0 if found; GIT_ENOTFOUND if not found - */ -extern int git__bsearch( - void **array, - size_t array_len, - const void *key, - int (*compare)(const void *key, const void *element), - size_t *position); - -extern int git__bsearch_r( - void **array, - size_t array_len, - const void *key, - int (*compare_r)(const void *key, const void *element, void *payload), - void *payload, - size_t *position); - -#define git__strcmp strcmp -#define git__strncmp strncmp - -extern int git__strcmp_cb(const void *a, const void *b); -extern int git__strcasecmp_cb(const void *a, const void *b); - -extern int git__strcasecmp(const char *a, const char *b); -extern int git__strncasecmp(const char *a, const char *b, size_t sz); - -extern int git__strcasesort_cmp(const char *a, const char *b); - -/* - * Compare some NUL-terminated `a` to a possibly non-NUL terminated - * `b` of length `b_len`; like `strncmp` but ensuring that - * `strlen(a) == b_len` as well. - */ -GIT_INLINE(int) git__strlcmp(const char *a, const char *b, size_t b_len) -{ - int cmp = strncmp(a, b, b_len); - return cmp ? cmp : (int)a[b_len]; -} - -typedef struct { - git_atomic32 refcount; - void *owner; -} git_refcount; - -typedef void (*git_refcount_freeptr)(void *r); - -#define GIT_REFCOUNT_INC(r) { \ - git_atomic32_inc(&(r)->rc.refcount); \ -} - -#define GIT_REFCOUNT_DEC(_r, do_free) { \ - git_refcount *r = &(_r)->rc; \ - int val = git_atomic32_dec(&r->refcount); \ - if (val <= 0 && r->owner == NULL) { do_free(_r); } \ -} - -#define GIT_REFCOUNT_OWN(r, o) { \ - (void)git_atomic_swap((r)->rc.owner, o); \ -} - -#define GIT_REFCOUNT_OWNER(r) git_atomic_load((r)->rc.owner) - -#define GIT_REFCOUNT_VAL(r) git_atomic32_get((r)->rc.refcount) - - -static signed char from_hex[] = { --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */ --1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 */ --1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 70 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 90 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* b0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* c0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* d0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* e0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* f0 */ -}; - -GIT_INLINE(int) git__fromhex(char h) -{ - return from_hex[(unsigned char) h]; -} - -GIT_INLINE(int) git__ishex(const char *str) -{ - unsigned i; - for (i=0; str[i] != '\0'; i++) - if (git__fromhex(str[i]) < 0) - return 0; - return 1; -} - -GIT_INLINE(size_t) git__size_t_bitmask(size_t v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - - return v; -} - -GIT_INLINE(size_t) git__size_t_powerof2(size_t v) -{ - return git__size_t_bitmask(v) + 1; -} - -GIT_INLINE(bool) git__isspace_nonlf(int c) -{ - return (c == ' ' || c == '\t' || c == '\f' || c == '\r' || c == '\v'); -} - -GIT_INLINE(bool) git__iswildcard(int c) -{ - return (c == '*' || c == '?' || c == '['); -} - -/* - * Parse a string value as a boolean, just like Core Git does. - * - * Valid values for true are: 'true', 'yes', 'on' - * Valid values for false are: 'false', 'no', 'off' - */ -extern int git__parse_bool(int *out, const char *value); - -/* - * Unescapes a string in-place. - * - * Edge cases behavior: - * - "jackie\" -> "jacky\" - * - "chan\\" -> "chan\" - */ -extern size_t git__unescape(char *str); - -/* - * Safely zero-out memory, making sure that the compiler - * doesn't optimize away the operation. - */ -GIT_INLINE(void) git__memzero(void *data, size_t size) -{ -#ifdef _MSC_VER - SecureZeroMemory((PVOID)data, size); -#else - volatile uint8_t *scan = (volatile uint8_t *)data; - - while (size--) - *scan++ = 0x0; -#endif -} - -#ifdef GIT_WIN32 - -GIT_INLINE(uint64_t) git_time_monotonic(void) -{ - /* GetTickCount64 returns the number of milliseconds that have - * elapsed since the system was started. */ - return GetTickCount64(); -} - -#elif __APPLE__ - -#include -#include - -GIT_INLINE(uint64_t) git_time_monotonic(void) -{ - static double scaling_factor = 0; - - if (scaling_factor == 0) { - mach_timebase_info_data_t info; - - scaling_factor = mach_timebase_info(&info) == KERN_SUCCESS ? - ((double)info.numer / (double)info.denom) / 1.0E6 : - -1; - } else if (scaling_factor < 0) { - struct timeval tv; - - /* mach_timebase_info failed; fall back to gettimeofday */ - gettimeofday(&tv, NULL); - return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); - } - - return (uint64_t)(mach_absolute_time() * scaling_factor); -} - -#elif defined(__amigaos4__) - -#include - -GIT_INLINE(uint64_t) git_time_monotonic(void) -{ - struct TimeVal tv; - ITimer->GetUpTime(&tv); - return (tv.Seconds * 1000) + (tv.Microseconds / 1000); -} - -#else - -#include - -GIT_INLINE(uint64_t) git_time_monotonic(void) -{ - struct timeval tv; - -#ifdef CLOCK_MONOTONIC - struct timespec tp; - if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) - return (tp.tv_sec * 1000) + (tp.tv_nsec / 1.0E6); -#endif - - /* Fall back to using gettimeofday */ - gettimeofday(&tv, NULL); - return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); -} - -#endif - -extern int git__getenv(git_str *out, const char *name); - -extern int git__online_cpus(void); - -GIT_INLINE(int) git__noop(void) { return 0; } -GIT_INLINE(int) git__noop_args(void *a, ...) { GIT_UNUSED(a); return 0; } - -#include "alloc.h" - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/varint.c b/vendor/libgit2-sys/libgit2/src/util/varint.c deleted file mode 100644 index 9ffc1d7..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/varint.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "varint.h" - -uintmax_t git_decode_varint(const unsigned char *bufp, size_t *varint_len) -{ - const unsigned char *buf = bufp; - unsigned char c = *buf++; - uintmax_t val = c & 127; - while (c & 128) { - val += 1; - if (!val || MSB(val, 7)) { - /* This is not a valid varint_len, so it signals - the error */ - *varint_len = 0; - return 0; /* overflow */ - } - c = *buf++; - val = (val << 7) + (c & 127); - } - *varint_len = buf - bufp; - return val; -} - -int git_encode_varint(unsigned char *buf, size_t bufsize, uintmax_t value) -{ - unsigned char varint[16]; - unsigned pos = sizeof(varint) - 1; - varint[pos] = value & 127; - while (value >>= 7) - varint[--pos] = 128 | (--value & 127); - if (buf) { - if (bufsize < (sizeof(varint) - pos)) - return -1; - memcpy(buf, varint + pos, sizeof(varint) - pos); - } - return sizeof(varint) - pos; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/varint.h b/vendor/libgit2-sys/libgit2/src/util/varint.h deleted file mode 100644 index 79b8f55..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/varint.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_varint_h__ -#define INCLUDE_varint_h__ - -#include "git2_util.h" - -#include - -extern int git_encode_varint(unsigned char *, size_t, uintmax_t); -extern uintmax_t git_decode_varint(const unsigned char *, size_t *); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/vector.c b/vendor/libgit2-sys/libgit2/src/util/vector.c deleted file mode 100644 index 34ac3bb..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/vector.c +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "vector.h" - -#include "integer.h" - -/* In elements, not bytes */ -#define MIN_ALLOCSIZE 8 - -GIT_INLINE(size_t) compute_new_size(git_vector *v) -{ - size_t new_size = v->_alloc_size; - - /* Use a resize factor of 1.5, which is quick to compute using integer - * instructions and less than the golden ratio (1.618...) */ - if (new_size < MIN_ALLOCSIZE) - new_size = MIN_ALLOCSIZE; - else if (new_size <= (SIZE_MAX / 3) * 2) - new_size += new_size / 2; - else - new_size = SIZE_MAX; - - return new_size; -} - -GIT_INLINE(int) resize_vector(git_vector *v, size_t new_size) -{ - void *new_contents; - - if (new_size == 0) - return 0; - - new_contents = git__reallocarray(v->contents, new_size, sizeof(void *)); - GIT_ERROR_CHECK_ALLOC(new_contents); - - v->_alloc_size = new_size; - v->contents = new_contents; - - return 0; -} - -int git_vector_size_hint(git_vector *v, size_t size_hint) -{ - if (v->_alloc_size >= size_hint) - return 0; - return resize_vector(v, size_hint); -} - -int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp) -{ - GIT_ASSERT_ARG(v); - GIT_ASSERT_ARG(src); - - v->_alloc_size = 0; - v->contents = NULL; - v->_cmp = cmp ? cmp : src->_cmp; - v->length = src->length; - v->flags = src->flags; - if (cmp != src->_cmp) - git_vector_set_sorted(v, 0); - - if (src->length) { - size_t bytes; - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&bytes, src->length, sizeof(void *)); - v->contents = git__malloc(bytes); - GIT_ERROR_CHECK_ALLOC(v->contents); - v->_alloc_size = src->length; - memcpy(v->contents, src->contents, bytes); - } - - return 0; -} - -void git_vector_dispose(git_vector *v) -{ - if (!v) - return; - - git__free(v->contents); - v->contents = NULL; - - v->length = 0; - v->_alloc_size = 0; -} - -void git_vector_dispose_deep(git_vector *v) -{ - size_t i; - - if (!v) - return; - - for (i = 0; i < v->length; ++i) { - git__free(v->contents[i]); - v->contents[i] = NULL; - } - - git_vector_dispose(v); -} - -int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp) -{ - GIT_ASSERT_ARG(v); - - v->_alloc_size = 0; - v->_cmp = cmp; - v->length = 0; - v->flags = GIT_VECTOR_SORTED; - v->contents = NULL; - - return resize_vector(v, max(initial_size, MIN_ALLOCSIZE)); -} - -void **git_vector_detach(size_t *size, size_t *asize, git_vector *v) -{ - void **data = v->contents; - - if (size) - *size = v->length; - if (asize) - *asize = v->_alloc_size; - - v->_alloc_size = 0; - v->length = 0; - v->contents = NULL; - - return data; -} - -int git_vector_insert(git_vector *v, void *element) -{ - GIT_ASSERT_ARG(v); - - if (v->length >= v->_alloc_size && - resize_vector(v, compute_new_size(v)) < 0) - return -1; - - v->contents[v->length++] = element; - - git_vector_set_sorted(v, v->length <= 1); - - return 0; -} - -int git_vector_insert_sorted( - git_vector *v, void *element, int (*on_dup)(void **old, void *new)) -{ - int result; - size_t pos; - - GIT_ASSERT_ARG(v); - GIT_ASSERT(v->_cmp); - - if (!git_vector_is_sorted(v)) - git_vector_sort(v); - - if (v->length >= v->_alloc_size && - resize_vector(v, compute_new_size(v)) < 0) - return -1; - - /* If we find the element and have a duplicate handler callback, - * invoke it. If it returns non-zero, then cancel insert, otherwise - * proceed with normal insert. - */ - if (!git__bsearch(v->contents, v->length, element, v->_cmp, &pos) && - on_dup && (result = on_dup(&v->contents[pos], element)) < 0) - return result; - - /* shift elements to the right */ - if (pos < v->length) - memmove(v->contents + pos + 1, v->contents + pos, - (v->length - pos) * sizeof(void *)); - - v->contents[pos] = element; - v->length++; - - return 0; -} - -void git_vector_sort(git_vector *v) -{ - if (git_vector_is_sorted(v) || !v->_cmp) - return; - - if (v->length > 1) - git__tsort(v->contents, v->length, v->_cmp); - git_vector_set_sorted(v, 1); -} - -int git_vector_bsearch2( - size_t *at_pos, - git_vector *v, - git_vector_cmp key_lookup, - const void *key) -{ - GIT_ASSERT_ARG(v); - GIT_ASSERT_ARG(key); - GIT_ASSERT(key_lookup); - - /* need comparison function to sort the vector */ - if (!v->_cmp) - return -1; - - git_vector_sort(v); - - return git__bsearch(v->contents, v->length, key, key_lookup, at_pos); -} - -int git_vector_search2( - size_t *at_pos, const git_vector *v, git_vector_cmp key_lookup, const void *key) -{ - size_t i; - - GIT_ASSERT_ARG(v); - GIT_ASSERT_ARG(key); - GIT_ASSERT(key_lookup); - - for (i = 0; i < v->length; ++i) { - if (key_lookup(key, v->contents[i]) == 0) { - if (at_pos) - *at_pos = i; - - return 0; - } - } - - return GIT_ENOTFOUND; -} - -static int strict_comparison(const void *a, const void *b) -{ - return (a == b) ? 0 : -1; -} - -int git_vector_search(size_t *at_pos, const git_vector *v, const void *entry) -{ - return git_vector_search2(at_pos, v, v->_cmp ? v->_cmp : strict_comparison, entry); -} - -int git_vector_remove(git_vector *v, size_t idx) -{ - size_t shift_count; - - GIT_ASSERT_ARG(v); - - if (idx >= v->length) - return GIT_ENOTFOUND; - - shift_count = v->length - idx - 1; - - if (shift_count) - memmove(&v->contents[idx], &v->contents[idx + 1], - shift_count * sizeof(void *)); - - v->length--; - return 0; -} - -void git_vector_pop(git_vector *v) -{ - if (v->length > 0) - v->length--; -} - -void git_vector_uniq(git_vector *v, void (*git_free_cb)(void *)) -{ - git_vector_cmp cmp; - size_t i, j; - - if (v->length <= 1) - return; - - git_vector_sort(v); - cmp = v->_cmp ? v->_cmp : strict_comparison; - - for (i = 0, j = 1 ; j < v->length; ++j) - if (!cmp(v->contents[i], v->contents[j])) { - if (git_free_cb) - git_free_cb(v->contents[i]); - - v->contents[i] = v->contents[j]; - } else - v->contents[++i] = v->contents[j]; - - v->length -= j - i - 1; -} - -void git_vector_remove_matching( - git_vector *v, - int (*match)(const git_vector *v, size_t idx, void *payload), - void *payload) -{ - size_t i, j; - - for (i = 0, j = 0; j < v->length; ++j) { - v->contents[i] = v->contents[j]; - - if (!match(v, i, payload)) - i++; - } - - v->length = i; -} - -void git_vector_clear(git_vector *v) -{ - v->length = 0; - git_vector_set_sorted(v, 1); -} - -void git_vector_swap(git_vector *a, git_vector *b) -{ - git_vector t; - - if (a != b) { - memcpy(&t, a, sizeof(t)); - memcpy(a, b, sizeof(t)); - memcpy(b, &t, sizeof(t)); - } -} - -int git_vector_resize_to(git_vector *v, size_t new_length) -{ - if (new_length > v->_alloc_size && - resize_vector(v, new_length) < 0) - return -1; - - if (new_length > v->length) - memset(&v->contents[v->length], 0, - sizeof(void *) * (new_length - v->length)); - - v->length = new_length; - - return 0; -} - -int git_vector_insert_null(git_vector *v, size_t idx, size_t insert_len) -{ - size_t new_length; - - GIT_ASSERT_ARG(insert_len > 0); - GIT_ASSERT_ARG(idx <= v->length); - - GIT_ERROR_CHECK_ALLOC_ADD(&new_length, v->length, insert_len); - - if (new_length > v->_alloc_size && resize_vector(v, new_length) < 0) - return -1; - - memmove(&v->contents[idx + insert_len], &v->contents[idx], - sizeof(void *) * (v->length - idx)); - memset(&v->contents[idx], 0, sizeof(void *) * insert_len); - - v->length = new_length; - return 0; -} - -int git_vector_remove_range(git_vector *v, size_t idx, size_t remove_len) -{ - size_t new_length = v->length - remove_len; - size_t end_idx = 0; - - GIT_ASSERT_ARG(remove_len > 0); - - if (git__add_sizet_overflow(&end_idx, idx, remove_len)) - GIT_ASSERT(0); - - GIT_ASSERT(end_idx <= v->length); - - if (end_idx < v->length) - memmove(&v->contents[idx], &v->contents[end_idx], - sizeof(void *) * (v->length - end_idx)); - - memset(&v->contents[new_length], 0, sizeof(void *) * remove_len); - - v->length = new_length; - return 0; -} - -int git_vector_set(void **old, git_vector *v, size_t position, void *value) -{ - if (position + 1 > v->length) { - if (git_vector_resize_to(v, position + 1) < 0) - return -1; - } - - if (old != NULL) - *old = v->contents[position]; - - v->contents[position] = value; - - return 0; -} - -int git_vector_verify_sorted(const git_vector *v) -{ - size_t i; - - if (!git_vector_is_sorted(v)) - return -1; - - for (i = 1; i < v->length; ++i) { - if (v->_cmp(v->contents[i - 1], v->contents[i]) > 0) - return -1; - } - - return 0; -} - -void git_vector_reverse(git_vector *v) -{ - size_t a, b; - - if (v->length == 0) - return; - - a = 0; - b = v->length - 1; - - while (a < b) { - void *tmp = v->contents[a]; - v->contents[a] = v->contents[b]; - v->contents[b] = tmp; - a++; - b--; - } -} diff --git a/vendor/libgit2-sys/libgit2/src/util/vector.h b/vendor/libgit2-sys/libgit2/src/util/vector.h deleted file mode 100644 index 02f82b3..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/vector.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_vector_h__ -#define INCLUDE_vector_h__ - -#include "git2_util.h" - -typedef int (*git_vector_cmp)(const void *, const void *); - -enum { - GIT_VECTOR_SORTED = (1u << 0), - GIT_VECTOR_FLAG_MAX = (1u << 1) -}; - -typedef struct git_vector { - size_t _alloc_size; - git_vector_cmp _cmp; - void **contents; - size_t length; - uint32_t flags; -} git_vector; - -#define GIT_VECTOR_INIT {0} - -GIT_WARN_UNUSED_RESULT int git_vector_init( - git_vector *v, size_t initial_size, git_vector_cmp cmp); -void git_vector_dispose(git_vector *v); -void git_vector_dispose_deep(git_vector *v); /* free each entry and self */ -void git_vector_clear(git_vector *v); -GIT_WARN_UNUSED_RESULT int git_vector_dup( - git_vector *v, const git_vector *src, git_vector_cmp cmp); -void git_vector_swap(git_vector *a, git_vector *b); -int git_vector_size_hint(git_vector *v, size_t size_hint); - -void **git_vector_detach(size_t *size, size_t *asize, git_vector *v); - -void git_vector_sort(git_vector *v); - -/** Linear search for matching entry using internal comparison function */ -int git_vector_search(size_t *at_pos, const git_vector *v, const void *entry); - -/** Linear search for matching entry using explicit comparison function */ -int git_vector_search2(size_t *at_pos, const git_vector *v, git_vector_cmp cmp, const void *key); - -/** - * Binary search for matching entry using explicit comparison function that - * returns position where item would go if not found. - */ -int git_vector_bsearch2( - size_t *at_pos, git_vector *v, git_vector_cmp cmp, const void *key); - -/** Binary search for matching entry using internal comparison function */ -GIT_INLINE(int) git_vector_bsearch(size_t *at_pos, git_vector *v, const void *key) -{ - return git_vector_bsearch2(at_pos, v, v->_cmp, key); -} - -GIT_INLINE(void *) git_vector_get(const git_vector *v, size_t position) -{ - return (position < v->length) ? v->contents[position] : NULL; -} - -#define GIT_VECTOR_GET(V,I) ((I) < (V)->length ? (V)->contents[(I)] : NULL) - -GIT_INLINE(size_t) git_vector_length(const git_vector *v) -{ - return v->length; -} - -GIT_INLINE(void *) git_vector_last(const git_vector *v) -{ - return (v->length > 0) ? git_vector_get(v, v->length - 1) : NULL; -} - -#define git_vector_foreach(v, iter, elem) \ - for ((iter) = 0; (iter) < (v)->length && ((elem) = (v)->contents[(iter)], 1); (iter)++ ) - -#define git_vector_rforeach(v, iter, elem) \ - for ((iter) = (v)->length - 1; (iter) < SIZE_MAX && ((elem) = (v)->contents[(iter)], 1); (iter)-- ) - -int git_vector_insert(git_vector *v, void *element); -int git_vector_insert_sorted(git_vector *v, void *element, - int (*on_dup)(void **old, void *new)); -int git_vector_remove(git_vector *v, size_t idx); -void git_vector_pop(git_vector *v); -void git_vector_uniq(git_vector *v, void (*git_free_cb)(void *)); - -void git_vector_remove_matching( - git_vector *v, - int (*match)(const git_vector *v, size_t idx, void *payload), - void *payload); - -int git_vector_resize_to(git_vector *v, size_t new_length); -int git_vector_insert_null(git_vector *v, size_t idx, size_t insert_len); -int git_vector_remove_range(git_vector *v, size_t idx, size_t remove_len); - -int git_vector_set(void **old, git_vector *v, size_t position, void *value); - -/** Check if vector is sorted */ -#define git_vector_is_sorted(V) (((V)->flags & GIT_VECTOR_SORTED) != 0) - -/** Directly set sorted state of vector */ -#define git_vector_set_sorted(V,S) do { \ - (V)->flags = (S) ? ((V)->flags | GIT_VECTOR_SORTED) : \ - ((V)->flags & ~GIT_VECTOR_SORTED); } while (0) - -/** Set the comparison function used for sorting the vector */ -GIT_INLINE(void) git_vector_set_cmp(git_vector *v, git_vector_cmp cmp) -{ - if (cmp != v->_cmp) { - v->_cmp = cmp; - git_vector_set_sorted(v, 0); - } -} - -/* Just use this in tests, not for realz. returns -1 if not sorted */ -int git_vector_verify_sorted(const git_vector *v); - -/** - * Reverse the vector in-place. - */ -void git_vector_reverse(git_vector *v); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/wildmatch.c b/vendor/libgit2-sys/libgit2/src/util/wildmatch.c deleted file mode 100644 index a894e48..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/wildmatch.c +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - * - * Do shell-style pattern matching for ?, \, [], and * characters. - * It is 8bit clean. - * - * Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. - * Rich $alz is now . - * - * Modified by Wayne Davison to special-case '/' matching, to make '**' - * work differently than '*', and to fix the character-class code. - * - * Imported from git.git. - */ - -#include "wildmatch.h" - -#define GIT_SPACE 0x01 -#define GIT_DIGIT 0x02 -#define GIT_ALPHA 0x04 -#define GIT_GLOB_SPECIAL 0x08 -#define GIT_REGEX_SPECIAL 0x10 -#define GIT_PATHSPEC_MAGIC 0x20 -#define GIT_CNTRL 0x40 -#define GIT_PUNCT 0x80 - -enum { - S = GIT_SPACE, - A = GIT_ALPHA, - D = GIT_DIGIT, - G = GIT_GLOB_SPECIAL, /* *, ?, [, \\ */ - R = GIT_REGEX_SPECIAL, /* $, (, ), +, ., ^, {, | */ - P = GIT_PATHSPEC_MAGIC, /* other non-alnum, except for ] and } */ - X = GIT_CNTRL, - U = GIT_PUNCT, - Z = GIT_CNTRL | GIT_SPACE -}; - -static const unsigned char sane_ctype[256] = { - X, X, X, X, X, X, X, X, X, Z, Z, X, X, Z, X, X, /* 0.. 15 */ - X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, /* 16.. 31 */ - S, P, P, P, R, P, P, P, R, R, G, R, P, P, R, P, /* 32.. 47 */ - D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, G, /* 48.. 63 */ - P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, /* 64.. 79 */ - A, A, A, A, A, A, A, A, A, A, A, G, G, U, R, P, /* 80.. 95 */ - P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, /* 96..111 */ - A, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X, /* 112..127 */ - /* Nothing in the 128.. range */ -}; - -#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) -#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL) - -typedef unsigned char uchar; - -/* What character marks an inverted character class? */ -#define NEGATE_CLASS '!' -#define NEGATE_CLASS2 '^' - -#define CC_EQ(class, len, litmatch) ((len) == sizeof (litmatch)-1 \ - && *(class) == *(litmatch) \ - && strncmp((char*)class, litmatch, len) == 0) - -#if defined STDC_HEADERS || !defined isascii -# define ISASCII(c) 1 -#else -# define ISASCII(c) isascii(c) -#endif - -#ifdef isblank -# define ISBLANK(c) (ISASCII(c) && isblank(c)) -#else -# define ISBLANK(c) ((c) == ' ' || (c) == '\t') -#endif - -#ifdef isgraph -# define ISGRAPH(c) (ISASCII(c) && isgraph(c)) -#else -# define ISGRAPH(c) (ISASCII(c) && isprint(c) && !isspace(c)) -#endif - -#define ISPRINT(c) (ISASCII(c) && isprint(c)) -#define ISDIGIT(c) (ISASCII(c) && isdigit(c)) -#define ISALNUM(c) (ISASCII(c) && isalnum(c)) -#define ISALPHA(c) (ISASCII(c) && isalpha(c)) -#define ISCNTRL(c) (ISASCII(c) && iscntrl(c)) -#define ISLOWER(c) (ISASCII(c) && islower(c)) -#define ISPUNCT(c) (ISASCII(c) && ispunct(c)) -#define ISSPACE(c) (ISASCII(c) && isspace(c)) -#define ISUPPER(c) (ISASCII(c) && isupper(c)) -#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c)) - -/* Match pattern "p" against "text" */ -static int dowild(const uchar *p, const uchar *text, unsigned int flags) -{ - uchar p_ch; - const uchar *pattern = p; - - for ( ; (p_ch = *p) != '\0'; text++, p++) { - int matched, match_slash, negated; - uchar t_ch, prev_ch; - if ((t_ch = *text) == '\0' && p_ch != '*') - return WM_ABORT_ALL; - if ((flags & WM_CASEFOLD) && ISUPPER(t_ch)) - t_ch = tolower(t_ch); - if ((flags & WM_CASEFOLD) && ISUPPER(p_ch)) - p_ch = tolower(p_ch); - switch (p_ch) { - case '\\': - /* Literal match with following character. Note that the test - * in "default" handles the p[1] == '\0' failure case. */ - p_ch = *++p; - /* FALLTHROUGH */ - default: - if (t_ch != p_ch) - return WM_NOMATCH; - continue; - case '?': - /* Match anything but '/'. */ - if ((flags & WM_PATHNAME) && t_ch == '/') - return WM_NOMATCH; - continue; - case '*': - if (*++p == '*') { - const uchar *prev_p = p - 2; - while (*++p == '*') {} - if (!(flags & WM_PATHNAME)) - /* without WM_PATHNAME, '*' == '**' */ - match_slash = 1; - else if ((prev_p < pattern || *prev_p == '/') && - (*p == '\0' || *p == '/' || - (p[0] == '\\' && p[1] == '/'))) { - /* - * Assuming we already match 'foo/' and are at - * , just assume it matches - * nothing and go ahead match the rest of the - * pattern with the remaining string. This - * helps make foo/<*><*>/bar (<> because - * otherwise it breaks C comment syntax) match - * both foo/bar and foo/a/bar. - */ - if (p[0] == '/' && - dowild(p + 1, text, flags) == WM_MATCH) - return WM_MATCH; - match_slash = 1; - } else /* WM_PATHNAME is set */ - match_slash = 0; - } else - /* without WM_PATHNAME, '*' == '**' */ - match_slash = flags & WM_PATHNAME ? 0 : 1; - if (*p == '\0') { - /* Trailing "**" matches everything. Trailing "*" matches - * only if there are no more slash characters. */ - if (!match_slash) { - if (strchr((char*)text, '/') != NULL) - return WM_NOMATCH; - } - return WM_MATCH; - } else if (!match_slash && *p == '/') { - /* - * _one_ asterisk followed by a slash - * with WM_PATHNAME matches the next - * directory - */ - const char *slash = strchr((char*)text, '/'); - if (!slash) - return WM_NOMATCH; - text = (const uchar*)slash; - /* the slash is consumed by the top-level for loop */ - break; - } - while (1) { - if (t_ch == '\0') - break; - /* - * Try to advance faster when an asterisk is - * followed by a literal. We know in this case - * that the string before the literal - * must belong to "*". - * If match_slash is false, do not look past - * the first slash as it cannot belong to '*'. - */ - if (!is_glob_special(*p)) { - p_ch = *p; - if ((flags & WM_CASEFOLD) && ISUPPER(p_ch)) - p_ch = tolower(p_ch); - while ((t_ch = *text) != '\0' && - (match_slash || t_ch != '/')) { - if ((flags & WM_CASEFOLD) && ISUPPER(t_ch)) - t_ch = tolower(t_ch); - if (t_ch == p_ch) - break; - text++; - } - if (t_ch != p_ch) - return WM_NOMATCH; - } - if ((matched = dowild(p, text, flags)) != WM_NOMATCH) { - if (!match_slash || matched != WM_ABORT_TO_STARSTAR) - return matched; - } else if (!match_slash && t_ch == '/') - return WM_ABORT_TO_STARSTAR; - t_ch = *++text; - } - return WM_ABORT_ALL; - case '[': - p_ch = *++p; -#ifdef NEGATE_CLASS2 - if (p_ch == NEGATE_CLASS2) - p_ch = NEGATE_CLASS; -#endif - /* Assign literal 1/0 because of "matched" comparison. */ - negated = p_ch == NEGATE_CLASS ? 1 : 0; - if (negated) { - /* Inverted character class. */ - p_ch = *++p; - } - prev_ch = 0; - matched = 0; - do { - if (!p_ch) - return WM_ABORT_ALL; - if (p_ch == '\\') { - p_ch = *++p; - if (!p_ch) - return WM_ABORT_ALL; - if (t_ch == p_ch) - matched = 1; - } else if (p_ch == '-' && prev_ch && p[1] && p[1] != ']') { - p_ch = *++p; - if (p_ch == '\\') { - p_ch = *++p; - if (!p_ch) - return WM_ABORT_ALL; - } - if (t_ch <= p_ch && t_ch >= prev_ch) - matched = 1; - else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) { - uchar t_ch_upper = toupper(t_ch); - if (t_ch_upper <= p_ch && t_ch_upper >= prev_ch) - matched = 1; - } - p_ch = 0; /* This makes "prev_ch" get set to 0. */ - } else if (p_ch == '[' && p[1] == ':') { - const uchar *s; - int i; - for (s = p += 2; (p_ch = *p) && p_ch != ']'; p++) {} /*SHARED ITERATOR*/ - if (!p_ch) - return WM_ABORT_ALL; - i = (int)(p - s - 1); - if (i < 0 || p[-1] != ':') { - /* Didn't find ":]", so treat like a normal set. */ - p = s - 2; - p_ch = '['; - if (t_ch == p_ch) - matched = 1; - continue; - } - if (CC_EQ(s,i, "alnum")) { - if (ISALNUM(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "alpha")) { - if (ISALPHA(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "blank")) { - if (ISBLANK(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "cntrl")) { - if (ISCNTRL(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "digit")) { - if (ISDIGIT(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "graph")) { - if (ISGRAPH(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "lower")) { - if (ISLOWER(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "print")) { - if (ISPRINT(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "punct")) { - if (ISPUNCT(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "space")) { - if (ISSPACE(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "upper")) { - if (ISUPPER(t_ch)) - matched = 1; - else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) - matched = 1; - } else if (CC_EQ(s,i, "xdigit")) { - if (ISXDIGIT(t_ch)) - matched = 1; - } else /* malformed [:class:] string */ - return WM_ABORT_ALL; - p_ch = 0; /* This makes "prev_ch" get set to 0. */ - } else if (t_ch == p_ch) - matched = 1; - } while (prev_ch = p_ch, (p_ch = *++p) != ']'); - if (matched == negated || - ((flags & WM_PATHNAME) && t_ch == '/')) - return WM_NOMATCH; - continue; - } - } - - return *text ? WM_NOMATCH : WM_MATCH; -} - -/* Match the "pattern" against the "text" string. */ -int wildmatch(const char *pattern, const char *text, unsigned int flags) -{ - return dowild((const uchar*)pattern, (const uchar*)text, flags); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/wildmatch.h b/vendor/libgit2-sys/libgit2/src/util/wildmatch.h deleted file mode 100644 index f206405..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/wildmatch.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_wildmatch_h__ -#define INCLUDE_wildmatch_h__ - -#include "git2_util.h" - -#define WM_CASEFOLD 1 -#define WM_PATHNAME 2 - -#define WM_NOMATCH 1 -#define WM_MATCH 0 -#define WM_ABORT_ALL -1 -#define WM_ABORT_TO_STARSTAR -2 - -int wildmatch(const char *pattern, const char *text, unsigned int flags); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/dir.c b/vendor/libgit2-sys/libgit2/src/util/win32/dir.c deleted file mode 100644 index 44052ca..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/dir.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "dir.h" - -#define GIT__WIN32_NO_WRAP_DIR -#include "posix.h" - -git__DIR *git__opendir(const char *dir) -{ - git_win32_path filter_w; - git__DIR *new = NULL; - size_t dirlen, alloclen; - - if (!dir || !git_win32__findfirstfile_filter(filter_w, dir)) - return NULL; - - dirlen = strlen(dir); - - if (GIT_ADD_SIZET_OVERFLOW(&alloclen, sizeof(*new), dirlen) || - GIT_ADD_SIZET_OVERFLOW(&alloclen, alloclen, 1) || - !(new = git__calloc(1, alloclen))) - return NULL; - - memcpy(new->dir, dir, dirlen); - - new->h = FindFirstFileW(filter_w, &new->f); - - if (new->h == INVALID_HANDLE_VALUE) { - git_error_set(GIT_ERROR_OS, "could not open directory '%s'", dir); - git__free(new); - return NULL; - } - - new->first = 1; - return new; -} - -int git__readdir_ext( - git__DIR *d, - struct git__dirent *entry, - struct git__dirent **result, - int *is_dir) -{ - if (!d || !entry || !result || d->h == INVALID_HANDLE_VALUE) - return -1; - - *result = NULL; - - if (d->first) - d->first = 0; - else if (!FindNextFileW(d->h, &d->f)) { - if (GetLastError() == ERROR_NO_MORE_FILES) - return 0; - git_error_set(GIT_ERROR_OS, "could not read from directory '%s'", d->dir); - return -1; - } - - /* Convert the path to UTF-8 */ - if (git_win32_path_to_utf8(entry->d_name, d->f.cFileName) < 0) - return -1; - - entry->d_ino = 0; - - *result = entry; - - if (is_dir != NULL) - *is_dir = ((d->f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); - - return 0; -} - -struct git__dirent *git__readdir(git__DIR *d) -{ - struct git__dirent *result; - if (git__readdir_ext(d, &d->entry, &result, NULL) < 0) - return NULL; - return result; -} - -void git__rewinddir(git__DIR *d) -{ - git_win32_path filter_w; - - if (!d) - return; - - if (d->h != INVALID_HANDLE_VALUE) { - FindClose(d->h); - d->h = INVALID_HANDLE_VALUE; - d->first = 0; - } - - if (!git_win32__findfirstfile_filter(filter_w, d->dir)) - return; - - d->h = FindFirstFileW(filter_w, &d->f); - - if (d->h == INVALID_HANDLE_VALUE) - git_error_set(GIT_ERROR_OS, "could not open directory '%s'", d->dir); - else - d->first = 1; -} - -int git__closedir(git__DIR *d) -{ - if (!d) - return 0; - - if (d->h != INVALID_HANDLE_VALUE) { - FindClose(d->h); - d->h = INVALID_HANDLE_VALUE; - } - - git__free(d); - return 0; -} - diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/dir.h b/vendor/libgit2-sys/libgit2/src/util/win32/dir.h deleted file mode 100644 index 8101115..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/dir.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_dir_h__ -#define INCLUDE_win32_dir_h__ - -#include "git2_util.h" - -#include "w32_util.h" - -struct git__dirent { - int d_ino; - git_win32_utf8_path d_name; -}; - -typedef struct { - HANDLE h; - WIN32_FIND_DATAW f; - struct git__dirent entry; - int first; - char dir[GIT_FLEX_ARRAY]; -} git__DIR; - -extern git__DIR *git__opendir(const char *); -extern struct git__dirent *git__readdir(git__DIR *); -extern int git__readdir_ext( - git__DIR *, struct git__dirent *, struct git__dirent **, int *); -extern void git__rewinddir(git__DIR *); -extern int git__closedir(git__DIR *); - -# ifndef GIT__WIN32_NO_WRAP_DIR -# define dirent git__dirent -# define DIR git__DIR -# define opendir git__opendir -# define readdir git__readdir -# define readdir_r(d,e,r) git__readdir_ext((d),(e),(r),NULL) -# define rewinddir git__rewinddir -# define closedir git__closedir -# endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/error.c b/vendor/libgit2-sys/libgit2/src/util/win32/error.c deleted file mode 100644 index dfd6fa1..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/error.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "error.h" - -#include "utf-conv.h" - -#ifdef GIT_WINHTTP -# include -#endif - -char *git_win32_get_error_message(DWORD error_code) -{ - LPWSTR lpMsgBuf = NULL; - HMODULE hModule = NULL; - char *utf8_msg = NULL; - DWORD dwFlags = - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS; - - if (!error_code) - return NULL; - -#ifdef GIT_WINHTTP - /* Errors raised by WinHTTP are not in the system resource table */ - if (error_code >= WINHTTP_ERROR_BASE && - error_code <= WINHTTP_ERROR_LAST) - hModule = GetModuleHandleW(L"winhttp"); -#endif - - GIT_UNUSED(hModule); - - if (hModule) - dwFlags |= FORMAT_MESSAGE_FROM_HMODULE; - else - dwFlags |= FORMAT_MESSAGE_FROM_SYSTEM; - - if (FormatMessageW(dwFlags, hModule, error_code, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPWSTR)&lpMsgBuf, 0, NULL)) { - /* Convert the message to UTF-8. If this fails, we will - * return NULL, which is a condition expected by the caller */ - if (git_utf8_from_16_alloc(&utf8_msg, lpMsgBuf) < 0) - utf8_msg = NULL; - - LocalFree(lpMsgBuf); - } - - return utf8_msg; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/error.h b/vendor/libgit2-sys/libgit2/src/util/win32/error.h deleted file mode 100644 index fd53b7f..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/error.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_win32_error_h__ -#define INCLUDE_win32_error_h__ - -#include "git2_util.h" - -extern char *git_win32_get_error_message(DWORD error_code); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/map.c b/vendor/libgit2-sys/libgit2/src/util/win32/map.c deleted file mode 100644 index 52e1363..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/map.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" - -#include "map.h" -#include - -#ifndef NO_MMAP - -static DWORD get_page_size(void) -{ - static DWORD page_size; - SYSTEM_INFO sys; - - if (!page_size) { - GetSystemInfo(&sys); - page_size = sys.dwPageSize; - } - - return page_size; -} - -static DWORD get_allocation_granularity(void) -{ - static DWORD granularity; - SYSTEM_INFO sys; - - if (!granularity) { - GetSystemInfo(&sys); - granularity = sys.dwAllocationGranularity; - } - - return granularity; -} - -int git__page_size(size_t *page_size) -{ - *page_size = get_page_size(); - return 0; -} - -int git__mmap_alignment(size_t *page_size) -{ - *page_size = get_allocation_granularity(); - return 0; -} - -int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset) -{ - HANDLE fh = (HANDLE)_get_osfhandle(fd); - DWORD alignment = get_allocation_granularity(); - DWORD fmap_prot = 0; - DWORD view_prot = 0; - DWORD off_low = 0; - DWORD off_hi = 0; - off64_t page_start; - off64_t page_offset; - - GIT_MMAP_VALIDATE(out, len, prot, flags); - - out->data = NULL; - out->len = 0; - out->fmh = NULL; - - if (fh == INVALID_HANDLE_VALUE) { - errno = EBADF; - git_error_set(GIT_ERROR_OS, "failed to mmap. Invalid handle value"); - return -1; - } - - if (prot & GIT_PROT_WRITE) - fmap_prot |= PAGE_READWRITE; - else if (prot & GIT_PROT_READ) - fmap_prot |= PAGE_READONLY; - - if (prot & GIT_PROT_WRITE) - view_prot |= FILE_MAP_WRITE; - if (prot & GIT_PROT_READ) - view_prot |= FILE_MAP_READ; - - page_start = (offset / alignment) * alignment; - page_offset = offset - page_start; - - if (page_offset != 0) { /* offset must be multiple of the allocation granularity */ - errno = EINVAL; - git_error_set(GIT_ERROR_OS, "failed to mmap. Offset must be multiple of allocation granularity"); - return -1; - } - - out->fmh = CreateFileMapping(fh, NULL, fmap_prot, 0, 0, NULL); - if (!out->fmh || out->fmh == INVALID_HANDLE_VALUE) { - git_error_set(GIT_ERROR_OS, "failed to mmap. Invalid handle value"); - out->fmh = NULL; - return -1; - } - - off_low = (DWORD)(page_start); - off_hi = (DWORD)(page_start >> 32); - out->data = MapViewOfFile(out->fmh, view_prot, off_hi, off_low, len); - if (!out->data) { - git_error_set(GIT_ERROR_OS, "failed to mmap. No data written"); - CloseHandle(out->fmh); - out->fmh = NULL; - return -1; - } - out->len = len; - - return 0; -} - -int p_munmap(git_map *map) -{ - int error = 0; - - GIT_ASSERT_ARG(map); - - if (map->data) { - if (!UnmapViewOfFile(map->data)) { - git_error_set(GIT_ERROR_OS, "failed to munmap. Could not unmap view of file"); - error = -1; - } - map->data = NULL; - } - - if (map->fmh) { - if (!CloseHandle(map->fmh)) { - git_error_set(GIT_ERROR_OS, "failed to munmap. Could not close handle"); - error = -1; - } - map->fmh = NULL; - } - - return error; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/mingw-compat.h b/vendor/libgit2-sys/libgit2/src/util/win32/mingw-compat.h deleted file mode 100644 index aa2bef9..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/mingw-compat.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_mingw_compat_h__ -#define INCLUDE_win32_mingw_compat_h__ - -#if defined(__MINGW32__) - -#undef stat - -#if _WIN32_WINNT < 0x0600 && !defined(__MINGW64_VERSION_MAJOR) -#undef MemoryBarrier -void __mingworg_MemoryBarrier(void); -#define MemoryBarrier __mingworg_MemoryBarrier -#define VOLUME_NAME_DOS 0x0 -#endif - -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/msvc-compat.h b/vendor/libgit2-sys/libgit2/src/util/win32/msvc-compat.h deleted file mode 100644 index 03f9f36..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/msvc-compat.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_msvc_compat_h__ -#define INCLUDE_win32_msvc_compat_h__ - -#if defined(_MSC_VER) - -typedef unsigned short mode_t; -typedef SSIZE_T ssize_t; - -#ifdef _WIN64 -# define SSIZE_MAX _I64_MAX -#else -# define SSIZE_MAX LONG_MAX -#endif - -#define strcasecmp(s1, s2) _stricmp(s1, s2) -#define strncasecmp(s1, s2, c) _strnicmp(s1, s2, c) - -#endif - -/* - * Offer GIT_LIBGIT2_CALL for our calling conventions (__cdecl, always). - * This is useful for providing callbacks to userspace code. - * - * Offer GIT_SYSTEM_CALL for the system calling conventions (__stdcall on - * Win32). Useful for providing callbacks to system libraries. - */ -#define GIT_LIBGIT2_CALL __cdecl -#define GIT_SYSTEM_CALL NTAPI - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/path_w32.c b/vendor/libgit2-sys/libgit2/src/util/win32/path_w32.c deleted file mode 100644 index 2714efb..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/path_w32.c +++ /dev/null @@ -1,718 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "path_w32.h" - -#include "fs_path.h" -#include "utf-conv.h" -#include "posix.h" -#include "reparse.h" -#include "dir.h" - -#define PATH__NT_NAMESPACE L"\\\\?\\" -#define PATH__NT_NAMESPACE_LEN 4 - -#define PATH__ABSOLUTE_LEN 3 - -#define path__is_nt_namespace(p) \ - (((p)[0] == '\\' && (p)[1] == '\\' && (p)[2] == '?' && (p)[3] == '\\') || \ - ((p)[0] == '/' && (p)[1] == '/' && (p)[2] == '?' && (p)[3] == '/')) - -#define path__is_unc(p) \ - (((p)[0] == '\\' && (p)[1] == '\\') || ((p)[0] == '/' && (p)[1] == '/')) - -#define path__startswith_slash(p) \ - ((p)[0] == '\\' || (p)[0] == '/') - -GIT_INLINE(int) path__cwd(wchar_t *path, int size) -{ - int len; - - if ((len = GetCurrentDirectoryW(size, path)) == 0) { - errno = GetLastError() == ERROR_ACCESS_DENIED ? EACCES : ENOENT; - return -1; - } else if (len > size) { - errno = ENAMETOOLONG; - return -1; - } - - /* The Win32 APIs may return "\\?\" once you've used it first. - * But it may not. What a gloriously predictable API! - */ - if (wcsncmp(path, PATH__NT_NAMESPACE, PATH__NT_NAMESPACE_LEN)) - return len; - - len -= PATH__NT_NAMESPACE_LEN; - - memmove(path, path + PATH__NT_NAMESPACE_LEN, sizeof(wchar_t) * len); - return len; -} - -static wchar_t *path__skip_server(wchar_t *path) -{ - wchar_t *c; - - for (c = path; *c; c++) { - if (git_fs_path_is_dirsep(*c)) - return c + 1; - } - - return c; -} - -static wchar_t *path__skip_prefix(wchar_t *path) -{ - if (path__is_nt_namespace(path)) { - path += PATH__NT_NAMESPACE_LEN; - - if (wcsncmp(path, L"UNC\\", 4) == 0) - path = path__skip_server(path + 4); - else if (git_fs_path_is_absolute(path)) - path += PATH__ABSOLUTE_LEN; - } else if (git_fs_path_is_absolute(path)) { - path += PATH__ABSOLUTE_LEN; - } else if (path__is_unc(path)) { - path = path__skip_server(path + 2); - } - - return path; -} - -int git_win32_path_canonicalize(git_win32_path path) -{ - wchar_t *base, *from, *to, *next; - size_t len; - - base = to = path__skip_prefix(path); - - /* Unposixify if the prefix */ - for (from = path; from < to; from++) { - if (*from == L'/') - *from = L'\\'; - } - - while (*from) { - for (next = from; *next; ++next) { - if (*next == L'/') { - *next = L'\\'; - break; - } - - if (*next == L'\\') - break; - } - - len = next - from; - - if (len == 1 && from[0] == L'.') - /* do nothing with singleton dot */; - - else if (len == 2 && from[0] == L'.' && from[1] == L'.') { - if (to == base) { - /* no more path segments to strip, eat the "../" */ - if (*next == L'\\') - len++; - - base = to; - } else { - /* back up a path segment */ - while (to > base && to[-1] == L'\\') to--; - while (to > base && to[-1] != L'\\') to--; - } - } else { - if (*next == L'\\' && *from != L'\\') - len++; - - if (to != from) - memmove(to, from, sizeof(wchar_t) * len); - - to += len; - } - - from += len; - - while (*from == L'\\') from++; - } - - /* Strip trailing backslashes */ - while (to > base && to[-1] == L'\\') to--; - - *to = L'\0'; - - if ((to - path) > INT_MAX) { - SetLastError(ERROR_FILENAME_EXCED_RANGE); - return -1; - } - - return (int)(to - path); -} - -static int git_win32_path_join( - git_win32_path dest, - size_t *dest_len, - const wchar_t *one, - size_t one_len, - const wchar_t *two, - size_t two_len) -{ - size_t backslash = 0; - - if (one_len && two_len && one[one_len - 1] != L'\\') - backslash = 1; - - if (one_len + two_len + backslash > MAX_PATH) { - git_error_set(GIT_ERROR_INVALID, "path too long"); - return -1; - } - - memmove(dest, one, one_len * sizeof(wchar_t)); - - if (backslash) - dest[one_len] = L'\\'; - - memcpy(dest + one_len + backslash, two, two_len * sizeof(wchar_t)); - dest[one_len + backslash + two_len] = L'\0'; - - if (dest_len) - *dest_len = one_len + backslash + two_len; - - return 0; -} - -struct win32_path_iter { - wchar_t *env; - const wchar_t *current_dir; -}; - -static int win32_path_iter_init(struct win32_path_iter *iter) -{ - DWORD len = GetEnvironmentVariableW(L"PATH", NULL, 0); - - if (!len && GetLastError() == ERROR_ENVVAR_NOT_FOUND) { - iter->env = NULL; - iter->current_dir = NULL; - return 0; - } else if (!len) { - git_error_set(GIT_ERROR_OS, "could not load PATH"); - return -1; - } - - iter->env = git__malloc(len * sizeof(wchar_t)); - GIT_ERROR_CHECK_ALLOC(iter->env); - - len = GetEnvironmentVariableW(L"PATH", iter->env, len); - - if (len == 0) { - git_error_set(GIT_ERROR_OS, "could not load PATH"); - return -1; - } - - iter->current_dir = iter->env; - return 0; -} - -static int win32_path_iter_next( - const wchar_t **out, - size_t *out_len, - struct win32_path_iter *iter) -{ - const wchar_t *start; - wchar_t term; - size_t len = 0; - - if (!iter->current_dir || !*iter->current_dir) - return GIT_ITEROVER; - - term = (*iter->current_dir == L'"') ? *iter->current_dir++ : L';'; - start = iter->current_dir; - - while (*iter->current_dir && *iter->current_dir != term) { - iter->current_dir++; - len++; - } - - *out = start; - *out_len = len; - - if (term == L'"' && *iter->current_dir) - iter->current_dir++; - - while (*iter->current_dir == L';') - iter->current_dir++; - - return 0; -} - -static void win32_path_iter_dispose(struct win32_path_iter *iter) -{ - if (!iter) - return; - - git__free(iter->env); - iter->env = NULL; - iter->current_dir = NULL; -} - -struct executable_suffix { - const wchar_t *suffix; - size_t len; -}; - -static struct executable_suffix suffixes[] = { { NULL, 0 }, { L".exe", 4 }, { L".cmd", 4 } }; - -static bool has_executable_suffix(wchar_t *exe, size_t exe_len) -{ - size_t i; - - for (i = 0; i < ARRAY_SIZE(suffixes); i++) { - struct executable_suffix *suffix = &suffixes[i]; - - if (!suffix->len) - continue; - - if (exe_len < suffix->len) - continue; - - if (memcmp(&exe[exe_len - suffix->len], suffix->suffix, suffix->len) == 0) - return true; - } - - return false; -} - -static int is_executable(git_win32_path path, size_t path_len, bool suffixed) -{ - size_t i; - - /* - * if the given name has an executable suffix, then try looking for it - * directly. in all cases, append executable extensions - * (".exe", ".cmd"...) - */ - for (i = suffixed ? 0 : 1; i < ARRAY_SIZE(suffixes); i++) { - struct executable_suffix *suffix = &suffixes[i]; - - if (suffix->len) { - if (path_len + suffix->len > MAX_PATH) - continue; - - wcscat(path, suffix->suffix); - } - - if (_waccess(path, 0) == 0) - return true; - - path[path_len] = L'\0'; - } - - return false; -} - -int git_win32_path_find_executable(git_win32_path fullpath, wchar_t *exe) -{ - struct win32_path_iter path_iter; - const wchar_t *dir; - size_t dir_len, exe_len, fullpath_len; - bool suffixed = false, found = false; - - if ((exe_len = wcslen(exe)) > MAX_PATH) - goto done; - - /* see if the given executable has an executable suffix; if so we will - * look for the explicit name directly, as well as with added suffixes. - */ - suffixed = has_executable_suffix(exe, exe_len); - - /* For fully-qualified paths we do not look in PATH */ - if (wcschr(exe, L'\\') != NULL || wcschr(exe, L'/') != NULL) { - if ((found = is_executable(exe, exe_len, suffixed))) - wcscpy(fullpath, exe); - - goto done; - } - - if (win32_path_iter_init(&path_iter) < 0) - return -1; - - while (win32_path_iter_next(&dir, &dir_len, &path_iter) != GIT_ITEROVER && !found) { - if (git_win32_path_join(fullpath, &fullpath_len, dir, dir_len, exe, exe_len) < 0) - continue; - - if (is_executable(fullpath, fullpath_len, suffixed)) { - found = true; - break; - } - } - - win32_path_iter_dispose(&path_iter); - -done: - if (found) - return 0; - - fullpath[0] = L'\0'; - return GIT_ENOTFOUND; -} - -static int win32_path_cwd(wchar_t *out, size_t len) -{ - int cwd_len; - - if (len > INT_MAX) { - errno = ENAMETOOLONG; - return -1; - } - - if ((cwd_len = path__cwd(out, (int)len)) < 0) - return -1; - - /* UNC paths */ - if (wcsncmp(L"\\\\", out, 2) == 0) { - /* Our buffer must be at least 5 characters larger than the - * current working directory: we swallow one of the leading - * '\'s, but we we add a 'UNC' specifier to the path, plus - * a trailing directory separator, plus a NUL. - */ - if (cwd_len > GIT_WIN_PATH_MAX - 4) { - errno = ENAMETOOLONG; - return -1; - } - - memmove(out+2, out, sizeof(wchar_t) * cwd_len); - out[0] = L'U'; - out[1] = L'N'; - out[2] = L'C'; - - cwd_len += 2; - } - - /* Our buffer must be at least 2 characters larger than the current - * working directory. (One character for the directory separator, - * one for the null. - */ - else if (cwd_len > GIT_WIN_PATH_MAX - 2) { - errno = ENAMETOOLONG; - return -1; - } - - return cwd_len; -} - -int git_win32_path_from_utf8(git_win32_path out, const char *src) -{ - wchar_t *dest = out; - - /* All win32 paths are in NT-prefixed format, beginning with "\\?\". */ - memcpy(dest, PATH__NT_NAMESPACE, sizeof(wchar_t) * PATH__NT_NAMESPACE_LEN); - dest += PATH__NT_NAMESPACE_LEN; - - /* See if this is an absolute path (beginning with a drive letter) */ - if (git_fs_path_is_absolute(src)) { - if (git_utf8_to_16(dest, GIT_WIN_PATH_MAX, src) < 0) - goto on_error; - } - /* File-prefixed NT-style paths beginning with \\?\ */ - else if (path__is_nt_namespace(src)) { - /* Skip the NT prefix, the destination already contains it */ - if (git_utf8_to_16(dest, GIT_WIN_PATH_MAX, src + PATH__NT_NAMESPACE_LEN) < 0) - goto on_error; - } - /* UNC paths */ - else if (path__is_unc(src)) { - memcpy(dest, L"UNC\\", sizeof(wchar_t) * 4); - dest += 4; - - /* Skip the leading "\\" */ - if (git_utf8_to_16(dest, GIT_WIN_PATH_MAX - 2, src + 2) < 0) - goto on_error; - } - /* Absolute paths omitting the drive letter */ - else if (path__startswith_slash(src)) { - if (path__cwd(dest, GIT_WIN_PATH_MAX) < 0) - goto on_error; - - if (!git_fs_path_is_absolute(dest)) { - errno = ENOENT; - goto on_error; - } - - /* Skip the drive letter specification ("C:") */ - if (git_utf8_to_16(dest + 2, GIT_WIN_PATH_MAX - 2, src) < 0) - goto on_error; - } - /* Relative paths */ - else { - int cwd_len; - - if ((cwd_len = win32_path_cwd(dest, GIT_WIN_PATH_MAX)) < 0) - goto on_error; - - dest[cwd_len++] = L'\\'; - - if (git_utf8_to_16(dest + cwd_len, GIT_WIN_PATH_MAX - cwd_len, src) < 0) - goto on_error; - } - - return git_win32_path_canonicalize(out); - -on_error: - /* set windows error code so we can use its error message */ - if (errno == ENAMETOOLONG) - SetLastError(ERROR_FILENAME_EXCED_RANGE); - - return -1; -} - -int git_win32_path_relative_from_utf8(git_win32_path out, const char *src) -{ - wchar_t *dest = out, *p; - int len; - - /* Handle absolute paths */ - if (git_fs_path_is_absolute(src) || - path__is_nt_namespace(src) || - path__is_unc(src) || - path__startswith_slash(src)) { - return git_win32_path_from_utf8(out, src); - } - - if ((len = git_utf8_to_16(dest, GIT_WIN_PATH_MAX, src)) < 0) - return -1; - - for (p = dest; p < (dest + len); p++) { - if (*p == L'/') - *p = L'\\'; - } - - return len; -} - -int git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src) -{ - char *out = dest; - int len; - - /* Strip NT namespacing "\\?\" */ - if (path__is_nt_namespace(src)) { - src += 4; - - /* "\\?\UNC\server\share" -> "\\server\share" */ - if (wcsncmp(src, L"UNC\\", 4) == 0) { - src += 4; - - memcpy(dest, "\\\\", 2); - out = dest + 2; - } - } - - if ((len = git_utf8_from_16(out, GIT_WIN_PATH_UTF8, src)) < 0) - return len; - - git_fs_path_mkposix(dest); - - return len; -} - -char *git_win32_path_8dot3_name(const char *path) -{ - git_win32_path longpath, shortpath; - wchar_t *start; - char *shortname; - int len, namelen = 1; - - if (git_win32_path_from_utf8(longpath, path) < 0) - return NULL; - - len = GetShortPathNameW(longpath, shortpath, GIT_WIN_PATH_UTF16); - - while (len && shortpath[len-1] == L'\\') - shortpath[--len] = L'\0'; - - if (len == 0 || len >= GIT_WIN_PATH_UTF16) - return NULL; - - for (start = shortpath + (len - 1); - start > shortpath && *(start-1) != '/' && *(start-1) != '\\'; - start--) - namelen++; - - /* We may not have actually been given a short name. But if we have, - * it will be in the ASCII byte range, so we don't need to worry about - * multi-byte sequences and can allocate naively. - */ - if (namelen > 12 || (shortname = git__malloc(namelen + 1)) == NULL) - return NULL; - - if ((len = git_utf8_from_16(shortname, namelen + 1, start)) < 0) - return NULL; - - return shortname; -} - -static bool path_is_volume(wchar_t *target, size_t target_len) -{ - return (target_len && wcsncmp(target, L"\\??\\Volume{", 11) == 0); -} - -/* On success, returns the length, in characters, of the path stored in dest. - * On failure, returns a negative value. */ -int git_win32_path_readlink_w(git_win32_path dest, const git_win32_path path) -{ - BYTE buf[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; - GIT_REPARSE_DATA_BUFFER *reparse_buf = (GIT_REPARSE_DATA_BUFFER *)buf; - HANDLE handle = NULL; - DWORD ioctl_ret; - wchar_t *target; - size_t target_len; - - int error = -1; - - handle = CreateFileW(path, GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, - FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL); - - if (handle == INVALID_HANDLE_VALUE) { - errno = ENOENT; - return -1; - } - - if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0, - reparse_buf, sizeof(buf), &ioctl_ret, NULL)) { - errno = EINVAL; - goto on_error; - } - - switch (reparse_buf->ReparseTag) { - case IO_REPARSE_TAG_SYMLINK: - target = reparse_buf->ReparseBuffer.SymbolicLink.PathBuffer + - (reparse_buf->ReparseBuffer.SymbolicLink.SubstituteNameOffset / sizeof(WCHAR)); - target_len = reparse_buf->ReparseBuffer.SymbolicLink.SubstituteNameLength / sizeof(WCHAR); - break; - case IO_REPARSE_TAG_MOUNT_POINT: - target = reparse_buf->ReparseBuffer.MountPoint.PathBuffer + - (reparse_buf->ReparseBuffer.MountPoint.SubstituteNameOffset / sizeof(WCHAR)); - target_len = reparse_buf->ReparseBuffer.MountPoint.SubstituteNameLength / sizeof(WCHAR); - break; - default: - errno = EINVAL; - goto on_error; - } - - if (path_is_volume(target, target_len)) { - /* This path is a reparse point that represents another volume mounted - * at this location, it is not a symbolic link our input was canonical. - */ - errno = EINVAL; - error = -1; - } else if (target_len) { - /* The path may need to have a namespace prefix removed. */ - target_len = git_win32_path_remove_namespace(target, target_len); - - /* Need one additional character in the target buffer - * for the terminating NULL. */ - if (GIT_WIN_PATH_UTF16 > target_len) { - wcscpy(dest, target); - error = (int)target_len; - } - } - -on_error: - CloseHandle(handle); - return error; -} - -/** - * Removes any trailing backslashes from a path, except in the case of a drive - * letter path (C:\, D:\, etc.). This function cannot fail. - * - * @param path The path which should be trimmed. - * @return The length of the modified string (<= the input length) - */ -size_t git_win32_path_trim_end(wchar_t *str, size_t len) -{ - while (1) { - if (!len || str[len - 1] != L'\\') - break; - - /* - * Don't trim backslashes from drive letter paths, which - * are 3 characters long and of the form C:\, D:\, etc. - */ - if (len == 3 && git_win32__isalpha(str[0]) && str[1] == ':') - break; - - len--; - } - - str[len] = L'\0'; - - return len; -} - -/** - * Removes any of the following namespace prefixes from a path, - * if found: "\??\", "\\?\", "\\?\UNC\". This function cannot fail. - * - * @param path The path which should be converted. - * @return The length of the modified string (<= the input length) - */ -size_t git_win32_path_remove_namespace(wchar_t *str, size_t len) -{ - static const wchar_t dosdevices_namespace[] = L"\\\?\?\\"; - static const wchar_t nt_namespace[] = L"\\\\?\\"; - static const wchar_t unc_namespace_remainder[] = L"UNC\\"; - static const wchar_t unc_prefix[] = L"\\\\"; - - const wchar_t *prefix = NULL, *remainder = NULL; - size_t prefix_len = 0, remainder_len = 0; - - /* "\??\" -- DOS Devices prefix */ - if (len >= CONST_STRLEN(dosdevices_namespace) && - !wcsncmp(str, dosdevices_namespace, CONST_STRLEN(dosdevices_namespace))) { - remainder = str + CONST_STRLEN(dosdevices_namespace); - remainder_len = len - CONST_STRLEN(dosdevices_namespace); - } - /* "\\?\" -- NT namespace prefix */ - else if (len >= CONST_STRLEN(nt_namespace) && - !wcsncmp(str, nt_namespace, CONST_STRLEN(nt_namespace))) { - remainder = str + CONST_STRLEN(nt_namespace); - remainder_len = len - CONST_STRLEN(nt_namespace); - } - - /* "\??\UNC\", "\\?\UNC\" -- UNC prefix */ - if (remainder_len >= CONST_STRLEN(unc_namespace_remainder) && - !wcsncmp(remainder, unc_namespace_remainder, CONST_STRLEN(unc_namespace_remainder))) { - - /* - * The proper Win32 path for a UNC share has "\\" at beginning of it - * and looks like "\\server\share\". So remove the - * UNC namespace and add a prefix of "\\" in its place. - */ - remainder += CONST_STRLEN(unc_namespace_remainder); - remainder_len -= CONST_STRLEN(unc_namespace_remainder); - - prefix = unc_prefix; - prefix_len = CONST_STRLEN(unc_prefix); - } - - /* - * Sanity check that the new string isn't longer than the old one. - * (This could only happen due to programmer error introducing a - * prefix longer than the namespace it replaces.) - */ - if (remainder && len >= remainder_len + prefix_len) { - if (prefix) - memmove(str, prefix, prefix_len * sizeof(wchar_t)); - - memmove(str + prefix_len, remainder, remainder_len * sizeof(wchar_t)); - - len = remainder_len + prefix_len; - str[len] = L'\0'; - } - - return git_win32_path_trim_end(str, len); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/path_w32.h b/vendor/libgit2-sys/libgit2/src/util/win32/path_w32.h deleted file mode 100644 index b241d5c..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/path_w32.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_path_w32_h__ -#define INCLUDE_win32_path_w32_h__ - -#include "git2_util.h" - -/** - * Create a Win32 path (in UCS-2 format) from a UTF-8 string. If the given - * path is relative, then it will be turned into an absolute path by having - * the current working directory prepended. - * - * @param dest The buffer to receive the wide string. - * @param src The UTF-8 string to convert. - * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure - */ -extern int git_win32_path_from_utf8(git_win32_path dest, const char *src); - -/** - * Create a Win32 path (in UCS-2 format) from a UTF-8 string. If the given - * path is relative, then it will not be turned into an absolute path. - * - * @param dest The buffer to receive the wide string. - * @param src The UTF-8 string to convert. - * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure - */ -extern int git_win32_path_relative_from_utf8(git_win32_path dest, const char *src); - -/** - * Canonicalize a Win32 UCS-2 path so that it is suitable for delivery to the - * Win32 APIs: remove multiple directory separators, squashing to a single one, - * strip trailing directory separators, ensure directory separators are all - * canonical (always backslashes, never forward slashes) and process any - * directory entries of '.' or '..'. - * - * Note that this is intended to be used on absolute Windows paths, those - * that start with `C:\`, `\\server\share`, `\\?\`, etc. - * - * This processes the buffer in place. - * - * @param path The buffer to process - * @return The new length of the buffer, in wchar_t's (not counting the NULL terminator) - */ -extern int git_win32_path_canonicalize(git_win32_path path); - -/** - * Create an internal format (posix-style) UTF-8 path from a Win32 UCS-2 path. - * - * @param dest The buffer to receive the UTF-8 string. - * @param src The wide string to convert. - * @return The length of the UTF-8 string, in bytes (not counting the NULL terminator), or < 0 for failure - */ -extern int git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src); - -/** - * Get the short name for the terminal path component in the given path. - * For example, given "C:\Foo\Bar\Asdf.txt", this will return the short name - * for the file "Asdf.txt". - * - * @param path The given path in UTF-8 - * @return The name of the shortname for the given path - */ -extern char *git_win32_path_8dot3_name(const char *path); - -extern int git_win32_path_readlink_w(git_win32_path dest, const git_win32_path path); - -/** - * Removes any trailing backslashes from a path, except in the case of a drive - * letter path (C:\, D:\, etc.). This function cannot fail. - * - * @param path The path which should be trimmed. - * @return The length of the modified string (<= the input length) - */ -size_t git_win32_path_trim_end(wchar_t *str, size_t len); - -/** - * Removes any of the following namespace prefixes from a path, - * if found: "\??\", "\\?\", "\\?\UNC\". This function cannot fail. - * - * @param path The path which should be converted. - * @return The length of the modified string (<= the input length) - */ -size_t git_win32_path_remove_namespace(wchar_t *str, size_t len); - -int git_win32_path_find_executable(git_win32_path fullpath, wchar_t* exe); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/posix.h b/vendor/libgit2-sys/libgit2/src/util/win32/posix.h deleted file mode 100644 index 03fa2ac..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/posix.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_posix_h__ -#define INCLUDE_win32_posix_h__ - -#include "git2_util.h" -#include "../posix.h" -#include "win32-compat.h" -#include "path_w32.h" -#include "utf-conv.h" -#include "dir.h" - -extern unsigned long git_win32__createfile_sharemode; -extern int git_win32__retries; - -typedef SOCKET GIT_SOCKET; - -#define p_lseek(f,n,w) _lseeki64(f, n, w) - -extern int p_fstat(int fd, struct stat *buf); -extern int p_lstat(const char *file_name, struct stat *buf); -extern int p_stat(const char *path, struct stat *buf); - -extern int p_utimes(const char *filename, const struct p_timeval times[2]); -extern int p_futimes(int fd, const struct p_timeval times[2]); - -extern int p_readlink(const char *path, char *buf, size_t bufsiz); -extern int p_symlink(const char *old, const char *new); -extern int p_link(const char *old, const char *new); -extern int p_unlink(const char *path); -extern int p_mkdir(const char *path, mode_t mode); -extern int p_fsync(int fd); -extern char *p_realpath(const char *orig_path, char *buffer); - -extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags); -extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags); -extern int p_inet_pton(int af, const char *src, void* dst); - -extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr); -extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4); -extern int p_chdir(const char *path); -extern int p_chmod(const char *path, mode_t mode); -extern int p_rmdir(const char *path); -extern int p_access(const char *path, mode_t mode); -extern int p_ftruncate(int fd, off64_t size); - -/* p_lstat is almost but not quite POSIX correct. Specifically, the use of - * ENOTDIR is wrong, in that it does not mean precisely that a non-directory - * entry was encountered. Making it correct is potentially expensive, - * however, so this is a separate version of p_lstat to use when correct - * POSIX ENOTDIR semantics is required. - */ -extern int p_lstat_posixly(const char *filename, struct stat *buf); - -extern struct tm * p_localtime_r(const time_t *timer, struct tm *result); -extern struct tm * p_gmtime_r(const time_t *timer, struct tm *result); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/posix_w32.c b/vendor/libgit2-sys/libgit2/src/util/win32/posix_w32.c deleted file mode 100644 index 7ace3b1..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/posix_w32.c +++ /dev/null @@ -1,1070 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "git2_util.h" - -#include "../posix.h" -#include "../futils.h" -#include "fs_path.h" -#include "path_w32.h" -#include "utf-conv.h" -#include "reparse.h" -#include -#include -#include -#include - -#ifndef FILE_NAME_NORMALIZED -# define FILE_NAME_NORMALIZED 0 -#endif - -#ifndef IO_REPARSE_TAG_SYMLINK -#define IO_REPARSE_TAG_SYMLINK (0xA000000CL) -#endif - -#ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE -# define SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE 0x02 -#endif - -#ifndef SYMBOLIC_LINK_FLAG_DIRECTORY -# define SYMBOLIC_LINK_FLAG_DIRECTORY 0x01 -#endif - -/* Allowable mode bits on Win32. Using mode bits that are not supported on - * Win32 (eg S_IRWXU) is generally ignored, but Wine warns loudly about it - * so we simply remove them. - */ -#define WIN32_MODE_MASK (_S_IREAD | _S_IWRITE) - -unsigned long git_win32__createfile_sharemode = - FILE_SHARE_READ | FILE_SHARE_WRITE; -int git_win32__retries = 10; - -GIT_INLINE(void) set_errno(void) -{ - switch (GetLastError()) { - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - case ERROR_INVALID_DRIVE: - case ERROR_NO_MORE_FILES: - case ERROR_BAD_NETPATH: - case ERROR_BAD_NET_NAME: - case ERROR_BAD_PATHNAME: - case ERROR_FILENAME_EXCED_RANGE: - errno = ENOENT; - break; - case ERROR_BAD_ENVIRONMENT: - errno = E2BIG; - break; - case ERROR_BAD_FORMAT: - case ERROR_INVALID_STARTING_CODESEG: - case ERROR_INVALID_STACKSEG: - case ERROR_INVALID_MODULETYPE: - case ERROR_INVALID_EXE_SIGNATURE: - case ERROR_EXE_MARKED_INVALID: - case ERROR_BAD_EXE_FORMAT: - case ERROR_ITERATED_DATA_EXCEEDS_64k: - case ERROR_INVALID_MINALLOCSIZE: - case ERROR_DYNLINK_FROM_INVALID_RING: - case ERROR_IOPL_NOT_ENABLED: - case ERROR_INVALID_SEGDPL: - case ERROR_AUTODATASEG_EXCEEDS_64k: - case ERROR_RING2SEG_MUST_BE_MOVABLE: - case ERROR_RELOC_CHAIN_XEEDS_SEGLIM: - case ERROR_INFLOOP_IN_RELOC_CHAIN: - errno = ENOEXEC; - break; - case ERROR_INVALID_HANDLE: - case ERROR_INVALID_TARGET_HANDLE: - case ERROR_DIRECT_ACCESS_HANDLE: - errno = EBADF; - break; - case ERROR_WAIT_NO_CHILDREN: - case ERROR_CHILD_NOT_COMPLETE: - errno = ECHILD; - break; - case ERROR_NO_PROC_SLOTS: - case ERROR_MAX_THRDS_REACHED: - case ERROR_NESTING_NOT_ALLOWED: - errno = EAGAIN; - break; - case ERROR_ARENA_TRASHED: - case ERROR_NOT_ENOUGH_MEMORY: - case ERROR_INVALID_BLOCK: - case ERROR_NOT_ENOUGH_QUOTA: - errno = ENOMEM; - break; - case ERROR_ACCESS_DENIED: - case ERROR_CURRENT_DIRECTORY: - case ERROR_WRITE_PROTECT: - case ERROR_BAD_UNIT: - case ERROR_NOT_READY: - case ERROR_BAD_COMMAND: - case ERROR_CRC: - case ERROR_BAD_LENGTH: - case ERROR_SEEK: - case ERROR_NOT_DOS_DISK: - case ERROR_SECTOR_NOT_FOUND: - case ERROR_OUT_OF_PAPER: - case ERROR_WRITE_FAULT: - case ERROR_READ_FAULT: - case ERROR_GEN_FAILURE: - case ERROR_SHARING_VIOLATION: - case ERROR_LOCK_VIOLATION: - case ERROR_WRONG_DISK: - case ERROR_SHARING_BUFFER_EXCEEDED: - case ERROR_NETWORK_ACCESS_DENIED: - case ERROR_CANNOT_MAKE: - case ERROR_FAIL_I24: - case ERROR_DRIVE_LOCKED: - case ERROR_SEEK_ON_DEVICE: - case ERROR_NOT_LOCKED: - case ERROR_LOCK_FAILED: - errno = EACCES; - break; - case ERROR_FILE_EXISTS: - case ERROR_ALREADY_EXISTS: - errno = EEXIST; - break; - case ERROR_NOT_SAME_DEVICE: - errno = EXDEV; - break; - case ERROR_INVALID_FUNCTION: - case ERROR_INVALID_ACCESS: - case ERROR_INVALID_DATA: - case ERROR_INVALID_PARAMETER: - case ERROR_NEGATIVE_SEEK: - errno = EINVAL; - break; - case ERROR_TOO_MANY_OPEN_FILES: - errno = EMFILE; - break; - case ERROR_DISK_FULL: - errno = ENOSPC; - break; - case ERROR_BROKEN_PIPE: - errno = EPIPE; - break; - case ERROR_DIR_NOT_EMPTY: - errno = ENOTEMPTY; - break; - default: - errno = EINVAL; - } -} - -GIT_INLINE(bool) last_error_retryable(void) -{ - int os_error = GetLastError(); - - return (os_error == ERROR_SHARING_VIOLATION || - os_error == ERROR_ACCESS_DENIED); -} - -#define do_with_retries(fn, remediation) \ - do { \ - int __retry, __ret; \ - for (__retry = git_win32__retries; __retry; __retry--) { \ - if ((__ret = (fn)) != GIT_RETRY) \ - return __ret; \ - if (__retry > 1 && (__ret = (remediation)) != 0) { \ - if (__ret == GIT_RETRY) \ - continue; \ - return __ret; \ - } \ - Sleep(5); \ - } \ - return -1; \ - } while (0) \ - -static int ensure_writable(wchar_t *path) -{ - DWORD attrs; - - if ((attrs = GetFileAttributesW(path)) == INVALID_FILE_ATTRIBUTES) - goto on_error; - - if ((attrs & FILE_ATTRIBUTE_READONLY) == 0) - return 0; - - if (!SetFileAttributesW(path, (attrs & ~FILE_ATTRIBUTE_READONLY))) - goto on_error; - - return GIT_RETRY; - -on_error: - set_errno(); - return -1; -} - -/** - * Truncate or extend file. - * - * We now take a "git_off_t" rather than "long" because - * files may be longer than 2Gb. - */ -int p_ftruncate(int fd, off64_t size) -{ - if (size < 0) { - errno = EINVAL; - return -1; - } - -#if !defined(__MINGW32__) || defined(MINGW_HAS_SECURE_API) - return ((_chsize_s(fd, size) == 0) ? 0 : -1); -#else - /* TODO MINGW32 Find a replacement for _chsize() that handles big files. */ - if (size > INT32_MAX) { - errno = EFBIG; - return -1; - } - return _chsize(fd, (long)size); -#endif -} - -int p_mkdir(const char *path, mode_t mode) -{ - git_win32_path buf; - - GIT_UNUSED(mode); - - if (git_win32_path_from_utf8(buf, path) < 0) - return -1; - - return _wmkdir(buf); -} - -int p_link(const char *old, const char *new) -{ - GIT_UNUSED(old); - GIT_UNUSED(new); - errno = ENOSYS; - return -1; -} - -GIT_INLINE(int) unlink_once(const wchar_t *path) -{ - DWORD error; - - if (DeleteFileW(path)) - return 0; - - if ((error = GetLastError()) == ERROR_ACCESS_DENIED) { - WIN32_FILE_ATTRIBUTE_DATA fdata; - if (!GetFileAttributesExW(path, GetFileExInfoStandard, &fdata) || - !(fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) || - !(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - goto out; - - if (RemoveDirectoryW(path)) - return 0; - } - -out: - SetLastError(error); - - if (last_error_retryable()) - return GIT_RETRY; - - set_errno(); - return -1; -} - -int p_unlink(const char *path) -{ - git_win32_path wpath; - - if (git_win32_path_from_utf8(wpath, path) < 0) - return -1; - - do_with_retries(unlink_once(wpath), ensure_writable(wpath)); -} - -int p_fsync(int fd) -{ - HANDLE fh = (HANDLE)_get_osfhandle(fd); - - p_fsync__cnt++; - - if (fh == INVALID_HANDLE_VALUE) { - errno = EBADF; - return -1; - } - - if (!FlushFileBuffers(fh)) { - DWORD code = GetLastError(); - - if (code == ERROR_INVALID_HANDLE) - errno = EINVAL; - else - errno = EIO; - - return -1; - } - - return 0; -} - -#define WIN32_IS_WSEP(CH) ((CH) == L'/' || (CH) == L'\\') - -static int lstat_w( - wchar_t *path, - struct stat *buf, - bool posix_enotdir) -{ - WIN32_FILE_ATTRIBUTE_DATA fdata; - - if (GetFileAttributesExW(path, GetFileExInfoStandard, &fdata)) { - if (!buf) - return 0; - - return git_win32__file_attribute_to_stat(buf, &fdata, path); - } - - switch (GetLastError()) { - case ERROR_ACCESS_DENIED: - errno = EACCES; - break; - default: - errno = ENOENT; - break; - } - - /* To match POSIX behavior, set ENOTDIR when any of the folders in the - * file path is a regular file, otherwise set ENOENT. - */ - if (errno == ENOENT && posix_enotdir) { - size_t path_len = wcslen(path); - - /* scan up path until we find an existing item */ - while (1) { - DWORD attrs; - - /* remove last directory component */ - for (path_len--; path_len > 0 && !WIN32_IS_WSEP(path[path_len]); path_len--); - - if (path_len <= 0) - break; - - path[path_len] = L'\0'; - attrs = GetFileAttributesW(path); - - if (attrs != INVALID_FILE_ATTRIBUTES) { - if (!(attrs & FILE_ATTRIBUTE_DIRECTORY)) - errno = ENOTDIR; - break; - } - } - } - - return -1; -} - -static int do_lstat(const char *path, struct stat *buf, bool posixly_correct) -{ - git_win32_path path_w; - int len; - - if ((len = git_win32_path_from_utf8(path_w, path)) < 0) - return -1; - - git_win32_path_trim_end(path_w, len); - - return lstat_w(path_w, buf, posixly_correct); -} - -int p_lstat(const char *filename, struct stat *buf) -{ - return do_lstat(filename, buf, false); -} - -int p_lstat_posixly(const char *filename, struct stat *buf) -{ - return do_lstat(filename, buf, true); -} - -int p_readlink(const char *path, char *buf, size_t bufsiz) -{ - git_win32_path path_w, target_w; - git_win32_utf8_path target; - int len; - - /* readlink(2) does not NULL-terminate the string written - * to the target buffer. Furthermore, the target buffer need - * not be large enough to hold the entire result. A truncated - * result should be written in this case. Since this truncation - * could occur in the middle of the encoding of a code point, - * we need to buffer the result on the stack. */ - - if (git_win32_path_from_utf8(path_w, path) < 0 || - git_win32_path_readlink_w(target_w, path_w) < 0 || - (len = git_win32_path_to_utf8(target, target_w)) < 0) - return -1; - - bufsiz = min((size_t)len, bufsiz); - memcpy(buf, target, bufsiz); - - return (int)bufsiz; -} - -static bool target_is_dir(const char *target, const char *path) -{ - git_str resolved = GIT_STR_INIT; - git_win32_path resolved_w; - bool isdir = true; - - if (git_fs_path_is_absolute(target)) - git_win32_path_from_utf8(resolved_w, target); - else if (git_fs_path_dirname_r(&resolved, path) < 0 || - git_fs_path_apply_relative(&resolved, target) < 0 || - git_win32_path_from_utf8(resolved_w, resolved.ptr) < 0) - goto out; - - isdir = GetFileAttributesW(resolved_w) & FILE_ATTRIBUTE_DIRECTORY; - -out: - git_str_dispose(&resolved); - return isdir; -} - -int p_symlink(const char *target, const char *path) -{ - git_win32_path target_w, path_w; - DWORD dwFlags; - - /* - * Convert both target and path to Windows-style paths. Note that we do - * not want to use `git_win32_path_from_utf8` for converting the target, - * as that function will automatically pre-pend the current working - * directory in case the path is not absolute. As Git will instead use - * relative symlinks, this is not something we want. - */ - if (git_win32_path_from_utf8(path_w, path) < 0 || - git_win32_path_relative_from_utf8(target_w, target) < 0) - return -1; - - dwFlags = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE; - if (target_is_dir(target, path)) - dwFlags |= SYMBOLIC_LINK_FLAG_DIRECTORY; - - if (!CreateSymbolicLinkW(path_w, target_w, dwFlags)) - return -1; - - return 0; -} - -struct open_opts { - DWORD access; - DWORD sharing; - SECURITY_ATTRIBUTES security; - DWORD creation_disposition; - DWORD attributes; - int osf_flags; -}; - -GIT_INLINE(void) open_opts_from_posix(struct open_opts *opts, int flags, mode_t mode) -{ - memset(opts, 0, sizeof(struct open_opts)); - - switch (flags & (O_WRONLY | O_RDWR)) { - case O_WRONLY: - opts->access = GENERIC_WRITE; - break; - case O_RDWR: - opts->access = GENERIC_READ | GENERIC_WRITE; - break; - default: - opts->access = GENERIC_READ; - break; - } - - opts->sharing = (DWORD)git_win32__createfile_sharemode; - - switch (flags & (O_CREAT | O_TRUNC | O_EXCL)) { - case O_CREAT | O_EXCL: - case O_CREAT | O_TRUNC | O_EXCL: - opts->creation_disposition = CREATE_NEW; - break; - case O_CREAT | O_TRUNC: - opts->creation_disposition = CREATE_ALWAYS; - break; - case O_TRUNC: - opts->creation_disposition = TRUNCATE_EXISTING; - break; - case O_CREAT: - opts->creation_disposition = OPEN_ALWAYS; - break; - default: - opts->creation_disposition = OPEN_EXISTING; - break; - } - - opts->attributes = ((flags & O_CREAT) && !(mode & S_IWRITE)) ? - FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL; - opts->osf_flags = flags & (O_RDONLY | O_APPEND); - - opts->security.nLength = sizeof(SECURITY_ATTRIBUTES); - opts->security.lpSecurityDescriptor = NULL; - opts->security.bInheritHandle = 0; -} - -GIT_INLINE(int) open_once( - const wchar_t *path, - struct open_opts *opts) -{ - int fd; - - HANDLE handle = CreateFileW(path, opts->access, opts->sharing, - &opts->security, opts->creation_disposition, opts->attributes, 0); - - if (handle == INVALID_HANDLE_VALUE) { - if (last_error_retryable()) - return GIT_RETRY; - - set_errno(); - return -1; - } - - if ((fd = _open_osfhandle((intptr_t)handle, opts->osf_flags)) < 0) - CloseHandle(handle); - - return fd; -} - -int p_open(const char *path, int flags, ...) -{ - git_win32_path wpath; - mode_t mode = 0; - struct open_opts opts = {0}; - - #ifdef GIT_DEBUG_STRICT_OPEN - if (strstr(path, "//") != NULL) { - errno = EACCES; - return -1; - } - #endif - - if (git_win32_path_from_utf8(wpath, path) < 0) - return -1; - - if (flags & O_CREAT) { - va_list arg_list; - - va_start(arg_list, flags); - mode = (mode_t)va_arg(arg_list, int); - va_end(arg_list); - } - - open_opts_from_posix(&opts, flags, mode); - - do_with_retries( - open_once(wpath, &opts), - 0); -} - -int p_creat(const char *path, mode_t mode) -{ - return p_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); -} - -int p_utimes(const char *path, const struct p_timeval times[2]) -{ - git_win32_path wpath; - int fd, error; - DWORD attrs_orig, attrs_new = 0; - struct open_opts opts = { 0 }; - - if (git_win32_path_from_utf8(wpath, path) < 0) - return -1; - - attrs_orig = GetFileAttributesW(wpath); - - if (attrs_orig & FILE_ATTRIBUTE_READONLY) { - attrs_new = attrs_orig & ~FILE_ATTRIBUTE_READONLY; - - if (!SetFileAttributesW(wpath, attrs_new)) { - git_error_set(GIT_ERROR_OS, "failed to set attributes"); - return -1; - } - } - - open_opts_from_posix(&opts, O_RDWR, 0); - - if ((fd = open_once(wpath, &opts)) < 0) { - error = -1; - goto done; - } - - error = p_futimes(fd, times); - close(fd); - -done: - if (attrs_orig != attrs_new) { - DWORD os_error = GetLastError(); - SetFileAttributesW(wpath, attrs_orig); - SetLastError(os_error); - } - - return error; -} - -int p_futimes(int fd, const struct p_timeval times[2]) -{ - HANDLE handle; - FILETIME atime = { 0 }, mtime = { 0 }; - - if (times == NULL) { - SYSTEMTIME st; - - GetSystemTime(&st); - SystemTimeToFileTime(&st, &atime); - SystemTimeToFileTime(&st, &mtime); - } - else { - git_win32__timeval_to_filetime(&atime, times[0]); - git_win32__timeval_to_filetime(&mtime, times[1]); - } - - if ((handle = (HANDLE)_get_osfhandle(fd)) == INVALID_HANDLE_VALUE) - return -1; - - if (SetFileTime(handle, NULL, &atime, &mtime) == 0) - return -1; - - return 0; -} - -int p_getcwd(char *buffer_out, size_t size) -{ - git_win32_path buf; - wchar_t *cwd = _wgetcwd(buf, GIT_WIN_PATH_UTF16); - - if (!cwd) - return -1; - - git_win32_path_remove_namespace(cwd, wcslen(cwd)); - - /* Convert the working directory back to UTF-8 */ - if (git_utf8_from_16(buffer_out, size, cwd) < 0) { - DWORD code = GetLastError(); - - if (code == ERROR_INSUFFICIENT_BUFFER) - errno = ERANGE; - else - errno = EINVAL; - - return -1; - } - - git_fs_path_mkposix(buffer_out); - return 0; -} - -static int getfinalpath_w( - git_win32_path dest, - const wchar_t *path) -{ - HANDLE hFile; - DWORD dwChars; - - /* Use FILE_FLAG_BACKUP_SEMANTICS so we can open a directory. Do not - * specify FILE_FLAG_OPEN_REPARSE_POINT; we want to open a handle to the - * target of the link. */ - hFile = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, - NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - - if (INVALID_HANDLE_VALUE == hFile) - return -1; - - /* Call GetFinalPathNameByHandle */ - dwChars = GetFinalPathNameByHandleW(hFile, dest, GIT_WIN_PATH_UTF16, FILE_NAME_NORMALIZED); - CloseHandle(hFile); - - if (!dwChars || dwChars >= GIT_WIN_PATH_UTF16) - return -1; - - /* The path may be delivered to us with a namespace prefix; remove */ - return (int)git_win32_path_remove_namespace(dest, dwChars); -} - -static int follow_and_lstat_link(git_win32_path path, struct stat *buf) -{ - git_win32_path target_w; - - if (getfinalpath_w(target_w, path) < 0) - return -1; - - return lstat_w(target_w, buf, false); -} - -int p_fstat(int fd, struct stat *buf) -{ - BY_HANDLE_FILE_INFORMATION fhInfo; - - HANDLE fh = (HANDLE)_get_osfhandle(fd); - - if (fh == INVALID_HANDLE_VALUE || - !GetFileInformationByHandle(fh, &fhInfo)) { - errno = EBADF; - return -1; - } - - git_win32__file_information_to_stat(buf, &fhInfo); - return 0; -} - -int p_stat(const char *path, struct stat *buf) -{ - git_win32_path path_w; - int len; - - if ((len = git_win32_path_from_utf8(path_w, path)) < 0 || - lstat_w(path_w, buf, false) < 0) - return -1; - - /* The item is a symbolic link or mount point. No need to iterate - * to follow multiple links; use GetFinalPathNameFromHandle. */ - if (S_ISLNK(buf->st_mode)) - return follow_and_lstat_link(path_w, buf); - - return 0; -} - -int p_chdir(const char *path) -{ - git_win32_path buf; - - if (git_win32_path_from_utf8(buf, path) < 0) - return -1; - - return _wchdir(buf); -} - -int p_chmod(const char *path, mode_t mode) -{ - git_win32_path buf; - - if (git_win32_path_from_utf8(buf, path) < 0) - return -1; - - return _wchmod(buf, mode); -} - -int p_rmdir(const char *path) -{ - git_win32_path buf; - int error; - - if (git_win32_path_from_utf8(buf, path) < 0) - return -1; - - error = _wrmdir(buf); - - if (error == -1) { - switch (GetLastError()) { - /* _wrmdir() is documented to return EACCES if "A program has an open - * handle to the directory." This sounds like what everybody else calls - * EBUSY. Let's convert appropriate error codes. - */ - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - errno = EBUSY; - break; - - /* This error can be returned when trying to rmdir an extant file. */ - case ERROR_DIRECTORY: - errno = ENOTDIR; - break; - } - } - - return error; -} - -char *p_realpath(const char *orig_path, char *buffer) -{ - git_win32_path orig_path_w, buffer_w; - DWORD long_len; - - if (git_win32_path_from_utf8(orig_path_w, orig_path) < 0) - return NULL; - - /* - * POSIX realpath performs two functions: first, it turns relative - * paths into absolute paths. For this, we need GetFullPathName. - * - * Note that if the path provided is a relative path, then the current directory - * is used to resolve the path -- which is a concurrency issue because the current - * directory is a process-wide variable. - */ - if (!GetFullPathNameW(orig_path_w, GIT_WIN_PATH_UTF16, buffer_w, NULL)) { - if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) - errno = ENAMETOOLONG; - else - errno = EINVAL; - - return NULL; - } - - /* - * Then, the path is canonicalized. eg, on macOS, - * "/TMP" -> "/private/tmp". For this, we need GetLongPathName. - */ - if ((long_len = GetLongPathNameW(buffer_w, buffer_w, GIT_WIN_PATH_UTF16)) == 0) { - DWORD error = GetLastError(); - - if (error == ERROR_FILE_NOT_FOUND || - error == ERROR_PATH_NOT_FOUND) - errno = ENOENT; - else if (error == ERROR_ACCESS_DENIED) - errno = EPERM; - else - errno = EINVAL; - - return NULL; - } - - if (long_len > GIT_WIN_PATH_UTF16) { - errno = ENAMETOOLONG; - return NULL; - } - - if (!buffer && !(buffer = git__malloc(GIT_WIN_PATH_UTF8))) { - errno = ENOMEM; - return NULL; - } - - /* Convert the path to UTF-8. If the caller provided a buffer, then it - * is assumed to be GIT_WIN_PATH_UTF8 characters in size. If it isn't, - * then we may overflow. */ - if (git_win32_path_to_utf8(buffer, buffer_w) < 0) - return NULL; - - git_fs_path_mkposix(buffer); - return buffer; -} - -int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) -{ -#if defined(_MSC_VER) - int len; - - if (count == 0) - return _vscprintf(format, argptr); - - #if _MSC_VER >= 1500 - len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr); - #else - len = _vsnprintf(buffer, count, format, argptr); - #endif - - if (len < 0) - return _vscprintf(format, argptr); - - return len; -#else /* MinGW */ - return vsnprintf(buffer, count, format, argptr); -#endif -} - -int p_snprintf(char *buffer, size_t count, const char *format, ...) -{ - va_list va; - int r; - - va_start(va, format); - r = p_vsnprintf(buffer, count, format, va); - va_end(va); - - return r; -} - -int p_access(const char *path, mode_t mode) -{ - git_win32_path buf; - - if (git_win32_path_from_utf8(buf, path) < 0) - return -1; - - return _waccess(buf, mode & WIN32_MODE_MASK); -} - -GIT_INLINE(int) rename_once(const wchar_t *from, const wchar_t *to) -{ - if (MoveFileExW(from, to, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED)) - return 0; - - if (last_error_retryable()) - return GIT_RETRY; - - set_errno(); - return -1; -} - -int p_rename(const char *from, const char *to) -{ - git_win32_path wfrom, wto; - - if (git_win32_path_from_utf8(wfrom, from) < 0 || - git_win32_path_from_utf8(wto, to) < 0) - return -1; - - do_with_retries(rename_once(wfrom, wto), ensure_writable(wto)); -} - -int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags) -{ - if ((size_t)((int)length) != length) - return -1; /* git_error_set will be done by caller */ - - return recv(socket, buffer, (int)length, flags); -} - -int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags) -{ - if ((size_t)((int)length) != length) - return -1; /* git_error_set will be done by caller */ - - return send(socket, buffer, (int)length, flags); -} - -/** - * Borrowed from http://old.nabble.com/Porting-localtime_r-and-gmtime_r-td15282276.html - * On Win32, `gmtime_r` doesn't exist but `gmtime` is threadsafe, so we can use that - */ -struct tm * -p_localtime_r (const time_t *timer, struct tm *result) -{ - struct tm *local_result; - local_result = localtime (timer); - - if (local_result == NULL || result == NULL) - return NULL; - - memcpy (result, local_result, sizeof (struct tm)); - return result; -} -struct tm * -p_gmtime_r (const time_t *timer, struct tm *result) -{ - struct tm *local_result; - local_result = gmtime (timer); - - if (local_result == NULL || result == NULL) - return NULL; - - memcpy (result, local_result, sizeof (struct tm)); - return result; -} - -int p_inet_pton(int af, const char *src, void *dst) -{ - struct sockaddr_storage sin; - void *addr; - int sin_len = sizeof(struct sockaddr_storage), addr_len; - int error = 0; - - if (af == AF_INET) { - addr = &((struct sockaddr_in *)&sin)->sin_addr; - addr_len = sizeof(struct in_addr); - } else if (af == AF_INET6) { - addr = &((struct sockaddr_in6 *)&sin)->sin6_addr; - addr_len = sizeof(struct in6_addr); - } else { - errno = EAFNOSUPPORT; - return -1; - } - - if ((error = WSAStringToAddressA((LPSTR)src, af, NULL, (LPSOCKADDR)&sin, &sin_len)) == 0) { - memcpy(dst, addr, addr_len); - return 1; - } - - switch(WSAGetLastError()) { - case WSAEINVAL: - return 0; - case WSAEFAULT: - errno = ENOSPC; - return -1; - case WSA_NOT_ENOUGH_MEMORY: - errno = ENOMEM; - return -1; - } - - errno = EINVAL; - return -1; -} - -ssize_t p_pread(int fd, void *data, size_t size, off64_t offset) -{ - HANDLE fh; - DWORD rsize = 0; - OVERLAPPED ov = {0}; - LARGE_INTEGER pos = {0}; - off64_t final_offset = 0; - - /* Fail if the final offset would have overflowed to match POSIX semantics. */ - if (!git__is_ssizet(size) || git__add_int64_overflow(&final_offset, offset, (int64_t)size)) { - errno = EINVAL; - return -1; - } - - /* - * Truncate large writes to the maximum allowable size: the caller - * needs to always call this in a loop anyways. - */ - if (size > INT32_MAX) { - size = INT32_MAX; - } - - pos.QuadPart = offset; - ov.Offset = pos.LowPart; - ov.OffsetHigh = pos.HighPart; - fh = (HANDLE)_get_osfhandle(fd); - - if (ReadFile(fh, data, (DWORD)size, &rsize, &ov)) { - return (ssize_t)rsize; - } - - set_errno(); - return -1; -} - -ssize_t p_pwrite(int fd, const void *data, size_t size, off64_t offset) -{ - HANDLE fh; - DWORD wsize = 0; - OVERLAPPED ov = {0}; - LARGE_INTEGER pos = {0}; - off64_t final_offset = 0; - - /* Fail if the final offset would have overflowed to match POSIX semantics. */ - if (!git__is_ssizet(size) || git__add_int64_overflow(&final_offset, offset, (int64_t)size)) { - errno = EINVAL; - return -1; - } - - /* - * Truncate large writes to the maximum allowable size: the caller - * needs to always call this in a loop anyways. - */ - if (size > INT32_MAX) { - size = INT32_MAX; - } - - pos.QuadPart = offset; - ov.Offset = pos.LowPart; - ov.OffsetHigh = pos.HighPart; - fh = (HANDLE)_get_osfhandle(fd); - - if (WriteFile(fh, data, (DWORD)size, &wsize, &ov)) { - return (ssize_t)wsize; - } - - set_errno(); - return -1; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/precompiled.c b/vendor/libgit2-sys/libgit2/src/util/win32/precompiled.c deleted file mode 100644 index 5f656a4..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/precompiled.c +++ /dev/null @@ -1 +0,0 @@ -#include "precompiled.h" diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/precompiled.h b/vendor/libgit2-sys/libgit2/src/util/win32/precompiled.h deleted file mode 100644 index 1163c3d..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/precompiled.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "git2_util.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#ifdef GIT_THREADS - #include "win32/thread.h" -#endif - -#include "git2.h" diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/process.c b/vendor/libgit2-sys/libgit2/src/util/win32/process.c deleted file mode 100644 index ad4ae89..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/process.c +++ /dev/null @@ -1,522 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include -#include - -#include "git2_util.h" -#include "process.h" -#include "strlist.h" -#include "fs_path.h" - -#ifndef DWORD_MAX -# define DWORD_MAX INT32_MAX -#endif - -#define ENV_MAX 32767 - -struct git_process { - char *app_name; - wchar_t *app_path; - wchar_t *cmdline; - wchar_t *env; - - wchar_t *cwd; - - unsigned int capture_in : 1, - capture_out : 1, - capture_err : 1; - - PROCESS_INFORMATION process_info; - - HANDLE child_in; - HANDLE child_out; - HANDLE child_err; - - git_process_result_status status; -}; - -/* - * Windows processes have a single command-line that is split by the - * invoked application into arguments (instead of an array of - * command-line arguments). This command-line is split by space or - * tab delimiters, unless that whitespace is within a double quote. - * Literal double-quotes themselves can be escaped by a backslash, - * but only when not within double quotes. Literal backslashes can - * be escaped by a backslash. - * - * Effectively, this means that instead of thinking about quoting - * individual strings, think about double quotes as an escaping - * mechanism for whitespace. - * - * In other words (using ` as a string boundary): - * [ `foo`, `bar` ] => `foo bar` - * [ `foo bar` ] => `foo" "bar` - * [ `foo bar`, `foo bar` ] => `foo" "bar foo" "bar` - * [ `foo "bar" foo` ] => `foo" "\"bar\"" "foo` - */ -int git_process__cmdline( - git_str *out, - const char **in, - size_t in_len) -{ - bool quoted = false; - const char *c; - size_t i; - - for (i = 0; i < in_len; i++) { - /* Arguments are delimited by an unquoted space */ - if (i) - git_str_putc(out, ' '); - - for (c = in[i]; *c; c++) { - /* Start or stop quoting spaces within an argument */ - if ((*c == ' ' || *c == '\t') && !quoted) { - git_str_putc(out, '"'); - quoted = true; - } else if (*c != ' ' && *c != '\t' && quoted) { - git_str_putc(out, '"'); - quoted = false; - } - - /* Escape double-quotes and backslashes */ - if (*c == '"' || *c == '\\') - git_str_putc(out, '\\'); - - git_str_putc(out, *c); - } - } - - return git_str_oom(out) ? -1 : 0; -} - -GIT_INLINE(bool) is_delete_env(const char *env) -{ - char *c = strchr(env, '='); - - if (c == NULL) - return false; - - return *(c+1) == '\0'; -} - -static int merge_env(wchar_t **out, const char **in, size_t in_len, bool exclude_env) -{ - git_str merged = GIT_STR_INIT; - wchar_t *in16 = NULL, *env = NULL, *e; - char *e8 = NULL; - size_t e_len; - int ret = 0; - size_t i; - - *out = NULL; - - in16 = git__malloc(ENV_MAX * sizeof(wchar_t)); - GIT_ERROR_CHECK_ALLOC(in16); - - e8 = git__malloc(ENV_MAX); - GIT_ERROR_CHECK_ALLOC(e8); - - for (i = 0; in && i < in_len; i++) { - if (is_delete_env(in[i])) - continue; - - if ((ret = git_utf8_to_16(in16, ENV_MAX, in[i])) < 0) - goto done; - - git_str_put(&merged, (const char *)in16, ret * 2); - git_str_put(&merged, "\0\0", 2); - } - - if (!exclude_env) { - env = GetEnvironmentStringsW(); - - for (e = env; *e; e += (e_len + 1)) { - e_len = wcslen(e); - - if ((ret = git_utf8_from_16(e8, ENV_MAX, e)) < 0) - goto done; - - if (git_strlist_contains_key(in, in_len, e8, '=')) - continue; - - git_str_put(&merged, (const char *)e, e_len * 2); - git_str_put(&merged, "\0\0", 2); - } - } - - git_str_put(&merged, "\0\0", 2); - - *out = (wchar_t *)git_str_detach(&merged); - -done: - if (env) - FreeEnvironmentStringsW(env); - - git_str_dispose(&merged); - git__free(e8); - git__free(in16); - - return ret < 0 ? -1 : 0; -} - -static int process_new( - git_process **out, - const char *appname, - const char *cmdline, - const char **env, - size_t env_len, - git_process_options *opts) -{ - git_process *process; - int error = 0; - - *out = NULL; - - process = git__calloc(1, sizeof(git_process)); - GIT_ERROR_CHECK_ALLOC(process); - - if (appname && (process->app_name = git__strdup(appname)) == NULL) { - error = -1; - goto done; - } - - if (git_utf8_to_16_alloc(&process->cmdline, cmdline) < 0) { - error = -1; - goto done; - } - - if (opts && opts->cwd && - git_utf8_to_16_alloc(&process->cwd, opts->cwd) < 0) { - error = -1; - goto done; - } - - if (env && (error = merge_env(&process->env, env, env_len, opts && opts->exclude_env) < 0)) - goto done; - - if (opts) { - process->capture_in = opts->capture_in; - process->capture_out = opts->capture_out; - process->capture_err = opts->capture_err; - } - -done: - if (error) - git_process_free(process); - else - *out = process; - - return error; -} - -int git_process_new_from_cmdline( - git_process **out, - const char *cmdline, - const char **env, - size_t env_len, - git_process_options *opts) -{ - GIT_ASSERT_ARG(out && cmdline); - - return process_new(out, NULL, cmdline, env, env_len, opts); -} - -int git_process_new( - git_process **out, - const char **args, - size_t args_len, - const char **env, - size_t env_len, - git_process_options *opts) -{ - git_str cmd_path = GIT_STR_INIT, cmdline = GIT_STR_INIT; - int error; - - GIT_ASSERT_ARG(out && args && args_len > 0); - - if ((error = git_process__cmdline(&cmdline, args, args_len)) < 0) - goto done; - - error = process_new(out, args[0], cmdline.ptr, env, env_len, opts); - -done: - git_str_dispose(&cmd_path); - git_str_dispose(&cmdline); - return error; -} - -#define CLOSE_HANDLE(h) do { if ((h) != NULL) CloseHandle(h); } while(0) - -int git_process_start(git_process *process) -{ - STARTUPINFOW startup_info; - SECURITY_ATTRIBUTES security_attrs; - DWORD flags = CREATE_UNICODE_ENVIRONMENT; - HANDLE in[2] = { NULL, NULL }, - out[2] = { NULL, NULL }, - err[2] = { NULL, NULL }; - - if (process->app_name) { - git_str cmd_path = GIT_STR_INIT; - int error; - - if ((error = git_fs_path_find_executable(&cmd_path, process->app_name)) == 0) - error = git_utf8_to_16_alloc(&process->app_path, cmd_path.ptr); - - git_str_dispose(&cmd_path); - - if (error < 0) - goto on_error; - } - - memset(&security_attrs, 0, sizeof(SECURITY_ATTRIBUTES)); - security_attrs.bInheritHandle = TRUE; - - memset(&startup_info, 0, sizeof(STARTUPINFOW)); - startup_info.cb = sizeof(STARTUPINFOW); - startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); - startup_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); - startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); - - if (process->capture_in) { - if (!CreatePipe(&in[0], &in[1], &security_attrs, 0) || - !SetHandleInformation(in[1], HANDLE_FLAG_INHERIT, 0)) { - git_error_set(GIT_ERROR_OS, "could not create pipe"); - goto on_error; - } - - startup_info.hStdInput = in[0]; - startup_info.dwFlags |= STARTF_USESTDHANDLES; - } - - if (process->capture_out) { - if (!CreatePipe(&out[0], &out[1], &security_attrs, 0) || - !SetHandleInformation(out[0], HANDLE_FLAG_INHERIT, 0)) { - git_error_set(GIT_ERROR_OS, "could not create pipe"); - goto on_error; - } - - startup_info.hStdOutput = out[1]; - startup_info.dwFlags |= STARTF_USESTDHANDLES; - } - - if (process->capture_err) { - if (!CreatePipe(&err[0], &err[1], &security_attrs, 0) || - !SetHandleInformation(err[0], HANDLE_FLAG_INHERIT, 0)) { - git_error_set(GIT_ERROR_OS, "could not create pipe"); - goto on_error; - } - - startup_info.hStdError = err[1]; - startup_info.dwFlags |= STARTF_USESTDHANDLES; - } - - memset(&process->process_info, 0, sizeof(PROCESS_INFORMATION)); - - if (!CreateProcessW(process->app_path, process->cmdline, - NULL, NULL, TRUE, flags, process->env, - process->cwd, - &startup_info, - &process->process_info)) { - git_error_set(GIT_ERROR_OS, "could not create process"); - goto on_error; - } - - CLOSE_HANDLE(in[0]); process->child_in = in[1]; - CLOSE_HANDLE(out[1]); process->child_out = out[0]; - CLOSE_HANDLE(err[1]); process->child_err = err[0]; - - return 0; - -on_error: - CLOSE_HANDLE(in[0]); CLOSE_HANDLE(in[1]); - CLOSE_HANDLE(out[0]); CLOSE_HANDLE(out[1]); - CLOSE_HANDLE(err[0]); CLOSE_HANDLE(err[1]); - return -1; -} - -int git_process_id(p_pid_t *out, git_process *process) -{ - GIT_ASSERT(out && process); - - if (!process->process_info.dwProcessId) { - git_error_set(GIT_ERROR_INVALID, "process not running"); - return -1; - } - - *out = process->process_info.dwProcessId; - return 0; -} - -ssize_t git_process_read(git_process *process, void *buf, size_t count) -{ - DWORD ret; - - if (count > DWORD_MAX) - count = DWORD_MAX; - if (count > SSIZE_MAX) - count = SSIZE_MAX; - - if (!ReadFile(process->child_out, buf, (DWORD)count, &ret, NULL)) { - if (GetLastError() == ERROR_BROKEN_PIPE) - return 0; - - git_error_set(GIT_ERROR_OS, "could not read"); - return -1; - } - - return ret; -} - -ssize_t git_process_write(git_process *process, const void *buf, size_t count) -{ - DWORD ret; - - if (count > DWORD_MAX) - count = DWORD_MAX; - if (count > SSIZE_MAX) - count = SSIZE_MAX; - - if (!WriteFile(process->child_in, buf, (DWORD)count, &ret, NULL)) { - git_error_set(GIT_ERROR_OS, "could not write"); - return -1; - } - - return ret; -} - -int git_process_close_in(git_process *process) -{ - if (!process->capture_in) { - git_error_set(GIT_ERROR_INVALID, "input is not open"); - return -1; - } - - if (process->child_in) { - CloseHandle(process->child_in); - process->child_in = NULL; - } - - return 0; -} - -int git_process_close_out(git_process *process) -{ - if (!process->capture_out) { - git_error_set(GIT_ERROR_INVALID, "output is not open"); - return -1; - } - - if (process->child_out) { - CloseHandle(process->child_out); - process->child_out = NULL; - } - - return 0; -} - -int git_process_close_err(git_process *process) -{ - if (!process->capture_err) { - git_error_set(GIT_ERROR_INVALID, "error is not open"); - return -1; - } - - if (process->child_err) { - CloseHandle(process->child_err); - process->child_err = NULL; - } - - return 0; -} - -int git_process_close(git_process *process) -{ - if (process->child_in) { - CloseHandle(process->child_in); - process->child_in = NULL; - } - - if (process->child_out) { - CloseHandle(process->child_out); - process->child_out = NULL; - } - - if (process->child_err) { - CloseHandle(process->child_err); - process->child_err = NULL; - } - - CloseHandle(process->process_info.hProcess); - process->process_info.hProcess = NULL; - - CloseHandle(process->process_info.hThread); - process->process_info.hThread = NULL; - - return 0; -} - -int git_process_wait(git_process_result *result, git_process *process) -{ - DWORD exitcode; - - if (result) - memset(result, 0, sizeof(git_process_result)); - - if (!process->process_info.dwProcessId) { - git_error_set(GIT_ERROR_INVALID, "process is stopped"); - return -1; - } - - if (WaitForSingleObject(process->process_info.hProcess, INFINITE) == WAIT_FAILED) { - git_error_set(GIT_ERROR_OS, "could not wait for process"); - return -1; - } - - if (!GetExitCodeProcess(process->process_info.hProcess, &exitcode)) { - git_error_set(GIT_ERROR_OS, "could not get process exit code"); - return -1; - } - - result->status = GIT_PROCESS_STATUS_NORMAL; - result->exitcode = exitcode; - - memset(&process->process_info, 0, sizeof(PROCESS_INFORMATION)); - return 0; -} - -int git_process_result_msg(git_str *out, git_process_result *result) -{ - if (result->status == GIT_PROCESS_STATUS_NONE) { - return git_str_puts(out, "process not started"); - } else if (result->status == GIT_PROCESS_STATUS_NORMAL) { - return git_str_printf(out, "process exited with code %d", - result->exitcode); - } else if (result->signal) { - return git_str_printf(out, "process exited on signal %d", - result->signal); - } - - return git_str_puts(out, "unknown error"); -} - -void git_process_free(git_process *process) -{ - if (!process) - return; - - if (process->process_info.hProcess) - git_process_close(process); - - git__free(process->env); - git__free(process->cwd); - git__free(process->cmdline); - git__free(process->app_path); - git__free(process->app_name); - git__free(process); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/reparse.h b/vendor/libgit2-sys/libgit2/src/util/win32/reparse.h deleted file mode 100644 index 2331231..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/reparse.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* Copyright (C) the libgit2 contributors. All rights reserved. -* -* This file is part of libgit2, distributed under the GNU GPL v2 with -* a Linking Exception. For full terms see the included COPYING file. -*/ - -#ifndef INCLUDE_win32_reparse_h__ -#define INCLUDE_win32_reparse_h__ - -/* This structure is defined on MSDN at -* http://msdn.microsoft.com/en-us/library/windows/hardware/ff552012(v=vs.85).aspx -* -* It was formerly included in the Windows 2000 SDK and remains defined in -* MinGW, so we must define it with a silly name to avoid conflicting. -*/ -typedef struct _GIT_REPARSE_DATA_BUFFER { - ULONG ReparseTag; - USHORT ReparseDataLength; - USHORT Reserved; - union { - struct { - USHORT SubstituteNameOffset; - USHORT SubstituteNameLength; - USHORT PrintNameOffset; - USHORT PrintNameLength; - ULONG Flags; - WCHAR PathBuffer[1]; - } SymbolicLink; - struct { - USHORT SubstituteNameOffset; - USHORT SubstituteNameLength; - USHORT PrintNameOffset; - USHORT PrintNameLength; - WCHAR PathBuffer[1]; - } MountPoint; - struct { - UCHAR DataBuffer[1]; - } Generic; - } ReparseBuffer; -} GIT_REPARSE_DATA_BUFFER; - -#define REPARSE_DATA_HEADER_SIZE 8 -#define REPARSE_DATA_MOUNTPOINT_HEADER_SIZE 8 -#define REPARSE_DATA_UNION_SIZE 12 - -/* Missing in MinGW */ -#ifndef FSCTL_GET_REPARSE_POINT -# define FSCTL_GET_REPARSE_POINT 0x000900a8 -#endif - -/* Missing in MinGW */ -#ifndef FSCTL_SET_REPARSE_POINT -# define FSCTL_SET_REPARSE_POINT 0x000900a4 -#endif - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/thread.c b/vendor/libgit2-sys/libgit2/src/util/win32/thread.c deleted file mode 100644 index f5cacd3..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/thread.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "thread.h" -#include "runtime.h" - -#define CLEAN_THREAD_EXIT 0x6F012842 - -typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *); - -static win32_srwlock_fn win32_srwlock_initialize; -static win32_srwlock_fn win32_srwlock_acquire_shared; -static win32_srwlock_fn win32_srwlock_release_shared; -static win32_srwlock_fn win32_srwlock_acquire_exclusive; -static win32_srwlock_fn win32_srwlock_release_exclusive; - -static DWORD fls_index; - -/* The thread procedure stub used to invoke the caller's procedure - * and capture the return value for later collection. Windows will - * only hold a DWORD, but we need to be able to store an entire - * void pointer. This requires the indirection. */ -static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter) -{ - git_thread *thread = lpParameter; - - /* Set the current thread for `git_thread_exit` */ - FlsSetValue(fls_index, thread); - - thread->result = thread->proc(thread->param); - - return CLEAN_THREAD_EXIT; -} - -static void git_threads_global_shutdown(void) -{ - FlsFree(fls_index); -} - -int git_threads_global_init(void) -{ - HMODULE hModule = GetModuleHandleW(L"kernel32"); - - if (hModule) { - win32_srwlock_initialize = (win32_srwlock_fn)(void *) - GetProcAddress(hModule, "InitializeSRWLock"); - win32_srwlock_acquire_shared = (win32_srwlock_fn)(void *) - GetProcAddress(hModule, "AcquireSRWLockShared"); - win32_srwlock_release_shared = (win32_srwlock_fn)(void *) - GetProcAddress(hModule, "ReleaseSRWLockShared"); - win32_srwlock_acquire_exclusive = (win32_srwlock_fn)(void *) - GetProcAddress(hModule, "AcquireSRWLockExclusive"); - win32_srwlock_release_exclusive = (win32_srwlock_fn)(void *) - GetProcAddress(hModule, "ReleaseSRWLockExclusive"); - } - - if ((fls_index = FlsAlloc(NULL)) == FLS_OUT_OF_INDEXES) - return -1; - - return git_runtime_shutdown_register(git_threads_global_shutdown); -} - -int git_thread_create( - git_thread *GIT_RESTRICT thread, - void *(*start_routine)(void*), - void *GIT_RESTRICT arg) -{ - thread->result = NULL; - thread->param = arg; - thread->proc = start_routine; - thread->thread = CreateThread( - NULL, 0, git_win32__threadproc, thread, 0, NULL); - - return thread->thread ? 0 : -1; -} - -int git_thread_join( - git_thread *thread, - void **value_ptr) -{ - DWORD exit; - - if (WaitForSingleObject(thread->thread, INFINITE) != WAIT_OBJECT_0) - return -1; - - if (!GetExitCodeThread(thread->thread, &exit)) { - CloseHandle(thread->thread); - return -1; - } - - /* Check for the thread having exited uncleanly. If exit was unclean, - * then we don't have a return value to give back to the caller. */ - GIT_ASSERT(exit == CLEAN_THREAD_EXIT); - - if (value_ptr) - *value_ptr = thread->result; - - CloseHandle(thread->thread); - return 0; -} - -void git_thread_exit(void *value) -{ - git_thread *thread = FlsGetValue(fls_index); - - if (thread) - thread->result = value; - - ExitThread(CLEAN_THREAD_EXIT); -} - -size_t git_thread_currentid(void) -{ - return GetCurrentThreadId(); -} - -int git_mutex_init(git_mutex *GIT_RESTRICT mutex) -{ - InitializeCriticalSection(mutex); - return 0; -} - -int git_mutex_free(git_mutex *mutex) -{ - DeleteCriticalSection(mutex); - return 0; -} - -int git_mutex_lock(git_mutex *mutex) -{ - EnterCriticalSection(mutex); - return 0; -} - -int git_mutex_unlock(git_mutex *mutex) -{ - LeaveCriticalSection(mutex); - return 0; -} - -int git_cond_init(git_cond *cond) -{ - /* This is an auto-reset event. */ - *cond = CreateEventW(NULL, FALSE, FALSE, NULL); - GIT_ASSERT(*cond); - - /* If we can't create the event, claim that the reason was out-of-memory. - * The actual reason can be fetched with GetLastError(). */ - return *cond ? 0 : ENOMEM; -} - -int git_cond_free(git_cond *cond) -{ - BOOL closed; - - if (!cond) - return EINVAL; - - closed = CloseHandle(*cond); - GIT_ASSERT(closed); - GIT_UNUSED(closed); - - *cond = NULL; - return 0; -} - -int git_cond_wait(git_cond *cond, git_mutex *mutex) -{ - int error; - DWORD wait_result; - - if (!cond || !mutex) - return EINVAL; - - /* The caller must be holding the mutex. */ - error = git_mutex_unlock(mutex); - - if (error) - return error; - - wait_result = WaitForSingleObject(*cond, INFINITE); - GIT_ASSERT(WAIT_OBJECT_0 == wait_result); - GIT_UNUSED(wait_result); - - return git_mutex_lock(mutex); -} - -int git_cond_signal(git_cond *cond) -{ - BOOL signaled; - - if (!cond) - return EINVAL; - - signaled = SetEvent(*cond); - GIT_ASSERT(signaled); - GIT_UNUSED(signaled); - - return 0; -} - -int git_rwlock_init(git_rwlock *GIT_RESTRICT lock) -{ - if (win32_srwlock_initialize) - win32_srwlock_initialize(&lock->native.srwl); - else - InitializeCriticalSection(&lock->native.csec); - - return 0; -} - -int git_rwlock_rdlock(git_rwlock *lock) -{ - if (win32_srwlock_acquire_shared) - win32_srwlock_acquire_shared(&lock->native.srwl); - else - EnterCriticalSection(&lock->native.csec); - - return 0; -} - -int git_rwlock_rdunlock(git_rwlock *lock) -{ - if (win32_srwlock_release_shared) - win32_srwlock_release_shared(&lock->native.srwl); - else - LeaveCriticalSection(&lock->native.csec); - - return 0; -} - -int git_rwlock_wrlock(git_rwlock *lock) -{ - if (win32_srwlock_acquire_exclusive) - win32_srwlock_acquire_exclusive(&lock->native.srwl); - else - EnterCriticalSection(&lock->native.csec); - - return 0; -} - -int git_rwlock_wrunlock(git_rwlock *lock) -{ - if (win32_srwlock_release_exclusive) - win32_srwlock_release_exclusive(&lock->native.srwl); - else - LeaveCriticalSection(&lock->native.csec); - - return 0; -} - -int git_rwlock_free(git_rwlock *lock) -{ - if (!win32_srwlock_initialize) - DeleteCriticalSection(&lock->native.csec); - git__memzero(lock, sizeof(*lock)); - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/thread.h b/vendor/libgit2-sys/libgit2/src/util/win32/thread.h deleted file mode 100644 index 184762e..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/thread.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_win32_thread_h__ -#define INCLUDE_win32_thread_h__ - -#include "git2_util.h" - -#if defined (_MSC_VER) -# define GIT_RESTRICT __restrict -#else -# define GIT_RESTRICT __restrict__ -#endif - -typedef struct { - HANDLE thread; - void *(*proc)(void *); - void *param; - void *result; -} git_thread; - -typedef CRITICAL_SECTION git_mutex; -typedef HANDLE git_cond; - -typedef struct { void *Ptr; } GIT_SRWLOCK; - -typedef struct { - union { - GIT_SRWLOCK srwl; - CRITICAL_SECTION csec; - } native; -} git_rwlock; - -int git_threads_global_init(void); - -int git_thread_create(git_thread *GIT_RESTRICT, - void *(*) (void *), - void *GIT_RESTRICT); -int git_thread_join(git_thread *, void **); -size_t git_thread_currentid(void); -void git_thread_exit(void *); - -int git_mutex_init(git_mutex *GIT_RESTRICT mutex); -int git_mutex_free(git_mutex *); -int git_mutex_lock(git_mutex *); -int git_mutex_unlock(git_mutex *); - -int git_cond_init(git_cond *); -int git_cond_free(git_cond *); -int git_cond_wait(git_cond *, git_mutex *); -int git_cond_signal(git_cond *); - -int git_rwlock_init(git_rwlock *GIT_RESTRICT lock); -int git_rwlock_rdlock(git_rwlock *); -int git_rwlock_rdunlock(git_rwlock *); -int git_rwlock_wrlock(git_rwlock *); -int git_rwlock_wrunlock(git_rwlock *); -int git_rwlock_free(git_rwlock *); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/utf-conv.c b/vendor/libgit2-sys/libgit2/src/util/win32/utf-conv.c deleted file mode 100644 index ad35c0c..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/utf-conv.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "utf-conv.h" - -GIT_INLINE(void) git__set_errno(void) -{ - if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) - errno = ENAMETOOLONG; - else - errno = EINVAL; -} - -int git_utf8_to_16(wchar_t *dest, size_t dest_size, const char *src) -{ - /* Length of -1 indicates NULL termination of the input string. */ - return git_utf8_to_16_with_len(dest, dest_size, src, -1); -} - -int git_utf8_to_16_with_len( - wchar_t *dest, - size_t _dest_size, - const char *src, - int src_len) -{ - int dest_size = (int)min(_dest_size, INT_MAX); - int len; - - /* - * Subtract 1 from the result to turn 0 into -1 (an error code) and - * to not count the NULL terminator as part of the string's length. - * MultiByteToWideChar never returns int's minvalue, so underflow - * is not possible. - */ - len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, - src, src_len, dest, dest_size) - 1; - - if (len < 0) - git__set_errno(); - - return len; -} - -int git_utf8_from_16(char *dest, size_t dest_size, const wchar_t *src) -{ - /* Length of -1 indicates NULL termination of the input string. */ - return git_utf8_from_16_with_len(dest, dest_size, src, -1); -} - -int git_utf8_from_16_with_len( - char *dest, - size_t _dest_size, - const wchar_t *src, - int src_len) -{ - int dest_size = (int)min(_dest_size, INT_MAX); - int len; - - /* - * Subtract 1 from the result to turn 0 into -1 (an error code) and - * to not count the NULL terminator as part of the string's length. - * WideCharToMultiByte never returns int's minvalue, so underflow - * is not possible. - */ - len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, - src, src_len, dest, dest_size, NULL, NULL) - 1; - - if (len < 0) - git__set_errno(); - - return len; -} - -int git_utf8_to_16_alloc(wchar_t **dest, const char *src) -{ - /* Length of -1 indicates NULL termination of the input string. */ - return git_utf8_to_16_alloc_with_len(dest, src, -1); -} - -int git_utf8_to_16_alloc_with_len(wchar_t **dest, const char *src, int src_len) -{ - int utf16_size; - - *dest = NULL; - - utf16_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, - src, src_len, NULL, 0); - - if (!utf16_size) { - git__set_errno(); - return -1; - } - - *dest = git__mallocarray(utf16_size, sizeof(wchar_t)); - GIT_ERROR_CHECK_ALLOC(*dest); - - utf16_size = git_utf8_to_16_with_len(*dest, (size_t)utf16_size, - src, src_len); - - if (utf16_size < 0) { - git__free(*dest); - *dest = NULL; - } - - return utf16_size; -} - -int git_utf8_from_16_alloc(char **dest, const wchar_t *src) -{ - /* Length of -1 indicates NULL termination of the input string. */ - return git_utf8_from_16_alloc_with_len(dest, src, -1); -} - -int git_utf8_from_16_alloc_with_len(char **dest, const wchar_t *src, int src_len) -{ - int utf8_size; - - *dest = NULL; - - utf8_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, - src, src_len, NULL, 0, NULL, NULL); - - if (!utf8_size) { - git__set_errno(); - return -1; - } - - *dest = git__malloc(utf8_size); - GIT_ERROR_CHECK_ALLOC(*dest); - - utf8_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, - src, src_len, *dest, utf8_size, NULL, NULL); - - if (utf8_size < 0) { - git__free(*dest); - *dest = NULL; - } - - return utf8_size; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/utf-conv.h b/vendor/libgit2-sys/libgit2/src/util/win32/utf-conv.h deleted file mode 100644 index 301f5a6..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/utf-conv.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_utf_conv_h__ -#define INCLUDE_win32_utf_conv_h__ - -#include "git2_util.h" - -#include - -#ifndef WC_ERR_INVALID_CHARS -# define WC_ERR_INVALID_CHARS 0x80 -#endif - -/** - * Converts a NUL-terminated UTF-8 string to wide characters. This is a - * convenience function for `git_utf8_to_16_with_len`. - * - * @param dest The buffer to receive the wide string. - * @param dest_size The size of the buffer, in characters. - * @param src The UTF-8 string to convert. - * @return The length of the wide string, in characters - * (not counting the NULL terminator), or < 0 for failure - */ -int git_utf8_to_16(wchar_t *dest, size_t dest_size, const char *src); - -/** - * Converts a UTF-8 string to wide characters. - * - * @param dest The buffer to receive the wide string. - * @param dest_size The size of the buffer, in characters. - * @param src The UTF-8 string to convert. - * @param src_len The length of the string to convert. - * @return The length of the wide string, in characters - * (not counting the NULL terminator), or < 0 for failure - */ -int git_utf8_to_16_with_len( - wchar_t *dest, - size_t dest_size, - const char *src, - int src_len); - -/** - * Converts a NUL-terminated wide string to UTF-8. This is a convenience - * function for `git_utf8_from_16_with_len`. - * - * @param dest The buffer to receive the UTF-8 string. - * @param dest_size The size of the buffer, in bytes. - * @param src The wide string to convert. - * @param src_len The length of the string to convert. - * @return The length of the UTF-8 string, in bytes - * (not counting the NULL terminator), or < 0 for failure - */ -int git_utf8_from_16(char *dest, size_t dest_size, const wchar_t *src); - -/** - * Converts a wide string to UTF-8. - * - * @param dest The buffer to receive the UTF-8 string. - * @param dest_size The size of the buffer, in bytes. - * @param src The wide string to convert. - * @param src_len The length of the string to convert. - * @return The length of the UTF-8 string, in bytes - * (not counting the NULL terminator), or < 0 for failure - */ -int git_utf8_from_16_with_len(char *dest, size_t dest_size, const wchar_t *src, int src_len); - -/** - * Converts a UTF-8 string to wide characters. Memory is allocated to hold - * the converted string. The caller is responsible for freeing the string - * with git__free. - * - * @param dest Receives a pointer to the wide string. - * @param src The UTF-8 string to convert. - * @return The length of the wide string, in characters - * (not counting the NULL terminator), or < 0 for failure - */ -int git_utf8_to_16_alloc(wchar_t **dest, const char *src); - -/** - * Converts a UTF-8 string to wide characters. Memory is allocated to hold - * the converted string. The caller is responsible for freeing the string - * with git__free. - * - * @param dest Receives a pointer to the wide string. - * @param src The UTF-8 string to convert. - * @param src_len The length of the string. - * @return The length of the wide string, in characters - * (not counting the NULL terminator), or < 0 for failure - */ -int git_utf8_to_16_alloc_with_len( - wchar_t **dest, - const char *src, - int src_len); - -/** - * Converts a wide string to UTF-8. Memory is allocated to hold the - * converted string. The caller is responsible for freeing the string - * with git__free. - * - * @param dest Receives a pointer to the UTF-8 string. - * @param src The wide string to convert. - * @return The length of the UTF-8 string, in bytes - * (not counting the NULL terminator), or < 0 for failure - */ -int git_utf8_from_16_alloc(char **dest, const wchar_t *src); - -/** - * Converts a wide string to UTF-8. Memory is allocated to hold the - * converted string. The caller is responsible for freeing the string - * with git__free. - * - * @param dest Receives a pointer to the UTF-8 string. - * @param src The wide string to convert. - * @param src_len The length of the wide string. - * @return The length of the UTF-8 string, in bytes - * (not counting the NULL terminator), or < 0 for failure - */ -int git_utf8_from_16_alloc_with_len( - char **dest, - const wchar_t *src, - int src_len); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/version.h b/vendor/libgit2-sys/libgit2/src/util/win32/version.h deleted file mode 100644 index 7966769..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/version.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_version_h__ -#define INCLUDE_win32_version_h__ - -#include - -GIT_INLINE(int) git_has_win32_version(int major, int minor, int service_pack) -{ - OSVERSIONINFOEX version_test = {0}; - DWORD version_test_mask; - DWORDLONG version_condition_mask = 0; - - version_test.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - version_test.dwMajorVersion = major; - version_test.dwMinorVersion = minor; - version_test.wServicePackMajor = (WORD)service_pack; - version_test.wServicePackMinor = 0; - - version_test_mask = (VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR); - - VER_SET_CONDITION(version_condition_mask, VER_MAJORVERSION, VER_GREATER_EQUAL); - VER_SET_CONDITION(version_condition_mask, VER_MINORVERSION, VER_GREATER_EQUAL); - VER_SET_CONDITION(version_condition_mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); - VER_SET_CONDITION(version_condition_mask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); - - if (!VerifyVersionInfo(&version_test, version_test_mask, version_condition_mask)) - return 0; - - return 1; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/w32_buffer.c b/vendor/libgit2-sys/libgit2/src/util/win32/w32_buffer.c deleted file mode 100644 index 6fee820..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/w32_buffer.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "w32_buffer.h" - -#include "utf-conv.h" - -GIT_INLINE(int) handle_wc_error(void) -{ - if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) - errno = ENAMETOOLONG; - else - errno = EINVAL; - - return -1; -} - -int git_str_put_w(git_str *buf, const wchar_t *string_w, size_t len_w) -{ - int utf8_len, utf8_write_len; - size_t new_size; - - if (!len_w) { - return 0; - } else if (len_w > INT_MAX) { - git_error_set_oom(); - return -1; - } - - GIT_ASSERT(string_w); - - /* Measure the string necessary for conversion */ - if ((utf8_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string_w, (int)len_w, NULL, 0, NULL, NULL)) == 0) - return 0; - - GIT_ASSERT(utf8_len > 0); - - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len); - GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1); - - if (git_str_grow(buf, new_size) < 0) - return -1; - - if ((utf8_write_len = WideCharToMultiByte( - CP_UTF8, WC_ERR_INVALID_CHARS, string_w, (int)len_w, &buf->ptr[buf->size], utf8_len, NULL, NULL)) == 0) - return handle_wc_error(); - - GIT_ASSERT(utf8_write_len == utf8_len); - - buf->size += utf8_write_len; - buf->ptr[buf->size] = '\0'; - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/w32_buffer.h b/vendor/libgit2-sys/libgit2/src/util/win32/w32_buffer.h deleted file mode 100644 index 68ea960..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/w32_buffer.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_w32_buffer_h__ -#define INCLUDE_win32_w32_buffer_h__ - -#include "git2_util.h" -#include "str.h" - -/** - * Convert a wide character string to UTF-8 and append the results to the - * buffer. - */ -int git_str_put_w(git_str *buf, const wchar_t *string_w, size_t len_w); - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/w32_common.h b/vendor/libgit2-sys/libgit2/src/util/win32/w32_common.h deleted file mode 100644 index c20b3e8..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/w32_common.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_win32_w32_common_h__ -#define INCLUDE_win32_w32_common_h__ - -#include - -/* - * 4096 is the max allowed Git path. `MAX_PATH` (260) is the typical max allowed - * Windows path length, however win32 Unicode APIs generally allow up to 32,767 - * if prefixed with "\\?\" (i.e. converted to an NT-style name). - */ -#define GIT_WIN_PATH_MAX GIT_PATH_MAX - -/* - * Provides a large enough buffer to support Windows Git paths: - * GIT_WIN_PATH_MAX is 4096, corresponding to a maximum path length of 4095 - * characters plus a NULL terminator. Prefixing with "\\?\" adds 4 characters, - * but if the original was a UNC path, then we turn "\\server\share" into - * "\\?\UNC\server\share". So we replace the first two characters with - * 8 characters, a net gain of 6, so the maximum length is GIT_WIN_PATH_MAX+6. - */ -#define GIT_WIN_PATH_UTF16 GIT_WIN_PATH_MAX+6 - -/* Maximum size of a UTF-8 Win32 Git path. We remove the "\\?\" or "\\?\UNC\" - * prefixes for presentation, bringing us back to 4095 (non-NULL) - * characters. UTF-8 does have 4-byte sequences, but they are encoded in - * UTF-16 using surrogate pairs, which takes up the space of two characters. - * Two characters in the range U+0800 -> U+FFFF take up more space in UTF-8 - * (6 bytes) than one surrogate pair (4 bytes). - */ -#define GIT_WIN_PATH_UTF8 ((GIT_WIN_PATH_MAX - 1) * 3 + 1) - -/* - * The length of a Windows "shortname", for 8.3 compatibility. - */ -#define GIT_WIN_PATH_SHORTNAME 13 - -/* Win32 path types */ -typedef wchar_t git_win32_path[GIT_WIN_PATH_UTF16]; -typedef char git_win32_utf8_path[GIT_WIN_PATH_UTF8]; - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/w32_leakcheck.c b/vendor/libgit2-sys/libgit2/src/util/win32/w32_leakcheck.c deleted file mode 100644 index 0f095de..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/w32_leakcheck.c +++ /dev/null @@ -1,581 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "w32_leakcheck.h" - -#if defined(GIT_WIN32_LEAKCHECK) - -#include "Windows.h" -#include "Dbghelp.h" -#include "win32/posix.h" -#include "hash.h" -#include "runtime.h" - -/* Stack frames (for stack tracing, below) */ - -static bool g_win32_stack_initialized = false; -static HANDLE g_win32_stack_process = INVALID_HANDLE_VALUE; -static git_win32_leakcheck_stack_aux_cb_alloc g_aux_cb_alloc = NULL; -static git_win32_leakcheck_stack_aux_cb_lookup g_aux_cb_lookup = NULL; - -int git_win32_leakcheck_stack_set_aux_cb( - git_win32_leakcheck_stack_aux_cb_alloc cb_alloc, - git_win32_leakcheck_stack_aux_cb_lookup cb_lookup) -{ - g_aux_cb_alloc = cb_alloc; - g_aux_cb_lookup = cb_lookup; - - return 0; -} - -/** - * Load symbol table data. This should be done in the primary - * thread at startup (under a lock if there are other threads - * active). - */ -void git_win32_leakcheck_stack_init(void) -{ - if (!g_win32_stack_initialized) { - g_win32_stack_process = GetCurrentProcess(); - SymSetOptions(SYMOPT_LOAD_LINES); - SymInitialize(g_win32_stack_process, NULL, TRUE); - g_win32_stack_initialized = true; - } -} - -/** - * Cleanup symbol table data. This should be done in the - * primary thead at shutdown (under a lock if there are other - * threads active). - */ -void git_win32_leakcheck_stack_cleanup(void) -{ - if (g_win32_stack_initialized) { - SymCleanup(g_win32_stack_process); - g_win32_stack_process = INVALID_HANDLE_VALUE; - g_win32_stack_initialized = false; - } -} - -int git_win32_leakcheck_stack_capture(git_win32_leakcheck_stack_raw_data *pdata, int skip) -{ - if (!g_win32_stack_initialized) { - git_error_set(GIT_ERROR_INVALID, "git_win32_stack not initialized."); - return GIT_ERROR; - } - - memset(pdata, 0, sizeof(*pdata)); - pdata->nr_frames = RtlCaptureStackBackTrace( - skip+1, GIT_WIN32_LEAKCHECK_STACK_MAX_FRAMES, pdata->frames, NULL); - - /* If an "aux" data provider was registered, ask it to capture - * whatever data it needs and give us an "aux_id" to it so that - * we can refer to it later when reporting. - */ - if (g_aux_cb_alloc) - (g_aux_cb_alloc)(&pdata->aux_id); - - return 0; -} - -int git_win32_leakcheck_stack_compare( - git_win32_leakcheck_stack_raw_data *d1, - git_win32_leakcheck_stack_raw_data *d2) -{ - return memcmp(d1, d2, sizeof(*d1)); -} - -int git_win32_leakcheck_stack_format( - char *pbuf, size_t buf_len, - const git_win32_leakcheck_stack_raw_data *pdata, - const char *prefix, const char *suffix) -{ -#define MY_MAX_FILENAME 255 - - /* SYMBOL_INFO has char FileName[1] at the end. The docs say to - * to malloc it with extra space for your desired max filename. - */ - struct { - SYMBOL_INFO symbol; - char extra[MY_MAX_FILENAME + 1]; - } s; - - IMAGEHLP_LINE64 line; - size_t buf_used = 0; - unsigned int k; - char detail[MY_MAX_FILENAME * 2]; /* filename plus space for function name and formatting */ - size_t detail_len; - - if (!g_win32_stack_initialized) { - git_error_set(GIT_ERROR_INVALID, "git_win32_stack not initialized."); - return GIT_ERROR; - } - - if (!prefix) - prefix = "\t"; - if (!suffix) - suffix = "\n"; - - memset(pbuf, 0, buf_len); - - memset(&s, 0, sizeof(s)); - s.symbol.MaxNameLen = MY_MAX_FILENAME; - s.symbol.SizeOfStruct = sizeof(SYMBOL_INFO); - - memset(&line, 0, sizeof(line)); - line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); - - for (k=0; k < pdata->nr_frames; k++) { - DWORD64 frame_k = (DWORD64)pdata->frames[k]; - DWORD dwUnused; - - if (SymFromAddr(g_win32_stack_process, frame_k, 0, &s.symbol) && - SymGetLineFromAddr64(g_win32_stack_process, frame_k, &dwUnused, &line)) { - const char *pslash; - const char *pfile; - - pslash = strrchr(line.FileName, '\\'); - pfile = ((pslash) ? (pslash+1) : line.FileName); - p_snprintf(detail, sizeof(detail), "%s%s:%d> %s%s", - prefix, pfile, line.LineNumber, s.symbol.Name, suffix); - } else { - /* This happens when we cross into another module. - * For example, in CLAR tests, this is typically - * the CRT startup code. Just print an unknown - * frame and continue. - */ - p_snprintf(detail, sizeof(detail), "%s??%s", prefix, suffix); - } - detail_len = strlen(detail); - - if (buf_len < (buf_used + detail_len + 1)) { - /* we don't have room for this frame in the buffer, so just stop. */ - break; - } - - memcpy(&pbuf[buf_used], detail, detail_len); - buf_used += detail_len; - } - - /* "aux_id" 0 is reserved to mean no aux data. This is needed to handle - * allocs that occur before the aux callbacks were registered. - */ - if (pdata->aux_id > 0) { - p_snprintf(detail, sizeof(detail), "%saux_id: %d%s", - prefix, pdata->aux_id, suffix); - detail_len = strlen(detail); - if ((buf_used + detail_len + 1) < buf_len) { - memcpy(&pbuf[buf_used], detail, detail_len); - buf_used += detail_len; - } - - /* If an "aux" data provider is still registered, ask it to append its detailed - * data to the end of ours using the "aux_id" it gave us when this de-duped - * item was created. - */ - if (g_aux_cb_lookup) - (g_aux_cb_lookup)(pdata->aux_id, &pbuf[buf_used], (buf_len - buf_used - 1)); - } - - return GIT_OK; -} - -int git_win32_leakcheck_stack( - char * pbuf, size_t buf_len, - int skip, - const char *prefix, const char *suffix) -{ - git_win32_leakcheck_stack_raw_data data; - int error; - - if ((error = git_win32_leakcheck_stack_capture(&data, skip)) < 0) - return error; - if ((error = git_win32_leakcheck_stack_format(pbuf, buf_len, &data, prefix, suffix)) < 0) - return error; - return 0; -} - -/* Stack tracing */ - -#define STACKTRACE_UID_LEN (15) - -/** - * The stacktrace of an allocation can be distilled - * to a unique id based upon the stackframe pointers - * and ignoring any size arguments. We will use these - * UIDs as the (char const*) __FILE__ argument we - * give to the CRT malloc routines. - */ -typedef struct { - char uid[STACKTRACE_UID_LEN + 1]; -} git_win32_leakcheck_stacktrace_uid; - -/** - * All mallocs with the same stacktrace will be de-duped - * and aggregated into this row. - */ -typedef struct { - git_win32_leakcheck_stacktrace_uid uid; /* must be first */ - git_win32_leakcheck_stack_raw_data raw_data; - unsigned int count_allocs; /* times this alloc signature seen since init */ - unsigned int count_allocs_at_last_checkpoint; /* times since last mark */ - unsigned int transient_count_leaks; /* sum of leaks */ -} git_win32_leakcheck_stacktrace_row; - -static CRITICAL_SECTION g_crtdbg_stacktrace_cs; - -/** - * CRTDBG memory leak tracking takes a "char const * const file_name" - * and stores the pointer in the heap data (instead of allocing a copy - * for itself). Normally, this is not a problem, since we usually pass - * in __FILE__. But I'm going to lie to it and pass in the address of - * the UID in place of the file_name. Also, I do not want to alloc the - * stacktrace data (because we are called from inside our alloc routines). - * Therefore, I'm creating a very large static pool array to store row - * data. This also eliminates the temptation to realloc it (and move the - * UID pointers). - * - * And to efficiently look for duplicates we need an index on the rows - * so we can bsearch it. Again, without mallocing. - * - * If we observe more than MY_ROW_LIMIT unique malloc signatures, we - * fall through and use the traditional __FILE__ processing and don't - * try to de-dup them. If your testing hits this limit, just increase - * it and try again. - */ - -#define MY_ROW_LIMIT (2 * 1024 * 1024) -static git_win32_leakcheck_stacktrace_row g_cs_rows[MY_ROW_LIMIT]; -static git_win32_leakcheck_stacktrace_row *g_cs_index[MY_ROW_LIMIT]; - -static unsigned int g_cs_end = MY_ROW_LIMIT; -static unsigned int g_cs_ins = 0; /* insertion point == unique allocs seen */ -static unsigned int g_count_total_allocs = 0; /* number of allocs seen */ -static unsigned int g_transient_count_total_leaks = 0; /* number of total leaks */ -static unsigned int g_transient_count_dedup_leaks = 0; /* number of unique leaks */ -static bool g_limit_reached = false; /* had allocs after we filled row table */ - -static unsigned int g_checkpoint_id = 0; /* to better label leak checkpoints */ -static bool g_transient_leaks_since_mark = false; /* payload for hook */ - -/** - * Compare function for bsearch on g_cs_index table. - */ -static int row_cmp(const void *v1, const void *v2) -{ - git_win32_leakcheck_stack_raw_data *d1 = (git_win32_leakcheck_stack_raw_data*)v1; - git_win32_leakcheck_stacktrace_row *r2 = (git_win32_leakcheck_stacktrace_row *)v2; - - return (git_win32_leakcheck_stack_compare(d1, &r2->raw_data)); -} - -/** - * Unique insert the new data into the row and index tables. - * We have to sort by the stackframe data itself, not the uid. - */ -static git_win32_leakcheck_stacktrace_row * insert_unique( - const git_win32_leakcheck_stack_raw_data *pdata) -{ - size_t pos; - if (git__bsearch(g_cs_index, g_cs_ins, pdata, row_cmp, &pos) < 0) { - /* Append new unique item to row table. */ - memcpy(&g_cs_rows[g_cs_ins].raw_data, pdata, sizeof(*pdata)); - sprintf(g_cs_rows[g_cs_ins].uid.uid, "##%08lx", g_cs_ins); - - /* Insert pointer to it into the proper place in the index table. */ - if (pos < g_cs_ins) - memmove(&g_cs_index[pos+1], &g_cs_index[pos], (g_cs_ins - pos)*sizeof(g_cs_index[0])); - g_cs_index[pos] = &g_cs_rows[g_cs_ins]; - - g_cs_ins++; - } - - g_cs_index[pos]->count_allocs++; - - return g_cs_index[pos]; -} - -/** - * Hook function to receive leak data from the CRT. (This includes - * both ":()" data, but also each of the - * various headers and fields. - * - * Scan this for the special "##" UID forms that we substituted - * for the "". Map back to the row data and - * increment its leak count. - * - * See https://msdn.microsoft.com/en-us/library/74kabxyx.aspx - * - * We suppress the actual crtdbg output. - */ -static int __cdecl report_hook(int nRptType, char *szMsg, int *retVal) -{ - static int hook_result = TRUE; /* FALSE to get stock dump; TRUE to suppress. */ - unsigned int pos; - - *retVal = 0; /* do not invoke debugger */ - - if ((szMsg[0] != '#') || (szMsg[1] != '#')) - return hook_result; - - if (sscanf(&szMsg[2], "%08lx", &pos) < 1) - return hook_result; - if (pos >= g_cs_ins) - return hook_result; - - if (g_transient_leaks_since_mark) { - if (g_cs_rows[pos].count_allocs == g_cs_rows[pos].count_allocs_at_last_checkpoint) - return hook_result; - } - - g_cs_rows[pos].transient_count_leaks++; - - if (g_cs_rows[pos].transient_count_leaks == 1) - g_transient_count_dedup_leaks++; - - g_transient_count_total_leaks++; - - return hook_result; -} - -/** - * Write leak data to all of the various places we need. - * We force the caller to sprintf() the message first - * because we want to avoid fprintf() because it allocs. - */ -static void my_output(const char *buf) -{ - fwrite(buf, strlen(buf), 1, stderr); - OutputDebugString(buf); -} - -/** - * For each row with leaks, dump a stacktrace for it. - */ -static void dump_summary(const char *label) -{ - unsigned int k; - char buf[10 * 1024]; - - if (g_transient_count_total_leaks == 0) - return; - - fflush(stdout); - fflush(stderr); - my_output("\n"); - - if (g_limit_reached) { - sprintf(buf, - "LEAK SUMMARY: de-dup row table[%d] filled. Increase MY_ROW_LIMIT.\n", - MY_ROW_LIMIT); - my_output(buf); - } - - if (!label) - label = ""; - - if (g_transient_leaks_since_mark) { - sprintf(buf, "LEAK CHECKPOINT %d: leaks %d unique %d: %s\n", - g_checkpoint_id, g_transient_count_total_leaks, g_transient_count_dedup_leaks, label); - my_output(buf); - } else { - sprintf(buf, "LEAK SUMMARY: TOTAL leaks %d de-duped %d: %s\n", - g_transient_count_total_leaks, g_transient_count_dedup_leaks, label); - my_output(buf); - } - my_output("\n"); - - for (k = 0; k < g_cs_ins; k++) { - if (g_cs_rows[k].transient_count_leaks > 0) { - sprintf(buf, "LEAK: %s leaked %d of %d times:\n", - g_cs_rows[k].uid.uid, - g_cs_rows[k].transient_count_leaks, - g_cs_rows[k].count_allocs); - my_output(buf); - - if (git_win32_leakcheck_stack_format( - buf, sizeof(buf), &g_cs_rows[k].raw_data, - NULL, NULL) >= 0) { - my_output(buf); - } - - my_output("\n"); - } - } - - fflush(stderr); -} - -/** - * Initialize our memory leak tracking and de-dup data structures. - * This should ONLY be called by git_libgit2_init(). - */ -void git_win32_leakcheck_stacktrace_init(void) -{ - InitializeCriticalSection(&g_crtdbg_stacktrace_cs); - - EnterCriticalSection(&g_crtdbg_stacktrace_cs); - - _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - - _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); - _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); - - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); - _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); - - LeaveCriticalSection(&g_crtdbg_stacktrace_cs); -} - -int git_win32_leakcheck_stacktrace_dump( - git_win32_leakcheck_stacktrace_options opt, - const char *label) -{ - _CRT_REPORT_HOOK old; - unsigned int k; - int r = 0; - -#define IS_BIT_SET(o,b) (((o) & (b)) != 0) - - bool b_set_mark = IS_BIT_SET(opt, GIT_WIN32_LEAKCHECK_STACKTRACE_SET_MARK); - bool b_leaks_since_mark = IS_BIT_SET(opt, GIT_WIN32_LEAKCHECK_STACKTRACE_LEAKS_SINCE_MARK); - bool b_leaks_total = IS_BIT_SET(opt, GIT_WIN32_LEAKCHECK_STACKTRACE_LEAKS_TOTAL); - bool b_quiet = IS_BIT_SET(opt, GIT_WIN32_LEAKCHECK_STACKTRACE_QUIET); - - if (b_leaks_since_mark && b_leaks_total) { - git_error_set(GIT_ERROR_INVALID, "cannot combine LEAKS_SINCE_MARK and LEAKS_TOTAL."); - return GIT_ERROR; - } - if (!b_set_mark && !b_leaks_since_mark && !b_leaks_total) { - git_error_set(GIT_ERROR_INVALID, "nothing to do."); - return GIT_ERROR; - } - - EnterCriticalSection(&g_crtdbg_stacktrace_cs); - - if (b_leaks_since_mark || b_leaks_total) { - /* All variables with "transient" in the name are per-dump counters - * and reset before each dump. This lets us handle checkpoints. - */ - g_transient_count_total_leaks = 0; - g_transient_count_dedup_leaks = 0; - for (k = 0; k < g_cs_ins; k++) { - g_cs_rows[k].transient_count_leaks = 0; - } - } - - g_transient_leaks_since_mark = b_leaks_since_mark; - - old = _CrtSetReportHook(report_hook); - _CrtDumpMemoryLeaks(); - _CrtSetReportHook(old); - - if (b_leaks_since_mark || b_leaks_total) { - r = g_transient_count_dedup_leaks; - - if (!b_quiet) - dump_summary(label); - } - - if (b_set_mark) { - for (k = 0; k < g_cs_ins; k++) { - g_cs_rows[k].count_allocs_at_last_checkpoint = g_cs_rows[k].count_allocs; - } - - g_checkpoint_id++; - } - - LeaveCriticalSection(&g_crtdbg_stacktrace_cs); - - return r; -} - -/** - * Shutdown our memory leak tracking and dump summary data. - * This should ONLY be called by git_libgit2_shutdown(). - * - * We explicitly call _CrtDumpMemoryLeaks() during here so - * that we can compute summary data for the leaks. We print - * the stacktrace of each unique leak. - * - * This cleanup does not happen if the app calls exit() - * without calling the libgit2 shutdown code. - * - * This info we print here is independent of any automatic - * reporting during exit() caused by _CRTDBG_LEAK_CHECK_DF. - * Set it in your app if you also want traditional reporting. - */ -void git_win32_leakcheck_stacktrace_cleanup(void) -{ - /* At shutdown/cleanup, dump cumulative leak info - * with everything since startup. This might generate - * extra noise if the caller has been doing checkpoint - * dumps, but it might also eliminate some false - * positives for resources previously reported during - * checkpoints. - */ - git_win32_leakcheck_stacktrace_dump( - GIT_WIN32_LEAKCHECK_STACKTRACE_LEAKS_TOTAL, - "CLEANUP"); - - DeleteCriticalSection(&g_crtdbg_stacktrace_cs); -} - -const char *git_win32_leakcheck_stacktrace(int skip, const char *file) -{ - git_win32_leakcheck_stack_raw_data new_data; - git_win32_leakcheck_stacktrace_row *row; - const char * result = file; - - if (git_win32_leakcheck_stack_capture(&new_data, skip+1) < 0) - return result; - - EnterCriticalSection(&g_crtdbg_stacktrace_cs); - - if (g_cs_ins < g_cs_end) { - row = insert_unique(&new_data); - result = row->uid.uid; - } else { - g_limit_reached = true; - } - - g_count_total_allocs++; - - LeaveCriticalSection(&g_crtdbg_stacktrace_cs); - - return result; -} - -static void git_win32_leakcheck_global_shutdown(void) -{ - git_win32_leakcheck_stacktrace_cleanup(); - git_win32_leakcheck_stack_cleanup(); -} - -bool git_win32_leakcheck_has_leaks(void) -{ - return (g_transient_count_total_leaks > 0); -} - -int git_win32_leakcheck_global_init(void) -{ - git_win32_leakcheck_stacktrace_init(); - git_win32_leakcheck_stack_init(); - - return git_runtime_shutdown_register(git_win32_leakcheck_global_shutdown); -} - -#else - -int git_win32_leakcheck_global_init(void) -{ - return 0; -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/w32_leakcheck.h b/vendor/libgit2-sys/libgit2/src/util/win32/w32_leakcheck.h deleted file mode 100644 index 82d8638..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/w32_leakcheck.h +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_win32_leakcheck_h__ -#define INCLUDE_win32_leakcheck_h__ - -#include "git2_util.h" - -/* Initialize the win32 leak checking system. */ -int git_win32_leakcheck_global_init(void); - -#if defined(GIT_WIN32_LEAKCHECK) - -#include -#include - -#include "git2/errors.h" -#include "strnlen.h" - -bool git_win32_leakcheck_has_leaks(void); - -/* Stack frames (for stack tracing, below) */ - -/** - * This type defines a callback to be used to augment a C stacktrace - * with "aux" data. This can be used, for example, to allow LibGit2Sharp - * (or other interpreted consumer libraries) to give us C# stacktrace - * data for the PInvoke. - * - * This callback will be called during crtdbg-instrumented allocs. - * - * @param aux_id [out] A returned "aux_id" representing a unique - * (de-duped at the C# layer) stacktrace. "aux_id" 0 is reserved - * to mean no aux stacktrace data. - */ -typedef void (*git_win32_leakcheck_stack_aux_cb_alloc)(unsigned int *aux_id); - -/** - * This type defines a callback to be used to augment the output of - * a stacktrace. This will be used to request the C# layer format - * the C# stacktrace associated with "aux_id" into the provided - * buffer. - * - * This callback will be called during leak reporting. - * - * @param aux_id The "aux_id" key associated with a stacktrace. - * @param aux_msg A buffer where a formatted message should be written. - * @param aux_msg_len The size of the buffer. - */ -typedef void (*git_win32_leakcheck_stack_aux_cb_lookup)(unsigned int aux_id, char *aux_msg, size_t aux_msg_len); - -/** - * Register an "aux" data provider to augment our C stacktrace data. - * - * This can be used, for example, to allow LibGit2Sharp (or other - * interpreted consumer libraries) to give us the C# stacktrace of - * the PInvoke. - * - * If you choose to use this feature, it should be registered during - * initialization and not changed for the duration of the process. - */ -int git_win32_leakcheck_stack_set_aux_cb( - git_win32_leakcheck_stack_aux_cb_alloc cb_alloc, - git_win32_leakcheck_stack_aux_cb_lookup cb_lookup); - -/** - * Maximum number of stackframes to record for a - * single stacktrace. - */ -#define GIT_WIN32_LEAKCHECK_STACK_MAX_FRAMES 30 - -/** - * Wrapper containing the raw unprocessed stackframe - * data for a single stacktrace and any "aux_id". - * - * I put the aux_id first so leaks will be sorted by it. - * So, for example, if a specific callstack in C# leaks - * a repo handle, all of the pointers within the associated - * repo pointer will be grouped together. - */ -typedef struct { - unsigned int aux_id; - unsigned int nr_frames; - void *frames[GIT_WIN32_LEAKCHECK_STACK_MAX_FRAMES]; -} git_win32_leakcheck_stack_raw_data; - -/** - * Capture raw stack trace data for the current process/thread. - * - * @param skip Number of initial frames to skip. Pass 0 to - * begin with the caller of this routine. Pass 1 to begin - * with its caller. And so on. - */ -int git_win32_leakcheck_stack_capture(git_win32_leakcheck_stack_raw_data *pdata, int skip); - -/** - * Compare 2 raw stacktraces with the usual -1,0,+1 result. - * This includes any "aux_id" values in the comparison, so that - * our de-dup is also "aux" context relative. - */ -int git_win32_leakcheck_stack_compare( - git_win32_leakcheck_stack_raw_data *d1, - git_win32_leakcheck_stack_raw_data *d2); - -/** - * Format raw stacktrace data into buffer WITHOUT using any mallocs. - * - * @param prefix String written before each frame; defaults to "\t". - * @param suffix String written after each frame; defaults to "\n". - */ -int git_win32_leakcheck_stack_format( - char *pbuf, size_t buf_len, - const git_win32_leakcheck_stack_raw_data *pdata, - const char *prefix, const char *suffix); - -/** - * Convenience routine to capture and format stacktrace into - * a buffer WITHOUT using any mallocs. This is primarily a - * wrapper for testing. - * - * @param skip Number of initial frames to skip. Pass 0 to - * begin with the caller of this routine. Pass 1 to begin - * with its caller. And so on. - * @param prefix String written before each frame; defaults to "\t". - * @param suffix String written after each frame; defaults to "\n". - */ -int git_win32_leakcheck_stack( - char * pbuf, size_t buf_len, - int skip, - const char *prefix, const char *suffix); - -/* Stack tracing */ - -/* MSVC CRTDBG memory leak reporting. - * - * We DO NOT use the "_CRTDBG_MAP_ALLOC" macro described in the MSVC - * documentation because all allocs/frees in libgit2 already go through - * the "git__" routines defined in this file. Simply using the normal - * reporting mechanism causes all leaks to be attributed to a routine - * here in util.h (ie, the actual call to calloc()) rather than the - * caller of git__calloc(). - * - * Therefore, we declare a set of "git__crtdbg__" routines to replace - * the corresponding "git__" routines and re-define the "git__" symbols - * as macros. This allows us to get and report the file:line info of - * the real caller. - * - * We DO NOT replace the "git__free" routine because it needs to remain - * a function pointer because it is used as a function argument when - * setting up various structure "destructors". - * - * We also DO NOT use the "_CRTDBG_MAP_ALLOC" macro because it causes - * "free" to be remapped to "_free_dbg" and this causes problems for - * structures which define a field named "free". - * - * Finally, CRTDBG must be explicitly enabled and configured at program - * startup. See tests/main.c for an example. - */ - -/** - * Checkpoint options. - */ -typedef enum git_win32_leakcheck_stacktrace_options { - /** - * Set checkpoint marker. - */ - GIT_WIN32_LEAKCHECK_STACKTRACE_SET_MARK = (1 << 0), - - /** - * Dump leaks since last checkpoint marker. - * May not be combined with _LEAKS_TOTAL. - * - * Note that this may generate false positives for global TLS - * error state and other global caches that aren't cleaned up - * until the thread/process terminates. So when using this - * around a region of interest, also check the final (at exit) - * dump before digging into leaks reported here. - */ - GIT_WIN32_LEAKCHECK_STACKTRACE_LEAKS_SINCE_MARK = (1 << 1), - - /** - * Dump leaks since init. May not be combined - * with _LEAKS_SINCE_MARK. - */ - GIT_WIN32_LEAKCHECK_STACKTRACE_LEAKS_TOTAL = (1 << 2), - - /** - * Suppress printing during dumps. - * Just return leak count. - */ - GIT_WIN32_LEAKCHECK_STACKTRACE_QUIET = (1 << 3), - -} git_win32_leakcheck_stacktrace_options; - -/** - * Checkpoint memory state and/or dump unique stack traces of - * current memory leaks. - * - * @return number of unique leaks (relative to requested starting - * point) or error. - */ -int git_win32_leakcheck_stacktrace_dump( - git_win32_leakcheck_stacktrace_options opt, - const char *label); - -/** - * Construct stacktrace and append it to the global buffer. - * Return pointer to start of this string. On any error or - * lack of buffer space, just return the given file buffer - * so it will behave as usual. - * - * This should ONLY be called by our internal memory allocations - * routines. - */ -const char *git_win32_leakcheck_stacktrace(int skip, const char *file); - -#endif -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/w32_util.c b/vendor/libgit2-sys/libgit2/src/util/win32/w32_util.c deleted file mode 100644 index f5b006a..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/w32_util.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "w32_util.h" - -/** - * Creates a FindFirstFile(Ex) filter string from a UTF-8 path. - * The filter string enumerates all items in the directory. - * - * @param dest The buffer to receive the filter string. - * @param src The UTF-8 path of the directory to enumerate. - * @return True if the filter string was created successfully; false otherwise - */ -bool git_win32__findfirstfile_filter(git_win32_path dest, const char *src) -{ - static const wchar_t suffix[] = L"\\*"; - int len = git_win32_path_from_utf8(dest, src); - - /* Ensure the path was converted */ - if (len < 0) - return false; - - /* Ensure that the path does not end with a trailing slash, - * because we're about to add one. Don't rely our trim_end - * helper, because we want to remove the backslash even for - * drive letter paths, in this case. */ - if (len > 0 && - (dest[len - 1] == L'/' || dest[len - 1] == L'\\')) { - dest[len - 1] = L'\0'; - len--; - } - - /* Ensure we have enough room to add the suffix */ - if ((size_t)len >= GIT_WIN_PATH_UTF16 - CONST_STRLEN(suffix)) - return false; - - wcscat(dest, suffix); - return true; -} - -/** - * Ensures the given path (file or folder) has the +H (hidden) attribute set. - * - * @param path The path which should receive the +H bit. - * @return 0 on success; -1 on failure - */ -int git_win32__set_hidden(const char *path, bool hidden) -{ - git_win32_path buf; - DWORD attrs, newattrs; - - if (git_win32_path_from_utf8(buf, path) < 0) - return -1; - - attrs = GetFileAttributesW(buf); - - /* Ensure the path exists */ - if (attrs == INVALID_FILE_ATTRIBUTES) - return -1; - - if (hidden) - newattrs = attrs | FILE_ATTRIBUTE_HIDDEN; - else - newattrs = attrs & ~FILE_ATTRIBUTE_HIDDEN; - - if (attrs != newattrs && !SetFileAttributesW(buf, newattrs)) { - git_error_set(GIT_ERROR_OS, "failed to %s hidden bit for '%s'", - hidden ? "set" : "unset", path); - return -1; - } - - return 0; -} - -int git_win32__hidden(bool *out, const char *path) -{ - git_win32_path buf; - DWORD attrs; - - if (git_win32_path_from_utf8(buf, path) < 0) - return -1; - - attrs = GetFileAttributesW(buf); - - /* Ensure the path exists */ - if (attrs == INVALID_FILE_ATTRIBUTES) - return -1; - - *out = (attrs & FILE_ATTRIBUTE_HIDDEN) ? true : false; - return 0; -} - -int git_win32__file_attribute_to_stat( - struct stat *st, - const WIN32_FILE_ATTRIBUTE_DATA *attrdata, - const wchar_t *path) -{ - git_win32__stat_init(st, - attrdata->dwFileAttributes, - attrdata->nFileSizeHigh, - attrdata->nFileSizeLow, - attrdata->ftCreationTime, - attrdata->ftLastAccessTime, - attrdata->ftLastWriteTime); - - if (attrdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && path) { - git_win32_path target; - - if (git_win32_path_readlink_w(target, path) >= 0) { - st->st_mode = (st->st_mode & ~S_IFMT) | S_IFLNK; - - /* st_size gets the UTF-8 length of the target name, in bytes, - * not counting the NULL terminator */ - if ((st->st_size = git_utf8_from_16(NULL, 0, target)) < 0) { - git_error_set(GIT_ERROR_OS, "could not convert reparse point name for '%ls'", path); - return -1; - } - } - } - - return 0; -} diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/w32_util.h b/vendor/libgit2-sys/libgit2/src/util/win32/w32_util.h deleted file mode 100644 index 5196637..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/w32_util.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_win32_w32_util_h__ -#define INCLUDE_win32_w32_util_h__ - -#include "git2_util.h" - -#include "utf-conv.h" -#include "posix.h" -#include "path_w32.h" - -/* - -#include "common.h" -#include "path.h" -#include "path_w32.h" -#include "utf-conv.h" -#include "posix.h" -#include "reparse.h" -#include "dir.h" -*/ - - -GIT_INLINE(bool) git_win32__isalpha(wchar_t c) -{ - return ((c >= L'A' && c <= L'Z') || (c >= L'a' && c <= L'z')); -} - -/** - * Creates a FindFirstFile(Ex) filter string from a UTF-8 path. - * The filter string enumerates all items in the directory. - * - * @param dest The buffer to receive the filter string. - * @param src The UTF-8 path of the directory to enumerate. - * @return True if the filter string was created successfully; false otherwise - */ -bool git_win32__findfirstfile_filter(git_win32_path dest, const char *src); - -/** - * Ensures the given path (file or folder) has the +H (hidden) attribute set - * or unset. - * - * @param path The path that should receive the +H bit. - * @param hidden true to set +H, false to unset it - * @return 0 on success; -1 on failure - */ -extern int git_win32__set_hidden(const char *path, bool hidden); - -/** - * Determines if the given file or folder has the hidden attribute set. - * @param hidden pointer to store hidden value - * @param path The path that should be queried for hiddenness. - * @return 0 on success or an error code. - */ -extern int git_win32__hidden(bool *hidden, const char *path); - -extern int git_win32__file_attribute_to_stat( - struct stat *st, - const WIN32_FILE_ATTRIBUTE_DATA *attrdata, - const wchar_t *path); - -/** - * Converts a FILETIME structure to a struct timespec. - * - * @param FILETIME A pointer to a FILETIME - * @param ts A pointer to the timespec structure to fill in - */ -GIT_INLINE(void) git_win32__filetime_to_timespec( - const FILETIME *ft, - struct timespec *ts) -{ - int64_t winTime = ((int64_t)ft->dwHighDateTime << 32) + ft->dwLowDateTime; - winTime -= INT64_C(116444736000000000); /* Windows to Unix Epoch conversion */ - ts->tv_sec = (time_t)(winTime / 10000000); -#ifdef GIT_USE_NSEC - ts->tv_nsec = (winTime % 10000000) * 100; -#else - ts->tv_nsec = 0; -#endif -} - -GIT_INLINE(void) git_win32__timeval_to_filetime( - FILETIME *ft, const struct p_timeval tv) -{ - int64_t ticks = (tv.tv_sec * INT64_C(10000000)) + - (tv.tv_usec * INT64_C(10)) + INT64_C(116444736000000000); - - ft->dwHighDateTime = ((ticks >> 32) & INT64_C(0xffffffff)); - ft->dwLowDateTime = (ticks & INT64_C(0xffffffff)); -} - -GIT_INLINE(void) git_win32__stat_init( - struct stat *st, - DWORD dwFileAttributes, - DWORD nFileSizeHigh, - DWORD nFileSizeLow, - FILETIME ftCreationTime, - FILETIME ftLastAccessTime, - FILETIME ftLastWriteTime) -{ - mode_t mode = S_IREAD; - - memset(st, 0, sizeof(struct stat)); - - if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - mode |= S_IFDIR; - else - mode |= S_IFREG; - - if ((dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0) - mode |= S_IWRITE; - - st->st_ino = 0; - st->st_gid = 0; - st->st_uid = 0; - st->st_nlink = 1; - st->st_mode = mode; - st->st_size = ((int64_t)nFileSizeHigh << 32) + nFileSizeLow; - st->st_dev = _getdrive() - 1; - st->st_rdev = st->st_dev; - git_win32__filetime_to_timespec(&ftLastAccessTime, &(st->st_atim)); - git_win32__filetime_to_timespec(&ftLastWriteTime, &(st->st_mtim)); - git_win32__filetime_to_timespec(&ftCreationTime, &(st->st_ctim)); -} - -GIT_INLINE(void) git_win32__file_information_to_stat( - struct stat *st, - const BY_HANDLE_FILE_INFORMATION *fileinfo) -{ - git_win32__stat_init(st, - fileinfo->dwFileAttributes, - fileinfo->nFileSizeHigh, - fileinfo->nFileSizeLow, - fileinfo->ftCreationTime, - fileinfo->ftLastAccessTime, - fileinfo->ftLastWriteTime); -} - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/win32/win32-compat.h b/vendor/libgit2-sys/libgit2/src/util/win32/win32-compat.h deleted file mode 100644 index dee40a4..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/win32/win32-compat.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_win32_win32_compat_h__ -#define INCLUDE_win32_win32_compat_h__ - -#include -#include -#include -#include -#include - -typedef long suseconds_t; - -struct p_timeval { - time_t tv_sec; - suseconds_t tv_usec; -}; - -struct p_timespec { - time_t tv_sec; - long tv_nsec; -}; - -#define timespec p_timespec - -struct p_stat { - _dev_t st_dev; - _ino_t st_ino; - mode_t st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - __int64 st_size; - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; -#define st_atime st_atim.tv_sec -#define st_mtime st_mtim.tv_sec -#define st_ctime st_ctim.tv_sec -#define st_atime_nsec st_atim.tv_nsec -#define st_mtime_nsec st_mtim.tv_nsec -#define st_ctime_nsec st_ctim.tv_nsec -}; - -#define stat p_stat - -#endif diff --git a/vendor/libgit2-sys/libgit2/src/util/zstream.c b/vendor/libgit2-sys/libgit2/src/util/zstream.c deleted file mode 100644 index cb8b125..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/zstream.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "zstream.h" - -#include - -#include "str.h" - -#define ZSTREAM_BUFFER_SIZE (1024 * 1024) -#define ZSTREAM_BUFFER_MIN_EXTRA 8 - -GIT_INLINE(int) zstream_seterr(git_zstream *zs) -{ - switch (zs->zerr) { - case Z_OK: - case Z_STREAM_END: - case Z_BUF_ERROR: /* not fatal; we retry with a larger buffer */ - return 0; - case Z_MEM_ERROR: - git_error_set_oom(); - break; - default: - if (zs->z.msg) - git_error_set_str(GIT_ERROR_ZLIB, zs->z.msg); - else - git_error_set(GIT_ERROR_ZLIB, "unknown compression error"); - } - - return -1; -} - -int git_zstream_init(git_zstream *zstream, git_zstream_t type) -{ - zstream->type = type; - - if (zstream->type == GIT_ZSTREAM_INFLATE) - zstream->zerr = inflateInit(&zstream->z); - else - zstream->zerr = deflateInit(&zstream->z, Z_DEFAULT_COMPRESSION); - return zstream_seterr(zstream); -} - -void git_zstream_free(git_zstream *zstream) -{ - if (zstream->type == GIT_ZSTREAM_INFLATE) - inflateEnd(&zstream->z); - else - deflateEnd(&zstream->z); -} - -void git_zstream_reset(git_zstream *zstream) -{ - if (zstream->type == GIT_ZSTREAM_INFLATE) - inflateReset(&zstream->z); - else - deflateReset(&zstream->z); - zstream->in = NULL; - zstream->in_len = 0; - zstream->zerr = Z_STREAM_END; -} - -int git_zstream_set_input(git_zstream *zstream, const void *in, size_t in_len) -{ - zstream->in = in; - zstream->in_len = in_len; - zstream->zerr = Z_OK; - return 0; -} - -bool git_zstream_done(git_zstream *zstream) -{ - return (!zstream->in_len && zstream->zerr == Z_STREAM_END); -} - -bool git_zstream_eos(git_zstream *zstream) -{ - return zstream->zerr == Z_STREAM_END; -} - -size_t git_zstream_suggest_output_len(git_zstream *zstream) -{ - if (zstream->in_len > ZSTREAM_BUFFER_SIZE) - return ZSTREAM_BUFFER_SIZE; - else if (zstream->in_len > ZSTREAM_BUFFER_MIN_EXTRA) - return zstream->in_len; - else - return ZSTREAM_BUFFER_MIN_EXTRA; -} - -int git_zstream_get_output_chunk( - void *out, size_t *out_len, git_zstream *zstream) -{ - size_t in_queued, in_used, out_queued; - - /* set up input data */ - zstream->z.next_in = (Bytef *)zstream->in; - - /* feed as much data to zlib as it can consume, at most UINT_MAX */ - if (zstream->in_len > UINT_MAX) { - zstream->z.avail_in = UINT_MAX; - zstream->flush = Z_NO_FLUSH; - } else { - zstream->z.avail_in = (uInt)zstream->in_len; - zstream->flush = Z_FINISH; - } - in_queued = (size_t)zstream->z.avail_in; - - /* set up output data */ - zstream->z.next_out = out; - zstream->z.avail_out = (uInt)*out_len; - - if ((size_t)zstream->z.avail_out != *out_len) - zstream->z.avail_out = UINT_MAX; - out_queued = (size_t)zstream->z.avail_out; - - /* compress next chunk */ - if (zstream->type == GIT_ZSTREAM_INFLATE) - zstream->zerr = inflate(&zstream->z, zstream->flush); - else - zstream->zerr = deflate(&zstream->z, zstream->flush); - - if (zstream_seterr(zstream)) - return -1; - - in_used = (in_queued - zstream->z.avail_in); - zstream->in_len -= in_used; - zstream->in += in_used; - - *out_len = (out_queued - zstream->z.avail_out); - - return 0; -} - -int git_zstream_get_output(void *out, size_t *out_len, git_zstream *zstream) -{ - size_t out_remain = *out_len; - - if (zstream->in_len && zstream->zerr == Z_STREAM_END) { - git_error_set(GIT_ERROR_ZLIB, "zlib input had trailing garbage"); - return -1; - } - - while (out_remain > 0 && zstream->zerr != Z_STREAM_END) { - size_t out_written = out_remain; - - if (git_zstream_get_output_chunk(out, &out_written, zstream) < 0) - return -1; - - out_remain -= out_written; - out = ((char *)out) + out_written; - } - - /* either we finished the input or we did not flush the data */ - GIT_ASSERT(zstream->in_len > 0 || zstream->flush == Z_FINISH); - - /* set out_size to number of bytes actually written to output */ - *out_len = *out_len - out_remain; - - return 0; -} - -static int zstream_buf(git_str *out, const void *in, size_t in_len, git_zstream_t type) -{ - git_zstream zs = GIT_ZSTREAM_INIT; - int error = 0; - - if ((error = git_zstream_init(&zs, type)) < 0) - return error; - - if ((error = git_zstream_set_input(&zs, in, in_len)) < 0) - goto done; - - while (!git_zstream_done(&zs)) { - size_t step = git_zstream_suggest_output_len(&zs), written; - - if ((error = git_str_grow_by(out, step)) < 0) - goto done; - - written = out->asize - out->size; - - if ((error = git_zstream_get_output( - out->ptr + out->size, &written, &zs)) < 0) - goto done; - - out->size += written; - } - - /* NULL terminate for consistency if possible */ - if (out->size < out->asize) - out->ptr[out->size] = '\0'; - -done: - git_zstream_free(&zs); - return error; -} - -int git_zstream_deflatebuf(git_str *out, const void *in, size_t in_len) -{ - return zstream_buf(out, in, in_len, GIT_ZSTREAM_DEFLATE); -} - -int git_zstream_inflatebuf(git_str *out, const void *in, size_t in_len) -{ - return zstream_buf(out, in, in_len, GIT_ZSTREAM_INFLATE); -} diff --git a/vendor/libgit2-sys/libgit2/src/util/zstream.h b/vendor/libgit2-sys/libgit2/src/util/zstream.h deleted file mode 100644 index d78b112..0000000 --- a/vendor/libgit2-sys/libgit2/src/util/zstream.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ -#ifndef INCLUDE_zstream_h__ -#define INCLUDE_zstream_h__ - -#include "git2_util.h" - -#include - -#include "str.h" - -typedef enum { - GIT_ZSTREAM_INFLATE, - GIT_ZSTREAM_DEFLATE -} git_zstream_t; - -typedef struct { - z_stream z; - git_zstream_t type; - const char *in; - size_t in_len; - int flush; - int zerr; -} git_zstream; - -#define GIT_ZSTREAM_INIT {{0}} - -int git_zstream_init(git_zstream *zstream, git_zstream_t type); -void git_zstream_free(git_zstream *zstream); - -int git_zstream_set_input(git_zstream *zstream, const void *in, size_t in_len); - -size_t git_zstream_suggest_output_len(git_zstream *zstream); - -/* get as much output as is available in the input buffer */ -int git_zstream_get_output_chunk( - void *out, size_t *out_len, git_zstream *zstream); - -/* get all the output from the entire input buffer */ -int git_zstream_get_output(void *out, size_t *out_len, git_zstream *zstream); - -bool git_zstream_done(git_zstream *zstream); -bool git_zstream_eos(git_zstream *zstream); - -void git_zstream_reset(git_zstream *zstream); - -int git_zstream_deflatebuf(git_str *out, const void *in, size_t in_len); -int git_zstream_inflatebuf(git_str *out, const void *in, size_t in_len); - -#endif